@lexical/mark 0.2.7 → 0.3.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/LexicalMark.d.ts +5 -3
- package/LexicalMark.dev.js +38 -17
- package/LexicalMark.prod.js +8 -7
- package/package.json +3 -3
package/LexicalMark.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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.
|
|
@@ -10,7 +10,7 @@ import {ElementNode, LexicalNode} from 'lexical';
|
|
|
10
10
|
export declare class MarkNode extends ElementNode {
|
|
11
11
|
__ids: Array<string>;
|
|
12
12
|
clone(node: MarkNode): MarkNode;
|
|
13
|
-
constructor(ids: Array<string>, key?: NodeKey)
|
|
13
|
+
constructor(ids: Array<string>, key?: NodeKey);
|
|
14
14
|
hasID(id: string): boolean;
|
|
15
15
|
getIDs(): Array<string>;
|
|
16
16
|
addID(id: string): void;
|
|
@@ -19,7 +19,9 @@ export declare class MarkNode extends ElementNode {
|
|
|
19
19
|
canInsertTextAfter(): false;
|
|
20
20
|
isInline(): true;
|
|
21
21
|
}
|
|
22
|
-
export function $isMarkNode(
|
|
22
|
+
export function $isMarkNode(
|
|
23
|
+
node: LexicalNode | null | undefined,
|
|
24
|
+
): node is MarkNode;
|
|
23
25
|
export function $createMarkNode(ids: Array<string>): MarkNode;
|
|
24
26
|
export function $getMarkIDs(
|
|
25
27
|
node: TextNode,
|
package/LexicalMark.dev.js
CHANGED
|
@@ -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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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();
|
package/LexicalMark.prod.js
CHANGED
|
@@ -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){
|
|
9
|
-
c));return!1}hasID(a){
|
|
10
|
-
b,c){if(!k.$isRangeSelection(b)||"html"===c)return!1;
|
|
11
|
-
exports.$getMarkIDs=function(a,b){for(;null!==a;){if(
|
|
12
|
-
exports.$
|
|
13
|
-
|
|
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.
|
|
11
|
+
"version": "0.3.0",
|
|
12
12
|
"main": "LexicalMark.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.3.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.3.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|