@wordpress/block-editor 12.24.0 → 12.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +1 -1
- package/build/components/alignment-control/ui.js +3 -1
- package/build/components/alignment-control/ui.js.map +1 -1
- package/build/components/block-inspector/index.js +1 -1
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +0 -9
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/index.js +4 -3
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/index.native.js +1 -9
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +6 -6
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-block-refs.js +17 -46
- package/build/components/block-list/use-block-props/use-block-refs.js.map +1 -1
- package/build/components/block-list/use-block-props/use-is-hovered.js +10 -14
- package/build/components/block-list/use-block-props/use-is-hovered.js.map +1 -1
- package/build/components/block-mover/index.native.js +3 -1
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +0 -25
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/pattern-transformations-menu.js +3 -1
- package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build/components/block-switcher/use-transformed-patterns.js +6 -2
- package/build/components/block-switcher/use-transformed-patterns.js.map +1 -1
- package/build/components/block-switcher/utils.js +15 -5
- package/build/components/block-switcher/utils.js.map +1 -1
- package/build/components/block-toolbar/use-has-block-toolbar.js +14 -9
- package/build/components/block-toolbar/use-has-block-toolbar.js.map +1 -1
- package/build/components/block-tools/index.js +3 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/use-show-block-tools.js +2 -5
- package/build/components/block-tools/use-show-block-tools.js.map +1 -1
- package/build/components/block-tools/zoom-out-mode-inserters.js +5 -1
- package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build/components/block-variation-picker/index.js +3 -2
- package/build/components/block-variation-picker/index.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +3 -1
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/floating-toolbar/index.native.js +9 -5
- package/build/components/floating-toolbar/index.native.js.map +1 -1
- package/build/components/global-styles/background-panel.js +1 -1
- package/build/components/global-styles/background-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +3 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +16 -0
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +3 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +23 -23
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +149 -132
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +45 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/inner-blocks/index.js +16 -2
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/index.js +12 -31
- package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +4 -0
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/category-tabs/index.js +56 -0
- package/build/components/inserter/category-tabs/index.js.map +1 -0
- package/build/components/inserter/media-tab/index.js +2 -2
- package/build/components/inserter/media-tab/index.js.map +1 -1
- package/build/components/inserter/media-tab/media-panel.js +0 -25
- package/build/components/inserter/media-tab/media-panel.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +13 -3
- package/build/components/inserter/media-tab/media-preview.js.map +1 -1
- package/build/components/inserter/media-tab/media-tab.js +15 -29
- package/build/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build/components/inserter/menu.js +59 -69
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/tabs.js +6 -6
- package/build/components/inserter/tabs.js.map +1 -1
- package/build/components/line-height-control/index.js +6 -2
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/link-control/search-item.js +9 -3
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/list-view/block-select-button.js +5 -170
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +166 -14
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/index.js +1 -1
- package/build/components/list-view/index.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/list-view/utils.js +3 -1
- package/build/components/list-view/utils.js.map +1 -1
- package/build/components/media-placeholder/index.js +3 -3
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +3 -1
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/provider/block-refs-provider.js +3 -4
- package/build/components/provider/block-refs-provider.js.map +1 -1
- package/build/components/provider/use-block-sync.js +3 -12
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/rich-text/event-listeners/before-input-rules.js +93 -0
- package/build/components/rich-text/event-listeners/before-input-rules.js.map +1 -0
- package/build/components/rich-text/event-listeners/delete.js +58 -0
- package/build/components/rich-text/event-listeners/delete.js.map +1 -0
- package/build/components/rich-text/event-listeners/enter.js +98 -0
- package/build/components/rich-text/event-listeners/enter.js.map +1 -0
- package/build/components/rich-text/event-listeners/firefox-compat.js +36 -0
- package/build/components/rich-text/event-listeners/firefox-compat.js.map +1 -0
- package/build/components/rich-text/event-listeners/index.js +44 -0
- package/build/components/rich-text/event-listeners/index.js.map +1 -0
- package/build/components/rich-text/event-listeners/input-events.js +22 -0
- package/build/components/rich-text/event-listeners/input-events.js.map +1 -0
- package/build/components/rich-text/event-listeners/input-rules.js +135 -0
- package/build/components/rich-text/event-listeners/input-rules.js.map +1 -0
- package/build/components/rich-text/event-listeners/insert-replacement-text.js +33 -0
- package/build/components/rich-text/event-listeners/insert-replacement-text.js.map +1 -0
- package/build/components/rich-text/event-listeners/paste-handler.js +146 -0
- package/build/components/rich-text/event-listeners/paste-handler.js.map +1 -0
- package/build/components/rich-text/event-listeners/remove-browser-shortcuts.js +27 -0
- package/build/components/rich-text/event-listeners/remove-browser-shortcuts.js.map +1 -0
- package/build/components/rich-text/event-listeners/shortcuts.js +22 -0
- package/build/components/rich-text/event-listeners/shortcuts.js.map +1 -0
- package/build/components/rich-text/event-listeners/undo-automatic-change.js +51 -0
- package/build/components/rich-text/event-listeners/undo-automatic-change.js.map +1 -0
- package/build/components/rich-text/index.js +11 -31
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +13 -3
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/multiline.js +6 -2
- package/build/components/rich-text/multiline.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +12 -0
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/rich-text/use-format-types.js +8 -4
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build/components/segmented-text-control/index.js +62 -0
- package/build/components/segmented-text-control/index.js.map +1 -0
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +16 -2
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/text-alignment-control/index.js +76 -0
- package/build/components/text-alignment-control/index.js.map +1 -0
- package/build/components/text-decoration-control/index.js +21 -25
- package/build/components/text-decoration-control/index.js.map +1 -1
- package/build/components/text-transform-control/index.js +18 -22
- package/build/components/text-transform-control/index.js.map +1 -1
- package/build/components/use-block-display-information/index.js +9 -3
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +3 -1
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/writing-flow/use-drag-selection.js +3 -1
- package/build/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +3 -1
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/components/writing-mode-control/index.js +16 -20
- package/build/components/writing-mode-control/index.js.map +1 -1
- package/build/hooks/duotone.js +3 -1
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/utils.js +11 -6
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +4 -2
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +32 -8
- package/build/store/actions.js.map +1 -1
- package/build/store/private-selectors.js +27 -6
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +11 -8
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +21 -7
- package/build/store/selectors.js.map +1 -1
- package/build/utils/object.js +17 -0
- package/build/utils/object.js.map +1 -1
- package/build/utils/order-inserter-block-items.js +6 -2
- package/build/utils/order-inserter-block-items.js.map +1 -1
- package/build/utils/pasting.js +6 -2
- package/build/utils/pasting.js.map +1 -1
- package/build-module/components/alignment-control/ui.js +3 -1
- package/build-module/components/alignment-control/ui.js.map +1 -1
- package/build-module/components/block-inspector/index.js +1 -1
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +0 -9
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/index.js +4 -3
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/index.native.js +1 -9
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +6 -6
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-block-refs.js +19 -48
- package/build-module/components/block-list/use-block-props/use-block-refs.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-is-hovered.js +10 -14
- package/build-module/components/block-list/use-block-props/use-is-hovered.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +3 -1
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +1 -26
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/pattern-transformations-menu.js +3 -1
- package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build-module/components/block-switcher/use-transformed-patterns.js +6 -2
- package/build-module/components/block-switcher/use-transformed-patterns.js.map +1 -1
- package/build-module/components/block-switcher/utils.js +15 -5
- package/build-module/components/block-switcher/utils.js.map +1 -1
- package/build-module/components/block-toolbar/use-has-block-toolbar.js +14 -9
- package/build-module/components/block-toolbar/use-has-block-toolbar.js.map +1 -1
- package/build-module/components/block-tools/index.js +3 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/use-show-block-tools.js +2 -5
- package/build-module/components/block-tools/use-show-block-tools.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-mode-inserters.js +5 -1
- package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build-module/components/block-variation-picker/index.js +3 -2
- package/build-module/components/block-variation-picker/index.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +3 -1
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/floating-toolbar/index.native.js +9 -5
- package/build-module/components/floating-toolbar/index.native.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +1 -1
- package/build-module/components/global-styles/background-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +3 -1
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +17 -1
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +3 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +24 -24
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +149 -132
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +44 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +16 -2
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/index.js +13 -32
- package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +4 -0
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/category-tabs/index.js +49 -0
- package/build-module/components/inserter/category-tabs/index.js.map +1 -0
- package/build-module/components/inserter/media-tab/index.js +1 -1
- package/build-module/components/inserter/media-tab/index.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-panel.js +0 -24
- package/build-module/components/inserter/media-tab/media-panel.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +13 -3
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-tab.js +17 -31
- package/build-module/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +61 -71
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/tabs.js +6 -6
- package/build-module/components/inserter/tabs.js.map +1 -1
- package/build-module/components/line-height-control/index.js +6 -2
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/link-control/search-item.js +9 -3
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +7 -172
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +167 -15
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/index.js +1 -1
- package/build-module/components/list-view/index.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/list-view/utils.js +3 -1
- package/build-module/components/list-view/utils.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +3 -3
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +3 -1
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/provider/block-refs-provider.js +3 -4
- package/build-module/components/provider/block-refs-provider.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +4 -13
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/rich-text/event-listeners/before-input-rules.js +86 -0
- package/build-module/components/rich-text/event-listeners/before-input-rules.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/delete.js +51 -0
- package/build-module/components/rich-text/event-listeners/delete.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/enter.js +92 -0
- package/build-module/components/rich-text/event-listeners/enter.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/firefox-compat.js +29 -0
- package/build-module/components/rich-text/event-listeners/firefox-compat.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/index.js +36 -0
- package/build-module/components/rich-text/event-listeners/index.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/input-events.js +15 -0
- package/build-module/components/rich-text/event-listeners/input-events.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/input-rules.js +127 -0
- package/build-module/components/rich-text/event-listeners/input-rules.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/insert-replacement-text.js +27 -0
- package/build-module/components/rich-text/event-listeners/insert-replacement-text.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/paste-handler.js +142 -0
- package/build-module/components/rich-text/event-listeners/paste-handler.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.js +21 -0
- package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/shortcuts.js +15 -0
- package/build-module/components/rich-text/event-listeners/shortcuts.js.map +1 -0
- package/build-module/components/rich-text/event-listeners/undo-automatic-change.js +45 -0
- package/build-module/components/rich-text/event-listeners/undo-automatic-change.js.map +1 -0
- package/build-module/components/rich-text/index.js +12 -32
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +13 -3
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/multiline.js +6 -2
- package/build-module/components/rich-text/multiline.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +12 -0
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-format-types.js +8 -4
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/segmented-text-control/index.js +55 -0
- package/build-module/components/segmented-text-control/index.js.map +1 -0
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +16 -2
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/text-alignment-control/index.js +68 -0
- package/build-module/components/text-alignment-control/index.js.map +1 -0
- package/build-module/components/text-decoration-control/index.js +21 -25
- package/build-module/components/text-decoration-control/index.js.map +1 -1
- package/build-module/components/text-transform-control/index.js +18 -22
- package/build-module/components/text-transform-control/index.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +9 -3
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +3 -1
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/writing-flow/use-drag-selection.js +3 -1
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +3 -1
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/writing-mode-control/index.js +16 -20
- package/build-module/components/writing-mode-control/index.js.map +1 -1
- package/build-module/hooks/duotone.js +3 -1
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/utils.js +11 -6
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +4 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +32 -8
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-selectors.js +27 -5
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +11 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +21 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/object.js +16 -0
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/order-inserter-block-items.js +6 -2
- package/build-module/utils/order-inserter-block-items.js.map +1 -1
- package/build-module/utils/pasting.js +6 -2
- package/build-module/utils/pasting.js.map +1 -1
- package/build-style/content-rtl.css +41 -68
- package/build-style/content.css +41 -68
- package/build-style/style-rtl.css +100 -199
- package/build-style/style.css +100 -199
- package/package.json +31 -31
- package/src/components/alignment-control/ui.js +3 -1
- package/src/components/block-bindings-toolbar-indicator/style.scss +1 -4
- package/src/components/block-canvas/style.scss +1 -3
- package/src/components/block-draggable/test/helpers.native.js +8 -8
- package/src/components/block-inspector/index.js +1 -2
- package/src/components/block-list/block.js +2 -13
- package/src/components/block-list/content.scss +9 -1
- package/src/components/block-list/index.js +4 -4
- package/src/components/block-list/index.native.js +1 -6
- package/src/components/block-list/use-block-props/index.js +12 -4
- package/src/components/block-list/use-block-props/use-block-refs.js +17 -57
- package/src/components/block-list/use-block-props/use-is-hovered.js +11 -16
- package/src/components/block-mover/index.native.js +3 -1
- package/src/components/block-patterns-list/style.scss +1 -3
- package/src/components/block-preview/style.scss +13 -15
- package/src/components/block-settings-menu/block-settings-dropdown.js +1 -51
- package/src/components/block-switcher/pattern-transformations-menu.js +3 -1
- package/src/components/block-switcher/use-transformed-patterns.js +6 -2
- package/src/components/block-switcher/utils.js +14 -5
- package/src/components/block-toolbar/style.scss +8 -11
- package/src/components/block-toolbar/use-has-block-toolbar.js +21 -16
- package/src/components/block-tools/index.js +3 -1
- package/src/components/block-tools/use-show-block-tools.js +36 -48
- package/src/components/block-tools/zoom-out-mode-inserters.js +5 -1
- package/src/components/block-variation-picker/content.scss +22 -72
- package/src/components/block-variation-picker/index.js +3 -2
- package/src/components/block-variation-transforms/index.js +3 -1
- package/src/components/floating-toolbar/index.native.js +5 -2
- package/src/components/global-styles/background-panel.js +1 -3
- package/src/components/global-styles/color-panel.js +3 -1
- package/src/components/global-styles/dimensions-panel.js +18 -1
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/test/utils.js +21 -0
- package/src/components/global-styles/typography-panel.js +27 -23
- package/src/components/global-styles/use-global-styles-output.js +211 -187
- package/src/components/global-styles/utils.js +55 -0
- package/src/components/inner-blocks/index.js +14 -1
- package/src/components/inserter/block-patterns-tab/index.js +15 -65
- package/src/components/inserter/block-types-tab.js +5 -0
- package/src/components/inserter/category-tabs/index.js +74 -0
- package/src/components/inserter/media-tab/index.js +1 -1
- package/src/components/inserter/media-tab/media-panel.js +0 -22
- package/src/components/inserter/media-tab/media-preview.js +15 -7
- package/src/components/inserter/media-tab/media-tab.js +44 -83
- package/src/components/inserter/menu.js +139 -117
- package/src/components/inserter/style.scss +90 -170
- package/src/components/inserter/tabs.js +5 -13
- package/src/components/line-height-control/index.js +6 -2
- package/src/components/link-control/search-item.js +9 -3
- package/src/components/list-view/block-select-button.js +73 -266
- package/src/components/list-view/block.js +218 -28
- package/src/components/list-view/index.js +1 -1
- package/src/components/list-view/style.scss +20 -28
- package/src/components/list-view/use-list-view-drop-zone.js +1 -1
- package/src/components/list-view/utils.js +3 -1
- package/src/components/media-placeholder/content.scss +0 -11
- package/src/components/media-placeholder/index.js +3 -3
- package/src/components/navigable-toolbar/index.js +3 -1
- package/src/components/provider/block-refs-provider.js +3 -8
- package/src/components/provider/test/use-block-sync.js +7 -0
- package/src/components/provider/use-block-sync.js +3 -20
- package/src/components/rich-text/event-listeners/before-input-rules.js +92 -0
- package/src/components/rich-text/event-listeners/delete.js +53 -0
- package/src/components/rich-text/event-listeners/enter.js +104 -0
- package/src/components/rich-text/event-listeners/firefox-compat.js +31 -0
- package/src/components/rich-text/event-listeners/index.js +56 -0
- package/src/components/rich-text/event-listeners/input-events.js +13 -0
- package/src/components/rich-text/event-listeners/input-rules.js +146 -0
- package/src/components/rich-text/event-listeners/insert-replacement-text.js +28 -0
- package/src/components/rich-text/event-listeners/paste-handler.js +169 -0
- package/src/components/rich-text/event-listeners/remove-browser-shortcuts.js +24 -0
- package/src/components/rich-text/event-listeners/shortcuts.js +13 -0
- package/src/components/rich-text/event-listeners/undo-automatic-change.js +45 -0
- package/src/components/rich-text/index.js +7 -34
- package/src/components/rich-text/index.native.js +11 -0
- package/src/components/rich-text/multiline.js +6 -2
- package/src/components/rich-text/native/index.native.js +11 -0
- package/src/components/rich-text/use-format-types.js +6 -2
- package/src/components/segmented-text-control/index.js +63 -0
- package/src/components/{writing-mode-control → segmented-text-control}/style.scss +2 -5
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +16 -1
- package/src/components/text-alignment-control/index.js +91 -0
- package/src/components/text-alignment-control/stories/index.story.js +39 -0
- package/src/components/text-decoration-control/index.js +20 -33
- package/src/components/text-transform-control/index.js +17 -30
- package/src/components/use-block-display-information/index.js +9 -3
- package/src/components/use-on-block-drop/index.js +3 -1
- package/src/components/writing-flow/use-drag-selection.js +3 -1
- package/src/components/writing-flow/use-tab-nav.js +3 -1
- package/src/components/writing-mode-control/index.js +15 -28
- package/src/hooks/duotone.js +3 -1
- package/src/hooks/utils.js +16 -2
- package/src/private-apis.js +4 -2
- package/src/store/actions.js +36 -12
- package/src/store/private-selectors.js +28 -4
- package/src/store/reducer.js +13 -23
- package/src/store/selectors.js +20 -7
- package/src/style.scss +1 -2
- package/src/utils/object.js +16 -0
- package/src/utils/order-inserter-block-items.js +6 -2
- package/src/utils/pasting.js +6 -2
- package/build/components/block-list/use-block-props/use-block-moving-mode-class-names.js +0 -54
- package/build/components/block-list/use-block-props/use-block-moving-mode-class-names.js.map +0 -1
- package/build/components/rich-text/use-before-input-rules.js +0 -98
- package/build/components/rich-text/use-before-input-rules.js.map +0 -1
- package/build/components/rich-text/use-delete.js +0 -64
- package/build/components/rich-text/use-delete.js.map +0 -1
- package/build/components/rich-text/use-enter.js +0 -109
- package/build/components/rich-text/use-enter.js.map +0 -1
- package/build/components/rich-text/use-firefox-compat.js +0 -44
- package/build/components/rich-text/use-firefox-compat.js.map +0 -1
- package/build/components/rich-text/use-input-events.js +0 -25
- package/build/components/rich-text/use-input-events.js.map +0 -1
- package/build/components/rich-text/use-input-rules.js +0 -139
- package/build/components/rich-text/use-input-rules.js.map +0 -1
- package/build/components/rich-text/use-insert-replacement-text.js +0 -38
- package/build/components/rich-text/use-insert-replacement-text.js.map +0 -1
- package/build/components/rich-text/use-paste-handler.js +0 -158
- package/build/components/rich-text/use-paste-handler.js.map +0 -1
- package/build/components/rich-text/use-remove-browser-shortcuts.js +0 -32
- package/build/components/rich-text/use-remove-browser-shortcuts.js.map +0 -1
- package/build/components/rich-text/use-shortcuts.js +0 -25
- package/build/components/rich-text/use-shortcuts.js.map +0 -1
- package/build/components/rich-text/use-undo-automatic-change.js +0 -53
- package/build/components/rich-text/use-undo-automatic-change.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-block-moving-mode-class-names.js +0 -47
- package/build-module/components/block-list/use-block-props/use-block-moving-mode-class-names.js.map +0 -1
- package/build-module/components/rich-text/use-before-input-rules.js +0 -92
- package/build-module/components/rich-text/use-before-input-rules.js.map +0 -1
- package/build-module/components/rich-text/use-delete.js +0 -57
- package/build-module/components/rich-text/use-delete.js.map +0 -1
- package/build-module/components/rich-text/use-enter.js +0 -102
- package/build-module/components/rich-text/use-enter.js.map +0 -1
- package/build-module/components/rich-text/use-firefox-compat.js +0 -37
- package/build-module/components/rich-text/use-firefox-compat.js.map +0 -1
- package/build-module/components/rich-text/use-input-events.js +0 -18
- package/build-module/components/rich-text/use-input-events.js.map +0 -1
- package/build-module/components/rich-text/use-input-rules.js +0 -132
- package/build-module/components/rich-text/use-input-rules.js.map +0 -1
- package/build-module/components/rich-text/use-insert-replacement-text.js +0 -32
- package/build-module/components/rich-text/use-insert-replacement-text.js.map +0 -1
- package/build-module/components/rich-text/use-paste-handler.js +0 -152
- package/build-module/components/rich-text/use-paste-handler.js.map +0 -1
- package/build-module/components/rich-text/use-remove-browser-shortcuts.js +0 -26
- package/build-module/components/rich-text/use-remove-browser-shortcuts.js.map +0 -1
- package/build-module/components/rich-text/use-shortcuts.js +0 -18
- package/build-module/components/rich-text/use-shortcuts.js.map +0 -1
- package/build-module/components/rich-text/use-undo-automatic-change.js +0 -46
- package/build-module/components/rich-text/use-undo-automatic-change.js.map +0 -1
- package/src/components/block-list/use-block-props/use-block-moving-mode-class-names.js +0 -55
- package/src/components/rich-text/use-before-input-rules.js +0 -99
- package/src/components/rich-text/use-delete.js +0 -59
- package/src/components/rich-text/use-enter.js +0 -110
- package/src/components/rich-text/use-firefox-compat.js +0 -39
- package/src/components/rich-text/use-input-events.js +0 -19
- package/src/components/rich-text/use-input-rules.js +0 -150
- package/src/components/rich-text/use-insert-replacement-text.js +0 -31
- package/src/components/rich-text/use-paste-handler.js +0 -180
- package/src/components/rich-text/use-remove-browser-shortcuts.js +0 -29
- package/src/components/rich-text/use-shortcuts.js +0 -19
- package/src/components/rich-text/use-undo-automatic-change.js +0 -46
- package/src/components/text-decoration-control/style.scss +0 -18
- package/src/components/text-transform-control/style.scss +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","Button","FormFileUpload","Placeholder","DropZone","withFilters","__","useState","useEffect","useSelect","keyboardReturn","pasteHandler","deprecated","MediaUpload","MediaUploadCheck","URLPopover","store","blockEditorStore","noop","InsertFromURLPopover","src","onChange","onSubmit","onClose","popoverAnchor","createElement","anchor","className","type","placeholder","value","icon","label","URLSelectionUI","isURLInputVisible","onChangeSrc","onSubmitSrc","openURLInput","closeURLInput","setPopoverAnchor","ref","onClick","isPressed","variant","MediaPlaceholder","allowedTypes","labels","mediaPreview","notices","isAppender","accept","addToGallery","multiple","handleUpload","disableDropZone","disableMediaButtons","onError","onSelect","onCancel","onSelectURL","onToggleFeaturedImage","onDoubleClick","onFilesPreUpload","onHTMLDrop","deprecatedOnHTMLDrop","children","mediaLibraryButton","style","since","version","mediaUpload","select","getSettings","setSrc","setIsURLInputVisible","_value$src","onlyAllowsImages","length","every","allowedType","startsWith","event","target","preventDefault","onFilesUpload","files","setMedia","lastMediaPassed","newMedia","filteredMedia","filter","item","id","some","Number","urlSlug","url","includes","concat","map","media","cutOffIndex","lastIndexOf","slice","filesList","onFileChange","handleBlocksDrop","blocks","Array","isArray","recursivelyFindMediaFromBlocks","_blocks","flatMap","block","name","attributes","innerBlocks","mediaBlocks","uploadedMediaList","Promise","all","resolve","reject","window","fetch","then","response","blob","additionalData","title","alt_text","alt","caption","catch","err","HTML","onUpload","defaultRenderPlaceholder","content","instructions","undefined","typesAllowed","firstAllowedType","isOneType","isAudio","isImage","isVideo","placeholderClassName","preview","renderPlaceholder","renderDropZone","onFilesDrop","renderCancelLink","renderUrlSelectionUI","renderFeaturedImageToggle","renderMediaUploadChecked","defaultButton","open","libraryButton","uploadMediaLibraryButton","gallery","mode","render","Fragment","openFileDialog","fallback"],"sources":["@wordpress/block-editor/src/components/media-placeholder/index.js"],"sourcesContent":["/**\n * External dependencies\n */\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 { keyboardReturn } from '@wordpress/icons';\nimport { pasteHandler } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\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 noop = () => {};\n\nconst InsertFromURLPopover = ( {\n\tsrc,\n\tonChange,\n\tonSubmit,\n\tonClose,\n\tpopoverAnchor,\n} ) => (\n\t<URLPopover anchor={ popoverAnchor } 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\nconst URLSelectionUI = ( {\n\tisURLInputVisible,\n\tsrc,\n\tonChangeSrc,\n\tonSubmitSrc,\n\topenURLInput,\n\tcloseURLInput,\n} ) => {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-media-placeholder__url-input-container\"\n\t\t\tref={ setPopoverAnchor }\n\t\t>\n\t\t\t<Button\n\t\t\t\tclassName=\"block-editor-media-placeholder__button\"\n\t\t\t\tonClick={ openURLInput }\n\t\t\t\tisPressed={ isURLInputVisible }\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t>\n\t\t\t\t{ __( 'Insert from URL' ) }\n\t\t\t</Button>\n\t\t\t{ isURLInputVisible && (\n\t\t\t\t<InsertFromURLPopover\n\t\t\t\t\tsrc={ src }\n\t\t\t\t\tonChange={ onChangeSrc }\n\t\t\t\t\tonSubmit={ onSubmitSrc }\n\t\t\t\t\tonClose={ closeURLInput }\n\t\t\t\t\tpopoverAnchor={ popoverAnchor }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\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\tdisableDropZone,\n\tdisableMediaButtons,\n\tonError,\n\tonSelect,\n\tonCancel,\n\tonSelectURL,\n\tonToggleFeaturedImage,\n\tonDoubleClick,\n\tonFilesPreUpload = noop,\n\tonHTMLDrop: deprecatedOnHTMLDrop,\n\tchildren,\n\tmediaLibraryButton,\n\tplaceholder,\n\tstyle,\n} ) {\n\tif ( deprecatedOnHTMLDrop ) {\n\t\tdeprecated( 'wp.blockEditor.MediaPlaceholder onHTMLDrop prop', {\n\t\t\tsince: '6.2',\n\t\t\tversion: '6.4',\n\t\t} );\n\t}\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\tasync function handleBlocksDrop( blocks ) {\n\t\tif ( ! blocks || ! Array.isArray( blocks ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction recursivelyFindMediaFromBlocks( _blocks ) {\n\t\t\treturn _blocks.flatMap( ( block ) =>\n\t\t\t\t( block.name === 'core/image' ||\n\t\t\t\t\tblock.name === 'core/audio' ||\n\t\t\t\t\tblock.name === 'core/video' ) &&\n\t\t\t\tblock.attributes.url\n\t\t\t\t\t? [ block ]\n\t\t\t\t\t: recursivelyFindMediaFromBlocks( block.innerBlocks )\n\t\t\t);\n\t\t}\n\n\t\tconst mediaBlocks = recursivelyFindMediaFromBlocks( blocks );\n\n\t\tif ( ! mediaBlocks.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst uploadedMediaList = await Promise.all(\n\t\t\tmediaBlocks.map( ( block ) =>\n\t\t\t\tblock.attributes.id\n\t\t\t\t\t? block.attributes\n\t\t\t\t\t: new Promise( ( resolve, reject ) => {\n\t\t\t\t\t\t\twindow\n\t\t\t\t\t\t\t\t.fetch( block.attributes.url )\n\t\t\t\t\t\t\t\t.then( ( response ) => response.blob() )\n\t\t\t\t\t\t\t\t.then( ( blob ) =>\n\t\t\t\t\t\t\t\t\tmediaUpload( {\n\t\t\t\t\t\t\t\t\t\tfilesList: [ blob ],\n\t\t\t\t\t\t\t\t\t\tadditionalData: {\n\t\t\t\t\t\t\t\t\t\t\ttitle: block.attributes.title,\n\t\t\t\t\t\t\t\t\t\t\talt_text: block.attributes.alt,\n\t\t\t\t\t\t\t\t\t\t\tcaption: block.attributes.caption,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tonFileChange: ( [ media ] ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( media.id ) {\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( media );\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\tallowedTypes,\n\t\t\t\t\t\t\t\t\t\tonError: reject,\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\t.catch( () => resolve( block.attributes.url ) );\n\t\t\t\t\t } )\n\t\t\t)\n\t\t).catch( ( err ) => onError( err ) );\n\n\t\tif ( multiple ) {\n\t\t\tonSelect( uploadedMediaList );\n\t\t} else {\n\t\t\tonSelect( uploadedMediaList[ 0 ] );\n\t\t}\n\t}\n\n\tasync function onHTMLDrop( HTML ) {\n\t\tconst blocks = pasteHandler( { HTML } );\n\t\treturn await handleBlocksDrop( blocks );\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<URLSelectionUI\n\t\t\t\t\tisURLInputVisible={ isURLInputVisible }\n\t\t\t\t\tsrc={ src }\n\t\t\t\t\tonChangeSrc={ onChangeSrc }\n\t\t\t\t\tonSubmitSrc={ onSubmitSrc }\n\t\t\t\t\topenURLInput={ openURLInput }\n\t\t\t\t\tcloseURLInput={ closeURLInput }\n\t\t\t\t/>\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderFeaturedImageToggle = () => {\n\t\treturn (\n\t\t\tonToggleFeaturedImage && (\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={ onToggleFeaturedImage }\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Use featured image' ) }\n\t\t\t\t\t</Button>\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\tmode={ 'browse' }\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{ renderFeaturedImageToggle() }\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{ renderFeaturedImageToggle() }\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 ( disableMediaButtons ) {\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"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SACCC,MAAM,EACNC,cAAc,EACdC,WAAW,EACXC,QAAQ,EACRC,WAAW,QACL,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACxD,SAASC,SAAS,QAAQ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{"version":3,"names":["classnames","Button","FormFileUpload","Placeholder","DropZone","withFilters","__","useState","useEffect","useSelect","keyboardReturn","pasteHandler","deprecated","MediaUpload","MediaUploadCheck","URLPopover","store","blockEditorStore","noop","InsertFromURLPopover","src","onChange","onSubmit","onClose","popoverAnchor","createElement","anchor","className","type","placeholder","value","icon","label","URLSelectionUI","isURLInputVisible","onChangeSrc","onSubmitSrc","openURLInput","closeURLInput","setPopoverAnchor","ref","onClick","isPressed","variant","MediaPlaceholder","allowedTypes","labels","mediaPreview","notices","isAppender","accept","addToGallery","multiple","handleUpload","disableDropZone","disableMediaButtons","onError","onSelect","onCancel","onSelectURL","onToggleFeaturedImage","onDoubleClick","onFilesPreUpload","onHTMLDrop","deprecatedOnHTMLDrop","children","mediaLibraryButton","style","since","version","mediaUpload","select","getSettings","setSrc","setIsURLInputVisible","_value$src","onlyAllowsImages","length","every","allowedType","startsWith","event","target","preventDefault","onFilesUpload","files","setMedia","lastMediaPassed","newMedia","filteredMedia","filter","item","id","some","Number","urlSlug","url","includes","concat","map","media","cutOffIndex","lastIndexOf","slice","filesList","onFileChange","handleBlocksDrop","blocks","Array","isArray","recursivelyFindMediaFromBlocks","_blocks","flatMap","block","name","attributes","innerBlocks","mediaBlocks","uploadedMediaList","Promise","all","resolve","reject","window","fetch","then","response","blob","additionalData","title","alt_text","alt","caption","catch","err","HTML","onUpload","defaultRenderPlaceholder","content","instructions","undefined","typesAllowed","firstAllowedType","isOneType","isAudio","isImage","isVideo","placeholderClassName","preview","renderPlaceholder","renderDropZone","onFilesDrop","renderCancelLink","renderUrlSelectionUI","renderFeaturedImageToggle","renderMediaUploadChecked","defaultButton","open","libraryButton","uploadMediaLibraryButton","gallery","mode","render","Fragment","openFileDialog","fallback"],"sources":["@wordpress/block-editor/src/components/media-placeholder/index.js"],"sourcesContent":["/**\n * External dependencies\n */\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 { keyboardReturn } from '@wordpress/icons';\nimport { pasteHandler } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\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 noop = () => {};\n\nconst InsertFromURLPopover = ( {\n\tsrc,\n\tonChange,\n\tonSubmit,\n\tonClose,\n\tpopoverAnchor,\n} ) => (\n\t<URLPopover anchor={ popoverAnchor } 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\nconst URLSelectionUI = ( {\n\tisURLInputVisible,\n\tsrc,\n\tonChangeSrc,\n\tonSubmitSrc,\n\topenURLInput,\n\tcloseURLInput,\n} ) => {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-media-placeholder__url-input-container\"\n\t\t\tref={ setPopoverAnchor }\n\t\t>\n\t\t\t<Button\n\t\t\t\tclassName=\"block-editor-media-placeholder__button\"\n\t\t\t\tonClick={ openURLInput }\n\t\t\t\tisPressed={ isURLInputVisible }\n\t\t\t\tvariant=\"secondary\"\n\t\t\t>\n\t\t\t\t{ __( 'Insert from URL' ) }\n\t\t\t</Button>\n\t\t\t{ isURLInputVisible && (\n\t\t\t\t<InsertFromURLPopover\n\t\t\t\t\tsrc={ src }\n\t\t\t\t\tonChange={ onChangeSrc }\n\t\t\t\t\tonSubmit={ onSubmitSrc }\n\t\t\t\t\tonClose={ closeURLInput }\n\t\t\t\t\tpopoverAnchor={ popoverAnchor }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\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\tdisableDropZone,\n\tdisableMediaButtons,\n\tonError,\n\tonSelect,\n\tonCancel,\n\tonSelectURL,\n\tonToggleFeaturedImage,\n\tonDoubleClick,\n\tonFilesPreUpload = noop,\n\tonHTMLDrop: deprecatedOnHTMLDrop,\n\tchildren,\n\tmediaLibraryButton,\n\tplaceholder,\n\tstyle,\n} ) {\n\tif ( deprecatedOnHTMLDrop ) {\n\t\tdeprecated( 'wp.blockEditor.MediaPlaceholder onHTMLDrop prop', {\n\t\t\tsince: '6.2',\n\t\t\tversion: '6.4',\n\t\t} );\n\t}\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\tasync function handleBlocksDrop( blocks ) {\n\t\tif ( ! blocks || ! Array.isArray( blocks ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction recursivelyFindMediaFromBlocks( _blocks ) {\n\t\t\treturn _blocks.flatMap( ( block ) =>\n\t\t\t\t( block.name === 'core/image' ||\n\t\t\t\t\tblock.name === 'core/audio' ||\n\t\t\t\t\tblock.name === 'core/video' ) &&\n\t\t\t\tblock.attributes.url\n\t\t\t\t\t? [ block ]\n\t\t\t\t\t: recursivelyFindMediaFromBlocks( block.innerBlocks )\n\t\t\t);\n\t\t}\n\n\t\tconst mediaBlocks = recursivelyFindMediaFromBlocks( blocks );\n\n\t\tif ( ! mediaBlocks.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst uploadedMediaList = await Promise.all(\n\t\t\tmediaBlocks.map( ( block ) =>\n\t\t\t\tblock.attributes.id\n\t\t\t\t\t? block.attributes\n\t\t\t\t\t: new Promise( ( resolve, reject ) => {\n\t\t\t\t\t\t\twindow\n\t\t\t\t\t\t\t\t.fetch( block.attributes.url )\n\t\t\t\t\t\t\t\t.then( ( response ) => response.blob() )\n\t\t\t\t\t\t\t\t.then( ( blob ) =>\n\t\t\t\t\t\t\t\t\tmediaUpload( {\n\t\t\t\t\t\t\t\t\t\tfilesList: [ blob ],\n\t\t\t\t\t\t\t\t\t\tadditionalData: {\n\t\t\t\t\t\t\t\t\t\t\ttitle: block.attributes.title,\n\t\t\t\t\t\t\t\t\t\t\talt_text: block.attributes.alt,\n\t\t\t\t\t\t\t\t\t\t\tcaption: block.attributes.caption,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tonFileChange: ( [ media ] ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( media.id ) {\n\t\t\t\t\t\t\t\t\t\t\t\tresolve( media );\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\tallowedTypes,\n\t\t\t\t\t\t\t\t\t\tonError: reject,\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\t.catch( () => resolve( block.attributes.url ) );\n\t\t\t\t\t } )\n\t\t\t)\n\t\t).catch( ( err ) => onError( err ) );\n\n\t\tif ( multiple ) {\n\t\t\tonSelect( uploadedMediaList );\n\t\t} else {\n\t\t\tonSelect( uploadedMediaList[ 0 ] );\n\t\t}\n\t}\n\n\tasync function onHTMLDrop( HTML ) {\n\t\tconst blocks = pasteHandler( { HTML } );\n\t\treturn await handleBlocksDrop( blocks );\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<URLSelectionUI\n\t\t\t\t\tisURLInputVisible={ isURLInputVisible }\n\t\t\t\t\tsrc={ src }\n\t\t\t\t\tonChangeSrc={ onChangeSrc }\n\t\t\t\t\tonSubmitSrc={ onSubmitSrc }\n\t\t\t\t\topenURLInput={ openURLInput }\n\t\t\t\t\tcloseURLInput={ closeURLInput }\n\t\t\t\t/>\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderFeaturedImageToggle = () => {\n\t\treturn (\n\t\t\tonToggleFeaturedImage && (\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={ onToggleFeaturedImage }\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Use featured image' ) }\n\t\t\t\t\t</Button>\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=\"secondary\"\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\tmode={ 'browse' }\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{ renderFeaturedImageToggle() }\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{ renderFeaturedImageToggle() }\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 ( disableMediaButtons ) {\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"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SACCC,MAAM,EACNC,cAAc,EACdC,WAAW,EACXC,QAAQ,EACRC,WAAW,QACL,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACxD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,OAAOC,WAAW,MAAM,iBAAiB;AACzC,OAAOC,gBAAgB,MAAM,uBAAuB;AACpD,OAAOC,UAAU,MAAM,gBAAgB;AACvC,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AAEvD,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,MAAMC,oBAAoB,GAAGA,CAAE;EAC9BC,GAAG;EACHC,QAAQ;EACRC,QAAQ;EACRC,OAAO;EACPC;AACD,CAAC,KACAC,aAAA,CAACV,UAAU;EAACW,MAAM,EAAGF,aAAe;EAACD,OAAO,EAAGA;AAAS,GACvDE,aAAA;EACCE,SAAS,EAAC,gDAAgD;EAC1DL,QAAQ,EAAGA;AAAU,GAErBG,aAAA;EACCE,SAAS,EAAC,iDAAiD;EAC3DC,IAAI,EAAC,MAAM;EACX,cAAatB,EAAE,CAAE,KAAM,CAAG;EAC1BuB,WAAW,EAAGv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AoB,CAAC,CAAC,EACtBC,yBAAyB,CAAC,CAAC,EAC3BF,gBAAgB,CAAC,CAClB,CACF;MACD,OAAOH,iBAAiB,CAAEX,OAAQ,CAAC;IACpC;IAEA,OAAOW,iBAAiB,CAAEU,wBAAyB,CAAC;EACrD,CAAC;EAED,IAAKxG,mBAAmB,EAAG;IAC1B,OAAO9B,aAAA,CAACX,gBAAgB,QAAGwI,cAAc,CAAC,CAAqB,CAAC;EACjE;EAEA,OACC7H,aAAA,CAACX,gBAAgB;IAChBuJ,QAAQ,EAAGhB,iBAAiB,CAAEI,oBAAoB,CAAC,CAAE;EAAG,GAEtDE,wBAAwB,CAAC,CACV,CAAC;AAErB;;AAEA;AACA;AACA;AACA,eAAetJ,WAAW,CAAE,yBAA0B,CAAC,CAAEuC,gBAAiB,CAAC","ignoreList":[]}
|
|
@@ -135,7 +135,9 @@ function useToolbarFocus({
|
|
|
135
135
|
}
|
|
136
136
|
return () => {
|
|
137
137
|
window.cancelAnimationFrame(raf);
|
|
138
|
-
if (!onIndexChange || !navigableToolbarRef)
|
|
138
|
+
if (!onIndexChange || !navigableToolbarRef) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
139
141
|
// When the toolbar element is unmounted and onIndexChange is passed, we
|
|
140
142
|
// pass the focused toolbar item index so it can be hydrated later.
|
|
141
143
|
const items = getAllFocusableToolbarItemsIn(navigableToolbarRef);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NavigableMenu","Toolbar","useState","useRef","useLayoutEffect","useEffect","useCallback","useSelect","deprecated","focus","useShortcut","ESCAPE","store","blockEditorStore","unlock","hasOnlyToolbarItem","elements","dataProp","some","element","dataset","getAllFocusableToolbarItemsIn","container","Array","from","querySelectorAll","hasFocusWithin","contains","ownerDocument","activeElement","focusFirstTabbableIn","firstTabbable","tabbable","find","preventScroll","useIsAccessibleToolbar","toolbarRef","initialAccessibleToolbarState","isAccessibleToolbar","setIsAccessibleToolbar","determineIsAccessibleToolbar","tabbables","current","onlyToolbarItem","since","alternative","link","observer","window","MutationObserver","observe","childList","subtree","disconnect","useToolbarFocus","focusOnMount","defaultIndex","onIndexChange","shouldUseKeyboardFocusShortcut","focusEditorOnEscape","initialFocusOnMount","initialIndex","focusToolbar","focusToolbarViaShortcut","navigableToolbarRef","raf","requestAnimationFrame","items","index","cancelAnimationFrame","findIndex","item","tabIndex","getLastFocus","handleKeyDown","event","lastFocus","keyCode","preventDefault","addEventListener","removeEventListener","NavigableToolbar","children","__experimentalInitialIndex","__experimentalOnIndexChange","props","createElement","label","ref","orientation","role"],"sources":["@wordpress/block-editor/src/components/navigable-toolbar/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { NavigableMenu, Toolbar } from '@wordpress/components';\nimport {\n\tuseState,\n\tuseRef,\n\tuseLayoutEffect,\n\tuseEffect,\n\tuseCallback,\n} from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { focus } from '@wordpress/dom';\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nfunction hasOnlyToolbarItem( elements ) {\n\tconst dataProp = 'toolbarItem';\n\treturn ! elements.some( ( element ) => ! ( dataProp in element.dataset ) );\n}\n\nfunction getAllFocusableToolbarItemsIn( container ) {\n\treturn Array.from(\n\t\tcontainer.querySelectorAll( '[data-toolbar-item]:not([disabled])' )\n\t);\n}\n\nfunction hasFocusWithin( container ) {\n\treturn container.contains( container.ownerDocument.activeElement );\n}\n\nfunction focusFirstTabbableIn( container ) {\n\tconst [ firstTabbable ] = focus.tabbable.find( container );\n\n\tif ( firstTabbable ) {\n\t\tfirstTabbable.focus( {\n\t\t\t// When focusing newly mounted toolbars,\n\t\t\t// the position of the popover is often not right on the first render\n\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\tpreventScroll: true,\n\t\t} );\n\t}\n}\n\nfunction useIsAccessibleToolbar( toolbarRef ) {\n\t/*\n\t * By default, we'll assume the starting accessible state of the Toolbar\n\t * is true, as it seems to be the most common case.\n\t *\n\t * Transitioning from an (initial) false to true state causes the\n\t * <Toolbar /> component to mount twice, which is causing undesired\n\t * side-effects. These side-effects appear to only affect certain\n\t * E2E tests.\n\t *\n\t * This was initial discovered in this pull-request:\n\t * https://github.com/WordPress/gutenberg/pull/23425\n\t */\n\tconst initialAccessibleToolbarState = true;\n\n\t// By default, it's gonna render NavigableMenu. If all the tabbable elements\n\t// inside the toolbar are ToolbarItem components (or derived components like\n\t// ToolbarButton), then we can wrap them with the accessible Toolbar\n\t// component.\n\tconst [ isAccessibleToolbar, setIsAccessibleToolbar ] = useState(\n\t\tinitialAccessibleToolbarState\n\t);\n\n\tconst determineIsAccessibleToolbar = useCallback( () => {\n\t\tconst tabbables = focus.tabbable.find( toolbarRef.current );\n\t\tconst onlyToolbarItem = hasOnlyToolbarItem( tabbables );\n\t\tif ( ! onlyToolbarItem ) {\n\t\t\tdeprecated( 'Using custom components as toolbar controls', {\n\t\t\t\tsince: '5.6',\n\t\t\t\talternative:\n\t\t\t\t\t'ToolbarItem, ToolbarButton or ToolbarDropdownMenu components',\n\t\t\t\tlink: 'https://developer.wordpress.org/block-editor/components/toolbar-button/#inside-blockcontrols',\n\t\t\t} );\n\t\t}\n\t\tsetIsAccessibleToolbar( onlyToolbarItem );\n\t}, [ toolbarRef ] );\n\n\tuseLayoutEffect( () => {\n\t\t// Toolbar buttons may be rendered asynchronously, so we use\n\t\t// MutationObserver to check if the toolbar subtree has been modified.\n\t\tconst observer = new window.MutationObserver(\n\t\t\tdetermineIsAccessibleToolbar\n\t\t);\n\t\tobserver.observe( toolbarRef.current, {\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t} );\n\t\treturn () => observer.disconnect();\n\t}, [ determineIsAccessibleToolbar, isAccessibleToolbar, toolbarRef ] );\n\n\treturn isAccessibleToolbar;\n}\n\nfunction useToolbarFocus( {\n\ttoolbarRef,\n\tfocusOnMount,\n\tisAccessibleToolbar,\n\tdefaultIndex,\n\tonIndexChange,\n\tshouldUseKeyboardFocusShortcut,\n\tfocusEditorOnEscape,\n} ) {\n\t// Make sure we don't use modified versions of this prop.\n\tconst [ initialFocusOnMount ] = useState( focusOnMount );\n\tconst [ initialIndex ] = useState( defaultIndex );\n\n\tconst focusToolbar = useCallback( () => {\n\t\tfocusFirstTabbableIn( toolbarRef.current );\n\t}, [ toolbarRef ] );\n\n\tconst focusToolbarViaShortcut = () => {\n\t\tif ( shouldUseKeyboardFocusShortcut ) {\n\t\t\tfocusToolbar();\n\t\t}\n\t};\n\n\t// Focus on toolbar when pressing alt+F10 when the toolbar is visible.\n\tuseShortcut( 'core/block-editor/focus-toolbar', focusToolbarViaShortcut );\n\n\tuseEffect( () => {\n\t\tif ( initialFocusOnMount ) {\n\t\t\tfocusToolbar();\n\t\t}\n\t}, [ isAccessibleToolbar, initialFocusOnMount, focusToolbar ] );\n\n\tuseEffect( () => {\n\t\t// Store ref so we have access on useEffect cleanup: https://legacy.reactjs.org/blog/2020/08/10/react-v17-rc.html#effect-cleanup-timing\n\t\tconst navigableToolbarRef = toolbarRef.current;\n\t\t// If initialIndex is passed, we focus on that toolbar item when the\n\t\t// toolbar gets mounted and initial focus is not forced.\n\t\t// We have to wait for the next browser paint because block controls aren't\n\t\t// rendered right away when the toolbar gets mounted.\n\t\tlet raf = 0;\n\n\t\t// If the toolbar already had focus before the render, we don't want to move it.\n\t\t// https://github.com/WordPress/gutenberg/issues/58511\n\t\tif (\n\t\t\t! initialFocusOnMount &&\n\t\t\t! hasFocusWithin( navigableToolbarRef )\n\t\t) {\n\t\t\traf = window.requestAnimationFrame( () => {\n\t\t\t\tconst items =\n\t\t\t\t\tgetAllFocusableToolbarItemsIn( navigableToolbarRef );\n\t\t\t\tconst index = initialIndex || 0;\n\t\t\t\tif ( items[ index ] && hasFocusWithin( navigableToolbarRef ) ) {\n\t\t\t\t\titems[ index ].focus( {\n\t\t\t\t\t\t// When focusing newly mounted toolbars,\n\t\t\t\t\t\t// the position of the popover is often not right on the first render\n\t\t\t\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\t\t\t\tpreventScroll: true,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t\treturn () => {\n\t\t\twindow.cancelAnimationFrame( raf );\n\t\t\tif ( ! onIndexChange || ! navigableToolbarRef ) return;\n\t\t\t// When the toolbar element is unmounted and onIndexChange is passed, we\n\t\t\t// pass the focused toolbar item index so it can be hydrated later.\n\t\t\tconst items = getAllFocusableToolbarItemsIn( navigableToolbarRef );\n\t\t\tconst index = items.findIndex( ( item ) => item.tabIndex === 0 );\n\t\t\tonIndexChange( index );\n\t\t};\n\t}, [ initialIndex, initialFocusOnMount, onIndexChange, toolbarRef ] );\n\n\tconst { getLastFocus } = unlock( useSelect( blockEditorStore ) );\n\t/**\n\t * Handles returning focus to the block editor canvas when pressing escape.\n\t */\n\tuseEffect( () => {\n\t\tconst navigableToolbarRef = toolbarRef.current;\n\n\t\tif ( focusEditorOnEscape ) {\n\t\t\tconst handleKeyDown = ( event ) => {\n\t\t\t\tconst lastFocus = getLastFocus();\n\t\t\t\tif ( event.keyCode === ESCAPE && lastFocus?.current ) {\n\t\t\t\t\t// Focus the last focused element when pressing escape.\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tlastFocus.current.focus();\n\t\t\t\t}\n\t\t\t};\n\t\t\tnavigableToolbarRef.addEventListener( 'keydown', handleKeyDown );\n\t\t\treturn () => {\n\t\t\t\tnavigableToolbarRef.removeEventListener(\n\t\t\t\t\t'keydown',\n\t\t\t\t\thandleKeyDown\n\t\t\t\t);\n\t\t\t};\n\t\t}\n\t}, [ focusEditorOnEscape, getLastFocus, toolbarRef ] );\n}\n\nexport default function NavigableToolbar( {\n\tchildren,\n\tfocusOnMount,\n\tfocusEditorOnEscape = false,\n\tshouldUseKeyboardFocusShortcut = true,\n\t__experimentalInitialIndex: initialIndex,\n\t__experimentalOnIndexChange: onIndexChange,\n\t...props\n} ) {\n\tconst toolbarRef = useRef();\n\tconst isAccessibleToolbar = useIsAccessibleToolbar( toolbarRef );\n\n\tuseToolbarFocus( {\n\t\ttoolbarRef,\n\t\tfocusOnMount,\n\t\tdefaultIndex: initialIndex,\n\t\tonIndexChange,\n\t\tisAccessibleToolbar,\n\t\tshouldUseKeyboardFocusShortcut,\n\t\tfocusEditorOnEscape,\n\t} );\n\n\tif ( isAccessibleToolbar ) {\n\t\treturn (\n\t\t\t<Toolbar\n\t\t\t\tlabel={ props[ 'aria-label' ] }\n\t\t\t\tref={ toolbarRef }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</Toolbar>\n\t\t);\n\t}\n\n\treturn (\n\t\t<NavigableMenu\n\t\t\torientation=\"horizontal\"\n\t\t\trole=\"toolbar\"\n\t\t\tref={ toolbarRef }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</NavigableMenu>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,OAAO,QAAQ,uBAAuB;AAC9D,SACCC,QAAQ,EACRC,MAAM,EACNC,eAAe,EACfC,SAAS,EACTC,WAAW,QACL,oBAAoB;AAC3B,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SAASC,WAAW,QAAQ,+BAA+B;AAC3D,SAASC,MAAM,QAAQ,qBAAqB;;AAE5C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,kBAAkBA,CAAEC,QAAQ,EAAG;EACvC,MAAMC,QAAQ,GAAG,aAAa;EAC9B,OAAO,CAAED,QAAQ,CAACE,IAAI,CAAIC,OAAO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
+
{"version":3,"names":["NavigableMenu","Toolbar","useState","useRef","useLayoutEffect","useEffect","useCallback","useSelect","deprecated","focus","useShortcut","ESCAPE","store","blockEditorStore","unlock","hasOnlyToolbarItem","elements","dataProp","some","element","dataset","getAllFocusableToolbarItemsIn","container","Array","from","querySelectorAll","hasFocusWithin","contains","ownerDocument","activeElement","focusFirstTabbableIn","firstTabbable","tabbable","find","preventScroll","useIsAccessibleToolbar","toolbarRef","initialAccessibleToolbarState","isAccessibleToolbar","setIsAccessibleToolbar","determineIsAccessibleToolbar","tabbables","current","onlyToolbarItem","since","alternative","link","observer","window","MutationObserver","observe","childList","subtree","disconnect","useToolbarFocus","focusOnMount","defaultIndex","onIndexChange","shouldUseKeyboardFocusShortcut","focusEditorOnEscape","initialFocusOnMount","initialIndex","focusToolbar","focusToolbarViaShortcut","navigableToolbarRef","raf","requestAnimationFrame","items","index","cancelAnimationFrame","findIndex","item","tabIndex","getLastFocus","handleKeyDown","event","lastFocus","keyCode","preventDefault","addEventListener","removeEventListener","NavigableToolbar","children","__experimentalInitialIndex","__experimentalOnIndexChange","props","createElement","label","ref","orientation","role"],"sources":["@wordpress/block-editor/src/components/navigable-toolbar/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { NavigableMenu, Toolbar } from '@wordpress/components';\nimport {\n\tuseState,\n\tuseRef,\n\tuseLayoutEffect,\n\tuseEffect,\n\tuseCallback,\n} from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { focus } from '@wordpress/dom';\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nfunction hasOnlyToolbarItem( elements ) {\n\tconst dataProp = 'toolbarItem';\n\treturn ! elements.some( ( element ) => ! ( dataProp in element.dataset ) );\n}\n\nfunction getAllFocusableToolbarItemsIn( container ) {\n\treturn Array.from(\n\t\tcontainer.querySelectorAll( '[data-toolbar-item]:not([disabled])' )\n\t);\n}\n\nfunction hasFocusWithin( container ) {\n\treturn container.contains( container.ownerDocument.activeElement );\n}\n\nfunction focusFirstTabbableIn( container ) {\n\tconst [ firstTabbable ] = focus.tabbable.find( container );\n\n\tif ( firstTabbable ) {\n\t\tfirstTabbable.focus( {\n\t\t\t// When focusing newly mounted toolbars,\n\t\t\t// the position of the popover is often not right on the first render\n\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\tpreventScroll: true,\n\t\t} );\n\t}\n}\n\nfunction useIsAccessibleToolbar( toolbarRef ) {\n\t/*\n\t * By default, we'll assume the starting accessible state of the Toolbar\n\t * is true, as it seems to be the most common case.\n\t *\n\t * Transitioning from an (initial) false to true state causes the\n\t * <Toolbar /> component to mount twice, which is causing undesired\n\t * side-effects. These side-effects appear to only affect certain\n\t * E2E tests.\n\t *\n\t * This was initial discovered in this pull-request:\n\t * https://github.com/WordPress/gutenberg/pull/23425\n\t */\n\tconst initialAccessibleToolbarState = true;\n\n\t// By default, it's gonna render NavigableMenu. If all the tabbable elements\n\t// inside the toolbar are ToolbarItem components (or derived components like\n\t// ToolbarButton), then we can wrap them with the accessible Toolbar\n\t// component.\n\tconst [ isAccessibleToolbar, setIsAccessibleToolbar ] = useState(\n\t\tinitialAccessibleToolbarState\n\t);\n\n\tconst determineIsAccessibleToolbar = useCallback( () => {\n\t\tconst tabbables = focus.tabbable.find( toolbarRef.current );\n\t\tconst onlyToolbarItem = hasOnlyToolbarItem( tabbables );\n\t\tif ( ! onlyToolbarItem ) {\n\t\t\tdeprecated( 'Using custom components as toolbar controls', {\n\t\t\t\tsince: '5.6',\n\t\t\t\talternative:\n\t\t\t\t\t'ToolbarItem, ToolbarButton or ToolbarDropdownMenu components',\n\t\t\t\tlink: 'https://developer.wordpress.org/block-editor/components/toolbar-button/#inside-blockcontrols',\n\t\t\t} );\n\t\t}\n\t\tsetIsAccessibleToolbar( onlyToolbarItem );\n\t}, [ toolbarRef ] );\n\n\tuseLayoutEffect( () => {\n\t\t// Toolbar buttons may be rendered asynchronously, so we use\n\t\t// MutationObserver to check if the toolbar subtree has been modified.\n\t\tconst observer = new window.MutationObserver(\n\t\t\tdetermineIsAccessibleToolbar\n\t\t);\n\t\tobserver.observe( toolbarRef.current, {\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t} );\n\t\treturn () => observer.disconnect();\n\t}, [ determineIsAccessibleToolbar, isAccessibleToolbar, toolbarRef ] );\n\n\treturn isAccessibleToolbar;\n}\n\nfunction useToolbarFocus( {\n\ttoolbarRef,\n\tfocusOnMount,\n\tisAccessibleToolbar,\n\tdefaultIndex,\n\tonIndexChange,\n\tshouldUseKeyboardFocusShortcut,\n\tfocusEditorOnEscape,\n} ) {\n\t// Make sure we don't use modified versions of this prop.\n\tconst [ initialFocusOnMount ] = useState( focusOnMount );\n\tconst [ initialIndex ] = useState( defaultIndex );\n\n\tconst focusToolbar = useCallback( () => {\n\t\tfocusFirstTabbableIn( toolbarRef.current );\n\t}, [ toolbarRef ] );\n\n\tconst focusToolbarViaShortcut = () => {\n\t\tif ( shouldUseKeyboardFocusShortcut ) {\n\t\t\tfocusToolbar();\n\t\t}\n\t};\n\n\t// Focus on toolbar when pressing alt+F10 when the toolbar is visible.\n\tuseShortcut( 'core/block-editor/focus-toolbar', focusToolbarViaShortcut );\n\n\tuseEffect( () => {\n\t\tif ( initialFocusOnMount ) {\n\t\t\tfocusToolbar();\n\t\t}\n\t}, [ isAccessibleToolbar, initialFocusOnMount, focusToolbar ] );\n\n\tuseEffect( () => {\n\t\t// Store ref so we have access on useEffect cleanup: https://legacy.reactjs.org/blog/2020/08/10/react-v17-rc.html#effect-cleanup-timing\n\t\tconst navigableToolbarRef = toolbarRef.current;\n\t\t// If initialIndex is passed, we focus on that toolbar item when the\n\t\t// toolbar gets mounted and initial focus is not forced.\n\t\t// We have to wait for the next browser paint because block controls aren't\n\t\t// rendered right away when the toolbar gets mounted.\n\t\tlet raf = 0;\n\n\t\t// If the toolbar already had focus before the render, we don't want to move it.\n\t\t// https://github.com/WordPress/gutenberg/issues/58511\n\t\tif (\n\t\t\t! initialFocusOnMount &&\n\t\t\t! hasFocusWithin( navigableToolbarRef )\n\t\t) {\n\t\t\traf = window.requestAnimationFrame( () => {\n\t\t\t\tconst items =\n\t\t\t\t\tgetAllFocusableToolbarItemsIn( navigableToolbarRef );\n\t\t\t\tconst index = initialIndex || 0;\n\t\t\t\tif ( items[ index ] && hasFocusWithin( navigableToolbarRef ) ) {\n\t\t\t\t\titems[ index ].focus( {\n\t\t\t\t\t\t// When focusing newly mounted toolbars,\n\t\t\t\t\t\t// the position of the popover is often not right on the first render\n\t\t\t\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\t\t\t\tpreventScroll: true,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t\treturn () => {\n\t\t\twindow.cancelAnimationFrame( raf );\n\t\t\tif ( ! onIndexChange || ! navigableToolbarRef ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// When the toolbar element is unmounted and onIndexChange is passed, we\n\t\t\t// pass the focused toolbar item index so it can be hydrated later.\n\t\t\tconst items = getAllFocusableToolbarItemsIn( navigableToolbarRef );\n\t\t\tconst index = items.findIndex( ( item ) => item.tabIndex === 0 );\n\t\t\tonIndexChange( index );\n\t\t};\n\t}, [ initialIndex, initialFocusOnMount, onIndexChange, toolbarRef ] );\n\n\tconst { getLastFocus } = unlock( useSelect( blockEditorStore ) );\n\t/**\n\t * Handles returning focus to the block editor canvas when pressing escape.\n\t */\n\tuseEffect( () => {\n\t\tconst navigableToolbarRef = toolbarRef.current;\n\n\t\tif ( focusEditorOnEscape ) {\n\t\t\tconst handleKeyDown = ( event ) => {\n\t\t\t\tconst lastFocus = getLastFocus();\n\t\t\t\tif ( event.keyCode === ESCAPE && lastFocus?.current ) {\n\t\t\t\t\t// Focus the last focused element when pressing escape.\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tlastFocus.current.focus();\n\t\t\t\t}\n\t\t\t};\n\t\t\tnavigableToolbarRef.addEventListener( 'keydown', handleKeyDown );\n\t\t\treturn () => {\n\t\t\t\tnavigableToolbarRef.removeEventListener(\n\t\t\t\t\t'keydown',\n\t\t\t\t\thandleKeyDown\n\t\t\t\t);\n\t\t\t};\n\t\t}\n\t}, [ focusEditorOnEscape, getLastFocus, toolbarRef ] );\n}\n\nexport default function NavigableToolbar( {\n\tchildren,\n\tfocusOnMount,\n\tfocusEditorOnEscape = false,\n\tshouldUseKeyboardFocusShortcut = true,\n\t__experimentalInitialIndex: initialIndex,\n\t__experimentalOnIndexChange: onIndexChange,\n\t...props\n} ) {\n\tconst toolbarRef = useRef();\n\tconst isAccessibleToolbar = useIsAccessibleToolbar( toolbarRef );\n\n\tuseToolbarFocus( {\n\t\ttoolbarRef,\n\t\tfocusOnMount,\n\t\tdefaultIndex: initialIndex,\n\t\tonIndexChange,\n\t\tisAccessibleToolbar,\n\t\tshouldUseKeyboardFocusShortcut,\n\t\tfocusEditorOnEscape,\n\t} );\n\n\tif ( isAccessibleToolbar ) {\n\t\treturn (\n\t\t\t<Toolbar\n\t\t\t\tlabel={ props[ 'aria-label' ] }\n\t\t\t\tref={ toolbarRef }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</Toolbar>\n\t\t);\n\t}\n\n\treturn (\n\t\t<NavigableMenu\n\t\t\torientation=\"horizontal\"\n\t\t\trole=\"toolbar\"\n\t\t\tref={ toolbarRef }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</NavigableMenu>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,OAAO,QAAQ,uBAAuB;AAC9D,SACCC,QAAQ,EACRC,MAAM,EACNC,eAAe,EACfC,SAAS,EACTC,WAAW,QACL,oBAAoB;AAC3B,SAASC,SAAS,QAAQ,iBAA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;IAC9BC;EACD,CAAE,CAAC;EAEH,IAAKrB,mBAAmB,EAAG;IAC1B,OACCgD,aAAA,CAACrF,OAAO;MACPsF,KAAK,EAAGF,KAAK,CAAE,YAAY,CAAI;MAC/BG,GAAG,EAAGpD,UAAY;MAAA,GACbiD;IAAK,GAERH,QACM,CAAC;EAEZ;EAEA,OACCI,aAAA,CAACtF,aAAa;IACbyF,WAAW,EAAC,YAAY;IACxBC,IAAI,EAAC,SAAS;IACdF,GAAG,EAAGpD,UAAY;IAAA,GACbiD;EAAK,GAERH,QACY,CAAC;AAElB","ignoreList":[]}
|
|
@@ -3,16 +3,15 @@ import { createElement } from "react";
|
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { createContext, useMemo } from '@wordpress/element';
|
|
6
|
+
import { observableMap } from '@wordpress/compose';
|
|
6
7
|
export const BlockRefs = createContext({
|
|
7
|
-
|
|
8
|
-
callbacks: new Map()
|
|
8
|
+
refsMap: observableMap()
|
|
9
9
|
});
|
|
10
10
|
export function BlockRefsProvider({
|
|
11
11
|
children
|
|
12
12
|
}) {
|
|
13
13
|
const value = useMemo(() => ({
|
|
14
|
-
|
|
15
|
-
callbacks: new Map()
|
|
14
|
+
refsMap: observableMap()
|
|
16
15
|
}), []);
|
|
17
16
|
return createElement(BlockRefs.Provider, {
|
|
18
17
|
value: value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useMemo","
|
|
1
|
+
{"version":3,"names":["createContext","useMemo","observableMap","BlockRefs","refsMap","BlockRefsProvider","children","value","createElement","Provider"],"sources":["@wordpress/block-editor/src/components/provider/block-refs-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useMemo } from '@wordpress/element';\nimport { observableMap } from '@wordpress/compose';\n\nexport const BlockRefs = createContext( { refsMap: observableMap() } );\n\nexport function BlockRefsProvider( { children } ) {\n\tconst value = useMemo( () => ( { refsMap: observableMap() } ), [] );\n\treturn (\n\t\t<BlockRefs.Provider value={ value }>{ children }</BlockRefs.Provider>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,OAAO,QAAQ,oBAAoB;AAC3D,SAASC,aAAa,QAAQ,oBAAoB;AAElD,OAAO,MAAMC,SAAS,GAAGH,aAAa,CAAE;EAAEI,OAAO,EAAEF,aAAa,CAAC;AAAE,CAAE,CAAC;AAEtE,OAAO,SAASG,iBAAiBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACjD,MAAMC,KAAK,GAAGN,OAAO,CAAE,OAAQ;IAAEG,OAAO,EAAEF,aAAa,CAAC;EAAE,CAAC,CAAE,EAAE,EAAG,CAAC;EACnE,OACCM,aAAA,CAACL,SAAS,CAACM,QAAQ;IAACF,KAAK,EAAGA;EAAO,GAAGD,QAA8B,CAAC;AAEvE","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useEffect, useRef } from '@wordpress/element';
|
|
5
|
-
import { useRegistry
|
|
5
|
+
import { useRegistry } from '@wordpress/data';
|
|
6
6
|
import { cloneBlock } from '@wordpress/blocks';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -84,9 +84,6 @@ export default function useBlockSync({
|
|
|
84
84
|
getSelectionStart,
|
|
85
85
|
getSelectionEnd
|
|
86
86
|
} = registry.select(blockEditorStore);
|
|
87
|
-
const isControlled = useSelect(select => {
|
|
88
|
-
return !clientId || select(blockEditorStore).areInnerBlocksControlled(clientId);
|
|
89
|
-
}, [clientId]);
|
|
90
87
|
const pendingChanges = useRef({
|
|
91
88
|
incoming: null,
|
|
92
89
|
outgoing: []
|
|
@@ -171,14 +168,6 @@ export default function useBlockSync({
|
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
170
|
}, [controlledBlocks, clientId]);
|
|
174
|
-
useEffect(() => {
|
|
175
|
-
// When the block becomes uncontrolled, it means its inner state has been reset
|
|
176
|
-
// we need to take the blocks again from the external value property.
|
|
177
|
-
if (!isControlled) {
|
|
178
|
-
pendingChanges.current.outgoing = [];
|
|
179
|
-
setControlledBlocks();
|
|
180
|
-
}
|
|
181
|
-
}, [isControlled]);
|
|
182
171
|
useEffect(() => {
|
|
183
172
|
const {
|
|
184
173
|
getSelectedBlocksInitialCaretPosition,
|
|
@@ -198,7 +187,9 @@ export default function useBlockSync({
|
|
|
198
187
|
// the subscription is triggering for a block (`clientId !== null`)
|
|
199
188
|
// and its block name can't be found because it's not on the list.
|
|
200
189
|
// (`getBlockName( clientId ) === null`).
|
|
201
|
-
if (clientId !== null && getBlockName(clientId) === null)
|
|
190
|
+
if (clientId !== null && getBlockName(clientId) === null) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
202
193
|
|
|
203
194
|
// When RESET_BLOCKS on parent blocks get called, the controlled blocks
|
|
204
195
|
// can reset to uncontrolled, in these situations, it means we need to populate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useRegistry","useSelect","cloneBlock","store","blockEditorStore","undoIgnoreBlocks","noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","getBlockName","getBlocks","getSelectionStart","getSelectionEnd","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","unsetControlledBlocks","onInputRef","onChangeRef","includes","length","selectionStart","selectionEnd","initialPosition","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent","undoIgnore","has","delete"],"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"sourcesContent":["/**\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';\nimport { undoIgnoreBlocks } from '../../store/undo-ignore';\n\nconst noop = () => {};\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, getSelectionStart, getSelectionEnd } =\n\t\tregistry.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// Clean up the changes made by setControlledBlocks() when the component\n\t// containing useBlockSync() unmounts.\n\tconst unsetControlledBlocks = () => {\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\tsetHasControlledInnerBlocks( clientId, false );\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\treplaceInnerBlocks( clientId, [] );\n\t\t} else {\n\t\t\tresetBlocks( [] );\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\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === 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\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\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\tconst undoIgnore = undoIgnoreBlocks.has( blocks );\n\t\t\t\tif ( undoIgnore ) {\n\t\t\t\t\tundoIgnoreBlocks.delete( blocks );\n\t\t\t\t}\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:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t\tundoIgnore,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t}, blockEditorStore );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tunsetControlledBlocks();\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,UAAU,QAAQ,mBAAmB;;AAE9C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,gBAAgB,QAAQ,yBAAyB;AAE1D,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,YAAYA,CAAE;EACrCC,QAAQ,GAAG,IAAI;EACfC,KAAK,EAAEC,gBAAgB;EACvBC,SAAS,EAAEC,mBAAmB;EAC9BC,QAAQ,GAAGP,IAAI;EACfQ,OAAO,GAAGR;AACX,CAAC,EAAG;EACH,MAAMS,QAAQ,GAAGf,WAAW,CAAC,CAAC;EAE9B,MAAM;IACLgB,WAAW;IACXC,cAAc;IACdC,kBAAkB;IAClBC,2BAA2B;IAC3BC;EACD,CAAC,GAAGL,QAAQ,CAACM,QAAQ,CAAEjB,gBAAiB,CAAC;EACzC,MAAM;IAAEkB,YAAY;IAAEC,SAAS;IAAEC,iBAAiB;IAAEC;EAAgB,CAAC,GACpEV,QAAQ,CAACW,MAAM,CAAEtB,gBAAiB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AAkB,IACpBF,eAAe,IACf,CAAEL,YAAY;MAEf,IAAKO,kBAAkB,IAAIC,oBAAoB,EAAG;QACjDR,YAAY,GAAGK,eAAe;QAC9B;QACA;QACA;QACA;QACA3B,cAAc,CAACS,OAAO,CAACP,QAAQ,CAAC6B,IAAI,CAAEV,MAAO,CAAC;;QAE9C;QACA;QACA,MAAMW,YAAY,GAAGV,YAAY,GAC9BV,WAAW,CAACH,OAAO,GACnBE,UAAU,CAACF,OAAO;QACrB,MAAMwB,UAAU,GAAGzD,gBAAgB,CAAC0D,GAAG,CAAEb,MAAO,CAAC;QACjD,IAAKY,UAAU,EAAG;UACjBzD,gBAAgB,CAAC2D,MAAM,CAAEd,MAAO,CAAC;QAClC;QACAW,YAAY,CAAEX,MAAM,EAAE;UACrBvC,SAAS,EAAE;YACViC,cAAc,EAAEpB,iBAAiB,CAAC,CAAC;YACnCqB,YAAY,EAAEpB,eAAe,CAAC,CAAC;YAC/BqB,eAAe,EACdC,qCAAqC,CAAC;UACxC,CAAC;UACDe;QACD,CAAE,CAAC;MACJ;MACAV,0BAA0B,GAAGM,kBAAkB;IAChD,CAAC,EAAEtD,gBAAiB,CAAC;IAErB,OAAO,MAAM;MACZ4B,UAAU,CAACM,OAAO,GAAG,KAAK;MAC1Be,WAAW,CAAC,CAAC;IACd,CAAC;EACF,CAAC,EAAE,CAAEtC,QAAQ,EAAEP,QAAQ,CAAG,CAAC;EAE3BV,SAAS,CAAE,MAAM;IAChB,OAAO,MAAM;MACZyC,qBAAqB,CAAC,CAAC;IACxB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useRegistry","cloneBlock","store","blockEditorStore","undoIgnoreBlocks","noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","getBlockName","getBlocks","getSelectionStart","getSelectionEnd","select","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","unsetControlledBlocks","onInputRef","onChangeRef","includes","length","selectionStart","selectionEnd","initialPosition","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","areInnerBlocksControlled","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent","undoIgnore","has","delete"],"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"sourcesContent":["/**\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';\nimport { undoIgnoreBlocks } from '../../store/undo-ignore';\n\nconst noop = () => {};\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, getSelectionStart, getSelectionEnd } =\n\t\tregistry.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\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// Clean up the changes made by setControlledBlocks() when the component\n\t// containing useBlockSync() unmounts.\n\tconst unsetControlledBlocks = () => {\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\tsetHasControlledInnerBlocks( clientId, false );\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\treplaceInnerBlocks( clientId, [] );\n\t\t} else {\n\t\t\tresetBlocks( [] );\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\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === 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\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\t\t\t}\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\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\tconst undoIgnore = undoIgnoreBlocks.has( blocks );\n\t\t\t\tif ( undoIgnore ) {\n\t\t\t\t\tundoIgnoreBlocks.delete( blocks );\n\t\t\t\t}\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:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t\tundoIgnore,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t}, blockEditorStore );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tunsetControlledBlocks();\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,UAAU,QAAQ,mBAAmB;;AAE9C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,gBAAgB,QAAQ,yBAAyB;AAE1D,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,YAAYA,CAAE;EACrCC,QAAQ,GAAG,IAAI;EACfC,KAAK,EAAEC,gBAAgB;EACvBC,SAAS,EAAEC,mBAAmB;EAC9BC,QAAQ,GAAGP,IAAI;EACfQ,OAAO,GAAGR;AACX,CAAC,EAAG;EACH,MAAMS,QAAQ,GAAGd,WAAW,CAAC,CAAC;EAE9B,MAAM;IACLe,WAAW;IACXC,cAAc;IACdC,kBAAkB;IAClBC,2BAA2B;IAC3BC;EACD,CAAC,GAAGL,QAAQ,CAACM,QAAQ,CAAEjB,gBAAiB,CAAC;EACzC,MAAM;IAAEkB,YAAY;IAAEC,SAAS;IAAEC,iBAA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yB,UAAU,GAAGxD,gBAAgB,CAACyD,GAAG,CAAEb,MAAO,CAAC;QACjD,IAAKY,UAAU,EAAG;UACjBxD,gBAAgB,CAAC0D,MAAM,CAAEd,MAAO,CAAC;QAClC;QACAW,YAAY,CAAEX,MAAM,EAAE;UACrBtC,SAAS,EAAE;YACV+B,cAAc,EAAElB,iBAAiB,CAAC,CAAC;YACnCmB,YAAY,EAAElB,eAAe,CAAC,CAAC;YAC/BmB,eAAe,EACdC,qCAAqC,CAAC;UACxC,CAAC;UACDgB;QACD,CAAE,CAAC;MACJ;MACAV,0BAA0B,GAAGM,kBAAkB;IAChD,CAAC,EAAErD,gBAAiB,CAAC;IAErB,OAAO,MAAM;MACZ0B,UAAU,CAACM,OAAO,GAAG,KAAK;MAC1BgB,WAAW,CAAC,CAAC;IACd,CAAC;EACF,CAAC,EAAE,CAAErC,QAAQ,EAAEP,QAAQ,CAAG,CAAC;EAE3BT,SAAS,CAAE,MAAM;IAChB,OAAO,MAAM;MACZsC,qBAAqB,CAAC,CAAC;IACxB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { insert, isCollapsed } from '@wordpress/rich-text';
|
|
5
|
+
import { applyFilters } from '@wordpress/hooks';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as blockEditorStore } from '../../../store';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* When typing over a selection, the selection will we wrapped by a matching
|
|
14
|
+
* character pair. The second character is optional, it defaults to the first
|
|
15
|
+
* character.
|
|
16
|
+
*
|
|
17
|
+
* @type {string[]} Array of character pairs.
|
|
18
|
+
*/
|
|
19
|
+
const wrapSelectionSettings = ['`', '"', "'", '“”', '‘’'];
|
|
20
|
+
export default (props => element => {
|
|
21
|
+
function onInput(event) {
|
|
22
|
+
const {
|
|
23
|
+
inputType,
|
|
24
|
+
data
|
|
25
|
+
} = event;
|
|
26
|
+
const {
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
registry
|
|
30
|
+
} = props.current;
|
|
31
|
+
|
|
32
|
+
// Only run the rules when inserting text.
|
|
33
|
+
if (inputType !== 'insertText') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (isCollapsed(value)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const pair = applyFilters('blockEditor.wrapSelectionSettings', wrapSelectionSettings).find(([startChar, endChar]) => startChar === data || endChar === data);
|
|
40
|
+
if (!pair) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const [startChar, endChar = startChar] = pair;
|
|
44
|
+
const start = value.start;
|
|
45
|
+
const end = value.end + startChar.length;
|
|
46
|
+
let newValue = insert(value, startChar, start, start);
|
|
47
|
+
newValue = insert(newValue, endChar, end, end);
|
|
48
|
+
const {
|
|
49
|
+
__unstableMarkLastChangeAsPersistent,
|
|
50
|
+
__unstableMarkAutomaticChange
|
|
51
|
+
} = registry.dispatch(blockEditorStore);
|
|
52
|
+
__unstableMarkLastChangeAsPersistent();
|
|
53
|
+
onChange(newValue);
|
|
54
|
+
__unstableMarkAutomaticChange();
|
|
55
|
+
const init = {};
|
|
56
|
+
for (const key in event) {
|
|
57
|
+
init[key] = event[key];
|
|
58
|
+
}
|
|
59
|
+
init.data = endChar;
|
|
60
|
+
const {
|
|
61
|
+
ownerDocument
|
|
62
|
+
} = element;
|
|
63
|
+
const {
|
|
64
|
+
defaultView
|
|
65
|
+
} = ownerDocument;
|
|
66
|
+
const newEvent = new defaultView.InputEvent('input', init);
|
|
67
|
+
|
|
68
|
+
// Dispatch an `input` event with the new data. This will trigger the
|
|
69
|
+
// input rules.
|
|
70
|
+
// Postpone the `input` to the next event loop tick so that the dispatch
|
|
71
|
+
// doesn't happen synchronously in the middle of `beforeinput` dispatch.
|
|
72
|
+
// This is closer to how native `input` event would be timed, and also
|
|
73
|
+
// makes sure that the `input` event is dispatched only after the `onChange`
|
|
74
|
+
// call few lines above has fully updated the data store state and rerendered
|
|
75
|
+
// all affected components.
|
|
76
|
+
window.queueMicrotask(() => {
|
|
77
|
+
event.target.dispatchEvent(newEvent);
|
|
78
|
+
});
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
}
|
|
81
|
+
element.addEventListener('beforeinput', onInput);
|
|
82
|
+
return () => {
|
|
83
|
+
element.removeEventListener('beforeinput', onInput);
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=before-input-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["insert","isCollapsed","applyFilters","store","blockEditorStore","wrapSelectionSettings","props","element","onInput","event","inputType","data","value","onChange","registry","current","pair","find","startChar","endChar","start","end","length","newValue","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","dispatch","init","key","ownerDocument","defaultView","newEvent","InputEvent","window","queueMicrotask","target","dispatchEvent","preventDefault","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/rich-text/event-listeners/before-input-rules.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { insert, isCollapsed } from '@wordpress/rich-text';\nimport { applyFilters } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\n\n/**\n * When typing over a selection, the selection will we wrapped by a matching\n * character pair. The second character is optional, it defaults to the first\n * character.\n *\n * @type {string[]} Array of character pairs.\n */\nconst wrapSelectionSettings = [ '`', '\"', \"'\", '“”', '‘’' ];\n\nexport default ( props ) => ( element ) => {\n\tfunction onInput( event ) {\n\t\tconst { inputType, data } = event;\n\t\tconst { value, onChange, registry } = props.current;\n\n\t\t// Only run the rules when inserting text.\n\t\tif ( inputType !== 'insertText' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst pair = applyFilters(\n\t\t\t'blockEditor.wrapSelectionSettings',\n\t\t\twrapSelectionSettings\n\t\t).find(\n\t\t\t( [ startChar, endChar ] ) => startChar === data || endChar === data\n\t\t);\n\n\t\tif ( ! pair ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst [ startChar, endChar = startChar ] = pair;\n\t\tconst start = value.start;\n\t\tconst end = value.end + startChar.length;\n\n\t\tlet newValue = insert( value, startChar, start, start );\n\t\tnewValue = insert( newValue, endChar, end, end );\n\n\t\tconst {\n\t\t\t__unstableMarkLastChangeAsPersistent,\n\t\t\t__unstableMarkAutomaticChange,\n\t\t} = registry.dispatch( blockEditorStore );\n\n\t\t__unstableMarkLastChangeAsPersistent();\n\t\tonChange( newValue );\n\t\t__unstableMarkAutomaticChange();\n\n\t\tconst init = {};\n\n\t\tfor ( const key in event ) {\n\t\t\tinit[ key ] = event[ key ];\n\t\t}\n\n\t\tinit.data = endChar;\n\n\t\tconst { ownerDocument } = element;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst newEvent = new defaultView.InputEvent( 'input', init );\n\n\t\t// Dispatch an `input` event with the new data. This will trigger the\n\t\t// input rules.\n\t\t// Postpone the `input` to the next event loop tick so that the dispatch\n\t\t// doesn't happen synchronously in the middle of `beforeinput` dispatch.\n\t\t// This is closer to how native `input` event would be timed, and also\n\t\t// makes sure that the `input` event is dispatched only after the `onChange`\n\t\t// call few lines above has fully updated the data store state and rerendered\n\t\t// all affected components.\n\t\twindow.queueMicrotask( () => {\n\t\t\tevent.target.dispatchEvent( newEvent );\n\t\t} );\n\t\tevent.preventDefault();\n\t}\n\n\telement.addEventListener( 'beforeinput', onInput );\n\treturn () => {\n\t\telement.removeEventListener( 'beforeinput', onInput );\n\t};\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,WAAW,QAAQ,sBAAsB;AAC1D,SAASC,YAAY,QAAQ,kBAAkB;;AAE/C;AACA;AACA;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C;IACtCX,QAAQ,CAAEU,QAAS,CAAC;IACpBE,6BAA6B,CAAC,CAAC;IAE/B,MAAME,IAAI,GAAG,CAAC,CAAC;IAEf,KAAM,MAAMC,GAAG,IAAInB,KAAK,EAAG;MAC1BkB,IAAI,CAAEC,GAAG,CAAE,GAAGnB,KAAK,CAAEmB,GAAG,CAAE;IAC3B;IAEAD,IAAI,CAAChB,IAAI,GAAGQ,OAAO;IAEnB,MAAM;MAAEU;IAAc,CAAC,GAAGtB,OAAO;IACjC,MAAM;MAAEuB;IAAY,CAAC,GAAGD,aAAa;IACrC,MAAME,QAAQ,GAAG,IAAID,WAAW,CAACE,UAAU,CAAE,OAAO,EAAEL,IAAK,CAAC;;IAE5D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAM,MAAM,CAACC,cAAc,CAAE,MAAM;MAC5BzB,KAAK,CAAC0B,MAAM,CAACC,aAAa,CAAEL,QAAS,CAAC;IACvC,CAAE,CAAC;IACHtB,KAAK,CAAC4B,cAAc,CAAC,CAAC;EACvB;EAEA9B,OAAO,CAAC+B,gBAAgB,CAAE,aAAa,EAAE9B,OAAQ,CAAC;EAClD,OAAO,MAAM;IACZD,OAAO,CAACgC,mBAAmB,CAAE,aAAa,EAAE/B,OAAQ,CAAC;EACtD,CAAC;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { DELETE, BACKSPACE } from '@wordpress/keycodes';
|
|
5
|
+
import { isCollapsed, isEmpty } from '@wordpress/rich-text';
|
|
6
|
+
export default (props => element => {
|
|
7
|
+
function onKeyDown(event) {
|
|
8
|
+
const {
|
|
9
|
+
keyCode
|
|
10
|
+
} = event;
|
|
11
|
+
if (event.defaultPrevented) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
value,
|
|
16
|
+
onMerge,
|
|
17
|
+
onRemove
|
|
18
|
+
} = props.current;
|
|
19
|
+
if (keyCode === DELETE || keyCode === BACKSPACE) {
|
|
20
|
+
const {
|
|
21
|
+
start,
|
|
22
|
+
end,
|
|
23
|
+
text
|
|
24
|
+
} = value;
|
|
25
|
+
const isReverse = keyCode === BACKSPACE;
|
|
26
|
+
const hasActiveFormats = value.activeFormats && !!value.activeFormats.length;
|
|
27
|
+
|
|
28
|
+
// Only process delete if the key press occurs at an uncollapsed edge.
|
|
29
|
+
if (!isCollapsed(value) || hasActiveFormats || isReverse && start !== 0 || !isReverse && end !== text.length) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (onMerge) {
|
|
33
|
+
onMerge(!isReverse);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Only handle remove on Backspace. This serves dual-purpose of being
|
|
37
|
+
// an intentional user interaction distinguishing between Backspace and
|
|
38
|
+
// Delete to remove the empty field, but also to avoid merge & remove
|
|
39
|
+
// causing destruction of two fields (merge, then removed merged).
|
|
40
|
+
else if (onRemove && isEmpty(value) && isReverse) {
|
|
41
|
+
onRemove(!isReverse);
|
|
42
|
+
}
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
element.addEventListener('keydown', onKeyDown);
|
|
47
|
+
return () => {
|
|
48
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DELETE","BACKSPACE","isCollapsed","isEmpty","props","element","onKeyDown","event","keyCode","defaultPrevented","value","onMerge","onRemove","current","start","end","text","isReverse","hasActiveFormats","activeFormats","length","preventDefault","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/rich-text/event-listeners/delete.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { DELETE, BACKSPACE } from '@wordpress/keycodes';\nimport { isCollapsed, isEmpty } from '@wordpress/rich-text';\n\nexport default ( props ) => ( element ) => {\n\tfunction onKeyDown( event ) {\n\t\tconst { keyCode } = event;\n\n\t\tif ( event.defaultPrevented ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { value, onMerge, onRemove } = props.current;\n\n\t\tif ( keyCode === DELETE || keyCode === BACKSPACE ) {\n\t\t\tconst { start, end, text } = value;\n\t\t\tconst isReverse = keyCode === BACKSPACE;\n\t\t\tconst hasActiveFormats =\n\t\t\t\tvalue.activeFormats && !! value.activeFormats.length;\n\n\t\t\t// Only process delete if the key press occurs at an uncollapsed edge.\n\t\t\tif (\n\t\t\t\t! isCollapsed( value ) ||\n\t\t\t\thasActiveFormats ||\n\t\t\t\t( isReverse && start !== 0 ) ||\n\t\t\t\t( ! isReverse && end !== text.length )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( onMerge ) {\n\t\t\t\tonMerge( ! isReverse );\n\t\t\t}\n\n\t\t\t// Only handle remove on Backspace. This serves dual-purpose of being\n\t\t\t// an intentional user interaction distinguishing between Backspace and\n\t\t\t// Delete to remove the empty field, but also to avoid merge & remove\n\t\t\t// causing destruction of two fields (merge, then removed merged).\n\t\t\telse if ( onRemove && isEmpty( value ) && isReverse ) {\n\t\t\t\tonRemove( ! isReverse );\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t}\n\t}\n\n\telement.addEventListener( 'keydown', onKeyDown );\n\treturn () => {\n\t\telement.removeEventListener( 'keydown', onKeyDown );\n\t};\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,QAAQ,qBAAqB;AACvD,SAASC,WAAW,EAAEC,OAAO,QAAQ,sBAAsB;AAE3D,gBAAiBC,KAAK,IAAQC,OAAO,IAAM;EAC1C,SAASC,SAASA,CAAEC,KAAK,EAAG;IAC3B,MAAM;MAAEC;IAAQ,CAAC,GAAGD,KAAK;IAEzB,IAAKA,KAAK,CAACE,gBAAgB,EAAG;MAC7B;IACD;IAEA,M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