@payloadcms/richtext-lexical 3.0.0-beta.34 → 3.0.0-beta.36

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 (251) hide show
  1. package/dist/cell/index.d.ts +2 -0
  2. package/dist/cell/index.d.ts.map +1 -1
  3. package/dist/cell/index.js +24 -15
  4. package/dist/cell/index.js.map +1 -1
  5. package/dist/field/Field.d.ts.map +1 -1
  6. package/dist/field/Field.js +66 -47
  7. package/dist/field/Field.js.map +1 -1
  8. package/dist/field/features/blocks/component/BlockContent.js +62 -45
  9. package/dist/field/features/blocks/component/BlockContent.js.map +1 -1
  10. package/dist/field/features/blocks/component/index.js +38 -28
  11. package/dist/field/features/blocks/component/index.js.map +1 -1
  12. package/dist/field/features/blocks/component/index.scss +0 -4
  13. package/dist/field/features/blocks/drawer/index.js +2 -1
  14. package/dist/field/features/blocks/drawer/index.js.map +1 -1
  15. package/dist/field/features/blocks/nodes/BlocksNode.d.ts +1 -1
  16. package/dist/field/features/blocks/nodes/BlocksNode.d.ts.map +1 -1
  17. package/dist/field/features/blocks/nodes/BlocksNode.js +2 -1
  18. package/dist/field/features/blocks/nodes/BlocksNode.js.map +1 -1
  19. package/dist/field/features/blocks/plugin/index.js +2 -1
  20. package/dist/field/features/blocks/plugin/index.js.map +1 -1
  21. package/dist/field/features/blocks/validate.js +1 -1
  22. package/dist/field/features/blocks/validate.js.map +1 -1
  23. package/dist/field/features/debug/testRecorder/plugin/index.js +65 -39
  24. package/dist/field/features/debug/testRecorder/plugin/index.js.map +1 -1
  25. package/dist/field/features/debug/treeView/plugin/index.js +2 -1
  26. package/dist/field/features/debug/treeView/plugin/index.js.map +1 -1
  27. package/dist/field/features/horizontalRule/nodes/HorizontalRuleNode.js +2 -1
  28. package/dist/field/features/horizontalRule/nodes/HorizontalRuleNode.js.map +1 -1
  29. package/dist/field/features/link/drawer/index.js +30 -22
  30. package/dist/field/features/link/drawer/index.js.map +1 -1
  31. package/dist/field/features/link/plugins/clickableLink/index.js +2 -1
  32. package/dist/field/features/link/plugins/clickableLink/index.js.map +1 -1
  33. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  34. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js +88 -70
  35. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  36. package/dist/field/features/link/plugins/floatingLinkEditor/index.js +2 -1
  37. package/dist/field/features/link/plugins/floatingLinkEditor/index.js.map +1 -1
  38. package/dist/field/features/link/validate.js +1 -1
  39. package/dist/field/features/link/validate.js.map +1 -1
  40. package/dist/field/features/lists/checklist/plugin/index.js +2 -1
  41. package/dist/field/features/lists/checklist/plugin/index.js.map +1 -1
  42. package/dist/field/features/lists/plugin/index.js +2 -1
  43. package/dist/field/features/lists/plugin/index.js.map +1 -1
  44. package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js +9 -1
  45. package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
  46. package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.d.ts +1 -1
  47. package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.d.ts.map +1 -1
  48. package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js +2 -1
  49. package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
  50. package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js +9 -1
  51. package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
  52. package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.d.ts +1 -1
  53. package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.d.ts.map +1 -1
  54. package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js +2 -1
  55. package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
  56. package/dist/field/features/relationship/drawer/index.js +10 -2
  57. package/dist/field/features/relationship/drawer/index.js.map +1 -1
  58. package/dist/field/features/relationship/nodes/RelationshipNode.d.ts +1 -1
  59. package/dist/field/features/relationship/nodes/RelationshipNode.d.ts.map +1 -1
  60. package/dist/field/features/relationship/nodes/RelationshipNode.js +2 -1
  61. package/dist/field/features/relationship/nodes/RelationshipNode.js.map +1 -1
  62. package/dist/field/features/relationship/nodes/components/RelationshipComponent.js +64 -44
  63. package/dist/field/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
  64. package/dist/field/features/relationship/plugins/index.js +2 -1
  65. package/dist/field/features/relationship/plugins/index.js.map +1 -1
  66. package/dist/field/features/toolbars/fixed/Toolbar/index.js +60 -55
  67. package/dist/field/features/toolbars/fixed/Toolbar/index.js.map +1 -1
  68. package/dist/field/features/toolbars/fixed/Toolbar/index.scss +16 -2
  69. package/dist/field/features/toolbars/inline/Toolbar/index.js +57 -49
  70. package/dist/field/features/toolbars/inline/Toolbar/index.js.map +1 -1
  71. package/dist/field/features/toolbars/shared/ToolbarButton/index.d.ts +1 -1
  72. package/dist/field/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
  73. package/dist/field/features/toolbars/shared/ToolbarButton/index.js +5 -3
  74. package/dist/field/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
  75. package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.d.ts.map +1 -1
  76. package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.js +54 -35
  77. package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
  78. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.d.ts +1 -1
  79. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
  80. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.js +25 -22
  81. package/dist/field/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
  82. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js +30 -22
  83. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js.map +1 -1
  84. package/dist/field/features/upload/component/index.js +104 -71
  85. package/dist/field/features/upload/component/index.js.map +1 -1
  86. package/dist/field/features/upload/drawer/index.js +8 -4
  87. package/dist/field/features/upload/drawer/index.js.map +1 -1
  88. package/dist/field/features/upload/nodes/UploadNode.d.ts +1 -1
  89. package/dist/field/features/upload/nodes/UploadNode.d.ts.map +1 -1
  90. package/dist/field/features/upload/nodes/UploadNode.js +2 -1
  91. package/dist/field/features/upload/nodes/UploadNode.js.map +1 -1
  92. package/dist/field/features/upload/plugin/index.js +2 -1
  93. package/dist/field/features/upload/plugin/index.js.map +1 -1
  94. package/dist/field/features/upload/validate.js +1 -1
  95. package/dist/field/features/upload/validate.js.map +1 -1
  96. package/dist/field/index.d.ts +2 -0
  97. package/dist/field/index.d.ts.map +1 -1
  98. package/dist/field/index.js +29 -21
  99. package/dist/field/index.js.map +1 -1
  100. package/dist/field/index.scss +0 -21
  101. package/dist/field/lexical/EditorFocusProvider.d.ts +1 -2
  102. package/dist/field/lexical/EditorFocusProvider.d.ts.map +1 -1
  103. package/dist/field/lexical/EditorFocusProvider.js +5 -3
  104. package/dist/field/lexical/EditorFocusProvider.js.map +1 -1
  105. package/dist/field/lexical/EditorPlugin.js +3 -2
  106. package/dist/field/lexical/EditorPlugin.js.map +1 -1
  107. package/dist/field/lexical/LexicalEditor.js +113 -81
  108. package/dist/field/lexical/LexicalEditor.js.map +1 -1
  109. package/dist/field/lexical/LexicalEditor.scss +10 -1
  110. package/dist/field/lexical/LexicalProvider.js +16 -10
  111. package/dist/field/lexical/LexicalProvider.js.map +1 -1
  112. package/dist/field/lexical/config/client/EditorConfigProvider.js +5 -3
  113. package/dist/field/lexical/config/client/EditorConfigProvider.js.map +1 -1
  114. package/dist/field/lexical/config/client/sanitize.d.ts +2 -1
  115. package/dist/field/lexical/config/client/sanitize.d.ts.map +1 -1
  116. package/dist/field/lexical/config/client/sanitize.js +2 -1
  117. package/dist/field/lexical/config/client/sanitize.js.map +1 -1
  118. package/dist/field/lexical/config/types.d.ts +2 -0
  119. package/dist/field/lexical/config/types.d.ts.map +1 -1
  120. package/dist/field/lexical/config/types.js.map +1 -1
  121. package/dist/field/lexical/plugins/MarkdownShortcut/index.js +2 -1
  122. package/dist/field/lexical/plugins/MarkdownShortcut/index.js.map +1 -1
  123. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +1 -1
  124. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
  125. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
  126. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts +1 -1
  127. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
  128. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +2 -1
  129. package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
  130. package/dist/field/lexical/plugins/SlashMenu/index.js +51 -40
  131. package/dist/field/lexical/plugins/SlashMenu/index.js.map +1 -1
  132. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.d.ts +2 -2
  133. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.d.ts.map +1 -1
  134. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js +38 -119
  135. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
  136. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.scss +2 -2
  137. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/highlightElemOriginalPosition.d.ts +1 -1
  138. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/highlightElemOriginalPosition.d.ts.map +1 -1
  139. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/highlightElemOriginalPosition.js.map +1 -1
  140. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts +2 -2
  141. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
  142. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js +102 -58
  143. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
  144. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.scss +12 -3
  145. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.d.ts +8 -1
  146. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.d.ts.map +1 -1
  147. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.js +73 -25
  148. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.js.map +1 -1
  149. package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.d.ts +5 -0
  150. package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.d.ts.map +1 -0
  151. package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.js +21 -0
  152. package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.js.map +1 -0
  153. package/dist/field/lexical/plugins/handles/{DraggableBlockPlugin → utils}/getNodeCloseToPoint.d.ts +4 -0
  154. package/dist/field/lexical/plugins/handles/utils/getNodeCloseToPoint.d.ts.map +1 -0
  155. package/dist/field/lexical/plugins/handles/{DraggableBlockPlugin → utils}/getNodeCloseToPoint.js +2 -14
  156. package/dist/field/lexical/plugins/handles/utils/getNodeCloseToPoint.js.map +1 -0
  157. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
  158. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js +4 -2
  159. package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
  160. package/dist/field/lexical/theme/EditorTheme.scss +5 -0
  161. package/dist/field/lexical/ui/ContentEditable.d.ts +1 -1
  162. package/dist/field/lexical/ui/ContentEditable.d.ts.map +1 -1
  163. package/dist/field/lexical/ui/ContentEditable.js +2 -1
  164. package/dist/field/lexical/ui/ContentEditable.js.map +1 -1
  165. package/dist/field/lexical/ui/ContentEditable.scss +50 -2
  166. package/dist/field/lexical/ui/icons/AI/index.js +26 -17
  167. package/dist/field/lexical/ui/icons/AI/index.js.map +1 -1
  168. package/dist/field/lexical/ui/icons/Add/index.js +14 -9
  169. package/dist/field/lexical/ui/icons/Add/index.js.map +1 -1
  170. package/dist/field/lexical/ui/icons/Add/light.svg +4 -0
  171. package/dist/field/lexical/ui/icons/AlignCenter/index.js +21 -15
  172. package/dist/field/lexical/ui/icons/AlignCenter/index.js.map +1 -1
  173. package/dist/field/lexical/ui/icons/AlignJustify/index.js +21 -15
  174. package/dist/field/lexical/ui/icons/AlignJustify/index.js.map +1 -1
  175. package/dist/field/lexical/ui/icons/AlignLeft/index.js +21 -15
  176. package/dist/field/lexical/ui/icons/AlignLeft/index.js.map +1 -1
  177. package/dist/field/lexical/ui/icons/AlignRight/index.js +21 -15
  178. package/dist/field/lexical/ui/icons/AlignRight/index.js.map +1 -1
  179. package/dist/field/lexical/ui/icons/Block/index.js +30 -24
  180. package/dist/field/lexical/ui/icons/Block/index.js.map +1 -1
  181. package/dist/field/lexical/ui/icons/Blockquote/index.js +8 -6
  182. package/dist/field/lexical/ui/icons/Blockquote/index.js.map +1 -1
  183. package/dist/field/lexical/ui/icons/Bold/index.js +8 -6
  184. package/dist/field/lexical/ui/icons/Bold/index.js.map +1 -1
  185. package/dist/field/lexical/ui/icons/Checklist/index.js +19 -14
  186. package/dist/field/lexical/ui/icons/Checklist/index.js.map +1 -1
  187. package/dist/field/lexical/ui/icons/Code/index.js +14 -9
  188. package/dist/field/lexical/ui/icons/Code/index.js.map +1 -1
  189. package/dist/field/lexical/ui/icons/CodeBlock/index.js +14 -9
  190. package/dist/field/lexical/ui/icons/CodeBlock/index.js.map +1 -1
  191. package/dist/field/lexical/ui/icons/DraggableBlock/light.svg +9 -0
  192. package/dist/field/lexical/ui/icons/H1/index.js +8 -6
  193. package/dist/field/lexical/ui/icons/H1/index.js.map +1 -1
  194. package/dist/field/lexical/ui/icons/H2/index.js +8 -6
  195. package/dist/field/lexical/ui/icons/H2/index.js.map +1 -1
  196. package/dist/field/lexical/ui/icons/H3/index.js +8 -6
  197. package/dist/field/lexical/ui/icons/H3/index.js.map +1 -1
  198. package/dist/field/lexical/ui/icons/H4/index.js +8 -6
  199. package/dist/field/lexical/ui/icons/H4/index.js.map +1 -1
  200. package/dist/field/lexical/ui/icons/H5/index.js +8 -6
  201. package/dist/field/lexical/ui/icons/H5/index.js.map +1 -1
  202. package/dist/field/lexical/ui/icons/H6/index.js +8 -6
  203. package/dist/field/lexical/ui/icons/H6/index.js.map +1 -1
  204. package/dist/field/lexical/ui/icons/HorizontalRule/index.js +11 -9
  205. package/dist/field/lexical/ui/icons/HorizontalRule/index.js.map +1 -1
  206. package/dist/field/lexical/ui/icons/IndentDecrease/index.js +25 -18
  207. package/dist/field/lexical/ui/icons/IndentDecrease/index.js.map +1 -1
  208. package/dist/field/lexical/ui/icons/IndentIncrease/index.js +25 -18
  209. package/dist/field/lexical/ui/icons/IndentIncrease/index.js.map +1 -1
  210. package/dist/field/lexical/ui/icons/Italic/index.js +8 -6
  211. package/dist/field/lexical/ui/icons/Italic/index.js.map +1 -1
  212. package/dist/field/lexical/ui/icons/Link/index.js +26 -17
  213. package/dist/field/lexical/ui/icons/Link/index.js.map +1 -1
  214. package/dist/field/lexical/ui/icons/OrderedList/index.js +29 -21
  215. package/dist/field/lexical/ui/icons/OrderedList/index.js.map +1 -1
  216. package/dist/field/lexical/ui/icons/Relationship/index.js +26 -17
  217. package/dist/field/lexical/ui/icons/Relationship/index.js.map +1 -1
  218. package/dist/field/lexical/ui/icons/Strikethrough/index.js +14 -9
  219. package/dist/field/lexical/ui/icons/Strikethrough/index.js.map +1 -1
  220. package/dist/field/lexical/ui/icons/Subscript/index.js +8 -6
  221. package/dist/field/lexical/ui/icons/Subscript/index.js.map +1 -1
  222. package/dist/field/lexical/ui/icons/Superscript/index.js +8 -6
  223. package/dist/field/lexical/ui/icons/Superscript/index.js.map +1 -1
  224. package/dist/field/lexical/ui/icons/Text/index.js +8 -6
  225. package/dist/field/lexical/ui/icons/Text/index.js.map +1 -1
  226. package/dist/field/lexical/ui/icons/Underline/index.js +14 -9
  227. package/dist/field/lexical/ui/icons/Underline/index.js.map +1 -1
  228. package/dist/field/lexical/ui/icons/UnorderedList/index.js +45 -36
  229. package/dist/field/lexical/ui/icons/UnorderedList/index.js.map +1 -1
  230. package/dist/field/lexical/ui/icons/Upload/index.js +24 -18
  231. package/dist/field/lexical/ui/icons/Upload/index.js.map +1 -1
  232. package/dist/generateComponentMap.js +8 -8
  233. package/dist/generateComponentMap.js.map +1 -1
  234. package/dist/index.d.ts.map +1 -1
  235. package/dist/index.js +2 -0
  236. package/dist/index.js.map +1 -1
  237. package/dist/populate/defaultValue.d.ts +0 -1
  238. package/dist/populate/defaultValue.d.ts.map +1 -1
  239. package/dist/populate/defaultValue.js +0 -19
  240. package/dist/populate/defaultValue.js.map +1 -1
  241. package/dist/types.d.ts +7 -0
  242. package/dist/types.d.ts.map +1 -1
  243. package/dist/types.js.map +1 -1
  244. package/dist/validate/index.d.ts.map +1 -1
  245. package/dist/validate/index.js +3 -2
  246. package/dist/validate/index.js.map +1 -1
  247. package/dist/validate/validateNodes.js +1 -1
  248. package/dist/validate/validateNodes.js.map +1 -1
  249. package/package.json +18 -14
  250. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/getNodeCloseToPoint.d.ts.map +0 -1
  251. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/getNodeCloseToPoint.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
