@wordpress/edit-site 6.33.5 → 6.33.6

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.
Files changed (61) hide show
  1. package/build/components/add-new-template/add-custom-template-modal-content.js +3 -1
  2. package/build/components/add-new-template/add-custom-template-modal-content.js.map +2 -2
  3. package/build/components/add-new-template/index.js +6 -4
  4. package/build/components/add-new-template/index.js.map +2 -2
  5. package/build/components/add-new-template/utils.js +84 -9
  6. package/build/components/add-new-template/utils.js.map +2 -2
  7. package/build/components/dataviews-actions/index.js +2 -55
  8. package/build/components/dataviews-actions/index.js.map +3 -3
  9. package/build/components/editor/index.js +0 -1
  10. package/build/components/editor/index.js.map +2 -2
  11. package/build/components/editor/use-resolve-edited-entity.js +5 -11
  12. package/build/components/editor/use-resolve-edited-entity.js.map +2 -2
  13. package/build/components/page-templates/fields.js +5 -80
  14. package/build/components/page-templates/fields.js.map +3 -3
  15. package/build/components/page-templates/hooks.js +1 -1
  16. package/build/components/page-templates/hooks.js.map +2 -2
  17. package/build/components/page-templates/index.js +46 -217
  18. package/build/components/page-templates/index.js.map +3 -3
  19. package/build/components/page-templates/view-utils.js +1 -5
  20. package/build/components/page-templates/view-utils.js.map +2 -2
  21. package/build/components/sidebar-navigation-screen-templates-browse/content.js +6 -21
  22. package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
  23. package/build/components/site-editor-routes/template-item.js +14 -15
  24. package/build/components/site-editor-routes/template-item.js.map +2 -2
  25. package/build-module/components/add-new-template/add-custom-template-modal-content.js +3 -1
  26. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +2 -2
  27. package/build-module/components/add-new-template/index.js +7 -4
  28. package/build-module/components/add-new-template/index.js.map +2 -2
  29. package/build-module/components/add-new-template/utils.js +84 -9
  30. package/build-module/components/add-new-template/utils.js.map +2 -2
  31. package/build-module/components/dataviews-actions/index.js +1 -53
  32. package/build-module/components/dataviews-actions/index.js.map +2 -2
  33. package/build-module/components/editor/index.js +0 -1
  34. package/build-module/components/editor/index.js.map +2 -2
  35. package/build-module/components/editor/use-resolve-edited-entity.js +5 -11
  36. package/build-module/components/editor/use-resolve-edited-entity.js.map +2 -2
  37. package/build-module/components/page-templates/fields.js +6 -85
  38. package/build-module/components/page-templates/fields.js.map +3 -3
  39. package/build-module/components/page-templates/hooks.js +1 -1
  40. package/build-module/components/page-templates/hooks.js.map +2 -2
  41. package/build-module/components/page-templates/index.js +51 -235
  42. package/build-module/components/page-templates/index.js.map +2 -2
  43. package/build-module/components/page-templates/view-utils.js +1 -5
  44. package/build-module/components/page-templates/view-utils.js.map +2 -2
  45. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +7 -22
  46. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
  47. package/build-module/components/site-editor-routes/template-item.js +14 -15
  48. package/build-module/components/site-editor-routes/template-item.js.map +2 -2
  49. package/package.json +17 -17
  50. package/src/components/add-new-template/add-custom-template-modal-content.js +3 -1
  51. package/src/components/add-new-template/index.js +9 -4
  52. package/src/components/add-new-template/utils.js +118 -9
  53. package/src/components/dataviews-actions/index.js +0 -61
  54. package/src/components/editor/index.js +0 -1
  55. package/src/components/editor/use-resolve-edited-entity.js +5 -20
  56. package/src/components/page-templates/fields.js +5 -95
  57. package/src/components/page-templates/hooks.js +1 -1
  58. package/src/components/page-templates/index.js +35 -244
  59. package/src/components/page-templates/view-utils.js +1 -8
  60. package/src/components/sidebar-navigation-screen-templates-browse/content.js +7 -22
  61. package/src/components/site-editor-routes/template-item.js +26 -28
