Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu.../js/dist
File: block-editor.js
* @param {string} attributeKey The selected block attribute key.
[15500] Fix | Delete
* @param {number} startOffset The start offset.
[15501] Fix | Delete
* @param {number} endOffset The end offset.
[15502] Fix | Delete
*
[15503] Fix | Delete
* @return {Object} Action object.
[15504] Fix | Delete
*/
[15505] Fix | Delete
function selectionChange(clientId, attributeKey, startOffset, endOffset) {
[15506] Fix | Delete
if (typeof clientId === 'string') {
[15507] Fix | Delete
return {
[15508] Fix | Delete
type: 'SELECTION_CHANGE',
[15509] Fix | Delete
clientId,
[15510] Fix | Delete
attributeKey,
[15511] Fix | Delete
startOffset,
[15512] Fix | Delete
endOffset
[15513] Fix | Delete
};
[15514] Fix | Delete
}
[15515] Fix | Delete
return {
[15516] Fix | Delete
type: 'SELECTION_CHANGE',
[15517] Fix | Delete
...clientId
[15518] Fix | Delete
};
[15519] Fix | Delete
}
[15520] Fix | Delete
[15521] Fix | Delete
/**
[15522] Fix | Delete
* Action that adds a new block of the default type to the block list.
[15523] Fix | Delete
*
[15524] Fix | Delete
* @param {?Object} attributes Optional attributes of the block to assign.
[15525] Fix | Delete
* @param {?string} rootClientId Optional root client ID of block list on which
[15526] Fix | Delete
* to append.
[15527] Fix | Delete
* @param {?number} index Optional index where to insert the default block.
[15528] Fix | Delete
*/
[15529] Fix | Delete
const insertDefaultBlock = (attributes, rootClientId, index) => ({
[15530] Fix | Delete
dispatch
[15531] Fix | Delete
}) => {
[15532] Fix | Delete
// Abort if there is no default block type (if it has been unregistered).
[15533] Fix | Delete
const defaultBlockName = (0,external_wp_blocks_namespaceObject.getDefaultBlockName)();
[15534] Fix | Delete
if (!defaultBlockName) {
[15535] Fix | Delete
return;
[15536] Fix | Delete
}
[15537] Fix | Delete
const block = (0,external_wp_blocks_namespaceObject.createBlock)(defaultBlockName, attributes);
[15538] Fix | Delete
return dispatch.insertBlock(block, index, rootClientId);
[15539] Fix | Delete
};
[15540] Fix | Delete
[15541] Fix | Delete
/**
[15542] Fix | Delete
* @typedef {Object< string, Object >} SettingsByClientId
[15543] Fix | Delete
*/
[15544] Fix | Delete
[15545] Fix | Delete
/**
[15546] Fix | Delete
* Action that changes the nested settings of the given block(s).
[15547] Fix | Delete
*
[15548] Fix | Delete
* @param {string | SettingsByClientId} clientId Client ID of the block whose
[15549] Fix | Delete
* nested setting are being
[15550] Fix | Delete
* received, or object of settings
[15551] Fix | Delete
* by client ID.
[15552] Fix | Delete
* @param {Object} settings Object with the new settings
[15553] Fix | Delete
* for the nested block.
[15554] Fix | Delete
*
[15555] Fix | Delete
* @return {Object} Action object
[15556] Fix | Delete
*/
[15557] Fix | Delete
function updateBlockListSettings(clientId, settings) {
[15558] Fix | Delete
return {
[15559] Fix | Delete
type: 'UPDATE_BLOCK_LIST_SETTINGS',
[15560] Fix | Delete
clientId,
[15561] Fix | Delete
settings
[15562] Fix | Delete
};
[15563] Fix | Delete
}
[15564] Fix | Delete
[15565] Fix | Delete
/**
[15566] Fix | Delete
* Action that updates the block editor settings.
[15567] Fix | Delete
*
[15568] Fix | Delete
* @param {Object} settings Updated settings
[15569] Fix | Delete
*
[15570] Fix | Delete
* @return {Object} Action object
[15571] Fix | Delete
*/
[15572] Fix | Delete
function updateSettings(settings) {
[15573] Fix | Delete
return __experimentalUpdateSettings(settings, {
[15574] Fix | Delete
stripExperimentalSettings: true
[15575] Fix | Delete
});
[15576] Fix | Delete
}
[15577] Fix | Delete
[15578] Fix | Delete
/**
[15579] Fix | Delete
* Action that signals that a temporary reusable block has been saved
[15580] Fix | Delete
* in order to switch its temporary id with the real id.
[15581] Fix | Delete
*
[15582] Fix | Delete
* @param {string} id Reusable block's id.
[15583] Fix | Delete
* @param {string} updatedId Updated block's id.
[15584] Fix | Delete
*
[15585] Fix | Delete
* @return {Object} Action object.
[15586] Fix | Delete
*/
[15587] Fix | Delete
function __unstableSaveReusableBlock(id, updatedId) {
[15588] Fix | Delete
return {
[15589] Fix | Delete
type: 'SAVE_REUSABLE_BLOCK_SUCCESS',
[15590] Fix | Delete
id,
[15591] Fix | Delete
updatedId
[15592] Fix | Delete
};
[15593] Fix | Delete
}
[15594] Fix | Delete
[15595] Fix | Delete
/**
[15596] Fix | Delete
* Action that marks the last block change explicitly as persistent.
[15597] Fix | Delete
*
[15598] Fix | Delete
* @return {Object} Action object.
[15599] Fix | Delete
*/
[15600] Fix | Delete
function __unstableMarkLastChangeAsPersistent() {
[15601] Fix | Delete
return {
[15602] Fix | Delete
type: 'MARK_LAST_CHANGE_AS_PERSISTENT'
[15603] Fix | Delete
};
[15604] Fix | Delete
}
[15605] Fix | Delete
[15606] Fix | Delete
/**
[15607] Fix | Delete
* Action that signals that the next block change should be marked explicitly as not persistent.
[15608] Fix | Delete
*
[15609] Fix | Delete
* @return {Object} Action object.
[15610] Fix | Delete
*/
[15611] Fix | Delete
function __unstableMarkNextChangeAsNotPersistent() {
[15612] Fix | Delete
return {
[15613] Fix | Delete
type: 'MARK_NEXT_CHANGE_AS_NOT_PERSISTENT'
[15614] Fix | Delete
};
[15615] Fix | Delete
}
[15616] Fix | Delete
[15617] Fix | Delete
/**
[15618] Fix | Delete
* Action that marks the last block change as an automatic change, meaning it was not
[15619] Fix | Delete
* performed by the user, and can be undone using the `Escape` and `Backspace` keys.
[15620] Fix | Delete
* This action must be called after the change was made, and any actions that are a
[15621] Fix | Delete
* consequence of it, so it is recommended to be called at the next idle period to ensure all
[15622] Fix | Delete
* selection changes have been recorded.
[15623] Fix | Delete
*/
[15624] Fix | Delete
const __unstableMarkAutomaticChange = () => ({
[15625] Fix | Delete
dispatch
[15626] Fix | Delete
}) => {
[15627] Fix | Delete
dispatch({
[15628] Fix | Delete
type: 'MARK_AUTOMATIC_CHANGE'
[15629] Fix | Delete
});
[15630] Fix | Delete
const {
[15631] Fix | Delete
requestIdleCallback = cb => setTimeout(cb, 100)
[15632] Fix | Delete
} = window;
[15633] Fix | Delete
requestIdleCallback(() => {
[15634] Fix | Delete
dispatch({
[15635] Fix | Delete
type: 'MARK_AUTOMATIC_CHANGE_FINAL'
[15636] Fix | Delete
});
[15637] Fix | Delete
});
[15638] Fix | Delete
};
[15639] Fix | Delete
[15640] Fix | Delete
/**
[15641] Fix | Delete
* Action that enables or disables the navigation mode.
[15642] Fix | Delete
*
[15643] Fix | Delete
* @param {boolean} isNavigationMode Enable/Disable navigation mode.
[15644] Fix | Delete
*/
[15645] Fix | Delete
const setNavigationMode = (isNavigationMode = true) => ({
[15646] Fix | Delete
dispatch
[15647] Fix | Delete
}) => {
[15648] Fix | Delete
dispatch.__unstableSetEditorMode(isNavigationMode ? 'navigation' : 'edit');
[15649] Fix | Delete
};
[15650] Fix | Delete
[15651] Fix | Delete
/**
[15652] Fix | Delete
* Action that sets the editor mode
[15653] Fix | Delete
*
[15654] Fix | Delete
* @param {string} mode Editor mode
[15655] Fix | Delete
*/
[15656] Fix | Delete
const __unstableSetEditorMode = mode => ({
[15657] Fix | Delete
dispatch,
[15658] Fix | Delete
select,
[15659] Fix | Delete
registry
[15660] Fix | Delete
}) => {
[15661] Fix | Delete
// When switching to zoom-out mode, we need to select the parent section
[15662] Fix | Delete
if (mode === 'zoom-out') {
[15663] Fix | Delete
const firstSelectedClientId = select.getBlockSelectionStart();
[15664] Fix | Delete
const {
[15665] Fix | Delete
sectionRootClientId
[15666] Fix | Delete
} = unlock(registry.select(STORE_NAME).getSettings());
[15667] Fix | Delete
if (firstSelectedClientId) {
[15668] Fix | Delete
let sectionClientId;
[15669] Fix | Delete
if (sectionRootClientId) {
[15670] Fix | Delete
const sectionClientIds = select.getBlockOrder(sectionRootClientId);
[15671] Fix | Delete
sectionClientId = select.getBlockParents(firstSelectedClientId).find(parent => sectionClientIds.includes(parent));
[15672] Fix | Delete
} else {
[15673] Fix | Delete
sectionClientId = select.getBlockHierarchyRootClientId(firstSelectedClientId);
[15674] Fix | Delete
}
[15675] Fix | Delete
if (sectionClientId) {
[15676] Fix | Delete
dispatch.selectBlock(sectionClientId);
[15677] Fix | Delete
} else {
[15678] Fix | Delete
dispatch.clearSelectedBlock();
[15679] Fix | Delete
}
[15680] Fix | Delete
}
[15681] Fix | Delete
}
[15682] Fix | Delete
dispatch({
[15683] Fix | Delete
type: 'SET_EDITOR_MODE',
[15684] Fix | Delete
mode
[15685] Fix | Delete
});
[15686] Fix | Delete
if (mode === 'navigation') {
[15687] Fix | Delete
(0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('You are currently in navigation mode. Navigate blocks using the Tab key and Arrow keys. Use Left and Right Arrow keys to move between nesting levels. To exit navigation mode and edit the selected block, press Enter.'));
[15688] Fix | Delete
} else if (mode === 'edit') {
[15689] Fix | Delete
(0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('You are currently in edit mode. To return to the navigation mode, press Escape.'));
[15690] Fix | Delete
} else if (mode === 'zoom-out') {
[15691] Fix | Delete
(0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('You are currently in zoom-out mode.'));
[15692] Fix | Delete
}
[15693] Fix | Delete
};
[15694] Fix | Delete
[15695] Fix | Delete
/**
[15696] Fix | Delete
* Action that enables or disables the block moving mode.
[15697] Fix | Delete
*
[15698] Fix | Delete
* @param {string|null} hasBlockMovingClientId Enable/Disable block moving mode.
[15699] Fix | Delete
*/
[15700] Fix | Delete
const setBlockMovingClientId = (hasBlockMovingClientId = null) => ({
[15701] Fix | Delete
dispatch
[15702] Fix | Delete
}) => {
[15703] Fix | Delete
dispatch({
[15704] Fix | Delete
type: 'SET_BLOCK_MOVING_MODE',
[15705] Fix | Delete
hasBlockMovingClientId
[15706] Fix | Delete
});
[15707] Fix | Delete
if (hasBlockMovingClientId) {
[15708] Fix | Delete
(0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('Use the Tab key and Arrow keys to choose new block location. Use Left and Right Arrow keys to move between nesting levels. Once location is selected press Enter or Space to move the block.'));
[15709] Fix | Delete
}
[15710] Fix | Delete
};
[15711] Fix | Delete
[15712] Fix | Delete
/**
[15713] Fix | Delete
* Action that duplicates a list of blocks.
[15714] Fix | Delete
*
[15715] Fix | Delete
* @param {string[]} clientIds
[15716] Fix | Delete
* @param {boolean} updateSelection
[15717] Fix | Delete
*/
[15718] Fix | Delete
const duplicateBlocks = (clientIds, updateSelection = true) => ({
[15719] Fix | Delete
select,
[15720] Fix | Delete
dispatch
[15721] Fix | Delete
}) => {
[15722] Fix | Delete
if (!clientIds || !clientIds.length) {
[15723] Fix | Delete
return;
[15724] Fix | Delete
}
[15725] Fix | Delete
[15726] Fix | Delete
// Return early if blocks don't exist.
[15727] Fix | Delete
const blocks = select.getBlocksByClientId(clientIds);
[15728] Fix | Delete
if (blocks.some(block => !block)) {
[15729] Fix | Delete
return;
[15730] Fix | Delete
}
[15731] Fix | Delete
[15732] Fix | Delete
// Return early if blocks don't support multiple usage.
[15733] Fix | Delete
const blockNames = blocks.map(block => block.name);
[15734] Fix | Delete
if (blockNames.some(blockName => !(0,external_wp_blocks_namespaceObject.hasBlockSupport)(blockName, 'multiple', true))) {
[15735] Fix | Delete
return;
[15736] Fix | Delete
}
[15737] Fix | Delete
const rootClientId = select.getBlockRootClientId(clientIds[0]);
[15738] Fix | Delete
const clientIdsArray = actions_castArray(clientIds);
[15739] Fix | Delete
const lastSelectedIndex = select.getBlockIndex(clientIdsArray[clientIdsArray.length - 1]);
[15740] Fix | Delete
const clonedBlocks = blocks.map(block => (0,external_wp_blocks_namespaceObject.__experimentalCloneSanitizedBlock)(block));
[15741] Fix | Delete
dispatch.insertBlocks(clonedBlocks, lastSelectedIndex + 1, rootClientId, updateSelection);
[15742] Fix | Delete
if (clonedBlocks.length > 1 && updateSelection) {
[15743] Fix | Delete
dispatch.multiSelect(clonedBlocks[0].clientId, clonedBlocks[clonedBlocks.length - 1].clientId);
[15744] Fix | Delete
}
[15745] Fix | Delete
return clonedBlocks.map(block => block.clientId);
[15746] Fix | Delete
};
[15747] Fix | Delete
[15748] Fix | Delete
/**
[15749] Fix | Delete
* Action that inserts a default block before a given block.
[15750] Fix | Delete
*
[15751] Fix | Delete
* @param {string} clientId
[15752] Fix | Delete
*/
[15753] Fix | Delete
const insertBeforeBlock = clientId => ({
[15754] Fix | Delete
select,
[15755] Fix | Delete
dispatch
[15756] Fix | Delete
}) => {
[15757] Fix | Delete
if (!clientId) {
[15758] Fix | Delete
return;
[15759] Fix | Delete
}
[15760] Fix | Delete
const rootClientId = select.getBlockRootClientId(clientId);
[15761] Fix | Delete
const isLocked = select.getTemplateLock(rootClientId);
[15762] Fix | Delete
if (isLocked) {
[15763] Fix | Delete
return;
[15764] Fix | Delete
}
[15765] Fix | Delete
const blockIndex = select.getBlockIndex(clientId);
[15766] Fix | Delete
const directInsertBlock = rootClientId ? select.getDirectInsertBlock(rootClientId) : null;
[15767] Fix | Delete
if (!directInsertBlock) {
[15768] Fix | Delete
return dispatch.insertDefaultBlock({}, rootClientId, blockIndex);
[15769] Fix | Delete
}
[15770] Fix | Delete
const copiedAttributes = {};
[15771] Fix | Delete
if (directInsertBlock.attributesToCopy) {
[15772] Fix | Delete
const attributes = select.getBlockAttributes(clientId);
[15773] Fix | Delete
directInsertBlock.attributesToCopy.forEach(key => {
[15774] Fix | Delete
if (attributes[key]) {
[15775] Fix | Delete
copiedAttributes[key] = attributes[key];
[15776] Fix | Delete
}
[15777] Fix | Delete
});
[15778] Fix | Delete
}
[15779] Fix | Delete
const block = (0,external_wp_blocks_namespaceObject.createBlock)(directInsertBlock.name, {
[15780] Fix | Delete
...directInsertBlock.attributes,
[15781] Fix | Delete
...copiedAttributes
[15782] Fix | Delete
});
[15783] Fix | Delete
return dispatch.insertBlock(block, blockIndex, rootClientId);
[15784] Fix | Delete
};
[15785] Fix | Delete
[15786] Fix | Delete
/**
[15787] Fix | Delete
* Action that inserts a default block after a given block.
[15788] Fix | Delete
*
[15789] Fix | Delete
* @param {string} clientId
[15790] Fix | Delete
*/
[15791] Fix | Delete
const insertAfterBlock = clientId => ({
[15792] Fix | Delete
select,
[15793] Fix | Delete
dispatch
[15794] Fix | Delete
}) => {
[15795] Fix | Delete
if (!clientId) {
[15796] Fix | Delete
return;
[15797] Fix | Delete
}
[15798] Fix | Delete
const rootClientId = select.getBlockRootClientId(clientId);
[15799] Fix | Delete
const isLocked = select.getTemplateLock(rootClientId);
[15800] Fix | Delete
if (isLocked) {
[15801] Fix | Delete
return;
[15802] Fix | Delete
}
[15803] Fix | Delete
const blockIndex = select.getBlockIndex(clientId);
[15804] Fix | Delete
const directInsertBlock = rootClientId ? select.getDirectInsertBlock(rootClientId) : null;
[15805] Fix | Delete
if (!directInsertBlock) {
[15806] Fix | Delete
return dispatch.insertDefaultBlock({}, rootClientId, blockIndex + 1);
[15807] Fix | Delete
}
[15808] Fix | Delete
const copiedAttributes = {};
[15809] Fix | Delete
if (directInsertBlock.attributesToCopy) {
[15810] Fix | Delete
const attributes = select.getBlockAttributes(clientId);
[15811] Fix | Delete
directInsertBlock.attributesToCopy.forEach(key => {
[15812] Fix | Delete
if (attributes[key]) {
[15813] Fix | Delete
copiedAttributes[key] = attributes[key];
[15814] Fix | Delete
}
[15815] Fix | Delete
});
[15816] Fix | Delete
}
[15817] Fix | Delete
const block = (0,external_wp_blocks_namespaceObject.createBlock)(directInsertBlock.name, {
[15818] Fix | Delete
...directInsertBlock.attributes,
[15819] Fix | Delete
...copiedAttributes
[15820] Fix | Delete
});
[15821] Fix | Delete
return dispatch.insertBlock(block, blockIndex + 1, rootClientId);
[15822] Fix | Delete
};
[15823] Fix | Delete
[15824] Fix | Delete
/**
[15825] Fix | Delete
* Action that toggles the highlighted block state.
[15826] Fix | Delete
*
[15827] Fix | Delete
* @param {string} clientId The block's clientId.
[15828] Fix | Delete
* @param {boolean} isHighlighted The highlight state.
[15829] Fix | Delete
*/
[15830] Fix | Delete
function toggleBlockHighlight(clientId, isHighlighted) {
[15831] Fix | Delete
return {
[15832] Fix | Delete
type: 'TOGGLE_BLOCK_HIGHLIGHT',
[15833] Fix | Delete
clientId,
[15834] Fix | Delete
isHighlighted
[15835] Fix | Delete
};
[15836] Fix | Delete
}
[15837] Fix | Delete
[15838] Fix | Delete
/**
[15839] Fix | Delete
* Action that "flashes" the block with a given `clientId` by rhythmically highlighting it.
[15840] Fix | Delete
*
[15841] Fix | Delete
* @param {string} clientId Target block client ID.
[15842] Fix | Delete
*/
[15843] Fix | Delete
const flashBlock = clientId => async ({
[15844] Fix | Delete
dispatch
[15845] Fix | Delete
}) => {
[15846] Fix | Delete
dispatch(toggleBlockHighlight(clientId, true));
[15847] Fix | Delete
await new Promise(resolve => setTimeout(resolve, 150));
[15848] Fix | Delete
dispatch(toggleBlockHighlight(clientId, false));
[15849] Fix | Delete
};
[15850] Fix | Delete
[15851] Fix | Delete
/**
[15852] Fix | Delete
* Action that sets whether a block has controlled inner blocks.
[15853] Fix | Delete
*
[15854] Fix | Delete
* @param {string} clientId The block's clientId.
[15855] Fix | Delete
* @param {boolean} hasControlledInnerBlocks True if the block's inner blocks are controlled.
[15856] Fix | Delete
*/
[15857] Fix | Delete
function setHasControlledInnerBlocks(clientId, hasControlledInnerBlocks) {
[15858] Fix | Delete
return {
[15859] Fix | Delete
type: 'SET_HAS_CONTROLLED_INNER_BLOCKS',
[15860] Fix | Delete
hasControlledInnerBlocks,
[15861] Fix | Delete
clientId
[15862] Fix | Delete
};
[15863] Fix | Delete
}
[15864] Fix | Delete
[15865] Fix | Delete
/**
[15866] Fix | Delete
* Action that sets whether given blocks are visible on the canvas.
[15867] Fix | Delete
*
[15868] Fix | Delete
* @param {Record<string,boolean>} updates For each block's clientId, its new visibility setting.
[15869] Fix | Delete
*/
[15870] Fix | Delete
function setBlockVisibility(updates) {
[15871] Fix | Delete
return {
[15872] Fix | Delete
type: 'SET_BLOCK_VISIBILITY',
[15873] Fix | Delete
updates
[15874] Fix | Delete
};
[15875] Fix | Delete
}
[15876] Fix | Delete
[15877] Fix | Delete
/**
[15878] Fix | Delete
* Action that sets whether a block is being temporarily edited as blocks.
[15879] Fix | Delete
*
[15880] Fix | Delete
* DO-NOT-USE in production.
[15881] Fix | Delete
* This action is created for internal/experimental only usage and may be
[15882] Fix | Delete
* removed anytime without any warning, causing breakage on any plugin or theme invoking it.
[15883] Fix | Delete
*
[15884] Fix | Delete
* @param {?string} temporarilyEditingAsBlocks The block's clientId being temporarily edited as blocks.
[15885] Fix | Delete
* @param {?string} focusModeToRevert The focus mode to revert after temporarily edit as blocks finishes.
[15886] Fix | Delete
*/
[15887] Fix | Delete
function __unstableSetTemporarilyEditingAsBlocks(temporarilyEditingAsBlocks, focusModeToRevert) {
[15888] Fix | Delete
return {
[15889] Fix | Delete
type: 'SET_TEMPORARILY_EDITING_AS_BLOCKS',
[15890] Fix | Delete
temporarilyEditingAsBlocks,
[15891] Fix | Delete
focusModeToRevert
[15892] Fix | Delete
};
[15893] Fix | Delete
}
[15894] Fix | Delete
[15895] Fix | Delete
/**
[15896] Fix | Delete
* Interface for inserter media requests.
[15897] Fix | Delete
*
[15898] Fix | Delete
* @typedef {Object} InserterMediaRequest
[15899] Fix | Delete
* @property {number} per_page How many items to fetch per page.
[15900] Fix | Delete
* @property {string} search The search term to use for filtering the results.
[15901] Fix | Delete
*/
[15902] Fix | Delete
[15903] Fix | Delete
/**
[15904] Fix | Delete
* Interface for inserter media responses. Any media resource should
[15905] Fix | Delete
* map their response to this interface, in order to create the core
[15906] Fix | Delete
* WordPress media blocks (image, video, audio).
[15907] Fix | Delete
*
[15908] Fix | Delete
* @typedef {Object} InserterMediaItem
[15909] Fix | Delete
* @property {string} title The title of the media item.
[15910] Fix | Delete
* @property {string} url The source url of the media item.
[15911] Fix | Delete
* @property {string} [previewUrl] The preview source url of the media item to display in the media list.
[15912] Fix | Delete
* @property {number} [id] The WordPress id of the media item.
[15913] Fix | Delete
* @property {number|string} [sourceId] The id of the media item from external source.
[15914] Fix | Delete
* @property {string} [alt] The alt text of the media item.
[15915] Fix | Delete
* @property {string} [caption] The caption of the media item.
[15916] Fix | Delete
*/
[15917] Fix | Delete
[15918] Fix | Delete
/**
[15919] Fix | Delete
* Registers a new inserter media category. Once registered, the media category is
[15920] Fix | Delete
* available in the inserter's media tab.
[15921] Fix | Delete
*
[15922] Fix | Delete
* The following interfaces are used:
[15923] Fix | Delete
*
[15924] Fix | Delete
* _Type Definition_
[15925] Fix | Delete
*
[15926] Fix | Delete
* - _InserterMediaRequest_ `Object`: Interface for inserter media requests.
[15927] Fix | Delete
*
[15928] Fix | Delete
* _Properties_
[15929] Fix | Delete
*
[15930] Fix | Delete
* - _per_page_ `number`: How many items to fetch per page.
[15931] Fix | Delete
* - _search_ `string`: The search term to use for filtering the results.
[15932] Fix | Delete
*
[15933] Fix | Delete
* _Type Definition_
[15934] Fix | Delete
*
[15935] Fix | Delete
* - _InserterMediaItem_ `Object`: Interface for inserter media responses. Any media resource should
[15936] Fix | Delete
* map their response to this interface, in order to create the core
[15937] Fix | Delete
* WordPress media blocks (image, video, audio).
[15938] Fix | Delete
*
[15939] Fix | Delete
* _Properties_
[15940] Fix | Delete
*
[15941] Fix | Delete
* - _title_ `string`: The title of the media item.
[15942] Fix | Delete
* - _url_ `string: The source url of the media item.
[15943] Fix | Delete
* - _previewUrl_ `[string]`: The preview source url of the media item to display in the media list.
[15944] Fix | Delete
* - _id_ `[number]`: The WordPress id of the media item.
[15945] Fix | Delete
* - _sourceId_ `[number|string]`: The id of the media item from external source.
[15946] Fix | Delete
* - _alt_ `[string]`: The alt text of the media item.
[15947] Fix | Delete
* - _caption_ `[string]`: The caption of the media item.
[15948] Fix | Delete
*
[15949] Fix | Delete
* @param {InserterMediaCategory} category The inserter media category to register.
[15950] Fix | Delete
*
[15951] Fix | Delete
* @example
[15952] Fix | Delete
* ```js
[15953] Fix | Delete
*
[15954] Fix | Delete
* wp.data.dispatch('core/block-editor').registerInserterMediaCategory( {
[15955] Fix | Delete
* name: 'openverse',
[15956] Fix | Delete
* labels: {
[15957] Fix | Delete
* name: 'Openverse',
[15958] Fix | Delete
* search_items: 'Search Openverse',
[15959] Fix | Delete
* },
[15960] Fix | Delete
* mediaType: 'image',
[15961] Fix | Delete
* async fetch( query = {} ) {
[15962] Fix | Delete
* const defaultArgs = {
[15963] Fix | Delete
* mature: false,
[15964] Fix | Delete
* excluded_source: 'flickr,inaturalist,wikimedia',
[15965] Fix | Delete
* license: 'pdm,cc0',
[15966] Fix | Delete
* };
[15967] Fix | Delete
* const finalQuery = { ...query, ...defaultArgs };
[15968] Fix | Delete
* // Sometimes you might need to map the supported request params according to `InserterMediaRequest`.
[15969] Fix | Delete
* // interface. In this example the `search` query param is named `q`.
[15970] Fix | Delete
* const mapFromInserterMediaRequest = {
[15971] Fix | Delete
* per_page: 'page_size',
[15972] Fix | Delete
* search: 'q',
[15973] Fix | Delete
* };
[15974] Fix | Delete
* const url = new URL( 'https://api.openverse.org/v1/images/' );
[15975] Fix | Delete
* Object.entries( finalQuery ).forEach( ( [ key, value ] ) => {
[15976] Fix | Delete
* const queryKey = mapFromInserterMediaRequest[ key ] || key;
[15977] Fix | Delete
* url.searchParams.set( queryKey, value );
[15978] Fix | Delete
* } );
[15979] Fix | Delete
* const response = await window.fetch( url, {
[15980] Fix | Delete
* headers: {
[15981] Fix | Delete
* 'User-Agent': 'WordPress/inserter-media-fetch',
[15982] Fix | Delete
* },
[15983] Fix | Delete
* } );
[15984] Fix | Delete
* const jsonResponse = await response.json();
[15985] Fix | Delete
* const results = jsonResponse.results;
[15986] Fix | Delete
* return results.map( ( result ) => ( {
[15987] Fix | Delete
* ...result,
[15988] Fix | Delete
* // If your response result includes an `id` prop that you want to access later, it should
[15989] Fix | Delete
* // be mapped to `InserterMediaItem`'s `sourceId` prop. This can be useful if you provide
[15990] Fix | Delete
* // a report URL getter.
[15991] Fix | Delete
* // Additionally you should always clear the `id` value of your response results because
[15992] Fix | Delete
* // it is used to identify WordPress media items.
[15993] Fix | Delete
* sourceId: result.id,
[15994] Fix | Delete
* id: undefined,
[15995] Fix | Delete
* caption: result.caption,
[15996] Fix | Delete
* previewUrl: result.thumbnail,
[15997] Fix | Delete
* } ) );
[15998] Fix | Delete
* },
[15999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function