@wordpress/block-editor 10.4.0 → 10.5.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 +7 -0
- package/README.md +0 -1
- package/build/components/block-lock/menu-item.js +1 -1
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +16 -9
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-styles/utils.js +3 -3
- package/build/components/block-styles/utils.js.map +1 -1
- package/build/components/block-switcher/index.js +19 -4
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +27 -4
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors/with-colors.js +4 -3
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +24 -40
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/font-sizes/with-font-sizes.js +7 -5
- package/build/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build/components/index.js +9 -0
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +5 -3
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.js +4 -1
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/link-control/index.js +18 -34
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -1
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/link-control/use-internal-input-value.js +26 -0
- package/build/components/link-control/use-internal-input-value.js.map +1 -0
- package/build/components/list-view/block.js +5 -3
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +9 -3
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +100 -0
- package/build/components/off-canvas-editor/block-contents.js.map +1 -0
- package/build/components/off-canvas-editor/block-select-button.js +119 -0
- package/build/components/off-canvas-editor/block-select-button.js.map +1 -0
- package/build/components/off-canvas-editor/block.js +292 -0
- package/build/components/off-canvas-editor/block.js.map +1 -0
- package/build/components/off-canvas-editor/branch.js +181 -0
- package/build/components/off-canvas-editor/branch.js.map +1 -0
- package/build/components/off-canvas-editor/context.js +19 -0
- package/build/components/off-canvas-editor/context.js.map +1 -0
- package/build/components/off-canvas-editor/drop-indicator.js +118 -0
- package/build/components/off-canvas-editor/drop-indicator.js.map +1 -0
- package/build/components/off-canvas-editor/expander.js +41 -0
- package/build/components/off-canvas-editor/expander.js.map +1 -0
- package/build/components/off-canvas-editor/index.js +204 -0
- package/build/components/off-canvas-editor/index.js.map +1 -0
- package/build/components/off-canvas-editor/leaf.js +60 -0
- package/build/components/off-canvas-editor/leaf.js.map +1 -0
- package/build/components/off-canvas-editor/use-block-selection.js +139 -0
- package/build/components/off-canvas-editor/use-block-selection.js.map +1 -0
- package/build/components/off-canvas-editor/use-list-view-client-ids.js +33 -0
- package/build/components/off-canvas-editor/use-list-view-client-ids.js.map +1 -0
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js +235 -0
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -0
- package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js +60 -0
- package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +1 -0
- package/build/components/off-canvas-editor/utils.js +60 -0
- package/build/components/off-canvas-editor/utils.js.map +1 -0
- package/build/components/url-popover/index.js +31 -2
- package/build/components/url-popover/index.js.map +1 -1
- package/build/components/use-setting/index.js +1 -1
- package/build/components/use-setting/index.js.map +1 -1
- package/build/hooks/color-panel.js +17 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color.js +1 -1
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/content-lock-ui.js +13 -6
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/dimensions.js +44 -13
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/layout.js +2 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/margin.js +4 -2
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/min-height.js +145 -0
- package/build/hooks/min-height.js.map +1 -0
- package/build/hooks/padding.js +4 -2
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/style.js +3 -2
- package/build/hooks/style.js.map +1 -1
- package/build/layouts/flex.js +22 -21
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +26 -0
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +46 -14
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +16 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +2 -2
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +17 -10
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-styles/utils.js +3 -3
- package/build-module/components/block-styles/utils.js.map +1 -1
- package/build-module/components/block-switcher/index.js +19 -4
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +27 -5
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors/with-colors.js +5 -4
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +24 -40
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/font-sizes/with-font-sizes.js +8 -6
- package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +5 -3
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.js +3 -1
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/link-control/index.js +17 -34
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -1
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/link-control/use-internal-input-value.js +18 -0
- package/build-module/components/link-control/use-internal-input-value.js.map +1 -0
- package/build-module/components/list-view/block.js +5 -3
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +9 -3
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +85 -0
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -0
- package/build-module/components/off-canvas-editor/block-select-button.js +101 -0
- package/build-module/components/off-canvas-editor/block-select-button.js.map +1 -0
- package/build-module/components/off-canvas-editor/block.js +268 -0
- package/build-module/components/off-canvas-editor/block.js.map +1 -0
- package/build-module/components/off-canvas-editor/branch.js +165 -0
- package/build-module/components/off-canvas-editor/branch.js.map +1 -0
- package/build-module/components/off-canvas-editor/context.js +7 -0
- package/build-module/components/off-canvas-editor/context.js.map +1 -0
- package/build-module/components/off-canvas-editor/drop-indicator.js +111 -0
- package/build-module/components/off-canvas-editor/drop-indicator.js.map +1 -0
- package/build-module/components/off-canvas-editor/expander.js +32 -0
- package/build-module/components/off-canvas-editor/expander.js.map +1 -0
- package/build-module/components/off-canvas-editor/index.js +181 -0
- package/build-module/components/off-canvas-editor/index.js.map +1 -0
- package/build-module/components/off-canvas-editor/leaf.js +45 -0
- package/build-module/components/off-canvas-editor/leaf.js.map +1 -0
- package/build-module/components/off-canvas-editor/use-block-selection.js +124 -0
- package/build-module/components/off-canvas-editor/use-block-selection.js.map +1 -0
- package/build-module/components/off-canvas-editor/use-list-view-client-ids.js +24 -0
- package/build-module/components/off-canvas-editor/use-list-view-client-ids.js.map +1 -0
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js +220 -0
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -0
- package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js +50 -0
- package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +1 -0
- package/build-module/components/off-canvas-editor/utils.js +44 -0
- package/build-module/components/off-canvas-editor/utils.js.map +1 -0
- package/build-module/components/url-popover/index.js +30 -3
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +1 -1
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/hooks/color-panel.js +17 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color.js +1 -1
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +15 -8
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/dimensions.js +39 -12
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/layout.js +2 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/margin.js +4 -2
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/min-height.js +122 -0
- package/build-module/hooks/min-height.js.map +1 -0
- package/build-module/hooks/padding.js +4 -2
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/style.js +4 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/layouts/flex.js +23 -22
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +22 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +44 -14
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +13 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +39 -26
- package/build-style/style.css +39 -26
- package/package.json +28 -28
- package/src/components/alignment-control/README.md +1 -1
- package/src/components/block-alignment-control/test/index.native.js +4 -4
- package/src/components/block-draggable/test/helpers.native.js +3 -3
- package/src/components/block-draggable/test/index.native.js +27 -27
- package/src/components/block-list/style.scss +10 -5
- package/src/components/block-lock/menu-item.js +5 -2
- package/src/components/block-lock/modal.js +19 -36
- package/src/components/block-lock/style.scss +8 -17
- package/src/components/block-mover/style.scss +0 -1
- package/src/components/block-popover/style.scss +1 -1
- package/src/components/block-styles/utils.js +3 -3
- package/src/components/block-switcher/index.js +19 -4
- package/src/components/block-tools/selected-block-popover.js +80 -34
- package/src/components/block-tools/style.scss +15 -0
- package/src/components/colors/with-colors.js +13 -23
- package/src/components/default-block-appender/style.scss +1 -0
- package/src/components/font-sizes/fluid-utils.js +37 -64
- package/src/components/font-sizes/test/fluid-utils.js +5 -5
- package/src/components/font-sizes/with-font-sizes.js +14 -11
- package/src/components/index.js +1 -0
- package/src/components/inner-blocks/index.js +7 -4
- package/src/components/inserter/reusable-blocks-tab.js +4 -2
- package/src/components/inserter/style.scss +8 -7
- package/src/components/inserter/test/reusable-blocks-tab.js +14 -57
- package/src/components/link-control/index.js +23 -39
- package/src/components/link-control/search-input.js +1 -1
- package/src/components/link-control/test/index.js +272 -241
- package/src/components/link-control/use-internal-input-value.js +22 -0
- package/src/components/list-view/block.js +4 -3
- package/src/components/list-view/branch.js +11 -6
- package/src/components/off-canvas-editor/README.md +5 -0
- package/src/components/off-canvas-editor/block-contents.js +89 -0
- package/src/components/off-canvas-editor/block-select-button.js +113 -0
- package/src/components/off-canvas-editor/block.js +335 -0
- package/src/components/off-canvas-editor/branch.js +210 -0
- package/src/components/off-canvas-editor/context.js +8 -0
- package/src/components/off-canvas-editor/drop-indicator.js +126 -0
- package/src/components/off-canvas-editor/expander.js +26 -0
- package/src/components/off-canvas-editor/index.js +216 -0
- package/src/components/off-canvas-editor/leaf.js +48 -0
- package/src/components/off-canvas-editor/style.scss +397 -0
- package/src/components/off-canvas-editor/test/utils.js +50 -0
- package/src/components/off-canvas-editor/use-block-selection.js +169 -0
- package/src/components/off-canvas-editor/use-list-view-client-ids.js +29 -0
- package/src/components/off-canvas-editor/use-list-view-drop-zone.js +260 -0
- package/src/components/off-canvas-editor/use-list-view-expand-selected-item.js +58 -0
- package/src/components/off-canvas-editor/utils.js +58 -0
- package/src/components/responsive-block-control/test/index.js +69 -92
- package/src/components/url-popover/README.md +12 -3
- package/src/components/url-popover/index.js +33 -3
- package/src/components/use-setting/index.js +7 -1
- package/src/hooks/color-panel.js +13 -1
- package/src/hooks/color.js +2 -0
- package/src/hooks/content-lock-ui.js +46 -34
- package/src/hooks/dimensions.js +76 -16
- package/src/hooks/layout.js +2 -3
- package/src/hooks/margin.js +4 -3
- package/src/hooks/min-height.js +121 -0
- package/src/hooks/padding.js +4 -3
- package/src/hooks/style.js +10 -2
- package/src/hooks/test/style.js +4 -0
- package/src/hooks/test/use-typography-props.js +1 -1
- package/src/layouts/flex.js +43 -38
- package/src/store/actions.js +22 -0
- package/src/store/reducer.js +50 -40
- package/src/store/selectors.js +16 -9
- package/src/store/test/actions.js +18 -0
- package/src/store/test/reducer.js +40 -0
- package/src/store/test/selectors.js +19 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { memo } from '@wordpress/element';
|
|
5
|
+
import { AsyncModeProvider, useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import ListViewBlock from './block';
|
|
11
|
+
import { useListViewContext } from './context';
|
|
12
|
+
import { isClientIdSelected } from './utils';
|
|
13
|
+
import { store as blockEditorStore } from '../../store';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Given a block, returns the total number of blocks in that subtree. This is used to help determine
|
|
17
|
+
* the list position of a block.
|
|
18
|
+
*
|
|
19
|
+
* When a block is collapsed, we do not count their children as part of that total. In the current drag
|
|
20
|
+
* implementation dragged blocks and their children are not counted.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} block block tree
|
|
23
|
+
* @param {Object} expandedState state that notes which branches are collapsed
|
|
24
|
+
* @param {Array} draggedClientIds a list of dragged client ids
|
|
25
|
+
* @param {boolean} isExpandedByDefault flag to determine the default fallback expanded state.
|
|
26
|
+
* @return {number} block count
|
|
27
|
+
*/
|
|
28
|
+
function countBlocks(
|
|
29
|
+
block,
|
|
30
|
+
expandedState,
|
|
31
|
+
draggedClientIds,
|
|
32
|
+
isExpandedByDefault
|
|
33
|
+
) {
|
|
34
|
+
const isDragged = draggedClientIds?.includes( block.clientId );
|
|
35
|
+
if ( isDragged ) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
const isExpanded = expandedState[ block.clientId ] ?? isExpandedByDefault;
|
|
39
|
+
|
|
40
|
+
if ( isExpanded ) {
|
|
41
|
+
return (
|
|
42
|
+
1 +
|
|
43
|
+
block.innerBlocks.reduce(
|
|
44
|
+
countReducer(
|
|
45
|
+
expandedState,
|
|
46
|
+
draggedClientIds,
|
|
47
|
+
isExpandedByDefault
|
|
48
|
+
),
|
|
49
|
+
0
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
const countReducer =
|
|
56
|
+
( expandedState, draggedClientIds, isExpandedByDefault ) =>
|
|
57
|
+
( count, block ) => {
|
|
58
|
+
const isDragged = draggedClientIds?.includes( block.clientId );
|
|
59
|
+
if ( isDragged ) {
|
|
60
|
+
return count;
|
|
61
|
+
}
|
|
62
|
+
const isExpanded =
|
|
63
|
+
expandedState[ block.clientId ] ?? isExpandedByDefault;
|
|
64
|
+
if ( isExpanded && block.innerBlocks.length > 0 ) {
|
|
65
|
+
return (
|
|
66
|
+
count +
|
|
67
|
+
countBlocks(
|
|
68
|
+
block,
|
|
69
|
+
expandedState,
|
|
70
|
+
draggedClientIds,
|
|
71
|
+
isExpandedByDefault
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return count + 1;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function ListViewBranch( props ) {
|
|
79
|
+
const {
|
|
80
|
+
blocks,
|
|
81
|
+
selectBlock,
|
|
82
|
+
showBlockMovers,
|
|
83
|
+
selectedClientIds,
|
|
84
|
+
level = 1,
|
|
85
|
+
path = '',
|
|
86
|
+
isBranchSelected = false,
|
|
87
|
+
listPosition = 0,
|
|
88
|
+
fixedListWindow,
|
|
89
|
+
isExpanded,
|
|
90
|
+
parentId,
|
|
91
|
+
shouldShowInnerBlocks = true,
|
|
92
|
+
selectBlockInCanvas,
|
|
93
|
+
} = props;
|
|
94
|
+
|
|
95
|
+
const isContentLocked = useSelect(
|
|
96
|
+
( select ) => {
|
|
97
|
+
return !! (
|
|
98
|
+
parentId &&
|
|
99
|
+
select( blockEditorStore ).getTemplateLock( parentId ) ===
|
|
100
|
+
'contentOnly'
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
[ parentId ]
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const { expandedState, draggedClientIds } = useListViewContext();
|
|
107
|
+
|
|
108
|
+
if ( isContentLocked ) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const filteredBlocks = blocks.filter( Boolean );
|
|
113
|
+
const blockCount = filteredBlocks.length;
|
|
114
|
+
let nextPosition = listPosition;
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<>
|
|
118
|
+
{ filteredBlocks.map( ( block, index ) => {
|
|
119
|
+
const { clientId, innerBlocks } = block;
|
|
120
|
+
|
|
121
|
+
if ( index > 0 ) {
|
|
122
|
+
nextPosition += countBlocks(
|
|
123
|
+
filteredBlocks[ index - 1 ],
|
|
124
|
+
expandedState,
|
|
125
|
+
draggedClientIds,
|
|
126
|
+
isExpanded
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const { itemInView } = fixedListWindow;
|
|
131
|
+
const blockInView = itemInView( nextPosition );
|
|
132
|
+
|
|
133
|
+
const position = index + 1;
|
|
134
|
+
const updatedPath =
|
|
135
|
+
path.length > 0
|
|
136
|
+
? `${ path }_${ position }`
|
|
137
|
+
: `${ position }`;
|
|
138
|
+
const hasNestedBlocks = !! innerBlocks?.length;
|
|
139
|
+
|
|
140
|
+
const shouldExpand =
|
|
141
|
+
hasNestedBlocks && shouldShowInnerBlocks
|
|
142
|
+
? expandedState[ clientId ] ?? isExpanded
|
|
143
|
+
: undefined;
|
|
144
|
+
|
|
145
|
+
const isDragged = !! draggedClientIds?.includes( clientId );
|
|
146
|
+
|
|
147
|
+
const showBlock = isDragged || blockInView;
|
|
148
|
+
|
|
149
|
+
// Make updates to the selected or dragged blocks synchronous,
|
|
150
|
+
// but asynchronous for any other block.
|
|
151
|
+
const isSelected = isClientIdSelected(
|
|
152
|
+
clientId,
|
|
153
|
+
selectedClientIds
|
|
154
|
+
);
|
|
155
|
+
const isSelectedBranch =
|
|
156
|
+
isBranchSelected || ( isSelected && hasNestedBlocks );
|
|
157
|
+
return (
|
|
158
|
+
<AsyncModeProvider key={ clientId } value={ ! isSelected }>
|
|
159
|
+
{ showBlock && (
|
|
160
|
+
<ListViewBlock
|
|
161
|
+
block={ block }
|
|
162
|
+
selectBlock={ selectBlock }
|
|
163
|
+
isSelected={ isSelected }
|
|
164
|
+
isBranchSelected={ isSelectedBranch }
|
|
165
|
+
isDragged={ isDragged }
|
|
166
|
+
level={ level }
|
|
167
|
+
position={ position }
|
|
168
|
+
rowCount={ blockCount }
|
|
169
|
+
siblingBlockCount={ blockCount }
|
|
170
|
+
showBlockMovers={ showBlockMovers }
|
|
171
|
+
path={ updatedPath }
|
|
172
|
+
isExpanded={ shouldExpand }
|
|
173
|
+
listPosition={ nextPosition }
|
|
174
|
+
selectedClientIds={ selectedClientIds }
|
|
175
|
+
selectBlockInCanvas={ selectBlockInCanvas }
|
|
176
|
+
/>
|
|
177
|
+
) }
|
|
178
|
+
{ ! showBlock && (
|
|
179
|
+
<tr>
|
|
180
|
+
<td className="block-editor-list-view-placeholder" />
|
|
181
|
+
</tr>
|
|
182
|
+
) }
|
|
183
|
+
{ hasNestedBlocks && shouldExpand && ! isDragged && (
|
|
184
|
+
<ListViewBranch
|
|
185
|
+
parentId={ clientId }
|
|
186
|
+
blocks={ innerBlocks }
|
|
187
|
+
selectBlock={ selectBlock }
|
|
188
|
+
showBlockMovers={ showBlockMovers }
|
|
189
|
+
level={ level + 1 }
|
|
190
|
+
path={ updatedPath }
|
|
191
|
+
listPosition={ nextPosition + 1 }
|
|
192
|
+
fixedListWindow={ fixedListWindow }
|
|
193
|
+
isBranchSelected={ isSelectedBranch }
|
|
194
|
+
selectedClientIds={ selectedClientIds }
|
|
195
|
+
isExpanded={ isExpanded }
|
|
196
|
+
selectBlockInCanvas={ selectBlockInCanvas }
|
|
197
|
+
/>
|
|
198
|
+
) }
|
|
199
|
+
</AsyncModeProvider>
|
|
200
|
+
);
|
|
201
|
+
} ) }
|
|
202
|
+
</>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
ListViewBranch.defaultProps = {
|
|
207
|
+
selectBlock: () => {},
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default memo( ListViewBranch );
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Popover } from '@wordpress/components';
|
|
5
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
6
|
+
|
|
7
|
+
export default function ListViewDropIndicator( {
|
|
8
|
+
listViewRef,
|
|
9
|
+
blockDropTarget,
|
|
10
|
+
} ) {
|
|
11
|
+
const { rootClientId, clientId, dropPosition } = blockDropTarget || {};
|
|
12
|
+
|
|
13
|
+
const [ rootBlockElement, blockElement ] = useMemo( () => {
|
|
14
|
+
if ( ! listViewRef.current ) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The rootClientId will be defined whenever dropping into inner
|
|
19
|
+
// block lists, but is undefined when dropping at the root level.
|
|
20
|
+
const _rootBlockElement = rootClientId
|
|
21
|
+
? listViewRef.current.querySelector(
|
|
22
|
+
`[data-block="${ rootClientId }"]`
|
|
23
|
+
)
|
|
24
|
+
: undefined;
|
|
25
|
+
|
|
26
|
+
// The clientId represents the sibling block, the dragged block will
|
|
27
|
+
// usually be inserted adjacent to it. It will be undefined when
|
|
28
|
+
// dropping a block into an empty block list.
|
|
29
|
+
const _blockElement = clientId
|
|
30
|
+
? listViewRef.current.querySelector(
|
|
31
|
+
`[data-block="${ clientId }"]`
|
|
32
|
+
)
|
|
33
|
+
: undefined;
|
|
34
|
+
|
|
35
|
+
return [ _rootBlockElement, _blockElement ];
|
|
36
|
+
}, [ rootClientId, clientId ] );
|
|
37
|
+
|
|
38
|
+
// The targetElement is the element that the drop indicator will appear
|
|
39
|
+
// before or after. When dropping into an empty block list, blockElement
|
|
40
|
+
// is undefined, so the indicator will appear after the rootBlockElement.
|
|
41
|
+
const targetElement = blockElement || rootBlockElement;
|
|
42
|
+
|
|
43
|
+
const getDropIndicatorIndent = useCallback( () => {
|
|
44
|
+
if ( ! rootBlockElement ) {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Calculate the indent using the block icon of the root block.
|
|
49
|
+
// Using a classname selector here might be flaky and could be
|
|
50
|
+
// improved.
|
|
51
|
+
const targetElementRect = targetElement.getBoundingClientRect();
|
|
52
|
+
const rootBlockIconElement = rootBlockElement.querySelector(
|
|
53
|
+
'.block-editor-block-icon'
|
|
54
|
+
);
|
|
55
|
+
const rootBlockIconRect = rootBlockIconElement.getBoundingClientRect();
|
|
56
|
+
return rootBlockIconRect.right - targetElementRect.left;
|
|
57
|
+
}, [ rootBlockElement, targetElement ] );
|
|
58
|
+
|
|
59
|
+
const style = useMemo( () => {
|
|
60
|
+
if ( ! targetElement ) {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const indent = getDropIndicatorIndent();
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
width: targetElement.offsetWidth - indent,
|
|
68
|
+
};
|
|
69
|
+
}, [ getDropIndicatorIndent, targetElement ] );
|
|
70
|
+
|
|
71
|
+
const popoverAnchor = useMemo( () => {
|
|
72
|
+
const isValidDropPosition =
|
|
73
|
+
dropPosition === 'top' ||
|
|
74
|
+
dropPosition === 'bottom' ||
|
|
75
|
+
dropPosition === 'inside';
|
|
76
|
+
if ( ! targetElement || ! isValidDropPosition ) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
ownerDocument: targetElement.ownerDocument,
|
|
82
|
+
getBoundingClientRect() {
|
|
83
|
+
const rect = targetElement.getBoundingClientRect();
|
|
84
|
+
const indent = getDropIndicatorIndent();
|
|
85
|
+
|
|
86
|
+
const left = rect.left + indent;
|
|
87
|
+
const right = rect.right;
|
|
88
|
+
let top = 0;
|
|
89
|
+
let bottom = 0;
|
|
90
|
+
|
|
91
|
+
if ( dropPosition === 'top' ) {
|
|
92
|
+
top = rect.top;
|
|
93
|
+
bottom = rect.top;
|
|
94
|
+
} else {
|
|
95
|
+
// `dropPosition` is either `bottom` or `inside`
|
|
96
|
+
top = rect.bottom;
|
|
97
|
+
bottom = rect.bottom;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const width = right - left;
|
|
101
|
+
const height = bottom - top;
|
|
102
|
+
|
|
103
|
+
return new window.DOMRect( left, top, width, height );
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}, [ targetElement, dropPosition, getDropIndicatorIndent ] );
|
|
107
|
+
|
|
108
|
+
if ( ! targetElement ) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Popover
|
|
114
|
+
animate={ false }
|
|
115
|
+
anchor={ popoverAnchor }
|
|
116
|
+
focusOnMount={ false }
|
|
117
|
+
className="block-editor-list-view-drop-indicator"
|
|
118
|
+
variant="unstyled"
|
|
119
|
+
>
|
|
120
|
+
<div
|
|
121
|
+
style={ style }
|
|
122
|
+
className="block-editor-list-view-drop-indicator__line"
|
|
123
|
+
/>
|
|
124
|
+
</Popover>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { chevronRightSmall, chevronLeftSmall, Icon } from '@wordpress/icons';
|
|
5
|
+
import { isRTL } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
export default function ListViewExpander( { onClick } ) {
|
|
8
|
+
return (
|
|
9
|
+
// Keyboard events are handled by TreeGrid see: components/src/tree-grid/index.js
|
|
10
|
+
//
|
|
11
|
+
// The expander component is implemented as a pseudo element in the w3 example
|
|
12
|
+
// https://www.w3.org/TR/wai-aria-practices/examples/treegrid/treegrid-1.html
|
|
13
|
+
//
|
|
14
|
+
// We've mimicked this by adding an icon with aria-hidden set to true to hide this from the accessibility tree.
|
|
15
|
+
// For the current tree grid implementation, please do not try to make this a button.
|
|
16
|
+
//
|
|
17
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
18
|
+
<span
|
|
19
|
+
className="block-editor-list-view__expander"
|
|
20
|
+
onClick={ ( event ) => onClick( event, { forceToggle: true } ) }
|
|
21
|
+
aria-hidden="true"
|
|
22
|
+
>
|
|
23
|
+
<Icon icon={ isRTL() ? chevronLeftSmall : chevronRightSmall } />
|
|
24
|
+
</span>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
useMergeRefs,
|
|
6
|
+
__experimentalUseFixedWindowList as useFixedWindowList,
|
|
7
|
+
} from '@wordpress/compose';
|
|
8
|
+
import { __experimentalTreeGrid as TreeGrid } from '@wordpress/components';
|
|
9
|
+
import { AsyncModeProvider, useSelect } from '@wordpress/data';
|
|
10
|
+
import {
|
|
11
|
+
useCallback,
|
|
12
|
+
useEffect,
|
|
13
|
+
useMemo,
|
|
14
|
+
useRef,
|
|
15
|
+
useReducer,
|
|
16
|
+
forwardRef,
|
|
17
|
+
} from '@wordpress/element';
|
|
18
|
+
import { __ } from '@wordpress/i18n';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
import ListViewBranch from './branch';
|
|
24
|
+
import { ListViewContext } from './context';
|
|
25
|
+
import ListViewDropIndicator from './drop-indicator';
|
|
26
|
+
import useBlockSelection from './use-block-selection';
|
|
27
|
+
import useListViewClientIds from './use-list-view-client-ids';
|
|
28
|
+
import useListViewDropZone from './use-list-view-drop-zone';
|
|
29
|
+
import useListViewExpandSelectedItem from './use-list-view-expand-selected-item';
|
|
30
|
+
import { store as blockEditorStore } from '../../store';
|
|
31
|
+
|
|
32
|
+
const expanded = ( state, action ) => {
|
|
33
|
+
if ( Array.isArray( action.clientIds ) ) {
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
...action.clientIds.reduce(
|
|
37
|
+
( newState, id ) => ( {
|
|
38
|
+
...newState,
|
|
39
|
+
[ id ]: action.type === 'expand',
|
|
40
|
+
} ),
|
|
41
|
+
{}
|
|
42
|
+
),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return state;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const BLOCK_LIST_ITEM_HEIGHT = 36;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Show a hierarchical list of blocks.
|
|
52
|
+
*
|
|
53
|
+
* @param {Object} props Components props.
|
|
54
|
+
* @param {string} props.id An HTML element id for the root element of ListView.
|
|
55
|
+
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
|
|
56
|
+
* @param {boolean} props.showBlockMovers Flag to enable block movers
|
|
57
|
+
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
|
|
58
|
+
* @param {boolean} props.selectBlockInCanvas Flag to determine whether the list view should be a block selection mechanism,.
|
|
59
|
+
* @param {Object} ref Forwarded ref
|
|
60
|
+
*/
|
|
61
|
+
function __ExperimentalOffCanvasEditor(
|
|
62
|
+
{
|
|
63
|
+
id,
|
|
64
|
+
blocks,
|
|
65
|
+
showBlockMovers = false,
|
|
66
|
+
isExpanded = false,
|
|
67
|
+
selectBlockInCanvas = true,
|
|
68
|
+
},
|
|
69
|
+
ref
|
|
70
|
+
) {
|
|
71
|
+
const { clientIdsTree, draggedClientIds, selectedClientIds } =
|
|
72
|
+
useListViewClientIds( blocks );
|
|
73
|
+
|
|
74
|
+
const { visibleBlockCount, shouldShowInnerBlocks } = useSelect(
|
|
75
|
+
( select ) => {
|
|
76
|
+
const {
|
|
77
|
+
getGlobalBlockCount,
|
|
78
|
+
getClientIdsOfDescendants,
|
|
79
|
+
__unstableGetEditorMode,
|
|
80
|
+
} = select( blockEditorStore );
|
|
81
|
+
const draggedBlockCount =
|
|
82
|
+
draggedClientIds?.length > 0
|
|
83
|
+
? getClientIdsOfDescendants( draggedClientIds ).length + 1
|
|
84
|
+
: 0;
|
|
85
|
+
return {
|
|
86
|
+
visibleBlockCount: getGlobalBlockCount() - draggedBlockCount,
|
|
87
|
+
shouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
[ draggedClientIds ]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const { updateBlockSelection } = useBlockSelection();
|
|
94
|
+
|
|
95
|
+
const [ expandedState, setExpandedState ] = useReducer( expanded, {} );
|
|
96
|
+
|
|
97
|
+
const { ref: dropZoneRef, target: blockDropTarget } = useListViewDropZone();
|
|
98
|
+
const elementRef = useRef();
|
|
99
|
+
const treeGridRef = useMergeRefs( [ elementRef, dropZoneRef, ref ] );
|
|
100
|
+
|
|
101
|
+
const isMounted = useRef( false );
|
|
102
|
+
const { setSelectedTreeId } = useListViewExpandSelectedItem( {
|
|
103
|
+
firstSelectedBlockClientId: selectedClientIds[ 0 ],
|
|
104
|
+
setExpandedState,
|
|
105
|
+
} );
|
|
106
|
+
const selectEditorBlock = useCallback(
|
|
107
|
+
( event, clientId ) => {
|
|
108
|
+
updateBlockSelection( event, clientId );
|
|
109
|
+
setSelectedTreeId( clientId );
|
|
110
|
+
},
|
|
111
|
+
[ setSelectedTreeId, updateBlockSelection ]
|
|
112
|
+
);
|
|
113
|
+
useEffect( () => {
|
|
114
|
+
isMounted.current = true;
|
|
115
|
+
}, [] );
|
|
116
|
+
|
|
117
|
+
// List View renders a fixed number of items and relies on each having a fixed item height of 36px.
|
|
118
|
+
// If this value changes, we should also change the itemHeight value set in useFixedWindowList.
|
|
119
|
+
// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.
|
|
120
|
+
const [ fixedListWindow ] = useFixedWindowList(
|
|
121
|
+
elementRef,
|
|
122
|
+
BLOCK_LIST_ITEM_HEIGHT,
|
|
123
|
+
visibleBlockCount,
|
|
124
|
+
{
|
|
125
|
+
useWindowing: true,
|
|
126
|
+
windowOverscan: 40,
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const expand = useCallback(
|
|
131
|
+
( clientId ) => {
|
|
132
|
+
if ( ! clientId ) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
setExpandedState( { type: 'expand', clientIds: [ clientId ] } );
|
|
136
|
+
},
|
|
137
|
+
[ setExpandedState ]
|
|
138
|
+
);
|
|
139
|
+
const collapse = useCallback(
|
|
140
|
+
( clientId ) => {
|
|
141
|
+
if ( ! clientId ) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
setExpandedState( { type: 'collapse', clientIds: [ clientId ] } );
|
|
145
|
+
},
|
|
146
|
+
[ setExpandedState ]
|
|
147
|
+
);
|
|
148
|
+
const expandRow = useCallback(
|
|
149
|
+
( row ) => {
|
|
150
|
+
expand( row?.dataset?.block );
|
|
151
|
+
},
|
|
152
|
+
[ expand ]
|
|
153
|
+
);
|
|
154
|
+
const collapseRow = useCallback(
|
|
155
|
+
( row ) => {
|
|
156
|
+
collapse( row?.dataset?.block );
|
|
157
|
+
},
|
|
158
|
+
[ collapse ]
|
|
159
|
+
);
|
|
160
|
+
const focusRow = useCallback(
|
|
161
|
+
( event, startRow, endRow ) => {
|
|
162
|
+
if ( event.shiftKey ) {
|
|
163
|
+
updateBlockSelection(
|
|
164
|
+
event,
|
|
165
|
+
startRow?.dataset?.block,
|
|
166
|
+
endRow?.dataset?.block
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
[ updateBlockSelection ]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const contextValue = useMemo(
|
|
174
|
+
() => ( {
|
|
175
|
+
isTreeGridMounted: isMounted.current,
|
|
176
|
+
draggedClientIds,
|
|
177
|
+
expandedState,
|
|
178
|
+
expand,
|
|
179
|
+
collapse,
|
|
180
|
+
} ),
|
|
181
|
+
[ isMounted.current, draggedClientIds, expandedState, expand, collapse ]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<AsyncModeProvider value={ true }>
|
|
186
|
+
<ListViewDropIndicator
|
|
187
|
+
listViewRef={ elementRef }
|
|
188
|
+
blockDropTarget={ blockDropTarget }
|
|
189
|
+
/>
|
|
190
|
+
<TreeGrid
|
|
191
|
+
id={ id }
|
|
192
|
+
className="block-editor-list-view-tree"
|
|
193
|
+
aria-label={ __( 'Block navigation structure' ) }
|
|
194
|
+
ref={ treeGridRef }
|
|
195
|
+
onCollapseRow={ collapseRow }
|
|
196
|
+
onExpandRow={ expandRow }
|
|
197
|
+
onFocusRow={ focusRow }
|
|
198
|
+
applicationAriaLabel={ __( 'Block navigation structure' ) }
|
|
199
|
+
>
|
|
200
|
+
<ListViewContext.Provider value={ contextValue }>
|
|
201
|
+
<ListViewBranch
|
|
202
|
+
blocks={ clientIdsTree }
|
|
203
|
+
selectBlock={ selectEditorBlock }
|
|
204
|
+
showBlockMovers={ showBlockMovers }
|
|
205
|
+
fixedListWindow={ fixedListWindow }
|
|
206
|
+
selectedClientIds={ selectedClientIds }
|
|
207
|
+
isExpanded={ isExpanded }
|
|
208
|
+
shouldShowInnerBlocks={ shouldShowInnerBlocks }
|
|
209
|
+
selectBlockInCanvas={ selectBlockInCanvas }
|
|
210
|
+
/>
|
|
211
|
+
</ListViewContext.Provider>
|
|
212
|
+
</TreeGrid>
|
|
213
|
+
</AsyncModeProvider>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
export default forwardRef( __ExperimentalOffCanvasEditor );
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { animated } from '@react-spring/web';
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { __experimentalTreeGridRow as TreeGridRow } from '@wordpress/components';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import useMovingAnimation from '../use-moving-animation';
|
|
16
|
+
|
|
17
|
+
const AnimatedTreeGridRow = animated( TreeGridRow );
|
|
18
|
+
|
|
19
|
+
export default function ListViewLeaf( {
|
|
20
|
+
isSelected,
|
|
21
|
+
position,
|
|
22
|
+
level,
|
|
23
|
+
rowCount,
|
|
24
|
+
children,
|
|
25
|
+
className,
|
|
26
|
+
path,
|
|
27
|
+
...props
|
|
28
|
+
} ) {
|
|
29
|
+
const ref = useMovingAnimation( {
|
|
30
|
+
isSelected,
|
|
31
|
+
adjustScrolling: false,
|
|
32
|
+
enableAnimation: true,
|
|
33
|
+
triggerAnimationOnChange: path,
|
|
34
|
+
} );
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<AnimatedTreeGridRow
|
|
38
|
+
ref={ ref }
|
|
39
|
+
className={ classnames( 'block-editor-list-view-leaf', className ) }
|
|
40
|
+
level={ level }
|
|
41
|
+
positionInSet={ position }
|
|
42
|
+
setSize={ rowCount }
|
|
43
|
+
{ ...props }
|
|
44
|
+
>
|
|
45
|
+
{ children }
|
|
46
|
+
</AnimatedTreeGridRow>
|
|
47
|
+
);
|
|
48
|
+
}
|