@pixerate/editor-react 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/dist/canvas/index.cjs +252 -119
  3. package/dist/canvas/index.cjs.map +1 -1
  4. package/dist/canvas/index.d.cts +55 -7
  5. package/dist/canvas/index.d.ts +55 -7
  6. package/dist/canvas/index.js +155 -19
  7. package/dist/canvas/index.js.map +1 -1
  8. package/dist/chunk-4ZC2WCUO.js +196 -0
  9. package/dist/chunk-4ZC2WCUO.js.map +1 -0
  10. package/dist/{chunk-TL27COKM.js → chunk-LPFZMZ3L.js} +45 -2
  11. package/dist/chunk-LPFZMZ3L.js.map +1 -0
  12. package/dist/{chunk-25S5EHH4.js → chunk-QVQYYHJ5.js} +4 -3
  13. package/dist/chunk-QVQYYHJ5.js.map +1 -0
  14. package/dist/commands/index.cjs +232 -0
  15. package/dist/commands/index.cjs.map +1 -0
  16. package/dist/commands/index.d.cts +69 -0
  17. package/dist/commands/index.d.ts +69 -0
  18. package/dist/commands/index.js +13 -0
  19. package/dist/commands/index.js.map +1 -0
  20. package/dist/image-editor/index.cjs +41 -0
  21. package/dist/image-editor/index.cjs.map +1 -1
  22. package/dist/image-editor/index.d.cts +5 -3
  23. package/dist/image-editor/index.d.ts +5 -3
  24. package/dist/image-editor/index.js +1 -1
  25. package/dist/index.cjs +535 -251
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +61 -22
  28. package/dist/index.d.ts +61 -22
  29. package/dist/index.js +131 -70
  30. package/dist/index.js.map +1 -1
  31. package/dist/spreadsheet/index.cjs +1 -1
  32. package/dist/spreadsheet/index.cjs.map +1 -1
  33. package/dist/spreadsheet/index.d.cts +7 -7
  34. package/dist/spreadsheet/index.d.ts +7 -7
  35. package/dist/spreadsheet/index.js +1 -1
  36. package/package.json +10 -2
  37. package/dist/chunk-25S5EHH4.js.map +0 -1
  38. package/dist/chunk-TL27COKM.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/usePromptEditor.ts","../src/hooks/useEditor.ts","../src/hooks/useNavigationGuard.ts","../src/hooks/useDismissGuard.ts","../src/hooks/useHistory.ts","../src/hooks/useHistoryShortcuts.ts","../src/hooks/useFileImport.ts","../src/hooks/useAgentToolProvider.ts","../src/components/EditorContent.tsx","../src/components/BubbleMenu.tsx","../src/components/TemplateRenderer.tsx","../src/components/VariableForm.tsx","../src/hooks/useOutline.ts","../src/components/OutlinePanel.tsx","../src/index.ts","../src/slots.tsx","../src/review/useReview.ts","../src/review/CommentsPanel.tsx","../src/review/ReviewToolbar.tsx","../src/review/CommentButton.tsx"],"sourcesContent":["import { useMemo, useEffect, useRef } from \"react\";\nimport { useEditor } from \"@tiptap/react\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { Slice } from \"@tiptap/pm/model\";\nimport {\n Template,\n ColorGradient,\n GradientText,\n TemplateSuggestions,\n LoadingNode,\n plainTextToTipTapHtml,\n plainTextToSlice,\n getEditorText,\n tokenizePrompt,\n FileImport,\n type FileImportOptions,\n} from \"@pixerate/editor\";\n\nexport interface UsePromptEditorProps {\n /**\n * The editor content as plain text. Changes from the parent (e.g. clearing\n * after submit) are applied to the editor; echoes of the editor's own\n * updates via `onContentChange` are ignored.\n */\n content: string;\n /** Callback fired when the editor content changes (returns plain text) */\n onContentChange: (text: string) => void;\n /** List of available templates to be suggested and highlighted */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether the editor is editable */\n isEditing?: boolean;\n /** Placeholder text for the editor */\n placeholder?: string;\n /** Additional CSS classes for the editor container */\n className?: string;\n /** Callback fired when the Escape key is pressed */\n onEscape?: () => void;\n /** Custom keydown handler. Return true to prevent default behavior */\n onKeyDown?: (event: KeyboardEvent) => boolean;\n /** Callback fired when text selection changes */\n onSelectionChange?: (selection: { from: number; to: number } | null) => void;\n /** Callback fired when a slash command (e.g., /template) matches */\n onSlashCommandMatch?: (\n match: RegExpMatchArray,\n from: number,\n to: number,\n coords: { top: number; left: number },\n ) => void;\n /** Callback to dismiss/clear the active slash command */\n clearSlashCommand?: () => void;\n /** Whether a slash command menu is currently active */\n slashCommandActive?: boolean;\n /**\n * Callback fired the first time each milestone is reached while the editor\n * is mounted: `used_variable` ({variable}) and `used_magic` (__instruction__).\n */\n onMilestone?: (milestone: string) => void;\n /** DOM element ID of the container, used for positioning popovers */\n containerId?: string;\n /** Variable names originating from structured JSON output steps */\n jsonVariables?: string[];\n /** Animation speed for gradient decorations */\n speed?: number;\n /**\n * Import text from .md, .html, .txt and .rtf files dropped onto the editor\n * (opt-in). Content is always inserted as plain text. Pasting keeps the\n * plain-text paste handler, so pasted files are not imported.\n */\n fileImport?: Omit<FileImportOptions, \"asPlainText\"> | boolean;\n}\n\nconst DEFAULT_TEMPLATES: Template[] = [];\nconst DEFAULT_COLOR_MAP = new Map<string, ColorGradient>([\n [\"default\", { from: \"#f43f5e\", to: \"#8b5cf6\" }],\n]);\nconst DEFAULT_CLASS_NAME =\n \"w-full border border-input rounded-md p-3 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary whitespace-pre-wrap break-words\";\n\nconst normalizeNewlines = (text: string) => text.replace(/\\r\\n?/g, \"\\n\");\n\nexport function usePromptEditor({\n content,\n onContentChange,\n templates = DEFAULT_TEMPLATES,\n templateColorMap: userColorMap,\n isEditing = true,\n placeholder = \"Write a prompt, use {{template}}, {variable}, or /command...\",\n className,\n onEscape,\n onKeyDown,\n onSelectionChange,\n onSlashCommandMatch,\n clearSlashCommand,\n slashCommandActive = false,\n onMilestone,\n containerId = \"editor-container\",\n jsonVariables,\n speed = 2,\n fileImport,\n}: UsePromptEditorProps) {\n const fileImportRef = useRef(fileImport);\n fileImportRef.current = fileImport;\n const fileImportEnabled = !!fileImport;\n\n const slashCommandActiveRef = useRef(slashCommandActive);\n slashCommandActiveRef.current = slashCommandActive;\n\n const clearSlashCommandRef = useRef(clearSlashCommand);\n clearSlashCommandRef.current = clearSlashCommand;\n\n const onEscapeRef = useRef(onEscape);\n onEscapeRef.current = onEscape;\n\n const onKeyDownRef = useRef(onKeyDown);\n onKeyDownRef.current = onKeyDown;\n\n const onSelectionChangeRef = useRef(onSelectionChange);\n onSelectionChangeRef.current = onSelectionChange;\n\n const onSlashCommandMatchRef = useRef(onSlashCommandMatch);\n onSlashCommandMatchRef.current = onSlashCommandMatch;\n\n const onContentChangeRef = useRef(onContentChange);\n onContentChangeRef.current = onContentChange;\n\n const onMilestoneRef = useRef(onMilestone);\n onMilestoneRef.current = onMilestone;\n\n const containerIdRef = useRef(containerId);\n containerIdRef.current = containerId;\n\n const templateKey = useMemo(() => {\n return (templates || [])\n .map((t) => `${t.id || t.name}:${(t as any).latestVersion || \"\"}`)\n .sort()\n .join(\",\");\n }, [templates]);\n\n // Key the color map by value so an inline `new Map(...)` does not recreate\n // the editor on every render.\n const colorMapKey = userColorMap\n ? JSON.stringify(Array.from(userColorMap.entries()))\n : \"\";\n const resolvedColorMap = useMemo(() => {\n if (userColorMap) return userColorMap;\n const map = new Map<string, ColorGradient>();\n templates.forEach((t) => {\n map.set(t.name, { from: \"#f43f5e\", to: \"#8b5cf6\" });\n });\n return map.size > 0 ? map : DEFAULT_COLOR_MAP;\n }, [colorMapKey, templateKey]);\n\n const jsonVariablesKey = (jsonVariables || []).join(\"\\u0000\");\n\n const reachedMilestonesRef = useRef(new Set<string>());\n\n const StarterKitExt =\n (StarterKit as any)?.configure\n ? StarterKit\n : (StarterKit as any)?.default?.configure\n ? (StarterKit as any)?.default\n : StarterKit;\n\n const PlaceholderExt =\n (Placeholder as any)?.configure\n ? Placeholder\n : (Placeholder as any)?.default?.configure\n ? (Placeholder as any)?.default\n : Placeholder;\n\n const editor = useEditor(\n {\n immediatelyRender: false,\n enablePasteRules: false,\n enableInputRules: false,\n editable: isEditing,\n extensions: [\n StarterKitExt.configure({\n heading: false,\n codeBlock: false,\n }),\n PlaceholderExt.configure({ placeholder }),\n GradientText.configure({\n templateColorMap: resolvedColorMap,\n speed,\n jsonVariables,\n }),\n TemplateSuggestions.configure({\n templates,\n }),\n LoadingNode,\n ...(fileImportEnabled\n ? [\n FileImport.configure({\n ...(typeof fileImportRef.current === \"object\" ? fileImportRef.current : {}),\n // Prompt editors only ever receive plain text.\n asPlainText: true,\n }),\n ]\n : []),\n ],\n content: plainTextToTipTapHtml(content),\n onUpdate: ({ editor: ed }) => {\n const plainText = getEditorText(ed);\n onContentChangeRef.current?.(plainText);\n\n if (onMilestoneRef.current) {\n const reached = reachedMilestonesRef.current;\n for (const token of tokenizePrompt(plainText)) {\n const milestone =\n token.type === \"variable\"\n ? \"used_variable\"\n : token.type === \"instruction\"\n ? \"used_magic\"\n : null;\n if (milestone && !reached.has(milestone)) {\n reached.add(milestone);\n onMilestoneRef.current(milestone);\n }\n }\n }\n\n const { state, view } = ed;\n const { selection } = state;\n const { $from, from, to } = selection;\n\n onSelectionChangeRef.current?.({ from, to });\n\n if (onSlashCommandMatchRef.current && clearSlashCommandRef.current) {\n const textBeforeCursor = $from?.parent?.textBetween\n ? $from.parent.textBetween(0, $from.parentOffset)\n : \"\";\n const slashMatch = textBeforeCursor.match(\n /(?:^|\\s)\\/([a-zA-Z0-9_-]*)$/,\n );\n\n if (slashMatch) {\n const coords = view.coordsAtPos($from.pos);\n const containerEl =\n document.getElementById(containerIdRef.current) ||\n document.getElementById(\"editor-container\") ||\n (view.dom.closest?.(\".relative\") as HTMLElement | null);\n const containerCoords = containerEl?.getBoundingClientRect();\n\n if (containerCoords) {\n onSlashCommandMatchRef.current(\n slashMatch,\n $from.pos -\n slashMatch[0].length +\n (slashMatch[0].startsWith(\" \") ? 1 : 0),\n $from.pos,\n {\n top: coords.bottom - containerCoords.top + 5,\n left: coords.left - containerCoords.left,\n },\n );\n }\n } else {\n clearSlashCommandRef.current();\n }\n }\n },\n onSelectionUpdate: ({ editor: ed }) => {\n const { from, to } = ed.state.selection;\n onSelectionChangeRef.current?.({ from, to });\n },\n editorProps: {\n attributes: {\n class: className || DEFAULT_CLASS_NAME,\n role: \"textbox\",\n \"aria-label\": \"Prompt editor\",\n },\n handleKeyDown(view, event) {\n if (slashCommandActiveRef.current) {\n if (\n event.key === \"ArrowUp\" ||\n event.key === \"ArrowDown\" ||\n event.key === \"Enter\"\n ) {\n event.preventDefault();\n return true;\n }\n if (event.key === \"Escape\") {\n clearSlashCommandRef.current?.();\n event.preventDefault();\n event.stopPropagation();\n return true;\n }\n }\n if (onKeyDownRef.current && onKeyDownRef.current(event as KeyboardEvent)) {\n return true;\n }\n if (event.key === \"Escape\" && onEscapeRef.current) {\n onEscapeRef.current();\n return true;\n }\n return false;\n },\n handlePaste: (view, event) => {\n // Paste as plain text even when the clipboard also carries HTML.\n const text = event.clipboardData?.getData(\"text/plain\");\n if (!text) return false;\n event.preventDefault();\n const schema = view.state.schema;\n if (!schema) return false;\n view.dispatch(\n view.state.tr.replaceSelection(plainTextToSlice(text, schema)),\n );\n return true;\n },\n clipboardTextParser: (text, context, _plain, view) => {\n const schema =\n (context as any)?.doc?.type?.schema ||\n (context as any)?.schema ||\n view?.state?.schema;\n\n if (!schema) return Slice.empty;\n return plainTextToSlice(text, schema);\n },\n },\n },\n // Only options baked into extensions recreate the editor; editable state,\n // placeholder, class names and content are applied to the live instance.\n [resolvedColorMap, templateKey, speed, jsonVariablesKey, fileImportEnabled],\n );\n\n useEffect(() => {\n if (editor && !editor.isDestroyed) {\n editor.setEditable(isEditing);\n }\n }, [editor, isEditing]);\n\n // Apply content changes made by the parent (e.g. clearing after submit).\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n if (normalizeNewlines(content) === getEditorText(editor)) return;\n const { from, to } = editor.state.selection;\n editor.commands.setContent(plainTextToTipTapHtml(content), false);\n const max = editor.state.doc.content.size;\n editor.commands.setTextSelection({\n from: Math.min(from, max),\n to: Math.min(to, max),\n });\n }, [editor, content]);\n\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n editor.setOptions({\n editorProps: {\n ...editor.options.editorProps,\n attributes: {\n ...(editor.options.editorProps.attributes as Record<string, string>),\n class: className || DEFAULT_CLASS_NAME,\n },\n },\n });\n }, [editor, className]);\n\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n const placeholderExt = editor.extensionManager.extensions.find(\n (ext) => ext.name === \"placeholder\",\n );\n if (!placeholderExt || placeholderExt.options.placeholder === placeholder) {\n return;\n }\n placeholderExt.options.placeholder = placeholder;\n // Re-run decorations so the new placeholder renders.\n editor.view.dispatch(editor.state.tr);\n }, [editor, placeholder]);\n\n return editor;\n}\n","import { useEditor as useTipTapEditor, UseEditorOptions } from \"@tiptap/react\";\nimport {\n createRichTextPreset,\n RichTextPresetOptions,\n type FileImportOptions,\n type RichClipboardOptions,\n} from \"@pixerate/editor\";\n\nexport interface UseRichEditorProps extends UseEditorOptions {\n richTextOptions?: RichTextPresetOptions;\n /**\n * Import .md, .html, .txt and .rtf files dropped or pasted into the editor\n * at the drop position (opt-in; same as `richTextOptions.fileImport`).\n */\n fileImport?: FileImportOptions | boolean;\n /**\n * Copy/paste lossless ProseMirror slices between editors via the\n * `application/x.pixerate.document+json` clipboard type (opt-in; same as\n * `richTextOptions.richClipboard`).\n */\n richClipboard?: RichClipboardOptions | boolean;\n}\n\n/**\n * Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.\n */\nexport function useEditor(options: UseRichEditorProps = {}) {\n const {\n richTextOptions,\n fileImport,\n richClipboard,\n extensions = [],\n ...editorOptions\n } = options;\n\n const preset = createRichTextPreset({\n ...(fileImport !== undefined ? { fileImport } : {}),\n ...(richClipboard !== undefined ? { richClipboard } : {}),\n ...richTextOptions,\n });\n const combinedExtensions = [...preset, ...extensions];\n\n return useTipTapEditor({\n extensions: combinedExtensions,\n ...editorOptions,\n });\n}\n","import { useState, useEffect, useCallback, useRef } from \"react\";\n\nexport interface UseNavigationGuardOptions {\n /** Whether the current form or editor has unsaved changes */\n isDirty: boolean;\n /** Whether guarding is enabled (defaults to true) */\n enabled?: boolean;\n /** Custom navigation function (e.g. router.push from next/navigation or react-router) */\n onNavigate?: (url: string) => void;\n /** Optional callback fired when an internal navigation attempt is intercepted */\n onBlocked?: (url: string) => void;\n}\n\nexport interface UseNavigationGuardReturn {\n /** Whether the unsaved changes confirmation dialog should be displayed */\n showConfirm: boolean;\n /** Setter to manually control the dialog visibility */\n setShowConfirm: (show: boolean) => void;\n /** The target URL that the user attempted to navigate to */\n pendingUrl: string | null;\n /** Proceeds with the blocked navigation and closes the dialog */\n confirmLeave: () => void;\n /** Cancels the navigation attempt and keeps the user on the current page */\n cancelLeave: () => void;\n}\n\n/**\n * Hook to guard against navigation when there are unsaved changes.\n * Intercepts both external unloads (tab closing/refreshing) and internal link clicks.\n */\nexport function useNavigationGuard({\n isDirty,\n enabled = true,\n onNavigate,\n onBlocked,\n}: UseNavigationGuardOptions): UseNavigationGuardReturn {\n const [showConfirm, setShowConfirm] = useState(false);\n const [pendingUrl, setPendingUrl] = useState<string | null>(null);\n\n const onNavigateRef = useRef(onNavigate);\n onNavigateRef.current = onNavigate;\n\n const onBlockedRef = useRef(onBlocked);\n onBlockedRef.current = onBlocked;\n\n // 1. Intercept external navigation / tab close (beforeunload)\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n if (!enabled || !isDirty) return;\n\n const handleBeforeUnload = (e: BeforeUnloadEvent) => {\n e.preventDefault();\n e.returnValue = \"\";\n };\n\n window.addEventListener(\"beforeunload\", handleBeforeUnload);\n return () => {\n window.removeEventListener(\"beforeunload\", handleBeforeUnload);\n };\n }, [enabled, isDirty]);\n\n // 2. Intercept internal anchor link clicks\n useEffect(() => {\n if (typeof document === \"undefined\" || typeof window === \"undefined\")\n return;\n if (!enabled || !isDirty) return;\n\n const handleClick = (e: MouseEvent) => {\n const target = e.target as HTMLElement | null;\n const anchor = target?.closest?.(\"a\");\n\n if (!anchor) return;\n if (anchor.target === \"_blank\") return;\n\n // Only guard internal origins\n const isInternal = anchor.host === window.location.host;\n if (!isInternal) return;\n\n // Ignore navigation to the exact same path & query\n if (\n anchor.pathname === window.location.pathname &&\n anchor.search === window.location.search\n ) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n const href = anchor.href;\n setPendingUrl(href);\n setShowConfirm(true);\n onBlockedRef.current?.(href);\n };\n\n document.addEventListener(\"click\", handleClick, { capture: true });\n return () => {\n document.removeEventListener(\"click\", handleClick, { capture: true });\n };\n }, [enabled, isDirty]);\n\n const confirmLeave = useCallback(() => {\n setShowConfirm(false);\n if (pendingUrl) {\n if (onNavigateRef.current) {\n onNavigateRef.current(pendingUrl);\n } else if (typeof window !== \"undefined\") {\n window.location.href = pendingUrl;\n }\n }\n }, [pendingUrl]);\n\n const cancelLeave = useCallback(() => {\n setShowConfirm(false);\n setPendingUrl(null);\n }, []);\n\n return {\n showConfirm,\n setShowConfirm,\n pendingUrl,\n confirmLeave,\n cancelLeave,\n };\n}\n","import { useState, useCallback, useRef } from \"react\";\n\nexport interface UseDismissGuardOptions {\n /** Whether there are unsaved changes */\n isDirty: boolean;\n /** Whether the dismissal guard is enabled (defaults to true) */\n enabled?: boolean;\n /** Callback fired when dismissal is confirmed or when clean dismissal occurs */\n onDismiss?: () => void;\n}\n\nexport interface UseDismissGuardReturn {\n /** Whether the discard confirmation modal should be shown */\n showConfirm: boolean;\n /** Manually update confirmation modal visibility */\n setShowConfirm: (show: boolean) => void;\n /** Request dismissal - checks isDirty and shows confirm or executes onDismiss */\n requestDismiss: () => void;\n /** Confirm discarding changes and dismiss */\n confirmDismiss: () => void;\n /** Cancel discarding and resume editing */\n cancelDismiss: () => void;\n /** Helper keydown handler intercepting Escape key */\n handleKeyDown: (event: React.KeyboardEvent | KeyboardEvent) => boolean;\n}\n\n/**\n * Hook to guard against closing or exiting an editor/dialog with uncommitted changes.\n */\nexport function useDismissGuard({\n isDirty,\n enabled = true,\n onDismiss,\n}: UseDismissGuardOptions): UseDismissGuardReturn {\n const [showConfirm, setShowConfirm] = useState(false);\n\n const onDismissRef = useRef(onDismiss);\n onDismissRef.current = onDismiss;\n\n const requestDismiss = useCallback(() => {\n if (enabled && isDirty) {\n setShowConfirm(true);\n } else {\n onDismissRef.current?.();\n }\n }, [enabled, isDirty]);\n\n const confirmDismiss = useCallback(() => {\n setShowConfirm(false);\n onDismissRef.current?.();\n }, []);\n\n const cancelDismiss = useCallback(() => {\n setShowConfirm(false);\n }, []);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent | KeyboardEvent) => {\n if (event.key === \"Escape\") {\n if (event.defaultPrevented) return false;\n event.preventDefault();\n requestDismiss();\n return true;\n }\n return false;\n },\n [requestDismiss],\n );\n\n return {\n showConfirm,\n setShowConfirm,\n requestDismiss,\n confirmDismiss,\n cancelDismiss,\n handleKeyDown,\n };\n}\n","import { useSyncExternalStore, useRef, useCallback } from \"react\";\nimport {\n HistoryManager,\n HistoryState,\n Command,\n createHistoryManager,\n HistoryManagerOptions,\n} from \"@pixerate/editor\";\n\nexport interface UseHistoryResult extends HistoryState {\n manager: HistoryManager;\n undo: () => boolean;\n redo: () => boolean;\n clear: () => void;\n execute: (command: Command) => void;\n executeMerged: (command: Command, options?: { windowMs?: number }) => void;\n batch: (name: string, fn: () => void) => void;\n}\n\n/**\n * React hook that subscribes to a HistoryManager instance.\n * Accepts an existing HistoryManager or config options to create an instance\n * (options are read on first render only).\n */\nexport function useHistory(\n managerOrOptions?: HistoryManager | HistoryManagerOptions,\n): UseHistoryResult {\n // Options are read once, so passing an inline options object does not\n // create a new manager (and wipe history) on every render.\n const ownManagerRef = useRef<HistoryManager | null>(null);\n let manager: HistoryManager;\n if (managerOrOptions instanceof HistoryManager) {\n manager = managerOrOptions;\n } else {\n ownManagerRef.current ??= createHistoryManager(managerOrOptions);\n manager = ownManagerRef.current;\n }\n\n const state = useSyncExternalStore(\n useCallback(\n (onStoreChange) => manager.subscribe(onStoreChange),\n [manager],\n ),\n () => manager.getState(),\n () => manager.getState(),\n );\n\n const undo = useCallback(() => manager.undo(), [manager]);\n const redo = useCallback(() => manager.redo(), [manager]);\n const clear = useCallback(() => manager.clear(), [manager]);\n const execute = useCallback(\n (cmd: Command) => manager.execute(cmd),\n [manager],\n );\n const executeMerged = useCallback(\n (cmd: Command, opts?: { windowMs?: number }) =>\n manager.executeMerged(cmd, opts),\n [manager],\n );\n const batch = useCallback(\n (name: string, fn: () => void) => manager.batch(name, fn),\n [manager],\n );\n\n return {\n ...state,\n manager,\n undo,\n redo,\n clear,\n execute,\n executeMerged,\n batch,\n };\n}\n","import { useEffect } from \"react\";\nimport { HistoryManager } from \"@pixerate/editor\";\n\nexport interface HistoryShortcutsOptions {\n /**\n * Whether the keyboard shortcuts are enabled. Defaults to true.\n */\n enabled?: boolean;\n /**\n * Target element or window to listen on. Defaults to window.\n */\n target?: Window | HTMLElement | null;\n /**\n * When true (default), shortcuts will not trigger if an <input>, <textarea>,\n * or [contenteditable] element is currently active / focused.\n */\n ignoreEditableElements?: boolean;\n}\n\n/**\n * Attaches keyboard listeners for Undo (Mod+Z) and Redo (Mod+Shift+Z / Mod+Y).\n * Automatically guards against active text inputs and contenteditable editors.\n */\nexport function useHistoryShortcuts(\n manager: HistoryManager,\n options: HistoryShortcutsOptions = {},\n): void {\n const {\n enabled = true,\n target,\n ignoreEditableElements = true,\n } = options;\n\n useEffect(() => {\n if (!enabled) return;\n\n const eventTarget = target ?? (typeof window !== \"undefined\" ? window : null);\n if (!eventTarget) return;\n\n const handleKeyDown = (event: Event) => {\n const e = event as KeyboardEvent;\n const isMac =\n typeof navigator !== \"undefined\" &&\n /Mac|iPod|iPhone|iPad/.test(navigator.platform || navigator.userAgent);\n const modifier = isMac ? e.metaKey : e.ctrlKey;\n\n if (!modifier) return;\n\n if (ignoreEditableElements && typeof document !== \"undefined\") {\n const targetEl = (e.target || document.activeElement) as HTMLElement | null;\n if (targetEl && targetEl.tagName) {\n const tagName = targetEl.tagName.toLowerCase();\n const isInput = tagName === \"input\" || tagName === \"textarea\";\n const isContentEditable =\n targetEl.isContentEditable ||\n targetEl.getAttribute?.(\"contenteditable\") === \"true\";\n if (isInput || isContentEditable) {\n return;\n }\n }\n }\n\n const key = e.key.toLowerCase();\n\n // Undo: Mod+Z (without Shift)\n if (key === \"z\" && !e.shiftKey) {\n if (manager.getState().canUndo) {\n e.preventDefault();\n manager.undo();\n }\n return;\n }\n\n // Redo: Mod+Shift+Z or (on non-Mac) Mod+Y\n const isRedoKey =\n (key === \"z\" && e.shiftKey) || (!isMac && key === \"y\" && !e.shiftKey);\n\n if (isRedoKey) {\n if (manager.getState().canRedo) {\n e.preventDefault();\n manager.redo();\n }\n }\n };\n\n eventTarget.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n eventTarget.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [manager, enabled, target, ignoreEditableElements]);\n}\n","import { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport {\n FileImportController,\n type FileImportControllerOptions,\n type FileImportState,\n} from \"@pixerate/editor\";\n\nexport interface UseFileImportResult extends FileImportState {\n /** Value for `<input type=\"file\" accept={…}>`. */\n accept: string;\n /** Opens the browser file picker and imports the chosen files at the selection. */\n openFilePicker: FileImportController[\"openFilePicker\"];\n /** Imports files (e.g. from your own `<input>` or drop zone) at `at` or the selection. */\n importFiles: FileImportController[\"importFiles\"];\n}\n\n/**\n * Imports markdown, HTML, plain-text and RTF files (or anything registered\n * with `registerImportAdapter` for the `document` target) into an editor.\n * Pair it with `useEditor({ fileImport: true })` to also accept dropped files.\n */\nexport function useFileImport(\n editor: Editor | null | undefined,\n options: FileImportControllerOptions = {},\n): UseFileImportResult {\n const editorRef = useRef(editor);\n editorRef.current = editor;\n\n const controller = useMemo(\n () =>\n new FileImportController(() => {\n const current = editorRef.current;\n return current && !current.isDestroyed ? current : null;\n }, options),\n [],\n );\n\n useEffect(() => {\n controller.setOptions(options);\n });\n\n const state = useSyncExternalStore(controller.subscribe, controller.getState, controller.getState);\n\n return {\n ...state,\n accept: controller.accept,\n openFilePicker: controller.openFilePicker,\n importFiles: controller.importFiles,\n };\n}\n","import { useEffect } from \"react\";\nimport type { AgentToolProvider, ToolRegistry } from \"@pixerate/editor/agent\";\n\n/**\n * Registers a tool provider with a `ToolRegistry` while the component is\n * mounted and unregisters it on unmount (the registry then announces the\n * change through `onListChanged`).\n *\n * Memoize the provider (e.g. `useMemo(() => createRichTextToolProvider(editor,\n * { id }), [editor])`): a new provider object re-registers it. Pass `null`\n * while it isn't ready.\n */\nexport function useAgentToolProvider(\n registry: ToolRegistry | null | undefined,\n provider: AgentToolProvider | null | undefined,\n): void {\n useEffect(() => {\n if (!registry || !provider) return;\n return registry.register(provider);\n }, [registry, provider]);\n}\n","import React from \"react\";\nimport {\n EditorContent as TipTapEditorContent,\n EditorContentProps as TipTapEditorContentProps,\n} from \"@tiptap/react\";\n\nexport interface EditorContentProps extends TipTapEditorContentProps {\n className?: string;\n}\n\nexport const EditorContent: React.FC<EditorContentProps> = ({\n className,\n editor,\n ...props\n}) => {\n return (\n <div className={className}>\n <TipTapEditorContent editor={editor} {...props} />\n </div>\n );\n};\n","import React, { useEffect, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n BubbleMenuPlugin,\n type BubbleMenuPluginProps,\n} from \"@tiptap/extension-bubble-menu\";\nimport type { Editor } from \"@tiptap/core\";\n\nexport interface BubbleMenuProps {\n editor: Editor | null;\n className?: string;\n children: React.ReactNode;\n tippyOptions?: BubbleMenuPluginProps[\"tippyOptions\"];\n shouldShow?: BubbleMenuPluginProps[\"shouldShow\"];\n pluginKey?: BubbleMenuPluginProps[\"pluginKey\"];\n updateDelay?: BubbleMenuPluginProps[\"updateDelay\"];\n}\n\nexport const BubbleMenu: React.FC<BubbleMenuProps> = ({\n editor,\n className = \"flex items-center gap-1 bg-popover text-popover-foreground border shadow-md rounded-md p-1\",\n children,\n tippyOptions = { duration: 100 },\n shouldShow = null,\n pluginKey = \"bubbleMenu\",\n updateDelay,\n}) => {\n const menuEl = useRef<HTMLDivElement | null>(null);\n const [mounted, setMounted] = useState(false);\n\n if (!menuEl.current && typeof document !== \"undefined\") {\n menuEl.current = document.createElement(\"div\");\n }\n\n useEffect(() => {\n if (!editor || !menuEl.current || editor.isDestroyed) {\n return;\n }\n\n const element = menuEl.current;\n element.className = className;\n\n const plugin = BubbleMenuPlugin({\n editor,\n element,\n pluginKey,\n tippyOptions,\n shouldShow,\n updateDelay,\n });\n\n editor.registerPlugin(plugin);\n setMounted(true);\n\n return () => {\n setMounted(false);\n editor.unregisterPlugin(pluginKey);\n if (element.parentNode) {\n element.parentNode.removeChild(element);\n }\n };\n }, [editor, className, pluginKey]);\n\n if (!editor || !menuEl.current || !mounted) {\n return null;\n }\n\n return createPortal(children, menuEl.current);\n};\n","import React, { useMemo } from \"react\";\nimport {\n evaluatePromptTokens,\n resolveTemplates,\n Template,\n ColorGradient,\n PromptValues,\n} from \"@pixerate/editor\";\n\nexport interface TemplateRendererProps {\n /** Raw prompt or text string to render */\n content: string;\n /** Available templates for recursive resolution and custom coloring */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether to resolve nested templates recursively before displaying */\n resolve?: boolean;\n /** Template version bindings used when `resolve` is set */\n bindings?: Record<string, string>;\n /**\n * Variable values. When set, variables show their value (or default),\n * sections whose condition fails are hidden, and section tags are dropped.\n */\n values?: PromptValues;\n /** Custom class name for the wrapper */\n className?: string;\n /** Click callback for template badges */\n onTemplateClick?: (templateName: string) => void;\n /** Click callback for variable badges */\n onVariableClick?: (variableName: string) => void;\n}\n\nconst CONDITIONAL_PREFIX = { if: \"?\", unless: \"!\", end: \"/\" } as const;\n\nexport const TemplateRenderer: React.FC<TemplateRendererProps> = ({\n content,\n templates = [],\n templateColorMap,\n resolve = false,\n bindings,\n values,\n className = \"font-mono text-sm leading-relaxed whitespace-pre-wrap break-words\",\n onTemplateClick,\n onVariableClick,\n}) => {\n const displayText = useMemo(() => {\n if (!resolve || templates.length === 0) return content;\n return resolveTemplates(content, templates, { bindings });\n }, [content, templates, resolve, bindings]);\n\n const tokens = useMemo(() => {\n return evaluatePromptTokens(displayText, values);\n }, [displayText, values]);\n\n return (\n <div className={className}>\n {tokens.map((token, index) => {\n if (token.type === \"template\") {\n const colors = templateColorMap?.get(token.value) || {\n from: \"#f43f5e\",\n to: \"#8b5cf6\",\n };\n const style = {\n \"--color-from\": colors.from,\n \"--color-to\": colors.to,\n } as React.CSSProperties;\n\n return (\n <span\n key={index}\n style={style}\n onClick={() => onTemplateClick?.(token.value)}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all\"\n title={`Template: ${token.value}`}\n >\n {`{{${token.value}}}`}\n </span>\n );\n }\n\n if (token.type === \"variable\") {\n const details = [\n `Variable: ${token.value}`,\n token.description,\n token.defaultValue !== undefined\n ? `Default: ${token.defaultValue || \"(empty)\"}`\n : undefined,\n ]\n .filter(Boolean)\n .join(\"\\n\");\n\n if (token.resolvedValue !== undefined) {\n return (\n <span\n key={index}\n onClick={() => onVariableClick?.(token.value)}\n data-variable={token.value}\n data-value-source={token.valueSource}\n className={\n token.valueSource === \"value\"\n ? \"inline px-1 mx-0.5 rounded-md bg-emerald-400/15 text-emerald-700 dark:text-emerald-300 border-b border-emerald-400/60 cursor-pointer\"\n : \"inline px-1 mx-0.5 rounded-md bg-violet-400/10 text-violet-600 dark:text-violet-300 italic border-b border-dashed border-violet-400/60 cursor-pointer\"\n }\n title={details}\n >\n {token.resolvedValue}\n </span>\n );\n }\n\n return (\n <span\n key={index}\n onClick={() => onVariableClick?.(token.value)}\n data-variable={token.value}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 dark:text-violet-300 hover:brightness-110 cursor-pointer transition-all\"\n title={details}\n >\n {`{${token.value}`}\n {token.defaultValue !== undefined && (\n <span className=\"opacity-60\">{`|${token.defaultValue}`}</span>\n )}\n {\"}\"}\n </span>\n );\n }\n\n if (token.type === \"conditional\" && token.conditional) {\n return (\n <span\n key={index}\n data-conditional={token.conditional}\n className=\"inline-flex items-center px-1 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-amber-400/40 bg-amber-400/15 text-amber-700 dark:text-amber-300\"\n title={\n token.conditional === \"end\"\n ? `End of section: ${token.value}`\n : token.conditional === \"if\"\n ? `Shown when \"${token.value}\" has a value`\n : `Shown when \"${token.value}\" is empty`\n }\n >\n {`{${CONDITIONAL_PREFIX[token.conditional]}${token.value}}`}\n </span>\n );\n }\n\n if (token.type === \"instruction\") {\n return (\n <span\n key={index}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600 dark:text-rose-300\"\n title={`Instruction: ${token.value}`}\n >\n {`__${token.value}__`}\n </span>\n );\n }\n\n return <span key={index}>{token.value}</span>;\n })}\n </div>\n );\n};\n","import React, { useId, useMemo, useState } from \"react\";\nimport {\n compactVariableValues,\n getVariableFormFields,\n PromptValues,\n Template,\n VariableFormField,\n} from \"@pixerate/editor\";\n\nexport interface VariableFormProps {\n /** Prompt whose variables become form fields */\n content: string;\n /** Templates searched recursively for further variables */\n templates?: Template[];\n /** Template version bindings */\n bindings?: Record<string, string>;\n /** Entered text per variable (controlled). Omit to let the form keep its own state. */\n values?: Record<string, string>;\n /** Initial entered text when uncontrolled */\n defaultValues?: Record<string, string>;\n /**\n * Called on every edit with the values to resolve with (blank fields\n * dropped so defaults apply) and the raw entered text.\n */\n onChange?: (values: PromptValues, entered: Record<string, string>) => void;\n /** Custom class name for the wrapper */\n className?: string;\n}\n\n/**\n * Renders one input per prompt variable: labelled with its description,\n * using its default as the placeholder. Variables only used by `{?name}`\n * conditions render as checkboxes.\n */\nexport const VariableForm: React.FC<VariableFormProps> = ({\n content,\n templates,\n bindings,\n values,\n defaultValues,\n onChange,\n className = \"flex flex-col gap-3 text-sm\",\n}) => {\n const idPrefix = useId();\n const [internal, setInternal] = useState<Record<string, string>>(\n () => defaultValues ?? {},\n );\n const entered = values ?? internal;\n\n const fields = useMemo<VariableFormField[]>(\n () => getVariableFormFields(content, { templates, bindings }),\n [content, templates, bindings],\n );\n\n const update = (name: string, value: string) => {\n const next = { ...entered, [name]: value };\n if (values === undefined) setInternal(next);\n onChange?.(compactVariableValues(next), next);\n };\n\n if (fields.length === 0) return null;\n\n return (\n <form className={className} onSubmit={(event) => event.preventDefault()}>\n {fields.map((field) => {\n const id = `${idPrefix}-${field.name}`;\n if (field.conditionOnly) {\n return (\n <label\n key={field.name}\n htmlFor={id}\n className=\"flex items-center gap-2\"\n data-variable-field={field.name}\n >\n <input\n id={id}\n name={field.name}\n type=\"checkbox\"\n checked={(entered[field.name] ?? \"\") !== \"\"}\n onChange={(event) =>\n update(field.name, event.target.checked ? \"true\" : \"\")\n }\n />\n <span>{field.label}</span>\n </label>\n );\n }\n return (\n <label\n key={field.name}\n htmlFor={id}\n className=\"flex flex-col gap-1\"\n data-variable-field={field.name}\n >\n <span className=\"font-medium\">\n {field.label}\n {field.required && (\n <span className=\"text-rose-500\" aria-hidden=\"true\">\n {\" *\"}\n </span>\n )}\n </span>\n <input\n id={id}\n name={field.name}\n type=\"text\"\n value={entered[field.name] ?? \"\"}\n placeholder={field.placeholder}\n aria-required={field.required || undefined}\n onChange={(event) => update(field.name, event.target.value)}\n className=\"px-2 py-1 rounded-md border border-violet-400/40 bg-transparent\"\n />\n </label>\n );\n })}\n </form>\n );\n};\n","import { useMemo, useSyncExternalStore } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport { createOutlineStore, type OutlineSnapshot } from \"@pixerate/editor\";\n\nexport type { OutlineHeading, OutlineSnapshot, OutlineTreeItem } from \"@pixerate/editor\";\n\n/**\n * Subscribes to an editor's heading outline. Returns the headings (flat and\n * nested) and the id of the heading whose section contains the selection.\n * Re-renders only when the outline or the active heading changes.\n *\n * Install the `Outline` extension (`richTextOptions: { outline: true }`) for\n * stable heading ids; without it, headings are still listed.\n */\nexport function useOutline(editor: Editor | null | undefined): OutlineSnapshot {\n // The store only listens to the editor while subscribed, so it needs no\n // explicit cleanup (and survives StrictMode's double effects).\n const store = useMemo(() => createOutlineStore(editor), [editor]);\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n}\n","import React from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport { navigateToHeading, type OutlineHeading } from \"@pixerate/editor\";\nimport { useOutline } from \"../hooks/useOutline\";\n\nexport interface OutlinePanelProps {\n editor: Editor | null;\n /** Heading shown above the list. Pass `null` to hide it. */\n title?: React.ReactNode;\n /** Content shown when the document has no headings. */\n emptyState?: React.ReactNode;\n /** Deepest heading level listed. Defaults to 6. */\n maxLevel?: number;\n /** Whether clicking an entry focuses the editor. Defaults to `true`. */\n focusOnNavigate?: boolean;\n /** Custom class name for the wrapper. */\n className?: string;\n /** Class name for each entry button. */\n itemClassName?: string;\n /** Class name added to the entry of the section containing the selection. */\n activeItemClassName?: string;\n /** Called after navigating to a heading. */\n onNavigate?: (heading: OutlineHeading) => void;\n}\n\n/**\n * Navigation sidebar listing the document's headings (Word's Navigation pane).\n * Clicking an entry moves the caret to that heading; the entry for the\n * section containing the selection is highlighted.\n */\nexport const OutlinePanel: React.FC<OutlinePanelProps> = ({\n editor,\n title = \"Outline\",\n emptyState = \"Add headings to see the outline.\",\n maxLevel = 6,\n focusOnNavigate = true,\n className = \"flex flex-col gap-1 text-sm\",\n itemClassName = \"w-full truncate rounded px-2 py-1 text-left hover:bg-black/5\",\n activeItemClassName = \"font-semibold bg-black/5\",\n onNavigate,\n}) => {\n const { headings, activeId } = useOutline(editor);\n const visible = headings.filter((h) => h.level <= maxLevel);\n\n return (\n <nav className={className} aria-label=\"Document outline\" data-outline-panel=\"\">\n {title != null && <div className=\"pixerate-outline-title\">{title}</div>}\n {visible.length === 0 ? (\n <div className=\"pixerate-outline-empty\">{emptyState}</div>\n ) : (\n <ul role=\"list\" style={{ listStyle: \"none\", margin: 0, padding: 0 }}>\n {visible.map((heading) => {\n const active = heading.id === activeId;\n return (\n <li key={heading.id} data-level={heading.level}>\n <button\n type=\"button\"\n className={active ? `${itemClassName} ${activeItemClassName}` : itemClassName}\n style={{ paddingLeft: `${0.5 + heading.depth * 0.75}rem` }}\n aria-current={active ? \"location\" : undefined}\n data-heading-id={heading.id}\n onClick={() => {\n if (!editor) return;\n if (navigateToHeading(editor, heading, { focus: focusOnNavigate })) {\n onNavigate?.(heading);\n }\n }}\n >\n {heading.text || \"Untitled\"}\n </button>\n </li>\n );\n })}\n </ul>\n )}\n </nav>\n );\n};\n","export * from \"./hooks/usePromptEditor\";\nexport * from \"./hooks/useEditor\";\nexport * from \"./hooks/useNavigationGuard\";\nexport * from \"./hooks/useDismissGuard\";\nexport * from \"./hooks/useHistory\";\nexport * from \"./hooks/useHistoryShortcuts\";\nexport * from \"./hooks/useFileImport\";\nexport * from \"./hooks/useAgentToolProvider\";\nexport * from \"./components/EditorContent\";\nexport * from \"./components/BubbleMenu\";\nexport * from \"./components/TemplateRenderer\";\nexport * from \"./components/VariableForm\";\nexport * from \"./hooks/useOutline\";\nexport * from \"./components/OutlinePanel\";\n\n// Re-export core types for easy consumer access\nexport {\n DirtyTracker,\n createDirtyTracker,\n defaultIsEqual,\n HistoryManager,\n createHistoryManager,\n} from \"@pixerate/editor\";\nexport type {\n Template,\n TemplateVersion,\n Token,\n TokenType,\n ColorGradient,\n RichTextPresetOptions,\n DirtyTrackerOptions,\n Command,\n HistoryState,\n HistoryManagerOptions,\n} from \"@pixerate/editor\";\nexport type {\n PromptValues,\n PromptDiagnostic,\n VariableFormField,\n} from \"@pixerate/editor\";\n\nexport * from \"./spreadsheet\";\nexport * from \"./slots\";\nexport * from \"./image-editor\";\nexport * from \"./review\";\n","import React, { createContext, useContext, useMemo } from 'react';\nimport type {\n\tButtonSlotProps,\n\tEditorSlotsMap,\n\tNodeHeaderSlotProps,\n\tTooltipSlotProps\n} from '@pixerate/editor';\n\nconst defaultSlots: EditorSlotsMap = {\n\tButton: (props: ButtonSlotProps) => (\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tclassName={`pixerate-btn ${props.className || ''}`}\n\t\t\tonClick={props.onClick}\n\t\t\tdisabled={props.disabled}\n\t\t>\n\t\t\t{props.children}\n\t\t</button>\n\t),\n\tTooltip: (props: TooltipSlotProps) => (\n\t\t<div className={`pixerate-tooltip-container ${props.className || ''}`} title={String(props.content)}>\n\t\t\t{props.children}\n\t\t</div>\n\t),\n\tNodeHeader: (props: NodeHeaderSlotProps) => (\n\t\t<div className={`pixerate-node-header flex items-center justify-between ${props.className || ''}`}>\n\t\t\t<div className=\"flex items-center gap-2\">\n\t\t\t\t{props.icon}\n\t\t\t\t<span className=\"font-semibold\">{props.title}</span>\n\t\t\t</div>\n\t\t\t{props.onClose && (\n\t\t\t\t<button type=\"button\" onClick={props.onClose} className=\"opacity-70 hover:opacity-100\">\n\t\t\t\t\t×\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</div>\n\t)\n};\n\nconst EditorSlotsContext = createContext<EditorSlotsMap>(defaultSlots);\n\nexport interface EditorSlotsProviderProps {\n\tslots?: Partial<EditorSlotsMap>;\n\tchildren: React.ReactNode;\n}\n\n/**\n * Context provider allowing consumers to inject custom design system components into the editor.\n */\nexport function EditorSlotsProvider({ slots, children }: EditorSlotsProviderProps) {\n\tconst mergedSlots = useMemo(() => ({ ...defaultSlots, ...slots }), [slots]);\n\n\treturn (\n\t\t<EditorSlotsContext.Provider value={mergedSlots}>\n\t\t\t{children}\n\t\t</EditorSlotsContext.Provider>\n\t);\n}\n\n/**\n * Hook to access injected design system slots.\n */\nexport function useEditorSlots(): EditorSlotsMap {\n\treturn useContext(EditorSlotsContext);\n}\n","import { useCallback, useMemo, useSyncExternalStore } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport {\n getCommentStore,\n getTrackChangesStore,\n type CommentStore,\n type CommentStoreSnapshot,\n type TrackChangesSnapshot,\n type TrackedChange,\n} from \"@pixerate/editor\";\n\nconst EMPTY_COMMENTS: CommentStoreSnapshot = Object.freeze({\n threads: [],\n activeThreadId: null,\n}) as CommentStoreSnapshot;\n\nconst EMPTY_TRACK_CHANGES: TrackChangesSnapshot = Object.freeze({\n enabled: false,\n author: { id: \"anonymous\", name: \"Anonymous\" },\n changes: [],\n currentChangeId: null,\n}) as TrackChangesSnapshot;\n\nconst noopUnsubscribe = () => {};\n\nfunction isCommentStore(value: unknown): value is CommentStore {\n return (\n !!value &&\n typeof (value as CommentStore).getSnapshot === \"function\" &&\n typeof (value as CommentStore).createThread === \"function\"\n );\n}\n\nexport interface UseCommentsResult extends CommentStoreSnapshot {\n store: CommentStore | null;\n}\n\n/**\n * Subscribes to a comment store: pass the store itself, or an editor using\n * the `Comments` extension (`null` while the editor is being created).\n */\nexport function useComments(\n source: Editor | CommentStore | null | undefined,\n): UseCommentsResult {\n const store = isCommentStore(source) ? source : getCommentStore(source as Editor | null);\n const subscribe = useCallback(\n (onChange: () => void) => (store ? store.subscribe(() => onChange()) : noopUnsubscribe),\n [store],\n );\n const getSnapshot = () => store?.getSnapshot() ?? EMPTY_COMMENTS;\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n return useMemo(() => ({ ...snapshot, store }), [snapshot, store]);\n}\n\nexport interface UseTrackChangesResult extends TrackChangesSnapshot {\n currentChange: TrackedChange | null;\n setEnabled: (enabled: boolean) => void;\n toggle: () => void;\n accept: (id: string) => void;\n reject: (id: string) => void;\n acceptAll: () => void;\n rejectAll: () => void;\n next: () => void;\n previous: () => void;\n}\n\n/**\n * Subscribes to the tracked-change state of an editor using the\n * `TrackChanges` extension and exposes its commands.\n */\nexport function useTrackChanges(editor: Editor | null | undefined): UseTrackChangesResult {\n const store = getTrackChangesStore(editor ?? null);\n const subscribe = useCallback(\n (onChange: () => void) => (store ? store.subscribe(() => onChange()) : noopUnsubscribe),\n [store],\n );\n const getSnapshot = () => store?.getSnapshot() ?? EMPTY_TRACK_CHANGES;\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return useMemo(() => {\n const run = (fn: (e: Editor) => void) => () => {\n if (editor && !editor.isDestroyed) fn(editor);\n };\n return {\n ...snapshot,\n currentChange:\n snapshot.changes.find((c) => c.id === snapshot.currentChangeId) ?? null,\n setEnabled: (enabled: boolean) => run((e) => e.commands.setTrackChanges(enabled))(),\n toggle: run((e) => e.commands.toggleTrackChanges()),\n accept: (id: string) => run((e) => e.commands.acceptChange(id))(),\n reject: (id: string) => run((e) => e.commands.rejectChange(id))(),\n acceptAll: run((e) => e.commands.acceptAllChanges()),\n rejectAll: run((e) => e.commands.rejectAllChanges()),\n next: run((e) => e.chain().focus().selectNextChange().run()),\n previous: run((e) => e.chain().focus().selectPreviousChange().run()),\n };\n }, [snapshot, editor]);\n}\n","import React, { useState } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport {\n formatReviewTime,\n getCommentAuthor,\n type CommentStore,\n type CommentThread,\n type ReviewAuthor,\n} from \"@pixerate/editor\";\nimport { useComments } from \"./useReview\";\n\nexport interface CommentsPanelProps {\n editor: Editor | null;\n /** Defaults to the store of the editor's `Comments` extension. */\n store?: CommentStore;\n /** Author of replies. Defaults to the `Comments` extension's author. */\n author?: ReviewAuthor;\n /** Initially show resolved threads. */\n showResolved?: boolean;\n className?: string;\n formatTime?: (timestamp: number) => string;\n emptyMessage?: string;\n}\n\nconst buttonClass =\n \"rounded px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50\";\nconst primaryButtonClass =\n \"rounded px-2 py-1 text-xs bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-50\";\nconst textareaClass =\n \"w-full resize-y rounded-md border border-input bg-background p-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary\";\n\n/**\n * Lists comment threads with reply, resolve and delete actions. Clicking a\n * thread selects its text in the editor. Threads with an empty body are\n * drafts (e.g. created by `CommentButton`) and show a compose box.\n */\nexport const CommentsPanel: React.FC<CommentsPanelProps> = ({\n editor,\n store: storeProp,\n author: authorProp,\n showResolved: showResolvedInitial = false,\n className = \"flex flex-col gap-2 text-sm text-foreground\",\n formatTime = (t) => formatReviewTime(t),\n emptyMessage = \"No comments yet. Select text and add a comment.\",\n}) => {\n const { threads, activeThreadId, store } = useComments(storeProp ?? editor);\n const [showResolved, setShowResolved] = useState(showResolvedInitial);\n const author = authorProp ?? getCommentAuthor(editor) ?? { id: \"anonymous\", name: \"Anonymous\" };\n\n const visible = threads.filter((t) => showResolved || !t.resolved);\n const resolvedCount = threads.filter((t) => t.resolved).length;\n\n return (\n <aside className={className} aria-label=\"Comments\">\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"text-xs font-medium text-muted-foreground\">\n {threads.length - resolvedCount} open\n {resolvedCount > 0 ? ` · ${resolvedCount} resolved` : \"\"}\n </span>\n {resolvedCount > 0 && (\n <button\n type=\"button\"\n className={buttonClass}\n aria-pressed={showResolved}\n onClick={() => setShowResolved((v) => !v)}\n >\n {showResolved ? \"Hide resolved\" : \"Show resolved\"}\n </button>\n )}\n </div>\n {visible.length === 0 ? (\n <p className=\"text-xs text-muted-foreground\">{emptyMessage}</p>\n ) : (\n <ul className=\"flex flex-col gap-2\" role=\"list\">\n {visible.map((thread) => (\n <CommentThreadCard\n key={thread.id}\n thread={thread}\n active={thread.id === activeThreadId}\n editor={editor}\n store={store}\n author={author}\n formatTime={formatTime}\n />\n ))}\n </ul>\n )}\n </aside>\n );\n};\n\ninterface CommentThreadCardProps {\n thread: CommentThread;\n active: boolean;\n editor: Editor | null;\n store: CommentStore | null;\n author: ReviewAuthor;\n formatTime: (timestamp: number) => string;\n}\n\nconst CommentThreadCard: React.FC<CommentThreadCardProps> = ({\n thread,\n active,\n editor,\n store,\n author,\n formatTime,\n}) => {\n const [draft, setDraft] = useState(\"\");\n const isDraft = thread.body === \"\";\n const quote = thread.anchor?.quote ?? thread.lastQuote ?? \"\";\n const live = editor && !editor.isDestroyed ? editor : null;\n\n const focus = () => {\n if (!active) {\n if (live && !thread.orphaned) live.commands.focusComment(thread.id);\n else store?.setActiveThread(thread.id);\n }\n };\n const remove = () => {\n if (live) live.commands.deleteComment(thread.id);\n else store?.deleteThread(thread.id);\n };\n const setResolved = (resolved: boolean) => {\n if (live) live.commands.resolveComment(thread.id, resolved);\n else store?.resolveThread(thread.id, resolved, author);\n };\n const submit = () => {\n const body = draft.trim();\n if (!body || !store) return;\n if (isDraft) store.editComment(thread.id, body);\n else store.addReply(thread.id, { body, author });\n setDraft(\"\");\n };\n const stop = (e: React.SyntheticEvent) => e.stopPropagation();\n\n return (\n <li\n className={`flex flex-col gap-2 rounded-md border bg-background p-3 cursor-pointer ${\n active ? \"border-primary ring-1 ring-primary\" : \"border-border\"\n } ${thread.resolved ? \"opacity-70\" : \"\"}`}\n data-thread-id={thread.id}\n data-active={active || undefined}\n aria-current={active || undefined}\n tabIndex={0}\n onClick={focus}\n onKeyDown={(e) => {\n if (e.target === e.currentTarget && (e.key === \"Enter\" || e.key === \" \")) {\n e.preventDefault();\n focus();\n }\n }}\n >\n <div className=\"flex items-baseline justify-between gap-2\">\n <span className=\"font-medium\">{thread.author.name}</span>\n <span className=\"text-xs text-muted-foreground\">{formatTime(thread.createdAt)}</span>\n </div>\n {quote && (\n <blockquote className=\"border-l-2 border-border pl-2 text-xs text-muted-foreground line-clamp-2\">\n {quote}\n </blockquote>\n )}\n {thread.orphaned && (\n <span className=\"text-xs text-destructive\">The commented text was deleted.</span>\n )}\n {thread.resolved && <span className=\"text-xs text-muted-foreground\">Resolved</span>}\n {!isDraft && <p className=\"whitespace-pre-wrap break-words\">{thread.body}</p>}\n {thread.replies.length > 0 && (\n <ul className=\"flex flex-col gap-2 border-l border-border pl-3\" role=\"list\">\n {thread.replies.map((reply) => (\n <li key={reply.id} className=\"flex flex-col gap-0.5\" data-reply-id={reply.id}>\n <span className=\"text-xs\">\n <span className=\"font-medium\">{reply.author.name}</span>{\" \"}\n <span className=\"text-muted-foreground\">{formatTime(reply.createdAt)}</span>\n </span>\n <p className=\"whitespace-pre-wrap break-words\">{reply.body}</p>\n </li>\n ))}\n </ul>\n )}\n {(active || isDraft) && !thread.resolved && (\n <div className=\"flex flex-col gap-1\" onClick={stop}>\n <textarea\n className={textareaClass}\n rows={2}\n value={draft}\n aria-label={isDraft ? \"Comment\" : \"Reply\"}\n placeholder={isDraft ? \"Add a comment…\" : \"Reply…\"}\n autoFocus={isDraft}\n onChange={(e) => setDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n e.preventDefault();\n submit();\n }\n }}\n />\n <div className=\"flex justify-end gap-1\">\n {isDraft && (\n <button type=\"button\" className={buttonClass} onClick={remove}>\n Cancel\n </button>\n )}\n <button\n type=\"button\"\n className={primaryButtonClass}\n disabled={!draft.trim()}\n onClick={submit}\n >\n {isDraft ? \"Comment\" : \"Reply\"}\n </button>\n </div>\n </div>\n )}\n {!isDraft && (\n <div className=\"flex justify-end gap-1\" onClick={stop}>\n <button type=\"button\" className={buttonClass} onClick={() => setResolved(!thread.resolved)}>\n {thread.resolved ? \"Reopen\" : \"Resolve\"}\n </button>\n <button\n type=\"button\"\n className={`${buttonClass} hover:text-destructive`}\n onClick={remove}\n >\n Delete\n </button>\n </div>\n )}\n </li>\n );\n};\n","import React from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport { useTrackChanges } from \"./useReview\";\n\nexport interface ReviewToolbarProps {\n editor: Editor | null;\n className?: string;\n /**\n * Show the current change's author and description (e.g. \"Alice: Formatted:\n * Bold\"). Defaults to `true`.\n */\n showDescription?: boolean;\n /** Class of the description label. */\n descriptionClassName?: string;\n}\n\nconst defaultDescriptionClass = \"max-w-[16rem] truncate px-1 text-xs text-muted-foreground\";\n\nconst buttonClass =\n \"rounded px-2 py-1 text-xs text-foreground hover:bg-muted disabled:opacity-40 disabled:hover:bg-transparent\";\n\n/**\n * Toolbar for tracked changes: toggle tracking, step through changes\n * (insertions, deletions, formatting and block changes, with a description\n * of the current one), and accept or reject the current change or all\n * changes.\n */\nexport const ReviewToolbar: React.FC<ReviewToolbarProps> = ({\n editor,\n className = \"flex flex-wrap items-center gap-1 rounded-md border border-border bg-background p-1 text-sm\",\n showDescription = true,\n descriptionClassName = defaultDescriptionClass,\n}) => {\n const review = useTrackChanges(editor);\n const count = review.changes.length;\n const current = review.currentChange;\n const index = current ? review.changes.findIndex((c) => c.id === current.id) + 1 : 0;\n\n return (\n <div className={className} role=\"toolbar\" aria-label=\"Review\">\n <button\n type=\"button\"\n className={`${buttonClass} ${review.enabled ? \"bg-primary/10 text-primary\" : \"\"}`}\n aria-pressed={review.enabled}\n disabled={!editor}\n onClick={review.toggle}\n >\n {review.enabled ? \"Tracking on\" : \"Track changes\"}\n </button>\n <span className=\"mx-1 h-4 w-px bg-border\" aria-hidden=\"true\" />\n <button\n type=\"button\"\n className={buttonClass}\n aria-label=\"Previous change\"\n disabled={count === 0}\n onClick={review.previous}\n >\n ‹\n </button>\n <span className=\"min-w-[4rem] text-center text-xs text-muted-foreground\" aria-live=\"polite\">\n {count === 0 ? \"No changes\" : current ? `${index} of ${count}` : `${count} changes`}\n </span>\n <button\n type=\"button\"\n className={buttonClass}\n aria-label=\"Next change\"\n disabled={count === 0}\n onClick={review.next}\n >\n ›\n </button>\n {showDescription && current && (\n <span\n className={descriptionClassName}\n data-change-type={current.type}\n title={`${current.author.name}: ${current.description}`}\n >\n {current.author.name ? `${current.author.name}: ` : \"\"}\n {current.description}\n </span>\n )}\n <span className=\"mx-1 h-4 w-px bg-border\" aria-hidden=\"true\" />\n <button\n type=\"button\"\n className={buttonClass}\n disabled={!current}\n onClick={() => current && review.accept(current.id)}\n >\n Accept\n </button>\n <button\n type=\"button\"\n className={buttonClass}\n disabled={!current}\n onClick={() => current && review.reject(current.id)}\n >\n Reject\n </button>\n <button type=\"button\" className={buttonClass} disabled={count === 0} onClick={review.acceptAll}>\n Accept all\n </button>\n <button type=\"button\" className={buttonClass} disabled={count === 0} onClick={review.rejectAll}>\n Reject all\n </button>\n </div>\n );\n};\n","import React from \"react\";\nimport type { Editor } from \"@tiptap/core\";\n\nexport interface CommentButtonProps {\n editor: Editor | null;\n className?: string;\n children?: React.ReactNode;\n}\n\n/**\n * Adds a draft comment on the selection; drop it into a `BubbleMenu`. The\n * draft is completed in `CommentsPanel`.\n */\nexport const CommentButton: React.FC<CommentButtonProps> = ({\n editor,\n className = \"rounded px-2 py-1 text-xs text-popover-foreground hover:bg-muted\",\n children = \"Comment\",\n}) => (\n <button\n type=\"button\"\n className={className}\n disabled={!editor}\n onClick={() => editor?.chain().focus().addComment().run()}\n >\n {children}\n </button>\n);\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AACvB,OAAO,iBAAiB;AACxB,SAAS,aAAa;AACtB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAyDP,IAAM,oBAAgC,CAAC;AACvC,IAAM,oBAAoB,oBAAI,IAA2B;AAAA,EACvD,CAAC,WAAW,EAAE,MAAM,WAAW,IAAI,UAAU,CAAC;AAChD,CAAC;AACD,IAAM,qBACJ;AAEF,IAAM,oBAAoB,CAAC,SAAiB,KAAK,QAAQ,UAAU,IAAI;AAEhE,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd;AAAA,EACA;AAA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IAED;AAAA,IACA,gBAAAF;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,WAAWE;AAAA,QACX,UAAU,CAAC;AAAA,QACX,SAAS,MAAM,WAAW,OAAO,OAAO,QAAQ,EAAE;AAAA,QACnD;AAAA;AAAA,IAED;AAAA,IACA,gBAAAF,KAAC,YAAO,MAAK,UAAS,WAAWE,cAAa,UAAU,UAAU,GAAG,SAAS,OAAO,WAAW,wBAEhG;AAAA,IACA,gBAAAF,KAAC,YAAO,MAAK,UAAS,WAAWE,cAAa,UAAU,UAAU,GAAG,SAAS,OAAO,WAAW,wBAEhG;AAAA,KACF;AAEJ;;;ACxFE,gBAAAC,YAAA;AALK,IAAM,gBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,YAAY;AAAA,EACZ,WAAW;AACb,MACE,gBAAAA;AAAA,EAAC;AAAA;AAAA,IACC,MAAK;AAAA,IACL;AAAA,IACA,UAAU,CAAC;AAAA,IACX,SAAS,MAAM,QAAQ,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI;AAAA,IAEvD;AAAA;AACH;","names":["useEditor","useEffect","useRef","useState","useCallback","useRef","useRef","useCallback","useEffect","useEffect","useMemo","useRef","useSyncExternalStore","useEffect","useEffect","useRef","useState","useMemo","jsx","useMemo","useState","jsx","jsxs","useMemo","useSyncExternalStore","jsx","jsxs","HistoryManager","createHistoryManager","useMemo","jsx","jsxs","useCallback","useMemo","useSyncExternalStore","useState","jsx","jsxs","useState","jsx","jsxs","buttonClass","jsx"]}
