UNPKG

@atlaskit/editor-plugin-synced-block

Version:

SyncedBlock plugin for @atlaskit/editor-core

37 lines (34 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pasteSyncBlockHTMLContent = exports.findBodiedSyncBlockByLocalId = void 0; var findBodiedSyncBlockByLocalId = exports.findBodiedSyncBlockByLocalId = function findBodiedSyncBlockByLocalId(state, localId) { var result; state.doc.descendants(function (node, pos) { if (result) { return false; } if (node.type === state.schema.nodes.bodiedSyncBlock && node.attrs.localId === localId) { result = { node: node, pos: pos }; return false; } return true; }); return result; }; var pasteSyncBlockHTMLContent = exports.pasteSyncBlockHTMLContent = function pasteSyncBlockHTMLContent(contentDOM, view) { var tmpDiv = document.createElement('div'); tmpDiv.appendChild(contentDOM); // This is required so that prosemirror can read the fragment context and slice properly if (tmpDiv.firstChild instanceof HTMLElement) { tmpDiv.firstChild.setAttribute('data-pm-slice', '0 0 []'); // As per requirement - when unsync reference block, it should render its content as copy&paste behaviour // Hence here we call pasteHTML to evoke editor paste logic that handles any unsupported nodes/marks return view.pasteHTML(tmpDiv.innerHTML); } return false; };