@liveblocks/react-lexical 2.16.0-toolbars3 → 2.16.0-toolbars4

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.
@@ -7,7 +7,7 @@ function isParentRootOrShadowRoot(node) {
7
7
  const parent = node.getParent();
8
8
  return parent !== null && lexical.$isRootOrShadowRoot(parent);
9
9
  }
10
- function getSelectedBlockElement(editor) {
10
+ function getActiveBlockElement(editor) {
11
11
  return editor.getEditorState().read(() => {
12
12
  const selection = lexical.$getSelection();
13
13
  if (!lexical.$isRangeSelection(selection))
@@ -22,5 +22,5 @@ function getSelectedBlockElement(editor) {
22
22
  });
23
23
  }
24
24
 
25
- exports.getSelectedBlockElement = getSelectedBlockElement;
26
- //# sourceMappingURL=get-selected-block-element.js.map
25
+ exports.getActiveBlockElement = getActiveBlockElement;
26
+ //# sourceMappingURL=get-active-block-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-active-block-element.js","sources":["../src/get-active-block-element.ts"],"sourcesContent":["import { $findMatchingParent } from \"@lexical/utils\";\nimport type { LexicalEditor, LexicalNode } from \"lexical\";\nimport { $getSelection, $isRangeSelection, $isRootOrShadowRoot } from \"lexical\";\n\nfunction isParentRootOrShadowRoot(node: LexicalNode) {\n const parent = node.getParent();\n\n return parent !== null && $isRootOrShadowRoot(parent);\n}\n\nexport function getActiveBlockElement(editor: LexicalEditor) {\n return editor.getEditorState().read(() => {\n const selection = $getSelection();\n\n if (!$isRangeSelection(selection)) return null;\n\n const anchor = selection.anchor.getNode();\n const focus = selection.focus.getNode();\n\n const commonAncestor = anchor.getCommonAncestor(focus);\n\n if (!commonAncestor || $isRootOrShadowRoot(commonAncestor)) return null;\n\n const element = isParentRootOrShadowRoot(commonAncestor)\n ? commonAncestor\n : $findMatchingParent(commonAncestor, isParentRootOrShadowRoot);\n\n return element;\n });\n}\n"],"names":["$isRootOrShadowRoot","$getSelection","$isRangeSelection","$findMatchingParent"],"mappings":";;;;;AAIA,SAAS,yBAAyB,IAAmB,EAAA;AACnD,EAAM,MAAA,MAAA,GAAS,KAAK,SAAU,EAAA,CAAA;AAE9B,EAAO,OAAA,MAAA,KAAW,IAAQ,IAAAA,2BAAA,CAAoB,MAAM,CAAA,CAAA;AACtD,CAAA;AAEO,SAAS,sBAAsB,MAAuB,EAAA;AAC3D,EAAA,OAAO,MAAO,CAAA,cAAA,EAAiB,CAAA,IAAA,CAAK,MAAM;AACxC,IAAA,MAAM,YAAYC,qBAAc,EAAA,CAAA;AAEhC,IAAI,IAAA,CAACC,0BAAkB,SAAS,CAAA;AAAG,MAAO,OAAA,IAAA,CAAA;AAE1C,IAAM,MAAA,MAAA,GAAS,SAAU,CAAA,MAAA,CAAO,OAAQ,EAAA,CAAA;AACxC,IAAM,MAAA,KAAA,GAAQ,SAAU,CAAA,KAAA,CAAM,OAAQ,EAAA,CAAA;AAEtC,IAAM,MAAA,cAAA,GAAiB,MAAO,CAAA,iBAAA,CAAkB,KAAK,CAAA,CAAA;AAErD,IAAI,IAAA,CAAC,cAAkB,IAAAF,2BAAA,CAAoB,cAAc,CAAA;AAAG,MAAO,OAAA,IAAA,CAAA;AAEnE,IAAA,MAAM,UAAU,wBAAyB,CAAA,cAAc,IACnD,cACA,GAAAG,yBAAA,CAAoB,gBAAgB,wBAAwB,CAAA,CAAA;AAEhE,IAAO,OAAA,OAAA,CAAA;AAAA,GACR,CAAA,CAAA;AACH;;;;"}
@@ -5,7 +5,7 @@ function isParentRootOrShadowRoot(node) {
5
5
  const parent = node.getParent();
6
6
  return parent !== null && $isRootOrShadowRoot(parent);
7
7
  }
8
- function getSelectedBlockElement(editor) {
8
+ function getActiveBlockElement(editor) {
9
9
  return editor.getEditorState().read(() => {
10
10
  const selection = $getSelection();
11
11
  if (!$isRangeSelection(selection))
@@ -20,5 +20,5 @@ function getSelectedBlockElement(editor) {
20
20
  });
21
21
  }
22
22
 
23
- export { getSelectedBlockElement };
24
- //# sourceMappingURL=get-selected-block-element.mjs.map
23
+ export { getActiveBlockElement };
24
+ //# sourceMappingURL=get-active-block-element.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-active-block-element.mjs","sources":["../src/get-active-block-element.ts"],"sourcesContent":["import { $findMatchingParent } from \"@lexical/utils\";\nimport type { LexicalEditor, LexicalNode } from \"lexical\";\nimport { $getSelection, $isRangeSelection, $isRootOrShadowRoot } from \"lexical\";\n\nfunction isParentRootOrShadowRoot(node: LexicalNode) {\n const parent = node.getParent();\n\n return parent !== null && $isRootOrShadowRoot(parent);\n}\n\nexport function getActiveBlockElement(editor: LexicalEditor) {\n return editor.getEditorState().read(() => {\n const selection = $getSelection();\n\n if (!$isRangeSelection(selection)) return null;\n\n const anchor = selection.anchor.getNode();\n const focus = selection.focus.getNode();\n\n const commonAncestor = anchor.getCommonAncestor(focus);\n\n if (!commonAncestor || $isRootOrShadowRoot(commonAncestor)) return null;\n\n const element = isParentRootOrShadowRoot(commonAncestor)\n ? commonAncestor\n : $findMatchingParent(commonAncestor, isParentRootOrShadowRoot);\n\n return element;\n });\n}\n"],"names":[],"mappings":";;;AAIA,SAAS,yBAAyB,IAAmB,EAAA;AACnD,EAAM,MAAA,MAAA,GAAS,KAAK,SAAU,EAAA,CAAA;AAE9B,EAAO,OAAA,MAAA,KAAW,IAAQ,IAAA,mBAAA,CAAoB,MAAM,CAAA,CAAA;AACtD,CAAA;AAEO,SAAS,sBAAsB,MAAuB,EAAA;AAC3D,EAAA,OAAO,MAAO,CAAA,cAAA,EAAiB,CAAA,IAAA,CAAK,MAAM;AACxC,IAAA,MAAM,YAAY,aAAc,EAAA,CAAA;AAEhC,IAAI,IAAA,CAAC,kBAAkB,SAAS,CAAA;AAAG,MAAO,OAAA,IAAA,CAAA;AAE1C,IAAM,MAAA,MAAA,GAAS,SAAU,CAAA,MAAA,CAAO,OAAQ,EAAA,CAAA;AACxC,IAAM,MAAA,KAAA,GAAQ,SAAU,CAAA,KAAA,CAAM,OAAQ,EAAA,CAAA;AAEtC,IAAM,MAAA,cAAA,GAAiB,MAAO,CAAA,iBAAA,CAAkB,KAAK,CAAA,CAAA;AAErD,IAAI,IAAA,CAAC,cAAkB,IAAA,mBAAA,CAAoB,cAAc,CAAA;AAAG,MAAO,OAAA,IAAA,CAAA;AAEnE,IAAA,MAAM,UAAU,wBAAyB,CAAA,cAAc,IACnD,cACA,GAAA,mBAAA,CAAoB,gBAAgB,wBAAwB,CAAA,CAAA;AAEhE,IAAO,OAAA,OAAA,CAAA;AAAA,GACR,CAAA,CAAA;AACH;;;;"}
package/dist/index.d.mts CHANGED
@@ -77,7 +77,7 @@ interface FloatingThreadsProps<M extends BaseMetadata = DM> extends Omit<HTMLAtt
77
77
  }
78
78
  declare function FloatingThreads({ threads, components, ...props }: FloatingThreadsProps): react_jsx_runtime.JSX.Element | null;
79
79
 
80
- declare function getSelectedBlockElement(editor: LexicalEditor): LexicalNode | null;
80
+ declare function getActiveBlockElement(editor: LexicalEditor): LexicalNode | null;
81
81
 
82
82
  declare function isTextFormatActive(editor: LexicalEditor, format: TextFormatType): boolean;
83
83
 
@@ -190,48 +190,228 @@ interface ToolbarSlotProps {
190
190
  }
191
191
  type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;
192
192
  interface ToolbarProps extends Omit<ComponentProps<"div">, "children"> {
193
+ /**
194
+ * The content of the toolbar, overriding the default content.
195
+ * Use the `before` and `after` props if you want to keep and extend the default content.
196
+ */
193
197
  children?: ToolbarSlot;
198
+ /**
199
+ * The content to display at the start of the toolbar.
200
+ */
194
201
  before?: ToolbarSlot;
202
+ /**
203
+ * The content to display at the end of the toolbar.
204
+ */
195
205
  after?: ToolbarSlot;
196
206
  }
197
207
  interface ToolbarButtonProps extends ComponentProps<"button"> {
198
- icon?: ReactNode;
208
+ /**
209
+ * The name of this button displayed in its tooltip.
210
+ */
199
211
  name: string;
212
+ /**
213
+ * An optional icon displayed in this button.
214
+ */
215
+ icon?: ReactNode;
216
+ /**
217
+ * An optional keyboard shortcut displayed in this button's tooltip.
218
+ *
219
+ * @example
220
+ * "Mod-Alt-B" → "⌘⌥B" in Apple environments, "⌃⌥B" otherwise
221
+ * "Ctrl-Shift-Escape" → "⌃⇧⎋"
222
+ * "Space" → "␣"
223
+ */
200
224
  shortcut?: string;
201
225
  }
202
226
  interface ToolbarToggleProps extends ToolbarButtonProps {
227
+ /**
228
+ * Whether the button is toggled.
229
+ */
203
230
  active: boolean;
204
231
  }
232
+ type ToolbarSeparatorProps = ComponentProps<"div">;
205
233
  interface ToolbarBlockSelectorItem {
234
+ /**
235
+ * The name of this block element, displayed as the label of this item.
236
+ */
206
237
  name: string;
238
+ /**
239
+ * Optionally replace the name used as the label of this item by any content.
240
+ */
241
+ label?: ReactNode;
242
+ /**
243
+ * An optional icon displayed in this item.
244
+ */
207
245
  icon?: ReactNode;
246
+ /**
247
+ * Whether this block element is currently active.
248
+ * Set to `"default"` to display this item when no other item is active.
249
+ */
208
250
  isActive: ((element: LexicalNode | null, editor: LexicalEditor) => boolean) | "default";
251
+ /**
252
+ * A callback invoked when this item is selected.
253
+ */
209
254
  setActive: (editor: LexicalEditor) => void;
210
255
  }
211
256
  interface ToolbarBlockSelectorProps extends ComponentProps<"button"> {
257
+ /**
258
+ * The items displayed in this block selector.
259
+ * When provided as an array, the default items are overridden. To avoid this,
260
+ * a function can be provided instead and it will receive the default items.
261
+ *
262
+ * @example
263
+ * <Toolbar.BlockSelector
264
+ * items={[
265
+ * {
266
+ * name: "Text",
267
+ * isActive: "default",
268
+ * setActive: () => { ... },
269
+ * },
270
+ * {
271
+ * name: "Heading 1",
272
+ * isActive: () => { ... },
273
+ * setActive: () => { ... },
274
+ * },
275
+ * ]}
276
+ * />
277
+ *
278
+ * @example
279
+ * <Toolbar.BlockSelector
280
+ * items={(defaultItems) => [
281
+ * ...defaultItems,
282
+ * {
283
+ * name: "Custom block",
284
+ * isActive: () => { ... },
285
+ * setActive: () => { ... },
286
+ * },
287
+ * ]}
288
+ * />
289
+ */
212
290
  items?: ToolbarBlockSelectorItem[] | ((defaultItems: ToolbarBlockSelectorItem[]) => ToolbarBlockSelectorItem[]);
213
291
  }
214
292
  declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
215
293
  declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element | null;
216
294
  declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
295
+ /**
296
+ * A static toolbar containing actions and values related to the editor.
297
+ *
298
+ * @example
299
+ * <Toolbar />
300
+ *
301
+ * @example
302
+ * <Toolbar >
303
+ * <Toolbar.BlockSelector />
304
+ * <Toolbar.Separator />
305
+ * <Toolbar.SectionInline />
306
+ * <Toolbar.Separator />
307
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
308
+ * </Toolbar>
309
+ */
217
310
  declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
311
+ /**
312
+ * A button for triggering actions.
313
+ *
314
+ * @example
315
+ * <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }}>Comment</Toolbar.Button>
316
+ *
317
+ * @example
318
+ * <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
319
+ */
218
320
  Button: react.ForwardRefExoticComponent<Omit<ToolbarButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
321
+ /**
322
+ * A toggle button for values that can be active or inactive.
323
+ *
324
+ * @example
325
+ * <Toolbar.Toggle name="Bold" active={isBold}>Bold</Toolbar.Toggle>
326
+ *
327
+ * @example
328
+ * <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
329
+ */
219
330
  Toggle: react.ForwardRefExoticComponent<Omit<ToolbarToggleProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
331
+ /**
332
+ * A dropdown selector to switch between different block types.
333
+ *
334
+ * @example
335
+ * <Toolbar.BlockSelector />
336
+ */
337
+ BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
338
+ /**
339
+ * A visual (and accessible) separator to separate sections in a toolbar.
340
+ */
220
341
  Separator: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
342
+ /**
343
+ * A section containing history actions. (e.g. undo, redo)
344
+ */
221
345
  SectionHistory: typeof ToolbarSectionHistory;
346
+ /**
347
+ * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)
348
+ */
222
349
  SectionInline: typeof ToolbarSectionInline;
350
+ /**
351
+ * A section containing collaborative actions. (e.g. adding a comment)
352
+ */
223
353
  SectionCollaboration: typeof ToolbarSectionCollaboration;
224
- BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
225
354
  };
226
355
 
227
356
  interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
357
+ /**
358
+ * The vertical position of the floating toolbar.
359
+ */
228
360
  position?: FloatingPosition;
361
+ /**
362
+ * The vertical offset of the floating toolbar from the selection.
363
+ */
229
364
  offset?: number;
365
+ /**
366
+ * The content of the floating toolbar, overriding the default content.
367
+ * Use the `before` and `after` props if you want to keep and extend the default content.
368
+ */
230
369
  children?: ToolbarSlot;
370
+ /**
371
+ * The content to display at the start of the floating toolbar.
372
+ */
231
373
  before?: ToolbarSlot;
374
+ /**
375
+ * The content to display at the end of the floating toolbar.
376
+ */
232
377
  after?: ToolbarSlot;
233
378
  }
379
+ /**
380
+ * A floating toolbar attached to the selection and containing actions and values related to the editor.
381
+ *
382
+ * @example
383
+ * <FloatingToolbar />
384
+ *
385
+ * @example
386
+ * <FloatingToolbar>
387
+ * <Toolbar.BlockSelector />
388
+ * <Toolbar.Separator />
389
+ * <Toolbar.SectionInline />
390
+ * <Toolbar.Separator />
391
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
392
+ * </FloatingToolbar>
393
+ */
234
394
  declare const FloatingToolbar: react.ForwardRefExoticComponent<Omit<FloatingToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
395
+ /**
396
+ * A component that can be wrapped around elements which are rendered outside of the floating
397
+ * toolbar (e.g. portals) to prevent the toolbar from closing when clicking/focusing within them.
398
+ *
399
+ * @example
400
+ * <FloatingToolbar>
401
+ * <Popover.Root>
402
+ * <Popover.Trigger asChild>
403
+ * <Toolbar.Button>Open popover</Toolbar.Button>
404
+ * </Popover.Trigger>
405
+ * <Popover.Portal>
406
+ * <FloatingToolbar.External>
407
+ * <Popover.Content>
408
+ * This popover is rendered outside of the floating toolbar, but the toolbar will not close when clicking/focusing within it.
409
+ * </Popover.Content>
410
+ * </FloatingToolbar.External>
411
+ * </Popover.Portal>
412
+ * </Popover.Root>
413
+ * </FloatingToolbar>
414
+ */
235
415
  External: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
236
416
  };
