@liveblocks/react-lexical 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 (65) hide show
  1. package/dist/comments/anchored-threads.js +2 -2
  2. package/dist/comments/anchored-threads.js.map +1 -1
  3. package/dist/comments/anchored-threads.mjs +1 -1
  4. package/dist/comments/anchored-threads.mjs.map +1 -1
  5. package/dist/comments/comment-plugin-provider.js +8 -8
  6. package/dist/comments/comment-plugin-provider.js.map +1 -1
  7. package/dist/comments/comment-plugin-provider.mjs +6 -6
  8. package/dist/comments/comment-plugin-provider.mjs.map +1 -1
  9. package/dist/comments/floating-composer.js +7 -8
  10. package/dist/comments/floating-composer.js.map +1 -1
  11. package/dist/comments/floating-composer.mjs +8 -9
  12. package/dist/comments/floating-composer.mjs.map +1 -1
  13. package/dist/comments/floating-threads.js.map +1 -1
  14. package/dist/comments/floating-threads.mjs.map +1 -1
  15. package/dist/index.d.mts +250 -4
  16. package/dist/index.d.ts +250 -4
  17. package/dist/index.js +8 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +4 -0
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/is-block-node-active.js +51 -0
  22. package/dist/is-block-node-active.js.map +1 -0
  23. package/dist/is-block-node-active.mjs +49 -0
  24. package/dist/is-block-node-active.mjs.map +1 -0
  25. package/dist/is-command-registered.js +11 -0
  26. package/dist/is-command-registered.js.map +1 -0
  27. package/dist/is-command-registered.mjs +9 -0
  28. package/dist/is-command-registered.mjs.map +1 -0
  29. package/dist/is-text-format-active.js +16 -0
  30. package/dist/is-text-format-active.js.map +1 -0
  31. package/dist/is-text-format-active.mjs +14 -0
  32. package/dist/is-text-format-active.mjs.map +1 -0
  33. package/dist/liveblocks-plugin-provider.js +2 -15
  34. package/dist/liveblocks-plugin-provider.js.map +1 -1
  35. package/dist/liveblocks-plugin-provider.mjs +2 -14
  36. package/dist/liveblocks-plugin-provider.mjs.map +1 -1
  37. package/dist/toolbar/floating-toolbar.js +309 -0
  38. package/dist/toolbar/floating-toolbar.js.map +1 -0
  39. package/dist/toolbar/floating-toolbar.mjs +306 -0
  40. package/dist/toolbar/floating-toolbar.mjs.map +1 -0
  41. package/dist/toolbar/shared.js +36 -0
  42. package/dist/toolbar/shared.js.map +1 -0
  43. package/dist/toolbar/shared.mjs +33 -0
  44. package/dist/toolbar/shared.mjs.map +1 -0
  45. package/dist/toolbar/toolbar.js +433 -0
  46. package/dist/toolbar/toolbar.js.map +1 -0
  47. package/dist/toolbar/toolbar.mjs +408 -0
  48. package/dist/toolbar/toolbar.mjs.map +1 -0
  49. package/dist/use-root-element.js +21 -0
  50. package/dist/use-root-element.js.map +1 -0
  51. package/dist/use-root-element.mjs +19 -0
  52. package/dist/use-root-element.mjs.map +1 -0
  53. package/dist/version-history/history-version-preview.js +3 -10
  54. package/dist/version-history/history-version-preview.js.map +1 -1
  55. package/dist/version-history/history-version-preview.mjs +3 -10
  56. package/dist/version-history/history-version-preview.mjs.map +1 -1
  57. package/dist/version.js +1 -1
  58. package/dist/version.js.map +1 -1
  59. package/dist/version.mjs +1 -1
  60. package/dist/version.mjs.map +1 -1
  61. package/package.json +10 -6
  62. package/src/styles/constants.css +1 -1
  63. package/src/styles/index.css +44 -6
  64. package/styles.css +1 -1
  65. package/styles.css.map +1 -1
package/dist/index.d.mts CHANGED
@@ -1,10 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { BaseMetadata, DM, ThreadData, HistoryVersion } from '@liveblocks/core';
2
+ import { BaseMetadata, ThreadData } from '@liveblocks/client';
3
+ import { DM, HistoryVersion } from '@liveblocks/core';
3
4
  import { ThreadProps, ComposerProps } from '@liveblocks/react-ui';
4
5
  import * as react from 'react';
5
- import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ReactNode } from 'react';
6
+ import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ReactNode, ComponentProps } from 'react';
6
7
  import * as lexical from 'lexical';
