@wordpress/edit-site 4.9.0 → 4.10.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-generic-template-modal.js +84 -0
- package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build/components/add-new-template/add-custom-template-modal.js +92 -53
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build/components/add-new-template/new-template.js +77 -81
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +310 -44
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/code-editor/index.js +17 -4
- package/build/components/code-editor/index.js.map +1 -1
- package/build/components/editor/index.js +16 -0
- package/build/components/editor/index.js.map +1 -1
- package/build/components/error-boundary/index.js +6 -0
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +2 -6
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +4 -2
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/hooks.js +10 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/screen-color-palette.js +13 -17
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +9 -1
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-link-color.js +48 -14
- package/build/components/global-styles/screen-link-color.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +171 -33
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/template-details/edit-template-title.js +11 -3
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +1 -20
- package/build/components/template-details/index.js.map +1 -1
- package/build/store/selectors.js +4 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js +92 -53
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +80 -83
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +286 -40
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/code-editor/index.js +18 -5
- package/build-module/components/code-editor/index.js.map +1 -1
- package/build-module/components/editor/index.js +16 -0
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +5 -0
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +2 -6
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +4 -2
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +10 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/screen-color-palette.js +14 -19
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +9 -1
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-link-color.js +47 -14
- package/build-module/components/global-styles/screen-link-color.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +171 -35
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -2
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/template-details/edit-template-title.js +12 -3
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +2 -21
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/store/selectors.js +5 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +21 -23
- package/build-style/style.css +21 -23
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
- package/src/components/add-new-template/add-custom-template-modal.js +92 -58
- package/src/components/add-new-template/new-template.js +142 -94
- package/src/components/add-new-template/style.scss +21 -0
- package/src/components/add-new-template/utils.js +290 -46
- package/src/components/code-editor/index.js +15 -5
- package/src/components/editor/index.js +11 -0
- package/src/components/error-boundary/index.js +5 -0
- package/src/components/global-styles/dimensions-panel.js +2 -7
- package/src/components/global-styles/global-styles-provider.js +8 -9
- package/src/components/global-styles/hooks.js +15 -0
- package/src/components/global-styles/screen-color-palette.js +25 -27
- package/src/components/global-styles/screen-colors.js +9 -3
- package/src/components/global-styles/screen-link-color.js +65 -23
- package/src/components/global-styles/style.scss +7 -11
- package/src/components/global-styles/test/use-global-styles-output.js +168 -0
- package/src/components/global-styles/use-global-styles-output.js +234 -59
- package/src/components/global-styles/utils.js +2 -2
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
- package/src/components/list/style.scss +0 -8
- package/src/components/template-details/edit-template-title.js +10 -2
- package/src/components/template-details/index.js +4 -21
- package/src/components/test/error-boundary.js +38 -0
- package/src/store/selectors.js +11 -5
|
@@ -468,9 +468,6 @@ body.is-fullscreen-mode .interface-interface-skeleton {
|
|
|
468
468
|
.interface-preferences-modal .components-modal__content {
|
|
469
469
|
padding: 0;
|
|
470
470
|
}
|
|
471
|
-
.interface-preferences-modal .components-modal__content::before {
|
|
472
|
-
content: none;
|
|
473
|
-
}
|
|
474
471
|
}
|
|
475
472
|
|
|
476
473
|
.interface-preferences__tabs .components-tab-panel__tabs {
|
|
@@ -767,19 +764,13 @@ textarea.edit-site-code-editor-text-area.edit-site-code-editor-text-area:-ms-inp
|
|
|
767
764
|
margin: 0;
|
|
768
765
|
}
|
|
769
766
|
|
|
770
|
-
.edit-site-screen-color-palette-toggle.edit-site-screen-color-palette-toggle {
|
|
771
|
-
margin-left: 16px;
|
|
772
|
-
margin-right: 16px;
|
|
773
|
-
width: unset;
|
|
774
|
-
}
|
|
775
|
-
.edit-site-screen-color-palette-toggle.edit-site-screen-color-palette-toggle .components-toggle-group-control {
|
|
776
|
-
min-height: 32px;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
767
|
.edit-site-screen-text-color__control,
|
|
780
768
|
.edit-site-screen-link-color__control,
|
|
781
|
-
.edit-site-screen-button-color__control
|
|
782
|
-
|
|
769
|
+
.edit-site-screen-button-color__control {
|
|
770
|
+
padding: 16px;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
.edit-site-screen-background-color__control .block-editor-color-gradient-control__tab-panel {
|
|
783
774
|
padding: 16px;
|
|
784
775
|
}
|
|
785
776
|
|
|
@@ -1430,12 +1421,6 @@ body.is-fullscreen-mode .edit-site-list-header {
|
|
|
1430
1421
|
width: 320px;
|
|
1431
1422
|
}
|
|
1432
1423
|
}
|
|
1433
|
-
.edit-site-list__rename-modal .components-modal__header {
|
|
1434
|
-
border-bottom: none;
|
|
1435
|
-
}
|
|
1436
|
-
.edit-site-list__rename-modal .components-modal__content::before {
|
|
1437
|
-
margin-bottom: 4px;
|
|
1438
|
-
}
|
|
1439
1424
|
|
|
1440
1425
|
.edit-site-list__rename-modal-actions {
|
|
1441
1426
|
margin-top: 12px;
|
|
@@ -1601,6 +1586,22 @@ body.is-fullscreen-mode .edit-site-list-header {
|
|
|
1601
1586
|
margin-top: 16px;
|
|
1602
1587
|
}
|
|
1603
1588
|
|
|
1589
|
+
@media (min-width: 782px) {
|
|
1590
|
+
.edit-site-custom-generic-template__modal .components-base-control {
|
|
1591
|
+
width: 320px;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
.edit-site-custom-generic-template__modal .components-modal__header {
|
|
1595
|
+
border-bottom: none;
|
|
1596
|
+
}
|
|
1597
|
+
.edit-site-custom-generic-template__modal .components-modal__content::before {
|
|
1598
|
+
margin-bottom: 4px;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
.edit-site-custom-generic-template__modal-actions {
|
|
1602
|
+
margin-top: 12px;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1604
1605
|
.edit-site-sidebar {
|
|
1605
1606
|
width: 280px;
|
|
1606
1607
|
}
|
|
@@ -2138,9 +2139,6 @@ body.is-fullscreen-mode .edit-site .components-editor-notices__snackbar {
|
|
|
2138
2139
|
.edit-site-keyboard-shortcut-help-modal__section {
|
|
2139
2140
|
margin: 0 0 2rem 0;
|
|
2140
2141
|
}
|
|
2141
|
-
.edit-site-keyboard-shortcut-help-modal__main-shortcuts .edit-site-keyboard-shortcut-help-modal__shortcut-list {
|
|
2142
|
-
margin-top: -25px;
|
|
2143
|
-
}
|
|
2144
2142
|
.edit-site-keyboard-shortcut-help-modal__section-title {
|
|
2145
2143
|
font-size: 0.9rem;
|
|
2146
2144
|
font-weight: 600;
|
package/build-style/style.css
CHANGED
|
@@ -468,9 +468,6 @@ body.is-fullscreen-mode .interface-interface-skeleton {
|
|
|
468
468
|
.interface-preferences-modal .components-modal__content {
|
|
469
469
|
padding: 0;
|
|
470
470
|
}
|
|
471
|
-
.interface-preferences-modal .components-modal__content::before {
|
|
472
|
-
content: none;
|
|
473
|
-
}
|
|
474
471
|
}
|
|
475
472
|
|
|
476
473
|
.interface-preferences__tabs .components-tab-panel__tabs {
|
|
@@ -767,19 +764,13 @@ textarea.edit-site-code-editor-text-area.edit-site-code-editor-text-area:-ms-inp
|
|
|
767
764
|
margin: 0;
|
|
768
765
|
}
|
|
769
766
|
|
|
770
|
-
.edit-site-screen-color-palette-toggle.edit-site-screen-color-palette-toggle {
|
|
771
|
-
margin-right: 16px;
|
|
772
|
-
margin-left: 16px;
|
|
773
|
-
width: unset;
|
|
774
|
-
}
|
|
775
|
-
.edit-site-screen-color-palette-toggle.edit-site-screen-color-palette-toggle .components-toggle-group-control {
|
|
776
|
-
min-height: 32px;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
767
|
.edit-site-screen-text-color__control,
|
|
780
768
|
.edit-site-screen-link-color__control,
|
|
781
|
-
.edit-site-screen-button-color__control
|
|
782
|
-
|
|
769
|
+
.edit-site-screen-button-color__control {
|
|
770
|
+
padding: 16px;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
.edit-site-screen-background-color__control .block-editor-color-gradient-control__tab-panel {
|
|
783
774
|
padding: 16px;
|
|
784
775
|
}
|
|
785
776
|
|
|
@@ -1430,12 +1421,6 @@ body.is-fullscreen-mode .edit-site-list-header {
|
|
|
1430
1421
|
width: 320px;
|
|
1431
1422
|
}
|
|
1432
1423
|
}
|
|
1433
|
-
.edit-site-list__rename-modal .components-modal__header {
|
|
1434
|
-
border-bottom: none;
|
|
1435
|
-
}
|
|
1436
|
-
.edit-site-list__rename-modal .components-modal__content::before {
|
|
1437
|
-
margin-bottom: 4px;
|
|
1438
|
-
}
|
|
1439
1424
|
|
|
1440
1425
|
.edit-site-list__rename-modal-actions {
|
|
1441
1426
|
margin-top: 12px;
|
|
@@ -1601,6 +1586,22 @@ body.is-fullscreen-mode .edit-site-list-header {
|
|
|
1601
1586
|
margin-top: 16px;
|
|
1602
1587
|
}
|
|
1603
1588
|
|
|
1589
|
+
@media (min-width: 782px) {
|
|
1590
|
+
.edit-site-custom-generic-template__modal .components-base-control {
|
|
1591
|
+
width: 320px;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
.edit-site-custom-generic-template__modal .components-modal__header {
|
|
1595
|
+
border-bottom: none;
|
|
1596
|
+
}
|
|
1597
|
+
.edit-site-custom-generic-template__modal .components-modal__content::before {
|
|
1598
|
+
margin-bottom: 4px;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
.edit-site-custom-generic-template__modal-actions {
|
|
1602
|
+
margin-top: 12px;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1604
1605
|
.edit-site-sidebar {
|
|
1605
1606
|
width: 280px;
|
|
1606
1607
|
}
|
|
@@ -2138,9 +2139,6 @@ body.is-fullscreen-mode .edit-site .components-editor-notices__snackbar {
|
|
|
2138
2139
|
.edit-site-keyboard-shortcut-help-modal__section {
|
|
2139
2140
|
margin: 0 0 2rem 0;
|
|
2140
2141
|
}
|
|
2141
|
-
.edit-site-keyboard-shortcut-help-modal__main-shortcuts .edit-site-keyboard-shortcut-help-modal__shortcut-list {
|
|
2142
|
-
margin-top: -25px;
|
|
2143
|
-
}
|
|
2144
2142
|
.edit-site-keyboard-shortcut-help-modal__section-title {
|
|
2145
2143
|
font-size: 0.9rem;
|
|
2146
2144
|
font-weight: 600;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-site",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "Edit Site Page module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,33 +27,33 @@
|
|
|
27
27
|
"react-native": "src/index",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.16.0",
|
|
30
|
-
"@wordpress/a11y": "^3.
|
|
31
|
-
"@wordpress/api-fetch": "^6.
|
|
32
|
-
"@wordpress/block-editor": "^9.
|
|
33
|
-
"@wordpress/block-library": "^7.
|
|
34
|
-
"@wordpress/blocks": "^11.
|
|
35
|
-
"@wordpress/components": "^19.
|
|
36
|
-
"@wordpress/compose": "^5.
|
|
37
|
-
"@wordpress/core-data": "^4.
|
|
38
|
-
"@wordpress/data": "^6.
|
|
39
|
-
"@wordpress/deprecated": "^3.
|
|
40
|
-
"@wordpress/editor": "^12.
|
|
41
|
-
"@wordpress/element": "^4.
|
|
42
|
-
"@wordpress/hooks": "^3.
|
|
43
|
-
"@wordpress/html-entities": "^3.
|
|
44
|
-
"@wordpress/i18n": "^4.
|
|
45
|
-
"@wordpress/icons": "^9.
|
|
46
|
-
"@wordpress/interface": "^4.
|
|
47
|
-
"@wordpress/keyboard-shortcuts": "^3.
|
|
48
|
-
"@wordpress/keycodes": "^3.
|
|
49
|
-
"@wordpress/media-utils": "^4.
|
|
50
|
-
"@wordpress/notices": "^3.
|
|
51
|
-
"@wordpress/plugins": "^4.
|
|
52
|
-
"@wordpress/preferences": "^2.
|
|
53
|
-
"@wordpress/reusable-blocks": "^3.
|
|
54
|
-
"@wordpress/style-engine": "^0.
|
|
55
|
-
"@wordpress/url": "^3.
|
|
56
|
-
"@wordpress/viewport": "^4.
|
|
30
|
+
"@wordpress/a11y": "^3.13.0",
|
|
31
|
+
"@wordpress/api-fetch": "^6.10.0",
|
|
32
|
+
"@wordpress/block-editor": "^9.5.0",
|
|
33
|
+
"@wordpress/block-library": "^7.10.0",
|
|
34
|
+
"@wordpress/blocks": "^11.12.0",
|
|
35
|
+
"@wordpress/components": "^19.15.0",
|
|
36
|
+
"@wordpress/compose": "^5.11.0",
|
|
37
|
+
"@wordpress/core-data": "^4.11.0",
|
|
38
|
+
"@wordpress/data": "^6.13.0",
|
|
39
|
+
"@wordpress/deprecated": "^3.13.0",
|
|
40
|
+
"@wordpress/editor": "^12.12.0",
|
|
41
|
+
"@wordpress/element": "^4.11.0",
|
|
42
|
+
"@wordpress/hooks": "^3.13.0",
|
|
43
|
+
"@wordpress/html-entities": "^3.13.0",
|
|
44
|
+
"@wordpress/i18n": "^4.13.0",
|
|
45
|
+
"@wordpress/icons": "^9.4.0",
|
|
46
|
+
"@wordpress/interface": "^4.12.0",
|
|
47
|
+
"@wordpress/keyboard-shortcuts": "^3.11.0",
|
|
48
|
+
"@wordpress/keycodes": "^3.13.0",
|
|
49
|
+
"@wordpress/media-utils": "^4.4.0",
|
|
50
|
+
"@wordpress/notices": "^3.13.0",
|
|
51
|
+
"@wordpress/plugins": "^4.11.0",
|
|
52
|
+
"@wordpress/preferences": "^2.5.0",
|
|
53
|
+
"@wordpress/reusable-blocks": "^3.11.0",
|
|
54
|
+
"@wordpress/style-engine": "^0.12.0",
|
|
55
|
+
"@wordpress/url": "^3.14.0",
|
|
56
|
+
"@wordpress/viewport": "^4.11.0",
|
|
57
57
|
"classnames": "^2.3.1",
|
|
58
58
|
"downloadjs": "^1.4.7",
|
|
59
59
|
"history": "^5.1.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9d9d33bbdf317a4381b8ca1713e43bb50df653b3"
|
|
72
72
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { kebabCase } from 'lodash';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import { __ } from '@wordpress/i18n';
|
|
11
|
+
import {
|
|
12
|
+
Button,
|
|
13
|
+
Flex,
|
|
14
|
+
FlexItem,
|
|
15
|
+
Modal,
|
|
16
|
+
TextControl,
|
|
17
|
+
} from '@wordpress/components';
|
|
18
|
+
|
|
19
|
+
function AddCustomGenericTemplateModal( { onClose, createTemplate } ) {
|
|
20
|
+
const [ title, setTitle ] = useState( '' );
|
|
21
|
+
const defaultTitle = __( 'Custom Template' );
|
|
22
|
+
const [ isBusy, setIsBusy ] = useState( false );
|
|
23
|
+
async function onCreateTemplate( event ) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
|
|
26
|
+
if ( isBusy ) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setIsBusy( true );
|
|
31
|
+
|
|
32
|
+
createTemplate(
|
|
33
|
+
{
|
|
34
|
+
slug:
|
|
35
|
+
'wp-custom-template-' + kebabCase( title || defaultTitle ),
|
|
36
|
+
title: title || defaultTitle,
|
|
37
|
+
},
|
|
38
|
+
false
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return (
|
|
42
|
+
<Modal
|
|
43
|
+
title={ __( 'Create custom template' ) }
|
|
44
|
+
closeLabel={ __( 'Close' ) }
|
|
45
|
+
onRequestClose={ () => {
|
|
46
|
+
onClose();
|
|
47
|
+
} }
|
|
48
|
+
overlayClassName="edit-site-custom-generic-template__modal"
|
|
49
|
+
>
|
|
50
|
+
<form onSubmit={ onCreateTemplate }>
|
|
51
|
+
<Flex align="flex-start" gap={ 8 }>
|
|
52
|
+
<FlexItem>
|
|
53
|
+
<TextControl
|
|
54
|
+
label={ __( 'Name' ) }
|
|
55
|
+
value={ title }
|
|
56
|
+
onChange={ setTitle }
|
|
57
|
+
placeholder={ defaultTitle }
|
|
58
|
+
disabled={ isBusy }
|
|
59
|
+
help={ __(
|
|
60
|
+
'Describe the template, e.g. "Post with sidebar".'
|
|
61
|
+
) }
|
|
62
|
+
/>
|
|
63
|
+
</FlexItem>
|
|
64
|
+
</Flex>
|
|
65
|
+
|
|
66
|
+
<Flex
|
|
67
|
+
className="edit-site-custom-generic-template__modal-actions"
|
|
68
|
+
justify="flex-end"
|
|
69
|
+
expanded={ false }
|
|
70
|
+
>
|
|
71
|
+
<FlexItem>
|
|
72
|
+
<Button
|
|
73
|
+
variant="tertiary"
|
|
74
|
+
onClick={ () => {
|
|
75
|
+
onClose();
|
|
76
|
+
} }
|
|
77
|
+
>
|
|
78
|
+
{ __( 'Cancel' ) }
|
|
79
|
+
</Button>
|
|
80
|
+
</FlexItem>
|
|
81
|
+
<FlexItem>
|
|
82
|
+
<Button
|
|
83
|
+
variant="primary"
|
|
84
|
+
type="submit"
|
|
85
|
+
isBusy={ isBusy }
|
|
86
|
+
aria-disabled={ isBusy }
|
|
87
|
+
>
|
|
88
|
+
{ __( 'Create' ) }
|
|
89
|
+
</Button>
|
|
90
|
+
</FlexItem>
|
|
91
|
+
</Flex>
|
|
92
|
+
</form>
|
|
93
|
+
</Modal>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default AddCustomGenericTemplateModal;
|
|
@@ -25,11 +25,34 @@ import { useEntityRecords } from '@wordpress/core-data';
|
|
|
25
25
|
import { mapToIHasNameAndId } from './utils';
|
|
26
26
|
|
|
27
27
|
const EMPTY_ARRAY = [];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
|
|
29
|
+
function selectSuggestion( suggestion, onSelect, entityForSuggestions ) {
|
|
30
|
+
const {
|
|
31
|
+
labels,
|
|
32
|
+
slug,
|
|
33
|
+
config: { templateSlug, templatePrefix },
|
|
34
|
+
} = entityForSuggestions;
|
|
35
|
+
const title = sprintf(
|
|
36
|
+
// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type or taxonomy and %2$s is the name of the post or term, e.g. "Post: Hello, WordPress", "Category: shoes"
|
|
37
|
+
__( '%1$s: %2$s' ),
|
|
38
|
+
labels.singular_name,
|
|
39
|
+
suggestion.name
|
|
40
|
+
);
|
|
41
|
+
let newTemplateSlug = `${ templateSlug || slug }-${ suggestion.slug }`;
|
|
42
|
+
if ( templatePrefix ) {
|
|
43
|
+
newTemplateSlug = templatePrefix + newTemplateSlug;
|
|
44
|
+
}
|
|
45
|
+
const newTemplate = {
|
|
46
|
+
title,
|
|
47
|
+
description: sprintf(
|
|
48
|
+
// translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Post: Hello, WordPress"
|
|
49
|
+
__( 'Template for %1$s' ),
|
|
50
|
+
title
|
|
51
|
+
),
|
|
52
|
+
slug: newTemplateSlug,
|
|
53
|
+
};
|
|
54
|
+
onSelect( newTemplate );
|
|
55
|
+
}
|
|
33
56
|
|
|
34
57
|
function SuggestionListItem( {
|
|
35
58
|
suggestion,
|
|
@@ -46,23 +69,9 @@ function SuggestionListItem( {
|
|
|
46
69
|
as={ Button }
|
|
47
70
|
{ ...composite }
|
|
48
71
|
className={ baseCssClass }
|
|
49
|
-
onClick={ () =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
__( '%1$s: %2$s' ),
|
|
53
|
-
entityForSuggestions.labels.singular_name,
|
|
54
|
-
suggestion.name
|
|
55
|
-
);
|
|
56
|
-
onSelect( {
|
|
57
|
-
title,
|
|
58
|
-
description: sprintf(
|
|
59
|
-
// translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Post: Hello, WordPress"
|
|
60
|
-
__( 'Template for %1$s' ),
|
|
61
|
-
title
|
|
62
|
-
),
|
|
63
|
-
slug: `single-${ entityForSuggestions.slug }-${ suggestion.slug }`,
|
|
64
|
-
} );
|
|
65
|
-
} }
|
|
72
|
+
onClick={ () =>
|
|
73
|
+
selectSuggestion( suggestion, onSelect, entityForSuggestions )
|
|
74
|
+
}
|
|
66
75
|
>
|
|
67
76
|
<span className={ `${ baseCssClass }__title` }>
|
|
68
77
|
<TextHighlight text={ suggestion.name } highlight={ search } />
|
|
@@ -76,48 +85,73 @@ function SuggestionListItem( {
|
|
|
76
85
|
);
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
const [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
function useDebouncedInput() {
|
|
89
|
+
const [ input, setInput ] = useState( '' );
|
|
90
|
+
const [ debounced, setter ] = useState( '' );
|
|
91
|
+
const setDebounced = useDebounce( setter, 250 );
|
|
92
|
+
useEffect( () => {
|
|
93
|
+
if ( debounced !== input ) {
|
|
94
|
+
setDebounced( input );
|
|
95
|
+
}
|
|
96
|
+
}, [ debounced, input ] );
|
|
97
|
+
return [ input, setInput, debounced ];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function useSearchSuggestions( entityForSuggestions, search ) {
|
|
101
|
+
const { config, postsToExclude } = entityForSuggestions;
|
|
102
|
+
const query = useMemo(
|
|
103
|
+
() => ( {
|
|
104
|
+
order: 'asc',
|
|
105
|
+
_fields: 'id,name,title,slug,link',
|
|
106
|
+
context: 'view',
|
|
107
|
+
search,
|
|
108
|
+
orderBy: config.getOrderBy( { search } ),
|
|
109
|
+
exclude: postsToExclude,
|
|
110
|
+
per_page: search ? 20 : 10,
|
|
111
|
+
} ),
|
|
112
|
+
[ search, config, postsToExclude ]
|
|
113
|
+
);
|
|
94
114
|
const { records: searchResults, hasResolved: searchHasResolved } =
|
|
95
115
|
useEntityRecords(
|
|
96
116
|
entityForSuggestions.type,
|
|
97
117
|
entityForSuggestions.slug,
|
|
98
118
|
query
|
|
99
119
|
);
|
|
100
|
-
|
|
101
|
-
if ( search !== searchInputValue ) {
|
|
102
|
-
debouncedSearch( searchInputValue );
|
|
103
|
-
}
|
|
104
|
-
}, [ search, searchInputValue ] );
|
|
105
|
-
const entitiesInfo = useMemo( () => {
|
|
106
|
-
if ( ! searchResults?.length ) return EMPTY_ARRAY;
|
|
107
|
-
return mapToIHasNameAndId( searchResults, 'title.rendered' );
|
|
108
|
-
}, [ searchResults ] );
|
|
109
|
-
// Update suggestions only when the query has resolved.
|
|
120
|
+
const [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );
|
|
110
121
|
useEffect( () => {
|
|
111
122
|
if ( ! searchHasResolved ) return;
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
let newSuggestions = EMPTY_ARRAY;
|
|
124
|
+
if ( searchResults?.length ) {
|
|
125
|
+
newSuggestions = searchResults;
|
|
126
|
+
if ( config.recordNamePath ) {
|
|
127
|
+
newSuggestions = mapToIHasNameAndId(
|
|
128
|
+
newSuggestions,
|
|
129
|
+
config.recordNamePath
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Update suggestions only when the query has resolved, so as to keep
|
|
134
|
+
// the previous results in the UI.
|
|
135
|
+
setSuggestions( newSuggestions );
|
|
136
|
+
}, [ searchResults, searchHasResolved ] );
|
|
137
|
+
return suggestions;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function SuggestionList( { entityForSuggestions, onSelect } ) {
|
|
141
|
+
const composite = useCompositeState( { orientation: 'vertical' } );
|
|
142
|
+
const [ search, setSearch, debouncedSearch ] = useDebouncedInput();
|
|
143
|
+
const suggestions = useSearchSuggestions(
|
|
144
|
+
entityForSuggestions,
|
|
145
|
+
debouncedSearch
|
|
146
|
+
);
|
|
147
|
+
const { labels } = entityForSuggestions;
|
|
114
148
|
return (
|
|
115
149
|
<>
|
|
116
150
|
<SearchControl
|
|
117
|
-
onChange={
|
|
118
|
-
value={
|
|
119
|
-
label={
|
|
120
|
-
placeholder={
|
|
151
|
+
onChange={ setSearch }
|
|
152
|
+
value={ search }
|
|
153
|
+
label={ labels.search_items }
|
|
154
|
+
placeholder={ labels.search_items }
|
|
121
155
|
/>
|
|
122
156
|
{ !! suggestions?.length && (
|
|
123
157
|
<Composite
|
|
@@ -129,7 +163,7 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
|
|
|
129
163
|
<SuggestionListItem
|
|
130
164
|
key={ suggestion.slug }
|
|
131
165
|
suggestion={ suggestion }
|
|
132
|
-
search={
|
|
166
|
+
search={ debouncedSearch }
|
|
133
167
|
onSelect={ onSelect }
|
|
134
168
|
entityForSuggestions={ entityForSuggestions }
|
|
135
169
|
composite={ composite }
|
|
@@ -137,9 +171,9 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
|
|
|
137
171
|
) ) }
|
|
138
172
|
</Composite>
|
|
139
173
|
) }
|
|
140
|
-
{
|
|
174
|
+
{ debouncedSearch && ! suggestions?.length && (
|
|
141
175
|
<p className="edit-site-custom-template-modal__no-results">
|
|
142
|
-
{
|
|
176
|
+
{ labels.not_found }
|
|
143
177
|
</p>
|
|
144
178
|
) }
|
|
145
179
|
</>
|
|
@@ -187,7 +221,7 @@ function AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {
|
|
|
187
221
|
</Heading>
|
|
188
222
|
<Text as="span">
|
|
189
223
|
{
|
|
190
|
-
// translators: The user is given the choice to set up a template for all items of a post type, or just a specific one.
|
|
224
|
+
// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
|
|
191
225
|
__( 'For all items' )
|
|
192
226
|
}
|
|
193
227
|
</Text>
|
|
@@ -203,7 +237,7 @@ function AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {
|
|
|
203
237
|
</Heading>
|
|
204
238
|
<Text as="span">
|
|
205
239
|
{
|
|
206
|
-
// translators: The user is given the choice to set up a template for all items of a post type, or just a specific one.
|
|
240
|
+
// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
|
|
207
241
|
__( 'For a specific item' )
|
|
208
242
|
}
|
|
209
243
|
</Text>
|