@@ -34,32 +34,28 @@ module.exports = __toCommonJS(page_templates_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_admin_ui = require("@wordpress/admin-ui");
36
36
  var import_i18n = require("@wordpress/i18n");
37
- var import_html_entities = require("@wordpress/html-entities");
38
37
  var import_element = require("@wordpress/element");
39
38
  var import_core_data = require("@wordpress/core-data");
40
39
  var import_dataviews = require("@wordpress/dataviews");
41
40
  var import_router = require("@wordpress/router");
42
41
  var import_editor = require("@wordpress/editor");
43
42
  var import_url = require("@wordpress/url");
44
- var import_data = require("@wordpress/data");
45
43
  var import_compose = require("@wordpress/compose");
46
44
  var import_views = require("@wordpress/views");
47
45
  var import_components = require("@wordpress/components");
48
- var import_notices = require("@wordpress/notices");
49
46
  var import_add_new_template = __toESM(require("../add-new-template"));
50
47
  var import_constants = require("../../utils/constants");
51
48
  var import_lock_unlock = require("../../lock-unlock");
52
49
  var import_dataviews_actions = require("../dataviews-actions");
53
50
  var import_fields = require("./fields");
54
51
  var import_view_utils = require("./view-utils");
55
- const { usePostActions, usePostFields, templateTitleField } = (0, import_lock_unlock.unlock)(import_editor.privateApis);
52
+ const { usePostActions, templateTitleField } = (0, import_lock_unlock.unlock)(import_editor.privateApis);
56
53
  const { useHistory, useLocation } = (0, import_lock_unlock.unlock)(import_router.privateApis);
57
54
  const { useEntityRecordsWithPermissions } = (0, import_lock_unlock.unlock)(import_core_data.privateApis);
58
55
  function PageTemplates() {
59
56
  const { path, query } = useLocation();
60
57
  const { activeView = "active", postId } = query;
61
58
  const [selection, setSelection] = (0, import_element.useState)([postId]);
62
- const [selectedRegisteredTemplate, setSelectedRegisteredTemplate] = (0, import_element.useState)(false);
63
59
  const defaultView = (0, import_element.useMemo)(() => {
64
60
  return (0, import_view_utils.getDefaultView)(activeView);
65
61
  }, [activeView]);
@@ -82,105 +78,9 @@ function PageTemplates() {
82
78
  );
83
79
  }
84
80
  });
