@wordpress/edit-site 4.14.12 → 4.14.13

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.
@@ -5,206 +5,336 @@ import { getTypographyFontSizeValue } from '../typography-utils';
5
5
 
6
6
  describe( 'typography utils', () => {
7
7
  describe( 'getTypographyFontSizeValue', () => {
8
- it( 'should return the expected values', () => {
9
- [
10
- // Default return non-fluid value.
11
- {
12
- preset: {
13
- size: '28px',
14
- },
15
- typographySettings: undefined,
16
- expected: '28px',
8
+ [
9
+ {
10
+ message: 'returns value when fluid typography is deactivated',
11
+ preset: {
12
+ size: '28px',
17
13
  },
18
- // Default return value where font size is 0.
19
- {
20
- preset: {
21
- size: 0,
22
- },
23
- typographySettings: undefined,
24
- expected: 0,
14
+ typographySettings: undefined,
15
+ expected: '28px',
16
+ },
17
+
18
+ {
19
+ message: 'returns value where font size is 0',
20
+ preset: {
21
+ size: 0,
25
22
  },
26
- // Default return value where font size is '0'.
27
- {
28
- preset: {
29
- size: '0',
30
- },
31
- typographySettings: undefined,
32
- expected: '0',
23
+ typographySettings: undefined,
24
+ expected: 0,
25
+ },
26
+
27
+ {
28
+ message: "returns value where font size is '0'",
29
+ preset: {
30
+ size: '0',
33
31
  },
32
+ typographySettings: undefined,
33
+ expected: '0',
34
+ },
34
35
 
35
- // Default return non-fluid value where `size` is undefined.
36
- {
37
- preset: {
38
- size: undefined,
39
- },
40
- typographySettings: undefined,
41
- expected: undefined,
42
- },
43
- // Should return non-fluid value when fluid is `false`.
44
- {
45
- preset: {
46
- size: '28px',
47
- fluid: false,
48
- },
49
- typographySettings: {
50
- fluid: true,
51
- },
52
- expected: '28px',
36
+ {
37
+ message: 'returns value where `size` is `null`.',
38
+ preset: {
39
+ size: null,
53
40
  },
54
- // Should coerce integer to `px` and return fluid value.
55
- {
56
- preset: {
57
- size: 33,
58
- fluid: true,
59
- },
60
- typographySettings: {
61
- fluid: true,
62
- },
63
- expected:
64
- 'clamp(24.75px, 1.546875rem + ((1vw - 7.68px) * 2.975), 49.5px)',
41
+ typographySettings: null,
42
+ expected: null,
43
+ },
44
+
45
+ {
46
+ message: 'returns value when fluid is `false`',
47
+ preset: {
48
+ size: '28px',
49
+ fluid: false,
50
+ },
51
+ typographySettings: {
52
+ fluid: true,
65
53
  },
54
+ expected: '28px',
55
+ },
66
56
 
67
- // Should coerce float to `px` and return fluid value.
68
- {
69
- preset: {
70
- size: 100.23,
71
- fluid: true,
72
- },
73
- typographySettings: {
74
- fluid: true,
75
- },
76
- expected:
77
- 'clamp(75.1725px, 4.69828125rem + ((1vw - 7.68px) * 9.035), 150.345px)',
78
- },
79
- // Should return incoming value when already clamped.
80
- {
81
- preset: {
82
- size: 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
83
- fluid: false,
84
- },
85
- typographySettings: {
86
- fluid: true,
87
- },
88
- expected:
89
- 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
90
- },
91
- // Should return incoming value with unsupported unit.
92
- {
93
- preset: {
94
- size: '1000%',
95
- fluid: false,
96
- },
97
- typographySettings: {
98
- fluid: true,
99
- },
100
- expected: '1000%',
57
+ {
58
+ message: 'returns already clamped value',
59
+ preset: {
60
+ size: 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 2.524), 42px)',
61
+ fluid: false,
101
62
  },
102
- // Should return fluid value.
103
- {
104
- preset: {
105
- size: '1.75rem',
106
- },
107
- typographySettings: {
108
- fluid: true,
109
- },
110
- expected:
111
- 'clamp(1.3125rem, 1.3125rem + ((1vw - 0.48rem) * 2.524), 2.625rem)',
63
+ typographySettings: {
64
+ fluid: true,
112
65
  },
113
- // Should return fluid value for floats with units.
114
- {
115
- preset: {
116
- size: '100.175px',
117
- },
118
- typographySettings: {
119
- fluid: true,
120
- },
121
- expected:
122
- 'clamp(75.13125px, 4.695703125rem + ((1vw - 7.68px) * 9.03), 150.2625px)',
123
- },
124
- // Should return default fluid values with empty fluid array.
125
- {
126
- preset: {
127
- size: '28px',
128
- fluid: [],
129
- },
130
- typographySettings: {
131
- fluid: true,
132
- },
133
- expected:
134
- 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
66
+ expected:
67
+ 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 2.524), 42px)',
68
+ },
69
+
70
+ {
71
+ message: 'returns value with unsupported unit',
72
+ preset: {
73
+ size: '1000%',
74
+ fluid: false,
135
75
  },
76
+ typographySettings: {
77
+ fluid: true,
78
+ },
79
+ expected: '1000%',
80
+ },
136
81
 
137
- // Should return default fluid values with null values.
138
- {
139
- preset: {
140
- size: '28px',
141
- fluid: null,
142
- },
143
- typographySettings: {
144
- fluid: true,
82
+ {
83
+ message: 'returns clamp value with rem min and max units',
84
+ preset: {
85
+ size: '1.75rem',
86
+ },
87
+ typographySettings: {
88
+ fluid: true,
89
+ },
90
+ expected:
91
+ 'clamp(1.313rem, 1.313rem + ((1vw - 0.48rem) * 0.84), 1.75rem)',
92
+ },
93
+
94
+ {
95
+ message: 'returns clamp value with eem min and max units',
96
+ preset: {
97
+ size: '1.75em',
98
+ },
99
+ typographySettings: {
100
+ fluid: true,
101
+ },
102
+ expected:
103
+ 'clamp(1.313em, 1.313rem + ((1vw - 0.48em) * 0.84), 1.75em)',
104
+ },
105
+
106
+ {
107
+ message: 'returns clamp value for floats',
108
+ preset: {
109
+ size: '100.175px',
110
+ },
111
+ typographySettings: {
112
+ fluid: true,
113
+ },
114
+ expected:
115
+ 'clamp(75.131px, 4.696rem + ((1vw - 7.68px) * 3.01), 100.175px)',
116
+ },
117
+
118
+ {
119
+ message: 'coerces integer to `px` and returns clamp value',
120
+ preset: {
121
+ size: 33,
122
+ fluid: true,
123
+ },
124
+ typographySettings: {
125
+ fluid: true,
126
+ },
127
+ expected:
128
+ 'clamp(24.75px, 1.547rem + ((1vw - 7.68px) * 0.992), 33px)',
129
+ },
130
+
131
+ {
132
+ message: 'coerces float to `px` and returns clamp value',
133
+ preset: {
134
+ size: 100.23,
135
+ fluid: true,
136
+ },
137
+ typographySettings: {
138
+ fluid: true,
139
+ },
140
+ expected:
141
+ 'clamp(75.173px, 4.698rem + ((1vw - 7.68px) * 3.012), 100.23px)',
142
+ },
143
+
144
+ {
145
+ message: 'returns clamp value when `fluid` is empty array',
146
+ preset: {
147
+ size: '28px',
148
+ fluid: [],
149
+ },
150
+ typographySettings: {
151
+ fluid: true,
152
+ },
153
+ expected:
154
+ 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 0.841), 28px)',
155
+ },
156
+
157
+ {
158
+ message: 'returns clamp value when `fluid` is `null`',
159
+ preset: {
160
+ size: '28px',
161
+ fluid: null,
162
+ },
163
+ typographySettings: {
164
+ fluid: true,
165
+ },
166
+ expected:
167
+ 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 0.841), 28px)',
168
+ },
169
+
170
+ {
171
+ message:
172
+ 'returns clamp value if min font size is greater than max',
173
+ preset: {
174
+ size: '3rem',
175
+ fluid: {
176
+ min: '5rem',
177
+ max: '32px',
145
178
  },
146
- expected:
147
- 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
148
- },
149
-
150
- // Should return size with invalid fluid units.
151
- {
152
- preset: {
153
- size: '10em',
154
- fluid: {
155
- min: '20vw',
156
- max: '50%',
157
- },
179
+ },
180
+ typographySettings: {
181
+ fluid: true,
182
+ },
183
+ expected:
184
+ 'clamp(5rem, 5rem + ((1vw - 0.48rem) * -5.769), 32px)',
185
+ },
186
+
187
+ {
188
+ message: 'returns value with invalid min/max fluid units',
189
+ preset: {
190
+ size: '10em',
191
+ fluid: {
192
+ min: '20vw',
193
+ max: '50%',
158
194
  },
159
- typographySettings: {
160
- fluid: true,
195
+ },
196
+ typographySettings: {
197
+ fluid: true,
198
+ },
199
+ expected: '10em',
200
+ },
201
+
202
+ {
203
+ message:
204
+ 'returns value when size is < lower bounds and no fluid min/max set',
205
+ preset: {
206
+ size: '3px',
207
+ },
208
+ typographySettings: {
209
+ fluid: true,
210
+ },
211
+ expected: '3px',
212
+ },
213
+
214
+ {
215
+ message:
216
+ 'returns value when size is equal to lower bounds and no fluid min/max set',
217
+ preset: {
218
+ size: '14px',
219
+ },
220
+ typographySettings: {
221
+ fluid: true,
222
+ },
223
+ expected: '14px',
224
+ },
225
+
226
+ {
227
+ message: 'returns clamp value with different min max units',
228
+ preset: {
229
+ size: '28px',
230
+ fluid: {
231
+ min: '20px',
232
+ max: '50rem',
161
233
  },
162
- expected: '10em',
163
- },
164
- // Should return fluid clamp value.
165
- {
166
- preset: {
167
- size: '28px',
168
- fluid: {
169
- min: '20px',
170
- max: '50rem',
171
- },
234
+ },
235
+ typographySettings: {
236
+ fluid: true,
237
+ },
238
+ expected:
239
+ 'clamp(20px, 1.25rem + ((1vw - 7.68px) * 93.75), 50rem)',
240
+ },
241
+
242
+ {
243
+ message: 'returns clamp value where no fluid max size is set',
244
+ preset: {
245
+ size: '28px',
246
+ fluid: {
247
+ min: '2.6rem',
172
248
  },
173
- typographySettings: {
174
- fluid: true,
249
+ },
250
+ typographySettings: {
251
+ fluid: true,
252
+ },
253
+ expected:
254
+ 'clamp(2.6rem, 2.6rem + ((1vw - 0.48rem) * -1.635), 28px)',
255
+ },
256
+
257
+ {
258
+ message: 'returns clamp value where no fluid min size is set',
259
+ preset: {
260
+ size: '28px',
261
+ fluid: {
262
+ max: '80px',
175
263
  },
176
- expected:
177
- 'clamp(20px, 1.25rem + ((1vw - 7.68px) * 93.75), 50rem)',
178
- },
179
- // Should return clamp value with default fluid max value.
180
- {
181
- preset: {
182
- size: '28px',
183
- fluid: {
184
- min: '2.6rem',
185
- },
264
+ },
265
+ typographySettings: {
266
+ fluid: true,
267
+ },
268
+ expected:
269
+ 'clamp(21px, 1.313rem + ((1vw - 7.68px) * 7.091), 80px)',
270
+ },
271
+
272
+ {
273
+ message:
274
+ 'should not apply lower bound test when fluid values are set',
275
+ preset: {
276
+ size: '1.5rem',
277
+ fluid: {
278
+ min: '0.5rem',
279
+ max: '5rem',
186
280
  },
187
- typographySettings: {
188
- fluid: true,
281
+ },
282
+ typographySettings: {
283
+ fluid: true,
284
+ },
285
+ expected:
286
+ 'clamp(0.5rem, 0.5rem + ((1vw - 0.48rem) * 8.654), 5rem)',
287
+ },
288
+
289
+ {
290
+ message:
291
+ 'should not apply lower bound test when only fluid min is set',
292
+ preset: {
293
+ size: '20px',
294
+ fluid: {
295
+ min: '12px',
189
296
  },
190
- expected:
191
- 'clamp(2.6rem, 2.6rem + ((1vw - 0.48rem) * 0.048), 42px)',
192
- },
193
- // Should return clamp value with default fluid min value.
194
- {
195
- preset: {
196
- size: '28px',
197
- fluid: {
198
- max: '80px',
199
- },
297
+ },
298
+ typographySettings: {
299
+ fluid: true,
300
+ },
301
+ expected:
302
+ 'clamp(12px, 0.75rem + ((1vw - 7.68px) * 0.962), 20px)',
303
+ },
304
+
305
+ {
306
+ message:
307
+ 'should not apply lower bound test when only fluid max is set',
308
+ preset: {
309
+ size: '0.875rem',
310
+ fluid: {
311
+ max: '20rem',
200
312
  },
201
- typographySettings: {
202
- fluid: true,
313
+ },
314
+ typographySettings: {
315
+ fluid: true,
316
+ },
317
+ expected:
318
+ 'clamp(0.875rem, 0.875rem + ((1vw - 0.48rem) * 36.779), 20rem)',
319
+ },
320
+
321
+ {
322
+ message:
323
+ 'returns clamp value when min and max font sizes are equal',
324
+ preset: {
325
+ size: '4rem',
326
+ fluid: {
327
+ min: '30px',
328
+ max: '30px',
203
329
  },
204
- expected:
205
- 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 7.091), 80px)',
206
330
  },
207
- ].forEach( ( { preset, typographySettings, expected } ) => {
331
+ typographySettings: {
332
+ fluid: true,
333
+ },
334
+ expected: 'clamp(30px, 1.875rem + ((1vw - 7.68px) * 1), 30px)',
335
+ },
336
+ ].forEach( ( { message, preset, typographySettings, expected } ) => {
337
+ it( `should ${ message }`, () => {
208
338
  expect(
209
339
  getTypographyFontSizeValue( preset, typographySettings )
210
340
  ).toBe( expected );
@@ -711,7 +711,7 @@ describe( 'global styles renderer', () => {
711
711
  },
712
712
  typography: {
713
713
  fontFamily: 'sans-serif',
714
- fontSize: '14px',
714
+ fontSize: '15px',
715
715
  },
716
716
  };
717
717
 
@@ -725,7 +725,7 @@ describe( 'global styles renderer', () => {
725
725
  '--wp--style--root--padding-left: 33px',
726
726
  'background-color: var(--wp--preset--color--light-green-cyan)',
727
727
  'font-family: sans-serif',
728
- 'font-size: 14px',
728
+ 'font-size: 15px',
729
729
  ] );
730
730
  } );
731
731
 
@@ -739,7 +739,7 @@ describe( 'global styles renderer', () => {
739
739
  'padding-bottom: 33px',
740
740
  'padding-left: 33px',
741
741
  'font-family: sans-serif',
742
- 'font-size: 14px',
742
+ 'font-size: 15px',
743
743
  ] );
744
744
  } );
745
745
 
@@ -757,7 +757,7 @@ describe( 'global styles renderer', () => {
757
757
  'padding-bottom: 33px',
758
758
  'padding-left: 33px',
759
759
  'font-family: sans-serif',
760
- 'font-size: 14px',
760
+ 'font-size: 15px',
761
761
  ] );
762
762
  } );
763
763
 
@@ -782,7 +782,7 @@ describe( 'global styles renderer', () => {
782
782
  'padding-bottom: 33px',
783
783
  'padding-left: 33px',
784
784
  'font-family: sans-serif',
785
- 'font-size: clamp(10.5px, 0.65625rem + ((1vw - 7.68px) * 1.262), 21px)',
785
+ 'font-size: clamp(14px, 0.875rem + ((1vw - 7.68px) * 0.12), 15px)',
786
786
  ] );
787
787
  } );
788
788
 
@@ -807,7 +807,7 @@ describe( 'global styles renderer', () => {
807
807
  'padding-bottom: 33px',
808
808
  'padding-left: 33px',
809
809
  'font-family: sans-serif',
810
- 'font-size: 14px',
810
+ 'font-size: 15px',
811
811
  ] );
812
812
  } );
813
813
  } );
@@ -845,8 +845,44 @@ export const getBlockSelectors = ( blockTypes ) => {
845
845
  return result;
846
846
  };
847
847
 
848
+ /**
849
+ * If there is a separator block whose color is defined in theme.json via background,
850
+ * update the separator color to the same value by using border color.
851
+ *
852
+ * @param {Object} config Theme.json configuration file object.
853
+ * @return {Object} configTheme.json configuration file object updated.
854
+ */
855
+ function updateConfigWithSeparator( config ) {
856
+ const needsSeparatorStyleUpdate =
857
+ config.styles?.blocks[ 'core/separator' ] &&
858
+ config.styles?.blocks[ 'core/separator' ].color?.background &&
859
+ ! config.styles?.blocks[ 'core/separator' ].color?.text &&
860
+ ! config.styles?.blocks[ 'core/separator' ].border?.color;
861
+ if ( needsSeparatorStyleUpdate ) {
862
+ return {
863
+ ...config,
864
+ styles: {
865
+ ...config.styles,
866
+ blocks: {
867
+ ...config.styles.blocks,
868
+ 'core/separator': {
869
+ ...config.styles.blocks[ 'core/separator' ],
870
+ color: {
871
+ ...config.styles.blocks[ 'core/separator' ].color,
872
+ text: config.styles?.blocks[ 'core/separator' ]
873
+ .color.background,
874
+ },
875
+ },
876
+ },
877
+ },
878
+ };
879
+ }
880
+ return config;
881
+ }
882
+
848
883
  export function useGlobalStylesOutput() {
849
- const { merged: mergedConfig } = useContext( GlobalStylesContext );
884
+ let { merged: mergedConfig } = useContext( GlobalStylesContext );
885
+
850
886
  const [ blockGap ] = useSetting( 'spacing.blockGap' );
851
887
  const hasBlockGapSupport = blockGap !== null;
852
888
  const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
@@ -859,7 +895,7 @@ export function useGlobalStylesOutput() {
859
895
  if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
860
896
  return [];
861
897
  }
862
-
898
+ mergedConfig = updateConfigWithSeparator( mergedConfig );
863
899
  const blockSelectors = getBlockSelectors( getBlockTypes() );
864
900
  const customProperties = toCustomProperties(
865
901
  mergedConfig,
@@ -60,8 +60,8 @@ export default function Header( {
60
60
  listViewShortcut,
61
61
  isLoaded,
62
62
  isVisualMode,
63
- settings,
64
63
  blockEditorMode,
64
+ homeUrl,
65
65
  } = useSelect( ( select ) => {
66
66
  const {
67
67
  __experimentalGetPreviewDeviceType,
@@ -70,7 +70,6 @@ export default function Header( {
70
70
  isInserterOpened,
71
71
  isListViewOpened,
72
72
  getEditorMode,
73
- getSettings,
74
73
  } = select( editSiteStore );
75
74
  const { getEditedEntityRecord } = select( coreStore );
76
75
  const { __experimentalGetTemplateInfo: getTemplateInfo } =
@@ -83,6 +82,10 @@ export default function Header( {
83
82
  const record = getEditedEntityRecord( 'postType', postType, postId );
84
83
  const _isLoaded = !! postId;
85
84
 
85
+ const {
86
+ getUnstableBase, // Site index.
87
+ } = select( coreStore );
88
+
86
89
  return {
87
90
  deviceType: __experimentalGetPreviewDeviceType(),
88
91
  entityTitle: getTemplateInfo( record ).title,
@@ -95,8 +98,8 @@ export default function Header( {
95
98
  'core/edit-site/toggle-list-view'
96
99
  ),
97
100
  isVisualMode: getEditorMode() === 'visual',
98
- settings: getSettings(),
99
101
  blockEditorMode: __unstableGetEditorMode(),
102
+ homeUrl: getUnstableBase()?.home,
100
103
  };
101
104
  }, [] );
102
105
 
@@ -256,7 +259,7 @@ export default function Header( {
256
259
  >
257
260
  <MenuGroup>
258
261
  <MenuItem
259
- href={ settings?.siteUrl }
262
+ href={ homeUrl }
260
263
  target="_blank"
261
264
  icon={ external }
262
265
  >