@webiny/lexical-nodes 5.43.2 → 6.0.0-alpha.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.
- package/FontColorNode.js +97 -145
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +94 -146
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +142 -189
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +253 -346
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +276 -354
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +150 -204
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +114 -165
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +118 -172
- package/QuoteNode.js.map +1 -1
- package/TypographyNode.js +93 -130
- package/TypographyNode.js.map +1 -1
- package/components/ImageNode/ContentEditable.js +7 -14
- package/components/ImageNode/ContentEditable.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +104 -124
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +78 -83
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/components/ImageNode/Placeholder.js +10 -16
- package/components/ImageNode/Placeholder.js.map +1 -1
- package/components/ImageNode/SharedHistoryContext.js +12 -20
- package/components/ImageNode/SharedHistoryContext.js.map +1 -1
- package/index.js +48 -223
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/types.js +1 -5
- package/utils/clearNodeFormating.js +12 -18
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +171 -208
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +8 -15
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +8 -16
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +8 -15
- package/utils/formatToQuote.js.map +1 -1
- package/utils/listNode.js +37 -50
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +41 -45
- package/utils/toggleLink.js.map +1 -1
package/FontColorNode.js
CHANGED
|
@@ -1,169 +1,121 @@
|
|
|
1
|
-
|
|
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.ThemeColorValue = exports.FontColorNode = exports.ADD_FONT_COLOR_COMMAND = exports.$isFontColorNode = exports.$createFontColorNode = void 0;
|
|
9
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
-
var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
11
|
-
var _superPropGet2 = _interopRequireDefault(require("@babel/runtime/helpers/superPropGet"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
var _lexical = require("lexical");
|
|
16
|
-
var ThemeColorValue = exports.ThemeColorValue = /*#__PURE__*/function () {
|
|
1
|
+
import { $getSelection, $isRangeSelection, createCommand, TextNode } from "lexical";
|
|
2
|
+
export class ThemeColorValue {
|
|
17
3
|
// Webiny theme color variable, like color1, color2, etc.
|
|
18
4
|
|
|
19
5
|
// This can be a HEX value or a CSS variable.
|
|
20
6
|
|
|
21
|
-
|
|
22
|
-
(0, _classCallCheck2.default)(this, ThemeColorValue);
|
|
7
|
+
constructor(value, name) {
|
|
23
8
|
this.value = value;
|
|
24
9
|
this.name = name ?? "custom";
|
|
25
10
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}, {
|
|
37
|
-
key: "updateFromTheme",
|
|
38
|
-
value: function updateFromTheme(theme) {
|
|
39
|
-
if (theme?.styles?.colors && this.name !== "custom") {
|
|
40
|
-
this.value = theme.styles?.colors[this.name];
|
|
41
|
-
}
|
|
11
|
+
getValue() {
|
|
12
|
+
return this.value;
|
|
13
|
+
}
|
|
14
|
+
getName() {
|
|
15
|
+
return this.name;
|
|
16
|
+
}
|
|
17
|
+
updateFromTheme(theme) {
|
|
18
|
+
if (theme?.styles?.colors && this.name !== "custom") {
|
|
19
|
+
this.value = theme.styles?.colors[this.name];
|
|
42
20
|
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const ADD_FONT_COLOR_COMMAND = createCommand("ADD_FONT_COLOR_COMMAND");
|
|
24
|
+
const FontColorNodeAttrName = "data-theme-font-color-name";
|
|
47
25
|
/**
|
|
48
26
|
* Main responsibility of this node is to apply custom or Webiny theme color to selected text.
|
|
49
27
|
* Extends the original TextNode node to add additional transformation and support for webiny theme font color.
|
|
50
28
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_this = (0, _callSuper2.default)(this, FontColorNode, [text, key]);
|
|
56
|
-
_this.__color = color;
|
|
57
|
-
return _this;
|
|
29
|
+
export class FontColorNode extends TextNode {
|
|
30
|
+
constructor(text, color, key) {
|
|
31
|
+
super(text, key);
|
|
32
|
+
this.__color = color;
|
|
58
33
|
}
|
|
59
|
-
(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
34
|
+
static getType() {
|
|
35
|
+
return "font-color-node";
|
|
36
|
+
}
|
|
37
|
+
static clone(node) {
|
|
38
|
+
return new FontColorNode(node.__text, node.__color, node.__key);
|
|
39
|
+
}
|
|
40
|
+
static importJSON(serializedNode) {
|
|
41
|
+
const node = new FontColorNode(serializedNode.text, new ThemeColorValue(serializedNode.color, serializedNode.themeColor));
|
|
42
|
+
node.setTextContent(serializedNode.text);
|
|
43
|
+
node.setFormat(serializedNode.format);
|
|
44
|
+
node.setDetail(serializedNode.detail);
|
|
45
|
+
node.setMode(serializedNode.mode);
|
|
46
|
+
node.setStyle(serializedNode.style);
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
splitText(...splitOffsets) {
|
|
50
|
+
const newNodes = super.splitText(...splitOffsets);
|
|
51
|
+
const selection = $getSelection();
|
|
52
|
+
|
|
53
|
+
// After splitting, we need to re-apply styling to the new TextNodes.
|
|
54
|
+
const fontColorNodes = newNodes.map(node => {
|
|
55
|
+
if (node instanceof FontColorNode) {
|
|
56
|
+
return node;
|
|
66
57
|
}
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
const fontColorNode = $createFontColorNode(node.getTextContent(), this.__color);
|
|
59
|
+
$applyStylesToNode(fontColorNode, this);
|
|
60
|
+
const newNode = node.replace(fontColorNode);
|
|
69
61
|
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
// Since we're replacing the existing node, we need to update the selection keys.
|
|
63
|
+
// This is very important to not break the editor functionality!
|
|
64
|
+
if ($isRangeSelection(selection)) {
|
|
65
|
+
const anchor = selection.anchor;
|
|
66
|
+
const focus = selection.focus;
|
|
67
|
+
if (anchor.key === node.getKey()) {
|
|
68
|
+
anchor.key = newNode.getKey();
|
|
74
69
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var newNode = node.replace(fontColorNode);
|
|
78
|
-
|
|
79
|
-
// Since we're replacing the existing node, we need to update the selection keys.
|
|
80
|
-
// This is very important to not break the editor functionality!
|
|
81
|
-
if ((0, _lexical.$isRangeSelection)(selection)) {
|
|
82
|
-
var anchor = selection.anchor;
|
|
83
|
-
var focus = selection.focus;
|
|
84
|
-
if (anchor.key === node.getKey()) {
|
|
85
|
-
anchor.key = newNode.getKey();
|
|
86
|
-
}
|
|
87
|
-
if (focus.key === node.getKey()) {
|
|
88
|
-
focus.key = newNode.getKey();
|
|
89
|
-
}
|
|
70
|
+
if (focus.key === node.getKey()) {
|
|
71
|
+
focus.key = newNode.getKey();
|
|
90
72
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}, {
|
|
132
|
-
key: "createDOM",
|
|
133
|
-
value: function createDOM(config) {
|
|
134
|
-
var element = (0, _superPropGet2.default)(FontColorNode, "createDOM", this, 3)([config]);
|
|
135
|
-
return this.addColorValueToHTMLElement(element, config.theme);
|
|
136
|
-
}
|
|
137
|
-
}], [{
|
|
138
|
-
key: "getType",
|
|
139
|
-
value: function getType() {
|
|
140
|
-
return "font-color-node";
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "clone",
|
|
144
|
-
value: function clone(node) {
|
|
145
|
-
return new FontColorNode(node.__text, node.__color, node.__key);
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
key: "importJSON",
|
|
149
|
-
value: function importJSON(serializedNode) {
|
|
150
|
-
var node = new FontColorNode(serializedNode.text, new ThemeColorValue(serializedNode.color, serializedNode.themeColor));
|
|
151
|
-
node.setTextContent(serializedNode.text);
|
|
152
|
-
node.setFormat(serializedNode.format);
|
|
153
|
-
node.setDetail(serializedNode.detail);
|
|
154
|
-
node.setMode(serializedNode.mode);
|
|
155
|
-
node.setStyle(serializedNode.style);
|
|
156
|
-
return node;
|
|
157
|
-
}
|
|
158
|
-
}]);
|
|
159
|
-
}(_lexical.TextNode);
|
|
160
|
-
var $createFontColorNode = exports.$createFontColorNode = function $createFontColorNode(text, color) {
|
|
73
|
+
}
|
|
74
|
+
return newNode;
|
|
75
|
+
});
|
|
76
|
+
return fontColorNodes;
|
|
77
|
+
}
|
|
78
|
+
exportJSON() {
|
|
79
|
+
return {
|
|
80
|
+
...super.exportJSON(),
|
|
81
|
+
themeColor: this.__color.getName(),
|
|
82
|
+
color: this.__color.getValue(),
|
|
83
|
+
type: "font-color-node",
|
|
84
|
+
version: 1
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
addColorValueToHTMLElement(element, theme) {
|
|
88
|
+
// Update color from webiny theme
|
|
89
|
+
this.__color.updateFromTheme(theme);
|
|
90
|
+
element.setAttribute(FontColorNodeAttrName, this.__color.getName());
|
|
91
|
+
element.style.color = this.__color.getValue();
|
|
92
|
+
return element;
|
|
93
|
+
}
|
|
94
|
+
updateDOM(prevNode, dom, config) {
|
|
95
|
+
const isUpdated = super.updateDOM(prevNode, dom, config);
|
|
96
|
+
this.__color.updateFromTheme(config.theme);
|
|
97
|
+
dom.setAttribute(FontColorNodeAttrName, this.__color.getName());
|
|
98
|
+
dom.style.color = this.__color.getValue();
|
|
99
|
+
return isUpdated;
|
|
100
|
+
}
|
|
101
|
+
getColorStyle() {
|
|
102
|
+
return {
|
|
103
|
+
color: this.__color.getValue(),
|
|
104
|
+
themeColor: this.__color.getName()
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
createDOM(config) {
|
|
108
|
+
const element = super.createDOM(config);
|
|
109
|
+
return this.addColorValueToHTMLElement(element, config.theme);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export const $createFontColorNode = (text, color) => {
|
|
161
113
|
return new FontColorNode(text, color);
|
|
162
114
|
};
|
|
163
|
-
|
|
115
|
+
export const $isFontColorNode = node => {
|
|
164
116
|
return node instanceof FontColorNode;
|
|
165
117
|
};
|
|
166
|
-
function $applyStylesToNode(node, source) {
|
|
118
|
+
export function $applyStylesToNode(node, source) {
|
|
167
119
|
node.setFormat(source.getFormat());
|
|
168
120
|
node.setStyle(source.getStyle());
|
|
169
121
|
}
|
package/FontColorNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lexical","require","ThemeColorValue","exports","value","name","_classCallCheck2","default","_createClass2","key","getValue","getName","updateFromTheme","theme","styles","colors","ADD_FONT_COLOR_COMMAND","createCommand","FontColorNodeAttrName","FontColorNode","_TextNode","text","color","_this","_callSuper2","__color","_inherits2","splitText","_this2","_len","arguments","length","splitOffsets","Array","_key","newNodes","_superPropGet2","selection","$getSelection","fontColorNodes","map","node","fontColorNode","$createFontColorNode","getTextContent","$applyStylesToNode","newNode","replace","$isRangeSelection","anchor","focus","getKey","exportJSON","_objectSpread2","themeColor","type","version","addColorValueToHTMLElement","element","setAttribute","style","updateDOM","prevNode","dom","config","isUpdated","getColorStyle","createDOM","getType","clone","__text","__key","importJSON","serializedNode","setTextContent","setFormat","format","setDetail","detail","setMode","mode","setStyle","TextNode","$isFontColorNode","source","getFormat","getStyle"],"sources":["FontColorNode.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n createCommand,\n EditorConfig,\n LexicalNode,\n SerializedTextNode,\n Spread,\n TextNode\n} from \"lexical\";\nimport { EditorTheme } from \"@webiny/lexical-theme\";\n\nexport class ThemeColorValue {\n // Webiny theme color variable, like color1, color2, etc.\n private readonly name: string;\n // This can be a HEX value or a CSS variable.\n private value: string;\n\n constructor(value: string, name?: string) {\n this.value = value;\n this.name = name ?? \"custom\";\n }\n\n getValue() {\n return this.value;\n }\n\n getName() {\n return this.name;\n }\n\n updateFromTheme(theme: EditorTheme) {\n if (theme?.styles?.colors && this.name !== \"custom\") {\n this.value = theme.styles?.colors[this.name];\n }\n }\n}\n\nexport const ADD_FONT_COLOR_COMMAND = createCommand<FontColorPayload>(\"ADD_FONT_COLOR_COMMAND\");\n\nconst FontColorNodeAttrName = \"data-theme-font-color-name\";\n\nexport interface FontColorPayload {\n color: ThemeColorValue;\n}\n\nexport type SerializedFontColorNode = Spread<\n {\n themeColor: string;\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 private readonly __color: ThemeColorValue;\n\n constructor(text: string, color: ThemeColorValue, key?: string) {\n super(text, key);\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.__key);\n }\n\n static override importJSON(serializedNode: SerializedFontColorNode): TextNode {\n const node = new FontColorNode(\n serializedNode.text,\n new ThemeColorValue(serializedNode.color, 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 splitText(...splitOffsets: Array<number>): Array<FontColorNode> {\n const newNodes = super.splitText(...splitOffsets);\n\n const selection = $getSelection();\n\n // After splitting, we need to re-apply styling to the new TextNodes.\n const fontColorNodes = newNodes.map(node => {\n if (node instanceof FontColorNode) {\n return node;\n }\n\n const fontColorNode = $createFontColorNode(node.getTextContent(), this.__color);\n $applyStylesToNode(fontColorNode, this);\n\n const newNode = node.replace(fontColorNode);\n\n // Since we're replacing the existing node, we need to update the selection keys.\n // This is very important to not break the editor functionality!\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const focus = selection.focus;\n\n if (anchor.key === node.getKey()) {\n anchor.key = newNode.getKey();\n }\n\n if (focus.key === node.getKey()) {\n focus.key = newNode.getKey();\n }\n }\n\n return newNode;\n });\n\n return fontColorNodes as Array<FontColorNode>;\n }\n\n override exportJSON(): SerializedFontColorNode {\n return {\n ...super.exportJSON(),\n themeColor: this.__color.getName(),\n color: this.__color.getValue(),\n type: \"font-color-node\",\n version: 1\n };\n }\n\n private addColorValueToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n // Update color from webiny theme\n this.__color.updateFromTheme(theme);\n element.setAttribute(FontColorNodeAttrName, this.__color.getName());\n element.style.color = this.__color.getValue();\n return element;\n }\n\n override updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean {\n const isUpdated = super.updateDOM(prevNode, dom, config);\n this.__color.updateFromTheme(config.theme as EditorTheme);\n\n dom.setAttribute(FontColorNodeAttrName, this.__color.getName());\n dom.style.color = this.__color.getValue();\n return isUpdated;\n }\n\n getColorStyle() {\n return {\n color: this.__color.getValue(),\n themeColor: this.__color.getName()\n };\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.addColorValueToHTMLElement(element, config.theme as EditorTheme);\n }\n}\n\nexport const $createFontColorNode = (text: string, color: ThemeColorValue): FontColorNode => {\n return new FontColorNode(text, color);\n};\n\nexport const $isFontColorNode = (node: LexicalNode): node is FontColorNode => {\n return node instanceof FontColorNode;\n};\n\nexport function $applyStylesToNode(node: TextNode, source: TextNode) {\n node.setFormat(source.getFormat());\n node.setStyle(source.getStyle());\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AASiB,IAGJC,eAAe,GAAAC,OAAA,CAAAD,eAAA;EACxB;;EAEA;;EAGA,SAAAA,gBAAYE,KAAa,EAAEC,IAAa,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAL,eAAA;IACtC,IAAI,CAACE,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,IAAI,GAAGA,IAAI,IAAI,QAAQ;EAChC;EAAC,WAAA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;AAAA,EA3B8ByC,iBAAQ;AA0GpC,IAAMvC,oBAAoB,GAAAxC,OAAA,CAAAwC,oBAAA,GAAG,SAAvBA,oBAAoBA,CAAItB,IAAY,EAAEC,KAAsB,EAAoB;EACzF,OAAO,IAAIH,aAAa,CAACE,IAAI,EAAEC,KAAK,CAAC;AACzC,CAAC;AAEM,IAAM6D,gBAAgB,GAAAhF,OAAA,CAAAgF,gBAAA,GAAG,SAAnBA,gBAAgBA,CAAI1C,IAAiB,EAA4B;EAC1E,OAAOA,IAAI,YAAYtB,aAAa;AACxC,CAAC;AAEM,SAAS0B,kBAAkBA,CAACJ,IAAc,EAAE2C,MAAgB,EAAE;EACjE3C,IAAI,CAACkC,SAAS,CAACS,MAAM,CAACC,SAAS,CAAC,CAAC,CAAC;EAClC5C,IAAI,CAACwC,QAAQ,CAACG,MAAM,CAACE,QAAQ,CAAC,CAAC,CAAC;AACpC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["$getSelection","$isRangeSelection","createCommand","TextNode","ThemeColorValue","constructor","value","name","getValue","getName","updateFromTheme","theme","styles","colors","ADD_FONT_COLOR_COMMAND","FontColorNodeAttrName","FontColorNode","text","color","key","__color","getType","clone","node","__text","__key","importJSON","serializedNode","themeColor","setTextContent","setFormat","format","setDetail","detail","setMode","mode","setStyle","style","splitText","splitOffsets","newNodes","selection","fontColorNodes","map","fontColorNode","$createFontColorNode","getTextContent","$applyStylesToNode","newNode","replace","anchor","focus","getKey","exportJSON","type","version","addColorValueToHTMLElement","element","setAttribute","updateDOM","prevNode","dom","config","isUpdated","getColorStyle","createDOM","$isFontColorNode","source","getFormat","getStyle"],"sources":["FontColorNode.ts"],"sourcesContent":["import {\n $getSelection,\n $isRangeSelection,\n createCommand,\n EditorConfig,\n LexicalNode,\n SerializedTextNode,\n Spread,\n TextNode\n} from \"lexical\";\nimport { EditorTheme } from \"@webiny/lexical-theme\";\n\nexport class ThemeColorValue {\n // Webiny theme color variable, like color1, color2, etc.\n private readonly name: string;\n // This can be a HEX value or a CSS variable.\n private value: string;\n\n constructor(value: string, name?: string) {\n this.value = value;\n this.name = name ?? \"custom\";\n }\n\n getValue() {\n return this.value;\n }\n\n getName() {\n return this.name;\n }\n\n updateFromTheme(theme: EditorTheme) {\n if (theme?.styles?.colors && this.name !== \"custom\") {\n this.value = theme.styles?.colors[this.name];\n }\n }\n}\n\nexport const ADD_FONT_COLOR_COMMAND = createCommand<FontColorPayload>(\"ADD_FONT_COLOR_COMMAND\");\n\nconst FontColorNodeAttrName = \"data-theme-font-color-name\";\n\nexport interface FontColorPayload {\n color: ThemeColorValue;\n}\n\nexport type SerializedFontColorNode = Spread<\n {\n themeColor: string;\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 private readonly __color: ThemeColorValue;\n\n constructor(text: string, color: ThemeColorValue, key?: string) {\n super(text, key);\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.__key);\n }\n\n static override importJSON(serializedNode: SerializedFontColorNode): TextNode {\n const node = new FontColorNode(\n serializedNode.text,\n new ThemeColorValue(serializedNode.color, 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 splitText(...splitOffsets: Array<number>): Array<FontColorNode> {\n const newNodes = super.splitText(...splitOffsets);\n\n const selection = $getSelection();\n\n // After splitting, we need to re-apply styling to the new TextNodes.\n const fontColorNodes = newNodes.map(node => {\n if (node instanceof FontColorNode) {\n return node;\n }\n\n const fontColorNode = $createFontColorNode(node.getTextContent(), this.__color);\n $applyStylesToNode(fontColorNode, this);\n\n const newNode = node.replace(fontColorNode);\n\n // Since we're replacing the existing node, we need to update the selection keys.\n // This is very important to not break the editor functionality!\n if ($isRangeSelection(selection)) {\n const anchor = selection.anchor;\n const focus = selection.focus;\n\n if (anchor.key === node.getKey()) {\n anchor.key = newNode.getKey();\n }\n\n if (focus.key === node.getKey()) {\n focus.key = newNode.getKey();\n }\n }\n\n return newNode;\n });\n\n return fontColorNodes as Array<FontColorNode>;\n }\n\n override exportJSON(): SerializedFontColorNode {\n return {\n ...super.exportJSON(),\n themeColor: this.__color.getName(),\n color: this.__color.getValue(),\n type: \"font-color-node\",\n version: 1\n };\n }\n\n private addColorValueToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n // Update color from webiny theme\n this.__color.updateFromTheme(theme);\n element.setAttribute(FontColorNodeAttrName, this.__color.getName());\n element.style.color = this.__color.getValue();\n return element;\n }\n\n override updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean {\n const isUpdated = super.updateDOM(prevNode, dom, config);\n this.__color.updateFromTheme(config.theme as EditorTheme);\n\n dom.setAttribute(FontColorNodeAttrName, this.__color.getName());\n dom.style.color = this.__color.getValue();\n return isUpdated;\n }\n\n getColorStyle() {\n return {\n color: this.__color.getValue(),\n themeColor: this.__color.getName()\n };\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.addColorValueToHTMLElement(element, config.theme as EditorTheme);\n }\n}\n\nexport const $createFontColorNode = (text: string, color: ThemeColorValue): FontColorNode => {\n return new FontColorNode(text, color);\n};\n\nexport const $isFontColorNode = (node: LexicalNode): node is FontColorNode => {\n return node instanceof FontColorNode;\n};\n\nexport function $applyStylesToNode(node: TextNode, source: TextNode) {\n node.setFormat(source.getFormat());\n node.setStyle(source.getStyle());\n}\n"],"mappings":"AAAA,SACIA,aAAa,EACbC,iBAAiB,EACjBC,aAAa,EAKbC,QAAQ,QACL,SAAS;AAGhB,OAAO,MAAMC,eAAe,CAAC;EACzB;;EAEA;;EAGAC,WAAWA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AU,EAAE,IAAI,CAACR,OAAO,CAACX,OAAO,CAAC;IACrC,CAAC;EACL;EAESwD,SAASA,CAACH,MAAoB,EAAe;IAClD,MAAML,OAAO,GAAG,KAAK,CAACQ,SAAS,CAACH,MAAM,CAAC;IACvC,OAAO,IAAI,CAACN,0BAA0B,CAACC,OAAO,EAAEK,MAAM,CAACnD,KAAoB,CAAC;EAChF;AACJ;AAEA,OAAO,MAAMkC,oBAAoB,GAAGA,CAAC5B,IAAY,EAAEC,KAAsB,KAAoB;EACzF,OAAO,IAAIF,aAAa,CAACC,IAAI,EAAEC,KAAK,CAAC;AACzC,CAAC;AAED,OAAO,MAAMgD,gBAAgB,GAAI3C,IAAiB,IAA4B;EAC1E,OAAOA,IAAI,YAAYP,aAAa;AACxC,CAAC;AAED,OAAO,SAAS+B,kBAAkBA,CAACxB,IAAc,EAAE4C,MAAgB,EAAE;EACjE5C,IAAI,CAACO,SAAS,CAACqC,MAAM,CAACC,SAAS,CAAC,CAAC,CAAC;EAClC7C,IAAI,CAACa,QAAQ,CAAC+B,MAAM,CAACE,QAAQ,CAAC,CAAC,CAAC;AACpC","ignoreList":[]}
|
package/HeadingNode.js
CHANGED
|
@@ -1,165 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
15
|
-
var _superPropGet2 = _interopRequireDefault(require("@babel/runtime/helpers/superPropGet"));
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
-
var _lexical = require("lexical");
|
|
19
|
-
var _utils = require("@lexical/utils");
|
|
20
|
-
var _richText = require("@lexical/rich-text");
|
|
21
|
-
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
22
|
-
var HeadingNode = exports.HeadingNode = /*#__PURE__*/function (_BaseHeadingNode) {
|
|
23
|
-
function HeadingNode(tag, typographyStyleId, key) {
|
|
24
|
-
var _this;
|
|
25
|
-
(0, _classCallCheck2.default)(this, HeadingNode);
|
|
26
|
-
_this = (0, _callSuper2.default)(this, HeadingNode, [tag, key]);
|
|
27
|
-
(0, _defineProperty2.default)(_this, "__styles", []);
|
|
1
|
+
import { $applyNodeReplacement } from "lexical";
|
|
2
|
+
import { addClassNamesToElement } from "@lexical/utils";
|
|
3
|
+
import { HeadingNode as BaseHeadingNode } from "@lexical/rich-text";
|
|
4
|
+
import { findTypographyStyleByHtmlTag } from "@webiny/lexical-theme";
|
|
5
|
+
export class HeadingNode extends BaseHeadingNode {
|
|
6
|
+
__styles = [];
|
|
7
|
+
constructor(tag, typographyStyleId, key) {
|
|
8
|
+
super(tag, key);
|
|
28
9
|
if (typographyStyleId) {
|
|
29
|
-
|
|
10
|
+
this.__styles.push({
|
|
30
11
|
styleId: typographyStyleId,
|
|
31
12
|
type: "typography"
|
|
32
13
|
});
|
|
33
14
|
}
|
|
34
|
-
return _this;
|
|
35
15
|
}
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.__styles.push({
|
|
43
|
-
styleId: typographyStyle.id,
|
|
44
|
-
type: "typography"
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}, {
|
|
49
|
-
key: "getTypographyStyleId",
|
|
50
|
-
value: function getTypographyStyleId() {
|
|
51
|
-
var style = this.__styles.find(function (x) {
|
|
52
|
-
return x.type === "typography";
|
|
16
|
+
setDefaultTypography(themeEmotionMap) {
|
|
17
|
+
const typographyStyle = findTypographyStyleByHtmlTag(this.__tag, themeEmotionMap);
|
|
18
|
+
if (typographyStyle) {
|
|
19
|
+
this.__styles.push({
|
|
20
|
+
styleId: typographyStyle.id,
|
|
21
|
+
type: "typography"
|
|
53
22
|
});
|
|
54
|
-
return style?.styleId || undefined;
|
|
55
23
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
24
|
+
}
|
|
25
|
+
getTypographyStyleId() {
|
|
26
|
+
const style = this.__styles.find(x => x.type === "typography");
|
|
27
|
+
return style?.styleId || undefined;
|
|
28
|
+
}
|
|
29
|
+
hasTypographyStyle() {
|
|
30
|
+
return !!this.getTypographyStyleId();
|
|
31
|
+
}
|
|
32
|
+
getThemeStyles() {
|
|
33
|
+
const self = super.getLatest();
|
|
34
|
+
return self.__styles;
|
|
35
|
+
}
|
|
36
|
+
setThemeStyles(styles) {
|
|
37
|
+
const self = super.getWritable();
|
|
38
|
+
self.__styles = [...styles];
|
|
39
|
+
return self;
|
|
40
|
+
}
|
|
41
|
+
static getType() {
|
|
42
|
+
return "heading-element";
|
|
43
|
+
}
|
|
44
|
+
static clone(node) {
|
|
45
|
+
return new HeadingNode(node.getTag(), node.getTypographyStyleId(), node.__key);
|
|
46
|
+
}
|
|
47
|
+
updateElementWithThemeClasses(element, theme) {
|
|
48
|
+
if (!theme?.emotionMap) {
|
|
49
|
+
return element;
|
|
66
50
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
value: function setThemeStyles(styles) {
|
|
70
|
-
var self = (0, _superPropGet2.default)(HeadingNode, "getWritable", this, 3)([]);
|
|
71
|
-
self.__styles = (0, _toConsumableArray2.default)(styles);
|
|
72
|
-
return self;
|
|
51
|
+
if (!this.hasTypographyStyle()) {
|
|
52
|
+
this.setDefaultTypography(theme.emotionMap);
|
|
73
53
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
value: function updateElementWithThemeClasses(element, theme) {
|
|
77
|
-
if (!theme?.emotionMap) {
|
|
78
|
-
return element;
|
|
79
|
-
}
|
|
80
|
-
if (!this.hasTypographyStyle()) {
|
|
81
|
-
this.setDefaultTypography(theme.emotionMap);
|
|
82
|
-
}
|
|
83
|
-
var typoStyleId = this.getTypographyStyleId();
|
|
84
|
-
var themeClasses;
|
|
54
|
+
const typoStyleId = this.getTypographyStyleId();
|
|
55
|
+
let themeClasses;
|
|
85
56
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (themeClasses) {
|
|
94
|
-
(0, _utils.addClassNamesToElement)(element, themeClasses);
|
|
57
|
+
// Typography css class
|
|
58
|
+
if (typoStyleId) {
|
|
59
|
+
const typographyStyle = theme.emotionMap[typoStyleId];
|
|
60
|
+
if (typographyStyle) {
|
|
61
|
+
themeClasses = typographyStyle.className;
|
|
95
62
|
}
|
|
96
|
-
return element;
|
|
97
63
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
value: function createDOM(config) {
|
|
101
|
-
var element = (0, _superPropGet2.default)(HeadingNode, "createDOM", this, 3)([config]);
|
|
102
|
-
return this.updateElementWithThemeClasses(element, config.theme);
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
key: "exportJSON",
|
|
106
|
-
value: function exportJSON() {
|
|
107
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _superPropGet2.default)(HeadingNode, "exportJSON", this, 3)([])), {}, {
|
|
108
|
-
styles: this.__styles,
|
|
109
|
-
type: "heading-element",
|
|
110
|
-
version: 1
|
|
111
|
-
});
|
|
64
|
+
if (themeClasses) {
|
|
65
|
+
addClassNamesToElement(element, themeClasses);
|
|
112
66
|
}
|
|
67
|
+
return element;
|
|
68
|
+
}
|
|
69
|
+
createDOM(config) {
|
|
70
|
+
const element = super.createDOM(config);
|
|
71
|
+
return this.updateElementWithThemeClasses(element, config.theme);
|
|
72
|
+
}
|
|
73
|
+
static importJSON(serializedNode) {
|
|
74
|
+
const node = $createHeadingNode(serializedNode.tag);
|
|
75
|
+
node.setFormat(serializedNode.format);
|
|
76
|
+
node.setIndent(serializedNode.indent);
|
|
77
|
+
node.setDirection(serializedNode.direction);
|
|
78
|
+
node.setThemeStyles(serializedNode.styles);
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
exportJSON() {
|
|
82
|
+
return {
|
|
83
|
+
...super.exportJSON(),
|
|
84
|
+
styles: this.__styles,
|
|
85
|
+
type: "heading-element",
|
|
86
|
+
version: 1
|
|
87
|
+
};
|
|
88
|
+
}
|
|
113
89
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
this.replace(newElement);
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
}], [{
|
|
138
|
-
key: "getType",
|
|
139
|
-
value: function getType() {
|
|
140
|
-
return "heading-element";
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "clone",
|
|
144
|
-
value: function clone(node) {
|
|
145
|
-
return new HeadingNode(node.getTag(), node.getTypographyStyleId(), node.__key);
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
key: "importJSON",
|
|
149
|
-
value: function importJSON(serializedNode) {
|
|
150
|
-
var node = $createHeadingNode(serializedNode.tag);
|
|
151
|
-
node.setFormat(serializedNode.format);
|
|
152
|
-
node.setIndent(serializedNode.indent);
|
|
153
|
-
node.setDirection(serializedNode.direction);
|
|
154
|
-
node.setThemeStyles(serializedNode.styles);
|
|
155
|
-
return node;
|
|
156
|
-
}
|
|
157
|
-
}]);
|
|
158
|
-
}(_richText.HeadingNode);
|
|
159
|
-
function $createHeadingNode(tag, typographyStyleId) {
|
|
160
|
-
return (0, _lexical.$applyNodeReplacement)(new HeadingNode(tag, typographyStyleId));
|
|
90
|
+
// Mutation
|
|
91
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
92
|
+
// Next line for headings are always headings with the same tag
|
|
93
|
+
const newElement = $createHeadingNode(this.getTag());
|
|
94
|
+
const direction = this.getDirection();
|
|
95
|
+
newElement.setDirection(direction);
|
|
96
|
+
this.insertAfter(newElement, restoreSelection);
|
|
97
|
+
return newElement;
|
|
98
|
+
}
|
|
99
|
+
collapseAtStart() {
|
|
100
|
+
const newElement = $createHeadingNode(this.getTag());
|
|
101
|
+
const children = this.getChildren();
|
|
102
|
+
children.forEach(child => newElement.append(child));
|
|
103
|
+
this.replace(newElement);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function $createHeadingNode(tag, typographyStyleId) {
|
|
108
|
+
return $applyNodeReplacement(new HeadingNode(tag, typographyStyleId));
|
|
161
109
|
}
|
|
162
|
-
function $isHeadingNode(node) {
|
|
110
|
+
export function $isHeadingNode(node) {
|
|
163
111
|
return node instanceof HeadingNode;
|
|
164
112
|
}
|
|
165
113
|
|
package/HeadingNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lexical","require","_utils","_richText","_lexicalTheme","HeadingNode","exports","_BaseHeadingNode","tag","typographyStyleId","key","_this","_classCallCheck2","default","_callSuper2","_defineProperty2","__styles","push","styleId","type","_inherits2","_createClass2","value","setDefaultTypography","themeEmotionMap","typographyStyle","findTypographyStyleByHtmlTag","__tag","id","getTypographyStyleId","style","find","x","undefined","hasTypographyStyle","getThemeStyles","self","_superPropGet2","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","$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 { EditorTheme, 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 private 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 getTypographyStyleId(): string | undefined {\n const style = this.__styles.find(x => x.type === \"typography\");\n return style?.styleId || undefined;\n }\n\n private 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: EditorTheme): 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 EditorTheme);\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,GAAAC,OAAA,CAAAD,WAAA,0BAAAE,gBAAA;EAMpB,SAAAF,YAAYG,GAAmB,EAAEC,iBAA0B,EAAEC,GAAa,EAAE;IAAA,IAAAC,KAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAR,WAAA;IACxEM,KAAA,OAAAG,WAAA,CAAAD,OAAA,QAAAR,WAAA,GAAMG,GAAG,EAAEE,GAAG;IAAE,IAAAK,gBAAA,CAAAF,OAAA,EAAAF,KAAA,cAHU,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,UAAA,CAAAP,OAAA,EAAAR,WAAA,EAAAE,gBAAA;EAAA,WAAAc,aAAA,CAAAR,OAAA,EAAAR,WAAA;IAAAK,GAAA;IAAAY,KAAA,EAED,SAAQC,oBAAoBA,CAACC,eAAgC,EAAE;MAC3D,IAAMC,eAAe,GAAG,IAAAC,0CAA4B,EAAC,IAAI,CAACC,KAAK,EAAEH,eAAe,CAAC;MACjF,IAAIC,eAAe,EAAE;QACjB,IAAI,CAACT,QAAQ,CA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B,EAAe;EAC7F,OAAO,IAAA2E,8BAAqB,EAAC,IAAI/E,WAAW,CAACG,GAAG,EAAEC,iBAAiB,CAAC,CAAC;AACzE;AAEO,SAAS4E,cAAcA,CAACV,IAAoC,EAAuB;EACtF,OAAOA,IAAI,YAAYtE,WAAW;AACtC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["$applyNodeReplacement","addClassNamesToElement","HeadingNode","BaseHeadingNode","findTypographyStyleByHtmlTag","__styles","constructor","tag","typographyStyleId","key","push","styleId","type","setDefaultTypography","themeEmotionMap","typographyStyle","__tag","id","getTypographyStyleId","style","find","x","undefined","hasTypographyStyle","getThemeStyles","self","getLatest","setThemeStyles","styles","getWritable","getType","clone","node","getTag","__key","updateElementWithThemeClasses","element","theme","emotionMap","typoStyleId","themeClasses","className","createDOM","config","importJSON","serializedNode","$createHeadingNode","setFormat","format","setIndent","indent","setDirection","direction","exportJSON","version","insertNewAfter","selection","restoreSelection","newElement","getDirection","insertAfter","collapseAtStart","children","getChildren","forEach","child","append","replace","$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 { EditorTheme, 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 private 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 getTypographyStyleId(): string | undefined {\n const style = this.__styles.find(x => x.type === \"typography\");\n return style?.styleId || undefined;\n }\n\n private 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: EditorTheme): 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 EditorTheme);\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,SAEIA,qBAAqB,QAKlB,SAAS;AAChB,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,SACIC,WAAW,IAAIC,eAAe,QAG3B,oBAAoB;AAC3B,SAAuCC,4BAA4B,QAAQ,uBAAuB;AAYlG,OAAO,MAAMF,WAAW,SACZC,eAAe,CAE3B;EACIE,QAAQ,GAAsB,EAAE;EAEhCC,WAAWA,CAACC,GAAmB,EAAEC,iBAA0B,EAAEC,GAAa,EAAE;IACxE,KAAK,CAACF,GAAG,EAAEE,GAAG,CAAC;IAEf,IAAID,iBAAiB,EAAE;MACnB,IAAI,CAACH,QAAQ,CAACK,IAAI,CAAC;QAAEC,OAAO,EAAEH,iBAAiB;QAAEI,IAAI,EAAE;MAAa,CAAC,CAAC;IAC1E;EACJ;EAEQC,oBAAoBA,CAACC,eAAgC,EAAE;IAC3D,MAAMC,eAAe,GAAGX,4BAA4B,CAAC,IAAI,CAACY,KAAK,EAAEF,eAAe,CAAC;IACjF,IAAIC,eAAe,EAAE;MACjB,IAAI,CAACV,QAAQ,CAACK,IAAI,CAAC;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