@webiny/lexical-nodes 5.38.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 (72) hide show
  1. package/FontColorNode.d.ts +43 -0
  2. package/FontColorNode.js +125 -0
  3. package/FontColorNode.js.map +1 -0
  4. package/HeadingNode.d.ts +32 -0
  5. package/HeadingNode.js +193 -0
  6. package/HeadingNode.js.map +1 -0
  7. package/ImageNode.d.ts +58 -0
  8. package/ImageNode.js +217 -0
  9. package/ImageNode.js.map +1 -0
  10. package/LICENSE +21 -0
  11. package/LinkNode.d.ts +106 -0
  12. package/LinkNode.js +531 -0
  13. package/LinkNode.js.map +1 -0
  14. package/ListItemNode.d.ts +44 -0
  15. package/ListItemNode.js +442 -0
  16. package/ListItemNode.js.map +1 -0
  17. package/ListNode.d.ts +42 -0
  18. package/ListNode.js +290 -0
  19. package/ListNode.js.map +1 -0
  20. package/ParagraphNode.d.ts +31 -0
  21. package/ParagraphNode.js +220 -0
  22. package/ParagraphNode.js.map +1 -0
  23. package/QuoteNode.d.ts +33 -0
  24. package/QuoteNode.js +227 -0
  25. package/QuoteNode.js.map +1 -0
  26. package/README.md +6 -0
  27. package/TypographyNode.d.ts +41 -0
  28. package/TypographyNode.js +153 -0
  29. package/TypographyNode.js.map +1 -0
  30. package/components/ImageNode/ContentEditable.css +22 -0
  31. package/components/ImageNode/ContentEditable.d.ts +12 -0
  32. package/components/ImageNode/ContentEditable.js +26 -0
  33. package/components/ImageNode/ContentEditable.js.map +1 -0
  34. package/components/ImageNode/ImageComponent.css +43 -0
  35. package/components/ImageNode/ImageComponent.d.ts +16 -0
  36. package/components/ImageNode/ImageComponent.js +254 -0
  37. package/components/ImageNode/ImageComponent.js.map +1 -0
  38. package/components/ImageNode/ImageResizer.d.ts +26 -0
  39. package/components/ImageNode/ImageResizer.js +215 -0
  40. package/components/ImageNode/ImageResizer.js.map +1 -0
  41. package/components/ImageNode/Placeholder.css +20 -0
  42. package/components/ImageNode/Placeholder.d.ts +15 -0
  43. package/components/ImageNode/Placeholder.js +30 -0
  44. package/components/ImageNode/Placeholder.js.map +1 -0
  45. package/components/ImageNode/SharedHistoryContext.d.ts +11 -0
  46. package/components/ImageNode/SharedHistoryContext.js +28 -0
  47. package/components/ImageNode/SharedHistoryContext.js.map +1 -0
  48. package/index.d.ts +22 -0
  49. package/index.js +226 -0
  50. package/index.js.map +1 -0
  51. package/package.json +32 -0
  52. package/types.d.ts +15 -0
  53. package/types.js +7 -0
  54. package/types.js.map +1 -0
  55. package/utils/clearNodeFormating.d.ts +2 -0
  56. package/utils/clearNodeFormating.js +30 -0
  57. package/utils/clearNodeFormating.js.map +1 -0
  58. package/utils/formatList.d.ts +19 -0
  59. package/utils/formatList.js +449 -0
  60. package/utils/formatList.js.map +1 -0
  61. package/utils/formatToHeading.d.ts +3 -0
  62. package/utils/formatToHeading.js +27 -0
  63. package/utils/formatToHeading.js.map +1 -0
  64. package/utils/formatToParagraph.d.ts +2 -0
  65. package/utils/formatToParagraph.js +22 -0
  66. package/utils/formatToParagraph.js.map +1 -0
  67. package/utils/formatToQuote.d.ts +2 -0
  68. package/utils/formatToQuote.js +27 -0
  69. package/utils/formatToQuote.js.map +1 -0
  70. package/utils/listNode.d.ts +11 -0
  71. package/utils/listNode.js +109 -0
  72. package/utils/listNode.js.map +1 -0