7
- import { LexicalCommand } from 'lexical';
8
+ import { LexicalCommand, LexicalEditor, LexicalNode, TextFormatType } from 'lexical';
8
9
  import { InitialConfigType } from '@lexical/react/LexicalComposer';
9
10
 
10
11
  type AnchoredThreadsComponents = {
@@ -77,6 +78,19 @@ interface FloatingThreadsProps<M extends BaseMetadata = DM> extends Omit<HTMLAtt
77
78
  }
78
79
  declare function FloatingThreads({ threads, components, ...props }: FloatingThreadsProps): react_jsx_runtime.JSX.Element | null;
79
80
 
81
+ /**
82
+ * Checks if a block node is active in the current selection.
83
+ * If the selection contains multiple block nodes, it will return
84
+ * `true` only if all of them are of the same type.
85
+ */
86
+ declare function isBlockNodeActive(editor: LexicalEditor, isActive: (node: LexicalNode) => boolean): boolean;
87
+
88
+ /**
89
+ * Checks if a text format (e.g. bold, italic, …) is active in
90
+ * the current selection.
91
+ */
92
+ declare function isTextFormatActive(editor: LexicalEditor, format: TextFormatType): boolean;
93
+
80
94
  /**
81
95
  * Function that takes a Lexical editor config and modifies it to add the necessary
82
96
  * `nodes` and `theme` to make `LiveblocksPlugin` works correctly.
@@ -179,6 +193,238 @@ type LiveblocksPluginProps = {
179
193
  */
180
194
  declare const LiveblocksPlugin: ({ children, }: LiveblocksPluginProps) => JSX.Element;
181
195
 
