@wordpress/block-editor 10.0.2 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-list/index.js +19 -5
  3. package/build/components/block-list/index.js.map +1 -1
  4. package/build/components/block-list/use-block-props/index.js +7 -1
  5. package/build/components/block-list/use-block-props/index.js.map +1 -1
  6. package/build/components/block-list/use-in-between-inserter.js +10 -1
  7. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  8. package/build/components/block-popover/inbetween.js +24 -9
  9. package/build/components/block-popover/inbetween.js.map +1 -1
  10. package/build/components/block-popover/index.js +29 -2
  11. package/build/components/block-popover/index.js.map +1 -1
  12. package/build/components/block-preview/auto.js +23 -11
  13. package/build/components/block-preview/auto.js.map +1 -1
  14. package/build/components/block-styles/index.js +1 -3
  15. package/build/components/block-styles/index.js.map +1 -1
  16. package/build/components/block-tools/index.js +18 -13
  17. package/build/components/block-tools/index.js.map +1 -1
  18. package/build/components/block-tools/insertion-point.js +5 -3
  19. package/build/components/block-tools/insertion-point.js.map +1 -1
  20. package/build/components/block-variation-picker/index.native.js +2 -1
  21. package/build/components/block-variation-picker/index.native.js.map +1 -1
  22. package/build/components/button-block-appender/index.native.js +1 -0
  23. package/build/components/button-block-appender/index.native.js.map +1 -1
  24. package/build/components/list-view/index.js +2 -1
  25. package/build/components/list-view/index.js.map +1 -1
  26. package/build/components/rich-text/format-toolbar-container.js +8 -1
  27. package/build/components/rich-text/format-toolbar-container.js.map +1 -1
  28. package/build/components/rich-text/index.js +12 -0
  29. package/build/components/rich-text/index.js.map +1 -1
  30. package/build/components/url-input/index.js +1 -3
  31. package/build/components/url-input/index.js.map +1 -1
  32. package/build/components/use-setting/index.js +16 -12
  33. package/build/components/use-setting/index.js.map +1 -1
  34. package/build/components/writing-flow/use-arrow-nav.js +7 -1
  35. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  36. package/build/store/reducer.js +33 -19
  37. package/build/store/reducer.js.map +1 -1
  38. package/build/store/selectors.js +4 -4
  39. package/build/store/selectors.js.map +1 -1
  40. package/build-module/components/block-list/index.js +22 -8
  41. package/build-module/components/block-list/index.js.map +1 -1
  42. package/build-module/components/block-list/use-block-props/index.js +8 -2
  43. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  44. package/build-module/components/block-list/use-in-between-inserter.js +11 -2
  45. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  46. package/build-module/components/block-popover/inbetween.js +24 -9
  47. package/build-module/components/block-popover/inbetween.js.map +1 -1
  48. package/build-module/components/block-popover/index.js +29 -3
  49. package/build-module/components/block-popover/index.js.map +1 -1
  50. package/build-module/components/block-preview/auto.js +22 -10
  51. package/build-module/components/block-preview/auto.js.map +1 -1
  52. package/build-module/components/block-styles/index.js +1 -2
  53. package/build-module/components/block-styles/index.js.map +1 -1
  54. package/build-module/components/block-tools/index.js +18 -12
  55. package/build-module/components/block-tools/index.js.map +1 -1
  56. package/build-module/components/block-tools/insertion-point.js +5 -3
  57. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  58. package/build-module/components/block-variation-picker/index.native.js +2 -1
  59. package/build-module/components/block-variation-picker/index.native.js.map +1 -1
  60. package/build-module/components/button-block-appender/index.native.js +1 -0
  61. package/build-module/components/button-block-appender/index.native.js.map +1 -1
  62. package/build-module/components/list-view/index.js +2 -1
  63. package/build-module/components/list-view/index.js.map +1 -1
  64. package/build-module/components/rich-text/format-toolbar-container.js +6 -1
  65. package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
  66. package/build-module/components/rich-text/index.js +12 -0
  67. package/build-module/components/rich-text/index.js.map +1 -1
  68. package/build-module/components/url-input/index.js +1 -2
  69. package/build-module/components/url-input/index.js.map +1 -1
  70. package/build-module/components/use-setting/index.js +16 -12
  71. package/build-module/components/use-setting/index.js.map +1 -1
  72. package/build-module/components/writing-flow/use-arrow-nav.js +8 -2
  73. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  74. package/build-module/store/reducer.js +29 -18
  75. package/build-module/store/reducer.js.map +1 -1
  76. package/build-module/store/selectors.js +4 -4
  77. package/build-module/store/selectors.js.map +1 -1
  78. package/build-style/style-rtl.css +3 -5
  79. package/build-style/style.css +3 -5
  80. package/package.json +28 -28
  81. package/src/components/block-controls/test/index.js +84 -8
  82. package/src/components/block-list/index.js +42 -6
  83. package/src/components/block-list/use-block-props/index.js +6 -1
  84. package/src/components/block-list/use-in-between-inserter.js +9 -3
  85. package/src/components/block-mover/style.scss +2 -7
  86. package/src/components/block-popover/inbetween.js +34 -10
  87. package/src/components/block-popover/index.js +47 -2
  88. package/src/components/block-preview/auto.js +77 -65
  89. package/src/components/block-styles/index.js +1 -2
  90. package/src/components/block-tools/index.js +16 -10
  91. package/src/components/block-tools/insertion-point.js +3 -3
  92. package/src/components/block-variation-picker/index.native.js +1 -0
  93. package/src/components/button-block-appender/index.native.js +1 -0
  94. package/src/components/link-control/test/index.js +1 -2
  95. package/src/components/list-view/index.js +1 -0
  96. package/src/components/rich-text/format-toolbar-container.js +8 -2
  97. package/src/components/rich-text/index.js +14 -0
  98. package/src/components/url-input/index.js +6 -2
  99. package/src/components/use-setting/index.js +18 -16
  100. package/src/components/warning/style.scss +1 -0
  101. package/src/components/writing-flow/use-arrow-nav.js +11 -1
  102. package/src/store/reducer.js +22 -14
  103. package/src/store/selectors.js +4 -4
  104. package/src/store/test/reducer.js +0 -17
  105. package/src/components/block-controls/test/__snapshots__/index.js.snap +0 -64
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 10.1.0 (2022-09-21)
6
+
5
7
  ## 10.0.0 (2022-09-13)
