/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
apps/wpcom-block-editor/src/utils.js
82 строки
3 KB
Omar Alshaker
Janitorial: Remove unused functions (#108174)
19 янв 2026, 16:54
Не верифицирован
19 янв 2026, 16:54
e37afea
Код
Авторство
О чём код?
import { select, subscribe } from '@wordpress/data'; export const objectHasValues = ( object ) => Object.values( object ).some( ( value ) => value !== undefined ); /** * Sends a message object to the parent. The object is extended to include a type that * identifies the source as Gutenberg related. * @param {Object} message object containing the action to be performed on the parent and any require options */ export function sendMessage( message ) { if ( ! window || ! window.parent ) { return; } window.parent.postMessage( { ...message, type: 'gutenbergIframeMessage' }, '*' ); } /** * Indicates if the block editor has been initialized. * @returns {Promise} Promise that resolves when the editor has been initialized. */ export const isEditorReady = async () => new Promise( ( resolve ) => { const unsubscribe = subscribe( () => { // Calypso sends the message as soon as the iframe is loaded, so we // need to be sure that the editor is initialized and the core blocks // registered. There is an unstable selector for that, so we use // `isCleanNewPost` otherwise which is triggered when everything is // initialized if the post is new. const editorIsReady = select( 'core/editor' ).__unstableIsEditorReady ? select( 'core/editor' ).__unstableIsEditorReady() : select( 'core/editor' ).isCleanNewPost(); if ( editorIsReady ) { unsubscribe(); resolve(); } } ); } ); /** * Indicates if the block editor has been initialized with blocks. * @returns {Promise} Promise that resolves when the editor has been initialized with blocks. */ export const isEditorReadyWithBlocks = async () => new Promise( ( resolve ) => { const unsubscribe = subscribe( () => { const isCleanNewPost = select( 'core/editor' ).isCleanNewPost(); if ( isCleanNewPost ) { unsubscribe(); resolve( false ); } const blocks = select( 'core/editor' ).getBlocks(); if ( blocks.length > 0 ) { unsubscribe(); resolve( true ); } } ); } ); export const getPostTypeRecords = async ( name ) => new Promise( ( resolve ) => { const unsubscribe = subscribe( () => { const records = select( 'core' ).getEntityRecords( 'postType', name, { per_page: -1 } ); if ( records !== null ) { unsubscribe(); resolve( records ); } } ); } ); export const getPages = async () => getPostTypeRecords( 'page' ); // All end-to-end tests use a custom user agent containing this string. const E2E_USER_AGENT = 'wp-e2e-tests'; export const isE2ETest = () => typeof window !== 'undefined' && window.navigator.userAgent.includes( E2E_USER_AGENT );