@wordpress/block-editor 7.0.4 → 8.0.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 +11 -0
- package/README.md +31 -0
- package/build/components/alignment-control/ui.js +1 -2
- package/build/components/alignment-control/ui.js.map +1 -1
- package/build/components/block-icon/index.js +5 -1
- package/build/components/block-icon/index.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -0
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/index.native.js +1 -1
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/use-multi-selection.js +21 -8
- package/build/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
- package/build/components/block-navigation/dropdown.js +0 -1
- package/build/components/block-navigation/dropdown.js.map +1 -1
- package/build/components/block-patterns-list/index.js +1 -8
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-settings/container.native.js +5 -2
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +22 -2
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/preview.native.js +2 -2
- package/build/components/block-styles/preview.native.js.map +1 -1
- package/build/components/colors-gradients/control.js +8 -47
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +81 -6
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/duotone-control/index.js +5 -2
- package/build/components/duotone-control/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +27 -15
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/iframe/index.js +1 -1
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +20 -2
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +2 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/inner-blocks/index.js +5 -4
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +4 -3
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/explorer.js +62 -0
- package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +111 -0
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
- package/build/components/inserter/block-patterns-explorer/sidebar.js +78 -0
- package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
- package/build/components/inserter/block-patterns-tab.js +74 -45
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
- package/build/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
- package/build/components/inserter/pattern-panel.js +19 -10
- package/build/components/inserter/pattern-panel.js.map +1 -1
- package/build/components/inspector-controls/groups.js +3 -1
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +9 -6
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/link-control/index.js +88 -35
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/link-preview.js +19 -6
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/link-control/search-input.js +12 -3
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block.js +49 -23
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +92 -73
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +39 -16
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +1 -1
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +8 -58
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/rich-text/embed-handler-picker.native.js +1 -0
- package/build/components/rich-text/embed-handler-picker.native.js.map +1 -1
- package/build/components/rich-text/format-edit.js +28 -2
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/rich-text/format-toolbar/index.js +2 -1
- package/build/components/rich-text/format-toolbar/index.js.map +1 -1
- package/build/components/url-input/index.js +11 -4
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-setting/index.js +48 -9
- package/build/components/use-setting/index.js.map +1 -1
- package/build/hooks/border.js +5 -5
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color-panel.js +2 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/duotone.js +16 -5
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/font-appearance.js +49 -6
- package/build/hooks/font-appearance.js.map +1 -1
- package/build/hooks/font-family.js +37 -16
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +51 -9
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/index.js +8 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +8 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/letter-spacing.js +44 -7
- package/build/hooks/letter-spacing.js.map +1 -1
- package/build/hooks/line-height.js +45 -8
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/margin.js +1 -1
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +1 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/text-decoration.js +42 -6
- package/build/hooks/text-decoration.js.map +1 -1
- package/build/hooks/text-transform.js +42 -6
- package/build/hooks/text-transform.js.map +1 -1
- package/build/hooks/typography.js +108 -8
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/use-cached-truthy.js +29 -0
- package/build/hooks/use-cached-truthy.js.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/layouts/flex.js +120 -28
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +303 -265
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +1 -3
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +23 -22
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +44 -35
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/alignment-control/ui.js +1 -2
- package/build-module/components/alignment-control/ui.js.map +1 -1
- package/build-module/components/block-icon/index.js +5 -1
- package/build-module/components/block-icon/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +4 -0
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/index.native.js +1 -1
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-multi-selection.js +21 -8
- package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
- package/build-module/components/block-navigation/dropdown.js +0 -1
- package/build-module/components/block-navigation/dropdown.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +1 -6
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +6 -3
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +24 -4
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/preview.native.js +2 -2
- package/build-module/components/block-styles/preview.native.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +12 -53
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +82 -6
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/duotone-control/index.js +5 -2
- package/build-module/components/duotone-control/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +23 -15
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -1
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +3 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +6 -5
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +5 -4
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/explorer.js +50 -0
- package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +92 -0
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js +69 -0
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
- package/build-module/components/inserter/block-patterns-tab.js +75 -46
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
- package/build-module/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
- package/build-module/components/inserter/pattern-panel.js +21 -13
- package/build-module/components/inserter/pattern-panel.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +3 -1
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +9 -6
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/link-control/index.js +88 -36
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +19 -7
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/link-control/search-input.js +11 -3
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block.js +49 -24
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +92 -73
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +41 -18
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +1 -1
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +8 -58
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/rich-text/embed-handler-picker.native.js +1 -0
- package/build-module/components/rich-text/embed-handler-picker.native.js.map +1 -1
- package/build-module/components/rich-text/format-edit.js +28 -3
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar/index.js +2 -1
- package/build-module/components/rich-text/format-toolbar/index.js.map +1 -1
- package/build-module/components/url-input/index.js +11 -4
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +48 -9
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/hooks/border.js +5 -5
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color-panel.js +2 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/duotone.js +16 -5
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/font-appearance.js +45 -6
- package/build-module/hooks/font-appearance.js.map +1 -1
- package/build-module/hooks/font-family.js +33 -16
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +47 -9
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/letter-spacing.js +40 -7
- package/build-module/hooks/letter-spacing.js.map +1 -1
- package/build-module/hooks/line-height.js +41 -8
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/margin.js +1 -1
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +1 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/text-decoration.js +38 -6
- package/build-module/hooks/text-decoration.js.map +1 -1
- package/build-module/hooks/text-transform.js +38 -6
- package/build-module/hooks/text-transform.js.map +1 -1
- package/build-module/hooks/typography.js +117 -17
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/use-cached-truthy.js +21 -0
- package/build-module/hooks/use-cached-truthy.js.map +1 -0
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/flex.js +124 -32
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +266 -241
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +1 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +23 -22
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +42 -30
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +160 -57
- package/build-style/style.css +160 -57
- package/package.json +13 -14
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +0 -2
- package/src/components/alignment-control/ui.js +1 -4
- package/src/components/block-draggable/style.scss +19 -4
- package/src/components/block-icon/index.js +4 -1
- package/src/components/block-inspector/index.js +5 -0
- package/src/components/block-list/index.native.js +1 -1
- package/src/components/block-list/use-block-props/use-multi-selection.js +27 -7
- package/src/components/block-navigation/dropdown.js +0 -1
- package/src/components/block-patterns-list/index.js +1 -8
- package/src/components/block-patterns-list/style.scss +22 -12
- package/src/components/block-settings/container.native.js +7 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +19 -7
- package/src/components/block-styles/preview.native.js +2 -2
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +1 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +88 -63
- package/src/components/colors-gradients/control.js +19 -62
- package/src/components/colors-gradients/panel-color-gradient-settings.js +76 -6
- package/src/components/colors-gradients/style.scss +3 -14
- package/src/components/colors-gradients/test/control.js +0 -16
- package/src/components/duotone-control/index.js +6 -0
- package/src/components/duotone-control/style.scss +27 -12
- package/src/components/font-appearance-control/index.js +22 -14
- package/src/components/iframe/index.js +1 -1
- package/src/components/index.js +3 -4
- package/src/components/index.native.js +1 -4
- package/src/components/inner-blocks/index.js +4 -4
- package/src/components/inner-blocks/index.native.js +7 -4
- package/src/components/inserter/block-patterns-explorer/explorer.js +50 -0
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +122 -0
- package/src/components/inserter/block-patterns-explorer/sidebar.js +73 -0
- package/src/components/inserter/block-patterns-tab.js +107 -80
- package/src/components/inserter/hooks/use-block-type-impressions.native.js +14 -21
- package/src/components/inserter/pattern-panel.js +33 -16
- package/src/components/inserter/style.scss +64 -1
- package/src/components/inserter/test/block-types-tab.native.js +1 -1
- package/src/components/inserter/test/fixtures/index.native.js +12 -0
- package/src/components/inspector-controls/groups.js +4 -0
- package/src/components/letter-spacing-control/index.js +12 -6
- package/src/components/link-control/README.md +7 -0
- package/src/components/link-control/index.js +99 -34
- package/src/components/link-control/link-preview.js +21 -9
- package/src/components/link-control/search-input.js +9 -3
- package/src/components/link-control/style.scss +32 -16
- package/src/components/link-control/test/index.js +179 -4
- package/src/components/list-view/block.js +67 -23
- package/src/components/list-view/branch.js +113 -91
- package/src/components/list-view/index.js +58 -19
- package/src/components/list-view/leaf.js +1 -1
- package/src/components/list-view/style.scss +14 -3
- package/src/components/list-view/use-list-view-client-ids.js +7 -66
- package/src/components/rich-text/embed-handler-picker.native.js +1 -0
- package/src/components/rich-text/format-edit.js +36 -2
- package/src/components/rich-text/format-toolbar/index.js +3 -0
- package/src/components/url-input/index.js +14 -4
- package/src/components/use-setting/index.js +49 -11
- package/src/hooks/border.js +8 -11
- package/src/hooks/color-panel.js +1 -0
- package/src/hooks/duotone.js +21 -7
- package/src/hooks/font-appearance.js +38 -7
- package/src/hooks/font-family.js +29 -13
- package/src/hooks/font-size.js +42 -6
- package/src/hooks/index.js +1 -0
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/layout.scss +3 -1
- package/src/hooks/letter-spacing.js +35 -7
- package/src/hooks/line-height.js +37 -9
- package/src/hooks/margin.js +1 -1
- package/src/hooks/padding.js +1 -1
- package/src/hooks/text-decoration.js +34 -6
- package/src/hooks/text-transform.js +34 -6
- package/src/hooks/typography.js +165 -15
- package/src/hooks/typography.scss +16 -0
- package/src/hooks/use-cached-truthy.js +20 -0
- package/src/index.js +1 -0
- package/src/layouts/flex.js +137 -41
- package/src/store/actions.js +223 -391
- package/src/store/index.js +1 -2
- package/src/store/reducer.js +36 -18
- package/src/store/selectors.js +52 -47
- package/src/store/test/actions.js +395 -694
- package/src/store/test/selectors.js +79 -21
- package/src/style.scss +1 -1
- package/src/utils/test/parse-css-unit-to-px.js +127 -167
- package/build/components/text-decoration-and-transform/index.js +0 -39
- package/build/components/text-decoration-and-transform/index.js.map +0 -1
- package/build/store/controls.js +0 -44
- package/build/store/controls.js.map +0 -1
- package/build-module/components/text-decoration-and-transform/index.js +0 -30
- package/build-module/components/text-decoration-and-transform/index.js.map +0 -1
- package/build-module/store/controls.js +0 -32
- package/build-module/store/controls.js.map +0 -1
- package/src/components/text-decoration-and-transform/index.js +0 -36
- package/src/components/text-decoration-and-transform/style.scss +0 -3
- package/src/store/controls.js +0 -39
|
@@ -1,23 +1,38 @@
|
|
|
1
|
+
// Must equal $color-palette-circle-size and $color-palette-circle-spacing from:
|
|
2
|
+
// @wordpress/components/src/circular-option-picker/style.scss
|
|
3
|
+
$swatch-size: 28px;
|
|
4
|
+
$swatch-gap: 12px;
|
|
5
|
+
|
|
6
|
+
$popover-width: $sidebar-width;
|
|
7
|
+
$popover-padding: $grid-unit-20;
|
|
8
|
+
|
|
9
|
+
$swatch-columns: math.floor(math.div($popover-width + $swatch-gap - 2 * $popover-padding, $swatch-size + $swatch-gap));
|
|
10
|
+
|
|
1
11
|
.block-editor-duotone-control__popover {
|
|
2
|
-
.components-popover__content {
|
|
3
|
-
|
|
4
|
-
|
|
12
|
+
> .components-popover__content > div {
|
|
13
|
+
padding: $popover-padding;
|
|
14
|
+
width: $popover-width;
|
|
5
15
|
}
|
|
6
16
|
|
|
7
|
-
.components-
|
|
8
|
-
padding:
|
|
17
|
+
.components-menu-group__label {
|
|
18
|
+
padding: 0;
|
|
9
19
|
}
|
|
10
20
|
|
|
11
|
-
.components-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
.components-custom-gradient-picker__gradient-bar {
|
|
22
|
+
margin: $grid-unit-20 0 $grid-unit-15;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.components-circular-option-picker__swatches {
|
|
26
|
+
display: grid;
|
|
27
|
+
grid-template-columns: repeat($swatch-columns, $swatch-size);
|
|
28
|
+
gap: $swatch-gap;
|
|
29
|
+
justify-content: space-between;
|
|
15
30
|
}
|
|
16
31
|
}
|
|
17
32
|
|
|
18
|
-
.block-editor-duotone-
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
.block-editor-duotone-control__description {
|
|
34
|
+
margin: $grid-unit-20 0;
|
|
35
|
+
font-size: $helptext-font-size;
|
|
21
36
|
}
|
|
22
37
|
|
|
23
38
|
// Better align the popover under the swatch.
|
|
@@ -55,6 +55,26 @@ const FONT_WEIGHTS = [
|
|
|
55
55
|
},
|
|
56
56
|
];
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Adjusts font appearance field label in case either font styles or weights
|
|
60
|
+
* are disabled.
|
|
61
|
+
*
|
|
62
|
+
* @param {boolean} hasFontStyles Whether font styles are enabled and present.
|
|
63
|
+
* @param {boolean} hasFontWeights Whether font weights are enabled and present.
|
|
64
|
+
* @return {string} A label representing what font appearance is being edited.
|
|
65
|
+
*/
|
|
66
|
+
export const getFontAppearanceLabel = ( hasFontStyles, hasFontWeights ) => {
|
|
67
|
+
if ( ! hasFontStyles ) {
|
|
68
|
+
return __( 'Font weight' );
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if ( ! hasFontWeights ) {
|
|
72
|
+
return __( 'Font style' );
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return __( 'Appearance' );
|
|
76
|
+
};
|
|
77
|
+
|
|
58
78
|
/**
|
|
59
79
|
* Control to display unified font style and weight options.
|
|
60
80
|
*
|
|
@@ -70,6 +90,7 @@ export default function FontAppearanceControl( props ) {
|
|
|
70
90
|
value: { fontStyle, fontWeight },
|
|
71
91
|
} = props;
|
|
72
92
|
const hasStylesOrWeights = hasFontStyles || hasFontWeights;
|
|
93
|
+
const label = getFontAppearanceLabel( hasFontStyles, hasFontWeights );
|
|
73
94
|
const defaultOption = {
|
|
74
95
|
key: 'default',
|
|
75
96
|
name: __( 'Default' ),
|
|
@@ -152,19 +173,6 @@ export default function FontAppearanceControl( props ) {
|
|
|
152
173
|
option.style.fontWeight === fontWeight
|
|
153
174
|
) || selectOptions[ 0 ];
|
|
154
175
|
|
|
155
|
-
// Adjusts field label in case either styles or weights are disabled.
|
|
156
|
-
const getLabel = () => {
|
|
157
|
-
if ( ! hasFontStyles ) {
|
|
158
|
-
return __( 'Font weight' );
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if ( ! hasFontWeights ) {
|
|
162
|
-
return __( 'Font style' );
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return __( 'Appearance' );
|
|
166
|
-
};
|
|
167
|
-
|
|
168
176
|
// Adjusts screen reader description based on styles or weights.
|
|
169
177
|
const getDescribedBy = () => {
|
|
170
178
|
if ( ! currentSelection ) {
|
|
@@ -198,7 +206,7 @@ export default function FontAppearanceControl( props ) {
|
|
|
198
206
|
hasStylesOrWeights && (
|
|
199
207
|
<CustomSelectControl
|
|
200
208
|
className="components-font-appearance-control"
|
|
201
|
-
label={
|
|
209
|
+
label={ label }
|
|
202
210
|
describedBy={ getDescribedBy() }
|
|
203
211
|
options={ selectOptions }
|
|
204
212
|
value={ currentSelection }
|
|
@@ -76,7 +76,7 @@ function styleSheetsCompat( doc ) {
|
|
|
76
76
|
|
|
77
77
|
if ( isMatch && ! doc.getElementById( ownerNode.id ) ) {
|
|
78
78
|
// eslint-disable-next-line no-console
|
|
79
|
-
console.
|
|
79
|
+
console.warn(
|
|
80
80
|
`Stylesheet ${ ownerNode.id } was not properly added.
|
|
81
81
|
For blocks, use the block API's style (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#style) or editorStyle (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#editor-style).
|
|
82
82
|
For themes, use add_editor_style (https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#editor-styles).`,
|
package/src/components/index.js
CHANGED
|
@@ -45,6 +45,8 @@ export { default as __experimentalDuotoneControl } from './duotone-control';
|
|
|
45
45
|
export { default as __experimentalFontAppearanceControl } from './font-appearance-control';
|
|
46
46
|
export { default as __experimentalFontFamilyControl } from './font-family';
|
|
47
47
|
export { default as __experimentalLetterSpacingControl } from './letter-spacing-control';
|
|
48
|
+
export { default as __experimentalTextDecorationControl } from './text-decoration-control';
|
|
49
|
+
export { default as __experimentalTextTransformControl } from './text-transform-control';
|
|
48
50
|
export { default as __experimentalColorGradientControl } from './colors-gradients/control';
|
|
49
51
|
export { default as __experimentalPanelColorGradientSettings } from './colors-gradients/panel-color-gradient-settings';
|
|
50
52
|
export {
|
|
@@ -52,10 +54,7 @@ export {
|
|
|
52
54
|
ImageEditingProvider as __experimentalImageEditingProvider,
|
|
53
55
|
} from './image-editor';
|
|
54
56
|
export { default as __experimentalImageSizeControl } from './image-size-control';
|
|
55
|
-
export {
|
|
56
|
-
default as InnerBlocks,
|
|
57
|
-
useInnerBlocksProps as __experimentalUseInnerBlocksProps,
|
|
58
|
-
} from './inner-blocks';
|
|
57
|
+
export { default as InnerBlocks, useInnerBlocksProps } from './inner-blocks';
|
|
59
58
|
export {
|
|
60
59
|
default as InspectorControls,
|
|
61
60
|
InspectorAdvancedControls,
|
|
@@ -18,10 +18,7 @@ export * from './colors';
|
|
|
18
18
|
export * from './gradients';
|
|
19
19
|
export * from './font-sizes';
|
|
20
20
|
export { AlignmentControl, AlignmentToolbar } from './alignment-control';
|
|
21
|
-
export {
|
|
22
|
-
default as InnerBlocks,
|
|
23
|
-
useInnerBlocksProps as __experimentalUseInnerBlocksProps,
|
|
24
|
-
} from './inner-blocks';
|
|
21
|
+
export { default as InnerBlocks, useInnerBlocksProps } from './inner-blocks';
|
|
25
22
|
export {
|
|
26
23
|
default as InspectorControls,
|
|
27
24
|
InspectorAdvancedControls,
|
|
@@ -12,7 +12,7 @@ import { useSelect } from '@wordpress/data';
|
|
|
12
12
|
import {
|
|
13
13
|
getBlockType,
|
|
14
14
|
store as blocksStore,
|
|
15
|
-
|
|
15
|
+
__unstableGetInnerBlocksProps as getInnerBlocksProps,
|
|
16
16
|
} from '@wordpress/blocks';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -210,13 +210,13 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
|
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
useInnerBlocksProps.save = getInnerBlocksProps;
|
|
214
|
+
|
|
213
215
|
// Expose default appender placeholders as components.
|
|
214
216
|
ForwardedInnerBlocks.DefaultBlockAppender = DefaultBlockAppender;
|
|
215
217
|
ForwardedInnerBlocks.ButtonBlockAppender = ButtonBlockAppender;
|
|
216
218
|
|
|
217
|
-
ForwardedInnerBlocks.Content =
|
|
218
|
-
( { BlockContent } ) => <BlockContent />
|
|
219
|
-
);
|
|
219
|
+
ForwardedInnerBlocks.Content = () => useInnerBlocksProps.save().children;
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
222
|
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inner-blocks/README.md
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getBlockType,
|
|
7
|
+
__unstableGetInnerBlocksProps as getInnerBlocksProps,
|
|
8
|
+
} from '@wordpress/blocks';
|
|
6
9
|
import { useRef } from '@wordpress/element';
|
|
7
10
|
|
|
8
11
|
/**
|
|
@@ -189,9 +192,9 @@ const InnerBlocks = ( props ) => {
|
|
|
189
192
|
InnerBlocks.DefaultBlockAppender = DefaultBlockAppender;
|
|
190
193
|
InnerBlocks.ButtonBlockAppender = ButtonBlockAppender;
|
|
191
194
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
) );
|
|
195
|
+
useInnerBlocksProps.save = getInnerBlocksProps;
|
|
196
|
+
|
|
197
|
+
InnerBlocks.Content = () => useInnerBlocksProps.save().children;
|
|
195
198
|
|
|
196
199
|
/**
|
|
197
200
|
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inner-blocks/README.md
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Modal } from '@wordpress/components';
|
|
5
|
+
import { useState } from '@wordpress/element';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import PatternExplorerSidebar from './sidebar';
|
|
12
|
+
import PatternList from './patterns-list';
|
|
13
|
+
|
|
14
|
+
function PatternsExplorer( { initialCategory, patternCategories } ) {
|
|
15
|
+
const [ filterValue, setFilterValue ] = useState( '' );
|
|
16
|
+
const [ selectedCategory, setSelectedCategory ] = useState(
|
|
17
|
+
initialCategory?.name
|
|
18
|
+
);
|
|
19
|
+
return (
|
|
20
|
+
<div className="block-editor-block-patterns-explorer">
|
|
21
|
+
<PatternExplorerSidebar
|
|
22
|
+
selectedCategory={ selectedCategory }
|
|
23
|
+
patternCategories={ patternCategories }
|
|
24
|
+
onClickCategory={ setSelectedCategory }
|
|
25
|
+
filterValue={ filterValue }
|
|
26
|
+
setFilterValue={ setFilterValue }
|
|
27
|
+
/>
|
|
28
|
+
<PatternList
|
|
29
|
+
filterValue={ filterValue }
|
|
30
|
+
selectedCategory={ selectedCategory }
|
|
31
|
+
patternCategories={ patternCategories }
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function PatternsExplorerModal( { onModalClose, ...restProps } ) {
|
|
38
|
+
return (
|
|
39
|
+
<Modal
|
|
40
|
+
title={ __( 'Patterns' ) }
|
|
41
|
+
closeLabel={ __( 'Close' ) }
|
|
42
|
+
onRequestClose={ onModalClose }
|
|
43
|
+
isFullScreen
|
|
44
|
+
>
|
|
45
|
+
<PatternsExplorer { ...restProps } />
|
|
46
|
+
</Modal>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default PatternsExplorerModal;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo, useEffect } from '@wordpress/element';
|
|
5
|
+
import { _n, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import { useDebounce, useAsyncList } from '@wordpress/compose';
|
|
7
|
+
import { __experimentalHeading as Heading } from '@wordpress/components';
|
|
8
|
+
import { speak } from '@wordpress/a11y';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import BlockPatternsList from '../../block-patterns-list';
|
|
14
|
+
import InserterNoResults from '../no-results';
|
|
15
|
+
import useInsertionPoint from '../hooks/use-insertion-point';
|
|
16
|
+
import usePatternsState from '../hooks/use-patterns-state';
|
|
17
|
+
import InserterListbox from '../../inserter-listbox';
|
|
18
|
+
import { searchItems } from '../search-items';
|
|
19
|
+
|
|
20
|
+
const INITIAL_INSERTER_RESULTS = 2;
|
|
21
|
+
|
|
22
|
+
function PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {
|
|
23
|
+
if ( ! filterValue ) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<Heading
|
|
28
|
+
level={ 2 }
|
|
29
|
+
lineHeight={ '48px' }
|
|
30
|
+
className="block-editor-block-patterns-explorer__search-results-count"
|
|
31
|
+
>
|
|
32
|
+
{ sprintf(
|
|
33
|
+
/* translators: %d: number of patterns. %s: block pattern search query */
|
|
34
|
+
_n(
|
|
35
|
+
'%1$d pattern found for "%2$s"',
|
|
36
|
+
'%1$d patterns found for "%2$s"',
|
|
37
|
+
filteredBlockPatternsLength
|
|
38
|
+
),
|
|
39
|
+
filteredBlockPatternsLength,
|
|
40
|
+
filterValue
|
|
41
|
+
) }
|
|
42
|
+
</Heading>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function PatternList( { filterValue, selectedCategory, patternCategories } ) {
|
|
47
|
+
const debouncedSpeak = useDebounce( speak, 500 );
|
|
48
|
+
const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {
|
|
49
|
+
shouldFocusBlock: true,
|
|
50
|
+
} );
|
|
51
|
+
const [ allPatterns, , onSelectBlockPattern ] = usePatternsState(
|
|
52
|
+
onInsertBlocks,
|
|
53
|
+
destinationRootClientId
|
|
54
|
+
);
|
|
55
|
+
const registeredPatternCategories = useMemo(
|
|
56
|
+
() =>
|
|
57
|
+
patternCategories.map(
|
|
58
|
+
( patternCategory ) => patternCategory.name
|
|
59
|
+
),
|
|
60
|
+
[ patternCategories ]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const filteredBlockPatterns = useMemo( () => {
|
|
64
|
+
if ( ! filterValue ) {
|
|
65
|
+
return allPatterns.filter( ( pattern ) =>
|
|
66
|
+
selectedCategory === 'uncategorized'
|
|
67
|
+
? ! pattern.categories?.length ||
|
|
68
|
+
pattern.categories.every(
|
|
69
|
+
( category ) =>
|
|
70
|
+
! registeredPatternCategories.includes(
|
|
71
|
+
category
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
: pattern.categories?.includes( selectedCategory )
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return searchItems( allPatterns, filterValue );
|
|
78
|
+
}, [ filterValue, selectedCategory, allPatterns ] );
|
|
79
|
+
|
|
80
|
+
// Announce search results on change.
|
|
81
|
+
useEffect( () => {
|
|
82
|
+
if ( ! filterValue ) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const count = filteredBlockPatterns.length;
|
|
86
|
+
const resultsFoundMessage = sprintf(
|
|
87
|
+
/* translators: %d: number of results. */
|
|
88
|
+
_n( '%d result found.', '%d results found.', count ),
|
|
89
|
+
count
|
|
90
|
+
);
|
|
91
|
+
debouncedSpeak( resultsFoundMessage );
|
|
92
|
+
}, [ filterValue, debouncedSpeak ] );
|
|
93
|
+
|
|
94
|
+
const currentShownPatterns = useAsyncList( filteredBlockPatterns, {
|
|
95
|
+
step: INITIAL_INSERTER_RESULTS,
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
const hasItems = !! filteredBlockPatterns?.length;
|
|
99
|
+
return (
|
|
100
|
+
<div className="block-editor-block-patterns-explorer__list">
|
|
101
|
+
{ hasItems && (
|
|
102
|
+
<PatternsListHeader
|
|
103
|
+
filterValue={ filterValue }
|
|
104
|
+
filteredBlockPatternsLength={ filteredBlockPatterns.length }
|
|
105
|
+
/>
|
|
106
|
+
) }
|
|
107
|
+
<InserterListbox>
|
|
108
|
+
{ ! hasItems && <InserterNoResults /> }
|
|
109
|
+
{ hasItems && (
|
|
110
|
+
<BlockPatternsList
|
|
111
|
+
shownPatterns={ currentShownPatterns }
|
|
112
|
+
blockPatterns={ filteredBlockPatterns }
|
|
113
|
+
onClickPattern={ onSelectBlockPattern }
|
|
114
|
+
isDraggable={ false }
|
|
115
|
+
/>
|
|
116
|
+
) }
|
|
117
|
+
</InserterListbox>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default PatternList;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Button, SearchControl } from '@wordpress/components';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
function PatternCategoriesList( {
|
|
8
|
+
selectedCategory,
|
|
9
|
+
patternCategories,
|
|
10
|
+
onClickCategory,
|
|
11
|
+
} ) {
|
|
12
|
+
const baseClassName = 'block-editor-block-patterns-explorer__sidebar';
|
|
13
|
+
return (
|
|
14
|
+
<div className={ `${ baseClassName }__categories-list` }>
|
|
15
|
+
{ patternCategories.map( ( { name, label } ) => {
|
|
16
|
+
return (
|
|
17
|
+
<Button
|
|
18
|
+
key={ name }
|
|
19
|
+
label={ label }
|
|
20
|
+
className={ `${ baseClassName }__categories-list__item` }
|
|
21
|
+
isPressed={ selectedCategory === name }
|
|
22
|
+
onClick={ () => {
|
|
23
|
+
onClickCategory( name );
|
|
24
|
+
} }
|
|
25
|
+
>
|
|
26
|
+
{ label }
|
|
27
|
+
</Button>
|
|
28
|
+
);
|
|
29
|
+
} ) }
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function PatternsExplorerSearch( { filterValue, setFilterValue } ) {
|
|
35
|
+
const baseClassName = 'block-editor-block-patterns-explorer__search';
|
|
36
|
+
return (
|
|
37
|
+
<div className={ baseClassName }>
|
|
38
|
+
<SearchControl
|
|
39
|
+
onChange={ setFilterValue }
|
|
40
|
+
value={ filterValue }
|
|
41
|
+
label={ __( 'Search for patterns' ) }
|
|
42
|
+
placeholder={ __( 'Search' ) }
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function PatternExplorerSidebar( {
|
|
49
|
+
selectedCategory,
|
|
50
|
+
patternCategories,
|
|
51
|
+
onClickCategory,
|
|
52
|
+
filterValue,
|
|
53
|
+
setFilterValue,
|
|
54
|
+
} ) {
|
|
55
|
+
const baseClassName = 'block-editor-block-patterns-explorer__sidebar';
|
|
56
|
+
return (
|
|
57
|
+
<div className={ baseClassName }>
|
|
58
|
+
<PatternsExplorerSearch
|
|
59
|
+
filterValue={ filterValue }
|
|
60
|
+
setFilterValue={ setFilterValue }
|
|
61
|
+
/>
|
|
62
|
+
{ ! filterValue && (
|
|
63
|
+
<PatternCategoriesList
|
|
64
|
+
selectedCategory={ selectedCategory }
|
|
65
|
+
patternCategories={ patternCategories }
|
|
66
|
+
onClickCategory={ onClickCategory }
|
|
67
|
+
/>
|
|
68
|
+
) }
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default PatternExplorerSidebar;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { fromPairs } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
9
|
-
import { useMemo,
|
|
4
|
+
import { useMemo, useState, useCallback } from '@wordpress/element';
|
|
10
5
|
import { _x } from '@wordpress/i18n';
|
|
11
6
|
import { useAsyncList } from '@wordpress/compose';
|
|
12
7
|
|
|
@@ -16,66 +11,30 @@ import { useAsyncList } from '@wordpress/compose';
|
|
|
16
11
|
import PatternInserterPanel from './pattern-panel';
|
|
17
12
|
import usePatternsState from './hooks/use-patterns-state';
|
|
18
13
|
import BlockPatternList from '../block-patterns-list';
|
|
14
|
+
import PatternsExplorerModal from './block-patterns-explorer/explorer';
|
|
19
15
|
|
|
20
16
|
function BlockPatternsCategory( {
|
|
21
17
|
rootClientId,
|
|
22
18
|
onInsert,
|
|
23
19
|
selectedCategory,
|
|
24
|
-
|
|
20
|
+
populatedCategories,
|
|
25
21
|
} ) {
|
|
26
|
-
const [ allPatterns,
|
|
22
|
+
const [ allPatterns, , onClick ] = usePatternsState(
|
|
27
23
|
onInsert,
|
|
28
24
|
rootClientId
|
|
29
25
|
);
|
|
30
26
|
|
|
31
|
-
// Remove any empty categories
|
|
32
|
-
const populatedCategories = useMemo(
|
|
33
|
-
() =>
|
|
34
|
-
allCategories
|
|
35
|
-
.filter( ( category ) =>
|
|
36
|
-
allPatterns.some( ( pattern ) =>
|
|
37
|
-
pattern.categories?.includes( category.name )
|
|
38
|
-
)
|
|
39
|
-
)
|
|
40
|
-
.sort( ( { name: currentName }, { name: nextName } ) => {
|
|
41
|
-
if ( ! [ currentName, nextName ].includes( 'featured' ) ) {
|
|
42
|
-
return 0;
|
|
43
|
-
}
|
|
44
|
-
return currentName === 'featured' ? -1 : 1;
|
|
45
|
-
} ),
|
|
46
|
-
[ allPatterns, allCategories ]
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const patternCategory = selectedCategory
|
|
50
|
-
? selectedCategory
|
|
51
|
-
: populatedCategories[ 0 ];
|
|
52
|
-
|
|
53
|
-
useEffect( () => {
|
|
54
|
-
if (
|
|
55
|
-
allPatterns.some(
|
|
56
|
-
( pattern ) => getPatternIndex( pattern ) === Infinity
|
|
57
|
-
) &&
|
|
58
|
-
! populatedCategories.find(
|
|
59
|
-
( category ) => category.name === 'uncategorized'
|
|
60
|
-
)
|
|
61
|
-
) {
|
|
62
|
-
populatedCategories.push( {
|
|
63
|
-
name: 'uncategorized',
|
|
64
|
-
label: _x( 'Uncategorized' ),
|
|
65
|
-
} );
|
|
66
|
-
}
|
|
67
|
-
}, [ populatedCategories, allPatterns ] );
|
|
68
|
-
|
|
69
27
|
const getPatternIndex = useCallback(
|
|
70
28
|
( pattern ) => {
|
|
71
|
-
if ( ! pattern.categories
|
|
29
|
+
if ( ! pattern.categories?.length ) {
|
|
72
30
|
return Infinity;
|
|
73
31
|
}
|
|
74
|
-
const indexedCategories =
|
|
75
|
-
|
|
76
|
-
name
|
|
77
|
-
|
|
78
|
-
|
|
32
|
+
const indexedCategories = populatedCategories.reduce(
|
|
33
|
+
( accumulator, { name }, index ) => {
|
|
34
|
+
accumulator[ name ] = index;
|
|
35
|
+
return accumulator;
|
|
36
|
+
},
|
|
37
|
+
{}
|
|
79
38
|
);
|
|
80
39
|
return Math.min(
|
|
81
40
|
...pattern.categories.map( ( cat ) =>
|
|
@@ -91,12 +50,11 @@ function BlockPatternsCategory( {
|
|
|
91
50
|
const currentCategoryPatterns = useMemo(
|
|
92
51
|
() =>
|
|
93
52
|
allPatterns.filter( ( pattern ) =>
|
|
94
|
-
|
|
53
|
+
selectedCategory.name === 'uncategorized'
|
|
95
54
|
? getPatternIndex( pattern ) === Infinity
|
|
96
|
-
: pattern.categories
|
|
97
|
-
pattern.categories.includes( patternCategory.name )
|
|
55
|
+
: pattern.categories?.includes( selectedCategory.name )
|
|
98
56
|
),
|
|
99
|
-
[ allPatterns,
|
|
57
|
+
[ allPatterns, selectedCategory ]
|
|
100
58
|
);
|
|
101
59
|
|
|
102
60
|
// Ordering the patterns is important for the async rendering.
|
|
@@ -108,25 +66,21 @@ function BlockPatternsCategory( {
|
|
|
108
66
|
|
|
109
67
|
const currentShownPatterns = useAsyncList( orderedPatterns );
|
|
110
68
|
|
|
69
|
+
if ( ! currentCategoryPatterns.length ) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
111
73
|
return (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
onClickPattern={ onClick }
|
|
123
|
-
label={ patternCategory.label }
|
|
124
|
-
orientation="vertical"
|
|
125
|
-
isDraggable
|
|
126
|
-
/>
|
|
127
|
-
</PatternInserterPanel>
|
|
128
|
-
) }
|
|
129
|
-
</>
|
|
74
|
+
<div className="block-editor-inserter__panel-content">
|
|
75
|
+
<BlockPatternList
|
|
76
|
+
shownPatterns={ currentShownPatterns }
|
|
77
|
+
blockPatterns={ currentCategoryPatterns }
|
|
78
|
+
onClickPattern={ onClick }
|
|
79
|
+
label={ selectedCategory.label }
|
|
80
|
+
orientation="vertical"
|
|
81
|
+
isDraggable
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
130
84
|
);
|
|
131
85
|
}
|
|
132
86
|
|
|
@@ -136,13 +90,86 @@ function BlockPatternsTabs( {
|
|
|
136
90
|
onClickCategory,
|
|
137
91
|
selectedCategory,
|
|
138
92
|
} ) {
|
|
93
|
+
const [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );
|
|
94
|
+
const [ allPatterns, allCategories ] = usePatternsState();
|
|
95
|
+
|
|
96
|
+
const hasRegisteredCategory = useCallback(
|
|
97
|
+
( pattern ) => {
|
|
98
|
+
if ( ! pattern.categories || ! pattern.categories.length ) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return pattern.categories.some( ( cat ) =>
|
|
103
|
+
allCategories.some( ( category ) => category.name === cat )
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
[ allCategories ]
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Remove any empty categories
|
|
110
|
+
const populatedCategories = useMemo( () => {
|
|
111
|
+
const categories = allCategories
|
|
112
|
+
.filter( ( category ) =>
|
|
113
|
+
allPatterns.some( ( pattern ) =>
|
|
114
|
+
pattern.categories?.includes( category.name )
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
.sort( ( { name: currentName }, { name: nextName } ) => {
|
|
118
|
+
if ( ! [ currentName, nextName ].includes( 'featured' ) ) {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
return currentName === 'featured' ? -1 : 1;
|
|
122
|
+
} );
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
allPatterns.some(
|
|
126
|
+
( pattern ) => ! hasRegisteredCategory( pattern )
|
|
127
|
+
) &&
|
|
128
|
+
! categories.find(
|
|
129
|
+
( category ) => category.name === 'uncategorized'
|
|
130
|
+
)
|
|
131
|
+
) {
|
|
132
|
+
categories.push( {
|
|
133
|
+
name: 'uncategorized',
|
|
134
|
+
label: _x( 'Uncategorized' ),
|
|
135
|
+
} );
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return categories;
|
|
139
|
+
}, [ allPatterns, allCategories ] );
|
|
140
|
+
|
|
141
|
+
const patternCategory = selectedCategory
|
|
142
|
+
? selectedCategory
|
|
143
|
+
: populatedCategories[ 0 ];
|
|
144
|
+
|
|
139
145
|
return (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
<>
|
|
147
|
+
{ ! showPatternsExplorer && (
|
|
148
|
+
<>
|
|
149
|
+
<PatternInserterPanel
|
|
150
|
+
selectedCategory={ patternCategory }
|
|
151
|
+
patternCategories={ populatedCategories }
|
|
152
|
+
onClickCategory={ onClickCategory }
|
|
153
|
+
openPatternExplorer={ () =>
|
|
154
|
+
setShowPatternsExplorer( true )
|
|
155
|
+
}
|
|
156
|
+
/>
|
|
157
|
+
<BlockPatternsCategory
|
|
158
|
+
rootClientId={ rootClientId }
|
|
159
|
+
onInsert={ onInsert }
|
|
160
|
+
selectedCategory={ patternCategory }
|
|
161
|
+
populatedCategories={ populatedCategories }
|
|
162
|
+
/>
|
|
163
|
+
</>
|
|
164
|
+
) }
|
|
165
|
+
{ showPatternsExplorer && (
|
|
166
|
+
<PatternsExplorerModal
|
|
167
|
+
initialCategory={ patternCategory }
|
|
168
|
+
patternCategories={ populatedCategories }
|
|
169
|
+
onModalClose={ () => setShowPatternsExplorer( false ) }
|
|
170
|
+
/>
|
|
171
|
+
) }
|
|
172
|
+
</>
|
|
146
173
|
);
|
|
147
174
|
}
|
|
148
175
|
|