237
417
 
@@ -247,4 +427,4 @@ interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
247
427
  */
248
428
  declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVersionPreviewProps & react.RefAttributes<HTMLDivElement>>;
249
429
 
250
- export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, Toolbar, ToolbarProps, getSelectedBlockElement, isTextFormatActive, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
430
+ export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, getActiveBlockElement, isTextFormatActive, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
package/dist/index.d.ts CHANGED
@@ -77,7 +77,7 @@ interface FloatingThreadsProps<M extends BaseMetadata = DM> extends Omit<HTMLAtt
77
77
  }
78
78
  declare function FloatingThreads({ threads, components, ...props }: FloatingThreadsProps): react_jsx_runtime.JSX.Element | null;
79
79
 
80
- declare function getSelectedBlockElement(editor: LexicalEditor): LexicalNode | null;
80
+ declare function getActiveBlockElement(editor: LexicalEditor): LexicalNode | null;
81
81
 
82
82
  declare function isTextFormatActive(editor: LexicalEditor, format: TextFormatType): boolean;
83
83
 
@@ -190,48 +190,228 @@ interface ToolbarSlotProps {
190
190
  }
191
191
  type ToolbarSlot = ReactNode | ComponentType<ToolbarSlotProps>;
192
192
  interface ToolbarProps extends Omit<ComponentProps<"div">, "children"> {
193
+ /**
194
+ * The content of the toolbar, overriding the default content.
195
+ * Use the `before` and `after` props if you want to keep and extend the default content.
196
+ */
193
197
  children?: ToolbarSlot;
198
+ /**
199
+ * The content to display at the start of the toolbar.
200
+ */
194
201
  before?: ToolbarSlot;
202
+ /**
203
+ * The content to display at the end of the toolbar.
204
+ */
195
205
  after?: ToolbarSlot;
196
206
  }
