@wordpress/block-editor 15.10.1-next.ba3aee3a2.0 → 15.10.1-next.v.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 (159) hide show
  1. package/build/components/block-bindings/attribute-control.cjs +1 -1
  2. package/build/components/block-bindings/attribute-control.cjs.map +1 -1
  3. package/build/components/block-bindings/source-fields-list.cjs +1 -1
  4. package/build/components/block-bindings/source-fields-list.cjs.map +1 -1
  5. package/build/components/block-tools/index.cjs +82 -70
  6. package/build/components/block-tools/index.cjs.map +2 -2
  7. package/build/components/block-visibility/block-visibility-info.cjs +0 -59
  8. package/build/components/block-visibility/block-visibility-info.cjs.map +3 -3
  9. package/build/components/block-visibility/constants.cjs +10 -5
  10. package/build/components/block-visibility/constants.cjs.map +2 -2
  11. package/build/components/block-visibility/index.cjs +13 -5
  12. package/build/components/block-visibility/index.cjs.map +3 -3
  13. package/build/components/block-visibility/modal.cjs +397 -0
  14. package/build/components/block-visibility/modal.cjs.map +7 -0
  15. package/build/components/block-visibility/toolbar.cjs +1 -1
  16. package/build/components/block-visibility/toolbar.cjs.map +2 -2
  17. package/build/components/block-visibility/use-block-visibility.cjs +13 -17
  18. package/build/components/block-visibility/use-block-visibility.cjs.map +2 -2
  19. package/build/components/block-visibility/utils.cjs +81 -0
  20. package/build/components/block-visibility/utils.cjs.map +7 -0
  21. package/build/components/block-visibility/viewport-menu-item.cjs +61 -0
  22. package/build/components/block-visibility/viewport-menu-item.cjs.map +7 -0
  23. package/build/components/block-visibility/viewport-toolbar.cjs +89 -0
  24. package/build/components/block-visibility/viewport-toolbar.cjs.map +7 -0
  25. package/build/components/inner-blocks/use-inner-block-template-sync.cjs +1 -1
  26. package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +1 -1
  27. package/build/components/inserter/menu.cjs +6 -2
  28. package/build/components/inserter/menu.cjs.map +2 -2
  29. package/build/components/list-view/block-select-button.cjs +2 -2
  30. package/build/components/list-view/block-select-button.cjs.map +2 -2
  31. package/build/components/list-view/block.cjs +39 -22
  32. package/build/components/list-view/block.cjs.map +2 -2
  33. package/build/components/rich-text/index.cjs +1 -1
  34. package/build/components/rich-text/index.cjs.map +1 -1
  35. package/build/components/url-input/index.cjs +2 -0
  36. package/build/components/url-input/index.cjs.map +2 -2
  37. package/build/components/use-block-commands/index.cjs +1 -1
  38. package/build/components/use-block-commands/index.cjs.map +2 -2
  39. package/build/hooks/block-fields/index.cjs +75 -166
  40. package/build/hooks/block-fields/index.cjs.map +2 -2
  41. package/build/hooks/block-fields/link/index.cjs +13 -23
  42. package/build/hooks/block-fields/link/index.cjs.map +2 -2
  43. package/build/hooks/block-fields/media/index.cjs +32 -58
  44. package/build/hooks/block-fields/media/index.cjs.map +2 -2
  45. package/build/hooks/block-fields/rich-text/index.cjs +1 -5
  46. package/build/hooks/block-fields/rich-text/index.cjs.map +2 -2
  47. package/build/hooks/cross-origin-isolation.cjs +102 -0
  48. package/build/hooks/cross-origin-isolation.cjs.map +7 -0
  49. package/build/hooks/index.cjs +1 -0
  50. package/build/hooks/index.cjs.map +2 -2
  51. package/build/layouts/flex.cjs +6 -2
  52. package/build/layouts/flex.cjs.map +2 -2
  53. package/build/store/private-selectors.cjs +33 -1
  54. package/build/store/private-selectors.cjs.map +3 -3
  55. package/build/store/reducer.cjs +1 -1
  56. package/build/store/reducer.cjs.map +1 -1
  57. package/build/store/selectors.cjs +7 -8
  58. package/build/store/selectors.cjs.map +2 -2
  59. package/build-module/components/block-bindings/attribute-control.mjs +1 -1
  60. package/build-module/components/block-bindings/attribute-control.mjs.map +1 -1
  61. package/build-module/components/block-bindings/source-fields-list.mjs +1 -1
  62. package/build-module/components/block-bindings/source-fields-list.mjs.map +1 -1
  63. package/build-module/components/block-tools/index.mjs +85 -73
  64. package/build-module/components/block-tools/index.mjs.map +2 -2
  65. package/build-module/components/block-visibility/block-visibility-info.mjs +0 -59
  66. package/build-module/components/block-visibility/block-visibility-info.mjs.map +3 -3
  67. package/build-module/components/block-visibility/constants.mjs +8 -4
  68. package/build-module/components/block-visibility/constants.mjs.map +2 -2
  69. package/build-module/components/block-visibility/index.mjs +13 -6
  70. package/build-module/components/block-visibility/index.mjs.map +2 -2
  71. package/build-module/components/block-visibility/modal.mjs +384 -0
  72. package/build-module/components/block-visibility/modal.mjs.map +7 -0
  73. package/build-module/components/block-visibility/toolbar.mjs +1 -1
  74. package/build-module/components/block-visibility/toolbar.mjs.map +2 -2
  75. package/build-module/components/block-visibility/use-block-visibility.mjs +13 -13
  76. package/build-module/components/block-visibility/use-block-visibility.mjs.map +2 -2
  77. package/build-module/components/block-visibility/utils.mjs +55 -0
  78. package/build-module/components/block-visibility/utils.mjs.map +7 -0
  79. package/build-module/components/block-visibility/viewport-menu-item.mjs +40 -0
  80. package/build-module/components/block-visibility/viewport-menu-item.mjs.map +7 -0
  81. package/build-module/components/block-visibility/viewport-toolbar.mjs +68 -0
  82. package/build-module/components/block-visibility/viewport-toolbar.mjs.map +7 -0
  83. package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +1 -1
  84. package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +1 -1
  85. package/build-module/components/inserter/menu.mjs +6 -2
  86. package/build-module/components/inserter/menu.mjs.map +2 -2
  87. package/build-module/components/list-view/block-select-button.mjs +2 -2
  88. package/build-module/components/list-view/block-select-button.mjs.map +2 -2
  89. package/build-module/components/list-view/block.mjs +39 -22
  90. package/build-module/components/list-view/block.mjs.map +2 -2
  91. package/build-module/components/rich-text/index.mjs +1 -1
  92. package/build-module/components/rich-text/index.mjs.map +1 -1
  93. package/build-module/components/url-input/index.mjs +2 -0
  94. package/build-module/components/url-input/index.mjs.map +2 -2
  95. package/build-module/components/use-block-commands/index.mjs +1 -1
  96. package/build-module/components/use-block-commands/index.mjs.map +2 -2
  97. package/build-module/hooks/block-fields/index.mjs +75 -166
  98. package/build-module/hooks/block-fields/index.mjs.map +2 -2
  99. package/build-module/hooks/block-fields/link/index.mjs +13 -23
  100. package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
  101. package/build-module/hooks/block-fields/media/index.mjs +32 -58
  102. package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
  103. package/build-module/hooks/block-fields/rich-text/index.mjs +1 -5
  104. package/build-module/hooks/block-fields/rich-text/index.mjs.map +2 -2
  105. package/build-module/hooks/cross-origin-isolation.mjs +100 -0
  106. package/build-module/hooks/cross-origin-isolation.mjs.map +7 -0
  107. package/build-module/hooks/index.mjs +1 -0
  108. package/build-module/hooks/index.mjs.map +2 -2
  109. package/build-module/layouts/flex.mjs +6 -2
  110. package/build-module/layouts/flex.mjs.map +2 -2
  111. package/build-module/store/private-selectors.mjs +34 -1
  112. package/build-module/store/private-selectors.mjs.map +2 -2
  113. package/build-module/store/reducer.mjs +1 -1
  114. package/build-module/store/reducer.mjs.map +1 -1
  115. package/build-module/store/selectors.mjs +7 -8
  116. package/build-module/store/selectors.mjs.map +2 -2
  117. package/build-style/content-rtl.css +4 -1
  118. package/build-style/content.css +4 -1
  119. package/build-style/style-rtl.css +48 -0
  120. package/build-style/style.css +48 -0
  121. package/package.json +39 -39
  122. package/src/components/block-bindings/attribute-control.js +1 -1
  123. package/src/components/block-bindings/source-fields-list.js +1 -1
  124. package/src/components/block-list/content.scss +4 -1
  125. package/src/components/block-tools/index.js +45 -33
  126. package/src/components/block-visibility/block-visibility-info.js +0 -1
  127. package/src/components/block-visibility/constants.js +7 -3
  128. package/src/components/block-visibility/index.js +21 -3
  129. package/src/components/block-visibility/modal.js +358 -0
  130. package/src/components/block-visibility/style.scss +58 -0
  131. package/src/components/block-visibility/test/use-block-visibility.js +12 -56
  132. package/src/components/block-visibility/test/utils.js +266 -0
  133. package/src/components/block-visibility/toolbar.js +1 -1
  134. package/src/components/block-visibility/use-block-visibility.js +18 -21
  135. package/src/components/block-visibility/utils.js +95 -0
  136. package/src/components/block-visibility/viewport-menu-item.js +42 -0
  137. package/src/components/block-visibility/viewport-toolbar.js +88 -0
  138. package/src/components/inner-blocks/use-inner-block-template-sync.js +1 -1
  139. package/src/components/inserter/menu.js +6 -2
  140. package/src/components/list-view/block-select-button.js +2 -2
  141. package/src/components/list-view/block.js +47 -25
  142. package/src/components/rich-text/index.js +1 -1
  143. package/src/components/url-input/index.js +2 -0
  144. package/src/components/use-block-commands/index.js +4 -3
  145. package/src/hooks/block-fields/index.js +104 -224
  146. package/src/hooks/block-fields/link/index.js +13 -39
  147. package/src/hooks/block-fields/media/index.js +31 -90
  148. package/src/hooks/block-fields/rich-text/index.js +1 -5
  149. package/src/hooks/block-fields/styles.scss +2 -0
  150. package/src/hooks/cross-origin-isolation.js +143 -0
  151. package/src/hooks/index.js +1 -0
  152. package/src/layouts/flex.js +8 -3
  153. package/src/layouts/test/flex.js +53 -0
  154. package/src/store/private-selectors.js +64 -1
  155. package/src/store/reducer.js +1 -1
  156. package/src/store/selectors.js +7 -9
  157. package/src/store/test/private-selectors.js +80 -0
  158. package/src/style.scss +1 -0
  159. package/src/components/block-visibility/styles.scss +0 -10
