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
}
[12500] Fix | Delete
[12501] Fix | Delete
/**
[12502] Fix | Delete
* Returns the insertion point, the index at which the new inserted block would
[12503] Fix | Delete
* be placed. Defaults to the last index.
[12504] Fix | Delete
*
[12505] Fix | Delete
* @param {Object} state Editor state.
[12506] Fix | Delete
*
[12507] Fix | Delete
* @return {Object} Insertion point object with `rootClientId`, `index`.
[12508] Fix | Delete
*/
[12509] Fix | Delete
const getBlockInsertionPoint = (0,external_wp_data_namespaceObject.createSelector)(state => {
[12510] Fix | Delete
let rootClientId, index;
[12511] Fix | Delete
const {
[12512] Fix | Delete
insertionPoint,
[12513] Fix | Delete
selection: {
[12514] Fix | Delete
selectionEnd
[12515] Fix | Delete
}
[12516] Fix | Delete
} = state;
[12517] Fix | Delete
if (insertionPoint !== null) {
[12518] Fix | Delete
return insertionPoint;
[12519] Fix | Delete
}
[12520] Fix | Delete
const {
[12521] Fix | Delete
clientId
[12522] Fix | Delete
} = selectionEnd;
[12523] Fix | Delete
if (clientId) {
[12524] Fix | Delete
rootClientId = getBlockRootClientId(state, clientId) || undefined;
[12525] Fix | Delete
index = getBlockIndex(state, selectionEnd.clientId) + 1;
[12526] Fix | Delete
} else {
[12527] Fix | Delete
index = getBlockOrder(state).length;
[12528] Fix | Delete
}
[12529] Fix | Delete
return {
[12530] Fix | Delete
rootClientId,
[12531] Fix | Delete
index
[12532] Fix | Delete
};
[12533] Fix | Delete
}, state => [state.insertionPoint, state.selection.selectionEnd.clientId, state.blocks.parents, state.blocks.order]);
[12534] Fix | Delete
[12535] Fix | Delete
/**
[12536] Fix | Delete
* Returns true if we should show the block insertion point.
[12537] Fix | Delete
*
[12538] Fix | Delete
* @param {Object} state Global application state.
[12539] Fix | Delete
*
[12540] Fix | Delete
* @return {?boolean} Whether the insertion point is visible or not.
[12541] Fix | Delete
*/
[12542] Fix | Delete
function isBlockInsertionPointVisible(state) {
[12543] Fix | Delete
return state.insertionPoint !== null;
[12544] Fix | Delete
}
[12545] Fix | Delete
[12546] Fix | Delete
/**
[12547] Fix | Delete
* Returns whether the blocks matches the template or not.
[12548] Fix | Delete
*
[12549] Fix | Delete
* @param {boolean} state
[12550] Fix | Delete
* @return {?boolean} Whether the template is valid or not.
[12551] Fix | Delete
*/
[12552] Fix | Delete
function isValidTemplate(state) {
[12553] Fix | Delete
return state.template.isValid;
[12554] Fix | Delete
}
[12555] Fix | Delete
[12556] Fix | Delete
/**
[12557] Fix | Delete
* Returns the defined block template
[12558] Fix | Delete
*
[12559] Fix | Delete
* @param {boolean} state
[12560] Fix | Delete
*
[12561] Fix | Delete
* @return {?Array} Block Template.
[12562] Fix | Delete
*/
[12563] Fix | Delete
function getTemplate(state) {
[12564] Fix | Delete
return state.settings.template;
[12565] Fix | Delete
}
[12566] Fix | Delete
[12567] Fix | Delete
/**
[12568] Fix | Delete
* Returns the defined block template lock. Optionally accepts a root block
[12569] Fix | Delete
* client ID as context, otherwise defaulting to the global context.
[12570] Fix | Delete
*
[12571] Fix | Delete
* @param {Object} state Editor state.
[12572] Fix | Delete
* @param {?string} rootClientId Optional block root client ID.
[12573] Fix | Delete
*
[12574] Fix | Delete
* @return {string|false} Block Template Lock
[12575] Fix | Delete
*/
[12576] Fix | Delete
function getTemplateLock(state, rootClientId) {
[12577] Fix | Delete
var _getBlockListSettings;
[12578] Fix | Delete
if (!rootClientId) {
[12579] Fix | Delete
var _state$settings$templ;
[12580] Fix | Delete
return (_state$settings$templ = state.settings.templateLock) !== null && _state$settings$templ !== void 0 ? _state$settings$templ : false;
[12581] Fix | Delete
}
[12582] Fix | Delete
return (_getBlockListSettings = getBlockListSettings(state, rootClientId)?.templateLock) !== null && _getBlockListSettings !== void 0 ? _getBlockListSettings : false;
[12583] Fix | Delete
}
[12584] Fix | Delete
[12585] Fix | Delete
/**
[12586] Fix | Delete
* Determines if the given block type is allowed to be inserted into the block list.
[12587] Fix | Delete
* This function is not exported and not memoized because using a memoized selector
[12588] Fix | Delete
* inside another memoized selector is just a waste of time.
[12589] Fix | Delete
*
[12590] Fix | Delete
* @param {Object} state Editor state.
[12591] Fix | Delete
* @param {string|Object} blockName The block type object, e.g., the response
[12592] Fix | Delete
* from the block directory; or a string name of
[12593] Fix | Delete
* an installed block type, e.g.' core/paragraph'.
[12594] Fix | Delete
* @param {?string} rootClientId Optional root client ID of block list.
[12595] Fix | Delete
*
[12596] Fix | Delete
* @return {boolean} Whether the given block type is allowed to be inserted.
[12597] Fix | Delete
*/
[12598] Fix | Delete
const canInsertBlockTypeUnmemoized = (state, blockName, rootClientId = null) => {
[12599] Fix | Delete
let blockType;
[12600] Fix | Delete
if (blockName && 'object' === typeof blockName) {
[12601] Fix | Delete
blockType = blockName;
[12602] Fix | Delete
blockName = blockType.name;
[12603] Fix | Delete
} else {
[12604] Fix | Delete
blockType = (0,external_wp_blocks_namespaceObject.getBlockType)(blockName);
[12605] Fix | Delete
}
[12606] Fix | Delete
if (!blockType) {
[12607] Fix | Delete
return false;
[12608] Fix | Delete
}
[12609] Fix | Delete
const {
[12610] Fix | Delete
allowedBlockTypes
[12611] Fix | Delete
} = getSettings(state);
[12612] Fix | Delete
const isBlockAllowedInEditor = checkAllowList(allowedBlockTypes, blockName, true);
[12613] Fix | Delete
if (!isBlockAllowedInEditor) {
[12614] Fix | Delete
return false;
[12615] Fix | Delete
}
[12616] Fix | Delete
const isLocked = !!getTemplateLock(state, rootClientId);
[12617] Fix | Delete
if (isLocked) {
[12618] Fix | Delete
return false;
[12619] Fix | Delete
}
[12620] Fix | Delete
if (getBlockEditingMode(state, rootClientId !== null && rootClientId !== void 0 ? rootClientId : '') === 'disabled') {
[12621] Fix | Delete
return false;
[12622] Fix | Delete
}
[12623] Fix | Delete
const parentBlockListSettings = getBlockListSettings(state, rootClientId);
[12624] Fix | Delete
[12625] Fix | Delete
// The parent block doesn't have settings indicating it doesn't support
[12626] Fix | Delete
// inner blocks, return false.
[12627] Fix | Delete
if (rootClientId && parentBlockListSettings === undefined) {
[12628] Fix | Delete
return false;
[12629] Fix | Delete
}
[12630] Fix | Delete
const parentName = getBlockName(state, rootClientId);
[12631] Fix | Delete
const parentBlockType = (0,external_wp_blocks_namespaceObject.getBlockType)(parentName);
[12632] Fix | Delete
[12633] Fix | Delete
// Look at the `blockType.allowedBlocks` field to determine whether this is an allowed child block.
[12634] Fix | Delete
const parentAllowedChildBlocks = parentBlockType?.allowedBlocks;
[12635] Fix | Delete
let hasParentAllowedBlock = checkAllowList(parentAllowedChildBlocks, blockName);
[12636] Fix | Delete
[12637] Fix | Delete
// The `allowedBlocks` block list setting can further limit which blocks are allowed children.
[12638] Fix | Delete
if (hasParentAllowedBlock !== false) {
[12639] Fix | Delete
const parentAllowedBlocks = parentBlockListSettings?.allowedBlocks;
[12640] Fix | Delete
const hasParentListAllowedBlock = checkAllowList(parentAllowedBlocks, blockName);
[12641] Fix | Delete
// Never downgrade the result from `true` to `null`
[12642] Fix | Delete
if (hasParentListAllowedBlock !== null) {
[12643] Fix | Delete
hasParentAllowedBlock = hasParentListAllowedBlock;
[12644] Fix | Delete
}
[12645] Fix | Delete
}
[12646] Fix | Delete
const blockAllowedParentBlocks = blockType.parent;
[12647] Fix | Delete
const hasBlockAllowedParent = checkAllowList(blockAllowedParentBlocks, parentName);
[12648] Fix | Delete
let hasBlockAllowedAncestor = true;
[12649] Fix | Delete
const blockAllowedAncestorBlocks = blockType.ancestor;
[12650] Fix | Delete
if (blockAllowedAncestorBlocks) {
[12651] Fix | Delete
const ancestors = [rootClientId, ...getBlockParents(state, rootClientId)];
[12652] Fix | Delete
hasBlockAllowedAncestor = ancestors.some(ancestorClientId => checkAllowList(blockAllowedAncestorBlocks, getBlockName(state, ancestorClientId)));
[12653] Fix | Delete
}
[12654] Fix | Delete
const canInsert = hasBlockAllowedAncestor && (hasParentAllowedBlock === null && hasBlockAllowedParent === null || hasParentAllowedBlock === true || hasBlockAllowedParent === true);
[12655] Fix | Delete
if (!canInsert) {
[12656] Fix | Delete
return canInsert;
[12657] Fix | Delete
}
[12658] Fix | Delete
[12659] Fix | Delete
/**
[12660] Fix | Delete
* This filter is an ad-hoc solution to prevent adding template parts inside post content.
[12661] Fix | Delete
* Conceptually, having a filter inside a selector is bad pattern so this code will be
[12662] Fix | Delete
* replaced by a declarative API that doesn't the following drawbacks:
[12663] Fix | Delete
*
[12664] Fix | Delete
* Filters are not reactive: Upon switching between "template mode" and non "template mode",
[12665] Fix | Delete
* the filter and selector won't necessarily be executed again. For now, it doesn't matter much
[12666] Fix | Delete
* because you can't switch between the two modes while the inserter stays open.
[12667] Fix | Delete
*
[12668] Fix | Delete
* Filters are global: Once they're defined, they will affect all editor instances and all registries.
[12669] Fix | Delete
* An ideal API would only affect specific editor instances.
[12670] Fix | Delete
*/
[12671] Fix | Delete
return (0,external_wp_hooks_namespaceObject.applyFilters)('blockEditor.__unstableCanInsertBlockType', canInsert, blockType, rootClientId, {
[12672] Fix | Delete
// Pass bound selectors of the current registry. If we're in a nested
[12673] Fix | Delete
// context, the data will differ from the one selected from the root
[12674] Fix | Delete
// registry.
[12675] Fix | Delete
getBlock: getBlock.bind(null, state),
[12676] Fix | Delete
getBlockParentsByBlockName: getBlockParentsByBlockName.bind(null, state)
[12677] Fix | Delete
});
[12678] Fix | Delete
};
[12679] Fix | Delete
[12680] Fix | Delete
/**
[12681] Fix | Delete
* Determines if the given block type is allowed to be inserted into the block list.
[12682] Fix | Delete
*
[12683] Fix | Delete
* @param {Object} state Editor state.
[12684] Fix | Delete
* @param {string} blockName The name of the block type, e.g.' core/paragraph'.
[12685] Fix | Delete
* @param {?string} rootClientId Optional root client ID of block list.
[12686] Fix | Delete
*
[12687] Fix | Delete
* @return {boolean} Whether the given block type is allowed to be inserted.
[12688] Fix | Delete
*/
[12689] Fix | Delete
const canInsertBlockType = (0,external_wp_data_namespaceObject.createSelector)(canInsertBlockTypeUnmemoized, (state, blockName, rootClientId) => getInsertBlockTypeDependants(state, rootClientId));
[12690] Fix | Delete
[12691] Fix | Delete
/**
[12692] Fix | Delete
* Determines if the given blocks are allowed to be inserted into the block
[12693] Fix | Delete
* list.
[12694] Fix | Delete
*
[12695] Fix | Delete
* @param {Object} state Editor state.
[12696] Fix | Delete
* @param {string} clientIds The block client IDs to be inserted.
[12697] Fix | Delete
* @param {?string} rootClientId Optional root client ID of block list.
[12698] Fix | Delete
*
[12699] Fix | Delete
* @return {boolean} Whether the given blocks are allowed to be inserted.
[12700] Fix | Delete
*/
[12701] Fix | Delete
function canInsertBlocks(state, clientIds, rootClientId = null) {
[12702] Fix | Delete
return clientIds.every(id => canInsertBlockType(state, getBlockName(state, id), rootClientId));
[12703] Fix | Delete
}
[12704] Fix | Delete
[12705] Fix | Delete
/**
[12706] Fix | Delete
* Determines if the given block is allowed to be deleted.
[12707] Fix | Delete
*
[12708] Fix | Delete
* @param {Object} state Editor state.
[12709] Fix | Delete
* @param {string} clientId The block client Id.
[12710] Fix | Delete
*
[12711] Fix | Delete
* @return {boolean} Whether the given block is allowed to be removed.
[12712] Fix | Delete
*/
[12713] Fix | Delete
function canRemoveBlock(state, clientId) {
[12714] Fix | Delete
const attributes = getBlockAttributes(state, clientId);
[12715] Fix | Delete
if (attributes === null) {
[12716] Fix | Delete
return true;
[12717] Fix | Delete
}
[12718] Fix | Delete
if (attributes.lock?.remove !== undefined) {
[12719] Fix | Delete
return !attributes.lock.remove;
[12720] Fix | Delete
}
[12721] Fix | Delete
const rootClientId = getBlockRootClientId(state, clientId);
[12722] Fix | Delete
if (getTemplateLock(state, rootClientId)) {
[12723] Fix | Delete
return false;
[12724] Fix | Delete
}
[12725] Fix | Delete
return getBlockEditingMode(state, rootClientId) !== 'disabled';
[12726] Fix | Delete
}
[12727] Fix | Delete
[12728] Fix | Delete
/**
[12729] Fix | Delete
* Determines if the given blocks are allowed to be removed.
[12730] Fix | Delete
*
[12731] Fix | Delete
* @param {Object} state Editor state.
[12732] Fix | Delete
* @param {string} clientIds The block client IDs to be removed.
[12733] Fix | Delete
*
[12734] Fix | Delete
* @return {boolean} Whether the given blocks are allowed to be removed.
[12735] Fix | Delete
*/
[12736] Fix | Delete
function canRemoveBlocks(state, clientIds) {
[12737] Fix | Delete
return clientIds.every(clientId => canRemoveBlock(state, clientId));
[12738] Fix | Delete
}
[12739] Fix | Delete
[12740] Fix | Delete
/**
[12741] Fix | Delete
* Determines if the given block is allowed to be moved.
[12742] Fix | Delete
*
[12743] Fix | Delete
* @param {Object} state Editor state.
[12744] Fix | Delete
* @param {string} clientId The block client Id.
[12745] Fix | Delete
*
[12746] Fix | Delete
* @return {boolean | undefined} Whether the given block is allowed to be moved.
[12747] Fix | Delete
*/
[12748] Fix | Delete
function canMoveBlock(state, clientId) {
[12749] Fix | Delete
const attributes = getBlockAttributes(state, clientId);
[12750] Fix | Delete
if (attributes === null) {
[12751] Fix | Delete
return true;
[12752] Fix | Delete
}
[12753] Fix | Delete
if (attributes.lock?.move !== undefined) {
[12754] Fix | Delete
return !attributes.lock.move;
[12755] Fix | Delete
}
[12756] Fix | Delete
const rootClientId = getBlockRootClientId(state, clientId);
[12757] Fix | Delete
if (getTemplateLock(state, rootClientId) === 'all') {
[12758] Fix | Delete
return false;
[12759] Fix | Delete
}
[12760] Fix | Delete
return getBlockEditingMode(state, rootClientId) !== 'disabled';
[12761] Fix | Delete
}
[12762] Fix | Delete
[12763] Fix | Delete
/**
[12764] Fix | Delete
* Determines if the given blocks are allowed to be moved.
[12765] Fix | Delete
*
[12766] Fix | Delete
* @param {Object} state Editor state.
[12767] Fix | Delete
* @param {string} clientIds The block client IDs to be moved.
[12768] Fix | Delete
*
[12769] Fix | Delete
* @return {boolean} Whether the given blocks are allowed to be moved.
[12770] Fix | Delete
*/
[12771] Fix | Delete
function canMoveBlocks(state, clientIds) {
[12772] Fix | Delete
return clientIds.every(clientId => canMoveBlock(state, clientId));
[12773] Fix | Delete
}
[12774] Fix | Delete
[12775] Fix | Delete
/**
[12776] Fix | Delete
* Determines if the given block is allowed to be edited.
[12777] Fix | Delete
*
[12778] Fix | Delete
* @param {Object} state Editor state.
[12779] Fix | Delete
* @param {string} clientId The block client Id.
[12780] Fix | Delete
*
[12781] Fix | Delete
* @return {boolean} Whether the given block is allowed to be edited.
[12782] Fix | Delete
*/
[12783] Fix | Delete
function canEditBlock(state, clientId) {
[12784] Fix | Delete
const attributes = getBlockAttributes(state, clientId);
[12785] Fix | Delete
if (attributes === null) {
[12786] Fix | Delete
return true;
[12787] Fix | Delete
}
[12788] Fix | Delete
const {
[12789] Fix | Delete
lock
[12790] Fix | Delete
} = attributes;
[12791] Fix | Delete
[12792] Fix | Delete
// When the edit is true, we cannot edit the block.
[12793] Fix | Delete
return !lock?.edit;
[12794] Fix | Delete
}
[12795] Fix | Delete
[12796] Fix | Delete
/**
[12797] Fix | Delete
* Determines if the given block type can be locked/unlocked by a user.
[12798] Fix | Delete
*
[12799] Fix | Delete
* @param {Object} state Editor state.
[12800] Fix | Delete
* @param {(string|Object)} nameOrType Block name or type object.
[12801] Fix | Delete
*
[12802] Fix | Delete
* @return {boolean} Whether a given block type can be locked/unlocked.
[12803] Fix | Delete
*/
[12804] Fix | Delete
function canLockBlockType(state, nameOrType) {
[12805] Fix | Delete
if (!(0,external_wp_blocks_namespaceObject.hasBlockSupport)(nameOrType, 'lock', true)) {
[12806] Fix | Delete
return false;
[12807] Fix | Delete
}
[12808] Fix | Delete
[12809] Fix | Delete
// Use block editor settings as the default value.
[12810] Fix | Delete
return !!state.settings?.canLockBlocks;
[12811] Fix | Delete
}
[12812] Fix | Delete
[12813] Fix | Delete
/**
[12814] Fix | Delete
* Returns information about how recently and frequently a block has been inserted.
[12815] Fix | Delete
*
[12816] Fix | Delete
* @param {Object} state Global application state.
[12817] Fix | Delete
* @param {string} id A string which identifies the insert, e.g. 'core/block/12'
[12818] Fix | Delete
*
[12819] Fix | Delete
* @return {?{ time: number, count: number }} An object containing `time` which is when the last
[12820] Fix | Delete
* insert occurred as a UNIX epoch, and `count` which is
[12821] Fix | Delete
* the number of inserts that have occurred.
[12822] Fix | Delete
*/
[12823] Fix | Delete
function getInsertUsage(state, id) {
[12824] Fix | Delete
var _state$preferences$in;
[12825] Fix | Delete
return (_state$preferences$in = state.preferences.insertUsage?.[id]) !== null && _state$preferences$in !== void 0 ? _state$preferences$in : null;
[12826] Fix | Delete
}
[12827] Fix | Delete
[12828] Fix | Delete
/**
[12829] Fix | Delete
* Returns whether we can show a block type in the inserter
[12830] Fix | Delete
*
[12831] Fix | Delete
* @param {Object} state Global State
[12832] Fix | Delete
* @param {Object} blockType BlockType
[12833] Fix | Delete
* @param {?string} rootClientId Optional root client ID of block list.
[12834] Fix | Delete
*
[12835] Fix | Delete
* @return {boolean} Whether the given block type is allowed to be shown in the inserter.
[12836] Fix | Delete
*/
[12837] Fix | Delete
const canIncludeBlockTypeInInserter = (state, blockType, rootClientId) => {
[12838] Fix | Delete
if (!(0,external_wp_blocks_namespaceObject.hasBlockSupport)(blockType, 'inserter', true)) {
[12839] Fix | Delete
return false;
[12840] Fix | Delete
}
[12841] Fix | Delete
return canInsertBlockTypeUnmemoized(state, blockType.name, rootClientId);
[12842] Fix | Delete
};
[12843] Fix | Delete
[12844] Fix | Delete
/**
[12845] Fix | Delete
* Return a function to be used to tranform a block variation to an inserter item
[12846] Fix | Delete
*
[12847] Fix | Delete
* @param {Object} state Global State
[12848] Fix | Delete
* @param {Object} item Denormalized inserter item
[12849] Fix | Delete
* @return {Function} Function to transform a block variation to inserter item
[12850] Fix | Delete
*/
[12851] Fix | Delete
const getItemFromVariation = (state, item) => variation => {
[12852] Fix | Delete
const variationId = `${item.id}/${variation.name}`;
[12853] Fix | Delete
const {
[12854] Fix | Delete
time,
[12855] Fix | Delete
count = 0
[12856] Fix | Delete
} = getInsertUsage(state, variationId) || {};
[12857] Fix | Delete
return {
[12858] Fix | Delete
...item,
[12859] Fix | Delete
id: variationId,
[12860] Fix | Delete
icon: variation.icon || item.icon,
[12861] Fix | Delete
title: variation.title || item.title,
[12862] Fix | Delete
description: variation.description || item.description,
[12863] Fix | Delete
category: variation.category || item.category,
[12864] Fix | Delete
// If `example` is explicitly undefined for the variation, the preview will not be shown.
[12865] Fix | Delete
example: variation.hasOwnProperty('example') ? variation.example : item.example,
[12866] Fix | Delete
initialAttributes: {
[12867] Fix | Delete
...item.initialAttributes,
[12868] Fix | Delete
...variation.attributes
[12869] Fix | Delete
},
[12870] Fix | Delete
innerBlocks: variation.innerBlocks,
[12871] Fix | Delete
keywords: variation.keywords || item.keywords,
[12872] Fix | Delete
frecency: calculateFrecency(time, count)
[12873] Fix | Delete
};
[12874] Fix | Delete
};
[12875] Fix | Delete
[12876] Fix | Delete
/**
[12877] Fix | Delete
* Returns the calculated frecency.
[12878] Fix | Delete
*
[12879] Fix | Delete
* 'frecency' is a heuristic (https://en.wikipedia.org/wiki/Frecency)
[12880] Fix | Delete
* that combines block usage frequenty and recency.
[12881] Fix | Delete
*
[12882] Fix | Delete
* @param {number} time When the last insert occurred as a UNIX epoch
[12883] Fix | Delete
* @param {number} count The number of inserts that have occurred.
[12884] Fix | Delete
*
[12885] Fix | Delete
* @return {number} The calculated frecency.
[12886] Fix | Delete
*/
[12887] Fix | Delete
const calculateFrecency = (time, count) => {
[12888] Fix | Delete
if (!time) {
[12889] Fix | Delete
return count;
[12890] Fix | Delete
}
[12891] Fix | Delete
// The selector is cached, which means Date.now() is the last time that the
[12892] Fix | Delete
// relevant state changed. This suits our needs.
[12893] Fix | Delete
const duration = Date.now() - time;
[12894] Fix | Delete
switch (true) {
[12895] Fix | Delete
case duration < MILLISECONDS_PER_HOUR:
[12896] Fix | Delete
return count * 4;
[12897] Fix | Delete
case duration < MILLISECONDS_PER_DAY:
[12898] Fix | Delete
return count * 2;
[12899] Fix | Delete
case duration < MILLISECONDS_PER_WEEK:
[12900] Fix | Delete
return count / 2;
[12901] Fix | Delete
default:
[12902] Fix | Delete
return count / 4;
[12903] Fix | Delete
}
[12904] Fix | Delete
};
[12905] Fix | Delete
[12906] Fix | Delete
/**
[12907] Fix | Delete
* Returns a function that accepts a block type and builds an item to be shown
[12908] Fix | Delete
* in a specific context. It's used for building items for Inserter and available
[12909] Fix | Delete
* block Transfroms list.
[12910] Fix | Delete
*
[12911] Fix | Delete
* @param {Object} state Editor state.
[12912] Fix | Delete
* @param {Object} options Options object for handling the building of a block type.
[12913] Fix | Delete
* @param {string} options.buildScope The scope for which the item is going to be used.
[12914] Fix | Delete
* @return {Function} Function returns an item to be shown in a specific context (Inserter|Transforms list).
[12915] Fix | Delete
*/
[12916] Fix | Delete
const buildBlockTypeItem = (state, {
[12917] Fix | Delete
buildScope = 'inserter'
[12918] Fix | Delete
}) => blockType => {
[12919] Fix | Delete
const id = blockType.name;
[12920] Fix | Delete
let isDisabled = false;
[12921] Fix | Delete
if (!(0,external_wp_blocks_namespaceObject.hasBlockSupport)(blockType.name, 'multiple', true)) {
[12922] Fix | Delete
isDisabled = getBlocksByClientId(state, getClientIdsWithDescendants(state)).some(({
[12923] Fix | Delete
name
[12924] Fix | Delete
}) => name === blockType.name);
[12925] Fix | Delete
}
[12926] Fix | Delete
const {
[12927] Fix | Delete
time,
[12928] Fix | Delete
count = 0
[12929] Fix | Delete
} = getInsertUsage(state, id) || {};
[12930] Fix | Delete
const blockItemBase = {
[12931] Fix | Delete
id,
[12932] Fix | Delete
name: blockType.name,
[12933] Fix | Delete
title: blockType.title,
[12934] Fix | Delete
icon: blockType.icon,
[12935] Fix | Delete
isDisabled,
[12936] Fix | Delete
frecency: calculateFrecency(time, count)
[12937] Fix | Delete
};
[12938] Fix | Delete
if (buildScope === 'transform') {
[12939] Fix | Delete
return blockItemBase;
[12940] Fix | Delete
}
[12941] Fix | Delete
const inserterVariations = (0,external_wp_blocks_namespaceObject.getBlockVariations)(blockType.name, 'inserter');
[12942] Fix | Delete
return {
[12943] Fix | Delete
...blockItemBase,
[12944] Fix | Delete
initialAttributes: {},
[12945] Fix | Delete
description: blockType.description,
[12946] Fix | Delete
category: blockType.category,
[12947] Fix | Delete
keywords: blockType.keywords,
[12948] Fix | Delete
variations: inserterVariations,
[12949] Fix | Delete
example: blockType.example,
[12950] Fix | Delete
utility: 1 // Deprecated.
[12951] Fix | Delete
};
[12952] Fix | Delete
};
[12953] Fix | Delete
[12954] Fix | Delete
/**
[12955] Fix | Delete
* Determines the items that appear in the inserter. Includes both static
[12956] Fix | Delete
* items (e.g. a regular block type) and dynamic items (e.g. a reusable block).
[12957] Fix | Delete
*
[12958] Fix | Delete
* Each item object contains what's necessary to display a button in the
[12959] Fix | Delete
* inserter and handle its selection.
[12960] Fix | Delete
*
[12961] Fix | Delete
* The 'frecency' property is a heuristic (https://en.wikipedia.org/wiki/Frecency)
[12962] Fix | Delete
* that combines block usage frequenty and recency.
[12963] Fix | Delete
*
[12964] Fix | Delete
* Items are returned ordered descendingly by their 'utility' and 'frecency'.
[12965] Fix | Delete
*
[12966] Fix | Delete
* @param {Object} state Editor state.
[12967] Fix | Delete
* @param {?string} rootClientId Optional root client ID of block list.
[12968] Fix | Delete
*
[12969] Fix | Delete
* @return {WPEditorInserterItem[]} Items that appear in inserter.
[12970] Fix | Delete
*
[12971] Fix | Delete
* @typedef {Object} WPEditorInserterItem
[12972] Fix | Delete
* @property {string} id Unique identifier for the item.
[12973] Fix | Delete
* @property {string} name The type of block to create.
[12974] Fix | Delete
* @property {Object} initialAttributes Attributes to pass to the newly created block.
[12975] Fix | Delete
* @property {string} title Title of the item, as it appears in the inserter.
[12976] Fix | Delete
* @property {string} icon Dashicon for the item, as it appears in the inserter.
[12977] Fix | Delete
* @property {string} category Block category that the item is associated with.
[12978] Fix | Delete
* @property {string[]} keywords Keywords that can be searched to find this item.
[12979] Fix | Delete
* @property {boolean} isDisabled Whether or not the user should be prevented from inserting
[12980] Fix | Delete
* this item.
[12981] Fix | Delete
* @property {number} frecency Heuristic that combines frequency and recency.
[12982] Fix | Delete
*/
[12983] Fix | Delete
const getInserterItems = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (0,external_wp_data_namespaceObject.createSelector)((state, rootClientId = null, options = EMPTY_OBJECT) => {
[12984] Fix | Delete
const buildReusableBlockInserterItem = reusableBlock => {
[12985] Fix | Delete
const icon = !reusableBlock.wp_pattern_sync_status ? {
[12986] Fix | Delete
src: library_symbol,
[12987] Fix | Delete
foreground: 'var(--wp-block-synced-color)'
[12988] Fix | Delete
} : library_symbol;
[12989] Fix | Delete
const id = `core/block/${reusableBlock.id}`;
[12990] Fix | Delete
const {
[12991] Fix | Delete
time,
[12992] Fix | Delete
count = 0
[12993] Fix | Delete
} = getInsertUsage(state, id) || {};
[12994] Fix | Delete
const frecency = calculateFrecency(time, count);
[12995] Fix | Delete
return {
[12996] Fix | Delete
id,
[12997] Fix | Delete
name: 'core/block',
[12998] Fix | Delete
initialAttributes: {
[12999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function