197
207
  interface ToolbarButtonProps extends ComponentProps<"button"> {
198
- icon?: ReactNode;
208
+ /**
209
+ * The name of this button displayed in its tooltip.
210
+ */
199
211
  name: string;
212
+ /**
213
+ * An optional icon displayed in this button.
214
+ */
215
+ icon?: ReactNode;
216
+ /**
217
+ * An optional keyboard shortcut displayed in this button's tooltip.
218
+ *
219
+ * @example
220
+ * "Mod-Alt-B" → "⌘⌥B" in Apple environments, "⌃⌥B" otherwise
221
+ * "Ctrl-Shift-Escape" → "⌃⇧⎋"
222
+ * "Space" → "␣"
223
+ */
200
224
  shortcut?: string;
201
225
  }
202
226
  interface ToolbarToggleProps extends ToolbarButtonProps {
227
+ /**
228
+ * Whether the button is toggled.
229
+ */
203
230
  active: boolean;
204
231
  }
232
+ type ToolbarSeparatorProps = ComponentProps<"div">;
205
233
  interface ToolbarBlockSelectorItem {
234
+ /**
235
+ * The name of this block element, displayed as the label of this item.
236
+ */
206
237
  name: string;
238
+ /**
239
+ * Optionally replace the name used as the label of this item by any content.
240
+ */
241
+ label?: ReactNode;
242
+ /**
243
+ * An optional icon displayed in this item.
244
+ */
207
245
  icon?: ReactNode;
246
+ /**
247
+ * Whether this block element is currently active.
248
+ * Set to `"default"` to display this item when no other item is active.
249
+ */
208
250
  isActive: ((element: LexicalNode | null, editor: LexicalEditor) => boolean) | "default";
251
+ /**
252
+ * A callback invoked when this item is selected.
253
+ */
209
254
  setActive: (editor: LexicalEditor) => void;
210
255
  }
