@liveblocks/react-tiptap 2.16.0 → 2.16.1-ai1
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.
- package/dist/LiveblocksExtension.js +120 -21
- package/dist/LiveblocksExtension.js.map +1 -1
- package/dist/LiveblocksExtension.mjs +118 -19
- package/dist/LiveblocksExtension.mjs.map +1 -1
- package/dist/ai/AiExtension.js +299 -0
- package/dist/ai/AiExtension.js.map +1 -0
- package/dist/ai/AiExtension.mjs +296 -0
- package/dist/ai/AiExtension.mjs.map +1 -0
- package/dist/ai/AiToolbar.js +570 -0
- package/dist/ai/AiToolbar.js.map +1 -0
- package/dist/ai/AiToolbar.mjs +567 -0
- package/dist/ai/AiToolbar.mjs.map +1 -0
- package/dist/comments/CommentsExtension.js.map +1 -1
- package/dist/comments/CommentsExtension.mjs.map +1 -1
- package/dist/index.d.mts +58 -16
- package/dist/index.d.ts +58 -16
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/toolbar/FloatingToolbar.js +7 -0
- package/dist/toolbar/FloatingToolbar.js.map +1 -1
- package/dist/toolbar/FloatingToolbar.mjs +7 -0
- package/dist/toolbar/FloatingToolbar.mjs.map +1 -1
- package/dist/toolbar/Toolbar.js +37 -2
- package/dist/toolbar/Toolbar.js.map +1 -1
- package/dist/toolbar/Toolbar.mjs +38 -3
- package/dist/toolbar/Toolbar.mjs.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.js +21 -1
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +20 -2
- package/dist/utils.mjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +7 -6
- package/src/styles/index.css +319 -3
- package/styles.css +1 -1
- package/styles.css.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiToolbar.mjs","sources":["../../src/ai/AiToolbar.tsx"],"sourcesContent":["import {\n autoUpdate,\n type DetectOverflowOptions,\n hide,\n type Middleware,\n offset,\n useFloating,\n type UseFloatingOptions,\n} from \"@floating-ui/react-dom\";\nimport { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport {\n Button,\n CheckIcon,\n CrossIcon,\n EditIcon,\n LengthenIcon,\n QuestionMarkIcon,\n SendIcon,\n ShortcutTooltip,\n ShortenIcon,\n SparklesIcon,\n TooltipProvider,\n UndoIcon,\n useRefs,\n} from \"@liveblocks/react-ui/_private\";\nimport { type Editor, useEditorState } from \"@tiptap/react\";\nimport { Command, useCommandState } from \"cmdk\";\nimport type {\n ComponentProps,\n ComponentType,\n KeyboardEvent as ReactKeyboardEvent,\n PropsWithChildren,\n ReactNode,\n RefObject,\n} from \"react\";\nimport {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport { classNames } from \"../classnames\";\nimport { EditorProvider, useCurrentEditor } from \"../context\";\nimport type {\n AiCommands,\n AiExtensionStorage,\n AiToolbarState,\n ChainedAiCommands,\n FloatingPosition,\n} from \"../types\";\nimport { getDomRangeFromSelection } from \"../utils\";\nimport { DEFAULT_STATE } from \"./AiExtension\";\n\nexport const AI_TOOLBAR_COLLISION_PADDING = 10;\n\nexport interface AiToolbarProps\n extends Omit<ComponentProps<\"div\">, \"value\" | \"defaultValue\"> {\n editor: Editor | null;\n position?: FloatingPosition;\n offset?: number;\n suggestions?: ReactNode | ComponentType<PropsWithChildren>;\n}\n\ninterface AiToolbarDropdownGroupProps extends ComponentProps<\"div\"> {\n label: string;\n}\n\ninterface AiToolbarDropdownItemProps\n extends ComponentProps<typeof Command.Item> {\n icon?: ReactNode;\n}\n\ntype AiToolbarSuggestionsGroupProps = AiToolbarDropdownGroupProps;\n\ninterface AiToolbarSuggestionProps extends ComponentProps<\"div\"> {\n prompt?: string;\n icon?: ReactNode;\n}\n\ninterface AiToolbarContext {\n state: AiToolbarState;\n toolbarRef: RefObject<HTMLDivElement>;\n dropdownRef: RefObject<HTMLDivElement>;\n isDropdownHidden: boolean;\n}\n\nconst AiToolbarContext = createContext<AiToolbarContext | null>(null);\n\nfunction useAiToolbarContext() {\n const context = useContext(AiToolbarContext);\n\n if (!context) {\n throw new Error(\"useAiToolbarContext must be used within an AiToolbar\");\n }\n\n return context;\n}\n\n/**\n * A custom Floating UI middleware to position/scale the toolbar:\n * - Vertically: relative to the reference (e.g. selection)\n * - Horizontally: relative to the editor\n * - Width: relative to the editor\n */\nfunction tiptapFloating(editor: Editor | null): Middleware {\n return {\n name: \"tiptap\",\n options: editor,\n fn({ elements }) {\n if (!editor) {\n return {};\n }\n\n const editorRect = editor.view.dom.getBoundingClientRect();\n\n elements.floating.style.setProperty(\n \"--lb-tiptap-editor-width\",\n `${editorRect.width}px`\n );\n elements.floating.style.setProperty(\n \"--lb-tiptap-editor-height\",\n `${editorRect.height}px`\n );\n\n return {\n x: editorRect.x,\n };\n },\n };\n}\n\nconst AiToolbarDropdownGroup = forwardRef<\n HTMLDivElement,\n AiToolbarDropdownGroupProps\n>(({ children, label, ...props }, forwardedRef) => {\n return (\n <Command.Group\n heading={<span className=\"lb-dropdown-label\">{label}</span>}\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Command.Group>\n );\n});\n\nconst AiToolbarSuggestionsGroup = forwardRef<\n HTMLDivElement,\n AiToolbarSuggestionsGroupProps\n>((props, forwardedRef) => {\n return <AiToolbarDropdownGroup ref={forwardedRef} {...props} />;\n});\n\nconst AiToolbarDropdownItem = forwardRef<\n HTMLDivElement,\n AiToolbarDropdownItemProps\n>(({ children, onSelect, icon, ...props }, forwardedRef) => {\n return (\n <Command.Item\n className=\"lb-dropdown-item\"\n onSelect={onSelect}\n {...props}\n ref={forwardedRef}\n >\n {icon ? <span className=\"lb-icon-container\">{icon}</span> : null}\n {children ? (\n <span className=\"lb-dropdown-item-label\">{children}</span>\n ) : null}\n </Command.Item>\n );\n});\n\nconst AiToolbarSuggestion = forwardRef<\n HTMLDivElement,\n AiToolbarSuggestionProps\n>(({ prompt: manualPrompt, ...props }, forwardedRef) => {\n const editor = useCurrentEditor(\"Suggestion\", \"AiToolbar\");\n\n const handleSelect = useCallback(\n (prompt: string) => {\n (editor.commands as unknown as AiCommands).$startAiToolbarThinking(\n manualPrompt ?? prompt\n );\n },\n [editor, manualPrompt]\n );\n\n return (\n <AiToolbarDropdownItem\n {...props}\n onSelect={handleSelect}\n ref={forwardedRef}\n />\n );\n});\n\nfunction AiToolbarReviewingSuggestions() {\n const editor = useCurrentEditor(\"ReviewingSuggestions\", \"AiToolbar\");\n const { state } = useAiToolbarContext();\n const { output } = state as Extract<AiToolbarState, { phase: \"reviewing\" }>;\n\n const handleDiscard = useCallback(() => {\n (editor.commands as unknown as AiCommands).$closeAiToolbar();\n }, [editor]);\n\n const handleAccept = useCallback(() => {\n (editor.commands as unknown as AiCommands).$acceptAiToolbarOutput();\n }, [editor]);\n\n if (output.type === \"insert\" || output.type === \"modification\") {\n return (\n <>\n <AiToolbarDropdownItem icon={<CheckIcon />} onSelect={handleAccept}>\n Accept\n </AiToolbarDropdownItem>\n <AiToolbarDropdownItem icon={<UndoIcon />} disabled>\n Try again\n </AiToolbarDropdownItem>\n <AiToolbarDropdownItem icon={<CrossIcon />} onSelect={handleDiscard}>\n Discard\n </AiToolbarDropdownItem>\n </>\n );\n } else if (output.type === \"other\") {\n return (\n <>\n <AiToolbarDropdownItem icon={<CheckIcon />} disabled>\n Replace selection\n </AiToolbarDropdownItem>\n <AiToolbarDropdownItem icon={<CheckIcon />} disabled>\n Insert below\n </AiToolbarDropdownItem>\n <AiToolbarDropdownItem icon={<UndoIcon />} disabled>\n Try again\n </AiToolbarDropdownItem>\n <AiToolbarDropdownItem icon={<CrossIcon />} onSelect={handleDiscard}>\n Discard\n </AiToolbarDropdownItem>\n </>\n );\n }\n\n return null;\n}\n\nfunction AiToolbarCustomPromptContent({ disabled }: { disabled?: boolean }) {\n const editor = useCurrentEditor(\"CustomPromptContent\", \"AiToolbar\");\n const aiName = (editor.storage.liveblocksAi as AiExtensionStorage).name;\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n const { state, dropdownRef, isDropdownHidden } = useAiToolbarContext();\n const { customPrompt } = state as Exclude<\n AiToolbarState,\n { phase: \"closed\" }\n >;\n const isCustomPromptEmpty = useMemo(\n () => customPrompt.trim() === \"\",\n [customPrompt]\n );\n\n useLayoutEffect(\n () => {\n setTimeout(() => {\n const textArea = textAreaRef.current;\n\n if (!textArea) {\n return;\n }\n\n textArea.focus();\n textArea.setSelectionRange(\n textArea.value.length,\n textArea.value.length\n );\n }, 0);\n },\n [] // eslint-disable-line react-hooks/exhaustive-deps\n );\n\n const handlePromptKeyDown = (\n event: ReactKeyboardEvent<HTMLTextAreaElement>\n ) => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n event.stopPropagation();\n\n if (event.shiftKey) {\n // If the shift key is pressed, add a new line\n (editor.commands as unknown as AiCommands)._updateAiToolbarCustomPrompt(\n (customPrompt) => customPrompt + \"\\n\"\n );\n } else {\n const selectedDropdownItem = dropdownRef.current?.querySelector(\n \"[role='option'][data-selected='true']\"\n ) as HTMLElement | null;\n\n if (!isDropdownHidden && selectedDropdownItem) {\n // If there's a selected dropdown item, select it\n selectedDropdownItem.click();\n } else if (!isCustomPromptEmpty) {\n // Otherwise, submit the custom prompt\n (editor.commands as unknown as AiCommands).$startAiToolbarThinking(\n customPrompt\n );\n }\n }\n }\n };\n\n const handleCustomPromptChange = useCallback(\n (customPrompt: string) => {\n (editor.commands as unknown as AiCommands)._updateAiToolbarCustomPrompt(\n customPrompt\n );\n },\n [editor]\n );\n\n const handleSendClick = useCallback(() => {\n if (isCustomPromptEmpty) {\n return;\n }\n\n (editor.commands as unknown as AiCommands).$startAiToolbarThinking(\n customPrompt\n );\n }, [editor, customPrompt, isCustomPromptEmpty]);\n\n return (\n <div className=\"lb-tiptap-ai-toolbar-content\">\n <span className=\"lb-icon-container lb-tiptap-ai-toolbar-icon-container\">\n <SparklesIcon />\n </span>\n <div\n className=\"lb-tiptap-ai-toolbar-custom-prompt-container\"\n data-value={customPrompt}\n >\n <Command.Input\n value={customPrompt}\n onValueChange={handleCustomPromptChange}\n asChild\n >\n <textarea\n ref={textAreaRef}\n className=\"lb-tiptap-ai-toolbar-custom-prompt\"\n placeholder={`Ask ${aiName} anything…`}\n onKeyDown={handlePromptKeyDown}\n rows={1}\n autoFocus\n disabled={disabled}\n />\n </Command.Input>\n </div>\n <div className=\"lb-tiptap-ai-toolbar-actions\">\n <ShortcutTooltip content={`Ask ${aiName}`} shortcut=\"Enter\">\n <Button\n className=\"lb-tiptap-ai-toolbar-action\"\n variant=\"primary\"\n aria-label={`Ask ${aiName}`}\n icon={<SendIcon />}\n disabled={isCustomPromptEmpty || disabled}\n onClick={handleSendClick}\n />\n </ShortcutTooltip>\n </div>\n </div>\n );\n}\n\nfunction AiToolbarAsking() {\n return <AiToolbarCustomPromptContent />;\n}\n\nfunction AiToolbarThinking() {\n const editor = useCurrentEditor(\"AiToolbarThinking\", \"AiToolbar\");\n const contentRef = useRef<HTMLDivElement>(null);\n const aiName = (editor.storage.liveblocksAi as AiExtensionStorage).name;\n\n const handleCancel = useCallback(() => {\n (editor.commands as unknown as AiCommands).$cancelAiToolbarThinking();\n }, [editor]);\n\n // Focus the toolbar content and clear the current window selection while thinking\n useLayoutEffect(() => {\n contentRef.current?.focus();\n window.getSelection()?.removeAllRanges();\n }, []);\n\n return (\n <>\n <div\n className=\"lb-tiptap-ai-toolbar-content\"\n tabIndex={0}\n ref={contentRef}\n >\n <span className=\"lb-icon-container lb-tiptap-ai-toolbar-icon-container\">\n <SparklesIcon />\n </span>\n <div className=\"lb-tiptap-ai-toolbar-thinking\">\n {aiName} is thinking…\n </div>\n <div className=\"lb-tiptap-ai-toolbar-actions\">\n <ShortcutTooltip content=\"Cancel\" shortcut=\"Escape\">\n <Button\n className=\"lb-tiptap-ai-toolbar-action\"\n variant=\"secondary\"\n aria-label=\"Cancel\"\n icon={<UndoIcon />}\n onClick={handleCancel}\n />\n </ShortcutTooltip>\n </div>\n </div>\n </>\n );\n}\n\nfunction AiToolbarReviewing() {\n const { state } = useAiToolbarContext();\n const { output } = state as Extract<AiToolbarState, { phase: \"reviewing\" }>;\n\n return (\n <>\n {output.type === \"other\" ? (\n <div className=\"lb-tiptap-ai-toolbar-output-container\">\n <div className=\"lb-tiptap-ai-toolbar-output\">{output.text}</div>\n </div>\n ) : null}\n {/* TODO: Allow to refine the output with another prompt */}\n <AiToolbarCustomPromptContent disabled />\n </>\n );\n}\n\nfunction AiToolbarContainer({\n state,\n toolbarRef,\n dropdownRef,\n children,\n}: PropsWithChildren<{\n state: AiToolbarState;\n toolbarRef: RefObject<HTMLDivElement>;\n dropdownRef: RefObject<HTMLDivElement>;\n}>) {\n const editor = useCurrentEditor(\"AiToolbarContainer\", \"AiToolbar\");\n const customPrompt = state.customPrompt;\n const isCustomPromptMultiline = useMemo(\n () => customPrompt?.includes(\"\\n\"),\n [customPrompt]\n );\n const hasDropdownItems = useCommandState(\n (state) => state.filtered.count > 0\n ) as boolean;\n const isDropdownHidden = isCustomPromptMultiline || !hasDropdownItems;\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (!event.defaultPrevented && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n\n if (state.phase === \"thinking\") {\n (editor.commands as unknown as AiCommands).$cancelAiToolbarThinking();\n } else {\n (editor.chain() as ChainedAiCommands).$closeAiToolbar().focus().run();\n }\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [editor, state.phase]);\n\n return (\n <AiToolbarContext.Provider\n value={{ state, toolbarRef, dropdownRef, isDropdownHidden }}\n >\n <div className=\"lb-tiptap-ai-toolbar-container\">\n <div className=\"lb-elevation lb-tiptap-ai-toolbar\">\n {state.phase === \"asking\" ? (\n <AiToolbarAsking />\n ) : state.phase === \"thinking\" ? (\n <AiToolbarThinking />\n ) : state.phase === \"reviewing\" ? (\n <AiToolbarReviewing />\n ) : null}\n </div>\n <div\n className=\"lb-tiptap-ai-toolbar-halo\"\n data-active={state.phase === \"thinking\" ? \"\" : undefined}\n aria-hidden\n >\n <div className=\"lb-tiptap-ai-toolbar-halo-horizontal\" />\n <div className=\"lb-tiptap-ai-toolbar-halo-vertical\" />\n </div>\n </div>\n {state.phase === \"asking\" || state.phase === \"reviewing\" ? (\n <Command.List\n className=\"lb-elevation lb-dropdown lb-tiptap-ai-toolbar-dropdown\"\n data-hidden={isDropdownHidden ? \"\" : undefined}\n ref={dropdownRef}\n >\n {state.phase === \"reviewing\" ? (\n <AiToolbarReviewingSuggestions />\n ) : (\n children\n )}\n </Command.List>\n ) : null}\n </AiToolbarContext.Provider>\n );\n}\n\nconst defaultSuggestions = (\n <>\n <AiToolbarSuggestionsGroup label=\"Modify\">\n <AiToolbarSuggestion icon={<EditIcon />}>\n Improve writing\n </AiToolbarSuggestion>\n <AiToolbarSuggestion icon={<CheckIcon />}>\n Fix mistakes\n </AiToolbarSuggestion>\n <AiToolbarSuggestion icon={<ShortenIcon />}>Simplify</AiToolbarSuggestion>\n <AiToolbarSuggestion icon={<LengthenIcon />}>\n Add more detail\n </AiToolbarSuggestion>\n </AiToolbarSuggestionsGroup>\n <AiToolbarSuggestionsGroup label=\"Generate\">\n <AiToolbarSuggestion icon={<QuestionMarkIcon />}>\n Explain\n </AiToolbarSuggestion>\n </AiToolbarSuggestionsGroup>\n </>\n);\n\nexport const AiToolbar = Object.assign(\n forwardRef<HTMLDivElement, AiToolbarProps>(\n (\n {\n position = \"bottom\",\n offset: sideOffset = 6,\n editor,\n className,\n suggestions: Suggestions = defaultSuggestions,\n ...props\n },\n forwardedRef\n ) => {\n const state =\n useEditorState({\n editor,\n selector: (ctx) => {\n return (\n ctx.editor?.storage.liveblocksAi as AiExtensionStorage | undefined\n )?.state;\n },\n }) ?? DEFAULT_STATE;\n const selection = state.selection ?? editor?.state.selection;\n const floatingOptions: UseFloatingOptions = useMemo(() => {\n const detectOverflowOptions: DetectOverflowOptions = {\n padding: AI_TOOLBAR_COLLISION_PADDING,\n };\n\n return {\n strategy: \"fixed\",\n placement: position,\n middleware: [\n tiptapFloating(editor),\n hide(detectOverflowOptions),\n offset(sideOffset),\n ],\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n };\n }, [editor, position, sideOffset]);\n const isOpen = selection !== undefined && state.phase !== \"closed\";\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n isPositioned,\n } = useFloating({\n ...floatingOptions,\n open: isOpen,\n });\n const toolbarRef = useRef<HTMLDivElement>(null);\n const mergedRefs = useRefs(forwardedRef, toolbarRef, setFloating);\n const dropdownRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n if (!selection && state.phase !== \"closed\") {\n (editor.commands as unknown as AiCommands).$closeAiToolbar();\n }\n }, [state.phase, editor, selection]);\n\n useLayoutEffect(() => {\n if (!editor || !isOpen) {\n return;\n }\n\n setReference(null);\n\n setTimeout(() => {\n if (!selection) {\n setReference(null);\n } else {\n const domRange = getDomRangeFromSelection(selection, editor);\n setReference(domRange);\n }\n }, 0);\n }, [selection, editor, isOpen, setReference]);\n\n // Close the toolbar when clicking anywhere outside of it\n useEffect(() => {\n if (!editor || !isOpen) {\n return;\n }\n\n const handleOutsideEvent = (event: MouseEvent) => {\n if (!toolbarRef.current) {\n return;\n }\n\n if (\n event.target &&\n !toolbarRef.current.contains(event.target as Node) &&\n (dropdownRef.current\n ? !dropdownRef.current.contains(event.target as Node)\n : true)\n ) {\n (editor.commands as unknown as AiCommands).$closeAiToolbar();\n }\n };\n\n setTimeout(() => {\n document.addEventListener(\"pointerdown\", handleOutsideEvent);\n }, 0);\n\n return () => {\n document.removeEventListener(\"pointerdown\", handleOutsideEvent);\n };\n }, [editor, isOpen]);\n\n if (!editor || !isOpen) {\n return null;\n }\n\n return createPortal(\n <TooltipProvider>\n <EditorProvider editor={editor}>\n <Command\n role=\"toolbar\"\n label=\"AI toolbar\"\n aria-orientation=\"horizontal\"\n className={classNames(\n \"lb-root lb-portal lb-tiptap-ai-toolbar-portal\",\n className\n )}\n ref={mergedRefs}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: isPositioned\n ? `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`\n : \"translate3d(0, -200%, 0)\",\n }}\n {...props}\n >\n <AiToolbarContainer\n state={state}\n dropdownRef={dropdownRef}\n toolbarRef={toolbarRef}\n >\n {typeof Suggestions === \"function\" ? (\n <Suggestions children={defaultSuggestions} />\n ) : (\n Suggestions\n )}\n </AiToolbarContainer>\n </Command>\n </EditorProvider>\n </TooltipProvider>,\n document.body\n );\n }\n ),\n {\n SuggestionsGroup: AiToolbarSuggestionsGroup,\n Suggestion: AiToolbarSuggestion,\n }\n);\n"],"names":["customPrompt","state"],"mappings":";;;;;;;;;;;;;AA0DO,MAAM,4BAA+B,GAAA,GAAA;AAiC5C,MAAM,gBAAA,GAAmB,cAAuC,IAAI,CAAA,CAAA;AAEpE,SAAS,mBAAsB,GAAA;AAC7B,EAAM,MAAA,OAAA,GAAU,WAAW,gBAAgB,CAAA,CAAA;AAE3C,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,sDAAsD,CAAA,CAAA;AAAA,GACxE;AAEA,EAAO,OAAA,OAAA,CAAA;AACT,CAAA;AAQA,SAAS,eAAe,MAAmC,EAAA;AACzD,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,QAAA;AAAA,IACN,OAAS,EAAA,MAAA;AAAA,IACT,EAAA,CAAG,EAAE,QAAA,EAAY,EAAA;AACf,MAAA,IAAI,CAAC,MAAQ,EAAA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 -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommentsExtension.js","sources":["../../src/comments/CommentsExtension.ts"],"sourcesContent":["import { Extension, Mark, mergeAttributes } from \"@tiptap/core\";\nimport type { Node } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\nimport { Plugin } from \"@tiptap/pm/state\";\nimport { Decoration, DecorationSet } from \"@tiptap/pm/view\";\nimport { ySyncPluginKey } from \"y-prosemirror\";\n\nimport type { CommentsExtensionStorage, ThreadPluginState } from \"../types\";\nimport {\n LIVEBLOCKS_COMMENT_MARK_TYPE,\n ThreadPluginActions,\n THREADS_ACTIVE_SELECTION_PLUGIN,\n THREADS_PLUGIN_KEY,\n} from \"../types\";\n\ntype ThreadPluginAction = {\n name: ThreadPluginActions;\n data: string | null;\n};\n\n/**\n * Known issues: Overlapping marks are merged when reloading the doc. May be related:\n * https://github.com/ueberdosis/tiptap/issues/4339\n * https://github.com/yjs/y-prosemirror/issues/47\n */\nconst Comment = Mark.create({\n name: LIVEBLOCKS_COMMENT_MARK_TYPE,\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n addAttributes() {\n // Return an object with attribute configuration\n return {\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-lb-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-lb-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, any> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"lb-root lb-tiptap-thread-mark\",\n }),\n ];\n },\n\n /**\n * This plugin tracks the (first) position of each thread mark in the doc and creates a decoration for the selected thread\n */\n addProseMirrorPlugins() {\n const updateState = (doc: Node, selectedThreadId: string | null) => {\n const threadPositions = new Map<string, { from: number; to: number }>();\n const decorations: Decoration[] = [];\n // find all thread marks and store their position + create decoration for selected thread\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type === this.type) {\n const thisThreadId = (\n mark.attrs as { threadId: string | undefined }\n ).threadId;\n if (!thisThreadId) {\n return;\n }\n const from = pos;\n const to = from + node.nodeSize;\n\n // FloatingThreads component uses \"to\" as the position, so always store the largest \"to\" found\n // AnchoredThreads component uses \"from\" as the position, so always store the smallest \"from\" found\n const currentPosition = threadPositions.get(thisThreadId) ?? {\n from: Infinity,\n to: 0,\n };\n threadPositions.set(thisThreadId, {\n from: Math.min(from, currentPosition.from),\n to: Math.max(to, currentPosition.to),\n });\n\n if (selectedThreadId === thisThreadId) {\n decorations.push(\n Decoration.inline(from, to, {\n class: \"lb-root lb-tiptap-thread-mark-selected\",\n })\n );\n }\n }\n });\n });\n return {\n decorations: DecorationSet.create(doc, decorations),\n selectedThreadId,\n threadPositions,\n selectedThreadPos:\n selectedThreadId !== null\n ? (threadPositions.get(selectedThreadId)?.to ?? null)\n : null,\n };\n };\n\n return [\n new Plugin({\n key: THREADS_PLUGIN_KEY,\n state: {\n init() {\n return {\n threadPositions: new Map<string, { from: number; to: number }>(),\n selectedThreadId: null,\n selectedThreadPos: null,\n decorations: DecorationSet.empty,\n } as ThreadPluginState;\n },\n apply(tr, state) {\n const action = tr.getMeta(THREADS_PLUGIN_KEY) as ThreadPluginAction;\n if (!tr.docChanged && !action) {\n return state;\n }\n\n if (!action) {\n // Doc changed, but no action, just update rects\n return updateState(tr.doc, state.selectedThreadId);\n }\n // handle actions, possibly support more actions\n if (\n action.name === ThreadPluginActions.SET_SELECTED_THREAD_ID &&\n state.selectedThreadId !== action.data\n ) {\n return updateState(tr.doc, action.data);\n }\n\n return state;\n },\n },\n props: {\n decorations: (state) => {\n return (\n THREADS_PLUGIN_KEY.getState(state)?.decorations ??\n DecorationSet.empty\n );\n },\n handleClick: (view, pos, event) => {\n if (event.button !== 0) {\n return;\n }\n\n const selectThread = (threadId: string | null) => {\n view.dispatch(\n view.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: threadId,\n })\n );\n };\n\n const node = view.state.doc.nodeAt(pos);\n if (!node) {\n selectThread(null);\n return;\n }\n const commentMark = node.marks.find(\n (mark) => mark.type === this.type\n );\n // don't allow selecting orphaned threads\n if (commentMark?.attrs.orphan) {\n selectThread(null);\n return;\n }\n const threadId = commentMark?.attrs.threadId as string | undefined;\n selectThread(threadId ?? null);\n },\n },\n }),\n ];\n },\n});\n\nexport const CommentsExtension = Extension.create<\n never,\n CommentsExtensionStorage\n>({\n name: \"liveblocksComments\",\n priority: 95,\n addExtensions() {\n return [Comment];\n },\n\n addStorage() {\n return {\n pendingComment: false,\n };\n },\n\n addCommands() {\n return {\n addPendingComment: () => () => {\n if (this.editor.state.selection.empty) {\n return false;\n }\n // unselect any open threads\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: null,\n })\n );\n this.storage.pendingComment = true;\n return true;\n },\n closePendingComment: () => () => {\n this.storage.pendingComment = false;\n return true;\n },\n selectThread: (id: string | null) => () => {\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: id,\n })\n );\n return true;\n },\n addComment:\n (id: string) =>\n ({ commands }) => {\n if (\n !this.storage.pendingComment ||\n this.editor.state.selection.empty\n ) {\n return false;\n }\n commands.setMark(LIVEBLOCKS_COMMENT_MARK_TYPE, { threadId: id });\n this.storage.pendingComment = false;\n return true;\n },\n };\n },\n\n //@ts-expect-error - this is incorrectly typed upstream in Mark.ts of TipTap. This event does include transaction\n // correct: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/types.ts#L60\n // incorrect: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/Mark.ts#L330\n onSelectionUpdate(\n this: { storage: Storage }, // NOTE: there are more types here I didn't override, this gets removed after submitting PR to tiptap\n { transaction }: { transaction: Transaction } // TODO: remove this after submitting PR to tiptap\n ) {\n // ignore changes made by yjs\n if (!this.storage.pendingComment || transaction.getMeta(ySyncPluginKey)) {\n return;\n }\n // if selection changes, hide the composer. We could keep the composer open and move it to the new selection?\n this.storage.pendingComment = false;\n },\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: THREADS_ACTIVE_SELECTION_PLUGIN,\n props: {\n decorations: ({ doc, selection }) => {\n if (!this.storage.pendingComment) {\n return DecorationSet.create(doc, []);\n }\n const { from, to } = selection;\n const decorations: Decoration[] = [\n Decoration.inline(from, to, {\n class: \"lb-root lb-selection lb-tiptap-active-selection\",\n }),\n ];\n return DecorationSet.create(doc, decorations);\n },\n },\n }),\n ];\n },\n});\n"],"names":["Mark","LIVEBLOCKS_COMMENT_MARK_TYPE","mergeAttributes","Decoration","DecorationSet","Plugin","THREADS_PLUGIN_KEY","ThreadPluginActions","threadId","Extension","ySyncPluginKey","THREADS_ACTIVE_SELECTION_PLUGIN"],"mappings":";;;;;;;;AAyBA,MAAM,OAAA,GAAUA,UAAK,MAAO,CAAA;AAAA,EAC1B,IAAM,EAAAC,kCAAA;AAAA,EACN,QAAU,EAAA,EAAA;AAAA,EACV,SAAW,EAAA,KAAA;AAAA,EACX,WAAa,EAAA,IAAA;AAAA,EACb,aAAgB,GAAA;AAEd,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA;AAAA,QACN,WAAW,CAAC,OAAA,KAAY,CAAC,CAAC,OAAA,CAAQ,aAAa,aAAa,CAAA;AAAA,QAC5D,UAAA,EAAY,CAAC,UAAe,KAAA;AAC1B,UAAA,OAAQ,WAAmC,MACvC,GAAA;AAAA,YACE,aAAe,EAAA,MAAA;AAAA,cAEjB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cAAiB,GAAA,KAAA,CAAA;AAAA,GAChC;AAAA,EACA,qBAAwB,GAAA;AACtB,IAAO,OAAA;AAAA,MACL,IAAIL,YAAO,CAAA;AAAA,QACT,GAAK,EAAAM,qCAAA;AAAA,QACL,KAAO,EAAA;AAAA,UACL,WAAa,EAAA,CAAC,EAAE,GAAA,EAAK,WAAgB,KAAA;AACnC,YAAI,IAAA,CAAC,IAAK,CAAA,OAAA,CAAQ,cAAgB,EAAA;AAChC,cAAA,OAAOP,kBAAc,CAAA,MAAA,CAAO,GAAK,EAAA,EAAE,CAAA,CAAA;AAAA,aACrC;AACA,YAAM,MAAA,EAAE,IAAM,EAAA,EAAA,EAAO,GAAA,SAAA,CAAA;AACrB,YAAA,MAAM,WAA4B,GAAA;AAAA,cAChCD,eAAA,CAAW,MAAO,CAAA,IAAA,EAAM,EAAI,EAAA;AAAA,gBAC1B,KAAO,EAAA,iDAAA;AAAA,eACR,CAAA;AAAA,aACH,CAAA;AACA,YAAO,OAAAC,kBAAA,CAAc,MAAO,CAAA,GAAA,EAAK,WAAW,CAAA,CAAA;AAAA,WAC9C;AAAA,SACF;AAAA,OACD,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AACF,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"CommentsExtension.js","sources":["../../src/comments/CommentsExtension.ts"],"sourcesContent":["import { Extension, Mark, mergeAttributes } from \"@tiptap/core\";\nimport type { Node } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\nimport { Plugin } from \"@tiptap/pm/state\";\nimport { Decoration, DecorationSet } from \"@tiptap/pm/view\";\nimport { ySyncPluginKey } from \"y-prosemirror\";\n\nimport type { CommentsExtensionStorage, ThreadPluginState } from \"../types\";\nimport {\n LIVEBLOCKS_COMMENT_MARK_TYPE,\n ThreadPluginActions,\n THREADS_ACTIVE_SELECTION_PLUGIN,\n THREADS_PLUGIN_KEY,\n} from \"../types\";\n\ntype ThreadPluginAction = {\n name: ThreadPluginActions;\n data: string | null;\n};\n\n/**\n * Known issues: Overlapping marks are merged when reloading the doc. May be related:\n * https://github.com/ueberdosis/tiptap/issues/4339\n * https://github.com/yjs/y-prosemirror/issues/47\n */\nconst Comment = Mark.create({\n name: LIVEBLOCKS_COMMENT_MARK_TYPE,\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n addAttributes() {\n // Return an object with attribute configuration\n return {\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-lb-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-lb-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, any> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"lb-root lb-tiptap-thread-mark\",\n }),\n ];\n },\n\n /**\n * This plugin tracks the (first) position of each thread mark in the doc and creates a decoration for the selected thread\n */\n addProseMirrorPlugins() {\n const updateState = (doc: Node, selectedThreadId: string | null) => {\n const threadPositions = new Map<string, { from: number; to: number }>();\n const decorations: Decoration[] = [];\n // find all thread marks and store their position + create decoration for selected thread\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type === this.type) {\n const thisThreadId = (\n mark.attrs as { threadId: string | undefined }\n ).threadId;\n if (!thisThreadId) {\n return;\n }\n const from = pos;\n const to = from + node.nodeSize;\n\n // FloatingThreads component uses \"to\" as the position, so always store the largest \"to\" found\n // AnchoredThreads component uses \"from\" as the position, so always store the smallest \"from\" found\n const currentPosition = threadPositions.get(thisThreadId) ?? {\n from: Infinity,\n to: 0,\n };\n threadPositions.set(thisThreadId, {\n from: Math.min(from, currentPosition.from),\n to: Math.max(to, currentPosition.to),\n });\n\n if (selectedThreadId === thisThreadId) {\n decorations.push(\n Decoration.inline(from, to, {\n class: \"lb-root lb-tiptap-thread-mark-selected\",\n })\n );\n }\n }\n });\n });\n return {\n decorations: DecorationSet.create(doc, decorations),\n selectedThreadId,\n threadPositions,\n selectedThreadPos:\n selectedThreadId !== null\n ? (threadPositions.get(selectedThreadId)?.to ?? null)\n : null,\n };\n };\n\n return [\n new Plugin({\n key: THREADS_PLUGIN_KEY,\n state: {\n init() {\n return {\n threadPositions: new Map<string, { from: number; to: number }>(),\n selectedThreadId: null,\n selectedThreadPos: null,\n decorations: DecorationSet.empty,\n } as ThreadPluginState;\n },\n apply(tr, state) {\n const action = tr.getMeta(THREADS_PLUGIN_KEY) as ThreadPluginAction;\n if (!tr.docChanged && !action) {\n return state;\n }\n\n if (!action) {\n // Doc changed, but no action, just update rects\n return updateState(tr.doc, state.selectedThreadId);\n }\n // handle actions, possibly support more actions\n if (\n action.name === ThreadPluginActions.SET_SELECTED_THREAD_ID &&\n state.selectedThreadId !== action.data\n ) {\n return updateState(tr.doc, action.data);\n }\n\n return state;\n },\n },\n props: {\n decorations: (state) => {\n return (\n THREADS_PLUGIN_KEY.getState(state)?.decorations ??\n DecorationSet.empty\n );\n },\n handleClick: (view, pos, event) => {\n if (event.button !== 0) {\n return;\n }\n\n const selectThread = (threadId: string | null) => {\n view.dispatch(\n view.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: threadId,\n })\n );\n };\n\n const node = view.state.doc.nodeAt(pos);\n if (!node) {\n selectThread(null);\n return;\n }\n const commentMark = node.marks.find(\n (mark) => mark.type === this.type\n );\n // don't allow selecting orphaned threads\n if (commentMark?.attrs.orphan) {\n selectThread(null);\n return;\n }\n const threadId = commentMark?.attrs.threadId as string | undefined;\n selectThread(threadId ?? null);\n },\n },\n }),\n ];\n },\n});\n\nexport const CommentsExtension = Extension.create<\n never,\n CommentsExtensionStorage\n>({\n name: \"liveblocksComments\",\n priority: 95,\n addExtensions() {\n return [Comment];\n },\n\n addStorage() {\n return {\n pendingComment: false,\n };\n },\n\n addCommands() {\n return {\n addPendingComment: () => () => {\n if (this.editor.state.selection.empty) {\n return false;\n }\n // unselect any open threads\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: null,\n })\n );\n this.storage.pendingComment = true;\n return true;\n },\n closePendingComment: () => () => {\n this.storage.pendingComment = false;\n return true;\n },\n selectThread: (id: string | null) => () => {\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: id,\n })\n );\n return true;\n },\n addComment:\n (id: string) =>\n ({ commands }) => {\n if (\n !this.storage.pendingComment ||\n this.editor.state.selection.empty\n ) {\n return false;\n }\n commands.setMark(LIVEBLOCKS_COMMENT_MARK_TYPE, { threadId: id });\n this.storage.pendingComment = false;\n return true;\n },\n };\n },\n\n // @ts-expect-error - this is incorrectly typed upstream in Mark.ts of TipTap. This event does include transaction\n // correct: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/types.ts#L60\n // incorrect: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/Mark.ts#L330\n onSelectionUpdate(\n this: { storage: CommentsExtensionStorage }, // NOTE: there are more types here I didn't override, this gets removed after submitting PR to tiptap\n { transaction }: { transaction: Transaction } // TODO: remove this after submitting PR to tiptap\n ) {\n // ignore changes made by yjs\n if (!this.storage.pendingComment || transaction.getMeta(ySyncPluginKey)) {\n return;\n }\n // if selection changes, hide the composer. We could keep the composer open and move it to the new selection?\n this.storage.pendingComment = false;\n },\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: THREADS_ACTIVE_SELECTION_PLUGIN,\n props: {\n decorations: ({ doc, selection }) => {\n if (!this.storage.pendingComment) {\n return DecorationSet.create(doc, []);\n }\n const { from, to } = selection;\n const decorations: Decoration[] = [\n Decoration.inline(from, to, {\n class: \"lb-root lb-selection lb-tiptap-active-selection\",\n }),\n ];\n return DecorationSet.create(doc, decorations);\n },\n },\n }),\n ];\n },\n});\n"],"names":["Mark","LIVEBLOCKS_COMMENT_MARK_TYPE","mergeAttributes","Decoration","DecorationSet","Plugin","THREADS_PLUGIN_KEY","ThreadPluginActions","threadId","Extension","ySyncPluginKey","THREADS_ACTIVE_SELECTION_PLUGIN"],"mappings":";;;;;;;;AAyBA,MAAM,OAAA,GAAUA,UAAK,MAAO,CAAA;AAAA,EAC1B,IAAM,EAAAC,kCAAA;AAAA,EACN,QAAU,EAAA,EAAA;AAAA,EACV,SAAW,EAAA,KAAA;AAAA,EACX,WAAa,EAAA,IAAA;AAAA,EACb,aAAgB,GAAA;AAEd,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA;AAAA,QACN,WAAW,CAAC,OAAA,KAAY,CAAC,CAAC,OAAA,CAAQ,aAAa,aAAa,CAAA;AAAA,QAC5D,UAAA,EAAY,CAAC,UAAe,KAAA;AAC1B,UAAA,OAAQ,WAAmC,MACvC,GAAA;AAAA,YACE,aAAe,EAAA,MAAA;AAAA,cAEjB,EAAC,CAAA;AAAA,SACP;AAAA,QACA,OAAS,EAAA,KAAA;AAAA,OACX;AAAA,MACA,QAAU,EAAA;AAAA,QACR,SAAW,EAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,aAAa,mBAAmB,CAAA;AAAA,QAChE,UAAA,EAAY,CAAC,UAAe,KAAA;AAC1B,UAAO,OAAA;AAAA,YACL,qBAAsB,UAAoC,CAAA,QAAA;AAAA,WAC5D,CAAA;AAAA,SACF;AAAA,QACA,OAAS,EAAA,EAAA;AAAA,OACX;AAAA,KACF,CAAA;AAAA,GACF;AAAA,EAEA,UAAA,CAAW,EAAE,cAAA,EAA2D,EAAA;AACtE,IAAO,OAAA;AAAA,MACL,MAAA;AAAA,MACAC,qBAAgB,cAAgB,EAAA;A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AChCD,eAAA,CAAW,MAAO,CAAA,IAAA,EAAM,EAAI,EAAA;AAAA,gBAC1B,KAAO,EAAA,iDAAA;AAAA,eACR,CAAA;AAAA,aACH,CAAA;AACA,YAAO,OAAAC,kBAAA,CAAc,MAAO,CAAA,GAAA,EAAK,WAAW,CAAA,CAAA;AAAA,WAC9C;AAAA,SACF;AAAA,OACD,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AACF,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommentsExtension.mjs","sources":["../../src/comments/CommentsExtension.ts"],"sourcesContent":["import { Extension, Mark, mergeAttributes } from \"@tiptap/core\";\nimport type { Node } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\nimport { Plugin } from \"@tiptap/pm/state\";\nimport { Decoration, DecorationSet } from \"@tiptap/pm/view\";\nimport { ySyncPluginKey } from \"y-prosemirror\";\n\nimport type { CommentsExtensionStorage, ThreadPluginState } from \"../types\";\nimport {\n LIVEBLOCKS_COMMENT_MARK_TYPE,\n ThreadPluginActions,\n THREADS_ACTIVE_SELECTION_PLUGIN,\n THREADS_PLUGIN_KEY,\n} from \"../types\";\n\ntype ThreadPluginAction = {\n name: ThreadPluginActions;\n data: string | null;\n};\n\n/**\n * Known issues: Overlapping marks are merged when reloading the doc. May be related:\n * https://github.com/ueberdosis/tiptap/issues/4339\n * https://github.com/yjs/y-prosemirror/issues/47\n */\nconst Comment = Mark.create({\n name: LIVEBLOCKS_COMMENT_MARK_TYPE,\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n addAttributes() {\n // Return an object with attribute configuration\n return {\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-lb-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-lb-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, any> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"lb-root lb-tiptap-thread-mark\",\n }),\n ];\n },\n\n /**\n * This plugin tracks the (first) position of each thread mark in the doc and creates a decoration for the selected thread\n */\n addProseMirrorPlugins() {\n const updateState = (doc: Node, selectedThreadId: string | null) => {\n const threadPositions = new Map<string, { from: number; to: number }>();\n const decorations: Decoration[] = [];\n // find all thread marks and store their position + create decoration for selected thread\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type === this.type) {\n const thisThreadId = (\n mark.attrs as { threadId: string | undefined }\n ).threadId;\n if (!thisThreadId) {\n return;\n }\n const from = pos;\n const to = from + node.nodeSize;\n\n // FloatingThreads component uses \"to\" as the position, so always store the largest \"to\" found\n // AnchoredThreads component uses \"from\" as the position, so always store the smallest \"from\" found\n const currentPosition = threadPositions.get(thisThreadId) ?? {\n from: Infinity,\n to: 0,\n };\n threadPositions.set(thisThreadId, {\n from: Math.min(from, currentPosition.from),\n to: Math.max(to, currentPosition.to),\n });\n\n if (selectedThreadId === thisThreadId) {\n decorations.push(\n Decoration.inline(from, to, {\n class: \"lb-root lb-tiptap-thread-mark-selected\",\n })\n );\n }\n }\n });\n });\n return {\n decorations: DecorationSet.create(doc, decorations),\n selectedThreadId,\n threadPositions,\n selectedThreadPos:\n selectedThreadId !== null\n ? (threadPositions.get(selectedThreadId)?.to ?? null)\n : null,\n };\n };\n\n return [\n new Plugin({\n key: THREADS_PLUGIN_KEY,\n state: {\n init() {\n return {\n threadPositions: new Map<string, { from: number; to: number }>(),\n selectedThreadId: null,\n selectedThreadPos: null,\n decorations: DecorationSet.empty,\n } as ThreadPluginState;\n },\n apply(tr, state) {\n const action = tr.getMeta(THREADS_PLUGIN_KEY) as ThreadPluginAction;\n if (!tr.docChanged && !action) {\n return state;\n }\n\n if (!action) {\n // Doc changed, but no action, just update rects\n return updateState(tr.doc, state.selectedThreadId);\n }\n // handle actions, possibly support more actions\n if (\n action.name === ThreadPluginActions.SET_SELECTED_THREAD_ID &&\n state.selectedThreadId !== action.data\n ) {\n return updateState(tr.doc, action.data);\n }\n\n return state;\n },\n },\n props: {\n decorations: (state) => {\n return (\n THREADS_PLUGIN_KEY.getState(state)?.decorations ??\n DecorationSet.empty\n );\n },\n handleClick: (view, pos, event) => {\n if (event.button !== 0) {\n return;\n }\n\n const selectThread = (threadId: string | null) => {\n view.dispatch(\n view.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: threadId,\n })\n );\n };\n\n const node = view.state.doc.nodeAt(pos);\n if (!node) {\n selectThread(null);\n return;\n }\n const commentMark = node.marks.find(\n (mark) => mark.type === this.type\n );\n // don't allow selecting orphaned threads\n if (commentMark?.attrs.orphan) {\n selectThread(null);\n return;\n }\n const threadId = commentMark?.attrs.threadId as string | undefined;\n selectThread(threadId ?? null);\n },\n },\n }),\n ];\n },\n});\n\nexport const CommentsExtension = Extension.create<\n never,\n CommentsExtensionStorage\n>({\n name: \"liveblocksComments\",\n priority: 95,\n addExtensions() {\n return [Comment];\n },\n\n addStorage() {\n return {\n pendingComment: false,\n };\n },\n\n addCommands() {\n return {\n addPendingComment: () => () => {\n if (this.editor.state.selection.empty) {\n return false;\n }\n // unselect any open threads\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: null,\n })\n );\n this.storage.pendingComment = true;\n return true;\n },\n closePendingComment: () => () => {\n this.storage.pendingComment = false;\n return true;\n },\n selectThread: (id: string | null) => () => {\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: id,\n })\n );\n return true;\n },\n addComment:\n (id: string) =>\n ({ commands }) => {\n if (\n !this.storage.pendingComment ||\n this.editor.state.selection.empty\n ) {\n return false;\n }\n commands.setMark(LIVEBLOCKS_COMMENT_MARK_TYPE, { threadId: id });\n this.storage.pendingComment = false;\n return true;\n },\n };\n },\n\n //@ts-expect-error - this is incorrectly typed upstream in Mark.ts of TipTap. This event does include transaction\n // correct: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/types.ts#L60\n // incorrect: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/Mark.ts#L330\n onSelectionUpdate(\n this: { storage: Storage }, // NOTE: there are more types here I didn't override, this gets removed after submitting PR to tiptap\n { transaction }: { transaction: Transaction } // TODO: remove this after submitting PR to tiptap\n ) {\n // ignore changes made by yjs\n if (!this.storage.pendingComment || transaction.getMeta(ySyncPluginKey)) {\n return;\n }\n // if selection changes, hide the composer. We could keep the composer open and move it to the new selection?\n this.storage.pendingComment = false;\n },\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: THREADS_ACTIVE_SELECTION_PLUGIN,\n props: {\n decorations: ({ doc, selection }) => {\n if (!this.storage.pendingComment) {\n return DecorationSet.create(doc, []);\n }\n const { from, to } = selection;\n const decorations: Decoration[] = [\n Decoration.inline(from, to, {\n class: \"lb-root lb-selection lb-tiptap-active-selection\",\n }),\n ];\n return DecorationSet.create(doc, decorations);\n },\n },\n }),\n ];\n },\n});\n"],"names":["threadId"],"mappings":";;;;;;AAyBA,MAAM,OAAA,GAAU,KAAK,MAAO,CAAA;AAAA,EAC1B,IAAM,EAAA,4BAAA;AAAA,EACN,QAAU,EAAA,EAAA;AAAA,EACV,SAAW,EAAA,KAAA;AAAA,EACX,WAAa,EAAA,IAAA;AAAA,EACb,aAAgB,GAAA;AAEd,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA;AAAA,QACN,WAAW,CAAC,OAAA,KAAY,CAAC,CAAC,OAAA,CAAQ,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A,CAAQ,kBAAkB,WAAY,CAAA,OAAA,CAAQ,cAAc,CAAG,EAAA;AACvE,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,QAAQ,cAAiB,GAAA,KAAA,CAAA;AAAA,GAChC;AAAA,EACA,qBAAwB,GAAA;AACtB,IAAO,OAAA;AAAA,MACL,IAAI,MAAO,CAAA;AAAA,QACT,GAAK,EAAA,+BAAA;AAAA,QACL,KAAO,EAAA;AAAA,UACL,WAAa,EAAA,CAAC,EAAE,GAAA,EAAK,WAAgB,KAAA;AACnC,YAAI,IAAA,CAAC,IAAK,CAAA,OAAA,CAAQ,cAAgB,EAAA;AAChC,cAAA,OAAO,aAAc,CAAA,MAAA,CAAO,GAAK,EAAA,EAAE,CAAA,CAAA;AAAA,aACrC;AACA,YAAM,MAAA,EAAE,IAAM,EAAA,EAAA,EAAO,GAAA,SAAA,CAAA;AACrB,YAAA,MAAM,WAA4B,GAAA;AAAA,cAChC,UAAA,CAAW,MAAO,CAAA,IAAA,EAAM,EAAI,EAAA;AAAA,gBAC1B,KAAO,EAAA,iDAAA;AAAA,eACR,CAAA;AAAA,aACH,CAAA;AACA,YAAO,OAAA,aAAA,CAAc,MAAO,CAAA,GAAA,EAAK,WAAW,CAAA,CAAA;AAAA,WAC9C;AAAA,SACF;AAAA,OACD,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AACF,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"CommentsExtension.mjs","sources":["../../src/comments/CommentsExtension.ts"],"sourcesContent":["import { Extension, Mark, mergeAttributes } from \"@tiptap/core\";\nimport type { Node } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\nimport { Plugin } from \"@tiptap/pm/state\";\nimport { Decoration, DecorationSet } from \"@tiptap/pm/view\";\nimport { ySyncPluginKey } from \"y-prosemirror\";\n\nimport type { CommentsExtensionStorage, ThreadPluginState } from \"../types\";\nimport {\n LIVEBLOCKS_COMMENT_MARK_TYPE,\n ThreadPluginActions,\n THREADS_ACTIVE_SELECTION_PLUGIN,\n THREADS_PLUGIN_KEY,\n} from \"../types\";\n\ntype ThreadPluginAction = {\n name: ThreadPluginActions;\n data: string | null;\n};\n\n/**\n * Known issues: Overlapping marks are merged when reloading the doc. May be related:\n * https://github.com/ueberdosis/tiptap/issues/4339\n * https://github.com/yjs/y-prosemirror/issues/47\n */\nconst Comment = Mark.create({\n name: LIVEBLOCKS_COMMENT_MARK_TYPE,\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n addAttributes() {\n // Return an object with attribute configuration\n return {\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-lb-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-lb-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, any> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"lb-root lb-tiptap-thread-mark\",\n }),\n ];\n },\n\n /**\n * This plugin tracks the (first) position of each thread mark in the doc and creates a decoration for the selected thread\n */\n addProseMirrorPlugins() {\n const updateState = (doc: Node, selectedThreadId: string | null) => {\n const threadPositions = new Map<string, { from: number; to: number }>();\n const decorations: Decoration[] = [];\n // find all thread marks and store their position + create decoration for selected thread\n doc.descendants((node, pos) => {\n node.marks.forEach((mark) => {\n if (mark.type === this.type) {\n const thisThreadId = (\n mark.attrs as { threadId: string | undefined }\n ).threadId;\n if (!thisThreadId) {\n return;\n }\n const from = pos;\n const to = from + node.nodeSize;\n\n // FloatingThreads component uses \"to\" as the position, so always store the largest \"to\" found\n // AnchoredThreads component uses \"from\" as the position, so always store the smallest \"from\" found\n const currentPosition = threadPositions.get(thisThreadId) ?? {\n from: Infinity,\n to: 0,\n };\n threadPositions.set(thisThreadId, {\n from: Math.min(from, currentPosition.from),\n to: Math.max(to, currentPosition.to),\n });\n\n if (selectedThreadId === thisThreadId) {\n decorations.push(\n Decoration.inline(from, to, {\n class: \"lb-root lb-tiptap-thread-mark-selected\",\n })\n );\n }\n }\n });\n });\n return {\n decorations: DecorationSet.create(doc, decorations),\n selectedThreadId,\n threadPositions,\n selectedThreadPos:\n selectedThreadId !== null\n ? (threadPositions.get(selectedThreadId)?.to ?? null)\n : null,\n };\n };\n\n return [\n new Plugin({\n key: THREADS_PLUGIN_KEY,\n state: {\n init() {\n return {\n threadPositions: new Map<string, { from: number; to: number }>(),\n selectedThreadId: null,\n selectedThreadPos: null,\n decorations: DecorationSet.empty,\n } as ThreadPluginState;\n },\n apply(tr, state) {\n const action = tr.getMeta(THREADS_PLUGIN_KEY) as ThreadPluginAction;\n if (!tr.docChanged && !action) {\n return state;\n }\n\n if (!action) {\n // Doc changed, but no action, just update rects\n return updateState(tr.doc, state.selectedThreadId);\n }\n // handle actions, possibly support more actions\n if (\n action.name === ThreadPluginActions.SET_SELECTED_THREAD_ID &&\n state.selectedThreadId !== action.data\n ) {\n return updateState(tr.doc, action.data);\n }\n\n return state;\n },\n },\n props: {\n decorations: (state) => {\n return (\n THREADS_PLUGIN_KEY.getState(state)?.decorations ??\n DecorationSet.empty\n );\n },\n handleClick: (view, pos, event) => {\n if (event.button !== 0) {\n return;\n }\n\n const selectThread = (threadId: string | null) => {\n view.dispatch(\n view.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: threadId,\n })\n );\n };\n\n const node = view.state.doc.nodeAt(pos);\n if (!node) {\n selectThread(null);\n return;\n }\n const commentMark = node.marks.find(\n (mark) => mark.type === this.type\n );\n // don't allow selecting orphaned threads\n if (commentMark?.attrs.orphan) {\n selectThread(null);\n return;\n }\n const threadId = commentMark?.attrs.threadId as string | undefined;\n selectThread(threadId ?? null);\n },\n },\n }),\n ];\n },\n});\n\nexport const CommentsExtension = Extension.create<\n never,\n CommentsExtensionStorage\n>({\n name: \"liveblocksComments\",\n priority: 95,\n addExtensions() {\n return [Comment];\n },\n\n addStorage() {\n return {\n pendingComment: false,\n };\n },\n\n addCommands() {\n return {\n addPendingComment: () => () => {\n if (this.editor.state.selection.empty) {\n return false;\n }\n // unselect any open threads\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: null,\n })\n );\n this.storage.pendingComment = true;\n return true;\n },\n closePendingComment: () => () => {\n this.storage.pendingComment = false;\n return true;\n },\n selectThread: (id: string | null) => () => {\n this.editor.view.dispatch(\n this.editor.state.tr.setMeta(THREADS_PLUGIN_KEY, {\n name: ThreadPluginActions.SET_SELECTED_THREAD_ID,\n data: id,\n })\n );\n return true;\n },\n addComment:\n (id: string) =>\n ({ commands }) => {\n if (\n !this.storage.pendingComment ||\n this.editor.state.selection.empty\n ) {\n return false;\n }\n commands.setMark(LIVEBLOCKS_COMMENT_MARK_TYPE, { threadId: id });\n this.storage.pendingComment = false;\n return true;\n },\n };\n },\n\n // @ts-expect-error - this is incorrectly typed upstream in Mark.ts of TipTap. This event does include transaction\n // correct: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/types.ts#L60\n // incorrect: https://github.com/ueberdosis/tiptap/blob/2ff327ced84df6865b4ef98947b667aa79992292/packages/core/src/Mark.ts#L330\n onSelectionUpdate(\n this: { storage: CommentsExtensionStorage }, // NOTE: there are more types here I didn't override, this gets removed after submitting PR to tiptap\n { transaction }: { transaction: Transaction } // TODO: remove this after submitting PR to tiptap\n ) {\n // ignore changes made by yjs\n if (!this.storage.pendingComment || transaction.getMeta(ySyncPluginKey)) {\n return;\n }\n // if selection changes, hide the composer. We could keep the composer open and move it to the new selection?\n this.storage.pendingComment = false;\n },\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: THREADS_ACTIVE_SELECTION_PLUGIN,\n props: {\n decorations: ({ doc, selection }) => {\n if (!this.storage.pendingComment) {\n return DecorationSet.create(doc, []);\n }\n const { from, to } = selection;\n const decorations: Decoration[] = [\n Decoration.inline(from, to, {\n class: \"lb-root lb-selection lb-tiptap-active-selection\",\n }),\n ];\n return DecorationSet.create(doc, decorations);\n },\n },\n }),\n ];\n },\n});\n"],"names":["threadId"],"mappings":";;;;;;AAyBA,MAAM,OAAA,GAAU,KAAK,MAAO,CAAA;AAAA,EAC1B,IAAM,EAAA,4BAAA;AAAA,EACN,QAAU,EAAA,EAAA;AAAA,EACV,SAAW,EAAA,KAAA;AAAA,EACX,WAAa,EAAA,IAAA;AAAA,EACb,aAAgB,GAAA;AAEd,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA;AAAA,QACN,WAAW,CAAC,OAAA,KAAY,CAAC,CAAC,OAAA,CAAQ,aAAa,aAAa,CAAA;AAAA,QAC5D,UAAA,EAAY,CAAC,UAAe,KAAA;AAC1B,UAAA,OAAQ,WAAmC,MACvC,GAAA;AAAA,YACE,aAAe,EAAA,MAAA;AAAA,cAEjB,EAAC,CAAA;AAAA,SACP;AAAA,QACA,OAAS,EAAA,KAAA;AAAA,OACX;AAAA,MACA,QAAU,EAAA;AAAA,QACR,SAAW,EAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,aAAa,mBAAmB,CAAA;AAAA,QAChE,UAAA,EAAY,CAAC,UAAe,KAAA;AAC1B,UAAO,OAAA;AAAA,YACL,qBAAsB,UAAoC,CAAA,QAAA;AAAA,WAC5D,CAAA;AAAA,SACF;AAAA,QACA,OAAS,EAAA,EAAA;AAAA,OACX;AAAA,KACF,CAAA;AAAA,GACF;AAAA,EAEA,UAAA,CAAW,EAAE,cAAA,EAA2D,EAAA;AACtE,IAAO,OAAA;AAAA,MACL,MAAA;AAAA,MACA,gBAAgB,cAAgB,EAAA;AAAA,QAC9B,KAAO,EAAA,+BAAA;AAA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gBAC1B,KAAO,EAAA,iDAAA;AAAA,eACR,CAAA;AAAA,aACH,CAAA;AACA,YAAO,OAAA,aAAA,CAAc,MAAO,CAAA,GAAA,EAAK,WAAW,CAAA,CAAA;AAAA,WAC9C;AAAA,SACF;AAAA,OACD,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AACF,CAAC;;;;"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
+
import { Content, Extension } from '@tiptap/core';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ComponentProps, ReactNode, ComponentType, PropsWithChildren, ComponentPropsWithoutRef, HTMLAttributes } from 'react';
|
|
4
|
+
import { Editor } from '@tiptap/react';
|
|
1
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
6
|
import { BaseMetadata, DM, ThreadData, HistoryVersion } from '@liveblocks/core';
|
|
3
7
|
import { ThreadProps, ComposerProps } from '@liveblocks/react-ui';
|
|
4
|
-
import { Editor } from '@tiptap/react';
|
|
5
|
-
import * as react from 'react';
|
|
6
|
-
import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ComponentProps, ReactNode } from 'react';
|
|
7
8
|
import { BaseMetadata as BaseMetadata$1 } from '@liveblocks/client';
|
|
8
|
-
import { Extension, Content } from '@tiptap/core';
|
|
9
9
|
|
|
10
|
+
type ResolveAiPromptArgs = {
|
|
11
|
+
prompt: string;
|
|
12
|
+
selectionText: string;
|
|
13
|
+
context: string;
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
};
|
|
16
|
+
interface AiConfiguration {
|
|
17
|
+
name?: string;
|
|
18
|
+
resolveAiPrompt?: (args: ResolveAiPromptArgs) => Promise<AiResponse>;
|
|
19
|
+
}
|
|
20
|
+
type LiveblocksExtensionOptions = {
|
|
21
|
+
field?: string;
|
|
22
|
+
comments?: boolean;
|
|
23
|
+
mentions?: boolean;
|
|
24
|
+
ai?: boolean | AiConfiguration;
|
|
25
|
+
offlineSupport_experimental?: boolean;
|
|
26
|
+
initialContent?: Content;
|
|
27
|
+
};
|
|
10
28
|
type FloatingPosition = "top" | "bottom";
|
|
11
|
-
type CommentsCommands<ReturnType> = {
|
|
29
|
+
type CommentsCommands<ReturnType = boolean> = {
|
|
12
30
|
/**
|
|
13
31
|
* Add a comment
|
|
14
32
|
*/
|
|
@@ -16,6 +34,31 @@ type CommentsCommands<ReturnType> = {
|
|
|
16
34
|
selectThread: (id: string | null) => ReturnType;
|
|
17
35
|
addPendingComment: () => ReturnType;
|
|
18
36
|
};
|
|
37
|
+
type AiCommands<ReturnType = boolean> = {
|
|
38
|
+
askAi: (prompt?: string) => ReturnType;
|
|
39
|
+
};
|
|
40
|
+
type AiResponse = {
|
|
41
|
+
content: string;
|
|
42
|
+
type: "insert" | "modification" | "other";
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
interface AiToolbarProps extends Omit<ComponentProps<"div">, "value" | "defaultValue"> {
|
|
46
|
+
editor: Editor | null;
|
|
47
|
+
position?: FloatingPosition;
|
|
48
|
+
offset?: number;
|
|
49
|
+
suggestions?: ReactNode | ComponentType<PropsWithChildren>;
|
|
50
|
+
}
|
|
51
|
+
interface AiToolbarDropdownGroupProps extends ComponentProps<"div"> {
|
|
52
|
+
label: string;
|
|
53
|
+
}
|
|
54
|
+
interface AiToolbarSuggestionProps extends ComponentProps<"div"> {
|
|
55
|
+
prompt?: string;
|
|
56
|
+
icon?: ReactNode;
|
|
57
|
+
}
|
|
58
|
+
declare const AiToolbar: react.ForwardRefExoticComponent<Omit<AiToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
|
|
59
|
+
SuggestionsGroup: react.ForwardRefExoticComponent<Omit<AiToolbarDropdownGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
60
|
+
Suggestion: react.ForwardRefExoticComponent<Omit<AiToolbarSuggestionProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
61
|
+
};
|
|
19
62
|
|
|
20
63
|
type AnchoredThreadsComponents = {
|
|
21
64
|
Thread: ComponentType<ThreadProps>;
|
|
@@ -62,13 +105,6 @@ interface FloatingThreadsProps<M extends BaseMetadata = DM> extends Omit<HTMLAtt
|
|
|
62
105
|
}
|
|
63
106
|
declare function FloatingThreads({ threads, components, editor, ...props }: FloatingThreadsProps): react_jsx_runtime.JSX.Element | null;
|
|
64
107
|
|
|
65
|
-
type LiveblocksExtensionOptions = {
|
|
66
|
-
field?: string;
|
|
67
|
-
comments?: boolean;
|
|
68
|
-
mentions?: boolean;
|
|
69
|
-
offlineSupport_experimental?: boolean;
|
|
70
|
-
initialContent?: Content;
|
|
71
|
-
};
|
|
72
108
|
/**
|
|
73
109
|
* Returns whether the editor has loaded the initial text contents from the
|
|
74
110
|
* server and is ready to be used.
|
|
@@ -188,6 +224,7 @@ type ToolbarSeparatorProps = ComponentProps<"div">;
|
|
|
188
224
|
declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
|
|
189
225
|
declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element;
|
|
190
226
|
declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
|
|
227
|
+
declare function ToolbarSectionAi(): react_jsx_runtime.JSX.Element;
|
|
191
228
|
/**
|
|
192
229
|
* A static toolbar containing actions and values related to the editor.
|
|
193
230
|
*
|
|
@@ -208,7 +245,7 @@ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref">
|
|
|
208
245
|
* A button for triggering actions.
|
|
209
246
|
*
|
|
210
247
|
* @example
|
|
211
|
-
* <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }}
|
|
248
|
+
* <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }} />
|
|
212
249
|
*
|
|
213
250
|
* @example
|
|
214
251
|
* <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
|
|
@@ -218,7 +255,7 @@ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref">
|
|
|
218
255
|
* A toggle button for values that can be active or inactive.
|
|
219
256
|
*
|
|
220
257
|
* @example
|
|
221
|
-
* <Toolbar.Toggle name="Bold" active={isBold}
|
|
258
|
+
* <Toolbar.Toggle name="Bold" active={isBold} />
|
|
222
259
|
*
|
|
223
260
|
* @example
|
|
224
261
|
* <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
|
|
@@ -247,6 +284,10 @@ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref">
|
|
|
247
284
|
* A section containing collaborative actions. (e.g. adding a comment)
|
|
248
285
|
*/
|
|
249
286
|
SectionCollaboration: typeof ToolbarSectionCollaboration;
|
|
287
|
+
/**
|
|
288
|
+
* A section containing AI actions. (e.g. opening the AI toolbar)
|
|
289
|
+
*/
|
|
290
|
+
SectionAi: typeof ToolbarSectionAi;
|
|
250
291
|
};
|
|
251
292
|
|
|
252
293
|
interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
|
|
@@ -330,8 +371,9 @@ declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVers
|
|
|
330
371
|
|
|
331
372
|
declare module "@tiptap/core" {
|
|
332
373
|
interface Commands<ReturnType> {
|
|
333
|
-
|
|
374
|
+
liveblocksComments: CommentsCommands<ReturnType>;
|
|
375
|
+
liveblocksAi: AiCommands<ReturnType>;
|
|
334
376
|
}
|
|
335
377
|
}
|
|
336
378
|
|
|
337
|
-
export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, useIsEditorReady, useLiveblocksExtension };
|
|
379
|
+
export { AiToolbar, AiToolbarProps, AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, useIsEditorReady, useLiveblocksExtension };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
+
import { Content, Extension } from '@tiptap/core';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ComponentProps, ReactNode, ComponentType, PropsWithChildren, ComponentPropsWithoutRef, HTMLAttributes } from 'react';
|
|
4
|
+
import { Editor } from '@tiptap/react';
|
|
1
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
6
|
import { BaseMetadata, DM, ThreadData, HistoryVersion } from '@liveblocks/core';
|
|
3
7
|
import { ThreadProps, ComposerProps } from '@liveblocks/react-ui';
|
|
4
|
-
import { Editor } from '@tiptap/react';
|
|
5
|
-
import * as react from 'react';
|
|
6
|
-
import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ComponentProps, ReactNode } from 'react';
|
|
7
8
|
import { BaseMetadata as BaseMetadata$1 } from '@liveblocks/client';
|
|
8
|
-
import { Extension, Content } from '@tiptap/core';
|
|
9
9
|
|
|
10
|
+
type ResolveAiPromptArgs = {
|
|
11
|
+
prompt: string;
|
|
12
|
+
selectionText: string;
|
|
13
|
+
context: string;
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
};
|
|
16
|
+
interface AiConfiguration {
|
|
17
|
+
name?: string;
|
|
18
|
+
resolveAiPrompt?: (args: ResolveAiPromptArgs) => Promise<AiResponse>;
|
|
19
|
+
}
|
|
20
|
+
type LiveblocksExtensionOptions = {
|
|
21
|
+
field?: string;
|
|
22
|
+
comments?: boolean;
|
|
23
|
+
mentions?: boolean;
|
|
24
|
+
ai?: boolean | AiConfiguration;
|
|
25
|
+
offlineSupport_experimental?: boolean;
|
|
26
|
+
initialContent?: Content;
|
|
27
|
+
};
|
|
10
28
|
type FloatingPosition = "top" | "bottom";
|
|
11
|
-
type CommentsCommands<ReturnType> = {
|
|
29
|
+
type CommentsCommands<ReturnType = boolean> = {
|
|
12
30
|
/**
|
|
13
31
|
* Add a comment
|
|
14
32
|
*/
|
|
@@ -16,6 +34,31 @@ type CommentsCommands<ReturnType> = {
|
|
|
16
34
|
selectThread: (id: string | null) => ReturnType;
|
|
17
35
|
addPendingComment: () => ReturnType;
|
|
18
36
|
};
|
|
37
|
+
type AiCommands<ReturnType = boolean> = {
|
|
38
|
+
askAi: (prompt?: string) => ReturnType;
|
|
39
|
+
};
|
|
40
|
+
type AiResponse = {
|
|
41
|
+
content: string;
|
|
42
|
+
type: "insert" | "modification" | "other";
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
interface AiToolbarProps extends Omit<ComponentProps<"div">, "value" | "defaultValue"> {
|
|
46
|
+
editor: Editor | null;
|
|
47
|
+
position?: FloatingPosition;
|
|
48
|
+
offset?: number;
|
|
49
|
+
suggestions?: ReactNode | ComponentType<PropsWithChildren>;
|
|
50
|
+
}
|
|
51
|
+
interface AiToolbarDropdownGroupProps extends ComponentProps<"div"> {
|
|
52
|
+
label: string;
|
|
53
|
+
}
|
|
54
|
+
interface AiToolbarSuggestionProps extends ComponentProps<"div"> {
|
|
55
|
+
prompt?: string;
|
|
56
|
+
icon?: ReactNode;
|
|
57
|
+
}
|
|
58
|
+
declare const AiToolbar: react.ForwardRefExoticComponent<Omit<AiToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
|
|
59
|
+
SuggestionsGroup: react.ForwardRefExoticComponent<Omit<AiToolbarDropdownGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
60
|
+
Suggestion: react.ForwardRefExoticComponent<Omit<AiToolbarSuggestionProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
61
|
+
};
|
|
19
62
|
|
|
20
63
|
type AnchoredThreadsComponents = {
|
|
21
64
|
Thread: ComponentType<ThreadProps>;
|
|
@@ -62,13 +105,6 @@ interface FloatingThreadsProps<M extends BaseMetadata = DM> extends Omit<HTMLAtt
|
|
|
62
105
|
}
|
|
63
106
|
declare function FloatingThreads({ threads, components, editor, ...props }: FloatingThreadsProps): react_jsx_runtime.JSX.Element | null;
|
|
64
107
|
|
|
65
|
-
type LiveblocksExtensionOptions = {
|
|
66
|
-
field?: string;
|
|
67
|
-
comments?: boolean;
|
|
68
|
-
mentions?: boolean;
|
|
69
|
-
offlineSupport_experimental?: boolean;
|
|
70
|
-
initialContent?: Content;
|
|
71
|
-
};
|
|
72
108
|
/**
|
|
73
109
|
* Returns whether the editor has loaded the initial text contents from the
|
|
74
110
|
* server and is ready to be used.
|
|
@@ -188,6 +224,7 @@ type ToolbarSeparatorProps = ComponentProps<"div">;
|
|
|
188
224
|
declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
|
|
189
225
|
declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element;
|
|
190
226
|
declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
|
|
227
|
+
declare function ToolbarSectionAi(): react_jsx_runtime.JSX.Element;
|
|
191
228
|
/**
|
|
192
229
|
* A static toolbar containing actions and values related to the editor.
|
|
193
230
|
*
|
|
@@ -208,7 +245,7 @@ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref">
|
|
|
208
245
|
* A button for triggering actions.
|
|
209
246
|
*
|
|
210
247
|
* @example
|
|
211
|
-
* <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }}
|
|
248
|
+
* <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }} />
|
|
212
249
|
*
|
|
213
250
|
* @example
|
|
214
251
|
* <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
|
|
@@ -218,7 +255,7 @@ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref">
|
|
|
218
255
|
* A toggle button for values that can be active or inactive.
|
|
219
256
|
*
|
|
220
257
|
* @example
|
|
221
|
-
* <Toolbar.Toggle name="Bold" active={isBold}
|
|
258
|
+
* <Toolbar.Toggle name="Bold" active={isBold} />
|
|
222
259
|
*
|
|
223
260
|
* @example
|
|
224
261
|
* <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
|
|
@@ -247,6 +284,10 @@ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref">
|
|
|
247
284
|
* A section containing collaborative actions. (e.g. adding a comment)
|
|
248
285
|
*/
|
|
249
286
|
SectionCollaboration: typeof ToolbarSectionCollaboration;
|
|
287
|
+
/**
|
|
288
|
+
* A section containing AI actions. (e.g. opening the AI toolbar)
|
|
289
|
+
*/
|
|
290
|
+
SectionAi: typeof ToolbarSectionAi;
|
|
250
291
|
};
|
|
251
292
|
|
|
252
293
|
interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
|
|
@@ -330,8 +371,9 @@ declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVers
|
|
|
330
371
|
|
|
331
372
|
declare module "@tiptap/core" {
|
|
332
373
|
interface Commands<ReturnType> {
|
|
333
|
-
|
|
374
|
+
liveblocksComments: CommentsCommands<ReturnType>;
|
|
375
|
+
liveblocksAi: AiCommands<ReturnType>;
|
|
334
376
|
}
|
|
335
377
|
}
|
|
336
378
|
|
|
337
|
-
export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, useIsEditorReady, useLiveblocksExtension };
|
|
379
|
+
export { AiToolbar, AiToolbarProps, AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, useIsEditorReady, useLiveblocksExtension };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@liveblocks/core');
|
|
4
4
|
var version = require('./version.js');
|
|
5
|
+
var AiToolbar = require('./ai/AiToolbar.js');
|
|
5
6
|
var AnchoredThreads = require('./comments/AnchoredThreads.js');
|
|
6
7
|
var FloatingComposer = require('./comments/FloatingComposer.js');
|
|
7
8
|
var FloatingThreads = require('./comments/FloatingThreads.js');
|
|
@@ -12,6 +13,7 @@ var HistoryVersionPreview = require('./version-history/HistoryVersionPreview.js'
|
|
|
12
13
|
|
|
13
14
|
core.detectDupes(version.PKG_NAME, version.PKG_VERSION, version.PKG_FORMAT);
|
|
14
15
|
|
|
16
|
+
exports.AiToolbar = AiToolbar.AiToolbar;
|
|
15
17
|
exports.AnchoredThreads = AnchoredThreads.AnchoredThreads;
|
|
16
18
|
exports.FloatingComposer = FloatingComposer.FloatingComposer;
|
|
17
19
|
exports.FloatingThreads = FloatingThreads.FloatingThreads;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport type { CommentsCommands } from \"./types\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { AnchoredThreadsProps } from \"./comments/AnchoredThreads\";\nexport { AnchoredThreads } from \"./comments/AnchoredThreads\";\nexport type { FloatingComposerProps } from \"./comments/FloatingComposer\";\nexport { FloatingComposer } from \"./comments/FloatingComposer\";\nexport type { FloatingThreadsProps } from \"./comments/FloatingThreads\";\nexport { FloatingThreads } from \"./comments/FloatingThreads\";\nexport { useLiveblocksExtension } from \"./LiveblocksExtension\";\nexport { useIsEditorReady } from \"./LiveblocksExtension\";\nexport type { FloatingToolbarProps } from \"./toolbar/FloatingToolbar\";\nexport { FloatingToolbar } from \"./toolbar/FloatingToolbar\";\nexport type {\n ToolbarBlockSelectorItem,\n ToolbarBlockSelectorProps,\n ToolbarButtonProps,\n ToolbarProps,\n ToolbarSeparatorProps,\n ToolbarToggleProps,\n} from \"./toolbar/Toolbar\";\nexport { Toolbar } from \"./toolbar/Toolbar\";\nexport type { HistoryVersionPreviewProps } from \"./version-history/HistoryVersionPreview\";\nexport { HistoryVersionPreview } from \"./version-history/HistoryVersionPreview\";\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport type { AiCommands, CommentsCommands } from \"./types\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { AiToolbarProps } from \"./ai/AiToolbar\";\nexport { AiToolbar } from \"./ai/AiToolbar\";\nexport type { AnchoredThreadsProps } from \"./comments/AnchoredThreads\";\nexport { AnchoredThreads } from \"./comments/AnchoredThreads\";\nexport type { FloatingComposerProps } from \"./comments/FloatingComposer\";\nexport { FloatingComposer } from \"./comments/FloatingComposer\";\nexport type { FloatingThreadsProps } from \"./comments/FloatingThreads\";\nexport { FloatingThreads } from \"./comments/FloatingThreads\";\nexport { useLiveblocksExtension } from \"./LiveblocksExtension\";\nexport { useIsEditorReady } from \"./LiveblocksExtension\";\nexport type { FloatingToolbarProps } from \"./toolbar/FloatingToolbar\";\nexport { FloatingToolbar } from \"./toolbar/FloatingToolbar\";\nexport type {\n ToolbarBlockSelectorItem,\n ToolbarBlockSelectorProps,\n ToolbarButtonProps,\n ToolbarProps,\n ToolbarSeparatorProps,\n ToolbarToggleProps,\n} from \"./toolbar/Toolbar\";\nexport { Toolbar } from \"./toolbar/Toolbar\";\nexport type { HistoryVersionPreviewProps } from \"./version-history/HistoryVersionPreview\";\nexport { HistoryVersionPreview } from \"./version-history/HistoryVersionPreview\";\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n liveblocksComments: CommentsCommands<ReturnType>;\n liveblocksAi: AiCommands<ReturnType>;\n }\n}\n"],"names":["detectDupes","PKG_NAME","PKG_VERSION","PKG_FORMAT"],"mappings":";;;;;;;;;;;;;AAKAA,gBAAY,CAAAC,gBAAA,EAAUC,qBAAaC,kBAAU,CAAA;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { detectDupes } from '@liveblocks/core';
|
|
2
2
|
import { PKG_NAME, PKG_VERSION, PKG_FORMAT } from './version.mjs';
|
|
3
|
+
export { AiToolbar } from './ai/AiToolbar.mjs';
|
|
3
4
|
export { AnchoredThreads } from './comments/AnchoredThreads.mjs';
|
|
4
5
|
export { FloatingComposer } from './comments/FloatingComposer.mjs';
|
|
5
6
|
export { FloatingThreads } from './comments/FloatingThreads.mjs';
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport type { CommentsCommands } from \"./types\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { AnchoredThreadsProps } from \"./comments/AnchoredThreads\";\nexport { AnchoredThreads } from \"./comments/AnchoredThreads\";\nexport type { FloatingComposerProps } from \"./comments/FloatingComposer\";\nexport { FloatingComposer } from \"./comments/FloatingComposer\";\nexport type { FloatingThreadsProps } from \"./comments/FloatingThreads\";\nexport { FloatingThreads } from \"./comments/FloatingThreads\";\nexport { useLiveblocksExtension } from \"./LiveblocksExtension\";\nexport { useIsEditorReady } from \"./LiveblocksExtension\";\nexport type { FloatingToolbarProps } from \"./toolbar/FloatingToolbar\";\nexport { FloatingToolbar } from \"./toolbar/FloatingToolbar\";\nexport type {\n ToolbarBlockSelectorItem,\n ToolbarBlockSelectorProps,\n ToolbarButtonProps,\n ToolbarProps,\n ToolbarSeparatorProps,\n ToolbarToggleProps,\n} from \"./toolbar/Toolbar\";\nexport { Toolbar } from \"./toolbar/Toolbar\";\nexport type { HistoryVersionPreviewProps } from \"./version-history/HistoryVersionPreview\";\nexport { HistoryVersionPreview } from \"./version-history/HistoryVersionPreview\";\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport type { AiCommands, CommentsCommands } from \"./types\";\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { AiToolbarProps } from \"./ai/AiToolbar\";\nexport { AiToolbar } from \"./ai/AiToolbar\";\nexport type { AnchoredThreadsProps } from \"./comments/AnchoredThreads\";\nexport { AnchoredThreads } from \"./comments/AnchoredThreads\";\nexport type { FloatingComposerProps } from \"./comments/FloatingComposer\";\nexport { FloatingComposer } from \"./comments/FloatingComposer\";\nexport type { FloatingThreadsProps } from \"./comments/FloatingThreads\";\nexport { FloatingThreads } from \"./comments/FloatingThreads\";\nexport { useLiveblocksExtension } from \"./LiveblocksExtension\";\nexport { useIsEditorReady } from \"./LiveblocksExtension\";\nexport type { FloatingToolbarProps } from \"./toolbar/FloatingToolbar\";\nexport { FloatingToolbar } from \"./toolbar/FloatingToolbar\";\nexport type {\n ToolbarBlockSelectorItem,\n ToolbarBlockSelectorProps,\n ToolbarButtonProps,\n ToolbarProps,\n ToolbarSeparatorProps,\n ToolbarToggleProps,\n} from \"./toolbar/Toolbar\";\nexport { Toolbar } from \"./toolbar/Toolbar\";\nexport type { HistoryVersionPreviewProps } from \"./version-history/HistoryVersionPreview\";\nexport { HistoryVersionPreview } from \"./version-history/HistoryVersionPreview\";\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n liveblocksComments: CommentsCommands<ReturnType>;\n liveblocksAi: AiCommands<ReturnType>;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAKA,WAAY,CAAA,QAAA,EAAU,aAAa,UAAU,CAAA"}
|
|
@@ -16,8 +16,15 @@ const FLOATING_TOOLBAR_COLLISION_PADDING = 10;
|
|
|
16
16
|
const FLOATING_TOOLBAR_OPEN_DELAY = 50;
|
|
17
17
|
function DefaultFloatingToolbarContent({ editor }) {
|
|
18
18
|
const supportsThread = "addPendingComment" in editor.commands;
|
|
19
|
+
const supportsAi = "askAi" in editor.commands;
|
|
19
20
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
20
21
|
children: [
|
|
22
|
+
supportsAi ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.SectionAi, {}),
|
|
25
|
+
/* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.Separator, {})
|
|
26
|
+
]
|
|
27
|
+
}) : null,
|
|
21
28
|
/* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.BlockSelector, {}),
|
|
22
29
|
/* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.SectionInline, {}),
|
|
23
30
|
supportsThread ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|