@wordpress/block-editor 15.21.0 → 15.22.1-next.v.202606191442.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 +23 -1
- package/build/components/block-card/index.cjs +4 -5
- package/build/components/block-card/index.cjs.map +2 -2
- package/build/components/block-compare/index.cjs +2 -2
- package/build/components/block-compare/index.cjs.map +2 -2
- package/build/components/block-inspector/index.cjs +3 -4
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-mover/mover-description.cjs +6 -6
- package/build/components/block-mover/mover-description.cjs.map +1 -1
- package/build/components/block-patterns-list/index.cjs +1 -1
- package/build/components/block-patterns-list/index.cjs.map +2 -2
- package/build/components/block-patterns-paging/index.cjs +4 -4
- package/build/components/block-patterns-paging/index.cjs.map +2 -2
- package/build/components/block-popover/use-popover-scroll.cjs.map +1 -1
- package/build/components/block-quick-navigation/index.cjs +7 -5
- package/build/components/block-quick-navigation/index.cjs.map +2 -2
- package/build/components/block-switcher/block-transformations-menu.cjs +16 -15
- package/build/components/block-switcher/block-transformations-menu.cjs.map +2 -2
- package/build/components/block-switcher/index.cjs +4 -4
- package/build/components/block-switcher/index.cjs.map +2 -2
- package/build/components/block-toolbar/edit-section-button.cjs.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.cjs +10 -4
- package/build/components/block-tools/use-block-toolbar-popover-props.cjs.map +2 -2
- package/build/components/child-layout-control/index.cjs +51 -19
- package/build/components/child-layout-control/index.cjs.map +2 -2
- package/build/components/dimensions-tool/index.cjs +4 -5
- package/build/components/dimensions-tool/index.cjs.map +2 -2
- package/build/components/dimensions-tool/scale-tool.cjs +1 -1
- package/build/components/dimensions-tool/scale-tool.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs +23 -15
- package/build/components/global-styles/advanced-panel.cjs.map +2 -2
- package/build/components/global-styles/background-panel.cjs +2 -2
- package/build/components/global-styles/background-panel.cjs.map +2 -2
- package/build/components/global-styles/border-panel.cjs +2 -0
- package/build/components/global-styles/border-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +2 -2
- package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/grid/grid-item-resizer.cjs.map +1 -1
- package/build/components/grid/grid-visualizer.cjs.map +1 -1
- package/build/components/iframe/index.cjs +6 -3
- package/build/components/iframe/index.cjs.map +3 -3
- package/build/components/image-editor/use-transform-image.cjs.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs +3 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +2 -2
- package/build/components/inserter/get-appender-label.cjs.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.cjs +1 -1
- package/build/components/inserter/hooks/use-patterns-state.cjs.map +2 -2
- package/build/components/inserter/index.cjs +179 -220
- package/build/components/inserter/index.cjs.map +3 -3
- package/build/components/inserter/media-tab/media-preview.cjs.map +2 -2
- package/build/components/inserter/search-items.cjs.map +1 -1
- package/build/components/inserter/search-results.cjs +1 -1
- package/build/components/inserter/search-results.cjs.map +2 -2
- package/build/components/inspector-controls/fill.cjs +1 -3
- package/build/components/inspector-controls/fill.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/index.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/styles-tab.cjs +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -1
- package/build/components/line-height-control/index.cjs.map +1 -1
- package/build/components/link-control/index.cjs +1 -1
- package/build/components/link-control/index.cjs.map +1 -1
- package/build/components/link-control/normalize-url.cjs.map +1 -1
- package/build/components/list-view/block-select-button.cjs +10 -12
- package/build/components/list-view/block-select-button.cjs.map +2 -2
- package/build/components/list-view/block.cjs +2 -1
- package/build/components/list-view/block.cjs.map +2 -2
- package/build/components/list-view/utils.cjs.map +1 -1
- package/build/components/preset-input-control/custom-value-controls.cjs.map +2 -2
- package/build/components/provider/index.cjs.map +1 -1
- package/build/components/provider/use-block-sync.cjs +11 -2
- package/build/components/provider/use-block-sync.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/before-input-rules.cjs +5 -5
- package/build/components/rich-text/event-listeners/before-input-rules.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/delete.cjs +4 -4
- package/build/components/rich-text/event-listeners/delete.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/enter.cjs +7 -2
- package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/input-events.cjs +4 -4
- package/build/components/rich-text/event-listeners/input-events.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/input-rules.cjs +17 -4
- package/build/components/rich-text/event-listeners/input-rules.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/insert-replacement-text.cjs +4 -4
- package/build/components/rich-text/event-listeners/insert-replacement-text.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/paste-handler.cjs.map +1 -1
- package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs +4 -4
- package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/shortcuts.cjs +4 -4
- package/build/components/rich-text/event-listeners/shortcuts.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/undo-automatic-change.cjs +4 -4
- package/build/components/rich-text/event-listeners/undo-automatic-change.cjs.map +3 -3
- package/build/components/rich-text/index.cjs +1 -23
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/rich-text/prevent-event-discovery.cjs +1 -1
- package/build/components/rich-text/prevent-event-discovery.cjs.map +1 -1
- package/build/components/use-block-commands/index.cjs +5 -5
- package/build/components/use-block-commands/index.cjs.map +2 -2
- package/build/components/writing-flow/use-tab-nav.cjs.map +1 -1
- package/build/hooks/anchor.cjs +12 -16
- package/build/hooks/anchor.cjs.map +2 -2
- package/build/hooks/background.cjs.map +1 -1
- package/build/hooks/block-fields/index.cjs +13 -2
- package/build/hooks/block-fields/index.cjs.map +2 -2
- package/build/hooks/border.cjs +0 -3
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/color.cjs +1 -4
- package/build/hooks/color.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +13 -5
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/fit-text.cjs +11 -0
- package/build/hooks/fit-text.cjs.map +2 -2
- package/build/hooks/layout-child.cjs +27 -2
- package/build/hooks/layout-child.cjs.map +2 -2
- package/build/hooks/list-view.cjs +10 -7
- package/build/hooks/list-view.cjs.map +2 -2
- package/build/hooks/position.cjs +19 -22
- package/build/hooks/position.cjs.map +2 -2
- package/build/hooks/spacing-visualizer.cjs.map +1 -1
- package/build/hooks/state-utils.cjs.map +1 -1
- package/build/hooks/style.cjs +42 -2
- package/build/hooks/style.cjs.map +2 -2
- package/build/hooks/supports.cjs +0 -7
- package/build/hooks/supports.cjs.map +2 -2
- package/build/private-apis.cjs +4 -0
- package/build/private-apis.cjs.map +2 -2
- package/build/store/actions.cjs +7 -3
- package/build/store/actions.cjs.map +2 -2
- package/build/store/private-actions.cjs +1 -2
- package/build/store/private-actions.cjs.map +2 -2
- package/build/store/private-selectors.cjs +42 -2
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/store/reducer.cjs +14 -6
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +60 -41
- package/build/store/selectors.cjs.map +2 -2
- package/build/utils/dom.cjs.map +1 -1
- package/build/utils/selection.cjs +1 -1
- package/build-module/components/block-card/index.mjs +5 -6
- package/build-module/components/block-card/index.mjs.map +2 -2
- package/build-module/components/block-compare/index.mjs +1 -1
- package/build-module/components/block-compare/index.mjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +3 -5
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-mover/mover-description.mjs +6 -6
- package/build-module/components/block-mover/mover-description.mjs.map +1 -1
- package/build-module/components/block-patterns-list/index.mjs +1 -1
- package/build-module/components/block-patterns-list/index.mjs.map +2 -2
- package/build-module/components/block-patterns-paging/index.mjs +4 -4
- package/build-module/components/block-patterns-paging/index.mjs.map +2 -2
- package/build-module/components/block-popover/use-popover-scroll.mjs.map +1 -1
- package/build-module/components/block-quick-navigation/index.mjs +8 -6
- package/build-module/components/block-quick-navigation/index.mjs.map +2 -2
- package/build-module/components/block-switcher/block-transformations-menu.mjs +16 -15
- package/build-module/components/block-switcher/block-transformations-menu.mjs.map +2 -2
- package/build-module/components/block-switcher/index.mjs +4 -4
- package/build-module/components/block-switcher/index.mjs.map +2 -2
- package/build-module/components/block-toolbar/edit-section-button.mjs.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.mjs +10 -4
- package/build-module/components/block-tools/use-block-toolbar-popover-props.mjs.map +2 -2
- package/build-module/components/child-layout-control/index.mjs +51 -19
- package/build-module/components/child-layout-control/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/index.mjs +4 -5
- package/build-module/components/dimensions-tool/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/scale-tool.mjs +1 -1
- package/build-module/components/dimensions-tool/scale-tool.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +23 -15
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/background-panel.mjs +3 -3
- package/build-module/components/global-styles/background-panel.mjs.map +2 -2
- package/build-module/components/global-styles/border-panel.mjs +2 -0
- package/build-module/components/global-styles/border-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +3 -4
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/grid/grid-item-resizer.mjs.map +1 -1
- package/build-module/components/grid/grid-visualizer.mjs.map +1 -1
- package/build-module/components/iframe/index.mjs +6 -3
- package/build-module/components/iframe/index.mjs.map +2 -2
- package/build-module/components/image-editor/use-transform-image.mjs.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +3 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +2 -2
- package/build-module/components/inserter/get-appender-label.mjs.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.mjs +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.mjs.map +2 -2
- package/build-module/components/inserter/index.mjs +185 -222
- package/build-module/components/inserter/index.mjs.map +3 -3
- package/build-module/components/inserter/media-tab/media-preview.mjs.map +2 -2
- package/build-module/components/inserter/search-items.mjs.map +1 -1
- package/build-module/components/inserter/search-results.mjs +1 -1
- package/build-module/components/inserter/search-results.mjs.map +2 -2
- package/build-module/components/inspector-controls/fill.mjs +1 -3
- package/build-module/components/inspector-controls/fill.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/index.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
- package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -1
- package/build-module/components/line-height-control/index.mjs.map +1 -1
- package/build-module/components/link-control/index.mjs +1 -1
- package/build-module/components/link-control/index.mjs.map +1 -1
- package/build-module/components/link-control/normalize-url.mjs.map +1 -1
- package/build-module/components/list-view/block-select-button.mjs +10 -12
- package/build-module/components/list-view/block-select-button.mjs.map +2 -2
- package/build-module/components/list-view/block.mjs +2 -1
- package/build-module/components/list-view/block.mjs.map +2 -2
- package/build-module/components/list-view/utils.mjs.map +1 -1
- package/build-module/components/preset-input-control/custom-value-controls.mjs.map +2 -2
- package/build-module/components/provider/index.mjs.map +1 -1
- package/build-module/components/provider/use-block-sync.mjs +11 -2
- package/build-module/components/provider/use-block-sync.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/before-input-rules.mjs +5 -5
- package/build-module/components/rich-text/event-listeners/before-input-rules.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/delete.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/delete.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs +7 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/input-events.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/input-events.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/input-rules.mjs +17 -4
- package/build-module/components/rich-text/event-listeners/input-rules.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/paste-handler.mjs.map +1 -1
- package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/shortcuts.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/shortcuts.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +1 -23
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/rich-text/prevent-event-discovery.mjs +1 -1
- package/build-module/components/rich-text/prevent-event-discovery.mjs.map +1 -1
- package/build-module/components/use-block-commands/index.mjs +5 -5
- package/build-module/components/use-block-commands/index.mjs.map +2 -2
- package/build-module/components/writing-flow/use-tab-nav.mjs.map +1 -1
- package/build-module/hooks/anchor.mjs +12 -16
- package/build-module/hooks/anchor.mjs.map +2 -2
- package/build-module/hooks/background.mjs.map +1 -1
- package/build-module/hooks/block-fields/index.mjs +13 -2
- package/build-module/hooks/block-fields/index.mjs.map +2 -2
- package/build-module/hooks/border.mjs +1 -4
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/color.mjs +2 -5
- package/build-module/hooks/color.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +13 -6
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/fit-text.mjs +11 -0
- package/build-module/hooks/fit-text.mjs.map +2 -2
- package/build-module/hooks/layout-child.mjs +27 -2
- package/build-module/hooks/layout-child.mjs.map +2 -2
- package/build-module/hooks/list-view.mjs +10 -7
- package/build-module/hooks/list-view.mjs.map +2 -2
- package/build-module/hooks/position.mjs +20 -23
- package/build-module/hooks/position.mjs.map +2 -2
- package/build-module/hooks/spacing-visualizer.mjs.map +1 -1
- package/build-module/hooks/state-utils.mjs.map +1 -1
- package/build-module/hooks/style.mjs +44 -3
- package/build-module/hooks/style.mjs.map +2 -2
- package/build-module/hooks/supports.mjs +0 -7
- package/build-module/hooks/supports.mjs.map +2 -2
- package/build-module/private-apis.mjs +8 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/actions.mjs +7 -3
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +1 -2
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +39 -1
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +14 -6
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +62 -42
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-module/utils/dom.mjs.map +1 -1
- package/build-module/utils/selection.mjs +1 -1
- package/build-style/content-rtl.css +12 -0
- package/build-style/content.css +12 -0
- package/build-style/style-rtl.css +26 -8
- package/build-style/style.css +26 -8
- package/package.json +54 -46
- package/src/components/block-breadcrumb/README.md +2 -2
- package/src/components/block-card/index.js +7 -13
- package/src/components/block-compare/README.md +6 -6
- package/src/components/block-compare/index.js +1 -3
- package/src/components/block-inspector/index.js +2 -10
- package/src/components/block-patterns-list/index.js +1 -2
- package/src/components/block-preview/README.md +1 -1
- package/src/components/block-quick-navigation/index.js +7 -7
- package/src/components/block-switcher/block-transformations-menu.js +16 -18
- package/src/components/block-switcher/index.js +4 -4
- package/src/components/block-tools/use-block-toolbar-popover-props.js +10 -4
- package/src/components/block-types-list/README.md +0 -19
- package/src/components/child-layout-control/index.js +65 -20
- package/src/components/child-layout-control/test/index.js +64 -0
- package/src/components/dimensions-tool/index.js +4 -9
- package/src/components/dimensions-tool/scale-tool.js +1 -2
- package/src/components/dimensions-tool/test/index.js +89 -11
- package/src/components/global-styles/advanced-panel.js +5 -1
- package/src/components/global-styles/background-panel.js +3 -3
- package/src/components/global-styles/border-panel.js +2 -0
- package/src/components/global-styles/dimensions-panel.js +13 -15
- package/src/components/global-styles/shadow-panel-components.js +0 -1
- package/src/components/iframe/index.js +8 -3
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -1
- package/src/components/inserter/hooks/use-patterns-state.js +1 -1
- package/src/components/inserter/index.js +257 -288
- package/src/components/inserter/media-tab/media-preview.js +0 -1
- package/src/components/inserter/search-results.js +1 -3
- package/src/components/inspector-controls/fill.js +6 -8
- package/src/components/inspector-controls-tabs/index.js +0 -1
- package/src/components/inspector-controls-tabs/styles-tab.js +5 -1
- package/src/components/justify-content-control/README.md +1 -1
- package/src/components/list-view/block-select-button.js +9 -14
- package/src/components/list-view/block.js +1 -0
- package/src/components/media-placeholder/README.md +1 -29
- package/src/components/media-upload/README.md +0 -19
- package/src/components/preset-input-control/custom-value-controls.js +0 -1
- package/src/components/provider/test/use-block-sync.js +40 -0
- package/src/components/provider/use-block-sync.js +12 -2
- package/src/components/rich-text/event-listeners/before-input-rules.js +5 -4
- package/src/components/rich-text/event-listeners/delete.js +9 -4
- package/src/components/rich-text/event-listeners/enter.js +9 -2
- package/src/components/rich-text/event-listeners/input-events.js +13 -4
- package/src/components/rich-text/event-listeners/input-rules.js +20 -4
- package/src/components/rich-text/event-listeners/insert-replacement-text.js +9 -4
- package/src/components/rich-text/event-listeners/remove-browser-shortcuts.js +9 -4
- package/src/components/rich-text/event-listeners/shortcuts.js +13 -4
- package/src/components/rich-text/event-listeners/undo-automatic-change.js +5 -4
- package/src/components/rich-text/index.js +1 -33
- package/src/components/unit-control/README.md +1 -1
- package/src/components/url-popover/README.md +1 -1
- package/src/components/use-block-commands/index.js +5 -5
- package/src/hooks/anchor.js +9 -17
- package/src/hooks/block-fields/index.js +27 -2
- package/src/hooks/border.js +1 -5
- package/src/hooks/color.js +1 -6
- package/src/hooks/dimensions.js +15 -8
- package/src/hooks/fit-text.js +16 -0
- package/src/hooks/layout-child.js +41 -2
- package/src/hooks/list-view.js +10 -11
- package/src/hooks/position.js +23 -27
- package/src/hooks/style.js +80 -2
- package/src/hooks/supports.js +0 -9
- package/src/hooks/test/dimensions.js +71 -0
- package/src/hooks/test/layout-child.js +165 -0
- package/src/hooks/test/style.js +126 -4
- package/src/private-apis.js +8 -0
- package/src/store/actions.js +13 -3
- package/src/store/private-actions.js +1 -4
- package/src/store/private-selectors.js +89 -0
- package/src/store/reducer.js +19 -7
- package/src/store/selectors.js +91 -53
- package/src/store/test/actions.js +21 -0
- package/src/store/test/private-selectors.js +138 -0
- package/src/store/test/reducer.js +46 -0
- package/src/store/test/selectors.js +77 -0
- package/build/components/media-upload-progress/constants.cjs +0 -46
- package/build/components/media-upload-progress/constants.cjs.map +0 -7
- package/build/components/rich-text/native/format-edit.cjs +0 -60
- package/build/components/rich-text/native/format-edit.cjs.map +0 -7
- package/build/components/rich-text/native/index.cjs +0 -28
- package/build/components/rich-text/native/index.cjs.map +0 -7
- package/build/components/rich-text/native/use-format-types.cjs +0 -139
- package/build/components/rich-text/native/use-format-types.cjs.map +0 -7
- package/build-module/components/media-upload-progress/constants.mjs +0 -16
- package/build-module/components/media-upload-progress/constants.mjs.map +0 -7
- package/build-module/components/rich-text/native/format-edit.mjs +0 -39
- package/build-module/components/rich-text/native/format-edit.mjs.map +0 -7
- package/build-module/components/rich-text/native/index.mjs +0 -7
- package/build-module/components/rich-text/native/index.mjs.map +0 -7
- package/build-module/components/rich-text/native/use-format-types.mjs +0 -114
- package/build-module/components/rich-text/native/use-format-types.mjs.map +0 -7
- package/src/components/audio-player/audio-url-parser.native.js +0 -20
- package/src/components/audio-player/index.native.js +0 -225
- package/src/components/audio-player/styles.native.scss +0 -114
- package/src/components/audio-player/test/audio-url-parser.native.js +0 -53
- package/src/components/block-alignment-control/test/index.native.js +0 -37
- package/src/components/block-alignment-control/ui.native.js +0 -86
- package/src/components/block-caption/README.md +0 -104
- package/src/components/block-caption/index.native.js +0 -89
- package/src/components/block-caption/styles.native.scss +0 -7
- package/src/components/block-controls/slot.native.js +0 -33
- package/src/components/block-draggable/draggable-chip.native.js +0 -49
- package/src/components/block-draggable/dropping-insertion-point.native.js +0 -181
- package/src/components/block-draggable/dropping-insertion-point.native.scss +0 -8
- package/src/components/block-draggable/index.native.js +0 -467
- package/src/components/block-draggable/style.native.scss +0 -19
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +0 -73
- package/src/components/block-draggable/test/helpers.native.js +0 -182
- package/src/components/block-draggable/test/index.native.js +0 -419
- package/src/components/block-draggable/use-scroll-when-dragging.native.js +0 -135
- package/src/components/block-edit/edit.native.js +0 -49
- package/src/components/block-edit/test/edit.native.js +0 -65
- package/src/components/block-heading-level-dropdown/index.native.js +0 -68
- package/src/components/block-icon/index.native.js +0 -47
- package/src/components/block-icon/style.native.scss +0 -7
- package/src/components/block-list/block-crash-boundary.native.js +0 -43
- package/src/components/block-list/block-crash-warning.native.js +0 -21
- package/src/components/block-list/block-invalid-warning.native.js +0 -70
- package/src/components/block-list/block-list-context.native.js +0 -172
- package/src/components/block-list/block-list-item-cell.native.js +0 -62
- package/src/components/block-list/block-list-item.native.js +0 -209
- package/src/components/block-list/block-list-item.native.scss +0 -16
- package/src/components/block-list/block-outline.native.js +0 -77
- package/src/components/block-list/block-selection-button.native.js +0 -100
- package/src/components/block-list/block-selection-button.native.scss +0 -34
- package/src/components/block-list/block.native.js +0 -716
- package/src/components/block-list/block.native.scss +0 -62
- package/src/components/block-list/grid-item.native.js +0 -58
- package/src/components/block-list/index.native.js +0 -437
- package/src/components/block-list/insertion-point.native.js +0 -36
- package/src/components/block-list/style.native.scss +0 -117
- package/src/components/block-list/test/block-invalid-warning.native.js +0 -62
- package/src/components/block-list/test/block-list-context.native.js +0 -243
- package/src/components/block-list/test/block-outline.native.js +0 -255
- package/src/components/block-list/test/fixtures/block-list-context.native.js +0 -79
- package/src/components/block-list/test/index.native.js +0 -205
- package/src/components/block-list/use-block-props/index.native.js +0 -10
- package/src/components/block-list/use-scroll-upon-insertion.native.js +0 -52
- package/src/components/block-list-appender/index.native.js +0 -70
- package/src/components/block-list-appender/style.native.scss +0 -8
- package/src/components/block-media-update-progress/README.md +0 -100
- package/src/components/block-media-update-progress/index.native.js +0 -299
- package/src/components/block-media-update-progress/styles.native.scss +0 -9
- package/src/components/block-media-update-progress/test/index.native.js +0 -543
- package/src/components/block-mover/index.native.js +0 -193
- package/src/components/block-mover/mover-description.native.js +0 -155
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +0 -218
- package/src/components/block-mover/test/index.native.js +0 -186
- package/src/components/block-settings/button.native.js +0 -41
- package/src/components/block-settings/container.native.js +0 -91
- package/src/components/block-settings/container.native.scss +0 -4
- package/src/components/block-settings/index.native.js +0 -5
- package/src/components/block-styles/index.native.js +0 -94
- package/src/components/block-styles/preview.native.js +0 -109
- package/src/components/block-styles/style.native.scss +0 -64
- package/src/components/block-switcher/block-transformations-menu.native.js +0 -91
- package/src/components/block-toolbar/block-toolbar-menu.native.js +0 -477
- package/src/components/block-toolbar/index.native.js +0 -126
- package/src/components/block-toolbar/test/__snapshots__/block-toolbar-menu.native.js.snap +0 -125
- package/src/components/block-toolbar/test/block-toolbar-menu.native.js +0 -405
- package/src/components/block-toolbar/test/index.native.js +0 -36
- package/src/components/block-types-list/index.native.js +0 -175
- package/src/components/block-types-list/style.native.scss +0 -25
- package/src/components/block-variation-picker/index.native.js +0 -107
- package/src/components/block-variation-picker/style.native.scss +0 -32
- package/src/components/button-block-appender/index.native.js +0 -92
- package/src/components/button-block-appender/styles.native.scss +0 -43
- package/src/components/caption/README.md +0 -44
- package/src/components/caption/index.native.js +0 -61
- package/src/components/colors-gradients/panel-color-gradient-settings.native.js +0 -59
- package/src/components/contrast-checker/index.native.js +0 -113
- package/src/components/contrast-checker/style.native.scss +0 -26
- package/src/components/convert-to-group-buttons/index.native.js +0 -79
- package/src/components/default-block-appender/index.native.js +0 -113
- package/src/components/default-block-appender/style.native.scss +0 -18
- package/src/components/floating-toolbar/floatingToolbar.android.scss +0 -4
- package/src/components/floating-toolbar/floatingToolbar.ios.scss +0 -3
- package/src/components/floating-toolbar/index.native.js +0 -141
- package/src/components/floating-toolbar/styles.native.scss +0 -43
- package/src/components/font-sizes/index.native.js +0 -7
- package/src/components/global-styles/color-panel.native.js +0 -207
- package/src/components/global-styles/test/use-global-styles-context.native.js +0 -435
- package/src/components/global-styles/use-global-styles-context.native.js +0 -592
- package/src/components/gradients/index.native.js +0 -2
- package/src/components/image-link-destinations/index.native.js +0 -152
- package/src/components/image-link-destinations/style.native.scss +0 -16
- package/src/components/index.native.js +0 -108
- package/src/components/inner-blocks/constants.native.js +0 -5
- package/src/components/inner-blocks/index.native.js +0 -221
- package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +0 -124
- package/src/components/inserter/block-types-tab.native.js +0 -76
- package/src/components/inserter/hooks/use-block-type-impressions.native.js +0 -47
- package/src/components/inserter/hooks/use-clipboard-block.native.js +0 -40
- package/src/components/inserter/index.native.js +0 -424
- package/src/components/inserter/menu.native.js +0 -237
- package/src/components/inserter/no-results.native.js +0 -49
- package/src/components/inserter/reusable-blocks-tab.native.js +0 -45
- package/src/components/inserter/search-results.native.js +0 -67
- package/src/components/inserter/style.native.scss +0 -83
- package/src/components/inserter/tabs.native.js +0 -152
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +0 -117
- package/src/components/inserter/test/fixtures/index.native.js +0 -12
- package/src/components/inserter/test/index.native.js +0 -273
- package/src/components/inserter/test/reusable-blocks-tab.native.js +0 -62
- package/src/components/inserter/test/utils.native.js +0 -37
- package/src/components/inserter/utils.native.js +0 -46
- package/src/components/inserter-button/index.native.js +0 -108
- package/src/components/inserter-button/style.native.scss +0 -72
- package/src/components/inspector-controls/fill.native.js +0 -62
- package/src/components/inspector-controls/slot.native.js +0 -35
- package/src/components/inspector-controls-tabs/advanced-controls-panel.native.js +0 -31
- package/src/components/line-height-control/index.native.js +0 -28
- package/src/components/media-placeholder/index.native.js +0 -258
- package/src/components/media-placeholder/styles.native.scss +0 -108
- package/src/components/media-replace-flow/index.native.js +0 -12
- package/src/components/media-upload/constants.native.js +0 -14
- package/src/components/media-upload/index.native.js +0 -356
- package/src/components/media-upload/style.native.scss +0 -4
- package/src/components/media-upload/test/index.native.js +0 -172
- package/src/components/media-upload-progress/README.md +0 -100
- package/src/components/media-upload-progress/constants.js +0 -6
- package/src/components/media-upload-progress/index.native.js +0 -233
- package/src/components/media-upload-progress/styles.native.scss +0 -15
- package/src/components/media-upload-progress/test/index.native.js +0 -220
- package/src/components/plain-text/index.native.js +0 -164
- package/src/components/plain-text/style.native.scss +0 -10
- package/src/components/provider/index.native.js +0 -32
- package/src/components/rich-text/embed-handler-picker.native.js +0 -65
- package/src/components/rich-text/file-paste-handler.native.js +0 -3
- package/src/components/rich-text/format-toolbar/index.native.js +0 -21
- package/src/components/rich-text/format-toolbar-container.native.js +0 -16
- package/src/components/rich-text/index.native.js +0 -701
- package/src/components/rich-text/input-event.native.js +0 -10
- package/src/components/rich-text/native/format-edit.js +0 -44
- package/src/components/rich-text/native/get-format-colors.native.js +0 -47
- package/src/components/rich-text/native/index.js +0 -1
- package/src/components/rich-text/native/index.native.js +0 -1389
- package/src/components/rich-text/native/style.native.scss +0 -28
- package/src/components/rich-text/native/test/__snapshots__/index.native.js.snap +0 -79
- package/src/components/rich-text/native/test/index.native.js +0 -345
- package/src/components/rich-text/native/test/performance/rich-text.native.js +0 -44
- package/src/components/rich-text/native/toolbar-button-with-options.native.js +0 -61
- package/src/components/rich-text/native/use-format-types.js +0 -146
- package/src/components/rich-text/remove-browser-shortcuts.native.js +0 -1
- package/src/components/rich-text/shortcut.native.js +0 -10
- package/src/components/ungroup-button/README.md +0 -23
- package/src/components/ungroup-button/index.native.js +0 -77
- package/src/components/unsupported-block-details/index.native.js +0 -187
- package/src/components/unsupported-block-details/style.native.scss +0 -56
- package/src/components/url-input/index.native.js +0 -33
- package/src/components/use-block-drop-zone/index.native.js +0 -207
- package/src/components/use-on-block-drop/index.native.js +0 -115
- package/src/components/use-unsupported-block-editor/index.native.js +0 -59
- package/src/components/video-player/gridicon-play.native.js +0 -13
- package/src/components/video-player/index.native.js +0 -133
- package/src/components/video-player/styles.native.scss +0 -29
- package/src/components/warning/index.native.js +0 -64
- package/src/components/warning/style.native.scss +0 -47
- package/src/hooks/align.native.js +0 -49
- package/src/hooks/custom-class-name.native.js +0 -70
- package/src/hooks/index.native.js +0 -36
- package/src/hooks/layout.native.js +0 -23
- package/src/hooks/test/__snapshots__/align.native.js.snap +0 -73
- package/src/hooks/test/__snapshots__/anchor.native.js.snap +0 -7
- package/src/hooks/test/align.native.js +0 -134
- package/src/hooks/test/anchor.native.js +0 -32
- package/src/hooks/test/use-editor-wrapper-styles.native.js +0 -282
- package/src/hooks/typography.native.js +0 -60
- package/src/hooks/use-editor-wrapper-styles.native.js +0 -250
- package/src/hooks/use-editor-wrapper-styles.native.scss +0 -12
- package/src/index.native.js +0 -6
- package/src/private-apis.native.js +0 -21
- package/src/store/defaults.native.js +0 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/preset-input-control/custom-value-controls.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tRangeControl,\n\t__experimentalUnitControl as UnitControl,\n} from '@wordpress/components';\n\
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA,6BAA6B;AAAA,OACvB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tRangeControl,\n\t__experimentalUnitControl as UnitControl,\n} from '@wordpress/components';\n\nimport { Tooltip } from '@wordpress/ui';\n\n/**\n * CustomValueControls component for handling custom value input.\n *\n * Renders a UnitControl and RangeControl for custom value input mode.\n * Handles conditional tooltip wrapping and drag event coordination.\n *\n * @param {Object} props\n * @param {boolean} props.allowNegativeOnDrag Whether to allow negative values during drag operations.\n * @param {string} props.ariaLabel Accessible label for the controls.\n * @param {string} props.allPlaceholder Placeholder text (e.g., \"Mixed\").\n * @param {number} props.minValue Minimum allowed value.\n * @param {number} props.parsedQuantity The numeric part of the current value.\n * @param {string} props.computedUnit The unit part of the current value.\n * @param {Array} props.units Array of available unit objects.\n * @param {boolean} props.isMixed Whether the current value is mixed.\n * @param {number} props.step Step value for the range control.\n * @param {number} props.max Maximum value for the range control.\n * @param {boolean} props.showTooltip Whether to wrap UnitControl in a tooltip.\n * @param {string} props.value Current value for drag event checks.\n * @param {number} props.minimumCustomValue Minimum custom value for drag end reset.\n * @param {Function} props.onCustomValueChange Callback when UnitControl value changes.\n * @param {Function} props.onCustomValueSliderChange Callback when RangeControl value changes.\n * @param {Function} props.onUnitChange Callback when unit changes.\n * @param {Function} props.onMouseOut Mouse out event handler.\n * @param {Function} props.onMouseOver Mouse over event handler.\n * @param {Function} props.setMinValue Function to set minimum value state.\n *\n * @return {Element} The CustomValueControls component.\n */\nexport default function CustomValueControls( {\n\tallowNegativeOnDrag,\n\tariaLabel,\n\tallPlaceholder,\n\tminValue,\n\tparsedQuantity,\n\tcomputedUnit,\n\tunits,\n\tisMixed,\n\tstep,\n\tmax,\n\tshowTooltip,\n\tvalue,\n\tminimumCustomValue,\n\tonCustomValueChange,\n\tonCustomValueSliderChange,\n\tonUnitChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsetMinValue,\n} ) {\n\tconst unitControl = (\n\t\t<UnitControl\n\t\t\tclassName=\"preset-input-control__unit-control\"\n\t\t\tdisableUnits={ isMixed }\n\t\t\thideLabelFromVision\n\t\t\tlabel={ ariaLabel }\n\t\t\tmin={ minValue }\n\t\t\tonChange={ onCustomValueChange }\n\t\t\tonUnitChange={ onUnitChange }\n\t\t\tonBlur={ onMouseOut }\n\t\t\tonFocus={ onMouseOver }\n\t\t\tonMouseOut={ onMouseOut }\n\t\t\tonMouseOver={ onMouseOver }\n\t\t\tsize=\"__unstable-large\"\n\t\t\tunits={ units }\n\t\t\tvalue={ [ parsedQuantity, computedUnit ].join( '' ) }\n\t\t\tplaceholder={ allPlaceholder }\n\t\t\tonDragStart={ () => {\n\t\t\t\tif ( allowNegativeOnDrag && value?.charAt( 0 ) === '-' ) {\n\t\t\t\t\tsetMinValue( 0 );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonDrag={ () => {\n\t\t\t\tif ( allowNegativeOnDrag && value?.charAt( 0 ) === '-' ) {\n\t\t\t\t\tsetMinValue( 0 );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonDragEnd={ () => {\n\t\t\t\tif ( allowNegativeOnDrag ) {\n\t\t\t\t\tsetMinValue( minimumCustomValue );\n\t\t\t\t}\n\t\t\t} }\n\t\t/>\n\t);\n\n\tconst wrappedUnitControl = showTooltip ? (\n\t\t<Tooltip.Root>\n\t\t\t<Tooltip.Trigger\n\t\t\t\trender={\n\t\t\t\t\t<div className=\"preset-input-control__tooltip-wrapper\">\n\t\t\t\t\t\t{ unitControl }\n\t\t\t\t\t</div>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Tooltip.Popup>{ ariaLabel }</Tooltip.Popup>\n\t\t</Tooltip.Root>\n\t) : (\n\t\tunitControl\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ wrappedUnitControl }\n\t\t\t<RangeControl\n\t\t\t\tclassName=\"preset-input-control__custom-value-range\"\n\t\t\t\thideLabelFromVision\n\t\t\t\tinitialPosition={ 0 }\n\t\t\t\tlabel={ ariaLabel }\n\t\t\t\tmax={ max }\n\t\t\t\tmin={ 0 }\n\t\t\t\tonBlur={ onMouseOut }\n\t\t\t\tonChange={ onCustomValueSliderChange }\n\t\t\t\tonFocus={ onMouseOver }\n\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\tstep={ step }\n\t\t\t\tvalue={ parsedQuantity }\n\t\t\t\twithInputField={ false }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA,6BAA6B;AAAA,OACvB;AAEP,SAAS,eAAe;AAqDtB,SAkDA,UAlDA,KAmCA,YAnCA;AAtBa,SAAR,oBAAsC;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,cACL;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,cAAe;AAAA,MACf,qBAAmB;AAAA,MACnB,OAAQ;AAAA,MACR,KAAM;AAAA,MACN,UAAW;AAAA,MACX;AAAA,MACA,QAAS;AAAA,MACT,SAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,MAAK;AAAA,MACL;AAAA,MACA,OAAQ,CAAE,gBAAgB,YAAa,EAAE,KAAM,EAAG;AAAA,MAClD,aAAc;AAAA,MACd,aAAc,MAAM;AACnB,YAAK,uBAAuB,OAAO,OAAQ,CAAE,MAAM,KAAM;AACxD,sBAAa,CAAE;AAAA,QAChB;AAAA,MACD;AAAA,MACA,QAAS,MAAM;AACd,YAAK,uBAAuB,OAAO,OAAQ,CAAE,MAAM,KAAM;AACxD,sBAAa,CAAE;AAAA,QAChB;AAAA,MACD;AAAA,MACA,WAAY,MAAM;AACjB,YAAK,qBAAsB;AAC1B,sBAAa,kBAAmB;AAAA,QACjC;AAAA,MACD;AAAA;AAAA,EACD;AAGD,QAAM,qBAAqB,cAC1B,qBAAC,QAAQ,MAAR,EACA;AAAA;AAAA,MAAC,QAAQ;AAAA,MAAR;AAAA,QACA,QACC,oBAAC,SAAI,WAAU,yCACZ,uBACH;AAAA;AAAA,IAEF;AAAA,IACA,oBAAC,QAAQ,OAAR,EAAgB,qBAAW;AAAA,KAC7B,IAEA;AAGD,SACC,iCACG;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,qBAAmB;AAAA,QACnB,iBAAkB;AAAA,QAClB,OAAQ;AAAA,QACR;AAAA,QACA,KAAM;AAAA,QACN,QAAS;AAAA,QACT,UAAW;AAAA,QACX,SAAU;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAQ;AAAA,QACR,gBAAiB;AAAA,QACjB,uBAAqB;AAAA;AAAA,IACtB;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/provider/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { useEffect, useMemo, useRef } from '@wordpress/element';\nimport { SlotFillProvider } from '@wordpress/components';\nimport {\n\tMediaUploadProvider,\n\tstore as uploadStore,\n\tdetectClientSideMediaSupport,\n\tisHeicCanvasSupported,\n} from '@wordpress/upload-media';\n\n/**\n * Internal dependencies\n */\nimport withRegistryProvider from './with-registry-provider';\nimport useBlockSync from './use-block-sync';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockRefsProvider } from './block-refs-provider';\nimport { unlock } from '../../lock-unlock';\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport useMediaUploadSettings from './use-media-upload-settings';\nimport { mediaUploadOnSuccessKey } from '../../store/private-keys';\nimport { SelectionContext } from './selection-context';\n\n/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */\n\nconst noop = () => {};\n\n/**\n * Flag to track if we've already logged the fallback message.\n */\nlet hasLoggedFallback = false;\n\n/**\n * Cached result of whether client-side media processing should be enabled.\n * This is computed once per session for efficiency and stability.\n */\nlet isClientSideMediaEnabledCache = null;\n\n/**\n * Cached result of whether HEIC-only canvas processing should be enabled.\n */\nlet isHeicCanvasEnabledCache = null;\n\n/**\n * HEIC MIME types that should be routed through the upload-media pipeline\n * when in HEIC-only mode.\n */\nconst HEIC_MIME_TYPES = [ 'image/heic', 'image/heif' ];\n\n/**\n * Checks if client-side media processing should be enabled.\n *\n * Returns true only if:\n * 1. The client-side media processing flag is enabled\n * 2. The browser supports WebAssembly, SharedArrayBuffer, cross-origin isolation, and CSP allows blob workers\n *\n * The result is cached for the session to ensure stability during React renders.\n *\n * @return {boolean} Whether client-side media processing should be enabled.\n */\nfunction shouldEnableClientSideMediaProcessing() {\n\t// Return cached result if available.\n\tif ( isClientSideMediaEnabledCache !== null ) {\n\t\treturn isClientSideMediaEnabledCache;\n\t}\n\n\t// Check if the client-side media processing flag is enabled first.\n\tif ( ! window.__clientSideMediaProcessing ) {\n\t\tisClientSideMediaEnabledCache = false;\n\t\treturn false;\n\t}\n\n\t// Safety check in case the import is unavailable.\n\tif ( typeof detectClientSideMediaSupport !== 'function' ) {\n\t\tisClientSideMediaEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tconst detection = detectClientSideMediaSupport();\n\tif ( ! detection || ! detection.supported ) {\n\t\t// Only log once per session to avoid console spam.\n\t\tif ( ! hasLoggedFallback ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.info(\n\t\t\t\t`Client-side media processing unavailable: ${ detection.reason }. Using server-side processing.`\n\t\t\t);\n\t\t\thasLoggedFallback = true;\n\t\t}\n\t\tisClientSideMediaEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tisClientSideMediaEnabledCache = true;\n\treturn true;\n}\n\n/**\n * Checks if HEIC-only canvas processing should be enabled.\n *\n * Returns true when:\n * 1. Full client-side processing is NOT available (otherwise it handles HEIC already)\n * 2. The server has set the __heicUploadSupport flag\n * 3. The browser supports createImageBitmap + OffscreenCanvas (e.g. Safari)\n *\n * @return {boolean} Whether HEIC-only canvas processing should be enabled.\n */\nfunction shouldEnableHeicCanvasProcessing() {\n\tif ( isHeicCanvasEnabledCache !== null ) {\n\t\treturn isHeicCanvasEnabledCache;\n\t}\n\n\t// If full client-side processing is enabled, it already handles HEIC.\n\tif ( shouldEnableClientSideMediaProcessing() ) {\n\t\tisHeicCanvasEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tif ( ! window.__heicUploadSupport ) {\n\t\tisHeicCanvasEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tif (\n\t\ttypeof isHeicCanvasSupported !== 'function' ||\n\t\t! isHeicCanvasSupported()\n\t) {\n\t\tisHeicCanvasEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tisHeicCanvasEnabledCache = true;\n\treturn true;\n}\n\n/**\n * Upload a media file when the file upload button is activated\n * or when adding a file to the editor via drag & drop.\n *\n * @param {WPDataRegistry} registry\n * @param {Object} settings Block editor settings.\n * @param {Object} $3 Parameters object passed to the function.\n * @param {Array} $3.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param {Object} $3.additionalData Additional data to include in the request.\n * @param {Array<File>} $3.filesList List of files.\n * @param {Function} $3.onError Function called when an error happens.\n * @param {Function} $3.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param {Function} $3.onSuccess Function called once a file has completely finished uploading, including thumbnails.\n * @param {Function} $3.onBatchSuccess Function called once all files in a group have completely finished uploading, including thumbnails.\n */\nfunction mediaUpload(\n\tregistry,\n\tsettings,\n\t{\n\t\tallowedTypes,\n\t\tadditionalData = {},\n\t\tfilesList,\n\t\tonError = noop,\n\t\tonFileChange,\n\t\tonSuccess,\n\t\tonBatchSuccess,\n\t}\n) {\n\tvoid registry.dispatch( uploadStore ).addItems( {\n\t\tfiles: Array.from( filesList ),\n\t\tonChange: onFileChange,\n\t\tonSuccess: ( attachments ) => {\n\t\t\tsettings?.[ mediaUploadOnSuccessKey ]?.( attachments );\n\t\t\tonSuccess?.( attachments );\n\t\t},\n\t\tonBatchSuccess,\n\t\tonError: ( error ) =>\n\t\t\tonError( typeof error === 'string' ? error : error?.message ?? '' ),\n\t\tadditionalData,\n\t\tallowedTypes,\n\t} );\n}\n\n/**\n * Upload interceptor for HEIC-only mode.\n *\n * Routes HEIC files through the upload-media pipeline for canvas-based\n * conversion, while passing non-HEIC files to the original mediaUpload\n * function for standard server-side processing.\n *\n * @param {WPDataRegistry} registry\n * @param {Object} settings Block editor settings.\n * @param {Object} $3 Parameters object passed to the function.\n * @param {Array} $3.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param {Object} $3.additionalData Additional data to include in the request.\n * @param {Array<File>} $3.filesList List of files.\n * @param {Function} $3.onError Function called when an error happens.\n * @param {Function} $3.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param {Function} $3.onSuccess Function called once a file has completely finished uploading, including thumbnails.\n * @param {Function} $3.onBatchSuccess Function called once all files in a group have completely finished uploading, including thumbnails.\n */\nfunction heicMediaUpload(\n\tregistry,\n\tsettings,\n\t{\n\t\tallowedTypes,\n\t\tadditionalData = {},\n\t\tfilesList,\n\t\tonError = noop,\n\t\tonFileChange,\n\t\tonSuccess,\n\t\tonBatchSuccess,\n\t}\n) {\n\tconst files = Array.from( filesList );\n\tconst heicFiles = files.filter( ( file ) =>\n\t\tHEIC_MIME_TYPES.includes( file.type )\n\t);\n\tconst otherFiles = files.filter(\n\t\t( file ) => ! HEIC_MIME_TYPES.includes( file.type )\n\t);\n\n\t// When the batch contains both HEIC and non-HEIC files, coordinate\n\t// onBatchSuccess so it fires only after *both* paths have completed.\n\tconst hasBothPaths =\n\t\theicFiles.length > 0 && otherFiles.length > 0 && settings?.mediaUpload;\n\tlet pathsRemaining = hasBothPaths ? 2 : 1;\n\tconst coordinatedBatchSuccess = hasBothPaths\n\t\t? () => {\n\t\t\t\tpathsRemaining--;\n\t\t\t\tif ( pathsRemaining <= 0 ) {\n\t\t\t\t\tonBatchSuccess?.();\n\t\t\t\t}\n\t\t }\n\t\t: onBatchSuccess;\n\n\t// Route HEIC files through the upload-media pipeline.\n\tif ( heicFiles.length > 0 ) {\n\t\tvoid registry.dispatch( uploadStore ).addItems( {\n\t\t\tfiles: heicFiles,\n\t\t\tonChange: onFileChange,\n\t\t\tonSuccess: ( attachments ) => {\n\t\t\t\tsettings?.[ mediaUploadOnSuccessKey ]?.( attachments );\n\t\t\t\tonSuccess?.( attachments );\n\t\t\t},\n\t\t\tonBatchSuccess: coordinatedBatchSuccess,\n\t\t\tonError: ( error ) =>\n\t\t\t\tonError(\n\t\t\t\t\ttypeof error === 'string' ? error : error?.message ?? ''\n\t\t\t\t),\n\t\t\tadditionalData,\n\t\t\tallowedTypes,\n\t\t} );\n\t}\n\n\t// Pass non-HEIC files to the original server-side upload function.\n\tif ( otherFiles.length > 0 && settings?.mediaUpload ) {\n\t\tsettings.mediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tadditionalData,\n\t\t\tfilesList: otherFiles,\n\t\t\tonError,\n\t\t\tonFileChange,\n\t\t\tonSuccess,\n\t\t\tonBatchSuccess: coordinatedBatchSuccess,\n\t\t} );\n\t}\n}\n\n/**\n * Calls useBlockSync as a child of SelectionContext.Provider so that the\n * hook can read selection state from the context provided by this tree\n * rather than from a parent provider (which may not exist for the root).\n *\n * @param {Object} props Props forwarded to useBlockSync.\n */\nfunction BlockSyncEffect( props ) {\n\tuseBlockSync( props );\n\treturn null;\n}\n\nexport const ExperimentalBlockEditorProvider = withRegistryProvider(\n\t( props ) => {\n\t\tconst {\n\t\t\tsettings: _settings,\n\t\t\tregistry,\n\t\t\tstripExperimentalSettings = false,\n\t\t} = props;\n\n\t\tconst mediaUploadSettings = useMediaUploadSettings( _settings );\n\n\t\tconst isClientSideMediaEnabled =\n\t\t\tshouldEnableClientSideMediaProcessing();\n\t\tconst isHeicCanvasEnabled = shouldEnableHeicCanvasProcessing();\n\t\tconst useUploadMediaPipeline =\n\t\t\tisClientSideMediaEnabled || isHeicCanvasEnabled;\n\n\t\t// Nested providers (e.g. from useBlockPreview) inherit settings\n\t\t// where mediaUpload has already been replaced with the\n\t\t// interceptor. Detect this so we skip the replacement and\n\t\t// MediaUploadProvider for them \u2014 see the longer comment below.\n\t\tconst isMediaUploadIntercepted =\n\t\t\t!! _settings?.mediaUpload?.__isMediaUploadInterceptor;\n\n\t\tconst settings = useMemo( () => {\n\t\t\tif (\n\t\t\t\tuseUploadMediaPipeline &&\n\t\t\t\t_settings?.mediaUpload &&\n\t\t\t\t! isMediaUploadIntercepted\n\t\t\t) {\n\t\t\t\t// Choose the right interceptor:\n\t\t\t\t// - Full mode: all uploads go through upload-media pipeline.\n\t\t\t\t// - HEIC-only mode: only HEIC files go through, rest use legacy path.\n\t\t\t\tconst uploadFn = isClientSideMediaEnabled\n\t\t\t\t\t? mediaUpload\n\t\t\t\t\t: heicMediaUpload;\n\t\t\t\tconst interceptor = uploadFn.bind( null, registry, _settings );\n\t\t\t\tinterceptor.__isMediaUploadInterceptor = true;\n\t\t\t\treturn {\n\t\t\t\t\t..._settings,\n\t\t\t\t\tmediaUpload: interceptor,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn _settings;\n\t\t}, [\n\t\t\t_settings,\n\t\t\tregistry,\n\t\t\tuseUploadMediaPipeline,\n\t\t\tisClientSideMediaEnabled,\n\t\t\tisMediaUploadIntercepted,\n\t\t] );\n\n\t\tconst { __experimentalUpdateSettings } = unlock(\n\t\t\tuseDispatch( blockEditorStore )\n\t\t);\n\t\tuseEffect( () => {\n\t\t\t__experimentalUpdateSettings(\n\t\t\t\t{\n\t\t\t\t\t...settings,\n\t\t\t\t\t__internalIsInitialized: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tstripExperimentalSettings,\n\t\t\t\t\treset: true,\n\t\t\t\t}\n\t\t\t);\n\t\t}, [\n\t\t\tsettings,\n\t\t\tstripExperimentalSettings,\n\t\t\t__experimentalUpdateSettings,\n\t\t] );\n\n\t\t// Store selection and onChangeSelection in refs and expose\n\t\t// stable getters/callers so that the context value is a\n\t\t// complete constant. This prevents re-rendering the entire\n\t\t// block tree (including async-rendered off-screen blocks)\n\t\t// when either value changes.\n\t\tconst selectionRef = useRef( props.selection );\n\t\tselectionRef.current = props.selection;\n\t\tconst onChangeSelectionRef = useRef( props.onChangeSelection ?? noop );\n\t\tonChangeSelectionRef.current = props.onChangeSelection ?? noop;\n\n\t\tconst selectionContextValue = useMemo(\n\t\t\t() => ( {\n\t\t\t\tgetSelection: () => selectionRef.current,\n\t\t\t\tonChangeSelection: ( ...args ) =>\n\t\t\t\t\tonChangeSelectionRef.current( ...args ),\n\t\t\t} ),\n\t\t\t[]\n\t\t);\n\n\t\tconst children = (\n\t\t\t<SlotFillProvider passthrough>\n\t\t\t\t{ ! settings?.isPreviewMode && <KeyboardShortcuts.Register /> }\n\t\t\t\t<BlockRefsProvider>{ props.children }</BlockRefsProvider>\n\t\t\t</SlotFillProvider>\n\t\t);\n\n\t\tconst content = (\n\t\t\t<SelectionContext.Provider value={ selectionContextValue }>\n\t\t\t\t<BlockSyncEffect\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tvalue={ props.value }\n\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\tonInput={ props.onInput }\n\t\t\t\t/>\n\t\t\t\t{ children }\n\t\t\t</SelectionContext.Provider>\n\t\t);\n\n\t\t// MediaUploadProvider writes the mediaUpload function from\n\t\t// _settings into the shared upload-media store so the store can\n\t\t// hand files off to the server. useMediaUploadSettings extracts\n\t\t// mediaUpload from the original _settings prop \u2014 *before* the\n\t\t// interceptor replacement above \u2014 so the store receives the\n\t\t// real server-side upload function.\n\t\t//\n\t\t// Only the first (outermost) provider should do this.\n\t\t// Nested providers (e.g. from useBlockPreview in\n\t\t// core/post-template) inherit settings that already contain\n\t\t// the interceptor, so their MediaUploadProvider would\n\t\t// overwrite the store's server-side function with the\n\t\t// interceptor, causing uploads to loop instead of reaching\n\t\t// the server.\n\t\tif ( useUploadMediaPipeline && ! isMediaUploadIntercepted ) {\n\t\t\treturn (\n\t\t\t\t<MediaUploadProvider\n\t\t\t\t\tsettings={ mediaUploadSettings }\n\t\t\t\t\tuseSubRegistry={ false }\n\t\t\t\t>\n\t\t\t\t\t{ content }\n\t\t\t\t</MediaUploadProvider>\n\t\t\t);\n\t\t}\n\n\t\treturn content;\n\t}\n);\n\nexport const BlockEditorProvider = ( props ) => {\n\treturn (\n\t\t<ExperimentalBlockEditorProvider { ...props } stripExperimentalSettings>\n\t\t\t{ props.children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n};\n\nexport default BlockEditorProvider;\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { useEffect, useMemo, useRef } from '@wordpress/element';\nimport { SlotFillProvider } from '@wordpress/components';\nimport {\n\tMediaUploadProvider,\n\tstore as uploadStore,\n\tdetectClientSideMediaSupport,\n\tisHeicCanvasSupported,\n} from '@wordpress/upload-media';\n\n/**\n * Internal dependencies\n */\nimport withRegistryProvider from './with-registry-provider';\nimport useBlockSync from './use-block-sync';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockRefsProvider } from './block-refs-provider';\nimport { unlock } from '../../lock-unlock';\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport useMediaUploadSettings from './use-media-upload-settings';\nimport { mediaUploadOnSuccessKey } from '../../store/private-keys';\nimport { SelectionContext } from './selection-context';\n\n/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */\n\nconst noop = () => {};\n\n/**\n * Flag to track if we've already logged the fallback message.\n */\nlet hasLoggedFallback = false;\n\n/**\n * Cached result of whether client-side media processing should be enabled.\n * This is computed once per session for efficiency and stability.\n */\nlet isClientSideMediaEnabledCache = null;\n\n/**\n * Cached result of whether HEIC-only canvas processing should be enabled.\n */\nlet isHeicCanvasEnabledCache = null;\n\n/**\n * HEIC MIME types that should be routed through the upload-media pipeline\n * when in HEIC-only mode.\n */\nconst HEIC_MIME_TYPES = [ 'image/heic', 'image/heif' ];\n\n/**\n * Checks if client-side media processing should be enabled.\n *\n * Returns true only if:\n * 1. The client-side media processing flag is enabled\n * 2. The browser supports WebAssembly, SharedArrayBuffer, cross-origin isolation, and CSP allows blob workers\n *\n * The result is cached for the session to ensure stability during React renders.\n *\n * @return {boolean} Whether client-side media processing should be enabled.\n */\nfunction shouldEnableClientSideMediaProcessing() {\n\t// Return cached result if available.\n\tif ( isClientSideMediaEnabledCache !== null ) {\n\t\treturn isClientSideMediaEnabledCache;\n\t}\n\n\t// Check if the client-side media processing flag is enabled first.\n\tif ( ! window.__clientSideMediaProcessing ) {\n\t\tisClientSideMediaEnabledCache = false;\n\t\treturn false;\n\t}\n\n\t// Safety check in case the import is unavailable.\n\tif ( typeof detectClientSideMediaSupport !== 'function' ) {\n\t\tisClientSideMediaEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tconst detection = detectClientSideMediaSupport();\n\tif ( ! detection || ! detection.supported ) {\n\t\t// Only log once per session to avoid console spam.\n\t\tif ( ! hasLoggedFallback ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.info(\n\t\t\t\t`Client-side media processing unavailable: ${ detection.reason }. Using server-side processing.`\n\t\t\t);\n\t\t\thasLoggedFallback = true;\n\t\t}\n\t\tisClientSideMediaEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tisClientSideMediaEnabledCache = true;\n\treturn true;\n}\n\n/**\n * Checks if HEIC-only canvas processing should be enabled.\n *\n * Returns true when:\n * 1. Full client-side processing is NOT available (otherwise it handles HEIC already)\n * 2. The server has set the __heicUploadSupport flag\n * 3. The browser supports createImageBitmap + OffscreenCanvas (e.g. Safari)\n *\n * @return {boolean} Whether HEIC-only canvas processing should be enabled.\n */\nfunction shouldEnableHeicCanvasProcessing() {\n\tif ( isHeicCanvasEnabledCache !== null ) {\n\t\treturn isHeicCanvasEnabledCache;\n\t}\n\n\t// If full client-side processing is enabled, it already handles HEIC.\n\tif ( shouldEnableClientSideMediaProcessing() ) {\n\t\tisHeicCanvasEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tif ( ! window.__heicUploadSupport ) {\n\t\tisHeicCanvasEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tif (\n\t\ttypeof isHeicCanvasSupported !== 'function' ||\n\t\t! isHeicCanvasSupported()\n\t) {\n\t\tisHeicCanvasEnabledCache = false;\n\t\treturn false;\n\t}\n\n\tisHeicCanvasEnabledCache = true;\n\treturn true;\n}\n\n/**\n * Upload a media file when the file upload button is activated\n * or when adding a file to the editor via drag & drop.\n *\n * @param {WPDataRegistry} registry\n * @param {Object} settings Block editor settings.\n * @param {Object} $3 Parameters object passed to the function.\n * @param {Array} $3.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param {Object} $3.additionalData Additional data to include in the request.\n * @param {Array<File>} $3.filesList List of files.\n * @param {Function} $3.onError Function called when an error happens.\n * @param {Function} $3.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param {Function} $3.onSuccess Function called once a file has completely finished uploading, including thumbnails.\n * @param {Function} $3.onBatchSuccess Function called once all files in a group have completely finished uploading, including thumbnails.\n */\nfunction mediaUpload(\n\tregistry,\n\tsettings,\n\t{\n\t\tallowedTypes,\n\t\tadditionalData = {},\n\t\tfilesList,\n\t\tonError = noop,\n\t\tonFileChange,\n\t\tonSuccess,\n\t\tonBatchSuccess,\n\t}\n) {\n\tvoid registry.dispatch( uploadStore ).addItems( {\n\t\tfiles: Array.from( filesList ),\n\t\tonChange: onFileChange,\n\t\tonSuccess: ( attachments ) => {\n\t\t\tsettings?.[ mediaUploadOnSuccessKey ]?.( attachments );\n\t\t\tonSuccess?.( attachments );\n\t\t},\n\t\tonBatchSuccess,\n\t\tonError: ( error ) =>\n\t\t\tonError( typeof error === 'string' ? error : error?.message ?? '' ),\n\t\tadditionalData,\n\t\tallowedTypes,\n\t} );\n}\n\n/**\n * Upload interceptor for HEIC-only mode.\n *\n * Routes HEIC files through the upload-media pipeline for canvas-based\n * conversion, while passing non-HEIC files to the original mediaUpload\n * function for standard server-side processing.\n *\n * @param {WPDataRegistry} registry\n * @param {Object} settings Block editor settings.\n * @param {Object} $3 Parameters object passed to the function.\n * @param {Array} $3.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param {Object} $3.additionalData Additional data to include in the request.\n * @param {Array<File>} $3.filesList List of files.\n * @param {Function} $3.onError Function called when an error happens.\n * @param {Function} $3.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param {Function} $3.onSuccess Function called once a file has completely finished uploading, including thumbnails.\n * @param {Function} $3.onBatchSuccess Function called once all files in a group have completely finished uploading, including thumbnails.\n */\nfunction heicMediaUpload(\n\tregistry,\n\tsettings,\n\t{\n\t\tallowedTypes,\n\t\tadditionalData = {},\n\t\tfilesList,\n\t\tonError = noop,\n\t\tonFileChange,\n\t\tonSuccess,\n\t\tonBatchSuccess,\n\t}\n) {\n\tconst files = Array.from( filesList );\n\tconst heicFiles = files.filter( ( file ) =>\n\t\tHEIC_MIME_TYPES.includes( file.type )\n\t);\n\tconst otherFiles = files.filter(\n\t\t( file ) => ! HEIC_MIME_TYPES.includes( file.type )\n\t);\n\n\t// When the batch contains both HEIC and non-HEIC files, coordinate\n\t// onBatchSuccess so it fires only after *both* paths have completed.\n\tconst hasBothPaths =\n\t\theicFiles.length > 0 && otherFiles.length > 0 && settings?.mediaUpload;\n\tlet pathsRemaining = hasBothPaths ? 2 : 1;\n\tconst coordinatedBatchSuccess = hasBothPaths\n\t\t? () => {\n\t\t\t\tpathsRemaining--;\n\t\t\t\tif ( pathsRemaining <= 0 ) {\n\t\t\t\t\tonBatchSuccess?.();\n\t\t\t\t}\n\t\t }\n\t\t: onBatchSuccess;\n\n\t// Route HEIC files through the upload-media pipeline.\n\tif ( heicFiles.length > 0 ) {\n\t\tvoid registry.dispatch( uploadStore ).addItems( {\n\t\t\tfiles: heicFiles,\n\t\t\tonChange: onFileChange,\n\t\t\tonSuccess: ( attachments ) => {\n\t\t\t\tsettings?.[ mediaUploadOnSuccessKey ]?.( attachments );\n\t\t\t\tonSuccess?.( attachments );\n\t\t\t},\n\t\t\tonBatchSuccess: coordinatedBatchSuccess,\n\t\t\tonError: ( error ) =>\n\t\t\t\tonError(\n\t\t\t\t\ttypeof error === 'string' ? error : error?.message ?? ''\n\t\t\t\t),\n\t\t\tadditionalData,\n\t\t\tallowedTypes,\n\t\t} );\n\t}\n\n\t// Pass non-HEIC files to the original server-side upload function.\n\tif ( otherFiles.length > 0 && settings?.mediaUpload ) {\n\t\tsettings.mediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tadditionalData,\n\t\t\tfilesList: otherFiles,\n\t\t\tonError,\n\t\t\tonFileChange,\n\t\t\tonSuccess,\n\t\t\tonBatchSuccess: coordinatedBatchSuccess,\n\t\t} );\n\t}\n}\n\n/**\n * Calls useBlockSync as a child of SelectionContext.Provider so that the\n * hook can read selection state from the context provided by this tree\n * rather than from a parent provider (which may not exist for the root).\n *\n * @param {Object} props Props forwarded to useBlockSync.\n */\nfunction BlockSyncEffect( props ) {\n\tuseBlockSync( props );\n\treturn null;\n}\n\nexport const ExperimentalBlockEditorProvider = withRegistryProvider(\n\t( props ) => {\n\t\tconst {\n\t\t\tsettings: _settings,\n\t\t\tregistry,\n\t\t\tstripExperimentalSettings = false,\n\t\t} = props;\n\n\t\tconst mediaUploadSettings = useMediaUploadSettings( _settings );\n\n\t\tconst isClientSideMediaEnabled =\n\t\t\tshouldEnableClientSideMediaProcessing();\n\t\tconst isHeicCanvasEnabled = shouldEnableHeicCanvasProcessing();\n\t\tconst useUploadMediaPipeline =\n\t\t\tisClientSideMediaEnabled || isHeicCanvasEnabled;\n\n\t\t// Nested providers (e.g. from useBlockPreview) inherit settings\n\t\t// where mediaUpload has already been replaced with the\n\t\t// interceptor. Detect this so we skip the replacement and\n\t\t// MediaUploadProvider for them — see the longer comment below.\n\t\tconst isMediaUploadIntercepted =\n\t\t\t!! _settings?.mediaUpload?.__isMediaUploadInterceptor;\n\n\t\tconst settings = useMemo( () => {\n\t\t\tif (\n\t\t\t\tuseUploadMediaPipeline &&\n\t\t\t\t_settings?.mediaUpload &&\n\t\t\t\t! isMediaUploadIntercepted\n\t\t\t) {\n\t\t\t\t// Choose the right interceptor:\n\t\t\t\t// - Full mode: all uploads go through upload-media pipeline.\n\t\t\t\t// - HEIC-only mode: only HEIC files go through, rest use legacy path.\n\t\t\t\tconst uploadFn = isClientSideMediaEnabled\n\t\t\t\t\t? mediaUpload\n\t\t\t\t\t: heicMediaUpload;\n\t\t\t\tconst interceptor = uploadFn.bind( null, registry, _settings );\n\t\t\t\tinterceptor.__isMediaUploadInterceptor = true;\n\t\t\t\treturn {\n\t\t\t\t\t..._settings,\n\t\t\t\t\tmediaUpload: interceptor,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn _settings;\n\t\t}, [\n\t\t\t_settings,\n\t\t\tregistry,\n\t\t\tuseUploadMediaPipeline,\n\t\t\tisClientSideMediaEnabled,\n\t\t\tisMediaUploadIntercepted,\n\t\t] );\n\n\t\tconst { __experimentalUpdateSettings } = unlock(\n\t\t\tuseDispatch( blockEditorStore )\n\t\t);\n\t\tuseEffect( () => {\n\t\t\t__experimentalUpdateSettings(\n\t\t\t\t{\n\t\t\t\t\t...settings,\n\t\t\t\t\t__internalIsInitialized: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tstripExperimentalSettings,\n\t\t\t\t\treset: true,\n\t\t\t\t}\n\t\t\t);\n\t\t}, [\n\t\t\tsettings,\n\t\t\tstripExperimentalSettings,\n\t\t\t__experimentalUpdateSettings,\n\t\t] );\n\n\t\t// Store selection and onChangeSelection in refs and expose\n\t\t// stable getters/callers so that the context value is a\n\t\t// complete constant. This prevents re-rendering the entire\n\t\t// block tree (including async-rendered off-screen blocks)\n\t\t// when either value changes.\n\t\tconst selectionRef = useRef( props.selection );\n\t\tselectionRef.current = props.selection;\n\t\tconst onChangeSelectionRef = useRef( props.onChangeSelection ?? noop );\n\t\tonChangeSelectionRef.current = props.onChangeSelection ?? noop;\n\n\t\tconst selectionContextValue = useMemo(\n\t\t\t() => ( {\n\t\t\t\tgetSelection: () => selectionRef.current,\n\t\t\t\tonChangeSelection: ( ...args ) =>\n\t\t\t\t\tonChangeSelectionRef.current( ...args ),\n\t\t\t} ),\n\t\t\t[]\n\t\t);\n\n\t\tconst children = (\n\t\t\t<SlotFillProvider passthrough>\n\t\t\t\t{ ! settings?.isPreviewMode && <KeyboardShortcuts.Register /> }\n\t\t\t\t<BlockRefsProvider>{ props.children }</BlockRefsProvider>\n\t\t\t</SlotFillProvider>\n\t\t);\n\n\t\tconst content = (\n\t\t\t<SelectionContext.Provider value={ selectionContextValue }>\n\t\t\t\t<BlockSyncEffect\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tvalue={ props.value }\n\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\tonInput={ props.onInput }\n\t\t\t\t/>\n\t\t\t\t{ children }\n\t\t\t</SelectionContext.Provider>\n\t\t);\n\n\t\t// MediaUploadProvider writes the mediaUpload function from\n\t\t// _settings into the shared upload-media store so the store can\n\t\t// hand files off to the server. useMediaUploadSettings extracts\n\t\t// mediaUpload from the original _settings prop — *before* the\n\t\t// interceptor replacement above — so the store receives the\n\t\t// real server-side upload function.\n\t\t//\n\t\t// Only the first (outermost) provider should do this.\n\t\t// Nested providers (e.g. from useBlockPreview in\n\t\t// core/post-template) inherit settings that already contain\n\t\t// the interceptor, so their MediaUploadProvider would\n\t\t// overwrite the store's server-side function with the\n\t\t// interceptor, causing uploads to loop instead of reaching\n\t\t// the server.\n\t\tif ( useUploadMediaPipeline && ! isMediaUploadIntercepted ) {\n\t\t\treturn (\n\t\t\t\t<MediaUploadProvider\n\t\t\t\t\tsettings={ mediaUploadSettings }\n\t\t\t\t\tuseSubRegistry={ false }\n\t\t\t\t>\n\t\t\t\t\t{ content }\n\t\t\t\t</MediaUploadProvider>\n\t\t\t);\n\t\t}\n\n\t\treturn content;\n\t}\n);\n\nexport const BlockEditorProvider = ( props ) => {\n\treturn (\n\t\t<ExperimentalBlockEditorProvider { ...props } stripExperimentalSettings>\n\t\t\t{ props.children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n};\n\nexport default BlockEditorProvider;\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,WAAW,SAAS,cAAc;AAC3C,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,OACM;AAKP,OAAO,0BAA0B;AACjC,OAAO,kBAAkB;AACzB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,yBAAyB;AAClC,SAAS,cAAc;AACvB,OAAO,uBAAuB;AAC9B,OAAO,4BAA4B;AACnC,SAAS,+BAA+B;AACxC,SAAS,wBAAwB;AAyV9B,SACgC,KADhC;AArVH,IAAM,OAAO,MAAM;AAAC;AAKpB,IAAI,oBAAoB;AAMxB,IAAI,gCAAgC;AAKpC,IAAI,2BAA2B;AAM/B,IAAM,kBAAkB,CAAE,cAAc,YAAa;AAarD,SAAS,wCAAwC;AAEhD,MAAK,kCAAkC,MAAO;AAC7C,WAAO;AAAA,EACR;AAGA,MAAK,CAAE,OAAO,6BAA8B;AAC3C,oCAAgC;AAChC,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,iCAAiC,YAAa;AACzD,oCAAgC;AAChC,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,6BAA6B;AAC/C,MAAK,CAAE,aAAa,CAAE,UAAU,WAAY;AAE3C,QAAK,CAAE,mBAAoB;AAE1B,cAAQ;AAAA,QACP,6CAA8C,UAAU,MAAO;AAAA,MAChE;AACA,0BAAoB;AAAA,IACrB;AACA,oCAAgC;AAChC,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,gBAAiB;AAAA,UAEf;AAAA;AAAA,MACH;AAAA,IAEF;AAEA,WAAO;AAAA,EACR;AACD;AAEO,IAAM,sBAAsB,CAAE,UAAW;AAC/C,SACC,oBAAC,mCAAkC,GAAG,OAAQ,2BAAyB,MACpE,gBAAM,UACT;AAEF;AAEA,IAAO,mBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -160,12 +160,14 @@ function useBlockSync({
|
|
|
160
160
|
const {
|
|
161
161
|
getSelectedBlocksInitialCaretPosition,
|
|
162
162
|
isLastBlockChangePersistent,
|
|
163
|
+
__unstableGetLastBlockChangeHistoryMode,
|
|
163
164
|
__unstableIsLastBlockChangeIgnored,
|
|
164
165
|
areInnerBlocksControlled,
|
|
165
166
|
getBlockParents
|
|
166
167
|
} = registry.select(blockEditorStore);
|
|
167
168
|
let blocks = getBlocks(clientId);
|
|
168
169
|
let isPersistent = isLastBlockChangePersistent();
|
|
170
|
+
let blockHistoryMode = __unstableGetLastBlockChangeHistoryMode();
|
|
169
171
|
let previousAreBlocksDifferent = false;
|
|
170
172
|
let prevSelectionStart = getSelectionStart();
|
|
171
173
|
let prevSelectionEnd = getSelectionEnd();
|
|
@@ -175,12 +177,14 @@ function useBlockSync({
|
|
|
175
177
|
return;
|
|
176
178
|
}
|
|
177
179
|
const newIsPersistent = isLastBlockChangePersistent();
|
|
180
|
+
const newBlockHistoryMode = __unstableGetLastBlockChangeHistoryMode();
|
|
178
181
|
const newBlocks = getBlocks(clientId);
|
|
179
182
|
const areBlocksDifferent = newBlocks !== blocks;
|
|
180
183
|
blocks = newBlocks;
|
|
181
184
|
if (areBlocksDifferent && (pendingChangesRef.current.incoming || __unstableIsLastBlockChangeIgnored())) {
|
|
182
185
|
pendingChangesRef.current.incoming = null;
|
|
183
186
|
isPersistent = newIsPersistent;
|
|
187
|
+
blockHistoryMode = newBlockHistoryMode;
|
|
184
188
|
return;
|
|
185
189
|
}
|
|
186
190
|
const didPersistenceChange = previousAreBlocksDifferent && !areBlocksDifferent && newIsPersistent && !isPersistent;
|
|
@@ -196,6 +200,7 @@ function useBlockSync({
|
|
|
196
200
|
registry.batch(() => {
|
|
197
201
|
if (blocksChanged) {
|
|
198
202
|
isPersistent = newIsPersistent;
|
|
203
|
+
blockHistoryMode = newBlockHistoryMode;
|
|
199
204
|
const blocksForParent = clientId ? restoreExternalIds(blocks, idMappingRef.current) : blocks;
|
|
200
205
|
const selectionInfo = {
|
|
201
206
|
selectionStart: newSelectionStart,
|
|
@@ -210,9 +215,13 @@ function useBlockSync({
|
|
|
210
215
|
blocksForParent
|
|
211
216
|
);
|
|
212
217
|
const updateParent = isPersistent ? onChangeRef.current : onInputRef.current;
|
|
213
|
-
|
|
218
|
+
const updateOptions = {
|
|
214
219
|
selection: selectionForParent
|
|
215
|
-
}
|
|
220
|
+
};
|
|
221
|
+
if (blockHistoryMode === "ignore") {
|
|
222
|
+
updateOptions.undoIgnore = true;
|
|
223
|
+
}
|
|
224
|
+
updateParent(blocksForParent, updateOptions);
|
|
216
225
|
}
|
|
217
226
|
if (selectionChanged && !blocksChanged && newSelectionStart?.clientId && !isRestoringSelectionRef.current) {
|
|
218
227
|
const isOurs = clientId ? idMappingRef.current.internalToExternal.has(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/provider/use-block-sync.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext, 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 { SelectionContext } from './selection-context';\n\nconst noop = () => {};\n\n/**\n * Clones a block and its inner blocks, building a bidirectional mapping\n * between external (original) and internal (cloned) client IDs.\n *\n * This allows the block editor to use unique internal IDs while preserving\n * stable external IDs for features like real-time collaboration.\n *\n * @param {Object} block The block to clone.\n * @param {Object} mapping The mapping object with externalToInternal and internalToExternal Maps.\n * @return {Object} The cloned block with a new clientId.\n */\nfunction cloneBlockWithMapping( block, mapping ) {\n\tconst clonedBlock = cloneBlock( block );\n\n\t// Build bidirectional mapping\n\tmapping.externalToInternal.set( block.clientId, clonedBlock.clientId );\n\tmapping.internalToExternal.set( clonedBlock.clientId, block.clientId );\n\n\t// Recursively map inner blocks\n\tif ( block.innerBlocks?.length ) {\n\t\tclonedBlock.innerBlocks = block.innerBlocks.map( ( innerBlock ) => {\n\t\t\tconst clonedInner = cloneBlockWithMapping( innerBlock, mapping );\n\t\t\t// The clonedBlock already has cloned inner blocks from cloneBlock(),\n\t\t\t// but we need to use our mapped versions to maintain the mapping.\n\t\t\treturn clonedInner;\n\t\t} );\n\t}\n\n\treturn clonedBlock;\n}\n\n/**\n * Restores external (original) client IDs on blocks before passing them\n * to onChange/onInput callbacks.\n *\n * @param {Object[]} blocks The blocks with internal client IDs.\n * @param {Object} mapping The mapping object with internalToExternal Map.\n * @return {Object[]} Blocks with external client IDs restored.\n */\nfunction restoreExternalIds( blocks, mapping ) {\n\treturn blocks.map( ( block ) => {\n\t\tconst externalId = mapping.internalToExternal.get( block.clientId );\n\t\treturn {\n\t\t\t...block,\n\t\t\t// Use external ID if available, otherwise keep internal ID (for new blocks)\n\t\t\tclientId: externalId ?? block.clientId,\n\t\t\tinnerBlocks: restoreExternalIds( block.innerBlocks, mapping ),\n\t\t};\n\t} );\n}\n\n/**\n * Restores external client IDs in selection state.\n *\n * @param {Object} selectionState The selection state with internal client IDs.\n * @param {Object} mapping The mapping object with internalToExternal Map.\n * @return {Object} Selection state with external client IDs.\n */\nfunction restoreSelectionIds( selectionState, mapping ) {\n\tconst { selectionStart, selectionEnd, initialPosition } = selectionState;\n\n\tconst restoreClientId = ( sel ) => {\n\t\tif ( ! sel?.clientId ) {\n\t\t\treturn sel;\n\t\t}\n\t\tconst externalId = mapping.internalToExternal.get( sel.clientId );\n\t\treturn {\n\t\t\t...sel,\n\t\t\tclientId: externalId ?? sel.clientId,\n\t\t};\n\t};\n\n\treturn {\n\t\tselectionStart: restoreClientId( selectionStart ),\n\t\tselectionEnd: restoreClientId( selectionEnd ),\n\t\tinitialPosition,\n\t};\n}\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 * - Initializes 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 initialize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\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\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\tconst { getSelection, onChangeSelection } = useContext( SelectionContext );\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 pendingChangesRef = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribedRef = useRef( false );\n\n\t// Mapping between external (original) and internal (cloned) client IDs.\n\t// This allows stable external IDs while using unique internal IDs.\n\tconst idMappingRef = useRef( {\n\t\texternalToInternal: new Map(),\n\t\tinternalToExternal: new Map(),\n\t} );\n\n\t// Tracks which context selection has already been applied, to avoid\n\t// duplicate restoration.\n\tconst appliedSelectionRef = useRef( null );\n\t// Flag to prevent the subscription from re-reporting a selection\n\t// change that was just restored from context (which would loop).\n\tconst isRestoringSelectionRef = useRef( false );\n\n\t// Restores selection from the SelectionContext using the current\n\t// idMapping. Called after blocks are (re-)cloned so that the\n\t// mapping is guaranteed to be fresh.\n\tconst restoreSelection = () => {\n\t\tconst selection = getSelection();\n\t\tif (\n\t\t\t! selection?.selectionStart?.clientId ||\n\t\t\tselection === appliedSelectionRef.current\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst startClientId = selection.selectionStart.clientId;\n\n\t\t// Check if this selection belongs to this controller.\n\t\t// Inner block controllers (clientId is set) own the block if\n\t\t// the external ID appears in their clone mapping.\n\t\t// The root controller (no clientId) owns it if the block\n\t\t// exists directly in the store.\n\t\tconst isOurs = clientId\n\t\t\t? idMappingRef.current.externalToInternal.has( startClientId )\n\t\t\t: !! getBlockName( startClientId );\n\n\t\tif ( isOurs ) {\n\t\t\tappliedSelectionRef.current = selection;\n\t\t\t// Inner block controllers need to convert external\u2192internal\n\t\t\t// IDs via the clone mapping; the root controller uses\n\t\t\t// external IDs directly (no mapping needed).\n\t\t\tconst convert = ( sel ) => {\n\t\t\t\tif ( ! sel?.clientId || ! clientId ) {\n\t\t\t\t\treturn sel;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...sel,\n\t\t\t\t\tclientId:\n\t\t\t\t\t\tidMappingRef.current.externalToInternal.get(\n\t\t\t\t\t\t\tsel.clientId\n\t\t\t\t\t\t) ?? sel.clientId,\n\t\t\t\t};\n\t\t\t};\n\t\t\t// Flag prevents the subscription from re-reporting this\n\t\t\t// selection change back to the entity (which would cause\n\t\t\t// an infinite update loop).\n\t\t\tisRestoringSelectionRef.current = true;\n\t\t\tresetSelection(\n\t\t\t\tconvert( selection.selectionStart ),\n\t\t\t\tconvert( selection.selectionEnd ),\n\t\t\t\tselection.initialPosition\n\t\t\t);\n\t\t\tisRestoringSelectionRef.current = false;\n\t\t}\n\t};\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\tif ( clientId ) {\n\t\t\t// Batch so that the controlled flag and block replacement\n\t\t\t// are applied atomically \u2014 subscribers see a consistent state.\n\t\t\tregistry.batch( () => {\n\t\t\t\t// Clear previous mappings and build new ones during cloning.\n\t\t\t\t// This ensures the mapping stays in sync with the current blocks.\n\t\t\t\tidMappingRef.current.externalToInternal.clear();\n\t\t\t\tidMappingRef.current.internalToExternal.clear();\n\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlockWithMapping( block, idMappingRef.current )\n\t\t\t\t);\n\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\n\t\t\t\tif ( subscribedRef.current ) {\n\t\t\t\t\tpendingChangesRef.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\n\t\t\t\t// Invalidate the applied-selection ref so that\n\t\t\t\t// restoreSelection() at the end of the\n\t\t\t\t// controlledBlocks effect re-applies with the\n\t\t\t\t// freshly-built mapping (new internal IDs).\n\t\t\t\tappliedSelectionRef.current = null;\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribedRef.current ) {\n\t\t\t\tpendingChangesRef.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\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\t// Also restores selection from context after blocks are set.\n\tuseEffect( () => {\n\t\tconst isOutgoing =\n\t\t\tpendingChangesRef.current.outgoing.includes( controlledBlocks );\n\t\tconst storeMatch = getBlocks( clientId ) === controlledBlocks;\n\n\t\tif ( isOutgoing ) {\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\tpendingChangesRef.current.outgoing[\n\t\t\t\t\tpendingChangesRef.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChangesRef.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( ! storeMatch ) {\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\tpendingChangesRef.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\n\t\t\t// Restore selection from context if it targets our scope.\n\t\t\t// Only done when blocks were reset from an external source\n\t\t\t// (undo/redo, entity navigation) \u2014 NOT for outgoing changes,\n\t\t\t// because dispatching resetSelection between keystrokes breaks\n\t\t\t// the isUpdatingSameBlockAttribute chain and creates per-\n\t\t\t// character undo levels.\n\t\t\trestoreSelection();\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\tgetBlockParents,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\t\tlet prevSelectionStart = getSelectionStart();\n\t\tlet prevSelectionEnd = getSelectionEnd();\n\n\t\tsubscribedRef.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\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( pendingChangesRef.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChangesRef.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\tconst blocksChanged = areBlocksDifferent || didPersistenceChange;\n\n\t\t\t// Check if selection changed.\n\t\t\tconst newSelectionStart = getSelectionStart();\n\t\t\tconst newSelectionEnd = getSelectionEnd();\n\t\t\tconst selectionChanged =\n\t\t\t\tnewSelectionStart !== prevSelectionStart ||\n\t\t\t\tnewSelectionEnd !== prevSelectionEnd;\n\n\t\t\tif ( selectionChanged ) {\n\t\t\t\tprevSelectionStart = newSelectionStart;\n\t\t\t\tprevSelectionEnd = newSelectionEnd;\n\t\t\t}\n\n\t\t\tif ( blocksChanged || selectionChanged ) {\n\t\t\t\t// Batch block and selection updates so the entity\n\t\t\t\t// receives both changes atomically.\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tif ( blocksChanged ) {\n\t\t\t\t\t\tisPersistent = newIsPersistent;\n\n\t\t\t\t\t\t// For inner block controllers (clientId is set), restore external IDs\n\t\t\t\t\t\t// before passing blocks to the parent.\n\t\t\t\t\t\tconst blocksForParent = clientId\n\t\t\t\t\t\t\t? restoreExternalIds( blocks, idMappingRef.current )\n\t\t\t\t\t\t\t: blocks;\n\n\t\t\t\t\t\t// Build selection state for the undo level.\n\t\t\t\t\t\tconst selectionInfo = {\n\t\t\t\t\t\t\tselectionStart: newSelectionStart,\n\t\t\t\t\t\t\tselectionEnd: newSelectionEnd,\n\t\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t\t};\n\t\t\t\t\t\t// Restore external IDs in selection for inner block controllers.\n\t\t\t\t\t\tconst selectionForParent = clientId\n\t\t\t\t\t\t\t? restoreSelectionIds(\n\t\t\t\t\t\t\t\t\tselectionInfo,\n\t\t\t\t\t\t\t\t\tidMappingRef.current\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: selectionInfo;\n\n\t\t\t\t\t\tpendingChangesRef.current.outgoing.push(\n\t\t\t\t\t\t\tblocksForParent\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t\t\t: onInputRef.current;\n\t\t\t\t\t\tupdateParent( blocksForParent, {\n\t\t\t\t\t\t\tselection: selectionForParent,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectionChanged &&\n\t\t\t\t\t\t! blocksChanged &&\n\t\t\t\t\t\tnewSelectionStart?.clientId &&\n\t\t\t\t\t\t! isRestoringSelectionRef.current\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Report selection via onChangeSelection.\n\t\t\t\t\t\t// Each useBlockSync only reports if the selected block\n\t\t\t\t\t\t// is within its own scope.\n\t\t\t\t\t\t// Inner block controllers own the block if the internal\n\t\t\t\t\t\t// ID appears in their clone mapping.\n\t\t\t\t\t\t// The root controller owns it if the block is not inside\n\t\t\t\t\t\t// any controlled inner block.\n\t\t\t\t\t\tconst isOurs = clientId\n\t\t\t\t\t\t\t? idMappingRef.current.internalToExternal.has(\n\t\t\t\t\t\t\t\t\tnewSelectionStart.clientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: ! getBlockParents(\n\t\t\t\t\t\t\t\t\tnewSelectionStart.clientId\n\t\t\t\t\t\t\t ).some( ( parentId ) =>\n\t\t\t\t\t\t\t\t\tareInnerBlocksControlled( parentId )\n\t\t\t\t\t\t\t );\n\n\t\t\t\t\t\tif ( isOurs ) {\n\t\t\t\t\t\t\tconst selectionInfo = {\n\t\t\t\t\t\t\t\tselectionStart: newSelectionStart,\n\t\t\t\t\t\t\t\tselectionEnd: newSelectionEnd,\n\t\t\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\t\tclientId\n\t\t\t\t\t\t\t\t\t? restoreSelectionIds(\n\t\t\t\t\t\t\t\t\t\t\tselectionInfo,\n\t\t\t\t\t\t\t\t\t\t\tidMappingRef.current\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: selectionInfo\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t}, blockEditorStore );\n\n\t\treturn () => {\n\t\t\tsubscribedRef.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"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,YAAY,WAAW,cAAc;AAC9C,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAK3B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,wBAAwB;AAEjC,IAAM,OAAO,MAAM;AAAC;AAapB,SAAS,sBAAuB,OAAO,SAAU;AAChD,QAAM,cAAc,WAAY,KAAM;AAGtC,UAAQ,mBAAmB,IA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D,IAAI,SAAS,OAAQ,gBAAiB;AAEtC,QAAI,SAAS,UAAW,QAAS;AACjC,QAAI,eAAe,4BAA4B;AAC/C,QAAI,6BAA6B;AACjC,QAAI,qBAAqB,kBAAkB;AAC3C,QAAI,mBAAmB,gBAAgB;AAEvC,kBAAc,UAAU;AACxB,UAAM,cAAc,SAAS,UAAW,MAAM;AAQ7C,UAAK,aAAa,QAAQ,aAAc,QAAS,MAAM,MAAO;AAC7D;AAAA,MACD;AAEA,YAAM,kBAAkB,4BAA4B;AACpD,YAAM,YAAY,UAAW,QAAS;AACtC,YAAM,qBAAqB,cAAc;AACzC,eAAS;AACT,UACC,uBACE,kBAAkB,QAAQ,YAC3B,mCAAmC,IACnC;AACD,0BAAkB,QAAQ,WAAW;AACrC,uBAAe;AACf;AAAA,MACD;AAKA,YAAM,uBACL,8BACA,CAAE,sBACF,mBACA,CAAE;AAEH,YAAM,gBAAgB,sBAAsB;AAG5C,YAAM,oBAAoB,kBAAkB;AAC5C,YAAM,kBAAkB,gBAAgB;AACxC,YAAM,mBACL,sBAAsB,sBACtB,oBAAoB;AAErB,UAAK,kBAAmB;AACvB,6BAAqB;AACrB,2BAAmB;AAAA,MACpB;AAEA,UAAK,iBAAiB,kBAAmB;AAGxC,iBAAS,MAAO,MAAM;AACrB,cAAK,eAAgB;AACpB,2BAAe;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext, 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 { SelectionContext } from './selection-context';\n\nconst noop = () => {};\n\n/**\n * Clones a block and its inner blocks, building a bidirectional mapping\n * between external (original) and internal (cloned) client IDs.\n *\n * This allows the block editor to use unique internal IDs while preserving\n * stable external IDs for features like real-time collaboration.\n *\n * @param {Object} block The block to clone.\n * @param {Object} mapping The mapping object with externalToInternal and internalToExternal Maps.\n * @return {Object} The cloned block with a new clientId.\n */\nfunction cloneBlockWithMapping( block, mapping ) {\n\tconst clonedBlock = cloneBlock( block );\n\n\t// Build bidirectional mapping\n\tmapping.externalToInternal.set( block.clientId, clonedBlock.clientId );\n\tmapping.internalToExternal.set( clonedBlock.clientId, block.clientId );\n\n\t// Recursively map inner blocks\n\tif ( block.innerBlocks?.length ) {\n\t\tclonedBlock.innerBlocks = block.innerBlocks.map( ( innerBlock ) => {\n\t\t\tconst clonedInner = cloneBlockWithMapping( innerBlock, mapping );\n\t\t\t// The clonedBlock already has cloned inner blocks from cloneBlock(),\n\t\t\t// but we need to use our mapped versions to maintain the mapping.\n\t\t\treturn clonedInner;\n\t\t} );\n\t}\n\n\treturn clonedBlock;\n}\n\n/**\n * Restores external (original) client IDs on blocks before passing them\n * to onChange/onInput callbacks.\n *\n * @param {Object[]} blocks The blocks with internal client IDs.\n * @param {Object} mapping The mapping object with internalToExternal Map.\n * @return {Object[]} Blocks with external client IDs restored.\n */\nfunction restoreExternalIds( blocks, mapping ) {\n\treturn blocks.map( ( block ) => {\n\t\tconst externalId = mapping.internalToExternal.get( block.clientId );\n\t\treturn {\n\t\t\t...block,\n\t\t\t// Use external ID if available, otherwise keep internal ID (for new blocks)\n\t\t\tclientId: externalId ?? block.clientId,\n\t\t\tinnerBlocks: restoreExternalIds( block.innerBlocks, mapping ),\n\t\t};\n\t} );\n}\n\n/**\n * Restores external client IDs in selection state.\n *\n * @param {Object} selectionState The selection state with internal client IDs.\n * @param {Object} mapping The mapping object with internalToExternal Map.\n * @return {Object} Selection state with external client IDs.\n */\nfunction restoreSelectionIds( selectionState, mapping ) {\n\tconst { selectionStart, selectionEnd, initialPosition } = selectionState;\n\n\tconst restoreClientId = ( sel ) => {\n\t\tif ( ! sel?.clientId ) {\n\t\t\treturn sel;\n\t\t}\n\t\tconst externalId = mapping.internalToExternal.get( sel.clientId );\n\t\treturn {\n\t\t\t...sel,\n\t\t\tclientId: externalId ?? sel.clientId,\n\t\t};\n\t};\n\n\treturn {\n\t\tselectionStart: restoreClientId( selectionStart ),\n\t\tselectionEnd: restoreClientId( selectionEnd ),\n\t\tinitialPosition,\n\t};\n}\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 * - Initializes 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 initialize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\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\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\tconst { getSelection, onChangeSelection } = useContext( SelectionContext );\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 pendingChangesRef = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribedRef = useRef( false );\n\n\t// Mapping between external (original) and internal (cloned) client IDs.\n\t// This allows stable external IDs while using unique internal IDs.\n\tconst idMappingRef = useRef( {\n\t\texternalToInternal: new Map(),\n\t\tinternalToExternal: new Map(),\n\t} );\n\n\t// Tracks which context selection has already been applied, to avoid\n\t// duplicate restoration.\n\tconst appliedSelectionRef = useRef( null );\n\t// Flag to prevent the subscription from re-reporting a selection\n\t// change that was just restored from context (which would loop).\n\tconst isRestoringSelectionRef = useRef( false );\n\n\t// Restores selection from the SelectionContext using the current\n\t// idMapping. Called after blocks are (re-)cloned so that the\n\t// mapping is guaranteed to be fresh.\n\tconst restoreSelection = () => {\n\t\tconst selection = getSelection();\n\t\tif (\n\t\t\t! selection?.selectionStart?.clientId ||\n\t\t\tselection === appliedSelectionRef.current\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst startClientId = selection.selectionStart.clientId;\n\n\t\t// Check if this selection belongs to this controller.\n\t\t// Inner block controllers (clientId is set) own the block if\n\t\t// the external ID appears in their clone mapping.\n\t\t// The root controller (no clientId) owns it if the block\n\t\t// exists directly in the store.\n\t\tconst isOurs = clientId\n\t\t\t? idMappingRef.current.externalToInternal.has( startClientId )\n\t\t\t: !! getBlockName( startClientId );\n\n\t\tif ( isOurs ) {\n\t\t\tappliedSelectionRef.current = selection;\n\t\t\t// Inner block controllers need to convert external→internal\n\t\t\t// IDs via the clone mapping; the root controller uses\n\t\t\t// external IDs directly (no mapping needed).\n\t\t\tconst convert = ( sel ) => {\n\t\t\t\tif ( ! sel?.clientId || ! clientId ) {\n\t\t\t\t\treturn sel;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...sel,\n\t\t\t\t\tclientId:\n\t\t\t\t\t\tidMappingRef.current.externalToInternal.get(\n\t\t\t\t\t\t\tsel.clientId\n\t\t\t\t\t\t) ?? sel.clientId,\n\t\t\t\t};\n\t\t\t};\n\t\t\t// Flag prevents the subscription from re-reporting this\n\t\t\t// selection change back to the entity (which would cause\n\t\t\t// an infinite update loop).\n\t\t\tisRestoringSelectionRef.current = true;\n\t\t\tresetSelection(\n\t\t\t\tconvert( selection.selectionStart ),\n\t\t\t\tconvert( selection.selectionEnd ),\n\t\t\t\tselection.initialPosition\n\t\t\t);\n\t\t\tisRestoringSelectionRef.current = false;\n\t\t}\n\t};\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\tif ( clientId ) {\n\t\t\t// Batch so that the controlled flag and block replacement\n\t\t\t// are applied atomically — subscribers see a consistent state.\n\t\t\tregistry.batch( () => {\n\t\t\t\t// Clear previous mappings and build new ones during cloning.\n\t\t\t\t// This ensures the mapping stays in sync with the current blocks.\n\t\t\t\tidMappingRef.current.externalToInternal.clear();\n\t\t\t\tidMappingRef.current.internalToExternal.clear();\n\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlockWithMapping( block, idMappingRef.current )\n\t\t\t\t);\n\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\n\t\t\t\tif ( subscribedRef.current ) {\n\t\t\t\t\tpendingChangesRef.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\n\t\t\t\t// Invalidate the applied-selection ref so that\n\t\t\t\t// restoreSelection() at the end of the\n\t\t\t\t// controlledBlocks effect re-applies with the\n\t\t\t\t// freshly-built mapping (new internal IDs).\n\t\t\t\tappliedSelectionRef.current = null;\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribedRef.current ) {\n\t\t\t\tpendingChangesRef.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\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\t// Also restores selection from context after blocks are set.\n\tuseEffect( () => {\n\t\tconst isOutgoing =\n\t\t\tpendingChangesRef.current.outgoing.includes( controlledBlocks );\n\t\tconst storeMatch = getBlocks( clientId ) === controlledBlocks;\n\n\t\tif ( isOutgoing ) {\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\tpendingChangesRef.current.outgoing[\n\t\t\t\t\tpendingChangesRef.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChangesRef.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( ! storeMatch ) {\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\tpendingChangesRef.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\n\t\t\t// Restore selection from context if it targets our scope.\n\t\t\t// Only done when blocks were reset from an external source\n\t\t\t// (undo/redo, entity navigation) — NOT for outgoing changes,\n\t\t\t// because dispatching resetSelection between keystrokes breaks\n\t\t\t// the isUpdatingSameBlockAttribute chain and creates per-\n\t\t\t// character undo levels.\n\t\t\trestoreSelection();\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__unstableGetLastBlockChangeHistoryMode,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t\tgetBlockParents,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet blockHistoryMode = __unstableGetLastBlockChangeHistoryMode();\n\t\tlet previousAreBlocksDifferent = false;\n\t\tlet prevSelectionStart = getSelectionStart();\n\t\tlet prevSelectionEnd = getSelectionEnd();\n\n\t\tsubscribedRef.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\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlockHistoryMode =\n\t\t\t\t__unstableGetLastBlockChangeHistoryMode();\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( pendingChangesRef.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChangesRef.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\tblockHistoryMode = newBlockHistoryMode;\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\tconst blocksChanged = areBlocksDifferent || didPersistenceChange;\n\n\t\t\t// Check if selection changed.\n\t\t\tconst newSelectionStart = getSelectionStart();\n\t\t\tconst newSelectionEnd = getSelectionEnd();\n\t\t\tconst selectionChanged =\n\t\t\t\tnewSelectionStart !== prevSelectionStart ||\n\t\t\t\tnewSelectionEnd !== prevSelectionEnd;\n\n\t\t\tif ( selectionChanged ) {\n\t\t\t\tprevSelectionStart = newSelectionStart;\n\t\t\t\tprevSelectionEnd = newSelectionEnd;\n\t\t\t}\n\n\t\t\tif ( blocksChanged || selectionChanged ) {\n\t\t\t\t// Batch block and selection updates so the entity\n\t\t\t\t// receives both changes atomically.\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tif ( blocksChanged ) {\n\t\t\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t\t\tblockHistoryMode = newBlockHistoryMode;\n\n\t\t\t\t\t\t// For inner block controllers (clientId is set), restore external IDs\n\t\t\t\t\t\t// before passing blocks to the parent.\n\t\t\t\t\t\tconst blocksForParent = clientId\n\t\t\t\t\t\t\t? restoreExternalIds( blocks, idMappingRef.current )\n\t\t\t\t\t\t\t: blocks;\n\n\t\t\t\t\t\t// Build selection state for the undo level.\n\t\t\t\t\t\tconst selectionInfo = {\n\t\t\t\t\t\t\tselectionStart: newSelectionStart,\n\t\t\t\t\t\t\tselectionEnd: newSelectionEnd,\n\t\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t\t};\n\t\t\t\t\t\t// Restore external IDs in selection for inner block controllers.\n\t\t\t\t\t\tconst selectionForParent = clientId\n\t\t\t\t\t\t\t? restoreSelectionIds(\n\t\t\t\t\t\t\t\t\tselectionInfo,\n\t\t\t\t\t\t\t\t\tidMappingRef.current\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: selectionInfo;\n\n\t\t\t\t\t\tpendingChangesRef.current.outgoing.push(\n\t\t\t\t\t\t\tblocksForParent\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t\t\t: onInputRef.current;\n\t\t\t\t\t\tconst updateOptions = {\n\t\t\t\t\t\t\tselection: selectionForParent,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif ( blockHistoryMode === 'ignore' ) {\n\t\t\t\t\t\t\tupdateOptions.undoIgnore = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tupdateParent( blocksForParent, updateOptions );\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectionChanged &&\n\t\t\t\t\t\t! blocksChanged &&\n\t\t\t\t\t\tnewSelectionStart?.clientId &&\n\t\t\t\t\t\t! isRestoringSelectionRef.current\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Report selection via onChangeSelection.\n\t\t\t\t\t\t// Each useBlockSync only reports if the selected block\n\t\t\t\t\t\t// is within its own scope.\n\t\t\t\t\t\t// Inner block controllers own the block if the internal\n\t\t\t\t\t\t// ID appears in their clone mapping.\n\t\t\t\t\t\t// The root controller owns it if the block is not inside\n\t\t\t\t\t\t// any controlled inner block.\n\t\t\t\t\t\tconst isOurs = clientId\n\t\t\t\t\t\t\t? idMappingRef.current.internalToExternal.has(\n\t\t\t\t\t\t\t\t\tnewSelectionStart.clientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: ! getBlockParents(\n\t\t\t\t\t\t\t\t\tnewSelectionStart.clientId\n\t\t\t\t\t\t\t ).some( ( parentId ) =>\n\t\t\t\t\t\t\t\t\tareInnerBlocksControlled( parentId )\n\t\t\t\t\t\t\t );\n\n\t\t\t\t\t\tif ( isOurs ) {\n\t\t\t\t\t\t\tconst selectionInfo = {\n\t\t\t\t\t\t\t\tselectionStart: newSelectionStart,\n\t\t\t\t\t\t\t\tselectionEnd: newSelectionEnd,\n\t\t\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\t\tclientId\n\t\t\t\t\t\t\t\t\t? restoreSelectionIds(\n\t\t\t\t\t\t\t\t\t\t\tselectionInfo,\n\t\t\t\t\t\t\t\t\t\t\tidMappingRef.current\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: selectionInfo\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t}, blockEditorStore );\n\n\t\treturn () => {\n\t\t\tsubscribedRef.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tunset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
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// packages/block-editor/src/components/rich-text/event-listeners/before-input-rules.js
|
|
2
2
|
import { insert, isCollapsed } from "@wordpress/rich-text";
|
|
3
3
|
import { applyFilters } from "@wordpress/hooks";
|
|
4
|
+
import { privateApis as composePrivateApis } from "@wordpress/compose";
|
|
4
5
|
import { store as blockEditorStore } from "../../../store/index.mjs";
|
|
5
|
-
|
|
6
|
+
import { unlock } from "../../../lock-unlock.mjs";
|
|
7
|
+
var { subscribeDelegatedListener } = unlock(composePrivateApis);
|
|
8
|
+
var wrapSelectionSettings = ["`", '"', "'", "“”", "‘’"];
|
|
6
9
|
var before_input_rules_default = (props) => (element) => {
|
|
7
10
|
function onInput(event) {
|
|
8
11
|
const { inputType, data } = event;
|
|
@@ -47,10 +50,7 @@ var before_input_rules_default = (props) => (element) => {
|
|
|
47
50
|
});
|
|
48
51
|
event.preventDefault();
|
|
49
52
|
}
|
|
50
|
-
element
|
|
51
|
-
return () => {
|
|
52
|
-
element.removeEventListener("beforeinput", onInput);
|
|
53
|
-
};
|
|
53
|
+
return subscribeDelegatedListener(element, "beforeinput", onInput, true);
|
|
54
54
|
};
|
|
55
55
|
export {
|
|
56
56
|
before_input_rules_default as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/rich-text/event-listeners/before-input-rules.js"],
|
|
4
|
-
"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 = [ '`', '\"', \"'\", '
|
|
5
|
-
"mappings": ";AAGA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { insert, isCollapsed } from '@wordpress/rich-text';\nimport { applyFilters } from '@wordpress/hooks';\nimport { privateApis as composePrivateApis } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\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\treturn subscribeDelegatedListener( element, 'beforeinput', onInput, true );\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,oBAAoB;AAC7B,SAAS,eAAe,0BAA0B;AAKlD,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AAEvB,IAAM,EAAE,2BAA2B,IAAI,OAAQ,kBAAmB;AASlE,IAAM,wBAAwB,CAAE,KAAK,KAAK,KAAK,MAAM,IAAK;AAE1D,IAAO,6BAAQ,CAAE,UAAW,CAAE,YAAa;AAC1C,WAAS,QAAS,OAAQ;AACzB,UAAM,EAAE,WAAW,KAAK,IAAI;AAC5B,UAAM,EAAE,OAAO,UAAU,SAAS,IAAI,MAAM;AAG5C,QAAK,cAAc,cAAe;AACjC;AAAA,IACD;AAEA,QAAK,YAAa,KAAM,GAAI;AAC3B;AAAA,IACD;AAEA,UAAM,OAAO;AAAA,MACZ;AAAA,MACA;AAAA,IACD,EAAE;AAAA,MACD,CAAE,CAAEA,YAAWC,QAAQ,MAAOD,eAAc,QAAQC,aAAY;AAAA,IACjE;AAEA,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AAEA,UAAM,CAAE,WAAW,UAAU,SAAU,IAAI;AAC3C,UAAM,QAAQ,MAAM;AACpB,UAAM,MAAM,MAAM,MAAM,UAAU;AAElC,QAAI,WAAW,OAAQ,OAAO,WAAW,OAAO,KAAM;AACtD,eAAW,OAAQ,UAAU,SAAS,KAAK,GAAI;AAE/C,UAAM;AAAA,MACL;AAAA,MACA;AAAA,IACD,IAAI,SAAS,SAAU,gBAAiB;AAExC,yCAAqC;AACrC,aAAU,QAAS;AACnB,kCAA8B;AAE9B,UAAM,OAAO,CAAC;AAEd,eAAY,OAAO,OAAQ;AAC1B,WAAM,GAAI,IAAI,MAAO,GAAI;AAAA,IAC1B;AAEA,SAAK,OAAO;AAEZ,UAAM,EAAE,cAAc,IAAI;AAC1B,UAAM,EAAE,YAAY,IAAI;AACxB,UAAM,WAAW,IAAI,YAAY,WAAY,SAAS,IAAK;AAU3D,WAAO,eAAgB,MAAM;AAC5B,YAAM,OAAO,cAAe,QAAS;AAAA,IACtC,CAAE;AACF,UAAM,eAAe;AAAA,EACtB;AAEA,SAAO,2BAA4B,SAAS,eAAe,SAAS,IAAK;AAC1E;",
|
|
6
6
|
"names": ["startChar", "endChar"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// packages/block-editor/src/components/rich-text/event-listeners/delete.js
|
|
2
2
|
import { DELETE, BACKSPACE } from "@wordpress/keycodes";
|
|
3
3
|
import { isCollapsed, isEmpty } from "@wordpress/rich-text";
|
|
4
|
+
import { privateApis as composePrivateApis } from "@wordpress/compose";
|
|
5
|
+
import { unlock } from "../../../lock-unlock.mjs";
|
|
6
|
+
var { subscribeDelegatedListener } = unlock(composePrivateApis);
|
|
4
7
|
var delete_default = (props) => (element) => {
|
|
5
8
|
function onKeyDown(event) {
|
|
6
9
|
const { keyCode } = event;
|
|
@@ -23,10 +26,7 @@ var delete_default = (props) => (element) => {
|
|
|
23
26
|
event.preventDefault();
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
element
|
|
27
|
-
return () => {
|
|
28
|
-
element.removeEventListener("keydown", onKeyDown);
|
|
29
|
-
};
|
|
29
|
+
return subscribeDelegatedListener(element, "keydown", onKeyDown);
|
|
30
30
|
};
|
|
31
31
|
export {
|
|
32
32
|
delete_default as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/rich-text/event-listeners/delete.js"],
|
|
4
|
-
"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\
|
|
5
|
-
"mappings": ";AAGA,SAAS,QAAQ,iBAAiB;AAClC,SAAS,aAAa,eAAe;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DELETE, BACKSPACE } from '@wordpress/keycodes';\nimport { isCollapsed, isEmpty } from '@wordpress/rich-text';\nimport { privateApis as composePrivateApis } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\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\treturn subscribeDelegatedListener( element, 'keydown', onKeyDown );\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,QAAQ,iBAAiB;AAClC,SAAS,aAAa,eAAe;AACrC,SAAS,eAAe,0BAA0B;AAKlD,SAAS,cAAc;AAEvB,IAAM,EAAE,2BAA2B,IAAI,OAAQ,kBAAmB;AAElE,IAAO,iBAAQ,CAAE,UAAW,CAAE,YAAa;AAC1C,WAAS,UAAW,OAAQ;AAC3B,UAAM,EAAE,QAAQ,IAAI;AAEpB,QAAK,MAAM,kBAAmB;AAC7B;AAAA,IACD;AAEA,UAAM,EAAE,OAAO,SAAS,SAAS,IAAI,MAAM;AAE3C,QAAK,YAAY,UAAU,YAAY,WAAY;AAClD,YAAM,EAAE,OAAO,KAAK,KAAK,IAAI;AAC7B,YAAM,YAAY,YAAY;AAC9B,YAAM,mBACL,MAAM,iBAAiB,CAAC,CAAE,MAAM,cAAc;AAG/C,UACC,CAAE,YAAa,KAAM,KACrB,oBACE,aAAa,UAAU,KACvB,CAAE,aAAa,QAAQ,KAAK,QAC7B;AACD;AAAA,MACD;AAEA,UAAK,SAAU;AACd,gBAAS,CAAE,SAAU;AAAA,MACtB,WAMU,YAAY,QAAS,KAAM,KAAK,WAAY;AACrD,iBAAU,CAAE,SAAU;AAAA,MACvB;AAEA,YAAM,eAAe;AAAA,IACtB;AAAA,EACD;AAEA,SAAO,2BAA4B,SAAS,WAAW,SAAU;AAClE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -62,10 +62,15 @@ var enter_default = (props) => (element) => {
|
|
|
62
62
|
"keydown",
|
|
63
63
|
onKeyDown
|
|
64
64
|
);
|
|
65
|
-
|
|
65
|
+
const unsubscribeKeyDownDeprecated = subscribeDelegatedListener(
|
|
66
|
+
element,
|
|
67
|
+
"keydown",
|
|
68
|
+
onKeyDownDeprecated,
|
|
69
|
+
true
|
|
70
|
+
);
|
|
66
71
|
return () => {
|
|
67
72
|
unsubscribeKeyDown();
|
|
68
|
-
|
|
73
|
+
unsubscribeKeyDownDeprecated();
|
|
69
74
|
};
|
|
70
75
|
};
|
|
71
76
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/rich-text/event-listeners/enter.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { ENTER } from '@wordpress/keycodes';\nimport { insert, remove } from '@wordpress/rich-text';\nimport { privateApis as composePrivateApis } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\n\nexport default ( props ) => ( element ) => {\n\tfunction onKeyDownDeprecated( event ) {\n\t\tif ( event.keyCode !== ENTER ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { onReplace, onSplit } = props.current;\n\n\t\tif ( onReplace && onSplit ) {\n\t\t\tevent.__deprecatedOnSplit = true;\n\t\t}\n\t}\n\n\tfunction onKeyDown( event ) {\n\t\tif ( event.defaultPrevented ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The event listener is attached to the window, so we need to check if\n\t\t// the target is the element.\n\t\tif ( event.target !== element ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( event.keyCode !== ENTER ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst {\n\t\t\tvalue,\n\t\t\tonChange,\n\t\t\tdisableLineBreaks,\n\t\t\tonSplitAtEnd,\n\t\t\tonSplitAtDoubleLineEnd,\n\t\t\tregistry,\n\t\t} = props.current;\n\n\t\tevent.preventDefault();\n\n\t\tconst { text, start, end } = value;\n\n\t\tif ( event.shiftKey ) {\n\t\t\tif ( ! disableLineBreaks ) {\n\t\t\t\tonChange( insert( value, '\\n' ) );\n\t\t\t}\n\t\t} else if ( onSplitAtEnd && start === end && end === text.length ) {\n\t\t\tonSplitAtEnd();\n\t\t} else if (\n\t\t\t// For some blocks it's desirable to split at the end of the\n\t\t\t// block when there are two line breaks at the end of the\n\t\t\t// block, so triple Enter exits the block.\n\t\t\tonSplitAtDoubleLineEnd &&\n\t\t\tstart === end &&\n\t\t\tend === text.length &&\n\t\t\ttext.slice( -2 ) === '\\n\\n'\n\t\t) {\n\t\t\tregistry.batch( () => {\n\t\t\t\tconst _value = { ...value };\n\t\t\t\t_value.start = _value.end - 2;\n\t\t\t\tonChange( remove( _value ) );\n\t\t\t\tonSplitAtDoubleLineEnd();\n\t\t\t} );\n\t\t} else if ( ! disableLineBreaks ) {\n\t\t\tonChange( insert( value, '\\n' ) );\n\t\t}\n\t}\n\n\tconst { defaultView } = element.ownerDocument;\n\n\t// Attach the listener to the window so parent elements have the chance to\n\t// prevent the default behavior.\n\tconst unsubscribeKeyDown = subscribeDelegatedListener(\n\t\tdefaultView,\n\t\t'keydown',\n\t\tonKeyDown\n\t);\n\
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,QAAQ,cAAc;AAC/B,SAAS,eAAe,0BAA0B;AAKlD,SAAS,cAAc;AAEvB,IAAM,EAAE,2BAA2B,IAAI,OAAQ,kBAAmB;AAElE,IAAO,gBAAQ,CAAE,UAAW,CAAE,YAAa;AAC1C,WAAS,oBAAqB,OAAQ;AACrC,QAAK,MAAM,YAAY,OAAQ;AAC9B;AAAA,IACD;AAEA,UAAM,EAAE,WAAW,QAAQ,IAAI,MAAM;AAErC,QAAK,aAAa,SAAU;AAC3B,YAAM,sBAAsB;AAAA,IAC7B;AAAA,EACD;AAEA,WAAS,UAAW,OAAQ;AAC3B,QAAK,MAAM,kBAAmB;AAC7B;AAAA,IACD;AAIA,QAAK,MAAM,WAAW,SAAU;AAC/B;AAAA,IACD;AAEA,QAAK,MAAM,YAAY,OAAQ;AAC9B;AAAA,IACD;AAEA,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,IAAI,MAAM;AAEV,UAAM,eAAe;AAErB,UAAM,EAAE,MAAM,OAAO,IAAI,IAAI;AAE7B,QAAK,MAAM,UAAW;AACrB,UAAK,CAAE,mBAAoB;AAC1B,iBAAU,OAAQ,OAAO,IAAK,CAAE;AAAA,MACjC;AAAA,IACD,WAAY,gBAAgB,UAAU,OAAO,QAAQ,KAAK,QAAS;AAClE,mBAAa;AAAA,IACd;AAAA;AAAA;AAAA;AAAA,MAIC,0BACA,UAAU,OACV,QAAQ,KAAK,UACb,KAAK,MAAO,EAAG,MAAM;AAAA,MACpB;AACD,eAAS,MAAO,MAAM;AACrB,cAAM,SAAS,EAAE,GAAG,MAAM;AAC1B,eAAO,QAAQ,OAAO,MAAM;AAC5B,iBAAU,OAAQ,MAAO,CAAE;AAC3B,+BAAuB;AAAA,MACxB,CAAE;AAAA,IACH,WAAY,CAAE,mBAAoB;AACjC,eAAU,OAAQ,OAAO,IAAK,CAAE;AAAA,IACjC;AAAA,EACD;AAEA,QAAM,EAAE,YAAY,IAAI,QAAQ;AAIhC,QAAM,qBAAqB;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,EACD;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { ENTER } from '@wordpress/keycodes';\nimport { insert, remove } from '@wordpress/rich-text';\nimport { privateApis as composePrivateApis } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\n\nexport default ( props ) => ( element ) => {\n\tfunction onKeyDownDeprecated( event ) {\n\t\tif ( event.keyCode !== ENTER ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { onReplace, onSplit } = props.current;\n\n\t\tif ( onReplace && onSplit ) {\n\t\t\tevent.__deprecatedOnSplit = true;\n\t\t}\n\t}\n\n\tfunction onKeyDown( event ) {\n\t\tif ( event.defaultPrevented ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The event listener is attached to the window, so we need to check if\n\t\t// the target is the element.\n\t\tif ( event.target !== element ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( event.keyCode !== ENTER ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst {\n\t\t\tvalue,\n\t\t\tonChange,\n\t\t\tdisableLineBreaks,\n\t\t\tonSplitAtEnd,\n\t\t\tonSplitAtDoubleLineEnd,\n\t\t\tregistry,\n\t\t} = props.current;\n\n\t\tevent.preventDefault();\n\n\t\tconst { text, start, end } = value;\n\n\t\tif ( event.shiftKey ) {\n\t\t\tif ( ! disableLineBreaks ) {\n\t\t\t\tonChange( insert( value, '\\n' ) );\n\t\t\t}\n\t\t} else if ( onSplitAtEnd && start === end && end === text.length ) {\n\t\t\tonSplitAtEnd();\n\t\t} else if (\n\t\t\t// For some blocks it's desirable to split at the end of the\n\t\t\t// block when there are two line breaks at the end of the\n\t\t\t// block, so triple Enter exits the block.\n\t\t\tonSplitAtDoubleLineEnd &&\n\t\t\tstart === end &&\n\t\t\tend === text.length &&\n\t\t\ttext.slice( -2 ) === '\\n\\n'\n\t\t) {\n\t\t\tregistry.batch( () => {\n\t\t\t\tconst _value = { ...value };\n\t\t\t\t_value.start = _value.end - 2;\n\t\t\t\tonChange( remove( _value ) );\n\t\t\t\tonSplitAtDoubleLineEnd();\n\t\t\t} );\n\t\t} else if ( ! disableLineBreaks ) {\n\t\t\tonChange( insert( value, '\\n' ) );\n\t\t}\n\t}\n\n\tconst { defaultView } = element.ownerDocument;\n\n\t// Attach the listener to the window so parent elements have the chance to\n\t// prevent the default behavior.\n\tconst unsubscribeKeyDown = subscribeDelegatedListener(\n\t\tdefaultView,\n\t\t'keydown',\n\t\tonKeyDown\n\t);\n\t// Capture phase so this runs before ancestor (writing flow) bubble\n\t// handlers, matching the timing of the previous raw element listener.\n\tconst unsubscribeKeyDownDeprecated = subscribeDelegatedListener(\n\t\telement,\n\t\t'keydown',\n\t\tonKeyDownDeprecated,\n\t\ttrue\n\t);\n\treturn () => {\n\t\tunsubscribeKeyDown();\n\t\tunsubscribeKeyDownDeprecated();\n\t};\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,QAAQ,cAAc;AAC/B,SAAS,eAAe,0BAA0B;AAKlD,SAAS,cAAc;AAEvB,IAAM,EAAE,2BAA2B,IA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AM,+BAA+B;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SAAO,MAAM;AACZ,uBAAmB;AACnB,iCAA6B;AAAA,EAC9B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// packages/block-editor/src/components/rich-text/event-listeners/input-events.js
|
|
2
|
+
import { privateApis as composePrivateApis } from "@wordpress/compose";
|
|
3
|
+
import { unlock } from "../../../lock-unlock.mjs";
|
|
4
|
+
var { subscribeDelegatedListener } = unlock(composePrivateApis);
|
|
2
5
|
var input_events_default = (props) => (element) => {
|
|
3
6
|
const { inputEvents } = props.current;
|
|
4
7
|
function onInput(event) {
|
|
@@ -6,10 +9,7 @@ var input_events_default = (props) => (element) => {
|
|
|
6
9
|
keyboardShortcut(event);
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
|
-
element
|
|
10
|
-
return () => {
|
|
11
|
-
element.removeEventListener("input", onInput);
|
|
12
|
-
};
|
|
12
|
+
return subscribeDelegatedListener(element, "input", onInput);
|
|
13
13
|
};
|
|
14
14
|
export {
|
|
15
15
|
input_events_default as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/rich-text/event-listeners/input-events.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis as composePrivateApis } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\n\nexport default ( props ) => ( element ) => {\n\tconst { inputEvents } = props.current;\n\tfunction onInput( event ) {\n\t\tfor ( const keyboardShortcut of inputEvents.current ) {\n\t\t\tkeyboardShortcut( event );\n\t\t}\n\t}\n\n\treturn subscribeDelegatedListener( element, 'input', onInput );\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,eAAe,0BAA0B;AAKlD,SAAS,cAAc;AAEvB,IAAM,EAAE,2BAA2B,IAAI,OAAQ,kBAAmB;AAElE,IAAO,uBAAQ,CAAE,UAAW,CAAE,YAAa;AAC1C,QAAM,EAAE,YAAY,IAAI,MAAM;AAC9B,WAAS,QAAS,OAAQ;AACzB,eAAY,oBAAoB,YAAY,SAAU;AACrD,uBAAkB,KAAM;AAAA,IACzB;AAAA,EACD;AAEA,SAAO,2BAA4B,SAAS,SAAS,OAAQ;AAC9D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// packages/block-editor/src/components/rich-text/event-listeners/input-rules.js
|
|
2
2
|
import { insert, toHTMLString } from "@wordpress/rich-text";
|
|
3
3
|
import { getBlockTransforms, findTransform } from "@wordpress/blocks";
|
|
4
|
+
import { privateApis as composePrivateApis } from "@wordpress/compose";
|
|
4
5
|
import { store as blockEditorStore } from "../../../store/index.mjs";
|
|
5
6
|
import { preventEventDiscovery } from "../prevent-event-discovery.mjs";
|
|
6
7
|
import {
|
|
7
8
|
retrieveSelectedAttribute,
|
|
8
9
|
START_OF_SELECTED_AREA
|
|
9
10
|
} from "../../../utils/selection.mjs";
|
|
11
|
+
import { unlock } from "../../../lock-unlock.mjs";
|
|
12
|
+
var { subscribeDelegatedListener } = unlock(composePrivateApis);
|
|
10
13
|
function findSelection(blocks) {
|
|
11
14
|
let i = blocks.length;
|
|
12
15
|
while (i--) {
|
|
@@ -108,11 +111,21 @@ var input_rules_default = (props) => (element) => {
|
|
|
108
111
|
__unstableMarkAutomaticChange();
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
const unsubscribeInput = subscribeDelegatedListener(
|
|
115
|
+
element,
|
|
116
|
+
"input",
|
|
117
|
+
onInput,
|
|
118
|
+
true
|
|
119
|
+
);
|
|
120
|
+
const unsubscribeCompositionEnd = subscribeDelegatedListener(
|
|
121
|
+
element,
|
|
122
|
+
"compositionend",
|
|
123
|
+
onInput,
|
|
124
|
+
true
|
|
125
|
+
);
|
|
113
126
|
return () => {
|
|
114
|
-
|
|
115
|
-
|
|
127
|
+
unsubscribeInput();
|
|
128
|
+
unsubscribeCompositionEnd();
|
|
116
129
|
};
|
|
117
130
|
};
|
|
118
131
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/rich-text/event-listeners/input-rules.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { insert, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { preventEventDiscovery } from '../prevent-event-discovery';\nimport {\n\tretrieveSelectedAttribute,\n\tSTART_OF_SELECTED_AREA,\n} from '../../../utils/selection';\n\nexport function findSelection( blocks ) {\n\tlet i = blocks.length;\n\n\twhile ( i-- ) {\n\t\tconst attributeKey = retrieveSelectedAttribute(\n\t\t\tblocks[ i ].attributes\n\t\t);\n\n\t\tif ( attributeKey ) {\n\t\t\tblocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[\n\t\t\t\tattributeKey\n\t\t\t]\n\t\t\t\t// To do: refactor this to use rich text's selection instead, so\n\t\t\t\t// we no longer have to use on this hack inserting a special\n\t\t\t\t// character.\n\t\t\t\t.toString()\n\t\t\t\t.replace( START_OF_SELECTED_AREA, '' );\n\t\t\treturn [ blocks[ i ].clientId, attributeKey, 0, 0 ];\n\t\t}\n\n\t\tconst nestedSelection = findSelection( blocks[ i ].innerBlocks );\n\n\t\tif ( nestedSelection ) {\n\t\t\treturn nestedSelection;\n\t\t}\n\t}\n\n\treturn [];\n}\n\nexport default ( props ) => ( element ) => {\n\tfunction inputRule() {\n\t\tconst { getValue, onReplace, selectionChange, registry } =\n\t\t\tprops.current;\n\n\t\tif ( ! onReplace ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We must use getValue() here because value may be update\n\t\t// asynchronously.\n\t\tconst value = getValue();\n\t\tconst { start, text } = value;\n\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t// The character right before the caret must be a plain space.\n\t\tif ( characterBefore !== ' ' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t( { type } ) => type === 'prefix'\n\t\t);\n\t\tconst transformation = findTransform(\n\t\t\tprefixTransforms,\n\t\t\t( { prefix } ) => {\n\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t}\n\t\t);\n\n\t\tif ( ! transformation ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst content = toHTMLString( {\n\t\t\tvalue: insert( value, START_OF_SELECTED_AREA, 0, start ),\n\t\t} );\n\t\tconst block = transformation.transform( content );\n\n\t\tselectionChange( ...findSelection( [ block ] ) );\n\t\tonReplace( [ block ] );\n\t\tregistry.dispatch( blockEditorStore ).__unstableMarkAutomaticChange();\n\n\t\treturn true;\n\t}\n\n\tfunction onInput( event ) {\n\t\tconst { inputType, type } = event;\n\t\tconst {\n\t\t\tgetValue,\n\t\t\tonChange,\n\t\t\t__unstableAllowPrefixTransformations,\n\t\t\tformatTypes,\n\t\t\tregistry,\n\t\t\tonReplace,\n\t\t} = props.current;\n\n\t\t// Only run input rules when inserting text.\n\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( __unstableAllowPrefixTransformations && inputRule() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst value = getValue();\n\n\t\tconst transforms = getBlockTransforms( 'from' ).filter(\n\t\t\t( transform ) => transform.type === 'input'\n\t\t);\n\t\tconst transformation = findTransform( transforms, ( item ) => {\n\t\t\treturn item.regExp.test( value.text );\n\t\t} );\n\n\t\tif ( transformation ) {\n\t\t\tonReplace( transformation.transform() );\n\t\t\tregistry\n\t\t\t\t.dispatch( blockEditorStore )\n\t\t\t\t.__unstableMarkAutomaticChange();\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformed = formatTypes.reduce(\n\t\t\t( accumulator, { __unstableInputRule } ) => {\n\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\taccumulator = __unstableInputRule( accumulator );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\tpreventEventDiscovery( value )\n\t\t);\n\n\t\tconst {\n\t\t\t__unstableMarkLastChangeAsPersistent,\n\t\t\t__unstableMarkAutomaticChange,\n\t\t} = registry.dispatch( blockEditorStore );\n\n\t\tif ( transformed !== value ) {\n\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\tonChange( {\n\t\t\t\t...transformed,\n\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t} );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\t}\n\n\
|
|
5
|
-
"mappings": ";AAGA,SAAS,QAAQ,oBAAoB;AACrC,SAAS,oBAAoB,qBAAqB;AAKlD,SAAS,SAAS,wBAAwB;AAC1C,SAAS,6BAA6B;AACtC;AAAA,EACC;AAAA,EACA;AAAA,OACM;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { insert, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { privateApis as composePrivateApis } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { preventEventDiscovery } from '../prevent-event-discovery';\nimport {\n\tretrieveSelectedAttribute,\n\tSTART_OF_SELECTED_AREA,\n} from '../../../utils/selection';\nimport { unlock } from '../../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\n\nexport function findSelection( blocks ) {\n\tlet i = blocks.length;\n\n\twhile ( i-- ) {\n\t\tconst attributeKey = retrieveSelectedAttribute(\n\t\t\tblocks[ i ].attributes\n\t\t);\n\n\t\tif ( attributeKey ) {\n\t\t\tblocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[\n\t\t\t\tattributeKey\n\t\t\t]\n\t\t\t\t// To do: refactor this to use rich text's selection instead, so\n\t\t\t\t// we no longer have to use on this hack inserting a special\n\t\t\t\t// character.\n\t\t\t\t.toString()\n\t\t\t\t.replace( START_OF_SELECTED_AREA, '' );\n\t\t\treturn [ blocks[ i ].clientId, attributeKey, 0, 0 ];\n\t\t}\n\n\t\tconst nestedSelection = findSelection( blocks[ i ].innerBlocks );\n\n\t\tif ( nestedSelection ) {\n\t\t\treturn nestedSelection;\n\t\t}\n\t}\n\n\treturn [];\n}\n\nexport default ( props ) => ( element ) => {\n\tfunction inputRule() {\n\t\tconst { getValue, onReplace, selectionChange, registry } =\n\t\t\tprops.current;\n\n\t\tif ( ! onReplace ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We must use getValue() here because value may be update\n\t\t// asynchronously.\n\t\tconst value = getValue();\n\t\tconst { start, text } = value;\n\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t// The character right before the caret must be a plain space.\n\t\tif ( characterBefore !== ' ' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t( { type } ) => type === 'prefix'\n\t\t);\n\t\tconst transformation = findTransform(\n\t\t\tprefixTransforms,\n\t\t\t( { prefix } ) => {\n\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t}\n\t\t);\n\n\t\tif ( ! transformation ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst content = toHTMLString( {\n\t\t\tvalue: insert( value, START_OF_SELECTED_AREA, 0, start ),\n\t\t} );\n\t\tconst block = transformation.transform( content );\n\n\t\tselectionChange( ...findSelection( [ block ] ) );\n\t\tonReplace( [ block ] );\n\t\tregistry.dispatch( blockEditorStore ).__unstableMarkAutomaticChange();\n\n\t\treturn true;\n\t}\n\n\tfunction onInput( event ) {\n\t\tconst { inputType, type } = event;\n\t\tconst {\n\t\t\tgetValue,\n\t\t\tonChange,\n\t\t\t__unstableAllowPrefixTransformations,\n\t\t\tformatTypes,\n\t\t\tregistry,\n\t\t\tonReplace,\n\t\t} = props.current;\n\n\t\t// Only run input rules when inserting text.\n\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( __unstableAllowPrefixTransformations && inputRule() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst value = getValue();\n\n\t\tconst transforms = getBlockTransforms( 'from' ).filter(\n\t\t\t( transform ) => transform.type === 'input'\n\t\t);\n\t\tconst transformation = findTransform( transforms, ( item ) => {\n\t\t\treturn item.regExp.test( value.text );\n\t\t} );\n\n\t\tif ( transformation ) {\n\t\t\tonReplace( transformation.transform() );\n\t\t\tregistry\n\t\t\t\t.dispatch( blockEditorStore )\n\t\t\t\t.__unstableMarkAutomaticChange();\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformed = formatTypes.reduce(\n\t\t\t( accumulator, { __unstableInputRule } ) => {\n\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\taccumulator = __unstableInputRule( accumulator );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\tpreventEventDiscovery( value )\n\t\t);\n\n\t\tconst {\n\t\t\t__unstableMarkLastChangeAsPersistent,\n\t\t\t__unstableMarkAutomaticChange,\n\t\t} = registry.dispatch( blockEditorStore );\n\n\t\tif ( transformed !== value ) {\n\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\tonChange( {\n\t\t\t\t...transformed,\n\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t} );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\t}\n\n\t// Capture phase so these run before ancestor (writing flow) bubble\n\t// handlers, matching the timing of the previous raw element listeners.\n\tconst unsubscribeInput = subscribeDelegatedListener(\n\t\telement,\n\t\t'input',\n\t\tonInput,\n\t\ttrue\n\t);\n\tconst unsubscribeCompositionEnd = subscribeDelegatedListener(\n\t\telement,\n\t\t'compositionend',\n\t\tonInput,\n\t\ttrue\n\t);\n\treturn () => {\n\t\tunsubscribeInput();\n\t\tunsubscribeCompositionEnd();\n\t};\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,QAAQ,oBAAoB;AACrC,SAAS,oBAAoB,qBAAqB;AAClD,SAAS,eAAe,0BAA0B;AAKlD,SAAS,SAAS,wBAAwB;AAC1C,SAAS,6BAA6B;AACtC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc;AAEvB,IAAM,EAAE,2BAA2B,IAAI,OAAQ,kBAAmB;AAE3D,SAAS,cAAe,QAAS;AACvC,MAAI,IAAI,OAAO;AAEf,SAAQ,KAAM;AACb,UAAM,eAAe;AAAA,MACpB,OAAQ,CAAE,EAAE;AAAA,IACb;AAEA,QAAK,cAAe;AACnB,aAAQ,CAAE,EAAE,WAAY,YAAa,IAAI,OAAQ,CAAE,EAAE,WACpD,YACD,EAIE,SAAS,EACT,QAAS,wBAAwB,EAAG;AACtC,aAAO,CAAE,OAAQ,CAAE,EAAE,UAAU,cAAc,GAAG,CAAE;AAAA,IACnD;AAEA,UAAM,kBAAkB,cAAe,OAAQ,CAAE,EAAE,WAAY;AAE/D,QAAK,iBAAkB;AACtB,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO,CAAC;AACT;AAEA,IAAO,sBAAQ,CAAE,UAAW,CAAE,YAAa;AAC1C,WAAS,YAAY;AACpB,UAAM,EAAE,UAAU,WAAW,iBAAiB,SAAS,IACtD,MAAM;AAEP,QAAK,CAAE,WAAY;AAClB;AAAA,IACD;AAIA,UAAM,QAAQ,SAAS;AACvB,UAAM,EAAE,OAAO,KAAK,IAAI;AACxB,UAAM,kBAAkB,KAAK,MAAO,QAAQ,GAAG,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A,IACD;AAEA,UAAM,cAAc,YAAY;AAAA,MAC/B,CAAE,aAAa,EAAE,oBAAoB,MAAO;AAC3C,YAAK,qBAAsB;AAC1B,wBAAc,oBAAqB,WAAY;AAAA,QAChD;AAEA,eAAO;AAAA,MACR;AAAA,MACA,sBAAuB,KAAM;AAAA,IAC9B;AAEA,UAAM;AAAA,MACL;AAAA,MACA;AAAA,IACD,IAAI,SAAS,SAAU,gBAAiB;AAExC,QAAK,gBAAgB,OAAQ;AAC5B,2CAAqC;AACrC,eAAU;AAAA,QACT,GAAG;AAAA,QACH,eAAe,MAAM;AAAA,MACtB,CAAE;AACF,oCAA8B;AAAA,IAC/B;AAAA,EACD;AAIA,QAAM,mBAAmB;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,QAAM,4BAA4B;AAAA,IACjC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SAAO,MAAM;AACZ,qBAAiB;AACjB,8BAA0B;AAAA,EAC3B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// packages/block-editor/src/components/rich-text/event-listeners/insert-replacement-text.js
|
|
2
|
+
import { privateApis as composePrivateApis } from "@wordpress/compose";
|
|
2
3
|
import { store as blockEditorStore } from "../../../store/index.mjs";
|
|
4
|
+
import { unlock } from "../../../lock-unlock.mjs";
|
|
5
|
+
var { subscribeDelegatedListener } = unlock(composePrivateApis);
|
|
3
6
|
var insert_replacement_text_default = (props) => (element) => {
|
|
4
7
|
function onInput(event) {
|
|
5
8
|
if (event.inputType !== "insertReplacementText") {
|
|
@@ -8,10 +11,7 @@ var insert_replacement_text_default = (props) => (element) => {
|
|
|
8
11
|
const { registry } = props.current;
|
|
9
12
|
registry.dispatch(blockEditorStore).__unstableMarkLastChangeAsPersistent();
|
|
10
13
|
}
|
|
11
|
-
element
|
|
12
|
-
return () => {
|
|
13
|
-
element.removeEventListener("beforeinput", onInput);
|
|
14
|
-
};
|
|
14
|
+
return subscribeDelegatedListener(element, "beforeinput", onInput);
|
|
15
15
|
};
|
|
16
16
|
export {
|
|
17
17
|
insert_replacement_text_default as default
|