@lexical/hashtag 0.1.16 → 0.1.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dominic Gannaway
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -14,10 +14,8 @@ export declare class HashtagNode extends TextNode {
14
14
  clone(node: HashtagNode): HashtagNode;
15
15
  constructor(text: string, key?: NodeKey);
16
16
  createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
17
- setTextContent(text: string): TextNode;
18
17
  canInsertTextBefore(): boolean;
19
- canInsertTextAfter(): boolean;
18
+ isTextEntity(): true;
20
19
  }
21
- export function $toggleHashtag(node: TextNode): TextNode;
22
20
  export function $createHashtagNode(text?: string): TextNode;
23
21
  export function $isHashtagNode(node: LexicalNode | null | undefined): boolean;
@@ -36,53 +36,15 @@ class HashtagNode extends lexical.TextNode {
36
36
  return element;
37
37
  }
38
38
 
39
- setTextContent(text) {
40
- let targetNode = super.setTextContent(text); // Handle hashtags
41
-
42
- if (targetNode.getParent() !== null && !targetNode.isComposing()) {
43
- const indexOfHash = text.indexOf('#');
44
-
45
- if (indexOfHash === -1 || targetNode.getTextContent() === '#') {
46
- targetNode = $toggleHashtag(targetNode);
47
- } else if (indexOfHash > 0) {
48
- [targetNode] = targetNode.splitText(indexOfHash);
49
- targetNode = $toggleHashtag(targetNode);
50
- } // Check for invalid characters
51
-
52
-
53
- if (lexical.$isTextNode(targetNode) && targetNode.isAttached()) {
54
- const targetTextContent = targetNode.getTextContent().slice(1);
55
- const indexOfInvalidChar = targetTextContent.search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/);
56
-
57
- if (indexOfInvalidChar === 0) {
58
- targetNode = $toggleHashtag(targetNode);
59
- } else if (indexOfInvalidChar > 0) {
60
- [, targetNode] = targetNode.splitText(indexOfInvalidChar + 1);
61
- targetNode = $toggleHashtag(targetNode);
62
- }
63
- }
64
-
65
- return targetNode;
66
- }
67
-
68
- return this;
69
- }
70
-
71
39
  canInsertTextBefore() {
72
40
  return false;
73
41
  }
74
42
 
75
- canInsertTextAfter() {
43
+ isTextEntity() {
76
44
  return true;
77
45
  }
78
46
 
79
47
  }
80
- function $toggleHashtag(node) {
81
- const text = node.getTextContent();
82
- const replacement = !$isHashtagNode(node) ? $createHashtagNode(text) : lexical.$createTextNode(text);
83
- node.replace(replacement);
84
- return replacement;
85
- }
86
48
  function $createHashtagNode(text = '') {
87
49
  return new HashtagNode(text);
88
50
  }
@@ -92,5 +54,4 @@ function $isHashtagNode(node) {
92
54
 
93
55
  exports.$createHashtagNode = $createHashtagNode;
94
56
  exports.$isHashtagNode = $isHashtagNode;
95
- exports.$toggleHashtag = $toggleHashtag;
96
57
  exports.HashtagNode = HashtagNode;
@@ -0,0 +1,25 @@
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
+ * @flow strict
8
+ */
9
+
10
+ import type {EditorConfig, LexicalNode, NodeKey} from 'lexical';
11
+
12
+ import {TextNode} from 'lexical';
13
+
14
+ declare export class HashtagNode extends TextNode {
15
+ static getType(): string;
16
+ static clone(node: HashtagNode): HashtagNode;
17
+ constructor(text: string, key?: NodeKey): void;
18
+ createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
19
+ canInsertTextBefore(): boolean;
20
+ isTextEntity(): true;
21
+ }
22
+ declare export function $createHashtagNode(text?: string): HashtagNode;
23
+ declare export function $isHashtagNode(
24
+ node: ?LexicalNode,
25
+ ): boolean %checks(node instanceof HashtagNode);
@@ -4,6 +4,4 @@
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 c=require("@lexical/utils"),d=require("lexical");
8
- class e extends d.TextNode{static getType(){return"hashtag"}static clone(b){return new e(b.__text,b.__key)}constructor(b,a){super(b,a)}createDOM(b){const a=super.createDOM(b);c.addClassNamesToElement(a,b.theme.hashtag);return a}setTextContent(b){let a=super.setTextContent(b);return null===a.getParent()||a.isComposing()?this:(b=b.indexOf("#"),-1===b||"#"===a.getTextContent()?a=f(a):0<b&&([a]=a.splitText(b),a=f(a)),d.$isTextNode(a)&&a.isAttached()&&(b=a.getTextContent().slice(1).search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/),
9
- 0===b?a=f(a):0<b&&([,a]=a.splitText(b+1),a=f(a))),a)}canInsertTextBefore(){return!1}canInsertTextAfter(){return!0}}function f(b){var a=b.getTextContent();a=g(b)?d.$createTextNode(a):h(a);b.replace(a);return a}function h(b=""){return new e(b)}function g(b){return b instanceof e}exports.$createHashtagNode=h;exports.$isHashtagNode=g;exports.$toggleHashtag=f;exports.HashtagNode=e;
7
+ var b=require("@lexical/utils"),d=require("lexical");class e extends d.TextNode{static getType(){return"hashtag"}static clone(a){return new e(a.__text,a.__key)}constructor(a,c){super(a,c)}createDOM(a){const c=super.createDOM(a);b.addClassNamesToElement(c,a.theme.hashtag);return c}canInsertTextBefore(){return!1}isTextEntity(){return!0}}exports.$createHashtagNode=function(a=""){return new e(a)};exports.$isHashtagNode=function(a){return a instanceof e};exports.HashtagNode=e;
package/package.json CHANGED
@@ -1,25 +1,20 @@
1
1
  {
2
2
  "name": "@lexical/hashtag",
3
- "author": {
4
- "name": "Dominic Gannaway",
5
- "email": "dg@domgan.com"
6
- },
7
3
  "description": "This package contains the functionality for Lexical hashtags.",
8
4
  "keywords": [
9
5
  "lexical",
10
6
  "editor",
11
7
  "rich-text",
12
- "table",
13
8
  "hashtag"
14
9
  ],
15
10
  "license": "MIT",
16
- "version": "0.1.16",
11
+ "version": "0.1.17",
17
12
  "main": "LexicalHashtag.js",
18
13
  "peerDependencies": {
19
- "lexical": "0.1.16"
14
+ "lexical": "0.1.17"
20
15
  },
21
16
  "dependencies": {
22
- "@lexical/utils": "0.1.16"
17
+ "@lexical/utils": "0.1.17"
23
18
  },
24
19
  "repository": {
25
20
  "type": "git",