Example: link-mark-view
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 { defineExtension } from './extension'
export default function Editor() {
const editor = useMemo(() => {
return createEditor({ extension: defineExtension(), 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 shadow dark:border-zinc-700 flex flex-col bg-white dark:bg-gray-950'>
<div className='relative w-full flex-1 box-border overflow-y-scroll'>
<div ref={editor.mount} className='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none outline-0 [&_span[data-mention="user"]]:text-blue-500 [&_span[data-mention="tag"]]:text-violet-500'></div>
</div>
</div>
</ProseKit>
)
}
const defaultContent = `
<p>Here is a link that changes color every second: <a href="https://www.example.com">example link</a>
`
import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { defineReactMarkView } from 'prosekit/react'
import LinkView from './link-view'
export function defineExtension() {
return union(
defineBasicExtension(),
defineReactMarkView({
name: 'link',
component: LinkView,
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>
import type { ReactMarkViewProps } from 'prosekit/react'
import {
useEffect,
useState,
} from 'react'
const colors = [
'#f06292',
'#ba68c8',
'#9575cd',
'#7986cb',
'#64b5f6',
'#4fc3f7',
'#4dd0e1',
'#4db6ac',
'#81c784',
'#aed581',
'#ffb74d',
'#ffa726',
'#ff8a65',
'#d4e157',
'#ffd54f',
'#ffecb3',
]
function pickRandomColor() {
return colors[Math.floor(Math.random() * colors.length)]
}
export default function Link(props: ReactMarkViewProps) {
const [color, setColor] = useState(colors[0])
const { mark, contentRef } = props
const href = mark.attrs.href as string
useEffect(() => {
const interval = setInterval(() => {
setColor(pickRandomColor())
}, 1000)
return () => clearInterval(interval)
}, [])
return (
<a
href={href}
ref={contentRef}
style={{ color, transition: 'color 1s ease-in-out' }}
>
</a>
)
}
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/solid'
import { defineExtension } from './extension'
export default function Editor() {
const editor = createEditor({ extension: defineExtension(), 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 shadow dark:border-zinc-700 flex flex-col bg-white dark:bg-gray-950'>
<div class='relative w-full flex-1 box-border overflow-y-scroll'>
<div ref={editor.mount} class='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none outline-0 [&_span[data-mention="user"]]:text-blue-500 [&_span[data-mention="tag"]]:text-violet-500'></div>
</div>
</div>
</ProseKit>
)
}
const defaultContent = `
<p>Here is a link that changes color every second: <a href="https://www.example.com">example link</a>
`
import { defineBasicExtension } from 'prosekit/basic'
import { union } from 'prosekit/core'
import { defineSolidMarkView } from 'prosekit/solid'
import LinkView from './link-view'
export function defineExtension() {
return union(
defineBasicExtension(),
defineSolidMarkView({
name: 'link',
component: LinkView,
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>
import type { SolidMarkViewProps } from 'prosekit/solid'
import {
createSignal,
onCleanup,
onMount,
} from 'solid-js'
const colors = [
'#f06292',
'#ba68c8',
'#9575cd',
'#7986cb',
'#64b5f6',
'#4fc3f7',
'#4dd0e1',
'#4db6ac',
'#81c784',
'#aed581',
'#ffb74d',
'#ffa726',
'#ff8a65',
'#d4e157',
'#ffd54f',
'#ffecb3',
]
function pickRandomColor() {
return colors[Math.floor(Math.random() * colors.length)]
}
export default function Link(props: SolidMarkViewProps) {
const [color, setColor] = createSignal(colors[0])
const { mark, contentRef } = props
const href = mark.attrs.href as string
onMount(() => {
const interval = setInterval(() => {
setColor(pickRandomColor())
}, 1000)
onCleanup(() => clearInterval(interval))
})
return (
<a
href={href}
ref={contentRef}
style={{ color: color(), transition: 'color 1s ease-in-out' }}
>
</a>
)
}
<script lang="ts">
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/svelte'
import { defineExtension } from './extension'
const defaultContent = `
<p>Here is a link that changes color every second: <a href="https://www.example.com">example link</a>
`
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 shadow dark:border-zinc-700 flex flex-col bg-white dark:bg-gray-950'>
<div class='relative w-full flex-1 box-border overflow-y-scroll'>
<div use:mount class='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none 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 { defineSvelteMarkView } from 'prosekit/svelte'
import LinkView from './link-view.svelte'
export function defineExtension() {
return union(
defineBasicExtension(),
defineSvelteMarkView({
name: 'link',
component: LinkView,
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>
<script lang="ts">
import type { SvelteMarkViewProps } from 'prosekit/svelte'
const colors = [
'#f06292',
'#ba68c8',
'#9575cd',
'#7986cb',
'#64b5f6',
'#4fc3f7',
'#4dd0e1',
'#4db6ac',
'#81c784',
'#aed581',
'#ffb74d',
'#ffa726',
'#ff8a65',
'#d4e157',
'#ffd54f',
'#ffecb3',
]
function pickRandomColor() {
return colors[Math.floor(Math.random() * colors.length)]
}
let { mark, contentRef }: SvelteMarkViewProps = $props()
const href = $derived($mark.attrs.href as string)
let color = $state(colors[0])
$effect(() => {
const interval = setInterval(() => {
color = pickRandomColor()
}, 1000)
return () => clearInterval(interval)
})
</script>
<a
{href}
use:contentRef
style="color: {color}; transition: color 1s ease-in-out"
></a>
<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 { defineExtension } from './extension'
const defaultContent = `
<p>Here is a link that changes color every second: <a href="https://www.example.com">example link</a>
`
const editor = createEditor({ extension: defineExtension(), 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 shadow dark:border-zinc-700 flex flex-col bg-white dark:bg-gray-950'>
<div class='relative w-full flex-1 box-border overflow-y-scroll'>
<div ref="editorRef" class='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none 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 {
defineVueMarkView,
type VueMarkViewComponent,
} from 'prosekit/vue'
import LinkView from './link-view.vue'
export function defineExtension() {
return union(
defineBasicExtension(),
defineVueMarkView({
name: 'link',
component: LinkView as VueMarkViewComponent,
}),
)
}
export type EditorExtension = ReturnType<typeof defineExtension>
<script lang="ts" setup>
import type { VueMarkViewProps } from 'prosekit/vue'
import {
computed,
onMounted,
onUnmounted,
ref,
} from 'vue'
const colors = [
'#f06292',
'#ba68c8',
'#9575cd',
'#7986cb',
'#64b5f6',
'#4fc3f7',
'#4dd0e1',
'#4db6ac',
'#81c784',
'#aed581',
'#ffb74d',
'#ffa726',
'#ff8a65',
'#d4e157',
'#ffd54f',
'#ffecb3',
]
function pickRandomColor() {
return colors[Math.floor(Math.random() * colors.length)]
}
const props = defineProps<VueMarkViewProps>()
const color = ref(colors[0])
const href = computed(() => props.mark.value.attrs.href as string)
onMounted(() => {
const interval = setInterval(() => {
color.value = pickRandomColor()
}, 1000)
onUnmounted(() => clearInterval(interval))
})
</script>
<template>
<a
:ref="contentRef"
:href="href"
:style="{ color: color, transition: 'color 1s ease-in-out' }"
></a>
</template>