@wordpress/block-editor 12.0.0 → 12.1.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 +4 -0
- package/README.md +1 -1
- package/build/components/block-controls/slot.js +12 -4
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-controls/slot.native.js +10 -1
- package/build/components/block-controls/slot.native.js.map +1 -1
- package/build/components/block-draggable/index.js +11 -7
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-draggable/use-scroll-when-dragging.js +2 -2
- package/build/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
- package/build/components/block-list/block-invalid-warning.native.js +15 -7
- package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build/components/block-list/block-list-item-cell.native.js +15 -2
- package/build/components/block-list/block-list-item-cell.native.js.map +1 -1
- package/build/components/block-list/block-list-item.native.js +158 -195
- package/build/components/block-list/block-list-item.native.js.map +1 -1
- package/build/components/block-list/block-outline.native.js +57 -0
- package/build/components/block-list/block-outline.native.js.map +1 -0
- package/build/components/block-list/block.native.js +343 -299
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +202 -298
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/insertion-point.native.js +4 -2
- package/build/components/block-list/insertion-point.native.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +8 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +15 -4
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +17 -62
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +3 -8
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build/components/global-styles/advanced-panel.js +86 -0
- package/build/components/global-styles/advanced-panel.js.map +1 -0
- package/build/components/global-styles/color-panel.js +4 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +6 -6
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +1 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +24 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +1 -1
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +27 -4
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +30 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +24 -8
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +5 -0
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/fill.js +1 -1
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +1 -1
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/slot.js +3 -6
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls/slot.native.js +1 -1
- package/build/components/inspector-controls/slot.native.js.map +1 -1
- package/build/components/line-height-control/index.js +7 -2
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/link-control/use-internal-input-value.js +9 -8
- package/build/components/link-control/use-internal-input-value.js.map +1 -1
- package/build/components/list-view/block-contents.js +7 -2
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block-select-button.js +2 -1
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +4 -4
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/index.js +32 -18
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +163 -11
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-placeholder/index.js +68 -7
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/multi-selection-inspector/index.js +2 -2
- package/build/components/multi-selection-inspector/index.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +3 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build/components/preview-options/index.js +6 -1
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/url-input/index.js +1 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/hooks/align.js +1 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/border.js +1 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +1 -1
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/content-lock-ui.js +8 -12
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/duotone.js +1 -1
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.native.js +8 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/layout.js +2 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/position.js +1 -1
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/style.js +1 -1
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-editor-wrapper-styles.native.js +255 -0
- package/build/hooks/use-editor-wrapper-styles.native.js.map +1 -0
- package/build/hooks/use-typography-props.js +14 -10
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/index.native.js +31 -0
- package/build/index.native.js.map +1 -0
- package/build/utils/use-should-contextual-toolbar-show.js +16 -12
- package/build/utils/use-should-contextual-toolbar-show.js.map +1 -1
- package/build-module/components/block-controls/slot.js +11 -4
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-controls/slot.native.js +9 -1
- package/build-module/components/block-controls/slot.native.js.map +1 -1
- package/build-module/components/block-draggable/index.js +10 -6
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-draggable/use-scroll-when-dragging.js +2 -2
- package/build-module/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
- package/build-module/components/block-list/block-invalid-warning.native.js +16 -8
- package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build-module/components/block-list/block-list-item-cell.native.js +13 -2
- package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -1
- package/build-module/components/block-list/block-list-item.native.js +160 -190
- package/build-module/components/block-list/block-list-item.native.js.map +1 -1
- package/build-module/components/block-list/block-outline.native.js +44 -0
- package/build-module/components/block-list/block-outline.native.js.map +1 -0
- package/build-module/components/block-list/block.native.js +341 -298
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +203 -293
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/insertion-point.native.js +4 -2
- package/build-module/components/block-list/insertion-point.native.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +8 -9
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +13 -5
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +18 -62
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +3 -7
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build-module/components/global-styles/advanced-panel.js +74 -0
- package/build-module/components/global-styles/advanced-panel.js.map +1 -0
- package/build-module/components/global-styles/color-panel.js +5 -2
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +6 -6
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +1 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +3 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +1 -1
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +25 -4
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +25 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +24 -8
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -0
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +1 -1
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +1 -1
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +4 -7
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls/slot.native.js +1 -1
- package/build-module/components/inspector-controls/slot.native.js.map +1 -1
- package/build-module/components/line-height-control/index.js +7 -2
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/link-control/use-internal-input-value.js +9 -8
- package/build-module/components/link-control/use-internal-input-value.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +7 -3
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +2 -1
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +4 -4
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/index.js +32 -18
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +160 -11
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +66 -7
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/multi-selection-inspector/index.js +2 -2
- package/build-module/components/multi-selection-inspector/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +3 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build-module/components/preview-options/index.js +7 -2
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/url-input/index.js +1 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/hooks/align.js +1 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/border.js +1 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +1 -1
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +8 -11
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/duotone.js +1 -1
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/layout.js +2 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/position.js +1 -1
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/style.js +1 -1
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-editor-wrapper-styles.native.js +242 -0
- package/build-module/hooks/use-editor-wrapper-styles.native.js.map +1 -0
- package/build-module/hooks/use-typography-props.js +14 -10
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/index.native.js +6 -0
- package/build-module/index.native.js.map +1 -0
- package/build-module/utils/use-should-contextual-toolbar-show.js +16 -12
- package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -1
- package/build-style/content-rtl.css +0 -1
- package/build-style/content.css +0 -1
- package/build-style/style-rtl.css +37 -13
- package/build-style/style.css +37 -13
- package/package.json +31 -31
- package/src/components/block-breadcrumb/style.scss +2 -1
- package/src/components/block-controls/slot.js +8 -4
- package/src/components/block-controls/slot.native.js +6 -1
- package/src/components/block-draggable/index.js +10 -6
- package/src/components/block-draggable/use-scroll-when-dragging.js +8 -2
- package/src/components/block-list/block-invalid-warning.native.js +17 -9
- package/src/components/block-list/block-list-item-cell.native.js +10 -1
- package/src/components/block-list/block-list-item.native.js +180 -208
- package/src/components/block-list/block-outline.native.js +58 -0
- package/src/components/block-list/block.native.js +564 -523
- package/src/components/block-list/content.scss +0 -1
- package/src/components/block-list/index.native.js +229 -298
- package/src/components/block-list/insertion-point.native.js +2 -2
- package/src/components/block-list/test/block-invalid-warning.native.js +48 -0
- package/src/components/block-list/test/index.native.js +205 -0
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -1
- package/src/components/block-pattern-setup/style.scss +1 -4
- package/src/components/block-patterns-list/style.scss +1 -4
- package/src/components/block-settings-menu/block-settings-dropdown.js +10 -17
- package/src/components/block-settings-menu-controls/index.js +24 -4
- package/src/components/block-styles/style.scss +4 -4
- package/src/components/block-tools/block-contextual-toolbar.js +28 -62
- package/src/components/block-tools/selected-block-popover.js +3 -5
- package/src/components/block-tools/style.scss +8 -0
- package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +16 -2
- package/src/components/global-styles/advanced-panel.js +82 -0
- package/src/components/global-styles/color-panel.js +6 -1
- package/src/components/global-styles/dimensions-panel.js +6 -6
- package/src/components/global-styles/hooks.js +1 -5
- package/src/components/global-styles/index.js +6 -1
- package/src/components/global-styles/style.scss +14 -0
- package/src/components/global-styles/test/utils.js +57 -1
- package/src/components/global-styles/typography-panel.js +1 -1
- package/src/components/global-styles/use-global-styles-output.js +21 -3
- package/src/components/global-styles/utils.js +27 -0
- package/src/components/image-editor/use-save-image.js +20 -9
- package/src/components/inserter-draggable-blocks/index.js +4 -0
- package/src/components/inspector-controls/fill.js +1 -1
- package/src/components/inspector-controls/fill.native.js +1 -1
- package/src/components/inspector-controls/slot.js +4 -9
- package/src/components/inspector-controls/slot.native.js +1 -1
- package/src/components/line-height-control/index.js +7 -2
- package/src/components/line-height-control/stories/index.js +1 -1
- package/src/components/link-control/test/index.js +42 -0
- package/src/components/link-control/use-internal-input-value.js +8 -7
- package/src/components/list-view/block-contents.js +26 -20
- package/src/components/list-view/block-select-button.js +5 -1
- package/src/components/list-view/block.js +5 -2
- package/src/components/list-view/index.js +26 -14
- package/src/components/list-view/style.scss +5 -2
- package/src/components/list-view/test/use-list-view-drop-zone.js +88 -12
- package/src/components/list-view/use-list-view-drop-zone.js +194 -11
- package/src/components/media-placeholder/index.js +74 -1
- package/src/components/multi-selection-inspector/index.js +2 -2
- package/src/components/off-canvas-editor/leaf-more-menu.js +2 -1
- package/src/components/preview-options/index.js +9 -2
- package/src/components/spacing-sizes-control/spacing-input-control.js +1 -0
- package/src/components/url-input/index.js +1 -2
- package/src/hooks/align.js +2 -1
- package/src/hooks/border.js +2 -1
- package/src/hooks/color.js +2 -1
- package/src/hooks/content-lock-ui.js +3 -15
- package/src/hooks/duotone.js +1 -0
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/layout.js +4 -2
- package/src/hooks/position.js +2 -1
- package/src/hooks/style.js +2 -1
- package/src/hooks/test/use-editor-wrapper-styles.native.js +282 -0
- package/src/hooks/test/use-typography-props.js +47 -2
- package/src/hooks/use-editor-wrapper-styles.native.js +250 -0
- package/src/hooks/use-editor-wrapper-styles.native.scss +11 -0
- package/src/hooks/use-typography-props.js +10 -11
- package/src/index.native.js +6 -0
- package/src/utils/use-should-contextual-toolbar-show.js +19 -9
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/index.js"],"names":["expanded","state","action","Array","isArray","clientIds","reduce","newState","id","type","BLOCK_LIST_ITEM_HEIGHT","ListViewComponent","ref","blocks","showBlockMovers","isExpanded","showAppender","blockSettingsMenu","BlockSettingsMenu","BlockSettingsDropdown","rootClientId","description","since","alternative","instanceId","clientIdsTree","draggedClientIds","selectedClientIds","visibleBlockCount","shouldShowInnerBlocks","select","getGlobalBlockCount","getClientIdsOfDescendants","__unstableGetEditorMode","blockEditorStore","draggedBlockCount","length","updateBlockSelection","expandedState","setExpandedState","dropZoneRef","target","blockDropTarget","elementRef","treeGridRef","isMounted","setSelectedTreeId","firstSelectedBlockClientId","selectEditorBlock","event","clientId","current","fixedListWindow","useWindowing","windowOverscan","expand","collapse","expandRow","row","dataset","block","collapseRow","focusRow","startRow","endRow","shiftKey","contextValue","isTreeGridMounted","listViewInstanceId","PrivateListView","props"],"mappings":";;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AASA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAhCA;AACA;AACA;;AAmBA;AACA;AACA;AAWA,MAAMA,QAAQ,GAAG,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACrC,MAAKC,KAAK,CAACC,OAAN,CAAeF,MAAM,CAACG,SAAtB,CAAL,EAAyC;AACxC,WAAO,EACN,GAAGJ,KADG;AAEN,SAAGC,MAAM,CAACG,SAAP,CAAiBC,MAAjB,CACF,CAAEC,QAAF,EAAYC,EAAZ,MAAsB,EACrB,GAAGD,QADkB;AAErB,SAAEC,EAAF,GAAQN,MAAM,CAACO,IAAP,KAAgB;AAFH,OAAtB,CADE,EAKF,EALE;AAFG,KAAP;AAUA;;AACD,SAAOR,KAAP;AACA,CAdD;;AAgBO,MAAMS,sBAAsB,GAAG,EAA/B;AAEP;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;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eAEQ,yBAAY,CAAE2D,KAAF,EAAS1D,GAAT,KAAkB;AAC5C,SACC,4BAAC,eAAD;AACC,IAAA,GAAG,EAAGA;AADP,KAEM0D,KAFN;AAGC,IAAA,YAAY,EAAG,KAHhB;AAIC,IAAA,iBAAiB,EAAGnD,4CAJrB;AAKC,IAAA,YAAY,EAAG;AALhB,KADD;AASA,CAVc,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseInstanceId,\n\tuseMergeRefs,\n\t__experimentalUseFixedWindowList as useFixedWindowList,\n} from '@wordpress/compose';\nimport { __experimentalTreeGrid as TreeGrid } from '@wordpress/components';\nimport { AsyncModeProvider, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseReducer,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport ListViewBranch from './branch';\nimport { ListViewContext } from './context';\nimport ListViewDropIndicator from './drop-indicator';\nimport useBlockSelection from './use-block-selection';\nimport useListViewClientIds from './use-list-view-client-ids';\nimport useListViewDropZone from './use-list-view-drop-zone';\nimport useListViewExpandSelectedItem from './use-list-view-expand-selected-item';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockSettingsDropdown } from '../block-settings-menu/block-settings-dropdown';\n\nconst expanded = ( state, action ) => {\n\tif ( Array.isArray( action.clientIds ) ) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t...action.clientIds.reduce(\n\t\t\t\t( newState, id ) => ( {\n\t\t\t\t\t...newState,\n\t\t\t\t\t[ id ]: action.type === 'expand',\n\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t),\n\t\t};\n\t}\n\treturn state;\n};\n\nexport const BLOCK_LIST_ITEM_HEIGHT = 36;\n\n/** @typedef {import('react').ComponentType} ComponentType */\n/** @typedef {import('react').Ref<HTMLElement>} Ref */\n\n/**\n * Show a hierarchical list of blocks.\n *\n * @param {Object} props Components props.\n * @param {string} props.id An HTML element id for the root element of ListView.\n * @param {Array} props.blocks _deprecated_ Custom subset of block client IDs to be used instead of the default hierarchy.\n * @param {?boolean} props.showBlockMovers Flag to enable block movers. Defaults to `false`.\n * @param {?boolean} props.isExpanded Flag to determine whether nested levels are expanded by default. Defaults to `false`.\n * @param {?boolean} props.showAppender Flag to show or hide the block appender. Defaults to `false`.\n * @param {?ComponentType} props.blockSettingsMenu Optional more menu substitution. Defaults to the standard `BlockSettingsDropdown` component.\n * @param {string} props.rootClientId The client id of the root block from which we determine the blocks to show in the list.\n * @param {string} props.description Optional accessible description for the tree grid component.\n * @param {Ref} ref Forwarded ref\n */\nfunction ListViewComponent(\n\t{\n\t\tid,\n\t\tblocks,\n\t\tshowBlockMovers = false,\n\t\tisExpanded = false,\n\t\tshowAppender = false,\n\t\tblockSettingsMenu: BlockSettingsMenu = BlockSettingsDropdown,\n\t\trootClientId,\n\t\tdescription,\n\t},\n\tref\n) {\n\t// This can be removed once we no longer need to support the blocks prop.\n\tif ( blocks ) {\n\t\tdeprecated(\n\t\t\t'`blocks` property in `wp.blockEditor.__experimentalListView`',\n\t\t\t{\n\t\t\t\tsince: '6.3',\n\t\t\t\talternative: '`rootClientId` property',\n\t\t\t}\n\t\t);\n\t}\n\n\tconst instanceId = useInstanceId( ListViewComponent );\n\tconst { clientIdsTree, draggedClientIds, selectedClientIds } =\n\t\tuseListViewClientIds( { blocks, rootClientId } );\n\n\tconst { visibleBlockCount, shouldShowInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetGlobalBlockCount,\n\t\t\t\tgetClientIdsOfDescendants,\n\t\t\t\t__unstableGetEditorMode,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst draggedBlockCount =\n\t\t\t\tdraggedClientIds?.length > 0\n\t\t\t\t\t? getClientIdsOfDescendants( draggedClientIds ).length + 1\n\t\t\t\t\t: 0;\n\t\t\treturn {\n\t\t\t\tvisibleBlockCount: getGlobalBlockCount() - draggedBlockCount,\n\t\t\t\tshouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',\n\t\t\t};\n\t\t},\n\t\t[ draggedClientIds ]\n\t);\n\n\tconst { updateBlockSelection } = useBlockSelection();\n\n\tconst [ expandedState, setExpandedState ] = useReducer( expanded, {} );\n\n\tconst { ref: dropZoneRef, target: blockDropTarget } = useListViewDropZone();\n\tconst elementRef = useRef();\n\tconst treeGridRef = useMergeRefs( [ elementRef, dropZoneRef, ref ] );\n\n\tconst isMounted = useRef( false );\n\tconst { setSelectedTreeId } = useListViewExpandSelectedItem( {\n\t\tfirstSelectedBlockClientId: selectedClientIds[ 0 ],\n\t\tsetExpandedState,\n\t} );\n\tconst selectEditorBlock = useCallback(\n\t\t( event, clientId ) => {\n\t\t\tupdateBlockSelection( event, clientId );\n\t\t\tsetSelectedTreeId( clientId );\n\t\t},\n\t\t[ setSelectedTreeId, updateBlockSelection ]\n\t);\n\tuseEffect( () => {\n\t\tisMounted.current = true;\n\t}, [] );\n\n\t// List View renders a fixed number of items and relies on each having a fixed item height of 36px.\n\t// If this value changes, we should also change the itemHeight value set in useFixedWindowList.\n\t// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.\n\tconst [ fixedListWindow ] = useFixedWindowList(\n\t\telementRef,\n\t\tBLOCK_LIST_ITEM_HEIGHT,\n\t\tvisibleBlockCount,\n\t\t{\n\t\t\tuseWindowing: true,\n\t\t\twindowOverscan: 40,\n\t\t}\n\t);\n\n\tconst expand = useCallback(\n\t\t( clientId ) => {\n\t\t\tif ( ! clientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( { type: 'expand', clientIds: [ clientId ] } );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst collapse = useCallback(\n\t\t( clientId ) => {\n\t\t\tif ( ! clientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( { type: 'collapse', clientIds: [ clientId ] } );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst expandRow = useCallback(\n\t\t( row ) => {\n\t\t\texpand( row?.dataset?.block );\n\t\t},\n\t\t[ expand ]\n\t);\n\tconst collapseRow = useCallback(\n\t\t( row ) => {\n\t\t\tcollapse( row?.dataset?.block );\n\t\t},\n\t\t[ collapse ]\n\t);\n\tconst focusRow = useCallback(\n\t\t( event, startRow, endRow ) => {\n\t\t\tif ( event.shiftKey ) {\n\t\t\t\tupdateBlockSelection(\n\t\t\t\t\tevent,\n\t\t\t\t\tstartRow?.dataset?.block,\n\t\t\t\t\tendRow?.dataset?.block\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ updateBlockSelection ]\n\t);\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tisTreeGridMounted: isMounted.current,\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tBlockSettingsMenu,\n\t\t\tlistViewInstanceId: instanceId,\n\t\t} ),\n\t\t[\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tBlockSettingsMenu,\n\t\t\tinstanceId,\n\t\t]\n\t);\n\n\t// If there are no blocks to show, do not render the list view.\n\tif ( ! clientIdsTree.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<AsyncModeProvider value={ true }>\n\t\t\t<ListViewDropIndicator\n\t\t\t\tlistViewRef={ elementRef }\n\t\t\t\tblockDropTarget={ blockDropTarget }\n\t\t\t/>\n\t\t\t<TreeGrid\n\t\t\t\tid={ id }\n\t\t\t\tclassName=\"block-editor-list-view-tree\"\n\t\t\t\taria-label={ __( 'Block navigation structure' ) }\n\t\t\t\tref={ treeGridRef }\n\t\t\t\tonCollapseRow={ collapseRow }\n\t\t\t\tonExpandRow={ expandRow }\n\t\t\t\tonFocusRow={ focusRow }\n\t\t\t\tapplicationAriaLabel={ __( 'Block navigation structure' ) }\n\t\t\t\t// eslint-disable-next-line jsx-a11y/aria-props\n\t\t\t\taria-description={ description }\n\t\t\t>\n\t\t\t\t<ListViewContext.Provider value={ contextValue }>\n\t\t\t\t\t<ListViewBranch\n\t\t\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\t\t\tparentId={ rootClientId }\n\t\t\t\t\t\tselectBlock={ selectEditorBlock }\n\t\t\t\t\t\tshowBlockMovers={ showBlockMovers }\n\t\t\t\t\t\tfixedListWindow={ fixedListWindow }\n\t\t\t\t\t\tselectedClientIds={ selectedClientIds }\n\t\t\t\t\t\tisExpanded={ isExpanded }\n\t\t\t\t\t\tshouldShowInnerBlocks={ shouldShowInnerBlocks }\n\t\t\t\t\t\tshowAppender={ showAppender }\n\t\t\t\t\t/>\n\t\t\t\t</ListViewContext.Provider>\n\t\t\t</TreeGrid>\n\t\t</AsyncModeProvider>\n\t);\n}\nexport const PrivateListView = forwardRef( ListViewComponent );\n\nexport default forwardRef( ( props, ref ) => {\n\treturn (\n\t\t<PrivateListView\n\t\t\tref={ ref }\n\t\t\t{ ...props }\n\t\t\tshowAppender={ false }\n\t\t\tblockSettingsMenu={ BlockSettingsDropdown }\n\t\t\trootClientId={ null }\n\t\t/>\n\t);\n} );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/index.js"],"names":["expanded","state","action","Array","isArray","clientIds","reduce","newState","id","type","BLOCK_LIST_ITEM_HEIGHT","ListViewComponent","ref","blocks","showBlockMovers","isExpanded","showAppender","blockSettingsMenu","BlockSettingsMenu","BlockSettingsDropdown","rootClientId","description","onSelect","renderAdditionalBlockUI","since","alternative","instanceId","clientIdsTree","draggedClientIds","selectedClientIds","getBlock","blockEditorStore","visibleBlockCount","shouldShowInnerBlocks","select","getGlobalBlockCount","getClientIdsOfDescendants","__unstableGetEditorMode","draggedBlockCount","length","updateBlockSelection","expandedState","setExpandedState","dropZoneRef","target","blockDropTarget","elementRef","treeGridRef","isMounted","setSelectedTreeId","firstSelectedBlockClientId","selectEditorBlock","event","blockClientId","current","fixedListWindow","useWindowing","windowOverscan","expand","clientId","collapse","expandRow","row","dataset","block","collapseRow","focusRow","startRow","endRow","shiftKey","contextValue","isTreeGridMounted","listViewInstanceId","PrivateListView","props"],"mappings":";;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AASA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAhCA;AACA;AACA;;AAmBA;AACA;AACA;AAWA,MAAMA,QAAQ,GAAG,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACrC,MAAKC,KAAK,CAACC,OAAN,CAAeF,MAAM,CAACG,SAAtB,CAAL,EAAyC;AACxC,WAAO,EACN,GAAGJ,KADG;AAEN,SAAGC,MAAM,CAACG,SAAP,CAAiBC,MAAjB,CACF,CAAEC,QAAF,EAAYC,EAAZ,MAAsB,EACrB,GAAGD,QADkB;AAErB,SAAEC,EAAF,GAAQN,MAAM,CAACO,IAAP,KAAgB;AAFH,OAAtB,CADE,EAKF,EALE;AAFG,KAAP;AAUA;;AACD,SAAOR,KAAP;AACA,CAdD;;AAgBO,MAAMS,sBAAsB,GAAG,EAA/B;AAEP;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,iBAAT,OAaCC,GAbD,EAcE;AAAA,MAbD;AACCJ,IAAAA,EADD;AAECK,IAAAA,MAFD;AAGCC,IAAAA,eAAe,GAAG,KAHnB;AAICC,IAAAA,UAAU,GAAG,KAJd;AAKCC,IAAAA,YAAY,GAAG,KALhB;AAMCC,IAAAA,iBAAiB,EAAEC,iBAAiB,GAAGC,4CANxC;AAOCC,IAAAA,YAPD;AAQCC,IAAAA,WARD;AASCC,IAAAA,QATD;AAUCC,IAAAA;AAVD,GAaC;;AACD;AACA,MAAKV,MAAL,EAAc;AACb,6BACC,8DADD,EAEC;AACCW,MAAAA,KAAK,EAAE,KADR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D,4CAJrB;AAKC,IAAA,YAAY,EAAG,IALhB;AAMC,IAAA,QAAQ,EAAG,IANZ;AAOC,IAAA,+BAA+B,EAAG;AAPnC,KADD;AAWA,CAZc,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseInstanceId,\n\tuseMergeRefs,\n\t__experimentalUseFixedWindowList as useFixedWindowList,\n} from '@wordpress/compose';\nimport { __experimentalTreeGrid as TreeGrid } from '@wordpress/components';\nimport { AsyncModeProvider, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseReducer,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport ListViewBranch from './branch';\nimport { ListViewContext } from './context';\nimport ListViewDropIndicator from './drop-indicator';\nimport useBlockSelection from './use-block-selection';\nimport useListViewClientIds from './use-list-view-client-ids';\nimport useListViewDropZone from './use-list-view-drop-zone';\nimport useListViewExpandSelectedItem from './use-list-view-expand-selected-item';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockSettingsDropdown } from '../block-settings-menu/block-settings-dropdown';\n\nconst expanded = ( state, action ) => {\n\tif ( Array.isArray( action.clientIds ) ) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t...action.clientIds.reduce(\n\t\t\t\t( newState, id ) => ( {\n\t\t\t\t\t...newState,\n\t\t\t\t\t[ id ]: action.type === 'expand',\n\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t),\n\t\t};\n\t}\n\treturn state;\n};\n\nexport const BLOCK_LIST_ITEM_HEIGHT = 36;\n\n/** @typedef {import('react').ComponentType} ComponentType */\n/** @typedef {import('react').Ref<HTMLElement>} Ref */\n\n/**\n * Show a hierarchical list of blocks.\n *\n * @param {Object} props Components props.\n * @param {string} props.id An HTML element id for the root element of ListView.\n * @param {Array} props.blocks _deprecated_ Custom subset of block client IDs to be used instead of the default hierarchy.\n * @param {?boolean} props.showBlockMovers Flag to enable block movers. Defaults to `false`.\n * @param {?boolean} props.isExpanded Flag to determine whether nested levels are expanded by default. Defaults to `false`.\n * @param {?boolean} props.showAppender Flag to show or hide the block appender. Defaults to `false`.\n * @param {?ComponentType} props.blockSettingsMenu Optional more menu substitution. Defaults to the standard `BlockSettingsDropdown` component.\n * @param {string} props.rootClientId The client id of the root block from which we determine the blocks to show in the list.\n * @param {string} props.description Optional accessible description for the tree grid component.\n * @param {?Function} props.onSelect Optional callback to be invoked when a block is selected. Receives the block object that was selected.\n * @param {Function} props.renderAdditionalBlockUI Function that renders additional block content UI.\n * @param {Ref} ref Forwarded ref\n */\nfunction ListViewComponent(\n\t{\n\t\tid,\n\t\tblocks,\n\t\tshowBlockMovers = false,\n\t\tisExpanded = false,\n\t\tshowAppender = false,\n\t\tblockSettingsMenu: BlockSettingsMenu = BlockSettingsDropdown,\n\t\trootClientId,\n\t\tdescription,\n\t\tonSelect,\n\t\trenderAdditionalBlockUI,\n\t},\n\tref\n) {\n\t// This can be removed once we no longer need to support the blocks prop.\n\tif ( blocks ) {\n\t\tdeprecated(\n\t\t\t'`blocks` property in `wp.blockEditor.__experimentalListView`',\n\t\t\t{\n\t\t\t\tsince: '6.3',\n\t\t\t\talternative: '`rootClientId` property',\n\t\t\t}\n\t\t);\n\t}\n\n\tconst instanceId = useInstanceId( ListViewComponent );\n\tconst { clientIdsTree, draggedClientIds, selectedClientIds } =\n\t\tuseListViewClientIds( { blocks, rootClientId } );\n\n\tconst { getBlock } = useSelect( blockEditorStore );\n\tconst { visibleBlockCount, shouldShowInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetGlobalBlockCount,\n\t\t\t\tgetClientIdsOfDescendants,\n\t\t\t\t__unstableGetEditorMode,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst draggedBlockCount =\n\t\t\t\tdraggedClientIds?.length > 0\n\t\t\t\t\t? getClientIdsOfDescendants( draggedClientIds ).length + 1\n\t\t\t\t\t: 0;\n\t\t\treturn {\n\t\t\t\tvisibleBlockCount: getGlobalBlockCount() - draggedBlockCount,\n\t\t\t\tshouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',\n\t\t\t};\n\t\t},\n\t\t[ draggedClientIds ]\n\t);\n\n\tconst { updateBlockSelection } = useBlockSelection();\n\n\tconst [ expandedState, setExpandedState ] = useReducer( expanded, {} );\n\n\tconst { ref: dropZoneRef, target: blockDropTarget } = useListViewDropZone();\n\tconst elementRef = useRef();\n\tconst treeGridRef = useMergeRefs( [ elementRef, dropZoneRef, ref ] );\n\n\tconst isMounted = useRef( false );\n\tconst { setSelectedTreeId } = useListViewExpandSelectedItem( {\n\t\tfirstSelectedBlockClientId: selectedClientIds[ 0 ],\n\t\tsetExpandedState,\n\t} );\n\tconst selectEditorBlock = useCallback(\n\t\t( event, blockClientId ) => {\n\t\t\tupdateBlockSelection( event, blockClientId );\n\t\t\tsetSelectedTreeId( blockClientId );\n\t\t\tif ( onSelect ) {\n\t\t\t\tonSelect( getBlock( blockClientId ) );\n\t\t\t}\n\t\t},\n\t\t[ setSelectedTreeId, updateBlockSelection, onSelect, getBlock ]\n\t);\n\tuseEffect( () => {\n\t\tisMounted.current = true;\n\t}, [] );\n\n\t// List View renders a fixed number of items and relies on each having a fixed item height of 36px.\n\t// If this value changes, we should also change the itemHeight value set in useFixedWindowList.\n\t// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.\n\tconst [ fixedListWindow ] = useFixedWindowList(\n\t\telementRef,\n\t\tBLOCK_LIST_ITEM_HEIGHT,\n\t\tvisibleBlockCount,\n\t\t{\n\t\t\tuseWindowing: true,\n\t\t\twindowOverscan: 40,\n\t\t}\n\t);\n\n\tconst expand = useCallback(\n\t\t( clientId ) => {\n\t\t\tif ( ! clientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( { type: 'expand', clientIds: [ clientId ] } );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst collapse = useCallback(\n\t\t( clientId ) => {\n\t\t\tif ( ! clientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetExpandedState( { type: 'collapse', clientIds: [ clientId ] } );\n\t\t},\n\t\t[ setExpandedState ]\n\t);\n\tconst expandRow = useCallback(\n\t\t( row ) => {\n\t\t\texpand( row?.dataset?.block );\n\t\t},\n\t\t[ expand ]\n\t);\n\tconst collapseRow = useCallback(\n\t\t( row ) => {\n\t\t\tcollapse( row?.dataset?.block );\n\t\t},\n\t\t[ collapse ]\n\t);\n\tconst focusRow = useCallback(\n\t\t( event, startRow, endRow ) => {\n\t\t\tif ( event.shiftKey ) {\n\t\t\t\tupdateBlockSelection(\n\t\t\t\t\tevent,\n\t\t\t\t\tstartRow?.dataset?.block,\n\t\t\t\t\tendRow?.dataset?.block\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ updateBlockSelection ]\n\t);\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tisTreeGridMounted: isMounted.current,\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tBlockSettingsMenu,\n\t\t\tlistViewInstanceId: instanceId,\n\t\t\trenderAdditionalBlockUI,\n\t\t} ),\n\t\t[\n\t\t\tdraggedClientIds,\n\t\t\texpandedState,\n\t\t\texpand,\n\t\t\tcollapse,\n\t\t\tBlockSettingsMenu,\n\t\t\tinstanceId,\n\t\t\trenderAdditionalBlockUI,\n\t\t]\n\t);\n\n\t// If there are no blocks to show, do not render the list view.\n\tif ( ! clientIdsTree.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<AsyncModeProvider value={ true }>\n\t\t\t<ListViewDropIndicator\n\t\t\t\tlistViewRef={ elementRef }\n\t\t\t\tblockDropTarget={ blockDropTarget }\n\t\t\t/>\n\t\t\t<TreeGrid\n\t\t\t\tid={ id }\n\t\t\t\tclassName=\"block-editor-list-view-tree\"\n\t\t\t\taria-label={ __( 'Block navigation structure' ) }\n\t\t\t\tref={ treeGridRef }\n\t\t\t\tonCollapseRow={ collapseRow }\n\t\t\t\tonExpandRow={ expandRow }\n\t\t\t\tonFocusRow={ focusRow }\n\t\t\t\tapplicationAriaLabel={ __( 'Block navigation structure' ) }\n\t\t\t\t// eslint-disable-next-line jsx-a11y/aria-props\n\t\t\t\taria-description={ description }\n\t\t\t>\n\t\t\t\t<ListViewContext.Provider value={ contextValue }>\n\t\t\t\t\t<ListViewBranch\n\t\t\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\t\t\tparentId={ rootClientId }\n\t\t\t\t\t\tselectBlock={ selectEditorBlock }\n\t\t\t\t\t\tshowBlockMovers={ showBlockMovers }\n\t\t\t\t\t\tfixedListWindow={ fixedListWindow }\n\t\t\t\t\t\tselectedClientIds={ selectedClientIds }\n\t\t\t\t\t\tisExpanded={ isExpanded }\n\t\t\t\t\t\tshouldShowInnerBlocks={ shouldShowInnerBlocks }\n\t\t\t\t\t\tshowAppender={ showAppender }\n\t\t\t\t\t/>\n\t\t\t\t</ListViewContext.Provider>\n\t\t\t</TreeGrid>\n\t\t</AsyncModeProvider>\n\t);\n}\nexport const PrivateListView = forwardRef( ListViewComponent );\n\nexport default forwardRef( ( props, ref ) => {\n\treturn (\n\t\t<PrivateListView\n\t\t\tref={ ref }\n\t\t\t{ ...props }\n\t\t\tshowAppender={ false }\n\t\t\tblockSettingsMenu={ BlockSettingsDropdown }\n\t\t\trootClientId={ null }\n\t\t\tonSelect={ null }\n\t\t\trenderAdditionalBlockUICallback={ null }\n\t\t/>\n\t);\n} );\n"]}
|
|
@@ -5,6 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.NESTING_LEVEL_INDENTATION = void 0;
|
|
8
9
|
exports.default = useListViewDropZone;
|
|
9
10
|
exports.getListViewDropTarget = getListViewDropTarget;
|
|
10
11
|
|
|
@@ -37,9 +38,9 @@ var _store = require("../../store");
|
|
|
37
38
|
*/
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
|
-
* An
|
|
41
|
+
* An object representing data for blocks in the DOM used by drag and drop.
|
|
41
42
|
*
|
|
42
|
-
* @typedef {Object}
|
|
43
|
+
* @typedef {Object} WPListViewDropZoneBlock
|
|
43
44
|
* @property {string} clientId The client id for the block.
|
|
44
45
|
* @property {string} rootClientId The root client id for the block.
|
|
45
46
|
* @property {number} blockIndex The block's index.
|
|
@@ -51,6 +52,12 @@ var _store = require("../../store");
|
|
|
51
52
|
* @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.
|
|
52
53
|
*/
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* An array representing data for blocks in the DOM used by drag and drop.
|
|
57
|
+
*
|
|
58
|
+
* @typedef {WPListViewDropZoneBlock[]} WPListViewDropZoneBlocks
|
|
59
|
+
*/
|
|
60
|
+
|
|
54
61
|
/**
|
|
55
62
|
* An object containing details of a drop target.
|
|
56
63
|
*
|
|
@@ -61,20 +68,113 @@ var _store = require("../../store");
|
|
|
61
68
|
* @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.
|
|
62
69
|
* 'inside' refers to nesting as an inner block.
|
|
63
70
|
*/
|
|
71
|
+
// When the indentation level, the corresponding left margin in `style.scss`
|
|
72
|
+
// must be updated as well to ensure the drop zone is aligned with the indentation.
|
|
73
|
+
const NESTING_LEVEL_INDENTATION = 28;
|
|
74
|
+
/**
|
|
75
|
+
* Determines whether the user is positioning the dragged block to be
|
|
76
|
+
* moved up to a parent level.
|
|
77
|
+
*
|
|
78
|
+
* Determined based on nesting level indentation of the current block.
|
|
79
|
+
*
|
|
80
|
+
* @param {WPPoint} point The point representing the cursor position when dragging.
|
|
81
|
+
* @param {DOMRect} rect The rectangle.
|
|
82
|
+
* @param {number} nestingLevel The nesting level of the block.
|
|
83
|
+
* @return {boolean} Whether the gesture is an upward gesture.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
exports.NESTING_LEVEL_INDENTATION = NESTING_LEVEL_INDENTATION;
|
|
87
|
+
|
|
88
|
+
function isUpGesture(point, rect) {
|
|
89
|
+
let nestingLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
90
|
+
// If the block is nested, and the user is dragging to the bottom
|
|
91
|
+
// left of the block, then it is an upward gesture.
|
|
92
|
+
const blockIndentPosition = rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;
|
|
93
|
+
return point.x < blockIndentPosition;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns how many nesting levels up the user is attempting to drag to.
|
|
97
|
+
*
|
|
98
|
+
* The relative parent level is calculated based on how far
|
|
99
|
+
* the cursor is from the provided nesting level (e.g. of a candidate block
|
|
100
|
+
* that the user is hovering over). The nesting level is considered "desired"
|
|
101
|
+
* because it is not guaranteed that the user will be able to drag to the desired level.
|
|
102
|
+
*
|
|
103
|
+
* The returned integer can be used to access an ascending array
|
|
104
|
+
* of parent blocks, where the first item is the block the user
|
|
105
|
+
* is hovering over, and the last item is the root block.
|
|
106
|
+
*
|
|
107
|
+
* @param {WPPoint} point The point representing the cursor position when dragging.
|
|
108
|
+
* @param {DOMRect} rect The rectangle.
|
|
109
|
+
* @param {number} nestingLevel The nesting level of the block.
|
|
110
|
+
* @return {number} The desired relative parent level.
|
|
111
|
+
*/
|
|
64
112
|
|
|
113
|
+
|
|
114
|
+
function getDesiredRelativeParentLevel(point, rect) {
|
|
115
|
+
let nestingLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
116
|
+
const blockIndentPosition = rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;
|
|
117
|
+
const desiredParentLevel = Math.round((point.x - blockIndentPosition) / NESTING_LEVEL_INDENTATION);
|
|
118
|
+
return Math.abs(desiredParentLevel);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns an array of the parent blocks of the block the user is dropping to.
|
|
122
|
+
*
|
|
123
|
+
* @param {WPListViewDropZoneBlock} candidateBlockData The block the user is dropping to.
|
|
124
|
+
* @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.
|
|
125
|
+
* @return {WPListViewDropZoneBlocks} An array of block parents, including the block the user is dropping to.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
function getCandidateBlockParents(candidateBlockData, blocksData) {
|
|
130
|
+
const candidateBlockParents = [];
|
|
131
|
+
let currentBlockData = candidateBlockData;
|
|
132
|
+
|
|
133
|
+
while (currentBlockData) {
|
|
134
|
+
candidateBlockParents.push({ ...currentBlockData
|
|
135
|
+
});
|
|
136
|
+
currentBlockData = blocksData.find(blockData => blockData.clientId === currentBlockData.rootClientId);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return candidateBlockParents;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Given a list of blocks data and a block index, return the next non-dragged
|
|
143
|
+
* block. This is used to determine the block that the user is dropping to,
|
|
144
|
+
* while ignoring the dragged block.
|
|
145
|
+
*
|
|
146
|
+
* @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.
|
|
147
|
+
* @param {number} index The index to begin searching from.
|
|
148
|
+
* @return {WPListViewDropZoneBlock | undefined} The next non-dragged block.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function getNextNonDraggedBlock(blocksData, index) {
|
|
153
|
+
const nextBlockData = blocksData[index + 1];
|
|
154
|
+
|
|
155
|
+
if (nextBlockData && nextBlockData.isDraggedBlock) {
|
|
156
|
+
return getNextNonDraggedBlock(blocksData, index + 1);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return nextBlockData;
|
|
160
|
+
}
|
|
65
161
|
/**
|
|
66
162
|
* Determines whether the user positioning the dragged block to nest as an
|
|
67
163
|
* inner block.
|
|
68
164
|
*
|
|
69
|
-
*
|
|
70
|
-
* of the
|
|
165
|
+
* Determined based on nesting level indentation of the current block, plus
|
|
166
|
+
* the indentation of the next level of nesting.
|
|
71
167
|
*
|
|
72
|
-
* @param {WPPoint} point
|
|
73
|
-
* @param {DOMRect} rect
|
|
168
|
+
* @param {WPPoint} point The point representing the cursor position when dragging.
|
|
169
|
+
* @param {DOMRect} rect The rectangle.
|
|
170
|
+
* @param {number} nestingLevel The nesting level of the block.
|
|
74
171
|
*/
|
|
172
|
+
|
|
173
|
+
|
|
75
174
|
function isNestingGesture(point, rect) {
|
|
76
|
-
|
|
77
|
-
|
|
175
|
+
let nestingLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
176
|
+
const blockIndentPosition = rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;
|
|
177
|
+
return point.x > blockIndentPosition + NESTING_LEVEL_INDENTATION;
|
|
78
178
|
} // Block navigation is always a vertical list, so only allow dropping
|
|
79
179
|
// to the above or below a block.
|
|
80
180
|
|
|
@@ -94,8 +194,11 @@ function getListViewDropTarget(blocksData, position) {
|
|
|
94
194
|
let candidateBlockData;
|
|
95
195
|
let candidateDistance;
|
|
96
196
|
let candidateRect;
|
|
197
|
+
let candidateBlockIndex;
|
|
198
|
+
|
|
199
|
+
for (let i = 0; i < blocksData.length; i++) {
|
|
200
|
+
const blockData = blocksData[i];
|
|
97
201
|
|
|
98
|
-
for (const blockData of blocksData) {
|
|
99
202
|
if (blockData.isDraggedBlock) {
|
|
100
203
|
continue;
|
|
101
204
|
}
|
|
@@ -115,10 +218,12 @@ function getListViewDropTarget(blocksData, position) {
|
|
|
115
218
|
candidateBlockData = previousBlockData;
|
|
116
219
|
candidateEdge = 'bottom';
|
|
117
220
|
candidateRect = previousBlockData.element.getBoundingClientRect();
|
|
221
|
+
candidateBlockIndex = index - 1;
|
|
118
222
|
} else {
|
|
119
223
|
candidateBlockData = blockData;
|
|
120
224
|
candidateEdge = edge;
|
|
121
225
|
candidateRect = rect;
|
|
226
|
+
candidateBlockIndex = index;
|
|
122
227
|
} // If the mouse position is within the block, break early
|
|
123
228
|
// as the user would intend to drop either before or after
|
|
124
229
|
// this block.
|
|
@@ -137,14 +242,58 @@ function getListViewDropTarget(blocksData, position) {
|
|
|
137
242
|
return;
|
|
138
243
|
}
|
|
139
244
|
|
|
245
|
+
const candidateBlockParents = getCandidateBlockParents(candidateBlockData, blocksData);
|
|
140
246
|
const isDraggingBelow = candidateEdge === 'bottom'; // If the user is dragging towards the bottom of the block check whether
|
|
247
|
+
// they might be trying to move the block to be at a parent level.
|
|
248
|
+
|
|
249
|
+
if (isDraggingBelow && candidateBlockData.rootClientId && isUpGesture(position, candidateRect, candidateBlockParents.length)) {
|
|
250
|
+
const nextBlock = getNextNonDraggedBlock(blocksData, candidateBlockIndex);
|
|
251
|
+
const currentLevel = candidateBlockData.nestingLevel;
|
|
252
|
+
const nextLevel = nextBlock ? nextBlock.nestingLevel : 1;
|
|
253
|
+
|
|
254
|
+
if (currentLevel && nextLevel) {
|
|
255
|
+
// Determine the desired relative level of the block to be dropped.
|
|
256
|
+
const desiredRelativeLevel = getDesiredRelativeParentLevel(position, candidateRect, candidateBlockParents.length);
|
|
257
|
+
const targetParentIndex = Math.max(Math.min(desiredRelativeLevel, currentLevel - nextLevel), 0);
|
|
258
|
+
|
|
259
|
+
if (candidateBlockParents[targetParentIndex]) {
|
|
260
|
+
// Default to the block index of the candidate block.
|
|
261
|
+
let newBlockIndex = candidateBlockData.blockIndex; // If the next block is at the same level, use that as the default
|
|
262
|
+
// block index. This ensures that the block is dropped in the correct
|
|
263
|
+
// position when dragging to the bottom of a block.
|
|
264
|
+
|
|
265
|
+
if (candidateBlockParents[targetParentIndex].nestingLevel === (nextBlock === null || nextBlock === void 0 ? void 0 : nextBlock.nestingLevel)) {
|
|
266
|
+
newBlockIndex = nextBlock === null || nextBlock === void 0 ? void 0 : nextBlock.blockIndex;
|
|
267
|
+
} else {
|
|
268
|
+
// Otherwise, search from the current block index back
|
|
269
|
+
// to find the last block index within the same target parent.
|
|
270
|
+
for (let i = candidateBlockIndex; i >= 0; i--) {
|
|
271
|
+
const blockData = blocksData[i];
|
|
272
|
+
|
|
273
|
+
if (blockData.rootClientId === candidateBlockParents[targetParentIndex].rootClientId) {
|
|
274
|
+
newBlockIndex = blockData.blockIndex + 1;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
rootClientId: candidateBlockParents[targetParentIndex].rootClientId,
|
|
282
|
+
clientId: candidateBlockData.clientId,
|
|
283
|
+
blockIndex: newBlockIndex,
|
|
284
|
+
dropPosition: candidateEdge
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} // If the user is dragging towards the bottom of the block check whether
|
|
141
289
|
// they might be trying to nest the block as a child.
|
|
142
290
|
// If the block already has inner blocks, and is expanded, this should be treated
|
|
143
291
|
// as nesting since the next block in the tree will be the first child.
|
|
144
292
|
// However, if the block is collapsed, dragging beneath the block should
|
|
145
293
|
// still be allowed, as the next visible block in the tree will be a sibling.
|
|
146
294
|
|
|
147
|
-
|
|
295
|
+
|
|
296
|
+
if (isDraggingBelow && candidateBlockData.canInsertDraggedBlocksAsChild && (candidateBlockData.innerBlockCount > 0 && candidateBlockData.isExpanded || isNestingGesture(position, candidateRect, candidateBlockParents.length))) {
|
|
148
297
|
return {
|
|
149
298
|
rootClientId: candidateBlockData.clientId,
|
|
150
299
|
blockIndex: 0,
|
|
@@ -197,7 +346,9 @@ function useListViewDropZone() {
|
|
|
197
346
|
const blockElements = Array.from(currentTarget.querySelectorAll('[data-block]'));
|
|
198
347
|
const blocksData = blockElements.map(blockElement => {
|
|
199
348
|
const clientId = blockElement.dataset.block;
|
|
200
|
-
const isExpanded = blockElement.dataset.expanded === 'true';
|
|
349
|
+
const isExpanded = blockElement.dataset.expanded === 'true'; // Get nesting level from `aria-level` attribute because Firefox does not support `element.ariaLevel`.
|
|
350
|
+
|
|
351
|
+
const nestingLevel = parseInt(blockElement.getAttribute('aria-level'), 10);
|
|
201
352
|
const rootClientId = getBlockRootClientId(clientId);
|
|
202
353
|
return {
|
|
203
354
|
clientId,
|
|
@@ -205,6 +356,7 @@ function useListViewDropZone() {
|
|
|
205
356
|
rootClientId,
|
|
206
357
|
blockIndex: getBlockIndex(clientId),
|
|
207
358
|
element: blockElement,
|
|
359
|
+
nestingLevel: nestingLevel || undefined,
|
|
208
360
|
isDraggedBlock: isBlockDrag ? draggedBlockClientIds.includes(clientId) : false,
|
|
209
361
|
innerBlockCount: getBlockCount(clientId),
|
|
210
362
|
canInsertDraggedBlocksAsSibling: isBlockDrag ? canInsertBlocks(draggedBlockClientIds, rootClientId) : true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["isNestingGesture","point","rect","blockCenterX","left","width","x","ALLOWED_DROP_EDGES","getListViewDropTarget","blocksData","position","candidateEdge","candidateBlockData","candidateDistance","candidateRect","blockData","isDraggedBlock","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","index","indexOf","previousBlockData","rootClientId","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","isExpanded","clientId","blockIndex","dropPosition","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","blockEditorStore","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","y","clientY","isBlockDrag","length","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","expanded","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAQA;;AAIA;;AACA;;AAlBA;AACA;AACA;;AAQA;AACA;AACA;;AAQA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;A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QAAAA,YAHM;AAINM,QAAAA,UAAU,EAAEM,aAAa,CAAEP,QAAF,CAJnB;AAKNd,QAAAA,OAAO,EAAE6C,YALH;AAMN9C,QAAAA,cAAc,EAAEuC,WAAW,GACxBP,qBAAqB,CAACkB,QAAtB,CAAgCnC,QAAhC,CADwB,GAExB,KARG;AASNF,QAAAA,eAAe,EAAEU,aAAa,CAAER,QAAF,CATxB;AAUNG,QAAAA,+BAA+B,EAAEqB,WAAW,GACzCd,eAAe,CACfO,qBADe,EAEftB,YAFe,CAD0B,GAKzC,IAfG;AAgBNE,QAAAA,6BAA6B,EAAE2B,WAAW,GACvCd,eAAe,CAAEO,qBAAF,EAAyBjB,QAAzB,CADwB,GAEvC;AAlBG,OAAP;AAoBA,KAzBkB,CAAnB;AA2BA,UAAMoC,SAAS,GAAG3D,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKyD,SAAL,EAAiB;AAChBvB,MAAAA,SAAS,CAAEuB,SAAF,CAAT;AACA;AACD,GAzCF,EA0CC,CAAEnB,qBAAF,CA1CD,CADiB,EA6CjB,GA7CiB,CAAlB;AAgDA,QAAMoB,GAAG,GAAG,wCAAa;AACxBC,IAAAA,MAAM,EAAEtB,WADgB;;AAExBuB,IAAAA,UAAU,CAAEpB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBoB,IAAAA,SAAS,GAAG;AACXtB,MAAAA,SAAS,CAACuB,MAAV;AACA5B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAb,CAAZ;AAcA,SAAO;AAAEwB,IAAAA,GAAF;AAAOzB,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlocks\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} isExpanded Whether the block is expanded in the UI.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Presently this is determined by whether the cursor is on the right hand side\n * of the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n */\nfunction isNestingGesture( point, rect ) {\n\tconst blockCenterX = rect.left + rect.width / 2;\n\treturn point.x > blockCenterX;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n *\n * @return {WPListViewDropZoneTarget | undefined} An object containing data about the drop target.\n */\nexport function getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\n\tfor ( const blockData of blocksData ) {\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\n\t\t\t\t\tpreviousBlockData.element.getBoundingClientRect();\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, and is expanded, this should be treated\n\t// as nesting since the next block in the tree will be the first child.\n\t// However, if the block is collapsed, dragging beneath the block should\n\t// still be allowed, as the next visible block in the tree will be a sibling.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( ( candidateBlockData.innerBlockCount > 0 &&\n\t\t\tcandidateBlockData.isExpanded ) ||\n\t\t\tisNestingGesture( position, candidateRect ) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst isExpanded = blockElement.dataset.expanded === 'true';\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tisExpanded,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["NESTING_LEVEL_INDENTATION","isUpGesture","point","rect","nestingLevel","blockIndentPosition","left","x","getDesiredRelativeParentLevel","desiredParentLevel","Math","round","abs","getCandidateBlockParents","candidateBlockData","blocksData","candidateBlockParents","currentBlockData","push","find","blockData","clientId","rootClientId","getNextNonDraggedBlock","index","nextBlockData","isDraggedBlock","isNestingGesture","ALLOWED_DROP_EDGES","getListViewDropTarget","position","candidateEdge","candidateDistance","candidateRect","candidateBlockIndex","i","length","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","indexOf","previousBlockData","isDraggingBelow","nextBlock","currentLevel","nextLevel","desiredRelativeLevel","targetParentIndex","max","min","newBlockIndex","blockIndex","dropPosition","canInsertDraggedBlocksAsChild","innerBlockCount","isExpanded","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","blockEditorStore","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","y","clientY","isBlockDrag","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","expanded","parseInt","getAttribute","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAQA;;AAIA;;AACA;;AAlBA;AACA;AACA;;AAQA;AACA;AACA;;AAQA;;AAEA;AACA;AACA;AACA;AACA;;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AA,OAAO,EAAEiD,YALH;AAMNlF,QAAAA,YAAY,EAAEA,YAAY,IAAIsC,SANxB;AAONhB,QAAAA,cAAc,EAAEsD,WAAW,GACxBP,qBAAqB,CAACmB,QAAtB,CAAgCvE,QAAhC,CADwB,GAExB,KATG;AAUNoC,QAAAA,eAAe,EAAEO,aAAa,CAAE3C,QAAF,CAVxB;AAWNsC,QAAAA,+BAA+B,EAAEqB,WAAW,GACzCd,eAAe,CACfO,qBADe,EAEfnD,YAFe,CAD0B,GAKzC,IAhBG;AAiBNkC,QAAAA,6BAA6B,EAAEwB,WAAW,GACvCd,eAAe,CAAEO,qBAAF,EAAyBpD,QAAzB,CADwB,GAEvC;AAnBG,OAAP;AAqBA,KAhCkB,CAAnB;AAkCA,UAAMwE,SAAS,GAAGhE,qBAAqB,CAAEd,UAAF,EAAce,QAAd,CAAvC;;AAEA,QAAK+D,SAAL,EAAiB;AAChBxB,MAAAA,SAAS,CAAEwB,SAAF,CAAT;AACA;AACD,GAhDF,EAiDC,CAAEpB,qBAAF,CAjDD,CADiB,EAoDjB,GApDiB,CAAlB;AAuDA,QAAMqB,GAAG,GAAG,wCAAa;AACxBC,IAAAA,MAAM,EAAEvB,WADgB;;AAExBwB,IAAAA,UAAU,CAAErB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBqB,IAAAA,SAAS,GAAG;AACXvB,MAAAA,SAAS,CAACwB,MAAV;AACA7B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAb,CAAZ;AAcA,SAAO;AAAEyB,IAAAA,GAAF;AAAO1B,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An object representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlock\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} isExpanded Whether the block is expanded in the UI.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {WPListViewDropZoneBlock[]} WPListViewDropZoneBlocks\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n// When the indentation level, the corresponding left margin in `style.scss`\n// must be updated as well to ensure the drop zone is aligned with the indentation.\nexport const NESTING_LEVEL_INDENTATION = 28;\n\n/**\n * Determines whether the user is positioning the dragged block to be\n * moved up to a parent level.\n *\n * Determined based on nesting level indentation of the current block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @return {boolean} Whether the gesture is an upward gesture.\n */\nfunction isUpGesture( point, rect, nestingLevel = 1 ) {\n\t// If the block is nested, and the user is dragging to the bottom\n\t// left of the block, then it is an upward gesture.\n\tconst blockIndentPosition =\n\t\trect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\treturn point.x < blockIndentPosition;\n}\n\n/**\n * Returns how many nesting levels up the user is attempting to drag to.\n *\n * The relative parent level is calculated based on how far\n * the cursor is from the provided nesting level (e.g. of a candidate block\n * that the user is hovering over). The nesting level is considered \"desired\"\n * because it is not guaranteed that the user will be able to drag to the desired level.\n *\n * The returned integer can be used to access an ascending array\n * of parent blocks, where the first item is the block the user\n * is hovering over, and the last item is the root block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @return {number} The desired relative parent level.\n */\nfunction getDesiredRelativeParentLevel( point, rect, nestingLevel = 1 ) {\n\tconst blockIndentPosition =\n\t\trect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\tconst desiredParentLevel = Math.round(\n\t\t( point.x - blockIndentPosition ) / NESTING_LEVEL_INDENTATION\n\t);\n\treturn Math.abs( desiredParentLevel );\n}\n\n/**\n * Returns an array of the parent blocks of the block the user is dropping to.\n *\n * @param {WPListViewDropZoneBlock} candidateBlockData The block the user is dropping to.\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @return {WPListViewDropZoneBlocks} An array of block parents, including the block the user is dropping to.\n */\nfunction getCandidateBlockParents( candidateBlockData, blocksData ) {\n\tconst candidateBlockParents = [];\n\tlet currentBlockData = candidateBlockData;\n\n\twhile ( currentBlockData ) {\n\t\tcandidateBlockParents.push( { ...currentBlockData } );\n\t\tcurrentBlockData = blocksData.find(\n\t\t\t( blockData ) =>\n\t\t\t\tblockData.clientId === currentBlockData.rootClientId\n\t\t);\n\t}\n\n\treturn candidateBlockParents;\n}\n\n/**\n * Given a list of blocks data and a block index, return the next non-dragged\n * block. This is used to determine the block that the user is dropping to,\n * while ignoring the dragged block.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {number} index The index to begin searching from.\n * @return {WPListViewDropZoneBlock | undefined} The next non-dragged block.\n */\nfunction getNextNonDraggedBlock( blocksData, index ) {\n\tconst nextBlockData = blocksData[ index + 1 ];\n\tif ( nextBlockData && nextBlockData.isDraggedBlock ) {\n\t\treturn getNextNonDraggedBlock( blocksData, index + 1 );\n\t}\n\n\treturn nextBlockData;\n}\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Determined based on nesting level indentation of the current block, plus\n * the indentation of the next level of nesting.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n */\nfunction isNestingGesture( point, rect, nestingLevel = 1 ) {\n\tconst blockIndentPosition =\n\t\trect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\treturn point.x > blockIndentPosition + NESTING_LEVEL_INDENTATION;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n *\n * @return {WPListViewDropZoneTarget | undefined} An object containing data about the drop target.\n */\nexport function getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\tlet candidateBlockIndex;\n\n\tfor ( let i = 0; i < blocksData.length; i++ ) {\n\t\tconst blockData = blocksData[ i ];\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\n\t\t\t\t\tpreviousBlockData.element.getBoundingClientRect();\n\t\t\t\tcandidateBlockIndex = index - 1;\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t\tcandidateBlockIndex = index;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst candidateBlockParents = getCandidateBlockParents(\n\t\tcandidateBlockData,\n\t\tblocksData\n\t);\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to move the block to be at a parent level.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.rootClientId &&\n\t\tisUpGesture( position, candidateRect, candidateBlockParents.length )\n\t) {\n\t\tconst nextBlock = getNextNonDraggedBlock(\n\t\t\tblocksData,\n\t\t\tcandidateBlockIndex\n\t\t);\n\t\tconst currentLevel = candidateBlockData.nestingLevel;\n\t\tconst nextLevel = nextBlock ? nextBlock.nestingLevel : 1;\n\n\t\tif ( currentLevel && nextLevel ) {\n\t\t\t// Determine the desired relative level of the block to be dropped.\n\t\t\tconst desiredRelativeLevel = getDesiredRelativeParentLevel(\n\t\t\t\tposition,\n\t\t\t\tcandidateRect,\n\t\t\t\tcandidateBlockParents.length\n\t\t\t);\n\n\t\t\tconst targetParentIndex = Math.max(\n\t\t\t\tMath.min( desiredRelativeLevel, currentLevel - nextLevel ),\n\t\t\t\t0\n\t\t\t);\n\n\t\t\tif ( candidateBlockParents[ targetParentIndex ] ) {\n\t\t\t\t// Default to the block index of the candidate block.\n\t\t\t\tlet newBlockIndex = candidateBlockData.blockIndex;\n\n\t\t\t\t// If the next block is at the same level, use that as the default\n\t\t\t\t// block index. This ensures that the block is dropped in the correct\n\t\t\t\t// position when dragging to the bottom of a block.\n\t\t\t\tif (\n\t\t\t\t\tcandidateBlockParents[ targetParentIndex ].nestingLevel ===\n\t\t\t\t\tnextBlock?.nestingLevel\n\t\t\t\t) {\n\t\t\t\t\tnewBlockIndex = nextBlock?.blockIndex;\n\t\t\t\t} else {\n\t\t\t\t\t// Otherwise, search from the current block index back\n\t\t\t\t\t// to find the last block index within the same target parent.\n\t\t\t\t\tfor ( let i = candidateBlockIndex; i >= 0; i-- ) {\n\t\t\t\t\t\tconst blockData = blocksData[ i ];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tblockData.rootClientId ===\n\t\t\t\t\t\t\tcandidateBlockParents[ targetParentIndex ]\n\t\t\t\t\t\t\t\t.rootClientId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewBlockIndex = blockData.blockIndex + 1;\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\treturn {\n\t\t\t\t\trootClientId:\n\t\t\t\t\t\tcandidateBlockParents[ targetParentIndex ].rootClientId,\n\t\t\t\t\tclientId: candidateBlockData.clientId,\n\t\t\t\t\tblockIndex: newBlockIndex,\n\t\t\t\t\tdropPosition: candidateEdge,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, and is expanded, this should be treated\n\t// as nesting since the next block in the tree will be the first child.\n\t// However, if the block is collapsed, dragging beneath the block should\n\t// still be allowed, as the next visible block in the tree will be a sibling.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( ( candidateBlockData.innerBlockCount > 0 &&\n\t\t\tcandidateBlockData.isExpanded ) ||\n\t\t\tisNestingGesture(\n\t\t\t\tposition,\n\t\t\t\tcandidateRect,\n\t\t\t\tcandidateBlockParents.length\n\t\t\t) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst isExpanded = blockElement.dataset.expanded === 'true';\n\n\t\t\t\t\t// Get nesting level from `aria-level` attribute because Firefox does not support `element.ariaLevel`.\n\t\t\t\t\tconst nestingLevel = parseInt(\n\t\t\t\t\t\tblockElement.getAttribute( 'aria-level' ),\n\t\t\t\t\t\t10\n\t\t\t\t\t);\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tisExpanded,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tnestingLevel: nestingLevel || undefined,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
@@ -20,6 +20,10 @@ var _data = require("@wordpress/data");
|
|
|
20
20
|
|
|
21
21
|
var _icons = require("@wordpress/icons");
|
|
22
22
|
|
|
23
|
+
var _blocks2 = require("@wordpress/blocks");
|
|
24
|
+
|
|
25
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
26
|
+
|
|
23
27
|
var _mediaUpload = _interopRequireDefault(require("../media-upload"));
|
|
24
28
|
|
|
25
29
|
var _check = _interopRequireDefault(require("../media-upload/check"));
|
|
@@ -91,12 +95,20 @@ function MediaPlaceholder(_ref2) {
|
|
|
91
95
|
onToggleFeaturedImage,
|
|
92
96
|
onDoubleClick,
|
|
93
97
|
onFilesPreUpload = noop,
|
|
94
|
-
onHTMLDrop
|
|
98
|
+
onHTMLDrop: deprecatedOnHTMLDrop,
|
|
95
99
|
children,
|
|
96
100
|
mediaLibraryButton,
|
|
97
101
|
placeholder,
|
|
98
102
|
style
|
|
99
103
|
} = _ref2;
|
|
104
|
+
|
|
105
|
+
if (deprecatedOnHTMLDrop) {
|
|
106
|
+
(0, _deprecated.default)('wp.blockEditor.MediaPlaceholder onHTMLDrop prop', {
|
|
107
|
+
since: '6.2',
|
|
108
|
+
version: '6.4'
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
100
112
|
const mediaUpload = (0, _data.useSelect)(select => {
|
|
101
113
|
const {
|
|
102
114
|
getSettings
|
|
@@ -212,6 +224,55 @@ function MediaPlaceholder(_ref2) {
|
|
|
212
224
|
});
|
|
213
225
|
};
|
|
214
226
|
|
|
227
|
+
async function handleBlocksDrop(blocks) {
|
|
228
|
+
if (!blocks || !Array.isArray(blocks)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function recursivelyFindMediaFromBlocks(_blocks) {
|
|
233
|
+
return _blocks.flatMap(block => (block.name === 'core/image' || block.name === 'core/audio' || block.name === 'core/video') && block.attributes.url ? [block] : recursivelyFindMediaFromBlocks(block.innerBlocks));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const mediaBlocks = recursivelyFindMediaFromBlocks(blocks);
|
|
237
|
+
|
|
238
|
+
if (!mediaBlocks.length) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const uploadedMediaList = await Promise.all(mediaBlocks.map(block => block.attributes.id ? block.attributes : new Promise((resolve, reject) => {
|
|
243
|
+
window.fetch(block.attributes.url).then(response => response.blob()).then(blob => mediaUpload({
|
|
244
|
+
filesList: [blob],
|
|
245
|
+
additionalData: {
|
|
246
|
+
title: block.attributes.title,
|
|
247
|
+
alt_text: block.attributes.alt,
|
|
248
|
+
caption: block.attributes.caption
|
|
249
|
+
},
|
|
250
|
+
onFileChange: _ref6 => {
|
|
251
|
+
let [media] = _ref6;
|
|
252
|
+
|
|
253
|
+
if (media.id) {
|
|
254
|
+
resolve(media);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
allowedTypes,
|
|
258
|
+
onError: reject
|
|
259
|
+
})).catch(() => resolve(block.attributes.url));
|
|
260
|
+
}))).catch(err => onError(err));
|
|
261
|
+
|
|
262
|
+
if (multiple) {
|
|
263
|
+
onSelect(uploadedMediaList);
|
|
264
|
+
} else {
|
|
265
|
+
onSelect(uploadedMediaList[0]);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function onHTMLDrop(HTML) {
|
|
270
|
+
const blocks = (0, _blocks2.pasteHandler)({
|
|
271
|
+
HTML
|
|
272
|
+
});
|
|
273
|
+
return await handleBlocksDrop(blocks);
|
|
274
|
+
}
|
|
275
|
+
|
|
215
276
|
const onUpload = event => {
|
|
216
277
|
onFilesUpload(event.target.files);
|
|
217
278
|
};
|
|
@@ -323,10 +384,10 @@ function MediaPlaceholder(_ref2) {
|
|
|
323
384
|
};
|
|
324
385
|
|
|
325
386
|
const renderMediaUploadChecked = () => {
|
|
326
|
-
const defaultButton =
|
|
387
|
+
const defaultButton = _ref7 => {
|
|
327
388
|
let {
|
|
328
389
|
open
|
|
329
|
-
} =
|
|
390
|
+
} = _ref7;
|
|
330
391
|
return (0, _element.createElement)(_components.Button, {
|
|
331
392
|
variant: "tertiary",
|
|
332
393
|
onClick: () => {
|
|
@@ -343,10 +404,10 @@ function MediaPlaceholder(_ref2) {
|
|
|
343
404
|
onSelect: onSelect,
|
|
344
405
|
allowedTypes: allowedTypes,
|
|
345
406
|
mode: 'browse',
|
|
346
|
-
value: Array.isArray(value) ? value.map(
|
|
407
|
+
value: Array.isArray(value) ? value.map(_ref8 => {
|
|
347
408
|
let {
|
|
348
409
|
id
|
|
349
|
-
} =
|
|
410
|
+
} = _ref8;
|
|
350
411
|
return id;
|
|
351
412
|
}) : value.id,
|
|
352
413
|
render: libraryButton
|
|
@@ -357,10 +418,10 @@ function MediaPlaceholder(_ref2) {
|
|
|
357
418
|
onChange: onUpload,
|
|
358
419
|
accept: accept,
|
|
359
420
|
multiple: multiple,
|
|
360
|
-
render:
|
|
421
|
+
render: _ref9 => {
|
|
361
422
|
let {
|
|
362
423
|
openFileDialog
|
|
363
|
-
} =
|
|
424
|
+
} = _ref9;
|
|
364
425
|
const content = (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.Button, {
|
|
365
426
|
variant: "primary",
|
|
366
427
|
className: (0, _classnames.default)('block-editor-media-placeholder__button', 'block-editor-media-placeholder__upload-button'),
|