@liveblocks/react-tiptap 2.17.0-channels1 → 2.17.0-usrnotsettings1

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 (56) hide show
  1. package/dist/LiveblocksExtension.js +0 -4
  2. package/dist/LiveblocksExtension.js.map +1 -1
  3. package/dist/LiveblocksExtension.mjs +2 -6
  4. package/dist/LiveblocksExtension.mjs.map +1 -1
  5. package/dist/comments/CommentsExtension.js +6 -2
  6. package/dist/comments/CommentsExtension.js.map +1 -1
  7. package/dist/comments/CommentsExtension.mjs +7 -3
  8. package/dist/comments/CommentsExtension.mjs.map +1 -1
  9. package/dist/comments/FloatingComposer.js +29 -30
  10. package/dist/comments/FloatingComposer.js.map +1 -1
  11. package/dist/comments/FloatingComposer.mjs +31 -32
  12. package/dist/comments/FloatingComposer.mjs.map +1 -1
  13. package/dist/context.js +24 -0
  14. package/dist/context.js.map +1 -0
  15. package/dist/context.mjs +21 -0
  16. package/dist/context.mjs.map +1 -0
  17. package/dist/index.d.mts +254 -10
  18. package/dist/index.d.ts +254 -10
  19. package/dist/index.js +4 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +2 -0
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/toolbar/FloatingToolbar.js +321 -0
  24. package/dist/toolbar/FloatingToolbar.js.map +1 -0
  25. package/dist/toolbar/FloatingToolbar.mjs +318 -0
  26. package/dist/toolbar/FloatingToolbar.mjs.map +1 -0
  27. package/dist/toolbar/Toolbar.js +397 -0
  28. package/dist/toolbar/Toolbar.js.map +1 -0
  29. package/dist/toolbar/Toolbar.mjs +372 -0
  30. package/dist/toolbar/Toolbar.mjs.map +1 -0
  31. package/dist/toolbar/shared.js +36 -0
  32. package/dist/toolbar/shared.js.map +1 -0
  33. package/dist/toolbar/shared.mjs +33 -0
  34. package/dist/toolbar/shared.mjs.map +1 -0
  35. package/dist/types.js +7 -3
  36. package/dist/types.js.map +1 -1
  37. package/dist/types.mjs +6 -3
  38. package/dist/types.mjs.map +1 -1
  39. package/dist/utils.js +17 -0
  40. package/dist/utils.js.map +1 -1
  41. package/dist/utils.mjs +16 -1
  42. package/dist/utils.mjs.map +1 -1
  43. package/dist/version-history/HistoryVersionPreview.js +79 -79
  44. package/dist/version-history/HistoryVersionPreview.js.map +1 -1
  45. package/dist/version-history/HistoryVersionPreview.mjs +79 -79
  46. package/dist/version-history/HistoryVersionPreview.mjs.map +1 -1
  47. package/dist/version.js +1 -1
  48. package/dist/version.js.map +1 -1
  49. package/dist/version.mjs +1 -1
  50. package/dist/version.mjs.map +1 -1
  51. package/package.json +8 -6
  52. package/src/styles/constants.css +2 -1
  53. package/src/styles/index.css +58 -6
  54. package/src/styles/utils.css +11 -0
  55. package/styles.css +1 -1
  56. package/styles.css.map +1 -1
package/dist/index.d.ts CHANGED
@@ -3,10 +3,20 @@ import { BaseMetadata, DM, ThreadData, HistoryVersion } from '@liveblocks/core';
3
3
  import { ThreadProps, ComposerProps } from '@liveblocks/react-ui';
4
4
  import { Editor } from '@tiptap/react';
5
5
  import * as react from 'react';
6
- import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes } from 'react';
6
+ import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ComponentProps, ReactNode } from 'react';
7
7
  import { BaseMetadata as BaseMetadata$1 } from '@liveblocks/client';
8
8
  import { Extension, Content } from '@tiptap/core';
9
9
 
10
+ type FloatingPosition = "top" | "bottom";
11
+ type CommentsCommands<ReturnType> = {
12
+ /**
13
+ * Add a comment
14
+ */
15
+ addComment: (id: string) => ReturnType;
16
+ selectThread: (id: string | null) => ReturnType;
17
+ addPendingComment: () => ReturnType;
18
+ };
19
+
10
20
  type AnchoredThreadsComponents = {
11
21
  Thread: ComponentType<ThreadProps>;
12
22
  };
