@wordpress/edit-site 6.30.1-next.a730c9c8c.0 → 6.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build/components/add-new-template/index.js +1 -5
- package/build/components/add-new-template/index.js.map +1 -1
- package/build/components/add-new-template/utils.js +8 -84
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/dataviews-actions/index.js +51 -1
- package/build/components/dataviews-actions/index.js.map +1 -1
- package/build/components/editor/index.js +1 -1
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor/use-resolve-edited-entity.js +42 -14
- package/build/components/editor/use-resolve-edited-entity.js.map +1 -1
- package/build/components/page-templates/fields.js +65 -5
- package/build/components/page-templates/fields.js.map +1 -1
- package/build/components/page-templates/hooks.js +1 -1
- package/build/components/page-templates/hooks.js.map +1 -1
- package/build/components/page-templates/index.js +103 -29
- package/build/components/page-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build/components/site-editor-routes/index.js +1 -1
- package/build/components/site-editor-routes/index.js.map +1 -1
- package/build/components/site-editor-routes/template-item.js +29 -23
- package/build/components/site-editor-routes/template-item.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build-module/components/add-new-template/index.js +2 -6
- package/build-module/components/add-new-template/index.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +8 -84
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/dataviews-actions/index.js +49 -0
- package/build-module/components/dataviews-actions/index.js.map +1 -1
- package/build-module/components/editor/index.js +1 -1
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor/use-resolve-edited-entity.js +42 -14
- package/build-module/components/editor/use-resolve-edited-entity.js.map +1 -1
- package/build-module/components/page-templates/fields.js +65 -5
- package/build-module/components/page-templates/fields.js.map +1 -1
- package/build-module/components/page-templates/hooks.js +1 -1
- package/build-module/components/page-templates/hooks.js.map +1 -1
- package/build-module/components/page-templates/index.js +105 -31
- package/build-module/components/page-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build-module/components/site-editor-routes/index.js +2 -2
- package/build-module/components/site-editor-routes/index.js.map +1 -1
- package/build-module/components/site-editor-routes/template-item.js +28 -22
- package/build-module/components/site-editor-routes/template-item.js.map +1 -1
- package/package.json +41 -41
- package/src/components/add-new-template/add-custom-template-modal-content.js +1 -3
- package/src/components/add-new-template/index.js +1 -8
- package/src/components/add-new-template/utils.js +9 -118
- package/src/components/dataviews-actions/index.js +51 -0
- package/src/components/editor/index.js +1 -0
- package/src/components/editor/use-resolve-edited-entity.js +54 -7
- package/src/components/page-templates/fields.js +70 -4
- package/src/components/page-templates/hooks.js +1 -1
- package/src/components/page-templates/index.js +160 -57
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +17 -7
- package/src/components/site-editor-routes/index.js +2 -1
- package/src/components/site-editor-routes/template-item.js +34 -26
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.previewField = exports.descriptionField = exports.authorField = void 0;
|
|
7
|
+
exports.slugField = exports.previewField = exports.descriptionField = exports.authorField = exports.activeField = void 0;
|
|
8
8
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
9
9
|
var _components = require("@wordpress/components");
|
|
10
10
|
var _i18n = require("@wordpress/i18n");
|
|
@@ -13,7 +13,9 @@ var _htmlEntities = require("@wordpress/html-entities");
|
|
|
13
13
|
var _blocks = require("@wordpress/blocks");
|
|
14
14
|
var _blockEditor = require("@wordpress/block-editor");
|
|
15
15
|
var _editor = require("@wordpress/editor");
|
|
16
|
+
var _coreData = require("@wordpress/core-data");
|
|
16
17
|
var _hooks = require("./hooks");
|
|
18
|
+
var _utils = require("../add-new-template/utils");
|
|
17
19
|
var _usePatternSettings = _interopRequireDefault(require("../page-patterns/use-pattern-settings"));
|
|
18
20
|
var _lockUnlock = require("../../lock-unlock");
|
|
19
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -32,6 +34,27 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
32
34
|
const {
|
|
33
35
|
useGlobalStyle
|
|
34
36
|
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
37
|
+
const {
|
|
38
|
+
Badge
|
|
39
|
+
} = (0, _lockUnlock.unlock)(_components.privateApis);
|
|
40
|
+
const {
|
|
41
|
+
useEntityRecordsWithPermissions
|
|
42
|
+
} = (0, _lockUnlock.unlock)(_coreData.privateApis);
|
|
43
|
+
function useAllDefaultTemplateTypes() {
|
|
44
|
+
const defaultTemplateTypes = (0, _utils.useDefaultTemplateTypes)();
|
|
45
|
+
const {
|
|
46
|
+
records: staticRecords
|
|
47
|
+
} = useEntityRecordsWithPermissions('postType', 'wp_registered_template', {
|
|
48
|
+
per_page: -1
|
|
49
|
+
});
|
|
50
|
+
return [...defaultTemplateTypes, ...staticRecords?.filter(record => !record.is_custom).map(record => {
|
|
51
|
+
return {
|
|
52
|
+
slug: record.slug,
|
|
53
|
+
title: record.title.rendered,
|
|
54
|
+
description: record.description
|
|
55
|
+
};
|
|
56
|
+
})];
|
|
57
|
+
}
|
|
35
58
|
function PreviewField({
|
|
36
59
|
item
|
|
37
60
|
}) {
|
|
@@ -73,10 +96,12 @@ const previewField = exports.previewField = {
|
|
|
73
96
|
const descriptionField = exports.descriptionField = {
|
|
74
97
|
label: (0, _i18n.__)('Description'),
|
|
75
98
|
id: 'description',
|
|
76
|
-
render: ({
|
|
99
|
+
render: function RenderDescription({
|
|
77
100
|
item
|
|
78
|
-
})
|
|
79
|
-
|
|
101
|
+
}) {
|
|
102
|
+
const defaultTemplateTypes = useAllDefaultTemplateTypes();
|
|
103
|
+
const defaultTemplateType = defaultTemplateTypes.find(type => type.slug === item.slug);
|
|
104
|
+
return item.description ? (0, _htmlEntities.decodeEntities)(item.description) : defaultTemplateType?.description;
|
|
80
105
|
},
|
|
81
106
|
enableSorting: false,
|
|
82
107
|
enableGlobalSearch: true
|
|
@@ -118,7 +143,42 @@ const authorField = exports.authorField = {
|
|
|
118
143
|
id: 'author',
|
|
119
144
|
getValue: ({
|
|
120
145
|
item
|
|
121
|
-
}) =>
|
|
146
|
+
}) => {
|
|
147
|
+
var _item$author_text;
|
|
148
|
+
return (_item$author_text = item.author_text) !== null && _item$author_text !== void 0 ? _item$author_text : item.author;
|
|
149
|
+
},
|
|
122
150
|
render: AuthorField
|
|
123
151
|
};
|
|
152
|
+
const activeField = exports.activeField = {
|
|
153
|
+
label: (0, _i18n.__)('Status'),
|
|
154
|
+
id: 'active',
|
|
155
|
+
getValue: ({
|
|
156
|
+
item
|
|
157
|
+
}) => item._isActive,
|
|
158
|
+
render: function Render({
|
|
159
|
+
item
|
|
160
|
+
}) {
|
|
161
|
+
const isActive = item._isActive;
|
|
162
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Badge, {
|
|
163
|
+
intent: isActive ? 'success' : 'default',
|
|
164
|
+
children: isActive ? (0, _i18n.__)('Active') : (0, _i18n.__)('Inactive')
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const slugField = exports.slugField = {
|
|
169
|
+
label: (0, _i18n.__)('Template Type'),
|
|
170
|
+
id: 'slug',
|
|
171
|
+
getValue: ({
|
|
172
|
+
item
|
|
173
|
+
}) => item.slug,
|
|
174
|
+
render: function Render({
|
|
175
|
+
item
|
|
176
|
+
}) {
|
|
177
|
+
const defaultTemplateTypes = useAllDefaultTemplateTypes();
|
|
178
|
+
const defaultTemplateType = defaultTemplateTypes.find(type => type.slug === item.slug);
|
|
179
|
+
return defaultTemplateType?.title ||
|
|
180
|
+
// translators: %s is the slug of a custom template.
|
|
181
|
+
(0, _i18n.__)('Custom');
|
|
182
|
+
}
|
|
183
|
+
};
|
|
124
184
|
//# sourceMappingURL=fields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_components","_i18n","_element","_htmlEntities","_blocks","_blockEditor","_editor","_hooks","_usePatternSettings","_lockUnlock","_jsxRuntime","useGlobalStyle","unlock","blockEditorPrivateApis","PreviewField","item","settings","usePatternSettings","backgroundColor","blocks","useMemo","parse","content","raw","isEmpty","length","jsx","EditorProvider","post","children","jsxs","className","style","__","BlockPreview","Async","previewField","exports","label","id","render","enableSorting","descriptionField","description","decodeEntities","enableGlobalSearch","AuthorField","isImageLoaded","setIsImageLoaded","useState","text","icon","imageUrl","useAddedBy","type","__experimentalHStack","alignment","spacing","clsx","onLoad","alt","src","Icon","authorField","getValue","author_text"],"sources":["@wordpress/edit-site/src/components/page-templates/fields.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Icon, __experimentalHStack as HStack } from '@wordpress/components';\nimport { __ } 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';\n\n/**\n * Internal dependencies\n */\nimport { useAddedBy } from './hooks';\nimport usePatternSettings from '../page-patterns/use-pattern-settings';\nimport { unlock } from '../../lock-unlock';\n\nconst { useGlobalStyle } = unlock( blockEditorPrivateApis );\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: ( { item } ) => {\n\t\treturn item.description && decodeEntities( item.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,\n\trender: AuthorField,\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAIA,IAAAO,OAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,mBAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAA2C,IAAAW,WAAA,GAAAX,OAAA;AAxB3C;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;AAKA,MAAM;EAAEY;AAAe,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAE3D,SAASC,YAAYA,CAAE;EAAEC;AAAK,CAAC,EAAG;EACjC,MAAMC,QAAQ,GAAG,IAAAC,2BAAkB,EAAC,CAAC;EACrC,MAAM,CAAEC,eAAe,GAAG,OAAO,CAAE,GAAGP,cAAc,CAAE,kBAAmB,CAAC;EAC1E,MAAMQ,MAAM,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAC7B,OAAO,IAAAC,aAAK,EAAEN,IAAI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AAE,QAAQ;EACZyB,QAAQ,EAAEA,CAAE;IAAEjD;EAAK,CAAC,KAAMA,IAAI,CAACkD,WAAW;EAC1CzB,MAAM,EAAEM;AACT,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_components","_i18n","_element","_htmlEntities","_blocks","_blockEditor","_editor","_coreData","_hooks","_utils","_usePatternSettings","_lockUnlock","_jsxRuntime","useGlobalStyle","unlock","blockEditorPrivateApis","Badge","componentsPrivateApis","useEntityRecordsWithPermissions","corePrivateApis","useAllDefaultTemplateTypes","defaultTemplateTypes","useDefaultTemplateTypes","records","staticRecords","per_page","filter","record","is_custom","map","slug","title","rendered","description","PreviewField","item","settings","usePatternSettings","backgroundColor","blocks","useMemo","parse","content","raw","isEmpty","length","jsx","EditorProvider","post","children","jsxs","className","style","__","BlockPreview","Async","previewField","exports","label","id","render","enableSorting","descriptionField","RenderDescription","defaultTemplateType","find","type","decodeEntities","enableGlobalSearch","AuthorField","isImageLoaded","setIsImageLoaded","useState","text","icon","imageUrl","useAddedBy","__experimentalHStack","alignment","spacing","clsx","onLoad","alt","src","Icon","authorField","getValue","_item$author_text","author_text","author","activeField","_isActive","Render","isActive","intent","slugField"],"sources":["@wordpress/edit-site/src/components/page-templates/fields.js"],"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 { __ } 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 { privateApis as corePrivateApis } from '@wordpress/core-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'postType',\n\t\t'wp_registered_template',\n\t\t{ per_page: -1 }\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\tgetValue: ( { item } ) => item._isActive,\n\trender: function Render( { item } ) {\n\t\tconst isActive = item._isActive;\n\t\treturn (\n\t\t\t<Badge intent={ isActive ? 'success' : 'default' }>\n\t\t\t\t{ isActive ? __( 'Active' ) : __( 'Inactive' ) }\n\t\t\t</Badge>\n\t\t);\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 (\n\t\t\tdefaultTemplateType?.title ||\n\t\t\t// translators: %s is the slug of a custom template.\n\t\t\t__( 'Custom' )\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAKA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAIA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,MAAA,GAAAV,OAAA;AACA,IAAAW,mBAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AAA2C,IAAAa,WAAA,GAAAb,OAAA;AA9B3C;AACA;AACA;;AAGA;AACA;AACA;;AAiBA;AACA;AACA;;AAMA,MAAM;EAAEc;AAAe,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAC3D,MAAM;EAAEC;AAAM,CAAC,GAAG,IAAAF,kBAAM,EAAEG,uBAAsB,CAAC;AACjD,MAAM;EAAEC;AAAg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 @@ function useAddedBy(postType, postId) {
|
|
|
80
80
|
type: 'user',
|
|
81
81
|
icon: _icons.commentAuthorAvatar,
|
|
82
82
|
imageUrl: user?.avatar_urls?.[48],
|
|
83
|
-
text: authorText,
|
|
83
|
+
text: authorText !== null && authorText !== void 0 ? authorText : user?.name,
|
|
84
84
|
isCustomized: false
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_data","_icons","_constants","useAddedBy","postType","postId","useSelect","select","getEntityRecord","getUser","getEditedEntityRecord","coreStore","template","originalSource","original_source","authorText","author_text","type","icon","themeIcon","text","isCustomized","source","TEMPLATE_ORIGINS","custom","pluginIcon","siteData","globeIcon","imageUrl","site_logo","source_url","undefined","user","author","authorIcon","avatar_urls"],"sources":["@wordpress/edit-site/src/components/page-templates/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tcommentAuthorAvatar as authorIcon,\n\tlayout as themeIcon,\n\tplugins as pluginIcon,\n\tglobe as globeIcon,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_ORIGINS } from '../../utils/constants';\n\n/** @typedef {'wp_template'|'wp_template_part'} TemplateType */\n\n/**\n * @typedef {'theme'|'plugin'|'site'|'user'} AddedByType\n *\n * @typedef AddedByData\n * @type {Object}\n * @property {AddedByType} type The type of the data.\n * @property {JSX.Element} icon The icon to display.\n * @property {string} [imageUrl] The optional image URL to display.\n * @property {string} [text] The text to display.\n * @property {boolean} isCustomized Whether the template has been customized.\n *\n * @param {TemplateType} postType The template post type.\n * @param {number} postId The template post id.\n * @return {AddedByData} The added by object or null.\n */\nexport function useAddedBy( postType, postId ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getUser, getEditedEntityRecord } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst template = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\tconst originalSource = template?.original_source;\n\t\t\tconst authorText = template?.author_text;\n\n\t\t\tswitch ( originalSource ) {\n\t\t\t\tcase 'theme': {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: originalSource,\n\t\t\t\t\t\ticon: themeIcon,\n\t\t\t\t\t\ttext: authorText,\n\t\t\t\t\t\tisCustomized:\n\t\t\t\t\t\t\ttemplate.source === TEMPLATE_ORIGINS.custom,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase 'plugin': {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: originalSource,\n\t\t\t\t\t\ticon: pluginIcon,\n\t\t\t\t\t\ttext: authorText,\n\t\t\t\t\t\tisCustomized:\n\t\t\t\t\t\t\ttemplate.source === TEMPLATE_ORIGINS.custom,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase 'site': {\n\t\t\t\t\tconst siteData = getEntityRecord(\n\t\t\t\t\t\t'root',\n\t\t\t\t\t\t'__unstableBase'\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: originalSource,\n\t\t\t\t\t\ticon: globeIcon,\n\t\t\t\t\t\timageUrl: siteData?.site_logo\n\t\t\t\t\t\t\t? getEntityRecord(\n\t\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\t\t\t\tsiteData.site_logo\n\t\t\t\t\t\t\t )?.source_url\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\ttext: authorText,\n\t\t\t\t\t\tisCustomized: false,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tconst user = getUser( template.author );\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'user',\n\t\t\t\t\t\ticon: authorIcon,\n\t\t\t\t\t\timageUrl: user?.avatar_urls?.[ 48 ],\n\t\t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AO;YACNS,IAAI,EAAEJ,cAAc;YACpBK,IAAI,EAAES,YAAS;YACfC,QAAQ,EAAEF,QAAQ,EAAEG,SAAS,GAC1BrB,eAAe,CACf,UAAU,EACV,YAAY,EACZkB,QAAQ,CAACG,SACT,CAAC,EAAEC,UAAU,GACbC,SAAS;YACZX,IAAI,EAAEL,UAAU;YAChBM,YAAY,EAAE;UACf,CAAC;QACF;MACA;QAAS;UACR,MAAMW,IAAI,GAAGvB,OAAO,CAAEG,QAAQ,CAACqB,MAAO,CAAC;UACvC,OAAO;YACNhB,IAAI,EAAE,MAAM;YACZC,IAAI,EAAEgB,0BAAU;YAChBN,QAAQ,EAAEI,IAAI,EAAEG,WAAW,GAAI,EAAE,CAAE;YACnCf,IAAI,EAAEL,UAAU;
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","_icons","_constants","useAddedBy","postType","postId","useSelect","select","getEntityRecord","getUser","getEditedEntityRecord","coreStore","template","originalSource","original_source","authorText","author_text","type","icon","themeIcon","text","isCustomized","source","TEMPLATE_ORIGINS","custom","pluginIcon","siteData","globeIcon","imageUrl","site_logo","source_url","undefined","user","author","authorIcon","avatar_urls","name"],"sources":["@wordpress/edit-site/src/components/page-templates/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tcommentAuthorAvatar as authorIcon,\n\tlayout as themeIcon,\n\tplugins as pluginIcon,\n\tglobe as globeIcon,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_ORIGINS } from '../../utils/constants';\n\n/** @typedef {'wp_template'|'wp_template_part'} TemplateType */\n\n/**\n * @typedef {'theme'|'plugin'|'site'|'user'} AddedByType\n *\n * @typedef AddedByData\n * @type {Object}\n * @property {AddedByType} type The type of the data.\n * @property {JSX.Element} icon The icon to display.\n * @property {string} [imageUrl] The optional image URL to display.\n * @property {string} [text] The text to display.\n * @property {boolean} isCustomized Whether the template has been customized.\n *\n * @param {TemplateType} postType The template post type.\n * @param {number} postId The template post id.\n * @return {AddedByData} The added by object or null.\n */\nexport function useAddedBy( postType, postId ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getUser, getEditedEntityRecord } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst template = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\tconst originalSource = template?.original_source;\n\t\t\tconst authorText = template?.author_text;\n\n\t\t\tswitch ( originalSource ) {\n\t\t\t\tcase 'theme': {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: originalSource,\n\t\t\t\t\t\ticon: themeIcon,\n\t\t\t\t\t\ttext: authorText,\n\t\t\t\t\t\tisCustomized:\n\t\t\t\t\t\t\ttemplate.source === TEMPLATE_ORIGINS.custom,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase 'plugin': {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: originalSource,\n\t\t\t\t\t\ticon: pluginIcon,\n\t\t\t\t\t\ttext: authorText,\n\t\t\t\t\t\tisCustomized:\n\t\t\t\t\t\t\ttemplate.source === TEMPLATE_ORIGINS.custom,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase 'site': {\n\t\t\t\t\tconst siteData = getEntityRecord(\n\t\t\t\t\t\t'root',\n\t\t\t\t\t\t'__unstableBase'\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: originalSource,\n\t\t\t\t\t\ticon: globeIcon,\n\t\t\t\t\t\timageUrl: siteData?.site_logo\n\t\t\t\t\t\t\t? getEntityRecord(\n\t\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\t\t\t\tsiteData.site_logo\n\t\t\t\t\t\t\t )?.source_url\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\ttext: authorText,\n\t\t\t\t\t\tisCustomized: false,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tconst user = getUser( template.author );\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'user',\n\t\t\t\t\t\ticon: authorIcon,\n\t\t\t\t\t\timageUrl: user?.avatar_urls?.[ 48 ],\n\t\t\t\t\t\ttext: authorText ?? user?.name,\n\t\t\t\t\t\tisCustomized: false,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[ postType, postId ]\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAUA,IAAAG,UAAA,GAAAH,OAAA;AAfA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,UAAUA,CAAEC,QAAQ,EAAEC,MAAM,EAAG;EAC9C,OAAO,IAAAC,eAAS,EACbC,MAAM,IAAM;IACb,MAAM;MAAEC,eAAe;MAAEC,OAAO;MAAEC;IAAsB,CAAC,GACxDH,MAAM,CAAEI,eAAU,CAAC;IACpB,MAAMC,QAAQ,GAAGF,qBAAqB,CACrC,UAAU,EACVN,QAAQ,EACRC,MACD,CAAC;IACD,MAAMQ,cAAc,GAAGD,QAAQ,EAAEE,eAAe;IAChD,MAAMC,UAAU,GAAGH,QAAQ,EAAEI,WAAW;IAExC,QAASH,cAAc;MACtB,KAAK,OAAO;QAAE;UACb,OAAO;YACNI,IAAI,EAAEJ,cAAc;YACpBK,IAAI,EAAEC,aAAS;YACfC,IAAI,EAAEL,UAAU;YAChBM,YAAY,EACXT,QAAQ,CAACU,MAAM,KAAKC,2BAAgB,CAACC;UACvC,CAAC;QACF;MACA,KAAK,QAAQ;QAAE;UACd,OAAO;YACNP,IAAI,EAAEJ,cAAc;YACpBK,IAAI,EAAEO,cAAU;YAChBL,IAAI,EAAEL,UAAU;YAChBM,YAAY,EACXT,QAAQ,CAACU,MAAM,KAAKC,2BAAgB,CAACC;UACvC,CAAC;QACF;MACA,KAAK,MAAM;QAAE;UACZ,MAAME,QAAQ,GAAGlB,eAAe,CAC/B,MAAM,EACN,gBACD,CAAC;UACD,OAAO;YACNS,IAAI,EAAEJ,cAAc;YACpBK,IAAI,EAAES,YAAS;YACfC,QAAQ,EAAEF,QAAQ,EAAEG,SAAS,GAC1BrB,eAAe,CACf,UAAU,EACV,YAAY,EACZkB,QAAQ,CAACG,SACT,CAAC,EAAEC,UAAU,GACbC,SAAS;YACZX,IAAI,EAAEL,UAAU;YAChBM,YAAY,EAAE;UACf,CAAC;QACF;MACA;QAAS;UACR,MAAMW,IAAI,GAAGvB,OAAO,CAAEG,QAAQ,CAACqB,MAAO,CAAC;UACvC,OAAO;YACNhB,IAAI,EAAE,MAAM;YACZC,IAAI,EAAEgB,0BAAU;YAChBN,QAAQ,EAAEI,IAAI,EAAEG,WAAW,GAAI,EAAE,CAAE;YACnCf,IAAI,EAAEL,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIiB,IAAI,EAAEI,IAAI;YAC9Bf,YAAY,EAAE;UACf,CAAC;QACF;IACD;EACD,CAAC,EACD,CAAEjB,QAAQ,EAAEC,MAAM,CACnB,CAAC;AACF","ignoreList":[]}
|
|
@@ -12,13 +12,14 @@ var _dataviews = require("@wordpress/dataviews");
|
|
|
12
12
|
var _router = require("@wordpress/router");
|
|
13
13
|
var _editor = require("@wordpress/editor");
|
|
14
14
|
var _url = require("@wordpress/url");
|
|
15
|
+
var _data = require("@wordpress/data");
|
|
16
|
+
var _compose = require("@wordpress/compose");
|
|
15
17
|
var _page = _interopRequireDefault(require("../page"));
|
|
16
18
|
var _addNewTemplate = _interopRequireDefault(require("../add-new-template"));
|
|
17
19
|
var _constants = require("../../utils/constants");
|
|
18
20
|
var _lockUnlock = require("../../lock-unlock");
|
|
19
21
|
var _dataviewsActions = require("../dataviews-actions");
|
|
20
|
-
var
|
|
21
|
-
var _compose = require("@wordpress/compose");
|
|
22
|
+
var _fields2 = require("./fields");
|
|
22
23
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
24
|
/**
|
|
24
25
|
* WordPress dependencies
|
|
@@ -39,7 +40,6 @@ const {
|
|
|
39
40
|
const {
|
|
40
41
|
useEntityRecordsWithPermissions
|
|
41
42
|
} = (0, _lockUnlock.unlock)(_coreData.privateApis);
|
|
42
|
-
const EMPTY_ARRAY = [];
|
|
43
43
|
const defaultLayouts = {
|
|
44
44
|
[_constants.LAYOUT_TABLE]: {
|
|
45
45
|
showMedia: false
|
|
@@ -63,7 +63,7 @@ const DEFAULT_VIEW = {
|
|
|
63
63
|
titleField: 'title',
|
|
64
64
|
descriptionField: 'description',
|
|
65
65
|
mediaField: 'preview',
|
|
66
|
-
fields: ['author'],
|
|
66
|
+
fields: ['author', 'active', 'slug'],
|
|
67
67
|
filters: [],
|
|
68
68
|
...defaultLayouts[_constants.LAYOUT_GRID]
|
|
69
69
|
};
|
|
@@ -73,7 +73,7 @@ function PageTemplates() {
|
|
|
73
73
|
query
|
|
74
74
|
} = useLocation();
|
|
75
75
|
const {
|
|
76
|
-
activeView = '
|
|
76
|
+
activeView = 'active',
|
|
77
77
|
layout,
|
|
78
78
|
postId
|
|
79
79
|
} = query;
|
|
@@ -83,7 +83,7 @@ function PageTemplates() {
|
|
|
83
83
|
return {
|
|
84
84
|
...DEFAULT_VIEW,
|
|
85
85
|
type: usedType,
|
|
86
|
-
filters:
|
|
86
|
+
filters: !['active', 'user'].includes(activeView) ? [{
|
|
87
87
|
field: 'author',
|
|
88
88
|
operator: 'isAny',
|
|
89
89
|
value: [activeView]
|
|
@@ -105,19 +105,95 @@ function PageTemplates() {
|
|
|
105
105
|
(0, _element.useEffect)(() => {
|
|
106
106
|
setView(currentView => ({
|
|
107
107
|
...currentView,
|
|
108
|
-
filters:
|
|
108
|
+
filters: !['active', 'user'].includes(activeView) ? [{
|
|
109
109
|
field: 'author',
|
|
110
110
|
operator: _constants.OPERATOR_IS_ANY,
|
|
111
111
|
value: [activeView]
|
|
112
112
|
}] : []
|
|
113
113
|
}));
|
|
114
114
|
}, [setView, activeView]);
|
|
115
|
+
const activeTemplatesOption = (0, _data.useSelect)(select => select(_coreData.store).getEntityRecord('root', 'site')?.active_templates);
|
|
116
|
+
// Todo: this will have to be better so that we're not fetching all the
|
|
117
|
+
// records all the time. Active templates query will need to move server
|
|
118
|
+
// side.
|
|
115
119
|
const {
|
|
116
|
-
records,
|
|
117
|
-
isResolving:
|
|
120
|
+
records: userRecords,
|
|
121
|
+
isResolving: isLoadingUserRecords
|
|
118
122
|
} = useEntityRecordsWithPermissions('postType', _constants.TEMPLATE_POST_TYPE, {
|
|
119
123
|
per_page: -1
|
|
120
124
|
});
|
|
125
|
+
const {
|
|
126
|
+
records: staticRecords,
|
|
127
|
+
isResolving: isLoadingStaticData
|
|
128
|
+
} = useEntityRecordsWithPermissions('postType', 'wp_registered_template', {
|
|
129
|
+
per_page: -1
|
|
130
|
+
});
|
|
131
|
+
const activeTemplates = (0, _element.useMemo)(() => {
|
|
132
|
+
const _active = [...staticRecords].filter(record => !record.is_custom);
|
|
133
|
+
if (activeTemplatesOption) {
|
|
134
|
+
for (const activeSlug in activeTemplatesOption) {
|
|
135
|
+
const activeId = activeTemplatesOption[activeSlug];
|
|
136
|
+
if (activeId === false) {
|
|
137
|
+
// Remove the template from the array.
|
|
138
|
+
const index = _active.findIndex(template => template.slug === activeSlug);
|
|
139
|
+
if (index !== -1) {
|
|
140
|
+
_active.splice(index, 1);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
// Replace the template in the array.
|
|
144
|
+
const template = userRecords.find(({
|
|
145
|
+
id
|
|
146
|
+
}) => id === activeId);
|
|
147
|
+
if (template) {
|
|
148
|
+
const index = _active.findIndex(({
|
|
149
|
+
slug
|
|
150
|
+
}) => slug === template.slug);
|
|
151
|
+
if (index !== -1) {
|
|
152
|
+
_active[index] = template;
|
|
153
|
+
} else {
|
|
154
|
+
_active.push(template);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return _active;
|
|
161
|
+
}, [userRecords, staticRecords, activeTemplatesOption]);
|
|
162
|
+
let _records;
|
|
163
|
+
let isLoadingData;
|
|
164
|
+
if (activeView === 'active') {
|
|
165
|
+
_records = activeTemplates;
|
|
166
|
+
isLoadingData = isLoadingUserRecords || isLoadingStaticData;
|
|
167
|
+
} else if (activeView === 'user') {
|
|
168
|
+
_records = userRecords;
|
|
169
|
+
isLoadingData = isLoadingUserRecords;
|
|
170
|
+
} else {
|
|
171
|
+
_records = staticRecords;
|
|
172
|
+
isLoadingData = isLoadingStaticData;
|
|
173
|
+
}
|
|
174
|
+
const records = (0, _element.useMemo)(() => {
|
|
175
|
+
return _records.map(record => ({
|
|
176
|
+
...record,
|
|
177
|
+
_isActive: typeof record.id === 'string' ? activeTemplatesOption[record.slug] === record.id || activeTemplatesOption[record.slug] === undefined : Object.values(activeTemplatesOption).includes(record.id)
|
|
178
|
+
}));
|
|
179
|
+
}, [_records, activeTemplatesOption]);
|
|
180
|
+
const users = (0, _data.useSelect)(select => {
|
|
181
|
+
const {
|
|
182
|
+
getUser
|
|
183
|
+
} = select(_coreData.store);
|
|
184
|
+
return records.reduce((acc, record) => {
|
|
185
|
+
if (record.author_text) {
|
|
186
|
+
if (!acc[record.author_text]) {
|
|
187
|
+
acc[record.author_text] = record.author_text;
|
|
188
|
+
}
|
|
189
|
+
} else if (record.author) {
|
|
190
|
+
if (!acc[record.author]) {
|
|
191
|
+
acc[record.author] = getUser(record.author);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return acc;
|
|
195
|
+
}, {});
|
|
196
|
+
}, [records]);
|
|
121
197
|
const history = useHistory();
|
|
122
198
|
const onChangeSelection = (0, _element.useCallback)(items => {
|
|
123
199
|
setSelection(items);
|
|
@@ -127,23 +203,22 @@ function PageTemplates() {
|
|
|
127
203
|
}));
|
|
128
204
|
}
|
|
129
205
|
}, [history, path, view?.type]);
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
206
|
+
const fields = (0, _element.useMemo)(() => {
|
|
207
|
+
const _fields = [_fields2.previewField, templateTitleField, _fields2.descriptionField, _fields2.activeField, _fields2.slugField];
|
|
208
|
+
const elements = [];
|
|
209
|
+
for (const author in users) {
|
|
210
|
+
var _users$author$id, _users$author$name;
|
|
211
|
+
elements.push({
|
|
212
|
+
value: (_users$author$id = users[author]?.id) !== null && _users$author$id !== void 0 ? _users$author$id : author,
|
|
213
|
+
label: (_users$author$name = users[author]?.name) !== null && _users$author$name !== void 0 ? _users$author$name : author
|
|
214
|
+
});
|
|
133
215
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
216
|
+
_fields.push({
|
|
217
|
+
..._fields2.authorField,
|
|
218
|
+
elements
|
|
137
219
|
});
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
label: author
|
|
141
|
-
}));
|
|
142
|
-
}, [records]);
|
|
143
|
-
const fields = (0, _element.useMemo)(() => [_fields.previewField, templateTitleField, _fields.descriptionField, {
|
|
144
|
-
..._fields.authorField,
|
|
145
|
-
elements: authors
|
|
146
|
-
}], [authors]);
|
|
220
|
+
return _fields;
|
|
221
|
+
}, [users]);
|
|
147
222
|
const {
|
|
148
223
|
data,
|
|
149
224
|
paginationInfo
|
|
@@ -155,7 +230,8 @@ function PageTemplates() {
|
|
|
155
230
|
context: 'list'
|
|
156
231
|
});
|
|
157
232
|
const editAction = (0, _dataviewsActions.useEditPostAction)();
|
|
158
|
-
const
|
|
233
|
+
const setActiveTemplateAction = (0, _dataviewsActions.useSetActiveTemplateAction)();
|
|
234
|
+
const actions = (0, _element.useMemo)(() => activeView === 'user' ? [setActiveTemplateAction, editAction, ...postTypeActions] : [setActiveTemplateAction, ...postTypeActions], [postTypeActions, setActiveTemplateAction, editAction, activeView]);
|
|
159
235
|
const onChangeView = (0, _compose.useEvent)(newView => {
|
|
160
236
|
setView(newView);
|
|
161
237
|
if (newView.type !== layout) {
|
|
@@ -178,10 +254,8 @@ function PageTemplates() {
|
|
|
178
254
|
onChangeView: onChangeView,
|
|
179
255
|
onChangeSelection: onChangeSelection,
|
|
180
256
|
isItemClickable: () => true,
|
|
181
|
-
onClickItem:
|
|
182
|
-
id
|
|
183
|
-
}) => {
|
|
184
|
-
history.navigate(`/wp_template/${id}?canvas=edit`);
|
|
257
|
+
onClickItem: item => {
|
|
258
|
+
history.navigate(`/${item.type}/${item.id}?canvas=edit`);
|
|
185
259
|
},
|
|
186
260
|
selection: selection,
|
|
187
261
|
defaultLayouts: defaultLayouts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_coreData","_dataviews","_router","_editor","_url","_page","_interopRequireDefault","_addNewTemplate","_constants","_lockUnlock","_dataviewsActions","_fields","_compose","_jsxRuntime","usePostActions","templateTitleField","unlock","editorPrivateApis","useHistory","useLocation","routerPrivateApis","useEntityRecordsWithPermissions","corePrivateApis","EMPTY_ARRAY","defaultLayouts","LAYOUT_TABLE","showMedia","LAYOUT_GRID","LAYOUT_LIST","DEFAULT_VIEW","type","search","page","perPage","sort","field","direction","titleField","descriptionField","mediaField","fields","filters","PageTemplates","path","query","activeView","layout","postId","selection","setSelection","useState","defaultView","useMemo","usedType","operator","value","view","setView","useEffect","currentView","OPERATOR_IS_ANY","records","isResolving","isLoadingData","TEMPLATE_POST_TYPE","per_page","history","onChangeSelection","useCallback","items","navigate","addQueryArgs","length","undefined","authors","authorsSet","Set","forEach","template","add","author_text","Array","from","map","author","label","previewField","authorField","elements","data","paginationInfo","filterSortAndPaginate","postTypeActions","postType","context","editAction","useEditPostAction","actions","onChangeView","useEvent","newView","jsx","default","className","title","__","children","DataViews","isLoading","isItemClickable","onClickItem","id"],"sources":["@wordpress/edit-site/src/components/page-templates/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo, useCallback, useEffect } 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';\n\n/**\n * Internal dependencies\n */\nimport Page from '../page';\nimport AddNewTemplate from '../add-new-template';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tOPERATOR_IS_ANY,\n\tLAYOUT_GRID,\n\tLAYOUT_TABLE,\n\tLAYOUT_LIST,\n} from '../../utils/constants';\nimport { unlock } from '../../lock-unlock';\nimport { useEditPostAction } from '../dataviews-actions';\nimport { authorField, descriptionField, previewField } from './fields';\nimport { useEvent } from '@wordpress/compose';\n\nconst { usePostActions, templateTitleField } = unlock( editorPrivateApis );\nconst { useHistory, useLocation } = unlock( routerPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nconst defaultLayouts = {\n\t[ LAYOUT_TABLE ]: {\n\t\tshowMedia: false,\n\t},\n\t[ LAYOUT_GRID ]: {\n\t\tshowMedia: true,\n\t},\n\t[ LAYOUT_LIST ]: {\n\t\tshowMedia: false,\n\t},\n};\n\nconst DEFAULT_VIEW = {\n\ttype: LAYOUT_GRID,\n\tsearch: '',\n\tpage: 1,\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' ],\n\tfilters: [],\n\t...defaultLayouts[ LAYOUT_GRID ],\n};\n\nexport default function PageTemplates() {\n\tconst { path, query } = useLocation();\n\tconst { activeView = 'all', layout, postId } = query;\n\tconst [ selection, setSelection ] = useState( [ postId ] );\n\n\tconst defaultView = useMemo( () => {\n\t\tconst usedType = layout ?? DEFAULT_VIEW.type;\n\t\treturn {\n\t\t\t...DEFAULT_VIEW,\n\t\t\ttype: usedType,\n\t\t\tfilters:\n\t\t\t\tactiveView !== 'all'\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\t\t\toperator: 'isAny',\n\t\t\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t ]\n\t\t\t\t\t: [],\n\t\t\t...defaultLayouts[ usedType ],\n\t\t};\n\t}, [ layout, activeView ] );\n\tconst [ view, setView ] = useState( defaultView );\n\n\t// Sync the layout from the URL to the view state.\n\tuseEffect( () => {\n\t\tsetView( ( currentView ) => ( {\n\t\t\t...currentView,\n\t\t\ttype: layout ?? DEFAULT_VIEW.type,\n\t\t} ) );\n\t}, [ setView, layout ] );\n\n\t// Sync the active view from the URL to the view state.\n\tuseEffect( () => {\n\t\tsetView( ( currentView ) => ( {\n\t\t\t...currentView,\n\t\t\tfilters:\n\t\t\t\tactiveView !== 'all'\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\t\t\toperator: OPERATOR_IS_ANY,\n\t\t\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t ]\n\t\t\t\t\t: [],\n\t\t} ) );\n\t}, [ setView, activeView ] );\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 === LAYOUT_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 EMPTY_ARRAY;\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\tsetView( newView );\n\t\tif ( newView.type !== layout ) {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\tlayout: newView.type,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\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={ <AddNewTemplate /> }\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"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AAKA,IAAAO,KAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,eAAA,GAAAD,sBAAA,CAAAR,OAAA;AACA,IAAAU,UAAA,GAAAV,OAAA;AAOA,IAAAW,WAAA,GAAAX,OAAA;AACA,IAAAY,iBAAA,GAAAZ,OAAA;AACA,IAAAa,OAAA,GAAAb,OAAA;AACA,IAAAc,QAAA,GAAAd,OAAA;AAA8C,IAAAe,WAAA,GAAAf,OAAA;AA1B9C;AACA;AACA;;AASA;AACA;AACA;;AAeA,MAAM;EAAEgB,cAAc;EAAEC;AAAmB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAC1E,MAAM;EAAEC,UAAU;EAAEC;AAAY,CAAC,GAAG,IAAAH,kBAAM,EAAEI,mBAAkB,CAAC;AAC/D,MAAM;EAAEC;AAAgC,CAAC,GAAG,IAAAL,kBAAM,EAAEM,qBAAgB,CAAC;AAErE,MAAMC,WAAW,GAAG,EAAE;AAEtB,MAAMC,cAAc,GAAG;EACtB,CAAEC,uBAAY,GAAI;IACjBC,SAAS,EAAE;EACZ,CAAC;EACD,CAAE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,eAAe,EAAEG,UAAU,CAC9B,CAAC;EAED,MAAMG,YAAY,GAAG,IAAAC,iBAAQ,EAAIC,OAAO,IAAM;IAC7C3C,OAAO,CAAE2C,OAAQ,CAAC;IAClB,IAAKA,OAAO,CAACtE,IAAI,KAAKgB,MAAM,EAAG;MAC9BoB,OAAO,CAACI,QAAQ,CACf,IAAAC,iBAAY,EAAE5B,IAAI,EAAE;QACnBG,MAAM,EAAEsD,OAAO,CAACtE;MACjB,CAAE,CACH,CAAC;IACF;EACD,CAAE,CAAC;EAEH,oBACC,IAAAjB,WAAA,CAAAwF,GAAA,EAAChG,KAAA,CAAAiG,OAAI;IACJC,SAAS,EAAC,0BAA0B;IACpCC,KAAK,EAAG,IAAAC,QAAE,EAAE,WAAY,CAAG;IAC3BR,OAAO,eAAG,IAAApF,WAAA,CAAAwF,GAAA,EAAC9F,eAAA,CAAA+F,OAAc,IAAE,CAAG;IAAAI,QAAA,eAE9B,IAAA7F,WAAA,CAAAwF,GAAA,EAACpG,UAAA,CAAA0G,SAAS;MAETjB,cAAc,EAAGA,cAAgB;MACjClD,MAAM,EAAGA,MAAQ;MACjByD,OAAO,EAAGA,OAAS;MACnBR,IAAI,EAAGA,IAAM;MACbmB,SAAS,EAAG7C,aAAe;MAC3BP,IAAI,EAAGA,IAAM;MACb0C,YAAY,EAAGA,YAAc;MAC7B/B,iBAAiB,EAAGA,iBAAmB;MACvC0C,eAAe,EAAGA,CAAA,KAAM,IAAM;MAC9BC,WAAW,EAAGA,CAAE;QAAEC;MAAG,CAAC,KAAM;QAC3B7C,OAAO,CAACI,QAAQ,CAAE,gBAAiByC,EAAE,cAAgB,CAAC;MACvD,CAAG;MACH/D,SAAS,EAAGA,SAAW;MACvBxB,cAAc,EAAGA;IAAgB,GAd3BqB,UAeN;EAAC,CACG,CAAC;AAET","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_coreData","_dataviews","_router","_editor","_url","_data","_compose","_page","_interopRequireDefault","_addNewTemplate","_constants","_lockUnlock","_dataviewsActions","_fields2","_jsxRuntime","usePostActions","templateTitleField","unlock","editorPrivateApis","useHistory","useLocation","routerPrivateApis","useEntityRecordsWithPermissions","corePrivateApis","defaultLayouts","LAYOUT_TABLE","showMedia","LAYOUT_GRID","LAYOUT_LIST","DEFAULT_VIEW","type","search","page","perPage","sort","field","direction","titleField","descriptionField","mediaField","fields","filters","PageTemplates","path","query","activeView","layout","postId","selection","setSelection","useState","defaultView","useMemo","usedType","includes","operator","value","view","setView","useEffect","currentView","OPERATOR_IS_ANY","activeTemplatesOption","useSelect","select","coreStore","getEntityRecord","active_templates","records","userRecords","isResolving","isLoadingUserRecords","TEMPLATE_POST_TYPE","per_page","staticRecords","isLoadingStaticData","activeTemplates","_active","filter","record","is_custom","activeSlug","activeId","index","findIndex","template","slug","splice","find","id","push","_records","isLoadingData","map","_isActive","undefined","Object","values","users","getUser","reduce","acc","author_text","author","history","onChangeSelection","useCallback","items","navigate","addQueryArgs","length","_fields","previewField","activeField","slugField","elements","_users$author$id","_users$author$name","label","name","authorField","data","paginationInfo","filterSortAndPaginate","postTypeActions","postType","context","editAction","useEditPostAction","setActiveTemplateAction","useSetActiveTemplateAction","actions","onChangeView","useEvent","newView","jsx","default","className","title","__","children","DataViews","isLoading","isItemClickable","onClickItem","item"],"sources":["@wordpress/edit-site/src/components/page-templates/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo, useCallback, useEffect } from '@wordpress/element';\nimport {\n\tprivateApis as corePrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { privateApis as editorPrivateApis } from '@wordpress/editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { useSelect } from '@wordpress/data';\nimport { useEvent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport Page from '../page';\nimport AddNewTemplate from '../add-new-template';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tOPERATOR_IS_ANY,\n\tLAYOUT_GRID,\n\tLAYOUT_TABLE,\n\tLAYOUT_LIST,\n} 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} from './fields';\n\nconst { usePostActions, templateTitleField } = unlock( editorPrivateApis );\nconst { useHistory, useLocation } = unlock( routerPrivateApis );\nconst { useEntityRecordsWithPermissions } = unlock( corePrivateApis );\n\nconst defaultLayouts = {\n\t[ LAYOUT_TABLE ]: {\n\t\tshowMedia: false,\n\t},\n\t[ LAYOUT_GRID ]: {\n\t\tshowMedia: true,\n\t},\n\t[ LAYOUT_LIST ]: {\n\t\tshowMedia: false,\n\t},\n};\n\nconst DEFAULT_VIEW = {\n\ttype: LAYOUT_GRID,\n\tsearch: '',\n\tpage: 1,\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[ LAYOUT_GRID ],\n};\n\nexport default function PageTemplates() {\n\tconst { path, query } = useLocation();\n\tconst { activeView = 'active', layout, postId } = query;\n\tconst [ selection, setSelection ] = useState( [ postId ] );\n\tconst defaultView = useMemo( () => {\n\t\tconst usedType = layout ?? DEFAULT_VIEW.type;\n\t\treturn {\n\t\t\t...DEFAULT_VIEW,\n\t\t\ttype: usedType,\n\t\t\tfilters: ! [ 'active', 'user' ].includes( activeView )\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\t\toperator: 'isAny',\n\t\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t\t},\n\t\t\t\t ]\n\t\t\t\t: [],\n\t\t\t...defaultLayouts[ usedType ],\n\t\t};\n\t}, [ layout, activeView ] );\n\tconst [ view, setView ] = useState( defaultView );\n\n\t// Sync the layout from the URL to the view state.\n\tuseEffect( () => {\n\t\tsetView( ( currentView ) => ( {\n\t\t\t...currentView,\n\t\t\ttype: layout ?? DEFAULT_VIEW.type,\n\t\t} ) );\n\t}, [ setView, layout ] );\n\n\t// Sync the active view from the URL to the view state.\n\tuseEffect( () => {\n\t\tsetView( ( currentView ) => ( {\n\t\t\t...currentView,\n\t\t\tfilters: ! [ 'active', 'user' ].includes( activeView )\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: 'author',\n\t\t\t\t\t\t\toperator: OPERATOR_IS_ANY,\n\t\t\t\t\t\t\tvalue: [ activeView ],\n\t\t\t\t\t\t},\n\t\t\t\t ]\n\t\t\t\t: [],\n\t\t} ) );\n\t}, [ setView, activeView ] );\n\n\tconst activeTemplatesOption = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord( 'root', 'site' )\n\t\t\t\t?.active_templates\n\t);\n\t// Todo: this will have to be better so that we're not fetching all the\n\t// records all the time. Active templates query will need to move server\n\t// side.\n\tconst { records: userRecords, isResolving: isLoadingUserRecords } =\n\t\tuseEntityRecordsWithPermissions( 'postType', TEMPLATE_POST_TYPE, {\n\t\t\tper_page: -1,\n\t\t} );\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( { id } ) => id === activeId\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 ] );\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:\n\t\t\t\ttypeof record.id === 'string'\n\t\t\t\t\t? activeTemplatesOption[ record.slug ] === record.id ||\n\t\t\t\t\t activeTemplatesOption[ record.slug ] === undefined\n\t\t\t\t\t: Object.values( activeTemplatesOption ).includes(\n\t\t\t\t\t\t\trecord.id\n\t\t\t\t\t ),\n\t\t} ) );\n\t}, [ _records, activeTemplatesOption ] );\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 === LAYOUT_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 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\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 ] );\n\n\tconst { data, paginationInfo } = useMemo( () => {\n\t\treturn filterSortAndPaginate( records, view, fields );\n\t}, [ records, view, fields ] );\n\n\tconst postTypeActions = usePostActions( {\n\t\tpostType: TEMPLATE_POST_TYPE,\n\t\tcontext: 'list',\n\t} );\n\tconst editAction = useEditPostAction();\n\tconst setActiveTemplateAction = useSetActiveTemplateAction();\n\tconst actions = useMemo(\n\t\t() =>\n\t\t\tactiveView === 'user'\n\t\t\t\t? [ setActiveTemplateAction, editAction, ...postTypeActions ]\n\t\t\t\t: [ setActiveTemplateAction, ...postTypeActions ],\n\t\t[ postTypeActions, setActiveTemplateAction, editAction, activeView ]\n\t);\n\n\tconst onChangeView = useEvent( ( newView ) => {\n\t\tsetView( newView );\n\t\tif ( newView.type !== layout ) {\n\t\t\thistory.navigate(\n\t\t\t\taddQueryArgs( path, {\n\t\t\t\t\tlayout: newView.type,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\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={ <AddNewTemplate /> }\n\t\t>\n\t\t\t<DataViews\n\t\t\t\tkey={ activeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tfields={ fields }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tisLoading={ isLoadingData }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\tisItemClickable={ () => true }\n\t\t\t\tonClickItem={ ( item ) => {\n\t\t\t\t\thistory.navigate(\n\t\t\t\t\t\t`/${ item.type }/${ item.id }?canvas=edit`\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t\tselection={ selection }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t/>\n\t\t</Page>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAIA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAKA,I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AKqC,IAAI,CAACnH,IAAI,IAAMmH,IAAI,CAACxD,EAAE,cAC5B,CAAC;MACF,CAAG;MACHzC,SAAS,EAAGA,SAAW;MACvBxB,cAAc,EAAGA;IAAgB,GAhB3BqB,UAiBN;EAAC,CACG,CAAC;AAET","ignoreList":[]}
|
|
@@ -14,7 +14,6 @@ var _url = require("@wordpress/url");
|
|
|
14
14
|
var _sidebarNavigationItem = _interopRequireDefault(require("../sidebar-navigation-item"));
|
|
15
15
|
var _hooks = require("../page-templates/hooks");
|
|
16
16
|
var _icons = require("@wordpress/icons");
|
|
17
|
-
var _constants = require("../../utils/constants");
|
|
18
17
|
var _lockUnlock = require("../../lock-unlock");
|
|
19
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
19
|
/**
|
|
@@ -49,12 +48,12 @@ function TemplateDataviewItem({
|
|
|
49
48
|
function DataviewsTemplatesSidebarContent() {
|
|
50
49
|
const {
|
|
51
50
|
query: {
|
|
52
|
-
activeView = '
|
|
51
|
+
activeView = 'active'
|
|
53
52
|
}
|
|
54
53
|
} = useLocation();
|
|
55
54
|
const {
|
|
56
55
|
records
|
|
57
|
-
} = (0, _coreData.useEntityRecords)('postType',
|
|
56
|
+
} = (0, _coreData.useEntityRecords)('postType', 'wp_registered_template', {
|
|
58
57
|
per_page: -1
|
|
59
58
|
});
|
|
60
59
|
const firstItemPerAuthorText = (0, _element.useMemo)(() => {
|
|
@@ -73,8 +72,15 @@ function DataviewsTemplatesSidebarContent() {
|
|
|
73
72
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationItem.default, {
|
|
74
73
|
to: "/template",
|
|
75
74
|
icon: _icons.layout,
|
|
76
|
-
"aria-current": activeView === '
|
|
77
|
-
children: (0, _i18n.__)('
|
|
75
|
+
"aria-current": activeView === 'active',
|
|
76
|
+
children: (0, _i18n.__)('Active templates')
|
|
77
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationItem.default, {
|
|
78
|
+
to: (0, _url.addQueryArgs)('/template', {
|
|
79
|
+
activeView: 'user'
|
|
80
|
+
}),
|
|
81
|
+
icon: _icons.layout,
|
|
82
|
+
"aria-current": activeView === 'user',
|
|
83
|
+
children: (0, _i18n.__)('Custom templates')
|
|
78
84
|
}), firstItemPerAuthorText.map(template => {
|
|
79
85
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(TemplateDataviewItem, {
|
|
80
86
|
template: template,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_element","_components","_i18n","_router","_url","_sidebarNavigationItem","_interopRequireDefault","_hooks","_icons","
|
|
1
|
+
{"version":3,"names":["_coreData","require","_element","_components","_i18n","_router","_url","_sidebarNavigationItem","_interopRequireDefault","_hooks","_icons","_lockUnlock","_jsxRuntime","useLocation","unlock","routerPrivateApis","EMPTY_ARRAY","TemplateDataviewItem","template","isActive","text","icon","useAddedBy","type","id","jsx","default","to","addQueryArgs","activeView","children","DataviewsTemplatesSidebarContent","query","records","useEntityRecords","per_page","firstItemPerAuthorText","useMemo","_ref","firstItemPerAuthor","reduce","acc","author","author_text","Object","values","jsxs","__experimentalItemGroup","className","layout","__","map"],"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-templates-browse/content.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __experimentalItemGroup as ItemGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport { useAddedBy } from '../page-templates/hooks';\nimport { layout } from '@wordpress/icons';\nimport { unlock } from '../../lock-unlock';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nfunction TemplateDataviewItem( { template, isActive } ) {\n\tconst { text, icon } = useAddedBy( template.type, template.id );\n\n\treturn (\n\t\t<SidebarNavigationItem\n\t\t\tto={ addQueryArgs( '/template', { activeView: text } ) }\n\t\t\ticon={ icon }\n\t\t\taria-current={ isActive }\n\t\t>\n\t\t\t{ text }\n\t\t</SidebarNavigationItem>\n\t);\n}\n\nexport default function DataviewsTemplatesSidebarContent() {\n\tconst {\n\t\tquery: { activeView = 'active' },\n\t} = useLocation();\n\tconst { records } = useEntityRecords(\n\t\t'postType',\n\t\t'wp_registered_template',\n\t\t{\n\t\t\tper_page: -1,\n\t\t}\n\t);\n\tconst firstItemPerAuthorText = useMemo( () => {\n\t\tconst firstItemPerAuthor = records?.reduce( ( acc, template ) => {\n\t\t\tconst author = template.author_text;\n\t\t\tif ( author && ! acc[ author ] ) {\n\t\t\t\tacc[ author ] = template;\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, {} );\n\t\treturn (\n\t\t\t( firstItemPerAuthor && Object.values( firstItemPerAuthor ) ) ??\n\t\t\tEMPTY_ARRAY\n\t\t);\n\t}, [ records ] );\n\n\treturn (\n\t\t<ItemGroup className=\"edit-site-sidebar-navigation-screen-templates-browse\">\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto=\"/template\"\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'active' }\n\t\t\t>\n\t\t\t\t{ __( 'Active templates' ) }\n\t\t\t</SidebarNavigationItem>\n\t\t\t<SidebarNavigationItem\n\t\t\t\tto={ addQueryArgs( '/template', { activeView: 'user' } ) }\n\t\t\t\ticon={ layout }\n\t\t\t\taria-current={ activeView === 'user' }\n\t\t\t>\n\t\t\t\t{ __( 'Custom 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/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CAACe,GAAG,CAAIjC,QAAQ,IAAM;MAC7C,oBACC,IAAAN,WAAA,CAAAa,GAAA,EAACR,oBAAoB;QAEpBC,QAAQ,EAAGA,QAAU;QACrBC,QAAQ,EAAGU,UAAU,KAAKX,QAAQ,CAACyB;MAAa,GAF1CzB,QAAQ,CAACyB,WAGf,CAAC;IAEJ,CAAE,CAAC;EAAA,CACO,CAAC;AAEd","ignoreList":[]}
|
|
@@ -29,7 +29,7 @@ var _notfound = require("./notfound");
|
|
|
29
29
|
* Internal dependencies
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
const routes = [_pageItem.pageItemRoute, _pages.pagesRoute, _templateItem.templateItemRoute, _templates.templatesRoute, _templatePartItem.templatePartItemRoute, _patternItem.patternItemRoute, _patterns.patternsRoute, _navigationItem.navigationItemRoute, _navigation.navigationRoute, _styles.stylesRoute, _home.homeRoute, _stylebook.stylebookRoute, _notfound.notFoundRoute];
|
|
32
|
+
const routes = [_pageItem.pageItemRoute, _pages.pagesRoute, _templateItem.templateItemRoute, _templateItem.staticTemplateItemRoute, _templates.templatesRoute, _templatePartItem.templatePartItemRoute, _patternItem.patternItemRoute, _patterns.patternsRoute, _navigationItem.navigationItemRoute, _navigation.navigationRoute, _styles.stylesRoute, _home.homeRoute, _stylebook.stylebookRoute, _notfound.notFoundRoute];
|
|
33
33
|
function useRegisterSiteEditorRoutes() {
|
|
34
34
|
const registry = (0, _data.useRegistry)();
|
|
35
35
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_element","_lockUnlock","_store","_home","_styles","_navigation","_navigationItem","_patterns","_patternItem","_templatePartItem","_templates","_templateItem","_pages","_pageItem","_stylebook","_notfound","routes","pageItemRoute","pagesRoute","templateItemRoute","templatesRoute","templatePartItemRoute","patternItemRoute","patternsRoute","navigationItemRoute","navigationRoute","stylesRoute","homeRoute","stylebookRoute","notFoundRoute","useRegisterSiteEditorRoutes","registry","useRegistry","registerRoute","unlock","useDispatch","siteEditorStore","useEffect","batch","forEach"],"sources":["@wordpress/edit-site/src/components/site-editor-routes/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRegistry, useDispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as siteEditorStore } from '../../store';\nimport { homeRoute } from './home';\nimport { stylesRoute } from './styles';\nimport { navigationRoute } from './navigation';\nimport { navigationItemRoute } from './navigation-item';\nimport { patternsRoute } from './patterns';\nimport { patternItemRoute } from './pattern-item';\nimport { templatePartItemRoute } from './template-part-item';\nimport { templatesRoute } from './templates';\nimport { templateItemRoute } from './template-item';\nimport { pagesRoute } from './pages';\nimport { pageItemRoute } from './page-item';\nimport { stylebookRoute } from './stylebook';\nimport { notFoundRoute } from './notfound';\n\nconst routes = [\n\tpageItemRoute,\n\tpagesRoute,\n\ttemplateItemRoute,\n\ttemplatesRoute,\n\ttemplatePartItemRoute,\n\tpatternItemRoute,\n\tpatternsRoute,\n\tnavigationItemRoute,\n\tnavigationRoute,\n\tstylesRoute,\n\thomeRoute,\n\tstylebookRoute,\n\tnotFoundRoute,\n];\n\nexport function useRegisterSiteEditorRoutes() {\n\tconst registry = useRegistry();\n\tconst { registerRoute } = unlock( useDispatch( siteEditorStore ) );\n\tuseEffect( () => {\n\t\tregistry.batch( () => {\n\t\t\troutes.forEach( registerRoute );\n\t\t} );\n\t}, [ registry, registerRoute ] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,UAAA,GAAAX,OAAA;AACA,IAAAY,aAAA,GAAAZ,OAAA;AACA,IAAAa,MAAA,GAAAb,OAAA;AACA,IAAAc,SAAA,GAAAd,OAAA;AACA,IAAAe,UAAA,GAAAf,OAAA;AACA,IAAAgB,SAAA,GAAAhB,OAAA;AAvBA;AACA;AACA;;AAIA;AACA;AACA;;AAiBA,MAAMiB,MAAM,GAAG,CACdC,uBAAa,EACbC,iBAAU,EACVC,+BAAiB,EACjBC,yBAAc,EACdC,uCAAqB,EACrBC,6BAAgB,EAChBC,uBAAa,EACbC,mCAAmB,EACnBC,2BAAe,EACfC,mBAAW,EACXC,eAAS,EACTC,yBAAc,EACdC,uBAAa,CACb;AAEM,SAASC,2BAA2BA,CAAA,EAAG;EAC7C,MAAMC,QAAQ,GAAG,IAAAC,iBAAW,EAAC,CAAC;EAC9B,MAAM;IAAEC;EAAc,CAAC,GAAG,IAAAC,kBAAM,EAAE,IAAAC,iBAAW,EAAEC,YAAgB,CAAE,CAAC;EAClE,IAAAC,kBAAS,EAAE,MAAM;IAChBN,QAAQ,CAACO,KAAK,CAAE,MAAM;
|
|
1
|
+
{"version":3,"names":["_data","require","_element","_lockUnlock","_store","_home","_styles","_navigation","_navigationItem","_patterns","_patternItem","_templatePartItem","_templates","_templateItem","_pages","_pageItem","_stylebook","_notfound","routes","pageItemRoute","pagesRoute","templateItemRoute","staticTemplateItemRoute","templatesRoute","templatePartItemRoute","patternItemRoute","patternsRoute","navigationItemRoute","navigationRoute","stylesRoute","homeRoute","stylebookRoute","notFoundRoute","useRegisterSiteEditorRoutes","registry","useRegistry","registerRoute","unlock","useDispatch","siteEditorStore","useEffect","batch","forEach"],"sources":["@wordpress/edit-site/src/components/site-editor-routes/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRegistry, useDispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as siteEditorStore } from '../../store';\nimport { homeRoute } from './home';\nimport { stylesRoute } from './styles';\nimport { navigationRoute } from './navigation';\nimport { navigationItemRoute } from './navigation-item';\nimport { patternsRoute } from './patterns';\nimport { patternItemRoute } from './pattern-item';\nimport { templatePartItemRoute } from './template-part-item';\nimport { templatesRoute } from './templates';\nimport { templateItemRoute, staticTemplateItemRoute } from './template-item';\nimport { pagesRoute } from './pages';\nimport { pageItemRoute } from './page-item';\nimport { stylebookRoute } from './stylebook';\nimport { notFoundRoute } from './notfound';\n\nconst routes = [\n\tpageItemRoute,\n\tpagesRoute,\n\ttemplateItemRoute,\n\tstaticTemplateItemRoute,\n\ttemplatesRoute,\n\ttemplatePartItemRoute,\n\tpatternItemRoute,\n\tpatternsRoute,\n\tnavigationItemRoute,\n\tnavigationRoute,\n\tstylesRoute,\n\thomeRoute,\n\tstylebookRoute,\n\tnotFoundRoute,\n];\n\nexport function useRegisterSiteEditorRoutes() {\n\tconst registry = useRegistry();\n\tconst { registerRoute } = unlock( useDispatch( siteEditorStore ) );\n\tuseEffect( () => {\n\t\tregistry.batch( () => {\n\t\t\troutes.forEach( registerRoute );\n\t\t} );\n\t}, [ registry, registerRoute ] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,UAAA,GAAAX,OAAA;AACA,IAAAY,aAAA,GAAAZ,OAAA;AACA,IAAAa,MAA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