4
  import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js';
4
5
  import { mergeRegister } from '@lexical/utils';
@@ -102,57 +103,76 @@ const Component = (props)=>{
102
103
  setSelected,
103
104
  onClick
104
105
  ]);
105
- return /*#__PURE__*/ React.createElement("div", {
106
+ return /*#__PURE__*/ _jsxs("div", {
106
107
  className: [
107
108
  baseClass,
108
109
  isSelected && `${baseClass}--selected`
109
110
  ].filter(Boolean).join(' '),
110
111
  contentEditable: false,
111
- ref: relationshipElemRef
112
- }, /*#__PURE__*/ React.createElement("div", {
113
- className: `${baseClass}__wrap`
114
- }, /*#__PURE__*/ React.createElement("p", {
115
- className: `${baseClass}__label`
116
- }, t('fields:labelRelationship', {
117
- label: getTranslation(relatedCollection.labels.singular, i18n)
118
- })), /*#__PURE__*/ React.createElement(DocumentDrawerToggler, {
119
- className: `${baseClass}__doc-drawer-toggler`
120
- }, /*#__PURE__*/ React.createElement("p", {
121
- className: `${baseClass}__title`
122
- }, data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : id))), editor.isEditable() && /*#__PURE__*/ React.createElement("div", {
123
- className: `${baseClass}__actions`
124
- }, /*#__PURE__*/ React.createElement(Button, {
125
- buttonStyle: "icon-label",
126
- className: `${baseClass}__swapButton`,
127
- disabled: field?.readOnly,
128
- el: "div",
129
- icon: "swap",
130
- onClick: ()=>{
131
- editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {
132
- replace: {
133
- nodeKey
134
- }
135
- });
136
- },
137
- round: true,
138
- tooltip: t('fields:swapRelationship')
139
- }), /*#__PURE__*/ React.createElement(Button, {
140
- buttonStyle: "icon-label",
141
- className: `${baseClass}__removeButton`,
142
- disabled: field?.readOnly,
143
- icon: "x",
144
- onClick: (e)=>{
145
- e.preventDefault();
146
- removeRelationship();
147
- },
148
- round: true,
149
- tooltip: t('fields:removeRelationship')
150
- })), id && /*#__PURE__*/ React.createElement(DocumentDrawer, {
151
- onSave: updateRelationship
152
- }), children);
112
+ ref: relationshipElemRef,
113
+ children: [
114
+ /*#__PURE__*/ _jsxs("div", {
115
+ className: `${baseClass}__wrap`,
116
+ children: [
117
+ /*#__PURE__*/ _jsx("p", {
118
+ className: `${baseClass}__label`,
119
+ children: t('fields:labelRelationship', {
120
+ label: getTranslation(relatedCollection.labels.singular, i18n)
121
+ })
122
+ }),
123
+ /*#__PURE__*/ _jsx(DocumentDrawerToggler, {
124
+ className: `${baseClass}__doc-drawer-toggler`,
125
+ children: /*#__PURE__*/ _jsx("p", {
126
+ className: `${baseClass}__title`,
127
+ children: data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : id
128
+ })
129
+ })
130
+ ]
131
+ }),
132
+ editor.isEditable() && /*#__PURE__*/ _jsxs("div", {
133
+ className: `${baseClass}__actions`,
134
+ children: [
135
+ /*#__PURE__*/ _jsx(Button, {
136
+ buttonStyle: "icon-label",
137
+ className: `${baseClass}__swapButton`,
138
+ disabled: field?.readOnly,
139
+ el: "div",
140
+ icon: "swap",
141
+ onClick: ()=>{
142
+ editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {
143
+ replace: {
144
+ nodeKey
145
+ }
146
+ });
147
+ },
148
+ round: true,
149
+ tooltip: t('fields:swapRelationship')
150
+ }),
151
+ /*#__PURE__*/ _jsx(Button, {
152
+ buttonStyle: "icon-label",
153
+ className: `${baseClass}__removeButton`,
154
+ disabled: field?.readOnly,
155
+ icon: "x",
156
+ onClick: (e)=>{
157
+ e.preventDefault();
158
+ removeRelationship();
159
+ },
160
+ round: true,
161
+ tooltip: t('fields:removeRelationship')
162
+ })
163
+ ]
164
+ }),
165
+ id && /*#__PURE__*/ _jsx(DocumentDrawer, {
166
+ onSave: updateRelationship
167
+ }),
168
+ children
169
+ ]
170
+ });
153
171
  };
