@liveblocks/react-tiptap 2.18.2 → 2.18.4-uns1

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 (100) hide show
  1. package/dist/{LiveblocksExtension.mjs → LiveblocksExtension.cjs} +41 -38
  2. package/dist/{LiveblocksExtension.mjs.map → LiveblocksExtension.cjs.map} +1 -1
  3. package/dist/LiveblocksExtension.js +37 -40
  4. package/dist/LiveblocksExtension.js.map +1 -1
  5. package/dist/ai/{AiExtension.mjs → AiExtension.cjs} +36 -32
  6. package/dist/ai/AiExtension.cjs.map +1 -0
  7. package/dist/ai/AiExtension.js +31 -35
  8. package/dist/ai/AiExtension.js.map +1 -1
  9. package/dist/ai/{AiToolbar.mjs → AiToolbar.cjs} +145 -142
  10. package/dist/ai/{AiToolbar.mjs.map → AiToolbar.cjs.map} +1 -1
  11. package/dist/ai/AiToolbar.js +141 -144
  12. package/dist/ai/AiToolbar.js.map +1 -1
  13. package/dist/{classnames.mjs → classnames.cjs} +4 -2
  14. package/dist/{classnames.mjs.map → classnames.cjs.map} +1 -1
  15. package/dist/classnames.js +1 -3
  16. package/dist/classnames.js.map +1 -1
  17. package/dist/comments/{AnchoredThreads.mjs → AnchoredThreads.cjs} +38 -36
  18. package/dist/comments/{AnchoredThreads.mjs.map → AnchoredThreads.cjs.map} +1 -1
  19. package/dist/comments/AnchoredThreads.js +35 -37
  20. package/dist/comments/AnchoredThreads.js.map +1 -1
  21. package/dist/comments/{CommentsExtension.mjs → CommentsExtension.cjs} +34 -32
  22. package/dist/comments/{CommentsExtension.mjs.map → CommentsExtension.cjs.map} +1 -1
  23. package/dist/comments/CommentsExtension.js +31 -33
  24. package/dist/comments/CommentsExtension.js.map +1 -1
  25. package/dist/comments/{FloatingComposer.mjs → FloatingComposer.cjs} +34 -31
  26. package/dist/comments/{FloatingComposer.mjs.map → FloatingComposer.cjs.map} +1 -1
  27. package/dist/comments/FloatingComposer.js +30 -33
  28. package/dist/comments/FloatingComposer.js.map +1 -1
  29. package/dist/comments/{FloatingThreads.mjs → FloatingThreads.cjs} +39 -36
  30. package/dist/comments/{FloatingThreads.mjs.map → FloatingThreads.cjs.map} +1 -1
  31. package/dist/comments/FloatingThreads.js +35 -38
  32. package/dist/comments/FloatingThreads.js.map +1 -1
  33. package/dist/context.cjs +24 -0
  34. package/dist/{context.mjs.map → context.cjs.map} +1 -1
  35. package/dist/context.js +8 -11
  36. package/dist/context.js.map +1 -1
  37. package/dist/index.cjs +29 -0
  38. package/dist/{index.mjs.map → index.cjs.map} +1 -1
  39. package/dist/index.js +13 -27
  40. package/dist/index.js.map +1 -1
  41. package/dist/mentions/{Avatar.mjs → Avatar.cjs} +16 -14
  42. package/dist/mentions/Avatar.cjs.map +1 -0
  43. package/dist/mentions/Avatar.js +13 -15
  44. package/dist/mentions/Avatar.js.map +1 -1
  45. package/dist/mentions/Mention.cjs +31 -0
  46. package/dist/mentions/Mention.cjs.map +1 -0
  47. package/dist/mentions/Mention.js +25 -25
  48. package/dist/mentions/Mention.js.map +1 -1
  49. package/dist/mentions/{MentionExtension.mjs → MentionExtension.cjs} +35 -33
  50. package/dist/mentions/{MentionExtension.mjs.map → MentionExtension.cjs.map} +1 -1
  51. package/dist/mentions/MentionExtension.js +32 -34
  52. package/dist/mentions/MentionExtension.js.map +1 -1
  53. package/dist/mentions/{MentionNode.mjs → MentionNode.cjs} +12 -10
  54. package/dist/mentions/{MentionNode.mjs.map → MentionNode.cjs.map} +1 -1
  55. package/dist/mentions/MentionNode.js +9 -11
  56. package/dist/mentions/MentionNode.js.map +1 -1
  57. package/dist/mentions/{MentionsList.mjs → MentionsList.cjs} +39 -35
  58. package/dist/mentions/{MentionsList.mjs.map → MentionsList.cjs.map} +1 -1
  59. package/dist/mentions/MentionsList.js +34 -38
  60. package/dist/mentions/MentionsList.js.map +1 -1
  61. package/dist/toolbar/{FloatingToolbar.mjs → FloatingToolbar.cjs} +67 -64
  62. package/dist/toolbar/{FloatingToolbar.mjs.map → FloatingToolbar.cjs.map} +1 -1
  63. package/dist/toolbar/FloatingToolbar.js +63 -66
  64. package/dist/toolbar/FloatingToolbar.js.map +1 -1
  65. package/dist/toolbar/{Toolbar.mjs → Toolbar.cjs} +116 -91
  66. package/dist/toolbar/{Toolbar.mjs.map → Toolbar.cjs.map} +1 -1
  67. package/dist/toolbar/Toolbar.js +90 -115
  68. package/dist/toolbar/Toolbar.js.map +1 -1
  69. package/dist/toolbar/shared.cjs +36 -0
  70. package/dist/toolbar/{shared.mjs.map → shared.cjs.map} +1 -1
  71. package/dist/toolbar/shared.js +12 -15
  72. package/dist/toolbar/shared.js.map +1 -1
  73. package/dist/types.cjs +39 -0
  74. package/dist/{types.mjs.map → types.cjs.map} +1 -1
  75. package/dist/types.js +8 -19
  76. package/dist/types.js.map +1 -1
  77. package/dist/{utils.mjs → utils.cjs} +23 -14
  78. package/dist/{utils.mjs.map → utils.cjs.map} +1 -1
  79. package/dist/utils.js +13 -22
  80. package/dist/utils.js.map +1 -1
  81. package/dist/version-history/{HistoryVersionPreview.mjs → HistoryVersionPreview.cjs} +36 -34
  82. package/dist/version-history/{HistoryVersionPreview.mjs.map → HistoryVersionPreview.cjs.map} +1 -1
  83. package/dist/version-history/HistoryVersionPreview.js +33 -35
  84. package/dist/version-history/HistoryVersionPreview.js.map +1 -1
  85. package/dist/version.cjs +10 -0
  86. package/dist/{version.mjs.map → version.cjs.map} +1 -1
  87. package/dist/version.js +3 -7
  88. package/dist/version.js.map +1 -1
  89. package/package.json +18 -17
  90. package/styles.css.d.cts +1 -0
  91. package/dist/ai/AiExtension.mjs.map +0 -1
  92. package/dist/context.mjs +0 -21
  93. package/dist/index.mjs +0 -15
  94. package/dist/mentions/Avatar.mjs.map +0 -1
  95. package/dist/mentions/Mention.mjs +0 -27
  96. package/dist/mentions/Mention.mjs.map +0 -1
  97. package/dist/toolbar/shared.mjs +0 -33
  98. package/dist/types.mjs +0 -28
  99. package/dist/version.mjs +0 -6
  100. /package/dist/{index.d.mts → index.d.cts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Toolbar.js","sources":["../../src/toolbar/Toolbar.tsx"],"sourcesContent":["import {\n BlockquoteIcon,\n BoldIcon,\n Button,\n CheckIcon,\n CodeIcon,\n CommentIcon,\n H1Icon,\n H2Icon,\n H3Icon,\n ItalicIcon,\n ListOrderedIcon,\n ListUnorderedIcon,\n QuestionMarkIcon,\n RedoIcon,\n SelectButton,\n ShortcutTooltip,\n SparklesIcon,\n StrikethroughIcon,\n TextIcon,\n TooltipProvider,\n UnderlineIcon,\n UndoIcon,\n} from \"@liveblocks/react-ui/_private\";\nimport * as SelectPrimitive from \"@radix-ui/react-select\";\nimport * as TogglePrimitive from \"@radix-ui/react-toggle\";\nimport type { Editor } from \"@tiptap/react\";\nimport type {\n ComponentProps,\n ComponentType,\n KeyboardEvent,\n ReactNode,\n} from \"react\";\nimport { forwardRef, useCallback, useContext, useMemo } from \"react\";\n\nimport { classNames } from \"../classnames\";\nimport { EditorProvider, useCurrentEditor } from \"../context\";\nimport type { AiExtensionStorage, ExtendedChainedCommands } from \"../types\";\nimport { FloatingToolbarContext, FloatingToolbarExternal } from \"./shared\";\n\nexport const BLOCK_SELECT_SIDE_OFFSET = 10;\nexport const FLOATING_ELEMENT_COLLISION_PADDING = 10;\n\nexport interface ToolbarSlotProps {\n editor: Editor;\n}\n\nexport type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;\n\nexport interface ToolbarProps extends Omit<ComponentProps<\"div\">, \"children\"> {\n /**\n * The Tiptap editor.\n */\n editor: Editor | null;\n\n /**\n * The content of the toolbar, overriding the default content.\n * Use the `before` and `after` props if you want to keep and extend the default content.\n */\n children?: ToolbarSlot;\n\n /**\n * The content to display at the start of the toolbar.\n */\n before?: ToolbarSlot;\n\n /**\n * The content to display at the end of the toolbar.\n */\n after?: ToolbarSlot;\n}\n\nexport interface ToolbarButtonProps extends ComponentProps<\"button\"> {\n /**\n * The name of this button displayed in its tooltip.\n */\n name: string;\n\n /**\n * An optional icon displayed in this button.\n */\n icon?: ReactNode;\n\n /**\n * An optional keyboard shortcut displayed in this button's tooltip.\n *\n * @example\n * \"Mod-Alt-B\" → \"⌘⌥B\" in Apple environments, \"⌃⌥B\" otherwise\n * \"Ctrl-Shift-Escape\" → \"⌃⇧⎋\"\n * \"Space\" → \"␣\"\n */\n shortcut?: string;\n}\n\nexport interface ToolbarToggleProps extends ToolbarButtonProps {\n /**\n * Whether the button is toggled.\n */\n active: boolean;\n}\n\nexport interface ToolbarBlockSelectorItem {\n /**\n * The name of this block element, displayed as the label of this item.\n */\n name: string;\n\n /**\n * Optionally replace the name used as the label of this item by any content.\n */\n label?: ReactNode;\n\n /**\n * An optional icon displayed in this item.\n */\n icon?: ReactNode;\n\n /**\n * Whether this block element is currently active.\n * Set to `\"default\"` to display this item when no other item is active.\n */\n isActive: ((editor: Editor) => boolean) | \"default\";\n\n /**\n * A callback invoked when this item is selected.\n */\n setActive: (editor: Editor) => void;\n}\n\nexport interface ToolbarBlockSelectorProps extends ComponentProps<\"button\"> {\n /**\n * The items displayed in this block selector.\n * When provided as an array, the default items are overridden. To avoid this,\n * a function can be provided instead and it will receive the default items.\n *\n * @example\n * <Toolbar.BlockSelector\n * items={[\n * {\n * name: \"Text\",\n * isActive: \"default\",\n * setActive: () => { ... },\n * },\n * {\n * name: \"Heading 1\",\n * isActive: () => { ... },\n * setActive: () => { ... },\n * },\n * ]}\n * />\n *\n * @example\n * <Toolbar.BlockSelector\n * items={(defaultItems) => [\n * ...defaultItems,\n * {\n * name: \"Custom block\",\n * isActive: () => { ... },\n * setActive: () => { ... },\n * },\n * ]}\n * />\n */\n items?:\n | ToolbarBlockSelectorItem[]\n | ((\n defaultItems: ToolbarBlockSelectorItem[]\n ) => ToolbarBlockSelectorItem[]);\n}\n\nexport type ToolbarSeparatorProps = ComponentProps<\"div\">;\n\nexport function applyToolbarSlot(\n slot: ToolbarSlot,\n props: ToolbarSlotProps\n): ReactNode {\n if (typeof slot === \"function\") {\n const Component = slot;\n\n return <Component {...props} />;\n }\n\n return slot;\n}\n\nconst ToolbarButton = forwardRef<HTMLButtonElement, ToolbarButtonProps>(\n ({ icon, children, name, shortcut, onKeyDown, ...props }, forwardedRef) => {\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const closeFloatingToolbar = floatingToolbarContext?.close;\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLButtonElement>) => {\n onKeyDown?.(event);\n\n if (\n !event.isDefaultPrevented() &&\n closeFloatingToolbar &&\n event.key === \"Escape\"\n ) {\n closeFloatingToolbar();\n event.preventDefault();\n event.stopPropagation();\n }\n },\n [onKeyDown, closeFloatingToolbar]\n );\n\n return (\n <ShortcutTooltip content={name} shortcut={shortcut}>\n <Button\n type=\"button\"\n variant=\"toolbar\"\n ref={forwardedRef}\n icon={icon}\n aria-label={!children ? name : undefined}\n {...props}\n onKeyDown={handleKeyDown}\n >\n {!children && !icon ? name : children}\n </Button>\n </ShortcutTooltip>\n );\n }\n);\n\nconst ToolbarToggle = forwardRef<HTMLButtonElement, ToolbarToggleProps>(\n ({ active, ...props }, forwardedRef) => {\n return (\n <TogglePrimitive.Root asChild pressed={active}>\n <ToolbarButton ref={forwardedRef} {...props} />\n </TogglePrimitive.Root>\n );\n }\n);\n\nfunction createDefaultBlockSelectorItems(\n editor: Editor\n): ToolbarBlockSelectorItem[] {\n const items: (ToolbarBlockSelectorItem | null)[] = [\n {\n name: \"Text\",\n icon: <TextIcon />,\n isActive: \"default\",\n setActive: (editor) => editor.chain().focus().clearNodes().run(),\n },\n \"toggleHeading\" in editor.commands\n ? {\n name: \"Heading 1\",\n icon: <H1Icon />,\n isActive: (editor) => editor.isActive(\"heading\", { level: 1 }),\n setActive: (editor) =>\n (\n editor.chain().focus().clearNodes() as ExtendedChainedCommands<\n \"toggleHeading\",\n [{ level: number }]\n >\n )\n .toggleHeading({ level: 1 })\n .run(),\n }\n : null,\n \"toggleHeading\" in editor.commands\n ? {\n name: \"Heading 2\",\n icon: <H2Icon />,\n isActive: (editor) => editor.isActive(\"heading\", { level: 2 }),\n setActive: (editor) =>\n (\n editor.chain().focus().clearNodes() as ExtendedChainedCommands<\n \"toggleHeading\",\n [{ level: number }]\n >\n )\n .toggleHeading({ level: 2 })\n .run(),\n }\n : null,\n \"toggleHeading\" in editor.commands\n ? {\n name: \"Heading 3\",\n icon: <H3Icon />,\n isActive: (editor) => editor.isActive(\"heading\", { level: 3 }),\n setActive: (editor) =>\n (\n editor.chain().focus().clearNodes() as ExtendedChainedCommands<\n \"toggleHeading\",\n [{ level: number }]\n >\n )\n .toggleHeading({ level: 3 })\n .run(),\n }\n : null,\n \"toggleBulletList\" in editor.commands\n ? {\n name: \"Bullet list\",\n icon: <ListUnorderedIcon />,\n isActive: (editor) => editor.isActive(\"bulletList\"),\n setActive: (editor) =>\n (\n editor\n .chain()\n .focus()\n .clearNodes() as ExtendedChainedCommands<\"toggleBulletList\">\n )\n .toggleBulletList()\n .run(),\n }\n : null,\n \"toggleOrderedList\" in editor.commands\n ? {\n name: \"Numbered list\",\n icon: <ListOrderedIcon />,\n isActive: (editor) => editor.isActive(\"orderedList\"),\n setActive: (editor) =>\n (\n editor\n .chain()\n .focus()\n .clearNodes() as ExtendedChainedCommands<\"toggleOrderedList\">\n )\n .toggleOrderedList()\n .run(),\n }\n : null,\n \"toggleBlockquote\" in editor.commands\n ? {\n name: \"Blockquote\",\n icon: <BlockquoteIcon />,\n isActive: (editor) => editor.isActive(\"blockquote\"),\n setActive: (editor) =>\n (\n editor\n .chain()\n .focus()\n .clearNodes() as ExtendedChainedCommands<\"toggleBlockquote\">\n )\n .toggleBlockquote()\n .run(),\n }\n : null,\n ];\n\n return items.filter(Boolean) as ToolbarBlockSelectorItem[];\n}\n\nconst ToolbarBlockSelector = forwardRef<\n HTMLButtonElement,\n ToolbarBlockSelectorProps\n>(({ items, onKeyDown, ...props }, forwardedRef) => {\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const closeFloatingToolbar = floatingToolbarContext?.close;\n const editor = useCurrentEditor(\n \"BlockSelector\",\n \"Toolbar or FloatingToolbar\"\n );\n const resolvedItems = useMemo(() => {\n if (Array.isArray(items)) {\n return items;\n }\n\n const defaultItems = createDefaultBlockSelectorItems(editor);\n\n return items ? items(defaultItems) : defaultItems;\n }, [editor, items]);\n let defaultItem: ToolbarBlockSelectorItem | undefined;\n let activeItem = editor.isInitialized\n ? resolvedItems.find((item) => {\n if (item.isActive === \"default\") {\n defaultItem = item;\n return false;\n }\n\n return item.isActive(editor);\n })\n : undefined;\n\n if (!activeItem) {\n activeItem = defaultItem;\n }\n\n const handleItemChange = (name: string) => {\n const item = resolvedItems.find((item) => item.name === name);\n\n if (item) {\n item.setActive(editor);\n\n // If present in a floating toolbar, close it on change\n floatingToolbarContext?.close();\n }\n };\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLButtonElement>) => {\n onKeyDown?.(event);\n\n if (\n !event.isDefaultPrevented() &&\n closeFloatingToolbar &&\n event.key === \"Escape\"\n ) {\n closeFloatingToolbar();\n event.preventDefault();\n event.stopPropagation();\n }\n },\n [onKeyDown, closeFloatingToolbar]\n );\n\n return (\n <SelectPrimitive.Root\n value={activeItem?.name}\n onValueChange={handleItemChange}\n >\n <ShortcutTooltip content=\"Turn into…\">\n <SelectPrimitive.Trigger\n asChild\n {...props}\n ref={forwardedRef}\n onKeyDown={handleKeyDown}\n disabled={resolvedItems.length === 0}\n >\n <SelectButton variant=\"toolbar\">\n {activeItem?.name ?? \"Turn into…\"}\n </SelectButton>\n </SelectPrimitive.Trigger>\n </ShortcutTooltip>\n <SelectPrimitive.Portal>\n <FloatingToolbarExternal>\n <SelectPrimitive.Content\n position=\"popper\"\n sideOffset={BLOCK_SELECT_SIDE_OFFSET}\n collisionPadding={FLOATING_ELEMENT_COLLISION_PADDING}\n className=\"lb-root lb-portal lb-elevation lb-dropdown lb-select-dropdown lb-tiptap-block-selector-dropdown\"\n >\n {resolvedItems.map((item) => (\n <SelectPrimitive.Item\n key={item.name}\n value={item.name}\n className=\"lb-dropdown-item\"\n data-name={item.name}\n >\n {item.icon ? (\n <span className=\"lb-dropdown-item-icon lb-icon-container\">\n {item.icon}\n </span>\n ) : null}\n <span className=\"lb-dropdown-item-label\">\n {item.label ?? item.name}\n </span>\n {item.name === activeItem?.name ? (\n <span className=\"lb-dropdown-item-accessory lb-icon-container\">\n <CheckIcon />\n </span>\n ) : null}\n </SelectPrimitive.Item>\n ))}\n </SelectPrimitive.Content>\n </FloatingToolbarExternal>\n </SelectPrimitive.Portal>\n </SelectPrimitive.Root>\n );\n});\n\nconst ToolbarSeparator = forwardRef<HTMLDivElement, ToolbarSeparatorProps>(\n ({ className, ...props }, forwardedRef) => {\n return (\n <div\n ref={forwardedRef}\n role=\"separator\"\n aria-orientation=\"vertical\"\n className={classNames(\"lb-tiptap-toolbar-separator\", className)}\n {...props}\n />\n );\n }\n);\n\nfunction ToolbarSectionHistory() {\n const editor = useCurrentEditor(\n \"SectionHistory\",\n \"Toolbar or FloatingToolbar\"\n );\n\n return (\n <>\n <ToolbarButton\n name=\"Undo\"\n icon={<UndoIcon />}\n shortcut=\"Mod-Z\"\n onClick={() => editor.chain().focus().undo().run()}\n disabled={!editor.can().chain().focus().undo().run()}\n />\n <ToolbarButton\n name=\"Redo\"\n icon={<RedoIcon />}\n shortcut=\"Mod-Shift-Z\"\n onClick={() => editor.chain().focus().redo().run()}\n disabled={!editor.can().chain().focus().redo().run()}\n />\n </>\n );\n}\n\nfunction ToolbarSectionInline() {\n const editor = useCurrentEditor(\n \"SectionInline\",\n \"Toolbar or FloatingToolbar\"\n );\n const supportsBold = \"toggleBold\" in editor.commands;\n const supportsItalic = \"toggleItalic\" in editor.commands;\n const supportsUnderline = \"toggleUnderline\" in editor.commands;\n const supportsStrike = \"toggleStrike\" in editor.commands;\n const supportsCode = \"toggleCode\" in editor.commands;\n\n return (\n <>\n {supportsBold && (\n <ToolbarToggle\n name=\"Bold\"\n icon={<BoldIcon />}\n shortcut=\"Mod-B\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleBold\">)\n .toggleBold()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleBold\">\n )\n .toggleBold()\n .run()\n }\n active={editor.isActive(\"bold\")}\n />\n )}\n {supportsItalic && (\n <ToolbarToggle\n name=\"Italic\"\n icon={<ItalicIcon />}\n shortcut=\"Mod-I\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleItalic\">)\n .toggleItalic()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleItalic\">\n )\n .toggleItalic()\n .run()\n }\n active={editor.isActive(\"italic\")}\n />\n )}\n {supportsUnderline && (\n <ToolbarToggle\n name=\"Underline\"\n icon={<UnderlineIcon />}\n shortcut=\"Mod-U\"\n onClick={() =>\n (\n editor\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleUnderline\">\n )\n .toggleUnderline()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleUnderline\">\n )\n .toggleUnderline()\n .run()\n }\n active={editor.isActive(\"underline\")}\n />\n )}\n {supportsStrike && (\n <ToolbarToggle\n name=\"Strikethrough\"\n icon={<StrikethroughIcon />}\n shortcut=\"Mod-U\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleStrike\">)\n .toggleStrike()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleStrike\">\n )\n .toggleStrike()\n .run()\n }\n active={editor.isActive(\"strike\")}\n />\n )}\n {supportsCode && (\n <ToolbarToggle\n name=\"Inline code\"\n icon={<CodeIcon />}\n shortcut=\"Mod-E\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleCode\">)\n .toggleCode()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleCode\">\n )\n .toggleCode()\n .run()\n }\n active={editor.isActive(\"code\")}\n />\n )}\n </>\n );\n}\n\nfunction ToolbarSectionCollaboration() {\n const editor = useCurrentEditor(\n \"SectionCollaboration\",\n \"Toolbar or FloatingToolbar\"\n );\n const supportsThread = \"addPendingComment\" in editor.commands;\n\n return (\n <>\n {supportsThread && (\n <ToolbarButton\n name=\"Add a comment\"\n icon={<CommentIcon />}\n onClick={() =>\n (\n editor\n .chain()\n .focus() as ExtendedChainedCommands<\"addPendingComment\">\n )\n .addPendingComment()\n .run()\n }\n >\n Comment\n </ToolbarButton>\n )}\n </>\n );\n}\n\nfunction ToolbarSectionAi() {\n const editor = useCurrentEditor(\"SectionAi\", \"Toolbar or FloatingToolbar\");\n const supportsAi = \"askAi\" in editor.commands;\n const aiName = (editor.storage.liveblocksAi as AiExtensionStorage | undefined)\n ?.name;\n\n return (\n <>\n {supportsAi && (\n <>\n <ToolbarButton\n name={`Ask ${aiName} anything…`}\n icon={<SparklesIcon />}\n onClick={() =>\n (\n editor.chain().focus() as ExtendedChainedCommands<\"askAi\">\n ).askAi()\n }\n >\n Ask {aiName}\n </ToolbarButton>\n <ToolbarButton\n name=\"Explain\"\n icon={<QuestionMarkIcon />}\n onClick={() =>\n (\n editor.chain().focus() as ExtendedChainedCommands<\"askAi\">\n ).askAi(\"Explain what the text is about\")\n }\n >\n Explain\n </ToolbarButton>\n </>\n )}\n </>\n );\n}\n\nfunction DefaultToolbarContent({ editor }: ToolbarSlotProps) {\n const supportsThread = \"addPendingComment\" in editor.commands;\n const supportsAi = \"askAi\" in editor.commands;\n\n return (\n <>\n <ToolbarSectionHistory />\n <ToolbarSeparator />\n {supportsAi ? (\n <>\n <ToolbarSectionAi />\n <ToolbarSeparator />\n </>\n ) : null}\n <ToolbarBlockSelector />\n <ToolbarSectionInline />\n {supportsThread ? (\n <>\n <ToolbarSeparator />\n <ToolbarSectionCollaboration />\n </>\n ) : null}\n </>\n );\n}\n\n/**\n * A static toolbar containing actions and values related to the editor.\n *\n * @example\n * <Toolbar editor={editor} />\n *\n * @example\n * <Toolbar editor={editor}>\n * <Toolbar.BlockSelector />\n * <Toolbar.Separator />\n * <Toolbar.SectionInline />\n * <Toolbar.Separator />\n * <Toolbar.Button name=\"Custom action\" onClick={() => { ... }} icon={<Icon.QuestionMark />} />\n * </Toolbar>\n */\nexport const Toolbar = Object.assign(\n forwardRef<HTMLDivElement, ToolbarProps>(\n (\n {\n before,\n after,\n children = DefaultToolbarContent,\n editor,\n className,\n ...props\n },\n forwardedRef\n ) => {\n if (!editor) {\n return null;\n }\n\n const slotProps: ToolbarSlotProps = { editor };\n\n return (\n <TooltipProvider>\n <EditorProvider editor={editor}>\n <div\n ref={forwardedRef}\n role=\"toolbar\"\n aria-label=\"Toolbar\"\n aria-orientation=\"horizontal\"\n className={classNames(\"lb-root lb-tiptap-toolbar\", className)}\n {...props}\n >\n {applyToolbarSlot(before, slotProps)}\n {applyToolbarSlot(children, slotProps)}\n {applyToolbarSlot(after, slotProps)}\n </div>\n </EditorProvider>\n </TooltipProvider>\n );\n }\n ),\n {\n /**\n * A button for triggering actions.\n *\n * @example\n * <Toolbar.Button name=\"Comment\" shortcut=\"Mod-Shift-E\" onClick={() => { ... }} />\n *\n * @example\n * <Toolbar.Button name=\"Mention someone\" icon={<Icon.Mention />} onClick={() => { ... }} />\n */\n Button: ToolbarButton,\n\n /**\n * A toggle button for values that can be active or inactive.\n *\n * @example\n * <Toolbar.Toggle name=\"Bold\" active={isBold} />\n *\n * @example\n * <Toolbar.Toggle name=\"Italic\" icon={<Icon.Italic />} shortcut=\"Mod-I\" active={isItalic} onClick={() => { ... }} />\n */\n Toggle: ToolbarToggle,\n\n /**\n * A dropdown selector to switch between different block types.\n *\n * @example\n * <Toolbar.BlockSelector />\n */\n BlockSelector: ToolbarBlockSelector,\n\n /**\n * A visual (and accessible) separator to separate sections in a toolbar.\n */\n Separator: ToolbarSeparator,\n\n /**\n * A section containing history actions. (e.g. undo, redo)\n */\n SectionHistory: ToolbarSectionHistory,\n\n /**\n * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)\n */\n SectionInline: ToolbarSectionInline,\n\n /**\n * A section containing collaborative actions. (e.g. adding a comment)\n */\n SectionCollaboration: ToolbarSectionCollaboration,\n\n /**\n * A section containing AI actions. (e.g. opening the AI toolbar)\n */\n SectionAi: ToolbarSectionAi,\n }\n);\n"],"names":["jsx","forwardRef","useContext","FloatingToolbarContext","useCallback","ShortcutTooltip","Button","TogglePrimitive","TextIcon","editor","H1Icon","H2Icon","H3Icon","ListUnorderedIcon","ListOrderedIcon","BlockquoteIcon","useCurrentEditor","useMemo","item","jsxs","SelectPrimitive","SelectButton","FloatingToolbarExternal","CheckIcon","classNames","Fragment","UndoIcon","RedoIcon","BoldIcon","ItalicIcon","UnderlineIcon","StrikethroughIcon","CodeIcon","CommentIcon","SparklesIcon","QuestionMarkIcon","TooltipProvider","EditorProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,wBAA2B,GAAA,GAAA;AACjC,MAAM,kCAAqC,GAAA,GAAA;AAmIlC,SAAA,gBAAA,CACd,MACA,KACW,EAAA;AACX,EAAI,IAAA,OAAO,SAAS,UAAY,EAAA;AAC9B,IAAA,MAAM,SAAY,GAAA,IAAA,CAAA;AAElB,IAAA,uBAAQA,cAAA,CAAA,SAAA,EAAA;AAAA,MAAW,GAAG,KAAA;AAAA,KAAO,CAAA,CAAA;AAAA,GAC/B;AAEA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAEA,MAAM,aAAgB,GAAAC,gBAAA;AAAA,EACpB,CAAC,EAAE,IAAM,EAAA,QAAA,EAAU,MAAM,QAAU,EAAA,SAAA,EAAA,GAAc,KAAM,EAAA,EAAG,YAAiB,KAAA;AACzE,IAAM,MAAA,sBAAA,GAAyBC,iBAAWC,6BAAsB,CAAA,CAAA;AAChE,IAAA,MAAM,uB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;AAAA,UACd,QAAC,kBAAAlB,eAAA,CAAA,KAAA,EAAA;AAAA,YACC,GAAK,EAAA,YAAA;AAAA,YACL,IAAK,EAAA,SAAA;AAAA,YACL,YAAW,EAAA,SAAA;AAAA,YACX,kBAAiB,EAAA,YAAA;AAAA,YACjB,SAAA,EAAWK,qBAAW,CAAA,2BAAA,EAA6B,SAAS,CAAA;AAAA,YAC3D,GAAG,KAAA;AAAA,YAEH,QAAA,EAAA;AAAA,cAAA,gBAAA,CAAiB,QAAQ,SAAS,CAAA;AAAA,cAClC,gBAAA,CAAiB,UAAU,SAAS,CAAA;AAAA,cACpC,gBAAA,CAAiB,OAAO,SAAS,CAAA;AAAA,aAAA;AAAA,WACpC,CAAA;AAAA,SACF,CAAA;AAAA,OACF,CAAA,CAAA;AAAA,KAEJ;AAAA,GACF;AAAA,EACA;AAAA,IAUE,MAAQ,EAAA,aAAA;AAAA,IAWR,MAAQ,EAAA,aAAA;AAAA,IAQR,aAAe,EAAA,oBAAA;AAAA,IAKf,SAAW,EAAA,gBAAA;AAAA,IAKX,cAAgB,EAAA,qBAAA;AAAA,IAKhB,aAAe,EAAA,oBAAA;AAAA,IAKf,oBAAsB,EAAA,2BAAA;AAAA,IAKtB,SAAW,EAAA,gBAAA;AAAA,GACb;AACF;;;;;;;"}