@@ -26,6 +36,9 @@ interface AnchoredThreadsProps<M extends BaseMetadata = DM> extends Omit<Compone
26
36
  }
27
37
  declare function AnchoredThreads({ threads, components, className, style, editor, ...props }: AnchoredThreadsProps): react_jsx_runtime.JSX.Element | null;
28
38
 
39
+ type FloatingComposerProps<M extends BaseMetadata$1 = DM> = Omit<ComposerProps<M>, "threadId" | "commentId"> & {
40
+ editor: Editor | null;
41
+ };
29
42
  declare const FloatingComposer: react.ForwardRefExoticComponent<Omit<ComposerProps<BaseMetadata$1>, "threadId" | "commentId"> & {
30
43
  editor: Editor | null;
31
44
  } & react.RefAttributes<HTMLFormElement>>;
@@ -64,6 +77,244 @@ type LiveblocksExtensionOptions = {
64
77
  declare function useIsEditorReady(): boolean;
65
78
  declare const useLiveblocksExtension: (opts?: LiveblocksExtensionOptions) => Extension;
66
79
 
80
+ interface ToolbarSlotProps {
81
+ editor: Editor;
82
+ }
83
+ type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;
84
+ interface ToolbarProps extends Omit<ComponentProps<"div">, "children"> {
85
+ /**
86
+ * The Tiptap editor.
87
+ */
88
+ editor: Editor | null;
89
+ /**
90
+ * The content of the toolbar, overriding the default content.
91
+ * Use the `before` and `after` props if you want to keep and extend the default content.
92
+ */
93
+ children?: ToolbarSlot;
94
+ /**
95
+ * The content to display at the start of the toolbar.
96
+ */
97
+ before?: ToolbarSlot;
98
+ /**
99
+ * The content to display at the end of the toolbar.
100
+ */
101
+ after?: ToolbarSlot;
102
+ }
103
+ interface ToolbarButtonProps extends ComponentProps<"button"> {
104
+ /**
105
+ * The name of this button displayed in its tooltip.
106
+ */
107
+ name: string;
108
+ /**
109
+ * An optional icon displayed in this button.
110
+ */
111
+ icon?: ReactNode;
112
+ /**
113
+ * An optional keyboard shortcut displayed in this button's tooltip.
114
+ *
115
+ * @example
116
+ * "Mod-Alt-B" → "⌘⌥B" in Apple environments, "⌃⌥B" otherwise
117
+ * "Ctrl-Shift-Escape" → "⌃⇧⎋"
118
+ * "Space" → "␣"
119
+ */
120
+ shortcut?: string;
121
+ }
122
+ interface ToolbarToggleProps extends ToolbarButtonProps {
123
+ /**
124
+ * Whether the button is toggled.
125
+ */
126
+ active: boolean;
127
+ }
128
+ interface ToolbarBlockSelectorItem {
129
+ /**
130
+ * The name of this block element, displayed as the label of this item.
131
+ */
132
+ name: string;
133
+ /**
134
+ * Optionally replace the name used as the label of this item by any content.
135
+ */
136
+ label?: ReactNode;
137
+ /**
138
+ * An optional icon displayed in this item.
139
+ */
140
+ icon?: ReactNode;
141
+ /**
142
+ * Whether this block element is currently active.
143
+ * Set to `"default"` to display this item when no other item is active.
144
+ */
145
+ isActive: ((editor: Editor) => boolean) | "default";
146
+ /**
147
+ * A callback invoked when this item is selected.
148
+ */
149
+ setActive: (editor: Editor) => void;
150
+ }
151
+ interface ToolbarBlockSelectorProps extends ComponentProps<"button"> {
152
+ /**
153
+ * The items displayed in this block selector.
154
+ * When provided as an array, the default items are overridden. To avoid this,
155
+ * a function can be provided instead and it will receive the default items.
156
+ *
157
+ * @example
158
+ * <Toolbar.BlockSelector
159
+ * items={[
160
+ * {
161
+ * name: "Text",
162
+ * isActive: "default",
163
+ * setActive: () => { ... },
164
+ * },
165
+ * {
166
+ * name: "Heading 1",
167
+ * isActive: () => { ... },
168
+ * setActive: () => { ... },
169
+ * },
170
+ * ]}
171
+ * />
172
+ *
173
+ * @example
174
+ * <Toolbar.BlockSelector
175
+ * items={(defaultItems) => [
176
+ * ...defaultItems,
177
+ * {
178
+ * name: "Custom block",
179
+ * isActive: () => { ... },
180
+ * setActive: () => { ... },
181
+ * },
182
+ * ]}
183
+ * />
184
+ */
185
+ items?: ToolbarBlockSelectorItem[] | ((defaultItems: ToolbarBlockSelectorItem[]) => ToolbarBlockSelectorItem[]);
186
+ }
187
+ type ToolbarSeparatorProps = ComponentProps<"div">;
188
+ declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
189
+ declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element;
190
+ declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
191
+ /**
192
+ * A static toolbar containing actions and values related to the editor.
193
+ *
194
+ * @example
195
+ * <Toolbar editor={editor} />
196
+ *
197
+ * @example
198
+ * <Toolbar editor={editor}>
199
+ * <Toolbar.BlockSelector />
200
+ * <Toolbar.Separator />
201
+ * <Toolbar.SectionInline />
202
+ * <Toolbar.Separator />
203
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
204
+ * </Toolbar>
205
+ */
206
+ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
207
+ /**
208
+ * A button for triggering actions.
209
+ *
210
+ * @example
211
+ * <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }} />
212
+ *
213
+ * @example
214
+ * <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
215
+ */
216
+ Button: react.ForwardRefExoticComponent<Omit<ToolbarButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
217
+ /**
218
+ * A toggle button for values that can be active or inactive.
219
+ *
220
+ * @example
221
+ * <Toolbar.Toggle name="Bold" active={isBold} />
222
+ *
223
+ * @example
224
+ * <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
225
+ */
226
+ Toggle: react.ForwardRefExoticComponent<Omit<ToolbarToggleProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
227
+ /**
228
+ * A dropdown selector to switch between different block types.
229
+ *
230
+ * @example
231
+ * <Toolbar.BlockSelector />
232
+ */
233
+ BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
234
+ /**
235
+ * A visual (and accessible) separator to separate sections in a toolbar.
236
+ */
237
+ Separator: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
238
+ /**
239
+ * A section containing history actions. (e.g. undo, redo)
240
+ */
241
+ SectionHistory: typeof ToolbarSectionHistory;
242
+ /**
243
+ * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)
244
+ */
245
+ SectionInline: typeof ToolbarSectionInline;
246
+ /**
247
+ * A section containing collaborative actions. (e.g. adding a comment)
248
+ */
249
+ SectionCollaboration: typeof ToolbarSectionCollaboration;
250
+ };
251
+
252
+ interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
253
+ /**
254
+ * The Tiptap editor.
255
+ */
256
+ editor: Editor | null;
257
+ /**
258
+ * The vertical position of the floating toolbar.
259
+ */
260
+ position?: FloatingPosition;
261
+ /**
262
+ * The vertical offset of the floating toolbar from the selection.
263
+ */
264
+ offset?: number;
265
+ /**
266
+ * The content of the floating toolbar, overriding the default content.
267
+ * Use the `before` and `after` props if you want to keep and extend the default content.
268
+ */
269
+ children?: ToolbarSlot;
270
+ /**
271
+ * The content to display at the start of the floating toolbar.
272
+ */
273
+ before?: ToolbarSlot;
274
+ /**
275
+ * The content to display at the end of the floating toolbar.
276
+ */
277
+ after?: ToolbarSlot;
278
+ }
279
+ /**
280
+ * A floating toolbar attached to the selection and containing actions and values related to the editor.
281
+ *
282
+ * @example
283
+ * <FloatingToolbar editor={editor} />
284
+ *
285
+ * @example
286
+ * <FloatingToolbar editor={editor}>
287
+ * <Toolbar.BlockSelector />
288
+ * <Toolbar.Separator />
289
+ * <Toolbar.SectionInline />
290
+ * <Toolbar.Separator />
291
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
292
+ * </FloatingToolbar>
293
+ */
294
+ declare const FloatingToolbar: react.ForwardRefExoticComponent<Omit<FloatingToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
295
+ /**
296
+ * A component that can be wrapped around elements which are rendered outside of the floating
297
+ * toolbar (e.g. portals) to prevent the toolbar from closing when clicking/focusing within them.
298
+ *
299
+ * @example
300
+ * <FloatingToolbar editor={editor}>
301
+ * <Popover.Root>
302
+ * <Popover.Trigger asChild>
303
+ * <Toolbar.Button>Open popover</Toolbar.Button>
304
+ * </Popover.Trigger>
305
+ * <Popover.Portal>
306
+ * <FloatingToolbar.External>
307
+ * <Popover.Content>
308
+ * This popover is rendered outside of the floating toolbar, but the toolbar will not close when clicking/focusing within it.
309
+ * </Popover.Content>
310
+ * </FloatingToolbar.External>
311
+ * </Popover.Portal>
312
+ * </Popover.Root>
313
+ * </FloatingToolbar>
314
+ */
315
+ External: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
316
+ };
317
+
67
318
  interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
