@lexical/list 0.7.3 → 0.7.5
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/LexicalList.dev.js +23 -2
- package/LexicalList.prod.js +5 -4
- package/LexicalListNode.d.ts +2 -1
- package/package.json +3 -3
package/LexicalList.dev.js
CHANGED
|
@@ -1020,8 +1020,9 @@ function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
1022
1022
|
function convertListItemElement(domNode) {
|
|
1023
|
+
const checked = domNode instanceof HTMLElement && domNode.getAttribute('aria-checked') === 'true';
|
|
1023
1024
|
return {
|
|
1024
|
-
node: $createListItemNode()
|
|
1025
|
+
node: $createListItemNode(checked)
|
|
1025
1026
|
};
|
|
1026
1027
|
}
|
|
1027
1028
|
|
|
@@ -1123,6 +1124,22 @@ class ListNode extends lexical.ElementNode {
|
|
|
1123
1124
|
return node;
|
|
1124
1125
|
}
|
|
1125
1126
|
|
|
1127
|
+
exportDOM(editor) {
|
|
1128
|
+
const element = document.createElement(this.__tag);
|
|
1129
|
+
|
|
1130
|
+
if (this.__start !== 1) {
|
|
1131
|
+
element.setAttribute('start', String(this.__start));
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
if (this.__listType === 'check') {
|
|
1135
|
+
element.setAttribute('__lexicalListType', 'check');
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
return {
|
|
1139
|
+
element
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1126
1143
|
exportJSON() {
|
|
1127
1144
|
return { ...super.exportJSON(),
|
|
1128
1145
|
listType: this.getListType(),
|
|
@@ -1259,7 +1276,11 @@ function convertListNode(domNode) {
|
|
|
1259
1276
|
if (nodeName === 'ol') {
|
|
1260
1277
|
node = $createListNode('number');
|
|
1261
1278
|
} else if (nodeName === 'ul') {
|
|
1262
|
-
|
|
1279
|
+
if (domNode instanceof HTMLElement && domNode.getAttribute('__lexicallisttype') === 'check') {
|
|
1280
|
+
node = $createListNode('check');
|
|
1281
|
+
} else {
|
|
1282
|
+
node = $createListNode('bullet');
|
|
1283
|
+
}
|
|
1263
1284
|
}
|
|
1264
1285
|
|
|
1265
1286
|
return {
|
package/LexicalList.prod.js
CHANGED
|
@@ -21,12 +21,13 @@ b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=p(d);1==
|
|
|
21
21
|
a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=this.getParent();if(null===a)return this.getLatest().__indent;a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(G([this]),b++):(H([this]),b--);return this}canIndent(){return!1}insertBefore(a){if(p(a)){let b=this.getParentOrThrow();if(q(b)){let c=this.getNextSiblings();F(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||
|
|
22
22
|
p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}}
|
|
23
23
|
function L(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(f=f.split(" "),d.push(...f));if(b){f=c.getParent();f=q(f)&&"check"===f.getListType();let l=c.getChecked();f&&!l||e.push(b.listitemUnchecked);f&&l||e.push(b.listitemChecked);f&&d.push(l?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(l=>q(l))?d.push(...g):e.push(...g));0<e.length&&k.removeClassNamesFromElement(a,...e);0<d.length&&k.addClassNamesToElement(a,
|
|
24
|
-
...d)}function K(a,b,c,d){"check"===d.getListType()?q(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false")):null!=b.getChecked()&&b.setChecked(void 0)}function M(){return{node:z(
|
|
24
|
+
...d)}function K(a,b,c,d){"check"===d.getListType()?q(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false")):null!=b.getChecked()&&b.setChecked(void 0)}function M(a){a=a instanceof HTMLElement&&"true"===a.getAttribute("aria-checked");return{node:z(a)}}
|
|
25
|
+
function z(a){return h.$applyNodeReplacement(new J(void 0,a))}function p(a){return a instanceof J}
|
|
25
26
|
class N extends h.ElementNode{static getType(){return"list"}static clone(a){return new N(a.__listType||O[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=O[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));b.__lexicalListType=this.__listType;P(b,a.theme,this);
|
|
26
|
-
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;P(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:Q,priority:0}),ul:()=>({conversion:Q,priority:0})}}static importJSON(a){let b=E(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}
|
|
27
|
-
0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{let d=z();q(b)?d.append(b):h.$isElementNode(b)?(b=h.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
27
|
+
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;P(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:Q,priority:0}),ul:()=>({conversion:Q,priority:0})}}static importJSON(a){let b=E(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(){let a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));"check"===this.__listType&&a.setAttribute("__lexicalListType","check");return{element:a}}exportJSON(){return{...super.exportJSON(),
|
|
28
|
+
listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{let d=z();q(b)?d.append(b):h.$isElementNode(b)?(b=h.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
28
29
|
function P(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let l=f[`${c.__tag}Depth`]||[];b=n(c)-1;let x=b%l.length;var g=l[x];let y=f[c.__tag],B;f=f.nested;void 0!==f&&f.list&&(B=f.list);void 0!==y&&d.push(y);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<l.length;g++)g!==x&&e.push(c.__tag+g);void 0!==B&&(c=B.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&k.removeClassNamesFromElement(a,...e);0<d.length&&k.addClassNamesToElement(a,...d)}
|
|
29
|
-
function R(a){let b=[];for(let c=0;c<a.length;c++){let d=a[c];p(d)?(b.push(d),d.getChildren().forEach(e=>{q(e)&&b.push(w(e))})):b.push(w(d))}return b}function Q(a){
|
|
30
|
+
function R(a){let b=[];for(let c=0;c<a.length;c++){let d=a[c];p(d)?(b.push(d),d.getChildren().forEach(e=>{q(e)&&b.push(w(e))})):b.push(w(d))}return b}function Q(a){let b=a.nodeName.toLowerCase(),c=null;"ol"===b?c=E("number"):"ul"===b&&(c=a instanceof HTMLElement&&"check"===a.getAttribute("__lexicallisttype")?E("check"):E("bullet"));return{after:R,node:c}}let O={ol:"number",ul:"bullet"};function E(a,b=1){return h.$applyNodeReplacement(new N(a,b))}function q(a){return a instanceof N}
|
|
30
31
|
let S=h.createCommand("INSERT_UNORDERED_LIST_COMMAND"),T=h.createCommand("INSERT_ORDERED_LIST_COMMAND"),U=h.createCommand("INSERT_CHECK_LIST_COMMAND"),V=h.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=z;exports.$createListNode=E;exports.$getListDepth=n;
|
|
31
32
|
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=r(a),c=a.getParent();q(c)||m(40);let d=c.getParent(),e;if(h.$isRootOrShadowRoot(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=z(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=E(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=z(),c.append(f),
|
|
32
33
|
e.insertAfter(c));b.forEach(g=>{g.remove();f.append(g)})}v(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=U;exports.INSERT_ORDERED_LIST_COMMAND=T;exports.INSERT_UNORDERED_LIST_COMMAND=S;exports.ListItemNode=J;exports.ListNode=N;exports.REMOVE_LIST_COMMAND=V;exports.indentList=function(){I("indent")};
|
package/LexicalListNode.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { DOMConversionMap, EditorConfig, ElementNode, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from 'lexical';
|
|
8
|
+
import { DOMConversionMap, DOMExportOutput, EditorConfig, ElementNode, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from 'lexical';
|
|
9
9
|
export declare type SerializedListNode = Spread<{
|
|
10
10
|
listType: ListType;
|
|
11
11
|
start: number;
|
|
@@ -33,6 +33,7 @@ export declare class ListNode extends ElementNode {
|
|
|
33
33
|
updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
34
34
|
static importDOM(): DOMConversionMap | null;
|
|
35
35
|
static importJSON(serializedNode: SerializedListNode): ListNode;
|
|
36
|
+
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
36
37
|
exportJSON(): SerializedListNode;
|
|
37
38
|
canBeEmpty(): false;
|
|
38
39
|
canIndent(): false;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.5",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.7.
|
|
14
|
+
"lexical": "0.7.5"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.7.
|
|
17
|
+
"@lexical/utils": "0.7.5"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|