@webiny/lexical-editor 0.0.0-unstable.085ff6572f

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 (306) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/commands/webiny-list.d.ts +7 -0
  4. package/commands/webiny-list.js +13 -0
  5. package/commands/webiny-list.js.map +1 -0
  6. package/commands/webiny-quote.d.ts +5 -0
  7. package/commands/webiny-quote.js +9 -0
  8. package/commands/webiny-quote.js.map +1 -0
  9. package/components/AddRichTextEditorNodeType.d.ts +6 -0
  10. package/components/AddRichTextEditorNodeType.js +28 -0
  11. package/components/AddRichTextEditorNodeType.js.map +1 -0
  12. package/components/AddRichTextEditorPlugin.d.ts +12 -0
  13. package/components/AddRichTextEditorPlugin.js +33 -0
  14. package/components/AddRichTextEditorPlugin.js.map +1 -0
  15. package/components/AddToolbarAction.d.ts +7 -0
  16. package/components/AddToolbarAction.js +33 -0
  17. package/components/AddToolbarAction.js.map +1 -0
  18. package/components/Editor/HeadingEditor.d.ts +7 -0
  19. package/components/Editor/HeadingEditor.js +29 -0
  20. package/components/Editor/HeadingEditor.js.map +1 -0
  21. package/components/Editor/ParagraphEditor.d.ts +7 -0
  22. package/components/Editor/ParagraphEditor.js +30 -0
  23. package/components/Editor/ParagraphEditor.js.map +1 -0
  24. package/components/Editor/RichTextEditor.d.ts +26 -0
  25. package/components/Editor/RichTextEditor.js +138 -0
  26. package/components/Editor/RichTextEditor.js.map +1 -0
  27. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +11 -0
  28. package/components/LexicalEditorConfig/LexicalEditorConfig.js +19 -0
  29. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -0
  30. package/components/LexicalHtmlRenderer.d.ts +16 -0
  31. package/components/LexicalHtmlRenderer.js +67 -0
  32. package/components/LexicalHtmlRenderer.js.map +1 -0
  33. package/components/Toolbar/HeadingToolbar.d.ts +12 -0
  34. package/components/Toolbar/HeadingToolbar.js +23 -0
  35. package/components/Toolbar/HeadingToolbar.js.map +1 -0
  36. package/components/Toolbar/ParagraphToolbar.d.ts +12 -0
  37. package/components/Toolbar/ParagraphToolbar.js +23 -0
  38. package/components/Toolbar/ParagraphToolbar.js.map +1 -0
  39. package/components/Toolbar/Toolbar.css +435 -0
  40. package/components/Toolbar/Toolbar.d.ts +13 -0
  41. package/components/Toolbar/Toolbar.js +215 -0
  42. package/components/Toolbar/Toolbar.js.map +1 -0
  43. package/components/ToolbarActions/BoldAction.d.ts +2 -0
  44. package/components/ToolbarActions/BoldAction.js +43 -0
  45. package/components/ToolbarActions/BoldAction.js.map +1 -0
  46. package/components/ToolbarActions/BulletListAction.d.ts +2 -0
  47. package/components/ToolbarActions/BulletListAction.js +56 -0
  48. package/components/ToolbarActions/BulletListAction.js.map +1 -0
  49. package/components/ToolbarActions/CodeHighlightAction.d.ts +2 -0
  50. package/components/ToolbarActions/CodeHighlightAction.js +43 -0
  51. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -0
  52. package/components/ToolbarActions/FontColorAction.d.ts +11 -0
  53. package/components/ToolbarActions/FontColorAction.js +83 -0
  54. package/components/ToolbarActions/FontColorAction.js.map +1 -0
  55. package/components/ToolbarActions/FontSizeAction.d.ts +2 -0
  56. package/components/ToolbarActions/FontSizeAction.js +101 -0
  57. package/components/ToolbarActions/FontSizeAction.js.map +1 -0
  58. package/components/ToolbarActions/ItalicAction.d.ts +2 -0
  59. package/components/ToolbarActions/ItalicAction.js +43 -0
  60. package/components/ToolbarActions/ItalicAction.js.map +1 -0
  61. package/components/ToolbarActions/LinkAction.d.ts +2 -0
  62. package/components/ToolbarActions/LinkAction.js +64 -0
  63. package/components/ToolbarActions/LinkAction.js.map +1 -0
  64. package/components/ToolbarActions/NumberedListAction.d.ts +2 -0
  65. package/components/ToolbarActions/NumberedListAction.js +58 -0
  66. package/components/ToolbarActions/NumberedListAction.js.map +1 -0
  67. package/components/ToolbarActions/QuoteAction.d.ts +2 -0
  68. package/components/ToolbarActions/QuoteAction.js +52 -0
  69. package/components/ToolbarActions/QuoteAction.js.map +1 -0
  70. package/components/ToolbarActions/TextAlignmentAction.d.ts +11 -0
  71. package/components/ToolbarActions/TextAlignmentAction.js +70 -0
  72. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -0
  73. package/components/ToolbarActions/TypographyAction.d.ts +11 -0
  74. package/components/ToolbarActions/TypographyAction.js +145 -0
  75. package/components/ToolbarActions/TypographyAction.js.map +1 -0
  76. package/components/ToolbarActions/UnderlineAction.d.ts +2 -0
  77. package/components/ToolbarActions/UnderlineAction.js +43 -0
  78. package/components/ToolbarActions/UnderlineAction.js.map +1 -0
  79. package/components/ToolbarPresets/HeadingToolbarPreset.d.ts +2 -0
  80. package/components/ToolbarPresets/HeadingToolbarPreset.js +56 -0
  81. package/components/ToolbarPresets/HeadingToolbarPreset.js.map +1 -0
  82. package/components/ToolbarPresets/ParagraphToolbarPreset.d.ts +2 -0
  83. package/components/ToolbarPresets/ParagraphToolbarPreset.js +71 -0
  84. package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +1 -0
  85. package/context/FontColorActionContext.d.ts +6 -0
  86. package/context/FontColorActionContext.js +10 -0
  87. package/context/FontColorActionContext.js.map +1 -0
  88. package/context/RichTextEditorContext.d.ts +26 -0
  89. package/context/RichTextEditorContext.js +68 -0
  90. package/context/RichTextEditorContext.js.map +1 -0
  91. package/context/SharedHistoryContext.d.ts +11 -0
  92. package/context/SharedHistoryContext.js +26 -0
  93. package/context/SharedHistoryContext.js.map +1 -0
  94. package/context/TextAlignmentActionContextProps.d.ts +9 -0
  95. package/context/TextAlignmentActionContextProps.js +10 -0
  96. package/context/TextAlignmentActionContextProps.js.map +1 -0
  97. package/context/TypographyActionContext.d.ts +7 -0
  98. package/context/TypographyActionContext.js +10 -0
  99. package/context/TypographyActionContext.js.map +1 -0
  100. package/hooks/useFontColorPicker.d.ts +2 -0
  101. package/hooks/useFontColorPicker.js +15 -0
  102. package/hooks/useFontColorPicker.js.map +1 -0
  103. package/hooks/useList.d.ts +2 -0
  104. package/hooks/useList.js +39 -0
  105. package/hooks/useList.js.map +1 -0
  106. package/hooks/useQuote.d.ts +2 -0
  107. package/hooks/useQuote.js +20 -0
  108. package/hooks/useQuote.js.map +1 -0
  109. package/hooks/useRichTextEditor.d.ts +2 -0
  110. package/hooks/useRichTextEditor.js +15 -0
  111. package/hooks/useRichTextEditor.js.map +1 -0
  112. package/hooks/useTextAlignmentAction.d.ts +1 -0
  113. package/hooks/useTextAlignmentAction.js +15 -0
  114. package/hooks/useTextAlignmentAction.js.map +1 -0
  115. package/hooks/useTypographyAction.d.ts +1 -0
  116. package/hooks/useTypographyAction.js +15 -0
  117. package/hooks/useTypographyAction.js.map +1 -0
  118. package/images/icons/LICENSE.md +5 -0
  119. package/images/icons/chat-square-quote.svg +1 -0
  120. package/images/icons/chevron-down.svg +1 -0
  121. package/images/icons/code.svg +1 -0
  122. package/images/icons/font-color.svg +1 -0
  123. package/images/icons/indent.svg +3 -0
  124. package/images/icons/justify.svg +3 -0
  125. package/images/icons/link.svg +1 -0
  126. package/images/icons/list-ol.svg +1 -0
  127. package/images/icons/list-ul.svg +1 -0
  128. package/images/icons/outdent.svg +3 -0
  129. package/images/icons/pencil-fill.svg +1 -0
  130. package/images/icons/text-center.svg +1 -0
  131. package/images/icons/text-left.svg +1 -0
  132. package/images/icons/text-paragraph.svg +1 -0
  133. package/images/icons/text-right.svg +1 -0
  134. package/images/icons/type-bold.svg +1 -0
  135. package/images/icons/type-h1.svg +1 -0
  136. package/images/icons/type-h2.svg +1 -0
  137. package/images/icons/type-h3.svg +1 -0
  138. package/images/icons/type-h4.svg +1 -0
  139. package/images/icons/type-h5.svg +1 -0
  140. package/images/icons/type-h6.svg +1 -0
  141. package/images/icons/type-italic.svg +1 -0
  142. package/images/icons/type-strikethrough.svg +1 -0
  143. package/images/icons/type-underline.svg +1 -0
  144. package/images/icons/unlink_icon.svg +1 -0
  145. package/index.d.ts +42 -0
  146. package/index.js +295 -0
  147. package/index.js.map +1 -0
  148. package/nodes/FontColorNode.d.ts +43 -0
  149. package/nodes/FontColorNode.js +127 -0
  150. package/nodes/FontColorNode.js.map +1 -0
  151. package/nodes/HeadingNode.d.ts +34 -0
  152. package/nodes/HeadingNode.js +192 -0
  153. package/nodes/HeadingNode.js.map +1 -0
  154. package/nodes/ListItemNode.d.ts +46 -0
  155. package/nodes/ListItemNode.js +441 -0
  156. package/nodes/ListItemNode.js.map +1 -0
  157. package/nodes/ListNode/formatList.d.ts +12 -0
  158. package/nodes/ListNode/formatList.js +424 -0
  159. package/nodes/ListNode/formatList.js.map +1 -0
  160. package/nodes/ListNode.d.ts +42 -0
  161. package/nodes/ListNode.js +294 -0
  162. package/nodes/ListNode.js.map +1 -0
  163. package/nodes/ParagraphNode.d.ts +32 -0
  164. package/nodes/ParagraphNode.js +218 -0
  165. package/nodes/ParagraphNode.js.map +1 -0
  166. package/nodes/QuoteNode.d.ts +34 -0
  167. package/nodes/QuoteNode.js +225 -0
  168. package/nodes/QuoteNode.js.map +1 -0
  169. package/nodes/TypographyElementNode.d.ts +42 -0
  170. package/nodes/TypographyElementNode.js +155 -0
  171. package/nodes/TypographyElementNode.js.map +1 -0
  172. package/nodes/types.d.ts +15 -0
  173. package/nodes/types.js +5 -0
  174. package/nodes/types.js.map +1 -0
  175. package/nodes/webinyNodes.d.ts +7 -0
  176. package/nodes/webinyNodes.js +45 -0
  177. package/nodes/webinyNodes.js.map +1 -0
  178. package/package.json +41 -0
  179. package/plugins/AutoLinkPlugin/AutoLinkPlugin.d.ts +11 -0
  180. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js +46 -0
  181. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +1 -0
  182. package/plugins/AutoLinkPlugin/index.d.ts +1 -0
  183. package/plugins/AutoLinkPlugin/index.js +16 -0
  184. package/plugins/AutoLinkPlugin/index.js.map +1 -0
  185. package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +7 -0
  186. package/plugins/BlurEventPlugin/BlurEventPlugin.js +28 -0
  187. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -0
  188. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.d.ts +17 -0
  189. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js +88 -0
  190. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +1 -0
  191. package/plugins/ClickableLinkPlugin/index.d.ts +1 -0
  192. package/plugins/ClickableLinkPlugin/index.js +16 -0
  193. package/plugins/ClickableLinkPlugin/index.js.map +1 -0
  194. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.d.ts +1 -0
  195. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +20 -0
  196. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -0
  197. package/plugins/CodeHighlightPlugin/index.d.ts +1 -0
  198. package/plugins/CodeHighlightPlugin/index.js +16 -0
  199. package/plugins/CodeHighlightPlugin/index.js.map +1 -0
  200. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +118 -0
  201. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +7 -0
  202. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +222 -0
  203. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -0
  204. package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -0
  205. package/plugins/FloatingLinkEditorPlugin/index.js +16 -0
  206. package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -0
  207. package/plugins/FontColorPlugin/FontColorPlugin.d.ts +2 -0
  208. package/plugins/FontColorPlugin/FontColorPlugin.js +39 -0
  209. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -0
  210. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.d.ts +8 -0
  211. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js +34 -0
  212. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +1 -0
  213. package/plugins/LexicalUpdateStatePlugin/index.d.ts +1 -0
  214. package/plugins/LexicalUpdateStatePlugin/index.js +16 -0
  215. package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -0
  216. package/plugins/TypographyPlugin/TypographyPlugin.d.ts +2 -0
  217. package/plugins/TypographyPlugin/TypographyPlugin.js +35 -0
  218. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -0
  219. package/plugins/WebinyListPLugin/WebinyListPlugin.d.ts +1 -0
  220. package/plugins/WebinyListPLugin/WebinyListPlugin.js +25 -0
  221. package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +1 -0
  222. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.d.ts +1 -0
  223. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js +24 -0
  224. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -0
  225. package/themes/webinyLexicalTheme.css +429 -0
  226. package/themes/webinyLexicalTheme.d.ts +9 -0
  227. package/themes/webinyLexicalTheme.js +87 -0
  228. package/themes/webinyLexicalTheme.js.map +1 -0
  229. package/types.d.ts +63 -0
  230. package/types.js +25 -0
  231. package/types.js.map +1 -0
  232. package/ui/Divider.d.ts +2 -0
  233. package/ui/Divider.js +13 -0
  234. package/ui/Divider.js.map +1 -0
  235. package/ui/DropDown.d.ts +26 -0
  236. package/ui/DropDown.js +206 -0
  237. package/ui/DropDown.js.map +1 -0
  238. package/ui/Input.css +32 -0
  239. package/ui/LinkPreview.css +69 -0
  240. package/ui/LinkPreview.d.ts +12 -0
  241. package/ui/LinkPreview.js +101 -0
  242. package/ui/LinkPreview.js.map +1 -0
  243. package/ui/Placeholder.css +23 -0
  244. package/ui/Placeholder.d.ts +13 -0
  245. package/ui/Placeholder.js +24 -0
  246. package/ui/Placeholder.js.map +1 -0
  247. package/ui/TextInput.d.ts +18 -0
  248. package/ui/TextInput.js +39 -0
  249. package/ui/TextInput.js.map +1 -0
  250. package/ui/ToolbarActionDialog.d.ts +12 -0
  251. package/ui/ToolbarActionDialog.js +106 -0
  252. package/ui/ToolbarActionDialog.js.map +1 -0
  253. package/utils/findTypographyStyleByHtmlTag.d.ts +8 -0
  254. package/utils/findTypographyStyleByHtmlTag.js +16 -0
  255. package/utils/findTypographyStyleByHtmlTag.js.map +1 -0
  256. package/utils/generateInitialLexicalValue.d.ts +5 -0
  257. package/utils/generateInitialLexicalValue.js +30 -0
  258. package/utils/generateInitialLexicalValue.js.map +1 -0
  259. package/utils/getDOMRangeRect.d.ts +10 -0
  260. package/utils/getDOMRangeRect.js +27 -0
  261. package/utils/getDOMRangeRect.js.map +1 -0
  262. package/utils/getLexicalTextSelectionState.d.ts +5 -0
  263. package/utils/getLexicalTextSelectionState.js +163 -0
  264. package/utils/getLexicalTextSelectionState.js.map +1 -0
  265. package/utils/getSelectedNode.d.ts +2 -0
  266. package/utils/getSelectedNode.js +30 -0
  267. package/utils/getSelectedNode.js.map +1 -0
  268. package/utils/isValidJSON.d.ts +1 -0
  269. package/utils/isValidJSON.js +18 -0
  270. package/utils/isValidJSON.js.map +1 -0
  271. package/utils/isValidLexicalData.d.ts +2 -0
  272. package/utils/isValidLexicalData.js +24 -0
  273. package/utils/isValidLexicalData.js.map +1 -0
  274. package/utils/nodes/clearNodeFormating.d.ts +2 -0
  275. package/utils/nodes/clearNodeFormating.js +28 -0
  276. package/utils/nodes/clearNodeFormating.js.map +1 -0
  277. package/utils/nodes/formatToHeading.d.ts +3 -0
  278. package/utils/nodes/formatToHeading.js +25 -0
  279. package/utils/nodes/formatToHeading.js.map +1 -0
  280. package/utils/nodes/formatToParagraph.d.ts +2 -0
  281. package/utils/nodes/formatToParagraph.js +20 -0
  282. package/utils/nodes/formatToParagraph.js.map +1 -0
  283. package/utils/nodes/formatToQuote.d.ts +2 -0
  284. package/utils/nodes/formatToQuote.js +25 -0
  285. package/utils/nodes/formatToQuote.js.map +1 -0
  286. package/utils/nodes/listNode.d.ts +11 -0
  287. package/utils/nodes/listNode.js +107 -0
  288. package/utils/nodes/listNode.js.map +1 -0
  289. package/utils/point.d.ts +21 -0
  290. package/utils/point.js +77 -0
  291. package/utils/point.js.map +1 -0
  292. package/utils/rect.d.ts +47 -0
  293. package/utils/rect.js +169 -0
  294. package/utils/rect.js.map +1 -0
  295. package/utils/sanitizeUrl.d.ts +8 -0
  296. package/utils/sanitizeUrl.js +27 -0
  297. package/utils/sanitizeUrl.js.map +1 -0
  298. package/utils/setFloatingElemPosition.d.ts +3 -0
  299. package/utils/setFloatingElemPosition.js +40 -0
  300. package/utils/setFloatingElemPosition.js.map +1 -0
  301. package/utils/styleObjectToString.d.ts +2 -0
  302. package/utils/styleObjectToString.js +22 -0
  303. package/utils/styleObjectToString.js.map +1 -0
  304. package/utils/toTypographyEmotionMap.d.ts +3 -0
  305. package/utils/toTypographyEmotionMap.js +36 -0
  306. package/utils/toTypographyEmotionMap.js.map +1 -0
