@webiny/lexical-editor 0.0.0-unstable.ecd8734205 → 5.35.0-beta.0

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 (186) hide show
  1. package/commands/webiny-list.d.ts +7 -0
  2. package/commands/webiny-list.js +13 -0
  3. package/commands/webiny-list.js.map +1 -0
  4. package/commands/webiny-quote.d.ts +5 -0
  5. package/commands/webiny-quote.js +9 -0
  6. package/commands/webiny-quote.js.map +1 -0
  7. package/components/AddRichTextEditorNodeType.js.map +1 -1
  8. package/components/AddRichTextEditorPlugin.d.ts +2 -0
  9. package/components/AddRichTextEditorPlugin.js +4 -2
  10. package/components/AddRichTextEditorPlugin.js.map +1 -1
  11. package/components/AddToolbarAction.js.map +1 -1
  12. package/components/Editor/HeadingEditor.js +2 -1
  13. package/components/Editor/HeadingEditor.js.map +1 -1
  14. package/components/Editor/ParagraphEditor.js +3 -3
  15. package/components/Editor/ParagraphEditor.js.map +1 -1
  16. package/components/Editor/RichTextEditor.d.ts +4 -1
  17. package/components/Editor/RichTextEditor.js +37 -6
  18. package/components/Editor/RichTextEditor.js.map +1 -1
  19. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +9 -0
  20. package/components/LexicalEditorConfig/LexicalEditorConfig.js +17 -0
  21. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -0
  22. package/components/LexicalHtmlRenderer.d.ts +8 -1
  23. package/components/LexicalHtmlRenderer.js +29 -6
  24. package/components/LexicalHtmlRenderer.js.map +1 -1
  25. package/components/Toolbar/HeadingToolbar.js.map +1 -1
  26. package/components/Toolbar/ParagraphToolbar.js.map +1 -1
  27. package/components/Toolbar/Toolbar.css +9 -0
  28. package/components/Toolbar/Toolbar.js +25 -5
  29. package/components/Toolbar/Toolbar.js.map +1 -1
  30. package/components/ToolbarActions/BoldAction.d.ts +0 -3
  31. package/components/ToolbarActions/BoldAction.js +8 -3
  32. package/components/ToolbarActions/BoldAction.js.map +1 -1
  33. package/components/ToolbarActions/BulletListAction.d.ts +0 -3
  34. package/components/ToolbarActions/BulletListAction.js +17 -55
  35. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  36. package/components/ToolbarActions/CodeHighlightAction.d.ts +0 -4
  37. package/components/ToolbarActions/CodeHighlightAction.js +8 -4
  38. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  39. package/components/ToolbarActions/FontColorAction.d.ts +11 -0
  40. package/components/ToolbarActions/FontColorAction.js +83 -0
  41. package/components/ToolbarActions/FontColorAction.js.map +1 -0
  42. package/components/ToolbarActions/FontSizeAction.js +0 -3
  43. package/components/ToolbarActions/FontSizeAction.js.map +1 -1
  44. package/components/ToolbarActions/ItalicAction.d.ts +0 -3
  45. package/components/ToolbarActions/ItalicAction.js +8 -3
  46. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  47. package/components/ToolbarActions/LinkAction.d.ts +0 -5
  48. package/components/ToolbarActions/LinkAction.js +0 -5
  49. package/components/ToolbarActions/LinkAction.js.map +1 -1
  50. package/components/ToolbarActions/NumberedListAction.d.ts +0 -3
  51. package/components/ToolbarActions/NumberedListAction.js +17 -53
  52. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  53. package/components/ToolbarActions/QuoteAction.d.ts +0 -2
  54. package/components/ToolbarActions/QuoteAction.js +16 -29
  55. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  56. package/components/ToolbarActions/TypographyAction.d.ts +11 -0
  57. package/components/ToolbarActions/TypographyAction.js +118 -0
  58. package/components/ToolbarActions/TypographyAction.js.map +1 -0
  59. package/components/ToolbarActions/UnderlineAction.d.ts +0 -3
  60. package/components/ToolbarActions/UnderlineAction.js +8 -3
  61. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  62. package/components/ToolbarPresets/HeadingToolbarPreset.js +8 -0
  63. package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -1
  64. package/components/ToolbarPresets/ParagraphToolbarPreset.js +8 -0
  65. package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -1
  66. package/context/FontColorActionContext.d.ts +6 -0
  67. package/context/FontColorActionContext.js +10 -0
  68. package/context/FontColorActionContext.js.map +1 -0
  69. package/context/RichTextEditorContext.d.ts +10 -0
  70. package/context/RichTextEditorContext.js +28 -1
  71. package/context/RichTextEditorContext.js.map +1 -1
  72. package/context/SharedHistoryContext.d.ts +11 -0
  73. package/context/SharedHistoryContext.js +26 -0
  74. package/context/SharedHistoryContext.js.map +1 -0
  75. package/context/TypographyActionContext.d.ts +7 -0
  76. package/context/TypographyActionContext.js +10 -0
  77. package/context/TypographyActionContext.js.map +1 -0
  78. package/hooks/useFontColorPicker.d.ts +2 -0
  79. package/hooks/useFontColorPicker.js +15 -0
  80. package/hooks/useFontColorPicker.js.map +1 -0
  81. package/hooks/useRichTextEditor.js.map +1 -1
  82. package/hooks/useTypographyAction.d.ts +1 -0
  83. package/hooks/useTypographyAction.js +15 -0
  84. package/hooks/useTypographyAction.js.map +1 -0
  85. package/hooks/useWebinyList.d.ts +2 -0
  86. package/hooks/useWebinyList.js +39 -0
  87. package/hooks/useWebinyList.js.map +1 -0
  88. package/hooks/useWebinyQuote.d.ts +2 -0
  89. package/hooks/useWebinyQuote.js +20 -0
  90. package/hooks/useWebinyQuote.js.map +1 -0
  91. package/images/icons/font-color.svg +1 -0
  92. package/index.d.ts +7 -1
  93. package/index.js +44 -2
  94. package/index.js.map +1 -1
  95. package/nodes/FontColorNode.d.ts +43 -0
  96. package/nodes/FontColorNode.js +127 -0
  97. package/nodes/FontColorNode.js.map +1 -0
  98. package/nodes/TypographyElementNode.d.ts +42 -0
  99. package/nodes/TypographyElementNode.js +154 -0
  100. package/nodes/TypographyElementNode.js.map +1 -0
  101. package/nodes/WebinyQuoteNode.d.ts +29 -0
  102. package/nodes/WebinyQuoteNode.js +148 -0
  103. package/nodes/WebinyQuoteNode.js.map +1 -0
  104. package/nodes/list-node/WebinyListItemNode.d.ts +46 -0
  105. package/nodes/list-node/WebinyListItemNode.js +441 -0
  106. package/nodes/list-node/WebinyListItemNode.js.map +1 -0
  107. package/nodes/list-node/WebinyListNode.d.ts +38 -0
  108. package/nodes/list-node/WebinyListNode.js +253 -0
  109. package/nodes/list-node/WebinyListNode.js.map +1 -0
  110. package/nodes/list-node/formatList.d.ts +12 -0
  111. package/nodes/list-node/formatList.js +423 -0
  112. package/nodes/list-node/formatList.js.map +1 -0
  113. package/nodes/webinyNodes.d.ts +6 -1
  114. package/nodes/webinyNodes.js +8 -2
  115. package/nodes/webinyNodes.js.map +1 -1
  116. package/package.json +9 -6
  117. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +1 -1
  118. package/plugins/AutoLinkPlugin/index.js.map +1 -1
  119. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  120. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +1 -1
  121. package/plugins/ClickableLinkPlugin/index.js.map +1 -1
  122. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  123. package/plugins/CodeHighlightPlugin/index.js.map +1 -1
  124. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  125. package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
  126. package/plugins/FontColorPlugin/FontColorPlugin.d.ts +2 -0
  127. package/plugins/FontColorPlugin/FontColorPlugin.js +38 -0
  128. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -0
  129. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +1 -1
  130. package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
  131. package/plugins/TypographyPlugin/TypographyPlugin.d.ts +2 -0
  132. package/plugins/TypographyPlugin/TypographyPlugin.js +31 -0
  133. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -0
  134. package/plugins/WebinyListPLugin/WebinyListPlugin.d.ts +1 -0
  135. package/plugins/WebinyListPLugin/WebinyListPlugin.js +25 -0
  136. package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +1 -0
  137. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts +1 -0
  138. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +24 -0
  139. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -0
  140. package/themes/webinyLexicalTheme.css +0 -2
  141. package/themes/webinyLexicalTheme.d.ts +7 -8
  142. package/themes/webinyLexicalTheme.js +7 -27
  143. package/themes/webinyLexicalTheme.js.map +1 -1
  144. package/types.d.ts +59 -0
  145. package/types.js +8 -1
  146. package/types.js.map +1 -1
  147. package/ui/Divider.js.map +1 -1
  148. package/ui/DropDown.d.ts +2 -1
  149. package/ui/DropDown.js +7 -2
  150. package/ui/DropDown.js.map +1 -1
  151. package/ui/LinkPreview.js.map +1 -1
  152. package/ui/Placeholder.js.map +1 -1
  153. package/ui/TextInput.js.map +1 -1
  154. package/ui/ToolbarActionDialog.d.ts +12 -0
  155. package/ui/ToolbarActionDialog.js +106 -0
  156. package/ui/ToolbarActionDialog.js.map +1 -0
  157. package/utils/generateInitialLexicalValue.js.map +1 -1
  158. package/utils/getDOMRangeRect.js.map +1 -1
  159. package/utils/getLexicalTextSelectionState.d.ts +5 -0
  160. package/utils/getLexicalTextSelectionState.js +141 -0
  161. package/utils/getLexicalTextSelectionState.js.map +1 -0
  162. package/utils/getSelectedNode.js.map +1 -1
  163. package/utils/isValidJSON.js.map +1 -1
  164. package/utils/isValidLexicalData.js.map +1 -1
  165. package/utils/nodes/clearNodeFormating.d.ts +2 -0
  166. package/utils/nodes/clearNodeFormating.js +28 -0
  167. package/utils/nodes/clearNodeFormating.js.map +1 -0
  168. package/utils/nodes/formatToParagraph.d.ts +2 -0
  169. package/utils/nodes/formatToParagraph.js +19 -0
  170. package/utils/nodes/formatToParagraph.js.map +1 -0
  171. package/utils/nodes/formatToQuote.d.ts +2 -0
  172. package/utils/nodes/formatToQuote.js +20 -0
  173. package/utils/nodes/formatToQuote.js.map +1 -0
  174. package/utils/nodes/list-node.d.ts +11 -0
  175. package/utils/nodes/list-node.js +107 -0
  176. package/utils/nodes/list-node.js.map +1 -0
  177. package/utils/point.js.map +1 -1
  178. package/utils/rect.js.map +1 -1
  179. package/utils/sanitizeUrl.js.map +1 -1
  180. package/utils/setFloatingElemPosition.js.map +1 -1
  181. package/utils/styleObjectToString.d.ts +2 -0
  182. package/utils/styleObjectToString.js +22 -0
  183. package/utils/styleObjectToString.js.map +1 -0
  184. package/utils/toTypographyEmotionMap.d.ts +3 -0
  185. package/utils/toTypographyEmotionMap.js +36 -0
  186. package/utils/toTypographyEmotionMap.js.map +1 -0
