@wordpress/edit-site 6.32.1-next.b8c8708f3.0 → 6.33.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/build/components/editor/use-resolve-edited-entity.js +3 -20
- package/build/components/editor/use-resolve-edited-entity.js.map +2 -2
- package/build/components/page-templates/index.js +92 -24
- package/build/components/page-templates/index.js.map +3 -3
- package/build/components/post-edit/index.js +1 -1
- package/build/components/post-edit/index.js.map +2 -2
- package/build/components/post-list/index.js +4 -4
- package/build/components/post-list/index.js.map +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +5 -1
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
- package/build/components/site-editor-routes/index.js +0 -1
- package/build/components/site-editor-routes/index.js.map +2 -2
- package/build/components/site-editor-routes/template-item.js +0 -7
- package/build/components/site-editor-routes/template-item.js.map +2 -2
- package/build-module/components/editor/use-resolve-edited-entity.js +3 -20
- package/build-module/components/editor/use-resolve-edited-entity.js.map +2 -2
- package/build-module/components/page-templates/index.js +95 -27
- package/build-module/components/page-templates/index.js.map +2 -2
- package/build-module/components/post-edit/index.js +1 -1
- package/build-module/components/post-edit/index.js.map +2 -2
- package/build-module/components/post-list/index.js +4 -4
- package/build-module/components/post-list/index.js.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +5 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
- package/build-module/components/site-editor-routes/index.js +1 -2
- package/build-module/components/site-editor-routes/index.js.map +2 -2
- package/build-module/components/site-editor-routes/template-item.js +0 -6
- package/build-module/components/site-editor-routes/template-item.js.map +2 -2
- package/build-style/posts-rtl.css +8 -1
- package/build-style/posts.css +8 -1
- package/build-style/style-rtl.css +8 -1
- package/build-style/style.css +8 -1
- package/package.json +44 -44
- package/src/components/editor/use-resolve-edited-entity.js +2 -20
- package/src/components/page-templates/index.js +75 -7
- package/src/components/post-edit/index.js +1 -1
- package/src/components/post-list/index.js +4 -4
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +7 -1
- package/src/components/site-editor-routes/index.js +1 -2
- package/src/components/site-editor-routes/template-item.js +0 -6
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var template_item_exports = {};
|
|
30
30
|
__export(template_item_exports, {
|
|
31
|
-
staticTemplateItemRoute: () => staticTemplateItemRoute,
|
|
32
31
|
templateItemRoute: () => templateItemRoute
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(template_item_exports);
|
|
@@ -55,14 +54,8 @@ const templateItemRoute = {
|
|
|
55
54
|
path: "/wp_template/*postId",
|
|
56
55
|
areas
|
|
57
56
|
};
|
|
58
|
-
const staticTemplateItemRoute = {
|
|
59
|
-
name: "static-template-item",
|
|
60
|
-
path: "/wp_registered_template/*postId",
|
|
61
|
-
areas
|
|
62
|
-
};
|
|
63
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
58
|
0 && (module.exports = {
|
|
65
|
-
staticTemplateItemRoute,
|
|
66
59
|
templateItemRoute
|
|
67
60
|
});
|
|
68
61
|
//# sourceMappingURL=template-item.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/site-editor-routes/template-item.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport Editor from '../editor';\nimport SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';\nimport SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';\n\nconst areas = {\n\tsidebar( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<SidebarNavigationScreenTemplatesBrowse backPath=\"/\" />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n\tmobile( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<Editor />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n\tpreview( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<Editor />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n};\n\nexport const templateItemRoute = {\n\tname: 'template-item',\n\tpath: '/wp_template/*postId',\n\tareas,\n};\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport Editor from '../editor';\nimport SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';\nimport SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';\n\nconst areas = {\n\tsidebar( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<SidebarNavigationScreenTemplatesBrowse backPath=\"/\" />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n\tmobile( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<Editor />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n\tpreview( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<Editor />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n};\n\nexport const templateItemRoute = {\n\tname: 'template-item',\n\tpath: '/wp_template/*postId',\n\tareas,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWG;AARH,oBAAmB;AACnB,wDAAmD;AACnD,mDAA+C;AAE/C,MAAM,QAAQ;AAAA,EACb,QAAS,EAAE,SAAS,GAAI;AACvB,UAAM,eAAe,SAAS,cAAc;AAC5C,WAAO,eACN,4CAAC,kDAAAA,SAAA,EAAuC,UAAS,KAAI,IAErD,4CAAC,6CAAAC,SAAA,EAAmC;AAAA,EAEtC;AAAA,EACA,OAAQ,EAAE,SAAS,GAAI;AACtB,UAAM,eAAe,SAAS,cAAc;AAC5C,WAAO,eACN,4CAAC,cAAAC,SAAA,EAAO,IAER,4CAAC,6CAAAD,SAAA,EAAmC;AAAA,EAEtC;AAAA,EACA,QAAS,EAAE,SAAS,GAAI;AACvB,UAAM,eAAe,SAAS,cAAc;AAC5C,WAAO,eACN,4CAAC,cAAAC,SAAA,EAAO,IAER,4CAAC,6CAAAD,SAAA,EAAmC;AAAA,EAEtC;AACD;AAEO,MAAM,oBAAoB;AAAA,EAChC,MAAM;AAAA,EACN,MAAM;AAAA,EACN;AACD;",
|
|
6
6
|
"names": ["SidebarNavigationScreenTemplatesBrowse", "SidebarNavigationScreenUnsupported", "Editor"]
|
|
7
7
|
}
|
|
@@ -15,8 +15,7 @@ const postTypesWithoutParentTemplate = [
|
|
|
15
15
|
TEMPLATE_POST_TYPE,
|
|
16
16
|
TEMPLATE_PART_POST_TYPE,
|
|
17
17
|
NAVIGATION_POST_TYPE,
|
|
18
|
-
PATTERN_TYPES.user
|
|
19
|
-
"wp_registered_template"
|
|
18
|
+
PATTERN_TYPES.user
|
|
20
19
|
];
|
|
21
20
|
const authorizedPostTypes = ["page", "post"];
|
|
22
21
|
function getPostType(name) {
|
|
@@ -31,8 +30,6 @@ function getPostType(name) {
|
|
|
31
30
|
postType = TEMPLATE_POST_TYPE;
|
|
32
31
|
} else if (name === "template-item") {
|
|
33
32
|
postType = TEMPLATE_POST_TYPE;
|
|
34
|
-
} else if (name === "static-template-item") {
|
|
35
|
-
postType = "wp_registered_template";
|
|
36
33
|
} else if (name === "page-item" || name === "pages") {
|
|
37
34
|
postType = "page";
|
|
38
35
|
} else if (name === "post-item" || name === "posts") {
|
|
@@ -42,26 +39,12 @@ function getPostType(name) {
|
|
|
42
39
|
}
|
|
43
40
|
function useResolveEditedEntity() {
|
|
44
41
|
const { name, params = {}, query } = useLocation();
|
|
45
|
-
const { postId
|
|
46
|
-
const
|
|
42
|
+
const { postId = query?.postId } = params;
|
|
43
|
+
const postType = getPostType(name, postId) ?? query?.postType;
|
|
47
44
|
const homePage = useSelect((select) => {
|
|
48
45
|
const { getHomePage } = unlock(select(coreDataStore));
|
|
49
46
|
return getHomePage();
|
|
50
47
|
}, []);
|
|
51
|
-
const [postType, postId] = useSelect(
|
|
52
|
-
(select) => {
|
|
53
|
-
if (_postType !== "wp_registered_template") {
|
|
54
|
-
return [_postType, _postId];
|
|
55
|
-
}
|
|
56
|
-
return [
|
|
57
|
-
TEMPLATE_POST_TYPE,
|
|
58
|
-
unlock(select(coreDataStore)).getTemplateAutoDraftId(
|
|
59
|
-
_postId
|
|
60
|
-
)
|
|
61
|
-
];
|
|
62
|
-
},
|
|
63
|
-
[_postType, _postId]
|
|
64
|
-
);
|
|
65
48
|
const resolvedTemplateId = useSelect(
|
|
66
49
|
(select) => {
|
|
67
50
|
if (postTypesWithoutParentTemplate.includes(postType) && postId) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/editor/use-resolve-edited-entity.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n\tNAVIGATION_POST_TYPE,\n\tPATTERN_TYPES,\n} from '../../utils/constants';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst postTypesWithoutParentTemplate = [\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n\tNAVIGATION_POST_TYPE,\n\tPATTERN_TYPES.user,\n
|
|
5
|
-
"mappings": "AAGA,SAAS,WAAW,eAAe;AACnC,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,qBAAqB;AACvC,SAAS,eAAe,yBAAyB;AAKjD,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,MAAM,EAAE,YAAY,IAAI,OAAQ,iBAAkB;AAElD,MAAM,iCAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n\tNAVIGATION_POST_TYPE,\n\tPATTERN_TYPES,\n} from '../../utils/constants';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst postTypesWithoutParentTemplate = [\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n\tNAVIGATION_POST_TYPE,\n\tPATTERN_TYPES.user,\n];\n\nconst authorizedPostTypes = [ 'page', 'post' ];\n\nfunction getPostType( name ) {\n\tlet postType;\n\tif ( name === 'navigation-item' ) {\n\t\tpostType = NAVIGATION_POST_TYPE;\n\t} else if ( name === 'pattern-item' ) {\n\t\tpostType = PATTERN_TYPES.user;\n\t} else if ( name === 'template-part-item' ) {\n\t\tpostType = TEMPLATE_PART_POST_TYPE;\n\t} else if ( name === 'templates' ) {\n\t\tpostType = TEMPLATE_POST_TYPE;\n\t} else if ( name === 'template-item' ) {\n\t\tpostType = TEMPLATE_POST_TYPE;\n\t} else if ( name === 'page-item' || name === 'pages' ) {\n\t\tpostType = 'page';\n\t} else if ( name === 'post-item' || name === 'posts' ) {\n\t\tpostType = 'post';\n\t}\n\n\treturn postType;\n}\n\nexport function useResolveEditedEntity() {\n\tconst { name, params = {}, query } = useLocation();\n\tconst { postId = query?.postId } = params; // Fallback to query param for postId for list view routes.\n\tconst postType = getPostType( name, postId ) ?? query?.postType;\n\n\tconst homePage = useSelect( ( select ) => {\n\t\tconst { getHomePage } = unlock( select( coreDataStore ) );\n\t\treturn getHomePage();\n\t}, [] );\n\n\t/**\n\t * This is a hook that recreates the logic to resolve a template for a given WordPress postID postTypeId\n\t * in order to match the frontend as closely as possible in the site editor.\n\t *\n\t * It is not possible to rely on the server logic because there maybe unsaved changes that impact the template resolution.\n\t */\n\tconst resolvedTemplateId = useSelect(\n\t\t( select ) => {\n\t\t\t// If we're rendering a post type that doesn't have a template\n\t\t\t// no need to resolve its template.\n\t\t\tif (\n\t\t\t\tpostTypesWithoutParentTemplate.includes( postType ) &&\n\t\t\t\tpostId\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Don't trigger resolution for multi-selected posts.\n\t\t\tif ( postId && postId.includes( ',' ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { getTemplateId } = unlock( select( coreDataStore ) );\n\n\t\t\t// If we're rendering a specific page, we need to resolve its template.\n\t\t\t// The site editor only supports pages for now, not other CPTs.\n\t\t\tif (\n\t\t\t\tpostType &&\n\t\t\t\tpostId &&\n\t\t\t\tauthorizedPostTypes.includes( postType )\n\t\t\t) {\n\t\t\t\treturn getTemplateId( postType, postId );\n\t\t\t}\n\n\t\t\t// If we're rendering the home page, and we have a static home page, resolve its template.\n\t\t\tif ( homePage?.postType === 'page' ) {\n\t\t\t\treturn getTemplateId( 'page', homePage?.postId );\n\t\t\t}\n\n\t\t\tif ( homePage?.postType === 'wp_template' ) {\n\t\t\t\treturn homePage?.postId;\n\t\t\t}\n\t\t},\n\t\t[ homePage, postId, postType ]\n\t);\n\n\tconst context = useMemo( () => {\n\t\tif ( postTypesWithoutParentTemplate.includes( postType ) && postId ) {\n\t\t\treturn {};\n\t\t}\n\n\t\tif ( postType && postId && authorizedPostTypes.includes( postType ) ) {\n\t\t\treturn { postType, postId };\n\t\t}\n\t\t// TODO: for post types lists we should probably not render the front page, but maybe a placeholder\n\t\t// with a message like \"Select a page\" or something similar.\n\t\tif ( homePage?.postType === 'page' ) {\n\t\t\treturn { postType: 'page', postId: homePage?.postId };\n\t\t}\n\n\t\treturn {};\n\t}, [ homePage, postType, postId ] );\n\n\tif ( postTypesWithoutParentTemplate.includes( postType ) && postId ) {\n\t\treturn { isReady: true, postType, postId, context };\n\t}\n\n\tif ( !! homePage ) {\n\t\treturn {\n\t\t\tisReady: resolvedTemplateId !== undefined,\n\t\t\tpostType: TEMPLATE_POST_TYPE,\n\t\t\tpostId: resolvedTemplateId,\n\t\t\tcontext,\n\t\t};\n\t}\n\n\treturn { isReady: false };\n}\n\nexport function useSyncDeprecatedEntityIntoState( {\n\tpostType,\n\tpostId,\n\tcontext,\n\tisReady,\n} ) {\n\tconst { setEditedEntity } = useDispatch( editSiteStore );\n\n\tuseEffect( () => {\n\t\tif ( isReady ) {\n\t\t\t// setEditedEntity expects a string (because the postId used to be\n\t\t\t// the template slug, even for edited templates). Now the postId can\n\t\t\t// be a number (either because it's an auto-draft or edited\n\t\t\t// template). Passing a number could break plugins doing things like\n\t\t\t// `id.includes`. It would be way more complex to keep passing the\n\t\t\t// template slug, while also being incorrect, so the easiest\n\t\t\t// solution is to cast the postId to a string.\n\t\t\tsetEditedEntity( postType, String( postId ), context );\n\t\t}\n\t}, [ isReady, postType, postId, context, setEditedEntity ] );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,WAAW,eAAe;AACnC,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,qBAAqB;AACvC,SAAS,eAAe,yBAAyB;AAKjD,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,MAAM,EAAE,YAAY,IAAI,OAAQ,iBAAkB;AAElD,MAAM,iCAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AACf;AAEA,MAAM,sBAAsB,CAAE,QAAQ,MAAO;AAE7C,SAAS,YAAa,MAAO;AAC5B,MAAI;AACJ,MAAK,SAAS,mBAAoB;AACjC,eAAW;AAAA,EACZ,WAAY,SAAS,gBAAiB;AACrC,eAAW,cAAc;AAAA,EAC1B,WAAY,SAAS,sBAAuB;AAC3C,eAAW;AAAA,EACZ,WAAY,SAAS,aAAc;AAClC,eAAW;AAAA,EACZ,WAAY,SAAS,iBAAkB;AACtC,eAAW;AAAA,EACZ,WAAY,SAAS,eAAe,SAAS,SAAU;AACtD,eAAW;AAAA,EACZ,WAAY,SAAS,eAAe,SAAS,SAAU;AACtD,eAAW;AAAA,EACZ;AAEA,SAAO;AACR;AAEO,SAAS,yBAAyB;AACxC,QAAM,EAAE,MAAM,SAAS,CAAC,GAAG,MAAM,IAAI,YAAY;AACjD,QAAM,EAAE,SAAS,OAAO,OAAO,IAAI;AACnC,QAAM,WAAW,YAAa,MAAM,MAAO,KAAK,OAAO;AAEvD,QAAM,WAAW,UAAW,CAAE,WAAY;AACzC,UAAM,EAAE,YAAY,IAAI,OAAQ,OAAQ,aAAc,CAAE;AACxD,WAA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,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,EAAE,gBAAgB,IAAI,YAAa,aAAc;AAEvD,YAAW,MAAM;AAChB,QAAK,SAAU;AAQd,sBAAiB,UAAU,OAAQ,MAAO,GAAG,OAAQ;AAAA,IACtD;AAAA,EACD,GAAG,CAAE,SAAS,UAAU,QAAQ,SAAS,eAAgB,CAAE;AAC5D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Page } from "@wordpress/admin-ui";
|
|
3
|
-
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { __, sprintf } from "@wordpress/i18n";
|
|
4
|
+
import { decodeEntities } from "@wordpress/html-entities";
|
|
4
5
|
import { useState, useMemo, useCallback } from "@wordpress/element";
|
|
5
6
|
import {
|
|
6
7
|
privateApis as corePrivateApis,
|
|
@@ -10,10 +11,11 @@ import { DataViews, filterSortAndPaginate } from "@wordpress/dataviews";
|
|
|
10
11
|
import { privateApis as routerPrivateApis } from "@wordpress/router";
|
|
11
12
|
import { privateApis as editorPrivateApis } from "@wordpress/editor";
|
|
12
13
|
import { addQueryArgs } from "@wordpress/url";
|
|
13
|
-
import { useSelect } from "@wordpress/data";
|
|
14
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
14
15
|
import { useEvent } from "@wordpress/compose";
|
|
15
16
|
import { useView } from "@wordpress/views";
|
|
16
|
-
import { Button } from "@wordpress/components";
|
|
17
|
+
import { Button, Modal } from "@wordpress/components";
|
|
18
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
17
19
|
import AddNewTemplate from "../add-new-template";
|
|
18
20
|
import { TEMPLATE_POST_TYPE } from "../../utils/constants";
|
|
19
21
|
import { unlock } from "../../lock-unlock";
|
|
@@ -37,6 +39,7 @@ function PageTemplates() {
|
|
|
37
39
|
const { path, query } = useLocation();
|
|
38
40
|
const { activeView = "active", postId } = query;
|
|
39
41
|
const [selection, setSelection] = useState([postId]);
|
|
42
|
+
const [selectedRegisteredTemplate, setSelectedRegisteredTemplate] = useState(false);
|
|
40
43
|
const defaultView = useMemo(() => {
|
|
41
44
|
return getDefaultView(activeView);
|
|
42
45
|
}, [activeView]);
|
|
@@ -182,13 +185,49 @@ function PageTemplates() {
|
|
|
182
185
|
elements
|
|
183
186
|
});
|
|
184
187
|
return _fields;
|
|
185
|
-
}, [users, activeView]);
|
|
188
|
+
}, [users, activeView, themeField]);
|
|
186
189
|
const { data, paginationInfo } = useMemo(() => {
|
|
187
190
|
return filterSortAndPaginate(records, view, fields);
|
|
188
191
|
}, [records, view, fields]);
|
|
192
|
+
const { createSuccessNotice } = useDispatch(noticesStore);
|
|
193
|
+
const onActionPerformed = useCallback(
|
|
194
|
+
(actionId, items) => {
|
|
195
|
+
switch (actionId) {
|
|
196
|
+
case "duplicate-post":
|
|
197
|
+
{
|
|
198
|
+
const newItem = items[0];
|
|
199
|
+
const _title = typeof newItem.title === "string" ? newItem.title : newItem.title?.rendered;
|
|
200
|
+
createSuccessNotice(
|
|
201
|
+
sprintf(
|
|
202
|
+
// translators: %s: Title of the created post or template, e.g: "Hello world".
|
|
203
|
+
__('"%s" successfully created.'),
|
|
204
|
+
decodeEntities(_title) || __("(no title)")
|
|
205
|
+
),
|
|
206
|
+
{
|
|
207
|
+
type: "snackbar",
|
|
208
|
+
id: "duplicate-post-action",
|
|
209
|
+
actions: [
|
|
210
|
+
{
|
|
211
|
+
label: __("Edit"),
|
|
212
|
+
onClick: () => {
|
|
213
|
+
history.navigate(
|
|
214
|
+
`/${newItem.type}/${newItem.id}?canvas=edit`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
[history, createSuccessNotice]
|
|
226
|
+
);
|
|
189
227
|
const postTypeActions = usePostActions({
|
|
190
228
|
postType: TEMPLATE_POST_TYPE,
|
|
191
|
-
context: "list"
|
|
229
|
+
context: "list",
|
|
230
|
+
onActionPerformed
|
|
192
231
|
});
|
|
193
232
|
const editAction = useEditPostAction();
|
|
194
233
|
const setActiveTemplateAction = useSetActiveTemplateAction();
|
|
@@ -202,7 +241,10 @@ function PageTemplates() {
|
|
|
202
241
|
}
|
|
203
242
|
updateView(newView);
|
|
204
243
|
});
|
|
205
|
-
|
|
244
|
+
const duplicateAction = actions.find(
|
|
245
|
+
(action) => action.id === "duplicate-post"
|
|
246
|
+
);
|
|
247
|
+
return /* @__PURE__ */ jsxs(
|
|
206
248
|
Page,
|
|
207
249
|
{
|
|
208
250
|
className: "edit-site-page-templates",
|
|
@@ -221,28 +263,54 @@ function PageTemplates() {
|
|
|
221
263
|
),
|
|
222
264
|
/* @__PURE__ */ jsx(AddNewTemplate, {})
|
|
223
265
|
] }),
|
|
224
|
-
children:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
266
|
+
children: [
|
|
267
|
+
/* @__PURE__ */ jsx(
|
|
268
|
+
DataViews,
|
|
269
|
+
{
|
|
270
|
+
paginationInfo,
|
|
271
|
+
fields,
|
|
272
|
+
actions,
|
|
273
|
+
data,
|
|
274
|
+
isLoading: isLoadingData,
|
|
275
|
+
view,
|
|
276
|
+
onChangeView,
|
|
277
|
+
onChangeSelection,
|
|
278
|
+
isItemClickable: () => true,
|
|
279
|
+
onClickItem: (item) => {
|
|
280
|
+
if (item.type === "wp_registered_template") {
|
|
281
|
+
setSelectedRegisteredTemplate(item);
|
|
282
|
+
} else {
|
|
283
|
+
history.navigate(
|
|
284
|
+
`/${item.type}/${item.id}?canvas=edit`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
selection,
|
|
289
|
+
defaultLayouts
|
|
240
290
|
},
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
291
|
+
activeView
|
|
292
|
+
),
|
|
293
|
+
selectedRegisteredTemplate && duplicateAction && /* @__PURE__ */ jsx(
|
|
294
|
+
Modal,
|
|
295
|
+
{
|
|
296
|
+
title: __("Duplicate"),
|
|
297
|
+
onRequestClose: () => setSelectedRegisteredTemplate(),
|
|
298
|
+
size: "small",
|
|
299
|
+
children: /* @__PURE__ */ jsx(
|
|
300
|
+
duplicateAction.RenderModal,
|
|
301
|
+
{
|
|
302
|
+
items: [selectedRegisteredTemplate],
|
|
303
|
+
closeModal: () => setSelectedRegisteredTemplate(),
|
|
304
|
+
onActionPerformed: ([item]) => {
|
|
305
|
+
history.navigate(
|
|
306
|
+
`/${item.type}/${item.id}?canvas=edit`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
]
|
|
246
314
|
}
|
|
247
315
|
);
|
|
248
316
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/page-templates/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo, useCallback } from '@wordpress/element';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { useSelect } from '@wordpress/data';\nimport { useEvent } from '@wordpress/compose';\nimport { useView } from '@wordpress/views';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport AddNewTemplate from '../add-new-template';\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tuseEditPostAction,\n\tuseSetActiveTemplateAction,\n} from '../dataviews-actions';\nimport {\n\tauthorField,\n\tdescriptionField,\n\tpreviewField,\n\tactiveField,\n\tslugField,\n\tuseThemeField,\n} from './fields';\nimport { defaultLayouts, getDefaultView } from './view-utils';\n\nconst { usePostActions, templateTitleField } = unlock( editorPrivateApis );\nconst { useHistory, useLocation } = unlock( routerPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nexport default function PageTemplates() {\n\tconst { path, query } = useLocation();\n\tconst { activeView = 'active', postId } = query;\n\tconst [ selection, setSelection ] = useState( [ postId ] );\n\tconst defaultView = useMemo( () => {\n\t\treturn getDefaultView( activeView );\n\t}, [ activeView ] );\n\tconst { view, updateView, isModified, resetToDefault } = useView( {\n\t\tkind: 'postType',\n\t\tname: TEMPLATE_POST_TYPE,\n\t\tslug: activeView,\n\t\tdefaultView,\n\t\tqueryParams: {\n\t\t\tpage: query.pageNumber,\n\t\t\tsearch: query.search,\n\t\t},\n\t\tonChangeQueryParams: ( newQueryParams ) => {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t...query,\n\t\t\t\t\tpageNumber: newQueryParams.page,\n\t\t\t\t\tsearch: newQueryParams.search || undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t} );\n\n\tconst { activeTemplatesOption, activeTheme } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord, getCurrentTheme } = select( coreStore );\n\t\treturn {\n\t\t\tactiveTemplatesOption: getEntityRecord( 'root', 'site' )\n\t\t\t\t?.active_templates,\n\t\t\tactiveTheme: getCurrentTheme(),\n\t\t};\n\t} );\n\t// Todo: this will have to be better so that we're not fetching all the\n\t// records all the time. Active templates query will need to move server\n\t// side.\n\tconst { records: userRecords, isResolving: isLoadingUserRecords } =\n\t\tuseEntityRecordsWithPermissions( 'postType', TEMPLATE_POST_TYPE, {\n\t\t\tper_page: -1,\n\t\t\tcombinedTemplates: false,\n\t\t} );\n\tconst { records: staticRecords, isResolving: isLoadingStaticData } =\n\t\tuseEntityRecordsWithPermissions( 'postType', 'wp_registered_template', {\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ].filter(\n\t\t\t( record ) => ! record.is_custom\n\t\t);\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\tif ( activeId === false ) {\n\t\t\t\t\t// Remove the template from the array.\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( template ) => template.slug === activeSlug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active.splice( index, 1 );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Replace the template in the array.\n\t\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t\t);\n\t\t\t\t\tif ( template ) {\n\t\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t_active.push( template );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn _active;\n\t}, [ userRecords, staticRecords, activeTemplatesOption, activeTheme ] );\n\n\tlet _records;\n\tlet isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\t_records = activeTemplates;\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\t_records = userRecords;\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\t_records = staticRecords;\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.find(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t} ) );\n\t}, [ _records, activeTemplates ] );\n\n\tconst users = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUser } = select( coreStore );\n\t\t\treturn records.reduce( ( acc, record ) => {\n\t\t\t\tif ( record.author_text ) {\n\t\t\t\t\tif ( ! acc[ record.author_text ] ) {\n\t\t\t\t\t\tacc[ record.author_text ] = record.author_text;\n\t\t\t\t\t}\n\t\t\t\t} else if ( record.author ) {\n\t\t\t\t\tif ( ! acc[ record.author ] ) {\n\t\t\t\t\t\tacc[ record.author ] = getUser( record.author );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} );\n\t\t},\n\t\t[ records ]\n\t);\n\n\tconst history = useHistory();\n\tconst onChangeSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items );\n\t\t\tif ( view?.type === 'list' ) {\n\t\t\t\thistory.navigate(\n\t\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t\tpostId: items.length === 1 ? items[ 0 ] : undefined,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ history, path, view?.type ]\n\t);\n\n\tconst themeField = useThemeField();\n\tconst fields = useMemo( () => {\n\t\tconst _fields = [\n\t\t\tpreviewField,\n\t\t\ttemplateTitleField,\n\t\t\tdescriptionField,\n\t\t\tactiveField,\n\t\t\tslugField,\n\t\t];\n\t\tif ( activeView === 'user' ) {\n\t\t\t_fields.push( themeField );\n\t\t}\n\t\tconst elements = [];\n\t\tfor ( const author in users ) {\n\t\t\telements.push( {\n\t\t\t\tvalue: users[ author ]?.id ?? author,\n\t\t\t\tlabel: users[ author ]?.name ?? author,\n\t\t\t} );\n\t\t}\n\t\t_fields.push( {\n\t\t\t...authorField,\n\t\t\telements,\n\t\t} );\n\t\treturn _fields;\n\t}, [ users, activeView ] );\n\n\tconst { data, paginationInfo } = useMemo( () => {\n\t\treturn filterSortAndPaginate( records, view, fields );\n\t}, [ records, view, fields ] );\n\n\tconst postTypeActions = usePostActions( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t\tcontext: 'list',\n\t} );\n\tconst editAction = useEditPostAction();\n\tconst setActiveTemplateAction = useSetActiveTemplateAction();\n\tconst actions = useMemo(\n\t\t() =>\n\t\t\tactiveView === 'user'\n\t\t\t\t? [ setActiveTemplateAction, editAction, ...postTypeActions ]\n\t\t\t\t: [ setActiveTemplateAction, ...postTypeActions ],\n\t\t[ postTypeActions, setActiveTemplateAction, editAction, activeView ]\n\t);\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tif ( newView.type !== view.type ) {\n\t\t\t// Retrigger the routing areas resolution.\n\t\t\thistory.invalidate();\n\t\t}\n\t\tupdateView( newView );\n\t} );\n\n\treturn (\n\t\t<Page\n\t\t\tclassName=\"edit-site-page-templates\"\n\t\t\ttitle={ __( 'Templates' ) }\n\t\t\tactions={\n\t\t\t\t<>\n\t\t\t\t\t{ isModified && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tresetToDefault();\n\t\t\t\t\t\t\t\thistory.invalidate();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset view' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t<AddNewTemplate />\n\t\t\t\t</>\n\t\t\t}\n\t\t>\n\t\t\t<DataViews\n\t\t\t\tkey={ activeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tfields={ fields }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tisLoading={ isLoadingData }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tisItemClickable={ () => true }\n\t\t\t\tonClickItem={ ( item ) => {\n\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t`/${ item.type }/${ item.id }?canvas=edit`\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t\tselection={ selection }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t/>\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState, useMemo, useCallback } from '@wordpress/element';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEvent } from '@wordpress/compose';\nimport { useView } from '@wordpress/views';\nimport { Button, Modal } from '@wordpress/components';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddNewTemplate from '../add-new-template';\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tuseEditPostAction,\n\tuseSetActiveTemplateAction,\n} from '../dataviews-actions';\nimport {\n\tauthorField,\n\tdescriptionField,\n\tpreviewField,\n\tactiveField,\n\tslugField,\n\tuseThemeField,\n} from './fields';\nimport { defaultLayouts, getDefaultView } from './view-utils';\n\nconst { usePostActions, templateTitleField } = unlock( editorPrivateApis );\nconst { useHistory, useLocation } = unlock( routerPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nexport default function PageTemplates() {\n\tconst { path, query } = useLocation();\n\tconst { activeView = 'active', postId } = query;\n\tconst [ selection, setSelection ] = useState( [ postId ] );\n\tconst [ selectedRegisteredTemplate, setSelectedRegisteredTemplate ] =\n\t\tuseState( false );\n\tconst defaultView = useMemo( () => {\n\t\treturn getDefaultView( activeView );\n\t}, [ activeView ] );\n\tconst { view, updateView, isModified, resetToDefault } = useView( {\n\t\tkind: 'postType',\n\t\tname: TEMPLATE_POST_TYPE,\n\t\tslug: activeView,\n\t\tdefaultView,\n\t\tqueryParams: {\n\t\t\tpage: query.pageNumber,\n\t\t\tsearch: query.search,\n\t\t},\n\t\tonChangeQueryParams: ( newQueryParams ) => {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t...query,\n\t\t\t\t\tpageNumber: newQueryParams.page,\n\t\t\t\t\tsearch: newQueryParams.search || undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t} );\n\n\tconst { activeTemplatesOption, activeTheme } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord, getCurrentTheme } = select( coreStore );\n\t\treturn {\n\t\t\tactiveTemplatesOption: getEntityRecord( 'root', 'site' )\n\t\t\t\t?.active_templates,\n\t\t\tactiveTheme: getCurrentTheme(),\n\t\t};\n\t} );\n\t// Todo: this will have to be better so that we're not fetching all the\n\t// records all the time. Active templates query will need to move server\n\t// side.\n\tconst { records: userRecords, isResolving: isLoadingUserRecords } =\n\t\tuseEntityRecordsWithPermissions( 'postType', TEMPLATE_POST_TYPE, {\n\t\t\tper_page: -1,\n\t\t\tcombinedTemplates: false,\n\t\t} );\n\tconst { records: staticRecords, isResolving: isLoadingStaticData } =\n\t\tuseEntityRecordsWithPermissions( 'postType', 'wp_registered_template', {\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ].filter(\n\t\t\t( record ) => ! record.is_custom\n\t\t);\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\tif ( activeId === false ) {\n\t\t\t\t\t// Remove the template from the array.\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( template ) => template.slug === activeSlug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active.splice( index, 1 );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Replace the template in the array.\n\t\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t\t);\n\t\t\t\t\tif ( template ) {\n\t\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t_active.push( template );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn _active;\n\t}, [ userRecords, staticRecords, activeTemplatesOption, activeTheme ] );\n\n\tlet _records;\n\tlet isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\t_records = activeTemplates;\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\t_records = userRecords;\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\t_records = staticRecords;\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.find(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t} ) );\n\t}, [ _records, activeTemplates ] );\n\n\tconst users = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUser } = select( coreStore );\n\t\t\treturn records.reduce( ( acc, record ) => {\n\t\t\t\tif ( record.author_text ) {\n\t\t\t\t\tif ( ! acc[ record.author_text ] ) {\n\t\t\t\t\t\tacc[ record.author_text ] = record.author_text;\n\t\t\t\t\t}\n\t\t\t\t} else if ( record.author ) {\n\t\t\t\t\tif ( ! acc[ record.author ] ) {\n\t\t\t\t\t\tacc[ record.author ] = getUser( record.author );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} );\n\t\t},\n\t\t[ records ]\n\t);\n\n\tconst history = useHistory();\n\tconst onChangeSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items );\n\t\t\tif ( view?.type === 'list' ) {\n\t\t\t\thistory.navigate(\n\t\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t\tpostId: items.length === 1 ? items[ 0 ] : undefined,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ history, path, view?.type ]\n\t);\n\n\tconst themeField = useThemeField();\n\tconst fields = useMemo( () => {\n\t\tconst _fields = [\n\t\t\tpreviewField,\n\t\t\ttemplateTitleField,\n\t\t\tdescriptionField,\n\t\t\tactiveField,\n\t\t\tslugField,\n\t\t];\n\t\tif ( activeView === 'user' ) {\n\t\t\t_fields.push( themeField );\n\t\t}\n\t\tconst elements = [];\n\t\tfor ( const author in users ) {\n\t\t\telements.push( {\n\t\t\t\tvalue: users[ author ]?.id ?? author,\n\t\t\t\tlabel: users[ author ]?.name ?? author,\n\t\t\t} );\n\t\t}\n\t\t_fields.push( {\n\t\t\t...authorField,\n\t\t\telements,\n\t\t} );\n\t\treturn _fields;\n\t}, [ users, activeView, themeField ] );\n\n\tconst { data, paginationInfo } = useMemo( () => {\n\t\treturn filterSortAndPaginate( records, view, fields );\n\t}, [ records, view, fields ] );\n\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst onActionPerformed = useCallback(\n\t\t( actionId, items ) => {\n\t\t\tswitch ( actionId ) {\n\t\t\t\tcase 'duplicate-post':\n\t\t\t\t\t{\n\t\t\t\t\t\tconst newItem = items[ 0 ];\n\t\t\t\t\t\tconst _title =\n\t\t\t\t\t\t\ttypeof newItem.title === 'string'\n\t\t\t\t\t\t\t\t? newItem.title\n\t\t\t\t\t\t\t\t: newItem.title?.rendered;\n\t\t\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Title of the created post or template, e.g: \"Hello world\".\n\t\t\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\t\t\tdecodeEntities( _title ) || __( '(no title)' )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tlabel: __( 'Edit' ),\n\t\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t\t\t\t\t\t`/${ newItem.type }/${ newItem.id }?canvas=edit`\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t},\n\t\t[ history, createSuccessNotice ]\n\t);\n\tconst postTypeActions = usePostActions( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t\tcontext: 'list',\n\t\tonActionPerformed,\n\t} );\n\tconst editAction = useEditPostAction();\n\tconst setActiveTemplateAction = useSetActiveTemplateAction();\n\tconst actions = useMemo(\n\t\t() =>\n\t\t\tactiveView === 'user'\n\t\t\t\t? [ setActiveTemplateAction, editAction, ...postTypeActions ]\n\t\t\t\t: [ setActiveTemplateAction, ...postTypeActions ],\n\t\t[ postTypeActions, setActiveTemplateAction, editAction, activeView ]\n\t);\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tif ( newView.type !== view.type ) {\n\t\t\t// Retrigger the routing areas resolution.\n\t\t\thistory.invalidate();\n\t\t}\n\t\tupdateView( newView );\n\t} );\n\n\tconst duplicateAction = actions.find(\n\t\t( action ) => action.id === 'duplicate-post'\n\t);\n\n\treturn (\n\t\t<Page\n\t\t\tclassName=\"edit-site-page-templates\"\n\t\t\ttitle={ __( 'Templates' ) }\n\t\t\tactions={\n\t\t\t\t<>\n\t\t\t\t\t{ isModified && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tresetToDefault();\n\t\t\t\t\t\t\t\thistory.invalidate();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset view' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t<AddNewTemplate />\n\t\t\t\t</>\n\t\t\t}\n\t\t>\n\t\t\t<DataViews\n\t\t\t\tkey={ activeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tfields={ fields }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tisLoading={ isLoadingData }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tisItemClickable={ () => true }\n\t\t\t\tonClickItem={ ( item ) => {\n\t\t\t\t\tif ( item.type === 'wp_registered_template' ) {\n\t\t\t\t\t\tsetSelectedRegisteredTemplate( item );\n\t\t\t\t\t} else {\n\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t`/${ item.type }/${ item.id }?canvas=edit`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tselection={ selection }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t/>\n\t\t\t{ selectedRegisteredTemplate && duplicateAction && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Duplicate' ) }\n\t\t\t\t\tonRequestClose={ () => setSelectedRegisteredTemplate() }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t>\n\t\t\t\t\t<duplicateAction.RenderModal\n\t\t\t\t\t\titems={ [ selectedRegisteredTemplate ] }\n\t\t\t\t\t\tcloseModal={ () => setSelectedRegisteredTemplate() }\n\t\t\t\t\t\tonActionPerformed={ ( [ item ] ) => {\n\t\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t\t`/${ item.type }/${ item.id }?canvas=edit`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAiSI,mBAEE,KAFF;AA9RJ,SAAS,YAAY;AACrB,SAAS,IAAI,eAAe;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,UAAU,SAAS,mBAAmB;AAC/C;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,WAAW,6BAA6B;AACjD,SAAS,eAAe,yBAAyB;AACjD,SAAS,eAAe,yBAAyB;AACjD,SAAS,oBAAoB;AAC7B,SAAS,WAAW,mBAAmB;AACvC,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,QAAQ,aAAa;AAC9B,SAAS,SAAS,oBAAoB;AAKtC,OAAO,oBAAo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A;AAAA,YACA,OAAQ,GAAI,WAAY;AAAA,YACxB,gBAAiB,MAAM,8BAA8B;AAAA,YACrD,MAAK;AAAA,YAEL;AAAA,cAAC,gBAAgB;AAAA,cAAhB;AAAA,gBACA,OAAQ,CAAE,0BAA2B;AAAA,gBACrC,YAAa,MAAM,8BAA8B;AAAA,gBACjD,mBAAoB,CAAE,CAAE,IAAK,MAAO;AACnC,0BAAQ;AAAA,oBACP,IAAK,KAAK,IAAK,IAAK,KAAK,EAAG;AAAA,kBAC7B;AAAA,gBACD;AAAA;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -40,7 +40,7 @@ function PostEditForm({ postType, postId }) {
|
|
|
40
40
|
);
|
|
41
41
|
const [multiEdits, setMultiEdits] = useState({});
|
|
42
42
|
const { editEntityRecord } = useDispatch(coreDataStore);
|
|
43
|
-
const
|
|
43
|
+
const _fields = usePostFields({ postType });
|
|
44
44
|
const fields = useMemo(
|
|
45
45
|
() => _fields?.map((field) => {
|
|
46
46
|
if (field.id === "status") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/post-edit/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { __ } from '@wordpress/i18n';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { __experimentalVStack as VStack } from '@wordpress/components';\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\nconst { usePostFields, PostCardPanel } = unlock( editorPrivateApis );\n\nconst fieldsWithBulkEditSupport = [\n\t'title',\n\t'status',\n\t'date',\n\t'author',\n\t'discussion',\n];\n\nfunction PostEditForm( { postType, postId } ) {\n\tconst ids = useMemo( () => postId.split( ',' ), [ postId ] );\n\tconst { record, hasFinishedResolution } = useSelect(\n\t\t( select ) => {\n\t\t\tconst args = [ 'postType', postType, ids[ 0 ] ];\n\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\thasFinishedResolution: hasFinished,\n\t\t\t} = select( coreDataStore );\n\n\t\t\treturn {\n\t\t\t\trecord:\n\t\t\t\t\tids.length === 1 ? getEditedEntityRecord( ...args ) : null,\n\t\t\t\thasFinishedResolution: hasFinished(\n\t\t\t\t\t'getEditedEntityRecord',\n\t\t\t\t\targs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ postType, ids ]\n\t);\n\tconst [ multiEdits, setMultiEdits ] = useState( {} );\n\tconst { editEntityRecord } = useDispatch( coreDataStore );\n\tconst
|
|
5
|
-
"mappings": "AAsKO,cAUL,YAVK;AAnKP,OAAO,UAAU;AAKjB,SAAS,YAAY;AACrB,SAAS,UAAU;AACnB,SAAS,gBAAgB;AACzB,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,qBAAqB;AACvC,SAAS,wBAAwB,cAAc;AAC/C,SAAS,UAAU,SAAS,iBAAiB;AAC7C,SAAS,eAAe,yBAAyB;AAKjD,SAAS,cAAc;AACvB,OAAO,wBAAwB;AAC/B,SAAS,eAAe,8BAA8B;AAEtD,MAAM,EAAE,eAAe,cAAc,IAAI,OAAQ,iBAAkB;AAEnE,MAAM,4BAA4B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEA,SAAS,aAAc,EAAE,UAAU,OAAO,GAAI;AAC7C,QAAM,MAAM,QAAS,MAAM,OAAO,MAAO,GAAI,GAAG,CAAE,MAAO,CAAE;AAC3D,QAAM,EAAE,QAAQ,sBAAsB,IAAI;AAAA,IACzC,CAAE,WAAY;AACb,YAAM,OAAO,CAAE,YAAY,UAAU,IAAK,CAAE,CAAE;AAE9C,YAAM;AAAA,QACL;AAAA,QACA,uBAAuB;AAAA,MACxB,IAAI,OAAQ,aAAc;AAE1B,aAAO;AAAA,QACN,QACC,IAAI,WAAW,IAAI,sBAAuB,GAAG,IAAK,IAAI;AAAA,QACvD,uBAAuB;AAAA,UACtB;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,UAAU,GAAI;AAAA,EACjB;AACA,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,CAAC,CAAE;AACnD,QAAM,EAAE,iBAAiB,IAAI,YAAa,aAAc;AACxD,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { __ } from '@wordpress/i18n';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { __experimentalVStack as VStack } from '@wordpress/components';\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\nconst { usePostFields, PostCardPanel } = unlock( editorPrivateApis );\n\nconst fieldsWithBulkEditSupport = [\n\t'title',\n\t'status',\n\t'date',\n\t'author',\n\t'discussion',\n];\n\nfunction PostEditForm( { postType, postId } ) {\n\tconst ids = useMemo( () => postId.split( ',' ), [ postId ] );\n\tconst { record, hasFinishedResolution } = useSelect(\n\t\t( select ) => {\n\t\t\tconst args = [ 'postType', postType, ids[ 0 ] ];\n\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\thasFinishedResolution: hasFinished,\n\t\t\t} = select( coreDataStore );\n\n\t\t\treturn {\n\t\t\t\trecord:\n\t\t\t\t\tids.length === 1 ? getEditedEntityRecord( ...args ) : null,\n\t\t\t\thasFinishedResolution: hasFinished(\n\t\t\t\t\t'getEditedEntityRecord',\n\t\t\t\t\targs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ postType, ids ]\n\t);\n\tconst [ multiEdits, setMultiEdits ] = useState( {} );\n\tconst { editEntityRecord } = useDispatch( coreDataStore );\n\tconst _fields = usePostFields( { postType } );\n\tconst fields = useMemo(\n\t\t() =>\n\t\t\t_fields?.map( ( field ) => {\n\t\t\t\tif ( field.id === 'status' ) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...field,\n\t\t\t\t\t\telements: field.elements.filter(\n\t\t\t\t\t\t\t( element ) => element.value !== 'trash'\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn field;\n\t\t\t} ),\n\t\t[ _fields ]\n\t);\n\n\tconst form = useMemo(\n\t\t() => ( {\n\t\t\tlayout: {\n\t\t\t\ttype: 'panel',\n\t\t\t},\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tid: 'featured_media',\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: 'status',\n\t\t\t\t\tlabel: __( 'Status & Visibility' ),\n\t\t\t\t\tchildren: [ 'status', 'password' ],\n\t\t\t\t},\n\t\t\t\t'author',\n\t\t\t\t'date',\n\t\t\t\t'slug',\n\t\t\t\t'parent',\n\t\t\t\t{\n\t\t\t\t\tid: 'discussion',\n\t\t\t\t\tlabel: __( 'Discussion' ),\n\t\t\t\t\tchildren: [ 'comment_status', 'ping_status' ],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: __( 'Template' ),\n\t\t\t\t\tid: 'template',\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'side',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t].filter(\n\t\t\t\t( field ) =>\n\t\t\t\t\tids.length === 1 ||\n\t\t\t\t\tfieldsWithBulkEditSupport.includes(\n\t\t\t\t\t\ttypeof field === 'string' ? field : field.id\n\t\t\t\t\t)\n\t\t\t),\n\t\t} ),\n\t\t[ ids ]\n\t);\n\tconst onChange = ( edits ) => {\n\t\tfor ( const id of ids ) {\n\t\t\tif (\n\t\t\t\tedits.status &&\n\t\t\t\tedits.status !== 'future' &&\n\t\t\t\trecord?.status === 'future' &&\n\t\t\t\tnew Date( record.date ) > new Date()\n\t\t\t) {\n\t\t\t\tedits.date = null;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tedits.status &&\n\t\t\t\tedits.status === 'private' &&\n\t\t\t\trecord.password\n\t\t\t) {\n\t\t\t\tedits.password = '';\n\t\t\t}\n\t\t\teditEntityRecord( 'postType', postType, id, edits );\n\t\t\tif ( ids.length > 1 ) {\n\t\t\t\tsetMultiEdits( ( prev ) => ( {\n\t\t\t\t\t...prev,\n\t\t\t\t\t...edits,\n\t\t\t\t} ) );\n\t\t\t}\n\t\t}\n\t};\n\tuseEffect( () => {\n\t\tsetMultiEdits( {} );\n\t}, [ ids ] );\n\n\tconst { ExperimentalBlockEditorProvider } = unlock(\n\t\tblockEditorPrivateApis\n\t);\n\tconst settings = usePatternSettings();\n\n\t/**\n\t * The template field depends on the block editor settings.\n\t * This is a workaround to ensure that the block editor settings are available.\n\t * For more information, see: https://github.com/WordPress/gutenberg/issues/67521\n\t */\n\tconst fieldsWithDependency = useMemo( () => {\n\t\treturn fields.map( ( field ) => {\n\t\t\tif ( field.id === 'template' ) {\n\t\t\t\treturn {\n\t\t\t\t\t...field,\n\t\t\t\t\tEdit: ( data ) => (\n\t\t\t\t\t\t<ExperimentalBlockEditorProvider settings={ settings }>\n\t\t\t\t\t\t\t<field.Edit { ...data } />\n\t\t\t\t\t\t</ExperimentalBlockEditorProvider>\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field;\n\t\t} );\n\t}, [ fields, settings ] );\n\n\treturn (\n\t\t<VStack spacing={ 4 }>\n\t\t\t<PostCardPanel postType={ postType } postId={ ids } />\n\t\t\t{ hasFinishedResolution && (\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ ids.length === 1 ? record : multiEdits }\n\t\t\t\t\tfields={ fieldsWithDependency }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport function PostEdit( { postType, postId } ) {\n\treturn (\n\t\t<Page\n\t\t\tclassName={ clsx( 'edit-site-post-edit', {\n\t\t\t\t'is-empty': ! postId,\n\t\t\t} ) }\n\t\t\tlabel={ __( 'Post Edit' ) }\n\t\t>\n\t\t\t{ postId && (\n\t\t\t\t<PostEditForm postType={ postType } postId={ postId } />\n\t\t\t) }\n\t\t\t{ ! postId && <p>{ __( 'Select a page to edit' ) }</p> }\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAsKO,cAUL,YAVK;AAnKP,OAAO,UAAU;AAKjB,SAAS,YAAY;AACrB,SAAS,UAAU;AACnB,SAAS,gBAAgB;AACzB,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,qBAAqB;AACvC,SAAS,wBAAwB,cAAc;AAC/C,SAAS,UAAU,SAAS,iBAAiB;AAC7C,SAAS,eAAe,yBAAyB;AAKjD,SAAS,cAAc;AACvB,OAAO,wBAAwB;AAC/B,SAAS,eAAe,8BAA8B;AAEtD,MAAM,EAAE,eAAe,cAAc,IAAI,OAAQ,iBAAkB;AAEnE,MAAM,4BAA4B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEA,SAAS,aA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,MAAN,EAAa,GAAG,MAAO,GACzB;AAAA,QAEF;AAAA,MACD;AACA,aAAO;AAAA,IACR,CAAE;AAAA,EACH,GAAG,CAAE,QAAQ,QAAS,CAAE;AAExB,SACC,qBAAC,UAAO,SAAU,GACjB;AAAA,wBAAC,iBAAc,UAAsB,QAAS,KAAM;AAAA,IAClD,yBACD;AAAA,MAAC;AAAA;AAAA,QACA,MAAO,IAAI,WAAW,IAAI,SAAS;AAAA,QACnC,QAAS;AAAA,QACT;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEO,SAAS,SAAU,EAAE,UAAU,OAAO,GAAI;AAChD,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAY,KAAM,uBAAuB;AAAA,QACxC,YAAY,CAAE;AAAA,MACf,CAAE;AAAA,MACF,OAAQ,GAAI,WAAY;AAAA,MAEtB;AAAA,kBACD,oBAAC,gBAAa,UAAsB,QAAkB;AAAA,QAErD,CAAE,UAAU,oBAAC,OAAI,aAAI,uBAAwB,GAAG;AAAA;AAAA;AAAA,EACnD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -83,7 +83,7 @@ function PostList({ postType }) {
|
|
|
83
83
|
},
|
|
84
84
|
[path, history]
|
|
85
85
|
);
|
|
86
|
-
const
|
|
86
|
+
const fields = usePostFields({
|
|
87
87
|
postType
|
|
88
88
|
});
|
|
89
89
|
const queryArgs = useMemo(() => {
|
|
@@ -119,7 +119,7 @@ function PostList({ postType }) {
|
|
|
119
119
|
totalPages
|
|
120
120
|
} = useEntityRecordsWithPermissions("postType", postType, queryArgs);
|
|
121
121
|
const data = useMemo(() => {
|
|
122
|
-
if (
|
|
122
|
+
if (view?.sort?.field === "author") {
|
|
123
123
|
return filterSortAndPaginate(
|
|
124
124
|
records,
|
|
125
125
|
{ sort: { ...view.sort } },
|
|
@@ -127,7 +127,7 @@ function PostList({ postType }) {
|
|
|
127
127
|
).data;
|
|
128
128
|
}
|
|
129
129
|
return records;
|
|
130
|
-
}, [records, fields,
|
|
130
|
+
}, [records, fields, view?.sort]);
|
|
131
131
|
const ids = data?.map((record) => getItemId(record)) ?? [];
|
|
132
132
|
const prevIds = usePrevious(ids) ?? [];
|
|
133
133
|
const deletedIds = prevIds.filter((id) => !ids.includes(id));
|
|
@@ -220,7 +220,7 @@ function PostList({ postType }) {
|
|
|
220
220
|
fields,
|
|
221
221
|
actions,
|
|
222
222
|
data: data || EMPTY_ARRAY,
|
|
223
|
-
isLoading: isLoadingData
|
|
223
|
+
isLoading: isLoadingData,
|
|
224
224
|
view,
|
|
225
225
|
onChangeView,
|
|
226
226
|
selection,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/post-list/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { Button } from '@wordpress/components';\nimport {\n\tstore as coreStore,\n\tprivateApis as coreDataPrivateApis,\n} from '@wordpress/core-data';\nimport { useState, useMemo, useCallback, useEffect } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { useSelect } from '@wordpress/data';\nimport { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { __ } from '@wordpress/i18n';\nimport { drawerRight } from '@wordpress/icons';\nimport { useEvent, usePrevious } from '@wordpress/compose';\nimport { addQueryArgs } from '@wordpress/url';\nimport { useView } from '@wordpress/views';\n\n/**\n * Internal dependencies\n */\nimport {\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tLAYOUT_LIST,\n} from '../../utils/constants';\n\nimport AddNewPostModal from '../add-new-post';\nimport { unlock } from '../../lock-unlock';\nimport { useEditPostAction } from '../dataviews-actions';\nimport { defaultLayouts, getDefaultView } from './view-utils';\n\nconst { usePostActions, usePostFields } = unlock( editorPrivateApis );\nconst { useLocation, useHistory } = unlock( routerPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );\nconst EMPTY_ARRAY = [];\n\nconst DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'trash'.\n\nfunction getItemId( item ) {\n\treturn item.id.toString();\n}\n\nfunction getItemLevel( item ) {\n\treturn item.level;\n}\n\nexport default function PostList( { postType } ) {\n\tconst { path, query } = useLocation();\n\tconst { activeView = 'all', postId, quickEdit = false } = query;\n\tconst history = useHistory();\n\tconst postTypeObject = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\treturn getPostType( postType );\n\t\t},\n\t\t[ postType ]\n\t);\n\tconst { view, updateView, isModified, resetToDefault } = useView( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t\tslug: activeView,\n\t\tqueryParams: {\n\t\t\tpage: query.pageNumber,\n\t\t\tsearch: query.search,\n\t\t},\n\t\tonChangeQueryParams: ( newQueryParams ) => {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t...query,\n\t\t\t\t\tpageNumber: newQueryParams.page,\n\t\t\t\t\tsearch: newQueryParams.search || undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t\tdefaultView: getDefaultView( postTypeObject, activeView ),\n\t} );\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tif ( newView.type !== view.type ) {\n\t\t\t// Retrigger the routing areas resolution.\n\t\t\thistory.invalidate();\n\t\t}\n\t\tupdateView( newView );\n\t} );\n\n\tconst [ selection, setSelection ] = useState( postId?.split( ',' ) ?? [] );\n\tconst onChangeSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items );\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\tpostId: items.join( ',' ),\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t\t[ path, history ]\n\t);\n\n\tconst
|
|
5
|
-
"mappings": "AAkOM,SAWA,UAXA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N,aAAa;AAAA,MACZ,MAAM,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,IACf;AAAA,IACA,qBAAqB,CAAE,mBAAoB;AAC1C,cAAQ;AAAA,QACP,aAAc,MAAM;AAAA,UACnB,GAAG;AAAA,UACH,YAAY,eAAe;AAAA,UAC3B,QAAQ,eAAe,UAAU;AAAA,QAClC,CAAE;AAAA,MACH;AAAA,IACD;AAAA,IACA,aAAa,eAAgB,gBAAgB,UAAW;AAAA,EACzD,CAAE;AAEF,QAAM,eAAe,SAAU,CAAE,YAAa;AAC7C,QAAK,QAAQ,SAAS,KAAK,MAAO;AAEjC,cAAQ,WAAW;AAAA,IACpB;AACA,eAAY,OAAQ;AAAA,EACrB,CAAE;AAEF,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,QAAQ,MAAO,GAAI,KAAK,CAAC,CAAE;AACzE,QAAM,oBAAoB;AAAA,IACzB,CAAE,UAAW;AACZ,mBAAc,KAAM;AACpB,cAAQ;AAAA,QACP,aAAc,MAAM;AAAA,UACnB,QAAQ,MAAM,KAAM,GAAI;AAAA,QACzB,CAAE;AAAA,MACH;AAAA,IACD;AAAA,IACA,CAAE,MAAM,OAAQ;AAAA,EACjB;AAEA,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { Button } from '@wordpress/components';\nimport {\n\tstore as coreStore,\n\tprivateApis as coreDataPrivateApis,\n} from '@wordpress/core-data';\nimport { useState, useMemo, useCallback, useEffect } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { useSelect } from '@wordpress/data';\nimport { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { __ } from '@wordpress/i18n';\nimport { drawerRight } from '@wordpress/icons';\nimport { useEvent, usePrevious } from '@wordpress/compose';\nimport { addQueryArgs } from '@wordpress/url';\nimport { useView } from '@wordpress/views';\n\n/**\n * Internal dependencies\n */\nimport {\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tLAYOUT_LIST,\n} from '../../utils/constants';\n\nimport AddNewPostModal from '../add-new-post';\nimport { unlock } from '../../lock-unlock';\nimport { useEditPostAction } from '../dataviews-actions';\nimport { defaultLayouts, getDefaultView } from './view-utils';\n\nconst { usePostActions, usePostFields } = unlock( editorPrivateApis );\nconst { useLocation, useHistory } = unlock( routerPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );\nconst EMPTY_ARRAY = [];\n\nconst DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'trash'.\n\nfunction getItemId( item ) {\n\treturn item.id.toString();\n}\n\nfunction getItemLevel( item ) {\n\treturn item.level;\n}\n\nexport default function PostList( { postType } ) {\n\tconst { path, query } = useLocation();\n\tconst { activeView = 'all', postId, quickEdit = false } = query;\n\tconst history = useHistory();\n\tconst postTypeObject = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\treturn getPostType( postType );\n\t\t},\n\t\t[ postType ]\n\t);\n\tconst { view, updateView, isModified, resetToDefault } = useView( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t\tslug: activeView,\n\t\tqueryParams: {\n\t\t\tpage: query.pageNumber,\n\t\t\tsearch: query.search,\n\t\t},\n\t\tonChangeQueryParams: ( newQueryParams ) => {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t...query,\n\t\t\t\t\tpageNumber: newQueryParams.page,\n\t\t\t\t\tsearch: newQueryParams.search || undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t\tdefaultView: getDefaultView( postTypeObject, activeView ),\n\t} );\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tif ( newView.type !== view.type ) {\n\t\t\t// Retrigger the routing areas resolution.\n\t\t\thistory.invalidate();\n\t\t}\n\t\tupdateView( newView );\n\t} );\n\n\tconst [ selection, setSelection ] = useState( postId?.split( ',' ) ?? [] );\n\tconst onChangeSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items );\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\tpostId: items.join( ',' ),\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t\t[ path, history ]\n\t);\n\n\tconst fields = usePostFields( {\n\t\tpostType,\n\t} );\n\n\tconst queryArgs = useMemo( () => {\n\t\tconst filters = {};\n\t\tview.filters?.forEach( ( filter ) => {\n\t\t\tif (\n\t\t\t\tfilter.field === 'status' &&\n\t\t\t\tfilter.operator === OPERATOR_IS_ANY\n\t\t\t) {\n\t\t\t\tfilters.status = filter.value;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tfilter.field === 'author' &&\n\t\t\t\tfilter.operator === OPERATOR_IS_ANY\n\t\t\t) {\n\t\t\t\tfilters.author = filter.value;\n\t\t\t} else if (\n\t\t\t\tfilter.field === 'author' &&\n\t\t\t\tfilter.operator === OPERATOR_IS_NONE\n\t\t\t) {\n\t\t\t\tfilters.author_exclude = filter.value;\n\t\t\t}\n\t\t} );\n\n\t\t// We want to provide a different default item for the status filter\n\t\t// than the REST API provides.\n\t\tif ( ! filters.status || filters.status === '' ) {\n\t\t\tfilters.status = DEFAULT_STATUSES;\n\t\t}\n\n\t\treturn {\n\t\t\tper_page: view.perPage,\n\t\t\tpage: view.page,\n\t\t\t_embed: 'author,wp:featuredmedia',\n\t\t\torder: view.sort?.direction,\n\t\t\torderby: view.sort?.field,\n\t\t\torderby_hierarchy: !! view.showLevels,\n\t\t\tsearch: view.search,\n\t\t\t...filters,\n\t\t};\n\t}, [ view ] );\n\tconst {\n\t\trecords,\n\t\tisResolving: isLoadingData,\n\t\ttotalItems,\n\t\ttotalPages,\n\t} = useEntityRecordsWithPermissions( 'postType', postType, queryArgs );\n\n\t// The REST API sort the authors by ID, but we want to sort them by name.\n\tconst data = useMemo( () => {\n\t\tif ( view?.sort?.field === 'author' ) {\n\t\t\treturn filterSortAndPaginate(\n\t\t\t\trecords,\n\t\t\t\t{ sort: { ...view.sort } },\n\t\t\t\tfields\n\t\t\t).data;\n\t\t}\n\n\t\treturn records;\n\t}, [ records, fields, view?.sort ] );\n\n\tconst ids = data?.map( ( record ) => getItemId( record ) ) ?? [];\n\tconst prevIds = usePrevious( ids ) ?? [];\n\tconst deletedIds = prevIds.filter( ( id ) => ! ids.includes( id ) );\n\tconst postIdWasDeleted = deletedIds.includes( postId );\n\n\tuseEffect( () => {\n\t\tif ( postIdWasDeleted ) {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\tpostId: undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\t}, [ history, postIdWasDeleted, path ] );\n\n\tconst paginationInfo = useMemo(\n\t\t() => ( {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t} ),\n\t\t[ totalItems, totalPages ]\n\t);\n\n\tconst { labels, canCreateRecord } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getPostType, canUser } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tlabels: getPostType( postType )?.labels,\n\t\t\t\tcanCreateRecord: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: postType,\n\t\t\t\t} ),\n\t\t\t};\n\t\t},\n\t\t[ postType ]\n\t);\n\n\tconst postTypeActions = usePostActions( {\n\t\tpostType,\n\t\tcontext: 'list',\n\t} );\n\tconst editAction = useEditPostAction();\n\tconst actions = useMemo(\n\t\t() => [ editAction, ...postTypeActions ],\n\t\t[ postTypeActions, editAction ]\n\t);\n\n\tconst [ showAddPostModal, setShowAddPostModal ] = useState( false );\n\n\tconst openModal = () => setShowAddPostModal( true );\n\tconst closeModal = () => setShowAddPostModal( false );\n\tconst handleNewPage = ( { type, id } ) => {\n\t\thistory.navigate( `/${ type }/${ id }?canvas=edit` );\n\t\tcloseModal();\n\t};\n\n\treturn (\n\t\t<Page\n\t\t\ttitle={ labels?.name }\n\t\t\tactions={\n\t\t\t\t<>\n\t\t\t\t\t{ isModified && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tresetToDefault();\n\t\t\t\t\t\t\t\thistory.invalidate();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset view' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t{ labels?.add_new_item && canCreateRecord && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\tonClick={ openModal }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ labels.add_new_item }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t{ showAddPostModal && (\n\t\t\t\t\t\t\t\t<AddNewPostModal\n\t\t\t\t\t\t\t\t\tpostType={ postType }\n\t\t\t\t\t\t\t\t\tonSave={ handleNewPage }\n\t\t\t\t\t\t\t\t\tonClose={ closeModal }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t}\n\t\t>\n\t\t\t<DataViews\n\t\t\t\tkey={ activeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tfields={ fields }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data || EMPTY_ARRAY }\n\t\t\t\tisLoading={ isLoadingData }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tselection={ selection }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tisItemClickable={ ( item ) => item.status !== 'trash' }\n\t\t\t\tonClickItem={ ( { id } ) => {\n\t\t\t\t\thistory.navigate( `/${ postType }/${ id }?canvas=edit` );\n\t\t\t\t} }\n\t\t\t\tgetItemId={ getItemId }\n\t\t\t\tgetItemLevel={ getItemLevel }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\theader={\n\t\t\t\t\twindow.__experimentalQuickEditDataViews &&\n\t\t\t\t\tview.type !== LAYOUT_LIST &&\n\t\t\t\t\tpostType === 'page' && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tisPressed={ quickEdit }\n\t\t\t\t\t\t\ticon={ drawerRight }\n\t\t\t\t\t\t\tlabel={ __( 'Details' ) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t\t\t\t\t\tquickEdit: quickEdit ? undefined : true,\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAkOM,SAWA,UAXA,KAWA,YAXA;AA/NN,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB;AAAA,EACC,SAAS;AAAA,EACT,eAAe;AAAA,OACT;AACP,SAAS,UAAU,SAAS,aAAa,iBAAiB;AAC1D,SAAS,eAAe,yBAAyB;AACjD,SAAS,iBAAiB;AAC1B,SAAS,WAAW,6BAA6B;AACjD,SAAS,eAAe,yBAAyB;AACjD,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,UAAU,mBAAmB;AACtC,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AAKxB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,OAAO,qBAAqB;AAC5B,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,gBAAgB,sBAAsB;A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BAAQ;AAAA,kBACP,aAAc,MAAM;AAAA,oBACnB,WAAW,YAAY,SAAY;AAAA,kBACpC,CAAE;AAAA,gBACH;AAAA,cACD;AAAA;AAAA,UACD;AAAA;AAAA,QAjCI;AAAA,MAoCP;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -60,7 +60,11 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
60
60
|
to: addQueryArgs("/template", { activeView: "user" }),
|
|
61
61
|
icon: layout,
|
|
62
62
|
"aria-current": activeView === "user",
|
|
63
|
-
|
|
63
|
+
// Let's avoid calling them "custom templates" to avoid
|
|
64
|
+
// confusion. "Created" is closest to meaning database
|
|
65
|
+
// templates, created by users.
|
|
66
|
+
// https://developer.wordpress.org/themes/classic-themes/templates/page-template-files/#creating-custom-page-templates-for-global-use
|
|
67
|
+
children: __("Created templates")
|
|
64
68
|
}
|
|
65
69
|
),
|
|
66
70
|
firstItemPerAuthorText.map((template) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/sidebar-navigation-screen-templates-browse/content.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { layout } from '@wordpress/icons';\nimport { unlock } from '../../lock-unlock';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nfunction TemplateDataviewItem( { template, isActive } ) {\n\tconst { text, icon } = useAddedBy( template.type, template.id );\n\n\treturn (\n\t\t<SidebarNavigationItem\n\t\t\tto={ addQueryArgs( '/template', { activeView: text } ) }\n\t\t\ticon={ icon }\n\t\t\taria-current={ isActive }\n\t\t>\n\t\t\t{ text }\n\t\t</SidebarNavigationItem>\n\t);\n}\n\nexport default function DataviewsTemplatesSidebarContent() {\n\tconst {\n\t\tquery: { activeView = 'active' },\n\t} = useLocation();\n\tconst { records } = useEntityRecords(\n\t\t'postType',\n\t\t'wp_registered_template',\n\t\t{\n\t\t\tper_page: -1,\n\t\t}\n\t);\n\tconst firstItemPerAuthorText = useMemo( () => {\n\t\tconst firstItemPerAuthor = records?.reduce( ( acc, template ) => {\n\t\t\tconst author = template.author_text;\n\t\t\tif ( author && ! acc[ author ] ) {\n\t\t\t\tacc[ author ] = template;\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, {} );\n\t\treturn (\n\t\t\t( firstItemPerAuthor && Object.values( firstItemPerAuthor ) ) ??\n\t\t\tEMPTY_ARRAY\n\t\t);\n\t}, [ records ] );\n\n\treturn (\n\t\t<ItemGroup className=\"edit-site-sidebar-navigation-screen-templates-browse\">\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto=\"/template\"\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'active' }\n\t\t\t>\n\t\t\t\t{ __( 'Active templates' ) }\n\t\t\t</SidebarNavigationItem>\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto={ addQueryArgs( '/template', { activeView: 'user' } ) }\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'user' }\n\t\t\t>\n\t\t\t\t{
|
|
5
|
-
"mappings": "AA0BE,cAoCA,YApCA;AAvBF,SAAS,wBAAwB;AACjC,SAAS,eAAe;AACxB,SAAS,2BAA2B,iBAAiB;AACrD,SAAS,UAAU;AACnB,SAAS,eAAe,yBAAyB;AACjD,SAAS,oBAAoB;AAK7B,OAAO,2BAA2B;AAClC,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,MAAM,EAAE,YAAY,IAAI,OAAQ,iBAAkB;AAElD,MAAM,cAAc,CAAC;AAErB,SAAS,qBAAsB,EAAE,UAAU,SAAS,GAAI;AACvD,QAAM,EAAE,MAAM,KAAK,IAAI,WAAY,SAAS,MAAM,SAAS,EAAG;AAE9D,SACC;AAAA,IAAC;AAAA;AAAA,MACA,IAAK,aAAc,aAAa,EAAE,YAAY,KAAK,CAAE;AAAA,MACrD;AAAA,MACA,gBAAe;AAAA,MAEb;AAAA;AAAA,EACH;AAEF;AAEe,SAAR,mCAAoD;AAC1D,QAAM;AAAA,IACL,OAAO,EAAE,aAAa,SAAS;AAAA,EAChC,IAAI,YAAY;AAChB,QAAM,EAAE,QAAQ,IAAI;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,MACC,UAAU;AAAA,IACX;AAAA,EACD;AACA,QAAM,yBAAyB,QAAS,MAAM;AAC7C,UAAM,qBAAqB,SAAS,OAAQ,CAAE,KAAK,aAAc;AAChE,YAAM,SAAS,SAAS;AACxB,UAAK,UAAU,CAAE,IAAK,MAAO,GAAI;AAChC,YAAK,MAAO,IAAI;AAAA,MACjB;AACA,aAAO;AAAA,IACR,GAAG,CAAC,CAAE;AACN,YACG,sBAAsB,OAAO,OAAQ,kBAAmB,MAC1D;AAAA,EAEF,GAAG,CAAE,OAAQ,CAAE;AAEf,SACC,qBAAC,aAAU,WAAU,wDACpB;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,IAAG;AAAA,QACH,MAAO;AAAA,QACP,gBAAe,eAAe;AAAA,QAE5B,aAAI,kBAAmB;AAAA;AAAA,IAC1B;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,IAAK,aAAc,aAAa,EAAE,YAAY,OAAO,CAAE;AAAA,QACvD,MAAO;AAAA,QACP,gBAAe,eAAe;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { layout } from '@wordpress/icons';\nimport { unlock } from '../../lock-unlock';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nfunction TemplateDataviewItem( { template, isActive } ) {\n\tconst { text, icon } = useAddedBy( template.type, template.id );\n\n\treturn (\n\t\t<SidebarNavigationItem\n\t\t\tto={ addQueryArgs( '/template', { activeView: text } ) }\n\t\t\ticon={ icon }\n\t\t\taria-current={ isActive }\n\t\t>\n\t\t\t{ text }\n\t\t</SidebarNavigationItem>\n\t);\n}\n\nexport default function DataviewsTemplatesSidebarContent() {\n\tconst {\n\t\tquery: { activeView = 'active' },\n\t} = useLocation();\n\tconst { records } = useEntityRecords(\n\t\t'postType',\n\t\t'wp_registered_template',\n\t\t{\n\t\t\tper_page: -1,\n\t\t}\n\t);\n\tconst firstItemPerAuthorText = useMemo( () => {\n\t\tconst firstItemPerAuthor = records?.reduce( ( acc, template ) => {\n\t\t\tconst author = template.author_text;\n\t\t\tif ( author && ! acc[ author ] ) {\n\t\t\t\tacc[ author ] = template;\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, {} );\n\t\treturn (\n\t\t\t( firstItemPerAuthor && Object.values( firstItemPerAuthor ) ) ??\n\t\t\tEMPTY_ARRAY\n\t\t);\n\t}, [ records ] );\n\n\treturn (\n\t\t<ItemGroup className=\"edit-site-sidebar-navigation-screen-templates-browse\">\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto=\"/template\"\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'active' }\n\t\t\t>\n\t\t\t\t{ __( 'Active templates' ) }\n\t\t\t</SidebarNavigationItem>\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto={ addQueryArgs( '/template', { activeView: 'user' } ) }\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'user' }\n\t\t\t>\n\t\t\t\t{\n\t\t\t\t\t// Let's avoid calling them \"custom templates\" to avoid\n\t\t\t\t\t// confusion. \"Created\" is closest to meaning database\n\t\t\t\t\t// templates, created by users.\n\t\t\t\t\t// https://developer.wordpress.org/themes/classic-themes/templates/page-template-files/#creating-custom-page-templates-for-global-use\n\t\t\t\t\t__( 'Created templates' )\n\t\t\t\t}\n\t\t\t</SidebarNavigationItem>\n\t\t\t{ firstItemPerAuthorText.map( ( template ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<TemplateDataviewItem\n\t\t\t\t\t\tkey={ template.author_text }\n\t\t\t\t\t\ttemplate={ template }\n\t\t\t\t\t\tisActive={ activeView === template.author_text }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</ItemGroup>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AA0BE,cAoCA,YApCA;AAvBF,SAAS,wBAAwB;AACjC,SAAS,eAAe;AACxB,SAAS,2BAA2B,iBAAiB;AACrD,SAAS,UAAU;AACnB,SAAS,eAAe,yBAAyB;AACjD,SAAS,oBAAoB;AAK7B,OAAO,2BAA2B;AAClC,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,MAAM,EAAE,YAAY,IAAI,OAAQ,iBAAkB;AAElD,MAAM,cAAc,CAAC;AAErB,SAAS,qBAAsB,EAAE,UAAU,SAAS,GAAI;AACvD,QAAM,EAAE,MAAM,KAAK,IAAI,WAAY,SAAS,MAAM,SAAS,EAAG;AAE9D,SACC;AAAA,IAAC;AAAA;AAAA,MACA,IAAK,aAAc,aAAa,EAAE,YAAY,KAAK,CAAE;AAAA,MACrD;AAAA,MACA,gBAAe;AAAA,MAEb;AAAA;AAAA,EACH;AAEF;AAEe,SAAR,mCAAoD;AAC1D,QAAM;AAAA,IACL,OAAO,EAAE,aAAa,SAAS;AAAA,EAChC,IAAI,YAAY;AAChB,QAAM,EAAE,QAAQ,IAAI;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,MACC,UAAU;AAAA,IACX;AAAA,EACD;AACA,QAAM,yBAAyB,QAAS,MAAM;AAC7C,UAAM,qBAAqB,SAAS,OAAQ,CAAE,KAAK,aAAc;AAChE,YAAM,SAAS,SAAS;AACxB,UAAK,UAAU,CAAE,IAAK,MAAO,GAAI;AAChC,YAAK,MAAO,IAAI;AAAA,MACjB;AACA,aAAO;AAAA,IACR,GAAG,CAAC,CAAE;AACN,YACG,sBAAsB,OAAO,OAAQ,kBAAmB,MAC1D;AAAA,EAEF,GAAG,CAAE,OAAQ,CAAE;AAEf,SACC,qBAAC,aAAU,WAAU,wDACpB;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,IAAG;AAAA,QACH,MAAO;AAAA,QACP,gBAAe,eAAe;AAAA,QAE5B,aAAI,kBAAmB;AAAA;AAAA,IAC1B;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,IAAK,aAAc,aAAa,EAAE,YAAY,OAAO,CAAE;AAAA,QACvD,MAAO;AAAA,QACP,gBAAe,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,QAO7B,aAAI,mBAAoB;AAAA;AAAA,IAE1B;AAAA,IACE,uBAAuB,IAAK,CAAE,aAAc;AAC7C,aACC;AAAA,QAAC;AAAA;AAAA,UAEA;AAAA,UACA,UAAW,eAAe,SAAS;AAAA;AAAA,QAF7B,SAAS;AAAA,MAGhB;AAAA,IAEF,CAAE;AAAA,KACH;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,7 +10,7 @@ import { patternsRoute } from "./patterns";
|
|
|
10
10
|
import { patternItemRoute } from "./pattern-item";
|
|
11
11
|
import { templatePartItemRoute } from "./template-part-item";
|
|
12
12
|
import { templatesRoute } from "./templates";
|
|
13
|
-
import { templateItemRoute
|
|
13
|
+
import { templateItemRoute } from "./template-item";
|
|
14
14
|
import { pagesRoute } from "./pages";
|
|
15
15
|
import { pageItemRoute } from "./page-item";
|
|
16
16
|
import { stylebookRoute } from "./stylebook";
|
|
@@ -19,7 +19,6 @@ const routes = [
|
|
|
19
19
|
pageItemRoute,
|
|
20
20
|
pagesRoute,
|
|
21
21
|
templateItemRoute,
|
|
22
|
-
staticTemplateItemRoute,
|
|
23
22
|
templatesRoute,
|
|
24
23
|
templatePartItemRoute,
|
|
25
24
|
patternItemRoute,
|