@wordpress/edit-site 6.33.3 → 6.33.5
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/build/components/page-templates/fields.js +2 -2
- package/build/components/page-templates/fields.js.map +2 -2
- package/build/components/page-templates/index.js +11 -8
- package/build/components/page-templates/index.js.map +2 -2
- package/build/components/page-templates/view-utils.js +4 -0
- package/build/components/page-templates/view-utils.js.map +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
- package/build-module/components/page-templates/fields.js +2 -2
- package/build-module/components/page-templates/fields.js.map +2 -2
- package/build-module/components/page-templates/index.js +11 -8
- package/build-module/components/page-templates/index.js.map +2 -2
- package/build-module/components/page-templates/view-utils.js +4 -0
- package/build-module/components/page-templates/view-utils.js.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +3 -3
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
- package/package.json +12 -12
- package/src/components/page-templates/fields.js +3 -3
- package/src/components/page-templates/index.js +11 -7
- package/src/components/page-templates/view-utils.js +7 -0
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +3 -3
|
@@ -145,10 +145,10 @@ const activeField = {
|
|
|
145
145
|
type: "boolean",
|
|
146
146
|
getValue: ({ item }) => item._isActive,
|
|
147
147
|
render: function Render({ item }) {
|
|
148
|
-
const activeLabel = item._isCustom ? (0, import_i18n.
|
|
148
|
+
const activeLabel = item._isCustom ? (0, import_i18n._x)("Active when used", "template") : (0, import_i18n._x)("Active", "template");
|
|
149
149
|
const activeIntent = item._isCustom ? "info" : "success";
|
|
150
150
|
const isActive = item._isActive;
|
|
151
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { intent: isActive ? activeIntent : "default", children: isActive ? activeLabel : (0, import_i18n.
|
|
151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { intent: isActive ? activeIntent : "default", children: isActive ? activeLabel : (0, import_i18n._x)("Inactive", "template") });
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
const useThemeField = () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/page-templates/fields.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { parse } from '@wordpress/blocks';\nimport {\n\tBlockPreview,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { EditorProvider } from '@wordpress/editor';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useAddedBy } from './hooks';\nimport { useDefaultTemplateTypes } from '../add-new-template/utils';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalStyle } = unlock( blockEditorPrivateApis );\nconst { Badge } = unlock( componentsPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nfunction useAllDefaultTemplateTypes() {\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst { records: staticRecords } = useEntityRecordsWithPermissions(\n\t\t'root',\n\t\t'registeredTemplate'\n\t);\n\treturn [\n\t\t...defaultTemplateTypes,\n\t\t...staticRecords\n\t\t\t?.filter( ( record ) => ! record.is_custom )\n\t\t\t.map( ( record ) => {\n\t\t\t\treturn {\n\t\t\t\t\tslug: record.slug,\n\t\t\t\t\ttitle: record.title.rendered,\n\t\t\t\t\tdescription: record.description,\n\t\t\t\t};\n\t\t\t} ),\n\t];\n}\n\nfunction PreviewField( { item } ) {\n\tconst settings = usePatternSettings();\n\tconst [ backgroundColor = 'white' ] = useGlobalStyle( 'color.background' );\n\tconst blocks = useMemo( () => {\n\t\treturn parse( item.content.raw );\n\t}, [ item.content.raw ] );\n\n\tconst isEmpty = ! blocks?.length;\n\t// Wrap everything in a block editor provider to ensure 'styles' that are needed\n\t// for the previews are synced between the site editor store and the block editor store.\n\t// Additionally we need to have the `__experimentalBlockPatterns` setting in order to\n\t// render patterns inside the previews.\n\t// TODO: Same approach is used in the patterns list and it becomes obvious that some of\n\t// the block editor settings are needed in context where we don't have the block editor.\n\t// Explore how we can solve this in a better way.\n\treturn (\n\t\t<EditorProvider post={ item } settings={ settings }>\n\t\t\t<div\n\t\t\t\tclassName=\"page-templates-preview-field\"\n\t\t\t\tstyle={ { backgroundColor } }\n\t\t\t>\n\t\t\t\t{ isEmpty && __( 'Empty template' ) }\n\t\t\t\t{ ! isEmpty && (\n\t\t\t\t\t<BlockPreview.Async>\n\t\t\t\t\t\t<BlockPreview blocks={ blocks } />\n\t\t\t\t\t</BlockPreview.Async>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</EditorProvider>\n\t);\n}\n\nexport const previewField = {\n\tlabel: __( 'Preview' ),\n\tid: 'preview',\n\trender: PreviewField,\n\tenableSorting: false,\n};\n\nexport const descriptionField = {\n\tlabel: __( 'Description' ),\n\tid: 'description',\n\trender: function RenderDescription( { item } ) {\n\t\tconst defaultTemplateTypes = useAllDefaultTemplateTypes();\n\t\tconst defaultTemplateType = defaultTemplateTypes.find(\n\t\t\t( type ) => type.slug === item.slug\n\t\t);\n\t\treturn item.description\n\t\t\t? decodeEntities( item.description )\n\t\t\t: defaultTemplateType?.description;\n\t},\n\tenableSorting: false,\n\tenableGlobalSearch: true,\n};\n\nfunction AuthorField( { item } ) {\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\tconst { text, icon, imageUrl } = useAddedBy( item.type, item.id );\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport const authorField = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\tgetValue: ( { item } ) => item.author_text ?? item.author,\n\trender: AuthorField,\n};\n\nexport const activeField = {\n\tlabel: __( 'Status' ),\n\tid: 'active',\n\ttype: 'boolean',\n\tgetValue: ( { item } ) => item._isActive,\n\trender: function Render( { item } ) {\n\t\tconst activeLabel = item._isCustom\n\t\t\t?
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EG;AA1EH,kBAAiB;AAKjB,wBAIO;AACP,kBAAuB;AACvB,qBAAkC;AAClC,2BAA+B;AAC/B,oBAAsB;AACtB,0BAGO;AACP,oBAA+B;AAC/B,uBAGO;AACP,kBAA0B;AAK1B,mBAA2B;AAC3B,mBAAwC;AACxC,kCAA+B;AAC/B,yBAAuB;AAEvB,MAAM,EAAE,eAAe,QAAI,2BAAQ,oBAAAA,WAAuB;AAC1D,MAAM,EAAE,MAAM,QAAI,2BAAQ,kBAAAC,WAAsB;AAChD,MA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\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { parse } from '@wordpress/blocks';\nimport {\n\tBlockPreview,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { EditorProvider } from '@wordpress/editor';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useAddedBy } from './hooks';\nimport { useDefaultTemplateTypes } from '../add-new-template/utils';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalStyle } = unlock( blockEditorPrivateApis );\nconst { Badge } = unlock( componentsPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nfunction useAllDefaultTemplateTypes() {\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst { records: staticRecords } = useEntityRecordsWithPermissions(\n\t\t'root',\n\t\t'registeredTemplate'\n\t);\n\treturn [\n\t\t...defaultTemplateTypes,\n\t\t...staticRecords\n\t\t\t?.filter( ( record ) => ! record.is_custom )\n\t\t\t.map( ( record ) => {\n\t\t\t\treturn {\n\t\t\t\t\tslug: record.slug,\n\t\t\t\t\ttitle: record.title.rendered,\n\t\t\t\t\tdescription: record.description,\n\t\t\t\t};\n\t\t\t} ),\n\t];\n}\n\nfunction PreviewField( { item } ) {\n\tconst settings = usePatternSettings();\n\tconst [ backgroundColor = 'white' ] = useGlobalStyle( 'color.background' );\n\tconst blocks = useMemo( () => {\n\t\treturn parse( item.content.raw );\n\t}, [ item.content.raw ] );\n\n\tconst isEmpty = ! blocks?.length;\n\t// Wrap everything in a block editor provider to ensure 'styles' that are needed\n\t// for the previews are synced between the site editor store and the block editor store.\n\t// Additionally we need to have the `__experimentalBlockPatterns` setting in order to\n\t// render patterns inside the previews.\n\t// TODO: Same approach is used in the patterns list and it becomes obvious that some of\n\t// the block editor settings are needed in context where we don't have the block editor.\n\t// Explore how we can solve this in a better way.\n\treturn (\n\t\t<EditorProvider post={ item } settings={ settings }>\n\t\t\t<div\n\t\t\t\tclassName=\"page-templates-preview-field\"\n\t\t\t\tstyle={ { backgroundColor } }\n\t\t\t>\n\t\t\t\t{ isEmpty && __( 'Empty template' ) }\n\t\t\t\t{ ! isEmpty && (\n\t\t\t\t\t<BlockPreview.Async>\n\t\t\t\t\t\t<BlockPreview blocks={ blocks } />\n\t\t\t\t\t</BlockPreview.Async>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</EditorProvider>\n\t);\n}\n\nexport const previewField = {\n\tlabel: __( 'Preview' ),\n\tid: 'preview',\n\trender: PreviewField,\n\tenableSorting: false,\n};\n\nexport const descriptionField = {\n\tlabel: __( 'Description' ),\n\tid: 'description',\n\trender: function RenderDescription( { item } ) {\n\t\tconst defaultTemplateTypes = useAllDefaultTemplateTypes();\n\t\tconst defaultTemplateType = defaultTemplateTypes.find(\n\t\t\t( type ) => type.slug === item.slug\n\t\t);\n\t\treturn item.description\n\t\t\t? decodeEntities( item.description )\n\t\t\t: defaultTemplateType?.description;\n\t},\n\tenableSorting: false,\n\tenableGlobalSearch: true,\n};\n\nfunction AuthorField( { item } ) {\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\tconst { text, icon, imageUrl } = useAddedBy( item.type, item.id );\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport const authorField = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\tgetValue: ( { item } ) => item.author_text ?? item.author,\n\trender: AuthorField,\n};\n\nexport const activeField = {\n\tlabel: __( 'Status' ),\n\tid: 'active',\n\ttype: 'boolean',\n\tgetValue: ( { item } ) => item._isActive,\n\trender: function Render( { item } ) {\n\t\tconst activeLabel = item._isCustom\n\t\t\t? _x( 'Active when used', 'template' )\n\t\t\t: _x( 'Active', 'template' );\n\t\tconst activeIntent = item._isCustom ? 'info' : 'success';\n\t\tconst isActive = item._isActive;\n\t\treturn (\n\t\t\t<Badge intent={ isActive ? activeIntent : 'default' }>\n\t\t\t\t{ isActive ? activeLabel : _x( 'Inactive', 'template' ) }\n\t\t\t</Badge>\n\t\t);\n\t},\n};\n\nexport const useThemeField = () => {\n\tconst activeTheme = useSelect( ( select ) =>\n\t\tselect( coreStore ).getCurrentTheme()\n\t);\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tlabel: __( 'Compatible Theme' ),\n\t\t\tid: 'theme',\n\t\t\tgetValue: ( { item } ) => item.theme,\n\t\t\trender: function Render( { item } ) {\n\t\t\t\tif ( item.theme === activeTheme.stylesheet ) {\n\t\t\t\t\treturn <Badge intent=\"success\">{ item.theme }</Badge>;\n\t\t\t\t}\n\t\t\t\treturn <Badge intent=\"error\">{ item.theme }</Badge>;\n\t\t\t},\n\t\t} ),\n\t\t[ activeTheme ]\n\t);\n};\n\nexport const slugField = {\n\tlabel: __( 'Template Type' ),\n\tid: 'slug',\n\tgetValue: ( { item } ) => item.slug,\n\trender: function Render( { item } ) {\n\t\tconst defaultTemplateTypes = useAllDefaultTemplateTypes();\n\t\tconst defaultTemplateType = defaultTemplateTypes.find(\n\t\t\t( type ) => type.slug === item.slug\n\t\t);\n\t\treturn defaultTemplateType?.title || _x( 'Custom', 'template type' );\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EG;AA1EH,kBAAiB;AAKjB,wBAIO;AACP,kBAAuB;AACvB,qBAAkC;AAClC,2BAA+B;AAC/B,oBAAsB;AACtB,0BAGO;AACP,oBAA+B;AAC/B,uBAGO;AACP,kBAA0B;AAK1B,mBAA2B;AAC3B,mBAAwC;AACxC,kCAA+B;AAC/B,yBAAuB;AAEvB,MAAM,EAAE,eAAe,QAAI,2BAAQ,oBAAAA,WAAuB;AAC1D,MAAM,EAAE,MAAM,QAAI,2BAAQ,kBAAAC,WAAsB;AAChD,MAAM,EAAE,gCAAgC,QAAI,2BAAQ,iBAAAC,WAAgB;AAEpE,SAAS,6BAA6B;AACrC,QAAM,2BAAuB,sCAAwB;AACrD,QAAM,EAAE,SAAS,cAAc,IAAI;AAAA,IAClC;AAAA,IACA;AAAA,EACD;AACA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,eACA,OAAQ,CAAE,WAAY,CAAE,OAAO,SAAU,EAC1C,IAAK,CAAE,WAAY;AACnB,aAAO;AAAA,QACN,MAAM,OAAO;AAAA,QACb,OAAO,OAAO,MAAM;AAAA,QACpB,aAAa,OAAO;AAAA,MACrB;AAAA,IACD,CAAE;AAAA,EACJ;AACD;AAEA,SAAS,aAAc,EAAE,KAAK,GAAI;AACjC,QAAM,eAAW,4BAAAC,SAAmB;AACpC,QAAM,CAAE,kBAAkB,OAAQ,IAAI,eAAgB,kBAAmB;AACzE,QAAM,aAAS,wBAAS,MAAM;AAC7B,eAAO,qBAAO,KAAK,QAAQ,GAA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,IACD;AAAA,IACA,CAAE,WAAY;AAAA,EACf;AACD;AAEO,MAAM,YAAY;AAAA,EACxB,WAAO,gBAAI,eAAgB;AAAA,EAC3B,IAAI;AAAA,EACJ,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK;AAAA,EAC/B,QAAQ,SAASA,QAAQ,EAAE,KAAK,GAAI;AACnC,UAAM,uBAAuB,2BAA2B;AACxD,UAAM,sBAAsB,qBAAqB;AAAA,MAChD,CAAE,SAAU,KAAK,SAAS,KAAK;AAAA,IAChC;AACA,WAAO,qBAAqB,aAAS,gBAAI,UAAU,eAAgB;AAAA,EACpE;AACD;",
|
|
6
6
|
"names": ["blockEditorPrivateApis", "componentsPrivateApis", "corePrivateApis", "usePatternSettings", "HStack", "clsx", "coreStore", "Render"]
|
|
7
7
|
}
|
|
@@ -52,7 +52,7 @@ var import_lock_unlock = require("../../lock-unlock");
|
|
|
52
52
|
var import_dataviews_actions = require("../dataviews-actions");
|
|
53
53
|
var import_fields = require("./fields");
|
|
54
54
|
var import_view_utils = require("./view-utils");
|
|
55
|
-
const { usePostActions, templateTitleField } = (0, import_lock_unlock.unlock)(import_editor.privateApis);
|
|
55
|
+
const { usePostActions, usePostFields, templateTitleField } = (0, import_lock_unlock.unlock)(import_editor.privateApis);
|
|
56
56
|
const { useHistory, useLocation } = (0, import_lock_unlock.unlock)(import_router.privateApis);
|
|
57
57
|
const { useEntityRecordsWithPermissions } = (0, import_lock_unlock.unlock)(import_core_data.privateApis);
|
|
58
58
|
function PageTemplates() {
|
|
@@ -195,6 +195,10 @@ function PageTemplates() {
|
|
|
195
195
|
},
|
|
196
196
|
[history, path, view?.type]
|
|
197
197
|
);
|
|
198
|
+
const postTypeFields = usePostFields({
|
|
199
|
+
postType: import_constants.TEMPLATE_POST_TYPE
|
|
200
|
+
});
|
|
201
|
+
const dateField = postTypeFields.find((field) => field.id === "date");
|
|
198
202
|
const themeField = (0, import_fields.useThemeField)();
|
|
199
203
|
const fields = (0, import_element.useMemo)(() => {
|
|
200
204
|
const _fields = [
|
|
@@ -206,6 +210,9 @@ function PageTemplates() {
|
|
|
206
210
|
];
|
|
207
211
|
if (activeView === "user") {
|
|
208
212
|
_fields.push(themeField);
|
|
213
|
+
if (dateField) {
|
|
214
|
+
_fields.push(dateField);
|
|
215
|
+
}
|
|
209
216
|
}
|
|
210
217
|
const elements = [];
|
|
211
218
|
for (const author in users) {
|
|
@@ -219,7 +226,7 @@ function PageTemplates() {
|
|
|
219
226
|
elements
|
|
220
227
|
});
|
|
221
228
|
return _fields;
|
|
222
|
-
}, [users, activeView, themeField]);
|
|
229
|
+
}, [users, activeView, themeField, dateField]);
|
|
223
230
|
const { data, paginationInfo } = (0, import_element.useMemo)(() => {
|
|
224
231
|
return (0, import_dataviews.filterSortAndPaginate)(records, view, fields);
|
|
225
232
|
}, [records, view, fields]);
|
|
@@ -231,6 +238,7 @@ function PageTemplates() {
|
|
|
231
238
|
{
|
|
232
239
|
const newItem = items[0];
|
|
233
240
|
const _title = typeof newItem.title === "string" ? newItem.title : newItem.title?.rendered;
|
|
241
|
+
history.navigate(`/template?activeView=user`);
|
|
234
242
|
createSuccessNotice(
|
|
235
243
|
(0, import_i18n.sprintf)(
|
|
236
244
|
// translators: %s: Title of the created post or template, e.g: "Hello world".
|
|
@@ -334,12 +342,7 @@ function PageTemplates() {
|
|
|
334
342
|
duplicateAction.RenderModal,
|
|
335
343
|
{
|
|
336
344
|
items: [selectedRegisteredTemplate],
|
|
337
|
-
closeModal: () => setSelectedRegisteredTemplate()
|
|
338
|
-
onActionPerformed: ([item]) => {
|
|
339
|
-
history.navigate(
|
|
340
|
-
`/${item.type}/${item.id}?canvas=edit`
|
|
341
|
-
);
|
|
342
|
-
}
|
|
345
|
+
closeModal: () => setSelectedRegisteredTemplate()
|
|
343
346
|
}
|
|
344
347
|
)
|
|
345
348
|
}
|
|
@@ -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 { __, 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, defaultTemplateTypes } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getEntityRecord, getCurrentTheme } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tactiveTemplatesOption: getEntityRecord( 'root', 'site' )\n\t\t\t\t\t?.active_templates,\n\t\t\t\tactiveTheme: getCurrentTheme(),\n\t\t\t\tdefaultTemplateTypes:\n\t\t\t\t\tselect( coreStore ).getCurrentTheme()\n\t\t\t\t\t\t?.default_template_types,\n\t\t\t};\n\t\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( 'root', 'registeredTemplate', {\n\t\t\t// This should not be needed, the endpoint returns all registered\n\t\t\t// templates, but it's not possible right now to turn off pagination\n\t\t\t// for entity configs.\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ];\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\t// Replace the template in the array.\n\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t);\n\t\t\t\tif ( template ) {\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_active.push( template );\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 isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\tfunction isCustom( record ) {\n\t\t\t// For registered templates, the is_custom field is defined.\n\t\t\treturn (\n\t\t\t\trecord.is_custom ??\n\t\t\t\t// For user templates it's custom if the is_wp_suggestion meta\n\t\t\t\t// field is not set and the slug is not found in the default\n\t\t\t\t// template types.\n\t\t\t\t( ! record.meta?.is_wp_suggestion &&\n\t\t\t\t\t! defaultTemplateTypes.some(\n\t\t\t\t\t\t( type ) => type.slug === record.slug\n\t\t\t\t\t) )\n\t\t\t);\n\t\t}\n\n\t\tlet _records;\n\t\tif ( activeView === 'active' ) {\n\t\t\t// Don't show active custom templates in the active view.\n\t\t\t_records = activeTemplates.filter(\n\t\t\t\t( record ) => ! isCustom( record )\n\t\t\t);\n\t\t} else if ( activeView === 'user' ) {\n\t\t\t_records = userRecords;\n\t\t} else {\n\t\t\t_records = staticRecords;\n\t\t}\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.some(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t\t_isCustom: isCustom( record ),\n\t\t} ) );\n\t}, [\n\t\tactiveTemplates,\n\t\tdefaultTemplateTypes,\n\t\tuserRecords,\n\t\tstaticRecords,\n\t\tactiveView,\n\t] );\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 ( typeof item.id === 'string' ) {\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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, usePostFields, templateTitleField } =\n\tunlock( 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, defaultTemplateTypes } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getEntityRecord, getCurrentTheme } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tactiveTemplatesOption: getEntityRecord( 'root', 'site' )\n\t\t\t\t\t?.active_templates,\n\t\t\t\tactiveTheme: getCurrentTheme(),\n\t\t\t\tdefaultTemplateTypes:\n\t\t\t\t\tselect( coreStore ).getCurrentTheme()\n\t\t\t\t\t\t?.default_template_types,\n\t\t\t};\n\t\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( 'root', 'registeredTemplate', {\n\t\t\t// This should not be needed, the endpoint returns all registered\n\t\t\t// templates, but it's not possible right now to turn off pagination\n\t\t\t// for entity configs.\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ];\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\t// Replace the template in the array.\n\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t);\n\t\t\t\tif ( template ) {\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_active.push( template );\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 isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\tfunction isCustom( record ) {\n\t\t\t// For registered templates, the is_custom field is defined.\n\t\t\treturn (\n\t\t\t\trecord.is_custom ??\n\t\t\t\t// For user templates it's custom if the is_wp_suggestion meta\n\t\t\t\t// field is not set and the slug is not found in the default\n\t\t\t\t// template types.\n\t\t\t\t( ! record.meta?.is_wp_suggestion &&\n\t\t\t\t\t! defaultTemplateTypes.some(\n\t\t\t\t\t\t( type ) => type.slug === record.slug\n\t\t\t\t\t) )\n\t\t\t);\n\t\t}\n\n\t\tlet _records;\n\t\tif ( activeView === 'active' ) {\n\t\t\t// Don't show active custom templates in the active view.\n\t\t\t_records = activeTemplates.filter(\n\t\t\t\t( record ) => ! isCustom( record )\n\t\t\t);\n\t\t} else if ( activeView === 'user' ) {\n\t\t\t_records = userRecords;\n\t\t} else {\n\t\t\t_records = staticRecords;\n\t\t}\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.some(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t\t_isCustom: isCustom( record ),\n\t\t} ) );\n\t}, [\n\t\tactiveTemplates,\n\t\tdefaultTemplateTypes,\n\t\tuserRecords,\n\t\tstaticRecords,\n\t\tactiveView,\n\t] );\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 postTypeFields = usePostFields( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t} );\n\tconst dateField = postTypeFields.find( ( field ) => field.id === 'date' );\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\tif ( dateField ) {\n\t\t\t\t_fields.push( dateField );\n\t\t\t}\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, dateField ] );\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\thistory.navigate( `/template?activeView=user` );\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 ( typeof item.id === 'string' ) {\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/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiUI;AA9TJ,sBAAqB;AACrB,kBAA4B;AAC5B,2BAA+B;AAC/B,qBAA+C;AAC/C,uBAGO;AACP,uBAAiD;AACjD,oBAAiD;AACjD,oBAAiD;AACjD,iBAA6B;AAC7B,kBAAuC;AACvC,qBAAyB;AACzB,mBAAwB;AACxB,wBAA8B;AAC9B,qBAAsC;AAKtC,8BAA2B;AAC3B,uBAAmC;AACnC,yBAAuB;AACvB,+BAGO;AACP,oBAOO;AACP,wBAA+C;AAE/C,MAAM,EAAE,gBAAgB,eAAe,mBAAmB,QACzD,2BAAQ,cAAAA,WAAkB;AAC3B,MAAM,EAAE,YAAY,YAAY,QAAI,2BAAQ,cAAAC,WAAkB;AAC9D,MAAM,EAAE,gCAAgC,QAAI,2BAAQ,iBAAAC,WAAgB;AAErD,SAAR,gBAAiC;AACvC,QAAM,EAAE,MAAM,MAAM,IAAI,YAAY;AACpC,QAAM,EAAE,aAAa,UAAU,OAAO,IAAI;AAC1C,QAAM,CAAE,WAAW,YAAa,QAAI,yBAAU,CAAE,MAAO,CAAE;AACzD,QAAM,CAAE,4BAA4B,6BAA8B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BAAI,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;AAAA,YAClD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF;AAEF;",
|
|
6
6
|
"names": ["editorPrivateApis", "routerPrivateApis", "corePrivateApis", "coreStore", "noticesStore", "AddNewTemplate"]
|
|
7
7
|
}
|
|
@@ -50,6 +50,10 @@ const DEFAULT_VIEW = {
|
|
|
50
50
|
function getDefaultView(activeView) {
|
|
51
51
|
return {
|
|
52
52
|
...DEFAULT_VIEW,
|
|
53
|
+
sort: activeView === "user" ? {
|
|
54
|
+
field: "date",
|
|
55
|
+
direction: "desc"
|
|
56
|
+
} : DEFAULT_VIEW.sort,
|
|
53
57
|
filters: !["active", "user"].includes(activeView) ? [
|
|
54
58
|
{
|
|
55
59
|
field: "author",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/page-templates/view-utils.js"],
|
|
4
|
-
"sourcesContent": ["export const defaultLayouts = {\n\ttable: {\n\t\tshowMedia: false,\n\t},\n\tgrid: {\n\t\tshowMedia: true,\n\t},\n\tlist: {\n\t\tshowMedia: false,\n\t},\n};\n\nconst DEFAULT_VIEW = {\n\ttype: 'grid',\n\tperPage: 20,\n\tsort: {\n\t\tfield: 'title',\n\t\tdirection: 'asc',\n\t},\n\ttitleField: 'title',\n\tdescriptionField: 'description',\n\tmediaField: 'preview',\n\tfields: [ 'author', 'active', 'slug', 'theme' ],\n\tfilters: [],\n\t...defaultLayouts.grid,\n};\n\nexport function getDefaultView( activeView ) {\n\treturn {\n\t\t...DEFAULT_VIEW,\n\t\tfilters: ! [ 'active', 'user' ].includes( activeView )\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\toperator: 'isAny',\n\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t},\n\t\t\t ]\n\t\t\t: [],\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,iBAAiB;AAAA,EAC7B,OAAO;AAAA,IACN,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AACD;AAEA,MAAM,eAAe;AAAA,EACpB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,IACL,OAAO;AAAA,IACP,WAAW;AAAA,EACZ;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,QAAQ,CAAE,UAAU,UAAU,QAAQ,OAAQ;AAAA,EAC9C,SAAS,CAAC;AAAA,EACV,GAAG,eAAe;AACnB;AAEO,SAAS,eAAgB,YAAa;AAC5C,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS,CAAE,CAAE,UAAU,MAAO,EAAE,SAAU,UAAW,IAClD;AAAA,MACA;AAAA,QACC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO,CAAE,UAAW;AAAA,MACrB;AAAA,IACA,IACA,CAAC;AAAA,EACL;AACD;",
|
|
4
|
+
"sourcesContent": ["export const defaultLayouts = {\n\ttable: {\n\t\tshowMedia: false,\n\t},\n\tgrid: {\n\t\tshowMedia: true,\n\t},\n\tlist: {\n\t\tshowMedia: false,\n\t},\n};\n\nconst DEFAULT_VIEW = {\n\ttype: 'grid',\n\tperPage: 20,\n\tsort: {\n\t\tfield: 'title',\n\t\tdirection: 'asc',\n\t},\n\ttitleField: 'title',\n\tdescriptionField: 'description',\n\tmediaField: 'preview',\n\tfields: [ 'author', 'active', 'slug', 'theme' ],\n\tfilters: [],\n\t...defaultLayouts.grid,\n};\n\nexport function getDefaultView( activeView ) {\n\treturn {\n\t\t...DEFAULT_VIEW,\n\t\tsort:\n\t\t\tactiveView === 'user'\n\t\t\t\t? {\n\t\t\t\t\t\tfield: 'date',\n\t\t\t\t\t\tdirection: 'desc',\n\t\t\t\t }\n\t\t\t\t: DEFAULT_VIEW.sort,\n\t\tfilters: ! [ 'active', 'user' ].includes( activeView )\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\toperator: 'isAny',\n\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t},\n\t\t\t ]\n\t\t\t: [],\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,iBAAiB;AAAA,EAC7B,OAAO;AAAA,IACN,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AACD;AAEA,MAAM,eAAe;AAAA,EACpB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,IACL,OAAO;AAAA,IACP,WAAW;AAAA,EACZ;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,QAAQ,CAAE,UAAU,UAAU,QAAQ,OAAQ;AAAA,EAC9C,SAAS,CAAC;AAAA,EACV,GAAG,eAAe;AACnB;AAEO,SAAS,eAAgB,YAAa;AAC5C,SAAO;AAAA,IACN,GAAG;AAAA,IACH,MACC,eAAe,SACZ;AAAA,MACA,OAAO;AAAA,MACP,WAAW;AAAA,IACX,IACA,aAAa;AAAA,IACjB,SAAS,CAAE,CAAE,UAAU,MAAO,EAAE,SAAU,UAAW,IAClD;AAAA,MACA;AAAA,QACC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO,CAAE,UAAW;AAAA,MACrB;AAAA,IACA,IACA,CAAC;AAAA,EACL;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -81,7 +81,7 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
81
81
|
import_sidebar_navigation_item.default,
|
|
82
82
|
{
|
|
83
83
|
to: "/template",
|
|
84
|
-
icon: import_icons.
|
|
84
|
+
icon: import_icons.published,
|
|
85
85
|
"aria-current": activeView === "active",
|
|
86
86
|
children: (0, import_i18n.__)("Active templates")
|
|
87
87
|
}
|
|
@@ -90,7 +90,7 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
90
90
|
import_sidebar_navigation_item.default,
|
|
91
91
|
{
|
|
92
92
|
to: (0, import_url.addQueryArgs)("/template", { activeView: "user" }),
|
|
93
|
-
icon: import_icons.
|
|
93
|
+
icon: import_icons.commentAuthorAvatar,
|
|
94
94
|
"aria-current": activeView === "user",
|
|
95
95
|
// Let's avoid calling them "custom templates" to avoid
|
|
96
96
|
// confusion. "Created" is closest to meaning database
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BE;AAvBF,uBAAiC;AACjC,qBAAwB;AACxB,wBAAqD;AACrD,kBAAmB;AACnB,oBAAiD;AACjD,iBAA6B;AAK7B,qCAAkC;AAClC,mBAA2B;AAC3B,
|
|
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 { commentAuthorAvatar, published } 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( 'root', 'registeredTemplate', {\n\t\t// This should not be needed, the endpoint returns all registered\n\t\t// templates, but it's not possible right now to turn off pagination for\n\t\t// entity configs.\n\t\tper_page: -1,\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={ published }\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={ commentAuthorAvatar }\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BE;AAvBF,uBAAiC;AACjC,qBAAwB;AACxB,wBAAqD;AACrD,kBAAmB;AACnB,oBAAiD;AACjD,iBAA6B;AAK7B,qCAAkC;AAClC,mBAA2B;AAC3B,mBAA+C;AAC/C,yBAAuB;AAEvB,MAAM,EAAE,YAAY,QAAI,2BAAQ,cAAAA,WAAkB;AAElD,MAAM,cAAc,CAAC;AAErB,SAAS,qBAAsB,EAAE,UAAU,SAAS,GAAI;AACvD,QAAM,EAAE,MAAM,KAAK,QAAI,yBAAY,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F7B,SAAS;AAAA,MAGhB;AAAA,IAEF,CAAE;AAAA,KACH;AAEF;",
|
|
6
6
|
"names": ["routerPrivateApis", "SidebarNavigationItem", "ItemGroup"]
|
|
7
7
|
}
|
|
@@ -117,10 +117,10 @@ const activeField = {
|
|
|
117
117
|
type: "boolean",
|
|
118
118
|
getValue: ({ item }) => item._isActive,
|
|
119
119
|
render: function Render({ item }) {
|
|
120
|
-
const activeLabel = item._isCustom ?
|
|
120
|
+
const activeLabel = item._isCustom ? _x("Active when used", "template") : _x("Active", "template");
|
|
121
121
|
const activeIntent = item._isCustom ? "info" : "success";
|
|
122
122
|
const isActive = item._isActive;
|
|
123
|
-
return /* @__PURE__ */ jsx(Badge, { intent: isActive ? activeIntent : "default", children: isActive ? activeLabel :
|
|
123
|
+
return /* @__PURE__ */ jsx(Badge, { intent: isActive ? activeIntent : "default", children: isActive ? activeLabel : _x("Inactive", "template") });
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
const useThemeField = () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/page-templates/fields.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { parse } from '@wordpress/blocks';\nimport {\n\tBlockPreview,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { EditorProvider } from '@wordpress/editor';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useAddedBy } from './hooks';\nimport { useDefaultTemplateTypes } from '../add-new-template/utils';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalStyle } = unlock( blockEditorPrivateApis );\nconst { Badge } = unlock( componentsPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nfunction useAllDefaultTemplateTypes() {\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst { records: staticRecords } = useEntityRecordsWithPermissions(\n\t\t'root',\n\t\t'registeredTemplate'\n\t);\n\treturn [\n\t\t...defaultTemplateTypes,\n\t\t...staticRecords\n\t\t\t?.filter( ( record ) => ! record.is_custom )\n\t\t\t.map( ( record ) => {\n\t\t\t\treturn {\n\t\t\t\t\tslug: record.slug,\n\t\t\t\t\ttitle: record.title.rendered,\n\t\t\t\t\tdescription: record.description,\n\t\t\t\t};\n\t\t\t} ),\n\t];\n}\n\nfunction PreviewField( { item } ) {\n\tconst settings = usePatternSettings();\n\tconst [ backgroundColor = 'white' ] = useGlobalStyle( 'color.background' );\n\tconst blocks = useMemo( () => {\n\t\treturn parse( item.content.raw );\n\t}, [ item.content.raw ] );\n\n\tconst isEmpty = ! blocks?.length;\n\t// Wrap everything in a block editor provider to ensure 'styles' that are needed\n\t// for the previews are synced between the site editor store and the block editor store.\n\t// Additionally we need to have the `__experimentalBlockPatterns` setting in order to\n\t// render patterns inside the previews.\n\t// TODO: Same approach is used in the patterns list and it becomes obvious that some of\n\t// the block editor settings are needed in context where we don't have the block editor.\n\t// Explore how we can solve this in a better way.\n\treturn (\n\t\t<EditorProvider post={ item } settings={ settings }>\n\t\t\t<div\n\t\t\t\tclassName=\"page-templates-preview-field\"\n\t\t\t\tstyle={ { backgroundColor } }\n\t\t\t>\n\t\t\t\t{ isEmpty && __( 'Empty template' ) }\n\t\t\t\t{ ! isEmpty && (\n\t\t\t\t\t<BlockPreview.Async>\n\t\t\t\t\t\t<BlockPreview blocks={ blocks } />\n\t\t\t\t\t</BlockPreview.Async>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</EditorProvider>\n\t);\n}\n\nexport const previewField = {\n\tlabel: __( 'Preview' ),\n\tid: 'preview',\n\trender: PreviewField,\n\tenableSorting: false,\n};\n\nexport const descriptionField = {\n\tlabel: __( 'Description' ),\n\tid: 'description',\n\trender: function RenderDescription( { item } ) {\n\t\tconst defaultTemplateTypes = useAllDefaultTemplateTypes();\n\t\tconst defaultTemplateType = defaultTemplateTypes.find(\n\t\t\t( type ) => type.slug === item.slug\n\t\t);\n\t\treturn item.description\n\t\t\t? decodeEntities( item.description )\n\t\t\t: defaultTemplateType?.description;\n\t},\n\tenableSorting: false,\n\tenableGlobalSearch: true,\n};\n\nfunction AuthorField( { item } ) {\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\tconst { text, icon, imageUrl } = useAddedBy( item.type, item.id );\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport const authorField = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\tgetValue: ( { item } ) => item.author_text ?? item.author,\n\trender: AuthorField,\n};\n\nexport const activeField = {\n\tlabel: __( 'Status' ),\n\tid: 'active',\n\ttype: 'boolean',\n\tgetValue: ( { item } ) => item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,qCACd,8BAAC,QAAK,MAAc,GACrB;AAAA,IAED,oBAAC,UAAK,WAAU,qCAAsC,gBAAM;AAAA,KAC7D;AAEF;AAEO,MAAM,cAAc;AAAA,EAC1B,OAAO,GAAI,QAAS;AAAA,EACpB,IAAI;AAAA,EACJ,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK,eAAe,KAAK;AAAA,EACnD,QAAQ;AACT;AAEO,MAAM,cAAc;AAAA,EAC1B,OAAO,GAAI,QAAS;AAAA,EACpB,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK;AAAA,EAC/B,QAAQ,SAAS,OAAQ,EAAE,KAAK,GAAI;AACnC,UAAM,cAAc,KAAK,YACtB,GAAI,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { parse } from '@wordpress/blocks';\nimport {\n\tBlockPreview,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { EditorProvider } from '@wordpress/editor';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useAddedBy } from './hooks';\nimport { useDefaultTemplateTypes } from '../add-new-template/utils';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalStyle } = unlock( blockEditorPrivateApis );\nconst { Badge } = unlock( componentsPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nfunction useAllDefaultTemplateTypes() {\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst { records: staticRecords } = useEntityRecordsWithPermissions(\n\t\t'root',\n\t\t'registeredTemplate'\n\t);\n\treturn [\n\t\t...defaultTemplateTypes,\n\t\t...staticRecords\n\t\t\t?.filter( ( record ) => ! record.is_custom )\n\t\t\t.map( ( record ) => {\n\t\t\t\treturn {\n\t\t\t\t\tslug: record.slug,\n\t\t\t\t\ttitle: record.title.rendered,\n\t\t\t\t\tdescription: record.description,\n\t\t\t\t};\n\t\t\t} ),\n\t];\n}\n\nfunction PreviewField( { item } ) {\n\tconst settings = usePatternSettings();\n\tconst [ backgroundColor = 'white' ] = useGlobalStyle( 'color.background' );\n\tconst blocks = useMemo( () => {\n\t\treturn parse( item.content.raw );\n\t}, [ item.content.raw ] );\n\n\tconst isEmpty = ! blocks?.length;\n\t// Wrap everything in a block editor provider to ensure 'styles' that are needed\n\t// for the previews are synced between the site editor store and the block editor store.\n\t// Additionally we need to have the `__experimentalBlockPatterns` setting in order to\n\t// render patterns inside the previews.\n\t// TODO: Same approach is used in the patterns list and it becomes obvious that some of\n\t// the block editor settings are needed in context where we don't have the block editor.\n\t// Explore how we can solve this in a better way.\n\treturn (\n\t\t<EditorProvider post={ item } settings={ settings }>\n\t\t\t<div\n\t\t\t\tclassName=\"page-templates-preview-field\"\n\t\t\t\tstyle={ { backgroundColor } }\n\t\t\t>\n\t\t\t\t{ isEmpty && __( 'Empty template' ) }\n\t\t\t\t{ ! isEmpty && (\n\t\t\t\t\t<BlockPreview.Async>\n\t\t\t\t\t\t<BlockPreview blocks={ blocks } />\n\t\t\t\t\t</BlockPreview.Async>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</EditorProvider>\n\t);\n}\n\nexport const previewField = {\n\tlabel: __( 'Preview' ),\n\tid: 'preview',\n\trender: PreviewField,\n\tenableSorting: false,\n};\n\nexport const descriptionField = {\n\tlabel: __( 'Description' ),\n\tid: 'description',\n\trender: function RenderDescription( { item } ) {\n\t\tconst defaultTemplateTypes = useAllDefaultTemplateTypes();\n\t\tconst defaultTemplateType = defaultTemplateTypes.find(\n\t\t\t( type ) => type.slug === item.slug\n\t\t);\n\t\treturn item.description\n\t\t\t? decodeEntities( item.description )\n\t\t\t: defaultTemplateType?.description;\n\t},\n\tenableSorting: false,\n\tenableGlobalSearch: true,\n};\n\nfunction AuthorField( { item } ) {\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\tconst { text, icon, imageUrl } = useAddedBy( item.type, item.id );\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport const authorField = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\tgetValue: ( { item } ) => item.author_text ?? item.author,\n\trender: AuthorField,\n};\n\nexport const activeField = {\n\tlabel: __( 'Status' ),\n\tid: 'active',\n\ttype: 'boolean',\n\tgetValue: ( { item } ) => item._isActive,\n\trender: function Render( { item } ) {\n\t\tconst activeLabel = item._isCustom\n\t\t\t? _x( 'Active when used', 'template' )\n\t\t\t: _x( 'Active', 'template' );\n\t\tconst activeIntent = item._isCustom ? 'info' : 'success';\n\t\tconst isActive = item._isActive;\n\t\treturn (\n\t\t\t<Badge intent={ isActive ? activeIntent : 'default' }>\n\t\t\t\t{ isActive ? activeLabel : _x( 'Inactive', 'template' ) }\n\t\t\t</Badge>\n\t\t);\n\t},\n};\n\nexport const useThemeField = () => {\n\tconst activeTheme = useSelect( ( select ) =>\n\t\tselect( coreStore ).getCurrentTheme()\n\t);\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tlabel: __( 'Compatible Theme' ),\n\t\t\tid: 'theme',\n\t\t\tgetValue: ( { item } ) => item.theme,\n\t\t\trender: function Render( { item } ) {\n\t\t\t\tif ( item.theme === activeTheme.stylesheet ) {\n\t\t\t\t\treturn <Badge intent=\"success\">{ item.theme }</Badge>;\n\t\t\t\t}\n\t\t\t\treturn <Badge intent=\"error\">{ item.theme }</Badge>;\n\t\t\t},\n\t\t} ),\n\t\t[ activeTheme ]\n\t);\n};\n\nexport const slugField = {\n\tlabel: __( 'Template Type' ),\n\tid: 'slug',\n\tgetValue: ( { item } ) => item.slug,\n\trender: function Render( { item } ) {\n\t\tconst defaultTemplateTypes = useAllDefaultTemplateTypes();\n\t\tconst defaultTemplateType = defaultTemplateTypes.find(\n\t\t\t( type ) => type.slug === item.slug\n\t\t);\n\t\treturn defaultTemplateType?.title || _x( 'Custom', 'template type' );\n\t},\n};\n"],
|
|
5
|
+
"mappings": "AA6EG,SAOG,KAPH;AA1EH,OAAO,UAAU;AAKjB;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,eAAe;AAAA,OACT;AACP,SAAS,IAAI,UAAU;AACvB,SAAS,UAAU,eAAe;AAClC,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AACtB;AAAA,EACC;AAAA,EACA,eAAe;AAAA,OACT;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,iBAAiB;AAK1B,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B;AACxC,OAAO,wBAAwB;AAC/B,SAAS,cAAc;AAEvB,MAAM,EAAE,eAAe,IAAI,OAAQ,sBAAuB;AAC1D,MAAM,EAAE,MAAM,IAAI,OAAQ,qB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ACC,oBAAC,SAAM,QAAS,WAAW,eAAe,WACvC,qBAAW,cAAc,GAAI,YAAY,UAAW,GACvD;AAAA,EAEF;AACD;AAEO,MAAM,gBAAgB,MAAM;AAClC,QAAM,cAAc;AAAA,IAAW,CAAE,WAChC,OAAQ,SAAU,EAAE,gBAAgB;AAAA,EACrC;AACA,SAAO;AAAA,IACN,OAAQ;AAAA,MACP,OAAO,GAAI,kBAAmB;AAAA,MAC9B,IAAI;AAAA,MACJ,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK;AAAA,MAC/B,QAAQ,SAASA,QAAQ,EAAE,KAAK,GAAI;AACnC,YAAK,KAAK,UAAU,YAAY,YAAa;AAC5C,iBAAO,oBAAC,SAAM,QAAO,WAAY,eAAK,OAAO;AAAA,QAC9C;AACA,eAAO,oBAAC,SAAM,QAAO,SAAU,eAAK,OAAO;AAAA,MAC5C;AAAA,IACD;AAAA,IACA,CAAE,WAAY;AAAA,EACf;AACD;AAEO,MAAM,YAAY;AAAA,EACxB,OAAO,GAAI,eAAgB;AAAA,EAC3B,IAAI;AAAA,EACJ,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK;AAAA,EAC/B,QAAQ,SAASA,QAAQ,EAAE,KAAK,GAAI;AACnC,UAAM,uBAAuB,2BAA2B;AACxD,UAAM,sBAAsB,qBAAqB;AAAA,MAChD,CAAE,SAAU,KAAK,SAAS,KAAK;AAAA,IAChC;AACA,WAAO,qBAAqB,SAAS,GAAI,UAAU,eAAgB;AAAA,EACpE;AACD;",
|
|
6
6
|
"names": ["Render"]
|
|
7
7
|
}
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
useThemeField
|
|
33
33
|
} from "./fields";
|
|
34
34
|
import { defaultLayouts, getDefaultView } from "./view-utils";
|
|
35
|
-
const { usePostActions, templateTitleField } = unlock(editorPrivateApis);
|
|
35
|
+
const { usePostActions, usePostFields, templateTitleField } = unlock(editorPrivateApis);
|
|
36
36
|
const { useHistory, useLocation } = unlock(routerPrivateApis);
|
|
37
37
|
const { useEntityRecordsWithPermissions } = unlock(corePrivateApis);
|
|
38
38
|
function PageTemplates() {
|
|
@@ -175,6 +175,10 @@ function PageTemplates() {
|
|
|
175
175
|
},
|
|
176
176
|
[history, path, view?.type]
|
|
177
177
|
);
|
|
178
|
+
const postTypeFields = usePostFields({
|
|
179
|
+
postType: TEMPLATE_POST_TYPE
|
|
180
|
+
});
|
|
181
|
+
const dateField = postTypeFields.find((field) => field.id === "date");
|
|
178
182
|
const themeField = useThemeField();
|
|
179
183
|
const fields = useMemo(() => {
|
|
180
184
|
const _fields = [
|
|
@@ -186,6 +190,9 @@ function PageTemplates() {
|
|
|
186
190
|
];
|
|
187
191
|
if (activeView === "user") {
|
|
188
192
|
_fields.push(themeField);
|
|
193
|
+
if (dateField) {
|
|
194
|
+
_fields.push(dateField);
|
|
195
|
+
}
|
|
189
196
|
}
|
|
190
197
|
const elements = [];
|
|
191
198
|
for (const author in users) {
|
|
@@ -199,7 +206,7 @@ function PageTemplates() {
|
|
|
199
206
|
elements
|
|
200
207
|
});
|
|
201
208
|
return _fields;
|
|
202
|
-
}, [users, activeView, themeField]);
|
|
209
|
+
}, [users, activeView, themeField, dateField]);
|
|
203
210
|
const { data, paginationInfo } = useMemo(() => {
|
|
204
211
|
return filterSortAndPaginate(records, view, fields);
|
|
205
212
|
}, [records, view, fields]);
|
|
@@ -211,6 +218,7 @@ function PageTemplates() {
|
|
|
211
218
|
{
|
|
212
219
|
const newItem = items[0];
|
|
213
220
|
const _title = typeof newItem.title === "string" ? newItem.title : newItem.title?.rendered;
|
|
221
|
+
history.navigate(`/template?activeView=user`);
|
|
214
222
|
createSuccessNotice(
|
|
215
223
|
sprintf(
|
|
216
224
|
// translators: %s: Title of the created post or template, e.g: "Hello world".
|
|
@@ -314,12 +322,7 @@ function PageTemplates() {
|
|
|
314
322
|
duplicateAction.RenderModal,
|
|
315
323
|
{
|
|
316
324
|
items: [selectedRegisteredTemplate],
|
|
317
|
-
closeModal: () => setSelectedRegisteredTemplate()
|
|
318
|
-
onActionPerformed: ([item]) => {
|
|
319
|
-
history.navigate(
|
|
320
|
-
`/${item.type}/${item.id}?canvas=edit`
|
|
321
|
-
);
|
|
322
|
-
}
|
|
325
|
+
closeModal: () => setSelectedRegisteredTemplate()
|
|
323
326
|
}
|
|
324
327
|
)
|
|
325
328
|
}
|
|
@@ -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 { __, 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, defaultTemplateTypes } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getEntityRecord, getCurrentTheme } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tactiveTemplatesOption: getEntityRecord( 'root', 'site' )\n\t\t\t\t\t?.active_templates,\n\t\t\t\tactiveTheme: getCurrentTheme(),\n\t\t\t\tdefaultTemplateTypes:\n\t\t\t\t\tselect( coreStore ).getCurrentTheme()\n\t\t\t\t\t\t?.default_template_types,\n\t\t\t};\n\t\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( 'root', 'registeredTemplate', {\n\t\t\t// This should not be needed, the endpoint returns all registered\n\t\t\t// templates, but it's not possible right now to turn off pagination\n\t\t\t// for entity configs.\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ];\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\t// Replace the template in the array.\n\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t);\n\t\t\t\tif ( template ) {\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_active.push( template );\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 isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\tfunction isCustom( record ) {\n\t\t\t// For registered templates, the is_custom field is defined.\n\t\t\treturn (\n\t\t\t\trecord.is_custom ??\n\t\t\t\t// For user templates it's custom if the is_wp_suggestion meta\n\t\t\t\t// field is not set and the slug is not found in the default\n\t\t\t\t// template types.\n\t\t\t\t( ! record.meta?.is_wp_suggestion &&\n\t\t\t\t\t! defaultTemplateTypes.some(\n\t\t\t\t\t\t( type ) => type.slug === record.slug\n\t\t\t\t\t) )\n\t\t\t);\n\t\t}\n\n\t\tlet _records;\n\t\tif ( activeView === 'active' ) {\n\t\t\t// Don't show active custom templates in the active view.\n\t\t\t_records = activeTemplates.filter(\n\t\t\t\t( record ) => ! isCustom( record )\n\t\t\t);\n\t\t} else if ( activeView === 'user' ) {\n\t\t\t_records = userRecords;\n\t\t} else {\n\t\t\t_records = staticRecords;\n\t\t}\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.some(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t\t_isCustom: isCustom( record ),\n\t\t} ) );\n\t}, [\n\t\tactiveTemplates,\n\t\tdefaultTemplateTypes,\n\t\tuserRecords,\n\t\tstaticRecords,\n\t\tactiveView,\n\t] );\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 ( typeof item.id === 'string' ) {\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": "
|
|
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, usePostFields, templateTitleField } =\n\tunlock( 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, defaultTemplateTypes } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getEntityRecord, getCurrentTheme } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tactiveTemplatesOption: getEntityRecord( 'root', 'site' )\n\t\t\t\t\t?.active_templates,\n\t\t\t\tactiveTheme: getCurrentTheme(),\n\t\t\t\tdefaultTemplateTypes:\n\t\t\t\t\tselect( coreStore ).getCurrentTheme()\n\t\t\t\t\t\t?.default_template_types,\n\t\t\t};\n\t\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( 'root', 'registeredTemplate', {\n\t\t\t// This should not be needed, the endpoint returns all registered\n\t\t\t// templates, but it's not possible right now to turn off pagination\n\t\t\t// for entity configs.\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ];\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\t// Replace the template in the array.\n\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t);\n\t\t\t\tif ( template ) {\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_active.push( template );\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 isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\tfunction isCustom( record ) {\n\t\t\t// For registered templates, the is_custom field is defined.\n\t\t\treturn (\n\t\t\t\trecord.is_custom ??\n\t\t\t\t// For user templates it's custom if the is_wp_suggestion meta\n\t\t\t\t// field is not set and the slug is not found in the default\n\t\t\t\t// template types.\n\t\t\t\t( ! record.meta?.is_wp_suggestion &&\n\t\t\t\t\t! defaultTemplateTypes.some(\n\t\t\t\t\t\t( type ) => type.slug === record.slug\n\t\t\t\t\t) )\n\t\t\t);\n\t\t}\n\n\t\tlet _records;\n\t\tif ( activeView === 'active' ) {\n\t\t\t// Don't show active custom templates in the active view.\n\t\t\t_records = activeTemplates.filter(\n\t\t\t\t( record ) => ! isCustom( record )\n\t\t\t);\n\t\t} else if ( activeView === 'user' ) {\n\t\t\t_records = userRecords;\n\t\t} else {\n\t\t\t_records = staticRecords;\n\t\t}\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.some(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t\t_isCustom: isCustom( record ),\n\t\t} ) );\n\t}, [\n\t\tactiveTemplates,\n\t\tdefaultTemplateTypes,\n\t\tuserRecords,\n\t\tstaticRecords,\n\t\tactiveView,\n\t] );\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 postTypeFields = usePostFields( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t} );\n\tconst dateField = postTypeFields.find( ( field ) => field.id === 'date' );\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\tif ( dateField ) {\n\t\t\t\t_fields.push( dateField );\n\t\t\t}\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, dateField ] );\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\thistory.navigate( `/template?activeView=user` );\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 ( typeof item.id === 'string' ) {\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/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAiUI,mBAEE,KAFF;AA9TJ,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,oBAAoB;AAC3B,SAAS,0BAA0B;AACnC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AA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;AAAA,YACA;AAAA,YACA;AAAA,YACA,iBAAkB,MAAM;AAAA,YACxB,aAAc,CAAE,SAAU;AACzB,kBAAK,OAAO,KAAK,OAAO,UAAW;AAClC,8CAA+B,IAAK;AAAA,cACrC,OAAO;AACN,wBAAQ;AAAA,kBACP,IAAK,KAAK,IAAK,IAAK,KAAK,EAAG;AAAA,gBAC7B;AAAA,cACD;AAAA,YACD;AAAA,YACA;AAAA,YACA;AAAA;AAAA,UApBM;AAAA,QAqBP;AAAA,QACE,8BAA8B,mBAC/B;AAAA,UAAC;AAAA;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;AAAA,YAClD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,10 @@ const DEFAULT_VIEW = {
|
|
|
26
26
|
function getDefaultView(activeView) {
|
|
27
27
|
return {
|
|
28
28
|
...DEFAULT_VIEW,
|
|
29
|
+
sort: activeView === "user" ? {
|
|
30
|
+
field: "date",
|
|
31
|
+
direction: "desc"
|
|
32
|
+
} : DEFAULT_VIEW.sort,
|
|
29
33
|
filters: !["active", "user"].includes(activeView) ? [
|
|
30
34
|
{
|
|
31
35
|
field: "author",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/page-templates/view-utils.js"],
|
|
4
|
-
"sourcesContent": ["export const defaultLayouts = {\n\ttable: {\n\t\tshowMedia: false,\n\t},\n\tgrid: {\n\t\tshowMedia: true,\n\t},\n\tlist: {\n\t\tshowMedia: false,\n\t},\n};\n\nconst DEFAULT_VIEW = {\n\ttype: 'grid',\n\tperPage: 20,\n\tsort: {\n\t\tfield: 'title',\n\t\tdirection: 'asc',\n\t},\n\ttitleField: 'title',\n\tdescriptionField: 'description',\n\tmediaField: 'preview',\n\tfields: [ 'author', 'active', 'slug', 'theme' ],\n\tfilters: [],\n\t...defaultLayouts.grid,\n};\n\nexport function getDefaultView( activeView ) {\n\treturn {\n\t\t...DEFAULT_VIEW,\n\t\tfilters: ! [ 'active', 'user' ].includes( activeView )\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\toperator: 'isAny',\n\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t},\n\t\t\t ]\n\t\t\t: [],\n\t};\n}\n"],
|
|
5
|
-
"mappings": "AAAO,MAAM,iBAAiB;AAAA,EAC7B,OAAO;AAAA,IACN,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AACD;AAEA,MAAM,eAAe;AAAA,EACpB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,IACL,OAAO;AAAA,IACP,WAAW;AAAA,EACZ;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,QAAQ,CAAE,UAAU,UAAU,QAAQ,OAAQ;AAAA,EAC9C,SAAS,CAAC;AAAA,EACV,GAAG,eAAe;AACnB;AAEO,SAAS,eAAgB,YAAa;AAC5C,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS,CAAE,CAAE,UAAU,MAAO,EAAE,SAAU,UAAW,IAClD;AAAA,MACA;AAAA,QACC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO,CAAE,UAAW;AAAA,MACrB;AAAA,IACA,IACA,CAAC;AAAA,EACL;AACD;",
|
|
4
|
+
"sourcesContent": ["export const defaultLayouts = {\n\ttable: {\n\t\tshowMedia: false,\n\t},\n\tgrid: {\n\t\tshowMedia: true,\n\t},\n\tlist: {\n\t\tshowMedia: false,\n\t},\n};\n\nconst DEFAULT_VIEW = {\n\ttype: 'grid',\n\tperPage: 20,\n\tsort: {\n\t\tfield: 'title',\n\t\tdirection: 'asc',\n\t},\n\ttitleField: 'title',\n\tdescriptionField: 'description',\n\tmediaField: 'preview',\n\tfields: [ 'author', 'active', 'slug', 'theme' ],\n\tfilters: [],\n\t...defaultLayouts.grid,\n};\n\nexport function getDefaultView( activeView ) {\n\treturn {\n\t\t...DEFAULT_VIEW,\n\t\tsort:\n\t\t\tactiveView === 'user'\n\t\t\t\t? {\n\t\t\t\t\t\tfield: 'date',\n\t\t\t\t\t\tdirection: 'desc',\n\t\t\t\t }\n\t\t\t\t: DEFAULT_VIEW.sort,\n\t\tfilters: ! [ 'active', 'user' ].includes( activeView )\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\toperator: 'isAny',\n\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t},\n\t\t\t ]\n\t\t\t: [],\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,iBAAiB;AAAA,EAC7B,OAAO;AAAA,IACN,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACL,WAAW;AAAA,EACZ;AACD;AAEA,MAAM,eAAe;AAAA,EACpB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,IACL,OAAO;AAAA,IACP,WAAW;AAAA,EACZ;AAAA,EACA,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,QAAQ,CAAE,UAAU,UAAU,QAAQ,OAAQ;AAAA,EAC9C,SAAS,CAAC;AAAA,EACV,GAAG,eAAe;AACnB;AAEO,SAAS,eAAgB,YAAa;AAC5C,SAAO;AAAA,IACN,GAAG;AAAA,IACH,MACC,eAAe,SACZ;AAAA,MACA,OAAO;AAAA,MACP,WAAW;AAAA,IACX,IACA,aAAa;AAAA,IACjB,SAAS,CAAE,CAAE,UAAU,MAAO,EAAE,SAAU,UAAW,IAClD;AAAA,MACA;AAAA,QACC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO,CAAE,UAAW;AAAA,MACrB;AAAA,IACA,IACA,CAAC;AAAA,EACL;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,7 +7,7 @@ import { privateApis as routerPrivateApis } from "@wordpress/router";
|
|
|
7
7
|
import { addQueryArgs } from "@wordpress/url";
|
|
8
8
|
import SidebarNavigationItem from "../sidebar-navigation-item";
|
|
9
9
|
import { useAddedBy } from "../page-templates/hooks";
|
|
10
|
-
import {
|
|
10
|
+
import { commentAuthorAvatar, published } from "@wordpress/icons";
|
|
11
11
|
import { unlock } from "../../lock-unlock";
|
|
12
12
|
const { useLocation } = unlock(routerPrivateApis);
|
|
13
13
|
const EMPTY_ARRAY = [];
|
|
@@ -48,7 +48,7 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
48
48
|
SidebarNavigationItem,
|
|
49
49
|
{
|
|
50
50
|
to: "/template",
|
|
51
|
-
icon:
|
|
51
|
+
icon: published,
|
|
52
52
|
"aria-current": activeView === "active",
|
|
53
53
|
children: __("Active templates")
|
|
54
54
|
}
|
|
@@ -57,7 +57,7 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
57
57
|
SidebarNavigationItem,
|
|
58
58
|
{
|
|
59
59
|
to: addQueryArgs("/template", { activeView: "user" }),
|
|
60
|
-
icon:
|
|
60
|
+
icon: commentAuthorAvatar,
|
|
61
61
|
"aria-current": activeView === "user",
|
|
62
62
|
// Let's avoid calling them "custom templates" to avoid
|
|
63
63
|
// confusion. "Created" is closest to meaning database
|
|
@@ -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 {
|
|
5
|
-
"mappings": "AA0BE,cAmCA,YAnCA;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,
|
|
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 { commentAuthorAvatar, published } 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( 'root', 'registeredTemplate', {\n\t\t// This should not be needed, the endpoint returns all registered\n\t\t// templates, but it's not possible right now to turn off pagination for\n\t\t// entity configs.\n\t\tper_page: -1,\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={ published }\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={ commentAuthorAvatar }\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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AA;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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-site",
|
|
3
|
-
"version": "6.33.
|
|
3
|
+
"version": "6.33.5",
|
|
4
4
|
"description": "Edit Site Page module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -42,22 +42,22 @@
|
|
|
42
42
|
"@wordpress/api-fetch": "^7.33.1",
|
|
43
43
|
"@wordpress/base-styles": "^6.9.1",
|
|
44
44
|
"@wordpress/blob": "^4.33.1",
|
|
45
|
-
"@wordpress/block-editor": "^15.6.
|
|
46
|
-
"@wordpress/block-library": "^9.33.
|
|
45
|
+
"@wordpress/block-editor": "^15.6.3",
|
|
46
|
+
"@wordpress/block-library": "^9.33.4",
|
|
47
47
|
"@wordpress/blocks": "^15.6.1",
|
|
48
48
|
"@wordpress/commands": "^1.33.1",
|
|
49
49
|
"@wordpress/components": "^30.6.1",
|
|
50
50
|
"@wordpress/compose": "^7.33.1",
|
|
51
|
-
"@wordpress/core-data": "^7.33.
|
|
51
|
+
"@wordpress/core-data": "^7.33.3",
|
|
52
52
|
"@wordpress/data": "^10.33.1",
|
|
53
|
-
"@wordpress/dataviews": "^10.1.
|
|
53
|
+
"@wordpress/dataviews": "^10.1.2",
|
|
54
54
|
"@wordpress/date": "^5.33.1",
|
|
55
55
|
"@wordpress/deprecated": "^4.33.1",
|
|
56
56
|
"@wordpress/dom": "^4.33.1",
|
|
57
|
-
"@wordpress/editor": "^14.33.
|
|
57
|
+
"@wordpress/editor": "^14.33.5",
|
|
58
58
|
"@wordpress/element": "^6.33.1",
|
|
59
59
|
"@wordpress/escape-html": "^3.33.1",
|
|
60
|
-
"@wordpress/fields": "^0.25.
|
|
60
|
+
"@wordpress/fields": "^0.25.5",
|
|
61
61
|
"@wordpress/hooks": "^4.33.1",
|
|
62
62
|
"@wordpress/html-entities": "^4.33.1",
|
|
63
63
|
"@wordpress/i18n": "^6.6.1",
|
|
@@ -66,18 +66,18 @@
|
|
|
66
66
|
"@wordpress/keycodes": "^4.33.1",
|
|
67
67
|
"@wordpress/media-utils": "^5.33.1",
|
|
68
68
|
"@wordpress/notices": "^5.33.1",
|
|
69
|
-
"@wordpress/patterns": "^2.33.
|
|
69
|
+
"@wordpress/patterns": "^2.33.3",
|
|
70
70
|
"@wordpress/plugins": "^7.33.1",
|
|
71
71
|
"@wordpress/preferences": "^4.33.1",
|
|
72
72
|
"@wordpress/primitives": "^4.33.1",
|
|
73
73
|
"@wordpress/private-apis": "^1.33.1",
|
|
74
|
-
"@wordpress/reusable-blocks": "^5.33.
|
|
74
|
+
"@wordpress/reusable-blocks": "^5.33.3",
|
|
75
75
|
"@wordpress/router": "^1.33.1",
|
|
76
76
|
"@wordpress/style-engine": "^2.33.1",
|
|
77
77
|
"@wordpress/url": "^4.33.1",
|
|
78
78
|
"@wordpress/viewport": "^6.33.1",
|
|
79
|
-
"@wordpress/views": "^1.0.
|
|
80
|
-
"@wordpress/widgets": "^4.33.
|
|
79
|
+
"@wordpress/views": "^1.0.3",
|
|
80
|
+
"@wordpress/widgets": "^4.33.3",
|
|
81
81
|
"@wordpress/wordcount": "^4.33.1",
|
|
82
82
|
"change-case": "^4.1.2",
|
|
83
83
|
"clsx": "^2.1.1",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"access": "public"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "b54bd3285e50e409580bdfa2c47bc81f0000a0c9"
|
|
97
97
|
}
|
|
@@ -156,13 +156,13 @@ export const activeField = {
|
|
|
156
156
|
getValue: ( { item } ) => item._isActive,
|
|
157
157
|
render: function Render( { item } ) {
|
|
158
158
|
const activeLabel = item._isCustom
|
|
159
|
-
?
|
|
160
|
-
:
|
|
159
|
+
? _x( 'Active when used', 'template' )
|
|
160
|
+
: _x( 'Active', 'template' );
|
|
161
161
|
const activeIntent = item._isCustom ? 'info' : 'success';
|
|
162
162
|
const isActive = item._isActive;
|
|
163
163
|
return (
|
|
164
164
|
<Badge intent={ isActive ? activeIntent : 'default' }>
|
|
165
|
-
{ isActive ? activeLabel :
|
|
165
|
+
{ isActive ? activeLabel : _x( 'Inactive', 'template' ) }
|
|
166
166
|
</Badge>
|
|
167
167
|
);
|
|
168
168
|
},
|
|
@@ -39,7 +39,8 @@ import {
|
|
|
39
39
|
} from './fields';
|
|
40
40
|
import { defaultLayouts, getDefaultView } from './view-utils';
|
|
41
41
|
|
|
42
|
-
const { usePostActions, templateTitleField } =
|
|
42
|
+
const { usePostActions, usePostFields, templateTitleField } =
|
|
43
|
+
unlock( editorPrivateApis );
|
|
43
44
|
const { useHistory, useLocation } = unlock( routerPrivateApis );
|
|
44
45
|
const { useEntityRecordsWithPermissions } = unlock( corePrivateApis );
|
|
45
46
|
|
|
@@ -210,6 +211,10 @@ export default function PageTemplates() {
|
|
|
210
211
|
[ history, path, view?.type ]
|
|
211
212
|
);
|
|
212
213
|
|
|
214
|
+
const postTypeFields = usePostFields( {
|
|
215
|
+
postType: TEMPLATE_POST_TYPE,
|
|
216
|
+
} );
|
|
217
|
+
const dateField = postTypeFields.find( ( field ) => field.id === 'date' );
|
|
213
218
|
const themeField = useThemeField();
|
|
214
219
|
const fields = useMemo( () => {
|
|
215
220
|
const _fields = [
|
|
@@ -221,6 +226,9 @@ export default function PageTemplates() {
|
|
|
221
226
|
];
|
|
222
227
|
if ( activeView === 'user' ) {
|
|
223
228
|
_fields.push( themeField );
|
|
229
|
+
if ( dateField ) {
|
|
230
|
+
_fields.push( dateField );
|
|
231
|
+
}
|
|
224
232
|
}
|
|
225
233
|
const elements = [];
|
|
226
234
|
for ( const author in users ) {
|
|
@@ -234,7 +242,7 @@ export default function PageTemplates() {
|
|
|
234
242
|
elements,
|
|
235
243
|
} );
|
|
236
244
|
return _fields;
|
|
237
|
-
}, [ users, activeView, themeField ] );
|
|
245
|
+
}, [ users, activeView, themeField, dateField ] );
|
|
238
246
|
|
|
239
247
|
const { data, paginationInfo } = useMemo( () => {
|
|
240
248
|
return filterSortAndPaginate( records, view, fields );
|
|
@@ -251,6 +259,7 @@ export default function PageTemplates() {
|
|
|
251
259
|
typeof newItem.title === 'string'
|
|
252
260
|
? newItem.title
|
|
253
261
|
: newItem.title?.rendered;
|
|
262
|
+
history.navigate( `/template?activeView=user` );
|
|
254
263
|
createSuccessNotice(
|
|
255
264
|
sprintf(
|
|
256
265
|
// translators: %s: Title of the created post or template, e.g: "Hello world".
|
|
@@ -358,11 +367,6 @@ export default function PageTemplates() {
|
|
|
358
367
|
<duplicateAction.RenderModal
|
|
359
368
|
items={ [ selectedRegisteredTemplate ] }
|
|
360
369
|
closeModal={ () => setSelectedRegisteredTemplate() }
|
|
361
|
-
onActionPerformed={ ( [ item ] ) => {
|
|
362
|
-
history.navigate(
|
|
363
|
-
`/${ item.type }/${ item.id }?canvas=edit`
|
|
364
|
-
);
|
|
365
|
-
} }
|
|
366
370
|
/>
|
|
367
371
|
</Modal>
|
|
368
372
|
) }
|
|
@@ -28,6 +28,13 @@ const DEFAULT_VIEW = {
|
|
|
28
28
|
export function getDefaultView( activeView ) {
|
|
29
29
|
return {
|
|
30
30
|
...DEFAULT_VIEW,
|
|
31
|
+
sort:
|
|
32
|
+
activeView === 'user'
|
|
33
|
+
? {
|
|
34
|
+
field: 'date',
|
|
35
|
+
direction: 'desc',
|
|
36
|
+
}
|
|
37
|
+
: DEFAULT_VIEW.sort,
|
|
31
38
|
filters: ! [ 'active', 'user' ].includes( activeView )
|
|
32
39
|
? [
|
|
33
40
|
{
|
|
@@ -13,7 +13,7 @@ import { addQueryArgs } from '@wordpress/url';
|
|
|
13
13
|
*/
|
|
14
14
|
import SidebarNavigationItem from '../sidebar-navigation-item';
|
|
15
15
|
import { useAddedBy } from '../page-templates/hooks';
|
|
16
|
-
import {
|
|
16
|
+
import { commentAuthorAvatar, published } from '@wordpress/icons';
|
|
17
17
|
import { unlock } from '../../lock-unlock';
|
|
18
18
|
|
|
19
19
|
const { useLocation } = unlock( routerPrivateApis );
|
|
@@ -62,14 +62,14 @@ export default function DataviewsTemplatesSidebarContent() {
|
|
|
62
62
|
<ItemGroup className="edit-site-sidebar-navigation-screen-templates-browse">
|
|
63
63
|
<SidebarNavigationItem
|
|
64
64
|
to="/template"
|
|
65
|
-
icon={
|
|
65
|
+
icon={ published }
|
|
66
66
|
aria-current={ activeView === 'active' }
|
|
67
67
|
>
|
|
68
68
|
{ __( 'Active templates' ) }
|
|
69
69
|
</SidebarNavigationItem>
|
|
70
70
|
<SidebarNavigationItem
|
|
71
71
|
to={ addQueryArgs( '/template', { activeView: 'user' } ) }
|
|
72
|
-
icon={
|
|
72
|
+
icon={ commentAuthorAvatar }
|
|
73
73
|
aria-current={ activeView === 'user' }
|
|
74
74
|
>
|
|
75
75
|
{
|