@webiny/lexical-nodes 5.44.1-beta.1 → 5.45.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.d.ts +6 -6
- package/FontColorNode.js +102 -145
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.d.ts +29 -17
- package/HeadingNode.js +184 -152
- package/HeadingNode.js.map +1 -1
- package/ImageNode.d.ts +1 -11
- package/ImageNode.js +119 -190
- package/ImageNode.js.map +1 -1
- package/LinkNode.d.ts +2 -2
- package/LinkNode.js +249 -346
- package/LinkNode.js.map +1 -1
- package/ListItemNode.d.ts +4 -3
- package/ListItemNode.js +275 -354
- package/ListItemNode.js.map +1 -1
- package/ListNode.d.ts +28 -14
- package/ListNode.js +170 -209
- package/ListNode.js.map +1 -1
- package/ParagraphNode.d.ts +28 -16
- package/ParagraphNode.js +143 -179
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.d.ts +26 -19
- package/QuoteNode.js +102 -188
- package/QuoteNode.js.map +1 -1
- package/README.md +9 -4
- package/components/ImageNode/ImageComponent.d.ts +2 -7
- package/components/ImageNode/ImageComponent.js +72 -166
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.d.ts +1 -8
- package/components/ImageNode/ImageResizer.js +74 -89
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.d.ts +4 -0
- package/generateInitialLexicalValue.js +27 -0
- package/generateInitialLexicalValue.js.map +1 -0
- package/index.d.ts +19 -23
- package/index.js +50 -233
- package/index.js.map +1 -1
- package/package.json +16 -20
- package/prepareLexicalState.d.ts +2 -0
- package/prepareLexicalState.js +53 -0
- package/prepareLexicalState.js.map +1 -0
- package/types.d.ts +4 -5
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/clearNodeFormating.d.ts +1 -1
- package/utils/clearNodeFormating.js +12 -18
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.d.ts +4 -4
- package/utils/formatList.js +171 -208
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.d.ts +2 -2
- package/utils/formatToHeading.js +8 -15
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.d.ts +1 -1
- package/utils/formatToParagraph.js +8 -16
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.d.ts +1 -1
- package/utils/formatToQuote.js +8 -15
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.d.ts +11 -0
- package/utils/getStyleId.js +14 -0
- package/utils/getStyleId.js.map +1 -0
- package/utils/listNode.d.ts +2 -2
- package/utils/listNode.js +37 -50
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.d.ts +1 -1
- package/utils/toggleLink.js +41 -45
- package/utils/toggleLink.js.map +1 -1
- package/TypographyNode.d.ts +0 -39
- package/TypographyNode.js +0 -146
- package/TypographyNode.js.map +0 -1
- package/components/ImageNode/ContentEditable.css +0 -22
- package/components/ImageNode/ContentEditable.d.ts +0 -12
- package/components/ImageNode/ContentEditable.js +0 -26
- package/components/ImageNode/ContentEditable.js.map +0 -1
- package/components/ImageNode/ImageComponent.css +0 -43
- package/components/ImageNode/Placeholder.css +0 -20
- package/components/ImageNode/Placeholder.d.ts +0 -15
- package/components/ImageNode/Placeholder.js +0 -30
- package/components/ImageNode/Placeholder.js.map +0 -1
- package/components/ImageNode/SharedHistoryContext.d.ts +0 -10
- package/components/ImageNode/SharedHistoryContext.js +0 -27
- package/components/ImageNode/SharedHistoryContext.js.map +0 -1
package/ListNode.js
CHANGED
|
@@ -1,204 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.$createListNode = $createListNode;
|
|
8
|
-
exports.$isListNode = $isListNode;
|
|
9
|
-
exports.ListNode = void 0;
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
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 _lexical = require("lexical");
|
|
18
|
-
var _lexicalTheme = require("@webiny/lexical-theme");
|
|
19
|
-
var _utils = require("@lexical/utils");
|
|
20
|
-
var _listNode = require("./utils/listNode");
|
|
21
|
-
var _ListItemNode = require("./ListItemNode");
|
|
22
|
-
var TypographyStyleAttrName = "data-theme-list-style-id";
|
|
23
|
-
var ListNode = exports.ListNode = /*#__PURE__*/function (_ElementNode) {
|
|
1
|
+
import { ElementNode, addClassNamesToElement, removeClassNamesFromElement } from "lexical";
|
|
2
|
+
import { Theme } from "@webiny/lexical-theme";
|
|
3
|
+
import { $getListDepth, wrapInListItem } from "./utils/listNode.js";
|
|
4
|
+
import { $isListItemNode } from "./ListItemNode.js";
|
|
5
|
+
export class ListNode extends ElementNode {
|
|
24
6
|
/** @internal */
|
|
25
7
|
|
|
26
8
|
/** @internal */
|
|
27
9
|
|
|
28
10
|
/** @internal */
|
|
29
11
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
constructor(listType, options = {}) {
|
|
13
|
+
const {
|
|
14
|
+
styleId,
|
|
15
|
+
key,
|
|
16
|
+
className,
|
|
17
|
+
start
|
|
18
|
+
} = options;
|
|
19
|
+
super(key);
|
|
20
|
+
this.__styleId = styleId ?? "";
|
|
21
|
+
this.__className = className;
|
|
22
|
+
const _listType = TAG_TO_WEBINY_LIST_TYPE[listType] || listType;
|
|
23
|
+
this.__listType = _listType;
|
|
24
|
+
this.__tag = _listType === "number" ? "ol" : "ul";
|
|
25
|
+
this.__start = start || 1;
|
|
40
26
|
}
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
dom.setAttribute("start", String(this.__start));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// If styleId is not set or user removed from theme, set default style
|
|
53
|
-
if (!this.hasThemeStyle() || !this.isStyleExistInTheme(wTheme)) {
|
|
54
|
-
this.setDefaultThemeListStyleByTag(this.__tag, wTheme);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// @ts-expect-error Internal field.
|
|
58
|
-
dom.__lexicalListType = this.__listType;
|
|
59
|
-
var theme = config.theme;
|
|
60
|
-
setListThemeClassNames(dom, theme, this, this.__themeStyleId);
|
|
61
|
-
dom.setAttribute(TypographyStyleAttrName, this.__themeStyleId);
|
|
62
|
-
return dom;
|
|
63
|
-
}
|
|
64
|
-
}, {
|
|
65
|
-
key: "getStyleId",
|
|
66
|
-
value: function getStyleId() {
|
|
67
|
-
return this.__themeStyleId;
|
|
68
|
-
}
|
|
69
|
-
}, {
|
|
70
|
-
key: "exportJSON",
|
|
71
|
-
value: function exportJSON() {
|
|
72
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _superPropGet2.default)(ListNode, "exportJSON", this, 3)([])), {}, {
|
|
73
|
-
themeStyleId: this.getStyleId(),
|
|
74
|
-
listType: this.getListType(),
|
|
75
|
-
start: this.getStart(),
|
|
76
|
-
tag: this.getTag(),
|
|
77
|
-
type: "webiny-list",
|
|
78
|
-
version: 1
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "updateDOM",
|
|
83
|
-
value: function updateDOM(prevNode, dom, config) {
|
|
84
|
-
var wTheme = config.theme;
|
|
85
|
-
if (prevNode.__tag !== this.__tag) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// if styleId is not set or user removed from theme, set default style.
|
|
90
|
-
if (!this.hasThemeStyle() || !this.isStyleExistInTheme(wTheme)) {
|
|
91
|
-
this.setDefaultThemeListStyleByTag(this.__tag, wTheme);
|
|
92
|
-
}
|
|
93
|
-
setListThemeClassNames(dom, config.theme, this, this.__themeStyleId);
|
|
94
|
-
dom.setAttribute(TypographyStyleAttrName, this.__themeStyleId);
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "extractWithChild",
|
|
99
|
-
value: function extractWithChild(child) {
|
|
100
|
-
return (0, _ListItemNode.$isListItemNode)(child);
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "getListType",
|
|
104
|
-
value: function getListType() {
|
|
105
|
-
return this.__listType;
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "getStart",
|
|
109
|
-
value: function getStart() {
|
|
110
|
-
return this.__start;
|
|
27
|
+
static getType() {
|
|
28
|
+
return "wby-list";
|
|
29
|
+
}
|
|
30
|
+
createDOM(config) {
|
|
31
|
+
const tag = this.__tag;
|
|
32
|
+
const element = document.createElement(tag);
|
|
33
|
+
if (this.__start !== 1) {
|
|
34
|
+
element.setAttribute("start", String(this.__start));
|
|
111
35
|
}
|
|
36
|
+
this.updateElementWithThemeClasses(element, Theme.from(config.theme));
|
|
112
37
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
38
|
+
// @ts-expect-error Internal field.
|
|
39
|
+
element.__lexicalListType = this.__listType;
|
|
40
|
+
const theme = Theme.from(config.theme);
|
|
41
|
+
setListThemeClassNames(element, theme, this, this.__styleId);
|
|
42
|
+
return element;
|
|
43
|
+
}
|
|
44
|
+
exportDOM(editor) {
|
|
45
|
+
const base = super.exportDOM(editor);
|
|
46
|
+
const element = base.element;
|
|
47
|
+
if (element && this.__className) {
|
|
48
|
+
element.classList.add(this.__className);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...base,
|
|
52
|
+
element
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
static clone(node) {
|
|
56
|
+
return new ListNode(node.getListType(), {
|
|
57
|
+
className: node.getClassName(),
|
|
58
|
+
styleId: node.getStyleId(),
|
|
59
|
+
start: node.getStart(),
|
|
60
|
+
key: node.getKey()
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getStyleId() {
|
|
64
|
+
return this.__styleId;
|
|
65
|
+
}
|
|
66
|
+
setStyleId(styleId) {
|
|
67
|
+
this.__styleId = styleId ?? "";
|
|
68
|
+
}
|
|
69
|
+
setClassName(className) {
|
|
70
|
+
this.__className = className;
|
|
71
|
+
}
|
|
72
|
+
getClassName() {
|
|
73
|
+
return this.__className;
|
|
74
|
+
}
|
|
75
|
+
static importJSON(serializedNode) {
|
|
76
|
+
const node = $createListNode(serializedNode.listType,
|
|
77
|
+
// `styleId` is for backwards compatibility
|
|
78
|
+
serializedNode.styleId ?? serializedNode.styleId, serializedNode.start);
|
|
79
|
+
node.setFormat(serializedNode.format);
|
|
80
|
+
node.setIndent(serializedNode.indent);
|
|
81
|
+
node.setDirection(serializedNode.direction);
|
|
82
|
+
node.setClassName(serializedNode.className);
|
|
83
|
+
return node;
|
|
84
|
+
}
|
|
85
|
+
exportJSON() {
|
|
86
|
+
return {
|
|
87
|
+
...super.exportJSON(),
|
|
88
|
+
styleId: this.__styleId,
|
|
89
|
+
className: this.__className,
|
|
90
|
+
listType: this.getListType(),
|
|
91
|
+
start: this.getStart(),
|
|
92
|
+
tag: this.getTag(),
|
|
93
|
+
type: "wby-list"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
static importDomConversionMap() {
|
|
97
|
+
return {
|
|
98
|
+
conversion: convertListNode,
|
|
99
|
+
priority: 0
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
static importDOM() {
|
|
103
|
+
return {
|
|
104
|
+
ol: () => {
|
|
105
|
+
return this.importDomConversionMap();
|
|
106
|
+
},
|
|
107
|
+
ul: () => {
|
|
108
|
+
return this.importDomConversionMap();
|
|
129
109
|
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
updateDOM(prevNode, dom, config) {
|
|
113
|
+
if (prevNode.__tag !== this.__tag) {
|
|
114
|
+
return true;
|
|
130
115
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return "webiny-list";
|
|
150
|
-
}
|
|
151
|
-
}, {
|
|
152
|
-
key: "clone",
|
|
153
|
-
value: function clone(node) {
|
|
154
|
-
return new ListNode(node.getListType(), node.getStyleId(), node.getStart(), node.__key);
|
|
155
|
-
}
|
|
156
|
-
}, {
|
|
157
|
-
key: "importJSON",
|
|
158
|
-
value: function importJSON(serializedNode) {
|
|
159
|
-
var node = $createListNode(serializedNode.listType, serializedNode.themeStyleId, serializedNode.start);
|
|
160
|
-
node.setFormat(serializedNode.format);
|
|
161
|
-
node.setIndent(serializedNode.indent);
|
|
162
|
-
node.setDirection(serializedNode.direction);
|
|
163
|
-
return node;
|
|
116
|
+
setListThemeClassNames(dom, Theme.from(config.theme), this, this.__styleId);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
extractWithChild(child) {
|
|
120
|
+
return $isListItemNode(child);
|
|
121
|
+
}
|
|
122
|
+
getListType() {
|
|
123
|
+
return this.__listType;
|
|
124
|
+
}
|
|
125
|
+
getStart() {
|
|
126
|
+
return this.__start;
|
|
127
|
+
}
|
|
128
|
+
getTag() {
|
|
129
|
+
return this.__tag;
|
|
130
|
+
}
|
|
131
|
+
updateElementWithThemeClasses(element, theme) {
|
|
132
|
+
if (!this.__styleId || !this.__className) {
|
|
133
|
+
this.setDefaultTypography(theme);
|
|
164
134
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
value: function importDomConversionMap() {
|
|
168
|
-
return {
|
|
169
|
-
conversion: convertListNode,
|
|
170
|
-
priority: 0
|
|
171
|
-
};
|
|
135
|
+
if (this.__className) {
|
|
136
|
+
addClassNamesToElement(element, this.__className);
|
|
172
137
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
},
|
|
181
|
-
ul: function ul() {
|
|
182
|
-
return _this2.importDomConversionMap();
|
|
183
|
-
}
|
|
184
|
-
};
|
|
138
|
+
return element;
|
|
139
|
+
}
|
|
140
|
+
setDefaultTypography(theme) {
|
|
141
|
+
const typographyStyle = theme.getTypographyByTag(this.getTag());
|
|
142
|
+
if (typographyStyle) {
|
|
143
|
+
this.__styleId = typographyStyle.id;
|
|
144
|
+
this.__className = typographyStyle.className;
|
|
185
145
|
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
function setListThemeClassNames(dom,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var listTheme = editorThemeClasses.list;
|
|
193
|
-
var emotionMap = editorTheme?.emotionMap || {};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function setListThemeClassNames(dom, theme, node, styleId) {
|
|
149
|
+
const classesToAdd = [];
|
|
150
|
+
const classesToRemove = [];
|
|
151
|
+
const listTheme = theme.tokens.list;
|
|
194
152
|
if (listTheme !== undefined) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
153
|
+
const listTypography = theme.getTypographyById(styleId);
|
|
154
|
+
const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];
|
|
155
|
+
const listDepth = $getListDepth(node) - 1;
|
|
156
|
+
const normalizedListDepth = listDepth % listLevelsClassNames.length;
|
|
157
|
+
const listLevelClassName = listLevelsClassNames[normalizedListDepth];
|
|
158
|
+
const listClassName = `${listTheme[node.__tag]} ${listTypography?.className ?? ""}`;
|
|
159
|
+
let nestedListClassName;
|
|
160
|
+
const nestedListTheme = listTheme.nested;
|
|
202
161
|
if (nestedListTheme !== undefined && nestedListTheme.list) {
|
|
203
162
|
nestedListClassName = nestedListTheme.list;
|
|
204
163
|
}
|
|
@@ -206,28 +165,28 @@ function setListThemeClassNames(dom, editorTheme, node, themeStyleId) {
|
|
|
206
165
|
classesToAdd.push(listClassName);
|
|
207
166
|
}
|
|
208
167
|
if (listLevelClassName !== undefined) {
|
|
209
|
-
|
|
210
|
-
classesToAdd.push
|
|
211
|
-
for (
|
|
168
|
+
const listItemClasses = listLevelClassName.split(" ");
|
|
169
|
+
classesToAdd.push(...listItemClasses);
|
|
170
|
+
for (let i = 0; i < listLevelsClassNames.length; i++) {
|
|
212
171
|
if (i !== normalizedListDepth) {
|
|
213
172
|
classesToRemove.push(node.__tag + i);
|
|
214
173
|
}
|
|
215
174
|
}
|
|
216
175
|
}
|
|
217
176
|
if (nestedListClassName !== undefined) {
|
|
218
|
-
|
|
177
|
+
const nestedListItemClasses = nestedListClassName.split(" ");
|
|
219
178
|
if (listDepth > 1) {
|
|
220
|
-
classesToAdd.push
|
|
179
|
+
classesToAdd.push(...nestedListItemClasses);
|
|
221
180
|
} else {
|
|
222
|
-
classesToRemove.push
|
|
181
|
+
classesToRemove.push(...nestedListItemClasses);
|
|
223
182
|
}
|
|
224
183
|
}
|
|
225
184
|
}
|
|
226
185
|
if (classesToRemove.length > 0) {
|
|
227
|
-
|
|
186
|
+
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
228
187
|
}
|
|
229
188
|
if (classesToAdd.length > 0) {
|
|
230
|
-
|
|
189
|
+
addClassNamesToElement(dom, ...classesToAdd);
|
|
231
190
|
}
|
|
232
191
|
}
|
|
233
192
|
|
|
@@ -237,25 +196,25 @@ function setListThemeClassNames(dom, editorTheme, node, themeStyleId) {
|
|
|
237
196
|
* or some other inline content.
|
|
238
197
|
*/
|
|
239
198
|
function normalizeChildren(nodes) {
|
|
240
|
-
|
|
241
|
-
for (
|
|
242
|
-
|
|
243
|
-
if (
|
|
199
|
+
const normalizedListItems = [];
|
|
200
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
201
|
+
const node = nodes[i];
|
|
202
|
+
if ($isListItemNode(node)) {
|
|
244
203
|
normalizedListItems.push(node);
|
|
245
|
-
node.getChildren().forEach(
|
|
204
|
+
node.getChildren().forEach(child => {
|
|
246
205
|
if ($isListNode(child)) {
|
|
247
|
-
normalizedListItems.push(
|
|
206
|
+
normalizedListItems.push(wrapInListItem(child));
|
|
248
207
|
}
|
|
249
208
|
});
|
|
250
209
|
} else {
|
|
251
|
-
normalizedListItems.push(
|
|
210
|
+
normalizedListItems.push(wrapInListItem(node));
|
|
252
211
|
}
|
|
253
212
|
}
|
|
254
213
|
return normalizedListItems;
|
|
255
214
|
}
|
|
256
215
|
function convertListNode(domNode) {
|
|
257
|
-
|
|
258
|
-
|
|
216
|
+
const nodeName = domNode.nodeName.toLowerCase();
|
|
217
|
+
let node = null;
|
|
259
218
|
if (nodeName === "ol") {
|
|
260
219
|
node = $createListNode("number");
|
|
261
220
|
} else if (nodeName === "ul") {
|
|
@@ -264,18 +223,20 @@ function convertListNode(domNode) {
|
|
|
264
223
|
return {
|
|
265
224
|
// @ts-expect-error
|
|
266
225
|
after: normalizeChildren,
|
|
267
|
-
node
|
|
226
|
+
node
|
|
268
227
|
};
|
|
269
228
|
}
|
|
270
|
-
|
|
229
|
+
const TAG_TO_WEBINY_LIST_TYPE = {
|
|
271
230
|
ol: "number",
|
|
272
231
|
ul: "bullet"
|
|
273
232
|
};
|
|
274
|
-
function $createListNode(listType,
|
|
275
|
-
|
|
276
|
-
|
|
233
|
+
export function $createListNode(listType, styleId, start = 1) {
|
|
234
|
+
return new ListNode(listType, {
|
|
235
|
+
start,
|
|
236
|
+
styleId
|
|
237
|
+
});
|
|
277
238
|
}
|
|
278
|
-
function $isListNode(node) {
|
|
239
|
+
export function $isListNode(node) {
|
|
279
240
|
return node instanceof ListNode;
|
|
280
241
|
}
|
|
281
242
|
|
package/ListNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lexical","require","_lexicalTheme","_utils","_listNode","_ListItemNode","TypographyStyleAttrName","ListNode","exports","_ElementNode","listType","themeStyleId","start","key","_this","_classCallCheck2","default","_callSuper2","__themeStyleId","_listType","TAG_TO_WEBINY_LIST_TYPE","__listType","__tag","__start","_inherits2","_createClass2","value","createDOM","config","tag","dom","document","createElement","wTheme","theme","setAttribute","String","hasThemeStyle","isStyleExistInTheme","setDefaultThemeListStyleByTag","__lexicalListType","setListThemeClassNames","getStyleId","exportJSON","_objectSpread2","_superPropGet2","getListType","getStart","getTag","type","version","updateDOM","prevNode","extractWithChild","child","$isListItemNode","themeEmotionMap","emotionMap","style","findTypographyStyleByHtmlTag","id","getType","clone","node","__key","importJSON","serializedNode","$createListNode","setFormat","format","setIndent","indent","setDirection","direction","importDomConversionMap","conversion","convertListNode","priority","importDOM","_this2","ol","ul","ElementNode","editorTheme","editorThemeClasses","classesToAdd","classesToRemove","listTheme","list","undefined","listLevelsClassNames","concat","listDepth","$getListDepth","normalizedListDepth","length","listLevelClassName","listClassName","className","nestedListClassName","nestedListTheme","nested","push","listItemClasses","split","apply","_toConsumableArray2","i","nestedListItemClasses","removeClassNamesFromElement","addClassNamesToElement","normalizeChildren","nodes","normalizedListItems","getChildren","forEach","$isListNode","wrapInListItem","domNode","nodeName","toLowerCase","after","arguments"],"sources":["ListNode.ts"],"sourcesContent":["import {\n DOMConversion,\n DOMConversionMap,\n DOMConversionOutput,\n EditorConfig,\n ElementNode,\n LexicalNode,\n NodeKey,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport { EditorTheme, findTypographyStyleByHtmlTag } from \"@webiny/lexical-theme\";\nimport { addClassNamesToElement, removeClassNamesFromElement } from \"@lexical/utils\";\nimport { ListNodeTagType } from \"@lexical/list/LexicalListNode\";\nimport { $getListDepth, wrapInListItem } from \"~/utils/listNode\";\nimport { $isListItemNode, ListItemNode } from \"./ListItemNode\";\nimport { ListType } from \"@lexical/list\";\n\nconst TypographyStyleAttrName = \"data-theme-list-style-id\";\n\nexport type SerializedWebinyListNode = Spread<\n {\n themeStyleId: string;\n listType: ListType;\n start: number;\n tag: ListNodeTagType;\n type: \"webiny-list\";\n version: 1;\n },\n SerializedElementNode\n>;\n\nexport class ListNode extends ElementNode {\n /** @internal */\n __tag: ListNodeTagType;\n /** @internal */\n __start: number;\n /** @internal */\n __listType: ListType;\n\n private __themeStyleId: string;\n\n constructor(listType: ListType, themeStyleId?: string, start?: number, key?: NodeKey) {\n super(key);\n this.__themeStyleId = themeStyleId || \"\";\n const _listType = TAG_TO_WEBINY_LIST_TYPE[listType] || listType;\n this.__listType = _listType;\n this.__tag = _listType === \"number\" ? \"ol\" : \"ul\";\n this.__start = start || 1;\n }\n\n static override getType() {\n return \"webiny-list\";\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const tag = this.__tag;\n const dom = document.createElement(tag);\n const wTheme = config.theme as EditorTheme;\n\n if (this.__start !== 1) {\n dom.setAttribute(\"start\", String(this.__start));\n }\n\n // If styleId is not set or user removed from theme, set default style\n if (!this.hasThemeStyle() || !this.isStyleExistInTheme(wTheme)) {\n this.setDefaultThemeListStyleByTag(this.__tag, wTheme);\n }\n\n // @ts-expect-error Internal field.\n dom.__lexicalListType = this.__listType;\n const theme = config.theme as EditorTheme;\n setListThemeClassNames(dom, theme, this, this.__themeStyleId);\n dom.setAttribute(TypographyStyleAttrName, this.__themeStyleId);\n return dom;\n }\n\n static override clone(node: ListNode): ListNode {\n return new ListNode(node.getListType(), node.getStyleId(), node.getStart(), node.__key);\n }\n\n getStyleId(): string {\n return this.__themeStyleId;\n }\n\n static override importJSON(serializedNode: SerializedWebinyListNode): ListNode {\n const node = $createListNode(\n serializedNode.listType,\n serializedNode.themeStyleId,\n serializedNode.start\n );\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n return node;\n }\n\n override exportJSON(): SerializedWebinyListNode {\n return {\n ...super.exportJSON(),\n themeStyleId: this.getStyleId(),\n listType: this.getListType(),\n start: this.getStart(),\n tag: this.getTag(),\n type: \"webiny-list\",\n version: 1\n };\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertListNode,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n ol: () => {\n return this.importDomConversionMap();\n },\n ul: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n override updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean {\n const wTheme = config.theme as EditorTheme;\n\n if (prevNode.__tag !== this.__tag) {\n return true;\n }\n\n // if styleId is not set or user removed from theme, set default style.\n if (!this.hasThemeStyle() || !this.isStyleExistInTheme(wTheme)) {\n this.setDefaultThemeListStyleByTag(this.__tag, wTheme);\n }\n\n setListThemeClassNames(dom, config.theme as EditorTheme, this, this.__themeStyleId);\n dom.setAttribute(TypographyStyleAttrName, this.__themeStyleId);\n return false;\n }\n\n override extractWithChild(child: LexicalNode): boolean {\n return $isListItemNode(child);\n }\n\n public getListType(): ListType {\n return this.__listType;\n }\n\n public getStart(): number {\n return this.__start;\n }\n\n /*\n * Set default styleId from first style that is found in the theme that contains current ul or ol tag\n */\n private setDefaultThemeListStyleByTag(tag: string, theme: EditorTheme) {\n if (!tag) {\n return;\n }\n\n const themeEmotionMap = theme?.emotionMap;\n if (!themeEmotionMap) {\n return;\n }\n\n const style = findTypographyStyleByHtmlTag(tag, themeEmotionMap);\n\n if (style) {\n this.__themeStyleId = style.id;\n }\n }\n\n private hasThemeStyle(): boolean {\n return !!this.__themeStyleId;\n }\n\n private getTag(): ListNodeTagType {\n return this.__tag;\n }\n\n private isStyleExistInTheme(theme: EditorTheme): boolean {\n return theme?.emotionMap ? !!theme?.emotionMap[this.__themeStyleId] : false;\n }\n}\n\nfunction setListThemeClassNames(\n dom: HTMLElement,\n editorTheme: EditorTheme,\n node: ListNode,\n themeStyleId: string\n): void {\n const editorThemeClasses = editorTheme;\n const classesToAdd = [];\n const classesToRemove = [];\n const listTheme = editorThemeClasses.list;\n const emotionMap = editorTheme?.emotionMap || {};\n if (listTheme !== undefined) {\n const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];\n const listDepth = $getListDepth(node) - 1;\n const normalizedListDepth = listDepth % listLevelsClassNames.length;\n const listLevelClassName = listLevelsClassNames[normalizedListDepth];\n const listClassName = `${listTheme[node.__tag]} ${\n emotionMap[themeStyleId]?.className ?? \"\"\n }`;\n let nestedListClassName;\n const nestedListTheme = listTheme.nested;\n\n if (nestedListTheme !== undefined && nestedListTheme.list) {\n nestedListClassName = nestedListTheme.list;\n }\n\n if (listClassName) {\n classesToAdd.push(listClassName);\n }\n\n if (listLevelClassName !== undefined) {\n const listItemClasses = listLevelClassName.split(\" \");\n classesToAdd.push(...listItemClasses);\n for (let i = 0; i < listLevelsClassNames.length; i++) {\n if (i !== normalizedListDepth) {\n classesToRemove.push(node.__tag + i);\n }\n }\n }\n\n if (nestedListClassName !== undefined) {\n const nestedListItemClasses = nestedListClassName.split(\" \");\n\n if (listDepth > 1) {\n classesToAdd.push(...nestedListItemClasses);\n } else {\n classesToRemove.push(...nestedListItemClasses);\n }\n }\n }\n\n if (classesToRemove.length > 0) {\n removeClassNamesFromElement(dom, ...classesToRemove);\n }\n\n if (classesToAdd.length > 0) {\n addClassNamesToElement(dom, ...classesToAdd);\n }\n}\n\n/*\n * This function normalizes the children of a ListNode after the conversion from HTML,\n * ensuring that they are all ListItemNodes and contain either a single nested ListNode\n * or some other inline content.\n */\nfunction normalizeChildren(nodes: Array<ListNode>): Array<ListItemNode> {\n const normalizedListItems: Array<ListItemNode> = [];\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if ($isListItemNode(node)) {\n normalizedListItems.push(node);\n node.getChildren().forEach(child => {\n if ($isListNode(child)) {\n normalizedListItems.push(wrapInListItem(child));\n }\n });\n } else {\n normalizedListItems.push(wrapInListItem(node));\n }\n }\n return normalizedListItems;\n}\n\nfunction convertListNode(domNode: Node): DOMConversionOutput {\n const nodeName = domNode.nodeName.toLowerCase();\n let node = null;\n\n if (nodeName === \"ol\") {\n node = $createListNode(\"number\");\n } else if (nodeName === \"ul\") {\n node = $createListNode(\"bullet\");\n }\n\n return {\n // @ts-expect-error\n after: normalizeChildren,\n node\n };\n}\n\nconst TAG_TO_WEBINY_LIST_TYPE: Record<string, ListType> = {\n ol: \"number\",\n ul: \"bullet\"\n};\n\nexport function $createListNode(listType: ListType, themeStyleId?: string, start = 1): ListNode {\n return new ListNode(listType, themeStyleId, start);\n}\n\nexport function $isListNode(node: LexicalNode | null | undefined): node is ListNode {\n return node instanceof ListNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAWA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAGA,IAAMK,uBAAuB,GAAG,0BAA0B;AAAC,IAc9CC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,0BAAAE,YAAA;EACjB;;EAEA;;EAEA;;EAKA,SAAAF,SAAYG,QAAkB,EAAEC,YAAqB,EAAEC,KAAc,EAAEC,GA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AACrD,IAAoC,EAAoB;EAChF,OAAOA,IAAI,YAAYxD,QAAQ;AACnC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["ElementNode","addClassNamesToElement","removeClassNamesFromElement","Theme","$getListDepth","wrapInListItem","$isListItemNode","ListNode","constructor","listType","options","styleId","key","className","start","__styleId","__className","_listType","TAG_TO_WEBINY_LIST_TYPE","__listType","__tag","__start","getType","createDOM","config","tag","element","document","createElement","setAttribute","String","updateElementWithThemeClasses","from","theme","__lexicalListType","setListThemeClassNames","exportDOM","editor","base","classList","add","clone","node","getListType","getClassName","getStyleId","getStart","getKey","setStyleId","setClassName","importJSON","serializedNode","$createListNode","setFormat","format","setIndent","indent","setDirection","direction","exportJSON","getTag","type","importDomConversionMap","conversion","convertListNode","priority","importDOM","ol","ul","updateDOM","prevNode","dom","extractWithChild","child","setDefaultTypography","typographyStyle","getTypographyByTag","id","classesToAdd","classesToRemove","listTheme","tokens","list","undefined","listTypography","getTypographyById","listLevelsClassNames","listDepth","normalizedListDepth","length","listLevelClassName","listClassName","nestedListClassName","nestedListTheme","nested","push","listItemClasses","split","i","nestedListItemClasses","normalizeChildren","nodes","normalizedListItems","getChildren","forEach","$isListNode","domNode","nodeName","toLowerCase","after"],"sources":["ListNode.ts"],"sourcesContent":["import type {\n DOMConversion,\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport { ElementNode, addClassNamesToElement, removeClassNamesFromElement } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { ListNodeTagType } from \"@lexical/list\";\nimport { $getListDepth, wrapInListItem } from \"~/utils/listNode.js\";\nimport type { ListItemNode } from \"./ListItemNode.js\";\nimport { $isListItemNode } from \"./ListItemNode.js\";\nimport type { ListType } from \"@lexical/list\";\nimport type { TypographyStylesNode } from \"~/types.js\";\n\nexport type SerializedWebinyListNode = Spread<\n {\n styleId?: string;\n className?: string;\n listType: ListType;\n start: number;\n tag: ListNodeTagType;\n type: \"wby-list\";\n },\n SerializedElementNode\n>;\n\ntype ListNodeOptions = {\n styleId?: string;\n className?: string;\n start?: number;\n key?: NodeKey;\n};\n\nexport class ListNode extends ElementNode implements TypographyStylesNode {\n /** @internal */\n __tag: ListNodeTagType;\n /** @internal */\n __start: number;\n /** @internal */\n __listType: ListType;\n\n private __styleId: string;\n private __className: string | undefined;\n\n constructor(listType: ListType, options: ListNodeOptions = {}) {\n const { styleId, key, className, start } = options;\n super(key);\n this.__styleId = styleId ?? \"\";\n this.__className = className;\n const _listType = TAG_TO_WEBINY_LIST_TYPE[listType] || listType;\n this.__listType = _listType;\n this.__tag = _listType === \"number\" ? \"ol\" : \"ul\";\n this.__start = start || 1;\n }\n\n static override getType() {\n return \"wby-list\";\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const tag = this.__tag;\n const element = document.createElement(tag);\n\n if (this.__start !== 1) {\n element.setAttribute(\"start\", String(this.__start));\n }\n\n this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n\n // @ts-expect-error Internal field.\n element.__lexicalListType = this.__listType;\n const theme = Theme.from(config.theme);\n setListThemeClassNames(element, theme, this, this.__styleId);\n return element;\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n static override clone(node: ListNode): ListNode {\n return new ListNode(node.getListType(), {\n className: node.getClassName(),\n styleId: node.getStyleId(),\n start: node.getStart(),\n key: node.getKey()\n });\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId ?? \"\";\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n static override importJSON(serializedNode: SerializedWebinyListNode): ListNode {\n const node = $createListNode(\n serializedNode.listType,\n // `styleId` is for backwards compatibility\n serializedNode.styleId ?? serializedNode.styleId,\n serializedNode.start\n );\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n node.setClassName(serializedNode.className);\n\n return node;\n }\n\n override exportJSON(): SerializedWebinyListNode {\n return {\n ...super.exportJSON(),\n styleId: this.__styleId,\n className: this.__className,\n listType: this.getListType(),\n start: this.getStart(),\n tag: this.getTag(),\n type: \"wby-list\"\n };\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertListNode,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n ol: () => {\n return this.importDomConversionMap();\n },\n ul: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n override updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean {\n if (prevNode.__tag !== this.__tag) {\n return true;\n }\n\n setListThemeClassNames(dom, Theme.from(config.theme), this, this.__styleId);\n return false;\n }\n\n override extractWithChild(child: LexicalNode): boolean {\n return $isListItemNode(child);\n }\n\n public getListType(): ListType {\n return this.__listType;\n }\n\n public getStart(): number {\n return this.__start;\n }\n\n private getTag(): ListNodeTagType {\n return this.__tag;\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n\n private setDefaultTypography(theme: Theme) {\n const typographyStyle = theme.getTypographyByTag(this.getTag());\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n}\n\nfunction setListThemeClassNames(\n dom: HTMLElement,\n theme: Theme,\n node: ListNode,\n styleId: string\n): void {\n const classesToAdd = [];\n const classesToRemove = [];\n const listTheme = theme.tokens.list;\n if (listTheme !== undefined) {\n const listTypography = theme.getTypographyById(styleId);\n const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];\n const listDepth = $getListDepth(node) - 1;\n const normalizedListDepth = listDepth % listLevelsClassNames.length;\n const listLevelClassName = listLevelsClassNames[normalizedListDepth];\n const listClassName = `${listTheme[node.__tag]} ${listTypography?.className ?? \"\"}`;\n let nestedListClassName;\n const nestedListTheme = listTheme.nested;\n\n if (nestedListTheme !== undefined && nestedListTheme.list) {\n nestedListClassName = nestedListTheme.list;\n }\n\n if (listClassName) {\n classesToAdd.push(listClassName);\n }\n\n if (listLevelClassName !== undefined) {\n const listItemClasses = listLevelClassName.split(\" \");\n classesToAdd.push(...listItemClasses);\n for (let i = 0; i < listLevelsClassNames.length; i++) {\n if (i !== normalizedListDepth) {\n classesToRemove.push(node.__tag + i);\n }\n }\n }\n\n if (nestedListClassName !== undefined) {\n const nestedListItemClasses = nestedListClassName.split(\" \");\n\n if (listDepth > 1) {\n classesToAdd.push(...nestedListItemClasses);\n } else {\n classesToRemove.push(...nestedListItemClasses);\n }\n }\n }\n\n if (classesToRemove.length > 0) {\n removeClassNamesFromElement(dom, ...classesToRemove);\n }\n\n if (classesToAdd.length > 0) {\n addClassNamesToElement(dom, ...classesToAdd);\n }\n}\n\n/*\n * This function normalizes the children of a ListNode after the conversion from HTML,\n * ensuring that they are all ListItemNodes and contain either a single nested ListNode\n * or some other inline content.\n */\nfunction normalizeChildren(nodes: Array<ListNode>): Array<ListItemNode> {\n const normalizedListItems: Array<ListItemNode> = [];\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if ($isListItemNode(node)) {\n normalizedListItems.push(node);\n node.getChildren().forEach(child => {\n if ($isListNode(child)) {\n normalizedListItems.push(wrapInListItem(child));\n }\n });\n } else {\n normalizedListItems.push(wrapInListItem(node));\n }\n }\n return normalizedListItems;\n}\n\nfunction convertListNode(domNode: Node): DOMConversionOutput {\n const nodeName = domNode.nodeName.toLowerCase();\n let node = null;\n\n if (nodeName === \"ol\") {\n node = $createListNode(\"number\");\n } else if (nodeName === \"ul\") {\n node = $createListNode(\"bullet\");\n }\n\n return {\n // @ts-expect-error\n after: normalizeChildren,\n node\n };\n}\n\nconst TAG_TO_WEBINY_LIST_TYPE: Record<string, ListType> = {\n ol: \"number\",\n ul: \"bullet\"\n};\n\nexport function $createListNode(listType: ListType, styleId?: string, start = 1): ListNode {\n return new ListNode(listType, {\n start,\n styleId\n });\n}\n\nexport function $isListNode(node: LexicalNode | null | undefined): node is ListNode {\n return node instanceof ListNode;\n}\n"],"mappings":"AAYA,SAASA,WAAW,EAAEC,sBAAsB,EAAEC,2BAA2B,QAAQ,SAAS;AAC1F,SAASC,KAAK,QAAQ,uBAAuB;AAE7C,SAASC,aAAa,EAAEC,cAAc;AAEtC,SAASC,eAAe;AAuBxB,OAAO,MAAMC,QAAQ,SAASP,WAAW,CAAiC;EACtE;;EAEA;;EAEA;;EAMAQ,WAAWA,CAACC,QAAkB,EAAEC,OAAwB,GAAG,CAAC,CAAC,EAAE;IAC3D,MAAM;MAAEC,OAAO;MAAEC,GAAG;MAAEC,SAAS;MAAEC;IAAM,CAAC,GAAGJ,OAAO;IAClD,KAAK,CAACE,GAAG,CAAC;IACV,IAAI,CAACG,SAAS,GAAGJ,OAAO,IAAI,EAAE;IAC9B,IAAI,CAACK,WAAW,GAAGH,SAAS;IAC5B,MAAMI,SAAS,GAAGC,uBAAuB,CAACT,QAAQ,CAAC,IAAIA,QAAQ;IAC/D,IAAI,CAACU,UAAU,GAAGF,SAAS;IAC3B,IAAI,CAACG,KAAK,GAAGH,SAAS,KAAK,QAAQ,GAAG,IAAI,GAAG,IAAI;IACjD,IAAI,CAACI,OAAO,GAAGP,KAAK,IAAI,CAAC;EAC7B;EAEA,OAAgBQ,OAAOA,CAAA,EAAG;IACtB,OAAO,UAAU;EACrB;EAESC,SAASA,CAACC,MAAoB,EAAe;IAClD,MAAMC,GAAG,GAAG,IAAI,CAACL,KAAK;IACtB,MAAMM,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAACH,GAAG,CAAC;IAE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B6B,mBAAmB,CAACP,IAAI,CAAC1F,cAAc,CAACoE,KAAK,CAAC,CAAC;QACnD;MACJ,CAAC,CAAC;IACN,CAAC,MAAM;MACH6B,mBAAmB,CAACP,IAAI,CAAC1F,cAAc,CAACqC,IAAI,CAAC,CAAC;IAClD;EACJ;EACA,OAAO4D,mBAAmB;AAC9B;AAEA,SAAStC,eAAeA,CAAC0C,OAAa,EAAuB;EACzD,MAAMC,QAAQ,GAAGD,OAAO,CAACC,QAAQ,CAACC,WAAW,CAAC,CAAC;EAC/C,IAAIlE,IAAI,GAAG,IAAI;EAEf,IAAIiE,QAAQ,KAAK,IAAI,EAAE;IACnBjE,IAAI,GAAGU,eAAe,CAAC,QAAQ,CAAC;EACpC,CAAC,MAAM,IAAIuD,QAAQ,KAAK,IAAI,EAAE;IAC1BjE,IAAI,GAAGU,eAAe,CAAC,QAAQ,CAAC;EACpC;EAEA,OAAO;IACH;IACAyD,KAAK,EAAET,iBAAiB;IACxB1D;EACJ,CAAC;AACL;AAEA,MAAMxB,uBAAiD,GAAG;EACtDiD,EAAE,EAAE,QAAQ;EACZC,EAAE,EAAE;AACR,CAAC;AAED,OAAO,SAAShB,eAAeA,CAAC3C,QAAkB,EAAEE,OAAgB,EAAEG,KAAK,GAAG,CAAC,EAAY;EACvF,OAAO,IAAIP,QAAQ,CAACE,QAAQ,EAAE;IAC1BK,KAAK;IACLH;EACJ,CAAC,CAAC;AACN;AAEA,OAAO,SAAS8F,WAAWA,CAAC/D,IAAoC,EAAoB;EAChF,OAAOA,IAAI,YAAYnC,QAAQ;AACnC","ignoreList":[]}
|
package/ParagraphNode.d.ts
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
|
-
import { DOMConversionMap, LexicalNode, NodeKey,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { DOMConversionMap, LexicalNode, NodeKey, SerializedParagraphNode as SerializedBaseParagraphNode, Spread, LexicalEditor, DOMExportOutput, RangeSelection } from "lexical";
|
|
2
|
+
import { ParagraphNode as BaseParagraphNode } from "lexical";
|
|
3
|
+
import type { EditorConfig } from "lexical";
|
|
4
|
+
import { Theme } from "@webiny/lexical-theme";
|
|
5
|
+
import type { TypographyStylesNode, ThemeStyleValue } from "./types.js";
|
|
5
6
|
export type SerializeParagraphNode = Spread<{
|
|
6
|
-
styles
|
|
7
|
-
|
|
7
|
+
styles?: ThemeStyleValue[];
|
|
8
|
+
styleId?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
type: "wby-paragraph";
|
|
8
11
|
}, SerializedBaseParagraphNode>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
interface ParagraphNodeOptions {
|
|
13
|
+
className?: string;
|
|
14
|
+
styleId?: string;
|
|
15
|
+
key?: NodeKey;
|
|
16
|
+
}
|
|
17
|
+
export declare class ParagraphNode extends BaseParagraphNode implements TypographyStylesNode {
|
|
18
|
+
private __styleId;
|
|
19
|
+
private __className;
|
|
20
|
+
constructor(options?: ParagraphNodeOptions);
|
|
21
|
+
getStyleId(): string | undefined;
|
|
22
|
+
setStyleId(styleId: string | undefined): void;
|
|
23
|
+
setClassName(className: string | undefined): void;
|
|
24
|
+
getClassName(): string | undefined;
|
|
17
25
|
static getType(): string;
|
|
18
26
|
static clone(node: ParagraphNode): ParagraphNode;
|
|
19
|
-
|
|
27
|
+
insertNewAfter(rangeSelection: RangeSelection, restoreSelection: boolean): ParagraphNode;
|
|
20
28
|
createDOM(config: EditorConfig): HTMLElement;
|
|
29
|
+
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
21
30
|
updateDOM(prevNode: ParagraphNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
22
31
|
static importDOM(): DOMConversionMap | null;
|
|
23
32
|
static importJSON(serializedNode: SerializeParagraphNode): BaseParagraphNode;
|
|
24
33
|
exportJSON(): SerializeParagraphNode;
|
|
34
|
+
protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement;
|
|
35
|
+
private setDefaultTypography;
|
|
25
36
|
}
|
|
26
|
-
export declare function $createParagraphNode(
|
|
37
|
+
export declare function $createParagraphNode(styleId?: string): ParagraphNode;
|
|
27
38
|
export declare function $isParagraphNode(node: LexicalNode | null | undefined): node is ParagraphNode;
|
|
39
|
+
export {};
|