/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/e2e-test-utils-playwright/src/editor/insert-block.ts
51 строка
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { Editor } from './index'; interface BlockRepresentation { name: string; attributes?: Object; innerBlocks?: BlockRepresentation[]; } /** * Insert a block. * * @param blockRepresentation Inserted block representation. * @param options * @param options.clientId Client ID of the parent block to insert into. */ async function insertBlock( this: Editor, blockRepresentation: BlockRepresentation, { clientId }: { clientId?: string } = {} ) { await this.page.waitForFunction( () => window?.wp?.blocks && window?.wp?.data ); await this.page.evaluate( ( [ _blockRepresentation, _clientId ] ) => { function recursiveCreateBlock( { name, attributes = {}, innerBlocks = [], }: BlockRepresentation ): Object { return window.wp.blocks.createBlock( name, attributes, innerBlocks.map( ( innerBlock ) => recursiveCreateBlock( innerBlock ) ) ); } const block = recursiveCreateBlock( _blockRepresentation ); window.wp.data .dispatch( 'core/block-editor' ) .insertBlock( block, undefined, _clientId ); }, [ blockRepresentation, clientId ] as const ); } export type { BlockRepresentation }; export { insertBlock };