@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
  3. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  4. package/build/components/add-new-template/add-custom-template-modal.js +92 -53
  5. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  6. package/build/components/add-new-template/new-template.js +77 -81
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/add-new-template/utils.js +310 -44
  9. package/build/components/add-new-template/utils.js.map +1 -1
  10. package/build/components/code-editor/index.js +17 -4
  11. package/build/components/code-editor/index.js.map +1 -1
  12. package/build/components/editor/index.js +16 -0
  13. package/build/components/editor/index.js.map +1 -1
  14. package/build/components/error-boundary/index.js +6 -0
  15. package/build/components/error-boundary/index.js.map +1 -1
  16. package/build/components/global-styles/dimensions-panel.js +2 -6
  17. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  18. package/build/components/global-styles/global-styles-provider.js +4 -2
  19. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  20. package/build/components/global-styles/hooks.js +10 -1
  21. package/build/components/global-styles/hooks.js.map +1 -1
  22. package/build/components/global-styles/screen-color-palette.js +13 -17
  23. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  24. package/build/components/global-styles/screen-colors.js +9 -1
  25. package/build/components/global-styles/screen-colors.js.map +1 -1
  26. package/build/components/global-styles/screen-link-color.js +48 -14
  27. package/build/components/global-styles/screen-link-color.js.map +1 -1
  28. package/build/components/global-styles/use-global-styles-output.js +171 -33
  29. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  30. package/build/components/global-styles/utils.js +1 -1
  31. package/build/components/global-styles/utils.js.map +1 -1
  32. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  33. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  34. package/build/components/template-details/edit-template-title.js +11 -3
  35. package/build/components/template-details/edit-template-title.js.map +1 -1
  36. package/build/components/template-details/index.js +1 -20
  37. package/build/components/template-details/index.js.map +1 -1
  38. package/build/store/selectors.js +4 -1
  39. package/build/store/selectors.js.map +1 -1
  40. package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
  41. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  42. package/build-module/components/add-new-template/add-custom-template-modal.js +92 -53
  43. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  44. package/build-module/components/add-new-template/new-template.js +80 -83
  45. package/build-module/components/add-new-template/new-template.js.map +1 -1
  46. package/build-module/components/add-new-template/utils.js +286 -40
  47. package/build-module/components/add-new-template/utils.js.map +1 -1
  48. package/build-module/components/code-editor/index.js +18 -5
  49. package/build-module/components/code-editor/index.js.map +1 -1
  50. package/build-module/components/editor/index.js +16 -0
  51. package/build-module/components/editor/index.js.map +1 -1
  52. package/build-module/components/error-boundary/index.js +5 -0
  53. package/build-module/components/error-boundary/index.js.map +1 -1
  54. package/build-module/components/global-styles/dimensions-panel.js +2 -6
  55. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  56. package/build-module/components/global-styles/global-styles-provider.js +4 -2
  57. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  58. package/build-module/components/global-styles/hooks.js +10 -1
  59. package/build-module/components/global-styles/hooks.js.map +1 -1
  60. package/build-module/components/global-styles/screen-color-palette.js +14 -19
  61. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  62. package/build-module/components/global-styles/screen-colors.js +9 -1
  63. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  64. package/build-module/components/global-styles/screen-link-color.js +47 -14
  65. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  66. package/build-module/components/global-styles/use-global-styles-output.js +171 -35
  67. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  68. package/build-module/components/global-styles/utils.js +2 -2
  69. package/build-module/components/global-styles/utils.js.map +1 -1
  70. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
  71. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  72. package/build-module/components/template-details/edit-template-title.js +12 -3
  73. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  74. package/build-module/components/template-details/index.js +2 -21
  75. package/build-module/components/template-details/index.js.map +1 -1
  76. package/build-module/store/selectors.js +5 -2
  77. package/build-module/store/selectors.js.map +1 -1
  78. package/build-style/style-rtl.css +21 -23
  79. package/build-style/style.css +21 -23
  80. package/package.json +29 -29
  81. package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
  82. package/src/components/add-new-template/add-custom-template-modal.js +92 -58
  83. package/src/components/add-new-template/new-template.js +142 -94
  84. package/src/components/add-new-template/style.scss +21 -0
  85. package/src/components/add-new-template/utils.js +290 -46
  86. package/src/components/code-editor/index.js +15 -5
  87. package/src/components/editor/index.js +11 -0
  88. package/src/components/error-boundary/index.js +5 -0
  89. package/src/components/global-styles/dimensions-panel.js +2 -7
  90. package/src/components/global-styles/global-styles-provider.js +8 -9
  91. package/src/components/global-styles/hooks.js +15 -0
  92. package/src/components/global-styles/screen-color-palette.js +25 -27
  93. package/src/components/global-styles/screen-colors.js +9 -3
  94. package/src/components/global-styles/screen-link-color.js +65 -23
  95. package/src/components/global-styles/style.scss +7 -11
  96. package/src/components/global-styles/test/use-global-styles-output.js +168 -0
  97. package/src/components/global-styles/use-global-styles-output.js +234 -59
  98. package/src/components/global-styles/utils.js +2 -2
  99. package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
  100. package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
  101. package/src/components/list/style.scss +0 -8
  102. package/src/components/template-details/edit-template-title.js +10 -2
  103. package/src/components/template-details/index.js +4 -21
  104. package/src/components/test/error-boundary.js +38 -0
  105. package/src/store/selectors.js +11 -5
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';
6
-
6
+ import { TabPanel } from '@wordpress/components';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
@@ -29,40 +29,82 @@ function ScreenLinkColor( { name } ) {
29
29
  isLinkEnabled &&
30
30
  ( solids.length > 0 || areCustomSolidsEnabled );
31
31
 
32
- const [ linkColor, setLinkColor ] = useStyle(
33
- 'elements.link.color.text',
34
- name
35
- );
36
- const [ userLinkColor ] = useStyle(
37
- 'elements.link.color.text',
38
- name,
39
- 'user'
40
- );
32
+ const pseudoStates = {
33
+ default: {
34
+ label: __( 'Default' ),
35
+ value: useStyle( 'elements.link.color.text', name )[ 0 ],
36
+ handler: useStyle( 'elements.link.color.text', name )[ 1 ],
37
+ userValue: useStyle(
38
+ 'elements.link.color.text',
39
+ name,
40
+ 'user'
41
+ )[ 0 ],
42
+ },
43
+ hover: {
44
+ label: __( 'Hover' ),
45
+ value: useStyle( 'elements.link.:hover.color.text', name )[ 0 ],
46
+ handler: useStyle( 'elements.link.:hover.color.text', name )[ 1 ],
47
+ userValue: useStyle(
48
+ 'elements.link.:hover.color.text',
49
+ name,
50
+ 'user'
51
+ )[ 0 ],
52
+ },
53
+ };
41
54
 
42
55
  if ( ! hasLinkColor ) {
43
56
  return null;
44
57
  }
45
58
 
59
+ const tabs = Object.entries( pseudoStates ).map(
60
+ ( [ selector, config ] ) => {
61
+ return {
62
+ name: selector,
63
+ title: config.label,
64
+ className: `color-text-${ selector }`,
65
+ };
66
+ }
67
+ );
68
+
46
69
  return (
47
70
  <>
48
71
  <ScreenHeader
49
72
  title={ __( 'Links' ) }
50
73
  description={ __(
51
- 'Set the default color used for links across the site.'
74
+ 'Set the colors used for links across the site.'
52
75
  ) }
53
76
  />
54
- <ColorGradientControl
55
- className="edit-site-screen-link-color__control"
56
- colors={ colorsPerOrigin }
57
- disableCustomColors={ ! areCustomSolidsEnabled }
58
- __experimentalHasMultipleOrigins
59
- showTitle={ false }
60
- enableAlpha
61
- __experimentalIsRenderedInSidebar
62
- colorValue={ linkColor }
63
- onColorChange={ setLinkColor }
64
- clearable={ linkColor === userLinkColor }
65
- />
77
+
78
+ <TabPanel tabs={ tabs }>
79
+ { ( tab ) => {
80
+ const pseudoSelectorConfig =
81
+ pseudoStates[ tab.name ] ?? null;
82
+
83
+ if ( ! pseudoSelectorConfig ) {
84
+ return null;
85
+ }
86
+
87
+ return (
88
+ <>
89
+ <ColorGradientControl
90
+ className="edit-site-screen-link-color__control"
91
+ colors={ colorsPerOrigin }
92
+ disableCustomColors={ ! areCustomSolidsEnabled }
93
+ __experimentalHasMultipleOrigins
94
+ showTitle={ false }
95
+ enableAlpha
96
+ __experimentalIsRenderedInSidebar
97
+ colorValue={ pseudoSelectorConfig.value }
98
+ onColorChange={ pseudoSelectorConfig.handler }
99
+ clearable={
100
+ pseudoSelectorConfig.value ===
101
+ pseudoSelectorConfig.userValue
102
+ }
103
+ />
104
+ </>
105
+ );
106
+ } }
107
+ </TabPanel>
66
108
  </>
67
109
  );
68
110
  }