6
8
 
7
9
  ### Breaking change
@@ -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
- const updates = {};
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
- updates[clientId] = entry.isIntersecting;
112
+ pendingBlockVisibilityUpdatesPerRegistry.get(registry).push([clientId, entry.isIntersecting]);
99
113
  }
100
114
 
101
- setBlockVisibility(updates);
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(_ref2) {
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
- } = _ref2;
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,QACLF,MAAM,CAAEG,YAAF,CADP;AAEA,UAAM;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,QAA6BJ,WAAW,EAA9C;AACA,WAAO;AACNJ,MAAAA,aAAa,EAAEO,WADT;AA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AAC,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,EAA9C;AACA,WAAO;AACNJ,MAAAA,aAAa,EAAEO,WADT;AAENN,MAAAA,WAAW,EAAEO,SAFP;AAGNN,MAAAA,UAAU,EAAEG,uBAAuB;AAH7B,KAAP;AAKA,GAViD,EAWlD,EAXkD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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;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AACA,MAAK7B,eAAe,GAAG,CAAlB,IAAuBR,QAAQ,KAAKqC,gBAAgB,CAACrC,QAA1D,EAAqE;AACpE,mHACE,eAAeO,IAAM,uFADvB;AAGA;;AAED,SAAO;AACN+B,IAAAA,QAAQ,EAAE,CADJ;AAEN,OAAGpC,YAFG;AAGN,OAAGJ,KAHG;AAINoC,IAAAA,GAAG,EAAED,UAJC;AAKNM,IAAAA,EAAE,EAAG,SAASvC,QAAU,GAAGgC,UAAY,EALjC;AAMNQ,IAAAA,IAAI,EAAE,UANA;AAON,kBAAcT,UAPR;AAQN,kBAAc/B,QARR;AASN,iBAAaO,IATP;AAUN,kBAAcE,UAVR;AAWNR,IAAAA,SAAS,EAAE,0BACV;AACA,6BAAY,gCAAZ,EAA8C;AAC7C,kBAAY,CAAEE,SAD+B;AAE7C,2BAAqB2B;AAFwB,KAA9C,CAFU,EAMV7B,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;AAyBNyC,IAAAA,KAAK,EAAE,EAAE,GAAGvC,YAAY,CAACuC,KAAlB;AAAyB,SAAG3C,KAAK,CAAC2C;AAAlC;AAzBD,GAAP;AA2BA;AAED;AACA;AACA;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;AAKLC,IAAAA,UALK;AAMLC,IAAAA,iBANK;AAOLC,IAAAA,eAPK;AAQLC,IAAAA;AARK,MASF,qBACDC,MAAF,IAAc;AACb,UAAM;AACLC,MAAAA,kBADK;AAELC,MAAAA,aAFK;AAGLC,MAAAA,YAHK;AAILC,MAAAA,YAJK;AAKLC,MAAAA,QALK;AAMLC,MAAAA,mBANK;AAOLC,MAAAA,eAPK;AAQLC,MAAAA,oBARK;AASLC,MAAAA,uBATK;AAULC,MAAAA;AAVK,QAWFV,MAAM,CAAEW,YAAF,CAXV;AAYA,UAAM;AAAEC,MAAAA;AAAF,QAA8BZ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D,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
  }
