@lexical/hashtag
Advanced tools
Comparing version 0.1.16 to 0.1.17
@@ -17,8 +17,6 @@ /** | ||
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement; | ||
setTextContent(text: string): TextNode; | ||
canInsertTextBefore(): boolean; | ||
canInsertTextAfter(): boolean; | ||
isTextEntity(): true; | ||
} | ||
export function $toggleHashtag(node: TextNode): TextNode; | ||
export function $createHashtagNode(text?: string): TextNode; | ||
export function $isHashtagNode(node: LexicalNode | null | undefined): boolean; |
@@ -39,34 +39,2 @@ /** | ||
setTextContent(text) { | ||
let targetNode = super.setTextContent(text); // Handle hashtags | ||
if (targetNode.getParent() !== null && !targetNode.isComposing()) { | ||
const indexOfHash = text.indexOf('#'); | ||
if (indexOfHash === -1 || targetNode.getTextContent() === '#') { | ||
targetNode = $toggleHashtag(targetNode); | ||
} else if (indexOfHash > 0) { | ||
[targetNode] = targetNode.splitText(indexOfHash); | ||
targetNode = $toggleHashtag(targetNode); | ||
} // Check for invalid characters | ||
if (lexical.$isTextNode(targetNode) && targetNode.isAttached()) { | ||
const targetTextContent = targetNode.getTextContent().slice(1); | ||
const indexOfInvalidChar = targetTextContent.search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/); | ||
if (indexOfInvalidChar === 0) { | ||
targetNode = $toggleHashtag(targetNode); | ||
} else if (indexOfInvalidChar > 0) { | ||
[, targetNode] = targetNode.splitText(indexOfInvalidChar + 1); | ||
targetNode = $toggleHashtag(targetNode); | ||
} | ||
} | ||
return targetNode; | ||
} | ||
return this; | ||
} | ||
canInsertTextBefore() { | ||
@@ -76,3 +44,3 @@ return false; | ||
canInsertTextAfter() { | ||
isTextEntity() { | ||
return true; | ||
@@ -82,8 +50,2 @@ } | ||
} | ||
function $toggleHashtag(node) { | ||
const text = node.getTextContent(); | ||
const replacement = !$isHashtagNode(node) ? $createHashtagNode(text) : lexical.$createTextNode(text); | ||
node.replace(replacement); | ||
return replacement; | ||
} | ||
function $createHashtagNode(text = '') { | ||
@@ -98,3 +60,2 @@ return new HashtagNode(text); | ||
exports.$isHashtagNode = $isHashtagNode; | ||
exports.$toggleHashtag = $toggleHashtag; | ||
exports.HashtagNode = HashtagNode; |
@@ -7,4 +7,2 @@ /** | ||
*/ | ||
var c=require("@lexical/utils"),d=require("lexical"); | ||
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.,\\\/#!$%\^&\*;:{}=\-`~()@]/), | ||
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; | ||
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; |
{ | ||
"name": "@lexical/hashtag", | ||
"author": { | ||
"name": "Dominic Gannaway", | ||
"email": "dg@domgan.com" | ||
}, | ||
"description": "This package contains the functionality for Lexical hashtags.", | ||
@@ -12,13 +8,12 @@ "keywords": [ | ||
"rich-text", | ||
"table", | ||
"hashtag" | ||
], | ||
"license": "MIT", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"main": "LexicalHashtag.js", | ||
"peerDependencies": { | ||
"lexical": "0.1.16" | ||
"lexical": "0.1.17" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.1.16" | ||
"@lexical/utils": "0.1.17" | ||
}, | ||
@@ -25,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8
2
5531
83
2
+ Added@lexical/list@0.1.17(transitive)
+ Added@lexical/table@0.1.17(transitive)
+ Added@lexical/utils@0.1.17(transitive)
+ Addedlexical@0.1.17(transitive)
- Removed@lexical/list@0.1.16(transitive)
- Removed@lexical/table@0.1.16(transitive)
- Removed@lexical/utils@0.1.16(transitive)
- Removedlexical@0.1.16(transitive)
Updated@lexical/utils@0.1.17