@wordpress/block-editor 15.6.1-next.36001005c.0 → 15.6.1
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/build/components/background-image-control/index.js +2 -2
- package/build/components/background-image-control/index.js.map +2 -2
- package/build/components/block-list/block.js +3 -3
- package/build/components/block-list/block.js.map +2 -2
- package/build/components/block-list/index.js +2 -2
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-quick-navigation/index.js +0 -1
- package/build/components/block-quick-navigation/index.js.map +2 -2
- package/build/components/global-styles/border-panel.js +1 -2
- package/build/components/global-styles/border-panel.js.map +2 -2
- package/build/components/global-styles/color-panel.js +1 -2
- package/build/components/global-styles/color-panel.js.map +2 -2
- package/build/components/global-styles/dimensions-panel.js +2 -3
- package/build/components/global-styles/dimensions-panel.js.map +2 -2
- package/build/components/global-styles/filters-panel.js +1 -2
- package/build/components/global-styles/filters-panel.js.map +2 -2
- package/build/components/global-styles/get-block-css-selector.js +78 -0
- package/build/components/global-styles/get-block-css-selector.js.map +7 -0
- package/build/components/global-styles/hooks.js +95 -23
- package/build/components/global-styles/hooks.js.map +2 -2
- package/build/components/global-styles/index.js +14 -0
- package/build/components/global-styles/index.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +19 -3
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/global-styles/typography-utils.js +49 -2
- package/build/components/global-styles/typography-utils.js.map +2 -2
- package/build/components/global-styles/use-global-styles-output.js +998 -0
- package/build/components/global-styles/use-global-styles-output.js.map +7 -0
- package/build/components/global-styles/utils.js +377 -0
- package/build/components/global-styles/utils.js.map +2 -2
- package/build/components/rich-text/index.js +8 -7
- package/build/components/rich-text/index.js.map +2 -2
- package/build/hooks/block-bindings.js +111 -170
- package/build/hooks/block-bindings.js.map +2 -2
- package/build/hooks/block-style-variation.js +10 -6
- package/build/hooks/block-style-variation.js.map +2 -2
- package/build/hooks/custom-class-name.js +1 -1
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/duotone.js +3 -3
- package/build/hooks/duotone.js.map +2 -2
- package/build/hooks/fit-text.js +31 -18
- package/build/hooks/fit-text.js.map +2 -2
- package/build/hooks/font-size.js +6 -5
- package/build/hooks/font-size.js.map +2 -2
- package/build/hooks/metadata.js +48 -2
- package/build/hooks/metadata.js.map +2 -2
- package/build/hooks/typography.js +11 -4
- package/build/hooks/typography.js.map +3 -3
- package/build/hooks/use-typography-props.js +2 -2
- package/build/hooks/use-typography-props.js.map +2 -2
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/selectors.js +38 -13
- package/build/store/selectors.js.map +2 -2
- package/build/store/utils.js +2 -1
- package/build/store/utils.js.map +2 -2
- package/build/utils/fit-text-utils.js +4 -4
- package/build/utils/fit-text-utils.js.map +2 -2
- package/build-module/components/background-image-control/index.js +1 -1
- package/build-module/components/background-image-control/index.js.map +2 -2
- package/build-module/components/block-list/block.js +3 -3
- package/build-module/components/block-list/block.js.map +2 -2
- package/build-module/components/block-list/index.js +2 -2
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-quick-navigation/index.js +0 -1
- package/build-module/components/block-quick-navigation/index.js.map +2 -2
- package/build-module/components/global-styles/border-panel.js +1 -2
- package/build-module/components/global-styles/border-panel.js.map +2 -2
- package/build-module/components/global-styles/color-panel.js +1 -2
- package/build-module/components/global-styles/color-panel.js.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.js +1 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
- package/build-module/components/global-styles/filters-panel.js +1 -2
- package/build-module/components/global-styles/filters-panel.js.map +2 -2
- package/build-module/components/global-styles/get-block-css-selector.js +54 -0
- package/build-module/components/global-styles/get-block-css-selector.js.map +7 -0
- package/build-module/components/global-styles/hooks.js +95 -27
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/index.js +14 -0
- package/build-module/components/global-styles/index.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +19 -3
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/global-styles/typography-utils.js +49 -1
- package/build-module/components/global-styles/typography-utils.js.map +2 -2
- package/build-module/components/global-styles/use-global-styles-output.js +979 -0
- package/build-module/components/global-styles/use-global-styles-output.js.map +7 -0
- package/build-module/components/global-styles/utils.js +364 -0
- package/build-module/components/global-styles/utils.js.map +2 -2
- package/build-module/components/rich-text/index.js +8 -7
- package/build-module/components/rich-text/index.js.map +2 -2
- package/build-module/hooks/block-bindings.js +112 -172
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/block-style-variation.js +12 -4
- package/build-module/hooks/block-style-variation.js.map +2 -2
- package/build-module/hooks/custom-class-name.js +1 -1
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/duotone.js +3 -3
- package/build-module/hooks/duotone.js.map +2 -2
- package/build-module/hooks/fit-text.js +32 -19
- package/build-module/hooks/fit-text.js.map +2 -2
- package/build-module/hooks/font-size.js +5 -4
- package/build-module/hooks/font-size.js.map +2 -2
- package/build-module/hooks/metadata.js +46 -1
- package/build-module/hooks/metadata.js.map +2 -2
- package/build-module/hooks/typography.js +11 -4
- package/build-module/hooks/typography.js.map +3 -3
- package/build-module/hooks/use-typography-props.js +1 -1
- package/build-module/hooks/use-typography-props.js.map +2 -2
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/selectors.js +39 -14
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/store/utils.js +3 -2
- package/build-module/store/utils.js.map +2 -2
- package/build-module/utils/fit-text-utils.js +4 -4
- package/build-module/utils/fit-text-utils.js.map +2 -2
- package/build-style/style-rtl.css +6 -10
- package/build-style/style.css +6 -10
- package/package.json +35 -36
- package/src/components/background-image-control/index.js +1 -1
- package/src/components/block-card/style.scss +1 -1
- package/src/components/block-list/block.js +1 -1
- package/src/components/block-list/index.js +2 -2
- package/src/components/block-navigation/style.scss +1 -1
- package/src/components/block-quick-navigation/index.js +0 -1
- package/src/components/block-switcher/style.scss +1 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/global-styles/border-panel.js +1 -2
- package/src/components/global-styles/color-panel.js +1 -2
- package/src/components/global-styles/color-panel.native.js +1 -1
- package/src/components/global-styles/dimensions-panel.js +1 -2
- package/src/components/global-styles/filters-panel.js +1 -2
- package/src/components/global-styles/get-block-css-selector.js +114 -0
- package/src/components/global-styles/hooks.js +108 -29
- package/src/components/global-styles/index.js +8 -0
- package/src/components/global-styles/test/typography-utils.js +806 -0
- package/src/components/global-styles/test/use-global-styles-output.js +1131 -0
- package/src/components/global-styles/test/utils.js +442 -1
- package/src/components/global-styles/typography-panel.js +27 -3
- package/src/components/global-styles/typography-utils.js +133 -0
- package/src/components/global-styles/use-global-styles-output.js +1487 -0
- package/src/components/global-styles/utils.js +537 -0
- package/src/components/inserter/style.scss +2 -2
- package/src/components/multi-selection-inspector/style.scss +1 -1
- package/src/components/rich-text/index.js +8 -14
- package/src/hooks/block-bindings.js +79 -153
- package/src/hooks/block-style-variation.js +12 -4
- package/src/hooks/custom-class-name.js +1 -1
- package/src/hooks/duotone.js +3 -3
- package/src/hooks/fit-text.js +37 -28
- package/src/hooks/font-size.js +8 -4
- package/src/hooks/metadata.js +89 -0
- package/src/hooks/test/metadata.js +316 -0
- package/src/hooks/typography.js +15 -4
- package/src/hooks/use-typography-props.js +1 -1
- package/src/store/private-selectors.js +2 -2
- package/src/store/selectors.js +59 -21
- package/src/store/test/selectors.js +1 -1
- package/src/store/utils.js +2 -1
- package/src/style.scss +0 -1
- package/src/utils/fit-text-utils.js +4 -16
- package/tsconfig.json +0 -1
- package/src/components/block-quick-navigation/style.scss +0 -5
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
getBlockTypes,
|
|
6
|
+
registerBlockType,
|
|
7
|
+
unregisterBlockType,
|
|
8
|
+
} from '@wordpress/blocks';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { addTransforms } from '../metadata';
|
|
14
|
+
|
|
15
|
+
describe( 'metadata', () => {
|
|
16
|
+
afterEach( () => {
|
|
17
|
+
getBlockTypes().forEach( ( block ) => {
|
|
18
|
+
unregisterBlockType( block.name );
|
|
19
|
+
} );
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
describe( 'addTransforms()', () => {
|
|
23
|
+
it( 'should not preserve metadata in wrapping transforms', () => {
|
|
24
|
+
const source = [
|
|
25
|
+
{
|
|
26
|
+
name: 'core/foo',
|
|
27
|
+
attributes: { metadata: { noteId: 1 } },
|
|
28
|
+
innerBlocks: [],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'core/foo',
|
|
32
|
+
attributes: { metadata: { noteId: 2 } },
|
|
33
|
+
innerBlocks: [],
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const result = {
|
|
37
|
+
name: 'core/bar',
|
|
38
|
+
attributes: {},
|
|
39
|
+
innerBlocks: source,
|
|
40
|
+
};
|
|
41
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
42
|
+
|
|
43
|
+
expect( transformed.attributes.metadata ).toBeUndefined();
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
it( 'should not preserve metadata in one-to-many transforms', () => {
|
|
47
|
+
const source = [
|
|
48
|
+
{
|
|
49
|
+
name: 'core/foo',
|
|
50
|
+
attributes: { metadata: { noteId: 1 } },
|
|
51
|
+
innerBlocks: [],
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
const results = [
|
|
55
|
+
{
|
|
56
|
+
name: 'core/bar',
|
|
57
|
+
attributes: {},
|
|
58
|
+
innerBlocks: [],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'core/bar',
|
|
62
|
+
attributes: {},
|
|
63
|
+
innerBlocks: [],
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
const transformed = addTransforms(
|
|
67
|
+
results[ 0 ],
|
|
68
|
+
source,
|
|
69
|
+
0,
|
|
70
|
+
results
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect( transformed.attributes.metadata ).toBeUndefined();
|
|
74
|
+
} );
|
|
75
|
+
|
|
76
|
+
it( 'should not preserve metadata in many-to-one transforms', () => {
|
|
77
|
+
const source = [
|
|
78
|
+
{
|
|
79
|
+
name: 'core/foo',
|
|
80
|
+
attributes: { metadata: { noteId: 1 } },
|
|
81
|
+
innerBlocks: [],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'core/foo',
|
|
85
|
+
attributes: { metadata: { noteId: 2 } },
|
|
86
|
+
innerBlocks: [],
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
const result = {
|
|
90
|
+
name: 'core/bar',
|
|
91
|
+
attributes: {},
|
|
92
|
+
innerBlocks: [],
|
|
93
|
+
};
|
|
94
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
95
|
+
|
|
96
|
+
expect( transformed.attributes.metadata ).toBeUndefined();
|
|
97
|
+
} );
|
|
98
|
+
|
|
99
|
+
it( 'should not preserve metadata in many-to-many transforms with different counts', () => {
|
|
100
|
+
const source = [
|
|
101
|
+
{
|
|
102
|
+
name: 'core/foo',
|
|
103
|
+
attributes: { metadata: { noteId: 1 } },
|
|
104
|
+
innerBlocks: [],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'core/foo',
|
|
108
|
+
attributes: { metadata: { noteId: 2 } },
|
|
109
|
+
innerBlocks: [],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'core/foo',
|
|
113
|
+
attributes: { metadata: { noteId: 3 } },
|
|
114
|
+
innerBlocks: [],
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
const results = [
|
|
118
|
+
{
|
|
119
|
+
name: 'core/bar',
|
|
120
|
+
attributes: {},
|
|
121
|
+
innerBlocks: [],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'core/bar',
|
|
125
|
+
attributes: {},
|
|
126
|
+
innerBlocks: [],
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
const [ firstTransformed, secondTransformed ] = results.map(
|
|
130
|
+
( result, index ) =>
|
|
131
|
+
addTransforms( result, source, index, results )
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect( firstTransformed.attributes.metadata ).toBeUndefined();
|
|
135
|
+
expect( secondTransformed.attributes.metadata ).toBeUndefined();
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
it( 'should preserve metadata in many-to-many transforms with same counts', () => {
|
|
139
|
+
const source = [
|
|
140
|
+
{
|
|
141
|
+
name: 'core/foo',
|
|
142
|
+
attributes: { metadata: { noteId: 1 } },
|
|
143
|
+
innerBlocks: [],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'core/foo',
|
|
147
|
+
attributes: { metadata: { noteId: 2 } },
|
|
148
|
+
innerBlocks: [],
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
const results = [
|
|
152
|
+
{
|
|
153
|
+
name: 'core/bar',
|
|
154
|
+
attributes: { metadata: { noteId: 1 } },
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: 'core/bar',
|
|
158
|
+
attributes: { metadata: { noteId: 2 } },
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
const [ firstTransformed, secondTransformed ] = results.map(
|
|
163
|
+
( result, index ) =>
|
|
164
|
+
addTransforms( result, source, index, results )
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
expect( firstTransformed.attributes.metadata ).toEqual( {
|
|
168
|
+
noteId: 1,
|
|
169
|
+
} );
|
|
170
|
+
expect( secondTransformed.attributes.metadata ).toEqual( {
|
|
171
|
+
noteId: 2,
|
|
172
|
+
} );
|
|
173
|
+
} );
|
|
174
|
+
|
|
175
|
+
it( 'should preserve custom name metadata', () => {
|
|
176
|
+
registerBlockType( 'core/bar', {
|
|
177
|
+
title: 'Bar',
|
|
178
|
+
} );
|
|
179
|
+
const source = [
|
|
180
|
+
{
|
|
181
|
+
name: 'core/foo',
|
|
182
|
+
attributes: {
|
|
183
|
+
metadata: { name: 'Custom Name' },
|
|
184
|
+
},
|
|
185
|
+
innerBlocks: [],
|
|
186
|
+
},
|
|
187
|
+
];
|
|
188
|
+
const result = {
|
|
189
|
+
name: 'core/bar',
|
|
190
|
+
attributes: {},
|
|
191
|
+
innerBlocks: [],
|
|
192
|
+
};
|
|
193
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
194
|
+
|
|
195
|
+
expect( transformed.attributes.metadata.name ).toBe(
|
|
196
|
+
'Custom Name'
|
|
197
|
+
);
|
|
198
|
+
} );
|
|
199
|
+
|
|
200
|
+
it( 'should not preserve custom name metadata when target block does not support renaming', () => {
|
|
201
|
+
registerBlockType( 'core/bar', {
|
|
202
|
+
title: 'Bar',
|
|
203
|
+
supports: {
|
|
204
|
+
renaming: false,
|
|
205
|
+
},
|
|
206
|
+
} );
|
|
207
|
+
|
|
208
|
+
const source = [
|
|
209
|
+
{
|
|
210
|
+
name: 'core/foo',
|
|
211
|
+
attributes: {
|
|
212
|
+
metadata: { name: 'Custom Name' },
|
|
213
|
+
},
|
|
214
|
+
innerBlocks: [],
|
|
215
|
+
},
|
|
216
|
+
];
|
|
217
|
+
const result = {
|
|
218
|
+
name: 'core/bar',
|
|
219
|
+
attributes: {},
|
|
220
|
+
innerBlocks: [],
|
|
221
|
+
};
|
|
222
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
223
|
+
|
|
224
|
+
expect( transformed.attributes.metadata?.name ).toBeUndefined();
|
|
225
|
+
} );
|
|
226
|
+
|
|
227
|
+
it( 'should preserve block visibility metadata', () => {
|
|
228
|
+
registerBlockType( 'core/bar', {
|
|
229
|
+
title: 'Bar',
|
|
230
|
+
} );
|
|
231
|
+
|
|
232
|
+
const source = [
|
|
233
|
+
{
|
|
234
|
+
name: 'core/foo',
|
|
235
|
+
attributes: {
|
|
236
|
+
metadata: { blockVisibility: false },
|
|
237
|
+
},
|
|
238
|
+
innerBlocks: [],
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
const result = {
|
|
242
|
+
name: 'core/bar',
|
|
243
|
+
attributes: {},
|
|
244
|
+
innerBlocks: [],
|
|
245
|
+
};
|
|
246
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
247
|
+
|
|
248
|
+
expect( transformed.attributes.metadata?.blockVisibility ).toBe(
|
|
249
|
+
false
|
|
250
|
+
);
|
|
251
|
+
} );
|
|
252
|
+
|
|
253
|
+
it( 'should not preserve block visibility metadata when target block does not support it', () => {
|
|
254
|
+
registerBlockType( 'core/bar', {
|
|
255
|
+
title: 'Bar',
|
|
256
|
+
supports: {
|
|
257
|
+
blockVisibility: false,
|
|
258
|
+
},
|
|
259
|
+
} );
|
|
260
|
+
|
|
261
|
+
const source = [
|
|
262
|
+
{
|
|
263
|
+
name: 'core/foo',
|
|
264
|
+
attributes: {
|
|
265
|
+
metadata: { blockVisibility: false },
|
|
266
|
+
},
|
|
267
|
+
innerBlocks: [],
|
|
268
|
+
},
|
|
269
|
+
];
|
|
270
|
+
const result = {
|
|
271
|
+
name: 'core/bar',
|
|
272
|
+
attributes: {},
|
|
273
|
+
innerBlocks: [],
|
|
274
|
+
};
|
|
275
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
276
|
+
|
|
277
|
+
expect(
|
|
278
|
+
transformed.attributes.metadata?.blockVisibility
|
|
279
|
+
).toBeUndefined();
|
|
280
|
+
} );
|
|
281
|
+
|
|
282
|
+
it( 'should not override existing metadata in target block', () => {
|
|
283
|
+
const source = [
|
|
284
|
+
{
|
|
285
|
+
name: 'core/foo',
|
|
286
|
+
attributes: {
|
|
287
|
+
metadata: {
|
|
288
|
+
noteId: 1,
|
|
289
|
+
name: 'Custom Name',
|
|
290
|
+
blockVisibility: false,
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
innerBlocks: [],
|
|
294
|
+
},
|
|
295
|
+
];
|
|
296
|
+
const result = {
|
|
297
|
+
name: 'core/bar',
|
|
298
|
+
attributes: {
|
|
299
|
+
metadata: {
|
|
300
|
+
noteId: 2,
|
|
301
|
+
name: 'Existing Name',
|
|
302
|
+
blockVisibility: true,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
innerBlocks: [],
|
|
306
|
+
};
|
|
307
|
+
const transformed = addTransforms( result, source, 0, [ result ] );
|
|
308
|
+
|
|
309
|
+
expect( transformed.attributes.metadata ).toEqual( {
|
|
310
|
+
noteId: 2,
|
|
311
|
+
name: 'Existing Name',
|
|
312
|
+
blockVisibility: true,
|
|
313
|
+
} );
|
|
314
|
+
} );
|
|
315
|
+
} );
|
|
316
|
+
} );
|
package/src/hooks/typography.js
CHANGED
|
@@ -116,11 +116,13 @@ function TypographyInspectorControl( { children, resetAllFilter } ) {
|
|
|
116
116
|
|
|
117
117
|
export function TypographyPanel( { clientId, name, setAttributes, settings } ) {
|
|
118
118
|
function selector( select ) {
|
|
119
|
-
const { style, fontFamily, fontSize } =
|
|
119
|
+
const { style, fontFamily, fontSize, fitText } =
|
|
120
120
|
select( blockEditorStore ).getBlockAttributes( clientId ) || {};
|
|
121
|
-
return { style, fontFamily, fontSize };
|
|
121
|
+
return { style, fontFamily, fontSize, fitText };
|
|
122
122
|
}
|
|
123
|
-
const { style, fontFamily, fontSize } = useSelect( selector, [
|
|
123
|
+
const { style, fontFamily, fontSize, fitText } = useSelect( selector, [
|
|
124
|
+
clientId,
|
|
125
|
+
] );
|
|
124
126
|
const isEnabled = useHasTypographyPanel( settings );
|
|
125
127
|
const value = useMemo(
|
|
126
128
|
() => attributesToStyle( { style, fontFamily, fontSize } ),
|
|
@@ -128,7 +130,16 @@ export function TypographyPanel( { clientId, name, setAttributes, settings } ) {
|
|
|
128
130
|
);
|
|
129
131
|
|
|
130
132
|
const onChange = ( newStyle ) => {
|
|
131
|
-
|
|
133
|
+
const newAttributes = styleToAttributes( newStyle );
|
|
134
|
+
|
|
135
|
+
// If setting a font size and fitText is currently enabled, disable it
|
|
136
|
+
const hasFontSize =
|
|
137
|
+
newAttributes.fontSize || newAttributes.style?.typography?.fontSize;
|
|
138
|
+
if ( hasFontSize && fitText ) {
|
|
139
|
+
newAttributes.fitText = undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setAttributes( newAttributes );
|
|
132
143
|
};
|
|
133
144
|
|
|
134
145
|
if ( ! isEnabled ) {
|
|
@@ -7,13 +7,13 @@ import clsx from 'clsx';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
10
|
-
import { getTypographyFontSizeValue } from '@wordpress/global-styles-engine';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Internal dependencies
|
|
14
13
|
*/
|
|
15
14
|
import { getInlineStyles } from './style';
|
|
16
15
|
import { getFontSizeClass } from '../components/font-sizes';
|
|
16
|
+
import { getTypographyFontSizeValue } from '../components/global-styles/typography-utils';
|
|
17
17
|
import { unlock } from '../lock-unlock';
|
|
18
18
|
|
|
19
19
|
const { kebabCase } = unlock( componentsPrivateApis );
|
|
@@ -95,7 +95,7 @@ export const isBlockSubtreeDisabled = ( state, clientId ) => {
|
|
|
95
95
|
* @param {string} rootClientId The client ID of the root container block.
|
|
96
96
|
* @return {boolean} Whether the container allows insertion.
|
|
97
97
|
*/
|
|
98
|
-
export function
|
|
98
|
+
export function isContainerInsertableToInContentOnlyMode(
|
|
99
99
|
state,
|
|
100
100
|
blockName,
|
|
101
101
|
rootClientId
|
|
@@ -105,7 +105,7 @@ export function isContainerInsertableToInWriteMode(
|
|
|
105
105
|
const isContainerContentBlock = isContentBlock( rootBlockName );
|
|
106
106
|
const isRootBlockMain = getSectionRootClientId( state ) === rootClientId;
|
|
107
107
|
|
|
108
|
-
// In
|
|
108
|
+
// In contentOnly mode, containers shouldn't be inserted into unless:
|
|
109
109
|
// 1. they are a section root;
|
|
110
110
|
// 2. they are a content block and the block to be inserted is also content.
|
|
111
111
|
return (
|
package/src/store/selectors.js
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
isSectionBlock,
|
|
44
44
|
getParentSectionBlock,
|
|
45
45
|
isZoomOut,
|
|
46
|
-
|
|
46
|
+
isContainerInsertableToInContentOnlyMode,
|
|
47
47
|
} from './private-selectors';
|
|
48
48
|
|
|
49
49
|
const { isContentBlock } = unlock( blocksPrivateApis );
|
|
@@ -1682,15 +1682,7 @@ const canInsertBlockTypeUnmemoized = (
|
|
|
1682
1682
|
blockType = getBlockType( blockName );
|
|
1683
1683
|
}
|
|
1684
1684
|
|
|
1685
|
-
|
|
1686
|
-
if ( isLocked ) {
|
|
1687
|
-
return false;
|
|
1688
|
-
}
|
|
1689
|
-
const isContentRoleBlock = isContentBlock( blockName );
|
|
1690
|
-
const isParentSectionBlock = !! isSectionBlock( state, rootClientId );
|
|
1691
|
-
// It shouldn't be possible to insert inside a section block unless in
|
|
1692
|
-
// some cases when the block is a content block.
|
|
1693
|
-
if ( isParentSectionBlock && ! isContentRoleBlock ) {
|
|
1685
|
+
if ( getTemplateLock( state, rootClientId ) ) {
|
|
1694
1686
|
return false;
|
|
1695
1687
|
}
|
|
1696
1688
|
|
|
@@ -1707,10 +1699,29 @@ const canInsertBlockTypeUnmemoized = (
|
|
|
1707
1699
|
return false;
|
|
1708
1700
|
}
|
|
1709
1701
|
|
|
1710
|
-
//
|
|
1702
|
+
// It shouldn't be possible to insert inside a section block unless in
|
|
1703
|
+
// some cases when the block is a content block.
|
|
1704
|
+
const isContentRoleBlock = isContentBlock( blockName );
|
|
1705
|
+
const isParentSectionBlock = !! isSectionBlock( state, rootClientId );
|
|
1706
|
+
const isBlockWithinSection = !! getParentSectionBlock(
|
|
1707
|
+
state,
|
|
1708
|
+
rootClientId
|
|
1709
|
+
);
|
|
1710
|
+
if (
|
|
1711
|
+
( isParentSectionBlock || isBlockWithinSection ) &&
|
|
1712
|
+
! isContentRoleBlock
|
|
1713
|
+
) {
|
|
1714
|
+
return false;
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
// In content only mode, check if this container allows insertion.
|
|
1711
1718
|
if (
|
|
1712
|
-
blockEditingMode === 'contentOnly' &&
|
|
1713
|
-
!
|
|
1719
|
+
( isParentSectionBlock || blockEditingMode === 'contentOnly' ) &&
|
|
1720
|
+
! isContainerInsertableToInContentOnlyMode(
|
|
1721
|
+
state,
|
|
1722
|
+
blockName,
|
|
1723
|
+
rootClientId
|
|
1724
|
+
)
|
|
1714
1725
|
) {
|
|
1715
1726
|
return false;
|
|
1716
1727
|
}
|
|
@@ -1858,6 +1869,8 @@ export function canRemoveBlock( state, clientId ) {
|
|
|
1858
1869
|
return false;
|
|
1859
1870
|
}
|
|
1860
1871
|
|
|
1872
|
+
// It shouldn't be possible to move in a section block unless in
|
|
1873
|
+
// some cases when the block is a content block.
|
|
1861
1874
|
const isBlockWithinSection = !! getParentSectionBlock( state, clientId );
|
|
1862
1875
|
const isContentRoleBlock = isContentBlock(
|
|
1863
1876
|
getBlockName( state, clientId )
|
|
@@ -1866,21 +1879,21 @@ export function canRemoveBlock( state, clientId ) {
|
|
|
1866
1879
|
return false;
|
|
1867
1880
|
}
|
|
1868
1881
|
|
|
1869
|
-
const
|
|
1870
|
-
|
|
1871
|
-
// Check if the parent container allows insertion/removal in
|
|
1882
|
+
const isParentSectionBlock = !! isSectionBlock( state, rootClientId );
|
|
1883
|
+
const rootBlockEditingMode = getBlockEditingMode( state, rootClientId );
|
|
1884
|
+
// Check if the parent container allows insertion/removal in contentOnly mode
|
|
1872
1885
|
if (
|
|
1873
|
-
|
|
1874
|
-
!
|
|
1886
|
+
( isParentSectionBlock || rootBlockEditingMode === 'contentOnly' ) &&
|
|
1887
|
+
! isContainerInsertableToInContentOnlyMode(
|
|
1875
1888
|
state,
|
|
1876
|
-
getBlockName( state,
|
|
1889
|
+
getBlockName( state, clientId ),
|
|
1877
1890
|
rootClientId
|
|
1878
1891
|
)
|
|
1879
1892
|
) {
|
|
1880
1893
|
return false;
|
|
1881
1894
|
}
|
|
1882
1895
|
|
|
1883
|
-
return
|
|
1896
|
+
return rootBlockEditingMode !== 'disabled';
|
|
1884
1897
|
}
|
|
1885
1898
|
|
|
1886
1899
|
/**
|
|
@@ -1913,9 +1926,34 @@ export function canMoveBlock( state, clientId ) {
|
|
|
1913
1926
|
}
|
|
1914
1927
|
|
|
1915
1928
|
const rootClientId = getBlockRootClientId( state, clientId );
|
|
1916
|
-
|
|
1929
|
+
const templateLock = getTemplateLock( state, rootClientId );
|
|
1930
|
+
if ( templateLock === 'all' || templateLock === 'contentOnly' ) {
|
|
1931
|
+
return false;
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
const isBlockWithinSection = !! getParentSectionBlock( state, clientId );
|
|
1935
|
+
const isContentRoleBlock = isContentBlock(
|
|
1936
|
+
getBlockName( state, clientId )
|
|
1937
|
+
);
|
|
1938
|
+
if ( isBlockWithinSection && ! isContentRoleBlock ) {
|
|
1917
1939
|
return false;
|
|
1918
1940
|
}
|
|
1941
|
+
|
|
1942
|
+
// If the parent is a section or is `contentOnly`, then check is the inner block
|
|
1943
|
+
// should be allowed to move.
|
|
1944
|
+
const isParentSectionBlock = !! isSectionBlock( state, rootClientId );
|
|
1945
|
+
const rootBlockEditingMode = getBlockEditingMode( state, rootClientId );
|
|
1946
|
+
if (
|
|
1947
|
+
( isParentSectionBlock || rootBlockEditingMode === 'contentOnly' ) &&
|
|
1948
|
+
! isContainerInsertableToInContentOnlyMode(
|
|
1949
|
+
state,
|
|
1950
|
+
getBlockName( state, clientId ),
|
|
1951
|
+
rootClientId
|
|
1952
|
+
)
|
|
1953
|
+
) {
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1919
1957
|
return getBlockEditingMode( state, rootClientId ) !== 'disabled';
|
|
1920
1958
|
}
|
|
1921
1959
|
|
|
@@ -3081,7 +3081,7 @@ describe( 'selectors', () => {
|
|
|
3081
3081
|
byClientId: new Map(
|
|
3082
3082
|
Object.entries( {
|
|
3083
3083
|
block1: { name: 'core/test-block-ancestor' },
|
|
3084
|
-
block2: { name: 'core/
|
|
3084
|
+
block2: { name: 'core/group' },
|
|
3085
3085
|
block3: { name: 'core/test-block-parent' },
|
|
3086
3086
|
} )
|
|
3087
3087
|
),
|
package/src/store/utils.js
CHANGED
|
@@ -10,7 +10,7 @@ import { parse as grammarParse } from '@wordpress/block-serialization-default-pa
|
|
|
10
10
|
import { selectBlockPatternsKey } from './private-keys';
|
|
11
11
|
import { unlock } from '../lock-unlock';
|
|
12
12
|
import { STORE_NAME } from './constants';
|
|
13
|
-
import { getSectionRootClientId } from './private-selectors';
|
|
13
|
+
import { getSectionRootClientId, isSectionBlock } from './private-selectors';
|
|
14
14
|
import { getBlockEditingMode } from './selectors';
|
|
15
15
|
import { INSERTER_PATTERN_TYPES } from '../components/inserter/block-patterns-tab/utils';
|
|
16
16
|
|
|
@@ -140,5 +140,6 @@ export const getInsertBlockTypeDependants = () => ( state, rootClientId ) => {
|
|
|
140
140
|
state.settings.templateLock,
|
|
141
141
|
getBlockEditingMode( state, rootClientId ),
|
|
142
142
|
getSectionRootClientId( state ),
|
|
143
|
+
isSectionBlock( state, rootClientId ),
|
|
143
144
|
];
|
|
144
145
|
};
|
package/src/style.scss
CHANGED
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
@use "./components/block-patterns-paging/style.scss" as *;
|
|
21
21
|
@use "./components/block-popover/style.scss" as *;
|
|
22
22
|
@use "./components/block-preview/style.scss" as *;
|
|
23
|
-
@use "./components/block-quick-navigation/style.scss" as *;
|
|
24
23
|
@use "./components/block-rename/style.scss" as *;
|
|
25
24
|
@use "./components/block-styles/style.scss" as *;
|
|
26
25
|
@use "./components/block-switcher/style.scss" as *;
|
|
@@ -20,18 +20,13 @@ function generateCSSRule( elementSelector, fontSize ) {
|
|
|
20
20
|
* @param {HTMLElement} textElement The text element
|
|
21
21
|
* @param {string} elementSelector CSS selector for the text element
|
|
22
22
|
* @param {Function} applyStylesFn Function to apply test styles
|
|
23
|
-
* @param {number} maxSize Maximum font size in pixels (default: 600)
|
|
24
23
|
* @return {number} Optimal font size
|
|
25
24
|
*/
|
|
26
|
-
function findOptimalFontSize(
|
|
27
|
-
textElement,
|
|
28
|
-
elementSelector,
|
|
29
|
-
applyStylesFn,
|
|
30
|
-
maxSize = 600
|
|
31
|
-
) {
|
|
25
|
+
function findOptimalFontSize( textElement, elementSelector, applyStylesFn ) {
|
|
32
26
|
const alreadyHasScrollableHeight =
|
|
33
27
|
textElement.scrollHeight > textElement.clientHeight;
|
|
34
28
|
let minSize = 5;
|
|
29
|
+
let maxSize = 600;
|
|
35
30
|
let bestSize = minSize;
|
|
36
31
|
|
|
37
32
|
while ( minSize <= maxSize ) {
|
|
@@ -61,14 +56,8 @@ function findOptimalFontSize(
|
|
|
61
56
|
* @param {HTMLElement} textElement The text element (paragraph, heading, etc.)
|
|
62
57
|
* @param {string} elementSelector CSS selector for the text element
|
|
63
58
|
* @param {Function} applyStylesFn Function to apply CSS styles (pass empty string to clear)
|
|
64
|
-
* @param {number} maxSize Maximum font size in pixels.
|
|
65
59
|
*/
|
|
66
|
-
export function optimizeFitText(
|
|
67
|
-
textElement,
|
|
68
|
-
elementSelector,
|
|
69
|
-
applyStylesFn,
|
|
70
|
-
maxSize
|
|
71
|
-
) {
|
|
60
|
+
export function optimizeFitText( textElement, elementSelector, applyStylesFn ) {
|
|
72
61
|
if ( ! textElement ) {
|
|
73
62
|
return;
|
|
74
63
|
}
|
|
@@ -78,8 +67,7 @@ export function optimizeFitText(
|
|
|
78
67
|
const optimalSize = findOptimalFontSize(
|
|
79
68
|
textElement,
|
|
80
69
|
elementSelector,
|
|
81
|
-
applyStylesFn
|
|
82
|
-
maxSize
|
|
70
|
+
applyStylesFn
|
|
83
71
|
);
|
|
84
72
|
|
|
85
73
|
const cssRule = generateCSSRule( elementSelector, optimalSize );
|
package/tsconfig.json
CHANGED