@lexical/hashtag 0.13.1 → 0.14.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.
@@ -0,0 +1,74 @@
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
+ import { addClassNamesToElement } from '@lexical/utils';
8
+ import { TextNode, $applyNodeReplacement } from 'lexical';
9
+
10
+ /**
11
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
12
+ *
13
+ * This source code is licensed under the MIT license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ /** @noInheritDoc */
19
+ class HashtagNode extends TextNode {
20
+ static getType() {
21
+ return 'hashtag';
22
+ }
23
+ static clone(node) {
24
+ return new HashtagNode(node.__text, node.__key);
25
+ }
26
+ constructor(text, key) {
27
+ super(text, key);
28
+ }
29
+ createDOM(config) {
30
+ const element = super.createDOM(config);
31
+ addClassNamesToElement(element, config.theme.hashtag);
32
+ return element;
33
+ }
34
+ static importJSON(serializedNode) {
35
+ const node = $createHashtagNode(serializedNode.text);
36
+ node.setFormat(serializedNode.format);
37
+ node.setDetail(serializedNode.detail);
38
+ node.setMode(serializedNode.mode);
39
+ node.setStyle(serializedNode.style);
40
+ return node;
41
+ }
42
+ exportJSON() {
43
+ return {
44
+ ...super.exportJSON(),
45
+ type: 'hashtag'
46
+ };
47
+ }
48
+ canInsertTextBefore() {
49
+ return false;
50
+ }
51
+ isTextEntity() {
52
+ return true;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Generates a HashtagNode, which is a string following the format of a # followed by some text, eg. #lexical.
58
+ * @param text - The text used inside the HashtagNode.
59
+ * @returns - The HashtagNode with the embedded text.
60
+ */
61
+ function $createHashtagNode(text = '') {
62
+ return $applyNodeReplacement(new HashtagNode(text));
63
+ }
64
+
65
+ /**
66
+ * Determines if node is a HashtagNode.
67
+ * @param node - The node to be checked.
68
+ * @returns true if node is a HashtagNode, false otherwise.
69
+ */
70
+ function $isHashtagNode(node) {
71
+ return node instanceof HashtagNode;
72
+ }
73
+
74
+ export { $createHashtagNode, $isHashtagNode, HashtagNode };
@@ -0,0 +1,12 @@
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
+ import * as modDev from './LexicalHashtag.dev.esm.js';
8
+ import * as modProd from './LexicalHashtag.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const $createHashtagNode = mod.$createHashtagNode;
11
+ export const $isHashtagNode = mod.$isHashtagNode;
12
+ export const HashtagNode = mod.HashtagNode;
package/LexicalHashtag.js CHANGED
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalHashtag = process.env.NODE_ENV === 'development' ? require('./LexicalHashtag.dev.js') : require('./LexicalHashtag.prod.js')
8
+ const LexicalHashtag = process.env.NODE_ENV === 'development' ? require('./LexicalHashtag.dev.js') : require('./LexicalHashtag.prod.js');
9
9
  module.exports = LexicalHashtag;
@@ -0,0 +1,7 @@
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
+ import{addClassNamesToElement as t}from"@lexical/utils";import{TextNode as e,$applyNodeReplacement as r}from"lexical";class n extends e{static getType(){return"hashtag"}static clone(t){return new n(t.__text,t.__key)}constructor(t,e){super(t,e)}createDOM(e){const r=super.createDOM(e);return t(r,e.theme.hashtag),r}static importJSON(t){const e=s(t.text);return e.setFormat(t.format),e.setDetail(t.detail),e.setMode(t.mode),e.setStyle(t.style),e}exportJSON(){return{...super.exportJSON(),type:"hashtag"}}canInsertTextBefore(){return!1}isTextEntity(){return!0}}function s(t=""){return r(new n(t))}function o(t){return t instanceof n}export{s as $createHashtagNode,o as $isHashtagNode,n as HashtagNode};
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # `@lexical/hashtag`
2
2
 
3
+ [![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_hashtag)
4
+
3
5
  This package contains the functionality for Lexical hashtags.
4
6
 
5
7
  More documentation coming soon.
package/package.json CHANGED
@@ -8,17 +8,19 @@
8
8
  "hashtag"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.13.1",
11
+ "version": "0.14.0",
12
12
  "main": "LexicalHashtag.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.13.1"
14
+ "lexical": "0.14.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.13.1"
17
+ "@lexical/utils": "0.14.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
21
  "url": "https://github.com/facebook/lexical",
22
22
  "directory": "packages/lexical-hashtag"
23
- }
23
+ },
24
+ "module": "LexicalHashtag.esm.js",
25
+ "sideEffects": false
24
26
  }