85
- const { activeTemplatesOption, activeTheme, defaultTemplateTypes } = (0, import_data.useSelect)((select) => {
86
- const { getEntityRecord, getCurrentTheme } = select(import_core_data.store);
87
- return {
88
- activeTemplatesOption: getEntityRecord("root", "site")?.active_templates,
89
- activeTheme: getCurrentTheme(),
90
- defaultTemplateTypes: select(import_core_data.store).getCurrentTheme()?.default_template_types
91
- };
92
- });
93
- const { records: userRecords, isResolving: isLoadingUserRecords } = useEntityRecordsWithPermissions("postType", import_constants.TEMPLATE_POST_TYPE, {
94
- per_page: -1,
95
- combinedTemplates: false
96
- });
97
- const { records: staticRecords, isResolving: isLoadingStaticData } = useEntityRecordsWithPermissions("root", "registeredTemplate", {
98
- // This should not be needed, the endpoint returns all registered
99
- // templates, but it's not possible right now to turn off pagination
100
- // for entity configs.
81
+ const { records, isResolving: isLoadingData } = useEntityRecordsWithPermissions("postType", import_constants.TEMPLATE_POST_TYPE, {
101
82
  per_page: -1
102
83
  });
103
- const activeTemplates = (0, import_element.useMemo)(() => {
104
- const _active = [...staticRecords];
105
- if (activeTemplatesOption) {
106
- for (const activeSlug in activeTemplatesOption) {
107
- const activeId = activeTemplatesOption[activeSlug];
108
- const template = userRecords.find(
109
- (userRecord) => userRecord.id === activeId && userRecord.theme === activeTheme.stylesheet
110
- );
111
- if (template) {
112
- const index = _active.findIndex(
113
- ({ slug }) => slug === template.slug
114
- );
115
- if (index !== -1) {
116
- _active[index] = template;
117
- } else {
118
- _active.push(template);
119
- }
120
- }
121
- }
122
- }
123
- return _active;
124
- }, [userRecords, staticRecords, activeTemplatesOption, activeTheme]);
125
- let isLoadingData;
126
- if (activeView === "active") {
127
- isLoadingData = isLoadingUserRecords || isLoadingStaticData;
128
- } else if (activeView === "user") {
129
- isLoadingData = isLoadingUserRecords;
130
- } else {
131
- isLoadingData = isLoadingStaticData;
132
- }
133
- const records = (0, import_element.useMemo)(() => {
134
- function isCustom(record) {
135
- return record.is_custom ?? // For user templates it's custom if the is_wp_suggestion meta
136
- // field is not set and the slug is not found in the default
137
- // template types.
138
- (!record.meta?.is_wp_suggestion && !defaultTemplateTypes.some(
139
- (type) => type.slug === record.slug
140
- ));
141
- }
142
- let _records;
143
- if (activeView === "active") {
144
- _records = activeTemplates.filter(
145
- (record) => !isCustom(record)
146
- );
147
- } else if (activeView === "user") {
148
- _records = userRecords;
149
- } else {
150
- _records = staticRecords;
151
- }
152
- return _records.map((record) => ({
153
- ...record,
154
- _isActive: activeTemplates.some(
155
- (template) => template.id === record.id
156
- ),
157
- _isCustom: isCustom(record)
158
- }));
159
- }, [
160
- activeTemplates,
161
- defaultTemplateTypes,
162
- userRecords,
163
- staticRecords,
164
- activeView
165
- ]);
166
- const users = (0, import_data.useSelect)(
167
- (select) => {
168
- const { getUser } = select(import_core_data.store);
169
- return records.reduce((acc, record) => {
170
- if (record.author_text) {
171
- if (!acc[record.author_text]) {
172
- acc[record.author_text] = record.author_text;
173
- }
174
- } else if (record.author) {
175
- if (!acc[record.author]) {
176
- acc[record.author] = getUser(record.author);
177
- }
178
- }
179
- return acc;
180
- }, {});
181
- },
182
- [records]
183
- );
184
84
  const history = useHistory();
185
85
  const onChangeSelection = (0, import_element.useCallback)(
186
86
  (items) => {
@@ -195,87 +95,42 @@ function PageTemplates() {
195
95
  },
196
96
  [history, path, view?.type]
197
97
  );
198
- const postTypeFields = usePostFields({
199
- postType: import_constants.TEMPLATE_POST_TYPE
200
- });
201
- const dateField = postTypeFields.find((field) => field.id === "date");
202
- const themeField = (0, import_fields.useThemeField)();
203
- const fields = (0, import_element.useMemo)(() => {
204
- const _fields = [
98
+ const authors = (0, import_element.useMemo)(() => {
99
+ if (!records) {
100
+ return [];
101
+ }
102
+ const authorsSet = /* @__PURE__ */ new Set();
103
+ records.forEach((template) => {
104
+ authorsSet.add(template.author_text);
105
+ });
106
+ return Array.from(authorsSet).map((author) => ({
107
+ value: author,
108
+ label: author
109
+ }));
110
+ }, [records]);
111
+ const fields = (0, import_element.useMemo)(
112
+ () => [
205
113
  import_fields.previewField,
206
114
  templateTitleField,
207
115
  import_fields.descriptionField,
208
- import_fields.activeField,
209
- import_fields.slugField
210
- ];
211
- if (activeView === "user") {
212
- _fields.push(themeField);
213
- if (dateField) {
214
- _fields.push(dateField);
116
+ {
117
+ ...import_fields.authorField,
118
+ elements: authors
215
119
  }
216
- }
217
- const elements = [];
218
- for (const author in users) {
219
- elements.push({
220
- value: users[author]?.id ?? author,
221
- label: users[author]?.name ?? author
222
- });
223
- }
224
- _fields.push({
225
- ...import_fields.authorField,
226
- elements
227
- });
228
- return _fields;
229
- }, [users, activeView, themeField, dateField]);
120
+ ],
121
+ [authors]
122
+ );
230
123
  const { data, paginationInfo } = (0, import_element.useMemo)(() => {
231
124
  return (0, import_dataviews.filterSortAndPaginate)(records, view, fields);
232
125
  }, [records, view, fields]);
233
- const { createSuccessNotice } = (0, import_data.useDispatch)(import_notices.store);
234
- const onActionPerformed = (0, import_element.useCallback)(
235
- (actionId, items) => {
236
- switch (actionId) {
237
- case "duplicate-post":
238
- {
239
- const newItem = items[0];
240
- const _title = typeof newItem.title === "string" ? newItem.title : newItem.title?.rendered;
241
- history.navigate(`/template?activeView=user`);
242
- createSuccessNotice(
243
- (0, import_i18n.sprintf)(
244
- // translators: %s: Title of the created post or template, e.g: "Hello world".
245
- (0, import_i18n.__)('"%s" successfully created.'),
246
- (0, import_html_entities.decodeEntities)(_title) || (0, import_i18n.__)("(no title)")
247
- ),
248
- {
249
- type: "snackbar",
250
- id: "duplicate-post-action",
251
- actions: [
252
- {
253
- label: (0, import_i18n.__)("Edit"),
254
- onClick: () => {
255
- history.navigate(
256
- `/${newItem.type}/${newItem.id}?canvas=edit`
257
- );
258
- }
259
- }
260
- ]
261
- }
262
- );
263
- }
264
- break;
265
- }
266
- },
267
- [history, createSuccessNotice]
268
- );
269
126
  const postTypeActions = usePostActions({
270
127
  postType: import_constants.TEMPLATE_POST_TYPE,
271
- context: "list",
272
- onActionPerformed
128
+ context: "list"
273
129
  });
274
130
  const editAction = (0, import_dataviews_actions.useEditPostAction)();
275
- const setActiveTemplateAction = (0, import_dataviews_actions.useSetActiveTemplateAction)();
276
131
  const actions = (0, import_element.useMemo)(
277
- () => activeView === "user" ? [setActiveTemplateAction, editAction, ...postTypeActions] : [setActiveTemplateAction, ...postTypeActions],
278
- [postTypeActions, setActiveTemplateAction, editAction, activeView]
132
+ () => [editAction, ...postTypeActions],
133
+ [postTypeActions, editAction]
279
134
  );
280
135
  const onChangeView = (0, import_compose.useEvent)((newView) => {
281
136
  if (newView.type !== view.type) {
@@ -283,10 +138,7 @@ function PageTemplates() {
283
138
  }
284
139
  updateView(newView);
285
140
  });
286
- const duplicateAction = actions.find(
287
- (action) => action.id === "duplicate-post"
288
- );
289
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
141
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
290
142
  import_admin_ui.Page,
291
143
  {
292
144
  className: "edit-site-page-templates",
@@ -305,49 +157,26 @@ function PageTemplates() {
305
157
  ),
306
158
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_add_new_template.default, {})
307
159
  ] }),
308
- children: [
309
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
310
- import_dataviews.DataViews,
311
- {
312
- paginationInfo,
313
- fields,
314
- actions,
315
- data,
316
- isLoading: isLoadingData,
317
- view,
318
- onChangeView,
319
- onChangeSelection,
320
- isItemClickable: () => true,
321
- onClickItem: (item) => {
322
- if (typeof item.id === "string") {
323
- setSelectedRegisteredTemplate(item);
324
- } else {
325
- history.navigate(
326
- `/${item.type}/${item.id}?canvas=edit`
327
- );
328
- }
329
- },
330
- selection,
331
- defaultLayouts: import_view_utils.defaultLayouts
160
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
161
+ import_dataviews.DataViews,
162
+ {
163
+ paginationInfo,
164
+ fields,
165
+ actions,
166
+ data,
167
+ isLoading: isLoadingData,
168
+ view,
169
+ onChangeView,
170
+ onChangeSelection,
171
+ isItemClickable: () => true,
172
+ onClickItem: ({ id }) => {
173
+ history.navigate(`/wp_template/${id}?canvas=edit`);
332
174
  },
333
- activeView
334
- ),
335
- selectedRegisteredTemplate && duplicateAction && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
336
- import_components.Modal,
337
- {
338
- title: (0, import_i18n.__)("Duplicate"),
339
- onRequestClose: () => setSelectedRegisteredTemplate(),
340
- size: "small",
341
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
342
- duplicateAction.RenderModal,
343
- {
344
- items: [selectedRegisteredTemplate],
345
- closeModal: () => setSelectedRegisteredTemplate()
346
- }
347
- )
348
- }
349
- )
350
- ]
175
+ selection,
176
+ defaultLayouts: import_view_utils.defaultLayouts
177
+ },
178
+ activeView
179
+ )
351
180
  }