@@ -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
- showInsertionPoint(rootClientId, index, {
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","rect","getBoundingClientRect","offsetTop","clientY","top","offsetLeft","clientX","left","children","Array","from","element","find","blockEl","id","firstElementChild","clientId","slice","length","includes","elementRect","bottom","right","index","__unstableWithInserter","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AAEA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;AAIO,SAASA,oBAAT,GAAgC;AACtC,QAAMC,OAAO,GAAG,yBAAYC,qCAAZ,CAAhB;AACA,QAAMC,2BAA2B,GAAG,qBACjCC,MAAF,IACCA,MAAM,CAAEC,YAAF,CAAN,CAA2BC,WAA3B,GAAyCC,YAAzC,IACAH,MAAM,CAAEC,YAAF,CAAN,CAA2BG,uBAA3B,OAAyD,UAHvB,EAInC,EAJmC,CAApC;AAMA,QAAM;AACLC,IAAAA,oBADK;AAELC,IAAAA,oBAFK;AAGLC,IAAAA,aAHK;AAILC,IAAAA,4BAJK;AAKLC,IAAAA,gBALK;AAMLC,IAAAA,yBANK;AAOLC,IAAAA,eAPK;AAQLC,IAAAA;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AF5B,CAJH,EAOE;AACD,YAAK1B,4BAA4B,EAAjC,EAAsC;AACrCM,UAAAA,kBAAkB;AAClB;;AACD;AACA;;AAED,YAAMoC,KAAK,GAAG3C,aAAa,CAAEoC,QAAF,CAA3B,CArG6B,CAuG7B;AACA;;AACA,UAAKO,KAAK,KAAK,CAAf,EAAmB;AAClB,YAAK1C,4BAA4B,EAAjC,EAAsC;AACrCM,UAAAA,kBAAkB;AAClB;;AACD;AACA;;AAEDD,MAAAA,kBAAkB,CAAES,YAAF,EAAgB4B,KAAhB,EAAuB;AACxCC,QAAAA,sBAAsB,EAAE;AADgB,OAAvB,CAAlB;AAGA;;AAEDpC,IAAAA,IAAI,CAACqC,gBAAL,CAAuB,WAAvB,EAAoCpC,WAApC;AAEA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACsC,mBAAL,CAA0B,WAA1B,EAAuCrC,WAAvC;AACA,KAFD;AAGA,GAhIK,EAiIN,CACCnB,OADD,EAECQ,oBAFD,EAGCC,oBAHD,EAICC,aAJD,EAKCC,4BALD,EAMCC,gBAND,EAOCI,kBAPD,EAQCC,kBARD,EASCJ,yBATD,EAUCX,2BAVD,CAjIM,CAAP;AA8IA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\n\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\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\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 rect = event.target.getBoundingClientRect();\n\t\t\t\tconst offsetTop = event.clientY - rect.top;\n\t\t\t\tconst offsetLeft = event.clientX - rect.left;\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\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\tblockEl.offsetTop > 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\tblockEl.offsetLeft > 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\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\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\tshowInsertionPoint( 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"]}
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","rect","getBoundingClientRect","offsetTop","clientY","top","offsetLeft","clientX","left","children","Array","from","element","find","blockEl","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,yBAAYC,qCAAZ,CAAhB;AACA,QAAMC,2BAA2B,GAAG,qBACjCC,MAAF,IACCA,MAAM,CAAEC,YAAF,CAAN,CAA2BC,WAA3B,GAAyCC,YAAzC,IACAH,MAAM,CAAEC,YAAF,CAAN,CAA2BG,uBAA3B,OAAyD,UAHvB,EAInC,EAJmC,CAApC;AAMA,QAAM;AACLC,IAAAA,oBADK;AAELC,IAAAA,oBAFK;AAGLC,IAAAA,aAHK;AAILC,IAAAA,4BAJK;AAKLC,IAAAA,gBALK;AAMLC,IAAAA,yBANK;AAOLC,IAAAA,eAPK;AAQLC,IAAAA;AARK,MASF,qBAAWX,YAAX,CATJ;AAUA,QAAM;AAAEY,IAAAA,kBAAF;AAAsBC,IAAAA;AAAtB,MACL,uBAAab,YAAb,CADD;AAGA,QAAMc,yBAAyB,GAAG,0BAAaF,kBAAb,EAAiC,GAAjC,EAAsC;AACvEG,IAAAA,QAAQ,EAAE;AAD6D,GAAtC,CAAlC;AAIA,SAAO,2BACJC,IAAF,IAAY;AACX,QAAKlB,2BAAL,EAAmC;AAClC;AACA;;AAED,aAASmB,WAAT,CAAsBC,KAAtB,EAA8B;AAAA;;AAC7B,UAAKtB,OAAO,CAACuB,OAAb,EAAuB;AACtB;AACA;;AAED,UAAKX,gBAAgB,EAArB,EAA0B;AACzB;AACA;;AAED,UACC,CAAEU,KAAK,CAACE,MAAN,CAAaC,SAAb,CAAuBC,QAAvB,CACD,iCADC,CADH,EAIE;AACDR,QAAAA,yBAAyB,CAACS,MAA1B;;AACA,YAAKhB,4BAA4B,EAAjC,EAAsC;AACrCM,UAAAA,kBAAk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CAAzB;AAGA;;AAEDrC,IAAAA,IAAI,CAACsC,gBAAL,CAAuB,WAAvB,EAAoCrC,WAApC;AAEA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACuC,mBAAL,CAA0B,WAA1B,EAAuCtC,WAAvC;AACA,KAFD;AAGA,GAnIK,EAoIN,CACCrB,OADD,EAECQ,oBAFD,EAGCC,oBAHD,EAICC,aAJD,EAKCC,4BALD,EAMCC,gBAND,EAOCI,kBAPD,EAQCC,kBARD,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 rect = event.target.getBoundingClientRect();\n\t\t\t\tconst offsetTop = event.clientY - rect.top;\n\t\t\t\tconst offsetLeft = event.clientX - rect.left;\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\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\tblockEl.offsetTop > 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\tblockEl.offsetLeft > 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 [positionRecompute, forceRecompute] = (0, _element.useReducer)(s => s + 1, 0);
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 (!previousElement && !nextElement || !isVisible) {
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, positionRecompute, isVisible]);
107
+ }, [previousElement, nextElement, isVertical, popoverRecomputeCounter, isVisible]);
103
108
  const popoverAnchor = (0, _element.useMemo)(() => {
104
- if (!previousElement && !nextElement || !isVisible) {
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, positionRecompute, isVertical, isVisible]);
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(forceRecompute);
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(forceRecompute);
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', forceRecompute);
196
+ previousElement.ownerDocument.defaultView.addEventListener('resize', forcePopoverRecompute);
182
197
  return () => {
183
- previousElement.ownerDocument.defaultView.removeEventListener('resize', forceRecompute);
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":";;;;;;;;;AASA;;;;AANA;;AAKA;;AAOA;;AACA;;AAKA;;AACA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;AAKO,MAAMA,qBAAqB,GAA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AAG,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,IAAAA,oBAL+B;AAM/B,OAAGC;AAN4B,GAO5B;AACH;AACA,QAAM,CAAEC,uBAAF,EAA2BC,qBAA3B,IAAqD,0BAC1D;AACEC,EAAAA,CAAF,IAAS,CAAEA,CAAC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AG,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 (!selectedElement || bottomClientId && !lastSelectedElement) {
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;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-popover/index.js"],"names":["BlockPopover","ref","clientId","bottomClientId","children","__unstableRefreshSize","__unstableCoverTarget","__unstablePopoverSlot","__unstableContentRef","props","selectedElement","lastSelectedElement","mergedRefs","style","position","width","offsetWidth","height","offsetHeight","popoverAnchor","undefined","getBoundingClientRect","selectedBCR","lastSelectedBCR","left","Math","min","Infinity","top","right","max","bottom","window","DOMRect","ownerDocument","className"],"mappings":";;;;;;;;;AAUA;;;;AAPA;;AAKA;;AACA;;AAMA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAIA,SAASA,YAAT,OAWCC,GAXD,EAYE;AAAA,MAXD;AACCC,IAAAA,QADD;AAECC,IAAAA,cAFD;AAGCC,IAAAA,QAHD;AAICC,IAAAA,qBAJD;AAKCC,IAAAA,qBAAqB,GAAG,KALzB;AAMCC,IAAAA,qBAND;AAOCC,IAAAA,oBAPD;AAQC,OAAGC;AARJ,GAWC;AACD,QAAMC,eAAe,GAAG,6CAAiBR,QAAjB,CAAxB;AACA,QAAMS,mBAAmB,GAAG,6CAAiBR,cAAjB,aAAiBA,cAAjB,cAAiBA,cAAjB,GAAmCD,QAAnC,CAA5B;AACA,QAAMU,UAAU,GAAG,2BAAc,CAChCX,GADgC,EAEhC,+BAAkBO,oBAAlB,CAFgC,CAAd,CAAnB;AAIA,QAAMK,KAAK,GAAG,sBAAS,MAAM;AAC5B,QAAK,CAAEH,eAAF,IAAqBC,mBAAmB,KAAKD,eAAlD,EAAoE;AACnE,aAAO,EAAP;AACA;;AAED,WAAO;AACNI,MAAAA,QAAQ,EAAE,UADJ;AAENC,MAAAA,KAAK,EAAEL,eAAe,CAACM,WAFjB;AAGNC,MAAAA,MAAM,EAAEP,eAAe,CAACQ;AAHlB,KAAP;AAKA,GAVa,EAUX,CAAER,eAAF,EAAmBC,mBAAnB,EAAwCN,qBAAxC,CAVW,CAAd;AAYA,QAAMc,aAAa,GAAG,sBAAS,MAAM;AACpC,QACC,CAAET,eAAF,IACEP,cAAc,IAAI,CAAEQ,mBAFvB,EAGE;AACD,aAAOS,SAAP;AACA;;AAED,WAAO;AACNC,MAAAA,qBAAqB,GAAG;AAAA;;AACvB,cAAMC,WAAW,GAAGZ,eAAe,CAACW,qBAAhB,EAApB;AACA,cA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hB;AAKC,IAAA,MAAM,EAAGO,aALV,CAMC;AACA;AAPD;AAQC,IAAA,kBAAkB,EAAGZ,qBAAqB,IAAI,IAR/C;AASC,IAAA,MAAM,EAAG,KATV;AAUC,IAAA,IAAI,EAAG,KAVR;AAWC,IAAA,KAAK;AAXN,KAYME,KAZN;AAaC,IAAA,SAAS,EAAG,yBACX,4BADW,EAEXA,KAAK,CAAC0B,SAFK;AAbb,MAkBG7B,qBAAqB,IAAI;AAAK,IAAA,KAAK,EAAGO;AAAb,KAAuBT,QAAvB,CAlB5B,EAmBG,CAAEE,qBAAF,IAA2BF,QAnB9B,CADD;AAuBA;;eAEc,yBAAYJ,YAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { Popover } from '@wordpress/components';\nimport { forwardRef, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';\nimport usePopoverScroll from './use-popover-scroll';\n\nfunction BlockPopover(\n\t{\n\t\tclientId,\n\t\tbottomClientId,\n\t\tchildren,\n\t\t__unstableRefreshSize,\n\t\t__unstableCoverTarget = false,\n\t\t__unstablePopoverSlot,\n\t\t__unstableContentRef,\n\t\t...props\n\t},\n\tref\n) {\n\tconst selectedElement = useBlockElement( clientId );\n\tconst lastSelectedElement = useBlockElement( bottomClientId ?? clientId );\n\tconst mergedRefs = useMergeRefs( [\n\t\tref,\n\t\tusePopoverScroll( __unstableContentRef ),\n\t] );\n\tconst style = useMemo( () => {\n\t\tif ( ! selectedElement || lastSelectedElement !== selectedElement ) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn {\n\t\t\tposition: 'absolute',\n\t\t\twidth: selectedElement.offsetWidth,\n\t\t\theight: selectedElement.offsetHeight,\n\t\t};\n\t}, [ selectedElement, lastSelectedElement, __unstableRefreshSize ] );\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif (\n\t\t\t! selectedElement ||\n\t\t\t( bottomClientId && ! lastSelectedElement )\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst selectedBCR = selectedElement.getBoundingClientRect();\n\t\t\t\tconst lastSelectedBCR =\n\t\t\t\t\tlastSelectedElement?.getBoundingClientRect();\n\n\t\t\t\t// Get the biggest rectangle that encompasses completely the currently\n\t\t\t\t// selected element and the last selected element:\n\t\t\t\t// - for top/left coordinates, use the smaller numbers\n\t\t\t\t// - for the bottom/right coordinates, use the largest numbers\n\t\t\t\tconst left = Math.min(\n\t\t\t\t\tselectedBCR.left,\n\t\t\t\t\tlastSelectedBCR?.left ?? Infinity\n\t\t\t\t);\n\t\t\t\tconst top = Math.min(\n\t\t\t\t\tselectedBCR.top,\n\t\t\t\t\tlastSelectedBCR?.top ?? Infinity\n\t\t\t\t);\n\t\t\t\tconst right = Math.max(\n\t\t\t\t\tselectedBCR.right,\n\t\t\t\t\tlastSelectedBCR.right ?? -Infinity\n\t\t\t\t);\n\t\t\t\tconst bottom = Math.max(\n\t\t\t\t\tselectedBCR.bottom,\n\t\t\t\t\tlastSelectedBCR.bottom ?? -Infinity\n\t\t\t\t);\n\t\t\t\tconst width = right - left;\n\t\t\t\tconst height = bottom - top;\n\n\t\t\t\treturn new window.DOMRect( left, top, width, height );\n\t\t\t},\n\t\t\townerDocument: selectedElement.ownerDocument,\n\t\t};\n\t}, [ bottomClientId, lastSelectedElement, selectedElement ] );\n\n\tif ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ mergedRefs }\n\t\t\tanimate={ false }\n\t\t\tposition=\"top right left\"\n\t\t\tfocusOnMount={ false }\n\t\t\tanchor={ popoverAnchor }\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\tresize={ false }\n\t\t\tflip={ false }\n\t\t\tshift\n\t\t\t{ ...props }\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-block-popover',\n\t\t\t\tprops.className\n\t\t\t) }\n\t\t>\n\t\t\t{ __unstableCoverTarget && <div style={ style }>{ children }</div> }\n\t\t\t{ ! __unstableCoverTarget && children }\n\t\t</Popover>\n\t);\n}\n\nexport default forwardRef( BlockPopover );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-popover/index.js"],"names":["MAX_POPOVER_RECOMPUTE_COUNTER","Number","MAX_SAFE_INTEGER","BlockPopover","ref","clientId","bottomClientId","children","__unstableRefreshSize","__unstableCoverTarget","__unstablePopoverSlot","__unstableContentRef","props","selectedElement","lastSelectedElement","mergedRefs","style","position","width","offsetWidth","height","offsetHeight","popoverAnchorRecomputeCounter","forceRecomputePopoverAnchor","s","observer","window","MutationObserver","observe","attributes","disconnect","popoverAnchor","undefined","getBoundingClientRect","selectedBCR","lastSelectedBCR","left","Math","min","Infinity","top","right","max","bottom","DOMRect","ownerDocument","className"],"mappings":";;;;;;;;;AAUA;;;;AAPA;;AAKA;;AACA;;AAWA;;AACA;;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;AAIA,MAAMA,6BAA6B,GAAGC,MAAM,CAACC,gBAA7C;;AAEA,SAASC,YAAT,OAWCC,GAXD,EAYE;AAAA,MAXD;AACCC,IAAAA,QADD;AAECC,IAAAA,cAFD;AAGCC,IAAAA,QAHD;AAICC,IAAAA,qBAJD;AAKCC,IAAAA,qBAAqB,GAAG,KALzB;AAMCC,IAAAA,qBAND;AAOCC,IAAAA,oBAPD;AAQC,OAAGC;AARJ,GAWC;AACD,QAAMC,eAAe,GAAG,6CAAiBR,QAAjB,CAAxB;AACA,QAAMS,mBAAmB,GAAG,6CAAiBR,cAAjB,aAAiBA,cAAjB,cAAiBA,cAAjB,GAAmCD,QA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gBAHV;AAIC,IAAA,YAAY,EAAG,KAJhB;AAKC,IAAA,MAAM,EAAGgB,aALV,CAMC;AACA;AAPD;AAQC,IAAA,kBAAkB,EAAGrB,qBAAqB,IAAI,IAR/C;AASC,IAAA,MAAM,EAAG,KATV;AAUC,IAAA,IAAI,EAAG,KAVR;AAWC,IAAA,KAAK;AAXN,KAYME,KAZN;AAaC,IAAA,SAAS,EAAG,yBACX,4BADW,EAEXA,KAAK,CAACkC,SAFK;AAbb,MAkBGrC,qBAAqB,IAAI;AAAK,IAAA,KAAK,EAAGO;AAAb,KAAuBT,QAAvB,CAlB5B,EAmBG,CAAEE,qBAAF,IAA2BF,QAnB9B,CADD;AAuBA;;eAEc,yBAAYJ,YAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { Popover } from '@wordpress/components';\nimport {\n\tforwardRef,\n\tuseMemo,\n\tuseReducer,\n\tuseLayoutEffect,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\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\nfunction BlockPopover(\n\t{\n\t\tclientId,\n\t\tbottomClientId,\n\t\tchildren,\n\t\t__unstableRefreshSize,\n\t\t__unstableCoverTarget = false,\n\t\t__unstablePopoverSlot,\n\t\t__unstableContentRef,\n\t\t...props\n\t},\n\tref\n) {\n\tconst selectedElement = useBlockElement( clientId );\n\tconst lastSelectedElement = useBlockElement( bottomClientId ?? clientId );\n\tconst mergedRefs = useMergeRefs( [\n\t\tref,\n\t\tusePopoverScroll( __unstableContentRef ),\n\t] );\n\tconst style = useMemo( () => {\n\t\tif ( ! selectedElement || lastSelectedElement !== selectedElement ) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn {\n\t\t\tposition: 'absolute',\n\t\t\twidth: selectedElement.offsetWidth,\n\t\t\theight: selectedElement.offsetHeight,\n\t\t};\n\t}, [ selectedElement, lastSelectedElement, __unstableRefreshSize ] );\n\n\tconst [ popoverAnchorRecomputeCounter, forceRecomputePopoverAnchor ] =\n\t\tuseReducer(\n\t\t\t// Module is there to make sure that the counter doesn't overflow.\n\t\t\t( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,\n\t\t\t0\n\t\t);\n\n\t// When blocks are moved up/down, they are animated to their new position 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 ( ! selectedElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst observer = new window.MutationObserver(\n\t\t\tforceRecomputePopoverAnchor\n\t\t);\n\t\tobserver.observe( selectedElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ selectedElement ] );\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif (\n\t\t\t// popoverAnchorRecomputeCounter is by definition always equal or greater\n\t\t\t// than 0. 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\tpopoverAnchorRecomputeCounter < 0 ||\n\t\t\t! selectedElement ||\n\t\t\t( bottomClientId && ! lastSelectedElement )\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst selectedBCR = selectedElement.getBoundingClientRect();\n\t\t\t\tconst lastSelectedBCR =\n\t\t\t\t\tlastSelectedElement?.getBoundingClientRect();\n\n\t\t\t\t// Get the biggest rectangle that encompasses completely the currently\n\t\t\t\t// selected element and the last selected element:\n\t\t\t\t// - for top/left coordinates, use the smaller numbers\n\t\t\t\t// - for the bottom/right coordinates, use the largest numbers\n\t\t\t\tconst left = Math.min(\n\t\t\t\t\tselectedBCR.left,\n\t\t\t\t\tlastSelectedBCR?.left ?? Infinity\n\t\t\t\t);\n\t\t\t\tconst top = Math.min(\n\t\t\t\t\tselectedBCR.top,\n\t\t\t\t\tlastSelectedBCR?.top ?? Infinity\n\t\t\t\t);\n\t\t\t\tconst right = Math.max(\n\t\t\t\t\tselectedBCR.right,\n\t\t\t\t\tlastSelectedBCR.right ?? -Infinity\n\t\t\t\t);\n\t\t\t\tconst bottom = Math.max(\n\t\t\t\t\tselectedBCR.bottom,\n\t\t\t\t\tlastSelectedBCR.bottom ?? -Infinity\n\t\t\t\t);\n\t\t\t\tconst width = right - left;\n\t\t\t\tconst height = bottom - top;\n\n\t\t\t\treturn new window.DOMRect( left, top, width, height );\n\t\t\t},\n\t\t\townerDocument: selectedElement.ownerDocument,\n\t\t};\n\t}, [\n\t\tbottomClientId,\n\t\tlastSelectedElement,\n\t\tselectedElement,\n\t\tpopoverAnchorRecomputeCounter,\n\t] );\n\n\tif ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ mergedRefs }\n\t\t\tanimate={ false }\n\t\t\tposition=\"top right left\"\n\t\t\tfocusOnMount={ false }\n\t\t\tanchor={ popoverAnchor }\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\tresize={ false }\n\t\t\tflip={ false }\n\t\t\tshift\n\t\t\t{ ...props }\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-block-popover',\n\t\t\t\tprops.className\n\t\t\t) }\n\t\t>\n\t\t\t{ __unstableCoverTarget && <div style={ style }>{ children }</div> }\n\t\t\t{ ! __unstableCoverTarget && children }\n\t\t</Popover>\n\t);\n}\n\nexport default forwardRef( BlockPopover );\n"]}