211
256
  interface ToolbarBlockSelectorProps extends ComponentProps<"button"> {
257
+ /**
258
+ * The items displayed in this block selector.
259
+ * When provided as an array, the default items are overridden. To avoid this,
260
+ * a function can be provided instead and it will receive the default items.
261
+ *
262
+ * @example
263
+ * <Toolbar.BlockSelector
264
+ * items={[
265
+ * {
266
+ * name: "Text",
267
+ * isActive: "default",
268
+ * setActive: () => { ... },
269
+ * },
270
+ * {
271
+ * name: "Heading 1",
272
+ * isActive: () => { ... },
273
+ * setActive: () => { ... },
274
+ * },
275
+ * ]}
276
+ * />
277
+ *
278
+ * @example
279
+ * <Toolbar.BlockSelector
280
+ * items={(defaultItems) => [
281
+ * ...defaultItems,
282
+ * {
283
+ * name: "Custom block",
284
+ * isActive: () => { ... },
285
+ * setActive: () => { ... },
286
+ * },
287
+ * ]}
288
+ * />
289
+ */
212
290
  items?: ToolbarBlockSelectorItem[] | ((defaultItems: ToolbarBlockSelectorItem[]) => ToolbarBlockSelectorItem[]);
213
291
  }
214
292
  declare function ToolbarSectionHistory(): react_jsx_runtime.JSX.Element;
