@wordpress/core-data 7.34.0 → 7.34.1-next.2f1c7c01b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/actions.js +12 -10
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +4 -2
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +3 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/batch/index.js +2 -0
- package/build/batch/index.js.map +1 -1
- package/build/dynamic-entities.js +4 -2
- package/build/dynamic-entities.js.map +1 -1
- package/build/entities.js +10 -8
- package/build/entities.js.map +1 -1
- package/build/entity-context.js +3 -1
- package/build/entity-context.js.map +1 -1
- package/build/entity-provider.js +3 -1
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/attachment.js +2 -0
- package/build/entity-types/attachment.js.map +1 -1
- package/build/entity-types/base-entity-records.js +2 -0
- package/build/entity-types/base-entity-records.js.map +1 -1
- package/build/entity-types/base.js +2 -0
- package/build/entity-types/base.js.map +1 -1
- package/build/entity-types/comment.js +2 -0
- package/build/entity-types/comment.js.map +1 -1
- package/build/entity-types/global-styles-revision.js +2 -0
- package/build/entity-types/global-styles-revision.js.map +1 -1
- package/build/entity-types/helpers.js +2 -0
- package/build/entity-types/helpers.js.map +1 -1
- package/build/entity-types/index.js +2 -0
- package/build/entity-types/index.js.map +1 -1
- package/build/entity-types/menu-location.js +2 -0
- package/build/entity-types/menu-location.js.map +1 -1
- package/build/entity-types/nav-menu-item.js +2 -0
- package/build/entity-types/nav-menu-item.js.map +1 -1
- package/build/entity-types/nav-menu.js +2 -0
- package/build/entity-types/nav-menu.js.map +1 -1
- package/build/entity-types/page.js +2 -0
- package/build/entity-types/page.js.map +1 -1
- package/build/entity-types/plugin.js +2 -0
- package/build/entity-types/plugin.js.map +1 -1
- package/build/entity-types/post-revision.js +2 -0
- package/build/entity-types/post-revision.js.map +1 -1
- package/build/entity-types/post-status.js +2 -0
- package/build/entity-types/post-status.js.map +1 -1
- package/build/entity-types/post.js +2 -0
- package/build/entity-types/post.js.map +1 -1
- package/build/entity-types/settings.js +2 -0
- package/build/entity-types/settings.js.map +1 -1
- package/build/entity-types/sidebar.js +2 -0
- package/build/entity-types/sidebar.js.map +1 -1
- package/build/entity-types/taxonomy.js +2 -0
- package/build/entity-types/taxonomy.js.map +1 -1
- package/build/entity-types/term.js +2 -0
- package/build/entity-types/term.js.map +1 -1
- package/build/entity-types/theme.js +2 -0
- package/build/entity-types/theme.js.map +1 -1
- package/build/entity-types/type.js +2 -0
- package/build/entity-types/type.js.map +1 -1
- package/build/entity-types/user.js +2 -0
- package/build/entity-types/user.js.map +1 -1
- package/build/entity-types/widget-type.js +2 -0
- package/build/entity-types/widget-type.js.map +1 -1
- package/build/entity-types/widget.js +2 -0
- package/build/entity-types/widget.js.map +1 -1
- package/build/entity-types/wp-template-part.js +2 -0
- package/build/entity-types/wp-template-part.js.map +1 -1
- package/build/entity-types/wp-template.js +2 -0
- package/build/entity-types/wp-template.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +4 -2
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/fetch/index.js +2 -0
- package/build/fetch/index.js.map +1 -1
- package/build/footnotes/get-footnotes-order.js +3 -1
- package/build/footnotes/get-footnotes-order.js.map +1 -1
- package/build/footnotes/get-rich-text-values-cached.js +4 -2
- package/build/footnotes/get-rich-text-values-cached.js.map +1 -1
- package/build/footnotes/index.js +3 -1
- package/build/footnotes/index.js.map +1 -1
- package/build/hooks/constants.js +2 -0
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/memoize.js +2 -0
- package/build/hooks/memoize.js.map +1 -1
- package/build/hooks/use-entity-block-editor.js +4 -2
- package/build/hooks/use-entity-block-editor.js.map +1 -1
- package/build/hooks/use-entity-id.js +2 -0
- package/build/hooks/use-entity-id.js.map +1 -1
- package/build/hooks/use-entity-prop.js +2 -0
- package/build/hooks/use-entity-prop.js.map +1 -1
- package/build/hooks/use-entity-record.js +3 -1
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +3 -1
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +4 -2
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +2 -0
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +8 -6
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +3 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/locks/actions.js +2 -0
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +2 -0
- package/build/locks/engine.js.map +1 -1
- package/build/locks/reducer.js +3 -1
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +2 -0
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +2 -0
- package/build/locks/utils.js.map +1 -1
- package/build/name.js +3 -1
- package/build/name.js.map +1 -1
- package/build/private-actions.js +3 -1
- package/build/private-actions.js.map +1 -1
- package/build/private-apis.js +3 -1
- package/build/private-apis.js.map +1 -1
- package/build/private-selectors.js +7 -5
- package/build/private-selectors.js.map +1 -1
- package/build/queried-data/actions.js +2 -0
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +2 -0
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/index.js +2 -0
- package/build/queried-data/index.js.map +1 -1
- package/build/queried-data/reducer.js +4 -2
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -2
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +4 -2
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +30 -28
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +18 -16
- package/build/selectors.js.map +1 -1
- package/build/sync.js +3 -1
- package/build/sync.js.map +1 -1
- package/build/types.js +2 -0
- package/build/types.js.map +1 -1
- package/build/utils/conservative-map-item.js +2 -0
- package/build/utils/conservative-map-item.js.map +1 -1
- package/build/utils/crdt-blocks.js +4 -2
- package/build/utils/crdt-blocks.js.map +1 -1
- package/build/utils/crdt.js +5 -3
- package/build/utils/crdt.js.map +1 -1
- package/build/utils/forward-resolver.js +3 -1
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/get-nested-value.js +2 -0
- package/build/utils/get-nested-value.js.map +1 -1
- package/build/utils/get-normalized-comma-separable.js +2 -0
- package/build/utils/get-normalized-comma-separable.js.map +1 -1
- package/build/utils/if-matching-action.js +3 -1
- package/build/utils/if-matching-action.js.map +1 -1
- package/build/utils/index.js +2 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-numeric-id.js +2 -0
- package/build/utils/is-numeric-id.js.map +1 -1
- package/build/utils/is-raw-attribute.js +2 -0
- package/build/utils/is-raw-attribute.js.map +1 -1
- package/build/utils/log-entity-deprecation.js +3 -1
- package/build/utils/log-entity-deprecation.js.map +1 -1
- package/build/utils/on-sub-key.js +3 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/receive-intermediate-results.js +3 -1
- package/build/utils/receive-intermediate-results.js.map +1 -1
- package/build/utils/replace-action.js +3 -1
- package/build/utils/replace-action.js.map +1 -1
- package/build/utils/set-nested-value.js +2 -0
- package/build/utils/set-nested-value.js.map +1 -1
- package/build/utils/user-permissions.js +3 -1
- package/build/utils/user-permissions.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +2 -0
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js +11 -10
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +3 -2
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +2 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/batch/index.js +1 -0
- package/build-module/batch/index.js.map +1 -1
- package/build-module/dynamic-entities.js +3 -2
- package/build-module/dynamic-entities.js.map +1 -1
- package/build-module/entities.js +9 -8
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-context.js +2 -1
- package/build-module/entity-context.js.map +1 -1
- package/build-module/entity-provider.js +2 -1
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +1 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +3 -2
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/fetch/index.js +1 -0
- package/build-module/fetch/index.js.map +1 -1
- package/build-module/footnotes/get-footnotes-order.js +2 -1
- package/build-module/footnotes/get-footnotes-order.js.map +1 -1
- package/build-module/footnotes/get-rich-text-values-cached.js +3 -2
- package/build-module/footnotes/get-rich-text-values-cached.js.map +1 -1
- package/build-module/footnotes/index.js +2 -1
- package/build-module/footnotes/index.js.map +1 -1
- package/build-module/hooks/constants.js +1 -0
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/memoize.js +1 -0
- package/build-module/hooks/memoize.js.map +1 -1
- package/build-module/hooks/use-entity-block-editor.js +3 -2
- package/build-module/hooks/use-entity-block-editor.js.map +1 -1
- package/build-module/hooks/use-entity-id.js +1 -0
- package/build-module/hooks/use-entity-id.js.map +1 -1
- package/build-module/hooks/use-entity-prop.js +1 -0
- package/build-module/hooks/use-entity-prop.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +2 -1
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -1
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +3 -2
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +1 -0
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +13 -12
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js +2 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/locks/actions.js +1 -0
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +1 -0
- package/build-module/locks/engine.js.map +1 -1
- package/build-module/locks/reducer.js +2 -1
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +1 -0
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +1 -0
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/name.js +2 -1
- package/build-module/name.js.map +1 -1
- package/build-module/private-actions.js +2 -1
- package/build-module/private-actions.js.map +1 -1
- package/build-module/private-apis.js +2 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-selectors.js +6 -5
- package/build-module/private-selectors.js.map +1 -1
- package/build-module/queried-data/actions.js +1 -0
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +1 -0
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/index.js +1 -0
- package/build-module/queried-data/index.js.map +1 -1
- package/build-module/queried-data/reducer.js +3 -2
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +3 -2
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +3 -2
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +29 -28
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +17 -16
- package/build-module/selectors.js.map +1 -1
- package/build-module/sync.js +2 -1
- package/build-module/sync.js.map +1 -1
- package/build-module/utils/conservative-map-item.js +1 -0
- package/build-module/utils/conservative-map-item.js.map +1 -1
- package/build-module/utils/crdt-blocks.js +3 -2
- package/build-module/utils/crdt-blocks.js.map +1 -1
- package/build-module/utils/crdt.js +4 -3
- package/build-module/utils/crdt.js.map +1 -1
- package/build-module/utils/forward-resolver.js +2 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/get-nested-value.js +1 -0
- package/build-module/utils/get-nested-value.js.map +1 -1
- package/build-module/utils/get-normalized-comma-separable.js +1 -0
- package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
- package/build-module/utils/if-matching-action.js +2 -1
- package/build-module/utils/if-matching-action.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-numeric-id.js +1 -0
- package/build-module/utils/is-numeric-id.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js +1 -0
- package/build-module/utils/is-raw-attribute.js.map +1 -1
- package/build-module/utils/log-entity-deprecation.js +2 -1
- package/build-module/utils/log-entity-deprecation.js.map +1 -1
- package/build-module/utils/on-sub-key.js +2 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/receive-intermediate-results.js +2 -1
- package/build-module/utils/receive-intermediate-results.js.map +1 -1
- package/build-module/utils/replace-action.js +2 -1
- package/build-module/utils/replace-action.js.map +1 -1
- package/build-module/utils/set-nested-value.js +1 -0
- package/build-module/utils/set-nested-value.js.map +1 -1
- package/build-module/utils/user-permissions.js +2 -1
- package/build-module/utils/user-permissions.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +1 -0
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/package.json +18 -18
- package/src/test/resolvers.js +78 -0
|
@@ -12,6 +12,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/core-data/src/entity-types/wp-template.ts
|
|
15
17
|
var wp_template_exports = {};
|
|
16
18
|
module.exports = __toCommonJS(wp_template_exports);
|
|
17
19
|
//# sourceMappingURL=wp-template.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/entity-types/wp-template.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tContext,\n\tPostStatus,\n\tRenderedText,\n\tOmitNevers,\n\tContextualField,\n} from './helpers';\n\nimport type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';\n\ndeclare module './base-entity-records' {\n\texport namespace BaseEntityRecords {\n\t\texport interface WpTemplate< C extends Context > {\n\t\t\t/**\n\t\t\t * ID of template.\n\t\t\t */\n\t\t\tid: string;\n\t\t\t/**\n\t\t\t * Unique slug identifying the template.\n\t\t\t */\n\t\t\tslug: string;\n\t\t\t/**\n\t\t\t * Theme identifier for the template.\n\t\t\t */\n\t\t\ttheme: string;\n\t\t\t/**\n\t\t\t * Type of template.\n\t\t\t */\n\t\t\ttype: string;\n\t\t\t/**\n\t\t\t * Source of template\n\t\t\t */\n\t\t\tsource: string;\n\t\t\t/**\n\t\t\t * Source of a customized template\n\t\t\t */\n\t\t\torigin: string;\n\t\t\t/**\n\t\t\t * Content of template.\n\t\t\t *\n\t\t\t * This field never has a `rendered` property when reading but still uses\n\t\t\t * the RenderedText type so it can be set as a string when sending updates to\n\t\t\t * the server.\n\t\t\t *\n\t\t\t * TODO: Figure out how to mesh this with `RenderedText<C>`\n\t\t\t */\n\t\t\tcontent: ContextualField<\n\t\t\t\tRenderedText< C > & {\n\t\t\t\t\t/**\n\t\t\t\t\t * Version of the content block format used by the template.\n\t\t\t\t\t */\n\t\t\t\t\tblock_version: ContextualField< number, 'edit', C >;\n\t\t\t\t},\n\t\t\t\t'view' | 'edit',\n\t\t\t\tC\n\t\t\t>;\n\t\t\t/**\n\t\t\t * Title of template.\n\t\t\t */\n\t\t\ttitle: RenderedText< 'edit' >;\n\t\t\t/**\n\t\t\t * Description of template.\n\t\t\t */\n\t\t\tdescription: string;\n\t\t\t/**\n\t\t\t * Status of template.\n\t\t\t */\n\t\t\tstatus: PostStatus;\n\t\t\t/**\n\t\t\t * Post ID.\n\t\t\t */\n\t\t\twp_id: number;\n\t\t\t/**\n\t\t\t * Plugin that registered the template.\n\t\t\t */\n\t\t\tplugin?: string;\n\t\t\t/**\n\t\t\t * Theme file exists.\n\t\t\t */\n\t\t\thas_theme_file: Record< string, string >;\n\t\t\t/**\n\t\t\t * The ID for the author of the template.\n\t\t\t */\n\t\t\tauthor: number;\n\t\t\t/**\n\t\t\t * Whether a template is a custom template.\n\t\t\t */\n\t\t\tis_custom: Record< string, string >;\n\t\t\t/**\n\t\t\t * The date the template was last modified, in the site's timezone.\n\t\t\t */\n\t\t\tmodified: ContextualField< string, 'view' | 'edit', C >;\n\t\t}\n\t}\n}\n\nexport type WpTemplate< C extends Context = 'edit' > = OmitNevers<\n\t_BaseEntityRecords.WpTemplate< C >\n>;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/fetch/__experimental-fetch-link-suggestions.ts
|
|
29
31
|
var experimental_fetch_link_suggestions_exports = {};
|
|
30
32
|
__export(experimental_fetch_link_suggestions_exports, {
|
|
31
33
|
default: () => fetchLinkSuggestions,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/fetch/__experimental-fetch-link-suggestions.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\nexport type SearchOptions = {\n\t/**\n\t * Displays initial search suggestions, when true.\n\t */\n\tisInitialSuggestions?: boolean;\n\t/**\n\t * Search options for initial suggestions.\n\t */\n\tinitialSuggestionsSearchOptions?: Omit<\n\t\tSearchOptions,\n\t\t'isInitialSuggestions' | 'initialSuggestionsSearchOptions'\n\t>;\n\t/**\n\t * Filters by search type.\n\t */\n\ttype?: 'attachment' | 'post' | 'term' | 'post-format';\n\t/**\n\t * Slug of the post-type or taxonomy.\n\t */\n\tsubtype?: string;\n\t/**\n\t * Which page of results to return.\n\t */\n\tpage?: number;\n\t/**\n\t * Search results per page.\n\t */\n\tperPage?: number;\n};\n\nexport type EditorSettings = {\n\t/**\n\t * Disables post formats, when true.\n\t */\n\tdisablePostFormats?: boolean;\n};\n\ntype SearchAPIResult = {\n\tid: number;\n\ttitle: string;\n\turl: string;\n\ttype: string;\n\tsubtype: string;\n};\n\ntype MediaAPIResult = {\n\tid: number;\n\ttitle: { rendered: string };\n\tsource_url: string;\n\ttype: string;\n};\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\n/**\n * Fetches link suggestions from the WordPress API.\n *\n * WordPress does not support searching multiple tables at once, e.g. posts and terms, so we\n * perform multiple queries at the same time and then merge the results together.\n *\n * @param search\n * @param searchOptions\n * @param editorSettings\n *\n * @example\n * ```js\n * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchLinkSuggestions = (\n * search,\n * searchOptions\n * ) => fetchLinkSuggestions( search, searchOptions, settings );\n * ```\n */\nexport default async function fetchLinkSuggestions(\n\tsearch: string,\n\tsearchOptions: SearchOptions = {},\n\teditorSettings: EditorSettings = {}\n): Promise< SearchResult[] > {\n\tconst searchOptionsToUse =\n\t\tsearchOptions.isInitialSuggestions &&\n\t\tsearchOptions.initialSuggestionsSearchOptions\n\t\t\t? {\n\t\t\t\t\t...searchOptions,\n\t\t\t\t\t...searchOptions.initialSuggestionsSearchOptions,\n\t\t\t }\n\t\t\t: searchOptions;\n\n\tconst {\n\t\ttype,\n\t\tsubtype,\n\t\tpage,\n\t\tperPage = searchOptions.isInitialSuggestions ? 3 : 20,\n\t} = searchOptionsToUse;\n\n\tconst { disablePostFormats = false } = editorSettings;\n\n\tconst queries: Promise< SearchResult[] >[] = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'post-type',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'term' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'term',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'taxonomy',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post-format',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'taxonomy',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< MediaAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.source_url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title.rendered || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.type,\n\t\t\t\t\t\t\tkind: 'media',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tconst responses = await Promise.all( queries );\n\n\tlet results = responses.flat();\n\tresults = results.filter( ( result ) => !! result.id );\n\tresults = sortResults( results, search );\n\tresults = results.slice( 0, perPage );\n\treturn results;\n}\n\n/**\n * Sort search results by relevance to the given query.\n *\n * Sorting is necessary as we're querying multiple endpoints and merging the results. For example\n * a taxonomy title might be more relevant than a post title, but by default taxonomy results will\n * be ordered after all the (potentially irrelevant) post results.\n *\n * We sort by scoring each result, where the score is the number of tokens in the title that are\n * also in the search query, divided by the total number of tokens in the title. This gives us a\n * score between 0 and 1, where 1 is a perfect match.\n *\n * @param results\n * @param search\n */\nexport function sortResults( results: SearchResult[], search: string ) {\n\tconst searchTokens = tokenize( search );\n\n\tconst scores = {};\n\tfor ( const result of results ) {\n\t\tif ( result.title ) {\n\t\t\tconst titleTokens = tokenize( result.title );\n\t\t\tconst exactMatchingTokens = titleTokens.filter( ( titleToken ) =>\n\t\t\t\tsearchTokens.some(\n\t\t\t\t\t( searchToken ) => titleToken === searchToken\n\t\t\t\t)\n\t\t\t);\n\t\t\tconst subMatchingTokens = titleTokens.filter( ( titleToken ) =>\n\t\t\t\tsearchTokens.some(\n\t\t\t\t\t( searchToken ) =>\n\t\t\t\t\t\ttitleToken !== searchToken &&\n\t\t\t\t\t\ttitleToken.includes( searchToken )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// The score is a combination of exact matches and sub-matches.\n\t\t\t// More weight is given to exact matches, as they are more relevant (e.g. \"cat\" vs \"caterpillar\").\n\t\t\t// Diving by the total number of tokens in the title normalizes the score and skews\n\t\t\t// the results towards shorter titles.\n\t\t\tconst exactMatchScore =\n\t\t\t\t( exactMatchingTokens.length / titleTokens.length ) * 10;\n\n\t\t\tconst subMatchScore = subMatchingTokens.length / titleTokens.length;\n\n\t\t\tscores[ result.id ] = exactMatchScore + subMatchScore;\n\t\t} else {\n\t\t\tscores[ result.id ] = 0;\n\t\t}\n\t}\n\n\treturn results.sort( ( a, b ) => scores[ b.id ] - scores[ a.id ] );\n}\n\n/**\n * Turns text into an array of tokens, with whitespace and punctuation removed.\n *\n * For example, `\"I'm having a ball.\"` becomes `[ \"im\", \"having\", \"a\", \"ball\" ]`.\n *\n * @param text\n */\nexport function tokenize( text: string ): string[] {\n\t// \\p{L} matches any kind of letter from any language.\n\t// \\p{N} matches any kind of numeric character.\n\treturn text.toLowerCase().match( /[\\p{L}\\p{N}]+/gu ) || [];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AACrB,iBAA6B;AAC7B,2BAA+B;AAC/B,kBAAmB;AAqGnB,eAAO,qBACN,QACA,gBAA+B,CAAC,GAChC,iBAAiC,CAAC,GACN;AAC5B,QAAM,qBACL,cAAc,wBACd,cAAc,kCACX;AAAA,IACA,GAAG;AAAA,IACH,GAAG,cAAc;AAAA,EACjB,IACA;AAEJ,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,cAAc,uBAAuB,IAAI;AAAA,EACpD,IAAI;AAEJ,QAAM,EAAE,qBAAqB,MAAM,IAAI;AAEvC,QAAM,UAAuC,CAAC;AAE9C,MAAK,CAAE,QAAQ,SAAS,QAAS;AAChC,YAAQ;AAA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B,aAAY,UAAU,SAAU;AAC/B,QAAK,OAAO,OAAQ;AACnB,YAAM,cAAc,SAAU,OAAO,KAAM;AAC3C,YAAM,sBAAsB,YAAY;AAAA,QAAQ,CAAE,eACjD,aAAa;AAAA,UACZ,CAAE,gBAAiB,eAAe;AAAA,QACnC;AAAA,MACD;AACA,YAAM,oBAAoB,YAAY;AAAA,QAAQ,CAAE,eAC/C,aAAa;AAAA,UACZ,CAAE,gBACD,eAAe,eACf,WAAW,SAAU,WAAY;AAAA,QACnC;AAAA,MACD;AAMA,YAAM,kBACH,oBAAoB,SAAS,YAAY,SAAW;AAEvD,YAAM,gBAAgB,kBAAkB,SAAS,YAAY;AAE7D,aAAQ,OAAO,EAAG,IAAI,kBAAkB;AAAA,IACzC,OAAO;AACN,aAAQ,OAAO,EAAG,IAAI;AAAA,IACvB;AAAA,EACD;AAEA,SAAO,QAAQ,KAAM,CAAE,GAAG,MAAO,OAAQ,EAAE,EAAG,IAAI,OAAQ,EAAE,EAAG,CAAE;AAClE;AASO,SAAS,SAAU,MAAyB;AAGlD,SAAO,KAAK,YAAY,EAAE,MAAO,iBAAkB,KAAK,CAAC;AAC1D;",
|
|
6
6
|
"names": ["apiFetch", "results"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/fetch/__experimental-fetch-url-data.js
|
|
29
31
|
var experimental_fetch_url_data_exports = {};
|
|
30
32
|
__export(experimental_fetch_url_data_exports, {
|
|
31
33
|
default: () => experimental_fetch_url_data_default
|
|
@@ -33,8 +35,8 @@ __export(experimental_fetch_url_data_exports, {
|
|
|
33
35
|
module.exports = __toCommonJS(experimental_fetch_url_data_exports);
|
|
34
36
|
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
35
37
|
var import_url = require("@wordpress/url");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
var CACHE = /* @__PURE__ */ new Map();
|
|
39
|
+
var fetchUrlData = async (url, options = {}) => {
|
|
38
40
|
const endpoint = "/wp-block-editor/v1/url-details";
|
|
39
41
|
const args = {
|
|
40
42
|
url: (0, import_url.prependHTTP)(url)
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/fetch/__experimental-fetch-url-data.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\taddQueryArgs,\n\tprependHTTP,\n\tisURL,\n\tgetProtocol,\n\tisValidProtocol,\n} from '@wordpress/url';\n\n/**\n * A simple in-memory cache for requests.\n * This avoids repeat HTTP requests which may be beneficial\n * for those wishing to preserve low-bandwidth.\n */\nconst CACHE = new Map();\n\n/**\n * @typedef WPRemoteUrlData\n *\n * @property {string} title contents of the remote URL's `<title>` tag.\n */\n\n/**\n * Fetches data about a remote URL.\n * eg: <title> tag, favicon...etc.\n *\n * @async\n * @param {string} url the URL to request details from.\n * @param {?Object} options any options to pass to the underlying fetch.\n * @example\n * ```js\n * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchUrlData = (\n * url\n * ) => fetchUrlData( url );\n * ```\n * @return {Promise< WPRemoteUrlData[] >} Remote URL data.\n */\nconst fetchUrlData = async ( url, options = {} ) => {\n\tconst endpoint = '/wp-block-editor/v1/url-details';\n\n\tconst args = {\n\t\turl: prependHTTP( url ),\n\t};\n\n\tif ( ! isURL( url ) ) {\n\t\treturn Promise.reject( `${ url } is not a valid URL.` );\n\t}\n\n\t// Test for \"http\" based URL as it is possible for valid\n\t// yet unusable URLs such as `tel:123456` to be passed.\n\tconst protocol = getProtocol( url );\n\n\tif (\n\t\t! protocol ||\n\t\t! isValidProtocol( protocol ) ||\n\t\t! protocol.startsWith( 'http' ) ||\n\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( url )\n\t) {\n\t\treturn Promise.reject(\n\t\t\t`${ url } does not have a valid protocol. URLs must be \"http\" based`\n\t\t);\n\t}\n\n\tif ( CACHE.has( url ) ) {\n\t\treturn CACHE.get( url );\n\t}\n\n\treturn apiFetch( {\n\t\tpath: addQueryArgs( endpoint, args ),\n\t\t...options,\n\t} ).then( ( res ) => {\n\t\tCACHE.set( url, res );\n\t\treturn res;\n\t} );\n};\n\nexport default fetchUrlData;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AACrB,iBAMO;AAOP,IAAM,QAAQ,oBAAI,IAAI;AA6BtB,IAAM,eAAe,OAAQ,KAAK,UAAU,CAAC,MAAO;AACnD,QAAM,WAAW;AAEjB,QAAM,OAAO;AAAA,IACZ,SAAK,wBAAa,GAAI;AAAA,EACvB;AAEA,MAAK,KAAE,kBAAO,GAAI,GAAI;AACrB,WAAO,QAAQ,OAAQ,GAAI,GAAI,sBAAuB;AAAA,EACvD;AAIA,QAAM,eAAW,wBAAa,GAAI;AAElC,MACC,CAAE,YACF,KAAE,4BAAiB,QAAS,KAC5B,CAAE,SAAS,WAAY,MAAO,KAC9B,CAAE,uBAAuB,KAAM,GAAI,GAClC;AACD,WAAO,QAAQ;AAAA,MACd,GAAI,GAAI;AAAA,IACT;AAAA,EACD;AAEA,MAAK,MAAM,IAAK,GAAI,GAAI;AACvB,WAAO,MAAM,IAAK,GAAI;AAAA,EACvB;AAEA,aAAO,iBAAAA,SAAU;AAAA,IAChB,UAAM,yBAAc,UAAU,IAAK;AAAA,IACnC,GAAG;AAAA,EACJ,CAAE,EAAE,KAAM,CAAE,QAAS;AACpB,UAAM,IAAK,KAAK,GAAI;AACpB,WAAO;AAAA,EACR,CAAE;AACH;AAEA,IAAO,sCAAQ;",
|
|
6
6
|
"names": ["apiFetch"]
|
|
7
7
|
}
|
package/build/fetch/index.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/fetch/index.js
|
|
29
31
|
var fetch_exports = {};
|
|
30
32
|
__export(fetch_exports, {
|
|
31
33
|
__experimentalFetchLinkSuggestions: () => import_experimental_fetch_link_suggestions.default,
|
package/build/fetch/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/fetch/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\nexport { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n\nexport async function fetchBlockPatterns() {\n\tconst restPatterns = await apiFetch( {\n\t\tpath: '/wp/v2/block-patterns/patterns',\n\t} );\n\tif ( ! restPatterns ) {\n\t\treturn [];\n\t}\n\treturn restPatterns.map( ( pattern ) =>\n\t\tObject.fromEntries(\n\t\t\tObject.entries( pattern ).map( ( [ key, value ] ) => [\n\t\t\t\tcamelCase( key ),\n\t\t\t\tvalue,\n\t\t\t] )\n\t\t)\n\t);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAA0B;AAK1B,uBAAqB;AAErB,iDAA8D;AAC9D,yCAAsD;AAEtD,eAAsB,qBAAqB;AAC1C,QAAM,eAAe,UAAM,iBAAAA,SAAU;AAAA,IACpC,MAAM;AAAA,EACP,CAAE;AACF,MAAK,CAAE,cAAe;AACrB,WAAO,CAAC;AAAA,EACT;AACA,SAAO,aAAa;AAAA,IAAK,CAAE,YAC1B,OAAO;AAAA,MACN,OAAO,QAAS,OAAQ,EAAE,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO;AAAA,YACpD,8BAAW,GAAI;AAAA,QACf;AAAA,MACD,CAAE;AAAA,IACH;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["apiFetch"]
|
|
7
7
|
}
|
|
@@ -26,13 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/footnotes/get-footnotes-order.js
|
|
29
31
|
var get_footnotes_order_exports = {};
|
|
30
32
|
__export(get_footnotes_order_exports, {
|
|
31
33
|
default: () => getFootnotesOrder
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(get_footnotes_order_exports);
|
|
34
36
|
var import_get_rich_text_values_cached = __toESM(require("./get-rich-text-values-cached"));
|
|
35
|
-
|
|
37
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
36
38
|
function getBlockFootnotesOrder(block) {
|
|
37
39
|
if (!cache.has(block)) {
|
|
38
40
|
const order = [];
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/footnotes/get-footnotes-order.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport getRichTextValuesCached from './get-rich-text-values-cached';\n\nconst cache = new WeakMap();\n\nfunction getBlockFootnotesOrder( block ) {\n\tif ( ! cache.has( block ) ) {\n\t\tconst order = [];\n\t\tfor ( const value of getRichTextValuesCached( block ) ) {\n\t\t\tif ( ! value ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// replacements is a sparse array, use forEach to skip empty slots.\n\t\t\tvalue.replacements.forEach( ( { type, attributes } ) => {\n\t\t\t\tif ( type === 'core/footnote' ) {\n\t\t\t\t\torder.push( attributes[ 'data-fn' ] );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t\tcache.set( block, order );\n\t}\n\n\treturn cache.get( block );\n}\n\nexport default function getFootnotesOrder( blocks ) {\n\t// We can only separate getting order from blocks at the root level. For\n\t// deeper inner blocks, this will not work since it's possible to have both\n\t// inner blocks and block attributes, so order needs to be computed from the\n\t// Edit functions as a whole.\n\treturn blocks.flatMap( getBlockFootnotesOrder );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yCAAoC;AAEpC,IAAM,QAAQ,oBAAI,QAAQ;AAE1B,SAAS,uBAAwB,OAAQ;AACxC,MAAK,CAAE,MAAM,IAAK,KAAM,GAAI;AAC3B,UAAM,QAAQ,CAAC;AACf,eAAY,aAAS,mCAAAA,SAAyB,KAAM,GAAI;AACvD,UAAK,CAAE,OAAQ;AACd;AAAA,MACD;AAGA,YAAM,aAAa,QAAS,CAAE,EAAE,MAAM,WAAW,MAAO;AACvD,YAAK,SAAS,iBAAkB;AAC/B,gBAAM,KAAM,WAAY,SAAU,CAAE;AAAA,QACrC;AAAA,MACD,CAAE;AAAA,IACH;AACA,UAAM,IAAK,OAAO,KAAM;AAAA,EACzB;AAEA,SAAO,MAAM,IAAK,KAAM;AACzB;AAEe,SAAR,kBAAoC,QAAS;AAKnD,SAAO,OAAO,QAAS,sBAAuB;AAC/C;",
|
|
6
6
|
"names": ["getRichTextValuesCached"]
|
|
7
7
|
}
|
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/core-data/src/footnotes/get-rich-text-values-cached.js
|
|
19
21
|
var get_rich_text_values_cached_exports = {};
|
|
20
22
|
__export(get_rich_text_values_cached_exports, {
|
|
21
23
|
default: () => getRichTextValuesCached
|
|
@@ -23,8 +25,8 @@ __export(get_rich_text_values_cached_exports, {
|
|
|
23
25
|
module.exports = __toCommonJS(get_rich_text_values_cached_exports);
|
|
24
26
|
var import_block_editor = require("@wordpress/block-editor");
|
|
25
27
|
var import_lock_unlock = require("../lock-unlock");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
var unlockedApis;
|
|
29
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
28
30
|
function getRichTextValuesCached(block) {
|
|
29
31
|
if (!unlockedApis) {
|
|
30
32
|
unlockedApis = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/footnotes/get-rich-text-values-cached.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\n// TODO: The following line should have been:\n//\n// const unlockedApis = unlock( blockEditorPrivateApis );\n//\n// But there are hidden circular dependencies in RNMobile code, specifically in\n// certain native components in the `components` package that depend on\n// `block-editor`. What follows is a workaround that defers the `unlock` call\n// to prevent native code from failing.\n//\n// Fix once https://github.com/WordPress/gutenberg/issues/52692 is closed.\nlet unlockedApis;\n\nconst cache = new WeakMap();\n\nexport default function getRichTextValuesCached( block ) {\n\tif ( ! unlockedApis ) {\n\t\tunlockedApis = unlock( blockEditorPrivateApis );\n\t}\n\n\tif ( ! cache.has( block ) ) {\n\t\tconst values = unlockedApis.getRichTextValues( [ block ] );\n\t\tcache.set( block, values );\n\t}\n\treturn cache.get( block );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAsD;AAKtD,yBAAuB;AAYvB,IAAI;AAEJ,IAAM,QAAQ,oBAAI,QAAQ;AAEX,SAAR,wBAA0C,OAAQ;AACxD,MAAK,CAAE,cAAe;AACrB,uBAAe,2BAAQ,oBAAAA,WAAuB;AAAA,EAC/C;AAEA,MAAK,CAAE,MAAM,IAAK,KAAM,GAAI;AAC3B,UAAM,SAAS,aAAa,kBAAmB,CAAE,KAAM,CAAE;AACzD,UAAM,IAAK,OAAO,MAAO;AAAA,EAC1B;AACA,SAAO,MAAM,IAAK,KAAM;AACzB;",
|
|
6
6
|
"names": ["blockEditorPrivateApis"]
|
|
7
7
|
}
|
package/build/footnotes/index.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/footnotes/index.js
|
|
29
31
|
var footnotes_exports = {};
|
|
30
32
|
__export(footnotes_exports, {
|
|
31
33
|
updateFootnotesFromMeta: () => updateFootnotesFromMeta
|
|
@@ -33,7 +35,7 @@ __export(footnotes_exports, {
|
|
|
33
35
|
module.exports = __toCommonJS(footnotes_exports);
|
|
34
36
|
var import_rich_text = require("@wordpress/rich-text");
|
|
35
37
|
var import_get_footnotes_order = __toESM(require("./get-footnotes-order"));
|
|
36
|
-
|
|
38
|
+
var oldFootnotes = {};
|
|
37
39
|
function updateFootnotesFromMeta(blocks, meta) {
|
|
38
40
|
const output = { blocks };
|
|
39
41
|
if (!meta) {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/footnotes/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { RichTextData, create, toHTMLString } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport getFootnotesOrder from './get-footnotes-order';\n\nlet oldFootnotes = {};\n\nexport function updateFootnotesFromMeta( blocks, meta ) {\n\tconst output = { blocks };\n\tif ( ! meta ) {\n\t\treturn output;\n\t}\n\n\t// If meta.footnotes is empty, it means the meta is not registered.\n\tif ( meta.footnotes === undefined ) {\n\t\treturn output;\n\t}\n\n\tconst newOrder = getFootnotesOrder( blocks );\n\n\tconst footnotes = meta.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst currentOrder = footnotes.map( ( fn ) => fn.id );\n\n\tif ( currentOrder.join( '' ) === newOrder.join( '' ) ) {\n\t\treturn output;\n\t}\n\n\tconst newFootnotes = newOrder.map(\n\t\t( fnId ) =>\n\t\t\tfootnotes.find( ( fn ) => fn.id === fnId ) ||\n\t\t\toldFootnotes[ fnId ] || {\n\t\t\t\tid: fnId,\n\t\t\t\tcontent: '',\n\t\t\t}\n\t);\n\n\tfunction updateAttributes( attributes ) {\n\t\t// Only attempt to update attributes, if attributes is an object.\n\t\tif (\n\t\t\t! attributes ||\n\t\t\tArray.isArray( attributes ) ||\n\t\t\ttypeof attributes !== 'object'\n\t\t) {\n\t\t\treturn attributes;\n\t\t}\n\n\t\tattributes = { ...attributes };\n\n\t\tfor ( const key in attributes ) {\n\t\t\tconst value = attributes[ key ];\n\n\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\tattributes[ key ] = value.map( updateAttributes );\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// To do, remove support for string values?\n\t\t\tif (\n\t\t\t\ttypeof value !== 'string' &&\n\t\t\t\t! ( value instanceof RichTextData )\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst richTextValue =\n\t\t\t\ttypeof value === 'string'\n\t\t\t\t\t? RichTextData.fromHTMLString( value )\n\t\t\t\t\t: new RichTextData( value );\n\n\t\t\tlet hasFootnotes = false;\n\n\t\t\trichTextValue.replacements.forEach( ( replacement ) => {\n\t\t\t\tif ( replacement.type === 'core/footnote' ) {\n\t\t\t\t\tconst id = replacement.attributes[ 'data-fn' ];\n\t\t\t\t\tconst index = newOrder.indexOf( id );\n\t\t\t\t\t// The innerHTML contains the count wrapped in a link.\n\t\t\t\t\tconst countValue = create( {\n\t\t\t\t\t\thtml: replacement.innerHTML,\n\t\t\t\t\t} );\n\t\t\t\t\tcountValue.text = String( index + 1 );\n\t\t\t\t\tcountValue.formats = Array.from(\n\t\t\t\t\t\t{ length: countValue.text.length },\n\t\t\t\t\t\t() => countValue.formats[ 0 ]\n\t\t\t\t\t);\n\t\t\t\t\tcountValue.replacements = Array.from(\n\t\t\t\t\t\t{ length: countValue.text.length },\n\t\t\t\t\t\t() => countValue.replacements[ 0 ]\n\t\t\t\t\t);\n\t\t\t\t\treplacement.innerHTML = toHTMLString( {\n\t\t\t\t\t\tvalue: countValue,\n\t\t\t\t\t} );\n\t\t\t\t\thasFootnotes = true;\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\tif ( hasFootnotes ) {\n\t\t\t\tattributes[ key ] =\n\t\t\t\t\ttypeof value === 'string'\n\t\t\t\t\t\t? richTextValue.toHTMLString()\n\t\t\t\t\t\t: richTextValue;\n\t\t\t}\n\t\t}\n\n\t\treturn attributes;\n\t}\n\n\tfunction updateBlocksAttributes( __blocks ) {\n\t\treturn __blocks.map( ( block ) => {\n\t\t\treturn {\n\t\t\t\t...block,\n\t\t\t\tattributes: updateAttributes( block.attributes ),\n\t\t\t\tinnerBlocks: updateBlocksAttributes( block.innerBlocks ),\n\t\t\t};\n\t\t} );\n\t}\n\n\t// We need to go through all block attributes deeply and update the\n\t// footnote anchor numbering (textContent) to match the new order.\n\tconst newBlocks = updateBlocksAttributes( blocks );\n\n\toldFootnotes = {\n\t\t...oldFootnotes,\n\t\t...footnotes.reduce( ( acc, fn ) => {\n\t\t\tif ( ! newOrder.includ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Q;AACnC,UAAK,CAAE,SAAS,SAAU,GAAG,EAAG,GAAI;AACnC,YAAK,GAAG,EAAG,IAAI;AAAA,MAChB;AACA,aAAO;AAAA,IACR,GAAG,CAAC,CAAE;AAAA,EACP;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,MACL,GAAG;AAAA,MACH,WAAW,KAAK,UAAW,YAAa;AAAA,IACzC;AAAA,IACA,QAAQ;AAAA,EACT;AACD;",
|
|
6
6
|
"names": ["getFootnotesOrder"]
|
|
7
7
|
}
|
package/build/hooks/constants.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/core-data/src/hooks/constants.ts
|
|
19
21
|
var constants_exports = {};
|
|
20
22
|
__export(constants_exports, {
|
|
21
23
|
Status: () => Status
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/constants.ts"],
|
|
4
4
|
"sourcesContent": ["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAW,SAAX,kBAAWA,YAAX;AACN,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,eAAY;AACZ,EAAAA,QAAA,WAAQ;AACR,EAAAA,QAAA,aAAU;AAJO,SAAAA;AAAA,GAAA;",
|
|
6
6
|
"names": ["Status"]
|
|
7
7
|
}
|
package/build/hooks/index.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/index.ts
|
|
29
31
|
var hooks_exports = {};
|
|
30
32
|
__export(hooks_exports, {
|
|
31
33
|
__experimentalUseEntityRecord: () => import_use_entity_record.__experimentalUseEntityRecord,
|
package/build/hooks/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/index.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { WithPermissions } from './use-entity-records';\n\n/**\n * Utility type that adds permissions to any record type.\n */\nexport type { WithPermissions };\nexport {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\nexport {\n\tdefault as useResourcePermissions,\n\t__experimentalUseResourcePermissions,\n} from './use-resource-permissions';\nexport { default as useEntityBlockEditor } from './use-entity-block-editor';\nexport { default as useEntityId } from './use-entity-id';\nexport { default as useEntityProp } from './use-entity-prop';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,+BAGO;AACP,gCAGO;AACP,sCAGO;AACP,qCAAgD;AAChD,2BAAuC;AACvC,6BAAyC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/hooks/memoize.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/memoize.js
|
|
29
31
|
var memoize_exports = {};
|
|
30
32
|
__export(memoize_exports, {
|
|
31
33
|
default: () => memoize_default
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/memoize.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n// re-export due to restrictive esModuleInterop setting\nexport default memoize;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAoB;AAGpB,IAAO,kBAAQ,cAAAA;",
|
|
6
6
|
"names": ["memoize"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/use-entity-block-editor.js
|
|
29
31
|
var use_entity_block_editor_exports = {};
|
|
30
32
|
__export(use_entity_block_editor_exports, {
|
|
31
33
|
default: () => useEntityBlockEditor
|
|
@@ -37,8 +39,8 @@ var import_blocks = require("@wordpress/blocks");
|
|
|
37
39
|
var import_name = require("../name");
|
|
38
40
|
var import_use_entity_id = __toESM(require("./use-entity-id"));
|
|
39
41
|
var import_footnotes = require("../footnotes");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
var EMPTY_ARRAY = [];
|
|
43
|
+
var parsedBlocksCache = /* @__PURE__ */ new WeakMap();
|
|
42
44
|
function useEntityBlockEditor(kind, name, { id: _id } = {}) {
|
|
43
45
|
const providerId = (0, import_use_entity_id.default)(kind, name);
|
|
44
46
|
const id = _id ?? providerId;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-entity-block-editor.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\nimport { updateFootnotesFromMeta } from '../footnotes';\n\nconst EMPTY_ARRAY = [];\nconst parsedBlocksCache = new WeakMap();\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[unknown[], Function, Function]} The block array and setters.\n */\nexport default function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME );\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( ! id ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\tif ( ! content || typeof content !== 'string' ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\t// If there's an edit, cache the parsed blocks by the edit.\n\t\t// If not, cache by the original entity record.\n\t\tconst edits = getEntityRecordEdits( kind, name, id );\n\t\tconst isUnedited = ! edits || ! Object.keys( edits ).length;\n\t\tconst cackeKey = isUnedited ? getEntityRecord( kind, name, id ) : edits;\n\t\tlet _blocks = parsedBlocksCache.get( cackeKey );\n\n\t\tif ( ! _blocks ) {\n\t\t\t_blocks = parse( content );\n\t\t\tparsedBlocksCache.set( cackeKey, _blocks );\n\t\t}\n\n\t\treturn _blocks;\n\t}, [\n\t\tkind,\n\t\tname,\n\t\tid,\n\t\teditedBlocks,\n\t\tcontent,\n\t\tgetEntityRecord,\n\t\tgetEntityRecordEdits,\n\t] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection, ...rest } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotesFromMeta( newBlocks, meta ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: false,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tmeta,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection, ...rest } = options;\n\t\t\tconst footnotesChanges = updateFootnotesFromMeta( newBlocks, meta );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: true,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, meta, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAqC;AACrC,kBAAuC;AACvC,oBAAmD;AAKnD,kBAA2B;AAC3B,2BAAwB;AACxB,uBAAwC;AAExC,IAAM,cAAc,CAAC;AACrB,IAAM,oBAAoB,oBAAI,QAAQ;AAoBvB,SAAR,qBAAuC,MAAM,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,GAAI;AAC5E,QAAM,iBAAa,qBAAAA,SAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OAAO;AAClB,QAAM,EAAE,iBAAiB,qBAAqB,QAAI,uBAAW,sBAAW;AACxE,QAAM,EAAE,SAAS,cAAc,KAAK,QAAI;AAAA,IACvC,CAAE,WAAY;AACb,UAAK,CAAE,IAAK;AACX,eAAO,CAAC;AAAA,MACT;AACA,YAAM,EAAE,sBAAsB,IAAI,OAAQ,sBAAW;AACrD,YAAM,eAAe,sBAAuB,MAAM,MAAM,EAAG;AAC3D,aAAO;AAAA,QACN,cAAc,aAAa;AAAA,QAC3B,SAAS,aAAa;AAAA,QACtB,MAAM,aAAa;AAAA,MACpB;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,EAAG;AAAA,EAClB;AACA,QAAM,EAAE,2BAA2B,iBAAiB,QACnD,yBAAa,sBAAW;AAEzB,QAAM,aAAS,wBAAS,MAAM;AAC7B,QAAK,CAAE,IAAK;AACX,aAAO;AAAA,IACR;AAEA,QAAK,cAAe;A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,iBAAiB;AAE/C,uBAAkB,MAAM,MAAM,IAAI,OAAO;AAAA,QACxC,UAAU;AAAA,QACV,GAAG;AAAA,MACJ,CAAE;AAAA,IACH;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,MAAM,gBAAiB;AAAA,EAC1C;AAEA,SAAO,CAAE,QAAQ,SAAS,QAAS;AACpC;",
|
|
6
6
|
"names": ["useEntityId"]
|
|
7
7
|
}
|
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/core-data/src/hooks/use-entity-id.js
|
|
19
21
|
var use_entity_id_exports = {};
|
|
20
22
|
__export(use_entity_id_exports, {
|
|
21
23
|
default: () => useEntityId
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-entity-id.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { EntityContext } from '../entity-context';\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport default function useEntityId( kind, name ) {\n\tconst context = useContext( EntityContext );\n\treturn context?.[ kind ]?.[ name ];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2B;AAK3B,4BAA8B;AASf,SAAR,YAA8B,MAAM,MAAO;AACjD,QAAM,cAAU,2BAAY,mCAAc;AAC1C,SAAO,UAAW,IAAK,IAAK,IAAK;AAClC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/use-entity-prop.js
|
|
29
31
|
var use_entity_prop_exports = {};
|
|
30
32
|
__export(use_entity_prop_exports, {
|
|
31
33
|
default: () => useEntityProp
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-entity-prop.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA4B;AAC5B,kBAAuC;AAKvC,kBAA2B;AAC3B,2BAAwB;AAmBT,SAAR,cAAgC,MAAM,MAAM,MAAM,KAAM;AAC9D,QAAM,iBAAa,qBAAAA,SAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OAAO;AAElB,QAAM,EAAE,OAAO,UAAU,QAAI;AAAA,IAC5B,CAAE,WAAY;AACb,YAAM,EAAE,iBAAiB,sBAAsB,IAC9C,OAAQ,sBAAW;AACpB,YAAM,SAAS,gBAAiB,MAAM,MAAM,EAAG;AAC/C,YAAM,eAAe,sBAAuB,MAAM,MAAM,EAAG;AAC3D,aAAO,UAAU,eACd;AAAA,QACA,OAAO,aAAc,IAAK;AAAA,QAC1B,WAAW,OAAQ,IAAK;AAAA,MACxB,IACA,CAAC;AAAA,IACL;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,IAAK;AAAA,EACxB;AACA,QAAM,EAAE,iBAAiB,QAAI,yBAAa,sBAAW;AACrD,QAAM,eAAW;AAAA,IAChB,CAAE,aAAc;AACf,uBAAkB,MAAM,MAAM,IAAI;AAAA,QACjC,CAAE,IAAK,GAAG;AAAA,MACX,CAAE;AAAA,IACH;AAAA,IACA,CAAE,kBAAkB,MAAM,MAAM,IAAI,IAAK;AAAA,EAC1C;AAEA,SAAO,CAAE,OAAO,UAAU,SAAU;AACrC;",
|
|
6
6
|
"names": ["useEntityId"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/use-entity-record.ts
|
|
29
31
|
var use_entity_record_exports = {};
|
|
30
32
|
__export(use_entity_record_exports, {
|
|
31
33
|
__experimentalUseEntityRecord: () => __experimentalUseEntityRecord,
|
|
@@ -37,7 +39,7 @@ var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
|
37
39
|
var import_element = require("@wordpress/element");
|
|
38
40
|
var import_use_query_select = __toESM(require("./use-query-select"));
|
|
39
41
|
var import__ = require("../");
|
|
40
|
-
|
|
42
|
+
var EMPTY_OBJECT = {};
|
|
41
43
|
function useEntityRecord(kind, name, recordId, options = { enabled: true }) {
|
|
42
44
|
const { editEntityRecord, saveEditedEntityRecord } = (0, import_data.useDispatch)(import__.store);
|
|
43
45
|
const mutations = (0, import_element.useMemo)(
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-entity-record.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** The edits to the edited entity record */\n\tedits: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useCallback } from 'react';\n * import { useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n *\t\t\t\t__nextHasNoMarginBottom\n *\t\t\t\t__next40pxDefaultSize\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\teditedRecord: EMPTY_OBJECT,\n\t\t\t\t\thasEdits: false,\n\t\t\t\t\tedits: EMPTY_OBJECT,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\tedits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuC;AACvC,wBAAuB;AACvB,qBAAwB;AAKxB,8BAA2B;AAC3B,eAAmC;AA+CnC,IAAM,eAAe,CAAC;AA4FP,SAAR,gBACN,MAC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AE,MAAM,MAAM,UAAU,QAAQ,OAAQ;AAAA,EACzC;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACD;AAEO,SAAS,8BACf,MACA,MACA,UACA,SACC;AACD,wBAAAG,SAAY,yCAAyC;AAAA,IACpD,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,gBAAiB,MAAM,MAAM,UAAU,OAAQ;AACvD;",
|
|
6
6
|
"names": ["coreStore", "record", "useQuerySelect", "deprecated"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/use-entity-records.ts
|
|
29
31
|
var use_entity_records_exports = {};
|
|
30
32
|
__export(use_entity_records_exports, {
|
|
31
33
|
__experimentalUseEntityRecords: () => __experimentalUseEntityRecords,
|
|
@@ -41,7 +43,7 @@ var import_use_query_select = __toESM(require("./use-query-select"));
|
|
|
41
43
|
var import__ = require("../");
|
|
42
44
|
var import_lock_unlock = require("../lock-unlock");
|
|
43
45
|
var import_utils = require("../utils");
|
|
44
|
-
|
|
46
|
+
var EMPTY_ARRAY = [];
|
|
45
47
|
function useEntityRecords(kind, name, queryArgs = {}, options = { enabled: true }) {
|
|
46
48
|
const queryAsString = (0, import_url.addQueryArgs)("", queryArgs);
|
|
47
49
|
const { data: records, ...rest } = (0, import_use_query_select.default)(
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-entity-records.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options } from './use-entity-record';\nimport type { Status } from './constants';\nimport { unlock } from '../lock-unlock';\nimport { getNormalizedCommaSeparable } from '../utils';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity records */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n\n\t/**\n\t * The total number of available items (if not paginated).\n\t */\n\ttotalItems: number | null;\n\n\t/**\n\t * The total number of pages.\n\t */\n\ttotalPages: number | null;\n}\n\nexport type WithPermissions< RecordType > = RecordType & {\n\tpermissions: { delete: boolean; update: boolean };\n};\n\ninterface EntityRecordsWithPermissionsResolution< RecordType >\n\textends Omit< EntityRecordsResolution< RecordType >, 'records' > {\n\t/** The requested entity records with permissions */\n\trecords: WithPermissions< RecordType >[] | null;\n}\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecords } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\tconst { totalItems, totalPages } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\ttotalItems: null,\n\t\t\t\t\ttotalPages: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttotalItems: select( coreStore ).getEntityRecordsTotalItems(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t\ttotalPages: select( coreStore ).getEntityRecordsTotalPages(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\ttotalItems,\n\t\ttotalPages,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n\nexport function useEntityRecordsWithPermissions< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsWithPermissionsResolution< RecordType > {\n\tconst entityConfig = useSelect(\n\t\t( select ) => select( coreStore ).getEntityConfig( kind, name ),\n\t\t[ kind, name ]\n\t);\n\tconst { records: data, ...ret } = useEntityRecords(\n\t\tkind,\n\t\tname,\n\t\t{\n\t\t\t...queryArgs,\n\t\t\t// If _fields is provided, we need to include _links in the request for permission caching to work.\n\t\t\t...( queryArgs._fields\n\t\t\t\t? {\n\t\t\t\t\t\t_fields: [\n\t\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t\t...( getNormalizedCommaSeparable(\n\t\t\t\t\t\t\t\t\tqueryArgs._fields\n\t\t\t\t\t\t\t\t) || [] ),\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t] ),\n\t\t\t\t\t\t].join(),\n\t\t\t\t }\n\t\t\t\t: {} ),\n\t\t},\n\t\toptions\n\t);\n\tconst ids = useMemo(\n\t\t() =>\n\t\t\tdata?.map(\n\t\t\t\t// @ts-ignore\n\t\t\t\t( record: RecordType ) => record[ entityConfig?.key ?? 'id' ]\n\t\t\t) ?? [],\n\t\t[ data, entityConfig?.key ]\n\t);\n\n\tconst permissions = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecordsPermissions } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\t\t\treturn getEntityRecordsPermissions( kind, name, ids );\n\t\t},\n\t\t[ ids, kind, name ]\n\t);\n\n\tconst dataWithPermissions = useMemo(\n\t\t() =>\n\t\t\tdata?.map( ( record, index ) => ( {\n\t\t\t\t// @ts-ignore\n\t\t\t\t...record,\n\t\t\t\tpermissions: permissions[ index ],\n\t\t\t} ) ) ?? [],\n\t\t[ data, permissions ]\n\t);\n\n\treturn { records: dataWithPermissions, ...ret };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA6B;AAC7B,wBAAuB;AACvB,kBAA0B;AAC1B,qBAAwB;AAKxB,8BAA2B;AAC3B,eAAmC;AAGnC,yBAAuB;AACvB,mBAA4C;AAwC5C,IAAM,cAAc,CAAC;AA0CN,SAAR,iBACN,MACA,MACA,YAAuC,CAAC,GACxC,UAAmB,EAAE,SAAS,KAAK,GACK;AAKxC,QAAM,oBAAgB,yBAAc,IAAI,SAAU;AAElD,QAAM,EAAE,MAAM,SAAS,GAAG,KAAK,QAAI,wBAAAA;AAAA,IAClC,CAAE,UAAW;AACZ,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO;AAAA;AAAA,UAEN,MAAM;AAAA,QACP;AAAA,MACD;AACA,aAAO,MAAO,SAAAC,KAAU,EAAE,iBAAkB,MAAM,MAAM,SAAU;AAAA,IACnE;AAAA,IACA,CAAE,MAAM,MAAM,eAAe,QAAQ,OAAQ;AAAA,EAC9C;AAEA,QAAM,EAAE,YAAY,WAAW,QAAI;AAAA,IAClC,CAAE,WAAY;AACb,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO;AAAA,UACN,YAAY;AAAA,UACZ,YAAY;AAAA,QACb;AAAA,MACD;AACA,aAAO;AAAA,QACN,YAAY,OAAQ,SAAAA,KAAU,EAAE;AAAA,UAC/B;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,QACA,YAAY,OAAQ,SAAAA,KAAU,EAAE;AAAA,UAC/B;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,eAAe,QAAQ,OAA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,MACC,MAAM,IAAK,CAAE,QAAQ,WAAa;AAAA;AAAA,MAEjC,GAAG;AAAA,MACH,aAAa,YAAa,KAAM;AAAA,IACjC,EAAI,KAAK,CAAC;AAAA,IACX,CAAE,MAAM,WAAY;AAAA,EACrB;AAEA,SAAO,EAAE,SAAS,qBAAqB,GAAG,IAAI;AAC/C;",
|
|
6
6
|
"names": ["useQuerySelect", "coreStore", "deprecated"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/use-query-select.ts
|
|
29
31
|
var use_query_select_exports = {};
|
|
30
32
|
__export(use_query_select_exports, {
|
|
31
33
|
META_SELECTORS: () => META_SELECTORS,
|
|
@@ -35,7 +37,7 @@ module.exports = __toCommonJS(use_query_select_exports);
|
|
|
35
37
|
var import_data = require("@wordpress/data");
|
|
36
38
|
var import_memoize = __toESM(require("./memoize"));
|
|
37
39
|
var import_constants = require("./constants");
|
|
38
|
-
|
|
40
|
+
var META_SELECTORS = [
|
|
39
41
|
"getIsResolving",
|
|
40
42
|
"hasStartedResolution",
|
|
41
43
|
"hasFinishedResolution",
|
|
@@ -48,7 +50,7 @@ function useQuerySelect(mapQuerySelect, deps) {
|
|
|
48
50
|
return mapQuerySelect(resolve, registry);
|
|
49
51
|
}, deps);
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
var enrichSelectors = (0, import_memoize.default)(((selectors) => {
|
|
52
54
|
const resolvers = {};
|
|
53
55
|
for (const selectorName in selectors) {
|
|
54
56
|
if (META_SELECTORS.includes(selectorName)) {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-query-select.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `isResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @since 6.1.0 Introduced in WordPress core.\n * @private\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function useQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\t\t\t\t\tconst resolutionStatus = selectors.getResolutionState(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)?.status;\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tswitch ( resolutionStatus ) {\n\t\t\t\t\t\tcase 'resolving':\n\t\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'finished':\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'error':\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving: status === Status.Resolving,\n\t\t\t\t\t\thasStarted: status !== Status.Idle,\n\t\t\t\t\t\thasResolved:\n\t\t\t\t\t\t\tstatus === Status.Success ||\n\t\t\t\t\t\t\tstatus === Status.Error,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAK1B,qBAAoB;AACpB,uBAAuB;AAEhB,IAAM,iBAAiB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AA2De,SAAR,eAAiC,gBAAgB,MAAO;AAC9D,aAAO,uBAAW,CAAE,QAAQ,aAAc;AACzC,UAAM,UAAU,CAAE,UAAW,gBAAiB,OAAQ,KAAM,CAAE;AAC9D,WAAO,eAAgB,SAAS,QAAS;AAAA,EAC1C,GAAG,IAAK;AACT;AAmBA,IAAM,sBAAkB,eAAAA,UAAW,CAAE,cAAe;AACnD,QAAM,YAAY,CAAC;AACnB,aAAY,gBAAgB,WAAY;AACvC,QAAK,eAAe,SAAU,YAAa,GAAI;AAC9C;AAAA,IACD;AACA,WAAO,eAAgB,WAAW,cAAc;AAAA,MAC/C,KACC,MACA,IAAK,SAAqB;AACzB,cAAM,OAAO,UAAW,YAAa,EAAG,GAAG,IAAK;AAChD,cAAM,mBAAmB,UAAU;AAAA,UAClC;AAAA,UACA;AAAA,QACD,GAAG;AAEH,YAAI;AACJ,gBAAS,kBAAmB;AAAA,UAC3B,KAAK;AACJ,qBAAS,wBAAO;AAChB;AAAA,UACD,KAAK;AACJ,qBAAS,wBAAO;AAChB;AAAA,UACD,KAAK;AACJ,qBAAS,wBAAO;AAChB;AAAA,UACD,KAAK;AACJ,qBAAS,wBAAO;AAChB;AAAA,QACF;AAEA,eAAO;AAAA,UACN;AAAA,UACA;AAAA,UACA,aAAa,WAAW,wBAAO;AAAA,UAC/B,YAAY,WAAW,wBAAO;AAAA,UAC9B,aACC,WAAW,wBAAO,WAClB,WAAW,wBAAO;AAAA,QACpB;AAAA,MACD;AAAA,IACF,CAAE;AAAA,EACH;AACA,SAAO;AACR,EAAyB;",
|
|
6
6
|
"names": ["memoize"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/core-data/src/hooks/use-resource-permissions.ts
|
|
29
31
|
var use_resource_permissions_exports = {};
|
|
30
32
|
__export(use_resource_permissions_exports, {
|
|
31
33
|
__experimentalUseResourcePermissions: () => __experimentalUseResourcePermissions,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-resource-permissions.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} ),\n];\n\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,qBAAoB;AAKpB,eAAmC;AACnC,uBAAuB;AACvB,8BAA2B;AAmH3B,SAAS,uBACR,UACA,IAC0C;AAK1C,QAAM,WAAW,OAAO,aAAa;AACrC,QAAM,mBAAmB,WAAW,KAAK,UAAW,QAAS,IAAI;AAEjE,MAAK,YAAY,OAAO,OAAO,aAAc;AAC5C,uBAAAA;AAAA,MACC;AAAA,IACD;AAAA,EACD;AAEA,aAAO,wBAAAC;AAAA,IACN,CAAE,YAAa;AACd,YAAM,QAAQ,WAAW,CAAC,CAAE,SAAS,KAAK,CAAC,CAAE;AAC7C,YAAM,EAAE,QAAQ,IAAI,QAAS,SAAAC,KAAU;AACvC,YAAM,SAAS;AAAA,QACd;AAAA,QACA,WACG,EAAE,MAAM,SAAS,MAAM,MAAM,SAAS,KAAK,IAC3C;AAAA,MACJ;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ySelect", "coreStore", "read", "isResolving", "hasResolved", "status", "deprecated"]
|
|
7
7
|
}
|