@@ -0,0 +1,20 @@
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 _ParagraphNode = require("../../nodes/ParagraphNode");
9
+ var _selection = require("@lexical/selection");
10
+ var formatToParagraph = function formatToParagraph(editor, typographyStyleId) {
11
+ editor.update(function () {
12
+ var selection = (0, _lexical.$getSelection)();
13
+ if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
14
+ (0, _selection.$setBlocksType)(selection, function () {
15
+ return (0, _ParagraphNode.$createParagraphNode)(typographyStyleId);
16
+ });
17
+ }
18
+ });
19
+ };
20
+ exports.formatToParagraph = formatToParagraph;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["formatToParagraph","editor","typographyStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$setBlocksType","$createParagraphNode"],"sources":["formatToParagraph.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $createParagraphNode } from \"~/nodes/ParagraphNode\";\nimport { $setBlocksType } from \"@lexical/selection\";\n\nexport const formatToParagraph = (editor: LexicalEditor, typographyStyleId?: string) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $setBlocksType(selection, () => $createParagraphNode(typographyStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIC,MAAqB,EAAEC,iBAA0B,EAAK;EACpFD,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,yBAAc,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,mCAAoB,EAACP,iBAAiB,CAAC;MAAA,EAAC;IAC5E;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,25 @@
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 _QuoteNode = require("../../nodes/QuoteNode");
10
+ /*
11
+ * Will change the selected root HTML tag to specified quoteblock tag.
12
+ * For example if the selection is paragraph <p> with content inside after formatting the root tag
13
+ * will be quoteblock with same content inside.
14
+ * */
15
+ var formatToQuote = function formatToQuote(editor, themeStyleId) {
16
+ editor.update(function () {
17
+ var selection = (0, _lexical.$getSelection)();
18
+ if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
19
+ (0, _selection.$setBlocksType)(selection, function () {
20
+ return (0, _QuoteNode.$createQuoteNode)(themeStyleId);
21
+ });
22
+ }
23
+ });
24
+ };
25
+ exports.formatToQuote = formatToQuote;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["formatToQuote","editor","themeStyleId","update","selection","$getSelection","$isRangeSelection","DEPRECATED_$isGridSelection","$setBlocksType","$createQuoteNode"],"sources":["formatToQuote.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n DEPRECATED_$isGridSelection,\n LexicalEditor\n} from \"lexical\";\nimport { $setBlocksType } from \"@lexical/selection\";\nimport { $createQuoteNode } from \"~/nodes/QuoteNode\";\n\n/*\n * Will change the selected root HTML tag to specified quoteblock tag.\n * For example if the selection is paragraph <p> with content inside after formatting the root tag\n * will be quoteblock with same content inside.\n * */\nexport const formatToQuote = (editor: LexicalEditor, themeStyleId?: string) => {\n editor.update(() => {\n const selection = $getSelection();\n if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {\n $setBlocksType(selection, () => $createQuoteNode(themeStyleId));\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAMA;AACA;AAEA;AACA;AACA;AACA;AACA;AACO,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,yBAAc,EAACJ,SAAS,EAAE;QAAA,OAAM,IAAAK,2BAAgB,EAACP,YAAY,CAAC;MAAA,EAAC;IACnE;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,11 @@
1
+ import type { LexicalNode } from "lexical";
2
+ import { ListNode } from "../../nodes/ListNode";
3
+ import { ListItemNode } from "../../nodes/ListItemNode";
4
+ export declare function $getListDepth(listNode: ListNode): number;
5
+ export declare function $getTopListNode(listItem: LexicalNode): ListNode;
6
+ export declare function $getAllListItems(node: ListNode): Array<ListItemNode>;
7
+ export declare function isNestedListNode(node: LexicalNode | null | undefined): boolean;
8
+ export declare function findNearestWebinyListItemNode(node: LexicalNode): ListItemNode | null;
9
+ export declare function getUniqueWebinyListItemNodes(nodeList: Array<LexicalNode>): Array<ListItemNode>;
10
+ export declare function $removeHighestEmptyListParent(sublist: ListItemNode | ListNode): void;
11
+ export declare function wrapInListItem(node: LexicalNode): ListItemNode;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.$getAllListItems = $getAllListItems;
7
+ exports.$getListDepth = $getListDepth;
8
+ exports.$getTopListNode = $getTopListNode;
9
+ exports.$removeHighestEmptyListParent = $removeHighestEmptyListParent;
10
+ exports.findNearestWebinyListItemNode = findNearestWebinyListItemNode;
11
+ exports.getUniqueWebinyListItemNodes = getUniqueWebinyListItemNodes;
12
+ exports.isNestedListNode = isNestedListNode;
13
+ exports.wrapInListItem = wrapInListItem;
14
+ var _ListNode = require("../../nodes/ListNode");
15
+ var _ListItemNode = require("../../nodes/ListItemNode");
16
+ function $getListDepth(listNode) {
17
+ var depth = 1;
18
+ var parent = listNode.getParent();
19
+ while (parent !== null) {
20
+ if ((0, _ListItemNode.$isListItemNode)(parent)) {
21
+ var parentList = parent.getParent();
22
+ if ((0, _ListNode.$isListNode)(parentList)) {
23
+ depth++;
24
+ parent = (parentList === null || parentList === void 0 ? void 0 : parentList.getParent()) || null;
25
+ continue;
26
+ }
27
+ console.log("A WebinyListItemNode must have a WebinyListNode for a parent.");
28
+ }
29
+ return depth;
30
+ }
31
+ return depth;
32
+ }
33
+ function $getTopListNode(listItem) {
34
+ var list = listItem.getParent();
35
+ if (!(0, _ListNode.$isListNode)(list)) {
36
+ console.log("A WebinyListItemNode must have a ListNode for a parent.");
37
+ return listItem;
38
+ }
39
+ var parent = list;
40
+ while (parent !== null) {
41
+ parent = parent.getParent();
42
+ if ((0, _ListNode.$isListNode)(parent)) {
43
+ list = parent;
44
+ }
45
+ }
46
+ return list;
47
+ }
48
+ function $getAllListItems(node) {
49
+ var listItemNodes = [];
50
+ var listChildren = node.getChildren().filter(_ListItemNode.$isListItemNode);
51
+ for (var i = 0; i < listChildren.length; i++) {
52
+ var listItemNode = listChildren[i];
53
+ var firstChild = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.getFirstChild();
54
+ if ((0, _ListNode.$isListNode)(firstChild)) {
55
+ listItemNodes = listItemNodes.concat($getAllListItems(firstChild));
56
+ } else {
57
+ listItemNodes.push(listItemNode);
58
+ }
59
+ }
60
+ return listItemNodes;
61
+ }
62
+ function isNestedListNode(node) {
63
+ return (0, _ListItemNode.$isListItemNode)(node) && (0, _ListNode.$isListNode)(node === null || node === void 0 ? void 0 : node.getFirstChild());
64
+ }
65
+
66
+ // TODO: rewrite with $findMatchingParent or *nodeOfType
67
+ function findNearestWebinyListItemNode(node) {
68
+ var currentNode = node;
69
+ while (currentNode !== null) {
70
+ if ((0, _ListItemNode.$isListItemNode)(currentNode)) {
71
+ return currentNode;
72
+ }
73
+ currentNode = currentNode.getParent();
74
+ }
75
+ return null;
76
+ }
77
+ function getUniqueWebinyListItemNodes(nodeList) {
78
+ var keys = new Set();
79
+ for (var i = 0; i < nodeList.length; i++) {
80
+ var node = nodeList[i];
81
+ if ((0, _ListItemNode.$isListItemNode)(node)) {
82
+ keys.add(node);
83
+ }
84
+ }
85
+ return Array.from(keys);
86
+ }
87
+ function $removeHighestEmptyListParent(sublist) {
88
+ // Nodes may be repeatedly indented, to create deeply nested lists that each
89
+ // contain just one bullet.
90
+ // Our goal is to remove these (empty) deeply nested lists. The easiest
91
+ // way to do that is crawl back up the tree until we find a node that has siblings
92
+ // (e.g. is actually part of the list contents) and delete that, or delete
93
+ // the root of the list (if no list nodes have siblings.)
94
+ var emptyListPtr = sublist;
95
+ while (emptyListPtr.getNextSibling() == null && emptyListPtr.getPreviousSibling() == null) {
96
+ var parent = emptyListPtr.getParent();
97
+ if (parent == null || !((0, _ListItemNode.$isListItemNode)(emptyListPtr) || (0, _ListNode.$isListNode)(emptyListPtr))) {
98
+ break;
99
+ }
100
+ emptyListPtr = parent;
101
+ }
102
+ emptyListPtr.remove();
103
+ }
104
+ function wrapInListItem(node) {
105
+ var listItemWrapper = (0, _ListItemNode.$createListItemNode)();
106
+ return listItemWrapper.append(node);
107
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["$getListDepth","listNode","depth","parent","getParent","$isListItemNode","parentList","$isListNode","console","log","$getTopListNode","listItem","list","$getAllListItems","node","listItemNodes","listChildren","getChildren","filter","i","length","listItemNode","firstChild","getFirstChild","concat","push","isNestedListNode","findNearestWebinyListItemNode","currentNode","getUniqueWebinyListItemNodes","nodeList","keys","Set","add","Array","from","$removeHighestEmptyListParent","sublist","emptyListPtr","getNextSibling","getPreviousSibling","remove","wrapInListItem","listItemWrapper","$createListItemNode","append"],"sources":["listNode.ts"],"sourcesContent":["import type { LexicalNode } from \"lexical\";\n\nimport { $isListNode, ListNode } from \"~/nodes/ListNode\";\nimport { $createListItemNode, $isListItemNode, ListItemNode } from \"~/nodes/ListItemNode\";\n\nexport function $getListDepth(listNode: ListNode): number {\n let depth = 1;\n let parent = listNode.getParent();\n\n while (parent !== null) {\n if ($isListItemNode(parent)) {\n const parentList = parent.getParent();\n\n if ($isListNode(parentList)) {\n depth++;\n parent = parentList?.getParent() || null;\n continue;\n }\n console.log(\"A WebinyListItemNode must have a WebinyListNode for a parent.\");\n }\n\n return depth;\n }\n\n return depth;\n}\n\nexport function $getTopListNode(listItem: LexicalNode): ListNode {\n let list = listItem.getParent<ListNode>();\n\n if (!$isListNode(list)) {\n console.log(\"A WebinyListItemNode must have a ListNode for a parent.\");\n return listItem as ListNode;\n }\n\n let parent: ListNode | null = list;\n\n while (parent !== null) {\n parent = parent.getParent();\n\n if ($isListNode(parent)) {\n list = parent;\n }\n }\n\n return list;\n}\n\nexport function $getAllListItems(node: ListNode): Array<ListItemNode> {\n let listItemNodes: Array<ListItemNode> = [];\n const listChildren: Array<ListItemNode> = node.getChildren().filter($isListItemNode);\n\n for (let i = 0; i < listChildren.length; i++) {\n const listItemNode = listChildren[i];\n const firstChild = listItemNode?.getFirstChild();\n\n if ($isListNode(firstChild)) {\n listItemNodes = listItemNodes.concat($getAllListItems(firstChild));\n } else {\n listItemNodes.push(listItemNode);\n }\n }\n\n return listItemNodes;\n}\n\nexport function isNestedListNode(node: LexicalNode | null | undefined): boolean {\n return $isListItemNode(node) && $isListNode(node?.getFirstChild());\n}\n\n// TODO: rewrite with $findMatchingParent or *nodeOfType\nexport function findNearestWebinyListItemNode(node: LexicalNode): ListItemNode | null {\n let currentNode: LexicalNode | null = node;\n\n while (currentNode !== null) {\n if ($isListItemNode(currentNode)) {\n return currentNode;\n }\n currentNode = currentNode.getParent();\n }\n\n return null;\n}\n\nexport function getUniqueWebinyListItemNodes(nodeList: Array<LexicalNode>): Array<ListItemNode> {\n const keys = new Set<ListItemNode>();\n\n for (let i = 0; i < nodeList.length; i++) {\n const node = nodeList[i];\n\n if ($isListItemNode(node)) {\n keys.add(node);\n }\n }\n\n return Array.from(keys);\n}\n\nexport function $removeHighestEmptyListParent(sublist: ListItemNode | ListNode) {\n // Nodes may be repeatedly indented, to create deeply nested lists that each\n // contain just one bullet.\n // Our goal is to remove these (empty) deeply nested lists. The easiest\n // way to do that is crawl back up the tree until we find a node that has siblings\n // (e.g. is actually part of the list contents) and delete that, or delete\n // the root of the list (if no list nodes have siblings.)\n let emptyListPtr = sublist;\n\n while (emptyListPtr.getNextSibling() == null && emptyListPtr.getPreviousSibling() == null) {\n const parent = emptyListPtr.getParent<ListItemNode | ListNode>();\n\n if (parent == null || !($isListItemNode(emptyListPtr) || $isListNode(emptyListPtr))) {\n break;\n }\n\n emptyListPtr = parent;\n }\n\n emptyListPtr.remove();\n}\n\nexport function wrapInListItem(node: LexicalNode): ListItemNode {\n const listItemWrapper = $createListItemNode();\n return listItemWrapper.append(node);\n}\n"],"mappings":";;;;;;;;;;;;;AAEA;AACA;AAEO,SAASA,aAAa,CAACC,QAAkB,EAAU;EACtD,IAAIC,KAAK,GAAG,CAAC;EACb,IAAIC,MAAM,GAAGF,QAAQ,CAACG,SAAS,EAAE;EAEjC,OAAOD,MAAM,KAAK,IAAI,EAAE;IACpB,IAAI,IAAAE,6BAAe,EAACF,MAAM,CAAC,EAAE;MACzB,IAAMG,UAAU,GAAGH,MAAM,CAACC,SAAS,EAAE;MAErC,IAAI,IAAAG,qBAAW,EAACD,UAAU,CAAC,EAAE;QACzBJ,KAAK,EAAE;QACPC,MAAM,GAAG,CAAAG,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEF,SAAS,EAAE,KAAI,IAAI;QACxC;MACJ;MACAI,OAAO,CAACC,GAAG,CAAC,+DAA+D,CAAC;IAChF;IAEA,OAAOP,KAAK;EAChB;EAEA,OAAOA,KAAK;AAChB;AAEO,SAASQ,eAAe,CAACC,QAAqB,EAAY;EAC7D,IAAIC,IAAI,GAAGD,QAAQ,CAACP,SAAS,EAAY;EAEzC,IAAI,CAAC,IAAAG,qBAAW,EAACK,IAAI,CAAC,EAAE;IACpBJ,OAAO,CAACC,GAAG,CAAC,yDAAyD,CAAC;IACtE,OAAOE,QAAQ;EACnB;EAEA,IAAIR,MAAuB,GAAGS,IAAI;EAElC,OAAOT,MAAM,KAAK,IAAI,EAAE;IACpBA,MAAM,GAAGA,MAAM,CAACC,SAAS,EAAE;IAE3B,IAAI,IAAAG,qBAAW,EAACJ,MAAM,CAAC,EAAE;MACrBS,IAAI,GAAGT,MAAM;IACjB;EACJ;EAEA,OAAOS,IAAI;AACf;AAEO,SAASC,gBAAgB,CAACC,IAAc,EAAu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AI,GAAGgB,QAAQ,CAACX,CAAC,CAAC;IAExB,IAAI,IAAAd,6BAAe,EAACS,IAAI,CAAC,EAAE;MACvBiB,IAAI,CAACE,GAAG,CAACnB,IAAI,CAAC;IAClB;EACJ;EAEA,OAAOoB,KAAK,CAACC,IAAI,CAACJ,IAAI,CAAC;AAC3B;AAEO,SAASK,6BAA6B,CAACC,OAAgC,EAAE;EAC5E;EACA;EACA;EACA;EACA;EACA;EACA,IAAIC,YAAY,GAAGD,OAAO;EAE1B,OAAOC,YAAY,CAACC,cAAc,EAAE,IAAI,IAAI,IAAID,YAAY,CAACE,kBAAkB,EAAE,IAAI,IAAI,EAAE;IACvF,IAAMrC,MAAM,GAAGmC,YAAY,CAAClC,SAAS,EAA2B;IAEhE,IAAID,MAAM,IAAI,IAAI,IAAI,EAAE,IAAAE,6BAAe,EAACiC,YAAY,CAAC,IAAI,IAAA/B,qBAAW,EAAC+B,YAAY,CAAC,CAAC,EAAE;MACjF;IACJ;IAEAA,YAAY,GAAGnC,MAAM;EACzB;EAEAmC,YAAY,CAACG,MAAM,EAAE;AACzB;AAEO,SAASC,cAAc,CAAC5B,IAAiB,EAAgB;EAC5D,IAAM6B,eAAe,GAAG,IAAAC,iCAAmB,GAAE;EAC7C,OAAOD,eAAe,CAACE,MAAM,CAAC/B,IAAI,CAAC;AACvC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export declare class Point {
9
+ private readonly _x;
10
+ private readonly _y;
11
+ constructor(x: number, y: number);
12
+ get x(): number;
13
+ get y(): number;
14
+ equals({ x, y }: Point): boolean;
15
+ calcDeltaXTo({ x }: Point): number;
16
+ calcDeltaYTo({ y }: Point): number;
17
+ calcHorizontalDistanceTo(point: Point): number;
18
+ calcVerticalDistance(point: Point): number;
19
+ calcDistanceTo(point: Point): number;
20
+ }
21
+ export declare function isPoint(x: unknown): x is Point;
package/utils/point.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Point = void 0;
8
+ exports.isPoint = isPoint;
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+ var Point = /*#__PURE__*/function () {
20
+ function Point(x, y) {
21
+ (0, _classCallCheck2.default)(this, Point);
22
+ (0, _defineProperty2.default)(this, "_x", void 0);
23
+ (0, _defineProperty2.default)(this, "_y", void 0);
24
+ this._x = x;
25
+ this._y = y;
26
+ }
27
+ (0, _createClass2.default)(Point, [{
28
+ key: "x",
29
+ get: function get() {
30
+ return this._x;
31
+ }
32
+ }, {
33
+ key: "y",
34
+ get: function get() {
35
+ return this._y;
36
+ }
37
+ }, {
38
+ key: "equals",
39
+ value: function equals(_ref) {
40
+ var x = _ref.x,
41
+ y = _ref.y;
42
+ return this.x === x && this.y === y;
43
+ }
44
+ }, {
45
+ key: "calcDeltaXTo",
46
+ value: function calcDeltaXTo(_ref2) {
47
+ var x = _ref2.x;
48
+ return this.x - x;
49
+ }
50
+ }, {
51
+ key: "calcDeltaYTo",
52
+ value: function calcDeltaYTo(_ref3) {
53
+ var y = _ref3.y;
54
+ return this.y - y;
55
+ }
56
+ }, {
57
+ key: "calcHorizontalDistanceTo",
58
+ value: function calcHorizontalDistanceTo(point) {
59
+ return Math.abs(this.calcDeltaXTo(point));
60
+ }
61
+ }, {
62
+ key: "calcVerticalDistance",
63
+ value: function calcVerticalDistance(point) {
64
+ return Math.abs(this.calcDeltaYTo(point));
65
+ }
66
+ }, {
67
+ key: "calcDistanceTo",
68
+ value: function calcDistanceTo(point) {
69
+ return Math.sqrt(Math.pow(this.calcDeltaXTo(point), 2) + Math.pow(this.calcDeltaYTo(point), 2));
70
+ }
71
+ }]);
72
+ return Point;
73
+ }();
74
+ exports.Point = Point;
75
+ function isPoint(x) {
76
+ return x instanceof Point;
77
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Point","x","y","_x","_y","point","Math","abs","calcDeltaXTo","calcDeltaYTo","sqrt","pow","isPoint"],"sources":["point.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 class Point {\n private readonly _x: number;\n private readonly _y: number;\n\n constructor(x: number, y: number) {\n this._x = x;\n this._y = y;\n }\n\n get x(): number {\n return this._x;\n }\n\n get y(): number {\n return this._y;\n }\n\n public equals({ x, y }: Point): boolean {\n return this.x === x && this.y === y;\n }\n\n public calcDeltaXTo({ x }: Point): number {\n return this.x - x;\n }\n\n public calcDeltaYTo({ y }: Point): number {\n return this.y - y;\n }\n\n public calcHorizontalDistanceTo(point: Point): number {\n return Math.abs(this.calcDeltaXTo(point));\n }\n\n public calcVerticalDistance(point: Point): number {\n return Math.abs(this.calcDeltaYTo(point));\n }\n\n public calcDistanceTo(point: Point): number {\n return Math.sqrt(\n Math.pow(this.calcDeltaXTo(point), 2) + Math.pow(this.calcDeltaYTo(point), 2)\n );\n }\n}\n\nexport function isPoint(x: unknown): x is Point {\n return x instanceof Point;\n}\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,IAOaA,KAAK;EAId,eAAYC,CAAS,EAAEC,CAAS,EAAE;IAAA;IAAA;IAAA;IAC9B,IAAI,CAACC,EAAE,GAAGF,CAAC;IACX,IAAI,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// <reference types="web" />
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ */
10
+ import { Point } from "./point";
11
+ declare type ContainsPointReturn = {
12
+ result: boolean;
13
+ reason: {
14
+ isOnTopSide: boolean;
15
+ isOnBottomSide: boolean;
16
+ isOnLeftSide: boolean;
17
+ isOnRightSide: boolean;
18
+ };
19
+ };
20
+ export declare class Rect {
21
+ private readonly _left;
22
+ private readonly _top;
23
+ private readonly _right;
24
+ private readonly _bottom;
25
+ constructor(left: number, top: number, right: number, bottom: number);
26
+ get top(): number;
27
+ get right(): number;
28
+ get bottom(): number;
29
+ get left(): number;
30
+ get width(): number;
31
+ get height(): number;
32
+ equals({ top, left, bottom, right }: Rect): boolean;
33
+ contains({ x, y }: Point): ContainsPointReturn;
34
+ contains({ top, left, bottom, right }: Rect): boolean;
35
+ intersectsWith(rect: Rect): boolean;
36
+ generateNewRect({ left, top, right, bottom }: {
37
+ left?: number | undefined;
38
+ top?: number | undefined;
39
+ right?: number | undefined;
40
+ bottom?: number | undefined;
41
+ }): Rect;
42
+ static fromLTRB(left: number, top: number, right: number, bottom: number): Rect;
43
+ static fromLWTH(left: number, width: number, top: number, height: number): Rect;
44
+ static fromPoints(startPoint: Point, endPoint: Point): Rect;
45
+ static fromDOM(dom: HTMLElement): Rect;
46
+ }
47
+ export {};
package/utils/rect.js ADDED
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Rect = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ var _point = require("./point");
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+ var Rect = /*#__PURE__*/function () {
21
+ function Rect(left, top, right, bottom) {
22
+ (0, _classCallCheck2.default)(this, Rect);
23
+ (0, _defineProperty2.default)(this, "_left", void 0);
24
+ (0, _defineProperty2.default)(this, "_top", void 0);
25
+ (0, _defineProperty2.default)(this, "_right", void 0);
26
+ (0, _defineProperty2.default)(this, "_bottom", void 0);
27
+ var _ref = top <= bottom ? [top, bottom] : [bottom, top],
28
+ _ref2 = (0, _slicedToArray2.default)(_ref, 2),
29
+ physicTop = _ref2[0],
30
+ physicBottom = _ref2[1];
31
+ var _ref3 = left <= right ? [left, right] : [right, left],
32
+ _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
33
+ physicLeft = _ref4[0],
34
+ physicRight = _ref4[1];
35
+ this._top = physicTop;
36
+ this._right = physicRight;
37
+ this._left = physicLeft;
38
+ this._bottom = physicBottom;
39
+ }
40
+ (0, _createClass2.default)(Rect, [{
41
+ key: "top",
42
+ get: function get() {
43
+ return this._top;
44
+ }
45
+ }, {
46
+ key: "right",
47
+ get: function get() {
48
+ return this._right;
49
+ }
50
+ }, {
51
+ key: "bottom",
52
+ get: function get() {
53
+ return this._bottom;
54
+ }
55
+ }, {
56
+ key: "left",
57
+ get: function get() {
58
+ return this._left;
59
+ }
60
+ }, {
61
+ key: "width",
62
+ get: function get() {
63
+ return Math.abs(this._left - this._right);
64
+ }
65
+ }, {
66
+ key: "height",
67
+ get: function get() {
68
+ return Math.abs(this._bottom - this._top);
69
+ }
70
+ }, {
71
+ key: "equals",
72
+ value: function equals(_ref5) {
73
+ var top = _ref5.top,
74
+ left = _ref5.left,
75
+ bottom = _ref5.bottom,
76
+ right = _ref5.right;
77
+ return top === this._top && bottom === this._bottom && left === this._left && right === this._right;
78
+ }
79
+ }, {
80
+ key: "contains",
81
+ value: function contains(target) {
82
+ if ((0, _point.isPoint)(target)) {
83
+ var x = target.x,
84
+ y = target.y;
85
+ var isOnTopSide = y < this._top;
86
+ var isOnBottomSide = y > this._bottom;
87
+ var isOnLeftSide = x < this._left;
88
+ var isOnRightSide = x > this._right;
89
+ var result = !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;
90
+ return {
91
+ reason: {
92
+ isOnBottomSide: isOnBottomSide,
93
+ isOnLeftSide: isOnLeftSide,
94
+ isOnRightSide: isOnRightSide,
95
+ isOnTopSide: isOnTopSide
96
+ },
97
+ result: result
98
+ };
99
+ } else {
100
+ var top = target.top,
101
+ left = target.left,
102
+ bottom = target.bottom,
103
+ right = target.right;
104
+ return top >= this._top && top <= this._bottom && bottom >= this._top && bottom <= this._bottom && left >= this._left && left <= this._right && right >= this._left && right <= this._right;
105
+ }
106
+ }
107
+ }, {
108
+ key: "intersectsWith",
109
+ value: function intersectsWith(rect) {
110
+ var x1 = rect.left,
111
+ y1 = rect.top,
112
+ w1 = rect.width,
113
+ h1 = rect.height;
114
+ var x2 = this.left,
115
+ y2 = this.top,
116
+ w2 = this.width,
117
+ h2 = this.height;
118
+ var maxX = x1 + w1 >= x2 + w2 ? x1 + w1 : x2 + w2;
119
+ var maxY = y1 + h1 >= y2 + h2 ? y1 + h1 : y2 + h2;
120
+ var minX = x1 <= x2 ? x1 : x2;
121
+ var minY = y1 <= y2 ? y1 : y2;
122
+ return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;
123
+ }
124
+ }, {
125
+ key: "generateNewRect",
126
+ value: function generateNewRect(_ref6) {
127
+ var _ref6$left = _ref6.left,
128
+ left = _ref6$left === void 0 ? this.left : _ref6$left,
129
+ _ref6$top = _ref6.top,
130
+ top = _ref6$top === void 0 ? this.top : _ref6$top,
131
+ _ref6$right = _ref6.right,
132
+ right = _ref6$right === void 0 ? this.right : _ref6$right,
133
+ _ref6$bottom = _ref6.bottom,
134
+ bottom = _ref6$bottom === void 0 ? this.bottom : _ref6$bottom;
135
+ return new Rect(left, top, right, bottom);
136
+ }
137
+ }], [{
138
+ key: "fromLTRB",
139
+ value: function fromLTRB(left, top, right, bottom) {
140
+ return new Rect(left, top, right, bottom);
141
+ }
142
+ }, {
143
+ key: "fromLWTH",
144
+ value: function fromLWTH(left, width, top, height) {
145
+ return new Rect(left, top, left + width, top + height);
146
+ }
147
+ }, {
148
+ key: "fromPoints",
149
+ value: function fromPoints(startPoint, endPoint) {
150
+ var top = startPoint.y,
151
+ left = startPoint.x;
152
+ var bottom = endPoint.y,
153
+ right = endPoint.x;
154
+ return Rect.fromLTRB(left, top, right, bottom);
155
+ }
156
+ }, {
157
+ key: "fromDOM",
158
+ value: function fromDOM(dom) {
159
+ var _dom$getBoundingClien = dom.getBoundingClientRect(),
160
+ top = _dom$getBoundingClien.top,
161
+ width = _dom$getBoundingClien.width,
162
+ left = _dom$getBoundingClien.left,
163
+ height = _dom$getBoundingClien.height;
164
+ return Rect.fromLWTH(left, width, top, height);
165
+ }
166
+ }]);
167
+ return Rect;
168
+ }();
169
+ exports.Rect = Rect;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Rect","left","top","right","bottom","physicTop","physicBottom","physicLeft","physicRight","_top","_right","_left","_bottom","Math","abs","target","isPoint","x","y","isOnTopSide","isOnBottomSide","isOnLeftSide","isOnRightSide","result","reason","rect","x1","y1","w1","width","h1","height","x2","y2","w2","h2","maxX","maxY","minX","minY","startPoint","endPoint","fromLTRB","dom","getBoundingClientRect","fromLWTH"],"sources":["rect.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 { isPoint, Point } from \"./point\";\n\ntype ContainsPointReturn = {\n result: boolean;\n reason: {\n isOnTopSide: boolean;\n isOnBottomSide: boolean;\n isOnLeftSide: boolean;\n isOnRightSide: boolean;\n };\n};\n\nexport class Rect {\n private readonly _left: number;\n private readonly _top: number;\n private readonly _right: number;\n private readonly _bottom: number;\n\n constructor(left: number, top: number, right: number, bottom: number) {\n const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];\n\n const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];\n\n this._top = physicTop;\n this._right = physicRight;\n this._left = physicLeft;\n this._bottom = physicBottom;\n }\n\n get top(): number {\n return this._top;\n }\n\n get right(): number {\n return this._right;\n }\n\n get bottom(): number {\n return this._bottom;\n }\n\n get left(): number {\n return this._left;\n }\n\n get width(): number {\n return Math.abs(this._left - this._right);\n }\n\n get height(): number {\n return Math.abs(this._bottom - this._top);\n }\n\n public equals({ top, left, bottom, right }: Rect): boolean {\n return (\n top === this._top &&\n bottom === this._bottom &&\n left === this._left &&\n right === this._right\n );\n }\n\n public contains({ x, y }: Point): ContainsPointReturn;\n public contains({ top, left, bottom, right }: Rect): boolean;\n public contains(target: Point | Rect): boolean | ContainsPointReturn {\n if (isPoint(target)) {\n const { x, y } = target;\n\n const isOnTopSide = y < this._top;\n const isOnBottomSide = y > this._bottom;\n const isOnLeftSide = x < this._left;\n const isOnRightSide = x > this._right;\n\n const result = !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;\n\n return {\n reason: {\n isOnBottomSide,\n isOnLeftSide,\n isOnRightSide,\n isOnTopSide\n },\n result\n };\n } else {\n const { top, left, bottom, right } = target;\n\n return (\n top >= this._top &&\n top <= this._bottom &&\n bottom >= this._top &&\n bottom <= this._bottom &&\n left >= this._left &&\n left <= this._right &&\n right >= this._left &&\n right <= this._right\n );\n }\n }\n\n public intersectsWith(rect: Rect): boolean {\n const { left: x1, top: y1, width: w1, height: h1 } = rect;\n const { left: x2, top: y2, width: w2, height: h2 } = this;\n const maxX = x1 + w1 >= x2 + w2 ? x1 + w1 : x2 + w2;\n const maxY = y1 + h1 >= y2 + h2 ? y1 + h1 : y2 + h2;\n const minX = x1 <= x2 ? x1 : x2;\n const minY = y1 <= y2 ? y1 : y2;\n return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;\n }\n\n public generateNewRect({\n left = this.left,\n top = this.top,\n right = this.right,\n bottom = this.bottom\n }): Rect {\n return new Rect(left, top, right, bottom);\n }\n\n static fromLTRB(left: number, top: number, right: number, bottom: number): Rect {\n return new Rect(left, top, right, bottom);\n }\n\n static fromLWTH(left: number, width: number, top: number, height: number): Rect {\n return new Rect(left, top, left + width, top + height);\n }\n\n static fromPoints(startPoint: Point, endPoint: Point): Rect {\n const { y: top, x: left } = startPoint;\n const { y: bottom, x: right } = endPoint;\n return Rect.fromLTRB(left, top, right, bottom);\n }\n\n static fromDOM(dom: HTMLElement): Rect {\n const { top, width, left, height } = dom.getBoundingClientRect();\n return Rect.fromLWTH(left, width, top, height);\n }\n}\n"],"mappings":";;;;;;;;;;;AAOA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,IAmBaA,IAAI;EAMb,cAAYC,IAAY,EAAEC,GAAW,EAAEC,KAAa,EAAEC,MAAc,EAAE;IAAA;IAAA;IAAA;IAAA;IAAA;IAClE,WAAkCF,GAAG,IAAIE,MAAM,GAAG,CAACF,GAAG,EAAEE,MAAM,CAAC,GAAG,CAACA,MAAM,EAAEF,GAAG,CAAC;MAAA;MAAxEG,SAAS;MAAEC,YAAY;IAE9B,YAAkCL,IAAI,IAAIE,KAAK,GAAG,CAACF,IAAI,EAAEE,KAAK,CAAC,GAAG,CAACA,KAAK,EAAEF,IAAI,CAAC;MAAA;MAAxEM,UAAU;MAAEC,WAAW;IAE9B,IAAI,CAACC,IAAI,GAAGJ,SAAS;IACrB,IAAI,CAACK,MAAM,GAAGF,WAAW;IACzB,IAAI,CAACG,KAAK,GAAGJ,UAAU;IACvB,IAAI,CAACK,OAAO,GAAGN,YAAY;EAC/B;EAAC;IAAA;IAAA,KAED,eAAkB;MACd,OAAO,IAAI,CAACG,IAAI;IACpB;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QAAUjB,IAAI,GAAKuC,UAAU,CAAtBvB,CAAC;MACjB,IAAWb,MAAM,GAAeqC,QAAQ,CAAhCvB,CAAC;QAAaf,KAAK,GAAKsC,QAAQ,CAArBxB,CAAC;MACpB,OAAOjB,IAAI,CAAC0C,QAAQ,CAACzC,IAAI,EAAEC,GAAG,EAAEC,KAAK,EAAEC,MAAM,CAAC;IAClD;EAAC;IAAA;IAAA,OAED,iBAAeuC,GAAgB,EAAQ;MACnC,4BAAqCA,GAAG,CAACC,qBAAqB,EAAE;QAAxD1C,GAAG,yBAAHA,GAAG;QAAE2B,KAAK,yBAALA,KAAK;QAAE5B,IAAI,yBAAJA,IAAI;QAAE8B,MAAM,yBAANA,MAAM;MAChC,OAAO/B,IAAI,CAAC6C,QAAQ,CAAC5C,IAAI,EAAE4B,KAAK,EAAE3B,GAAG,EAAE6B,MAAM,CAAC;IAClD;EAAC;EAAA;AAAA;AAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export declare const sanitizeUrl: (url: string) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sanitizeUrl = void 0;
7
+ /**
8
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ *
13
+ */
14
+
15
+ var sanitizeUrl = function sanitizeUrl(url) {
16
+ /** A pattern that matches safe URLs. */
17
+ var SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi;
18
+
19
+ /** A pattern that matches safe data URLs. */
20
+ var DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+/]+=*$/i;
21
+ url = String(url).trim();
22
+ if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN)) {
23
+ return url;
24
+ }
25
+ return "https://";
26
+ };
27
+ exports.sanitizeUrl = sanitizeUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["sanitizeUrl","url","SAFE_URL_PATTERN","DATA_URL_PATTERN","String","trim","match"],"sources":["sanitizeUrl.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 */\n\nexport const sanitizeUrl = (url: string): string => {\n /** A pattern that matches safe URLs. */\n const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi;\n\n /** A pattern that matches safe data URLs. */\n const DATA_URL_PATTERN =\n /^data:(?:image\\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\\/(?:mpeg|mp4|ogg|webm)|audio\\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+/]+=*$/i;\n\n url = String(url).trim();\n\n if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN)) {\n return url;\n }\n\n return `https://`;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,GAAW,EAAa;EAChD;EACA,IAAMC,gBAAgB,GAAG,iEAAiE;;EAE1F;EACA,IAAMC,gBAAgB,GAClB,qIAAqI;EAEzIF,GAAG,GAAGG,MAAM,CAACH,GAAG,CAAC,CAACI,IAAI,EAAE;EAExB,IAAIJ,GAAG,CAACK,KAAK,CAACJ,gBAAgB,CAAC,IAAID,GAAG,CAACK,KAAK,CAACH,gBAAgB,CAAC,EAAE;IAC5D,OAAOF,GAAG;EACd;EAEA;AACJ,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="web" />
2
+ /// <reference types="react" />
3
+ export declare function setFloatingElemPosition(targetRect: ClientRect | null, floatingElem: HTMLElement, anchorElem: HTMLElement, verticalGap?: number, horizontalOffset?: number): void;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setFloatingElemPosition = setFloatingElemPosition;
7
+ /**
8
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ *
13
+ */
14
+ var VERTICAL_GAP = 10;
15
+ var HORIZONTAL_OFFSET = 5;
16
+ function setFloatingElemPosition(targetRect, floatingElem, anchorElem) {
17
+ var verticalGap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : VERTICAL_GAP;
18
+ var horizontalOffset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : HORIZONTAL_OFFSET;
19
+ var scrollerElem = anchorElem.parentElement;
20
+ if (targetRect === null || !scrollerElem) {
21
+ floatingElem.style.opacity = "0";
22
+ floatingElem.style.transform = "translate(-10000px, -10000px)";
23
+ return;
24
+ }
25
+ var floatingElemRect = floatingElem.getBoundingClientRect();
26
+ var anchorElementRect = anchorElem.getBoundingClientRect();
27
+ var editorScrollerRect = scrollerElem.getBoundingClientRect();
28
+ var top = targetRect.top - floatingElemRect.height - verticalGap;
29
+ var left = targetRect.left - horizontalOffset;
30
+ if (top < editorScrollerRect.top) {
31
+ top += floatingElemRect.height + targetRect.height + verticalGap * 2;
32
+ }
33
+ if (left + floatingElemRect.width > editorScrollerRect.right) {
34
+ left = editorScrollerRect.right - floatingElemRect.width - horizontalOffset;
35
+ }
36
+ top -= anchorElementRect.top;
37
+ left -= anchorElementRect.left;
38
+ floatingElem.style.opacity = "1";
39
+ floatingElem.style.transform = "translate(".concat(left, "px, ").concat(top, "px)");
40
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VERTICAL_GAP","HORIZONTAL_OFFSET","setFloatingElemPosition","targetRect","floatingElem","anchorElem","verticalGap","horizontalOffset","scrollerElem","parentElement","style","opacity","transform","floatingElemRect","getBoundingClientRect","anchorElementRect","editorScrollerRect","top","height","left","width","right"],"sources":["setFloatingElemPosition.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 */\nconst VERTICAL_GAP = 10;\nconst HORIZONTAL_OFFSET = 5;\n\nexport function setFloatingElemPosition(\n targetRect: ClientRect | null,\n floatingElem: HTMLElement,\n anchorElem: HTMLElement,\n verticalGap: number = VERTICAL_GAP,\n horizontalOffset: number = HORIZONTAL_OFFSET\n): void {\n const scrollerElem = anchorElem.parentElement;\n\n if (targetRect === null || !scrollerElem) {\n floatingElem.style.opacity = \"0\";\n floatingElem.style.transform = \"translate(-10000px, -10000px)\";\n return;\n }\n\n const floatingElemRect = floatingElem.getBoundingClientRect();\n const anchorElementRect = anchorElem.getBoundingClientRect();\n const editorScrollerRect = scrollerElem.getBoundingClientRect();\n\n let top = targetRect.top - floatingElemRect.height - verticalGap;\n let left = targetRect.left - horizontalOffset;\n\n if (top < editorScrollerRect.top) {\n top += floatingElemRect.height + targetRect.height + verticalGap * 2;\n }\n\n if (left + floatingElemRect.width > editorScrollerRect.right) {\n left = editorScrollerRect.right - floatingElemRect.width - horizontalOffset;\n }\n\n top -= anchorElementRect.top;\n left -= anchorElementRect.left;\n\n floatingElem.style.opacity = \"1\";\n floatingElem.style.transform = `translate(${left}px, ${top}px)`;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,YAAY,GAAG,EAAE;AACvB,IAAMC,iBAAiB,GAAG,CAAC;AAEpB,SAASC,uBAAuB,CACnCC,UAA6B,EAC7BC,YAAyB,EACzBC,UAAuB,EAGnB;EAAA,IA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