package/ui/DropDown.js CHANGED
@@ -45,6 +45,8 @@ function DropDownItem(_ref) {
45
45
  function DropDownItems(_ref2) {
46
46
  var children = _ref2.children,
47
47
  dropDownRef = _ref2.dropDownRef,
48
+ _ref2$showScroll = _ref2.showScroll,
49
+ showScroll = _ref2$showScroll === void 0 ? true : _ref2$showScroll,
48
50
  onClose = _ref2.onClose;
49
51
  var _useState = (0, React.useState)(),
50
52
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -102,7 +104,7 @@ function DropDownItems(_ref2) {
102
104
  return /*#__PURE__*/React.createElement(DropDownContext.Provider, {
103
105
  value: contextValue
104
106
  }, /*#__PURE__*/React.createElement("div", {
105
- className: "lexical-dropdown",
107
+ className: "lexical-dropdown ".concat(showScroll ? "" : "no-scroll"),
106
108
  ref: dropDownRef !== null && dropDownRef !== void 0 ? dropDownRef : null,
107
109
  onKeyDown: handleKeyDown
108
110
  }, children));
@@ -115,7 +117,9 @@ function DropDown(_ref3) {
115
117
  buttonClassName = _ref3.buttonClassName,
116
118
  buttonIconClassName = _ref3.buttonIconClassName,
117
119
  children = _ref3.children,
118
- stopCloseOnClickSelf = _ref3.stopCloseOnClickSelf;
120
+ stopCloseOnClickSelf = _ref3.stopCloseOnClickSelf,
121
+ _ref3$showScroll = _ref3.showScroll,
122
+ showScroll = _ref3$showScroll === void 0 ? true : _ref3$showScroll;
119
123
  var buttonRef = (0, React.useRef)(null);
120
124
  var _useState5 = (0, React.useState)(false),
121
125
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
@@ -163,6 +167,7 @@ function DropDown(_ref3) {
163
167
  }), showDropDown && /*#__PURE__*/React.createElement("div", {
164
168
  className: "lexical-dropdown-container"
165
169
  }, /*#__PURE__*/React.createElement(DropDownItems, {
170
+ showScroll: showScroll,
166
171
  onClose: handleClose
167
172
  }, children)));
168
173
  }
@@ -1 +1 @@
1
- {"version":3,"names":["React","_interopRequireWildcard","require","DropDownContext","createContext","DropDownItem","_ref","children","className","onClick","title","ref","useRef","dropDownContext","useContext","Error","registerItem","useEffect","current","createElement","DropDownItems","_ref2","dropDownRef","onClose","_useState","useState","_useState2","_slicedToArray2","default","items","setItems","_useState3","_useState4","highlightedItem","setHighlightedItem","useCallback","itemRef","prev","concat","_toConsumableArray2","handleKeyDown","event","key","includes","preventDefault","index","indexOf","length","contextValue","useMemo","focus","Provider","value","onKeyDown","DropDown","_ref3","_ref3$disabled","disabled","buttonLabel","buttonAriaLabel","buttonClassName","buttonIconClassName","stopCloseOnClickSelf","buttonRef","_useState5","_useState6","showDropDown","setShowDropDown","handleClose","button","handle","target","contains","document","addEventListener","removeEventListener","style","position"],"sources":["DropDown.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport * as React from \"react\";\n\ntype DropDownContextType = {\n registerItem: (ref: React.RefObject<HTMLButtonElement>) => void;\n};\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null);\n\nexport function DropDownItem({\n children,\n className,\n onClick,\n title\n}: {\n children: React.ReactNode;\n className: string;\n onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;\n title?: string;\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 && ref.current) {\n registerItem(ref);\n }\n }, [ref, registerItem]);\n\n return (\n <button className={className} onClick={onClick} ref={ref} title={title}>\n {children}\n </button>\n );\n}\n\nfunction DropDownItems({\n children,\n dropDownRef,\n onClose\n}: {\n children: React.ReactNode;\n dropDownRef?: React.Ref<HTMLDivElement>;\n onClose: () => void;\n}) {\n const [items, setItems] = useState<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 ? [...prev, itemRef] : [itemRef]));\n },\n [setItems]\n );\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (!items) {\n return;\n }\n\n const key = event.key;\n\n if ([\"Escape\", \"ArrowUp\", \"ArrowDown\", \"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) {\n return items[0];\n }\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) {\n return items[0];\n }\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 && !highlightedItem) {\n setHighlightedItem(items[0]);\n }\n\n if (highlightedItem && highlightedItem.current) {\n highlightedItem.current.focus();\n }\n }, [items, highlightedItem]);\n\n return (\n <DropDownContext.Provider value={contextValue}>\n <div className=\"lexical-dropdown\" ref={dropDownRef ?? null} onKeyDown={handleKeyDown}>\n {children}\n </div>\n </DropDownContext.Provider>\n );\n}\n\nexport function DropDown({\n disabled = false,\n buttonLabel,\n buttonAriaLabel,\n buttonClassName,\n buttonIconClassName,\n children,\n stopCloseOnClickSelf\n}: {\n disabled?: boolean;\n buttonAriaLabel?: string;\n buttonClassName: string;\n buttonIconClassName?: string;\n buttonLabel?: string;\n children: ReactNode;\n stopCloseOnClickSelf?: boolean;\n}): JSX.Element {\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [showDropDown, setShowDropDown] = useState(false);\n\n const handleClose = () => {\n setShowDropDown(false);\n if (buttonRef && buttonRef.current) {\n buttonRef.current.focus();\n }\n };\n\n useEffect(() => {\n const button = buttonRef.current;\n if (button === null || !showDropDown) {\n return;\n }\n\n const handle = (event: MouseEvent) => {\n const target = event.target;\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 }, [buttonRef, showDropDown, stopCloseOnClickSelf]);\n\n return (\n <button\n style={{ position: \"relative\" }}\n disabled={disabled}\n aria-label={buttonAriaLabel || buttonLabel}\n className={buttonClassName}\n onClick={() => setShowDropDown(!showDropDown)}\n ref={buttonRef}\n >\n {buttonIconClassName && <span className={buttonIconClassName} />}\n {buttonLabel && <span className=\"text dropdown-button-text\">{buttonLabel}</span>}\n <i className=\"chevron-down\" />\n {showDropDown && (\n <div className={\"lexical-dropdown-container\"}>\n <DropDownItems onClose={handleClose}>{children}</DropDownItems>\n </div>\n )}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;;AAQA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,IAAMC,eAAe,gBAAGH,KAAK,CAACI,aAAa,CAA6B,IAAI,CAAC;AAEtE,SAASC,YAAYA,CAAAC,IAAA,EAUzB;EAAA,IATCC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,SAAS,GAAAF,IAAA,CAAT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,SAAS,EAAEqD;EAAoB,EAAG,EAC/DH,WAAW,iBAAI1D,KAAA,CAAAmB,aAAA;IAAMX,SAAS,EAAC;EAA2B,GAAEkD,WAAW,CAAQ,eAChF1D,KAAA,CAAAmB,aAAA;IAAGX,SAAS,EAAC;EAAc,EAAG,EAC7B0D,YAAY,iBACTlE,KAAA,CAAAmB,aAAA;IAAKX,SAAS,EAAE;EAA6B,gBACzCR,KAAA,CAAAmB,aAAA,CAACC,aAAa;IAACG,OAAO,EAAE6C;EAAY,GAAE7D,QAAQ,CAAiB,CAEtE,CACI;AAEjB"}
1
+ {"version":3,"names":["DropDownContext","React","createContext","DropDownItem","children","className","onClick","title","ref","useRef","dropDownContext","useContext","Error","registerItem","useEffect","current","DropDownItems","dropDownRef","showScroll","onClose","useState","items","setItems","highlightedItem","setHighlightedItem","useCallback","itemRef","prev","handleKeyDown","event","key","includes","preventDefault","index","indexOf","length","contextValue","useMemo","focus","DropDown","disabled","buttonLabel","buttonAriaLabel","buttonClassName","buttonIconClassName","stopCloseOnClickSelf","buttonRef","showDropDown","setShowDropDown","handleClose","button","handle","target","contains","document","addEventListener","removeEventListener","position"],"sources":["DropDown.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport * as React from \"react\";\n\ntype DropDownContextType = {\n registerItem: (ref: React.RefObject<HTMLButtonElement>) => void;\n};\n\nconst DropDownContext = React.createContext<DropDownContextType | null>(null);\n\nexport function DropDownItem({\n children,\n className,\n onClick,\n title\n}: {\n children: React.ReactNode;\n className: string;\n onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;\n title?: string;\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 && ref.current) {\n registerItem(ref);\n }\n }, [ref, registerItem]);\n\n return (\n <button className={className} onClick={onClick} ref={ref} title={title}>\n {children}\n </button>\n );\n}\n\nfunction DropDownItems({\n children,\n dropDownRef,\n showScroll = true,\n onClose\n}: {\n children: React.ReactNode;\n dropDownRef?: React.Ref<HTMLDivElement>;\n showScroll?: boolean;\n onClose: () => void;\n}) {\n const [items, setItems] = useState<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 ? [...prev, itemRef] : [itemRef]));\n },\n [setItems]\n );\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (!items) {\n return;\n }\n\n const key = event.key;\n\n if ([\"Escape\", \"ArrowUp\", \"ArrowDown\", \"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) {\n return items[0];\n }\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) {\n return items[0];\n }\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 && !highlightedItem) {\n setHighlightedItem(items[0]);\n }\n\n if (highlightedItem && highlightedItem.current) {\n highlightedItem.current.focus();\n }\n }, [items, highlightedItem]);\n\n return (\n <DropDownContext.Provider value={contextValue}>\n <div\n className={`lexical-dropdown ${showScroll ? \"\" : \"no-scroll\"}`}\n ref={dropDownRef ?? null}\n onKeyDown={handleKeyDown}\n >\n {children}\n </div>\n </DropDownContext.Provider>\n );\n}\n\nexport function DropDown({\n disabled = false,\n buttonLabel,\n buttonAriaLabel,\n buttonClassName,\n buttonIconClassName,\n children,\n stopCloseOnClickSelf,\n showScroll = true\n}: {\n disabled?: boolean;\n buttonAriaLabel?: string;\n buttonClassName: string;\n buttonIconClassName?: string;\n buttonLabel?: string;\n children: ReactNode;\n stopCloseOnClickSelf?: boolean;\n showScroll?: boolean;\n}): JSX.Element {\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [showDropDown, setShowDropDown] = useState(false);\n\n const handleClose = () => {\n setShowDropDown(false);\n if (buttonRef && buttonRef.current) {\n buttonRef.current.focus();\n }\n };\n\n useEffect(() => {\n const button = buttonRef.current;\n if (button === null || !showDropDown) {\n return;\n }\n\n const handle = (event: MouseEvent) => {\n const target = event.target;\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 }, [buttonRef, showDropDown, stopCloseOnClickSelf]);\n\n return (\n <button\n style={{ position: \"relative\" }}\n disabled={disabled}\n aria-label={buttonAriaLabel || buttonLabel}\n className={buttonClassName}\n onClick={() => setShowDropDown(!showDropDown)}\n ref={buttonRef}\n >\n {buttonIconClassName && <span className={buttonIconClassName} />}\n {buttonLabel && <span className=\"text dropdown-button-text\">{buttonLabel}</span>}\n <i className=\"chevron-down\" />\n {showDropDown && (\n <div className={\"lexical-dropdown-container\"}>\n <DropDownItems showScroll={showScroll} onClose={handleClose}>\n {children}\n </DropDownItems>\n </div>\n )}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;;AAQA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,IAAMA,eAAe,gBAAGC,KAAK,CAACC,aAAa,CAA6B,IAAI,CAAC;AAEtE,SAASC,YAAY,OAUzB;EAAA,IATCC,QAAQ,QAARA,QAAQ;IACRC,SAAS,QAATA,SAAS;IACTC,OAAO,QAAPA,OAAO;IACPC,KAAK,QAALA,KAAK;EAOL,IAAMC,GAAG,GAAG,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MAAM,CAAS,EAAE;QAClCJ,eAAe,CAAC,KAAK,CAAC;MAC1B;IACJ,CAAC;IACDM,QAAQ,CAACC,gBAAgB,CAAC,OAAO,EAAEJ,MAAM,CAAC;IAE1C,OAAO,YAAM;MACTG,QAAQ,CAACE,mBAAmB,CAAC,OAAO,EAAEL,MAAM,CAAC;IACjD,CAAC;EACL,CAAC,EAAE,CAACL,SAAS,EAAEC,YAAY,EAAEF,oBAAoB,CAAC,CAAC;EAEnD,oBACI;IACI,KAAK,EAAE;MAAEY,QAAQ,EAAE;IAAW,CAAE;IAChC,QAAQ,EAAEjB,QAAS;IACnB,cAAYE,eAAe,IAAID,WAAY;IAC3C,SAAS,EAAEE,eAAgB;IAC3B,OAAO,EAAE;MAAA,OAAMK,eAAe,CAAC,CAACD,YAAY,CAAC;IAAA,CAAC;IAC9C,GAAG,EAAED;EAAU,GAEdF,mBAAmB,iBAAI;IAAM,SAAS,EAAEA;EAAoB,EAAG,EAC/DH,WAAW,iBAAI;IAAM,SAAS,EAAC;EAA2B,GAAEA,WAAW,CAAQ,eAChF;IAAG,SAAS,EAAC;EAAc,EAAG,EAC7BM,YAAY,iBACT;IAAK,SAAS,EAAE;EAA6B,gBACzC,oBAAC,aAAa;IAAC,UAAU,EAAE7B,UAAW;IAAC,OAAO,EAAE+B;EAAY,GACvD7C,QAAQ,CACG,CAEvB,CACI;AAEjB"}
@@ -1 +1 @@
1
- {"version":3,"names":["require","React","_interopRequireWildcard","PREVIEW_CACHE","URL_MATCHER","useSuspenseRequest","url","cached","match","preview","fetch","concat","encodeURI","then","response","json","catch","Promise","LinkPreviewContent","_ref","_useSuspenseRequest","createElement","className","img","src","alt","title","domain","description","Glimmer","props","Object","assign","style","_objectSpread2","default","animationDelay","String","index","LinkPreview","_ref2","Suspense","fallback","Fragment","height","width"],"sources":["LinkPreview.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./LinkPreview.css\";\n\nimport * as React from \"react\";\nimport { CSSProperties, Suspense } from \"react\";\n\ntype Preview = {\n title: string;\n description: string;\n img: string;\n domain: string;\n} | null;\n\n// Cached responses or running request promises\nconst PREVIEW_CACHE: Record<string, Promise<Preview> | { preview: Preview }> = {};\n\nconst URL_MATCHER =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;\n\nfunction useSuspenseRequest(url: string) {\n let cached = PREVIEW_CACHE[url];\n\n if (!url.match(URL_MATCHER)) {\n return { preview: null };\n }\n\n if (!cached) {\n cached = PREVIEW_CACHE[url] = fetch(`/api/link-preview?url=${encodeURI(url)}`)\n .then(response => response.json())\n .then(preview => {\n PREVIEW_CACHE[url] = preview;\n return preview;\n })\n .catch(() => {\n PREVIEW_CACHE[url] = { preview: null };\n });\n }\n\n if (cached instanceof Promise) {\n throw cached;\n }\n\n return cached;\n}\n\nfunction LinkPreviewContent({\n url\n}: Readonly<{\n url: string;\n}>): JSX.Element | null {\n const { preview } = useSuspenseRequest(url);\n if (preview === null) {\n return null;\n }\n return (\n <div className=\"LinkPreview__container\">\n {preview.img && (\n <div className=\"LinkPreview__imageWrapper\">\n <img src={preview.img} alt={preview.title} className=\"LinkPreview__image\" />\n </div>\n )}\n {preview.domain && <div className=\"LinkPreview__domain\">{preview.domain}</div>}\n {preview.title && <div className=\"LinkPreview__title\">{preview.title}</div>}\n {preview.description && (\n <div className=\"LinkPreview__description\">{preview.description}</div>\n )}\n </div>\n );\n}\n\nfunction Glimmer(props: { style: CSSProperties; index: number }): JSX.Element {\n return (\n <div\n className=\"LinkPreview__glimmer\"\n {...props}\n style={{\n animationDelay: String((props.index || 0) * 300),\n ...(props.style || {})\n }}\n />\n );\n}\n\nexport function LinkPreview({\n url\n}: Readonly<{\n url: string;\n}>): JSX.Element {\n return (\n <Suspense\n fallback={\n <>\n <Glimmer style={{ height: \"80px\" }} index={0} />\n <Glimmer style={{ width: \"60%\" }} index={1} />\n <Glimmer style={{ width: \"80%\" }} index={2} />\n </>\n }\n >\n <LinkPreviewContent url={url} />\n </Suspense>\n );\n}\n"],"mappings":";;;;;;;;;AAQAA,OAAA;AAEA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA;AACA,IAAMG,aAAsE,GAAG,CAAC,CAAC;AAEjF,IAAMC,WAAW,GACb,iHAAiH;AAErH,SAASC,kBAAkBA,CAACC,GAAW,EAAE;EACrC,IAAIC,MAAM,GAAGJ,aAAa,CAACG,GAAG,CAAC;EAE/B,IAAI,CAACA,GAAG,CAACE,KAAK,CAACJ,WAAW,CAAC,EAAE;IACzB,OAAO;MAAEK,OAAO,EAAE;IAAK,CAAC;EAC5B;EAEA,IAAI,CAACF,MAAM,EAAE;IACTA,MAAM,GAAGJ,aAAa,CAACG,GAAG,CAAC,GAAGI,KAAK,0BAAAC,MAAA,CAA0BC,SAAS,CAACN,GAAG,CAAC,EAAG,CACzEO,IAAI,CAAC,UAAAC,QAAQ;MAAA,OAAIA,QAAQ,CAACC,IAAI,EAAE;IAAA,EAAC,CACjCF,IAAI,CAAC,UAAAJ,OAAO,EAAI;MACbN,aAAa,CAACG,GAAG,CAAC,GAAGG,OAAO;MAC5B,OAAOA,OAAO;IAClB,CAAC,CAAC,CACDO,KAAK,CAAC,YAAM;MACTb,aAAa,CAACG,GAAG,CAAC,GAAG;QAAEG,OAAO,EAAE;MAAK,CAAC;IAC1C,CAAC,CAAC;EACV;EAEA,IAAIF,MAAM,YAAYU,OAAO,EAAE;IAC3B,MAAMV,MAAM;EAChB;EAEA,OAAOA,MAAM;AACjB;AAEA,SAASW,kBAAkBA,CAAAC,IAAA,EAIH;EAAA,IAHpBb,GAAG,GAAAa,IAAA,CAAHb,GAAG;EAIH,IAAAc,mBAAA,G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,CAACpB,KAAA,CAAAwC,QAAQ;IACLC,QAAQ,eACJzC,KAAA,CAAAoB,aAAA,CAAApB,KAAA,CAAA0C,QAAA,qBACI1C,KAAA,CAAAoB,aAAA,CAACQ,OAAO;MAACI,KAAK,EAAE;QAAEW,MAAM,EAAE;MAAO,CAAE;MAACN,KAAK,EAAE;IAAE,EAAG,eAChDrC,KAAA,CAAAoB,aAAA,CAACQ,OAAO;MAACI,KAAK,EAAE;QAAEY,KAAK,EAAE;MAAM,CAAE;MAACP,KAAK,EAAE;IAAE,EAAG,eAC9CrC,KAAA,CAAAoB,aAAA,CAACQ,OAAO;MAACI,KAAK,EAAE;QAAEY,KAAK,EAAE;MAAM,CAAE;MAACP,KAAK,EAAE;IAAE,EAAG;EAErD,gBAEDrC,KAAA,CAAAoB,aAAA,CAACH,kBAAkB;IAACZ,GAAG,EAAEA;EAAI,EAAG,CACzB;AAEnB"}
1
+ {"version":3,"names":["PREVIEW_CACHE","URL_MATCHER","useSuspenseRequest","url","cached","match","preview","fetch","encodeURI","then","response","json","catch","Promise","LinkPreviewContent","img","title","domain","description","Glimmer","props","animationDelay","String","index","style","LinkPreview","height","width"],"sources":["LinkPreview.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./LinkPreview.css\";\n\nimport * as React from \"react\";\nimport { CSSProperties, Suspense } from \"react\";\n\ntype Preview = {\n title: string;\n description: string;\n img: string;\n domain: string;\n} | null;\n\n// Cached responses or running request promises\nconst PREVIEW_CACHE: Record<string, Promise<Preview> | { preview: Preview }> = {};\n\nconst URL_MATCHER =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;\n\nfunction useSuspenseRequest(url: string) {\n let cached = PREVIEW_CACHE[url];\n\n if (!url.match(URL_MATCHER)) {\n return { preview: null };\n }\n\n if (!cached) {\n cached = PREVIEW_CACHE[url] = fetch(`/api/link-preview?url=${encodeURI(url)}`)\n .then(response => response.json())\n .then(preview => {\n PREVIEW_CACHE[url] = preview;\n return preview;\n })\n .catch(() => {\n PREVIEW_CACHE[url] = { preview: null };\n });\n }\n\n if (cached instanceof Promise) {\n throw cached;\n }\n\n return cached;\n}\n\nfunction LinkPreviewContent({\n url\n}: Readonly<{\n url: string;\n}>): JSX.Element | null {\n const { preview } = useSuspenseRequest(url);\n if (preview === null) {\n return null;\n }\n return (\n <div className=\"LinkPreview__container\">\n {preview.img && (\n <div className=\"LinkPreview__imageWrapper\">\n <img src={preview.img} alt={preview.title} className=\"LinkPreview__image\" />\n </div>\n )}\n {preview.domain && <div className=\"LinkPreview__domain\">{preview.domain}</div>}\n {preview.title && <div className=\"LinkPreview__title\">{preview.title}</div>}\n {preview.description && (\n <div className=\"LinkPreview__description\">{preview.description}</div>\n )}\n </div>\n );\n}\n\nfunction Glimmer(props: { style: CSSProperties; index: number }): JSX.Element {\n return (\n <div\n className=\"LinkPreview__glimmer\"\n {...props}\n style={{\n animationDelay: String((props.index || 0) * 300),\n ...(props.style || {})\n }}\n />\n );\n}\n\nexport function LinkPreview({\n url\n}: Readonly<{\n url: string;\n}>): JSX.Element {\n return (\n <Suspense\n fallback={\n <>\n <Glimmer style={{ height: \"80px\" }} index={0} />\n <Glimmer style={{ width: \"60%\" }} index={1} />\n <Glimmer style={{ width: \"80%\" }} index={2} />\n </>\n }\n >\n <LinkPreviewContent url={url} />\n </Suspense>\n );\n}\n"],"mappings":";;;;;;;;;AAQA;AAEA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA;AACA,IAAMA,aAAsE,GAAG,CAAC,CAAC;AAEjF,IAAMC,WAAW,GACb,iHAAiH;AAErH,SAASC,kBAAkB,CAACC,GAAW,EAAE;EACrC,IAAIC,MAAM,GAAGJ,aAAa,CAACG,GAAG,CA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O,EAC1EV,OAAO,CAACY,WAAW,iBAChB;IAAK,SAAS,EAAC;EAA0B,GAAEZ,OAAO,CAACY,WAAW,CACjE,CACC;AAEd;AAEA,SAASC,OAAO,CAACC,KAA8C,EAAe;EAC1E,oBACI;IACI,SAAS,EAAC;EAAsB,GAC5BA,KAAK;IACT,KAAK;MACDC,cAAc,EAAEC,MAAM,CAAC,CAACF,KAAK,CAACG,KAAK,IAAI,CAAC,IAAI,GAAG;IAAC,GAC5CH,KAAK,CAACI,KAAK,IAAI,CAAC,CAAC;EACvB,GACJ;AAEV;AAEO,SAASC,WAAW,QAIV;EAAA,IAHbtB,GAAG,SAAHA,GAAG;EAIH,oBACI,oBAAC,cAAQ;IACL,QAAQ,eACJ,uDACI,oBAAC,OAAO;MAAC,KAAK,EAAE;QAAEuB,MAAM,EAAE;MAAO,CAAE;MAAC,KAAK,EAAE;IAAE,EAAG,eAChD,oBAAC,OAAO;MAAC,KAAK,EAAE;QAAEC,KAAK,EAAE;MAAM,CAAE;MAAC,KAAK,EAAE;IAAE,EAAG,eAC9C,oBAAC,OAAO;MAAC,KAAK,EAAE;QAAEA,KAAK,EAAE;MAAM,CAAE;MAAC,KAAK,EAAE;IAAE,EAAG;EAErD,gBAED,oBAAC,kBAAkB;IAAC,GAAG,EAAExB;EAAI,EAAG,CACzB;AAEnB"}
@@ -1 +1 @@
1
- {"version":3,"names":["require","React","_interopRequireWildcard","Placeholder","_ref","children","className","createElement"],"sources":["Placeholder.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./Placeholder.css\";\n\nimport * as React from \"react\";\nimport { ReactNode } from \"react\";\n\nexport function Placeholder({\n children,\n className\n}: {\n children: ReactNode;\n className?: string;\n}): JSX.Element {\n return <div className={className || \"Placeholder__root\"}>{children}</div>;\n}\n"],"mappings":";;;;;;;AAQAA,OAAA;AAEA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOO,SAASG,WAAWA,CAAAC,IAAA,EAMX;EAAA,IALZC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,SAAS,GAAAF,IAAA,CAATE,SAAS;EAKT,oBAAOL,KAAA,CAAAM,aAAA;IAAKD,SAAS,EAAEA,SAAS,IAAI;EAAoB,GAAED,QAAQ,CAAO;AAC7E"}
1
+ {"version":3,"names":["Placeholder","children","className"],"sources":["Placeholder.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./Placeholder.css\";\n\nimport * as React from \"react\";\nimport { ReactNode } from \"react\";\n\nexport function Placeholder({\n children,\n className\n}: {\n children: ReactNode;\n className?: string;\n}): JSX.Element {\n return <div className={className || \"Placeholder__root\"}>{children}</div>;\n}\n"],"mappings":";;;;;;;AAQA;AAEA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOO,SAASA,WAAW,OAMX;EAAA,IALZC,QAAQ,QAARA,QAAQ;IACRC,SAAS,QAATA,SAAS;EAKT,oBAAO;IAAK,SAAS,EAAEA,SAAS,IAAI;EAAoB,GAAED,QAAQ,CAAO;AAC7E"}
@@ -1 +1 @@
1
- {"version":3,"names":["require","React","_interopRequireWildcard","TextInput","_ref","label","value","onChange","_ref$placeholder","placeholder","dataTestId","createElement","className","type","e","target"],"sources":["TextInput.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./Input.css\";\n\nimport * as React from \"react\";\n\ntype Props = Readonly<{\n \"data-test-id\"?: string;\n label: string;\n onChange: (val: string) => void;\n placeholder?: string;\n value: string;\n}>;\n\nexport default function TextInput({\n label,\n value,\n onChange,\n placeholder = \"\",\n \"data-test-id\": dataTestId\n}: Props): JSX.Element {\n return (\n <div className=\"Input__wrapper\">\n <label className=\"Input__label\">{label}</label>\n <input\n type=\"text\"\n className=\"Input__input\"\n placeholder={placeholder}\n value={value}\n onChange={e => {\n onChange(e.target.value);\n }}\n data-test-id={dataTestId}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;AAQAA,OAAA;AAEA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAce,SAASG,SAASA,CAAAC,IAAA,EAMV;EAAA,IALnBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IACLC,KAAK,GAAAF,IAAA,CAALE,KAAK;IACLC,SAAQ,GAAAH,IAAA,CAARG,QAAQ;IAAAC,gBAAA,GAAAJ,IAAA,CACRK,WAAW;IAAXA,WAAW,GAAAD,gBAAA,cAAG,EAAE,GAAAA,gBAAA;IACAE,UAAU,GAAAN,IAAA,CAA1B,cAAc;EAEd,oBACIH,KAAA,CAAAU,aAAA;IAAKC,SAAS,EAAC;EAAgB,gBAC3BX,KAAA,CAAAU,aAAA;IAAOC,SAAS,EAAC;EAAc,GAAEP,KAAK,CAAS,eAC/CJ,KAAA,CAAAU,aAAA;IACIE,IAAI,EAAC,MAAM;IACXD,SAAS,EAAC,cAAc;IACxBH,WAAW,EAAEA,WAAY;IACzBH,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAE,SAAAA,SAAAO,CAAC,EAAI;MACXP,SAAQ,CAACO,CAAC,CAACC,MAAM,CAACT,KAAK,CAAC;IAC5B,CAAE;IACF,gBAAcI;EAAW,EAC3B,CACA;AAEd"}
1
+ {"version":3,"names":["TextInput","label","value","onChange","placeholder","dataTestId","e","target"],"sources":["TextInput.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport \"./Input.css\";\n\nimport * as React from \"react\";\n\ntype Props = Readonly<{\n \"data-test-id\"?: string;\n label: string;\n onChange: (val: string) => void;\n placeholder?: string;\n value: string;\n}>;\n\nexport default function TextInput({\n label,\n value,\n onChange,\n placeholder = \"\",\n \"data-test-id\": dataTestId\n}: Props): JSX.Element {\n return (\n <div className=\"Input__wrapper\">\n <label className=\"Input__label\">{label}</label>\n <input\n type=\"text\"\n className=\"Input__input\"\n placeholder={placeholder}\n value={value}\n onChange={e => {\n onChange(e.target.value);\n }}\n data-test-id={dataTestId}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;AAQA;AAEA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAce,SAASA,SAAS,OAMV;EAAA,IALnBC,KAAK,QAALA,KAAK;IACLC,KAAK,QAALA,KAAK;IACLC,SAAQ,QAARA,QAAQ;IAAA,wBACRC,WAAW;IAAXA,WAAW,iCAAG,EAAE;IACAC,UAAU,QAA1B,cAAc;EAEd,oBACI;IAAK,SAAS,EAAC;EAAgB,gBAC3B;IAAO,SAAS,EAAC;EAAc,GAAEJ,KAAK,CAAS,eAC/C;IACI,IAAI,EAAC,MAAM;IACX,SAAS,EAAC,cAAc;IACxB,WAAW,EAAEG,WAAY;IACzB,KAAK,EAAEF,KAAM;IACb,QAAQ,EAAE,kBAAAI,CAAC,EAAI;MACXH,SAAQ,CAACG,CAAC,CAACC,MAAM,CAACL,KAAK,CAAC;IAC5B,CAAE;IACF,gBAAcG;EAAW,EAC3B,CACA;AAEd"}
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ interface ToolbarActionDialogProps {
3
+ disabled: boolean;
4
+ buttonLabel?: string;
5
+ buttonAriaLabel: string;
6
+ buttonClassName: string;
7
+ buttonIconClassName: string;
8
+ children: React.ReactNode | React.ReactNode[];
9
+ stopCloseOnClickSelf?: boolean;
10
+ }
11
+ export declare const ToolbarActionDialog: React.FC<ToolbarActionDialogProps>;
12
+ export {};
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.ToolbarActionDialog = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var React = _interopRequireWildcard(require("react"));
11
+ function MenuContainer(_ref) {
12
+ var children = _ref.children,
13
+ menuContainerRef = _ref.menuContainerRef,
14
+ onClose = _ref.onClose;
15
+ var handleKeyDown = function handleKeyDown(event) {
16
+ var key = event.key;
17
+ if (["Escape", "ArrowUp", "ArrowDown", "Tab"].includes(key)) {
18
+ event.preventDefault();
19
+ }
20
+ if (key === "Escape" || key === "Tab") {
21
+ onClose();
22
+ }
23
+ };
24
+ var handleContainerClick = function handleContainerClick(e) {
25
+ e.preventDefault();
26
+ console.log("click", e);
27
+ };
28
+ return /*#__PURE__*/React.createElement("div", {
29
+ style: {
30
+ position: "relative"
31
+ }
32
+ }, /*#__PURE__*/React.createElement("div", {
33
+ onClick: function onClick(e) {
34
+ return handleContainerClick(e);
35
+ },
36
+ style: {
37
+ position: "absolute",
38
+ top: -10,
39
+ left: 0,
40
+ width: 240,
41
+ backgroundColor: "#fff"
42
+ },
43
+ ref: menuContainerRef !== null && menuContainerRef !== void 0 ? menuContainerRef : null,
44
+ onKeyDown: handleKeyDown
45
+ }, children));
46
+ }
47
+ var ToolbarActionDialog = function ToolbarActionDialog(_ref2) {
48
+ var disabled = _ref2.disabled,
49
+ buttonAriaLabel = _ref2.buttonAriaLabel,
50
+ buttonClassName = _ref2.buttonClassName,
51
+ buttonIconClassName = _ref2.buttonIconClassName,
52
+ buttonLabel = _ref2.buttonLabel,
53
+ children = _ref2.children,
54
+ stopCloseOnClickSelf = _ref2.stopCloseOnClickSelf;
55
+ var menuWindowRef = (0, React.useRef)(null);
56
+ var _useState = (0, React.useState)(false),
57
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
58
+ showDropDown = _useState2[0],
59
+ setShowDropDown = _useState2[1];
60
+ var handleClose = function handleClose() {
61
+ if (menuWindowRef && menuWindowRef.current) {
62
+ setShowDropDown(false);
63
+ menuWindowRef.current.focus();
64
+ }
65
+ };
66
+ (0, React.useEffect)(function () {
67
+ if (!showDropDown) {
68
+ return;
69
+ }
70
+ var handle = function handle(event) {
71
+ /* const target = event.target;
72
+ if (!button.contains(target as Node)) {
73
+ setShowDropDown(false);
74
+ }*/
75
+ console.log("handle", event);
76
+ };
77
+ document.addEventListener("click", handle);
78
+ return function () {
79
+ document.removeEventListener("click", handle);
80
+ };
81
+ }, [showDropDown, stopCloseOnClickSelf]);
82
+ return /*#__PURE__*/React.createElement("div", {
83
+ style: {
84
+ position: "relative"
85
+ }
86
+ }, /*#__PURE__*/React.createElement("button", {
87
+ style: {
88
+ position: "relative"
89
+ },
90
+ disabled: disabled,
91
+ "aria-label": buttonAriaLabel || buttonLabel,
92
+ className: buttonClassName,
93
+ onClick: function onClick() {
94
+ setShowDropDown(!showDropDown);
95
+ }
96
+ }, buttonIconClassName && /*#__PURE__*/React.createElement("span", {
97
+ className: buttonIconClassName
98
+ }), buttonLabel && /*#__PURE__*/React.createElement("span", {
99
+ className: "text dropdown-button-text"
100
+ }, buttonLabel), /*#__PURE__*/React.createElement("i", {
101
+ className: "chevron-down"
102
+ })), showDropDown && /*#__PURE__*/React.createElement(MenuContainer, {
103
+ onClose: handleClose
104
+ }, children));
105
+ };
106
+ exports.ToolbarActionDialog = ToolbarActionDialog;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MenuContainer","children","menuContainerRef","onClose","handleKeyDown","event","key","includes","preventDefault","handleContainerClick","e","console","log","position","top","left","width","backgroundColor","ToolbarActionDialog","disabled","buttonAriaLabel","buttonClassName","buttonIconClassName","buttonLabel","stopCloseOnClickSelf","menuWindowRef","useRef","useState","showDropDown","setShowDropDown","handleClose","current","focus","useEffect","handle","document","addEventListener","removeEventListener"],"sources":["ToolbarActionDialog.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport * as React from \"react\";\n\nfunction MenuContainer({\n children,\n menuContainerRef,\n onClose\n}: {\n children: React.ReactNode | React.ReactNode[];\n menuContainerRef?: React.Ref<HTMLDivElement>;\n onClose: () => void;\n}) {\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const key = event.key;\n\n if ([\"Escape\", \"ArrowUp\", \"ArrowDown\", \"Tab\"].includes(key)) {\n event.preventDefault();\n }\n\n if (key === \"Escape\" || key === \"Tab\") {\n onClose();\n }\n };\n\n const handleContainerClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n e.preventDefault();\n console.log(\"click\", e);\n };\n\n return (\n <div style={{ position: \"relative\" }}>\n <div\n onClick={e => handleContainerClick(e)}\n style={{\n position: \"absolute\",\n top: -10,\n left: 0,\n width: 240,\n backgroundColor: \"#fff\"\n }}\n ref={menuContainerRef ?? null}\n onKeyDown={handleKeyDown}\n >\n {children}\n </div>\n </div>\n );\n}\ninterface ToolbarActionDialogProps {\n disabled: boolean;\n buttonLabel?: string;\n buttonAriaLabel: string;\n buttonClassName: string;\n buttonIconClassName: string;\n children: React.ReactNode | React.ReactNode[];\n stopCloseOnClickSelf?: boolean;\n}\n\nexport const ToolbarActionDialog: React.FC<ToolbarActionDialogProps> = ({\n disabled,\n buttonAriaLabel,\n buttonClassName,\n buttonIconClassName,\n buttonLabel,\n children,\n stopCloseOnClickSelf\n}): JSX.Element => {\n const menuWindowRef = useRef<HTMLDivElement>(null);\n const [showDropDown, setShowDropDown] = useState(false);\n\n const handleClose = () => {\n if (menuWindowRef && menuWindowRef.current) {\n setShowDropDown(false);\n menuWindowRef.current.focus();\n }\n };\n\n useEffect(() => {\n if (!showDropDown) {\n return;\n }\n\n const handle = (event: MouseEvent) => {\n /* const target = event.target;\n if (!button.contains(target as Node)) {\n setShowDropDown(false);\n }*/\n console.log(\"handle\", event);\n };\n document.addEventListener(\"click\", handle);\n\n return () => {\n document.removeEventListener(\"click\", handle);\n };\n }, [showDropDown, stopCloseOnClickSelf]);\n\n return (\n <div style={{ position: \"relative\" }}>\n <button\n style={{ position: \"relative\" }}\n disabled={disabled}\n aria-label={buttonAriaLabel || buttonLabel}\n className={buttonClassName}\n onClick={() => {\n setShowDropDown(!showDropDown);\n }}\n >\n {buttonIconClassName && <span className={buttonIconClassName} />}\n {buttonLabel && <span className=\"text dropdown-button-text\">{buttonLabel}</span>}\n <i className=\"chevron-down\" />\n </button>\n {showDropDown && <MenuContainer onClose={handleClose}>{children}</MenuContainer>}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;AAGA,SAASA,aAAa,OAQnB;EAAA,IAPCC,QAAQ,QAARA,QAAQ;IACRC,gBAAgB,QAAhBA,gBAAgB;IAChBC,OAAO,QAAPA,OAAO;EAMP,IAAMC,aAAa,GAAG,SAAhBA,aAAa,CAAIC,KAA0C,EAAK;IAClE,IAAMC,GAAG,GAAGD,KAAK,CAACC,GAAG;IAErB,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,CAACC,QAAQ,CAACD,GAAG,CAAC,EAAE;MACzDD,KAAK,CAACG,cAAc,EAAE;IAC1B;IAEA,IAAIF,GAAG,KAAK,QAAQ,IAAIA,GAAG,KAAK,KAAK,EAAE;MACnCH,OAAO,EAAE;IACb;EACJ,CAAC;EAED,IAAMM,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIC,CAA+C,EAAK;IAC9EA,CAAC,CAACF,cAAc,EAAE;IAClBG,OAAO,CAACC,GAAG,CAAC,OAAO,EAAEF,CAAC,CAAC;EAC3B,CAAC;EAED,oBACI;IAAK,KAAK,EAAE;MAAEG,QAAQ,EAAE;IAAW;EAAE,gBACjC;IACI,OAAO,EAAE,iBAAAH,CAAC;MAAA,OAAID,oBAAoB,CAACC,CAAC,CAAC;IAAA,CAAC;IACtC,KAAK,EAAE;MACHG,QAAQ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AY,EAAEJ,oBAAoB,CAAC,CAAC;EAExC,oBACI;IAAK,KAAK,EAAE;MAAEX,QAAQ,EAAE;IAAW;EAAE,gBACjC;IACI,KAAK,EAAE;MAAEA,QAAQ,EAAE;IAAW,CAAE;IAChC,QAAQ,EAAEM,QAAS;IACnB,cAAYC,eAAe,IAAIG,WAAY;IAC3C,SAAS,EAAEF,eAAgB;IAC3B,OAAO,EAAE,mBAAM;MACXQ,eAAe,CAAC,CAACD,YAAY,CAAC;IAClC;EAAE,GAEDN,mBAAmB,iBAAI;IAAM,SAAS,EAAEA;EAAoB,EAAG,EAC/DC,WAAW,iBAAI;IAAM,SAAS,EAAC;EAA2B,GAAEA,WAAW,CAAQ,eAChF;IAAG,SAAS,EAAC;EAAc,EAAG,CACzB,EACRK,YAAY,iBAAI,oBAAC,aAAa;IAAC,OAAO,EAAEE;EAAY,GAAE7B,QAAQ,CAAiB,CAC9E;AAEd,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["generateInitialLexicalValue","JSON","stringify","root","children","direction","format","indent","type","version","exports"],"sources":["generateInitialLexicalValue.ts"],"sourcesContent":["import { LexicalValue } from \"~/types\";\n\n/**\n * @description Basic JSON data string that will initialize the editor.\n */\nexport const generateInitialLexicalValue = (): LexicalValue => {\n return JSON.stringify({\n root: {\n children: [\n {\n children: [],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"paragraph\",\n version: 1\n }\n ],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"root\",\n version: 1\n }\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAAA,EAAuB;EAC3D,OAAOC,IAAI,CAACC,SAAS,CAAC;IAClBC,IAAI,EAAE;MACFC,QAAQ,EAAE,CACN;QACIA,QAAQ,EAAE,EAAE;QACZC,SAAS,EAAE,IAAI;QACfC,MAAM,EAAE,EAAE;QACVC,MAAM,EAAE,CAAC;QACTC,IAAI,EAAE,WAAW;QACjBC,OAAO,EAAE;MACb,CAAC,CACJ;MACDJ,SAAS,EAAE,IAAI;MACfC,MAAM,EAAE,EAAE;MACVC,MAAM,EAAE,CAAC;MACTC,IAAI,EAAE,MAAM;MACZC,OAAO,EAAE;IACb;EACJ,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAV,2BAAA,GAAAA,2BAAA"}
1
+ {"version":3,"names":["generateInitialLexicalValue","JSON","stringify","root","children","direction","format","indent","type","version"],"sources":["generateInitialLexicalValue.ts"],"sourcesContent":["import { LexicalValue } from \"~/types\";\n\n/**\n * @description Basic JSON data string that will initialize the editor.\n */\nexport const generateInitialLexicalValue = (): LexicalValue => {\n return JSON.stringify({\n root: {\n children: [\n {\n children: [],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"paragraph\",\n version: 1\n }\n ],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"root\",\n version: 1\n }\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAG,SAA9BA,2BAA2B,GAAuB;EAC3D,OAAOC,IAAI,CAACC,SAAS,CAAC;IAClBC,IAAI,EAAE;MACFC,QAAQ,EAAE,CACN;QACIA,QAAQ,EAAE,EAAE;QACZC,SAAS,EAAE,IAAI;QACfC,MAAM,EAAE,EAAE;QACVC,MAAM,EAAE,CAAC;QACTC,IAAI,EAAE,WAAW;QACjBC,OAAO,EAAE;MACb,CAAC,CACJ;MACDJ,SAAS,EAAE,IAAI;MACfC,MAAM,EAAE,EAAE;MACVC,MAAM,EAAE,CAAC;MACTC,IAAI,EAAE,MAAM;MACZC,OAAO,EAAE;IACb;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["getDOMRangeRect","nativeSelection","rootElement","domRange","getRangeAt","rect","anchorNode","inner","firstElementChild","getBoundingClientRect"],"sources":["getDOMRangeRect.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nexport function getDOMRangeRect(nativeSelection: Selection, rootElement: HTMLElement): DOMRect {\n const domRange = nativeSelection.getRangeAt(0);\n\n let rect;\n\n if (nativeSelection.anchorNode === rootElement) {\n let inner = rootElement;\n while (inner.firstElementChild != null) {\n inner = inner.firstElementChild as HTMLElement;\n }\n rect = inner.getBoundingClientRect();\n } else {\n rect = domRange.getBoundingClientRect();\n }\n\n return rect;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAeA,CAACC,eAA0B,EAAEC,WAAwB,EAAW;EAC3F,IAAMC,QAAQ,GAAGF,eAAe,CAACG,UAAU,CAAC,CAAC,CAAC;EAE9C,IAAIC,IAAI;EAER,IAAIJ,eAAe,CAACK,UAAU,KAAKJ,WAAW,EAAE;IAC5C,IAAIK,KAAK,GAAGL,WAAW;IACvB,OAAOK,KAAK,CAACC,iBAAiB,IAAI,IAAI,EAAE;MACpCD,KAAK,GAAGA,KAAK,CAACC,iBAAgC;IAClD;IACAH,IAAI,GAAGE,KAAK,CAACE,qBAAqB,EAAE;EACxC,CAAC,MAAM;IACHJ,IAAI,GAAGF,QAAQ,CAACM,qBAAqB,EAAE;EAC3C;EAEA,OAAOJ,IAAI;AACf"}
1
+ {"version":3,"names":["getDOMRangeRect","nativeSelection","rootElement","domRange","getRangeAt","rect","anchorNode","inner","firstElementChild","getBoundingClientRect"],"sources":["getDOMRangeRect.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nexport function getDOMRangeRect(nativeSelection: Selection, rootElement: HTMLElement): DOMRect {\n const domRange = nativeSelection.getRangeAt(0);\n\n let rect;\n\n if (nativeSelection.anchorNode === rootElement) {\n let inner = rootElement;\n while (inner.firstElementChild != null) {\n inner = inner.firstElementChild as HTMLElement;\n }\n rect = inner.getBoundingClientRect();\n } else {\n rect = domRange.getBoundingClientRect();\n }\n\n return rect;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAe,CAACC,eAA0B,EAAEC,WAAwB,EAAW;EAC3F,IAAMC,QAAQ,GAAGF,eAAe,CAACG,UAAU,CAAC,CAAC,CAAC;EAE9C,IAAIC,IAAI;EAER,IAAIJ,eAAe,CAACK,UAAU,KAAKJ,WAAW,EAAE;IAC5C,IAAIK,KAAK,GAAGL,WAAW;IACvB,OAAOK,KAAK,CAACC,iBAAiB,IAAI,IAAI,EAAE;MACpCD,KAAK,GAAGA,KAAK,CAACC,iBAAgC;IAClD;IACAH,IAAI,GAAGE,KAAK,CAACE,qBAAqB,EAAE;EACxC,CAAC,MAAM;IACHJ,IAAI,GAAGF,QAAQ,CAACM,qBAAqB,EAAE;EAC3C;EAEA,OAAOJ,IAAI;AACf"}
@@ -0,0 +1,5 @@
1
+ import { TextFormatting, TextBlockSelection, ToolbarState } from "../types";
2
+ import { ElementNode, LexicalEditor, LexicalNode, RangeSelection, TextNode } from "lexical";
3
+ export declare const getSelectionTextFormat: (selection: RangeSelection | undefined) => TextFormatting;
4
+ export declare const getToolbarState: (selection: RangeSelection, node: LexicalNode, parent: LexicalNode | null, element: LexicalNode | null, anchorNode: ElementNode | TextNode) => ToolbarState;
5
+ export declare const getLexicalTextSelectionState: (activeEditor: LexicalEditor, selection: RangeSelection) => TextBlockSelection | null;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarState = exports.getSelectionTextFormat = exports.getLexicalTextSelectionState = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _lexical = require("lexical");
10
+ var _utils = require("@lexical/utils");
11
+ var _getSelectedNode = require("./getSelectedNode");
12
+ var _link = require("@lexical/link");
13
+ var _WebinyListNode = require("../nodes/list-node/WebinyListNode");
14
+ var _richText = require("@lexical/rich-text");
15
+ var _TypographyElementNode = require("../nodes/TypographyElementNode");
16
+ var _FontColorNode = require("../nodes/FontColorNode");
17
+ var _WebinyQuoteNode = require("../nodes/WebinyQuoteNode");
18
+ var getSelectionTextFormat = function getSelectionTextFormat(selection) {
19
+ return !(0, _lexical.$isRangeSelection)(selection) ? {
20
+ italic: false,
21
+ bold: false,
22
+ underline: false,
23
+ code: false
24
+ } : {
25
+ bold: selection.hasFormat("bold"),
26
+ italic: selection.hasFormat("italic"),
27
+ underline: selection.hasFormat("underline"),
28
+ code: selection.hasFormat("code")
29
+ };
30
+ };
31
+ exports.getSelectionTextFormat = getSelectionTextFormat;
32
+ var getDefaultToolbarState = function getDefaultToolbarState() {
33
+ return {
34
+ bold: false,
35
+ italic: false,
36
+ underline: false,
37
+ code: false,
38
+ link: {
39
+ isSelected: false
40
+ },
41
+ list: {
42
+ isSelected: false
43
+ },
44
+ typography: {
45
+ isSelected: false
46
+ },
47
+ fontColor: {
48
+ isSelected: false
49
+ },
50
+ quote: {
51
+ isSelected: false
52
+ },
53
+ textType: undefined
54
+ };
55
+ };
56
+ var getToolbarState = function getToolbarState(selection, node, parent, element, anchorNode) {
57
+ var textFormat = getSelectionTextFormat(selection);
58
+ var state = getDefaultToolbarState();
59
+ state = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
60
+ bold: textFormat.bold,
61
+ italic: textFormat.italic,
62
+ underline: textFormat.underline,
63
+ code: textFormat.code
64
+ });
65
+
66
+ // link
67
+ state.link.isSelected = (0, _link.$isLinkNode)(parent) || (0, _link.$isLinkNode)(node);
68
+ if (state.link.isSelected) {
69
+ state.textType = "link";
70
+ }
71
+ // font color
72
+ if ((0, _FontColorNode.$isFontColorNode)(node)) {
73
+ state.fontColor.isSelected = true;
74
+ }
75
+ if ((0, _WebinyListNode.$isWebinyListNode)(element)) {
76
+ var parentList = (0, _utils.$getNearestNodeOfType)(anchorNode, _WebinyListNode.WebinyListNode);
77
+ var type = parentList ? parentList.getListType() : element.getListType();
78
+ state.textType = type;
79
+ }
80
+ if ((0, _richText.$isHeadingNode)(node) || (0, _richText.$isHeadingNode)(element)) {
81
+ state.textType = "heading";
82
+ }
83
+ if ((0, _lexical.$isParagraphNode)(element)) {
84
+ state.textType = "paragraph";
85
+ }
86
+ if ((0, _TypographyElementNode.$isTypographyElementNode)(element)) {
87
+ state.typography.isSelected = true;
88
+ var value = element === null || element === void 0 ? void 0 : element.getTypographyValue();
89
+ if (value.tag.includes("h")) {
90
+ state.textType = "heading";
91
+ }
92
+ if (value.tag.includes("p")) {
93
+ state.textType = "paragraph";
94
+ }
95
+ }
96
+ if ((0, _TypographyElementNode.$isTypographyElementNode)(element)) {
97
+ state.fontColor.isSelected = true;
98
+ }
99
+ if ((0, _WebinyQuoteNode.$isWebinyQuoteNode)(element)) {
100
+ state.textType = "quoteblock";
101
+ state.quote.isSelected = true;
102
+ }
103
+ return state;
104
+ };
105
+
106
+ /*
107
+ * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.
108
+ */
109
+ exports.getToolbarState = getToolbarState;
110
+ var getLexicalTextSelectionState = function getLexicalTextSelectionState(activeEditor, selection) {
111
+ if ((0, _lexical.$isRangeSelection)(selection)) {
112
+ var anchorNode = selection.anchor.getNode();
113
+ var element = anchorNode.getKey() === "root" ? anchorNode : (0, _utils.$findMatchingParent)(anchorNode, function (e) {
114
+ var parent = e.getParent();
115
+ return parent !== null && (0, _lexical.$isRootOrShadowRoot)(parent);
116
+ });
117
+ if (element === null) {
118
+ element = anchorNode.getTopLevelElementOrThrow();
119
+ }
120
+ var elementKey = element.getKey();
121
+ var elementDOM = activeEditor.getElementByKey(elementKey);
122
+
123
+ // Update links
124
+ var node = (0, _getSelectedNode.getSelectedNode)(selection);
125
+ var parent = node.getParent();
126
+ var isElementDom = elementDOM !== null;
127
+ return {
128
+ // node/element data from selection
129
+ elementKey: elementKey,
130
+ element: element,
131
+ parent: parent,
132
+ node: node,
133
+ anchorNode: anchorNode,
134
+ selection: selection,
135
+ isElementDom: isElementDom,
136
+ state: getToolbarState(selection, node, parent, element, anchorNode)
137
+ };
138
+ }
139
+ return null;
140
+ };
141
+ exports.getLexicalTextSelectionState = getLexicalTextSelectionState;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getSelectionTextFormat","selection","$isRangeSelection","italic","bold","underline","code","hasFormat","getDefaultToolbarState","link","isSelected","list","typography","fontColor","quote","textType","undefined","getToolbarState","node","parent","element","anchorNode","textFormat","state","$isLinkNode","$isFontColorNode","$isWebinyListNode","parentList","$getNearestNodeOfType","WebinyListNode","type","getListType","$isHeadingNode","$isParagraphNode","$isTypographyElementNode","value","getTypographyValue","tag","includes","$isWebinyQuoteNode","getLexicalTextSelectionState","activeEditor","anchor","getNode","getKey","$findMatchingParent","e","getParent","$isRootOrShadowRoot","getTopLevelElementOrThrow","elementKey","elementDOM","getElementByKey","getSelectedNode","isElementDom"],"sources":["getLexicalTextSelectionState.ts"],"sourcesContent":["import { TextFormatting, TextBlockSelection, ToolbarState, TypographyValue } from \"~/types\";\nimport {\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n ElementNode,\n LexicalEditor,\n LexicalNode,\n RangeSelection,\n TextNode\n} from \"lexical\";\nimport { $findMatchingParent, $getNearestNodeOfType } from \"@lexical/utils\";\nimport { getSelectedNode } from \"~/utils/getSelectedNode\";\nimport { $isLinkNode } from \"@lexical/link\";\nimport { $isWebinyListNode, WebinyListNode } from \"~/nodes/list-node/WebinyListNode\";\nimport { $isHeadingNode } from \"@lexical/rich-text\";\nimport { $isTypographyElementNode } from \"~/nodes/TypographyElementNode\";\nimport { $isFontColorNode } from \"~/nodes/FontColorNode\";\nimport { $isWebinyQuoteNode } from \"~/nodes/WebinyQuoteNode\";\n\nexport const getSelectionTextFormat = (selection: RangeSelection | undefined): TextFormatting => {\n return !$isRangeSelection(selection)\n ? {\n italic: false,\n bold: false,\n underline: false,\n code: false\n }\n : {\n bold: selection.hasFormat(\"bold\"),\n italic: selection.hasFormat(\"italic\"),\n underline: selection.hasFormat(\"underline\"),\n code: selection.hasFormat(\"code\")\n };\n};\n\nconst getDefaultToolbarState = (): ToolbarState => {\n return {\n bold: false,\n italic: false,\n underline: false,\n code: false,\n link: { isSelected: false },\n list: { isSelected: false },\n typography: { isSelected: false },\n fontColor: { isSelected: false },\n quote: { isSelected: false },\n textType: undefined\n };\n};\n\nexport const getToolbarState = (\n selection: RangeSelection,\n node: LexicalNode,\n parent: LexicalNode | null,\n element: LexicalNode | null,\n anchorNode: ElementNode | TextNode\n): ToolbarState => {\n const textFormat = getSelectionTextFormat(selection);\n let state: ToolbarState = getDefaultToolbarState();\n state = {\n ...state,\n bold: textFormat.bold,\n italic: textFormat.italic,\n underline: textFormat.underline,\n code: textFormat.code\n };\n\n // link\n state.link.isSelected = $isLinkNode(parent) || $isLinkNode(node);\n if (state.link.isSelected) {\n state.textType = \"link\";\n }\n // font color\n if ($isFontColorNode(node)) {\n state.fontColor.isSelected = true;\n }\n if ($isWebinyListNode(element)) {\n const parentList = $getNearestNodeOfType<WebinyListNode>(anchorNode, WebinyListNode);\n const type = parentList ? parentList.getListType() : element.getListType();\n state.textType = type;\n }\n if ($isHeadingNode(node) || $isHeadingNode(element)) {\n state.textType = \"heading\";\n }\n if ($isParagraphNode(element)) {\n state.textType = \"paragraph\";\n }\n if ($isTypographyElementNode(element)) {\n state.typography.isSelected = true;\n const value = element?.getTypographyValue() as TypographyValue;\n if (value.tag.includes(\"h\")) {\n state.textType = \"heading\";\n }\n if (value.tag.includes(\"p\")) {\n state.textType = \"paragraph\";\n }\n }\n if ($isTypographyElementNode(element)) {\n state.fontColor.isSelected = true;\n }\n if ($isWebinyQuoteNode(element)) {\n state.textType = \"quoteblock\";\n state.quote.isSelected = true;\n }\n\n return state;\n};\n\n/*\n * @desc Get selection data and provide processed toolbar state and data about the text, element and parent nodes.\n */\nexport const getLexicalTextSelectionState = (\n activeEditor: LexicalEditor,\n selection: RangeSelection\n): TextBlockSelection | null => {\n if ($isRangeSelection(selection)) {\n const anchorNode = selection.anchor.getNode();\n let element =\n anchorNode.getKey() === \"root\"\n ? anchorNode\n : $findMatchingParent(anchorNode, e => {\n const parent = e.getParent();\n return parent !== null && $isRootOrShadowRoot(parent);\n });\n\n if (element === null) {\n element = anchorNode.getTopLevelElementOrThrow();\n }\n\n const elementKey = element.getKey();\n const elementDOM = activeEditor.getElementByKey(elementKey);\n\n // Update links\n const node = getSelectedNode(selection);\n const parent = node.getParent();\n const isElementDom = elementDOM !== null;\n\n return {\n // node/element data from selection\n elementKey,\n element,\n parent,\n node,\n anchorNode,\n selection,\n isElementDom,\n state: getToolbarState(selection, node, parent, element, anchorNode)\n };\n }\n return null;\n};\n"],"mappings":";;;;;;;;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,CAAIC,SAAqC,EAAqB;EAC7F,OAAO,CAAC,IAAAC,0BAAiB,EAACD,SAAS,CAAC,GAC9B;IACIE,MAAM,EAAE,KAAK;IACbC,IAAI,EAAE,KAAK;IACXC,SAAS,EAAE,KAAK;IAChBC,IAAI,EAAE;EACV,CAAC,GACD;IACIF,IAAI,EAAEH,SAAS,CAACM,SAAS,CAAC,MAAM,CAAC;IACjCJ,MAAM,EAAEF,SAAS,CAACM,SAAS,CAAC,QAAQ,CAAC;IACrCF,SAAS,EAAEJ,SAAS,CAACM,SAAS,CAAC,WAAW,CAAC;IAC3CD,IAAI,EAAEL,SAAS,CAACM,SAAS,CAAC,MAAM;EACpC,CAAC;AACX,CAAC;AAAC;AAEF,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAsB,GAAuB;EAC/C,OAAO;IACHJ,IAAI,EAAE,KAAK;IACXD,MAAM,EAAE,KAAK;IACbE,SAAS,EAAE,KAAK;IAChBC,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,CAACyC,MAAM,CAACC,OAAO,EAAE;IAC7C,IAAIvB,OAAO,GACPC,UAAU,CAACuB,MAAM,EAAE,KAAK,MAAM,GACxBvB,UAAU,GACV,IAAAwB,0BAAmB,EAACxB,UAAU,EAAE,UAAAyB,CAAC,EAAI;MACjC,IAAM3B,MAAM,GAAG2B,CAAC,CAACC,SAAS,EAAE;MAC5B,OAAO5B,MAAM,KAAK,IAAI,IAAI,IAAA6B,4BAAmB,EAAC7B,MAAM,CAAC;IACzD,CAAC,CAAC;IAEZ,IAAIC,OAAO,KAAK,IAAI,EAAE;MAClBA,OAAO,GAAGC,UAAU,CAAC4B,yBAAyB,EAAE;IACpD;IAEA,IAAMC,UAAU,GAAG9B,OAAO,CAACwB,MAAM,EAAE;IACnC,IAAMO,UAAU,GAAGV,YAAY,CAACW,eAAe,CAACF,UAAU,CAAC;;IAE3D;IACA,IAAMhC,IAAI,GAAG,IAAAmC,gCAAe,EAACpD,SAAS,CAAC;IACvC,IAAMkB,MAAM,GAAGD,IAAI,CAAC6B,SAAS,EAAE;IAC/B,IAAMO,YAAY,GAAGH,UAAU,KAAK,IAAI;IAExC,OAAO;MACH;MACAD,UAAU,EAAVA,UAAU;MACV9B,OAAO,EAAPA,OAAO;MACPD,MAAM,EAANA,MAAM;MACND,IAAI,EAAJA,IAAI;MACJG,UAAU,EAAVA,UAAU;MACVpB,SAAS,EAATA,SAAS;MACTqD,YAAY,EAAZA,YAAY;MACZ/B,KAAK,EAAEN,eAAe,CAAChB,SAAS,EAAEiB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,UAAU;IACvE,CAAC;EACL;EACA,OAAO,IAAI;AACf,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["_selection","require","getSelectedNode","selection","anchor","focus","anchorNode","getNode","focusNode","isBackward","$isAtNodeEnd"],"sources":["getSelectedNode.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { $isAtNodeEnd } from \"@lexical/selection\";\nimport { ElementNode, RangeSelection, TextNode } from \"lexical\";\n\nexport function getSelectedNode(selection: RangeSelection): TextNode | ElementNode {\n const anchor = selection.anchor;\n const focus = selection.focus;\n const anchorNode = selection.anchor.getNode();\n const focusNode = selection.focus.getNode();\n if (anchorNode === focusNode) {\n return anchorNode;\n }\n const isBackward = selection.isBackward();\n if (isBackward) {\n return $isAtNodeEnd(focus) ? anchorNode : focusNode;\n } else {\n return $isAtNodeEnd(anchor) ? focusNode : anchorNode;\n }\n}\n"],"mappings":";;;;;;AAOA,IAAAA,UAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIO,SAASC,eAAeA,CAACC,SAAyB,EAA0B;EAC/E,IAAMC,MAAM,GAAGD,SAAS,CAACC,MAAM;EAC/B,IAAMC,KAAK,GAAGF,SAAS,CAACE,KAAK;EAC7B,IAAMC,UAAU,GAAGH,SAAS,CAACC,MAAM,CAACG,OAAO,EAAE;EAC7C,IAAMC,SAAS,GAAGL,SAAS,CAACE,KAAK,CAACE,OAAO,EAAE;EAC3C,IAAID,UAAU,KAAKE,SAAS,EAAE;IAC1B,OAAOF,UAAU;EACrB;EACA,IAAMG,UAAU,GAAGN,SAAS,CAACM,UAAU,EAAE;EACzC,IAAIA,UAAU,EAAE;IACZ,OAAO,IAAAC,uBAAY,EAACL,KAAK,CAAC,GAAGC,UAAU,GAAGE,SAAS;EACvD,CAAC,MAAM;IACH,OAAO,IAAAE,uBAAY,EAACN,MAAM,CAAC,GAAGI,SAAS,GAAGF,UAAU;EACxD;AACJ"}
1
+ {"version":3,"names":["getSelectedNode","selection","anchor","focus","anchorNode","getNode","focusNode","isBackward","$isAtNodeEnd"],"sources":["getSelectedNode.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { $isAtNodeEnd } from \"@lexical/selection\";\nimport { ElementNode, RangeSelection, TextNode } from \"lexical\";\n\nexport function getSelectedNode(selection: RangeSelection): TextNode | ElementNode {\n const anchor = selection.anchor;\n const focus = selection.focus;\n const anchorNode = selection.anchor.getNode();\n const focusNode = selection.focus.getNode();\n if (anchorNode === focusNode) {\n return anchorNode;\n }\n const isBackward = selection.isBackward();\n if (isBackward) {\n return $isAtNodeEnd(focus) ? anchorNode : focusNode;\n } else {\n return $isAtNodeEnd(anchor) ? focusNode : anchorNode;\n }\n}\n"],"mappings":";;;;;;AAOA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIO,SAASA,eAAe,CAACC,SAAyB,EAA0B;EAC/E,IAAMC,MAAM,GAAGD,SAAS,CAACC,MAAM;EAC/B,IAAMC,KAAK,GAAGF,SAAS,CAACE,KAAK;EAC7B,IAAMC,UAAU,GAAGH,SAAS,CAACC,MAAM,CAACG,OAAO,EAAE;EAC7C,IAAMC,SAAS,GAAGL,SAAS,CAACE,KAAK,CAACE,OAAO,EAAE;EAC3C,IAAID,UAAU,KAAKE,SAAS,EAAE;IAC1B,OAAOF,UAAU;EACrB;EACA,IAAMG,UAAU,GAAGN,SAAS,CAACM,UAAU,EAAE;EACzC,IAAIA,UAAU,EAAE;IACZ,OAAO,IAAAC,uBAAY,EAACL,KAAK,CAAC,GAAGC,UAAU,GAAGE,SAAS;EACvD,CAAC,MAAM;IACH,OAAO,IAAAE,uBAAY,EAACN,MAAM,CAAC,GAAGI,SAAS,GAAGF,UAAU;EACxD;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"names":["isValidJSON","value","o","JSON","parse","Array","isArray","_unused","exports"],"sources":["isValidJSON.ts"],"sourcesContent":["export const isValidJSON = (value: string | undefined | null): boolean => {\n if (!value) {\n return false;\n }\n try {\n const o = JSON.parse(value);\n return !!o && typeof o === \"object\" && !Array.isArray(o);\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;AAAO,IAAMA,WAAW,GAAG,SAAdA,WAAWA,CAAIC,KAAgC,EAAc;EACtE,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,KAAK;EAChB;EACA,IAAI;IACA,IAAMC,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACH,KAAK,CAAC;IAC3B,OAAO,CAAC,CAACC,CAAC,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,CAACG,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC;EAC5D,CAAC,CAAC,OAAAK,OAAA,EAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAACC,OAAA,CAAAR,WAAA,GAAAA,WAAA"}
1
+ {"version":3,"names":["isValidJSON","value","o","JSON","parse","Array","isArray"],"sources":["isValidJSON.ts"],"sourcesContent":["export const isValidJSON = (value: string | undefined | null): boolean => {\n if (!value) {\n return false;\n }\n try {\n const o = JSON.parse(value);\n return !!o && typeof o === \"object\" && !Array.isArray(o);\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;AAAO,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,KAAgC,EAAc;EACtE,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,KAAK;EAChB;EACA,IAAI;IACA,IAAMC,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACH,KAAK,CAAC;IAC3B,OAAO,CAAC,CAACC,CAAC,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,CAACG,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC;EAC5D,CAAC,CAAC,gBAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["_isValidJSON","require","isValidLexicalData","editorStateValue","isValidJSON","data","JSON","parse","exports"],"sources":["isValidLexicalData.ts"],"sourcesContent":["import { isValidJSON } from \"~/utils/isValidJSON\";\nimport { LexicalValue } from \"~/types\";\n/*\n * @description Checks for valid lexical data.\n *\n * Check for first level of properties that empty editor state data need to have.\n * @see generateInitialLexicalValue\n */\nexport const isValidLexicalData = (editorStateValue: LexicalValue | null): boolean => {\n if (!editorStateValue) {\n return false;\n }\n if (!isValidJSON(editorStateValue)) {\n return false;\n }\n const data = JSON.parse(editorStateValue);\n return !!data[\"root\"];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAIC,gBAAqC,EAAc;EAClF,IAAI,CAACA,gBAAgB,EAAE;IACnB,OAAO,KAAK;EAChB;EACA,IAAI,CAAC,IAAAC,wBAAW,EAACD,gBAAgB,CAAC,EAAE;IAChC,OAAO,KAAK;EAChB;EACA,IAAME,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACJ,gBAAgB,CAAC;EACzC,OAAO,CAAC,CAACE,IAAI,CAAC,MAAM,CAAC;AACzB,CAAC;AAACG,OAAA,CAAAN,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["isValidLexicalData","editorStateValue","isValidJSON","data","JSON","parse"],"sources":["isValidLexicalData.ts"],"sourcesContent":["import { isValidJSON } from \"~/utils/isValidJSON\";\nimport { LexicalValue } from \"~/types\";\n/*\n * @description Checks for valid lexical data.\n *\n * Check for first level of properties that empty editor state data need to have.\n * @see generateInitialLexicalValue\n */\nexport const isValidLexicalData = (editorStateValue: LexicalValue | null): boolean => {\n if (!editorStateValue) {\n return false;\n }\n if (!isValidJSON(editorStateValue)) {\n return false;\n }\n const data = JSON.parse(editorStateValue);\n return !!data[\"root\"];\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAkB,CAAIC,gBAAqC,EAAc;EAClF,IAAI,CAACA,gBAAgB,EAAE;IACnB,OAAO,KAAK;EAChB;EACA,IAAI,CAAC,IAAAC,wBAAW,EAACD,gBAAgB,CAAC,EAAE;IAChC,OAAO,KAAK;EAChB;EACA,IAAME,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACJ,gBAAgB,CAAC;EACzC,OAAO,CAAC,CAACE,IAAI,CAAC,MAAM,CAAC;AACzB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { GridSelection, LexicalEditor, NodeSelection, RangeSelection } from "lexical";
2
+ export declare const clearNodeFormatting: (activeEditor: LexicalEditor, selection: RangeSelection | NodeSelection | GridSelection | null) => void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clearNodeFormatting = void 0;
7
+ var _lexical = require("lexical");
8
+ var _selection = require("@lexical/selection");
9
+ var _utils = require("@lexical/utils");
10
+ var _LexicalDecoratorBlockNode = require("@lexical/react/LexicalDecoratorBlockNode");
11
+ var clearNodeFormatting = function clearNodeFormatting(activeEditor, selection) {
12
+ activeEditor.update(function () {
13
+ if ((0, _lexical.$isRangeSelection)(selection)) {
14
+ (0, _selection.$selectAll)(selection);
15
+ selection.getNodes().forEach(function (node) {
16
+ if ((0, _lexical.$isTextNode)(node)) {
17
+ node.setFormat(0);
18
+ node.setStyle("");
19
+ (0, _utils.$getNearestBlockElementAncestorOrThrow)(node).setFormat("");
20
+ }
21
+ if ((0, _LexicalDecoratorBlockNode.$isDecoratorBlockNode)(node)) {
22
+ node.setFormat("");
23
+ }
24
+ });
25
+ }
26
+ });
27
+ };
28
+ exports.clearNodeFormatting = clearNodeFormatting;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["clearNodeFormatting","activeEditor","selection","update","$isRangeSelection","$selectAll","getNodes","forEach","node","$isTextNode","setFormat","setStyle","$getNearestBlockElementAncestorOrThrow","$isDecoratorBlockNode"],"sources":["clearNodeFormating.ts"],"sourcesContent":["import {\n $isRangeSelection,\n $isTextNode,\n GridSelection,\n LexicalEditor,\n NodeSelection,\n RangeSelection\n} from \"lexical\";\nimport { $selectAll } from \"@lexical/selection\";\nimport { $getNearestBlockElementAncestorOrThrow } from \"@lexical/utils\";\nimport { $isDecoratorBlockNode } from \"@lexical/react/LexicalDecoratorBlockNode\";\n\nexport const clearNodeFormatting = (\n activeEditor: LexicalEditor,\n selection: RangeSelection | NodeSelection | GridSelection | null\n) => {\n activeEditor.update(() => {\n if ($isRangeSelection(selection)) {\n $selectAll(selection);\n selection.getNodes().forEach(node => {\n if ($isTextNode(node)) {\n node.setFormat(0);\n node.setStyle(\"\");\n $getNearestBlockElementAncestorOrThrow(node).setFormat(\"\");\n }\n if ($isDecoratorBlockNode(node)) {\n node.setFormat(\"\");\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAQA;AACA;AACA;AAEO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAmB,CAC5BC,YAA2B,EAC3BC,SAAgE,EAC/D;EACDD,YAAY,CAACE,MAAM,CAAC,YAAM;IACtB,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,EAAE;MAC9B,IAAAG,qBAAU,EAACH,SAAS,CAAC;MACrBA,SAAS,CAACI,QAAQ,EAAE,CAACC,OAAO,CAAC,UAAAC,IAAI,EAAI;QACjC,IAAI,IAAAC,oBAAW,EAACD,IAAI,CAAC,EAAE;UACnBA,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC;UACjBF,IAAI,CAACG,QAAQ,CAAC,EAAE,CAAC;UACjB,IAAAC,6CAAsC,EAACJ,IAAI,CAAC,CAACE,SAAS,CAAC,EAAE,CAAC;QAC9D;QACA,IAAI,IAAAG,gDAAqB,EAACL,IAAI,CAAC,EAAE;UAC7BA,IAAI,CAACE,SAAS,CAAC,EAAE,CAAC;QACtB;MACJ,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { LexicalEditor } from "lexical";
2
+ export declare const formatToParagraph: (editor: LexicalEditor) => void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatToParagraph = void 0;
7
+ var _lexical = require("lexical");
8
+ var _selection = require("@lexical/selection");
9
+ var formatToParagraph = function formatToParagraph(editor) {
10
+ editor.update(function () {
11
+ var selection = (0, _lexical.$getSelection)();
12
+ if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
13
+ (0, _selection.$wrapNodes)(selection, function () {
14
+ return (0, _lexical.$createParagraphNode)();
15
+ });
16
+ }
17
+ });
18
+ };
19
+ exports.formatToParagraph = formatToParagraph;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["formatToParagraph","editor","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$wrapNodes","$createParagraphNode"],"sources":["formatToParagraph.ts"],"sourcesContent":["import {\n $createParagraphNode,\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $wrapNodes } from \"@lexical/selection\";\n\nexport const formatToParagraph = (editor: LexicalEditor) => {\n editor.update(() => {\n const selection = $getSelection();\n\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $wrapNodes(selection, () => $createParagraphNode());\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAOA;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIC,MAAqB,EAAK;EACxDA,MAAM,CAACC,MAAM,CAAC,YAAM;IAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IAEjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,IAAI,IAAAG,oCAA2B,EAACH,SAAS,CAAC,EAAE;MACxE,IAAAI,qBAAU,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,6BAAoB,GAAE;MAAA,EAAC;IACvD;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { LexicalEditor } from "lexical";
2
+ export declare const formatToQuote: (editor: LexicalEditor, themeStyleId?: string) => void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatToQuote = void 0;
7
+ var _lexical = require("lexical");
8
+ var _selection = require("@lexical/selection");
9
+ var _WebinyQuoteNode = require("../../nodes/WebinyQuoteNode");
10
+ var formatToQuote = function formatToQuote(editor, themeStyleId) {
11
+ editor.update(function () {
12
+ var selection = (0, _lexical.$getSelection)();
13
+ if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
14
+ (0, _selection.$wrapNodes)(selection, function () {
15
+ return (0, _WebinyQuoteNode.$createWebinyQuoteNode)(themeStyleId);
16
+ });
17
+ }
18
+ });
19
+ };
20
+ exports.formatToQuote = formatToQuote;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["formatToQuote","editor","themeStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$wrapNodes","$createWebinyQuoteNode"],"sources":["formatToQuote.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $wrapNodes } from \"@lexical/selection\";\nimport { $createWebinyQuoteNode } from \"~/nodes/WebinyQuoteNode\";\n\nexport const formatToQuote = (editor: LexicalEditor, themeStyleId?: string) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $wrapNodes(selection, () => $createWebinyQuoteNode(themeStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAEO,IAAMA,aAAa,GAAG,SAAhBA,aAAa,CAAIC,MAAqB,EAAEC,YAAqB,EAAK;EAC3ED,MAAM,CAACE,MAAM,CAAC,YAAM;IAChB,IAAMC,SAAS,GAAG,IAAAC,sBAAa,GAAE;IACjC,IAAI,IAAAC,0BAAiB,EAACF,SAAS,CAAC,IAAI,IAAAG,oCAA2B,EAACH,SAAS,CAAC,EAAE;MACxE,IAAAI,qBAAU,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,uCAAsB,EAACP,YAAY,CAAC;MAAA,EAAC;IACrE;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}