Example: placeholder
Install this example with
shadcn:npx shadcn@latest add @prosekit/react-example-placeholdernpx shadcn@latest add @prosekit/preact-example-placeholdernpx shadcn@latest add @prosekit/solid-example-placeholdernpx shadcn@latest add @prosekit/svelte-example-placeholdernpx shadcn@latest add @prosekit/vue-example-placeholderimport 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import {
useCallback,
useMemo,
} from 'preact/hooks'
import {
createEditor,
jsonFromNode,
type NodeJSON,
} from 'prosekit/core'
import type { ProseMirrorNode } from 'prosekit/pm/model'
import {
ProseKit,
useDocChange,
} from 'prosekit/preact'
import { defineExtension } from './extension'
export default function Editor(props: {
initialContent?: NodeJSON
onDocUpdate?: (doc: NodeJSON) => void
}) {
const editor = useMemo(() => {
const extension = defineExtension()
return createEditor({ extension, defaultContent: props.initialContent })
}, [props.initialContent])
const { onDocUpdate } = props
const handleDocChange = useCallback(
(doc: ProseMirrorNode) => onDocUpdate?.(jsonFromNode(doc)),
[onDocUpdate],
)
useDocChange(handleDocChange, { editor })
return (
<ProseKit editor={editor}>
<div className="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 text-black dark:text-white">
<div className="relative w-full flex-1 box-border overflow-y-auto">
<div ref={editor.mount} className="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
</div>
</div>
</ProseKit>
)
}import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { definePlaceholder } from 'prosekit/extensions/placeholder'
export function defineExtension() {
return union(
defineBasicExtension(),
definePlaceholder({ placeholder: 'Type something...' }),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor'import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import {
createEditor,
jsonFromNode,
type NodeJSON,
} from 'prosekit/core'
import type { ProseMirrorNode } from 'prosekit/pm/model'
import {
ProseKit,
useDocChange,
} from 'prosekit/react'
import {
useCallback,
useMemo,
} from 'react'
import { defineExtension } from './extension'
export default function Editor(props: {
initialContent?: NodeJSON
onDocUpdate?: (doc: NodeJSON) => void
}) {
const editor = useMemo(() => {
const extension = defineExtension()
return createEditor({ extension, defaultContent: props.initialContent })
}, [props.initialContent])
const { onDocUpdate } = props
const handleDocChange = useCallback(
(doc: ProseMirrorNode) => onDocUpdate?.(jsonFromNode(doc)),
[onDocUpdate],
)
useDocChange(handleDocChange, { editor })
return (
<ProseKit editor={editor}>
<div className="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 text-black dark:text-white">
<div className="relative w-full flex-1 box-border overflow-y-auto">
<div ref={editor.mount} className="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
</div>
</div>
</ProseKit>
)
}import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { definePlaceholder } from 'prosekit/extensions/placeholder'
export function defineExtension() {
return union(
defineBasicExtension(),
definePlaceholder({ placeholder: 'Type something...' }),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>'use client'
export { default as ExampleEditor } from './editor'import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import {
createEditor,
jsonFromNode,
type NodeJSON,
} from 'prosekit/core'
import type { ProseMirrorNode } from 'prosekit/pm/model'
import {
ProseKit,
useDocChange,
} from 'prosekit/solid'
import type { JSX } from 'solid-js'
import { defineExtension } from './extension'
export default function Editor(props: {
initialContent?: NodeJSON
onDocUpdate?: (doc: NodeJSON) => void
}): JSX.Element {
const extension = defineExtension()
const editor = createEditor({ extension, defaultContent: props.initialContent })
const handleDocChange = (doc: ProseMirrorNode) => props.onDocUpdate?.(jsonFromNode(doc))
useDocChange(handleDocChange, { editor })
return (
<ProseKit editor={editor}>
<div class="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 text-black dark:text-white">
<div class="relative w-full flex-1 box-border overflow-y-auto">
<div ref={editor.mount} class="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
</div>
</div>
</ProseKit>
)
}import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { definePlaceholder } from 'prosekit/extensions/placeholder'
export function defineExtension() {
return union(
defineBasicExtension(),
definePlaceholder({ placeholder: 'Type something...' }),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor'<script lang="ts">
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import {
createEditor,
jsonFromNode,
type NodeJSON,
} from 'prosekit/core'
import type { ProseMirrorNode } from 'prosekit/pm/model'
import {
ProseKit,
useDocChange,
} from 'prosekit/svelte'
import { defineExtension } from './extension'
const props = $props<{
initialContent?: NodeJSON
onDocUpdate?: (doc: NodeJSON) => void
}>()
const extension = defineExtension()
const editor = createEditor({ extension, defaultContent: props.initialContent })
const handleDocChange = (doc: ProseMirrorNode) => props.onDocUpdate?.(jsonFromNode(doc))
useDocChange(handleDocChange, { editor })
const mount = (element: HTMLElement) => {
editor.mount(element)
return { destroy: () => editor.unmount() }
}
</script>
<ProseKit {editor}>
<div class="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 text-black dark:text-white">
<div class="relative w-full flex-1 box-border overflow-y-auto">
<div use:mount class="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
</div>
</div>
</ProseKit>import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { definePlaceholder } from 'prosekit/extensions/placeholder'
export function defineExtension() {
return union(
defineBasicExtension(),
definePlaceholder({ placeholder: 'Type something...' }),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor.svelte'<script setup lang="ts">
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import {
createEditor,
jsonFromNode,
type NodeJSON,
} from 'prosekit/core'
import type { ProseMirrorNode } from 'prosekit/pm/model'
import {
ProseKit,
useDocChange,
} from 'prosekit/vue'
import {
ref,
watchPostEffect,
} from 'vue'
import { defineExtension } from './extension'
const props = defineProps<{
initialContent?: NodeJSON
onDocUpdate?: (doc: NodeJSON) => void
}>()
const extension = defineExtension()
const editor = createEditor({ extension, defaultContent: props.initialContent })
const handleDocChange = (doc: ProseMirrorNode) => props.onDocUpdate?.(jsonFromNode(doc))
useDocChange(handleDocChange, { editor })
const editorRef = ref<HTMLDivElement | null>(null)
watchPostEffect((onCleanup) => {
editor.mount(editorRef.value)
onCleanup(() => editor.unmount())
})
</script>
<template>
<ProseKit :editor="editor">
<div class="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 text-black dark:text-white">
<div class="relative w-full flex-1 box-border overflow-y-auto">
<div ref="editorRef" class="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500" />
</div>
</div>
</ProseKit>
</template>import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { definePlaceholder } from 'prosekit/extensions/placeholder'
export function defineExtension() {
return union(
defineBasicExtension(),
definePlaceholder({ placeholder: 'Type something...' }),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor.vue'