352
181
  );
353
182
  }
@@ -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, 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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sBAAQ,WAAW;AAAA,YACpB;AAAA,YAEE,8BAAI,YAAa;AAAA;AAAA,QACpB;AAAA,QAED,4CAAC,wBAAAC,SAAA,EAAe;AAAA,SACjB;AAAA,MAGD;AAAA;AAAA,UAAC;AAAA;AAAA,YAEA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,WAAY;AAAA,YACZ;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,gBAAiB;AAAA;AAAA,UApBX;AAAA,QAqBP;AAAA,QACE,8BAA8B,mBAC/B;AAAA,UAAC;AAAA;AAAA,YACA,WAAQ,gBAAI,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
- "names": ["editorPrivateApis", "routerPrivateApis", "corePrivateApis", "coreStore", "noticesStore", "AddNewTemplate"]
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Page } from '@wordpress/admin-ui';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo, useCallback } from '@wordpress/element';\nimport { privateApis as corePrivateApis } 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 { useEvent } from '@wordpress/compose';\nimport { useView } from '@wordpress/views';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport AddNewTemplate from '../add-new-template';\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\nimport { unlock } from '../../lock-unlock';\nimport { useEditPostAction } from '../dataviews-actions';\nimport { authorField, descriptionField, previewField } 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\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 { records, isResolving: isLoadingData } =\n\t\tuseEntityRecordsWithPermissions( 'postType', TEMPLATE_POST_TYPE, {\n\t\t\tper_page: -1,\n\t\t} );\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 authors = useMemo( () => {\n\t\tif ( ! records ) {\n\t\t\treturn [];\n\t\t}\n\t\tconst authorsSet = new Set();\n\t\trecords.forEach( ( template ) => {\n\t\t\tauthorsSet.add( template.author_text );\n\t\t} );\n\t\treturn Array.from( authorsSet ).map( ( author ) => ( {\n\t\t\tvalue: author,\n\t\t\tlabel: author,\n\t\t} ) );\n\t}, [ records ] );\n\n\tconst fields = useMemo(\n\t\t() => [\n\t\t\tpreviewField,\n\t\t\ttemplateTitleField,\n\t\t\tdescriptionField,\n\t\t\t{\n\t\t\t\t...authorField,\n\t\t\t\telements: authors,\n\t\t\t},\n\t\t],\n\t\t[ authors ]\n\t);\n\n\tconst { data, paginationInfo } = useMemo( () => {\n\t\treturn filterSortAndPaginate( records, view, fields );\n\t}, [ records, view, fields ] );\n\n\tconst postTypeActions = usePostActions( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t\tcontext: 'list',\n\t} );\n\tconst editAction = useEditPostAction();\n\tconst actions = useMemo(\n\t\t() => [ editAction, ...postTypeActions ],\n\t\t[ postTypeActions, editAction ]\n\t);\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tif ( newView.type !== view.type ) {\n\t\t\t// Retrigger the routing areas resolution.\n\t\t\thistory.invalidate();\n\t\t}\n\t\tupdateView( newView );\n\t} );\n\n\treturn (\n\t\t<Page\n\t\t\tclassName=\"edit-site-page-templates\"\n\t\t\ttitle={ __( 'Templates' ) }\n\t\t\tactions={\n\t\t\t\t<>\n\t\t\t\t\t{ isModified && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tresetToDefault();\n\t\t\t\t\t\t\t\thistory.invalidate();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset view' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t<AddNewTemplate />\n\t\t\t\t</>\n\t\t\t}\n\t\t>\n\t\t\t<DataViews\n\t\t\t\tkey={ activeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tfields={ fields }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tisLoading={ isLoadingData }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tisItemClickable={ () => true }\n\t\t\t\tonClickItem={ ( { id } ) => {\n\t\t\t\t\thistory.navigate( `/wp_template/${ id }?canvas=edit` );\n\t\t\t\t} }\n\t\t\t\tselection={ selection }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t/>\n\t\t</Page>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkII;AA/HJ,sBAAqB;AACrB,kBAAmB;AACnB,qBAA+C;AAC/C,uBAA+C;AAC/C,uBAAiD;AACjD,oBAAiD;AACjD,oBAAiD;AACjD,iBAA6B;AAC7B,qBAAyB;AACzB,mBAAwB;AACxB,wBAAuB;AAKvB,8BAA2B;AAC3B,uBAAmC;AACnC,yBAAuB;AACvB,+BAAkC;AAClC,oBAA4D;AAC5D,wBAA+C;AAE/C,MAAM,EAAE,gBAAgB,mBAAmB,QAAI,2BAAQ,cAAAA,WAAkB;AACzE,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,CAA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AAA,UACtD;AAAA,UACA;AAAA,UACA,gBAAiB;AAAA;AAAA,QAdX;AAAA,MAeP;AAAA;AAAA,EACD;AAEF;",
6
+ "names": ["editorPrivateApis", "routerPrivateApis", "corePrivateApis", "AddNewTemplate"]
7
7
  }
