@wordpress/block-editor 10.2.0 → 10.3.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 +12 -0
- package/README.md +41 -0
- package/build/components/block-draggable/draggable-chip.js +4 -2
- package/build/components/block-draggable/draggable-chip.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -4
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-list-compact.native.js +1 -0
- package/build/components/block-list/block-list-compact.native.js.map +1 -1
- package/build/components/block-list/block.js +72 -14
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +79 -12
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -23
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +9 -6
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-parent-selector/index.js +3 -3
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +5 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-popover/drop-zone.js +85 -0
- package/build/components/block-popover/drop-zone.js.map +1 -0
- package/build/components/block-popover/index.js +2 -1
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +2 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +6 -9
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-preview/live.js +3 -7
- package/build/components/block-preview/live.js.map +1 -1
- package/build/components/block-selection-clearer/index.js +9 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +17 -11
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +18 -42
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -4
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -1
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +50 -20
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +15 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/control.js +1 -1
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -2
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +256 -0
- package/build/components/font-sizes/fluid-utils.js.map +1 -0
- package/build/components/font-sizes/index.js +8 -0
- package/build/components/font-sizes/index.js.map +1 -1
- package/build/components/index.js +0 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +151 -78
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/menu.js +14 -3
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +4 -2
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/preview-options/index.js +2 -3
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +35 -5
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +98 -57
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +12 -12
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-on-block-drop/types.js +6 -0
- package/build/components/use-on-block-drop/types.js.map +1 -0
- package/build/hooks/align.js +1 -3
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/align.native.js +1 -7
- package/build/hooks/align.native.js.map +1 -1
- package/build/hooks/font-size.js +60 -0
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/margin.js +6 -5
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +2 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/style.js +126 -4
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-typography-props.js +17 -3
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/hooks/utils.js +1 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/store/actions.js +59 -45
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +3 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +31 -15
- package/build/store/reducer.js.map +1 -1
- package/build/utils/math.js +14 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/pre-parse-patterns.js +19 -2
- package/build/utils/pre-parse-patterns.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.js +7 -3
- package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
- package/build-module/components/block-inspector/index.js +4 -4
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-list-compact.native.js +1 -0
- package/build-module/components/block-list/block-list-compact.native.js.map +1 -1
- package/build-module/components/block-list/block.js +72 -14
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +80 -13
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +8 -24
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +10 -8
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +3 -3
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +5 -4
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-popover/drop-zone.js +70 -0
- package/build-module/components/block-popover/drop-zone.js.map +1 -0
- package/build-module/components/block-popover/index.js +2 -1
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +6 -9
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-preview/live.js +3 -6
- package/build-module/components/block-preview/live.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js +9 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +18 -12
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +19 -44
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +4 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +2 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +48 -20
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +15 -3
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +2 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +3 -3
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +245 -0
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
- package/build-module/components/font-sizes/index.js +1 -0
- package/build-module/components/font-sizes/index.js.map +1 -1
- package/build-module/components/index.js +0 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +148 -81
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +10 -3
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -3
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +34 -5
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +98 -58
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +12 -12
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/types.js +2 -0
- package/build-module/components/use-on-block-drop/types.js.map +1 -0
- package/build-module/hooks/align.js +1 -2
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/align.native.js +1 -6
- package/build-module/hooks/align.native.js.map +1 -1
- package/build-module/hooks/font-size.js +59 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/margin.js +6 -5
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +2 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/style.js +124 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-typography-props.js +17 -4
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/hooks/utils.js +2 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/store/actions.js +55 -42
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +3 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +32 -16
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/pre-parse-patterns.js +19 -2
- package/build-module/utils/pre-parse-patterns.js.map +1 -1
- package/build-style/style-rtl.css +243 -144
- package/build-style/style.css +243 -144
- package/package.json +28 -28
- package/src/components/block-breadcrumb/test/index.js +1 -1
- package/src/components/block-draggable/draggable-chip.js +4 -2
- package/src/components/block-inspector/index.js +8 -7
- package/src/components/block-list/block-list-compact.native.js +1 -0
- package/src/components/block-list/block.js +111 -7
- package/src/components/block-list/block.native.js +123 -9
- package/src/components/block-list/style.scss +93 -126
- package/src/components/block-list/use-in-between-inserter.js +8 -19
- package/src/components/block-lock/modal.js +12 -7
- package/src/components/block-mover/style.scss +0 -1
- package/src/components/block-parent-selector/index.js +3 -3
- package/src/components/block-patterns-list/index.js +9 -5
- package/src/components/block-patterns-list/style.scss +7 -3
- package/src/components/block-popover/README.md +8 -0
- package/src/components/block-popover/drop-zone.js +63 -0
- package/src/components/block-popover/index.js +2 -1
- package/src/components/block-popover/style.scss +17 -1
- package/src/components/block-preview/auto.js +1 -1
- package/src/components/block-preview/index.js +7 -8
- package/src/components/block-preview/live.js +2 -7
- package/src/components/block-preview/test/index.js +1 -7
- package/src/components/block-selection-clearer/index.js +7 -2
- package/src/components/block-selection-clearer/test/index.js +118 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +25 -11
- package/src/components/block-settings-menu/test/block-mode-toggle.js +17 -17
- package/src/components/block-styles/index.js +26 -49
- package/src/components/block-switcher/test/index.js +2 -2
- package/src/components/block-toolbar/index.js +4 -6
- package/src/components/block-toolbar/style.scss +38 -14
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +42 -17
- package/src/components/block-tools/selected-block-popover.js +14 -1
- package/src/components/button-block-appender/style.scss +4 -2
- package/src/components/color-palette/test/__snapshots__/control.js.snap +32 -52
- package/src/components/color-palette/test/control.js +11 -15
- package/src/components/colors-gradients/control.js +2 -2
- package/src/components/colors-gradients/panel-color-gradient-settings.js +3 -4
- package/src/components/colors-gradients/test/control.js +49 -77
- package/src/components/font-sizes/fluid-utils.js +296 -0
- package/src/components/font-sizes/index.js +1 -0
- package/src/components/font-sizes/test/fluid-utils.js +168 -0
- package/src/components/image-size-control/test/index.js +47 -60
- package/src/components/index.js +0 -1
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/src/components/inserter/block-patterns-tab.js +232 -98
- package/src/components/inserter/menu.js +15 -2
- package/src/components/inserter/style.scss +94 -9
- package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
- package/src/components/inserter-draggable-blocks/index.js +12 -2
- package/src/components/inserter-list-item/style.scss +20 -1
- package/src/components/link-control/test/index.js +1 -1
- package/src/components/list-view/use-list-view-drop-zone.js +4 -18
- package/src/components/panel-color-settings/test/index.js +4 -4
- package/src/components/preview-options/index.js +2 -2
- package/src/components/preview-options/style.scss +1 -1
- package/src/components/provider/test/use-block-sync.js +131 -165
- package/src/components/responsive-block-control/test/index.js +4 -4
- package/src/components/spacing-sizes-control/spacing-input-control.js +16 -2
- package/src/components/spacing-sizes-control/style.scss +26 -19
- package/src/components/use-block-drop-zone/index.js +136 -79
- package/src/components/use-block-drop-zone/test/index.js +333 -81
- package/src/components/use-on-block-drop/index.js +11 -12
- package/src/components/use-on-block-drop/types.ts +1 -0
- package/src/hooks/align.js +3 -2
- package/src/hooks/align.native.js +5 -8
- package/src/hooks/font-size.js +75 -0
- package/src/hooks/margin.js +5 -4
- package/src/hooks/padding.js +1 -0
- package/src/hooks/style.js +122 -3
- package/src/hooks/test/style.js +206 -1
- package/src/hooks/test/use-typography-props.js +22 -0
- package/src/hooks/use-typography-props.js +18 -3
- package/src/hooks/utils.js +6 -2
- package/src/store/actions.js +20 -12
- package/src/store/defaults.js +3 -0
- package/src/store/reducer.js +31 -24
- package/src/store/test/actions.js +0 -9
- package/src/utils/math.js +17 -0
- package/src/utils/pre-parse-patterns.js +12 -7
- package/build/components/inserter/pattern-panel.js +0 -87
- package/build/components/inserter/pattern-panel.js.map +0 -1
- package/build-module/components/inserter/pattern-panel.js +0 -74
- package/build-module/components/inserter/pattern-panel.js.map +0 -1
- package/src/components/inserter/pattern-panel.js +0 -93
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["useSelect","useState","useCallback","useThrottle","__experimentalUseDropZone","useDropZone","getDistanceToNearestEdge","useOnBlockDrop","store","blockEditorStore","isPointContainedByRect","point","rect","left","x","right","top","y","bottom","isNestingGesture","blockCenterX","width","ALLOWED_DROP_EDGES","getListViewDropTarget","blocksData","position","candidateEdge","candidateBlockData","candidateDistance","candidateRect","blockData","isDraggedBlock","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","index","indexOf","previousBlockData","rootClientId","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","clientId","blockIndex","dropPosition","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","clientY","isBlockDrag","length","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,oBAHP;AAKA;AACA;AACA;;AACA,SAASC,wBAAT,QAAyC,kBAAzC;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC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AEA,aAAO;AACNA,QAAAA,QADM;AAENJ,QAAAA,YAFM;AAGNK,QAAAA,UAAU,EAAEM,aAAa,CAAEP,QAAF,CAHnB;AAINb,QAAAA,OAAO,EAAE0C,YAJH;AAKN3C,QAAAA,cAAc,EAAEoC,WAAW,GACxBN,qBAAqB,CAACgB,QAAtB,CAAgChC,QAAhC,CADwB,GAExB,KAPG;AAQND,QAAAA,eAAe,EAAES,aAAa,CAAER,QAAF,CARxB;AASNG,QAAAA,+BAA+B,EAAEmB,WAAW,GACzCZ,eAAe,CACfM,qBADe,EAEfpB,YAFe,CAD0B,GAKzC,IAdG;AAeNE,QAAAA,6BAA6B,EAAEwB,WAAW,GACvCZ,eAAe,CAAEM,qBAAF,EAAyBhB,QAAzB,CADwB,GAEvC;AAjBG,OAAP;AAmBA,KAvBkB,CAAnB;AAyBA,UAAMiC,SAAS,GAAGvD,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKqD,SAAL,EAAiB;AAChBrB,MAAAA,SAAS,CAAEqB,SAAF,CAAT;AACA;AACD,GAvCS,EAwCV,CAAEjB,qBAAF,CAxCU,CADiB,EA2C5B,GA3C4B,CAA7B;AA8CA,QAAMkB,GAAG,GAAG1E,WAAW,CAAE;AACxB2E,IAAAA,MAAM,EAAEpB,WADgB;;AAExBqB,IAAAA,UAAU,CAAElB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBkB,IAAAA,SAAS,GAAG;AACXpB,MAAAA,SAAS,CAACqB,MAAV;AACA1B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAF,CAAvB;AAcA,SAAO;AAAEsB,IAAAA,GAAF;AAAOvB,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlocks\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n/**\n * Is the point contained by the rectangle.\n *\n * @param {WPPoint} point The point.\n * @param {DOMRect} rect The rectangle.\n *\n * @return {boolean} True if the point is contained by the rectangle, false otherwise.\n */\nfunction isPointContainedByRect( point, rect ) {\n\treturn (\n\t\trect.left <= point.x &&\n\t\trect.right >= point.x &&\n\t\trect.top <= point.y &&\n\t\trect.bottom >= point.y\n\t);\n}\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Presently this is determined by whether the cursor is on the right hand side\n * of the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n */\nfunction isNestingGesture( point, rect ) {\n\tconst blockCenterX = rect.left + rect.width / 2;\n\treturn point.x > blockCenterX;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n *\n * @return {WPListViewDropZoneTarget} An object containing data about the drop target.\n */\nfunction getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\n\tfor ( const blockData of blocksData ) {\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\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, this should always be treated\n\t// as nesting since the next block in the tree will be the first child.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( candidateBlockData.innerBlockCount > 0 ||\n\t\t\tisNestingGesture( position, candidateRect ) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["useSelect","useState","useCallback","useThrottle","__experimentalUseDropZone","useDropZone","getDistanceToNearestEdge","isPointContainedByRect","useOnBlockDrop","store","blockEditorStore","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","clientId","blockIndex","dropPosition","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","y","clientY","isBlockDrag","length","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,oBAHP;AAKA;AACA;AACA;;AACA,SACCC,wBADD,EAECC,sBAFD,QAGO,kBAHP;AAIA,OAAOC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AAEA,aAAO;AACNA,QAAAA,QADM;AAENJ,QAAAA,YAFM;AAGNK,QAAAA,UAAU,EAAEM,aAAa,CAAEP,QAAF,CAHnB;AAINb,QAAAA,OAAO,EAAE2C,YAJH;AAKN5C,QAAAA,cAAc,EAAEqC,WAAW,GACxBP,qBAAqB,CAACiB,QAAtB,CAAgCjC,QAAhC,CADwB,GAExB,KAPG;AAQND,QAAAA,eAAe,EAAES,aAAa,CAAER,QAAF,CARxB;AASNG,QAAAA,+BAA+B,EAAEoB,WAAW,GACzCb,eAAe,CACfM,qBADe,EAEfpB,YAFe,CAD0B,GAKzC,IAdG;AAeNE,QAAAA,6BAA6B,EAAEyB,WAAW,GACvCb,eAAe,CAAEM,qBAAF,EAAyBhB,QAAzB,CADwB,GAEvC;AAjBG,OAAP;AAmBA,KAvBkB,CAAnB;AAyBA,UAAMkC,SAAS,GAAGxD,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKsD,SAAL,EAAiB;AAChBtB,MAAAA,SAAS,CAAEsB,SAAF,CAAT;AACA;AACD,GAvCS,EAwCV,CAAElB,qBAAF,CAxCU,CADiB,EA2C5B,GA3C4B,CAA7B;AA8CA,QAAMmB,GAAG,GAAGvE,WAAW,CAAE;AACxBwE,IAAAA,MAAM,EAAErB,WADgB;;AAExBsB,IAAAA,UAAU,CAAEnB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBmB,IAAAA,SAAS,GAAG;AACXrB,MAAAA,SAAS,CAACsB,MAAV;AACA3B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAF,CAAvB;AAcA,SAAO;AAAEuB,IAAAA,GAAF;AAAOxB,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} 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} An object containing data about the drop target.\n */\nfunction getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\n\tfor ( const blockData of blocksData ) {\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\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, this should always be treated\n\t// as nesting since the next block in the tree will be the first child.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( candidateBlockData.innerBlockCount > 0 ||\n\t\t\tisNestingGesture( position, candidateRect ) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
@@ -15,6 +15,7 @@ import { check } from '@wordpress/icons';
|
|
|
15
15
|
export default function PreviewOptions(_ref) {
|
|
16
16
|
let {
|
|
17
17
|
children,
|
|
18
|
+
viewLabel,
|
|
18
19
|
className,
|
|
19
20
|
isEnabled = true,
|
|
20
21
|
deviceType,
|
|
@@ -30,9 +31,7 @@ export default function PreviewOptions(_ref) {
|
|
|
30
31
|
variant: 'tertiary',
|
|
31
32
|
className: 'block-editor-post-preview__button-toggle',
|
|
32
33
|
disabled: !isEnabled,
|
|
33
|
-
|
|
34
|
-
/* translators: button label text should, if possible, be under 16 characters. */
|
|
35
|
-
children: __('View')
|
|
34
|
+
children: viewLabel
|
|
36
35
|
};
|
|
37
36
|
const menuProps = {
|
|
38
37
|
'aria-label': __('View options')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/preview-options/index.js"],"names":["classnames","useViewportMatch","DropdownMenu","MenuGroup","MenuItem","__","check","PreviewOptions","children","className","isEnabled","deviceType","setDeviceType","isMobile","popoverProps","position","toggleProps","variant","disabled","menuProps"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,YAAT,EAAuBC,SAAvB,EAAkCC,QAAlC,QAAkD,uBAAlD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AAEA,eAAe,SAASC,cAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/preview-options/index.js"],"names":["classnames","useViewportMatch","DropdownMenu","MenuGroup","MenuItem","__","check","PreviewOptions","children","viewLabel","className","isEnabled","deviceType","setDeviceType","isMobile","popoverProps","position","toggleProps","variant","dis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AGC,IAAA,IAAI,EAAGD,UAAU,KAAK,SAAf,IAA4BN;AAHpC,KAKGD,EAAE,CAAE,SAAF,CALL,CADD,EAQC,cAAC,QAAD;AACC,IAAA,SAAS,EAAC,0CADX;AAEC,IAAA,OAAO,EAAG,MAAMQ,aAAa,CAAE,QAAF,CAF9B;AAGC,IAAA,IAAI,EAAGD,UAAU,KAAK,QAAf,IAA2BN;AAHnC,KAKGD,EAAE,CAAE,QAAF,CALL,CARD,EAeC,cAAC,QAAD;AACC,IAAA,SAAS,EAAC,0CADX;AAEC,IAAA,OAAO,EAAG,MAAMQ,aAAa,CAAE,QAAF,CAF9B;AAGC,IAAA,IAAI,EAAGD,UAAU,KAAK,QAAf,IAA2BN;AAHnC,KAKGD,EAAE,CAAE,QAAF,CALL,CAfD,CADD,EAwBGG,QAxBH,CARF,CADD;AAsCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { check } from '@wordpress/icons';\n\nexport default function PreviewOptions( {\n\tchildren,\n\tviewLabel,\n\tclassName,\n\tisEnabled = true,\n\tdeviceType,\n\tsetDeviceType,\n} ) {\n\tconst isMobile = useViewportMatch( 'small', '<' );\n\tif ( isMobile ) return null;\n\n\tconst popoverProps = {\n\t\tclassName: classnames(\n\t\t\tclassName,\n\t\t\t'block-editor-post-preview__dropdown-content'\n\t\t),\n\t\tposition: 'bottom left',\n\t};\n\tconst toggleProps = {\n\t\tvariant: 'tertiary',\n\t\tclassName: 'block-editor-post-preview__button-toggle',\n\t\tdisabled: ! isEnabled,\n\t\tchildren: viewLabel,\n\t};\n\tconst menuProps = {\n\t\t'aria-label': __( 'View options' ),\n\t};\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"block-editor-post-preview__dropdown\"\n\t\t\tpopoverProps={ popoverProps }\n\t\t\ttoggleProps={ toggleProps }\n\t\t\tmenuProps={ menuProps }\n\t\t\ticon={ null }\n\t\t>\n\t\t\t{ () => (\n\t\t\t\t<>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tclassName=\"block-editor-post-preview__button-resize\"\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Desktop' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Desktop' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Desktop' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tclassName=\"block-editor-post-preview__button-resize\"\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Tablet' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Tablet' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Tablet' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tclassName=\"block-editor-post-preview__button-resize\"\n\t\t\t\t\t\t\tonClick={ () => setDeviceType( 'Mobile' ) }\n\t\t\t\t\t\t\ticon={ deviceType === 'Mobile' && check }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Mobile' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t{ children }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"]}
|
|
@@ -20,8 +20,34 @@ import { settings } from '@wordpress/icons';
|
|
|
20
20
|
import useSetting from '../use-setting';
|
|
21
21
|
import { store as blockEditorStore } from '../../store';
|
|
22
22
|
import { LABELS, getSliderValueFromPreset, getCustomValueFromPreset, getPresetValueFromCustomValue, isValueSpacingPreset } from './utils';
|
|
23
|
+
const CUSTOM_VALUE_SETTINGS = {
|
|
24
|
+
px: {
|
|
25
|
+
max: 300,
|
|
26
|
+
steps: 1
|
|
27
|
+
},
|
|
28
|
+
'%': {
|
|
29
|
+
max: 100,
|
|
30
|
+
steps: 1
|
|
31
|
+
},
|
|
32
|
+
vw: {
|
|
33
|
+
max: 100,
|
|
34
|
+
steps: 1
|
|
35
|
+
},
|
|
36
|
+
vh: {
|
|
37
|
+
max: 100,
|
|
38
|
+
steps: 1
|
|
39
|
+
},
|
|
40
|
+
em: {
|
|
41
|
+
max: 10,
|
|
42
|
+
steps: 0.1
|
|
43
|
+
},
|
|
44
|
+
rm: {
|
|
45
|
+
max: 10,
|
|
46
|
+
steps: 0.1
|
|
47
|
+
}
|
|
48
|
+
};
|
|
23
49
|
export default function SpacingInputControl(_ref) {
|
|
24
|
-
var _spacingSizes$current;
|
|
50
|
+
var _CUSTOM_VALUE_SETTING, _CUSTOM_VALUE_SETTING2, _CUSTOM_VALUE_SETTING3, _CUSTOM_VALUE_SETTING4, _spacingSizes$current;
|
|
25
51
|
|
|
26
52
|
let {
|
|
27
53
|
spacingSizes,
|
|
@@ -73,7 +99,7 @@ export default function SpacingInputControl(_ref) {
|
|
|
73
99
|
return value === undefined ? undefined : (_spacingSizes$newValu = spacingSizes[newValue]) === null || _spacingSizes$newValu === void 0 ? void 0 : _spacingSizes$newValu.name;
|
|
74
100
|
};
|
|
75
101
|
|
|
76
|
-
const customRangeValue =
|
|
102
|
+
const customRangeValue = parseFloat(currentValue, 10);
|
|
77
103
|
|
|
78
104
|
const getNewCustomValue = newSize => {
|
|
79
105
|
const isNumeric = !isNaN(parseFloat(newSize));
|
|
@@ -151,11 +177,13 @@ export default function SpacingInputControl(_ref) {
|
|
|
151
177
|
className: "components-spacing-sizes-control__custom-value-input",
|
|
152
178
|
style: {
|
|
153
179
|
gridColumn: '1'
|
|
154
|
-
}
|
|
180
|
+
},
|
|
181
|
+
size: '__unstable-large'
|
|
155
182
|
}), createElement(RangeControl, {
|
|
156
183
|
value: customRangeValue,
|
|
157
184
|
min: 0,
|
|
158
|
-
max:
|
|
185
|
+
max: (_CUSTOM_VALUE_SETTING = (_CUSTOM_VALUE_SETTING2 = CUSTOM_VALUE_SETTINGS[selectedUnit]) === null || _CUSTOM_VALUE_SETTING2 === void 0 ? void 0 : _CUSTOM_VALUE_SETTING2.max) !== null && _CUSTOM_VALUE_SETTING !== void 0 ? _CUSTOM_VALUE_SETTING : 10,
|
|
186
|
+
step: (_CUSTOM_VALUE_SETTING3 = (_CUSTOM_VALUE_SETTING4 = CUSTOM_VALUE_SETTINGS[selectedUnit]) === null || _CUSTOM_VALUE_SETTING4 === void 0 ? void 0 : _CUSTOM_VALUE_SETTING4.steps) !== null && _CUSTOM_VALUE_SETTING3 !== void 0 ? _CUSTOM_VALUE_SETTING3 : 0.1,
|
|
159
187
|
withInputField: false,
|
|
160
188
|
onChange: handleCustomValueSliderChange,
|
|
161
189
|
className: "components-spacing-sizes-control__custom-value-range"
|
|
@@ -192,7 +220,8 @@ export default function SpacingInputControl(_ref) {
|
|
|
192
220
|
options: options,
|
|
193
221
|
label: ariaLabel,
|
|
194
222
|
hideLabelFromVision: true,
|
|
195
|
-
__nextUnconstrainedWidth: true
|
|
223
|
+
__nextUnconstrainedWidth: true,
|
|
224
|
+
size: '__unstable-large'
|
|
196
225
|
}));
|
|
197
226
|
}
|
|
198
227
|
//# sourceMappingURL=spacing-input-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/spacing-input-control.js"],"names":["classnames","useState","useMemo","useSelect","BaseControl","Button","RangeControl","CustomSelectControl","__experimentalUnitControl","UnitControl","__experimentalHStack","HStack","__experimentalUseCustomUnits","useCustomUnits","__experimentalParseQuantityAndUnitFromRawValue","parseQuantityAndUnitFromRawValue","__","sprintf","settings","useSetting","store","blockEditorStore","LABELS","getSliderValueFromPreset","getCustomValueFromPreset","getPresetValueFromCustomValue","isValueSpacingPreset","SpacingInputControl","spacingSizes","value","side","onChange","isMixed","type","minimumCustomValue","selectListSizes","showRangeControl","length","disableCustomSpacingSizes","select","editorSettings","getSettings","showCustomValueControl","setShowCustomValueControl","undefined","units","availableUnits","currentValue","showCustomValueInSelectList","name","slug","size","selectedUnit","setInitialValue","customTooltipContent","newValue","customRangeValue","parseInt","getNewCustomValue","newSize","isNumeric","isNaN","parseFloat","nextValue","getNewPresetValue","controlType","handleCustomValueSliderChange","next","join","allPlaceholder","currentValueHint","options","map","index","key","marks","label","ariaLabel","toLowerCase","showHint","gridColumn","event","nativeEvent","offsetX","find","option","selection","selectedItem"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,OAAnB,QAAkC,oBAAlC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,WADD,EAECC,MAFD,EAGCC,YAHD,EAICC,mBAJD,EAKCC,yBAAyB,IAAIC,WAL9B,EAMCC,oBAAoB,IAAIC,MANzB,EAOCC,4BAA4B,IAAIC,cAPjC,EAQCC,8CAA8C,IAAIC,gCARnD,QASO,uBATP;AAUA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,QAAT,QAAyB,kBAAzB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,gBAAvB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SACCC,MADD,EAECC,wBAFD,EAGCC,wBAHD,EAICC,6BAJD,EAKCC,oBALD,QAMO,SANP;AAQA,eAAe,SAASC,mBAAT,OAQX;AAAA;;AAAA,MARyC;AAC5CC,IAAAA,YAD4C;AAE5CC,IAAAA,KAF4C;AAG5CC,IAAAA,IAH4C;AAI5CC,IAAAA,QAJ4C;AAK5CC,IAAAA,OAAO,GAAG,KALkC;AAM5CC,IAAAA,IAN4C;AAO5CC,IAAAA;AAP4C,GAQzC;AACH;AACAL,EAAAA,KAAK,GAAGJ,6BAA6B,CAAEI,KAAF,EAASD,YAAT,CAArC;AAEA,MAAIO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GAAP,KAAe3B,YAD9B,KAEK,EAHD,CAGI;AALV;AAOC,IAAA,QAAQ,EAAKuC,SAAF,IAAiB;AAC3BvD,MAAAA,QAAQ,CACPiC,iBAAiB,CAChBsB,SAAS,CAACC,YAAV,CAAuBb,GADP,EAEhB,YAFgB,CADV,CAAR;AAMA,KAdF;AAeC,IAAA,OAAO,EAAGH,OAfX;AAgBC,IAAA,KAAK,EAAGM,SAhBT;AAiBC,IAAA,mBAAmB,EAAG,IAjBvB;AAkBC,IAAA,wBAAwB,EAAG;AAlB5B,IAhGF,CADD;AAwHA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tBaseControl,\n\tButton,\n\tRangeControl,\n\tCustomSelectControl,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalHStack as HStack,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { settings } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../use-setting';\nimport { store as blockEditorStore } from '../../store';\nimport {\n\tLABELS,\n\tgetSliderValueFromPreset,\n\tgetCustomValueFromPreset,\n\tgetPresetValueFromCustomValue,\n\tisValueSpacingPreset,\n} from './utils';\n\nexport default function SpacingInputControl( {\n\tspacingSizes,\n\tvalue,\n\tside,\n\tonChange,\n\tisMixed = false,\n\ttype,\n\tminimumCustomValue,\n} ) {\n\t// Treat value as a preset value if the passed in value matches the value of one of the spacingSizes.\n\tvalue = getPresetValueFromCustomValue( value, spacingSizes );\n\n\tlet selectListSizes = spacingSizes;\n\tconst showRangeControl = spacingSizes.length <= 8;\n\n\tconst disableCustomSpacingSizes = useSelect( ( select ) => {\n\t\tconst editorSettings = select( blockEditorStore ).getSettings();\n\t\treturn editorSettings?.disableCustomSpacingSizes;\n\t} );\n\n\tconst [ showCustomValueControl, setShowCustomValueControl ] = useState(\n\t\t! disableCustomSpacingSizes &&\n\t\t\tvalue !== undefined &&\n\t\t\t! isValueSpacingPreset( value )\n\t);\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tlet currentValue = null;\n\n\tconst showCustomValueInSelectList =\n\t\t! showRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tvalue !== undefined &&\n\t\t( ! isValueSpacingPreset( value ) ||\n\t\t\t( isValueSpacingPreset( value ) && isMixed ) );\n\n\tif ( showCustomValueInSelectList ) {\n\t\tselectListSizes = [\n\t\t\t...spacingSizes,\n\t\t\t{\n\t\t\t\tname: ! isMixed\n\t\t\t\t\t? // translators: A custom measurement, eg. a number followed by a unit like 12px.\n\t\t\t\t\t sprintf( __( 'Custom (%s)' ), value )\n\t\t\t\t\t: __( 'Mixed' ),\n\t\t\t\tslug: 'custom',\n\t\t\t\tsize: value,\n\t\t\t},\n\t\t];\n\t\tcurrentValue = selectListSizes.length - 1;\n\t} else if ( ! isMixed ) {\n\t\tcurrentValue = ! showCustomValueControl\n\t\t\t? getSliderValueFromPreset( value, spacingSizes )\n\t\t\t: getCustomValueFromPreset( value, spacingSizes );\n\t}\n\n\tconst selectedUnit =\n\t\tuseMemo(\n\t\t\t() => parseQuantityAndUnitFromRawValue( currentValue ),\n\t\t\t[ currentValue ]\n\t\t)[ 1 ] || units[ 0 ].value;\n\n\tconst setInitialValue = () => {\n\t\tif ( value === undefined ) {\n\t\t\tonChange( '0' );\n\t\t}\n\t};\n\n\tconst customTooltipContent = ( newValue ) =>\n\t\tvalue === undefined ? undefined : spacingSizes[ newValue ]?.name;\n\n\tconst customRangeValue = parseInt( currentValue, 10 );\n\n\tconst getNewCustomValue = ( newSize ) => {\n\t\tconst isNumeric = ! isNaN( parseFloat( newSize ) );\n\t\tconst nextValue = isNumeric ? newSize : undefined;\n\t\treturn nextValue;\n\t};\n\n\tconst getNewPresetValue = ( newSize, controlType ) => {\n\t\tconst size = parseInt( newSize, 10 );\n\n\t\tif ( controlType === 'selectList' ) {\n\t\t\tif ( size === 0 ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ( size === 1 ) {\n\t\t\t\treturn '0';\n\t\t\t}\n\t\t} else if ( size === 0 ) {\n\t\t\treturn '0';\n\t\t}\n\t\treturn `var:preset|spacing|${ spacingSizes[ newSize ]?.slug }`;\n\t};\n\n\tconst handleCustomValueSliderChange = ( next ) => {\n\t\tonChange( [ next, selectedUnit ].join( '' ) );\n\t};\n\n\tconst allPlaceholder = isMixed ? __( 'Mixed' ) : null;\n\n\tconst currentValueHint = ! isMixed\n\t\t? customTooltipContent( currentValue )\n\t\t: __( 'Mixed' );\n\n\tconst options = selectListSizes.map( ( size, index ) => ( {\n\t\tkey: index,\n\t\tname: size.name,\n\t} ) );\n\n\tconst marks = spacingSizes.map( ( newValue, index ) => ( {\n\t\tvalue: index,\n\t\tlabel: undefined,\n\t} ) );\n\n\tconst ariaLabel = sprintf(\n\t\t// translators: 1: The side of the block being modified (top, bottom, left, etc.). 2. Type of spacing being modified (Padding, margin, etc)\n\t\t__( '%1$s %2$s' ),\n\t\tLABELS[ side ],\n\t\ttype?.toLowerCase()\n\t);\n\n\tconst showHint =\n\t\tshowRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tcurrentValueHint !== undefined;\n\n\treturn (\n\t\t<>\n\t\t\t{ side !== 'all' && (\n\t\t\t\t<HStack className=\"components-spacing-sizes-control__side-labels\">\n\t\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__side-label\">\n\t\t\t\t\t\t{ LABELS[ side ] }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\n\t\t\t\t\t{ showHint && (\n\t\t\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__hint-single\">\n\t\t\t\t\t\t\t{ currentValueHint }\n\t\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t) }\n\t\t\t{ side === 'all' && showHint && (\n\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__hint-all\">\n\t\t\t\t\t{ currentValueHint }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t) }\n\n\t\t\t{ ! disableCustomSpacingSizes && (\n\t\t\t\t<Button\n\t\t\t\t\tlabel={\n\t\t\t\t\t\tshowCustomValueControl\n\t\t\t\t\t\t\t? __( 'Use size preset' )\n\t\t\t\t\t\t\t: __( 'Set custom size' )\n\t\t\t\t\t}\n\t\t\t\t\ticon={ settings }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetShowCustomValueControl( ! showCustomValueControl );\n\t\t\t\t\t} }\n\t\t\t\t\tisPressed={ showCustomValueControl }\n\t\t\t\t\tisSmall\n\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-all':\n\t\t\t\t\t\t\tside === 'all',\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-single':\n\t\t\t\t\t\t\tside !== 'all',\n\t\t\t\t\t} ) }\n\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomValueControl && (\n\t\t\t\t<>\n\t\t\t\t\t<UnitControl\n\t\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\t\tonChange( getNewCustomValue( newSize ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tmin={ minimumCustomValue }\n\t\t\t\t\t\tplaceholder={ allPlaceholder }\n\t\t\t\t\t\tdisableUnits={ isMixed }\n\t\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-input\"\n\t\t\t\t\t\tstyle={ { gridColumn: '1' } }\n\t\t\t\t\t/>\n\n\t\t\t\t\t<RangeControl\n\t\t\t\t\t\tvalue={ customRangeValue }\n\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\tmax={ 100 }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\tonChange={ handleCustomValueSliderChange }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-range\"\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<RangeControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__range-control\"\n\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\tonChange( getNewPresetValue( newSize ) )\n\t\t\t\t\t}\n\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t// If mouse down is near start of range set initial value to 0, which\n\t\t\t\t\t\t// prevents the user have to drag right then left to get 0 setting.\n\t\t\t\t\t\tif ( event?.nativeEvent?.offsetX < 35 ) {\n\t\t\t\t\t\t\tsetInitialValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\twithInputField={ false }\n\t\t\t\t\taria-valuenow={ currentValue }\n\t\t\t\t\taria-valuetext={ spacingSizes[ currentValue ]?.name }\n\t\t\t\t\trenderTooltipContent={ customTooltipContent }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tmax={ spacingSizes.length - 1 }\n\t\t\t\t\tmarks={ marks }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<CustomSelectControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-select-control\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\toptions.find(\n\t\t\t\t\t\t\t( option ) => option.key === currentValue\n\t\t\t\t\t\t) || '' // passing undefined here causes a downshift controlled/uncontrolled warning\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( selection ) => {\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tgetNewPresetValue(\n\t\t\t\t\t\t\t\tselection.selectedItem.key,\n\t\t\t\t\t\t\t\t'selectList'\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\toptions={ options }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextUnconstrainedWidth={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/spacing-input-control.js"],"names":["classnames","useState","useMemo","useSelect","BaseControl","Button","RangeControl","CustomSelectControl","__experimentalUnitControl","UnitControl","__experimentalHStack","HStack","__experimentalUseCustomUnits","useCustomUnits","__experimentalParseQuantityAndUnitFromRawValue","parseQuantityAndUnitFromRawValue","__","sprintf","settings","useSetting","store","blockEditorStore","LABELS","getSliderValueFromPreset","getCustomValueFromPreset","getPresetValueFromCustomValue","isValueSpacingPreset","CUSTOM_VALUE_SETTINGS","px","max","steps","vw","vh","em","rm","SpacingInputControl","spacingSizes","value","side","onChange","isMixed","type","minimumCustomValue","selectListSizes","showRangeControl","length","disableCustomSpacingSizes","select","editorSettings","getSettings","showCustomValueControl","setShowCustomValueControl","undefined","units","availableUnits","currentValue","showCustomValueInSelectList","name","slug","size","selectedUnit","setInitialValue","customTooltipContent","newValue","customRangeValue","parseFloat","getNewCustomValue","newSize","isNumeric","isNaN","nextValue","getNewPresetValue","controlType","parseInt","handleCustomValueSliderChange","next","join","allPlaceholder","currentValueHint","options","map","index","key","marks","label","ariaLabel","toLowerCase","showHint","gridColumn","event","nativeEvent","offsetX","find","option","selection","selectedItem"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nB,YAAY,CAAEmB,YAAF,CAA7B,0DAAiB,sBAA8BE,IAfhD;AAgBC,IAAA,oBAAoB,EAAGK,oBAhBxB;AAiBC,IAAA,GAAG,EAAG,CAjBP;AAkBC,IAAA,GAAG,EAAG1B,YAAY,CAACS,MAAb,GAAsB,CAlB7B;AAmBC,IAAA,KAAK,EAAGsC,KAnBT;AAoBC,IAAA,KAAK,EAAGE,SApBT;AAqBC,IAAA,mBAAmB,EAAG,IArBvB;AAsBC,IAAA,uBAAuB,EAAG;AAtB3B,IA1EF,EAmGG,CAAEzC,gBAAF,IAAsB,CAAEM,sBAAxB,IACD,cAAC,mBAAD;AACC,IAAA,SAAS,EAAC,yDADX;AAEC,IAAA,KAAK,EACJ6B,OAAO,CAACa,IAAR,CACGC,MAAF,IAAcA,MAAM,CAACX,GAAP,KAAe3B,YAD9B,KAEK,EAHD,CAGI;AALV;AAOC,IAAA,QAAQ,EAAKuC,SAAF,IAAiB;AAC3BvD,MAAAA,QAAQ,CACPgC,iBAAiB,CAChBuB,SAAS,CAACC,YAAV,CAAuBb,GADP,EAEhB,YAFgB,CADV,CAAR;AAMA,KAdF;AAeC,IAAA,OAAO,EAAGH,OAfX;AAgBC,IAAA,KAAK,EAAGM,SAhBT;AAiBC,IAAA,mBAAmB,EAAG,IAjBvB;AAkBC,IAAA,wBAAwB,EAAG,IAlB5B;AAmBC,IAAA,IAAI,EAAG;AAnBR,IApGF,CADD;AA6HA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tBaseControl,\n\tButton,\n\tRangeControl,\n\tCustomSelectControl,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalHStack as HStack,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { settings } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../use-setting';\nimport { store as blockEditorStore } from '../../store';\nimport {\n\tLABELS,\n\tgetSliderValueFromPreset,\n\tgetCustomValueFromPreset,\n\tgetPresetValueFromCustomValue,\n\tisValueSpacingPreset,\n} from './utils';\n\nconst CUSTOM_VALUE_SETTINGS = {\n\tpx: { max: 300, steps: 1 },\n\t'%': { max: 100, steps: 1 },\n\tvw: { max: 100, steps: 1 },\n\tvh: { max: 100, steps: 1 },\n\tem: { max: 10, steps: 0.1 },\n\trm: { max: 10, steps: 0.1 },\n};\n\nexport default function SpacingInputControl( {\n\tspacingSizes,\n\tvalue,\n\tside,\n\tonChange,\n\tisMixed = false,\n\ttype,\n\tminimumCustomValue,\n} ) {\n\t// Treat value as a preset value if the passed in value matches the value of one of the spacingSizes.\n\tvalue = getPresetValueFromCustomValue( value, spacingSizes );\n\n\tlet selectListSizes = spacingSizes;\n\tconst showRangeControl = spacingSizes.length <= 8;\n\n\tconst disableCustomSpacingSizes = useSelect( ( select ) => {\n\t\tconst editorSettings = select( blockEditorStore ).getSettings();\n\t\treturn editorSettings?.disableCustomSpacingSizes;\n\t} );\n\n\tconst [ showCustomValueControl, setShowCustomValueControl ] = useState(\n\t\t! disableCustomSpacingSizes &&\n\t\t\tvalue !== undefined &&\n\t\t\t! isValueSpacingPreset( value )\n\t);\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tlet currentValue = null;\n\n\tconst showCustomValueInSelectList =\n\t\t! showRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tvalue !== undefined &&\n\t\t( ! isValueSpacingPreset( value ) ||\n\t\t\t( isValueSpacingPreset( value ) && isMixed ) );\n\n\tif ( showCustomValueInSelectList ) {\n\t\tselectListSizes = [\n\t\t\t...spacingSizes,\n\t\t\t{\n\t\t\t\tname: ! isMixed\n\t\t\t\t\t? // translators: A custom measurement, eg. a number followed by a unit like 12px.\n\t\t\t\t\t sprintf( __( 'Custom (%s)' ), value )\n\t\t\t\t\t: __( 'Mixed' ),\n\t\t\t\tslug: 'custom',\n\t\t\t\tsize: value,\n\t\t\t},\n\t\t];\n\t\tcurrentValue = selectListSizes.length - 1;\n\t} else if ( ! isMixed ) {\n\t\tcurrentValue = ! showCustomValueControl\n\t\t\t? getSliderValueFromPreset( value, spacingSizes )\n\t\t\t: getCustomValueFromPreset( value, spacingSizes );\n\t}\n\n\tconst selectedUnit =\n\t\tuseMemo(\n\t\t\t() => parseQuantityAndUnitFromRawValue( currentValue ),\n\t\t\t[ currentValue ]\n\t\t)[ 1 ] || units[ 0 ].value;\n\n\tconst setInitialValue = () => {\n\t\tif ( value === undefined ) {\n\t\t\tonChange( '0' );\n\t\t}\n\t};\n\n\tconst customTooltipContent = ( newValue ) =>\n\t\tvalue === undefined ? undefined : spacingSizes[ newValue ]?.name;\n\n\tconst customRangeValue = parseFloat( currentValue, 10 );\n\n\tconst getNewCustomValue = ( newSize ) => {\n\t\tconst isNumeric = ! isNaN( parseFloat( newSize ) );\n\t\tconst nextValue = isNumeric ? newSize : undefined;\n\t\treturn nextValue;\n\t};\n\n\tconst getNewPresetValue = ( newSize, controlType ) => {\n\t\tconst size = parseInt( newSize, 10 );\n\n\t\tif ( controlType === 'selectList' ) {\n\t\t\tif ( size === 0 ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ( size === 1 ) {\n\t\t\t\treturn '0';\n\t\t\t}\n\t\t} else if ( size === 0 ) {\n\t\t\treturn '0';\n\t\t}\n\t\treturn `var:preset|spacing|${ spacingSizes[ newSize ]?.slug }`;\n\t};\n\n\tconst handleCustomValueSliderChange = ( next ) => {\n\t\tonChange( [ next, selectedUnit ].join( '' ) );\n\t};\n\n\tconst allPlaceholder = isMixed ? __( 'Mixed' ) : null;\n\n\tconst currentValueHint = ! isMixed\n\t\t? customTooltipContent( currentValue )\n\t\t: __( 'Mixed' );\n\n\tconst options = selectListSizes.map( ( size, index ) => ( {\n\t\tkey: index,\n\t\tname: size.name,\n\t} ) );\n\n\tconst marks = spacingSizes.map( ( newValue, index ) => ( {\n\t\tvalue: index,\n\t\tlabel: undefined,\n\t} ) );\n\n\tconst ariaLabel = sprintf(\n\t\t// translators: 1: The side of the block being modified (top, bottom, left, etc.). 2. Type of spacing being modified (Padding, margin, etc)\n\t\t__( '%1$s %2$s' ),\n\t\tLABELS[ side ],\n\t\ttype?.toLowerCase()\n\t);\n\n\tconst showHint =\n\t\tshowRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tcurrentValueHint !== undefined;\n\n\treturn (\n\t\t<>\n\t\t\t{ side !== 'all' && (\n\t\t\t\t<HStack className=\"components-spacing-sizes-control__side-labels\">\n\t\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__side-label\">\n\t\t\t\t\t\t{ LABELS[ side ] }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\n\t\t\t\t\t{ showHint && (\n\t\t\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__hint-single\">\n\t\t\t\t\t\t\t{ currentValueHint }\n\t\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t) }\n\t\t\t{ side === 'all' && showHint && (\n\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__hint-all\">\n\t\t\t\t\t{ currentValueHint }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t) }\n\n\t\t\t{ ! disableCustomSpacingSizes && (\n\t\t\t\t<Button\n\t\t\t\t\tlabel={\n\t\t\t\t\t\tshowCustomValueControl\n\t\t\t\t\t\t\t? __( 'Use size preset' )\n\t\t\t\t\t\t\t: __( 'Set custom size' )\n\t\t\t\t\t}\n\t\t\t\t\ticon={ settings }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetShowCustomValueControl( ! showCustomValueControl );\n\t\t\t\t\t} }\n\t\t\t\t\tisPressed={ showCustomValueControl }\n\t\t\t\t\tisSmall\n\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-all':\n\t\t\t\t\t\t\tside === 'all',\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-single':\n\t\t\t\t\t\t\tside !== 'all',\n\t\t\t\t\t} ) }\n\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomValueControl && (\n\t\t\t\t<>\n\t\t\t\t\t<UnitControl\n\t\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\t\tonChange( getNewCustomValue( newSize ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tmin={ minimumCustomValue }\n\t\t\t\t\t\tplaceholder={ allPlaceholder }\n\t\t\t\t\t\tdisableUnits={ isMixed }\n\t\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-input\"\n\t\t\t\t\t\tstyle={ { gridColumn: '1' } }\n\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t/>\n\n\t\t\t\t\t<RangeControl\n\t\t\t\t\t\tvalue={ customRangeValue }\n\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\tmax={ CUSTOM_VALUE_SETTINGS[ selectedUnit ]?.max ?? 10 }\n\t\t\t\t\t\tstep={\n\t\t\t\t\t\t\tCUSTOM_VALUE_SETTINGS[ selectedUnit ]?.steps ?? 0.1\n\t\t\t\t\t\t}\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\tonChange={ handleCustomValueSliderChange }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-range\"\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<RangeControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__range-control\"\n\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\tonChange( getNewPresetValue( newSize ) )\n\t\t\t\t\t}\n\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t// If mouse down is near start of range set initial value to 0, which\n\t\t\t\t\t\t// prevents the user have to drag right then left to get 0 setting.\n\t\t\t\t\t\tif ( event?.nativeEvent?.offsetX < 35 ) {\n\t\t\t\t\t\t\tsetInitialValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\twithInputField={ false }\n\t\t\t\t\taria-valuenow={ currentValue }\n\t\t\t\t\taria-valuetext={ spacingSizes[ currentValue ]?.name }\n\t\t\t\t\trenderTooltipContent={ customTooltipContent }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tmax={ spacingSizes.length - 1 }\n\t\t\t\t\tmarks={ marks }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<CustomSelectControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-select-control\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\toptions.find(\n\t\t\t\t\t\t\t( option ) => option.key === currentValue\n\t\t\t\t\t\t) || '' // passing undefined here causes a downshift controlled/uncontrolled warning\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( selection ) => {\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tgetNewPresetValue(\n\t\t\t\t\t\t\t\tselection.selectedItem.key,\n\t\t\t\t\t\t\t\t'selectList'\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\toptions={ options }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextUnconstrainedWidth={ true }\n\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -5,15 +5,18 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
5
5
|
import { useCallback, useState } from '@wordpress/element';
|
|
6
6
|
import { useThrottle, __experimentalUseDropZone as useDropZone } from '@wordpress/compose';
|
|
7
7
|
import { isRTL } from '@wordpress/i18n';
|
|
8
|
+
import { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
import useOnBlockDrop from '../use-on-block-drop';
|
|
13
|
-
import { getDistanceToNearestEdge } from '../../utils/math';
|
|
14
|
+
import { getDistanceToNearestEdge, isPointContainedByRect } from '../../utils/math';
|
|
14
15
|
import { store as blockEditorStore } from '../../store';
|
|
15
16
|
/** @typedef {import('../../utils/math').WPPoint} WPPoint */
|
|
16
17
|
|
|
18
|
+
/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */
|
|
19
|
+
|
|
17
20
|
/**
|
|
18
21
|
* The orientation of a block list.
|
|
19
22
|
*
|
|
@@ -21,48 +24,70 @@ import { store as blockEditorStore } from '../../store';
|
|
|
21
24
|
*/
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
|
-
*
|
|
25
|
-
* at.
|
|
27
|
+
* The insert position when dropping a block.
|
|
26
28
|
*
|
|
27
|
-
* @
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
* @typedef {'before'|'after'} WPInsertPosition
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {Object} WPBlockData
|
|
34
|
+
* @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.
|
|
35
|
+
* @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.
|
|
36
|
+
* @property {number} blockIndex The index of the block.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the drop target position from a given drop point and the orientation.
|
|
30
41
|
*
|
|
31
|
-
* @
|
|
42
|
+
* @param {WPBlockData[]} blocksData The block data list.
|
|
43
|
+
* @param {WPPoint} position The position of the item being dragged.
|
|
44
|
+
* @param {WPBlockListOrientation} orientation The orientation of the block list.
|
|
45
|
+
* @return {[number, WPDropOperation]} The drop target position.
|
|
32
46
|
*/
|
|
33
47
|
|
|
34
|
-
export function
|
|
48
|
+
export function getDropTargetPosition(blocksData, position) {
|
|
49
|
+
var _blocksData$nearestIn, _blocksData$adjacentI;
|
|
50
|
+
|
|
51
|
+
let orientation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'vertical';
|
|
35
52
|
const allowedEdges = orientation === 'horizontal' ? ['left', 'right'] : ['top', 'bottom'];
|
|
36
53
|
const isRightToLeft = isRTL();
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
let nearestIndex = 0;
|
|
55
|
+
let insertPosition = 'before';
|
|
56
|
+
let minDistance = Infinity;
|
|
57
|
+
blocksData.forEach(_ref => {
|
|
58
|
+
let {
|
|
59
|
+
isUnmodifiedDefaultBlock,
|
|
60
|
+
getBoundingClientRect,
|
|
61
|
+
blockIndex
|
|
62
|
+
} = _ref;
|
|
63
|
+
const rect = getBoundingClientRect();
|
|
64
|
+
let [distance, edge] = getDistanceToNearestEdge(position, rect, allowedEdges); // Prioritize the element if the point is inside of an unmodified default block.
|
|
65
|
+
|
|
66
|
+
if (isUnmodifiedDefaultBlock && isPointContainedByRect(position, rect)) {
|
|
67
|
+
distance = 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (distance < minDistance) {
|
|
71
|
+
// Where the dropped block will be inserted on the nearest block.
|
|
72
|
+
insertPosition = edge === 'bottom' || !isRightToLeft && edge === 'right' || isRightToLeft && edge === 'left' ? 'after' : 'before'; // Update the currently known best candidate.
|
|
73
|
+
|
|
74
|
+
minDistance = distance;
|
|
75
|
+
nearestIndex = blockIndex;
|
|
53
76
|
}
|
|
54
77
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
const adjacentIndex = nearestIndex + (insertPosition === 'after' ? 1 : -1);
|
|
79
|
+
const isNearestBlockUnmodifiedDefaultBlock = !!((_blocksData$nearestIn = blocksData[nearestIndex]) !== null && _blocksData$nearestIn !== void 0 && _blocksData$nearestIn.isUnmodifiedDefaultBlock);
|
|
80
|
+
const isAdjacentBlockUnmodifiedDefaultBlock = !!((_blocksData$adjacentI = blocksData[adjacentIndex]) !== null && _blocksData$adjacentI !== void 0 && _blocksData$adjacentI.isUnmodifiedDefaultBlock); // If both blocks are not unmodified default blocks then just insert between them.
|
|
81
|
+
|
|
82
|
+
if (!isNearestBlockUnmodifiedDefaultBlock && !isAdjacentBlockUnmodifiedDefaultBlock) {
|
|
83
|
+
// If the user is dropping to the trailing edge of the block
|
|
84
|
+
// add 1 to the index to represent dragging after.
|
|
85
|
+
const insertionIndex = insertPosition === 'after' ? nearestIndex + 1 : nearestIndex;
|
|
86
|
+
return [insertionIndex, 'insert'];
|
|
87
|
+
} // Otherwise, replace the nearest unmodified default block.
|
|
88
|
+
|
|
63
89
|
|
|
64
|
-
|
|
65
|
-
return !!element && element.dataset.type === 'core/paragraph' && element.dataset.empty === 'true';
|
|
90
|
+
return [isNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex, 'replace'];
|
|
66
91
|
}
|
|
67
92
|
/**
|
|
68
93
|
* @typedef {Object} WPBlockDropZoneConfig
|
|
@@ -75,7 +100,6 @@ function isEmptyParagraph(element) {
|
|
|
75
100
|
* @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.
|
|
76
101
|
*/
|
|
77
102
|
|
|
78
|
-
|
|
79
103
|
export default function useBlockDropZone() {
|
|
80
104
|
let {
|
|
81
105
|
// An undefined value represents a top-level block. Default to an empty
|
|
@@ -84,7 +108,10 @@ export default function useBlockDropZone() {
|
|
|
84
108
|
// an empty string to represent top-level blocks.
|
|
85
109
|
rootClientId: targetRootClientId = ''
|
|
86
110
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
87
|
-
const [
|
|
111
|
+
const [dropTarget, setDropTarget] = useState({
|
|
112
|
+
index: null,
|
|
113
|
+
operation: 'insert'
|
|
114
|
+
});
|
|
88
115
|
const isDisabled = useSelect(select => {
|
|
89
116
|
const {
|
|
90
117
|
getTemplateLock,
|
|
@@ -95,35 +122,50 @@ export default function useBlockDropZone() {
|
|
|
95
122
|
return ['all', 'contentOnly'].some(lock => lock === templateLock) || __unstableHasActiveBlockOverlayActive(targetRootClientId) || __unstableIsWithinBlockOverlay(targetRootClientId);
|
|
96
123
|
}, [targetRootClientId]);
|
|
97
124
|
const {
|
|
98
|
-
getBlockListSettings
|
|
125
|
+
getBlockListSettings,
|
|
126
|
+
getBlocks,
|
|
127
|
+
getBlockIndex
|
|
99
128
|
} = useSelect(blockEditorStore);
|
|
100
129
|
const {
|
|
101
130
|
showInsertionPoint,
|
|
102
131
|
hideInsertionPoint
|
|
103
132
|
} = useDispatch(blockEditorStore);
|
|
104
|
-
const onBlockDrop = useOnBlockDrop(targetRootClientId,
|
|
105
|
-
|
|
133
|
+
const onBlockDrop = useOnBlockDrop(targetRootClientId, dropTarget.index, {
|
|
134
|
+
operation: dropTarget.operation
|
|
135
|
+
});
|
|
136
|
+
const throttled = useThrottle(useCallback((event, ownerDocument) => {
|
|
106
137
|
var _getBlockListSettings;
|
|
107
138
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
const blocks = getBlocks(targetRootClientId); // The block list is empty, don't show the insertion point but still allow dropping.
|
|
140
|
+
|
|
141
|
+
if (blocks.length === 0) {
|
|
142
|
+
setDropTarget({
|
|
143
|
+
index: 0,
|
|
144
|
+
operation: 'insert'
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const blocksData = blocks.map(block => {
|
|
150
|
+
const clientId = block.clientId;
|
|
151
|
+
return {
|
|
152
|
+
isUnmodifiedDefaultBlock: getIsUnmodifiedDefaultBlock(block),
|
|
153
|
+
getBoundingClientRect: () => ownerDocument.getElementById(`block-${clientId}`).getBoundingClientRect(),
|
|
154
|
+
blockIndex: getBlockIndex(clientId)
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
const [targetIndex, operation] = getDropTargetPosition(blocksData, {
|
|
111
158
|
x: event.clientX,
|
|
112
159
|
y: event.clientY
|
|
113
160
|
}, (_getBlockListSettings = getBlockListSettings(targetRootClientId)) === null || _getBlockListSettings === void 0 ? void 0 : _getBlockListSettings.orientation);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
showInsertionPoint(targetRootClientId, targetIndex);
|
|
125
|
-
}
|
|
126
|
-
}, []), 200);
|
|
161
|
+
setDropTarget({
|
|
162
|
+
index: targetIndex,
|
|
163
|
+
operation
|
|
164
|
+
});
|
|
165
|
+
showInsertionPoint(targetRootClientId, targetIndex, {
|
|
166
|
+
operation
|
|
167
|
+
});
|
|
168
|
+
}, [targetRootClientId]), 200);
|
|
127
169
|
return useDropZone({
|
|
128
170
|
isDisabled,
|
|
129
171
|
onDrop: onBlockDrop,
|
|
@@ -132,19 +174,17 @@ export default function useBlockDropZone() {
|
|
|
132
174
|
// `currentTarget` is only available while the event is being
|
|
133
175
|
// handled, so get it now and pass it to the thottled function.
|
|
134
176
|
// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
|
|
135
|
-
throttled(event, event.currentTarget);
|
|
177
|
+
throttled(event, event.currentTarget.ownerDocument);
|
|
136
178
|
},
|
|
137
179
|
|
|
138
180
|
onDragLeave() {
|
|
139
181
|
throttled.cancel();
|
|
140
182
|
hideInsertionPoint();
|
|
141
|
-
setTargetBlockIndex(null);
|
|
142
183
|
},
|
|
143
184
|
|
|
144
185
|
onDragEnd() {
|
|
145
186
|
throttled.cancel();
|
|
146
187
|
hideInsertionPoint();
|
|
147
|
-
setTargetBlockIndex(null);
|
|
148
188
|
}
|
|
149
189
|
|
|
150
190
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"names":["useDispatch","useSelect","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","useOnBlockDrop","getDistanceToNearestEdge","store","blockEditorStore","getNearestBlockIndex","elements","position","orientation","allowedEdges","isRightToLeft","candidateIndex","candidateDistance","forEach","element","index","rect","getBoundingClientRect","distance","edge","undefined","isTrailingEdge","offset","isEmptyParagraph","dataset","type","empty","useBlockDropZone","rootClientId","targetRootClientId","targetBlockIndex","setTargetBlockIndex","isDisabled","select","getTemplateLock","__unstableIsWithinBlockOverlay","__unstableHasActiveBlockOverlayActive","templateLock","some","lock","getBlockListSettings","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","currentTarget","blockElements","Array","from","children","filter","classList","contains","targetIndex","x","clientX","y","clientY","nextBlock","previousBlock","onDrop","onDragOver","onDragLeave","cancel","onDragEnd"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAA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B;;AAcnBkC,IAAAA,SAAS,GAAG;AACXrB,MAAAA,SAAS,CAACoB,MAAV;AACAtB,MAAAA,kBAAkB;AAClBX,MAAAA,mBAAmB,CAAE,IAAF,CAAnB;AACA;;AAlBkB,GAAF,CAAlB;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * Given a list of block DOM elements finds the index that a block should be dropped\n * at.\n *\n * @param {Element[]} elements Array of DOM elements that represent each block in a block list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of a block list.\n *\n * @return {number|undefined} The block index that's closest to the drag position.\n */\nexport function getNearestBlockIndex( elements, position, orientation ) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tconst isRightToLeft = isRTL();\n\n\tlet candidateIndex;\n\tlet candidateDistance;\n\n\telements.forEach( ( element, index ) => {\n\t\tconst rect = element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tallowedEdges\n\t\t);\n\n\t\tif ( candidateDistance === undefined || distance < candidateDistance ) {\n\t\t\t// If the user is dropping to the trailing edge of the block\n\t\t\t// add 1 to the index to represent dragging after.\n\t\t\t// Take RTL languages into account where the left edge is\n\t\t\t// the trailing edge.\n\t\t\tconst isTrailingEdge =\n\t\t\t\tedge === 'bottom' ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( isRightToLeft && edge === 'left' );\n\t\t\tconst offset = isTrailingEdge ? 1 : 0;\n\n\t\t\t// Update the currently known best candidate.\n\t\t\tcandidateDistance = distance;\n\t\t\tcandidateIndex = index + offset;\n\t\t}\n\t} );\n\n\treturn candidateIndex;\n}\n\n/**\n * Determine if the element is an empty paragraph block.\n *\n * @param {?HTMLElement} element The element being tested.\n * @return {boolean} True or False.\n */\nfunction isEmptyParagraph( element ) {\n\treturn (\n\t\t!! element &&\n\t\telement.dataset.type === 'core/paragraph' &&\n\t\telement.dataset.empty === 'true'\n\t);\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst [ targetBlockIndex, setTargetBlockIndex ] = useState( null );\n\n\tconst isDisabled = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetTemplateLock,\n\t\t\t\t__unstableIsWithinBlockOverlay,\n\t\t\t\t__unstableHasActiveBlockOverlayActive,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst templateLock = getTemplateLock( targetRootClientId );\n\t\t\treturn (\n\t\t\t\t[ 'all', 'contentOnly' ].some(\n\t\t\t\t\t( lock ) => lock === templateLock\n\t\t\t\t) ||\n\t\t\t\t__unstableHasActiveBlockOverlayActive( targetRootClientId ) ||\n\t\t\t\t__unstableIsWithinBlockOverlay( targetRootClientId )\n\t\t\t);\n\t\t},\n\t\t[ targetRootClientId ]\n\t);\n\n\tconst { getBlockListSettings } = useSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\tconst throttled = useThrottle(\n\t\tuseCallback( ( event, currentTarget ) => {\n\t\t\tconst blockElements = Array.from( currentTarget.children ).filter(\n\t\t\t\t// Ensure the element is a block. It should have the `wp-block` class.\n\t\t\t\t( element ) => element.classList.contains( 'wp-block' )\n\t\t\t);\n\t\t\tconst targetIndex = getNearestBlockIndex(\n\t\t\t\tblockElements,\n\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation\n\t\t\t);\n\n\t\t\tsetTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex );\n\n\t\t\tif ( targetIndex !== undefined ) {\n\t\t\t\tconst nextBlock = blockElements[ targetIndex ];\n\t\t\t\tconst previousBlock = blockElements[ targetIndex - 1 ];\n\n\t\t\t\t// Don't show the insertion point when it's near an empty paragraph block.\n\t\t\t\tif (\n\t\t\t\t\tisEmptyParagraph( nextBlock ) ||\n\t\t\t\t\tisEmptyParagraph( previousBlock )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tshowInsertionPoint( targetRootClientId, targetIndex );\n\t\t\t}\n\t\t}, [] ),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tisDisabled,\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\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t\tsetTargetBlockIndex( null );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t\tsetTargetBlockIndex( null );\n\t\t},\n\t} );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"names":["useDispatch","useSelect","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","isUnmodifiedDefaultBlock","getIsUnmodifiedDefaultBlock","useOnBlockDrop","getDistanceToNearestEdge","isPointContainedByRect","store","blockEditorStore","getDropTargetPosition","blocksData","position","orientation","allowedEdges","isRightToLeft","nearestIndex","insertPosition","minDistance","Infinity","forEach","getBoundingClientRect","blockIndex","rect","distance","edge","adjacentIndex","isNearestBlockUnmodifiedDefaultBlock","isAdjacentBlockUnmodifiedDefaultBlock","insertionIndex","useBlockDropZone","rootClientId","targetRootClientId","dropTarget","setDropTarget","index","operation","isDisabled","select","getTemplateLock","__unstableIsWithinBlockOverlay","__unstableHasActiveBlockOverlayActive","templateLock","some","lock","getBlockListSettings","getBlocks","getBlockIndex","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","ownerDocument","blocks","length","map","block","clientId","getElementById","targetIndex","x","clientX","y","clientY","onDrop","onDragOver","currentTarget","onDragLeave","cancel","onDragEnd"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,oBAHP;AAIA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,wBAAwB,IAAIC,2BAArC,QAAwE,mBAAxE;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AACA,SACCC,wBADD,EAECC,sBAFD,QAGO,kBAHP;AAIA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA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AFuD,2BAGvDnB,oBAAoB,CAAEb,kBAAF,CAHmC,0DAGvD,sBAA4CnB,WAHW,CAAxD;AAMAqB,IAAAA,aAAa,CAAE;AACdC,MAAAA,KAAK,EAAEyB,WADO;AAEdxB,MAAAA;AAFc,KAAF,CAAb;AAIAY,IAAAA,kBAAkB,CAAEhB,kBAAF,EAAsB4B,WAAtB,EAAmC;AACpDxB,MAAAA;AADoD,KAAnC,CAAlB;AAGA,GAxCS,EAyCV,CAAEJ,kBAAF,CAzCU,CADiB,EA4C5B,GA5C4B,CAA7B;AA+CA,SAAO/B,WAAW,CAAE;AACnBoC,IAAAA,UADmB;AAEnB4B,IAAAA,MAAM,EAAEf,WAFW;;AAGnBgB,IAAAA,UAAU,CAAEd,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACe,aAAN,CAAoBd,aAA7B,CAAT;AACA,KARkB;;AASnBe,IAAAA,WAAW,GAAG;AACbjB,MAAAA,SAAS,CAACkB,MAAV;AACApB,MAAAA,kBAAkB;AAClB,KAZkB;;AAanBqB,IAAAA,SAAS,GAAG;AACXnB,MAAAA,SAAS,CAACkB,MAAV;AACApB,MAAAA,kBAAkB;AAClB;;AAhBkB,GAAF,CAAlB;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\nimport { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * The insert position when dropping a block.\n *\n * @typedef {'before'|'after'} WPInsertPosition\n */\n\n/**\n * @typedef {Object} WPBlockData\n * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.\n * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.\n * @property {number} blockIndex The index of the block.\n */\n\n/**\n * Get the drop target position from a given drop point and the orientation.\n *\n * @param {WPBlockData[]} blocksData The block data list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of the block list.\n * @return {[number, WPDropOperation]} The drop target position.\n */\nexport function getDropTargetPosition(\n\tblocksData,\n\tposition,\n\torientation = 'vertical'\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tconst isRightToLeft = isRTL();\n\n\tlet nearestIndex = 0;\n\tlet insertPosition = 'before';\n\tlet minDistance = Infinity;\n\n\tblocksData.forEach(\n\t\t( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {\n\t\t\tconst rect = getBoundingClientRect();\n\n\t\t\tlet [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\tallowedEdges\n\t\t\t);\n\t\t\t// Prioritize the element if the point is inside of an unmodified default block.\n\t\t\tif (\n\t\t\t\tisUnmodifiedDefaultBlock &&\n\t\t\t\tisPointContainedByRect( position, rect )\n\t\t\t) {\n\t\t\t\tdistance = 0;\n\t\t\t}\n\n\t\t\tif ( distance < minDistance ) {\n\t\t\t\t// Where the dropped block will be inserted on the nearest block.\n\t\t\t\tinsertPosition =\n\t\t\t\t\tedge === 'bottom' ||\n\t\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t\t( isRightToLeft && edge === 'left' )\n\t\t\t\t\t\t? 'after'\n\t\t\t\t\t\t: 'before';\n\n\t\t\t\t// Update the currently known best candidate.\n\t\t\t\tminDistance = distance;\n\t\t\t\tnearestIndex = blockIndex;\n\t\t\t}\n\t\t}\n\t);\n\n\tconst adjacentIndex =\n\t\tnearestIndex + ( insertPosition === 'after' ? 1 : -1 );\n\tconst isNearestBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;\n\tconst isAdjacentBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;\n\n\t// If both blocks are not unmodified default blocks then just insert between them.\n\tif (\n\t\t! isNearestBlockUnmodifiedDefaultBlock &&\n\t\t! isAdjacentBlockUnmodifiedDefaultBlock\n\t) {\n\t\t// If the user is dropping to the trailing edge of the block\n\t\t// add 1 to the index to represent dragging after.\n\t\tconst insertionIndex =\n\t\t\tinsertPosition === 'after' ? nearestIndex + 1 : nearestIndex;\n\t\treturn [ insertionIndex, 'insert' ];\n\t}\n\n\t// Otherwise, replace the nearest unmodified default block.\n\treturn [\n\t\tisNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,\n\t\t'replace',\n\t];\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst [ dropTarget, setDropTarget ] = useState( {\n\t\tindex: null,\n\t\toperation: 'insert',\n\t} );\n\n\tconst isDisabled = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetTemplateLock,\n\t\t\t\t__unstableIsWithinBlockOverlay,\n\t\t\t\t__unstableHasActiveBlockOverlayActive,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst templateLock = getTemplateLock( targetRootClientId );\n\t\t\treturn (\n\t\t\t\t[ 'all', 'contentOnly' ].some(\n\t\t\t\t\t( lock ) => lock === templateLock\n\t\t\t\t) ||\n\t\t\t\t__unstableHasActiveBlockOverlayActive( targetRootClientId ) ||\n\t\t\t\t__unstableIsWithinBlockOverlay( targetRootClientId )\n\t\t\t);\n\t\t},\n\t\t[ targetRootClientId ]\n\t);\n\n\tconst { getBlockListSettings, getBlocks, getBlockIndex } =\n\t\tuseSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, dropTarget.index, {\n\t\toperation: dropTarget.operation,\n\t} );\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, ownerDocument ) => {\n\t\t\t\tconst blocks = getBlocks( targetRootClientId );\n\n\t\t\t\t// The block list is empty, don't show the insertion point but still allow dropping.\n\t\t\t\tif ( blocks.length === 0 ) {\n\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocksData = blocks.map( ( block ) => {\n\t\t\t\t\tconst clientId = block.clientId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisUnmodifiedDefaultBlock:\n\t\t\t\t\t\t\tgetIsUnmodifiedDefaultBlock( block ),\n\t\t\t\t\t\tgetBoundingClientRect: () =>\n\t\t\t\t\t\t\townerDocument\n\t\t\t\t\t\t\t\t.getElementById( `block-${ clientId }` )\n\t\t\t\t\t\t\t\t.getBoundingClientRect(),\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst [ targetIndex, operation ] = getDropTargetPosition(\n\t\t\t\t\tblocksData,\n\t\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation\n\t\t\t\t);\n\n\t\t\t\tsetDropTarget( {\n\t\t\t\t\tindex: targetIndex,\n\t\t\t\t\toperation,\n\t\t\t\t} );\n\t\t\t\tshowInsertionPoint( targetRootClientId, targetIndex, {\n\t\t\t\t\toperation,\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[ targetRootClientId ]\n\t\t),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tisDisabled,\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.ownerDocument );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"]}
|