@@ -0,0 +1,43 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="web" />
3
+ import { EditorConfig, LexicalCommand, LexicalEditor, LexicalNode, NodeKey, RangeSelection, SerializedTextNode, Spread, TextNode } from "lexical";
4
+ import { EditorTheme } from "@webiny/lexical-theme";
5
+ export declare const ADD_FONT_COLOR_COMMAND: LexicalCommand<FontColorPayload>;
6
+ export interface FontColorPayload {
7
+ color: string;
8
+ themeColorName: string | undefined;
9
+ caption?: LexicalEditor;
10
+ key?: NodeKey;
11
+ }
12
+ declare type ThemeStyleColorName = string;
13
+ declare type ThemeColor = "custom" | ThemeStyleColorName;
14
+ export declare type SerializedFontColorNode = Spread<{
15
+ themeColor: ThemeColor;
16
+ color: string;
17
+ type: "font-color-node";
18
+ version: 1;
19
+ }, SerializedTextNode>;
20
+ /**
21
+ * Main responsibility of this node is to apply custom or Webiny theme color to selected text.
22
+ * Extends the original TextNode node to add additional transformation and support for webiny theme font color.
23
+ */
24
+ export declare class FontColorNode extends TextNode {
25
+ __themeColor: ThemeColor;
26
+ __color: string;
27
+ constructor(text: string, color: string, themeColor?: ThemeColor, key?: NodeKey);
28
+ static getType(): string;
29
+ static clone(node: FontColorNode): FontColorNode;
30
+ static importJSON(serializedNode: SerializedFontColorNode): TextNode;
31
+ exportJSON(): SerializedFontColorNode;
32
+ addColorValueToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement;
33
+ updateDOM(prevNode: FontColorNode, dom: HTMLElement, config: EditorConfig): boolean;
34
+ getColorStyle(): {
35
+ color: string;
36
+ themeColor: ThemeColor;
37
+ };
38
+ createDOM(config: EditorConfig): HTMLElement;
39
+ }
40
+ export declare const $createFontColorNode: (text: string, color: string, themeColor?: ThemeColor, key?: NodeKey) => FontColorNode;
41
+ export declare const $isFontColorNode: (node: LexicalNode) => node is FontColorNode;
42
+ export declare function $applyStylesToNode(node: FontColorNode, nodeStyleProvider: RangeSelection): void;
43
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.$applyStylesToNode = $applyStylesToNode;
8
+ exports.FontColorNode = exports.ADD_FONT_COLOR_COMMAND = exports.$isFontColorNode = exports.$createFontColorNode = void 0;
9
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
13
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
+ var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
16
+ var _lexical = require("lexical");
17
+ var ADD_FONT_COLOR_COMMAND = (0, _lexical.createCommand)("ADD_FONT_COLOR_COMMAND");
18
+ exports.ADD_FONT_COLOR_COMMAND = ADD_FONT_COLOR_COMMAND;
19
+ var FontColorNodeAttrName = "data-theme-font-color-name";
20
+ /**
21
+ * Main responsibility of this node is to apply custom or Webiny theme color to selected text.
22
+ * Extends the original TextNode node to add additional transformation and support for webiny theme font color.
23
+ */
24
+ var FontColorNode = /*#__PURE__*/function (_TextNode) {
25
+ (0, _inherits2.default)(FontColorNode, _TextNode);
26
+ var _super = (0, _createSuper2.default)(FontColorNode);
27
+ function FontColorNode(text, color, themeColor, key) {
28
+ var _this;
29
+ (0, _classCallCheck2.default)(this, FontColorNode);
30
+ _this = _super.call(this, text, key);
31
+ _this.__themeColor = themeColor || "custom";
32
+ _this.__color = color;
33
+ return _this;
34
+ }
35
+ (0, _createClass2.default)(FontColorNode, [{
36
+ key: "exportJSON",
37
+ value: function exportJSON() {
38
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(FontColorNode.prototype), "exportJSON", this).call(this)), {}, {
39
+ themeColor: this.__themeColor,
40
+ color: this.__color,
41
+ type: "font-color-node",
42
+ version: 1
43
+ });
44
+ }
45
+ }, {
46
+ key: "addColorValueToHTMLElement",
47
+ value: function addColorValueToHTMLElement(element, theme) {
48
+ var _theme$styles;
49
+ var hasThemeColor = this.__themeColor !== "custom";
50
+ // get the updated color from webiny theme
51
+ if (hasThemeColor && theme !== null && theme !== void 0 && (_theme$styles = theme.styles) !== null && _theme$styles !== void 0 && _theme$styles.colors) {
52
+ this.__color = theme.styles.colors[this.__themeColor];
53
+ }
54
+ element.setAttribute(FontColorNodeAttrName, this.__themeColor);
55
+ element.style.color = this.__color;
56
+ return element;
57
+ }
58
+ }, {
59
+ key: "updateDOM",
60
+ value: function updateDOM(prevNode, dom, config) {
61
+ var _theme$styles2;
62
+ var theme = config.theme;
63
+ var isUpdated = (0, _get2.default)((0, _getPrototypeOf2.default)(FontColorNode.prototype), "updateDOM", this).call(this, prevNode, dom, config);
64
+ var hasThemeColor = this.__themeColor !== "custom";
65
+ // get the updated color from webiny theme
66
+ if (hasThemeColor && theme !== null && theme !== void 0 && (_theme$styles2 = theme.styles) !== null && _theme$styles2 !== void 0 && _theme$styles2.colors) {
67
+ this.__color = theme.styles.colors[this.__themeColor];
68
+ }
69
+ dom.setAttribute(FontColorNodeAttrName, this.__themeColor);
70
+ dom.style.color = this.__color;
71
+ return isUpdated;
72
+ }
73
+ }, {
74
+ key: "getColorStyle",
75
+ value: function getColorStyle() {
76
+ return {
77
+ color: this.__color,
78
+ themeColor: this.__themeColor
79
+ };
80
+ }
81
+ }, {
82
+ key: "createDOM",
83
+ value: function createDOM(config) {
84
+ var element = (0, _get2.default)((0, _getPrototypeOf2.default)(FontColorNode.prototype), "createDOM", this).call(this, config);
85
+ return this.addColorValueToHTMLElement(element, config.theme);
86
+ }
87
+ }], [{
88
+ key: "getType",
89
+ value: function getType() {
90
+ return "font-color-node";
91
+ }
92
+ }, {
93
+ key: "clone",
94
+ value: function clone(node) {
95
+ return new FontColorNode(node.__text, node.__color, node.__themeColor, node.__key);
96
+ }
97
+ }, {
98
+ key: "importJSON",
99
+ value: function importJSON(serializedNode) {
100
+ var node = new FontColorNode(serializedNode.text, serializedNode.color, serializedNode.themeColor);
101
+ node.setTextContent(serializedNode.text);
102
+ node.setFormat(serializedNode.format);
103
+ node.setDetail(serializedNode.detail);
104
+ node.setMode(serializedNode.mode);
105
+ node.setStyle(serializedNode.style);
106
+ return node;
107
+ }
108
+ }]);
109
+ return FontColorNode;
110
+ }(_lexical.TextNode);
111
+ exports.FontColorNode = FontColorNode;
112
+ var $createFontColorNode = function $createFontColorNode(text, color, themeColor, key) {
113
+ return new FontColorNode(text, color, themeColor, key);
114
+ };
115
+ exports.$createFontColorNode = $createFontColorNode;
116
+ var $isFontColorNode = function $isFontColorNode(node) {
117
+ return node instanceof FontColorNode;
118
+ };
119
+ exports.$isFontColorNode = $isFontColorNode;
120
+ function $applyStylesToNode(node, nodeStyleProvider) {
121
+ node.setFormat(nodeStyleProvider.format);
122
+ node.setStyle(nodeStyleProvider.style);
123
+ }
124
+
125
+ //# sourceMappingURL=FontColorNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_lexical","require","ADD_FONT_COLOR_COMMAND","createCommand","exports","FontColorNodeAttrName","FontColorNode","_TextNode","_inherits2","default","_super","_createSuper2","text","color","themeColor","key","_this","_classCallCheck2","call","__themeColor","__color","_createClass2","value","exportJSON","_objectSpread2","_get2","_getPrototypeOf2","prototype","type","version","addColorValueToHTMLElement","element","theme","_theme$styles","hasThemeColor","styles","colors","setAttribute","style","updateDOM","prevNode","dom","config","_theme$styles2","isUpdated","getColorStyle","createDOM","getType","clone","node","__text","__key","importJSON","serializedNode","setTextContent","setFormat","format","setDetail","detail","setMode","mode","setStyle","TextNode","$createFontColorNode","$isFontColorNode","$applyStylesToNode","nodeStyleProvider"],"sources":["FontColorNode.ts"],"sourcesContent":["import {\n createCommand,\n EditorConfig,\n LexicalCommand,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n RangeSelection,\n SerializedTextNode,\n Spread,\n TextNode\n} from \"lexical\";\nimport { EditorTheme } from \"@webiny/lexical-theme\";\n\nexport const ADD_FONT_COLOR_COMMAND: LexicalCommand<FontColorPayload> =\n createCommand(\"ADD_FONT_COLOR_COMMAND\");\nconst FontColorNodeAttrName = \"data-theme-font-color-name\";\n\nexport interface FontColorPayload {\n // This color can be hex string\n color: string;\n // webiny theme color variable like color1, color2...\n themeColorName: string | undefined;\n caption?: LexicalEditor;\n key?: NodeKey;\n}\n\ntype ThemeStyleColorName = string;\ntype ThemeColor = \"custom\" | ThemeStyleColorName;\n\nexport type SerializedFontColorNode = Spread<\n {\n themeColor: ThemeColor;\n color: string;\n type: \"font-color-node\";\n version: 1;\n },\n SerializedTextNode\n>;\n\n/**\n * Main responsibility of this node is to apply custom or Webiny theme color to selected text.\n * Extends the original TextNode node to add additional transformation and support for webiny theme font color.\n */\nexport class FontColorNode extends TextNode {\n __themeColor: ThemeColor;\n __color: string;\n\n constructor(text: string, color: string, themeColor?: ThemeColor, key?: NodeKey) {\n super(text, key);\n this.__themeColor = themeColor || \"custom\";\n this.__color = color;\n }\n\n static override getType(): string {\n return \"font-color-node\";\n }\n\n static override clone(node: FontColorNode): FontColorNode {\n return new FontColorNode(node.__text, node.__color, node.__themeColor, node.__key);\n }\n\n static override importJSON(serializedNode: SerializedFontColorNode): TextNode {\n const node = new FontColorNode(\n serializedNode.text,\n serializedNode.color,\n serializedNode.themeColor\n );\n node.setTextContent(serializedNode.text);\n node.setFormat(serializedNode.format);\n node.setDetail(serializedNode.detail);\n node.setMode(serializedNode.mode);\n node.setStyle(serializedNode.style);\n return node;\n }\n\n override exportJSON(): SerializedFontColorNode {\n return {\n ...super.exportJSON(),\n themeColor: this.__themeColor,\n color: this.__color,\n type: \"font-color-node\",\n version: 1\n };\n }\n\n addColorValueToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n const hasThemeColor = this.__themeColor !== \"custom\";\n // get the updated color from webiny theme\n if (hasThemeColor && theme?.styles?.colors) {\n this.__color = theme.styles.colors[this.__themeColor];\n }\n\n element.setAttribute(FontColorNodeAttrName, this.__themeColor);\n element.style.color = this.__color;\n return element;\n }\n\n override updateDOM(prevNode: FontColorNode, dom: HTMLElement, config: EditorConfig): boolean {\n const theme = config.theme;\n const isUpdated = super.updateDOM(prevNode, dom, config);\n const hasThemeColor = this.__themeColor !== \"custom\";\n // get the updated color from webiny theme\n if (hasThemeColor && theme?.styles?.colors) {\n this.__color = theme.styles.colors[this.__themeColor];\n }\n\n dom.setAttribute(FontColorNodeAttrName, this.__themeColor);\n dom.style.color = this.__color;\n return isUpdated;\n }\n\n getColorStyle(): { color: string; themeColor: ThemeColor } {\n return {\n color: this.__color,\n themeColor: this.__themeColor\n };\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.addColorValueToHTMLElement(element, config.theme);\n }\n}\n\nexport const $createFontColorNode = (\n text: string,\n color: string,\n themeColor?: ThemeColor,\n key?: NodeKey\n): FontColorNode => {\n return new FontColorNode(text, color, themeColor, key);\n};\n\nexport const $isFontColorNode = (node: LexicalNode): node is FontColorNode => {\n return node instanceof FontColorNode;\n};\n\nexport function $applyStylesToNode(node: FontColorNode, nodeStyleProvider: RangeSelection) {\n node.setFormat(nodeStyleProvider.format);\n node.setStyle(nodeStyleProvider.style);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAcO,IAAMC,sBAAwD,GACjE,IAAAC,sBAAa,EAAC,wBAAwB,CAAC;AAACC,OAAA,CAAAF,sBAAA,GAAAA,sBAAA;AAC5C,IAAMG,qBAAqB,GAAG,4BAA4B;AAwB1D;AACA;AACA;AACA;AAHA,IAIaC,aAAa,0BAAAC,SAAA;EAAA,IAAAC,UAAA,CAAAC,OAAA,EAAAH,aAAA,EAAAC,SAAA;EAAA,IAAAG,MAAA,OAAAC,aAAA,CAAAF,OAAA,EAAAH,aAAA;EAItB,SAAAA,cAAYM,IAAY,EAAEC,KAAa,EAAEC,UAAuB,EAAEC,GAAa,EAAE;IAAA,IAAAC,KAAA;IAAA,IAAAC,gBAAA,CAAAR,OAAA,QAAAH,aAAA;IAC7EU,KAAA,GAAAN,MAAA,CAAAQ,IAAA,OAAMN,IAAI,EAAEG,GAAG;IACfC,KAAA,CAAKG,YAAY,GAAGL,UAAU,IAAI,QAAQ;IAC1CE,KAAA,CAAKI,OAAO,GAAGP,KAAK;IAAC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CAAC;AAC1C"}
@@ -0,0 +1,32 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="web" />
3
+ import { EditorConfig, LexicalNode, NodeKey, RangeSelection, Spread } from "lexical";
4
+ import { HeadingNode as BaseHeadingNode, HeadingTagType, SerializedHeadingNode as BaseSerializedHeadingNode } from "@lexical/rich-text";
5
+ import { WebinyTheme, ThemeEmotionMap } from "@webiny/lexical-theme";
6
+ import { ParagraphNode } from "./ParagraphNode";
7
+ import { TypographyStylesNode, ThemeStyleValue, TextNodeThemeStyles } from "./types";
8
+ export declare type SerializeHeadingNode = Spread<{
9
+ styles: ThemeStyleValue[];
10
+ type: "heading-element";
11
+ }, BaseSerializedHeadingNode>;
12
+ export declare class HeadingNode extends BaseHeadingNode implements TextNodeThemeStyles, TypographyStylesNode {
13
+ __styles: ThemeStyleValue[];
14
+ constructor(tag: HeadingTagType, typographyStyleId?: string, key?: NodeKey);
15
+ protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap): void;
16
+ setTypography(typographyStyleId: string): this;
17
+ getTypographyStyleId(): string | undefined;
18
+ clearTypographyStyle(): this;
19
+ hasTypographyStyle(): boolean;
20
+ getThemeStyles(): ThemeStyleValue[];
21
+ setThemeStyles(styles: ThemeStyleValue[]): this;
22
+ static getType(): string;
23
+ static clone(node: HeadingNode): HeadingNode;
24
+ protected updateElementWithThemeClasses(element: HTMLElement, theme: WebinyTheme): HTMLElement;
25
+ createDOM(config: EditorConfig): HTMLElement;
26
+ static importJSON(serializedNode: SerializeHeadingNode): BaseHeadingNode;
27
+ exportJSON(): SerializeHeadingNode;
28
+ insertNewAfter(selection?: RangeSelection, restoreSelection?: boolean): ParagraphNode | HeadingNode;
29
+ collapseAtStart(): true;
30
+ }
31
+ export declare function $createHeadingNode(tag: HeadingTagType, typographyStyleId?: string): HeadingNode;
32
+ export declare function $isHeadingNode(node: LexicalNode | null | undefined): node is HeadingNode;
package/HeadingNode.js ADDED
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.$createHeadingNode = $createHeadingNode;
8
+ exports.$isHeadingNode = $isHeadingNode;
9
+ exports.HeadingNode = void 0;
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
16
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
18
+ var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+ var _lexical = require("lexical");
21
+ var _utils = require("@lexical/utils");
22
+ var _richText = require("@lexical/rich-text");
23
+ var _lexicalTheme = require("@webiny/lexical-theme");
24
+ var HeadingNode = /*#__PURE__*/function (_BaseHeadingNode) {
25
+ (0, _inherits2.default)(HeadingNode, _BaseHeadingNode);
26
+ var _super = (0, _createSuper2.default)(HeadingNode);
27
+ function HeadingNode(tag, typographyStyleId, key) {
28
+ var _this;
29
+ (0, _classCallCheck2.default)(this, HeadingNode);
30
+ _this = _super.call(this, tag, key);
31
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "__styles", []);
32
+ if (typographyStyleId) {
33
+ _this.__styles.push({
34
+ styleId: typographyStyleId,
35
+ type: "typography"
36
+ });
37
+ }
38
+ return _this;
39
+ }
40
+ (0, _createClass2.default)(HeadingNode, [{
41
+ key: "setDefaultTypography",
42
+ value: function setDefaultTypography(themeEmotionMap) {
43
+ var typographyStyle = (0, _lexicalTheme.findTypographyStyleByHtmlTag)(this.__tag, themeEmotionMap);
44
+ if (typographyStyle) {
45
+ this.__styles.push({
46
+ styleId: typographyStyle.id,
47
+ type: "typography"
48
+ });
49
+ }
50
+ }
51
+ }, {
52
+ key: "setTypography",
53
+ value: function setTypography(typographyStyleId) {
54
+ var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getWritable", this).call(this);
55
+ if (!this.hasTypographyStyle()) {
56
+ var themeStyle = {
57
+ styleId: typographyStyleId,
58
+ type: "typography"
59
+ };
60
+ self.__styles.push(themeStyle);
61
+ }
62
+ return self;
63
+ }
64
+ }, {
65
+ key: "getTypographyStyleId",
66
+ value: function getTypographyStyleId() {
67
+ var style = this.__styles.find(function (x) {
68
+ return x.type === "typography";
69
+ });
70
+ return (style === null || style === void 0 ? void 0 : style.styleId) || undefined;
71
+ }
72
+ }, {
73
+ key: "clearTypographyStyle",
74
+ value: function clearTypographyStyle() {
75
+ var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getWritable", this).call(this);
76
+ self.__styles = self.__styles.filter(function (s) {
77
+ return s.type !== "typography";
78
+ });
79
+ return self;
80
+ }
81
+ }, {
82
+ key: "hasTypographyStyle",
83
+ value: function hasTypographyStyle() {
84
+ return !!this.getTypographyStyleId();
85
+ }
86
+ }, {
87
+ key: "getThemeStyles",
88
+ value: function getThemeStyles() {
89
+ var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getLatest", this).call(this);
90
+ return self.__styles;
91
+ }
92
+ }, {
93
+ key: "setThemeStyles",
94
+ value: function setThemeStyles(styles) {
95
+ var self = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "getWritable", this).call(this);
96
+ self.__styles = (0, _toConsumableArray2.default)(styles);
97
+ return self;
98
+ }
99
+ }, {
100
+ key: "updateElementWithThemeClasses",
101
+ value: function updateElementWithThemeClasses(element, theme) {
102
+ if (!(theme !== null && theme !== void 0 && theme.emotionMap)) {
103
+ return element;
104
+ }
105
+ if (!this.hasTypographyStyle()) {
106
+ this.setDefaultTypography(theme.emotionMap);
107
+ }
108
+ var typoStyleId = this.getTypographyStyleId();
109
+ var themeClasses;
110
+
111
+ // Typography css class
112
+ if (typoStyleId) {
113
+ var typographyStyle = theme.emotionMap[typoStyleId];
114
+ if (typographyStyle) {
115
+ themeClasses = typographyStyle.className;
116
+ }
117
+ }
118
+ if (themeClasses) {
119
+ (0, _utils.addClassNamesToElement)(element, themeClasses);
120
+ }
121
+ return element;
122
+ }
123
+ }, {
124
+ key: "createDOM",
125
+ value: function createDOM(config) {
126
+ var element = (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "createDOM", this).call(this, config);
127
+ return this.updateElementWithThemeClasses(element, config.theme);
128
+ }
129
+ }, {
130
+ key: "exportJSON",
131
+ value: function exportJSON() {
132
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(HeadingNode.prototype), "exportJSON", this).call(this)), {}, {
133
+ styles: this.__styles,
134
+ type: "heading-element",
135
+ version: 1
136
+ });
137
+ }
138
+
139
+ // Mutation
140
+ }, {
141
+ key: "insertNewAfter",
142
+ value: function insertNewAfter(selection) {
143
+ var restoreSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
144
+ // Next line for headings are always headings with the same tag
145
+ var newElement = $createHeadingNode(this.getTag());
146
+ var direction = this.getDirection();
147
+ newElement.setDirection(direction);
148
+ this.insertAfter(newElement, restoreSelection);
149
+ return newElement;
150
+ }
151
+ }, {
152
+ key: "collapseAtStart",
153
+ value: function collapseAtStart() {
154
+ var newElement = $createHeadingNode(this.getTag());
155
+ var children = this.getChildren();
156
+ children.forEach(function (child) {
157
+ return newElement.append(child);
158
+ });
159
+ this.replace(newElement);
160
+ return true;
161
+ }
162
+ }], [{
163
+ key: "getType",
164
+ value: function getType() {
165
+ return "heading-element";
166
+ }
167
+ }, {
168
+ key: "clone",
169
+ value: function clone(node) {
170
+ return new HeadingNode(node.getTag(), node.getTypographyStyleId(), node.__key);
171
+ }
172
+ }, {
173
+ key: "importJSON",
174
+ value: function importJSON(serializedNode) {
175
+ var node = $createHeadingNode(serializedNode.tag);
176
+ node.setFormat(serializedNode.format);
177
+ node.setIndent(serializedNode.indent);
178
+ node.setDirection(serializedNode.direction);
179
+ node.setThemeStyles(serializedNode.styles);
180
+ return node;
181
+ }
182
+ }]);
183
+ return HeadingNode;
184
+ }(_richText.HeadingNode);
185
+ exports.HeadingNode = HeadingNode;
186
+ function $createHeadingNode(tag, typographyStyleId) {
187
+ return (0, _lexical.$applyNodeReplacement)(new HeadingNode(tag, typographyStyleId));
188
+ }
189
+ function $isHeadingNode(node) {
190
+ return node instanceof HeadingNode;
191
+ }
192
+
193
+ //# sourceMappingURL=HeadingNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_lexical","require","_utils","_richText","_lexicalTheme","HeadingNode","_BaseHeadingNode","_inherits2","default","_super","_createSuper2","tag","typographyStyleId","key","_this","_classCallCheck2","call","_defineProperty2","_assertThisInitialized2","__styles","push","styleId","type","_createClass2","value","setDefaultTypography","themeEmotionMap","typographyStyle","findTypographyStyleByHtmlTag","__tag","id","setTypography","self","_get2","_getPrototypeOf2","prototype","hasTypographyStyle","themeStyle","getTypographyStyleId","style","find","x","undefined","clearTypographyStyle","filter","s","getThemeStyles","setThemeStyles","styles","_toConsumableArray2","updateElementWithThemeClasses","element","theme","emotionMap","typoStyleId","themeClasses","className","addClassNamesToElement","createDOM","config","exportJSON","_objectSpread2","version","insertNewAfter","selection","restoreSelection","arguments","length","newElement","$createHeadingNode","getTag","direction","getDirection","setDirection","insertAfter","collapseAtStart","children","getChildren","forEach","child","append","replace","getType","clone","node","__key","importJSON","serializedNode","setFormat","format","setIndent","indent","BaseHeadingNode","exports","$applyNodeReplacement","$isHeadingNode"],"sources":["HeadingNode.ts"],"sourcesContent":["import {\n EditorConfig,\n $applyNodeReplacement,\n LexicalNode,\n NodeKey,\n RangeSelection,\n Spread\n} from \"lexical\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport {\n HeadingNode as BaseHeadingNode,\n HeadingTagType,\n SerializedHeadingNode as BaseSerializedHeadingNode\n} from \"@lexical/rich-text\";\nimport { WebinyTheme, ThemeEmotionMap, findTypographyStyleByHtmlTag } from \"@webiny/lexical-theme\";\nimport { ParagraphNode } from \"~/ParagraphNode\";\nimport { TypographyStylesNode, ThemeStyleValue, TextNodeThemeStyles } from \"~/types\";\n\nexport type SerializeHeadingNode = Spread<\n {\n styles: ThemeStyleValue[];\n type: \"heading-element\";\n },\n BaseSerializedHeadingNode\n>;\n\nexport class HeadingNode\n extends BaseHeadingNode\n implements TextNodeThemeStyles, TypographyStylesNode\n{\n __styles: ThemeStyleValue[] = [];\n\n constructor(tag: HeadingTagType, typographyStyleId?: string, key?: NodeKey) {\n super(tag, key);\n\n if (typographyStyleId) {\n this.__styles.push({ styleId: typographyStyleId, type: \"typography\" });\n }\n }\n\n protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap) {\n const typographyStyle = findTypographyStyleByHtmlTag(this.__tag, themeEmotionMap);\n if (typographyStyle) {\n this.__styles.push({ styleId: typographyStyle.id, type: \"typography\" });\n }\n }\n\n setTypography(typographyStyleId: string): this {\n const self = super.getWritable();\n if (!this.hasTypographyStyle()) {\n const themeStyle = {\n styleId: typographyStyleId,\n type: \"typography\"\n } as ThemeStyleValue;\n self.__styles.push(themeStyle);\n }\n return self;\n }\n\n getTypographyStyleId(): string | undefined {\n const style = this.__styles.find(x => x.type === \"typography\");\n return style?.styleId || undefined;\n }\n\n clearTypographyStyle(): this {\n const self = super.getWritable();\n self.__styles = self.__styles.filter(s => s.type !== \"typography\");\n return self;\n }\n\n hasTypographyStyle(): boolean {\n return !!this.getTypographyStyleId();\n }\n\n getThemeStyles(): ThemeStyleValue[] {\n const self = super.getLatest();\n return self.__styles;\n }\n\n setThemeStyles(styles: ThemeStyleValue[]) {\n const self = super.getWritable();\n self.__styles = [...styles];\n return self;\n }\n\n static override getType(): string {\n return \"heading-element\";\n }\n\n static override clone(node: HeadingNode): HeadingNode {\n return new HeadingNode(node.getTag(), node.getTypographyStyleId(), node.__key);\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: WebinyTheme): HTMLElement {\n if (!theme?.emotionMap) {\n return element;\n }\n\n if (!this.hasTypographyStyle()) {\n this.setDefaultTypography(theme.emotionMap);\n }\n\n const typoStyleId = this.getTypographyStyleId();\n\n let themeClasses;\n\n // Typography css class\n if (typoStyleId) {\n const typographyStyle = theme.emotionMap[typoStyleId];\n if (typographyStyle) {\n themeClasses = typographyStyle.className;\n }\n }\n\n if (themeClasses) {\n addClassNamesToElement(element, themeClasses);\n }\n\n return element;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.updateElementWithThemeClasses(element, config.theme as WebinyTheme);\n }\n\n static override importJSON(serializedNode: SerializeHeadingNode): BaseHeadingNode {\n const node = $createHeadingNode(serializedNode.tag);\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n node.setThemeStyles(serializedNode.styles);\n return node;\n }\n\n override exportJSON(): SerializeHeadingNode {\n return {\n ...super.exportJSON(),\n styles: this.__styles,\n type: \"heading-element\",\n version: 1\n };\n }\n\n // Mutation\n override insertNewAfter(\n selection?: RangeSelection,\n restoreSelection = true\n ): ParagraphNode | HeadingNode {\n // Next line for headings are always headings with the same tag\n const newElement = $createHeadingNode(this.getTag());\n const direction = this.getDirection();\n newElement.setDirection(direction);\n this.insertAfter(newElement, restoreSelection);\n return newElement;\n }\n\n override collapseAtStart(): true {\n const newElement = $createHeadingNode(this.getTag());\n const children = this.getChildren();\n children.forEach(child => newElement.append(child));\n this.replace(newElement);\n return true;\n }\n}\n\nexport function $createHeadingNode(tag: HeadingTagType, typographyStyleId?: string): HeadingNode {\n return $applyNodeReplacement(new HeadingNode(tag, typographyStyleId));\n}\n\nexport function $isHeadingNode(node: LexicalNode | null | undefined): node is HeadingNode {\n return node instanceof HeadingNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAQA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,aAAA,GAAAH,OAAA;AAAmG,IAYtFI,WAAW,0BAAAC,gBAAA;EAAA,IAAAC,UAAA,CAAAC,OAAA,EAAAH,WAAA,EAAAC,gBAAA;EAAA,IAAAG,MAAA,OAAAC,aAAA,CAAAF,OAAA,EAAAH,WAAA;EAMpB,SAAAA,YAAYM,GAAmB,EAAEC,iBAA0B,EAAEC,GAAa,EAAE;IAAA,IAAAC,KAAA;IAAA,IAAAC,gBAAA,CAAAP,OAAA,QAAAH,WAAA;IACxES,KAAA,GAAAL,MAAA,CAAAO,IAAA,OAAML,GAAG,EAAEE,GAAG;IAAE,IAAAI,gBAAA,CAAAT,OAAA,MAAAU,uBAAA,CAAAV,OAAA,EAAAM,KAAA,eAHU,EAAE;IAK5B,IAAIF,iBAAiB,EAAE;MACnBE,KAAA,CAAKK,QAAQ,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAET,iBAAiB;QAAEU,IAAI,EAAE;MAAa,CAAC,CAAC;IAC1E;IAAC,OAAAR,KAAA;EACL;EAAC,IAAAS,aAAA,CAAAf,OAAA,EAAAH,WAAA;IAAAQ,GAAA;IAAAW,KAAA,EAED,SAAAC,qBAA+BC,eAAgC,EAAE;MAC7D,IAAMC,eAAe,GAAG,IAAAC,0CAA4B,EAAC,IAAI,CAACC,KAAK,EAAEH,eAAe,CAAC;MACjF,IAAIC,eAAe,EAAE;QACjB,IAAI,CAACR,QAAQ,CAACC,IAAI,CAAC;UAAEC,OAAO,EAAEM,eAAe,C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.ts ADDED
@@ -0,0 +1,58 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="web" />
3
+ /// <reference types="react" />
4
+ import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedEditor, SerializedLexicalNode, Spread } from "lexical";
5
+ import { DecoratorNode } from "lexical";
6
+ export declare type SerializedImageNode = Spread<{
7
+ id: string;
8
+ altText: string;
9
+ caption: SerializedEditor;
10
+ height?: number;
11
+ maxWidth: number;
12
+ showCaption: boolean;
13
+ src: string;
14
+ width?: number;
15
+ }, SerializedLexicalNode>;
16
+ export interface ImageNodeProps {
17
+ id: string;
18
+ src: string;
19
+ altText: string;
20
+ maxWidth: number;
21
+ width?: "inherit" | number;
22
+ height?: "inherit" | number;
23
+ showCaption?: boolean;
24
+ caption?: LexicalEditor;
25
+ captionsEnabled?: boolean;
26
+ }
27
+ export declare class ImageNode extends DecoratorNode<JSX.Element> {
28
+ __id: string;
29
+ __src: string;
30
+ __altText: string;
31
+ __width: "inherit" | number;
32
+ __height: "inherit" | number;
33
+ __maxWidth: number;
34
+ __showCaption: boolean;
35
+ __caption: LexicalEditor;
36
+ __captionsEnabled: boolean;
37
+ static getType(): string;
38
+ static clone(node: ImageNode): ImageNode;
39
+ static importJSON(serializedNode: SerializedImageNode): ImageNode;
40
+ exportDOM(): DOMExportOutput;
41
+ /**
42
+ * Control how an HTMLElement is represented in Lexical.
43
+ * DOM data comes from clipboard or parsing HTML to nodes with the available lexical functions.
44
+ * (@see @lexical/html package: https://github.com/facebook/lexical/blob/main/packages/lexical-html/README.md).
45
+ */
46
+ static importDOM(): DOMConversionMap | null;
47
+ constructor(props: ImageNodeProps, key?: NodeKey);
48
+ exportJSON(): SerializedImageNode;
49
+ setWidthAndHeight(width: "inherit" | number, height: "inherit" | number): void;
50
+ setShowCaption(showCaption: boolean): void;
51
+ createDOM(config: EditorConfig): HTMLElement;
52
+ updateDOM(): false;
53
+ getSrc(): string;
54
+ getAltText(): string;
55
+ decorate(): JSX.Element;
56
+ }
57
+ export declare function $createImageNode(props: ImageNodeProps, key?: string): ImageNode;
58
+ export declare function $isImageNode(node: LexicalNode | null | undefined): node is ImageNode;