68
319
  version: HistoryVersion;
69
320
  editor: Editor;
@@ -79,15 +330,8 @@ declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVers
79
330
 
80
331
  declare module "@tiptap/core" {
81
332
  interface Commands<ReturnType> {
82
- comments: {
83
- /**
84
- * Add a comment
85
- */
86
- addComment: (id: string) => ReturnType;
87
- selectThread: (id: string | null) => ReturnType;
88
- addPendingComment: () => ReturnType;
89
- };
333
+ comments: CommentsCommands<ReturnType>;
90
334
  }
91
335
  }
92
336
 
93
- export { AnchoredThreads, FloatingComposer, FloatingThreads, HistoryVersionPreview, useIsEditorReady, useLiveblocksExtension };
337
+ export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, useIsEditorReady, useLiveblocksExtension };
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ var AnchoredThreads = require('./comments/AnchoredThreads.js');
6
6
  var FloatingComposer = require('./comments/FloatingComposer.js');
7
7
  var FloatingThreads = require('./comments/FloatingThreads.js');
8
8
  var LiveblocksExtension = require('./LiveblocksExtension.js');
9
+ var FloatingToolbar = require('./toolbar/FloatingToolbar.js');
10
+ var Toolbar = require('./toolbar/Toolbar.js');
9
11
  var HistoryVersionPreview = require('./version-history/HistoryVersionPreview.js');