215
293
  declare function ToolbarSectionInline(): react_jsx_runtime.JSX.Element | null;
216
294
  declare function ToolbarSectionCollaboration(): react_jsx_runtime.JSX.Element;
295
+ /**
296
+ * A static toolbar containing actions and values related to the editor.
297
+ *
298
+ * @example
299
+ * <Toolbar />
300
+ *
301
+ * @example
302
+ * <Toolbar >
303
+ * <Toolbar.BlockSelector />
304
+ * <Toolbar.Separator />
305
+ * <Toolbar.SectionInline />
306
+ * <Toolbar.Separator />
307
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
308
+ * </Toolbar>
309
+ */
217
310
  declare const Toolbar: react.ForwardRefExoticComponent<Omit<ToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
311
+ /**
312
+ * A button for triggering actions.
313
+ *
314
+ * @example
315
+ * <Toolbar.Button name="Comment" shortcut="Mod-Shift-E" onClick={() => { ... }}>Comment</Toolbar.Button>
316
+ *
317
+ * @example
318
+ * <Toolbar.Button name="Mention someone" icon={<Icon.Mention />} onClick={() => { ... }} />
319
+ */
218
320
  Button: react.ForwardRefExoticComponent<Omit<ToolbarButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
321
+ /**
322
+ * A toggle button for values that can be active or inactive.
323
+ *
324
+ * @example
325
+ * <Toolbar.Toggle name="Bold" active={isBold}>Bold</Toolbar.Toggle>
326
+ *
327
+ * @example
328
+ * <Toolbar.Toggle name="Italic" icon={<Icon.Italic />} shortcut="Mod-I" active={isItalic} onClick={() => { ... }} />
329
+ */
219
330
  Toggle: react.ForwardRefExoticComponent<Omit<ToolbarToggleProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