196
+ type FloatingPosition = "top" | "bottom";
197
+
198
+ interface ToolbarSlotProps {
199
+ editor: LexicalEditor;
200
+ }
201
+ type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;
202
+ interface ToolbarProps extends Omit<ComponentProps<"div">, "children"> {
203
+ /**
204
+ * The content of the toolbar, overriding the default content.
205
+ * Use the `before` and `after` props if you want to keep and extend the default content.
206
+ */
207
+ children?: ToolbarSlot;
208
+ /**
209
+ * The content to display at the start of the toolbar.
210
+ */
211
+ before?: ToolbarSlot;
212
+ /**
213
+ * The content to display at the end of the toolbar.
214
+ */
215
+ after?: ToolbarSlot;
216
+ }
217
+ interface ToolbarButtonProps extends ComponentProps<"button"> {
218
+ /**
219
+ * The name of this button displayed in its tooltip.
220
+ */
221
+ name: string;
222
+ /**
223
+ * An optional icon displayed in this button.
224
+ */
225
+ icon?: ReactNode;
226
+ /**
227
+ * An optional keyboard shortcut displayed in this button's tooltip.
228
+ *
229
+ * @example
230
+ * "Mod-Alt-B" → "⌘⌥B" in Apple environments, "⌃⌥B" otherwise
231
+ * "Ctrl-Shift-Escape" → "⌃⇧⎋"
232
+ * "Space" → "␣"
233
+ */
234
+ shortcut?: string;
235
+ }
236
+ interface ToolbarToggleProps extends ToolbarButtonProps {
237
+ /**
238
+ * Whether the button is toggled.
239
+ */
240
+ active: boolean;
241
+ }
242
+ type ToolbarSeparatorProps = ComponentProps<"div">;
243
+ interface ToolbarBlockSelectorItem {
244
+ /**
245
+ * The name of this block element, displayed as the label of this item.
246
+ */
247
+ name: string;
248
+ /**
249
+ * Optionally replace the name used as the label of this item by any content.
250
+ */
251
+ label?: ReactNode;
252
+ /**
253
+ * An optional icon displayed in this item.
254
+ */
255
+ icon?: ReactNode;
256
+ /**
257
+ * Whether this block element is currently active.
258
+ * Set to `"default"` to display this item when no other item is active.
259
+ */
260
+ isActive: ((editor: LexicalEditor) => boolean) | "default";
261
+ /**
262
+ * A callback invoked when this item is selected.
263
+ */
264
+ setActive: (editor: LexicalEditor) => void;
265
+ }
266
+ interface ToolbarBlockSelectorProps extends ComponentProps<"button"> {
267
+ /**
268
+ * The items displayed in this block selector.
269
+ * When provided as an array, the default items are overridden. To avoid this,
270
+ * a function can be provided instead and it will receive the default items.
271
+ *
272
+ * @example
273
+ * <Toolbar.BlockSelector
274
+ * items={[
275
+ * {
276
+ * name: "Text",
277
+ * isActive: "default",
278
+ * setActive: () => { ... },
279
+ * },
280
+ * {
281
+ * name: "Heading 1",
282
+ * isActive: () => { ... },
283
+ * setActive: () => { ... },
284
+ * },
285
+ * ]}
286
+ * />
287
+ *
288
+ * @example
289
+ * <Toolbar.BlockSelector
290
+ * items={(defaultItems) => [
291
+ * ...defaultItems,
292
+ * {
293
+ * name: "Custom block",
294
+ * isActive: () => { ... },
295
+ * setActive: () => { ... },
296
+ * },
297
+ * ]}
298
+ * />
299
+ */
300
+ items?: ToolbarBlockSelectorItem[] | ((defaultItems: ToolbarBlockSelectorItem[]) => ToolbarBlockSelectorItem[]);
301
+ }
302
+ declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
303
+ declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element | null;
304
+ declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
305
+ /**
306
+ * A static toolbar containing actions and values related to the editor.
307
+ *
308
+ * @example
309
+ * <Toolbar />
310
+ *
311
+ * @example
312
+ * <Toolbar >
313
+ * <Toolbar.BlockSelector />
314
+ * <Toolbar.Separator />
315
+ * <Toolbar.SectionInline />
316
+ * <Toolbar.Separator />
317
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
318
+ * </Toolbar>
319
+ */
320
+ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
321
+ /**
322
+ * A button for triggering actions.
323
+ *
324
+ * @example
325
+ * <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }} />
326
+ *
327
+ * @example
328
+ * <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
329
+ */
330
+ Button: react.ForwardRefExoticComponent<Omit<ToolbarButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
331
+ /**
332
+ * A toggle button for values that can be active or inactive.
333
+ *
334
+ * @example
335
+ * <Toolbar.Toggle name="Bold" active={isBold} />
336
+ *
337
+ * @example
338
+ * <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
339
+ */
340
+ Toggle: react.ForwardRefExoticComponent<Omit<ToolbarToggleProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
341
+ /**
342
+ * A dropdown selector to switch between different block types.
343
+ *
344
+ * @example
345
+ * <Toolbar.BlockSelector />
346
+ */
347
+ BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
348
+ /**
349
+ * A visual (and accessible) separator to separate sections in a toolbar.
350
+ */
351
+ Separator: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
352
+ /**
353
+ * A section containing history actions. (e.g. undo, redo)
354
+ */
355
+ SectionHistory: typeof ToolbarSectionHistory;
356
+ /**
357
+ * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)
358
+ */
359
+ SectionInline: typeof ToolbarSectionInline;
360
+ /**
361
+ * A section containing collaborative actions. (e.g. adding a comment)
362
+ */
363
+ SectionCollaboration: typeof ToolbarSectionCollaboration;
364
+ };
365
+
366
+ interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
367
+ /**
368
+ * The vertical position of the floating toolbar.
369
+ */
370
+ position?: FloatingPosition;
371
+ /**
372
+ * The vertical offset of the floating toolbar from the selection.
373
+ */
374
+ offset?: number;
375
+ /**
376
+ * The content of the floating toolbar, overriding the default content.
377
+ * Use the `before` and `after` props if you want to keep and extend the default content.
378
+ */
379
+ children?: ToolbarSlot;
380
+ /**
381
+ * The content to display at the start of the floating toolbar.
382
+ */
383
+ before?: ToolbarSlot;
384
+ /**
385
+ * The content to display at the end of the floating toolbar.
386
+ */
387
+ after?: ToolbarSlot;
388
+ }
389
+ /**
390
+ * A floating toolbar attached to the selection and containing actions and values related to the editor.
391
+ *
392
+ * @example
393
+ * <FloatingToolbar />
394
+ *
395
+ * @example
396
+ * <FloatingToolbar>
397
+ * <Toolbar.BlockSelector />
398
+ * <Toolbar.Separator />
399
+ * <Toolbar.SectionInline />
400
+ * <Toolbar.Separator />
401
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
402
+ * </FloatingToolbar>
403
+ */
404
+ declare const FloatingToolbar: react.ForwardRefExoticComponent<Omit<FloatingToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
405
+ /**
406
+ * A component that can be wrapped around elements which are rendered outside of the floating
407
+ * toolbar (e.g. portals) to prevent the toolbar from closing when clicking/focusing within them.
408
+ *
409
+ * @example
410
+ * <FloatingToolbar>
411
+ * <Popover.Root>
412
+ * <Popover.Trigger asChild>
413
+ * <Toolbar.Button>Open popover</Toolbar.Button>
414
+ * </Popover.Trigger>
415
+ * <Popover.Portal>
416
+ * <FloatingToolbar.External>
417
+ * <Popover.Content>
418
+ * This popover is rendered outside of the floating toolbar, but the toolbar will not close when clicking/focusing within it.
419
+ * </Popover.Content>
420
+ * </FloatingToolbar.External>
421
+ * </Popover.Portal>
422
+ * </Popover.Root>
423
+ * </FloatingToolbar>
424
+ */
425
+ External: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
426
+ };
427
+
182
428
  interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
