@webiny/lexical-nodes 5.43.2-beta.0 → 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/QuoteNode.js
CHANGED
|
@@ -1,201 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.QuoteNode = 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 _lexicalTheme = require("@webiny/lexical-theme");
|
|
19
|
-
var _utils = require("@lexical/utils");
|
|
20
|
-
var _richText = require("@lexical/rich-text");
|
|
21
|
-
var QuoteNode = exports.QuoteNode = /*#__PURE__*/function (_BaseQuoteNode) {
|
|
22
|
-
function QuoteNode(themeStyleId, key) {
|
|
23
|
-
var _this;
|
|
24
|
-
(0, _classCallCheck2.default)(this, QuoteNode);
|
|
25
|
-
_this = (0, _callSuper2.default)(this, QuoteNode, [key]);
|
|
26
|
-
(0, _defineProperty2.default)(_this, "__styles", []);
|
|
27
|
-
_this.__themeStyleId = themeStyleId || "";
|
|
1
|
+
import { findTypographyStyleByHtmlTag } from "@webiny/lexical-theme";
|
|
2
|
+
import { addClassNamesToElement } from "@lexical/utils";
|
|
3
|
+
import { QuoteNode as BaseQuoteNode } from "@lexical/rich-text";
|
|
4
|
+
export class QuoteNode extends BaseQuoteNode {
|
|
5
|
+
__styles = [];
|
|
6
|
+
constructor(themeStyleId, key) {
|
|
7
|
+
super(key);
|
|
8
|
+
this.__themeStyleId = themeStyleId || "";
|
|
28
9
|
if (themeStyleId) {
|
|
29
|
-
|
|
10
|
+
this.__styles.push({
|
|
30
11
|
styleId: themeStyleId,
|
|
31
12
|
type: "typography"
|
|
32
13
|
});
|
|
33
14
|
}
|
|
34
|
-
return _this;
|
|
35
15
|
}
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
value: function getStyleId() {
|
|
40
|
-
return this.__themeStyleId;
|
|
41
|
-
}
|
|
16
|
+
getStyleId() {
|
|
17
|
+
return this.__themeStyleId;
|
|
18
|
+
}
|
|
42
19
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
styleId: typographyStyle.id,
|
|
53
|
-
type: "typography"
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}, {
|
|
58
|
-
key: "typographyStyleExist",
|
|
59
|
-
value: function typographyStyleExist(themeEmotionMap) {
|
|
60
|
-
var styleId = this.getTypographyStyleId();
|
|
61
|
-
if (!styleId) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
var style = themeEmotionMap[styleId];
|
|
65
|
-
return !!style;
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "getTypographyStyleId",
|
|
69
|
-
value: function getTypographyStyleId() {
|
|
70
|
-
var style = this.__styles.find(function (x) {
|
|
71
|
-
return x.type === "typography";
|
|
20
|
+
/*
|
|
21
|
+
* Find the first occurrence of the quoteblock in the theme styles and set as default.
|
|
22
|
+
*/
|
|
23
|
+
setDefaultTypography(themeEmotionMap) {
|
|
24
|
+
const typographyStyle = findTypographyStyleByHtmlTag("quoteblock", themeEmotionMap);
|
|
25
|
+
if (typographyStyle) {
|
|
26
|
+
this.__styles.push({
|
|
27
|
+
styleId: typographyStyle.id,
|
|
28
|
+
type: "typography"
|
|
72
29
|
});
|
|
73
|
-
return style?.styleId || undefined;
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
key: "hasTypographyStyle",
|
|
77
|
-
value: function hasTypographyStyle() {
|
|
78
|
-
return !!this.getTypographyStyleId();
|
|
79
30
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
}, {
|
|
87
|
-
key: "setThemeStyles",
|
|
88
|
-
value: function setThemeStyles(styles) {
|
|
89
|
-
var self = (0, _superPropGet2.default)(QuoteNode, "getWritable", this, 3)([]);
|
|
90
|
-
self.__styles = (0, _toConsumableArray2.default)(styles);
|
|
91
|
-
return self;
|
|
31
|
+
}
|
|
32
|
+
typographyStyleExist(themeEmotionMap) {
|
|
33
|
+
const styleId = this.getTypographyStyleId();
|
|
34
|
+
if (!styleId) {
|
|
35
|
+
return false;
|
|
92
36
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
37
|
+
const style = themeEmotionMap[styleId];
|
|
38
|
+
return !!style;
|
|
39
|
+
}
|
|
40
|
+
getTypographyStyleId() {
|
|
41
|
+
const style = this.__styles.find(x => x.type === "typography");
|
|
42
|
+
return style?.styleId || undefined;
|
|
43
|
+
}
|
|
44
|
+
hasTypographyStyle() {
|
|
45
|
+
return !!this.getTypographyStyleId();
|
|
46
|
+
}
|
|
47
|
+
getThemeStyles() {
|
|
48
|
+
const self = super.getLatest();
|
|
49
|
+
return self.__styles;
|
|
50
|
+
}
|
|
51
|
+
setThemeStyles(styles) {
|
|
52
|
+
const self = super.getWritable();
|
|
53
|
+
self.__styles = [...styles];
|
|
54
|
+
return self;
|
|
55
|
+
}
|
|
56
|
+
static getType() {
|
|
57
|
+
return "webiny-quote";
|
|
58
|
+
}
|
|
59
|
+
static clone(node) {
|
|
60
|
+
return new QuoteNode(node.getTypographyStyleId(), node.__key);
|
|
61
|
+
}
|
|
62
|
+
addThemeStylesToHTMLElement(element, theme) {
|
|
63
|
+
const themeEmotionMap = theme?.emotionMap;
|
|
64
|
+
if (!themeEmotionMap) {
|
|
110
65
|
return element;
|
|
111
66
|
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "createDOM",
|
|
114
|
-
value: function createDOM(config) {
|
|
115
|
-
var element = (0, _superPropGet2.default)(QuoteNode, "createDOM", this, 3)([config]);
|
|
116
|
-
var wTheme = config.theme;
|
|
117
|
-
var emotionThemeMap = wTheme?.emotionMap;
|
|
118
|
-
if (!emotionThemeMap) {
|
|
119
|
-
return element;
|
|
120
|
-
}
|
|
121
67
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
68
|
+
// style exist and is in active use
|
|
69
|
+
if (this.hasTypographyStyle() && this.typographyStyleExist(themeEmotionMap)) {
|
|
70
|
+
const styleId = this.getTypographyStyleId();
|
|
71
|
+
if (styleId) {
|
|
72
|
+
const typographyValue = themeEmotionMap[styleId];
|
|
73
|
+
addClassNamesToElement(element, typographyValue?.className);
|
|
74
|
+
return element;
|
|
125
75
|
}
|
|
126
|
-
this.addThemeStylesToHTMLElement(element, config.theme);
|
|
127
|
-
return element;
|
|
128
76
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
}], [{
|
|
139
|
-
key: "getType",
|
|
140
|
-
value: function getType() {
|
|
141
|
-
return "webiny-quote";
|
|
142
|
-
}
|
|
143
|
-
}, {
|
|
144
|
-
key: "clone",
|
|
145
|
-
value: function clone(node) {
|
|
146
|
-
return new QuoteNode(node.getTypographyStyleId(), node.__key);
|
|
147
|
-
}
|
|
148
|
-
}, {
|
|
149
|
-
key: "importDomConversionMap",
|
|
150
|
-
value: function importDomConversionMap() {
|
|
151
|
-
return {
|
|
152
|
-
conversion: convertBlockquoteElement,
|
|
153
|
-
priority: 0
|
|
154
|
-
};
|
|
77
|
+
return element;
|
|
78
|
+
}
|
|
79
|
+
createDOM(config) {
|
|
80
|
+
const element = super.createDOM(config);
|
|
81
|
+
const wTheme = config.theme;
|
|
82
|
+
const emotionThemeMap = wTheme?.emotionMap;
|
|
83
|
+
if (!emotionThemeMap) {
|
|
84
|
+
return element;
|
|
155
85
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
blockquote: function blockquote() {
|
|
162
|
-
return _this2.importDomConversionMap();
|
|
163
|
-
}
|
|
164
|
-
};
|
|
86
|
+
|
|
87
|
+
// if styleId is not set or user removed the style from theme, set default style
|
|
88
|
+
if (!this.hasTypographyStyle() || !this.typographyStyleExist(emotionThemeMap)) {
|
|
89
|
+
this.setDefaultTypography(emotionThemeMap);
|
|
165
90
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var styles = [{
|
|
180
|
-
styleId: serializedNode.styleId,
|
|
181
|
-
type: "typography"
|
|
182
|
-
}];
|
|
183
|
-
node.setThemeStyles(styles);
|
|
91
|
+
this.addThemeStylesToHTMLElement(element, config.theme);
|
|
92
|
+
return element;
|
|
93
|
+
}
|
|
94
|
+
static importDomConversionMap() {
|
|
95
|
+
return {
|
|
96
|
+
conversion: convertBlockquoteElement,
|
|
97
|
+
priority: 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
static importDOM() {
|
|
101
|
+
return {
|
|
102
|
+
blockquote: () => {
|
|
103
|
+
return this.importDomConversionMap();
|
|
184
104
|
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
static importJSON(serializedNode) {
|
|
108
|
+
const node = $createQuoteNode();
|
|
109
|
+
node.setFormat(serializedNode.format);
|
|
110
|
+
node.setIndent(serializedNode.indent);
|
|
111
|
+
node.setDirection(serializedNode.direction);
|
|
112
|
+
if (!!serializedNode?.styles?.length) {
|
|
113
|
+
node.setThemeStyles(serializedNode.styles);
|
|
185
114
|
return node;
|
|
186
115
|
}
|
|
187
|
-
|
|
188
|
-
|
|
116
|
+
// for old nodes data migrate the style id into the list
|
|
117
|
+
if (!!serializedNode?.styleId) {
|
|
118
|
+
const styles = [{
|
|
119
|
+
styleId: serializedNode.styleId,
|
|
120
|
+
type: "typography"
|
|
121
|
+
}];
|
|
122
|
+
node.setThemeStyles(styles);
|
|
123
|
+
}
|
|
124
|
+
return node;
|
|
125
|
+
}
|
|
126
|
+
exportJSON() {
|
|
127
|
+
return {
|
|
128
|
+
...super.exportJSON(),
|
|
129
|
+
type: "webiny-quote",
|
|
130
|
+
styles: this.__styles,
|
|
131
|
+
styleId: this.getTypographyStyleId()
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
189
135
|
function convertBlockquoteElement() {
|
|
190
|
-
|
|
136
|
+
const node = $createQuoteNode();
|
|
191
137
|
return {
|
|
192
|
-
node
|
|
138
|
+
node
|
|
193
139
|
};
|
|
194
140
|
}
|
|
195
|
-
function $createQuoteNode(themeStyleId, key) {
|
|
141
|
+
export function $createQuoteNode(themeStyleId, key) {
|
|
196
142
|
return new QuoteNode(themeStyleId, key);
|
|
197
143
|
}
|
|
198
|
-
function $isQuoteNode(node) {
|
|
144
|
+
export function $isQuoteNode(node) {
|
|
199
145
|
return node instanceof QuoteNode;
|
|
200
146
|
}
|
|
201
147
|
|
package/QuoteNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lexicalTheme","require","_utils","_richText","QuoteNode","exports","_BaseQuoteNode","themeStyleId","key","_this","_classCallCheck2","default","_callSuper2","_defineProperty2","__themeStyleId","__styles","push","styleId","type","_inherits2","_createClass2","value","getStyleId","setDefaultTypography","themeEmotionMap","typographyStyle","findTypographyStyleByHtmlTag","id","typographyStyleExist","getTypographyStyleId","style","find","x","undefined","hasTypographyStyle","getThemeStyles","self","_superPropGet2","setThemeStyles","styles","_toConsumableArray2","addThemeStylesToHTMLElement","element","theme","emotionMap","typographyValue","addClassNamesToElement","className","createDOM","config","wTheme","emotionThemeMap","exportJSON","_objectSpread2","getType","clone","node","__key","importDomConversionMap","conversion","convertBlockquoteElement","priority","importDOM","_this2","blockquote","importJSON","serializedNode","$createQuoteNode","setFormat","format","setIndent","indent","setDirection","direction","length","BaseQuoteNode","$isQuoteNode"],"sources":["QuoteNode.ts"],"sourcesContent":["import {\n DOMConversion,\n DOMConversionMap,\n EditorConfig,\n LexicalNode,\n NodeKey,\n Spread\n} from \"lexical\";\nimport { EditorTheme, ThemeEmotionMap, findTypographyStyleByHtmlTag } from \"@webiny/lexical-theme\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport {\n QuoteNode as BaseQuoteNode,\n SerializedQuoteNode as BaseSerializedQuoteNode\n} from \"@lexical/rich-text\";\nimport { TextNodeThemeStyles, ThemeStyleValue, TypographyStylesNode } from \"~/types\";\n\nexport type SerializedQuoteNode = Spread<\n {\n styleId?: string;\n styles: ThemeStyleValue[];\n type: \"webiny-quote\";\n },\n BaseSerializedQuoteNode\n>;\n\nexport class QuoteNode extends BaseQuoteNode implements TextNodeThemeStyles, TypographyStylesNode {\n private __themeStyleId: string;\n private __styles: ThemeStyleValue[] = [];\n\n constructor(themeStyleId?: string, key?: NodeKey) {\n super(key);\n this.__themeStyleId = themeStyleId || \"\";\n\n if (themeStyleId) {\n this.__styles.push({ styleId: themeStyleId, type: \"typography\" });\n }\n }\n\n getStyleId(): string {\n return this.__themeStyleId;\n }\n\n /*\n * Find the first occurrence of the quoteblock in the theme styles and set as default.\n */\n protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap) {\n const typographyStyle = findTypographyStyleByHtmlTag(\"quoteblock\", themeEmotionMap);\n if (typographyStyle) {\n this.__styles.push({ styleId: typographyStyle.id, type: \"typography\" });\n }\n }\n\n protected typographyStyleExist(themeEmotionMap: ThemeEmotionMap): boolean {\n const styleId = this.getTypographyStyleId();\n if (!styleId) {\n return false;\n }\n const style = themeEmotionMap[styleId];\n return !!style;\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 \"webiny-quote\";\n }\n\n static override clone(node: QuoteNode): QuoteNode {\n return new QuoteNode(node.getTypographyStyleId(), node.__key);\n }\n\n addThemeStylesToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n const themeEmotionMap = theme?.emotionMap;\n\n if (!themeEmotionMap) {\n return element;\n }\n\n // style exist and is in active use\n if (this.hasTypographyStyle() && this.typographyStyleExist(themeEmotionMap)) {\n const styleId = this.getTypographyStyleId();\n if (styleId) {\n const typographyValue = themeEmotionMap[styleId];\n addClassNamesToElement(element, typographyValue?.className);\n return element;\n }\n }\n\n return element;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n const wTheme = config.theme as EditorTheme;\n const emotionThemeMap = wTheme?.emotionMap;\n\n if (!emotionThemeMap) {\n return element;\n }\n\n // if styleId is not set or user removed the style from theme, set default style\n if (!this.hasTypographyStyle() || !this.typographyStyleExist(emotionThemeMap)) {\n this.setDefaultTypography(emotionThemeMap);\n }\n\n this.addThemeStylesToHTMLElement(element, config.theme as EditorTheme);\n return element;\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertBlockquoteElement,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n blockquote: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n static override importJSON(serializedNode: SerializedQuoteNode): QuoteNode {\n const node = $createQuoteNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n if (!!serializedNode?.styles?.length) {\n node.setThemeStyles(serializedNode.styles);\n return node;\n }\n // for old nodes data migrate the style id into the list\n if (!!serializedNode?.styleId) {\n const styles = [\n { styleId: serializedNode.styleId, type: \"typography\" }\n ] as ThemeStyleValue[];\n node.setThemeStyles(styles);\n }\n return node;\n }\n\n override exportJSON(): SerializedQuoteNode {\n return {\n ...super.exportJSON(),\n type: \"webiny-quote\",\n styles: this.__styles,\n styleId: this.getTypographyStyleId()\n };\n }\n}\n\nfunction convertBlockquoteElement() {\n const node = $createQuoteNode();\n return {\n node\n };\n}\n\nexport function $createQuoteNode(themeStyleId?: string, key?: NodeKey): QuoteNode {\n return new QuoteNode(themeStyleId, key);\n}\n\nexport function $isQuoteNode(node: LexicalNode | null | undefined): node is QuoteNode {\n return node instanceof QuoteNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAG4B,IAYfG,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAAAE,cAAA;EAIlB,SAAAF,UAAYG,YAAqB,EAAEC,GAAa,EAAE;IAAA,IAAAC,KAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAP,SAAA;IAC9CK,KAAA,OAAAG,WAAA,CAAAD,OAAA,QAAAP,SAAA,GAAMI,GAAG;IAAE,IAAAK,gBAAA,CAAAF,OAA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AoC,EAAqB;EAClF,OAAOA,IAAI,YAAYpD,SAAS;AACpC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["findTypographyStyleByHtmlTag","addClassNamesToElement","QuoteNode","BaseQuoteNode","__styles","constructor","themeStyleId","key","__themeStyleId","push","styleId","type","getStyleId","setDefaultTypography","themeEmotionMap","typographyStyle","id","typographyStyleExist","getTypographyStyleId","style","find","x","undefined","hasTypographyStyle","getThemeStyles","self","getLatest","setThemeStyles","styles","getWritable","getType","clone","node","__key","addThemeStylesToHTMLElement","element","theme","emotionMap","typographyValue","className","createDOM","config","wTheme","emotionThemeMap","importDomConversionMap","conversion","convertBlockquoteElement","priority","importDOM","blockquote","importJSON","serializedNode","$createQuoteNode","setFormat","format","setIndent","indent","setDirection","direction","length","exportJSON","$isQuoteNode"],"sources":["QuoteNode.ts"],"sourcesContent":["import {\n DOMConversion,\n DOMConversionMap,\n EditorConfig,\n LexicalNode,\n NodeKey,\n Spread\n} from \"lexical\";\nimport { EditorTheme, ThemeEmotionMap, findTypographyStyleByHtmlTag } from \"@webiny/lexical-theme\";\nimport { addClassNamesToElement } from \"@lexical/utils\";\nimport {\n QuoteNode as BaseQuoteNode,\n SerializedQuoteNode as BaseSerializedQuoteNode\n} from \"@lexical/rich-text\";\nimport { TextNodeThemeStyles, ThemeStyleValue, TypographyStylesNode } from \"~/types\";\n\nexport type SerializedQuoteNode = Spread<\n {\n styleId?: string;\n styles: ThemeStyleValue[];\n type: \"webiny-quote\";\n },\n BaseSerializedQuoteNode\n>;\n\nexport class QuoteNode extends BaseQuoteNode implements TextNodeThemeStyles, TypographyStylesNode {\n private __themeStyleId: string;\n private __styles: ThemeStyleValue[] = [];\n\n constructor(themeStyleId?: string, key?: NodeKey) {\n super(key);\n this.__themeStyleId = themeStyleId || \"\";\n\n if (themeStyleId) {\n this.__styles.push({ styleId: themeStyleId, type: \"typography\" });\n }\n }\n\n getStyleId(): string {\n return this.__themeStyleId;\n }\n\n /*\n * Find the first occurrence of the quoteblock in the theme styles and set as default.\n */\n protected setDefaultTypography(themeEmotionMap: ThemeEmotionMap) {\n const typographyStyle = findTypographyStyleByHtmlTag(\"quoteblock\", themeEmotionMap);\n if (typographyStyle) {\n this.__styles.push({ styleId: typographyStyle.id, type: \"typography\" });\n }\n }\n\n protected typographyStyleExist(themeEmotionMap: ThemeEmotionMap): boolean {\n const styleId = this.getTypographyStyleId();\n if (!styleId) {\n return false;\n }\n const style = themeEmotionMap[styleId];\n return !!style;\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 \"webiny-quote\";\n }\n\n static override clone(node: QuoteNode): QuoteNode {\n return new QuoteNode(node.getTypographyStyleId(), node.__key);\n }\n\n addThemeStylesToHTMLElement(element: HTMLElement, theme: EditorTheme): HTMLElement {\n const themeEmotionMap = theme?.emotionMap;\n\n if (!themeEmotionMap) {\n return element;\n }\n\n // style exist and is in active use\n if (this.hasTypographyStyle() && this.typographyStyleExist(themeEmotionMap)) {\n const styleId = this.getTypographyStyleId();\n if (styleId) {\n const typographyValue = themeEmotionMap[styleId];\n addClassNamesToElement(element, typographyValue?.className);\n return element;\n }\n }\n\n return element;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n const wTheme = config.theme as EditorTheme;\n const emotionThemeMap = wTheme?.emotionMap;\n\n if (!emotionThemeMap) {\n return element;\n }\n\n // if styleId is not set or user removed the style from theme, set default style\n if (!this.hasTypographyStyle() || !this.typographyStyleExist(emotionThemeMap)) {\n this.setDefaultTypography(emotionThemeMap);\n }\n\n this.addThemeStylesToHTMLElement(element, config.theme as EditorTheme);\n return element;\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertBlockquoteElement,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n blockquote: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n static override importJSON(serializedNode: SerializedQuoteNode): QuoteNode {\n const node = $createQuoteNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n if (!!serializedNode?.styles?.length) {\n node.setThemeStyles(serializedNode.styles);\n return node;\n }\n // for old nodes data migrate the style id into the list\n if (!!serializedNode?.styleId) {\n const styles = [\n { styleId: serializedNode.styleId, type: \"typography\" }\n ] as ThemeStyleValue[];\n node.setThemeStyles(styles);\n }\n return node;\n }\n\n override exportJSON(): SerializedQuoteNode {\n return {\n ...super.exportJSON(),\n type: \"webiny-quote\",\n styles: this.__styles,\n styleId: this.getTypographyStyleId()\n };\n }\n}\n\nfunction convertBlockquoteElement() {\n const node = $createQuoteNode();\n return {\n node\n };\n}\n\nexport function $createQuoteNode(themeStyleId?: string, key?: NodeKey): QuoteNode {\n return new QuoteNode(themeStyleId, key);\n}\n\nexport function $isQuoteNode(node: LexicalNode | null | undefined): node is QuoteNode {\n return node instanceof QuoteNode;\n}\n"],"mappings":"AAQA,SAAuCA,4BAA4B,QAAQ,uBAAuB;AAClG,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,SACIC,SAAS,IAAIC,aAAa,QAEvB,oBAAoB;AAY3B,OAAO,MAAMD,SAAS,SAASC,aAAa,CAAsD;EAEtFC,QAAQ,GAAsB,EAAE;EAExCC,WAAWA,CAACC,YAAqB,EAAEC,GAAa,EAAE;IAC9C,KAAK,CAACA,GAAG,CAAC;IACV,IAAI,CAACC,cAAc,GAAGF,YAAY,IAAI,EAAE;IAExC,IAAIA,YAAY,EAAE;MACd,IAAI,CAACF,QAAQ,CAACK,IAAI,CAAC;QAAEC,OAAO,EAAEJ,YAAY;QAAEK,IAAI,E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EA,OAAO,SAASoB,gBAAgBA,CAAC9C,YAAqB,EAAEC,GAAa,EAAa;EAC9E,OAAO,IAAIL,SAAS,CAACI,YAAY,EAAEC,GAAG,CAAC;AAC3C;AAEA,OAAO,SAASsD,YAAYA,CAAC7B,IAAoC,EAAqB;EAClF,OAAOA,IAAI,YAAY9B,SAAS;AACpC","ignoreList":[]}
|
package/TypographyNode.js
CHANGED
|
@@ -1,145 +1,108 @@
|
|
|
1
|
-
|
|
1
|
+
import { createCommand, ElementNode } from "lexical";
|
|
2
|
+
import { addClassNamesToElement } from "@lexical/utils";
|
|
3
|
+
import { $createParagraphNode } from "./ParagraphNode";
|
|
2
4
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.TypographyNode = exports.ADD_TYPOGRAPHY_COMMAND = exports.$isTypographyNode = exports.$createTypographyNode = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
12
|
-
var _superPropGet2 = _interopRequireDefault(require("@babel/runtime/helpers/superPropGet"));
|
|
13
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
|
-
var _lexical = require("lexical");
|
|
15
|
-
var _utils = require("@lexical/utils");
|
|
16
|
-
var _ParagraphNode = require("./ParagraphNode");
|
|
17
5
|
// Command and payload
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
export const ADD_TYPOGRAPHY_COMMAND = createCommand("ADD_TYPOGRAPHY_COMMAND");
|
|
7
|
+
const TypographyNodeAttrName = "data-typography-style-id";
|
|
20
8
|
|
|
21
9
|
// Node
|
|
10
|
+
|
|
22
11
|
/**
|
|
23
12
|
* Main responsibility of this node is to apply custom or Webiny theme typography to selected text.
|
|
24
13
|
* Extends the original ElementNode node to add additional transformation and support for webiny theme typography.
|
|
25
14
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_this.__name = value.name;
|
|
34
|
-
_this.__css = value.css;
|
|
35
|
-
return _this;
|
|
15
|
+
export class TypographyNode extends ElementNode {
|
|
16
|
+
constructor(value, key) {
|
|
17
|
+
super(key);
|
|
18
|
+
this.__tag = value.tag;
|
|
19
|
+
this.__styleId = value.id;
|
|
20
|
+
this.__name = value.name;
|
|
21
|
+
this.__css = value.css;
|
|
36
22
|
}
|
|
37
|
-
(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
value: function exportJSON() {
|
|
62
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _superPropGet2.default)(TypographyNode, "exportJSON", this, 3)([])), {}, {
|
|
63
|
-
tag: this.__tag,
|
|
64
|
-
typographyStyles: this.__css,
|
|
65
|
-
name: this.__name,
|
|
66
|
-
styleId: this.__styleId,
|
|
67
|
-
type: "typography-el-node",
|
|
68
|
-
version: 1
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "createDOM",
|
|
73
|
-
value: function createDOM(config) {
|
|
74
|
-
var tag = this.__tag;
|
|
75
|
-
var element = document.createElement(tag);
|
|
76
|
-
return this.addStylesHTMLElement(element, config.theme);
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "updateDOM",
|
|
80
|
-
value: function updateDOM() {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "insertNewAfter",
|
|
85
|
-
value: function insertNewAfter() {
|
|
86
|
-
var newElement = $createTypographyNode({
|
|
87
|
-
tag: this.__tag,
|
|
88
|
-
name: this.__name,
|
|
89
|
-
css: this.__css,
|
|
90
|
-
id: this.__styleId
|
|
91
|
-
});
|
|
92
|
-
var direction = this.getDirection();
|
|
93
|
-
newElement.setDirection(direction);
|
|
94
|
-
this.insertAfter(newElement);
|
|
95
|
-
return newElement;
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "collapseAtStart",
|
|
99
|
-
value: function collapseAtStart() {
|
|
100
|
-
var paragraph = (0, _ParagraphNode.$createParagraphNode)();
|
|
101
|
-
var children = this.getChildren();
|
|
102
|
-
children.forEach(function (child) {
|
|
103
|
-
return paragraph.append(child);
|
|
104
|
-
});
|
|
105
|
-
this.replace(paragraph);
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
}], [{
|
|
109
|
-
key: "getType",
|
|
110
|
-
value: function getType() {
|
|
111
|
-
return "typography-el-node";
|
|
112
|
-
}
|
|
113
|
-
}, {
|
|
114
|
-
key: "clone",
|
|
115
|
-
value: function clone(node) {
|
|
116
|
-
return new TypographyNode({
|
|
117
|
-
css: node.__css,
|
|
118
|
-
id: node.__styleId,
|
|
119
|
-
name: node.__name,
|
|
120
|
-
tag: node.__tag
|
|
121
|
-
}, node.__key);
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
key: "importJSON",
|
|
125
|
-
value: function importJSON(serializedNode) {
|
|
126
|
-
var node = new TypographyNode({
|
|
127
|
-
id: serializedNode.styleId,
|
|
128
|
-
css: serializedNode.typographyStyles,
|
|
129
|
-
tag: serializedNode.tag,
|
|
130
|
-
name: serializedNode.name
|
|
131
|
-
});
|
|
132
|
-
node.setFormat(serializedNode.format);
|
|
133
|
-
node.setIndent(serializedNode.indent);
|
|
134
|
-
node.setDirection(serializedNode.direction);
|
|
135
|
-
return node;
|
|
23
|
+
static getType() {
|
|
24
|
+
return "typography-el-node";
|
|
25
|
+
}
|
|
26
|
+
static clone(node) {
|
|
27
|
+
return new TypographyNode({
|
|
28
|
+
css: node.__css,
|
|
29
|
+
id: node.__styleId,
|
|
30
|
+
name: node.__name,
|
|
31
|
+
tag: node.__tag
|
|
32
|
+
}, node.__key);
|
|
33
|
+
}
|
|
34
|
+
getTypographyValue() {
|
|
35
|
+
return {
|
|
36
|
+
tag: this.__tag,
|
|
37
|
+
css: this.__css,
|
|
38
|
+
id: this.__styleId,
|
|
39
|
+
name: this.__name
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
addStylesHTMLElement(element, theme) {
|
|
43
|
+
const typographyStyleValue = theme.emotionMap ? theme.emotionMap[this.__styleId] : undefined;
|
|
44
|
+
if (typographyStyleValue) {
|
|
45
|
+
this.__css = typographyStyleValue.styles;
|
|
46
|
+
addClassNamesToElement(element, typographyStyleValue.className);
|
|
136
47
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
48
|
+
element.setAttribute(TypographyNodeAttrName, this.__styleId);
|
|
49
|
+
return element;
|
|
50
|
+
}
|
|
51
|
+
exportJSON() {
|
|
52
|
+
return {
|
|
53
|
+
...super.exportJSON(),
|
|
54
|
+
tag: this.__tag,
|
|
55
|
+
typographyStyles: this.__css,
|
|
56
|
+
name: this.__name,
|
|
57
|
+
styleId: this.__styleId,
|
|
58
|
+
type: "typography-el-node",
|
|
59
|
+
version: 1
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static importJSON(serializedNode) {
|
|
63
|
+
const node = new TypographyNode({
|
|
64
|
+
id: serializedNode.styleId,
|
|
65
|
+
css: serializedNode.typographyStyles,
|
|
66
|
+
tag: serializedNode.tag,
|
|
67
|
+
name: serializedNode.name
|
|
68
|
+
});
|
|
69
|
+
node.setFormat(serializedNode.format);
|
|
70
|
+
node.setIndent(serializedNode.indent);
|
|
71
|
+
node.setDirection(serializedNode.direction);
|
|
72
|
+
return node;
|
|
73
|
+
}
|
|
74
|
+
createDOM(config) {
|
|
75
|
+
const tag = this.__tag;
|
|
76
|
+
const element = document.createElement(tag);
|
|
77
|
+
return this.addStylesHTMLElement(element, config.theme);
|
|
78
|
+
}
|
|
79
|
+
updateDOM() {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
insertNewAfter() {
|
|
83
|
+
const newElement = $createTypographyNode({
|
|
84
|
+
tag: this.__tag,
|
|
85
|
+
name: this.__name,
|
|
86
|
+
css: this.__css,
|
|
87
|
+
id: this.__styleId
|
|
88
|
+
});
|
|
89
|
+
const direction = this.getDirection();
|
|
90
|
+
newElement.setDirection(direction);
|
|
91
|
+
this.insertAfter(newElement);
|
|
92
|
+
return newElement;
|
|
93
|
+
}
|
|
94
|
+
collapseAtStart() {
|
|
95
|
+
const paragraph = $createParagraphNode();
|
|
96
|
+
const children = this.getChildren();
|
|
97
|
+
children.forEach(child => paragraph.append(child));
|
|
98
|
+
this.replace(paragraph);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export const $createTypographyNode = (value, key) => {
|
|
140
103
|
return new TypographyNode(value, key);
|
|
141
104
|
};
|
|
142
|
-
|
|
105
|
+
export const $isTypographyNode = node => {
|
|
143
106
|
return node instanceof TypographyNode;
|
|
144
107
|
};
|
|
145
108
|
|