@webiny/lexical-editor 5.37.0-beta.0 → 5.37.0-beta.2

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 (205) hide show
  1. package/commands/insertFiles.d.ts +14 -0
  2. package/commands/insertFiles.js +9 -0
  3. package/commands/insertFiles.js.map +1 -0
  4. package/commands/webiny-list.js.map +1 -1
  5. package/commands/webiny-quote.js.map +1 -1
  6. package/components/Editor/HeadingEditor.js +7 -9
  7. package/components/Editor/HeadingEditor.js.map +1 -1
  8. package/components/Editor/ParagraphEditor.js +7 -10
  9. package/components/Editor/ParagraphEditor.js.map +1 -1
  10. package/components/Editor/RichTextEditor.d.ts +9 -1
  11. package/components/Editor/RichTextEditor.js +41 -20
  12. package/components/Editor/RichTextEditor.js.map +1 -1
  13. package/components/ImageComponent.d.ts +23 -0
  14. package/components/ImageComponent.js +252 -0
  15. package/components/ImageComponent.js.map +1 -0
  16. package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +19 -10
  17. package/components/LexicalEditorConfig/LexicalEditorConfig.js +63 -9
  18. package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
  19. package/components/LexicalEditorConfig/components/Node.d.ts +14 -0
  20. package/components/LexicalEditorConfig/components/Node.js +38 -0
  21. package/components/LexicalEditorConfig/components/Node.js.map +1 -0
  22. package/components/LexicalEditorConfig/components/Plugin.d.ts +13 -0
  23. package/components/LexicalEditorConfig/components/Plugin.js +38 -0
  24. package/components/LexicalEditorConfig/components/Plugin.js.map +1 -0
  25. package/components/LexicalEditorConfig/components/ToolbarElement.d.ts +13 -0
  26. package/components/LexicalEditorConfig/components/ToolbarElement.js +38 -0
  27. package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -0
  28. package/components/LexicalHtmlRenderer.d.ts +2 -0
  29. package/components/LexicalHtmlRenderer.js +1 -1
  30. package/components/LexicalHtmlRenderer.js.map +1 -1
  31. package/components/Toolbar/StaticToolbar.css +260 -0
  32. package/components/Toolbar/StaticToolbar.d.ts +3 -0
  33. package/components/Toolbar/StaticToolbar.js +101 -0
  34. package/components/Toolbar/StaticToolbar.js.map +1 -0
  35. package/components/Toolbar/Toolbar.css +215 -4
  36. package/components/Toolbar/Toolbar.d.ts +2 -8
  37. package/components/Toolbar/Toolbar.js +25 -37
  38. package/components/Toolbar/Toolbar.js.map +1 -1
  39. package/components/ToolbarActions/BoldAction.js.map +1 -1
  40. package/components/ToolbarActions/BulletListAction.js +2 -2
  41. package/components/ToolbarActions/BulletListAction.js.map +1 -1
  42. package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
  43. package/components/ToolbarActions/FontColorAction.js +1 -1
  44. package/components/ToolbarActions/FontColorAction.js.map +1 -1
  45. package/components/ToolbarActions/FontSizeAction.js.map +1 -1
  46. package/components/ToolbarActions/ImageAction.d.ts +2 -0
  47. package/components/ToolbarActions/ImageAction.js +53 -0
  48. package/components/ToolbarActions/ImageAction.js.map +1 -0
  49. package/components/ToolbarActions/ItalicAction.js.map +1 -1
  50. package/components/ToolbarActions/LinkAction.js.map +1 -1
  51. package/components/ToolbarActions/NumberedListAction.js +16 -4
  52. package/components/ToolbarActions/NumberedListAction.js.map +1 -1
  53. package/components/ToolbarActions/QuoteAction.js.map +1 -1
  54. package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
  55. package/components/ToolbarActions/TypographyAction.js +1 -1
  56. package/components/ToolbarActions/TypographyAction.js.map +1 -1
  57. package/components/ToolbarActions/UnderlineAction.js.map +1 -1
  58. package/context/FontColorActionContext.js.map +1 -1
  59. package/context/RichTextEditorContext.d.ts +3 -1
  60. package/context/RichTextEditorContext.js +17 -11
  61. package/context/RichTextEditorContext.js.map +1 -1
  62. package/context/SharedHistoryContext.js.map +1 -1
  63. package/context/TextAlignmentActionContextProps.js.map +1 -1
  64. package/context/TypographyActionContext.js.map +1 -1
  65. package/hooks/useFontColorPicker.js.map +1 -1
  66. package/hooks/useList.js.map +1 -1
  67. package/hooks/useQuote.js.map +1 -1
  68. package/hooks/useRichTextEditor.js.map +1 -1
  69. package/hooks/useTextAlignmentAction.js.map +1 -1
  70. package/hooks/useTypographyAction.js.map +1 -1
  71. package/images/icons/insert-image.svg +4 -0
  72. package/index.d.ts +9 -9
  73. package/index.js +50 -44
  74. package/index.js.map +1 -1
  75. package/nodes/FontColorNode.js +0 -4
  76. package/nodes/FontColorNode.js.map +1 -1
  77. package/nodes/HeadingNode.js.map +1 -1
  78. package/nodes/ImageNode.d.ts +50 -0
  79. package/nodes/ImageNode.js +206 -0
  80. package/nodes/ImageNode.js.map +1 -0
  81. package/nodes/ListItemNode.js +0 -4
  82. package/nodes/ListItemNode.js.map +1 -1
  83. package/nodes/ListNode/formatList.js.map +1 -1
  84. package/nodes/ListNode.js +0 -6
  85. package/nodes/ListNode.js.map +1 -1
  86. package/nodes/ParagraphNode.js.map +1 -1
  87. package/nodes/QuoteNode.js.map +1 -1
  88. package/nodes/TypographyElementNode.js +2 -6
  89. package/nodes/TypographyElementNode.js.map +1 -1
  90. package/nodes/imageNode.css +43 -0
  91. package/nodes/webinyNodes.js +2 -1
  92. package/nodes/webinyNodes.js.map +1 -1
  93. package/package.json +6 -5
  94. package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
  95. package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
  96. package/plugins/CodeHighlightPlugin/index.js.map +1 -1
  97. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +5 -1
  98. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +52 -14
  99. package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
  100. package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
  101. package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
  102. package/plugins/ImagesPlugin/ImagesPlugin.d.ts +13 -0
  103. package/plugins/ImagesPlugin/ImagesPlugin.js +152 -0
  104. package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -0
  105. package/plugins/LexicalUpdateStatePlugin/LexicalUpdateStatePlugin.js.map +1 -1
  106. package/plugins/LexicalUpdateStatePlugin/index.js.map +1 -1
  107. package/plugins/ListPLugin/ListPlugin.d.ts +1 -0
  108. package/plugins/{WebinyListPLugin/WebinyListPlugin.js → ListPLugin/ListPlugin.js} +3 -3
  109. package/plugins/ListPLugin/ListPlugin.js.map +1 -0
  110. package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
  111. package/plugins/WebinyQuoteNodePlugin/WebinyQuoteNodePlugin.js.map +1 -1
  112. package/themes/webinyLexicalTheme.css +0 -6
  113. package/themes/webinyLexicalTheme.js +4 -1
  114. package/themes/webinyLexicalTheme.js.map +1 -1
  115. package/types.d.ts +9 -0
  116. package/types.js +28 -1
  117. package/types.js.map +1 -1
  118. package/ui/ContentEditable.css +22 -0
  119. package/ui/ContentEditable.d.ts +12 -0
  120. package/ui/ContentEditable.js +24 -0
  121. package/ui/ContentEditable.js.map +1 -0
  122. package/ui/Divider.js.map +1 -1
  123. package/ui/DropDown.js.map +1 -1
  124. package/ui/ImageResizer.d.ts +26 -0
  125. package/ui/ImageResizer.js +213 -0
  126. package/ui/ImageResizer.js.map +1 -0
  127. package/ui/LinkPreview.js +7 -7
  128. package/ui/LinkPreview.js.map +1 -1
  129. package/ui/Placeholder.css +2 -5
  130. package/ui/Placeholder.d.ts +3 -1
  131. package/ui/Placeholder.js +5 -1
  132. package/ui/Placeholder.js.map +1 -1
  133. package/ui/TextInput.js.map +1 -1
  134. package/ui/ToolbarActionDialog.js.map +1 -1
  135. package/utils/canUseDOM.d.ts +1 -0
  136. package/utils/canUseDOM.js +8 -0
  137. package/utils/canUseDOM.js.map +1 -0
  138. package/utils/files.d.ts +12 -0
  139. package/utils/files.js +62 -0
  140. package/utils/files.js.map +1 -0
  141. package/utils/findTypographyStyleByHtmlTag.js.map +1 -1
  142. package/utils/generateInitialLexicalValue.js.map +1 -1
  143. package/utils/getDOMRangeRect.js.map +1 -1
  144. package/utils/getLexicalTextSelectionState.js.map +1 -1
  145. package/utils/getSelectedNode.js.map +1 -1
  146. package/utils/getTransparentImage.d.ts +1 -0
  147. package/utils/getTransparentImage.js +10 -0
  148. package/utils/getTransparentImage.js.map +1 -0
  149. package/{plugins/AutoLinkPlugin/AutoLinkPlugin.d.ts → utils/isHTMLElement.d.ts} +3 -4
  150. package/utils/isHTMLElement.js +16 -0
  151. package/utils/isHTMLElement.js.map +1 -0
  152. package/utils/isValidJSON.js.map +1 -1
  153. package/utils/isValidLexicalData.js.map +1 -1
  154. package/utils/nodes/clearNodeFormating.js.map +1 -1
  155. package/utils/nodes/formatToHeading.js.map +1 -1
  156. package/utils/nodes/formatToParagraph.js.map +1 -1
  157. package/utils/nodes/formatToQuote.js.map +1 -1
  158. package/utils/nodes/insertImage.d.ts +2 -0
  159. package/utils/nodes/insertImage.js +22 -0
  160. package/utils/nodes/insertImage.js.map +1 -0
  161. package/utils/nodes/listNode.js.map +1 -1
  162. package/utils/point.js +0 -3
  163. package/utils/point.js.map +1 -1
  164. package/utils/rect.js +0 -5
  165. package/utils/rect.js.map +1 -1
  166. package/utils/sanitizeUrl.js.map +1 -1
  167. package/utils/setFloatingElemPosition.js.map +1 -1
  168. package/utils/styleObjectToString.js.map +1 -1
  169. package/utils/toTypographyEmotionMap.d.ts +1 -1
  170. package/utils/toTypographyEmotionMap.js +7 -2
  171. package/utils/toTypographyEmotionMap.js.map +1 -1
  172. package/components/AddRichTextEditorNodeType.d.ts +0 -6
  173. package/components/AddRichTextEditorNodeType.js +0 -28
  174. package/components/AddRichTextEditorNodeType.js.map +0 -1
  175. package/components/AddRichTextEditorPlugin.d.ts +0 -12
  176. package/components/AddRichTextEditorPlugin.js +0 -33
  177. package/components/AddRichTextEditorPlugin.js.map +0 -1
  178. package/components/AddToolbarAction.d.ts +0 -7
  179. package/components/AddToolbarAction.js +0 -33
  180. package/components/AddToolbarAction.js.map +0 -1
  181. package/components/Toolbar/HeadingToolbar.d.ts +0 -12
  182. package/components/Toolbar/HeadingToolbar.js +0 -23
  183. package/components/Toolbar/HeadingToolbar.js.map +0 -1
  184. package/components/Toolbar/ParagraphToolbar.d.ts +0 -12
  185. package/components/Toolbar/ParagraphToolbar.js +0 -23
  186. package/components/Toolbar/ParagraphToolbar.js.map +0 -1
  187. package/components/ToolbarPresets/HeadingToolbarPreset.d.ts +0 -2
  188. package/components/ToolbarPresets/HeadingToolbarPreset.js +0 -56
  189. package/components/ToolbarPresets/HeadingToolbarPreset.js.map +0 -1
  190. package/components/ToolbarPresets/ParagraphToolbarPreset.d.ts +0 -2
  191. package/components/ToolbarPresets/ParagraphToolbarPreset.js +0 -71
  192. package/components/ToolbarPresets/ParagraphToolbarPreset.js.map +0 -1
  193. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js +0 -46
  194. package/plugins/AutoLinkPlugin/AutoLinkPlugin.js.map +0 -1
  195. package/plugins/AutoLinkPlugin/index.d.ts +0 -1
  196. package/plugins/AutoLinkPlugin/index.js +0 -16
  197. package/plugins/AutoLinkPlugin/index.js.map +0 -1
  198. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.d.ts +0 -17
  199. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js +0 -88
  200. package/plugins/ClickableLinkPlugin/ClickableLinkPlugin.js.map +0 -1
  201. package/plugins/ClickableLinkPlugin/index.d.ts +0 -1
  202. package/plugins/ClickableLinkPlugin/index.js +0 -16
  203. package/plugins/ClickableLinkPlugin/index.js.map +0 -1
  204. package/plugins/WebinyListPLugin/WebinyListPlugin.d.ts +0 -1
  205. package/plugins/WebinyListPLugin/WebinyListPlugin.js.map +0 -1
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.LexicalAutoLinkPlugin = void 0;
8
- var _LexicalAutoLinkPlugin = require("@lexical/react/LexicalAutoLinkPlugin");
9
- var React = _interopRequireWildcard(require("react"));
10
- /**
11
- * Copyright (c) Meta Platforms, Inc. and affiliates.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file in the root directory of this source tree.
15
- *
16
- */
17
-
18
- var URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
19
- var EMAIL_MATCHER = /(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/;
20
- var MATCHERS = [function (text) {
21
- var match = URL_MATCHER.exec(text);
22
- if (match === null) {
23
- return null;
24
- }
25
- var fullMatch = match[0];
26
- return {
27
- index: match.index,
28
- length: fullMatch.length,
29
- text: fullMatch,
30
- url: fullMatch.startsWith("http") ? fullMatch : "https://".concat(fullMatch)
31
- };
32
- }, function (text) {
33
- var match = EMAIL_MATCHER.exec(text);
34
- return match && {
35
- index: match.index,
36
- length: match[0].length,
37
- text: match[0],
38
- url: "mailto:".concat(match[0])
39
- };
40
- }];
41
- var LexicalAutoLinkPlugin = function LexicalAutoLinkPlugin() {
42
- return /*#__PURE__*/React.createElement(_LexicalAutoLinkPlugin.AutoLinkPlugin, {
43
- matchers: MATCHERS
44
- });
45
- };
46
- exports.LexicalAutoLinkPlugin = LexicalAutoLinkPlugin;
@@ -1 +0,0 @@
1
- {"version":3,"names":["URL_MATCHER","EMAIL_MATCHER","MATCHERS","text","match","exec","fullMatch","index","length","url","startsWith","LexicalAutoLinkPlugin"],"sources":["AutoLinkPlugin.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 { AutoLinkPlugin } from \"@lexical/react/LexicalAutoLinkPlugin\";\nimport * as React from \"react\";\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\nconst EMAIL_MATCHER =\n /(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))/;\n\nconst MATCHERS = [\n (text: string) => {\n const match = URL_MATCHER.exec(text);\n if (match === null) {\n return null;\n }\n const fullMatch = match[0];\n return {\n index: match.index,\n length: fullMatch.length,\n text: fullMatch,\n url: fullMatch.startsWith(\"http\") ? fullMatch : `https://${fullMatch}`\n };\n },\n (text: string) => {\n const match = EMAIL_MATCHER.exec(text);\n return (\n match && {\n index: match.index,\n length: match[0].length,\n text: match[0],\n url: `mailto:${match[0]}`\n }\n );\n }\n];\n\nexport const LexicalAutoLinkPlugin = (): JSX.Element => {\n return <AutoLinkPlugin matchers={MATCHERS} />;\n};\n"],"mappings":";;;;;;;AAQA;AACA;AATA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,IAAMA,WAAW,GACb,iHAAiH;AAErH,IAAMC,aAAa,GACf,qJAAqJ;AAEzJ,IAAMC,QAAQ,GAAG,CACb,UAACC,IAAY,EAAK;EACd,IAAMC,KAAK,GAAGJ,WAAW,CAACK,IAAI,CAACF,IAAI,CAAC;EACpC,IAAIC,KAAK,KAAK,IAAI,EAAE;IAChB,OAAO,IAAI;EACf;EACA,IAAME,SAAS,GAAGF,KAAK,CAAC,CAAC,CAAC;EAC1B,OAAO;IACHG,KAAK,EAAEH,KAAK,CAACG,KAAK;IAClBC,MAAM,EAAEF,SAAS,CAACE,MAAM;IACxBL,IAAI,EAAEG,SAAS;IACfG,GAAG,EAAEH,SAAS,CAACI,UAAU,CAAC,MAAM,CAAC,GAAGJ,SAAS,qBAAcA,SAAS;EACxE,CAAC;AACL,CAAC,EACD,UAACH,IAAY,EAAK;EACd,IAAMC,KAAK,GAAGH,aAAa,CAACI,IAAI,CAACF,IAAI,CAAC;EACtC,OACIC,KAAK,IAAI;IACLG,KAAK,EAAEH,KAAK,CAACG,KAAK;IAClBC,MAAM,EAAEJ,KAAK,CAAC,CAAC,CAAC,CAACI,MAAM;IACvBL,IAAI,EAAEC,KAAK,CAAC,CAAC,CAAC;IACdK,GAAG,mBAAYL,KAAK,CAAC,CAAC,CAAC;EAC3B,CAAC;AAET,CAAC,CACJ;AAEM,IAAMO,qBAAqB,GAAG,SAAxBA,qBAAqB,GAAsB;EACpD,oBAAO,oBAAC,qCAAc;IAAC,QAAQ,EAAET;EAAS,EAAG;AACjD,CAAC;AAAC"}
@@ -1 +0,0 @@
1
- export * from "./AutoLinkPlugin";
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _AutoLinkPlugin = require("./AutoLinkPlugin");
7
- Object.keys(_AutoLinkPlugin).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _AutoLinkPlugin[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _AutoLinkPlugin[key];
14
- }
15
- });
16
- });
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./AutoLinkPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,17 +0,0 @@
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
- /// <reference types="react" />
9
- /// <reference types="react" />
10
- /// <reference types="web" />
11
- import type { LinkNode } from "@lexical/link";
12
- declare type LinkFilter = (event: MouseEvent, linkNode: LinkNode) => boolean;
13
- export declare function ClickableLinkPlugin({ filter, newTab }: {
14
- filter?: LinkFilter;
15
- newTab?: boolean;
16
- }): JSX.Element | null;
17
- export {};
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.ClickableLinkPlugin = ClickableLinkPlugin;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _link = require("@lexical/link");
10
- var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
11
- var _lexical = require("lexical");
12
- var _react = require("react");
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
-
21
- function ClickableLinkPlugin(_ref) {
22
- var filter = _ref.filter,
23
- _ref$newTab = _ref.newTab,
24
- newTab = _ref$newTab === void 0 ? true : _ref$newTab;
25
- var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
26
- _useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
27
- editor = _useLexicalComposerCo2[0];
28
- (0, _react.useEffect)(function () {
29
- function onClick(e) {
30
- var event = e;
31
- var linkDomNode = getLinkDomNode(event, editor);
32
- if (linkDomNode === null) {
33
- return;
34
- }
35
- var href = linkDomNode.getAttribute("href");
36
- if (linkDomNode.getAttribute("contenteditable") === "false" || href === undefined) {
37
- return;
38
- }
39
-
40
- // Allow user to select link text without following url
41
- var selection = editor.getEditorState().read(_lexical.$getSelection);
42
- if ((0, _lexical.$isRangeSelection)(selection) && !selection.isCollapsed()) {
43
- return;
44
- }
45
- var linkNode = null;
46
- editor.update(function () {
47
- var maybeLinkNode = (0, _lexical.$getNearestNodeFromDOMNode)(linkDomNode);
48
- if ((0, _link.$isLinkNode)(maybeLinkNode)) {
49
- linkNode = maybeLinkNode;
50
- }
51
- });
52
- if (linkNode === null || filter !== undefined && !filter(event, linkNode)) {
53
- return;
54
- }
55
- try {
56
- if (href !== null) {
57
- window.open(href, newTab || event.metaKey || event.ctrlKey ? "_blank" : "_self");
58
- }
59
- } catch (_unused) {
60
- // It didn't work, which is better than throwing an exception!
61
- }
62
- }
63
- return editor.registerRootListener(function (rootElement, prevRootElement) {
64
- if (prevRootElement !== null) {
65
- prevRootElement.removeEventListener("click", onClick);
66
- }
67
- if (rootElement !== null) {
68
- rootElement.addEventListener("click", onClick);
69
- }
70
- });
71
- }, [editor, filter, newTab]);
72
- return null;
73
- }
74
- function isLinkDomNode(domNode) {
75
- return domNode.nodeName.toLowerCase() === "a";
76
- }
77
- function getLinkDomNode(event, editor) {
78
- return editor.getEditorState().read(function () {
79
- var domNode = event.target;
80
- if (isLinkDomNode(domNode)) {
81
- return domNode;
82
- }
83
- if (domNode.parentNode && isLinkDomNode(domNode.parentNode)) {
84
- return domNode.parentNode;
85
- }
86
- return null;
87
- });
88
- }
@@ -1 +0,0 @@
1
- {"version":3,"names":["ClickableLinkPlugin","filter","newTab","useLexicalComposerContext","editor","useEffect","onClick","e","event","linkDomNode","getLinkDomNode","href","getAttribute","undefined","selection","getEditorState","read","$getSelection","$isRangeSelection","isCollapsed","linkNode","update","maybeLinkNode","$getNearestNodeFromDOMNode","$isLinkNode","window","open","metaKey","ctrlKey","registerRootListener","rootElement","prevRootElement","removeEventListener","addEventListener","isLinkDomNode","domNode","nodeName","toLowerCase","target","parentNode"],"sources":["ClickableLinkPlugin.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 type { LinkNode } from \"@lexical/link\";\nimport type { LexicalEditor } from \"lexical\";\n\nimport { $isLinkNode } from \"@lexical/link\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { $getNearestNodeFromDOMNode, $getSelection, $isRangeSelection } from \"lexical\";\nimport { useEffect } from \"react\";\n\ntype LinkFilter = (event: MouseEvent, linkNode: LinkNode) => boolean;\n\nexport function ClickableLinkPlugin({\n filter,\n newTab = true\n}: {\n filter?: LinkFilter;\n newTab?: boolean;\n}): JSX.Element | null {\n const [editor] = useLexicalComposerContext();\n useEffect(() => {\n function onClick(e: Event) {\n const event = e as MouseEvent;\n const linkDomNode = getLinkDomNode(event, editor);\n\n if (linkDomNode === null) {\n return;\n }\n\n const href = linkDomNode.getAttribute(\"href\");\n\n if (linkDomNode.getAttribute(\"contenteditable\") === \"false\" || href === undefined) {\n return;\n }\n\n // Allow user to select link text without following url\n const selection = editor.getEditorState().read($getSelection);\n if ($isRangeSelection(selection) && !selection.isCollapsed()) {\n return;\n }\n\n let linkNode = null;\n editor.update(() => {\n const maybeLinkNode = $getNearestNodeFromDOMNode(linkDomNode);\n\n if ($isLinkNode(maybeLinkNode)) {\n linkNode = maybeLinkNode;\n }\n });\n\n if (linkNode === null || (filter !== undefined && !filter(event, linkNode))) {\n return;\n }\n\n try {\n if (href !== null) {\n window.open(\n href,\n newTab || event.metaKey || event.ctrlKey ? \"_blank\" : \"_self\"\n );\n }\n } catch {\n // It didn't work, which is better than throwing an exception!\n }\n }\n\n return editor.registerRootListener(\n (rootElement: null | HTMLElement, prevRootElement: null | HTMLElement) => {\n if (prevRootElement !== null) {\n prevRootElement.removeEventListener(\"click\", onClick);\n }\n\n if (rootElement !== null) {\n rootElement.addEventListener(\"click\", onClick);\n }\n }\n );\n }, [editor, filter, newTab]);\n return null;\n}\n\nfunction isLinkDomNode(domNode: Node): boolean {\n return domNode.nodeName.toLowerCase() === \"a\";\n}\n\nfunction getLinkDomNode(event: MouseEvent, editor: LexicalEditor): HTMLAnchorElement | null {\n return editor.getEditorState().read(() => {\n const domNode = event.target as Node;\n\n if (isLinkDomNode(domNode)) {\n return domNode as HTMLAnchorElement;\n }\n\n if (domNode.parentNode && isLinkDomNode(domNode.parentNode)) {\n return domNode.parentNode as HTMLAnchorElement;\n }\n\n return null;\n });\n}\n"],"mappings":";;;;;;;;AAWA;AACA;AACA;AACA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYO,SAASA,mBAAmB,OAMZ;EAAA,IALnBC,MAAM,QAANA,MAAM;IAAA,mBACNC,MAAM;IAANA,MAAM,4BAAG,IAAI;EAKb,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EACb,IAAAC,gBAAS,EAAC,YAAM;IACZ,SAASC,OAAO,CAACC,CAAQ,EAAE;MACvB,IAAMC,KAAK,GAAGD,CAAe;MAC7B,IAAME,WAAW,GAAGC,cAAc,CAACF,KAAK,EAAEJ,MAAM,CAAC;MAEjD,IAAIK,WAAW,KAAK,IAAI,EAAE;QACtB;MACJ;MAEA,IAAME,IAAI,GAAGF,WAAW,CAACG,YAAY,CAAC,MAAM,CAAC;MAE7C,IAAIH,WAAW,CAACG,YAAY,CAAC,iBAAiB,CAAC,KAAK,OAAO,IAAID,IAAI,KAAKE,SAAS,EAAE;QAC/E;MACJ;;MAEA;MACA,IAAMC,SAAS,GAAGV,MAAM,CAACW,cAAc,EAAE,CAACC,IAAI,CAACC,sBAAa,CAAC;MAC7D,IAAI,IAAAC,0BAAiB,EAACJ,SAAS,CAAC,IAAI,CAACA,SAAS,CAACK,WAAW,EAAE,EAAE;QAC1D;MACJ;MAEA,IAAIC,QAAQ,GAAG,IAAI;MACnBhB,MAAM,CAACiB,MAAM,CAAC,YAAM;QAChB,IAAMC,aAAa,GAAG,IAAAC,mCAA0B,EAACd,WAAW,CAAC;QAE7D,IAAI,IAAAe,iBAAW,EAACF,aAAa,CAAC,EAAE;UAC5BF,QAAQ,GAAGE,aAAa;QAC5B;MACJ,CAAC,CAAC;MAEF,IAAIF,QAAQ,KAAK,IAAI,IAAKnB,MAAM,KAAKY,SAAS,IAAI,CAACZ,MAAM,CAACO,KAAK,EAAEY,QAAQ,CAAE,EAAE;QACzE;MACJ;MAEA,IAAI;QACA,IAAIT,IAAI,KAAK,IAAI,EAAE;UACfc,MAAM,CAACC,IAAI,CACPf,IAAI,EACJT,MAAM,IAAIM,KAAK,CAACmB,OAAO,IAAInB,KAAK,CAACoB,OAAO,GAAG,QAAQ,GAAG,OAAO,CAChE;QACL;MACJ,CAAC,CAAC,gBAAM;QACJ;MAAA;IAER;IAEA,OAAOxB,MAAM,CAACyB,oBAAoB,CAC9B,UAACC,WAA+B,EAAEC,eAAmC,EAAK;MACtE,IAAIA,eAAe,KAAK,IAAI,EAAE;QAC1BA,eAAe,CAACC,mBAAmB,CAAC,OAAO,EAAE1B,OAAO,CAAC;MACzD;MAEA,IAAIwB,WAAW,KAAK,IAAI,EAAE;QACtBA,WAAW,CAACG,gBAAgB,CAAC,OAAO,EAAE3B,OAAO,CAAC;MAClD;IACJ,CAAC,CACJ;EACL,CAAC,EAAE,CAACF,MAAM,EAAEH,MAAM,EAAEC,MAAM,CAAC,CAAC;EAC5B,OAAO,IAAI;AACf;AAEA,SAASgC,aAAa,CAACC,OAAa,EAAW;EAC3C,OAAOA,OAAO,CAACC,QAAQ,CAACC,WAAW,EAAE,KAAK,GAAG;AACjD;AAEA,SAAS3B,cAAc,CAACF,KAAiB,EAAEJ,MAAqB,EAA4B;EACxF,OAAOA,MAAM,CAACW,cAAc,EAAE,CAACC,IAAI,CAAC,YAAM;IACtC,IAAMmB,OAAO,GAAG3B,KAAK,CAAC8B,MAAc;IAEpC,IAAIJ,aAAa,CAACC,OAAO,CAAC,EAAE;MACxB,OAAOA,OAAO;IAClB;IAEA,IAAIA,OAAO,CAACI,UAAU,IAAIL,aAAa,CAACC,OAAO,CAACI,UAAU,CAAC,EAAE;MACzD,OAAOJ,OAAO,CAACI,UAAU;IAC7B;IAEA,OAAO,IAAI;EACf,CAAC,CAAC;AACN"}
@@ -1 +0,0 @@
1
- export * from "./ClickableLinkPlugin";
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _ClickableLinkPlugin = require("./ClickableLinkPlugin");
7
- Object.keys(_ClickableLinkPlugin).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _ClickableLinkPlugin[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _ClickableLinkPlugin[key];
14
- }
15
- });
16
- });
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ClickableLinkPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1 +0,0 @@
1
- export declare function WebinyListPlugin(): null;
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyListPlugin","useLexicalComposerContext","editor","useEffect","hasNodes","ListNode","ListItemNode","Error","useList"],"sources":["WebinyListPlugin.ts"],"sourcesContent":["import { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { useEffect } from \"react\";\nimport { ListNode } from \"~/nodes/ListNode\";\nimport { ListItemNode } from \"~/nodes/ListItemNode\";\nimport { useList } from \"~/hooks/useList\";\n\nexport function WebinyListPlugin(): null {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n if (!editor.hasNodes([ListNode, ListItemNode])) {\n throw new Error(\n \"WebinyListPlugin: WebinyListNode and/or WebinyListItemNode not registered on editor\"\n );\n }\n }, [editor]);\n\n useList(editor);\n\n return null;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEO,SAASA,gBAAgB,GAAS;EACrC,4BAAiB,IAAAC,iDAAyB,GAAE;IAAA;IAArCC,MAAM;EAEb,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAI,CAACD,MAAM,CAACE,QAAQ,CAAC,CAACC,kBAAQ,EAAEC,0BAAY,CAAC,CAAC,EAAE;MAC5C,MAAM,IAAIC,KAAK,CACX,qFAAqF,CACxF;IACL;EACJ,CAAC,EAAE,CAACL,MAAM,CAAC,CAAC;EAEZ,IAAAM,gBAAO,EAACN,MAAM,CAAC;EAEf,OAAO,IAAI;AACf"}