UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

43 lines (42 loc) • 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.batchStepsUpdate = void 0; var _batchAttrsStep = require("@atlaskit/adf-schema/steps/batch-attrs-step"); var _collab = require("@atlaskit/editor-common/collab"); var _fg = require("@atlaskit/platform-feature-flags/fg"); /** * 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 _batchAttrsStep.BatchAttrsStep(steps)); if (tr.steps.length > 0 && tr.doc.eq(state.doc)) { return false; } (0, _collab.tintDirtyTransaction)(tr); if ((0, _fg.fg)('platform_editor_media_hydration_skip_history')) { // Attribute hydration is not a user edit, so it must not take an undo step. tr.setMeta('addToHistory', false); } dispatch(tr); };