@@ -0,0 +1,358 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { __, sprintf } from '@wordpress/i18n';
10
+ import {
11
+ useState,
12
+ useMemo,
13
+ useCallback,
14
+ createInterpolateElement,
15
+ } from '@wordpress/element';
16
+ import {
17
+ Button,
18
+ CheckboxControl,
19
+ Flex,
20
+ FlexItem,
21
+ Icon,
22
+ Modal,
23
+ } from '@wordpress/components';
24
+ import { useDispatch, useSelect } from '@wordpress/data';
25
+ import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
26
+ import { store as noticesStore } from '@wordpress/notices';
27
+
28
+ /**
29
+ * Internal dependencies
30
+ */
31
+ import {
32
+ BLOCK_VISIBILITY_VIEWPORT_ENTRIES,
33
+ BLOCK_VISIBILITY_VIEWPORTS,
34
+ } from './constants';
35
+ import { store as blockEditorStore } from '../../store';
36
+ import { cleanEmptyObject } from '../../hooks/utils';
37
+ import {
38
+ getViewportCheckboxState,
39
+ getHideEverywhereCheckboxState,
40
+ } from './utils';
41
+ import './style.scss';
42
+
43
+ const DEFAULT_VIEWPORT_CHECKBOX_VALUES = {
44
+ [ BLOCK_VISIBILITY_VIEWPORTS.mobile.key ]: false,
45
+ [ BLOCK_VISIBILITY_VIEWPORTS.tablet.key ]: false,
46
+ [ BLOCK_VISIBILITY_VIEWPORTS.desktop.key ]: false,
47
+ };
48
+
49
+ const EMPTY_BLOCKS = [];
50
+
51
+ /**
52
+ * Modal component for configuring block visibility across viewports.
53
+ *
54
+ * Allows users to hide blocks on specific viewport sizes (mobile, tablet, desktop)
55
+ * or hide them everywhere. When editing multiple blocks, checkboxes only show as
56
+ * checked if ALL selected blocks share the same setting to avoid ambiguity.
57
+ *
58
+ * @param {Object} props Component props.
59
+ * @param {Array} props.clientIds The client IDs of the blocks to hide.
60
+ * @param {Function} props.onClose Callback function invoked when the modal is closed.
61
+ * @return {JSX.Element} The modal component.
62
+ */
63
+ export default function BlockVisibilityModal( { clientIds, onClose } ) {
64
+ const { createSuccessNotice } = useDispatch( noticesStore );
65
+ const { updateBlockAttributes } = useDispatch( blockEditorStore );
66
+
67
+ const blocks = useSelect(
68
+ ( select ) =>
69
+ select( blockEditorStore ).getBlocksByClientId( clientIds ) ??
70
+ EMPTY_BLOCKS,
71
+ [ clientIds ]
72
+ );
73
+ const listViewShortcut = useSelect( ( select ) => {
74
+ return select( keyboardShortcutsStore ).getShortcutRepresentation(
75
+ 'core/editor/toggle-list-view'
76
+ );
77
+ }, [] );
78
+
79
+ const initialViewportValues = useMemo( () => {
80
+ if ( blocks?.length === 0 ) {
81
+ return {
82
+ hideEverywhere: false,
83
+ viewportChecked: {},
84
+ };
85
+ }
86
+
87
+ const viewportValues = {};
88
+
89
+ BLOCK_VISIBILITY_VIEWPORT_ENTRIES.forEach( ( [ , { key } ] ) => {
90
+ viewportValues[ key ] = getViewportCheckboxState( blocks, key );
91
+ } );
92
+
93
+ return {
94
+ hideEverywhere: getHideEverywhereCheckboxState( blocks ),
95
+ viewportChecked: viewportValues,
96
+ };
97
+ }, [ blocks ] );
98
+
99
+ const [ viewportChecked, setViewportChecked ] = useState(
100
+ initialViewportValues?.viewportChecked ?? {}
101
+ );
102
+ const [ hideEverywhere, setHideEverywhere ] = useState(
103
+ initialViewportValues?.hideEverywhere ?? false
104
+ );
105
+
106
+ const handleViewportCheckboxChange = useCallback(
107
+ ( viewport, isChecked ) => {
108
+ setViewportChecked( {
109
+ ...viewportChecked,
110
+ [ viewport ]: isChecked,
111
+ } );
112
+ },
113
+ [ viewportChecked ]
114
+ );
115
+
116
+ const noticeMessage = useMemo( () => {
117
+ if ( ! hideEverywhere ) {
118
+ return sprintf(
119
+ // translators: %s: The shortcut key to access the List View.
120
+ __(
121
+ 'Block visibility settings saved. You can access them via the List View (%s).'
122
+ ),
123
+ listViewShortcut
124
+ );
125
+ }
126
+
127
+ const message =
128
+ blocks?.length > 1
129
+ ? // translators: %s: The shortcut key to access the List View.
130
+ __(
131
+ 'Blocks hidden. You can access them via the List View (%s).'
132
+ )
133
+ : // translators: %s: The shortcut key to access the List View.
134
+ __(
135
+ 'Block hidden. You can access it via the List View (%s).'
136
+ );
137
+
138
+ return sprintf( message, listViewShortcut );
139
+ }, [ hideEverywhere, blocks?.length, listViewShortcut ] );
140
+
141
+ const isAnyViewportChecked = useMemo(
142
+ () =>
143
+ Object.values( viewportChecked ).some(
144
+ ( checked ) => checked === true || checked === null
145
+ ),
146
+ [ viewportChecked ]
147
+ );
148
+
149
+ const hasIndeterminateValues = useMemo( () => {
150
+ if ( hideEverywhere === null ) {
151
+ return true;
152
+ }
153
+ return Object.values( viewportChecked ).some(
154
+ ( checked ) => checked === null
155
+ );
156
+ }, [ hideEverywhere, viewportChecked ] );
157
+
158
+ const handleSubmit = useCallback(
159
+ ( event ) => {
160
+ event.preventDefault();
161
+ const newVisibility = hideEverywhere
162
+ ? false
163
+ : BLOCK_VISIBILITY_VIEWPORT_ENTRIES.reduce(
164
+ ( acc, [ , { key } ] ) => {
165
+ if ( viewportChecked[ key ] ) {
166
+ // Values are inverted to hide the block on the selected viewport.
167
+ // In the UI, the checkbox is checked (true) when the block is hidden on the selected viewport,
168
+ // so 'false' means hide the block on the selected viewport.
169
+ acc[ key ] = false;
170
+ }
171
+ return acc;
172
+ },
173
+ {}
174
+ );
175
+ const attributesByClientId = Object.fromEntries(
176
+ blocks.map( ( { clientId, attributes } ) => [
177
+ clientId,
178
+ {
179
+ metadata: cleanEmptyObject( {
180
+ ...attributes?.metadata,
181
+ blockVisibility: newVisibility,
182
+ } ),
183
+ },
184
+ ] )
185
+ );
186
+ updateBlockAttributes( clientIds, attributesByClientId, {
187
+ uniqueByBlock: true,
188
+ } );
189
+
190
+ createSuccessNotice( noticeMessage, {
191
+ id: hideEverywhere
192
+ ? 'block-visibility-hidden'
193
+ : 'block-visibility-viewports-saved',
194
+ type: 'snackbar',
195
+ } );
196
+ onClose();
197
+ },
198
+ [
199
+ blocks,
200
+ clientIds,
201
+ createSuccessNotice,
202
+ hideEverywhere,
203
+ noticeMessage,
204
+ onClose,
205
+ updateBlockAttributes,
206
+ viewportChecked,
207
+ ]
208
+ );
209
+
210
+ const hasMultipleBlocks = blocks?.length > 1;
211
+
212
+ return (
213
+ <Modal
214
+ title={
215
+ clientIds?.length > 1 ? __( 'Hide blocks' ) : __( 'Hide block' )
216
+ }
217
+ onRequestClose={ onClose }
218
+ overlayClassName="block-editor-block-visibility-modal"
219
+ size="small"
220
+ >
221
+ <form onSubmit={ handleSubmit }>
222
+ <fieldset>
223
+ <legend>
224
+ { hasMultipleBlocks
225
+ ? __(
226
+ 'Select the viewport sizes for which you want to hide the blocks. Changes will apply to all selected blocks.'
227
+ )
228
+ : __(
229
+ 'Select the viewport size for which you want to hide the block.'
230
+ ) }
231
+ </legend>
232
+ <ul className="block-editor-block-visibility-modal__options">
233
+ <li className="block-editor-block-visibility-modal__options-item block-editor-block-visibility-modal__options-item--everywhere">
234
+ <CheckboxControl
235
+ className="block-editor-block-visibility-modal__options-checkbox--everywhere"
236
+ label={ __( 'Omit from published content' ) }
237
+ checked={ hideEverywhere === true }
238
+ indeterminate={ hideEverywhere === null }
239
+ onChange={ ( checked ) => {
240
+ setHideEverywhere( checked );
241
+ // Reset viewport checkboxes when hide everywhere is checked.
242
+ setViewportChecked(
243
+ DEFAULT_VIEWPORT_CHECKBOX_VALUES
244
+ );
245
+ } }
246
+ />
247
+ { hideEverywhere !== true && (
248
+ <ul className="block-editor-block-visibility-modal__sub-options">
249
+ { BLOCK_VISIBILITY_VIEWPORT_ENTRIES.map(
250
+ ( [ , { label, icon, key } ] ) => (
251
+ <li
252
+ key={ key }
253
+ className="block-editor-block-visibility-modal__options-item"
254
+ >
255
+ <CheckboxControl
256
+ label={ sprintf(
257
+ // translators: %s: The viewport name.
258
+ __( 'Hide on %s' ),
259
+ label
260
+ ) }
261
+ checked={
262
+ viewportChecked[
263
+ key
264
+ ] ?? false
265
+ }
266
+ indeterminate={
267
+ viewportChecked[
268
+ key
269
+ ] === null
270
+ }
271
+ onChange={ ( checked ) =>
272
+ handleViewportCheckboxChange(
273
+ key,
274
+ checked
275
+ )
276
+ }
277
+ />
278
+ <Icon
279
+ icon={ icon }
280
+ className={ clsx( {
281
+ 'block-editor-block-visibility-modal__options-icon--checked':
282
+ viewportChecked[
283
+ key
284
+ ],
285
+ } ) }
286
+ />
287
+ </li>
288
+ )
289
+ ) }
290
+ </ul>
291
+ ) }
292
+ </li>
293
+ </ul>
294
+ { hasMultipleBlocks && hasIndeterminateValues && (
295
+ <p className="block-editor-block-visibility-modal__description">
296
+ { __(
297
+ 'Selected blocks have different visibility settings. The checkboxes show an indeterminate state when settings differ.'
298
+ ) }
299
+ </p>
300
+ ) }
301
+ { ! hasMultipleBlocks && hideEverywhere === true && (
302
+ <p className="block-editor-block-visibility-modal__description">
303
+ { sprintf(
304
+ // translators: %s: The shortcut key to access the List View.
305
+ __(
306
+ 'Block will be hidden in the editor, and omitted from the published markup on the frontend. You can configure it again by selecting it in the List View (%s).'
307
+ ),
308
+ listViewShortcut
309
+ ) }
310
+ </p>
311
+ ) }
312
+ { ! hasMultipleBlocks &&
313
+ ! hideEverywhere &&
314
+ isAnyViewportChecked && (
315
+ <p className="block-editor-block-visibility-modal__description">
316
+ { createInterpolateElement(
317
+ sprintf(
318
+ // translators: %s: The shortcut key to access the List View
319
+ __(
320
+ 'Block will be hidden according to the selected viewports. It will be <strong>included in the published markup on the frontend</strong>. You can configure it again by selecting it in the List View (%s).'
321
+ ),
322
+ listViewShortcut
323
+ ),
324
+ {
325
+ strong: <strong />,
326
+ }
327
+ ) }
328
+ </p>
329
+ ) }
330
+ </fieldset>
331
+ <Flex
332
+ className="block-editor-block-visibility-modal__actions"
333
+ justify="flex-end"
334
+ expanded={ false }
335
+ >
336
+ <FlexItem>
337
+ <Button
338
+ variant="tertiary"
339
+ onClick={ onClose }
340
+ __next40pxDefaultSize
341
+ >
342
+ { __( 'Cancel' ) }
343
+ </Button>
344
+ </FlexItem>
345
+ <FlexItem>
346
+ <Button
347
+ variant="primary"
348
+ type="submit"
349
+ __next40pxDefaultSize
350
+ >
351
+ { __( 'Apply' ) }
352
+ </Button>
353
+ </FlexItem>
354
+ </Flex>
355
+ </form>
356
+ </Modal>
357
+ );
358
+ }
@@ -0,0 +1,58 @@
1
+ @use "@wordpress/base-styles/variables" as *;
2
+ @use "@wordpress/base-styles/colors" as *;
3
+ @use "@wordpress/base-styles/z-index" as *;
4
+
5
+ .block-editor-block-visibility-modal {
6
+ z-index: z-index(".block-editor-block-visibility-modal");
7
+
8
+ &__options {
9
+ border: 0;
10
+ padding: 0;
11
+ list-style: none;
12
+ margin: $grid-unit-30 0;
13
+
14
+ &-item {
15
+ display: flex;
16
+ align-items: center;
17
+ justify-content: space-between;
18
+ margin: 0 0 $grid-unit-20 0;
19
+ gap: $grid-unit-30;
20
+ }
21
+
22
+ &-item:last-child {
23
+ margin: 0;
24
+ }
25
+
26
+ &-item--everywhere {
27
+ flex-direction: column;
28
+ align-items: start;
29
+ }
30
+
31
+ &-checkbox--everywhere {
32
+ font-weight: 600;
33
+ }
34
+
35
+ &-icon--checked {
36
+ fill: $gray-300;
37
+ }
38
+ }
39
+
40
+ &__sub-options {
41
+ width: 100%;
42
+ padding-inline-start: $grid-unit-15;
43
+ }
44
+
45
+ &__description {
46
+ font-size: $font-size-small;
47
+ color: $gray-700;
48
+ }
49
+ }
50
+
51
+ .block-editor-block-visibility-info {
52
+ padding-top: $grid-unit-05;
53
+ padding-bottom: $grid-unit-05;
54
+ margin: 0 $grid-unit-20 $grid-unit-20;
55
+ display: flex;
56
+ align-items: center;
57
+ justify-content: start;
58
+ }
@@ -16,7 +16,7 @@ jest.mock( '@wordpress/compose', () => ( {
16
16
  /**
17
17
  * Internal dependencies
18
18
  */
19
- import { useBlockVisibility } from '../use-block-visibility';
19
+ import useBlockVisibility from '../use-block-visibility';
20
20
 
21
21
  describe( 'useBlockVisibility', () => {
22
22
  // Helper function to set up viewport matches
@@ -271,58 +271,13 @@ describe( 'useBlockVisibility', () => {
271
271
  } );
272
272
  } );
273
273
 
274
- describe( 'Default values', () => {
275
- it( 'should return false when no options are provided', () => {
276
- setupViewport( {
277
- isMobileOrLarger: true,
278
- isMediumOrLarger: true,
279
- } );
280
-
281
- const { result } = renderHook( () => useBlockVisibility( {} ) );
282
-
283
- expect( result.current.isBlockCurrentlyHidden ).toBe( false );
284
- expect( result.current.currentViewport ).toBe( 'desktop' );
285
- } );
286
-
287
- it( 'should default to desktop deviceType when not provided', () => {
288
- setupViewport( {
289
- isMobileOrLarger: true,
290
- isMediumOrLarger: true,
291
- } );
292
-
293
- const { result } = renderHook( () =>
294
- useBlockVisibility( {
295
- blockVisibility: { desktop: false },
296
- } )
297
- );
298
-
299
- expect( result.current.isBlockCurrentlyHidden ).toBe( true );
300
- expect( result.current.currentViewport ).toBe( 'desktop' );
301
- } );
302
-
303
- it( 'should default to undefined blockVisibility when not provided', () => {
304
- setupViewport( {
305
- isMobileOrLarger: true,
306
- isMediumOrLarger: true,
307
- } );
308
-
309
- const { result } = renderHook( () =>
310
- useBlockVisibility( {
311
- deviceType: 'desktop',
312
- } )
313
- );
314
-
315
- expect( result.current.isBlockCurrentlyHidden ).toBe( false );
316
- } );
317
- } );
318
-
319
274
  describe( 'Edge cases', () => {
320
- it( 'should return false when blockVisibility is an empty object', () => {
275
+ it( 'should return false when no visibility settings are defined', () => {
321
276
  setupViewport( { isMobileOrLarger: true } );
322
277
 
323
278
  const { result } = renderHook( () =>
324
279
  useBlockVisibility( {
325
- blockVisibility: {},
280
+ blockVisibility: true,
326
281
  deviceType: 'desktop',
327
282
  } )
328
283
  );
@@ -330,12 +285,12 @@ describe( 'useBlockVisibility', () => {
330
285
  expect( result.current.isBlockCurrentlyHidden ).toBe( false );
331
286
  } );
332
287
 
333
- it( 'should handle null blockVisibility', () => {
288
+ it( 'should return false when blockVisibility is undefined', () => {
334
289
  setupViewport( { isMobileOrLarger: true } );
335
290
 
336
291
  const { result } = renderHook( () =>
337
292
  useBlockVisibility( {
338
- blockVisibility: null,
293
+ blockVisibility: undefined,
339
294
  deviceType: 'desktop',
340
295
  } )
341
296
  );
@@ -343,18 +298,19 @@ describe( 'useBlockVisibility', () => {
343
298
  expect( result.current.isBlockCurrentlyHidden ).toBe( false );
344
299
  } );
345
300
 
346
- it( 'should handle case-insensitive deviceType', () => {
347
- setupViewport( { isMobileOrLarger: true } );
301
+ it( 'should default to desktop deviceType when not provided', () => {
302
+ setupViewport( {
303
+ isMobileOrLarger: true,
304
+ isMediumOrLarger: true,
305
+ } );
348
306
 
349
307
  const { result } = renderHook( () =>
350
308
  useBlockVisibility( {
351
- blockVisibility: { mobile: false },
352
- deviceType: 'MOBILE',
309
+ blockVisibility: { desktop: false },
353
310
  } )
354
311
  );
355
312
 
356
- // Should still work but viewport detection uses lowercase
357
- expect( result.current.currentViewport ).toBe( 'desktop' );
313
+ expect( result.current.isBlockCurrentlyHidden ).toBe( true );
358
314
  } );
359
315
  } );
360
316
  } );