10
12
 
11
13
  core.detectDupes(version.PKG_NAME, version.PKG_VERSION, version.PKG_FORMAT);
@@ -15,5 +17,7 @@ exports.FloatingComposer = FloatingComposer.FloatingComposer;
15
17
  exports.FloatingThreads = FloatingThreads.FloatingThreads;
16
18
  exports.useIsEditorReady = LiveblocksExtension.useIsEditorReady;
17
19
  exports.useLiveblocksExtension = LiveblocksExtension.useLiveblocksExtension;
20
+ exports.FloatingToolbar = FloatingToolbar.FloatingToolbar;
21
+ exports.Toolbar = Toolbar.Toolbar;
18
22
  exports.HistoryVersionPreview = HistoryVersionPreview.HistoryVersionPreview;
19
23
  //# sourceMappingURL=index.js.map
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 { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport { AnchoredThreads } from \"./comments/AnchoredThreads\";\nexport { FloatingComposer } from \"./comments/FloatingComposer\";\nexport { FloatingThreads } from \"./comments/FloatingThreads\";\nexport { useLiveblocksExtension } from \"./LiveblocksExtension\";\nexport { useIsEditorReady } from \"./LiveblocksExtension\";\nexport { HistoryVersionPreview } from \"./version-history/HistoryVersionPreview\";\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n comments: {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n };\n }\n}\n"],"names":["detectDupes","PKG_NAME","PKG_VERSION","PKG_FORMAT"],"mappings":";;;;;;;;;;AAIAA,gBAAY,CAAAC,gBAAA,EAAUC,qBAAaC,kBAAU,CAAA;;;;;;;;;"}
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 comments: CommentsCommands<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
@@ -4,6 +4,8 @@ export { AnchoredThreads } from './comments/AnchoredThreads.mjs';
4
4
  export { FloatingComposer } from './comments/FloatingComposer.mjs';
5
5
  export { FloatingThreads } from './comments/FloatingThreads.mjs';
6
6
  export { useIsEditorReady, useLiveblocksExtension } from './LiveblocksExtension.mjs';
7
+ export { FloatingToolbar } from './toolbar/FloatingToolbar.mjs';
8
+ export { Toolbar } from './toolbar/Toolbar.mjs';
7
9
  export { HistoryVersionPreview } from './version-history/HistoryVersionPreview.mjs';
8
10
 