183
429
  version: HistoryVersion;
184
430
  onVersionRestore?: (version: HistoryVersion) => void;
@@ -191,4 +437,4 @@ interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
191
437
  */
192
438
  declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVersionPreviewProps & react.RefAttributes<HTMLDivElement>>;
193
439
 
194
- export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
440
+ export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, isBlockNodeActive, isTextFormatActive, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { BaseMetadata, DM, ThreadData, HistoryVersion } from '@liveblocks/core';
2
+ import { BaseMetadata, ThreadData } from '@liveblocks/client';
3
+ import { DM, HistoryVersion } from '@liveblocks/core';
3
4
  import { ThreadProps, ComposerProps } from '@liveblocks/react-ui';
4
5
  import * as react from 'react';
5
- import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ReactNode } from 'react';
6
+ import { ComponentPropsWithoutRef, ComponentType, HTMLAttributes, ReactNode, ComponentProps } from 'react';
6
7
  import * as lexical from 'lexical';
7
- import { LexicalCommand } from 'lexical';
8
+ import { LexicalCommand, LexicalEditor, LexicalNode, TextFormatType } from 'lexical';
8
9
  import { InitialConfigType } from '@lexical/react/LexicalComposer';
9
10
 
10
11
  type AnchoredThreadsComponents = {
@@ -77,6 +78,19 @@ interface FloatingThreadsProps<M extends BaseMetadata = DM> extends Omit<HTMLAtt
77
78
  }
78
79
  declare function FloatingThreads({ threads, components, ...props }: FloatingThreadsProps): react_jsx_runtime.JSX.Element | null;
79
80
 
81
+ /**
82
+ * Checks if a block node is active in the current selection.
83
+ * If the selection contains multiple block nodes, it will return
84
+ * `true` only if all of them are of the same type.
85
+ */
86
+ declare function isBlockNodeActive(editor: LexicalEditor, isActive: (node: LexicalNode) => boolean): boolean;
87
+
88
+ /**
89
+ * Checks if a text format (e.g. bold, italic, …) is active in
90
+ * the current selection.
91
+ */
92
+ declare function isTextFormatActive(editor: LexicalEditor, format: TextFormatType): boolean;
93
+
80
94
  /**
81
95
  * Function that takes a Lexical editor config and modifies it to add the necessary
82
96
  * `nodes` and `theme` to make `LiveblocksPlugin` works correctly.
@@ -179,6 +193,238 @@ type LiveblocksPluginProps = {
179
193
  */
180
194
  declare const LiveblocksPlugin: ({ children, }: LiveblocksPluginProps) => JSX.Element;
181
195
 
