@wordpress/edit-site 6.30.1-next.a730c9c8c.0 → 6.31.1-next.233ccab9b.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 +3 -2
- 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 +26 -87
- 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/global-styles/screen-css.js +2 -3
- package/build/components/global-styles/screen-css.js.map +1 -1
- package/build/components/global-styles/screen-root.js +3 -35
- package/build/components/global-styles/screen-root.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-global-styles-wrapper/index.js +45 -13
- package/build/components/sidebar-global-styles-wrapper/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 +3 -2
- 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 +26 -87
- 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/global-styles/screen-css.js +2 -3
- package/build-module/components/global-styles/screen-css.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +4 -36
- package/build-module/components/global-styles/screen-root.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-global-styles-wrapper/index.js +48 -16
- package/build-module/components/sidebar-global-styles-wrapper/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 +3 -4
- package/src/components/add-new-template/index.js +1 -8
- package/src/components/add-new-template/utils.js +36 -121
- 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/global-styles/screen-css.js +4 -5
- package/src/components/global-styles/screen-root.js +5 -51
- 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-global-styles-wrapper/index.js +62 -16
- 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
|
@@ -26,7 +26,6 @@ const {
|
|
|
26
26
|
AdvancedPanel: StylesAdvancedPanel
|
|
27
27
|
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
28
28
|
function ScreenCSS() {
|
|
29
|
-
const description = (0, _i18n.__)('Add your own CSS to customize the appearance and layout of your site.');
|
|
30
29
|
const [style] = useGlobalStyle('', undefined, 'user', {
|
|
31
30
|
shouldDecodeEncode: false
|
|
32
31
|
});
|
|
@@ -38,9 +37,9 @@ function ScreenCSS() {
|
|
|
38
37
|
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
39
38
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
40
39
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_header.default, {
|
|
41
|
-
title: (0, _i18n.__)('CSS'),
|
|
40
|
+
title: (0, _i18n.__)('Additional CSS'),
|
|
42
41
|
description: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
43
|
-
children: [
|
|
42
|
+
children: [(0, _i18n.__)('You can add custom CSS to further customize the appearance and layout of your site.'), /*#__PURE__*/(0, _jsxRuntime.jsx)("br", {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ExternalLink, {
|
|
44
43
|
href: (0, _i18n.__)('https://developer.wordpress.org/advanced-administration/wordpress/css/'),
|
|
45
44
|
className: "edit-site-global-styles-screen-css-help-link",
|
|
46
45
|
children: (0, _i18n.__)('Learn more about CSS')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_blockEditor","_data","_lockUnlock","_store","_header","_interopRequireDefault","_jsxRuntime","useGlobalStyle","AdvancedPanel","StylesAdvancedPanel","unlock","blockEditorPrivateApis","ScreenCSS","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_blockEditor","_data","_lockUnlock","_store","_header","_interopRequireDefault","_jsxRuntime","useGlobalStyle","AdvancedPanel","StylesAdvancedPanel","unlock","blockEditorPrivateApis","ScreenCSS","style","undefined","shouldDecodeEncode","inheritedStyle","setStyle","setEditorCanvasContainerView","useDispatch","editSiteStore","jsxs","Fragment","children","jsx","default","title","__","description","ExternalLink","href","className","onBack","value","onChange","inheritedValue","_default","exports"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-css.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { ExternalLink } from '@wordpress/components';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editSiteStore } from '../../store';\nimport ScreenHeader from './header';\n\nconst { useGlobalStyle, AdvancedPanel: StylesAdvancedPanel } = unlock(\n\tblockEditorPrivateApis\n);\n\nfunction ScreenCSS() {\n\tconst [ style ] = useGlobalStyle( '', undefined, 'user', {\n\t\tshouldDecodeEncode: false,\n\t} );\n\tconst [ inheritedStyle, setStyle ] = useGlobalStyle( '', undefined, 'all', {\n\t\tshouldDecodeEncode: false,\n\t} );\n\n\tconst { setEditorCanvasContainerView } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<ScreenHeader\n\t\t\t\ttitle={ __( 'Additional CSS' ) }\n\t\t\t\tdescription={\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'You can add custom CSS to further customize the appearance and layout of your site.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<br />\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t'https://developer.wordpress.org/advanced-administration/wordpress/css/'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-css-help-link\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Learn more about CSS' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tonBack={ () => {\n\t\t\t\t\tsetEditorCanvasContainerView( undefined );\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<div className=\"edit-site-global-styles-screen-css\">\n\t\t\t\t<StylesAdvancedPanel\n\t\t\t\t\tvalue={ style }\n\t\t\t\t\tonChange={ setStyle }\n\t\t\t\t\tinheritedValue={ inheritedStyle }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default ScreenCSS;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAC,sBAAA,CAAAP,OAAA;AAAoC,IAAAQ,WAAA,GAAAR,OAAA;AAbpC;AACA;AACA;;AAMA;AACA;AACA;;AAKA,MAAM;EAAES,cAAc;EAAEC,aAAa,EAAEC;AAAoB,CAAC,GAAG,IAAAC,kBAAM,EACpEC,wBACD,CAAC;AAED,SAASC,SAASA,CAAA,EAAG;EACpB,MAAM,CAAEC,KAAK,CAAE,GAAGN,cAAc,CAAE,EAAE,EAAEO,SAAS,EAAE,MAAM,EAAE;IACxDC,kBAAkB,EAAE;EACrB,CAAE,CAAC;EACH,MAAM,CAAEC,cAAc,EAAEC,QAAQ,CAAE,GAAGV,cAAc,CAAE,EAAE,EAAEO,SAAS,EAAE,KAAK,EAAE;IAC1EC,kBAAkB,EAAE;EACrB,CAAE,CAAC;EAEH,MAAM;IAAEG;EAA6B,CAAC,GAAG,IAAAR,kBAAM,EAC9C,IAAAS,iBAAW,EAAEC,YAAc,CAC5B,CAAC;EAED,oBACC,IAAAd,WAAA,CAAAe,IAAA,EAAAf,WAAA,CAAAgB,QAAA;IAAAC,QAAA,gBACC,IAAAjB,WAAA,CAAAkB,GAAA,EAACpB,OAAA,CAAAqB,OAAY;MACZC,KAAK,EAAG,IAAAC,QAAE,EAAE,gBAAiB,CAAG;MAChCC,WAAW,eACV,IAAAtB,WAAA,CAAAe,IAAA,EAAAf,WAAA,CAAAgB,QAAA;QAAAC,QAAA,GACG,IAAAI,QAAE,EACH,qFACD,CAAC,eACD,IAAArB,WAAA,CAAAkB,GAAA,UAAK,CAAC,eACN,IAAAlB,WAAA,CAAAkB,GAAA,EAACzB,WAAA,CAAA8B,YAAY;UACZC,IAAI,EAAG,IAAAH,QAAE,EACR,wEACD,CAAG;UACHI,SAAS,EAAC,8CAA8C;UAAAR,QAAA,EAEtD,IAAAI,QAAE,EAAE,sBAAuB;QAAC,CACjB,CAAC;MAAA,CACd,CACF;MACDK,MAAM,EAAGA,CAAA,KAAM;QACdd,4BAA4B,CAAEJ,SAAU,CAAC;MAC1C;IAAG,CACH,CAAC,eACF,IAAAR,WAAA,CAAAkB,GAAA;MAAKO,SAAS,EAAC,oCAAoC;MAAAR,QAAA,eAClD,IAAAjB,WAAA,CAAAkB,GAAA,EAACf,mBAAmB;QACnBwB,KAAK,EAAGpB,KAAO;QACfqB,QAAQ,EAAGjB,QAAU;QACrBkB,cAAc,EAAGnB;MAAgB,CACjC;IAAC,CACE,CAAC;EAAA,CACL,CAAC;AAEL;AAAC,IAAAoB,QAAA,GAAAC,OAAA,CAAAZ,OAAA,GAEcb,SAAS","ignoreList":[]}
|
|
@@ -24,21 +24,11 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
function ScreenRoot() {
|
|
27
|
-
const {
|
|
28
|
-
hasVariations,
|
|
29
|
-
canEditCSS
|
|
30
|
-
} = (0, _data.useSelect)(select => {
|
|
27
|
+
const hasVariations = (0, _data.useSelect)(select => {
|
|
31
28
|
const {
|
|
32
|
-
getEntityRecord,
|
|
33
|
-
__experimentalGetCurrentGlobalStylesId,
|
|
34
29
|
__experimentalGetCurrentThemeGlobalStylesVariations
|
|
35
30
|
} = select(_coreData.store);
|
|
36
|
-
|
|
37
|
-
const globalStyles = globalStylesId ? getEntityRecord('root', 'globalStyles', globalStylesId) : undefined;
|
|
38
|
-
return {
|
|
39
|
-
hasVariations: !!__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
|
|
40
|
-
canEditCSS: !!globalStyles?._links?.['wp:action-edit-css']
|
|
41
|
-
};
|
|
31
|
+
return !!__experimentalGetCurrentThemeGlobalStylesVariations()?.length;
|
|
42
32
|
}, []);
|
|
43
33
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Card, {
|
|
44
34
|
size: "small",
|
|
@@ -78,7 +68,7 @@ function ScreenRoot() {
|
|
|
78
68
|
* the nav button inset should be looked at before reusing further.
|
|
79
69
|
*/,
|
|
80
70
|
paddingX: "13px",
|
|
81
|
-
marginBottom:
|
|
71
|
+
marginBottom: 2,
|
|
82
72
|
children: (0, _i18n.__)('Customize the appearance of specific blocks for the whole site.')
|
|
83
73
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalItemGroup, {
|
|
84
74
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_navigationButton.NavigationButtonAsItem, {
|
|
@@ -93,28 +83,6 @@ function ScreenRoot() {
|
|
|
93
83
|
})
|
|
94
84
|
})
|
|
95
85
|
})]
|
|
96
|
-
}), canEditCSS && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
97
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CardDivider, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.CardBody, {
|
|
98
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalSpacer, {
|
|
99
|
-
as: "p",
|
|
100
|
-
paddingTop: 2,
|
|
101
|
-
paddingX: "13px",
|
|
102
|
-
marginBottom: 4,
|
|
103
|
-
children: (0, _i18n.__)('Add your own CSS to customize the appearance and layout of your site.')
|
|
104
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalItemGroup, {
|
|
105
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_navigationButton.NavigationButtonAsItem, {
|
|
106
|
-
path: "/css",
|
|
107
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
108
|
-
justify: "space-between",
|
|
109
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexItem, {
|
|
110
|
-
children: (0, _i18n.__)('Additional CSS')
|
|
111
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_iconWithCurrentColor.IconWithCurrentColor, {
|
|
112
|
-
icon: (0, _i18n.isRTL)() ? _icons.chevronLeft : _icons.chevronRight
|
|
113
|
-
})]
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
})]
|
|
117
|
-
})]
|
|
118
86
|
})]
|
|
119
87
|
});
|
|
120
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_icons","_data","_coreData","_iconWithCurrentColor","_navigationButton","_rootMenu","_interopRequireDefault","_previewStyles","_jsxRuntime","ScreenRoot","hasVariations","
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_icons","_data","_coreData","_iconWithCurrentColor","_navigationButton","_rootMenu","_interopRequireDefault","_previewStyles","_jsxRuntime","ScreenRoot","hasVariations","useSelect","select","__experimentalGetCurrentThemeGlobalStylesVariations","coreStore","length","jsxs","Card","size","isBorderless","className","isRounded","children","jsx","CardBody","__experimentalVStack","spacing","CardMedia","default","__experimentalItemGroup","NavigationButtonAsItem","path","__experimentalHStack","justify","FlexItem","__","IconWithCurrentColor","icon","isRTL","chevronLeft","chevronRight","CardDivider","__experimentalSpacer","as","paddingTop","paddingX","marginBottom","_default","exports"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-root.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalHStack as HStack,\n\t__experimentalSpacer as Spacer,\n\t__experimentalVStack as VStack,\n\tFlexItem,\n\tCardBody,\n\tCard,\n\tCardDivider,\n\tCardMedia,\n} from '@wordpress/components';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { chevronLeft, chevronRight } from '@wordpress/icons';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { IconWithCurrentColor } from './icon-with-current-color';\nimport { NavigationButtonAsItem } from './navigation-button';\nimport RootMenu from './root-menu';\nimport PreviewStyles from './preview-styles';\n\nfunction ScreenRoot() {\n\tconst hasVariations = useSelect( ( select ) => {\n\t\tconst { __experimentalGetCurrentThemeGlobalStylesVariations } =\n\t\t\tselect( coreStore );\n\t\treturn !! __experimentalGetCurrentThemeGlobalStylesVariations()?.length;\n\t}, [] );\n\n\treturn (\n\t\t<Card\n\t\t\tsize=\"small\"\n\t\t\tisBorderless\n\t\t\tclassName=\"edit-site-global-styles-screen-root\"\n\t\t\tisRounded={ false }\n\t\t>\n\t\t\t<CardBody>\n\t\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t\t<Card className=\"edit-site-global-styles-screen-root__active-style-tile\">\n\t\t\t\t\t\t<CardMedia className=\"edit-site-global-styles-screen-root__active-style-tile-preview\">\n\t\t\t\t\t\t\t<PreviewStyles />\n\t\t\t\t\t\t</CardMedia>\n\t\t\t\t\t</Card>\n\t\t\t\t\t{ hasVariations && (\n\t\t\t\t\t\t<ItemGroup>\n\t\t\t\t\t\t\t<NavigationButtonAsItem path=\"/variations\">\n\t\t\t\t\t\t\t\t<HStack justify=\"space-between\">\n\t\t\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Browse styles' ) }\n\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t<IconWithCurrentColor\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\tisRTL() ? chevronLeft : chevronRight\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</HStack>\n\t\t\t\t\t\t\t</NavigationButtonAsItem>\n\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t) }\n\t\t\t\t\t<RootMenu />\n\t\t\t\t</VStack>\n\t\t\t</CardBody>\n\n\t\t\t<CardDivider />\n\n\t\t\t<CardBody>\n\t\t\t\t<Spacer\n\t\t\t\t\tas=\"p\"\n\t\t\t\t\tpaddingTop={ 2 }\n\t\t\t\t\t/*\n\t\t\t\t\t * 13px matches the text inset of the NavigationButton (12px padding, plus the width of the button's border).\n\t\t\t\t\t * This is an ad hoc override for this instance and the Additional CSS option below. Other options for matching the\n\t\t\t\t\t * the nav button inset should be looked at before reusing further.\n\t\t\t\t\t */\n\t\t\t\t\tpaddingX=\"13px\"\n\t\t\t\t\tmarginBottom={ 2 }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Customize the appearance of specific blocks for the whole site.'\n\t\t\t\t\t) }\n\t\t\t\t</Spacer>\n\t\t\t\t<ItemGroup>\n\t\t\t\t\t<NavigationButtonAsItem path=\"/blocks\">\n\t\t\t\t\t\t<HStack justify=\"space-between\">\n\t\t\t\t\t\t\t<FlexItem>{ __( 'Blocks' ) }</FlexItem>\n\t\t\t\t\t\t\t<IconWithCurrentColor\n\t\t\t\t\t\t\t\ticon={ isRTL() ? chevronLeft : chevronRight }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</NavigationButtonAsItem>\n\t\t\t\t</ItemGroup>\n\t\t\t</CardBody>\n\t\t</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AC1B,WAAA,CAAAgC,uBAAS;QAAAP,QAAA,eACT,IAAAd,WAAA,CAAAe,GAAA,EAACnB,iBAAA,CAAA0B,sBAAsB;UAACC,IAAI,EAAC,SAAS;UAAAT,QAAA,eACrC,IAAAd,WAAA,CAAAQ,IAAA,EAACnB,WAAA,CAAAmC,oBAAM;YAACC,OAAO,EAAC,eAAe;YAAAX,QAAA,gBAC9B,IAAAd,WAAA,CAAAe,GAAA,EAAC1B,WAAA,CAAAqC,QAAQ;cAAAZ,QAAA,EAAG,IAAAa,QAAE,EAAE,QAAS;YAAC,CAAY,CAAC,eACvC,IAAA3B,WAAA,CAAAe,GAAA,EAACpB,qBAAA,CAAAiC,oBAAoB;cACpBC,IAAI,EAAG,IAAAC,WAAK,EAAC,CAAC,GAAGC,kBAAW,GAAGC;YAAc,CAC7C,CAAC;UAAA,CACK;QAAC,CACc;MAAC,CACf,CAAC;IAAA,CACH,CAAC;EAAA,CACN,CAAC;AAET;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAApB,OAAA,GAEcnB,UAAU","ignoreList":[]}
|
|
@@ -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,CAACO,OAAO,CAACC,GAAI,CAAC;EACjC,CAAC,EAAE,CAAER,IAAI,CAACO,OAAO,CAACC,GAAG,CAAG,CAAC;EAEzB,MAAMC,OAAO,GAAG,CAAEL,MAAM,EAAEM,MAAM;EAChC;EACA;EACA;EACA;EACA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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;AAAgC,CAAC,GAAG,IAAAJ,kBAAM,EAAEK,qBAAgB,CAAC;AAErE,SAASC,0BAA0BA,CAAA,EAAG;EACrC,MAAMC,oBAAoB,GAAG,IAAAC,8BAAuB,EAAC,CAAC;EACtD,MAAM;IAAEC,OAAO,EAAEC;E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E,QAAS,CAAC;EACrBM,EAAE,EAAE,QAAQ;EACZ2B,QAAQ,EAAEA,CAAE;IAAEnD;EAAK,CAAC,KAAMA,IAAI,CAACwD,SAAS;EACxC/B,MAAM,EAAE,SAASgC,MAAMA,CAAE;IAAEzD;EAAK,CAAC,EAAG;IACnC,MAAM0D,QAAQ,GAAG1D,IAAI,CAACwD,SAAS;IAC/B,oBACC,IAAA/E,WAAA,CAAAkC,GAAA,EAAC9B,KAAK;MAAC8E,MAAM,EAAGD,QAAQ,GAAG,SAAS,GAAG,SAAW;MAAA5C,QAAA,EAC/C4C,QAAQ,GAAG,IAAAxC,QAAE,EAAE,QAAS,CAAC,GAAG,IAAAA,QAAE,EAAE,UAAW;IAAC,CACxC,CAAC;EAEV;AACD,CAAC;AAEM,MAAM0C,SAAS,GAAAtC,OAAA,CAAAsC,SAAA,GAAG;EACxBrC,KAAK,EAAE,IAAAL,QAAE,EAAE,eAAgB,CAAC;EAC5BM,EAAE,EAAE,MAAM;EACV2B,QAAQ,EAAEA,CAAE;IAAEnD;EAAK,CAAC,KAAMA,IAAI,CAACL,IAAI;EACnC8B,MAAM,EAAE,SAASgC,MAAMA,CAAE;IAAEzD;EAAK,CAAC,EAAG;IACnC,MAAMd,oBAAoB,GAAGD,0BAA0B,CAAC,CAAC;IACzD,MAAM4C,mBAAmB,GAAG3C,oBAAoB,CAAC4C,IAAI,CAClDC,IAAI,IAAMA,IAAI,CAACpC,IAAI,KAAKK,IAAI,CAACL,IAChC,CAAC;IACD,OACCkC,mBAAmB,EAAEjC,KAAK;IAC1B;IACA,IAAAsB,QAAE,EAAE,QAAS,CAAC;EAEhB;AACD,CAAC","ignoreList":[]}
|
|
@@ -80,7 +80,7 @@ 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\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}\n\t\t},\n\t\t[ postType, postId ]\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA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AU,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
|