@lexical/mark 0.2.8 → 0.3.1

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/LexicalMark.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -15,7 +15,6 @@ var utils = require('@lexical/utils');
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
- *
19
18
  */
20
19
  class MarkNode extends lexical.ElementNode {
21
20
  static getType() {
@@ -26,6 +25,25 @@ class MarkNode extends lexical.ElementNode {
26
25
  return new MarkNode(Array.from(node.__ids), node.__key);
27
26
  }
28
27
 
28
+ static importDOM() {
29
+ return null;
30
+ }
31
+
32
+ static importJSON(serializedNode) {
33
+ const node = $createMarkNode(serializedNode.ids);
34
+ node.setFormat(serializedNode.format);
35
+ node.setIndent(serializedNode.indent);
36
+ node.setDirection(serializedNode.direction);
37
+ return node;
38
+ }
39
+
40
+ exportJSON() {
41
+ return { ...super.exportJSON(),
42
+ ids: this.getIDs(),
43
+ type: 'mark'
44
+ };
45
+ }
46
+
29
47
  constructor(ids, key) {
30
48
  super(key);
31
49
  this.__ids = ids || [];
@@ -76,33 +94,37 @@ class MarkNode extends lexical.ElementNode {
76
94
 
77
95
  getIDs() {
78
96
  const self = this.getLatest();
79
- return self.__ids;
97
+ return $isMarkNode(self) ? self.__ids : [];
80
98
  }
81
99
 
82
100
  addID(id) {
83
101
  const self = this.getWritable();
84
- const ids = self.__ids;
85
- self.__ids = ids;
86
102
 
87
- for (let i = 0; i < ids.length; i++) {
88
- // If we already have it, don't add again
89
- if (id === ids[i]) {
90
- return;
103
+ if ($isMarkNode(self)) {
104
+ const ids = self.__ids;
105
+ self.__ids = ids;
106
+
107
+ for (let i = 0; i < ids.length; i++) {
108
+ // If we already have it, don't add again
109
+ if (id === ids[i]) return;
91
110
  }
92
- }
93
111
 
94
- ids.push(id);
112
+ ids.push(id);
113
+ }
95
114
  }
96
115
 
97
116
  deleteID(id) {
98
117
  const self = this.getWritable();
99
- const ids = self.__ids;
100
- self.__ids = ids;
101
118
 
102
- for (let i = 0; i < ids.length; i++) {
103
- if (id === ids[i]) {
104
- ids.splice(i, 1);
105
- return;
119
+ if ($isMarkNode(self)) {
120
+ const ids = self.__ids;
121
+ self.__ids = ids;
122
+
123
+ for (let i = 0; i < ids.length; i++) {
124
+ if (id === ids[i]) {
125
+ ids.splice(i, 1);
126
+ return;
127
+ }
106
128
  }
107
129
  }
108
130
  }
@@ -167,7 +189,6 @@ function $isMarkNode(node) {
167
189
  * This source code is licensed under the MIT license found in the
168
190
  * LICENSE file in the root directory of this source tree.
169
191
  *
170
- *
171
192
  */
172
193
  function $unwrapMarkNode(node) {
173
194
  const children = node.getChildren();
@@ -4,10 +4,11 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var k=require("lexical"),m=require("@lexical/utils");
8
- class n extends k.ElementNode{static getType(){return"mark"}static clone(a){return new n(Array.from(a.__ids),a.__key)}constructor(a,b){super(b);this.__ids=a||[]}createDOM(a){const b=document.createElement("mark");m.addClassNamesToElement(b,a.theme.mark);1<this.__ids.length&&m.addClassNamesToElement(b,a.theme.markOverlap);return b}updateDOM(a,b,c){a=a.__ids.length;const e=this.__ids.length;c=c.theme.markOverlap;a!==e&&(1===a?2===e&&m.addClassNamesToElement(b,c):1===e&&m.removeClassNamesFromElement(b,
9
- c));return!1}hasID(a){const b=this.getIDs();for(let c=0;c<b.length;c++)if(a===b[c])return!0;return!1}getIDs(){return this.getLatest().__ids}addID(a){var b=this.getWritable();const c=b.__ids;b.__ids=c;for(b=0;b<c.length;b++)if(a===c[b])return;c.push(a)}deleteID(a){var b=this.getWritable();const c=b.__ids;b.__ids=c;for(b=0;b<c.length;b++)if(a===c[b]){c.splice(b,1);break}}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(k.$isElementNode(a)){const b=q(this.__ids);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,
10
- b,c){if(!k.$isRangeSelection(b)||"html"===c)return!1;const e=b.anchor,d=b.focus;a=e.getNode();c=d.getNode();b=b.isBackward()?e.offset-d.offset:d.offset-e.offset;return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b}excludeFromCopy(a){return"clone"!==a}}function q(a){return new n(a)}function r(a){return a instanceof n}exports.$createMarkNode=q;
11
- exports.$getMarkIDs=function(a,b){for(;null!==a;){if(r(a))return a.getIDs();if(k.$isTextNode(a)&&b===a.getTextContentSize()){const c=a.getNextSibling();if(r(c))return c.getIDs()}a=a.getParent()}return null};exports.$isMarkNode=r;exports.$unwrapMarkNode=function(a){const b=a.getChildren();let c=null;for(let e=0;e<b.length;e++){const d=b[e];null===c?a.insertBefore(d):c.insertAfter(d);c=d}a.remove()};
12
- exports.$wrapSelectionInMarkNode=function(a,b,c){const e=a.getNodes();var d=a.anchor.offset,g=a.focus.offset;a=e.length;const x=b?g:d;b=b?d:g;let p,h;for(d=0;d<a;d++){const l=e[d];if(k.$isElementNode(h)&&h.isParentOf(l))continue;g=0===d;const u=d===a-1;var f=void 0;if(k.$isTextNode(l)){const v=l.getTextContentSize(),w=g?x:0,t=u?b:v;if(0===w&&0===t)continue;f=l.splitText(w,t);f=1<f.length&&(3===f.length||g&&!u||t===v)?f[1]:f[0]}else k.$isElementNode(l)&&l.isInline()&&(f=l);void 0!==f?f&&f.is(p)||(g=
13
- f.getParent(),null!=g&&g.is(p)||(h=void 0),p=g,void 0===h&&(h=q([c]),f.insertBefore(h)),h.append(f)):h=p=void 0}};exports.MarkNode=n;
7
+ 'use strict';var k=require("lexical"),m=require("@lexical/utils");
8
+ class n extends k.ElementNode{static getType(){return"mark"}static clone(a){return new n(Array.from(a.__ids),a.__key)}static importDOM(){return null}static importJSON(a){let b=p(a.ids);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),ids:this.getIDs(),type:"mark"}}constructor(a,b){super(b);this.__ids=a||[]}createDOM(a){let b=document.createElement("mark");m.addClassNamesToElement(b,a.theme.mark);1<this.__ids.length&&m.addClassNamesToElement(b,
9
+ a.theme.markOverlap);return b}updateDOM(a,b,c){a=a.__ids.length;let e=this.__ids.length;c=c.theme.markOverlap;a!==e&&(1===a?2===e&&m.addClassNamesToElement(b,c):1===e&&m.removeClassNamesFromElement(b,c));return!1}hasID(a){let b=this.getIDs();for(let c=0;c<b.length;c++)if(a===b[c])return!0;return!1}getIDs(){let a=this.getLatest();return q(a)?a.__ids:[]}addID(a){var b=this.getWritable();if(q(b)){let c=b.__ids;b.__ids=c;for(b=0;b<c.length;b++)if(a===c[b])return;c.push(a)}}deleteID(a){var b=this.getWritable();
10
+ if(q(b)){let c=b.__ids;b.__ids=c;for(b=0;b<c.length;b++)if(a===c[b]){c.splice(b,1);break}}}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(k.$isElementNode(a)){let b=p(this.__ids);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b,c){if(!k.$isRangeSelection(b)||"html"===c)return!1;let e=b.anchor,d=b.focus;a=e.getNode();c=d.getNode();b=b.isBackward()?e.offset-d.offset:d.offset-
11
+ e.offset;return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b}excludeFromCopy(a){return"clone"!==a}}function p(a){return new n(a)}function q(a){return a instanceof n}exports.$createMarkNode=p;exports.$getMarkIDs=function(a,b){for(;null!==a;){if(q(a))return a.getIDs();if(k.$isTextNode(a)&&b===a.getTextContentSize()){let c=a.getNextSibling();if(q(c))return c.getIDs()}a=a.getParent()}return null};exports.$isMarkNode=q;
12
+ exports.$unwrapMarkNode=function(a){let b=a.getChildren(),c=null;for(let e=0;e<b.length;e++){let d=b[e];null===c?a.insertBefore(d):c.insertAfter(d);c=d}a.remove()};
13
+ exports.$wrapSelectionInMarkNode=function(a,b,c){let e=a.getNodes();var d=a.anchor.offset,g=a.focus.offset;a=e.length;let x=b?g:d;b=b?d:g;let r,h;for(d=0;d<a;d++){let l=e[d];if(k.$isElementNode(h)&&h.isParentOf(l))continue;g=0===d;let u=d===a-1;var f=void 0;if(k.$isTextNode(l)){let v=l.getTextContentSize(),w=g?x:0,t=u?b:v;if(0===w&&0===t)continue;f=l.splitText(w,t);f=1<f.length&&(3===f.length||g&&!u||t===v)?f[1]:f[0]}else k.$isElementNode(l)&&l.isInline()&&(f=l);void 0!==f?f&&f.is(r)||(g=f.getParent(),
14
+ null!=g&&g.is(r)||(h=void 0),r=g,void 0===h&&(h=p([c]),f.insertBefore(h)),h.append(f)):h=r=void 0}};exports.MarkNode=n
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "mark"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.2.8",
11
+ "version": "0.3.1",
12
12
  "main": "LexicalMark.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.8"
14
+ "lexical": "0.3.1"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.8"
17
+ "@lexical/utils": "0.3.1"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",