@payloadcms/richtext-lexical 3.79.0 → 3.79.1

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 (66) hide show
  1. package/dist/exports/client/bundled.css +1 -1
  2. package/dist/exports/client/index.js +22 -22
  3. package/dist/exports/client/index.js.map +4 -4
  4. package/dist/features/converters/lexicalToHtml/async/converters/heading.d.ts.map +1 -1
  5. package/dist/features/converters/lexicalToHtml/async/converters/heading.js +3 -1
  6. package/dist/features/converters/lexicalToHtml/async/converters/heading.js.map +1 -1
  7. package/dist/features/converters/lexicalToHtml/async/converters/link.d.ts.map +1 -1
  8. package/dist/features/converters/lexicalToHtml/async/converters/link.js +7 -2
  9. package/dist/features/converters/lexicalToHtml/async/converters/link.js.map +1 -1
  10. package/dist/features/converters/lexicalToHtml/async/converters/list.d.ts.map +1 -1
  11. package/dist/features/converters/lexicalToHtml/async/converters/list.js +5 -1
  12. package/dist/features/converters/lexicalToHtml/async/converters/list.js.map +1 -1
  13. package/dist/features/converters/lexicalToHtml/async/converters/table.d.ts.map +1 -1
  14. package/dist/features/converters/lexicalToHtml/async/converters/table.js +2 -1
  15. package/dist/features/converters/lexicalToHtml/async/converters/table.js.map +1 -1
  16. package/dist/features/converters/lexicalToHtml/async/converters/text.d.ts.map +1 -1
  17. package/dist/features/converters/lexicalToHtml/async/converters/text.js +2 -1
  18. package/dist/features/converters/lexicalToHtml/async/converters/text.js.map +1 -1
  19. package/dist/features/converters/lexicalToHtml/async/converters/upload.d.ts.map +1 -1
  20. package/dist/features/converters/lexicalToHtml/async/converters/upload.js +11 -10
  21. package/dist/features/converters/lexicalToHtml/async/converters/upload.js.map +1 -1
  22. package/dist/features/converters/lexicalToHtml/shared/cssColors.d.ts +5 -0
  23. package/dist/features/converters/lexicalToHtml/shared/cssColors.d.ts.map +1 -0
  24. package/dist/features/converters/lexicalToHtml/shared/cssColors.js +8 -0
  25. package/dist/features/converters/lexicalToHtml/shared/cssColors.js.map +1 -0
  26. package/dist/features/converters/lexicalToHtml/sync/converters/heading.d.ts.map +1 -1
  27. package/dist/features/converters/lexicalToHtml/sync/converters/heading.js +3 -1
  28. package/dist/features/converters/lexicalToHtml/sync/converters/heading.js.map +1 -1
  29. package/dist/features/converters/lexicalToHtml/sync/converters/link.d.ts.map +1 -1
  30. package/dist/features/converters/lexicalToHtml/sync/converters/link.js +7 -2
  31. package/dist/features/converters/lexicalToHtml/sync/converters/link.js.map +1 -1
  32. package/dist/features/converters/lexicalToHtml/sync/converters/list.d.ts.map +1 -1
  33. package/dist/features/converters/lexicalToHtml/sync/converters/list.js +5 -1
  34. package/dist/features/converters/lexicalToHtml/sync/converters/list.js.map +1 -1
  35. package/dist/features/converters/lexicalToHtml/sync/converters/table.d.ts.map +1 -1
  36. package/dist/features/converters/lexicalToHtml/sync/converters/table.js +2 -1
  37. package/dist/features/converters/lexicalToHtml/sync/converters/table.js.map +1 -1
  38. package/dist/features/converters/lexicalToHtml/sync/converters/text.d.ts.map +1 -1
  39. package/dist/features/converters/lexicalToHtml/sync/converters/text.js +2 -1
  40. package/dist/features/converters/lexicalToHtml/sync/converters/text.js.map +1 -1
  41. package/dist/features/converters/lexicalToHtml/sync/converters/upload.d.ts.map +1 -1
  42. package/dist/features/converters/lexicalToHtml/sync/converters/upload.js +11 -10
  43. package/dist/features/converters/lexicalToHtml/sync/converters/upload.js.map +1 -1
  44. package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
  45. package/dist/features/toolbars/fixed/client/Toolbar/index.js +84 -141
  46. package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
  47. package/dist/features/toolbars/inline/client/Toolbar/index.d.ts.map +1 -1
  48. package/dist/features/toolbars/inline/client/Toolbar/index.js +46 -101
  49. package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
  50. package/dist/features/toolbars/shared/ToolbarButton/index.d.ts +3 -1
  51. package/dist/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
  52. package/dist/features/toolbars/shared/ToolbarButton/index.js +38 -111
  53. package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
  54. package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts +4 -10
  55. package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
  56. package/dist/features/toolbars/shared/ToolbarDropdown/index.js +10 -79
  57. package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
  58. package/dist/features/toolbars/shared/useToolbarStates.d.ts +22 -0
  59. package/dist/features/toolbars/shared/useToolbarStates.d.ts.map +1 -0
  60. package/dist/features/toolbars/shared/useToolbarStates.js +127 -0
  61. package/dist/features/toolbars/shared/useToolbarStates.js.map +1 -0
  62. package/dist/field/Diff/converters/link.d.ts.map +1 -1
  63. package/dist/field/Diff/converters/link.js +7 -2
  64. package/dist/field/Diff/converters/link.js.map +1 -1
  65. package/dist/field/bundled.css +1 -1
  66. package/package.json +6 -6
@@ -6,7 +6,7 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
6
6
  import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
7
7
  import { mergeRegister } from '@lexical/utils';
8
8
  import { $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_LOW, getDOMSelection, SELECTION_CHANGE_COMMAND } from 'lexical';
9
- import { useCallback, useEffect, useRef, useState } from 'react';
9
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
10
  import * as React from 'react';
11
11
  import { createPortal } from 'react-dom';