@@ -66,22 +66,18 @@
66
66
  margin: 0;
67
67
  }
68
68
 
69
- .edit-site-screen-color-palette-toggle.edit-site-screen-color-palette-toggle {
70
- margin-right: $grid-unit-20;
71
- margin-left: $grid-unit-20;
72
- width: unset;
73
- .components-toggle-group-control {
74
- min-height: $grid-unit-40;
75
- }
76
- }
77
-
78
69
  .edit-site-screen-text-color__control,
79
70
  .edit-site-screen-link-color__control,
80
- .edit-site-screen-button-color__control,
81
- .edit-site-screen-background-color__control {
71
+ .edit-site-screen-button-color__control {
82
72
  padding: $grid-unit-20;
83
73
  }
84
74
 
75
+ .edit-site-screen-background-color__control {
76
+ .block-editor-color-gradient-control__tab-panel {
77
+ padding: $grid-unit-20;
78
+ }
79
+ }
80
+
85
81
  .edit-site-global-styles-variations_item {
86
82
  box-sizing: border-box;
87
83
 
@@ -7,6 +7,7 @@ import { __EXPERIMENTAL_ELEMENTS as ELEMENTS } from '@wordpress/blocks';
7
7
  * Internal dependencies
8
8
  */
9
9
  import {
10
+ getLayoutStyles,
10
11
  getNodesWithSettings,
11
12
  getNodesWithStyles,
12
13
  toCustomProperties,
@@ -450,4 +451,171 @@ describe( 'global styles renderer', () => {
450
451
  );
451
452
  } );
452
453
  } );