196
+ type FloatingPosition = "top" | "bottom";
197
+
198
+ interface ToolbarSlotProps {
199
+ editor: LexicalEditor;
200
+ }
201
+ type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;
202
+ interface ToolbarProps extends Omit<ComponentProps<"div">, "children"> {
203
+ /**
204
+ * The content of the toolbar, overriding the default content.
205
+ * Use the `before` and `after` props if you want to keep and extend the default content.
206
+ */
207
+ children?: ToolbarSlot;
208
+ /**
209
+ * The content to display at the start of the toolbar.
210
+ */
211
+ before?: ToolbarSlot;
212
+ /**
213
+ * The content to display at the end of the toolbar.
214
+ */
215
+ after?: ToolbarSlot;
216
+ }
217
+ interface ToolbarButtonProps extends ComponentProps<"button"> {
218
+ /**
219
+ * The name of this button displayed in its tooltip.
220
+ */
221
+ name: string;
222
+ /**
223
+ * An optional icon displayed in this button.
224
+ */
225
+ icon?: ReactNode;
226
+ /**
227
+ * An optional keyboard shortcut displayed in this button's tooltip.
228
+ *
229
+ * @example
230
+ * "Mod-Alt-B" → "⌘⌥B" in Apple environments, "⌃⌥B" otherwise
231
+ * "Ctrl-Shift-Escape" → "⌃⇧⎋"
232
+ * "Space" → "␣"
233
+ */
234
+ shortcut?: string;
235
+ }
236
+ interface ToolbarToggleProps extends ToolbarButtonProps {
237
+ /**
238
+ * Whether the button is toggled.
239
+ */
240
+ active: boolean;
241
+ }
242
+ type ToolbarSeparatorProps = ComponentProps<"div">;
243
+ interface ToolbarBlockSelectorItem {
244
+ /**
245
+ * The name of this block element, displayed as the label of this item.
246
+ */
247
+ name: string;
248
+ /**
249
+ * Optionally replace the name used as the label of this item by any content.
250
+ */
251
+ label?: ReactNode;
252
+ /**
253
+ * An optional icon displayed in this item.
254
+ */
255
+ icon?: ReactNode;
256
+ /**
257
+ * Whether this block element is currently active.
258
+ * Set to `"default"` to display this item when no other item is active.
259
+ */
260
+ isActive: ((editor: LexicalEditor) => boolean) | "default";
261
+ /**
262
+ * A callback invoked when this item is selected.
263
+ */
264
+ setActive: (editor: LexicalEditor) => void;
265
+ }
266
+ interface ToolbarBlockSelectorProps extends ComponentProps<"button"> {
267
+ /**
268
+ * The items displayed in this block selector.
269
+ * When provided as an array, the default items are overridden. To avoid this,
270
+ * a function can be provided instead and it will receive the default items.
271
+ *
272
+ * @example
273
+ * <Toolbar.BlockSelector
274
+ * items={[
275
+ * {
276
+ * name: "Text",
277
+ * isActive: "default",
278
+ * setActive: () => { ... },
279
+ * },
280
+ * {
281
+ * name: "Heading 1",
282
+ * isActive: () => { ... },
283
+ * setActive: () => { ... },
284
+ * },
285
+ * ]}
286
+ * />
287
+ *
288
+ * @example
289
+ * <Toolbar.BlockSelector
290
+ * items={(defaultItems) => [
291
+ * ...defaultItems,
292
+ * {
293
+ * name: "Custom block",
294
+ * isActive: () => { ... },
295
+ * setActive: () => { ... },
296
+ * },
297
+ * ]}
298
+ * />
299
+ */
300
+ items?: ToolbarBlockSelectorItem[] | ((defaultItems: ToolbarBlockSelectorItem[]) => ToolbarBlockSelectorItem[]);
301
+ }
302
+ declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
303
+ declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element | null;
304
+ declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
305
+ /**
306
+ * A static toolbar containing actions and values related to the editor.
307
+ *
308
+ * @example
309
+ * <Toolbar />
310
+ *
311
+ * @example
312
+ * <Toolbar >
313
+ * <Toolbar.BlockSelector />
314
+ * <Toolbar.Separator />
315
+ * <Toolbar.SectionInline />
316
+ * <Toolbar.Separator />
317
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
318
+ * </Toolbar>
319
+ */
320
+ declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
321
+ /**
322
+ * A button for triggering actions.
323
+ *
324
+ * @example
325
+ * <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }} />
326
+ *
327
+ * @example
328
+ * <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
329
+ */
330
+ Button: react.ForwardRefExoticComponent<Omit<ToolbarButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
331
+ /**
332
+ * A toggle button for values that can be active or inactive.
333
+ *
334
+ * @example
335
+ * <Toolbar.Toggle name="Bold" active={isBold} />
336
+ *
337
+ * @example
338
+ * <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
339
+ */
340
+ Toggle: react.ForwardRefExoticComponent<Omit<ToolbarToggleProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
341
+ /**
342
+ * A dropdown selector to switch between different block types.
343
+ *
344
+ * @example
345
+ * <Toolbar.BlockSelector />
346
+ */
347
+ BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
348
+ /**
349
+ * A visual (and accessible) separator to separate sections in a toolbar.
350
+ */
351
+ Separator: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
352
+ /**
353
+ * A section containing history actions. (e.g. undo, redo)
354
+ */
355
+ SectionHistory: typeof ToolbarSectionHistory;
356
+ /**
357
+ * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)
358
+ */
359
+ SectionInline: typeof ToolbarSectionInline;
360
+ /**
361
+ * A section containing collaborative actions. (e.g. adding a comment)
362
+ */
363
+ SectionCollaboration: typeof ToolbarSectionCollaboration;
364
+ };
365
+
366
+ interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
367
+ /**
368
+ * The vertical position of the floating toolbar.
369
+ */
370
+ position?: FloatingPosition;
371
+ /**
372
+ * The vertical offset of the floating toolbar from the selection.
373
+ */
374
+ offset?: number;
375
+ /**
376
+ * The content of the floating toolbar, overriding the default content.
377
+ * Use the `before` and `after` props if you want to keep and extend the default content.
378
+ */
379
+ children?: ToolbarSlot;
380
+ /**
381
+ * The content to display at the start of the floating toolbar.
382
+ */
383
+ before?: ToolbarSlot;
384
+ /**
385
+ * The content to display at the end of the floating toolbar.
386
+ */
387
+ after?: ToolbarSlot;
388
+ }
389
+ /**
390
+ * A floating toolbar attached to the selection and containing actions and values related to the editor.
391
+ *
392
+ * @example
393
+ * <FloatingToolbar />
394
+ *
395
+ * @example
396
+ * <FloatingToolbar>
397
+ * <Toolbar.BlockSelector />
398
+ * <Toolbar.Separator />
399
+ * <Toolbar.SectionInline />
400
+ * <Toolbar.Separator />
401
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
402
+ * </FloatingToolbar>
403
+ */
404
+ declare const FloatingToolbar: react.ForwardRefExoticComponent<Omit<FloatingToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
405
+ /**
406
+ * A component that can be wrapped around elements which are rendered outside of the floating
407
+ * toolbar (e.g. portals) to prevent the toolbar from closing when clicking/focusing within them.
408
+ *
409
+ * @example
410
+ * <FloatingToolbar>
411
+ * <Popover.Root>
412
+ * <Popover.Trigger asChild>
413
+ * <Toolbar.Button>Open popover</Toolbar.Button>
414
+ * </Popover.Trigger>
415
+ * <Popover.Portal>
416
+ * <FloatingToolbar.External>
417
+ * <Popover.Content>
418
+ * This popover is rendered outside of the floating toolbar, but the toolbar will not close when clicking/focusing within it.
419
+ * </Popover.Content>
420
+ * </FloatingToolbar.External>
421
+ * </Popover.Portal>
422
+ * </Popover.Root>
423
+ * </FloatingToolbar>
424
+ */
425
+ External: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
426
+ };
427
+
182
428
  interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
