) & MemizeMemoizedFunction} Memoized function.
*/
function memize(fn, options) {
var size = 0;
/** @type {?MemizeCacheNode|undefined} */
var head;
/** @type {?MemizeCacheNode|undefined} */
var tail;
options = options || {};
function memoized(/* ...args */) {
var node = head,
len = arguments.length,
args,
i;
searchCache: while (node) {
// Perform a shallow equality test to confirm that whether the node
// under test is a candidate for the arguments passed. Two arrays
// are shallowly equal if their length matches and each entry is
// strictly equal between the two sets. Avoid abstracting to a
// function which could incur an arguments leaking deoptimization.
// Check whether node arguments match arguments length
if (node.args.length !== arguments.length) {
node = node.next;
continue;
}
// Check whether node arguments match arguments values
for (i = 0; i < len; i++) {
if (node.args[i] !== arguments[i]) {
node = node.next;
continue searchCache;
}
}
// At this point we can assume we've found a match
// Surface matched node to head if not already
if (node !== head) {
// As tail, shift to previous. Must only shift if not also
// head, since if both head and tail, there is no previous.
if (node === tail) {
tail = node.prev;
}
// Adjust siblings to point to each other. If node was tail,
// this also handles new tail's empty `next` assignment.
/** @type {MemizeCacheNode} */ (node.prev).next = node.next;
if (node.next) {
node.next.prev = node.prev;
}
node.next = head;
node.prev = null;
/** @type {MemizeCacheNode} */ (head).prev = node;
head = node;
}
// Return immediately
return node.val;
}
// No cached value found. Continue to insertion phase:
// Create a copy of arguments (avoid leaking deoptimization)
args = new Array(len);
for (i = 0; i < len; i++) {
args[i] = arguments[i];
}
node = {
args: args,
// Generate the result from original function
val: fn.apply(null, args),
};
// Don't need to check whether node is already head, since it would
// have been returned above already if it was
// Shift existing head down list
if (head) {
head.prev = node;
node.next = head;
} else {
// If no head, follows that there's no tail (at initial or reset)
tail = node;
}
// Trim tail if we're reached max size and are pending cache insertion
if (size === /** @type {MemizeOptions} */ (options).maxSize) {
tail = /** @type {MemizeCacheNode} */ (tail).prev;
/** @type {MemizeCacheNode} */ (tail).next = null;
} else {
size++;
}
head = node;
return node.val;
}
memoized.clear = function () {
head = null;
tail = null;
size = 0;
};
// Ignore reason: There's not a clear solution to create an intersection of
// the function with additional properties, where the goal is to retain the
// function signature of the incoming argument and add control properties
// on the return value.
// @ts-ignore
return memoized;
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/memoize.js
/**
* External dependencies
*/
// re-export due to restrictive esModuleInterop setting
/* harmony default export */ const memoize = (memize);
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/constants.js
let Status = /*#__PURE__*/function (Status) {
Status["Idle"] = "IDLE";
Status["Resolving"] = "RESOLVING";
Status["Error"] = "ERROR";
Status["Success"] = "SUCCESS";
return Status;
}({});
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-query-select.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
/**
* Like useSelect, but the selectors return objects containing
* both the original data AND the resolution info.
*
* @since 6.1.0 Introduced in WordPress core.
* @private
*
* @param {Function} mapQuerySelect see useSelect
* @param {Array} deps see useSelect
*
* @example
* ```js
* import { useQuerySelect } from '@wordpress/data';
* import { store as coreDataStore } from '@wordpress/core-data';
*
* function PageTitleDisplay( { id } ) {
* const { data: page, isResolving } = useQuerySelect( ( query ) => {
* return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )
* }, [ id ] );
*
* if ( isResolving ) {
* return 'Loading...';
* }
*
* return page.title;
* }
*
* // Rendered in the application:
* //
* ```
*
* In the above example, when `PageTitleDisplay` is rendered into an
* application, the page and the resolution details will be retrieved from
* the store state using the `mapSelect` callback on `useQuerySelect`.
*
* If the id prop changes then any page in the state for that id is
* retrieved. If the id prop doesn't change and other props are passed in
* that do change, the title will not change because the dependency is just
* the id.
* @see useSelect
*
* @return {QuerySelectResponse} Queried data.
*/
function useQuerySelect(mapQuerySelect, deps) {
return (0,external_wp_data_namespaceObject.useSelect)((select, registry) => {
const resolve = store => enrichSelectors(select(store));
return mapQuerySelect(resolve, registry);
}, deps);
}
/**
* Transform simple selectors into ones that return an object with the
* original return value AND the resolution info.
*
* @param {Object} selectors Selectors to enrich
* @return {EnrichedSelectors} Enriched selectors
*/
const enrichSelectors = memoize(selectors => {
const resolvers = {};
for (const selectorName in selectors) {
if (META_SELECTORS.includes(selectorName)) {
continue;
}
Object.defineProperty(resolvers, selectorName, {
get: () => (...args) => {
const {
getIsResolving,
hasFinishedResolution
} = selectors;
const isResolving = !!getIsResolving(selectorName, args);
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
const data = selectors[selectorName](...args);
let status;
if (isResolving) {
status = Status.Resolving;
} else if (hasResolved) {
if (data) {
status = Status.Success;
} else {
status = Status.Error;
}
} else {
status = Status.Idle;
}
return {
data,
status,
isResolving,
hasResolved
};
}
});
}
return resolvers;
});
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-entity-record.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const use_entity_record_EMPTY_OBJECT = {};
/**
* Resolves the specified entity record.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
* @param recordId ID of the requested entity record.
* @param options Optional hook options.
* @example
* ```js
* import { useEntityRecord } from '@wordpress/core-data';
*
* function PageTitleDisplay( { id } ) {
* const { record, isResolving } = useEntityRecord( 'postType', 'page', id );
*
* if ( isResolving ) {
* return 'Loading...';
* }
*
* return record.title;
* }
*
* // Rendered in the application:
* //
* ```
*
* In the above example, when `PageTitleDisplay` is rendered into an
* application, the page and the resolution details will be retrieved from
* the store state using `getEntityRecord()`, or resolved if missing.
*
* @example
* ```js
* import { useCallback } from 'react';
* import { useDispatch } from '@wordpress/data';
* import { __ } from '@wordpress/i18n';
* import { TextControl } from '@wordpress/components';
* import { store as noticeStore } from '@wordpress/notices';
* import { useEntityRecord } from '@wordpress/core-data';
*
* function PageRenameForm( { id } ) {
* const page = useEntityRecord( 'postType', 'page', id );
* const { createSuccessNotice, createErrorNotice } =
* useDispatch( noticeStore );
*
* const setTitle = useCallback( ( title ) => {
* page.edit( { title } );
* }, [ page.edit ] );
*
* if ( page.isResolving ) {
* return 'Loading...';
* }
*
* async function onRename( event ) {
* event.preventDefault();
* try {
* await page.save();
* createSuccessNotice( __( 'Page renamed.' ), {
* type: 'snackbar',
* } );
* } catch ( error ) {
* createErrorNotice( error.message, { type: 'snackbar' } );
* }
* }
*
* return (
*
* );
* }
*
* // Rendered in the application:
* //
* ```
*
* In the above example, updating and saving the page title is handled
* via the `edit()` and `save()` mutation helpers provided by
* `useEntityRecord()`;
*
* @return Entity record data.
* @template RecordType
*/
function useEntityRecord(kind, name, recordId, options = {
enabled: true
}) {
const {
editEntityRecord,
saveEditedEntityRecord
} = (0,external_wp_data_namespaceObject.useDispatch)(store);
const mutations = (0,external_wp_element_namespaceObject.useMemo)(() => ({
edit: (record, editOptions = {}) => editEntityRecord(kind, name, recordId, record, editOptions),
save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
throwOnError: true,
...saveOptions
})
}), [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]);
const {
editedRecord,
hasEdits,
edits
} = (0,external_wp_data_namespaceObject.useSelect)(select => {
if (!options.enabled) {
return {
editedRecord: use_entity_record_EMPTY_OBJECT,
hasEdits: false,
edits: use_entity_record_EMPTY_OBJECT
};
}
return {
editedRecord: select(store).getEditedEntityRecord(kind, name, recordId),
hasEdits: select(store).hasEditsForEntityRecord(kind, name, recordId),
edits: select(store).getEntityRecordNonTransientEdits(kind, name, recordId)
};
}, [kind, name, recordId, options.enabled]);
const {
data: record,
...querySelectRest
} = useQuerySelect(query => {
if (!options.enabled) {
return {
data: null
};
}
return query(store).getEntityRecord(kind, name, recordId);
}, [kind, name, recordId, options.enabled]);
return {
record,
editedRecord,
hasEdits,
edits,
...querySelectRest,
...mutations
};
}
function __experimentalUseEntityRecord(kind, name, recordId, options) {
external_wp_deprecated_default()(`wp.data.__experimentalUseEntityRecord`, {
alternative: 'wp.data.useEntityRecord',
since: '6.1'
});
return useEntityRecord(kind, name, recordId, options);
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-entity-records.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const use_entity_records_EMPTY_ARRAY = [];
/**
* Resolves the specified entity records.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
* @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
* @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
* @param options Optional hook options.
* @example
* ```js
* import { useEntityRecords } from '@wordpress/core-data';
*
* function PageTitlesList() {
* const { records, isResolving } = useEntityRecords( 'postType', 'page' );
*
* if ( isResolving ) {
* return 'Loading...';
* }
*
* return (
*
* {records.map(( page ) => (
* - { page.title }
* ))}
*
* );
* }
*
* // Rendered in the application:
* //
* ```
*
* In the above example, when `PageTitlesList` is rendered into an
* application, the list of records and the resolution details will be retrieved from
* the store state using `getEntityRecords()`, or resolved if missing.
*
* @return Entity records data.
* @template RecordType
*/
function useEntityRecords(kind, name, queryArgs = {}, options = {
enabled: true
}) {
// Serialize queryArgs to a string that can be safely used as a React dep.
// We can't just pass queryArgs as one of the deps, because if it is passed
// as an object literal, then it will be a different object on each call even
// if the values remain the same.
const queryAsString = (0,external_wp_url_namespaceObject.addQueryArgs)('', queryArgs);
const {
data: records,
...rest
} = useQuerySelect(query => {
if (!options.enabled) {
return {
// Avoiding returning a new reference on every execution.
data: use_entity_records_EMPTY_ARRAY
};
}
return query(store).getEntityRecords(kind, name, queryArgs);
}, [kind, name, queryAsString, options.enabled]);
const {
totalItems,
totalPages
} = (0,external_wp_data_namespaceObject.useSelect)(select => {
if (!options.enabled) {
return {
totalItems: null,
totalPages: null
};
}
return {
totalItems: select(store).getEntityRecordsTotalItems(kind, name, queryArgs),
totalPages: select(store).getEntityRecordsTotalPages(kind, name, queryArgs)
};
}, [kind, name, queryAsString, options.enabled]);
return {
records,
totalItems,
totalPages,
...rest
};
}
function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
external_wp_deprecated_default()(`wp.data.__experimentalUseEntityRecords`, {
alternative: 'wp.data.useEntityRecords',
since: '6.1'
});
return useEntityRecords(kind, name, queryArgs, options);
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-resource-permissions.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Resolves resource permissions.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param resource The resource in question, e.g. media.
* @param id ID of a specific resource entry, if needed, e.g. 10.
*
* @example
* ```js
* import { useResourcePermissions } from '@wordpress/core-data';
*
* function PagesList() {
* const { canCreate, isResolving } = useResourcePermissions( 'pages' );
*
* if ( isResolving ) {
* return 'Loading ...';
* }
*
* return (
*
* {canCreate ? () : false}
* // ...
*
* );
* }
*
* // Rendered in the application:
* //
* ```
*
* @example
* ```js
* import { useResourcePermissions } from '@wordpress/core-data';
*
* function Page({ pageId }) {
* const {
* canCreate,
* canUpdate,
* canDelete,
* isResolving
* } = useResourcePermissions( 'pages', pageId );
*
* if ( isResolving ) {
* return 'Loading ...';
* }
*
* return (
*
* {canCreate ? () : false}
* {canUpdate ? () : false}
* {canDelete ? () : false}
* // ...
*
* );
* }
*
* // Rendered in the application:
* //
* ```
*
* In the above example, when `PagesList` is rendered into an
* application, the appropriate permissions and the resolution details will be retrieved from
* the store state using `canUser()`, or resolved if missing.
*
* @return Entity records data.
* @template IdType
*/
function useResourcePermissions(resource, id) {
return useQuerySelect(resolve => {
const {
canUser
} = resolve(store);
const create = canUser('create', resource);
if (!id) {
const read = canUser('read', resource);
const isResolving = create.isResolving || read.isResolving;
const hasResolved = create.hasResolved && read.hasResolved;
let status = Status.Idle;
if (isResolving) {
status = Status.Resolving;
} else if (hasResolved) {
status = Status.Success;
}
return {
status,
isResolving,
hasResolved,
canCreate: create.hasResolved && create.data,
canRead: read.hasResolved && read.data
};
}
const read = canUser('read', resource, id);
const update = canUser('update', resource, id);
const _delete = canUser('delete', resource, id);
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
let status = Status.Idle;
if (isResolving) {
status = Status.Resolving;
} else if (hasResolved) {
status = Status.Success;
}
return {
status,
isResolving,
hasResolved,
canRead: hasResolved && read.data,
canCreate: hasResolved && create.data,
canUpdate: hasResolved && update.data,
canDelete: hasResolved && _delete.data
};
}, [resource, id]);
}
function __experimentalUseResourcePermissions(resource, id) {
external_wp_deprecated_default()(`wp.data.__experimentalUseResourcePermissions`, {
alternative: 'wp.data.useResourcePermissions',
since: '6.1'
});
return useResourcePermissions(resource, id);
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/index.js
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
// The "kind" and the "name" of the entity are combined to generate these shortcuts.
const entitySelectors = rootEntitiesConfig.reduce((result, entity) => {
const {
kind,
name
} = entity;
result[getMethodName(kind, name)] = (state, key, query) => getEntityRecord(state, kind, name, key, query);
result[getMethodName(kind, name, 'get', true)] = (state, query) => getEntityRecords(state, kind, name, query);
return result;
}, {});
const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
const {
kind,
name
} = entity;
result[getMethodName(kind, name)] = (key, query) => resolvers_getEntityRecord(kind, name, key, query);
const pluralMethodName = getMethodName(kind, name, 'get', true);
result[pluralMethodName] = (...args) => resolvers_getEntityRecords(kind, name, ...args);
result[pluralMethodName].shouldInvalidate = action => resolvers_getEntityRecords.shouldInvalidate(action, kind, name);
return result;
}, {});
const entityActions = rootEntitiesConfig.reduce((result, entity) => {
const {
kind,
name
} = entity;
result[getMethodName(kind, name, 'save')] = (record, options) => saveEntityRecord(kind, name, record, options);
result[getMethodName(kind, name, 'delete')] = (key, query, options) => deleteEntityRecord(kind, name, key, query, options);
return result;
}, {});
const storeConfig = () => ({
reducer: build_module_reducer,
actions: {
...build_module_actions_namespaceObject,
...entityActions,
...createLocksActions()
},
selectors: {
...build_module_selectors_namespaceObject,
...entitySelectors
},
resolvers: {
...resolvers_namespaceObject,
...entityResolvers
}
});
/**
* Store definition for the code data namespace.
*
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
*/
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig());
unlock(store).registerPrivateSelectors(private_selectors_namespaceObject);
(0,external_wp_data_namespaceObject.register)(store); // Register store after unlocking private selectors to allow resolvers to use them.
})();
(window.wp = window.wp || {}).coreData = __webpack_exports__;
/******/ })()
;