154
172
  export const RelationshipComponent = (props)=>{
155
- return /*#__PURE__*/ React.createElement(Component, props);
173
+ return /*#__PURE__*/ _jsx(Component, {
174
+ ...props
175
+ });
156
176
  };
157
177
 
158
178
  //# sourceMappingURL=RelationshipComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/field/features/relationship/nodes/components/RelationshipComponent.tsx"],"sourcesContent":["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { useDocumentDrawer } from '@payloadcms/ui/elements/DocumentDrawer'\nimport usePayloadAPI from '@payloadcms/ui/hooks/usePayloadAPI'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport {\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} from 'lexical'\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../RelationshipNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../../drawer/commands.js'\nimport { $isRelationshipNode } from '../RelationshipNode.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n children?: React.ReactNode\n className?: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nconst Component: React.FC<Props> = (props) => {\n const {\n children,\n data: { relationTo, value: id },\n nodeKey,\n } = props\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n const { field } = useEditorConfigContext()\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const [relatedCollection, setRelatedCollection] = useState(() =>\n collections.find((coll) => coll.slug === relationTo),\n )\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${id}`,\n { initialParams },\n )\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id,\n collectionSlug: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n const updateRelationship = React.useCallback(\n ({ doc }) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeDrawer()\n dispatchCacheBust()\n },\n [cacheBust, setParams, closeDrawer],\n )\n\n const $onDelete = useCallback(\n (payload: KeyboardEvent) => {\n if (isSelected && $isNodeSelection($getSelection())) {\n const event: KeyboardEvent = payload\n event.preventDefault()\n const node = $getNodeByKey(nodeKey)\n if ($isRelationshipNode(node)) {\n node.remove()\n return true\n }\n }\n return false\n },\n [isSelected, nodeKey],\n )\n const onClick = useCallback(\n (payload: MouseEvent) => {\n const event = payload\n // Check if relationshipElemRef.target or anything WITHIN relationshipElemRef.target was clicked\n if (\n event.target === relationshipElemRef.current ||\n relationshipElemRef.current?.contains(event.target as Node)\n ) {\n if (event.shiftKey) {\n setSelected(!isSelected)\n } else {\n if (!isSelected) {\n clearSelection()\n setSelected(true)\n }\n }\n return true\n }\n\n return false\n },\n [isSelected, setSelected, clearSelection],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<MouseEvent>(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW),\n\n editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected, onClick])\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n ref={relationshipElemRef}\n >\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : id}\n </p>\n </DocumentDrawerToggler>\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={field?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n )}\n\n {id && <DocumentDrawer onSave={updateRelationship} />}\n {children}\n </div>\n )\n}\n\nexport const RelationshipComponent = (props: Props): React.ReactNode => {\n return <Component {...props} />\n}\n"],"names":["useLexicalComposerContext","useLexicalNodeSelection","mergeRegister","getTranslation","Button","useDocumentDrawer","usePayloadAPI","useConfig","useTranslation","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","$getNodeByKey","React","useCallback","useEffect","useReducer","useRef","useState","useEditorConfigContext","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","$isRelationshipNode","baseClass","initialParams","depth","Component","props","children","data","relationTo","value","id","nodeKey","relationshipElemRef","editor","isSelected","setSelected","clearSelection","field","collections","routes","api","serverURL","relatedCollection","setRelatedCollection","find","coll","slug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","DocumentDrawer","DocumentDrawerToggler","closeDrawer","collectionSlug","removeRelationship","update","remove","updateRelationship","doc","$onDelete","payload","event","preventDefault","node","onClick","target","current","contains","shiftKey","registerCommand","div","className","filter","Boolean","join","contentEditable","ref","p","label","labels","singular","admin","useAsTitle","isEditable","buttonStyle","disabled","readOnly","el","icon","dispatchCommand","replace","round","tooltip","e","onSave","RelationshipComponent"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,4CAA2C;AACnF,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,OAAOC,mBAAmB,qCAAoC;AAC9D,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SACEC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,QACb,UAAS;AAChB,SAASC,aAAa,QAAQ,UAAS;AACvC,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAInF,SAASC,sBAAsB,QAAQ,4DAA2D;AAClG,SAASC,u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AAC,EAAErD,UAAU,MAAM,CAAC;qBAClC,oBAAC2D;QAAEN,WAAW,CAAC,EAAErD,UAAU,OAAO,CAAC;OAChC2B,EAAE,4BAA4B;QAC7BiC,OAAOlF,eAAe2C,kBAAkBwC,MAAM,CAACC,QAAQ,EAAEpC;IAC3D,mBAEF,oBAACO;QAAsBoB,WAAW,CAAC,EAAErD,UAAU,oBAAoB,CAAC;qBAClE,oBAAC2D;QAAEN,WAAW,CAAC,EAAErD,UAAU,OAAO,CAAC;OAChCM,OAAOA,IAAI,CAACe,mBAAmB0C,OAAOC,cAAc,KAAK,GAAGvD,OAIlEG,OAAOqD,UAAU,oBAChB,oBAACb;QAAIC,WAAW,CAAC,EAAErD,UAAU,SAAS,CAAC;qBACrC,oBAACrB;QACCuF,aAAY;QACZb,WAAW,CAAC,EAAErD,UAAU,YAAY,CAAC;QACrCmE,UAAUnD,OAAOoD;QACjBC,IAAG;QACHC,MAAK;QACLxB,SAAS;YACPlC,OAAO2D,eAAe,CAACzE,yCAAyC;gBAC9D0E,SAAS;oBAAE9D;gBAAQ;YACrB;QACF;QACA+D,OAAAA;QACAC,SAAS/C,EAAE;sBAEb,oBAAChD;QACCuF,aAAY;QACZb,WAAW,CAAC,EAAErD,UAAU,cAAc,CAAC;QACvCmE,UAAUnD,OAAOoD;QACjBE,MAAK;QACLxB,SAAS,CAAC6B;YACRA,EAAE/B,cAAc;YAChBR;QACF;QACAqC,OAAAA;QACAC,SAAS/C,EAAE;SAKhBlB,oBAAM,oBAACuB;QAAe4C,QAAQrC;QAC9BlC;AAGP;AAEA,OAAO,MAAMwE,wBAAwB,CAACzE;IACpC,qBAAO,oBAACD,WAAcC;AACxB,EAAC"}
