@wordpress/core-data 7.12.0 → 7.13.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 +1 -1
- package/build/entities.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/private-selectors.js +110 -1
- package/build/private-selectors.js.map +1 -1
- package/build-module/entities.js +1 -1
- package/build-module/entities.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/private-selectors.js +107 -1
- package/build-module/private-selectors.js.map +1 -1
- package/build-types/entities.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/private-selectors.d.ts +4 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/entities.js +2 -0
- package/src/hooks/use-entity-record.ts +2 -0
- package/src/private-selectors.ts +149 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -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,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAE;MAC7CW,YAA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Y;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,CAAC;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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C,QAAQ,EAAEC,OAAQ,CAAC;AACxD","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,C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istrySelector","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,QAAQ,eAAe;AAItC;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,GAAGV,sBAAsB,CAC9DW,MAAW,IACZZ,cAAc,CACb,CAAEO,KAAK,EAAEM,QAAQ,KAChBD,MAAM,CAAER,UAAW,CAAC,CAClBU,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,CAAER,UAAW,CAAC,CAACU,gBAAgB,CAAC,CAAC,CAChD,CACF,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMM,2BAA2B,GAAGnB,sBAAsB,CAAIW,MAAM,IAC1EZ,cAAc,CACb,CAAEO,KAAY,EAAEc,IAAY,EAAEC,IAAY,EAAEC,GAAa,KAAM;EAC9D,MAAMC,aAAa,GAAGP,KAAK,CAACC,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G;IAC1B,MAAME,eAAe,GAAGhD,MAAM,CAAER,UAAW,CAAC,CAC1CgD,gBAAgB,CAAE,UAAU,EAAE,aAAa,EAAE;MAC7CC,QAAQ,EAAE,CAAC;IACZ,CAAE,CAAC,EACDC,IAAI,CAAE,CAAE;MAAER;IAAK,CAAC,KAAMA,IAAI,KAAKY,mBAAoB,CAAC;IACvD,IAAKE,eAAe,EAAG;MACtB,OAAOA,eAAe,CAAClC,EAAE;IAC1B;EACD;EACA;EACA,IAAImC,WAAW;EACf;EACA;EACA;EACA;EACA,IAAKN,YAAY,CAACT,IAAI,EAAG;IACxBe,WAAW,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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAYA,sCAAuC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAYA,sCAAuC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0ME;AAEF;;;;;;;;;;KASE;AASK,0EAqBN;AAkMM,oCANI,MAAM,QACN,MAAM,WACN,MAAM,GAEL,MAAM,CAMjB;AA7KD;;;;GAIG;AACH,sDAyEC;AAuBD;;;;GAIG;AACH,gDA2CC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-entity-record.d.ts","sourceRoot":"","sources":["../../src/hooks/use-entity-record.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,WAAW,sBAAsB,CAAE,UAAU;IAClD,kCAAkC;IAClC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAE1B,+BAA+B;IAC/B,YAAY,EAAE,OAAO,CAAE,UAAU,CAAE,CAAC;IAEpC,4CAA4C;IAC5C,KAAK,EAAE,OAAO,CAAE,UAAU,CAAE,CAAC;IAE7B,iEAAiE;IACjE,IAAI,EAAE,CAAE,IAAI,EAAE,OAAO,CAAE,UAAU,CAAE,KAAM,IAAI,CAAC;IAE9C,sCAAsC;IACtC,IAAI,EAAE,MAAM,OAAO,CAAE,IAAI,CAAE,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACvB;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;CACjB;AAID
|
|
1
|
+
{"version":3,"file":"use-entity-record.d.ts","sourceRoot":"","sources":["../../src/hooks/use-entity-record.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CA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ecordKey = string | number;
|
|
6
6
|
/**
|
|
7
7
|
* Returns the previous edit from the current undo offset
|
|
@@ -44,5 +44,8 @@ export declare function getEntityRecordPermissions(state: State, kind: string, n
|
|
|
44
44
|
* @return Registered post meta fields.
|
|
45
45
|
*/
|
|
46
46
|
export declare function getRegisteredPostMeta(state: State, postType: string): Object;
|
|
47
|
+
export declare const getHomePage: Function;
|
|
48
|
+
export declare const getPostsPageId: Function;
|
|
49
|
+
export declare const getTemplateId: Function;
|
|
47
50
|
export {};
|
|
48
51
|
//# sourceMappingURL=private-selectors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAIhF,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,mEAE3C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,eAAO,MAAM,2BAA2B,UAcvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,UAmBvC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAGV;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAEpE;AAqBD,eAAO,MAAM,WAAW,UAgCvB,CAAC;AAEF,eAAO,MAAM,cAAc,UAOxB,CAAC;AAEJ,eAAO,MAAM,aAAa,UAmFzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.0",
|
|
4
4
|
"description": "Access to and manipulation of core WordPress entities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "cce81c13739c2a8b53d91df90c4f037cb68c2665"
|
|
66
66
|
}
|
package/src/entities.js
CHANGED
package/src/private-selectors.ts
CHANGED
|
@@ -6,8 +6,9 @@ import { createSelector, createRegistrySelector } from '@wordpress/data';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import type
|
|
9
|
+
import { getDefaultTemplateId, getEntityRecord, type State } from './selectors';
|
|
10
10
|
import { STORE_NAME } from './name';
|
|
11
|
+
import { unlock } from './lock-unlock';
|
|
11
12
|
|
|
12
13
|
type EntityRecordKey = string | number;
|
|
13
14
|
|
|
@@ -105,3 +106,150 @@ export function getEntityRecordPermissions(
|
|
|
105
106
|
export function getRegisteredPostMeta( state: State, postType: string ) {
|
|
106
107
|
return state.registeredPostMeta?.[ postType ] ?? {};
|
|
107
108
|
}
|
|
109
|
+
|
|
110
|
+
function normalizePageId( value: number | string | undefined ): string | null {
|
|
111
|
+
if ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// We also need to check if it's not zero (`'0'`).
|
|
116
|
+
if ( Number( value ) === 0 ) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return value.toString();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface SiteData {
|
|
124
|
+
show_on_front?: string;
|
|
125
|
+
page_on_front?: string | number;
|
|
126
|
+
page_for_posts?: string | number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const getHomePage = createRegistrySelector( ( select ) =>
|
|
130
|
+
createSelector(
|
|
131
|
+
() => {
|
|
132
|
+
const siteData = select( STORE_NAME ).getEntityRecord(
|
|
133
|
+
'root',
|
|
134
|
+
'site'
|
|
135
|
+
) as SiteData | undefined;
|
|
136
|
+
if ( ! siteData ) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const homepageId =
|
|
140
|
+
siteData?.show_on_front === 'page'
|
|
141
|
+
? normalizePageId( siteData.page_on_front )
|
|
142
|
+
: null;
|
|
143
|
+
if ( homepageId ) {
|
|
144
|
+
return { postType: 'page', postId: homepageId };
|
|
145
|
+
}
|
|
146
|
+
const frontPageTemplateId = select(
|
|
147
|
+
STORE_NAME
|
|
148
|
+
).getDefaultTemplateId( {
|
|
149
|
+
slug: 'front-page',
|
|
150
|
+
} );
|
|
151
|
+
return { postType: 'wp_template', postId: frontPageTemplateId };
|
|
152
|
+
},
|
|
153
|
+
( state ) => [
|
|
154
|
+
// @ts-expect-error
|
|
155
|
+
getEntityRecord( state, 'root', 'site' ),
|
|
156
|
+
getDefaultTemplateId( state, {
|
|
157
|
+
slug: 'front-page',
|
|
158
|
+
} ),
|
|
159
|
+
]
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
export const getPostsPageId = createRegistrySelector( ( select ) => () => {
|
|
164
|
+
const siteData = select( STORE_NAME ).getEntityRecord( 'root', 'site' ) as
|
|
165
|
+
| SiteData
|
|
166
|
+
| undefined;
|
|
167
|
+
return siteData?.show_on_front === 'page'
|
|
168
|
+
? normalizePageId( siteData.page_for_posts )
|
|
169
|
+
: null;
|
|
170
|
+
} );
|
|
171
|
+
|
|
172
|
+
export const getTemplateId = createRegistrySelector(
|
|
173
|
+
( select ) => ( state, postType, postId ) => {
|
|
174
|
+
const homepage = unlock( select( STORE_NAME ) ).getHomePage();
|
|
175
|
+
|
|
176
|
+
if ( ! homepage ) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// For the front page, we always use the front page template if existing.
|
|
181
|
+
if (
|
|
182
|
+
postType === 'page' &&
|
|
183
|
+
postType === homepage?.postType &&
|
|
184
|
+
postId.toString() === homepage?.postId
|
|
185
|
+
) {
|
|
186
|
+
// The /lookup endpoint cannot currently handle a lookup
|
|
187
|
+
// when a page is set as the front page, so specifically in
|
|
188
|
+
// that case, we want to check if there is a front page
|
|
189
|
+
// template, and instead of falling back to the home
|
|
190
|
+
// template, we want to fall back to the page template.
|
|
191
|
+
const templates = select( STORE_NAME ).getEntityRecords(
|
|
192
|
+
'postType',
|
|
193
|
+
'wp_template',
|
|
194
|
+
{
|
|
195
|
+
per_page: -1,
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
if ( ! templates ) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const id = templates.find( ( { slug } ) => slug === 'front-page' )
|
|
202
|
+
?.id;
|
|
203
|
+
if ( id ) {
|
|
204
|
+
return id;
|
|
205
|
+
}
|
|
206
|
+
// If no front page template is found, continue with the
|
|
207
|
+
// logic below (fetching the page template).
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const editedEntity = select( STORE_NAME ).getEditedEntityRecord(
|
|
211
|
+
'postType',
|
|
212
|
+
postType,
|
|
213
|
+
postId
|
|
214
|
+
);
|
|
215
|
+
if ( ! editedEntity ) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();
|
|
219
|
+
// Check if the current page is the posts page.
|
|
220
|
+
if ( postType === 'page' && postsPageId === postId.toString() ) {
|
|
221
|
+
return select( STORE_NAME ).getDefaultTemplateId( {
|
|
222
|
+
slug: 'home',
|
|
223
|
+
} );
|
|
224
|
+
}
|
|
225
|
+
// First see if the post/page has an assigned template and fetch it.
|
|
226
|
+
const currentTemplateSlug = editedEntity.template;
|
|
227
|
+
if ( currentTemplateSlug ) {
|
|
228
|
+
const currentTemplate = select( STORE_NAME )
|
|
229
|
+
.getEntityRecords( 'postType', 'wp_template', {
|
|
230
|
+
per_page: -1,
|
|
231
|
+
} )
|
|
232
|
+
?.find( ( { slug } ) => slug === currentTemplateSlug );
|
|
233
|
+
if ( currentTemplate ) {
|
|
234
|
+
return currentTemplate.id;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// If no template is assigned, use the default template.
|
|
238
|
+
let slugToCheck;
|
|
239
|
+
// In `draft` status we might not have a slug available, so we use the `single`
|
|
240
|
+
// post type templates slug(ex page, single-post, single-product etc..).
|
|
241
|
+
// Pages do not need the `single` prefix in the slug to be prioritized
|
|
242
|
+
// through template hierarchy.
|
|
243
|
+
if ( editedEntity.slug ) {
|
|
244
|
+
slugToCheck =
|
|
245
|
+
postType === 'page'
|
|
246
|
+
? `${ postType }-${ editedEntity.slug }`
|
|
247
|
+
: `single-${ postType }-${ editedEntity.slug }`;
|
|
248
|
+
} else {
|
|
249
|
+
slugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;
|
|
250
|
+
}
|
|
251
|
+
return select( STORE_NAME ).getDefaultTemplateId( {
|
|
252
|
+
slug: slugToCheck,
|
|
253
|
+
} );
|
|
254
|
+
}
|
|
255
|
+
);
|