183
429
  version: HistoryVersion;
184
430
  onVersionRestore?: (version: HistoryVersion) => void;
@@ -191,4 +437,4 @@ interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
191
437
  */
192
438
  declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVersionPreviewProps & react.RefAttributes<HTMLDivElement>>;
193
439
 
194
- export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
440
+ export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, isBlockNodeActive, isTextFormatActive, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
package/dist/index.js CHANGED
@@ -6,8 +6,12 @@ var anchoredThreads = require('./comments/anchored-threads.js');
6
6
  var commentPluginProvider = require('./comments/comment-plugin-provider.js');
7
7
  var floatingComposer = require('./comments/floating-composer.js');
8
8
  var floatingThreads = require('./comments/floating-threads.js');
9
+ var isBlockNodeActive = require('./is-block-node-active.js');
10
+ var isTextFormatActive = require('./is-text-format-active.js');
9
11
  var liveblocksConfig = require('./liveblocks-config.js');
10
12
  var liveblocksPluginProvider = require('./liveblocks-plugin-provider.js');
13
+ var floatingToolbar = require('./toolbar/floating-toolbar.js');
14
+ var toolbar = require('./toolbar/toolbar.js');
11
15
  var historyVersionPreview = require('./version-history/history-version-preview.js');
12
16
 
13
17
  core.detectDupes(version.PKG_NAME, version.PKG_VERSION, version.PKG_FORMAT);
@@ -17,9 +21,13 @@ exports.useIsThreadActive = commentPluginProvider.useIsThreadActive;
17
21
  exports.FloatingComposer = floatingComposer.FloatingComposer;
18
22
  exports.OPEN_FLOATING_COMPOSER_COMMAND = floatingComposer.OPEN_FLOATING_COMPOSER_COMMAND;
19
23
  exports.FloatingThreads = floatingThreads.FloatingThreads;