331
+ /**
332
+ * A dropdown selector to switch between different block types.
333
+ *
334
+ * @example
335
+ * <Toolbar.BlockSelector />
336
+ */
337
+ BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
338
+ /**
339
+ * A visual (and accessible) separator to separate sections in a toolbar.
340
+ */
220
341
  Separator: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
342
+ /**
343
+ * A section containing history actions. (e.g. undo, redo)
344
+ */
221
345
  SectionHistory: typeof ToolbarSectionHistory;
346
+ /**
347
+ * A section containing inline formatting actions. (e.g. bold, italic, underline, ...)
348
+ */
222
349
  SectionInline: typeof ToolbarSectionInline;
350
+ /**
351
+ * A section containing collaborative actions. (e.g. adding a comment)
352
+ */
223
353
  SectionCollaboration: typeof ToolbarSectionCollaboration;
224
- BlockSelector: react.ForwardRefExoticComponent<Omit<ToolbarBlockSelectorProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
225
354
  };
226
355
 
227
356
  interface FloatingToolbarProps extends Omit<ComponentProps<"div">, "children"> {
357
+ /**
358
+ * The vertical position of the floating toolbar.
359
+ */
228
360
  position?: FloatingPosition;
361
+ /**
362
+ * The vertical offset of the floating toolbar from the selection.
363
+ */
229
364
  offset?: number;
365
+ /**
366
+ * The content of the floating toolbar, overriding the default content.
367
+ * Use the `before` and `after` props if you want to keep and extend the default content.
368
+ */
230
369
  children?: ToolbarSlot;
370
+ /**
371
+ * The content to display at the start of the floating toolbar.
372
+ */
231
373
  before?: ToolbarSlot;
374
+ /**
375
+ * The content to display at the end of the floating toolbar.
376
+ */
232
377
  after?: ToolbarSlot;
233
378
  }
