@wordpress/block-editor 9.4.0 → 9.7.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 +6 -0
- package/README.md +1 -8
- package/build/components/block-list/block-invalid-warning.native.js +54 -6
- package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build/components/block-list/block.js +14 -4
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +2 -1
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +5 -4
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/layout.js +20 -5
- package/build/components/block-list/layout.js.map +1 -1
- package/build/components/block-list/use-block-props/use-block-class-names.js +5 -2
- package/build/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build/components/block-lock/modal.js +37 -7
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-mover/mover-description.js +95 -32
- package/build/components/block-mover/mover-description.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +5 -17
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +2 -2
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +1 -1
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-settings-menu/block-mode-toggle.js +1 -1
- package/build/components/block-settings-menu/block-mode-toggle.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-styles/index.js +3 -6
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-styles/preview.native.js.map +1 -1
- package/build/components/block-switcher/index.js +7 -1
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-title/index.js +8 -2
- package/build/components/block-title/index.js.map +1 -1
- package/build/components/block-title/use-block-display-title.js +12 -5
- package/build/components/block-title/use-block-display-title.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +1 -7
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +4 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-types-list/index.js +1 -1
- package/build/components/block-types-list/index.js.map +1 -1
- package/build/components/block-types-list/index.native.js +65 -23
- package/build/components/block-types-list/index.native.js.map +1 -1
- package/build/components/border-radius-control/index.js +5 -1
- package/build/components/border-radius-control/index.js.map +1 -1
- package/build/components/colors/utils.js +6 -2
- package/build/components/colors/utils.js.map +1 -1
- package/build/components/colors/with-colors.js +1 -1
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/control.js +49 -39
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +9 -3
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/date-format-picker/index.js +1 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +10 -4
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/iframe/index.js +19 -6
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/cropper.js +4 -3
- package/build/components/image-editor/cropper.js.map +1 -1
- package/build/components/image-editor/index.js +3 -1
- package/build/components/image-editor/index.js.map +1 -1
- package/build/components/image-size-control/index.js +3 -1
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +13 -6
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +11 -4
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/block-types-tab.native.js +30 -16
- package/build/components/inserter/block-types-tab.native.js.map +1 -1
- package/build/components/inserter/index.native.js +8 -3
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/preview-panel.js +8 -8
- package/build/components/inserter/preview-panel.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +5 -1
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/search-results.native.js +5 -2
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/inserter/utils.native.js +21 -0
- package/build/components/inserter/utils.native.js.map +1 -1
- package/build/components/inserter-list-item/index.js +7 -20
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +6 -3
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/line-height-control/index.js +6 -3
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/link-control/index.js +1 -1
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/is-url-like.js +1 -7
- package/build/components/link-control/is-url-like.js.map +1 -1
- package/build/components/link-control/use-search-handler.js +1 -7
- package/build/components/link-control/use-search-handler.js.map +1 -1
- package/build/components/list-view/block-select-button.js +15 -7
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/branch.js +1 -7
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +1 -1
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/expander.js +3 -1
- package/build/components/list-view/expander.js.map +1 -1
- package/build/components/media-placeholder/index.js +13 -2
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +3 -6
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/media-upload/index.native.js +8 -3
- package/build/components/media-upload/index.native.js.map +1 -1
- package/build/components/observe-typing/index.js +22 -8
- package/build/components/observe-typing/index.js.map +1 -1
- package/build/components/preview-options/index.js +2 -2
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/{use-no-recursive-renders → recursion-provider}/index.js +40 -18
- package/build/components/recursion-provider/index.js.map +1 -0
- package/build/components/rich-text/format-toolbar-container.js +61 -12
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +8 -2
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +3 -1
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/use-before-input-rules.js +110 -0
- package/build/components/rich-text/use-before-input-rules.js.map +1 -0
- package/build/components/rich-text/use-format-types.js +36 -16
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build/components/text-decoration-control/index.js +3 -1
- package/build/components/text-decoration-control/index.js.map +1 -1
- package/build/components/text-transform-control/index.js +3 -1
- package/build/components/text-transform-control/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +4 -1
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/url-popover/index.js +2 -1
- package/build/components/url-popover/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +38 -27
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-drag-selection.js +9 -2
- package/build/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js +3 -47
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-select-all.js +3 -1
- package/build/components/writing-flow/use-select-all.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +1 -3
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +1 -1
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/color.js +2 -4
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/index.js +8 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +61 -15
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +41 -31
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/utils.js +5 -3
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/layouts/flex.js +40 -36
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +35 -37
- package/build/layouts/flow.js.map +1 -1
- package/build/layouts/utils.js +35 -3
- package/build/layouts/utils.js.map +1 -1
- package/build/store/actions.js +15 -18
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +0 -4
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +5 -3
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +3 -3
- package/build/store/selectors.js.map +1 -1
- package/build/utils/block-variation-transforms.js +15 -9
- package/build/utils/block-variation-transforms.js.map +1 -1
- package/build/utils/pasting.js +9 -1
- package/build/utils/pasting.js.map +1 -1
- package/build-module/components/block-list/block-invalid-warning.native.js +50 -6
- package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build-module/components/block-list/block.js +15 -5
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -1
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +4 -2
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/layout.js +19 -4
- package/build-module/components/block-list/layout.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-block-class-names.js +5 -2
- package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build-module/components/block-lock/modal.js +39 -8
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-mover/mover-description.js +97 -33
- package/build-module/components/block-mover/mover-description.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +6 -18
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +2 -2
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +1 -1
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-mode-toggle.js +1 -1
- package/build-module/components/block-settings-menu/block-mode-toggle.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +2 -2
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-styles/index.js +4 -7
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-styles/preview.native.js.map +1 -1
- package/build-module/components/block-switcher/index.js +7 -1
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-title/index.js +8 -2
- package/build-module/components/block-title/index.js.map +1 -1
- package/build-module/components/block-title/use-block-display-title.js +12 -5
- package/build-module/components/block-title/use-block-display-title.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +1 -7
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +4 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-types-list/index.js +1 -1
- package/build-module/components/block-types-list/index.js.map +1 -1
- package/build-module/components/block-types-list/index.native.js +67 -25
- package/build-module/components/block-types-list/index.native.js.map +1 -1
- package/build-module/components/border-radius-control/index.js +6 -2
- package/build-module/components/border-radius-control/index.js.map +1 -1
- package/build-module/components/colors/utils.js +7 -3
- package/build-module/components/colors/utils.js.map +1 -1
- package/build-module/components/colors/with-colors.js +2 -2
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +50 -40
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +10 -4
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +1 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +7 -4
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/iframe/index.js +19 -6
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/cropper.js +4 -3
- package/build-module/components/image-editor/cropper.js.map +1 -1
- package/build-module/components/image-editor/index.js +3 -1
- package/build-module/components/image-editor/index.js.map +1 -1
- package/build-module/components/image-size-control/index.js +3 -1
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.js +1 -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/inserter/block-types-tab.native.js +31 -15
- package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
- package/build-module/components/inserter/index.native.js +9 -2
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/preview-panel.js +9 -9
- package/build-module/components/inserter/preview-panel.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +6 -2
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js +6 -3
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/inserter/utils.native.js +19 -0
- package/build-module/components/inserter/utils.native.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +5 -18
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +5 -3
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/line-height-control/index.js +5 -3
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -1
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/is-url-like.js +1 -6
- package/build-module/components/link-control/is-url-like.js.map +1 -1
- package/build-module/components/link-control/use-search-handler.js +1 -6
- package/build-module/components/link-control/use-search-handler.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +16 -8
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/branch.js +1 -6
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +1 -1
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/expander.js +3 -2
- package/build-module/components/list-view/expander.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +13 -2
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +4 -7
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/media-upload/index.native.js +9 -2
- package/build-module/components/media-upload/index.native.js.map +1 -1
- package/build-module/components/observe-typing/index.js +22 -8
- package/build-module/components/observe-typing/index.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -2
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/{use-no-recursive-renders → recursion-provider}/index.js +39 -19
- package/build-module/components/recursion-provider/index.js.map +1 -0
- package/build-module/components/rich-text/format-toolbar-container.js +58 -12
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +7 -2
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +3 -1
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-before-input-rules.js +96 -0
- package/build-module/components/rich-text/use-before-input-rules.js.map +1 -0
- package/build-module/components/rich-text/use-format-types.js +37 -18
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/text-decoration-control/index.js +4 -2
- package/build-module/components/text-decoration-control/index.js.map +1 -1
- package/build-module/components/text-transform-control/index.js +4 -2
- package/build-module/components/text-transform-control/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +4 -1
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/url-popover/index.js +2 -1
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +40 -29
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-drag-selection.js +9 -2
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js +3 -45
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-select-all.js +3 -1
- package/build-module/components/writing-flow/use-select-all.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +1 -3
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/color.js +2 -3
- package/build-module/hooks/color.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/layout.js +62 -16
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +44 -35
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/utils.js +5 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/flex.js +41 -33
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +35 -38
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/layouts/utils.js +33 -3
- package/build-module/layouts/utils.js.map +1 -1
- package/build-module/store/actions.js +9 -10
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +0 -4
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +5 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +4 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/block-variation-transforms.js +14 -7
- package/build-module/utils/block-variation-transforms.js.map +1 -1
- package/build-module/utils/pasting.js +9 -1
- package/build-module/utils/pasting.js.map +1 -1
- package/build-style/style-rtl.css +72 -14
- package/build-style/style.css +72 -14
- package/package.json +28 -28
- package/src/components/block-list/block-invalid-warning.native.js +42 -7
- package/src/components/block-list/block.js +15 -4
- package/src/components/block-list/block.native.js +1 -0
- package/src/components/block-list/index.native.js +2 -2
- package/src/components/block-list/layout.js +15 -3
- package/src/components/block-list/style.scss +1 -1
- package/src/components/block-list/use-block-props/use-block-class-names.js +5 -1
- package/src/components/block-lock/modal.js +47 -9
- package/src/components/block-lock/style.scss +10 -0
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -3
- package/src/components/block-mover/mover-description.js +131 -48
- package/src/components/block-mover/test/mover-description.js +55 -3
- package/src/components/block-pattern-setup/index.js +3 -15
- package/src/components/block-pattern-setup/style.scss +4 -2
- package/src/components/block-popover/inbetween.js +2 -1
- package/src/components/block-popover/index.js +1 -1
- package/src/components/block-popover/style.scss +25 -2
- package/src/components/block-settings-menu/block-mode-toggle.js +1 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/block-settings-menu-controls/index.js +2 -2
- package/src/components/block-styles/index.js +4 -7
- package/src/components/block-styles/preview.native.js +1 -0
- package/src/components/block-styles/style.scss +10 -0
- package/src/components/block-switcher/index.js +7 -1
- package/src/components/block-title/index.js +3 -2
- package/src/components/block-title/use-block-display-title.js +11 -5
- package/src/components/block-tools/block-contextual-toolbar.js +3 -1
- package/src/components/block-tools/block-selection-button.js +0 -5
- package/src/components/block-tools/index.js +4 -1
- package/src/components/block-types-list/index.js +1 -1
- package/src/components/block-types-list/index.native.js +76 -24
- package/src/components/block-types-list/style.native.scss +18 -0
- package/src/components/border-radius-control/index.js +6 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +91 -79
- package/src/components/colors/test/__snapshots__/with-colors.js.snap +1 -1
- package/src/components/colors/test/with-colors.js +1 -1
- package/src/components/colors/utils.js +5 -2
- package/src/components/colors/with-colors.js +2 -2
- package/src/components/colors-gradients/control.js +82 -65
- package/src/components/colors-gradients/dropdown.js +14 -3
- package/src/components/colors-gradients/style.scss +34 -9
- package/src/components/colors-gradients/test/control.js +16 -23
- package/src/components/date-format-picker/index.js +1 -0
- package/src/components/font-appearance-control/index.js +3 -0
- package/src/components/iframe/index.js +25 -6
- package/src/components/image-editor/cropper.js +9 -3
- package/src/components/image-editor/index.js +2 -0
- package/src/components/image-size-control/README.md +7 -0
- package/src/components/image-size-control/index.js +2 -0
- package/src/components/index.js +4 -1
- package/src/components/index.native.js +4 -1
- package/src/components/inserter/block-types-tab.native.js +42 -21
- package/src/components/inserter/index.native.js +7 -2
- package/src/components/inserter/preview-panel.js +6 -14
- package/src/components/inserter/reusable-blocks-tab.native.js +4 -2
- package/src/components/inserter/search-results.native.js +4 -2
- package/src/components/inserter/style.scss +1 -1
- package/src/components/inserter/test/block-types-tab.native.js +2 -0
- package/src/components/inserter/test/utils.native.js +37 -0
- package/src/components/inserter/utils.native.js +11 -0
- package/src/components/inserter-list-item/index.js +5 -18
- package/src/components/letter-spacing-control/index.js +2 -0
- package/src/components/line-height-control/index.js +2 -0
- package/src/components/link-control/index.js +1 -0
- package/src/components/link-control/is-url-like.js +1 -6
- package/src/components/link-control/test/index.js +6 -4
- package/src/components/link-control/use-search-handler.js +1 -6
- package/src/components/list-view/block-select-button.js +29 -14
- package/src/components/list-view/branch.js +1 -6
- package/src/components/list-view/drop-indicator.js +1 -1
- package/src/components/list-view/expander.js +4 -2
- package/src/components/list-view/style.scss +18 -4
- package/src/components/media-placeholder/index.js +19 -0
- package/src/components/media-replace-flow/index.js +3 -6
- package/src/components/media-replace-flow/test/index.js +14 -4
- package/src/components/media-upload/index.native.js +7 -3
- package/src/components/observe-typing/index.js +17 -14
- package/src/components/preview-options/index.js +2 -2
- package/src/components/{use-no-recursive-renders → recursion-provider}/index.js +39 -28
- package/src/components/{use-no-recursive-renders/test/use-no-recursive-renders.js → recursion-provider/test/index.js} +5 -6
- package/src/components/rich-text/README.md +13 -1
- package/src/components/rich-text/format-toolbar-container.js +63 -14
- package/src/components/rich-text/index.js +3 -0
- package/src/components/rich-text/index.native.js +2 -0
- package/src/components/rich-text/use-before-input-rules.js +91 -0
- package/src/components/rich-text/use-format-types.js +38 -17
- package/src/components/text-decoration-control/index.js +4 -2
- package/src/components/text-transform-control/index.js +4 -2
- package/src/components/url-popover/image-url-input-ui.js +3 -0
- package/src/components/url-popover/index.js +1 -0
- package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -0
- package/src/components/writing-flow/use-arrow-nav.js +36 -34
- package/src/components/writing-flow/use-drag-selection.js +7 -1
- package/src/components/writing-flow/use-multi-selection.js +1 -48
- package/src/components/writing-flow/use-select-all.js +2 -1
- package/src/components/writing-flow/use-selection-observer.js +2 -3
- package/src/components/writing-flow/use-tab-nav.js +1 -1
- package/src/hooks/color.js +10 -3
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +66 -23
- package/src/hooks/style.js +46 -39
- package/src/hooks/utils.js +7 -3
- package/src/index.js +1 -0
- package/src/layouts/flex.js +47 -41
- package/src/layouts/flow.js +35 -34
- package/src/layouts/test/flex.js +21 -0
- package/src/layouts/test/flow.js +21 -0
- package/src/layouts/test/utils.js +138 -0
- package/src/layouts/utils.js +44 -3
- package/src/store/actions.js +10 -11
- package/src/store/index.js +0 -4
- package/src/store/reducer.js +3 -2
- package/src/store/selectors.js +3 -4
- package/src/utils/block-variation-transforms.js +13 -6
- package/src/utils/pasting.js +10 -1
- package/src/utils/test/block-variation-transforms.js +24 -0
- package/src/utils/test/pasting.js +10 -0
- package/tsconfig.json +2 -1
- package/build/components/use-no-recursive-renders/index.js.map +0 -1
- package/build-module/components/use-no-recursive-renders/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-selection-button.js"],"names":["classnames","dragHandle","Button","Flex","FlexItem","useSelect","useDispatch","useEffect","useRef","BACKSPACE","DELETE","UP","DOWN","LEFT","RIGHT","TAB","ESCAPE","ENTER","SPACE","getBlockType","__experimentalGetAccessibleBlockLabel","getAccessibleBlockLabel","speak","focus","__","BlockTitle","BlockIcon","store","blockEditorStore","BlockDraggable","useBlockDisplayInformation","__unstableUseBlockElement","useBlockElement","BlockSelectionButton","clientId","rootClientId","blockInformation","selected","select","getBlock","getBlockIndex","hasBlockMovingClientId","getBlockListSettings","index","name","attributes","blockMovingMode","orientation","setNavigationMode","removeBlock","ref","blockType","label","current","blockElement","getBlockRootClientId","getClientIdsOfDescendants","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","isNavigationMode","selectBlock","clearSelectedBlock","setBlockMovingClientId","moveBlockToPosition","onKeyDown","event","keyCode","isUp","isDown","isLeft","isRight","isTab","isEscape","isEnter","isSpace","isShift","shiftKey","preventDefault","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","navigateUp","navigateDown","navigateOut","navigateIn","focusedBlockUid","startingBlockClientId","defaultPrevented","sourceRoot","destRoot","sourceBlockIndex","destinationBlockIndex","nextTabbable","tabbable","findNext","contains","ownerDocument","defaultView","frameElement","findPrevious","classNames","dragHandleLabel","icon","draggableProps"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,kBAA3B;AACA,SAASC,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,QAAuC,uBAAvC;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SACCC,SADD,EAECC,MAFD,EAGCC,EAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,GAPD,EAQCC,MARD,EASCC,KATD,EAUCC,KAVD,QAWO,qBAXP;AAYA,SACCC,YADD,EAECC,qCAAqC,IAAIC,uBAF1C,QAGO,mBAHP;AAIA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,KAAT,QAAsB,gBAAtB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AAC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ACA;AAND;AAOC,IAAA,QAAQ,EAAC;AAPV,KAQME,cARN,EAFF,CADD,CAPD,EAuBC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,GAAG,EAAGxD,GADP;AAEC,IAAA,OAAO,EAAG,MAAMF,iBAAiB,CAAE,KAAF,CAFlC;AAGC,IAAA,SAAS,EAAGkB,SAHb;AAIC,IAAA,KAAK,EAAGd,KAJT;AAKC,IAAA,WAAW,EAAG,KALf;AAMC,IAAA,SAAS,EAAC;AANX,KAQC,cAAC,UAAD;AACC,IAAA,QAAQ,EAAGlB,QADZ;AAEC,IAAA,aAAa,EAAG;AAFjB,IARD,CADD,CAvBD,CADD,CADD;AA2CA;;AAED,eAAeD,oBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { dragHandle } from '@wordpress/icons';\nimport { Button, Flex, FlexItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport {\n\tBACKSPACE,\n\tDELETE,\n\tUP,\n\tDOWN,\n\tLEFT,\n\tRIGHT,\n\tTAB,\n\tESCAPE,\n\tENTER,\n\tSPACE,\n} from '@wordpress/keycodes';\nimport {\n\tgetBlockType,\n\t__experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,\n} from '@wordpress/blocks';\nimport { speak } from '@wordpress/a11y';\nimport { focus } from '@wordpress/dom';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockTitle from '../block-title';\nimport BlockIcon from '../block-icon';\nimport { store as blockEditorStore } from '../../store';\nimport BlockDraggable from '../block-draggable';\nimport useBlockDisplayInformation from '../use-block-display-information';\nimport { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';\n\n/**\n * Block selection button component, displaying the label of the block. If the block\n * descends from a root block, a button is displayed enabling the user to select\n * the root block.\n *\n * @param {string} props Component props.\n * @param {string} props.clientId Client ID of block.\n *\n * @return {WPComponent} The component to be rendered.\n */\nfunction BlockSelectionButton( { clientId, rootClientId } ) {\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\tconst selected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockIndex,\n\t\t\t\thasBlockMovingClientId,\n\t\t\t\tgetBlockListSettings,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst index = getBlockIndex( clientId );\n\t\t\tconst { name, attributes } = getBlock( clientId );\n\t\t\tconst blockMovingMode = hasBlockMovingClientId();\n\t\t\treturn {\n\t\t\t\tindex,\n\t\t\t\tname,\n\t\t\t\tattributes,\n\t\t\t\tblockMovingMode,\n\t\t\t\torientation: getBlockListSettings( rootClientId )?.orientation,\n\t\t\t};\n\t\t},\n\t\t[ clientId, rootClientId ]\n\t);\n\tconst { index, name, attributes, blockMovingMode, orientation } = selected;\n\tconst { setNavigationMode, removeBlock } = useDispatch( blockEditorStore );\n\tconst ref = useRef();\n\n\tconst blockType = getBlockType( name );\n\tconst label = getAccessibleBlockLabel(\n\t\tblockType,\n\t\tattributes,\n\t\tindex + 1,\n\t\torientation\n\t);\n\n\t// Focus the breadcrumb in navigation mode.\n\tuseEffect( () => {\n\t\tref.current.focus();\n\n\t\tspeak( label );\n\t}, [ label ] );\n\tconst blockElement = useBlockElement( clientId );\n\n\tconst {\n\t\thasBlockMovingClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockRootClientId,\n\t\tgetClientIdsOfDescendants,\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tisNavigationMode,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tselectBlock,\n\t\tclearSelectedBlock,\n\t\tsetBlockMovingClientId,\n\t\tmoveBlockToPosition,\n\t} = useDispatch( blockEditorStore );\n\n\tfunction onKeyDown( event ) {\n\t\tconst { keyCode } = event;\n\t\tconst isUp = keyCode === UP;\n\t\tconst isDown = keyCode === DOWN;\n\t\tconst isLeft = keyCode === LEFT;\n\t\tconst isRight = keyCode === RIGHT;\n\t\tconst isTab = keyCode === TAB;\n\t\tconst isEscape = keyCode === ESCAPE;\n\t\tconst isEnter = keyCode === ENTER;\n\t\tconst isSpace = keyCode === SPACE;\n\t\tconst isShift = event.shiftKey;\n\n\t\tif ( keyCode === BACKSPACE || keyCode === DELETE ) {\n\t\t\tremoveBlock( clientId );\n\t\t\tevent.preventDefault();\n\t\t\treturn;\n\t\t}\n\n\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\n\t\tconst navigateUp = ( isTab && isShift ) || isUp;\n\t\tconst navigateDown = ( isTab && ! isShift ) || isDown;\n\t\t// Move out of current nesting level (no effect if at root level).\n\t\tconst navigateOut = isLeft;\n\t\t// Move into next nesting level (no effect if the current block has no innerBlocks).\n\t\tconst navigateIn = isRight;\n\n\t\tlet focusedBlockUid;\n\t\tif ( navigateUp ) {\n\t\t\tfocusedBlockUid = selectionBeforeEndClientId;\n\t\t} else if ( navigateDown ) {\n\t\t\tfocusedBlockUid = selectionAfterEndClientId;\n\t\t} else if ( navigateOut ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetBlockRootClientId( selectedBlockClientId ) ??\n\t\t\t\tselectedBlockClientId;\n\t\t} else if ( navigateIn ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetClientIdsOfDescendants( [ selectedBlockClientId ] )[ 0 ] ??\n\t\t\t\tselectedBlockClientId;\n\t\t}\n\t\tconst startingBlockClientId = hasBlockMovingClientId();\n\t\tif ( isEscape && isNavigationMode() ) {\n\t\t\tclearSelectedBlock();\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tif ( isEscape && startingBlockClientId && ! event.defaultPrevented ) {\n\t\t\tsetBlockMovingClientId( null );\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tif ( ( isEnter || isSpace ) && startingBlockClientId ) {\n\t\t\tconst sourceRoot = getBlockRootClientId( startingBlockClientId );\n\t\t\tconst destRoot = getBlockRootClientId( selectedBlockClientId );\n\t\t\tconst sourceBlockIndex = getBlockIndex( startingBlockClientId );\n\t\t\tlet destinationBlockIndex = getBlockIndex( selectedBlockClientId );\n\t\t\tif (\n\t\t\t\tsourceBlockIndex < destinationBlockIndex &&\n\t\t\t\tsourceRoot === destRoot\n\t\t\t) {\n\t\t\t\tdestinationBlockIndex -= 1;\n\t\t\t}\n\t\t\tmoveBlockToPosition(\n\t\t\t\tstartingBlockClientId,\n\t\t\t\tsourceRoot,\n\t\t\t\tdestRoot,\n\t\t\t\tdestinationBlockIndex\n\t\t\t);\n\t\t\tselectBlock( startingBlockClientId );\n\t\t\tsetBlockMovingClientId( null );\n\t\t}\n\t\tif ( navigateDown || navigateUp || navigateOut || navigateIn ) {\n\t\t\tif ( focusedBlockUid ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectBlock( focusedBlockUid );\n\t\t\t} else if ( isTab && selectedBlockClientId ) {\n\t\t\t\tlet nextTabbable;\n\n\t\t\t\tif ( navigateDown ) {\n\t\t\t\t\tnextTabbable = blockElement;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tnextTabbable = focus.tabbable.findNext( nextTabbable );\n\t\t\t\t\t} while (\n\t\t\t\t\t\tnextTabbable &&\n\t\t\t\t\t\tblockElement.contains( nextTabbable )\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( ! nextTabbable ) {\n\t\t\t\t\t\tnextTabbable =\n\t\t\t\t\t\t\tblockElement.ownerDocument.defaultView.frameElement;\n\t\t\t\t\t\tnextTabbable = focus.tabbable.findNext( nextTabbable );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnextTabbable = focus.tabbable.findPrevious( blockElement );\n\t\t\t\t}\n\n\t\t\t\tif ( nextTabbable ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tnextTabbable.focus();\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst classNames = classnames(\n\t\t'block-editor-block-list__block-selection-button',\n\t\t{\n\t\t\t'is-block-moving-mode': !! blockMovingMode,\n\t\t}\n\t);\n\n\tconst dragHandleLabel = __( 'Drag' );\n\n\treturn (\n\t\t<div className={ classNames }>\n\t\t\t<Flex\n\t\t\t\tjustify=\"center\"\n\t\t\t\tclassName=\"block-editor-block-list__block-selection-button__content\"\n\t\t\t>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockIcon icon={ blockInformation?.icon } showColors />\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockDraggable clientIds={ [ clientId ] }>\n\t\t\t\t\t\t{ ( draggableProps ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ dragHandle }\n\t\t\t\t\t\t\t\tclassName=\"block-selection-button_drag-handle\"\n\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\tlabel={ dragHandleLabel }\n\t\t\t\t\t\t\t\t// Should not be able to tab to drag handle as this\n\t\t\t\t\t\t\t\t// button can only be used with a pointer device.\n\t\t\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\t\t\t{ ...draggableProps }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</BlockDraggable>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tonClick={ () => setNavigationMode( false ) }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t\t\tclassName=\"block-selection-button_select-button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockTitle\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tmaximumLength={ 35 }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\t\t</div>\n\t);\n}\n\nexport default BlockSelectionButton;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-selection-button.js"],"names":["classnames","dragHandle","Button","Flex","FlexItem","useSelect","useDispatch","useEffect","useRef","BACKSPACE","DELETE","UP","DOWN","LEFT","RIGHT","TAB","ESCAPE","ENTER","SPACE","getBlockType","__experimentalGetAccessibleBlockLabel","getAccessibleBlockLabel","speak","focus","__","BlockTitle","BlockIcon","store","blockEditorStore","BlockDraggable","useBlockDisplayInformation","__unstableUseBlockElement","useBlockElement","BlockSelectionButton","clientId","rootClientId","blockInformation","selected","select","getBlock","getBlockIndex","hasBlockMovingClientId","getBlockListSettings","index","name","attributes","blockMovingMode","orientation","setNavigationMode","removeBlock","ref","blockType","label","current","blockElement","getBlockRootClientId","getClientIdsOfDescendants","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","selectBlock","clearSelectedBlock","setBlockMovingClientId","moveBlockToPosition","onKeyDown","event","keyCode","isUp","isDown","isLeft","isRight","isTab","isEscape","isEnter","isSpace","isShift","shiftKey","preventDefault","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","navigateUp","navigateDown","navigateOut","navigateIn","focusedBlockUid","startingBlockClientId","defaultPrevented","sourceRoot","destRoot","sourceBlockIndex","destinationBlockIndex","nextTabbable","tabbable","findNext","contains","ownerDocument","defaultView","frameElement","findPrevious","classNames","dragHandleLabel","icon","draggableProps"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,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,EAAC;AAFX,KAIC,cAAC,QAAD,QACC,cAAC,SAAD;AAAW,IAAA,IAAI,EAAGlE,gBAAH,aAAGA,gBAAH,uBAAGA,gBAAgB,CAAEoE,IAApC;AAA2C,IAAA,UAAU;AAArD,IADD,CAJD,EAOC,cAAC,QAAD,QACC,cAAC,cAAD;AAAgB,IAAA,SAAS,EAAG,CAAEtE,QAAF;AAA5B,KACKuE,cAAF,IACD,cAAC,MAAD;AACC,IAAA,IAAI,EAAGxG,UADR;AAEC,IAAA,SAAS,EAAC,oCAFX;AAGC,mBAAY,MAHb;AAIC,IAAA,KAAK,EAAGsG,eAJT,CAKC;AACA;AAND;AAOC,IAAA,QAAQ,EAAC;AAPV,KAQME,cARN,EAFF,CADD,CAPD,EAuBC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,GAAG,EAAGvD,GADP;AAEC,IAAA,OAAO,EAAG,MAAMF,iBAAiB,CAAE,KAAF,CAFlC;AAGC,IAAA,SAAS,EAAGiB,SAHb;AAIC,IAAA,KAAK,EAAGb,KAJT;AAKC,IAAA,WAAW,EAAG,KALf;AAMC,IAAA,SAAS,EAAC;AANX,KAQC,cAAC,UAAD;AACC,IAAA,QAAQ,EAAGlB,QADZ;AAEC,IAAA,aAAa,EAAG;AAFjB,IARD,CADD,CAvBD,CADD,CADD;AA2CA;;AAED,eAAeD,oBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { dragHandle } from '@wordpress/icons';\nimport { Button, Flex, FlexItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport {\n\tBACKSPACE,\n\tDELETE,\n\tUP,\n\tDOWN,\n\tLEFT,\n\tRIGHT,\n\tTAB,\n\tESCAPE,\n\tENTER,\n\tSPACE,\n} from '@wordpress/keycodes';\nimport {\n\tgetBlockType,\n\t__experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,\n} from '@wordpress/blocks';\nimport { speak } from '@wordpress/a11y';\nimport { focus } from '@wordpress/dom';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockTitle from '../block-title';\nimport BlockIcon from '../block-icon';\nimport { store as blockEditorStore } from '../../store';\nimport BlockDraggable from '../block-draggable';\nimport useBlockDisplayInformation from '../use-block-display-information';\nimport { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';\n\n/**\n * Block selection button component, displaying the label of the block. If the block\n * descends from a root block, a button is displayed enabling the user to select\n * the root block.\n *\n * @param {string} props Component props.\n * @param {string} props.clientId Client ID of block.\n *\n * @return {WPComponent} The component to be rendered.\n */\nfunction BlockSelectionButton( { clientId, rootClientId } ) {\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\tconst selected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockIndex,\n\t\t\t\thasBlockMovingClientId,\n\t\t\t\tgetBlockListSettings,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst index = getBlockIndex( clientId );\n\t\t\tconst { name, attributes } = getBlock( clientId );\n\t\t\tconst blockMovingMode = hasBlockMovingClientId();\n\t\t\treturn {\n\t\t\t\tindex,\n\t\t\t\tname,\n\t\t\t\tattributes,\n\t\t\t\tblockMovingMode,\n\t\t\t\torientation: getBlockListSettings( rootClientId )?.orientation,\n\t\t\t};\n\t\t},\n\t\t[ clientId, rootClientId ]\n\t);\n\tconst { index, name, attributes, blockMovingMode, orientation } = selected;\n\tconst { setNavigationMode, removeBlock } = useDispatch( blockEditorStore );\n\tconst ref = useRef();\n\n\tconst blockType = getBlockType( name );\n\tconst label = getAccessibleBlockLabel(\n\t\tblockType,\n\t\tattributes,\n\t\tindex + 1,\n\t\torientation\n\t);\n\n\t// Focus the breadcrumb in navigation mode.\n\tuseEffect( () => {\n\t\tref.current.focus();\n\n\t\tspeak( label );\n\t}, [ label ] );\n\tconst blockElement = useBlockElement( clientId );\n\n\tconst {\n\t\thasBlockMovingClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockRootClientId,\n\t\tgetClientIdsOfDescendants,\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tselectBlock,\n\t\tclearSelectedBlock,\n\t\tsetBlockMovingClientId,\n\t\tmoveBlockToPosition,\n\t} = useDispatch( blockEditorStore );\n\n\tfunction onKeyDown( event ) {\n\t\tconst { keyCode } = event;\n\t\tconst isUp = keyCode === UP;\n\t\tconst isDown = keyCode === DOWN;\n\t\tconst isLeft = keyCode === LEFT;\n\t\tconst isRight = keyCode === RIGHT;\n\t\tconst isTab = keyCode === TAB;\n\t\tconst isEscape = keyCode === ESCAPE;\n\t\tconst isEnter = keyCode === ENTER;\n\t\tconst isSpace = keyCode === SPACE;\n\t\tconst isShift = event.shiftKey;\n\n\t\tif ( keyCode === BACKSPACE || keyCode === DELETE ) {\n\t\t\tremoveBlock( clientId );\n\t\t\tevent.preventDefault();\n\t\t\treturn;\n\t\t}\n\n\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t);\n\n\t\tconst navigateUp = ( isTab && isShift ) || isUp;\n\t\tconst navigateDown = ( isTab && ! isShift ) || isDown;\n\t\t// Move out of current nesting level (no effect if at root level).\n\t\tconst navigateOut = isLeft;\n\t\t// Move into next nesting level (no effect if the current block has no innerBlocks).\n\t\tconst navigateIn = isRight;\n\n\t\tlet focusedBlockUid;\n\t\tif ( navigateUp ) {\n\t\t\tfocusedBlockUid = selectionBeforeEndClientId;\n\t\t} else if ( navigateDown ) {\n\t\t\tfocusedBlockUid = selectionAfterEndClientId;\n\t\t} else if ( navigateOut ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetBlockRootClientId( selectedBlockClientId ) ??\n\t\t\t\tselectedBlockClientId;\n\t\t} else if ( navigateIn ) {\n\t\t\tfocusedBlockUid =\n\t\t\t\tgetClientIdsOfDescendants( [ selectedBlockClientId ] )[ 0 ] ??\n\t\t\t\tselectedBlockClientId;\n\t\t}\n\t\tconst startingBlockClientId = hasBlockMovingClientId();\n\t\tif ( isEscape && startingBlockClientId && ! event.defaultPrevented ) {\n\t\t\tsetBlockMovingClientId( null );\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tif ( ( isEnter || isSpace ) && startingBlockClientId ) {\n\t\t\tconst sourceRoot = getBlockRootClientId( startingBlockClientId );\n\t\t\tconst destRoot = getBlockRootClientId( selectedBlockClientId );\n\t\t\tconst sourceBlockIndex = getBlockIndex( startingBlockClientId );\n\t\t\tlet destinationBlockIndex = getBlockIndex( selectedBlockClientId );\n\t\t\tif (\n\t\t\t\tsourceBlockIndex < destinationBlockIndex &&\n\t\t\t\tsourceRoot === destRoot\n\t\t\t) {\n\t\t\t\tdestinationBlockIndex -= 1;\n\t\t\t}\n\t\t\tmoveBlockToPosition(\n\t\t\t\tstartingBlockClientId,\n\t\t\t\tsourceRoot,\n\t\t\t\tdestRoot,\n\t\t\t\tdestinationBlockIndex\n\t\t\t);\n\t\t\tselectBlock( startingBlockClientId );\n\t\t\tsetBlockMovingClientId( null );\n\t\t}\n\t\tif ( navigateDown || navigateUp || navigateOut || navigateIn ) {\n\t\t\tif ( focusedBlockUid ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectBlock( focusedBlockUid );\n\t\t\t} else if ( isTab && selectedBlockClientId ) {\n\t\t\t\tlet nextTabbable;\n\n\t\t\t\tif ( navigateDown ) {\n\t\t\t\t\tnextTabbable = blockElement;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tnextTabbable = focus.tabbable.findNext( nextTabbable );\n\t\t\t\t\t} while (\n\t\t\t\t\t\tnextTabbable &&\n\t\t\t\t\t\tblockElement.contains( nextTabbable )\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( ! nextTabbable ) {\n\t\t\t\t\t\tnextTabbable =\n\t\t\t\t\t\t\tblockElement.ownerDocument.defaultView.frameElement;\n\t\t\t\t\t\tnextTabbable = focus.tabbable.findNext( nextTabbable );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnextTabbable = focus.tabbable.findPrevious( blockElement );\n\t\t\t\t}\n\n\t\t\t\tif ( nextTabbable ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tnextTabbable.focus();\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst classNames = classnames(\n\t\t'block-editor-block-list__block-selection-button',\n\t\t{\n\t\t\t'is-block-moving-mode': !! blockMovingMode,\n\t\t}\n\t);\n\n\tconst dragHandleLabel = __( 'Drag' );\n\n\treturn (\n\t\t<div className={ classNames }>\n\t\t\t<Flex\n\t\t\t\tjustify=\"center\"\n\t\t\t\tclassName=\"block-editor-block-list__block-selection-button__content\"\n\t\t\t>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockIcon icon={ blockInformation?.icon } showColors />\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<BlockDraggable clientIds={ [ clientId ] }>\n\t\t\t\t\t\t{ ( draggableProps ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ dragHandle }\n\t\t\t\t\t\t\t\tclassName=\"block-selection-button_drag-handle\"\n\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\tlabel={ dragHandleLabel }\n\t\t\t\t\t\t\t\t// Should not be able to tab to drag handle as this\n\t\t\t\t\t\t\t\t// button can only be used with a pointer device.\n\t\t\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\t\t\t{ ...draggableProps }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</BlockDraggable>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tonClick={ () => setNavigationMode( false ) }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t\t\tclassName=\"block-selection-button_select-button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockTitle\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tmaximumLength={ 35 }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\t\t</div>\n\t);\n}\n\nexport default BlockSelectionButton;\n"]}
|
|
@@ -56,6 +56,8 @@ export default function BlockTools(_ref) {
|
|
|
56
56
|
} = useDispatch(blockEditorStore);
|
|
57
57
|
|
|
58
58
|
function onKeyDown(event) {
|
|
59
|
+
if (event.defaultPrevented) return;
|
|
60
|
+
|
|
59
61
|
if (isMatch('core/block-editor/move-up', event)) {
|
|
60
62
|
const clientIds = getSelectedBlockClientIds();
|
|
61
63
|
|
|
@@ -103,10 +105,11 @@ export default function BlockTools(_ref) {
|
|
|
103
105
|
} else if (isMatch('core/block-editor/unselect', event)) {
|
|
104
106
|
const clientIds = getSelectedBlockClientIds();
|
|
105
107
|
|
|
106
|
-
if (clientIds.length
|
|
108
|
+
if (clientIds.length) {
|
|
107
109
|
event.preventDefault();
|
|
108
110
|
clearSelectedBlock();
|
|
109
111
|
event.target.ownerDocument.defaultView.getSelection().removeAllRanges();
|
|
112
|
+
__unstableContentRef === null || __unstableContentRef === void 0 ? void 0 : __unstableContentRef.current.focus();
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/index.js"],"names":["first","last","useSelect","useDispatch","useViewportMatch","Popover","__unstableUseShortcutEventMatch","useShortcutEventMatch","InsertionPoint","SelectedBlockPopover","store","blockEditorStore","BlockContextualToolbar","usePopoverScroll","BlockTools","children","__unstableContentRef","props","isLargeViewport","hasFixedToolbar","select","getSettings","isMatch","getSelectedBlockClientIds","getBlockRootClientId","duplicateBlocks","removeBlocks","insertAfterBlock","insertBeforeBlock","clearSelectedBlock","moveBlocksUp","moveBlocksDown","onKeyDown","event","clientIds","length","preventDefault","rootClientId","target","ownerDocument","defaultView","getSelection","removeAllRanges"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,OAAT,QAAwB,uBAAxB;AACA,SAASC,+BAA+B,IAAIC,qBAA5C,QAAyE,+BAAzE;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,OAAOC,sBAAP,MAAmC,4BAAnC;AACA,OAAOC,gBAAP,MAA6B,qCAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,UAAT,OAIX;AAAA,MAJgC;AACnCC,IAAAA,QADmC;AAEnCC,IAAAA,oBAFmC;AAGnC,OAAGC;AAHgC,GAIhC;AACH,QAAMC,eAAe,GAAGd,gBAAgB,CAAE,QAAF,CAAxC;AACA,QAAMe,eAAe,GAAGjB,SAAS,CAC9BkB,MAAF,IAAcA,MAAM,CAAET,gBAAF,CAAN,CAA2BU,WAA3B,GAAyCF,eADvB,EAEhC,EAFgC,CAAjC;AAIA,QAAMG,OAAO,GAAGf,qBAAqB,EAArC;AACA,QAAM;AAAEgB,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACLtB,SAAS,CAAES,gBAAF,CADV;AAEA,QAAM;AACLc,IAAAA,eADK;AAELC,IAAAA,YAFK;AAGLC,IAAAA,gBAHK;AAILC,IAAAA,iBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,YANK;AAOLC,IAAAA;AAPK,MAQF5B,WAAW,CAAEQ,gBAAF,CARf;;AAUA,WAASqB,SAAT,CAAoBC,KAApB,EAA4B;AAC3B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/index.js"],"names":["first","last","useSelect","useDispatch","useViewportMatch","Popover","__unstableUseShortcutEventMatch","useShortcutEventMatch","InsertionPoint","SelectedBlockPopover","store","blockEditorStore","BlockContextualToolbar","usePopoverScroll","BlockTools","children","__unstableContentRef","props","isLargeViewport","hasFixedToolbar","select","getSettings","isMatch","getSelectedBlockClientIds","getBlockRootClientId","duplicateBlocks","removeBlocks","insertAfterBlock","insertBeforeBlock","clearSelectedBlock","moveBlocksUp","moveBlocksDown","onKeyDown","event","defaultPrevented","clientIds","length","preventDefault","rootClientId","target","ownerDocument","defaultView","getSelection","removeAllRanges","current","focus"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,OAAT,QAAwB,uBAAxB;AACA,SAASC,+BAA+B,IAAIC,qBAA5C,QAAyE,+BAAzE;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,OAAOC,sBAAP,MAAmC,4BAAnC;AACA,OAAOC,gBAA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yBAAyB,EAA3C;;AACA,UAAKY,SAAS,CAACC,MAAf,EAAwB;AACvBH,QAAAA,KAAK,CAACI,cAAN;AACAR,QAAAA,kBAAkB;AAClBI,QAAAA,KAAK,CAACM,MAAN,CAAaC,aAAb,CAA2BC,WAA3B,CACEC,YADF,GAEEC,eAFF;AAGA3B,QAAAA,oBAAoB,SAApB,IAAAA,oBAAoB,WAApB,YAAAA,oBAAoB,CAAE4B,OAAtB,CAA8BC,KAA9B;AACA;AACD;AACD;;AAED,SACC;AACA,sCAAU5B,KAAV;AAAkB,MAAA,SAAS,EAAGe;AAA9B,QACC,cAAC,cAAD;AAAgB,MAAA,oBAAoB,EAAGhB;AAAvC,OACG,CAAEG,eAAe,IAAI,CAAED,eAAvB,KACD,cAAC,sBAAD;AAAwB,MAAA,OAAO;AAA/B,MAFF,EAMC,cAAC,oBAAD;AACC,MAAA,oBAAoB,EAAGF;AADxB,MAND,EAUC,cAAC,OAAD,CAAS,IAAT;AACC,MAAA,IAAI,EAAC,eADN;AAEC,MAAA,GAAG,EAAGH,gBAAgB,CAAEG,oBAAF;AAFvB,MAVD,EAcGD,QAdH,EAgBC,cAAC,OAAD,CAAS,IAAT;AACC,MAAA,IAAI,EAAC,8BADN;AAEC,MAAA,GAAG,EAAGF,gBAAgB,CAAEG,oBAAF;AAFvB,MAhBD,CADD;AAFD;AA0BA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Popover } from '@wordpress/components';\nimport { __unstableUseShortcutEventMatch as useShortcutEventMatch } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\nimport InsertionPoint from './insertion-point';\nimport SelectedBlockPopover from './selected-block-popover';\nimport { store as blockEditorStore } from '../../store';\nimport BlockContextualToolbar from './block-contextual-toolbar';\nimport usePopoverScroll from '../block-popover/use-popover-scroll';\n\n/**\n * Renders block tools (the block toolbar, select/navigation mode toolbar, the\n * insertion point and a slot for the inline rich text toolbar). Must be wrapped\n * around the block content and editor styles wrapper or iframe.\n *\n * @param {Object} $0 Props.\n * @param {Object} $0.children The block content and style container.\n * @param {Object} $0.__unstableContentRef Ref holding the content scroll container.\n */\nexport default function BlockTools( {\n\tchildren,\n\t__unstableContentRef,\n\t...props\n} ) {\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst hasFixedToolbar = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().hasFixedToolbar,\n\t\t[]\n\t);\n\tconst isMatch = useShortcutEventMatch();\n\tconst { getSelectedBlockClientIds, getBlockRootClientId } =\n\t\tuseSelect( blockEditorStore );\n\tconst {\n\t\tduplicateBlocks,\n\t\tremoveBlocks,\n\t\tinsertAfterBlock,\n\t\tinsertBeforeBlock,\n\t\tclearSelectedBlock,\n\t\tmoveBlocksUp,\n\t\tmoveBlocksDown,\n\t} = useDispatch( blockEditorStore );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( event.defaultPrevented ) return;\n\n\t\tif ( isMatch( 'core/block-editor/move-up', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst rootClientId = getBlockRootClientId( first( clientIds ) );\n\t\t\t\tmoveBlocksUp( clientIds, rootClientId );\n\t\t\t}\n\t\t} else if ( isMatch( 'core/block-editor/move-down', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst rootClientId = getBlockRootClientId( first( clientIds ) );\n\t\t\t\tmoveBlocksDown( clientIds, rootClientId );\n\t\t\t}\n\t\t} else if ( isMatch( 'core/block-editor/duplicate', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tduplicateBlocks( clientIds );\n\t\t\t}\n\t\t} else if ( isMatch( 'core/block-editor/remove', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tremoveBlocks( clientIds );\n\t\t\t}\n\t\t} else if ( isMatch( 'core/block-editor/insert-after', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tinsertAfterBlock( last( clientIds ) );\n\t\t\t}\n\t\t} else if ( isMatch( 'core/block-editor/insert-before', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tinsertBeforeBlock( first( clientIds ) );\n\t\t\t}\n\t\t} else if ( isMatch( 'core/block-editor/unselect', event ) ) {\n\t\t\tconst clientIds = getSelectedBlockClientIds();\n\t\t\tif ( clientIds.length ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tclearSelectedBlock();\n\t\t\t\tevent.target.ownerDocument.defaultView\n\t\t\t\t\t.getSelection()\n\t\t\t\t\t.removeAllRanges();\n\t\t\t\t__unstableContentRef?.current.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\treturn (\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div { ...props } onKeyDown={ onKeyDown }>\n\t\t\t<InsertionPoint __unstableContentRef={ __unstableContentRef }>\n\t\t\t\t{ ( hasFixedToolbar || ! isLargeViewport ) && (\n\t\t\t\t\t<BlockContextualToolbar isFixed />\n\t\t\t\t) }\n\t\t\t\t{ /* Even if the toolbar is fixed, the block popover is still\n\t\t\t\t\tneeded for navigation and exploded mode. */ }\n\t\t\t\t<SelectedBlockPopover\n\t\t\t\t\t__unstableContentRef={ __unstableContentRef }\n\t\t\t\t/>\n\t\t\t\t{ /* Used for the inline rich text toolbar. */ }\n\t\t\t\t<Popover.Slot\n\t\t\t\t\tname=\"block-toolbar\"\n\t\t\t\t\tref={ usePopoverScroll( __unstableContentRef ) }\n\t\t\t\t/>\n\t\t\t\t{ children }\n\t\t\t\t{ /* Used for inline rich text popovers. */ }\n\t\t\t\t<Popover.Slot\n\t\t\t\t\tname=\"__unstable-block-tools-after\"\n\t\t\t\t\tref={ usePopoverScroll( __unstableContentRef ) }\n\t\t\t\t/>\n\t\t\t</InsertionPoint>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -41,7 +41,7 @@ function BlockTypesList(_ref) {
|
|
|
41
41
|
className: getBlockMenuDefaultClassName(item.id),
|
|
42
42
|
onSelect: onSelect,
|
|
43
43
|
onHover: onHover,
|
|
44
|
-
isDraggable: isDraggable,
|
|
44
|
+
isDraggable: isDraggable && !item.isDisabled,
|
|
45
45
|
isFirst: i === 0 && j === 0
|
|
46
46
|
})))), children);
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-types-list/index.js"],"names":["getBlockMenuDefaultClassName","InserterListItem","InserterListboxGroup","InserterListboxRow","chunk","array","size","chunks","i","j","length","push","slice","BlockTypesList","items","onSelect","onHover","children","label","isDraggable","map","row","item","id"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,4BAAT,QAA6C,mBAA7C;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AACA,SAASC,oBAAT,EAA+BC,kBAA/B,QAAyD,qBAAzD;;AAEA,SAASC,KAAT,CAAgBC,KAAhB,EAAuBC,IAAvB,EAA8B;AAC7B,QAAMC,MAAM,GAAG,EAAf;;AACA,OAAM,IAAIC,CAAC,GAAG,CAAR,EAAWC,CAAC,GAAGJ,KAAK,CAACK,MAA3B,EAAmCF,CAAC,GAAGC,CAAvC,EAA0CD,CAAC,IAAIF,IAA/C,EAAsD;AACrDC,IAAAA,MAAM,CAACI,IAAP,CAAaN,KAAK,CAACO,KAAN,CAAaJ,CAAb,EAAgBA,CAAC,GAAGF,IAApB,CAAb;AACA;;AACD,SAAOC,MAAP;AACA;;AAED,SAASM,cAAT,OAOI;AAAA,MAPqB;AACxBC,IAAAA,KAAK,GAAG,EADgB;AAExBC,IAAAA,QAFwB;AAGxBC,IAAAA,OAAO,GAAG,MAAM,CAAE,CAHM;AAIxBC,IAAAA,QAJwB;AAKxBC,IAAAA,KALwB;AAMxBC,IAAAA,WAAW,GAAG;AANU,GAOrB;AACH,SACC,cAAC,oBAAD;AACC,IAAA,SAAS,EAAC,+BADX;AAEC,kBAAaD;AAFd,KAIGd,KAAK,CAAEU,KAAF,EAAS,CAAT,CAAL,CAAkBM,GAAlB,CAAuB,CAAEC,GAAF,EAAOb,CAAP,KACxB,cAAC,kBAAD;AAAoB,IAAA,GAAG,EAAGA;AAA1B,KACGa,GAAG,CAACD,GAAJ,CAAS,CAAEE,IAAF,EAAQb,CAAR,KACV,cAAC,gBAAD;AACC,IAAA,GAAG,EAAGa,IAAI,CAACC,EADZ;AAEC,IAAA,IAAI,EAAGD,IAFR;AAGC,IAAA,SAAS,EAAGtB,4BAA4B,CACvCsB,IAAI,CAACC,EADkC,CAHzC;AAMC,IAAA,QAAQ,EAAGR,QANZ;AAOC,IAAA,OAAO,EAAGC,OAPX;AAQC,IAAA,WAAW,EAAGG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-types-list/index.js"],"names":["getBlockMenuDefaultClassName","InserterListItem","InserterListboxGroup","InserterListboxRow","chunk","array","size","chunks","i","j","length","push","slice","BlockTypesList","items","onSelect","onHover","children","label","isDraggable","map","row","item","id","isDisabled"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,4BAAT,QAA6C,mBAA7C;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AACA,SAASC,oBAAT,EAA+BC,kBAA/B,QAAyD,qBAAzD;;AAEA,SAASC,KAAT,CAAgBC,KAAhB,EAAuBC,IAAvB,EAA8B;AAC7B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Content":["/**\n * WordPress dependencies\n */\nimport { getBlockMenuDefaultClassName } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport InserterListItem from '../inserter-list-item';\nimport { InserterListboxGroup, InserterListboxRow } from '../inserter-listbox';\n\nfunction chunk( array, size ) {\n\tconst chunks = [];\n\tfor ( let i = 0, j = array.length; i < j; i += size ) {\n\t\tchunks.push( array.slice( i, i + size ) );\n\t}\n\treturn chunks;\n}\n\nfunction BlockTypesList( {\n\titems = [],\n\tonSelect,\n\tonHover = () => {},\n\tchildren,\n\tlabel,\n\tisDraggable = true,\n} ) {\n\treturn (\n\t\t<InserterListboxGroup\n\t\t\tclassName=\"block-editor-block-types-list\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ chunk( items, 3 ).map( ( row, i ) => (\n\t\t\t\t<InserterListboxRow key={ i }>\n\t\t\t\t\t{ row.map( ( item, j ) => (\n\t\t\t\t\t\t<InserterListItem\n\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tclassName={ getBlockMenuDefaultClassName(\n\t\t\t\t\t\t\t\titem.id\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\tisDraggable={ isDraggable && ! item.isDisabled }\n\t\t\t\t\t\t\tisFirst={ i === 0 && j === 0 }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</InserterListboxRow>\n\t\t\t) ) }\n\t\t\t{ children }\n\t\t</InserterListboxGroup>\n\t);\n}\n\nexport default BlockTypesList;\n"]}
|
|
@@ -4,13 +4,14 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
/**
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
|
-
import { Dimensions, FlatList, StyleSheet, TouchableWithoutFeedback, View } from 'react-native';
|
|
7
|
+
import { Dimensions, FlatList, SectionList, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native';
|
|
8
8
|
/**
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { useState, useEffect } from '@wordpress/element';
|
|
13
|
-
import { BottomSheet, InserterButton } from '@wordpress/components';
|
|
13
|
+
import { BottomSheet, Gradient, InserterButton } from '@wordpress/components';
|
|
14
|
+
import { usePreferredColorScheme, usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
14
15
|
/**
|
|
15
16
|
* Internal dependencies
|
|
16
17
|
*/
|
|
@@ -20,7 +21,7 @@ const MIN_COL_NUM = 3;
|
|
|
20
21
|
export default function BlockTypesList(_ref) {
|
|
21
22
|
let {
|
|
22
23
|
name,
|
|
23
|
-
|
|
24
|
+
sections,
|
|
24
25
|
onSelect,
|
|
25
26
|
listProps,
|
|
26
27
|
initialNumToRender = 3
|
|
@@ -65,32 +66,73 @@ export default function BlockTypesList(_ref) {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
const contentContainerStyle = StyleSheet.flatten(listProps.contentContainerStyle);
|
|
68
|
-
|
|
69
|
+
|
|
70
|
+
const renderSection = _ref2 => {
|
|
71
|
+
let {
|
|
72
|
+
item
|
|
73
|
+
} = _ref2;
|
|
74
|
+
return createElement(TouchableWithoutFeedback, {
|
|
75
|
+
accessible: false
|
|
76
|
+
}, createElement(FlatList, {
|
|
77
|
+
data: item.list,
|
|
78
|
+
key: `InserterUI-${name}-${numberOfColumns}` // Re-render when numberOfColumns changes.
|
|
79
|
+
,
|
|
80
|
+
numColumns: numberOfColumns,
|
|
81
|
+
ItemSeparatorComponent: () => createElement(TouchableWithoutFeedback, {
|
|
82
|
+
accessible: false
|
|
83
|
+
}, createElement(View, {
|
|
84
|
+
style: styles['block-types-list__row-separator']
|
|
85
|
+
})),
|
|
86
|
+
scrollEnabled: false,
|
|
87
|
+
renderItem: renderListItem
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const renderListItem = _ref3 => {
|
|
92
|
+
let {
|
|
93
|
+
item
|
|
94
|
+
} = _ref3;
|
|
95
|
+
return createElement(InserterButton, {
|
|
96
|
+
item: item,
|
|
97
|
+
itemWidth: itemWidth,
|
|
98
|
+
maxWidth: maxWidth,
|
|
99
|
+
onSelect: onSelect
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const colorScheme = usePreferredColorScheme();
|
|
104
|
+
const sectionHeaderGradientValue = colorScheme === 'light' ? 'linear-gradient(#fff 70%, rgba(255, 255, 255, 0))' : 'linear-gradient(#2e2e2e 70%, rgba(46, 46, 46, 0))';
|
|
105
|
+
const sectionHeaderTitleStyles = usePreferredColorSchemeStyle(styles['block-types-list__section-header-title'], styles['block-types-list__section-header-title--dark']);
|
|
106
|
+
|
|
107
|
+
const renderSectionHeader = _ref4 => {
|
|
108
|
+
let {
|
|
109
|
+
section: {
|
|
110
|
+
metadata
|
|
111
|
+
}
|
|
112
|
+
} = _ref4;
|
|
113
|
+
|
|
114
|
+
if (!(metadata !== null && metadata !== void 0 && metadata.icon) || !(metadata !== null && metadata !== void 0 && metadata.title)) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return createElement(TouchableWithoutFeedback, {
|
|
119
|
+
accessible: false
|
|
120
|
+
}, createElement(Gradient, {
|
|
121
|
+
gradientValue: sectionHeaderGradientValue,
|
|
122
|
+
style: styles['block-types-list__section-header']
|
|
123
|
+
}, metadata === null || metadata === void 0 ? void 0 : metadata.icon, createElement(Text, {
|
|
124
|
+
style: sectionHeaderTitleStyles
|
|
125
|
+
}, metadata === null || metadata === void 0 ? void 0 : metadata.title)));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return createElement(SectionList, _extends({
|
|
69
129
|
onLayout: onLayout,
|
|
70
|
-
key: `InserterUI-${name}-${numberOfColumns}` // Re-render when numberOfColumns changes.
|
|
71
|
-
,
|
|
72
130
|
testID: `InserterUI-${name}`,
|
|
73
131
|
keyboardShouldPersistTaps: "always",
|
|
74
|
-
|
|
75
|
-
data: items,
|
|
132
|
+
sections: sections,
|
|
76
133
|
initialNumToRender: initialNumToRender,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}, createElement(View, {
|
|
80
|
-
style: styles['block-types-list__row-separator']
|
|
81
|
-
})),
|
|
82
|
-
keyExtractor: item => item.id,
|
|
83
|
-
renderItem: _ref2 => {
|
|
84
|
-
let {
|
|
85
|
-
item
|
|
86
|
-
} = _ref2;
|
|
87
|
-
return createElement(InserterButton, {
|
|
88
|
-
item,
|
|
89
|
-
itemWidth,
|
|
90
|
-
maxWidth,
|
|
91
|
-
onSelect
|
|
92
|
-
});
|
|
93
|
-
}
|
|
134
|
+
renderItem: renderSection,
|
|
135
|
+
renderSectionHeader: renderSectionHeader
|
|
94
136
|
}, listProps, {
|
|
95
137
|
contentContainerStyle: { ...contentContainerStyle,
|
|
96
138
|
paddingBottom: Math.max(listProps.safeAreaBottomInset, contentContainerStyle.paddingBottom)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-types-list/index.native.js"],"names":["Dimensions","FlatList","StyleSheet","TouchableWithoutFeedback","View","useState","useEffect","BottomSheet","InserterButton","styles","MIN_COL_NUM","BlockTypesList","name","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-types-list/index.native.js"],"names":["Dimensions","FlatList","SectionList","StyleSheet","Text","TouchableWithoutFeedback","View","useState","useEffect","BottomSheet","Gradient","InserterButton","usePreferredColorScheme","usePreferredColorSchemeStyle","styles","MIN_COL_NUM","BlockTypesList","name","sections","onSelect","listProps","initialNumToRender","numberOfColumns","setNumberOfColumns","itemWidth","setItemWidth","maxWidth","setMaxWidth","dimensionsChangeSubscription","addEventListener","onLayout","remove","calculateItemWidth","paddingLeft","itemPaddingLeft","paddingRight","itemPaddingRight","Styles","modalItem","width","modalIconWrapper","columnStyle","sumLeftRightPadding","bottomSheetWidth","getWidth","containerTotalWidth","itemTotalWidth","columnsFitToWidth","Math","floor","numColumns","max","updatedItemWidth","contentContainerStyle","flatten","renderSection","item","list","renderListItem","colorScheme","sectionHeaderGradientValue","sectionHeaderTitleStyles","renderSectionHeader","section","metadata","icon","title","paddingBottom","safeAreaBottomInset"],"mappings":";;;AAAA;AACA;AACA;AACA,SACCA,UADD,EAECC,QAFD,EAGCC,WAHD,EAICC,UAJD,EAKCC,IALD,EAMCC,wBAND,EAOCC,IAPD,QAQO,cARP;AAUA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,SAASC,WAAT,EAAsBC,QAAtB,EAAgCC,cAAhC,QAAsD,uBAAtD;AACA,SACCC,uBADD,EAECC,4BAFD,QAGO,oBAHP;AAKA;AACA;AACA;;AACA,OAAOC,MAAP,MAAmB,cAAnB;AAEA,MAAMC,WAAW,GAAG,CAApB;AAEA,eAAe,SAASC,cAAT,OAMX;AAAA,MANoC;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA,QAFuC;AAGvCC,IAAAA,QAHuC;AAIvCC,IAAAA,SAJuC;AAKvCC,IAAAA,kBAAkB,GAAG;AALkB,GAMpC;AACH,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0ChB,QAAQ,CAAEQ,WAAF,CAAxD;AACA,QAAM,CAAES,SAAF,EAAaC,YAAb,IAA8BlB,QAAQ,EAA5C;AACA,QAAM,CAAEmB,QAAF,EAAYC,WAAZ,IAA4BpB,QAAQ,EAA1C;AAEAC,EAAAA,SAAS,CAAE,MAAM;AAChB,UAAMoB,4BAA4B,GAAG5B,UAAU,CAAC6B,gBAAX,CACpC,QADoC,EAEpCC,QAFoC,CAArC;AAIAA,IAAAA,QAAQ;AACR,WAAO,MAAM;AACZF,MAAAA,4BAA4B,CAACG,MAA7B;AACA,KAFD;AAGA,GATQ,EASN,EATM,CAAT;;AAWA,WAASC,kBAAT,GAA8B;AAC7B,UAAM;AAAEC,MAAAA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EC,MAAA,KAAK,EAAG9C,MAAM,CAAE,kCAAF;AAFf,OAIGkD,QAJH,aAIGA,QAJH,uBAIGA,QAAQ,CAAEC,IAJb,EAKC,cAAC,IAAD;AAAM,MAAA,KAAK,EAAGJ;AAAd,OACGG,QADH,aACGA,QADH,uBACGA,QAAQ,CAAEE,KADb,CALD,CADD,CADD;AAaA,GAlBD;;AAoBA,SACC,cAAC,WAAD;AACC,IAAA,QAAQ,EAAGpC,QADZ;AAEC,IAAA,MAAM,EAAI,cAAcb,IAAM,EAF/B;AAGC,IAAA,yBAAyB,EAAC,QAH3B;AAIC,IAAA,QAAQ,EAAGC,QAJZ;AAKC,IAAA,kBAAkB,EAAGG,kBALtB;AAMC,IAAA,UAAU,EAAGkC,aANd;AAOC,IAAA,mBAAmB,EAAGO;AAPvB,KAQM1C,SARN;AASC,IAAA,qBAAqB,EAAG,EACvB,GAAGiC,qBADoB;AAEvBc,MAAAA,aAAa,EAAEnB,IAAI,CAACG,GAAL,CACd/B,SAAS,CAACgD,mBADI,EAEdf,qBAAqB,CAACc,aAFR;AAFQ;AATzB,KADD;AAmBA","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tDimensions,\n\tFlatList,\n\tSectionList,\n\tStyleSheet,\n\tText,\n\tTouchableWithoutFeedback,\n\tView,\n} from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport { BottomSheet, Gradient, InserterButton } from '@wordpress/components';\nimport {\n\tusePreferredColorScheme,\n\tusePreferredColorSchemeStyle,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nconst MIN_COL_NUM = 3;\n\nexport default function BlockTypesList( {\n\tname,\n\tsections,\n\tonSelect,\n\tlistProps,\n\tinitialNumToRender = 3,\n} ) {\n\tconst [ numberOfColumns, setNumberOfColumns ] = useState( MIN_COL_NUM );\n\tconst [ itemWidth, setItemWidth ] = useState();\n\tconst [ maxWidth, setMaxWidth ] = useState();\n\n\tuseEffect( () => {\n\t\tconst dimensionsChangeSubscription = Dimensions.addEventListener(\n\t\t\t'change',\n\t\t\tonLayout\n\t\t);\n\t\tonLayout();\n\t\treturn () => {\n\t\t\tdimensionsChangeSubscription.remove();\n\t\t};\n\t}, [] );\n\n\tfunction calculateItemWidth() {\n\t\tconst { paddingLeft: itemPaddingLeft, paddingRight: itemPaddingRight } =\n\t\t\tInserterButton.Styles.modalItem;\n\t\tconst { width } = InserterButton.Styles.modalIconWrapper;\n\t\treturn width + itemPaddingLeft + itemPaddingRight;\n\t}\n\n\tfunction onLayout() {\n\t\tconst columnStyle = styles[ 'block-types-list__column' ];\n\t\tconst sumLeftRightPadding =\n\t\t\tcolumnStyle.paddingLeft + columnStyle.paddingRight;\n\n\t\tconst bottomSheetWidth = BottomSheet.getWidth();\n\t\tconst containerTotalWidth = bottomSheetWidth - sumLeftRightPadding;\n\t\tconst itemTotalWidth = calculateItemWidth();\n\n\t\tconst columnsFitToWidth = Math.floor(\n\t\t\tcontainerTotalWidth / itemTotalWidth\n\t\t);\n\n\t\tconst numColumns = Math.max( MIN_COL_NUM, columnsFitToWidth );\n\n\t\tsetNumberOfColumns( numColumns );\n\t\tsetMaxWidth( containerTotalWidth / numColumns );\n\n\t\tif ( columnsFitToWidth < MIN_COL_NUM ) {\n\t\t\tconst updatedItemWidth =\n\t\t\t\t( bottomSheetWidth - 2 * sumLeftRightPadding ) / MIN_COL_NUM;\n\t\t\tsetItemWidth( updatedItemWidth );\n\t\t}\n\t}\n\n\tconst contentContainerStyle = StyleSheet.flatten(\n\t\tlistProps.contentContainerStyle\n\t);\n\n\tconst renderSection = ( { item } ) => {\n\t\treturn (\n\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t<FlatList\n\t\t\t\t\tdata={ item.list }\n\t\t\t\t\tkey={ `InserterUI-${ name }-${ numberOfColumns }` } // Re-render when numberOfColumns changes.\n\t\t\t\t\tnumColumns={ numberOfColumns }\n\t\t\t\t\tItemSeparatorComponent={ () => (\n\t\t\t\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t\t\t\t<View\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tstyles[ 'block-types-list__row-separator' ]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t\t\t) }\n\t\t\t\t\tscrollEnabled={ false }\n\t\t\t\t\trenderItem={ renderListItem }\n\t\t\t\t/>\n\t\t\t</TouchableWithoutFeedback>\n\t\t);\n\t};\n\n\tconst renderListItem = ( { item } ) => {\n\t\treturn (\n\t\t\t<InserterButton\n\t\t\t\titem={ item }\n\t\t\t\titemWidth={ itemWidth }\n\t\t\t\tmaxWidth={ maxWidth }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst colorScheme = usePreferredColorScheme();\n\tconst sectionHeaderGradientValue =\n\t\tcolorScheme === 'light'\n\t\t\t? 'linear-gradient(#fff 70%, rgba(255, 255, 255, 0))'\n\t\t\t: 'linear-gradient(#2e2e2e 70%, rgba(46, 46, 46, 0))';\n\tconst sectionHeaderTitleStyles = usePreferredColorSchemeStyle(\n\t\tstyles[ 'block-types-list__section-header-title' ],\n\t\tstyles[ 'block-types-list__section-header-title--dark' ]\n\t);\n\n\tconst renderSectionHeader = ( { section: { metadata } } ) => {\n\t\tif ( ! metadata?.icon || ! metadata?.title ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn (\n\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t<Gradient\n\t\t\t\t\tgradientValue={ sectionHeaderGradientValue }\n\t\t\t\t\tstyle={ styles[ 'block-types-list__section-header' ] }\n\t\t\t\t>\n\t\t\t\t\t{ metadata?.icon }\n\t\t\t\t\t<Text style={ sectionHeaderTitleStyles }>\n\t\t\t\t\t\t{ metadata?.title }\n\t\t\t\t\t</Text>\n\t\t\t\t</Gradient>\n\t\t\t</TouchableWithoutFeedback>\n\t\t);\n\t};\n\n\treturn (\n\t\t<SectionList\n\t\t\tonLayout={ onLayout }\n\t\t\ttestID={ `InserterUI-${ name }` }\n\t\t\tkeyboardShouldPersistTaps=\"always\"\n\t\t\tsections={ sections }\n\t\t\tinitialNumToRender={ initialNumToRender }\n\t\t\trenderItem={ renderSection }\n\t\t\trenderSectionHeader={ renderSectionHeader }\n\t\t\t{ ...listProps }\n\t\t\tcontentContainerStyle={ {\n\t\t\t\t...contentContainerStyle,\n\t\t\t\tpaddingBottom: Math.max(\n\t\t\t\t\tlistProps.safeAreaBottomInset,\n\t\t\t\t\tcontentContainerStyle.paddingBottom\n\t\t\t\t),\n\t\t\t} }\n\t\t/>\n\t);\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { RangeControl, __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue, __experimentalUseCustomUnits as useCustomUnits } from '@wordpress/components';
|
|
6
|
+
import { BaseControl, RangeControl, __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue, __experimentalUseCustomUnits as useCustomUnits } from '@wordpress/components';
|
|
7
7
|
import { useState } from '@wordpress/element';
|
|
8
8
|
import { __ } from '@wordpress/i18n';
|
|
9
9
|
/**
|
|
@@ -59,7 +59,9 @@ export default function BorderRadiusControl(_ref) {
|
|
|
59
59
|
|
|
60
60
|
return createElement("fieldset", {
|
|
61
61
|
className: "components-border-radius-control"
|
|
62
|
-
}, createElement(
|
|
62
|
+
}, createElement(BaseControl.VisualLabel, {
|
|
63
|
+
as: "legend"
|
|
64
|
+
}, __('Radius')), createElement("div", {
|
|
63
65
|
className: "components-border-radius-control__wrapper"
|
|
64
66
|
}, isLinked ? createElement(Fragment, null, createElement(AllInputControl, {
|
|
65
67
|
className: "components-border-radius-control__unit-control",
|
|
@@ -68,6 +70,8 @@ export default function BorderRadiusControl(_ref) {
|
|
|
68
70
|
onChange: onChange,
|
|
69
71
|
units: units
|
|
70
72
|
}), createElement(RangeControl, {
|
|
73
|
+
label: __('Border radius'),
|
|
74
|
+
hideLabelFromVision: true,
|
|
71
75
|
className: "components-border-radius-control__range-control",
|
|
72
76
|
value: allValue !== null && allValue !== void 0 ? allValue : '',
|
|
73
77
|
min: MIN_BORDER_RADIUS_VALUE,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/index.js"],"names":["RangeControl","__experimentalParseQuantityAndUnitFromRawValue","parseQuantityAndUnitFromRawValue","__experimentalUseCustomUnits","useCustomUnits","useState","__","AllInputControl","InputControls","LinkedButton","useSetting","getAllValue","getAllUnit","hasDefinedValues","hasMixedValues","DEFAULT_VALUES","topLeft","topRight","bottomLeft","bottomRight","MIN_BORDER_RADIUS_VALUE","MAX_BORDER_RADIUS_VALUES","px","em","rem","BorderRadiusControl","onChange","values","isLinked","setIsLinked","units","availableUnits","unit","unitConfig","find","item","value","step","allValue","toggleLinked","handleSliderChange","next","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/index.js"],"names":["BaseControl","RangeControl","__experimentalParseQuantityAndUnitFromRawValue","parseQuantityAndUnitFromRawValue","__experimentalUseCustomUnits","useCustomUnits","useState","__","AllInputControl","InputControls","LinkedButton","useSetting","getAllValue","getAllUnit","hasDefinedValues","hasMixedValues","DEFAULT_VALUES","topLeft","topRight","bottomLeft","bottomRight","MIN_BORDER_RADIUS_VALUE","MAX_BORDER_RADIUS_VALUES","px","em","rem","BorderRadiusControl","onChange","values","isLinked","setIsLinked","units","availableUnits","unit","unitConfig","find","item","value","step","allValue","toggleLinked","handleSliderChange","next","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,WADD,EAECC,YAFD,EAGCC,8CAA8C,IAA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AAA,IAAI,EAAGH;AAVR,IARD,CADS,GAuBT,cAAC,aAAD;AACC,IAAA,GAAG,EAAGjB,uBADP;AAEC,IAAA,QAAQ,EAAGM,QAFZ;AAGC,IAAA,MAAM,EAAGC,MAAM,IAAIZ,cAHpB;AAIC,IAAA,KAAK,EAAGe;AAJT,IAxBF,EA+BC,cAAC,YAAD;AAAc,IAAA,OAAO,EAAGS,YAAxB;AAAuC,IAAA,QAAQ,EAAGX;AAAlD,IA/BD,CAJD,CADD;AAwCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tBaseControl,\n\tRangeControl,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n\t__experimentalUseCustomUnits as useCustomUnits,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport AllInputControl from './all-input-control';\nimport InputControls from './input-controls';\nimport LinkedButton from './linked-button';\nimport useSetting from '../use-setting';\nimport {\n\tgetAllValue,\n\tgetAllUnit,\n\thasDefinedValues,\n\thasMixedValues,\n} from './utils';\n\nconst DEFAULT_VALUES = {\n\ttopLeft: null,\n\ttopRight: null,\n\tbottomLeft: null,\n\tbottomRight: null,\n};\nconst MIN_BORDER_RADIUS_VALUE = 0;\nconst MAX_BORDER_RADIUS_VALUES = {\n\tpx: 100,\n\tem: 20,\n\trem: 20,\n};\n\n/**\n * Control to display border radius options.\n *\n * @param {Object} props Component props.\n * @param {Function} props.onChange Callback to handle onChange.\n * @param {Object} props.values Border radius values.\n *\n * @return {WPElement} Custom border radius control.\n */\nexport default function BorderRadiusControl( { onChange, values } ) {\n\tconst [ isLinked, setIsLinked ] = useState(\n\t\t! hasDefinedValues( values ) || ! hasMixedValues( values )\n\t);\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tconst unit = getAllUnit( values );\n\tconst unitConfig = units && units.find( ( item ) => item.value === unit );\n\tconst step = unitConfig?.step || 1;\n\n\tconst [ allValue ] = parseQuantityAndUnitFromRawValue(\n\t\tgetAllValue( values )\n\t);\n\n\tconst toggleLinked = () => setIsLinked( ! isLinked );\n\n\tconst handleSliderChange = ( next ) => {\n\t\tonChange( next !== undefined ? `${ next }${ unit }` : undefined );\n\t};\n\n\treturn (\n\t\t<fieldset className=\"components-border-radius-control\">\n\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t{ __( 'Radius' ) }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t<div className=\"components-border-radius-control__wrapper\">\n\t\t\t\t{ isLinked ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<AllInputControl\n\t\t\t\t\t\t\tclassName=\"components-border-radius-control__unit-control\"\n\t\t\t\t\t\t\tvalues={ values }\n\t\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\tlabel={ __( 'Border radius' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tclassName=\"components-border-radius-control__range-control\"\n\t\t\t\t\t\t\tvalue={ allValue ?? '' }\n\t\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\t\tmax={ MAX_BORDER_RADIUS_VALUES[ unit ] }\n\t\t\t\t\t\t\tinitialPosition={ 0 }\n\t\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\t\tonChange={ handleSliderChange }\n\t\t\t\t\t\t\tstep={ step }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<InputControls\n\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tvalues={ values || DEFAULT_VALUES }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<LinkedButton onClick={ toggleLinked } isLinked={ isLinked } />\n\t\t\t</div>\n\t\t</fieldset>\n\t);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { find, kebabCase
|
|
4
|
+
import { find, kebabCase } from 'lodash';
|
|
5
5
|
import { colord, extend } from 'colord';
|
|
6
6
|
import namesPlugin from 'colord/plugins/names';
|
|
7
7
|
import a11yPlugin from 'colord/plugins/a11y';
|
|
@@ -77,11 +77,15 @@ export function getColorClassName(colorContextName, colorSlug) {
|
|
|
77
77
|
|
|
78
78
|
export function getMostReadableColor(colors, colorValue) {
|
|
79
79
|
const colordColor = colord(colorValue);
|
|
80
|
-
|
|
80
|
+
|
|
81
|
+
const getColorContrast = _ref => {
|
|
81
82
|
let {
|
|
82
83
|
color
|
|
83
84
|
} = _ref;
|
|
84
85
|
return colordColor.contrast(color);
|
|
85
|
-
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const maxContrast = Math.max(...colors.map(getColorContrast));
|
|
89
|
+
return colors.find(color => getColorContrast(color) === maxContrast).color;
|
|
86
90
|
}
|
|
87
91
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/colors/utils.js"],"names":["find","kebabCase","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors/utils.js"],"names":["find","kebabCase","colord","extend","namesPlugin","a11yPlugin","getColorObjectByAttributeValues","colors","definedColor","customColor","colorObj","slug","color","getColorObjectByColorValue","colorValue","getColorClassName","colorContextName","colorSlug","undefined","getMostReadableColor","colordColor","getColorContrast","contrast","maxContrast","Math","max","map"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,SAAf,QAAgC,QAAhC;AACA,SA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A;AAAF,KAAF;AAAA,WAAiBQ,WAAW,CAACE,QAAZ,CAAsBV,KAAtB,CAAjB;AAAA,GAAzB;;AAEA,QAAMW,WAAW,GAAGC,IAAI,CAACC,GAAL,CAAU,GAAGlB,MAAM,CAACmB,GAAP,CAAYL,gBAAZ,CAAb,CAApB;AACA,SAAOd,MAAM,CAACP,IAAP,CAAeY,KAAF,IAAaS,gBAAgB,CAAET,KAAF,CAAhB,KAA8BW,WAAxD,EACLX,KADF;AAEA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, kebabCase } from 'lodash';\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport a11yPlugin from 'colord/plugins/a11y';\n\nextend( [ namesPlugin, a11yPlugin ] );\n\n/**\n * Provided an array of color objects as set by the theme or by the editor defaults,\n * and the values of the defined color or custom color returns a color object describing the color.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} definedColor A string containing the color slug.\n * @param {?string} customColor A string containing the customColor value.\n *\n * @return {?Object} If definedColor is passed and the name is found in colors,\n * the color object exactly as set by the theme or editor defaults is returned.\n * Otherwise, an object that just sets the color is defined.\n */\nexport const getColorObjectByAttributeValues = (\n\tcolors,\n\tdefinedColor,\n\tcustomColor\n) => {\n\tif ( definedColor ) {\n\t\tconst colorObj = find( colors, { slug: definedColor } );\n\n\t\tif ( colorObj ) {\n\t\t\treturn colorObj;\n\t\t}\n\t}\n\treturn {\n\t\tcolor: customColor,\n\t};\n};\n\n/**\n * Provided an array of color objects as set by the theme or by the editor defaults, and a color value returns the color object matching that value or undefined.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} colorValue A string containing the color value.\n *\n * @return {?Object} Color object included in the colors array whose color property equals colorValue.\n * Returns undefined if no color object matches this requirement.\n */\nexport const getColorObjectByColorValue = ( colors, colorValue ) => {\n\treturn find( colors, { color: colorValue } );\n};\n\n/**\n * Returns a class based on the context a color is being used and its slug.\n *\n * @param {string} colorContextName Context/place where color is being used e.g: background, text etc...\n * @param {string} colorSlug Slug of the color.\n *\n * @return {?string} String with the class corresponding to the color in the provided context.\n * Returns undefined if either colorContextName or colorSlug are not provided.\n */\nexport function getColorClassName( colorContextName, colorSlug ) {\n\tif ( ! colorContextName || ! colorSlug ) {\n\t\treturn undefined;\n\t}\n\n\treturn `has-${ kebabCase( colorSlug ) }-${ colorContextName }`;\n}\n\n/**\n * Given an array of color objects and a color value returns the color value of the most readable color in the array.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} colorValue A string containing the color value.\n *\n * @return {string} String with the color value of the most readable color.\n */\nexport function getMostReadableColor( colors, colorValue ) {\n\tconst colordColor = colord( colorValue );\n\tconst getColorContrast = ( { color } ) => colordColor.contrast( color );\n\n\tconst maxContrast = Math.max( ...colors.map( getColorContrast ) );\n\treturn colors.find( ( color ) => getColorContrast( color ) === maxContrast )\n\t\t.color;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
/**
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { kebabCase, reduce, upperFirst } from 'lodash';
|
|
8
8
|
/**
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
@@ -63,7 +63,7 @@ const withEditorColorPalette = () => createHigherOrderComponent(WrappedComponent
|
|
|
63
63
|
function createColorHOC(colorTypes, withColorPalette) {
|
|
64
64
|
const colorMap = reduce(colorTypes, (colorObject, colorType) => {
|
|
65
65
|
return { ...colorObject,
|
|
66
|
-
...(
|
|
66
|
+
...(typeof colorType === 'string' ? {
|
|
67
67
|
[colorType]: kebabCase(colorType)
|
|
68
68
|
} : colorType)
|
|
69
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/colors/with-colors.js"],"names":["isString","kebabCase","reduce","upperFirst","useMemo","Component","compose","createHigherOrderComponent","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","getMostReadableColor","useSetting","withCustomColorPalette","colorsArray","WrappedComponent","props","withEditorColorPalette","userPalette","themePalette","defaultPalette","allColors","createColorHOC","colorTypes","withColorPalette","colorMap","colorObject","colorType","constructor","setters","createSetters","colorUtils","bind","state","colorValue","colors","settersAccumulator","colorContext","colorAttributeName","upperFirstColorAttributeName","customColorAttributeName","createSetColor","setAttributes","slug","undefined","getDerivedStateFromProps","previousState","attributes","newState","previousColorObject","previousColor","color","class","render","createCustomColorsHOC","withColors"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,SAAnB,EAA8BC,MAA9B,EAAsCC,UAAtC,QAAwD,QAAxD;AAEA;AACA;AACA;;AACA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,oBAAnC;AACA,SAASC,OAAT,EAAkBC,0BAAlB,QAAoD,oBAApD;AAEA;AACA;AACA;;AACA,SACCC,iBADD,EAECC,0BAFD,EAGCC,+BAHD,EAICC,oBAJD,QAKO,SALP;AAMA,OAAOC,UAAP,MAAuB,gBAAvB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,WAAF,IAC9BP,0BAA0B,CACvBQ,gBAAF,IAA0BC,KAAF,IACvB,cAAC,gBAAD,eAAuBA,KAAvB;AAA+B,EAAA,MAAM,EAAGF;AAAxC,GAFwB,EAGzB,wBAHyB,CAD3B;AAOA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,sBAAsB,GAAG,MAC9BV,0BAA0B,CACvBQ,gBAAF,IAA0BC,KAAF,IAAa;AACpC;AACA;AACA;AACA,QAAME,WAAW,GAAGN,UAAU,CAAE,sBAAF,CAA9B;AACA,QAAMO,YAAY,GAAGP,UAAU,CAAE,qBAAF,CAA/B;AACA,QAAMQ,cAAc,GAAGR,UAAU,CAAE,uBAAF,CAAjC;AACA,QAAMS,SAAS,GAAGjB,OAAO,CACxB,MAAM,CACL,I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B,UAAT,GAAqC;AACnD,QAAM/B,gBAAgB,GAAGP,sBAAsB,EAA/C;;AADmD,qCAAbM,UAAa;AAAbA,IAAAA,UAAa;AAAA;;AAEnD,SAAOhB,0BAA0B,CAChCe,cAAc,CAAEC,UAAF,EAAcC,gBAAd,CADkB,EAEhC,YAFgC,CAAjC;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { isString, kebabCase, reduce, upperFirst } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, Component } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport useSetting from '../use-setting';\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) =>\n\t\t\t<WrappedComponent { ...props } colors={ colorsArray } />,\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) => {\n\t\t\t// Some color settings have a special handling for deprecated flags in `useSetting`,\n\t\t\t// so we can't unwrap them by doing const { ... } = useSetting('color')\n\t\t\t// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.\n\t\t\tconst userPalette = useSetting( 'color.palette.custom' );\n\t\t\tconst themePalette = useSetting( 'color.palette.theme' );\n\t\t\tconst defaultPalette = useSetting( 'color.palette.default' );\n\t\t\tconst allColors = useMemo(\n\t\t\t\t() => [\n\t\t\t\t\t...( userPalette || [] ),\n\t\t\t\t\t...( themePalette || [] ),\n\t\t\t\t\t...( defaultPalette || [] ),\n\t\t\t\t],\n\t\t\t\t[ userPalette, themePalette, defaultPalette ]\n\t\t\t);\n\t\t\treturn <WrappedComponent { ...props } colors={ allColors } />;\n\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {WPComponent} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = reduce(\n\t\tcolorTypes,\n\t\t( colorObject, colorType ) => {\n\t\t\treturn {\n\t\t\t\t...colorObject,\n\t\t\t\t...( isString( colorType )\n\t\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t\t: colorType ),\n\t\t\t};\n\t\t},\n\t\t{}\n\t);\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn class extends Component {\n\t\t\t\tconstructor( props ) {\n\t\t\t\t\tsuper( props );\n\n\t\t\t\t\tthis.setters = this.createSetters();\n\t\t\t\t\tthis.colorUtils = {\n\t\t\t\t\t\tgetMostReadableColor:\n\t\t\t\t\t\t\tthis.getMostReadableColor.bind( this ),\n\t\t\t\t\t};\n\n\t\t\t\t\tthis.state = {};\n\t\t\t\t}\n\n\t\t\t\tgetMostReadableColor( colorValue ) {\n\t\t\t\t\tconst { colors } = this.props;\n\t\t\t\t\treturn getMostReadableColor( colors, colorValue );\n\t\t\t\t}\n\n\t\t\t\tcreateSetters() {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tsettersAccumulator,\n\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst upperFirstColorAttributeName =\n\t\t\t\t\t\t\t\tupperFirst( colorAttributeName );\n\t\t\t\t\t\t\tconst customColorAttributeName = `custom${ upperFirstColorAttributeName }`;\n\t\t\t\t\t\t\tsettersAccumulator[\n\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`\n\t\t\t\t\t\t\t] = this.createSetColor(\n\t\t\t\t\t\t\t\tcolorAttributeName,\n\t\t\t\t\t\t\t\tcustomColorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn settersAccumulator;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcreateSetColor( colorAttributeName, customColorAttributeName ) {\n\t\t\t\t\treturn ( colorValue ) => {\n\t\t\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\t\t\tthis.props.colors,\n\t\t\t\t\t\t\tcolorValue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.props.setAttributes( {\n\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? colorObject.slug\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t[ customColorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: colorValue,\n\t\t\t\t\t\t} );\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tstatic getDerivedStateFromProps(\n\t\t\t\t\t{ attributes, colors },\n\t\t\t\t\tpreviousState\n\t\t\t\t) {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t( newState, colorContext, colorAttributeName ) => {\n\t\t\t\t\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\tcolors,\n\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\tattributes[\n\t\t\t\t\t\t\t\t\t`custom${ upperFirst(\n\t\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t\t) }`\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst previousColorObject =\n\t\t\t\t\t\t\t\tpreviousState[ colorAttributeName ];\n\t\t\t\t\t\t\tconst previousColor = previousColorObject?.color;\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The \"and previousColorObject\" condition checks that a previous color object was already computed.\n\t\t\t\t\t\t\t * At the start previousColorObject and colorValue are both equal to undefined\n\t\t\t\t\t\t\t * bus as previousColorObject does not exist we should compute the object.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpreviousColor === colorObject.color &&\n\t\t\t\t\t\t\t\tpreviousColorObject\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] =\n\t\t\t\t\t\t\t\t\tpreviousColorObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] = {\n\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\tcolorObject.slug\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn newState;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\trender() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t...this.props,\n\t\t\t\t\t\t\t\tcolors: undefined,\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\t...this.setters,\n\t\t\t\t\t\t\t\tcolorUtils: this.colorUtils,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors/with-colors.js"],"names":["kebabCase","reduce","upperFirst","useMemo","Component","compose","createHigherOrderComponent","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","getMostReadableColor","useSetting","withCustomColorPalette","colorsArray","WrappedComponent","props","withEditorColorPalette","userPalette","themePalette","defaultPalette","allColors","createColorHOC","colorTypes","withColorPalette","colorMap","colorObject","colorType","constructor","setters","createSetters","colorUtils","bind","state","colorValue","colors","settersAccumulator","colorContext","colorAttributeName","upperFirstColorAttributeName","customColorAttributeName","createSetColor","setAttributes","slug","undefined","getDerivedStateFromProps","previousState","attributes","newState","previousColorObject","previousColor","color","class","render","createCustomColorsHOC","withColors"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,UAA5B,QAA8C,QAA9C;AAEA;AACA;AACA;;AACA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,oBAAnC;AACA,SAASC,OAAT,EAAkBC,0BAAlB,QAAoD,oBAApD;AAEA;AACA;AACA;;AACA,SACCC,iBADD,EAECC,0BAFD,EAGCC,+BAHD,EAICC,oBAJD,QAKO,SALP;AAMA,OAAOC,UAAP,MAAuB,gBAAvB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAKC,WAAF,IAC9BP,0BAA0B,CACvBQ,gBAAF,IAA0BC,KAAF,IACvB,cAAC,gBAAD,eAAuBA,KAAvB;AAA+B,EAAA,MAAM,EAAGF;AAAxC,GAFwB,EAGzB,wBAHyB,CAD3B;AAOA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,sBAAsB,GAAG,MAC9BV,0BAA0B,CACvBQ,gBAAF,IAA0BC,KAAF,IAAa;AACpC;AACA;AACA;AACA,QAAME,WAAW,GAAGN,UAAU,CAAE,sBAAF,CAA9B;AACA,QAAMO,YAAY,GAAGP,UAAU,CAAE,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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAAS+B,UAAT,GAAqC;AACnD,QAAM/B,gBAAgB,GAAGP,sBAAsB,EAA/C;;AADmD,qCAAbM,UAAa;AAAbA,IAAAA,UAAa;AAAA;;AAEnD,SAAOhB,0BAA0B,CAChCe,cAAc,CAAEC,UAAF,EAAcC,gBAAd,CADkB,EAEhC,YAFgC,CAAjC;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase, reduce, upperFirst } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, Component } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport useSetting from '../use-setting';\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) =>\n\t\t\t<WrappedComponent { ...props } colors={ colorsArray } />,\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( props ) => {\n\t\t\t// Some color settings have a special handling for deprecated flags in `useSetting`,\n\t\t\t// so we can't unwrap them by doing const { ... } = useSetting('color')\n\t\t\t// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.\n\t\t\tconst userPalette = useSetting( 'color.palette.custom' );\n\t\t\tconst themePalette = useSetting( 'color.palette.theme' );\n\t\t\tconst defaultPalette = useSetting( 'color.palette.default' );\n\t\t\tconst allColors = useMemo(\n\t\t\t\t() => [\n\t\t\t\t\t...( userPalette || [] ),\n\t\t\t\t\t...( themePalette || [] ),\n\t\t\t\t\t...( defaultPalette || [] ),\n\t\t\t\t],\n\t\t\t\t[ userPalette, themePalette, defaultPalette ]\n\t\t\t);\n\t\t\treturn <WrappedComponent { ...props } colors={ allColors } />;\n\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {WPComponent} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = reduce(\n\t\tcolorTypes,\n\t\t( colorObject, colorType ) => {\n\t\t\treturn {\n\t\t\t\t...colorObject,\n\t\t\t\t...( typeof colorType === 'string'\n\t\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t\t: colorType ),\n\t\t\t};\n\t\t},\n\t\t{}\n\t);\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn class extends Component {\n\t\t\t\tconstructor( props ) {\n\t\t\t\t\tsuper( props );\n\n\t\t\t\t\tthis.setters = this.createSetters();\n\t\t\t\t\tthis.colorUtils = {\n\t\t\t\t\t\tgetMostReadableColor:\n\t\t\t\t\t\t\tthis.getMostReadableColor.bind( this ),\n\t\t\t\t\t};\n\n\t\t\t\t\tthis.state = {};\n\t\t\t\t}\n\n\t\t\t\tgetMostReadableColor( colorValue ) {\n\t\t\t\t\tconst { colors } = this.props;\n\t\t\t\t\treturn getMostReadableColor( colors, colorValue );\n\t\t\t\t}\n\n\t\t\t\tcreateSetters() {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tsettersAccumulator,\n\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst upperFirstColorAttributeName =\n\t\t\t\t\t\t\t\tupperFirst( colorAttributeName );\n\t\t\t\t\t\t\tconst customColorAttributeName = `custom${ upperFirstColorAttributeName }`;\n\t\t\t\t\t\t\tsettersAccumulator[\n\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`\n\t\t\t\t\t\t\t] = this.createSetColor(\n\t\t\t\t\t\t\t\tcolorAttributeName,\n\t\t\t\t\t\t\t\tcustomColorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn settersAccumulator;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcreateSetColor( colorAttributeName, customColorAttributeName ) {\n\t\t\t\t\treturn ( colorValue ) => {\n\t\t\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\t\t\tthis.props.colors,\n\t\t\t\t\t\t\tcolorValue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.props.setAttributes( {\n\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? colorObject.slug\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t[ customColorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: colorValue,\n\t\t\t\t\t\t} );\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tstatic getDerivedStateFromProps(\n\t\t\t\t\t{ attributes, colors },\n\t\t\t\t\tpreviousState\n\t\t\t\t) {\n\t\t\t\t\treturn reduce(\n\t\t\t\t\t\tcolorMap,\n\t\t\t\t\t\t( newState, colorContext, colorAttributeName ) => {\n\t\t\t\t\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\tcolors,\n\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\tattributes[\n\t\t\t\t\t\t\t\t\t`custom${ upperFirst(\n\t\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t\t) }`\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst previousColorObject =\n\t\t\t\t\t\t\t\tpreviousState[ colorAttributeName ];\n\t\t\t\t\t\t\tconst previousColor = previousColorObject?.color;\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The \"and previousColorObject\" condition checks that a previous color object was already computed.\n\t\t\t\t\t\t\t * At the start previousColorObject and colorValue are both equal to undefined\n\t\t\t\t\t\t\t * bus as previousColorObject does not exist we should compute the object.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpreviousColor === colorObject.color &&\n\t\t\t\t\t\t\t\tpreviousColorObject\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] =\n\t\t\t\t\t\t\t\t\tpreviousColorObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] = {\n\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\tcolorObject.slug\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn newState;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\trender() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t...this.props,\n\t\t\t\t\t\t\t\tcolors: undefined,\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\t...this.setters,\n\t\t\t\t\t\t\t\tcolorUtils: this.colorUtils,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"]}
|