{
  "name": "svelte-example-text-color",
  "title": "svelte-example-text-color",
  "type": "registry:block",
  "description": "Change text and background color.",
  "registryDependencies": [
    "https://unpkg.com/prosekit-registry/dist/r/svelte-sample-sample-doc-text-color.json",
    "https://unpkg.com/prosekit-registry/dist/r/svelte-ui-button.json"
  ],
  "dependencies": [
    "prosekit@^0.23.2"
  ],
  "files": [
    {
      "path": "registry/src/svelte/examples/text-color/editor.svelte",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/editor.svelte",
      "content": "<script lang=\"ts\">\nimport 'prosekit/basic/style.css'\nimport 'prosekit/basic/typography.css'\n\nimport { createEditor, type NodeJSON } from 'prosekit/core'\nimport { ProseKit } from 'prosekit/svelte'\nimport { untrack } from 'svelte'\n\nimport { sampleContent } from '../../sample/sample-doc-text-color.ts'\n\nimport { defineExtension } from './extension.ts'\nimport InlineMenu from './inline-menu.svelte'\n\nconst props: {\n  initialContent?: NodeJSON\n} = $props()\n\nconst extension = defineExtension()\nconst defaultContent = untrack(() => props.initialContent ?? sampleContent)\nconst editor = createEditor({ extension, defaultContent })\n</script>\n\n<ProseKit {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 {@attach 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>\n      <InlineMenu />\n    </div>\n  </div>\n</ProseKit>\n"
    },
    {
      "path": "registry/src/svelte/examples/text-color/extension.ts",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/extension.ts",
      "content": "import { defineBasicExtension } from 'prosekit/basic'\nimport { union } from 'prosekit/core'\nimport { defineBackgroundColor } from 'prosekit/extensions/background-color'\nimport { defineTextColor } from 'prosekit/extensions/text-color'\n\nexport function defineExtension() {\n  return union(defineBasicExtension(), defineTextColor(), defineBackgroundColor())\n}\n\nexport type EditorExtension = ReturnType<typeof defineExtension>\n"
    },
    {
      "path": "registry/src/svelte/examples/text-color/index.ts",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/index.ts",
      "content": "export { default as ExampleEditor } from './editor.svelte'\n"
    },
    {
      "path": "registry/src/svelte/examples/text-color/inline-menu.svelte",
      "type": "registry:component",
      "target": "components/editor/examples/text-color/inline-menu.svelte",
      "content": "<script lang=\"ts\">\nimport type { Editor } from 'prosekit/core'\nimport { useEditorDerivedValue, useKeymap } from 'prosekit/svelte'\nimport { InlinePopoverPopup, InlinePopoverPositioner, InlinePopoverRoot } from 'prosekit/svelte/inline-popover'\nimport { toStore } from 'svelte/store'\n\nimport { Button } from '../../ui/button/index.ts'\n\nimport type { EditorExtension } from './extension.ts'\n\nconst textColors = [\n  { label: 'Gray', value: '#9ca3af' },\n  { label: 'Brown', value: '#92400e' },\n  { label: 'Orange', value: '#ea580c' },\n  { label: 'Yellow', value: '#ca8a04' },\n  { label: 'Green', value: '#16a34a' },\n  { label: 'Blue', value: '#2563eb' },\n  { label: 'Purple', value: '#9333ea' },\n  { label: 'Magenta', value: '#c026d3' },\n  { label: 'Red', value: '#dc2626' },\n]\n\nconst backgroundColors = [\n  { label: 'Gray', value: '#f3f4f6' },\n  { label: 'Brown', value: '#fef3c7' },\n  { label: 'Orange', value: '#ffedd5' },\n  { label: 'Yellow', value: '#fef9c3' },\n  { label: 'Green', value: '#d1fae5' },\n  { label: 'Blue', value: '#dbeafe' },\n  { label: 'Purple', value: '#e9d5ff' },\n  { label: 'Pink', value: '#fce7f3' },\n  { label: 'Red', value: '#fecaca' },\n]\n\nfunction getTextColorState(editor: Editor<EditorExtension>) {\n  return [{\n    label: 'Default',\n    value: 'currentColor',\n    isActive: !editor.marks.textColor.isActive(),\n    onClick: () => editor.commands.removeTextColor(),\n  }].concat(textColors.map((color) => ({\n    label: color.label,\n    value: color.value,\n    isActive: editor.marks.textColor.isActive({ color: color.value }),\n    onClick: () => editor.commands.addTextColor({ color: color.value }),\n  })))\n}\n\nfunction getBackgroundColorState(editor: Editor<EditorExtension>) {\n  return [{\n    label: 'Default',\n    value: 'canvas',\n    isActive: !editor.marks.backgroundColor.isActive(),\n    onClick: () => editor.commands.removeBackgroundColor(),\n  }].concat(\n    backgroundColors.map((color) => ({\n      label: color.label,\n      value: color.value,\n      isActive: editor.marks.backgroundColor.isActive({ color: color.value }),\n      onClick: () => editor.commands.addBackgroundColor({ color: color.value }),\n    })),\n  )\n}\n\nconst textColorState = useEditorDerivedValue(getTextColorState)\nconst backgroundColorState = useEditorDerivedValue(getBackgroundColorState)\n\nlet open = $state(false)\n\nconst keymap = $derived({\n  Escape: () => {\n    if (open) {\n      open = false\n      return true\n    }\n    return false\n  },\n})\n\nuseKeymap(toStore(() => keymap))\n</script>\n\n<InlinePopoverRoot\n  {open}\n  onOpenChange={(event) => open = event.detail}\n>\n  <InlinePopoverPositioner class=\"block overflow-visible w-min h-min z-50 ease-out transition-transform duration-100 motion-reduce:transition-none\">\n    <InlinePopoverPopup class=\"box-border origin-(--transform-origin) transition-[opacity,scale] transition-discrete motion-reduce:transition-none data-[state=closed]:duration-150 data-[state=closed]:opacity-0 starting:opacity-0 data-[state=closed]:scale-95 starting:scale-95 duration-40 border border-gray-200 dark:border-gray-800 shadow-lg bg-[canvas] relative flex min-w-32 space-x-1 overflow-auto whitespace-nowrap rounded-lg p-1\">\n      <div class=\"flex flex-col gap-4 p-4 w-60\">\n        <div class=\"flex flex-col gap-2\">\n          <div class=\"text-sm\">Text color</div>\n          <div class=\"grid grid-cols-5 gap-1\">\n            {#each $textColorState as color (color.label)}\n              <Button\n                pressed={color.isActive}\n                tooltip={`Text: ${color.label}`}\n                onClick={color.onClick}\n              >\n                <span class=\"text-base font-medium\" style:color={color.value}>\n                  A\n                </span>\n              </Button>\n            {/each}\n          </div>\n        </div>\n        <div class=\"flex flex-col gap-2\">\n          <div class=\"text-sm\">Background color</div>\n          <div class=\"grid grid-cols-5 gap-1\">\n            {#each $backgroundColorState as color (color.label)}\n              <Button\n                pressed={color.isActive}\n                tooltip={`Background: ${color.label}`}\n                onClick={color.onClick}\n              >\n                <div\n                  class=\"w-6 h-6 rounded border border-gray-200 dark:border-gray-700\"\n                  style:background-color={color.value}\n                >\n                </div>\n              </Button>\n            {/each}\n          </div>\n        </div>\n      </div>\n    </InlinePopoverPopup>\n  </InlinePopoverPositioner>\n</InlinePopoverRoot>\n"
    }
  ],
  "meta": {
    "hasIcons": false,
    "hidden": false,
    "story": "text-color",
    "framework": "svelte",
    "accumulatedFiles": [
      "registry/src/svelte/examples/text-color/editor.svelte",
      "registry/src/svelte/examples/text-color/extension.ts",
      "registry/src/svelte/examples/text-color/index.ts",
      "registry/src/svelte/examples/text-color/inline-menu.svelte",
      "registry/src/svelte/sample/sample-doc-text-color.ts",
      "registry/src/svelte/ui/button/button.svelte",
      "registry/src/svelte/ui/button/index.ts"
    ],
    "internalDependencies": [
      "svelte-sample-sample-doc-text-color",
      "svelte-ui-button"
    ]
  },
  "$schema": "https://ui.shadcn.com/schema/registry-item.json"
}
