@wordpress/block-editor 10.0.2 → 10.1.1-next.4d3b314fd5.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 +2 -0
- package/build/components/block-draggable/index.js +1 -1
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-list/index.js +19 -5
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +7 -1
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +14 -5
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-popover/inbetween.js +24 -9
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +29 -3
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +23 -11
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-styles/index.js +1 -3
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-tools/index.js +18 -13
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +5 -3
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +6 -3
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/block-variation-picker/index.native.js +2 -1
- package/build/components/block-variation-picker/index.native.js.map +1 -1
- package/build/components/button-block-appender/index.native.js +1 -0
- package/build/components/button-block-appender/index.native.js.map +1 -1
- package/build/components/index.js +9 -0
- package/build/components/index.js.map +1 -1
- package/build/components/list-view/index.js +2 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +8 -1
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +12 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/url-input/index.js +1 -3
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +1 -1
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +19 -1
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +62 -20
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-setting/index.js +16 -12
- package/build/components/use-setting/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +21 -8
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/hooks/index.js +13 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +76 -23
- package/build/hooks/layout.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/store/reducer.js +33 -19
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +5 -5
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-draggable/index.js +1 -1
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-list/index.js +22 -8
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +8 -2
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +15 -6
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +24 -9
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +29 -4
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +22 -10
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-styles/index.js +1 -2
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-tools/index.js +18 -12
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +5 -3
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +6 -3
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/block-variation-picker/index.native.js +2 -1
- package/build-module/components/block-variation-picker/index.native.js.map +1 -1
- package/build-module/components/button-block-appender/index.native.js +1 -0
- package/build-module/components/button-block-appender/index.native.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/list-view/index.js +2 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +6 -1
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +12 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/url-input/index.js +1 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +19 -1
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +62 -21
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +16 -12
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +22 -9
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +73 -23
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/reducer.js +29 -18
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +5 -5
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +24 -6
- package/build-style/style.css +24 -6
- package/package.json +29 -29
- package/src/components/block-controls/test/index.js +84 -8
- package/src/components/block-draggable/index.js +1 -1
- package/src/components/block-draggable/test/index.native.js +0 -9
- package/src/components/block-list/index.js +42 -6
- package/src/components/block-list/use-block-props/index.js +6 -1
- package/src/components/block-list/use-in-between-inserter.js +14 -8
- package/src/components/block-mover/style.scss +2 -7
- package/src/components/block-popover/inbetween.js +34 -10
- package/src/components/block-popover/index.js +47 -3
- package/src/components/block-preview/auto.js +77 -65
- package/src/components/block-preview/style.scss +13 -0
- package/src/components/block-styles/index.js +1 -2
- package/src/components/block-tools/index.js +16 -10
- package/src/components/block-tools/insertion-point.js +3 -3
- package/src/components/block-tools/use-block-toolbar-popover-props.js +6 -0
- package/src/components/block-variation-picker/index.native.js +1 -0
- package/src/components/button-block-appender/index.native.js +1 -0
- package/src/components/index.js +1 -0
- package/src/components/link-control/test/index.js +1 -2
- package/src/components/list-view/index.js +1 -0
- package/src/components/rich-text/format-toolbar-container.js +8 -2
- package/src/components/rich-text/index.js +14 -0
- package/src/components/url-input/index.js +6 -2
- package/src/components/url-popover/image-url-input-ui.js +1 -1
- package/src/components/use-block-drop-zone/index.js +26 -1
- package/src/components/use-on-block-drop/index.js +110 -35
- package/src/components/use-on-block-drop/test/index.js +33 -43
- package/src/components/use-setting/index.js +18 -16
- package/src/components/warning/style.scss +1 -0
- package/src/components/writing-flow/use-arrow-nav.js +23 -9
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +64 -21
- package/src/index.js +2 -0
- package/src/store/reducer.js +22 -14
- package/src/store/selectors.js +5 -4
- package/src/store/test/reducer.js +0 -17
- package/src/components/block-controls/test/__snapshots__/index.js.snap +0 -64
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-draggable/index.js"],"names":["BlockDraggable","children","clientIds","cloneClassname","onDragStart","onDragEnd","srcRootClientId","isDraggable","icon","select","canMoveBlocks","getBlockRootClientId","getBlockName","blockEditorStore","rootClientId","blockName","isDragging","startScrolling","scrollOnDragOver","stopScrolling","startDraggingBlocks","stopDraggingBlocks","current","transferData","type","srcClientIds","event","length","onDraggableStart","onDraggableEnd"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-draggable/index.js"],"names":["BlockDraggable","children","clientIds","cloneClassname","onDragStart","onDragEnd","srcRootClientId","isDraggable","icon","select","canMoveBlocks","getBlockRootClientId","getBlockName","blockEditorStore","rootClientId","blockName","isDragging","startScrolling","scrollOnDragOver","stopScrolling","startDraggingBlocks","stopDraggingBlocks","current","draggable","transferData","type","srcClientIds","event","length","onDraggableStart","onDraggableEnd"],"mappings":";;;;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AAbA;AACA;AACA;;AAMA;AACA;AACA;AAKA,MAAMA,cAAc,GAAG,QAMhB;AAAA,MANkB;AACxBC,IAAAA,QADwB;AAExBC,IAAAA,SAFwB;AAGxBC,IAAAA,cAHwB;AAIxBC,IAAAA,WAJwB;AAKxBC,IAAAA;AALwB,GAMlB;AACN,QAAM;AAAEC,IAAAA,eAAF;AAAmBC,IAAAA,WAAnB;AAAgCC,IAAAA;AAAhC,MAAyC,qBAC5CC,MAAF,IAAc;AAAA;;AACb,UAAM;AAAEC,MAAAA,aAAF;AAAiBC,MAAAA,oBAAjB;AAAuCC,MAAAA;AAAvC,QACLH,MAAM,CAAEI,YAAF,CADP;AAEA,UAAMC,YAAY,GAAGH,oBAAoB,CAAET,SAAS,CAAE,CAAF,CAAX,CAAzC;AACA,UAAMa,SAAS,GAAGH,YAAY,CAAEV,SAAS,CAAE,CAAF,CAAX,CAA9B;AAEA,WAAO;AACNI,MAAAA,eAAe,EAAEQ,YADX;AAENP,MAAAA,WAAW,EAAEG,aAAa,CAAER,SAAF,EAAaY,YAAb,CAFpB;AAGNN,MAAAA,IAAI,mBAAE,0BAAcO,SAAd,CAAF,kDAAE,cAA2BP;AAH3B,KAAP;AAKA,GAZ6C,EAa9C,CAAEN,SAAF,CAb8C,CAA/C;AAeA,QAAMc,UAAU,GAAG,qBAAQ,KAAR,CAAnB;AACA,QAAM,CAAEC,cAAF,EAAkBC,gBAAlB,EAAoCC,aAApC,IACL,qCADD;AAGA,QAAM;AAAEC,IAAAA,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B,QAAQ,CAAE;AAChBsB,MAAAA,SAAS,EAAE,IADK;AAEhBnB,MAAAA,WAAW,EAAEyB,gBAFG;AAGhBxB,MAAAA,SAAS,EAAEyB;AAHK,KAAF,CAAf;AAKA,GAnCF,CADD;AAuCA,CAvFD;;eAyFe9B,c","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockType } from '@wordpress/blocks';\nimport { Draggable } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockDraggableChip from './draggable-chip';\nimport useScrollWhenDragging from './use-scroll-when-dragging';\nimport { store as blockEditorStore } from '../../store';\n\nconst BlockDraggable = ( {\n\tchildren,\n\tclientIds,\n\tcloneClassname,\n\tonDragStart,\n\tonDragEnd,\n} ) => {\n\tconst { srcRootClientId, isDraggable, icon } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canMoveBlocks, getBlockRootClientId, getBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientIds[ 0 ] );\n\t\t\tconst blockName = getBlockName( clientIds[ 0 ] );\n\n\t\t\treturn {\n\t\t\t\tsrcRootClientId: rootClientId,\n\t\t\t\tisDraggable: canMoveBlocks( clientIds, rootClientId ),\n\t\t\t\ticon: getBlockType( blockName )?.icon,\n\t\t\t};\n\t\t},\n\t\t[ clientIds ]\n\t);\n\tconst isDragging = useRef( false );\n\tconst [ startScrolling, scrollOnDragOver, stopScrolling ] =\n\t\tuseScrollWhenDragging();\n\n\tconst { startDraggingBlocks, stopDraggingBlocks } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// Stop dragging blocks if the block draggable is unmounted.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( isDragging.current ) {\n\t\t\t\tstopDraggingBlocks();\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\tif ( ! isDraggable ) {\n\t\treturn children( { draggable: false } );\n\t}\n\n\tconst transferData = {\n\t\ttype: 'block',\n\t\tsrcClientIds: clientIds,\n\t\tsrcRootClientId,\n\t};\n\n\treturn (\n\t\t<Draggable\n\t\t\tcloneClassname={ cloneClassname }\n\t\t\t__experimentalTransferDataType=\"wp-blocks\"\n\t\t\ttransferData={ transferData }\n\t\t\tonDragStart={ ( event ) => {\n\t\t\t\tstartDraggingBlocks( clientIds );\n\t\t\t\tisDragging.current = true;\n\n\t\t\t\tstartScrolling( event );\n\n\t\t\t\tif ( onDragStart ) {\n\t\t\t\t\tonDragStart();\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonDragOver={ scrollOnDragOver }\n\t\t\tonDragEnd={ () => {\n\t\t\t\tstopDraggingBlocks();\n\t\t\t\tisDragging.current = false;\n\n\t\t\t\tstopScrolling();\n\n\t\t\t\tif ( onDragEnd ) {\n\t\t\t\t\tonDragEnd();\n\t\t\t\t}\n\t\t\t} }\n\t\t\t__experimentalDragComponent={\n\t\t\t\t<BlockDraggableChip count={ clientIds.length } icon={ icon } />\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: true,\n\t\t\t\t\tonDragStart: onDraggableStart,\n\t\t\t\t\tonDragEnd: onDraggableEnd,\n\t\t\t\t} );\n\t\t\t} }\n\t\t</Draggable>\n\t);\n};\n\nexport default BlockDraggable;\n"]}
|
|
@@ -51,6 +51,7 @@ var _context = require("../block-edit/context");
|
|
|
51
51
|
const elementContext = (0, _element.createContext)();
|
|
52
52
|
const IntersectionObserver = (0, _element.createContext)();
|
|
53
53
|
exports.IntersectionObserver = IntersectionObserver;
|
|
54
|
+
const pendingBlockVisibilityUpdatesPerRegistry = new WeakMap();
|
|
54
55
|
|
|
55
56
|
function Root(_ref) {
|
|
56
57
|
let {
|
|
@@ -78,9 +79,20 @@ function Root(_ref) {
|
|
|
78
79
|
editorMode: __unstableGetEditorMode()
|
|
79
80
|
};
|
|
80
81
|
}, []);
|
|
82
|
+
const registry = (0, _data.useRegistry)();
|
|
81
83
|
const {
|
|
82
84
|
setBlockVisibility
|
|
83
85
|
} = (0, _data.useDispatch)(_store.store);
|
|
86
|
+
const delayedBlockVisibilityUpdates = (0, _compose.useDebounce)((0, _element.useCallback)(() => {
|
|
87
|
+
const updates = {};
|
|
88
|
+
pendingBlockVisibilityUpdatesPerRegistry.get(registry).forEach(_ref2 => {
|
|
89
|
+
let [id, isIntersecting] = _ref2;
|
|
90
|
+
updates[id] = isIntersecting;
|
|
91
|
+
});
|
|
92
|
+
setBlockVisibility(updates);
|
|
93
|
+
}, [registry]), 300, {
|
|
94
|
+
trailing: true
|
|
95
|
+
});
|
|
84
96
|
const intersectionObserver = (0, _element.useMemo)(() => {
|
|
85
97
|
const {
|
|
86
98
|
IntersectionObserver: Observer
|
|
@@ -91,14 +103,16 @@ function Root(_ref) {
|
|
|
91
103
|
}
|
|
92
104
|
|
|
93
105
|
return new Observer(entries => {
|
|
94
|
-
|
|
106
|
+
if (!pendingBlockVisibilityUpdatesPerRegistry.get(registry)) {
|
|
107
|
+
pendingBlockVisibilityUpdatesPerRegistry.set(registry, []);
|
|
108
|
+
}
|
|
95
109
|
|
|
96
110
|
for (const entry of entries) {
|
|
97
111
|
const clientId = entry.target.getAttribute('data-block');
|
|
98
|
-
|
|
112
|
+
pendingBlockVisibilityUpdatesPerRegistry.get(registry).push([clientId, entry.isIntersecting]);
|
|
99
113
|
}
|
|
100
114
|
|
|
101
|
-
|
|
115
|
+
delayedBlockVisibilityUpdates();
|
|
102
116
|
});
|
|
103
117
|
}, []);
|
|
104
118
|
const innerBlocksProps = (0, _innerBlocks.useInnerBlocksProps)({
|
|
@@ -125,14 +139,14 @@ function BlockList(settings) {
|
|
|
125
139
|
|
|
126
140
|
BlockList.__unstableElementContext = elementContext;
|
|
127
141
|
|
|
128
|
-
function Items(
|
|
142
|
+
function Items(_ref3) {
|
|
129
143
|
let {
|
|
130
144
|
placeholder,
|
|
131
145
|
rootClientId,
|
|
132
146
|
renderAppender,
|
|
133
147
|
__experimentalAppenderTagName,
|
|
134
148
|
__experimentalLayout: layout = _layout.defaultLayout
|
|
135
|
-
} =
|
|
149
|
+
} = _ref3;
|
|
136
150
|
const {
|
|
137
151
|
order,
|
|
138
152
|
selectedBlocks,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/index.js"],"names":["elementContext","IntersectionObserver","Root","className","settings","element","setElement","isLargeViewport","isOutlineMode","isFocusMode","editorMode","select","getSettings","__unstableGetEditorMode","blockEditorStore","outlineMode","focusMode","setBlockVisibility","intersectionObserver","Observer","window","entries","updates","entry","clientId","target","getAttribute","isIntersecting","innerBlocksProps","ref","BlockList","DEFAULT_BLOCK_EDIT_CONTEXT","__unstableElementContext","Items","placeholder","rootClientId","renderAppender","__experimentalAppenderTagName","__experimentalLayout","layout","defaultLayout","order","selectedBlocks","visibleBlocks","getBlockOrder","getSelectedBlockClientIds","__unstableGetVisibleBlocks","map","has","includes","length","BlockListItems","props"],"mappings":";;;;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAeA,MAAMA,cAAc,GAAG,6BAAvB;AAEO,MAAMC,oBAAoB,GAAG,6BAA7B;;;AAEP,SAASC,IAAT,OAA4C;AAAA,MAA7B;AAAEC,IAAAA,SAAF;AAAa,OAAGC;AAAhB,GAA6B;AAC3C,QAAM,CAAEC,OAAF,EAAWC,UAAX,IAA0B,wBAAhC;AACA,QAAMC,eAAe,GAAG,+BAAkB,QAAlB,CAAxB;AACA,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,WAAjB;AAA8BC,IAAAA;AAA9B,MAA6C,qBAChDC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,Q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AAD;AACC,IAAA,YAAY,EAAGW,YADhB;AAEC,IAAA,QAAQ,EAAGX;AAFZ,IATD,CADC,CADH,EAiBGiB,KAAK,CAACS,MAAN,GAAe,CAAf,IAAoBhB,WAjBvB,EAkBC,4BAAC,0BAAD;AACC,IAAA,OAAO,EAAGG,6BADX;AAEC,IAAA,YAAY,EAAGF,YAFhB;AAGC,IAAA,cAAc,EAAGC;AAHlB,IAlBD,CADD;AA0BA;;AAEM,SAASe,cAAT,CAAyBC,KAAzB,EAAiC;AACvC;AACA;AACA,SACC,4BAAC,uBAAD;AAAmB,IAAA,KAAK,EAAG;AAA3B,KACC,4BAAC,KAAD,EAAYA,KAAZ,CADD,CADD;AAKA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { AsyncModeProvider, useSelect, useDispatch } from '@wordpress/data';\nimport { useViewportMatch, useMergeRefs } from '@wordpress/compose';\nimport { createContext, useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockListBlock from './block';\nimport BlockListAppender from '../block-list-appender';\nimport { useInBetweenInserter } from './use-in-between-inserter';\nimport { store as blockEditorStore } from '../../store';\nimport { usePreParsePatterns } from '../../utils/pre-parse-patterns';\nimport { LayoutProvider, defaultLayout } from './layout';\nimport BlockToolsBackCompat from '../block-tools/back-compat';\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useInnerBlocksProps } from '../inner-blocks';\nimport {\n\tBlockEditContextProvider,\n\tDEFAULT_BLOCK_EDIT_CONTEXT,\n} from '../block-edit/context';\n\nconst elementContext = createContext();\n\nexport const IntersectionObserver = createContext();\n\nfunction Root( { className, ...settings } ) {\n\tconst [ element, setElement ] = useState();\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst { isOutlineMode, isFocusMode, editorMode } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, __unstableGetEditorMode } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { outlineMode, focusMode } = getSettings();\n\t\t\treturn {\n\t\t\t\tisOutlineMode: outlineMode,\n\t\t\t\tisFocusMode: focusMode,\n\t\t\t\teditorMode: __unstableGetEditorMode(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { setBlockVisibility } = useDispatch( blockEditorStore );\n\tconst intersectionObserver = useMemo( () => {\n\t\tconst { IntersectionObserver: Observer } = window;\n\n\t\tif ( ! Observer ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn new Observer( ( entries ) => {\n\t\t\tconst updates = {};\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst clientId = entry.target.getAttribute( 'data-block' );\n\t\t\t\tupdates[ clientId ] = entry.isIntersecting;\n\t\t\t}\n\t\t\tsetBlockVisibility( updates );\n\t\t} );\n\t}, [] );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\tref: useMergeRefs( [\n\t\t\t\tuseBlockSelectionClearer(),\n\t\t\t\tuseInBetweenInserter(),\n\t\t\t\tsetElement,\n\t\t\t] ),\n\t\t\tclassName: classnames( 'is-root-container', className, {\n\t\t\t\t'is-outline-mode': isOutlineMode,\n\t\t\t\t'is-focus-mode': isFocusMode && isLargeViewport,\n\t\t\t\t'is-navigate-mode': editorMode === 'navigation',\n\t\t\t} ),\n\t\t},\n\t\tsettings\n\t);\n\treturn (\n\t\t<elementContext.Provider value={ element }>\n\t\t\t<IntersectionObserver.Provider value={ intersectionObserver }>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</IntersectionObserver.Provider>\n\t\t</elementContext.Provider>\n\t);\n}\n\nexport default function BlockList( settings ) {\n\tusePreParsePatterns();\n\treturn (\n\t\t<BlockToolsBackCompat>\n\t\t\t<BlockEditContextProvider value={ DEFAULT_BLOCK_EDIT_CONTEXT }>\n\t\t\t\t<Root { ...settings } />\n\t\t\t</BlockEditContextProvider>\n\t\t</BlockToolsBackCompat>\n\t);\n}\n\nBlockList.__unstableElementContext = elementContext;\n\nfunction Items( {\n\tplaceholder,\n\trootClientId,\n\trenderAppender,\n\t__experimentalAppenderTagName,\n\t__experimentalLayout: layout = defaultLayout,\n} ) {\n\tconst { order, selectedBlocks, visibleBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockOrder,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t__unstableGetVisibleBlocks,\n\t\t\t} = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\torder: getBlockOrder( rootClientId ),\n\t\t\t\tselectedBlocks: getSelectedBlockClientIds(),\n\t\t\t\tvisibleBlocks: __unstableGetVisibleBlocks(),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\n\treturn (\n\t\t<LayoutProvider value={ layout }>\n\t\t\t{ order.map( ( clientId ) => (\n\t\t\t\t<AsyncModeProvider\n\t\t\t\t\tkey={ clientId }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\t// Only provide data asynchronously if the block is\n\t\t\t\t\t\t// not visible and not selected.\n\t\t\t\t\t\t! visibleBlocks.has( clientId ) &&\n\t\t\t\t\t\t! selectedBlocks.includes( clientId )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<BlockListBlock\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t/>\n\t\t\t\t</AsyncModeProvider>\n\t\t\t) ) }\n\t\t\t{ order.length < 1 && placeholder }\n\t\t\t<BlockListAppender\n\t\t\t\ttagName={ __experimentalAppenderTagName }\n\t\t\t\trootClientId={ rootClientId }\n\t\t\t\trenderAppender={ renderAppender }\n\t\t\t/>\n\t\t</LayoutProvider>\n\t);\n}\n\nexport function BlockListItems( props ) {\n\t// This component needs to always be synchronous as it's the one changing\n\t// the async mode depending on the block selection.\n\treturn (\n\t\t<AsyncModeProvider value={ false }>\n\t\t\t<Items { ...props } />\n\t\t</AsyncModeProvider>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/index.js"],"names":["elementContext","IntersectionObserver","pendingBlockVisibilityUpdatesPerRegistry","WeakMap","Root","className","settings","element","setElement","isLargeViewport","isOutlineMode","isFocusMode","editorMode","select","getSettings","__unstableGetEditorMode","blockEditorStore","outlineMode","focusMode","registry","setBlockVisibility","delayedBlockVisibilityUpdates","updates","get","forEach","id","isIntersecting","trailing","intersectionObserver","Observer","window","entries","set","entry","clientId","target","getAttribute","push","innerBlocksProps","ref","BlockList","DEFAULT_BLOCK_EDIT_CONTEXT","__unstableElementContext","Items","placeholder","rootClientId","renderAppender","__experimentalAppenderTagName","__experimentalLayout","layout","defaultLayout","order","selectedBlocks","visibleBlocks","getBlockOrder","getSelectedBlockClientIds","__unstableGetVisibleBlocks","map","has","includes","length","BlockListItems","props"],"mappings":";;;;;;;;;;;AAmBA;;AAhBA;;AAKA;;AAMA;;AAeA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAtCA;AACA;AACA;;AAGA;AACA;AACA;;AAmBA;AACA;AACA;AAeA,MAAMA,cAAc,GAAG,6BAAvB;AAEO,MAAMC,oBAAoB,GAAG,6BAA7B;;AACP,MAAMC,wCAAwC,GAAG,IAAIC,OAAJ,EAAjD;;AAEA,SAASC,IAAT,OAA4C;AAAA,MAA7B;AAAEC,IAAAA,SAAF;AAAa,OAAGC;AAAhB,GAA6B;AAC3C,QAAM,CAAEC,OAAF,EAAWC,UAAX,IAA0B,wBAAhC;AACA,QAAMC,eAAe,GAAG,+BAAkB,QAAlB,CAAxB;AACA,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,WAAjB;AAA8BC,IAAAA;AAA9B,MAA6C,qBAChDC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,QACLF,MAAM,CAAEG,YAAF,CADP;AAEA,UAAM;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,QAA6BJ,WAAW,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AEG,YAAF,CAJV;AAKA,WAAO;AACNmC,MAAAA,KAAK,EAAEG,aAAa,CAAET,YAAF,CADd;AAENO,MAAAA,cAAc,EAAEG,yBAAyB,EAFnC;AAGNF,MAAAA,aAAa,EAAEG,0BAA0B;AAHnC,KAAP;AAKA,GAZ+C,EAahD,CAAEX,YAAF,CAbgD,CAAjD;AAgBA,SACC,4BAAC,sBAAD;AAAgB,IAAA,KAAK,EAAGI;AAAxB,KACGE,KAAK,CAACM,GAAN,CAAavB,QAAF,IACZ,4BAAC,uBAAD;AACC,IAAA,GAAG,EAAGA,QADP;AAEC,IAAA,KAAK,EACJ;AACA;AACA,KAAEmB,aAAa,CAACK,GAAd,CAAmBxB,QAAnB,CAAF,IACA,CAAEkB,cAAc,CAACO,QAAf,CAAyBzB,QAAzB;AANJ,KASC,4BAAC,cAAD;AACC,IAAA,YAAY,EAAGW,YADhB;AAEC,IAAA,QAAQ,EAAGX;AAFZ,IATD,CADC,CADH,EAiBGiB,KAAK,CAACS,MAAN,GAAe,CAAf,IAAoBhB,WAjBvB,EAkBC,4BAAC,0BAAD;AACC,IAAA,OAAO,EAAGG,6BADX;AAEC,IAAA,YAAY,EAAGF,YAFhB;AAGC,IAAA,cAAc,EAAGC;AAHlB,IAlBD,CADD;AA0BA;;AAEM,SAASe,cAAT,CAAyBC,KAAzB,EAAiC;AACvC;AACA;AACA,SACC,4BAAC,uBAAD;AAAmB,IAAA,KAAK,EAAG;AAA3B,KACC,4BAAC,KAAD,EAAYA,KAAZ,CADD,CADD;AAKA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tAsyncModeProvider,\n\tuseSelect,\n\tuseDispatch,\n\tuseRegistry,\n} from '@wordpress/data';\nimport {\n\tuseViewportMatch,\n\tuseMergeRefs,\n\tuseDebounce,\n} from '@wordpress/compose';\nimport {\n\tcreateContext,\n\tuseState,\n\tuseMemo,\n\tuseCallback,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockListBlock from './block';\nimport BlockListAppender from '../block-list-appender';\nimport { useInBetweenInserter } from './use-in-between-inserter';\nimport { store as blockEditorStore } from '../../store';\nimport { usePreParsePatterns } from '../../utils/pre-parse-patterns';\nimport { LayoutProvider, defaultLayout } from './layout';\nimport BlockToolsBackCompat from '../block-tools/back-compat';\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useInnerBlocksProps } from '../inner-blocks';\nimport {\n\tBlockEditContextProvider,\n\tDEFAULT_BLOCK_EDIT_CONTEXT,\n} from '../block-edit/context';\n\nconst elementContext = createContext();\n\nexport const IntersectionObserver = createContext();\nconst pendingBlockVisibilityUpdatesPerRegistry = new WeakMap();\n\nfunction Root( { className, ...settings } ) {\n\tconst [ element, setElement ] = useState();\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst { isOutlineMode, isFocusMode, editorMode } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, __unstableGetEditorMode } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { outlineMode, focusMode } = getSettings();\n\t\t\treturn {\n\t\t\t\tisOutlineMode: outlineMode,\n\t\t\t\tisFocusMode: focusMode,\n\t\t\t\teditorMode: __unstableGetEditorMode(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst registry = useRegistry();\n\tconst { setBlockVisibility } = useDispatch( blockEditorStore );\n\n\tconst delayedBlockVisibilityUpdates = useDebounce(\n\t\tuseCallback( () => {\n\t\t\tconst updates = {};\n\t\t\tpendingBlockVisibilityUpdatesPerRegistry\n\t\t\t\t.get( registry )\n\t\t\t\t.forEach( ( [ id, isIntersecting ] ) => {\n\t\t\t\t\tupdates[ id ] = isIntersecting;\n\t\t\t\t} );\n\t\t\tsetBlockVisibility( updates );\n\t\t}, [ registry ] ),\n\t\t300,\n\t\t{\n\t\t\ttrailing: true,\n\t\t}\n\t);\n\tconst intersectionObserver = useMemo( () => {\n\t\tconst { IntersectionObserver: Observer } = window;\n\n\t\tif ( ! Observer ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn new Observer( ( entries ) => {\n\t\t\tif ( ! pendingBlockVisibilityUpdatesPerRegistry.get( registry ) ) {\n\t\t\t\tpendingBlockVisibilityUpdatesPerRegistry.set( registry, [] );\n\t\t\t}\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst clientId = entry.target.getAttribute( 'data-block' );\n\t\t\t\tpendingBlockVisibilityUpdatesPerRegistry\n\t\t\t\t\t.get( registry )\n\t\t\t\t\t.push( [ clientId, entry.isIntersecting ] );\n\t\t\t}\n\t\t\tdelayedBlockVisibilityUpdates();\n\t\t} );\n\t}, [] );\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\tref: useMergeRefs( [\n\t\t\t\tuseBlockSelectionClearer(),\n\t\t\t\tuseInBetweenInserter(),\n\t\t\t\tsetElement,\n\t\t\t] ),\n\t\t\tclassName: classnames( 'is-root-container', className, {\n\t\t\t\t'is-outline-mode': isOutlineMode,\n\t\t\t\t'is-focus-mode': isFocusMode && isLargeViewport,\n\t\t\t\t'is-navigate-mode': editorMode === 'navigation',\n\t\t\t} ),\n\t\t},\n\t\tsettings\n\t);\n\treturn (\n\t\t<elementContext.Provider value={ element }>\n\t\t\t<IntersectionObserver.Provider value={ intersectionObserver }>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</IntersectionObserver.Provider>\n\t\t</elementContext.Provider>\n\t);\n}\n\nexport default function BlockList( settings ) {\n\tusePreParsePatterns();\n\treturn (\n\t\t<BlockToolsBackCompat>\n\t\t\t<BlockEditContextProvider value={ DEFAULT_BLOCK_EDIT_CONTEXT }>\n\t\t\t\t<Root { ...settings } />\n\t\t\t</BlockEditContextProvider>\n\t\t</BlockToolsBackCompat>\n\t);\n}\n\nBlockList.__unstableElementContext = elementContext;\n\nfunction Items( {\n\tplaceholder,\n\trootClientId,\n\trenderAppender,\n\t__experimentalAppenderTagName,\n\t__experimentalLayout: layout = defaultLayout,\n} ) {\n\tconst { order, selectedBlocks, visibleBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockOrder,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t__unstableGetVisibleBlocks,\n\t\t\t} = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\torder: getBlockOrder( rootClientId ),\n\t\t\t\tselectedBlocks: getSelectedBlockClientIds(),\n\t\t\t\tvisibleBlocks: __unstableGetVisibleBlocks(),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\n\treturn (\n\t\t<LayoutProvider value={ layout }>\n\t\t\t{ order.map( ( clientId ) => (\n\t\t\t\t<AsyncModeProvider\n\t\t\t\t\tkey={ clientId }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\t// Only provide data asynchronously if the block is\n\t\t\t\t\t\t// not visible and not selected.\n\t\t\t\t\t\t! visibleBlocks.has( clientId ) &&\n\t\t\t\t\t\t! selectedBlocks.includes( clientId )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<BlockListBlock\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t/>\n\t\t\t\t</AsyncModeProvider>\n\t\t\t) ) }\n\t\t\t{ order.length < 1 && placeholder }\n\t\t\t<BlockListAppender\n\t\t\t\ttagName={ __experimentalAppenderTagName }\n\t\t\t\trootClientId={ rootClientId }\n\t\t\t\trenderAppender={ renderAppender }\n\t\t\t/>\n\t\t</LayoutProvider>\n\t);\n}\n\nexport function BlockListItems( props ) {\n\t// This component needs to always be synchronous as it's the one changing\n\t// the async mode depending on the block selection.\n\treturn (\n\t\t<AsyncModeProvider value={ false }>\n\t\t\t<Items { ...props } />\n\t\t</AsyncModeProvider>\n\t);\n}\n"]}
|
|
@@ -109,6 +109,7 @@ function useBlockProps() {
|
|
|
109
109
|
enableAnimation
|
|
110
110
|
} = (0, _data.useSelect)(select => {
|
|
111
111
|
const {
|
|
112
|
+
getBlockAttributes,
|
|
112
113
|
getBlockIndex,
|
|
113
114
|
getBlockMode,
|
|
114
115
|
getBlockName,
|
|
@@ -119,16 +120,21 @@ function useBlockProps() {
|
|
|
119
120
|
isAncestorMultiSelected,
|
|
120
121
|
isFirstMultiSelectedBlock
|
|
121
122
|
} = select(_store.store);
|
|
123
|
+
const {
|
|
124
|
+
getActiveBlockVariation
|
|
125
|
+
} = select(_blocks.store);
|
|
122
126
|
const isSelected = isBlockSelected(clientId);
|
|
123
127
|
const isPartOfMultiSelection = isBlockMultiSelected(clientId) || isAncestorMultiSelected(clientId);
|
|
124
128
|
const blockName = getBlockName(clientId);
|
|
125
129
|
const blockType = (0, _blocks.getBlockType)(blockName);
|
|
130
|
+
const attributes = getBlockAttributes(clientId);
|
|
131
|
+
const match = getActiveBlockVariation(blockName, attributes);
|
|
126
132
|
return {
|
|
127
133
|
index: getBlockIndex(clientId),
|
|
128
134
|
mode: getBlockMode(clientId),
|
|
129
135
|
name: blockName,
|
|
130
136
|
blockApiVersion: (blockType === null || blockType === void 0 ? void 0 : blockType.apiVersion) || 1,
|
|
131
|
-
blockTitle: blockType === null || blockType === void 0 ? void 0 : blockType.title,
|
|
137
|
+
blockTitle: (match === null || match === void 0 ? void 0 : match.title) || (blockType === null || blockType === void 0 ? void 0 : blockType.title),
|
|
132
138
|
isPartOfSelection: isSelected || isPartOfMultiSelection,
|
|
133
139
|
adjustScrolling: isSelected || isFirstMultiSelectedBlock(clientId),
|
|
134
140
|
enableAnimation: !isTyping() && getGlobalBlockCount() <= BLOCK_ANIMATION_THRESHOLD
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/index.js"],"names":["BLOCK_ANIMATION_THRESHOLD","useBlockProps","props","__unstableIsHtml","clientId","className","wrapperProps","isAligned","BlockListBlockContext","index","mode","name","blockApiVersion","blockTitle","isPartOfSelection","adjustScrolling","enableAnimation","select","getBlockIndex","getBlockMode","getBlockName","isTyping","getGlobalBlockCount","isBlockSelected","isBlockMultiSelected","isAncestorMultiSelected","isFirstMultiSelectedBlock","blockEditorStore","isSelected","isPartOfMultiSelection","blockName","blockType","apiVersion","title","hasOverlay","blockLabel","htmlSuffix","mergedRefs","ref","triggerAnimationOnChange","isDisabled","blockEditContext","tabIndex","id","role","style","save","getBlockProps"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AApCA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;;AAkBA;AACA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAG,GAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,aAAT,GAAgE;AAAA,MAAxCC,KAAwC,uEAAhC,EAAgC;AAAA,MAA5B;AAAEC,IAAAA;AAAF,GAA4B,uEAAL,EAAK;AACtE,QAAM;AACLC,IAAAA,QADK;AAELC,IAAAA,SAFK;AAGLC,IAAAA,YAAY,GAAG,EAHV;AAILC,IAAAA;AAJK,MAKF,yBAAYC,4BAAZ,CALJ;AAMA,QAAM;AACLC,IAAAA,KADK;AAELC,IAAAA,IAFK;AAGLC,IAAAA,IAHK;AAILC,IAAAA,eAJK;AAKLC,IAAAA,UALK;AAMLC,IAAAA,iBANK;AAOLC,IAAAA,eAPK;AAQLC,IAAAA;AARK,MASF,qBACDC,MAAF,IAAc;AACb,UAAM;AACLC,MAAAA,aADK;AAELC,MAAAA,YAFK;AAGLC,MAAAA,YAHK;AAILC,MAAAA,QAJK;AAKLC,MAAAA,mBALK;AAMLC,MAAAA,eANK;AAOLC,MAAAA,oBAPK;AAQLC,MAAAA,uBARK;AASLC,MAAAA;AATK,QAUFT,MAAM,CAAEU,YAAF,CA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AACA;AACA;;;AACA5C,aAAa,CAAC6C,IAAd,GAAqBC,+BAArB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__unstableGetBlockProps as getBlockProps,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport { useMergeRefs, useDisabled } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport useMovingAnimation from '../../use-moving-animation';\nimport { BlockListBlockContext } from '../block';\nimport { useFocusFirstElement } from './use-focus-first-element';\nimport { useIsHovered } from './use-is-hovered';\nimport { useBlockEditContext } from '../../block-edit/context';\nimport { useBlockClassNames } from './use-block-class-names';\nimport { useBlockDefaultClassName } from './use-block-default-class-name';\nimport { useBlockCustomClassName } from './use-block-custom-class-name';\nimport { useBlockMovingModeClassNames } from './use-block-moving-mode-class-names';\nimport { useFocusHandler } from './use-focus-handler';\nimport { useEventHandlers } from './use-selected-block-event-handlers';\nimport { useNavModeExit } from './use-nav-mode-exit';\nimport { useBlockRefProvider } from './use-block-refs';\nimport { useIntersectionObserver } from './use-intersection-observer';\nimport { store as blockEditorStore } from '../../../store';\nimport useBlockOverlayActive from '../../block-content-overlay';\n\n/**\n * If the block count exceeds the threshold, we disable the reordering animation\n * to avoid laginess.\n */\nconst BLOCK_ANIMATION_THRESHOLD = 200;\n\n/**\n * This hook is used to lightly mark an element as a block element. The element\n * should be the outermost element of a block. Call this hook and pass the\n * returned props to the element to mark as a block. If you define a ref for the\n * element, it is important to pass the ref to this hook, which the hook in turn\n * will pass to the component through the props it returns. Optionally, you can\n * also pass any other props through this hook, and they will be merged and\n * returned.\n *\n * @param {Object} props Optional. Props to pass to the element. Must contain\n * the ref if one is defined.\n * @param {Object} options Options for internal use only.\n * @param {boolean} options.__unstableIsHtml\n *\n * @return {Object} Props to pass to the element to mark as a block.\n */\nexport function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {\n\tconst {\n\t\tclientId,\n\t\tclassName,\n\t\twrapperProps = {},\n\t\tisAligned,\n\t} = useContext( BlockListBlockContext );\n\tconst {\n\t\tindex,\n\t\tmode,\n\t\tname,\n\t\tblockApiVersion,\n\t\tblockTitle,\n\t\tisPartOfSelection,\n\t\tadjustScrolling,\n\t\tenableAnimation,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockIndex,\n\t\t\t\tgetBlockMode,\n\t\t\t\tgetBlockName,\n\t\t\t\tisTyping,\n\t\t\t\tgetGlobalBlockCount,\n\t\t\t\tisBlockSelected,\n\t\t\t\tisBlockMultiSelected,\n\t\t\t\tisAncestorMultiSelected,\n\t\t\t\tisFirstMultiSelectedBlock,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst isSelected = isBlockSelected( clientId );\n\t\t\tconst isPartOfMultiSelection =\n\t\t\t\tisBlockMultiSelected( clientId ) ||\n\t\t\t\tisAncestorMultiSelected( clientId );\n\t\t\tconst blockName = getBlockName( clientId );\n\t\t\tconst blockType = getBlockType( blockName );\n\n\t\t\treturn {\n\t\t\t\tindex: getBlockIndex( clientId ),\n\t\t\t\tmode: getBlockMode( clientId ),\n\t\t\t\tname: blockName,\n\t\t\t\tblockApiVersion: blockType?.apiVersion || 1,\n\t\t\t\tblockTitle: blockType?.title,\n\t\t\t\tisPartOfSelection: isSelected || isPartOfMultiSelection,\n\t\t\t\tadjustScrolling:\n\t\t\t\t\tisSelected || isFirstMultiSelectedBlock( clientId ),\n\t\t\t\tenableAnimation:\n\t\t\t\t\t! isTyping() &&\n\t\t\t\t\tgetGlobalBlockCount() <= BLOCK_ANIMATION_THRESHOLD,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hasOverlay = useBlockOverlayActive( clientId );\n\n\t// translators: %s: Type of block (i.e. Text, Image etc)\n\tconst blockLabel = sprintf( __( 'Block: %s' ), blockTitle );\n\tconst htmlSuffix = mode === 'html' && ! __unstableIsHtml ? '-visual' : '';\n\tconst mergedRefs = useMergeRefs( [\n\t\tprops.ref,\n\t\tuseFocusFirstElement( clientId ),\n\t\tuseBlockRefProvider( clientId ),\n\t\tuseFocusHandler( clientId ),\n\t\tuseEventHandlers( clientId ),\n\t\tuseNavModeExit( clientId ),\n\t\tuseIsHovered(),\n\t\tuseIntersectionObserver(),\n\t\tuseMovingAnimation( {\n\t\t\tisSelected: isPartOfSelection,\n\t\t\tadjustScrolling,\n\t\t\tenableAnimation,\n\t\t\ttriggerAnimationOnChange: index,\n\t\t} ),\n\t\tuseDisabled( { isDisabled: ! hasOverlay } ),\n\t] );\n\n\tconst blockEditContext = useBlockEditContext();\n\t// Ensures it warns only inside the `edit` implementation for the block.\n\tif ( blockApiVersion < 2 && clientId === blockEditContext.clientId ) {\n\t\twarning(\n\t\t\t`Block type \"${ name }\" must support API version 2 or higher to work correctly with \"useBlockProps\" method.`\n\t\t);\n\t}\n\n\treturn {\n\t\ttabIndex: 0,\n\t\t...wrapperProps,\n\t\t...props,\n\t\tref: mergedRefs,\n\t\tid: `block-${ clientId }${ htmlSuffix }`,\n\t\trole: 'document',\n\t\t'aria-label': blockLabel,\n\t\t'data-block': clientId,\n\t\t'data-type': name,\n\t\t'data-title': blockTitle,\n\t\tclassName: classnames(\n\t\t\t// The wp-block className is important for editor styles.\n\t\t\tclassnames( 'block-editor-block-list__block', {\n\t\t\t\t'wp-block': ! isAligned,\n\t\t\t\t'has-block-overlay': hasOverlay,\n\t\t\t} ),\n\t\t\tclassName,\n\t\t\tprops.className,\n\t\t\twrapperProps.className,\n\t\t\tuseBlockClassNames( clientId ),\n\t\t\tuseBlockDefaultClassName( clientId ),\n\t\t\tuseBlockCustomClassName( clientId ),\n\t\t\tuseBlockMovingModeClassNames( clientId )\n\t\t),\n\t\tstyle: { ...wrapperProps.style, ...props.style },\n\t};\n}\n\n/**\n * Call within a save function to get the props for the block wrapper.\n *\n * @param {Object} props Optional. Props to pass to the element.\n */\nuseBlockProps.save = getBlockProps;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/index.js"],"names":["BLOCK_ANIMATION_THRESHOLD","useBlockProps","props","__unstableIsHtml","clientId","className","wrapperProps","isAligned","BlockListBlockContext","index","mode","name","blockApiVersion","blockTitle","isPartOfSelection","adjustScrolling","enableAnimation","select","getBlockAttributes","getBlockIndex","getBlockMode","getBlockName","isTyping","getGlobalBlockCount","isBlockSelected","isBlockMultiSelected","isAncestorMultiSelected","isFirstMultiSelectedBlock","blockEditorStore","getActiveBlockVariation","blocksStore","isSelected","isPartOfMultiSelection","blockName","blockType","attributes","match","apiVersion","title","hasOverlay","blockLabel","htmlSuffix","mergedRefs","ref","triggerAnimationOnChange","isDisabled","blockEditContext","tabIndex","id","role","style","save","getBlockProps"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AArCA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;AAkBA;AACA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAG,GAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,aAAT,GAAgE;AAAA,MAAxCC,KAAwC,uEAAhC,EAAgC;AAAA,MAA5B;AAAEC,IAAAA;AAAF,GAA4B,uEAAL,EAAK;AACtE,QAAM;AACLC,IAAAA,QADK;AAELC,IAAAA,SAFK;AAGLC,IAAAA,YAAY,GAAG,EAHV;AAILC,IAAAA;AAJK,MAKF,yBAAYC,4BAAZ,CALJ;AAMA,QAAM;AACLC,IAAAA,KADK;AAELC,IAAAA,IAFK;AAGLC,IAAAA,IAHK;AAILC,IAAAA,eAJK;AAKL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UAJC;AAKNM,IAAAA,EAAE,EAAG,SAAS5C,QAAU,GAAGqC,UAAY,EALjC;AAMNQ,IAAAA,IAAI,EAAE,UANA;AAON,kBAAcT,UAPR;AAQN,kBAAcpC,QARR;AASN,iBAAaO,IATP;AAUN,kBAAcE,UAVR;AAWNR,IAAAA,SAAS,EAAE,0BACV;AACA,6BAAY,gCAAZ,EAA8C;AAC7C,kBAAY,CAAEE,SAD+B;AAE7C,2BAAqBgC;AAFwB,KAA9C,CAFU,EAMVlC,SANU,EAOVH,KAAK,CAACG,SAPI,EAQVC,YAAY,CAACD,SARH,EASV,4CAAoBD,QAApB,CATU,EAUV,wDAA0BA,QAA1B,CAVU,EAWV,sDAAyBA,QAAzB,CAXU,EAYV,gEAA8BA,QAA9B,CAZU,CAXL;AAyBN8C,IAAAA,KAAK,EAAE,EAAE,GAAG5C,YAAY,CAAC4C,KAAlB;AAAyB,SAAGhD,KAAK,CAACgD;AAAlC;AAzBD,GAAP;AA2BA;AAED;AACA;AACA;AACA;AACA;;;AACAjD,aAAa,CAACkD,IAAd,GAAqBC,+BAArB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__unstableGetBlockProps as getBlockProps,\n\tgetBlockType,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { useMergeRefs, useDisabled } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport useMovingAnimation from '../../use-moving-animation';\nimport { BlockListBlockContext } from '../block';\nimport { useFocusFirstElement } from './use-focus-first-element';\nimport { useIsHovered } from './use-is-hovered';\nimport { useBlockEditContext } from '../../block-edit/context';\nimport { useBlockClassNames } from './use-block-class-names';\nimport { useBlockDefaultClassName } from './use-block-default-class-name';\nimport { useBlockCustomClassName } from './use-block-custom-class-name';\nimport { useBlockMovingModeClassNames } from './use-block-moving-mode-class-names';\nimport { useFocusHandler } from './use-focus-handler';\nimport { useEventHandlers } from './use-selected-block-event-handlers';\nimport { useNavModeExit } from './use-nav-mode-exit';\nimport { useBlockRefProvider } from './use-block-refs';\nimport { useIntersectionObserver } from './use-intersection-observer';\nimport { store as blockEditorStore } from '../../../store';\nimport useBlockOverlayActive from '../../block-content-overlay';\n\n/**\n * If the block count exceeds the threshold, we disable the reordering animation\n * to avoid laginess.\n */\nconst BLOCK_ANIMATION_THRESHOLD = 200;\n\n/**\n * This hook is used to lightly mark an element as a block element. The element\n * should be the outermost element of a block. Call this hook and pass the\n * returned props to the element to mark as a block. If you define a ref for the\n * element, it is important to pass the ref to this hook, which the hook in turn\n * will pass to the component through the props it returns. Optionally, you can\n * also pass any other props through this hook, and they will be merged and\n * returned.\n *\n * @param {Object} props Optional. Props to pass to the element. Must contain\n * the ref if one is defined.\n * @param {Object} options Options for internal use only.\n * @param {boolean} options.__unstableIsHtml\n *\n * @return {Object} Props to pass to the element to mark as a block.\n */\nexport function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {\n\tconst {\n\t\tclientId,\n\t\tclassName,\n\t\twrapperProps = {},\n\t\tisAligned,\n\t} = useContext( BlockListBlockContext );\n\tconst {\n\t\tindex,\n\t\tmode,\n\t\tname,\n\t\tblockApiVersion,\n\t\tblockTitle,\n\t\tisPartOfSelection,\n\t\tadjustScrolling,\n\t\tenableAnimation,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tgetBlockMode,\n\t\t\t\tgetBlockName,\n\t\t\t\tisTyping,\n\t\t\t\tgetGlobalBlockCount,\n\t\t\t\tisBlockSelected,\n\t\t\t\tisBlockMultiSelected,\n\t\t\t\tisAncestorMultiSelected,\n\t\t\t\tisFirstMultiSelectedBlock,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst { getActiveBlockVariation } = select( blocksStore );\n\t\t\tconst isSelected = isBlockSelected( clientId );\n\t\t\tconst isPartOfMultiSelection =\n\t\t\t\tisBlockMultiSelected( clientId ) ||\n\t\t\t\tisAncestorMultiSelected( clientId );\n\t\t\tconst blockName = getBlockName( clientId );\n\t\t\tconst blockType = getBlockType( blockName );\n\t\t\tconst attributes = getBlockAttributes( clientId );\n\t\t\tconst match = getActiveBlockVariation( blockName, attributes );\n\n\t\t\treturn {\n\t\t\t\tindex: getBlockIndex( clientId ),\n\t\t\t\tmode: getBlockMode( clientId ),\n\t\t\t\tname: blockName,\n\t\t\t\tblockApiVersion: blockType?.apiVersion || 1,\n\t\t\t\tblockTitle: match?.title || blockType?.title,\n\t\t\t\tisPartOfSelection: isSelected || isPartOfMultiSelection,\n\t\t\t\tadjustScrolling:\n\t\t\t\t\tisSelected || isFirstMultiSelectedBlock( clientId ),\n\t\t\t\tenableAnimation:\n\t\t\t\t\t! isTyping() &&\n\t\t\t\t\tgetGlobalBlockCount() <= BLOCK_ANIMATION_THRESHOLD,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hasOverlay = useBlockOverlayActive( clientId );\n\n\t// translators: %s: Type of block (i.e. Text, Image etc)\n\tconst blockLabel = sprintf( __( 'Block: %s' ), blockTitle );\n\tconst htmlSuffix = mode === 'html' && ! __unstableIsHtml ? '-visual' : '';\n\tconst mergedRefs = useMergeRefs( [\n\t\tprops.ref,\n\t\tuseFocusFirstElement( clientId ),\n\t\tuseBlockRefProvider( clientId ),\n\t\tuseFocusHandler( clientId ),\n\t\tuseEventHandlers( clientId ),\n\t\tuseNavModeExit( clientId ),\n\t\tuseIsHovered(),\n\t\tuseIntersectionObserver(),\n\t\tuseMovingAnimation( {\n\t\t\tisSelected: isPartOfSelection,\n\t\t\tadjustScrolling,\n\t\t\tenableAnimation,\n\t\t\ttriggerAnimationOnChange: index,\n\t\t} ),\n\t\tuseDisabled( { isDisabled: ! hasOverlay } ),\n\t] );\n\n\tconst blockEditContext = useBlockEditContext();\n\t// Ensures it warns only inside the `edit` implementation for the block.\n\tif ( blockApiVersion < 2 && clientId === blockEditContext.clientId ) {\n\t\twarning(\n\t\t\t`Block type \"${ name }\" must support API version 2 or higher to work correctly with \"useBlockProps\" method.`\n\t\t);\n\t}\n\n\treturn {\n\t\ttabIndex: 0,\n\t\t...wrapperProps,\n\t\t...props,\n\t\tref: mergedRefs,\n\t\tid: `block-${ clientId }${ htmlSuffix }`,\n\t\trole: 'document',\n\t\t'aria-label': blockLabel,\n\t\t'data-block': clientId,\n\t\t'data-type': name,\n\t\t'data-title': blockTitle,\n\t\tclassName: classnames(\n\t\t\t// The wp-block className is important for editor styles.\n\t\t\tclassnames( 'block-editor-block-list__block', {\n\t\t\t\t'wp-block': ! isAligned,\n\t\t\t\t'has-block-overlay': hasOverlay,\n\t\t\t} ),\n\t\t\tclassName,\n\t\t\tprops.className,\n\t\t\twrapperProps.className,\n\t\t\tuseBlockClassNames( clientId ),\n\t\t\tuseBlockDefaultClassName( clientId ),\n\t\t\tuseBlockCustomClassName( clientId ),\n\t\t\tuseBlockMovingModeClassNames( clientId )\n\t\t),\n\t\tstyle: { ...wrapperProps.style, ...props.style },\n\t};\n}\n\n/**\n * Call within a save function to get the props for the block wrapper.\n *\n * @param {Object} props Optional. Props to pass to the element.\n */\nuseBlockProps.save = getBlockProps;\n"]}
|
|
@@ -39,6 +39,9 @@ function useInBetweenInserter() {
|
|
|
39
39
|
showInsertionPoint,
|
|
40
40
|
hideInsertionPoint
|
|
41
41
|
} = (0, _data.useDispatch)(_store.store);
|
|
42
|
+
const delayedShowInsertionPoint = (0, _compose.useDebounce)(showInsertionPoint, 500, {
|
|
43
|
+
trailing: true
|
|
44
|
+
});
|
|
42
45
|
return (0, _compose.useRefEffect)(node => {
|
|
43
46
|
if (isInBetweenInserterDisabled) {
|
|
44
47
|
return;
|
|
@@ -56,6 +59,8 @@ function useInBetweenInserter() {
|
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
if (!event.target.classList.contains('block-editor-block-list__layout')) {
|
|
62
|
+
delayedShowInsertionPoint.cancel();
|
|
63
|
+
|
|
59
64
|
if (isBlockInsertionPointVisible()) {
|
|
60
65
|
hideInsertionPoint();
|
|
61
66
|
}
|
|
@@ -76,12 +81,12 @@ function useInBetweenInserter() {
|
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
const orientation = ((_getBlockListSettings = getBlockListSettings(rootClientId)) === null || _getBlockListSettings === void 0 ? void 0 : _getBlockListSettings.orientation) || 'vertical';
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const offsetLeft = event.clientX - rect.left;
|
|
84
|
+
const offsetTop = event.clientY;
|
|
85
|
+
const offsetLeft = event.clientX;
|
|
82
86
|
const children = Array.from(event.target.children);
|
|
83
87
|
let element = children.find(blockEl => {
|
|
84
|
-
|
|
88
|
+
const blockElRect = blockEl.getBoundingClientRect();
|
|
89
|
+
return blockEl.classList.contains('wp-block') && orientation === 'vertical' && blockElRect.top > offsetTop || blockEl.classList.contains('wp-block') && orientation === 'horizontal' && blockElRect.left > offsetLeft;
|
|
85
90
|
});
|
|
86
91
|
|
|
87
92
|
if (!element) {
|
|
@@ -115,6 +120,8 @@ function useInBetweenInserter() {
|
|
|
115
120
|
const elementRect = element.getBoundingClientRect();
|
|
116
121
|
|
|
117
122
|
if (orientation === 'horizontal' && (event.clientY > elementRect.bottom || event.clientY < elementRect.top) || orientation === 'vertical' && (event.clientX > elementRect.right || event.clientX < elementRect.left)) {
|
|
123
|
+
delayedShowInsertionPoint.cancel();
|
|
124
|
+
|
|
118
125
|
if (isBlockInsertionPointVisible()) {
|
|
119
126
|
hideInsertionPoint();
|
|
120
127
|
}
|
|
@@ -126,6 +133,8 @@ function useInBetweenInserter() {
|
|
|
126
133
|
// the list (preserves the original behaviour).
|
|
127
134
|
|
|
128
135
|
if (index === 0) {
|
|
136
|
+
delayedShowInsertionPoint.cancel();
|
|
137
|
+
|
|
129
138
|
if (isBlockInsertionPointVisible()) {
|
|
130
139
|
hideInsertionPoint();
|
|
131
140
|
}
|
|
@@ -133,7 +142,7 @@ function useInBetweenInserter() {
|
|
|
133
142
|
return;
|
|
134
143
|
}
|
|
135
144
|
|
|
136
|
-
|
|
145
|
+
delayedShowInsertionPoint(rootClientId, index, {
|
|
137
146
|
__unstableWithInserter: true
|
|
138
147
|
});
|
|
139
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-in-between-inserter.js"],"names":["useInBetweenInserter","openRef","InsertionPointOpenRef","isInBetweenInserterDisabled","select","blockEditorStore","getSettings","hasReducedUI","__unstableGetEditorMode","getBlockListSettings","getBlockRootClientId","getBlockIndex","isBlockInsertionPointVisible","isMultiSelecting","getSelectedBlockClientIds","getTemplateLock","__unstableIsWithinBlockOverlay","showInsertionPoint","hideInsertionPoint","node","onMouseMove","event","current","target","classList","contains","rootClientId","blockElement","getAttribute","closest","orientation","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-in-between-inserter.js"],"names":["useInBetweenInserter","openRef","InsertionPointOpenRef","isInBetweenInserterDisabled","select","blockEditorStore","getSettings","hasReducedUI","__unstableGetEditorMode","getBlockListSettings","getBlockRootClientId","getBlockIndex","isBlockInsertionPointVisible","isMultiSelecting","getSelectedBlockClientIds","getTemplateLock","__unstableIsWithinBlockOverlay","showInsertionPoint","hideInsertionPoint","delayedShowInsertionPoint","trailing","node","onMouseMove","event","current","target","classList","contains","cancel","rootClientId","blockElement","getAttribute","closest","orientation","offsetTop","clientY","offsetLeft","clientX","children","Array","from","element","find","blockEl","blockElRect","getBoundingClientRect","top","left","id","firstElementChild","clientId","slice","length","includes","elementRect","bottom","right","index","__unstableWithInserter","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIO,SAASA,oBAAT,GAAgC;AACtC,QAAMC,OAAO,GAAG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D,EASCJ,yBATD,EAUCX,2BAVD,CApIM,CAAP;AAiJA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect, useDebounce } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { InsertionPointOpenRef } from '../block-tools/insertion-point';\n\nexport function useInBetweenInserter() {\n\tconst openRef = useContext( InsertionPointOpenRef );\n\tconst isInBetweenInserterDisabled = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().hasReducedUI ||\n\t\t\tselect( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',\n\t\t[]\n\t);\n\tconst {\n\t\tgetBlockListSettings,\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tisBlockInsertionPointVisible,\n\t\tisMultiSelecting,\n\t\tgetSelectedBlockClientIds,\n\t\tgetTemplateLock,\n\t\t__unstableIsWithinBlockOverlay,\n\t} = useSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst delayedShowInsertionPoint = useDebounce( showInsertionPoint, 500, {\n\t\ttrailing: true,\n\t} );\n\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isInBetweenInserterDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfunction onMouseMove( event ) {\n\t\t\t\tif ( openRef.current ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( isMultiSelecting() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t! event.target.classList.contains(\n\t\t\t\t\t\t'block-editor-block-list__layout'\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tdelayedShowInsertionPoint.cancel();\n\t\t\t\t\tif ( isBlockInsertionPointVisible() ) {\n\t\t\t\t\t\thideInsertionPoint();\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet rootClientId;\n\t\t\t\tif (\n\t\t\t\t\t! event.target.classList.contains( 'is-root-container' )\n\t\t\t\t) {\n\t\t\t\t\tconst blockElement = !! event.target.getAttribute(\n\t\t\t\t\t\t'data-block'\n\t\t\t\t\t)\n\t\t\t\t\t\t? event.target\n\t\t\t\t\t\t: event.target.closest( '[data-block]' );\n\t\t\t\t\trootClientId = blockElement.getAttribute( 'data-block' );\n\t\t\t\t}\n\n\t\t\t\t// Don't set the insertion point if the template is locked.\n\t\t\t\tif ( getTemplateLock( rootClientId ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst orientation =\n\t\t\t\t\tgetBlockListSettings( rootClientId )?.orientation ||\n\t\t\t\t\t'vertical';\n\t\t\t\tconst offsetTop = event.clientY;\n\t\t\t\tconst offsetLeft = event.clientX;\n\n\t\t\t\tconst children = Array.from( event.target.children );\n\t\t\t\tlet element = children.find( ( blockEl ) => {\n\t\t\t\t\tconst blockElRect = blockEl.getBoundingClientRect();\n\t\t\t\t\treturn (\n\t\t\t\t\t\t( blockEl.classList.contains( 'wp-block' ) &&\n\t\t\t\t\t\t\torientation === 'vertical' &&\n\t\t\t\t\t\t\tblockElRect.top > offsetTop ) ||\n\t\t\t\t\t\t( blockEl.classList.contains( 'wp-block' ) &&\n\t\t\t\t\t\t\torientation === 'horizontal' &&\n\t\t\t\t\t\t\tblockElRect.left > offsetLeft )\n\t\t\t\t\t);\n\t\t\t\t} );\n\n\t\t\t\tif ( ! element ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// The block may be in an alignment wrapper, so check the first direct\n\t\t\t\t// child if the element has no ID.\n\t\t\t\tif ( ! element.id ) {\n\t\t\t\t\telement = element.firstElementChild;\n\n\t\t\t\t\tif ( ! element ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Don't show the insertion point if a parent block has an \"overlay\"\n\t\t\t\t// See https://github.com/WordPress/gutenberg/pull/34012#pullrequestreview-727762337\n\t\t\t\tconst clientId = element.id.slice( 'block-'.length );\n\t\t\t\tif (\n\t\t\t\t\t! clientId ||\n\t\t\t\t\t__unstableIsWithinBlockOverlay( clientId )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Don't show the inserter when hovering above (conflicts with\n\t\t\t\t// block toolbar) or inside selected block(s).\n\t\t\t\tif ( getSelectedBlockClientIds().includes( clientId ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst elementRect = element.getBoundingClientRect();\n\n\t\t\t\tif (\n\t\t\t\t\t( orientation === 'horizontal' &&\n\t\t\t\t\t\t( event.clientY > elementRect.bottom ||\n\t\t\t\t\t\t\tevent.clientY < elementRect.top ) ) ||\n\t\t\t\t\t( orientation === 'vertical' &&\n\t\t\t\t\t\t( event.clientX > elementRect.right ||\n\t\t\t\t\t\t\tevent.clientX < elementRect.left ) )\n\t\t\t\t) {\n\t\t\t\t\tdelayedShowInsertionPoint.cancel();\n\t\t\t\t\tif ( isBlockInsertionPointVisible() ) {\n\t\t\t\t\t\thideInsertionPoint();\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst index = getBlockIndex( clientId );\n\n\t\t\t\t// Don't show the in-between inserter before the first block in\n\t\t\t\t// the list (preserves the original behaviour).\n\t\t\t\tif ( index === 0 ) {\n\t\t\t\t\tdelayedShowInsertionPoint.cancel();\n\t\t\t\t\tif ( isBlockInsertionPointVisible() ) {\n\t\t\t\t\t\thideInsertionPoint();\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdelayedShowInsertionPoint( rootClientId, index, {\n\t\t\t\t\t__unstableWithInserter: true,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousemove', onMouseMove );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousemove', onMouseMove );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\topenRef,\n\t\t\tgetBlockListSettings,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlockIndex,\n\t\t\tisBlockInsertionPointVisible,\n\t\t\tisMultiSelecting,\n\t\t\tshowInsertionPoint,\n\t\t\thideInsertionPoint,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tisInBetweenInserterDisabled,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -36,6 +36,7 @@ var _usePopoverScroll = _interopRequireDefault(require("./use-popover-scroll"));
|
|
|
36
36
|
/**
|
|
37
37
|
* Internal dependencies
|
|
38
38
|
*/
|
|
39
|
+
const MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;
|
|
39
40
|
const InsertionPointOpenRef = (0, _element.createContext)();
|
|
40
41
|
exports.InsertionPointOpenRef = InsertionPointOpenRef;
|
|
41
42
|
|
|
@@ -49,7 +50,8 @@ function BlockPopoverInbetween(_ref) {
|
|
|
49
50
|
...props
|
|
50
51
|
} = _ref;
|
|
51
52
|
// This is a temporary hack to get the inbetween inserter to recompute properly.
|
|
52
|
-
const [
|
|
53
|
+
const [popoverRecomputeCounter, forcePopoverRecompute] = (0, _element.useReducer)( // Module is there to make sure that the counter doesn't overflow.
|
|
54
|
+
s => (s + 1) % MAX_POPOVER_RECOMPUTE_COUNTER, 0);
|
|
53
55
|
const {
|
|
54
56
|
orientation,
|
|
55
57
|
rootClientId,
|
|
@@ -75,7 +77,10 @@ function BlockPopoverInbetween(_ref) {
|
|
|
75
77
|
const nextElement = (0, _useBlockRefs.__unstableUseBlockElement)(nextClientId);
|
|
76
78
|
const isVertical = orientation === 'vertical';
|
|
77
79
|
const style = (0, _element.useMemo)(() => {
|
|
78
|
-
if (
|
|
80
|
+
if ( // popoverRecomputeCounter is by definition always equal or greater than 0.
|
|
81
|
+
// This check is only there to satisfy the correctness of the
|
|
82
|
+
// exhaustive-deps rule for the `useMemo` hook.
|
|
83
|
+
popoverRecomputeCounter < 0 || !previousElement && !nextElement || !isVisible) {
|
|
79
84
|
return {};
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -99,9 +104,12 @@ function BlockPopoverInbetween(_ref) {
|
|
|
99
104
|
width,
|
|
100
105
|
height: previousRect ? previousRect.height : nextRect.height
|
|
101
106
|
};
|
|
102
|
-
}, [previousElement, nextElement, isVertical,
|
|
107
|
+
}, [previousElement, nextElement, isVertical, popoverRecomputeCounter, isVisible]);
|
|
103
108
|
const popoverAnchor = (0, _element.useMemo)(() => {
|
|
104
|
-
if (
|
|
109
|
+
if ( // popoverRecomputeCounter is by definition always equal or greater than 0.
|
|
110
|
+
// This check is only there to satisfy the correctness of the
|
|
111
|
+
// exhaustive-deps rule for the `useMemo` hook.
|
|
112
|
+
popoverRecomputeCounter < 0 || !previousElement && !nextElement || !isVisible) {
|
|
105
113
|
return undefined;
|
|
106
114
|
}
|
|
107
115
|
|
|
@@ -144,15 +152,22 @@ function BlockPopoverInbetween(_ref) {
|
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
};
|
|
147
|
-
}, [previousElement, nextElement,
|
|
155
|
+
}, [previousElement, nextElement, popoverRecomputeCounter, isVertical, isVisible]);
|
|
148
156
|
const popoverScrollRef = (0, _usePopoverScroll.default)(__unstableContentRef); // This is only needed for a smooth transition when moving blocks.
|
|
157
|
+
// When blocks are moved up/down, their position can be set by
|
|
158
|
+
// updating the `transform` property manually (i.e. without using CSS
|
|
159
|
+
// transitions or animations). The animation, which can also scroll the block
|
|
160
|
+
// editor, can sometimes cause the position of the Popover to get out of sync.
|
|
161
|
+
// A MutationObserver is therefore used to make sure that changes to the
|
|
162
|
+
// selectedElement's attribute (i.e. `transform`) can be tracked and used to
|
|
163
|
+
// trigger the Popover to rerender.
|
|
149
164
|
|
|
150
165
|
(0, _element.useLayoutEffect)(() => {
|
|
151
166
|
if (!previousElement) {
|
|
152
167
|
return;
|
|
153
168
|
}
|
|
154
169
|
|
|
155
|
-
const observer = new window.MutationObserver(
|
|
170
|
+
const observer = new window.MutationObserver(forcePopoverRecompute);
|
|
156
171
|
observer.observe(previousElement, {
|
|
157
172
|
attributes: true
|
|
158
173
|
});
|
|
@@ -165,7 +180,7 @@ function BlockPopoverInbetween(_ref) {
|
|
|
165
180
|
return;
|
|
166
181
|
}
|
|
167
182
|
|
|
168
|
-
const observer = new window.MutationObserver(
|
|
183
|
+
const observer = new window.MutationObserver(forcePopoverRecompute);
|
|
169
184
|
observer.observe(nextElement, {
|
|
170
185
|
attributes: true
|
|
171
186
|
});
|
|
@@ -178,9 +193,9 @@ function BlockPopoverInbetween(_ref) {
|
|
|
178
193
|
return;
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
previousElement.ownerDocument.defaultView.addEventListener('resize',
|
|
196
|
+
previousElement.ownerDocument.defaultView.addEventListener('resize', forcePopoverRecompute);
|
|
182
197
|
return () => {
|
|
183
|
-
previousElement.ownerDocument.defaultView.removeEventListener('resize',
|
|
198
|
+
previousElement.ownerDocument.defaultView.removeEventListener('resize', forcePopoverRecompute);
|
|
184
199
|
};
|
|
185
200
|
}, [previousElement]); // If there's either a previous or a next element, show the inbetween popover.
|
|
186
201
|
// Note that drag and drop uses the inbetween popover to show the drop indicator
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-popover/inbetween.js"],"names":["InsertionPointOpenRef","BlockPopoverInbetween","previousClientId","nextClientId","children","__unstablePopoverSlot","__unstableContentRef","props","positionRecompute","forceRecompute","s","orientation","rootClientId","isVisible","select","getBlockListSettings","getBlockRootClientId","isBlockVisible","blockEditorStore","_rootClientId","previousElement","nextElement","isVertical","style","previousRect","getBoundingClientRect","nextRect","width","height","top","bottom","left","right","popoverAnchor","undefined","ownerDocument","window","DOMRect","popoverScrollRef","observer","MutationObserver","observe","attributes","disconnect","defaultView","addEventListener","removeEventListener","className"],"mappings":";;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AAA,YAAY,EAAG,KAJhB,CAKC;AACA;AAND;AAOC,IAAA,kBAAkB,EAAG5B,qBAAqB,IAAI,IAP/C,CAQC;AACA;AATD;AAUC,IAAA,GAAG,EAAGF,YAAY,GAAG,IAAf,GAAsBS;AAV7B,KAWML,KAXN;AAYC,IAAA,SAAS,EAAG,yBACX,4BADW,EAEX,uCAFW,EAGXA,KAAK,CAACwC,SAHK,CAZb;AAiBC,IAAA,MAAM,EAAG,KAjBV;AAkBC,IAAA,IAAI,EAAG,KAlBR;AAmBC,IAAA,SAAS,EAAC;AAnBX,MAqBC;AACC,IAAA,SAAS,EAAC,iDADX;AAEC,IAAA,KAAK,EAAGxB;AAFT,KAIGnB,QAJH,CArBD,CADD;AA8BA;AACA;;eAEcH,qB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tuseMemo,\n\tcreateContext,\n\tuseReducer,\n\tuseLayoutEffect,\n} from '@wordpress/element';\nimport { Popover } from '@wordpress/components';\nimport { isRTL } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';\nimport usePopoverScroll from './use-popover-scroll';\n\nexport const InsertionPointOpenRef = createContext();\n\nfunction BlockPopoverInbetween( {\n\tpreviousClientId,\n\tnextClientId,\n\tchildren,\n\t__unstablePopoverSlot,\n\t__unstableContentRef,\n\t...props\n} ) {\n\t// This is a temporary hack to get the inbetween inserter to recompute properly.\n\tconst [ positionRecompute, forceRecompute ] = useReducer(\n\t\t( s ) => s + 1,\n\t\t0\n\t);\n\n\tconst { orientation, rootClientId, isVisible } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tisBlockVisible,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst _rootClientId = getBlockRootClientId(\n\t\t\t\tpreviousClientId ?? nextClientId\n\t\t\t);\n\t\t\treturn {\n\t\t\t\torientation:\n\t\t\t\t\tgetBlockListSettings( _rootClientId )?.orientation ||\n\t\t\t\t\t'vertical',\n\t\t\t\trootClientId: _rootClientId,\n\t\t\t\tisVisible:\n\t\t\t\t\tisBlockVisible( previousClientId ) &&\n\t\t\t\t\tisBlockVisible( nextClientId ),\n\t\t\t};\n\t\t},\n\t\t[ previousClientId, nextClientId ]\n\t);\n\tconst previousElement = useBlockElement( previousClientId );\n\tconst nextElement = useBlockElement( nextClientId );\n\tconst isVertical = orientation === 'vertical';\n\tconst style = useMemo( () => {\n\t\tif ( ( ! previousElement && ! nextElement ) || ! isVisible ) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst previousRect = previousElement\n\t\t\t? previousElement.getBoundingClientRect()\n\t\t\t: null;\n\t\tconst nextRect = nextElement\n\t\t\t? nextElement.getBoundingClientRect()\n\t\t\t: null;\n\n\t\tif ( isVertical ) {\n\t\t\treturn {\n\t\t\t\twidth: previousRect ? previousRect.width : nextRect.width,\n\t\t\t\theight:\n\t\t\t\t\tnextRect && previousRect\n\t\t\t\t\t\t? nextRect.top - previousRect.bottom\n\t\t\t\t\t\t: 0,\n\t\t\t};\n\t\t}\n\n\t\tlet width = 0;\n\t\tif ( previousRect && nextRect ) {\n\t\t\twidth = isRTL()\n\t\t\t\t? previousRect.left - nextRect.right\n\t\t\t\t: nextRect.left - previousRect.right;\n\t\t}\n\n\t\treturn {\n\t\t\twidth,\n\t\t\theight: previousRect ? previousRect.height : nextRect.height,\n\t\t};\n\t}, [\n\t\tpreviousElement,\n\t\tnextElement,\n\t\tisVertical,\n\t\tpositionRecompute,\n\t\tisVisible,\n\t] );\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif ( ( ! previousElement && ! nextElement ) || ! isVisible ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { ownerDocument } = previousElement || nextElement;\n\n\t\treturn {\n\t\t\townerDocument,\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst previousRect = previousElement\n\t\t\t\t\t? previousElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\t\t\t\tconst nextRect = nextElement\n\t\t\t\t\t? nextElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\n\t\t\t\tlet left = 0;\n\t\t\t\tlet top = 0;\n\n\t\t\t\tif ( isVertical ) {\n\t\t\t\t\t// vertical\n\t\t\t\t\ttop = previousRect ? previousRect.bottom : nextRect.top;\n\n\t\t\t\t\tif ( isRTL() ) {\n\t\t\t\t\t\t// vertical, rtl\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.right\n\t\t\t\t\t\t\t: nextRect.right;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// vertical, ltr\n\t\t\t\t\t\tleft = previousRect ? previousRect.left : nextRect.left;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttop = previousRect ? previousRect.top : nextRect.top;\n\n\t\t\t\t\tif ( isRTL() ) {\n\t\t\t\t\t\t// non vertical, rtl\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.left\n\t\t\t\t\t\t\t: nextRect.right;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// non vertical, ltr\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.right\n\t\t\t\t\t\t\t: nextRect.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn new window.DOMRect( left, top, 0, 0 );\n\t\t\t},\n\t\t};\n\t}, [\n\t\tpreviousElement,\n\t\tnextElement,\n\t\tpositionRecompute,\n\t\tisVertical,\n\t\tisVisible,\n\t] );\n\n\tconst popoverScrollRef = usePopoverScroll( __unstableContentRef );\n\n\t// This is only needed for a smooth transition when moving blocks.\n\tuseLayoutEffect( () => {\n\t\tif ( ! previousElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( forceRecompute );\n\t\tobserver.observe( previousElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ previousElement ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! nextElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( forceRecompute );\n\t\tobserver.observe( nextElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ nextElement ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! previousElement ) {\n\t\t\treturn;\n\t\t}\n\t\tpreviousElement.ownerDocument.defaultView.addEventListener(\n\t\t\t'resize',\n\t\t\tforceRecompute\n\t\t);\n\t\treturn () => {\n\t\t\tpreviousElement.ownerDocument.defaultView.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tforceRecompute\n\t\t\t);\n\t\t};\n\t}, [ previousElement ] );\n\n\t// If there's either a previous or a next element, show the inbetween popover.\n\t// Note that drag and drop uses the inbetween popover to show the drop indicator\n\t// before the first block and after the last block.\n\tif ( ( ! previousElement && ! nextElement ) || ! isVisible ) {\n\t\treturn null;\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */\n\t// While ideally it would be enough to capture the\n\t// bubbling focus event from the Inserter, due to the\n\t// characteristics of click focusing of `button`s in\n\t// Firefox and Safari, it is not reliable.\n\t//\n\t// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\treturn (\n\t\t<Popover\n\t\t\tref={ popoverScrollRef }\n\t\t\tanimate={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ false }\n\t\t\t// Render in the old slot if needed for backward compatibility,\n\t\t\t// otherwise render in place (not in the default popover slot).\n\t\t\t__unstableSlotName={ __unstablePopoverSlot || null }\n\t\t\t// Forces a remount of the popover when its position changes\n\t\t\t// This makes sure the popover doesn't animate from its previous position.\n\t\t\tkey={ nextClientId + '--' + rootClientId }\n\t\t\t{ ...props }\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-block-popover',\n\t\t\t\t'block-editor-block-popover__inbetween',\n\t\t\t\tprops.className\n\t\t\t) }\n\t\t\tresize={ false }\n\t\t\tflip={ false }\n\t\t\tplacement=\"bottom-start\"\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName=\"block-editor-block-popover__inbetween-container\"\n\t\t\t\tstyle={ style }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</Popover>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */\n}\n\nexport default BlockPopoverInbetween;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-popover/inbetween.js"],"names":["MAX_POPOVER_RECOMPUTE_COUNTER","Number","MAX_SAFE_INTEGER","InsertionPointOpenRef","BlockPopoverInbetween","previousClientId","nextClientId","children","__unstablePopoverSlot","__unstableContentRef","props","popoverRecomputeCounter","forcePopoverRecompute","s","orientation","rootClientId","isVisible","select","getBlockListSettings","getBlockRootClientId","isBlockVisible","blockEditorStore","_rootClientId","previousElement","nextElement","isVertical","style","previousRect","getBoundingClientRect","nextRect","width","height","top","bottom","left","right","popoverAnchor","undefined","ownerDocument","window","DOMRect","popoverScrollRef","observer","MutationObserver","observe","attributes","disconnect","defaultView","addEventListener","removeEventListener","className"],"mappings":";;;;;;;;;AASA;;;;AANA;;AAKA;;AAOA;;AACA;;AAKA;;AACA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;AAKA,MAAMA,6BAA6B,GAAGC,MAAM,CAACC,gBAA7C;AAEO,MAAMC,qBAAqB,GAAG,6BAA9B;;;AAEP,SAASC,qBAAT,OAOI;AAAA,MAP4B;AAC/BC,IAAAA,gBAD+B;AAE/BC,IAAAA,YAF+B;AAG/BC,IAAAA,QAH+B;AAI/BC,IAAAA,qBAJ+B;AAK/BC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Y,GAAG,IAAf,GAAsBS;AAV7B,KAWML,KAXN;AAYC,IAAA,SAAS,EAAG,yBACX,4BADW,EAEX,uCAFW,EAGXA,KAAK,CAACwC,SAHK,CAZb;AAiBC,IAAA,MAAM,EAAG,KAjBV;AAkBC,IAAA,IAAI,EAAG,KAlBR;AAmBC,IAAA,SAAS,EAAC;AAnBX,MAqBC;AACC,IAAA,SAAS,EAAC,iDADX;AAEC,IAAA,KAAK,EAAGxB;AAFT,KAIGnB,QAJH,CArBD,CADD;AA8BA;AACA;;eAEcH,qB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tuseMemo,\n\tcreateContext,\n\tuseReducer,\n\tuseLayoutEffect,\n} from '@wordpress/element';\nimport { Popover } from '@wordpress/components';\nimport { isRTL } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';\nimport usePopoverScroll from './use-popover-scroll';\n\nconst MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;\n\nexport const InsertionPointOpenRef = createContext();\n\nfunction BlockPopoverInbetween( {\n\tpreviousClientId,\n\tnextClientId,\n\tchildren,\n\t__unstablePopoverSlot,\n\t__unstableContentRef,\n\t...props\n} ) {\n\t// This is a temporary hack to get the inbetween inserter to recompute properly.\n\tconst [ popoverRecomputeCounter, forcePopoverRecompute ] = useReducer(\n\t\t// Module is there to make sure that the counter doesn't overflow.\n\t\t( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,\n\t\t0\n\t);\n\n\tconst { orientation, rootClientId, isVisible } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tisBlockVisible,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst _rootClientId = getBlockRootClientId(\n\t\t\t\tpreviousClientId ?? nextClientId\n\t\t\t);\n\t\t\treturn {\n\t\t\t\torientation:\n\t\t\t\t\tgetBlockListSettings( _rootClientId )?.orientation ||\n\t\t\t\t\t'vertical',\n\t\t\t\trootClientId: _rootClientId,\n\t\t\t\tisVisible:\n\t\t\t\t\tisBlockVisible( previousClientId ) &&\n\t\t\t\t\tisBlockVisible( nextClientId ),\n\t\t\t};\n\t\t},\n\t\t[ previousClientId, nextClientId ]\n\t);\n\tconst previousElement = useBlockElement( previousClientId );\n\tconst nextElement = useBlockElement( nextClientId );\n\tconst isVertical = orientation === 'vertical';\n\tconst style = useMemo( () => {\n\t\tif (\n\t\t\t// popoverRecomputeCounter is by definition always equal or greater than 0.\n\t\t\t// This check is only there to satisfy the correctness of the\n\t\t\t// exhaustive-deps rule for the `useMemo` hook.\n\t\t\tpopoverRecomputeCounter < 0 ||\n\t\t\t( ! previousElement && ! nextElement ) ||\n\t\t\t! isVisible\n\t\t) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst previousRect = previousElement\n\t\t\t? previousElement.getBoundingClientRect()\n\t\t\t: null;\n\t\tconst nextRect = nextElement\n\t\t\t? nextElement.getBoundingClientRect()\n\t\t\t: null;\n\n\t\tif ( isVertical ) {\n\t\t\treturn {\n\t\t\t\twidth: previousRect ? previousRect.width : nextRect.width,\n\t\t\t\theight:\n\t\t\t\t\tnextRect && previousRect\n\t\t\t\t\t\t? nextRect.top - previousRect.bottom\n\t\t\t\t\t\t: 0,\n\t\t\t};\n\t\t}\n\n\t\tlet width = 0;\n\t\tif ( previousRect && nextRect ) {\n\t\t\twidth = isRTL()\n\t\t\t\t? previousRect.left - nextRect.right\n\t\t\t\t: nextRect.left - previousRect.right;\n\t\t}\n\n\t\treturn {\n\t\t\twidth,\n\t\t\theight: previousRect ? previousRect.height : nextRect.height,\n\t\t};\n\t}, [\n\t\tpreviousElement,\n\t\tnextElement,\n\t\tisVertical,\n\t\tpopoverRecomputeCounter,\n\t\tisVisible,\n\t] );\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif (\n\t\t\t// popoverRecomputeCounter is by definition always equal or greater than 0.\n\t\t\t// This check is only there to satisfy the correctness of the\n\t\t\t// exhaustive-deps rule for the `useMemo` hook.\n\t\t\tpopoverRecomputeCounter < 0 ||\n\t\t\t( ! previousElement && ! nextElement ) ||\n\t\t\t! isVisible\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { ownerDocument } = previousElement || nextElement;\n\n\t\treturn {\n\t\t\townerDocument,\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst previousRect = previousElement\n\t\t\t\t\t? previousElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\t\t\t\tconst nextRect = nextElement\n\t\t\t\t\t? nextElement.getBoundingClientRect()\n\t\t\t\t\t: null;\n\n\t\t\t\tlet left = 0;\n\t\t\t\tlet top = 0;\n\n\t\t\t\tif ( isVertical ) {\n\t\t\t\t\t// vertical\n\t\t\t\t\ttop = previousRect ? previousRect.bottom : nextRect.top;\n\n\t\t\t\t\tif ( isRTL() ) {\n\t\t\t\t\t\t// vertical, rtl\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.right\n\t\t\t\t\t\t\t: nextRect.right;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// vertical, ltr\n\t\t\t\t\t\tleft = previousRect ? previousRect.left : nextRect.left;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttop = previousRect ? previousRect.top : nextRect.top;\n\n\t\t\t\t\tif ( isRTL() ) {\n\t\t\t\t\t\t// non vertical, rtl\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.left\n\t\t\t\t\t\t\t: nextRect.right;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// non vertical, ltr\n\t\t\t\t\t\tleft = previousRect\n\t\t\t\t\t\t\t? previousRect.right\n\t\t\t\t\t\t\t: nextRect.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn new window.DOMRect( left, top, 0, 0 );\n\t\t\t},\n\t\t};\n\t}, [\n\t\tpreviousElement,\n\t\tnextElement,\n\t\tpopoverRecomputeCounter,\n\t\tisVertical,\n\t\tisVisible,\n\t] );\n\n\tconst popoverScrollRef = usePopoverScroll( __unstableContentRef );\n\n\t// This is only needed for a smooth transition when moving blocks.\n\t// When blocks are moved up/down, their position can be set by\n\t// updating the `transform` property manually (i.e. without using CSS\n\t// transitions or animations). The animation, which can also scroll the block\n\t// editor, can sometimes cause the position of the Popover to get out of sync.\n\t// A MutationObserver is therefore used to make sure that changes to the\n\t// selectedElement's attribute (i.e. `transform`) can be tracked and used to\n\t// trigger the Popover to rerender.\n\tuseLayoutEffect( () => {\n\t\tif ( ! previousElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( forcePopoverRecompute );\n\t\tobserver.observe( previousElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ previousElement ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! nextElement ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new window.MutationObserver( forcePopoverRecompute );\n\t\tobserver.observe( nextElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ nextElement ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! previousElement ) {\n\t\t\treturn;\n\t\t}\n\t\tpreviousElement.ownerDocument.defaultView.addEventListener(\n\t\t\t'resize',\n\t\t\tforcePopoverRecompute\n\t\t);\n\t\treturn () => {\n\t\t\tpreviousElement.ownerDocument.defaultView.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tforcePopoverRecompute\n\t\t\t);\n\t\t};\n\t}, [ previousElement ] );\n\n\t// If there's either a previous or a next element, show the inbetween popover.\n\t// Note that drag and drop uses the inbetween popover to show the drop indicator\n\t// before the first block and after the last block.\n\tif ( ( ! previousElement && ! nextElement ) || ! isVisible ) {\n\t\treturn null;\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */\n\t// While ideally it would be enough to capture the\n\t// bubbling focus event from the Inserter, due to the\n\t// characteristics of click focusing of `button`s in\n\t// Firefox and Safari, it is not reliable.\n\t//\n\t// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\treturn (\n\t\t<Popover\n\t\t\tref={ popoverScrollRef }\n\t\t\tanimate={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ false }\n\t\t\t// Render in the old slot if needed for backward compatibility,\n\t\t\t// otherwise render in place (not in the default popover slot).\n\t\t\t__unstableSlotName={ __unstablePopoverSlot || null }\n\t\t\t// Forces a remount of the popover when its position changes\n\t\t\t// This makes sure the popover doesn't animate from its previous position.\n\t\t\tkey={ nextClientId + '--' + rootClientId }\n\t\t\t{ ...props }\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-block-popover',\n\t\t\t\t'block-editor-block-popover__inbetween',\n\t\t\t\tprops.className\n\t\t\t) }\n\t\t\tresize={ false }\n\t\t\tflip={ false }\n\t\t\tplacement=\"bottom-start\"\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName=\"block-editor-block-popover__inbetween-container\"\n\t\t\t\tstyle={ style }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</Popover>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */\n}\n\nexport default BlockPopoverInbetween;\n"]}
|
|
@@ -32,6 +32,8 @@ var _usePopoverScroll = _interopRequireDefault(require("./use-popover-scroll"));
|
|
|
32
32
|
/**
|
|
33
33
|
* Internal dependencies
|
|
34
34
|
*/
|
|
35
|
+
const MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;
|
|
36
|
+
|
|
35
37
|
function BlockPopover(_ref, ref) {
|
|
36
38
|
let {
|
|
37
39
|
clientId,
|
|
@@ -57,8 +59,33 @@ function BlockPopover(_ref, ref) {
|
|
|
57
59
|
height: selectedElement.offsetHeight
|
|
58
60
|
};
|
|
59
61
|
}, [selectedElement, lastSelectedElement, __unstableRefreshSize]);
|
|
62
|
+
const [popoverAnchorRecomputeCounter, forceRecomputePopoverAnchor] = (0, _element.useReducer)( // Module is there to make sure that the counter doesn't overflow.
|
|
63
|
+
s => (s + 1) % MAX_POPOVER_RECOMPUTE_COUNTER, 0); // When blocks are moved up/down, they are animated to their new position by
|
|
64
|
+
// updating the `transform` property manually (i.e. without using CSS
|
|
65
|
+
// transitions or animations). The animation, which can also scroll the block
|
|
66
|
+
// editor, can sometimes cause the position of the Popover to get out of sync.
|
|
67
|
+
// A MutationObserver is therefore used to make sure that changes to the
|
|
68
|
+
// selectedElement's attribute (i.e. `transform`) can be tracked and used to
|
|
69
|
+
// trigger the Popover to rerender.
|
|
70
|
+
|
|
71
|
+
(0, _element.useLayoutEffect)(() => {
|
|
72
|
+
if (!selectedElement) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const observer = new window.MutationObserver(forceRecomputePopoverAnchor);
|
|
77
|
+
observer.observe(selectedElement, {
|
|
78
|
+
attributes: true
|
|
79
|
+
});
|
|
80
|
+
return () => {
|
|
81
|
+
observer.disconnect();
|
|
82
|
+
};
|
|
83
|
+
}, [selectedElement]);
|
|
60
84
|
const popoverAnchor = (0, _element.useMemo)(() => {
|
|
61
|
-
if (
|
|
85
|
+
if ( // popoverAnchorRecomputeCounter is by definition always equal or greater
|
|
86
|
+
// than 0. This check is only there to satisfy the correctness of the
|
|
87
|
+
// exhaustive-deps rule for the `useMemo` hook.
|
|
88
|
+
popoverAnchorRecomputeCounter < 0 || !selectedElement || bottomClientId && !lastSelectedElement) {
|
|
62
89
|
return undefined;
|
|
63
90
|
}
|
|
64
91
|
|
|
@@ -83,7 +110,7 @@ function BlockPopover(_ref, ref) {
|
|
|
83
110
|
|
|
84
111
|
ownerDocument: selectedElement.ownerDocument
|
|
85
112
|
};
|
|
86
|
-
}, [bottomClientId, lastSelectedElement, selectedElement]);
|
|
113
|
+
}, [bottomClientId, lastSelectedElement, selectedElement, popoverAnchorRecomputeCounter]);
|
|
87
114
|
|
|
88
115
|
if (!selectedElement || bottomClientId && !lastSelectedElement) {
|
|
89
116
|
return null;
|
|
@@ -92,7 +119,6 @@ function BlockPopover(_ref, ref) {
|
|
|
92
119
|
return (0, _element.createElement)(_components.Popover, (0, _extends2.default)({
|
|
93
120
|
ref: mergedRefs,
|
|
94
121
|
animate: false,
|
|
95
|
-
position: "top right left",
|
|
96
122
|
focusOnMount: false,
|
|
97
123
|
anchor: popoverAnchor // Render in the old slot if needed for backward compatibility,
|
|
98
124
|
// otherwise render in place (not in the default popover slot).
|