@lexical/clipboard
Advanced tools
Comparing version 0.12.2 to 0.12.3
@@ -21,2 +21,3 @@ /** | ||
*/ | ||
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'; | ||
@@ -31,4 +32,4 @@ | ||
*/ | ||
const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null; | ||
const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null; | ||
/** | ||
@@ -43,7 +44,4 @@ * Returns the *currently selected* Lexical content as an HTML string, relying on the | ||
*/ | ||
function $getHtmlContent(editor) { | ||
const selection = lexical.$getSelection(); | ||
if (selection == null) { | ||
@@ -53,11 +51,11 @@ { | ||
} | ||
} // If we haven't selected anything | ||
} | ||
// If we haven't selected anything | ||
if (lexical.$isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) { | ||
return ''; | ||
} | ||
return html.$generateHtmlFromNodes(editor, selection); | ||
} | ||
/** | ||
@@ -72,6 +70,4 @@ * Returns the *currently selected* Lexical content as a JSON string, relying on the | ||
*/ | ||
function $getLexicalContent(editor) { | ||
const selection = lexical.$getSelection(); | ||
if (selection == null) { | ||
@@ -81,11 +77,11 @@ { | ||
} | ||
} // If we haven't selected anything | ||
} | ||
// If we haven't selected anything | ||
if (lexical.$isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) { | ||
return null; | ||
} | ||
return JSON.stringify($generateJSONFromSelectedNodes(editor, selection)); | ||
} | ||
/** | ||
@@ -99,6 +95,4 @@ * Attempts to insert content of the mime-types text/plain or text/uri-list from | ||
*/ | ||
function $insertDataTransferForPlainText(dataTransfer, selection) { | ||
const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list'); | ||
if (text != null) { | ||
@@ -108,2 +102,3 @@ selection.insertRawText(text); | ||
} | ||
/** | ||
@@ -118,10 +113,7 @@ * Attempts to insert content of the mime-types application/x-lexical-editor, text/html, | ||
*/ | ||
function $insertDataTransferForRichText(dataTransfer, selection, editor) { | ||
const lexicalString = dataTransfer.getData('application/x-lexical-editor'); | ||
if (lexicalString) { | ||
try { | ||
const payload = JSON.parse(lexicalString); | ||
if (payload.namespace === editor._config.namespace && Array.isArray(payload.nodes)) { | ||
@@ -131,8 +123,7 @@ const nodes = $generateNodesFromSerializedNodes(payload.nodes); | ||
} | ||
} catch {// Fail silently. | ||
} catch (_unused) { | ||
// Fail silently. | ||
} | ||
} | ||
const htmlString = dataTransfer.getData('text/html'); | ||
if (htmlString) { | ||
@@ -144,19 +135,19 @@ try { | ||
return $insertGeneratedNodes(editor, nodes, selection); | ||
} catch {// Fail silently. | ||
} catch (_unused2) { | ||
// Fail silently. | ||
} | ||
} // Multi-line plain text in rich text mode pasted as separate paragraphs | ||
} | ||
// Multi-line plain text in rich text mode pasted as separate paragraphs | ||
// instead of single paragraph with linebreaks. | ||
// Webkit-specific: Supports read 'text/uri-list' in clipboard. | ||
const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list'); | ||
if (text != null) { | ||
if (lexical.$isRangeSelection(selection)) { | ||
const parts = text.split(/(\r?\n|\t)/); | ||
const partsLength = parts.length; | ||
for (let i = 0; i < partsLength; i++) { | ||
if (parts[parts.length - 1] === '') { | ||
parts.pop(); | ||
} | ||
for (let i = 0; i < parts.length; i++) { | ||
const part = parts[i]; | ||
if (part === '\n' || part === '\r\n') { | ||
@@ -175,2 +166,3 @@ selection.insertParagraph(); | ||
} | ||
/** | ||
@@ -186,6 +178,4 @@ * Inserts Lexical nodes into the editor using different strategies depending on | ||
*/ | ||
function $insertGeneratedNodes(editor, nodes, selection) { | ||
const isSelectionInsideOfGrid = lexical.DEPRECATED_$isGridSelection(selection) || utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n)) !== null && utils.$findMatchingParent(selection.focus.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n)) !== null; | ||
if (isSelectionInsideOfGrid && nodes.length === 1 && lexical.DEPRECATED_$isGridNode(nodes[0])) { | ||
@@ -195,7 +185,5 @@ $mergeGridNodesStrategy(nodes, selection, false, editor); | ||
} | ||
$basicInsertStrategy(nodes, selection); | ||
return; | ||
} | ||
function $basicInsertStrategy(nodes, selection) { | ||
@@ -205,13 +193,11 @@ // Wrap text and inline nodes in paragraph nodes so we have all blocks at the top-level | ||
let currentBlock = null; | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
const isLineBreakNode = lexical.$isLineBreakNode(node); | ||
if (isLineBreakNode || lexical.$isDecoratorNode(node) && node.isInline() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || node.isParentRequired()) { | ||
if (currentBlock === null) { | ||
currentBlock = node.createParentElementNode(); | ||
topLevelBlocks.push(currentBlock); // In the case of LineBreakNode, we just need to | ||
topLevelBlocks.push(currentBlock); | ||
// In the case of LineBreakNode, we just need to | ||
// add an empty ParagraphNode to the topLevelBlocks. | ||
if (isLineBreakNode) { | ||
@@ -221,3 +207,2 @@ continue; | ||
} | ||
if (currentBlock !== null) { | ||
@@ -231,3 +216,2 @@ currentBlock.append(node); | ||
} | ||
if (lexical.$isRangeSelection(selection)) { | ||
@@ -238,3 +222,2 @@ selection.insertNodes(topLevelBlocks); | ||
const anchorCell = selection.anchor.getNode(); | ||
if (!lexical.DEPRECATED_$isGridCellNode(anchorCell)) { | ||
@@ -245,7 +228,5 @@ { | ||
} | ||
anchorCell.append(...topLevelBlocks); | ||
} | ||
} | ||
function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) { | ||
@@ -257,3 +238,2 @@ if (nodes.length !== 1 || !lexical.DEPRECATED_$isGridNode(nodes[0])) { | ||
} | ||
const newGrid = nodes[0]; | ||
@@ -266,3 +246,2 @@ const newGridRows = newGrid.getChildren(); | ||
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical.DEPRECATED_$isGridNode(n)); | ||
if (!lexical.DEPRECATED_$isGridCellNode(gridCellNode) || !lexical.DEPRECATED_$isGridRowNode(gridRowNode) || !lexical.DEPRECATED_$isGridNode(gridNode)) { | ||
@@ -273,3 +252,2 @@ { | ||
} | ||
const startY = gridRowNode.getIndexWithinParent(); | ||
@@ -287,6 +265,4 @@ const stopY = Math.min(gridNode.getChildrenSize() - 1, startY + newRowCount - 1); | ||
let newFocusCellKey; | ||
for (let r = fromY; r <= toY; r++) { | ||
const currentGridRowNode = gridRowNodes[r]; | ||
if (!lexical.DEPRECATED_$isGridRowNode(currentGridRowNode)) { | ||
@@ -297,5 +273,3 @@ { | ||
} | ||
const newGridRowNode = newGridRows[newRowIdx]; | ||
if (!lexical.DEPRECATED_$isGridRowNode(newGridRowNode)) { | ||
@@ -306,10 +280,7 @@ { | ||
} | ||
const gridCellNodes = currentGridRowNode.getChildren(); | ||
const newGridCellNodes = newGridRowNode.getChildren(); | ||
let newColumnIdx = 0; | ||
for (let c = fromX; c <= toX; c++) { | ||
const currentGridCellNode = gridCellNodes[c]; | ||
if (!lexical.DEPRECATED_$isGridCellNode(currentGridCellNode)) { | ||
@@ -320,5 +291,3 @@ { | ||
} | ||
const newGridCellNode = newGridCellNodes[newColumnIdx]; | ||
if (!lexical.DEPRECATED_$isGridCellNode(newGridCellNode)) { | ||
@@ -329,3 +298,2 @@ { | ||
} | ||
if (r === fromY && c === fromX) { | ||
@@ -336,3 +304,2 @@ newAnchorCellKey = currentGridCellNode.getKey(); | ||
} | ||
const originalChildren = currentGridCellNode.getChildren(); | ||
@@ -351,6 +318,4 @@ newGridCellNode.getChildren().forEach(child => { | ||
} | ||
newRowIdx++; | ||
} | ||
if (newAnchorCellKey && newFocusCellKey) { | ||
@@ -363,7 +328,7 @@ const newGridSelection = lexical.DEPRECATED_$createGridSelection(); | ||
} | ||
function exportNodeToJSON(node) { | ||
const serializedNode = node.exportJSON(); | ||
const nodeClass = node.constructor; // @ts-expect-error TODO Replace Class utility type with InstanceType | ||
const nodeClass = node.constructor; | ||
// @ts-expect-error TODO Replace Class utility type with InstanceType | ||
if (serializedNode.type !== nodeClass.getType()) { | ||
@@ -373,7 +338,6 @@ { | ||
} | ||
} // @ts-expect-error TODO Replace Class utility type with InstanceType | ||
} | ||
// @ts-expect-error TODO Replace Class utility type with InstanceType | ||
const serializedChildren = serializedNode.children; | ||
if (lexical.$isElementNode(node)) { | ||
@@ -386,6 +350,4 @@ if (!Array.isArray(serializedChildren)) { | ||
} | ||
return serializedNode; | ||
} | ||
function $appendNodesToJSON(editor, selection$1, currentNode, targetArray = []) { | ||
@@ -395,3 +357,2 @@ let shouldInclude = selection$1 != null ? currentNode.isSelected(selection$1) : true; | ||
let target = currentNode; | ||
if (selection$1 !== null) { | ||
@@ -402,5 +363,6 @@ let clone = selection.$cloneWithProperties(currentNode); | ||
} | ||
const children = lexical.$isElementNode(target) ? target.getChildren() : []; | ||
const serializedNode = exportNodeToJSON(target); | ||
const children = lexical.$isElementNode(target) ? target.getChildren() : []; | ||
const serializedNode = exportNodeToJSON(target); // TODO: TextNode calls getTextContent() (NOT node.__text) within it's exportJSON method | ||
// TODO: TextNode calls getTextContent() (NOT node.__text) within it's exportJSON method | ||
// which uses getLatest() to get the text from the original node with the same key. | ||
@@ -411,8 +373,7 @@ // This is a deeper issue with the word "clone" here, it's still a reference to the | ||
// until then this hack will work for the selected text extract use case. | ||
if (lexical.$isTextNode(target)) { | ||
const text = target.__text; // If an uncollapsed selection ends or starts at the end of a line of specialized, | ||
const text = target.__text; | ||
// If an uncollapsed selection ends or starts at the end of a line of specialized, | ||
// TextNodes, such as code tokens, we will get a 'blank' TextNode here, i.e., one | ||
// with text of length 0. We don't want this, it makes a confusing mess. Reset! | ||
if (text.length > 0) { | ||
@@ -424,7 +385,5 @@ serializedNode.text = text; | ||
} | ||
for (let i = 0; i < children.length; i++) { | ||
const childNode = children[i]; | ||
const shouldIncludeChild = $appendNodesToJSON(editor, selection$1, childNode, serializedNode.children); | ||
if (!shouldInclude && lexical.$isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection$1, 'clone')) { | ||
@@ -434,3 +393,2 @@ shouldInclude = true; | ||
} | ||
if (shouldInclude && !shouldExclude) { | ||
@@ -444,6 +402,6 @@ targetArray.push(serializedNode); | ||
} | ||
return shouldInclude; | ||
} // TODO why $ function with Editor instance? | ||
} | ||
// TODO why $ function with Editor instance? | ||
/** | ||
@@ -456,4 +414,2 @@ * Gets the Lexical JSON of the nodes inside the provided Selection. | ||
*/ | ||
function $generateJSONFromSelectedNodes(editor, selection) { | ||
@@ -463,3 +419,2 @@ const nodes = []; | ||
const topLevelChildren = root.getChildren(); | ||
for (let i = 0; i < topLevelChildren.length; i++) { | ||
@@ -469,3 +424,2 @@ const topLevelNode = topLevelChildren[i]; | ||
} | ||
return { | ||
@@ -476,2 +430,3 @@ namespace: editor._config.namespace, | ||
} | ||
/** | ||
@@ -485,23 +440,19 @@ * This method takes an array of objects conforming to the BaseSeralizedNode interface and returns | ||
*/ | ||
function $generateNodesFromSerializedNodes(serializedNodes) { | ||
const nodes = []; | ||
for (let i = 0; i < serializedNodes.length; i++) { | ||
const serializedNode = serializedNodes[i]; | ||
const node = lexical.$parseSerializedNode(serializedNode); | ||
if (lexical.$isTextNode(node)) { | ||
selection.$addNodeStyle(node); | ||
} | ||
nodes.push(node); | ||
} | ||
return nodes; | ||
} | ||
const EVENT_LATENCY = 50; | ||
let clipboardEventTimeout = null; // TODO custom selection | ||
let clipboardEventTimeout = null; | ||
// TODO custom selection | ||
// TODO potentially have a node customizable version for plain text | ||
/** | ||
@@ -516,3 +467,2 @@ * Copies the content of the current selection to the clipboard in | ||
*/ | ||
async function copyToClipboard(editor, event) { | ||
@@ -524,3 +474,2 @@ if (clipboardEventTimeout !== null) { | ||
} | ||
if (event !== null) { | ||
@@ -533,11 +482,8 @@ return new Promise((resolve, reject) => { | ||
} | ||
const rootElement = editor.getRootElement(); | ||
const windowDocument = editor._window == null ? window.document : editor._window.document; | ||
const domSelection = getDOMSelection(editor._window); | ||
if (rootElement === null || domSelection === null) { | ||
return false; | ||
} | ||
const element = windowDocument.createElement('span'); | ||
@@ -556,3 +502,2 @@ element.style.cssText = 'position: fixed; top: -1000px;'; | ||
removeListener(); | ||
if (clipboardEventTimeout !== null) { | ||
@@ -562,11 +507,9 @@ window.clearTimeout(clipboardEventTimeout); | ||
} | ||
resolve($copyToClipboardEvent(editor, secondEvent)); | ||
} // Block the entire copy flow while we wait for the next ClipboardEvent | ||
} | ||
// Block the entire copy flow while we wait for the next ClipboardEvent | ||
return true; | ||
}, lexical.COMMAND_PRIORITY_CRITICAL); // If the above hack execCommand hack works, this timeout code should never fire. Otherwise, | ||
}, lexical.COMMAND_PRIORITY_CRITICAL); | ||
// If the above hack execCommand hack works, this timeout code should never fire. Otherwise, | ||
// the listener will be quickly freed so that the user can reuse it again | ||
clipboardEventTimeout = window.setTimeout(() => { | ||
@@ -580,42 +523,33 @@ removeListener(); | ||
}); | ||
} // TODO shouldn't pass editor (pass namespace directly) | ||
} | ||
// TODO shouldn't pass editor (pass namespace directly) | ||
function $copyToClipboardEvent(editor, event) { | ||
const domSelection = getDOMSelection(editor._window); | ||
if (!domSelection) { | ||
return false; | ||
} | ||
const anchorDOM = domSelection.anchorNode; | ||
const focusDOM = domSelection.focusNode; | ||
if (anchorDOM !== null && focusDOM !== null && !lexical.isSelectionWithinEditor(editor, anchorDOM, focusDOM)) { | ||
return false; | ||
} | ||
event.preventDefault(); | ||
const clipboardData = event.clipboardData; | ||
const selection = lexical.$getSelection(); | ||
if (clipboardData === null || selection === null) { | ||
return false; | ||
} | ||
const htmlString = $getHtmlContent(editor); | ||
const lexicalString = $getLexicalContent(editor); | ||
let plainString = ''; | ||
if (selection !== null) { | ||
plainString = selection.getTextContent(); | ||
} | ||
if (htmlString !== null) { | ||
clipboardData.setData('text/html', htmlString); | ||
} | ||
if (lexicalString !== null) { | ||
clipboardData.setData('application/x-lexical-editor', lexicalString); | ||
} | ||
clipboardData.setData('text/plain', plainString); | ||
@@ -622,0 +556,0 @@ return true; |
@@ -9,14 +9,14 @@ /** | ||
let A="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;function B(a){let b=u.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return u.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?"":d.$generateHtmlFromNodes(a,b)} | ||
function C(a){let b=u.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return u.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:JSON.stringify(D(a,b))}function E(a,b,c){(u.DEPRECATED_$isGridSelection(c)||null!==r.$findMatchingParent(c.anchor.getNode(),e=>u.DEPRECATED_$isGridCellNode(e))&&null!==r.$findMatchingParent(c.focus.getNode(),e=>u.DEPRECATED_$isGridCellNode(e)))&&1===b.length&&u.DEPRECATED_$isGridNode(b[0])?F(b,c,!1,a):I(b,c)} | ||
function I(a,b){let c=[],e=null;for(let f=0;f<a.length;f++){let h=a[f],g=u.$isLineBreakNode(h);if(g||u.$isDecoratorNode(h)&&h.isInline()||u.$isElementNode(h)&&h.isInline()||u.$isTextNode(h)||h.isParentRequired()){if(null===e&&(e=h.createParentElementNode(),c.push(e),g))continue;null!==e&&e.append(h)}else c.push(h),e=null}u.$isRangeSelection(b)?b.insertNodes(c):u.DEPRECATED_$isGridSelection(b)&&(a=b.anchor.getNode(),u.DEPRECATED_$isGridCellNode(a)||z(41),a.append(...c))} | ||
function F(a,b,c,e){1===a.length&&u.DEPRECATED_$isGridNode(a[0])||z(42);var f=a[0];a=f.getChildren();c=f.getFirstChildOrThrow().getChildrenSize();var h=f.getChildrenSize(),g=r.$findMatchingParent(b.anchor.getNode(),l=>u.DEPRECATED_$isGridCellNode(l));b=(f=g&&r.$findMatchingParent(g,l=>u.DEPRECATED_$isGridRowNode(l)))&&r.$findMatchingParent(f,l=>u.DEPRECATED_$isGridNode(l));u.DEPRECATED_$isGridCellNode(g)&&u.DEPRECATED_$isGridRowNode(f)&&u.DEPRECATED_$isGridNode(b)||z(43);var k=f.getIndexWithinParent(), | ||
m=Math.min(b.getChildrenSize()-1,k+h-1);h=g.getIndexWithinParent();g=Math.min(f.getChildrenSize()-1,h+c-1);c=Math.min(h,g);f=Math.min(k,m);h=Math.max(h,g);k=Math.max(k,m);m=b.getChildren();g=0;let n,q;for(let l=f;l<=k;l++){var t=m[l];u.DEPRECATED_$isGridRowNode(t)||z(24);var y=a[g];u.DEPRECATED_$isGridRowNode(y)||z(24);t=t.getChildren();y=y.getChildren();let G=0;for(let v=c;v<=h;v++){let w=t[v];u.DEPRECATED_$isGridCellNode(w)||z(25);let H=y[G];u.DEPRECATED_$isGridCellNode(H)||z(25);l===f&&v===c?n= | ||
w.getKey():l===k&&v===h&&(q=w.getKey());let N=w.getChildren();H.getChildren().forEach(x=>{u.$isTextNode(x)&&u.$createParagraphNode().append(x);w.append(x)});N.forEach(x=>x.remove());G++}g++}n&&q&&(a=u.DEPRECATED_$createGridSelection(),a.set(b.getKey(),n,q),u.$setSelection(a),e.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))} | ||
function J(a,b,c,e=[]){let f=null!=b?c.isSelected(b):!0,h=u.$isElementNode(c)&&c.excludeFromCopy("html");var g=c;if(null!==b){var k=p.$cloneWithProperties(c);g=k=u.$isTextNode(k)&&null!=b?p.$sliceSelectedTextNodeContent(b,k):k}let m=u.$isElementNode(g)?g.getChildren():[];var n=g;k=n.exportJSON();var q=n.constructor;k.type!==q.getType()&&z(58,q.name);let t=k.children;u.$isElementNode(n)&&(Array.isArray(t)||z(59,q.name));u.$isTextNode(g)&&(g=g.__text,0<g.length?k.text=g:f=!1);for(g=0;g<m.length;g++)n= | ||
m[g],q=J(a,b,n,k.children),!f&&u.$isElementNode(c)&&q&&c.extractWithChild(n,b,"clone")&&(f=!0);if(f&&!h)e.push(k);else if(Array.isArray(k.children))for(a=0;a<k.children.length;a++)e.push(k.children[a]);return f}function D(a,b){let c=[],e=u.$getRoot().getChildren();for(let f=0;f<e.length;f++)J(a,b,e[f],c);return{namespace:a._config.namespace,nodes:c}}function K(a){let b=[];for(let c=0;c<a.length;c++){let e=u.$parseSerializedNode(a[c]);u.$isTextNode(e)&&p.$addNodeStyle(e);b.push(e)}return b}let L=null; | ||
function M(a,b){var c=A?(a._window||window).getSelection():null;if(!c)return!1;var e=c.anchorNode;c=c.focusNode;if(null!==e&&null!==c&&!u.isSelectionWithinEditor(a,e,c))return!1;b.preventDefault();b=b.clipboardData;e=u.$getSelection();if(null===b||null===e)return!1;c=B(a);a=C(a);let f="";null!==e&&(f=e.getTextContent());null!==c&&b.setData("text/html",c);null!==a&&b.setData("application/x-lexical-editor",a);b.setData("text/plain",f);return!0}exports.$generateJSONFromSelectedNodes=D; | ||
function C(a){let b=u.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return u.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:JSON.stringify(D(a,b))}function E(a,b,c){(u.DEPRECATED_$isGridSelection(c)||null!==r.$findMatchingParent(c.anchor.getNode(),f=>u.DEPRECATED_$isGridCellNode(f))&&null!==r.$findMatchingParent(c.focus.getNode(),f=>u.DEPRECATED_$isGridCellNode(f)))&&1===b.length&&u.DEPRECATED_$isGridNode(b[0])?F(b,c,!1,a):I(b,c)} | ||
function I(a,b){let c=[],f=null;for(let e=0;e<a.length;e++){let g=a[e],h=u.$isLineBreakNode(g);if(h||u.$isDecoratorNode(g)&&g.isInline()||u.$isElementNode(g)&&g.isInline()||u.$isTextNode(g)||g.isParentRequired()){if(null===f&&(f=g.createParentElementNode(),c.push(f),h))continue;null!==f&&f.append(g)}else c.push(g),f=null}u.$isRangeSelection(b)?b.insertNodes(c):u.DEPRECATED_$isGridSelection(b)&&(a=b.anchor.getNode(),u.DEPRECATED_$isGridCellNode(a)||z(41),a.append(...c))} | ||
function F(a,b,c,f){1===a.length&&u.DEPRECATED_$isGridNode(a[0])||z(42);var e=a[0];a=e.getChildren();c=e.getFirstChildOrThrow().getChildrenSize();var g=e.getChildrenSize(),h=r.$findMatchingParent(b.anchor.getNode(),l=>u.DEPRECATED_$isGridCellNode(l));b=(e=h&&r.$findMatchingParent(h,l=>u.DEPRECATED_$isGridRowNode(l)))&&r.$findMatchingParent(e,l=>u.DEPRECATED_$isGridNode(l));u.DEPRECATED_$isGridCellNode(h)&&u.DEPRECATED_$isGridRowNode(e)&&u.DEPRECATED_$isGridNode(b)||z(43);var k=e.getIndexWithinParent(), | ||
m=Math.min(b.getChildrenSize()-1,k+g-1);g=h.getIndexWithinParent();h=Math.min(e.getChildrenSize()-1,g+c-1);c=Math.min(g,h);e=Math.min(k,m);g=Math.max(g,h);k=Math.max(k,m);m=b.getChildren();h=0;let n,q;for(let l=e;l<=k;l++){var t=m[l];u.DEPRECATED_$isGridRowNode(t)||z(24);var y=a[h];u.DEPRECATED_$isGridRowNode(y)||z(24);t=t.getChildren();y=y.getChildren();let G=0;for(let v=c;v<=g;v++){let w=t[v];u.DEPRECATED_$isGridCellNode(w)||z(25);let H=y[G];u.DEPRECATED_$isGridCellNode(H)||z(25);l===e&&v===c?n= | ||
w.getKey():l===k&&v===g&&(q=w.getKey());let N=w.getChildren();H.getChildren().forEach(x=>{u.$isTextNode(x)&&u.$createParagraphNode().append(x);w.append(x)});N.forEach(x=>x.remove());G++}h++}n&&q&&(a=u.DEPRECATED_$createGridSelection(),a.set(b.getKey(),n,q),u.$setSelection(a),f.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))} | ||
function J(a,b,c,f=[]){let e=null!=b?c.isSelected(b):!0,g=u.$isElementNode(c)&&c.excludeFromCopy("html");var h=c;if(null!==b){var k=p.$cloneWithProperties(c);h=k=u.$isTextNode(k)&&null!=b?p.$sliceSelectedTextNodeContent(b,k):k}let m=u.$isElementNode(h)?h.getChildren():[];var n=h;k=n.exportJSON();var q=n.constructor;k.type!==q.getType()&&z(58,q.name);let t=k.children;u.$isElementNode(n)&&(Array.isArray(t)||z(59,q.name));u.$isTextNode(h)&&(h=h.__text,0<h.length?k.text=h:e=!1);for(h=0;h<m.length;h++)n= | ||
m[h],q=J(a,b,n,k.children),!e&&u.$isElementNode(c)&&q&&c.extractWithChild(n,b,"clone")&&(e=!0);if(e&&!g)f.push(k);else if(Array.isArray(k.children))for(a=0;a<k.children.length;a++)f.push(k.children[a]);return e}function D(a,b){let c=[],f=u.$getRoot().getChildren();for(let e=0;e<f.length;e++)J(a,b,f[e],c);return{namespace:a._config.namespace,nodes:c}}function K(a){let b=[];for(let c=0;c<a.length;c++){let f=u.$parseSerializedNode(a[c]);u.$isTextNode(f)&&p.$addNodeStyle(f);b.push(f)}return b}let L=null; | ||
function M(a,b){var c=A?(a._window||window).getSelection():null;if(!c)return!1;var f=c.anchorNode;c=c.focusNode;if(null!==f&&null!==c&&!u.isSelectionWithinEditor(a,f,c))return!1;b.preventDefault();b=b.clipboardData;f=u.$getSelection();if(null===b||null===f)return!1;c=B(a);a=C(a);let e="";null!==f&&(e=f.getTextContent());null!==c&&b.setData("text/html",c);null!==a&&b.setData("application/x-lexical-editor",a);b.setData("text/plain",e);return!0}exports.$generateJSONFromSelectedNodes=D; | ||
exports.$generateNodesFromSerializedNodes=K;exports.$getHtmlContent=B;exports.$getLexicalContent=C;exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain")||a.getData("text/uri-list");null!=a&&b.insertRawText(a)}; | ||
exports.$insertDataTransferForRichText=function(a,b,c){var e=a.getData("application/x-lexical-editor");if(e)try{let g=JSON.parse(e);if(g.namespace===c._config.namespace&&Array.isArray(g.nodes)){let k=K(g.nodes);return E(c,k,b)}}catch{}if(e=a.getData("text/html"))try{var f=(new DOMParser).parseFromString(e,"text/html"),h=d.$generateNodesFromDOM(c,f);return E(c,h,b)}catch{}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(u.$isRangeSelection(b))for(a=a.split(/(\r?\n|\t)/),c=a.length, | ||
f=0;f<c;f++)h=a[f],"\n"===h||"\r\n"===h?b.insertParagraph():"\t"===h?b.insertNodes([u.$createTabNode()]):b.insertText(h);else b.insertRawText(a)};exports.$insertGeneratedNodes=E; | ||
exports.copyToClipboard=async function(a,b){if(null!==L)return!1;if(null!==b)return new Promise(g=>{a.update(()=>{g(M(a,b))})});var c=a.getRootElement();let e=null==a._window?window.document:a._window.document,f=A?(a._window||window).getSelection():null;if(null===c||null===f)return!1;let h=e.createElement("span");h.style.cssText="position: fixed; top: -1000px;";h.append(e.createTextNode("#"));c.append(h);c=new Range;c.setStart(h,0);c.setEnd(h,1);f.removeAllRanges();f.addRange(c);return new Promise(g=> | ||
{let k=a.registerCommand(u.COPY_COMMAND,m=>{r.objectKlassEquals(m,ClipboardEvent)&&(k(),null!==L&&(window.clearTimeout(L),L=null),g(M(a,m)));return!0},u.COMMAND_PRIORITY_CRITICAL);L=window.setTimeout(()=>{k();L=null;g(!1)},50);e.execCommand("copy");h.remove()})} | ||
exports.$insertDataTransferForRichText=function(a,b,c){var f=a.getData("application/x-lexical-editor");if(f)try{let g=JSON.parse(f);if(g.namespace===c._config.namespace&&Array.isArray(g.nodes)){let h=K(g.nodes);return E(c,h,b)}}catch(g){}if(f=a.getData("text/html"))try{var e=(new DOMParser).parseFromString(f,"text/html");let g=d.$generateNodesFromDOM(c,e);return E(c,g,b)}catch(g){}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(u.$isRangeSelection(b))for(a=a.split(/(\r?\n|\t)/), | ||
""===a[a.length-1]&&a.pop(),c=0;c<a.length;c++)e=a[c],"\n"===e||"\r\n"===e?b.insertParagraph():"\t"===e?b.insertNodes([u.$createTabNode()]):b.insertText(e);else b.insertRawText(a)};exports.$insertGeneratedNodes=E; | ||
exports.copyToClipboard=async function(a,b){if(null!==L)return!1;if(null!==b)return new Promise(h=>{a.update(()=>{h(M(a,b))})});var c=a.getRootElement();let f=null==a._window?window.document:a._window.document,e=A?(a._window||window).getSelection():null;if(null===c||null===e)return!1;let g=f.createElement("span");g.style.cssText="position: fixed; top: -1000px;";g.append(f.createTextNode("#"));c.append(g);c=new Range;c.setStart(g,0);c.setEnd(g,1);e.removeAllRanges();e.addRange(c);return new Promise(h=> | ||
{let k=a.registerCommand(u.COPY_COMMAND,m=>{r.objectKlassEquals(m,ClipboardEvent)&&(k(),null!==L&&(window.clearTimeout(L),L=null),h(M(a,m)));return!0},u.COMMAND_PRIORITY_CRITICAL);L=window.setTimeout(()=>{k();L=null;h(!1)},50);f.execCommand("copy");g.remove()})} |
@@ -12,12 +12,12 @@ { | ||
"license": "MIT", | ||
"version": "0.12.2", | ||
"version": "0.12.3", | ||
"main": "LexicalClipboard.js", | ||
"peerDependencies": { | ||
"lexical": "0.12.2" | ||
"lexical": "0.12.3" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.12.2", | ||
"@lexical/list": "0.12.2", | ||
"@lexical/selection": "0.12.2", | ||
"@lexical/html": "0.12.2" | ||
"@lexical/utils": "0.12.3", | ||
"@lexical/list": "0.12.3", | ||
"@lexical/selection": "0.12.3", | ||
"@lexical/html": "0.12.3" | ||
}, | ||
@@ -24,0 +24,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
36370
642
24
49
+ Added@lexical/html@0.12.3(transitive)
+ Added@lexical/list@0.12.3(transitive)
+ Added@lexical/selection@0.12.3(transitive)
+ Added@lexical/table@0.12.3(transitive)
+ Added@lexical/utils@0.12.3(transitive)
+ Addedlexical@0.12.3(transitive)
- Removed@lexical/html@0.12.2(transitive)
- Removed@lexical/list@0.12.2(transitive)
- Removed@lexical/selection@0.12.2(transitive)
- Removed@lexical/table@0.12.2(transitive)
- Removed@lexical/utils@0.12.2(transitive)
- Removedlexical@0.12.2(transitive)
Updated@lexical/html@0.12.3
Updated@lexical/list@0.12.3
Updated@lexical/selection@0.12.3
Updated@lexical/utils@0.12.3