UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

38 lines (37 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.batchStepsUpdate = void 0; var _steps = require("@atlaskit/adf-schema/steps"); var _collab = require("@atlaskit/editor-common/collab"); /** * Applies a batch of attribute update steps to media nodes in the editor view. * * @param {EditorView} editorView - The editor view instance where the updates will be applied. * @param {BatchAttrsStepData[]} steps - An array of steps containing the positions and new attributes for media nodes. * @returns {boolean} - Returns false if no steps were applied or if the document remains unchanged after applying the steps. * * This function performs the following steps: * 1. Creates a new transaction from the current editor state. * 2. If there are no steps to apply, it returns false. * 3. Adds a new `BatchAttrsStep` to the transaction with the provided steps. * 4. If the transaction has no steps or the document remains unchanged, it returns false. * 5. Dispatches the transaction to apply the updates to the editor view. * * TODO: use pluginInjectionAPI to batch updates from a command in a separate PR later */ var batchStepsUpdate = exports.batchStepsUpdate = function batchStepsUpdate(editorView, steps) { var state = editorView.state, dispatch = editorView.dispatch; var tr = state.tr; if (steps.length === 0) { return false; } tr.step(new _steps.BatchAttrsStep(steps)); if (tr.steps.length > 0 && tr.doc.eq(state.doc)) { return false; } (0, _collab.tintDirtyTransaction)(tr); dispatch(tr); };