@payloadcms/richtext-lexical 3.0.0-beta.24 → 3.0.0-beta.25

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 (230) hide show
  1. package/dist/exports/components.d.ts +3 -2
  2. package/dist/exports/components.d.ts.map +1 -1
  3. package/dist/exports/components.js +3 -2
  4. package/dist/exports/components.js.map +1 -1
  5. package/dist/field/features/align/feature.client.d.ts.map +1 -1
  6. package/dist/field/features/align/feature.client.js +126 -46
  7. package/dist/field/features/align/feature.client.js.map +1 -1
  8. package/dist/field/features/align/toolbarAlignGroup.d.ts +3 -0
  9. package/dist/field/features/align/toolbarAlignGroup.d.ts.map +1 -0
  10. package/dist/field/features/align/{inlineToolbarAlignGroup.js → toolbarAlignGroup.js} +3 -3
  11. package/dist/field/features/align/toolbarAlignGroup.js.map +1 -0
  12. package/dist/field/features/blockquote/feature.client.d.ts.map +1 -1
  13. package/dist/field/features/blockquote/feature.client.js +37 -23
  14. package/dist/field/features/blockquote/feature.client.js.map +1 -1
  15. package/dist/field/features/blocks/component/index.d.ts.map +1 -1
  16. package/dist/field/features/blocks/component/index.js +1 -1
  17. package/dist/field/features/blocks/component/index.js.map +1 -1
  18. package/dist/field/features/blocks/feature.client.d.ts.map +1 -1
  19. package/dist/field/features/blocks/feature.client.js +39 -8
  20. package/dist/field/features/blocks/feature.client.js.map +1 -1
  21. package/dist/field/features/blocks/populationPromise.d.ts.map +1 -1
  22. package/dist/field/features/blocks/populationPromise.js +2 -1
  23. package/dist/field/features/blocks/populationPromise.js.map +1 -1
  24. package/dist/field/features/format/bold/feature.client.d.ts.map +1 -1
  25. package/dist/field/features/format/bold/feature.client.js +23 -19
  26. package/dist/field/features/format/bold/feature.client.js.map +1 -1
  27. package/dist/field/features/format/inlineCode/feature.client.d.ts.map +1 -1
  28. package/dist/field/features/format/inlineCode/feature.client.js +23 -19
  29. package/dist/field/features/format/inlineCode/feature.client.js.map +1 -1
  30. package/dist/field/features/format/italic/feature.client.d.ts.map +1 -1
  31. package/dist/field/features/format/italic/feature.client.js +23 -19
  32. package/dist/field/features/format/italic/feature.client.js.map +1 -1
  33. package/dist/field/features/format/shared/toolbarFormatGroup.d.ts +3 -0
  34. package/dist/field/features/format/shared/toolbarFormatGroup.d.ts.map +1 -0
  35. package/dist/field/features/format/shared/toolbarFormatGroup.js +10 -0
  36. package/dist/field/features/format/shared/toolbarFormatGroup.js.map +1 -0
  37. package/dist/field/features/format/strikethrough/feature.client.d.ts.map +1 -1
  38. package/dist/field/features/format/strikethrough/feature.client.js +23 -19
  39. package/dist/field/features/format/strikethrough/feature.client.js.map +1 -1
  40. package/dist/field/features/format/subscript/feature.client.d.ts.map +1 -1
  41. package/dist/field/features/format/subscript/feature.client.js +23 -19
  42. package/dist/field/features/format/subscript/feature.client.js.map +1 -1
  43. package/dist/field/features/format/superscript/feature.client.d.ts.map +1 -1
  44. package/dist/field/features/format/superscript/feature.client.js +23 -19
  45. package/dist/field/features/format/superscript/feature.client.js.map +1 -1
  46. package/dist/field/features/format/underline/feature.client.d.ts.map +1 -1
  47. package/dist/field/features/format/underline/feature.client.js +23 -19
  48. package/dist/field/features/format/underline/feature.client.js.map +1 -1
  49. package/dist/field/features/heading/feature.client.d.ts.map +1 -1
  50. package/dist/field/features/heading/feature.client.js +49 -29
  51. package/dist/field/features/heading/feature.client.js.map +1 -1
  52. package/dist/field/features/horizontalRule/feature.client.d.ts.map +1 -1
  53. package/dist/field/features/horizontalRule/feature.client.js +27 -4
  54. package/dist/field/features/horizontalRule/feature.client.js.map +1 -1
  55. package/dist/field/features/indent/feature.client.d.ts.map +1 -1
  56. package/dist/field/features/indent/feature.client.js +41 -37
  57. package/dist/field/features/indent/feature.client.js.map +1 -1
  58. package/dist/field/features/indent/toolbarIndentGroup.d.ts +3 -0
  59. package/dist/field/features/indent/toolbarIndentGroup.d.ts.map +1 -0
  60. package/dist/field/features/indent/toolbarIndentGroup.js +10 -0
  61. package/dist/field/features/indent/toolbarIndentGroup.js.map +1 -0
  62. package/dist/field/features/link/feature.client.d.ts.map +1 -1
  63. package/dist/field/features/link/feature.client.js +44 -40
  64. package/dist/field/features/link/feature.client.js.map +1 -1
  65. package/dist/field/features/link/populationPromise.d.ts.map +1 -1
  66. package/dist/field/features/link/populationPromise.js +2 -1
  67. package/dist/field/features/link/populationPromise.js.map +1 -1
  68. package/dist/field/features/lists/checklist/feature.client.d.ts.map +1 -1
  69. package/dist/field/features/lists/checklist/feature.client.js +44 -19
  70. package/dist/field/features/lists/checklist/feature.client.js.map +1 -1
  71. package/dist/field/features/lists/orderedList/feature.client.d.ts.map +1 -1
  72. package/dist/field/features/lists/orderedList/feature.client.js +44 -19
  73. package/dist/field/features/lists/orderedList/feature.client.js.map +1 -1
  74. package/dist/field/features/lists/unorderedList/feature.client.d.ts.map +1 -1
  75. package/dist/field/features/lists/unorderedList/feature.client.js +44 -19
  76. package/dist/field/features/lists/unorderedList/feature.client.js.map +1 -1
  77. package/dist/field/features/paragraph/feature.client.d.ts.map +1 -1
  78. package/dist/field/features/paragraph/feature.client.js +36 -22
  79. package/dist/field/features/paragraph/feature.client.js.map +1 -1
  80. package/dist/field/features/relationship/feature.client.d.ts.map +1 -1
  81. package/dist/field/features/relationship/feature.client.js +30 -4
  82. package/dist/field/features/relationship/feature.client.js.map +1 -1
  83. package/dist/field/features/relationship/populationPromise.d.ts.map +1 -1
  84. package/dist/field/features/relationship/populationPromise.js +2 -1
  85. package/dist/field/features/relationship/populationPromise.js.map +1 -1
  86. package/dist/field/features/shared/toolbar/addDropdownGroup.d.ts +3 -0
  87. package/dist/field/features/shared/toolbar/addDropdownGroup.d.ts.map +1 -0
  88. package/dist/field/features/shared/toolbar/addDropdownGroup.js +12 -0
  89. package/dist/field/features/shared/toolbar/addDropdownGroup.js.map +1 -0
  90. package/dist/field/features/shared/toolbar/featureButtonsGroup.d.ts +3 -0
  91. package/dist/field/features/shared/toolbar/featureButtonsGroup.d.ts.map +1 -0
  92. package/dist/field/features/shared/toolbar/featureButtonsGroup.js +10 -0
  93. package/dist/field/features/shared/toolbar/featureButtonsGroup.js.map +1 -0
  94. package/dist/field/features/shared/toolbar/textDropdownGroup.d.ts +3 -0
  95. package/dist/field/features/shared/toolbar/textDropdownGroup.d.ts.map +1 -0
  96. package/dist/field/features/shared/{inlineToolbar → toolbar}/textDropdownGroup.js +2 -2
  97. package/dist/field/features/shared/toolbar/textDropdownGroup.js.map +1 -0
  98. package/dist/field/features/toolbars/fixed/Toolbar/index.d.ts +6 -0
  99. package/dist/field/features/toolbars/fixed/Toolbar/index.d.ts.map +1 -0
  100. package/dist/field/features/toolbars/fixed/Toolbar/index.js +152 -0
  101. package/dist/field/features/toolbars/fixed/Toolbar/index.js.map +1 -0
  102. package/dist/field/features/toolbars/fixed/Toolbar/index.scss +81 -0
  103. package/dist/field/features/toolbars/fixed/feature.client.d.ts +3 -0
  104. package/dist/field/features/toolbars/fixed/feature.client.d.ts.map +1 -0
  105. package/dist/field/features/toolbars/fixed/feature.client.js +20 -0
  106. package/dist/field/features/toolbars/fixed/feature.client.js.map +1 -0
  107. package/dist/field/features/toolbars/fixed/feature.server.d.ts +3 -0
  108. package/dist/field/features/toolbars/fixed/feature.server.d.ts.map +1 -0
  109. package/dist/field/features/toolbars/fixed/feature.server.js +16 -0
  110. package/dist/field/features/toolbars/fixed/feature.server.js.map +1 -0
  111. package/dist/field/features/toolbars/inline/Toolbar/index.d.ts +6 -0
  112. package/dist/field/features/toolbars/inline/Toolbar/index.d.ts.map +1 -0
  113. package/dist/field/{lexical/plugins → features}/toolbars/inline/Toolbar/index.js +43 -17
  114. package/dist/field/features/toolbars/inline/Toolbar/index.js.map +1 -0
  115. package/dist/field/{lexical/plugins → features}/toolbars/inline/Toolbar/index.scss +3 -8
  116. package/dist/field/features/toolbars/inline/feature.client.d.ts +3 -0
  117. package/dist/field/features/toolbars/inline/feature.client.d.ts.map +1 -0
  118. package/dist/field/features/toolbars/inline/feature.client.js +20 -0
  119. package/dist/field/features/toolbars/inline/feature.client.js.map +1 -0
  120. package/dist/field/features/toolbars/inline/feature.server.d.ts +3 -0
  121. package/dist/field/features/toolbars/inline/feature.server.d.ts.map +1 -0
  122. package/dist/field/features/toolbars/inline/feature.server.js +16 -0
  123. package/dist/field/features/toolbars/inline/feature.server.js.map +1 -0
  124. package/dist/field/features/toolbars/shared/ToolbarButton/index.d.ts +10 -0
  125. package/dist/field/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -0
  126. package/dist/field/{lexical/plugins/toolbars/inline → features/toolbars/shared}/ToolbarButton/index.js +9 -5
  127. package/dist/field/features/toolbars/shared/ToolbarButton/index.js.map +1 -0
  128. package/dist/field/{lexical/plugins/toolbars/inline → features/toolbars/shared}/ToolbarButton/index.scss +3 -1
  129. package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.d.ts +23 -0
  130. package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.d.ts.map +1 -0
  131. package/dist/field/{lexical/plugins/toolbars/inline → features/toolbars/shared}/ToolbarDropdown/DropDown.js +14 -64
  132. package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -0
  133. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.d.ts +23 -0
  134. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -0
  135. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.js +139 -0
  136. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -0
  137. package/dist/field/{lexical/plugins/toolbars/inline → features/toolbars/shared}/ToolbarDropdown/index.scss +25 -13
  138. package/dist/field/{lexical/plugins/toolbars/inline → features/toolbars}/types.d.ts +16 -8
  139. package/dist/field/features/toolbars/types.d.ts.map +1 -0
  140. package/dist/field/features/toolbars/types.js.map +1 -0
  141. package/dist/field/features/types.d.ts +7 -7
  142. package/dist/field/features/types.d.ts.map +1 -1
  143. package/dist/field/features/types.js.map +1 -1
  144. package/dist/field/features/upload/feature.client.d.ts.map +1 -1
  145. package/dist/field/features/upload/feature.client.js +29 -4
  146. package/dist/field/features/upload/feature.client.js.map +1 -1
  147. package/dist/field/features/upload/populationPromise.d.ts.map +1 -1
  148. package/dist/field/features/upload/populationPromise.js +3 -1
  149. package/dist/field/features/upload/populationPromise.js.map +1 -1
  150. package/dist/field/lexical/EditorFocusProvider.d.ts +20 -0
  151. package/dist/field/lexical/EditorFocusProvider.d.ts.map +1 -0
  152. package/dist/field/lexical/EditorFocusProvider.js +78 -0
  153. package/dist/field/lexical/EditorFocusProvider.js.map +1 -0
  154. package/dist/field/lexical/LexicalEditor.d.ts.map +1 -1
  155. package/dist/field/lexical/LexicalEditor.js +20 -4
  156. package/dist/field/lexical/LexicalEditor.js.map +1 -1
  157. package/dist/field/lexical/LexicalProvider.d.ts.map +1 -1
  158. package/dist/field/lexical/LexicalProvider.js +3 -2
  159. package/dist/field/lexical/LexicalProvider.js.map +1 -1
  160. package/dist/field/lexical/config/client/EditorConfigProvider.d.ts +2 -3
  161. package/dist/field/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
  162. package/dist/field/lexical/config/client/EditorConfigProvider.js.map +1 -1
  163. package/dist/field/lexical/config/server/default.d.ts.map +1 -1
  164. package/dist/field/lexical/config/server/default.js +3 -1
  165. package/dist/field/lexical/config/server/default.js.map +1 -1
  166. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts +6 -6
  167. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts.map +1 -1
  168. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js.map +1 -1
  169. package/dist/field/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
  170. package/dist/field/lexical/plugins/SlashMenu/index.js +10 -10
  171. package/dist/field/lexical/plugins/SlashMenu/index.js.map +1 -1
  172. package/dist/field/lexical/ui/icons/Add/index.d.ts +3 -0
  173. package/dist/field/lexical/ui/icons/Add/index.d.ts.map +1 -0
  174. package/dist/field/lexical/ui/icons/Add/index.js +16 -0
  175. package/dist/field/lexical/ui/icons/Add/index.js.map +1 -0
  176. package/dist/index.d.ts +8 -5
  177. package/dist/index.d.ts.map +1 -1
  178. package/dist/index.js +8 -4
  179. package/dist/index.js.map +1 -1
  180. package/dist/populate/populate.d.ts +2 -1
  181. package/dist/populate/populate.d.ts.map +1 -1
  182. package/dist/populate/populate.js +13 -11
  183. package/dist/populate/populate.js.map +1 -1
  184. package/dist/populate/populateLexicalPopulationPromises.d.ts +1 -1
  185. package/dist/populate/populateLexicalPopulationPromises.d.ts.map +1 -1
  186. package/dist/populate/populateLexicalPopulationPromises.js +2 -1
  187. package/dist/populate/populateLexicalPopulationPromises.js.map +1 -1
  188. package/dist/populate/recurseNestedFields.d.ts +2 -1
  189. package/dist/populate/recurseNestedFields.d.ts.map +1 -1
  190. package/dist/populate/recurseNestedFields.js +2 -1
  191. package/dist/populate/recurseNestedFields.js.map +1 -1
  192. package/package.json +10 -10
  193. package/dist/field/features/align/inlineToolbarAlignGroup.d.ts +0 -3
  194. package/dist/field/features/align/inlineToolbarAlignGroup.d.ts.map +0 -1
  195. package/dist/field/features/align/inlineToolbarAlignGroup.js.map +0 -1
  196. package/dist/field/features/format/shared/inlineToolbarFormatGroup.d.ts +0 -3
  197. package/dist/field/features/format/shared/inlineToolbarFormatGroup.d.ts.map +0 -1
  198. package/dist/field/features/format/shared/inlineToolbarFormatGroup.js +0 -10
  199. package/dist/field/features/format/shared/inlineToolbarFormatGroup.js.map +0 -1
  200. package/dist/field/features/indent/inlineToolbarIndentGroup.d.ts +0 -3
  201. package/dist/field/features/indent/inlineToolbarIndentGroup.d.ts.map +0 -1
  202. package/dist/field/features/indent/inlineToolbarIndentGroup.js +0 -10
  203. package/dist/field/features/indent/inlineToolbarIndentGroup.js.map +0 -1
  204. package/dist/field/features/shared/inlineToolbar/featureButtonsGroup.d.ts +0 -3
  205. package/dist/field/features/shared/inlineToolbar/featureButtonsGroup.d.ts.map +0 -1
  206. package/dist/field/features/shared/inlineToolbar/featureButtonsGroup.js +0 -10
  207. package/dist/field/features/shared/inlineToolbar/featureButtonsGroup.js.map +0 -1
  208. package/dist/field/features/shared/inlineToolbar/textDropdownGroup.d.ts +0 -3
  209. package/dist/field/features/shared/inlineToolbar/textDropdownGroup.d.ts.map +0 -1
  210. package/dist/field/features/shared/inlineToolbar/textDropdownGroup.js.map +0 -1
  211. package/dist/field/lexical/plugins/toolbars/fixed/types.d.ts +0 -40
  212. package/dist/field/lexical/plugins/toolbars/fixed/types.d.ts.map +0 -1
  213. package/dist/field/lexical/plugins/toolbars/fixed/types.js.map +0 -1
  214. package/dist/field/lexical/plugins/toolbars/inline/Toolbar/index.d.ts +0 -6
  215. package/dist/field/lexical/plugins/toolbars/inline/Toolbar/index.d.ts.map +0 -1
  216. package/dist/field/lexical/plugins/toolbars/inline/Toolbar/index.js.map +0 -1
  217. package/dist/field/lexical/plugins/toolbars/inline/ToolbarButton/index.d.ts +0 -8
  218. package/dist/field/lexical/plugins/toolbars/inline/ToolbarButton/index.d.ts.map +0 -1
  219. package/dist/field/lexical/plugins/toolbars/inline/ToolbarButton/index.js.map +0 -1
  220. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/DropDown.d.ts +0 -17
  221. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/DropDown.d.ts.map +0 -1
  222. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/DropDown.js.map +0 -1
  223. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/index.d.ts +0 -18
  224. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/index.d.ts.map +0 -1
  225. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/index.js +0 -42
  226. package/dist/field/lexical/plugins/toolbars/inline/ToolbarDropdown/index.js.map +0 -1
  227. package/dist/field/lexical/plugins/toolbars/inline/types.d.ts.map +0 -1
  228. package/dist/field/lexical/plugins/toolbars/inline/types.js +0 -3
  229. package/dist/field/lexical/plugins/toolbars/inline/types.js.map +0 -1
  230. /package/dist/field/{lexical/plugins/toolbars/fixed → features/toolbars}/types.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/field/features/toolbars/inline/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { mergeRegister } from '@lexical/utils'\nimport {\n $getSelection,\n $isRangeSelection,\n $isTextNode,\n COMMAND_PRIORITY_LOW,\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 { 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 './index.scss'\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\n return (\n <ToolbarButton editor={editor} item={item} key={item.key}>\n {item?.ChildComponent && <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 | null>(null)\n\n React.useEffect(() => {\n if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {\n setDropdownIcon(() => group.ChildComponent)\n } else {\n setDropdownIcon(null)\n }\n }, [group])\n\n const onActiveChange = ({ 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(null)\n }\n return\n }\n const item = activeItems[0]\n setDropdownIcon(() => item.ChildComponent)\n }\n\n return (\n <div\n className={`inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`}\n key={group.key}\n >\n {group.type === 'dropdown' &&\n group.items.length &&\n (DropdownIcon ? (\n <ToolbarDropdown\n Icon={DropdownIcon}\n anchorElem={anchorElem}\n editor={editor}\n groupKey={group.key}\n items={group.items}\n maxActiveItems={1}\n onActiveChange={onActiveChange}\n />\n ) : (\n <ToolbarDropdown\n anchorElem={anchorElem}\n editor={editor}\n groupKey={group.key}\n items={group.items}\n maxActiveItems={1}\n onActiveChange={onActiveChange}\n />\n ))}\n {group.type === 'buttons' &&\n group.items.length &&\n group.items.map((item) => {\n return (\n <ButtonGroupItem anchorElem={anchorElem} editor={editor} item={item} key={item.key} />\n )\n })}\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 }, [floatingToolbarRef])\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 = window.getSelection()\n\n if (floatingToolbarRef.current === null) {\n return\n }\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 rangeRect, // selection to position around\n floatingToolbarRef.current, // what to position\n anchorElem, // anchor elem\n 'center',\n )\n\n // Position caret\n if (caretRef.current) {\n setFloatingElemPosition(\n rangeRect, // selection to position around\n caretRef.current, // what to position\n floatingToolbarRef.current, // anchor elem\n 'center',\n 10,\n 5,\n true,\n offsetIfFlipped,\n )\n }\n }\n }, [editor, 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 {editor.isEditable() && (\n <React.Fragment>\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 </React.Fragment>\n )}\n </div>\n )\n}\n\nfunction useInlineToolbar(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n): React.ReactElement | null {\n const [isText, setIsText] = useState(false)\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 = window.getSelection()\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) {\n return null\n }\n\n return createPortal(<InlineToolbar anchorElem={anchorElem} editor={editor} />, anchorElem)\n}\n\nexport function InlineToolbarPlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): React.ReactElement | null {\n const [editor] = useLexicalComposerContext()\n\n return useInlineToolbar(editor, anchorElem)\n}\n"],"names":["useLexicalComposerContext","mergeRegister","$getSelection","$isRangeSelection","$isTextNode","COMMAND_PRIORITY_LOW","SELECTION_CHANGE_COMMAND","useCallback","useEffect","useRef","useState","React","createPortal","useEditorConfigContext","getDOMRangeRect","setFloatingElemPosition","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","key","ChildComponent","ToolbarGroupComponent","group","index","editorConfig","DropdownIcon","setDropdownIcon","type","items","length","onActiveChange","activeItems","div","className","Icon","groupKey","maxActiveItems","map","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","getSelection","rootElement","getRootElement","isCollapsed","anchorNode","rangeRect","offsetIfFlipped","scrollerElem","parentElement","update","getEditorState","read","registerUpdateListener","editorState","registerCommand","ref","isEditable","Fragment","i","useInlineToolbar","isText","setIsText","updatePopup","isComposing","getTextContent","nodes","getNodes","foundNodeWithText","node","rawTextContent","replace","registerRootListener","InlineToolbarPlugin","body"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,SACEC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,oBAAoB,EACpBC,wBAAwB,QACnB,UAAS;AAChB,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAChE,YAAYC,WAAW,QAAO;AAC9B,SAASC,YAAY,QAAQ,YAAW;AAIxC,SAASC,sBAAsB,QAAQ,4DAA2D;AAClG,SAASC,eAAe,QAAQ,+CAA8C;AAC9E,SAASC,uBAAuB,QAAQ,uDAAsD;AAC9F,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,eAAe,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;YACF;QACF;IACF,GAAG;QAAC1E;KAAO;IAEXZ,UAAU;QACRuD,SAASI,gBAAgB,CAAC,mBAAmB4B;QAC7ChC,SAASI,gBAAgB,CAAC,WAAW4B;QACrC,OAAO;YACLhC,SAASK,mBAAmB,CAAC,mBAAmB2B;YAChDhC,SAASK,mBAAmB,CAAC,WAAW2B;QAC1C;IACF,GAAG;QAACA;KAAY;IAEhBvF,UAAU;QACR,OAAOP,cACLmB,OAAOiE,sBAAsB,CAAC;YAC5BU;QACF,IACA3E,OAAOoF,oBAAoB,CAAC;YAC1B,IAAIpF,OAAOuD,cAAc,OAAO,MAAM;gBACpCmB,UAAU;YACZ;QACF;IAEJ,GAAG;QAAC1E;QAAQ2E;KAAY;IAExB,IAAI,CAACF,QAAQ;QACX,OAAO;IACT;IAEA,qBAAOjF,2BAAa,oBAACiC;QAAc1B,YAAYA;QAAYC,QAAQA;QAAYD;AACjF;AAEA,OAAO,SAASsF,oBAAoB,EAClCtF,aAAa4C,SAAS2C,IAAI,EAG3B;IACC,MAAM,CAACtF,OAAO,GAAGpB;IAEjB,OAAO4F,iBAAiBxE,QAAQD;AAClC"}
@@ -1,4 +1,4 @@
1
- @import '../../../../../../scss/styles';
1
+ @import '../../../../../scss/styles';
2
2
 
3
3
  html[data-theme='light'] {
4
4
  .inline-toolbar-popup {
@@ -10,12 +10,12 @@ html[data-theme='light'] {
10
10
  display: flex;
11
11
  align-items: center;
12
12
  background: var(--color-base-0);
13
- padding: 0px 3.72px 0px 6.25px;
13
+ padding: 0 3.72px 0 6.25px;
14
14
  vertical-align: middle;
15
15
  position: absolute;
16
16
  top: 0;
17
17
  left: 0;
18
- z-index: 10;
18
+ z-index: 1;
19
19
  opacity: 0;
20
20
  border-radius: 6.25px;
21
21
  transition: opacity 0.2s;
@@ -50,9 +50,4 @@ html[data-theme='light'] {
50
50
  }
51
51
  }
52
52
 
53
- @media (max-width: 1024px) {
54
- button.insert-comment {
55
- display: none;
56
- }
57
- }
58
53
  }
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ export declare const InlineToolbarFeatureClientComponent: import("react").FC<undefined>;
3
+ //# sourceMappingURL=feature.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.client.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/toolbars/inline/feature.client.tsx"],"names":[],"mappings":";AAsBA,eAAO,MAAM,mCAAmC,+BAAoD,CAAA"}
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+ import { createClientComponent } from '../../createClientComponent.js';
3
+ import { InlineToolbarPlugin } from './Toolbar/index.js';
4
+ const InlineToolbarFeatureClient = (props)=>{
5
+ return {
6
+ clientFeatureProps: props,
7
+ feature: ()=>({
8
+ clientFeatureProps: props,
9
+ plugins: [
10
+ {
11
+ Component: InlineToolbarPlugin,
12
+ position: 'floatingAnchorElem'
13
+ }
14
+ ]
15
+ })
16
+ };
17
+ };
18
+ export const InlineToolbarFeatureClientComponent = createClientComponent(InlineToolbarFeatureClient);
19
+
20
+ //# sourceMappingURL=feature.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/field/features/toolbars/inline/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport type { FeatureProviderProviderClient } from '../../types.js'\n\nimport { createClientComponent } from '../../createClientComponent.js'\nimport { InlineToolbarPlugin } from './Toolbar/index.js'\n\nconst InlineToolbarFeatureClient: FeatureProviderProviderClient<undefined> = (props) => {\n return {\n clientFeatureProps: props,\n feature: () => ({\n clientFeatureProps: props,\n plugins: [\n {\n Component: InlineToolbarPlugin,\n position: 'floatingAnchorElem',\n },\n ],\n }),\n }\n}\n\nexport const InlineToolbarFeatureClientComponent = createClientComponent(InlineToolbarFeatureClient)\n"],"names":["createClientComponent","InlineToolbarPlugin","InlineToolbarFeatureClient","props","clientFeatureProps","feature","plugins","Component","position","InlineToolbarFeatureClientComponent"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,qBAAqB,QAAQ,iCAAgC;AACtE,SAASC,mBAAmB,QAAQ,qBAAoB;AAExD,MAAMC,6BAAuE,CAACC;IAC5E,OAAO;QACLC,oBAAoBD;QACpBE,SAAS,IAAO,CAAA;gBACdD,oBAAoBD;gBACpBG,SAAS;oBACP;wBACEC,WAAWN;wBACXO,UAAU;oBACZ;iBACD;YACH,CAAA;IACF;AACF;AAEA,OAAO,MAAMC,sCAAsCT,sBAAsBE,4BAA2B"}
@@ -0,0 +1,3 @@
1
+ import type { FeatureProviderProviderServer } from '../../types.js';
2
+ export declare const InlineToolbarFeature: FeatureProviderProviderServer<undefined, undefined>;
3
+ //# sourceMappingURL=feature.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/toolbars/inline/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AAInE,eAAO,MAAM,oBAAoB,EAAE,6BAA6B,CAAC,SAAS,EAAE,SAAS,CAcpF,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { InlineToolbarFeatureClientComponent } from './feature.client.js';
2
+ export const InlineToolbarFeature = (props)=>{
3
+ return {
4
+ feature: ()=>{
5
+ return {
6
+ ClientComponent: InlineToolbarFeatureClientComponent,
7
+ clientFeatureProps: null,
8
+ serverFeatureProps: props
9
+ };
10
+ },
11
+ key: 'toolbarInline',
12
+ serverFeatureProps: props
13
+ };
14
+ };
15
+
16
+ //# sourceMappingURL=feature.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/field/features/toolbars/inline/feature.server.ts"],"sourcesContent":["import type { FeatureProviderProviderServer } from '../../types.js'\n\nimport { InlineToolbarFeatureClientComponent } from './feature.client.js'\n\nexport const InlineToolbarFeature: FeatureProviderProviderServer<undefined, undefined> = (\n props,\n) => {\n return {\n feature: () => {\n return {\n ClientComponent: InlineToolbarFeatureClientComponent,\n clientFeatureProps: null,\n serverFeatureProps: props,\n }\n },\n key: 'toolbarInline',\n serverFeatureProps: props,\n }\n}\n"],"names":["InlineToolbarFeatureClientComponent","InlineToolbarFeature","props","feature","ClientComponent","clientFeatureProps","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;","mappings":"AAEA,SAASA,mCAAmC,QAAQ,sBAAqB;AAEzE,OAAO,MAAMC,uBAA4E,CACvFC;IAEA,OAAO;QACLC,SAAS;YACP,OAAO;gBACLC,iBAAiBJ;gBACjBK,oBAAoB;gBACpBC,oBAAoBJ;YACtB;QACF;QACAK,KAAK;QACLD,oBAAoBJ;IACtB;AACF,EAAC"}
@@ -0,0 +1,10 @@
1
+ import type { LexicalEditor } from 'lexical';
2
+ import React from 'react';
3
+ import type { ToolbarGroupItem } from '../../types.js';
4
+ import './index.scss';
5
+ export declare const ToolbarButton: ({ children, editor, item, }: {
6
+ children: React.JSX.Element;
7
+ editor: LexicalEditor;
8
+ item: ToolbarGroupItem;
9
+ }) => React.JSX.Element;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/toolbars/shared/ToolbarButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAI5C,OAAO,KAA2C,MAAM,OAAO,CAAA;AAE/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,aAAa,gCAIvB;IACD,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAA;IAC3B,MAAM,EAAE,aAAa,CAAA;IACrB,IAAI,EAAE,gBAAgB,CAAA;CACvB,sBA8EA,CAAA"}
@@ -1,21 +1,22 @@
1
1
  'use client';
2
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
2
  import { mergeRegister } from '@lexical/utils';
4
3
  import { $getSelection } from 'lexical';
5
4
  import React, { useCallback, useEffect, useState } from 'react';
5
+ import { useEditorFocus } from '../../../../lexical/EditorFocusProvider.js';
6
6
  import './index.scss';
7
- const baseClass = 'inline-toolbar-popup__button';
8
- export const ToolbarButton = ({ children, item })=>{
9
- const [editor] = useLexicalComposerContext();
7
+ const baseClass = 'toolbar-popup__button';
8
+ export const ToolbarButton = ({ children, editor, item })=>{
10
9
  const [enabled, setEnabled] = useState(true);
11
10
  const [active, setActive] = useState(false);
12
11
  const [className, setClassName] = useState(baseClass);
12
+ const editorFocusContext = useEditorFocus();
13
13
  const updateStates = useCallback(()=>{
14
14
  editor.getEditorState().read(()=>{
15
15
  const selection = $getSelection();
16
16
  if (item.isActive) {
17
17
  const isActive = item.isActive({
18
18
  editor,
19
+ editorFocusContext,
19
20
  selection
20
21
  });
21
22
  if (active !== isActive) {
@@ -25,6 +26,7 @@ export const ToolbarButton = ({ children, item })=>{
25
26
  if (item.isEnabled) {
26
27
  const isEnabled = item.isEnabled({
27
28
  editor,
29
+ editorFocusContext,
28
30
  selection
29
31
  });
30
32
  if (enabled !== isEnabled) {
@@ -35,6 +37,7 @@ export const ToolbarButton = ({ children, item })=>{
35
37
  }, [
36
38
  active,
37
39
  editor,
40
+ editorFocusContext,
38
41
  enabled,
39
42
  item
40
43
  ]);
@@ -69,7 +72,8 @@ export const ToolbarButton = ({ children, item })=>{
69
72
  }, [
70
73
  enabled,
71
74
  active,
72
- className
75
+ className,
76
+ item.key
73
77
  ]);
74
78
  return /*#__PURE__*/ React.createElement("button", {
75
79
  className: className,
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/field/features/toolbars/shared/ToolbarButton/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { $getSelection } from 'lexical'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorFocus } from '../../../../lexical/EditorFocusProvider.js'\nimport './index.scss'\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 [enabled, setEnabled] = useState<boolean>(true)\n const [active, setActive] = useState<boolean>(false)\n const [className, setClassName] = useState<string>(baseClass)\n const editorFocusContext = useEditorFocus()\n\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (item.isActive) {\n const isActive = item.isActive({ editor, editorFocusContext, selection })\n if (active !== isActive) {\n setActive(isActive)\n }\n }\n if (item.isEnabled) {\n const isEnabled = item.isEnabled({ editor, editorFocusContext, selection })\n if (enabled !== isEnabled) {\n setEnabled(isEnabled)\n }\n }\n })\n }, [active, editor, editorFocusContext, enabled, item])\n\n useEffect(() => {\n updateStates()\n }, [updateStates])\n\n useEffect(() => {\n document.addEventListener('mouseup', updateStates)\n return () => {\n document.removeEventListener('mouseup', updateStates)\n }\n }, [updateStates])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updateStates()\n }),\n )\n }, [editor, updateStates])\n\n useEffect(() => {\n setClassName(\n [\n baseClass,\n enabled === false ? 'disabled' : '',\n active ? 'active' : '',\n item?.key ? `${baseClass}-` + item.key : '',\n ]\n .filter(Boolean)\n .join(' '),\n )\n }, [enabled, active, className, item.key])\n\n return (\n <button\n className={className}\n onClick={() => {\n if (enabled !== false) {\n item.onSelect({\n editor,\n isActive: active,\n })\n }\n }}\n onMouseDown={(e) => {\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 type=\"button\"\n >\n {children}\n </button>\n )\n}\n"],"names":["mergeRegister","$getSelection","React","useCallback","useEffect","useState","useEditorFocus","baseClass","ToolbarButton","children","editor","item","enabled","setEnabled","active","setActive","className","setClassName","editorFocusContext","updateStates","getEditorState","read","selection","isActive","isEnabled","document","addEventListener","removeEventListener","registerUpdateListener","key","filter","Boolean","join","button","onClick","onSelect","onMouseDown","e","preventDefault","type"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAASA,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,aAAa,QAAQ,UAAS;AACvC,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAI/D,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,gBAAgB,CAAC,EAC5BC,QAAQ,EACRC,MAAM,EACNC,IAAI,EAKL;IACC,MAAM,CAACC,SAASC,WAAW,GAAGR,SAAkB;IAChD,MAAM,CAACS,QAAQC,UAAU,GAAGV,SAAkB;IAC9C,MAAM,CAACW,WAAWC,aAAa,GAAGZ,SAAiBE;IACnD,MAAMW,qBAAqBZ;IAE3B,MAAMa,eAAehB,YAAY;QAC/BO,OAAOU,cAAc,GAAGC,IAAI,CAAC;YAC3B,MAAMC,YAAYrB;YAClB,IAAIU,KAAKY,QAAQ,EAAE;gBACjB,MAAMA,WAAWZ,KAAKY,QAAQ,CAAC;oBAAEb;oBAAQQ;oBAAoBI;gBAAU;gBACvE,IAAIR,WAAWS,UAAU;oBACvBR,UAAUQ;gBACZ;YACF;YACA,IAAIZ,KAAKa,SAAS,EAAE;gBAClB,MAAMA,YAAYb,KAAKa,SAAS,CAAC;oBAAEd;oBAAQQ;oBAAoBI;gBAAU;gBACzE,IAAIV,YAAYY,WAAW;oBACzBX,WAAWW;gBACb;YACF;QACF;IACF,GAAG;QAACV;QAAQJ;QAAQQ;QAAoBN;QAASD;KAAK;IAEtDP,UAAU;QACRe;IACF,GAAG;QAACA;KAAa;IAEjBf,UAAU;QACRqB,SAASC,gBAAgB,CAAC,WAAWP;QACrC,OAAO;YACLM,SAASE,mBAAmB,CAAC,WAAWR;QAC1C;IACF,GAAG;QAACA;KAAa;IAEjBf,UAAU;QACR,OAAOJ,cACLU,OAAOkB,sBAAsB,CAAC;YAC5BT;QACF;IAEJ,GAAG;QAACT;QAAQS;KAAa;IAEzBf,UAAU;QACRa,aACE;YACEV;YACAK,YAAY,QAAQ,aAAa;YACjCE,SAAS,WAAW;YACpBH,MAAMkB,MAAM,CAAC,EAAEtB,UAAU,CAAC,CAAC,GAAGI,KAAKkB,GAAG,GAAG;SAC1C,CACEC,MAAM,CAACC,SACPC,IAAI,CAAC;IAEZ,GAAG;QAACpB;QAASE;QAAQE;QAAWL,KAAKkB,GAAG;KAAC;IAEzC,qBACE,oBAACI;QACCjB,WAAWA;QACXkB,SAAS;YACP,IAAItB,YAAY,OAAO;gBACrBD,KAAKwB,QAAQ,CAAC;oBACZzB;oBACAa,UAAUT;gBACZ;YACF;QACF;QACAsB,aAAa,CAACC;YACZ,8HAA8H;YAC9H,2JAA2J;YAC3J,sKAAsK;YACtKA,EAAEC,cAAc;QAClB;QACAC,MAAK;OAEJ9B;AAGP,EAAC"}
@@ -1,4 +1,6 @@
1
- .inline-toolbar-popup__button {
1
+ @import '../../../../../scss/styles';
2
+
3
+ .toolbar-popup__button {
2
4
  display: flex;
3
5
  align-items: center;
4
6
  vertical-align: middle;
@@ -0,0 +1,23 @@
1
+ import type { LexicalEditor } from 'lexical';
2
+ import { type ReactNode } from 'react';
3
+ import React from 'react';
4
+ import type { ToolbarGroupItem } from '../../types.js';
5
+ export declare function DropDownItem({ active, children, editor, enabled, item, title, }: {
6
+ active?: boolean;
7
+ children: React.ReactNode;
8
+ editor: LexicalEditor;
9
+ enabled?: boolean;
10
+ item: ToolbarGroupItem;
11
+ title?: string;
12
+ }): React.ReactNode;
13
+ export declare function DropDown({ Icon, buttonAriaLabel, buttonClassName, children, disabled, itemsContainerClassNames, label, stopCloseOnClickSelf, }: {
14
+ Icon?: React.FC;
15
+ buttonAriaLabel?: string;
16
+ buttonClassName: string;
17
+ children: ReactNode;
18
+ disabled?: boolean;
19
+ itemsContainerClassNames?: string[];
20
+ label?: string;
21
+ stopCloseOnClickSelf?: boolean;
22
+ }): React.ReactNode;
23
+ //# sourceMappingURL=DropDown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DropDown.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/toolbars/shared/ToolbarDropdown/DropDown.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAA;AACzF,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAUtD,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,GACN,EAAE;IACD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,EAAE,aAAa,CAAA;IACrB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,gBAAgB,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,KAAK,CAAC,SAAS,CAuDlB;AA8ED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,eAAe,EACf,eAAe,EACf,QAAQ,EACR,QAAgB,EAChB,wBAAwB,EACxB,KAAK,EACL,oBAAoB,GACrB,EAAE;IACD,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;IACf,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,SAAS,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,GAAG,KAAK,CAAC,SAAS,CAqFlB"}
@@ -1,66 +1,11 @@
1
1
  'use client';
2
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
- import { mergeRegister } from '@lexical/utils';
4
- import { $getSelection } from 'lexical';
5
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
3
  import React from 'react';
7
4
  import { createPortal } from 'react-dom';
8
- const baseClass = 'inline-toolbar-popup__dropdown-item';
5
+ const baseClass = 'toolbar-popup__dropdown-item';
9
6
  const DropDownContext = /*#__PURE__*/ React.createContext(null);
10
- export function DropDownItem({ children, item, title }) {
11
- const [editor] = useLexicalComposerContext();
12
- const [enabled, setEnabled] = useState(true);
13
- const [active, setActive] = useState(false);
7
+ export function DropDownItem({ active, children, editor, enabled, item, title }) {
14
8
  const [className, setClassName] = useState(baseClass);
15
- const updateStates = useCallback(()=>{
16
- editor.getEditorState().read(()=>{
17
- const selection = $getSelection();
18
- if (item.isActive) {
19
- const isActive = item.isActive({
20
- editor,
21
- selection
22
- });
23
- if (active !== isActive) {
24
- setActive(isActive);
25
- }
26
- }
27
- if (item.isEnabled) {
28
- const isEnabled = item.isEnabled({
29
- editor,
30
- selection
31
- });
32
- if (enabled !== isEnabled) {
33
- setEnabled(isEnabled);
34
- }
35
- }
36
- });
37
- }, [
38
- active,
39
- editor,
40
- enabled,
41
- item
42
- ]);
43
- useEffect(()=>{
44
- updateStates();
45
- }, [
46
- updateStates
47
- ]);
48
- useEffect(()=>{
49
- document.addEventListener('mouseup', updateStates);
50
- return ()=>{
51
- document.removeEventListener('mouseup', updateStates);
52
- };
53
- }, [
54
- updateStates
55
- ]);
56
- useEffect(()=>{
57
- return mergeRegister(editor.registerUpdateListener(()=>{
58
- updateStates();
59
- }));
60
- }, [
61
- editor,
62
- updateStates
63
- ]);
64
9
  useEffect(()=>{
65
10
  setClassName([
66
11
  baseClass,
@@ -108,7 +53,7 @@ export function DropDownItem({ children, item, title }) {
108
53
  type: "button"
109
54
  }, children);
110
55
  }
111
- function DropDownItems({ children, dropDownRef, onClose }) {
56
+ function DropDownItems({ children, dropDownRef, itemsContainerClassNames, onClose }) {
112
57
  const [items, setItems] = useState();
113
58
  const [highlightedItem, setHighlightedItem] = useState();
114
59
  const registerItem = useCallback((itemRef)=>{
@@ -156,7 +101,7 @@ function DropDownItems({ children, dropDownRef, onClose }) {
156
101
  if (items != null && highlightedItem == null) {
157
102
  setHighlightedItem(items[0]);
158
103
  }
159
- if (highlightedItem?.current != null) {
104
+ if (highlightedItem != null && highlightedItem?.current != null) {
160
105
  highlightedItem.current.focus();
161
106
  }
162
107
  }, [
@@ -166,12 +111,14 @@ function DropDownItems({ children, dropDownRef, onClose }) {
166
111
  return /*#__PURE__*/ React.createElement(DropDownContext.Provider, {
167
112
  value: contextValue
168
113
  }, /*#__PURE__*/ React.createElement("div", {
169
- className: "inline-toolbar-popup__dropdown-items",
114
+ className: (itemsContainerClassNames ?? [
115
+ 'toolbar-popup__dropdown-items'
116
+ ]).join(' '),
170
117
  onKeyDown: handleKeyDown,
171
118
  ref: dropDownRef
172
119
  }, children));
173
120
  }
174
- export function DropDown({ Icon, buttonAriaLabel, buttonClassName, children, disabled = false, stopCloseOnClickSelf }) {
121
+ export function DropDown({ Icon, buttonAriaLabel, buttonClassName, children, disabled = false, itemsContainerClassNames, label, stopCloseOnClickSelf }) {
175
122
  const dropDownRef = useRef(null);
176
123
  const buttonRef = useRef(null);
177
124
  const [showDropDown, setShowDropDown] = useState(false);
@@ -186,7 +133,7 @@ export function DropDown({ Icon, buttonAriaLabel, buttonClassName, children, dis
186
133
  const dropDown = dropDownRef.current;
187
134
  if (showDropDown && button !== null && dropDown !== null) {
188
135
  const { left, top } = button.getBoundingClientRect();
189
- const scrollTopOffset = window.pageYOffset || document.documentElement.scrollTop;
136
+ const scrollTopOffset = window.scrollY || document.documentElement.scrollTop;
190
137
  dropDown.style.top = `${top + scrollTopOffset + button.offsetHeight + 5}px`;
191
138
  dropDown.style.left = `${Math.min(left - 5, window.innerWidth - dropDown.offsetWidth - 20)}px`;
192
139
  }
@@ -237,10 +184,13 @@ export function DropDown({ Icon, buttonAriaLabel, buttonClassName, children, dis
237
184
  },
238
185
  ref: buttonRef,
239
186
  type: "button"
240
- }, /*#__PURE__*/ React.createElement(Icon, null), /*#__PURE__*/ React.createElement("i", {
241
- className: "inline-toolbar-popup__dropdown-caret"
187
+ }, Icon && /*#__PURE__*/ React.createElement(Icon, null), label && /*#__PURE__*/ React.createElement("span", {
188
+ className: "toolbar-popup__dropdown-label"
189
+ }, label), /*#__PURE__*/ React.createElement("i", {
190
+ className: "toolbar-popup__dropdown-caret"
242
191
  })), showDropDown && /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(DropDownItems, {
243
192
  dropDownRef: dropDownRef,
193
+ itemsContainerClassNames: itemsContainerClassNames,
244
194
  onClose: handleClose
245
195
  }, children), document.body));
246
196
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/field/features/toolbars/shared/ToolbarDropdown/DropDown.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport React from 'react'\nimport { createPortal } from 'react-dom'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nconst baseClass = 'toolbar-popup__dropdown-item'\n\ninterface DropDownContextType {\n registerItem: (ref: React.RefObject<HTMLButtonElement>) => void\n}\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null)\n\nexport function DropDownItem({\n active,\n children,\n editor,\n enabled,\n item,\n title,\n}: {\n active?: boolean\n children: React.ReactNode\n editor: LexicalEditor\n enabled?: boolean\n item: ToolbarGroupItem\n title?: string\n}): React.ReactNode {\n const [className, setClassName] = useState<string>(baseClass)\n\n useEffect(() => {\n setClassName(\n [\n baseClass,\n enabled === false ? 'disabled' : '',\n active ? 'active' : '',\n item?.key ? `${baseClass}-${item.key}` : '',\n ]\n .filter(Boolean)\n .join(' '),\n )\n }, [enabled, active, className, item.key])\n\n const ref = useRef<HTMLButtonElement>(null)\n\n const dropDownContext = React.useContext(DropDownContext)\n\n if (dropDownContext === null) {\n throw new Error('DropDownItem must be used within a DropDown')\n }\n\n const { registerItem } = dropDownContext\n\n useEffect(() => {\n if (ref?.current != null) {\n registerItem(ref)\n }\n }, [ref, registerItem])\n\n return (\n <button\n className={className}\n onClick={() => {\n if (enabled !== false) {\n item.onSelect({\n editor,\n isActive: active,\n })\n }\n }}\n onMouseDown={(e) => {\n // This is required for Firefox compatibility. Without it, the dropdown will disappear without the onClick being called.\n // This only happens in Firefox. Must be something about how Firefox handles focus events differently.\n e.preventDefault()\n }}\n ref={ref}\n title={title}\n type=\"button\"\n >\n {children}\n </button>\n )\n}\n\nfunction DropDownItems({\n children,\n dropDownRef,\n itemsContainerClassNames,\n onClose,\n}: {\n children: React.ReactNode\n dropDownRef: React.Ref<HTMLDivElement>\n itemsContainerClassNames?: string[]\n onClose: () => void\n}): React.ReactElement {\n const [items, setItems] = useState<Array<React.RefObject<HTMLButtonElement>>>()\n const [highlightedItem, setHighlightedItem] = useState<React.RefObject<HTMLButtonElement>>()\n\n const registerItem = useCallback(\n (itemRef: React.RefObject<HTMLButtonElement>) => {\n setItems((prev) => (prev != null ? [...prev, itemRef] : [itemRef]))\n },\n [setItems],\n )\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {\n if (items == null) return\n\n const { key } = event\n\n if (['ArrowDown', 'ArrowUp', 'Escape', 'Tab'].includes(key)) {\n event.preventDefault()\n }\n\n if (key === 'Escape' || key === 'Tab') {\n onClose()\n } else if (key === 'ArrowUp') {\n setHighlightedItem((prev) => {\n if (prev == null) return items[0]\n const index = items.indexOf(prev) - 1\n return items[index === -1 ? items.length - 1 : index]\n })\n } else if (key === 'ArrowDown') {\n setHighlightedItem((prev) => {\n if (prev == null) return items[0]\n return items[items.indexOf(prev) + 1]\n })\n }\n }\n\n const contextValue = useMemo(\n () => ({\n registerItem,\n }),\n [registerItem],\n )\n\n useEffect(() => {\n if (items != null && highlightedItem == null) {\n setHighlightedItem(items[0])\n }\n\n if (highlightedItem != null && highlightedItem?.current != null) {\n highlightedItem.current.focus()\n }\n }, [items, highlightedItem])\n\n return (\n <DropDownContext.Provider value={contextValue}>\n <div\n className={(itemsContainerClassNames ?? ['toolbar-popup__dropdown-items']).join(' ')}\n onKeyDown={handleKeyDown}\n ref={dropDownRef}\n >\n {children}\n </div>\n </DropDownContext.Provider>\n )\n}\n\nexport function DropDown({\n Icon,\n buttonAriaLabel,\n buttonClassName,\n children,\n disabled = false,\n itemsContainerClassNames,\n label,\n stopCloseOnClickSelf,\n}: {\n Icon?: React.FC\n buttonAriaLabel?: string\n buttonClassName: string\n children: ReactNode\n disabled?: boolean\n itemsContainerClassNames?: string[]\n label?: string\n stopCloseOnClickSelf?: boolean\n}): React.ReactNode {\n const dropDownRef = useRef<HTMLDivElement>(null)\n const buttonRef = useRef<HTMLButtonElement>(null)\n const [showDropDown, setShowDropDown] = useState(false)\n\n const handleClose = (): void => {\n setShowDropDown(false)\n if (buttonRef?.current != null) {\n buttonRef.current.focus()\n }\n }\n\n useEffect(() => {\n const button = buttonRef.current\n const dropDown = dropDownRef.current\n\n if (showDropDown && button !== null && dropDown !== null) {\n const { left, top } = button.getBoundingClientRect()\n const scrollTopOffset = window.scrollY || document.documentElement.scrollTop\n dropDown.style.top = `${top + scrollTopOffset + button.offsetHeight + 5}px`\n dropDown.style.left = `${Math.min(left - 5, window.innerWidth - dropDown.offsetWidth - 20)}px`\n }\n }, [dropDownRef, buttonRef, showDropDown])\n\n useEffect(() => {\n const button = buttonRef.current\n\n if (button !== null && showDropDown) {\n const handle = (event: MouseEvent): void => {\n const { target } = event\n if (stopCloseOnClickSelf != null) {\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (dropDownRef.current != null && dropDownRef.current.contains(target as Node)) {\n return\n }\n }\n if (!button.contains(target as Node)) {\n setShowDropDown(false)\n }\n }\n document.addEventListener('click', handle)\n\n return () => {\n document.removeEventListener('click', handle)\n }\n }\n }, [dropDownRef, buttonRef, showDropDown, stopCloseOnClickSelf])\n\n return (\n <React.Fragment>\n <button\n aria-label={buttonAriaLabel}\n className={buttonClassName + (showDropDown ? ' active' : '')}\n disabled={disabled}\n onClick={(event) => {\n event.preventDefault()\n setShowDropDown(!showDropDown)\n }}\n onMouseDown={(e) => {\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 ref={buttonRef}\n type=\"button\"\n >\n {Icon && <Icon />}\n {label && <span className=\"toolbar-popup__dropdown-label\">{label}</span>}\n <i className=\"toolbar-popup__dropdown-caret\" />\n </button>\n\n {showDropDown &&\n createPortal(\n <DropDownItems\n dropDownRef={dropDownRef}\n itemsContainerClassNames={itemsContainerClassNames}\n onClose={handleClose}\n >\n {children}\n </DropDownItems>,\n document.body,\n )}\n </React.Fragment>\n )\n}\n"],"names":["useCallback","useEffect","useMemo","useRef","useState","React","createPortal","baseClass","DropDownContext","createContext","DropDownItem","active","children","editor","enabled","item","title","className","setClassName","key","filter","Boolean","join","ref","dropDownContext","useContext","Error","registerItem","current","button","onClick","onSelect","isActive","onMouseDown","e","preventDefault","type","DropDownItems","dropDownRef","itemsContainerClassNames","onClose","items","setItems","highlightedItem","setHighlightedItem","itemRef","prev","handleKeyDown","event","includes","index","indexOf","length","contextValue","focus","Provider","value","div","onKeyDown","DropDown","Icon","buttonAriaLabel","buttonClassName","disabled","label","stopCloseOnClickSelf","buttonRef","showDropDown","setShowDropDown","handleClose","dropDown","left","top","getBoundingClientRect","scrollTopOffset","window","scrollY","document","documentElement","scrollTop","style","offsetHeight","Math","min","innerWidth","offsetWidth","handle","target","contains","addEventListener","removeEventListener","Fragment","aria-label","span","i","body"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAAyBA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACzF,OAAOC,WAAW,QAAO;AACzB,SAASC,YAAY,QAAQ,YAAW;AAIxC,MAAMC,YAAY;AAMlB,MAAMC,gCAAkBH,MAAMI,aAAa,CAA6B;AAExE,OAAO,SAASC,aAAa,EAC3BC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,KAAK,EAQN;IACC,MAAM,CAACC,WAAWC,aAAa,GAAGd,SAAiBG;IAEnDN,UAAU;QACRiB,aACE;YACEX;YACAO,YAAY,QAAQ,aAAa;YACjCH,SAAS,WAAW;YACpBI,MAAMI,MAAM,CAAC,EAAEZ,UAAU,CAAC,EAAEQ,KAAKI,GAAG,CAAC,CAAC,GAAG;SAC1C,CACEC,MAAM,CAACC,SACPC,IAAI,CAAC;IAEZ,GAAG;QAACR;QAASH;QAAQM;QAAWF,KAAKI,GAAG;KAAC;IAEzC,MAAMI,MAAMpB,OAA0B;IAEtC,MAAMqB,kBAAkBnB,MAAMoB,UAAU,CAACjB;IAEzC,IAAIgB,oBAAoB,MAAM;QA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K2C;QACL9B,MAAK;OAEJwB,sBAAQ,oBAACA,aACTI,uBAAS,oBAAC6B;QAAK5E,WAAU;OAAiC+C,sBAC3D,oBAAC8B;QAAE7E,WAAU;SAGdkD,8BACC7D,2BACE,oBAAC+B;QACCC,aAAaA;QACbC,0BAA0BA;QAC1BC,SAAS6B;OAERzD,WAEHiE,SAASkB,IAAI;AAIvB"}
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import type { LexicalEditor } from 'lexical';
3
+ import type { ToolbarGroupItem } from '../../types.js';
4
+ import './index.scss';
5
+ export declare const ToolbarDropdown: ({ Icon, anchorElem, classNames, editor, groupKey, items, itemsContainerClassNames, label, maxActiveItems, onActiveChange, }: {
6
+ Icon?: React.FC;
7
+ anchorElem: HTMLElement;
8
+ classNames?: string[];
9
+ editor: LexicalEditor;
10
+ groupKey: string;
11
+ items: ToolbarGroupItem[];
12
+ itemsContainerClassNames?: string[];
13
+ label?: string;
14
+ /**
15
+ * Maximum number of active items allowed. This is a performance optimization to prevent
16
+ * unnecessary item active checks when the maximum number of active items is reached.
17
+ */
18
+ maxActiveItems?: number;
19
+ onActiveChange?: ({ activeItems }: {
20
+ activeItems: ToolbarGroupItem[];
21
+ }) => void;
22
+ }) => React.JSX.Element;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/toolbars/shared/ToolbarDropdown/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAIrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAItD,OAAO,cAAc,CAAA;AAiDrB,eAAO,MAAM,eAAe,gIAWzB;IACD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,UAAU,EAAE,WAAW,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,gBAAgB,EAAE,CAAA;IACzB,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,sBAoFA,CAAA"}
@@ -0,0 +1,139 @@
1
+ 'use client';
2
+ import React, { useCallback, useEffect } from 'react';
3
+ const baseClass = 'toolbar-popup__dropdown';
4
+ import { mergeRegister } from '@lexical/utils';
5
+ import { useTranslation } from '@payloadcms/ui/providers/Translation';
6
+ import { $getSelection } from 'lexical';
7
+ import { useEditorFocus } from '../../../../lexical/EditorFocusProvider.js';
8
+ import { DropDown, DropDownItem } from './DropDown.js';
9
+ import './index.scss';
10
+ const ToolbarItem = ({ active, anchorElem, editor, enabled, item })=>{
11
+ const { i18n } = useTranslation();
12
+ if (item.Component) {
13
+ return item?.Component && /*#__PURE__*/ React.createElement(item.Component, {
14
+ active: active,
15
+ anchorElem: anchorElem,
16
+ editor: editor,
17
+ enabled: enabled,
18
+ item: item,
19
+ key: item.key
20
+ });
21
+ }
22
+ let title = item.key;
23
+ if (item.label) {
24
+ title = typeof item.label === 'function' ? item.label({
25
+ i18n
26
+ }) : item.label;
27
+ }
28
+ // Crop title to max. 25 characters
29
+ if (title.length > 25) {
30
+ title = title.substring(0, 25) + '...';
31
+ }
32
+ return /*#__PURE__*/ React.createElement(DropDownItem, {
33
+ active: active,
34
+ editor: editor,
35
+ enabled: enabled,
36
+ item: item,
37
+ key: item.key
38
+ }, item?.ChildComponent && /*#__PURE__*/ React.createElement(item.ChildComponent, null), /*#__PURE__*/ React.createElement("span", {
39
+ className: "text"
40
+ }, title));
41
+ };
42
+ export const ToolbarDropdown = ({ Icon, anchorElem, classNames, editor, groupKey, items, itemsContainerClassNames, label, maxActiveItems, onActiveChange })=>{
43
+ const [activeItemKeys, setActiveItemKeys] = React.useState([]);
44
+ const [enabledItemKeys, setEnabledItemKeys] = React.useState([]);
45
+ const editorFocusContext = useEditorFocus();
46
+ const updateStates = useCallback(()=>{
47
+ editor.getEditorState().read(()=>{
48
+ const selection = $getSelection();
49
+ const _activeItemKeys = [];
50
+ const _activeItems = [];
51
+ const _enabledItemKeys = [];
52
+ for (const item of items){
53
+ if (item.isActive && (!maxActiveItems || _activeItemKeys.length < maxActiveItems)) {
54
+ const isActive = item.isActive({
55
+ editor,
56
+ editorFocusContext,
57
+ selection
58
+ });
59
+ if (isActive) {
60
+ _activeItemKeys.push(item.key);
61
+ _activeItems.push(item);
62
+ }
63
+ }
64
+ if (item.isEnabled) {
65
+ const isEnabled = item.isEnabled({
66
+ editor,
67
+ editorFocusContext,
68
+ selection
69
+ });
70
+ if (isEnabled) {
71
+ _enabledItemKeys.push(item.key);
72
+ }
73
+ } else {
74
+ _enabledItemKeys.push(item.key);
75
+ }
76
+ }
77
+ setActiveItemKeys(_activeItemKeys);
78
+ setEnabledItemKeys(_enabledItemKeys);
79
+ if (onActiveChange) {
80
+ onActiveChange({
81
+ activeItems: _activeItems
82
+ });
83
+ }
84
+ });
85
+ }, [
86
+ editor,
87
+ editorFocusContext,
88
+ items,
89
+ maxActiveItems,
90
+ onActiveChange
91
+ ]);
92
+ useEffect(()=>{
93
+ updateStates();
94
+ }, [
95
+ updateStates
96
+ ]);
97
+ useEffect(()=>{
98
+ document.addEventListener('mouseup', updateStates);
99
+ return ()=>{
100
+ document.removeEventListener('mouseup', updateStates);
101
+ };
102
+ }, [
103
+ updateStates
104
+ ]);
105
+ useEffect(()=>{
106
+ return mergeRegister(editor.registerUpdateListener(()=>{
107
+ updateStates();
108
+ }));
109
+ }, [
110
+ editor,
111
+ updateStates
112
+ ]);
113
+ return /*#__PURE__*/ React.createElement(DropDown, {
114
+ Icon: Icon,
115
+ buttonAriaLabel: `${groupKey} dropdown`,
116
+ buttonClassName: [
117
+ baseClass,
118
+ `${baseClass}-${groupKey}`,
119
+ ...classNames || []
120
+ ].filter(Boolean).join(' '),
121
+ itemsContainerClassNames: [
122
+ `${baseClass}-items`,
123
+ ...itemsContainerClassNames || []
124
+ ],
125
+ key: groupKey,
126
+ label: label
127
+ }, items.length && items.map((item)=>{
128
+ return /*#__PURE__*/ React.createElement(ToolbarItem, {
129
+ active: activeItemKeys.includes(item.key),
130
+ anchorElem: anchorElem,
131
+ editor: editor,
132
+ enabled: enabledItemKeys.includes(item.key),
133
+ item: item,
134
+ key: item.key
135
+ });
136
+ }));
137
+ };
138
+
139
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/field/features/toolbars/shared/ToolbarDropdown/index.tsx"],"sourcesContent":["'use client'\nimport React, { useCallback, useEffect } from 'react'\n\nconst baseClass = 'toolbar-popup__dropdown'\n\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport { $getSelection } from 'lexical'\n\nimport type { ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorFocus } from '../../../../lexical/EditorFocusProvider.js'\nimport { DropDown, DropDownItem } from './DropDown.js'\nimport './index.scss'\n\nconst ToolbarItem = ({\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}) => {\n const { i18n } = useTranslation()\n\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component\n active={active}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabled}\n item={item}\n key={item.key}\n />\n )\n )\n }\n\n let title = item.key\n if (item.label) {\n title = typeof item.label === 'function' ? item.label({ i18n }) : item.label\n }\n // Crop title to max. 25 characters\n if (title.length > 25) {\n title = title.substring(0, 25) + '...'\n }\n\n return (\n <DropDownItem active={active} editor={editor} enabled={enabled} item={item} key={item.key}>\n {item?.ChildComponent && <item.ChildComponent />}\n <span className=\"text\">{title}</span>\n </DropDownItem>\n )\n}\n\nexport const ToolbarDropdown = ({\n Icon,\n anchorElem,\n classNames,\n editor,\n groupKey,\n items,\n itemsContainerClassNames,\n label,\n maxActiveItems,\n onActiveChange,\n}: {\n Icon?: React.FC\n anchorElem: HTMLElement\n classNames?: string[]\n editor: LexicalEditor\n groupKey: string\n items: ToolbarGroupItem[]\n itemsContainerClassNames?: string[]\n label?: string\n /**\n * Maximum number of active items allowed. This is a performance optimization to prevent\n * unnecessary item active checks when the maximum number of active items is reached.\n */\n maxActiveItems?: number\n onActiveChange?: ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => void\n}) => {\n const [activeItemKeys, setActiveItemKeys] = React.useState<string[]>([])\n const [enabledItemKeys, setEnabledItemKeys] = React.useState<string[]>([])\n const editorFocusContext = useEditorFocus()\n\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n\n const _activeItemKeys: string[] = []\n const _activeItems: ToolbarGroupItem[] = []\n const _enabledItemKeys: string[] = []\n\n for (const item of items) {\n if (item.isActive && (!maxActiveItems || _activeItemKeys.length < maxActiveItems)) {\n const isActive = item.isActive({ editor, editorFocusContext, selection })\n if (isActive) {\n _activeItemKeys.push(item.key)\n _activeItems.push(item)\n }\n }\n if (item.isEnabled) {\n const isEnabled = item.isEnabled({ editor, editorFocusContext, selection })\n if (isEnabled) {\n _enabledItemKeys.push(item.key)\n }\n } else {\n _enabledItemKeys.push(item.key)\n }\n }\n setActiveItemKeys(_activeItemKeys)\n setEnabledItemKeys(_enabledItemKeys)\n\n if (onActiveChange) {\n onActiveChange({ activeItems: _activeItems })\n }\n })\n }, [editor, editorFocusContext, items, maxActiveItems, onActiveChange])\n\n useEffect(() => {\n updateStates()\n }, [updateStates])\n\n useEffect(() => {\n document.addEventListener('mouseup', updateStates)\n return () => {\n document.removeEventListener('mouseup', updateStates)\n }\n }, [updateStates])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updateStates()\n }),\n )\n }, [editor, updateStates])\n\n return (\n <DropDown\n Icon={Icon}\n buttonAriaLabel={`${groupKey} dropdown`}\n buttonClassName={[baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])]\n .filter(Boolean)\n .join(' ')}\n itemsContainerClassNames={[`${baseClass}-items`, ...(itemsContainerClassNames || [])]}\n key={groupKey}\n label={label}\n >\n {items.length &&\n items.map((item) => {\n return (\n <ToolbarItem\n active={activeItemKeys.includes(item.key)}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabledItemKeys.includes(item.key)}\n item={item}\n key={item.key}\n />\n )\n })}\n </DropDown>\n )\n}\n"],"names":["React","useCallback","useEffect","baseClass","mergeRegister","useTranslation","$getSelection","useEditorFocus","DropDown","DropDownItem","ToolbarItem","active","anchorElem","editor","enabled","item","i18n","Component","key","title","label","length","substring","ChildComponent","span","className","ToolbarDropdown","Icon","classNames","groupKey","items","itemsContainerClassNames","maxActiveItems","onActiveChange","activeItemKeys","setActiveItemKeys","useState","enabledItemKeys","setEnabledItemKeys","editorFocusContext","updateStates","getEditorState","read","selection","_activeItemKeys","_activeItems","_enabledItemKeys","isActive","push","isEnabled","activeItems","document","addEventListener","removeEventListener","registerUpdateListener","buttonAriaLabel","buttonClassName","filter","Boolean","join","map","includes"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AACA,OAAOA,SAASC,WAAW,EAAEC,SAAS,QAAQ,QAAO;AAErD,MAAMC,YAAY;AAIlB,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,cA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