@lexical/mark 0.5.1-next.1 → 0.6.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.dev.js +3 -2
- package/LexicalMark.js.flow +15 -1
- package/LexicalMark.prod.js +8 -8
- package/index.d.ts +1 -1
- package/package.json +3 -3
package/LexicalMark.dev.js
CHANGED
|
@@ -206,7 +206,7 @@ function $unwrapMarkNode(node) {
|
|
|
206
206
|
|
|
207
207
|
node.remove();
|
|
208
208
|
}
|
|
209
|
-
function $wrapSelectionInMarkNode(selection, isBackward, id) {
|
|
209
|
+
function $wrapSelectionInMarkNode(selection, isBackward, id, createNode) {
|
|
210
210
|
const nodes = selection.getNodes();
|
|
211
211
|
const anchorOffset = selection.anchor.offset;
|
|
212
212
|
const focusOffset = selection.focus.offset;
|
|
@@ -277,7 +277,8 @@ function $wrapSelectionInMarkNode(selection, isBackward, id) {
|
|
|
277
277
|
|
|
278
278
|
if (lastCreatedMarkNode === undefined) {
|
|
279
279
|
// If we don't have a created mark node, we can make one
|
|
280
|
-
|
|
280
|
+
const createMarkNode = createNode || $createMarkNode;
|
|
281
|
+
lastCreatedMarkNode = createMarkNode([id]);
|
|
281
282
|
targetNode.insertBefore(lastCreatedMarkNode);
|
|
282
283
|
} // Add the target node to be wrapped in the latest created mark node
|
|
283
284
|
|
package/LexicalMark.js.flow
CHANGED
|
@@ -7,9 +7,22 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
NodeKey,
|
|
12
|
+
RangeSelection,
|
|
13
|
+
TextNode,
|
|
14
|
+
SerializedElementNode,
|
|
15
|
+
} from 'lexical';
|
|
11
16
|
import {ElementNode, LexicalNode} from 'lexical';
|
|
12
17
|
|
|
18
|
+
export type SerializedMarkNode = {
|
|
19
|
+
...SerializedElementNode,
|
|
20
|
+
ids: Array<string>,
|
|
21
|
+
type: 'mark',
|
|
22
|
+
version: 1,
|
|
23
|
+
...
|
|
24
|
+
};
|
|
25
|
+
|
|
13
26
|
declare export class MarkNode extends ElementNode {
|
|
14
27
|
__ids: Array<string>;
|
|
15
28
|
|
|
@@ -40,6 +53,7 @@ declare export function $wrapSelectionInMarkNode(
|
|
|
40
53
|
selection: RangeSelection,
|
|
41
54
|
isBackward: boolean,
|
|
42
55
|
id: string,
|
|
56
|
+
createNode?: (ids: Array<string>) => MarkNode,
|
|
43
57
|
): void;
|
|
44
58
|
|
|
45
59
|
declare export function $unwrapMarkNode(node: MarkNode): void;
|
package/LexicalMark.prod.js
CHANGED
|
@@ -4,11 +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
|
-
'use strict';var
|
|
8
|
-
class
|
|
9
|
-
|
|
10
|
-
this.getWritable();if(
|
|
11
|
-
|
|
12
|
-
exports.$unwrapMarkNode=function(a){let b=a.getChildren(),c=null;for(let
|
|
13
|
-
exports.$wrapSelectionInMarkNode=function(a,b,c){let
|
|
14
|
-
(h=
|
|
7
|
+
'use strict';var m=require("lexical"),n=require("@lexical/utils");
|
|
8
|
+
class p extends m.ElementNode{static getType(){return"mark"}static clone(a){return new p(Array.from(a.__ids),a.__key)}static importDOM(){return null}static importJSON(a){let b=q(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",version:1}}constructor(a,b){super(b);this.__ids=a||[]}createDOM(a){let b=document.createElement("mark");n.addClassNamesToElement(b,a.theme.mark);1<this.__ids.length&&
|
|
9
|
+
n.addClassNamesToElement(b,a.theme.markOverlap);return b}updateDOM(a,b,c){a=a.__ids.length;let d=this.__ids.length;c=c.theme.markOverlap;a!==d&&(1===a?2===d&&n.addClassNamesToElement(b,c):1===d&&n.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 r(a)?a.__ids:[]}addID(a){var b=this.getWritable();if(r(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=
|
|
10
|
+
this.getWritable();if(r(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(m.$isElementNode(a)){let 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,b,c){if(!m.$isRangeSelection(b)||"html"===c)return!1;let d=b.anchor,g=b.focus;a=d.getNode();c=g.getNode();b=b.isBackward()?d.offset-
|
|
11
|
+
g.offset:g.offset-d.offset;return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b}excludeFromCopy(a){return"clone"!==a}}function q(a){return new p(a)}function r(a){return a instanceof p}exports.$createMarkNode=q;exports.$getMarkIDs=function(a,b){for(;null!==a;){if(r(a))return a.getIDs();if(m.$isTextNode(a)&&b===a.getTextContentSize()){let c=a.getNextSibling();if(r(c))return c.getIDs()}a=a.getParent()}return null};exports.$isMarkNode=r;
|
|
12
|
+
exports.$unwrapMarkNode=function(a){let b=a.getChildren(),c=null;for(let d=0;d<b.length;d++){let g=b[d];null===c?a.insertBefore(g):c.insertAfter(g);c=g}a.remove()};
|
|
13
|
+
exports.$wrapSelectionInMarkNode=function(a,b,c,d){let g=a.getNodes();var k=a.anchor.offset,h=a.focus.offset;a=g.length;let x=b?h:k;b=b?k:h;let t,l;for(k=0;k<a;k++){var e=g[k];if(m.$isElementNode(l)&&l.isParentOf(e))continue;h=0===k;let v=k===a-1;var f=null;if(m.$isTextNode(e)){f=e.getTextContentSize();let w=h?x:0,u=v?b:f;if(0===w&&0===u)continue;e=e.splitText(w,u);f=1<e.length&&(3===e.length||h&&!v||u===f)?e[1]:e[0]}else if(r(e))continue;else m.$isElementNode(e)&&e.isInline()&&(f=e);null!==f?f&&
|
|
14
|
+
f.is(t)||(h=f.getParent(),null!=h&&h.is(t)||(l=void 0),t=h,void 0===l&&(l=(d||q)([c]),f.insertBefore(l)),l.append(f)):l=t=void 0}};exports.MarkNode=p
|
package/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ import type { SerializedMarkNode } from './MarkNode';
|
|
|
10
10
|
import type { RangeSelection, TextNode } from 'lexical';
|
|
11
11
|
import { $createMarkNode, $isMarkNode, MarkNode } from './MarkNode';
|
|
12
12
|
export declare function $unwrapMarkNode(node: MarkNode): void;
|
|
13
|
-
export declare function $wrapSelectionInMarkNode(selection: RangeSelection, isBackward: boolean, id: string): void;
|
|
13
|
+
export declare function $wrapSelectionInMarkNode(selection: RangeSelection, isBackward: boolean, id: string, createNode?: (ids: Array<string>) => MarkNode): void;
|
|
14
14
|
export declare function $getMarkIDs(node: TextNode, offset: number): null | Array<string>;
|
|
15
15
|
export { $createMarkNode, $isMarkNode, MarkNode, SerializedMarkNode };
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"mark"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.6.0",
|
|
12
12
|
"main": "LexicalMark.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.6.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.6.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|