1
+ {"version":3,"file":"Toolbar.js","sources":["../../src/toolbar/Toolbar.tsx"],"sourcesContent":["import {\n BlockquoteIcon,\n BoldIcon,\n Button,\n CheckIcon,\n CodeIcon,\n CommentIcon,\n H1Icon,\n H2Icon,\n H3Icon,\n ItalicIcon,\n ListOrderedIcon,\n ListUnorderedIcon,\n QuestionMarkIcon,\n RedoIcon,\n SelectButton,\n ShortcutTooltip,\n SparklesIcon,\n StrikethroughIcon,\n TextIcon,\n TooltipProvider,\n UnderlineIcon,\n UndoIcon,\n} from \"@liveblocks/react-ui/_private\";\nimport * as SelectPrimitive from \"@radix-ui/react-select\";\nimport * as TogglePrimitive from \"@radix-ui/react-toggle\";\nimport type { Editor } from \"@tiptap/react\";\nimport type {\n ComponentProps,\n ComponentType,\n KeyboardEvent,\n ReactNode,\n} from \"react\";\nimport { forwardRef, useCallback, useContext, useMemo } from \"react\";\n\nimport { classNames } from \"../classnames\";\nimport { EditorProvider, useCurrentEditor } from \"../context\";\nimport type { AiExtensionStorage, ExtendedChainedCommands } from \"../types\";\nimport { FloatingToolbarContext, FloatingToolbarExternal } from \"./shared\";\n\nexport const BLOCK_SELECT_SIDE_OFFSET = 10;\nexport const FLOATING_ELEMENT_COLLISION_PADDING = 10;\n\nexport interface ToolbarSlotProps {\n editor: Editor;\n}\n\nexport type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;\n\nexport interface ToolbarProps extends Omit<ComponentProps<\"div\">, \"children\"> {\n /**\n * The Tiptap editor.\n */\n editor: Editor | null;\n\n /**\n * The content of the toolbar, overriding the default content.\n * Use the `before` and `after` props if you want to keep and extend the default content.\n */\n children?: ToolbarSlot;\n\n /**\n * The content to display at the start of the toolbar.\n */\n before?: ToolbarSlot;\n\n /**\n * The content to display at the end of the toolbar.\n */\n after?: ToolbarSlot;\n}\n\nexport interface ToolbarButtonProps extends ComponentProps<\"button\"> {\n /**\n * The name of this button displayed in its tooltip.\n */\n name: string;\n\n /**\n * An optional icon displayed in this button.\n */\n icon?: ReactNode;\n\n /**\n * An optional keyboard shortcut displayed in this button's tooltip.\n *\n * @example\n * \"Mod-Alt-B\" → \"⌘⌥B\" in Apple environments, \"⌃⌥B\" otherwise\n * \"Ctrl-Shift-Escape\" → \"⌃⇧⎋\"\n * \"Space\" → \"␣\"\n */\n shortcut?: string;\n}\n\nexport interface ToolbarToggleProps extends ToolbarButtonProps {\n /**\n * Whether the button is toggled.\n */\n active: boolean;\n}\n\nexport interface ToolbarBlockSelectorItem {\n /**\n * The name of this block element, displayed as the label of this item.\n */\n name: string;\n\n /**\n * Optionally replace the name used as the label of this item by any content.\n */\n label?: ReactNode;\n\n /**\n * An optional icon displayed in this item.\n */\n icon?: ReactNode;\n\n /**\n * Whether this block element is currently active.\n * Set to `\"default\"` to display this item when no other item is active.\n */\n isActive: ((editor: Editor) => boolean) | \"default\";\n\n /**\n * A callback invoked when this item is selected.\n */\n setActive: (editor: Editor) => void;\n}\n\nexport interface ToolbarBlockSelectorProps extends ComponentProps<\"button\"> {\n /**\n * The items displayed in this block selector.\n * When provided as an array, the default items are overridden. To avoid this,\n * a function can be provided instead and it will receive the default items.\n *\n * @example\n * <Toolbar.BlockSelector\n * items={[\n * {\n * name: \"Text\",\n * isActive: \"default\",\n * setActive: () => { ... },\n * },\n * {\n * name: \"Heading 1\",\n * isActive: () => { ... },\n * setActive: () => { ... },\n * },\n * ]}\n * />\n *\n * @example\n * <Toolbar.BlockSelector\n * items={(defaultItems) => [\n * ...defaultItems,\n * {\n * name: \"Custom block\",\n * isActive: () => { ... },\n * setActive: () => { ... },\n * },\n * ]}\n * />\n */\n items?:\n | ToolbarBlockSelectorItem[]\n | ((\n defaultItems: ToolbarBlockSelectorItem[]\n ) => ToolbarBlockSelectorItem[]);\n}\n\nexport type ToolbarSeparatorProps = ComponentProps<\"div\">;\n\nexport function applyToolbarSlot(\n slot: ToolbarSlot,\n props: ToolbarSlotProps\n): ReactNode {\n if (typeof slot === \"function\") {\n const Component = slot;\n\n return <Component {...props} />;\n }\n\n return slot;\n}\n\nconst ToolbarButton = forwardRef<HTMLButtonElement, ToolbarButtonProps>(\n ({ icon, children, name, shortcut, onKeyDown, ...props }, forwardedRef) => {\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const closeFloatingToolbar = floatingToolbarContext?.close;\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLButtonElement>) => {\n onKeyDown?.(event);\n\n if (\n !event.isDefaultPrevented() &&\n closeFloatingToolbar &&\n event.key === \"Escape\"\n ) {\n closeFloatingToolbar();\n event.preventDefault();\n event.stopPropagation();\n }\n },\n [onKeyDown, closeFloatingToolbar]\n );\n\n return (\n <ShortcutTooltip content={name} shortcut={shortcut}>\n <Button\n type=\"button\"\n variant=\"toolbar\"\n ref={forwardedRef}\n icon={icon}\n aria-label={!children ? name : undefined}\n {...props}\n onKeyDown={handleKeyDown}\n >\n {!children && !icon ? name : children}\n </Button>\n </ShortcutTooltip>\n );\n }\n);\n\nconst ToolbarToggle = forwardRef<HTMLButtonElement, ToolbarToggleProps>(\n ({ active, ...props }, forwardedRef) => {\n return (\n <TogglePrimitive.Root asChild pressed={active}>\n <ToolbarButton ref={forwardedRef} {...props} />\n </TogglePrimitive.Root>\n );\n }\n);\n\nfunction createDefaultBlockSelectorItems(\n editor: Editor\n): ToolbarBlockSelectorItem[] {\n const items: (ToolbarBlockSelectorItem | null)[] = [\n {\n name: \"Text\",\n icon: <TextIcon />,\n isActive: \"default\",\n setActive: (editor) => editor.chain().focus().clearNodes().run(),\n },\n \"toggleHeading\" in editor.commands\n ? {\n name: \"Heading 1\",\n icon: <H1Icon />,\n isActive: (editor) => editor.isActive(\"heading\", { level: 1 }),\n setActive: (editor) =>\n (\n editor.chain().focus().clearNodes() as ExtendedChainedCommands<\n \"toggleHeading\",\n [{ level: number }]\n >\n )\n .toggleHeading({ level: 1 })\n .run(),\n }\n : null,\n \"toggleHeading\" in editor.commands\n ? {\n name: \"Heading 2\",\n icon: <H2Icon />,\n isActive: (editor) => editor.isActive(\"heading\", { level: 2 }),\n setActive: (editor) =>\n (\n editor.chain().focus().clearNodes() as ExtendedChainedCommands<\n \"toggleHeading\",\n [{ level: number }]\n >\n )\n .toggleHeading({ level: 2 })\n .run(),\n }\n : null,\n \"toggleHeading\" in editor.commands\n ? {\n name: \"Heading 3\",\n icon: <H3Icon />,\n isActive: (editor) => editor.isActive(\"heading\", { level: 3 }),\n setActive: (editor) =>\n (\n editor.chain().focus().clearNodes() as ExtendedChainedCommands<\n \"toggleHeading\",\n [{ level: number }]\n >\n )\n .toggleHeading({ level: 3 })\n .run(),\n }\n : null,\n \"toggleBulletList\" in editor.commands\n ? {\n name: \"Bullet list\",\n icon: <ListUnorderedIcon />,\n isActive: (editor) => editor.isActive(\"bulletList\"),\n setActive: (editor) =>\n (\n editor\n .chain()\n .focus()\n .clearNodes() as ExtendedChainedCommands<\"toggleBulletList\">\n )\n .toggleBulletList()\n .run(),\n }\n : null,\n \"toggleOrderedList\" in editor.commands\n ? {\n name: \"Numbered list\",\n icon: <ListOrderedIcon />,\n isActive: (editor) => editor.isActive(\"orderedList\"),\n setActive: (editor) =>\n (\n editor\n .chain()\n .focus()\n .clearNodes() as ExtendedChainedCommands<\"toggleOrderedList\">\n )\n .toggleOrderedList()\n .run(),\n }\n : null,\n \"toggleBlockquote\" in editor.commands\n ? {\n name: \"Blockquote\",\n icon: <BlockquoteIcon />,\n isActive: (editor) => editor.isActive(\"blockquote\"),\n setActive: (editor) =>\n (\n editor\n .chain()\n .focus()\n .clearNodes() as ExtendedChainedCommands<\"toggleBlockquote\">\n )\n .toggleBlockquote()\n .run(),\n }\n : null,\n ];\n\n return items.filter(Boolean) as ToolbarBlockSelectorItem[];\n}\n\nconst ToolbarBlockSelector = forwardRef<\n HTMLButtonElement,\n ToolbarBlockSelectorProps\n>(({ items, onKeyDown, ...props }, forwardedRef) => {\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const closeFloatingToolbar = floatingToolbarContext?.close;\n const editor = useCurrentEditor(\n \"BlockSelector\",\n \"Toolbar or FloatingToolbar\"\n );\n const resolvedItems = useMemo(() => {\n if (Array.isArray(items)) {\n return items;\n }\n\n const defaultItems = createDefaultBlockSelectorItems(editor);\n\n return items ? items(defaultItems) : defaultItems;\n }, [editor, items]);\n let defaultItem: ToolbarBlockSelectorItem | undefined;\n let activeItem = editor.isInitialized\n ? resolvedItems.find((item) => {\n if (item.isActive === \"default\") {\n defaultItem = item;\n return false;\n }\n\n return item.isActive(editor);\n })\n : undefined;\n\n if (!activeItem) {\n activeItem = defaultItem;\n }\n\n const handleItemChange = (name: string) => {\n const item = resolvedItems.find((item) => item.name === name);\n\n if (item) {\n item.setActive(editor);\n\n // If present in a floating toolbar, close it on change\n floatingToolbarContext?.close();\n }\n };\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLButtonElement>) => {\n onKeyDown?.(event);\n\n if (\n !event.isDefaultPrevented() &&\n closeFloatingToolbar &&\n event.key === \"Escape\"\n ) {\n closeFloatingToolbar();\n event.preventDefault();\n event.stopPropagation();\n }\n },\n [onKeyDown, closeFloatingToolbar]\n );\n\n return (\n <SelectPrimitive.Root\n value={activeItem?.name}\n onValueChange={handleItemChange}\n >\n <ShortcutTooltip content=\"Turn into…\">\n <SelectPrimitive.Trigger\n asChild\n {...props}\n ref={forwardedRef}\n onKeyDown={handleKeyDown}\n disabled={resolvedItems.length === 0}\n >\n <SelectButton variant=\"toolbar\">\n {activeItem?.name ?? \"Turn into…\"}\n </SelectButton>\n </SelectPrimitive.Trigger>\n </ShortcutTooltip>\n <SelectPrimitive.Portal>\n <FloatingToolbarExternal>\n <SelectPrimitive.Content\n position=\"popper\"\n sideOffset={BLOCK_SELECT_SIDE_OFFSET}\n collisionPadding={FLOATING_ELEMENT_COLLISION_PADDING}\n className=\"lb-root lb-portal lb-elevation lb-dropdown lb-select-dropdown lb-tiptap-block-selector-dropdown\"\n >\n {resolvedItems.map((item) => (\n <SelectPrimitive.Item\n key={item.name}\n value={item.name}\n className=\"lb-dropdown-item\"\n data-name={item.name}\n >\n {item.icon ? (\n <span className=\"lb-dropdown-item-icon lb-icon-container\">\n {item.icon}\n </span>\n ) : null}\n <span className=\"lb-dropdown-item-label\">\n {item.label ?? item.name}\n </span>\n {item.name === activeItem?.name ? (\n <span className=\"lb-dropdown-item-accessory lb-icon-container\">\n <CheckIcon />\n </span>\n ) : null}\n </SelectPrimitive.Item>\n ))}\n </SelectPrimitive.Content>\n </FloatingToolbarExternal>\n </SelectPrimitive.Portal>\n </SelectPrimitive.Root>\n );\n});\n\nconst ToolbarSeparator = forwardRef<HTMLDivElement, ToolbarSeparatorProps>(\n ({ className, ...props }, forwardedRef) => {\n return (\n <div\n ref={forwardedRef}\n role=\"separator\"\n aria-orientation=\"vertical\"\n className={classNames(\"lb-tiptap-toolbar-separator\", className)}\n {...props}\n />\n );\n }\n);\n\nfunction ToolbarSectionHistory() {\n const editor = useCurrentEditor(\n \"SectionHistory\",\n \"Toolbar or FloatingToolbar\"\n );\n\n return (\n <>\n <ToolbarButton\n name=\"Undo\"\n icon={<UndoIcon />}\n shortcut=\"Mod-Z\"\n onClick={() => editor.chain().focus().undo().run()}\n disabled={!editor.can().chain().focus().undo().run()}\n />\n <ToolbarButton\n name=\"Redo\"\n icon={<RedoIcon />}\n shortcut=\"Mod-Shift-Z\"\n onClick={() => editor.chain().focus().redo().run()}\n disabled={!editor.can().chain().focus().redo().run()}\n />\n </>\n );\n}\n\nfunction ToolbarSectionInline() {\n const editor = useCurrentEditor(\n \"SectionInline\",\n \"Toolbar or FloatingToolbar\"\n );\n const supportsBold = \"toggleBold\" in editor.commands;\n const supportsItalic = \"toggleItalic\" in editor.commands;\n const supportsUnderline = \"toggleUnderline\" in editor.commands;\n const supportsStrike = \"toggleStrike\" in editor.commands;\n const supportsCode = \"toggleCode\" in editor.commands;\n\n return (\n <>\n {supportsBold && (\n <ToolbarToggle\n name=\"Bold\"\n icon={<BoldIcon />}\n shortcut=\"Mod-B\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleBold\">)\n .toggleBold()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleBold\">\n )\n .toggleBold()\n .run()\n }\n active={editor.isActive(\"bold\")}\n />\n )}\n {supportsItalic && (\n <ToolbarToggle\n name=\"Italic\"\n icon={<ItalicIcon />}\n shortcut=\"Mod-I\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleItalic\">)\n .toggleItalic()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleItalic\">\n )\n .toggleItalic()\n .run()\n }\n active={editor.isActive(\"italic\")}\n />\n )}\n {supportsUnderline && (\n <ToolbarToggle\n name=\"Underline\"\n icon={<UnderlineIcon />}\n shortcut=\"Mod-U\"\n onClick={() =>\n (\n editor\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleUnderline\">\n )\n .toggleUnderline()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleUnderline\">\n )\n .toggleUnderline()\n .run()\n }\n active={editor.isActive(\"underline\")}\n />\n )}\n {supportsStrike && (\n <ToolbarToggle\n name=\"Strikethrough\"\n icon={<StrikethroughIcon />}\n shortcut=\"Mod-U\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleStrike\">)\n .toggleStrike()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleStrike\">\n )\n .toggleStrike()\n .run()\n }\n active={editor.isActive(\"strike\")}\n />\n )}\n {supportsCode && (\n <ToolbarToggle\n name=\"Inline code\"\n icon={<CodeIcon />}\n shortcut=\"Mod-E\"\n onClick={() =>\n (editor.chain().focus() as ExtendedChainedCommands<\"toggleCode\">)\n .toggleCode()\n .run()\n }\n disabled={\n !(\n editor\n .can()\n .chain()\n .focus() as ExtendedChainedCommands<\"toggleCode\">\n )\n .toggleCode()\n .run()\n }\n active={editor.isActive(\"code\")}\n />\n )}\n </>\n );\n}\n\nfunction ToolbarSectionCollaboration() {\n const editor = useCurrentEditor(\n \"SectionCollaboration\",\n \"Toolbar or FloatingToolbar\"\n );\n const supportsThread = \"addPendingComment\" in editor.commands;\n\n return (\n <>\n {supportsThread && (\n <ToolbarButton\n name=\"Add a comment\"\n icon={<CommentIcon />}\n onClick={() =>\n (\n editor\n .chain()\n .focus() as ExtendedChainedCommands<\"addPendingComment\">\n )\n .addPendingComment()\n .run()\n }\n >\n Comment\n </ToolbarButton>\n )}\n </>\n );\n}\n\nfunction ToolbarSectionAi() {\n const editor = useCurrentEditor(\"SectionAi\", \"Toolbar or FloatingToolbar\");\n const supportsAi = \"askAi\" in editor.commands;\n const aiName = (editor.storage.liveblocksAi as AiExtensionStorage | undefined)\n ?.name;\n\n return (\n <>\n {supportsAi && (\n <>\n <ToolbarButton\n name={`Ask ${aiName} anything…`}\n icon={<SparklesIcon />}\n onClick={() =>\n (\n editor.chain().focus() as ExtendedChainedCommands<\"askAi\">\n ).askAi()\n }\n >\n Ask {aiName}\n </ToolbarButton>\n <ToolbarButton\n name=\"Explain\"\n icon={<QuestionMarkIcon />}\n onClick={() =>\n (\n editor.chain().focus() as ExtendedChainedCommands<\"askAi\">\n ).askAi(\"Explain what the text is about\")\n }\n >\n Explain\n </ToolbarButton>\n </>\n )}\n </>\n );\n}\n\nfunction DefaultToolbarContent({ editor }: ToolbarSlotProps) {\n const supportsThread = \"addPendingComment\" in editor.commands;\n const supportsAi = \"askAi\" in editor.commands;\n\n return (\n <>\n <ToolbarSectionHistory />\n <ToolbarSeparator />\n {supportsAi ? (\n <>\n <ToolbarSectionAi />\n <ToolbarSeparator />\n </>\n ) : null}\n <ToolbarBlockSelector />\n <ToolbarSectionInline />\n {supportsThread ? (\n <>\n <ToolbarSeparator />\n <ToolbarSectionCollaboration />\n </>\n ) : null}\n </>\n );\n}\n\n/**\n * A static toolbar containing actions and values related to the editor.\n *\n * @example\n * <Toolbar editor={editor} />\n *\n * @example\n * <Toolbar editor={editor}>\n * <Toolbar.BlockSelector />\n * <Toolbar.Separator />\n * <Toolbar.SectionInline />\n * <Toolbar.Separator />\n * <Toolbar.Button name=\"Custom action\" onClick={() => { ... }} icon={<Icon.QuestionMark />} />\n * </Toolbar>\n */\nexport const Toolbar = Object.assign(\n forwardRef<HTMLDivElement, ToolbarProps>(\n (\n {\n before,\n after,\n children = DefaultToolbarContent,\n editor,\n className,\n ...props\n },\n forwardedRef\n ) => {\n if (!editor) {\n return null;\n }\n\n const slotProps: ToolbarSlotProps = { editor };\n\n return (\n <TooltipProvider>\n <EditorProvider editor={editor}>\n <div\n ref={forwardedRef}\n role=\"toolbar\"\n aria-label=\"Toolbar\"\n aria-orientation=\"horizontal\"\n className={classNames(\"lb-root lb-tiptap-toolbar\", className)}\n {...props}\n >\n {applyToolbarSlot(before, slotProps)}\n {applyToolbarSlot(children, slotProps)}\n {applyToolbarSlot(after, slotProps)}\n </div>\n </EditorProvider>\n </TooltipProvider>\n );\n }\n ),\n {\n /**\n * A button for triggering actions.\n *\n * @example\n * <Toolbar.Button name=\"Comment\" shortcut=\"Mod-Shift-E\" onClick={() => { ... }} />\n *\n * @example\n * <Toolbar.Button name=\"Mention someone\" icon={<Icon.Mention />} onClick={() => { ... }} />\n */\n Button: ToolbarButton,\n\n /**\n * A toggle button for values that can be active or inactive.\n *\n * @example\n * <Toolbar.Toggle name=\"Bold\" active={isBold} />\n *\n * @example\n * <Toolbar.Toggle name=\"Italic\" icon={<Icon.Italic />} shortcut=\"Mod-I\" active={isItalic} onClick={() => { ... }} />\n */\n Toggle: ToolbarToggle,\n\n /**\n * A dropdown selector to switch between different block types.\n *\n * @example\n * <Toolbar.BlockSelector />\n */\n BlockSelector: ToolbarBlockSelector,\n\n /**\n * A visual (and accessible) separator to separate sections in a toolbar.\n */\n Separator: ToolbarSeparator,\n\n /**\n * A section containing history actions. (e.g. undo, redo)\n */\n SectionHistory: ToolbarSectionHistory,\n\n /**\n * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)\n */\n SectionInline: ToolbarSectionInline,\n\n /**\n * A section containing collaborative actions. (e.g. adding a comment)\n */\n SectionCollaboration: ToolbarSectionCollaboration,\n\n /**\n * A section containing AI actions. (e.g. opening the AI toolbar)\n */\n SectionAi: ToolbarSectionAi,\n }\n);\n"],"names":["editor","item"],"mappings":";;;;;;;;;AAwCO,MAAM,wBAA2B,GAAA,GAAA;AACjC,MAAM,kCAAqC,GAAA,GAAA;AAmIlC,SAAA,gBAAA,CACd,MACA,KACW,EAAA;AACX,EAAI,IAAA,OAAO,SAAS,UAAY,EAAA;AA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AAC,MAAQ,EAAA;AACX,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAEA,MAAM,MAAA,SAAA,GAA8B,EAAE,MAAO,EAAA,CAAA;AAE7C,MAAA,uBACG,GAAA,CAAA,eAAA,EAAA;AAAA,QACC,QAAC,kBAAA,GAAA,CAAA,cAAA,EAAA;AAAA,UAAe,MAAA;AAAA,UACd,QAAC,kBAAA,IAAA,CAAA,KAAA,EAAA;AAAA,YACC,GAAK,EAAA,YAAA;AAAA,YACL,IAAK,EAAA,SAAA;AAAA,YACL,YAAW,EAAA,SAAA;AAAA,YACX,kBAAiB,EAAA,YAAA;AAAA,YACjB,SAAA,EAAW,UAAW,CAAA,2BAAA,EAA6B,SAAS,CAAA;AAAA,YAC3D,GAAG,KAAA;AAAA,YAEH,QAAA,EAAA;AAAA,cAAA,gBAAA,CAAiB,QAAQ,SAAS,CAAA;AAAA,cAClC,gBAAA,CAAiB,UAAU,SAAS,CAAA;AAAA,cACpC,gBAAA,CAAiB,OAAO,SAAS,CAAA;AAAA,aAAA;AAAA,WACpC,CAAA;AAAA,SACF,CAAA;AAAA,OACF,CAAA,CAAA;AAAA,KAEJ;AAAA,GACF;AAAA,EACA;AAAA,IAUE,MAAQ,EAAA,aAAA;AAAA,IAWR,MAAQ,EAAA,aAAA;AAAA,IAQR,aAAe,EAAA,oBAAA;AAAA,IAKf,SAAW,EAAA,gBAAA;AAAA,IAKX,cAAgB,EAAA,qBAAA;AAAA,IAKhB,aAAe,EAAA,oBAAA;AAAA,IAKf,oBAAsB,EAAA,2BAAA;AAAA,IAKtB,SAAW,EAAA,gBAAA;AAAA,GACb;AACF;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var _private = require('@liveblocks/react/_private');
5
+ var react = require('react');
6
+
7
+ const FloatingToolbarContext = react.createContext(null);
8
+ const FloatingToolbarExternal = react.forwardRef(({ children, style, ...props }, forwardedRef) => {
9
+ const id = react.useId();
10
+ const externalId = `liveblocks-floating-toolbar-external-${id}`;
11
+ const floatingToolbarContext = react.useContext(FloatingToolbarContext);
12
+ const registerExternal = floatingToolbarContext?.registerExternal;
13
+ _private.useLayoutEffect(() => {
14
+ if (!registerExternal) {
15
+ return;
16
+ }
17
+ return registerExternal(externalId);
18
+ }, [registerExternal, externalId]);
19
+ if (!floatingToolbarContext || react.Children.count(children) === 0) {
20
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
21
+ children
22
+ });
23
+ }
24
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
25
+ ref: forwardedRef,
26
+ style: { display: "contents", ...style },
27
+ "data-liveblocks-floating-toolbar-external": id,
28
+ ...props,
29
+ id: externalId,
30
+ children
31
+ });
32
+ });
33
+
34
+ exports.FloatingToolbarContext = FloatingToolbarContext;
35
+ exports.FloatingToolbarExternal = FloatingToolbarExternal;
36
+ //# sourceMappingURL=shared.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.mjs","sources":["../../src/toolbar/shared.tsx"],"sourcesContent":["import { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport {\n Children,\n type ComponentProps,\n createContext,\n forwardRef,\n useContext,\n useId,\n} from \"react\";\n\n// This file is separate to avoid circular dependencies\n\ntype FloatingToolbarContext = {\n close: () => void;\n registerExternal: (id: string) => () => void;\n};\n\nexport const FloatingToolbarContext =\n createContext<FloatingToolbarContext | null>(null);\n\nexport const FloatingToolbarExternal = forwardRef<\n HTMLDivElement,\n ComponentProps<\"div\">\n>(({ children, style, ...props }, forwardedRef) => {\n const id = useId();\n const externalId = `liveblocks-floating-toolbar-external-${id}`;\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const registerExternal = floatingToolbarContext?.registerExternal;\n\n useLayoutEffect(() => {\n if (!registerExternal) {\n return;\n }\n\n return registerExternal(externalId);\n }, [registerExternal, externalId]);\n\n if (!floatingToolbarContext || Children.count(children) === 0) {\n return <>{children}</>;\n }\n\n return (\n <div\n ref={forwardedRef}\n style={{ display: \"contents\", ...style }}\n data-liveblocks-floating-toolbar-external={id}\n {...props}\n id={externalId}\n >\n {children}\n </div>\n );\n});\n"],"names":[],"mappings":";;;;AAiBa,MAAA,sBAAA,GACX,cAA6C,IAAI,EAAA;AAEtC,MAAA,uBAAA,GAA0B,WAGrC,CAAC,EAAE,UAAU,KAAU,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,EAAA,MAAM,KAAK,KAAM,EAAA,CAAA;AACjB,EAAA,MAAM,aAAa,CAAwC,qCAAA,EAAA,EAAA,CAAA,CAAA,CAAA;AAC3D,EAAM,MAAA,sBAAA,GAAyB,WAAW,sBAAsB,CAAA,CAAA;AAChE,EAAA,MAAM,mBAAmB,sBAAwB,EAAA,gBAAA,CAAA;AAEjD,EAAA,eAAA,CAAgB,MAAM;AACpB,IAAA,IAAI,CAAC,gBAAkB,EAAA;AACrB,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,OAAO,iBAAiB,UAAU,CAAA,CAAA;AAAA,GACjC,EAAA,CAAC,gBAAkB,EAAA,UAAU,CAAC,CAAA,CAAA;AAEjC,EAAA,IAAI,CAAC,sBAA0B,IAAA,QAAA,CAAS,KAAM,CAAA,QAAQ,MAAM,CAAG,EAAA;AAC7D,IAAO,uBAAA,GAAA,CAAA,QAAA,EAAA;AAAA,MAAG,QAAA;AAAA,KAAS,CAAA,CAAA;AAAA,GACrB;AAEA,EAAA,uBACG,GAAA,CAAA,KAAA,EAAA;AAAA,IACC,GAAK,EAAA,YAAA;AAAA,IACL,KAAO,EAAA,EAAE,OAAS,EAAA,UAAA,EAAY,GAAG,KAAM,EAAA;AAAA,IACvC,2CAA2C,EAAA,EAAA;AAAA,IAC1C,GAAG,KAAA;AAAA,IACJ,EAAI,EAAA,UAAA;AAAA,IAEH,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAC;;;;"}
1
+ {"version":3,"file":"shared.cjs","sources":["../../src/toolbar/shared.tsx"],"sourcesContent":["import { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport {\n Children,\n type ComponentProps,\n createContext,\n forwardRef,\n useContext,\n useId,\n} from \"react\";\n\n// This file is separate to avoid circular dependencies\n\ntype FloatingToolbarContext = {\n close: () => void;\n registerExternal: (id: string) => () => void;\n};\n\nexport const FloatingToolbarContext =\n createContext<FloatingToolbarContext | null>(null);\n\nexport const FloatingToolbarExternal = forwardRef<\n HTMLDivElement,\n ComponentProps<\"div\">\n>(({ children, style, ...props }, forwardedRef) => {\n const id = useId();\n const externalId = `liveblocks-floating-toolbar-external-${id}`;\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const registerExternal = floatingToolbarContext?.registerExternal;\n\n useLayoutEffect(() => {\n if (!registerExternal) {\n return;\n }\n\n return registerExternal(externalId);\n }, [registerExternal, externalId]);\n\n if (!floatingToolbarContext || Children.count(children) === 0) {\n return <>{children}</>;\n }\n\n return (\n <div\n ref={forwardedRef}\n style={{ display: \"contents\", ...style }}\n data-liveblocks-floating-toolbar-external={id}\n {...props}\n id={externalId}\n >\n {children}\n </div>\n );\n});\n"],"names":["createContext","forwardRef","useId","useContext","useLayoutEffect","Children","jsx","Fragment"],"mappings":";;;;;;AAiBa,MAAA,sBAAA,GACXA,oBAA6C,IAAI,EAAA;AAEtC,MAAA,uBAAA,GAA0BC,iBAGrC,CAAC,EAAE,UAAU,KAAU,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,EAAA,MAAM,KAAKC,WAAM,EAAA,CAAA;AACjB,EAAA,MAAM,aAAa,CAAwC,qCAAA,EAAA,EAAA,CAAA,CAAA,CAAA;AAC3D,EAAM,MAAA,sBAAA,GAAyBC,iBAAW,sBAAsB,CAAA,CAAA;AAChE,EAAA,MAAM,mBAAmB,sBAAwB,EAAA,gBAAA,CAAA;AAEjD,EAAAC,wBAAA,CAAgB,MAAM;AACpB,IAAA,IAAI,CAAC,gBAAkB,EAAA;AACrB,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,OAAO,iBAAiB,UAAU,CAAA,CAAA;AAAA,GACjC,EAAA,CAAC,gBAAkB,EAAA,UAAU,CAAC,CAAA,CAAA;AAEjC,EAAA,IAAI,CAAC,sBAA0B,IAAAC,cAAA,CAAS,KAAM,CAAA,QAAQ,MAAM,CAAG,EAAA;AAC7D,IAAO,uBAAAC,cAAA,CAAAC,mBAAA,EAAA;AAAA,MAAG,QAAA;AAAA,KAAS,CAAA,CAAA;AAAA,GACrB;AAEA,EAAA,uBACGD,cAAA,CAAA,KAAA,EAAA;AAAA,IACC,GAAK,EAAA,YAAA;AAAA,IACL,KAAO,EAAA,EAAE,OAAS,EAAA,UAAA,EAAY,GAAG,KAAM,EAAA;AAAA,IACvC,2CAA2C,EAAA,EAAA;AAAA,IAC1C,GAAG,KAAA;AAAA,IACJ,EAAI,EAAA,UAAA;AAAA,IAEH,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAC;;;;;"}
@@ -1,27 +1,25 @@
1
- 'use strict';
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { useLayoutEffect } from '@liveblocks/react/_private';
3
+ import { createContext, forwardRef, useId, useContext, Children } from 'react';
2
4
 
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var _private = require('@liveblocks/react/_private');
5
- var react = require('react');
6
-
7
- const FloatingToolbarContext = react.createContext(null);
8
- const FloatingToolbarExternal = react.forwardRef(({ children, style, ...props }, forwardedRef) => {
9
- const id = react.useId();
5
+ const FloatingToolbarContext = createContext(null);
6
+ const FloatingToolbarExternal = forwardRef(({ children, style, ...props }, forwardedRef) => {
7
+ const id = useId();
10
8
  const externalId = `liveblocks-floating-toolbar-external-${id}`;
11
- const floatingToolbarContext = react.useContext(FloatingToolbarContext);
9
+ const floatingToolbarContext = useContext(FloatingToolbarContext);
12
10
  const registerExternal = floatingToolbarContext?.registerExternal;
13
- _private.useLayoutEffect(() => {
11
+ useLayoutEffect(() => {
14
12
  if (!registerExternal) {
15
13
  return;
16
14
  }
17
15
  return registerExternal(externalId);
18
16
  }, [registerExternal, externalId]);
19
- if (!floatingToolbarContext || react.Children.count(children) === 0) {
20
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
17
+ if (!floatingToolbarContext || Children.count(children) === 0) {
18
+ return /* @__PURE__ */ jsx(Fragment, {
21
19
  children
22
20
  });
23
21
  }
24
- return /* @__PURE__ */ jsxRuntime.jsx("div", {
22
+ return /* @__PURE__ */ jsx("div", {
25
23
  ref: forwardedRef,
26
24
  style: { display: "contents", ...style },
27
25
  "data-liveblocks-floating-toolbar-external": id,
@@ -31,6 +29,5 @@ const FloatingToolbarExternal = react.forwardRef(({ children, style, ...props },
31
29
  });
32
30
  });
33
31
 
34
- exports.FloatingToolbarContext = FloatingToolbarContext;
35
- exports.FloatingToolbarExternal = FloatingToolbarExternal;
32
+ export { FloatingToolbarContext, FloatingToolbarExternal };
36
33
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sources":["../../src/toolbar/shared.tsx"],"sourcesContent":["import { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport {\n Children,\n type ComponentProps,\n createContext,\n forwardRef,\n useContext,\n useId,\n} from \"react\";\n\n// This file is separate to avoid circular dependencies\n\ntype FloatingToolbarContext = {\n close: () => void;\n registerExternal: (id: string) => () => void;\n};\n\nexport const FloatingToolbarContext =\n createContext<FloatingToolbarContext | null>(null);\n\nexport const FloatingToolbarExternal = forwardRef<\n HTMLDivElement,\n ComponentProps<\"div\">\n>(({ children, style, ...props }, forwardedRef) => {\n const id = useId();\n const externalId = `liveblocks-floating-toolbar-external-${id}`;\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const registerExternal = floatingToolbarContext?.registerExternal;\n\n useLayoutEffect(() => {\n if (!registerExternal) {\n return;\n }\n\n return registerExternal(externalId);\n }, [registerExternal, externalId]);\n\n if (!floatingToolbarContext || Children.count(children) === 0) {\n return <>{children}</>;\n }\n\n return (\n <div\n ref={forwardedRef}\n style={{ display: \"contents\", ...style }}\n data-liveblocks-floating-toolbar-external={id}\n {...props}\n id={externalId}\n >\n {children}\n </div>\n );\n});\n"],"names":["createContext","forwardRef","useId","useContext","useLayoutEffect","Children","jsx","Fragment"],"mappings":";;;;;;AAiBa,MAAA,sBAAA,GACXA,oBAA6C,IAAI,EAAA;AAEtC,MAAA,uBAAA,GAA0BC,iBAGrC,CAAC,EAAE,UAAU,KAAU,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,EAAA,MAAM,KAAKC,WAAM,EAAA,CAAA;AACjB,EAAA,MAAM,aAAa,CAAwC,qCAAA,EAAA,EAAA,CAAA,CAAA,CAAA;AAC3D,EAAM,MAAA,sBAAA,GAAyBC,iBAAW,sBAAsB,CAAA,CAAA;AAChE,EAAA,MAAM,mBAAmB,sBAAwB,EAAA,gBAAA,CAAA;AAEjD,EAAAC,wBAAA,CAAgB,MAAM;AACpB,IAAA,IAAI,CAAC,gBAAkB,EAAA;AACrB,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,OAAO,iBAAiB,UAAU,CAAA,CAAA;AAAA,GACjC,EAAA,CAAC,gBAAkB,EAAA,UAAU,CAAC,CAAA,CAAA;AAEjC,EAAA,IAAI,CAAC,sBAA0B,IAAAC,cAAA,CAAS,KAAM,CAAA,QAAQ,MAAM,CAAG,EAAA;AAC7D,IAAO,uBAAAC,cAAA,CAAAC,mBAAA,EAAA;AAAA,MAAG,QAAA;AAAA,KAAS,CAAA,CAAA;AAAA,GACrB;AAEA,EAAA,uBACGD,cAAA,CAAA,KAAA,EAAA;AAAA,IACC,GAAK,EAAA,YAAA;AAAA,IACL,KAAO,EAAA,EAAE,OAAS,EAAA,UAAA,EAAY,GAAG,KAAM,EAAA;AAAA,IACvC,2CAA2C,EAAA,EAAA;AAAA,IAC1C,GAAG,KAAA;AAAA,IACJ,EAAI,EAAA,UAAA;AAAA,IAEH,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAC;;;;;"}
1
+ {"version":3,"file":"shared.js","sources":["../../src/toolbar/shared.tsx"],"sourcesContent":["import { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport {\n Children,\n type ComponentProps,\n createContext,\n forwardRef,\n useContext,\n useId,\n} from \"react\";\n\n// This file is separate to avoid circular dependencies\n\ntype FloatingToolbarContext = {\n close: () => void;\n registerExternal: (id: string) => () => void;\n};\n\nexport const FloatingToolbarContext =\n createContext<FloatingToolbarContext | null>(null);\n\nexport const FloatingToolbarExternal = forwardRef<\n HTMLDivElement,\n ComponentProps<\"div\">\n>(({ children, style, ...props }, forwardedRef) => {\n const id = useId();\n const externalId = `liveblocks-floating-toolbar-external-${id}`;\n const floatingToolbarContext = useContext(FloatingToolbarContext);\n const registerExternal = floatingToolbarContext?.registerExternal;\n\n useLayoutEffect(() => {\n if (!registerExternal) {\n return;\n }\n\n return registerExternal(externalId);\n }, [registerExternal, externalId]);\n\n if (!floatingToolbarContext || Children.count(children) === 0) {\n return <>{children}</>;\n }\n\n return (\n <div\n ref={forwardedRef}\n style={{ display: \"contents\", ...style }}\n data-liveblocks-floating-toolbar-external={id}\n {...props}\n id={externalId}\n >\n {children}\n </div>\n );\n});\n"],"names":[],"mappings":";;;;AAiBa,MAAA,sBAAA,GACX,cAA6C,IAAI,EAAA;AAEtC,MAAA,uBAAA,GAA0B,WAGrC,CAAC,EAAE,UAAU,KAAU,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,EAAA,MAAM,KAAK,KAAM,EAAA,CAAA;AACjB,EAAA,MAAM,aAAa,CAAwC,qCAAA,EAAA,EAAA,CAAA,CAAA,CAAA;AAC3D,EAAM,MAAA,sBAAA,GAAyB,WAAW,sBAAsB,CAAA,CAAA;AAChE,EAAA,MAAM,mBAAmB,sBAAwB,EAAA,gBAAA,CAAA;AAEjD,EAAA,eAAA,CAAgB,MAAM;AACpB,IAAA,IAAI,CAAC,gBAAkB,EAAA;AACrB,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,OAAO,iBAAiB,UAAU,CAAA,CAAA;AAAA,GACjC,EAAA,CAAC,gBAAkB,EAAA,UAAU,CAAC,CAAA,CAAA;AAEjC,EAAA,IAAI,CAAC,sBAA0B,IAAA,QAAA,CAAS,KAAM,CAAA,QAAQ,MAAM,CAAG,EAAA;AAC7D,IAAO,uBAAA,GAAA,CAAA,QAAA,EAAA;AAAA,MAAG,QAAA;AAAA,KAAS,CAAA,CAAA;AAAA,GACrB;AAEA,EAAA,uBACG,GAAA,CAAA,KAAA,EAAA;AAAA,IACC,GAAK,EAAA,YAAA;AAAA,IACL,KAAO,EAAA,EAAE,OAAS,EAAA,UAAA,EAAY,GAAG,KAAM,EAAA;AAAA,IACvC,2CAA2C,EAAA,EAAA;AAAA,IAC1C,GAAG,KAAA;AAAA,IACJ,EAAI,EAAA,UAAA;AAAA,IAEH,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAC;;;;"}
package/dist/types.cjs ADDED
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var state = require('@tiptap/pm/state');
4
+
5
+ const LIVEBLOCKS_MENTION_KEY = new state.PluginKey("lb-plugin-mention");
6
+ const LIVEBLOCKS_MENTION_PASTE_KEY = new state.PluginKey(
7
+ "lb-plugin-mention-paste"
8
+ );
9
+ const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new state.PluginKey(
10
+ "lb-plugin-mention-notify"
11
+ );
12
+ const LIVEBLOCKS_MENTION_EXTENSION = "liveblocksMentionExt";
13
+ const LIVEBLOCKS_MENTION_TYPE = "liveblocksMention";
14
+ const THREADS_ACTIVE_SELECTION_PLUGIN = new state.PluginKey(
15
+ "lb-threads-active-selection-plugin"
16
+ );
17
+ const THREADS_PLUGIN_KEY = new state.PluginKey(
18
+ "lb-threads-plugin"
19
+ );
20
+ const AI_TOOLBAR_SELECTION_PLUGIN = new state.PluginKey(
21
+ "lb-ai-toolbar-selection-plugin"
22
+ );
23
+ const LIVEBLOCKS_COMMENT_MARK_TYPE = "liveblocksCommentMark";
24
+ var ThreadPluginActions = /* @__PURE__ */ ((ThreadPluginActions2) => {
25
+ ThreadPluginActions2["SET_SELECTED_THREAD_ID"] = "SET_SELECTED_THREAD_ID";
26
+ return ThreadPluginActions2;
27
+ })(ThreadPluginActions || {});
28
+
29
+ exports.AI_TOOLBAR_SELECTION_PLUGIN = AI_TOOLBAR_SELECTION_PLUGIN;
30
+ exports.LIVEBLOCKS_COMMENT_MARK_TYPE = LIVEBLOCKS_COMMENT_MARK_TYPE;
31
+ exports.LIVEBLOCKS_MENTION_EXTENSION = LIVEBLOCKS_MENTION_EXTENSION;
32
+ exports.LIVEBLOCKS_MENTION_KEY = LIVEBLOCKS_MENTION_KEY;
33
+ exports.LIVEBLOCKS_MENTION_NOTIFIER_KEY = LIVEBLOCKS_MENTION_NOTIFIER_KEY;
34
+ exports.LIVEBLOCKS_MENTION_PASTE_KEY = LIVEBLOCKS_MENTION_PASTE_KEY;
35
+ exports.LIVEBLOCKS_MENTION_TYPE = LIVEBLOCKS_MENTION_TYPE;
36
+ exports.THREADS_ACTIVE_SELECTION_PLUGIN = THREADS_ACTIVE_SELECTION_PLUGIN;
37
+ exports.THREADS_PLUGIN_KEY = THREADS_PLUGIN_KEY;
38
+ exports.ThreadPluginActions = ThreadPluginActions;
39
+ //# sourceMappingURL=types.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n Relax,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n askAi: (prompt?: string) => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n"],"names":["ThreadPluginActions"],"mappings":";;AAaa,MAAA,sBAAA,GAAyB,IAAI,SAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAI,SAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAEhC,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAI,SAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAI,SAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AAsE1B,IAAA,mBAAA,qBAAAA,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;"}
1
+ {"version":3,"file":"types.cjs","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n Relax,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n askAi: (prompt?: string) => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n"],"names":["PluginKey","ThreadPluginActions"],"mappings":";;;;AAaa,MAAA,sBAAA,GAAyB,IAAIA,eAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAIA,eAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAEhC,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAIA,eAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAIA,eAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AAsE1B,IAAA,mBAAA,qBAAAC,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;;;;;;;;;;"}
package/dist/types.js CHANGED
@@ -1,23 +1,21 @@
1
- 'use strict';
1
+ import { PluginKey } from '@tiptap/pm/state';
2
2
 
3
- var state = require('@tiptap/pm/state');
4
-
5
- const LIVEBLOCKS_MENTION_KEY = new state.PluginKey("lb-plugin-mention");
6
- const LIVEBLOCKS_MENTION_PASTE_KEY = new state.PluginKey(
3
+ const LIVEBLOCKS_MENTION_KEY = new PluginKey("lb-plugin-mention");
4
+ const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(
7
5
  "lb-plugin-mention-paste"
8
6
  );
9
- const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new state.PluginKey(
7
+ const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(
10
8
  "lb-plugin-mention-notify"
11
9
  );
12
10
  const LIVEBLOCKS_MENTION_EXTENSION = "liveblocksMentionExt";
13
11
  const LIVEBLOCKS_MENTION_TYPE = "liveblocksMention";
14
- const THREADS_ACTIVE_SELECTION_PLUGIN = new state.PluginKey(
12
+ const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(
15
13
  "lb-threads-active-selection-plugin"
16
14
  );
17
- const THREADS_PLUGIN_KEY = new state.PluginKey(
15
+ const THREADS_PLUGIN_KEY = new PluginKey(
18
16
  "lb-threads-plugin"
19
17
  );
20
- const AI_TOOLBAR_SELECTION_PLUGIN = new state.PluginKey(
18
+ const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(
21
19
  "lb-ai-toolbar-selection-plugin"
22
20
  );
23
21
  const LIVEBLOCKS_COMMENT_MARK_TYPE = "liveblocksCommentMark";
@@ -26,14 +24,5 @@ var ThreadPluginActions = /* @__PURE__ */ ((ThreadPluginActions2) => {
26
24
  return ThreadPluginActions2;
27
25
  })(ThreadPluginActions || {});
28
26
 
29
- exports.AI_TOOLBAR_SELECTION_PLUGIN = AI_TOOLBAR_SELECTION_PLUGIN;
30
- exports.LIVEBLOCKS_COMMENT_MARK_TYPE = LIVEBLOCKS_COMMENT_MARK_TYPE;
31
- exports.LIVEBLOCKS_MENTION_EXTENSION = LIVEBLOCKS_MENTION_EXTENSION;
32
- exports.LIVEBLOCKS_MENTION_KEY = LIVEBLOCKS_MENTION_KEY;
33
- exports.LIVEBLOCKS_MENTION_NOTIFIER_KEY = LIVEBLOCKS_MENTION_NOTIFIER_KEY;
34
- exports.LIVEBLOCKS_MENTION_PASTE_KEY = LIVEBLOCKS_MENTION_PASTE_KEY;
35
- exports.LIVEBLOCKS_MENTION_TYPE = LIVEBLOCKS_MENTION_TYPE;
36
- exports.THREADS_ACTIVE_SELECTION_PLUGIN = THREADS_ACTIVE_SELECTION_PLUGIN;
37
- exports.THREADS_PLUGIN_KEY = THREADS_PLUGIN_KEY;
38
- exports.ThreadPluginActions = ThreadPluginActions;
27
+ export { AI_TOOLBAR_SELECTION_PLUGIN, LIVEBLOCKS_COMMENT_MARK_TYPE, LIVEBLOCKS_MENTION_EXTENSION, LIVEBLOCKS_MENTION_KEY, LIVEBLOCKS_MENTION_NOTIFIER_KEY, LIVEBLOCKS_MENTION_PASTE_KEY, LIVEBLOCKS_MENTION_TYPE, THREADS_ACTIVE_SELECTION_PLUGIN, THREADS_PLUGIN_KEY, ThreadPluginActions };
39
28
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n Relax,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n askAi: (prompt?: string) => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n"],"names":["PluginKey","ThreadPluginActions"],"mappings":";;;;AAaa,MAAA,sBAAA,GAAyB,IAAIA,eAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAIA,eAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAEhC,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAIA,eAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAIA,eAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AAsE1B,IAAA,mBAAA,qBAAAC,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n Relax,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n askAi: (prompt?: string) => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n"],"names":["ThreadPluginActions"],"mappings":";;AAaa,MAAA,sBAAA,GAAyB,IAAI,SAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAI,SAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAEhC,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAI,SAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAI,SAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AAsE1B,IAAA,mBAAA,qBAAAA,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;"}
@@ -1,23 +1,25 @@
1
- import { Fragment } from '@tiptap/pm/model';
2
- import { TextSelection } from '@tiptap/pm/state';
3
- import { ySyncPluginKey, getRelativeSelection, relativePositionToAbsolutePosition } from 'y-prosemirror';
4
- import { LIVEBLOCKS_MENTION_TYPE } from './types.mjs';
1
+ 'use strict';
2
+
3
+ var model = require('@tiptap/pm/model');
4
+ var state = require('@tiptap/pm/state');
5
+ var yProsemirror = require('y-prosemirror');
6
+ var types = require('./types.cjs');
5
7
 
6
8
  const CONTEXT_TRUNCATION = "[\u2026]";
7
9
  const CONTEXT_BLOCK_SEPARATOR = "\n";
8
10
  const getRelativeSelectionFromState = (state) => {
9
- const pluginState = ySyncPluginKey.getState(state);
11
+ const pluginState = yProsemirror.ySyncPluginKey.getState(state);
10
12
  if (!pluginState)
11
13
  return null;
12
- return getRelativeSelection(pluginState.binding, state);
14
+ return yProsemirror.getRelativeSelection(pluginState.binding, state);
13
15
  };
14
16
  const getRangeFromRelativeSelections = (pos, state) => {
15
- const pluginState = ySyncPluginKey.getState(state);
17
+ const pluginState = yProsemirror.ySyncPluginKey.getState(state);
16
18
  if (!pluginState || !pluginState.binding)
17
19
  return { from: 0, to: 0 };
18
20
  const { doc, type, mapping } = pluginState.binding;
19
- const anchor = relativePositionToAbsolutePosition(doc, type, pos.anchor, mapping) ?? 0;
20
- const head = relativePositionToAbsolutePosition(doc, type, pos.head, mapping) ?? 0;
21
+ const anchor = yProsemirror.relativePositionToAbsolutePosition(doc, type, pos.anchor, mapping) ?? 0;
22
+ const head = yProsemirror.relativePositionToAbsolutePosition(doc, type, pos.head, mapping) ?? 0;
21
23
  const from = anchor > head ? head : anchor;
22
24
  const to = anchor > head ? anchor : head;
23
25
  return { from, to };
@@ -34,7 +36,7 @@ const getRectFromCoords = (coords) => {
34
36
  const getMentionsFromNode = (node, range) => {
35
37
  const result = [];
36
38
  node.nodesBetween(range.from, range.to, (child) => {
37
- if (child.type.name === LIVEBLOCKS_MENTION_TYPE) {
39
+ if (child.type.name === types.LIVEBLOCKS_MENTION_TYPE) {
38
40
  const mention = child.attrs;
39
41
  if (mention.id && mention.notificationId) {
40
42
  result.push({
@@ -57,13 +59,13 @@ const mapFragment = (fragment, callback) => {
57
59
  }
58
60
  content.push(callback(node));
59
61
  });
60
- return Fragment.from(content);
62
+ return model.Fragment.from(content);
61
63
  };
62
64
  function getDomRangeFromSelection(editor, selection) {
63
65
  if (selection.from === selection.to) {
64
66
  const { parent, parentOffset } = selection.$from;
65
67
  if (parent.isBlock && parent.content.size === 0 || parent.isTextblock && parentOffset === parent.content.size) {
66
- selection = TextSelection.create(
68
+ selection = state.TextSelection.create(
67
69
  editor.state.doc,
68
70
  selection.$from.before(),
69
71
  selection.$from.after()
@@ -163,5 +165,12 @@ function getContextualPromptContext(editor, maxLength = 1e4) {
163
165
  }
164
166
  }
165
167
 
166
- export { compareSelections, getContextualPromptContext, getDomRangeFromSelection, getMentionsFromNode, getRangeFromRelativeSelections, getRectFromCoords, getRelativeSelectionFromState, mapFragment };
167
- //# sourceMappingURL=utils.mjs.map
168
+ exports.compareSelections = compareSelections;
169
+ exports.getContextualPromptContext = getContextualPromptContext;
170
+ exports.getDomRangeFromSelection = getDomRangeFromSelection;
171
+ exports.getMentionsFromNode = getMentionsFromNode;
172
+ exports.getRangeFromRelativeSelections = getRangeFromRelativeSelections;
173
+ exports.getRectFromCoords = getRectFromCoords;
174
+ exports.getRelativeSelectionFromState = getRelativeSelectionFromState;
175
+ exports.mapFragment = mapFragment;
176
+ //# sourceMappingURL=utils.cjs.map