@wordpress/edit-site 6.33.3-next.36001005c.0 → 6.33.3
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/dataviews-actions/index.js +8 -6
- package/build/components/dataviews-actions/index.js.map +2 -2
- package/build/components/global-styles-renderer/index.js +4 -2
- package/build/components/global-styles-renderer/index.js.map +3 -3
- package/build/components/page-templates/fields.js +19 -26
- package/build/components/page-templates/fields.js.map +2 -2
- package/build/components/page-templates/index.js +41 -31
- package/build/components/page-templates/index.js.map +2 -2
- package/build/components/revisions/index.js +2 -2
- package/build/components/revisions/index.js.map +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +6 -7
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
- package/build/components/style-book/index.js +8 -4
- package/build/components/style-book/index.js.map +2 -2
- package/build-module/components/dataviews-actions/index.js +8 -6
- package/build-module/components/dataviews-actions/index.js.map +2 -2
- package/build-module/components/global-styles-renderer/index.js +3 -1
- package/build-module/components/global-styles-renderer/index.js.map +2 -2
- package/build-module/components/page-templates/fields.js +19 -26
- package/build-module/components/page-templates/fields.js.map +2 -2
- package/build-module/components/page-templates/index.js +41 -31
- package/build-module/components/page-templates/index.js.map +2 -2
- package/build-module/components/revisions/index.js +1 -1
- package/build-module/components/revisions/index.js.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +6 -7
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
- package/build-module/components/style-book/index.js +6 -2
- package/build-module/components/style-book/index.js.map +2 -2
- package/build-style/posts-rtl.css +13 -13
- package/build-style/posts.css +13 -13
- package/build-style/style-rtl.css +23 -23
- package/build-style/style.css +23 -23
- package/package.json +44 -45
- package/src/components/dataviews-actions/index.js +12 -10
- package/src/components/global-styles/font-library-modal/style.scss +3 -3
- package/src/components/global-styles/style.scss +1 -1
- package/src/components/global-styles-renderer/index.js +4 -1
- package/src/components/global-styles-sidebar/style.scss +2 -2
- package/src/components/page-templates/fields.js +23 -29
- package/src/components/page-templates/index.js +51 -38
- package/src/components/revisions/index.js +1 -1
- package/src/components/sidebar-navigation-screen/style.scss +1 -1
- package/src/components/sidebar-navigation-screen-patterns/style.scss +1 -1
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +6 -7
- package/src/components/site-hub/style.scss +1 -1
- package/src/components/style-book/index.js +6 -3
- package/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/hooks/use-global-styles-output.js +0 -77
- package/build/hooks/use-global-styles-output.js.map +0 -7
- package/build-module/hooks/use-global-styles-output.js +0 -52
- package/build-module/hooks/use-global-styles-output.js.map +0 -7
- package/src/hooks/use-global-styles-output.js +0 -80
|
@@ -46,7 +46,13 @@ const useSetActiveTemplateAction = () => {
|
|
|
46
46
|
isPrimary: true,
|
|
47
47
|
icon: import_icons.pencil,
|
|
48
48
|
isEligible(item) {
|
|
49
|
-
|
|
49
|
+
if (item.theme !== activeTheme.stylesheet) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (typeof item.id !== "number") {
|
|
53
|
+
return item._isActive === false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
50
56
|
},
|
|
51
57
|
async callback(items) {
|
|
52
58
|
const deactivate = items.some((item) => item._isActive);
|
|
@@ -55,11 +61,7 @@ const useSetActiveTemplateAction = () => {
|
|
|
55
61
|
};
|
|
56
62
|
for (const item of items) {
|
|
57
63
|
if (deactivate) {
|
|
58
|
-
|
|
59
|
-
activeTemplates[item.slug] = false;
|
|
60
|
-
} else {
|
|
61
|
-
delete activeTemplates[item.slug];
|
|
62
|
-
}
|
|
64
|
+
delete activeTemplates[item.slug];
|
|
63
65
|
} else {
|
|
64
66
|
activeTemplates[item.slug] = item.id;
|
|
65
67
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-actions/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { pencil } from '@wordpress/icons';\nimport { useMemo } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_TYPES } from '../../utils/constants';\nimport { unlock } from '../../lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport const useSetActiveTemplateAction = () => {\n\tconst activeTheme = useSelect( ( select ) =>\n\t\tselect( coreStore ).getCurrentTheme()\n\t);\n\tconst { getEntityRecord } = useSelect( coreStore );\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tid: 'set-active-template',\n\t\t\tlabel( items ) {\n\t\t\t\treturn items.some( ( item ) => item._isActive )\n\t\t\t\t\t? __( 'Deactivate' )\n\t\t\t\t\t: __( 'Activate' );\n\t\t\t},\n\t\t\tisPrimary: true,\n\t\t\ticon: pencil,\n\t\t\tisEligible( item ) {\n\t\t\t\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,mBAAuB;AACvB,qBAAwB;AACxB,oBAAiD;AACjD,kBAAuC;AACvC,uBAAmC;AAKnC,uBAA8B;AAC9B,yBAAuB;AAEvB,MAAM,EAAE,WAAW,QAAI,2BAAQ,cAAAA,WAAkB;AAE1C,MAAM,6BAA6B,MAAM;AAC/C,QAAM,kBAAc;AAAA,IAAW,CAAE,WAChC,OAAQ,iBAAAC,KAAU,EAAE,gBAAgB;AAAA,EACrC;AACA,QAAM,EAAE,gBAAgB,QAAI,uBAAW,iBAAAA,KAAU;AACjD,QAAM,EAAE,kBAAkB,uBAAuB,QAChD,yBAAa,iBAAAA,KAAU;AACxB,aAAO;AAAA,IACN,OAAQ;AAAA,MACP,IAAI;AAAA,MACJ,MAAO,OAAQ;AACd,eAAO,MAAM,KAAM,CAAE,SAAU,KAAK,SAAU,QAC3C,gBAAI,YAAa,QACjB,gBAAI,UAAW;AAAA,MACnB;AAAA,MACA,WAAW;AAAA,MACX,MAAM;AAAA,MACN,WAAY,MAAO;AAClB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { pencil } from '@wordpress/icons';\nimport { useMemo } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_TYPES } from '../../utils/constants';\nimport { unlock } from '../../lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport const useSetActiveTemplateAction = () => {\n\tconst activeTheme = useSelect( ( select ) =>\n\t\tselect( coreStore ).getCurrentTheme()\n\t);\n\tconst { getEntityRecord } = useSelect( coreStore );\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tid: 'set-active-template',\n\t\t\tlabel( items ) {\n\t\t\t\treturn items.some( ( item ) => item._isActive )\n\t\t\t\t\t? __( 'Deactivate' )\n\t\t\t\t\t: __( 'Activate' );\n\t\t\t},\n\t\t\tisPrimary: true,\n\t\t\ticon: pencil,\n\t\t\tisEligible( item ) {\n\t\t\t\tif ( item.theme !== activeTheme.stylesheet ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t// If it's not a created template but a registered template,\n\t\t\t\t// only allow activating (so when it's inactive).\n\t\t\t\tif ( typeof item.id !== 'number' ) {\n\t\t\t\t\treturn item._isActive === false;\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tasync callback( items ) {\n\t\t\t\tconst deactivate = items.some( ( item ) => item._isActive );\n\t\t\t\t// current active templates\n\t\t\t\tconst activeTemplates = {\n\t\t\t\t\t...( ( await getEntityRecord( 'root', 'site' )\n\t\t\t\t\t\t.active_templates ) ?? {} ),\n\t\t\t\t};\n\t\t\t\tfor ( const item of items ) {\n\t\t\t\t\tif ( deactivate ) {\n\t\t\t\t\t\tdelete activeTemplates[ item.slug ];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tactiveTemplates[ item.slug ] = item.id;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tawait editEntityRecord( 'root', 'site', undefined, {\n\t\t\t\t\tactive_templates: activeTemplates,\n\t\t\t\t} );\n\t\t\t\tawait saveEditedEntityRecord( 'root', 'site' );\n\t\t\t},\n\t\t} ),\n\t\t[\n\t\t\teditEntityRecord,\n\t\t\tsaveEditedEntityRecord,\n\t\t\tgetEntityRecord,\n\t\t\tactiveTheme,\n\t\t]\n\t);\n};\n\nexport const useEditPostAction = () => {\n\tconst history = useHistory();\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tid: 'edit-post',\n\t\t\tlabel: __( 'Edit' ),\n\t\t\tisPrimary: true,\n\t\t\ticon: pencil,\n\t\t\tisEligible( post ) {\n\t\t\t\tif ( post.status === 'trash' ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t// It's eligible for all post types except theme patterns.\n\t\t\t\treturn post.type !== PATTERN_TYPES.theme;\n\t\t\t},\n\t\t\tcallback( items ) {\n\t\t\t\tconst post = items[ 0 ];\n\t\t\t\thistory.navigate( `/${ post.type }/${ post.id }?canvas=edit` );\n\t\t\t},\n\t\t} ),\n\t\t[ history ]\n\t);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,mBAAuB;AACvB,qBAAwB;AACxB,oBAAiD;AACjD,kBAAuC;AACvC,uBAAmC;AAKnC,uBAA8B;AAC9B,yBAAuB;AAE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AAEO,MAAM,oBAAoB,MAAM;AACtC,QAAM,UAAU,WAAW;AAC3B,aAAO;AAAA,IACN,OAAQ;AAAA,MACP,IAAI;AAAA,MACJ,WAAO,gBAAI,MAAO;AAAA,MAClB,WAAW;AAAA,MACX,MAAM;AAAA,MACN,WAAY,MAAO;AAClB,YAAK,KAAK,WAAW,SAAU;AAC9B,iBAAO;AAAA,QACR;AAEA,eAAO,KAAK,SAAS,+BAAc;AAAA,MACpC;AAAA,MACA,SAAU,OAAQ;AACjB,cAAM,OAAO,MAAO,CAAE;AACtB,gBAAQ,SAAU,IAAK,KAAK,IAAK,IAAK,KAAK,EAAG,cAAe;AAAA,MAC9D;AAAA,IACD;AAAA,IACA,CAAE,OAAQ;AAAA,EACX;AACD;",
|
|
6
6
|
"names": ["routerPrivateApis", "coreStore"]
|
|
7
7
|
}
|
|
@@ -23,10 +23,12 @@ __export(global_styles_renderer_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(global_styles_renderer_exports);
|
|
24
24
|
var import_element = require("@wordpress/element");
|
|
25
25
|
var import_data = require("@wordpress/data");
|
|
26
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
26
27
|
var import_store = require("../../store");
|
|
27
|
-
var
|
|
28
|
+
var import_lock_unlock = require("../../lock-unlock");
|
|
29
|
+
const { useGlobalStylesOutput } = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
|
|
28
30
|
function useGlobalStylesRenderer(disableRootPadding) {
|
|
29
|
-
const [styles, settings] =
|
|
31
|
+
const [styles, settings] = useGlobalStylesOutput(disableRootPadding);
|
|
30
32
|
const { getSettings } = (0, import_data.useSelect)(import_store.store);
|
|
31
33
|
const { updateSettings } = (0, import_data.useDispatch)(import_store.store);
|
|
32
34
|
(0, import_element.useEffect)(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/global-styles-renderer/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0B;AAC1B,kBAAuC;
|
|
6
|
-
"names": ["editSiteStore"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalStylesOutput } = unlock( blockEditorPrivateApis );\n\nfunction useGlobalStylesRenderer( disableRootPadding ) {\n\tconst [ styles, settings ] = useGlobalStylesOutput( disableRootPadding );\n\tconst { getSettings } = useSelect( editSiteStore );\n\tconst { updateSettings } = useDispatch( editSiteStore );\n\n\tuseEffect( () => {\n\t\tif ( ! styles || ! settings ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentStoreSettings = getSettings();\n\t\tconst nonGlobalStyles = Object.values(\n\t\t\tcurrentStoreSettings.styles ?? []\n\t\t).filter( ( style ) => ! style.isGlobalStyles );\n\t\tupdateSettings( {\n\t\t\t...currentStoreSettings,\n\t\t\tstyles: [ ...nonGlobalStyles, ...styles ],\n\t\t\t__experimentalFeatures: settings,\n\t\t} );\n\t}, [ styles, settings, updateSettings, getSettings ] );\n}\n\nexport function GlobalStylesRenderer( { disableRootPadding } ) {\n\tuseGlobalStylesRenderer( disableRootPadding );\n\n\treturn null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0B;AAC1B,kBAAuC;AACvC,0BAAsD;AAKtD,mBAAuC;AACvC,yBAAuB;AAEvB,MAAM,EAAE,sBAAsB,QAAI,2BAAQ,oBAAAA,WAAuB;AAEjE,SAAS,wBAAyB,oBAAqB;AACtD,QAAM,CAAE,QAAQ,QAAS,IAAI,sBAAuB,kBAAmB;AACvE,QAAM,EAAE,YAAY,QAAI,uBAAW,aAAAC,KAAc;AACjD,QAAM,EAAE,eAAe,QAAI,yBAAa,aAAAA,KAAc;AAEtD,gCAAW,MAAM;AAChB,QAAK,CAAE,UAAU,CAAE,UAAW;AAC7B;AAAA,IACD;AAEA,UAAM,uBAAuB,YAAY;AACzC,UAAM,kBAAkB,OAAO;AAAA,MAC9B,qBAAqB,UAAU,CAAC;AAAA,IACjC,EAAE,OAAQ,CAAE,UAAW,CAAE,MAAM,cAAe;AAC9C,mBAAgB;AAAA,MACf,GAAG;AAAA,MACH,QAAQ,CAAE,GAAG,iBAAiB,GAAG,MAAO;AAAA,MACxC,wBAAwB;AAAA,IACzB,CAAE;AAAA,EACH,GAAG,CAAE,QAAQ,UAAU,gBAAgB,WAAY,CAAE;AACtD;AAEO,SAAS,qBAAsB,EAAE,mBAAmB,GAAI;AAC9D,0BAAyB,kBAAmB;AAE5C,SAAO;AACR;",
|
|
6
|
+
"names": ["blockEditorPrivateApis", "editSiteStore"]
|
|
7
7
|
}
|
|
@@ -57,9 +57,8 @@ const { useEntityRecordsWithPermissions } = (0, import_lock_unlock.unlock)(impor
|
|
|
57
57
|
function useAllDefaultTemplateTypes() {
|
|
58
58
|
const defaultTemplateTypes = (0, import_utils.useDefaultTemplateTypes)();
|
|
59
59
|
const { records: staticRecords } = useEntityRecordsWithPermissions(
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
{ per_page: -1 }
|
|
60
|
+
"root",
|
|
61
|
+
"registeredTemplate"
|
|
63
62
|
);
|
|
64
63
|
return [
|
|
65
64
|
...defaultTemplateTypes,
|
|
@@ -143,39 +142,33 @@ const authorField = {
|
|
|
143
142
|
const activeField = {
|
|
144
143
|
label: (0, import_i18n.__)("Status"),
|
|
145
144
|
id: "active",
|
|
145
|
+
type: "boolean",
|
|
146
146
|
getValue: ({ item }) => item._isActive,
|
|
147
147
|
render: function Render({ item }) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
Badge,
|
|
151
|
-
{
|
|
152
|
-
intent: "info",
|
|
153
|
-
title: (0, import_i18n.__)(
|
|
154
|
-
"Custom templates cannot be active nor inactive."
|
|
155
|
-
),
|
|
156
|
-
children: (0, import_i18n.__)("N/A")
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
}
|
|
148
|
+
const activeLabel = item._isCustom ? (0, import_i18n.__)("Active when used") : (0, import_i18n.__)("Active");
|
|
149
|
+
const activeIntent = item._isCustom ? "info" : "success";
|
|
160
150
|
const isActive = item._isActive;
|
|
161
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { intent: isActive ?
|
|
151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { intent: isActive ? activeIntent : "default", children: isActive ? activeLabel : (0, import_i18n.__)("Inactive") });
|
|
162
152
|
}
|
|
163
153
|
};
|
|
164
154
|
const useThemeField = () => {
|
|
165
155
|
const activeTheme = (0, import_data.useSelect)(
|
|
166
156
|
(select) => select(import_core_data.store).getCurrentTheme()
|
|
167
157
|
);
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
return (0, import_element.useMemo)(
|
|
159
|
+
() => ({
|
|
160
|
+
label: (0, import_i18n.__)("Compatible Theme"),
|
|
161
|
+
id: "theme",
|
|
162
|
+
getValue: ({ item }) => item.theme,
|
|
163
|
+
render: function Render3({ item }) {
|
|
164
|
+
if (item.theme === activeTheme.stylesheet) {
|
|
165
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { intent: "success", children: item.theme });
|
|
166
|
+
}
|
|
167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, { intent: "error", children: item.theme });
|
|
175
168
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
169
|
+
}),
|
|
170
|
+
[activeTheme]
|
|
171
|
+
);
|
|
179
172
|
};
|
|
180
173
|
const slugField = {
|
|
181
174
|
label: (0, import_i18n.__)("Template Type"),
|
|
@@ -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'
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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? __( 'Active when used' )\n\t\t\t: __( 'Active' );\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 : __( 'Inactive' ) }\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,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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
|
}
|
|
@@ -94,65 +94,75 @@ function PageTemplates() {
|
|
|
94
94
|
per_page: -1,
|
|
95
95
|
combinedTemplates: false
|
|
96
96
|
});
|
|
97
|
-
const { records: staticRecords, isResolving: isLoadingStaticData } = useEntityRecordsWithPermissions("
|
|
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.
|
|
98
101
|
per_page: -1
|
|
99
102
|
});
|
|
100
103
|
const activeTemplates = (0, import_element.useMemo)(() => {
|
|
101
|
-
const _active = [...staticRecords]
|
|
102
|
-
(record) => !record.is_custom
|
|
103
|
-
);
|
|
104
|
+
const _active = [...staticRecords];
|
|
104
105
|
if (activeTemplatesOption) {
|
|
105
106
|
for (const activeSlug in activeTemplatesOption) {
|
|
106
107
|
const activeId = activeTemplatesOption[activeSlug];
|
|
107
|
-
|
|
108
|
+
const template = userRecords.find(
|
|
109
|
+
(userRecord) => userRecord.id === activeId && userRecord.theme === activeTheme.stylesheet
|
|
110
|
+
);
|
|
111
|
+
if (template) {
|
|
108
112
|
const index = _active.findIndex(
|
|
109
|
-
(
|
|
113
|
+
({ slug }) => slug === template.slug
|
|
110
114
|
);
|
|
111
115
|
if (index !== -1) {
|
|
112
|
-
_active
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const template = userRecords.find(
|
|
116
|
-
(userRecord) => userRecord.id === activeId && userRecord.theme === activeTheme.stylesheet
|
|
117
|
-
);
|
|
118
|
-
if (template) {
|
|
119
|
-
const index = _active.findIndex(
|
|
120
|
-
({ slug }) => slug === template.slug
|
|
121
|
-
);
|
|
122
|
-
if (index !== -1) {
|
|
123
|
-
_active[index] = template;
|
|
124
|
-
} else {
|
|
125
|
-
_active.push(template);
|
|
126
|
-
}
|
|
116
|
+
_active[index] = template;
|
|
117
|
+
} else {
|
|
118
|
+
_active.push(template);
|
|
127
119
|
}
|
|
128
120
|
}
|
|
129
121
|
}
|
|
130
122
|
}
|
|
131
123
|
return _active;
|
|
132
124
|
}, [userRecords, staticRecords, activeTemplatesOption, activeTheme]);
|
|
133
|
-
let _records;
|
|
134
125
|
let isLoadingData;
|
|
135
126
|
if (activeView === "active") {
|
|
136
|
-
_records = activeTemplates;
|
|
137
127
|
isLoadingData = isLoadingUserRecords || isLoadingStaticData;
|
|
138
128
|
} else if (activeView === "user") {
|
|
139
|
-
_records = userRecords;
|
|
140
129
|
isLoadingData = isLoadingUserRecords;
|
|
141
130
|
} else {
|
|
142
|
-
_records = staticRecords;
|
|
143
131
|
isLoadingData = isLoadingStaticData;
|
|
144
132
|
}
|
|
145
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
|
+
}
|
|
146
152
|
return _records.map((record) => ({
|
|
147
153
|
...record,
|
|
148
|
-
_isActive: activeTemplates.
|
|
154
|
+
_isActive: activeTemplates.some(
|
|
149
155
|
(template) => template.id === record.id
|
|
150
156
|
),
|
|
151
|
-
_isCustom: record
|
|
152
|
-
(type) => type.slug === record.slug
|
|
153
|
-
)
|
|
157
|
+
_isCustom: isCustom(record)
|
|
154
158
|
}));
|
|
155
|
-
}, [
|
|
159
|
+
}, [
|
|
160
|
+
activeTemplates,
|
|
161
|
+
defaultTemplateTypes,
|
|
162
|
+
userRecords,
|
|
163
|
+
staticRecords,
|
|
164
|
+
activeView
|
|
165
|
+
]);
|
|
156
166
|
const users = (0, import_data.useSelect)(
|
|
157
167
|
(select) => {
|
|
158
168
|
const { getUser } = select(import_core_data.store);
|
|
@@ -301,7 +311,7 @@ function PageTemplates() {
|
|
|
301
311
|
onChangeSelection,
|
|
302
312
|
isItemClickable: () => true,
|
|
303
313
|
onClickItem: (item) => {
|
|
304
|
-
if (item.
|
|
314
|
+
if (typeof item.id === "string") {
|
|
305
315
|
setSelectedRegisteredTemplate(item);
|
|
306
316
|
} else {
|
|
307
317
|
history.navigate(
|
|
@@ -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( 'postType', 'wp_registered_template', {\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst activeTemplates = useMemo( () => {\n\t\tconst _active = [ ...staticRecords ].filter(\n\t\t\t( record ) => ! record.is_custom\n\t\t);\n\t\tif ( activeTemplatesOption ) {\n\t\t\tfor ( const activeSlug in activeTemplatesOption ) {\n\t\t\t\tconst activeId = activeTemplatesOption[ activeSlug ];\n\t\t\t\tif ( activeId === false ) {\n\t\t\t\t\t// Remove the template from the array.\n\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t( template ) => template.slug === activeSlug\n\t\t\t\t\t);\n\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t_active.splice( index, 1 );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Replace the template in the array.\n\t\t\t\t\tconst template = userRecords.find(\n\t\t\t\t\t\t( userRecord ) =>\n\t\t\t\t\t\t\tuserRecord.id === activeId &&\n\t\t\t\t\t\t\tuserRecord.theme === activeTheme.stylesheet\n\t\t\t\t\t);\n\t\t\t\t\tif ( template ) {\n\t\t\t\t\t\tconst index = _active.findIndex(\n\t\t\t\t\t\t\t( { slug } ) => slug === template.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( index !== -1 ) {\n\t\t\t\t\t\t\t_active[ index ] = template;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t_active.push( template );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn _active;\n\t}, [ userRecords, staticRecords, activeTemplatesOption, activeTheme ] );\n\n\tlet _records;\n\tlet isLoadingData;\n\tif ( activeView === 'active' ) {\n\t\t_records = activeTemplates;\n\t\tisLoadingData = isLoadingUserRecords || isLoadingStaticData;\n\t} else if ( activeView === 'user' ) {\n\t\t_records = userRecords;\n\t\tisLoadingData = isLoadingUserRecords;\n\t} else {\n\t\t_records = staticRecords;\n\t\tisLoadingData = isLoadingStaticData;\n\t}\n\n\tconst records = useMemo( () => {\n\t\treturn _records.map( ( record ) => ( {\n\t\t\t...record,\n\t\t\t_isActive: activeTemplates.find(\n\t\t\t\t( template ) => template.id === record.id\n\t\t\t),\n\t\t\t_isCustom:\n\t\t\t\trecord.is_custom ||\n\t\t\t\t( ! record.meta?.is_wp_suggestion &&\n\t\t\t\t\t! defaultTemplateTypes.find(\n\t\t\t\t\t\t( type ) => type.slug === record.slug\n\t\t\t\t\t) ),\n\t\t} ) );\n\t}, [ _records, activeTemplates, defaultTemplateTypes ] );\n\n\tconst users = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUser } = select( coreStore );\n\t\t\treturn records.reduce( ( acc, record ) => {\n\t\t\t\tif ( record.author_text ) {\n\t\t\t\t\tif ( ! acc[ record.author_text ] ) {\n\t\t\t\t\t\tacc[ record.author_text ] = record.author_text;\n\t\t\t\t\t}\n\t\t\t\t} else if ( record.author ) {\n\t\t\t\t\tif ( ! acc[ record.author ] ) {\n\t\t\t\t\t\tacc[ record.author ] = getUser( record.author );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} );\n\t\t},\n\t\t[ records ]\n\t);\n\n\tconst history = useHistory();\n\tconst onChangeSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items );\n\t\t\tif ( view?.type === 'list' ) {\n\t\t\t\thistory.navigate(\n\t\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\t\tpostId: items.length === 1 ? items[ 0 ] : undefined,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ history, path, view?.type ]\n\t);\n\n\tconst themeField = useThemeField();\n\tconst fields = useMemo( () => {\n\t\tconst _fields = [\n\t\t\tpreviewField,\n\t\t\ttemplateTitleField,\n\t\t\tdescriptionField,\n\t\t\tactiveField,\n\t\t\tslugField,\n\t\t];\n\t\tif ( activeView === 'user' ) {\n\t\t\t_fields.push( themeField );\n\t\t}\n\t\tconst elements = [];\n\t\tfor ( const author in users ) {\n\t\t\telements.push( {\n\t\t\t\tvalue: users[ author ]?.id ?? author,\n\t\t\t\tlabel: users[ author ]?.name ?? author,\n\t\t\t} );\n\t\t}\n\t\t_fields.push( {\n\t\t\t...authorField,\n\t\t\telements,\n\t\t} );\n\t\treturn _fields;\n\t}, [ users, activeView, themeField ] );\n\n\tconst { data, paginationInfo } = useMemo( () => {\n\t\treturn filterSortAndPaginate( records, view, fields );\n\t}, [ records, view, fields ] );\n\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst onActionPerformed = useCallback(\n\t\t( actionId, items ) => {\n\t\t\tswitch ( actionId ) {\n\t\t\t\tcase 'duplicate-post':\n\t\t\t\t\t{\n\t\t\t\t\t\tconst newItem = items[ 0 ];\n\t\t\t\t\t\tconst _title =\n\t\t\t\t\t\t\ttypeof newItem.title === 'string'\n\t\t\t\t\t\t\t\t? newItem.title\n\t\t\t\t\t\t\t\t: newItem.title?.rendered;\n\t\t\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Title of the created post or template, e.g: \"Hello world\".\n\t\t\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\t\t\tdecodeEntities( _title ) || __( '(no title)' )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tlabel: __( 'Edit' ),\n\t\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t\t\t\t\t\t`/${ newItem.type }/${ newItem.id }?canvas=edit`\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t},\n\t\t[ history, createSuccessNotice ]\n\t);\n\tconst postTypeActions = usePostActions( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t\tcontext: 'list',\n\t\tonActionPerformed,\n\t} );\n\tconst editAction = useEditPostAction();\n\tconst setActiveTemplateAction = useSetActiveTemplateAction();\n\tconst actions = useMemo(\n\t\t() =>\n\t\t\tactiveView === 'user'\n\t\t\t\t? [ setActiveTemplateAction, editAction, ...postTypeActions ]\n\t\t\t\t: [ setActiveTemplateAction, ...postTypeActions ],\n\t\t[ postTypeActions, setActiveTemplateAction, editAction, activeView ]\n\t);\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tif ( newView.type !== view.type ) {\n\t\t\t// Retrigger the routing areas resolution.\n\t\t\thistory.invalidate();\n\t\t}\n\t\tupdateView( newView );\n\t} );\n\n\tconst duplicateAction = actions.find(\n\t\t( action ) => action.id === 'duplicate-post'\n\t);\n\n\treturn (\n\t\t<Page\n\t\t\tclassName=\"edit-site-page-templates\"\n\t\t\ttitle={ __( 'Templates' ) }\n\t\t\tactions={\n\t\t\t\t<>\n\t\t\t\t\t{ isModified && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tresetToDefault();\n\t\t\t\t\t\t\t\thistory.invalidate();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset view' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t<AddNewTemplate />\n\t\t\t\t</>\n\t\t\t}\n\t\t>\n\t\t\t<DataViews\n\t\t\t\tkey={ activeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tfields={ fields }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tisLoading={ isLoadingData }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tisItemClickable={ () => true }\n\t\t\t\tonClickItem={ ( item ) => {\n\t\t\t\t\tif ( item.type === 'wp_registered_template' ) {\n\t\t\t\t\t\tsetSelectedRegisteredTemplate( item );\n\t\t\t\t\t} else {\n\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t`/${ item.type }/${ item.id }?canvas=edit`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tselection={ selection }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t/>\n\t\t\t{ selectedRegisteredTemplate && duplicateAction && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Duplicate' ) }\n\t\t\t\t\tonRequestClose={ () => setSelectedRegisteredTemplate() }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t>\n\t\t\t\t\t<duplicateAction.RenderModal\n\t\t\t\t\t\titems={ [ selectedRegisteredTemplate ] }\n\t\t\t\t\t\tcloseModal={ () => setSelectedRegisteredTemplate() }\n\t\t\t\t\t\tonActionPerformed={ ( [ item ] ) => {\n\t\t\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t\t\t`/${ item.type }/${ item.id }?canvas=edit`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</Page>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;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, 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) }\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AAA,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,gBACjD,mBAAoB,CAAE,CAAE,IAAK,MAAO;AACnC,0BAAQ;AAAA,oBACP,IAAK,KAAK,IAAK,IAAK,KAAK,EAAG;AAAA,kBAC7B;AAAA,gBACD;AAAA;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF;AAEF;",
|
|
6
6
|
"names": ["editorPrivateApis", "routerPrivateApis", "corePrivateApis", "coreStore", "noticesStore", "AddNewTemplate"]
|
|
7
7
|
}
|
|
@@ -40,10 +40,10 @@ var import_data = require("@wordpress/data");
|
|
|
40
40
|
var import_element = require("@wordpress/element");
|
|
41
41
|
var import_lock_unlock = require("../../lock-unlock");
|
|
42
42
|
var import_editor_canvas_container = __toESM(require("../editor-canvas-container"));
|
|
43
|
-
var import_use_global_styles_output = require("../../hooks/use-global-styles-output");
|
|
44
43
|
const {
|
|
45
44
|
ExperimentalBlockEditorProvider,
|
|
46
45
|
GlobalStylesContext,
|
|
46
|
+
useGlobalStylesOutputWithConfig,
|
|
47
47
|
__unstableBlockStyleVariationOverridesWithConfig
|
|
48
48
|
} = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
|
|
49
49
|
const { mergeBaseAndUserConfigs } = (0, import_lock_unlock.unlock)(import_editor.privateApis);
|
|
@@ -73,7 +73,7 @@ function Revisions({ userConfig, blocks }) {
|
|
|
73
73
|
}),
|
|
74
74
|
[originalSettings]
|
|
75
75
|
);
|
|
76
|
-
const [globalStyles] =
|
|
76
|
+
const [globalStyles] = useGlobalStylesOutputWithConfig(mergedConfig);
|
|
77
77
|
const editorStyles = !isObjectEmpty(globalStyles) && !isObjectEmpty(userConfig) ? globalStyles : settings.styles;
|
|
78
78
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
79
79
|
import_editor_canvas_container.default,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/revisions/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Disabled } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockList,\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n\t__unstableEditorStyles as EditorStyles,\n\t__unstableIframe as Iframe,\n} from '@wordpress/block-editor';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { useSelect } from '@wordpress/data';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../../lock-unlock';\nimport EditorCanvasContainer from '../editor-canvas-container';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgFI;AA7EJ,wBAAyB;AACzB,kBAAmB;AACnB,0BAMO;AACP,oBAAiD;AACjD,kBAA0B;AAC1B,qBAAoC;AAMpC,yBAAuB;AACvB,qCAAkC;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Disabled } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockList,\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n\t__unstableEditorStyles as EditorStyles,\n\t__unstableIframe as Iframe,\n} from '@wordpress/block-editor';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { useSelect } from '@wordpress/data';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../../lock-unlock';\nimport EditorCanvasContainer from '../editor-canvas-container';\n\nconst {\n\tExperimentalBlockEditorProvider,\n\tGlobalStylesContext,\n\tuseGlobalStylesOutputWithConfig,\n\t__unstableBlockStyleVariationOverridesWithConfig,\n} = unlock( blockEditorPrivateApis );\nconst { mergeBaseAndUserConfigs } = unlock( editorPrivateApis );\n\nfunction isObjectEmpty( object ) {\n\treturn ! object || Object.keys( object ).length === 0;\n}\n\nfunction Revisions( { userConfig, blocks } ) {\n\tconst { base: baseConfig } = useContext( GlobalStylesContext );\n\n\tconst mergedConfig = useMemo( () => {\n\t\tif ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) {\n\t\t\treturn mergeBaseAndUserConfigs( baseConfig, userConfig );\n\t\t}\n\t\treturn {};\n\t}, [ baseConfig, userConfig ] );\n\n\tconst renderedBlocksArray = useMemo(\n\t\t() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),\n\t\t[ blocks ]\n\t);\n\n\tconst originalSettings = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings(),\n\t\t[]\n\t);\n\tconst settings = useMemo(\n\t\t() => ( {\n\t\t\t...originalSettings,\n\t\t\tisPreviewMode: true,\n\t\t} ),\n\t\t[ originalSettings ]\n\t);\n\n\tconst [ globalStyles ] = useGlobalStylesOutputWithConfig( mergedConfig );\n\n\tconst editorStyles =\n\t\t! isObjectEmpty( globalStyles ) && ! isObjectEmpty( userConfig )\n\t\t\t? globalStyles\n\t\t\t: settings.styles;\n\n\treturn (\n\t\t<EditorCanvasContainer\n\t\t\ttitle={ __( 'Revisions' ) }\n\t\t\tcloseButtonLabel={ __( 'Close revisions' ) }\n\t\t\tenableResizing\n\t\t>\n\t\t\t<Iframe\n\t\t\t\tclassName=\"edit-site-revisions__iframe\"\n\t\t\t\tname=\"revisions\"\n\t\t\t\ttabIndex={ 0 }\n\t\t\t>\n\t\t\t\t<style>\n\t\t\t\t\t{\n\t\t\t\t\t\t// Forming a \"block formatting context\" to prevent margin collapsing.\n\t\t\t\t\t\t// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context\n\t\t\t\t\t\t`.is-root-container { display: flow-root; }`\n\t\t\t\t\t}\n\t\t\t\t</style>\n\t\t\t\t<Disabled className=\"edit-site-revisions__example-preview__content\">\n\t\t\t\t\t<ExperimentalBlockEditorProvider\n\t\t\t\t\t\tvalue={ renderedBlocksArray }\n\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockList renderAppender={ false } />\n\t\t\t\t\t\t{ /*\n\t\t\t\t\t\t * Styles are printed inside the block editor provider,\n\t\t\t\t\t\t * so they can access any registered style overrides.\n\t\t\t\t\t\t */ }\n\t\t\t\t\t\t<EditorStyles styles={ editorStyles } />\n\t\t\t\t\t\t<__unstableBlockStyleVariationOverridesWithConfig\n\t\t\t\t\t\t\tconfig={ mergedConfig }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ExperimentalBlockEditorProvider>\n\t\t\t\t</Disabled>\n\t\t\t</Iframe>\n\t\t</EditorCanvasContainer>\n\t);\n}\n\nexport default Revisions;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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;AAAA,MACzC,gBAAc;AAAA,MAEd;AAAA,QAAC,oBAAAC;AAAA,QAAA;AAAA,UACA,WAAU;AAAA,UACV,MAAK;AAAA,UACL,UAAW;AAAA,UAEX;AAAA,wDAAC;AAAA;AAAA;AAAA,cAIC;AAAA,aAEF;AAAA,YACA,4CAAC,8BAAS,WAAU,iDACnB;AAAA,cAAC;AAAA;AAAA,gBACA,OAAQ;AAAA,gBACR;AAAA,gBAEA;AAAA,8DAAC,iCAAU,gBAAiB,OAAQ;AAAA,kBAKpC,4CAAC,oBAAAC,wBAAA,EAAa,QAAS,cAAe;AAAA,kBACtC;AAAA,oBAAC;AAAA;AAAA,sBACA,QAAS;AAAA;AAAA,kBACV;AAAA;AAAA;AAAA,YACD,GACD;AAAA;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": ["blockEditorPrivateApis", "editorPrivateApis", "blockEditorStore", "EditorCanvasContainer", "Iframe", "EditorStyles"]
|
|
7
7
|
}
|
|
@@ -60,13 +60,12 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
60
60
|
const {
|
|
61
61
|
query: { activeView = "active" }
|
|
62
62
|
} = useLocation();
|
|
63
|
-
const { records } = (0, import_core_data.useEntityRecords)(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
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.
|
|
67
|
+
per_page: -1
|
|
68
|
+
});
|
|
70
69
|
const firstItemPerAuthorText = (0, import_element.useMemo)(() => {
|
|
71
70
|
const firstItemPerAuthor = records?.reduce((acc, template) => {
|
|
72
71
|
const author = template.author_text;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/sidebar-navigation-screen-templates-browse/content.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { layout } from '@wordpress/icons';\nimport { unlock } from '../../lock-unlock';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nfunction TemplateDataviewItem( { template, isActive } ) {\n\tconst { text, icon } = useAddedBy( template.type, template.id );\n\n\treturn (\n\t\t<SidebarNavigationItem\n\t\t\tto={ addQueryArgs( '/template', { activeView: text } ) }\n\t\t\ticon={ icon }\n\t\t\taria-current={ isActive }\n\t\t>\n\t\t\t{ text }\n\t\t</SidebarNavigationItem>\n\t);\n}\n\nexport default function DataviewsTemplatesSidebarContent() {\n\tconst {\n\t\tquery: { activeView = 'active' },\n\t} = useLocation();\n\tconst { records } = useEntityRecords(\n\t\t
|
|
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,mBAAuB;AACvB,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,SAAS;AAAA,EAChC,IAAI,YAAY;AAChB,QAAM,EAAE,QAAQ,QAAI;AAAA
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { layout } from '@wordpress/icons';\nimport { unlock } from '../../lock-unlock';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nfunction TemplateDataviewItem( { template, isActive } ) {\n\tconst { text, icon } = useAddedBy( template.type, template.id );\n\n\treturn (\n\t\t<SidebarNavigationItem\n\t\t\tto={ addQueryArgs( '/template', { activeView: text } ) }\n\t\t\ticon={ icon }\n\t\t\taria-current={ isActive }\n\t\t>\n\t\t\t{ text }\n\t\t</SidebarNavigationItem>\n\t);\n}\n\nexport default function DataviewsTemplatesSidebarContent() {\n\tconst {\n\t\tquery: { activeView = 'active' },\n\t} = useLocation();\n\tconst { records } = useEntityRecords( '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={ layout }\n\t\t\t\taria-current={ activeView === 'active' }\n\t\t\t>\n\t\t\t\t{ __( 'Active templates' ) }\n\t\t\t</SidebarNavigationItem>\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto={ addQueryArgs( '/template', { activeView: 'user' } ) }\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'user' }\n\t\t\t>\n\t\t\t\t{\n\t\t\t\t\t// Let's avoid calling them \"custom templates\" to avoid\n\t\t\t\t\t// confusion. \"Created\" is closest to meaning database\n\t\t\t\t\t// templates, created by users.\n\t\t\t\t\t// https://developer.wordpress.org/themes/classic-themes/templates/page-template-files/#creating-custom-page-templates-for-global-use\n\t\t\t\t\t__( 'Created templates' )\n\t\t\t\t}\n\t\t\t</SidebarNavigationItem>\n\t\t\t{ firstItemPerAuthorText.map( ( template ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<TemplateDataviewItem\n\t\t\t\t\t\tkey={ template.author_text }\n\t\t\t\t\t\ttemplate={ template }\n\t\t\t\t\t\tisActive={ activeView === template.author_text }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</ItemGroup>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BE;AAvBF,uBAAiC;AACjC,qBAAwB;AACxB,wBAAqD;AACrD,kBAAmB;AACnB,oBAAiD;AACjD,iBAA6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vD,MAAO;AAAA,QACP,gBAAe,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,QAO7B,8BAAI,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": ["routerPrivateApis", "SidebarNavigationItem", "ItemGroup"]
|
|
7
7
|
}
|
|
@@ -55,8 +55,12 @@ var import_sidebar_global_styles_wrapper = require("../sidebar-global-styles-wra
|
|
|
55
55
|
var import_global_styles_renderer = require("../global-styles-renderer");
|
|
56
56
|
var import_utils = require("../global-styles/utils");
|
|
57
57
|
var import_constants2 = require("../style-book/constants");
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const {
|
|
59
|
+
ExperimentalBlockEditorProvider,
|
|
60
|
+
useGlobalStyle,
|
|
61
|
+
GlobalStylesContext,
|
|
62
|
+
useGlobalStylesOutputWithConfig
|
|
63
|
+
} = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
|
|
60
64
|
const { mergeBaseAndUserConfigs } = (0, import_lock_unlock.unlock)(import_editor.privateApis);
|
|
61
65
|
const { Tabs } = (0, import_lock_unlock.unlock)(import_components.privateApis);
|
|
62
66
|
function isObjectEmpty(object) {
|
|
@@ -216,7 +220,7 @@ function StyleBook({
|
|
|
216
220
|
(select) => select(import_block_editor.store).getSettings(),
|
|
217
221
|
[]
|
|
218
222
|
);
|
|
219
|
-
const [globalStyles] =
|
|
223
|
+
const [globalStyles] = useGlobalStylesOutputWithConfig(mergedConfig);
|
|
220
224
|
const settings = (0, import_element.useMemo)(
|
|
221
225
|
() => ({
|
|
222
226
|
...originalSettings,
|
|
@@ -399,7 +403,7 @@ const StyleBookPreview = ({ userConfig = {}, isStatic = false }) => {
|
|
|
399
403
|
}
|
|
400
404
|
return {};
|
|
401
405
|
}, [baseConfig, userConfig]);
|
|
402
|
-
const [globalStyles] =
|
|
406
|
+
const [globalStyles] = useGlobalStylesOutputWithConfig(mergedConfig);
|
|
403
407
|
const settings = (0, import_element.useMemo)(
|
|
404
408
|
() => ({
|
|
405
409
|
...siteEditorSettings,
|