@wordpress/block-editor 8.0.12-next.33ec3857e2.0 → 8.0.15
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/README.md +0 -4
- package/build/components/block-caption/index.native.js +3 -14
- package/build/components/block-caption/index.native.js.map +1 -1
- package/build/components/block-inspector/index.js +33 -12
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +1 -1
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +2 -3
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -3
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-list-appender/index.js +11 -3
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-mover/button.js +2 -2
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +2 -2
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-mover/index.native.js +2 -2
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-preview/auto.js +2 -10
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-settings/container.native.js +1 -2
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/block-styles/index.js +134 -110
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-styles/utils.js +0 -39
- package/build/components/block-styles/utils.js.map +1 -1
- package/build/components/block-switcher/block-styles-menu.js +23 -3
- package/build/components/block-switcher/block-styles-menu.js.map +1 -1
- package/build/components/block-tools/back-compat.js +1 -2
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +3 -3
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +9 -0
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +1 -11
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/button-block-appender/index.js +1 -2
- package/build/components/button-block-appender/index.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +10 -51
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/default-block-appender/index.js +19 -16
- package/build/components/default-block-appender/index.js.map +1 -1
- package/build/components/default-style-picker/index.js +3 -18
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +11 -11
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/gradients/use-gradient.js +4 -4
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/iframe/index.js +6 -7
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +9 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/default-block-appender.js +4 -2
- package/build/components/inner-blocks/default-block-appender.js.map +1 -1
- package/build/components/inserter/hooks/use-insertion-point.js +2 -2
- package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build/components/inserter/index.js +2 -2
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/index.native.js +3 -3
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +1 -1
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/tabs.native.js +4 -7
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inspector-controls/block-support-slot-container.js +1 -2
- package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +50 -22
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +5 -3
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +0 -2
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls/slot.js +3 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +6 -6
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +3 -23
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-placeholder/index.js +0 -2
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +0 -2
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +37 -10
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/rich-text/file-paste-handler.js +1 -1
- package/build/components/rich-text/file-paste-handler.js.map +1 -1
- package/build/components/rich-text/use-input-rules.js +1 -3
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/selection-scroll-into-view/index.js +1 -2
- package/build/components/selection-scroll-into-view/index.js.map +1 -1
- package/build/components/use-canvas-click-redirect/index.js +66 -0
- package/build/components/use-canvas-click-redirect/index.js.map +1 -0
- package/build/components/use-on-block-drop/index.js +4 -8
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-setting/index.js +7 -0
- package/build/components/use-setting/index.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js +1 -3
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/hooks/border-color.js +5 -63
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/border-radius.js +0 -47
- package/build/hooks/border-radius.js.map +1 -1
- package/build/hooks/border-style.js +0 -41
- package/build/hooks/border-style.js.map +1 -1
- package/build/hooks/border-width.js +31 -70
- package/build/hooks/border-width.js.map +1 -1
- package/build/hooks/border.js +11 -81
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +6 -5
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/layout.js +2 -1
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/letter-spacing.js +1 -1
- package/build/hooks/letter-spacing.js.map +1 -1
- package/build/hooks/style.js +2 -1
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +1 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/layouts/flex.js +9 -29
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +10 -6
- package/build/layouts/flow.js.map +1 -1
- package/build/store/actions.js +5 -4
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +1 -5
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +24 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +2 -2
- package/build/store/selectors.js.map +1 -1
- package/build/utils/get-paste-event-data.js +1 -1
- package/build/utils/get-paste-event-data.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +1 -1
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-caption/index.native.js +3 -13
- package/build-module/components/block-caption/index.native.js.map +1 -1
- package/build-module/components/block-inspector/index.js +33 -12
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +1 -1
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -3
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -3
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +10 -3
- package/build-module/components/block-list-appender/index.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/button.js +2 -2
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +2 -2
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +2 -2
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-preview/auto.js +2 -10
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +1 -2
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/block-styles/index.js +133 -112
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-styles/utils.js +0 -34
- package/build-module/components/block-styles/utils.js.map +1 -1
- package/build-module/components/block-switcher/block-styles-menu.js +21 -3
- package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +1 -2
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +3 -3
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +9 -0
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +1 -11
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/button-block-appender/index.js +1 -2
- package/build-module/components/button-block-appender/index.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +13 -54
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/default-block-appender/index.js +18 -15
- package/build-module/components/default-block-appender/index.js.map +1 -1
- package/build-module/components/default-style-picker/index.js +3 -17
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +12 -12
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/gradients/use-gradient.js +4 -3
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -7
- package/build-module/components/iframe/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/inner-blocks/default-block-appender.js +4 -2
- package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
- package/build-module/components/inserter/hooks/use-insertion-point.js +2 -2
- package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build-module/components/inserter/index.js +2 -2
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +4 -4
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +1 -1
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +4 -7
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-slot-container.js +1 -2
- package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +50 -22
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +5 -3
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +0 -2
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +3 -1
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +6 -6
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +3 -22
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +0 -2
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +0 -2
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +41 -14
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/rich-text/file-paste-handler.js +1 -1
- package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
- package/build-module/components/rich-text/use-input-rules.js +1 -2
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/selection-scroll-into-view/index.js +1 -2
- package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
- package/build-module/components/use-canvas-click-redirect/index.js +54 -0
- package/build-module/components/use-canvas-click-redirect/index.js.map +1 -0
- package/build-module/components/use-on-block-drop/index.js +4 -8
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +7 -0
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js +4 -3
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/hooks/border-color.js +7 -61
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/border-radius.js +0 -42
- package/build-module/hooks/border-radius.js.map +1 -1
- package/build-module/hooks/border-style.js +0 -36
- package/build-module/hooks/border-style.js.map +1 -1
- package/build-module/hooks/border-width.js +32 -66
- package/build-module/hooks/border-width.js.map +1 -1
- package/build-module/hooks/border.js +12 -80
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +6 -5
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/layout.js +2 -1
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/letter-spacing.js +1 -1
- package/build-module/hooks/letter-spacing.js.map +1 -1
- package/build-module/hooks/style.js +2 -1
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +1 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/layouts/flex.js +9 -29
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +10 -6
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/actions.js +5 -4
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +1 -5
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +24 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/get-paste-event-data.js +1 -1
- package/build-module/utils/get-paste-event-data.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +1 -1
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +180 -212
- package/build-style/style.css +180 -212
- package/package.json +27 -27
- package/src/components/block-caption/index.native.js +4 -22
- package/src/components/block-inspector/index.js +32 -13
- package/src/components/block-list/block.js +1 -1
- package/src/components/block-list/block.native.js +2 -2
- package/src/components/block-list/use-block-props/index.js +1 -3
- package/src/components/block-list/use-in-between-inserter.js +1 -1
- package/src/components/block-list-appender/index.js +21 -5
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +2 -5
- package/src/components/block-mover/button.js +2 -6
- package/src/components/block-mover/index.js +2 -5
- package/src/components/block-mover/index.native.js +2 -5
- package/src/components/block-preview/auto.js +2 -7
- package/src/components/block-settings/container.native.js +0 -1
- package/src/components/block-styles/index.js +145 -125
- package/src/components/block-styles/style.scss +51 -59
- package/src/components/block-styles/test/{utils.js → index.js} +1 -60
- package/src/components/block-styles/utils.js +0 -39
- package/src/components/block-switcher/block-styles-menu.js +38 -3
- package/src/components/block-tools/back-compat.js +0 -1
- package/src/components/block-tools/block-selection-button.js +3 -9
- package/src/components/block-tools/index.js +11 -0
- package/src/components/block-tools/insertion-point.js +1 -10
- package/src/components/border-style-control/style.scss +1 -0
- package/src/components/button-block-appender/index.js +0 -1
- package/src/components/colors-gradients/panel-color-gradient-settings.js +19 -75
- package/src/components/colors-gradients/style.scss +5 -42
- package/src/components/default-block-appender/index.js +24 -17
- package/src/components/default-block-appender/style.scss +0 -4
- package/src/components/default-block-appender/test/__snapshots__/index.js.snap +24 -12
- package/src/components/default-block-appender/test/index.js +14 -4
- package/src/components/default-style-picker/index.js +6 -18
- package/src/components/font-appearance-control/index.js +12 -12
- package/src/components/gradients/use-gradient.js +7 -7
- package/src/components/iframe/index.js +6 -13
- package/src/components/index.js +1 -1
- package/src/components/inner-blocks/README.md +0 -2
- package/src/components/inner-blocks/default-block-appender.js +7 -2
- package/src/components/inserter/hooks/use-insertion-point.js +2 -9
- package/src/components/inserter/index.js +2 -2
- package/src/components/inserter/index.native.js +4 -7
- package/src/components/inserter/quick-inserter.js +1 -1
- package/src/components/inserter/tabs.native.js +4 -5
- package/src/components/inspector-controls/block-support-slot-container.js +1 -3
- package/src/components/inspector-controls/block-support-tools-panel.js +57 -21
- package/src/components/inspector-controls/fill.native.js +3 -4
- package/src/components/inspector-controls/groups.js +0 -2
- package/src/components/inspector-controls/slot.js +7 -2
- package/src/components/letter-spacing-control/index.js +6 -6
- package/src/components/link-control/README.md +1 -1
- package/src/components/link-control/test/index.js +0 -2
- package/src/components/list-view/block-select-button.js +1 -20
- package/src/components/list-view/use-list-view-drop-zone.js +1 -1
- package/src/components/media-placeholder/index.js +0 -2
- package/src/components/media-replace-flow/index.js +0 -2
- package/src/components/provider/use-block-sync.js +45 -11
- package/src/components/rich-text/file-paste-handler.js +1 -3
- package/src/components/rich-text/use-input-rules.js +1 -2
- package/src/components/selection-scroll-into-view/index.js +0 -1
- package/src/components/url-input/README.md +0 -5
- package/src/components/use-canvas-click-redirect/index.js +57 -0
- package/src/components/use-on-block-drop/index.js +4 -11
- package/src/components/use-setting/index.js +9 -0
- package/src/components/writing-flow/use-multi-selection.js +9 -12
- package/src/hooks/border-color.js +3 -55
- package/src/hooks/border-radius.js +0 -32
- package/src/hooks/border-style.js +0 -26
- package/src/hooks/border-width.js +32 -56
- package/src/hooks/border.js +20 -115
- package/src/hooks/border.scss +17 -3
- package/src/hooks/color.js +13 -14
- package/src/hooks/layout.js +1 -0
- package/src/hooks/letter-spacing.js +1 -1
- package/src/hooks/style.js +2 -1
- package/src/hooks/test/style.js +0 -2
- package/src/hooks/typography.js +1 -1
- package/src/layouts/flex.js +8 -31
- package/src/layouts/flow.js +8 -6
- package/src/store/actions.js +5 -5
- package/src/store/defaults.js +0 -2
- package/src/store/reducer.js +23 -1
- package/src/store/selectors.js +2 -2
- package/src/store/test/reducer.js +35 -0
- package/src/store/test/selectors.js +1 -1
- package/src/style.scss +3 -4
- package/src/utils/get-paste-event-data.js +1 -1
- package/src/utils/parse-css-unit-to-px.js +1 -1
- package/src/utils/test/parse-css-unit-to-px.js +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/block-styles/menu-items.js +0 -63
- package/build/components/block-styles/menu-items.js.map +0 -1
- package/build/components/block-styles/preview-panel.js +0 -45
- package/build/components/block-styles/preview-panel.js.map +0 -1
- package/build/components/block-styles/use-styles-for-block.js +0 -119
- package/build/components/block-styles/use-styles-for-block.js.map +0 -1
- package/build/components/rich-text/prevent-event-discovery.js +0 -33
- package/build/components/rich-text/prevent-event-discovery.js.map +0 -1
- package/build/components/use-display-block-controls/index.native.js +0 -45
- package/build/components/use-display-block-controls/index.native.js.map +0 -1
- package/build-module/components/block-styles/menu-items.js +0 -50
- package/build-module/components/block-styles/menu-items.js.map +0 -1
- package/build-module/components/block-styles/preview-panel.js +0 -35
- package/build-module/components/block-styles/preview-panel.js.map +0 -1
- package/build-module/components/block-styles/use-styles-for-block.js +0 -107
- package/build-module/components/block-styles/use-styles-for-block.js.map +0 -1
- package/build-module/components/rich-text/prevent-event-discovery.js +0 -25
- package/build-module/components/rich-text/prevent-event-discovery.js.map +0 -1
- package/build-module/components/use-display-block-controls/index.native.js +0 -34
- package/build-module/components/use-display-block-controls/index.native.js.map +0 -1
- package/src/components/block-styles/menu-items.js +0 -49
- package/src/components/block-styles/preview-panel.js +0 -36
- package/src/components/block-styles/use-styles-for-block.js +0 -99
- package/src/components/rich-text/prevent-event-discovery.js +0 -23
- package/src/components/use-display-block-controls/index.native.js +0 -38
- package/src/components/writing-flow/test/use-multi-selection.js +0 -36
- package/src/hooks/dimensions.scss +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/block-select-button.js"],"names":["ListViewBlockSelectButton","ref","className","block","clientId","isSelected","onClick","onToggleExpanded","position","siblingBlockCount","level","tabIndex","onFocus","onDragStart","onDragEnd","draggable","blockInformation","instanceId","descriptionId","blockPositionDescription","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/block-select-button.js"],"names":["ListViewBlockSelectButton","ref","className","block","clientId","isSelected","onClick","onToggleExpanded","position","siblingBlockCount","level","tabIndex","onFocus","onDragStart","onDragEnd","draggable","blockInformation","instanceId","descriptionId","blockPositionDescription","icon","anchor"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAOA,SAASA,yBAAT,OAgBCC,GAhBD,EAiBE;AAAA,MAhBD;AACCC,IAAAA,SADD;AAECC,IAAAA,KAAK,EAAE;AAAEC,MAAAA;AAAF,KAFR;AAGCC,IAAAA,UAHD;AAICC,IAAAA,OAJD;AAKCC,IAAAA,gBALD;AAMCC,IAAAA,QAND;AAOCC,IAAAA,iBAPD;AAQCC,IAAAA,KARD;AASCC,IAAAA,QATD;AAUCC,IAAAA,OAVD;AAWCC,IAAAA,WAXD;AAYCC,IAAAA,SAZD;AAaCC,IAAAA;AAbD,GAgBC;AACD,QAAMC,gBAAgB,GAAG,yCAA4BZ,QAA5B,CAAzB;AACA,QAAMa,UAAU,GAAG,4BAAejB,yBAAf,CAAnB;AACA,QAAMkB,aAAa,GAAI,kCAAkCD,UAAY,EAArE;AACA,QAAME,wBAAwB,GAAG,wCAChCX,QADgC,EAEhCC,iBAFgC,EAGhCC,KAHgC,CAAjC;AAMA,SACC,qDACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAG,yBACX,4CADW,EAEXR,SAFW,CADb;AAKC,IAAA,OAAO,EAAGI,OALX;AAMC,wBAAmBY,aANpB;AAOC,IAAA,GAAG,EAAGjB,GAPP;AAQC,IAAA,QAAQ,EAAGU,QARZ;AASC,IAAA,OAAO,EAAGC,OATX;AAUC,IAAA,WAAW,EAAGC,WAVf;AAWC,IAAA,SAAS,EAAGC,SAXb;AAYC,IAAA,SAAS,EAAGC;AAZb,KAcC,4BAAC,iBAAD;AAAkB,IAAA,OAAO,EAAGR;AAA5B,IAdD,EAeC,4BAAC,kBAAD;AAAW,IAAA,IAAI,EAAGS,gBAAH,aAAGA,gBAAH,uBAAGA,gBAAgB,CAAEI,IAApC;AAA2C,IAAA,UAAU;AAArD,IAfD,EAgBC,4BAAC,mBAAD;AAAY,IAAA,QAAQ,EAAGhB;AAAvB,IAhBD,EAiBG,CAAAY,gBAAgB,SAAhB,IAAAA,gBAAgB,WAAhB,YAAAA,gBAAgB,CAAEK,MAAlB,KACD;AAAM,IAAA,SAAS,EAAC;AAAhB,KACGL,gBAAgB,CAACK,MADpB,CAlBF,EAsBGhB,UAAU,IACX,4BAAC,0BAAD,QACG,cAAI,kBAAJ,CADH,CAvBF,CADD,EA6BC;AACC,IAAA,SAAS,EAAC,yDADX;AAEC,IAAA,EAAE,EAAGa;AAFN,KAIGC,wBAJH,CA7BD,CADD;AAsCA;;eAEc,yBAAYnB,yBAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button, VisuallyHidden } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockIcon from '../block-icon';\nimport useBlockDisplayInformation from '../use-block-display-information';\nimport { getBlockPositionDescription } from './utils';\nimport BlockTitle from '../block-title';\nimport ListViewExpander from './expander';\n\nfunction ListViewBlockSelectButton(\n\t{\n\t\tclassName,\n\t\tblock: { clientId },\n\t\tisSelected,\n\t\tonClick,\n\t\tonToggleExpanded,\n\t\tposition,\n\t\tsiblingBlockCount,\n\t\tlevel,\n\t\ttabIndex,\n\t\tonFocus,\n\t\tonDragStart,\n\t\tonDragEnd,\n\t\tdraggable,\n\t},\n\tref\n) {\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\tconst instanceId = useInstanceId( ListViewBlockSelectButton );\n\tconst descriptionId = `list-view-block-select-button__${ instanceId }`;\n\tconst blockPositionDescription = getBlockPositionDescription(\n\t\tposition,\n\t\tsiblingBlockCount,\n\t\tlevel\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tclassName={ classnames(\n\t\t\t\t\t'block-editor-list-view-block-select-button',\n\t\t\t\t\tclassName\n\t\t\t\t) }\n\t\t\t\tonClick={ onClick }\n\t\t\t\taria-describedby={ descriptionId }\n\t\t\t\tref={ ref }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\tonFocus={ onFocus }\n\t\t\t\tonDragStart={ onDragStart }\n\t\t\t\tonDragEnd={ onDragEnd }\n\t\t\t\tdraggable={ draggable }\n\t\t\t>\n\t\t\t\t<ListViewExpander onClick={ onToggleExpanded } />\n\t\t\t\t<BlockIcon icon={ blockInformation?.icon } showColors />\n\t\t\t\t<BlockTitle clientId={ clientId } />\n\t\t\t\t{ blockInformation?.anchor && (\n\t\t\t\t\t<span className=\"block-editor-list-view-block-select-button__anchor\">\n\t\t\t\t\t\t{ blockInformation.anchor }\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t{ isSelected && (\n\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t{ __( '(selected block)' ) }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t) }\n\t\t\t</Button>\n\t\t\t<div\n\t\t\t\tclassName=\"block-editor-list-view-block-select-button__description\"\n\t\t\t\tid={ descriptionId }\n\t\t\t>\n\t\t\t\t{ blockPositionDescription }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default forwardRef( ListViewBlockSelectButton );\n"]}
|
|
@@ -210,7 +210,7 @@ function useListViewDropZone() {
|
|
|
210
210
|
return {
|
|
211
211
|
clientId,
|
|
212
212
|
rootClientId,
|
|
213
|
-
blockIndex: getBlockIndex(clientId
|
|
213
|
+
blockIndex: getBlockIndex(clientId),
|
|
214
214
|
element: blockElement,
|
|
215
215
|
isDraggedBlock: isBlockDrag ? draggedBlockClientIds.includes(clientId) : false,
|
|
216
216
|
innerBlockCount: getBlockCount(clientId),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["isPointContainedByRect","point","rect","left","x","right","top","y","bottom","isNestingGesture","blockCenterX","width","ALLOWED_DROP_EDGES","getListViewDropTarget","blocksData","position","candidateEdge","candidateBlockData","candidateDistance","candidateRect","blockData","isDraggedBlock","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","index","indexOf","previousBlockData","rootClientId","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","clientId","blockIndex","dropPosition","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","blockEditorStore","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","clientY","isBlockDrag","length","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AAfA;AACA;AACA;;AAQA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SACCA,IAAI,CAACC,IAAL,IAAaF,KAAK,CAACG,CAAnB,IACAF,IAAI,CAACG,KAAL,IAAcJ,KAAK,CAACG,CADpB,IAEAF,IAAI,CAACI,GAAL,IAAYL,KAAK,CAACM,CAFlB,IAGAL,IAAI,CAACM,MAAL,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CADwB,GAExB,KAPG;AAQND,QAAAA,eAAe,EAAES,aAAa,CAAER,QAAF,CARxB;AASNG,QAAAA,+BAA+B,EAAEoB,WAAW,GACzCb,eAAe,CACfO,qBADe,EAEfrB,YAFe,CAD0B,GAKzC,IAdG;AAeNE,QAAAA,6BAA6B,EAAEyB,WAAW,GACvCb,eAAe,CAAEO,qBAAF,EAAyBjB,QAAzB,CADwB,GAEvC;AAjBG,OAAP;AAmBA,KAvBkB,CAAnB;AAyBA,UAAMkC,SAAS,GAAGxD,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKsD,SAAL,EAAiB;AAChBrB,MAAAA,SAAS,CAAEqB,SAAF,CAAT;AACA;AACD,GAvCF,EAwCC,CAAEjB,qBAAF,CAxCD,CADiB,EA2CjB,GA3CiB,CAAlB;AA8CA,QAAMkB,GAAG,GAAG,wCAAa;AACxBC,IAAAA,MAAM,EAAEpB,WADgB;;AAExBqB,IAAAA,UAAU,CAAElB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBkB,IAAAA,SAAS,GAAG;AACXpB,MAAAA,SAAS,CAACqB,MAAV;AACA1B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAb,CAAZ;AAcA,SAAO;AAAEsB,IAAAA,GAAF;AAAOvB,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlocks\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n/**\n * Is the point contained by the rectangle.\n *\n * @param {WPPoint} point The point.\n * @param {DOMRect} rect The rectangle.\n *\n * @return {boolean} True if the point is contained by the rectangle, false otherwise.\n */\nfunction isPointContainedByRect( point, rect ) {\n\treturn (\n\t\trect.left <= point.x &&\n\t\trect.right >= point.x &&\n\t\trect.top <= point.y &&\n\t\trect.bottom >= point.y\n\t);\n}\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Presently this is determined by whether the cursor is on the right hand side\n * of the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n */\nfunction isNestingGesture( point, rect ) {\n\tconst blockCenterX = rect.left + rect.width / 2;\n\treturn point.x > blockCenterX;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n *\n * @return {WPListViewDropZoneTarget} An object containing data about the drop target.\n */\nfunction getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\n\tfor ( const blockData of blocksData ) {\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect = previousBlockData.element.getBoundingClientRect();\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, this should always be treated\n\t// as nesting since the next block in the tree will be the first child.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( candidateBlockData.innerBlockCount > 0 ||\n\t\t\tisNestingGesture( position, candidateRect ) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId, rootClientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["isPointContainedByRect","point","rect","left","x","right","top","y","bottom","isNestingGesture","blockCenterX","width","ALLOWED_DROP_EDGES","getListViewDropTarget","blocksData","position","candidateEdge","candidateBlockData","candidateDistance","candidateRect","blockData","isDraggedBlock","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","index","indexOf","previousBlockData","rootClientId","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","clientId","blockIndex","dropPosition","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","blockEditorStore","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","clientY","isBlockDrag","length","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AAfA;AACA;AACA;;AAQA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SACCA,IAAI,CAACC,IAAL,IAAaF,KAAK,CAACG,CAAnB,IACAF,IAAI,CAACG,KAAL,IAAcJ,KAAK,CAACG,CADpB,IAEAF,IAAI,CAACI,GAAL,IAAYL,KAAK,CAACM,CAFlB,IAGAL,IAAI,CAACM,MAAL,IAAeP,KAAK,CAACM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Ae,EAAES,aAAa,CAAER,QAAF,CARxB;AASNG,QAAAA,+BAA+B,EAAEoB,WAAW,GACzCb,eAAe,CACfO,qBADe,EAEfrB,YAFe,CAD0B,GAKzC,IAdG;AAeNE,QAAAA,6BAA6B,EAAEyB,WAAW,GACvCb,eAAe,CAAEO,qBAAF,EAAyBjB,QAAzB,CADwB,GAEvC;AAjBG,OAAP;AAmBA,KAvBkB,CAAnB;AAyBA,UAAMkC,SAAS,GAAGxD,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKsD,SAAL,EAAiB;AAChBrB,MAAAA,SAAS,CAAEqB,SAAF,CAAT;AACA;AACD,GAvCF,EAwCC,CAAEjB,qBAAF,CAxCD,CADiB,EA2CjB,GA3CiB,CAAlB;AA8CA,QAAMkB,GAAG,GAAG,wCAAa;AACxBC,IAAAA,MAAM,EAAEpB,WADgB;;AAExBqB,IAAAA,UAAU,CAAElB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBkB,IAAAA,SAAS,GAAG;AACXpB,MAAAA,SAAS,CAACqB,MAAV;AACA1B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAb,CAAZ;AAcA,SAAO;AAAEsB,IAAAA,GAAF;AAAOvB,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlocks\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n/**\n * Is the point contained by the rectangle.\n *\n * @param {WPPoint} point The point.\n * @param {DOMRect} rect The rectangle.\n *\n * @return {boolean} True if the point is contained by the rectangle, false otherwise.\n */\nfunction isPointContainedByRect( point, rect ) {\n\treturn (\n\t\trect.left <= point.x &&\n\t\trect.right >= point.x &&\n\t\trect.top <= point.y &&\n\t\trect.bottom >= point.y\n\t);\n}\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Presently this is determined by whether the cursor is on the right hand side\n * of the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n */\nfunction isNestingGesture( point, rect ) {\n\tconst blockCenterX = rect.left + rect.width / 2;\n\treturn point.x > blockCenterX;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n *\n * @return {WPListViewDropZoneTarget} An object containing data about the drop target.\n */\nfunction getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\n\tfor ( const blockData of blocksData ) {\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect = previousBlockData.element.getBoundingClientRect();\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, this should always be treated\n\t// as nesting since the next block in the tree will be the first child.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( candidateBlockData.innerBlockCount > 0 ||\n\t\t\tisNestingGesture( position, candidateRect ) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
@@ -94,7 +94,6 @@ function MediaPlaceholder(_ref2) {
|
|
|
94
94
|
onDoubleClick,
|
|
95
95
|
onFilesPreUpload = _lodash.noop,
|
|
96
96
|
onHTMLDrop = _lodash.noop,
|
|
97
|
-
onClose = _lodash.noop,
|
|
98
97
|
children,
|
|
99
98
|
mediaLibraryButton,
|
|
100
99
|
placeholder,
|
|
@@ -334,7 +333,6 @@ function MediaPlaceholder(_ref2) {
|
|
|
334
333
|
gallery: multiple && onlyAllowsImages(),
|
|
335
334
|
multiple: multiple,
|
|
336
335
|
onSelect: onSelect,
|
|
337
|
-
onClose: onClose,
|
|
338
336
|
allowedTypes: allowedTypes,
|
|
339
337
|
value: Array.isArray(value) ? value.map(_ref7 => {
|
|
340
338
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/media-placeholder/index.js"],"names":["InsertFromURLPopover","src","onChange","onSubmit","onClose","keyboardReturn","MediaPlaceholder","value","allowedTypes","className","icon","labels","mediaPreview","notices","isAppender","accept","addToGallery","multiple","handleUpload","dropZoneUIOnly","disableDropZone","disableMediaButtons","onError","onSelect","onCancel","onSelectURL","onDoubleClick","onFilesPreUpload","noop","onHTMLDrop","children","mediaLibraryButton","placeholder","style","mediaUpload","select","getSettings","blockEditorStore","setSrc","isURLInputVisible","setIsURLInputVisible","onlyAllowsImages","length","every","allowedType","startsWith","onChangeSrc","event","target","openURLInput","closeURLInput","onSubmitSrc","preventDefault","onFilesUpload","files","setMedia","lastMediaPassed","newMedia","filteredMedia","filter","item","id","some","Number","urlSlug","url","includes","concat","map","media","cutOffIndex","lastIndexOf","slice","filesList","onFileChange","onUpload","defaultRenderPlaceholder","content","instructions","title","undefined","typesAllowed","firstAllowedType","isOneType","isAudio","isImage","isVideo","placeholderClassName","renderPlaceholder","renderDropZone","renderCancelLink","renderUrlSelectionUI","renderMediaUploadChecked","defaultButton","open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ies\n */\nimport { noop } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tFormFileUpload,\n\tPlaceholder,\n\tDropZone,\n\twithFilters,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { keyboardReturn } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport MediaUpload from '../media-upload';\nimport MediaUploadCheck from '../media-upload/check';\nimport URLPopover from '../url-popover';\nimport { store as blockEditorStore } from '../../store';\n\nconst InsertFromURLPopover = ( { src, onChange, onSubmit, onClose } ) => (\n\t<URLPopover onClose={ onClose }>\n\t\t<form\n\t\t\tclassName=\"block-editor-media-placeholder__url-input-form\"\n\t\t\tonSubmit={ onSubmit }\n\t\t>\n\t\t\t<input\n\t\t\t\tclassName=\"block-editor-media-placeholder__url-input-field\"\n\t\t\t\ttype=\"text\"\n\t\t\t\taria-label={ __( 'URL' ) }\n\t\t\t\tplaceholder={ __( 'Paste or type URL' ) }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tvalue={ src }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tclassName=\"block-editor-media-placeholder__url-input-submit-button\"\n\t\t\t\ticon={ keyboardReturn }\n\t\t\t\tlabel={ __( 'Apply' ) }\n\t\t\t\ttype=\"submit\"\n\t\t\t/>\n\t\t</form>\n\t</URLPopover>\n);\n\nexport function MediaPlaceholder( {\n\tvalue = {},\n\tallowedTypes,\n\tclassName,\n\ticon,\n\tlabels = {},\n\tmediaPreview,\n\tnotices,\n\tisAppender,\n\taccept,\n\taddToGallery,\n\tmultiple = false,\n\thandleUpload = true,\n\tdropZoneUIOnly,\n\tdisableDropZone,\n\tdisableMediaButtons,\n\tonError,\n\tonSelect,\n\tonCancel,\n\tonSelectURL,\n\tonDoubleClick,\n\tonFilesPreUpload = noop,\n\tonHTMLDrop = noop,\n\tonClose = noop,\n\tchildren,\n\tmediaLibraryButton,\n\tplaceholder,\n\tstyle,\n} ) {\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().mediaUpload;\n\t}, [] );\n\tconst [ src, setSrc ] = useState( '' );\n\tconst [ isURLInputVisible, setIsURLInputVisible ] = useState( false );\n\n\tuseEffect( () => {\n\t\tsetSrc( value?.src ?? '' );\n\t}, [ value?.src ] );\n\n\tconst onlyAllowsImages = () => {\n\t\tif ( ! allowedTypes || allowedTypes.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn allowedTypes.every(\n\t\t\t( allowedType ) =>\n\t\t\t\tallowedType === 'image' || allowedType.startsWith( 'image/' )\n\t\t);\n\t};\n\n\tconst onChangeSrc = ( event ) => {\n\t\tsetSrc( event.target.value );\n\t};\n\n\tconst openURLInput = () => {\n\t\tsetIsURLInputVisible( true );\n\t};\n\tconst closeURLInput = () => {\n\t\tsetIsURLInputVisible( false );\n\t};\n\n\tconst onSubmitSrc = ( event ) => {\n\t\tevent.preventDefault();\n\t\tif ( src && onSelectURL ) {\n\t\t\tonSelectURL( src );\n\t\t\tcloseURLInput();\n\t\t}\n\t};\n\n\tconst onFilesUpload = ( files ) => {\n\t\tif ( ! handleUpload ) {\n\t\t\treturn onSelect( files );\n\t\t}\n\t\tonFilesPreUpload( files );\n\t\tlet setMedia;\n\t\tif ( multiple ) {\n\t\t\tif ( addToGallery ) {\n\t\t\t\t// Since the setMedia function runs multiple times per upload group\n\t\t\t\t// and is passed newMedia containing every item in its group each time, we must\n\t\t\t\t// filter out whatever this upload group had previously returned to the\n\t\t\t\t// gallery before adding and returning the image array with replacement newMedia\n\t\t\t\t// values.\n\n\t\t\t\t// Define an array to store urls from newMedia between subsequent function calls.\n\t\t\t\tlet lastMediaPassed = [];\n\t\t\t\tsetMedia = ( newMedia ) => {\n\t\t\t\t\t// Remove any images this upload group is responsible for (lastMediaPassed).\n\t\t\t\t\t// Their replacements are contained in newMedia.\n\t\t\t\t\tconst filteredMedia = ( value ?? [] ).filter( ( item ) => {\n\t\t\t\t\t\t// If Item has id, only remove it if lastMediaPassed has an item with that id.\n\t\t\t\t\t\tif ( item.id ) {\n\t\t\t\t\t\t\treturn ! lastMediaPassed.some(\n\t\t\t\t\t\t\t\t// Be sure to convert to number for comparison.\n\t\t\t\t\t\t\t\t( { id } ) => Number( id ) === Number( item.id )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Compare transient images via .includes since gallery may append extra info onto the url.\n\t\t\t\t\t\treturn ! lastMediaPassed.some( ( { urlSlug } ) =>\n\t\t\t\t\t\t\titem.url.includes( urlSlug )\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t\t// Return the filtered media array along with newMedia.\n\t\t\t\t\tonSelect( filteredMedia.concat( newMedia ) );\n\t\t\t\t\t// Reset lastMediaPassed and set it with ids and urls from newMedia.\n\t\t\t\t\tlastMediaPassed = newMedia.map( ( media ) => {\n\t\t\t\t\t\t// Add everything up to '.fileType' to compare via .includes.\n\t\t\t\t\t\tconst cutOffIndex = media.url.lastIndexOf( '.' );\n\t\t\t\t\t\tconst urlSlug = media.url.slice( 0, cutOffIndex );\n\t\t\t\t\t\treturn { id: media.id, urlSlug };\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tsetMedia = onSelect;\n\t\t\t}\n\t\t} else {\n\t\t\tsetMedia = ( [ media ] ) => onSelect( media );\n\t\t}\n\t\tmediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tfilesList: files,\n\t\t\tonFileChange: setMedia,\n\t\t\tonError,\n\t\t} );\n\t};\n\n\tconst onUpload = ( event ) => {\n\t\tonFilesUpload( event.target.files );\n\t};\n\n\tconst defaultRenderPlaceholder = ( content ) => {\n\t\tlet { instructions, title } = labels;\n\n\t\tif ( ! mediaUpload && ! onSelectURL ) {\n\t\t\tinstructions = __(\n\t\t\t\t'To edit this block, you need permission to upload media.'\n\t\t\t);\n\t\t}\n\n\t\tif ( instructions === undefined || title === undefined ) {\n\t\t\tconst typesAllowed = allowedTypes ?? [];\n\n\t\t\tconst [ firstAllowedType ] = typesAllowed;\n\t\t\tconst isOneType = 1 === typesAllowed.length;\n\t\t\tconst isAudio = isOneType && 'audio' === firstAllowedType;\n\t\t\tconst isImage = isOneType && 'image' === firstAllowedType;\n\t\t\tconst isVideo = isOneType && 'video' === firstAllowedType;\n\n\t\t\tif ( instructions === undefined && mediaUpload ) {\n\t\t\t\tinstructions = __(\n\t\t\t\t\t'Upload a media file or pick one from your media library.'\n\t\t\t\t);\n\n\t\t\t\tif ( isAudio ) {\n\t\t\t\t\tinstructions = __(\n\t\t\t\t\t\t'Upload an audio file, pick one from your media library, or add one with a URL.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( isImage ) {\n\t\t\t\t\tinstructions = __(\n\t\t\t\t\t\t'Upload an image file, pick one from your media library, or add one with a URL.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( isVideo ) {\n\t\t\t\t\tinstructions = __(\n\t\t\t\t\t\t'Upload a video file, pick one from your media library, or add one with a URL.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( title === undefined ) {\n\t\t\t\ttitle = __( 'Media' );\n\n\t\t\t\tif ( isAudio ) {\n\t\t\t\t\ttitle = __( 'Audio' );\n\t\t\t\t} else if ( isImage ) {\n\t\t\t\t\ttitle = __( 'Image' );\n\t\t\t\t} else if ( isVideo ) {\n\t\t\t\t\ttitle = __( 'Video' );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst placeholderClassName = classnames(\n\t\t\t'block-editor-media-placeholder',\n\t\t\tclassName,\n\t\t\t{\n\t\t\t\t'is-appender': isAppender,\n\t\t\t}\n\t\t);\n\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ title }\n\t\t\t\tinstructions={ instructions }\n\t\t\t\tclassName={ placeholderClassName }\n\t\t\t\tnotices={ notices }\n\t\t\t\tonDoubleClick={ onDoubleClick }\n\t\t\t\tpreview={ mediaPreview }\n\t\t\t\tstyle={ style }\n\t\t\t>\n\t\t\t\t{ content }\n\t\t\t\t{ children }\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\tconst renderPlaceholder = placeholder ?? defaultRenderPlaceholder;\n\n\tconst renderDropZone = () => {\n\t\tif ( disableDropZone ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn (\n\t\t\t<DropZone onFilesDrop={ onFilesUpload } onHTMLDrop={ onHTMLDrop } />\n\t\t);\n\t};\n\n\tconst renderCancelLink = () => {\n\t\treturn (\n\t\t\tonCancel && (\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"block-editor-media-placeholder__cancel-button\"\n\t\t\t\t\ttitle={ __( 'Cancel' ) }\n\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</Button>\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderUrlSelectionUI = () => {\n\t\treturn (\n\t\t\tonSelectURL && (\n\t\t\t\t<div className=\"block-editor-media-placeholder__url-input-container\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclassName=\"block-editor-media-placeholder__button\"\n\t\t\t\t\t\tonClick={ openURLInput }\n\t\t\t\t\t\tisPressed={ isURLInputVisible }\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Insert from URL' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t{ isURLInputVisible && (\n\t\t\t\t\t\t<InsertFromURLPopover\n\t\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\t\tonChange={ onChangeSrc }\n\t\t\t\t\t\t\tonSubmit={ onSubmitSrc }\n\t\t\t\t\t\t\tonClose={ closeURLInput }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderMediaUploadChecked = () => {\n\t\tconst defaultButton = ( { open } ) => {\n\t\t\treturn (\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\topen();\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Media Library' ) }\n\t\t\t\t</Button>\n\t\t\t);\n\t\t};\n\t\tconst libraryButton = mediaLibraryButton ?? defaultButton;\n\t\tconst uploadMediaLibraryButton = (\n\t\t\t<MediaUpload\n\t\t\t\taddToGallery={ addToGallery }\n\t\t\t\tgallery={ multiple && onlyAllowsImages() }\n\t\t\t\tmultiple={ multiple }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tonClose={ onClose }\n\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\tvalue={\n\t\t\t\t\tArray.isArray( value )\n\t\t\t\t\t\t? value.map( ( { id } ) => id )\n\t\t\t\t\t\t: value.id\n\t\t\t\t}\n\t\t\t\trender={ libraryButton }\n\t\t\t/>\n\t\t);\n\n\t\tif ( mediaUpload && isAppender ) {\n\t\t\treturn (\n\t\t\t\t<>\n\t\t\t\t\t{ renderDropZone() }\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\tonChange={ onUpload }\n\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t\trender={ ( { openFileDialog } ) => {\n\t\t\t\t\t\t\tconst content = (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t\t\t'block-editor-media-placeholder__button',\n\t\t\t\t\t\t\t\t\t\t\t'block-editor-media-placeholder__upload-button'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t{ uploadMediaLibraryButton }\n\t\t\t\t\t\t\t\t\t{ renderUrlSelectionUI() }\n\t\t\t\t\t\t\t\t\t{ renderCancelLink() }\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 renderPlaceholder( content );\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\n\t\tif ( mediaUpload ) {\n\t\t\tconst content = (\n\t\t\t\t<>\n\t\t\t\t\t{ renderDropZone() }\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-media-placeholder__button',\n\t\t\t\t\t\t\t'block-editor-media-placeholder__upload-button'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tonChange={ onUpload }\n\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t</FormFileUpload>\n\t\t\t\t\t{ uploadMediaLibraryButton }\n\t\t\t\t\t{ renderUrlSelectionUI() }\n\t\t\t\t\t{ renderCancelLink() }\n\t\t\t\t</>\n\t\t\t);\n\t\t\treturn renderPlaceholder( content );\n\t\t}\n\n\t\treturn renderPlaceholder( uploadMediaLibraryButton );\n\t};\n\n\tif ( dropZoneUIOnly || disableMediaButtons ) {\n\t\tif ( dropZoneUIOnly ) {\n\t\t\tdeprecated( 'wp.blockEditor.MediaPlaceholder dropZoneUIOnly prop', {\n\t\t\t\tsince: '5.4',\n\t\t\t\talternative: 'disableMediaButtons',\n\t\t\t} );\n\t\t}\n\n\t\treturn <MediaUploadCheck>{ renderDropZone() }</MediaUploadCheck>;\n\t}\n\n\treturn (\n\t\t<MediaUploadCheck\n\t\t\tfallback={ renderPlaceholder( renderUrlSelectionUI() ) }\n\t\t>\n\t\t\t{ renderMediaUploadChecked() }\n\t\t</MediaUploadCheck>\n\t);\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/media-placeholder/README.md\n */\nexport default withFilters( 'editor.MediaPlaceholder' )( MediaPlaceholder );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/media-placeholder/index.js"],"names":["InsertFromURLPopover","src","onChange","onSubmit","onClose","keyboardReturn","MediaPlaceholder","value","allowedTypes","className","icon","labels","mediaPreview","notices","isAppender","accept","addToGallery","multiple","handleUpload","dropZoneUIOnly","disableDropZone","disableMediaButtons","onError","onSelect","onCancel","onSelectURL","onDoubleClick","onFilesPreUpload","noop","onHTMLDrop","children","mediaLibraryButton","placeholder","style","mediaUpload","select","getSettings","blockEditorStore","setSrc","isURLInputVisible","setIsURLInputVisible","onlyAllowsImages","length","every","allowedType","startsWith","onChangeSrc","event","target","openURLInput","closeURLInput","onSubmitSrc","preventDefault","onFilesUpload","files","setMedia","lastMediaPassed","newMedia","filteredMedia","filter","item","id","some","Number","urlSlug","url","includes","concat","map","media","cutOffIndex","lastIndexOf","slice","filesList","onFileChange","onUpload","defaultRenderPlaceholder","content","instructions","title","undefined","typesAllowed","firstAllowedType","isOneType","isAudio","isImage","isVideo","placeholderClassName","renderPlaceholder","renderDropZone","renderCancelLink","renderUrlSelectionUI","renderMediaUploadChecked","defaultButton","open","libraryButton","uploadMediaLibraryButton","Array","isArray","openFileDialog","since","alternative"],"mappings":";;;;;;;;;;AAiBA;;AAdA;;AACA;;AAKA;;AAOA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAIA;AACA;AACA;;AAcA;AACA;AACA;AAMA,MAAMA,oBAAoB,GAAG;AAAA,MAAE;AAAEC,IA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K3C,WAAL,EAAmB;AAClB,YAAM2C,OAAO,GACZ,qDACGY,cAAc,EADjB,EAEC,4BAAC,0BAAD;AACC,QAAA,OAAO,EAAC,SADT;AAEC,QAAA,SAAS,EAAG,yBACX,wCADW,EAEX,+CAFW,CAFb;AAMC,QAAA,QAAQ,EAAGd,QANZ;AAOC,QAAA,MAAM,EAAG5D,MAPV;AAQC,QAAA,QAAQ,EAAGE;AARZ,SAUG,cAAI,QAAJ,CAVH,CAFD,EAcG+E,wBAdH,EAeGL,oBAAoB,EAfvB,EAgBGD,gBAAgB,EAhBnB,CADD;AAoBA,aAAOF,iBAAiB,CAAEX,OAAF,CAAxB;AACA;;AAED,WAAOW,iBAAiB,CAAEQ,wBAAF,CAAxB;AACA,GAxFD;;AA0FA,MAAK7E,cAAc,IAAIE,mBAAvB,EAA6C;AAC5C,QAAKF,cAAL,EAAsB;AACrB,+BAAY,qDAAZ,EAAmE;AAClEiF,QAAAA,KAAK,EAAE,KAD2D;AAElEC,QAAAA,WAAW,EAAE;AAFqD,OAAnE;AAIA;;AAED,WAAO,4BAAC,cAAD,QAAoBZ,cAAc,EAAlC,CAAP;AACA;;AAED,SACC,4BAAC,cAAD;AACC,IAAA,QAAQ,EAAGD,iBAAiB,CAAEG,oBAAoB,EAAtB;AAD7B,KAGGC,wBAAwB,EAH3B,CADD;AAOA;AAED;AACA;AACA;;;eACe,6BAAa,yBAAb,EAA0CtF,gBAA1C,C","sourcesContent":["/**\n * External dependencies\n */\nimport { noop } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tFormFileUpload,\n\tPlaceholder,\n\tDropZone,\n\twithFilters,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { keyboardReturn } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport MediaUpload from '../media-upload';\nimport MediaUploadCheck from '../media-upload/check';\nimport URLPopover from '../url-popover';\nimport { store as blockEditorStore } from '../../store';\n\nconst InsertFromURLPopover = ( { src, onChange, onSubmit, onClose } ) => (\n\t<URLPopover onClose={ onClose }>\n\t\t<form\n\t\t\tclassName=\"block-editor-media-placeholder__url-input-form\"\n\t\t\tonSubmit={ onSubmit }\n\t\t>\n\t\t\t<input\n\t\t\t\tclassName=\"block-editor-media-placeholder__url-input-field\"\n\t\t\t\ttype=\"text\"\n\t\t\t\taria-label={ __( 'URL' ) }\n\t\t\t\tplaceholder={ __( 'Paste or type URL' ) }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tvalue={ src }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tclassName=\"block-editor-media-placeholder__url-input-submit-button\"\n\t\t\t\ticon={ keyboardReturn }\n\t\t\t\tlabel={ __( 'Apply' ) }\n\t\t\t\ttype=\"submit\"\n\t\t\t/>\n\t\t</form>\n\t</URLPopover>\n);\n\nexport function MediaPlaceholder( {\n\tvalue = {},\n\tallowedTypes,\n\tclassName,\n\ticon,\n\tlabels = {},\n\tmediaPreview,\n\tnotices,\n\tisAppender,\n\taccept,\n\taddToGallery,\n\tmultiple = false,\n\thandleUpload = true,\n\tdropZoneUIOnly,\n\tdisableDropZone,\n\tdisableMediaButtons,\n\tonError,\n\tonSelect,\n\tonCancel,\n\tonSelectURL,\n\tonDoubleClick,\n\tonFilesPreUpload = noop,\n\tonHTMLDrop = noop,\n\tchildren,\n\tmediaLibraryButton,\n\tplaceholder,\n\tstyle,\n} ) {\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().mediaUpload;\n\t}, [] );\n\tconst [ src, setSrc ] = useState( '' );\n\tconst [ isURLInputVisible, setIsURLInputVisible ] = useState( false );\n\n\tuseEffect( () => {\n\t\tsetSrc( value?.src ?? '' );\n\t}, [ value?.src ] );\n\n\tconst onlyAllowsImages = () => {\n\t\tif ( ! allowedTypes || allowedTypes.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn allowedTypes.every(\n\t\t\t( allowedType ) =>\n\t\t\t\tallowedType === 'image' || allowedType.startsWith( 'image/' )\n\t\t);\n\t};\n\n\tconst onChangeSrc = ( event ) => {\n\t\tsetSrc( event.target.value );\n\t};\n\n\tconst openURLInput = () => {\n\t\tsetIsURLInputVisible( true );\n\t};\n\tconst closeURLInput = () => {\n\t\tsetIsURLInputVisible( false );\n\t};\n\n\tconst onSubmitSrc = ( event ) => {\n\t\tevent.preventDefault();\n\t\tif ( src && onSelectURL ) {\n\t\t\tonSelectURL( src );\n\t\t\tcloseURLInput();\n\t\t}\n\t};\n\n\tconst onFilesUpload = ( files ) => {\n\t\tif ( ! handleUpload ) {\n\t\t\treturn onSelect( files );\n\t\t}\n\t\tonFilesPreUpload( files );\n\t\tlet setMedia;\n\t\tif ( multiple ) {\n\t\t\tif ( addToGallery ) {\n\t\t\t\t// Since the setMedia function runs multiple times per upload group\n\t\t\t\t// and is passed newMedia containing every item in its group each time, we must\n\t\t\t\t// filter out whatever this upload group had previously returned to the\n\t\t\t\t// gallery before adding and returning the image array with replacement newMedia\n\t\t\t\t// values.\n\n\t\t\t\t// Define an array to store urls from newMedia between subsequent function calls.\n\t\t\t\tlet lastMediaPassed = [];\n\t\t\t\tsetMedia = ( newMedia ) => {\n\t\t\t\t\t// Remove any images this upload group is responsible for (lastMediaPassed).\n\t\t\t\t\t// Their replacements are contained in newMedia.\n\t\t\t\t\tconst filteredMedia = ( value ?? [] ).filter( ( item ) => {\n\t\t\t\t\t\t// If Item has id, only remove it if lastMediaPassed has an item with that id.\n\t\t\t\t\t\tif ( item.id ) {\n\t\t\t\t\t\t\treturn ! lastMediaPassed.some(\n\t\t\t\t\t\t\t\t// Be sure to convert to number for comparison.\n\t\t\t\t\t\t\t\t( { id } ) => Number( id ) === Number( item.id )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Compare transient images via .includes since gallery may append extra info onto the url.\n\t\t\t\t\t\treturn ! lastMediaPassed.some( ( { urlSlug } ) =>\n\t\t\t\t\t\t\titem.url.includes( urlSlug )\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t\t// Return the filtered media array along with newMedia.\n\t\t\t\t\tonSelect( filteredMedia.concat( newMedia ) );\n\t\t\t\t\t// Reset lastMediaPassed and set it with ids and urls from newMedia.\n\t\t\t\t\tlastMediaPassed = newMedia.map( ( media ) => {\n\t\t\t\t\t\t// Add everything up to '.fileType' to compare via .includes.\n\t\t\t\t\t\tconst cutOffIndex = media.url.lastIndexOf( '.' );\n\t\t\t\t\t\tconst urlSlug = media.url.slice( 0, cutOffIndex );\n\t\t\t\t\t\treturn { id: media.id, urlSlug };\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tsetMedia = onSelect;\n\t\t\t}\n\t\t} else {\n\t\t\tsetMedia = ( [ media ] ) => onSelect( media );\n\t\t}\n\t\tmediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tfilesList: files,\n\t\t\tonFileChange: setMedia,\n\t\t\tonError,\n\t\t} );\n\t};\n\n\tconst onUpload = ( event ) => {\n\t\tonFilesUpload( event.target.files );\n\t};\n\n\tconst defaultRenderPlaceholder = ( content ) => {\n\t\tlet { instructions, title } = labels;\n\n\t\tif ( ! mediaUpload && ! onSelectURL ) {\n\t\t\tinstructions = __(\n\t\t\t\t'To edit this block, you need permission to upload media.'\n\t\t\t);\n\t\t}\n\n\t\tif ( instructions === undefined || title === undefined ) {\n\t\t\tconst typesAllowed = allowedTypes ?? [];\n\n\t\t\tconst [ firstAllowedType ] = typesAllowed;\n\t\t\tconst isOneType = 1 === typesAllowed.length;\n\t\t\tconst isAudio = isOneType && 'audio' === firstAllowedType;\n\t\t\tconst isImage = isOneType && 'image' === firstAllowedType;\n\t\t\tconst isVideo = isOneType && 'video' === firstAllowedType;\n\n\t\t\tif ( instructions === undefined && mediaUpload ) {\n\t\t\t\tinstructions = __(\n\t\t\t\t\t'Upload a media file or pick one from your media library.'\n\t\t\t\t);\n\n\t\t\t\tif ( isAudio ) {\n\t\t\t\t\tinstructions = __(\n\t\t\t\t\t\t'Upload an audio file, pick one from your media library, or add one with a URL.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( isImage ) {\n\t\t\t\t\tinstructions = __(\n\t\t\t\t\t\t'Upload an image file, pick one from your media library, or add one with a URL.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( isVideo ) {\n\t\t\t\t\tinstructions = __(\n\t\t\t\t\t\t'Upload a video file, pick one from your media library, or add one with a URL.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( title === undefined ) {\n\t\t\t\ttitle = __( 'Media' );\n\n\t\t\t\tif ( isAudio ) {\n\t\t\t\t\ttitle = __( 'Audio' );\n\t\t\t\t} else if ( isImage ) {\n\t\t\t\t\ttitle = __( 'Image' );\n\t\t\t\t} else if ( isVideo ) {\n\t\t\t\t\ttitle = __( 'Video' );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst placeholderClassName = classnames(\n\t\t\t'block-editor-media-placeholder',\n\t\t\tclassName,\n\t\t\t{\n\t\t\t\t'is-appender': isAppender,\n\t\t\t}\n\t\t);\n\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ title }\n\t\t\t\tinstructions={ instructions }\n\t\t\t\tclassName={ placeholderClassName }\n\t\t\t\tnotices={ notices }\n\t\t\t\tonDoubleClick={ onDoubleClick }\n\t\t\t\tpreview={ mediaPreview }\n\t\t\t\tstyle={ style }\n\t\t\t>\n\t\t\t\t{ content }\n\t\t\t\t{ children }\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\tconst renderPlaceholder = placeholder ?? defaultRenderPlaceholder;\n\n\tconst renderDropZone = () => {\n\t\tif ( disableDropZone ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn (\n\t\t\t<DropZone onFilesDrop={ onFilesUpload } onHTMLDrop={ onHTMLDrop } />\n\t\t);\n\t};\n\n\tconst renderCancelLink = () => {\n\t\treturn (\n\t\t\tonCancel && (\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"block-editor-media-placeholder__cancel-button\"\n\t\t\t\t\ttitle={ __( 'Cancel' ) }\n\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</Button>\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderUrlSelectionUI = () => {\n\t\treturn (\n\t\t\tonSelectURL && (\n\t\t\t\t<div className=\"block-editor-media-placeholder__url-input-container\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclassName=\"block-editor-media-placeholder__button\"\n\t\t\t\t\t\tonClick={ openURLInput }\n\t\t\t\t\t\tisPressed={ isURLInputVisible }\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Insert from URL' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t{ isURLInputVisible && (\n\t\t\t\t\t\t<InsertFromURLPopover\n\t\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\t\tonChange={ onChangeSrc }\n\t\t\t\t\t\t\tonSubmit={ onSubmitSrc }\n\t\t\t\t\t\t\tonClose={ closeURLInput }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderMediaUploadChecked = () => {\n\t\tconst defaultButton = ( { open } ) => {\n\t\t\treturn (\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\topen();\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Media Library' ) }\n\t\t\t\t</Button>\n\t\t\t);\n\t\t};\n\t\tconst libraryButton = mediaLibraryButton ?? defaultButton;\n\t\tconst uploadMediaLibraryButton = (\n\t\t\t<MediaUpload\n\t\t\t\taddToGallery={ addToGallery }\n\t\t\t\tgallery={ multiple && onlyAllowsImages() }\n\t\t\t\tmultiple={ multiple }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\tvalue={\n\t\t\t\t\tArray.isArray( value )\n\t\t\t\t\t\t? value.map( ( { id } ) => id )\n\t\t\t\t\t\t: value.id\n\t\t\t\t}\n\t\t\t\trender={ libraryButton }\n\t\t\t/>\n\t\t);\n\n\t\tif ( mediaUpload && isAppender ) {\n\t\t\treturn (\n\t\t\t\t<>\n\t\t\t\t\t{ renderDropZone() }\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\tonChange={ onUpload }\n\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t\trender={ ( { openFileDialog } ) => {\n\t\t\t\t\t\t\tconst content = (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t\t\t'block-editor-media-placeholder__button',\n\t\t\t\t\t\t\t\t\t\t\t'block-editor-media-placeholder__upload-button'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t{ uploadMediaLibraryButton }\n\t\t\t\t\t\t\t\t\t{ renderUrlSelectionUI() }\n\t\t\t\t\t\t\t\t\t{ renderCancelLink() }\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 renderPlaceholder( content );\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\n\t\tif ( mediaUpload ) {\n\t\t\tconst content = (\n\t\t\t\t<>\n\t\t\t\t\t{ renderDropZone() }\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-media-placeholder__button',\n\t\t\t\t\t\t\t'block-editor-media-placeholder__upload-button'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tonChange={ onUpload }\n\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t</FormFileUpload>\n\t\t\t\t\t{ uploadMediaLibraryButton }\n\t\t\t\t\t{ renderUrlSelectionUI() }\n\t\t\t\t\t{ renderCancelLink() }\n\t\t\t\t</>\n\t\t\t);\n\t\t\treturn renderPlaceholder( content );\n\t\t}\n\n\t\treturn renderPlaceholder( uploadMediaLibraryButton );\n\t};\n\n\tif ( dropZoneUIOnly || disableMediaButtons ) {\n\t\tif ( dropZoneUIOnly ) {\n\t\t\tdeprecated( 'wp.blockEditor.MediaPlaceholder dropZoneUIOnly prop', {\n\t\t\t\tsince: '5.4',\n\t\t\t\talternative: 'disableMediaButtons',\n\t\t\t} );\n\t\t}\n\n\t\treturn <MediaUploadCheck>{ renderDropZone() }</MediaUploadCheck>;\n\t}\n\n\treturn (\n\t\t<MediaUploadCheck\n\t\t\tfallback={ renderPlaceholder( renderUrlSelectionUI() ) }\n\t\t>\n\t\t\t{ renderMediaUploadChecked() }\n\t\t</MediaUploadCheck>\n\t);\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/media-placeholder/README.md\n */\nexport default withFilters( 'editor.MediaPlaceholder' )( MediaPlaceholder );\n"]}
|
|
@@ -55,7 +55,6 @@ const MediaReplaceFlow = _ref => {
|
|
|
55
55
|
onSelect,
|
|
56
56
|
onSelectURL,
|
|
57
57
|
onFilesUpload = _lodash.noop,
|
|
58
|
-
onCloseModal = _lodash.noop,
|
|
59
58
|
name = (0, _i18n.__)('Replace'),
|
|
60
59
|
createNotice,
|
|
61
60
|
removeNotice,
|
|
@@ -156,7 +155,6 @@ const MediaReplaceFlow = _ref => {
|
|
|
156
155
|
value: mediaId,
|
|
157
156
|
onSelect: media => selectMedia(media),
|
|
158
157
|
allowedTypes: allowedTypes,
|
|
159
|
-
onClose: onCloseModal,
|
|
160
158
|
render: _ref5 => {
|
|
161
159
|
let {
|
|
162
160
|
open
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/media-replace-flow/index.js"],"names":["MediaReplaceFlow","mediaURL","mediaId","allowedTypes","accept","onSelect","onSelectURL","onFilesUpload","noop","onCloseModal","name","createNotice","removeNotice","children","mediaURLValue","setMediaURLValue","mediaUpload","select","blockEditorStore","getSettings","editMediaButtonRef","errorNoticeID","onError","message","errorElement","document","createElement","innerHTML","renderMsg","textContent","innerText","setTimeout","speak","id","isDismissible","selectMedia","media","url","selectURL","newURL","uploadFiles","event","files","target","setMedia","filesList","onFileChange","openOnArrowDown","keyCode","DOWN","preventDefault","click","POPOVER_PROPS","isAlternate","isOpen","onToggle","onClose","open","mediaIcon","openFileDialog","upload","current","focus","dispatch","noticesStore"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAkBA;AACA;AACA;AAMA,MAAMA,gBAAgB,GAAG,QAalB;AAAA,MAboB;AAC1BC,IAAAA,QAD0B;AAE1BC,IAAAA,OAF0B;AAG1BC,IAAAA,YAH0B;AAI1BC,IAAAA,MAJ0B;AAK1BC,IAAAA,QAL0B;AAM1BC,IAAAA,WAN0B;AAO1BC,IAAAA,aAAa,GAAGC,YAPU;AAQ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gBAAgB,CAAEsB,GAAF,CAAhB;AACAC,UAAAA,SAAS,CAAED,GAAF,CAAT;AACAjB,UAAAA,kBAAkB,CAACyC,OAAnB,CAA2BC,KAA3B;AACA;AARF,QAJD,CArCF,CADe;AAAA;AAdjB,IADD;AAyEA,CA7JD;;eA+Je,sBAAS,CACvB,wBAAgBC,QAAF,IAAgB;AAC7B,QAAM;AAAEpD,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAiCmD,QAAQ,CAAEC,cAAF,CAA/C;AACA,SAAO;AACNrD,IAAAA,YADM;AAENC,IAAAA;AAFM,GAAP;AAIA,CAND,CADuB,EAQvB,6BAAa,yBAAb,CARuB,CAAT,EASVZ,gBATU,C","sourcesContent":["/**\n * External dependencies\n */\nimport { uniqueId, noop } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState, createRef, renderToString } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport {\n\tFormFileUpload,\n\tNavigableMenu,\n\tMenuItem,\n\tToolbarButton,\n\tDropdown,\n\twithFilters,\n} from '@wordpress/components';\nimport { withDispatch, useSelect } from '@wordpress/data';\nimport { DOWN } from '@wordpress/keycodes';\nimport { compose } from '@wordpress/compose';\nimport { upload, media as mediaIcon } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport MediaUpload from '../media-upload';\nimport MediaUploadCheck from '../media-upload/check';\nimport LinkControl from '../link-control';\nimport { store as blockEditorStore } from '../../store';\n\nconst MediaReplaceFlow = ( {\n\tmediaURL,\n\tmediaId,\n\tallowedTypes,\n\taccept,\n\tonSelect,\n\tonSelectURL,\n\tonFilesUpload = noop,\n\tonCloseModal = noop,\n\tname = __( 'Replace' ),\n\tcreateNotice,\n\tremoveNotice,\n\tchildren,\n} ) => {\n\tconst [ mediaURLValue, setMediaURLValue ] = useState( mediaURL );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst editMediaButtonRef = createRef();\n\tconst errorNoticeID = uniqueId(\n\t\t'block-editor/media-replace-flow/error-notice/'\n\t);\n\n\tconst onError = ( message ) => {\n\t\tconst errorElement = document.createElement( 'div' );\n\t\terrorElement.innerHTML = renderToString( message );\n\t\t// The default error contains some HTML that,\n\t\t// for example, makes the filename bold.\n\t\t// The notice, by default, accepts strings only and so\n\t\t// we need to remove the html from the error.\n\t\tconst renderMsg =\n\t\t\terrorElement.textContent || errorElement.innerText || '';\n\t\t// We need to set a timeout for showing the notice\n\t\t// so that VoiceOver and possibly other screen readers\n\t\t// can announce the error afer the toolbar button\n\t\t// regains focus once the upload dialog closes.\n\t\t// Otherwise VO simply skips over the notice and announces\n\t\t// the focused element and the open menu.\n\t\tsetTimeout( () => {\n\t\t\tcreateNotice( 'error', renderMsg, {\n\t\t\t\tspeak: true,\n\t\t\t\tid: errorNoticeID,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}, 1000 );\n\t};\n\n\tconst selectMedia = ( media ) => {\n\t\tsetMediaURLValue( media.url );\n\t\t// Calling `onSelect` after the state update since it might unmount the component.\n\t\tonSelect( media );\n\t\tspeak( __( 'The media file has been replaced' ) );\n\t\tremoveNotice( errorNoticeID );\n\t};\n\n\tconst selectURL = ( newURL ) => {\n\t\tonSelectURL( newURL );\n\t};\n\n\tconst uploadFiles = ( event ) => {\n\t\tconst files = event.target.files;\n\t\tonFilesUpload( files );\n\t\tconst setMedia = ( [ media ] ) => {\n\t\t\tselectMedia( media );\n\t\t};\n\t\tmediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tfilesList: files,\n\t\t\tonFileChange: setMedia,\n\t\t\tonError,\n\t\t} );\n\t};\n\n\tconst openOnArrowDown = ( event ) => {\n\t\tif ( event.keyCode === DOWN ) {\n\t\t\tevent.preventDefault();\n\t\t\tevent.target.click();\n\t\t}\n\t};\n\n\tconst POPOVER_PROPS = {\n\t\tisAlternate: true,\n\t};\n\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tcontentClassName=\"block-editor-media-replace-flow__options\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tref={ editMediaButtonRef }\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tonKeyDown={ openOnArrowDown }\n\t\t\t\t>\n\t\t\t\t\t{ name }\n\t\t\t\t</ToolbarButton>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<NavigableMenu className=\"block-editor-media-replace-flow__media-upload-menu\">\n\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\tvalue={ mediaId }\n\t\t\t\t\t\t\tonSelect={ ( media ) => selectMedia( media ) }\n\t\t\t\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\t\t\t\tonClose={ onCloseModal }\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<MenuItem icon={ mediaIcon } onClick={ open }>\n\t\t\t\t\t\t\t\t\t{ __( 'Open Media Library' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\t\t\tonChange={ ( event ) => {\n\t\t\t\t\t\t\t\t\tuploadFiles( event, onClose );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\t\t\trender={ ( { openFileDialog } ) => {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\ticon={ upload }\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\topenFileDialog();\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\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</MediaUploadCheck>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t{ onSelectURL && (\n\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n\t\t\t\t\t\t<form className=\"block-editor-media-flow__url-input\">\n\t\t\t\t\t\t\t<span className=\"block-editor-media-replace-flow__image-url-label\">\n\t\t\t\t\t\t\t\t{ __( 'Current media URL:' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<LinkControl\n\t\t\t\t\t\t\t\tvalue={ { url: mediaURLValue } }\n\t\t\t\t\t\t\t\tsettings={ [] }\n\t\t\t\t\t\t\t\tshowSuggestions={ false }\n\t\t\t\t\t\t\t\tonChange={ ( { url } ) => {\n\t\t\t\t\t\t\t\t\tsetMediaURLValue( url );\n\t\t\t\t\t\t\t\t\tselectURL( url );\n\t\t\t\t\t\t\t\t\teditMediaButtonRef.current.focus();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t/>\n\t);\n};\n\nexport default compose( [\n\twithDispatch( ( dispatch ) => {\n\t\tconst { createNotice, removeNotice } = dispatch( noticesStore );\n\t\treturn {\n\t\t\tcreateNotice,\n\t\t\tremoveNotice,\n\t\t};\n\t} ),\n\twithFilters( 'editor.MediaReplaceFlow' ),\n] )( MediaReplaceFlow );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/media-replace-flow/index.js"],"names":["MediaReplaceFlow","mediaURL","mediaId","allowedTypes","accept","onSelect","onSelectURL","onFilesUpload","noop","name","createNotice","removeNotice","children","mediaURLValue","setMediaURLValue","mediaUpload","select","blockEditorStore","getSettings","editMediaButtonRef","errorNoticeID","onError","message","errorElement","document","createElement","innerHTML","renderMsg","textContent","innerText","setTimeout","speak","id","isDismissible","selectMedia","media","url","selectURL","newURL","uploadFiles","event","files","target","setMedia","filesList","onFileChange","openOnArrowDown","keyCode","DOWN","preventDefault","click","POPOVER_PROPS","isAlternate","isOpen","onToggle","onClose","open","mediaIcon","openFileDialog","upload","current","focus","dispatch","noticesStore"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAkBA;AACA;AACA;AAMA,MAAMA,gBAAgB,GAAG,QAYlB;AAAA,MAZoB;AAC1BC,IAAAA,QAD0B;AAE1BC,IAAAA,OAF0B;AAG1BC,IAAAA,YAH0B;AAI1BC,IAAAA,MAJ0B;AAK1BC,IAAAA,QAL0B;AAM1BC,IAAAA,WAN0B;AAO1BC,IAAAA,aAAa,GAAGC,YAPU;AAQ1BC,IAAAA,IAAI,GAAG,cAAI,SAAJ,CARmB;AAS1BC,IAAAA,YAT0B;AAU1BC,IAAAA,YAV0B;AAW1BC,IAAAA;AAX0B,GAYpB;AACN,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,uBAAUb,QAAV,CAA5C;AACA,QAAMc,WAAW,GAAG,qBAAaC,MAAF,IAAc;AAC5C,WAAOA,MAAM,CAAEC,YAAF,CAAN,CAA2BC,WAA3B,GAAyCH,WAAhD;AACA,GAFmB,EAEjB,EAFiB,CAApB;AAGA,QAAMI,kBAAkB,GAAG,yBAA3B;AACA,QAAMC,aAAa,GAAG,sBACrB,+CADqB,CAAtB;;AAIA,QAAMC,OAAO,GAAKC,OAAF,IAAe;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,UAAAA,WAAW,CAAEC,KAAF,EAASe,OAAT,CAAX;AACA,SAHF;AAIC,QAAA,MAAM,EAAGnD,MAJV;AAKC,QAAA,MAAM,EAAG,SAA0B;AAAA,cAAxB;AAAEsD,YAAAA;AAAF,WAAwB;AAClC,iBACC,4BAAC,oBAAD;AACC,YAAA,IAAI,EAAGC,aADR;AAEC,YAAA,OAAO,EAAG,MAAM;AACfD,cAAAA,cAAc;AACd;AAJF,aAMG,cAAI,QAAJ,CANH,CADD;AAUA;AAhBF,QADD,CAXD,EA+BG9C,QA/BH,CADD,EAkCGN,WAAW,IACZ;AACA;AAAM,QAAA,SAAS,EAAC;AAAhB,SACC;AAAM,QAAA,SAAS,EAAC;AAAhB,SACG,cAAI,oBAAJ,CADH,CADD,EAIC,4BAAC,oBAAD;AACC,QAAA,KAAK,EAAG;AAAE8B,UAAAA,GAAG,EAAEvB;AAAP,SADT;AAEC,QAAA,QAAQ,EAAG,EAFZ;AAGC,QAAA,eAAe,EAAG,KAHnB;AAIC,QAAA,QAAQ,EAAG,SAAe;AAAA,cAAb;AAAEuB,YAAAA;AAAF,WAAa;AACzBtB,UAAAA,gBAAgB,CAAEsB,GAAF,CAAhB;AACAC,UAAAA,SAAS,CAAED,GAAF,CAAT;AACAjB,UAAAA,kBAAkB,CAACyC,OAAnB,CAA2BC,KAA3B;AACA;AARF,QAJD,CApCF,CADe;AAAA;AAdjB,IADD;AAwEA,CA3JD;;eA6Je,sBAAS,CACvB,wBAAgBC,QAAF,IAAgB;AAC7B,QAAM;AAAEpD,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAiCmD,QAAQ,CAAEC,cAAF,CAA/C;AACA,SAAO;AACNrD,IAAAA,YADM;AAENC,IAAAA;AAFM,GAAP;AAIA,CAND,CADuB,EAQvB,6BAAa,yBAAb,CARuB,CAAT,EASVX,gBATU,C","sourcesContent":["/**\n * External dependencies\n */\nimport { uniqueId, noop } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState, createRef, renderToString } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport {\n\tFormFileUpload,\n\tNavigableMenu,\n\tMenuItem,\n\tToolbarButton,\n\tDropdown,\n\twithFilters,\n} from '@wordpress/components';\nimport { withDispatch, useSelect } from '@wordpress/data';\nimport { DOWN } from '@wordpress/keycodes';\nimport { compose } from '@wordpress/compose';\nimport { upload, media as mediaIcon } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport MediaUpload from '../media-upload';\nimport MediaUploadCheck from '../media-upload/check';\nimport LinkControl from '../link-control';\nimport { store as blockEditorStore } from '../../store';\n\nconst MediaReplaceFlow = ( {\n\tmediaURL,\n\tmediaId,\n\tallowedTypes,\n\taccept,\n\tonSelect,\n\tonSelectURL,\n\tonFilesUpload = noop,\n\tname = __( 'Replace' ),\n\tcreateNotice,\n\tremoveNotice,\n\tchildren,\n} ) => {\n\tconst [ mediaURLValue, setMediaURLValue ] = useState( mediaURL );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst editMediaButtonRef = createRef();\n\tconst errorNoticeID = uniqueId(\n\t\t'block-editor/media-replace-flow/error-notice/'\n\t);\n\n\tconst onError = ( message ) => {\n\t\tconst errorElement = document.createElement( 'div' );\n\t\terrorElement.innerHTML = renderToString( message );\n\t\t// The default error contains some HTML that,\n\t\t// for example, makes the filename bold.\n\t\t// The notice, by default, accepts strings only and so\n\t\t// we need to remove the html from the error.\n\t\tconst renderMsg =\n\t\t\terrorElement.textContent || errorElement.innerText || '';\n\t\t// We need to set a timeout for showing the notice\n\t\t// so that VoiceOver and possibly other screen readers\n\t\t// can announce the error afer the toolbar button\n\t\t// regains focus once the upload dialog closes.\n\t\t// Otherwise VO simply skips over the notice and announces\n\t\t// the focused element and the open menu.\n\t\tsetTimeout( () => {\n\t\t\tcreateNotice( 'error', renderMsg, {\n\t\t\t\tspeak: true,\n\t\t\t\tid: errorNoticeID,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}, 1000 );\n\t};\n\n\tconst selectMedia = ( media ) => {\n\t\tsetMediaURLValue( media.url );\n\t\t// Calling `onSelect` after the state update since it might unmount the component.\n\t\tonSelect( media );\n\t\tspeak( __( 'The media file has been replaced' ) );\n\t\tremoveNotice( errorNoticeID );\n\t};\n\n\tconst selectURL = ( newURL ) => {\n\t\tonSelectURL( newURL );\n\t};\n\n\tconst uploadFiles = ( event ) => {\n\t\tconst files = event.target.files;\n\t\tonFilesUpload( files );\n\t\tconst setMedia = ( [ media ] ) => {\n\t\t\tselectMedia( media );\n\t\t};\n\t\tmediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tfilesList: files,\n\t\t\tonFileChange: setMedia,\n\t\t\tonError,\n\t\t} );\n\t};\n\n\tconst openOnArrowDown = ( event ) => {\n\t\tif ( event.keyCode === DOWN ) {\n\t\t\tevent.preventDefault();\n\t\t\tevent.target.click();\n\t\t}\n\t};\n\n\tconst POPOVER_PROPS = {\n\t\tisAlternate: true,\n\t};\n\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tcontentClassName=\"block-editor-media-replace-flow__options\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tref={ editMediaButtonRef }\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tonKeyDown={ openOnArrowDown }\n\t\t\t\t>\n\t\t\t\t\t{ name }\n\t\t\t\t</ToolbarButton>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<NavigableMenu className=\"block-editor-media-replace-flow__media-upload-menu\">\n\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\tvalue={ mediaId }\n\t\t\t\t\t\t\tonSelect={ ( media ) => selectMedia( media ) }\n\t\t\t\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<MenuItem icon={ mediaIcon } onClick={ open }>\n\t\t\t\t\t\t\t\t\t{ __( 'Open Media Library' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\t\t\tonChange={ ( event ) => {\n\t\t\t\t\t\t\t\t\tuploadFiles( event, onClose );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\t\t\trender={ ( { openFileDialog } ) => {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\ticon={ upload }\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\topenFileDialog();\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\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</MediaUploadCheck>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t{ onSelectURL && (\n\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n\t\t\t\t\t\t<form className=\"block-editor-media-flow__url-input\">\n\t\t\t\t\t\t\t<span className=\"block-editor-media-replace-flow__image-url-label\">\n\t\t\t\t\t\t\t\t{ __( 'Current media URL:' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<LinkControl\n\t\t\t\t\t\t\t\tvalue={ { url: mediaURLValue } }\n\t\t\t\t\t\t\t\tsettings={ [] }\n\t\t\t\t\t\t\t\tshowSuggestions={ false }\n\t\t\t\t\t\t\t\tonChange={ ( { url } ) => {\n\t\t\t\t\t\t\t\t\tsetMediaURLValue( url );\n\t\t\t\t\t\t\t\t\tselectURL( url );\n\t\t\t\t\t\t\t\t\teditMediaButtonRef.current.focus();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t/>\n\t);\n};\n\nexport default compose( [\n\twithDispatch( ( dispatch ) => {\n\t\tconst { createNotice, removeNotice } = dispatch( noticesStore );\n\t\treturn {\n\t\t\tcreateNotice,\n\t\t\tremoveNotice,\n\t\t};\n\t} ),\n\twithFilters( 'editor.MediaReplaceFlow' ),\n] )( MediaReplaceFlow );\n"]}
|
|
@@ -98,6 +98,9 @@ function useBlockSync(_ref) {
|
|
|
98
98
|
getBlockName,
|
|
99
99
|
getBlocks
|
|
100
100
|
} = registry.select(_store.store);
|
|
101
|
+
const isControlled = (0, _data.useSelect)(select => {
|
|
102
|
+
return !clientId || select(_store.store).areInnerBlocksControlled(clientId);
|
|
103
|
+
}, [clientId]);
|
|
101
104
|
const pendingChanges = (0, _element.useRef)({
|
|
102
105
|
incoming: null,
|
|
103
106
|
outgoing: []
|
|
@@ -115,17 +118,22 @@ function useBlockSync(_ref) {
|
|
|
115
118
|
__unstableMarkNextChangeAsNotPersistent();
|
|
116
119
|
|
|
117
120
|
if (clientId) {
|
|
118
|
-
|
|
121
|
+
// It is important to batch here because otherwise,
|
|
122
|
+
// as soon as `setHasControlledInnerBlocks` is called
|
|
123
|
+
// the effect to restore might be triggered
|
|
124
|
+
// before the actual blocks get set properly in state.
|
|
125
|
+
registry.batch(() => {
|
|
126
|
+
setHasControlledInnerBlocks(clientId, true);
|
|
127
|
+
const storeBlocks = controlledBlocks.map(block => (0, _blocks.cloneBlock)(block));
|
|
119
128
|
|
|
120
|
-
|
|
129
|
+
if (subscribed.current) {
|
|
130
|
+
pendingChanges.current.incoming = storeBlocks;
|
|
131
|
+
}
|
|
121
132
|
|
|
122
|
-
|
|
133
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
replaceInnerBlocks(clientId, storeBlocks);
|
|
135
|
+
replaceInnerBlocks(clientId, storeBlocks);
|
|
136
|
+
});
|
|
129
137
|
} else {
|
|
130
138
|
if (subscribed.current) {
|
|
131
139
|
pendingChanges.current.incoming = controlledBlocks;
|
|
@@ -170,13 +178,22 @@ function useBlockSync(_ref) {
|
|
|
170
178
|
}
|
|
171
179
|
}
|
|
172
180
|
}, [controlledBlocks, clientId]);
|
|
181
|
+
(0, _element.useEffect)(() => {
|
|
182
|
+
// When the block becomes uncontrolled, it means its inner state has been reset
|
|
183
|
+
// we need to take the blocks again from the external value property.
|
|
184
|
+
if (!isControlled) {
|
|
185
|
+
pendingChanges.current.outgoing = [];
|
|
186
|
+
setControlledBlocks();
|
|
187
|
+
}
|
|
188
|
+
}, [isControlled]);
|
|
173
189
|
(0, _element.useEffect)(() => {
|
|
174
190
|
const {
|
|
175
191
|
getSelectionStart,
|
|
176
192
|
getSelectionEnd,
|
|
177
193
|
getSelectedBlocksInitialCaretPosition,
|
|
178
194
|
isLastBlockChangePersistent,
|
|
179
|
-
__unstableIsLastBlockChangeIgnored
|
|
195
|
+
__unstableIsLastBlockChangeIgnored,
|
|
196
|
+
areInnerBlocksControlled
|
|
180
197
|
} = registry.select(_store.store);
|
|
181
198
|
let blocks = getBlocks(clientId);
|
|
182
199
|
let isPersistent = isLastBlockChangePersistent();
|
|
@@ -190,7 +207,17 @@ function useBlockSync(_ref) {
|
|
|
190
207
|
// the subscription is triggering for a block (`clientId !== null`)
|
|
191
208
|
// and its block name can't be found because it's not on the list.
|
|
192
209
|
// (`getBlockName( clientId ) === null`).
|
|
193
|
-
if (clientId !== null && getBlockName(clientId) === null) return;
|
|
210
|
+
if (clientId !== null && getBlockName(clientId) === null) return; // When RESET_BLOCKS on parent blocks get called, the controlled blocks
|
|
211
|
+
// can reset to uncontrolled, in these situations, it means we need to populate
|
|
212
|
+
// the blocks again from the external blocks (the value property here)
|
|
213
|
+
// and we should stop triggering onChange
|
|
214
|
+
|
|
215
|
+
const isStillControlled = !clientId || areInnerBlocksControlled(clientId);
|
|
216
|
+
|
|
217
|
+
if (!isStillControlled) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
194
221
|
const newIsPersistent = isLastBlockChangePersistent();
|
|
195
222
|
const newBlocks = getBlocks(clientId);
|
|
196
223
|
const areBlocksDifferent = newBlocks !== blocks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","noop","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","blockEditorStore","getBlockName","getBlocks","select","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","storeBlocks","map","block","current","onInputRef","onChangeRef","includes","selectionStart","selectionEnd","initialPosition","getSelectionStart","getSelectionEnd","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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,OAAf,CAAuBN,QAAvB,CAAgC2B,IAAhC,CAAsCT,MAAtC,EANiD,CAQjD;AACA;;AACA,cAAMU,YAAY,GAAGT,YAAY,GAC9BX,WAAW,CAACF,OADkB,GAE9BC,UAAU,CAACD,OAFd;AAGAsB,QAAAA,YAAY,CAAEV,MAAF,EAAU;AACrBpC,UAAAA,SAAS,EAAE;AACV4B,YAAAA,cAAc,EAAEG,iBAAiB,EADvB;AAEVF,YAAAA,YAAY,EAAEG,eAAe,EAFnB;AAGVF,YAAAA,eAAe,EAAEG,qCAAqC;AAH5C;AADU,SAAV,CAAZ;AAOA;;AACDK,MAAAA,0BAA0B,GAAGK,kBAA7B;AACA,KA1DmB,CAApB;AA4DA,WAAO,MAAMJ,WAAW,EAAxB;AACA,GA3ED,EA2EG,CAAElC,QAAF,EAAYR,QAAZ,CA3EH;AA4EA","sourcesContent":["/**\n * External dependencies\n */\nimport { last, noop } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst { getBlockName, getBlocks } = registry.select( blockEditorStore );\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t}\n\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tlast( pendingChanges.current.outgoing ) === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition: getSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => unsubscribe();\n\t}, [ registry, clientId ] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","noop","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","blockEditorStore","getBlockName","getBlocks","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","onInputRef","onChangeRef","includes","selectionStart","selectionEnd","initialPosition","getSelectionStart","getSelectionEnd","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;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QAAF,EAAYR,QAAZ,CArFH;AAsFA","sourcesContent":["/**\n * External dependencies\n */\nimport { last, noop } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst { getBlockName, getBlocks } = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tlast( pendingChanges.current.outgoing ) === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition: getSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => unsubscribe();\n\t}, [ registry, clientId ] );\n}\n"]}
|
|
@@ -15,7 +15,7 @@ function filePasteHandler(files) {
|
|
|
15
15
|
let {
|
|
16
16
|
type
|
|
17
17
|
} = _ref;
|
|
18
|
-
return /^image\/(?:jpe?g|png|gif
|
|
18
|
+
return /^image\/(?:jpe?g|png|gif)$/.test(type);
|
|
19
19
|
}).map(file => `<img src="${(0, _blob.createBlobURL)(file)}">`).join('');
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=file-paste-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/file-paste-handler.js"],"names":["filePasteHandler","files","filter","type","test","map","file","join"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,SAASA,gBAAT,CAA2BC,KAA3B,EAAmC;AACzC,SAAOA,KAAK,CACVC,MADK,CACG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/file-paste-handler.js"],"names":["filePasteHandler","files","filter","type","test","map","file","join"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,SAASA,gBAAT,CAA2BC,KAA3B,EAAmC;AACzC,SAAOA,KAAK,CACVC,MADK,CACG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WAAgB,6BAA6BC,IAA7B,CAAmCD,IAAnC,CAAhB;AAAA,GADH,EAELE,GAFK,CAEEC,IAAF,IAAa,aAAa,yBAAeA,IAAf,CAAuB,IAFjD,EAGLC,IAHK,CAGC,EAHD,CAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlobURL } from '@wordpress/blob';\n\nexport function filePasteHandler( files ) {\n\treturn files\n\t\t.filter( ( { type } ) => /^image\\/(?:jpe?g|png|gif)$/.test( type ) )\n\t\t.map( ( file ) => `<img src=\"${ createBlobURL( file ) }\">` )\n\t\t.join( '' );\n}\n"]}
|
|
@@ -17,8 +17,6 @@ var _data = require("@wordpress/data");
|
|
|
17
17
|
|
|
18
18
|
var _store = require("../../store");
|
|
19
19
|
|
|
20
|
-
var _preventEventDiscovery = require("./prevent-event-discovery");
|
|
21
|
-
|
|
22
20
|
/**
|
|
23
21
|
* WordPress dependencies
|
|
24
22
|
*/
|
|
@@ -111,7 +109,7 @@ function useInputRules(props) {
|
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
return accumlator;
|
|
114
|
-
},
|
|
112
|
+
}, value);
|
|
115
113
|
|
|
116
114
|
if (transformed !== value) {
|
|
117
115
|
__unstableMarkLastChangeAsPersistent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","blockEditorStore","propsRef","current","element","inputRule","value","onReplace","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","length","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","blockEditorStore","propsRef","current","element","inputRule","value","onReplace","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","length","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGO,SAASA,aAAT,CAAwBC,KAAxB,EAAgC;AACtC,QAAM;AACLC,IAAAA,oCADK;AAELC,IAAAA;AAFK,MAGF,uBAAaC,YAAb,CAHJ;AAIA,QAAMC,QAAQ,GAAG,qBAAQJ,KAAR,CAAjB;AACAI,EAAAA,QAAQ,CAACC,OAAT,GAAmBL,KAAnB;AACA,SAAO,2BAAgBM,OAAF,IAAe;AACnC,aAASC,SAAT,GAAqB;AACpB,YAAM;AAAEC,QAAAA,KAAF;AAASC,QAAAA;AAAT,UAAuBL,QAAQ,CAACC,OAAtC;;AAEA,UAAK,CAAEI,SAAP,EAAmB;AAClB;AACA;;AAED,YAAM;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AK,gBAA5C,EAA+D;AAC9D;AACA;;AAED,UAAKW,oCAAoC,IAAItB,SAA7C,EAAyD;AACxDA,QAAAA,SAAS;AACT;;AAED,YAAMwB,WAAW,GAAGD,WAAW,CAACE,MAAZ,CACnB,CAAEC,UAAF,YAA2C;AAAA,YAA7B;AAAEC,UAAAA;AAAF,SAA6B;;AAC1C,YAAKA,mBAAL,EAA2B;AAC1BD,UAAAA,UAAU,GAAGC,mBAAmB,CAAED,UAAF,CAAhC;AACA;;AAED,eAAOA,UAAP;AACA,OAPkB,EAQnBzB,KARmB,CAApB;;AAWA,UAAKuB,WAAW,KAAKvB,KAArB,EAA6B;AAC5BP,QAAAA,oCAAoC;;AACpC2B,QAAAA,QAAQ,CAAE,EACT,GAAGG,WADM;AAETI,UAAAA,aAAa,EAAE3B,KAAK,CAAC2B;AAFZ,SAAF,CAAR;;AAIAjC,QAAAA,6BAA6B;AAC7B;AACD;;AAEDI,IAAAA,OAAO,CAAC8B,gBAAR,CAA0B,OAA1B,EAAmCX,OAAnC;AACAnB,IAAAA,OAAO,CAAC8B,gBAAR,CAA0B,gBAA1B,EAA4CX,OAA5C;AACA,WAAO,MAAM;AACZnB,MAAAA,OAAO,CAAC+B,mBAAR,CAA6B,OAA7B,EAAsCZ,OAAtC;AACAnB,MAAAA,OAAO,CAAC+B,mBAAR,CAA6B,gBAA7B,EAA+CZ,OAA/C;AACA,KAHD;AAIA,GArFM,EAqFJ,EArFI,CAAP;AAsFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { slice, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport function useInputRules( props ) {\n\tconst {\n\t\t__unstableMarkLastChangeAsPersistent,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction inputRule() {\n\t\t\tconst { value, onReplace } = propsRef.current;\n\n\t\t\tif ( ! onReplace ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { start, text } = value;\n\t\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t\t// The character right before the caret must be a plain space.\n\t\t\tif ( characterBefore !== ' ' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t( { type } ) => type === 'prefix'\n\t\t\t);\n\t\t\tconst transformation = findTransform(\n\t\t\t\tprefixTransforms,\n\t\t\t\t( { prefix } ) => {\n\t\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( ! transformation ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst content = toHTMLString( {\n\t\t\t\tvalue: slice( value, start, text.length ),\n\t\t\t} );\n\t\t\tconst block = transformation.transform( content );\n\n\t\t\tonReplace( [ block ] );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\n\t\tfunction onInput( event ) {\n\t\t\tconst { inputType, type } = event;\n\t\t\tconst {\n\t\t\t\tvalue,\n\t\t\t\tonChange,\n\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\tformatTypes,\n\t\t\t} = propsRef.current;\n\n\t\t\t// Only run input rules when inserting text.\n\t\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( __unstableAllowPrefixTransformations && inputRule ) {\n\t\t\t\tinputRule();\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstableInputRule } ) => {\n\t\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\t\taccumlator = __unstableInputRule( accumlator );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tvalue\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t\tonChange( {\n\t\t\t\t\t...transformed,\n\t\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t\t} );\n\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'input', onInput );\n\t\telement.addEventListener( 'compositionend', onInput );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'input', onInput );\n\t\t\telement.removeEventListener( 'compositionend', onInput );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -21,8 +21,7 @@ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
|
21
21
|
*/
|
|
22
22
|
function MultiSelectScrollIntoView() {
|
|
23
23
|
(0, _deprecated.default)('wp.blockEditor.MultiSelectScrollIntoView', {
|
|
24
|
-
hint: 'This behaviour is now built-in.'
|
|
25
|
-
since: '5.8'
|
|
24
|
+
hint: 'This behaviour is now built-in.'
|
|
26
25
|
});
|
|
27
26
|
return null;
|
|
28
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/selection-scroll-into-view/index.js"],"names":["MultiSelectScrollIntoView","hint"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/selection-scroll-into-view/index.js"],"names":["MultiSelectScrollIntoView","hint"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,yBAAT,GAAqC;AAC3C,2BAAY,0CAAZ,EAAwD;AACvDC,IAAAA,IAAI,EAAE;AADiD,GAAxD;AAGA,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Scrolls the multi block selection end into view if not in view already. This\n * is important to do after selection by keyboard.\n *\n * @deprecated\n */\nexport function MultiSelectScrollIntoView() {\n\tdeprecated( 'wp.blockEditor.MultiSelectScrollIntoView', {\n\t\thint: 'This behaviour is now built-in.',\n\t} );\n\treturn null;\n}\n"]}
|