@lexical/list 0.1.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Dominic Gannaway
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LexicalList.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';var f=require("lexical"),k=require("@lexical/list");function n(c,...a){a.forEach(b=>{null!=b&&"string"===typeof b&&c.classList.add(...b.split(" "))})}function p(c,...a){a.forEach(b=>{c.classList.remove(...b.split(" "))})}function r(c){throw Error(`Minified Lexical error #${c}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
2
+ function t(c){c=c.getParent();k.$isListNode(c)||r(2);let a=c;for(;null!==a;)a=a.getParent(),k.$isListNode(a)&&(c=a);return c}function u(c){let a=[];c=c.getChildren().filter(k.$isListItemNode);for(let b=0;b<c.length;b++){const d=c[b],e=d.getFirstChild();k.$isListNode(e)?a=a.concat(u(e)):a.push(d)}return a}function v(c){return k.$isListItemNode(c)&&k.$isListNode(c.getFirstChild())}
3
+ class w extends f.ElementNode{static getType(){return"list"}static clone(c){return new w(c.__tag,c.__start,c.__key)}constructor(c,a,b){super(b);this.__tag=c;this.__start=a}getTag(){return this.__tag}createDOM(c){const a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));x(a,c.theme,this);return a}updateDOM(c,a,b){if(c.__tag!==this.__tag)return!0;x(a,b.theme,this);return!1}canBeEmpty(){return!1}append(...c){for(let b=0;b<c.length;b++){var a=c[b];if(k.$isListItemNode(a))super.append(a);
4
+ else{const d=k.$createListItemNode();y(a)?d.append(a):(a=f.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
5
+ function x(c,a,b){const d=[],e=[];a=a.list;if(void 0!==a){a:{var g=1;for(var h=b.getParent();null!=h;){if(k.$isListItemNode(h)){h=h.getParent();if(k.$isListNode(h)){g++;h=h.getParent();continue}r(2)}break a}}h=g%5;const l=a[b.__tag+(0===h?5:h)],m=a[b.__tag];let q;a=a.nested;void 0!==a&&a.list&&(q=a.list);void 0!==m&&d.push(m);if(void 0!==l)for(a=l.split(" "),d.push(...a),a=1;6>a;a++)a!==h&&e.push(b.__tag+a);void 0!==q&&(b=q.split(" "),1<g?d.push(...b):e.push(...b))}0<d.length&&n(c,...d);0<e.length&&
6
+ p(c,...e)}function y(c){return c instanceof w}
7
+ class z extends f.ElementNode{static getType(){return"listitem"}static clone(c){return new z(c.__key)}constructor(c){super(c)}createDOM(c){const a=document.createElement("li");a.value=A(this);B(a,c.theme,this);return a}updateDOM(c,a,b){a.value=A(this);B(a,b.theme,this);return!1}append(...c){for(let a=0;a<c.length;a++){const b=c[a];if(f.$isElementNode(b)&&this.canMergeWith(b)){const d=b.getChildren();this.append(...d);b.remove()}else super.append(b)}return this}replace(c){if(C(c))return super.replace(c);const a=
8
+ this.getParentOrThrow();if(k.$isListNode(a)){var b=a.__children;const e=b.length;var d=b.indexOf(this.__key);if(0===d)a.insertBefore(c);else if(d===e-1)a.insertAfter(c);else{b=k.$createListNode(a.__tag);const g=a.getChildren();for(d+=1;d<e;d++)b.append(g[d]);a.insertAfter(c);c.insertAfter(b)}this.remove();1===e&&a.remove()}return c}insertAfter(c){var a=this.getNextSiblings();if(C(c))return a.forEach(d=>d.markDirty()),super.insertAfter(c);var b=this.getParentOrThrow();k.$isListNode(b)||r(1);if(k.$isListNode(c)&&
9
+ c.getTag()===b.getTag()){a=c;c=c.getChildren();for(b=c.length-1;0<=b;b--)a=c[b],this.insertAfter(a);return a}b.insertAfter(c);if(0!==a.length){const d=k.$createListNode(b.getTag());a.forEach(e=>d.append(e));c.insertAfter(d)}return c}insertNewAfter(){var c=this.getNextSibling(),a=this.getPreviousSibling(),b=t(this);var d=!0;var e=this.getFirstChild();if(k.$isListNode(e))d=!1;else for(e=this;null!==e;)k.$isListItemNode(e)&&0<e.getNextSiblings().length&&(d=!1),e=e.getParent();if(f.$isElementNode(b)&&
10
+ ""===this.getTextContent()&&(null===a||null===c)&&d){null===c?(c=f.$createParagraphNode(),b.insertAfter(c)):(c=f.$createParagraphNode(),b.insertBefore(c));for(b=this;null==b.getNextSibling()&&null==b.getPreviousSibling();){a=b.getParent();if(null==a||!C(b)&&!k.$isListNode(b))break;b=a}b.remove()}else c=D(),this.insertAfter(c);return c}collapseAtStart(c){const a=f.$createParagraphNode();this.getChildren().forEach(g=>a.append(g));var b=this.getParentOrThrow(),d=b.getParentOrThrow();const e=C(d);1===
11
+ b.getChildrenSize()?e?(b.remove(),d.select()):(b.replace(a),b=c.anchor,c=c.focus,d=a.getKey(),"element"===b.type&&b.getNode().is(this)&&b.set(d,b.offset,"element"),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element")):(b.insertBefore(a),this.remove());return!0}getIndent(){let c=this.getParentOrThrow().getParentOrThrow(),a=0;for(;C(c);)c=c.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(){return this}insertBefore(c){const a=this.getNextSiblings();C(c)&&a.forEach(b=>b.markDirty());
12
+ return super.insertBefore(c)}canInsertAfter(c){return C(c)}canReplaceWith(c){return C(c)}canMergeWith(c){return f.$isParagraphNode(c)||C(c)}}function A(c){var a=c.getParent();let b=1;null!=a&&(k.$isListNode(a)?b=a.__start:r(47));c=c.getPreviousSiblings();for(a=0;a<c.length;a++){const d=c[a];C(d)&&!k.$isListNode(d.getFirstChild())&&b++}return b}
13
+ function B(c,a,b){const d=[],e=[],g=(a=a.list)?a.listitem:void 0;if(a&&a.nested)var h=a.nested.listitem;void 0!==g&&(a=g.split(" "),d.push(...a));void 0!==h&&(h=h.split(" "),b.getChildren().some(l=>k.$isListNode(l))?d.push(...h):e.push(...h));0<d.length&&n(c,...d);0<e.length&&p(c,...e)}function D(){return new z}function C(c){return c instanceof z}function E(c,a){for(;null!=c&&!(c instanceof a);)c=c.getParent();return c}
14
+ function F(c,a){if(k.$isListNode(c))return c;const b=c.getPreviousSibling(),d=c.getNextSibling(),e=k.$createListItemNode();if(k.$isListNode(b)&&a===b.getTag())return e.append(c),b.append(e),k.$isListNode(d)&&a===d.getTag()&&(b.append(...d.getChildren()),d.remove()),b;if(k.$isListNode(d)&&a===d.getTag())return e.append(c),d.getFirstChildOrThrow().insertBefore(e),d;a=k.$createListNode(a);a.append(e);c.replace(a);e.append(c);return a}
15
+ function G(c){c.forEach(a=>{if(!v(a)){var b=a.getParent(),d=a.getNextSibling(),e=a.getPreviousSibling();if(v(d)&&v(e))e=e.getFirstChild(),k.$isListNode(e)&&(e.append(a),a=d.getFirstChild(),k.$isListNode(a)&&(d=a.getChildren(),e.append(...d),a.remove()),e.getChildren().forEach(g=>g.markDirty()));else if(v(d))d=d.getFirstChild(),k.$isListNode(d)&&(e=d.getFirstChild(),null!==e&&e.insertBefore(a),d.getChildren().forEach(g=>g.markDirty()));else if(v(e))d=e.getFirstChild(),k.$isListNode(d)&&(d.append(a),
16
+ d.getChildren().forEach(g=>g.markDirty()));else if(k.$isListNode(b)){const g=k.$createListItemNode(),h=k.$createListNode(b.getTag());g.append(h);h.append(a);e?e.insertAfter(g):d?d.insertBefore(g):b.append(g)}k.$isListNode(b)&&b.getChildren().forEach(g=>g.markDirty())}})}
17
+ function H(c){c.forEach(a=>{if(!v(a)){var b=a.getParent(),d=b?b.getParent():void 0,e=d?d.getParent():void 0;if(k.$isListNode(e)&&k.$isListItemNode(d)&&k.$isListNode(b)){var g=b?b.getFirstChild():void 0,h=b?b.getLastChild():void 0;if(a.is(g))d.insertBefore(a),b.isEmpty()&&d.remove();else if(a.is(h))d.insertAfter(a),b.isEmpty()&&d.remove();else{var l=b.getTag();g=k.$createListItemNode();const m=k.$createListNode(l);g.append(m);a.getPreviousSiblings().forEach(q=>m.append(q));h=k.$createListItemNode();
18
+ l=k.$createListNode(l);h.append(l);l.append(...a.getNextSiblings());d.insertBefore(g);d.insertAfter(h);d.replace(a)}b.getChildren().forEach(m=>m.markDirty());e.getChildren().forEach(m=>m.markDirty())}}})}
19
+ function I(c){var a=f.$getSelection();if(null===a)return!1;var b=a.getNodes(),d=[];0===b.length&&b.push(a.anchor.getNode());if(1===b.length){a:{for(b=b[0];null!==b;){if(k.$isListItemNode(b))break a;b=b.getParent()}b=null}null!==b&&(d=[b])}else{d=new Set;for(a=0;a<b.length;a++){const e=b[a];k.$isListItemNode(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===c?G(d):H(d),!0):!1}exports.$createListItemNode=D;exports.$createListNode=function(c,a=1){return new w(c,a)};exports.$isListItemNode=C;
20
+ exports.$isListNode=y;exports.ListItemNode=z;exports.ListNode=w;exports.indentList=function(){return I("indent")};
21
+ exports.insertList=function(c,a){c.update(()=>{f.$log("formatList");var b=f.$getSelection();if(null!==b){var d=b.getNodes();b=b.anchor.getNode();var e=b.getParent();if(0===d.length)d=k.$createListNode(a),f.$isRootNode(e)?(b.replace(d),b=k.$createListItemNode(),d.append(b)):k.$isListItemNode(b)&&(b=b.getParentOrThrow(),d.append(...b.getChildren()),b.replace(d));else for(b=new Set,e=0;e<d.length;e++){var g=d[e];if(f.$isElementNode(g)&&g.isEmpty()&&!b.has(g.getKey()))F(g,a);else if(f.$isLeafNode(g))for(g=
22
+ g.getParent();null!=g;){const l=g.getKey();if(k.$isListNode(g)){if(!b.has(l)){var h=k.$createListNode(a);h.append(...g.getChildren());g.replace(h);b.add(l)}break}else{h=g.getParent();if(f.$isRootNode(h)&&!b.has(l)){b.add(l);F(g,a);break}g=h}}}}})};exports.outdentList=function(){return I("outdent")};
23
+ exports.removeList=function(c){c.update(()=>{f.$log("removeList");var a=f.$getSelection();if(null!==a){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&k.$isListItemNode(a))d.add(t(a));else for(a=0;a<e.length;a++){var b=e[a];f.$isLeafNode(b)&&(b=E(b,k.ListItemNode),null!=b&&d.add(t(b)))}d.forEach(g=>{let h=g;u(g).forEach(l=>{if(null!=l){const m=f.$createParagraphNode();m.append(...l.getChildren());h.insertAfter(m);h=m;l.remove()}});g.remove()})}})};
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@lexical/list`
2
+
3
+ This package contains the functionality for the List feature of Lexical.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@lexical/list",
3
+ "author": {
4
+ "name": "Dominic Gannaway",
5
+ "email": "dg@domgan.com"
6
+ },
7
+ "description": "This package provides the list feature for Lexical.",
8
+ "keywords": [
9
+ "lexical",
10
+ "editor",
11
+ "rich-text",
12
+ "list"
13
+ ],
14
+ "license": "MIT",
15
+ "version": "0.1.7",
16
+ "main": "LexicalList.js",
17
+ "peerDependencies": {
18
+ "lexical": "0.1.7"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/facebook/lexical",
23
+ "directory": "packages/lexical-list"
24
+ }
25
+ }