{
  "name": "vue-example-change-tracking",
  "title": "vue-example-change-tracking",
  "type": "registry:block",
  "description": "Track and commit document changes with version history.",
  "registryDependencies": [],
  "dependencies": [
    "prosekit@^0.23.2"
  ],
  "files": [
    {
      "path": "registry/src/vue/examples/change-tracking/editor-diff.vue",
      "type": "registry:component",
      "target": "components/editor/examples/change-tracking/editor-diff.vue",
      "content": "<script setup lang=\"ts\">\nimport { defineBasicExtension } from 'prosekit/basic'\nimport { createEditor, union } from 'prosekit/core'\nimport { defineCommitViewer, type Commit } from 'prosekit/extensions/commit'\nimport { defineReadonly } from 'prosekit/extensions/readonly'\nimport { ProseKit } from 'prosekit/vue'\n\nconst props = defineProps<{ commit: Commit }>()\n\nconst editor = createEditor({\n  extension: union(\n    defineBasicExtension(),\n    defineReadonly(),\n    defineCommitViewer(props.commit),\n  ),\n})\n</script>\n\n<template>\n  <ProseKit :editor=\"editor\">\n    <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-[canvas] text-black dark:text-white\">\n      <div class=\"relative w-full flex-1 box-border overflow-y-auto\">\n        <div :ref=\"(el) => editor.mount(el as HTMLElement | null)\" 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>\n      </div>\n    </div>\n  </ProseKit>\n</template>\n"
    },
    {
      "path": "registry/src/vue/examples/change-tracking/editor-main.vue",
      "type": "registry:component",
      "target": "components/editor/examples/change-tracking/editor-main.vue",
      "content": "<script setup lang=\"ts\">\nimport 'prosekit/basic/style.css'\nimport 'prosekit/basic/typography.css'\n\nimport { defineBasicExtension } from 'prosekit/basic'\nimport { createEditor, union, type NodeJSON } from 'prosekit/core'\nimport { defineCommitRecorder, type CommitRecorder } from 'prosekit/extensions/commit'\nimport { ProseKit } from 'prosekit/vue'\n\nconst props = defineProps<{\n  commitRecorder: CommitRecorder\n  initialContent?: NodeJSON\n}>()\n\nconst editor = createEditor({\n  extension: union(\n    defineBasicExtension(),\n    defineCommitRecorder(props.commitRecorder),\n  ),\n  defaultContent: props.initialContent,\n})\n</script>\n\n<template>\n  <ProseKit :editor=\"editor\">\n    <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-[canvas] text-black dark:text-white\">\n      <div class=\"relative w-full flex-1 box-border overflow-y-auto\">\n        <div :ref=\"(el) => editor.mount(el as HTMLElement | null)\" 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>\n      </div>\n    </div>\n  </ProseKit>\n</template>\n"
    },
    {
      "path": "registry/src/vue/examples/change-tracking/editor.vue",
      "type": "registry:component",
      "target": "components/editor/examples/change-tracking/editor.vue",
      "content": "<script setup lang=\"ts\">\nimport 'prosekit/basic/style.css'\nimport 'prosekit/basic/typography.css'\n\nimport type { NodeJSON } from 'prosekit/core'\nimport { CommitRecorder, type Commit } from 'prosekit/extensions/commit'\nimport { ref } from 'vue'\n\nimport EditorDiff from './editor-diff.vue'\nimport EditorMain from './editor-main.vue'\n\nconst commits = ref<{ id: string; date: Date; commit: Commit }[]>([])\nconst key = ref(0)\nconst initialContent = ref<NodeJSON | undefined>()\nconst commitRecorder = new CommitRecorder()\n\nfunction handleCommit() {\n  const commit = commitRecorder.commit()\n  if (!commit) return\n  const id = Math.random().toString(36).slice(2, 9)\n  commits.value = [{ id, date: new Date(), commit }, ...commits.value]\n}\n\nfunction handleRestore(id: string) {\n  const index = commits.value.findIndex((commit) => commit.id === id)\n  const commit = commits.value[index]\n  if (index === -1 || !commit) return\n  const doc = commit.commit.doc\n  initialContent.value = doc\n  commits.value = commits.value.slice(index)\n  key.value = key.value + 1\n}\n</script>\n\n<template>\n  <div class=\"grid grid-cols-2 gap-2\">\n    <div class=\"flex flex-col gap-4\">\n      <div class=\"max-h-md\">\n        <EditorMain\n          :key=\"key\"\n          :initial-content=\"initialContent\"\n          :commit-recorder=\"commitRecorder\"\n        />\n      </div>\n      <button class=\"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-white dark:ring-offset-gray-950 transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-gray-900 dark:focus-visible:ring-gray-300 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border-0 bg-gray-900 dark:bg-gray-50 text-gray-50 dark:text-gray-900 hover:bg-gray-900/90 dark:hover:bg-gray-50/90 h-10 px-4 py-2\" @click=\"handleCommit\">\n        Save\n      </button>\n    </div>\n    <div class=\"flex flex-col gap-4\">\n      <div v-for=\"commit in commits\" :key=\"commit.id\">\n        <div class=\"max-h-md\">\n          <EditorDiff :commit=\"commit.commit\" />\n        </div>\n        <div class=\"w-full inline-flex justify-between p-1 text-sm\">\n          <span class=\"opacity-50\">\n            {{ commit.date.toLocaleTimeString() }}\n          </span>\n          <button\n            class=\"underline opacity-50 hover:opacity-100\"\n            @click=\"() => handleRestore(commit.id)\"\n          >\n            Restore\n          </button>\n        </div>\n      </div>\n    </div>\n  </div>\n</template>\n"
    },
    {
      "path": "registry/src/vue/examples/change-tracking/index.ts",
      "type": "registry:component",
      "target": "components/editor/examples/change-tracking/index.ts",
      "content": "export { default as ExampleEditor } from './editor.vue'\n"
    }
  ],
  "meta": {
    "hasIcons": false,
    "hidden": false,
    "story": "change-tracking",
    "framework": "vue",
    "accumulatedFiles": [
      "registry/src/vue/examples/change-tracking/editor-diff.vue",
      "registry/src/vue/examples/change-tracking/editor-main.vue",
      "registry/src/vue/examples/change-tracking/editor.vue",
      "registry/src/vue/examples/change-tracking/index.ts"
    ],
    "internalDependencies": []
  },
  "$schema": "https://ui.shadcn.com/schema/registry-item.json"
}