12
12
  import { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js';
@@ -14,9 +14,12 @@ import { getDOMRangeRect } from '../../../../../lexical/utils/getDOMRangeRect.js
14
14
  import { setFloatingElemPosition } from '../../../../../lexical/utils/setFloatingElemPosition.js';
15
15
  import { ToolbarButton } from '../../../shared/ToolbarButton/index.js';
16
16
  import { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js';
17
+ import { useToolbarStates } from '../../../shared/useToolbarStates.js';
17
18
  function ButtonGroupItem({
19
+ active,
18
20
  anchorElem,
19
21
  editor,
22
+ enabled,
20
23
  item
21
24
  }) {
22
25
  if (item.Component) {
@@ -30,113 +33,53 @@ function ButtonGroupItem({
30
33
  return null;
31
34
  }
32
35
  return /*#__PURE__*/_jsx(ToolbarButton, {
36
+ active: active,
33
37
  editor: editor,
38
+ enabled: enabled,
34
39
  item: item,
35
40
  children: /*#__PURE__*/_jsx(item.ChildComponent, {})
36
41
  }, item.key);
37
42
  }
38
- function ToolbarGroupComponent(t0) {
39
- const $ = _c(19);
40
- const {
41
- anchorElem,
42
- editor,
43
- group,
44
- index
45
- } = t0;
43
+ function ToolbarGroupComponent({
44
+ anchorElem,
45
+ editor,
46
+ group,
47
+ index,
48
+ toolbarStates
49
+ }) {
46
50
  const {
47
51
  editorConfig
48
52
  } = useEditorConfigContext();
49
- const [DropdownIcon, setDropdownIcon] = React.useState();
50
- let t1;
51
- if ($[0] !== group.ChildComponent || $[1] !== group.items || $[2] !== group.type) {
52
- t1 = () => {
53
- if (group?.type === "dropdown" && group.items.length && group.ChildComponent) {
54
- setDropdownIcon(() => group.ChildComponent);
55
- } else {
56
- setDropdownIcon(undefined);
57
- }
58
- };
59
- $[0] = group.ChildComponent;
60
- $[1] = group.items;
61
- $[2] = group.type;
62
- $[3] = t1;
63
- } else {
64
- t1 = $[3];
65
- }
66
- let t2;
67
- if ($[4] !== group) {
68
- t2 = [group];
69
- $[4] = group;
70
- $[5] = t2;
71
- } else {
72
- t2 = $[5];
73
- }
74
- React.useEffect(t1, t2);
75
- let t3;
76
- if ($[6] !== group.ChildComponent || $[7] !== group.items || $[8] !== group.type) {
77
- t3 = t4 => {
78
- const {
79
- activeItems
80
- } = t4;
81
- if (!activeItems.length) {
82
- if (group?.type === "dropdown" && group.items.length && group.ChildComponent) {
83
- setDropdownIcon(() => group.ChildComponent);
84
- } else {
85
- setDropdownIcon(undefined);
86
- }
87
- return;
88
- }
89
- const item = activeItems[0];
90
- setDropdownIcon(() => item?.ChildComponent);
91
- };
92
- $[6] = group.ChildComponent;
93
- $[7] = group.items;
94
- $[8] = group.type;
95
- $[9] = t3;
96
- } else {
97
- t3 = $[9];
98
- }
99
- const onActiveChange = t3;
100
- const t4 = `inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`;
101
- let t5;
102
- if ($[10] !== DropdownIcon || $[11] !== anchorElem || $[12] !== editor || $[13] !== editorConfig.features.toolbarInline?.groups.length || $[14] !== group || $[15] !== index || $[16] !== onActiveChange || $[17] !== t4) {
103
- t5 = _jsxs("div", {
104
- className: t4,
105
- "data-toolbar-group-key": group.key,
106
- children: [group.type === "dropdown" && group.items.length ? DropdownIcon ? _jsx(ToolbarDropdown, {
107
- anchorElem,
108
- editor,
109
- group,
110
- Icon: DropdownIcon,
111
- maxActiveItems: group.maxActiveItems ?? 1,
112
- onActiveChange
113
- }) : _jsx(ToolbarDropdown, {
114
- anchorElem,
115
- editor,
116
- group,
117
- maxActiveItems: group.maxActiveItems ?? 1,
118
- onActiveChange
119
- }) : null, group.type === "buttons" && group.items.length ? group.items.map(item_0 => _jsx(ButtonGroupItem, {
120
- anchorElem,
121
- editor,
122
- item: item_0
123
- }, item_0.key)) : null, index < editorConfig.features.toolbarInline?.groups.length - 1 && _jsx("div", {
124
- className: "divider"
125
- })]
126
- }, group.key);
127
- $[10] = DropdownIcon;
128
- $[11] = anchorElem;
129
- $[12] = editor;
130
- $[13] = editorConfig.features.toolbarInline?.groups.length;
131
- $[14] = group;
132
- $[15] = index;
133
- $[16] = onActiveChange;
134
- $[17] = t4;
135
- $[18] = t5;
136
- } else {
137
- t5 = $[18];
138
- }
139
- return t5;
53
+ const groupState = toolbarStates.groupStates.get(group.key);
54
+ const DropdownIcon = useMemo(() => {
55
+ if (group.type !== 'dropdown') {
56
+ return undefined;
57
+ }
58
+ const activeItem = groupState?.activeItems?.[0];
59
+ return activeItem?.ChildComponent ?? group.ChildComponent;
60
+ }, [group, groupState?.activeItems]);
61
+ return /*#__PURE__*/_jsxs("div", {
62
+ className: `inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`,
63
+ "data-toolbar-group-key": group.key,
64
+ children: [group.type === 'dropdown' && group.items.length && groupState ? /*#__PURE__*/_jsx(ToolbarDropdown, {
65
+ anchorElem: anchorElem,
66
+ editor: editor,
67
+ group: group,
68
+ groupState: groupState,
69
+ Icon: DropdownIcon
70
+ }) : null, group.type === 'buttons' && group.items.length ? group.items.map(item => {
71
+ const itemState = toolbarStates.itemStates.get(item.key);
72
+ return /*#__PURE__*/_jsx(ButtonGroupItem, {
73
+ active: itemState?.active ?? false,
74
+ anchorElem: anchorElem,
75
+ editor: editor,
76
+ enabled: itemState?.enabled ?? true,
77
+ item: item
78
+ }, item.key);
79
+ }) : null, index < editorConfig.features.toolbarInline?.groups.length - 1 && /*#__PURE__*/_jsx("div", {
80
+ className: "divider"
81
+ })]
82
+ }, group.key);
140
83
  }
141
84
  function InlineToolbar({
142
85
  anchorElem,
@@ -147,6 +90,7 @@ function InlineToolbar({
147
90
  const {
148
91
  editorConfig
149
92
  } = useEditorConfigContext();
93
+ const toolbarStates = useToolbarStates(editor, editorConfig?.features?.toolbarInline?.groups);
150
94
  const closeFloatingToolbar = useCallback(() => {
151
95
  if (floatingToolbarRef?.current) {
152
96
  const isOpacityZero = floatingToolbarRef.current.style.opacity === '0';
@@ -273,7 +217,8 @@ function InlineToolbar({
273
217
  anchorElem: anchorElem,
274
218
  editor: editor,
275
219
  group: group,
276
- index: i
220
+ index: i,
221
+ toolbarStates: toolbarStates
277
222
  }, group.key);
278
223
  })]
279
224
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useLexicalEditable","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","getDOMSelection","SELECTION_CHANGE_COMMAND","useCallback","useEffect","useRef","useState","React","createPortal","useEditorConfigContext","getDOMRangeRect","setFloatingElemPosition","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","_jsx","key","ChildComponent","ToolbarGroupComponent","t0","$","group","index","editorConfig","DropdownIcon","setDropdownIcon","t1","items","type","length","undefined","t2","t3","t4","activeItems","onActiveChange","t5","features","toolbarInline","groups","_jsxs","className","children","Icon","maxActiveItems","map","item_0","InlineToolbar","floatingToolbarRef","caretRef","closeFloatingToolbar","current","isOpacityZero","style","opacity","isPointerEventsNone","pointerEvents","mouseMoveListener","e","buttons","x","clientX","y","clientY","elementUnderMouse","document","elementFromPoint","contains","mouseUpListener","addEventListener","removeEventListener","$updateTextFormatFloatingToolbar","selection","nativeSelection","_window","possibleLinkEditor","querySelector","isLinkEditorVisible","rootElement","getRootElement","isCollapsed","anchorNode","rangeRect","offsetIfFlipped","alwaysDisplayOnTop","floatingElem","horizontalPosition","targetRect","anchorFlippedOffset","horizontalOffset","specialHandlingForCaret","verticalGap","scrollerElem","parentElement","update","getEditorState","read","window","registerUpdateListener","editorState","registerCommand","ref","i","useInlineToolbar","isText","setIsText","isEditable","isComposing","getTextContent","nodes","getNodes","foundNodeWithText","node","rawTextContent","replace","updatePopup","registerRootListener","InlineToolbarPlugin"],"sources":["../../../../../../src/features/toolbars/inline/client/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n getDOMSelection,\n SELECTION_CHANGE_COMMAND,\n} from 'lexical'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport type { PluginComponentWithAnchor } from '../../../../typesClient.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../../types.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { getDOMRangeRect } from '../../../../../lexical/utils/getDOMRangeRect.js'\nimport { setFloatingElemPosition } from '../../../../../lexical/utils/setFloatingElemPosition.js'\nimport { ToolbarButton } from '../../../shared/ToolbarButton/index.js'\nimport './index.scss'\nimport { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js'\n\nfunction ButtonGroupItem({\n anchorElem,\n editor,\n item,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n item: ToolbarGroupItem\n}): React.ReactNode {\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n )\n }\n if (!item.ChildComponent) {\n return null\n }\n\n return (\n <ToolbarButton editor={editor} item={item} key={item.key}>\n <item.ChildComponent />\n </ToolbarButton>\n )\n}\n\nfunction ToolbarGroupComponent({\n anchorElem,\n editor,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { editorConfig } = useEditorConfigContext()\n\n const [DropdownIcon, setDropdownIcon] = React.useState<React.FC | undefined>()\n\n React.useEffect(() => {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(undefined)\n }\n }, [group])\n\n const onActiveChange = useCallback(\n ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => {\n if (!activeItems.length) {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(undefined)\n }\n return\n }\n const item = activeItems[0]\n setDropdownIcon(() => item?.ChildComponent)\n },\n [group],\n )\n\n return (\n <div\n className={`inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`}\n data-toolbar-group-key={group.key}\n key={group.key}\n >\n {group.type === 'dropdown' && group.items.length ? (\n DropdownIcon ? (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n Icon={DropdownIcon}\n maxActiveItems={group.maxActiveItems ?? 1}\n onActiveChange={onActiveChange}\n />\n ) : (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n maxActiveItems={group.maxActiveItems ?? 1}\n onActiveChange={onActiveChange}\n />\n )\n ) : null}\n {group.type === 'buttons' && group.items.length\n ? group.items.map((item) => {\n return (\n <ButtonGroupItem anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n })\n : null}\n {index < editorConfig.features.toolbarInline?.groups.length - 1 && (\n <div className=\"divider\" />\n )}\n </div>\n )\n}\n\nfunction InlineToolbar({\n anchorElem,\n editor,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n}): React.ReactNode {\n const floatingToolbarRef = useRef<HTMLDivElement | null>(null)\n const caretRef = useRef<HTMLDivElement | null>(null)\n\n const { editorConfig } = useEditorConfigContext()\n\n const closeFloatingToolbar = useCallback(() => {\n if (floatingToolbarRef?.current) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n\n if (!isOpacityZero) {\n floatingToolbarRef.current.style.opacity = '0'\n }\n if (!isPointerEventsNone) {\n floatingToolbarRef.current.style.pointerEvents = 'none'\n }\n }\n }, [floatingToolbarRef])\n\n const mouseMoveListener = useCallback(\n (e: MouseEvent) => {\n if (floatingToolbarRef?.current && (e.buttons === 1 || e.buttons === 3)) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n if (!isOpacityZero || !isPointerEventsNone) {\n // Check if the mouse is not over the popup\n const x = e.clientX\n const y = e.clientY\n const elementUnderMouse = document.elementFromPoint(x, y)\n if (!floatingToolbarRef.current.contains(elementUnderMouse)) {\n // Mouse is not over the target element => not a normal click, but probably a drag\n closeFloatingToolbar()\n }\n }\n }\n },\n [closeFloatingToolbar],\n )\n\n const mouseUpListener = useCallback(() => {\n if (floatingToolbarRef?.current) {\n if (floatingToolbarRef.current.style.opacity !== '1') {\n floatingToolbarRef.current.style.opacity = '1'\n }\n if (floatingToolbarRef.current.style.pointerEvents !== 'auto') {\n floatingToolbarRef.current.style.pointerEvents = 'auto'\n }\n }\n }, [])\n\n useEffect(() => {\n document.addEventListener('mousemove', mouseMoveListener)\n document.addEventListener('mouseup', mouseUpListener)\n\n return () => {\n document.removeEventListener('mousemove', mouseMoveListener)\n document.removeEventListener('mouseup', mouseUpListener)\n }\n }, [floatingToolbarRef, mouseMoveListener, mouseUpListener])\n\n const $updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection()\n\n const nativeSelection = getDOMSelection(editor._window)\n\n if (floatingToolbarRef.current === null) {\n return\n }\n\n const possibleLinkEditor = anchorElem.querySelector(':scope > .link-editor')\n const isLinkEditorVisible =\n possibleLinkEditor !== null &&\n 'style' in possibleLinkEditor &&\n possibleLinkEditor?.style?.['opacity' as keyof typeof possibleLinkEditor.style] === '1'\n\n const rootElement = editor.getRootElement()\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement)\n\n // Position floating toolbar\n const offsetIfFlipped = setFloatingElemPosition({\n alwaysDisplayOnTop: isLinkEditorVisible,\n anchorElem,\n floatingElem: floatingToolbarRef.current,\n horizontalPosition: 'center',\n targetRect: rangeRect,\n })\n\n // Position caret\n if (caretRef.current) {\n setFloatingElemPosition({\n anchorElem: floatingToolbarRef.current,\n anchorFlippedOffset: offsetIfFlipped,\n floatingElem: caretRef.current,\n horizontalOffset: 5,\n horizontalPosition: 'center',\n specialHandlingForCaret: true,\n targetRect: rangeRect,\n verticalGap: 8,\n })\n }\n } else {\n closeFloatingToolbar()\n }\n }, [editor, closeFloatingToolbar, anchorElem])\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement\n\n const update = () => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }\n\n window.addEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.addEventListener('scroll', update)\n }\n\n return () => {\n window.removeEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.removeEventListener('scroll', update)\n }\n }\n }, [editor, $updateTextFormatFloatingToolbar, anchorElem])\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n $updateTextFormatFloatingToolbar()\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, $updateTextFormatFloatingToolbar])\n\n return (\n <div className=\"inline-toolbar-popup\" ref={floatingToolbarRef}>\n <div className=\"caret\" ref={caretRef} />\n {editorConfig?.features &&\n editorConfig.features?.toolbarInline?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </div>\n )\n}\n\nfunction useInlineToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n): null | React.ReactElement {\n const [isText, setIsText] = useState(false)\n const isEditable = useLexicalEditable()\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return\n }\n const selection = $getSelection()\n const nativeSelection = getDOMSelection(editor._window)\n const rootElement = editor.getRootElement()\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setIsText(false)\n return\n }\n\n if (!$isRangeSelection(selection)) {\n return\n }\n\n if (selection.getTextContent() !== '') {\n const nodes = selection.getNodes()\n let foundNodeWithText = false\n for (const node of nodes) {\n if ($isTextNode(node)) {\n setIsText(true)\n foundNodeWithText = true\n break\n }\n }\n if (!foundNodeWithText) {\n setIsText(false)\n }\n } else {\n setIsText(false)\n }\n\n const rawTextContent = selection.getTextContent().replace(/\\n/g, '')\n if (!selection.isCollapsed() && rawTextContent === '') {\n setIsText(false)\n return\n }\n })\n }, [editor])\n\n useEffect(() => {\n document.addEventListener('selectionchange', updatePopup)\n document.addEventListener('mouseup', updatePopup)\n return () => {\n document.removeEventListener('selectionchange', updatePopup)\n document.removeEventListener('mouseup', updatePopup)\n }\n }, [updatePopup])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup()\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setIsText(false)\n }\n }),\n )\n }, [editor, updatePopup])\n\n if (!isText || !isEditable) {\n return null\n }\n\n return createPortal(<InlineToolbar anchorElem={anchorElem} editor={editor} />, anchorElem)\n}\n\nexport const InlineToolbarPlugin: PluginComponentWithAnchor<undefined> = ({ anchorElem }) => {\n const [editor] = useLexicalComposerContext()\n\n return useInlineToolbar(editor, anchorElem)\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,aAAa,QAAQ;AAC9B,SACEC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,oBAAoB,EACpBC,eAAe,EACfC,wBAAwB,QACnB;AACP,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AACzD,YAAYC,KAAA,MAAW;AACvB,SAASC,YAAY,QAAQ;AAK7B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,eAAe,QAAQ;AAChC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,aAAa,QAAQ;AAE9B,SAASC,eAAe,QAAQ;AAEhC,SAASC,gBAAgB;EACvBC,UAAU;EACVC,MAAM;EACNC;AAAI,CAKL;EACC,IAAIA,IAAA,CAAKC,S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,CAAaW,IAAA,CAAAgC,aAAA;MAAApC,UAAA;MAAAC;IAAA,C,GAA2DD,UAAA;IAAAS,CAAA,MAAAT,UAAA;IAAAS,CAAA,OAAAR,MAAA;IAAAQ,CAAA,OAAAgB,EAAA;EAAA;IAAAA,EAAA,GAAAhB,CAAA;EAAA;EAAA,OAAxEgB,EAAwE;AAAA;AAGjF,OAAO,MAAMiF,mBAAA,GAA4DlG,EAAA;EAAC;IAAAR;EAAA,IAAAQ,EAAc;EACtF,OAAAP,MAAA,IAAiBtB,yBAAA;EAAA,OAEViH,gBAAA,CAAiB3F,MAAA,EAAQD,UAAA;AAAA,CAClC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useLexicalEditable","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","getDOMSelection","SELECTION_CHANGE_COMMAND","useCallback","useEffect","useMemo","useRef","useState","React","createPortal","useEditorConfigContext","getDOMRangeRect","setFloatingElemPosition","ToolbarButton","ToolbarDropdown","useToolbarStates","ButtonGroupItem","active","anchorElem","editor","enabled","item","Component","_jsx","key","ChildComponent","ToolbarGroupComponent","group","index","toolbarStates","editorConfig","groupState","groupStates","get","DropdownIcon","type","undefined","activeItem","activeItems","_jsxs","className","items","length","Icon","map","itemState","itemStates","features","toolbarInline","groups","InlineToolbar","floatingToolbarRef","caretRef","closeFloatingToolbar","current","isOpacityZero","style","opacity","isPointerEventsNone","pointerEvents","mouseMoveListener","e","buttons","x","clientX","y","clientY","elementUnderMouse","document","elementFromPoint","contains","mouseUpListener","addEventListener","removeEventListener","$updateTextFormatFloatingToolbar","selection","nativeSelection","_window","possibleLinkEditor","querySelector","isLinkEditorVisible","rootElement","getRootElement","isCollapsed","anchorNode","rangeRect","offsetIfFlipped","alwaysDisplayOnTop","floatingElem","horizontalPosition","targetRect","anchorFlippedOffset","horizontalOffset","specialHandlingForCaret","verticalGap","scrollerElem","parentElement","update","getEditorState","read","window","registerUpdateListener","editorState","registerCommand","ref","i","useInlineToolbar","$","isText","setIsText","isEditable","t0","isComposing","getTextContent","nodes","getNodes","foundNodeWithText","node","rawTextContent","replace","updatePopup","t1","t2","t3","t4","registerRootListener","t5","InlineToolbarPlugin"],"sources":["../../../../../../src/features/toolbars/inline/client/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\n getDOMSelection,\n SELECTION_CHANGE_COMMAND,\n} from 'lexical'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport * as React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport type { PluginComponentWithAnchor } from '../../../../typesClient.js'\nimport type { ToolbarStates } from '../../../shared/useToolbarStates.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../../types.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { getDOMRangeRect } from '../../../../../lexical/utils/getDOMRangeRect.js'\nimport { setFloatingElemPosition } from '../../../../../lexical/utils/setFloatingElemPosition.js'\nimport { ToolbarButton } from '../../../shared/ToolbarButton/index.js'\nimport { ToolbarDropdown } from '../../../shared/ToolbarDropdown/index.js'\nimport { useToolbarStates } from '../../../shared/useToolbarStates.js'\nimport './index.scss'\n\nfunction ButtonGroupItem({\n active,\n anchorElem,\n editor,\n enabled,\n item,\n}: {\n active: boolean\n anchorElem: HTMLElement\n editor: LexicalEditor\n enabled: boolean\n item: ToolbarGroupItem\n}): React.ReactNode {\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n )\n }\n if (!item.ChildComponent) {\n return null\n }\n\n return (\n <ToolbarButton active={active} editor={editor} enabled={enabled} item={item} key={item.key}>\n <item.ChildComponent />\n </ToolbarButton>\n )\n}\n\nfunction ToolbarGroupComponent({\n anchorElem,\n editor,\n group,\n index,\n toolbarStates,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n group: ToolbarGroup\n index: number\n toolbarStates: ToolbarStates\n}): React.ReactNode {\n const { editorConfig } = useEditorConfigContext()\n\n const groupState = toolbarStates.groupStates.get(group.key)\n\n const DropdownIcon = useMemo(() => {\n if (group.type !== 'dropdown') {\n return undefined\n }\n const activeItem = groupState?.activeItems?.[0]\n return activeItem?.ChildComponent ?? group.ChildComponent\n }, [group, groupState?.activeItems])\n\n return (\n <div\n className={`inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`}\n data-toolbar-group-key={group.key}\n key={group.key}\n >\n {group.type === 'dropdown' && group.items.length && groupState ? (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n groupState={groupState}\n Icon={DropdownIcon}\n />\n ) : null}\n {group.type === 'buttons' && group.items.length\n ? group.items.map((item) => {\n const itemState = toolbarStates.itemStates.get(item.key)\n return (\n <ButtonGroupItem\n active={itemState?.active ?? false}\n anchorElem={anchorElem}\n editor={editor}\n enabled={itemState?.enabled ?? true}\n item={item}\n key={item.key}\n />\n )\n })\n : null}\n {index < editorConfig.features.toolbarInline?.groups.length - 1 && (\n <div className=\"divider\" />\n )}\n </div>\n )\n}\n\nfunction InlineToolbar({\n anchorElem,\n editor,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n}): React.ReactNode {\n const floatingToolbarRef = useRef<HTMLDivElement | null>(null)\n const caretRef = useRef<HTMLDivElement | null>(null)\n\n const { editorConfig } = useEditorConfigContext()\n\n const toolbarStates = useToolbarStates(editor, editorConfig?.features?.toolbarInline?.groups)\n\n const closeFloatingToolbar = useCallback(() => {\n if (floatingToolbarRef?.current) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n\n if (!isOpacityZero) {\n floatingToolbarRef.current.style.opacity = '0'\n }\n if (!isPointerEventsNone) {\n floatingToolbarRef.current.style.pointerEvents = 'none'\n }\n }\n }, [floatingToolbarRef])\n\n const mouseMoveListener = useCallback(\n (e: MouseEvent) => {\n if (floatingToolbarRef?.current && (e.buttons === 1 || e.buttons === 3)) {\n const isOpacityZero = floatingToolbarRef.current.style.opacity === '0'\n const isPointerEventsNone = floatingToolbarRef.current.style.pointerEvents === 'none'\n if (!isOpacityZero || !isPointerEventsNone) {\n // Check if the mouse is not over the popup\n const x = e.clientX\n const y = e.clientY\n const elementUnderMouse = document.elementFromPoint(x, y)\n if (!floatingToolbarRef.current.contains(elementUnderMouse)) {\n // Mouse is not over the target element => not a normal click, but probably a drag\n closeFloatingToolbar()\n }\n }\n }\n },\n [closeFloatingToolbar],\n )\n\n const mouseUpListener = useCallback(() => {\n if (floatingToolbarRef?.current) {\n if (floatingToolbarRef.current.style.opacity !== '1') {\n floatingToolbarRef.current.style.opacity = '1'\n }\n if (floatingToolbarRef.current.style.pointerEvents !== 'auto') {\n floatingToolbarRef.current.style.pointerEvents = 'auto'\n }\n }\n }, [])\n\n useEffect(() => {\n document.addEventListener('mousemove', mouseMoveListener)\n document.addEventListener('mouseup', mouseUpListener)\n\n return () => {\n document.removeEventListener('mousemove', mouseMoveListener)\n document.removeEventListener('mouseup', mouseUpListener)\n }\n }, [floatingToolbarRef, mouseMoveListener, mouseUpListener])\n\n const $updateTextFormatFloatingToolbar = useCallback(() => {\n const selection = $getSelection()\n\n const nativeSelection = getDOMSelection(editor._window)\n\n if (floatingToolbarRef.current === null) {\n return\n }\n\n const possibleLinkEditor = anchorElem.querySelector(':scope > .link-editor')\n const isLinkEditorVisible =\n possibleLinkEditor !== null &&\n 'style' in possibleLinkEditor &&\n possibleLinkEditor?.style?.['opacity' as keyof typeof possibleLinkEditor.style] === '1'\n\n const rootElement = editor.getRootElement()\n if (\n selection !== null &&\n nativeSelection !== null &&\n !nativeSelection.isCollapsed &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n const rangeRect = getDOMRangeRect(nativeSelection, rootElement)\n\n // Position floating toolbar\n const offsetIfFlipped = setFloatingElemPosition({\n alwaysDisplayOnTop: isLinkEditorVisible,\n anchorElem,\n floatingElem: floatingToolbarRef.current,\n horizontalPosition: 'center',\n targetRect: rangeRect,\n })\n\n // Position caret\n if (caretRef.current) {\n setFloatingElemPosition({\n anchorElem: floatingToolbarRef.current,\n anchorFlippedOffset: offsetIfFlipped,\n floatingElem: caretRef.current,\n horizontalOffset: 5,\n horizontalPosition: 'center',\n specialHandlingForCaret: true,\n targetRect: rangeRect,\n verticalGap: 8,\n })\n }\n } else {\n closeFloatingToolbar()\n }\n }, [editor, closeFloatingToolbar, anchorElem])\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement\n\n const update = () => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }\n\n window.addEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.addEventListener('scroll', update)\n }\n\n return () => {\n window.removeEventListener('resize', update)\n if (scrollerElem) {\n scrollerElem.removeEventListener('scroll', update)\n }\n }\n }, [editor, $updateTextFormatFloatingToolbar, anchorElem])\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n $updateTextFormatFloatingToolbar()\n })\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n $updateTextFormatFloatingToolbar()\n })\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n $updateTextFormatFloatingToolbar()\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, $updateTextFormatFloatingToolbar])\n\n return (\n <div className=\"inline-toolbar-popup\" ref={floatingToolbarRef}>\n <div className=\"caret\" ref={caretRef} />\n {editorConfig?.features &&\n editorConfig.features?.toolbarInline?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n group={group}\n index={i}\n key={group.key}\n toolbarStates={toolbarStates}\n />\n )\n })}\n </div>\n )\n}\n\nfunction useInlineToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n): null | React.ReactElement {\n const [isText, setIsText] = useState(false)\n const isEditable = useLexicalEditable()\n\n const updatePopup = useCallback(() => {\n editor.getEditorState().read(() => {\n // Should not to pop up the floating toolbar when using IME input\n if (editor.isComposing()) {\n return\n }\n const selection = $getSelection()\n const nativeSelection = getDOMSelection(editor._window)\n const rootElement = editor.getRootElement()\n\n if (\n nativeSelection !== null &&\n (!$isRangeSelection(selection) ||\n rootElement === null ||\n !rootElement.contains(nativeSelection.anchorNode))\n ) {\n setIsText(false)\n return\n }\n\n if (!$isRangeSelection(selection)) {\n return\n }\n\n if (selection.getTextContent() !== '') {\n const nodes = selection.getNodes()\n let foundNodeWithText = false\n for (const node of nodes) {\n if ($isTextNode(node)) {\n setIsText(true)\n foundNodeWithText = true\n break\n }\n }\n if (!foundNodeWithText) {\n setIsText(false)\n }\n } else {\n setIsText(false)\n }\n\n const rawTextContent = selection.getTextContent().replace(/\\n/g, '')\n if (!selection.isCollapsed() && rawTextContent === '') {\n setIsText(false)\n return\n }\n })\n }, [editor])\n\n useEffect(() => {\n document.addEventListener('selectionchange', updatePopup)\n document.addEventListener('mouseup', updatePopup)\n return () => {\n document.removeEventListener('selectionchange', updatePopup)\n document.removeEventListener('mouseup', updatePopup)\n }\n }, [updatePopup])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updatePopup()\n }),\n editor.registerRootListener(() => {\n if (editor.getRootElement() === null) {\n setIsText(false)\n }\n }),\n )\n }, [editor, updatePopup])\n\n if (!isText || !isEditable) {\n return null\n }\n\n return createPortal(<InlineToolbar anchorElem={anchorElem} editor={editor} />, anchorElem)\n}\n\nexport const InlineToolbarPlugin: PluginComponentWithAnchor<undefined> = ({ anchorElem }) => {\n const [editor] = useLexicalComposerContext()\n\n return useInlineToolbar(editor, anch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,KAAWE,UAAA;IAAA;EAAA;EAAA,IAAAgB,EAAA;EAAA,IAAAnB,CAAA,QAAAzF,UAAA,IAAAyF,CAAA,SAAAxF,MAAA;IAIT2G,EAAA,GAAArH,YAAA,CAAac,IAAA,CAAA2B,aAAA;MAAAhC,UAAA;MAAAC;IAAA,C,GAA2DD,UAAA;IAAAyF,CAAA,MAAAzF,UAAA;IAAAyF,CAAA,OAAAxF,MAAA;IAAAwF,CAAA,OAAAmB,EAAA;EAAA;IAAAA,EAAA,GAAAnB,CAAA;EAAA;EAAA,OAAxEmB,EAAwE;AAAA;AAGjF,OAAO,MAAMC,mBAAA,GAA4DhB,EAAA;EAAC;IAAA7F;EAAA,IAAA6F,EAAc;EACtF,OAAA5F,MAAA,IAAiBzB,yBAAA;EAAA,OAEVgH,gBAAA,CAAiBvF,MAAA,EAAQD,UAAA;AAAA,CAClC","ignoreList":[]}
@@ -2,9 +2,11 @@ import type { LexicalEditor } from 'lexical';
2
2
  import React from 'react';
3
3
  import type { ToolbarGroupItem } from '../../types.js';
4
4
  import './index.scss';
5
- export declare const ToolbarButton: ({ children, editor, item, }: {
5
+ export declare const ToolbarButton: ({ active, children, editor, enabled, item, }: {
6
+ active?: boolean;
6
7
  children: React.JSX.Element;
7
8
  editor: LexicalEditor;
9
+ enabled?: boolean;
8
10
  item: ToolbarGroupItem;
9
11
  }) => React.JSX.Element;
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/toolbars/shared/ToolbarButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAI5C,OAAO,KAAsE,MAAM,OAAO,CAAA;AAE1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,OAAO,cAAc,CAAA;AAKrB,eAAO,MAAM,aAAa,gCAIvB;IACD,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAA;IAC3B,MAAM,EAAE,aAAa,CAAA;IACrB,IAAI,EAAE,gBAAgB,CAAA;CACvB,sBA2FA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/toolbars/shared/ToolbarButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAG5C,OAAO,KAA+B,MAAM,OAAO,CAAA;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,aAAa,iDAMvB;IACD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAA;IAC3B,MAAM,EAAE,aAAa,CAAA;IACrB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,gBAAgB,CAAA;CACvB,sBA+CA,CAAA"}
@@ -2,134 +2,61 @@
2
2
 
3
3
  import { c as _c } from "react/compiler-runtime";
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
- import { mergeRegister } from '@lexical/utils';
6
- import { $addUpdateTag, $getSelection } from 'lexical';
7
- import React, { useCallback, useDeferredValue, useEffect, useMemo, useState } from 'react';
8
- import { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js';
9
- import { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js';
5
+ import { $addUpdateTag } from 'lexical';
6
+ import React, { useCallback, useMemo } from 'react';
10
7
  const baseClass = 'toolbar-popup__button';
11
8
  export const ToolbarButton = t0 => {
12
- const $ = _c(23);
9
+ const $ = _c(14);
13
10
  const {
11
+ active: t1,
14
12
  children,
15
13
  editor,
14
+ enabled: t2,
16
15
  item
17
16
  } = t0;
18
- let t1;
19
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20
- t1 = {
21
- active: false,
22
- enabled: true
23
- };
24
- $[0] = t1;
25
- } else {
26
- t1 = $[0];
27
- }
28
- const [_state, setState] = useState(t1);
29
- const deferredState = useDeferredValue(_state);
30
- const editorConfigContext = useEditorConfigContext();
31
- const t2 = !deferredState.enabled ? "disabled" : "";
32
- const t3 = deferredState.active ? "active" : "";
33
- const t4 = item.key ? `${baseClass}-${item.key}` : "";
34
- let t5;
35
- if ($[1] !== t2 || $[2] !== t3 || $[3] !== t4) {
36
- t5 = [baseClass, t2, t3, t4].filter(Boolean);
37
- $[1] = t2;
38
- $[2] = t3;
39
- $[3] = t4;
40
- $[4] = t5;
41
- } else {
42
- t5 = $[4];
43
- }
44
- const className = t5.join(" ");
17
+ const active = t1 === undefined ? false : t1;
18
+ const enabled = t2 === undefined ? true : t2;
19
+ const t3 = !enabled ? "disabled" : "";
20
+ const t4 = active ? "active" : "";
21
+ const t5 = item.key ? `${baseClass}-${item.key}` : "";
45
22
  let t6;
46
- if ($[5] !== editor || $[6] !== editorConfigContext || $[7] !== item) {
47
- t6 = () => {
48
- editor.getEditorState().read(() => {
49
- const selection = $getSelection();
50
- if (!selection) {
51
- return;
52
- }
53
- const newActive = item.isActive ? item.isActive({
54
- editor,
55
- editorConfigContext,
56
- selection
57
- }) : false;
58
- const newEnabled = item.isEnabled ? item.isEnabled({
59
- editor,
60
- editorConfigContext,
61
- selection
62
- }) : true;
63
- setState(prev => {
64
- if (prev.active === newActive && prev.enabled === newEnabled) {
65
- return prev;
66
- }
67
- return {
68
- active: newActive,
69
- enabled: newEnabled
70
- };
71
- });
72
- });
73
- };
74
- $[5] = editor;
75
- $[6] = editorConfigContext;
76
- $[7] = item;
77
- $[8] = t6;
23
+ if ($[0] !== t3 || $[1] !== t4 || $[2] !== t5) {
24
+ t6 = [baseClass, t3, t4, t5].filter(Boolean);
25
+ $[0] = t3;
26
+ $[1] = t4;
27
+ $[2] = t5;
28
+ $[3] = t6;
78
29
  } else {
79
- t6 = $[8];
30
+ t6 = $[3];
80
31
  }
81
- const updateStates = t6;
82
- const runDeprioritized = useRunDeprioritized();
32
+ const className = t6.join(" ");
83
33
  let t7;
84
- let t8;
85
- if ($[9] !== editor || $[10] !== runDeprioritized || $[11] !== updateStates) {
34
+ if ($[4] !== active || $[5] !== editor || $[6] !== enabled || $[7] !== item) {
86
35
  t7 = () => {
87
- runDeprioritized(updateStates);
88
- const listener = () => runDeprioritized(updateStates);
89
- const cleanup = mergeRegister(editor.registerUpdateListener(listener));
90
- document.addEventListener("mouseup", listener);
91
- return () => {
92
- cleanup();
93
- document.removeEventListener("mouseup", listener);
94
- };
95
- };
96
- t8 = [editor, runDeprioritized, updateStates];
97
- $[9] = editor;
98
- $[10] = runDeprioritized;
99
- $[11] = updateStates;
100
- $[12] = t7;
101
- $[13] = t8;
102
- } else {
103
- t7 = $[12];
104
- t8 = $[13];
105
- }
106
- useEffect(t7, t8);
107
- let t9;
108
- if ($[14] !== _state || $[15] !== editor || $[16] !== item) {
109
- t9 = () => {
110
- if (!_state.enabled) {
36
+ if (!enabled) {
111
37
  return;
112
38
  }
113
39
  editor.focus(() => {
114
40
  editor.update(_temp);
115
41
  item.onSelect?.({
116
42
  editor,
117
- isActive: _state.active
43
+ isActive: active
118
44
  });
119
45
  });
120
46
  };
121
- $[14] = _state;
122
- $[15] = editor;
123
- $[16] = item;
124
- $[17] = t9;
47
+ $[4] = active;
48
+ $[5] = editor;
49
+ $[6] = enabled;
50
+ $[7] = item;
51
+ $[8] = t7;
125
52
  } else {
126
- t9 = $[17];
53
+ t7 = $[8];
127
54
  }
128
- const handleClick = t9;
55
+ const handleClick = t7;
129
56
  const handleMouseDown = _temp2;
130
- let t10;
131
- if ($[18] !== children || $[19] !== className || $[20] !== handleClick || $[21] !== item.key) {
132
- t10 = _jsx("button", {
57
+ let t8;
58
+ if ($[9] !== children || $[10] !== className || $[11] !== handleClick || $[12] !== item.key) {
59
+ t8 = _jsx("button", {
133
60
  className,
134
61
  "data-button-key": item.key,
135
62
  onClick: handleClick,
@@ -137,15 +64,15 @@ export const ToolbarButton = t0 => {
137
64
  type: "button",
138
65
  children
139
66
  });
140
- $[18] = children;
141
- $[19] = className;
142
- $[20] = handleClick;
143
- $[21] = item.key;
144
- $[22] = t10;
67
+ $[9] = children;
68
+ $[10] = className;
69
+ $[11] = handleClick;
70
+ $[12] = item.key;
71
+ $[13] = t8;
145
72
  } else {
146
- t10 = $[22];
73
+ t8 = $[13];
147
74
  }
148
- return t10;
75
+ return t8;
149
76
  };
150
77
  function _temp() {
151
78
  $addUpdateTag("toolbar");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","mergeRegister","$addUpdateTag","$getSelection","React","useCallback","useDeferredValue","useEffect","useMemo","useState","useEditorConfigContext","useRunDeprioritized","baseClass","ToolbarButton","t0","$","children","editor","item","t1","Symbol","for","active","enabled","_state","setState","deferredState","editorConfigContext","t2","t3","t4","key","t5","filter","Boolean","className","join","t6","getEditorState","read","selection","newActive","isActive","newEnabled","isEnabled","prev","updateStates","runDeprioritized","t7","t8","listener","cleanup","registerUpdateListener","document","addEventListener","removeEventListener","t9","focus","update","_temp","onSelect","handleClick","handleMouseDown","_temp2","t10","_jsx","onClick","onMouseDown","type","e","preventDefault"],"sources":["../../../../../src/features/toolbars/shared/ToolbarButton/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { $addUpdateTag, $getSelection } from 'lexical'\nimport React, { useCallback, useDeferredValue, useEffect, useMemo, useState } from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.scss'\nimport { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js'\n\nconst baseClass = 'toolbar-popup__button'\n\nexport const ToolbarButton = ({\n children,\n editor,\n item,\n}: {\n children: React.JSX.Element\n editor: LexicalEditor\n item: ToolbarGroupItem\n}) => {\n const [_state, setState] = useState({ active: false, enabled: true })\n const deferredState = useDeferredValue(_state)\n\n const editorConfigContext = useEditorConfigContext()\n\n const className = useMemo(() => {\n return [\n baseClass,\n !deferredState.enabled ? 'disabled' : '',\n deferredState.active ? 'active' : '',\n item.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }, [deferredState, item.key])\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!selection) {\n return\n }\n const newActive = item.isActive\n ? item.isActive({ editor, editorConfigContext, selection })\n : false\n\n const newEnabled = item.isEnabled\n ? item.isEnabled({ editor, editorConfigContext, selection })\n : true\n\n setState((prev) => {\n if (prev.active === newActive && prev.enabled === newEnabled) {\n return prev\n }\n return { active: newActive, enabled: newEnabled }\n })\n })\n }, [editor, editorConfigContext, item])\n\n const runDeprioritized = useRunDeprioritized()\n\n useEffect(() => {\n // Run on mount\n void runDeprioritized(updateStates)\n\n const listener = () => runDeprioritized(updateStates)\n\n const cleanup = mergeRegister(editor.registerUpdateListener(listener))\n document.addEventListener('mouseup', listener)\n\n return () => {\n cleanup()\n document.removeEventListener('mouseup', listener)\n }\n }, [editor, runDeprioritized, updateStates])\n\n const handleClick = useCallback(() => {\n if (!_state.enabled) {\n return\n }\n\n editor.focus(() => {\n editor.update(() => {\n $addUpdateTag('toolbar')\n })\n // We need to wrap the onSelect in the callback, so the editor is properly focused before the onSelect is called.\n item.onSelect?.({\n editor,\n isActive: _state.active,\n })\n })\n }, [editor, item, _state])\n\n const handleMouseDown = useCallback((e: React.MouseEvent) => {\n // This fixes a bug where you are unable to click the button if you are in a NESTED editor (editor in blocks field in editor).\n // Thus only happens if you click on the SVG of the button. Clicking on the outside works. Related issue: https://github.com/payloadcms/payload/issues/4025\n // TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.\n e.preventDefault()\n }, [])\n\n return (\n <button\n className={className}\n data-button-key={item.key}\n onClick={handleClick}\n onMouseDown={handleMouseDown}\n type=\"button\"\n >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AeK;EAEzB,MAAAM,eAAA,GAAAC,MAAA;EAKK,IAAAC,GAAA;EAAA,IAAAjD,CAAA,SAAAC,QAAA,IAAAD,CAAA,SAAAoB,SAAA,IAAApB,CAAA,SAAA8C,WAAA,IAAA9C,CAAA,SAAAG,IAAA,CAAAa,GAAA;IAGHiC,GAAA,GAAAC,IAAA,CAAC;MAAA9B,SAAA;MAAA,mBAEkBjB,IAAA,CAAAa,GAAA;MAAAmC,OAAA,EACRL,WAAA;MAAAM,WAAA,EACIL,eAAA;MAAAM,IAAA,EACR;MAAApD;IAAA,C;;;;;;;;;SALPgD,G;CAUJ;AAnG6B,SAAAL,MAAA;EAuErBzD,aAAA,CAAc;AAAA;AAvEO,SAAA6D,OAAAM,CAAA;EAqFzBA,CAAA,CAAAC,cAAA,CAAgB;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","$addUpdateTag","React","useCallback","useMemo","baseClass","ToolbarButton","t0","$","active","t1","children","editor","enabled","t2","item","undefined","t3","t4","t5","key","t6","filter","Boolean","className","join","t7","focus","update","_temp","onSelect","isActive","handleClick","handleMouseDown","_temp2","t8","_jsx","onClick","onMouseDown","type","e","preventDefault"],"sources":["../../../../../src/features/toolbars/shared/ToolbarButton/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { $addUpdateTag } from 'lexical'\nimport React, { useCallback, useMemo } from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nimport './index.scss'\n\nconst baseClass = 'toolbar-popup__button'\n\nexport const ToolbarButton = ({\n active = false,\n children,\n editor,\n enabled = true,\n item,\n}: {\n active?: boolean\n children: React.JSX.Element\n editor: LexicalEditor\n enabled?: boolean\n item: ToolbarGroupItem\n}) => {\n const className = useMemo(() => {\n return [\n baseClass,\n !enabled ? 'disabled' : '',\n active ? 'active' : '',\n item.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }, [active, enabled, item.key])\n\n const handleClick = useCallback(() => {\n if (!enabled) {\n return\n }\n\n editor.focus(() => {\n editor.update(() => {\n $addUpdateTag('toolbar')\n })\n // We need to wrap the onSelect in the callback, so the editor is properly focused before the onSelect is called.\n item.onSelect?.({\n editor,\n isActive: active,\n })\n })\n }, [editor, item, active, enabled])\n\n const handleMouseDown = useCallback((e: React.MouseEvent) => {\n // This fixes a bug where you are unable to click the button if you are in a NESTED editor (editor in blocks field in editor).\n // Thus only happens if you click on the SVG of the button. Clicking on the outside works. Related issue: https://github.com/payloadcms/payload/issues/4025\n // TODO: Find out why exactly it happens and why e.preventDefault() on the mouseDown fixes it. Write that down here, or potentially fix a root cause, if there is any.\n e.preventDefault()\n }, [])\n\n return (\n <button\n className={className}\n data-button-key={item.key}\n onClick={handleClick}\n onMouseDown={handleMouseDown}\n type=\"button\"\n >\n {children}\n </button>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,aAAa,QAAQ;AAC9B,OAAOC,KAAA,IAASC,WAAW,EAAEC,OAAO,QAAQ;AAM5C,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,aAAA,GAAgBC,EAAA;EAAA,MAAAC,CAAA,GAAAR,EAAA;EAAC;IAAAS,MAAA,EAAAC,EAAA;IAAAC,QAAA;IAAAC,MAAA;IAAAC,OAAA,EAAAC,EAAA;IAAAC;EAAA,IAAAR,EAY7B;EAXC,MAAAE,MAAA,GAAAC,EAAc,KAAAM,SAAA,WAAdN,EAAc;EAGd,MAAAG,OAAA,GAAAC,EAAc,KAAAE,SAAA,UAAdF,EAAc;EAYV,MAAAG,EAAA,IAACJ,OAAA,GAAU,aAAa;EACxB,MAAAK,EAAA,GAAAT,MAAA,GAAS,WAAW;EACpB,MAAAU,EAAA,GAAAJ,IAAA,CAAAK,GAAA,GAAW,GAAAf,SAAA,IAAgBU,IAAA,CAAAK,GAAA,EAAU,GAAG;EAAA,IAAAC,EAAA;EAAA,IAAAb,CAAA,QAAAS,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A,EACR;MAAA5B;IAAA,C;;;;;;;;;SALPwB,E;CAUJ;AA3D6B,SAAAN,MAAA;EA+BrB5B,aAAA,CAAc;AAAA;AA/BO,SAAAiC,OAAAM,CAAA;EA6CzBA,CAAA,CAAAC,cAAA,CAAgB;AAAA","ignoreList":[]}
@@ -1,22 +1,16 @@
1
1
  import React from 'react';
2
2
  import type { LexicalEditor } from 'lexical';
3
- import type { ToolbarDropdownGroup, ToolbarGroupItem } from '../../types.js';
3
+ import type { ToolbarDropdownGroup } from '../../types.js';
4
+ import type { ToolbarGroupState } from '../useToolbarStates.js';
4
5
  import './index.scss';
5
- export declare const ToolbarDropdown: ({ anchorElem, classNames, editor, group, Icon, itemsContainerClassNames, label, maxActiveItems, onActiveChange, }: {
6
+ export declare const ToolbarDropdown: ({ anchorElem, classNames, editor, group, groupState, Icon, itemsContainerClassNames, label, }: {
6
7
  anchorElem: HTMLElement;
7
8
  classNames?: string[];
8
9
  editor: LexicalEditor;
9
10
  group: ToolbarDropdownGroup;
11
+ groupState: ToolbarGroupState;
10
12
  Icon?: React.FC;
11
13
  itemsContainerClassNames?: string[];
12
14
  label?: string;
13
- /**
14
- * Maximum number of active items allowed. This is a performance optimization to prevent
15
- * unnecessary item active checks when the maximum number of active items is reached.
16
- */
17
- maxActiveItems?: number;
18
- onActiveChange?: ({ activeItems }: {
19
- activeItems: ToolbarGroupItem[];
20
- }) => void;
21
15
  }) => React.JSX.Element;
22
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAIhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAI5E,OAAO,cAAc,CAAA;AAqErB,eAAO,MAAM,eAAe,sHAUzB;IACD,UAAU,EAAE,WAAW,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;IAC3B,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;IACf,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,gBAAgB,EAAE,CAAA;KAAE,KAAK,IAAI,CAAA;CAChF,sBAsGA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAI5C,OAAO,KAAK,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAA;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/D,OAAO,cAAc,CAAA;AAoErB,eAAO,MAAM,eAAe,kGASzB;IACD,UAAU,EAAE,WAAW,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;IAC3B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;IACf,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,sBAkCA,CAAA"}