1
+ {"version":3,"sources":["../src/hooks/usePromptEditor.ts","../src/hooks/useEditor.ts","../src/hooks/useNavigationGuard.ts","../src/hooks/useDismissGuard.ts","../src/hooks/useHistory.ts","../src/hooks/useHistoryDirty.ts","../src/hooks/useHistoryShortcuts.ts","../src/hooks/useFileImport.ts","../src/hooks/useAgentToolProvider.ts","../src/components/EditorContent.tsx","../src/components/BubbleMenu.tsx","../src/components/TemplateRenderer.tsx","../src/components/VariableForm.tsx","../src/hooks/useOutline.ts","../src/components/OutlinePanel.tsx","../src/index.ts","../src/slots.tsx","../src/review/useReview.ts","../src/review/CommentsPanel.tsx","../src/review/ReviewToolbar.tsx","../src/review/CommentButton.tsx"],"sourcesContent":["import { useMemo, useEffect, useRef } from \"react\";\nimport { useEditor } from \"@tiptap/react\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { Slice } from \"@tiptap/pm/model\";\nimport {\n Template,\n ColorGradient,\n GradientText,\n TemplateSuggestions,\n LoadingNode,\n plainTextToTipTapHtml,\n plainTextToSlice,\n getEditorText,\n tokenizePrompt,\n FileImport,\n type FileImportOptions,\n} from \"@pixerate/editor\";\n\nexport interface UsePromptEditorProps {\n /**\n * The editor content as plain text. Changes from the parent (e.g. clearing\n * after submit) are applied to the editor; echoes of the editor's own\n * updates via `onContentChange` are ignored.\n */\n content: string;\n /** Callback fired when the editor content changes (returns plain text) */\n onContentChange: (text: string) => void;\n /** List of available templates to be suggested and highlighted */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether the editor is editable */\n isEditing?: boolean;\n /** Placeholder text for the editor */\n placeholder?: string;\n /** Additional CSS classes for the editor container */\n className?: string;\n /** Callback fired when the Escape key is pressed */\n onEscape?: () => void;\n /** Custom keydown handler. Return true to prevent default behavior */\n onKeyDown?: (event: KeyboardEvent) => boolean;\n /** Callback fired when text selection changes */\n onSelectionChange?: (selection: { from: number; to: number } | null) => void;\n /** Callback fired when a slash command (e.g., /template) matches */\n onSlashCommandMatch?: (\n match: RegExpMatchArray,\n from: number,\n to: number,\n coords: { top: number; left: number },\n ) => void;\n /** Callback to dismiss/clear the active slash command */\n clearSlashCommand?: () => void;\n /** Whether a slash command menu is currently active */\n slashCommandActive?: boolean;\n /**\n * Callback fired the first time each milestone is reached while the editor\n * is mounted: `used_variable` ({variable}) and `used_magic` (__instruction__).\n */\n onMilestone?: (milestone: string) => void;\n /** DOM element ID of the container, used for positioning popovers */\n containerId?: string;\n /** Variable names originating from structured JSON output steps */\n jsonVariables?: string[];\n /** Animation speed for gradient decorations */\n speed?: number;\n /**\n * Import text from .md, .html, .txt and .rtf files dropped onto the editor\n * (opt-in). Content is always inserted as plain text. Pasting keeps the\n * plain-text paste handler, so pasted files are not imported.\n */\n fileImport?: Omit<FileImportOptions, \"asPlainText\"> | boolean;\n}\n\nconst DEFAULT_TEMPLATES: Template[] = [];\nconst DEFAULT_COLOR_MAP = new Map<string, ColorGradient>([\n [\"default\", { from: \"#f43f5e\", to: \"#8b5cf6\" }],\n]);\nconst DEFAULT_CLASS_NAME =\n \"w-full border border-input rounded-md p-3 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary whitespace-pre-wrap break-words\";\n\nconst normalizeNewlines = (text: string) => text.replace(/\\r\\n?/g, \"\\n\");\n\nexport function usePromptEditor({\n content,\n onContentChange,\n templates = DEFAULT_TEMPLATES,\n templateColorMap: userColorMap,\n isEditing = true,\n placeholder = \"Write a prompt, use {{template}}, {variable}, or /command...\",\n className,\n onEscape,\n onKeyDown,\n onSelectionChange,\n onSlashCommandMatch,\n clearSlashCommand,\n slashCommandActive = false,\n onMilestone,\n containerId = \"editor-container\",\n jsonVariables,\n speed = 2,\n fileImport,\n}: UsePromptEditorProps) {\n const fileImportRef = useRef(fileImport);\n fileImportRef.current = fileImport;\n const fileImportEnabled = !!fileImport;\n\n const slashCommandActiveRef = useRef(slashCommandActive);\n slashCommandActiveRef.current = slashCommandActive;\n\n const clearSlashCommandRef = useRef(clearSlashCommand);\n clearSlashCommandRef.current = clearSlashCommand;\n\n const onEscapeRef = useRef(onEscape);\n onEscapeRef.current = onEscape;\n\n const onKeyDownRef = useRef(onKeyDown);\n onKeyDownRef.current = onKeyDown;\n\n const onSelectionChangeRef = useRef(onSelectionChange);\n onSelectionChangeRef.current = onSelectionChange;\n\n const onSlashCommandMatchRef = useRef(onSlashCommandMatch);\n onSlashCommandMatchRef.current = onSlashCommandMatch;\n\n const onContentChangeRef = useRef(onContentChange);\n onContentChangeRef.current = onContentChange;\n\n const onMilestoneRef = useRef(onMilestone);\n onMilestoneRef.current = onMilestone;\n\n const containerIdRef = useRef(containerId);\n containerIdRef.current = containerId;\n\n const templateKey = useMemo(() => {\n return (templates || [])\n .map((t) => `${t.id || t.name}:${(t as any).latestVersion || \"\"}`)\n .sort()\n .join(\",\");\n }, [templates]);\n\n // Key the color map by value so an inline `new Map(...)` does not recreate\n // the editor on every render.\n const colorMapKey = userColorMap\n ? JSON.stringify(Array.from(userColorMap.entries()))\n : \"\";\n const resolvedColorMap = useMemo(() => {\n if (userColorMap) return userColorMap;\n const map = new Map<string, ColorGradient>();\n templates.forEach((t) => {\n map.set(t.name, { from: \"#f43f5e\", to: \"#8b5cf6\" });\n });\n return map.size > 0 ? map : DEFAULT_COLOR_MAP;\n }, [colorMapKey, templateKey]);\n\n const jsonVariablesKey = (jsonVariables || []).join(\"\\u0000\");\n\n const reachedMilestonesRef = useRef(new Set<string>());\n\n const StarterKitExt =\n (StarterKit as any)?.configure\n ? StarterKit\n : (StarterKit as any)?.default?.configure\n ? (StarterKit as any)?.default\n : StarterKit;\n\n const PlaceholderExt =\n (Placeholder as any)?.configure\n ? Placeholder\n : (Placeholder as any)?.default?.configure\n ? (Placeholder as any)?.default\n : Placeholder;\n\n const editor = useEditor(\n {\n immediatelyRender: false,\n enablePasteRules: false,\n enableInputRules: false,\n editable: isEditing,\n extensions: [\n StarterKitExt.configure({\n heading: false,\n codeBlock: false,\n }),\n PlaceholderExt.configure({ placeholder }),\n GradientText.configure({\n templateColorMap: resolvedColorMap,\n speed,\n jsonVariables,\n }),\n TemplateSuggestions.configure({\n templates,\n }),\n LoadingNode,\n ...(fileImportEnabled\n ? [\n FileImport.configure({\n ...(typeof fileImportRef.current === \"object\" ? fileImportRef.current : {}),\n // Prompt editors only ever receive plain text.\n asPlainText: true,\n }),\n ]\n : []),\n ],\n content: plainTextToTipTapHtml(content),\n onUpdate: ({ editor: ed }) => {\n const plainText = getEditorText(ed);\n onContentChangeRef.current?.(plainText);\n\n if (onMilestoneRef.current) {\n const reached = reachedMilestonesRef.current;\n for (const token of tokenizePrompt(plainText)) {\n const milestone =\n token.type === \"variable\"\n ? \"used_variable\"\n : token.type === \"instruction\"\n ? \"used_magic\"\n : null;\n if (milestone && !reached.has(milestone)) {\n reached.add(milestone);\n onMilestoneRef.current(milestone);\n }\n }\n }\n\n const { state, view } = ed;\n const { selection } = state;\n const { $from, from, to } = selection;\n\n onSelectionChangeRef.current?.({ from, to });\n\n if (onSlashCommandMatchRef.current && clearSlashCommandRef.current) {\n const textBeforeCursor = $from?.parent?.textBetween\n ? $from.parent.textBetween(0, $from.parentOffset)\n : \"\";\n const slashMatch = textBeforeCursor.match(\n /(?:^|\\s)\\/([a-zA-Z0-9_-]*)$/,\n );\n\n if (slashMatch) {\n const coords = view.coordsAtPos($from.pos);\n const containerEl =\n document.getElementById(containerIdRef.current) ||\n document.getElementById(\"editor-container\") ||\n (view.dom.closest?.(\".relative\") as HTMLElement | null);\n const containerCoords = containerEl?.getBoundingClientRect();\n\n if (containerCoords) {\n onSlashCommandMatchRef.current(\n slashMatch,\n $from.pos -\n slashMatch[0].length +\n (slashMatch[0].startsWith(\" \") ? 1 : 0),\n $from.pos,\n {\n top: coords.bottom - containerCoords.top + 5,\n left: coords.left - containerCoords.left,\n },\n );\n }\n } else {\n clearSlashCommandRef.current();\n }\n }\n },\n onSelectionUpdate: ({ editor: ed }) => {\n const { from, to } = ed.state.selection;\n onSelectionChangeRef.current?.({ from, to });\n },\n editorProps: {\n attributes: {\n class: className || DEFAULT_CLASS_NAME,\n role: \"textbox\",\n \"aria-label\": \"Prompt editor\",\n },\n handleKeyDown(view, event) {\n if (slashCommandActiveRef.current) {\n if (\n event.key === \"ArrowUp\" ||\n event.key === \"ArrowDown\" ||\n event.key === \"Enter\"\n ) {\n event.preventDefault();\n return true;\n }\n if (event.key === \"Escape\") {\n clearSlashCommandRef.current?.();\n event.preventDefault();\n event.stopPropagation();\n return true;\n }\n }\n if (onKeyDownRef.current && onKeyDownRef.current(event as KeyboardEvent)) {\n return true;\n }\n if (event.key === \"Escape\" && onEscapeRef.current) {\n onEscapeRef.current();\n return true;\n }\n return false;\n },\n handlePaste: (view, event) => {\n // Paste as plain text even when the clipboard also carries HTML.\n const text = event.clipboardData?.getData(\"text/plain\");\n if (!text) return false;\n event.preventDefault();\n const schema = view.state.schema;\n if (!schema) return false;\n view.dispatch(\n view.state.tr.replaceSelection(plainTextToSlice(text, schema)),\n );\n return true;\n },\n clipboardTextParser: (text, context, _plain, view) => {\n const schema =\n (context as any)?.doc?.type?.schema ||\n (context as any)?.schema ||\n view?.state?.schema;\n\n if (!schema) return Slice.empty;\n return plainTextToSlice(text, schema);\n },\n },\n },\n // Only options baked into extensions recreate the editor; editable state,\n // placeholder, class names and content are applied to the live instance.\n [resolvedColorMap, templateKey, speed, jsonVariablesKey, fileImportEnabled],\n );\n\n useEffect(() => {\n if (editor && !editor.isDestroyed) {\n editor.setEditable(isEditing);\n }\n }, [editor, isEditing]);\n\n // Apply content changes made by the parent (e.g. clearing after submit).\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n if (normalizeNewlines(content) === getEditorText(editor)) return;\n const { from, to } = editor.state.selection;\n editor.commands.setContent(plainTextToTipTapHtml(content), false);\n const max = editor.state.doc.content.size;\n editor.commands.setTextSelection({\n from: Math.min(from, max),\n to: Math.min(to, max),\n });\n }, [editor, content]);\n\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n editor.setOptions({\n editorProps: {\n ...editor.options.editorProps,\n attributes: {\n ...(editor.options.editorProps.attributes as Record<string, string>),\n class: className || DEFAULT_CLASS_NAME,\n },\n },\n });\n }, [editor, className]);\n\n useEffect(() => {\n if (!editor || editor.isDestroyed) return;\n const placeholderExt = editor.extensionManager.extensions.find(\n (ext) => ext.name === \"placeholder\",\n );\n if (!placeholderExt || placeholderExt.options.placeholder === placeholder) {\n return;\n }\n placeholderExt.options.placeholder = placeholder;\n // Re-run decorations so the new placeholder renders.\n editor.view.dispatch(editor.state.tr);\n }, [editor, placeholder]);\n\n return editor;\n}\n","import { useEditor as useTipTapEditor, UseEditorOptions } from \"@tiptap/react\";\nimport {\n createRichTextPreset,\n RichTextPresetOptions,\n type FileImportOptions,\n type RichClipboardOptions,\n} from \"@pixerate/editor\";\n\nexport interface UseRichEditorProps extends UseEditorOptions {\n richTextOptions?: RichTextPresetOptions;\n /**\n * Import .md, .html, .txt and .rtf files dropped or pasted into the editor\n * at the drop position (opt-in; same as `richTextOptions.fileImport`).\n */\n fileImport?: FileImportOptions | boolean;\n /**\n * Copy/paste lossless ProseMirror slices between editors via the\n * `application/x.pixerate.document+json` clipboard type (opt-in; same as\n * `richTextOptions.richClipboard`).\n */\n richClipboard?: RichClipboardOptions | boolean;\n}\n\n/**\n * Hook to initialize a TipTap rich-text editor instance with pre-configured extensions.\n */\nexport function useEditor(options: UseRichEditorProps = {}) {\n const {\n richTextOptions,\n fileImport,\n richClipboard,\n extensions = [],\n ...editorOptions\n } = options;\n\n const preset = createRichTextPreset({\n ...(fileImport !== undefined ? { fileImport } : {}),\n ...(richClipboard !== undefined ? { richClipboard } : {}),\n ...richTextOptions,\n });\n const combinedExtensions = [...preset, ...extensions];\n\n return useTipTapEditor({\n extensions: combinedExtensions,\n ...editorOptions,\n });\n}\n","import { useState, useEffect, useCallback, useRef } from \"react\";\n\nexport interface UseNavigationGuardOptions {\n /** Whether the current form or editor has unsaved changes */\n isDirty: boolean;\n /** Whether guarding is enabled (defaults to true) */\n enabled?: boolean;\n /** Custom navigation function (e.g. router.push from next/navigation or react-router) */\n onNavigate?: (url: string) => void;\n /** Optional callback fired when an internal navigation attempt is intercepted */\n onBlocked?: (url: string) => void;\n}\n\nexport interface UseNavigationGuardReturn {\n /** Whether the unsaved changes confirmation dialog should be displayed */\n showConfirm: boolean;\n /** Setter to manually control the dialog visibility */\n setShowConfirm: (show: boolean) => void;\n /** The target URL that the user attempted to navigate to */\n pendingUrl: string | null;\n /** Proceeds with the blocked navigation and closes the dialog */\n confirmLeave: () => void;\n /** Cancels the navigation attempt and keeps the user on the current page */\n cancelLeave: () => void;\n}\n\n/**\n * Hook to guard against navigation when there are unsaved changes.\n * Intercepts both external unloads (tab closing/refreshing) and internal link clicks.\n */\nexport function useNavigationGuard({\n isDirty,\n enabled = true,\n onNavigate,\n onBlocked,\n}: UseNavigationGuardOptions): UseNavigationGuardReturn {\n const [showConfirm, setShowConfirm] = useState(false);\n const [pendingUrl, setPendingUrl] = useState<string | null>(null);\n\n const onNavigateRef = useRef(onNavigate);\n onNavigateRef.current = onNavigate;\n\n const onBlockedRef = useRef(onBlocked);\n onBlockedRef.current = onBlocked;\n\n // 1. Intercept external navigation / tab close (beforeunload)\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n if (!enabled || !isDirty) return;\n\n const handleBeforeUnload = (e: BeforeUnloadEvent) => {\n e.preventDefault();\n e.returnValue = \"\";\n };\n\n window.addEventListener(\"beforeunload\", handleBeforeUnload);\n return () => {\n window.removeEventListener(\"beforeunload\", handleBeforeUnload);\n };\n }, [enabled, isDirty]);\n\n // 2. Intercept internal anchor link clicks\n useEffect(() => {\n if (typeof document === \"undefined\" || typeof window === \"undefined\")\n return;\n if (!enabled || !isDirty) return;\n\n const handleClick = (e: MouseEvent) => {\n const target = e.target as HTMLElement | null;\n const anchor = target?.closest?.(\"a\");\n\n if (!anchor) return;\n if (anchor.target === \"_blank\") return;\n\n // Only guard internal origins\n const isInternal = anchor.host === window.location.host;\n if (!isInternal) return;\n\n // Ignore navigation to the exact same path & query\n if (\n anchor.pathname === window.location.pathname &&\n anchor.search === window.location.search\n ) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n const href = anchor.href;\n setPendingUrl(href);\n setShowConfirm(true);\n onBlockedRef.current?.(href);\n };\n\n document.addEventListener(\"click\", handleClick, { capture: true });\n return () => {\n document.removeEventListener(\"click\", handleClick, { capture: true });\n };\n }, [enabled, isDirty]);\n\n const confirmLeave = useCallback(() => {\n setShowConfirm(false);\n if (pendingUrl) {\n if (onNavigateRef.current) {\n onNavigateRef.current(pendingUrl);\n } else if (typeof window !== \"undefined\") {\n window.location.href = pendingUrl;\n }\n }\n }, [pendingUrl]);\n\n const cancelLeave = useCallback(() => {\n setShowConfirm(false);\n setPendingUrl(null);\n }, []);\n\n return {\n showConfirm,\n setShowConfirm,\n pendingUrl,\n confirmLeave,\n cancelLeave,\n };\n}\n","import { useState, useCallback, useRef } from \"react\";\n\nexport interface UseDismissGuardOptions {\n /** Whether there are unsaved changes */\n isDirty: boolean;\n /** Whether the dismissal guard is enabled (defaults to true) */\n enabled?: boolean;\n /** Callback fired when dismissal is confirmed or when clean dismissal occurs */\n onDismiss?: () => void;\n}\n\nexport interface UseDismissGuardReturn {\n /** Whether the discard confirmation modal should be shown */\n showConfirm: boolean;\n /** Manually update confirmation modal visibility */\n setShowConfirm: (show: boolean) => void;\n /** Request dismissal - checks isDirty and shows confirm or executes onDismiss */\n requestDismiss: () => void;\n /** Confirm discarding changes and dismiss */\n confirmDismiss: () => void;\n /** Cancel discarding and resume editing */\n cancelDismiss: () => void;\n /** Helper keydown handler intercepting Escape key */\n handleKeyDown: (event: React.KeyboardEvent | KeyboardEvent) => boolean;\n}\n\n/**\n * Hook to guard against closing or exiting an editor/dialog with uncommitted changes.\n */\nexport function useDismissGuard({\n isDirty,\n enabled = true,\n onDismiss,\n}: UseDismissGuardOptions): UseDismissGuardReturn {\n const [showConfirm, setShowConfirm] = useState(false);\n\n const onDismissRef = useRef(onDismiss);\n onDismissRef.current = onDismiss;\n\n const requestDismiss = useCallback(() => {\n if (enabled && isDirty) {\n setShowConfirm(true);\n } else {\n onDismissRef.current?.();\n }\n }, [enabled, isDirty]);\n\n const confirmDismiss = useCallback(() => {\n setShowConfirm(false);\n onDismissRef.current?.();\n }, []);\n\n const cancelDismiss = useCallback(() => {\n setShowConfirm(false);\n }, []);\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent | KeyboardEvent) => {\n if (event.key === \"Escape\") {\n if (event.defaultPrevented) return false;\n event.preventDefault();\n requestDismiss();\n return true;\n }\n return false;\n },\n [requestDismiss],\n );\n\n return {\n showConfirm,\n setShowConfirm,\n requestDismiss,\n confirmDismiss,\n cancelDismiss,\n handleKeyDown,\n };\n}\n","import { useSyncExternalStore, useRef, useCallback, useMemo } from \"react\";\nimport {\n HistoryManager,\n HistoryState,\n HistoryEntry,\n HistoryMark,\n Command,\n MergedExecutionOptions,\n createHistoryManager,\n HistoryManagerOptions,\n} from \"@pixerate/editor\";\n\nexport interface UseHistoryResult extends HistoryState {\n manager: HistoryManager;\n /** History panel rows (undo steps, then redo steps). */\n entries: HistoryEntry[];\n undo: () => boolean;\n redo: () => boolean;\n clear: () => void;\n execute: (command: Command) => void;\n executeMerged: (command: Command, options?: MergedExecutionOptions) => void;\n batch: (name: string, fn: () => void) => void;\n /** Undoes / redoes until the entry at `index` is current (`-1` = before all). */\n goTo: (index: number) => number;\n /** Captures the current point, e.g. when a drag starts. */\n mark: () => HistoryMark;\n /** Takes back every step since `mark` without leaving redo (Escape-cancel). */\n revertTo: (mark: HistoryMark) => number;\n /** Joins every merged execute into one step until `endGesture`. */\n beginGesture: (key: string) => void;\n endGesture: () => void;\n}\n\n/**\n * React hook that subscribes to a HistoryManager instance.\n * Accepts an existing HistoryManager or config options to create an instance\n * (options are read on first render only).\n */\nexport function useHistory(\n managerOrOptions?: HistoryManager | HistoryManagerOptions,\n): UseHistoryResult {\n // Options are read once, so passing an inline options object does not\n // create a new manager (and wipe history) on every render.\n const ownManagerRef = useRef<HistoryManager | null>(null);\n let manager: HistoryManager;\n if (managerOrOptions instanceof HistoryManager) {\n manager = managerOrOptions;\n } else {\n ownManagerRef.current ??= createHistoryManager(managerOrOptions);\n manager = ownManagerRef.current;\n }\n\n const state = useSyncExternalStore(\n useCallback(\n (onStoreChange) => manager.subscribe(onStoreChange),\n [manager],\n ),\n () => manager.getState(),\n () => manager.getState(),\n );\n\n // getEntries() is cached per history change, so `state` is a valid dependency.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const entries = useMemo(() => manager.getEntries(), [manager, state]);\n\n const undo = useCallback(() => manager.undo(), [manager]);\n const redo = useCallback(() => manager.redo(), [manager]);\n const clear = useCallback(() => manager.clear(), [manager]);\n const execute = useCallback(\n (cmd: Command) => manager.execute(cmd),\n [manager],\n );\n const executeMerged = useCallback(\n (cmd: Command, opts?: MergedExecutionOptions) =>\n manager.executeMerged(cmd, opts),\n [manager],\n );\n const batch = useCallback(\n (name: string, fn: () => void) => manager.batch(name, fn),\n [manager],\n );\n const goTo = useCallback((index: number) => manager.goTo(index), [manager]);\n const mark = useCallback(() => manager.mark(), [manager]);\n const revertTo = useCallback(\n (m: HistoryMark) => manager.revertTo(m),\n [manager],\n );\n const beginGesture = useCallback(\n (key: string) => manager.beginGesture(key),\n [manager],\n );\n const endGesture = useCallback(() => manager.endGesture(), [manager]);\n\n return {\n ...state,\n manager,\n entries,\n undo,\n redo,\n clear,\n execute,\n executeMerged,\n batch,\n goTo,\n mark,\n revertTo,\n beginGesture,\n endGesture,\n };\n}\n","import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport {\n DirtyTracker,\n bindDirtyToHistory,\n type DirtyTrackerOptions,\n type HistoryDirtyBinding,\n type HistoryManager,\n} from \"@pixerate/editor\";\n\nexport interface UseHistoryDirtyOptions<T> extends DirtyTrackerOptions<T> {\n /** The history whose changes re-check the document. */\n history: HistoryManager;\n /** Reads the current document value (the latest function is always used). */\n getValue: () => T;\n /** Existing tracker to drive (read on first render only). */\n tracker?: DirtyTracker<T>;\n}\n\nexport interface UseHistoryDirtyResult<T> {\n /** Whether the document differs from the saved state. Feed it to `useNavigationGuard`. */\n isDirty: boolean;\n /** Marks the current document as saved. */\n markClean: () => void;\n /** Runs a load / restore without marking the document dirty (re-entrant). */\n suppress: <R>(fn: () => R) => R;\n /** Re-checks after a change made outside the history. */\n refresh: () => boolean;\n tracker: DirtyTracker<T>;\n}\n\n/**\n * Dirty-vs-saved tracking bound to a HistoryManager: undoing back to the saved\n * state makes the document clean again, selection/viewport changes can be\n * ignored with `normalize`, and programmatic loads can be wrapped in `suppress`.\n * Options other than `getValue` and `history` are read on first render only.\n */\nexport function useHistoryDirty<T>(\n options: UseHistoryDirtyOptions<T>,\n): UseHistoryDirtyResult<T> {\n const getValueRef = useRef(options.getValue);\n getValueRef.current = options.getValue;\n\n const [tracker] = useState(\n () =>\n options.tracker ??\n new DirtyTracker<T>(options.getValue(), {\n isEqual: options.isEqual,\n normalize: options.normalize,\n }),\n );\n\n const bindingRef = useRef<HistoryDirtyBinding<T> | null>(null);\n useEffect(() => {\n const binding = bindDirtyToHistory<T>({\n history: options.history,\n getValue: () => getValueRef.current(),\n tracker,\n });\n bindingRef.current = binding;\n return () => {\n binding.destroy();\n if (bindingRef.current === binding) bindingRef.current = null;\n };\n }, [options.history, tracker]);\n\n const isDirty = useSyncExternalStore(\n useCallback((onChange) => tracker.subscribe(onChange), [tracker]),\n () => tracker.dirty,\n () => tracker.dirty,\n );\n\n const markClean = useCallback(\n () => tracker.markClean(getValueRef.current()),\n [tracker],\n );\n const suppress = useCallback(\n <R,>(fn: () => R): R =>\n bindingRef.current ? bindingRef.current.suppress(fn) : tracker.suppress(fn),\n [tracker],\n );\n const refresh = useCallback(\n () => tracker.update(getValueRef.current()),\n [tracker],\n );\n\n return { isDirty, markClean, suppress, refresh, tracker };\n}\n","import { useEffect } from \"react\";\nimport type { HistoryManager } from \"@pixerate/editor/history\";\nimport { matchHistoryShortcut } from \"@pixerate/editor/commands\";\n\nexport interface HistoryShortcutsOptions {\n /**\n * Whether the keyboard shortcuts are enabled. Defaults to true.\n */\n enabled?: boolean;\n /**\n * Target element or window to listen on. Defaults to window.\n */\n target?: Window | HTMLElement | null;\n /**\n * When true (default), shortcuts will not trigger if an <input>, <textarea>,\n * or [contenteditable] element is currently active / focused.\n */\n ignoreEditableElements?: boolean;\n}\n\n/**\n * Attaches keyboard listeners for Undo (Mod+Z) and Redo (Mod+Shift+Z / Mod+Y).\n * Automatically guards against active text inputs and contenteditable editors.\n */\nexport function useHistoryShortcuts(\n manager: HistoryManager,\n options: HistoryShortcutsOptions = {},\n): void {\n const {\n enabled = true,\n target,\n ignoreEditableElements = true,\n } = options;\n\n useEffect(() => {\n if (!enabled) return;\n\n const eventTarget = target ?? (typeof window !== \"undefined\" ? window : null);\n if (!eventTarget) return;\n\n const handleKeyDown = (event: Event) => {\n const e = event as KeyboardEvent;\n // Default bindings from the command system: Mod+Z, Mod+Shift+Z and (off macOS) Mod+Y,\n // matched by `event.code` with `Mod` = ⌘ on macOS and Ctrl elsewhere.\n const action = matchHistoryShortcut(e, { allowInEditable: !ignoreEditableElements });\n if (action === \"undo\" && manager.getState().canUndo) {\n e.preventDefault();\n manager.undo();\n } else if (action === \"redo\" && manager.getState().canRedo) {\n e.preventDefault();\n manager.redo();\n }\n };\n\n eventTarget.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n eventTarget.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [manager, enabled, target, ignoreEditableElements]);\n}\n","import { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport {\n FileImportController,\n type FileImportControllerOptions,\n type FileImportState,\n} from \"@pixerate/editor\";\n\nexport interface UseFileImportResult extends FileImportState {\n /** Value for `<input type=\"file\" accept={…}>`. */\n accept: string;\n /** Opens the browser file picker and imports the chosen files at the selection. */\n openFilePicker: FileImportController[\"openFilePicker\"];\n /** Imports files (e.g. from your own `<input>` or drop zone) at `at` or the selection. */\n importFiles: FileImportController[\"importFiles\"];\n}\n\n/**\n * Imports markdown, HTML, plain-text and RTF files (or anything registered\n * with `registerImportAdapter` for the `document` target) into an editor.\n * Pair it with `useEditor({ fileImport: true })` to also accept dropped files.\n */\nexport function useFileImport(\n editor: Editor | null | undefined,\n options: FileImportControllerOptions = {},\n): UseFileImportResult {\n const editorRef = useRef(editor);\n editorRef.current = editor;\n\n const controller = useMemo(\n () =>\n new FileImportController(() => {\n const current = editorRef.current;\n return current && !current.isDestroyed ? current : null;\n }, options),\n [],\n );\n\n useEffect(() => {\n controller.setOptions(options);\n });\n\n const state = useSyncExternalStore(controller.subscribe, controller.getState, controller.getState);\n\n return {\n ...state,\n accept: controller.accept,\n openFilePicker: controller.openFilePicker,\n importFiles: controller.importFiles,\n };\n}\n","import { useEffect } from \"react\";\nimport type { AgentToolProvider, ToolRegistry } from \"@pixerate/editor/agent\";\n\n/**\n * Registers a tool provider with a `ToolRegistry` while the component is\n * mounted and unregisters it on unmount (the registry then announces the\n * change through `onListChanged`).\n *\n * Memoize the provider (e.g. `useMemo(() => createRichTextToolProvider(editor,\n * { id }), [editor])`): a new provider object re-registers it. Pass `null`\n * while it isn't ready.\n */\nexport function useAgentToolProvider(\n registry: ToolRegistry | null | undefined,\n provider: AgentToolProvider | null | undefined,\n): void {\n useEffect(() => {\n if (!registry || !provider) return;\n return registry.register(provider);\n }, [registry, provider]);\n}\n","import React from \"react\";\nimport {\n EditorContent as TipTapEditorContent,\n EditorContentProps as TipTapEditorContentProps,\n} from \"@tiptap/react\";\n\nexport interface EditorContentProps extends TipTapEditorContentProps {\n className?: string;\n}\n\nexport const EditorContent: React.FC<EditorContentProps> = ({\n className,\n editor,\n ...props\n}) => {\n return (\n <div className={className}>\n <TipTapEditorContent editor={editor} {...props} />\n </div>\n );\n};\n","import React, { useEffect, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n BubbleMenuPlugin,\n type BubbleMenuPluginProps,\n} from \"@tiptap/extension-bubble-menu\";\nimport type { Editor } from \"@tiptap/core\";\n\nexport interface BubbleMenuProps {\n editor: Editor | null;\n className?: string;\n children: React.ReactNode;\n tippyOptions?: BubbleMenuPluginProps[\"tippyOptions\"];\n shouldShow?: BubbleMenuPluginProps[\"shouldShow\"];\n pluginKey?: BubbleMenuPluginProps[\"pluginKey\"];\n updateDelay?: BubbleMenuPluginProps[\"updateDelay\"];\n}\n\nexport const BubbleMenu: React.FC<BubbleMenuProps> = ({\n editor,\n className = \"flex items-center gap-1 bg-popover text-popover-foreground border shadow-md rounded-md p-1\",\n children,\n tippyOptions = { duration: 100 },\n shouldShow = null,\n pluginKey = \"bubbleMenu\",\n updateDelay,\n}) => {\n const menuEl = useRef<HTMLDivElement | null>(null);\n const [mounted, setMounted] = useState(false);\n\n if (!menuEl.current && typeof document !== \"undefined\") {\n menuEl.current = document.createElement(\"div\");\n }\n\n useEffect(() => {\n if (!editor || !menuEl.current || editor.isDestroyed) {\n return;\n }\n\n const element = menuEl.current;\n element.className = className;\n\n const plugin = BubbleMenuPlugin({\n editor,\n element,\n pluginKey,\n tippyOptions,\n shouldShow,\n updateDelay,\n });\n\n editor.registerPlugin(plugin);\n setMounted(true);\n\n return () => {\n setMounted(false);\n editor.unregisterPlugin(pluginKey);\n if (element.parentNode) {\n element.parentNode.removeChild(element);\n }\n };\n }, [editor, className, pluginKey]);\n\n if (!editor || !menuEl.current || !mounted) {\n return null;\n }\n\n return createPortal(children, menuEl.current);\n};\n","import React, { useMemo } from \"react\";\nimport {\n evaluatePromptTokens,\n resolveTemplates,\n Template,\n ColorGradient,\n PromptValues,\n} from \"@pixerate/editor\";\n\nexport interface TemplateRendererProps {\n /** Raw prompt or text string to render */\n content: string;\n /** Available templates for recursive resolution and custom coloring */\n templates?: Template[];\n /** Custom gradient color map for templates */\n templateColorMap?: Map<string, ColorGradient>;\n /** Whether to resolve nested templates recursively before displaying */\n resolve?: boolean;\n /** Template version bindings used when `resolve` is set */\n bindings?: Record<string, string>;\n /**\n * Variable values. When set, variables show their value (or default),\n * sections whose condition fails are hidden, and section tags are dropped.\n */\n values?: PromptValues;\n /** Custom class name for the wrapper */\n className?: string;\n /** Click callback for template badges */\n onTemplateClick?: (templateName: string) => void;\n /** Click callback for variable badges */\n onVariableClick?: (variableName: string) => void;\n}\n\nconst CONDITIONAL_PREFIX = { if: \"?\", unless: \"!\", end: \"/\" } as const;\n\nexport const TemplateRenderer: React.FC<TemplateRendererProps> = ({\n content,\n templates = [],\n templateColorMap,\n resolve = false,\n bindings,\n values,\n className = \"font-mono text-sm leading-relaxed whitespace-pre-wrap break-words\",\n onTemplateClick,\n onVariableClick,\n}) => {\n const displayText = useMemo(() => {\n if (!resolve || templates.length === 0) return content;\n return resolveTemplates(content, templates, { bindings });\n }, [content, templates, resolve, bindings]);\n\n const tokens = useMemo(() => {\n return evaluatePromptTokens(displayText, values);\n }, [displayText, values]);\n\n return (\n <div className={className}>\n {tokens.map((token, index) => {\n if (token.type === \"template\") {\n const colors = templateColorMap?.get(token.value) || {\n from: \"#f43f5e\",\n to: \"#8b5cf6\",\n };\n const style = {\n \"--color-from\": colors.from,\n \"--color-to\": colors.to,\n } as React.CSSProperties;\n\n return (\n <span\n key={index}\n style={style}\n onClick={() => onTemplateClick?.(token.value)}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-semibold rounded-md border border-[var(--color-to)]/40 bg-gradient-to-r from-[var(--color-from)]/15 to-[var(--color-to)]/15 text-[var(--color-to)] hover:brightness-110 cursor-pointer transition-all\"\n title={`Template: ${token.value}`}\n >\n {`{{${token.value}}}`}\n </span>\n );\n }\n\n if (token.type === \"variable\") {\n const details = [\n `Variable: ${token.value}`,\n token.description,\n token.defaultValue !== undefined\n ? `Default: ${token.defaultValue || \"(empty)\"}`\n : undefined,\n ]\n .filter(Boolean)\n .join(\"\\n\");\n\n if (token.resolvedValue !== undefined) {\n return (\n <span\n key={index}\n onClick={() => onVariableClick?.(token.value)}\n data-variable={token.value}\n data-value-source={token.valueSource}\n className={\n token.valueSource === \"value\"\n ? \"inline px-1 mx-0.5 rounded-md bg-emerald-400/15 text-emerald-700 dark:text-emerald-300 border-b border-emerald-400/60 cursor-pointer\"\n : \"inline px-1 mx-0.5 rounded-md bg-violet-400/10 text-violet-600 dark:text-violet-300 italic border-b border-dashed border-violet-400/60 cursor-pointer\"\n }\n title={details}\n >\n {token.resolvedValue}\n </span>\n );\n }\n\n return (\n <span\n key={index}\n onClick={() => onVariableClick?.(token.value)}\n data-variable={token.value}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-violet-400/40 bg-violet-400/15 text-violet-600 dark:text-violet-300 hover:brightness-110 cursor-pointer transition-all\"\n title={details}\n >\n {`{${token.value}`}\n {token.defaultValue !== undefined && (\n <span className=\"opacity-60\">{`|${token.defaultValue}`}</span>\n )}\n {\"}\"}\n </span>\n );\n }\n\n if (token.type === \"conditional\" && token.conditional) {\n return (\n <span\n key={index}\n data-conditional={token.conditional}\n className=\"inline-flex items-center px-1 py-0.5 mx-0.5 text-xs font-medium rounded-md border border-amber-400/40 bg-amber-400/15 text-amber-700 dark:text-amber-300\"\n title={\n token.conditional === \"end\"\n ? `End of section: ${token.value}`\n : token.conditional === \"if\"\n ? `Shown when \"${token.value}\" has a value`\n : `Shown when \"${token.value}\" is empty`\n }\n >\n {`{${CONDITIONAL_PREFIX[token.conditional]}${token.value}}`}\n </span>\n );\n }\n\n if (token.type === \"instruction\") {\n return (\n <span\n key={index}\n className=\"inline-flex items-center px-1.5 py-0.5 mx-0.5 text-xs italic font-medium rounded-md border border-rose-400/40 bg-rose-400/15 text-rose-600 dark:text-rose-300\"\n title={`Instruction: ${token.value}`}\n >\n {`__${token.value}__`}\n </span>\n );\n }\n\n return <span key={index}>{token.value}</span>;\n })}\n </div>\n );\n};\n","import React, { useId, useMemo, useState } from \"react\";\nimport {\n compactVariableValues,\n getVariableFormFields,\n PromptValues,\n Template,\n VariableFormField,\n} from \"@pixerate/editor\";\n\nexport interface VariableFormProps {\n /** Prompt whose variables become form fields */\n content: string;\n /** Templates searched recursively for further variables */\n templates?: Template[];\n /** Template version bindings */\n bindings?: Record<string, string>;\n /** Entered text per variable (controlled). Omit to let the form keep its own state. */\n values?: Record<string, string>;\n /** Initial entered text when uncontrolled */\n defaultValues?: Record<string, string>;\n /**\n * Called on every edit with the values to resolve with (blank fields\n * dropped so defaults apply) and the raw entered text.\n */\n onChange?: (values: PromptValues, entered: Record<string, string>) => void;\n /** Custom class name for the wrapper */\n className?: string;\n}\n\n/**\n * Renders one input per prompt variable: labelled with its description,\n * using its default as the placeholder. Variables only used by `{?name}`\n * conditions render as checkboxes.\n */\nexport const VariableForm: React.FC<VariableFormProps> = ({\n content,\n templates,\n bindings,\n values,\n defaultValues,\n onChange,\n className = \"flex flex-col gap-3 text-sm\",\n}) => {\n const idPrefix = useId();\n const [internal, setInternal] = useState<Record<string, string>>(\n () => defaultValues ?? {},\n );\n const entered = values ?? internal;\n\n const fields = useMemo<VariableFormField[]>(\n () => getVariableFormFields(content, { templates, bindings }),\n [content, templates, bindings],\n );\n\n const update = (name: string, value: string) => {\n const next = { ...entered, [name]: value };\n if (values === undefined) setInternal(next);\n onChange?.(compactVariableValues(next), next);\n };\n\n if (fields.length === 0) return null;\n\n return (\n <form className={className} onSubmit={(event) => event.preventDefault()}>\n {fields.map((field) => {\n const id = `${idPrefix}-${field.name}`;\n if (field.conditionOnly) {\n return (\n <label\n key={field.name}\n htmlFor={id}\n className=\"flex items-center gap-2\"\n data-variable-field={field.name}\n >\n <input\n id={id}\n name={field.name}\n type=\"checkbox\"\n checked={(entered[field.name] ?? \"\") !== \"\"}\n onChange={(event) =>\n update(field.name, event.target.checked ? \"true\" : \"\")\n }\n />\n <span>{field.label}</span>\n </label>\n );\n }\n return (\n <label\n key={field.name}\n htmlFor={id}\n className=\"flex flex-col gap-1\"\n data-variable-field={field.name}\n >\n <span className=\"font-medium\">\n {field.label}\n {field.required && (\n <span className=\"text-rose-500\" aria-hidden=\"true\">\n {\" *\"}\n </span>\n )}\n </span>\n <input\n id={id}\n name={field.name}\n type=\"text\"\n value={entered[field.name] ?? \"\"}\n placeholder={field.placeholder}\n aria-required={field.required || undefined}\n onChange={(event) => update(field.name, event.target.value)}\n className=\"px-2 py-1 rounded-md border border-violet-400/40 bg-transparent\"\n />\n </label>\n );\n })}\n </form>\n );\n};\n","import { useMemo, useSyncExternalStore } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport { createOutlineStore, type OutlineSnapshot } from \"@pixerate/editor\";\n\nexport type { OutlineHeading, OutlineSnapshot, OutlineTreeItem } from \"@pixerate/editor\";\n\n/**\n * Subscribes to an editor's heading outline. Returns the headings (flat and\n * nested) and the id of the heading whose section contains the selection.\n * Re-renders only when the outline or the active heading changes.\n *\n * Install the `Outline` extension (`richTextOptions: { outline: true }`) for\n * stable heading ids; without it, headings are still listed.\n */\nexport function useOutline(editor: Editor | null | undefined): OutlineSnapshot {\n // The store only listens to the editor while subscribed, so it needs no\n // explicit cleanup (and survives StrictMode's double effects).\n const store = useMemo(() => createOutlineStore(editor), [editor]);\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n}\n","import React from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport { navigateToHeading, type OutlineHeading } from \"@pixerate/editor\";\nimport { useOutline } from \"../hooks/useOutline\";\n\nexport interface OutlinePanelProps {\n editor: Editor | null;\n /** Heading shown above the list. Pass `null` to hide it. */\n title?: React.ReactNode;\n /** Content shown when the document has no headings. */\n emptyState?: React.ReactNode;\n /** Deepest heading level listed. Defaults to 6. */\n maxLevel?: number;\n /** Whether clicking an entry focuses the editor. Defaults to `true`. */\n focusOnNavigate?: boolean;\n /** Custom class name for the wrapper. */\n className?: string;\n /** Class name for each entry button. */\n itemClassName?: string;\n /** Class name added to the entry of the section containing the selection. */\n activeItemClassName?: string;\n /** Called after navigating to a heading. */\n onNavigate?: (heading: OutlineHeading) => void;\n}\n\n/**\n * Navigation sidebar listing the document's headings (Word's Navigation pane).\n * Clicking an entry moves the caret to that heading; the entry for the\n * section containing the selection is highlighted.\n */\nexport const OutlinePanel: React.FC<OutlinePanelProps> = ({\n editor,\n title = \"Outline\",\n emptyState = \"Add headings to see the outline.\",\n maxLevel = 6,\n focusOnNavigate = true,\n className = \"flex flex-col gap-1 text-sm\",\n itemClassName = \"w-full truncate rounded px-2 py-1 text-left hover:bg-black/5\",\n activeItemClassName = \"font-semibold bg-black/5\",\n onNavigate,\n}) => {\n const { headings, activeId } = useOutline(editor);\n const visible = headings.filter((h) => h.level <= maxLevel);\n\n return (\n <nav className={className} aria-label=\"Document outline\" data-outline-panel=\"\">\n {title != null && <div className=\"pixerate-outline-title\">{title}</div>}\n {visible.length === 0 ? (\n <div className=\"pixerate-outline-empty\">{emptyState}</div>\n ) : (\n <ul role=\"list\" style={{ listStyle: \"none\", margin: 0, padding: 0 }}>\n {visible.map((heading) => {\n const active = heading.id === activeId;\n return (\n <li key={heading.id} data-level={heading.level}>\n <button\n type=\"button\"\n className={active ? `${itemClassName} ${activeItemClassName}` : itemClassName}\n style={{ paddingLeft: `${0.5 + heading.depth * 0.75}rem` }}\n aria-current={active ? \"location\" : undefined}\n data-heading-id={heading.id}\n onClick={() => {\n if (!editor) return;\n if (navigateToHeading(editor, heading, { focus: focusOnNavigate })) {\n onNavigate?.(heading);\n }\n }}\n >\n {heading.text || \"Untitled\"}\n </button>\n </li>\n );\n })}\n </ul>\n )}\n </nav>\n );\n};\n","export * from \"./hooks/usePromptEditor\";\nexport * from \"./hooks/useEditor\";\nexport * from \"./hooks/useNavigationGuard\";\nexport * from \"./hooks/useDismissGuard\";\nexport * from \"./hooks/useHistory\";\nexport * from \"./hooks/useHistoryDirty\";\nexport * from \"./hooks/useHistoryShortcuts\";\nexport * from \"./hooks/useFileImport\";\nexport * from \"./hooks/useAgentToolProvider\";\nexport * from \"./components/EditorContent\";\nexport * from \"./components/BubbleMenu\";\nexport * from \"./components/TemplateRenderer\";\nexport * from \"./components/VariableForm\";\nexport * from \"./hooks/useOutline\";\nexport * from \"./components/OutlinePanel\";\n\n// Re-export core types for easy consumer access\nexport {\n DirtyTracker,\n createDirtyTracker,\n defaultIsEqual,\n HistoryManager,\n createHistoryManager,\n bindDirtyToHistory,\n withoutDirty,\n} from \"@pixerate/editor\";\nexport type {\n Template,\n TemplateVersion,\n Token,\n TokenType,\n ColorGradient,\n RichTextPresetOptions,\n DirtyTrackerOptions,\n Command,\n HistoryState,\n HistoryManagerOptions,\n HistoryEntry,\n HistoryMark,\n MergedExecutionOptions,\n HistoryDirtyBinding,\n BindDirtyToHistoryOptions,\n} from \"@pixerate/editor\";\nexport type {\n PromptValues,\n PromptDiagnostic,\n VariableFormField,\n} from \"@pixerate/editor\";\n\nexport * from \"./spreadsheet\";\nexport * from \"./slots\";\nexport * from \"./image-editor\";\nexport * from \"./review\";\nexport * from \"./commands\";\n","import React, { createContext, useContext, useMemo } from 'react';\nimport type {\n\tButtonSlotProps,\n\tEditorSlotsMap,\n\tNodeHeaderSlotProps,\n\tTooltipSlotProps\n} from '@pixerate/editor';\n\nconst defaultSlots: EditorSlotsMap = {\n\tButton: (props: ButtonSlotProps) => (\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tclassName={`pixerate-btn ${props.className || ''}`}\n\t\t\tonClick={props.onClick}\n\t\t\tdisabled={props.disabled}\n\t\t>\n\t\t\t{props.children}\n\t\t</button>\n\t),\n\tTooltip: (props: TooltipSlotProps) => (\n\t\t<div className={`pixerate-tooltip-container ${props.className || ''}`} title={String(props.content)}>\n\t\t\t{props.children}\n\t\t</div>\n\t),\n\tNodeHeader: (props: NodeHeaderSlotProps) => (\n\t\t<div className={`pixerate-node-header flex items-center justify-between ${props.className || ''}`}>\n\t\t\t<div className=\"flex items-center gap-2\">\n\t\t\t\t{props.icon}\n\t\t\t\t<span className=\"font-semibold\">{props.title}</span>\n\t\t\t</div>\n\t\t\t{props.onClose && (\n\t\t\t\t<button type=\"button\" onClick={props.onClose} className=\"opacity-70 hover:opacity-100\">\n\t\t\t\t\t×\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</div>\n\t)\n};\n\nconst EditorSlotsContext = createContext<EditorSlotsMap>(defaultSlots);\n\nexport interface EditorSlotsProviderProps {\n\tslots?: Partial<EditorSlotsMap>;\n\tchildren: React.ReactNode;\n}\n\n/**\n * Context provider allowing consumers to inject custom design system components into the editor.\n */\nexport function EditorSlotsProvider({ slots, children }: EditorSlotsProviderProps) {\n\tconst mergedSlots = useMemo(() => ({ ...defaultSlots, ...slots }), [slots]);\n\n\treturn (\n\t\t<EditorSlotsContext.Provider value={mergedSlots}>\n\t\t\t{children}\n\t\t</EditorSlotsContext.Provider>\n\t);\n}\n\n/**\n * Hook to access injected design system slots.\n */\nexport function useEditorSlots(): EditorSlotsMap {\n\treturn useContext(EditorSlotsContext);\n}\n","import { useCallback, useMemo, useSyncExternalStore } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport {\n getCommentStore,\n getTrackChangesStore,\n type CommentStore,\n type CommentStoreSnapshot,\n type TrackChangesSnapshot,\n type TrackedChange,\n} from \"@pixerate/editor\";\n\nconst EMPTY_COMMENTS: CommentStoreSnapshot = Object.freeze({\n threads: [],\n activeThreadId: null,\n}) as CommentStoreSnapshot;\n\nconst EMPTY_TRACK_CHANGES: TrackChangesSnapshot = Object.freeze({\n enabled: false,\n author: { id: \"anonymous\", name: \"Anonymous\" },\n changes: [],\n currentChangeId: null,\n}) as TrackChangesSnapshot;\n\nconst noopUnsubscribe = () => {};\n\nfunction isCommentStore(value: unknown): value is CommentStore {\n return (\n !!value &&\n typeof (value as CommentStore).getSnapshot === \"function\" &&\n typeof (value as CommentStore).createThread === \"function\"\n );\n}\n\nexport interface UseCommentsResult extends CommentStoreSnapshot {\n store: CommentStore | null;\n}\n\n/**\n * Subscribes to a comment store: pass the store itself, or an editor using\n * the `Comments` extension (`null` while the editor is being created).\n */\nexport function useComments(\n source: Editor | CommentStore | null | undefined,\n): UseCommentsResult {\n const store = isCommentStore(source) ? source : getCommentStore(source as Editor | null);\n const subscribe = useCallback(\n (onChange: () => void) => (store ? store.subscribe(() => onChange()) : noopUnsubscribe),\n [store],\n );\n const getSnapshot = () => store?.getSnapshot() ?? EMPTY_COMMENTS;\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n return useMemo(() => ({ ...snapshot, store }), [snapshot, store]);\n}\n\nexport interface UseTrackChangesResult extends TrackChangesSnapshot {\n currentChange: TrackedChange | null;\n setEnabled: (enabled: boolean) => void;\n toggle: () => void;\n accept: (id: string) => void;\n reject: (id: string) => void;\n acceptAll: () => void;\n rejectAll: () => void;\n next: () => void;\n previous: () => void;\n}\n\n/**\n * Subscribes to the tracked-change state of an editor using the\n * `TrackChanges` extension and exposes its commands.\n */\nexport function useTrackChanges(editor: Editor | null | undefined): UseTrackChangesResult {\n const store = getTrackChangesStore(editor ?? null);\n const subscribe = useCallback(\n (onChange: () => void) => (store ? store.subscribe(() => onChange()) : noopUnsubscribe),\n [store],\n );\n const getSnapshot = () => store?.getSnapshot() ?? EMPTY_TRACK_CHANGES;\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n return useMemo(() => {\n const run = (fn: (e: Editor) => void) => () => {\n if (editor && !editor.isDestroyed) fn(editor);\n };\n return {\n ...snapshot,\n currentChange:\n snapshot.changes.find((c) => c.id === snapshot.currentChangeId) ?? null,\n setEnabled: (enabled: boolean) => run((e) => e.commands.setTrackChanges(enabled))(),\n toggle: run((e) => e.commands.toggleTrackChanges()),\n accept: (id: string) => run((e) => e.commands.acceptChange(id))(),\n reject: (id: string) => run((e) => e.commands.rejectChange(id))(),\n acceptAll: run((e) => e.commands.acceptAllChanges()),\n rejectAll: run((e) => e.commands.rejectAllChanges()),\n next: run((e) => e.chain().focus().selectNextChange().run()),\n previous: run((e) => e.chain().focus().selectPreviousChange().run()),\n };\n }, [snapshot, editor]);\n}\n","import React, { useState } from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport {\n formatReviewTime,\n getCommentAuthor,\n type CommentStore,\n type CommentThread,\n type ReviewAuthor,\n} from \"@pixerate/editor\";\nimport { useComments } from \"./useReview\";\n\nexport interface CommentsPanelProps {\n editor: Editor | null;\n /** Defaults to the store of the editor's `Comments` extension. */\n store?: CommentStore;\n /** Author of replies. Defaults to the `Comments` extension's author. */\n author?: ReviewAuthor;\n /** Initially show resolved threads. */\n showResolved?: boolean;\n className?: string;\n formatTime?: (timestamp: number) => string;\n emptyMessage?: string;\n}\n\nconst buttonClass =\n \"rounded px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50\";\nconst primaryButtonClass =\n \"rounded px-2 py-1 text-xs bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-50\";\nconst textareaClass =\n \"w-full resize-y rounded-md border border-input bg-background p-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary\";\n\n/**\n * Lists comment threads with reply, resolve and delete actions. Clicking a\n * thread selects its text in the editor. Threads with an empty body are\n * drafts (e.g. created by `CommentButton`) and show a compose box.\n */\nexport const CommentsPanel: React.FC<CommentsPanelProps> = ({\n editor,\n store: storeProp,\n author: authorProp,\n showResolved: showResolvedInitial = false,\n className = \"flex flex-col gap-2 text-sm text-foreground\",\n formatTime = (t) => formatReviewTime(t),\n emptyMessage = \"No comments yet. Select text and add a comment.\",\n}) => {\n const { threads, activeThreadId, store } = useComments(storeProp ?? editor);\n const [showResolved, setShowResolved] = useState(showResolvedInitial);\n const author = authorProp ?? getCommentAuthor(editor) ?? { id: \"anonymous\", name: \"Anonymous\" };\n\n const visible = threads.filter((t) => showResolved || !t.resolved);\n const resolvedCount = threads.filter((t) => t.resolved).length;\n\n return (\n <aside className={className} aria-label=\"Comments\">\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"text-xs font-medium text-muted-foreground\">\n {threads.length - resolvedCount} open\n {resolvedCount > 0 ? ` · ${resolvedCount} resolved` : \"\"}\n </span>\n {resolvedCount > 0 && (\n <button\n type=\"button\"\n className={buttonClass}\n aria-pressed={showResolved}\n onClick={() => setShowResolved((v) => !v)}\n >\n {showResolved ? \"Hide resolved\" : \"Show resolved\"}\n </button>\n )}\n </div>\n {visible.length === 0 ? (\n <p className=\"text-xs text-muted-foreground\">{emptyMessage}</p>\n ) : (\n <ul className=\"flex flex-col gap-2\" role=\"list\">\n {visible.map((thread) => (\n <CommentThreadCard\n key={thread.id}\n thread={thread}\n active={thread.id === activeThreadId}\n editor={editor}\n store={store}\n author={author}\n formatTime={formatTime}\n />\n ))}\n </ul>\n )}\n </aside>\n );\n};\n\ninterface CommentThreadCardProps {\n thread: CommentThread;\n active: boolean;\n editor: Editor | null;\n store: CommentStore | null;\n author: ReviewAuthor;\n formatTime: (timestamp: number) => string;\n}\n\nconst CommentThreadCard: React.FC<CommentThreadCardProps> = ({\n thread,\n active,\n editor,\n store,\n author,\n formatTime,\n}) => {\n const [draft, setDraft] = useState(\"\");\n const isDraft = thread.body === \"\";\n const quote = thread.anchor?.quote ?? thread.lastQuote ?? \"\";\n const live = editor && !editor.isDestroyed ? editor : null;\n\n const focus = () => {\n if (!active) {\n if (live && !thread.orphaned) live.commands.focusComment(thread.id);\n else store?.setActiveThread(thread.id);\n }\n };\n const remove = () => {\n if (live) live.commands.deleteComment(thread.id);\n else store?.deleteThread(thread.id);\n };\n const setResolved = (resolved: boolean) => {\n if (live) live.commands.resolveComment(thread.id, resolved);\n else store?.resolveThread(thread.id, resolved, author);\n };\n const submit = () => {\n const body = draft.trim();\n if (!body || !store) return;\n if (isDraft) store.editComment(thread.id, body);\n else store.addReply(thread.id, { body, author });\n setDraft(\"\");\n };\n const stop = (e: React.SyntheticEvent) => e.stopPropagation();\n\n return (\n <li\n className={`flex flex-col gap-2 rounded-md border bg-background p-3 cursor-pointer ${\n active ? \"border-primary ring-1 ring-primary\" : \"border-border\"\n } ${thread.resolved ? \"opacity-70\" : \"\"}`}\n data-thread-id={thread.id}\n data-active={active || undefined}\n aria-current={active || undefined}\n tabIndex={0}\n onClick={focus}\n onKeyDown={(e) => {\n if (e.target === e.currentTarget && (e.key === \"Enter\" || e.key === \" \")) {\n e.preventDefault();\n focus();\n }\n }}\n >\n <div className=\"flex items-baseline justify-between gap-2\">\n <span className=\"font-medium\">{thread.author.name}</span>\n <span className=\"text-xs text-muted-foreground\">{formatTime(thread.createdAt)}</span>\n </div>\n {quote && (\n <blockquote className=\"border-l-2 border-border pl-2 text-xs text-muted-foreground line-clamp-2\">\n {quote}\n </blockquote>\n )}\n {thread.orphaned && (\n <span className=\"text-xs text-destructive\">The commented text was deleted.</span>\n )}\n {thread.resolved && <span className=\"text-xs text-muted-foreground\">Resolved</span>}\n {!isDraft && <p className=\"whitespace-pre-wrap break-words\">{thread.body}</p>}\n {thread.replies.length > 0 && (\n <ul className=\"flex flex-col gap-2 border-l border-border pl-3\" role=\"list\">\n {thread.replies.map((reply) => (\n <li key={reply.id} className=\"flex flex-col gap-0.5\" data-reply-id={reply.id}>\n <span className=\"text-xs\">\n <span className=\"font-medium\">{reply.author.name}</span>{\" \"}\n <span className=\"text-muted-foreground\">{formatTime(reply.createdAt)}</span>\n </span>\n <p className=\"whitespace-pre-wrap break-words\">{reply.body}</p>\n </li>\n ))}\n </ul>\n )}\n {(active || isDraft) && !thread.resolved && (\n <div className=\"flex flex-col gap-1\" onClick={stop}>\n <textarea\n className={textareaClass}\n rows={2}\n value={draft}\n aria-label={isDraft ? \"Comment\" : \"Reply\"}\n placeholder={isDraft ? \"Add a comment…\" : \"Reply…\"}\n autoFocus={isDraft}\n onChange={(e) => setDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n e.preventDefault();\n submit();\n }\n }}\n />\n <div className=\"flex justify-end gap-1\">\n {isDraft && (\n <button type=\"button\" className={buttonClass} onClick={remove}>\n Cancel\n </button>\n )}\n <button\n type=\"button\"\n className={primaryButtonClass}\n disabled={!draft.trim()}\n onClick={submit}\n >\n {isDraft ? \"Comment\" : \"Reply\"}\n </button>\n </div>\n </div>\n )}\n {!isDraft && (\n <div className=\"flex justify-end gap-1\" onClick={stop}>\n <button type=\"button\" className={buttonClass} onClick={() => setResolved(!thread.resolved)}>\n {thread.resolved ? \"Reopen\" : \"Resolve\"}\n </button>\n <button\n type=\"button\"\n className={`${buttonClass} hover:text-destructive`}\n onClick={remove}\n >\n Delete\n </button>\n </div>\n )}\n </li>\n );\n};\n","import React from \"react\";\nimport type { Editor } from \"@tiptap/core\";\nimport { useTrackChanges } from \"./useReview\";\n\nexport interface ReviewToolbarProps {\n editor: Editor | null;\n className?: string;\n /**\n * Show the current change's author and description (e.g. \"Alice: Formatted:\n * Bold\"). Defaults to `true`.\n */\n showDescription?: boolean;\n /** Class of the description label. */\n descriptionClassName?: string;\n}\n\nconst defaultDescriptionClass = \"max-w-[16rem] truncate px-1 text-xs text-muted-foreground\";\n\nconst buttonClass =\n \"rounded px-2 py-1 text-xs text-foreground hover:bg-muted disabled:opacity-40 disabled:hover:bg-transparent\";\n\n/**\n * Toolbar for tracked changes: toggle tracking, step through changes\n * (insertions, deletions, formatting and block changes, with a description\n * of the current one), and accept or reject the current change or all\n * changes.\n */\nexport const ReviewToolbar: React.FC<ReviewToolbarProps> = ({\n editor,\n className = \"flex flex-wrap items-center gap-1 rounded-md border border-border bg-background p-1 text-sm\",\n showDescription = true,\n descriptionClassName = defaultDescriptionClass,\n}) => {\n const review = useTrackChanges(editor);\n const count = review.changes.length;\n const current = review.currentChange;\n const index = current ? review.changes.findIndex((c) => c.id === current.id) + 1 : 0;\n\n return (\n <div className={className} role=\"toolbar\" aria-label=\"Review\">\n <button\n type=\"button\"\n className={`${buttonClass} ${review.enabled ? \"bg-primary/10 text-primary\" : \"\"}`}\n aria-pressed={review.enabled}\n disabled={!editor}\n onClick={review.toggle}\n >\n {review.enabled ? \"Tracking on\" : \"Track changes\"}\n </button>\n <span className=\"mx-1 h-4 w-px bg-border\" aria-hidden=\"true\" />\n <button\n type=\"button\"\n className={buttonClass}\n aria-label=\"Previous change\"\n disabled={count === 0}\n onClick={review.previous}\n >\n ‹\n </button>\n <span className=\"min-w-[4rem] text-center text-xs text-muted-foreground\" aria-live=\"polite\">\n {count === 0 ? \"No changes\" : current ? `${index} of ${count}` : `${count} changes`}\n </span>\n <button\n type=\"button\"\n className={buttonClass}\n aria-label=\"Next change\"\n disabled={count === 0}\n onClick={review.next}\n >\n ›\n </button>\n {showDescription && current && (\n <span\n className={descriptionClassName}\n data-change-type={current.type}\n title={`${current.author.name}: ${current.description}`}\n >\n {current.author.name ? `${current.author.name}: ` : \"\"}\n {current.description}\n </span>\n )}\n <span className=\"mx-1 h-4 w-px bg-border\" aria-hidden=\"true\" />\n <button\n type=\"button\"\n className={buttonClass}\n disabled={!current}\n onClick={() => current && review.accept(current.id)}\n >\n Accept\n </button>\n <button\n type=\"button\"\n className={buttonClass}\n disabled={!current}\n onClick={() => current && review.reject(current.id)}\n >\n Reject\n </button>\n <button type=\"button\" className={buttonClass} disabled={count === 0} onClick={review.acceptAll}>\n Accept all\n </button>\n <button type=\"button\" className={buttonClass} disabled={count === 0} onClick={review.rejectAll}>\n Reject all\n </button>\n </div>\n );\n};\n","import React from \"react\";\nimport type { Editor } from \"@tiptap/core\";\n\nexport interface CommentButtonProps {\n editor: Editor | null;\n className?: string;\n children?: React.ReactNode;\n}\n\n/**\n * Adds a draft comment on the selection; drop it into a `BubbleMenu`. The\n * draft is completed in `CommentsPanel`.\n */\nexport const CommentButton: React.FC<CommentButtonProps> = ({\n editor,\n className = \"rounded px-2 py-1 text-xs text-popover-foreground hover:bg-muted\",\n children = \"Comment\",\n}) => (\n <button\n type=\"button\"\n className={className}\n disabled={!editor}\n onClick={() => editor?.chain().focus().addComment().run()}\n >\n {children}\n </button>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,WAAW,cAAc;AAC3C,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AACvB,OAAO,iBAAiB;AACxB,SAAS,aAAa;AACtB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAyDP,IAAM,oBAAgC,CAAC;AACvC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AAAA,QACX,oBAAkB,QAAQ;AAAA,QAC1B,OAAO,GAAG,QAAQ,OAAO,IAAI,KAAK,QAAQ,WAAW;AAAA,QAEpD;AAAA,kBAAQ,OAAO,OAAO,GAAG,QAAQ,OAAO,IAAI,OAAO;AAAA,UACnD,QAAQ;AAAA;AAAA;AAAA,IACX;AAAA,IAEF,gBAAAD,KAAC,UAAK,WAAU,2BAA0B,eAAY,QAAO;AAAA,IAC7D,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,WAAWE;AAAA,QACX,UAAU,CAAC;AAAA,QACX,SAAS,MAAM,WAAW,OAAO,OAAO,QAAQ,EAAE;AAAA,QACnD;AAAA;AAAA,IAED;AAAA,IACA,gBAAAF;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,WAAWE;AAAA,QACX,UAAU,CAAC;AAAA,QACX,SAAS,MAAM,WAAW,OAAO,OAAO,QAAQ,EAAE;AAAA,QACnD;AAAA;AAAA,IAED;AAAA,IACA,gBAAAF,KAAC,YAAO,MAAK,UAAS,WAAWE,cAAa,UAAU,UAAU,GAAG,SAAS,OAAO,WAAW,wBAEhG;AAAA,IACA,gBAAAF,KAAC,YAAO,MAAK,UAAS,WAAWE,cAAa,UAAU,UAAU,GAAG,SAAS,OAAO,WAAW,wBAEhG;AAAA,KACF;AAEJ;;;ACxFE,gBAAAC,YAAA;AALK,IAAM,gBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,YAAY;AAAA,EACZ,WAAW;AACb,MACE,gBAAAA;AAAA,EAAC;AAAA;AAAA,IACC,MAAK;AAAA,IACL;AAAA,IACA,UAAU,CAAC;AAAA,IACX,SAAS,MAAM,QAAQ,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI;AAAA,IAEvD;AAAA;AACH;","names":["useEditor","useEffect","useRef","useState","useCallback","useRef","useRef","useCallback","useMemo","useCallback","useEffect","useRef","useState","useSyncExternalStore","useEffect","useEffect","useMemo","useRef","useSyncExternalStore","useEffect","useEffect","useRef","useState","useMemo","jsx","useMemo","useState","jsx","jsxs","useMemo","useSyncExternalStore","jsx","jsxs","DirtyTracker","HistoryManager","createHistoryManager","bindDirtyToHistory","useMemo","jsx","jsxs","useCallback","useMemo","useSyncExternalStore","useState","jsx","jsxs","useState","jsx","jsxs","buttonClass","jsx"]}
@@ -1119,7 +1119,7 @@ var SpreadsheetEditor = ({
1119
1119
  {
1120
1120
  className: `truncate block max-w-full ${cell.error ? "text-destructive font-semibold" : ""}`,
1121
1121
  title: cell.error ? cell.errorMessage ?? cell.error : void 0,
1122
- children: cell.error || (cell.value ?? "")
1122
+ children: (0, import_spreadsheet5.formatCellDisplay)(cell)
1123
1123
  }
1124
1124
  ),
1125
1125
  activeSpill && (0, import_spreadsheet5.rangeContains)(activeSpill.range, rIdx, cIdx) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", className: "spreadsheet-spill-border", style: spillBorderStyle(activeSpill.range, rIdx, cIdx) }),