@lexical/dragon
Advanced tools
Comparing version 0.12.2 to 0.12.3
@@ -14,3 +14,2 @@ /** | ||
const origin = window.location.origin; | ||
const handler = event => { | ||
@@ -20,14 +19,9 @@ if (event.origin !== origin) { | ||
} | ||
const rootElement = editor.getRootElement(); | ||
if (document.activeElement !== rootElement) { | ||
return; | ||
} | ||
const data = event.data; | ||
if (typeof data === 'string') { | ||
let parsedData; | ||
try { | ||
@@ -38,14 +32,10 @@ parsedData = JSON.parse(data); | ||
} | ||
if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') { | ||
const payload = parsedData.payload; | ||
if (payload && payload.functionId === 'makeChanges') { | ||
const args = payload.args; | ||
if (args) { | ||
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow? | ||
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; | ||
editor.update(() => { | ||
const selection = lexical.$getSelection(); | ||
if (lexical.$isRangeSelection(selection)) { | ||
@@ -56,3 +46,2 @@ const anchor = selection.anchor; | ||
let setSelEnd = 0; | ||
if (lexical.$isTextNode(anchorNode)) { | ||
@@ -62,8 +51,7 @@ // set initial selection | ||
setSelStart = elementStart; | ||
setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end | ||
setSelEnd = elementStart + elementLength; | ||
// If the offset is more than the end, make it the end | ||
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd); | ||
} | ||
} | ||
if (setSelStart !== setSelEnd || text !== '') { | ||
@@ -73,3 +61,2 @@ selection.insertRawText(text); | ||
} | ||
if (lexical.$isTextNode(anchorNode)) { | ||
@@ -79,10 +66,10 @@ // set final selection | ||
setSelEnd = selStart + selLength; | ||
const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end | ||
const anchorNodeTextLength = anchorNode.getTextContentSize(); | ||
// If the offset is more than the end, make it the end | ||
setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart; | ||
setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd; | ||
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd); | ||
} // block the chrome extension from handling this event | ||
} | ||
// block the chrome extension from handling this event | ||
event.stopImmediatePropagation(); | ||
@@ -96,3 +83,2 @@ } | ||
}; | ||
window.addEventListener('message', handler, true); | ||
@@ -99,0 +85,0 @@ return () => { |
@@ -12,6 +12,6 @@ { | ||
"license": "MIT", | ||
"version": "0.12.2", | ||
"version": "0.12.3", | ||
"main": "LexicalDragon.js", | ||
"peerDependencies": { | ||
"lexical": "0.12.2" | ||
"lexical": "0.12.3" | ||
}, | ||
@@ -18,0 +18,0 @@ "repository": { |
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
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
108
7050