@wordpress/core-data 4.1.1 → 4.2.0-next.e230fbab09.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/CHANGELOG.md +6 -0
- package/README.md +2 -10
- package/build/actions.js +9 -13
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +17 -12
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +1 -1
- package/build/entities.js.map +1 -1
- package/build/entity-types/attachment.js +6 -0
- package/build/entity-types/attachment.js.map +1 -0
- package/build/entity-types/base-entity-types.js +47 -0
- package/build/entity-types/base-entity-types.js.map +1 -0
- package/build/entity-types/comment.js +6 -0
- package/build/entity-types/comment.js.map +1 -0
- package/build/entity-types/helpers.js +6 -0
- package/build/entity-types/helpers.js.map +1 -0
- package/build/entity-types/index.js +6 -0
- package/build/entity-types/index.js.map +1 -0
- package/build/entity-types/menu-location.js +6 -0
- package/build/entity-types/menu-location.js.map +1 -0
- package/build/entity-types/nav-menu-item.js +6 -0
- package/build/entity-types/nav-menu-item.js.map +1 -0
- package/build/entity-types/nav-menu.js +6 -0
- package/build/entity-types/nav-menu.js.map +1 -0
- package/build/entity-types/navigation-area.js +6 -0
- package/build/entity-types/navigation-area.js.map +1 -0
- package/build/entity-types/page.js +6 -0
- package/build/entity-types/page.js.map +1 -0
- package/build/entity-types/plugin.js +6 -0
- package/build/entity-types/plugin.js.map +1 -0
- package/build/entity-types/post.js +6 -0
- package/build/entity-types/post.js.map +1 -0
- package/build/entity-types/settings.js +6 -0
- package/build/entity-types/settings.js.map +1 -0
- package/build/entity-types/sidebar.js +6 -0
- package/build/entity-types/sidebar.js.map +1 -0
- package/build/entity-types/taxonomy.js +6 -0
- package/build/entity-types/taxonomy.js.map +1 -0
- package/build/entity-types/theme.js +6 -0
- package/build/entity-types/theme.js.map +1 -0
- package/build/entity-types/type.js +6 -0
- package/build/entity-types/type.js.map +1 -0
- package/build/entity-types/user.js +6 -0
- package/build/entity-types/user.js.map +1 -0
- package/build/entity-types/widget-type.js +6 -0
- package/build/entity-types/widget-type.js.map +1 -0
- package/build/entity-types/widget.js +6 -0
- package/build/entity-types/widget.js.map +1 -0
- package/build/entity-types/wp-template-part.js +6 -0
- package/build/entity-types/wp-template-part.js.map +1 -0
- package/build/entity-types/wp-template.js +6 -0
- package/build/entity-types/wp-template.js.map +1 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/hooks/constants.js +18 -0
- package/build/hooks/constants.js.map +1 -0
- package/build/hooks/memoize.js +18 -0
- package/build/hooks/memoize.js.map +1 -0
- package/build/hooks/use-entity-record.js +60 -0
- package/build/hooks/use-entity-record.js.map +1 -0
- package/build/hooks/use-entity-records.js +77 -0
- package/build/hooks/use-entity-records.js.map +1 -0
- package/build/hooks/use-query-select.js +130 -0
- package/build/hooks/use-query-select.js.map +1 -0
- package/build/index.js +34 -3
- package/build/index.js.map +1 -1
- package/build/reducer.js +1 -1
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +7 -17
- package/build/resolvers.js.map +1 -1
- package/build-module/actions.js +9 -13
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +17 -12
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +1 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/attachment.js +2 -0
- package/build-module/entity-types/attachment.js.map +1 -0
- package/build-module/entity-types/base-entity-types.js +39 -0
- package/build-module/entity-types/base-entity-types.js.map +1 -0
- package/build-module/entity-types/comment.js +2 -0
- package/build-module/entity-types/comment.js.map +1 -0
- package/build-module/entity-types/helpers.js +2 -0
- package/build-module/entity-types/helpers.js.map +1 -0
- package/build-module/entity-types/index.js +2 -0
- package/build-module/entity-types/index.js.map +1 -0
- package/build-module/entity-types/menu-location.js +2 -0
- package/build-module/entity-types/menu-location.js.map +1 -0
- package/build-module/entity-types/nav-menu-item.js +2 -0
- package/build-module/entity-types/nav-menu-item.js.map +1 -0
- package/build-module/entity-types/nav-menu.js +2 -0
- package/build-module/entity-types/nav-menu.js.map +1 -0
- package/build-module/entity-types/navigation-area.js +2 -0
- package/build-module/entity-types/navigation-area.js.map +1 -0
- package/build-module/entity-types/page.js +2 -0
- package/build-module/entity-types/page.js.map +1 -0
- package/build-module/entity-types/plugin.js +2 -0
- package/build-module/entity-types/plugin.js.map +1 -0
- package/build-module/entity-types/post.js +2 -0
- package/build-module/entity-types/post.js.map +1 -0
- package/build-module/entity-types/settings.js +2 -0
- package/build-module/entity-types/settings.js.map +1 -0
- package/build-module/entity-types/sidebar.js +2 -0
- package/build-module/entity-types/sidebar.js.map +1 -0
- package/build-module/entity-types/taxonomy.js +2 -0
- package/build-module/entity-types/taxonomy.js.map +1 -0
- package/build-module/entity-types/theme.js +2 -0
- package/build-module/entity-types/theme.js.map +1 -0
- package/build-module/entity-types/type.js +2 -0
- package/build-module/entity-types/type.js.map +1 -0
- package/build-module/entity-types/user.js +2 -0
- package/build-module/entity-types/user.js.map +1 -0
- package/build-module/entity-types/widget-type.js +2 -0
- package/build-module/entity-types/widget-type.js.map +1 -0
- package/build-module/entity-types/widget.js +2 -0
- package/build-module/entity-types/widget.js.map +1 -0
- package/build-module/entity-types/wp-template-part.js +2 -0
- package/build-module/entity-types/wp-template-part.js.map +1 -0
- package/build-module/entity-types/wp-template.js +2 -0
- package/build-module/entity-types/wp-template.js.map +1 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/hooks/constants.js +10 -0
- package/build-module/hooks/constants.js.map +1 -0
- package/build-module/hooks/memoize.js +7 -0
- package/build-module/hooks/memoize.js.map +1 -0
- package/build-module/hooks/use-entity-record.js +49 -0
- package/build-module/hooks/use-entity-record.js.map +1 -0
- package/build-module/hooks/use-entity-records.js +65 -0
- package/build-module/hooks/use-entity-records.js.map +1 -0
- package/build-module/hooks/use-query-select.js +116 -0
- package/build-module/hooks/use-query-select.js.map +1 -0
- package/build-module/index.js +4 -2
- package/build-module/index.js.map +1 -1
- package/build-module/reducer.js +1 -1
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +8 -18
- package/build-module/resolvers.js.map +1 -1
- package/package.json +15 -11
- package/src/actions.js +9 -13
- package/src/batch/create-batch.js +16 -12
- package/src/entities.js +1 -1
- package/src/entity-types/README.md +193 -0
- package/src/entity-types/attachment.ts +146 -0
- package/src/entity-types/base-entity-types.ts +36 -0
- package/src/entity-types/comment.ts +96 -0
- package/src/entity-types/helpers.ts +153 -0
- package/src/entity-types/index.ts +72 -0
- package/src/entity-types/menu-location.ts +29 -0
- package/src/entity-types/nav-menu-item.ts +106 -0
- package/src/entity-types/nav-menu.ts +53 -0
- package/src/entity-types/navigation-area.ts +29 -0
- package/src/entity-types/page.ts +144 -0
- package/src/entity-types/plugin.ts +74 -0
- package/src/entity-types/post.ts +153 -0
- package/src/entity-types/settings.ts +93 -0
- package/src/entity-types/sidebar.ts +60 -0
- package/src/entity-types/taxonomy.ts +92 -0
- package/src/entity-types/theme.ts +222 -0
- package/src/entity-types/type.ts +80 -0
- package/src/entity-types/user.ts +109 -0
- package/src/entity-types/widget-type.ts +37 -0
- package/src/entity-types/widget.ts +64 -0
- package/src/entity-types/wp-template-part.ts +94 -0
- package/src/entity-types/wp-template.ts +94 -0
- package/src/fetch/__experimental-fetch-link-suggestions.js +2 -2
- package/src/hooks/constants.ts +7 -0
- package/src/hooks/memoize.js +7 -0
- package/src/hooks/test/use-entity-record.js +74 -0
- package/src/hooks/test/use-entity-records.js +78 -0
- package/src/hooks/test/use-query-select.js +194 -0
- package/src/hooks/use-entity-record.ts +72 -0
- package/src/hooks/use-entity-records.ts +89 -0
- package/src/hooks/use-query-select.ts +131 -0
- package/src/index.js +3 -1
- package/src/locks/test/engine.js +13 -13
- package/src/locks/test/reducer.js +3 -3
- package/src/locks/test/utils.js +2 -2
- package/src/reducer.js +1 -1
- package/src/resolvers.js +6 -17
- package/src/test/resolvers.js +17 -23
- package/src/test/selectors.js +2 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -113,7 +113,7 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
});
|
|
116
|
-
}).catch(() => []) //
|
|
116
|
+
}).catch(() => []) // Fail by returning no results.
|
|
117
117
|
);
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -160,7 +160,7 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
return Promise.all(queries).then(results => {
|
|
163
|
-
return results.reduce((accumulator, current) => accumulator.concat(current), //
|
|
163
|
+
return results.reduce((accumulator, current) => accumulator.concat(current), // Flatten list.
|
|
164
164
|
[]).filter(
|
|
165
165
|
/**
|
|
166
166
|
* @param {{ id: number }} result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["fetchLinkSuggestions","search","searchOptions","settings","isInitialSuggestions","type","undefined","subtype","page","perPage","disablePostFormats","queries","push","path","per_page","then","results","map","result","meta","kind","catch","Promise","all","reduce","accumulator","current","concat","filter","id","slice","url","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AAoBD,OAApB,CAFvB,EAEsD;AAC3D,MAHK,EAKLE,MALK;AAML;AACJ;AACA;AACMV,IAAAA,MAAF,IAAc;AACb,aAAO,CAAC,CAAEA,MAAM,CAACW,EAAjB;AACA,KAXI,EAaLC,KAbK,CAaE,CAbF,EAaKrB,OAbL,EAcLQ,GAdK;AAeL;AACJ;AACA;AACMC,IAAAA,MAAF,IAAc;AAAA;;AACb,aAAO;AACNW,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAENE,QAAAA,GAAG,EAAEb,MAAM,CAACa,GAFN;AAGNC,QAAAA,KAAK,EACJ,kCAAgBd,MAAM,CAACc,KAAP,IAAgB,EAAhC,KACA,cAAI,YAAJ,CALK;AAMN3B,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IANzB;AAONe,QAAAA,IAAI,EAAEF,MAAF,aAAEA,MAAF,uCAAEA,MAAM,CAAEC,IAAV,iDAAE,aAAcC;AAPd,OAAP;AASA,KA5BI,CAAP;AA8BA,GA/BM,CAAP;AAgCA,CAtHD;;eAwHepB,oB","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\n/**\n * Filters the search by type\n *\n * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType\n */\n\n/**\n * A link with an id may be of kind post-type or taxonomy\n *\n * @typedef { 'post-type' | 'taxonomy' } WPKind\n */\n\n/**\n * @typedef WPLinkSearchOptions\n *\n * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.\n * @property {WPLinkSearchType} [type] Filters by search type.\n * @property {string} [subtype] Slug of the post-type or taxonomy.\n * @property {number} [page] Which page of results to return.\n * @property {number} [perPage] Search results per page.\n */\n\n/**\n * @typedef WPLinkSearchResult\n *\n * @property {number} id Post or term id.\n * @property {string} url Link url.\n * @property {string} title Title of the link.\n * @property {string} type The taxonomy or post type slug or type URL.\n * @property {WPKind} [kind] Link kind of post-type or taxonomy\n */\n\n/**\n * @typedef WPEditorSettings\n *\n * @property {boolean} [ disablePostFormats ] Disables post formats, when true.\n */\n\n/**\n * Fetches link suggestions from the API.\n *\n * @async\n * @param {string} search\n * @param {WPLinkSearchOptions} [searchOptions]\n * @param {WPEditorSettings} [settings]\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 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions\n */\nconst fetchLinkSuggestions = async (\n\tsearch,\n\tsearchOptions = {},\n\tsettings = {}\n) => {\n\tconst {\n\t\tisInitialSuggestions = false,\n\t\ttype = undefined,\n\t\tsubtype = undefined,\n\t\tpage = undefined,\n\t\tperPage = isInitialSuggestions ? 3 : 20,\n\t} = searchOptions;\n\n\tconst { disablePostFormats = false } = settings;\n\n\tconst queries = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'post-type', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) //
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["fetchLinkSuggestions","search","searchOptions","settings","isInitialSuggestions","type","undefined","subtype","page","perPage","disablePostFormats","queries","push","path","per_page","then","results","map","result","meta","kind","catch","Promise","all","reduce","accumulator","current","concat","filter","id","slice","url","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;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;AACA;AACA,MAAMA,oBAAoB,GAAG,gBAC5BC,MAD4B,EAIxB;AAAA,MAFJC,aAEI,uEAFY,EAEZ;AAAA,MADJC,QACI,uEADO,EACP;AACJ,QAAM;AACLC,IAAAA,oBAAoB,GAAG,KADlB;AAELC,IAAAA,IAAI,GAAGC,SAFF;AAGLC,IAAAA,OAAO,GAAGD,SAHL;AAILE,IAAAA,IAAI,GAAGF,SAJF;AAKLG,IAAAA,OAAO,GAAGL,oBAAoB,GAAG,CAAH,GAAO;AALhC,MAMFF,aANJ;AAQA,QAAM;AAAEQ,IAAAA,kBAAkB,GAAG;AAAvB,MAAiCP,QAAvC;AAEA,QAAMQ,OAAO,GAAG,EAAhB;;AAEA,MAAK,CAAEN,IAAF,IAAUA,IAAI,KAAK,MAAxB,EAAiC;AAChCM,IAAAA,OAAO,CAACC,IAAR,CACC,uBAAU;AACTC,MAAAA,IAAI,EAAE,uBAAc,eAAd,EAA+B;AACpCZ,QAAAA,MADoC;AAEpCO,QAAAA,IAFoC;AAGpCM,QAAAA,QAAQ,EAAEL,OAH0B;AAIpCJ,QAAAA,IAAI,EAAE,MAJ8B;AAKpCE,QAAAA;AALoC,OAA/B;AADG,KAAV,EASEQ,IATF,CASUC,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AACrB,aAAOA,OAAO,CAACC,GAAR,CAAeC,MAAF,IAAc;AACjC,eAAO,EACN,GAAGA,MADG;AAENC,UAAAA,IAAI,EAAE;AAAEC,YAAAA,IAAI,EAAE,UAAR;AAAoBb,YAAAA;AAApB;AAFA,SAAP;AAIA,OALM,CAAP;AAMA,KAhBF,EAiBEc,KAjBF,CAiBS,MAAM,EAjBf,CADD;AAoBA;;AAED,SAAOC,OAAO,CAACC,GAAR,CAAaZ,OAAb,EAAuBI,IAAvB,CAA+BC,OAAF,IAAe;AAClD,WAAOA,OAAO,CACZQ,MADK,CAEL,CAAEC,WAAF,EAAeC,OAAf,KAA4BD,WAAW,CAACE,MAAZ,CAAoBD,OAApB,CAFvB,EAEsD;AAC3D,MAHK,EAKLE,MALK;AAML;AACJ;AACA;AACMV,IAAAA,MAAF,IAAc;AACb,aAAO,CAAC,CAAEA,MAAM,CAACW,EAAjB;AACA,KAXI,EAaLC,KAbK,CAaE,CAbF,EAaKrB,OAbL,EAcLQ,GAdK;AAeL;AACJ;AACA;AACMC,IAAAA,MAAF,IAAc;AAAA;;AACb,aAAO;AACNW,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAENE,QAAAA,GAAG,EAAEb,MAAM,CAACa,GAFN;AAGNC,QAAAA,KAAK,EACJ,kCAAgBd,MAAM,CAACc,KAAP,IAAgB,EAAhC,KACA,cAAI,YAAJ,CALK;AAMN3B,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IANzB;AAONe,QAAAA,IAAI,EAAEF,MAAF,aAAEA,MAAF,uCAAEA,MAAM,CAAEC,IAAV,iDAAE,aAAcC;AAPd,OAAP;AASA,KA5BI,CAAP;AA8BA,GA/BM,CAAP;AAgCA,CAtHD;;eAwHepB,oB","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\n/**\n * Filters the search by type\n *\n * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType\n */\n\n/**\n * A link with an id may be of kind post-type or taxonomy\n *\n * @typedef { 'post-type' | 'taxonomy' } WPKind\n */\n\n/**\n * @typedef WPLinkSearchOptions\n *\n * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.\n * @property {WPLinkSearchType} [type] Filters by search type.\n * @property {string} [subtype] Slug of the post-type or taxonomy.\n * @property {number} [page] Which page of results to return.\n * @property {number} [perPage] Search results per page.\n */\n\n/**\n * @typedef WPLinkSearchResult\n *\n * @property {number} id Post or term id.\n * @property {string} url Link url.\n * @property {string} title Title of the link.\n * @property {string} type The taxonomy or post type slug or type URL.\n * @property {WPKind} [kind] Link kind of post-type or taxonomy\n */\n\n/**\n * @typedef WPEditorSettings\n *\n * @property {boolean} [ disablePostFormats ] Disables post formats, when true.\n */\n\n/**\n * Fetches link suggestions from the API.\n *\n * @async\n * @param {string} search\n * @param {WPLinkSearchOptions} [searchOptions]\n * @param {WPEditorSettings} [settings]\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 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions\n */\nconst fetchLinkSuggestions = async (\n\tsearch,\n\tsearchOptions = {},\n\tsettings = {}\n) => {\n\tconst {\n\t\tisInitialSuggestions = false,\n\t\ttype = undefined,\n\t\tsubtype = undefined,\n\t\tpage = undefined,\n\t\tperPage = isInitialSuggestions ? 3 : 20,\n\t} = searchOptions;\n\n\tconst { disablePostFormats = false } = settings;\n\n\tconst queries = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'post-type', subtype },\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( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] )\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] )\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( accumulator, current ) => accumulator.concat( current ), // Flatten list.\n\t\t\t\t[]\n\t\t\t)\n\t\t\t.filter(\n\t\t\t\t/**\n\t\t\t\t * @param {{ id: number }} result\n\t\t\t\t */\n\t\t\t\t( result ) => {\n\t\t\t\t\treturn !! result.id;\n\t\t\t\t}\n\t\t\t)\n\t\t\t.slice( 0, perPage )\n\t\t\t.map(\n\t\t\t\t/**\n\t\t\t\t * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result\n\t\t\t\t */\n\t\t\t\t( result ) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t);\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Status = void 0;
|
|
7
|
+
|
|
8
|
+
/* eslint-disable-next-line no-shadow */
|
|
9
|
+
let Status;
|
|
10
|
+
exports.Status = Status;
|
|
11
|
+
|
|
12
|
+
(function (Status) {
|
|
13
|
+
Status["Idle"] = "IDLE";
|
|
14
|
+
Status["Resolving"] = "RESOLVING";
|
|
15
|
+
Status["Error"] = "ERROR";
|
|
16
|
+
Status["Success"] = "SUCCESS";
|
|
17
|
+
})(Status || (exports.Status = Status = {}));
|
|
18
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"names":["Status"],"mappings":";;;;;;;AAAA;IACYA,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M","sourcesContent":["/* eslint-disable-next-line no-shadow */\nexport enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _memize = _interopRequireDefault(require("memize"));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* External dependencies
|
|
14
|
+
*/
|
|
15
|
+
// re-export due to restrictive esModuleInterop setting
|
|
16
|
+
var _default = _memize.default;
|
|
17
|
+
exports.default = _default;
|
|
18
|
+
//# sourceMappingURL=memoize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/memoize.js"],"names":["memoize"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGA;eACeA,e","sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n// re-export due to restrictive esModuleInterop setting\nexport default memoize;\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = __experimentalUseEntityRecord;
|
|
9
|
+
|
|
10
|
+
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
11
|
+
|
|
12
|
+
var _ = require("../");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the specified entity record.
|
|
20
|
+
*
|
|
21
|
+
* @param kind Kind of the requested entity.
|
|
22
|
+
* @param name Name of the requested entity.
|
|
23
|
+
* @param recordId Record ID of the requested entity.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* import { useEntityRecord } from '@wordpress/core-data';
|
|
28
|
+
*
|
|
29
|
+
* function PageTitleDisplay( { id } ) {
|
|
30
|
+
* const { record, isResolving } = useEntityRecord( 'postType', 'page', id );
|
|
31
|
+
*
|
|
32
|
+
* if ( isResolving ) {
|
|
33
|
+
* return 'Loading...';
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* return record.title;
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // Rendered in the application:
|
|
40
|
+
* // <PageTitleDisplay id={ 1 } />
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* In the above example, when `PageTitleDisplay` is rendered into an
|
|
44
|
+
* application, the page and the resolution details will be retrieved from
|
|
45
|
+
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
46
|
+
*
|
|
47
|
+
* @return {EntityRecordResolution<RecordType>} Entity record data.
|
|
48
|
+
* @template RecordType
|
|
49
|
+
*/
|
|
50
|
+
function __experimentalUseEntityRecord(kind, name, recordId) {
|
|
51
|
+
const {
|
|
52
|
+
data: record,
|
|
53
|
+
...rest
|
|
54
|
+
} = (0, _useQuerySelect.default)(query => query(_.store).getEntityRecord(kind, name, recordId), [kind, name, recordId]);
|
|
55
|
+
return {
|
|
56
|
+
record,
|
|
57
|
+
...rest
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=use-entity-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["__experimentalUseEntityRecord","kind","name","recordId","data","record","rest","query","coreStore","getEntityRecord"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAuBA;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,SAASA,6BAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAIyB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAaA,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCR,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CADoB,EAEjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,CAFiC,CAAlC;AAKA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\n\ninterface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: 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\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the requested entity.\n * @param name Name of the requested entity.\n * @param recordId Record ID of the requested entity.\n *\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 * @return {EntityRecordResolution<RecordType>} Entity record data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => query( coreStore ).getEntityRecord( kind, name, recordId ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\t...rest,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = __experimentalUseEntityRecords;
|
|
9
|
+
|
|
10
|
+
var _url = require("@wordpress/url");
|
|
11
|
+
|
|
12
|
+
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
13
|
+
|
|
14
|
+
var _ = require("../");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the specified entity records.
|
|
26
|
+
*
|
|
27
|
+
* @param kind Kind of the requested entities.
|
|
28
|
+
* @param name Name of the requested entities.
|
|
29
|
+
* @param queryArgs HTTP query for the requested entities.
|
|
30
|
+
* @example
|
|
31
|
+
* ```js
|
|
32
|
+
* import { useEntityRecord } from '@wordpress/core-data';
|
|
33
|
+
*
|
|
34
|
+
* function PageTitlesList() {
|
|
35
|
+
* const { records, isResolving } = useEntityRecords( 'postType', 'page' );
|
|
36
|
+
*
|
|
37
|
+
* if ( isResolving ) {
|
|
38
|
+
* return 'Loading...';
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* return (
|
|
42
|
+
* <ul>
|
|
43
|
+
* {records.map(( page ) => (
|
|
44
|
+
* <li>{ page.title }</li>
|
|
45
|
+
* ))}
|
|
46
|
+
* </ul>
|
|
47
|
+
* );
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Rendered in the application:
|
|
51
|
+
* // <PageTitlesList />
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* In the above example, when `PageTitlesList` is rendered into an
|
|
55
|
+
* application, the list of records and the resolution details will be retrieved from
|
|
56
|
+
* the store state using `getEntityRecords()`, or resolved if missing.
|
|
57
|
+
*
|
|
58
|
+
* @return {EntityRecordsResolution<RecordType>} Entity records data.
|
|
59
|
+
* @template RecordType
|
|
60
|
+
*/
|
|
61
|
+
function __experimentalUseEntityRecords(kind, name) {
|
|
62
|
+
let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
63
|
+
// Serialize queryArgs to a string that can be safely used as a React dep.
|
|
64
|
+
// We can't just pass queryArgs as one of the deps, because if it is passed
|
|
65
|
+
// as an object literal, then it will be a different object on each call even
|
|
66
|
+
// if the values remain the same.
|
|
67
|
+
const queryAsString = (0, _url.addQueryArgs)('', queryArgs);
|
|
68
|
+
const {
|
|
69
|
+
data: records,
|
|
70
|
+
...rest
|
|
71
|
+
} = (0, _useQuerySelect.default)(query => query(_.store).getEntityRecords(kind, name, queryArgs), [kind, name, queryAsString]);
|
|
72
|
+
return {
|
|
73
|
+
records,
|
|
74
|
+
...rest
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=use-entity-records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["__experimentalUseEntityRecords","kind","name","queryArgs","queryAsString","data","records","rest","query","coreStore","getEntityRecords"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAuBA;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,SAASA,8BAAT,CACdC,IADc,EAEdC,IAFc,EAI0B;AAAA,MADxCC,SACwC,uEADnB,EACmB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBD,SAAlB,CAAtB;AAEA,QAAM;AAAEE,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IACCA,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCT,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAFiC,EAGlC,CAAEF,IAAF,EAAQC,IAAR,EAAcE,aAAd,CAHkC,CAAnC;AAMA,SAAO;AACNE,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport { 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\n/**\n * Resolves the specified entity records.\n *\n * @param kind Kind of the requested entities.\n * @param name Name of the requested entities.\n * @param queryArgs HTTP query for the requested entities.\n * @example\n * ```js\n * import { useEntityRecord } 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 {EntityRecordsResolution<RecordType>} Entity records data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: unknown = {}\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\tquery( coreStore ).getEntityRecords( kind, name, queryArgs ),\n\t\t[ kind, name, queryAsString ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.META_SELECTORS = void 0;
|
|
9
|
+
exports.default = __experimentalUseQuerySelect;
|
|
10
|
+
|
|
11
|
+
var _data = require("@wordpress/data");
|
|
12
|
+
|
|
13
|
+
var _memoize = _interopRequireDefault(require("./memoize"));
|
|
14
|
+
|
|
15
|
+
var _constants = require("./constants");
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
|
|
25
|
+
exports.META_SELECTORS = META_SELECTORS;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Like useSelect, but the selectors return objects containing
|
|
29
|
+
* both the original data AND the resolution info.
|
|
30
|
+
*
|
|
31
|
+
* @param {Function} mapQuerySelect see useSelect
|
|
32
|
+
* @param {Array} deps see useSelect
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```js
|
|
36
|
+
* import { useQuerySelect } from '@wordpress/data';
|
|
37
|
+
* import { store as coreDataStore } from '@wordpress/core-data';
|
|
38
|
+
*
|
|
39
|
+
* function PageTitleDisplay( { id } ) {
|
|
40
|
+
* const { data: page, isResolving } = useQuerySelect( ( query ) => {
|
|
41
|
+
* return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )
|
|
42
|
+
* }, [ id ] );
|
|
43
|
+
*
|
|
44
|
+
* if ( isResolving ) {
|
|
45
|
+
* return 'Loading...';
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* return page.title;
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* // Rendered in the application:
|
|
52
|
+
* // <PageTitleDisplay id={ 10 } />
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* In the above example, when `PageTitleDisplay` is rendered into an
|
|
56
|
+
* application, the page and the resolution details will be retrieved from
|
|
57
|
+
* the store state using the `mapSelect` callback on `useQuerySelect`.
|
|
58
|
+
*
|
|
59
|
+
* If the id prop changes then any page in the state for that id is
|
|
60
|
+
* retrieved. If the id prop doesn't change and other props are passed in
|
|
61
|
+
* that do change, the title will not change because the dependency is just
|
|
62
|
+
* the id.
|
|
63
|
+
* @see useSelect
|
|
64
|
+
*
|
|
65
|
+
* @return {QuerySelectResponse} Queried data.
|
|
66
|
+
*/
|
|
67
|
+
function __experimentalUseQuerySelect(mapQuerySelect, deps) {
|
|
68
|
+
return (0, _data.useSelect)((select, registry) => {
|
|
69
|
+
const resolve = store => enrichSelectors(select(store));
|
|
70
|
+
|
|
71
|
+
return mapQuerySelect(resolve, registry);
|
|
72
|
+
}, deps);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Transform simple selectors into ones that return an object with the
|
|
77
|
+
* original return value AND the resolution info.
|
|
78
|
+
*
|
|
79
|
+
* @param {Object} selectors Selectors to enrich
|
|
80
|
+
* @return {EnrichedSelectors} Enriched selectors
|
|
81
|
+
*/
|
|
82
|
+
const enrichSelectors = (0, _memoize.default)(selectors => {
|
|
83
|
+
const resolvers = {};
|
|
84
|
+
|
|
85
|
+
for (const selectorName in selectors) {
|
|
86
|
+
if (META_SELECTORS.includes(selectorName)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Object.defineProperty(resolvers, selectorName, {
|
|
91
|
+
get: () => function () {
|
|
92
|
+
const {
|
|
93
|
+
getIsResolving,
|
|
94
|
+
hasFinishedResolution
|
|
95
|
+
} = selectors;
|
|
96
|
+
|
|
97
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
98
|
+
args[_key] = arguments[_key];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const isResolving = !!getIsResolving(selectorName, args);
|
|
102
|
+
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
|
|
103
|
+
const data = selectors[selectorName](...args);
|
|
104
|
+
let status;
|
|
105
|
+
|
|
106
|
+
if (isResolving) {
|
|
107
|
+
status = _constants.Status.Resolving;
|
|
108
|
+
} else if (hasResolved) {
|
|
109
|
+
if (data) {
|
|
110
|
+
status = _constants.Status.Success;
|
|
111
|
+
} else {
|
|
112
|
+
status = _constants.Status.Error;
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
status = _constants.Status.Idle;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
data,
|
|
120
|
+
status,
|
|
121
|
+
isResolving,
|
|
122
|
+
hasResolved
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return resolvers;
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=use-query-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAMA,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;;AAsBP;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,SAASC,4BAAT,CAAuCC,cAAvC,EAAuDC,IAAvD,EAA8D;AAC5E,SAAO,qBAAW,CAAEC,MAAF,EAAUC,QAAV,KAAwB;AACzC,UAAMC,OAAO,GAAKC,KAAF,IAAaC,eAAe,CAAEJ,MAAM,CAAEG,KAAF,CAAR,CAA5C;;AACA,WAAOL,cAAc,CAAEI,O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V,SAAP;AACA,CAtCuB,CAAxB","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 {\n\t/** the requested selector return value */\n\tdata: Object;\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 * @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 __experimentalUseQuerySelect( 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\ntype QuerySelector = ( ...args ) => QuerySelectResponse;\ninterface EnrichedSelectors {\n\t[ key: string ]: QuerySelector;\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: () => ( ...args ) => {\n\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\tconst hasResolved =\n\t\t\t\t\t! isResolving &&\n\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\tlet status;\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\tif ( data ) {\n\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tdata,\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t};\n\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} );\n"]}
|