tag, favicon...etc.
*
* @async
* @param {string} url the URL to request details from.
* @param {Object?} options any options to pass to the underlying fetch.
* @example
* ```js
* import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';
*
* //...
*
* export function initialize( id, settings ) {
*
* settings.__experimentalFetchUrlData = (
* url
* ) => fetchUrlData( url );
* ```
* @return {Promise< WPRemoteUrlData[] >} Remote URL data.
*/
const fetchUrlData = async function (url) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const endpoint = '/wp-block-editor/v1/url-details';
const args = {
url: (0,external_wp_url_namespaceObject.prependHTTP)(url)
};
if (!(0,external_wp_url_namespaceObject.isURL)(url)) {
return Promise.reject(`${url} is not a valid URL.`);
} // Test for "http" based URL as it is possible for valid
// yet unusable URLs such as `tel:123456` to be passed.
const protocol = (0,external_wp_url_namespaceObject.getProtocol)(url);
if (!protocol || !(0,external_wp_url_namespaceObject.isValidProtocol)(protocol) || !protocol.startsWith('http') || !/^https?:\/\/[^\/\s]/i.test(url)) {
return Promise.reject(`${url} does not have a valid protocol. URLs must be "http" based`);
}
if (CACHE.has(url)) {
return CACHE.get(url);
}
return external_wp_apiFetch_default()({
path: (0,external_wp_url_namespaceObject.addQueryArgs)(endpoint, args),
...options
}).then(res => {
CACHE.set(url, res);
return res;
});
};
/* harmony default export */ var _experimental_fetch_url_data = (fetchUrlData);
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js
// EXTERNAL MODULE: ./node_modules/memize/index.js
var memize = __webpack_require__(9756);
var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/memoize.js
/**
* External dependencies
*/
// re-export due to restrictive esModuleInterop setting
/* harmony default export */ var memoize = ((memize_default()));
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/constants.js
let Status;
(function (Status) {
Status["Idle"] = "IDLE";
Status["Resolving"] = "RESOLVING";
Status["Error"] = "ERROR";
Status["Success"] = "SUCCESS";
})(Status || (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: () => function () {
const {
getIsResolving,
hasFinishedResolution
} = selectors;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
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
*/
/**
* 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 { useDispatch } from '@wordpress/data';
* import { useCallback } from '@wordpress/element';
* 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) {
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
enabled: true
};
const {
editEntityRecord,
saveEditedEntityRecord
} = (0,external_wp_data_namespaceObject.useDispatch)(store);
const mutations = (0,external_wp_element_namespaceObject.useMemo)(() => ({
edit: record => editEntityRecord(kind, name, recordId, record),
save: function () {
let saveOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return saveEditedEntityRecord(kind, name, recordId, {
throwOnError: true,
...saveOptions
});
}
}), [recordId]);
const {
editedRecord,
hasEdits
} = (0,external_wp_data_namespaceObject.useSelect)(select => ({
editedRecord: select(store).getEditedEntityRecord(kind, name, recordId),
hasEdits: select(store).hasEditsForEntityRecord(kind, name, recordId)
}), [kind, name, recordId]);
const {
data: record,
...querySelectRest
} = useQuerySelect(query => {
if (!options.enabled) {
return null;
}
return query(store).getEntityRecord(kind, name, recordId);
}, [kind, name, recordId, options.enabled]);
return {
record,
editedRecord,
hasEdits,
...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 { useEntityRecord } 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) {
let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
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]);
return {
records,
...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] = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return 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')] = key => saveEntityRecord(kind, name, key);
result[getMethodName(kind, name, 'delete')] = (key, query) => deleteEntityRecord(kind, name, key, query);
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());
(0,external_wp_data_namespaceObject.register)(store);
}();
(window.wp = window.wp || {}).coreData = __webpack_exports__;
/******/ })()
;