@wordpress/core-data 7.11.0 → 7.12.1-next.082ed6819.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 +2 -0
- package/README.md +2 -0
- package/build/entities.js +3 -1
- package/build/entities.js.map +1 -1
- package/build/entity-types/settings.js.map +1 -1
- package/build/hooks/use-entity-record.js +2 -0
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +3 -1
- package/build/private-apis.js.map +1 -1
- package/build/private-selectors.js +110 -1
- package/build/private-selectors.js.map +1 -1
- package/build/resolvers.js +44 -45
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +0 -19
- package/build/selectors.js.map +1 -1
- package/build/utils/index.js +7 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/receive-intermediate-results.js +8 -0
- package/build/utils/receive-intermediate-results.js.map +1 -0
- package/build-module/entities.js +3 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/settings.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +2 -0
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-selectors.js +107 -1
- package/build-module/private-selectors.js.map +1 -1
- package/build-module/resolvers.js +44 -44
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +0 -18
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/receive-intermediate-results.js +2 -0
- package/build-module/utils/receive-intermediate-results.js.map +1 -0
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-types/settings.d.ts +4 -0
- package/build-types/entity-types/settings.d.ts.map +1 -1
- package/build-types/hooks/use-entity-record.d.ts +2 -0
- package/build-types/hooks/use-entity-record.d.ts.map +1 -1
- package/build-types/index.d.ts +0 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +1 -2
- package/build-types/lock-unlock.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts +4 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/queried-data/reducer.d.ts +10 -2
- package/build-types/reducer.d.ts +24 -2
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -8
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts +0 -9
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -0
- package/build-types/utils/receive-intermediate-results.d.ts +2 -0
- package/build-types/utils/receive-intermediate-results.d.ts.map +1 -0
- package/package.json +18 -18
- package/src/entities.js +4 -0
- package/src/entity-types/settings.ts +4 -0
- package/src/hooks/use-entity-record.ts +2 -0
- package/src/private-apis.js +2 -0
- package/src/private-selectors.ts +149 -1
- package/src/resolvers.js +66 -61
- package/src/selectors.ts +0 -32
- package/src/utils/index.js +1 -0
- package/src/utils/receive-intermediate-results.js +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- /package/src/{lock-unlock.js → lock-unlock.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","EMPTY_OBJECT","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","editOptions","save","saveOptions","throwOnError","editedRecord","hasEdits","edits","select","getEditedEntityRecord","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** The edits to the edited entity record */\n\tedits: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useCallback } from 'react';\n * import { useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\teditedRecord: EMPTY_OBJECT,\n\t\t\t\t\thasEdits: false,\n\t\t\t\t\tedits: EMPTY_OBJECT,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\tedits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AA+CxC,MAAMC,YAAY,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CACtCC,IAAY,EACZC,IAAY,EACZC,QAAyB,EACzBC,OAAgB,GAAG;EAAEC,OAAO,EAAE;AAAK,CAAC,EACG;EACvC,MAAM;IAAEC,gBAAgB;IAAEC;EAAuB,CAAC,GACjDf,WAAW,CAAEM,SAAU,CAAC;EAEzB,MAAMU,SAAS,GAAGb,OAAO,CACxB,OAAQ;IACPc,IAAI,EAAEA,CAAEC,MAAM,EAAEC,WAAgB,GAAG,CAAC,CAAC,KACpCL,gBAAgB,CAAEL,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEO,MAAM,EAAEC,WAAY,CAAC;IAC9DC,IAAI,EAAEA,CAAEC,WAAgB,GAAG,CAAC,CAAC,KAC5BN,sBAAsB,CAAEN,IAA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AO,CACxC,CAAC;EAED,OAAO;IACNK,MAAM;IACNK,YAAY;IACZC,QAAQ;IACRC,KAAK;IACL,GAAGM,eAAe;IAClB,GAAGf;EACJ,CAAC;AACF;AAEA,OAAO,SAASkB,6BAA6BA,CAC5CzB,IAAY,EACZC,IAAY,EACZC,QAAa,EACbC,OAAY,EACX;EACDV,UAAU,CAAE,uCAAuC,EAAE;IACpDiC,WAAW,EAAE,yBAAyB;IACtCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAO5B,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","EMPTY_OBJECT","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","editOptions","save","saveOptions","throwOnError","editedRecord","hasEdits","edits","select","getEditedEntityRecord","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** The edits to the edited entity record */\n\tedits: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useCallback } from 'react';\n * import { useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n *\t\t\t\t__nextHasNoMarginBottom\n *\t\t\t\t__next40pxDefaultSize\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\teditedRecord: EMPTY_OBJECT,\n\t\t\t\t\thasEdits: false,\n\t\t\t\t\tedits: EMPTY_OBJECT,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\tedits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AA+CxC,MAAMC,YAAY,GAAG,CAAC,CA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H,OAAO5B,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/core-data/src/lock-unlock.
|
|
1
|
+
{"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/core-data/src/lock-unlock.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/core-data'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAE1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,+HAA+H,EAC/H,sBACD,CAAC","ignoreList":[]}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useEntityRecordsWithPermissions } from './hooks/use-entity-records';
|
|
5
|
+
import { RECEIVE_INTERMEDIATE_RESULTS } from './utils';
|
|
5
6
|
import { lock } from './lock-unlock';
|
|
6
7
|
export const privateApis = {};
|
|
7
8
|
lock(privateApis, {
|
|
8
|
-
useEntityRecordsWithPermissions
|
|
9
|
+
useEntityRecordsWithPermissions,
|
|
10
|
+
RECEIVE_INTERMEDIATE_RESULTS
|
|
9
11
|
});
|
|
10
12
|
//# sourceMappingURL=private-apis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEntityRecordsWithPermissions","lock","privateApis"],"sources":["@wordpress/core-data/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useEntityRecordsWithPermissions } from './hooks/use-entity-records';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseEntityRecordsWithPermissions,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,+BAA+B,QAAQ,4BAA4B;AAC5E,SAASC,IAAI,QAAQ,eAAe;AAEpC,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BD,IAAI,CAAEC,WAAW,EAAE;
|
|
1
|
+
{"version":3,"names":["useEntityRecordsWithPermissions","RECEIVE_INTERMEDIATE_RESULTS","lock","privateApis"],"sources":["@wordpress/core-data/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useEntityRecordsWithPermissions } from './hooks/use-entity-records';\nimport { RECEIVE_INTERMEDIATE_RESULTS } from './utils';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseEntityRecordsWithPermissions,\n\tRECEIVE_INTERMEDIATE_RESULTS,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,+BAA+B,QAAQ,4BAA4B;AAC5E,SAASC,4BAA4B,QAAQ,SAAS;AACtD,SAASC,IAAI,QAAQ,eAAe;AAEpC,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BD,IAAI,CAAEC,WAAW,EAAE;EAClBH,+BAA+B;EAC/BC;AACD,CAAE,CAAC","ignoreList":[]}
|
|
@@ -6,8 +6,9 @@ import { createSelector, createRegistrySelector } from '@wordpress/data';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
import { getDefaultTemplateId, getEntityRecord } from './selectors';
|
|
10
10
|
import { STORE_NAME } from './name';
|
|
11
|
+
import { unlock } from './lock-unlock';
|
|
11
12
|
/**
|
|
12
13
|
* Returns the previous edit from the current undo offset
|
|
13
14
|
* for the entity records edits history, if any.
|
|
@@ -78,4 +79,109 @@ export function getRegisteredPostMeta(state, postType) {
|
|
|
78
79
|
var _state$registeredPost;
|
|
79
80
|
return (_state$registeredPost = state.registeredPostMeta?.[postType]) !== null && _state$registeredPost !== void 0 ? _state$registeredPost : {};
|
|
80
81
|
}
|
|
82
|
+
function normalizePageId(value) {
|
|
83
|
+
if (!value || !['number', 'string'].includes(typeof value)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// We also need to check if it's not zero (`'0'`).
|
|
88
|
+
if (Number(value) === 0) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return value.toString();
|
|
92
|
+
}
|
|
93
|
+
export const getHomePage = createRegistrySelector(select => createSelector(() => {
|
|
94
|
+
const siteData = select(STORE_NAME).getEntityRecord('root', 'site');
|
|
95
|
+
if (!siteData) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const homepageId = siteData?.show_on_front === 'page' ? normalizePageId(siteData.page_on_front) : null;
|
|
99
|
+
if (homepageId) {
|
|
100
|
+
return {
|
|
101
|
+
postType: 'page',
|
|
102
|
+
postId: homepageId
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const frontPageTemplateId = select(STORE_NAME).getDefaultTemplateId({
|
|
106
|
+
slug: 'front-page'
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
postType: 'wp_template',
|
|
110
|
+
postId: frontPageTemplateId
|
|
111
|
+
};
|
|
112
|
+
}, state => [
|
|
113
|
+
// @ts-expect-error
|
|
114
|
+
getEntityRecord(state, 'root', 'site'), getDefaultTemplateId(state, {
|
|
115
|
+
slug: 'front-page'
|
|
116
|
+
})]));
|
|
117
|
+
export const getPostsPageId = createRegistrySelector(select => () => {
|
|
118
|
+
const siteData = select(STORE_NAME).getEntityRecord('root', 'site');
|
|
119
|
+
return siteData?.show_on_front === 'page' ? normalizePageId(siteData.page_for_posts) : null;
|
|
120
|
+
});
|
|
121
|
+
export const getTemplateId = createRegistrySelector(select => (state, postType, postId) => {
|
|
122
|
+
const homepage = unlock(select(STORE_NAME)).getHomePage();
|
|
123
|
+
if (!homepage) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// For the front page, we always use the front page template if existing.
|
|
128
|
+
if (postType === 'page' && postType === homepage?.postType && postId.toString() === homepage?.postId) {
|
|
129
|
+
// The /lookup endpoint cannot currently handle a lookup
|
|
130
|
+
// when a page is set as the front page, so specifically in
|
|
131
|
+
// that case, we want to check if there is a front page
|
|
132
|
+
// template, and instead of falling back to the home
|
|
133
|
+
// template, we want to fall back to the page template.
|
|
134
|
+
const templates = select(STORE_NAME).getEntityRecords('postType', 'wp_template', {
|
|
135
|
+
per_page: -1
|
|
136
|
+
});
|
|
137
|
+
if (!templates) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const id = templates.find(({
|
|
141
|
+
slug
|
|
142
|
+
}) => slug === 'front-page')?.id;
|
|
143
|
+
if (id) {
|
|
144
|
+
return id;
|
|
145
|
+
}
|
|
146
|
+
// If no front page template is found, continue with the
|
|
147
|
+
// logic below (fetching the page template).
|
|
148
|
+
}
|
|
149
|
+
const editedEntity = select(STORE_NAME).getEditedEntityRecord('postType', postType, postId);
|
|
150
|
+
if (!editedEntity) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const postsPageId = unlock(select(STORE_NAME)).getPostsPageId();
|
|
154
|
+
// Check if the current page is the posts page.
|
|
155
|
+
if (postType === 'page' && postsPageId === postId.toString()) {
|
|
156
|
+
return select(STORE_NAME).getDefaultTemplateId({
|
|
157
|
+
slug: 'home'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// First see if the post/page has an assigned template and fetch it.
|
|
161
|
+
const currentTemplateSlug = editedEntity.template;
|
|
162
|
+
if (currentTemplateSlug) {
|
|
163
|
+
const currentTemplate = select(STORE_NAME).getEntityRecords('postType', 'wp_template', {
|
|
164
|
+
per_page: -1
|
|
165
|
+
})?.find(({
|
|
166
|
+
slug
|
|
167
|
+
}) => slug === currentTemplateSlug);
|
|
168
|
+
if (currentTemplate) {
|
|
169
|
+
return currentTemplate.id;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// If no template is assigned, use the default template.
|
|
173
|
+
let slugToCheck;
|
|
174
|
+
// In `draft` status we might not have a slug available, so we use the `single`
|
|
175
|
+
// post type templates slug(ex page, single-post, single-product etc..).
|
|
176
|
+
// Pages do not need the `single` prefix in the slug to be prioritized
|
|
177
|
+
// through template hierarchy.
|
|
178
|
+
if (editedEntity.slug) {
|
|
179
|
+
slugToCheck = postType === 'page' ? `${postType}-${editedEntity.slug}` : `single-${postType}-${editedEntity.slug}`;
|
|
180
|
+
} else {
|
|
181
|
+
slugToCheck = postType === 'page' ? 'page' : `single-${postType}`;
|
|
182
|
+
}
|
|
183
|
+
return select(STORE_NAME).getDefaultTemplateId({
|
|
184
|
+
slug: slugToCheck
|
|
185
|
+
});
|
|
186
|
+
});
|
|
81
187
|
//# sourceMappingURL=private-selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSelector","createRegistrySelector","STORE_NAME","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","select","postType","getBlockPatterns","filter","postTypes","Array","isArray","includes","getEntityRecordsPermissions","kind","name","ids","normalizedIds","map","id","delete","canUser","update","userPermissions","getEntityRecordPermissions","getRegisteredPostMeta","_state$registeredPost","registeredPostMeta"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { State } from './selectors';\nimport { STORE_NAME } from './name';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t( state: State, kind: string, name: string, ids: string[] ) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;;AAExE;AACA;AACA;;AAEA,SAASC,UAAU,QAAQ,QAAQ;AAInC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAEC,KAAY,EAAG;EAC9C,OAAOA,KAAK,CAACC,WAAW;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CACtCF,KAAY,EACkB;EAC9B,OAAOA,KAAK,CAACG,oBAAoB;AAClC;AAEA,OAAO,MAAMC,2BAA2B,GAAGP,sBAAsB,CAC9DQ,MAAW,IACZT,cAAc,CACb,CAAEI,KAAK,EAAEM,QAAQ,KAChBD,MAAM,CAAEP,UAAW,CAAC,CAClBS,gBAAgB,CAAC,CAAC,CAClBC,MAAM,CACN,CAAE;EAAEC;AAAU,CAAC,KACd,CAAEA,SAAS,IACTC,KAAK,CAACC,OAAO,CAAEF,SAAU,CAAC,IAC3BA,SAAS,CAACG,QAAQ,CAAEN,QAAS,CAChC,CAAC,EACH,MAAM,CAAED,MAAM,CAAEP,UAAW,CAAC,CAACS,gBAAgB,CAAC,CAAC,CAChD,CACF,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMM,2BAA2B,GAAGhB,sBAAsB,CAAIQ,MAAM,IAC1ET,cAAc,CACb,CAAEI,KAAY,EAAEc,IAAY,EAAEC,IAAY,EAAEC,GAAa,KAAM;EAC9D,MAAMC,aAAa,GAAGP,KAAK,CAACC,OAAO,CAAEK,GAAI,CAAC,GAAGA,GAAG,GAAG,CAAEA,GAAG,CAAE;EAC1D,OAAOC,aAAa,CAACC,GAAG,CAAIC,EAAE,KAAQ;IACrCC,MAAM,EAAEf,MAAM,CAAEP,UAAW,CAAC,CAACuB,OAAO,CAAE,QAAQ,EAAE;MAC/CP,IAAI;MACJC,IAAI;MACJI;IACD,CAAE,CAAC;IACHG,MAAM,EAAEjB,MAAM,CAAEP,UAAW,CAAC,CAACuB,OAAO,CAAE,QAAQ,EAAE;MAC/CP,IAAI;MACJC,IAAI;MACJI;IACD,CAAE;EACH,CAAC,CAAG,CAAC;AACN,CAAC,EACCnB,KAAK,IAAM,CAAEA,KAAK,CAACuB,eAAe,CACrC,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CACzCxB,KAAY,EACZc,IAAY,EACZC,IAAY,EACZI,EAAU,EACT;EACD,OAAON,2BAA2B,CAAEb,KAAK,EAAEc,IAAI,EAAEC,IAAI,EAAEI,EAAG,CAAC,CAAE,CAAC,CAAE;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,qBAAqBA,CAAEzB,KAAY,EAAEM,QAAgB,EAAG;EAAA,IAAAoB,qBAAA;EACvE,QAAAA,qBAAA,GAAO1B,KAAK,CAAC2B,kBAAkB,GAAIrB,QAAQ,CAAE,cAAAoB,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAAC;AACpD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createSelector","createRegistrySelector","getDefaultTemplateId","getEntityRecord","STORE_NAME","unlock","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","select","postType","getBlockPatterns","filter","postTypes","Array","isArray","includes","getEntityRecordsPermissions","kind","name","ids","normalizedIds","map","id","delete","canUser","update","userPermissions","getEntityRecordPermissions","getRegisteredPostMeta","_state$registeredPost","registeredPostMeta","normalizePageId","value","Number","toString","getHomePage","siteData","homepageId","show_on_front","page_on_front","postId","frontPageTemplateId","slug","getPostsPageId","page_for_posts","getTemplateId","homepage","templates","getEntityRecords","per_page","find","editedEntity","getEditedEntityRecord","postsPageId","currentTemplateSlug","template","currentTemplate","slugToCheck"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getDefaultTemplateId, getEntityRecord, type State } from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t( state: State, kind: string, name: string, ids: string[] ) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'site'\n\t\t\t) as SiteData | undefined;\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\treturn { postType: 'wp_template', postId: frontPageTemplateId };\n\t\t},\n\t\t( state ) => [\n\t\t\t// @ts-expect-error\n\t\t\tgetEntityRecord( state, 'root', 'site' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst siteData = select( STORE_NAME ).getEntityRecord( 'root', 'site' ) as\n\t\t| SiteData\n\t\t| undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst currentTemplate = select( STORE_NAME )\n\t\t\t\t.getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} )\n\t\t\t\t?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\tif ( currentTemplate ) {\n\t\t\t\treturn currentTemplate.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;;AAExE;AACA;AACA;AACA,SAASC,oBAAoB,EAAEC,eAAe,QAAoB,aAAa;AAC/E,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,MAAM,Q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,GACVhD,QAAQ,KAAK,MAAM,GAChB,GAAIA,QAAQ,IAAM0C,YAAY,CAACT,IAAI,EAAG,GACtC,UAAWjC,QAAQ,IAAM0C,YAAY,CAACT,IAAI,EAAG;EAClD,CAAC,MAAM;IACNe,WAAW,GAAGhD,QAAQ,KAAK,MAAM,GAAG,MAAM,GAAG,UAAWA,QAAQ,EAAG;EACpE;EACA,OAAOD,MAAM,CAAER,UAAW,CAAC,CAACF,oBAAoB,CAAE;IACjD4C,IAAI,EAAEe;EACP,CAAE,CAAC;AACJ,CACD,CAAC","ignoreList":[]}
|
|
@@ -16,7 +16,7 @@ import apiFetch from '@wordpress/api-fetch';
|
|
|
16
16
|
*/
|
|
17
17
|
import { STORE_NAME } from './name';
|
|
18
18
|
import { additionalEntityConfigLoaders, DEFAULT_ENTITY_KEY } from './entities';
|
|
19
|
-
import { forwardResolver, getNormalizedCommaSeparable, getUserPermissionCacheKey, getUserPermissionsFromAllowHeader, ALLOWED_RESOURCE_ACTIONS } from './utils';
|
|
19
|
+
import { forwardResolver, getNormalizedCommaSeparable, getUserPermissionCacheKey, getUserPermissionsFromAllowHeader, ALLOWED_RESOURCE_ACTIONS, RECEIVE_INTERMEDIATE_RESULTS } from './utils';
|
|
20
20
|
import { getSyncProvider } from './sync';
|
|
21
21
|
import { fetchBlockPatterns } from './fetch';
|
|
22
22
|
|
|
@@ -196,6 +196,10 @@ export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
196
196
|
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
|
|
197
197
|
exclusive: false
|
|
198
198
|
});
|
|
199
|
+
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
200
|
+
function getResolutionsArgs(records) {
|
|
201
|
+
return records.filter(record => record?.[key]).map(record => [kind, name, record[key]]);
|
|
202
|
+
}
|
|
199
203
|
try {
|
|
200
204
|
if (query._fields) {
|
|
201
205
|
// If requesting specific fields, items and query association to said
|
|
@@ -210,7 +214,8 @@ export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
210
214
|
...entityConfig.baseURLParams,
|
|
211
215
|
...query
|
|
212
216
|
});
|
|
213
|
-
let records,
|
|
217
|
+
let records = [],
|
|
218
|
+
meta;
|
|
214
219
|
if (entityConfig.supportsPagination && query.per_page !== -1) {
|
|
215
220
|
const response = await apiFetch({
|
|
216
221
|
path,
|
|
@@ -221,6 +226,30 @@ export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
221
226
|
totalItems: parseInt(response.headers.get('X-WP-Total')),
|
|
222
227
|
totalPages: parseInt(response.headers.get('X-WP-TotalPages'))
|
|
223
228
|
};
|
|
229
|
+
} else if (query.per_page === -1 && query[RECEIVE_INTERMEDIATE_RESULTS] === true) {
|
|
230
|
+
let page = 1;
|
|
231
|
+
let totalPages;
|
|
232
|
+
do {
|
|
233
|
+
const response = await apiFetch({
|
|
234
|
+
path: addQueryArgs(path, {
|
|
235
|
+
page,
|
|
236
|
+
per_page: 100
|
|
237
|
+
}),
|
|
238
|
+
parse: false
|
|
239
|
+
});
|
|
240
|
+
const pageRecords = Object.values(await response.json());
|
|
241
|
+
totalPages = parseInt(response.headers.get('X-WP-TotalPages'));
|
|
242
|
+
records.push(...pageRecords);
|
|
243
|
+
registry.batch(() => {
|
|
244
|
+
dispatch.receiveEntityRecords(kind, name, records, query);
|
|
245
|
+
dispatch.finishResolutions('getEntityRecord', getResolutionsArgs(pageRecords));
|
|
246
|
+
});
|
|
247
|
+
page++;
|
|
248
|
+
} while (page <= totalPages);
|
|
249
|
+
meta = {
|
|
250
|
+
totalItems: records.length,
|
|
251
|
+
totalPages: 1
|
|
252
|
+
};
|
|
224
253
|
} else {
|
|
225
254
|
records = Object.values(await apiFetch({
|
|
226
255
|
path
|
|
@@ -252,8 +281,6 @@ export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
252
281
|
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
253
282
|
// See https://github.com/WordPress/gutenberg/pull/64504
|
|
254
283
|
if (!query?._fields && !query.context) {
|
|
255
|
-
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
256
|
-
const resolutionsArgs = records.filter(record => record?.[key]).map(record => [kind, name, record[key]]);
|
|
257
284
|
const targetHints = records.filter(record => record?.[key]).map(record => ({
|
|
258
285
|
id: record[key],
|
|
259
286
|
permissions: getUserPermissionsFromAllowHeader(record?._links?.self?.[0].targetHints.allow)
|
|
@@ -275,7 +302,7 @@ export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
275
302
|
}
|
|
276
303
|
}
|
|
277
304
|
dispatch.receiveUserPermissions(receiveUserPermissionArgs);
|
|
278
|
-
dispatch.finishResolutions('getEntityRecord',
|
|
305
|
+
dispatch.finishResolutions('getEntityRecord', getResolutionsArgs(records));
|
|
279
306
|
dispatch.finishResolutions('canUser', canUserResolutionsArgs);
|
|
280
307
|
}
|
|
281
308
|
dispatch.__unstableReleaseStoreLock(lock);
|
|
@@ -457,43 +484,6 @@ export const getAutosave = (postType, postId) => async ({
|
|
|
457
484
|
}) => {
|
|
458
485
|
await resolveSelect.getAutosaves(postType, postId);
|
|
459
486
|
};
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Retrieve the frontend template used for a given link.
|
|
463
|
-
*
|
|
464
|
-
* @param {string} link Link.
|
|
465
|
-
*/
|
|
466
|
-
export const __experimentalGetTemplateForLink = link => async ({
|
|
467
|
-
dispatch,
|
|
468
|
-
resolveSelect
|
|
469
|
-
}) => {
|
|
470
|
-
let template;
|
|
471
|
-
try {
|
|
472
|
-
// This is NOT calling a REST endpoint but rather ends up with a response from
|
|
473
|
-
// an Ajax function which has a different shape from a WP_REST_Response.
|
|
474
|
-
template = await apiFetch({
|
|
475
|
-
url: addQueryArgs(link, {
|
|
476
|
-
'_wp-find-template': true
|
|
477
|
-
})
|
|
478
|
-
}).then(({
|
|
479
|
-
data
|
|
480
|
-
}) => data);
|
|
481
|
-
} catch (e) {
|
|
482
|
-
// For non-FSE themes, it is possible that this request returns an error.
|
|
483
|
-
}
|
|
484
|
-
if (!template) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id);
|
|
488
|
-
if (record) {
|
|
489
|
-
dispatch.receiveEntityRecords('postType', 'wp_template', [record], {
|
|
490
|
-
'find-template': link
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
__experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
495
|
-
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
496
|
-
};
|
|
497
487
|
export const __experimentalGetCurrentGlobalStylesId = () => async ({
|
|
498
488
|
dispatch,
|
|
499
489
|
resolveSelect
|
|
@@ -626,14 +616,24 @@ export const getNavigationFallbackId = () => async ({
|
|
|
626
616
|
});
|
|
627
617
|
};
|
|
628
618
|
export const getDefaultTemplateId = query => async ({
|
|
629
|
-
dispatch
|
|
619
|
+
dispatch,
|
|
620
|
+
registry,
|
|
621
|
+
resolveSelect
|
|
630
622
|
}) => {
|
|
631
623
|
const template = await apiFetch({
|
|
632
624
|
path: addQueryArgs('/wp/v2/templates/lookup', query)
|
|
633
625
|
});
|
|
626
|
+
// Wait for the the entities config to be loaded, otherwise receiving
|
|
627
|
+
// the template as an entity will not work.
|
|
628
|
+
await resolveSelect.getEntitiesConfig('postType');
|
|
634
629
|
// Endpoint may return an empty object if no template is found.
|
|
635
630
|
if (template?.id) {
|
|
636
|
-
|
|
631
|
+
registry.batch(() => {
|
|
632
|
+
dispatch.receiveDefaultTemplateId(query, template.id);
|
|
633
|
+
dispatch.receiveEntityRecords('postType', 'wp_template', [template]);
|
|
634
|
+
// Avoid further network requests.
|
|
635
|
+
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_template', template.id]);
|
|
636
|
+
});
|
|
637
637
|
}
|
|
638
638
|
};
|
|
639
639
|
|