24
+ exports.isBlockNodeActive = isBlockNodeActive.isBlockNodeActive;
25
+ exports.isTextFormatActive = isTextFormatActive.isTextFormatActive;
20
26
  exports.liveblocksConfig = liveblocksConfig.liveblocksConfig;
21
27
  exports.LiveblocksPlugin = liveblocksPluginProvider.LiveblocksPlugin;
22
28
  exports.useEditorStatus = liveblocksPluginProvider.useEditorStatus;
23
29
  exports.useIsEditorReady = liveblocksPluginProvider.useIsEditorReady;
30
+ exports.FloatingToolbar = floatingToolbar.FloatingToolbar;
31
+ exports.Toolbar = toolbar.Toolbar;
24
32
  exports.HistoryVersionPreview = historyVersionPreview.HistoryVersionPreview;
25
33
  //# 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 type { AnchoredThreadsProps } from \"./comments/anchored-threads\";\nexport { AnchoredThreads } from \"./comments/anchored-threads\";\nexport { useIsThreadActive } from \"./comments/comment-plugin-provider\";\nexport type { FloatingComposerProps } from \"./comments/floating-composer\";\nexport {\n FloatingComposer,\n OPEN_FLOATING_COMPOSER_COMMAND,\n} from \"./comments/floating-composer\";\nexport type { FloatingThreadsProps } from \"./comments/floating-threads\";\nexport { FloatingThreads } from \"./comments/floating-threads\";\nexport { liveblocksConfig } from \"./liveblocks-config\";\nexport {\n LiveblocksPlugin,\n useEditorStatus,\n useIsEditorReady,\n} from \"./liveblocks-plugin-provider\";\nexport type { HistoryVersionPreviewProps } from \"./version-history/history-version-preview\";\nexport { HistoryVersionPreview } from \"./version-history/history-version-preview\";\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 { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { AnchoredThreadsProps } from \"./comments/anchored-threads\";\nexport { AnchoredThreads } from \"./comments/anchored-threads\";\nexport { useIsThreadActive } from \"./comments/comment-plugin-provider\";\nexport type { FloatingComposerProps } from \"./comments/floating-composer\";\nexport {\n FloatingComposer,\n OPEN_FLOATING_COMPOSER_COMMAND,\n} from \"./comments/floating-composer\";\nexport type { FloatingThreadsProps } from \"./comments/floating-threads\";\nexport { FloatingThreads } from \"./comments/floating-threads\";\nexport { isBlockNodeActive } from \"./is-block-node-active\";\nexport { isTextFormatActive } from \"./is-text-format-active\";\nexport { liveblocksConfig } from \"./liveblocks-config\";\nexport {\n LiveblocksPlugin,\n useEditorStatus,\n useIsEditorReady,\n} from \"./liveblocks-plugin-provider\";\nexport type { FloatingToolbarProps } from \"./toolbar/floating-toolbar\";\nexport { FloatingToolbar } from \"./toolbar/floating-toolbar\";\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/history-version-preview\";\nexport { HistoryVersionPreview } from \"./version-history/history-version-preview\";\n"],"names":["detectDupes","PKG_NAME","PKG_VERSION","PKG_FORMAT"],"mappings":";;;;;;;;;;;;;;;;AAIAA,gBAAY,CAAAC,gBAAA,EAAUC,qBAAaC,kBAAU,CAAA;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -4,8 +4,12 @@ export { AnchoredThreads } from './comments/anchored-threads.mjs';
4
4
  export { useIsThreadActive } from './comments/comment-plugin-provider.mjs';
5
5
  export { FloatingComposer, OPEN_FLOATING_COMPOSER_COMMAND } from './comments/floating-composer.mjs';
6
6
  export { FloatingThreads } from './comments/floating-threads.mjs';
7
+ export { isBlockNodeActive } from './is-block-node-active.mjs';
8
+ export { isTextFormatActive } from './is-text-format-active.mjs';
7
9
  export { liveblocksConfig } from './liveblocks-config.mjs';
8
10
  export { LiveblocksPlugin, useEditorStatus, useIsEditorReady } from './liveblocks-plugin-provider.mjs';
11
+ export { FloatingToolbar } from './toolbar/floating-toolbar.mjs';
12
+ export { Toolbar } from './toolbar/toolbar.mjs';
9
13
  export { HistoryVersionPreview } from './version-history/history-version-preview.mjs';
10
14
 
