MCPcopy Index your code
hub / github.com/codex-team/editor.js / update

Method update

src/components/modules/blockManager.ts:348–371  ·  view source on GitHub ↗

* Update Block data. * * Currently we don't have an 'update' method in the Tools API, so we just create a new block with the same id and type * Should not trigger 'block-removed' or 'block-added' events. * * If neither data nor tunes is provided, return the provided block instead.

(block: Block, data?: Partial<BlockToolData>, tunes?: {[name: string]: BlockTuneData})

Source from the content-addressed store, hash-verified

346 * @param tunes - (optional) tune data
347 */
348 public async update(block: Block, data?: Partial<BlockToolData>, tunes?: {[name: string]: BlockTuneData}): Promise<Block> {
349 if (!data && !tunes) {
350 return block;
351 }
352
353 const existingData = await block.data;
354
355 const newBlock = this.composeBlock({
356 id: block.id,
357 tool: block.name,
358 data: Object.assign({}, existingData, data ?? {}),
359 tunes: tunes ?? block.tunes,
360 });
361
362 const blockIndex = this.getBlockIndex(block);
363
364 this._blocks.replace(blockIndex, newBlock);
365
366 this.blockDidMutated(BlockChangedMutationType, newBlock, {
367 index: blockIndex,
368 });
369
370 return newBlock;
371 }
372
373 /**
374 * Replace passed Block with the new one with specified Tool and data

Callers

nothing calls this directly

Calls 4

composeBlockMethod · 0.95
getBlockIndexMethod · 0.95
blockDidMutatedMethod · 0.95
replaceMethod · 0.45

Tested by

no test coverage detected