@wordpress/block-editor 16.2.0 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/build/components/block-inspector/index.cjs +9 -6
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-keyboard-shortcuts/index.cjs +201 -0
- package/build/components/block-keyboard-shortcuts/index.cjs.map +7 -0
- package/build/components/block-list/block.cjs +10 -3
- package/build/components/block-list/block.cjs.map +2 -2
- package/build/components/block-list/index.cjs +6 -1
- package/build/components/block-list/index.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-focus-first-element.cjs +4 -0
- package/build/components/block-list/use-block-props/use-focus-first-element.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs +6 -7
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs.map +2 -2
- package/build/components/block-parent-selector/index.cjs +98 -29
- package/build/components/block-parent-selector/index.cjs.map +3 -3
- package/build/components/block-popover/inbetween.cjs +2 -2
- package/build/components/block-popover/inbetween.cjs.map +2 -2
- package/build/components/block-preview/index.cjs +0 -4
- package/build/components/block-preview/index.cjs.map +2 -2
- package/build/components/block-styles/index.cjs +77 -33
- package/build/components/block-styles/index.cjs.map +3 -3
- package/build/components/block-visibility/constants.cjs.map +2 -2
- package/build/components/child-layout-control/index.cjs.map +2 -2
- package/build/components/colors/with-colors.cjs +55 -71
- package/build/components/colors/with-colors.cjs.map +2 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs +4 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +2 -2
- package/build/components/dimensions-tool/index.cjs +18 -16
- package/build/components/dimensions-tool/index.cjs.map +2 -2
- package/build/components/dimensions-tool/utils.cjs +61 -0
- package/build/components/dimensions-tool/utils.cjs.map +7 -0
- package/build/components/duotone-control/index.cjs +2 -0
- package/build/components/duotone-control/index.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs.map +3 -3
- package/build/components/global-styles/border-panel.cjs +2 -5
- package/build/components/global-styles/border-panel.cjs.map +2 -2
- package/build/components/global-styles/color-panel.cjs +14 -2
- package/build/components/global-styles/color-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +9 -5
- package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
- package/build/components/global-styles/filters-panel.cjs +12 -8
- package/build/components/global-styles/filters-panel.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs +16 -11
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/global-styles/utils.cjs +9 -0
- package/build/components/global-styles/utils.cjs.map +2 -2
- package/build/components/inner-blocks/index.cjs +5 -3
- package/build/components/inner-blocks/index.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/index.cjs +39 -22
- package/build/components/inserter/block-patterns-explorer/index.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs +21 -55
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/pattern-list.cjs +19 -44
- package/build/components/inserter/block-patterns-explorer/pattern-list.cjs.map +3 -3
- package/build/components/inserter/hooks/use-insertion-point.cjs +4 -4
- package/build/components/inserter/hooks/use-insertion-point.cjs.map +2 -2
- package/build/components/inserter/menu.cjs +18 -7
- package/build/components/inserter/menu.cjs.map +2 -2
- package/build/components/inserter/quick-inserter.cjs +30 -27
- package/build/components/inserter/quick-inserter.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/list-view/index.cjs +31 -5
- package/build/components/list-view/index.cjs.map +3 -3
- package/build/components/list-view/utils.cjs +13 -1
- package/build/components/list-view/utils.cjs.map +2 -2
- package/build/components/media-placeholder/index.cjs +1 -1
- package/build/components/media-placeholder/index.cjs.map +3 -3
- package/build/components/provider/index.cjs +5 -1
- package/build/components/provider/index.cjs.map +3 -3
- package/build/components/publish-date-time-picker/index.cjs +3 -2
- package/build/components/publish-date-time-picker/index.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/enter.cjs +46 -39
- package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
- package/build/components/rich-text/index.cjs +7 -5
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/rich-text/multiline.cjs +105 -70
- package/build/components/rich-text/multiline.cjs.map +3 -3
- package/build/components/url-input/index.cjs.map +2 -2
- package/build/components/writing-flow/use-input.cjs +65 -13
- package/build/components/writing-flow/use-input.cjs.map +3 -3
- package/build/hooks/border.cjs +25 -3
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +9 -2
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/duotone.cjs +4 -3
- package/build/hooks/duotone.cjs.map +2 -2
- package/build/hooks/gap.cjs +8 -2
- package/build/hooks/gap.cjs.map +2 -2
- package/build/hooks/layout-child.cjs +35 -13
- package/build/hooks/layout-child.cjs.map +2 -2
- package/build/hooks/layout.cjs +23 -1
- package/build/hooks/layout.cjs.map +2 -2
- package/build/hooks/states.cjs +7 -4
- package/build/hooks/states.cjs.map +2 -2
- package/build/layouts/constrained.cjs +8 -1
- package/build/layouts/constrained.cjs.map +2 -2
- package/build/layouts/flex.cjs +9 -0
- package/build/layouts/flex.cjs.map +2 -2
- package/build/layouts/flow.cjs +4 -1
- package/build/layouts/flow.cjs.map +2 -2
- package/build/layouts/grid.cjs +5 -1
- package/build/layouts/grid.cjs.map +2 -2
- package/build/private-apis.cjs +3 -1
- package/build/private-apis.cjs.map +2 -2
- package/build/store/actions.cjs +1 -1
- package/build/store/actions.cjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +9 -6
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-keyboard-shortcuts/index.mjs +173 -0
- package/build-module/components/block-keyboard-shortcuts/index.mjs.map +7 -0
- package/build-module/components/block-list/block.mjs +10 -3
- package/build-module/components/block-list/block.mjs.map +2 -2
- package/build-module/components/block-list/index.mjs +6 -1
- package/build-module/components/block-list/index.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs +4 -0
- package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs +6 -7
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs.map +2 -2
- package/build-module/components/block-parent-selector/index.mjs +101 -32
- package/build-module/components/block-parent-selector/index.mjs.map +2 -2
- package/build-module/components/block-popover/inbetween.mjs +2 -2
- package/build-module/components/block-popover/inbetween.mjs.map +2 -2
- package/build-module/components/block-preview/index.mjs +0 -4
- package/build-module/components/block-preview/index.mjs.map +2 -2
- package/build-module/components/block-styles/index.mjs +79 -35
- package/build-module/components/block-styles/index.mjs.map +2 -2
- package/build-module/components/block-visibility/constants.mjs.map +2 -2
- package/build-module/components/child-layout-control/index.mjs +5 -5
- package/build-module/components/child-layout-control/index.mjs.map +1 -1
- package/build-module/components/colors/with-colors.mjs +56 -72
- package/build-module/components/colors/with-colors.mjs.map +2 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +4 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
- package/build-module/components/dimensions-tool/index.mjs +19 -17
- package/build-module/components/dimensions-tool/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/utils.mjs +35 -0
- package/build-module/components/dimensions-tool/utils.mjs.map +7 -0
- package/build-module/components/duotone-control/index.mjs +2 -0
- package/build-module/components/duotone-control/index.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +5 -2
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/border-panel.mjs +2 -5
- package/build-module/components/global-styles/border-panel.mjs.map +2 -2
- package/build-module/components/global-styles/color-panel.mjs +14 -2
- package/build-module/components/global-styles/color-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +9 -5
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/filters-panel.mjs +16 -9
- package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs +16 -11
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/global-styles/utils.mjs +8 -0
- package/build-module/components/global-styles/utils.mjs.map +2 -2
- package/build-module/components/inner-blocks/index.mjs +5 -3
- package/build-module/components/inner-blocks/index.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/index.mjs +39 -22
- package/build-module/components/inserter/block-patterns-explorer/index.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs +22 -56
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs +20 -45
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs.map +2 -2
- package/build-module/components/inserter/hooks/use-insertion-point.mjs +4 -4
- package/build-module/components/inserter/hooks/use-insertion-point.mjs.map +2 -2
- package/build-module/components/inserter/menu.mjs +19 -8
- package/build-module/components/inserter/menu.mjs.map +2 -2
- package/build-module/components/inserter/quick-inserter.mjs +30 -27
- package/build-module/components/inserter/quick-inserter.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/list-view/index.mjs +32 -5
- package/build-module/components/list-view/index.mjs.map +3 -3
- package/build-module/components/list-view/utils.mjs +13 -1
- package/build-module/components/list-view/utils.mjs.map +2 -2
- package/build-module/components/media-placeholder/index.mjs +3 -3
- package/build-module/components/media-placeholder/index.mjs.map +2 -2
- package/build-module/components/provider/index.mjs +6 -2
- package/build-module/components/provider/index.mjs.map +2 -2
- package/build-module/components/publish-date-time-picker/index.mjs +3 -2
- package/build-module/components/publish-date-time-picker/index.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs +46 -39
- package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +7 -5
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/rich-text/multiline.mjs +112 -72
- package/build-module/components/rich-text/multiline.mjs.map +2 -2
- package/build-module/components/url-input/index.mjs +2 -2
- package/build-module/components/url-input/index.mjs.map +1 -1
- package/build-module/components/writing-flow/use-input.mjs +66 -14
- package/build-module/components/writing-flow/use-input.mjs.map +3 -3
- package/build-module/hooks/border.mjs +26 -8
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +9 -2
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/duotone.mjs +8 -4
- package/build-module/hooks/duotone.mjs.map +2 -2
- package/build-module/hooks/gap.mjs +6 -1
- package/build-module/hooks/gap.mjs.map +2 -2
- package/build-module/hooks/layout-child.mjs +36 -13
- package/build-module/hooks/layout-child.mjs.map +2 -2
- package/build-module/hooks/layout.mjs +22 -1
- package/build-module/hooks/layout.mjs.map +2 -2
- package/build-module/hooks/states.mjs +8 -5
- package/build-module/hooks/states.mjs.map +2 -2
- package/build-module/layouts/constrained.mjs +8 -1
- package/build-module/layouts/constrained.mjs.map +2 -2
- package/build-module/layouts/flex.mjs +9 -0
- package/build-module/layouts/flex.mjs.map +2 -2
- package/build-module/layouts/flow.mjs +4 -1
- package/build-module/layouts/flow.mjs.map +2 -2
- package/build-module/layouts/grid.mjs +5 -1
- package/build-module/layouts/grid.mjs.map +2 -2
- package/build-module/private-apis.mjs +3 -1
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/actions.mjs +1 -1
- package/build-module/store/actions.mjs.map +2 -2
- package/build-style/style-rtl.css +108 -71
- package/build-style/style.css +108 -71
- package/build-types/components/block-visibility/constants.d.ts +4 -3
- package/build-types/components/block-visibility/constants.d.ts.map +1 -1
- package/package.json +43 -43
- package/src/components/background-image-control/README.md +122 -0
- package/src/components/block-edit-visually-button/README.md +39 -0
- package/src/components/block-editing-mode/README.md +72 -0
- package/src/components/block-inspector/index.js +6 -6
- package/src/components/block-keyboard-shortcuts/index.js +256 -0
- package/src/components/block-list/block.js +7 -0
- package/src/components/block-list/index.js +7 -1
- package/src/components/block-list/use-block-props/use-focus-first-element.js +5 -0
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +6 -8
- package/src/components/block-parent-selector/index.js +111 -30
- package/src/components/block-popover/README.md +10 -3
- package/src/components/block-popover/inbetween.js +8 -2
- package/src/components/block-popover/stories/index.story.jsx +143 -0
- package/src/components/block-preview/index.js +0 -2
- package/src/components/block-styles/index.js +95 -43
- package/src/components/block-styles/style.scss +5 -34
- package/src/components/block-tools/style.scss +94 -0
- package/src/components/block-visibility/constants.ts +4 -3
- package/src/components/child-layout-control/index.js +5 -5
- package/src/components/color-palette/test/__snapshots__/control.js.snap +3 -29
- package/src/components/colors/test/with-colors.js +6 -7
- package/src/components/colors/with-colors.js +79 -105
- package/src/components/dimensions-tool/aspect-ratio-tool.js +16 -4
- package/src/components/dimensions-tool/index.js +34 -22
- package/src/components/dimensions-tool/test/index.js +166 -2
- package/src/components/dimensions-tool/test/utils.js +51 -0
- package/src/components/dimensions-tool/utils.js +67 -0
- package/src/components/duotone-control/index.js +2 -0
- package/src/components/duotone-control/test/index.js +100 -0
- package/src/components/global-styles/advanced-panel.js +5 -2
- package/src/components/global-styles/border-panel.js +11 -9
- package/src/components/global-styles/color-panel.js +13 -1
- package/src/components/global-styles/dimensions-panel.js +17 -5
- package/src/components/global-styles/filters-panel.js +24 -10
- package/src/components/global-styles/shadow-panel-components.js +38 -11
- package/src/components/global-styles/test/border-panel.js +230 -0
- package/src/components/global-styles/test/color-panel.js +24 -0
- package/src/components/global-styles/test/dimensions-panel.js +98 -7
- package/src/components/global-styles/test/filters-panel.js +84 -0
- package/src/components/global-styles/test/utils.js +30 -0
- package/src/components/global-styles/utils.js +23 -0
- package/src/components/inner-blocks/index.js +11 -2
- package/src/components/inner-blocks/stories/index.story.jsx +246 -0
- package/src/components/inserter/block-patterns-explorer/index.js +24 -11
- package/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +18 -56
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +22 -47
- package/src/components/inserter/hooks/use-insertion-point.js +9 -4
- package/src/components/inserter/menu.js +23 -10
- package/src/components/inserter/quick-inserter.js +15 -13
- package/src/components/inserter/style.scss +44 -62
- package/src/components/inspector-controls-tabs/README.md +92 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -1
- package/src/components/link-control/test/index.js +5 -0
- package/src/components/list-view/index.js +50 -7
- package/src/components/list-view/utils.js +16 -1
- package/src/components/media-placeholder/index.js +9 -4
- package/src/components/plain-text/stories/index.story.jsx +3 -0
- package/src/components/provider/index.js +7 -1
- package/src/components/publish-date-time-picker/README.md +10 -0
- package/src/components/publish-date-time-picker/index.js +17 -14
- package/src/components/rich-text/event-listeners/enter.js +58 -45
- package/src/components/rich-text/index.js +9 -4
- package/src/components/rich-text/multiline.js +126 -86
- package/src/components/url-input/index.js +2 -2
- package/src/components/url-input/test/fixtures/validated-input-control-deprecation.js +27 -0
- package/src/components/url-input/test/index.js +5 -0
- package/src/components/url-popover/README.md +7 -0
- package/src/components/url-popover/stories/index.story.jsx +133 -47
- package/src/components/writing-flow/use-input.js +105 -15
- package/src/hooks/border.js +27 -8
- package/src/hooks/dimensions.js +8 -1
- package/src/hooks/duotone.js +23 -7
- package/src/hooks/gap.js +16 -0
- package/src/hooks/layout-child.js +41 -9
- package/src/hooks/layout.js +117 -71
- package/src/hooks/states.js +8 -5
- package/src/hooks/test/gap.js +31 -1
- package/src/hooks/test/layout-child.js +60 -1
- package/src/hooks/test/layout.js +27 -0
- package/src/layouts/constrained.js +9 -1
- package/src/layouts/flex.js +15 -0
- package/src/layouts/flow.js +4 -1
- package/src/layouts/grid.js +9 -1
- package/src/layouts/test/constrained.js +26 -0
- package/src/layouts/test/flow.js +26 -0
- package/src/layouts/test/grid.js +46 -0
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +14 -1
- package/build/components/floating-toolbar/nav-up-icon.cjs +0 -52
- package/build/components/floating-toolbar/nav-up-icon.cjs.map +0 -7
- package/build/components/gradients/with-gradient.cjs +0 -36
- package/build/components/gradients/with-gradient.cjs.map +0 -7
- package/build/components/inserter-button/sparkles.cjs +0 -36
- package/build/components/inserter-button/sparkles.cjs.map +0 -7
- package/build-module/components/floating-toolbar/nav-up-icon.mjs +0 -31
- package/build-module/components/floating-toolbar/nav-up-icon.mjs.map +0 -7
- package/build-module/components/gradients/with-gradient.mjs +0 -11
- package/build-module/components/gradients/with-gradient.mjs.map +0 -7
- package/build-module/components/inserter-button/sparkles.mjs +0 -15
- package/build-module/components/inserter-button/sparkles.mjs.map +0 -7
- package/build-style/default-editor-styles-rtl.css +0 -68
- package/build-style/default-editor-styles.css +0 -68
- package/src/components/floating-toolbar/nav-up-icon.js +0 -22
- package/src/components/gradients/with-gradient.js +0 -9
- package/src/components/inserter-button/README.md +0 -62
- package/src/components/inserter-button/sparkles.js +0 -12
- package/src/default-editor-styles.scss +0 -25
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-list/index.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tAsyncModeProvider,\n\tuseSelect,\n\tuseDispatch,\n\tuseRegistry,\n} from '@wordpress/data';\nimport { useMergeRefs, useDebounce } from '@wordpress/compose';\nimport {\n\tcreateContext,\n\tuseEffect,\n\tuseMemo,\n\tuseCallback,\n} from '@wordpress/element';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport BlockListBlock from './block';\nimport BlockListAppender from '../block-list-appender';\nimport { useInBetweenInserter } from './use-in-between-inserter';\nimport { store as blockEditorStore } from '../../store';\nimport { LayoutProvider, defaultLayout } from './layout';\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useInnerBlocksProps } from '../inner-blocks';\nimport {\n\tBlockEditContextProvider,\n\tDEFAULT_BLOCK_EDIT_CONTEXT,\n} from '../block-edit/context';\nimport { ZoomOutSeparator } from './zoom-out-separator';\nimport { unlock } from '../../lock-unlock';\n\nexport const IntersectionObserver = createContext();\nIntersectionObserver.displayName = 'IntersectionObserverContext';\n\nconst pendingBlockVisibilityUpdatesPerRegistry = new WeakMap();\nconst delayedBlockVisibilityDebounceOptions = {\n\ttrailing: true,\n};\n\nfunction Root( { className, ...settings } ) {\n\tconst {\n\t\tisOutlineMode,\n\t\tisFocusMode,\n\t\tisPreviewMode,\n\t\teditedContentOnlySection,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetSettings,\n\t\t\tisTyping,\n\t\t\thasBlockSpotlight,\n\t\t\tgetEditedContentOnlySection,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst {\n\t\t\toutlineMode,\n\t\t\tfocusMode,\n\t\t\tisPreviewMode: _isPreviewMode,\n\t\t} = getSettings();\n\t\treturn {\n\t\t\tisOutlineMode: outlineMode && ! isTyping(),\n\t\t\tisFocusMode: focusMode || hasBlockSpotlight(),\n\t\t\tisPreviewMode: _isPreviewMode,\n\t\t\teditedContentOnlySection: getEditedContentOnlySection(),\n\t\t};\n\t}, [] );\n\tconst registry = useRegistry();\n\tconst { setBlockVisibility } = useDispatch( blockEditorStore );\n\n\tconst delayedBlockVisibilityUpdates = useDebounce(\n\t\tuseCallback( () => {\n\t\t\tconst updates = {};\n\t\t\tpendingBlockVisibilityUpdatesPerRegistry\n\t\t\t\t.get( registry )\n\t\t\t\t.forEach( ( [ id, isIntersecting ] ) => {\n\t\t\t\t\tupdates[ id ] = isIntersecting;\n\t\t\t\t} );\n\t\t\tsetBlockVisibility( updates );\n\t\t}, [ registry ] ),\n\t\t300,\n\t\tdelayedBlockVisibilityDebounceOptions\n\t);\n\tconst intersectionObserver = useMemo( () => {\n\t\tconst { IntersectionObserver: Observer } = window;\n\n\t\tif ( ! Observer ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn new Observer( ( entries ) => {\n\t\t\tif ( ! pendingBlockVisibilityUpdatesPerRegistry.get( registry ) ) {\n\t\t\t\tpendingBlockVisibilityUpdatesPerRegistry.set( registry, [] );\n\t\t\t}\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst clientId = entry.target.getAttribute( 'data-block' );\n\t\t\t\tpendingBlockVisibilityUpdatesPerRegistry\n\t\t\t\t\t.get( registry )\n\t\t\t\t\t.push( [ clientId, entry.isIntersecting ] );\n\t\t\t}\n\t\t\tdelayedBlockVisibilityUpdates();\n\t\t} );\n\t}, [] );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\tref: useMergeRefs( [\n\t\t\t\tuseBlockSelectionClearer(),\n\t\t\t\tuseInBetweenInserter(),\n\t\t\t] ),\n\t\t\tclassName: clsx( 'is-root-container', className, {\n\t\t\t\t'is-outline-mode': isOutlineMode,\n\t\t\t\t'is-focus-mode': isFocusMode,\n\t\t\t\t'is-preview-mode': isPreviewMode,\n\t\t\t} ),\n\t\t},\n\t\tsettings\n\t);\n\treturn (\n\t\t<IntersectionObserver.Provider value={ intersectionObserver }>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t\t{ !! editedContentOnlySection && (\n\t\t\t\t<StopEditingContentOnlySectionOnOutsideSelect\n\t\t\t\t\tclientId={ editedContentOnlySection }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</IntersectionObserver.Provider>\n\t);\n}\n\nfunction StopEditingContentOnlySectionOnOutsideSelect( { clientId } ) {\n\tconst { stopEditingContentOnlySection } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tconst isBlockOrDescendantSelected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tisBlockSelected,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockSelectionStart,\n\t\t\t} = select( blockEditorStore );\n\t\t\treturn (\n\t\t\t\t! getBlockSelectionStart() ||\n\t\t\t\tisBlockSelected( clientId ) ||\n\t\t\t\thasSelectedInnerBlock( clientId, true )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( ! isBlockOrDescendantSelected ) {\n\t\t\tstopEditingContentOnlySection();\n\t\t}\n\t}, [ isBlockOrDescendantSelected, stopEditingContentOnlySection ] );\n\n\treturn null;\n}\n\nexport default function BlockList( settings ) {\n\treturn (\n\t\t<BlockEditContextProvider value={ DEFAULT_BLOCK_EDIT_CONTEXT }>\n\t\t\t<Root { ...settings } />\n\t\t</BlockEditContextProvider>\n\t);\n}\n\nconst EMPTY_ARRAY = [];\nconst EMPTY_SET = new Set();\n\nfunction Items( {\n\tplaceholder,\n\trootClientId,\n\trenderAppender: CustomAppender,\n\t__experimentalAppenderTagName,\n\tlayout = defaultLayout,\n} ) {\n\t// Avoid passing CustomAppender to useSelect because it could be a new\n\t// function on every render.\n\tconst hasAppender = CustomAppender !== false;\n\tconst hasCustomAppender = !! CustomAppender;\n\tconst {\n\t\torder,\n\t\tisZoomOut,\n\t\tselectedBlocks,\n\t\tvisibleBlocks,\n\t\tghostBlockName,\n\t\tghostBlockAttributes,\n\t\tshouldRenderAppender,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetSettings,\n\t\t\t\tgetBlockOrder,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t__unstableGetVisibleBlocks,\n\t\t\t\tgetTemplateLock,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t\tisSectionBlock,\n\t\t\t\tisContainerInsertableToInContentOnlyMode,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tisZoomOut: _isZoomOut,\n\t\t\t\tcanInsertBlockType,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\n\t\t\tconst _order = getBlockOrder( rootClientId );\n\n\t\t\tif ( getSettings().isPreviewMode ) {\n\t\t\t\treturn {\n\t\t\t\t\torder: _order,\n\t\t\t\t\tselectedBlocks: EMPTY_ARRAY,\n\t\t\t\t\tvisibleBlocks: EMPTY_SET,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// A block list without a custom appender renders a ghost of\n\t\t\t// the container's default block while empty: a real block\n\t\t\t// object rendered before it exists in the store, inserted on\n\t\t\t// entry.\n\t\t\tlet _ghostBlockName;\n\t\t\tlet _ghostBlockAttributes;\n\t\t\tif ( hasAppender && ! hasCustomAppender && ! _order.length ) {\n\t\t\t\tconst defaultBlock = ( rootClientId\n\t\t\t\t\t? getBlockListSettings( rootClientId )?.defaultBlock\n\t\t\t\t\t: undefined ) ?? { name: getDefaultBlockName() };\n\t\t\t\tif (\n\t\t\t\t\tdefaultBlock.name &&\n\t\t\t\t\tcanInsertBlockType( defaultBlock.name, rootClientId )\n\t\t\t\t) {\n\t\t\t\t\t_ghostBlockName = defaultBlock.name;\n\t\t\t\t\t_ghostBlockAttributes = defaultBlock.attributes;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\t\tconst selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\t\tconst showRootAppender =\n\t\t\t\t! rootClientId &&\n\t\t\t\t! selectedBlockClientId &&\n\t\t\t\t( ! _order.length ||\n\t\t\t\t\t! canInsertBlockType(\n\t\t\t\t\t\tgetDefaultBlockName(),\n\t\t\t\t\t\trootClientId\n\t\t\t\t\t) );\n\t\t\tconst hasSelectedRoot = !! (\n\t\t\t\trootClientId &&\n\t\t\t\tselectedBlockClientId &&\n\t\t\t\trootClientId === selectedBlockClientId\n\t\t\t);\n\n\t\t\tconst templateLock = getTemplateLock( rootClientId );\n\n\t\t\tconst appenderAllowed =\n\t\t\t\t( ! isSectionBlock( rootClientId ) ||\n\t\t\t\t\tisContainerInsertableToInContentOnlyMode(\n\t\t\t\t\t\tgetBlockName( selectedBlockClientId ),\n\t\t\t\t\t\trootClientId\n\t\t\t\t\t) ) &&\n\t\t\t\tgetBlockEditingMode( rootClientId ) !== 'disabled' &&\n\t\t\t\t( ! templateLock || templateLock === 'contentOnly' ) &&\n\t\t\t\thasAppender &&\n\t\t\t\t! _isZoomOut();\n\n\t\t\treturn {\n\t\t\t\torder: _order,\n\t\t\t\tselectedBlocks: selectedBlockClientIds,\n\t\t\t\tvisibleBlocks: __unstableGetVisibleBlocks(),\n\t\t\t\tisZoomOut: _isZoomOut(),\n\t\t\t\t// The ghost is the block list's empty state: it renders\n\t\t\t\t// whether or not the block is selected.\n\t\t\t\tghostBlockName: appenderAllowed ? _ghostBlockName : undefined,\n\t\t\t\tghostBlockAttributes: _ghostBlockAttributes,\n\t\t\t\tshouldRenderAppender:\n\t\t\t\t\tappenderAllowed &&\n\t\t\t\t\t( hasCustomAppender ||\n\t\t\t\t\t\thasSelectedRoot ||\n\t\t\t\t\t\tshowRootAppender ),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId, hasAppender, hasCustomAppender ]\n\t);\n\n\t// One ghost per empty period: regenerated when the list empties again\n\t// or the default block changes, stable in between so the client ID,\n\t// and with it the DOM, survives materialization.\n\tconst ghostBlock = useMemo(\n\t\t() =>\n\t\t\tghostBlockName\n\t\t\t\t? createBlock( ghostBlockName, ghostBlockAttributes )\n\t\t\t\t: null,\n\t\t[ ghostBlockName, ghostBlockAttributes ]\n\t);\n\tconst showGhost = !! ghostBlock;\n\n\tconst items = showGhost ? [ ...order, ghostBlock.clientId ] : order;\n\n\treturn (\n\t\t<LayoutProvider value={ layout }>\n\t\t\t{ items.map( ( clientId ) => (\n\t\t\t\t<AsyncModeProvider\n\t\t\t\t\tkey={ clientId }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\t// Only provide data asynchronously if the block is\n\t\t\t\t\t\t// not visible, not selected, and not the ghost.\n\t\t\t\t\t\tclientId !== ghostBlock?.clientId &&\n\t\t\t\t\t\t! visibleBlocks.has( clientId ) &&\n\t\t\t\t\t\t! selectedBlocks.includes( clientId )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ isZoomOut && (\n\t\t\t\t\t\t<ZoomOutSeparator\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tposition=\"top\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<BlockListBlock\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tghostBlock={\n\t\t\t\t\t\t\tclientId === ghostBlock?.clientId\n\t\t\t\t\t\t\t\t? ghostBlock\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t{ isZoomOut && (\n\t\t\t\t\t\t<ZoomOutSeparator\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tposition=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</AsyncModeProvider>\n\t\t\t) ) }\n\t\t\t{ order.length < 1 && placeholder }\n\t\t\t{ shouldRenderAppender && ! showGhost && (\n\t\t\t\t<BlockListAppender\n\t\t\t\t\ttagName={ __experimentalAppenderTagName }\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\tCustomAppender={ CustomAppender }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</LayoutProvider>\n\t);\n}\n\nexport function BlockListItems( props ) {\n\t// This component needs to always be synchronous as it's the one changing\n\t// the async mode depending on the block selection.\n\treturn (\n\t\t<AsyncModeProvider value={ false }>\n\t\t\t<Items { ...props } />\n\t\t</AsyncModeProvider>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAAU;AACjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,mBAAmB;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,2BAA2B;AACjD,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,gBAAgB,qBAAqB;AAC9C,SAAS,gCAAgC;AACzC,SAAS,2BAA2B;AACpC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB;AACjC,SAAS,cAAc;
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tAsyncModeProvider,\n\tuseSelect,\n\tuseDispatch,\n\tuseRegistry,\n} from '@wordpress/data';\nimport { useMergeRefs, useDebounce } from '@wordpress/compose';\nimport {\n\tcreateContext,\n\tuseEffect,\n\tuseMemo,\n\tuseCallback,\n} from '@wordpress/element';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport BlockListBlock from './block';\nimport BlockListAppender from '../block-list-appender';\nimport { useInBetweenInserter } from './use-in-between-inserter';\nimport { store as blockEditorStore } from '../../store';\nimport { LayoutProvider, defaultLayout } from './layout';\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useInnerBlocksProps } from '../inner-blocks';\nimport {\n\tBlockEditContextProvider,\n\tDEFAULT_BLOCK_EDIT_CONTEXT,\n} from '../block-edit/context';\nimport { ZoomOutSeparator } from './zoom-out-separator';\nimport { unlock } from '../../lock-unlock';\n\nexport const IntersectionObserver = createContext();\nIntersectionObserver.displayName = 'IntersectionObserverContext';\n\nconst pendingBlockVisibilityUpdatesPerRegistry = new WeakMap();\nconst delayedBlockVisibilityDebounceOptions = {\n\ttrailing: true,\n};\n\nfunction Root( { className, ...settings } ) {\n\tconst {\n\t\tisOutlineMode,\n\t\tisFocusMode,\n\t\tisPreviewMode,\n\t\teditedContentOnlySection,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetSettings,\n\t\t\tisTyping,\n\t\t\thasBlockSpotlight,\n\t\t\tgetEditedContentOnlySection,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst {\n\t\t\toutlineMode,\n\t\t\tfocusMode,\n\t\t\tisPreviewMode: _isPreviewMode,\n\t\t} = getSettings();\n\t\treturn {\n\t\t\tisOutlineMode: outlineMode && ! isTyping(),\n\t\t\t/*\n\t\t\t * Spotlight fades everything but the block being worked on, which\n\t\t\t * has nothing to offer a canvas that cannot be edited — a preview\n\t\t\t * would just render most of its content faded out.\n\t\t\t */\n\t\t\tisFocusMode:\n\t\t\t\t! _isPreviewMode && ( focusMode || hasBlockSpotlight() ),\n\t\t\tisPreviewMode: _isPreviewMode,\n\t\t\teditedContentOnlySection: getEditedContentOnlySection(),\n\t\t};\n\t}, [] );\n\tconst registry = useRegistry();\n\tconst { setBlockVisibility } = useDispatch( blockEditorStore );\n\n\tconst delayedBlockVisibilityUpdates = useDebounce(\n\t\tuseCallback( () => {\n\t\t\tconst updates = {};\n\t\t\tpendingBlockVisibilityUpdatesPerRegistry\n\t\t\t\t.get( registry )\n\t\t\t\t.forEach( ( [ id, isIntersecting ] ) => {\n\t\t\t\t\tupdates[ id ] = isIntersecting;\n\t\t\t\t} );\n\t\t\tsetBlockVisibility( updates );\n\t\t}, [ registry ] ),\n\t\t300,\n\t\tdelayedBlockVisibilityDebounceOptions\n\t);\n\tconst intersectionObserver = useMemo( () => {\n\t\tconst { IntersectionObserver: Observer } = window;\n\n\t\tif ( ! Observer ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn new Observer( ( entries ) => {\n\t\t\tif ( ! pendingBlockVisibilityUpdatesPerRegistry.get( registry ) ) {\n\t\t\t\tpendingBlockVisibilityUpdatesPerRegistry.set( registry, [] );\n\t\t\t}\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst clientId = entry.target.getAttribute( 'data-block' );\n\t\t\t\tpendingBlockVisibilityUpdatesPerRegistry\n\t\t\t\t\t.get( registry )\n\t\t\t\t\t.push( [ clientId, entry.isIntersecting ] );\n\t\t\t}\n\t\t\tdelayedBlockVisibilityUpdates();\n\t\t} );\n\t}, [] );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\tref: useMergeRefs( [\n\t\t\t\tuseBlockSelectionClearer(),\n\t\t\t\tuseInBetweenInserter(),\n\t\t\t] ),\n\t\t\tclassName: clsx( 'is-root-container', className, {\n\t\t\t\t'is-outline-mode': isOutlineMode,\n\t\t\t\t'is-focus-mode': isFocusMode,\n\t\t\t\t'is-preview-mode': isPreviewMode,\n\t\t\t} ),\n\t\t},\n\t\tsettings\n\t);\n\treturn (\n\t\t<IntersectionObserver.Provider value={ intersectionObserver }>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t\t{ !! editedContentOnlySection && (\n\t\t\t\t<StopEditingContentOnlySectionOnOutsideSelect\n\t\t\t\t\tclientId={ editedContentOnlySection }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</IntersectionObserver.Provider>\n\t);\n}\n\nfunction StopEditingContentOnlySectionOnOutsideSelect( { clientId } ) {\n\tconst { stopEditingContentOnlySection } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tconst isBlockOrDescendantSelected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tisBlockSelected,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockSelectionStart,\n\t\t\t} = select( blockEditorStore );\n\t\t\treturn (\n\t\t\t\t! getBlockSelectionStart() ||\n\t\t\t\tisBlockSelected( clientId ) ||\n\t\t\t\thasSelectedInnerBlock( clientId, true )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( ! isBlockOrDescendantSelected ) {\n\t\t\tstopEditingContentOnlySection();\n\t\t}\n\t}, [ isBlockOrDescendantSelected, stopEditingContentOnlySection ] );\n\n\treturn null;\n}\n\nexport default function BlockList( settings ) {\n\treturn (\n\t\t<BlockEditContextProvider value={ DEFAULT_BLOCK_EDIT_CONTEXT }>\n\t\t\t<Root { ...settings } />\n\t\t</BlockEditContextProvider>\n\t);\n}\n\nconst EMPTY_ARRAY = [];\nconst EMPTY_SET = new Set();\n\nfunction Items( {\n\tplaceholder,\n\trootClientId,\n\trenderAppender: CustomAppender,\n\t__experimentalAppenderTagName,\n\tlayout = defaultLayout,\n} ) {\n\t// Avoid passing CustomAppender to useSelect because it could be a new\n\t// function on every render.\n\tconst hasAppender = CustomAppender !== false;\n\tconst hasCustomAppender = !! CustomAppender;\n\tconst {\n\t\torder,\n\t\tisZoomOut,\n\t\tselectedBlocks,\n\t\tvisibleBlocks,\n\t\tghostBlockName,\n\t\tghostBlockAttributes,\n\t\tshouldRenderAppender,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetSettings,\n\t\t\t\tgetBlockOrder,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t__unstableGetVisibleBlocks,\n\t\t\t\tgetTemplateLock,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t\tisSectionBlock,\n\t\t\t\tisContainerInsertableToInContentOnlyMode,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tisZoomOut: _isZoomOut,\n\t\t\t\tcanInsertBlockType,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\n\t\t\tconst _order = getBlockOrder( rootClientId );\n\n\t\t\tif ( getSettings().isPreviewMode ) {\n\t\t\t\treturn {\n\t\t\t\t\torder: _order,\n\t\t\t\t\tselectedBlocks: EMPTY_ARRAY,\n\t\t\t\t\tvisibleBlocks: EMPTY_SET,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// A block list without a custom appender renders a ghost of\n\t\t\t// the container's default block while empty: a real block\n\t\t\t// object rendered before it exists in the store, inserted on\n\t\t\t// entry.\n\t\t\tlet _ghostBlockName;\n\t\t\tlet _ghostBlockAttributes;\n\t\t\tif ( hasAppender && ! hasCustomAppender && ! _order.length ) {\n\t\t\t\tconst defaultBlock = ( rootClientId\n\t\t\t\t\t? getBlockListSettings( rootClientId )?.defaultBlock\n\t\t\t\t\t: undefined ) ?? { name: getDefaultBlockName() };\n\t\t\t\tif (\n\t\t\t\t\tdefaultBlock.name &&\n\t\t\t\t\tcanInsertBlockType( defaultBlock.name, rootClientId )\n\t\t\t\t) {\n\t\t\t\t\t_ghostBlockName = defaultBlock.name;\n\t\t\t\t\t_ghostBlockAttributes = defaultBlock.attributes;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\t\tconst selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\t\tconst showRootAppender =\n\t\t\t\t! rootClientId &&\n\t\t\t\t! selectedBlockClientId &&\n\t\t\t\t( ! _order.length ||\n\t\t\t\t\t! canInsertBlockType(\n\t\t\t\t\t\tgetDefaultBlockName(),\n\t\t\t\t\t\trootClientId\n\t\t\t\t\t) );\n\t\t\tconst hasSelectedRoot = !! (\n\t\t\t\trootClientId &&\n\t\t\t\tselectedBlockClientId &&\n\t\t\t\trootClientId === selectedBlockClientId\n\t\t\t);\n\n\t\t\tconst templateLock = getTemplateLock( rootClientId );\n\n\t\t\tconst appenderAllowed =\n\t\t\t\t( ! isSectionBlock( rootClientId ) ||\n\t\t\t\t\tisContainerInsertableToInContentOnlyMode(\n\t\t\t\t\t\tgetBlockName( selectedBlockClientId ),\n\t\t\t\t\t\trootClientId\n\t\t\t\t\t) ) &&\n\t\t\t\tgetBlockEditingMode( rootClientId ) !== 'disabled' &&\n\t\t\t\t( ! templateLock || templateLock === 'contentOnly' ) &&\n\t\t\t\thasAppender &&\n\t\t\t\t! _isZoomOut();\n\n\t\t\treturn {\n\t\t\t\torder: _order,\n\t\t\t\tselectedBlocks: selectedBlockClientIds,\n\t\t\t\tvisibleBlocks: __unstableGetVisibleBlocks(),\n\t\t\t\tisZoomOut: _isZoomOut(),\n\t\t\t\t// The ghost is the block list's empty state: it renders\n\t\t\t\t// whether or not the block is selected.\n\t\t\t\tghostBlockName: appenderAllowed ? _ghostBlockName : undefined,\n\t\t\t\tghostBlockAttributes: _ghostBlockAttributes,\n\t\t\t\tshouldRenderAppender:\n\t\t\t\t\tappenderAllowed &&\n\t\t\t\t\t( hasCustomAppender ||\n\t\t\t\t\t\thasSelectedRoot ||\n\t\t\t\t\t\tshowRootAppender ),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId, hasAppender, hasCustomAppender ]\n\t);\n\n\t// One ghost per empty period: regenerated when the list empties again\n\t// or the default block changes, stable in between so the client ID,\n\t// and with it the DOM, survives materialization.\n\tconst ghostBlock = useMemo(\n\t\t() =>\n\t\t\tghostBlockName\n\t\t\t\t? createBlock( ghostBlockName, ghostBlockAttributes )\n\t\t\t\t: null,\n\t\t[ ghostBlockName, ghostBlockAttributes ]\n\t);\n\tconst showGhost = !! ghostBlock;\n\n\tconst items = showGhost ? [ ...order, ghostBlock.clientId ] : order;\n\n\treturn (\n\t\t<LayoutProvider value={ layout }>\n\t\t\t{ items.map( ( clientId ) => (\n\t\t\t\t<AsyncModeProvider\n\t\t\t\t\tkey={ clientId }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\t// Only provide data asynchronously if the block is\n\t\t\t\t\t\t// not visible, not selected, and not the ghost.\n\t\t\t\t\t\tclientId !== ghostBlock?.clientId &&\n\t\t\t\t\t\t! visibleBlocks.has( clientId ) &&\n\t\t\t\t\t\t! selectedBlocks.includes( clientId )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ isZoomOut && (\n\t\t\t\t\t\t<ZoomOutSeparator\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tposition=\"top\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<BlockListBlock\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tghostBlock={\n\t\t\t\t\t\t\tclientId === ghostBlock?.clientId\n\t\t\t\t\t\t\t\t? ghostBlock\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t{ isZoomOut && (\n\t\t\t\t\t\t<ZoomOutSeparator\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tposition=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</AsyncModeProvider>\n\t\t\t) ) }\n\t\t\t{ order.length < 1 && placeholder }\n\t\t\t{ shouldRenderAppender && ! showGhost && (\n\t\t\t\t<BlockListAppender\n\t\t\t\t\ttagName={ __experimentalAppenderTagName }\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\tCustomAppender={ CustomAppender }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</LayoutProvider>\n\t);\n}\n\nexport function BlockListItems( props ) {\n\t// This component needs to always be synchronous as it's the one changing\n\t// the async mode depending on the block selection.\n\treturn (\n\t\t<AsyncModeProvider value={ false }>\n\t\t\t<Items { ...props } />\n\t\t</AsyncModeProvider>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,mBAAmB;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,2BAA2B;AACjD,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,gBAAgB,qBAAqB;AAC9C,SAAS,gCAAgC;AACzC,SAAS,2BAA2B;AACpC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB;AACjC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AA,IAgCP,CACC;AAAA,IACA,MAAM,SAAS,KAAK;AAAA,IACpB,wBAAwB,CAAE,aAC3B;AAAA,MAAC;AAAA;AAAA,QACA,SAAU;AAAA,QACV;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEO,SAAS,eAAgB,OAAQ;AAGvC,SACC,oBAAC,qBAAkB,OAAQ,OAC1B,8BAAC,SAAQ,GAAG,OAAQ,GACrB;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,6 +27,10 @@ function useFocusFirstElement({ clientId, initialPosition }) {
|
|
|
27
27
|
if (isInsideRootBlock(ref.current, ownerDocument.activeElement)) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
+
if (initialPosition === true) {
|
|
31
|
+
ref.current.focus();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
30
34
|
const textInputs = focus.tabbable.find(ref.current).filter((node) => isTextField(node));
|
|
31
35
|
const isReverse = -1 === initialPosition;
|
|
32
36
|
const target = textInputs[isReverse ? textInputs.length - 1 : 0] || ref.current;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/block-list/use-block-props/use-focus-first-element.js"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useRef } from '@wordpress/element';\nimport {\n\tfocus,\n\tisFormElement,\n\tisTextField,\n\tplaceCaretAtHorizontalEdge,\n} from '@wordpress/dom';\nimport { useSelect } from '@wordpress/data';\nimport { isInsideRootBlock } from '../../../utils/dom';\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n\n/**\n * Transitions focus to the block or inner tabbable when the block becomes\n * selected and an initial position is set.\n *\n * @param {string} clientId Block client ID.\n *\n * @return {RefObject} React ref with the block element.\n */\nexport function useFocusFirstElement( { clientId, initialPosition } ) {\n\tconst ref = useRef();\n\tconst { isBlockSelected, isMultiSelecting, isZoomOut, getSelectionStart } =\n\t\tunlock( useSelect( blockEditorStore ) );\n\n\tuseEffect( () => {\n\t\t// Check if the block is still selected at the time this effect runs.\n\t\tif (\n\t\t\t! isBlockSelected( clientId ) ||\n\t\t\tisMultiSelecting() ||\n\t\t\tisZoomOut()\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( initialPosition === undefined || initialPosition === null ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerDocument } = ref.current;\n\n\t\t// Do not focus the block if it already contains the active element.\n\t\tif ( isInsideRootBlock( ref.current, ownerDocument.activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Find all tabbables within node.\n\t\tconst textInputs = focus.tabbable\n\t\t\t.find( ref.current )\n\t\t\t.filter( ( node ) => isTextField( node ) );\n\n\t\t// If reversed (e.g. merge via backspace), use the last in the set of\n\t\t// tabbables.\n\t\tconst isReverse = -1 === initialPosition;\n\t\tconst target =\n\t\t\ttextInputs[ isReverse ? textInputs.length - 1 : 0 ] || ref.current;\n\n\t\tif ( ! isInsideRootBlock( ref.current, target ) ) {\n\t\t\tref.current.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check to see if element is focussable before a generic caret insert.\n\t\tif ( ! ref.current.getAttribute( 'contenteditable' ) ) {\n\t\t\tconst focusElement = focus.tabbable.findNext( ref.current );\n\t\t\t// Make sure focusElement is valid, contained in the same block, and a form field.\n\t\t\tif (\n\t\t\t\tfocusElement &&\n\t\t\t\tisInsideRootBlock( ref.current, focusElement ) &&\n\t\t\t\tisFormElement( focusElement )\n\t\t\t) {\n\t\t\t\tfocusElement.focus();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t// Do not place a caret when the target already contains one:\n\t\t// while a focused editing host contains the target (the block\n\t\t// supports `editableRoot`), the caret can be inside it without the\n\t\t// target holding focus. Only a caret the rich text synchronized to\n\t\t// the store (offsets present) is deliberate; a leftover one yields\n\t\t// to an explicitly requested edge position (initialPosition -1).\n\t\tconst { activeElement } = ownerDocument;\n\t\tconst selection = ownerDocument.defaultView.getSelection();\n\t\tconst { clientId: selectionClientId, offset } = getSelectionStart();\n\t\tconst hasCaret =\n\t\t\tactiveElement?.isContentEditable &&\n\t\t\tactiveElement.contains( target ) &&\n\t\t\t!! selection.anchorNode &&\n\t\t\ttarget.contains( selection.anchorNode );\n\t\tconst isDeliberate =\n\t\t\tinitialPosition === 0 ||\n\t\t\t( offset !== undefined && selectionClientId === clientId );\n\n\t\tif ( ! ( hasCaret && isDeliberate ) ) {\n\t\t\tplaceCaretAtHorizontalEdge( target, isReverse );\n\t\t}\n\t}, [ initialPosition, clientId ] );\n\n\treturn ref;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,WAAW,cAAc;AAClC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AAYhB,SAAS,qBAAsB,EAAE,UAAU,gBAAgB,GAAI;AACrE,QAAM,MAAM,OAAO;AACnB,QAAM,EAAE,iBAAiB,kBAAkB,WAAW,kBAAkB,IACvE,OAAQ,UAAW,gBAAiB,CAAE;AAEvC,YAAW,MAAM;AAEhB,QACC,CAAE,gBAAiB,QAAS,KAC5B,iBAAiB,KACjB,UAAU,GACT;AACD;AAAA,IACD;AAEA,QAAK,oBAAoB,UAAa,oBAAoB,MAAO;AAChE;AAAA,IACD;AAEA,QAAK,CAAE,IAAI,SAAU;AACpB;AAAA,IACD;AAEA,UAAM,EAAE,cAAc,IAAI,IAAI;AAG9B,QAAK,kBAAmB,IAAI,SAAS,cAAc,aAAc,GAAI;AACpE;AAAA,IACD;AAGA,UAAM,aAAa,MAAM,SACvB,KAAM,IAAI,OAAQ,EAClB,OAAQ,CAAE,SAAU,YAAa,IAAK,CAAE;AAI1C,UAAM,YAAY,OAAO;AACzB,UAAM,SACL,WAAY,YAAY,WAAW,SAAS,IAAI,CAAE,KAAK,IAAI;AAE5D,QAAK,CAAE,kBAAmB,IAAI,SAAS,MAAO,GAAI;AACjD,UAAI,QAAQ,MAAM;AAClB;AAAA,IACD;AAGA,QAAK,CAAE,IAAI,QAAQ,aAAc,iBAAkB,GAAI;AACtD,YAAM,eAAe,MAAM,SAAS,SAAU,IAAI,OAAQ;AAE1D,UACC,gBACA,kBAAmB,IAAI,SAAS,YAAa,KAC7C,cAAe,YAAa,GAC3B;AACD,qBAAa,MAAM;AACnB;AAAA,MACD;AAAA,IACD;AAOA,UAAM,EAAE,cAAc,IAAI;AAC1B,UAAM,YAAY,cAAc,YAAY,aAAa;AACzD,UAAM,EAAE,UAAU,mBAAmB,OAAO,IAAI,kBAAkB;AAClE,UAAM,WACL,eAAe,qBACf,cAAc,SAAU,MAAO,KAC/B,CAAC,CAAE,UAAU,cACb,OAAO,SAAU,UAAU,UAAW;AACvC,UAAM,eACL,oBAAoB,KAClB,WAAW,UAAa,sBAAsB;AAEjD,QAAK,EAAI,YAAY,eAAiB;AACrC,iCAA4B,QAAQ,SAAU;AAAA,IAC/C;AAAA,EACD,GAAG,CAAE,iBAAiB,QAAS,CAAE;AAEjC,SAAO;AACR;",
|
|
4
|
+
"sourcesContent": ["import { useEffect, useRef } from '@wordpress/element';\nimport {\n\tfocus,\n\tisFormElement,\n\tisTextField,\n\tplaceCaretAtHorizontalEdge,\n} from '@wordpress/dom';\nimport { useSelect } from '@wordpress/data';\nimport { isInsideRootBlock } from '../../../utils/dom';\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n\n/**\n * Transitions focus to the block or inner tabbable when the block becomes\n * selected and an initial position is set.\n *\n * @param {string} clientId Block client ID.\n *\n * @return {RefObject} React ref with the block element.\n */\nexport function useFocusFirstElement( { clientId, initialPosition } ) {\n\tconst ref = useRef();\n\tconst { isBlockSelected, isMultiSelecting, isZoomOut, getSelectionStart } =\n\t\tunlock( useSelect( blockEditorStore ) );\n\n\tuseEffect( () => {\n\t\t// Check if the block is still selected at the time this effect runs.\n\t\tif (\n\t\t\t! isBlockSelected( clientId ) ||\n\t\t\tisMultiSelecting() ||\n\t\t\tisZoomOut()\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( initialPosition === undefined || initialPosition === null ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerDocument } = ref.current;\n\n\t\t// Do not focus the block if it already contains the active element.\n\t\tif ( isInsideRootBlock( ref.current, ownerDocument.activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( initialPosition === true ) {\n\t\t\tref.current.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Find all tabbables within node.\n\t\tconst textInputs = focus.tabbable\n\t\t\t.find( ref.current )\n\t\t\t.filter( ( node ) => isTextField( node ) );\n\n\t\t// If reversed (e.g. merge via backspace), use the last in the set of\n\t\t// tabbables.\n\t\tconst isReverse = -1 === initialPosition;\n\t\tconst target =\n\t\t\ttextInputs[ isReverse ? textInputs.length - 1 : 0 ] || ref.current;\n\n\t\tif ( ! isInsideRootBlock( ref.current, target ) ) {\n\t\t\tref.current.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check to see if element is focussable before a generic caret insert.\n\t\tif ( ! ref.current.getAttribute( 'contenteditable' ) ) {\n\t\t\tconst focusElement = focus.tabbable.findNext( ref.current );\n\t\t\t// Make sure focusElement is valid, contained in the same block, and a form field.\n\t\t\tif (\n\t\t\t\tfocusElement &&\n\t\t\t\tisInsideRootBlock( ref.current, focusElement ) &&\n\t\t\t\tisFormElement( focusElement )\n\t\t\t) {\n\t\t\t\tfocusElement.focus();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t// Do not place a caret when the target already contains one:\n\t\t// while a focused editing host contains the target (the block\n\t\t// supports `editableRoot`), the caret can be inside it without the\n\t\t// target holding focus. Only a caret the rich text synchronized to\n\t\t// the store (offsets present) is deliberate; a leftover one yields\n\t\t// to an explicitly requested edge position (initialPosition -1).\n\t\tconst { activeElement } = ownerDocument;\n\t\tconst selection = ownerDocument.defaultView.getSelection();\n\t\tconst { clientId: selectionClientId, offset } = getSelectionStart();\n\t\tconst hasCaret =\n\t\t\tactiveElement?.isContentEditable &&\n\t\t\tactiveElement.contains( target ) &&\n\t\t\t!! selection.anchorNode &&\n\t\t\ttarget.contains( selection.anchorNode );\n\t\tconst isDeliberate =\n\t\t\tinitialPosition === 0 ||\n\t\t\t( offset !== undefined && selectionClientId === clientId );\n\n\t\tif ( ! ( hasCaret && isDeliberate ) ) {\n\t\t\tplaceCaretAtHorizontalEdge( target, isReverse );\n\t\t}\n\t}, [ initialPosition, clientId ] );\n\n\treturn ref;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,WAAW,cAAc;AAClC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AAYhB,SAAS,qBAAsB,EAAE,UAAU,gBAAgB,GAAI;AACrE,QAAM,MAAM,OAAO;AACnB,QAAM,EAAE,iBAAiB,kBAAkB,WAAW,kBAAkB,IACvE,OAAQ,UAAW,gBAAiB,CAAE;AAEvC,YAAW,MAAM;AAEhB,QACC,CAAE,gBAAiB,QAAS,KAC5B,iBAAiB,KACjB,UAAU,GACT;AACD;AAAA,IACD;AAEA,QAAK,oBAAoB,UAAa,oBAAoB,MAAO;AAChE;AAAA,IACD;AAEA,QAAK,CAAE,IAAI,SAAU;AACpB;AAAA,IACD;AAEA,UAAM,EAAE,cAAc,IAAI,IAAI;AAG9B,QAAK,kBAAmB,IAAI,SAAS,cAAc,aAAc,GAAI;AACpE;AAAA,IACD;AAEA,QAAK,oBAAoB,MAAO;AAC/B,UAAI,QAAQ,MAAM;AAClB;AAAA,IACD;AAGA,UAAM,aAAa,MAAM,SACvB,KAAM,IAAI,OAAQ,EAClB,OAAQ,CAAE,SAAU,YAAa,IAAK,CAAE;AAI1C,UAAM,YAAY,OAAO;AACzB,UAAM,SACL,WAAY,YAAY,WAAW,SAAS,IAAI,CAAE,KAAK,IAAI;AAE5D,QAAK,CAAE,kBAAmB,IAAI,SAAS,MAAO,GAAI;AACjD,UAAI,QAAQ,MAAM;AAClB;AAAA,IACD;AAGA,QAAK,CAAE,IAAI,QAAQ,aAAc,iBAAkB,GAAI;AACtD,YAAM,eAAe,MAAM,SAAS,SAAU,IAAI,OAAQ;AAE1D,UACC,gBACA,kBAAmB,IAAI,SAAS,YAAa,KAC7C,cAAe,YAAa,GAC3B;AACD,qBAAa,MAAM;AACnB;AAAA,MACD;AAAA,IACD;AAOA,UAAM,EAAE,cAAc,IAAI;AAC1B,UAAM,YAAY,cAAc,YAAY,aAAa;AACzD,UAAM,EAAE,UAAU,mBAAmB,OAAO,IAAI,kBAAkB;AAClE,UAAM,WACL,eAAe,qBACf,cAAc,SAAU,MAAO,KAC/B,CAAC,CAAE,UAAU,cACb,OAAO,SAAU,UAAU,UAAW;AACvC,UAAM,eACL,oBAAoB,KAClB,WAAW,UAAa,sBAAsB;AAEjD,QAAK,EAAI,YAAY,eAAiB;AACrC,iCAA4B,QAAQ,SAAU;AAAA,IAC/C;AAAA,EACD,GAAG,CAAE,iBAAiB,QAAS,CAAE;AAEjC,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs
CHANGED
|
@@ -19,7 +19,6 @@ function useEventHandlers({ clientId, isSelected }) {
|
|
|
19
19
|
getBlock
|
|
20
20
|
} = unlock(useSelect(blockEditorStore));
|
|
21
21
|
const {
|
|
22
|
-
insertAfterBlock,
|
|
23
22
|
removeBlock,
|
|
24
23
|
resetZoomLevel,
|
|
25
24
|
startDraggingBlocks,
|
|
@@ -39,12 +38,13 @@ function useEventHandlers({ clientId, isSelected }) {
|
|
|
39
38
|
if (target !== node || isTextField(target)) {
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
if (keyCode === ENTER) {
|
|
42
|
+
if (isZoomOut()) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
resetZoomLevel();
|
|
45
|
+
}
|
|
47
46
|
} else {
|
|
47
|
+
event.preventDefault();
|
|
48
48
|
removeBlock(clientId);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -220,7 +220,6 @@ function useEventHandlers({ clientId, isSelected }) {
|
|
|
220
220
|
getBlock,
|
|
221
221
|
isReusableBlock,
|
|
222
222
|
isTemplatePart,
|
|
223
|
-
insertAfterBlock,
|
|
224
223
|
removeBlock,
|
|
225
224
|
isZoomOut,
|
|
226
225
|
resetZoomLevel,
|
package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/block-list/use-block-props/use-selected-block-event-handlers.js"],
|
|
4
|
-
"sourcesContent": ["import { isReusableBlock, isTemplatePart } from '@wordpress/blocks';\nimport { isTextField } from '@wordpress/dom';\nimport { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nfunction isColorTransparent( color ) {\n\treturn ! color || color === 'transparent' || color === 'rgba(0, 0, 0, 0)';\n}\n\n/**\n * Adds block behaviour:\n * - Removes the block on BACKSPACE.\n * - Inserts a default block on ENTER.\n * - Disables dragging of block contents.\n *\n * @param {string} clientId Block client ID.\n */\nexport function useEventHandlers( { clientId, isSelected } ) {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tisZoomOut,\n\t\thasMultiSelection,\n\t\tisSectionBlock,\n\t\teditedContentOnlySection,\n\t\tgetBlock,\n\t} = unlock( useSelect( blockEditorStore ) );\n\tconst {\n\t\tinsertAfterBlock,\n\t\tremoveBlock,\n\t\tresetZoomLevel,\n\t\tstartDraggingBlocks,\n\t\tstopDraggingBlocks,\n\t\teditContentOnlySection,\n\t} = unlock( useDispatch( blockEditorStore ) );\n\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( ! isSelected ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Interprets keydown event intent to remove or insert after block if\n\t\t\t * key event occurs on wrapper node. This can occur when the block has\n\t\t\t * no text fields of its own, particularly after initial insertion, to\n\t\t\t * allow for easy deletion and continuous writing flow to add additional\n\t\t\t * content.\n\t\t\t *\n\t\t\t * @param {KeyboardEvent} event Keydown event.\n\t\t\t */\n\t\t\tfunction onKeyDown( event ) {\n\t\t\t\tconst { keyCode, target } = event;\n\n\t\t\t\tif (\n\t\t\t\t\tkeyCode !== ENTER &&\n\t\t\t\t\tkeyCode !== BACKSPACE &&\n\t\t\t\t\tkeyCode !== DELETE\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( target !== node || isTextField( target ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( keyCode === ENTER && isZoomOut() ) {\n\t\t\t\t\tresetZoomLevel();\n\t\t\t\t} else if ( keyCode === ENTER ) {\n\t\t\t\t\tinsertAfterBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tremoveBlock( clientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Prevents default dragging behavior within a block. To do: we must\n\t\t\t * handle this in the future and clean up the drag target.\n\t\t\t *\n\t\t\t * @param {DragEvent} event Drag event.\n\t\t\t */\n\t\t\tfunction onDragStart( event ) {\n\t\t\t\tif (\n\t\t\t\t\tnode !== event.target ||\n\t\t\t\t\tnode.isContentEditable ||\n\t\t\t\t\tnode.ownerDocument.activeElement !== node ||\n\t\t\t\t\thasMultiSelection()\n\t\t\t\t) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst data = JSON.stringify( {\n\t\t\t\t\ttype: 'block',\n\t\t\t\t\tsrcClientIds: [ clientId ],\n\t\t\t\t\tsrcRootClientId: getBlockRootClientId( clientId ),\n\t\t\t\t} );\n\t\t\t\tevent.dataTransfer.effectAllowed = 'move'; // remove \"+\" cursor\n\t\t\t\tevent.dataTransfer.clearData();\n\t\t\t\tevent.dataTransfer.setData( 'wp-blocks', data );\n\t\t\t\tconst { ownerDocument } = node;\n\t\t\t\tconst { defaultView } = ownerDocument;\n\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\tselection.removeAllRanges();\n\n\t\t\t\t// Setting the drag chip as the drag image actually works, but\n\t\t\t\t// the behaviour is slightly different in every browser. In\n\t\t\t\t// Safari, it animates, in Firefox it's slightly transparent...\n\t\t\t\t// So we set a fake drag image and have to reposition it\n\t\t\t\t// ourselves.\n\t\t\t\tconst dragElement = ownerDocument.createElement( 'div' );\n\t\t\t\t// Chrome will show a globe icon if the drag element does not\n\t\t\t\t// have dimensions.\n\t\t\t\tdragElement.style.width = '1px';\n\t\t\t\tdragElement.style.height = '1px';\n\t\t\t\tdragElement.style.position = 'fixed';\n\t\t\t\tdragElement.style.visibility = 'hidden';\n\t\t\t\townerDocument.body.appendChild( dragElement );\n\t\t\t\tevent.dataTransfer.setDragImage( dragElement, 0, 0 );\n\n\t\t\t\tconst rect = node.getBoundingClientRect();\n\n\t\t\t\t// Remove the id and leave it on a shallow clone so that drop\n\t\t\t\t// target calculations are correct.\n\t\t\t\tconst id = node.id;\n\t\t\t\tconst clone = node.cloneNode();\n\t\t\t\tclone.style.display = 'none';\n\t\t\t\tnode.id = null;\n\t\t\t\tnode.after( clone );\n\n\t\t\t\tlet _scale = 1;\n\n\t\t\t\t{\n\t\t\t\t\tlet parentElement = node;\n\t\t\t\t\twhile ( ( parentElement = parentElement.parentElement ) ) {\n\t\t\t\t\t\tconst { scale } =\n\t\t\t\t\t\t\tdefaultView.getComputedStyle( parentElement );\n\t\t\t\t\t\tif ( scale && scale !== 'none' ) {\n\t\t\t\t\t\t\t_scale = parseFloat( scale );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst inverted = 1 / _scale;\n\n\t\t\t\tconst originalNodeProperties = {};\n\t\t\t\tfor ( const property of [\n\t\t\t\t\t'transform',\n\t\t\t\t\t'transformOrigin',\n\t\t\t\t\t'transition',\n\t\t\t\t\t'zIndex',\n\t\t\t\t\t'position',\n\t\t\t\t\t'top',\n\t\t\t\t\t'left',\n\t\t\t\t\t'pointerEvents',\n\t\t\t\t\t'opacity',\n\t\t\t\t\t'backgroundColor',\n\t\t\t\t] ) {\n\t\t\t\t\toriginalNodeProperties[ property ] = node.style[ property ];\n\t\t\t\t}\n\n\t\t\t\t// Get scroll position.\n\t\t\t\tconst originScrollTop = defaultView.scrollY;\n\t\t\t\tconst originScrollLeft = defaultView.scrollX;\n\t\t\t\tconst originClientX = event.clientX;\n\t\t\t\tconst originClientY = event.clientY;\n\n\t\t\t\t// We can't use position fixed because it will behave different\n\t\t\t\t// if the html element is scaled or transformed (position will\n\t\t\t\t// no longer be relative to the viewport). The downside of\n\t\t\t\t// relative is that we have to listen to scroll events. On the\n\t\t\t\t// upside we don't have to clone to keep a space. Absolute\n\t\t\t\t// positioning might be weird because it will be based on the\n\t\t\t\t// positioned parent, but it might be worth a try.\n\t\t\t\tnode.style.position = 'relative';\n\t\t\t\tnode.style.top = `${ 0 }px`;\n\t\t\t\tnode.style.left = `${ 0 }px`;\n\n\t\t\t\tconst originX = event.clientX - rect.left;\n\t\t\t\tconst originY = event.clientY - rect.top;\n\n\t\t\t\t// Scale everything to 200px.\n\t\t\t\tconst dragScale = rect.height > 200 ? 200 / rect.height : 1;\n\n\t\t\t\tnode.style.zIndex = '1000';\n\t\t\t\tnode.style.transformOrigin = `${ originX * inverted }px ${\n\t\t\t\t\toriginY * inverted\n\t\t\t\t}px`;\n\t\t\t\tnode.style.transition = 'transform 0.2s ease-out';\n\t\t\t\tnode.style.transform = `scale(${ dragScale })`;\n\t\t\t\tnode.style.opacity = '0.9';\n\n\t\t\t\t// If the block has no background color, use the parent's\n\t\t\t\t// background color.\n\t\t\t\tif (\n\t\t\t\t\tisColorTransparent(\n\t\t\t\t\t\tdefaultView.getComputedStyle( node ).backgroundColor\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tlet bgColor = 'transparent';\n\t\t\t\t\tlet parentElement = node;\n\t\t\t\t\twhile ( ( parentElement = parentElement.parentElement ) ) {\n\t\t\t\t\t\tconst { backgroundColor } =\n\t\t\t\t\t\t\tdefaultView.getComputedStyle( parentElement );\n\t\t\t\t\t\tif ( ! isColorTransparent( backgroundColor ) ) {\n\t\t\t\t\t\t\tbgColor = backgroundColor;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.style.backgroundColor = bgColor;\n\t\t\t\t}\n\n\t\t\t\tlet hasStarted = false;\n\t\t\t\tlet lastClientX = originClientX;\n\t\t\t\tlet lastClientY = originClientY;\n\n\t\t\t\tfunction dragOver( e ) {\n\t\t\t\t\t// Only trigger `over` if the mouse has moved.\n\t\t\t\t\tif (\n\t\t\t\t\t\te.clientX === lastClientX &&\n\t\t\t\t\t\te.clientY === lastClientY\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlastClientX = e.clientX;\n\t\t\t\t\tlastClientY = e.clientY;\n\t\t\t\t\tover();\n\t\t\t\t}\n\n\t\t\t\tfunction over() {\n\t\t\t\t\tif ( ! hasStarted ) {\n\t\t\t\t\t\thasStarted = true;\n\t\t\t\t\t\tnode.style.pointerEvents = 'none';\n\t\t\t\t\t}\n\t\t\t\t\tconst pointerYDelta = lastClientY - originClientY;\n\t\t\t\t\tconst pointerXDelta = lastClientX - originClientX;\n\t\t\t\t\tconst scrollTop = defaultView.scrollY;\n\t\t\t\t\tconst scrollLeft = defaultView.scrollX;\n\t\t\t\t\tconst scrollTopDelta = scrollTop - originScrollTop;\n\t\t\t\t\tconst scrollLeftDelta = scrollLeft - originScrollLeft;\n\t\t\t\t\tconst topDelta = pointerYDelta + scrollTopDelta;\n\t\t\t\t\tconst leftDelta = pointerXDelta + scrollLeftDelta;\n\t\t\t\t\tnode.style.top = `${ topDelta * inverted }px`;\n\t\t\t\t\tnode.style.left = `${ leftDelta * inverted }px`;\n\t\t\t\t}\n\n\t\t\t\tfunction end() {\n\t\t\t\t\townerDocument.removeEventListener( 'dragover', dragOver );\n\t\t\t\t\townerDocument.removeEventListener( 'dragend', end );\n\t\t\t\t\townerDocument.removeEventListener( 'drop', end );\n\t\t\t\t\townerDocument.removeEventListener( 'scroll', over );\n\t\t\t\t\tfor ( const [ property, value ] of Object.entries(\n\t\t\t\t\t\toriginalNodeProperties\n\t\t\t\t\t) ) {\n\t\t\t\t\t\tnode.style[ property ] = value;\n\t\t\t\t\t}\n\t\t\t\t\tclone.remove();\n\t\t\t\t\tnode.id = id;\n\t\t\t\t\tdragElement.remove();\n\t\t\t\t\tstopDraggingBlocks();\n\t\t\t\t\tdocument.body.classList.remove(\n\t\t\t\t\t\t'is-dragging-components-draggable'\n\t\t\t\t\t);\n\t\t\t\t\townerDocument.documentElement.classList.remove(\n\t\t\t\t\t\t'is-dragging'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\townerDocument.addEventListener( 'dragover', dragOver );\n\t\t\t\townerDocument.addEventListener( 'dragend', end );\n\t\t\t\townerDocument.addEventListener( 'drop', end );\n\t\t\t\townerDocument.addEventListener( 'scroll', over );\n\n\t\t\t\tstartDraggingBlocks( [ clientId ] );\n\t\t\t\t// Important because it hides the block toolbar.\n\t\t\t\tdocument.body.classList.add(\n\t\t\t\t\t'is-dragging-components-draggable'\n\t\t\t\t);\n\t\t\t\townerDocument.documentElement.classList.add( 'is-dragging' );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\t\tnode.addEventListener( 'dragstart', onDragStart );\n\n\t\t\t/**\n\t\t\t * Handles double-click events on section blocks to edit content only section.\n\t\t\t *\n\t\t\t * @param {MouseEvent} event Double-click event.\n\t\t\t */\n\t\t\tfunction onDoubleClick( event ) {\n\t\t\t\tconst isSection = isSectionBlock( clientId );\n\t\t\t\tconst block = getBlock( clientId );\n\t\t\t\tconst isSyncedPattern = isReusableBlock( block );\n\t\t\t\tconst isTemplatePartBlock = isTemplatePart( block );\n\t\t\t\tconst isAlreadyEditing = editedContentOnlySection === clientId;\n\n\t\t\t\tif (\n\t\t\t\t\t! isSection ||\n\t\t\t\t\tisAlreadyEditing ||\n\t\t\t\t\tisSyncedPattern ||\n\t\t\t\t\tisTemplatePartBlock\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\t\t\t\teditContentOnlySection( clientId );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'dblclick', onDoubleClick );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\t\tnode.removeEventListener( 'dragstart', onDragStart );\n\t\t\t\tnode.removeEventListener( 'dblclick', onDoubleClick );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tisSelected,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlock,\n\t\t\tisReusableBlock,\n\t\t\tisTemplatePart,\n\t\t\tinsertAfterBlock,\n\t\t\tremoveBlock,\n\t\t\tisZoomOut,\n\t\t\tresetZoomLevel,\n\t\t\thasMultiSelection,\n\t\t\tstartDraggingBlocks,\n\t\t\tstopDraggingBlocks,\n\t\t\tisSectionBlock,\n\t\t\teditedContentOnlySection,\n\t\t\teditContentOnlySection,\n\t\t]\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,OAAO,WAAW,cAAc;AACzC,SAAS,WAAW,mBAAmB;AACvC,SAAS,oBAAoB;AAC7B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AAEvB,SAAS,mBAAoB,OAAQ;AACpC,SAAO,CAAE,SAAS,UAAU,iBAAiB,UAAU;AACxD;AAUO,SAAS,iBAAkB,EAAE,UAAU,WAAW,GAAI;AAC5D,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,OAAQ,UAAW,gBAAiB,CAAE;AAC1C,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { isReusableBlock, isTemplatePart } from '@wordpress/blocks';\nimport { isTextField } from '@wordpress/dom';\nimport { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nfunction isColorTransparent( color ) {\n\treturn ! color || color === 'transparent' || color === 'rgba(0, 0, 0, 0)';\n}\n\n/**\n * Adds block behaviour:\n * - Removes the block on BACKSPACE.\n * - Inserts a default block on ENTER.\n * - Disables dragging of block contents.\n *\n * @param {string} clientId Block client ID.\n */\nexport function useEventHandlers( { clientId, isSelected } ) {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tisZoomOut,\n\t\thasMultiSelection,\n\t\tisSectionBlock,\n\t\teditedContentOnlySection,\n\t\tgetBlock,\n\t} = unlock( useSelect( blockEditorStore ) );\n\tconst {\n\t\tremoveBlock,\n\t\tresetZoomLevel,\n\t\tstartDraggingBlocks,\n\t\tstopDraggingBlocks,\n\t\teditContentOnlySection,\n\t} = unlock( useDispatch( blockEditorStore ) );\n\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( ! isSelected ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Interprets keydown event intent to remove or insert after block if\n\t\t\t * key event occurs on wrapper node. This can occur when the block has\n\t\t\t * no text fields of its own, particularly after initial insertion, to\n\t\t\t * allow for easy deletion and continuous writing flow to add additional\n\t\t\t * content.\n\t\t\t *\n\t\t\t * @param {KeyboardEvent} event Keydown event.\n\t\t\t */\n\t\t\tfunction onKeyDown( event ) {\n\t\t\t\tconst { keyCode, target } = event;\n\n\t\t\t\tif (\n\t\t\t\t\tkeyCode !== ENTER &&\n\t\t\t\t\tkeyCode !== BACKSPACE &&\n\t\t\t\t\tkeyCode !== DELETE\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( target !== node || isTextField( target ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( keyCode === ENTER ) {\n\t\t\t\t\tif ( isZoomOut() ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tresetZoomLevel();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tremoveBlock( clientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Prevents default dragging behavior within a block. To do: we must\n\t\t\t * handle this in the future and clean up the drag target.\n\t\t\t *\n\t\t\t * @param {DragEvent} event Drag event.\n\t\t\t */\n\t\t\tfunction onDragStart( event ) {\n\t\t\t\tif (\n\t\t\t\t\tnode !== event.target ||\n\t\t\t\t\tnode.isContentEditable ||\n\t\t\t\t\tnode.ownerDocument.activeElement !== node ||\n\t\t\t\t\thasMultiSelection()\n\t\t\t\t) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst data = JSON.stringify( {\n\t\t\t\t\ttype: 'block',\n\t\t\t\t\tsrcClientIds: [ clientId ],\n\t\t\t\t\tsrcRootClientId: getBlockRootClientId( clientId ),\n\t\t\t\t} );\n\t\t\t\tevent.dataTransfer.effectAllowed = 'move'; // remove \"+\" cursor\n\t\t\t\tevent.dataTransfer.clearData();\n\t\t\t\tevent.dataTransfer.setData( 'wp-blocks', data );\n\t\t\t\tconst { ownerDocument } = node;\n\t\t\t\tconst { defaultView } = ownerDocument;\n\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\tselection.removeAllRanges();\n\n\t\t\t\t// Setting the drag chip as the drag image actually works, but\n\t\t\t\t// the behaviour is slightly different in every browser. In\n\t\t\t\t// Safari, it animates, in Firefox it's slightly transparent...\n\t\t\t\t// So we set a fake drag image and have to reposition it\n\t\t\t\t// ourselves.\n\t\t\t\tconst dragElement = ownerDocument.createElement( 'div' );\n\t\t\t\t// Chrome will show a globe icon if the drag element does not\n\t\t\t\t// have dimensions.\n\t\t\t\tdragElement.style.width = '1px';\n\t\t\t\tdragElement.style.height = '1px';\n\t\t\t\tdragElement.style.position = 'fixed';\n\t\t\t\tdragElement.style.visibility = 'hidden';\n\t\t\t\townerDocument.body.appendChild( dragElement );\n\t\t\t\tevent.dataTransfer.setDragImage( dragElement, 0, 0 );\n\n\t\t\t\tconst rect = node.getBoundingClientRect();\n\n\t\t\t\t// Remove the id and leave it on a shallow clone so that drop\n\t\t\t\t// target calculations are correct.\n\t\t\t\tconst id = node.id;\n\t\t\t\tconst clone = node.cloneNode();\n\t\t\t\tclone.style.display = 'none';\n\t\t\t\tnode.id = null;\n\t\t\t\tnode.after( clone );\n\n\t\t\t\tlet _scale = 1;\n\n\t\t\t\t{\n\t\t\t\t\tlet parentElement = node;\n\t\t\t\t\twhile ( ( parentElement = parentElement.parentElement ) ) {\n\t\t\t\t\t\tconst { scale } =\n\t\t\t\t\t\t\tdefaultView.getComputedStyle( parentElement );\n\t\t\t\t\t\tif ( scale && scale !== 'none' ) {\n\t\t\t\t\t\t\t_scale = parseFloat( scale );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst inverted = 1 / _scale;\n\n\t\t\t\tconst originalNodeProperties = {};\n\t\t\t\tfor ( const property of [\n\t\t\t\t\t'transform',\n\t\t\t\t\t'transformOrigin',\n\t\t\t\t\t'transition',\n\t\t\t\t\t'zIndex',\n\t\t\t\t\t'position',\n\t\t\t\t\t'top',\n\t\t\t\t\t'left',\n\t\t\t\t\t'pointerEvents',\n\t\t\t\t\t'opacity',\n\t\t\t\t\t'backgroundColor',\n\t\t\t\t] ) {\n\t\t\t\t\toriginalNodeProperties[ property ] = node.style[ property ];\n\t\t\t\t}\n\n\t\t\t\t// Get scroll position.\n\t\t\t\tconst originScrollTop = defaultView.scrollY;\n\t\t\t\tconst originScrollLeft = defaultView.scrollX;\n\t\t\t\tconst originClientX = event.clientX;\n\t\t\t\tconst originClientY = event.clientY;\n\n\t\t\t\t// We can't use position fixed because it will behave different\n\t\t\t\t// if the html element is scaled or transformed (position will\n\t\t\t\t// no longer be relative to the viewport). The downside of\n\t\t\t\t// relative is that we have to listen to scroll events. On the\n\t\t\t\t// upside we don't have to clone to keep a space. Absolute\n\t\t\t\t// positioning might be weird because it will be based on the\n\t\t\t\t// positioned parent, but it might be worth a try.\n\t\t\t\tnode.style.position = 'relative';\n\t\t\t\tnode.style.top = `${ 0 }px`;\n\t\t\t\tnode.style.left = `${ 0 }px`;\n\n\t\t\t\tconst originX = event.clientX - rect.left;\n\t\t\t\tconst originY = event.clientY - rect.top;\n\n\t\t\t\t// Scale everything to 200px.\n\t\t\t\tconst dragScale = rect.height > 200 ? 200 / rect.height : 1;\n\n\t\t\t\tnode.style.zIndex = '1000';\n\t\t\t\tnode.style.transformOrigin = `${ originX * inverted }px ${\n\t\t\t\t\toriginY * inverted\n\t\t\t\t}px`;\n\t\t\t\tnode.style.transition = 'transform 0.2s ease-out';\n\t\t\t\tnode.style.transform = `scale(${ dragScale })`;\n\t\t\t\tnode.style.opacity = '0.9';\n\n\t\t\t\t// If the block has no background color, use the parent's\n\t\t\t\t// background color.\n\t\t\t\tif (\n\t\t\t\t\tisColorTransparent(\n\t\t\t\t\t\tdefaultView.getComputedStyle( node ).backgroundColor\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tlet bgColor = 'transparent';\n\t\t\t\t\tlet parentElement = node;\n\t\t\t\t\twhile ( ( parentElement = parentElement.parentElement ) ) {\n\t\t\t\t\t\tconst { backgroundColor } =\n\t\t\t\t\t\t\tdefaultView.getComputedStyle( parentElement );\n\t\t\t\t\t\tif ( ! isColorTransparent( backgroundColor ) ) {\n\t\t\t\t\t\t\tbgColor = backgroundColor;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.style.backgroundColor = bgColor;\n\t\t\t\t}\n\n\t\t\t\tlet hasStarted = false;\n\t\t\t\tlet lastClientX = originClientX;\n\t\t\t\tlet lastClientY = originClientY;\n\n\t\t\t\tfunction dragOver( e ) {\n\t\t\t\t\t// Only trigger `over` if the mouse has moved.\n\t\t\t\t\tif (\n\t\t\t\t\t\te.clientX === lastClientX &&\n\t\t\t\t\t\te.clientY === lastClientY\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlastClientX = e.clientX;\n\t\t\t\t\tlastClientY = e.clientY;\n\t\t\t\t\tover();\n\t\t\t\t}\n\n\t\t\t\tfunction over() {\n\t\t\t\t\tif ( ! hasStarted ) {\n\t\t\t\t\t\thasStarted = true;\n\t\t\t\t\t\tnode.style.pointerEvents = 'none';\n\t\t\t\t\t}\n\t\t\t\t\tconst pointerYDelta = lastClientY - originClientY;\n\t\t\t\t\tconst pointerXDelta = lastClientX - originClientX;\n\t\t\t\t\tconst scrollTop = defaultView.scrollY;\n\t\t\t\t\tconst scrollLeft = defaultView.scrollX;\n\t\t\t\t\tconst scrollTopDelta = scrollTop - originScrollTop;\n\t\t\t\t\tconst scrollLeftDelta = scrollLeft - originScrollLeft;\n\t\t\t\t\tconst topDelta = pointerYDelta + scrollTopDelta;\n\t\t\t\t\tconst leftDelta = pointerXDelta + scrollLeftDelta;\n\t\t\t\t\tnode.style.top = `${ topDelta * inverted }px`;\n\t\t\t\t\tnode.style.left = `${ leftDelta * inverted }px`;\n\t\t\t\t}\n\n\t\t\t\tfunction end() {\n\t\t\t\t\townerDocument.removeEventListener( 'dragover', dragOver );\n\t\t\t\t\townerDocument.removeEventListener( 'dragend', end );\n\t\t\t\t\townerDocument.removeEventListener( 'drop', end );\n\t\t\t\t\townerDocument.removeEventListener( 'scroll', over );\n\t\t\t\t\tfor ( const [ property, value ] of Object.entries(\n\t\t\t\t\t\toriginalNodeProperties\n\t\t\t\t\t) ) {\n\t\t\t\t\t\tnode.style[ property ] = value;\n\t\t\t\t\t}\n\t\t\t\t\tclone.remove();\n\t\t\t\t\tnode.id = id;\n\t\t\t\t\tdragElement.remove();\n\t\t\t\t\tstopDraggingBlocks();\n\t\t\t\t\tdocument.body.classList.remove(\n\t\t\t\t\t\t'is-dragging-components-draggable'\n\t\t\t\t\t);\n\t\t\t\t\townerDocument.documentElement.classList.remove(\n\t\t\t\t\t\t'is-dragging'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\townerDocument.addEventListener( 'dragover', dragOver );\n\t\t\t\townerDocument.addEventListener( 'dragend', end );\n\t\t\t\townerDocument.addEventListener( 'drop', end );\n\t\t\t\townerDocument.addEventListener( 'scroll', over );\n\n\t\t\t\tstartDraggingBlocks( [ clientId ] );\n\t\t\t\t// Important because it hides the block toolbar.\n\t\t\t\tdocument.body.classList.add(\n\t\t\t\t\t'is-dragging-components-draggable'\n\t\t\t\t);\n\t\t\t\townerDocument.documentElement.classList.add( 'is-dragging' );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\t\tnode.addEventListener( 'dragstart', onDragStart );\n\n\t\t\t/**\n\t\t\t * Handles double-click events on section blocks to edit content only section.\n\t\t\t *\n\t\t\t * @param {MouseEvent} event Double-click event.\n\t\t\t */\n\t\t\tfunction onDoubleClick( event ) {\n\t\t\t\tconst isSection = isSectionBlock( clientId );\n\t\t\t\tconst block = getBlock( clientId );\n\t\t\t\tconst isSyncedPattern = isReusableBlock( block );\n\t\t\t\tconst isTemplatePartBlock = isTemplatePart( block );\n\t\t\t\tconst isAlreadyEditing = editedContentOnlySection === clientId;\n\n\t\t\t\tif (\n\t\t\t\t\t! isSection ||\n\t\t\t\t\tisAlreadyEditing ||\n\t\t\t\t\tisSyncedPattern ||\n\t\t\t\t\tisTemplatePartBlock\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\t\t\t\teditContentOnlySection( clientId );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'dblclick', onDoubleClick );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\t\tnode.removeEventListener( 'dragstart', onDragStart );\n\t\t\t\tnode.removeEventListener( 'dblclick', onDoubleClick );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tisSelected,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlock,\n\t\t\tisReusableBlock,\n\t\t\tisTemplatePart,\n\t\t\tremoveBlock,\n\t\t\tisZoomOut,\n\t\t\tresetZoomLevel,\n\t\t\thasMultiSelection,\n\t\t\tstartDraggingBlocks,\n\t\t\tstopDraggingBlocks,\n\t\t\tisSectionBlock,\n\t\t\teditedContentOnlySection,\n\t\t\teditContentOnlySection,\n\t\t]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB,s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aAAc;AAAA,MACrD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,56 +1,125 @@
|
|
|
1
1
|
// packages/block-editor/src/components/block-parent-selector/index.js
|
|
2
|
-
import { ToolbarButton } from "@wordpress/components";
|
|
2
|
+
import { ToolbarButton, ToolbarGroup } from "@wordpress/components";
|
|
3
3
|
import { useSelect, useDispatch } from "@wordpress/data";
|
|
4
|
-
import { __, sprintf } from "@wordpress/i18n";
|
|
4
|
+
import { __, _x, sprintf } from "@wordpress/i18n";
|
|
5
5
|
import { useRef } from "@wordpress/element";
|
|
6
|
+
import { getBlockType, hasBlockSupport } from "@wordpress/blocks";
|
|
7
|
+
import { plus } from "@wordpress/icons";
|
|
6
8
|
import useBlockDisplayInformation from "../use-block-display-information/index.mjs";
|
|
7
9
|
import BlockIcon from "../block-icon/index.mjs";
|
|
10
|
+
import Inserter from "../inserter/index.mjs";
|
|
8
11
|
import { useShowHoveredOrFocusedGestures } from "../block-toolbar/utils.mjs";
|
|
9
12
|
import { store as blockEditorStore } from "../../store/index.mjs";
|
|
10
13
|
import { unlock } from "../../lock-unlock.mjs";
|
|
11
|
-
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
15
|
function BlockParentSelector() {
|
|
13
16
|
const { selectBlock } = useDispatch(blockEditorStore);
|
|
14
|
-
const { parentClientId } = useSelect(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
const { parentClientId, nextSiblingClientId, showInserter } = useSelect(
|
|
18
|
+
(select) => {
|
|
19
|
+
const {
|
|
20
|
+
getBlockParents,
|
|
21
|
+
getSelectedBlockClientIds,
|
|
22
|
+
getParentSectionBlock,
|
|
23
|
+
getBlockName,
|
|
24
|
+
getNextBlockClientId
|
|
25
|
+
} = unlock(select(blockEditorStore));
|
|
26
|
+
const [selectedBlockClientId] = getSelectedBlockClientIds();
|
|
27
|
+
const parentSection = getParentSectionBlock(
|
|
28
|
+
selectedBlockClientId
|
|
29
|
+
);
|
|
30
|
+
const parents = getBlockParents(selectedBlockClientId);
|
|
31
|
+
const immediateParentClientId = parents[parents.length - 1];
|
|
32
|
+
const _parentClientId = parentSection ?? immediateParentClientId;
|
|
33
|
+
const parentBlockType = getBlockType(
|
|
34
|
+
getBlockName(_parentClientId)
|
|
35
|
+
);
|
|
36
|
+
const isTextFlowWrapper = parentBlockType?.merge || hasBlockSupport(parentBlockType, "__experimentalOnMerge");
|
|
37
|
+
return {
|
|
38
|
+
parentClientId: _parentClientId,
|
|
39
|
+
nextSiblingClientId: getNextBlockClientId(
|
|
40
|
+
selectedBlockClientId
|
|
41
|
+
),
|
|
42
|
+
// When the shown parent is a section further up the tree
|
|
43
|
+
// rather than the direct parent, its content is locked and
|
|
44
|
+
// nothing can be inserted, so no button.
|
|
45
|
+
showInserter: !!_parentClientId && _parentClientId === immediateParentClientId && !isTextFlowWrapper
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
[]
|
|
49
|
+
);
|
|
28
50
|
const blockInformation = useBlockDisplayInformation(parentClientId);
|
|
29
51
|
const nodeRef = useRef();
|
|
30
52
|
const showHoveredOrFocusedGestures = useShowHoveredOrFocusedGestures({
|
|
31
53
|
ref: nodeRef,
|
|
32
54
|
highlightParent: true
|
|
33
55
|
});
|
|
34
|
-
|
|
56
|
+
const parentButton = /* @__PURE__ */ jsx(
|
|
57
|
+
ToolbarButton,
|
|
58
|
+
{
|
|
59
|
+
className: "block-editor-block-parent-selector__button",
|
|
60
|
+
onClick: () => selectBlock(parentClientId),
|
|
61
|
+
label: sprintf(
|
|
62
|
+
/* translators: %s: Name of the block's parent. */
|
|
63
|
+
__("Select parent block: %s"),
|
|
64
|
+
blockInformation?.title
|
|
65
|
+
),
|
|
66
|
+
showTooltip: true,
|
|
67
|
+
icon: /* @__PURE__ */ jsx(BlockIcon, { icon: blockInformation?.icon })
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
return /* @__PURE__ */ jsxs(
|
|
35
71
|
"div",
|
|
36
72
|
{
|
|
37
73
|
className: "block-editor-block-parent-selector",
|
|
38
74
|
ref: nodeRef,
|
|
39
75
|
...showHoveredOrFocusedGestures,
|
|
40
|
-
children:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
76
|
+
children: [
|
|
77
|
+
!showInserter && parentButton,
|
|
78
|
+
showInserter && // A real toolbar group, so the buttons get the standard
|
|
79
|
+
// toolbar sizing, and the group overlaps the container
|
|
80
|
+
// border the way toolbar groups overlap the toolbar box.
|
|
81
|
+
/* @__PURE__ */ jsxs(ToolbarGroup, { children: [
|
|
82
|
+
parentButton,
|
|
83
|
+
/* @__PURE__ */ jsx(
|
|
84
|
+
Inserter,
|
|
85
|
+
{
|
|
86
|
+
position: "bottom right",
|
|
87
|
+
rootClientId: parentClientId,
|
|
88
|
+
clientId: nextSiblingClientId,
|
|
89
|
+
isAppender: !nextSiblingClientId,
|
|
90
|
+
__experimentalIsQuick: true,
|
|
91
|
+
renderToggle: ({
|
|
92
|
+
onToggle,
|
|
93
|
+
isOpen,
|
|
94
|
+
disabled,
|
|
95
|
+
blockTitle,
|
|
96
|
+
hasSingleBlockType
|
|
97
|
+
}) => /* @__PURE__ */ jsx(
|
|
98
|
+
ToolbarButton,
|
|
99
|
+
{
|
|
100
|
+
className: "block-editor-block-parent-selector__inserter",
|
|
101
|
+
onClick: onToggle,
|
|
102
|
+
"aria-expanded": isOpen,
|
|
103
|
+
disabled,
|
|
104
|
+
label: hasSingleBlockType ? sprintf(
|
|
105
|
+
// translators: %s: the name of the block when there is only one
|
|
106
|
+
_x(
|
|
107
|
+
"Add %s",
|
|
108
|
+
"directly add the only allowed block"
|
|
109
|
+
),
|
|
110
|
+
blockTitle.toLowerCase()
|
|
111
|
+
) : _x(
|
|
112
|
+
"Add block",
|
|
113
|
+
"Generic label for block inserter button"
|
|
114
|
+
),
|
|
115
|
+
showTooltip: true,
|
|
116
|
+
icon: plus
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
] })
|
|
122
|
+
]
|
|
54
123
|
},
|
|
55
124
|
parentClientId
|
|
56
125
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-parent-selector/index.js"],
|
|
4
|
-
"sourcesContent": ["import { ToolbarButton } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport useBlockDisplayInformation from '../use-block-display-information';\nimport BlockIcon from '../block-icon';\nimport { useShowHoveredOrFocusedGestures } from '../block-toolbar/utils';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Block parent selector component, displaying the hierarchy of the\n * current block selection as a single icon to \"go up\" a level.\n *\n * @return {Component} Parent block selector.\n */\nexport default function BlockParentSelector() {\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst { parentClientId } = useSelect(
|
|
5
|
-
"mappings": ";AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport { getBlockType, hasBlockSupport } from '@wordpress/blocks';\nimport { plus } from '@wordpress/icons';\nimport useBlockDisplayInformation from '../use-block-display-information';\nimport BlockIcon from '../block-icon';\nimport Inserter from '../inserter';\nimport { useShowHoveredOrFocusedGestures } from '../block-toolbar/utils';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Block parent selector component, displaying the hierarchy of the\n * current block selection as a single icon to \"go up\" a level.\n *\n * @return {Component} Parent block selector.\n */\nexport default function BlockParentSelector() {\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst { parentClientId, nextSiblingClientId, showInserter } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockParents,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetParentSectionBlock,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetNextBlockClientId,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\t\t\t// Not getSelectedBlockClientId: a text selection crossing into a\n\t\t\t// nested block resolves to the ancestor alone, but its selection\n\t\t\t// start and end differ.\n\t\t\tconst [ selectedBlockClientId ] = getSelectedBlockClientIds();\n\t\t\tconst parentSection = getParentSectionBlock(\n\t\t\t\tselectedBlockClientId\n\t\t\t);\n\t\t\tconst parents = getBlockParents( selectedBlockClientId );\n\t\t\tconst immediateParentClientId = parents[ parents.length - 1 ];\n\t\t\tconst _parentClientId = parentSection ?? immediateParentClientId;\n\t\t\tconst parentBlockType = getBlockType(\n\t\t\t\tgetBlockName( _parentClientId )\n\t\t\t);\n\t\t\t// A wrapper that merges with the text flow (list, quote) grows\n\t\t\t// by typing: Enter continues it, and users know that. Any\n\t\t\t// other parent gets a plus button to add a child; the Inserter\n\t\t\t// hides itself when nothing is insertable.\n\t\t\tconst isTextFlowWrapper =\n\t\t\t\tparentBlockType?.merge ||\n\t\t\t\thasBlockSupport( parentBlockType, '__experimentalOnMerge' );\n\t\t\treturn {\n\t\t\t\tparentClientId: _parentClientId,\n\t\t\t\tnextSiblingClientId: getNextBlockClientId(\n\t\t\t\t\tselectedBlockClientId\n\t\t\t\t),\n\t\t\t\t// When the shown parent is a section further up the tree\n\t\t\t\t// rather than the direct parent, its content is locked and\n\t\t\t\t// nothing can be inserted, so no button.\n\t\t\t\tshowInserter:\n\t\t\t\t\t!! _parentClientId &&\n\t\t\t\t\t_parentClientId === immediateParentClientId &&\n\t\t\t\t\t! isTextFlowWrapper,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst blockInformation = useBlockDisplayInformation( parentClientId );\n\n\t// Allows highlighting the parent block outline when focusing or hovering\n\t// the parent block selector within the child.\n\tconst nodeRef = useRef();\n\tconst showHoveredOrFocusedGestures = useShowHoveredOrFocusedGestures( {\n\t\tref: nodeRef,\n\t\thighlightParent: true,\n\t} );\n\n\tconst parentButton = (\n\t\t<ToolbarButton\n\t\t\tclassName=\"block-editor-block-parent-selector__button\"\n\t\t\tonClick={ () => selectBlock( parentClientId ) }\n\t\t\tlabel={ sprintf(\n\t\t\t\t/* translators: %s: Name of the block's parent. */\n\t\t\t\t__( 'Select parent block: %s' ),\n\t\t\t\tblockInformation?.title\n\t\t\t) }\n\t\t\tshowTooltip\n\t\t\ticon={ <BlockIcon icon={ blockInformation?.icon } /> }\n\t\t/>\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-parent-selector\"\n\t\t\tkey={ parentClientId }\n\t\t\tref={ nodeRef }\n\t\t\t{ ...showHoveredOrFocusedGestures }\n\t\t>\n\t\t\t{ ! showInserter && parentButton }\n\t\t\t{ showInserter && (\n\t\t\t\t// A real toolbar group, so the buttons get the standard\n\t\t\t\t// toolbar sizing, and the group overlaps the container\n\t\t\t\t// border the way toolbar groups overlap the toolbar box.\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ parentButton }\n\t\t\t\t\t<Inserter\n\t\t\t\t\t\tposition=\"bottom right\"\n\t\t\t\t\t\trootClientId={ parentClientId }\n\t\t\t\t\t\tclientId={ nextSiblingClientId }\n\t\t\t\t\t\tisAppender={ ! nextSiblingClientId }\n\t\t\t\t\t\t__experimentalIsQuick\n\t\t\t\t\t\trenderToggle={ ( {\n\t\t\t\t\t\t\tonToggle,\n\t\t\t\t\t\t\tisOpen,\n\t\t\t\t\t\t\tdisabled,\n\t\t\t\t\t\t\tblockTitle,\n\t\t\t\t\t\t\thasSingleBlockType,\n\t\t\t\t\t\t} ) => (\n\t\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-parent-selector__inserter\"\n\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\thasSingleBlockType\n\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t// translators: %s: the name of the block when there is only one\n\t\t\t\t\t\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'Add %s',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'directly add the only allowed block'\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\tblockTitle.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t: _x(\n\t\t\t\t\t\t\t\t\t\t\t\t'Add block',\n\t\t\t\t\t\t\t\t\t\t\t\t'Generic label for block inserter button'\n\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\t\t\ticon={ plus }\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</ToolbarGroup>\n\t\t\t) }\n\t\t</div>\n\t);\n}\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QAAM,eACL;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,SAAU,MAAM,YAAa,cAAe;AAAA,MAC5C,OAAQ;AAAA;AAAA,QAEP,GAAI,yBAA0B;AAAA,QAC9B,kBAAkB;AAAA,MACnB;AAAA,MACA,aAAW;AAAA,MACX,MAAO,oBAAC,aAAU,MAAO,kBAAkB,MAAO;AAAA;AAAA,EACnD;AAGD,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MAEV,KAAM;AAAA,MACJ,GAAG;AAAA,MAEH;AAAA,SAAE,gBAAgB;AAAA,QAClB;AAAA;AAAA;AAAA,QAID,qBAAC,gBACE;AAAA;AAAA,UACF;AAAA,YAAC;AAAA;AAAA,cACA,UAAS;AAAA,cACT,cAAe;AAAA,cACf,UAAW;AAAA,cACX,YAAa,CAAE;AAAA,cACf,uBAAqB;AAAA,cACrB,cAAe,CAAE;AAAA,gBAChB;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,cACD,MACC;AAAA,gBAAC;AAAA;AAAA,kBACA,WAAU;AAAA,kBACV,SAAU;AAAA,kBACV,iBAAgB;AAAA,kBAChB;AAAA,kBACA,OACC,qBACG;AAAA;AAAA,oBAEA;AAAA,sBACC;AAAA,sBACA;AAAA,oBACD;AAAA,oBACA,WAAW,YAAY;AAAA,kBACvB,IACA;AAAA,oBACA;AAAA,oBACA;AAAA,kBACA;AAAA,kBAEJ,aAAW;AAAA,kBACX,MAAO;AAAA;AAAA,cACR;AAAA;AAAA,UAEF;AAAA,WACD;AAAA;AAAA;AAAA,IAjDK;AAAA,EAmDP;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -72,9 +72,9 @@ function BlockPopoverInbetween({
|
|
|
72
72
|
left = nearestSide === "left" ? targetRect.left - 2 : targetRect.right - 2;
|
|
73
73
|
} else if (isVertical) {
|
|
74
74
|
top = previousRect ? previousRect.bottom : nextRect.top;
|
|
75
|
-
width = previousRect ? previousRect.width : nextRect.width;
|
|
75
|
+
width = nextRect && previousRect ? (previousRect.width + nextRect.width) / 2 : (previousRect || nextRect).width;
|
|
76
76
|
height = nextRect && previousRect ? nextRect.top - previousRect.bottom : 0;
|
|
77
|
-
left = previousRect ? previousRect.left : nextRect.left;
|
|
77
|
+
left = nextRect && previousRect ? (previousRect.left + nextRect.left) / 2 : (previousRect || nextRect).left;
|
|
78
78
|
} else {
|
|
79
79
|
top = previousRect ? previousRect.top : nextRect.top;
|
|
80
80
|
height = previousRect ? previousRect.height : nextRect.height;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-popover/inbetween.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo, useReducer, useLayoutEffect } from '@wordpress/element';\nimport { Popover } from '@wordpress/components';\nimport { isRTL } from '@wordpress/i18n';\nimport { store as blockEditorStore } from '../../store';\nimport { useBlockElement } from '../block-list/use-block-props/use-block-refs';\nimport usePopoverScroll from './use-popover-scroll';\n\nconst MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;\n\nfunction BlockPopoverInbetween( {\n\tpreviousClientId,\n\tnextClientId,\n\tchildren,\n\t__unstablePopoverSlot,\n\t__unstableContentRef,\n\toperation = 'insert',\n\tnearestSide = 'right',\n\t...props\n} ) {\n\t// This is a temporary hack to get the inbetween inserter to recompute properly.\n\tconst [ popoverRecomputeCounter, forcePopoverRecompute ] = useReducer(\n\t\t// Module is there to make sure that the counter doesn't overflow.\n\t\t( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,\n\t\t0\n\t);\n\n\tconst { orientation, rootClientId, isVisible } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tisBlockVisible,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst _rootClientId = getBlockRootClientId(\n\t\t\t\tpreviousClientId ?? nextClientId\n\t\t\t);\n\t\t\treturn {\n\t\t\t\torientation:\n\t\t\t\t\tgetBlockListSettings( _rootClientId )?.orientation ||\n\t\t\t\t\t'vertical',\n\t\t\t\trootClientId: _rootClientId,\n\t\t\t\tisVisible:\n\t\t\t\t\tisBlockVisible( previousClientId ) &&\n\t\t\t\t\tisBlockVisible( nextClientId ),\n\t\t\t};\n\t\t},\n\t\t[ previousClientId, nextClientId ]\n\t);\n\tconst previousElement = useBlockElement( previousClientId );\n\tconst nextElement = useBlockElement( nextClientId );\n\tconst isVertical = orientation === 'vertical';\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif (\n\t\t\t// popoverRecomputeCounter is by definition always equal or greater than 0.\n\t\t\t// This check is only there to satisfy the correctness of the\n\t\t\t// exhaustive-deps rule for the `useMemo` hook.\n\t\t\tpopoverRecomputeCounter < 0 ||\n\t\t\t( ! previousElement && ! nextElement ) ||\n\t\t\t! isVisible\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst contextElement =\n\t\t\toperation === 'group'\n\t\t\t\t? nextElement || previousElement\n\t\t\t\t: previousElement || nextElement;\n\n\t\treturn {\n\t\t\tcontextElement,\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst previousRect = previousElement\n\t\t\t\t\t? previousElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\t\t\t\tconst nextRect = nextElement\n\t\t\t\t\t? nextElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\n\t\t\t\tlet left = 0;\n\t\t\t\tlet top = 0;\n\t\t\t\tlet width = 0;\n\t\t\t\tlet height = 0;\n\n\t\t\t\tif ( operation === 'group' ) {\n\t\t\t\t\tconst targetRect = nextRect || previousRect;\n\t\t\t\t\ttop = targetRect.top;\n\t\t\t\t\t// No spacing is likely around blocks in this operation.\n\t\t\t\t\t// So width of the inserter containing rect is set to 0.\n\t\t\t\t\twidth = 0;\n\t\t\t\t\theight = targetRect.bottom - targetRect.top;\n\t\t\t\t\t// Popover calculates its distance from mid-block so some\n\t\t\t\t\t// adjustments are needed to make it appear in the right place.\n\t\t\t\t\tleft =\n\t\t\t\t\t\tnearestSide === 'left'\n\t\t\t\t\t\t\t? targetRect.left - 2\n\t\t\t\t\t\t\t: targetRect.right - 2;\n\t\t\t\t} else if ( isVertical ) {\n\t\t\t\t\t// vertical\n\t\t\t\t\ttop = previousRect ? previousRect.bottom : nextRect.top;\n\t\t\t\t\twidth
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,SAAS,YAAY,uBAAuB;AACrD,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,uBAAuB;AAChC,OAAO,sBAAsB;
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo, useReducer, useLayoutEffect } from '@wordpress/element';\nimport { Popover } from '@wordpress/components';\nimport { isRTL } from '@wordpress/i18n';\nimport { store as blockEditorStore } from '../../store';\nimport { useBlockElement } from '../block-list/use-block-props/use-block-refs';\nimport usePopoverScroll from './use-popover-scroll';\n\nconst MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;\n\nfunction BlockPopoverInbetween( {\n\tpreviousClientId,\n\tnextClientId,\n\tchildren,\n\t__unstablePopoverSlot,\n\t__unstableContentRef,\n\toperation = 'insert',\n\tnearestSide = 'right',\n\t...props\n} ) {\n\t// This is a temporary hack to get the inbetween inserter to recompute properly.\n\tconst [ popoverRecomputeCounter, forcePopoverRecompute ] = useReducer(\n\t\t// Module is there to make sure that the counter doesn't overflow.\n\t\t( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,\n\t\t0\n\t);\n\n\tconst { orientation, rootClientId, isVisible } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tisBlockVisible,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst _rootClientId = getBlockRootClientId(\n\t\t\t\tpreviousClientId ?? nextClientId\n\t\t\t);\n\t\t\treturn {\n\t\t\t\torientation:\n\t\t\t\t\tgetBlockListSettings( _rootClientId )?.orientation ||\n\t\t\t\t\t'vertical',\n\t\t\t\trootClientId: _rootClientId,\n\t\t\t\tisVisible:\n\t\t\t\t\tisBlockVisible( previousClientId ) &&\n\t\t\t\t\tisBlockVisible( nextClientId ),\n\t\t\t};\n\t\t},\n\t\t[ previousClientId, nextClientId ]\n\t);\n\tconst previousElement = useBlockElement( previousClientId );\n\tconst nextElement = useBlockElement( nextClientId );\n\tconst isVertical = orientation === 'vertical';\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif (\n\t\t\t// popoverRecomputeCounter is by definition always equal or greater than 0.\n\t\t\t// This check is only there to satisfy the correctness of the\n\t\t\t// exhaustive-deps rule for the `useMemo` hook.\n\t\t\tpopoverRecomputeCounter < 0 ||\n\t\t\t( ! previousElement && ! nextElement ) ||\n\t\t\t! isVisible\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst contextElement =\n\t\t\toperation === 'group'\n\t\t\t\t? nextElement || previousElement\n\t\t\t\t: previousElement || nextElement;\n\n\t\treturn {\n\t\t\tcontextElement,\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst previousRect = previousElement\n\t\t\t\t\t? previousElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\t\t\t\tconst nextRect = nextElement\n\t\t\t\t\t? nextElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\n\t\t\t\tlet left = 0;\n\t\t\t\tlet top = 0;\n\t\t\t\tlet width = 0;\n\t\t\t\tlet height = 0;\n\n\t\t\t\tif ( operation === 'group' ) {\n\t\t\t\t\tconst targetRect = nextRect || previousRect;\n\t\t\t\t\ttop = targetRect.top;\n\t\t\t\t\t// No spacing is likely around blocks in this operation.\n\t\t\t\t\t// So width of the inserter containing rect is set to 0.\n\t\t\t\t\twidth = 0;\n\t\t\t\t\theight = targetRect.bottom - targetRect.top;\n\t\t\t\t\t// Popover calculates its distance from mid-block so some\n\t\t\t\t\t// adjustments are needed to make it appear in the right place.\n\t\t\t\t\tleft =\n\t\t\t\t\t\tnearestSide === 'left'\n\t\t\t\t\t\t\t? targetRect.left - 2\n\t\t\t\t\t\t\t: targetRect.right - 2;\n\t\t\t\t} else if ( isVertical ) {\n\t\t\t\t\t// vertical\n\t\t\t\t\ttop = previousRect ? previousRect.bottom : nextRect.top;\n\t\t\t\t\twidth =\n\t\t\t\t\t\tnextRect && previousRect\n\t\t\t\t\t\t\t? ( previousRect.width + nextRect.width ) / 2\n\t\t\t\t\t\t\t: ( previousRect || nextRect ).width;\n\t\t\t\t\theight =\n\t\t\t\t\t\tnextRect && previousRect\n\t\t\t\t\t\t\t? nextRect.top - previousRect.bottom\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tleft =\n\t\t\t\t\t\tnextRect && previousRect\n\t\t\t\t\t\t\t? ( previousRect.left + nextRect.left ) / 2\n\t\t\t\t\t\t\t: ( previousRect || nextRect ).left;\n\t\t\t\t} else {\n\t\t\t\t\ttop = previousRect ? previousRect.top : nextRect.top;\n\t\t\t\t\theight = previousRect\n\t\t\t\t\t\t? previousRect.height\n\t\t\t\t\t\t: nextRect.height;\n\n\t\t\t\t\tif ( isRTL() ) {\n\t\t\t\t\t\t// non vertical, rtl\n\t\t\t\t\t\tleft = nextRect ? nextRect.right : previousRect.left;\n\t\t\t\t\t\twidth =\n\t\t\t\t\t\t\tpreviousRect && nextRect\n\t\t\t\t\t\t\t\t? previousRect.left - nextRect.right\n\t\t\t\t\t\t\t\t: 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// non vertical, ltr\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.right\n\t\t\t\t\t\t\t: nextRect.left;\n\t\t\t\t\t\twidth =\n\t\t\t\t\t\t\tpreviousRect && nextRect\n\t\t\t\t\t\t\t\t? nextRect.left - previousRect.right\n\t\t\t\t\t\t\t\t: 0;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Avoid a negative width which happens when the next rect\n\t\t\t\t\t// is on the next line.\n\t\t\t\t\twidth = Math.max( width, 0 );\n\t\t\t\t}\n\n\t\t\t\treturn new window.DOMRect( left, top, width, height );\n\t\t\t},\n\t\t};\n\t}, [\n\t\tpreviousElement,\n\t\tnextElement,\n\t\tpopoverRecomputeCounter,\n\t\tisVertical,\n\t\tisVisible,\n\t\toperation,\n\t\tnearestSide,\n\t] );\n\n\tconst popoverScrollRef = usePopoverScroll( __unstableContentRef );\n\n\t// This is only needed for a smooth transition when moving blocks.\n\t// When blocks are moved up/down, their position can be set by\n\t// updating the `transform` property manually (i.e. without using CSS\n\t// transitions or animations). The animation, which can also scroll the block\n\t// editor, can sometimes cause the position of the Popover to get out of sync.\n\t// A MutationObserver is therefore used to make sure that changes to the\n\t// selectedElement's attribute (i.e. `transform`) can be tracked and used to\n\t// trigger the Popover to rerender.\n\tuseLayoutEffect( () => {\n\t\tif ( ! previousElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( forcePopoverRecompute );\n\t\tobserver.observe( previousElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ previousElement ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! nextElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( forcePopoverRecompute );\n\t\tobserver.observe( nextElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ nextElement ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! previousElement ) {\n\t\t\treturn;\n\t\t}\n\t\tpreviousElement.ownerDocument.defaultView.addEventListener(\n\t\t\t'resize',\n\t\t\tforcePopoverRecompute\n\t\t);\n\t\treturn () => {\n\t\t\tpreviousElement.ownerDocument.defaultView?.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tforcePopoverRecompute\n\t\t\t);\n\t\t};\n\t}, [ previousElement ] );\n\n\t// If there's either a previous or a next element, show the inbetween popover.\n\t// Note that drag and drop uses the inbetween popover to show the drop indicator\n\t// before the first block and after the last block.\n\tif ( ( ! previousElement && ! nextElement ) || ! isVisible ) {\n\t\treturn null;\n\t}\n\n\t// While ideally it would be enough to capture the\n\t// bubbling focus event from the Inserter, due to the\n\t// characteristics of click focusing of `button`s in\n\t// Firefox and Safari, it is not reliable.\n\t//\n\t// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\treturn (\n\t\t<Popover\n\t\t\tref={ popoverScrollRef }\n\t\t\tanimate={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ false }\n\t\t\t// Render in the old slot if needed for backward compatibility,\n\t\t\t// otherwise render in place (not in the default popover slot).\n\t\t\t__unstableSlotName={ __unstablePopoverSlot }\n\t\t\tinline={ ! __unstablePopoverSlot }\n\t\t\t// Forces a remount of the popover when its position changes\n\t\t\t// This makes sure the popover doesn't animate from its previous position.\n\t\t\tkey={ nextClientId + '--' + rootClientId }\n\t\t\t{ ...props }\n\t\t\tclassName={ clsx(\n\t\t\t\t'block-editor-block-popover',\n\t\t\t\t'block-editor-block-popover__inbetween',\n\t\t\t\tprops.className\n\t\t\t) }\n\t\t\tresize={ false }\n\t\t\tflip={ false }\n\t\t\tplacement=\"overlay\"\n\t\t\tvariant=\"unstyled\"\n\t\t>\n\t\t\t<div className=\"block-editor-block-popover__inbetween-container\">\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</Popover>\n\t);\n}\n\nexport default BlockPopoverInbetween;\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,SAAS,YAAY,uBAAuB;AACrD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ACZ,eAAS,WAAW;AAAA,IACrB;AAAA,EACD,GAAG,CAAE,eAAgB,CAAE;AAEvB,kBAAiB,MAAM;AACtB,QAAK,CAAE,aAAc;AACpB;AAAA,IACD;AACA,UAAM,WAAW,IAAI,OAAO,iBAAkB,qBAAsB;AACpE,aAAS,QAAS,aAAa,EAAE,YAAY,KAAK,CAAE;AAEpD,WAAO,MAAM;AACZ,eAAS,WAAW;AAAA,IACrB;AAAA,EACD,GAAG,CAAE,WAAY,CAAE;AAEnB,kBAAiB,MAAM;AACtB,QAAK,CAAE,iBAAkB;AACxB;AAAA,IACD;AACA,oBAAgB,cAAc,YAAY;AAAA,MACzC;AAAA,MACA;AAAA,IACD;AACA,WAAO,MAAM;AACZ,sBAAgB,cAAc,aAAa;AAAA,QAC1C;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,eAAgB,CAAE;AAKvB,MAAO,CAAE,mBAAmB,CAAE,eAAiB,CAAE,WAAY;AAC5D,WAAO;AAAA,EACR;AAQA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,KAAM;AAAA,MACN,SAAU;AAAA,MACV,QAAS;AAAA,MACT,cAAe;AAAA,MAGf,oBAAqB;AAAA,MACrB,QAAS,CAAE;AAAA,MAIT,GAAG;AAAA,MACL,WAAY;AAAA,QACX;AAAA,QACA;AAAA,QACA,MAAM;AAAA,MACP;AAAA,MACA,QAAS;AAAA,MACT,MAAO;AAAA,MACP,WAAU;AAAA,MACV,SAAQ;AAAA,MAER,8BAAC,SAAI,WAAU,mDACZ,UACH;AAAA;AAAA,IAdM,eAAe,OAAO;AAAA,EAe7B;AAEF;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -47,8 +47,6 @@ function BlockPreview({
|
|
|
47
47
|
const settings = useMemo(
|
|
48
48
|
() => ({
|
|
49
49
|
...originalSettings,
|
|
50
|
-
focusMode: false,
|
|
51
|
-
// Disable "Spotlight mode".
|
|
52
50
|
isPreviewMode: true
|
|
53
51
|
}),
|
|
54
52
|
[originalSettings]
|
|
@@ -89,8 +87,6 @@ function useBlockPreview({ blocks, props = {}, layout }) {
|
|
|
89
87
|
...originalSettings,
|
|
90
88
|
styles: void 0,
|
|
91
89
|
// Clear styles included by the parent settings, as they are already output by the parent's EditorStyles.
|
|
92
|
-
focusMode: false,
|
|
93
|
-
// Disable "Spotlight mode".
|
|
94
90
|
isPreviewMode: true
|
|
95
91
|
}),
|
|
96
92
|
[originalSettings]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-preview/index.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport { useDisabled, useMergeRefs } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { memo, useMemo } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { ExperimentalBlockEditorProvider } from '../provider';\nimport AutoHeightBlockPreview from './auto';\nimport EditorStyles from '../editor-styles';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockListItems } from '../block-list';\nimport { Async } from './async';\n\nconst EMPTY_ADDITIONAL_STYLES = [];\n\nexport function BlockPreview( {\n\tblocks,\n\tviewportWidth = 1200,\n\tminHeight,\n\tadditionalStyles = EMPTY_ADDITIONAL_STYLES,\n\t// Deprecated props:\n\t__experimentalMinHeight,\n\t__experimentalPadding,\n} ) {\n\tif ( __experimentalMinHeight ) {\n\t\tminHeight = __experimentalMinHeight;\n\t\tdeprecated( 'The __experimentalMinHeight prop', {\n\t\t\tsince: '6.2',\n\t\t\tversion: '6.4',\n\t\t\talternative: 'minHeight',\n\t\t} );\n\t}\n\tif ( __experimentalPadding ) {\n\t\tadditionalStyles = [\n\t\t\t...additionalStyles,\n\t\t\t{ css: `body { padding: ${ __experimentalPadding }px; }` },\n\t\t];\n\t\tdeprecated( 'The __experimentalPadding prop of BlockPreview', {\n\t\t\tsince: '6.2',\n\t\t\tversion: '6.4',\n\t\t\talternative: 'additionalStyles',\n\t\t} );\n\t}\n\n\tconst originalSettings = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings(),\n\t\t[]\n\t);\n\tconst settings = useMemo(\n\t\t() => ( {\n\t\t\t...originalSettings,\n\t\t\
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,aAAa,oBAAoB;AAC1C,SAAS,iBAAiB;AAC1B,SAAS,MAAM,eAAe;AAC9B,OAAO,gBAAgB;AACvB,SAAS,uCAAuC;AAChD,OAAO,4BAA4B;AACnC,OAAO,kBAAkB;AACzB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,sBAAsB;AAC/B,SAAS,aAAa;
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport { useDisabled, useMergeRefs } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { memo, useMemo } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { ExperimentalBlockEditorProvider } from '../provider';\nimport AutoHeightBlockPreview from './auto';\nimport EditorStyles from '../editor-styles';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockListItems } from '../block-list';\nimport { Async } from './async';\n\nconst EMPTY_ADDITIONAL_STYLES = [];\n\nexport function BlockPreview( {\n\tblocks,\n\tviewportWidth = 1200,\n\tminHeight,\n\tadditionalStyles = EMPTY_ADDITIONAL_STYLES,\n\t// Deprecated props:\n\t__experimentalMinHeight,\n\t__experimentalPadding,\n} ) {\n\tif ( __experimentalMinHeight ) {\n\t\tminHeight = __experimentalMinHeight;\n\t\tdeprecated( 'The __experimentalMinHeight prop', {\n\t\t\tsince: '6.2',\n\t\t\tversion: '6.4',\n\t\t\talternative: 'minHeight',\n\t\t} );\n\t}\n\tif ( __experimentalPadding ) {\n\t\tadditionalStyles = [\n\t\t\t...additionalStyles,\n\t\t\t{ css: `body { padding: ${ __experimentalPadding }px; }` },\n\t\t];\n\t\tdeprecated( 'The __experimentalPadding prop of BlockPreview', {\n\t\t\tsince: '6.2',\n\t\t\tversion: '6.4',\n\t\t\talternative: 'additionalStyles',\n\t\t} );\n\t}\n\n\tconst originalSettings = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings(),\n\t\t[]\n\t);\n\tconst settings = useMemo(\n\t\t() => ( {\n\t\t\t...originalSettings,\n\t\t\tisPreviewMode: true,\n\t\t} ),\n\t\t[ originalSettings ]\n\t);\n\tconst renderedBlocks = useMemo(\n\t\t() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),\n\t\t[ blocks ]\n\t);\n\n\tif ( ! blocks || blocks.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ExperimentalBlockEditorProvider\n\t\t\tvalue={ renderedBlocks }\n\t\t\tsettings={ settings }\n\t\t>\n\t\t\t<AutoHeightBlockPreview\n\t\t\t\tviewportWidth={ viewportWidth }\n\t\t\t\tminHeight={ minHeight }\n\t\t\t\tadditionalStyles={ additionalStyles }\n\t\t\t/>\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n}\n\nconst MemoizedBlockPreview = memo( BlockPreview );\n\nMemoizedBlockPreview.Async = Async;\n\n/**\n * BlockPreview renders a preview of a block or array of blocks.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-preview/README.md\n *\n * @param {Object} preview options for how the preview should be shown\n * @param {Array|Object} preview.blocks A block instance (object) or an array of blocks to be previewed.\n * @param {number} preview.viewportWidth Width of the preview container in pixels. Controls at what size the blocks will be rendered inside the preview. Default: 700.\n *\n * @return {Component} The component to be rendered.\n */\nexport default MemoizedBlockPreview;\n\n/**\n * This hook is used to lightly mark an element as a block preview wrapper\n * element. Call this hook and pass the returned props to the element to mark as\n * a block preview wrapper, automatically rendering inner blocks as children. If\n * you define a ref for the element, it is important to pass the ref to this\n * hook, which the hook in turn will pass to the component through the props it\n * returns. Optionally, you can also pass any other props through this hook, and\n * they will be merged and returned.\n *\n * @param {Object} options Preview options.\n * @param {WPBlock[]} options.blocks Block objects.\n * @param {Object} options.props Optional. Props to pass to the element. Must contain\n * the ref if one is defined.\n * @param {Object} options.layout Layout settings to be used in the preview.\n */\nexport function useBlockPreview( { blocks, props = {}, layout } ) {\n\tconst originalSettings = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings(),\n\t\t[]\n\t);\n\tconst settings = useMemo(\n\t\t() => ( {\n\t\t\t...originalSettings,\n\t\t\tstyles: undefined, // Clear styles included by the parent settings, as they are already output by the parent's EditorStyles.\n\t\t\tisPreviewMode: true,\n\t\t} ),\n\t\t[ originalSettings ]\n\t);\n\tconst disabledRef = useDisabled();\n\tconst ref = useMergeRefs( [ props.ref, disabledRef ] );\n\tconst renderedBlocks = useMemo(\n\t\t() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),\n\t\t[ blocks ]\n\t);\n\n\tconst children = (\n\t\t<ExperimentalBlockEditorProvider\n\t\t\tvalue={ renderedBlocks }\n\t\t\tsettings={ settings }\n\t\t>\n\t\t\t<EditorStyles />\n\t\t\t<BlockListItems renderAppender={ false } layout={ layout } />\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n\n\treturn {\n\t\t...props,\n\t\tref,\n\t\tclassName: clsx(\n\t\t\tprops.className,\n\t\t\t'block-editor-block-preview__live-content',\n\t\t\t'components-disabled'\n\t\t),\n\t\tchildren: blocks?.length ? children : null,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,aAAa,oBAAoB;AAC1C,SAAS,iBAAiB;AAC1B,SAAS,MAAM,eAAe;AAC9B,OAAO,gBAAgB;AACvB,SAAS,uCAAuC;AAChD,OAAO,4BAA4B;AACnC,OAAO,kBAAkB;AACzB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AA0DnB,cA8DD,YA9DC;AAxDH,IAAM,0BAA0B,CAAC;AAE1B,SAAS,aAAc;AAAA,EAC7B;AAAA,EACA,gBAAgB;AAAA,E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