@wordpress/core-data 6.16.0 → 6.17.1
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/CHANGELOG.md +2 -0
- package/build/actions.js +69 -134
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +0 -22
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +3 -15
- package/build/batch/default-processor.js.map +1 -1
- package/build/batch/index.js +0 -3
- package/build/batch/index.js.map +1 -1
- package/build/entities.js +109 -36
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +34 -53
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/attachment.js.map +1 -1
- package/build/entity-types/base-entity-records.js +0 -3
- package/build/entity-types/base-entity-records.js.map +1 -1
- package/build/entity-types/comment.js.map +1 -1
- package/build/entity-types/helpers.js.map +1 -1
- package/build/entity-types/index.js.map +1 -1
- package/build/entity-types/menu-location.js.map +1 -1
- package/build/entity-types/nav-menu-item.js.map +1 -1
- package/build/entity-types/nav-menu.js.map +1 -1
- package/build/entity-types/page.js.map +1 -1
- package/build/entity-types/plugin.js.map +1 -1
- package/build/entity-types/post.js.map +1 -1
- package/build/entity-types/settings.js.map +1 -1
- package/build/entity-types/sidebar.js.map +1 -1
- package/build/entity-types/taxonomy.js.map +1 -1
- package/build/entity-types/theme.js.map +1 -1
- package/build/entity-types/type.js.map +1 -1
- package/build/entity-types/user.js.map +1 -1
- package/build/entity-types/widget-type.js.map +1 -1
- package/build/entity-types/widget.js.map +1 -1
- package/build/entity-types/wp-template-part.js.map +1 -1
- package/build/entity-types/wp-template.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +14 -20
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +4 -13
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/fetch/index.js +0 -3
- package/build/fetch/index.js.map +1 -1
- package/build/hooks/constants.js +4 -5
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +0 -5
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/memoize.js +0 -3
- package/build/hooks/memoize.js.map +1 -1
- package/build/hooks/use-entity-record.js +0 -9
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -9
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +1 -13
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +0 -15
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +9 -41
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +1 -6
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +1 -9
- package/build/locks/engine.js.map +1 -1
- package/build/locks/reducer.js +8 -9
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +8 -11
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +4 -19
- package/build/locks/utils.js.map +1 -1
- package/build/name.js +0 -1
- package/build/name.js.map +1 -1
- package/build/private-apis.js +1 -2
- package/build/private-apis.js.map +1 -1
- package/build/private-selectors.js +2 -5
- package/build/private-selectors.js.map +1 -1
- package/build/queried-data/actions.js +4 -6
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +11 -24
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/index.js +0 -6
- package/build/queried-data/index.js.map +1 -1
- package/build/queried-data/reducer.js +33 -51
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -25
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +76 -128
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +91 -133
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +51 -145
- package/build/selectors.js.map +1 -1
- package/build/sync.js +19 -0
- package/build/sync.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build/utils/conservative-map-item.js +3 -10
- package/build/utils/conservative-map-item.js.map +1 -1
- package/build/utils/forward-resolver.js +0 -2
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/get-normalized-comma-separable.js +0 -3
- package/build/utils/get-normalized-comma-separable.js.map +1 -1
- package/build/utils/if-matching-action.js +0 -3
- package/build/utils/if-matching-action.js.map +1 -1
- package/build/utils/index.js +0 -10
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-raw-attribute.js +0 -1
- package/build/utils/is-raw-attribute.js.map +1 -1
- package/build/utils/on-sub-key.js +5 -9
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/replace-action.js +0 -2
- package/build/utils/replace-action.js.map +1 -1
- package/build/utils/set-nested-value.js +0 -4
- package/build/utils/set-nested-value.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +3 -6
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js +72 -95
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +1 -20
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +4 -13
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/batch/index.js.map +1 -1
- package/build-module/entities.js +109 -25
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +35 -45
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/attachment.js.map +1 -1
- package/build-module/entity-types/base-entity-records.js +0 -2
- package/build-module/entity-types/base-entity-records.js.map +1 -1
- package/build-module/entity-types/comment.js.map +1 -1
- package/build-module/entity-types/helpers.js.map +1 -1
- package/build-module/entity-types/index.js.map +1 -1
- package/build-module/entity-types/menu-location.js.map +1 -1
- package/build-module/entity-types/nav-menu-item.js.map +1 -1
- package/build-module/entity-types/nav-menu.js.map +1 -1
- package/build-module/entity-types/page.js.map +1 -1
- package/build-module/entity-types/plugin.js.map +1 -1
- package/build-module/entity-types/post.js.map +1 -1
- package/build-module/entity-types/settings.js.map +1 -1
- package/build-module/entity-types/sidebar.js.map +1 -1
- package/build-module/entity-types/taxonomy.js.map +1 -1
- package/build-module/entity-types/theme.js.map +1 -1
- package/build-module/entity-types/type.js.map +1 -1
- package/build-module/entity-types/user.js.map +1 -1
- package/build-module/entity-types/widget-type.js.map +1 -1
- package/build-module/entity-types/widget.js.map +1 -1
- package/build-module/entity-types/wp-template-part.js.map +1 -1
- package/build-module/entity-types/wp-template.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +15 -15
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +5 -10
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/fetch/index.js.map +1 -1
- package/build-module/hooks/constants.js +3 -4
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/memoize.js +2 -1
- package/build-module/hooks/memoize.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +1 -3
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -3
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +1 -9
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +1 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +11 -19
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +0 -3
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +0 -5
- package/build-module/locks/engine.js.map +1 -1
- package/build-module/locks/reducer.js +7 -7
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +7 -8
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +4 -14
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/name.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-selectors.js +2 -2
- package/build-module/private-selectors.js.map +1 -1
- package/build-module/queried-data/actions.js +4 -3
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +13 -21
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/index.js.map +1 -1
- package/build-module/queried-data/reducer.js +33 -42
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +6 -21
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +79 -104
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +94 -96
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +56 -92
- package/build-module/selectors.js.map +1 -1
- package/build-module/sync.js +12 -0
- package/build-module/sync.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-module/utils/conservative-map-item.js +4 -8
- package/build-module/utils/conservative-map-item.js.map +1 -1
- package/build-module/utils/forward-resolver.js +0 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/get-normalized-comma-separable.js +0 -2
- package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
- package/build-module/utils/if-matching-action.js +0 -2
- package/build-module/utils/if-matching-action.js.map +1 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js.map +1 -1
- package/build-module/utils/on-sub-key.js +5 -7
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/replace-action.js +0 -1
- package/build-module/utils/replace-action.js.map +1 -1
- package/build-module/utils/set-nested-value.js +0 -3
- package/build-module/utils/set-nested-value.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +3 -5
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +53 -0
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-provider.d.ts +1 -1
- package/build-types/entity-provider.d.ts.map +1 -1
- package/build-types/hooks/memoize.d.ts +1 -1
- package/build-types/hooks/memoize.d.ts.map +1 -1
- package/build-types/index.d.ts +3 -3
- package/build-types/index.d.ts.map +1 -1
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/sync.d.ts +2 -0
- package/build-types/sync.d.ts.map +1 -0
- package/package.json +17 -15
- package/src/actions.js +24 -14
- package/src/entities.js +91 -0
- package/src/entity-provider.js +11 -2
- package/src/resolvers.js +89 -41
- package/src/sync.js +18 -0
- package/src/test/entity-provider.js +272 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_apiFetch","_interopRequireDefault","require","_url","CACHE","Map","fetchUrlData","url","options","endpoint","args","prependHTTP","isURL","Promise","reject","protocol","getProtocol","isValidProtocol","startsWith","test","has","get","apiFetch","path","addQueryArgs","then","res","set","_default","exports","default"],"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"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"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAME,KAAK,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAG,MAAAA,CAAQC,GAAG,EAAEC,OAAO,GAAG,CAAC,CAAC,KAAM;EACnD,MAAMC,QAAQ,GAAG,iCAAiC;EAElD,MAAMC,IAAI,GAAG;IACZH,GAAG,EAAE,IAAAI,gBAAW,EAAEJ,GAAI;EACvB,CAAC;EAED,IAAK,CAAE,IAAAK,UAAK,EAAEL,GAAI,CAAC,EAAG;IACrB,OAAOM,OAAO,CAACC,MAAM,CAAG,GAAGP,GAAK,sBAAsB,CAAC;EACxD;;EAEA;EACA;EACA,MAAMQ,QAAQ,GAAG,IAAAC,gBAAW,EAAET,GAAI,CAAC;EAEnC,IACC,CAAEQ,QAAQ,IACV,CAAE,IAAAE,oBAAe,EAAEF,QAAS,CAAC,IAC7B,CAAEA,QAAQ,CAACG,UAAU,CAAE,MAAO,CAAC,IAC/B,CAAE,sBAAsB,CAACC,IAAI,CAAEZ,GAAI,CAAC,EACnC;IACD,OAAOM,OAAO,CAACC,MAAM,CACnB,GAAGP,GAAK,4DACV,CAAC;EACF;EAEA,IAAKH,KAAK,CAACgB,GAAG,CAAEb,GAAI,CAAC,EAAG;IACvB,OAAOH,KAAK,CAACiB,GAAG,CAAEd,GAAI,CAAC;EACxB;EAEA,OAAO,IAAAe,iBAAQ,EAAE;IAChBC,IAAI,EAAE,IAAAC,iBAAY,EAAEf,QAAQ,EAAEC,IAAK,CAAC;IACpC,GAAGF;EACJ,CAAE,CAAC,CAACiB,IAAI,CAAIC,GAAG,IAAM;IACpBtB,KAAK,CAACuB,GAAG,CAAEpB,GAAG,EAAEmB,GAAI,CAAC;IACrB,OAAOA,GAAG;EACX,CAAE,CAAC;AACJ,CAAC;AAAC,IAAAE,QAAA,GAEatB,YAAY;AAAAuB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/fetch/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -17,8 +16,6 @@ Object.defineProperty(exports, "__experimentalFetchUrlData", {
|
|
|
17
16
|
return _experimentalFetchUrlData.default;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
|
-
|
|
21
19
|
var _experimentalFetchLinkSuggestions = _interopRequireDefault(require("./__experimental-fetch-link-suggestions"));
|
|
22
|
-
|
|
23
20
|
var _experimentalFetchUrlData = _interopRequireDefault(require("./__experimental-fetch-url-data"));
|
|
24
21
|
//# sourceMappingURL=index.js.map
|
package/build/fetch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/index.js"],"
|
|
1
|
+
{"version":3,"names":["_experimentalFetchLinkSuggestions","_interopRequireDefault","require","_experimentalFetchUrlData"],"sources":["@wordpress/core-data/src/fetch/index.js"],"sourcesContent":["export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,iCAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,yBAAA,GAAAF,sBAAA,CAAAC,OAAA"}
|
package/build/hooks/constants.js
CHANGED
|
@@ -4,13 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Status = void 0;
|
|
7
|
-
let Status
|
|
8
|
-
exports.Status = Status;
|
|
9
|
-
|
|
10
|
-
(function (Status) {
|
|
7
|
+
let Status = /*#__PURE__*/function (Status) {
|
|
11
8
|
Status["Idle"] = "IDLE";
|
|
12
9
|
Status["Resolving"] = "RESOLVING";
|
|
13
10
|
Status["Error"] = "ERROR";
|
|
14
11
|
Status["Success"] = "SUCCESS";
|
|
15
|
-
|
|
12
|
+
return Status;
|
|
13
|
+
}({});
|
|
14
|
+
exports.Status = Status;
|
|
16
15
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"
|
|
1
|
+
{"version":3,"names":["Status","exports"],"sources":["@wordpress/core-data/src/hooks/constants.ts"],"sourcesContent":["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"],"mappings":";;;;;;IAAkBA,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA;AAAAC,OAAA,CAAAD,MAAA,GAAAA,MAAA"}
|
package/build/hooks/index.js
CHANGED
|
@@ -39,14 +39,9 @@ Object.defineProperty(exports, "useResourcePermissions", {
|
|
|
39
39
|
return _useResourcePermissions.default;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
-
|
|
43
42
|
var _useEntityRecord = _interopRequireWildcard(require("./use-entity-record"));
|
|
44
|
-
|
|
45
43
|
var _useEntityRecords = _interopRequireWildcard(require("./use-entity-records"));
|
|
46
|
-
|
|
47
44
|
var _useResourcePermissions = _interopRequireWildcard(require("./use-resource-permissions"));
|
|
48
|
-
|
|
49
45
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
50
|
-
|
|
51
46
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
52
47
|
//# sourceMappingURL=index.js.map
|
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"
|
|
1
|
+
{"version":3,"names":["_useEntityRecord","_interopRequireWildcard","require","_useEntityRecords","_useResourcePermissions","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sources":["@wordpress/core-data/src/hooks/index.ts"],"sourcesContent":["export {\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';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,iBAAA,GAAAF,uBAAA,CAAAC,OAAA;AAIA,IAAAE,uBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAGoC,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAL,wBAAAS,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
|
package/build/hooks/memoize.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _memize = _interopRequireDefault(require("memize"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* External dependencies
|
|
14
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/memoize.js"],"
|
|
1
|
+
{"version":3,"names":["_memize","_interopRequireDefault","require","_default","memoize","exports","default"],"sources":["@wordpress/core-data/src/hooks/memoize.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n// re-export due to restrictive esModuleInterop setting\nexport default memoize;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;AAGA;AAAA,IAAAC,QAAA,GACeC,eAAO;AAAAC,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.__experimentalUseEntityRecord = __experimentalUseEntityRecord;
|
|
9
8
|
exports.default = useEntityRecord;
|
|
10
|
-
|
|
11
9
|
var _data = require("@wordpress/data");
|
|
12
|
-
|
|
13
10
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
14
|
-
|
|
15
11
|
var _element = require("@wordpress/element");
|
|
16
|
-
|
|
17
12
|
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
18
|
-
|
|
19
13
|
var _ = require("../");
|
|
20
|
-
|
|
21
14
|
/**
|
|
22
15
|
* WordPress dependencies
|
|
23
16
|
*/
|
|
@@ -144,7 +137,6 @@ function useEntityRecord(kind, name, recordId, options = {
|
|
|
144
137
|
data: null
|
|
145
138
|
};
|
|
146
139
|
}
|
|
147
|
-
|
|
148
140
|
return query(_.store).getEntityRecord(kind, name, recordId);
|
|
149
141
|
}, [kind, name, recordId, options.enabled]);
|
|
150
142
|
return {
|
|
@@ -155,7 +147,6 @@ function useEntityRecord(kind, name, recordId, options = {
|
|
|
155
147
|
...mutations
|
|
156
148
|
};
|
|
157
149
|
}
|
|
158
|
-
|
|
159
150
|
function __experimentalUseEntityRecord(kind, name, recordId, options) {
|
|
160
151
|
(0, _deprecated.default)(`wp.data.__experimentalUseEntityRecord`, {
|
|
161
152
|
alternative: 'wp.data.useEntityRecord',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","_deprecated","_interopRequireDefault","_element","_useQuerySelect","_","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","mutations","useMemo","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","useSelect","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","useQuerySelect","query","getEntityRecord","__experimentalUseEntityRecord","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"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/** 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\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 { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\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\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 ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\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 } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\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\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"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,eAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,CAAA,GAAAL,OAAA;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AA8CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASM,eAAeA,CACtCC,IAAY,EACZC,IAAY,EACZC,QAAyB,EACzBC,OAAgB,GAAG;EAAEC,OAAO,EAAE;AAAK,CAAC,EACG;EACvC,MAAM;IAAEC,gBAAgB;IAAEC;EAAuB,CAAC,GACjD,IAAAC,iBAAW,EAAEC,OAAU,CAAC;EAEzB,MAAMC,SAAS,GAAG,IAAAC,gBAAO,EACxB,OAAQ;IACPC,IAAI,EAAIC,MAAM,IACbP,gBAAgB,CAAEL,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEU,MAAO,CAAC;IACjDC,IAAI,EAAEA,CAAEC,WAAgB,GAAG,CAAC,CAAC,KAC5BR,sBAAsB,CAAEN,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAE;MAC7Ca,YAAY,EAAE,IAAI;MAClB,GAAGD;IACJ,CAAE;EACJ,CAAC,CAAE,EACH,CAAET,gBAAgB,EAAE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2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.__experimentalUseEntityRecords = __experimentalUseEntityRecords;
|
|
9
8
|
exports.default = useEntityRecords;
|
|
10
|
-
|
|
11
9
|
var _url = require("@wordpress/url");
|
|
12
|
-
|
|
13
10
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
14
|
-
|
|
15
11
|
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
16
|
-
|
|
17
12
|
var _ = require("../");
|
|
18
|
-
|
|
19
13
|
/**
|
|
20
14
|
* WordPress dependencies
|
|
21
15
|
*/
|
|
@@ -23,7 +17,9 @@ var _ = require("../");
|
|
|
23
17
|
/**
|
|
24
18
|
* Internal dependencies
|
|
25
19
|
*/
|
|
20
|
+
|
|
26
21
|
const EMPTY_ARRAY = [];
|
|
22
|
+
|
|
27
23
|
/**
|
|
28
24
|
* Resolves the specified entity records.
|
|
29
25
|
*
|
|
@@ -64,7 +60,6 @@ const EMPTY_ARRAY = [];
|
|
|
64
60
|
* @return Entity records data.
|
|
65
61
|
* @template RecordType
|
|
66
62
|
*/
|
|
67
|
-
|
|
68
63
|
function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
69
64
|
enabled: true
|
|
70
65
|
}) {
|
|
@@ -83,7 +78,6 @@ function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
|
83
78
|
data: EMPTY_ARRAY
|
|
84
79
|
};
|
|
85
80
|
}
|
|
86
|
-
|
|
87
81
|
return query(_.store).getEntityRecords(kind, name, queryArgs);
|
|
88
82
|
}, [kind, name, queryAsString, options.enabled]);
|
|
89
83
|
return {
|
|
@@ -91,7 +85,6 @@ function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
|
91
85
|
...rest
|
|
92
86
|
};
|
|
93
87
|
}
|
|
94
|
-
|
|
95
88
|
function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
|
|
96
89
|
(0, _deprecated.default)(`wp.data.__experimentalUseEntityRecords`, {
|
|
97
90
|
alternative: 'wp.data.useEntityRecords',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_url","require","_deprecated","_interopRequireDefault","_useQuerySelect","_","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","addQueryArgs","data","records","rest","useQuerySelect","query","coreStore","getEntityRecords","__experimentalUseEntityRecords","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\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';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\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\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\treturn {\n\t\trecords,\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"],"mappings":";;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,eAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,CAAA,GAAAJ,OAAA;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAwBA,MAAMK,WAA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ault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.META_SELECTORS = void 0;
|
|
9
8
|
exports.default = useQuerySelect;
|
|
10
|
-
|
|
11
9
|
var _data = require("@wordpress/data");
|
|
12
|
-
|
|
13
10
|
var _memoize = _interopRequireDefault(require("./memoize"));
|
|
14
|
-
|
|
15
11
|
var _constants = require("./constants");
|
|
16
|
-
|
|
17
12
|
/**
|
|
18
13
|
* WordPress dependencies
|
|
19
14
|
*/
|
|
@@ -21,9 +16,9 @@ var _constants = require("./constants");
|
|
|
21
16
|
/**
|
|
22
17
|
* Internal dependencies
|
|
23
18
|
*/
|
|
19
|
+
|
|
24
20
|
const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
|
|
25
21
|
exports.META_SELECTORS = META_SELECTORS;
|
|
26
|
-
|
|
27
22
|
/**
|
|
28
23
|
* Like useSelect, but the selectors return objects containing
|
|
29
24
|
* both the original data AND the resolution info.
|
|
@@ -70,11 +65,9 @@ exports.META_SELECTORS = META_SELECTORS;
|
|
|
70
65
|
function useQuerySelect(mapQuerySelect, deps) {
|
|
71
66
|
return (0, _data.useSelect)((select, registry) => {
|
|
72
67
|
const resolve = store => enrichSelectors(select(store));
|
|
73
|
-
|
|
74
68
|
return mapQuerySelect(resolve, registry);
|
|
75
69
|
}, deps);
|
|
76
70
|
}
|
|
77
|
-
|
|
78
71
|
/**
|
|
79
72
|
* Transform simple selectors into ones that return an object with the
|
|
80
73
|
* original return value AND the resolution info.
|
|
@@ -84,12 +77,10 @@ function useQuerySelect(mapQuerySelect, deps) {
|
|
|
84
77
|
*/
|
|
85
78
|
const enrichSelectors = (0, _memoize.default)(selectors => {
|
|
86
79
|
const resolvers = {};
|
|
87
|
-
|
|
88
80
|
for (const selectorName in selectors) {
|
|
89
81
|
if (META_SELECTORS.includes(selectorName)) {
|
|
90
82
|
continue;
|
|
91
83
|
}
|
|
92
|
-
|
|
93
84
|
Object.defineProperty(resolvers, selectorName, {
|
|
94
85
|
get: () => (...args) => {
|
|
95
86
|
const {
|
|
@@ -100,7 +91,6 @@ const enrichSelectors = (0, _memoize.default)(selectors => {
|
|
|
100
91
|
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
|
|
101
92
|
const data = selectors[selectorName](...args);
|
|
102
93
|
let status;
|
|
103
|
-
|
|
104
94
|
if (isResolving) {
|
|
105
95
|
status = _constants.Status.Resolving;
|
|
106
96
|
} else if (hasResolved) {
|
|
@@ -112,7 +102,6 @@ const enrichSelectors = (0, _memoize.default)(selectors => {
|
|
|
112
102
|
} else {
|
|
113
103
|
status = _constants.Status.Idle;
|
|
114
104
|
}
|
|
115
|
-
|
|
116
105
|
return {
|
|
117
106
|
data,
|
|
118
107
|
status,
|
|
@@ -122,7 +111,6 @@ const enrichSelectors = (0, _memoize.default)(selectors => {
|
|
|
122
111
|
}
|
|
123
112
|
});
|
|
124
113
|
}
|
|
125
|
-
|
|
126
114
|
return resolvers;
|
|
127
115
|
});
|
|
128
116
|
//# sourceMappingURL=use-query-select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","_memoize","_interopRequireDefault","_constants","META_SELECTORS","exports","useQuerySelect","mapQuerySelect","deps","useSelect","select","registry","resolve","store","enrichSelectors","memoize","selectors","resolvers","selectorName","includes","Object","defineProperty","get","args","getIsResolving","hasFinishedResolution","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"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 `getIsResolving` 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 { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\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,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIO,MAAMI,cAAc,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AS,CAAEE,YAAY,CAAE,CAAE,GAAGK,IAAK,CAAC;QAEjD,IAAIM,MAAM;QACV,IAAKH,WAAW,EAAG;UAClBG,MAAM,GAAGC,iBAAM,CAACC,SAAS;QAC1B,CAAC,MAAM,IAAKJ,WAAW,EAAG;UACzB,IAAKC,IAAI,EAAG;YACXC,MAAM,GAAGC,iBAAM,CAACE,OAAO;UACxB,CAAC,MAAM;YACNH,MAAM,GAAGC,iBAAM,CAACG,KAAK;UACtB;QACD,CAAC,MAAM;UACNJ,MAAM,GAAGC,iBAAM,CAACI,IAAI;QACrB;QAEA,OAAO;UACNN,IAAI;UACJC,MAAM;UACNH,WAAW;UACXC;QACD,CAAC;MACF;IACF,CAAE,CAAC;EACJ;EACA,OAAOV,SAAS;AACjB,CAAyB,CAAC"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.__experimentalUseResourcePermissions = __experimentalUseResourcePermissions;
|
|
9
8
|
exports.default = useResourcePermissions;
|
|
10
|
-
|
|
11
9
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
12
|
-
|
|
13
10
|
var _ = require("../");
|
|
14
|
-
|
|
15
11
|
var _constants = require("./constants");
|
|
16
|
-
|
|
17
12
|
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
18
|
-
|
|
19
13
|
/**
|
|
20
14
|
* WordPress dependencies
|
|
21
15
|
*/
|
|
@@ -98,19 +92,16 @@ function useResourcePermissions(resource, id) {
|
|
|
98
92
|
canUser
|
|
99
93
|
} = resolve(_.store);
|
|
100
94
|
const create = canUser('create', resource);
|
|
101
|
-
|
|
102
95
|
if (!id) {
|
|
103
96
|
const read = canUser('read', resource);
|
|
104
97
|
const isResolving = create.isResolving || read.isResolving;
|
|
105
98
|
const hasResolved = create.hasResolved && read.hasResolved;
|
|
106
99
|
let status = _constants.Status.Idle;
|
|
107
|
-
|
|
108
100
|
if (isResolving) {
|
|
109
101
|
status = _constants.Status.Resolving;
|
|
110
102
|
} else if (hasResolved) {
|
|
111
103
|
status = _constants.Status.Success;
|
|
112
104
|
}
|
|
113
|
-
|
|
114
105
|
return {
|
|
115
106
|
status,
|
|
116
107
|
isResolving,
|
|
@@ -119,22 +110,17 @@ function useResourcePermissions(resource, id) {
|
|
|
119
110
|
canRead: read.hasResolved && read.data
|
|
120
111
|
};
|
|
121
112
|
}
|
|
122
|
-
|
|
123
113
|
const read = canUser('read', resource, id);
|
|
124
114
|
const update = canUser('update', resource, id);
|
|
125
|
-
|
|
126
115
|
const _delete = canUser('delete', resource, id);
|
|
127
|
-
|
|
128
116
|
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
|
|
129
117
|
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
130
118
|
let status = _constants.Status.Idle;
|
|
131
|
-
|
|
132
119
|
if (isResolving) {
|
|
133
120
|
status = _constants.Status.Resolving;
|
|
134
121
|
} else if (hasResolved) {
|
|
135
122
|
status = _constants.Status.Success;
|
|
136
123
|
}
|
|
137
|
-
|
|
138
124
|
return {
|
|
139
125
|
status,
|
|
140
126
|
isResolving,
|
|
@@ -146,7 +132,6 @@ function useResourcePermissions(resource, id) {
|
|
|
146
132
|
};
|
|
147
133
|
}, [resource, id]);
|
|
148
134
|
}
|
|
149
|
-
|
|
150
135
|
function __experimentalUseResourcePermissions(resource, id) {
|
|
151
136
|
(0, _deprecated.default)(`wp.data.__experimentalUseResourcePermissions`, {
|
|
152
137
|
alternative: 'wp.data.useResourcePermissions',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_deprecated","_interopRequireDefault","require","_","_constants","_useQuerySelect","useResourcePermissions","resource","id","useQuerySelect","resolve","canUser","coreStore","create","read","isResolving","hasResolved","status","Status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\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\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\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( 'pages', 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 */\nexport default function useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\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[ resource, id ]\n\t);\n}\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"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,CAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASI,sBAAsBA,CAC7CC,QAAgB,EAChBC,EAAW,EAC+B;EAC1C,OAAO,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