@@ -43,17 +43,13 @@ const DEFAULT_VIEW = {
43
43
  titleField: "title",
44
44
  descriptionField: "description",
45
45
  mediaField: "preview",
46
- fields: ["author", "active", "slug", "theme"],
46
+ fields: ["author", "active", "slug"],
47
47
  filters: [],
48
48
  ...defaultLayouts.grid
49
49
  };
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,
57
53
  filters: !["active", "user"].includes(activeView) ? [
58
54
  {
59
55
  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\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;",
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' ],\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,MAAO;AAAA,EACrC,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;",
6
6
  "names": []
7
7
  }
@@ -41,6 +41,7 @@ var import_url = require("@wordpress/url");
41
41
  var import_sidebar_navigation_item = __toESM(require("../sidebar-navigation-item"));
42
42
  var import_hooks = require("../page-templates/hooks");
43
43
  var import_icons = require("@wordpress/icons");
44
+ var import_constants = require("../../utils/constants");
44
45
  var import_lock_unlock = require("../../lock-unlock");
45
46
  const { useLocation } = (0, import_lock_unlock.unlock)(import_router.privateApis);
46
47
  const EMPTY_ARRAY = [];
@@ -58,12 +59,9 @@ function TemplateDataviewItem({ template, isActive }) {
58
59
  }
59
60
  function DataviewsTemplatesSidebarContent() {
60
61
  const {
61
- query: { activeView = "active" }
62
+ query: { activeView = "all" }
62
63
  } = useLocation();
63
- const { records } = (0, import_core_data.useEntityRecords)("root", "registeredTemplate", {
64
- // This should not be needed, the endpoint returns all registered
65
- // templates, but it's not possible right now to turn off pagination for
66
- // entity configs.
64
+ const { records } = (0, import_core_data.useEntityRecords)("postType", import_constants.TEMPLATE_POST_TYPE, {
67
65
  per_page: -1
68
66
  });
69
67
  const firstItemPerAuthorText = (0, import_element.useMemo)(() => {
@@ -81,22 +79,9 @@ function DataviewsTemplatesSidebarContent() {
81
79
  import_sidebar_navigation_item.default,
82
80
  {
83
81
  to: "/template",
84
- icon: import_icons.published,
85
- "aria-current": activeView === "active",
86
- children: (0, import_i18n.__)("Active templates")
87
- }
88
- ),
89
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
90
- import_sidebar_navigation_item.default,
91
- {
92
- to: (0, import_url.addQueryArgs)("/template", { activeView: "user" }),
93
- icon: import_icons.commentAuthorAvatar,
94
- "aria-current": activeView === "user",
95
- // Let's avoid calling them "custom templates" to avoid
96
- // confusion. "Created" is closest to meaning database
97
- // templates, created by users.
98
- // https://developer.wordpress.org/themes/classic-themes/templates/page-template-files/#creating-custom-page-templates-for-global-use
99
- children: (0, import_i18n.__)("Created templates")
82
+ icon: import_icons.layout,
83
+ "aria-current": activeView === "all",
84
+ children: (0, import_i18n.__)("All templates")
100
85
  }
101
86
  ),
102
87
  firstItemPerAuthorText.map((template) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/sidebar-navigation-screen-templates-browse/content.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { 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,SAAS,MAAM,SAAS,EAAG;AAE9D,SACC;AAAA,IAAC,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KACH;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { layout } from '@wordpress/icons';\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\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 = 'all' },\n\t} = useLocation();\n\tconst { records } = useEntityRecords( 'postType', TEMPLATE_POST_TYPE, {\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={ layout }\n\t\t\t\taria-current={ activeView === 'all' }\n\t\t\t>\n\t\t\t\t{ __( 'All templates' ) }\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;AA2BE;AAxBF,uBAAiC;AACjC,qBAAwB;AACxB,wBAAqD;AACrD,kBAAmB;AACnB,oBAAiD;AACjD,iBAA6B;AAK7B,qCAAkC;AAClC,mBAA2B;AAC3B,mBAAuB;AACvB,uBAAmC;AACnC,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,SAAS,MAAM,SAAS,EAAG;AAE9D,SACC;AAAA,IAAC,+BAAAC;AAAA,IAAA;AAAA,MACA,QAAK,yBAAc,aAAa,EAAE,YAAY,KAAK,CAAE;AAAA,MACrD;AAAA,MACA,gBAAe;AAAA,MAEb;AAAA;AAAA,EACH;AAEF;AAEe,SAAR,mCAAoD;AAC1D,QAAM;AAAA,IACL,OAAO,EAAE,aAAa,MAAM;AAAA,EAC7B,IAAI,YAAY;AAChB,QAAM,EAAE,QAAQ,QAAI,mCAAkB,YAAY,qCAAoB;AAAA,IACrE,UAAU;AAAA,EACX,CAAE;AACF,QAAM,6BAAyB,wBAAS,MAAM;AAC7C,UAAM,qBAAqB,SAAS,OAAQ,CAAE,KAAK,aAAc;AAChE,YAAM,SAAS,SAAS;AACxB,UAAK,UAAU,CAAE,IAAK,MAAO,GAAI;AAChC,YAAK,MAAO,IAAI;AAAA,MACjB;AACA,aAAO;AAAA,IACR,GAAG,CAAC,CAAE;AACN,YACG,sBAAsB,OAAO,OAAQ,kBAAmB,MAC1D;AAAA,EAEF,GAAG,CAAE,OAAQ,CAAE;AAEf,SACC,6CAAC,kBAAAC,yBAAA,EAAU,WAAU,wDACpB;AAAA;AAAA,MAAC,+BAAAD;AAAA,MAAA;AAAA,QACA,IAAG;AAAA,QACH,MAAO;AAAA,QACP,gBAAe,eAAe;AAAA,QAE5B,8BAAI,eAAgB;AAAA;AAAA,IACvB;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": ["routerPrivateApis", "SidebarNavigationItem", "ItemGroup"]
7
7
  }
@@ -35,24 +35,23 @@ var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_editor = __toESM(require("../editor"));
36
36
  var import_sidebar_navigation_screen_templates_browse = __toESM(require("../sidebar-navigation-screen-templates-browse"));
37
37
  var import_sidebar_navigation_screen_unsupported = __toESM(require("../sidebar-navigation-screen-unsupported"));
38
- const areas = {
39
- sidebar({ siteData }) {
40
- const isBlockTheme = siteData.currentTheme?.is_block_theme;
41
- return isBlockTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_templates_browse.default, { backPath: "/" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_unsupported.default, {});
42
- },
43
- mobile({ siteData }) {
44
- const isBlockTheme = siteData.currentTheme?.is_block_theme;
45
- return isBlockTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.default, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_unsupported.default, {});
46
- },
47
- preview({ siteData }) {
48
- const isBlockTheme = siteData.currentTheme?.is_block_theme;
49
- return isBlockTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.default, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_unsupported.default, {});
50
- }
51
- };
52
38
  const templateItemRoute = {
53
39
  name: "template-item",
54
40
  path: "/wp_template/*postId",
55
- areas
41
+ areas: {
42
+ sidebar({ siteData }) {
43
+ const isBlockTheme = siteData.currentTheme?.is_block_theme;
44
+ return isBlockTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_templates_browse.default, { backPath: "/" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_unsupported.default, {});
45
+ },
46
+ mobile({ siteData }) {
47
+ const isBlockTheme = siteData.currentTheme?.is_block_theme;
48
+ return isBlockTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.default, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_unsupported.default, {});
49
+ },
50
+ preview({ siteData }) {
51
+ const isBlockTheme = siteData.currentTheme?.is_block_theme;
52
+ return isBlockTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.default, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sidebar_navigation_screen_unsupported.default, {});
53
+ }
54
+ }
56
55
  };
57
56
  // Annotate the CommonJS export names for ESM import in node:
58
57
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/site-editor-routes/template-item.js"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport Editor from '../editor';\nimport SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';\nimport SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';\n\nconst areas = {\n\tsidebar( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<SidebarNavigationScreenTemplatesBrowse backPath=\"/\" />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n\tmobile( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<Editor />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n\tpreview( { siteData } ) {\n\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\treturn isBlockTheme ? (\n\t\t\t<Editor />\n\t\t) : (\n\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t);\n\t},\n};\n\nexport const templateItemRoute = {\n\tname: 'template-item',\n\tpath: '/wp_template/*postId',\n\tareas,\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWG;AARH,oBAAmB;AACnB,wDAAmD;AACnD,mDAA+C;AAE/C,MAAM,QAAQ;AAAA,EACb,QAAS,EAAE,SAAS,GAAI;AACvB,UAAM,eAAe,SAAS,cAAc;AAC5C,WAAO,eACN,4CAAC,kDAAAA,SAAA,EAAuC,UAAS,KAAI,IAErD,4CAAC,6CAAAC,SAAA,EAAmC;AAAA,EAEtC;AAAA,EACA,OAAQ,EAAE,SAAS,GAAI;AACtB,UAAM,eAAe,SAAS,cAAc;AAC5C,WAAO,eACN,4CAAC,cAAAC,SAAA,EAAO,IAER,4CAAC,6CAAAD,SAAA,EAAmC;AAAA,EAEtC;AAAA,EACA,QAAS,EAAE,SAAS,GAAI;AACvB,UAAM,eAAe,SAAS,cAAc;AAC5C,WAAO,eACN,4CAAC,cAAAC,SAAA,EAAO,IAER,4CAAC,6CAAAD,SAAA,EAAmC;AAAA,EAEtC;AACD;AAEO,MAAM,oBAAoB;AAAA,EAChC,MAAM;AAAA,EACN,MAAM;AAAA,EACN;AACD;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport Editor from '../editor';\nimport SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';\nimport SidebarNavigationScreenUnsupported from '../sidebar-navigation-screen-unsupported';\n\nexport const templateItemRoute = {\n\tname: 'template-item',\n\tpath: '/wp_template/*postId',\n\tareas: {\n\t\tsidebar( { siteData } ) {\n\t\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\t\treturn isBlockTheme ? (\n\t\t\t\t<SidebarNavigationScreenTemplatesBrowse backPath=\"/\" />\n\t\t\t) : (\n\t\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t\t);\n\t\t},\n\t\tmobile( { siteData } ) {\n\t\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\t\treturn isBlockTheme ? (\n\t\t\t\t<Editor />\n\t\t\t) : (\n\t\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t\t);\n\t\t},\n\t\tpreview( { siteData } ) {\n\t\t\tconst isBlockTheme = siteData.currentTheme?.is_block_theme;\n\t\t\treturn isBlockTheme ? (\n\t\t\t\t<Editor />\n\t\t\t) : (\n\t\t\t\t<SidebarNavigationScreenUnsupported />\n\t\t\t);\n\t\t},\n\t},\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcI;AAXJ,oBAAmB;AACnB,wDAAmD;AACnD,mDAA+C;AAExC,MAAM,oBAAoB;AAAA,EAChC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,IACN,QAAS,EAAE,SAAS,GAAI;AACvB,YAAM,eAAe,SAAS,cAAc;AAC5C,aAAO,eACN,4CAAC,kDAAAA,SAAA,EAAuC,UAAS,KAAI,IAErD,4CAAC,6CAAAC,SAAA,EAAmC;AAAA,IAEtC;AAAA,IACA,OAAQ,EAAE,SAAS,GAAI;AACtB,YAAM,eAAe,SAAS,cAAc;AAC5C,aAAO,eACN,4CAAC,cAAAC,SAAA,EAAO,IAER,4CAAC,6CAAAD,SAAA,EAAmC;AAAA,IAEtC;AAAA,IACA,QAAS,EAAE,SAAS,GAAI;AACvB,YAAM,eAAe,SAAS,cAAc;AAC5C,aAAO,eACN,4CAAC,cAAAC,SAAA,EAAO,IAER,4CAAC,6CAAAD,SAAA,EAAmC;AAAA,IAEtC;AAAA,EACD;AACD;",
6
6
  "names": ["SidebarNavigationScreenTemplatesBrowse", "SidebarNavigationScreenUnsupported", "Editor"]
7
7
  }
@@ -164,7 +164,9 @@ function AddCustomTemplateModalContent({
164
164
  onBack,
165
165
  containerRef
166
166
  }) {
167
- const [showSearchEntities, setShowSearchEntities] = useState();
167
+ const [showSearchEntities, setShowSearchEntities] = useState(
168
+ entityForSuggestions.hasGeneralTemplate
169
+ );
168
170
  useEffect(() => {
169
171
  if (containerRef.current) {
170
172
  const [firstFocusable] = focus.focusable.find(