@wordpress/block-editor 10.1.1-next.4d3b314fd5.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 +14 -0
- package/README.md +41 -0
- package/build/components/block-controls/slot.js +2 -2
- package/build/components/block-controls/slot.js.map +1 -1
- 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 -5
- 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 +5 -5
- 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/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +22 -17
- 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 +22 -16
- 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/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.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/block-types-tab.js +1 -1
- package/build/components/inserter/block-types-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/search-items.js +2 -17
- package/build/components/inserter/search-items.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/inspector-controls/slot.js +2 -1
- package/build/components/inspector-controls/slot.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/rich-text/index.js +17 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +40 -9
- 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 +36 -18
- 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-controls/slot.js +3 -3
- package/build-module/components/block-controls/slot.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 +5 -6
- 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 +5 -5
- 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/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +22 -17
- 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 +25 -19
- 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/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.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/block-types-tab.js +3 -3
- package/build-module/components/inserter/block-types-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/search-items.js +3 -17
- package/build-module/components/inserter/search-items.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/inspector-controls/slot.js +3 -2
- package/build-module/components/inspector-controls/slot.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/rich-text/index.js +17 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +40 -10
- 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 +36 -19
- 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 +256 -152
- package/build-style/style.css +256 -152
- package/package.json +28 -29
- package/src/components/block-breadcrumb/test/index.js +1 -1
- package/src/components/block-controls/slot.js +3 -3
- package/src/components/block-draggable/draggable-chip.js +4 -2
- package/src/components/block-inspector/index.js +8 -11
- 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 +5 -5
- 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/inbetween.js +1 -1
- package/src/components/block-popover/index.js +39 -22
- 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 +32 -18
- 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/__snapshots__/index.js.snap +104 -33
- package/src/components/block-switcher/test/index.js +121 -61
- 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 +5 -1
- 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-editor/use-transform-image.js +2 -2
- 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/block-types-tab.js +3 -3
- package/src/components/inserter/menu.js +15 -2
- package/src/components/inserter/search-items.js +3 -15
- package/src/components/inserter/style.scss +94 -9
- package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
- package/src/components/inserter/test/search-items.js +4 -0
- package/src/components/inserter-draggable-blocks/index.js +12 -2
- package/src/components/inserter-list-item/style.scss +20 -1
- package/src/components/inspector-controls/slot.js +6 -2
- 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 +77 -122
- package/src/components/rich-text/index.js +22 -0
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +24 -9
- package/src/components/spacing-sizes-control/style.scss +42 -31
- 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 +35 -28
- 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
|
@@ -62,7 +62,7 @@ function BlockTypesTab(_ref) {
|
|
|
62
62
|
return items.filter(item => !item.category);
|
|
63
63
|
}, [items]);
|
|
64
64
|
const itemsPerCategory = (0, _element.useMemo)(() => {
|
|
65
|
-
return (0,
|
|
65
|
+
return (0, _compose.pipe)(itemList => itemList.filter(item => item.category && item.category !== 'reusable'), itemList => (0, _lodash.groupBy)(itemList, 'category'))(items);
|
|
66
66
|
}, [items]);
|
|
67
67
|
const itemsPerCollection = (0, _element.useMemo)(() => {
|
|
68
68
|
// Create a new Object to avoid mutating collection.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/block-types-tab.js"],"names":["getBlockNamespace","item","name","split","MAX_SUGGESTED_ITEMS","EMPTY_ARRAY","BlockTypesTab","rootClientId","onInsert","onHover","showMostUsedBlocks","items","categories","collections","onSelectItem","suggestedItems","slice","uncategorizedItems","filter","category","itemsPerCategory","itemList","itemsPerCollection","result","Object","keys","forEach","namespace","length","currentlyRenderedCategories","didRenderAllCategories","collectionEntries","entries","currentlyRenderedCollections","categoryItems","slug","title","icon","collection","collectionItems"],"mappings":";;;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAMA,MAAMA,iBAAiB,GAAKC,IAAF,IAAYA,IAAI,CAACC,IAAL,CAAUC,KAAV,CAAiB,GAAjB,EAAwB,CAAxB,CAAtC;;AAEA,MAAMC,mBAAmB,GAAG,CAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;;AAEO,SAASC,aAAT,OAKH;AAAA,MAL2B;AAC9BC,IAAAA,YAD8B;AAE9BC,IAAAA,QAF8B;AAG9BC,IAAAA,OAH8B;AAI9BC,IAAAA;AAJ8B,GAK3B;AACH,QAAM,CAAEC,KAAF,EAASC,UAAT,EAAqBC,WAArB,EAAkCC,YAAlC,IAAmD,iCACxDP,YADwD,EAExDC,QAFwD,CAAzD;AAKA,QAAMO,cAAc,GAAG,sBAAS,MAAM;AACrC,WAAO,qBAASJ,KAAT,EAAgB,CAAE,UAAF,CAAhB,EAAgC,CAAE,MAAF,CAAhC,EAA6CK,KAA7C,CACN,CADM,EAENZ,mBAFM,CAAP;AAIA,GALsB,EAKpB,CAAEO,KAAF,CALoB,CAAvB;AAOA,QAAMM,kBAAkB,GAAG,sBAAS,MAAM;AACzC,WAAON,KAAK,CAACO,MAAN,CAAgBjB,IAAF,IAAY,CAAEA,IAAI,CAACkB,QAAjC,CAAP;AACA,GAF0B,EAExB,CAAER,KAAF,CAFwB,CAA3B;AAIA,QAAMS,gBAAgB,GAAG,sBAAS,MAAM;AACvC,WAAO,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/block-types-tab.js"],"names":["getBlockNamespace","item","name","split","MAX_SUGGESTED_ITEMS","EMPTY_ARRAY","BlockTypesTab","rootClientId","onInsert","onHover","showMostUsedBlocks","items","categories","collections","onSelectItem","suggestedItems","slice","uncategorizedItems","filter","category","itemsPerCategory","itemList","itemsPerCollection","result","Object","keys","forEach","namespace","length","currentlyRenderedCategories","didRenderAllCategories","collectionEntries","entries","currentlyRenderedCollections","categoryItems","slug","title","icon","collection","collectionItems"],"mappings":";;;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAMA,MAAMA,iBAAiB,GAAKC,IAAF,IAAYA,IAAI,CAACC,IAAL,CAAUC,KAAV,CAAiB,GAAjB,EAAwB,CAAxB,CAAtC;;AAEA,MAAMC,mBAAmB,GAAG,CAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;;AAEO,SAASC,aAA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CH,CADD,CADD;AA4EA;;eAEc9B,a","sourcesContent":["/**\n * External dependencies\n */\nimport { map, groupBy, orderBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x } from '@wordpress/i18n';\nimport { useMemo, useEffect } from '@wordpress/element';\nimport { pipe, useAsyncList } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport BlockTypesList from '../block-types-list';\nimport InserterPanel from './panel';\nimport useBlockTypesState from './hooks/use-block-types-state';\nimport InserterListbox from '../inserter-listbox';\n\nconst getBlockNamespace = ( item ) => item.name.split( '/' )[ 0 ];\n\nconst MAX_SUGGESTED_ITEMS = 6;\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation and rerendering the component.\n *\n * @type {Array}\n */\nconst EMPTY_ARRAY = [];\n\nexport function BlockTypesTab( {\n\trootClientId,\n\tonInsert,\n\tonHover,\n\tshowMostUsedBlocks,\n} ) {\n\tconst [ items, categories, collections, onSelectItem ] = useBlockTypesState(\n\t\trootClientId,\n\t\tonInsert\n\t);\n\n\tconst suggestedItems = useMemo( () => {\n\t\treturn orderBy( items, [ 'frecency' ], [ 'desc' ] ).slice(\n\t\t\t0,\n\t\t\tMAX_SUGGESTED_ITEMS\n\t\t);\n\t}, [ items ] );\n\n\tconst uncategorizedItems = useMemo( () => {\n\t\treturn items.filter( ( item ) => ! item.category );\n\t}, [ items ] );\n\n\tconst itemsPerCategory = useMemo( () => {\n\t\treturn pipe(\n\t\t\t( itemList ) =>\n\t\t\t\titemList.filter(\n\t\t\t\t\t( item ) => item.category && item.category !== 'reusable'\n\t\t\t\t),\n\t\t\t( itemList ) => groupBy( itemList, 'category' )\n\t\t)( items );\n\t}, [ items ] );\n\n\tconst itemsPerCollection = useMemo( () => {\n\t\t// Create a new Object to avoid mutating collection.\n\t\tconst result = { ...collections };\n\t\tObject.keys( collections ).forEach( ( namespace ) => {\n\t\t\tresult[ namespace ] = items.filter(\n\t\t\t\t( item ) => getBlockNamespace( item ) === namespace\n\t\t\t);\n\t\t\tif ( result[ namespace ].length === 0 ) {\n\t\t\t\tdelete result[ namespace ];\n\t\t\t}\n\t\t} );\n\n\t\treturn result;\n\t}, [ items, collections ] );\n\n\t// Hide block preview on unmount.\n\tuseEffect( () => () => onHover( null ), [] );\n\n\t/**\n\t * The inserter contains a big number of blocks and opening it is a costful operation.\n\t * The rendering is the most costful part of it, in order to improve the responsiveness\n\t * of the \"opening\" action, these lazy lists allow us to render the inserter category per category,\n\t * once all the categories are rendered, we start rendering the collections and the uncategorized block types.\n\t */\n\tconst currentlyRenderedCategories = useAsyncList( categories );\n\tconst didRenderAllCategories =\n\t\tcategories.length === currentlyRenderedCategories.length;\n\n\t// Async List requires an array.\n\tconst collectionEntries = useMemo( () => {\n\t\treturn Object.entries( collections );\n\t}, [ collections ] );\n\tconst currentlyRenderedCollections = useAsyncList(\n\t\tdidRenderAllCategories ? collectionEntries : EMPTY_ARRAY\n\t);\n\n\treturn (\n\t\t<InserterListbox>\n\t\t\t<div>\n\t\t\t\t{ showMostUsedBlocks && !! suggestedItems.length && (\n\t\t\t\t\t<InserterPanel title={ _x( 'Most used', 'blocks' ) }>\n\t\t\t\t\t\t<BlockTypesList\n\t\t\t\t\t\t\titems={ suggestedItems }\n\t\t\t\t\t\t\tonSelect={ onSelectItem }\n\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\tlabel={ _x( 'Most used', 'blocks' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</InserterPanel>\n\t\t\t\t) }\n\n\t\t\t\t{ map( currentlyRenderedCategories, ( category ) => {\n\t\t\t\t\tconst categoryItems = itemsPerCategory[ category.slug ];\n\t\t\t\t\tif ( ! categoryItems || ! categoryItems.length ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<InserterPanel\n\t\t\t\t\t\t\tkey={ category.slug }\n\t\t\t\t\t\t\ttitle={ category.title }\n\t\t\t\t\t\t\ticon={ category.icon }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<BlockTypesList\n\t\t\t\t\t\t\t\titems={ categoryItems }\n\t\t\t\t\t\t\t\tonSelect={ onSelectItem }\n\t\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\t\tlabel={ category.title }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</InserterPanel>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\n\t\t\t\t{ didRenderAllCategories && uncategorizedItems.length > 0 && (\n\t\t\t\t\t<InserterPanel\n\t\t\t\t\t\tclassName=\"block-editor-inserter__uncategorized-blocks-panel\"\n\t\t\t\t\t\ttitle={ __( 'Uncategorized' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockTypesList\n\t\t\t\t\t\t\titems={ uncategorizedItems }\n\t\t\t\t\t\t\tonSelect={ onSelectItem }\n\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\tlabel={ __( 'Uncategorized' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</InserterPanel>\n\t\t\t\t) }\n\n\t\t\t\t{ map(\n\t\t\t\t\tcurrentlyRenderedCollections,\n\t\t\t\t\t( [ namespace, collection ] ) => {\n\t\t\t\t\t\tconst collectionItems = itemsPerCollection[ namespace ];\n\t\t\t\t\t\tif ( ! collectionItems || ! collectionItems.length ) {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<InserterPanel\n\t\t\t\t\t\t\t\tkey={ namespace }\n\t\t\t\t\t\t\t\ttitle={ collection.title }\n\t\t\t\t\t\t\t\ticon={ collection.icon }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BlockTypesList\n\t\t\t\t\t\t\t\t\titems={ collectionItems }\n\t\t\t\t\t\t\t\t\tonSelect={ onSelectItem }\n\t\t\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\t\t\tlabel={ collection.title }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</InserterPanel>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</InserterListbox>\n\t);\n}\n\nexport default BlockTypesTab;\n"]}
|
|
@@ -23,7 +23,7 @@ var _previewPanel = _interopRequireDefault(require("./preview-panel"));
|
|
|
23
23
|
|
|
24
24
|
var _blockTypesTab = _interopRequireDefault(require("./block-types-tab"));
|
|
25
25
|
|
|
26
|
-
var _blockPatternsTab =
|
|
26
|
+
var _blockPatternsTab = _interopRequireWildcard(require("./block-patterns-tab"));
|
|
27
27
|
|
|
28
28
|
var _reusableBlocksTab = _interopRequireDefault(require("./reusable-blocks-tab"));
|
|
29
29
|
|
|
@@ -35,6 +35,10 @@ var _tabs = _interopRequireDefault(require("./tabs"));
|
|
|
35
35
|
|
|
36
36
|
var _store = require("../../store");
|
|
37
37
|
|
|
38
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
39
|
+
|
|
40
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
|
+
|
|
38
42
|
/**
|
|
39
43
|
* External dependencies
|
|
40
44
|
*/
|
|
@@ -62,6 +66,7 @@ function InserterMenu(_ref, ref) {
|
|
|
62
66
|
const [filterValue, setFilterValue] = (0, _element.useState)(__experimentalFilterValue);
|
|
63
67
|
const [hoveredItem, setHoveredItem] = (0, _element.useState)(null);
|
|
64
68
|
const [selectedPatternCategory, setSelectedPatternCategory] = (0, _element.useState)(null);
|
|
69
|
+
const [selectedTab, setSelectedTab] = (0, _element.useState)(null);
|
|
65
70
|
const [destinationRootClientId, onInsertBlocks, onToggleInsertionPoint] = (0, _useInsertionPoint.default)({
|
|
66
71
|
rootClientId,
|
|
67
72
|
clientId,
|
|
@@ -116,7 +121,7 @@ function InserterMenu(_ref, ref) {
|
|
|
116
121
|
const patternsTab = (0, _element.useMemo)(() => (0, _element.createElement)(_blockPatternsTab.default, {
|
|
117
122
|
rootClientId: destinationRootClientId,
|
|
118
123
|
onInsert: onInsertPattern,
|
|
119
|
-
|
|
124
|
+
onSelectCategory: onClickPatternCategory,
|
|
120
125
|
selectedCategory: selectedPatternCategory
|
|
121
126
|
}), [destinationRootClientId, onInsertPattern, onClickPatternCategory, selectedPatternCategory]);
|
|
122
127
|
const reusableBlocksTab = (0, _element.useMemo)(() => (0, _element.createElement)(_reusableBlocksTab.default, {
|
|
@@ -139,6 +144,7 @@ function InserterMenu(_ref, ref) {
|
|
|
139
144
|
searchRef.current.focus();
|
|
140
145
|
}
|
|
141
146
|
}));
|
|
147
|
+
const showPatternPanel = selectedTab === 'patterns' && !filterValue && selectedPatternCategory;
|
|
142
148
|
const showAsTabs = !filterValue && (showPatterns || hasReusableBlocks);
|
|
143
149
|
return (0, _element.createElement)("div", {
|
|
144
150
|
className: "block-editor-inserter__menu"
|
|
@@ -171,11 +177,16 @@ function InserterMenu(_ref, ref) {
|
|
|
171
177
|
})), showAsTabs && (0, _element.createElement)(_tabs.default, {
|
|
172
178
|
showPatterns: showPatterns,
|
|
173
179
|
showReusableBlocks: hasReusableBlocks,
|
|
174
|
-
prioritizePatterns: prioritizePatterns
|
|
180
|
+
prioritizePatterns: prioritizePatterns,
|
|
181
|
+
onSelect: setSelectedTab
|
|
175
182
|
}, getCurrentTab), !filterValue && !showAsTabs && (0, _element.createElement)("div", {
|
|
176
183
|
className: "block-editor-inserter__no-tab-container"
|
|
177
184
|
}, blocksTab)), showInserterHelpPanel && hoveredItem && (0, _element.createElement)(_previewPanel.default, {
|
|
178
185
|
item: hoveredItem
|
|
186
|
+
}), showPatternPanel && (0, _element.createElement)(_blockPatternsTab.BlockPatternsCategoryDialog, {
|
|
187
|
+
rootClientId: destinationRootClientId,
|
|
188
|
+
onInsert: onInsertPattern,
|
|
189
|
+
category: selectedPatternCategory
|
|
179
190
|
}));
|
|
180
191
|
}
|
|
181
192
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/menu.js"],"names":["InserterMenu","ref","rootClientId","clientId","isAppender","__experimentalInsertionIndex","onSelect","showInserterHelpPanel","showMostUsedBlocks","__experimentalFilterValue","shouldFocusBlock","prioritizePatterns","filterValue","setFilterValue","hoveredItem","setHoveredItem","selectedPatternCategory","setSelectedPatternCategory","destinationRootClientId","onInsertBlocks","onToggleInsertionPoint","insertionIndex","showPatterns","hasReusableBlocks","select","__experimentalGetAllowedPatterns","getSettings","blockEditorStore","length","__experimentalReusableBlocks","onInsert","blocks","meta","shouldForceFocusBlock","onInsertPattern","patternName","onHover","item","onClickPatternCategory","patternCategory","blocksTab","patternsTab","reusableBlocksTab","getCurrentTab","tab","name","searchRef","focusSearch","current","focus","showAsTabs","value"],"mappings":";;;;;;;;;AAQA;;AALA;;AAaA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;AAWA,SAASA,YAAT,OAaCC,GAbD,EAcE;AAAA,MAbD;AACCC,IAAAA,YADD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F,MAAAA,cAAc,CAAEsC,KAAF,CAAd;AACA,KALF;AAMC,IAAA,KAAK,EAAGvC,WANT;AAOC,IAAA,KAAK,EAAG,cAAI,gCAAJ,CAPT;AAQC,IAAA,WAAW,EAAG,cAAI,QAAJ,CARf;AASC,IAAA,GAAG,EAAGkC;AATP,IALD,EAgBG,CAAC,CAAElC,WAAH,IACD;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,sBAAD;AACC,IAAA,WAAW,EAAGA,WADf;AAEC,IAAA,QAAQ,EAAGN,QAFZ;AAGC,IAAA,OAAO,EAAG8B,OAHX;AAIC,IAAA,YAAY,EAAGlC,YAJhB;AAKC,IAAA,QAAQ,EAAGC,QALZ;AAMC,IAAA,UAAU,EAAGC,UANd;AAOC,IAAA,4BAA4B,EAC3BC,4BARF;AAUC,IAAA,kBAAkB,MAVnB;AAWC,IAAA,gBAAgB,EAAGK;AAXpB,IADD,CAjBF,EAiCGwC,UAAU,IACX,4BAAC,aAAD;AACC,IAAA,YAAY,EAAG5B,YADhB;AAEC,IAAA,kBAAkB,EAAGC,iBAFtB;AAGC,IAAA,kBAAkB,EAAGZ;AAHtB,KAKGgC,aALH,CAlCF,EA0CG,CAAE/B,WAAF,IAAiB,CAAEsC,UAAnB,IACD;AAAK,IAAA,SAAS,EAAC;AAAf,KACGV,SADH,CA3CF,CADD,EAiDGjC,qBAAqB,IAAIO,WAAzB,IACD,4BAAC,qBAAD;AAAsB,IAAA,IAAI,EAAGA;AAA7B,IAlDF,CADD;AAuDA;;eAEc,yBAAYd,YAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tforwardRef,\n\tuseState,\n\tuseCallback,\n\tuseMemo,\n\tuseImperativeHandle,\n\tuseRef,\n} from '@wordpress/element';\nimport { VisuallyHidden, SearchControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport Tips from './tips';\nimport InserterPreviewPanel from './preview-panel';\nimport BlockTypesTab from './block-types-tab';\nimport BlockPatternsTabs from './block-patterns-tab';\nimport ReusableBlocksTab from './reusable-blocks-tab';\nimport InserterSearchResults from './search-results';\nimport useInsertionPoint from './hooks/use-insertion-point';\nimport InserterTabs from './tabs';\nimport { store as blockEditorStore } from '../../store';\n\nfunction InserterMenu(\n\t{\n\t\trootClientId,\n\t\tclientId,\n\t\tisAppender,\n\t\t__experimentalInsertionIndex,\n\t\tonSelect,\n\t\tshowInserterHelpPanel,\n\t\tshowMostUsedBlocks,\n\t\t__experimentalFilterValue = '',\n\t\tshouldFocusBlock = true,\n\t\tprioritizePatterns,\n\t},\n\tref\n) {\n\tconst [ filterValue, setFilterValue ] = useState(\n\t\t__experimentalFilterValue\n\t);\n\tconst [ hoveredItem, setHoveredItem ] = useState( null );\n\tconst [ selectedPatternCategory, setSelectedPatternCategory ] =\n\t\tuseState( null );\n\n\tconst [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =\n\t\tuseInsertionPoint( {\n\t\t\trootClientId,\n\t\t\tclientId,\n\t\t\tisAppender,\n\t\t\tinsertionIndex: __experimentalInsertionIndex,\n\t\t\tshouldFocusBlock,\n\t\t} );\n\tconst { showPatterns, hasReusableBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __experimentalGetAllowedPatterns, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tshowPatterns: !! __experimentalGetAllowedPatterns(\n\t\t\t\t\tdestinationRootClientId\n\t\t\t\t).length,\n\t\t\t\thasReusableBlocks:\n\t\t\t\t\t!! getSettings().__experimentalReusableBlocks?.length,\n\t\t\t};\n\t\t},\n\t\t[ destinationRootClientId ]\n\t);\n\n\tconst onInsert = useCallback(\n\t\t( blocks, meta, shouldForceFocusBlock ) => {\n\t\t\tonInsertBlocks( blocks, meta, shouldForceFocusBlock );\n\t\t\tonSelect();\n\t\t},\n\t\t[ onInsertBlocks, onSelect ]\n\t);\n\n\tconst onInsertPattern = useCallback(\n\t\t( blocks, patternName ) => {\n\t\t\tonInsertBlocks( blocks, { patternName } );\n\t\t\tonSelect();\n\t\t},\n\t\t[ onInsertBlocks, onSelect ]\n\t);\n\n\tconst onHover = useCallback(\n\t\t( item ) => {\n\t\t\tonToggleInsertionPoint( !! item );\n\t\t\tsetHoveredItem( item );\n\t\t},\n\t\t[ onToggleInsertionPoint, setHoveredItem ]\n\t);\n\n\tconst onClickPatternCategory = useCallback(\n\t\t( patternCategory ) => {\n\t\t\tsetSelectedPatternCategory( patternCategory );\n\t\t},\n\t\t[ setSelectedPatternCategory ]\n\t);\n\n\tconst blocksTab = useMemo(\n\t\t() => (\n\t\t\t<>\n\t\t\t\t<div className=\"block-editor-inserter__block-list\">\n\t\t\t\t\t<BlockTypesTab\n\t\t\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\tshowMostUsedBlocks={ showMostUsedBlocks }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t{ showInserterHelpPanel && (\n\t\t\t\t\t<div className=\"block-editor-inserter__tips\">\n\t\t\t\t\t\t<VisuallyHidden as=\"h2\">\n\t\t\t\t\t\t\t{ __( 'A tip for using the block editor' ) }\n\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t<Tips />\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\t[\n\t\t\tdestinationRootClientId,\n\t\t\tonInsert,\n\t\t\tonHover,\n\t\t\tfilterValue,\n\t\t\tshowMostUsedBlocks,\n\t\t\tshowInserterHelpPanel,\n\t\t]\n\t);\n\n\tconst patternsTab = useMemo(\n\t\t() => (\n\t\t\t<BlockPatternsTabs\n\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\tonInsert={ onInsertPattern }\n\t\t\t\tonClickCategory={ onClickPatternCategory }\n\t\t\t\tselectedCategory={ selectedPatternCategory }\n\t\t\t/>\n\t\t),\n\t\t[\n\t\t\tdestinationRootClientId,\n\t\t\tonInsertPattern,\n\t\t\tonClickPatternCategory,\n\t\t\tselectedPatternCategory,\n\t\t]\n\t);\n\n\tconst reusableBlocksTab = useMemo(\n\t\t() => (\n\t\t\t<ReusableBlocksTab\n\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\tonInsert={ onInsert }\n\t\t\t\tonHover={ onHover }\n\t\t\t/>\n\t\t),\n\t\t[ destinationRootClientId, onInsert, onHover ]\n\t);\n\n\tconst getCurrentTab = useCallback(\n\t\t( tab ) => {\n\t\t\tif ( tab.name === 'blocks' ) {\n\t\t\t\treturn blocksTab;\n\t\t\t} else if ( tab.name === 'patterns' ) {\n\t\t\t\treturn patternsTab;\n\t\t\t}\n\t\t\treturn reusableBlocksTab;\n\t\t},\n\t\t[ blocksTab, patternsTab, reusableBlocksTab ]\n\t);\n\n\tconst searchRef = useRef();\n\tuseImperativeHandle( ref, () => ( {\n\t\tfocusSearch: () => {\n\t\t\tsearchRef.current.focus();\n\t\t},\n\t} ) );\n\n\tconst showAsTabs = ! filterValue && ( showPatterns || hasReusableBlocks );\n\n\treturn (\n\t\t<div className=\"block-editor-inserter__menu\">\n\t\t\t<div\n\t\t\t\tclassName={ classnames( 'block-editor-inserter__main-area', {\n\t\t\t\t\t'show-as-tabs': showAsTabs,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<SearchControl\n\t\t\t\t\tclassName=\"block-editor-inserter__search\"\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tif ( hoveredItem ) setHoveredItem( null );\n\t\t\t\t\t\tsetFilterValue( value );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ filterValue }\n\t\t\t\t\tlabel={ __( 'Search for blocks and patterns' ) }\n\t\t\t\t\tplaceholder={ __( 'Search' ) }\n\t\t\t\t\tref={ searchRef }\n\t\t\t\t/>\n\t\t\t\t{ !! filterValue && (\n\t\t\t\t\t<div className=\"block-editor-inserter__no-tab-container\">\n\t\t\t\t\t\t<InserterSearchResults\n\t\t\t\t\t\t\tfilterValue={ filterValue }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tisAppender={ isAppender }\n\t\t\t\t\t\t\t__experimentalInsertionIndex={\n\t\t\t\t\t\t\t\t__experimentalInsertionIndex\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tshowBlockDirectory\n\t\t\t\t\t\t\tshouldFocusBlock={ shouldFocusBlock }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ showAsTabs && (\n\t\t\t\t\t<InserterTabs\n\t\t\t\t\t\tshowPatterns={ showPatterns }\n\t\t\t\t\t\tshowReusableBlocks={ hasReusableBlocks }\n\t\t\t\t\t\tprioritizePatterns={ prioritizePatterns }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ getCurrentTab }\n\t\t\t\t\t</InserterTabs>\n\t\t\t\t) }\n\t\t\t\t{ ! filterValue && ! showAsTabs && (\n\t\t\t\t\t<div className=\"block-editor-inserter__no-tab-container\">\n\t\t\t\t\t\t{ blocksTab }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ showInserterHelpPanel && hoveredItem && (\n\t\t\t\t<InserterPreviewPanel item={ hoveredItem } />\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default forwardRef( InserterMenu );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/menu.js"],"names":["InserterMenu","ref","rootClientId","clientId","isAppender","__experimentalInsertionIndex","onSelect","showInserterHelpPanel","showMostUsedBlocks","__experimentalFilterValue","shouldFocusBlock","prioritizePatterns","filterValue","setFilterValue","hoveredItem","setHoveredItem","selectedPatternCategory","setSelectedPatternCategory","selectedTab","setSelectedTab","destinationRootClientId","onInsertBlocks","onToggleInsertionPoint","insertionIndex","showPatterns","hasReusableBlocks","select","__experimentalGetAllowedPatterns","getSettings","blockEditorStore","length","__experimentalReusableBlocks","onInsert","blocks","meta","shouldForceFocusBlock","onInsertPattern","patternName","onHover","item","onClickPatternCategory","patternCategory","blocksTab","patternsTab","reusableBlocksTab","getCurrentTab","tab","name","searchRef","focusSearch","current","focus","showPatternPanel","showAsTabs","value"],"mappings":";;;;;;;;;AAQA;;AALA;;AAaA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;;;;;AAjCA;AACA;AACA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;AAaA,SAASA,YAAT,OAaCC,GAbD,EAcE;AAAA,MAbD;AACCC,IAAAA,YADD;AAECC,IAAAA,QAFD;AAGCC,IAAAA,UAHD;AAICC,IAAAA,4BAJD;AAKCC,IAAAA,QALD;AAMCC,IAAAA,qBAND;AAOCC,IAAAA,kBAPD;AAQCC,IAAAA,yBAAyB,GAAG,EAR7B;AASCC,IAAAA,gBAAgB,GAAG,IATpB;AAUCC,IAAAA;AAVD,GAaC;AACD,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBACvCJ,yBADuC,CAAxC;AAGA,QAAM,CAAEK,WAAF,EAAeC,cAAf,IAAkC,uBAAU,IAAV,CAAxC;AACA,QAAM,CAAEC,uBAAF,EAA2BC,0BAA3B,IACL,uBAAU,IAAV,CADD;AAEA,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,IAAV,CAAxC;AAEA,QAAM,CAAEC,uBAAF,EAA2BC,cAA3B,EAA2CC,sBAA3C,IACL,gCAAmB;AAClBpB,IAAAA,YADkB;AAElBC,IAAAA,QAFkB;AAGlBC,IAAAA,UAHkB;AAIlBmB,IAAAA,cAAc,EAAElB,4BAJE;AAKlBK,IAAAA;AALkB,GA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VnB;AAWC,IAAA,gBAAgB,EAAGK;AAXpB,IADD,CAjBF,EAiCG2C,UAAU,IACX,4BAAC,aAAD;AACC,IAAA,YAAY,EAAG7B,YADhB;AAEC,IAAA,kBAAkB,EAAGC,iBAFtB;AAGC,IAAA,kBAAkB,EAAGd,kBAHtB;AAIC,IAAA,QAAQ,EAAGQ;AAJZ,KAMG0B,aANH,CAlCF,EA2CG,CAAEjC,WAAF,IAAiB,CAAEyC,UAAnB,IACD;AAAK,IAAA,SAAS,EAAC;AAAf,KACGX,SADH,CA5CF,CADD,EAkDGnC,qBAAqB,IAAIO,WAAzB,IACD,4BAAC,qBAAD;AAAsB,IAAA,IAAI,EAAGA;AAA7B,IAnDF,EAqDGsC,gBAAgB,IACjB,4BAAC,6CAAD;AACC,IAAA,YAAY,EAAGhC,uBADhB;AAEC,IAAA,QAAQ,EAAGgB,eAFZ;AAGC,IAAA,QAAQ,EAAGpB;AAHZ,IAtDF,CADD;AA+DA;;eAEc,yBAAYhB,YAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tforwardRef,\n\tuseState,\n\tuseCallback,\n\tuseMemo,\n\tuseImperativeHandle,\n\tuseRef,\n} from '@wordpress/element';\nimport { VisuallyHidden, SearchControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport Tips from './tips';\nimport InserterPreviewPanel from './preview-panel';\nimport BlockTypesTab from './block-types-tab';\nimport BlockPatternsTabs, {\n\tBlockPatternsCategoryDialog,\n} from './block-patterns-tab';\nimport ReusableBlocksTab from './reusable-blocks-tab';\nimport InserterSearchResults from './search-results';\nimport useInsertionPoint from './hooks/use-insertion-point';\nimport InserterTabs from './tabs';\nimport { store as blockEditorStore } from '../../store';\n\nfunction InserterMenu(\n\t{\n\t\trootClientId,\n\t\tclientId,\n\t\tisAppender,\n\t\t__experimentalInsertionIndex,\n\t\tonSelect,\n\t\tshowInserterHelpPanel,\n\t\tshowMostUsedBlocks,\n\t\t__experimentalFilterValue = '',\n\t\tshouldFocusBlock = true,\n\t\tprioritizePatterns,\n\t},\n\tref\n) {\n\tconst [ filterValue, setFilterValue ] = useState(\n\t\t__experimentalFilterValue\n\t);\n\tconst [ hoveredItem, setHoveredItem ] = useState( null );\n\tconst [ selectedPatternCategory, setSelectedPatternCategory ] =\n\t\tuseState( null );\n\tconst [ selectedTab, setSelectedTab ] = useState( null );\n\n\tconst [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =\n\t\tuseInsertionPoint( {\n\t\t\trootClientId,\n\t\t\tclientId,\n\t\t\tisAppender,\n\t\t\tinsertionIndex: __experimentalInsertionIndex,\n\t\t\tshouldFocusBlock,\n\t\t} );\n\tconst { showPatterns, hasReusableBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __experimentalGetAllowedPatterns, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tshowPatterns: !! __experimentalGetAllowedPatterns(\n\t\t\t\t\tdestinationRootClientId\n\t\t\t\t).length,\n\t\t\t\thasReusableBlocks:\n\t\t\t\t\t!! getSettings().__experimentalReusableBlocks?.length,\n\t\t\t};\n\t\t},\n\t\t[ destinationRootClientId ]\n\t);\n\n\tconst onInsert = useCallback(\n\t\t( blocks, meta, shouldForceFocusBlock ) => {\n\t\t\tonInsertBlocks( blocks, meta, shouldForceFocusBlock );\n\t\t\tonSelect();\n\t\t},\n\t\t[ onInsertBlocks, onSelect ]\n\t);\n\n\tconst onInsertPattern = useCallback(\n\t\t( blocks, patternName ) => {\n\t\t\tonInsertBlocks( blocks, { patternName } );\n\t\t\tonSelect();\n\t\t},\n\t\t[ onInsertBlocks, onSelect ]\n\t);\n\n\tconst onHover = useCallback(\n\t\t( item ) => {\n\t\t\tonToggleInsertionPoint( !! item );\n\t\t\tsetHoveredItem( item );\n\t\t},\n\t\t[ onToggleInsertionPoint, setHoveredItem ]\n\t);\n\n\tconst onClickPatternCategory = useCallback(\n\t\t( patternCategory ) => {\n\t\t\tsetSelectedPatternCategory( patternCategory );\n\t\t},\n\t\t[ setSelectedPatternCategory ]\n\t);\n\n\tconst blocksTab = useMemo(\n\t\t() => (\n\t\t\t<>\n\t\t\t\t<div className=\"block-editor-inserter__block-list\">\n\t\t\t\t\t<BlockTypesTab\n\t\t\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\tshowMostUsedBlocks={ showMostUsedBlocks }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t{ showInserterHelpPanel && (\n\t\t\t\t\t<div className=\"block-editor-inserter__tips\">\n\t\t\t\t\t\t<VisuallyHidden as=\"h2\">\n\t\t\t\t\t\t\t{ __( 'A tip for using the block editor' ) }\n\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t<Tips />\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\t[\n\t\t\tdestinationRootClientId,\n\t\t\tonInsert,\n\t\t\tonHover,\n\t\t\tfilterValue,\n\t\t\tshowMostUsedBlocks,\n\t\t\tshowInserterHelpPanel,\n\t\t]\n\t);\n\n\tconst patternsTab = useMemo(\n\t\t() => (\n\t\t\t<BlockPatternsTabs\n\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\tonInsert={ onInsertPattern }\n\t\t\t\tonSelectCategory={ onClickPatternCategory }\n\t\t\t\tselectedCategory={ selectedPatternCategory }\n\t\t\t/>\n\t\t),\n\t\t[\n\t\t\tdestinationRootClientId,\n\t\t\tonInsertPattern,\n\t\t\tonClickPatternCategory,\n\t\t\tselectedPatternCategory,\n\t\t]\n\t);\n\n\tconst reusableBlocksTab = useMemo(\n\t\t() => (\n\t\t\t<ReusableBlocksTab\n\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\tonInsert={ onInsert }\n\t\t\t\tonHover={ onHover }\n\t\t\t/>\n\t\t),\n\t\t[ destinationRootClientId, onInsert, onHover ]\n\t);\n\n\tconst getCurrentTab = useCallback(\n\t\t( tab ) => {\n\t\t\tif ( tab.name === 'blocks' ) {\n\t\t\t\treturn blocksTab;\n\t\t\t} else if ( tab.name === 'patterns' ) {\n\t\t\t\treturn patternsTab;\n\t\t\t}\n\t\t\treturn reusableBlocksTab;\n\t\t},\n\t\t[ blocksTab, patternsTab, reusableBlocksTab ]\n\t);\n\n\tconst searchRef = useRef();\n\tuseImperativeHandle( ref, () => ( {\n\t\tfocusSearch: () => {\n\t\t\tsearchRef.current.focus();\n\t\t},\n\t} ) );\n\n\tconst showPatternPanel =\n\t\tselectedTab === 'patterns' && ! filterValue && selectedPatternCategory;\n\tconst showAsTabs = ! filterValue && ( showPatterns || hasReusableBlocks );\n\n\treturn (\n\t\t<div className=\"block-editor-inserter__menu\">\n\t\t\t<div\n\t\t\t\tclassName={ classnames( 'block-editor-inserter__main-area', {\n\t\t\t\t\t'show-as-tabs': showAsTabs,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<SearchControl\n\t\t\t\t\tclassName=\"block-editor-inserter__search\"\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tif ( hoveredItem ) setHoveredItem( null );\n\t\t\t\t\t\tsetFilterValue( value );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ filterValue }\n\t\t\t\t\tlabel={ __( 'Search for blocks and patterns' ) }\n\t\t\t\t\tplaceholder={ __( 'Search' ) }\n\t\t\t\t\tref={ searchRef }\n\t\t\t\t/>\n\t\t\t\t{ !! filterValue && (\n\t\t\t\t\t<div className=\"block-editor-inserter__no-tab-container\">\n\t\t\t\t\t\t<InserterSearchResults\n\t\t\t\t\t\t\tfilterValue={ filterValue }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tisAppender={ isAppender }\n\t\t\t\t\t\t\t__experimentalInsertionIndex={\n\t\t\t\t\t\t\t\t__experimentalInsertionIndex\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tshowBlockDirectory\n\t\t\t\t\t\t\tshouldFocusBlock={ shouldFocusBlock }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ showAsTabs && (\n\t\t\t\t\t<InserterTabs\n\t\t\t\t\t\tshowPatterns={ showPatterns }\n\t\t\t\t\t\tshowReusableBlocks={ hasReusableBlocks }\n\t\t\t\t\t\tprioritizePatterns={ prioritizePatterns }\n\t\t\t\t\t\tonSelect={ setSelectedTab }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ getCurrentTab }\n\t\t\t\t\t</InserterTabs>\n\t\t\t\t) }\n\t\t\t\t{ ! filterValue && ! showAsTabs && (\n\t\t\t\t\t<div className=\"block-editor-inserter__no-tab-container\">\n\t\t\t\t\t\t{ blocksTab }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ showInserterHelpPanel && hoveredItem && (\n\t\t\t\t<InserterPreviewPanel item={ hoveredItem } />\n\t\t\t) }\n\t\t\t{ showPatternPanel && (\n\t\t\t\t<BlockPatternsCategoryDialog\n\t\t\t\t\trootClientId={ destinationRootClientId }\n\t\t\t\t\tonInsert={ onInsertPattern }\n\t\t\t\t\tcategory={ selectedPatternCategory }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default forwardRef( InserterMenu );\n"]}
|
|
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.getItemSearchRank = getItemSearchRank;
|
|
9
9
|
exports.searchItems = exports.searchBlockItems = exports.getNormalizedSearchTerms = void 0;
|
|
10
10
|
|
|
11
|
-
var _changeCase = require("change-case");
|
|
12
|
-
|
|
13
11
|
var _removeAccents = _interopRequireDefault(require("remove-accents"));
|
|
14
12
|
|
|
15
13
|
var _lodash = require("lodash");
|
|
@@ -51,19 +49,6 @@ function normalizeSearchInput() {
|
|
|
51
49
|
input = input.toLowerCase();
|
|
52
50
|
return input;
|
|
53
51
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Extracts words from an input string.
|
|
56
|
-
*
|
|
57
|
-
* @param {string} input The input string.
|
|
58
|
-
*
|
|
59
|
-
* @return {Array} Words, extracted from the input string.
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
function extractWords() {
|
|
64
|
-
let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
65
|
-
return (0, _changeCase.noCase)(input).split(' ').filter(Boolean);
|
|
66
|
-
}
|
|
67
52
|
/**
|
|
68
53
|
* Converts the search term into a list of normalized terms.
|
|
69
54
|
*
|
|
@@ -75,7 +60,7 @@ function extractWords() {
|
|
|
75
60
|
|
|
76
61
|
const getNormalizedSearchTerms = function () {
|
|
77
62
|
let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
78
|
-
return
|
|
63
|
+
return (0, _lodash.words)(normalizeSearchInput(input));
|
|
79
64
|
};
|
|
80
65
|
|
|
81
66
|
exports.getNormalizedSearchTerms = getNormalizedSearchTerms;
|
|
@@ -189,7 +174,7 @@ function getItemSearchRank(item, searchTerm) {
|
|
|
189
174
|
rank += 20;
|
|
190
175
|
} else {
|
|
191
176
|
const terms = [name, title, description, ...keywords, category, collection].join(' ');
|
|
192
|
-
const normalizedSearchTerms =
|
|
177
|
+
const normalizedSearchTerms = (0, _lodash.words)(normalizedSearchInput);
|
|
193
178
|
const unmatchedTerms = removeMatchingTerms(normalizedSearchTerms, terms);
|
|
194
179
|
|
|
195
180
|
if (unmatchedTerms.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/search-items.js"],"names":["defaultGetName","item","name","defaultGetTitle","title","defaultGetDescription","description","defaultGetKeywords","keywords","defaultGetCategory","category","defaultGetCollection","normalizeSearchInput","input","replace","toLowerCase","extractWords","split","filter","Boolean","getNormalizedSearchTerms","removeMatchingTerms","unmatchedTerms","unprocessedTerms","term","some","unprocessedTerm","includes","searchBlockItems","items","categories","collections","searchInput","normalizedSearchTerms","length","config","getCategory","slug","getCollection","searchItems","rankedItems","map","getItemSearchRank","rank","sort","rank1","rank2","searchTerm","getName","getTitle","getDescription","getKeywords","collection","normalizedSearchInput","normalizedTitle","startsWith","terms","join","isCoreBlockVariation","id"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKA;AACA,MAAMA,cAAc,GAAKC,IAAF,IAAYA,IAAI,CAACC,IAAL,IAAa,EAAhD;;AACA,MAAMC,eAAe,GAAKF,IAAF,IAAYA,IAAI,CAACG,KAAzC;;AACA,MAAMC,qBAAqB,GAAKJ,IAAF,IAAYA,IAAI,CAACK,WAAL,IAAoB,EAA9D;;AACA,MAAMC,kBAAkB,GAAKN,IAAF,IAAYA,IAAI,CAACO,QAAL,IAAiB,EAAxD;;AACA,MAAMC,kBAAkB,GAAKR,IAAF,IAAYA,IAAI,CAACS,QAA5C;;AACA,MAAMC,oBAAoB,GAAG,MAAM,IAAnC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,oBAAT,GAA4C;AAAA,MAAbC,KAAa,uEAAL,EAAK;AAC3C;AACA;AACAA,EAAAA,KAAK,GAAG,4BAAeA,KAAf,CAAR,CAH2C,CAK3C;AACA;;AACAA,EAAAA,KAAK,GAAGA,KAAK,CAACC,OAAN,CAAe,KAAf,EAAsB,EAAtB,CAAR,CAP2C,CAS3C;AACA;;AACAD,EAAAA,KAAK,GAAGA,KAAK,CAACE,WAAN,EAAR;AAEA,SAAOF,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,YAAT,GAAoC;AAAA,MAAbH,KAAa,uE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AgD;AAC/C,UAAMG,oBAAoB,GAAGxD,IAAI,KAAKD,IAAI,CAAC0D,EAA3C,CAD+C,CAE/C;;AACAhB,IAAAA,IAAI,IAAIe,oBAAoB,GAAG,CAAH,GAAO,CAAnC;AACA;;AAED,SAAOf,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { noCase } from 'change-case';\nimport removeAccents from 'remove-accents';\nimport { find } from 'lodash';\n\n// Default search helpers.\nconst defaultGetName = ( item ) => item.name || '';\nconst defaultGetTitle = ( item ) => item.title;\nconst defaultGetDescription = ( item ) => item.description || '';\nconst defaultGetKeywords = ( item ) => item.keywords || [];\nconst defaultGetCategory = ( item ) => item.category;\nconst defaultGetCollection = () => null;\n\n/**\n * Sanitizes the search input string.\n *\n * @param {string} input The search input to normalize.\n *\n * @return {string} The normalized search input.\n */\nfunction normalizeSearchInput( input = '' ) {\n\t// Disregard diacritics.\n\t// Input: \"média\"\n\tinput = removeAccents( input );\n\n\t// Accommodate leading slash, matching autocomplete expectations.\n\t// Input: \"/media\"\n\tinput = input.replace( /^\\//, '' );\n\n\t// Lowercase.\n\t// Input: \"MEDIA\"\n\tinput = input.toLowerCase();\n\n\treturn input;\n}\n\n/**\n * Extracts words from an input string.\n *\n * @param {string} input The input string.\n *\n * @return {Array} Words, extracted from the input string.\n */\nfunction extractWords( input = '' ) {\n\treturn noCase( input ).split( ' ' ).filter( Boolean );\n}\n\n/**\n * Converts the search term into a list of normalized terms.\n *\n * @param {string} input The search term to normalize.\n *\n * @return {string[]} The normalized list of search terms.\n */\nexport const getNormalizedSearchTerms = ( input = '' ) => {\n\treturn extractWords( normalizeSearchInput( input ) );\n};\n\nconst removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => {\n\treturn unmatchedTerms.filter(\n\t\t( term ) =>\n\t\t\t! getNormalizedSearchTerms( unprocessedTerms ).some(\n\t\t\t\t( unprocessedTerm ) => unprocessedTerm.includes( term )\n\t\t\t)\n\t);\n};\n\nexport const searchBlockItems = (\n\titems,\n\tcategories,\n\tcollections,\n\tsearchInput\n) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst config = {\n\t\tgetCategory: ( item ) =>\n\t\t\tfind( categories, { slug: item.category } )?.title,\n\t\tgetCollection: ( item ) =>\n\t\t\tcollections[ item.name.split( '/' )[ 0 ] ]?.title,\n\t};\n\n\treturn searchItems( items, searchInput, config );\n};\n\n/**\n * Filters an item list given a search term.\n *\n * @param {Array} items Item list\n * @param {string} searchInput Search input.\n * @param {Object} config Search Config.\n *\n * @return {Array} Filtered item list.\n */\nexport const searchItems = ( items = [], searchInput = '', config = {} ) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst rankedItems = items\n\t\t.map( ( item ) => {\n\t\t\treturn [ item, getItemSearchRank( item, searchInput, config ) ];\n\t\t} )\n\t\t.filter( ( [ , rank ] ) => rank > 0 );\n\n\trankedItems.sort( ( [ , rank1 ], [ , rank2 ] ) => rank2 - rank1 );\n\treturn rankedItems.map( ( [ item ] ) => item );\n};\n\n/**\n * Get the search rank for a given item and a specific search term.\n * The better the match, the higher the rank.\n * If the rank equals 0, it should be excluded from the results.\n *\n * @param {Object} item Item to filter.\n * @param {string} searchTerm Search term.\n * @param {Object} config Search Config.\n *\n * @return {number} Search Rank.\n */\nexport function getItemSearchRank( item, searchTerm, config = {} ) {\n\tconst {\n\t\tgetName = defaultGetName,\n\t\tgetTitle = defaultGetTitle,\n\t\tgetDescription = defaultGetDescription,\n\t\tgetKeywords = defaultGetKeywords,\n\t\tgetCategory = defaultGetCategory,\n\t\tgetCollection = defaultGetCollection,\n\t} = config;\n\n\tconst name = getName( item );\n\tconst title = getTitle( item );\n\tconst description = getDescription( item );\n\tconst keywords = getKeywords( item );\n\tconst category = getCategory( item );\n\tconst collection = getCollection( item );\n\n\tconst normalizedSearchInput = normalizeSearchInput( searchTerm );\n\tconst normalizedTitle = normalizeSearchInput( title );\n\n\tlet rank = 0;\n\n\t// Prefers exact matches\n\t// Then prefers if the beginning of the title matches the search term\n\t// name, keywords, categories, collection, variations match come later.\n\tif ( normalizedSearchInput === normalizedTitle ) {\n\t\trank += 30;\n\t} else if ( normalizedTitle.startsWith( normalizedSearchInput ) ) {\n\t\trank += 20;\n\t} else {\n\t\tconst terms = [\n\t\t\tname,\n\t\t\ttitle,\n\t\t\tdescription,\n\t\t\t...keywords,\n\t\t\tcategory,\n\t\t\tcollection,\n\t\t].join( ' ' );\n\t\tconst normalizedSearchTerms = extractWords( normalizedSearchInput );\n\t\tconst unmatchedTerms = removeMatchingTerms(\n\t\t\tnormalizedSearchTerms,\n\t\t\tterms\n\t\t);\n\n\t\tif ( unmatchedTerms.length === 0 ) {\n\t\t\trank += 10;\n\t\t}\n\t}\n\n\t// Give a better rank to \"core\" namespaced items.\n\tif ( rank !== 0 && name.startsWith( 'core/' ) ) {\n\t\tconst isCoreBlockVariation = name !== item.id;\n\t\t// Give a bit better rank to \"core\" blocks over \"core\" block variations.\n\t\trank += isCoreBlockVariation ? 1 : 2;\n\t}\n\n\treturn rank;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/search-items.js"],"names":["defaultGetName","item","name","defaultGetTitle","title","defaultGetDescription","description","defaultGetKeywords","keywords","defaultGetCategory","category","defaultGetCollection","normalizeSearchInput","input","replace","toLowerCase","getNormalizedSearchTerms","removeMatchingTerms","unmatchedTerms","unprocessedTerms","filter","term","some","unprocessedTerm","includes","searchBlockItems","items","categories","collections","searchInput","normalizedSearchTerms","length","config","getCategory","slug","getCollection","split","searchItems","rankedItems","map","getItemSearchRank","rank","sort","rank1","rank2","searchTerm","getName","getTitle","getDescription","getKeywords","collection","normalizedSearchInput","normalizedTitle","startsWith","terms","join","isCoreBlockVariation","id"],"mappings":";;;;;;;;;;AAGA;;AAC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eAA/B,EAAiD;AAChDX,IAAAA,IAAI,IAAI,EAAR;AACA,GAFD,MAEO,IAAKW,eAAe,CAACC,UAAhB,CAA4BF,qBAA5B,CAAL,EAA2D;AACjEV,IAAAA,IAAI,IAAI,EAAR;AACA,GAFM,MAEA;AACN,UAAMa,KAAK,GAAG,CACbpD,IADa,EAEbE,KAFa,EAGbE,WAHa,EAIb,GAAGE,QAJU,EAKbE,QALa,EAMbwC,UANa,EAOZK,IAPY,CAON,GAPM,CAAd;AAQA,UAAMzB,qBAAqB,GAAG,mBAAOqB,qBAAP,CAA9B;AACA,UAAMjC,cAAc,GAAGD,mBAAmB,CACzCa,qBADyC,EAEzCwB,KAFyC,CAA1C;;AAKA,QAAKpC,cAAc,CAACa,MAAf,KAA0B,CAA/B,EAAmC;AAClCU,MAAAA,IAAI,IAAI,EAAR;AACA;AACD,GA/CiE,CAiDlE;;;AACA,MAAKA,IAAI,KAAK,CAAT,IAAcvC,IAAI,CAACmD,UAAL,CAAiB,OAAjB,CAAnB,EAAgD;AAC/C,UAAMG,oBAAoB,GAAGtD,IAAI,KAAKD,IAAI,CAACwD,EAA3C,CAD+C,CAE/C;;AACAhB,IAAAA,IAAI,IAAIe,oBAAoB,GAAG,CAAH,GAAO,CAAnC;AACA;;AAED,SAAOf,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\nimport { find, words } from 'lodash';\n\n// Default search helpers.\nconst defaultGetName = ( item ) => item.name || '';\nconst defaultGetTitle = ( item ) => item.title;\nconst defaultGetDescription = ( item ) => item.description || '';\nconst defaultGetKeywords = ( item ) => item.keywords || [];\nconst defaultGetCategory = ( item ) => item.category;\nconst defaultGetCollection = () => null;\n\n/**\n * Sanitizes the search input string.\n *\n * @param {string} input The search input to normalize.\n *\n * @return {string} The normalized search input.\n */\nfunction normalizeSearchInput( input = '' ) {\n\t// Disregard diacritics.\n\t// Input: \"média\"\n\tinput = removeAccents( input );\n\n\t// Accommodate leading slash, matching autocomplete expectations.\n\t// Input: \"/media\"\n\tinput = input.replace( /^\\//, '' );\n\n\t// Lowercase.\n\t// Input: \"MEDIA\"\n\tinput = input.toLowerCase();\n\n\treturn input;\n}\n\n/**\n * Converts the search term into a list of normalized terms.\n *\n * @param {string} input The search term to normalize.\n *\n * @return {string[]} The normalized list of search terms.\n */\nexport const getNormalizedSearchTerms = ( input = '' ) => {\n\treturn words( normalizeSearchInput( input ) );\n};\n\nconst removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => {\n\treturn unmatchedTerms.filter(\n\t\t( term ) =>\n\t\t\t! getNormalizedSearchTerms( unprocessedTerms ).some(\n\t\t\t\t( unprocessedTerm ) => unprocessedTerm.includes( term )\n\t\t\t)\n\t);\n};\n\nexport const searchBlockItems = (\n\titems,\n\tcategories,\n\tcollections,\n\tsearchInput\n) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst config = {\n\t\tgetCategory: ( item ) =>\n\t\t\tfind( categories, { slug: item.category } )?.title,\n\t\tgetCollection: ( item ) =>\n\t\t\tcollections[ item.name.split( '/' )[ 0 ] ]?.title,\n\t};\n\n\treturn searchItems( items, searchInput, config );\n};\n\n/**\n * Filters an item list given a search term.\n *\n * @param {Array} items Item list\n * @param {string} searchInput Search input.\n * @param {Object} config Search Config.\n *\n * @return {Array} Filtered item list.\n */\nexport const searchItems = ( items = [], searchInput = '', config = {} ) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst rankedItems = items\n\t\t.map( ( item ) => {\n\t\t\treturn [ item, getItemSearchRank( item, searchInput, config ) ];\n\t\t} )\n\t\t.filter( ( [ , rank ] ) => rank > 0 );\n\n\trankedItems.sort( ( [ , rank1 ], [ , rank2 ] ) => rank2 - rank1 );\n\treturn rankedItems.map( ( [ item ] ) => item );\n};\n\n/**\n * Get the search rank for a given item and a specific search term.\n * The better the match, the higher the rank.\n * If the rank equals 0, it should be excluded from the results.\n *\n * @param {Object} item Item to filter.\n * @param {string} searchTerm Search term.\n * @param {Object} config Search Config.\n *\n * @return {number} Search Rank.\n */\nexport function getItemSearchRank( item, searchTerm, config = {} ) {\n\tconst {\n\t\tgetName = defaultGetName,\n\t\tgetTitle = defaultGetTitle,\n\t\tgetDescription = defaultGetDescription,\n\t\tgetKeywords = defaultGetKeywords,\n\t\tgetCategory = defaultGetCategory,\n\t\tgetCollection = defaultGetCollection,\n\t} = config;\n\n\tconst name = getName( item );\n\tconst title = getTitle( item );\n\tconst description = getDescription( item );\n\tconst keywords = getKeywords( item );\n\tconst category = getCategory( item );\n\tconst collection = getCollection( item );\n\n\tconst normalizedSearchInput = normalizeSearchInput( searchTerm );\n\tconst normalizedTitle = normalizeSearchInput( title );\n\n\tlet rank = 0;\n\n\t// Prefers exact matches\n\t// Then prefers if the beginning of the title matches the search term\n\t// name, keywords, categories, collection, variations match come later.\n\tif ( normalizedSearchInput === normalizedTitle ) {\n\t\trank += 30;\n\t} else if ( normalizedTitle.startsWith( normalizedSearchInput ) ) {\n\t\trank += 20;\n\t} else {\n\t\tconst terms = [\n\t\t\tname,\n\t\t\ttitle,\n\t\t\tdescription,\n\t\t\t...keywords,\n\t\t\tcategory,\n\t\t\tcollection,\n\t\t].join( ' ' );\n\t\tconst normalizedSearchTerms = words( normalizedSearchInput );\n\t\tconst unmatchedTerms = removeMatchingTerms(\n\t\t\tnormalizedSearchTerms,\n\t\t\tterms\n\t\t);\n\n\t\tif ( unmatchedTerms.length === 0 ) {\n\t\t\trank += 10;\n\t\t}\n\t}\n\n\t// Give a better rank to \"core\" namespaced items.\n\tif ( rank !== 0 && name.startsWith( 'core/' ) ) {\n\t\tconst isCoreBlockVariation = name !== item.id;\n\t\t// Give a bit better rank to \"core\" blocks over \"core\" block variations.\n\t\trank += isCoreBlockVariation ? 1 : 2;\n\t}\n\n\treturn rank;\n}\n"]}
|
|
@@ -25,7 +25,8 @@ const InserterDraggableBlocks = _ref => {
|
|
|
25
25
|
isEnabled,
|
|
26
26
|
blocks,
|
|
27
27
|
icon,
|
|
28
|
-
children
|
|
28
|
+
children,
|
|
29
|
+
isPattern
|
|
29
30
|
} = _ref;
|
|
30
31
|
const transferData = {
|
|
31
32
|
type: 'inserter',
|
|
@@ -36,7 +37,8 @@ const InserterDraggableBlocks = _ref => {
|
|
|
36
37
|
transferData: transferData,
|
|
37
38
|
__experimentalDragComponent: (0, _element.createElement)(_draggableChip.default, {
|
|
38
39
|
count: blocks.length,
|
|
39
|
-
icon: icon
|
|
40
|
+
icon: icon,
|
|
41
|
+
isPattern: isPattern
|
|
40
42
|
})
|
|
41
43
|
}, _ref2 => {
|
|
42
44
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter-draggable-blocks/index.js"],"names":["InserterDraggableBlocks","isEnabled","blocks","icon","children","transferData","type","length","onDraggableStart","onDraggableEnd","draggable","onDragStart","undefined","onDragEnd"],"mappings":";;;;;;;;;;;AAGA;;AAIA;;AAPA;AACA;AACA;;AAEA;AACA;AACA;AAGA,MAAMA,uBAAuB,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter-draggable-blocks/index.js"],"names":["InserterDraggableBlocks","isEnabled","blocks","icon","children","isPattern","transferData","type","length","onDraggableStart","onDraggableEnd","draggable","onDragStart","undefined","onDragEnd"],"mappings":";;;;;;;;;;;AAGA;;AAIA;;AAPA;AACA;AACA;;AAEA;AACA;AACA;AAGA,MAAMA,uBAAuB,GAAG,QAMzB;AAAA,MAN2B;AACjCC,IAAAA,SADiC;AAEjCC,IAAAA,MAFiC;AAGjCC,IAAAA,IAHiC;AAIjCC,IAAAA,QAJiC;AAKjCC,IAAAA;AALiC,GAM3B;AACN,QAAMC,YAAY,GAAG;AACpBC,IAAAA,IAAI,EAAE,UADc;AAEpBL,IAAAA;AAFoB,GAArB;AAKA,SACC,4BAAC,qBAAD;AACC,IAAA,8BAA8B,EAAC,WADhC;AAEC,IAAA,YAAY,EAAGI,YAFhB;AAGC,IAAA,2BAA2B,EAC1B,4BAAC,sBAAD;AACC,MAAA,KAAK,EAAGJ,MAAM,CAACM,MADhB;AAEC,MAAA,IAAI,EAAGL,IAFR;AAGC,MAAA,SAAS,EAAGE;AAHb;AAJF,KAWG,SAA4C;AAAA,QAA1C;AAAEI,MAAAA,gBAAF;AAAoBC,MAAAA;AAApB,KAA0C;AAC7C,WAAON,QAAQ,CAAE;AAChBO,MAAAA,SAAS,EAAEV,SADK;AAEhBW,MAAAA,WAAW,EAAEX,SAAS,GAAGQ,gBAAH,GAAsBI,SAF5B;AAGhBC,MAAAA,SAAS,EAAEb,SAAS,GAAGS,cAAH,GAAoBG;AAHxB,KAAF,CAAf;AAKA,GAjBF,CADD;AAqBA,CAjCD;;eAmCeb,uB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Draggable } from '@wordpress/components';\n/**\n * Internal dependencies\n */\nimport BlockDraggableChip from '../block-draggable/draggable-chip';\n\nconst InserterDraggableBlocks = ( {\n\tisEnabled,\n\tblocks,\n\ticon,\n\tchildren,\n\tisPattern,\n} ) => {\n\tconst transferData = {\n\t\ttype: 'inserter',\n\t\tblocks,\n\t};\n\n\treturn (\n\t\t<Draggable\n\t\t\t__experimentalTransferDataType=\"wp-blocks\"\n\t\t\ttransferData={ transferData }\n\t\t\t__experimentalDragComponent={\n\t\t\t\t<BlockDraggableChip\n\t\t\t\t\tcount={ blocks.length }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tisPattern={ isPattern }\n\t\t\t\t/>\n\t\t\t}\n\t\t>\n\t\t\t{ ( { onDraggableStart, onDraggableEnd } ) => {\n\t\t\t\treturn children( {\n\t\t\t\t\tdraggable: isEnabled,\n\t\t\t\t\tonDragStart: isEnabled ? onDraggableStart : undefined,\n\t\t\t\t\tonDragEnd: isEnabled ? onDraggableEnd : undefined,\n\t\t\t\t} );\n\t\t\t} }\n\t\t</Draggable>\n\t);\n};\n\nexport default InserterDraggableBlocks;\n"]}
|
|
@@ -38,13 +38,14 @@ function InspectorControlsSlot(_ref) {
|
|
|
38
38
|
} = _ref;
|
|
39
39
|
const Slot = (_groups$group = _groups.default[group]) === null || _groups$group === void 0 ? void 0 : _groups$group.Slot;
|
|
40
40
|
const slot = (0, _components.__experimentalUseSlot)(Slot === null || Slot === void 0 ? void 0 : Slot.__unstableName);
|
|
41
|
+
const fills = (0, _components.__experimentalUseSlotFills)(Slot === null || Slot === void 0 ? void 0 : Slot.__unstableName);
|
|
41
42
|
|
|
42
43
|
if (!Slot || !slot) {
|
|
43
44
|
typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" ? (0, _warning.default)(`Unknown InspectorControl group "${group}" provided.`) : void 0;
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
const hasFills = Boolean(
|
|
48
|
+
const hasFills = Boolean(fills && fills.length);
|
|
48
49
|
|
|
49
50
|
if (!hasFills) {
|
|
50
51
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inspector-controls/slot.js"],"names":["InspectorControlsSlot","__experimentalGroup","group","label","props","Slot","groups","slot","__unstableName","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inspector-controls/slot.js"],"names":["InspectorControlsSlot","__experimentalGroup","group","label","props","Slot","groups","slot","__unstableName","fills","hasFills","Boolean","length"],"mappings":";;;;;;;;;;;;;AAGA;;AAIA;;AAKA;;AACA;;AACA;;AAdA;AACA;AACA;;AAOA;AACA;AACA;AAKe,SAASA,qBAAT,OAIX;AAAA;;AAAA,MAJ2C;AAC9CC,IAAAA,mBAAmB,EAAEC,KAAK,GAAG,SADiB;AAE9CC,IAAAA,KAF8C;AAG9C,OAAGC;AAH2C,GAI3C;AACH,QAAMC,IAAI,oBAAGC,gBAAQJ,KAAR,CAAH,kDAAG,cAAiBG,IAA9B;AACA,QAAME,IAAI,GAAG,uCAASF,IAAT,aAASA,IAAT,uBAASA,IAAI,CAAEG,cAAf,CAAb;AACA,QAAMC,KAAK,GAAG,4CAAcJ,IAAd,aAAcA,IAAd,uBAAcA,IAAI,CAAEG,cAApB,CAAd;;AACA,MAAK,CAAEH,IAAF,IAAU,CAAEE,IAAjB,EAAwB;AACvB,mHAAU,mCAAmCL,KAAO,aAApD;AACA,WAAO,IAAP;AACA;;AAED,QAAMQ,QAAQ,GAAGC,OAAO,CAAEF,KAAK,IAAIA,KAAK,CAACG,MAAjB,CAAxB;;AACA,MAAK,CAAEF,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,MAAKP,KAAL,EAAa;AACZ,WACC,4BAAC,+BAAD;AAAwB,MAAA,KAAK,EAAGD,KAAhC;AAAwC,MAAA,KAAK,EAAGC;AAAhD,OACC,4BAAC,kCAAD,6BAAgCC,KAAhC;AAAwC,MAAA,IAAI,EAAGC;AAA/C,OADD,CADD;AAKA;;AAED,SAAO,4BAAC,IAAD,6BAAWD,KAAX;AAAmB,IAAA,gBAAgB;AAAnC,KAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalUseSlot as useSlot,\n\t__experimentalUseSlotFills as useSlotFills,\n} from '@wordpress/components';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport BlockSupportToolsPanel from './block-support-tools-panel';\nimport BlockSupportSlotContainer from './block-support-slot-container';\nimport groups from './groups';\n\nexport default function InspectorControlsSlot( {\n\t__experimentalGroup: group = 'default',\n\tlabel,\n\t...props\n} ) {\n\tconst Slot = groups[ group ]?.Slot;\n\tconst slot = useSlot( Slot?.__unstableName );\n\tconst fills = useSlotFills( Slot?.__unstableName );\n\tif ( ! Slot || ! slot ) {\n\t\twarning( `Unknown InspectorControl group \"${ group }\" provided.` );\n\t\treturn null;\n\t}\n\n\tconst hasFills = Boolean( fills && fills.length );\n\tif ( ! hasFills ) {\n\t\treturn null;\n\t}\n\n\tif ( label ) {\n\t\treturn (\n\t\t\t<BlockSupportToolsPanel group={ group } label={ label }>\n\t\t\t\t<BlockSupportSlotContainer { ...props } Slot={ Slot } />\n\t\t\t</BlockSupportToolsPanel>\n\t\t);\n\t}\n\n\treturn <Slot { ...props } bubblesVirtually />;\n}\n"]}
|
|
@@ -60,17 +60,6 @@ var _store = require("../../store");
|
|
|
60
60
|
* 'inside' refers to nesting as an inner block.
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* Is the point contained by the rectangle.
|
|
65
|
-
*
|
|
66
|
-
* @param {WPPoint} point The point.
|
|
67
|
-
* @param {DOMRect} rect The rectangle.
|
|
68
|
-
*
|
|
69
|
-
* @return {boolean} True if the point is contained by the rectangle, false otherwise.
|
|
70
|
-
*/
|
|
71
|
-
function isPointContainedByRect(point, rect) {
|
|
72
|
-
return rect.left <= point.x && rect.right >= point.x && rect.top <= point.y && rect.bottom >= point.y;
|
|
73
|
-
}
|
|
74
63
|
/**
|
|
75
64
|
* Determines whether the user positioning the dragged block to nest as an
|
|
76
65
|
* inner block.
|
|
@@ -81,8 +70,6 @@ function isPointContainedByRect(point, rect) {
|
|
|
81
70
|
* @param {WPPoint} point The point representing the cursor position when dragging.
|
|
82
71
|
* @param {DOMRect} rect The rectangle.
|
|
83
72
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
73
|
function isNestingGesture(point, rect) {
|
|
87
74
|
const blockCenterX = rect.left + rect.width / 2;
|
|
88
75
|
return point.x > blockCenterX;
|
|
@@ -113,7 +100,7 @@ function getListViewDropTarget(blocksData, position) {
|
|
|
113
100
|
|
|
114
101
|
const rect = blockData.element.getBoundingClientRect();
|
|
115
102
|
const [distance, edge] = (0, _math.getDistanceToNearestEdge)(position, rect, ALLOWED_DROP_EDGES);
|
|
116
|
-
const isCursorWithinBlock = isPointContainedByRect(position, rect);
|
|
103
|
+
const isCursorWithinBlock = (0, _math.isPointContainedByRect)(position, rect);
|
|
117
104
|
|
|
118
105
|
if (candidateDistance === undefined || distance < candidateDistance || isCursorWithinBlock) {
|
|
119
106
|
candidateDistance = distance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["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","blockEditorStore","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":";;;;;;;;;AAGA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AAfA;AACA;AACA;;AAQA;AACA;AACA;;AAKA;;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,SAASA,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SACCA,IAAI,CAACC,IAAL,IAAaF,KAAK,CAACG,CAAnB,IACAF,IAAI,CAACG,KAAL,IAAcJ,KAAK,CAACG,CADpB,IAEAF,IAAI,CAACI,GAAL,IAAYL,KAA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,QAAtB,CAAgCjC,QAAhC,CADwB,GAExB,KAPG;AAQND,QAAAA,eAAe,EAAES,aAAa,CAAER,QAAF,CARxB;AASNG,QAAAA,+BAA+B,EAAEoB,WAAW,GACzCb,eAAe,CACfO,qBADe,EAEfrB,YAFe,CAD0B,GAKzC,IAdG;AAeNE,QAAAA,6BAA6B,EAAEyB,WAAW,GACvCb,eAAe,CAAEO,qBAAF,EAAyBjB,QAAzB,CADwB,GAEvC;AAjBG,OAAP;AAmBA,KAvBkB,CAAnB;AAyBA,UAAMkC,SAAS,GAAGxD,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKsD,SAAL,EAAiB;AAChBrB,MAAAA,SAAS,CAAEqB,SAAF,CAAT;AACA;AACD,GAvCF,EAwCC,CAAEjB,qBAAF,CAxCD,CADiB,EA2CjB,GA3CiB,CAAlB;AA8CA,QAAMkB,GAAG,GAAG,wCAAa;AACxBC,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,GAAb,CAAZ;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":["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","blockEditorStore","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":";;;;;;;;;AAGA;;AACA;;AACA;;AAQA;;AAIA;;AACA;;AAlBA;AACA;AACA;;AAQA;AACA;AACA;;AAQA;;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;AACA;AACA,SAASA,gBAAT,CAA2BC,KAA3B,EAAkCC,IAAlC,EAAyC;AACxC,QAAMC,YAAY,GAAGD,IAAI,CAACE,IAAL,GAAYF,IAAI,CAACG,KAAL,GAAa,CAA9C;AACA,SAAOJ,KAAK,CAACK,CAAN,GAAUH,YAAjB;AACA,C,CAED;AACA;;;AACA,MAAMI,kBAAkB,GAAG,CAA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,EAAcC,QAAd,CAAvC;;AAEA,QAAKuD,SAAL,EAAiB;AAChBtB,MAAAA,SAAS,CAAEsB,SAAF,CAAT;AACA;AACD,GAvCF,EAwCC,CAAElB,qBAAF,CAxCD,CADiB,EA2CjB,GA3CiB,CAAlB;AA8CA,QAAMmB,GAAG,GAAG,wCAAa;AACxBC,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,GAAb,CAAZ;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"]}
|
|
@@ -29,6 +29,7 @@ var _icons = require("@wordpress/icons");
|
|
|
29
29
|
function PreviewOptions(_ref) {
|
|
30
30
|
let {
|
|
31
31
|
children,
|
|
32
|
+
viewLabel,
|
|
32
33
|
className,
|
|
33
34
|
isEnabled = true,
|
|
34
35
|
deviceType,
|
|
@@ -44,9 +45,7 @@ function PreviewOptions(_ref) {
|
|
|
44
45
|
variant: 'tertiary',
|
|
45
46
|
className: 'block-editor-post-preview__button-toggle',
|
|
46
47
|
disabled: !isEnabled,
|
|
47
|
-
|
|
48
|
-
/* translators: button label text should, if possible, be under 16 characters. */
|
|
49
|
-
children: (0, _i18n.__)('View')
|
|
48
|
+
children: viewLabel
|
|
50
49
|
};
|
|
51
50
|
const menuProps = {
|
|
52
51
|
'aria-label': (0, _i18n.__)('View options')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/preview-options/index.js"],"names":["PreviewOptions","children","className","isEnabled","deviceType","setDeviceType","isMobile","popoverProps","position","toggleProps","variant","disabled","menuProps","check"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;AAMe,SAASA,cAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/preview-options/index.js"],"names":["PreviewOptions","children","viewLabel","className","isEnabled","deviceType","setDeviceType","isMobile","popoverProps","position","toggleProps","variant","disabled","menuProps","check"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;AAMe,SAASA,cAAT,OAOX;AAAA,MAPoC;AACvCC,IAAAA,QADuC;AAEvCC,IAAAA,SAFuC;AAGvCC,IAAAA,SAHuC;AAIvCC,IAAAA,SAAS,GAAG,IAJ2B;AAKvCC,IAAAA,UALuC;AAMvCC,IAAAA;AANuC,GAOpC;AACH,QAAMC,QAAQ,GAAG,+BAAkB,OAAlB,EAA2B,GAA3B,CAAjB;AACA,MAAKA,QAAL,EAAgB,OAAO,IAAP;AAEhB,QAAMC,YAAY,GAAG;AACpBL,IAAAA,SAAS,EAAE,yBACVA,SADU,EAEV,6CAFU,CADS;AAKpBM,IAAAA,QAAQ,EAAE;AALU,GAArB;AAOA,QAAMC,WAAW,GAAG;AACnBC,IAAAA,OAAO,EAAE,UADU;AAEnBR,IAAAA,SAAS,EAAE,0CAFQ;AAGnBS,IAAAA,QAAQ,EAAE,CAAER,SAHO;AAInBH,IAAAA,QAAQ,EAAEC;AAJS,GAApB;AAMA,QAAMW,SAAS,GAAG;AACjB,kBAAc,cAAI,cAAJ;AADG,GAAlB;AAGA,SACC,4BAAC,wBAAD;AACC,IAAA,SAAS,EAAC,qCADX;AAEC,IAAA,YAAY,EAAGL,YAFhB;AAGC,IAAA,WAAW,EAAGE,WAHf;AAIC,IAAA,SAAS,EAAGG,SAJb;AAKC,IAAA,IAAI,EAAG;AALR,KAOG,MACD,qDACC,4BAAC,qBAAD,QACC,4BAAC,oBAAD;AACC,IAAA,SAAS,EAAC,0CADX;AAEC,IAAA,OAAO,EAAG,MAAMP,aAAa,CAAE,SAAF,CAF9B;AAGC,IAAA,IAAI,EAAGD,UAAU,KAAK,SAAf,IAA4BS;AAHpC,KAKG,cAAI,SAAJ,CALH,CADD,EAQC,4BAAC,oBAAD;AACC,IAAA,SAAS,EAAC,0CADX;AAEC,IAAA,OAAO,EAAG,MAAMR,aAAa,CAAE,QAAF,CAF9B;AAGC,IAAA,IAAI,EAAGD,UAAU,KAAK,QAAf,IAA2BS;AAHnC,KAKG,cAAI,QAAJ,CALH,CARD,EAeC,4BAAC,oBAAD;AACC,IAAA,SAAS,EAAC,0CADX;AAEC,IAAA,OAAO,EAAG,MAAMR,aAAa,CAAE,QAAF,CAF9B;AAGC,IAAA,IAAI,EAAGD,UAAU,KAAK,QAAf,IAA2BS;AAHnC,KAKG,cAAI,QAAJ,CALH,CAfD,CADD,EAwBGb,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"]}
|
|
@@ -213,6 +213,11 @@ function RichTextWrapper(_ref, forwardedRef) {
|
|
|
213
213
|
selectionEnd,
|
|
214
214
|
isSelected
|
|
215
215
|
} = (0, _data.useSelect)(selector);
|
|
216
|
+
const {
|
|
217
|
+
getSelectionStart,
|
|
218
|
+
getSelectionEnd,
|
|
219
|
+
getBlockRootClientId
|
|
220
|
+
} = (0, _data.useSelect)(_store.store);
|
|
216
221
|
const {
|
|
217
222
|
selectionChange
|
|
218
223
|
} = (0, _data.useDispatch)(_store.store);
|
|
@@ -243,6 +248,14 @@ function RichTextWrapper(_ref, forwardedRef) {
|
|
|
243
248
|
const unset = start === undefined && end === undefined;
|
|
244
249
|
|
|
245
250
|
if (typeof start === 'number' || unset) {
|
|
251
|
+
// If we are only setting the start (or the end below), which
|
|
252
|
+
// means a partial selection, and we're not updating a selection
|
|
253
|
+
// with the same client ID, abort. This means the selected block
|
|
254
|
+
// is a parent block.
|
|
255
|
+
if (end === undefined && getBlockRootClientId(clientId) !== getBlockRootClientId(getSelectionEnd().clientId)) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
246
259
|
selection.start = {
|
|
247
260
|
clientId,
|
|
248
261
|
attributeKey: identifier,
|
|
@@ -251,6 +264,10 @@ function RichTextWrapper(_ref, forwardedRef) {
|
|
|
251
264
|
}
|
|
252
265
|
|
|
253
266
|
if (typeof end === 'number' || unset) {
|
|
267
|
+
if (start === undefined && getBlockRootClientId(clientId) !== getBlockRootClientId(getSelectionStart().clientId)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
254
271
|
selection.end = {
|
|
255
272
|
clientId,
|
|
256
273
|
attributeKey: identifier,
|