11
15
  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 type { AnchoredThreadsProps } from \"./comments/anchored-threads\";\nexport { AnchoredThreads } from \"./comments/anchored-threads\";\nexport { useIsThreadActive } from \"./comments/comment-plugin-provider\";\nexport type { FloatingComposerProps } from \"./comments/floating-composer\";\nexport {\n FloatingComposer,\n OPEN_FLOATING_COMPOSER_COMMAND,\n} from \"./comments/floating-composer\";\nexport type { FloatingThreadsProps } from \"./comments/floating-threads\";\nexport { FloatingThreads } from \"./comments/floating-threads\";\nexport { liveblocksConfig } from \"./liveblocks-config\";\nexport {\n LiveblocksPlugin,\n useEditorStatus,\n useIsEditorReady,\n} from \"./liveblocks-plugin-provider\";\nexport type { HistoryVersionPreviewProps } from \"./version-history/history-version-preview\";\nexport { HistoryVersionPreview } from \"./version-history/history-version-preview\";\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 { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { AnchoredThreadsProps } from \"./comments/anchored-threads\";\nexport { AnchoredThreads } from \"./comments/anchored-threads\";\nexport { useIsThreadActive } from \"./comments/comment-plugin-provider\";\nexport type { FloatingComposerProps } from \"./comments/floating-composer\";\nexport {\n FloatingComposer,\n OPEN_FLOATING_COMPOSER_COMMAND,\n} from \"./comments/floating-composer\";\nexport type { FloatingThreadsProps } from \"./comments/floating-threads\";\nexport { FloatingThreads } from \"./comments/floating-threads\";\nexport { isBlockNodeActive } from \"./is-block-node-active\";\nexport { isTextFormatActive } from \"./is-text-format-active\";\nexport { liveblocksConfig } from \"./liveblocks-config\";\nexport {\n LiveblocksPlugin,\n useEditorStatus,\n useIsEditorReady,\n} from \"./liveblocks-plugin-provider\";\nexport type { FloatingToolbarProps } from \"./toolbar/floating-toolbar\";\nexport { FloatingToolbar } from \"./toolbar/floating-toolbar\";\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/history-version-preview\";\nexport { HistoryVersionPreview } from \"./version-history/history-version-preview\";\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAIA,WAAY,CAAA,QAAA,EAAU,aAAa,UAAU,CAAA"}
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@lexical/utils');
4
+ var lexical = require('lexical');
5
+
6
+ function isParentRootOrShadowRoot(node) {
7
+ const parent = node.getParent();
8
+ return parent !== null && lexical.$isRootOrShadowRoot(parent);
9
+ }
10
+ const activeNodesByEditor = /* @__PURE__ */ new WeakMap();
11
+ function getActiveBlockNodes(editor) {
12
+ const currentState = editor.getEditorState();
13
+ return currentState.read(() => {
14
+ const selection = lexical.$getSelection();
15
+ if (!lexical.$isRangeSelection(selection)) {
16
+ activeNodesByEditor.delete(editor);
17
+ return [];
18
+ }
19
+ const cache = activeNodesByEditor.get(editor);
20
+ if (cache?.state === currentState) {
21
+ return cache.nodes;
22
+ }
23
+ const anchor = selection.anchor.getNode();
24
+ const focus = selection.focus.getNode();
25
+ const commonAncestor = anchor.getCommonAncestor(focus);
26
+ let activeNodes = [];
27
+ if (commonAncestor && !lexical.$isRootOrShadowRoot(commonAncestor)) {
28
+ const activeNode = isParentRootOrShadowRoot(commonAncestor) ? commonAncestor : utils.$findMatchingParent(commonAncestor, isParentRootOrShadowRoot);
29
+ if (activeNode) {
30
+ activeNodes = [activeNode];
31
+ }
32
+ } else {
33
+ activeNodes = selection.getNodes().filter((node) => lexical.$isRootOrShadowRoot(node.getParent()));
34
+ }
35
+ activeNodesByEditor.set(editor, {
36
+ state: currentState,
37
+ nodes: activeNodes
38
+ });
39
+ return activeNodes;
40
+ });
41
+ }
42
+ function isBlockNodeActive(editor, isActive) {
43
+ const activeNodes = getActiveBlockNodes(editor);
44
+ if (activeNodes.length === 0) {
45
+ return false;
46
+ }
47
+ return activeNodes.every(isActive);
48
+ }
49
+
50
+ exports.isBlockNodeActive = isBlockNodeActive;
51
+ //# sourceMappingURL=is-block-node-active.js.map