9
11
  detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport { AnchoredThreads } from \"./comments/AnchoredThreads\";\nexport { FloatingComposer } from \"./comments/FloatingComposer\";\nexport { FloatingThreads } from \"./comments/FloatingThreads\";\nexport { useLiveblocksExtension } from \"./LiveblocksExtension\";\nexport { useIsEditorReady } from \"./LiveblocksExtension\";\nexport { HistoryVersionPreview } from \"./version-history/HistoryVersionPreview\";\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n comments: {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAIA,WAAY,CAAA,QAAA,EAAU,aAAa,UAAU,CAAA"}
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 comments: CommentsCommands<ReturnType>;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAKA,WAAY,CAAA,QAAA,EAAU,aAAa,UAAU,CAAA"}
@@ -0,0 +1,321 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var reactDom = require('@floating-ui/react-dom');
5
+ var _private$1 = require('@liveblocks/react/_private');
6
+ var _private = require('@liveblocks/react-ui/_private');
7
+ var react$1 = require('@tiptap/react');
8
+ var react = require('react');
9
+ var reactDom$1 = require('react-dom');
10
+ var classnames = require('../classnames.js');
11
+ var context = require('../context.js');
12
+ var shared = require('./shared.js');
13
+ var Toolbar = require('./Toolbar.js');
14
+
15
+ const FLOATING_TOOLBAR_COLLISION_PADDING = 10;
16
+ const FLOATING_TOOLBAR_OPEN_DELAY = 50;
17
+ function DefaultFloatingToolbarContent({ editor }) {
18
+ const supportsThread = "addPendingComment" in editor.commands;
19
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
20
+ children: [
21
+ /* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.BlockSelector, {}),
22
+ /* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.SectionInline, {}),
23
+ supportsThread ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
24
+ children: [
25
+ /* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.Separator, {}),
26
+ /* @__PURE__ */ jsxRuntime.jsx(Toolbar.Toolbar.SectionCollaboration, {})
27
+ ]
28
+ }) : null
29
+ ]
30
+ });
31
+ }
32
+ const FloatingToolbar = Object.assign(
33
+ react.forwardRef(
34
+ ({
35
+ children = DefaultFloatingToolbarContent,
36
+ before,
37
+ after,
38
+ position = "top",
39
+ offset: sideOffset = 6,
40
+ editor,
41
+ onPointerDown,
42
+ onFocus,
43
+ onBlur,
44
+ className,
45
+ ...props
46
+ }, forwardedRef) => {
47
+ const toolbarRef = react.useRef(null);
48
+ const externalIds = _private.useInitial(() => /* @__PURE__ */ new Set());
49
+ const [isPointerDown, setPointerDown] = react.useState(false);
50
+ const [isFocused, setFocused] = react.useState(false);
51
+ const [isManuallyClosed, setManuallyClosed] = react.useState(false);
52
+ const hasSelectionRange = react$1.useEditorState({
53
+ editor,
54
+ equalityFn: Object.is,
55
+ selector: (ctx) => {
56
+ const editor2 = ctx.editor;
57
+ if (!editor2) {
58
+ return false;
59
+ }
60
+ const { doc, selection } = editor2.state;
61
+ const { empty, ranges } = selection;
62
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
63
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
64
+ if (empty) {
65
+ return false;
66
+ }
67
+ return react$1.isTextSelection(selection) && doc.textBetween(from, to).length > 0;
68
+ }
69
+ }) ?? false;
70
+ const isOpen = isFocused && !isPointerDown && hasSelectionRange && !isManuallyClosed;
71
+ const [delayedIsOpen, setDelayedIsOpen] = react.useState(isOpen);
72
+ const delayedIsOpenTimeoutRef = react.useRef();
73
+ react.useEffect(() => {
74
+ if (!editor) {
75
+ return;
76
+ }
77
+ setManuallyClosed(false);
78
+ const handleSelectionChange = () => {
79
+ setManuallyClosed(false);
80
+ };
81
+ editor.on("selectionUpdate", handleSelectionChange);
82
+ return () => {
83
+ editor.off("selectionUpdate", handleSelectionChange);
84
+ };
85
+ }, [isFocused, hasSelectionRange, editor]);
86
+ react.useEffect(() => {
87
+ if (!editor) {
88
+ return;
89
+ }
90
+ const handleFocus2 = () => {
91
+ setFocused(true);
92
+ };
93
+ const handleBlur2 = (event) => {
94
+ if (event.relatedTarget && toolbarRef.current?.contains(event.relatedTarget)) {
95
+ return;
96
+ }
97
+ if (event.relatedTarget === editor.view.dom) {
98
+ return;
99
+ }
100
+ for (const externalId of externalIds) {
101
+ if (document.getElementById(externalId)?.contains(event.relatedTarget)) {
102
+ return;
103
+ }
104
+ }
105
+ setFocused(false);
106
+ };
107
+ editor.view.dom.addEventListener("focus", handleFocus2);
108
+ editor.view.dom.addEventListener("blur", handleBlur2);
109
+ return () => {
110
+ editor.view.dom.removeEventListener("focus", handleFocus2);
111
+ editor.view.dom.removeEventListener("blur", handleBlur2);
112
+ };
113
+ }, [editor, externalIds]);
114
+ const handleFocus = react.useCallback(
115
+ (event) => {
116
+ onFocus?.(event);
117
+ if (!event.isDefaultPrevented()) {
118
+ setFocused(true);
119
+ }
120
+ },
121
+ [onFocus]
122
+ );
123
+ const handleBlur = react.useCallback(
124
+ (event) => {
125
+ onBlur?.(event);
126
+ if (!event.isDefaultPrevented()) {
127
+ if (event.relatedTarget && toolbarRef.current?.contains(event.relatedTarget)) {
128
+ return;
129
+ }
130
+ if (event.relatedTarget === editor?.view.dom) {
131
+ return;
132
+ }
133
+ for (const externalId of externalIds) {
134
+ if (document.getElementById(externalId)?.contains(event.relatedTarget)) {
135
+ return;
136
+ }
137
+ }
138
+ setFocused(false);
139
+ }
140
+ },
141
+ [onBlur, editor, externalIds]
142
+ );
143
+ react.useEffect(() => {
144
+ if (isOpen) {
145
+ delayedIsOpenTimeoutRef.current = window.setTimeout(() => {
146
+ setDelayedIsOpen(true);
147
+ }, FLOATING_TOOLBAR_OPEN_DELAY);
148
+ } else {
149
+ setDelayedIsOpen(false);
150
+ }
151
+ return () => {
152
+ window.clearTimeout(delayedIsOpenTimeoutRef.current);
153
+ };
154
+ }, [isOpen]);
155
+ const floatingOptions = react.useMemo(() => {
156
+ const detectOverflowOptions = {
157
+ padding: FLOATING_TOOLBAR_COLLISION_PADDING
158
+ };
159
+ return {
160
+ strategy: "fixed",
161
+ placement: position,
162
+ middleware: [
163
+ reactDom.inline(detectOverflowOptions),
164
+ reactDom.flip({ ...detectOverflowOptions, crossAxis: false }),
165
+ reactDom.hide(detectOverflowOptions),
166
+ reactDom.shift({
167
+ ...detectOverflowOptions,
168
+ limiter: reactDom.limitShift()
169
+ }),
170
+ reactDom.offset(sideOffset),
171
+ reactDom.size(detectOverflowOptions)
172
+ ],
173
+ whileElementsMounted: (...args) => {
174
+ return reactDom.autoUpdate(...args, {
175
+ animationFrame: true
176
+ });
177
+ }
178
+ };
179
+ }, [position, sideOffset]);
180
+ const {
181
+ refs: { setReference, setFloating },
182
+ strategy,
183
+ x,
184
+ y,
185
+ isPositioned
186
+ } = reactDom.useFloating({
187
+ ...floatingOptions,
188
+ open: delayedIsOpen
189
+ });
190
+ const mergedRefs = _private.useRefs(forwardedRef, toolbarRef, setFloating);
191
+ const handlePointerDown = react.useCallback(
192
+ (event) => {
193
+ onPointerDown?.(event);
194
+ event.stopPropagation();
195
+ if (event.target === toolbarRef.current) {
196
+ event.preventDefault();
197
+ }
198
+ },
199
+ [onPointerDown]
200
+ );
201
+ react.useEffect(() => {
202
+ if (!editor) {
203
+ return;
204
+ }
205
+ const handlePointerDown2 = () => {
206
+ setPointerDown(true);
207
+ };
208
+ const handlePointerUp = () => {
209
+ setPointerDown(false);
210
+ };
211
+ editor.view.dom.addEventListener("pointerdown", handlePointerDown2);
212
+ document.addEventListener("pointercancel", handlePointerUp);
213
+ document.addEventListener("pointerup", handlePointerUp);
214
+ return () => {
215
+ editor.view.dom.removeEventListener("pointerdown", handlePointerDown2);
216
+ document.removeEventListener("pointercancel", handlePointerUp);
217
+ document.removeEventListener("pointerup", handlePointerUp);
218
+ };
219
+ }, [editor]);
220
+ _private$1.useLayoutEffect(() => {
221
+ if (!editor || !delayedIsOpen) {
222
+ return;
223
+ }
224
+ const updateSelectionReference = () => {
225
+ const domSelection = window.getSelection();
226
+ if (editor.state.selection.empty || !domSelection || !domSelection.rangeCount) {
227
+ setReference(null);
228
+ } else {
229
+ const domRange = domSelection.getRangeAt(0);
230
+ setReference(domRange);
231
+ }
232
+ };
233
+ editor.on("transaction", updateSelectionReference);
234
+ updateSelectionReference();
235
+ return () => {
236
+ editor.off("transaction", updateSelectionReference);
237
+ };
238
+ }, [editor, delayedIsOpen, setReference]);
239
+ react.useEffect(() => {
240
+ if (!editor || !delayedIsOpen) {
241
+ return;
242
+ }
243
+ const handleKeyDown = (event) => {
244
+ if (event.target !== editor.view.dom && event.defaultPrevented) {
245
+ return;
246
+ }
247
+ if (event.key === "Escape") {
248
+ event.preventDefault();
249
+ event.stopPropagation();
250
+ editor.commands.focus();
251
+ setManuallyClosed(true);
252
+ }
253
+ };
254
+ editor.view.dom.addEventListener("keydown", handleKeyDown);
255
+ return () => {
256
+ editor.view.dom.removeEventListener("keydown", handleKeyDown);
257
+ };
258
+ }, [editor, delayedIsOpen]);
259
+ const close = react.useCallback(() => {
260
+ setManuallyClosed(true);
261
+ }, [setManuallyClosed]);
262
+ const registerExternal = react.useCallback(
263
+ (id) => {
264
+ externalIds.add(id);
265
+ return () => {
266
+ externalIds.delete(id);
267
+ };
268
+ },
269
+ [externalIds]
270
+ );
271
+ if (!editor || !delayedIsOpen) {
272
+ return null;
273
+ }
274
+ const slotProps = { editor };
275
+ return reactDom$1.createPortal(
276
+ /* @__PURE__ */ jsxRuntime.jsx(_private.TooltipProvider, {
277
+ children: /* @__PURE__ */ jsxRuntime.jsx(context.EditorProvider, {
278
+ editor,
279
+ children: /* @__PURE__ */ jsxRuntime.jsx(shared.FloatingToolbarContext.Provider, {
280
+ value: { close, registerExternal },
281
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
282
+ role: "toolbar",
283
+ "aria-label": "Floating toolbar",
284
+ "aria-orientation": "horizontal",
285
+ className: classnames.classNames(
286
+ "lb-root lb-portal lb-elevation lb-tiptap-floating-toolbar lb-tiptap-toolbar",
287
+ className
288
+ ),
289
+ ref: mergedRefs,
290
+ style: {
291
+ position: strategy,
292
+ top: 0,
293
+ left: 0,
294
+ transform: isPositioned ? `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)` : "translate3d(0, -200%, 0)",
295
+ minWidth: "max-content"
296
+ },
297
+ onPointerDown: handlePointerDown,
298
+ onFocus: handleFocus,
299
+ onBlur: handleBlur,
300
+ ...props,
301
+ children: [
302
+ Toolbar.applyToolbarSlot(before, slotProps),
303
+ Toolbar.applyToolbarSlot(children, slotProps),
304
+ Toolbar.applyToolbarSlot(after, slotProps)
305
+ ]
306
+ })
307
+ })
308
+ })
309
+ }),
310
+ document.body
311
+ );
312
+ }
313
+ ),
314
+ {
315
+ External: shared.FloatingToolbarExternal
316
+ }
317
+ );
318
+
319
+ exports.FLOATING_TOOLBAR_COLLISION_PADDING = FLOATING_TOOLBAR_COLLISION_PADDING;
320
+ exports.FloatingToolbar = FloatingToolbar;
321
+ //# sourceMappingURL=FloatingToolbar.js.map