Example: drop-cursor
Install this example with
shadcn:npx shadcn@latest add @prosekit/react-example-drop-cursornpx shadcn@latest add @prosekit/preact-example-drop-cursornpx shadcn@latest add @prosekit/solid-example-drop-cursornpx shadcn@latest add @prosekit/svelte-example-drop-cursornpx shadcn@latest add @prosekit/vue-example-drop-cursorimport 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { useMemo } from 'preact/hooks'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/preact'
import { defaultContent } from '../../sample/sample-doc-drop-cursor'
import { defineExtension } from './extension'
export default function Editor() {
const editor = useMemo(() => {
const extension = defineExtension()
return createEditor({ extension, defaultContent })
}, [])
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 {
defineBaseKeymap,
union,
} from 'prosekit/core'
import { defineDoc } from 'prosekit/extensions/doc'
import { defineDropCursor } from 'prosekit/extensions/drop-cursor'
import { defineImage } from 'prosekit/extensions/image'
import { defineParagraph } from 'prosekit/extensions/paragraph'
import { defineText } from 'prosekit/extensions/text'
export function defineExtension() {
return union(
defineBaseKeymap(),
defineDoc(),
defineText(),
defineParagraph(),
defineImage(),
defineDropCursor({
color: false,
width: 4,
class: 'transition-all bg-blue-500',
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor'import type { NodeJSON } from 'prosekit/core'
export const defaultContent: NodeJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Drag the images below to see the custom drop cursor.',
},
],
},
{
type: 'image',
attrs: {
src: 'https://static.photos/yellow/320x240/42',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/green/320x240/40',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/blue/320x240/187',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/red/320x240/188',
},
},
],
}import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/react'
import { useMemo } from 'react'
import { defaultContent } from '../../sample/sample-doc-drop-cursor'
import { defineExtension } from './extension'
export default function Editor() {
const editor = useMemo(() => {
const extension = defineExtension()
return createEditor({ extension, defaultContent })
}, [])
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 {
defineBaseKeymap,
union,
} from 'prosekit/core'
import { defineDoc } from 'prosekit/extensions/doc'
import { defineDropCursor } from 'prosekit/extensions/drop-cursor'
import { defineImage } from 'prosekit/extensions/image'
import { defineParagraph } from 'prosekit/extensions/paragraph'
import { defineText } from 'prosekit/extensions/text'
export function defineExtension() {
return union(
defineBaseKeymap(),
defineDoc(),
defineText(),
defineParagraph(),
defineImage(),
defineDropCursor({
color: false,
width: 4,
class: 'transition-all bg-blue-500',
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>'use client'
export { default as ExampleEditor } from './editor'import type { NodeJSON } from 'prosekit/core'
export const defaultContent: NodeJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Drag the images below to see the custom drop cursor.',
},
],
},
{
type: 'image',
attrs: {
src: 'https://static.photos/yellow/320x240/42',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/green/320x240/40',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/blue/320x240/187',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/red/320x240/188',
},
},
],
}import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/solid'
import type { JSX } from 'solid-js'
import { defaultContent } from '../../sample/sample-doc-drop-cursor'
import { defineExtension } from './extension'
export default function Editor(): JSX.Element {
const extension = defineExtension()
const editor = createEditor({ extension, defaultContent })
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 {
defineBaseKeymap,
union,
} from 'prosekit/core'
import { defineDoc } from 'prosekit/extensions/doc'
import { defineDropCursor } from 'prosekit/extensions/drop-cursor'
import { defineImage } from 'prosekit/extensions/image'
import { defineParagraph } from 'prosekit/extensions/paragraph'
import { defineText } from 'prosekit/extensions/text'
export function defineExtension() {
return union(
defineBaseKeymap(),
defineDoc(),
defineText(),
defineParagraph(),
defineImage(),
defineDropCursor({
color: false,
width: 4,
class: 'transition-all bg-blue-500',
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor'import type { NodeJSON } from 'prosekit/core'
export const defaultContent: NodeJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Drag the images below to see the custom drop cursor.',
},
],
},
{
type: 'image',
attrs: {
src: 'https://static.photos/yellow/320x240/42',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/green/320x240/40',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/blue/320x240/187',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/red/320x240/188',
},
},
],
}<script lang="ts">
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/svelte'
import { defaultContent } from '../../sample/sample-doc-drop-cursor'
import { defineExtension } from './extension'
const extension = defineExtension()
const editor = createEditor({ extension, defaultContent })
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 {
defineBaseKeymap,
union,
} from 'prosekit/core'
import { defineDoc } from 'prosekit/extensions/doc'
import { defineDropCursor } from 'prosekit/extensions/drop-cursor'
import { defineImage } from 'prosekit/extensions/image'
import { defineParagraph } from 'prosekit/extensions/paragraph'
import { defineText } from 'prosekit/extensions/text'
export function defineExtension() {
return union(
defineBaseKeymap(),
defineDoc(),
defineText(),
defineParagraph(),
defineImage(),
defineDropCursor({
color: false,
width: 4,
class: 'transition-all bg-blue-500',
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor.svelte'import type { NodeJSON } from 'prosekit/core'
export const defaultContent: NodeJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Drag the images below to see the custom drop cursor.',
},
],
},
{
type: 'image',
attrs: {
src: 'https://static.photos/yellow/320x240/42',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/green/320x240/40',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/blue/320x240/187',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/red/320x240/188',
},
},
],
}<script setup lang="ts">
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/vue'
import {
ref,
watchPostEffect,
} from 'vue'
import { defaultContent } from '../../sample/sample-doc-drop-cursor'
import { defineExtension } from './extension'
const extension = defineExtension()
const editor = createEditor({ extension, defaultContent })
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 {
defineBaseKeymap,
union,
} from 'prosekit/core'
import { defineDoc } from 'prosekit/extensions/doc'
import { defineDropCursor } from 'prosekit/extensions/drop-cursor'
import { defineImage } from 'prosekit/extensions/image'
import { defineParagraph } from 'prosekit/extensions/paragraph'
import { defineText } from 'prosekit/extensions/text'
export function defineExtension() {
return union(
defineBaseKeymap(),
defineDoc(),
defineText(),
defineParagraph(),
defineImage(),
defineDropCursor({
color: false,
width: 4,
class: 'transition-all bg-blue-500',
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>export { default as ExampleEditor } from './editor.vue'import type { NodeJSON } from 'prosekit/core'
export const defaultContent: NodeJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Drag the images below to see the custom drop cursor.',
},
],
},
{
type: 'image',
attrs: {
src: 'https://static.photos/yellow/320x240/42',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/green/320x240/40',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/blue/320x240/187',
},
},
{
type: 'image',
attrs: {
src: 'https://static.photos/red/320x240/188',
},
},
],
}