@wordpress/core-data 7.32.0 → 7.32.1-next.ff1cebbba.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 +375 -632
- package/build/actions.js.map +7 -1
- package/build/batch/create-batch.js +49 -62
- package/build/batch/create-batch.js.map +7 -1
- package/build/batch/default-processor.js +43 -39
- package/build/batch/default-processor.js.map +7 -1
- package/build/batch/index.js +38 -17
- package/build/batch/index.js.map +7 -1
- package/build/dynamic-entities.js +30 -32
- package/build/dynamic-entities.js.map +7 -1
- package/build/entities.js +298 -410
- package/build/entities.js.map +7 -1
- package/build/entity-context.js +29 -12
- package/build/entity-context.js.map +7 -1
- package/build/entity-provider.js +38 -46
- package/build/entity-provider.js.map +7 -1
- package/build/entity-types/attachment.js +16 -5
- package/build/entity-types/attachment.js.map +7 -1
- package/build/entity-types/base-entity-records.js +16 -42
- package/build/entity-types/base-entity-records.js.map +7 -1
- package/build/entity-types/base.js +16 -5
- package/build/entity-types/base.js.map +7 -1
- package/build/entity-types/comment.js +16 -5
- package/build/entity-types/comment.js.map +7 -1
- package/build/entity-types/global-styles-revision.js +16 -5
- package/build/entity-types/global-styles-revision.js.map +7 -1
- package/build/entity-types/helpers.js +16 -5
- package/build/entity-types/helpers.js.map +7 -1
- package/build/entity-types/index.js +16 -5
- package/build/entity-types/index.js.map +7 -1
- package/build/entity-types/menu-location.js +16 -5
- package/build/entity-types/menu-location.js.map +7 -1
- package/build/entity-types/nav-menu-item.js +16 -5
- package/build/entity-types/nav-menu-item.js.map +7 -1
- package/build/entity-types/nav-menu.js +16 -5
- package/build/entity-types/nav-menu.js.map +7 -1
- package/build/entity-types/page.js +16 -5
- package/build/entity-types/page.js.map +7 -1
- package/build/entity-types/plugin.js +16 -5
- package/build/entity-types/plugin.js.map +7 -1
- package/build/entity-types/post-revision.js +16 -5
- package/build/entity-types/post-revision.js.map +7 -1
- package/build/entity-types/post-status.js +16 -5
- package/build/entity-types/post-status.js.map +7 -1
- package/build/entity-types/post.js +16 -5
- package/build/entity-types/post.js.map +7 -1
- package/build/entity-types/settings.js +16 -5
- package/build/entity-types/settings.js.map +7 -1
- package/build/entity-types/sidebar.js +16 -5
- package/build/entity-types/sidebar.js.map +7 -1
- package/build/entity-types/taxonomy.js +16 -5
- package/build/entity-types/taxonomy.js.map +7 -1
- package/build/entity-types/term.js +16 -5
- package/build/entity-types/term.js.map +7 -1
- package/build/entity-types/theme.js +16 -5
- package/build/entity-types/theme.js.map +7 -1
- package/build/entity-types/type.js +16 -5
- package/build/entity-types/type.js.map +7 -1
- package/build/entity-types/user.js +16 -5
- package/build/entity-types/user.js.map +7 -1
- package/build/entity-types/widget-type.js +16 -5
- package/build/entity-types/widget-type.js.map +7 -1
- package/build/entity-types/widget.js +16 -5
- package/build/entity-types/widget.js.map +7 -1
- package/build/entity-types/wp-template-part.js +16 -5
- package/build/entity-types/wp-template-part.js.map +7 -1
- package/build/entity-types/wp-template.js +16 -5
- package/build/entity-types/wp-template.js.map +7 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +141 -154
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build/fetch/__experimental-fetch-url-data.js +47 -59
- package/build/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build/fetch/index.js +53 -32
- package/build/fetch/index.js.map +7 -1
- package/build/footnotes/get-footnotes-order.js +38 -25
- package/build/footnotes/get-footnotes-order.js.map +7 -1
- package/build/footnotes/get-rich-text-values-cached.js +26 -27
- package/build/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build/footnotes/index.js +68 -55
- package/build/footnotes/index.js.map +7 -1
- package/build/hooks/constants.js +33 -12
- package/build/hooks/constants.js.map +7 -1
- package/build/hooks/index.js +59 -68
- package/build/hooks/index.js.map +7 -1
- package/build/hooks/memoize.js +34 -12
- package/build/hooks/memoize.js.map +7 -1
- package/build/hooks/use-entity-block-editor.js +111 -119
- package/build/hooks/use-entity-block-editor.js.map +7 -1
- package/build/hooks/use-entity-id.js +25 -23
- package/build/hooks/use-entity-id.js.map +7 -1
- package/build/hooks/use-entity-prop.js +59 -60
- package/build/hooks/use-entity-prop.js.map +7 -1
- package/build/hooks/use-entity-record.js +95 -155
- package/build/hooks/use-entity-record.js.map +7 -1
- package/build/hooks/use-entity-records.js +131 -139
- package/build/hooks/use-entity-records.js.map +7 -1
- package/build/hooks/use-query-select.js +65 -84
- package/build/hooks/use-query-select.js.map +7 -1
- package/build/hooks/use-resource-permissions.js +92 -145
- package/build/hooks/use-resource-permissions.js.map +7 -1
- package/build/index.js +96 -153
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/locks/actions.js +36 -19
- package/build/locks/actions.js.map +7 -1
- package/build/locks/engine.js +48 -47
- package/build/locks/engine.js.map +7 -1
- package/build/locks/reducer.js +54 -63
- package/build/locks/reducer.js.map +7 -1
- package/build/locks/selectors.js +35 -30
- package/build/locks/selectors.js.map +7 -1
- package/build/locks/utils.js +37 -16
- package/build/locks/utils.js.map +7 -1
- package/build/name.js +27 -12
- package/build/name.js.map +7 -1
- package/build/private-actions.js +67 -75
- package/build/private-actions.js.map +7 -1
- package/build/private-apis.js +33 -16
- package/build/private-apis.js.map +7 -1
- package/build/private-selectors.js +204 -184
- package/build/private-selectors.js.map +7 -1
- package/build/queried-data/actions.js +32 -41
- package/build/queried-data/actions.js.map +7 -1
- package/build/queried-data/get-query-parts.js +41 -79
- package/build/queried-data/get-query-parts.js.map +7 -1
- package/build/queried-data/index.js +39 -36
- package/build/queried-data/index.js.map +7 -1
- package/build/queried-data/reducer.js +162 -193
- package/build/queried-data/reducer.js.map +7 -1
- package/build/queried-data/selectors.js +57 -85
- package/build/queried-data/selectors.js.map +7 -1
- package/build/reducer.js +279 -404
- package/build/reducer.js.map +7 -1
- package/build/resolvers.js +553 -600
- package/build/resolvers.js.map +7 -1
- package/build/selectors.js +456 -981
- package/build/selectors.js.map +7 -1
- package/build/sync.js +34 -22
- package/build/sync.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/conservative-map-item.js +34 -27
- package/build/utils/conservative-map-item.js.map +7 -1
- package/build/utils/crdt-blocks.js +289 -0
- package/build/utils/crdt-blocks.js.map +7 -0
- package/build/utils/crdt.js +202 -0
- package/build/utils/crdt.js.map +7 -0
- package/build/utils/forward-resolver.js +24 -16
- package/build/utils/forward-resolver.js.map +7 -1
- package/build/utils/get-nested-value.js +26 -21
- package/build/utils/get-nested-value.js.map +7 -1
- package/build/utils/get-normalized-comma-separable.js +25 -17
- package/build/utils/get-normalized-comma-separable.js.map +7 -1
- package/build/utils/if-matching-action.js +25 -19
- package/build/utils/if-matching-action.js.map +7 -1
- package/build/utils/index.js +77 -108
- package/build/utils/index.js.map +7 -1
- package/build/utils/is-numeric-id.js +22 -12
- package/build/utils/is-numeric-id.js.map +7 -1
- package/build/utils/is-raw-attribute.js +22 -13
- package/build/utils/is-raw-attribute.js.map +7 -1
- package/build/utils/log-entity-deprecation.js +37 -38
- package/build/utils/log-entity-deprecation.js.map +7 -1
- package/build/utils/on-sub-key.js +30 -24
- package/build/utils/on-sub-key.js.map +7 -1
- package/build/utils/receive-intermediate-results.js +29 -6
- package/build/utils/receive-intermediate-results.js.map +7 -1
- package/build/utils/replace-action.js +24 -17
- package/build/utils/replace-action.js.map +7 -1
- package/build/utils/set-nested-value.js +25 -30
- package/build/utils/set-nested-value.js.map +7 -1
- package/build/utils/user-permissions.js +41 -13
- package/build/utils/user-permissions.js.map +7 -1
- package/build/utils/with-weak-map-cache.js +26 -22
- package/build/utils/with-weak-map-cache.js.map +7 -1
- package/build-module/actions.js +322 -601
- package/build-module/actions.js.map +7 -1
- package/build-module/batch/create-batch.js +21 -57
- package/build-module/batch/create-batch.js.map +7 -1
- package/build-module/batch/default-processor.js +14 -33
- package/build-module/batch/default-processor.js.map +7 -1
- package/build-module/batch/index.js +7 -3
- package/build-module/batch/index.js.map +7 -1
- package/build-module/dynamic-entities.js +7 -28
- package/build-module/dynamic-entities.js.map +7 -1
- package/build-module/entities.js +263 -399
- package/build-module/entities.js.map +7 -1
- package/build-module/entity-context.js +7 -7
- package/build-module/entity-context.js.map +7 -1
- package/build-module/entity-provider.js +19 -42
- package/build-module/entity-provider.js.map +7 -1
- package/build-module/entity-types/attachment.js +1 -2
- package/build-module/entity-types/attachment.js.map +7 -1
- package/build-module/entity-types/base-entity-records.js +1 -37
- package/build-module/entity-types/base-entity-records.js.map +7 -1
- package/build-module/entity-types/base.js +1 -2
- package/build-module/entity-types/base.js.map +7 -1
- package/build-module/entity-types/comment.js +1 -2
- package/build-module/entity-types/comment.js.map +7 -1
- package/build-module/entity-types/global-styles-revision.js +1 -2
- package/build-module/entity-types/global-styles-revision.js.map +7 -1
- package/build-module/entity-types/helpers.js +1 -2
- package/build-module/entity-types/helpers.js.map +7 -1
- package/build-module/entity-types/index.js +1 -2
- package/build-module/entity-types/index.js.map +7 -1
- package/build-module/entity-types/menu-location.js +1 -2
- package/build-module/entity-types/menu-location.js.map +7 -1
- package/build-module/entity-types/nav-menu-item.js +1 -2
- package/build-module/entity-types/nav-menu-item.js.map +7 -1
- package/build-module/entity-types/nav-menu.js +1 -2
- package/build-module/entity-types/nav-menu.js.map +7 -1
- package/build-module/entity-types/page.js +1 -2
- package/build-module/entity-types/page.js.map +7 -1
- package/build-module/entity-types/plugin.js +1 -2
- package/build-module/entity-types/plugin.js.map +7 -1
- package/build-module/entity-types/post-revision.js +1 -2
- package/build-module/entity-types/post-revision.js.map +7 -1
- package/build-module/entity-types/post-status.js +1 -2
- package/build-module/entity-types/post-status.js.map +7 -1
- package/build-module/entity-types/post.js +1 -2
- package/build-module/entity-types/post.js.map +7 -1
- package/build-module/entity-types/settings.js +1 -2
- package/build-module/entity-types/settings.js.map +7 -1
- package/build-module/entity-types/sidebar.js +1 -2
- package/build-module/entity-types/sidebar.js.map +7 -1
- package/build-module/entity-types/taxonomy.js +1 -2
- package/build-module/entity-types/taxonomy.js.map +7 -1
- package/build-module/entity-types/term.js +1 -2
- package/build-module/entity-types/term.js.map +7 -1
- package/build-module/entity-types/theme.js +1 -2
- package/build-module/entity-types/theme.js.map +7 -1
- package/build-module/entity-types/type.js +1 -2
- package/build-module/entity-types/type.js.map +7 -1
- package/build-module/entity-types/user.js +1 -2
- package/build-module/entity-types/user.js.map +7 -1
- package/build-module/entity-types/widget-type.js +1 -2
- package/build-module/entity-types/widget-type.js.map +7 -1
- package/build-module/entity-types/widget.js +1 -2
- package/build-module/entity-types/widget.js.map +7 -1
- package/build-module/entity-types/wp-template-part.js +1 -2
- package/build-module/entity-types/wp-template-part.js.map +7 -1
- package/build-module/entity-types/wp-template.js +1 -2
- package/build-module/entity-types/wp-template.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +111 -149
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +20 -49
- package/build-module/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build-module/fetch/index.js +20 -15
- package/build-module/fetch/index.js.map +7 -1
- package/build-module/footnotes/get-footnotes-order.js +10 -19
- package/build-module/footnotes/get-footnotes-order.js.map +7 -1
- package/build-module/footnotes/get-rich-text-values-cached.js +8 -23
- package/build-module/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build-module/footnotes/index.js +34 -47
- package/build-module/footnotes/index.js.map +7 -1
- package/build-module/hooks/constants.js +11 -8
- package/build-module/hooks/constants.js.map +7 -1
- package/build-module/hooks/index.js +27 -15
- package/build-module/hooks/index.js.map +7 -1
- package/build-module/hooks/memoize.js +6 -8
- package/build-module/hooks/memoize.js.map +7 -1
- package/build-module/hooks/use-entity-block-editor.js +80 -110
- package/build-module/hooks/use-entity-block-editor.js.map +7 -1
- package/build-module/hooks/use-entity-id.js +7 -19
- package/build-module/hooks/use-entity-id.js.map +7 -1
- package/build-module/hooks/use-entity-prop.js +31 -55
- package/build-module/hooks/use-entity-prop.js.map +7 -1
- package/build-module/hooks/use-entity-record.js +63 -148
- package/build-module/hooks/use-entity-record.js.map +7 -1
- package/build-module/hooks/use-entity-records.js +98 -131
- package/build-module/hooks/use-entity-records.js.map +7 -1
- package/build-module/hooks/use-query-select.js +27 -71
- package/build-module/hooks/use-query-select.js.map +7 -1
- package/build-module/hooks/use-resource-permissions.js +57 -136
- package/build-module/hooks/use-resource-permissions.js.map +7 -1
- package/build-module/index.js +49 -71
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/locks/actions.js +8 -13
- package/build-module/locks/actions.js.map +7 -1
- package/build-module/locks/engine.js +17 -38
- package/build-module/locks/engine.js.map +7 -1
- package/build-module/locks/reducer.js +37 -59
- package/build-module/locks/reducer.js.map +7 -1
- package/build-module/locks/selectors.js +16 -23
- package/build-module/locks/selectors.js.map +7 -1
- package/build-module/locks/utils.js +15 -12
- package/build-module/locks/utils.js.map +7 -1
- package/build-module/name.js +5 -8
- package/build-module/name.js.map +7 -1
- package/build-module/private-actions.js +35 -69
- package/build-module/private-actions.js.map +7 -1
- package/build-module/private-apis.js +8 -8
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-selectors.js +167 -174
- package/build-module/private-selectors.js.map +7 -1
- package/build-module/queried-data/actions.js +11 -38
- package/build-module/queried-data/actions.js.map +7 -1
- package/build-module/queried-data/get-query-parts.js +20 -75
- package/build-module/queried-data/get-query-parts.js.map +7 -1
- package/build-module/queried-data/index.js +7 -4
- package/build-module/queried-data/index.js.map +7 -1
- package/build-module/queried-data/reducer.js +134 -185
- package/build-module/queried-data/reducer.js.map +7 -1
- package/build-module/queried-data/selectors.js +23 -78
- package/build-module/queried-data/selectors.js.map +7 -1
- package/build-module/reducer.js +243 -393
- package/build-module/reducer.js.map +7 -1
- package/build-module/resolvers.js +478 -549
- package/build-module/resolvers.js.map +7 -1
- package/build-module/selectors.js +410 -953
- package/build-module/selectors.js.map +7 -1
- package/build-module/sync.js +14 -17
- package/build-module/sync.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/conservative-map-item.js +6 -22
- package/build-module/utils/conservative-map-item.js.map +7 -1
- package/build-module/utils/crdt-blocks.js +255 -0
- package/build-module/utils/crdt-blocks.js.map +7 -0
- package/build-module/utils/crdt.js +167 -0
- package/build-module/utils/crdt.js.map +7 -0
- package/build-module/utils/forward-resolver.js +6 -12
- package/build-module/utils/forward-resolver.js.map +7 -1
- package/build-module/utils/get-nested-value.js +9 -18
- package/build-module/utils/get-nested-value.js.map +7 -1
- package/build-module/utils/get-normalized-comma-separable.js +7 -13
- package/build-module/utils/get-normalized-comma-separable.js.map +7 -1
- package/build-module/utils/if-matching-action.js +7 -15
- package/build-module/utils/if-matching-action.js.map +7 -1
- package/build-module/utils/index.js +35 -14
- package/build-module/utils/index.js.map +7 -1
- package/build-module/utils/is-numeric-id.js +5 -9
- package/build-module/utils/is-numeric-id.js.map +7 -1
- package/build-module/utils/is-raw-attribute.js +5 -10
- package/build-module/utils/is-raw-attribute.js.map +7 -1
- package/build-module/utils/log-entity-deprecation.js +8 -31
- package/build-module/utils/log-entity-deprecation.js.map +7 -1
- package/build-module/utils/on-sub-key.js +8 -19
- package/build-module/utils/on-sub-key.js.map +7 -1
- package/build-module/utils/receive-intermediate-results.js +7 -2
- package/build-module/utils/receive-intermediate-results.js.map +7 -1
- package/build-module/utils/replace-action.js +6 -13
- package/build-module/utils/replace-action.js.map +7 -1
- package/build-module/utils/set-nested-value.js +8 -27
- package/build-module/utils/set-nested-value.js.map +7 -1
- package/build-module/utils/user-permissions.js +19 -9
- package/build-module/utils/user-permissions.js.map +7 -1
- package/build-module/utils/with-weak-map-cache.js +8 -18
- package/build-module/utils/with-weak-map-cache.js.map +7 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +0 -56
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/sync.d.ts +6 -1
- package/build-types/sync.d.ts.map +1 -1
- package/build-types/types.d.ts +9 -0
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts +30 -0
- package/build-types/utils/crdt-blocks.d.ts.map +1 -0
- package/build-types/utils/crdt.d.ts +49 -0
- package/build-types/utils/crdt.d.ts.map +1 -0
- package/package.json +26 -19
- package/src/actions.js +56 -74
- package/src/entities.js +59 -113
- package/src/private-selectors.ts +32 -7
- package/src/resolvers.js +173 -120
- package/src/selectors.ts +0 -13
- package/src/sync.ts +12 -0
- package/src/test/resolvers.js +183 -0
- package/src/types.ts +12 -0
- package/src/utils/crdt-blocks.ts +503 -0
- package/src/utils/crdt.ts +310 -0
- package/src/utils/test/crdt-blocks.ts +375 -0
- package/src/utils/test/crdt.ts +254 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/sync.js +0 -27
|
@@ -1,44 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var experimental_fetch_link_suggestions_exports = {};
|
|
30
|
+
__export(experimental_fetch_link_suggestions_exports, {
|
|
31
|
+
default: () => fetchLinkSuggestions,
|
|
32
|
+
sortResults: () => sortResults,
|
|
33
|
+
tokenize: () => tokenize
|
|
6
34
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
|
-
var _i18n = require("@wordpress/i18n");
|
|
14
|
-
/**
|
|
15
|
-
* WordPress dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Fetches link suggestions from the WordPress API.
|
|
20
|
-
*
|
|
21
|
-
* WordPress does not support searching multiple tables at once, e.g. posts and terms, so we
|
|
22
|
-
* perform multiple queries at the same time and then merge the results together.
|
|
23
|
-
*
|
|
24
|
-
* @param search
|
|
25
|
-
* @param searchOptions
|
|
26
|
-
* @param editorSettings
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```js
|
|
30
|
-
* import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
|
|
31
|
-
*
|
|
32
|
-
* //...
|
|
33
|
-
*
|
|
34
|
-
* export function initialize( id, settings ) {
|
|
35
|
-
*
|
|
36
|
-
* settings.__experimentalFetchLinkSuggestions = (
|
|
37
|
-
* search,
|
|
38
|
-
* searchOptions
|
|
39
|
-
* ) => fetchLinkSuggestions( search, searchOptions, settings );
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
35
|
+
module.exports = __toCommonJS(experimental_fetch_link_suggestions_exports);
|
|
36
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
37
|
+
var import_url = require("@wordpress/url");
|
|
38
|
+
var import_html_entities = require("@wordpress/html-entities");
|
|
39
|
+
var import_i18n = require("@wordpress/i18n");
|
|
42
40
|
async function fetchLinkSuggestions(search, searchOptions = {}, editorSettings = {}) {
|
|
43
41
|
const searchOptionsToUse = searchOptions.isInitialSuggestions && searchOptions.initialSuggestionsSearchOptions ? {
|
|
44
42
|
...searchOptions,
|
|
@@ -50,131 +48,125 @@ async function fetchLinkSuggestions(search, searchOptions = {}, editorSettings =
|
|
|
50
48
|
page,
|
|
51
49
|
perPage = searchOptions.isInitialSuggestions ? 3 : 20
|
|
52
50
|
} = searchOptionsToUse;
|
|
53
|
-
const {
|
|
54
|
-
disablePostFormats = false
|
|
55
|
-
} = editorSettings;
|
|
51
|
+
const { disablePostFormats = false } = editorSettings;
|
|
56
52
|
const queries = [];
|
|
57
|
-
if (!type || type ===
|
|
58
|
-
queries.push(
|
|
59
|
-
|
|
60
|
-
search,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
if (!type || type === "post") {
|
|
54
|
+
queries.push(
|
|
55
|
+
(0, import_api_fetch.default)({
|
|
56
|
+
path: (0, import_url.addQueryArgs)("/wp/v2/search", {
|
|
57
|
+
search,
|
|
58
|
+
page,
|
|
59
|
+
per_page: perPage,
|
|
60
|
+
type: "post",
|
|
61
|
+
subtype
|
|
62
|
+
})
|
|
63
|
+
}).then((results2) => {
|
|
64
|
+
return results2.map((result) => {
|
|
65
|
+
return {
|
|
66
|
+
id: result.id,
|
|
67
|
+
url: result.url,
|
|
68
|
+
title: (0, import_html_entities.decodeEntities)(result.title || "") || (0, import_i18n.__)("(no title)"),
|
|
69
|
+
type: result.subtype || result.type,
|
|
70
|
+
kind: "post-type"
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}).catch(() => [])
|
|
74
|
+
// Fail by returning no results.
|
|
77
75
|
);
|
|
78
76
|
}
|
|
79
|
-
if (!type || type ===
|
|
80
|
-
queries.push(
|
|
81
|
-
|
|
82
|
-
search,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
77
|
+
if (!type || type === "term") {
|
|
78
|
+
queries.push(
|
|
79
|
+
(0, import_api_fetch.default)({
|
|
80
|
+
path: (0, import_url.addQueryArgs)("/wp/v2/search", {
|
|
81
|
+
search,
|
|
82
|
+
page,
|
|
83
|
+
per_page: perPage,
|
|
84
|
+
type: "term",
|
|
85
|
+
subtype
|
|
86
|
+
})
|
|
87
|
+
}).then((results2) => {
|
|
88
|
+
return results2.map((result) => {
|
|
89
|
+
return {
|
|
90
|
+
id: result.id,
|
|
91
|
+
url: result.url,
|
|
92
|
+
title: (0, import_html_entities.decodeEntities)(result.title || "") || (0, import_i18n.__)("(no title)"),
|
|
93
|
+
type: result.subtype || result.type,
|
|
94
|
+
kind: "taxonomy"
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}).catch(() => [])
|
|
98
|
+
// Fail by returning no results.
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
|
-
if (!disablePostFormats && (!type || type ===
|
|
102
|
-
queries.push(
|
|
103
|
-
|
|
104
|
-
search,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
101
|
+
if (!disablePostFormats && (!type || type === "post-format")) {
|
|
102
|
+
queries.push(
|
|
103
|
+
(0, import_api_fetch.default)({
|
|
104
|
+
path: (0, import_url.addQueryArgs)("/wp/v2/search", {
|
|
105
|
+
search,
|
|
106
|
+
page,
|
|
107
|
+
per_page: perPage,
|
|
108
|
+
type: "post-format",
|
|
109
|
+
subtype
|
|
110
|
+
})
|
|
111
|
+
}).then((results2) => {
|
|
112
|
+
return results2.map((result) => {
|
|
113
|
+
return {
|
|
114
|
+
id: result.id,
|
|
115
|
+
url: result.url,
|
|
116
|
+
title: (0, import_html_entities.decodeEntities)(result.title || "") || (0, import_i18n.__)("(no title)"),
|
|
117
|
+
type: result.subtype || result.type,
|
|
118
|
+
kind: "taxonomy"
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
}).catch(() => [])
|
|
122
|
+
// Fail by returning no results.
|
|
121
123
|
);
|
|
122
124
|
}
|
|
123
|
-
if (!type || type ===
|
|
124
|
-
queries.push(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
if (!type || type === "attachment") {
|
|
126
|
+
queries.push(
|
|
127
|
+
(0, import_api_fetch.default)({
|
|
128
|
+
path: (0, import_url.addQueryArgs)("/wp/v2/media", {
|
|
129
|
+
search,
|
|
130
|
+
page,
|
|
131
|
+
per_page: perPage
|
|
132
|
+
})
|
|
133
|
+
}).then((results2) => {
|
|
134
|
+
return results2.map((result) => {
|
|
135
|
+
return {
|
|
136
|
+
id: result.id,
|
|
137
|
+
url: result.source_url,
|
|
138
|
+
title: (0, import_html_entities.decodeEntities)(result.title.rendered || "") || (0, import_i18n.__)("(no title)"),
|
|
139
|
+
type: result.type,
|
|
140
|
+
kind: "media"
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}).catch(() => [])
|
|
144
|
+
// Fail by returning no results.
|
|
141
145
|
);
|
|
142
146
|
}
|
|
143
147
|
const responses = await Promise.all(queries);
|
|
144
148
|
let results = responses.flat();
|
|
145
|
-
results = results.filter(result => !!result.id);
|
|
149
|
+
results = results.filter((result) => !!result.id);
|
|
146
150
|
results = sortResults(results, search);
|
|
147
151
|
results = results.slice(0, perPage);
|
|
148
152
|
return results;
|
|
149
153
|
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Sort search results by relevance to the given query.
|
|
153
|
-
*
|
|
154
|
-
* Sorting is necessary as we're querying multiple endpoints and merging the results. For example
|
|
155
|
-
* a taxonomy title might be more relevant than a post title, but by default taxonomy results will
|
|
156
|
-
* be ordered after all the (potentially irrelevant) post results.
|
|
157
|
-
*
|
|
158
|
-
* We sort by scoring each result, where the score is the number of tokens in the title that are
|
|
159
|
-
* also in the search query, divided by the total number of tokens in the title. This gives us a
|
|
160
|
-
* score between 0 and 1, where 1 is a perfect match.
|
|
161
|
-
*
|
|
162
|
-
* @param results
|
|
163
|
-
* @param search
|
|
164
|
-
*/
|
|
165
154
|
function sortResults(results, search) {
|
|
166
155
|
const searchTokens = tokenize(search);
|
|
167
156
|
const scores = {};
|
|
168
157
|
for (const result of results) {
|
|
169
158
|
if (result.title) {
|
|
170
159
|
const titleTokens = tokenize(result.title);
|
|
171
|
-
const exactMatchingTokens = titleTokens.filter(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
160
|
+
const exactMatchingTokens = titleTokens.filter(
|
|
161
|
+
(titleToken) => searchTokens.some(
|
|
162
|
+
(searchToken) => titleToken === searchToken
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
const subMatchingTokens = titleTokens.filter(
|
|
166
|
+
(titleToken) => searchTokens.some(
|
|
167
|
+
(searchToken) => titleToken !== searchToken && titleToken.includes(searchToken)
|
|
168
|
+
)
|
|
169
|
+
);
|
|
178
170
|
const exactMatchScore = exactMatchingTokens.length / titleTokens.length * 10;
|
|
179
171
|
const subMatchScore = subMatchingTokens.length / titleTokens.length;
|
|
180
172
|
scores[result.id] = exactMatchScore + subMatchScore;
|
|
@@ -184,17 +176,12 @@ function sortResults(results, search) {
|
|
|
184
176
|
}
|
|
185
177
|
return results.sort((a, b) => scores[b.id] - scores[a.id]);
|
|
186
178
|
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Turns text into an array of tokens, with whitespace and punctuation removed.
|
|
190
|
-
*
|
|
191
|
-
* For example, `"I'm having a ball."` becomes `[ "im", "having", "a", "ball" ]`.
|
|
192
|
-
*
|
|
193
|
-
* @param text
|
|
194
|
-
*/
|
|
195
179
|
function tokenize(text) {
|
|
196
|
-
// \p{L} matches any kind of letter from any language.
|
|
197
|
-
// \p{N} matches any kind of numeric character.
|
|
198
180
|
return text.toLowerCase().match(/[\p{L}\p{N}]+/gu) || [];
|
|
199
181
|
}
|
|
200
|
-
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
sortResults,
|
|
185
|
+
tokenize
|
|
186
|
+
});
|
|
187
|
+
//# sourceMappingURL=__experimental-fetch-link-suggestions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFetch","_interopRequireDefault","require","_url","_htmlEntities","_i18n","fetchLinkSuggestions","search","searchOptions","editorSettings","searchOptionsToUse","isInitialSuggestions","initialSuggestionsSearchOptions","type","subtype","page","perPage","disablePostFormats","queries","push","apiFetch","path","addQueryArgs","per_page","then","results","map","result","id","url","title","decodeEntities","__","kind","catch","source_url","rendered","responses","Promise","all","flat","filter","sortResults","slice","searchTokens","tokenize","scores","titleTokens","exactMatchingTokens","titleToken","some","searchToken","subMatchingTokens","includes","exactMatchScore","length","subMatchScore","sort","a","b","text","toLowerCase","match"],"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.ts"],"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"],"mappings":";;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAiFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,eAAeI,oBAAoBA,CACjDC,MAAc,EACdC,aAA4B,GAAG,CAAC,CAAC,EACjCC,cAA8B,GAAG,CAAC,CAAC,EACP;EAC5B,MAAMC,kBAAkB,GACvBF,aAAa,CAACG,oBAAoB,IAClCH,aAAa,CAACI,+BAA+B,GAC1C;IACA,GAAGJ,aAAa;IAChB,GAAGA,aAAa,CAACI;EACjB,CAAC,GACDJ,aAAa;EAEjB,MAAM;IACLK,IAAI;IACJC,OAAO;IACPC,IAAI;IACJC,OAAO,GAAGR,aAAa,CAACG,oBAAoB,GAAG,CAAC,GAAG;EACpD,CAAC,GAAGD,kBAAkB;EAEtB,MAAM;IAAEO,kBAAkB,GAAG;EAAM,CAAC,GAAGR,cAAc;EAErD,MAAMS,OAAoC,GAAG,EAAE;EAE/C,IAAK,CAAEL,IAAI,IAAIA,IAAI,KAAK,MAAM,EAAG;IAChCK,OAAO,CAACC,IAAI,CACX,IAAAC,iBAAQ,EAAuB;MAC9BC,IAAI,EAAE,IAAAC,iBAAY,EAAE,eAAe,EAAE;QACpCf,MAAM;QACNQ,IAAI;QACJQ,QAAQ,EAAEP,OAAO;QACjBH,IAAI,EAAE,MAAM;QACZC;MACD,CAAE;IACH,CAAE,CAAC,CACDU,IAAI,CAAIC,OAAO,IAAM;MACrB,OAAOA,OAAO,CAACC,GAAG,CAAIC,MAAM,IAAM;QACjC,O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A;MACA;MACA;MACA,MAAMG,eAAe,GAClBN,mBAAmB,CAACO,MAAM,GAAGR,WAAW,CAACQ,MAAM,GAAK,EAAE;MAEzD,MAAMC,aAAa,GAAGJ,iBAAiB,CAACG,MAAM,GAAGR,WAAW,CAACQ,MAAM;MAEnET,MAAM,CAAEnB,MAAM,CAACC,EAAE,CAAE,GAAG0B,eAAe,GAAGE,aAAa;IACtD,CAAC,MAAM;MACNV,MAAM,CAAEnB,MAAM,CAACC,EAAE,CAAE,GAAG,CAAC;IACxB;EACD;EAEA,OAAOH,OAAO,CAACgC,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAMb,MAAM,CAAEa,CAAC,CAAC/B,EAAE,CAAE,GAAGkB,MAAM,CAAEY,CAAC,CAAC9B,EAAE,CAAG,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASiB,QAAQA,CAAEe,IAAY,EAAa;EAClD;EACA;EACA,OAAOA,IAAI,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAE,iBAAkB,CAAC,IAAI,EAAE;AAC3D","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/fetch/__experimental-fetch-link-suggestions.ts"],
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAAA,UACP,iBAAAA,SAA+B;AAAA,QAC9B,UAAM,yBAAc,iBAAiB;AAAA,UACpC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACV,MAAM;AAAA,UACN;AAAA,QACD,CAAE;AAAA,MACH,CAAE,EACA,KAAM,CAAEC,aAAa;AACrB,eAAOA,SAAQ,IAAK,CAAE,WAAY;AACjC,iBAAO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,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
|
+
"names": ["apiFetch", "results"]
|
|
7
|
+
}
|
|
@@ -1,75 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var experimental_fetch_url_data_exports = {};
|
|
30
|
+
__export(experimental_fetch_url_data_exports, {
|
|
31
|
+
default: () => experimental_fetch_url_data_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A simple in-memory cache for requests.
|
|
16
|
-
* This avoids repeat HTTP requests which may be beneficial
|
|
17
|
-
* for those wishing to preserve low-bandwidth.
|
|
18
|
-
*/
|
|
19
|
-
const CACHE = new Map();
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @typedef WPRemoteUrlData
|
|
23
|
-
*
|
|
24
|
-
* @property {string} title contents of the remote URL's `<title>` tag.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Fetches data about a remote URL.
|
|
29
|
-
* eg: <title> tag, favicon...etc.
|
|
30
|
-
*
|
|
31
|
-
* @async
|
|
32
|
-
* @param {string} url the URL to request details from.
|
|
33
|
-
* @param {?Object} options any options to pass to the underlying fetch.
|
|
34
|
-
* @example
|
|
35
|
-
* ```js
|
|
36
|
-
* import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';
|
|
37
|
-
*
|
|
38
|
-
* //...
|
|
39
|
-
*
|
|
40
|
-
* export function initialize( id, settings ) {
|
|
41
|
-
*
|
|
42
|
-
* settings.__experimentalFetchUrlData = (
|
|
43
|
-
* url
|
|
44
|
-
* ) => fetchUrlData( url );
|
|
45
|
-
* ```
|
|
46
|
-
* @return {Promise< WPRemoteUrlData[] >} Remote URL data.
|
|
47
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(experimental_fetch_url_data_exports);
|
|
34
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
35
|
+
var import_url = require("@wordpress/url");
|
|
36
|
+
const CACHE = /* @__PURE__ */ new Map();
|
|
48
37
|
const fetchUrlData = async (url, options = {}) => {
|
|
49
|
-
const endpoint =
|
|
38
|
+
const endpoint = "/wp-block-editor/v1/url-details";
|
|
50
39
|
const args = {
|
|
51
|
-
url: (0,
|
|
40
|
+
url: (0, import_url.prependHTTP)(url)
|
|
52
41
|
};
|
|
53
|
-
if (!(0,
|
|
42
|
+
if (!(0, import_url.isURL)(url)) {
|
|
54
43
|
return Promise.reject(`${url} is not a valid URL.`);
|
|
55
44
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return Promise.reject(`${url} does not have a valid protocol. URLs must be "http" based`);
|
|
45
|
+
const protocol = (0, import_url.getProtocol)(url);
|
|
46
|
+
if (!protocol || !(0, import_url.isValidProtocol)(protocol) || !protocol.startsWith("http") || !/^https?:\/\/[^\/\s]/i.test(url)) {
|
|
47
|
+
return Promise.reject(
|
|
48
|
+
`${url} does not have a valid protocol. URLs must be "http" based`
|
|
49
|
+
);
|
|
62
50
|
}
|
|
63
51
|
if (CACHE.has(url)) {
|
|
64
52
|
return CACHE.get(url);
|
|
65
53
|
}
|
|
66
|
-
return (0,
|
|
67
|
-
path: (0,
|
|
54
|
+
return (0, import_api_fetch.default)({
|
|
55
|
+
path: (0, import_url.addQueryArgs)(endpoint, args),
|
|
68
56
|
...options
|
|
69
|
-
}).then(res => {
|
|
57
|
+
}).then((res) => {
|
|
70
58
|
CACHE.set(url, res);
|
|
71
59
|
return res;
|
|
72
60
|
});
|
|
73
61
|
};
|
|
74
|
-
var
|
|
75
|
-
//# sourceMappingURL=__experimental-fetch-url-data.js.map
|
|
62
|
+
var experimental_fetch_url_data_default = fetchUrlData;
|
|
63
|
+
//# sourceMappingURL=__experimental-fetch-url-data.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/fetch/__experimental-fetch-url-data.js"],
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AACrB,iBAMO;AAOP,MAAM,QAAQ,oBAAI,IAAI;AA6BtB,MAAM,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
|
+
"names": ["apiFetch"]
|
|
7
|
+
}
|