PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/core-data/index.js +2168 -791 12.6.0 → 14.5.2 View file →
@@ -1,11 +1,11 @@
1 -/******/ (function() { // webpackBootstrap
2 -/******/ "use strict";
1 +/******/ (() => { // webpackBootstrap
3 2 /******/ var __webpack_modules__ = ({
4 3
5 -/***/ 3909:
6 -/***/ (function(module) {
4 +/***/ 2167:
5 +/***/ ((module) => {
7 6
7 +"use strict";
8 8
9 9
10 10 function _typeof(obj) {
11 11 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
@@ -313,8 +313,176 @@
313 313
314 314 module.exports = EquivalentKeyMap;
315 315
316 316
317 +/***/ }),
318 +
319 +/***/ 9756:
320 +/***/ ((module) => {
321 +
322 +/**
323 + * Memize options object.
324 + *
325 + * @typedef MemizeOptions
326 + *
327 + * @property {number} [maxSize] Maximum size of the cache.
328 + */
329 +
330 +/**
331 + * Internal cache entry.
332 + *
333 + * @typedef MemizeCacheNode
334 + *
335 + * @property {?MemizeCacheNode|undefined} [prev] Previous node.
336 + * @property {?MemizeCacheNode|undefined} [next] Next node.
337 + * @property {Array<*>} args Function arguments for cache
338 + * entry.
339 + * @property {*} val Function result.
340 + */
341 +
342 +/**
343 + * Properties of the enhanced function for controlling cache.
344 + *
345 + * @typedef MemizeMemoizedFunction
346 + *
347 + * @property {()=>void} clear Clear the cache.
348 + */
349 +
350 +/**
351 + * Accepts a function to be memoized, and returns a new memoized function, with
352 + * optional options.
353 + *
354 + * @template {Function} F
355 + *
356 + * @param {F} fn Function to memoize.
357 + * @param {MemizeOptions} [options] Options object.
358 + *
359 + * @return {F & MemizeMemoizedFunction} Memoized function.
360 + */
361 +function memize( fn, options ) {
362 + var size = 0;
363 +
364 + /** @type {?MemizeCacheNode|undefined} */
365 + var head;
366 +
367 + /** @type {?MemizeCacheNode|undefined} */
368 + var tail;
369 +
370 + options = options || {};
371 +
372 + function memoized( /* ...args */ ) {
373 + var node = head,
374 + len = arguments.length,
375 + args, i;
376 +
377 + searchCache: while ( node ) {
378 + // Perform a shallow equality test to confirm that whether the node
379 + // under test is a candidate for the arguments passed. Two arrays
380 + // are shallowly equal if their length matches and each entry is
381 + // strictly equal between the two sets. Avoid abstracting to a
382 + // function which could incur an arguments leaking deoptimization.
383 +
384 + // Check whether node arguments match arguments length
385 + if ( node.args.length !== arguments.length ) {
386 + node = node.next;
387 + continue;
388 + }
389 +
390 + // Check whether node arguments match arguments values
391 + for ( i = 0; i < len; i++ ) {
392 + if ( node.args[ i ] !== arguments[ i ] ) {
393 + node = node.next;
394 + continue searchCache;
395 + }
396 + }
397 +
398 + // At this point we can assume we've found a match
399 +
400 + // Surface matched node to head if not already
401 + if ( node !== head ) {
402 + // As tail, shift to previous. Must only shift if not also
403 + // head, since if both head and tail, there is no previous.
404 + if ( node === tail ) {
405 + tail = node.prev;
406 + }
407 +
408 + // Adjust siblings to point to each other. If node was tail,
409 + // this also handles new tail's empty `next` assignment.
410 + /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
411 + if ( node.next ) {
412 + node.next.prev = node.prev;
413 + }
414 +
415 + node.next = head;
416 + node.prev = null;
417 + /** @type {MemizeCacheNode} */ ( head ).prev = node;
418 + head = node;
419 + }
420 +
421 + // Return immediately
422 + return node.val;
423 + }
424 +
425 + // No cached value found. Continue to insertion phase:
426 +
427 + // Create a copy of arguments (avoid leaking deoptimization)
428 + args = new Array( len );
429 + for ( i = 0; i < len; i++ ) {
430 + args[ i ] = arguments[ i ];
431 + }
432 +
433 + node = {
434 + args: args,
435 +
436 + // Generate the result from original function
437 + val: fn.apply( null, args ),
438 + };
439 +
440 + // Don't need to check whether node is already head, since it would
441 + // have been returned above already if it was
442 +
443 + // Shift existing head down list
444 + if ( head ) {
445 + head.prev = node;
446 + node.next = head;
447 + } else {
448 + // If no head, follows that there's no tail (at initial or reset)
449 + tail = node;
450 + }
451 +
452 + // Trim tail if we're reached max size and are pending cache insertion
453 + if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
454 + tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
455 + /** @type {MemizeCacheNode} */ ( tail ).next = null;
456 + } else {
457 + size++;
458 + }
459 +
460 + head = node;
461 +
462 + return node.val;
463 + }
464 +
465 + memoized.clear = function() {
466 + head = null;
467 + tail = null;
468 + size = 0;
469 + };
470 +
471 + if ( false ) {}
472 +
473 + // Ignore reason: There's not a clear solution to create an intersection of
474 + // the function with additional properties, where the goal is to retain the
475 + // function signature of the incoming argument and add control properties
476 + // on the return value.
477 +
478 + // @ts-ignore
479 + return memoized;
480 +}
481 +
482 +module.exports = memize;
483 +
484 +
317 485 /***/ })
318 486
319 487 /******/ });
320 488 /************************************************************************/
@@ -343,23 +511,23 @@
343 511 /******/ }
344 512 /******/
345 513 /************************************************************************/
346 514 /******/ /* webpack/runtime/compat get default export */
347 -/******/ !function() {
515 +/******/ (() => {
348 516 /******/ // getDefaultExport function for compatibility with non-harmony modules
349 -/******/ __webpack_require__.n = function(module) {
517 +/******/ __webpack_require__.n = (module) => {
350 518 /******/ var getter = module && module.__esModule ?
351 -/******/ function() { return module['default']; } :
352 -/******/ function() { return module; };
519 +/******/ () => (module['default']) :
520 +/******/ () => (module);
353 521 /******/ __webpack_require__.d(getter, { a: getter });
354 522 /******/ return getter;
355 523 /******/ };
356 -/******/ }();
524 +/******/ })();
357 525 /******/
358 526 /******/ /* webpack/runtime/define property getters */
359 -/******/ !function() {
527 +/******/ (() => {
360 528 /******/ // define getter functions for harmony exports
361 -/******/ __webpack_require__.d = function(exports, definition) {
529 +/******/ __webpack_require__.d = (exports, definition) => {
362 530 /******/ for(var key in definition) {
363 531 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
364 532 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
365 533 /******/ }
@@ -364,42 +532,49 @@
364 532 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
365 533 /******/ }
366 534 /******/ }
367 535 /******/ };
368 -/******/ }();
536 +/******/ })();
369 537 /******/
370 538 /******/ /* webpack/runtime/hasOwnProperty shorthand */
371 -/******/ !function() {
372 -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
373 -/******/ }();
539 +/******/ (() => {
540 +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
541 +/******/ })();
374 542 /******/
375 543 /******/ /* webpack/runtime/make namespace object */
376 -/******/ !function() {
544 +/******/ (() => {
377 545 /******/ // define __esModule on exports
378 -/******/ __webpack_require__.r = function(exports) {
546 +/******/ __webpack_require__.r = (exports) => {
379 547 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
380 548 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
381 549 /******/ }
382 550 /******/ Object.defineProperty(exports, '__esModule', { value: true });
383 551 /******/ };
384 -/******/ }();
552 +/******/ })();
385 553 /******/
386 554 /************************************************************************/
387 555 var __webpack_exports__ = {};
388 -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
389 -!function() {
556 +// This entry need to be wrapped in an IIFE because it need to be in strict mode.
557 +(() => {
558 +"use strict";
390 559 // ESM COMPAT FLAG
391 560 __webpack_require__.r(__webpack_exports__);
392 561
393 562 // EXPORTS
394 563 __webpack_require__.d(__webpack_exports__, {
395 - "EntityProvider": function() { return /* reexport */ EntityProvider; },
396 - "__experimentalFetchLinkSuggestions": function() { return /* reexport */ _experimental_fetch_link_suggestions; },
397 - "__experimentalFetchUrlData": function() { return /* reexport */ _experimental_fetch_url_data; },
398 - "store": function() { return /* binding */ store; },
399 - "useEntityBlockEditor": function() { return /* reexport */ useEntityBlockEditor; },
400 - "useEntityId": function() { return /* reexport */ useEntityId; },
401 - "useEntityProp": function() { return /* reexport */ useEntityProp; }
564 + "EntityProvider": () => (/* reexport */ EntityProvider),
565 + "__experimentalFetchLinkSuggestions": () => (/* reexport */ _experimental_fetch_link_suggestions),
566 + "__experimentalFetchUrlData": () => (/* reexport */ _experimental_fetch_url_data),
567 + "__experimentalUseEntityRecord": () => (/* reexport */ __experimentalUseEntityRecord),
568 + "__experimentalUseEntityRecords": () => (/* reexport */ __experimentalUseEntityRecords),
569 + "__experimentalUseResourcePermissions": () => (/* reexport */ __experimentalUseResourcePermissions),
570 + "store": () => (/* binding */ store),
571 + "useEntityBlockEditor": () => (/* reexport */ useEntityBlockEditor),
572 + "useEntityId": () => (/* reexport */ useEntityId),
573 + "useEntityProp": () => (/* reexport */ useEntityProp),
574 + "useEntityRecord": () => (/* reexport */ useEntityRecord),
575 + "useEntityRecords": () => (/* reexport */ useEntityRecords),
576 + "useResourcePermissions": () => (/* reexport */ useResourcePermissions)
402 577 });
403 578
404 579 // NAMESPACE OBJECT: ./packages/core-data/build-module/actions.js
405 580 var build_module_actions_namespaceObject = {};
@@ -404,30 +579,30 @@
404 579 // NAMESPACE OBJECT: ./packages/core-data/build-module/actions.js
405 580 var build_module_actions_namespaceObject = {};
406 581 __webpack_require__.r(build_module_actions_namespaceObject);
407 582 __webpack_require__.d(build_module_actions_namespaceObject, {
408 - "__experimentalBatch": function() { return __experimentalBatch; },
409 - "__experimentalReceiveCurrentGlobalStylesId": function() { return __experimentalReceiveCurrentGlobalStylesId; },
410 - "__experimentalReceiveThemeBaseGlobalStyles": function() { return __experimentalReceiveThemeBaseGlobalStyles; },
411 - "__experimentalReceiveThemeGlobalStyleVariations": function() { return __experimentalReceiveThemeGlobalStyleVariations; },
412 - "__experimentalSaveSpecifiedEntityEdits": function() { return __experimentalSaveSpecifiedEntityEdits; },
413 - "__unstableCreateUndoLevel": function() { return __unstableCreateUndoLevel; },
414 - "addEntities": function() { return addEntities; },
415 - "deleteEntityRecord": function() { return deleteEntityRecord; },
416 - "editEntityRecord": function() { return editEntityRecord; },
417 - "receiveAutosaves": function() { return receiveAutosaves; },
418 - "receiveCurrentTheme": function() { return receiveCurrentTheme; },
419 - "receiveCurrentUser": function() { return receiveCurrentUser; },
420 - "receiveEmbedPreview": function() { return receiveEmbedPreview; },
421 - "receiveEntityRecords": function() { return receiveEntityRecords; },
422 - "receiveThemeSupports": function() { return receiveThemeSupports; },
423 - "receiveUploadPermissions": function() { return receiveUploadPermissions; },
424 - "receiveUserPermission": function() { return receiveUserPermission; },
425 - "receiveUserQuery": function() { return receiveUserQuery; },
426 - "redo": function() { return redo; },
427 - "saveEditedEntityRecord": function() { return saveEditedEntityRecord; },
428 - "saveEntityRecord": function() { return saveEntityRecord; },
429 - "undo": function() { return undo; }
583 + "__experimentalBatch": () => (__experimentalBatch),
584 + "__experimentalReceiveCurrentGlobalStylesId": () => (__experimentalReceiveCurrentGlobalStylesId),
585 + "__experimentalReceiveThemeBaseGlobalStyles": () => (__experimentalReceiveThemeBaseGlobalStyles),
586 + "__experimentalReceiveThemeGlobalStyleVariations": () => (__experimentalReceiveThemeGlobalStyleVariations),
587 + "__experimentalSaveSpecifiedEntityEdits": () => (__experimentalSaveSpecifiedEntityEdits),
588 + "__unstableCreateUndoLevel": () => (__unstableCreateUndoLevel),
589 + "addEntities": () => (addEntities),
590 + "deleteEntityRecord": () => (deleteEntityRecord),
591 + "editEntityRecord": () => (editEntityRecord),
592 + "receiveAutosaves": () => (receiveAutosaves),
593 + "receiveCurrentTheme": () => (receiveCurrentTheme),
594 + "receiveCurrentUser": () => (receiveCurrentUser),
595 + "receiveEmbedPreview": () => (receiveEmbedPreview),
596 + "receiveEntityRecords": () => (receiveEntityRecords),
597 + "receiveThemeSupports": () => (receiveThemeSupports),
598 + "receiveUploadPermissions": () => (receiveUploadPermissions),
599 + "receiveUserPermission": () => (receiveUserPermission),
600 + "receiveUserQuery": () => (receiveUserQuery),
601 + "redo": () => (redo),
602 + "saveEditedEntityRecord": () => (saveEditedEntityRecord),
603 + "saveEntityRecord": () => (saveEntityRecord),
604 + "undo": () => (undo)
430 605 });
431 606
432 607 // NAMESPACE OBJECT: ./packages/core-data/build-module/selectors.js
433 608 var build_module_selectors_namespaceObject = {};
@@ -432,48 +607,52 @@
432 607 // NAMESPACE OBJECT: ./packages/core-data/build-module/selectors.js
433 608 var build_module_selectors_namespaceObject = {};
434 609 __webpack_require__.r(build_module_selectors_namespaceObject);
435 610 __webpack_require__.d(build_module_selectors_namespaceObject, {
436 - "__experimentalGetCurrentGlobalStylesId": function() { return __experimentalGetCurrentGlobalStylesId; },
437 - "__experimentalGetCurrentThemeBaseGlobalStyles": function() { return __experimentalGetCurrentThemeBaseGlobalStyles; },
438 - "__experimentalGetCurrentThemeGlobalStylesVariations": function() { return __experimentalGetCurrentThemeGlobalStylesVariations; },
439 - "__experimentalGetDirtyEntityRecords": function() { return __experimentalGetDirtyEntityRecords; },
440 - "__experimentalGetEntitiesBeingSaved": function() { return __experimentalGetEntitiesBeingSaved; },
441 - "__experimentalGetEntityRecordNoResolver": function() { return __experimentalGetEntityRecordNoResolver; },
442 - "__experimentalGetTemplateForLink": function() { return __experimentalGetTemplateForLink; },
443 - "canUser": function() { return canUser; },
444 - "canUserEditEntityRecord": function() { return canUserEditEntityRecord; },
445 - "getAuthors": function() { return getAuthors; },
446 - "getAutosave": function() { return getAutosave; },
447 - "getAutosaves": function() { return getAutosaves; },
448 - "getCurrentTheme": function() { return getCurrentTheme; },
449 - "getCurrentUser": function() { return getCurrentUser; },
450 - "getEditedEntityRecord": function() { return getEditedEntityRecord; },
451 - "getEmbedPreview": function() { return getEmbedPreview; },
452 - "getEntitiesByKind": function() { return getEntitiesByKind; },
453 - "getEntity": function() { return getEntity; },
454 - "getEntityRecord": function() { return getEntityRecord; },
455 - "getEntityRecordEdits": function() { return getEntityRecordEdits; },
456 - "getEntityRecordNonTransientEdits": function() { return getEntityRecordNonTransientEdits; },
457 - "getEntityRecords": function() { return getEntityRecords; },
458 - "getLastEntityDeleteError": function() { return getLastEntityDeleteError; },
459 - "getLastEntitySaveError": function() { return getLastEntitySaveError; },
460 - "getRawEntityRecord": function() { return getRawEntityRecord; },
461 - "getRedoEdit": function() { return getRedoEdit; },
462 - "getReferenceByDistinctEdits": function() { return getReferenceByDistinctEdits; },
463 - "getThemeSupports": function() { return getThemeSupports; },
464 - "getUndoEdit": function() { return getUndoEdit; },
465 - "getUserQueryResults": function() { return getUserQueryResults; },
466 - "hasEditsForEntityRecord": function() { return hasEditsForEntityRecord; },
467 - "hasEntityRecords": function() { return hasEntityRecords; },
468 - "hasFetchedAutosaves": function() { return hasFetchedAutosaves; },
469 - "hasRedo": function() { return hasRedo; },
470 - "hasUndo": function() { return hasUndo; },
471 - "isAutosavingEntityRecord": function() { return isAutosavingEntityRecord; },
472 - "isDeletingEntityRecord": function() { return isDeletingEntityRecord; },
473 - "isPreviewEmbedFallback": function() { return isPreviewEmbedFallback; },
474 - "isRequestingEmbedPreview": function() { return isRequestingEmbedPreview; },
475 - "isSavingEntityRecord": function() { return isSavingEntityRecord; }
611 + "__experimentalGetCurrentGlobalStylesId": () => (__experimentalGetCurrentGlobalStylesId),
612 + "__experimentalGetCurrentThemeBaseGlobalStyles": () => (__experimentalGetCurrentThemeBaseGlobalStyles),
613 + "__experimentalGetCurrentThemeGlobalStylesVariations": () => (__experimentalGetCurrentThemeGlobalStylesVariations),
614 + "__experimentalGetDirtyEntityRecords": () => (__experimentalGetDirtyEntityRecords),
615 + "__experimentalGetEntitiesBeingSaved": () => (__experimentalGetEntitiesBeingSaved),
616 + "__experimentalGetEntityRecordNoResolver": () => (__experimentalGetEntityRecordNoResolver),
617 + "__experimentalGetTemplateForLink": () => (__experimentalGetTemplateForLink),
618 + "canUser": () => (canUser),
619 + "canUserEditEntityRecord": () => (canUserEditEntityRecord),
620 + "getAuthors": () => (getAuthors),
621 + "getAutosave": () => (getAutosave),
622 + "getAutosaves": () => (getAutosaves),
623 + "getBlockPatternCategories": () => (getBlockPatternCategories),
624 + "getBlockPatterns": () => (getBlockPatterns),
625 + "getCurrentTheme": () => (getCurrentTheme),
626 + "getCurrentUser": () => (getCurrentUser),
627 + "getEditedEntityRecord": () => (getEditedEntityRecord),
628 + "getEmbedPreview": () => (getEmbedPreview),
629 + "getEntitiesByKind": () => (getEntitiesByKind),
630 + "getEntitiesConfig": () => (getEntitiesConfig),
631 + "getEntity": () => (getEntity),
632 + "getEntityConfig": () => (getEntityConfig),
633 + "getEntityRecord": () => (getEntityRecord),
634 + "getEntityRecordEdits": () => (getEntityRecordEdits),
635 + "getEntityRecordNonTransientEdits": () => (getEntityRecordNonTransientEdits),
636 + "getEntityRecords": () => (getEntityRecords),
637 + "getLastEntityDeleteError": () => (getLastEntityDeleteError),
638 + "getLastEntitySaveError": () => (getLastEntitySaveError),
639 + "getRawEntityRecord": () => (getRawEntityRecord),
640 + "getRedoEdit": () => (getRedoEdit),
641 + "getReferenceByDistinctEdits": () => (getReferenceByDistinctEdits),
642 + "getThemeSupports": () => (getThemeSupports),
643 + "getUndoEdit": () => (getUndoEdit),
644 + "getUserQueryResults": () => (getUserQueryResults),
645 + "hasEditsForEntityRecord": () => (hasEditsForEntityRecord),
646 + "hasEntityRecords": () => (hasEntityRecords),
647 + "hasFetchedAutosaves": () => (hasFetchedAutosaves),
648 + "hasRedo": () => (hasRedo),
649 + "hasUndo": () => (hasUndo),
650 + "isAutosavingEntityRecord": () => (isAutosavingEntityRecord),
651 + "isDeletingEntityRecord": () => (isDeletingEntityRecord),
652 + "isPreviewEmbedFallback": () => (isPreviewEmbedFallback),
653 + "isRequestingEmbedPreview": () => (isRequestingEmbedPreview),
654 + "isSavingEntityRecord": () => (isSavingEntityRecord)
476 655 });
477 656
478 657 // NAMESPACE OBJECT: ./packages/core-data/build-module/resolvers.js
479 658 var resolvers_namespaceObject = {};
@@ -478,43 +657,49 @@
478 657 // NAMESPACE OBJECT: ./packages/core-data/build-module/resolvers.js
479 658 var resolvers_namespaceObject = {};
480 659 __webpack_require__.r(resolvers_namespaceObject);
481 660 __webpack_require__.d(resolvers_namespaceObject, {
482 - "__experimentalGetCurrentGlobalStylesId": function() { return resolvers_experimentalGetCurrentGlobalStylesId; },
483 - "__experimentalGetCurrentThemeBaseGlobalStyles": function() { return resolvers_experimentalGetCurrentThemeBaseGlobalStyles; },
484 - "__experimentalGetCurrentThemeGlobalStylesVariations": function() { return resolvers_experimentalGetCurrentThemeGlobalStylesVariations; },
485 - "__experimentalGetTemplateForLink": function() { return resolvers_experimentalGetTemplateForLink; },
486 - "canUser": function() { return resolvers_canUser; },
487 - "canUserEditEntityRecord": function() { return resolvers_canUserEditEntityRecord; },
488 - "getAuthors": function() { return resolvers_getAuthors; },
489 - "getAutosave": function() { return resolvers_getAutosave; },
490 - "getAutosaves": function() { return resolvers_getAutosaves; },
491 - "getCurrentTheme": function() { return resolvers_getCurrentTheme; },
492 - "getCurrentUser": function() { return resolvers_getCurrentUser; },
493 - "getEditedEntityRecord": function() { return resolvers_getEditedEntityRecord; },
494 - "getEmbedPreview": function() { return resolvers_getEmbedPreview; },
495 - "getEntityRecord": function() { return resolvers_getEntityRecord; },
496 - "getEntityRecords": function() { return resolvers_getEntityRecords; },
497 - "getRawEntityRecord": function() { return resolvers_getRawEntityRecord; },
498 - "getThemeSupports": function() { return resolvers_getThemeSupports; }
661 + "__experimentalGetCurrentGlobalStylesId": () => (resolvers_experimentalGetCurrentGlobalStylesId),
662 + "__experimentalGetCurrentThemeBaseGlobalStyles": () => (resolvers_experimentalGetCurrentThemeBaseGlobalStyles),
663 + "__experimentalGetCurrentThemeGlobalStylesVariations": () => (resolvers_experimentalGetCurrentThemeGlobalStylesVariations),
664 + "__experimentalGetTemplateForLink": () => (resolvers_experimentalGetTemplateForLink),
665 + "canUser": () => (resolvers_canUser),
666 + "canUserEditEntityRecord": () => (resolvers_canUserEditEntityRecord),
667 + "getAuthors": () => (resolvers_getAuthors),
668 + "getAutosave": () => (resolvers_getAutosave),
669 + "getAutosaves": () => (resolvers_getAutosaves),
670 + "getBlockPatternCategories": () => (resolvers_getBlockPatternCategories),
671 + "getBlockPatterns": () => (resolvers_getBlockPatterns),
672 + "getCurrentTheme": () => (resolvers_getCurrentTheme),
673 + "getCurrentUser": () => (resolvers_getCurrentUser),
674 + "getEditedEntityRecord": () => (resolvers_getEditedEntityRecord),
675 + "getEmbedPreview": () => (resolvers_getEmbedPreview),
676 + "getEntityRecord": () => (resolvers_getEntityRecord),
677 + "getEntityRecords": () => (resolvers_getEntityRecords),
678 + "getRawEntityRecord": () => (resolvers_getRawEntityRecord),
679 + "getThemeSupports": () => (resolvers_getThemeSupports)
499 680 });
500 681
501 682 ;// CONCATENATED MODULE: external ["wp","data"]
502 -var external_wp_data_namespaceObject = window["wp"]["data"];
683 +const external_wp_data_namespaceObject = window["wp"]["data"];
503 684 ;// CONCATENATED MODULE: external "lodash"
504 -var external_lodash_namespaceObject = window["lodash"];
685 +const external_lodash_namespaceObject = window["lodash"];
686 +;// CONCATENATED MODULE: external ["wp","compose"]
687 +const external_wp_compose_namespaceObject = window["wp"]["compose"];
505 688 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"]
506 -var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
689 +const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
507 690 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
508 691 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/if-matching-action.js
692 +/** @typedef {import('../types').AnyFunction} AnyFunction */
693 +
509 694 /**
510 695 * A higher-order reducer creator which invokes the original reducer only if
511 696 * the dispatching action matches the given predicate, **OR** if state is
512 697 * initializing (undefined).
513 698 *
514 - * @param {Function} isMatch Function predicate for allowing reducer call.
699 + * @param {AnyFunction} isMatch Function predicate for allowing reducer call.
515 700 *
516 - * @return {Function} Higher-order reducer.
701 + * @return {AnyFunction} Higher-order reducer.
517 702 */
518 703 const ifMatchingAction = isMatch => reducer => (state, action) => {
519 704 if (state === undefined || isMatch(action)) {
520 705 return reducer(state, action);
@@ -522,25 +707,27 @@
522 707
523 708 return state;
524 709 };
525 710
526 -/* harmony default export */ var if_matching_action = (ifMatchingAction);
527 -//# sourceMappingURL=if-matching-action.js.map
711 +/* harmony default export */ const if_matching_action = (ifMatchingAction);
712 +
528 713 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/replace-action.js
714 +/** @typedef {import('../types').AnyFunction} AnyFunction */
715 +
529 716 /**
530 717 * Higher-order reducer creator which substitutes the action object before
531 718 * passing to the original reducer.
532 719 *
533 - * @param {Function} replacer Function mapping original action to replacement.
720 + * @param {AnyFunction} replacer Function mapping original action to replacement.
534 721 *
535 - * @return {Function} Higher-order reducer.
722 + * @return {AnyFunction} Higher-order reducer.
536 723 */
537 724 const replaceAction = replacer => reducer => (state, action) => {
538 725 return reducer(state, replacer(action));
539 726 };
540 727
541 -/* harmony default export */ var replace_action = (replaceAction);
542 -//# sourceMappingURL=replace-action.js.map
728 +/* harmony default export */ const replace_action = (replaceAction);
729 +
543 730 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/conservative-map-item.js
544 731 /**
545 732 * External dependencies
546 733 */
@@ -545,9 +732,9 @@
545 732 * External dependencies
546 733 */
547 734
548 735 /**
549 - * Given the current and next item entity, returns the minimally "modified"
736 + * Given the current and next item entity record, returns the minimally "modified"
550 737 * result of the next item, preferring value references from the original item
551 738 * if equal. If all values match, the original item is returned.
552 739 *
553 740 * @param {Object} item Original item.
@@ -588,10 +775,12 @@
588 775 }
589 776
590 777 return result;
591 778 }
592 -//# sourceMappingURL=conservative-map-item.js.map
779 +
593 780 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/on-sub-key.js
781 +/** @typedef {import('../types').AnyFunction} AnyFunction */
782 +
594 783 /**
595 784 * Higher-order reducer creator which creates a combined reducer object, keyed
596 785 * by a property on the action object.
597 786 *
@@ -596,9 +785,9 @@
596 785 * by a property on the action object.
597 786 *
598 787 * @param {string} actionProperty Action property by which to key object.
599 788 *
600 - * @return {Function} Higher-order reducer.
789 + * @return {AnyFunction} Higher-order reducer.
601 790 */
602 791 const onSubKey = actionProperty => reducer => function () {
603 792 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
604 793 let action = arguments.length > 1 ? arguments[1] : undefined;
@@ -621,15 +810,376 @@
621 810 return { ...state,
622 811 [key]: nextKeyState
623 812 };
624 813 };
625 -/* harmony default export */ var on_sub_key = (onSubKey);
626 -//# sourceMappingURL=on-sub-key.js.map
814 +/* harmony default export */ const on_sub_key = (onSubKey);
815 +
816 +;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
817 +/*! *****************************************************************************
818 +Copyright (c) Microsoft Corporation.
819 +
820 +Permission to use, copy, modify, and/or distribute this software for any
821 +purpose with or without fee is hereby granted.
822 +
823 +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
824 +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
825 +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
826 +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
827 +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
828 +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
829 +PERFORMANCE OF THIS SOFTWARE.
830 +***************************************************************************** */
831 +/* global Reflect, Promise */
832 +
833 +var extendStatics = function(d, b) {
834 + extendStatics = Object.setPrototypeOf ||
835 + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
836 + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
837 + return extendStatics(d, b);
838 +};
839 +
840 +function __extends(d, b) {
841 + if (typeof b !== "function" && b !== null)
842 + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
843 + extendStatics(d, b);
844 + function __() { this.constructor = d; }
845 + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
846 +}
847 +
848 +var __assign = function() {
849 + __assign = Object.assign || function __assign(t) {
850 + for (var s, i = 1, n = arguments.length; i < n; i++) {
851 + s = arguments[i];
852 + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
853 + }
854 + return t;
855 + }
856 + return __assign.apply(this, arguments);
857 +}
858 +
859 +function __rest(s, e) {
860 + var t = {};
861 + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
862 + t[p] = s[p];
863 + if (s != null && typeof Object.getOwnPropertySymbols === "function")
864 + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
865 + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
866 + t[p[i]] = s[p[i]];
867 + }
868 + return t;
869 +}
870 +
871 +function __decorate(decorators, target, key, desc) {
872 + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
873 + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
874 + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
875 + return c > 3 && r && Object.defineProperty(target, key, r), r;
876 +}
877 +
878 +function __param(paramIndex, decorator) {
879 + return function (target, key) { decorator(target, key, paramIndex); }
880 +}
881 +
882 +function __metadata(metadataKey, metadataValue) {
883 + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
884 +}
885 +
886 +function __awaiter(thisArg, _arguments, P, generator) {
887 + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
888 + return new (P || (P = Promise))(function (resolve, reject) {
889 + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
890 + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
891 + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
892 + step((generator = generator.apply(thisArg, _arguments || [])).next());
893 + });
894 +}
895 +
896 +function __generator(thisArg, body) {
897 + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
898 + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
899 + function verb(n) { return function (v) { return step([n, v]); }; }
900 + function step(op) {
901 + if (f) throw new TypeError("Generator is already executing.");
902 + while (_) try {
903 + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
904 + if (y = 0, t) op = [op[0] & 2, t.value];
905 + switch (op[0]) {
906 + case 0: case 1: t = op; break;
907 + case 4: _.label++; return { value: op[1], done: false };
908 + case 5: _.label++; y = op[1]; op = [0]; continue;
909 + case 7: op = _.ops.pop(); _.trys.pop(); continue;
910 + default:
911 + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
912 + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
913 + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
914 + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
915 + if (t[2]) _.ops.pop();
916 + _.trys.pop(); continue;
917 + }
918 + op = body.call(thisArg, _);
919 + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
920 + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
921 + }
922 +}
923 +
924 +var __createBinding = Object.create ? (function(o, m, k, k2) {
925 + if (k2 === undefined) k2 = k;
926 + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
927 +}) : (function(o, m, k, k2) {
928 + if (k2 === undefined) k2 = k;
929 + o[k2] = m[k];
930 +});
931 +
932 +function __exportStar(m, o) {
933 + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
934 +}
935 +
936 +function __values(o) {
937 + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
938 + if (m) return m.call(o);
939 + if (o && typeof o.length === "number") return {
940 + next: function () {
941 + if (o && i >= o.length) o = void 0;
942 + return { value: o && o[i++], done: !o };
943 + }
944 + };
945 + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
946 +}
947 +
948 +function __read(o, n) {
949 + var m = typeof Symbol === "function" && o[Symbol.iterator];
950 + if (!m) return o;
951 + var i = m.call(o), r, ar = [], e;
952 + try {
953 + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
954 + }
955 + catch (error) { e = { error: error }; }
956 + finally {
957 + try {
958 + if (r && !r.done && (m = i["return"])) m.call(i);
959 + }
960 + finally { if (e) throw e.error; }
961 + }
962 + return ar;
963 +}
964 +
965 +/** @deprecated */
966 +function __spread() {
967 + for (var ar = [], i = 0; i < arguments.length; i++)
968 + ar = ar.concat(__read(arguments[i]));
969 + return ar;
970 +}
971 +
972 +/** @deprecated */
973 +function __spreadArrays() {
974 + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
975 + for (var r = Array(s), k = 0, i = 0; i < il; i++)
976 + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
977 + r[k] = a[j];
978 + return r;
979 +}
980 +
981 +function __spreadArray(to, from, pack) {
982 + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
983 + if (ar || !(i in from)) {
984 + if (!ar) ar = Array.prototype.slice.call(from, 0, i);
985 + ar[i] = from[i];
986 + }
987 + }
988 + return to.concat(ar || from);
989 +}
990 +
991 +function __await(v) {
992 + return this instanceof __await ? (this.v = v, this) : new __await(v);
993 +}
994 +
995 +function __asyncGenerator(thisArg, _arguments, generator) {
996 + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
997 + var g = generator.apply(thisArg, _arguments || []), i, q = [];
998 + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
999 + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
1000 + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
1001 + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
1002 + function fulfill(value) { resume("next", value); }
1003 + function reject(value) { resume("throw", value); }
1004 + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
1005 +}
1006 +
1007 +function __asyncDelegator(o) {
1008 + var i, p;
1009 + return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
1010 + function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
1011 +}
1012 +
1013 +function __asyncValues(o) {
1014 + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1015 + var m = o[Symbol.asyncIterator], i;
1016 + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
1017 + function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
1018 + function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1019 +}
1020 +
1021 +function __makeTemplateObject(cooked, raw) {
1022 + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
1023 + return cooked;
1024 +};
1025 +
1026 +var __setModuleDefault = Object.create ? (function(o, v) {
1027 + Object.defineProperty(o, "default", { enumerable: true, value: v });
1028 +}) : function(o, v) {
1029 + o["default"] = v;
1030 +};
1031 +
1032 +function __importStar(mod) {
1033 + if (mod && mod.__esModule) return mod;
1034 + var result = {};
1035 + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1036 + __setModuleDefault(result, mod);
1037 + return result;
1038 +}
1039 +
1040 +function __importDefault(mod) {
1041 + return (mod && mod.__esModule) ? mod : { default: mod };
1042 +}
1043 +
1044 +function __classPrivateFieldGet(receiver, state, kind, f) {
1045 + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1046 + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1047 + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1048 +}
1049 +
1050 +function __classPrivateFieldSet(receiver, state, value, kind, f) {
1051 + if (kind === "m") throw new TypeError("Private method is not writable");
1052 + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1053 + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1054 + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1055 +}
1056 +
1057 +;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
1058 +/**
1059 + * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
1060 + */
1061 +var SUPPORTED_LOCALE = {
1062 + tr: {
1063 + regexp: /\u0130|\u0049|\u0049\u0307/g,
1064 + map: {
1065 + İ: "\u0069",
1066 + I: "\u0131",
1067 + İ: "\u0069",
1068 + },
1069 + },
1070 + az: {
1071 + regexp: /\u0130/g,
1072 + map: {
1073 + İ: "\u0069",
1074 + I: "\u0131",
1075 + İ: "\u0069",
1076 + },
1077 + },
1078 + lt: {
1079 + regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
1080 + map: {
1081 + I: "\u0069\u0307",
1082 + J: "\u006A\u0307",
1083 + Į: "\u012F\u0307",
1084 + Ì: "\u0069\u0307\u0300",
1085 + Í: "\u0069\u0307\u0301",
1086 + Ĩ: "\u0069\u0307\u0303",
1087 + },
1088 + },
1089 +};
1090 +/**
1091 + * Localized lower case.
1092 + */
1093 +function localeLowerCase(str, locale) {
1094 + var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
1095 + if (lang)
1096 + return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
1097 + return lowerCase(str);
1098 +}
1099 +/**
1100 + * Lower case as a function.
1101 + */
1102 +function lowerCase(str) {
1103 + return str.toLowerCase();
1104 +}
1105 +
1106 +;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
1107 +
1108 +// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
1109 +var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
1110 +// Remove all non-word characters.
1111 +var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
1112 +/**
1113 + * Normalize the string into something other libraries can manipulate easier.
1114 + */
1115 +function noCase(input, options) {
1116 + if (options === void 0) { options = {}; }
1117 + var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
1118 + var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
1119 + var start = 0;
1120 + var end = result.length;
1121 + // Trim the delimiter from around the output string.
1122 + while (result.charAt(start) === "\0")
1123 + start++;
1124 + while (result.charAt(end - 1) === "\0")
1125 + end--;
1126 + // Transform each token independently.
1127 + return result.slice(start, end).split("\0").map(transform).join(delimiter);
1128 +}
1129 +/**
1130 + * Replace `re` in the input string with the replacement value.
1131 + */
1132 +function replace(input, re, value) {
1133 + if (re instanceof RegExp)
1134 + return input.replace(re, value);
1135 + return re.reduce(function (input, re) { return input.replace(re, value); }, input);
1136 +}
1137 +
1138 +;// CONCATENATED MODULE: ./node_modules/upper-case-first/dist.es2015/index.js
1139 +/**
1140 + * Upper case the first character of an input string.
1141 + */
1142 +function upperCaseFirst(input) {
1143 + return input.charAt(0).toUpperCase() + input.substr(1);
1144 +}
1145 +
1146 +;// CONCATENATED MODULE: ./node_modules/capital-case/dist.es2015/index.js
1147 +
1148 +
1149 +
1150 +function capitalCaseTransform(input) {
1151 + return upperCaseFirst(input.toLowerCase());
1152 +}
1153 +function capitalCase(input, options) {
1154 + if (options === void 0) { options = {}; }
1155 + return noCase(input, __assign({ delimiter: " ", transform: capitalCaseTransform }, options));
1156 +}
1157 +
1158 +;// CONCATENATED MODULE: ./node_modules/pascal-case/dist.es2015/index.js
1159 +
1160 +
1161 +function pascalCaseTransform(input, index) {
1162 + var firstChar = input.charAt(0);
1163 + var lowerChars = input.substr(1).toLowerCase();
1164 + if (index > 0 && firstChar >= "0" && firstChar <= "9") {
1165 + return "_" + firstChar + lowerChars;
1166 + }
1167 + return "" + firstChar.toUpperCase() + lowerChars;
1168 +}
1169 +function dist_es2015_pascalCaseTransformMerge(input) {
1170 + return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
1171 +}
1172 +function pascalCase(input, options) {
1173 + if (options === void 0) { options = {}; }
1174 + return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
1175 +}
1176 +
627 1177 ;// CONCATENATED MODULE: external ["wp","apiFetch"]
628 -var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
1178 +const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
629 1179 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
630 1180 ;// CONCATENATED MODULE: external ["wp","i18n"]
631 -var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
1181 +const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
632 1182 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/rng.js
633 1183 // Unique ID creation requires a high quality random # generator. In the browser we therefore
634 1184 // require the crypto API and do not support built-in fallback to lower quality random number
635 1185 // generators (like Math.random()).
@@ -644,9 +1194,9 @@
644 1194
645 1195 return getRandomValues(rnds8);
646 1196 }
647 1197 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/regex.js
648 -/* harmony default export */ var regex = (/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i);
1198 +/* harmony default export */ const regex = (/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i);
649 1199 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/validate.js
650 1200
651 1201
652 1202 function validate(uuid) {
@@ -652,9 +1202,9 @@
652 1202 function validate(uuid) {
653 1203 return typeof uuid === 'string' && regex.test(uuid);
654 1204 }
655 1205
656 -/* harmony default export */ var esm_browser_validate = (validate);
1206 +/* harmony default export */ const esm_browser_validate = (validate);
657 1207 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/stringify.js
658 1208
659 1209 /**
660 1210 * Convert array of 16 byte values to UUID string format of the form:
@@ -683,9 +1233,9 @@
683 1233
684 1234 return uuid;
685 1235 }
686 1236
687 -/* harmony default export */ var esm_browser_stringify = (stringify);
1237 +/* harmony default export */ const esm_browser_stringify = (stringify);
688 1238 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/v4.js
689 1239
690 1240
691 1241
@@ -708,20 +1258,16 @@
708 1258
709 1259 return esm_browser_stringify(rnds);
710 1260 }
711 1261
712 -/* harmony default export */ var esm_browser_v4 = (v4);
1262 +/* harmony default export */ const esm_browser_v4 = (v4);
713 1263 ;// CONCATENATED MODULE: external ["wp","url"]
714 -var external_wp_url_namespaceObject = window["wp"]["url"];
1264 +const external_wp_url_namespaceObject = window["wp"]["url"];
715 1265 ;// CONCATENATED MODULE: external ["wp","deprecated"]
716 -var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
1266 +const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
717 1267 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
718 1268 ;// CONCATENATED MODULE: ./packages/core-data/build-module/queried-data/actions.js
719 1269 /**
720 - * External dependencies
721 - */
722 -
723 -/**
724 1270 * Returns an action object used in signalling that items have been received.
725 1271 *
726 1272 * @param {Array} items Items received.
727 1273 * @param {?Object} edits Optional edits to reset.
@@ -727,13 +1273,12 @@
727 1273 * @param {?Object} edits Optional edits to reset.
728 1274 *
729 1275 * @return {Object} Action object.
730 1276 */
731 -
732 1277 function receiveItems(items, edits) {
733 1278 return {
734 1279 type: 'RECEIVE_ITEMS',
735 - items: (0,external_lodash_namespaceObject.castArray)(items),
1280 + items: Array.isArray(items) ? items : [items],
736 1281 persistedEdits: edits
737 1282 };
738 1283 }
739 1284 /**
@@ -739,12 +1284,12 @@
739 1284 /**
740 1285 * Returns an action object used in signalling that entity records have been
741 1286 * deleted and they need to be removed from entities state.
742 1287 *
743 - * @param {string} kind Kind of the removed entities.
744 - * @param {string} name Name of the removed entities.
745 - * @param {Array|number} records Record IDs of the removed entities.
746 - * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
1288 + * @param {string} kind Kind of the removed entities.
1289 + * @param {string} name Name of the removed entities.
1290 + * @param {Array|number|string} records Record IDs of the removed entities.
1291 + * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
747 1292 * @return {Object} Action object.
748 1293 */
749 1294
750 1295 function removeItems(kind, name, records) {
@@ -750,9 +1295,9 @@
750 1295 function removeItems(kind, name, records) {
751 1296 let invalidateCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
752 1297 return {
753 1298 type: 'REMOVE_ITEMS',
754 - itemIds: (0,external_lodash_namespaceObject.castArray)(records),
1299 + itemIds: Array.isArray(records) ? records : [records],
755 1300 kind,
756 1301 name,
757 1302 invalidateCache
758 1303 };
@@ -774,19 +1319,14 @@
774 1319 return { ...receiveItems(items, edits),
775 1320 query
776 1321 };
777 1322 }
778 -//# sourceMappingURL=actions.js.map
1323 +
779 1324 ;// CONCATENATED MODULE: ./packages/core-data/build-module/batch/default-processor.js
780 1325 /**
781 - * External dependencies
782 - */
783 -
784 -/**
785 1326 * WordPress dependencies
786 1327 */
787 1328
788 -
789 1329 /**
790 1330 * Maximum number of requests to place in a single batch request. Obtained by
791 1331 * sending a preflight OPTIONS request to /batch/v1/.
792 1332 *
@@ -793,8 +1333,19 @@
793 1333 * @type {number?}
794 1334 */
795 1335
796 1336 let maxItems = null;
1337 +
1338 +function chunk(arr, chunkSize) {
1339 + const tmp = [...arr];
1340 + const cache = [];
1341 +
1342 + while (tmp.length) {
1343 + cache.push(tmp.splice(0, chunkSize));
1344 + }
1345 +
1346 + return cache;
1347 +}
797 1348 /**
798 1349 * Default batch processor. Sends its input requests to /batch/v1.
799 1350 *
800 1351 * @param {Array} requests List of API requests to perform at once.
@@ -799,12 +1350,13 @@
799 1350 *
800 1351 * @param {Array} requests List of API requests to perform at once.
801 1352 *
802 1353 * @return {Promise} Promise that resolves to a list of objects containing
803 - * either `output` (if that request was succesful) or `error`
1354 + * either `output` (if that request was successful) or `error`
804 1355 * (if not ).
805 1356 */
806 1357
1358 +
807 1359 async function defaultProcessor(requests) {
808 1360 if (maxItems === null) {
809 1361 const preflightResponse = await external_wp_apiFetch_default()({
810 1362 path: '/batch/v1',
@@ -812,11 +1364,11 @@
812 1364 });
813 1365 maxItems = preflightResponse.endpoints[0].args.requests.maxItems;
814 1366 }
815 1367
816 - const results = [];
1368 + const results = []; // @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count.
817 1369
818 - for (const batchRequests of (0,external_lodash_namespaceObject.chunk)(requests, maxItems)) {
1370 + for (const batchRequests of chunk(requests, maxItems)) {
819 1371 const batchResponse = await external_wp_apiFetch_default()({
820 1372 path: '/batch/v1',
821 1373 method: 'POST',
822 1374 data: {
@@ -854,19 +1406,14 @@
854 1406 }
855 1407
856 1408 return results;
857 1409 }
858 -//# sourceMappingURL=default-processor.js.map
1410 +
859 1411 ;// CONCATENATED MODULE: ./packages/core-data/build-module/batch/create-batch.js
860 1412 /**
861 - * External dependencies
862 - */
863 -
864 -/**
865 1413 * Internal dependencies
866 1414 */
867 1415
868 -
869 1416 /**
870 1417 * Creates a batch, which can be used to combine multiple API requests into one
871 1418 * API request using the WordPress batch processing API (/v1/batch).
872 1419 *
@@ -902,8 +1449,10 @@
902 1449
903 1450 function createBatch() {
904 1451 let processor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultProcessor;
905 1452 let lastId = 0;
1453 + /** @type {Array<{ input: any; resolve: ( value: any ) => void; reject: ( error: any ) => void }>} */
1454 +
906 1455 let queue = [];
907 1456 const pending = new ObservableSet();
908 1457 return {
909 1458 /**
@@ -944,9 +1493,9 @@
944 1493 });
945 1494 pending.delete(id);
946 1495 });
947 1496
948 - if ((0,external_lodash_namespaceObject.isFunction)(inputOrThunk)) {
1497 + if (typeof inputOrThunk === 'function') {
949 1498 return Promise.resolve(inputOrThunk(add)).finally(() => {
950 1499 pending.delete(id);
951 1500 });
952 1501 }
@@ -957,9 +1506,9 @@
957 1506 /**
958 1507 * Runs the batch. This calls `batchProcessor` and resolves or rejects
959 1508 * all promises returned by `add()`.
960 1509 *
961 - * @return {Promise} A promise that resolves to a boolean that is true
1510 + * @return {Promise<boolean>} A promise that resolves to a boolean that is true
962 1511 * if the processor returned no errors.
963 1512 */
964 1513 async run() {
965 1514 if (pending.size) {
@@ -966,9 +1515,9 @@
966 1515 await new Promise(resolve => {
967 1516 const unsubscribe = pending.subscribe(() => {
968 1517 if (!pending.size) {
969 1518 unsubscribe();
970 - resolve();
1519 + resolve(undefined);
971 1520 }
972 1521 });
973 1522 });
974 1523 }
@@ -996,23 +1545,20 @@
996 1545 throw error;
997 1546 }
998 1547
999 1548 let isSuccess = true;
1549 + results.forEach((result, key) => {
1550 + const queueItem = queue[key];
1000 1551
1001 - for (const [result, {
1002 - resolve,
1003 - reject
1004 - }] of (0,external_lodash_namespaceObject.zip)(results, queue)) {
1005 1552 if (result !== null && result !== void 0 && result.error) {
1006 - reject(result.error);
1553 + queueItem === null || queueItem === void 0 ? void 0 : queueItem.reject(result.error);
1007 1554 isSuccess = false;
1008 1555 } else {
1009 1556 var _result$output;
1010 1557
1011 - resolve((_result$output = result === null || result === void 0 ? void 0 : result.output) !== null && _result$output !== void 0 ? _result$output : result);
1558 + queueItem === null || queueItem === void 0 ? void 0 : queueItem.resolve((_result$output = result === null || result === void 0 ? void 0 : result.output) !== null && _result$output !== void 0 ? _result$output : result);
1012 1559 }
1013 - }
1014 -
1560 + });
1015 1561 queue = [];
1016 1562 return isSuccess;
1017 1563 }
1018 1564
@@ -1032,16 +1578,16 @@
1032 1578 get size() {
1033 1579 return this.set.size;
1034 1580 }
1035 1581
1036 - add() {
1037 - this.set.add(...arguments);
1582 + add(value) {
1583 + this.set.add(value);
1038 1584 this.subscribers.forEach(subscriber => subscriber());
1039 1585 return this;
1040 1586 }
1041 1587
1042 - delete() {
1043 - const isSuccess = this.set.delete(...arguments);
1588 + delete(value) {
1589 + const isSuccess = this.set.delete(value);
1044 1590 this.subscribers.forEach(subscriber => subscriber());
1045 1591 return isSuccess;
1046 1592 }
1047 1593
@@ -1052,9 +1598,9 @@
1052 1598 };
1053 1599 }
1054 1600
1055 1601 }
1056 -//# sourceMappingURL=create-batch.js.map
1602 +
1057 1603 ;// CONCATENATED MODULE: ./packages/core-data/build-module/name.js
1058 1604 /**
1059 1605 * The reducer key used by core data in store registration.
1060 1606 * This is defined in a separate file to avoid cycle-dependency
@@ -1061,9 +1607,9 @@
1061 1607 *
1062 1608 * @type {string}
1063 1609 */
1064 1610 const STORE_NAME = 'core';
1065 -//# sourceMappingURL=name.js.map
1611 +
1066 1612 ;// CONCATENATED MODULE: ./packages/core-data/build-module/actions.js
1067 1613 /**
1068 1614 * External dependencies
1069 1615 */
@@ -1085,9 +1631,12 @@
1085 1631
1086 1632
1087 1633 /**
1088 1634 * Returns an action object used in signalling that authors have been received.
1635 + * Ignored from documentation as it's internal to the data store.
1089 1636 *
1637 + * @ignore
1638 + *
1090 1639 * @param {string} queryID Query ID.
1091 1640 * @param {Array|Object} users Users received.
1092 1641 *
1093 1642 * @return {Object} Action object.
@@ -1095,15 +1644,18 @@
1095 1644
1096 1645 function receiveUserQuery(queryID, users) {
1097 1646 return {
1098 1647 type: 'RECEIVE_USER_QUERY',
1099 - users: (0,external_lodash_namespaceObject.castArray)(users),
1648 + users: Array.isArray(users) ? users : [users],
1100 1649 queryID
1101 1650 };
1102 1651 }
1103 1652 /**
1104 1653 * Returns an action used in signalling that the current user has been received.
1654 + * Ignored from documentation as it's internal to the data store.
1105 1655 *
1656 + * @ignore
1657 + *
1106 1658 * @param {Object} currentUser Current user object.
1107 1659 *
1108 1660 * @return {Object} Action object.
1109 1661 */
@@ -1130,10 +1682,10 @@
1130 1682 }
1131 1683 /**
1132 1684 * Returns an action object used in signalling that entity records have been received.
1133 1685 *
1134 - * @param {string} kind Kind of the received entity.
1135 - * @param {string} name Name of the received entity.
1686 + * @param {string} kind Kind of the received entity record.
1687 + * @param {string} name Name of the received entity record.
1136 1688 * @param {Array|Object} records Records received.
1137 1689 * @param {?Object} query Query Object.
1138 1690 * @param {?boolean} invalidateCache Should invalidate query caches.
1139 1691 * @param {?Object} edits Edits to reset.
@@ -1146,9 +1698,9 @@
1146 1698
1147 1699 // Auto drafts should not have titles, but some plugins rely on them so we can't filter this
1148 1700 // on the server.
1149 1701 if (kind === 'postType') {
1150 - records = (0,external_lodash_namespaceObject.castArray)(records).map(record => record.status === 'auto-draft' ? { ...record,
1702 + records = (Array.isArray(records) ? records : [records]).map(record => record.status === 'auto-draft' ? { ...record,
1151 1703 title: ''
1152 1704 } : record);
1153 1705 }
1154 1706
@@ -1167,9 +1719,12 @@
1167 1719 };
1168 1720 }
1169 1721 /**
1170 1722 * Returns an action object used in signalling that the current theme has been received.
1723 + * Ignored from documentation as it's internal to the data store.
1171 1724 *
1725 + * @ignore
1726 + *
1172 1727 * @param {Object} currentTheme The current theme.
1173 1728 *
1174 1729 * @return {Object} Action object.
1175 1730 */
@@ -1181,9 +1736,12 @@
1181 1736 };
1182 1737 }
1183 1738 /**
1184 1739 * Returns an action object used in signalling that the current global styles id has been received.
1740 + * Ignored from documentation as it's internal to the data store.
1185 1741 *
1742 + * @ignore
1743 + *
1186 1744 * @param {string} currentGlobalStylesId The current global styles id.
1187 1745 *
1188 1746 * @return {Object} Action object.
1189 1747 */
@@ -1195,9 +1753,12 @@
1195 1753 };
1196 1754 }
1197 1755 /**
1198 1756 * Returns an action object used in signalling that the theme base global styles have been received
1757 + * Ignored from documentation as it's internal to the data store.
1199 1758 *
1759 + * @ignore
1760 + *
1200 1761 * @param {string} stylesheet The theme's identifier
1201 1762 * @param {Object} globalStyles The global styles object.
1202 1763 *
1203 1764 * @return {Object} Action object.
@@ -1211,9 +1772,12 @@
1211 1772 };
1212 1773 }
1213 1774 /**
1214 1775 * Returns an action object used in signalling that the theme global styles variations have been received.
1776 + * Ignored from documentation as it's internal to the data store.
1215 1777 *
1778 + * @ignore
1779 + *
1216 1780 * @param {string} stylesheet The theme's identifier
1217 1781 * @param {Array} variations The global styles variations.
1218 1782 *
1219 1783 * @return {Object} Action object.
@@ -1244,9 +1808,12 @@
1244 1808 }
1245 1809 /**
1246 1810 * Returns an action object used in signalling that the preview data for
1247 1811 * a given URl has been received.
1812 + * Ignored from documentation as it's internal to the data store.
1248 1813 *
1814 + * @ignore
1815 + *
1249 1816 * @param {string} url URL to preview the embed for.
1250 1817 * @param {*} preview Preview data.
1251 1818 *
1252 1819 * @return {Object} Action object.
@@ -1261,29 +1828,32 @@
1261 1828 }
1262 1829 /**
1263 1830 * Action triggered to delete an entity record.
1264 1831 *
1265 - * @param {string} kind Kind of the deleted entity.
1266 - * @param {string} name Name of the deleted entity.
1267 - * @param {string} recordId Record ID of the deleted entity.
1268 - * @param {?Object} query Special query parameters for the
1269 - * DELETE API call.
1270 - * @param {Object} [options] Delete options.
1271 - * @param {Function} [options.__unstableFetch] Internal use only. Function to
1272 - * call instead of `apiFetch()`.
1273 - * Must return a promise.
1832 + * @param {string} kind Kind of the deleted entity.
1833 + * @param {string} name Name of the deleted entity.
1834 + * @param {string} recordId Record ID of the deleted entity.
1835 + * @param {?Object} query Special query parameters for the
1836 + * DELETE API call.
1837 + * @param {Object} [options] Delete options.
1838 + * @param {Function} [options.__unstableFetch] Internal use only. Function to
1839 + * call instead of `apiFetch()`.
1840 + * Must return a promise.
1841 + * @param {boolean} [options.throwOnError=false] If false, this action suppresses all
1842 + * the exceptions. Defaults to false.
1274 1843 */
1275 1844
1276 1845 const deleteEntityRecord = function (kind, name, recordId, query) {
1277 1846 let {
1278 - __unstableFetch = (external_wp_apiFetch_default())
1847 + __unstableFetch = (external_wp_apiFetch_default()),
1848 + throwOnError = false
1279 1849 } = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1280 1850 return async _ref => {
1281 1851 let {
1282 1852 dispatch
1283 1853 } = _ref;
1284 - const entities = await dispatch(getKindEntities(kind));
1285 - const entity = (0,external_lodash_namespaceObject.find)(entities, {
1854 + const configs = await dispatch(getOrLoadEntitiesConfig(kind));
1855 + const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
1286 1856 kind,
1287 1857 name
1288 1858 });
1289 1859 let error;
@@ -1288,13 +1858,13 @@
1288 1858 });
1289 1859 let error;
1290 1860 let deletedRecord = false;
1291 1861
1292 - if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
1862 + if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
1293 1863 return;
1294 1864 }
1295 1865
1296 - const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId], {
1866 + const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId], {
1297 1867 exclusive: true
1298 1868 });
1299 1869
1300 1870 try {
@@ -1303,11 +1873,12 @@
1303 1873 kind,
1304 1874 name,
1305 1875 recordId
1306 1876 });
1877 + let hasError = false;
1307 1878
1308 1879 try {
1309 - let path = `${entity.baseURL}/${recordId}`;
1880 + let path = `${entityConfig.baseURL}/${recordId}`;
1310 1881
1311 1882 if (query) {
1312 1883 path = (0,external_wp_url_namespaceObject.addQueryArgs)(path, query);
1313 1884 }
@@ -1317,8 +1888,9 @@
1317 1888 method: 'DELETE'
1318 1889 });
1319 1890 await dispatch(removeItems(kind, name, recordId, true));
1320 1891 } catch (_error) {
1892 + hasError = true;
1321 1893 error = _error;
1322 1894 }
1323 1895
1324 1896 dispatch({
@@ -1327,8 +1899,13 @@
1327 1899 name,
1328 1900 recordId,
1329 1901 error
1330 1902 });
1903 +
1904 + if (hasError && throwOnError) {
1905 + throw error;
1906 + }
1907 +
1331 1908 return deletedRecord;
1332 1909 } finally {
1333 1910 dispatch.__unstableReleaseStoreLock(lock);
1334 1911 }
@@ -1337,14 +1914,14 @@
1337 1914 /**
1338 1915 * Returns an action object that triggers an
1339 1916 * edit to an entity record.
1340 1917 *
1341 - * @param {string} kind Kind of the edited entity record.
1342 - * @param {string} name Name of the edited entity record.
1343 - * @param {number} recordId Record ID of the edited entity record.
1344 - * @param {Object} edits The edits.
1345 - * @param {Object} options Options for the edit.
1346 - * @param {boolean} options.undoIgnore Whether to ignore the edit in undo history or not.
1918 + * @param {string} kind Kind of the edited entity record.
1919 + * @param {string} name Name of the edited entity record.
1920 + * @param {number} recordId Record ID of the edited entity record.
1921 + * @param {Object} edits The edits.
1922 + * @param {Object} options Options for the edit.
1923 + * @param {boolean} [options.undoIgnore] Whether to ignore the edit in undo history or not.
1347 1924 *
1348 1925 * @return {Object} Action object.
1349 1926 */
1350 1927
@@ -1354,11 +1931,11 @@
1354 1931 let {
1355 1932 select,
1356 1933 dispatch
1357 1934 } = _ref2;
1358 - const entity = select.getEntity(kind, name);
1935 + const entityConfig = select.getEntityConfig(kind, name);
1359 1936
1360 - if (!entity) {
1937 + if (!entityConfig) {
1361 1938 throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
1362 1939 }
1363 1940
1364 1941 const {
@@ -1363,9 +1940,9 @@
1363 1940
1364 1941 const {
1365 1942 transientEdits = {},
1366 1943 mergedEdits = {}
1367 - } = entity;
1944 + } = entityConfig;
1368 1945 const record = select.getRawEntityRecord(kind, name, recordId);
1369 1946 const editedRecord = select.getEditedEntityRecord(kind, name, recordId);
1370 1947 const edit = {
1371 1948 kind,
@@ -1401,10 +1978,8 @@
1401 1978 };
1402 1979 /**
1403 1980 * Action triggered to undo the last edit to
1404 1981 * an entity record, if any.
1405 - *
1406 - * @return {undefined}
1407 1982 */
1408 1983
1409 1984 const undo = () => _ref3 => {
1410 1985 let {
@@ -1427,10 +2002,8 @@
1427 2002 };
1428 2003 /**
1429 2004 * Action triggered to redo the last undoed
1430 2005 * edit to an entity record, if any.
1431 - *
1432 - * @return {undefined}
1433 2006 */
1434 2007
1435 2008 const redo = () => _ref4 => {
1436 2009 let {
@@ -1464,22 +2037,25 @@
1464 2037 }
1465 2038 /**
1466 2039 * Action triggered to save an entity record.
1467 2040 *
1468 - * @param {string} kind Kind of the received entity.
1469 - * @param {string} name Name of the received entity.
1470 - * @param {Object} record Record to be saved.
1471 - * @param {Object} options Saving options.
1472 - * @param {boolean} [options.isAutosave=false] Whether this is an autosave.
1473 - * @param {Function} [options.__unstableFetch] Internal use only. Function to
1474 - * call instead of `apiFetch()`.
1475 - * Must return a promise.
2041 + * @param {string} kind Kind of the received entity.
2042 + * @param {string} name Name of the received entity.
2043 + * @param {Object} record Record to be saved.
2044 + * @param {Object} options Saving options.
2045 + * @param {boolean} [options.isAutosave=false] Whether this is an autosave.
2046 + * @param {Function} [options.__unstableFetch] Internal use only. Function to
2047 + * call instead of `apiFetch()`.
2048 + * Must return a promise.
2049 + * @param {boolean} [options.throwOnError=false] If false, this action suppresses all
2050 + * the exceptions. Defaults to false.
1476 2051 */
1477 2052
1478 2053 const saveEntityRecord = function (kind, name, record) {
1479 2054 let {
1480 2055 isAutosave = false,
1481 - __unstableFetch = (external_wp_apiFetch_default())
2056 + __unstableFetch = (external_wp_apiFetch_default()),
2057 + throwOnError = false
1482 2058 } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1483 2059 return async _ref5 => {
1484 2060 let {
1485 2061 select,
@@ -1485,21 +2061,21 @@
1485 2061 select,
1486 2062 resolveSelect,
1487 2063 dispatch
1488 2064 } = _ref5;
1489 - const entities = await dispatch(getKindEntities(kind));
1490 - const entity = (0,external_lodash_namespaceObject.find)(entities, {
2065 + const configs = await dispatch(getOrLoadEntitiesConfig(kind));
2066 + const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
1491 2067 kind,
1492 2068 name
1493 2069 });
1494 2070
1495 - if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
2071 + if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
1496 2072 return;
1497 2073 }
1498 2074
1499 - const entityIdKey = entity.key || DEFAULT_ENTITY_KEY;
2075 + const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
1500 2076 const recordId = record[entityIdKey];
1501 - const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, recordId || esm_browser_v4()], {
2077 + const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId || esm_browser_v4()], {
1502 2078 exclusive: true
1503 2079 });
1504 2080
1505 2081 try {
@@ -1525,11 +2101,12 @@
1525 2101 isAutosave
1526 2102 });
1527 2103 let updatedRecord;
1528 2104 let error;
2105 + let hasError = false;
1529 2106
1530 2107 try {
1531 - const path = `${entity.baseURL}${recordId ? '/' + recordId : ''}`;
2108 + const path = `${entityConfig.baseURL}${recordId ? '/' + recordId : ''}`;
1532 2109 const persistedRecord = select.getRawEntityRecord(kind, name, recordId);
1533 2110
1534 2111 if (isAutosave) {
1535 2112 // Most of this autosave logic is very specific to posts.
@@ -1537,9 +2114,9 @@
1537 2114 // but ideally this should all be handled in the back end,
1538 2115 // so the client just sends and receives objects.
1539 2116 const currentUser = select.getCurrentUser();
1540 2117 const currentUserId = currentUser ? currentUser.id : undefined;
1541 - const autosavePost = resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
2118 + const autosavePost = await resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
1542 2119 // So we fallback to the previous autosave and then
1543 2120 // to the actual persisted entity if the edits don't
1544 2121 // have a value.
1545 2122
@@ -1590,11 +2167,11 @@
1590 2167 }
1591 2168 } else {
1592 2169 let edits = record;
1593 2170
1594 - if (entity.__unstablePrePersist) {
2171 + if (entityConfig.__unstablePrePersist) {
1595 2172 edits = { ...edits,
1596 - ...entity.__unstablePrePersist(persistedRecord, edits)
2173 + ...entityConfig.__unstablePrePersist(persistedRecord, edits)
1597 2174 };
1598 2175 }
1599 2176
1600 2177 updatedRecord = await __unstableFetch({
@@ -1604,8 +2181,9 @@
1604 2181 });
1605 2182 dispatch.receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
1606 2183 }
1607 2184 } catch (_error) {
2185 + hasError = true;
1608 2186 error = _error;
1609 2187 }
1610 2188
1611 2189 dispatch({
@@ -1615,8 +2193,13 @@
1615 2193 recordId,
1616 2194 error,
1617 2195 isAutosave
1618 2196 });
2197 +
2198 + if (hasError && throwOnError) {
2199 + throw error;
2200 + }
2201 +
1619 2202 return updatedRecord;
1620 2203 } finally {
1621 2204 dispatch.__unstableReleaseStoreLock(lock);
1622 2205 }
@@ -1640,10 +2223,10 @@
1640 2223 * Each function is passed an object containing
1641 2224 * `saveEntityRecord`, `saveEditedEntityRecord`, and
1642 2225 * `deleteEntityRecord`.
1643 2226 *
1644 - * @return {Promise} A promise that resolves to an array containing the return
1645 - * values of each function given in `requests`.
2227 + * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return
2228 + * values of each function given in `requests`.
1646 2229 */
1647 2230
1648 2231 const __experimentalBatch = requests => async _ref6 => {
1649 2232 let {
@@ -1692,19 +2275,19 @@
1692 2275 if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
1693 2276 return;
1694 2277 }
1695 2278
1696 - const entities = await dispatch(getKindEntities(kind));
1697 - const entity = (0,external_lodash_namespaceObject.find)(entities, {
2279 + const configs = await dispatch(getOrLoadEntitiesConfig(kind));
2280 + const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
1698 2281 kind,
1699 2282 name
1700 2283 });
1701 2284
1702 - if (!entity) {
2285 + if (!entityConfig) {
1703 2286 return;
1704 2287 }
1705 2288
1706 - const entityIdKey = entity.key || DEFAULT_ENTITY_KEY;
2289 + const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
1707 2290 const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
1708 2291 const record = {
1709 2292 [entityIdKey]: recordId,
1710 2293 ...edits
@@ -1761,9 +2344,12 @@
1761 2344 }
1762 2345 /**
1763 2346 * Returns an action object used in signalling that the current user has
1764 2347 * permission to perform an action on a REST resource.
2348 + * Ignored from documentation as it's internal to the data store.
1765 2349 *
2350 + * @ignore
2351 + *
1766 2352 * @param {string} key A key that represents the action and REST resource.
1767 2353 * @param {boolean} isAllowed Whether or not the user can perform the action.
1768 2354 *
1769 2355 * @return {Object} Action object.
@@ -1778,9 +2364,12 @@
1778 2364 }
1779 2365 /**
1780 2366 * Returns an action object used in signalling that the autosaves for a
1781 2367 * post have been received.
2368 + * Ignored from documentation as it's internal to the data store.
1782 2369 *
2370 + * @ignore
2371 + *
1783 2372 * @param {number} postId The id of the post that is parent to the autosave.
1784 2373 * @param {Array|Object} autosaves An array of autosaves or singular autosave object.
1785 2374 *
1786 2375 * @return {Object} Action object.
@@ -1789,17 +2378,18 @@
1789 2378 function receiveAutosaves(postId, autosaves) {
1790 2379 return {
1791 2380 type: 'RECEIVE_AUTOSAVES',
1792 2381 postId,
1793 - autosaves: (0,external_lodash_namespaceObject.castArray)(autosaves)
2382 + autosaves: Array.isArray(autosaves) ? autosaves : [autosaves]
1794 2383 };
1795 2384 }
1796 -//# sourceMappingURL=actions.js.map
2385 +
1797 2386 ;// CONCATENATED MODULE: ./packages/core-data/build-module/entities.js
1798 2387 /**
1799 2388 * External dependencies
1800 2389 */
1801 2390
2391 +
1802 2392 /**
1803 2393 * WordPress dependencies
1804 2394 */
1805 2395
@@ -1811,13 +2401,16 @@
1811 2401
1812 2402
1813 2403 const DEFAULT_ENTITY_KEY = 'id';
1814 2404 const POST_RAW_ATTRIBUTES = ['title', 'excerpt', 'content'];
1815 -const defaultEntities = [{
2405 +const rootEntitiesConfig = [{
1816 2406 label: (0,external_wp_i18n_namespaceObject.__)('Base'),
2407 + kind: 'root',
1817 2408 name: '__unstableBase',
1818 - kind: 'root',
1819 - baseURL: '/'
2409 + baseURL: '/',
2410 + baseURLParams: {
2411 + _fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
2412 + }
1820 2413 }, {
1821 2414 label: (0,external_wp_i18n_namespaceObject.__)('Site'),
1822 2415 name: 'site',
1823 2416 kind: 'root',
@@ -1832,10 +2425,9 @@
1832 2425 key: 'slug',
1833 2426 baseURL: '/wp/v2/types',
1834 2427 baseURLParams: {
1835 2428 context: 'edit'
1836 - },
1837 - rawAttributes: POST_RAW_ATTRIBUTES
2429 + }
1838 2430 }, {
1839 2431 name: 'media',
1840 2432 kind: 'root',
1841 2433 baseURL: '/wp/v2/media',
@@ -1842,9 +2434,10 @@
1842 2434 baseURLParams: {
1843 2435 context: 'edit'
1844 2436 },
1845 2437 plural: 'mediaItems',
1846 - label: (0,external_wp_i18n_namespaceObject.__)('Media')
2438 + label: (0,external_wp_i18n_namespaceObject.__)('Media'),
2439 + rawAttributes: ['caption', 'title', 'description']
1847 2440 }, {
1848 2441 name: 'taxonomy',
1849 2442 kind: 'root',
1850 2443 key: 'slug',
@@ -1857,8 +2450,11 @@
1857 2450 }, {
1858 2451 name: 'sidebar',
1859 2452 kind: 'root',
1860 2453 baseURL: '/wp/v2/sidebars',
2454 + baseURLParams: {
2455 + context: 'edit'
2456 + },
1861 2457 plural: 'sidebars',
1862 2458 transientEdits: {
1863 2459 blocks: true
1864 2460 },
@@ -1919,9 +2515,9 @@
1919 2515 context: 'edit'
1920 2516 },
1921 2517 plural: 'menuItems',
1922 2518 label: (0,external_wp_i18n_namespaceObject.__)('Menu Item'),
1923 - rawAttributes: ['title', 'content']
2519 + rawAttributes: ['title']
1924 2520 }, {
1925 2521 name: 'menuLocation',
1926 2522 kind: 'root',
1927 2523 baseURL: '/wp/v2/menu-locations',
@@ -1931,19 +2527,8 @@
1931 2527 plural: 'menuLocations',
1932 2528 label: (0,external_wp_i18n_namespaceObject.__)('Menu Location'),
1933 2529 key: 'name'
1934 2530 }, {
1935 - name: 'navigationArea',
1936 - kind: 'root',
1937 - baseURL: '/wp/v2/block-navigation-areas',
1938 - baseURLParams: {
1939 - context: 'edit'
1940 - },
1941 - plural: 'navigationAreas',
1942 - label: (0,external_wp_i18n_namespaceObject.__)('Navigation Area'),
1943 - key: 'name',
1944 - getTitle: record => record === null || record === void 0 ? void 0 : record.description
1945 -}, {
1946 2531 label: (0,external_wp_i18n_namespaceObject.__)('Global Styles'),
1947 2532 name: 'globalStyles',
1948 2533 kind: 'root',
1949 2534 baseURL: '/wp/v2/global-styles',
@@ -1950,9 +2535,9 @@
1950 2535 baseURLParams: {
1951 2536 context: 'edit'
1952 2537 },
1953 2538 plural: 'globalStylesVariations',
1954 - // should be different than name
2539 + // Should be different than name.
1955 2540 getTitle: record => {
1956 2541 var _record$title;
1957 2542
1958 2543 return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title);
@@ -1975,13 +2560,13 @@
1975 2560 context: 'edit'
1976 2561 },
1977 2562 key: 'plugin'
1978 2563 }];
1979 -const kinds = [{
1980 - name: 'postType',
2564 +const additionalEntityConfigLoaders = [{
2565 + kind: 'postType',
1981 2566 loadEntities: loadPostTypeEntities
1982 2567 }, {
1983 - name: 'taxonomy',
2568 + kind: 'taxonomy',
1984 2569 loadEntities: loadTaxonomyEntities
1985 2570 }];
1986 2571 /**
1987 2572 * Returns a function to be used to retrieve extra edits to apply before persisting a post type.
@@ -2039,11 +2624,11 @@
2039 2624 meta: true
2040 2625 },
2041 2626 rawAttributes: POST_RAW_ATTRIBUTES,
2042 2627 getTitle: record => {
2043 - var _record$title2;
2628 + var _record$title2, _record$slug;
2044 2629
2045 - return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? (0,external_lodash_namespaceObject.startCase)(record.slug) : String(record.id));
2630 + return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? capitalCase((_record$slug = record.slug) !== null && _record$slug !== void 0 ? _record$slug : '') : String(record.id));
2046 2631 },
2047 2632 __unstablePrePersist: isTemplate ? undefined : prePersistPostType,
2048 2633 __unstable_rest_base: postType.rest_base
2049 2634 };
@@ -2077,8 +2662,17 @@
2077 2662 }
2078 2663 /**
2079 2664 * Returns the entity's getter method name given its kind and name.
2080 2665 *
2666 + * @example
2667 + * ```js
2668 + * const nameSingular = getMethodName( 'root', 'theme', 'get' );
2669 + * // nameSingular is getRootTheme
2670 + *
2671 + * const namePlural = getMethodName( 'root', 'theme', 'set' );
2672 + * // namePlural is setRootThemes
2673 + * ```
2674 + *
2081 2675 * @param {string} kind Entity kind.
2082 2676 * @param {string} name Entity name.
2083 2677 * @param {string} prefix Function prefix.
2084 2678 * @param {boolean} usePlural Whether to use the plural form or not.
@@ -2089,15 +2683,15 @@
2089 2683
2090 2684 const getMethodName = function (kind, name) {
2091 2685 let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'get';
2092 2686 let usePlural = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
2093 - const entity = (0,external_lodash_namespaceObject.find)(defaultEntities, {
2687 + const entityConfig = (0,external_lodash_namespaceObject.find)(rootEntitiesConfig, {
2094 2688 kind,
2095 2689 name
2096 2690 });
2097 - const kindPrefix = kind === 'root' ? '' : (0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(kind));
2098 - const nameSuffix = (0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(name)) + (usePlural ? 's' : '');
2099 - const suffix = usePlural && entity.plural ? (0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(entity.plural)) : nameSuffix;
2691 + const kindPrefix = kind === 'root' ? '' : pascalCase(kind);
2692 + const nameSuffix = pascalCase(name) + (usePlural ? 's' : '');
2693 + const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? pascalCase(entityConfig.plural) : nameSuffix;
2100 2694 return `${prefix}${kindPrefix}${suffix}`;
2101 2695 };
2102 2696 /**
2103 2697 * Loads the kind entities into the store.
@@ -2103,35 +2697,35 @@
2103 2697 * Loads the kind entities into the store.
2104 2698 *
2105 2699 * @param {string} kind Kind
2106 2700 *
2107 - * @return {Array} Entities
2701 + * @return {(thunkArgs: object) => Promise<Array>} Entities
2108 2702 */
2109 2703
2110 -const getKindEntities = kind => async _ref => {
2704 +const getOrLoadEntitiesConfig = kind => async _ref => {
2111 2705 let {
2112 2706 select,
2113 2707 dispatch
2114 2708 } = _ref;
2115 - let entities = select.getEntitiesByKind(kind);
2709 + let configs = select.getEntitiesConfig(kind);
2116 2710
2117 - if (entities && entities.length !== 0) {
2118 - return entities;
2711 + if (configs && configs.length !== 0) {
2712 + return configs;
2119 2713 }
2120 2714
2121 - const kindConfig = (0,external_lodash_namespaceObject.find)(kinds, {
2122 - name: kind
2715 + const loader = (0,external_lodash_namespaceObject.find)(additionalEntityConfigLoaders, {
2716 + kind
2123 2717 });
2124 2718
2125 - if (!kindConfig) {
2719 + if (!loader) {
2126 2720 return [];
2127 2721 }
2128 2722
2129 - entities = await kindConfig.loadEntities();
2130 - dispatch(addEntities(entities));
2131 - return entities;
2723 + configs = await loader.loadEntities();
2724 + dispatch(addEntities(configs));
2725 + return configs;
2132 2726 };
2133 -//# sourceMappingURL=entities.js.map
2727 +
2134 2728 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/get-normalized-comma-separable.js
2135 2729 /**
2136 2730 * Given a value which can be specified as one or the other of a comma-separated
2137 2731 * string or an array, returns a value normalized to an array of strings, or
@@ -2150,16 +2744,12 @@
2150 2744
2151 2745 return null;
2152 2746 }
2153 2747
2154 -/* harmony default export */ var get_normalized_comma_separable = (getNormalizedCommaSeparable);
2155 -//# sourceMappingURL=get-normalized-comma-separable.js.map
2748 +/* harmony default export */ const get_normalized_comma_separable = (getNormalizedCommaSeparable);
2749 +
2156 2750 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/with-weak-map-cache.js
2157 2751 /**
2158 - * External dependencies
2159 - */
2160 -
2161 -/**
2162 2752 * Given a function, returns an enhanced function which caches the result and
2163 2753 * tracks in WeakMap. The result is only cached if the original function is
2164 2754 * passed a valid object-like argument (requirement for WeakMap key).
2165 2755 *
@@ -2166,9 +2756,8 @@
2166 2756 * @param {Function} fn Original function.
2167 2757 *
2168 2758 * @return {Function} Enhanced caching function.
2169 2759 */
2170 -
2171 2760 function withWeakMapCache(fn) {
2172 2761 const cache = new WeakMap();
2173 2762 return key => {
2174 2763 let value;
@@ -2179,9 +2768,9 @@
2179 2768 value = fn(key); // Can reach here if key is not valid for WeakMap, since `has`
2180 2769 // will return false for invalid key. Since `set` will throw,
2181 2770 // ensure that key is valid before setting into cache.
2182 2771
2183 - if ((0,external_lodash_namespaceObject.isObjectLike)(key)) {
2772 + if (key !== null && typeof key === 'object') {
2184 2773 cache.set(key, value);
2185 2774 }
2186 2775 }
2187 2776
@@ -2188,10 +2777,10 @@
2188 2777 return value;
2189 2778 };
2190 2779 }
2191 2780
2192 -/* harmony default export */ var with_weak_map_cache = (withWeakMapCache);
2193 -//# sourceMappingURL=with-weak-map-cache.js.map
2781 +/* harmony default export */ const with_weak_map_cache = (withWeakMapCache);
2782 +
2194 2783 ;// CONCATENATED MODULE: ./packages/core-data/build-module/queried-data/get-query-parts.js
2195 2784 /**
2196 2785 * WordPress dependencies
2197 2786 */
@@ -2262,20 +2851,28 @@
2262 2851 default:
2263 2852 // While in theory, we could exclude "_fields" from the stableKey
2264 2853 // because two request with different fields have the same results
2265 2854 // We're not able to ensure that because the server can decide to omit
2266 - // fields from the response even if we explicitely asked for it.
2855 + // fields from the response even if we explicitly asked for it.
2267 2856 // Example: Asking for titles in posts without title support.
2268 2857 if (key === '_fields') {
2269 - parts.fields = get_normalized_comma_separable(value); // Make sure to normalize value for `stableKey`
2858 + var _getNormalizedCommaSe;
2270 2859
2860 + parts.fields = (_getNormalizedCommaSe = get_normalized_comma_separable(value)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : []; // Make sure to normalize value for `stableKey`
2861 +
2271 2862 value = parts.fields.join();
2272 2863 } // Two requests with different include values cannot have same results.
2273 2864
2274 2865
2275 2866 if (key === 'include') {
2276 - parts.include = get_normalized_comma_separable(value).map(Number); // Normalize value for `stableKey`.
2867 + var _getNormalizedCommaSe2;
2277 2868
2869 + if (typeof value === 'number') {
2870 + value = value.toString();
2871 + }
2872 +
2873 + parts.include = ((_getNormalizedCommaSe2 = get_normalized_comma_separable(value)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []).map(Number); // Normalize value for `stableKey`.
2874 +
2278 2875 value = parts.include.join();
2279 2876 } // While it could be any deterministic string, for simplicity's
2280 2877 // sake mimic querystring encoding for stable key.
2281 2878 //
@@ -2292,10 +2889,10 @@
2292 2889 }
2293 2890
2294 2891 return parts;
2295 2892 }
2296 -/* harmony default export */ var get_query_parts = (with_weak_map_cache(getQueryParts));
2297 -//# sourceMappingURL=get-query-parts.js.map
2893 +/* harmony default export */ const get_query_parts = (with_weak_map_cache(getQueryParts));
2894 +
2298 2895 ;// CONCATENATED MODULE: ./packages/core-data/build-module/queried-data/reducer.js
2299 2896 /**
2300 2897 * External dependencies
2301 2898 */
@@ -2304,8 +2901,9 @@
2304 2901 * WordPress dependencies
2305 2902 */
2306 2903
2307 2904
2905 +
2308 2906 /**
2309 2907 * Internal dependencies
2310 2908 */
2311 2909
@@ -2338,8 +2936,10 @@
2338 2936 */
2339 2937
2340 2938
2341 2939 function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
2940 + var _itemIds$length;
2941 +
2342 2942 const receivedAllIds = page === 1 && perPage === -1;
2343 2943
2344 2944 if (receivedAllIds) {
2345 2945 return nextItemIds;
@@ -2347,9 +2947,9 @@
2347 2947
2348 2948 const nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known
2349 2949 // size of the existing array, else calculate as extending the existing.
2350 2950
2351 - const size = Math.max(itemIds.length, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
2951 + const size = Math.max((_itemIds$length = itemIds === null || itemIds === void 0 ? void 0 : itemIds.length) !== null && _itemIds$length !== void 0 ? _itemIds$length : 0, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
2352 2952
2353 2953 const mergedItemIds = new Array(size);
2354 2954
2355 2955 for (let i = 0; i < size; i++) {
@@ -2354,9 +2954,9 @@
2354 2954
2355 2955 for (let i = 0; i < size; i++) {
2356 2956 // Preserve existing item ID except for subset of range of next items.
2357 2957 const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length;
2358 - mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds[i];
2958 + mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds === null || itemIds === void 0 ? void 0 : itemIds[i];
2359 2959 }
2360 2960
2361 2961 return mergedItemIds;
2362 2962 }
@@ -2404,12 +3004,12 @@
2404 3004 * where not all properties associated with an entity are necessarily returned.
2405 3005 * In such cases, completeness is used as an indication of whether it would be
2406 3006 * safe to use queried data for a non-`_fields`-limited request.
2407 3007 *
2408 - * @param {Object<string,boolean>} state Current state.
2409 - * @param {Object} action Dispatched action.
3008 + * @param {Object<string,Object<string,boolean>>} state Current state.
3009 + * @param {Object} action Dispatched action.
2410 3010 *
2411 - * @return {Object<string,boolean>} Next state.
3011 + * @return {Object<string,Object<string,boolean>>} Next state.
2412 3012 */
2413 3013
2414 3014 function itemIsComplete() {
2415 3015 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2424,9 +3024,9 @@
2424 3024 key = DEFAULT_ENTITY_KEY
2425 3025 } = action; // An item is considered complete if it is received without an associated
2426 3026 // fields query. Ideally, this would be implemented in such a way where the
2427 3027 // complete aggregate of all fields would satisfy completeness. Since the
2428 - // fields are not consistent across all entity types, this would require
3028 + // fields are not consistent across all entities, this would require
2429 3029 // introspection on the REST schema for each entity to know which fields
2430 3030 // compose a complete item for that entity.
2431 3031
2432 3032 const queryParts = query ? get_query_parts(query) : {};
@@ -2461,9 +3061,9 @@
2461 3061 *
2462 3062 * @return {Object} Next state.
2463 3063 */
2464 3064
2465 -const receiveQueries = (0,external_lodash_namespaceObject.flowRight)([// Limit to matching action type so we don't attempt to replace action on
3065 +const receiveQueries = (0,external_wp_compose_namespaceObject.compose)([// Limit to matching action type so we don't attempt to replace action on
2466 3066 // an unhandled action.
2467 3067 if_matching_action(action => 'query' in action), // Inject query parts into action for use both in `onSubKey` and reducer.
2468 3068 replace_action(action => {
2469 3069 // `ifMatchingAction` still passes on initialization, where state is
@@ -2528,14 +3128,14 @@
2528 3128 return state;
2529 3129 }
2530 3130 };
2531 3131
2532 -/* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
3132 +/* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
2533 3133 items,
2534 3134 itemIsComplete,
2535 3135 queries
2536 3136 }));
2537 -//# sourceMappingURL=reducer.js.map
3137 +
2538 3138 ;// CONCATENATED MODULE: ./packages/core-data/build-module/reducer.js
2539 3139 /**
2540 3140 * External dependencies
2541 3141 */
@@ -2545,8 +3145,9 @@
2545 3145 */
2546 3146
2547 3147
2548 3148
3149 +
2549 3150 /**
2550 3151 * Internal dependencies
2551 3152 */
2552 3153
@@ -2552,8 +3153,10 @@
2552 3153
2553 3154
2554 3155
2555 3156
3157 +/** @typedef {import('./types').AnyFunction} AnyFunction */
3158 +
2556 3159 /**
2557 3160 * Reducer managing terms state. Keyed by taxonomy slug, the value is either
2558 3161 * undefined (if no request has been made for given taxonomy), null (if a
2559 3162 * request is in-flight for given taxonomy), or the array of terms for the
@@ -2597,9 +3200,12 @@
2597 3200 switch (action.type) {
2598 3201 case 'RECEIVE_USER_QUERY':
2599 3202 return {
2600 3203 byId: { ...state.byId,
2601 - ...(0,external_lodash_namespaceObject.keyBy)(action.users, 'id')
3204 + // Key users by their ID.
3205 + ...action.users.reduce((newUsers, user) => ({ ...newUsers,
3206 + [user.id]: user
3207 + }), {})
2602 3208 },
2603 3209 queries: { ...state.queries,
2604 3210 [action.queryID]: (0,external_lodash_namespaceObject.map)(action.users, user => user.id)
2605 3211 }
@@ -2650,12 +3256,12 @@
2650 3256 }
2651 3257 /**
2652 3258 * Reducer managing the current theme.
2653 3259 *
2654 - * @param {string} state Current state.
2655 - * @param {Object} action Dispatched action.
3260 + * @param {string|undefined} state Current state.
3261 + * @param {Object} action Dispatched action.
2656 3262 *
2657 - * @return {string} Updated state.
3263 + * @return {string|undefined} Updated state.
2658 3264 */
2659 3265
2660 3266 function currentTheme() {
2661 3267 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
@@ -2670,12 +3276,12 @@
2670 3276 }
2671 3277 /**
2672 3278 * Reducer managing the current global styles id.
2673 3279 *
2674 - * @param {string} state Current state.
2675 - * @param {Object} action Dispatched action.
3280 + * @param {string|undefined} state Current state.
3281 + * @param {Object} action Dispatched action.
2676 3282 *
2677 - * @return {string} Updated state.
3283 + * @return {string|undefined} Updated state.
2678 3284 */
2679 3285
2680 3286 function currentGlobalStylesId() {
2681 3287 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
@@ -2690,12 +3296,12 @@
2690 3296 }
2691 3297 /**
2692 3298 * Reducer managing the theme base global styles.
2693 3299 *
2694 - * @param {string} state Current state.
2695 - * @param {Object} action Dispatched action.
3300 + * @param {Record<string, object>} state Current state.
3301 + * @param {Object} action Dispatched action.
2696 3302 *
2697 - * @return {string} Updated state.
3303 + * @return {Record<string, object>} Updated state.
2698 3304 */
2699 3305
2700 3306 function themeBaseGlobalStyles() {
2701 3307 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2712,12 +3318,12 @@
2712 3318 }
2713 3319 /**
2714 3320 * Reducer managing the theme global styles variations.
2715 3321 *
2716 - * @param {string} state Current state.
2717 - * @param {Object} action Dispatched action.
3322 + * @param {Record<string, object>} state Current state.
3323 + * @param {Object} action Dispatched action.
2718 3324 *
2719 - * @return {string} Updated state.
3325 + * @return {Record<string, object>} Updated state.
2720 3326 */
2721 3327
2722 3328 function themeGlobalStyleVariations() {
2723 3329 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2740,13 +3346,13 @@
2740 3346 * - Saving
2741 3347 *
2742 3348 * @param {Object} entityConfig Entity config.
2743 3349 *
2744 - * @return {Function} Reducer.
3350 + * @return {AnyFunction} Reducer.
2745 3351 */
2746 3352
2747 3353 function entity(entityConfig) {
2748 - return (0,external_lodash_namespaceObject.flowRight)([// Limit to matching action type so we don't attempt to replace action on
3354 + return (0,external_wp_compose_namespaceObject.compose)([// Limit to matching action type so we don't attempt to replace action on
2749 3355 // an unhandled action.
2750 3356 if_matching_action(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), // Inject the entity config into the action.
2751 3357 replace_action(action => {
2752 3358 return { ...action,
@@ -2868,9 +3474,9 @@
2868 3474 */
2869 3475
2870 3476
2871 3477 function entitiesConfig() {
2872 - let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultEntities;
3478 + let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : rootEntitiesConfig;
2873 3479 let action = arguments.length > 1 ? arguments[1] : undefined;
2874 3480
2875 3481 switch (action.type) {
2876 3482 case 'ADD_ENTITIES':
@@ -2890,9 +3496,9 @@
2890 3496
2891 3497 const entities = function () {
2892 3498 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2893 3499 let action = arguments.length > 1 ? arguments[1] : undefined;
2894 - const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities
3500 + const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities.
2895 3501
2896 3502 let entitiesDataReducer = state.reducer;
2897 3503
2898 3504 if (!entitiesDataReducer || newConfig !== state.config) {
@@ -2906,32 +3512,50 @@
2906 3512 return memo;
2907 3513 }, {}));
2908 3514 }
2909 3515
2910 - const newData = entitiesDataReducer(state.data, action);
3516 + const newData = entitiesDataReducer(state.records, action);
2911 3517
2912 - if (newData === state.data && newConfig === state.config && entitiesDataReducer === state.reducer) {
3518 + if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) {
2913 3519 return state;
2914 3520 }
2915 3521
2916 3522 return {
2917 3523 reducer: entitiesDataReducer,
2918 - data: newData,
3524 + records: newData,
2919 3525 config: newConfig
2920 3526 };
2921 3527 };
2922 3528 /**
3529 + * @typedef {Object} UndoStateMeta
3530 + *
3531 + * @property {number} offset Where in the undo stack we are.
3532 + * @property {Object} [flattenedUndo] Flattened form of undo stack.
3533 + */
3534 +
3535 +/** @typedef {Array<Object> & UndoStateMeta} UndoState */
3536 +
3537 +/**
3538 + * @type {UndoState}
3539 + *
3540 + * @todo Given how we use this we might want to make a custom class for it.
3541 + */
3542 +
3543 +const UNDO_INITIAL_STATE = Object.assign([], {
3544 + offset: 0
3545 +});
3546 +/** @type {Object} */
3547 +
3548 +let lastEditAction;
3549 +/**
2923 3550 * Reducer keeping track of entity edit undo history.
2924 3551 *
2925 - * @param {Object} state Current state.
2926 - * @param {Object} action Dispatched action.
3552 + * @param {UndoState} state Current state.
3553 + * @param {Object} action Dispatched action.
2927 3554 *
2928 - * @return {Object} Updated state.
3555 + * @return {UndoState} Updated state.
2929 3556 */
2930 3557
2931 -const UNDO_INITIAL_STATE = [];
2932 -UNDO_INITIAL_STATE.offset = 0;
2933 -let lastEditAction;
2934 3558 function reducer_undo() {
2935 3559 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE;
2936 3560 let action = arguments.length > 1 ? arguments[1] : undefined;
2937 3561
@@ -2956,12 +3580,15 @@
2956 3580 }
2957 3581 };
2958 3582 }
2959 3583 }
3584 + /** @type {UndoState} */
2960 3585
3586 +
2961 3587 let nextState;
2962 3588
2963 3589 if (isUndoOrRedo) {
3590 + // @ts-ignore we might consider using Object.assign({}, state)
2964 3591 nextState = [...state];
2965 3592 nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1);
2966 3593
2967 3594 if (state.flattenedUndo) {
@@ -2995,8 +3622,9 @@
2995 3622 // are merged. They are defined in the entity's config.
2996 3623
2997 3624
2998 3625 if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) {
3626 + // @ts-ignore we might consider using Object.assign({}, state)
2999 3627 nextState = [...state];
3000 3628 nextState.flattenedUndo = { ...state.flattenedUndo,
3001 3629 ...action.edits
3002 3630 };
@@ -3004,9 +3632,10 @@
3004 3632 return nextState;
3005 3633 } // Clear potential redos, because this only supports linear history.
3006 3634
3007 3635
3008 - nextState = nextState || state.slice(0, state.offset || undefined);
3636 + nextState = // @ts-ignore this needs additional cleanup, probably involving code-level changes
3637 + nextState || state.slice(0, state.offset || undefined);
3009 3638 nextState.offset = nextState.offset || 0;
3010 3639 nextState.pop();
3011 3640
3012 3641 if (!isCreateUndoLevel) {
@@ -3115,9 +3744,31 @@
3115 3744 }
3116 3745
3117 3746 return state;
3118 3747 }
3119 -/* harmony default export */ var build_module_reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
3748 +function blockPatterns() {
3749 + let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3750 + let action = arguments.length > 1 ? arguments[1] : undefined;
3751 +
3752 + switch (action.type) {
3753 + case 'RECEIVE_BLOCK_PATTERNS':
3754 + return action.patterns;
3755 + }
3756 +
3757 + return state;
3758 +}
3759 +function blockPatternCategories() {
3760 + let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3761 + let action = arguments.length > 1 ? arguments[1] : undefined;
3762 +
3763 + switch (action.type) {
3764 + case 'RECEIVE_BLOCK_PATTERN_CATEGORIES':
3765 + return action.categories;
3766 + }
3767 +
3768 + return state;
3769 +}
3770 +/* harmony default export */ const build_module_reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
3120 3771 terms,
3121 3772 users,
3122 3773 currentTheme,
3123 3774 currentGlobalStylesId,
@@ -3128,39 +3779,67 @@
3128 3779 entities,
3129 3780 undo: reducer_undo,
3130 3781 embedPreviews,
3131 3782 userPermissions,
3132 - autosaves
3783 + autosaves,
3784 + blockPatterns,
3785 + blockPatternCategories
3133 3786 }));
3134 -//# sourceMappingURL=reducer.js.map
3787 +
3135 3788 ;// CONCATENATED MODULE: ./node_modules/rememo/es/rememo.js
3136 3789
3137 3790
3138 -var LEAF_KEY, hasWeakMap;
3791 +/** @typedef {(...args: any[]) => *[]} GetDependants */
3139 3792
3793 +/** @typedef {() => void} Clear */
3794 +
3140 3795 /**
3141 - * Arbitrary value used as key for referencing cache object in WeakMap tree.
3796 + * @typedef {{
3797 + * getDependants: GetDependants,
3798 + * clear: Clear
3799 + * }} EnhancedSelector
3800 + */
3801 +
3802 +/**
3803 + * Internal cache entry.
3142 3804 *
3143 - * @type {Object}
3805 + * @typedef CacheNode
3806 + *
3807 + * @property {?CacheNode|undefined} [prev] Previous node.
3808 + * @property {?CacheNode|undefined} [next] Next node.
3809 + * @property {*[]} args Function arguments for cache entry.
3810 + * @property {*} val Function result.
3144 3811 */
3145 -LEAF_KEY = {};
3146 3812
3147 3813 /**
3148 - * Whether environment supports WeakMap.
3814 + * @typedef Cache
3149 3815 *
3150 - * @type {boolean}
3816 + * @property {Clear} clear Function to clear cache.
3817 + * @property {boolean} [isUniqueByDependants] Whether dependants are valid in
3818 + * considering cache uniqueness. A cache is unique if dependents are all arrays
3819 + * or objects.
3820 + * @property {CacheNode?} [head] Cache head.
3821 + * @property {*[]} [lastDependants] Dependants from previous invocation.
3151 3822 */
3152 -hasWeakMap = typeof WeakMap !== 'undefined';
3153 3823
3154 3824 /**
3825 + * Arbitrary value used as key for referencing cache object in WeakMap tree.
3826 + *
3827 + * @type {{}}
3828 + */
3829 +var LEAF_KEY = {};
3830 +
3831 +/**
3155 3832 * Returns the first argument as the sole entry in an array.
3156 3833 *
3157 - * @param {*} value Value to return.
3834 + * @template T
3158 3835 *
3159 - * @return {Array} Value returned as entry in array.
3836 + * @param {T} value Value to return.
3837 + *
3838 + * @return {[T]} Value returned as entry in array.
3160 3839 */
3161 -function arrayOf( value ) {
3162 - return [ value ];
3840 +function arrayOf(value) {
3841 + return [value];
3163 3842 }
3164 3843
3165 3844 /**
3166 3845 * Returns true if the value passed is object-like, or false otherwise. A value
@@ -3169,20 +3848,21 @@
3169 3848 * @param {*} value Value to test.
3170 3849 *
3171 3850 * @return {boolean} Whether value is object-like.
3172 3851 */
3173 -function isObjectLike( value ) {
3174 - return !! value && 'object' === typeof value;
3852 +function isObjectLike(value) {
3853 + return !!value && 'object' === typeof value;
3175 3854 }
3176 3855
3177 3856 /**
3178 3857 * Creates and returns a new cache object.
3179 3858 *
3180 - * @return {Object} Cache object.
3859 + * @return {Cache} Cache object.
3181 3860 */
3182 3861 function createCache() {
3862 + /** @type {Cache} */
3183 3863 var cache = {
3184 - clear: function() {
3864 + clear: function () {
3185 3865 cache.head = null;
3186 3866 },
3187 3867 };
3188 3868
@@ -3192,23 +3872,23 @@
3192 3872 /**
3193 3873 * Returns true if entries within the two arrays are strictly equal by
3194 3874 * reference from a starting index.
3195 3875 *
3196 - * @param {Array} a First array.
3197 - * @param {Array} b Second array.
3876 + * @param {*[]} a First array.
3877 + * @param {*[]} b Second array.
3198 3878 * @param {number} fromIndex Index from which to start comparison.
3199 3879 *
3200 3880 * @return {boolean} Whether arrays are shallowly equal.
3201 3881 */
3202 -function isShallowEqual( a, b, fromIndex ) {
3882 +function isShallowEqual(a, b, fromIndex) {
3203 3883 var i;
3204 3884
3205 - if ( a.length !== b.length ) {
3885 + if (a.length !== b.length) {
3206 3886 return false;
3207 3887 }
3208 3888
3209 - for ( i = fromIndex; i < a.length; i++ ) {
3210 - if ( a[ i ] !== b[ i ] ) {
3889 + for (i = fromIndex; i < a.length; i++) {
3890 + if (a[i] !== b[i]) {
3211 3891 return false;
3212 3892 }
3213 3893 }
3214 3894
@@ -3222,35 +3902,22 @@
3222 3902 * its own return value. The memoize cache is preserved only as long as those
3223 3903 * dependant references remain the same. If getDependants returns a different
3224 3904 * reference(s), the cache is cleared and the selector value regenerated.
3225 3905 *
3226 - * @param {Function} selector Selector function.
3227 - * @param {Function} getDependants Dependant getter returning an immutable
3228 - * reference or array of reference used in
3229 - * cache bust consideration.
3906 + * @template {(...args: *[]) => *} S
3230 3907 *
3231 - * @return {Function} Memoized selector.
3908 + * @param {S} selector Selector function.
3909 + * @param {GetDependants=} getDependants Dependant getter returning an array of
3910 + * references used in cache bust consideration.
3232 3911 */
3233 -/* harmony default export */ function rememo(selector, getDependants ) {
3234 - var rootCache, getCache;
3912 +/* harmony default export */ function rememo(selector, getDependants) {
3913 + /** @type {WeakMap<*,*>} */
3914 + var rootCache;
3235 3915
3236 - // Use object source as dependant if getter not provided
3237 - if ( ! getDependants ) {
3238 - getDependants = arrayOf;
3239 - }
3916 + /** @type {GetDependants} */
3917 + var normalizedGetDependants = getDependants ? getDependants : arrayOf;
3240 3918
3241 3919 /**
3242 - * Returns the root cache. If WeakMap is supported, this is assigned to the
3243 - * root WeakMap cache set, otherwise it is a shared instance of the default
3244 - * cache object.
3245 - *
3246 - * @return {(WeakMap|Object)} Root cache object.
3247 - */
3248 - function getRootCache() {
3249 - return rootCache;
3250 - }
3251 -
3252 - /**
3253 3920 * Returns the cache for a given dependants array. When possible, a WeakMap
3254 3921 * will be used to create a unique cache for each set of dependants. This
3255 3922 * is feasible due to the nature of WeakMap in allowing garbage collection
3256 3923 * to occur on entries where the key object is no longer referenced. Since
@@ -3262,34 +3929,37 @@
3262 3929 * like, then the cache is shared across all invocations.
3263 3930 *
3264 3931 * @see isObjectLike
3265 3932 *
3266 - * @param {Array} dependants Selector dependants.
3933 + * @param {*[]} dependants Selector dependants.
3267 3934 *
3268 - * @return {Object} Cache object.
3935 + * @return {Cache} Cache object.
3269 3936 */
3270 - function getWeakMapCache( dependants ) {
3937 + function getCache(dependants) {
3271 3938 var caches = rootCache,
3272 3939 isUniqueByDependants = true,
3273 - i, dependant, map, cache;
3940 + i,
3941 + dependant,
3942 + map,
3943 + cache;
3274 3944
3275 - for ( i = 0; i < dependants.length; i++ ) {
3276 - dependant = dependants[ i ];
3945 + for (i = 0; i < dependants.length; i++) {
3946 + dependant = dependants[i];
3277 3947
3278 3948 // Can only compose WeakMap from object-like key.
3279 - if ( ! isObjectLike( dependant ) ) {
3949 + if (!isObjectLike(dependant)) {
3280 3950 isUniqueByDependants = false;
3281 3951 break;
3282 3952 }
3283 3953
3284 3954 // Does current segment of cache already have a WeakMap?
3285 - if ( caches.has( dependant ) ) {
3955 + if (caches.has(dependant)) {
3286 3956 // Traverse into nested WeakMap.
3287 - caches = caches.get( dependant );
3957 + caches = caches.get(dependant);
3288 3958 } else {
3289 3959 // Create, set, and traverse into a new one.
3290 3960 map = new WeakMap();
3291 - caches.set( dependant, map );
3961 + caches.set(dependant, map);
3292 3962 caches = map;
3293 3963 }
3294 3964 }
3295 3965
@@ -3294,55 +3964,60 @@
3294 3964 }
3295 3965
3296 3966 // We use an arbitrary (but consistent) object as key for the last item
3297 3967 // in the WeakMap to serve as our running cache.
3298 - if ( ! caches.has( LEAF_KEY ) ) {
3968 + if (!caches.has(LEAF_KEY)) {
3299 3969 cache = createCache();
3300 3970 cache.isUniqueByDependants = isUniqueByDependants;
3301 - caches.set( LEAF_KEY, cache );
3971 + caches.set(LEAF_KEY, cache);
3302 3972 }
3303 3973
3304 - return caches.get( LEAF_KEY );
3974 + return caches.get(LEAF_KEY);
3305 3975 }
3306 3976
3307 - // Assign cache handler by availability of WeakMap
3308 - getCache = hasWeakMap ? getWeakMapCache : getRootCache;
3309 -
3310 3977 /**
3311 3978 * Resets root memoization cache.
3312 3979 */
3313 3980 function clear() {
3314 - rootCache = hasWeakMap ? new WeakMap() : createCache();
3981 + rootCache = new WeakMap();
3315 3982 }
3316 3983
3317 - // eslint-disable-next-line jsdoc/check-param-names
3984 + /* eslint-disable jsdoc/check-param-names */
3318 3985 /**
3319 3986 * The augmented selector call, considering first whether dependants have
3320 3987 * changed before passing it to underlying memoize function.
3321 3988 *
3322 - * @param {Object} source Source object for derivation.
3323 - * @param {...*} extraArgs Additional arguments to pass to selector.
3989 + * @param {*} source Source object for derivation.
3990 + * @param {...*} extraArgs Additional arguments to pass to selector.
3324 3991 *
3325 3992 * @return {*} Selector result.
3326 3993 */
3327 - function callSelector( /* source, ...extraArgs */ ) {
3994 + /* eslint-enable jsdoc/check-param-names */
3995 + function callSelector(/* source, ...extraArgs */) {
3328 3996 var len = arguments.length,
3329 - cache, node, i, args, dependants;
3997 + cache,
3998 + node,
3999 + i,
4000 + args,
4001 + dependants;
3330 4002
3331 4003 // Create copy of arguments (avoid leaking deoptimization).
3332 - args = new Array( len );
3333 - for ( i = 0; i < len; i++ ) {
3334 - args[ i ] = arguments[ i ];
4004 + args = new Array(len);
4005 + for (i = 0; i < len; i++) {
4006 + args[i] = arguments[i];
3335 4007 }
3336 4008
3337 - dependants = getDependants.apply( null, args );
3338 - cache = getCache( dependants );
4009 + dependants = normalizedGetDependants.apply(null, args);
4010 + cache = getCache(dependants);
3339 4011
3340 - // If not guaranteed uniqueness by dependants (primitive type or lack
3341 - // of WeakMap support), shallow compare against last dependants and, if
3342 - // references have changed, destroy cache to recalculate result.
3343 - if ( ! cache.isUniqueByDependants ) {
3344 - if ( cache.lastDependants && ! isShallowEqual( dependants, cache.lastDependants, 0 ) ) {
4012 + // If not guaranteed uniqueness by dependants (primitive type), shallow
4013 + // compare against last dependants and, if references have changed,
4014 + // destroy cache to recalculate result.
4015 + if (!cache.isUniqueByDependants) {
4016 + if (
4017 + cache.lastDependants &&
4018 + !isShallowEqual(dependants, cache.lastDependants, 0)
4019 + ) {
3345 4020 cache.clear();
3346 4021 }
3347 4022
3348 4023 cache.lastDependants = dependants;
@@ -3348,11 +4023,11 @@
3348 4023 cache.lastDependants = dependants;
3349 4024 }
3350 4025
3351 4026 node = cache.head;
3352 - while ( node ) {
4027 + while (node) {
3353 4028 // Check whether node arguments match arguments
3354 - if ( ! isShallowEqual( node.args, args, 1 ) ) {
4029 + if (!isShallowEqual(node.args, args, 1)) {
3355 4030 node = node.next;
3356 4031 continue;
3357 4032 }
3358 4033
@@ -3358,18 +4033,18 @@
3358 4033
3359 4034 // At this point we can assume we've found a match
3360 4035
3361 4036 // Surface matched node to head if not already
3362 - if ( node !== cache.head ) {
4037 + if (node !== cache.head) {
3363 4038 // Adjust siblings to point to each other.
3364 - node.prev.next = node.next;
3365 - if ( node.next ) {
4039 + /** @type {CacheNode} */ (node.prev).next = node.next;
4040 + if (node.next) {
3366 4041 node.next.prev = node.prev;
3367 4042 }
3368 4043
3369 4044 node.next = cache.head;
3370 4045 node.prev = null;
3371 - cache.head.prev = node;
4046 + /** @type {CacheNode} */ (cache.head).prev = node;
3372 4047 cache.head = node;
3373 4048 }
3374 4049
3375 4050 // Return immediately
@@ -3377,15 +4052,15 @@
3377 4052 }
3378 4053
3379 4054 // No cached value found. Continue to insertion phase:
3380 4055
3381 - node = {
4056 + node = /** @type {CacheNode} */ ({
3382 4057 // Generate the result from original function
3383 - val: selector.apply( null, args ),
3384 - };
4058 + val: selector.apply(null, args),
4059 + });
3385 4060
3386 4061 // Avoid including the source object in the cache.
3387 - args[ 0 ] = null;
4062 + args[0] = null;
3388 4063 node.args = args;
3389 4064
3390 4065 // Don't need to check whether node is already head, since it would
3391 4066 // have been returned above already if it was
@@ -3390,9 +4065,9 @@
3390 4065 // Don't need to check whether node is already head, since it would
3391 4066 // have been returned above already if it was
3392 4067
3393 4068 // Shift existing head down list
3394 - if ( cache.head ) {
4069 + if (cache.head) {
3395 4070 cache.head.prev = node;
3396 4071 node.next = cache.head;
3397 4072 }
3398 4073
@@ -3400,17 +4075,17 @@
3400 4075
3401 4076 return node.val;
3402 4077 }
3403 4078
3404 - callSelector.getDependants = getDependants;
4079 + callSelector.getDependants = normalizedGetDependants;
3405 4080 callSelector.clear = clear;
3406 4081 clear();
3407 4082
3408 - return callSelector;
4083 + return /** @type {S & EnhancedSelector} */ (callSelector);
3409 4084 }
3410 4085
3411 4086 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js
3412 -var equivalent_key_map = __webpack_require__(3909);
4087 +var equivalent_key_map = __webpack_require__(2167);
3413 4088 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map);
3414 4089 ;// CONCATENATED MODULE: ./packages/core-data/build-module/queried-data/selectors.js
3415 4090 /**
3416 4091 * External dependencies
@@ -3541,14 +4216,14 @@
3541 4216 const items = getQueriedItemsUncached(state, query);
3542 4217 queriedItemsCache.set(query, items);
3543 4218 return items;
3544 4219 });
3545 -//# sourceMappingURL=selectors.js.map
4220 +
3546 4221 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/is-raw-attribute.js
3547 4222 /**
3548 4223 * Checks whether the attribute is a "raw" attribute or not.
3549 4224 *
3550 - * @param {Object} entity Entity data.
4225 + * @param {Object} entity Entity record.
3551 4226 * @param {string} attribute Attribute name.
3552 4227 *
3553 4228 * @return {boolean} Is the attribute raw
3554 4229 */
@@ -3554,9 +4229,9 @@
3554 4229 */
3555 4230 function isRawAttribute(entity, attribute) {
3556 4231 return (entity.rawAttributes || []).includes(attribute);
3557 4232 }
3558 -//# sourceMappingURL=is-raw-attribute.js.map
4233 +
3559 4234 ;// CONCATENATED MODULE: ./packages/core-data/build-module/selectors.js
3560 4235 /**
3561 4236 * External dependencies
3562 4237 */
@@ -3576,8 +4251,9 @@
3576 4251
3577 4252
3578 4253
3579 4254
4255 +
3580 4256 /**
3581 4257 * Shared reference to an empty object for cases where it is important to avoid
3582 4258 * returning a new object reference on every invocation, as in a connected or
3583 4259 * other pure component which performs `shouldComponentUpdate` check on props.
@@ -3583,18 +4259,17 @@
3583 4259 * other pure component which performs `shouldComponentUpdate` check on props.
3584 4260 * This should be used as a last resort, since the normalized data should be
3585 4261 * maintained by the reducer result in state.
3586 4262 */
3587 -
3588 4263 const EMPTY_OBJECT = {};
3589 4264 /**
3590 4265 * Returns true if a request is in progress for embed preview data, or false
3591 4266 * otherwise.
3592 4267 *
3593 - * @param {Object} state Data state.
3594 - * @param {string} url URL the preview would be for.
4268 + * @param state Data state.
4269 + * @param url URL the preview would be for.
3595 4270 *
3596 - * @return {boolean} Whether a request is in progress for an embed preview.
4271 + * @return Whether a request is in progress for an embed preview.
3597 4272 */
3598 4273
3599 4274 const isRequestingEmbedPreview = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, url) => {
3600 4275 return select(STORE_NAME).isResolving('getEmbedPreview', [url]);
@@ -3603,12 +4278,12 @@
3603 4278 * Returns all available authors.
3604 4279 *
3605 4280 * @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
3606 4281 *
3607 - * @param {Object} state Data state.
3608 - * @param {Object|undefined} query Optional object of query parameters to
3609 - * include with request.
3610 - * @return {Array} Authors list.
4282 + * @param state Data state.
4283 + * @param query Optional object of query parameters to
4284 + * include with request.
4285 + * @return Authors list.
3611 4286 */
3612 4287
3613 4288 function getAuthors(state, query) {
3614 4289 external_wp_deprecated_default()("select( 'core' ).getAuthors()", {
@@ -3620,11 +4295,11 @@
3620 4295 }
3621 4296 /**
3622 4297 * Returns the current user.
3623 4298 *
3624 - * @param {Object} state Data state.
4299 + * @param state Data state.
3625 4300 *
3626 - * @return {Object} Current user object.
4301 + * @return Current user object.
3627 4302 */
3628 4303
3629 4304 function getCurrentUser(state) {
3630 4305 return state.currentUser;
@@ -3631,12 +4306,12 @@
3631 4306 }
3632 4307 /**
3633 4308 * Returns all the users returned by a query ID.
3634 4309 *
3635 - * @param {Object} state Data state.
3636 - * @param {string} queryID Query ID.
4310 + * @param state Data state.
4311 + * @param queryID Query ID.
3637 4312 *
3638 - * @return {Array} Users list.
4313 + * @return Users list.
3639 4314 */
3640 4315
3641 4316 const getUserQueryResults = rememo((state, queryID) => {
3642 4317 const queryResults = state.users.queries[queryID];
@@ -3642,32 +4317,67 @@
3642 4317 const queryResults = state.users.queries[queryID];
3643 4318 return (0,external_lodash_namespaceObject.map)(queryResults, id => state.users.byId[id]);
3644 4319 }, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
3645 4320 /**
3646 - * Returns whether the entities for the give kind are loaded.
4321 + * Returns the loaded entities for the given kind.
3647 4322 *
3648 - * @param {Object} state Data state.
3649 - * @param {string} kind Entity kind.
4323 + * @deprecated since WordPress 6.0. Use getEntitiesConfig instead
4324 + * @param state Data state.
4325 + * @param kind Entity kind.
3650 4326 *
3651 - * @return {Array<Object>} Array of entities with config matching kind.
4327 + * @return Array of entities with config matching kind.
3652 4328 */
3653 4329
3654 4330 function getEntitiesByKind(state, kind) {
4331 + external_wp_deprecated_default()("wp.data.select( 'core' ).getEntitiesByKind()", {
4332 + since: '6.0',
4333 + alternative: "wp.data.select( 'core' ).getEntitiesConfig()"
4334 + });
4335 + return getEntitiesConfig(state, kind);
4336 +}
4337 +/**
4338 + * Returns the loaded entities for the given kind.
4339 + *
4340 + * @param state Data state.
4341 + * @param kind Entity kind.
4342 + *
4343 + * @return Array of entities with config matching kind.
4344 + */
4345 +
4346 +function getEntitiesConfig(state, kind) {
3655 4347 return (0,external_lodash_namespaceObject.filter)(state.entities.config, {
3656 4348 kind
3657 4349 });
3658 4350 }
3659 4351 /**
3660 - * Returns the entity object given its kind and name.
4352 + * Returns the entity config given its kind and name.
3661 4353 *
3662 - * @param {Object} state Data state.
3663 - * @param {string} kind Entity kind.
3664 - * @param {string} name Entity name.
4354 + * @deprecated since WordPress 6.0. Use getEntityConfig instead
4355 + * @param state Data state.
4356 + * @param kind Entity kind.
4357 + * @param name Entity name.
3665 4358 *
3666 - * @return {Object} Entity
4359 + * @return Entity config
3667 4360 */
3668 4361
3669 4362 function getEntity(state, kind, name) {
4363 + external_wp_deprecated_default()("wp.data.select( 'core' ).getEntity()", {
4364 + since: '6.0',
4365 + alternative: "wp.data.select( 'core' ).getEntityConfig()"
4366 + });
4367 + return getEntityConfig(state, kind, name);
4368 +}
4369 +/**
4370 + * Returns the entity config given its kind and name.
4371 + *
4372 + * @param state Data state.
4373 + * @param kind Entity kind.
4374 + * @param name Entity name.
4375 + *
4376 + * @return Entity config
4377 + */
4378 +
4379 +function getEntityConfig(state, kind, name) {
3670 4380 return (0,external_lodash_namespaceObject.find)(state.entities.config, {
3671 4381 kind,
3672 4382 name
3673 4383 });
@@ -3672,25 +4382,50 @@
3672 4382 name
3673 4383 });
3674 4384 }
3675 4385 /**
4386 + * GetEntityRecord is declared as a *callable interface* with
4387 + * two signatures to work around the fact that TypeScript doesn't
4388 + * allow currying generic functions:
4389 + *
4390 + * ```ts
4391 + * type CurriedState = F extends ( state: any, ...args: infer P ) => infer R
4392 + * ? ( ...args: P ) => R
4393 + * : F;
4394 + * type Selector = <K extends string | number>(
4395 + * state: any,
4396 + * kind: K,
4397 + * key: K extends string ? 'string value' : false
4398 + * ) => K;
4399 + * type BadlyInferredSignature = CurriedState< Selector >
4400 + * // BadlyInferredSignature evaluates to:
4401 + * // (kind: string number, key: false | "string value") => string number
4402 + * ```
4403 + *
4404 + * The signature without the state parameter shipped as CurriedSignature
4405 + * is used in the return value of `select( coreStore )`.
4406 + *
4407 + * See https://github.com/WordPress/gutenberg/pull/41578 for more details.
4408 + */
4409 +
4410 +/**
3676 4411 * Returns the Entity's record object by key. Returns `null` if the value is not
3677 4412 * yet received, undefined if the value entity is known to not exist, or the
3678 4413 * entity object if it exists and is received.
3679 4414 *
3680 - * @param {Object} state State tree
3681 - * @param {string} kind Entity kind.
3682 - * @param {string} name Entity name.
3683 - * @param {number} key Record's key
3684 - * @param {?Object} query Optional query.
4415 + * @param state State tree
4416 + * @param kind Entity kind.
4417 + * @param name Entity name.
4418 + * @param key Record's key
4419 + * @param query Optional query. If requesting specific
4420 + * fields, fields must always include the ID.
3685 4421 *
3686 - * @return {Object?} Record.
4422 + * @return Record.
3687 4423 */
3688 -
3689 4424 const getEntityRecord = rememo((state, kind, name, key, query) => {
3690 4425 var _query$context, _queriedState$items$c;
3691 4426
3692 - const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData']);
4427 + const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData']);
3693 4428
3694 4429 if (!queriedState) {
3695 4430 return undefined;
3696 4431 }
@@ -3710,10 +4445,12 @@
3710 4445
3711 4446 const item = (_queriedState$items$c = queriedState.items[context]) === null || _queriedState$items$c === void 0 ? void 0 : _queriedState$items$c[key];
3712 4447
3713 4448 if (item && query._fields) {
4449 + var _getNormalizedCommaSe;
4450 +
3714 4451 const filteredItem = {};
3715 - const fields = get_normalized_comma_separable(query._fields);
4452 + const fields = (_getNormalizedCommaSe = get_normalized_comma_separable(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : [];
3716 4453
3717 4454 for (let f = 0; f < fields.length; f++) {
3718 4455 const field = fields[f].split('.');
3719 4456 const value = (0,external_lodash_namespaceObject.get)(item, field);
@@ -3727,19 +4464,19 @@
3727 4464 }, (state, kind, name, recordId, query) => {
3728 4465 var _query$context2;
3729 4466
3730 4467 const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
3731 - return [(0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
4468 + return [(0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
3732 4469 });
3733 4470 /**
3734 - * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state.
4471 + * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
3735 4472 *
3736 - * @param {Object} state State tree
3737 - * @param {string} kind Entity kind.
3738 - * @param {string} name Entity name.
3739 - * @param {number} key Record's key
4473 + * @param state State tree
4474 + * @param kind Entity kind.
4475 + * @param name Entity name.
4476 + * @param key Record's key
3740 4477 *
3741 - * @return {Object|null} Record.
4478 + * @return Record.
3742 4479 */
3743 4480
3744 4481 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
3745 4482 return getEntityRecord(state, kind, name, key);
@@ -3747,20 +4484,20 @@
3747 4484 /**
3748 4485 * Returns the entity's record object by key,
3749 4486 * with its attributes mapped to their raw values.
3750 4487 *
3751 - * @param {Object} state State tree.
3752 - * @param {string} kind Entity kind.
3753 - * @param {string} name Entity name.
3754 - * @param {number} key Record's key.
4488 + * @param state State tree.
4489 + * @param kind Entity kind.
4490 + * @param name Entity name.
4491 + * @param key Record's key.
3755 4492 *
3756 - * @return {Object?} Object with the entity's raw attributes.
4493 + * @return Object with the entity's raw attributes.
3757 4494 */
3758 4495
3759 4496 const getRawEntityRecord = rememo((state, kind, name, key) => {
3760 4497 const record = getEntityRecord(state, kind, name, key);
3761 4498 return record && Object.keys(record).reduce((accumulator, _key) => {
3762 - if (isRawAttribute(getEntity(state, kind, name), _key)) {
4499 + if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
3763 4500 // Because edits are the "raw" attribute values,
3764 4501 // we return those from record selectors to make rendering,
3765 4502 // comparisons, and joins with edits easier.
3766 4503 accumulator[_key] = (0,external_lodash_namespaceObject.get)(record[_key], 'raw', record[_key]);
@@ -3773,20 +4510,20 @@
3773 4510 }, (state, kind, name, recordId, query) => {
3774 4511 var _query$context3;
3775 4512
3776 4513 const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
3777 - return [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
4514 + return [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
3778 4515 });
3779 4516 /**
3780 4517 * Returns true if records have been received for the given set of parameters,
3781 4518 * or false otherwise.
3782 4519 *
3783 - * @param {Object} state State tree
3784 - * @param {string} kind Entity kind.
3785 - * @param {string} name Entity name.
3786 - * @param {?Object} query Optional terms query.
4520 + * @param state State tree
4521 + * @param kind Entity kind.
4522 + * @param name Entity name.
4523 + * @param query Optional terms query.
3787 4524 *
3788 - * @return {boolean} Whether entity records have been received.
4525 + * @return Whether entity records have been received.
3789 4526 */
3790 4527
3791 4528 function hasEntityRecords(state, kind, name, query) {
3792 4529 return Array.isArray(getEntityRecords(state, kind, name, query));
@@ -3791,22 +4528,31 @@
3791 4528 function hasEntityRecords(state, kind, name, query) {
3792 4529 return Array.isArray(getEntityRecords(state, kind, name, query));
3793 4530 }
3794 4531 /**
4532 + * GetEntityRecord is declared as a *callable interface* with
4533 + * two signatures to work around the fact that TypeScript doesn't
4534 + * allow currying generic functions.
4535 + *
4536 + * @see GetEntityRecord
4537 + * @see https://github.com/WordPress/gutenberg/pull/41578
4538 + */
4539 +
4540 +/**
3795 4541 * Returns the Entity's records.
3796 4542 *
3797 - * @param {Object} state State tree
3798 - * @param {string} kind Entity kind.
3799 - * @param {string} name Entity name.
3800 - * @param {?Object} query Optional terms query.
4543 + * @param state State tree
4544 + * @param kind Entity kind.
4545 + * @param name Entity name.
4546 + * @param query Optional terms query. If requesting specific
4547 + * fields, fields must always include the ID.
3801 4548 *
3802 - * @return {?Array} Records.
4549 + * @return Records.
3803 4550 */
3804 -
3805 -function getEntityRecords(state, kind, name, query) {
4551 +const getEntityRecords = (state, kind, name, query) => {
3806 4552 // Queried data state is prepopulated for all known entities. If this is not
3807 4553 // assigned for the given parameters, then it is known to not exist.
3808 - const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData']);
4554 + const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData']);
3809 4555
3810 4556 if (!queriedState) {
3811 4557 return null;
3812 4558 }
@@ -3811,41 +4557,41 @@
3811 4557 return null;
3812 4558 }
3813 4559
3814 4560 return getQueriedItems(queriedState, query);
3815 -}
4561 +};
4562 +
3816 4563 /**
3817 - * Returns the list of dirty entity records.
4564 + * Returns the list of dirty entity records.
3818 4565 *
3819 - * @param {Object} state State tree.
4566 + * @param state State tree.
3820 4567 *
3821 - * @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records
4568 + * @return The list of updated records
3822 4569 */
3823 -
3824 4570 const __experimentalGetDirtyEntityRecords = rememo(state => {
3825 4571 const {
3826 4572 entities: {
3827 - data
4573 + records
3828 4574 }
3829 4575 } = state;
3830 4576 const dirtyRecords = [];
3831 - Object.keys(data).forEach(kind => {
3832 - Object.keys(data[kind]).forEach(name => {
3833 - const primaryKeys = Object.keys(data[kind][name].edits).filter(primaryKey => // The entity record must exist (not be deleted),
4577 + Object.keys(records).forEach(kind => {
4578 + Object.keys(records[kind]).forEach(name => {
4579 + const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey => // The entity record must exist (not be deleted),
3834 4580 // and it must have edits.
3835 4581 getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey));
3836 4582
3837 4583 if (primaryKeys.length) {
3838 - const entity = getEntity(state, kind, name);
4584 + const entityConfig = getEntityConfig(state, kind, name);
3839 4585 primaryKeys.forEach(primaryKey => {
3840 - var _entity$getTitle;
4586 + var _entityConfig$getTitl;
3841 4587
3842 4588 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
3843 4589 dirtyRecords.push({
3844 4590 // We avoid using primaryKey because it's transformed into a string
3845 4591 // when it's used as an object key.
3846 - key: entityRecord[entity.key || DEFAULT_ENTITY_KEY],
3847 - title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle = entity.getTitle) === null || _entity$getTitle === void 0 ? void 0 : _entity$getTitle.call(entity, entityRecord)) || '',
4592 + key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : undefined,
4593 + title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl = entityConfig.getTitle) === null || _entityConfig$getTitl === void 0 ? void 0 : _entityConfig$getTitl.call(entityConfig, entityRecord)) || '',
3848 4594 name,
3849 4595 kind
3850 4596 });
3851 4597 });
@@ -3852,39 +4598,39 @@
3852 4598 }
3853 4599 });
3854 4600 });
3855 4601 return dirtyRecords;
3856 -}, state => [state.entities.data]);
4602 +}, state => [state.entities.records]);
3857 4603 /**
3858 4604 * Returns the list of entities currently being saved.
3859 4605 *
3860 - * @param {Object} state State tree.
4606 + * @param state State tree.
3861 4607 *
3862 - * @return {[{ title: string, key: string, name: string, kind: string }]} The list of records being saved.
4608 + * @return The list of records being saved.
3863 4609 */
3864 4610
3865 4611 const __experimentalGetEntitiesBeingSaved = rememo(state => {
3866 4612 const {
3867 4613 entities: {
3868 - data
4614 + records
3869 4615 }
3870 4616 } = state;
3871 4617 const recordsBeingSaved = [];
3872 - Object.keys(data).forEach(kind => {
3873 - Object.keys(data[kind]).forEach(name => {
3874 - const primaryKeys = Object.keys(data[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
4618 + Object.keys(records).forEach(kind => {
4619 + Object.keys(records[kind]).forEach(name => {
4620 + const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
3875 4621
3876 4622 if (primaryKeys.length) {
3877 - const entity = getEntity(state, kind, name);
4623 + const entityConfig = getEntityConfig(state, kind, name);
3878 4624 primaryKeys.forEach(primaryKey => {
3879 - var _entity$getTitle2;
4625 + var _entityConfig$getTitl2;
3880 4626
3881 4627 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
3882 4628 recordsBeingSaved.push({
3883 4629 // We avoid using primaryKey because it's transformed into a string
3884 4630 // when it's used as an object key.
3885 - key: entityRecord[entity.key || DEFAULT_ENTITY_KEY],
3886 - title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle2 = entity.getTitle) === null || _entity$getTitle2 === void 0 ? void 0 : _entity$getTitle2.call(entity, entityRecord)) || '',
4631 + key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : undefined,
4632 + title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl2 = entityConfig.getTitle) === null || _entityConfig$getTitl2 === void 0 ? void 0 : _entityConfig$getTitl2.call(entityConfig, entityRecord)) || '',
3887 4633 name,
3888 4634 kind
3889 4635 });
3890 4636 });
@@ -3891,22 +4637,22 @@
3891 4637 }
3892 4638 });
3893 4639 });
3894 4640 return recordsBeingSaved;
3895 -}, state => [state.entities.data]);
4641 +}, state => [state.entities.records]);
3896 4642 /**
3897 4643 * Returns the specified entity record's edits.
3898 4644 *
3899 - * @param {Object} state State tree.
3900 - * @param {string} kind Entity kind.
3901 - * @param {string} name Entity name.
3902 - * @param {number} recordId Record ID.
4645 + * @param state State tree.
4646 + * @param kind Entity kind.
4647 + * @param name Entity name.
4648 + * @param recordId Record ID.
3903 4649 *
3904 - * @return {Object?} The entity record's edits.
4650 + * @return The entity record's edits.
3905 4651 */
3906 4652
3907 4653 function getEntityRecordEdits(state, kind, name, recordId) {
3908 - return (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'edits', recordId]);
4654 + return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId]);
3909 4655 }
3910 4656 /**
3911 4657 * Returns the specified entity record's non transient edits.
3912 4658 *
@@ -3913,20 +4659,20 @@
3913 4659 * Transient edits don't create an undo level, and
3914 4660 * are not considered for change detection.
3915 4661 * They are defined in the entity's config.
3916 4662 *
3917 - * @param {Object} state State tree.
3918 - * @param {string} kind Entity kind.
3919 - * @param {string} name Entity name.
3920 - * @param {number} recordId Record ID.
4663 + * @param state State tree.
4664 + * @param kind Entity kind.
4665 + * @param name Entity name.
4666 + * @param recordId Record ID.
3921 4667 *
3922 - * @return {Object?} The entity record's non transient edits.
4668 + * @return The entity record's non transient edits.
3923 4669 */
3924 4670
3925 4671 const getEntityRecordNonTransientEdits = rememo((state, kind, name, recordId) => {
3926 4672 const {
3927 4673 transientEdits
3928 - } = getEntity(state, kind, name) || {};
4674 + } = getEntityConfig(state, kind, name) || {};
3929 4675 const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
3930 4676
3931 4677 if (!transientEdits) {
3932 4678 return edits;
@@ -3938,19 +4684,19 @@
3938 4684 }
3939 4685
3940 4686 return acc;
3941 4687 }, {});
3942 -}, (state, kind, name, recordId) => [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'edits', recordId])]);
4688 +}, (state, kind, name, recordId) => [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId])]);
3943 4689 /**
3944 4690 * Returns true if the specified entity record has edits,
3945 4691 * and false otherwise.
3946 4692 *
3947 - * @param {Object} state State tree.
3948 - * @param {string} kind Entity kind.
3949 - * @param {string} name Entity name.
3950 - * @param {number} recordId Record ID.
4693 + * @param state State tree.
4694 + * @param kind Entity kind.
4695 + * @param name Entity name.
4696 + * @param recordId Record ID.
3951 4697 *
3952 - * @return {boolean} Whether the entity record has edits or not.
4698 + * @return Whether the entity record has edits or not.
3953 4699 */
3954 4700
3955 4701 function hasEditsForEntityRecord(state, kind, name, recordId) {
3956 4702 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0;
@@ -3957,14 +4703,14 @@
3957 4703 }
3958 4704 /**
3959 4705 * Returns the specified entity record, merged with its edits.
3960 4706 *
3961 - * @param {Object} state State tree.
3962 - * @param {string} kind Entity kind.
3963 - * @param {string} name Entity name.
3964 - * @param {number} recordId Record ID.
4707 + * @param state State tree.
4708 + * @param kind Entity kind.
4709 + * @param name Entity name.
4710 + * @param recordId Record ID.
3965 4711 *
3966 - * @return {Object?} The entity record, merged with its edits.
4712 + * @return The entity record, merged with its edits.
3967 4713 */
3968 4714
3969 4715 const getEditedEntityRecord = rememo((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
3970 4716 ...getEntityRecordEdits(state, kind, name, recordId)
@@ -3971,19 +4717,19 @@
3971 4717 }), (state, kind, name, recordId, query) => {
3972 4718 var _query$context4;
3973 4719
3974 4720 const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
3975 - return [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'edits', recordId])];
4721 + return [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId])];
3976 4722 });
3977 4723 /**
3978 4724 * Returns true if the specified entity record is autosaving, and false otherwise.
3979 4725 *
3980 - * @param {Object} state State tree.
3981 - * @param {string} kind Entity kind.
3982 - * @param {string} name Entity name.
3983 - * @param {number} recordId Record ID.
4726 + * @param state State tree.
4727 + * @param kind Entity kind.
4728 + * @param name Entity name.
4729 + * @param recordId Record ID.
3984 4730 *
3985 - * @return {boolean} Whether the entity record is autosaving or not.
4731 + * @return Whether the entity record is autosaving or not.
3986 4732 */
3987 4733
3988 4734 function isAutosavingEntityRecord(state, kind, name, recordId) {
3989 4735 const {
@@ -3988,66 +4734,66 @@
3988 4734 function isAutosavingEntityRecord(state, kind, name, recordId) {
3989 4735 const {
3990 4736 pending,
3991 4737 isAutosave
3992 - } = (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'saving', recordId], {});
4738 + } = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId], {});
3993 4739 return Boolean(pending && isAutosave);
3994 4740 }
3995 4741 /**
3996 4742 * Returns true if the specified entity record is saving, and false otherwise.
3997 4743 *
3998 - * @param {Object} state State tree.
3999 - * @param {string} kind Entity kind.
4000 - * @param {string} name Entity name.
4001 - * @param {number} recordId Record ID.
4744 + * @param state State tree.
4745 + * @param kind Entity kind.
4746 + * @param name Entity name.
4747 + * @param recordId Record ID.
4002 4748 *
4003 - * @return {boolean} Whether the entity record is saving or not.
4749 + * @return Whether the entity record is saving or not.
4004 4750 */
4005 4751
4006 4752 function isSavingEntityRecord(state, kind, name, recordId) {
4007 - return (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'saving', recordId, 'pending'], false);
4753 + return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId, 'pending'], false);
4008 4754 }
4009 4755 /**
4010 4756 * Returns true if the specified entity record is deleting, and false otherwise.
4011 4757 *
4012 - * @param {Object} state State tree.
4013 - * @param {string} kind Entity kind.
4014 - * @param {string} name Entity name.
4015 - * @param {number} recordId Record ID.
4758 + * @param state State tree.
4759 + * @param kind Entity kind.
4760 + * @param name Entity name.
4761 + * @param recordId Record ID.
4016 4762 *
4017 - * @return {boolean} Whether the entity record is deleting or not.
4763 + * @return Whether the entity record is deleting or not.
4018 4764 */
4019 4765
4020 4766 function isDeletingEntityRecord(state, kind, name, recordId) {
4021 - return (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'deleting', recordId, 'pending'], false);
4767 + return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'deleting', recordId, 'pending'], false);
4022 4768 }
4023 4769 /**
4024 4770 * Returns the specified entity record's last save error.
4025 4771 *
4026 - * @param {Object} state State tree.
4027 - * @param {string} kind Entity kind.
4028 - * @param {string} name Entity name.
4029 - * @param {number} recordId Record ID.
4772 + * @param state State tree.
4773 + * @param kind Entity kind.
4774 + * @param name Entity name.
4775 + * @param recordId Record ID.
4030 4776 *
4031 - * @return {Object?} The entity record's save error.
4777 + * @return The entity record's save error.
4032 4778 */
4033 4779
4034 4780 function getLastEntitySaveError(state, kind, name, recordId) {
4035 - return (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'saving', recordId, 'error']);
4781 + return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId, 'error']);
4036 4782 }
4037 4783 /**
4038 4784 * Returns the specified entity record's last delete error.
4039 4785 *
4040 - * @param {Object} state State tree.
4041 - * @param {string} kind Entity kind.
4042 - * @param {string} name Entity name.
4043 - * @param {number} recordId Record ID.
4786 + * @param state State tree.
4787 + * @param kind Entity kind.
4788 + * @param name Entity name.
4789 + * @param recordId Record ID.
4044 4790 *
4045 - * @return {Object?} The entity record's save error.
4791 + * @return The entity record's save error.
4046 4792 */
4047 4793
4048 4794 function getLastEntityDeleteError(state, kind, name, recordId) {
4049 - return (0,external_lodash_namespaceObject.get)(state.entities.data, [kind, name, 'deleting', recordId, 'error']);
4795 + return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'deleting', recordId, 'error']);
4050 4796 }
4051 4797 /**
4052 4798 * Returns the current undo offset for the
4053 4799 * entity records edits history. The offset
@@ -4054,11 +4800,11 @@
4054 4800 * represents how many items from the end
4055 4801 * of the history stack we are at. 0 is the
4056 4802 * last edit, -1 is the second last, and so on.
4057 4803 *
4058 - * @param {Object} state State tree.
4804 + * @param state State tree.
4059 4805 *
4060 - * @return {number} The current undo offset.
4806 + * @return The current undo offset.
4061 4807 */
4062 4808
4063 4809 function getCurrentUndoOffset(state) {
4064 4810 return state.undo.offset;
@@ -4066,11 +4812,11 @@
4066 4812 /**
4067 4813 * Returns the previous edit from the current undo offset
4068 4814 * for the entity records edits history, if any.
4069 4815 *
4070 - * @param {Object} state State tree.
4816 + * @param state State tree.
4071 4817 *
4072 - * @return {Object?} The edit.
4818 + * @return The edit.
4073 4819 */
4074 4820
4075 4821
4076 4822 function getUndoEdit(state) {
@@ -4079,11 +4825,11 @@
4079 4825 /**
4080 4826 * Returns the next edit from the current undo offset
4081 4827 * for the entity records edits history, if any.
4082 4828 *
4083 - * @param {Object} state State tree.
4829 + * @param state State tree.
4084 4830 *
4085 - * @return {Object?} The edit.
4831 + * @return The edit.
4086 4832 */
4087 4833
4088 4834 function getRedoEdit(state) {
4089 4835 return state.undo[state.undo.length + getCurrentUndoOffset(state)];
@@ -4091,11 +4837,11 @@
4091 4837 /**
4092 4838 * Returns true if there is a previous edit from the current undo offset
4093 4839 * for the entity records edits history, and false otherwise.
4094 4840 *
4095 - * @param {Object} state State tree.
4841 + * @param state State tree.
4096 4842 *
4097 - * @return {boolean} Whether there is a previous edit or not.
4843 + * @return Whether there is a previous edit or not.
4098 4844 */
4099 4845
4100 4846 function hasUndo(state) {
4101 4847 return Boolean(getUndoEdit(state));
@@ -4103,11 +4849,11 @@
4103 4849 /**
4104 4850 * Returns true if there is a next edit from the current undo offset
4105 4851 * for the entity records edits history, and false otherwise.
4106 4852 *
4107 - * @param {Object} state State tree.
4853 + * @param state State tree.
4108 4854 *
4109 - * @return {boolean} Whether there is a next edit or not.
4855 + * @return Whether there is a next edit or not.
4110 4856 */
4111 4857
4112 4858 function hasRedo(state) {
4113 4859 return Boolean(getRedoEdit(state));
@@ -4114,11 +4860,11 @@
4114 4860 }
4115 4861 /**
4116 4862 * Return the current theme.
4117 4863 *
4118 - * @param {Object} state Data state.
4864 + * @param state Data state.
4119 4865 *
4120 - * @return {Object} The current theme.
4866 + * @return The current theme.
4121 4867 */
4122 4868
4123 4869 function getCurrentTheme(state) {
4124 4870 return getEntityRecord(state, 'root', 'theme', state.currentTheme);
@@ -4125,11 +4871,11 @@
4125 4871 }
4126 4872 /**
4127 4873 * Return the ID of the current global styles object.
4128 4874 *
4129 - * @param {Object} state Data state.
4875 + * @param state Data state.
4130 4876 *
4131 - * @return {string} The current global styles ID.
4877 + * @return The current global styles ID.
4132 4878 */
4133 4879
4134 4880 function __experimentalGetCurrentGlobalStylesId(state) {
4135 4881 return state.currentGlobalStylesId;
@@ -4136,11 +4882,11 @@
4136 4882 }
4137 4883 /**
4138 4884 * Return theme supports data in the index.
4139 4885 *
4140 - * @param {Object} state Data state.
4886 + * @param state Data state.
4141 4887 *
4142 - * @return {*} Index data.
4888 + * @return Index data.
4143 4889 */
4144 4890
4145 4891 function getThemeSupports(state) {
4146 4892 var _getCurrentTheme$them, _getCurrentTheme;
@@ -4149,12 +4895,12 @@
4149 4895 }
4150 4896 /**
4151 4897 * Returns the embed preview for the given URL.
4152 4898 *
4153 - * @param {Object} state Data state.
4154 - * @param {string} url Embedded URL.
4899 + * @param state Data state.
4900 + * @param url Embedded URL.
4155 4901 *
4156 - * @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
4902 + * @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
4157 4903 */
4158 4904
4159 4905 function getEmbedPreview(state, url) {
4160 4906 return state.embedPreviews[url];
@@ -4165,12 +4911,12 @@
4165 4911 * WordPress can be configured to return a simple link to a URL if it is not embeddable.
4166 4912 * We need to be able to determine if a URL is embeddable or not, based on what we
4167 4913 * get back from the oEmbed preview API.
4168 4914 *
4169 - * @param {Object} state Data state.
4170 - * @param {string} url Embedded URL.
4915 + * @param state Data state.
4916 + * @param url Embedded URL.
4171 4917 *
4172 - * @return {boolean} Is the preview for the URL an oEmbed link fallback.
4918 + * @return Is the preview for the URL an oEmbed link fallback.
4173 4919 */
4174 4920
4175 4921 function isPreviewEmbedFallback(state, url) {
4176 4922 const preview = state.embedPreviews[url];
@@ -4190,19 +4936,19 @@
4190 4936 * `canUser()` resolver.
4191 4937 *
4192 4938 * https://developer.wordpress.org/rest-api/reference/
4193 4939 *
4194 - * @param {Object} state Data state.
4195 - * @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'.
4196 - * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
4197 - * @param {string=} id Optional ID of the rest resource to check.
4940 + * @param state Data state.
4941 + * @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
4942 + * @param resource REST resource to check, e.g. 'media' or 'posts'.
4943 + * @param id Optional ID of the rest resource to check.
4198 4944 *
4199 - * @return {boolean|undefined} Whether or not the user can perform the action,
4945 + * @return Whether or not the user can perform the action,
4200 4946 * or `undefined` if the OPTIONS request is still being made.
4201 4947 */
4202 4948
4203 4949 function canUser(state, action, resource, id) {
4204 - const key = (0,external_lodash_namespaceObject.compact)([action, resource, id]).join('/');
4950 + const key = [action, resource, id].filter(Boolean).join('/');
4205 4951 return (0,external_lodash_namespaceObject.get)(state, ['userPermissions', key]);
4206 4952 }
4207 4953 /**
4208 4954 * Returns whether the current user can edit the given entity.
@@ -4211,24 +4957,24 @@
4211 4957 * `canUser()` resolver.
4212 4958 *
4213 4959 * https://developer.wordpress.org/rest-api/reference/
4214 4960 *
4215 - * @param {Object} state Data state.
4216 - * @param {string} kind Entity kind.
4217 - * @param {string} name Entity name.
4218 - * @param {string} recordId Record's id.
4219 - * @return {boolean|undefined} Whether or not the user can edit,
4961 + * @param state Data state.
4962 + * @param kind Entity kind.
4963 + * @param name Entity name.
4964 + * @param recordId Record's id.
4965 + * @return Whether or not the user can edit,
4220 4966 * or `undefined` if the OPTIONS request is still being made.
4221 4967 */
4222 4968
4223 4969 function canUserEditEntityRecord(state, kind, name, recordId) {
4224 - const entity = getEntity(state, kind, name);
4970 + const entityConfig = getEntityConfig(state, kind, name);
4225 4971
4226 - if (!entity) {
4972 + if (!entityConfig) {
4227 4973 return false;
4228 4974 }
4229 4975
4230 - const resource = entity.__unstable_rest_base;
4976 + const resource = entityConfig.__unstable_rest_base;
4231 4977 return canUser(state, 'update', resource, recordId);
4232 4978 }
4233 4979 /**
4234 4980 * Returns the latest autosaves for the post.
@@ -4235,13 +4981,13 @@
4235 4981 *
4236 4982 * May return multiple autosaves since the backend stores one autosave per
4237 4983 * author for each post.
4238 4984 *
4239 - * @param {Object} state State tree.
4240 - * @param {string} postType The type of the parent post.
4241 - * @param {number} postId The id of the parent post.
4985 + * @param state State tree.
4986 + * @param postType The type of the parent post.
4987 + * @param postId The id of the parent post.
4242 4988 *
4243 - * @return {?Array} An array of autosaves for the post, or undefined if there is none.
4989 + * @return An array of autosaves for the post, or undefined if there is none.
4244 4990 */
4245 4991
4246 4992 function getAutosaves(state, postType, postId) {
4247 4993 return state.autosaves[postId];
@@ -4248,14 +4994,14 @@
4248 4994 }
4249 4995 /**
4250 4996 * Returns the autosave for the post and author.
4251 4997 *
4252 - * @param {Object} state State tree.
4253 - * @param {string} postType The type of the parent post.
4254 - * @param {number} postId The id of the parent post.
4255 - * @param {number} authorId The id of the author.
4998 + * @param state State tree.
4999 + * @param postType The type of the parent post.
5000 + * @param postId The id of the parent post.
5001 + * @param authorId The id of the author.
4256 5002 *
4257 - * @return {?Object} The autosave for the post and author.
5003 + * @return The autosave for the post and author.
4258 5004 */
4259 5005
4260 5006 function getAutosave(state, postType, postId, authorId) {
4261 5007 if (authorId === undefined) {
@@ -4269,13 +5015,13 @@
4269 5015 }
4270 5016 /**
4271 5017 * Returns true if the REST request for autosaves has completed.
4272 5018 *
4273 - * @param {Object} state State tree.
4274 - * @param {string} postType The type of the parent post.
4275 - * @param {number} postId The id of the parent post.
5019 + * @param state State tree.
5020 + * @param postType The type of the parent post.
5021 + * @param postId The id of the parent post.
4276 5022 *
4277 - * @return {boolean} True if the REST request was completed. False otherwise.
5023 + * @return True if the REST request was completed. False otherwise.
4278 5024 */
4279 5025
4280 5026 const hasFetchedAutosaves = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, postType, postId) => {
4281 5027 return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]);
@@ -4293,21 +5039,22 @@
4293 5039 * getReferenceByDistinctEdits( afterState )
4294 5040 * );
4295 5041 * ```
4296 5042 *
4297 - * @param {Object} state Editor state.
5043 + * @param state Editor state.
4298 5044 *
4299 - * @return {*} A value whose reference will change only when an edit occurs.
5045 + * @return A value whose reference will change only when an edit occurs.
4300 5046 */
4301 5047
4302 -const getReferenceByDistinctEdits = rememo(() => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]);
5048 +const getReferenceByDistinctEdits = rememo( // This unused state argument is listed here for the documentation generating tool (docgen).
5049 +state => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]);
4303 5050 /**
4304 5051 * Retrieve the frontend template used for a given link.
4305 5052 *
4306 - * @param {Object} state Editor state.
4307 - * @param {string} link Link.
5053 + * @param state Editor state.
5054 + * @param link Link.
4308 5055 *
4309 - * @return {Object?} The template record.
5056 + * @return The template record.
4310 5057 */
4311 5058
4312 5059 function __experimentalGetTemplateForLink(state, link) {
4313 5060 const records = getEntityRecords(state, 'postType', 'wp_template', {
@@ -4312,22 +5059,21 @@
4312 5059 function __experimentalGetTemplateForLink(state, link) {
4313 5060 const records = getEntityRecords(state, 'postType', 'wp_template', {
4314 5061 'find-template': link
4315 5062 });
4316 - const template = records !== null && records !== void 0 && records.length ? records[0] : null;
4317 5063
4318 - if (template) {
4319 - return getEditedEntityRecord(state, 'postType', 'wp_template', template.id);
5064 + if (records !== null && records !== void 0 && records.length) {
5065 + return getEditedEntityRecord(state, 'postType', 'wp_template', records[0].id);
4320 5066 }
4321 5067
4322 - return template;
5068 + return null;
4323 5069 }
4324 5070 /**
4325 5071 * Retrieve the current theme's base global styles
4326 5072 *
4327 - * @param {Object} state Editor state.
5073 + * @param state Editor state.
4328 5074 *
4329 - * @return {Object?} The Global Styles object.
5075 + * @return The Global Styles object.
4330 5076 */
4331 5077
4332 5078 function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
4333 5079 const currentTheme = getCurrentTheme(state);
@@ -4340,11 +5086,11 @@
4340 5086 }
4341 5087 /**
4342 5088 * Return the ID of the current global styles object.
4343 5089 *
4344 - * @param {Object} state Data state.
5090 + * @param state Data state.
4345 5091 *
4346 - * @return {string} The current global styles ID.
5092 + * @return The current global styles ID.
4347 5093 */
4348 5094
4349 5095 function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
4350 5096 const currentTheme = getCurrentTheme(state);
@@ -4354,9 +5100,49 @@
4354 5100 }
4355 5101
4356 5102 return state.themeGlobalStyleVariations[currentTheme.stylesheet];
4357 5103 }
4358 -//# sourceMappingURL=selectors.js.map
5104 +/**
5105 + * Retrieve the list of registered block patterns.
5106 + *
5107 + * @param state Data state.
5108 + *
5109 + * @return Block pattern list.
5110 + */
5111 +
5112 +function getBlockPatterns(state) {
5113 + return state.blockPatterns;
5114 +}
5115 +/**
5116 + * Retrieve the list of registered block pattern categories.
5117 + *
5118 + * @param state Data state.
5119 + *
5120 + * @return Block pattern category list.
5121 + */
5122 +
5123 +function getBlockPatternCategories(state) {
5124 + return state.blockPatternCategories;
5125 +}
5126 +
5127 +;// CONCATENATED MODULE: ./node_modules/camel-case/dist.es2015/index.js
5128 +
5129 +
5130 +function camelCaseTransform(input, index) {
5131 + if (index === 0)
5132 + return input.toLowerCase();
5133 + return pascalCaseTransform(input, index);
5134 +}
5135 +function camelCaseTransformMerge(input, index) {
5136 + if (index === 0)
5137 + return input.toLowerCase();
5138 + return pascalCaseTransformMerge(input);
5139 +}
5140 +function camelCase(input, options) {
5141 + if (options === void 0) { options = {}; }
5142 + return pascalCase(input, __assign({ transform: camelCaseTransform }, options));
5143 +}
5144 +
4359 5145 ;// CONCATENATED MODULE: ./packages/core-data/build-module/utils/forward-resolver.js
4360 5146 /**
4361 5147 * Higher-order function which forward the resolution to another resolver with the same arguments.
4362 5148 *
@@ -4376,10 +5162,10 @@
4376 5162 await resolveSelect[resolverName](...args);
4377 5163 };
4378 5164 };
4379 5165
4380 -/* harmony default export */ var forward_resolver = (forwardResolver);
4381 -//# sourceMappingURL=forward-resolver.js.map
5166 +/* harmony default export */ const forward_resolver = (forwardResolver);
5167 +
4382 5168 ;// CONCATENATED MODULE: ./packages/core-data/build-module/resolvers.js
4383 5169 /**
4384 5170 * External dependencies
4385 5171 */
@@ -4433,9 +5219,10 @@
4433 5219 * @param {string} kind Entity kind.
4434 5220 * @param {string} name Entity name.
4435 5221 * @param {number|string} key Record's key
4436 5222 * @param {Object|undefined} query Optional object of query parameters to
4437 - * include with request.
5223 + * include with request. If requesting specific
5224 + * fields, fields must always include the ID.
4438 5225 */
4439 5226
4440 5227 const resolvers_getEntityRecord = function (kind, name) {
4441 5228 let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
@@ -4444,19 +5231,16 @@
4444 5231 let {
4445 5232 select,
4446 5233 dispatch
4447 5234 } = _ref3;
4448 - const entities = await dispatch(getKindEntities(kind));
4449 - const entity = (0,external_lodash_namespaceObject.find)(entities, {
4450 - kind,
4451 - name
4452 - });
5235 + const configs = await dispatch(getOrLoadEntitiesConfig(kind));
5236 + const entityConfig = configs.find(config => config.name === name && config.kind === kind);
4453 5237
4454 - if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
5238 + if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
4455 5239 return;
4456 5240 }
4457 5241
4458 - const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, key], {
5242 + const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], {
4459 5243 exclusive: false
4460 5244 });
4461 5245
4462 5246 try {
@@ -4464,9 +5248,9 @@
4464 5248 // If requesting specific fields, items and query association to said
4465 5249 // records are stored by ID reference. Thus, fields must always include
4466 5250 // the ID.
4467 5251 query = { ...query,
4468 - _fields: (0,external_lodash_namespaceObject.uniq)([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
5252 + _fields: [...new Set([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
4469 5253 };
4470 5254 } // Disable reason: While true that an early return could leave `path`
4471 5255 // unused, it's important that path is derived using the query prior to
4472 5256 // additional query modifications in the condition below, since those
@@ -4474,9 +5258,9 @@
4474 5258 // for how the request is made to the REST API.
4475 5259 // eslint-disable-next-line @wordpress/no-unused-vars-before-return
4476 5260
4477 5261
4478 - const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
5262 + const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
4479 5263 ...query
4480 5264 });
4481 5265
4482 5266 if (query !== undefined) {
@@ -4496,11 +5280,8 @@
4496 5280 const record = await external_wp_apiFetch_default()({
4497 5281 path
4498 5282 });
4499 5283 dispatch.receiveEntityRecords(kind, name, record, query);
4500 - } catch (error) {// We need a way to handle and access REST API errors in state
4501 - // Until then, catching the error ensures the resolver is marked as resolved.
4502 - // See similar implementation in `getEntityRecords()`.
4503 5284 } finally {
4504 5285 dispatch.__unstableReleaseStoreLock(lock);
4505 5286 }
4506 5287 };
@@ -4519,9 +5300,10 @@
4519 5300 * Requests the entity's records from the REST API.
4520 5301 *
4521 5302 * @param {string} kind Entity kind.
4522 5303 * @param {string} name Entity name.
4523 - * @param {Object?} query Query Object.
5304 + * @param {Object?} query Query Object. If requesting specific fields, fields
5305 + * must always include the ID.
4524 5306 */
4525 5307
4526 5308 const resolvers_getEntityRecords = function (kind, name) {
4527 5309 let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -4528,19 +5310,16 @@
4528 5310 return async _ref4 => {
4529 5311 let {
4530 5312 dispatch
4531 5313 } = _ref4;
4532 - const entities = await dispatch(getKindEntities(kind));
4533 - const entity = (0,external_lodash_namespaceObject.find)(entities, {
4534 - kind,
4535 - name
4536 - });
5314 + const configs = await dispatch(getOrLoadEntitiesConfig(kind));
5315 + const entityConfig = configs.find(config => config.name === name && config.kind === kind);
4537 5316
4538 - if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
5317 + if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
4539 5318 return;
4540 5319 }
4541 5320
4542 - const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
5321 + const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
4543 5322 exclusive: false
4544 5323 });
4545 5324
4546 5325 try {
@@ -4550,13 +5329,13 @@
4550 5329 // If requesting specific fields, items and query association to said
4551 5330 // records are stored by ID reference. Thus, fields must always include
4552 5331 // the ID.
4553 5332 query = { ...query,
4554 - _fields: (0,external_lodash_namespaceObject.uniq)([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
5333 + _fields: [...new Set([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
4555 5334 };
4556 5335 }
4557 5336
4558 - const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entity.baseURL, { ...entity.baseURLParams,
5337 + const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL, { ...entityConfig.baseURLParams,
4559 5338 ...query
4560 5339 });
4561 5340 let records = Object.values(await external_wp_apiFetch_default()({
4562 5341 path
@@ -4580,9 +5359,9 @@
4580 5359 // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
4581 5360 // See https://github.com/WordPress/gutenberg/pull/26575
4582 5361
4583 5362 if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
4584 - const key = entity.key || DEFAULT_ENTITY_KEY;
5363 + const key = entityConfig.key || DEFAULT_ENTITY_KEY;
4585 5364 const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
4586 5365 dispatch({
4587 5366 type: 'START_RESOLUTIONS',
4588 5367 selectorName: 'getEntityRecord',
@@ -4593,11 +5372,8 @@
4593 5372 selectorName: 'getEntityRecord',
4594 5373 args: resolutionsArgs
4595 5374 });
4596 5375 }
4597 - } catch (error) {// We need a way to handle and access REST API errors in state
4598 - // Until then, catching the error ensures the resolver is marked as resolved.
4599 - // See similar implementation in `getEntityRecord()`.
4600 5376 } finally {
4601 5377 dispatch.__unstableReleaseStoreLock(lock);
4602 5378 }
4603 5379 };
@@ -4652,41 +5428,50 @@
4652 5428 /**
4653 5429 * Checks whether the current user can perform the given action on the given
4654 5430 * REST resource.
4655 5431 *
4656 - * @param {string} action Action to check. One of: 'create', 'read', 'update',
4657 - * 'delete'.
4658 - * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
4659 - * @param {?string} id ID of the rest resource to check.
5432 + * @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',
5433 + * 'delete'.
5434 + * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
5435 + * @param {?string} id ID of the rest resource to check.
4660 5436 */
4661 5437
4662 -const resolvers_canUser = (action, resource, id) => async _ref7 => {
5438 +const resolvers_canUser = (requestedAction, resource, id) => async _ref7 => {
5439 + var _response$headers;
5440 +
4663 5441 let {
4664 - dispatch
5442 + dispatch,
5443 + registry
4665 5444 } = _ref7;
4666 - const methods = {
4667 - create: 'POST',
4668 - read: 'GET',
4669 - update: 'PUT',
4670 - delete: 'DELETE'
4671 - };
4672 - const method = methods[action];
5445 + const {
5446 + hasStartedResolution
5447 + } = registry.select(STORE_NAME);
5448 + const resourcePath = id ? `${resource}/${id}` : resource;
5449 + const retrievedActions = ['create', 'read', 'update', 'delete'];
4673 5450
4674 - if (!method) {
4675 - throw new Error(`'${action}' is not a valid action.`);
5451 + if (!retrievedActions.includes(requestedAction)) {
5452 + throw new Error(`'${requestedAction}' is not a valid action.`);
5453 + } // Prevent resolving the same resource twice.
5454 +
5455 +
5456 + for (const relatedAction of retrievedActions) {
5457 + if (relatedAction === requestedAction) {
5458 + continue;
5459 + }
5460 +
5461 + const isAlreadyResolving = hasStartedResolution('canUser', [relatedAction, resource, id]);
5462 +
5463 + if (isAlreadyResolving) {
5464 + return;
5465 + }
4676 5466 }
4677 5467
4678 - const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`;
4679 5468 let response;
4680 5469
4681 5470 try {
4682 5471 response = await external_wp_apiFetch_default()({
4683 - path,
4684 - // Ideally this would always be an OPTIONS request, but unfortunately there's
4685 - // a bug in the REST API which causes the Allow header to not be sent on
4686 - // OPTIONS requests to /posts/:id routes.
4687 - // https://core.trac.wordpress.org/ticket/45753
4688 - method: id ? 'GET' : 'OPTIONS',
5472 + path: `/wp/v2/${resourcePath}`,
5473 + method: 'OPTIONS',
4689 5474 parse: false
4690 5475 });
4691 5476 } catch (error) {
4692 5477 // Do nothing if our OPTIONS request comes back with an API error (4xx or
@@ -4691,25 +5476,30 @@
4691 5476 } catch (error) {
4692 5477 // Do nothing if our OPTIONS request comes back with an API error (4xx or
4693 5478 // 5xx). The previously determined isAllowed value will remain in the store.
4694 5479 return;
4695 - }
5480 + } // Optional chaining operator is used here because the API requests don't
5481 + // return the expected result in the native version. Instead, API requests
5482 + // only return the result, without including response properties like the headers.
4696 5483
4697 - let allowHeader;
4698 5484
4699 - if ((0,external_lodash_namespaceObject.hasIn)(response, ['headers', 'get'])) {
4700 - // If the request is fetched using the fetch api, the header can be
4701 - // retrieved using the 'get' method.
4702 - allowHeader = response.headers.get('allow');
4703 - } else {
4704 - // If the request was preloaded server-side and is returned by the
4705 - // preloading middleware, the header will be a simple property.
4706 - allowHeader = (0,external_lodash_namespaceObject.get)(response, ['headers', 'Allow'], '');
5485 + const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow');
5486 + const allowedMethods = (allowHeader === null || allowHeader === void 0 ? void 0 : allowHeader.allow) || allowHeader || '';
5487 + const permissions = {};
5488 + const methods = {
5489 + create: 'POST',
5490 + read: 'GET',
5491 + update: 'PUT',
5492 + delete: 'DELETE'
5493 + };
5494 +
5495 + for (const [actionName, methodName] of Object.entries(methods)) {
5496 + permissions[actionName] = allowedMethods.includes(methodName);
4707 5497 }
4708 5498
4709 - const key = (0,external_lodash_namespaceObject.compact)([action, resource, id]).join('/');
4710 - const isAllowed = (0,external_lodash_namespaceObject.includes)(allowHeader, method);
4711 - dispatch.receiveUserPermission(key, isAllowed);
5499 + for (const action of retrievedActions) {
5500 + dispatch.receiveUserPermission(`${action}/${resourcePath}`, permissions[action]);
5501 + }
4712 5502 };
4713 5503 /**
4714 5504 * Checks whether the current user can perform the given action on the given
4715 5505 * REST resource.
@@ -4722,19 +5512,16 @@
4722 5512 const resolvers_canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
4723 5513 let {
4724 5514 dispatch
4725 5515 } = _ref8;
4726 - const entities = await dispatch(getKindEntities(kind));
4727 - const entity = (0,external_lodash_namespaceObject.find)(entities, {
4728 - kind,
4729 - name
4730 - });
5516 + const configs = await dispatch(getOrLoadEntitiesConfig(kind));
5517 + const entityConfig = configs.find(config => config.name === name && config.kind === kind);
4731 5518
4732 - if (!entity) {
5519 + if (!entityConfig) {
4733 5520 return;
4734 5521 }
4735 5522
4736 - const resource = entity.__unstable_rest_base;
5523 + const resource = entityConfig.__unstable_rest_base;
4737 5524 await dispatch(resolvers_canUser('update', resource, recordId));
4738 5525 };
4739 5526 /**
4740 5527 * Request autosave data from the REST API.
@@ -4748,12 +5535,13 @@
4748 5535 dispatch,
4749 5536 resolveSelect
4750 5537 } = _ref9;
4751 5538 const {
4752 - rest_base: restBase
5539 + rest_base: restBase,
5540 + rest_namespace: restNamespace = 'wp/v2'
4753 5541 } = await resolveSelect.getPostType(postType);
4754 5542 const autosaves = await external_wp_apiFetch_default()({
4755 - path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit`
5543 + path: `/${restNamespace}/${restBase}/${postId}/autosaves?context=edit`
4756 5544 });
4757 5545
4758 5546 if (autosaves && autosaves.length) {
4759 5547 dispatch.receiveAutosaves(postId, autosaves);
@@ -4820,8 +5608,10 @@
4820 5608 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
4821 5609 };
4822 5610
4823 5611 const resolvers_experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
5612 + var _activeThemes$, _activeThemes$$_links, _activeThemes$$_links2, _activeThemes$$_links3;
5613 +
4824 5614 let {
4825 5615 dispatch,
4826 5616 resolveSelect
4827 5617 } = _ref13;
@@ -4827,9 +5617,9 @@
4827 5617 } = _ref13;
4828 5618 const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
4829 5619 status: 'active'
4830 5620 });
4831 - const globalStylesURL = (0,external_lodash_namespaceObject.get)(activeThemes, [0, '_links', 'wp:user-global-styles', 0, 'href']);
5621 + const globalStylesURL = activeThemes === null || activeThemes === void 0 ? void 0 : (_activeThemes$ = activeThemes[0]) === null || _activeThemes$ === void 0 ? void 0 : (_activeThemes$$_links = _activeThemes$._links) === null || _activeThemes$$_links === void 0 ? void 0 : (_activeThemes$$_links2 = _activeThemes$$_links['wp:user-global-styles']) === null || _activeThemes$$_links2 === void 0 ? void 0 : (_activeThemes$$_links3 = _activeThemes$$_links2[0]) === null || _activeThemes$$_links3 === void 0 ? void 0 : _activeThemes$$_links3.href;
4832 5622
4833 5623 if (globalStylesURL) {
4834 5624 const globalStylesObject = await external_wp_apiFetch_default()({
4835 5625 url: globalStylesURL
@@ -4861,9 +5651,37 @@
4861 5651 });
4862 5652
4863 5653 dispatch.__experimentalReceiveThemeGlobalStyleVariations(currentTheme.stylesheet, variations);
4864 5654 };
4865 -//# sourceMappingURL=resolvers.js.map
5655 +const resolvers_getBlockPatterns = () => async _ref16 => {
5656 + let {
5657 + dispatch
5658 + } = _ref16;
5659 + const restPatterns = await external_wp_apiFetch_default()({
5660 + path: '/wp/v2/block-patterns/patterns'
5661 + });
5662 + const patterns = restPatterns === null || restPatterns === void 0 ? void 0 : restPatterns.map(pattern => Object.fromEntries(Object.entries(pattern).map(_ref17 => {
5663 + let [key, value] = _ref17;
5664 + return [camelCase(key), value];
5665 + })));
5666 + dispatch({
5667 + type: 'RECEIVE_BLOCK_PATTERNS',
5668 + patterns
5669 + });
5670 +};
5671 +const resolvers_getBlockPatternCategories = () => async _ref18 => {
5672 + let {
5673 + dispatch
5674 + } = _ref18;
5675 + const categories = await external_wp_apiFetch_default()({
5676 + path: '/wp/v2/block-patterns/categories'
5677 + });
5678 + dispatch({
5679 + type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES',
5680 + categories
5681 + });
5682 +};
5683 +
4866 5684 ;// CONCATENATED MODULE: ./packages/core-data/build-module/locks/utils.js
4867 5685 function deepCopyLocksTreePath(tree, path) {
4868 5686 const newTree = { ...tree
4869 5687 };
@@ -4935,9 +5753,9 @@
4935 5753 }
4936 5754
4937 5755 return false;
4938 5756 }
4939 -//# sourceMappingURL=utils.js.map
5757 +
4940 5758 ;// CONCATENATED MODULE: ./packages/core-data/build-module/locks/reducer.js
4941 5759 /**
4942 5760 * Internal dependencies
4943 5761 */
@@ -5009,9 +5827,9 @@
5009 5827 }
5010 5828
5011 5829 return state;
5012 5830 }
5013 -//# sourceMappingURL=reducer.js.map
5831 +
5014 5832 ;// CONCATENATED MODULE: ./packages/core-data/build-module/locks/selectors.js
5015 5833 /**
5016 5834 * Internal dependencies
5017 5835 */
@@ -5052,9 +5870,9 @@
5052 5870 }
5053 5871
5054 5872 return true;
5055 5873 }
5056 -//# sourceMappingURL=selectors.js.map
5874 +
5057 5875 ;// CONCATENATED MODULE: ./packages/core-data/build-module/locks/engine.js
5058 5876 /**
5059 5877 * Internal dependencies
5060 5878 */
@@ -5119,9 +5937,9 @@
5119 5937 acquire,
5120 5938 release
5121 5939 };
5122 5940 }
5123 -//# sourceMappingURL=engine.js.map
5941 +
5124 5942 ;// CONCATENATED MODULE: ./packages/core-data/build-module/locks/actions.js
5125 5943 /**
5126 5944 * Internal dependencies
5127 5945 */
@@ -5144,13 +5962,13 @@
5144 5962 __unstableAcquireStoreLock,
5145 5963 __unstableReleaseStoreLock
5146 5964 };
5147 5965 }
5148 -//# sourceMappingURL=actions.js.map
5966 +
5149 5967 ;// CONCATENATED MODULE: external ["wp","element"]
5150 -var external_wp_element_namespaceObject = window["wp"]["element"];
5968 +const external_wp_element_namespaceObject = window["wp"]["element"];
5151 5969 ;// CONCATENATED MODULE: external ["wp","blocks"]
5152 -var external_wp_blocks_namespaceObject = window["wp"]["blocks"];
5970 +const external_wp_blocks_namespaceObject = window["wp"]["blocks"];
5153 5971 ;// CONCATENATED MODULE: ./packages/core-data/build-module/entity-provider.js
5154 5972
5155 5973
5156 5974 /**
@@ -5163,8 +5981,10 @@
5163 5981 * Internal dependencies
5164 5982 */
5165 5983
5166 5984
5985 +/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
5986 +
5167 5987 const EMPTY_ARRAY = [];
5168 5988 /**
5169 5989 * Internal dependencies
5170 5990 */
@@ -5169,44 +5989,44 @@
5169 5989 * Internal dependencies
5170 5990 */
5171 5991
5172 5992
5173 -const entity_provider_entities = { ...defaultEntities.reduce((acc, entity) => {
5174 - if (!acc[entity.kind]) {
5175 - acc[entity.kind] = {};
5993 +const entityContexts = { ...rootEntitiesConfig.reduce((acc, loader) => {
5994 + if (!acc[loader.kind]) {
5995 + acc[loader.kind] = {};
5176 5996 }
5177 5997
5178 - acc[entity.kind][entity.name] = {
5179 - context: (0,external_wp_element_namespaceObject.createContext)()
5998 + acc[loader.kind][loader.name] = {
5999 + context: (0,external_wp_element_namespaceObject.createContext)(undefined)
5180 6000 };
5181 6001 return acc;
5182 6002 }, {}),
5183 - ...kinds.reduce((acc, kind) => {
5184 - acc[kind.name] = {};
6003 + ...additionalEntityConfigLoaders.reduce((acc, loader) => {
6004 + acc[loader.kind] = {};
5185 6005 return acc;
5186 6006 }, {})
5187 6007 };
5188 6008
5189 -const entity_provider_getEntity = (kind, type) => {
5190 - if (!entity_provider_entities[kind]) {
6009 +const getEntityContext = (kind, name) => {
6010 + if (!entityContexts[kind]) {
5191 6011 throw new Error(`Missing entity config for kind: ${kind}.`);
5192 6012 }
5193 6013
5194 - if (!entity_provider_entities[kind][type]) {
5195 - entity_provider_entities[kind][type] = {
5196 - context: (0,external_wp_element_namespaceObject.createContext)()
6014 + if (!entityContexts[kind][name]) {
6015 + entityContexts[kind][name] = {
6016 + context: (0,external_wp_element_namespaceObject.createContext)(undefined)
5197 6017 };
5198 6018 }
5199 6019
5200 - return entity_provider_entities[kind][type];
6020 + return entityContexts[kind][name].context;
5201 6021 };
5202 6022 /**
5203 6023 * Context provider component for providing
5204 - * an entity for a specific entity type.
6024 + * an entity for a specific entity.
5205 6025 *
5206 6026 * @param {Object} props The component's props.
5207 6027 * @param {string} props.kind The entity kind.
5208 - * @param {string} props.type The entity type.
6028 + * @param {string} props.type The entity name.
5209 6029 * @param {number} props.id The entity ID.
5210 6030 * @param {*} props.children The children to wrap.
5211 6031 *
5212 6032 * @return {Object} The provided children, wrapped with
@@ -5216,13 +6036,13 @@
5216 6036
5217 6037 function EntityProvider(_ref) {
5218 6038 let {
5219 6039 kind,
5220 - type,
6040 + type: name,
5221 6041 id,
5222 6042 children
5223 6043 } = _ref;
5224 - const Provider = entity_provider_getEntity(kind, type).context.Provider;
6044 + const Provider = getEntityContext(kind, name).Provider;
5225 6045 return (0,external_wp_element_namespaceObject.createElement)(Provider, {
5226 6046 value: id
5227 6047 }, children);
5228 6048 }
@@ -5230,13 +6050,13 @@
5230 6050 * Hook that returns the ID for the nearest
5231 6051 * provided entity of the specified type.
5232 6052 *
5233 6053 * @param {string} kind The entity kind.
5234 - * @param {string} type The entity type.
6054 + * @param {string} name The entity name.
5235 6055 */
5236 6056
5237 -function useEntityId(kind, type) {
5238 - return (0,external_wp_element_namespaceObject.useContext)(entity_provider_getEntity(kind, type).context);
6057 +function useEntityId(kind, name) {
6058 + return (0,external_wp_element_namespaceObject.useContext)(getEntityContext(kind, name));
5239 6059 }
5240 6060 /**
5241 6061 * Hook that returns the value and a setter for the
5242 6062 * specified property of the nearest provided
@@ -5242,9 +6062,9 @@
5242 6062 * specified property of the nearest provided
5243 6063 * entity of the specified type.
5244 6064 *
5245 6065 * @param {string} kind The entity kind.
5246 - * @param {string} type The entity type.
6066 + * @param {string} name The entity name.
5247 6067 * @param {string} prop The property name.
5248 6068 * @param {string} [_id] An entity ID to use instead of the context-provided one.
5249 6069 *
5250 6070 * @return {[*, Function, *]} An array where the first item is the
@@ -5254,10 +6074,10 @@
5254 6074 * information like `raw`, `rendered` and
5255 6075 * `protected` props.
5256 6076 */
5257 6077
5258 -function useEntityProp(kind, type, prop, _id) {
5259 - const providerId = useEntityId(kind, type);
6078 +function useEntityProp(kind, name, prop, _id) {
6079 + const providerId = useEntityId(kind, name);
5260 6080 const id = _id !== null && _id !== void 0 ? _id : providerId;
5261 6081 const {
5262 6082 value,
5263 6083 fullValue
@@ -5265,24 +6085,24 @@
5265 6085 const {
5266 6086 getEntityRecord,
5267 6087 getEditedEntityRecord
5268 6088 } = select(STORE_NAME);
5269 - const entity = getEntityRecord(kind, type, id); // Trigger resolver.
6089 + const record = getEntityRecord(kind, name, id); // Trigger resolver.
5270 6090
5271 - const editedEntity = getEditedEntityRecord(kind, type, id);
5272 - return entity && editedEntity ? {
5273 - value: editedEntity[prop],
5274 - fullValue: entity[prop]
6091 + const editedRecord = getEditedEntityRecord(kind, name, id);
6092 + return record && editedRecord ? {
6093 + value: editedRecord[prop],
6094 + fullValue: record[prop]
5275 6095 } : {};
5276 - }, [kind, type, id, prop]);
6096 + }, [kind, name, id, prop]);
5277 6097 const {
5278 6098 editEntityRecord
5279 6099 } = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME);
5280 6100 const setValue = (0,external_wp_element_namespaceObject.useCallback)(newValue => {
5281 - editEntityRecord(kind, type, id, {
6101 + editEntityRecord(kind, name, id, {
5282 6102 [prop]: newValue
5283 6103 });
5284 - }, [kind, type, id, prop]);
6104 + }, [kind, name, id, prop]);
5285 6105 return [value, setValue, fullValue];
5286 6106 }
5287 6107 /**
5288 6108 * Hook that returns block content getters and setters for
@@ -5295,9 +6115,9 @@
5295 6115 * `BlockEditorProvider` and are intended to be used with it,
5296 6116 * or similar components or hooks.
5297 6117 *
5298 6118 * @param {string} kind The entity kind.
5299 - * @param {string} type The entity type.
6119 + * @param {string} name The entity name.
5300 6120 * @param {Object} options
5301 6121 * @param {string} [options.id] An entity ID to use instead of the context-provided one.
5302 6122 *
5303 6123 * @return {[WPBlock[], Function, Function]} The block array and setters.
@@ -5302,13 +6122,13 @@
5302 6122 *
5303 6123 * @return {[WPBlock[], Function, Function]} The block array and setters.
5304 6124 */
5305 6125
5306 -function useEntityBlockEditor(kind, type) {
6126 +function useEntityBlockEditor(kind, name) {
5307 6127 let {
5308 6128 id: _id
5309 6129 } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5310 - const providerId = useEntityId(kind, type);
6130 + const providerId = useEntityId(kind, name);
5311 6131 const id = _id !== null && _id !== void 0 ? _id : providerId;
5312 6132 const {
5313 6133 content,
5314 6134 blocks
@@ -5315,14 +6135,14 @@
5315 6135 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
5316 6136 const {
5317 6137 getEditedEntityRecord
5318 6138 } = select(STORE_NAME);
5319 - const editedEntity = getEditedEntityRecord(kind, type, id);
6139 + const editedRecord = getEditedEntityRecord(kind, name, id);
5320 6140 return {
5321 - blocks: editedEntity.blocks,
5322 - content: editedEntity.content
6141 + blocks: editedRecord.blocks,
6142 + content: editedRecord.content
5323 6143 };
5324 - }, [kind, type, id]);
6144 + }, [kind, name, id]);
5325 6145 const {
5326 6146 __unstableCreateUndoLevel,
5327 6147 editEntityRecord
5328 6148 } = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME);
@@ -5331,9 +6151,9 @@
5331 6151 // Guard against other instances that might have
5332 6152 // set content to a function already or the blocks are already in state.
5333 6153 if (content && typeof content !== 'function' && !blocks) {
5334 6154 const parsedContent = (0,external_wp_blocks_namespaceObject.parse)(content);
5335 - editEntityRecord(kind, type, id, {
6155 + editEntityRecord(kind, name, id, {
5336 6156 blocks: parsedContent
5337 6157 }, {
5338 6158 undoIgnore: true
5339 6159 });
@@ -5349,9 +6169,9 @@
5349 6169 };
5350 6170 const noChange = blocks === edits.blocks;
5351 6171
5352 6172 if (noChange) {
5353 - return __unstableCreateUndoLevel(kind, type, id);
6173 + return __unstableCreateUndoLevel(kind, name, id);
5354 6174 } // We create a new function here on every persistent edit
5355 6175 // to make sure the edit makes the post dirty and creates
5356 6176 // a new undo level.
5357 6177
@@ -5362,10 +6182,10 @@
5362 6182 } = _ref2;
5363 6183 return (0,external_wp_blocks_namespaceObject.__unstableSerializeAndClean)(blocksForSerialization);
5364 6184 };
5365 6185
5366 - editEntityRecord(kind, type, id, edits);
5367 - }, [kind, type, id, blocks]);
6186 + editEntityRecord(kind, name, id, edits);
6187 + }, [kind, name, id, blocks]);
5368 6188 const onInput = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => {
5369 6189 const {
5370 6190 selection
5371 6191 } = options;
@@ -5372,15 +6192,15 @@
5372 6192 const edits = {
5373 6193 blocks: newBlocks,
5374 6194 selection
5375 6195 };
5376 - editEntityRecord(kind, type, id, edits);
5377 - }, [kind, type, id]);
6196 + editEntityRecord(kind, name, id, edits);
6197 + }, [kind, name, id]);
5378 6198 return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange];
5379 6199 }
5380 -//# sourceMappingURL=entity-provider.js.map
6200 +
5381 6201 ;// CONCATENATED MODULE: external ["wp","htmlEntities"]
5382 -var external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
6202 +const external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
5383 6203 ;// CONCATENATED MODULE: ./packages/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js
5384 6204 /**
5385 6205 * WordPress dependencies
5386 6206 */
@@ -5390,9 +6210,9 @@
5390 6210
5391 6211 /**
5392 6212 * Filters the search by type
5393 6213 *
5394 - * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType
6214 + * @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType
5395 6215 */
5396 6216
5397 6217 /**
5398 6218 * A link with an id may be of kind post-type or taxonomy
@@ -5420,8 +6240,19 @@
5420 6240 * @property {WPKind} [kind] Link kind of post-type or taxonomy
5421 6241 */
5422 6242
5423 6243 /**
6244 + * @typedef WPLinkSearchResultAugments
6245 + *
6246 + * @property {{kind: WPKind}} [meta] Contains kind information.
6247 + * @property {WPKind} [subtype] Optional subtype if it exists.
6248 + */
6249 +
6250 +/**
6251 + * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented
6252 + */
6253 +
6254 +/**
5424 6255 * @typedef WPEditorSettings
5425 6256 *
5426 6257 * @property {boolean} [ disablePostFormats ] Disables post formats, when true.
5427 6258 */
@@ -5462,8 +6293,10 @@
5462 6293 } = searchOptions;
5463 6294 const {
5464 6295 disablePostFormats = false
5465 6296 } = settings;
6297 + /** @type {Promise<WPLinkSearchResult>[]} */
6298 +
5466 6299 const queries = [];
5467 6300
5468 6301 if (!type || type === 'post') {
5469 6302 queries.push(external_wp_apiFetch_default()({
@@ -5482,9 +6315,9 @@
5482 6315 subtype
5483 6316 }
5484 6317 };
5485 6318 });
5486 - }).catch(() => []) // fail by returning no results
6319 + }).catch(() => []) // Fail by returning no results.
5487 6320 );
5488 6321 }
5489 6322
5490 6323 if (!type || type === 'term') {
@@ -5504,9 +6337,10 @@
5504 6337 subtype
5505 6338 }
5506 6339 };
5507 6340 });
5508 - }).catch(() => []));
6341 + }).catch(() => []) // Fail by returning no results.
6342 + );
5509 6343 }
5510 6344
5511 6345 if (!disablePostFormats && (!type || type === 'post-format')) {
5512 6346 queries.push(external_wp_apiFetch_default()({
@@ -5525,13 +6359,35 @@
5525 6359 subtype
5526 6360 }
5527 6361 };
5528 6362 });
5529 - }).catch(() => []));
6363 + }).catch(() => []) // Fail by returning no results.
6364 + );
5530 6365 }
5531 6366
6367 + if (!type || type === 'attachment') {
6368 + queries.push(external_wp_apiFetch_default()({
6369 + path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/media', {
6370 + search,
6371 + page,
6372 + per_page: perPage
6373 + })
6374 + }).then(results => {
6375 + return results.map(result => {
6376 + return { ...result,
6377 + meta: {
6378 + kind: 'media'
6379 + }
6380 + };
6381 + });
6382 + }).catch(() => []) // Fail by returning no results.
6383 + );
6384 + }
6385 +
5532 6386 return Promise.all(queries).then(results => {
5533 - return results.reduce((accumulator, current) => accumulator.concat(current), //flatten list
6387 + return results.reduce((
6388 + /** @type {WPLinkSearchResult[]} */
6389 + accumulator, current) => accumulator.concat(current), // Flatten list.
5534 6390 []).filter(
5535 6391 /**
5536 6392 * @param {{ id: number }} result
5537 6393 */
@@ -5536,19 +6392,20 @@
5536 6392 * @param {{ id: number }} result
5537 6393 */
5538 6394 result => {
5539 6395 return !!result.id;
5540 - }).slice(0, perPage).map(
5541 - /**
5542 - * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result
5543 - */
5544 - result => {
6396 + }).slice(0, perPage).map((
6397 + /** @type {WPLinkSearchResultAugmented} */
6398 + result) => {
5545 6399 var _result$meta;
5546 6400
6401 + const isMedia = result.type === 'attachment';
5547 6402 return {
5548 6403 id: result.id,
5549 - url: result.url,
5550 - title: (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(result.title || '') || (0,external_wp_i18n_namespaceObject.__)('(no title)'),
6404 + // @ts-ignore fix when we make this a TS file
6405 + url: isMedia ? result.source_url : result.url,
6406 + title: (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(isMedia ? // @ts-ignore fix when we make this a TS file
6407 + result.title.rendered : result.title || '') || (0,external_wp_i18n_namespaceObject.__)('(no title)'),
5551 6408 type: result.subtype || result.type,
5552 6409 kind: result === null || result === void 0 ? void 0 : (_result$meta = result.meta) === null || _result$meta === void 0 ? void 0 : _result$meta.kind
5553 6410 };
5554 6411 });
@@ -5554,10 +6411,10 @@
5554 6411 });
5555 6412 });
5556 6413 };
5557 6414
5558 -/* harmony default export */ var _experimental_fetch_link_suggestions = (fetchLinkSuggestions);
5559 -//# sourceMappingURL=__experimental-fetch-link-suggestions.js.map
6415 +/* harmony default export */ const _experimental_fetch_link_suggestions = (fetchLinkSuggestions);
6416 +
5560 6417 ;// CONCATENATED MODULE: ./packages/core-data/build-module/fetch/__experimental-fetch-url-data.js
5561 6418 /**
5562 6419 * WordPress dependencies
5563 6420 */
@@ -5612,9 +6469,9 @@
5612 6469
5613 6470
5614 6471 const protocol = (0,external_wp_url_namespaceObject.getProtocol)(url);
5615 6472
5616 - if (!(0,external_wp_url_namespaceObject.isValidProtocol)(protocol) || !protocol.startsWith('http') || !/^https?:\/\/[^\/\s]/i.test(url)) {
6473 + if (!protocol || !(0,external_wp_url_namespaceObject.isValidProtocol)(protocol) || !protocol.startsWith('http') || !/^https?:\/\/[^\/\s]/i.test(url)) {
5617 6474 return Promise.reject(`${url} does not have a valid protocol. URLs must be "http" based`);
5618 6475 }
5619 6476
5620 6477 if (CACHE.has(url)) {
@@ -5629,14 +6486,546 @@
5629 6486 return res;
5630 6487 });
5631 6488 };
5632 6489
5633 -/* harmony default export */ var _experimental_fetch_url_data = (fetchUrlData);
5634 -//# sourceMappingURL=__experimental-fetch-url-data.js.map
6490 +/* harmony default export */ const _experimental_fetch_url_data = (fetchUrlData);
6491 +
5635 6492 ;// CONCATENATED MODULE: ./packages/core-data/build-module/fetch/index.js
5636 6493
5637 6494
5638 -//# sourceMappingURL=index.js.map
6495 +
6496 +// EXTERNAL MODULE: ./node_modules/memize/index.js
6497 +var memize = __webpack_require__(9756);
6498 +var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
6499 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/memoize.js
6500 +/**
6501 + * External dependencies
6502 + */
6503 + // re-export due to restrictive esModuleInterop setting
6504 +
6505 +/* harmony default export */ const memoize = ((memize_default()));
6506 +
6507 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/constants.js
6508 +let Status;
6509 +
6510 +(function (Status) {
6511 + Status["Idle"] = "IDLE";
6512 + Status["Resolving"] = "RESOLVING";
6513 + Status["Error"] = "ERROR";
6514 + Status["Success"] = "SUCCESS";
6515 +})(Status || (Status = {}));
6516 +
6517 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/use-query-select.js
6518 +/**
6519 + * WordPress dependencies
6520 + */
6521 +
6522 +/**
6523 + * Internal dependencies
6524 + */
6525 +
6526 +
6527 +
6528 +const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
6529 +
6530 +/**
6531 + * Like useSelect, but the selectors return objects containing
6532 + * both the original data AND the resolution info.
6533 + *
6534 + * @since 6.1.0 Introduced in WordPress core.
6535 + * @private
6536 + *
6537 + * @param {Function} mapQuerySelect see useSelect
6538 + * @param {Array} deps see useSelect
6539 + *
6540 + * @example
6541 + * ```js
6542 + * import { useQuerySelect } from '@wordpress/data';
6543 + * import { store as coreDataStore } from '@wordpress/core-data';
6544 + *
6545 + * function PageTitleDisplay( { id } ) {
6546 + * const { data: page, isResolving } = useQuerySelect( ( query ) => {
6547 + * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )
6548 + * }, [ id ] );
6549 + *
6550 + * if ( isResolving ) {
6551 + * return 'Loading...';
6552 + * }
6553 + *
6554 + * return page.title;
6555 + * }
6556 + *
6557 + * // Rendered in the application:
6558 + * // <PageTitleDisplay id={ 10 } />
6559 + * ```
6560 + *
6561 + * In the above example, when `PageTitleDisplay` is rendered into an
6562 + * application, the page and the resolution details will be retrieved from
6563 + * the store state using the `mapSelect` callback on `useQuerySelect`.
6564 + *
6565 + * If the id prop changes then any page in the state for that id is
6566 + * retrieved. If the id prop doesn't change and other props are passed in
6567 + * that do change, the title will not change because the dependency is just
6568 + * the id.
6569 + * @see useSelect
6570 + *
6571 + * @return {QuerySelectResponse} Queried data.
6572 + */
6573 +function useQuerySelect(mapQuerySelect, deps) {
6574 + return (0,external_wp_data_namespaceObject.useSelect)((select, registry) => {
6575 + const resolve = store => enrichSelectors(select(store));
6576 +
6577 + return mapQuerySelect(resolve, registry);
6578 + }, deps);
6579 +}
6580 +
6581 +/**
6582 + * Transform simple selectors into ones that return an object with the
6583 + * original return value AND the resolution info.
6584 + *
6585 + * @param {Object} selectors Selectors to enrich
6586 + * @return {EnrichedSelectors} Enriched selectors
6587 + */
6588 +const enrichSelectors = memoize(selectors => {
6589 + const resolvers = {};
6590 +
6591 + for (const selectorName in selectors) {
6592 + if (META_SELECTORS.includes(selectorName)) {
6593 + continue;
6594 + }
6595 +
6596 + Object.defineProperty(resolvers, selectorName, {
6597 + get: () => function () {
6598 + const {
6599 + getIsResolving,
6600 + hasFinishedResolution
6601 + } = selectors;
6602 +
6603 + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6604 + args[_key] = arguments[_key];
6605 + }
6606 +
6607 + const isResolving = !!getIsResolving(selectorName, args);
6608 + const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
6609 + const data = selectors[selectorName](...args);
6610 + let status;
6611 +
6612 + if (isResolving) {
6613 + status = Status.Resolving;
6614 + } else if (hasResolved) {
6615 + if (data) {
6616 + status = Status.Success;
6617 + } else {
6618 + status = Status.Error;
6619 + }
6620 + } else {
6621 + status = Status.Idle;
6622 + }
6623 +
6624 + return {
6625 + data,
6626 + status,
6627 + isResolving,
6628 + hasResolved
6629 + };
6630 + }
6631 + });
6632 + }
6633 +
6634 + return resolvers;
6635 +});
6636 +
6637 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/use-entity-record.js
6638 +/**
6639 + * WordPress dependencies
6640 + */
6641 +
6642 +
6643 +
6644 +/**
6645 + * Internal dependencies
6646 + */
6647 +
6648 +
6649 +
6650 +
6651 +/**
6652 + * Resolves the specified entity record.
6653 + *
6654 + * @since 6.1.0 Introduced in WordPress core.
6655 + *
6656 + * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
6657 + * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
6658 + * @param recordId ID of the requested entity record.
6659 + * @param options Optional hook options.
6660 + * @example
6661 + * ```js
6662 + * import { useEntityRecord } from '@wordpress/core-data';
6663 + *
6664 + * function PageTitleDisplay( { id } ) {
6665 + * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );
6666 + *
6667 + * if ( isResolving ) {
6668 + * return 'Loading...';
6669 + * }
6670 + *
6671 + * return record.title;
6672 + * }
6673 + *
6674 + * // Rendered in the application:
6675 + * // <PageTitleDisplay id={ 1 } />
6676 + * ```
6677 + *
6678 + * In the above example, when `PageTitleDisplay` is rendered into an
6679 + * application, the page and the resolution details will be retrieved from
6680 + * the store state using `getEntityRecord()`, or resolved if missing.
6681 + *
6682 + * @example
6683 + * ```js
6684 + * import { useDispatch } from '@wordpress/data';
6685 + * import { useCallback } from '@wordpress/element';
6686 + * import { __ } from '@wordpress/i18n';
6687 + * import { TextControl } from '@wordpress/components';
6688 + * import { store as noticeStore } from '@wordpress/notices';
6689 + * import { useEntityRecord } from '@wordpress/core-data';
6690 + *
6691 + * function PageRenameForm( { id } ) {
6692 + * const page = useEntityRecord( 'postType', 'page', id );
6693 + * const { createSuccessNotice, createErrorNotice } =
6694 + * useDispatch( noticeStore );
6695 + *
6696 + * const setTitle = useCallback( ( title ) => {
6697 + * page.edit( { title } );
6698 + * }, [ page.edit ] );
6699 + *
6700 + * if ( page.isResolving ) {
6701 + * return 'Loading...';
6702 + * }
6703 + *
6704 + * async function onRename( event ) {
6705 + * event.preventDefault();
6706 + * try {
6707 + * await page.save();
6708 + * createSuccessNotice( __( 'Page renamed.' ), {
6709 + * type: 'snackbar',
6710 + * } );
6711 + * } catch ( error ) {
6712 + * createErrorNotice( error.message, { type: 'snackbar' } );
6713 + * }
6714 + * }
6715 + *
6716 + * return (
6717 + * <form onSubmit={ onRename }>
6718 + * <TextControl
6719 + * label={ __( 'Name' ) }
6720 + * value={ page.editedRecord.title }
6721 + * onChange={ setTitle }
6722 + * />
6723 + * <button type="submit">{ __( 'Save' ) }</button>
6724 + * </form>
6725 + * );
6726 + * }
6727 + *
6728 + * // Rendered in the application:
6729 + * // <PageRenameForm id={ 1 } />
6730 + * ```
6731 + *
6732 + * In the above example, updating and saving the page title is handled
6733 + * via the `edit()` and `save()` mutation helpers provided by
6734 + * `useEntityRecord()`;
6735 + *
6736 + * @return Entity record data.
6737 + * @template RecordType
6738 + */
6739 +function useEntityRecord(kind, name, recordId) {
6740 + let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
6741 + enabled: true
6742 + };
6743 + const {
6744 + editEntityRecord,
6745 + saveEditedEntityRecord
6746 + } = (0,external_wp_data_namespaceObject.useDispatch)(store);
6747 + const mutations = (0,external_wp_element_namespaceObject.useMemo)(() => ({
6748 + edit: record => editEntityRecord(kind, name, recordId, record),
6749 + save: function () {
6750 + let saveOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6751 + return saveEditedEntityRecord(kind, name, recordId, {
6752 + throwOnError: true,
6753 + ...saveOptions
6754 + });
6755 + }
6756 + }), [recordId]);
6757 + const {
6758 + editedRecord,
6759 + hasEdits
6760 + } = (0,external_wp_data_namespaceObject.useSelect)(select => ({
6761 + editedRecord: select(store).getEditedEntityRecord(kind, name, recordId),
6762 + hasEdits: select(store).hasEditsForEntityRecord(kind, name, recordId)
6763 + }), [kind, name, recordId]);
6764 + const {
6765 + data: record,
6766 + ...querySelectRest
6767 + } = useQuerySelect(query => {
6768 + if (!options.enabled) {
6769 + return null;
6770 + }
6771 +
6772 + return query(store).getEntityRecord(kind, name, recordId);
6773 + }, [kind, name, recordId, options.enabled]);
6774 + return {
6775 + record,
6776 + editedRecord,
6777 + hasEdits,
6778 + ...querySelectRest,
6779 + ...mutations
6780 + };
6781 +}
6782 +function __experimentalUseEntityRecord(kind, name, recordId, options) {
6783 + external_wp_deprecated_default()(`wp.data.__experimentalUseEntityRecord`, {
6784 + alternative: 'wp.data.useEntityRecord',
6785 + since: '6.1'
6786 + });
6787 + return useEntityRecord(kind, name, recordId, options);
6788 +}
6789 +
6790 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/use-entity-records.js
6791 +/**
6792 + * WordPress dependencies
6793 + */
6794 +
6795 +
6796 +/**
6797 + * Internal dependencies
6798 + */
6799 +
6800 +
6801 +
6802 +const use_entity_records_EMPTY_ARRAY = [];
6803 +/**
6804 + * Resolves the specified entity records.
6805 + *
6806 + * @since 6.1.0 Introduced in WordPress core.
6807 + *
6808 + * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
6809 + * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
6810 + * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
6811 + * @param options Optional hook options.
6812 + * @example
6813 + * ```js
6814 + * import { useEntityRecord } from '@wordpress/core-data';
6815 + *
6816 + * function PageTitlesList() {
6817 + * const { records, isResolving } = useEntityRecords( 'postType', 'page' );
6818 + *
6819 + * if ( isResolving ) {
6820 + * return 'Loading...';
6821 + * }
6822 + *
6823 + * return (
6824 + * <ul>
6825 + * {records.map(( page ) => (
6826 + * <li>{ page.title }</li>
6827 + * ))}
6828 + * </ul>
6829 + * );
6830 + * }
6831 + *
6832 + * // Rendered in the application:
6833 + * // <PageTitlesList />
6834 + * ```
6835 + *
6836 + * In the above example, when `PageTitlesList` is rendered into an
6837 + * application, the list of records and the resolution details will be retrieved from
6838 + * the store state using `getEntityRecords()`, or resolved if missing.
6839 + *
6840 + * @return Entity records data.
6841 + * @template RecordType
6842 + */
6843 +
6844 +function useEntityRecords(kind, name) {
6845 + let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6846 + let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
6847 + enabled: true
6848 + };
6849 + // Serialize queryArgs to a string that can be safely used as a React dep.
6850 + // We can't just pass queryArgs as one of the deps, because if it is passed
6851 + // as an object literal, then it will be a different object on each call even
6852 + // if the values remain the same.
6853 + const queryAsString = (0,external_wp_url_namespaceObject.addQueryArgs)('', queryArgs);
6854 + const {
6855 + data: records,
6856 + ...rest
6857 + } = useQuerySelect(query => {
6858 + if (!options.enabled) {
6859 + return {
6860 + // Avoiding returning a new reference on every execution.
6861 + data: use_entity_records_EMPTY_ARRAY
6862 + };
6863 + }
6864 +
6865 + return query(store).getEntityRecords(kind, name, queryArgs);
6866 + }, [kind, name, queryAsString, options.enabled]);
6867 + return {
6868 + records,
6869 + ...rest
6870 + };
6871 +}
6872 +function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
6873 + external_wp_deprecated_default()(`wp.data.__experimentalUseEntityRecords`, {
6874 + alternative: 'wp.data.useEntityRecords',
6875 + since: '6.1'
6876 + });
6877 + return useEntityRecords(kind, name, queryArgs, options);
6878 +}
6879 +
6880 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/use-resource-permissions.js
6881 +/**
6882 + * WordPress dependencies
6883 + */
6884 +
6885 +/**
6886 + * Internal dependencies
6887 + */
6888 +
6889 +
6890 +
6891 +
6892 +
6893 +/**
6894 + * Resolves resource permissions.
6895 + *
6896 + * @since 6.1.0 Introduced in WordPress core.
6897 + *
6898 + * @param resource The resource in question, e.g. media.
6899 + * @param id ID of a specific resource entry, if needed, e.g. 10.
6900 + *
6901 + * @example
6902 + * ```js
6903 + * import { useResourcePermissions } from '@wordpress/core-data';
6904 + *
6905 + * function PagesList() {
6906 + * const { canCreate, isResolving } = useResourcePermissions( 'pages' );
6907 + *
6908 + * if ( isResolving ) {
6909 + * return 'Loading ...';
6910 + * }
6911 + *
6912 + * return (
6913 + * <div>
6914 + * {canCreate ? (<button>+ Create a new page</button>) : false}
6915 + * // ...
6916 + * </div>
6917 + * );
6918 + * }
6919 + *
6920 + * // Rendered in the application:
6921 + * // <PagesList />
6922 + * ```
6923 + *
6924 + * @example
6925 + * ```js
6926 + * import { useResourcePermissions } from '@wordpress/core-data';
6927 + *
6928 + * function Page({ pageId }) {
6929 + * const {
6930 + * canCreate,
6931 + * canUpdate,
6932 + * canDelete,
6933 + * isResolving
6934 + * } = useResourcePermissions( 'pages', pageId );
6935 + *
6936 + * if ( isResolving ) {
6937 + * return 'Loading ...';
6938 + * }
6939 + *
6940 + * return (
6941 + * <div>
6942 + * {canCreate ? (<button>+ Create a new page</button>) : false}
6943 + * {canUpdate ? (<button>Edit page</button>) : false}
6944 + * {canDelete ? (<button>Delete page</button>) : false}
6945 + * // ...
6946 + * </div>
6947 + * );
6948 + * }
6949 + *
6950 + * // Rendered in the application:
6951 + * // <Page pageId={ 15 } />
6952 + * ```
6953 + *
6954 + * In the above example, when `PagesList` is rendered into an
6955 + * application, the appropriate permissions and the resolution details will be retrieved from
6956 + * the store state using `canUser()`, or resolved if missing.
6957 + *
6958 + * @return Entity records data.
6959 + * @template IdType
6960 + */
6961 +function useResourcePermissions(resource, id) {
6962 + return useQuerySelect(resolve => {
6963 + const {
6964 + canUser
6965 + } = resolve(store);
6966 + const create = canUser('create', resource);
6967 +
6968 + if (!id) {
6969 + const read = canUser('read', resource);
6970 + const isResolving = create.isResolving || read.isResolving;
6971 + const hasResolved = create.hasResolved && read.hasResolved;
6972 + let status = Status.Idle;
6973 +
6974 + if (isResolving) {
6975 + status = Status.Resolving;
6976 + } else if (hasResolved) {
6977 + status = Status.Success;
6978 + }
6979 +
6980 + return {
6981 + status,
6982 + isResolving,
6983 + hasResolved,
6984 + canCreate: create.hasResolved && create.data,
6985 + canRead: read.hasResolved && read.data
6986 + };
6987 + }
6988 +
6989 + const read = canUser('read', resource, id);
6990 + const update = canUser('update', resource, id);
6991 +
6992 + const _delete = canUser('delete', resource, id);
6993 +
6994 + const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
6995 + const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
6996 + let status = Status.Idle;
6997 +
6998 + if (isResolving) {
6999 + status = Status.Resolving;
7000 + } else if (hasResolved) {
7001 + status = Status.Success;
7002 + }
7003 +
7004 + return {
7005 + status,
7006 + isResolving,
7007 + hasResolved,
7008 + canRead: hasResolved && read.data,
7009 + canCreate: hasResolved && create.data,
7010 + canUpdate: hasResolved && update.data,
7011 + canDelete: hasResolved && _delete.data
7012 + };
7013 + }, [resource, id]);
7014 +}
7015 +function __experimentalUseResourcePermissions(resource, id) {
7016 + external_wp_deprecated_default()(`wp.data.__experimentalUseResourcePermissions`, {
7017 + alternative: 'wp.data.useResourcePermissions',
7018 + since: '6.1'
7019 + });
7020 + return useResourcePermissions(resource, id);
7021 +}
7022 +
7023 +;// CONCATENATED MODULE: ./packages/core-data/build-module/hooks/index.js
7024 +
7025 +
7026 +
7027 +
5639 7028 ;// CONCATENATED MODULE: ./packages/core-data/build-module/index.js
5640 7029 /**
5641 7030 * WordPress dependencies
5642 7031 */
@@ -5651,13 +7040,13 @@
5651 7040
5652 7041
5653 7042
5654 7043 // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
5655 -// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)
5656 -// Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...
7044 +// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
7045 +// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
5657 7046 // The "kind" and the "name" of the entity are combined to generate these shortcuts.
5658 7047
5659 -const entitySelectors = defaultEntities.reduce((result, entity) => {
7048 +const entitySelectors = rootEntitiesConfig.reduce((result, entity) => {
5660 7049 const {
5661 7050 kind,
5662 7051 name
5663 7052 } = entity;
@@ -5663,19 +7052,13 @@
5663 7052 } = entity;
5664 7053
5665 7054 result[getMethodName(kind, name)] = (state, key, query) => getEntityRecord(state, kind, name, key, query);
5666 7055
5667 - result[getMethodName(kind, name, 'get', true)] = function (state) {
5668 - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
5669 - args[_key - 1] = arguments[_key];
5670 - }
7056 + result[getMethodName(kind, name, 'get', true)] = (state, query) => getEntityRecords(state, kind, name, query);
5671 7057
5672 - return getEntityRecords(state, kind, name, ...args);
5673 - };
5674 -
5675 7058 return result;
5676 7059 }, {});
5677 -const entityResolvers = defaultEntities.reduce((result, entity) => {
7060 +const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
5678 7061 const {
5679 7062 kind,
5680 7063 name
5681 7064 } = entity;
@@ -5684,26 +7067,20 @@
5684 7067
5685 7068 const pluralMethodName = getMethodName(kind, name, 'get', true);
5686 7069
5687 7070 result[pluralMethodName] = function () {
5688 - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
5689 - args[_key2] = arguments[_key2];
7071 + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7072 + args[_key] = arguments[_key];
5690 7073 }
5691 7074
5692 7075 return resolvers_getEntityRecords(kind, name, ...args);
5693 7076 };
5694 7077
5695 - result[pluralMethodName].shouldInvalidate = function (action) {
5696 - for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
5697 - args[_key3 - 1] = arguments[_key3];
5698 - }
7078 + result[pluralMethodName].shouldInvalidate = action => resolvers_getEntityRecords.shouldInvalidate(action, kind, name);
5699 7079
5700 - return resolvers_getEntityRecords.shouldInvalidate(action, kind, name, ...args);
5701 - };
5702 -
5703 7080 return result;
5704 7081 }, {});
5705 -const entityActions = defaultEntities.reduce((result, entity) => {
7082 +const entityActions = rootEntitiesConfig.reduce((result, entity) => {
5706 7083 const {
5707 7084 kind,
5708 7085 name
5709 7086 } = entity;
@@ -5725,17 +7102,14 @@
5725 7102 ...entitySelectors
5726 7103 },
5727 7104 resolvers: { ...resolvers_namespaceObject,
5728 7105 ...entityResolvers
5729 - },
5730 - __experimentalUseThunks: true
7106 + }
5731 7107 });
5732 7108 /**
5733 7109 * Store definition for the code data namespace.
5734 7110 *
5735 7111 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
5736 - *
5737 - * @type {Object}
5738 7112 */
5739 7113
5740 7114
5741 7115 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig());
@@ -5742,9 +7116,12 @@
5742 7116 (0,external_wp_data_namespaceObject.register)(store);
5743 7117
5744 7118
5745 7119
5746 -//# sourceMappingURL=index.js.map
5747 -}();
7120 +
7121 +
7122 +
7123 +})();
7124 +
5748 7125 (window.wp = window.wp || {}).coreData = __webpack_exports__;
5749 7126 /******/ })()
5750 7127 ;