454
+
455
+ describe( 'getLayoutStyles', () => {
456
+ const layoutDefinitionsTree = {
457
+ settings: {
458
+ layout: {
459
+ definitions: {
460
+ default: {
461
+ name: 'default',
462
+ slug: 'flow',
463
+ className: 'is-layout-flow',
464
+ baseStyles: [
465
+ {
466
+ selector: ' > .alignleft',
467
+ rules: {
468
+ float: 'left',
469
+ 'margin-inline-start': '0',
470
+ 'margin-inline-end': '2em',
471
+ },
472
+ },
473
+ {
474
+ selector: ' > .alignright',
475
+ rules: {
476
+ float: 'right',
477
+ 'margin-inline-start': '2em',
478
+ 'margin-inline-end': '0',
479
+ },
480
+ },
481
+ {
482
+ selector: ' > .aligncenter',
483
+ rules: {
484
+ 'margin-left': 'auto !important',
485
+ 'margin-right': 'auto !important',
486
+ },
487
+ },
488
+ ],
489
+ spacingStyles: [
490
+ {
491
+ selector: ' > *',
492
+ rules: {
493
+ 'margin-block-start': '0',
494
+ 'margin-block-end': '0',
495
+ },
496
+ },
497
+ {
498
+ selector: ' > * + *',
499
+ rules: {
500
+ 'margin-block-start': null,
501
+ 'margin-block-end': '0',
502
+ },
503
+ },
504
+ ],
505
+ },
506
+ flex: {
507
+ name: 'flex',
508
+ slug: 'flex',
509
+ className: 'is-layout-flex',
510
+ displayMode: 'flex',
511
+ baseStyles: [
512
+ {
513
+ selector: '',
514
+ rules: {
515
+ 'flex-wrap': 'wrap',
516
+ 'align-items': 'center',
517
+ },
518
+ },
519
+ {
520
+ selector: ' > *',
521
+ rules: {
522
+ margin: '0',
523
+ },
524
+ },
525
+ ],
526
+ spacingStyles: [
527
+ {
528
+ selector: '',
529
+ rules: {
530
+ gap: null,
531
+ },
532
+ },
533
+ ],
534
+ },
535
+ },
536
+ },
537
+ },
538
+ };
539
+
540
+ it( 'should return fallback gap flex layout style, and all base styles, if block styles are enabled and blockGap is disabled', () => {
541
+ const style = { spacing: { blockGap: '12px' } };
542
+
543
+ const layoutStyles = getLayoutStyles( {
544
+ tree: layoutDefinitionsTree,
545
+ style,
546
+ selector: 'body',
547
+ hasBlockGapSupport: false,
548
+ hasFallbackGapSupport: true,
549
+ } );
550
+
551
+ expect( layoutStyles ).toEqual(
552
+ 'body .is-layout-flex { gap: 0.5em; }body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }'
553
+ );
554
+ } );
555
+
556
+ it( 'should return fallback gap layout styles, and base styles, if blockGap is enabled, but there is no blockGap value', () => {
557
+ const style = {};
558
+
559
+ const layoutStyles = getLayoutStyles( {
560
+ tree: layoutDefinitionsTree,
561
+ style,
562
+ selector: 'body',
563
+ hasBlockGapSupport: true,
564
+ hasFallbackGapSupport: true,
565
+ } );
566
+
567
+ expect( layoutStyles ).toEqual(
568
+ 'body .is-layout-flow > * { margin-block-start: 0; margin-block-end: 0; }body .is-layout-flow > * + * { margin-block-start: 0.5em; margin-block-end: 0; }body .is-layout-flex { gap: 0.5em; }body { --wp--style--block-gap: 0.5em; }body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }'
569
+ );
570
+ } );
571
+
572
+ it( 'should return real gap layout style if blockGap is enabled, and base styles', () => {
573
+ const style = { spacing: { blockGap: '12px' } };
574
+
575
+ const layoutStyles = getLayoutStyles( {
576
+ tree: layoutDefinitionsTree,
577
+ style,
578
+ selector: 'body',
579
+ hasBlockGapSupport: true,
580
+ hasFallbackGapSupport: true,
581
+ } );
582
+
583
+ expect( layoutStyles ).toEqual(
584
+ 'body .is-layout-flow > * { margin-block-start: 0; margin-block-end: 0; }body .is-layout-flow > * + * { margin-block-start: 12px; margin-block-end: 0; }body .is-layout-flex { gap: 12px; }body { --wp--style--block-gap: 12px; }body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }'
585
+ );
586
+ } );
587
+
588
+ it( 'should return real gap layout style if blockGap is enabled', () => {
589
+ const style = { spacing: { blockGap: '12px' } };
590
+
591
+ const layoutStyles = getLayoutStyles( {
592
+ tree: layoutDefinitionsTree,
593
+ style,
594
+ selector: '.wp-block-group',
595
+ hasBlockGapSupport: true,
596
+ hasFallbackGapSupport: true,
597
+ } );
598
+
599
+ expect( layoutStyles ).toEqual(
600
+ '.wp-block-group.is-layout-flow > * { margin-block-start: 0; margin-block-end: 0; }.wp-block-group.is-layout-flow > * + * { margin-block-start: 12px; margin-block-end: 0; }.wp-block-group.is-layout-flex { gap: 12px; }'
601
+ );
602
+ } );
603
+
604
+ it( 'should return fallback gap flex layout style for a block if blockGap is disabled, and a fallback value is provided', () => {
605
+ const style = { spacing: { blockGap: '12px' } };
606
+
607
+ const layoutStyles = getLayoutStyles( {
608
+ tree: layoutDefinitionsTree,
609
+ style,
610
+ selector: '.wp-block-group',
611
+ hasBlockGapSupport: false, // This means that the fallback value will be used instead of the "real" one.
612
+ hasFallbackGapSupport: true,
613
+ fallbackGapValue: '2em',
614
+ } );
615
+
616
+ expect( layoutStyles ).toEqual(
617
+ '.wp-block-group.is-layout-flex { gap: 2em; }'
618
+ );
619
+ } );
620
+ } );
453
621
  } );