@webiny/lexical-nodes 6.3.0-beta.4 → 6.4.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.
- package/FontColorNode.js +94 -119
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +160 -183
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +101 -131
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +228 -315
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +249 -320
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +174 -223
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +119 -148
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +97 -102
- package/QuoteNode.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +117 -147
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +167 -194
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.js +20 -23
- package/generateInitialLexicalValue.js.map +1 -1
- package/index.js +38 -26
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/prepareLexicalState.js +30 -43
- package/prepareLexicalState.js.map +1 -1
- package/types.js +0 -3
- package/utils/clearNodeFormating.js +14 -15
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +277 -368
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +6 -13
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +6 -7
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +6 -13
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.js +6 -11
- package/utils/getStyleId.js.map +1 -1
- package/utils/listNode.js +60 -84
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +67 -118
- package/utils/toggleLink.js.map +1 -1
- package/types.js.map +0 -1
package/FontColorNode.js
CHANGED
|
@@ -1,128 +1,103 @@
|
|
|
1
|
-
import { $getSelection, $isRangeSelection,
|
|
1
|
+
import { $getSelection, $isRangeSelection, TextNode, createCommand } from "lexical";
|
|
2
2
|
import { Theme } from "@webiny/lexical-theme";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (theme.colors && this.id !== "custom") {
|
|
20
|
-
const color = theme.colors.find(color => color.id === this.id);
|
|
21
|
-
if (color) {
|
|
22
|
-
this.value = color.value;
|
|
23
|
-
}
|
|
3
|
+
class ThemeColorValue {
|
|
4
|
+
constructor(value, name){
|
|
5
|
+
this.value = value;
|
|
6
|
+
this.id = name ?? "custom";
|
|
7
|
+
}
|
|
8
|
+
getValue() {
|
|
9
|
+
return this.value;
|
|
10
|
+
}
|
|
11
|
+
getName() {
|
|
12
|
+
return this.id;
|
|
13
|
+
}
|
|
14
|
+
updateFromTheme(theme) {
|
|
15
|
+
if (theme.colors && "custom" !== this.id) {
|
|
16
|
+
const color = theme.colors.find((color)=>color.id === this.id);
|
|
17
|
+
if (color) this.value = color.value;
|
|
18
|
+
}
|
|
24
19
|
}
|
|
25
|
-
}
|
|
26
20
|
}
|
|
27
|
-
|
|
21
|
+
const ADD_FONT_COLOR_COMMAND = createCommand("ADD_FONT_COLOR_COMMAND");
|
|
28
22
|
const FontColorNodeAttrName = "data-theme-font-color-name";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
node.setFormat(serializedNode.format);
|
|
48
|
-
node.setDetail(serializedNode.detail);
|
|
49
|
-
node.setMode(serializedNode.mode);
|
|
50
|
-
node.setStyle(serializedNode.style);
|
|
51
|
-
return node;
|
|
52
|
-
}
|
|
53
|
-
splitText(...splitOffsets) {
|
|
54
|
-
const newNodes = super.splitText(...splitOffsets);
|
|
55
|
-
const selection = $getSelection();
|
|
56
|
-
|
|
57
|
-
// After splitting, we need to re-apply styling to the new TextNodes.
|
|
58
|
-
const fontColorNodes = newNodes.map(node => {
|
|
59
|
-
if (node instanceof FontColorNode) {
|
|
23
|
+
class FontColorNode extends TextNode {
|
|
24
|
+
constructor(text, color, key){
|
|
25
|
+
super(text, key);
|
|
26
|
+
this.__color = color;
|
|
27
|
+
}
|
|
28
|
+
static getType() {
|
|
29
|
+
return "wby-font-color";
|
|
30
|
+
}
|
|
31
|
+
static clone(node) {
|
|
32
|
+
return new FontColorNode(node.__text, node.__color, node.__key);
|
|
33
|
+
}
|
|
34
|
+
static importJSON(serializedNode) {
|
|
35
|
+
const node = new FontColorNode(serializedNode.text, new ThemeColorValue(serializedNode.color, serializedNode.themeColor));
|
|
36
|
+
node.setTextContent(serializedNode.text);
|
|
37
|
+
node.setFormat(serializedNode.format);
|
|
38
|
+
node.setDetail(serializedNode.detail);
|
|
39
|
+
node.setMode(serializedNode.mode);
|
|
40
|
+
node.setStyle(serializedNode.style);
|
|
60
41
|
return node;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const theme = Theme.from(config.theme);
|
|
114
|
-
return this.addColorValueToHTMLElement(element, theme);
|
|
115
|
-
}
|
|
42
|
+
}
|
|
43
|
+
splitText(...splitOffsets) {
|
|
44
|
+
const newNodes = super.splitText(...splitOffsets);
|
|
45
|
+
const selection = $getSelection();
|
|
46
|
+
const fontColorNodes = newNodes.map((node)=>{
|
|
47
|
+
if (node instanceof FontColorNode) return node;
|
|
48
|
+
const fontColorNode = $createFontColorNode(node.getTextContent(), this.__color);
|
|
49
|
+
$applyStylesToNode(fontColorNode, this);
|
|
50
|
+
const newNode = node.replace(fontColorNode);
|
|
51
|
+
if ($isRangeSelection(selection)) {
|
|
52
|
+
const anchor = selection.anchor;
|
|
53
|
+
const focus = selection.focus;
|
|
54
|
+
if (anchor.key === node.getKey()) anchor.key = newNode.getKey();
|
|
55
|
+
if (focus.key === node.getKey()) focus.key = newNode.getKey();
|
|
56
|
+
}
|
|
57
|
+
return newNode;
|
|
58
|
+
});
|
|
59
|
+
return fontColorNodes;
|
|
60
|
+
}
|
|
61
|
+
exportJSON() {
|
|
62
|
+
return {
|
|
63
|
+
...super.exportJSON(),
|
|
64
|
+
themeColor: this.__color.getName(),
|
|
65
|
+
color: this.__color.getValue(),
|
|
66
|
+
type: "wby-font-color"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
addColorValueToHTMLElement(element, theme) {
|
|
70
|
+
this.__color.updateFromTheme(theme);
|
|
71
|
+
element.setAttribute(FontColorNodeAttrName, this.__color.getName());
|
|
72
|
+
element.style.color = this.__color.getValue();
|
|
73
|
+
return element;
|
|
74
|
+
}
|
|
75
|
+
updateDOM(prevNode, dom, config) {
|
|
76
|
+
const isUpdated = super.updateDOM(prevNode, dom, config);
|
|
77
|
+
const theme = Theme.from(config.theme);
|
|
78
|
+
this.__color.updateFromTheme(theme);
|
|
79
|
+
dom.setAttribute(FontColorNodeAttrName, this.__color.getName());
|
|
80
|
+
dom.style.color = this.__color.getValue();
|
|
81
|
+
return isUpdated;
|
|
82
|
+
}
|
|
83
|
+
getColorStyle() {
|
|
84
|
+
return {
|
|
85
|
+
color: this.__color.getValue(),
|
|
86
|
+
themeColor: this.__color.getName()
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
createDOM(config) {
|
|
90
|
+
const element = super.createDOM(config);
|
|
91
|
+
const theme = Theme.from(config.theme);
|
|
92
|
+
return this.addColorValueToHTMLElement(element, theme);
|
|
93
|
+
}
|
|
116
94
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
123
|
-
export function $applyStylesToNode(node, source) {
|
|
124
|
-
node.setFormat(source.getFormat());
|
|
125
|
-
node.setStyle(source.getStyle());
|
|
95
|
+
const $createFontColorNode = (text, color)=>new FontColorNode(text, color);
|
|
96
|
+
const $isFontColorNode = (node)=>node instanceof FontColorNode;
|
|
97
|
+
function $applyStylesToNode(node, source) {
|
|
98
|
+
node.setFormat(source.getFormat());
|
|
99
|
+
node.setStyle(source.getStyle());
|
|
126
100
|
}
|
|
101
|
+
export { $applyStylesToNode, $createFontColorNode, $isFontColorNode, ADD_FONT_COLOR_COMMAND, FontColorNode, ThemeColorValue };
|
|
127
102
|
|
|
128
103
|
//# sourceMappingURL=FontColorNode.js.map
|
package/FontColorNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["$getSelection","$isRangeSelection","createCommand","TextNode","Theme","ThemeColorValue","constructor","value","name","id","getValue","getName","updateFromTheme","theme","colors","color","find","ADD_FONT_COLOR_COMMAND","FontColorNodeAttrName","FontColorNode","text","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","addColorValueToHTMLElement","element","setAttribute","updateDOM","prevNode","dom","config","isUpdated","from","getColorStyle","createDOM","$isFontColorNode","source","getFormat","getStyle"],"sources":["FontColorNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, SerializedTextNode, Spread } from \"lexical\";\nimport { $getSelection, $isRangeSelection, createCommand, TextNode } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\n\nexport class ThemeColorValue {\n // Webiny theme color variable, like color1, color2, etc.\n private readonly id: 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.id = name ?? \"custom\";\n }\n\n getValue() {\n return this.value;\n }\n\n getName() {\n return this.id;\n }\n\n updateFromTheme(theme: Theme) {\n if (theme.colors && this.id !== \"custom\") {\n const color = theme.colors.find(color => color.id === this.id);\n if (color) {\n this.value = color.value;\n }\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: \"wby-font-color\";\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 \"wby-font-color\";\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: \"wby-font-color\"\n };\n }\n\n private addColorValueToHTMLElement(element: HTMLElement, theme: Theme): 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 const theme = Theme.from(config.theme);\n this.__color.updateFromTheme(theme);\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 const theme = Theme.from(config.theme);\n return this.addColorValueToHTMLElement(element, theme);\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":"AACA,SAASA,aAAa,EAAEC,iBAAiB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,SAAS;AACnF,SAASC,KAAK,QAAQ,uBAAuB;AAE7C,OAAO,MAAMC,eAAe,CAAC;EACzB;;EAEA;;EAGAC,WAAWA,CAACC,KAAa,EAAEC,IAAa,EAAE;IACtC,IAAI,CAACD,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,EAAE,GAAGD,IAAI,IAAI,QAAQ;EAC9B;EAEAE,QAAQA,CAAA,EAAG;IACP,OAAO,IAAI,CAACH,KAAK;EACrB;EAEAI,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACF,EAAE;EAClB;EAEAG,eAAeA,CAACC,KAAY,EAAE;IAC1B,IAAIA,KAAK,CAACC,MAAM,IAAI,IAAI,CAACL,EAAE,KAAK,QAAQ,EAAE;MACtC,MAAMM,KAAK,GAAGF,KAAK,CAACC,MAAM,CAACE,IAAI,CAACD,KAAK,IAAIA,KAAK,CAACN,EAAE,KAAK,IAAI,CAACA,EAAE,CAAC;MAC9D,IAAIM,KAAK,EAAE;QACP,IAAI,CAACR,KAAK,GAAGQ,KAAK,CAACR,KAAK;MAC5B;IACJ;EACJ;AACJ;AAEA,OAAO,MAAMU,sBAAsB,GAAGf,aAAa,CAAmB,wBAAwB,CAAC;AAE/F,MAAMgB,qBAAqB,G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AAa;AACxC,CAAC;AAED,OAAO,SAAS8B,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":[]}
|
|
1
|
+
{"version":3,"file":"FontColorNode.js","sources":["../src/FontColorNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, SerializedTextNode, Spread } from \"lexical\";\nimport { $getSelection, $isRangeSelection, createCommand, TextNode } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\n\nexport class ThemeColorValue {\n // Webiny theme color variable, like color1, color2, etc.\n private readonly id: 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.id = name ?? \"custom\";\n }\n\n getValue() {\n return this.value;\n }\n\n getName() {\n return this.id;\n }\n\n updateFromTheme(theme: Theme) {\n if (theme.colors && this.id !== \"custom\") {\n const color = theme.colors.find(color => color.id === this.id);\n if (color) {\n this.value = color.value;\n }\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: \"wby-font-color\";\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 \"wby-font-color\";\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: \"wby-font-color\"\n };\n }\n\n private addColorValueToHTMLElement(element: HTMLElement, theme: Theme): 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 const theme = Theme.from(config.theme);\n this.__color.updateFromTheme(theme);\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 const theme = Theme.from(config.theme);\n return this.addColorValueToHTMLElement(element, theme);\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"],"names":["ThemeColorValue","value","name","theme","color","ADD_FONT_COLOR_COMMAND","createCommand","FontColorNodeAttrName","FontColorNode","TextNode","text","key","node","serializedNode","splitOffsets","newNodes","selection","$getSelection","fontColorNodes","fontColorNode","$createFontColorNode","$applyStylesToNode","newNode","$isRangeSelection","anchor","focus","element","prevNode","dom","config","isUpdated","Theme","$isFontColorNode","source"],"mappings":";;AAIO,MAAMA;IAMT,YAAYC,KAAa,EAAEC,IAAa,CAAE;QACtC,IAAI,CAAC,KAAK,GAAGD;QACb,IAAI,CAAC,EAAE,GAAGC,QAAQ;IACtB;IAEA,WAAW;QACP,OAAO,IAAI,CAAC,KAAK;IACrB;IAEA,UAAU;QACN,OAAO,IAAI,CAAC,EAAE;IAClB;IAEA,gBAAgBC,KAAY,EAAE;QAC1B,IAAIA,MAAM,MAAM,IAAI,AAAY,aAAZ,IAAI,CAAC,EAAE,EAAe;YACtC,MAAMC,QAAQD,MAAM,MAAM,CAAC,IAAI,CAACC,CAAAA,QAASA,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE;YAC7D,IAAIA,OACA,IAAI,CAAC,KAAK,GAAGA,MAAM,KAAK;QAEhC;IACJ;AACJ;AAEO,MAAMC,yBAAyBC,cAAgC;AAEtE,MAAMC,wBAAwB;AAmBvB,MAAMC,sBAAsBC;IAG/B,YAAYC,IAAY,EAAEN,KAAsB,EAAEO,GAAY,C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O,SAAS;IAC/BrB,KAAK,QAAQ,CAACqB,OAAO,QAAQ;AACjC"}
|
package/HeadingNode.js
CHANGED
|
@@ -1,198 +1,175 @@
|
|
|
1
|
-
import { $applyNodeReplacement,
|
|
2
|
-
import { HeadingNode
|
|
1
|
+
import { $applyNodeReplacement, addClassNamesToElement, setNodeIndentFromDOM } from "lexical";
|
|
2
|
+
import { HeadingNode } from "@lexical/rich-text";
|
|
3
3
|
import { Theme } from "@webiny/lexical-theme";
|
|
4
4
|
import { getStyleId } from "./utils/getStyleId.js";
|
|
5
5
|
function isGoogleDocsTitle(domNode) {
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
}
|
|
9
|
-
return false;
|
|
6
|
+
if ("span" === domNode.nodeName.toLowerCase()) return "26pt" === domNode.style.fontSize;
|
|
7
|
+
return false;
|
|
10
8
|
}
|
|
11
9
|
function $convertHeadingElement(element) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
node
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export class HeadingNode extends BaseHeadingNode {
|
|
26
|
-
constructor(tag, options = {}) {
|
|
27
|
-
const {
|
|
28
|
-
styleId,
|
|
29
|
-
key,
|
|
30
|
-
className
|
|
31
|
-
} = options;
|
|
32
|
-
super(tag, key);
|
|
33
|
-
this.__styleId = styleId;
|
|
34
|
-
this.__className = className;
|
|
35
|
-
}
|
|
36
|
-
getStyleId() {
|
|
37
|
-
return this.__styleId;
|
|
38
|
-
}
|
|
39
|
-
setStyleId(styleId) {
|
|
40
|
-
this.__styleId = styleId;
|
|
41
|
-
}
|
|
42
|
-
setClassName(className) {
|
|
43
|
-
this.__className = className;
|
|
44
|
-
}
|
|
45
|
-
getClassName() {
|
|
46
|
-
return this.__className;
|
|
47
|
-
}
|
|
48
|
-
static getType() {
|
|
49
|
-
return "wby-heading";
|
|
50
|
-
}
|
|
51
|
-
static clone(node) {
|
|
52
|
-
return new HeadingNode(node.getTag(), {
|
|
53
|
-
key: node.getKey(),
|
|
54
|
-
styleId: node.getStyleId(),
|
|
55
|
-
className: node.getClassName()
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
createDOM(config) {
|
|
59
|
-
const element = super.createDOM(config);
|
|
60
|
-
const theme = Theme.from(config.theme);
|
|
61
|
-
return this.updateElementWithThemeClasses(element, theme);
|
|
62
|
-
}
|
|
63
|
-
exportDOM(editor) {
|
|
64
|
-
const base = super.exportDOM(editor);
|
|
65
|
-
const element = base.element;
|
|
66
|
-
if (element && this.__className) {
|
|
67
|
-
element.classList.add(this.__className);
|
|
10
|
+
const nodeName = element.nodeName.toLowerCase();
|
|
11
|
+
let node = null;
|
|
12
|
+
if ("h1" === nodeName || "h2" === nodeName || "h3" === nodeName || "h4" === nodeName || "h5" === nodeName || "h6" === nodeName) {
|
|
13
|
+
node = $createHeadingNode(nodeName);
|
|
14
|
+
if (null !== element.style) {
|
|
15
|
+
setNodeIndentFromDOM(element, node);
|
|
16
|
+
node.setFormat(element.style.textAlign);
|
|
17
|
+
}
|
|
68
18
|
}
|
|
69
19
|
return {
|
|
70
|
-
|
|
71
|
-
element
|
|
20
|
+
node
|
|
72
21
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
22
|
+
}
|
|
23
|
+
class HeadingNode_HeadingNode extends HeadingNode {
|
|
24
|
+
constructor(tag, options = {}){
|
|
25
|
+
const { styleId, key, className } = options;
|
|
26
|
+
super(tag, key);
|
|
27
|
+
this.__styleId = styleId;
|
|
28
|
+
this.__className = className;
|
|
29
|
+
}
|
|
30
|
+
getStyleId() {
|
|
31
|
+
return this.__styleId;
|
|
32
|
+
}
|
|
33
|
+
setStyleId(styleId) {
|
|
34
|
+
this.__styleId = styleId;
|
|
35
|
+
}
|
|
36
|
+
setClassName(className) {
|
|
37
|
+
this.__className = className;
|
|
38
|
+
}
|
|
39
|
+
getClassName() {
|
|
40
|
+
return this.__className;
|
|
41
|
+
}
|
|
42
|
+
static getType() {
|
|
43
|
+
return "wby-heading";
|
|
44
|
+
}
|
|
45
|
+
static clone(node) {
|
|
46
|
+
return new HeadingNode_HeadingNode(node.getTag(), {
|
|
47
|
+
key: node.getKey(),
|
|
48
|
+
styleId: node.getStyleId(),
|
|
49
|
+
className: node.getClassName()
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
createDOM(config) {
|
|
53
|
+
const element = super.createDOM(config);
|
|
54
|
+
const theme = Theme.from(config.theme);
|
|
55
|
+
return this.updateElementWithThemeClasses(element, theme);
|
|
56
|
+
}
|
|
57
|
+
exportDOM(editor) {
|
|
58
|
+
const base = super.exportDOM(editor);
|
|
59
|
+
const element = base.element;
|
|
60
|
+
if (element && this.__className) element.classList.add(this.__className);
|
|
61
|
+
return {
|
|
62
|
+
...base,
|
|
63
|
+
element
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
static importDOM() {
|
|
67
|
+
return {
|
|
68
|
+
h1: ()=>({
|
|
69
|
+
conversion: $convertHeadingElement,
|
|
70
|
+
priority: 0
|
|
71
|
+
}),
|
|
72
|
+
h2: ()=>({
|
|
73
|
+
conversion: $convertHeadingElement,
|
|
74
|
+
priority: 0
|
|
75
|
+
}),
|
|
76
|
+
h3: ()=>({
|
|
77
|
+
conversion: $convertHeadingElement,
|
|
78
|
+
priority: 0
|
|
79
|
+
}),
|
|
80
|
+
h4: ()=>({
|
|
81
|
+
conversion: $convertHeadingElement,
|
|
82
|
+
priority: 0
|
|
83
|
+
}),
|
|
84
|
+
h5: ()=>({
|
|
85
|
+
conversion: $convertHeadingElement,
|
|
86
|
+
priority: 0
|
|
87
|
+
}),
|
|
88
|
+
h6: ()=>({
|
|
89
|
+
conversion: $convertHeadingElement,
|
|
90
|
+
priority: 0
|
|
91
|
+
}),
|
|
92
|
+
p: (node)=>{
|
|
93
|
+
const firstChild = node.firstChild;
|
|
94
|
+
if (null !== firstChild && isGoogleDocsTitle(firstChild)) return {
|
|
95
|
+
conversion: ()=>({
|
|
96
|
+
node: null
|
|
97
|
+
}),
|
|
98
|
+
priority: 3
|
|
99
|
+
};
|
|
100
|
+
return null;
|
|
120
101
|
},
|
|
121
|
-
|
|
122
|
-
|
|
102
|
+
span: (node)=>{
|
|
103
|
+
if (isGoogleDocsTitle(node)) return {
|
|
104
|
+
conversion: ()=>({
|
|
105
|
+
node: $createHeadingNode("h1")
|
|
106
|
+
}),
|
|
107
|
+
priority: 3
|
|
108
|
+
};
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
static importJSON(serializedNode) {
|
|
114
|
+
const node = $createHeadingNode(serializedNode.tag);
|
|
115
|
+
node.setFormat(serializedNode.format);
|
|
116
|
+
node.setIndent(serializedNode.indent);
|
|
117
|
+
node.setDirection(serializedNode.direction);
|
|
118
|
+
const styleId = getStyleId({
|
|
119
|
+
styleId: serializedNode.styleId,
|
|
120
|
+
styles: serializedNode.styles
|
|
121
|
+
});
|
|
122
|
+
node.setStyleId(styleId);
|
|
123
|
+
node.setClassName(serializedNode.className);
|
|
124
|
+
return node;
|
|
125
|
+
}
|
|
126
|
+
exportJSON() {
|
|
127
|
+
return {
|
|
128
|
+
...super.exportJSON(),
|
|
129
|
+
type: "wby-heading",
|
|
130
|
+
styleId: this.__styleId,
|
|
131
|
+
className: this.__className
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
135
|
+
const newElement = $createHeadingNode(this.getTag());
|
|
136
|
+
const direction = this.getDirection();
|
|
137
|
+
newElement.setDirection(direction);
|
|
138
|
+
this.insertAfter(newElement, restoreSelection);
|
|
139
|
+
return newElement;
|
|
140
|
+
}
|
|
141
|
+
collapseAtStart() {
|
|
142
|
+
const newElement = $createHeadingNode(this.getTag());
|
|
143
|
+
const children = this.getChildren();
|
|
144
|
+
children.forEach((child)=>newElement.append(child));
|
|
145
|
+
this.replace(newElement);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
updateElementWithThemeClasses(element, theme) {
|
|
149
|
+
if (!this.__styleId || !this.__className) this.setDefaultTypography(theme, this.__styleId);
|
|
150
|
+
if (this.__className) addClassNamesToElement(element, this.__className);
|
|
151
|
+
return element;
|
|
152
|
+
}
|
|
153
|
+
setDefaultTypography(theme, styleId) {
|
|
154
|
+
let typographyStyle = theme.getTypographyByTag(this.getTag());
|
|
155
|
+
if (styleId) {
|
|
156
|
+
const byStyleId = theme.getTypographyById(styleId);
|
|
157
|
+
if (byStyleId) typographyStyle = byStyleId;
|
|
123
158
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const node = $createHeadingNode(serializedNode.tag);
|
|
130
|
-
node.setFormat(serializedNode.format);
|
|
131
|
-
node.setIndent(serializedNode.indent);
|
|
132
|
-
node.setDirection(serializedNode.direction);
|
|
133
|
-
const styleId = getStyleId({
|
|
134
|
-
styleId: serializedNode.styleId,
|
|
135
|
-
styles: serializedNode.styles
|
|
136
|
-
});
|
|
137
|
-
node.setStyleId(styleId);
|
|
138
|
-
node.setClassName(serializedNode.className);
|
|
139
|
-
return node;
|
|
140
|
-
}
|
|
141
|
-
exportJSON() {
|
|
142
|
-
return {
|
|
143
|
-
...super.exportJSON(),
|
|
144
|
-
type: "wby-heading",
|
|
145
|
-
styleId: this.__styleId,
|
|
146
|
-
className: this.__className
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Mutation
|
|
151
|
-
insertNewAfter(selection, restoreSelection = true) {
|
|
152
|
-
// Next line for headings are always headings with the same tag
|
|
153
|
-
const newElement = $createHeadingNode(this.getTag());
|
|
154
|
-
const direction = this.getDirection();
|
|
155
|
-
newElement.setDirection(direction);
|
|
156
|
-
this.insertAfter(newElement, restoreSelection);
|
|
157
|
-
return newElement;
|
|
158
|
-
}
|
|
159
|
-
collapseAtStart() {
|
|
160
|
-
const newElement = $createHeadingNode(this.getTag());
|
|
161
|
-
const children = this.getChildren();
|
|
162
|
-
children.forEach(child => newElement.append(child));
|
|
163
|
-
this.replace(newElement);
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
updateElementWithThemeClasses(element, theme) {
|
|
167
|
-
if (!this.__styleId || !this.__className) {
|
|
168
|
-
this.setDefaultTypography(theme, this.__styleId);
|
|
169
|
-
}
|
|
170
|
-
if (this.__className) {
|
|
171
|
-
addClassNamesToElement(element, this.__className);
|
|
172
|
-
}
|
|
173
|
-
return element;
|
|
174
|
-
}
|
|
175
|
-
setDefaultTypography(theme, styleId) {
|
|
176
|
-
let typographyStyle = theme.getTypographyByTag(this.getTag());
|
|
177
|
-
if (styleId) {
|
|
178
|
-
const byStyleId = theme.getTypographyById(styleId);
|
|
179
|
-
if (byStyleId) {
|
|
180
|
-
typographyStyle = byStyleId;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (typographyStyle) {
|
|
184
|
-
this.__styleId = typographyStyle.id;
|
|
185
|
-
this.__className = typographyStyle.className;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
159
|
+
if (typographyStyle) {
|
|
160
|
+
this.__styleId = typographyStyle.id;
|
|
161
|
+
this.__className = typographyStyle.className;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
188
164
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
165
|
+
function $createHeadingNode(tag, styleId) {
|
|
166
|
+
return $applyNodeReplacement(new HeadingNode_HeadingNode(tag, {
|
|
167
|
+
styleId
|
|
168
|
+
}));
|
|
193
169
|
}
|
|
194
|
-
|
|
195
|
-
|
|
170
|
+
function $isHeadingNode(node) {
|
|
171
|
+
return node instanceof HeadingNode_HeadingNode;
|
|
196
172
|
}
|
|
173
|
+
export { $createHeadingNode, $isHeadingNode, HeadingNode_HeadingNode as HeadingNode };
|
|
197
174
|
|
|
198
175
|
//# sourceMappingURL=HeadingNode.js.map
|