@wordpress/core-data 4.3.0 → 4.4.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 +3 -0
- package/README.md +27 -3
- package/build/batch/default-processor.js +1 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +48 -11
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/hooks/use-entity-record.js +4 -4
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +4 -4
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/reducer.js +61 -9
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +31 -1
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +30 -4
- package/build/selectors.js.map +1 -1
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/build/utils/if-matching-action.js +4 -2
- package/build/utils/if-matching-action.js.map +1 -1
- package/build/utils/on-sub-key.js +3 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/replace-action.js +4 -2
- package/build/utils/replace-action.js.map +1 -1
- package/build-module/batch/default-processor.js +1 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +48 -11
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +4 -4
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +4 -4
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/reducer.js +58 -9
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +24 -0
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +26 -4
- package/build-module/selectors.js.map +1 -1
- package/build-module/types.js +2 -0
- package/build-module/types.js.map +1 -0
- package/build-module/utils/if-matching-action.js +4 -2
- package/build-module/utils/if-matching-action.js.map +1 -1
- package/build-module/utils/on-sub-key.js +3 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/replace-action.js +4 -2
- package/build-module/utils/replace-action.js.map +1 -1
- package/package.json +11 -11
- package/src/batch/default-processor.js +1 -0
- package/src/{entities.js → entities.ts} +7 -4
- package/src/fetch/__experimental-fetch-link-suggestions.js +56 -20
- package/src/fetch/test/__experimental-fetch-link-suggestions.js +39 -1
- package/src/hooks/use-entity-record.ts +4 -4
- package/src/hooks/use-entity-records.ts +4 -4
- package/src/hooks/use-query-select.ts +12 -7
- package/src/reducer.js +50 -7
- package/src/resolvers.js +14 -0
- package/src/{selectors.js → selectors.ts} +26 -4
- package/src/types.ts +3 -0
- package/src/utils/if-matching-action.js +4 -2
- package/src/utils/on-sub-key.js +3 -1
- package/src/utils/replace-action.js +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.4.0 (2022-04-08)
|
|
6
|
+
|
|
5
7
|
## 4.3.0 (2022-03-23)
|
|
6
8
|
|
|
7
9
|
### New Features
|
|
8
10
|
– The saveEntityRecord, saveEditedEntityRecord, and deleteEntityRecord actions now accept an optional throwOnError option (defaults to false). When set to true, any exceptions occurring when the action was executing are re-thrown, causing dispatch().saveEntityRecord() to reject with an error. ([#39258](https://github.com/WordPress/gutenberg/pull/39258))
|
|
11
|
+
- Added support for fetching block patterns and their categories, with the `getBlockPatterns` and `getBlockPatternCategories` selectors.
|
|
9
12
|
|
|
10
13
|
## 4.2.0 (2022-03-11)
|
|
11
14
|
|
package/README.md
CHANGED
|
@@ -251,7 +251,7 @@ an entity record, if any.
|
|
|
251
251
|
|
|
252
252
|
The following selectors are available on the object returned by `wp.data.select( 'core' )`:
|
|
253
253
|
|
|
254
|
-
<!-- START TOKEN(Autogenerated selectors|src/selectors.
|
|
254
|
+
<!-- START TOKEN(Autogenerated selectors|src/selectors.ts) -->
|
|
255
255
|
|
|
256
256
|
### canUser
|
|
257
257
|
|
|
@@ -341,6 +341,30 @@ _Returns_
|
|
|
341
341
|
|
|
342
342
|
- `?Array`: An array of autosaves for the post, or undefined if there is none.
|
|
343
343
|
|
|
344
|
+
### getBlockPatternCategories
|
|
345
|
+
|
|
346
|
+
Retrieve the list of registered block pattern categories.
|
|
347
|
+
|
|
348
|
+
_Parameters_
|
|
349
|
+
|
|
350
|
+
- _state_ `Object`: Data state.
|
|
351
|
+
|
|
352
|
+
_Returns_
|
|
353
|
+
|
|
354
|
+
- `Array`: Block pattern category list.
|
|
355
|
+
|
|
356
|
+
### getBlockPatterns
|
|
357
|
+
|
|
358
|
+
Retrieve the list of registered block patterns.
|
|
359
|
+
|
|
360
|
+
_Parameters_
|
|
361
|
+
|
|
362
|
+
- _state_ `Object`: Data state.
|
|
363
|
+
|
|
364
|
+
_Returns_
|
|
365
|
+
|
|
366
|
+
- `Array`: Block pattern list.
|
|
367
|
+
|
|
344
368
|
### getCurrentTheme
|
|
345
369
|
|
|
346
370
|
Return the current theme.
|
|
@@ -646,7 +670,7 @@ _Parameters_
|
|
|
646
670
|
- _state_ `Object`: State tree.
|
|
647
671
|
- _kind_ `string`: Entity kind.
|
|
648
672
|
- _name_ `string`: Entity name.
|
|
649
|
-
- _recordId_ `number`: Record ID.
|
|
673
|
+
- _recordId_ `number|string`: Record ID.
|
|
650
674
|
|
|
651
675
|
_Returns_
|
|
652
676
|
|
|
@@ -784,7 +808,7 @@ _Returns_
|
|
|
784
808
|
|
|
785
809
|
- `boolean`: Whether the entity record is saving or not.
|
|
786
810
|
|
|
787
|
-
<!-- END TOKEN(Autogenerated selectors|src/selectors.
|
|
811
|
+
<!-- END TOKEN(Autogenerated selectors|src/selectors.ts) -->
|
|
788
812
|
|
|
789
813
|
## Contributing to this package
|
|
790
814
|
|
|
@@ -45,7 +45,7 @@ async function defaultProcessor(requests) {
|
|
|
45
45
|
maxItems = preflightResponse.endpoints[0].args.requests.maxItems;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const results = [];
|
|
48
|
+
const results = []; // @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count.
|
|
49
49
|
|
|
50
50
|
for (const batchRequests of (0, _lodash.chunk)(requests, maxItems)) {
|
|
51
51
|
const batchResponse = await (0, _apiFetch.default)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/batch/default-processor.js"],"names":["maxItems","defaultProcessor","requests","preflightResponse","path","method","endpoints","args","results","batchRequests","batchResponse","data","validation","map","request","body","headers","batchResults","failed","responses","response","error","result","status","output","push"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,QAAQ,GAAG,IAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,eAAeC,gBAAf,CAAiCC,QAAjC,EAA4C;AAC1D,MAAKF,QAAQ,KAAK,IAAlB,EAAyB;AACxB,UAAMG,iBAAiB,GAAG,MAAM,uBAAU;AACzCC,MAAAA,IAAI,EAAE,WADmC;AAEzCC,MAAAA,MAAM,EAAE;AAFiC,KAAV,CAAhC;AAIAL,IAAAA,QAAQ,GAAGG,iBAAiB,CAACG,SAAlB,CAA6B,CAA7B,EAAiCC,IAAjC,CAAsCL,QAAtC,CAA+CF,QAA1D;AACA;;AAED,QAAMQ,OAAO,GAAG,EAAhB;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/batch/default-processor.js"],"names":["maxItems","defaultProcessor","requests","preflightResponse","path","method","endpoints","args","results","batchRequests","batchResponse","data","validation","map","request","body","headers","batchResults","failed","responses","response","error","result","status","output","push"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA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QAAQ,CAAEL;AAD4C,OAAlB,CAA7B,CAAf;AAGA,KAJD,MAIO;AACNE,MAAAA,YAAY,GAAGP,aAAa,CAACS,SAAd,CAAwBN,GAAxB,CAA+BO,QAAF,IAAgB;AAC3D,cAAME,MAAM,GAAG,EAAf;;AACA,YAAKF,QAAQ,CAACG,MAAT,IAAmB,GAAnB,IAA0BH,QAAQ,CAACG,MAAT,GAAkB,GAAjD,EAAuD;AACtDD,UAAAA,MAAM,CAACE,MAAP,GAAgBJ,QAAQ,CAACL,IAAzB;AACA,SAFD,MAEO;AACNO,UAAAA,MAAM,CAACD,KAAP,GAAeD,QAAQ,CAACL,IAAxB;AACA;;AACD,eAAOO,MAAP;AACA,OARc,CAAf;AASA;;AAEDd,IAAAA,OAAO,CAACiB,IAAR,CAAc,GAAGR,YAAjB;AACA;;AAED,SAAOT,OAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { chunk } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Maximum number of requests to place in a single batch request. Obtained by\n * sending a preflight OPTIONS request to /batch/v1/.\n *\n * @type {number?}\n */\nlet maxItems = null;\n\n/**\n * Default batch processor. Sends its input requests to /batch/v1.\n *\n * @param {Array} requests List of API requests to perform at once.\n *\n * @return {Promise} Promise that resolves to a list of objects containing\n * either `output` (if that request was succesful) or `error`\n * (if not ).\n */\nexport default async function defaultProcessor( requests ) {\n\tif ( maxItems === null ) {\n\t\tconst preflightResponse = await apiFetch( {\n\t\t\tpath: '/batch/v1',\n\t\t\tmethod: 'OPTIONS',\n\t\t} );\n\t\tmaxItems = preflightResponse.endpoints[ 0 ].args.requests.maxItems;\n\t}\n\n\tconst results = [];\n\n\t// @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count.\n\tfor ( const batchRequests of chunk( requests, maxItems ) ) {\n\t\tconst batchResponse = await apiFetch( {\n\t\t\tpath: '/batch/v1',\n\t\t\tmethod: 'POST',\n\t\t\tdata: {\n\t\t\t\tvalidation: 'require-all-validate',\n\t\t\t\trequests: batchRequests.map( ( request ) => ( {\n\t\t\t\t\tpath: request.path,\n\t\t\t\t\tbody: request.data, // Rename 'data' to 'body'.\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\theaders: request.headers,\n\t\t\t\t} ) ),\n\t\t\t},\n\t\t} );\n\n\t\tlet batchResults;\n\n\t\tif ( batchResponse.failed ) {\n\t\t\tbatchResults = batchResponse.responses.map( ( response ) => ( {\n\t\t\t\terror: response?.body,\n\t\t\t} ) );\n\t\t} else {\n\t\t\tbatchResults = batchResponse.responses.map( ( response ) => {\n\t\t\t\tconst result = {};\n\t\t\t\tif ( response.status >= 200 && response.status < 300 ) {\n\t\t\t\t\tresult.output = response.body;\n\t\t\t\t} else {\n\t\t\t\t\tresult.error = response.body;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t} );\n\t\t}\n\n\t\tresults.push( ...batchResults );\n\t}\n\n\treturn results;\n}\n"]}
|
package/build/entities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/entities.js"],"names":["DEFAULT_ENTITY_KEY","POST_RAW_ATTRIBUTES","rootEntitiesConfig","label","name","kind","baseURL","baseURLParams","_fields","join","getTitle","record","key","context","rawAttributes","plural","transientEdits","blocks","description","title","rendered","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","path","postType","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","String","id","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","getMethodName","prefix","usePlural","entityConfig","kindPrefix","nameSuffix","suffix","getOrLoadEntitiesConfig","select","dispatch","configs","getEntitiesConfig","length","loader"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAGO,M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XJ,SAAS,IAAIC,YAAJ,aAAIA,YAAJ,eAAIA,YAAY,CAAErC,MAA3B,GACG,wBAAY,uBAAWqC,YAAY,CAACrC,MAAxB,CAAZ,CADH,GAEGuC,UAHJ;AAIA,SAAQ,GAAGJ,MAAQ,GAAGG,UAAY,GAAGE,MAAQ,EAA7C;AACA,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAKnD,IAAF,IAAY,cAG5C;AAAA,MAHoD;AAC1DoD,IAAAA,MAD0D;AAE1DC,IAAAA;AAF0D,GAGpD;AACN,MAAIC,OAAO,GAAGF,MAAM,CAACG,iBAAP,CAA0BvD,IAA1B,CAAd;;AACA,MAAKsD,OAAO,IAAIA,OAAO,CAACE,MAAR,KAAmB,CAAnC,EAAuC;AACtC,WAAOF,OAAP;AACA;;AAED,QAAMG,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAEhB,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEyD,MAAP,EAAgB;AACf,WAAO,EAAP;AACA;;AAEDH,EAAAA,OAAO,GAAG,MAAMG,MAAM,CAACxC,YAAP,EAAhB;AACAoC,EAAAA,QAAQ,CAAE,0BAAaC,OAAb,CAAF,CAAR;AAEA,SAAOA,OAAP;AACA,CAlBM","sourcesContent":["/**\n * External dependencies\n */\nimport { upperFirst, camelCase, map, find, get, startCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { addEntities } from './actions';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tname: '__unstableBase',\n\t\tkind: 'root',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t].join( ',' ),\n\t\t},\n\t},\n\t{\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/settings',\n\t\tgetTitle: ( record ) => {\n\t\t\treturn get( record, [ 'title' ], __( 'Site Title' ) );\n\t\t},\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title', 'content' ],\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tname: 'navigationArea',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/block-navigation-areas',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'navigationAreas',\n\t\tlabel: __( 'Navigation Area' ),\n\t\tkey: 'name',\n\t\tgetTitle: ( record ) => record?.description,\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different than name.\n\t\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'plugin',\n\t},\n];\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n];\n\n/**\n * Returns a function to be used to retrieve extra edits to apply before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = ( persistedRecord, edits ) => {\n\tconst newEdits = {};\n\n\tif ( persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = await apiFetch( { path: '/wp/v2/types?context=view' } );\n\treturn map( postTypes, ( postType, name ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\tblocks: true,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate ? startCase( record.slug ) : String( record.id ) ),\n\t\t\t__unstablePrePersist: isTemplate ? undefined : prePersistPostType,\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn map( taxonomies, ( taxonomy, name ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the entity's getter method name given its kind and name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'theme', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} prefix Function prefix.\n * @param {boolean} usePlural Whether to use the plural form or not.\n *\n * @return {string} Method name\n */\nexport const getMethodName = (\n\tkind,\n\tname,\n\tprefix = 'get',\n\tusePlural = false\n) => {\n\tconst entityConfig = find( rootEntitiesConfig, { kind, name } );\n\tconst kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );\n\tconst nameSuffix =\n\t\tupperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );\n\tconst suffix =\n\t\tusePlural && entityConfig?.plural\n\t\t\t? upperFirst( camelCase( entityConfig.plural ) )\n\t\t\t: nameSuffix;\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n\n/**\n * Loads the kind entities into the store.\n *\n * @param {string} kind Kind\n *\n * @return {(thunkArgs: object) => Promise<Array>} Entities\n */\nexport const getOrLoadEntitiesConfig = ( kind ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tlet configs = select.getEntitiesConfig( kind );\n\tif ( configs && configs.length !== 0 ) {\n\t\treturn configs;\n\t}\n\n\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\tif ( ! loader ) {\n\t\treturn [];\n\t}\n\n\tconfigs = await loader.loadEntities();\n\tdispatch( addEntities( configs ) );\n\n\treturn configs;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/entities.ts"],"names":["DEFAULT_ENTITY_KEY","POST_RAW_ATTRIBUTES","rootEntitiesConfig","label","name","kind","baseURL","baseURLParams","_fields","join","getTitle","record","key","context","rawAttributes","plural","transientEdits","blocks","description","title","rendered","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","path","postType","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","String","id","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","getMethodName","prefix","usePlural","entityConfig","kindPrefix","nameSuffix","suffix","getOrLoadEntitiesConfig","select","dispatch","configs","getEntitiesConfig","length","loader"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAIO,MAAMA,kBAAkB,GAAG,IAA3B;;AAEP,MAAMC,mBAAmB,GAAG,CAAE,OAAF,EAAW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,wBAAY,uBAAWqC,YAAY,CAACrC,MAAxB,CAAZ,CADH,GAEGuC,UAHJ;AAIA,SAAQ,GAAGJ,MAAQ,GAAGG,UAAY,GAAGE,MAAQ,EAA7C;AACA,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAKnD,IAAF,IAAY,cAG5C;AAAA,MAHoD;AAC1DoD,IAAAA,MAD0D;AAE1DC,IAAAA;AAF0D,GAGpD;AACN,MAAIC,OAAO,GAAGF,MAAM,CAACG,iBAAP,CAA0BvD,IAA1B,CAAd;;AACA,MAAKsD,OAAO,IAAIA,OAAO,CAACE,MAAR,KAAmB,CAAnC,EAAuC;AACtC,WAAOF,OAAP;AACA;;AAED,QAAMG,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAEhB,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEyD,MAAP,EAAgB;AACf,WAAO,EAAP;AACA;;AAEDH,EAAAA,OAAO,GAAG,MAAMG,MAAM,CAACxC,YAAP,EAAhB;AACAoC,EAAAA,QAAQ,CAAE,0BAAaC,OAAb,CAAF,CAAR;AAEA,SAAOA,OAAP;AACA,CAlBM","sourcesContent":["/**\n * External dependencies\n */\nimport { upperFirst, camelCase, map, find, get, startCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { addEntities } from './actions';\nimport type { Post, Taxonomy, Type, Updatable } from './entity-types';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tname: '__unstableBase',\n\t\tkind: 'root',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t].join( ',' ),\n\t\t},\n\t},\n\t{\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/settings',\n\t\tgetTitle: ( record ) => {\n\t\t\treturn get( record, [ 'title' ], __( 'Site Title' ) );\n\t\t},\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title', 'content' ],\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tname: 'navigationArea',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/block-navigation-areas',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'navigationAreas',\n\t\tlabel: __( 'Navigation Area' ),\n\t\tkey: 'name',\n\t\tgetTitle: ( record ) => record?.description,\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different than name.\n\t\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'plugin',\n\t},\n];\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n];\n\n/**\n * Returns a function to be used to retrieve extra edits to apply before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = ( persistedRecord, edits ) => {\n\tconst newEdits = {} as Partial< Updatable< Post< 'edit' > > >;\n\n\tif ( persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = ( await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} ) ) as Record< string, Type< 'view' > >;\n\treturn map( postTypes, ( postType, name ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\tblocks: true,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate ? startCase( record.slug ) : String( record.id ) ),\n\t\t\t__unstablePrePersist: isTemplate ? undefined : prePersistPostType,\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = ( await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} ) ) as Record< string, Taxonomy< 'view' > >;\n\treturn map( taxonomies, ( taxonomy, name ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the entity's getter method name given its kind and name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'theme', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} prefix Function prefix.\n * @param {boolean} usePlural Whether to use the plural form or not.\n *\n * @return {string} Method name\n */\nexport const getMethodName = (\n\tkind,\n\tname,\n\tprefix = 'get',\n\tusePlural = false\n) => {\n\tconst entityConfig = find( rootEntitiesConfig, { kind, name } );\n\tconst kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );\n\tconst nameSuffix =\n\t\tupperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );\n\tconst suffix =\n\t\tusePlural && entityConfig?.plural\n\t\t\t? upperFirst( camelCase( entityConfig.plural ) )\n\t\t\t: nameSuffix;\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n\n/**\n * Loads the kind entities into the store.\n *\n * @param {string} kind Kind\n *\n * @return {(thunkArgs: object) => Promise<Array>} Entities\n */\nexport const getOrLoadEntitiesConfig = ( kind ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tlet configs = select.getEntitiesConfig( kind );\n\tif ( configs && configs.length !== 0 ) {\n\t\treturn configs;\n\t}\n\n\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\tif ( ! loader ) {\n\t\treturn [];\n\t}\n\n\tconfigs = await loader.loadEntities();\n\tdispatch( addEntities( configs ) );\n\n\treturn configs;\n};\n"]}
|
|
@@ -22,7 +22,7 @@ var _i18n = require("@wordpress/i18n");
|
|
|
22
22
|
/**
|
|
23
23
|
* Filters the search by type
|
|
24
24
|
*
|
|
25
|
-
* @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType
|
|
25
|
+
* @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -51,6 +51,17 @@ var _i18n = require("@wordpress/i18n");
|
|
|
51
51
|
* @property {WPKind} [kind] Link kind of post-type or taxonomy
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @typedef WPLinkSearchResultAugments
|
|
56
|
+
*
|
|
57
|
+
* @property {{kind: WPKind}} [meta] Contains kind information.
|
|
58
|
+
* @property {WPKind} [subtype] Optional subtype if it exists.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented
|
|
63
|
+
*/
|
|
64
|
+
|
|
54
65
|
/**
|
|
55
66
|
* @typedef WPEditorSettings
|
|
56
67
|
*
|
|
@@ -93,6 +104,8 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
93
104
|
const {
|
|
94
105
|
disablePostFormats = false
|
|
95
106
|
} = settings;
|
|
107
|
+
/** @type {Promise<WPLinkSearchResult>[]} */
|
|
108
|
+
|
|
96
109
|
const queries = [];
|
|
97
110
|
|
|
98
111
|
if (!type || type === 'post') {
|
|
@@ -135,7 +148,8 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
135
148
|
}
|
|
136
149
|
};
|
|
137
150
|
});
|
|
138
|
-
}).catch(() => [])
|
|
151
|
+
}).catch(() => []) // Fail by returning no results.
|
|
152
|
+
);
|
|
139
153
|
}
|
|
140
154
|
|
|
141
155
|
if (!disablePostFormats && (!type || type === 'post-format')) {
|
|
@@ -156,28 +170,51 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
156
170
|
}
|
|
157
171
|
};
|
|
158
172
|
});
|
|
159
|
-
}).catch(() => [])
|
|
173
|
+
}).catch(() => []) // Fail by returning no results.
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!type || type === 'attachment') {
|
|
178
|
+
queries.push((0, _apiFetch.default)({
|
|
179
|
+
path: (0, _url.addQueryArgs)('/wp/v2/media', {
|
|
180
|
+
search,
|
|
181
|
+
page,
|
|
182
|
+
per_page: perPage
|
|
183
|
+
})
|
|
184
|
+
}).then(results => {
|
|
185
|
+
return results.map(result => {
|
|
186
|
+
return { ...result,
|
|
187
|
+
meta: {
|
|
188
|
+
kind: 'media'
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
}).catch(() => []) // Fail by returning no results.
|
|
193
|
+
);
|
|
160
194
|
}
|
|
161
195
|
|
|
162
196
|
return Promise.all(queries).then(results => {
|
|
163
|
-
return results.reduce((
|
|
197
|
+
return results.reduce((
|
|
198
|
+
/** @type {WPLinkSearchResult[]} */
|
|
199
|
+
accumulator, current) => accumulator.concat(current), // Flatten list.
|
|
164
200
|
[]).filter(
|
|
165
201
|
/**
|
|
166
202
|
* @param {{ id: number }} result
|
|
167
203
|
*/
|
|
168
204
|
result => {
|
|
169
205
|
return !!result.id;
|
|
170
|
-
}).slice(0, perPage).map(
|
|
171
|
-
/**
|
|
172
|
-
|
|
173
|
-
*/
|
|
174
|
-
result => {
|
|
206
|
+
}).slice(0, perPage).map((
|
|
207
|
+
/** @type {WPLinkSearchResultAugmented} */
|
|
208
|
+
result) => {
|
|
175
209
|
var _result$meta;
|
|
176
210
|
|
|
211
|
+
const isMedia = result.type === 'attachment';
|
|
177
212
|
return {
|
|
178
213
|
id: result.id,
|
|
179
|
-
|
|
180
|
-
|
|
214
|
+
// @ts-ignore fix when we make this a TS file
|
|
215
|
+
url: isMedia ? result.source_url : result.url,
|
|
216
|
+
title: (0, _htmlEntities.decodeEntities)(isMedia ? // @ts-ignore fix when we make this a TS file
|
|
217
|
+
result.title.rendered : result.title || '') || (0, _i18n.__)('(no title)'),
|
|
181
218
|
type: result.subtype || result.type,
|
|
182
219
|
kind: result === null || result === void 0 ? void 0 : (_result$meta = result.meta) === null || _result$meta === void 0 ? void 0 : _result$meta.kind
|
|
183
220
|
};
|
|
@@ -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;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C,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, meta?: object, 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"]}
|
|
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","isMedia","url","source_url","title","rendered"],"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;AACA;;AAEA;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,QAC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;AAiCA,GAlCM,CAAP;AAmCA,CA/ID;;eAiJepB,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 { 'attachment' | '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 WPLinkSearchResultAugments\n *\n * @property {{kind: WPKind}} [meta] Contains kind information.\n * @property {WPKind} [subtype] Optional subtype if it exists.\n */\n\n/**\n * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented\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\t/** @type {Promise<WPLinkSearchResult>[]} */\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( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'media' },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( /** @type {WPLinkSearchResult[]} */ accumulator, current ) =>\n\t\t\t\t\taccumulator.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( ( /** @type {WPLinkSearchResultAugmented} */ result ) => {\n\t\t\t\tconst isMedia = result.type === 'attachment';\n\n\t\t\t\treturn {\n\t\t\t\t\tid: result.id,\n\t\t\t\t\t// @ts-ignore fix when we make this a TS file\n\t\t\t\t\turl: isMedia ? result.source_url : result.url,\n\t\t\t\t\ttitle:\n\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\tisMedia\n\t\t\t\t\t\t\t\t? // @ts-ignore fix when we make this a TS file\n\t\t\t\t\t\t\t\t result.title.rendered\n\t\t\t\t\t\t\t\t: result.title || ''\n\t\t\t\t\t\t) || __( '(no title)' ),\n\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t};\n\t\t\t} );\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
@@ -18,10 +18,10 @@ var _ = require("../");
|
|
|
18
18
|
/**
|
|
19
19
|
* Resolves the specified entity record.
|
|
20
20
|
*
|
|
21
|
-
* @param kind
|
|
22
|
-
* @param name
|
|
23
|
-
* @param recordId
|
|
24
|
-
* @param options
|
|
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
|
+
* @param options Hook options.
|
|
25
25
|
* @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
|
|
26
26
|
* @example
|
|
27
27
|
* ```js
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["__experimentalUseEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","coreStore","getEntityRecord"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AA2BA;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,6BAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCV,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANgC,EAOjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAPiC,CAAlC;AAUA,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 type { 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\ninterface Options {\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["__experimentalUseEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","coreStore","getEntityRecord"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AA2BA;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,6BAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCV,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANgC,EAOjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAPiC,CAAlC;AAUA,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 type { 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\ninterface Options {\n\tenabled: boolean;\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 * @param options Hook options.\n * @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.\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\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\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\t...rest,\n\t};\n}\n"]}
|
|
@@ -24,10 +24,10 @@ var _ = require("../");
|
|
|
24
24
|
/**
|
|
25
25
|
* Resolves the specified entity records.
|
|
26
26
|
*
|
|
27
|
-
* @param kind
|
|
28
|
-
* @param name
|
|
29
|
-
* @param queryArgs
|
|
30
|
-
* @param options
|
|
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
|
+
* @param options Hook options.
|
|
31
31
|
* @example
|
|
32
32
|
* ```js
|
|
33
33
|
* import { useEntityRecord } from '@wordpress/core-data';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["__experimentalUseEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAgCA;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,SAASA,8BAAT,CACdC,IADc,EAEdC,IAFc,EAK0B;AAAA,MAFxCC,SAEwC,uEAFD,EAEC;AAAA,MADxCC,OACwC,uEADrB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACqB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACNE,QAAAA,IAAI,EAAE;AADA,OAAP;AAGA;;AACD,WAAOG,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GARiC,EASlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CATkC,CAAnC;AAYA,SAAO;AACNG,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 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\ninterface 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 records.\n *\n * @param kind
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["__experimentalUseEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAgCA;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,SAASA,8BAAT,CACdC,IADc,EAEdC,IAFc,EAK0B;AAAA,MAFxCC,SAEwC,uEAFD,EAEC;AAAA,MADxCC,OACwC,uEADrB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACqB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACNE,QAAAA,IAAI,EAAE;AADA,OAAP;AAGA;;AACD,WAAOG,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GARiC,EASlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CATkC,CAAnC;AAYA,SAAO;AACNG,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 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\ninterface 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 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 * @param options Hook options.\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 Entity records data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecords< 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\tdata: [],\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"]}
|
|
@@ -1 +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,OAAF,EAAWD,QAAX,CAArB;AACA,GAHM,EAGJF,IAHI,CAAP;AAIA;;
|
|
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;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,IAAhB,CAFtB;AAGA,cAAMG,IAAI,GAAGZ,SAAS,CAAEE,YAAF,CAAT,CAA2B,GAAGO,IAA9B,CAAb;AAEA,YAAII,MAAJ;;AACA,YAAKH,WAAL,EAAmB;AAClBG,UAAAA,MAAM,GAAGC,kBAAOC,SAAhB;AACA,SAFD,MAEO,IAAKJ,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGC,kBAAOE,OAAhB;AACA,WAFD,MAEO;AACNH,YAAAA,MAAM,GAAGC,kBAAOG,KAAhB;AACA;AACD,SANM,MAMA;AACNJ,UAAAA,MAAM,GAAGC,kBAAOI,IAAhB;AACA;;AAED,eAAO;AACNN,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA5B8C,KAAhD;AA8BA;;AACD,SAAOV,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< 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 * @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\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: () => ( ...args: unknown[] ) => {\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} ) as EnrichedSelectors );\n"]}
|
package/build/reducer.js
CHANGED
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.autosaves = autosaves;
|
|
9
|
+
exports.blockPatternCategories = blockPatternCategories;
|
|
10
|
+
exports.blockPatterns = blockPatterns;
|
|
9
11
|
exports.currentGlobalStylesId = currentGlobalStylesId;
|
|
10
12
|
exports.currentTheme = currentTheme;
|
|
11
13
|
exports.currentUser = currentUser;
|
|
@@ -45,6 +47,8 @@ var _entities = require("./entities");
|
|
|
45
47
|
* Internal dependencies
|
|
46
48
|
*/
|
|
47
49
|
|
|
50
|
+
/** @typedef {import('./types').AnyFunction} AnyFunction */
|
|
51
|
+
|
|
48
52
|
/**
|
|
49
53
|
* Reducer managing terms state. Keyed by taxonomy slug, the value is either
|
|
50
54
|
* undefined (if no request has been made for given taxonomy), null (if a
|
|
@@ -239,7 +243,7 @@ function themeGlobalStyleVariations() {
|
|
|
239
243
|
*
|
|
240
244
|
* @param {Object} entityConfig Entity config.
|
|
241
245
|
*
|
|
242
|
-
* @return {
|
|
246
|
+
* @return {AnyFunction} Reducer.
|
|
243
247
|
*/
|
|
244
248
|
|
|
245
249
|
|
|
@@ -420,19 +424,36 @@ const entities = function () {
|
|
|
420
424
|
};
|
|
421
425
|
};
|
|
422
426
|
/**
|
|
423
|
-
*
|
|
427
|
+
* @typedef {Object} UndoStateMeta
|
|
424
428
|
*
|
|
425
|
-
* @
|
|
426
|
-
* @
|
|
429
|
+
* @property {number} offset Where in the undo stack we are.
|
|
430
|
+
* @property {Object} [flattenedUndo] Flattened form of undo stack.
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
/** @typedef {Array<Object> & UndoStateMeta} UndoState */
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* @type {UndoState}
|
|
427
437
|
*
|
|
428
|
-
* @
|
|
438
|
+
* @todo Given how we use this we might want to make a custom class for it.
|
|
429
439
|
*/
|
|
430
440
|
|
|
431
441
|
|
|
432
442
|
exports.entities = entities;
|
|
433
|
-
const UNDO_INITIAL_STATE = []
|
|
434
|
-
|
|
443
|
+
const UNDO_INITIAL_STATE = Object.assign([], {
|
|
444
|
+
offset: 0
|
|
445
|
+
});
|
|
446
|
+
/** @type {Object} */
|
|
447
|
+
|
|
435
448
|
let lastEditAction;
|
|
449
|
+
/**
|
|
450
|
+
* Reducer keeping track of entity edit undo history.
|
|
451
|
+
*
|
|
452
|
+
* @param {UndoState} state Current state.
|
|
453
|
+
* @param {Object} action Dispatched action.
|
|
454
|
+
*
|
|
455
|
+
* @return {UndoState} Updated state.
|
|
456
|
+
*/
|
|
436
457
|
|
|
437
458
|
function undo() {
|
|
438
459
|
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE;
|
|
@@ -460,10 +481,13 @@ function undo() {
|
|
|
460
481
|
};
|
|
461
482
|
}
|
|
462
483
|
}
|
|
484
|
+
/** @type {UndoState} */
|
|
485
|
+
|
|
463
486
|
|
|
464
487
|
let nextState;
|
|
465
488
|
|
|
466
489
|
if (isUndoOrRedo) {
|
|
490
|
+
// @ts-ignore we might consider using Object.assign({}, state)
|
|
467
491
|
nextState = [...state];
|
|
468
492
|
nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1);
|
|
469
493
|
|
|
@@ -499,6 +523,7 @@ function undo() {
|
|
|
499
523
|
|
|
500
524
|
|
|
501
525
|
if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) {
|
|
526
|
+
// @ts-ignore we might consider using Object.assign({}, state)
|
|
502
527
|
nextState = [...state];
|
|
503
528
|
nextState.flattenedUndo = { ...state.flattenedUndo,
|
|
504
529
|
...action.edits
|
|
@@ -508,7 +533,8 @@ function undo() {
|
|
|
508
533
|
} // Clear potential redos, because this only supports linear history.
|
|
509
534
|
|
|
510
535
|
|
|
511
|
-
nextState =
|
|
536
|
+
nextState = // @ts-ignore this needs additional cleanup, probably involving code-level changes
|
|
537
|
+
nextState || state.slice(0, state.offset || undefined);
|
|
512
538
|
nextState.offset = nextState.offset || 0;
|
|
513
539
|
nextState.pop();
|
|
514
540
|
|
|
@@ -623,6 +649,30 @@ function autosaves() {
|
|
|
623
649
|
return state;
|
|
624
650
|
}
|
|
625
651
|
|
|
652
|
+
function blockPatterns() {
|
|
653
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
654
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
655
|
+
|
|
656
|
+
switch (action.type) {
|
|
657
|
+
case 'RECEIVE_BLOCK_PATTERNS':
|
|
658
|
+
return action.patterns;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return state;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function blockPatternCategories() {
|
|
665
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
666
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
667
|
+
|
|
668
|
+
switch (action.type) {
|
|
669
|
+
case 'RECEIVE_BLOCK_PATTERN_CATEGORIES':
|
|
670
|
+
return action.categories;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return state;
|
|
674
|
+
}
|
|
675
|
+
|
|
626
676
|
var _default = (0, _data.combineReducers)({
|
|
627
677
|
terms,
|
|
628
678
|
users,
|
|
@@ -636,7 +686,9 @@ var _default = (0, _data.combineReducers)({
|
|
|
636
686
|
undo,
|
|
637
687
|
embedPreviews,
|
|
638
688
|
userPermissions,
|
|
639
|
-
autosaves
|
|
689
|
+
autosaves,
|
|
690
|
+
blockPatterns,
|
|
691
|
+
blockPatternCategories
|
|
640
692
|
});
|
|
641
693
|
|
|
642
694
|
exports.default = _default;
|