@lexical/mark 0.3.2 → 0.3.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.
@@ -40,7 +40,8 @@ class MarkNode extends lexical.ElementNode {
40
40
  exportJSON() {
41
41
  return { ...super.exportJSON(),
42
42
  ids: this.getIDs(),
43
- type: 'mark'
43
+ type: 'mark',
44
+ version: 1
44
45
  };
45
46
  }
46
47
 
@@ -5,10 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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;
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",version:1}}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&&
9
+ m.addClassNamesToElement(b,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=
10
+ this.getWritable();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-
11
+ d.offset:d.offset-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
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
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
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/MarkNode.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { EditorConfig, GridSelection, LexicalNode, NodeKey, NodeSelection, RangeSelection, SerializedElementNode, Spread } from 'lexical';
9
+ import { ElementNode } from 'lexical';
10
+ export declare type SerializedMarkNode = Spread<{
11
+ ids: Array<string>;
12
+ type: 'mark';
13
+ version: 1;
14
+ }, SerializedElementNode>;
15
+ export declare class MarkNode extends ElementNode {
16
+ __ids: Array<string>;
17
+ static getType(): string;
18
+ static clone(node: MarkNode): MarkNode;
19
+ static importDOM(): null;
20
+ static importJSON(serializedNode: SerializedMarkNode): MarkNode;
21
+ exportJSON(): SerializedMarkNode;
22
+ constructor(ids: Array<string>, key?: NodeKey);
23
+ createDOM(config: EditorConfig): HTMLElement;
24
+ updateDOM(prevNode: MarkNode, element: HTMLElement, config: EditorConfig): boolean;
25
+ hasID(id: string): boolean;
26
+ getIDs(): Array<string>;
27
+ addID(id: string): void;
28
+ deleteID(id: string): void;
29
+ insertNewAfter(selection: RangeSelection): null | ElementNode;
30
+ canInsertTextBefore(): false;
31
+ canInsertTextAfter(): false;
32
+ canBeEmpty(): false;
33
+ isInline(): true;
34
+ extractWithChild(child: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection, destination: 'clone' | 'html'): boolean;
35
+ excludeFromCopy(destination: 'clone' | 'html'): boolean;
36
+ }
37
+ export declare function $createMarkNode(ids: Array<string>): MarkNode;
38
+ export declare function $isMarkNode(node: LexicalNode | null): node is MarkNode;
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { RangeSelection, TextNode } from 'lexical';
9
+ import { $createMarkNode, $isMarkNode, MarkNode } from './MarkNode';
10
+ export declare function $unwrapMarkNode(node: MarkNode): void;
11
+ export declare function $wrapSelectionInMarkNode(selection: RangeSelection, isBackward: boolean, id: string): void;
12
+ export declare function $getMarkIDs(node: TextNode, offset: number): null | Array<string>;
13
+ export { $createMarkNode, $isMarkNode, MarkNode };
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "mark"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.2",
11
+ "version": "0.3.5",
12
12
  "main": "LexicalMark.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.2"
14
+ "lexical": "0.3.5"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.2"
17
+ "@lexical/utils": "0.3.5"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
package/LexicalMark.d.ts DELETED
@@ -1,35 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import type {NodeKey, RangeSelection, TextNode} from 'lexical';
9
- import {ElementNode, LexicalNode} from 'lexical';
10
- export declare class MarkNode extends ElementNode {
11
- __ids: Array<string>;
12
- clone(node: MarkNode): MarkNode;
13
- constructor(ids: Array<string>, key?: NodeKey);
14
- hasID(id: string): boolean;
15
- getIDs(): Array<string>;
16
- addID(id: string): void;
17
- deleteID(id: string): void;
18
- canInsertTextBefore(): false;
19
- canInsertTextAfter(): false;
20
- isInline(): true;
21
- }
22
- export function $isMarkNode(
23
- node: LexicalNode | null | undefined,
24
- ): node is MarkNode;
25
- export function $createMarkNode(ids: Array<string>): MarkNode;
26
- export function $getMarkIDs(
27
- node: TextNode,
28
- offset: number,
29
- ): null | Array<string>;
30
- export function $wrapSelectionInMarkNode(
31
- selection: RangeSelection,
32
- isBackward: boolean,
33
- id: string,
34
- ): void;
35
- export function $unwrapMarkNode(node: MarkNode): void;