@wordpress/block-editor 13.0.3 → 13.2.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 +21 -17
- package/README.md +1 -1
- package/build/components/block-lock/modal.js +67 -67
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-mover/index.js +12 -6
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/child-layout-control/index.js +185 -127
- package/build/components/child-layout-control/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +18 -10
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/grid/grid-item-movers.js +97 -0
- package/build/components/grid/grid-item-movers.js.map +1 -0
- package/build/components/{grid-visualizer → grid}/grid-item-resizer.js +18 -56
- package/build/components/grid/grid-item-resizer.js.map +1 -0
- package/build/components/grid/grid-visualizer.js +225 -0
- package/build/components/grid/grid-visualizer.js.map +1 -0
- package/build/components/{grid-visualizer → grid}/index.js +14 -0
- package/build/components/grid/index.js.map +1 -0
- package/build/components/grid/use-get-number-of-blocks-before-cell.js +40 -0
- package/build/components/grid/use-get-number-of-blocks-before-cell.js.map +1 -0
- package/build/components/grid/use-grid-layout-sync.js +162 -0
- package/build/components/grid/use-grid-layout-sync.js.map +1 -0
- package/build/components/grid/utils.js +145 -0
- package/build/components/grid/utils.js.map +1 -0
- package/build/components/inner-blocks/index.js +1 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inserter/block-types-tab.native.js +1 -1
- package/build/components/inserter/block-types-tab.native.js.map +1 -1
- package/build/components/link-control/link-preview.js +12 -1
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/provider/use-block-sync.js +1 -7
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/rich-text/event-listeners/input-rules.js +1 -0
- package/build/components/rich-text/event-listeners/input-rules.js.map +1 -1
- package/build/components/rich-text/index.native.js +14 -4
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +20 -4
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/hooks/block-style-variation.js +2 -2
- package/build/hooks/block-style-variation.js.map +1 -1
- package/build/hooks/layout-child.js +29 -21
- package/build/hooks/layout-child.js.map +1 -1
- package/build/layouts/grid.js +24 -47
- package/build/layouts/grid.js.map +1 -1
- package/build/store/private-actions.js +0 -34
- package/build/store/private-actions.js.map +1 -1
- package/build-module/components/block-lock/modal.js +67 -67
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-mover/index.js +12 -6
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +185 -127
- package/build-module/components/child-layout-control/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +19 -11
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/grid/grid-item-movers.js +90 -0
- package/build-module/components/grid/grid-item-movers.js.map +1 -0
- package/build-module/components/{grid-visualizer → grid}/grid-item-resizer.js +13 -51
- package/build-module/components/grid/grid-item-resizer.js.map +1 -0
- package/build-module/components/grid/grid-visualizer.js +217 -0
- package/build-module/components/grid/grid-visualizer.js.map +1 -0
- package/build-module/components/grid/index.js +5 -0
- package/build-module/components/grid/index.js.map +1 -0
- package/build-module/components/grid/use-get-number-of-blocks-before-cell.js +33 -0
- package/build-module/components/grid/use-get-number-of-blocks-before-cell.js.map +1 -0
- package/build-module/components/grid/use-grid-layout-sync.js +155 -0
- package/build-module/components/grid/use-grid-layout-sync.js.map +1 -0
- package/build-module/components/grid/utils.js +131 -0
- package/build-module/components/grid/utils.js.map +1 -0
- package/build-module/components/inner-blocks/index.js +1 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.native.js +1 -1
- package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +14 -1
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +1 -7
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/rich-text/event-listeners/input-rules.js +1 -1
- package/build-module/components/rich-text/event-listeners/input-rules.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +15 -5
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +20 -4
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/hooks/block-style-variation.js +2 -2
- package/build-module/hooks/block-style-variation.js.map +1 -1
- package/build-module/hooks/layout-child.js +27 -19
- package/build-module/hooks/layout-child.js.map +1 -1
- package/build-module/layouts/grid.js +24 -47
- package/build-module/layouts/grid.js.map +1 -1
- package/build-module/store/private-actions.js +0 -33
- package/build-module/store/private-actions.js.map +1 -1
- package/build-style/style-rtl.css +38 -16
- package/build-style/style.css +38 -16
- package/package.json +31 -31
- package/src/components/block-lock/modal.js +95 -82
- package/src/components/block-lock/style.scss +11 -1
- package/src/components/block-mover/index.js +37 -24
- package/src/components/child-layout-control/index.js +224 -159
- package/src/components/date-format-picker/index.js +25 -13
- package/src/components/grid/grid-item-movers.js +128 -0
- package/src/components/{grid-visualizer → grid}/grid-item-resizer.js +14 -52
- package/src/components/grid/grid-visualizer.js +267 -0
- package/src/components/grid/index.js +4 -0
- package/src/components/grid/style.scss +63 -0
- package/src/components/grid/use-get-number-of-blocks-before-cell.js +30 -0
- package/src/components/grid/use-grid-layout-sync.js +167 -0
- package/src/components/grid/utils.js +178 -0
- package/src/components/inner-blocks/index.js +3 -1
- package/src/components/inserter/block-types-tab.native.js +2 -1
- package/src/components/link-control/link-preview.js +18 -1
- package/src/components/provider/use-block-sync.js +0 -6
- package/src/components/rich-text/event-listeners/input-rules.js +1 -1
- package/src/components/rich-text/index.native.js +14 -8
- package/src/components/rich-text/native/index.native.js +20 -1
- package/src/hooks/block-style-variation.js +2 -2
- package/src/hooks/layout-child.js +34 -14
- package/src/layouts/grid.js +54 -62
- package/src/store/private-actions.js +0 -29
- package/src/style.scss +1 -1
- package/build/components/grid-visualizer/grid-item-resizer.js.map +0 -1
- package/build/components/grid-visualizer/grid-visualizer.js +0 -92
- package/build/components/grid-visualizer/grid-visualizer.js.map +0 -1
- package/build/components/grid-visualizer/index.js.map +0 -1
- package/build/components/grid-visualizer/utils.js +0 -10
- package/build/components/grid-visualizer/utils.js.map +0 -1
- package/build/store/undo-ignore.js +0 -11
- package/build/store/undo-ignore.js.map +0 -1
- package/build-module/components/grid-visualizer/grid-item-resizer.js.map +0 -1
- package/build-module/components/grid-visualizer/grid-visualizer.js +0 -84
- package/build-module/components/grid-visualizer/grid-visualizer.js.map +0 -1
- package/build-module/components/grid-visualizer/index.js +0 -3
- package/build-module/components/grid-visualizer/index.js.map +0 -1
- package/build-module/components/grid-visualizer/utils.js +0 -4
- package/build-module/components/grid-visualizer/utils.js.map +0 -1
- package/build-module/store/undo-ignore.js +0 -5
- package/build-module/store/undo-ignore.js.map +0 -1
- package/src/components/grid-visualizer/grid-visualizer.js +0 -101
- package/src/components/grid-visualizer/index.js +0 -2
- package/src/components/grid-visualizer/style.scss +0 -34
- package/src/components/grid-visualizer/utils.js +0 -5
- package/src/store/undo-ignore.js +0 -4
- /package/src/components/font-sizes/{README.MD → README.md} +0 -0
|
@@ -14,6 +14,13 @@ import {
|
|
|
14
14
|
} from '@wordpress/components';
|
|
15
15
|
import { __ } from '@wordpress/i18n';
|
|
16
16
|
import { useEffect } from '@wordpress/element';
|
|
17
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import { useGetNumberOfBlocksBeforeCell } from '../grid/use-get-number-of-blocks-before-cell';
|
|
23
|
+
import { store as blockEditorStore } from '../../store';
|
|
17
24
|
|
|
18
25
|
function helpText( selfStretch, parentLayout ) {
|
|
19
26
|
const { orientation = 'horizontal' } = parentLayout;
|
|
@@ -48,21 +55,46 @@ export default function ChildLayoutControl( {
|
|
|
48
55
|
isShownByDefault,
|
|
49
56
|
panelId,
|
|
50
57
|
} ) {
|
|
51
|
-
const {
|
|
52
|
-
selfStretch,
|
|
53
|
-
flexSize,
|
|
54
|
-
columnStart,
|
|
55
|
-
rowStart,
|
|
56
|
-
columnSpan,
|
|
57
|
-
rowSpan,
|
|
58
|
-
} = childLayout;
|
|
59
58
|
const {
|
|
60
59
|
type: parentType,
|
|
61
60
|
default: { type: defaultParentType = 'default' } = {},
|
|
62
|
-
orientation = 'horizontal',
|
|
63
61
|
} = parentLayout ?? {};
|
|
64
62
|
const parentLayoutType = parentType || defaultParentType;
|
|
65
63
|
|
|
64
|
+
if ( parentLayoutType === 'flex' ) {
|
|
65
|
+
return (
|
|
66
|
+
<FlexControls
|
|
67
|
+
childLayout={ childLayout }
|
|
68
|
+
onChange={ onChange }
|
|
69
|
+
parentLayout={ parentLayout }
|
|
70
|
+
isShownByDefault={ isShownByDefault }
|
|
71
|
+
panelId={ panelId }
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
} else if ( parentLayoutType === 'grid' ) {
|
|
75
|
+
return (
|
|
76
|
+
<GridControls
|
|
77
|
+
childLayout={ childLayout }
|
|
78
|
+
onChange={ onChange }
|
|
79
|
+
parentLayout={ parentLayout }
|
|
80
|
+
isShownByDefault={ isShownByDefault }
|
|
81
|
+
panelId={ panelId }
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function FlexControls( {
|
|
90
|
+
childLayout,
|
|
91
|
+
onChange,
|
|
92
|
+
parentLayout,
|
|
93
|
+
isShownByDefault,
|
|
94
|
+
panelId,
|
|
95
|
+
} ) {
|
|
96
|
+
const { selfStretch, flexSize } = childLayout;
|
|
97
|
+
const { orientation = 'horizontal' } = parentLayout ?? {};
|
|
66
98
|
const hasFlexValue = () => !! selfStretch;
|
|
67
99
|
const flexResetLabel =
|
|
68
100
|
orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );
|
|
@@ -73,6 +105,96 @@ export default function ChildLayoutControl( {
|
|
|
73
105
|
} );
|
|
74
106
|
};
|
|
75
107
|
|
|
108
|
+
useEffect( () => {
|
|
109
|
+
if ( selfStretch === 'fixed' && ! flexSize ) {
|
|
110
|
+
onChange( {
|
|
111
|
+
...childLayout,
|
|
112
|
+
selfStretch: 'fit',
|
|
113
|
+
} );
|
|
114
|
+
}
|
|
115
|
+
}, [] );
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<VStack
|
|
119
|
+
as={ ToolsPanelItem }
|
|
120
|
+
spacing={ 2 }
|
|
121
|
+
hasValue={ hasFlexValue }
|
|
122
|
+
label={ flexResetLabel }
|
|
123
|
+
onDeselect={ resetFlex }
|
|
124
|
+
isShownByDefault={ isShownByDefault }
|
|
125
|
+
panelId={ panelId }
|
|
126
|
+
>
|
|
127
|
+
<ToggleGroupControl
|
|
128
|
+
__nextHasNoMarginBottom
|
|
129
|
+
size="__unstable-large"
|
|
130
|
+
label={ childLayoutOrientation( parentLayout ) }
|
|
131
|
+
value={ selfStretch || 'fit' }
|
|
132
|
+
help={ helpText( selfStretch, parentLayout ) }
|
|
133
|
+
onChange={ ( value ) => {
|
|
134
|
+
const newFlexSize = value !== 'fixed' ? null : flexSize;
|
|
135
|
+
onChange( {
|
|
136
|
+
selfStretch: value,
|
|
137
|
+
flexSize: newFlexSize,
|
|
138
|
+
} );
|
|
139
|
+
} }
|
|
140
|
+
isBlock
|
|
141
|
+
>
|
|
142
|
+
<ToggleGroupControlOption
|
|
143
|
+
key="fit"
|
|
144
|
+
value="fit"
|
|
145
|
+
label={ __( 'Fit' ) }
|
|
146
|
+
/>
|
|
147
|
+
<ToggleGroupControlOption
|
|
148
|
+
key="fill"
|
|
149
|
+
value="fill"
|
|
150
|
+
label={ __( 'Fill' ) }
|
|
151
|
+
/>
|
|
152
|
+
<ToggleGroupControlOption
|
|
153
|
+
key="fixed"
|
|
154
|
+
value="fixed"
|
|
155
|
+
label={ __( 'Fixed' ) }
|
|
156
|
+
/>
|
|
157
|
+
</ToggleGroupControl>
|
|
158
|
+
{ selfStretch === 'fixed' && (
|
|
159
|
+
<UnitControl
|
|
160
|
+
size="__unstable-large"
|
|
161
|
+
onChange={ ( value ) => {
|
|
162
|
+
onChange( {
|
|
163
|
+
selfStretch,
|
|
164
|
+
flexSize: value,
|
|
165
|
+
} );
|
|
166
|
+
} }
|
|
167
|
+
value={ flexSize }
|
|
168
|
+
/>
|
|
169
|
+
) }
|
|
170
|
+
</VStack>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function childLayoutOrientation( parentLayout ) {
|
|
175
|
+
const { orientation = 'horizontal' } = parentLayout;
|
|
176
|
+
return orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function GridControls( {
|
|
180
|
+
childLayout,
|
|
181
|
+
onChange,
|
|
182
|
+
parentLayout,
|
|
183
|
+
isShownByDefault,
|
|
184
|
+
panelId,
|
|
185
|
+
} ) {
|
|
186
|
+
const { columnStart, rowStart, columnSpan, rowSpan } = childLayout;
|
|
187
|
+
const { columnCount } = parentLayout ?? {};
|
|
188
|
+
const gridColumnNumber = parseInt( columnCount, 10 ) || 3;
|
|
189
|
+
const rootClientId = useSelect( ( select ) =>
|
|
190
|
+
select( blockEditorStore ).getBlockRootClientId( panelId )
|
|
191
|
+
);
|
|
192
|
+
const { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } =
|
|
193
|
+
useDispatch( blockEditorStore );
|
|
194
|
+
const getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(
|
|
195
|
+
rootClientId,
|
|
196
|
+
gridColumnNumber
|
|
197
|
+
);
|
|
76
198
|
const hasStartValue = () => !! columnStart || !! rowStart;
|
|
77
199
|
const hasSpanValue = () => !! columnSpan || !! rowSpan;
|
|
78
200
|
const resetGridStarts = () => {
|
|
@@ -88,184 +210,127 @@ export default function ChildLayoutControl( {
|
|
|
88
210
|
} );
|
|
89
211
|
};
|
|
90
212
|
|
|
91
|
-
useEffect( () => {
|
|
92
|
-
if ( selfStretch === 'fixed' && ! flexSize ) {
|
|
93
|
-
onChange( {
|
|
94
|
-
...childLayout,
|
|
95
|
-
selfStretch: 'fit',
|
|
96
|
-
} );
|
|
97
|
-
}
|
|
98
|
-
}, [] );
|
|
99
|
-
|
|
100
213
|
return (
|
|
101
214
|
<>
|
|
102
|
-
|
|
103
|
-
|
|
215
|
+
<HStack
|
|
216
|
+
as={ ToolsPanelItem }
|
|
217
|
+
hasValue={ hasSpanValue }
|
|
218
|
+
label={ __( 'Grid span' ) }
|
|
219
|
+
onDeselect={ resetGridSpans }
|
|
220
|
+
isShownByDefault={ isShownByDefault }
|
|
221
|
+
panelId={ panelId }
|
|
222
|
+
>
|
|
223
|
+
<InputControl
|
|
224
|
+
size="__unstable-large"
|
|
225
|
+
label={ __( 'Column span' ) }
|
|
226
|
+
type="number"
|
|
227
|
+
onChange={ ( value ) => {
|
|
228
|
+
onChange( {
|
|
229
|
+
columnStart,
|
|
230
|
+
rowStart,
|
|
231
|
+
rowSpan,
|
|
232
|
+
columnSpan: value,
|
|
233
|
+
} );
|
|
234
|
+
} }
|
|
235
|
+
value={ columnSpan }
|
|
236
|
+
min={ 1 }
|
|
237
|
+
/>
|
|
238
|
+
<InputControl
|
|
239
|
+
size="__unstable-large"
|
|
240
|
+
label={ __( 'Row span' ) }
|
|
241
|
+
type="number"
|
|
242
|
+
onChange={ ( value ) => {
|
|
243
|
+
onChange( {
|
|
244
|
+
columnStart,
|
|
245
|
+
rowStart,
|
|
246
|
+
columnSpan,
|
|
247
|
+
rowSpan: value,
|
|
248
|
+
} );
|
|
249
|
+
} }
|
|
250
|
+
value={ rowSpan }
|
|
251
|
+
min={ 1 }
|
|
252
|
+
/>
|
|
253
|
+
</HStack>
|
|
254
|
+
{ window.__experimentalEnableGridInteractivity && columnCount && (
|
|
255
|
+
// Use Flex with an explicit width on the FlexItem instead of HStack to
|
|
256
|
+
// work around an issue in webkit where inputs with a max attribute are
|
|
257
|
+
// sized incorrectly.
|
|
258
|
+
<Flex
|
|
104
259
|
as={ ToolsPanelItem }
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
isShownByDefault={ isShownByDefault }
|
|
260
|
+
hasValue={ hasStartValue }
|
|
261
|
+
label={ __( 'Grid placement' ) }
|
|
262
|
+
onDeselect={ resetGridStarts }
|
|
263
|
+
isShownByDefault={ false }
|
|
110
264
|
panelId={ panelId }
|
|
111
265
|
>
|
|
112
|
-
<
|
|
113
|
-
__nextHasNoMarginBottom
|
|
114
|
-
size="__unstable-large"
|
|
115
|
-
label={ childLayoutOrientation( parentLayout ) }
|
|
116
|
-
value={ selfStretch || 'fit' }
|
|
117
|
-
help={ helpText( selfStretch, parentLayout ) }
|
|
118
|
-
onChange={ ( value ) => {
|
|
119
|
-
const newFlexSize =
|
|
120
|
-
value !== 'fixed' ? null : flexSize;
|
|
121
|
-
onChange( {
|
|
122
|
-
selfStretch: value,
|
|
123
|
-
flexSize: newFlexSize,
|
|
124
|
-
} );
|
|
125
|
-
} }
|
|
126
|
-
isBlock
|
|
127
|
-
>
|
|
128
|
-
<ToggleGroupControlOption
|
|
129
|
-
key="fit"
|
|
130
|
-
value="fit"
|
|
131
|
-
label={ __( 'Fit' ) }
|
|
132
|
-
/>
|
|
133
|
-
<ToggleGroupControlOption
|
|
134
|
-
key="fill"
|
|
135
|
-
value="fill"
|
|
136
|
-
label={ __( 'Fill' ) }
|
|
137
|
-
/>
|
|
138
|
-
<ToggleGroupControlOption
|
|
139
|
-
key="fixed"
|
|
140
|
-
value="fixed"
|
|
141
|
-
label={ __( 'Fixed' ) }
|
|
142
|
-
/>
|
|
143
|
-
</ToggleGroupControl>
|
|
144
|
-
{ selfStretch === 'fixed' && (
|
|
145
|
-
<UnitControl
|
|
146
|
-
size="__unstable-large"
|
|
147
|
-
onChange={ ( value ) => {
|
|
148
|
-
onChange( {
|
|
149
|
-
selfStretch,
|
|
150
|
-
flexSize: value,
|
|
151
|
-
} );
|
|
152
|
-
} }
|
|
153
|
-
value={ flexSize }
|
|
154
|
-
/>
|
|
155
|
-
) }
|
|
156
|
-
</VStack>
|
|
157
|
-
) }
|
|
158
|
-
{ parentLayoutType === 'grid' && (
|
|
159
|
-
<>
|
|
160
|
-
<HStack
|
|
161
|
-
as={ ToolsPanelItem }
|
|
162
|
-
hasValue={ hasSpanValue }
|
|
163
|
-
label={ __( 'Grid span' ) }
|
|
164
|
-
onDeselect={ resetGridSpans }
|
|
165
|
-
isShownByDefault={ isShownByDefault }
|
|
166
|
-
panelId={ panelId }
|
|
167
|
-
>
|
|
266
|
+
<FlexItem style={ { width: '50%' } }>
|
|
168
267
|
<InputControl
|
|
169
268
|
size="__unstable-large"
|
|
170
|
-
label={ __( 'Column
|
|
269
|
+
label={ __( 'Column' ) }
|
|
171
270
|
type="number"
|
|
172
271
|
onChange={ ( value ) => {
|
|
173
272
|
onChange( {
|
|
174
|
-
columnStart,
|
|
273
|
+
columnStart: value,
|
|
175
274
|
rowStart,
|
|
275
|
+
columnSpan,
|
|
176
276
|
rowSpan,
|
|
177
|
-
columnSpan: value,
|
|
178
277
|
} );
|
|
278
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
279
|
+
moveBlocksToPosition(
|
|
280
|
+
[ panelId ],
|
|
281
|
+
rootClientId,
|
|
282
|
+
rootClientId,
|
|
283
|
+
getNumberOfBlocksBeforeCell(
|
|
284
|
+
value,
|
|
285
|
+
rowStart
|
|
286
|
+
)
|
|
287
|
+
);
|
|
179
288
|
} }
|
|
180
|
-
value={
|
|
289
|
+
value={ columnStart }
|
|
181
290
|
min={ 1 }
|
|
291
|
+
max={
|
|
292
|
+
gridColumnNumber
|
|
293
|
+
? gridColumnNumber - ( columnSpan ?? 1 ) + 1
|
|
294
|
+
: undefined
|
|
295
|
+
}
|
|
182
296
|
/>
|
|
297
|
+
</FlexItem>
|
|
298
|
+
<FlexItem style={ { width: '50%' } }>
|
|
183
299
|
<InputControl
|
|
184
300
|
size="__unstable-large"
|
|
185
|
-
label={ __( 'Row
|
|
301
|
+
label={ __( 'Row' ) }
|
|
186
302
|
type="number"
|
|
187
303
|
onChange={ ( value ) => {
|
|
188
304
|
onChange( {
|
|
189
305
|
columnStart,
|
|
190
|
-
rowStart,
|
|
306
|
+
rowStart: value,
|
|
191
307
|
columnSpan,
|
|
192
|
-
rowSpan
|
|
308
|
+
rowSpan,
|
|
193
309
|
} );
|
|
310
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
311
|
+
moveBlocksToPosition(
|
|
312
|
+
[ panelId ],
|
|
313
|
+
rootClientId,
|
|
314
|
+
rootClientId,
|
|
315
|
+
getNumberOfBlocksBeforeCell(
|
|
316
|
+
columnStart,
|
|
317
|
+
value
|
|
318
|
+
)
|
|
319
|
+
);
|
|
194
320
|
} }
|
|
195
|
-
value={
|
|
321
|
+
value={ rowStart }
|
|
196
322
|
min={ 1 }
|
|
323
|
+
max={
|
|
324
|
+
parentLayout?.rowCount
|
|
325
|
+
? parentLayout.rowCount -
|
|
326
|
+
( rowSpan ?? 1 ) +
|
|
327
|
+
1
|
|
328
|
+
: undefined
|
|
329
|
+
}
|
|
197
330
|
/>
|
|
198
|
-
</
|
|
199
|
-
|
|
200
|
-
// Use Flex with an explicit width on the FlexItem instead of HStack to
|
|
201
|
-
// work around an issue in webkit where inputs with a max attribute are
|
|
202
|
-
// sized incorrectly.
|
|
203
|
-
<Flex
|
|
204
|
-
as={ ToolsPanelItem }
|
|
205
|
-
hasValue={ hasStartValue }
|
|
206
|
-
label={ __( 'Grid placement' ) }
|
|
207
|
-
onDeselect={ resetGridStarts }
|
|
208
|
-
isShownByDefault={ false }
|
|
209
|
-
panelId={ panelId }
|
|
210
|
-
>
|
|
211
|
-
<FlexItem style={ { width: '50%' } }>
|
|
212
|
-
<InputControl
|
|
213
|
-
size="__unstable-large"
|
|
214
|
-
label={ __( 'Column' ) }
|
|
215
|
-
type="number"
|
|
216
|
-
onChange={ ( value ) => {
|
|
217
|
-
onChange( {
|
|
218
|
-
columnStart: value,
|
|
219
|
-
rowStart,
|
|
220
|
-
columnSpan,
|
|
221
|
-
rowSpan,
|
|
222
|
-
} );
|
|
223
|
-
} }
|
|
224
|
-
value={ columnStart }
|
|
225
|
-
min={ 1 }
|
|
226
|
-
max={
|
|
227
|
-
parentLayout?.columnCount
|
|
228
|
-
? parentLayout.columnCount -
|
|
229
|
-
( columnSpan ?? 1 ) +
|
|
230
|
-
1
|
|
231
|
-
: undefined
|
|
232
|
-
}
|
|
233
|
-
/>
|
|
234
|
-
</FlexItem>
|
|
235
|
-
<FlexItem style={ { width: '50%' } }>
|
|
236
|
-
<InputControl
|
|
237
|
-
size="__unstable-large"
|
|
238
|
-
label={ __( 'Row' ) }
|
|
239
|
-
type="number"
|
|
240
|
-
onChange={ ( value ) => {
|
|
241
|
-
onChange( {
|
|
242
|
-
columnStart,
|
|
243
|
-
rowStart: value,
|
|
244
|
-
columnSpan,
|
|
245
|
-
rowSpan,
|
|
246
|
-
} );
|
|
247
|
-
} }
|
|
248
|
-
value={ rowStart }
|
|
249
|
-
min={ 1 }
|
|
250
|
-
max={
|
|
251
|
-
parentLayout?.rowCount
|
|
252
|
-
? parentLayout.rowCount -
|
|
253
|
-
( rowSpan ?? 1 ) +
|
|
254
|
-
1
|
|
255
|
-
: undefined
|
|
256
|
-
}
|
|
257
|
-
/>
|
|
258
|
-
</FlexItem>
|
|
259
|
-
</Flex>
|
|
260
|
-
) }
|
|
261
|
-
</>
|
|
331
|
+
</FlexItem>
|
|
332
|
+
</Flex>
|
|
262
333
|
) }
|
|
263
334
|
</>
|
|
264
335
|
);
|
|
265
336
|
}
|
|
266
|
-
|
|
267
|
-
export function childLayoutOrientation( parentLayout ) {
|
|
268
|
-
const { orientation = 'horizontal' } = parentLayout;
|
|
269
|
-
|
|
270
|
-
return orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );
|
|
271
|
-
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { _x, __ } from '@wordpress/i18n';
|
|
5
|
-
import { dateI18n } from '@wordpress/date';
|
|
5
|
+
import { dateI18n, humanTimeDiff } from '@wordpress/date';
|
|
6
6
|
import { useState, createInterpolateElement } from '@wordpress/element';
|
|
7
7
|
import {
|
|
8
8
|
TextControl,
|
|
@@ -13,11 +13,15 @@ import {
|
|
|
13
13
|
__experimentalVStack as VStack,
|
|
14
14
|
} from '@wordpress/components';
|
|
15
15
|
|
|
16
|
-
// So that we
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
// So that we illustrate the different formats in the dropdown properly, show a date that is
|
|
17
|
+
// somwhat recent, has a day greater than 12, and a month with more than three letters.
|
|
18
|
+
const exampleDate = new Date();
|
|
19
|
+
exampleDate.setDate( 20 );
|
|
20
|
+
exampleDate.setMonth( exampleDate.getMonth() - 3 );
|
|
21
|
+
if ( exampleDate.getMonth() === 4 ) {
|
|
22
|
+
// May has three letters, so use March.
|
|
23
|
+
exampleDate.setMonth( 3 );
|
|
24
|
+
}
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* The `DateFormatPicker` component renders controls that let the user choose a
|
|
@@ -54,7 +58,7 @@ export default function DateFormatPicker( {
|
|
|
54
58
|
label={ __( 'Default format' ) }
|
|
55
59
|
help={ `${ __( 'Example:' ) } ${ dateI18n(
|
|
56
60
|
defaultFormat,
|
|
57
|
-
|
|
61
|
+
exampleDate
|
|
58
62
|
) }` }
|
|
59
63
|
checked={ ! format }
|
|
60
64
|
onChange={ ( checked ) =>
|
|
@@ -95,13 +99,19 @@ function NonDefaultControls( { format, onChange } ) {
|
|
|
95
99
|
] ),
|
|
96
100
|
];
|
|
97
101
|
|
|
98
|
-
const suggestedOptions =
|
|
99
|
-
( suggestedFormat, index ) => ( {
|
|
102
|
+
const suggestedOptions = [
|
|
103
|
+
...suggestedFormats.map( ( suggestedFormat, index ) => ( {
|
|
100
104
|
key: `suggested-${ index }`,
|
|
101
|
-
name: dateI18n( suggestedFormat,
|
|
105
|
+
name: dateI18n( suggestedFormat, exampleDate ),
|
|
102
106
|
format: suggestedFormat,
|
|
103
|
-
} )
|
|
104
|
-
|
|
107
|
+
} ) ),
|
|
108
|
+
{
|
|
109
|
+
key: 'human-diff',
|
|
110
|
+
name: humanTimeDiff( exampleDate ),
|
|
111
|
+
format: 'human-diff',
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
105
115
|
const customOption = {
|
|
106
116
|
key: 'custom',
|
|
107
117
|
name: __( 'Custom' ),
|
|
@@ -111,7 +121,9 @@ function NonDefaultControls( { format, onChange } ) {
|
|
|
111
121
|
};
|
|
112
122
|
|
|
113
123
|
const [ isCustom, setIsCustom ] = useState(
|
|
114
|
-
() =>
|
|
124
|
+
() =>
|
|
125
|
+
!! format &&
|
|
126
|
+
! suggestedOptions.some( ( option ) => option.format === format )
|
|
115
127
|
);
|
|
116
128
|
|
|
117
129
|
return (
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { ToolbarButton } from '@wordpress/components';
|
|
6
|
+
import { arrowLeft, arrowUp, arrowDown, arrowRight } from '@wordpress/icons';
|
|
7
|
+
import { useDispatch } from '@wordpress/data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import BlockControls from '../block-controls';
|
|
13
|
+
import { useGetNumberOfBlocksBeforeCell } from './use-get-number-of-blocks-before-cell';
|
|
14
|
+
import { store as blockEditorStore } from '../../store';
|
|
15
|
+
|
|
16
|
+
export function GridItemMovers( {
|
|
17
|
+
layout,
|
|
18
|
+
parentLayout,
|
|
19
|
+
onChange,
|
|
20
|
+
gridClientId,
|
|
21
|
+
blockClientId,
|
|
22
|
+
} ) {
|
|
23
|
+
const { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } =
|
|
24
|
+
useDispatch( blockEditorStore );
|
|
25
|
+
|
|
26
|
+
const columnStart = layout?.columnStart ?? 1;
|
|
27
|
+
const rowStart = layout?.rowStart ?? 1;
|
|
28
|
+
const columnSpan = layout?.columnSpan ?? 1;
|
|
29
|
+
const rowSpan = layout?.rowSpan ?? 1;
|
|
30
|
+
const columnEnd = columnStart + columnSpan - 1;
|
|
31
|
+
const rowEnd = rowStart + rowSpan - 1;
|
|
32
|
+
const columnCount = parentLayout?.columnCount;
|
|
33
|
+
const rowCount = parentLayout?.rowCount;
|
|
34
|
+
|
|
35
|
+
const columnCountNumber = parseInt( columnCount, 10 );
|
|
36
|
+
const rowStartNumber = parseInt( rowStart, 10 );
|
|
37
|
+
const columnStartNumber = parseInt( columnStart, 10 );
|
|
38
|
+
|
|
39
|
+
const getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(
|
|
40
|
+
gridClientId,
|
|
41
|
+
columnCountNumber
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<BlockControls group="parent">
|
|
46
|
+
<ToolbarButton
|
|
47
|
+
icon={ arrowUp }
|
|
48
|
+
label={ __( 'Move block up' ) }
|
|
49
|
+
isDisabled={ rowStart <= 1 }
|
|
50
|
+
onClick={ () => {
|
|
51
|
+
onChange( {
|
|
52
|
+
rowStart: rowStart - 1,
|
|
53
|
+
} );
|
|
54
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
55
|
+
moveBlocksToPosition(
|
|
56
|
+
[ blockClientId ],
|
|
57
|
+
gridClientId,
|
|
58
|
+
gridClientId,
|
|
59
|
+
getNumberOfBlocksBeforeCell(
|
|
60
|
+
columnStartNumber,
|
|
61
|
+
rowStartNumber - 1
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
} }
|
|
65
|
+
/>
|
|
66
|
+
<ToolbarButton
|
|
67
|
+
icon={ arrowDown }
|
|
68
|
+
label={ __( 'Move block down' ) }
|
|
69
|
+
isDisabled={ rowCount && rowEnd >= rowCount }
|
|
70
|
+
onClick={ () => {
|
|
71
|
+
onChange( {
|
|
72
|
+
rowStart: rowStart + 1,
|
|
73
|
+
} );
|
|
74
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
75
|
+
moveBlocksToPosition(
|
|
76
|
+
[ blockClientId ],
|
|
77
|
+
gridClientId,
|
|
78
|
+
gridClientId,
|
|
79
|
+
getNumberOfBlocksBeforeCell(
|
|
80
|
+
columnStartNumber,
|
|
81
|
+
rowStartNumber + 1
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
} }
|
|
85
|
+
/>
|
|
86
|
+
<ToolbarButton
|
|
87
|
+
icon={ arrowLeft }
|
|
88
|
+
label={ __( 'Move block left' ) }
|
|
89
|
+
isDisabled={ columnStart <= 1 }
|
|
90
|
+
onClick={ () => {
|
|
91
|
+
onChange( {
|
|
92
|
+
columnStart: columnStartNumber - 1,
|
|
93
|
+
} );
|
|
94
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
95
|
+
moveBlocksToPosition(
|
|
96
|
+
[ blockClientId ],
|
|
97
|
+
gridClientId,
|
|
98
|
+
gridClientId,
|
|
99
|
+
getNumberOfBlocksBeforeCell(
|
|
100
|
+
columnStartNumber - 1,
|
|
101
|
+
rowStartNumber
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
} }
|
|
105
|
+
/>
|
|
106
|
+
<ToolbarButton
|
|
107
|
+
icon={ arrowRight }
|
|
108
|
+
label={ __( 'Move block right' ) }
|
|
109
|
+
isDisabled={ columnCount && columnEnd >= columnCount }
|
|
110
|
+
onClick={ () => {
|
|
111
|
+
onChange( {
|
|
112
|
+
columnStart: columnStartNumber + 1,
|
|
113
|
+
} );
|
|
114
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
115
|
+
moveBlocksToPosition(
|
|
116
|
+
[ blockClientId ],
|
|
117
|
+
gridClientId,
|
|
118
|
+
gridClientId,
|
|
119
|
+
getNumberOfBlocksBeforeCell(
|
|
120
|
+
columnStartNumber + 1,
|
|
121
|
+
rowStartNumber
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
} }
|
|
125
|
+
/>
|
|
126
|
+
</BlockControls>
|
|
127
|
+
);
|
|
128
|
+
}
|