379
+ /**
380
+ * A floating toolbar attached to the selection and containing actions and values related to the editor.
381
+ *
382
+ * @example
383
+ * <FloatingToolbar />
384
+ *
385
+ * @example
386
+ * <FloatingToolbar>
387
+ * <Toolbar.BlockSelector />
388
+ * <Toolbar.Separator />
389
+ * <Toolbar.SectionInline />
390
+ * <Toolbar.Separator />
391
+ * <Toolbar.Button name="Custom action" onClick={() => { ... }} icon={<Icon.QuestionMark />} />
392
+ * </FloatingToolbar>
393
+ */
234
394
  declare const FloatingToolbar: react.ForwardRefExoticComponent<Omit<FloatingToolbarProps, "ref"> & react.RefAttributes<HTMLDivElement>> & {
395
+ /**
396
+ * A component that can be wrapped around elements which are rendered outside of the floating
397
+ * toolbar (e.g. portals) to prevent the toolbar from closing when clicking/focusing within them.
398
+ *
399
+ * @example
400
+ * <FloatingToolbar>
401
+ * <Popover.Root>
402
+ * <Popover.Trigger asChild>
403
+ * <Toolbar.Button>Open popover</Toolbar.Button>
404
+ * </Popover.Trigger>
405
+ * <Popover.Portal>
406
+ * <FloatingToolbar.External>
407
+ * <Popover.Content>
408
+ * This popover is rendered outside of the floating toolbar, but the toolbar will not close when clicking/focusing within it.
409
+ * </Popover.Content>
410
+ * </FloatingToolbar.External>
411
+ * </Popover.Portal>
412
+ * </Popover.Root>
413
+ * </FloatingToolbar>
414
+ */
235
415
  External: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
236
416
  };
237
417
 
@@ -247,4 +427,4 @@ interface HistoryVersionPreviewProps extends ComponentPropsWithoutRef<"div"> {
247
427
  */
248
428
  declare const HistoryVersionPreview: react.ForwardRefExoticComponent<HistoryVersionPreviewProps & react.RefAttributes<HTMLDivElement>>;
249
429
 
250
- export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, Toolbar, ToolbarProps, getSelectedBlockElement, isTextFormatActive, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
430
+ export { AnchoredThreads, AnchoredThreadsProps, FloatingComposer, FloatingComposerProps, FloatingThreads, FloatingThreadsProps, FloatingToolbar, FloatingToolbarProps, HistoryVersionPreview, HistoryVersionPreviewProps, LiveblocksPlugin, OPEN_FLOATING_COMPOSER_COMMAND, Toolbar, ToolbarBlockSelectorItem, ToolbarBlockSelectorProps, ToolbarButtonProps, ToolbarProps, ToolbarSeparatorProps, ToolbarToggleProps, getActiveBlockElement, isTextFormatActive, liveblocksConfig, useEditorStatus, useIsEditorReady, useIsThreadActive };
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ 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 getSelectedBlockElement = require('./get-selected-block-element.js');
9
+ var getActiveBlockElement = require('./get-active-block-element.js');
10
10
  var isTextFormatActive = require('./is-text-format-active.js');
11
11
  var liveblocksConfig = require('./liveblocks-config.js');
12
12
  var liveblocksPluginProvider = require('./liveblocks-plugin-provider.js');
@@ -21,7 +21,7 @@ exports.useIsThreadActive = commentPluginProvider.useIsThreadActive;
21
21
  exports.FloatingComposer = floatingComposer.FloatingComposer;
22
22
  exports.OPEN_FLOATING_COMPOSER_COMMAND = floatingComposer.OPEN_FLOATING_COMPOSER_COMMAND;
23
23
  exports.FloatingThreads = floatingThreads.FloatingThreads;
24
- exports.getSelectedBlockElement = getSelectedBlockElement.getSelectedBlockElement;
24
+ exports.getActiveBlockElement = getActiveBlockElement.getActiveBlockElement;
25
25
  exports.isTextFormatActive = isTextFormatActive.isTextFormatActive;
26
26
  exports.liveblocksConfig = liveblocksConfig.liveblocksConfig;
27
27
  exports.LiveblocksPlugin = liveblocksPluginProvider.LiveblocksPlugin;
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 { getSelectedBlockElement } from \"./get-selected-block-element\";\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 { ToolbarProps } 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;;;;;;;;;;;;;;;;;"}
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 { getActiveBlockElement } from \"./get-active-block-element\";\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,7 +4,7 @@ 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 { getSelectedBlockElement } from './get-selected-block-element.mjs';
7
+ export { getActiveBlockElement } from './get-active-block-element.mjs';
8
8
  export { isTextFormatActive } from './is-text-format-active.mjs';
9
9
  export { liveblocksConfig } from './liveblocks-config.mjs';
10
10
  export { LiveblocksPlugin, useEditorStatus, useIsEditorReady } from './liveblocks-plugin-provider.mjs';
@@ -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 { getSelectedBlockElement } from \"./get-selected-block-element\";\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 { ToolbarProps } 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"}
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 { getActiveBlockElement } from \"./get-active-block-element\";\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"}