MCPcopy
hub / github.com/codex-team/editor.js / insertEditorJSData

Method insertEditorJSData

src/components/modules/paste.ts:870–893  ·  view source on GitHub ↗

* Insert data passed as application/x-editor-js JSON * * @param {Array} blocks — Blocks' data to insert * @returns {void}

(blocks: Pick<SavedData, 'id' | 'data' | 'tool'>[])

Source from the content-addressed store, hash-verified

868 * @returns {void}
869 */
870 private insertEditorJSData(blocks: Pick<SavedData, 'id' | 'data' | 'tool'>[]): void {
871 const { BlockManager, Caret, Tools } = this.Editor;
872 const sanitizedBlocks = sanitizeBlocks(blocks, (name) =>
873 Tools.blockTools.get(name).sanitizeConfig
874 );
875
876 sanitizedBlocks.forEach(({ tool, data }, i) => {
877 let needToReplaceCurrentBlock = false;
878
879 if (i === 0) {
880 const isCurrentBlockDefault = BlockManager.currentBlock && BlockManager.currentBlock.tool.isDefault;
881
882 needToReplaceCurrentBlock = isCurrentBlockDefault && BlockManager.currentBlock.isEmpty;
883 }
884
885 const block = BlockManager.insert({
886 tool,
887 data,
888 replace: needToReplaceCurrentBlock,
889 });
890
891 Caret.setToBlock(block, Caret.positions.END);
892 });
893 }
894
895 /**
896 * Fetch nodes from Element node

Callers 1

processDataTransferMethod · 0.95

Calls 5

sanitizeBlocksFunction · 0.90
forEachMethod · 0.80
getMethod · 0.65
insertMethod · 0.65
setToBlockMethod · 0.65

Tested by

no test coverage detected