1
+ {"version":3,"sources":["../../../../../../src/field/features/relationship/nodes/components/RelationshipComponent.tsx"],"sourcesContent":["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { useDocumentDrawer } from '@payloadcms/ui/elements/DocumentDrawer'\nimport usePayloadAPI from '@payloadcms/ui/hooks/usePayloadAPI'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport {\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} from 'lexical'\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../RelationshipNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../../drawer/commands.js'\nimport { $isRelationshipNode } from '../RelationshipNode.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n children?: React.ReactNode\n className?: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nconst Component: React.FC<Props> = (props) => {\n const {\n children,\n data: { relationTo, value: id },\n nodeKey,\n } = props\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n const { field } = useEditorConfigContext()\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const [relatedCollection, setRelatedCollection] = useState(() =>\n collections.find((coll) => coll.slug === relationTo),\n )\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${id}`,\n { initialParams },\n )\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id,\n collectionSlug: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n const updateRelationship = React.useCallback(\n ({ doc }) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeDrawer()\n dispatchCacheBust()\n },\n [cacheBust, setParams, closeDrawer],\n )\n\n const $onDelete = useCallback(\n (payload: KeyboardEvent) => {\n if (isSelected && $isNodeSelection($getSelection())) {\n const event: KeyboardEvent = payload\n event.preventDefault()\n const node = $getNodeByKey(nodeKey)\n if ($isRelationshipNode(node)) {\n node.remove()\n return true\n }\n }\n return false\n },\n [isSelected, nodeKey],\n )\n const onClick = useCallback(\n (payload: MouseEvent) => {\n const event = payload\n // Check if relationshipElemRef.target or anything WITHIN relationshipElemRef.target was clicked\n if (\n event.target === relationshipElemRef.current ||\n relationshipElemRef.current?.contains(event.target as Node)\n ) {\n if (event.shiftKey) {\n setSelected(!isSelected)\n } else {\n if (!isSelected) {\n clearSelection()\n setSelected(true)\n }\n }\n return true\n }\n\n return false\n },\n [isSelected, setSelected, clearSelection],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<MouseEvent>(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW),\n\n editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected, onClick])\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n ref={relationshipElemRef}\n >\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : id}\n </p>\n </DocumentDrawerToggler>\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={field?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n )}\n\n {id && <DocumentDrawer onSave={updateRelationship} />}\n {children}\n </div>\n )\n}\n\nexport const RelationshipComponent = (props: Props): React.ReactNode => {\n return <Component {...props} />\n}\n"],"names":["useLexicalComposerContext","useLexicalNodeSelection","mergeRegister","getTranslation","Button","useDocumentDrawer","usePayloadAPI","useConfig","useTranslation","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","$getNodeByKey","React","useCallback","useEffect","useReducer","useRef","useState","useEditorConfigContext","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","$isRelationshipNode","baseClass","initialParams","depth","Component","props","children","data","relationTo","value","id","nodeKey","relationshipElemRef","editor","isSelected","setSelected","clearSelection","field","collections","routes","api","serverURL","relatedCollection","setRelatedCollection","find","coll","slug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","DocumentDrawer","DocumentDrawerToggler","closeDrawer","collectionSlug","removeRelationship","update","remove","updateRelationship","doc","$onDelete","payload","event","preventDefault","node","onClick","target","current","contains","shiftKey","registerCommand","div","className","filter","Boolean","join","contentEditable","ref","p","label","labels","singular","admin","useAsTitle","isEditable","buttonStyle","disabled","readOnly","el","icon","dispatchCommand","replace","round","tooltip","e","onSave","RelationshipComponent"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,4CAA2C;AACnF,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,OAAOC,mBAAmB,qCAAoC;AAC9D,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SACEC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,QACb,UAAS;AAChB,SAASC,aAAa,QAAQ,UAAS;AACvC,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAInF,SAASC,sBAAsB,QAAQ,4DAA2D;AAClG,SAASC,uCAAuC,QAAQ,2BAA0B;AAClF,SAASC,mBAAmB,QAAQ,yBAAwB;AAC5D,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,MAAMC,gBAAgB;IACpBC,OAAO;AACT;AAUA,MAAMC,YAA6B,CAACC;IAClC,MAAM,EACJC,QAAQ,EACRC,MAAM,EAAEC,UAAU,EAAEC,OAAOC,EAAE,EAAE,EAC/BC,OAAO,EACR,GAAGN;IAEJ,M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D;4BAAEN,WAAW,CAAC,EAAErD,UAAU,OAAO,CAAC;sCAChCM,OAAOA,IAAI,CAACe,mBAAmB0C,OAAOC,cAAc,KAAK,GAAGvD;;;;;YAIlEG,OAAOqD,UAAU,oBAChB,MAACb;gBAAIC,WAAW,CAAC,EAAErD,UAAU,SAAS,CAAC;;kCACrC,KAACrB;wBACCuF,aAAY;wBACZb,WAAW,CAAC,EAAErD,UAAU,YAAY,CAAC;wBACrCmE,UAAUnD,OAAOoD;wBACjBC,IAAG;wBACHC,MAAK;wBACLxB,SAAS;4BACPlC,OAAO2D,eAAe,CAACzE,yCAAyC;gCAC9D0E,SAAS;oCAAE9D;gCAAQ;4BACrB;wBACF;wBACA+D,KAAK;wBACLC,SAAS/C,EAAE;;kCAEb,KAAChD;wBACCuF,aAAY;wBACZb,WAAW,CAAC,EAAErD,UAAU,cAAc,CAAC;wBACvCmE,UAAUnD,OAAOoD;wBACjBE,MAAK;wBACLxB,SAAS,CAAC6B;4BACRA,EAAE/B,cAAc;4BAChBR;wBACF;wBACAqC,KAAK;wBACLC,SAAS/C,EAAE;;;;YAKhBlB,oBAAM,KAACuB;gBAAe4C,QAAQrC;;YAC9BlC;;;AAGP;AAEA,OAAO,MAAMwE,wBAAwB,CAACzE;IACpC,qBAAO,KAACD;QAAW,GAAGC,KAAK;;AAC7B,EAAC"}
@@ -1,4 +1,5 @@
1
1
  'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
4
  import { $insertNodeToNearestRoot } from '@lexical/utils';
4
5
  import { useConfig } from '@payloadcms/ui/providers/Config';
@@ -42,7 +43,7 @@ export const RelationshipPlugin = ({ clientProps })=>{
42
43
  }, [
43
44
  editor
44
45
  ]);
45
- return /*#__PURE__*/ React.createElement(RelationshipDrawer, {
46
+ return /*#__PURE__*/ _jsx(RelationshipDrawer, {
46
47
  enabledCollectionSlugs: enabledRelations
47
48
  });
48
49
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/field/features/relationship/plugins/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot } from '@lexical/utils'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport {\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n COMMAND_PRIORITY_EDITOR,\n createCommand,\n} from 'lexical'\nimport { useEffect } from 'react'\nimport React from 'react'\n\nimport type { PluginComponent } from '../../types.js'\nimport type { RelationshipFeatureProps } from '../feature.server.js'\nimport type { RelationshipData } from '../nodes/RelationshipNode.js'\n\nimport { RelationshipDrawer } from '../drawer/index.js'\nimport { $createRelationshipNode, RelationshipNode } from '../nodes/RelationshipNode.js'\n\nexport const INSERT_RELATIONSHIP_COMMAND: LexicalCommand<RelationshipData> = createCommand(\n 'INSERT_RELATIONSHIP_COMMAND',\n)\n\nexport const RelationshipPlugin: PluginComponent<RelationshipFeatureProps> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n const { collections } = useConfig()\n\n let enabledRelations: string[] = null\n\n if (clientProps?.enabledCollections) {\n enabledRelations = clientProps?.enabledCollections\n } else if (clientProps?.disabledCollections) {\n enabledRelations = collections\n .filter(({ slug }) => !clientProps?.disabledCollections?.includes(slug))\n .map(({ slug }) => slug)\n }\n\n useEffect(() => {\n if (!editor.hasNodes([RelationshipNode])) {\n throw new Error('RelationshipPlugin: RelationshipNode not registered on editor')\n }\n\n return editor.registerCommand<RelationshipData>(\n INSERT_RELATIONSHIP_COMMAND,\n (payload) => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const relationshipNode = $createRelationshipNode(payload)\n // Insert relationship node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(relationshipNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParent()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor])\n\n return <RelationshipDrawer enabledCollectionSlugs={enabledRelations} />\n}\n"],"names":["useLexicalComposerContext","$insertNodeToNearestRoot","useConfig","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","useEffect","React","RelationshipDrawer","$createRelationshipNode","RelationshipNode","INSERT_RELATIONSHIP_COMMAND","RelationshipPlugin","clientProps","editor","collections","enabledRelations","enabledCollections","disabledCollections","filter","slug","includes","map","hasNodes","Error","registerCommand","payload","selection","relationshipNode","focus","focusNode","getNode","getTextContentSize","getParent","getChildren","node","length","remove","enabledCollectionSlugs"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,wBAAwB,QAAQ,iBAAgB;AACzD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,uBAAuB,EACvBC,aAAa,QACR,UAAS;AAChB,SAASC,SAAS,QAAQ,QAAO;AACjC,OAAOC,WAAW,QAAO;AAMzB,SAASC,kBAAkB,QAAQ,qBAAoB;AACvD,SAASC,uBAAuB,EAAEC,gBAAgB,QAAQ,+BAA8B;AAExF,OAAO,MAAMC,8BAAgEN,cAC3E,+BACD;AAED,OAAO,MAAMO,qBAAgE,CAAC,EAAEC,WAAW,EAAE;IAC3F,MAAM,CAACC,OAAO,GAAGjB;IACjB,MAAM,EAAEkB,WAAW,EAAE,GAAGhB;IAExB,IAAIiB,mBAA6B;IAEjC,IAAIH,aAAaI,oBAAoB;QACnCD,mBAAmBH,aAAaI;IAClC,OAAO,IAAIJ,aAAaK,qBAAqB;QAC3CF,mBAAmBD,YAChBI,MAAM,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAK,CAACP,aAAaK,qBAAqBG,SAASD,OACjEE,GAAG,CAAC,CAAC,EAAEF,IAAI,EAAE,GAAKA;IACvB;IAEAd,UAAU;QACR,IAAI,CAACQ,OAAOS,QAAQ,CAAC;YAACb;SAAiB,GAAG;YACxC,MAAM,IAAIc,MAAM;QAClB;QAEA,OAAOV,OAAOW,eAAe,CAC3Bd,6BACA,CAACe;YACC,MAAMC,YAAY1B,mBAAmBD;YAErC,IAAIG,kBAAkBwB,YAAY;gBAChC,MAAMC,mBAAmBnB,wBAAwBiB;gBACjD,oIAAoI;gBACpI5B,yBAAyB8B;gBAEzB,MAAM,EAAEC,KAAK,EAAE,GAAGF;gBAClB,MAAMG,YAAYD,MAAME,OAAO;gBAE/B,+FAA+F;gBAC/F,0FAA0F;gBAC1F,IACE7B,iBAAiB4B,cACjBA,UAAUE,kBAAkB,OAAO,KACnCF,UACGG,SAAS,GACTC,WAAW,GACXf,MAAM,CAAC,CAACgB,OAASjC,iBAAiBiC,OAAOC,MAAM,GAAG,GACrD;oBACAN,UAAUO,MAAM;gBAClB;YACF;YAEA,OAAO;QACT,GACAjC;IAEJ,GAAG;QAACU;KAAO;IAEX,qBAAO,oBAACN;QAAmB8B,wBAAwBtB;;AACrD,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/field/features/relationship/plugins/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot } from '@lexical/utils'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport {\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n COMMAND_PRIORITY_EDITOR,\n createCommand,\n} from 'lexical'\nimport { useEffect } from 'react'\nimport React from 'react'\n\nimport type { PluginComponent } from '../../types.js'\nimport type { RelationshipFeatureProps } from '../feature.server.js'\nimport type { RelationshipData } from '../nodes/RelationshipNode.js'\n\nimport { RelationshipDrawer } from '../drawer/index.js'\nimport { $createRelationshipNode, RelationshipNode } from '../nodes/RelationshipNode.js'\n\nexport const INSERT_RELATIONSHIP_COMMAND: LexicalCommand<RelationshipData> = createCommand(\n 'INSERT_RELATIONSHIP_COMMAND',\n)\n\nexport const RelationshipPlugin: PluginComponent<RelationshipFeatureProps> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n const { collections } = useConfig()\n\n let enabledRelations: string[] = null\n\n if (clientProps?.enabledCollections) {\n enabledRelations = clientProps?.enabledCollections\n } else if (clientProps?.disabledCollections) {\n enabledRelations = collections\n .filter(({ slug }) => !clientProps?.disabledCollections?.includes(slug))\n .map(({ slug }) => slug)\n }\n\n useEffect(() => {\n if (!editor.hasNodes([RelationshipNode])) {\n throw new Error('RelationshipPlugin: RelationshipNode not registered on editor')\n }\n\n return editor.registerCommand<RelationshipData>(\n INSERT_RELATIONSHIP_COMMAND,\n (payload) => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const relationshipNode = $createRelationshipNode(payload)\n // Insert relationship node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(relationshipNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParent()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor])\n\n return <RelationshipDrawer enabledCollectionSlugs={enabledRelations} />\n}\n"],"names":["useLexicalComposerContext","$insertNodeToNearestRoot","useConfig","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","useEffect","React","RelationshipDrawer","$createRelationshipNode","RelationshipNode","INSERT_RELATIONSHIP_COMMAND","RelationshipPlugin","clientProps","editor","collections","enabledRelations","enabledCollections","disabledCollections","filter","slug","includes","map","hasNodes","Error","registerCommand","payload","selection","relationshipNode","focus","focusNode","getNode","getTextContentSize","getParent","getChildren","node","length","remove","enabledCollectionSlugs"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,wBAAwB,QAAQ,iBAAgB;AACzD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,uBAAuB,EACvBC,aAAa,QACR,UAAS;AAChB,SAASC,SAAS,QAAQ,QAAO;AACjC,OAAOC,WAAW,QAAO;AAMzB,SAASC,kBAAkB,QAAQ,qBAAoB;AACvD,SAASC,uBAAuB,EAAEC,gBAAgB,QAAQ,+BAA8B;AAExF,OAAO,MAAMC,8BAAgEN,cAC3E,+BACD;AAED,OAAO,MAAMO,qBAAgE,CAAC,EAAEC,WAAW,EAAE;IAC3F,MAAM,CAACC,OAAO,GAAGjB;IACjB,MAAM,EAAEkB,WAAW,EAAE,GAAGhB;IAExB,IAAIiB,mBAA6B;IAEjC,IAAIH,aAAaI,oBAAoB;QACnCD,mBAAmBH,aAAaI;IAClC,OAAO,IAAIJ,aAAaK,qBAAqB;QAC3CF,mBAAmBD,YAChBI,MAAM,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAK,CAACP,aAAaK,qBAAqBG,SAASD,OACjEE,GAAG,CAAC,CAAC,EAAEF,IAAI,EAAE,GAAKA;IACvB;IAEAd,UAAU;QACR,IAAI,CAACQ,OAAOS,QAAQ,CAAC;YAACb;SAAiB,GAAG;YACxC,MAAM,IAAIc,MAAM;QAClB;QAEA,OAAOV,OAAOW,eAAe,CAC3Bd,6BACA,CAACe;YACC,MAAMC,YAAY1B,mBAAmBD;YAErC,IAAIG,kBAAkBwB,YAAY;gBAChC,MAAMC,mBAAmBnB,wBAAwBiB;gBACjD,oIAAoI;gBACpI5B,yBAAyB8B;gBAEzB,MAAM,EAAEC,KAAK,EAAE,GAAGF;gBAClB,MAAMG,YAAYD,MAAME,OAAO;gBAE/B,+FAA+F;gBAC/F,0FAA0F;gBAC1F,IACE7B,iBAAiB4B,cACjBA,UAAUE,kBAAkB,OAAO,KACnCF,UACGG,SAAS,GACTC,WAAW,GACXf,MAAM,CAAC,CAACgB,OAASjC,iBAAiBiC,OAAOC,MAAM,GAAG,GACrD;oBACAN,UAAUO,MAAM;gBAClB;YACF;YAEA,OAAO;QACT,GACAjC;IAEJ,GAAG;QAACU;KAAO;IAEX,qBAAO,KAACN;QAAmB8B,wBAAwBtB;;AACrD,EAAC"}
@@ -1,4 +1,5 @@
1
1
  'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
4
  import { useTranslation } from '@payloadcms/ui/providers/Translation';
4
5
  import * as React from 'react';
@@ -9,18 +10,17 @@ import { ToolbarDropdown } from '../../shared/ToolbarDropdown/index.js';
9
10
  import './index.scss';
10
11
  function ButtonGroupItem({ anchorElem, editor, item }) {
11
12
  if (item.Component) {
12
- return item?.Component && /*#__PURE__*/ React.createElement(item.Component, {
13
+ return item?.Component && /*#__PURE__*/ _jsx(item.Component, {
13
14
  anchorElem: anchorElem,
14
15
  editor: editor,
15
- item: item,
16
- key: item.key
17
- });
16
+ item: item
17
+ }, item.key);
18
18
  }
19
- return /*#__PURE__*/ React.createElement(ToolbarButton, {
19
+ return /*#__PURE__*/ _jsx(ToolbarButton, {
20
20
  editor: editor,
21
21
  item: item,
22
- key: item.key
23
- }, item?.ChildComponent && /*#__PURE__*/ React.createElement(item.ChildComponent, null));
22
+ children: item?.ChildComponent && /*#__PURE__*/ _jsx(item.ChildComponent, {})
23
+ }, item.key);
24
24
  }
25
25
  function ToolbarGroupComponent({ anchorElem, editor, editorConfig, group, index }) {
26
26
  const { i18n } = useTranslation();
@@ -60,61 +60,66 @@ function ToolbarGroupComponent({ anchorElem, editor, editorConfig, group, index
60
60
  setDropdownLabel(label);
61
61
  setDropdownIcon(()=>item.ChildComponent);
62
62
  };
63
- return /*#__PURE__*/ React.createElement("div", {
63
+ return /*#__PURE__*/ _jsxs("div", {
64
64
  className: `fixed-toolbar__group fixed-toolbar__group-${group.key}`,
65
- key: group.key
66
- }, group.type === 'dropdown' && group.items.length && (DropdownIcon ? /*#__PURE__*/ React.createElement(ToolbarDropdown, {
67
- Icon: DropdownIcon,
68
- anchorElem: anchorElem,
69
- editor: editor,
70
- groupKey: group.key,
71
- items: group.items,
72
- itemsContainerClassNames: [
73
- 'fixed-toolbar__dropdown-items'
74
- ],
75
- label: dropdownLabel,
76
- maxActiveItems: 1,
77
- onActiveChange: onActiveChange
78
- }) : /*#__PURE__*/ React.createElement(ToolbarDropdown, {
79
- anchorElem: anchorElem,
80
- editor: editor,
81
- groupKey: group.key,
82
- items: group.items,
83
- itemsContainerClassNames: [
84
- 'fixed-toolbar__dropdown-items'
85
- ],
86
- label: dropdownLabel,
87
- maxActiveItems: 1,
88
- onActiveChange: onActiveChange
89
- })), group.type === 'buttons' && group.items.length && group.items.map((item)=>{
90
- return /*#__PURE__*/ React.createElement(ButtonGroupItem, {
91
- anchorElem: anchorElem,
92
- editor: editor,
93
- item: item,
94
- key: item.key
95
- });
96
- }), index < editorConfig.features.toolbarFixed?.groups.length - 1 && /*#__PURE__*/ React.createElement("div", {
97
- className: "divider"
98
- }));
65
+ children: [
66
+ group.type === 'dropdown' && group.items.length && (DropdownIcon ? /*#__PURE__*/ _jsx(ToolbarDropdown, {
67
+ Icon: DropdownIcon,
68
+ anchorElem: anchorElem,
69
+ editor: editor,
70
+ groupKey: group.key,
71
+ items: group.items,
72
+ itemsContainerClassNames: [
73
+ 'fixed-toolbar__dropdown-items'
74
+ ],
75
+ label: dropdownLabel,
76
+ maxActiveItems: 1,
77
+ onActiveChange: onActiveChange
78
+ }) : /*#__PURE__*/ _jsx(ToolbarDropdown, {
79
+ anchorElem: anchorElem,
80
+ editor: editor,
81
+ groupKey: group.key,
82
+ items: group.items,
83
+ itemsContainerClassNames: [
84
+ 'fixed-toolbar__dropdown-items'
85
+ ],
86
+ label: dropdownLabel,
87
+ maxActiveItems: 1,
88
+ onActiveChange: onActiveChange
89
+ })),
90
+ group.type === 'buttons' && group.items.length && group.items.map((item)=>{
91
+ return /*#__PURE__*/ _jsx(ButtonGroupItem, {
92
+ anchorElem: anchorElem,
93
+ editor: editor,
94
+ item: item
95
+ }, item.key);
96
+ }),
97
+ index < editorConfig.features.toolbarFixed?.groups.length - 1 && /*#__PURE__*/ _jsx("div", {
98
+ className: "divider"
99
+ })
100
+ ]
101
+ }, group.key);
99
102
  }
100
103
  function FixedToolbar({ anchorElem, editor, editorConfig }) {
101
- return /*#__PURE__*/ React.createElement("div", {
104
+ return /*#__PURE__*/ _jsx("div", {
102
105
  className: "fixed-toolbar",
103
106
  onFocus: (event)=>{
104
107
  // Prevent other focus events being triggered. Otherwise, if this was to be clicked while in a child editor,
105
108
  // the parent editor will be focused, and the child editor will lose focus.
106
109
  event.stopPropagation();
107
- }
108
- }, editor.isEditable() && /*#__PURE__*/ React.createElement(React.Fragment, null, editorConfig?.features && editorConfig.features?.toolbarFixed?.groups.map((group, i)=>{
109
- return /*#__PURE__*/ React.createElement(ToolbarGroupComponent, {
110
- anchorElem: anchorElem,
111
- editor: editor,
112
- editorConfig: editorConfig,
113
- group: group,
114
- index: i,
115
- key: group.key
116
- });
117
- })));
110
+ },
111
+ children: editor.isEditable() && /*#__PURE__*/ _jsx(React.Fragment, {
112
+ children: editorConfig?.features && editorConfig.features?.toolbarFixed?.groups.map((group, i)=>{
113
+ return /*#__PURE__*/ _jsx(ToolbarGroupComponent, {
114
+ anchorElem: anchorElem,
115
+ editor: editor,
116
+ editorConfig: editorConfig,
117
+ group: group,
118
+ index: i
119
+ }, group.key);
120
+ })
121
+ })
122
+ });
118
123
  }
119
124
  const checkParentEditor = (editorFocus)=>{
120
125
  if (editorFocus.parentEditorConfigContext?.editorConfig) {
@@ -142,7 +147,7 @@ export const FixedToolbarPlugin = ({ anchorElem })=>{
142
147
  if (!editorConfig?.features?.toolbarFixed?.groups?.length) {
143
148
  return null;
144
149
  }
145
- return /*#__PURE__*/ React.createElement(FixedToolbar, {
150
+ return /*#__PURE__*/ _jsx(FixedToolbar, {
146
151
  anchorElem: anchorElem,
147
152
  editor: editor,
148
153
  editorConfig: editorConfig
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/field/features/toolbars/fixed/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport * as React from 'react'\n\nimport type { EditorFocusContextType } from '../../../../lexical/EditorFocusProvider.js'\nimport type { SanitizedClientEditorConfig } from '../../../../lexical/config/types.js'\nimport type { PluginComponentWithAnchor } from '../../../types.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorFocus } from '../../../../lexical/EditorFocusProvider.js'\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.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 editorConfig,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { i18n } = useTranslation()\n\n const [dropdownLabel, setDropdownLabel] = React.useState<null | string>(null)\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 setDropdownLabel(null)\n } else {\n setDropdownIcon(null)\n setDropdownLabel(null)\n }\n return\n }\n const item = activeItems[0]\n\n let label = item.key\n if (item.label) {\n label = typeof item.label === 'function' ? item.label({ i18n }) : item.label\n }\n // Crop title to max. 25 characters\n if (label.length > 25) {\n label = label.substring(0, 25) + '...'\n }\n setDropdownLabel(label)\n setDropdownIcon(() => item.ChildComponent)\n }\n\n return (\n <div className={`fixed-toolbar__group fixed-toolbar__group-${group.key}`} key={group.key}>\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 itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\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 itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\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.toolbarFixed?.groups.length - 1 && <div className=\"divider\" />}\n </div>\n )\n}\n\nfunction FixedToolbar({\n anchorElem,\n editor,\n editorConfig,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n}): React.ReactNode {\n return (\n <div\n className=\"fixed-toolbar\"\n onFocus={(event) => {\n // Prevent other focus events being triggered. Otherwise, if this was to be clicked while in a child editor,\n // the parent editor will be focused, and the child editor will lose focus.\n event.stopPropagation()\n }}\n >\n {editor.isEditable() && (\n <React.Fragment>\n {editorConfig?.features &&\n editorConfig.features?.toolbarFixed?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n editorConfig={editorConfig}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n\nconst checkParentEditor = (editorFocus: EditorFocusContextType): boolean => {\n if (editorFocus.parentEditorConfigContext?.editorConfig) {\n if (\n editorFocus.parentEditorConfigContext?.editorConfig.resolvedFeatureMap.has('toolbarFixed')\n ) {\n return true\n } else {\n if (editorFocus.parentEditorFocus) {\n return checkParentEditor(editorFocus.parentEditorFocus)\n }\n }\n }\n return false\n}\n\nexport const FixedToolbarPlugin: PluginComponentWithAnchor<undefined> = ({ anchorElem }) => {\n const [currentEditor] = useLexicalComposerContext()\n const { editorConfig: currentEditorConfig, uuid } = useEditorConfigContext()\n\n const editorFocus = useEditorFocus()\n const editor = editorFocus.focusedEditor || currentEditor\n\n const editorConfig = editorFocus.focusedEditorConfigContext?.editorConfig || currentEditorConfig\n\n // Check if there is a parent editor with a fixed toolbar already\n const hasParentWithFixedToolbar = checkParentEditor(editorFocus)\n\n if (hasParentWithFixedToolbar) {\n return null\n }\n\n if (!editorConfig?.features?.toolbarFixed?.groups?.length) {\n return null\n }\n\n return <FixedToolbar anchorElem={anchorElem} editor={editor} editorConfig={editorConfig} />\n}\n"],"names":["useLexicalComposerContext","useTranslation","React","useEditorFocus","useEditorConfigContext","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","key","ChildComponent","ToolbarGroupComponent","editorConfig","group","index","i18n","dropdownLabel","setDropdownLabel","useState","DropdownIcon","setDropdownIcon","useEffect","type","items","length","onActiveChange","activeItems","label","substring","div","className","Icon","groupKey","itemsContainerClassNames","maxActiveItems","map","features","toolbarFixed","groups","FixedToolbar","onFocus","event","stopPropagation","isEditable","Fragment","i","checkParentEditor","editorFocus","parentEditorConfigContext","resolvedFeatureMap","has","parentEditorFocus","FixedToolbarPlugin","currentEditor","currentEditorConfig","uuid","focusedEditor","focusedEditorConfigContext","hasParentWithFixedToolbar"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,cAAc,QAAQ,uCAAsC;AACrE,YAAYC,WAAW,QAAO;AAO9B,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,sBAAsB,QAAQ,4DAA2D;AAClG,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,eAAe,QAAQ,wCAAuC;AACvE,OAAO,eAAc;AAErB,SAASC,gBAAgB,EACvBC,UAAU,EACVC,MAAM,EACNC,IAAI,EAKL;IACC,IAAIA,KAA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C5C,MAAM6C,QAAQ,QACZhC,cAAcwB,YACbxB,aAAawB,QAAQ,EAAEC,cAAcC,OAAOH,IAAI,CAACtB,OAAOgC;QACtD,qBACE,oBAAClC;YACCN,YAAYA;YACZC,QAAQA;YACRM,cAAcA;YACdC,OAAOA;YACPC,OAAO+B;YACPpC,KAAKI,MAAMJ,GAAG;;IAGpB;AAKZ;AAEA,MAAMqC,oBAAoB,CAACC;IACzB,IAAIA,YAAYC,yBAAyB,EAAEpC,cAAc;QACvD,IACEmC,YAAYC,yBAAyB,EAAEpC,aAAaqC,mBAAmBC,IAAI,iBAC3E;YACA,OAAO;QACT,OAAO;YACL,IAAIH,YAAYI,iBAAiB,EAAE;gBACjC,OAAOL,kBAAkBC,YAAYI,iBAAiB;YACxD;QACF;IACF;IACA,OAAO;AACT;AAEA,OAAO,MAAMC,qBAA2D,CAAC,EAAE/C,UAAU,EAAE;IACrF,MAAM,CAACgD,cAAc,GAAGxD;IACxB,MAAM,EAAEe,cAAc0C,mBAAmB,EAAEC,IAAI,EAAE,GAAGtD;IAEpD,MAAM8C,cAAc/C;IACpB,MAAMM,SAASyC,YAAYS,aAAa,IAAIH;IAE5C,MAAMzC,eAAemC,YAAYU,0BAA0B,EAAE7C,gBAAgB0C;IAE7E,iEAAiE;IACjE,MAAMI,4BAA4BZ,kBAAkBC;IAEpD,IAAIW,2BAA2B;QAC7B,OAAO;IACT;IAEA,IAAI,CAAC9C,cAAcwB,UAAUC,cAAcC,QAAQd,QAAQ;QACzD,OAAO;IACT;IAEA,qBAAO,oBAACe;QAAalC,YAAYA;QAAYC,QAAQA;QAAQM,cAAcA;;AAC7E,EAAC"}
1
+ {"version":3,"sources":["../../../../../../src/field/features/toolbars/fixed/Toolbar/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport * as React from 'react'\n\nimport type { EditorFocusContextType } from '../../../../lexical/EditorFocusProvider.js'\nimport type { SanitizedClientEditorConfig } from '../../../../lexical/config/types.js'\nimport type { PluginComponentWithAnchor } from '../../../types.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorFocus } from '../../../../lexical/EditorFocusProvider.js'\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.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 editorConfig,\n group,\n index,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n group: ToolbarGroup\n index: number\n}): React.ReactNode {\n const { i18n } = useTranslation()\n\n const [dropdownLabel, setDropdownLabel] = React.useState<null | string>(null)\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 setDropdownLabel(null)\n } else {\n setDropdownIcon(null)\n setDropdownLabel(null)\n }\n return\n }\n const item = activeItems[0]\n\n let label = item.key\n if (item.label) {\n label = typeof item.label === 'function' ? item.label({ i18n }) : item.label\n }\n // Crop title to max. 25 characters\n if (label.length > 25) {\n label = label.substring(0, 25) + '...'\n }\n setDropdownLabel(label)\n setDropdownIcon(() => item.ChildComponent)\n }\n\n return (\n <div className={`fixed-toolbar__group fixed-toolbar__group-${group.key}`} key={group.key}>\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 itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\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 itemsContainerClassNames={['fixed-toolbar__dropdown-items']}\n label={dropdownLabel}\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.toolbarFixed?.groups.length - 1 && <div className=\"divider\" />}\n </div>\n )\n}\n\nfunction FixedToolbar({\n anchorElem,\n editor,\n editorConfig,\n}: {\n anchorElem: HTMLElement\n editor: LexicalEditor\n editorConfig: SanitizedClientEditorConfig\n}): React.ReactNode {\n return (\n <div\n className=\"fixed-toolbar\"\n onFocus={(event) => {\n // Prevent other focus events being triggered. Otherwise, if this was to be clicked while in a child editor,\n // the parent editor will be focused, and the child editor will lose focus.\n event.stopPropagation()\n }}\n >\n {editor.isEditable() && (\n <React.Fragment>\n {editorConfig?.features &&\n editorConfig.features?.toolbarFixed?.groups.map((group, i) => {\n return (\n <ToolbarGroupComponent\n anchorElem={anchorElem}\n editor={editor}\n editorConfig={editorConfig}\n group={group}\n index={i}\n key={group.key}\n />\n )\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n\nconst checkParentEditor = (editorFocus: EditorFocusContextType): boolean => {\n if (editorFocus.parentEditorConfigContext?.editorConfig) {\n if (\n editorFocus.parentEditorConfigContext?.editorConfig.resolvedFeatureMap.has('toolbarFixed')\n ) {\n return true\n } else {\n if (editorFocus.parentEditorFocus) {\n return checkParentEditor(editorFocus.parentEditorFocus)\n }\n }\n }\n return false\n}\n\nexport const FixedToolbarPlugin: PluginComponentWithAnchor<undefined> = ({ anchorElem }) => {\n const [currentEditor] = useLexicalComposerContext()\n const { editorConfig: currentEditorConfig, uuid } = useEditorConfigContext()\n\n const editorFocus = useEditorFocus()\n const editor = editorFocus.focusedEditor || currentEditor\n\n const editorConfig = editorFocus.focusedEditorConfigContext?.editorConfig || currentEditorConfig\n\n // Check if there is a parent editor with a fixed toolbar already\n const hasParentWithFixedToolbar = checkParentEditor(editorFocus)\n\n if (hasParentWithFixedToolbar) {\n return null\n }\n\n if (!editorConfig?.features?.toolbarFixed?.groups?.length) {\n return null\n }\n\n return <FixedToolbar anchorElem={anchorElem} editor={editor} editorConfig={editorConfig} />\n}\n"],"names":["useLexicalComposerContext","useTranslation","React","useEditorFocus","useEditorConfigContext","ToolbarButton","ToolbarDropdown","ButtonGroupItem","anchorElem","editor","item","Component","key","ChildComponent","ToolbarGroupComponent","editorConfig","group","index","i18n","dropdownLabel","setDropdownLabel","useState","DropdownIcon","setDropdownIcon","useEffect","type","items","length","onActiveChange","activeItems","label","substring","div","className","Icon","groupKey","itemsContainerClassNames","maxActiveItems","map","features","toolbarFixed","groups","FixedToolbar","onFocus","event","stopPropagation","isEditable","Fragment","i","checkParentEditor","editorFocus","parentEditorConfigContext","resolvedFeatureMap","has","parentEditorFocus","FixedToolbarPlugin","currentEditor","currentEditorConfig","uuid","focusedEditor","focusedEditorConfigContext","hasParentWithFixedToolbar"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAMI,4BAA4BZ,kBAAkBC;IAEpD,IAAIW,2BAA2B;QAC7B,OAAO;IACT;IAEA,IAAI,CAAC9C,cAAcwB,UAAUC,cAAcC,QAAQd,QAAQ;QACzD,OAAO;IACT;IAEA,qBAAO,KAACe;QAAalC,YAAYA;QAAYC,QAAQA;QAAQM,cAAcA;;AAC7E,EAAC"}
@@ -85,14 +85,28 @@ html[data-theme='dark'] {
85
85
  }
86
86
 
87
87
  + .editor-container {
88
- > .editor-scroller > .editor > .ContentEditable__root {
89
- padding-top: calc(var(--base) * 1.25);
88
+ > .editor-scroller > .editor {
89
+ > .ContentEditable__root {
90
+ padding-top: calc(var(--base) * 1.25);
91
+ }
90
92
  }
91
93
 
92
94
  > .editor-placeholder {
93
95
  top: calc(var(--base) * 1.25);
94
96
  }
95
97
  }
98
+ }
96
99
 
97
100
 
101
+ .rich-text-lexical--show-gutter {
102
+ .fixed-toolbar {
103
+ + .editor-container {
104
+ > .editor-scroller > .editor {
105
+ > .ContentEditable__root::before {
106
+ top: calc(var(--base) * 1.25)!important;
107
+ height: calc(100% - calc(var(--base) * 1.25) - 8px)!important;
108
+ }
109
+ }
110
+ }
111
+ }
98
112
  }
@@ -1,4 +1,5 @@
1
1
  'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
3
4
  import { mergeRegister } from '@lexical/utils';
4
5
  import { $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND } from 'lexical';
@@ -13,18 +14,17 @@ import { ToolbarDropdown } from '../../shared/ToolbarDropdown/index.js';
13
14
  import './index.scss';
14
15
  function ButtonGroupItem({ anchorElem, editor, item }) {
15
16
  if (item.Component) {
16
- return item?.Component && /*#__PURE__*/ React.createElement(item.Component, {
17
+ return item?.Component && /*#__PURE__*/ _jsx(item.Component, {
17
18
  anchorElem: anchorElem,
18
19
  editor: editor,
19
- item: item,
20
- key: item.key
21
- });
20
+ item: item
21
+ }, item.key);
22
22
  }
23
- return /*#__PURE__*/ React.createElement(ToolbarButton, {
23
+ return /*#__PURE__*/ _jsx(ToolbarButton, {
24
24
  editor: editor,
25
25
  item: item,
26
- key: item.key
27
- }, item?.ChildComponent && /*#__PURE__*/ React.createElement(item.ChildComponent, null));
26
+ children: item?.ChildComponent && /*#__PURE__*/ _jsx(item.ChildComponent, {})
27
+ }, item.key);
28
28
  }
29
29
  function ToolbarGroupComponent({ anchorElem, editor, group, index }) {
30
30
  const { editorConfig } = useEditorConfigContext();
@@ -50,34 +50,37 @@ function ToolbarGroupComponent({ anchorElem, editor, group, index }) {
50
50
  const item = activeItems[0];
51
51
  setDropdownIcon(()=>item.ChildComponent);
52
52
  };
53
- return /*#__PURE__*/ React.createElement("div", {
53
+ return /*#__PURE__*/ _jsxs("div", {
54
54
  className: `inline-toolbar-popup__group inline-toolbar-popup__group-${group.key}`,
55
- key: group.key
56
- }, group.type === 'dropdown' && group.items.length && (DropdownIcon ? /*#__PURE__*/ React.createElement(ToolbarDropdown, {
57
- Icon: DropdownIcon,
58
- anchorElem: anchorElem,
59
- editor: editor,
60
- groupKey: group.key,
61
- items: group.items,
62
- maxActiveItems: 1,
63
- onActiveChange: onActiveChange
64
- }) : /*#__PURE__*/ React.createElement(ToolbarDropdown, {
65
- anchorElem: anchorElem,
66
- editor: editor,
67
- groupKey: group.key,
68
- items: group.items,
69
- maxActiveItems: 1,
70
- onActiveChange: onActiveChange
71
- })), group.type === 'buttons' && group.items.length && group.items.map((item)=>{
72
- return /*#__PURE__*/ React.createElement(ButtonGroupItem, {
73
- anchorElem: anchorElem,
74
- editor: editor,
75
- item: item,
76
- key: item.key
77
- });
78
- }), index < editorConfig.features.toolbarInline?.groups.length - 1 && /*#__PURE__*/ React.createElement("div", {
79
- className: "divider"
80
- }));
55
+ children: [
56
+ group.type === 'dropdown' && group.items.length && (DropdownIcon ? /*#__PURE__*/ _jsx(ToolbarDropdown, {
57
+ Icon: DropdownIcon,
58
+ anchorElem: anchorElem,
59
+ editor: editor,
60
+ groupKey: group.key,
61
+ items: group.items,
62
+ maxActiveItems: 1,
63
+ onActiveChange: onActiveChange
64
+ }) : /*#__PURE__*/ _jsx(ToolbarDropdown, {
65
+ anchorElem: anchorElem,
66
+ editor: editor,
67
+ groupKey: group.key,
68
+ items: group.items,
69
+ maxActiveItems: 1,
70
+ onActiveChange: onActiveChange
71
+ })),
72
+ group.type === 'buttons' && group.items.length && group.items.map((item)=>{
73
+ return /*#__PURE__*/ _jsx(ButtonGroupItem, {
74
+ anchorElem: anchorElem,
75
+ editor: editor,
76
+ item: item
77
+ }, item.key);
78
+ }),
79
+ index < editorConfig.features.toolbarInline?.groups.length - 1 && /*#__PURE__*/ _jsx("div", {
80
+ className: "divider"
81
+ })
82
+ ]
83
+ }, group.key);
81
84
  }
82
85
  function InlineToolbar({ anchorElem, editor }) {
83
86
  const floatingToolbarRef = useRef(null);
@@ -215,21 +218,26 @@ function InlineToolbar({ anchorElem, editor }) {
215
218
  editor,
216
219
  $updateTextFormatFloatingToolbar
217
220
  ]);
218
- return /*#__PURE__*/ React.createElement("div", {
221
+ return /*#__PURE__*/ _jsxs("div", {
219
222
  className: "inline-toolbar-popup",
220
- ref: floatingToolbarRef
221
- }, /*#__PURE__*/ React.createElement("div", {
222
- className: "caret",
223
- ref: caretRef
224
- }), editor.isEditable() && /*#__PURE__*/ React.createElement(React.Fragment, null, editorConfig?.features && editorConfig.features?.toolbarInline?.groups.map((group, i)=>{
225
- return /*#__PURE__*/ React.createElement(ToolbarGroupComponent, {
226
- anchorElem: anchorElem,
227
- editor: editor,
228
- group: group,
229
- index: i,
230
- key: group.key
231
- });
232
- })));
223
+ ref: floatingToolbarRef,
224
+ children: [
225
+ /*#__PURE__*/ _jsx("div", {
226
+ className: "caret",
227
+ ref: caretRef
228
+ }),
229
+ editor.isEditable() && /*#__PURE__*/ _jsx(React.Fragment, {
230
+ children: editorConfig?.features && editorConfig.features?.toolbarInline?.groups.map((group, i)=>{
231
+ return /*#__PURE__*/ _jsx(ToolbarGroupComponent, {
232
+ anchorElem: anchorElem,
233
+ editor: editor,
234
+ group: group,
235
+ index: i
236
+ }, group.key);
237
+ })
238
+ })
239
+ ]
240
+ });
233
241
  }
234
242
  function useInlineToolbar(editor, anchorElem) {
235
243
  const [isText, setIsText] = useState(false);
@@ -299,7 +307,7 @@ function useInlineToolbar(editor, anchorElem) {
299
307
  if (!isText) {
300
308
  return null;
301
309
  }
302
- return /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(InlineToolbar, {
310
+ return /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsx(InlineToolbar, {
303
311
  anchorElem: anchorElem,
304
312
  editor: editor
305
313
  }), anchorElem);