@wordpress/block-editor 12.14.0 → 12.15.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 +2 -0
- package/README.md +1 -1
- package/build/components/block-list/block.native.js +2 -0
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js +1 -1
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +25 -16
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +4 -2
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-patterns-list/index.js +36 -19
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-rename/index.js +28 -0
- package/build/components/block-rename/index.js.map +1 -0
- package/build/components/block-rename/is-empty-string.js +10 -0
- package/build/components/block-rename/is-empty-string.js.map +1 -0
- package/build/components/block-rename/modal.js +87 -0
- package/build/components/block-rename/modal.js.map +1 -0
- package/build/components/block-rename/rename-control.js +74 -0
- package/build/components/block-rename/rename-control.js.map +1 -0
- package/build/components/block-rename/use-block-rename.js +17 -0
- package/build/components/block-rename/use-block-rename.js.map +1 -0
- package/build/components/block-settings-menu/block-settings-dropdown.js +33 -20
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +7 -0
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-toolbar/block-toolbar-menu.native.js +1 -1
- package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
- package/build/components/block-types-list/index.js +6 -2
- package/build/components/block-types-list/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +8 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/global-styles/advanced-panel.js +1 -1
- package/build/components/global-styles/advanced-panel.js.map +1 -1
- package/build/components/image-size-control/index.js +0 -5
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +3 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/warning-max-depth-exceeded.native.js +29 -31
- package/build/components/inner-blocks/warning-max-depth-exceeded.native.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/use-pattern-categories.js +1 -1
- package/build/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/utils.js +3 -4
- package/build/components/inserter/block-patterns-tab/utils.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +2 -1
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter-listbox/index.js +11 -6
- package/build/components/inserter-listbox/index.js.map +1 -1
- package/build/components/inserter-listbox/item.js +24 -23
- package/build/components/inserter-listbox/item.js.map +1 -1
- package/build/components/inserter-listbox/row.js +5 -5
- package/build/components/inserter-listbox/row.js.map +1 -1
- package/build/components/list-view/use-list-view-expand-selected-item.js +2 -3
- package/build/components/list-view/use-list-view-expand-selected-item.js.map +1 -1
- package/build/components/preview-options/index.js +4 -2
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +1 -1
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +34 -3
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/rich-text/use-input-rules.js +30 -1
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +4 -1
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-moving-animation/index.js +2 -1
- package/build/components/use-moving-animation/index.js.map +1 -1
- package/build/components/use-settings/index.js +2 -2
- package/build/components/use-settings/index.js.map +1 -1
- package/build/hooks/block-renaming.js +42 -0
- package/build/hooks/block-renaming.js.map +1 -1
- package/build/hooks/custom-fields.js +53 -48
- package/build/hooks/custom-fields.js.map +1 -1
- package/build/hooks/index.js +0 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +13 -7
- package/build/hooks/layout.js.map +1 -1
- package/build/layouts/constrained.js +4 -3
- package/build/layouts/constrained.js.map +1 -1
- package/build/store/selectors.js +2 -0
- package/build/store/selectors.js.map +1 -1
- package/build/utils/transform-styles/index.js +26 -6
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -0
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +1 -1
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +24 -15
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +4 -2
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +36 -19
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-rename/index.js +4 -0
- package/build-module/components/block-rename/index.js.map +1 -0
- package/build-module/components/block-rename/is-empty-string.js +4 -0
- package/build-module/components/block-rename/is-empty-string.js.map +1 -0
- package/build-module/components/block-rename/modal.js +79 -0
- package/build-module/components/block-rename/modal.js.map +1 -0
- package/build-module/components/block-rename/rename-control.js +66 -0
- package/build-module/components/block-rename/rename-control.js.map +1 -0
- package/build-module/components/block-rename/use-block-rename.js +10 -0
- package/build-module/components/block-rename/use-block-rename.js.map +1 -0
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +34 -21
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +7 -0
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js +1 -1
- package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
- package/build-module/components/block-types-list/index.js +6 -2
- package/build-module/components/block-types-list/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +8 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/global-styles/advanced-panel.js +1 -1
- package/build-module/components/global-styles/advanced-panel.js.map +1 -1
- package/build-module/components/image-size-control/index.js +0 -5
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +3 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/warning-max-depth-exceeded.native.js +30 -32
- package/build-module/components/inner-blocks/warning-max-depth-exceeded.native.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +4 -4
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js +2 -2
- package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/utils.js +3 -4
- package/build-module/components/inserter/block-patterns-tab/utils.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +2 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter-listbox/index.js +13 -8
- package/build-module/components/inserter-listbox/index.js.map +1 -1
- package/build-module/components/inserter-listbox/item.js +25 -23
- package/build-module/components/inserter-listbox/item.js.map +1 -1
- package/build-module/components/inserter-listbox/row.js +6 -5
- package/build-module/components/inserter-listbox/row.js.map +1 -1
- package/build-module/components/list-view/use-list-view-expand-selected-item.js +2 -3
- package/build-module/components/list-view/use-list-view-expand-selected-item.js.map +1 -1
- package/build-module/components/preview-options/index.js +4 -2
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +1 -1
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +34 -3
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-input-rules.js +31 -2
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +4 -1
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-moving-animation/index.js +2 -1
- package/build-module/components/use-moving-animation/index.js.map +1 -1
- package/build-module/components/use-settings/index.js +2 -2
- package/build-module/components/use-settings/index.js.map +1 -1
- package/build-module/hooks/block-renaming.js +40 -0
- package/build-module/hooks/block-renaming.js.map +1 -1
- package/build-module/hooks/custom-fields.js +53 -48
- package/build-module/hooks/custom-fields.js.map +1 -1
- package/build-module/hooks/index.js +0 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +13 -7
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/layouts/constrained.js +4 -3
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/store/selectors.js +2 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +24 -7
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +6 -6
- package/build-style/content.css +6 -6
- package/build-style/style-rtl.css +10 -5
- package/build-style/style.css +10 -5
- package/package.json +31 -31
- package/src/components/block-list/block.native.js +2 -0
- package/src/components/block-parent-selector/index.js +1 -1
- package/src/components/block-pattern-setup/index.js +38 -22
- package/src/components/block-pattern-setup/setup-toolbar.js +2 -0
- package/src/components/block-pattern-setup/style.scss +4 -1
- package/src/components/block-patterns-list/README.md +4 -4
- package/src/components/block-patterns-list/index.js +60 -34
- package/src/components/block-patterns-list/style.scss +7 -0
- package/src/components/block-rename/index.js +3 -0
- package/src/components/block-rename/is-empty-string.js +3 -0
- package/src/components/block-rename/modal.js +115 -0
- package/src/components/block-rename/rename-control.js +80 -0
- package/src/components/block-rename/use-block-rename.js +10 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +38 -34
- package/src/components/block-settings-menu-controls/index.js +9 -0
- package/src/components/block-toolbar/block-toolbar-menu.native.js +1 -4
- package/src/components/block-types-list/index.js +5 -4
- package/src/components/button-block-appender/content.scss +2 -2
- package/src/components/date-format-picker/index.js +7 -0
- package/src/components/editable-text/README.md +0 -36
- package/src/components/global-styles/advanced-panel.js +1 -1
- package/src/components/image-size-control/index.js +0 -6
- package/src/components/inner-blocks/index.js +6 -2
- package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +57 -33
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +5 -1
- package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +7 -3
- package/src/components/inserter/block-patterns-tab/use-pattern-categories.js +6 -1
- package/src/components/inserter/block-patterns-tab/utils.js +6 -4
- package/src/components/inserter/hooks/use-patterns-state.js +3 -1
- package/src/components/inserter-listbox/index.js +11 -7
- package/src/components/inserter-listbox/item.js +11 -12
- package/src/components/inserter-listbox/row.js +6 -12
- package/src/components/list-view/use-list-view-expand-selected-item.js +7 -8
- package/src/components/plain-text/README.md +0 -28
- package/src/components/preview-options/index.js +2 -0
- package/src/components/rich-text/README.md +0 -58
- package/src/components/rich-text/index.native.js +1 -1
- package/src/components/rich-text/native/index.native.js +45 -2
- package/src/components/rich-text/use-input-rules.js +30 -2
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/src/components/url-input/README.md +1 -74
- package/src/components/use-block-drop-zone/index.js +4 -1
- package/src/components/use-moving-animation/index.js +1 -1
- package/src/components/use-settings/index.js +2 -2
- package/src/components/use-settings/test/index.js +1 -1
- package/src/hooks/block-renaming.js +47 -0
- package/src/hooks/custom-fields.js +68 -65
- package/src/hooks/index.js +0 -1
- package/src/hooks/layout.js +12 -8
- package/src/hooks/test/__snapshots__/align.native.js.snap +5 -5
- package/src/layouts/constrained.js +57 -50
- package/src/store/selectors.js +2 -0
- package/src/style.scss +1 -1
- package/src/utils/test/transform-styles.js +49 -0
- package/src/utils/transform-styles/index.js +39 -13
- package/build/hooks/block-rename-ui.js +0 -167
- package/build/hooks/block-rename-ui.js.map +0 -1
- package/build-module/hooks/block-rename-ui.js +0 -159
- package/build-module/hooks/block-rename-ui.js.map +0 -1
- package/src/hooks/block-rename-ui.js +0 -228
- /package/src/{hooks/block-rename-ui.scss → components/block-rename/style.scss} +0 -0
|
@@ -9,7 +9,7 @@ import { TouchableWithoutFeedback, View } from 'react-native';
|
|
|
9
9
|
*/
|
|
10
10
|
import { __, sprintf } from '@wordpress/i18n';
|
|
11
11
|
import { useState } from '@wordpress/element';
|
|
12
|
-
import {
|
|
12
|
+
import { useSelect } from '@wordpress/data';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
@@ -19,48 +19,46 @@ import UnsupportedBlockDetails from '../unsupported-block-details';
|
|
|
19
19
|
import { store as blockEditorStore } from '../../store';
|
|
20
20
|
import { MAX_NESTING_DEPTH } from './constants';
|
|
21
21
|
import useUnsupportedBlockEditor from '../use-unsupported-block-editor';
|
|
22
|
+
import { useConvertToGroupButtons, useConvertToGroupButtonProps } from '../convert-to-group-buttons';
|
|
23
|
+
const EMPTY_ARRAY = [];
|
|
22
24
|
const WarningMaxDepthExceeded = ({
|
|
23
25
|
clientId
|
|
24
26
|
}) => {
|
|
25
27
|
const [showDetails, setShowDetails] = useState(false);
|
|
28
|
+
const isSelected = useSelect(select => select(blockEditorStore).isBlockSelected(clientId), [clientId]);
|
|
29
|
+
|
|
30
|
+
// We rely on the logic related to the Group/Ungroup buttons used in the block options to
|
|
31
|
+
// determine whether to use the Ungroup action.
|
|
32
|
+
const convertToGroupButtonProps = useConvertToGroupButtonProps([clientId]);
|
|
26
33
|
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} = select(blockEditorStore);
|
|
34
|
-
return {
|
|
35
|
-
innerBlocks: getBlock(clientId)?.innerBlocks || [],
|
|
36
|
-
isSelected: isBlockSelected(clientId)
|
|
37
|
-
};
|
|
38
|
-
}, [clientId]);
|
|
39
|
-
const {
|
|
40
|
-
replaceBlocks
|
|
41
|
-
} = useDispatch(blockEditorStore);
|
|
34
|
+
isUngroupable
|
|
35
|
+
} = convertToGroupButtonProps;
|
|
36
|
+
const convertToGroupButtons = useConvertToGroupButtons({
|
|
37
|
+
...convertToGroupButtonProps
|
|
38
|
+
});
|
|
39
|
+
const onUngroup = convertToGroupButtons.ungroup.onSelect;
|
|
42
40
|
const {
|
|
43
41
|
isUnsupportedBlockEditorSupported,
|
|
44
42
|
canEnableUnsupportedBlockEditor
|
|
45
43
|
} = useUnsupportedBlockEditor(clientId);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
replaceBlocks(clientId, innerBlocks);
|
|
51
|
-
};
|
|
52
|
-
let description;
|
|
53
|
-
// When UBE can't be used, the description mentions using the web browser to edit the block.
|
|
44
|
+
|
|
45
|
+
/* translators: Warning related to having blocks deeply nested. %d: The deepest nesting level. */
|
|
46
|
+
const descriptionFormat = __('Blocks nested deeper than %d levels may not render properly in the mobile editor.');
|
|
47
|
+
let description = sprintf(descriptionFormat, MAX_NESTING_DEPTH);
|
|
54
48
|
if (!isUnsupportedBlockEditorSupported && !canEnableUnsupportedBlockEditor) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
// When UBE can't be used, the description mentions using the web browser to edit the block.
|
|
50
|
+
description += ' ' + /* translators: Recommendation included in a warning related to having blocks deeply nested. */
|
|
51
|
+
__('For this reason, we recommend editing the block using your web browser.');
|
|
58
52
|
}
|
|
59
53
|
// Otherwise, the description mentions using the web editor (i.e. UBE).
|
|
60
54
|
else {
|
|
61
|
-
/* translators:
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
description += ' ' + /* translators: Recommendation included in a warning related to having blocks deeply nested. */
|
|
56
|
+
__('For this reason, we recommend editing the block using the web editor.');
|
|
57
|
+
}
|
|
58
|
+
// If the block can be flattened, we also suggest to ungroup the block.
|
|
59
|
+
if (isUngroupable) {
|
|
60
|
+
description += ' ' + /* translators: Alternative option included in a warning related to having blocks deeply nested. */
|
|
61
|
+
__('Alternatively, you can flatten the content by ungrouping the block.');
|
|
64
62
|
}
|
|
65
63
|
return createElement(TouchableWithoutFeedback, {
|
|
66
64
|
disabled: !isSelected,
|
|
@@ -76,10 +74,10 @@ const WarningMaxDepthExceeded = ({
|
|
|
76
74
|
onCloseSheet: () => setShowDetails(false),
|
|
77
75
|
title: __('Deeply nested block'),
|
|
78
76
|
description: description,
|
|
79
|
-
customActions: [{
|
|
77
|
+
customActions: isUngroupable ? [{
|
|
80
78
|
label: __('Ungroup block'),
|
|
81
79
|
onPress: onUngroup
|
|
82
|
-
}]
|
|
80
|
+
}] : EMPTY_ARRAY
|
|
83
81
|
})));
|
|
84
82
|
};
|
|
85
83
|
export default WarningMaxDepthExceeded;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TouchableWithoutFeedback","View","__","sprintf","useState","
|
|
1
|
+
{"version":3,"names":["TouchableWithoutFeedback","View","__","sprintf","useState","useSelect","Warning","UnsupportedBlockDetails","store","blockEditorStore","MAX_NESTING_DEPTH","useUnsupportedBlockEditor","useConvertToGroupButtons","useConvertToGroupButtonProps","EMPTY_ARRAY","WarningMaxDepthExceeded","clientId","showDetails","setShowDetails","isSelected","select","isBlockSelected","convertToGroupButtonProps","isUngroupable","convertToGroupButtons","onUngroup","ungroup","onSelect","isUnsupportedBlockEditorSupported","canEnableUnsupportedBlockEditor","descriptionFormat","description","createElement","disabled","accessibilityLabel","accessibilityRole","accessibilityHint","onPress","message","showSheet","onCloseSheet","title","customActions","label"],"sources":["@wordpress/block-editor/src/components/inner-blocks/warning-max-depth-exceeded.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { TouchableWithoutFeedback, View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport Warning from '../warning';\nimport UnsupportedBlockDetails from '../unsupported-block-details';\nimport { store as blockEditorStore } from '../../store';\nimport { MAX_NESTING_DEPTH } from './constants';\nimport useUnsupportedBlockEditor from '../use-unsupported-block-editor';\nimport {\n\tuseConvertToGroupButtons,\n\tuseConvertToGroupButtonProps,\n} from '../convert-to-group-buttons';\n\nconst EMPTY_ARRAY = [];\n\nconst WarningMaxDepthExceeded = ( { clientId } ) => {\n\tconst [ showDetails, setShowDetails ] = useState( false );\n\n\tconst isSelected = useSelect(\n\t\t( select ) => select( blockEditorStore ).isBlockSelected( clientId ),\n\t\t[ clientId ]\n\t);\n\n\t// We rely on the logic related to the Group/Ungroup buttons used in the block options to\n\t// determine whether to use the Ungroup action.\n\tconst convertToGroupButtonProps = useConvertToGroupButtonProps( [\n\t\tclientId,\n\t] );\n\tconst { isUngroupable } = convertToGroupButtonProps;\n\tconst convertToGroupButtons = useConvertToGroupButtons( {\n\t\t...convertToGroupButtonProps,\n\t} );\n\tconst onUngroup = convertToGroupButtons.ungroup.onSelect;\n\n\tconst {\n\t\tisUnsupportedBlockEditorSupported,\n\t\tcanEnableUnsupportedBlockEditor,\n\t} = useUnsupportedBlockEditor( clientId );\n\n\t/* translators: Warning related to having blocks deeply nested. %d: The deepest nesting level. */\n\tconst descriptionFormat = __(\n\t\t'Blocks nested deeper than %d levels may not render properly in the mobile editor.'\n\t);\n\tlet description = sprintf( descriptionFormat, MAX_NESTING_DEPTH );\n\tif (\n\t\t! isUnsupportedBlockEditorSupported &&\n\t\t! canEnableUnsupportedBlockEditor\n\t) {\n\t\t// When UBE can't be used, the description mentions using the web browser to edit the block.\n\t\tdescription +=\n\t\t\t' ' +\n\t\t\t/* translators: Recommendation included in a warning related to having blocks deeply nested. */\n\t\t\t__(\n\t\t\t\t'For this reason, we recommend editing the block using your web browser.'\n\t\t\t);\n\t}\n\t// Otherwise, the description mentions using the web editor (i.e. UBE).\n\telse {\n\t\tdescription +=\n\t\t\t' ' +\n\t\t\t/* translators: Recommendation included in a warning related to having blocks deeply nested. */\n\t\t\t__(\n\t\t\t\t'For this reason, we recommend editing the block using the web editor.'\n\t\t\t);\n\t}\n\t// If the block can be flattened, we also suggest to ungroup the block.\n\tif ( isUngroupable ) {\n\t\tdescription +=\n\t\t\t' ' +\n\t\t\t/* translators: Alternative option included in a warning related to having blocks deeply nested. */\n\t\t\t__(\n\t\t\t\t'Alternatively, you can flatten the content by ungrouping the block.'\n\t\t\t);\n\t}\n\n\treturn (\n\t\t<TouchableWithoutFeedback\n\t\t\tdisabled={ ! isSelected }\n\t\t\taccessibilityLabel={ __( 'Warning message' ) }\n\t\t\taccessibilityRole={ 'button' }\n\t\t\taccessibilityHint={ __( 'Tap here to show more details.' ) }\n\t\t\tonPress={ () => setShowDetails( true ) }\n\t\t>\n\t\t\t<View>\n\t\t\t\t<Warning\n\t\t\t\t\tmessage={ __(\n\t\t\t\t\t\t'Block cannot be rendered because it is deeply nested. Tap here for more details.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<UnsupportedBlockDetails\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tshowSheet={ showDetails }\n\t\t\t\t\tonCloseSheet={ () => setShowDetails( false ) }\n\t\t\t\t\ttitle={ __( 'Deeply nested block' ) }\n\t\t\t\t\tdescription={ description }\n\t\t\t\t\tcustomActions={\n\t\t\t\t\t\tisUngroupable\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tlabel: __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AAC;MAC5BmC,OAAO,EAAEZ;IACV,CAAC,CACA,GACDX;EACH,CACD,CACI,CACmB,CAAC;AAE7B,CAAC;AAED,eAAeC,uBAAuB"}
|
|
@@ -18,7 +18,7 @@ import InserterListbox from '../../inserter-listbox';
|
|
|
18
18
|
import { searchItems } from '../search-items';
|
|
19
19
|
import BlockPatternsPaging from '../../block-patterns-paging';
|
|
20
20
|
import usePatternsPaging from '../hooks/use-patterns-paging';
|
|
21
|
-
import { allPatternsCategory, myPatternsCategory } from '../block-patterns-tab/utils';
|
|
21
|
+
import { PATTERN_TYPES, allPatternsCategory, myPatternsCategory } from '../block-patterns-tab/utils';
|
|
22
22
|
function PatternsListHeader({
|
|
23
23
|
filterValue,
|
|
24
24
|
filteredBlockPatternsLength
|
|
@@ -50,7 +50,7 @@ function PatternList({
|
|
|
50
50
|
if (selectedCategory === allPatternsCategory.name) {
|
|
51
51
|
return true;
|
|
52
52
|
}
|
|
53
|
-
if (selectedCategory === myPatternsCategory.name && pattern.
|
|
53
|
+
if (selectedCategory === myPatternsCategory.name && pattern.type === PATTERN_TYPES.user) {
|
|
54
54
|
return true;
|
|
55
55
|
}
|
|
56
56
|
if (selectedCategory === 'uncategorized') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useEffect","useRef","useState","_n","sprintf","useDebounce","__experimentalHeading","Heading","speak","BlockPatternsList","useInsertionPoint","usePatternsState","InserterListbox","searchItems","BlockPatternsPaging","usePatternsPaging","allPatternsCategory","myPatternsCategory","PatternsListHeader","filterValue","filteredBlockPatternsLength","createElement","level","lineHeight","className","PatternList","searchValue","selectedCategory","patternCategories","container","debouncedSpeak","destinationRootClientId","onInsertBlocks","shouldFocusBlock","patterns","onClickPattern","registeredPatternCategories","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","
|
|
1
|
+
{"version":3,"names":["useMemo","useEffect","useRef","useState","_n","sprintf","useDebounce","__experimentalHeading","Heading","speak","BlockPatternsList","useInsertionPoint","usePatternsState","InserterListbox","searchItems","BlockPatternsPaging","usePatternsPaging","PATTERN_TYPES","allPatternsCategory","myPatternsCategory","PatternsListHeader","filterValue","filteredBlockPatternsLength","createElement","level","lineHeight","className","PatternList","searchValue","selectedCategory","patternCategories","container","debouncedSpeak","destinationRootClientId","onInsertBlocks","shouldFocusBlock","patterns","onClickPattern","registeredPatternCategories","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","type","user","hasKnownCategory","categories","some","category","includes","length","count","resultsFoundMessage","pagingProps","previousSearchValue","setPreviousSearchValue","changePage","hasItems","ref","Fragment","shownPatterns","categoryPatternsAsyncList","blockPatterns","categoryPatterns","isDraggable"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/pattern-list.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useEffect, useRef, useState } from '@wordpress/element';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useDebounce } from '@wordpress/compose';\nimport { __experimentalHeading as Heading } from '@wordpress/components';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport BlockPatternsList from '../../block-patterns-list';\nimport useInsertionPoint from '../hooks/use-insertion-point';\nimport usePatternsState from '../hooks/use-patterns-state';\nimport InserterListbox from '../../inserter-listbox';\nimport { searchItems } from '../search-items';\nimport BlockPatternsPaging from '../../block-patterns-paging';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport {\n\tPATTERN_TYPES,\n\tallPatternsCategory,\n\tmyPatternsCategory,\n} from '../block-patterns-tab/utils';\n\nfunction PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {\n\tif ( ! filterValue ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Heading\n\t\t\tlevel={ 2 }\n\t\t\tlineHeight={ '48px' }\n\t\t\tclassName=\"block-editor-block-patterns-explorer__search-results-count\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d: number of patterns. */\n\t\t\t\t_n(\n\t\t\t\t\t'%d pattern found',\n\t\t\t\t\t'%d patterns found',\n\t\t\t\t\tfilteredBlockPatternsLength\n\t\t\t\t),\n\t\t\t\tfilteredBlockPatternsLength\n\t\t\t) }\n\t\t</Heading>\n\t);\n}\n\nfunction PatternList( { searchValue, selectedCategory, patternCategories } ) {\n\tconst container = useRef();\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\tconst [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {\n\t\tshouldFocusBlock: true,\n\t} );\n\tconst [ patterns, , onClickPattern ] = usePatternsState(\n\t\tonInsertBlocks,\n\t\tdestinationRootClientId\n\t);\n\n\tconst registeredPatternCategories = useMemo(\n\t\t() =>\n\t\t\tpatternCategories.map(\n\t\t\t\t( patternCategory ) => patternCategory.name\n\t\t\t),\n\t\t[ patternCategories ]\n\t);\n\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\tconst filteredPatterns = patterns.filter( ( pattern ) => {\n\t\t\tif ( selectedCategory === allPatternsCategory.name ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tselectedCategory === myPatternsCategory.name &&\n\t\t\t\tpattern.type === PATTERN_TYPES.user\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( selectedCategory === 'uncategorized' ) {\n\t\t\t\tconst hasKnownCategory = pattern.categories.some(\n\t\t\t\t\t( category ) =>\n\t\t\t\t\t\tregisteredPatternCategories.includes( category )\n\t\t\t\t);\n\n\t\t\t\treturn ! pattern.categories?.length || ! hasKnownCategory;\n\t\t\t}\n\n\t\t\treturn pattern.categories?.includes( selectedCategory );\n\t\t} );\n\n\t\tif ( ! searchValue ) {\n\t\t\treturn filteredPatterns;\n\t\t}\n\n\t\treturn searchItems( filteredPatterns, searchValue );\n\t}, [\n\t\tsearchValue,\n\t\tpatterns,\n\t\tselectedCategory,\n\t\tregisteredPatternCategories,\n\t] );\n\n\t// Announce search results on change.\n\tuseEffect( () => {\n\t\tif ( ! searchValue ) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = filteredBlockPatterns.length;\n\t\tconst resultsFoundMessage = sprintf(\n\t\t\t/* translators: %d: number of results. */\n\t\t\t_n( '%d result found.', '%d results found.', count ),\n\t\t\tcount\n\t\t);\n\t\tdebouncedSpeak( resultsFoundMessage );\n\t}, [ searchValue, debouncedSpeak, filteredBlockPatterns.length ] );\n\n\tconst pagingProps = usePatternsPaging(\n\t\tfilteredBlockPatterns,\n\t\tselectedCategory,\n\t\tcontainer\n\t);\n\n\t// Reset page when search value changes.\n\tconst [ previousSearchValue, setPreviousSearchValue ] =\n\t\tuseState( searchValue );\n\tif ( searchValue !== previousSearchValue ) {\n\t\tsetPreviousSearchValue( searchValue );\n\t\tpagingProps.changePage( 1 );\n\t}\n\n\tconst hasItems = !! filteredBlockPatterns?.length;\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-patterns-explorer__list\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<PatternsListHeader\n\t\t\t\tfilterValue={ searchValue }\n\t\t\t\tfilteredBlockPatternsLength={ filteredBlockPatterns.length }\n\t\t\t/>\n\n\t\t\t<InserterListbox>\n\t\t\t\t{ hasItems && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tshownPatterns={\n\t\t\t\t\t\t\t\tpagingProps.categoryPatternsAsyncList\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\t\t\tonClickPattern={ onClickPattern }\n\t\t\t\t\t\t\tisDraggable={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</InserterListbox>\n\t\t</div>\n\t);\n}\n\nexport default PatternList;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAA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,mBAAmB,EAAEkD,KAAM,CAAC,EACpDA,KACD,CAAC;IACDtB,cAAc,CAAEuB,mBAAoB,CAAC;EACtC,CAAC,EAAE,CAAE3B,WAAW,EAAEI,cAAc,EAAEU,qBAAqB,CAACW,MAAM,CAAG,CAAC;EAElE,MAAMG,WAAW,GAAGxC,iBAAiB,CACpC0B,qBAAqB,EACrBb,gBAAgB,EAChBE,SACD,CAAC;;EAED;EACA,MAAM,CAAE0B,mBAAmB,EAAEC,sBAAsB,CAAE,GACpDvD,QAAQ,CAAEyB,WAAY,CAAC;EACxB,IAAKA,WAAW,KAAK6B,mBAAmB,EAAG;IAC1CC,sBAAsB,CAAE9B,WAAY,CAAC;IACrC4B,WAAW,CAACG,UAAU,CAAE,CAAE,CAAC;EAC5B;EAEA,MAAMC,QAAQ,GAAG,CAAC,CAAElB,qBAAqB,EAAEW,MAAM;EACjD,OACC9B,aAAA;IACCG,SAAS,EAAC,4CAA4C;IACtDmC,GAAG,EAAG9B;EAAW,GAEjBR,aAAA,CAACH,kBAAkB;IAClBC,WAAW,EAAGO,WAAa;IAC3BN,2BAA2B,EAAGoB,qBAAqB,CAACW;EAAQ,CAC5D,CAAC,EAEF9B,aAAA,CAACV,eAAe,QACb+C,QAAQ,IACTrC,aAAA,CAAAuC,QAAA,QACCvC,aAAA,CAACb,iBAAiB;IACjBqD,aAAa,EACZP,WAAW,CAACQ,yBACZ;IACDC,aAAa,EAAGT,WAAW,CAACU,gBAAkB;IAC9C7B,cAAc,EAAGA,cAAgB;IACjC8B,WAAW,EAAG;EAAO,CACrB,CAAC,EACF5C,aAAA,CAACR,mBAAmB;IAAA,GAAMyC;EAAW,CAAI,CACxC,CAEa,CACb,CAAC;AAER;AAEA,eAAe7B,WAAW"}
|
|
@@ -10,11 +10,11 @@ import { __experimentalHStack as HStack, __experimentalVStack as VStack, __exper
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import usePatternsState from '../hooks/use-patterns-state';
|
|
13
|
-
import
|
|
13
|
+
import BlockPatternsList from '../../block-patterns-list';
|
|
14
14
|
import usePatternsPaging from '../hooks/use-patterns-paging';
|
|
15
15
|
import { PatternsFilter } from './patterns-filter';
|
|
16
16
|
import { usePatternCategories } from './use-pattern-categories';
|
|
17
|
-
import { isPatternFiltered, allPatternsCategory, myPatternsCategory } from './utils';
|
|
17
|
+
import { isPatternFiltered, allPatternsCategory, myPatternsCategory, PATTERN_TYPES } from './utils';
|
|
18
18
|
const noop = () => {};
|
|
19
19
|
export function PatternCategoryPreviews({
|
|
20
20
|
rootClientId,
|
|
@@ -36,7 +36,7 @@ export function PatternCategoryPreviews({
|
|
|
36
36
|
if (category.name === allPatternsCategory.name) {
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
|
-
if (category.name === myPatternsCategory.name && pattern.
|
|
39
|
+
if (category.name === myPatternsCategory.name && pattern.type === PATTERN_TYPES.user) {
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
42
|
if (category.name !== 'uncategorized') {
|
|
@@ -82,7 +82,7 @@ export function PatternCategoryPreviews({
|
|
|
82
82
|
})), !currentCategoryPatterns.length && createElement(Text, {
|
|
83
83
|
variant: "muted",
|
|
84
84
|
className: "block-editor-inserter__patterns-category-no-results"
|
|
85
|
-
}, __('No results found'))), currentCategoryPatterns.length > 0 && createElement(
|
|
85
|
+
}, __('No results found'))), currentCategoryPatterns.length > 0 && createElement(BlockPatternsList, {
|
|
86
86
|
ref: scrollContainerRef,
|
|
87
87
|
shownPatterns: pagingProps.categoryPatternsAsyncList,
|
|
88
88
|
blockPatterns: pagingProps.categoryPatterns,
|
package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useState","useCallback","useRef","useEffect","__","__experimentalHStack","HStack","__experimentalVStack","VStack","__experimentalHeading","Heading","__experimentalText","Text","FlexBlock","usePatternsState","
|
|
1
|
+
{"version":3,"names":["useMemo","useState","useCallback","useRef","useEffect","__","__experimentalHStack","HStack","__experimentalVStack","VStack","__experimentalHeading","Heading","__experimentalText","Text","FlexBlock","usePatternsState","BlockPatternsList","usePatternsPaging","PatternsFilter","usePatternCategories","isPatternFiltered","allPatternsCategory","myPatternsCategory","PATTERN_TYPES","noop","PatternCategoryPreviews","rootClientId","onInsert","onHover","category","showTitlesAsTooltip","allPatterns","onClickPattern","patternSyncFilter","setPatternSyncFilter","patternSourceFilter","setPatternSourceFilter","availableCategories","scrollContainerRef","currentCategoryPatterns","filter","pattern","_pattern$categories$f","name","type","user","categories","includes","availablePatternCategories","cat","find","availableCategory","length","pagingProps","changePage","onSetPatternSyncFilter","value","onSetPatternSourceFilter","createElement","className","spacing","level","as","label","variant","ref","shownPatterns","categoryPatternsAsyncList","blockPatterns","categoryPatterns","orientation","isDraggable","patternFilter"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseState,\n\tuseCallback,\n\tuseRef,\n\tuseEffect,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalHeading as Heading,\n\t__experimentalText as Text,\n\tFlexBlock,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport usePatternsState from '../hooks/use-patterns-state';\nimport BlockPatternsList from '../../block-patterns-list';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport { PatternsFilter } from './patterns-filter';\nimport { usePatternCategories } from './use-pattern-categories';\nimport {\n\tisPatternFiltered,\n\tallPatternsCategory,\n\tmyPatternsCategory,\n\tPATTERN_TYPES,\n} from './utils';\n\nconst noop = () => {};\n\nexport function PatternCategoryPreviews( {\n\trootClientId,\n\tonInsert,\n\tonHover = noop,\n\tcategory,\n\tshowTitlesAsTooltip,\n} ) {\n\tconst [ allPatterns, , onClickPattern ] = usePatternsState(\n\t\tonInsert,\n\t\trootClientId\n\t);\n\tconst [ patternSyncFilter, setPatternSyncFilter ] = useState( 'all' );\n\tconst [ patternSourceFilter, setPatternSourceFilter ] = useState( 'all' );\n\n\tconst availableCategories = usePatternCategories(\n\t\trootClientId,\n\t\tpatternSourceFilter\n\t);\n\tconst scrollContainerRef = useRef();\n\tconst currentCategoryPatterns = useMemo(\n\t\t() =>\n\t\t\tallPatterns.filter( ( pattern ) => {\n\t\t\t\tif (\n\t\t\t\t\tisPatternFiltered(\n\t\t\t\t\t\tpattern,\n\t\t\t\t\t\tpatternSourceFilter,\n\t\t\t\t\t\tpatternSyncFilter\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif ( category.name === allPatternsCategory.name ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tcategory.name === myPatternsCategory.name &&\n\t\t\t\t\tpattern.type === PATTERN_TYPES.user\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif ( category.name !== 'uncategorized' ) {\n\t\t\t\t\treturn pattern.categories?.includes( category.name );\n\t\t\t\t}\n\n\t\t\t\t// The uncategorized category should show all the patterns without any category\n\t\t\t\t// or with no available category.\n\t\t\t\tconst availablePatternCategories =\n\t\t\t\t\tpattern.categories?.filter( ( cat ) =>\n\t\t\t\t\t\tavailableCategories.find(\n\t\t\t\t\t\t\t( availableCategory ) =>\n\t\t\t\t\t\t\t\tavailableCategory.name === cat\n\t\t\t\t\t\t)\n\t\t\t\t\t) ?? [];\n\n\t\t\t\treturn availablePatternCategories.length === 0;\n\t\t\t} ),\n\t\t[\n\t\t\tallPatterns,\n\t\t\tavailableCategories,\n\t\t\tcategory.name,\n\t\t\tpatternSourceFilter,\n\t\t\tpatternSyncFilter,\n\t\t]\n\t);\n\n\tconst pagingProps = usePatternsPaging(\n\t\tcurrentCategoryPatterns,\n\t\tcategory,\n\t\tscrollContainerRef\n\t);\n\tconst { changePage } = pagingProps;\n\n\t// Hide block pattern preview on unmount.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tuseEffect( () => () => onHover( null ), [] );\n\n\tconst onSetPatternSyncFilter = useCallback(\n\t\t( value ) => {\n\t\t\tsetPatternSyncFilter( value );\n\t\t\tchangePage( 1 );\n\t\t},\n\t\t[ setPatternSyncFilter, changePage ]\n\t);\n\tconst onSetPatternSourceFilter = useCallback(\n\t\t( value ) => {\n\t\t\tsetPatternSourceFilter( value );\n\t\t\tchangePage( 1 );\n\t\t},\n\t\t[ setPatternSourceFilter, changePage ]\n\t);\n\n\treturn (\n\t\t<div className=\"block-editor-inserter__patterns-category-panel\">\n\t\t\t<VStack\n\t\t\t\tspacing={ 2 }\n\t\t\t\tclassName=\"block-editor-inserter__patterns-category-panel-header\"\n\t\t\t>\n\t\t\t\t<HStack>\n\t\t\t\t\t<FlexBlock>\n\t\t\t\t\t\t<Heading level={ 4 } as=\"div\">\n\t\t\t\t\t\t\t{ category.label }\n\t\t\t\t\t\t</Heading>\n\t\t\t\t\t</FlexBlock>\n\t\t\t\t\t<PatternsFilter\n\t\t\t\t\t\tpatternSyncFilter={ patternSyncFilter }\n\t\t\t\t\t\tpatternSourceFilter={ patternSourceFilter }\n\t\t\t\t\t\tsetPatternSyncFilter={ onSetPatternSyncFilter }\n\t\t\t\t\t\tsetPatternSourceFilter={ onSetPatternSourceFilter }\n\t\t\t\t\t\tscrollContainerRef={ scrollContainerRef }\n\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t\t{ ! currentCategoryPatterns.length && (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tvariant=\"muted\"\n\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-category-no-results\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'No results found' ) }\n\t\t\t\t\t</Text>\n\t\t\t\t) }\n\t\t\t</VStack>\n\n\t\t\t{ currentCategoryPatterns.length > 0 && (\n\t\t\t\t<BlockPatternsList\n\t\t\t\t\tref={ scrollContainerRef }\n\t\t\t\t\tshownPatterns={ pagingProps.categoryPatternsAsyncList }\n\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\tonClickPattern={ onClickPattern }\n\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\tlabel={ category.label }\n\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\tcategory={ category.name }\n\t\t\t\t\tisDraggable\n\t\t\t\t\tshowTitlesAsTooltip={ showTitlesAsTooltip }\n\t\t\t\t\tpatternFilter={ patternSourceFilter }\n\t\t\t\t\tpagingProps={ pagingProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,MAAM,EACNC,SAAS,QACH,oBAAoB;AAC3B,SAASC,EAAE,QAAQ,iBAAiB;AAEpC,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,qBAAqB,IAAIC,OAAO,EAChCC,kBAAkB,IAAIC,IAAI,EAC1BC,SAAS,QACH,uBAAuB;;AAE9B;AACA;AACA;AACA,OAAOC,gBAAgB,MAAM,6BAA6B;AAC1D,OAAOC,iBAAiB,MAAM,2BAA2B;AACzD,OAAOC,iBAAiB,MAAM,8BAA8B;AAC5D,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,oBAAoB,QAAQ,0BAA0B;AAC/D,SACCC,iBAAiB,EACjBC,mBAAmB,EACnBC,kBAAkB,EAClBC,aAAa,QACP,SAAS;AAEhB,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,OAAO,SAASC,uBAAuBA,CAAE;EACxCC,YAAY;EACZC,QAAQ;EACRC,OAAO,GAAGJ,IAAI;EACdK,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAM,CAA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EU,uBAAuB,CAACa,MAAM,IACjCM,aAAA,CAAC7C,IAAI;IACJmD,OAAO,EAAC,OAAO;IACfL,SAAS,EAAC;EAAqD,GAE7DtD,EAAE,CAAE,kBAAmB,CACpB,CAEA,CAAC,EAEPkC,uBAAuB,CAACa,MAAM,GAAG,CAAC,IACnCM,aAAA,CAAC1C,iBAAiB;IACjBiD,GAAG,EAAG3B,kBAAoB;IAC1B4B,aAAa,EAAGb,WAAW,CAACc,yBAA2B;IACvDC,aAAa,EAAGf,WAAW,CAACgB,gBAAkB;IAC9CrC,cAAc,EAAGA,cAAgB;IACjCJ,OAAO,EAAGA,OAAS;IACnBmC,KAAK,EAAGlC,QAAQ,CAACkC,KAAO;IACxBO,WAAW,EAAC,UAAU;IACtBzC,QAAQ,EAAGA,QAAQ,CAACc,IAAM;IAC1B4B,WAAW;IACXzC,mBAAmB,EAAGA,mBAAqB;IAC3C0C,aAAa,EAAGrC,mBAAqB;IACrCkB,WAAW,EAAGA;EAAa,CAC3B,CAEE,CAAC;AAER"}
|
|
@@ -9,7 +9,7 @@ import { speak } from '@wordpress/a11y';
|
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
11
|
import usePatternsState from '../hooks/use-patterns-state';
|
|
12
|
-
import { isPatternFiltered, allPatternsCategory, myPatternsCategory } from './utils';
|
|
12
|
+
import { isPatternFiltered, allPatternsCategory, myPatternsCategory, PATTERN_TYPES } from './utils';
|
|
13
13
|
export function usePatternCategories(rootClientId, sourceFilter = 'all') {
|
|
14
14
|
const [patterns, allCategories] = usePatternsState(undefined, rootClientId);
|
|
15
15
|
const filteredPatterns = useMemo(() => sourceFilter === 'all' ? patterns : patterns.filter(pattern => !isPatternFiltered(pattern, sourceFilter)), [sourceFilter, patterns]);
|
|
@@ -29,7 +29,7 @@ export function usePatternCategories(rootClientId, sourceFilter = 'all') {
|
|
|
29
29
|
label: _x('Uncategorized')
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
if (filteredPatterns.some(pattern => pattern.
|
|
32
|
+
if (filteredPatterns.some(pattern => pattern.type === PATTERN_TYPES.user)) {
|
|
33
33
|
categories.unshift(myPatternsCategory);
|
|
34
34
|
}
|
|
35
35
|
if (filteredPatterns.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useCallback","_x","_n","sprintf","speak","usePatternsState","isPatternFiltered","allPatternsCategory","myPatternsCategory","usePatternCategories","rootClientId","sourceFilter","patterns","allCategories","undefined","filteredPatterns","filter","pattern","hasRegisteredCategory","categories","length","some","cat","category","name","populatedCategories","includes","sort","a","b","label","localeCompare","find","push","
|
|
1
|
+
{"version":3,"names":["useMemo","useCallback","_x","_n","sprintf","speak","usePatternsState","isPatternFiltered","allPatternsCategory","myPatternsCategory","PATTERN_TYPES","usePatternCategories","rootClientId","sourceFilter","patterns","allCategories","undefined","filteredPatterns","filter","pattern","hasRegisteredCategory","categories","length","some","cat","category","name","populatedCategories","includes","sort","a","b","label","localeCompare","find","push","type","user","unshift"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab/use-pattern-categories.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { _x, _n, sprintf } from '@wordpress/i18n';\n\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport usePatternsState from '../hooks/use-patterns-state';\nimport {\n\tisPatternFiltered,\n\tallPatternsCategory,\n\tmyPatternsCategory,\n\tPATTERN_TYPES,\n} from './utils';\n\nexport function usePatternCategories( rootClientId, sourceFilter = 'all' ) {\n\tconst [ patterns, allCategories ] = usePatternsState(\n\t\tundefined,\n\t\trootClientId\n\t);\n\n\tconst filteredPatterns = useMemo(\n\t\t() =>\n\t\t\tsourceFilter === 'all'\n\t\t\t\t? patterns\n\t\t\t\t: patterns.filter(\n\t\t\t\t\t\t( pattern ) =>\n\t\t\t\t\t\t\t! isPatternFiltered( pattern, sourceFilter )\n\t\t\t\t ),\n\t\t[ sourceFilter, patterns ]\n\t);\n\n\tconst hasRegisteredCategory = useCallback(\n\t\t( pattern ) => {\n\t\t\tif ( ! pattern.categories || ! pattern.categories.length ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn pattern.categories.some( ( cat ) =>\n\t\t\t\tallCategories.some( ( category ) => category.name === cat )\n\t\t\t);\n\t\t},\n\t\t[ allCategories ]\n\t);\n\n\t// Remove any empty categories.\n\tconst populatedCategories = useMemo( () => {\n\t\tconst categories = allCategories\n\t\t\t.filter( ( category ) =>\n\t\t\t\tfilteredPatterns.some( ( pattern ) =>\n\t\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.sort( ( a, b ) => a.label.localeCompare( b.label ) );\n\n\t\tif (\n\t\t\tfilteredPatterns.some(\n\t\t\t\t( pattern ) => ! hasRegisteredCategory( pattern )\n\t\t\t) &&\n\t\t\t! categories.find(\n\t\t\t\t( category ) => category.name === 'uncategorized'\n\t\t\t)\n\t\t) {\n\t\t\tcategories.push( {\n\t\t\t\tname: 'uncategorized',\n\t\t\t\tlabel: _x( 'Uncategorized' ),\n\t\t\t} );\n\t\t}\n\t\tif (\n\t\t\tfilteredPatterns.some(\n\t\t\t\t( pattern ) => pattern.type === PATTERN_TYPES.user\n\t\t\t)\n\t\t) {\n\t\t\tcategories.unshift( myPatternsCategory );\n\t\t}\n\t\tif ( filteredPatterns.length > 0 ) {\n\t\t\tcategories.unshift( {\n\t\t\t\tname: allPatternsCategory.name,\n\t\t\t\tlabel: allPatternsCategory.label,\n\t\t\t} );\n\t\t}\n\t\tspeak(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %d: number of categories . */\n\t\t\t\t_n(\n\t\t\t\t\t'%d category button displayed.',\n\t\t\t\t\t'%d category buttons displayed.',\n\t\t\t\t\tcategories.length\n\t\t\t\t),\n\t\t\t\tcategories.length\n\t\t\t)\n\t\t);\n\t\treturn categories;\n\t}, [ allCategories, filteredPatterns, has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20
20
|
name: 'allPatterns',
|
|
21
|
-
label: __('All
|
|
21
|
+
label: __('All')
|
|
22
22
|
};
|
|
23
23
|
export const myPatternsCategory = {
|
|
24
24
|
name: 'myPatterns',
|
|
@@ -40,9 +40,8 @@ export function isPatternFiltered(pattern, sourceFilter, syncFilter) {
|
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// If user source selected, filter out theme patterns.
|
|
44
|
-
|
|
45
|
-
if (sourceFilter === PATTERN_TYPES.user && !pattern.id) {
|
|
43
|
+
// If user source selected, filter out theme patterns.
|
|
44
|
+
if (sourceFilter === PATTERN_TYPES.user && pattern.type !== PATTERN_TYPES.user) {
|
|
46
45
|
return true;
|
|
47
46
|
}
|
|
48
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","PATTERN_TYPES","all","synced","unsynced","user","theme","directory","SYNC_TYPES","full","allPatternsCategory","name","label","myPatternsCategory","isPatternFiltered","pattern","sourceFilter","syncFilter","isUserPattern","startsWith","isDirectoryPattern","source","
|
|
1
|
+
{"version":3,"names":["__","PATTERN_TYPES","all","synced","unsynced","user","theme","directory","SYNC_TYPES","full","allPatternsCategory","name","label","myPatternsCategory","isPatternFiltered","pattern","sourceFilter","syncFilter","isUserPattern","startsWith","isDirectoryPattern","source","type","syncStatus"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { __ } from '@wordpress/i18n';\n\nexport const PATTERN_TYPES = {\n\tall: 'all',\n\tsynced: 'synced',\n\tunsynced: 'unsynced',\n\tuser: 'user',\n\ttheme: 'theme',\n\tdirectory: 'directory',\n};\n\nexport const SYNC_TYPES = {\n\tall: 'all',\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n\nexport const allPatternsCategory = {\n\tname: 'allPatterns',\n\tlabel: __( 'All' ),\n};\n\nexport const myPatternsCategory = {\n\tname: 'myPatterns',\n\tlabel: __( 'My patterns' ),\n};\n\nexport function isPatternFiltered( pattern, sourceFilter, syncFilter ) {\n\tconst isUserPattern = pattern.name.startsWith( 'core/block' );\n\tconst isDirectoryPattern =\n\t\tpattern.source === 'core' ||\n\t\tpattern.source?.startsWith( 'pattern-directory' );\n\n\t// If theme source selected, filter out user created patterns and those from\n\t// the core patterns directory.\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.theme &&\n\t\t( isUserPattern || isDirectoryPattern )\n\t) {\n\t\treturn true;\n\t}\n\n\t// If the directory source is selected, filter out user created patterns\n\t// and those bundled with the theme.\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.directory &&\n\t\t( isUserPattern || ! isDirectoryPattern )\n\t) {\n\t\treturn true;\n\t}\n\n\t// If user source selected, filter out theme patterns.\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.user &&\n\t\tpattern.type !== PATTERN_TYPES.user\n\t) {\n\t\treturn true;\n\t}\n\n\t// Filter by sync status.\n\tif ( syncFilter === SYNC_TYPES.full && pattern.syncStatus !== '' ) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\tsyncFilter === SYNC_TYPES.unsynced &&\n\t\tpattern.syncStatus !== 'unsynced' &&\n\t\tisUserPattern\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,EAAE,QAAQ,iBAAiB;AAEpC,OAAO,MAAMC,aAAa,GAAG;EAC5BC,GAAG,EAAE,KAAK;EACVC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,SAAS,EAAE;AACZ,CAAC;AAED,OAAO,MAAMC,UAAU,GAAG;EACzBN,GAAG,EAAE,KAAK;EACVO,IAAI,EAAE,OAAO;EACbL,QAAQ,EAAE;AACX,CAAC;AAED,OAAO,MAAMM,mBAAmB,GAAG;EAClCC,IAAI,EAAE,aAAa;EACnBC,KAAK,EAAEZ,EAAE,CAAE,KAAM;AAClB,CAAC;AAED,OAAO,MAAMa,kBAAkB,GAAG;EACjCF,IAAI,EAAE,YAAY;EAClBC,KAAK,EAAEZ,EAAE,CAAE,aAAc;AAC1B,CAAC;AAED,OAAO,SAASc,iBAAiBA,CAAEC,OAAO,EAAEC,YAAY,EAAEC,UAAU,EAAG;EACtE,MAAMC,aAAa,GAAGH,OAAO,CAACJ,IAAI,CAACQ,UAAU,CAAE,YAAa,CAAC;EAC7D,MAAMC,kBAAkB,GACvBL,OAAO,CAACM,MAAM,KAAK,MAAM,IACzBN,OAAO,CAACM,MAAM,EAAEF,UAAU,CAAE,mBAAoB,CAAC;;EAElD;EACA;EACA,IACCH,YAAY,KAAKf,aAAa,CAACK,KAAK,KAClCY,aAAa,IAAIE,kBAAkB,CAAE,EACtC;IACD,OAAO,IAAI;EACZ;;EAEA;EACA;EACA,IACCJ,YAAY,KAAKf,aAAa,CAACM,SAAS,KACtCW,aAAa,IAAI,CAAEE,kBAAkB,CAAE,EACxC;IACD,OAAO,IAAI;EACZ;;EAEA;EACA,IACCJ,YAAY,KAAKf,aAAa,CAACI,IAAI,IACnCU,OAAO,CAACO,IAAI,KAAKrB,aAAa,CAACI,IAAI,EAClC;IACD,OAAO,IAAI;EACZ;;EAEA;EACA,IAAKY,UAAU,KAAKT,UAAU,CAACC,IAAI,IAAIM,OAAO,CAACQ,UAAU,KAAK,EAAE,EAAG;IAClE,OAAO,IAAI;EACZ;EAEA,IACCN,UAAU,KAAKT,UAAU,CAACJ,QAAQ,IAClCW,OAAO,CAACQ,UAAU,KAAK,UAAU,IACjCL,aAAa,EACZ;IACD,OAAO,IAAI;EACZ;EAEA,OAAO,KAAK;AACb"}
|
|
@@ -11,6 +11,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
import { store as blockEditorStore } from '../../../store';
|
|
14
|
+
import { PATTERN_TYPES } from '../block-patterns-tab/utils';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Retrieves the block patterns inserter state.
|
|
@@ -53,7 +54,7 @@ const usePatternsState = (onInsert, rootClientId) => {
|
|
|
53
54
|
createSuccessNotice
|
|
54
55
|
} = useDispatch(noticesStore);
|
|
55
56
|
const onClickPattern = useCallback((pattern, blocks) => {
|
|
56
|
-
const patternBlocks = pattern.
|
|
57
|
+
const patternBlocks = pattern.type === PATTERN_TYPES.user && pattern.syncStatus !== 'unsynced' ? [createBlock('core/block', {
|
|
57
58
|
ref: pattern.id
|
|
58
59
|
})] : blocks;
|
|
59
60
|
onInsert((patternBlocks !== null && patternBlocks !== void 0 ? patternBlocks : []).map(block => cloneBlock(block)), pattern.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useMemo","cloneBlock","createBlock","useDispatch","useSelect","__","sprintf","store","noticesStore","blockEditorStore","usePatternsState","onInsert","rootClientId","patternCategories","patterns","userPatternCategories","select","__experimentalGetAllowedPatterns","getSettings","__experimentalUserPatternCategories","__experimentalBlockPatternCategories","allCategories","categories","forEach","userCategory","find","existingCategory","name","push","createSuccessNotice","onClickPattern","pattern","blocks","patternBlocks","
|
|
1
|
+
{"version":3,"names":["useCallback","useMemo","cloneBlock","createBlock","useDispatch","useSelect","__","sprintf","store","noticesStore","blockEditorStore","PATTERN_TYPES","usePatternsState","onInsert","rootClientId","patternCategories","patterns","userPatternCategories","select","__experimentalGetAllowedPatterns","getSettings","__experimentalUserPatternCategories","__experimentalBlockPatternCategories","allCategories","categories","forEach","userCategory","find","existingCategory","name","push","createSuccessNotice","onClickPattern","pattern","blocks","patternBlocks","type","user","syncStatus","ref","id","map","block","title"],"sources":["@wordpress/block-editor/src/components/inserter/hooks/use-patterns-state.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { cloneBlock, createBlock } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { PATTERN_TYPES } from '../block-patterns-tab/utils';\n\n/**\n * Retrieves the block patterns inserter state.\n *\n * @param {Function} onInsert function called when inserter a list of blocks.\n * @param {string=} rootClientId Insertion's root client ID.\n *\n * @return {Array} Returns the patterns state. (patterns, categories, onSelect handler)\n */\nconst usePatternsState = ( onInsert, rootClientId ) => {\n\tconst { patternCategories, patterns, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __experimentalGetAllowedPatterns, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst {\n\t\t\t\t__experimentalUserPatternCategories,\n\t\t\t\t__experimentalBlockPatternCategories,\n\t\t\t} = getSettings();\n\t\t\treturn {\n\t\t\t\tpatterns: __experimentalGetAllowedPatterns( rootClientId ),\n\t\t\t\tuserPatternCategories: __experimentalUserPatternCategories,\n\t\t\t\tpatternCategories: __experimentalBlockPatternCategories,\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\n\tconst allCategories = useMemo( () => {\n\t\tconst categories = [ ...patternCategories ];\n\t\tuserPatternCategories?.forEach( ( userCategory ) => {\n\t\t\tif (\n\t\t\t\t! categories.find(\n\t\t\t\t\t( existingCategory ) =>\n\t\t\t\t\t\texistingCategory.name === userCategory.name\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcategories.push( userCategory );\n\t\t\t}\n\t\t} );\n\t\treturn categories;\n\t}, [ patternCategories, userPatternCategories ] );\n\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst onClickPattern = useCallback(\n\t\t( pattern, blocks ) => {\n\t\t\tconst patternBlocks =\n\t\t\t\tpattern.type === PATTERN_TYPES.user &&\n\t\t\t\tpattern.syncStatus !== 'unsynced'\n\t\t\t\t\t? [ createBlock( 'core/block', { ref: pattern.id } ) ]\n\t\t\t\t\t: blocks;\n\t\t\tonInsert(\n\t\t\t\t( patternBlocks ?? [] ).map( ( block ) => cloneBlock( block ) ),\n\t\t\t\tpattern.name\n\t\t\t);\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: block pattern title. */\n\t\t\t\t\t__( 'Block pattern \"%s\" inserted.' ),\n\t\t\t\t\tpattern.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'block-pattern-inserted-notice',\n\t\t\t\t}\n\t\t\t);\n\t\t},\n\t\t[ createSuccessNotice, onInsert ]\n\t);\n\n\treturn [ patterns, allCategories, onClickPattern ];\n};\n\nexport default usePatternsState;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACzD,SAASC,UAAU,EAAEC,WAAW,QAAQ,mBAAmB;AAC3D,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;AACA,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,gBAAgB;AAC1D,SAASC,aAAa,QAAQ,6BAA6B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAEC,QAAQ,EAAEC,YAAY,KAAM;EACtD,MAAM;IAAEC,iBAAiB;IAAEC,QAAQ;IAAEC;EAAsB,CAAC,GAAGZ,SAAS,CACrEa,MAAM,IAAM;IACb,MAAM;MAAEC,gCAAgC;MAAEC;IAAY,CAAC,GACtDF,MAAM,CAAER,gBAAiB,CAAC;IAC3B,MAAM;MACLW,mCAAmC;MACnCC;IACD,CAAC,GAAGF,WAAW,CAAC,CAAC;IACjB,OAAO;MACNJ,QAAQ,EAAEG,gCAAgC,CAAEL,YAAa,CAAC;MAC1DG,qBAAqB,EAAEI,mCAA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AChC,CAAC;EAED,OAAO,CAAEG,QAAQ,EAAEO,aAAa,EAAES,cAAc,CAAE;AACnD,CAAC;AAED,eAAepB,gBAAgB"}
|
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
10
|
+
import { unlock } from '../../lock-unlock';
|
|
11
11
|
export { default as InserterListboxGroup } from './group';
|
|
12
12
|
export { default as InserterListboxRow } from './row';
|
|
13
13
|
export { default as InserterListboxItem } from './item';
|
|
14
|
+
const {
|
|
15
|
+
CompositeV2: Composite,
|
|
16
|
+
useCompositeStoreV2: useCompositeStore
|
|
17
|
+
} = unlock(componentsPrivateApis);
|
|
14
18
|
function InserterListbox({
|
|
15
19
|
children
|
|
16
20
|
}) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
const store = useCompositeStore({
|
|
22
|
+
focusShift: true,
|
|
23
|
+
focusWrap: 'horizontal'
|
|
20
24
|
});
|
|
21
|
-
return createElement(
|
|
22
|
-
|
|
25
|
+
return createElement(Composite, {
|
|
26
|
+
store: store,
|
|
27
|
+
render: createElement(Fragment, null)
|
|
23
28
|
}, children);
|
|
24
29
|
}
|
|
25
30
|
export default InserterListbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["privateApis","componentsPrivateApis","unlock","default","InserterListboxGroup","InserterListboxRow","InserterListboxItem","CompositeV2","Composite","useCompositeStoreV2","useCompositeStore","InserterListbox","children","store","focusShift","focusWrap","createElement","render","Fragment"],"sources":["@wordpress/block-editor/src/components/inserter-listbox/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nexport { default as InserterListboxGroup } from './group';\nexport { default as InserterListboxRow } from './row';\nexport { default as InserterListboxItem } from './item';\n\nconst { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =\n\tunlock( componentsPrivateApis );\n\nfunction InserterListbox( { children } ) {\n\tconst store = useCompositeStore( {\n\t\tfocusShift: true,\n\t\tfocusWrap: 'horizontal',\n\t} );\n\n\treturn (\n\t\t<Composite store={ store } render={ <></> }>\n\t\t\t{ children }\n\t\t</Composite>\n\t);\n}\n\nexport default InserterListbox;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,qBAAqB,QAAQ,uBAAuB;;AAE5E;AACA;AACA;AACA,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,OAAO,IAAIC,oBAAoB,QAAQ,SAAS;AACzD,SAASD,OAAO,IAAIE,kBAAkB,QAAQ,OAAO;AACrD,SAASF,OAAO,IAAIG,mBAAmB,QAAQ,QAAQ;AAEvD,MAAM;EAAEC,WAAW,EAAEC,SAAS;EAAEC,mBAAmB,EAAEC;AAAkB,CAAC,GACvER,MAAM,CAAED,qBAAsB,CAAC;AAEhC,SAASU,eAAeA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACxC,MAAMC,KAAK,GAAGH,iBAAiB,CAAE;IAChCI,UAAU,EAAE,IAAI;IAChBC,SAAS,EAAE;EACZ,CAAE,CAAC;EAEH,OACCC,aAAA,CAACR,SAAS;IAACK,KAAK,EAAGA,KAAO;IAACI,MAAM,EAAGD,aAAA,CAAAE,QAAA,MAAI;EAAG,GACxCN,QACQ,CAAC;AAEd;AAEA,eAAeD,eAAe"}
|
|
@@ -2,46 +2,48 @@ import { createElement } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
|
-
import { Button,
|
|
6
|
-
import { forwardRef
|
|
5
|
+
import { Button, privateApis as componentsPrivateApis } from '@wordpress/components';
|
|
6
|
+
import { forwardRef } from '@wordpress/element';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
11
|
+
import { unlock } from '../../lock-unlock';
|
|
12
|
+
const {
|
|
13
|
+
CompositeItemV2: CompositeItem
|
|
14
|
+
} = unlock(componentsPrivateApis);
|
|
12
15
|
function InserterListboxItem({
|
|
13
16
|
isFirst,
|
|
14
17
|
as: Component,
|
|
15
18
|
children,
|
|
16
19
|
...props
|
|
17
20
|
}, ref) {
|
|
18
|
-
const state = useContext(InserterListboxContext);
|
|
19
21
|
return createElement(CompositeItem, {
|
|
20
22
|
ref: ref,
|
|
21
|
-
state: state,
|
|
22
23
|
role: "option"
|
|
23
|
-
// Use the CompositeItem `
|
|
24
|
-
// isFocusable
|
|
25
|
-
// with tab order in the inserter list.
|
|
24
|
+
// Use the CompositeItem `accessibleWhenDisabled` prop
|
|
25
|
+
// over Button's `isFocusable`. The latter was shown to
|
|
26
|
+
// cause an issue with tab order in the inserter list.
|
|
26
27
|
,
|
|
27
|
-
|
|
28
|
-
...props
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
accessibleWhenDisabled: true,
|
|
29
|
+
...props,
|
|
30
|
+
render: htmlProps => {
|
|
31
|
+
const propsWithTabIndex = {
|
|
32
|
+
...htmlProps,
|
|
33
|
+
tabIndex: isFirst ? 0 : htmlProps.tabIndex
|
|
34
|
+
};
|
|
35
|
+
if (Component) {
|
|
36
|
+
return createElement(Component, {
|
|
37
|
+
...propsWithTabIndex
|
|
38
|
+
}, children);
|
|
39
|
+
}
|
|
40
|
+
if (typeof children === 'function') {
|
|
41
|
+
return children(propsWithTabIndex);
|
|
42
|
+
}
|
|
43
|
+
return createElement(Button, {
|
|
36
44
|
...propsWithTabIndex
|
|
37
45
|
}, children);
|
|
38
46
|
}
|
|
39
|
-
if (typeof children === 'function') {
|
|
40
|
-
return children(propsWithTabIndex);
|
|
41
|
-
}
|
|
42
|
-
return createElement(Button, {
|
|
43
|
-
...propsWithTabIndex
|
|
44
|
-
}, children);
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
export default forwardRef(InserterListboxItem);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Button","
|
|
1
|
+
{"version":3,"names":["Button","privateApis","componentsPrivateApis","forwardRef","unlock","CompositeItemV2","CompositeItem","InserterListboxItem","isFirst","as","Component","children","props","ref","createElement","role","accessibleWhenDisabled","render","htmlProps","propsWithTabIndex","tabIndex"],"sources":["@wordpress/block-editor/src/components/inserter-listbox/item.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { CompositeItemV2: CompositeItem } = unlock( componentsPrivateApis );\n\nfunction InserterListboxItem(\n\t{ isFirst, as: Component, children, ...props },\n\tref\n) {\n\treturn (\n\t\t<CompositeItem\n\t\t\tref={ ref }\n\t\t\trole=\"option\"\n\t\t\t// Use the CompositeItem `accessibleWhenDisabled` prop\n\t\t\t// over Button's `isFocusable`. The latter was shown to\n\t\t\t// cause an issue with tab order in the inserter list.\n\t\t\taccessibleWhenDisabled\n\t\t\t{ ...props }\n\t\t\trender={ ( htmlProps ) => {\n\t\t\t\tconst propsWithTabIndex = {\n\t\t\t\t\t...htmlProps,\n\t\t\t\t\ttabIndex: isFirst ? 0 : htmlProps.tabIndex,\n\t\t\t\t};\n\t\t\t\tif ( Component ) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Component { ...propsWithTabIndex }>\n\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t</Component>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif ( typeof children === 'function' ) {\n\t\t\t\t\treturn children( propsWithTabIndex );\n\t\t\t\t}\n\t\t\t\treturn <Button { ...propsWithTabIndex }>{ children }</Button>;\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nexport default forwardRef( InserterListboxItem );\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,MAAM,EACNC,WAAW,IAAIC,qBAAqB,QAC9B,uBAAuB;AAC9B,SAASC,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,MAAM;EAAEC,eAAe,EAAEC;AAAc,CAAC,GAAGF,MAAM,CAAEF,qBAAsB,CAAC;AAE1E,SAASK,mBAAmBA,CAC3B;EAAEC,OAAO;EAAEC,EAAE,EAAEC,SAAS;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAC9CC,GAAG,EACF;EACD,OACCC,aAAA,CAACR,aAAa;IACbO,GAAG,EAAGA,GAAK;IACXE,IAAI,EAAC;IACL;IACA;IACA;IAAA;IACAC,sBAAsB;IAAA,GACjBJ,KAAK;IACVK,MAAM,EAAKC,SAAS,IAAM;MACzB,MAAMC,iBAAiB,GAAG;QACzB,GAAGD,SAAS;QACZE,QAAQ,EAAEZ,OAAO,GAAG,CAAC,GAAGU,SAAS,CAACE;MACnC,CAAC;MACD,IAAKV,SAAS,EAAG;QAChB,OACCI,aAAA,CAACJ,SAAS;UAAA,GAAMS;QAAiB,GAC9BR,QACQ,CAAC;MAEd;MACA,IAAK,OAAOA,QAAQ,KAAK,UAAU,EAAG;QACrC,OAAOA,QAAQ,CAAEQ,iBAAkB,CAAC;MACrC;MACA,OAAOL,aAAA,CAACd,MAAM;QAAA,GAAMmB;MAAiB,GAAKR,QAAkB,CAAC;IAC9D;EAAG,CACH,CAAC;AAEJ;AAEA,eAAeR,UAAU,CAAEI,mBAAoB,CAAC"}
|