@wordpress/compose 6.11.0 → 6.12.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 (100) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/higher-order/pipe.js +6 -19
  3. package/build/higher-order/pipe.js.map +1 -1
  4. package/build/higher-order/with-global-events/listener.js +1 -3
  5. package/build/higher-order/with-global-events/listener.js.map +1 -1
  6. package/build/higher-order/with-state/index.js +1 -2
  7. package/build/higher-order/with-state/index.js.map +1 -1
  8. package/build/hooks/use-async-list/index.js +3 -4
  9. package/build/hooks/use-async-list/index.js.map +1 -1
  10. package/build/hooks/use-constrained-tabbing/index.js +1 -1
  11. package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
  12. package/build/hooks/use-copy-on-click/index.js +5 -8
  13. package/build/hooks/use-copy-on-click/index.js.map +1 -1
  14. package/build/hooks/use-copy-to-clipboard/index.js +3 -4
  15. package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
  16. package/build/hooks/use-dialog/index.js +3 -7
  17. package/build/hooks/use-dialog/index.js.map +1 -1
  18. package/build/hooks/use-disabled/index.js +4 -7
  19. package/build/hooks/use-disabled/index.js.map +1 -1
  20. package/build/hooks/use-dragging/index.js +5 -6
  21. package/build/hooks/use-dragging/index.js.map +1 -1
  22. package/build/hooks/use-drop-zone/index.js +27 -21
  23. package/build/hooks/use-drop-zone/index.js.map +1 -1
  24. package/build/hooks/use-fixed-window-list/index.js +14 -22
  25. package/build/hooks/use-fixed-window-list/index.js.map +1 -1
  26. package/build/hooks/use-focus-on-mount/index.js +3 -4
  27. package/build/hooks/use-focus-on-mount/index.js.map +1 -1
  28. package/build/hooks/use-focus-outside/index.js +1 -3
  29. package/build/hooks/use-focus-outside/index.js.map +1 -1
  30. package/build/hooks/use-focus-return/index.js +3 -7
  31. package/build/hooks/use-focus-return/index.js.map +1 -1
  32. package/build/hooks/use-keyboard-shortcut/index.js +14 -14
  33. package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
  34. package/build/hooks/use-media-query/index.js +1 -1
  35. package/build/hooks/use-media-query/index.js.map +1 -1
  36. package/build/hooks/use-preferred-color-scheme/index.android.js +3 -4
  37. package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
  38. package/build/hooks/use-resize-observer/index.js +1 -2
  39. package/build/hooks/use-resize-observer/index.js.map +1 -1
  40. package/build/hooks/use-resize-observer/index.native.js +3 -4
  41. package/build/hooks/use-resize-observer/index.native.js.map +1 -1
  42. package/build/hooks/use-viewport-match/index.js +1 -2
  43. package/build/hooks/use-viewport-match/index.js.map +1 -1
  44. package/build/hooks/use-warn-on-change/index.js +2 -5
  45. package/build/hooks/use-warn-on-change/index.js.map +1 -1
  46. package/build/utils/debounce/index.js +1 -6
  47. package/build/utils/debounce/index.js.map +1 -1
  48. package/build-module/higher-order/pipe.js +6 -19
  49. package/build-module/higher-order/pipe.js.map +1 -1
  50. package/build-module/higher-order/with-global-events/listener.js +1 -3
  51. package/build-module/higher-order/with-global-events/listener.js.map +1 -1
  52. package/build-module/higher-order/with-state/index.js +1 -2
  53. package/build-module/higher-order/with-state/index.js.map +1 -1
  54. package/build-module/hooks/use-async-list/index.js +3 -4
  55. package/build-module/hooks/use-async-list/index.js.map +1 -1
  56. package/build-module/hooks/use-constrained-tabbing/index.js +1 -1
  57. package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
  58. package/build-module/hooks/use-copy-on-click/index.js +5 -8
  59. package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
  60. package/build-module/hooks/use-copy-to-clipboard/index.js +3 -4
  61. package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
  62. package/build-module/hooks/use-dialog/index.js +3 -7
  63. package/build-module/hooks/use-dialog/index.js.map +1 -1
  64. package/build-module/hooks/use-disabled/index.js +4 -7
  65. package/build-module/hooks/use-disabled/index.js.map +1 -1
  66. package/build-module/hooks/use-dragging/index.js +5 -6
  67. package/build-module/hooks/use-dragging/index.js.map +1 -1
  68. package/build-module/hooks/use-drop-zone/index.js +27 -21
  69. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  70. package/build-module/hooks/use-fixed-window-list/index.js +14 -22
  71. package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
  72. package/build-module/hooks/use-focus-on-mount/index.js +3 -4
  73. package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
  74. package/build-module/hooks/use-focus-outside/index.js +1 -3
  75. package/build-module/hooks/use-focus-outside/index.js.map +1 -1
  76. package/build-module/hooks/use-focus-return/index.js +3 -7
  77. package/build-module/hooks/use-focus-return/index.js.map +1 -1
  78. package/build-module/hooks/use-keyboard-shortcut/index.js +14 -14
  79. package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
  80. package/build-module/hooks/use-media-query/index.js +1 -1
  81. package/build-module/hooks/use-media-query/index.js.map +1 -1
  82. package/build-module/hooks/use-preferred-color-scheme/index.android.js +3 -4
  83. package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
  84. package/build-module/hooks/use-resize-observer/index.js +1 -2
  85. package/build-module/hooks/use-resize-observer/index.js.map +1 -1
  86. package/build-module/hooks/use-resize-observer/index.native.js +3 -4
  87. package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
  88. package/build-module/hooks/use-viewport-match/index.js +1 -2
  89. package/build-module/hooks/use-viewport-match/index.js.map +1 -1
  90. package/build-module/hooks/use-warn-on-change/index.js +2 -5
  91. package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
  92. package/build-module/utils/debounce/index.js +1 -6
  93. package/build-module/utils/debounce/index.js.map +1 -1
  94. package/build-types/hooks/use-drop-zone/index.d.ts +11 -9
  95. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  96. package/package.json +8 -8
  97. package/src/hooks/use-drop-zone/README.md +71 -0
  98. package/src/hooks/use-drop-zone/index.js +17 -10
  99. package/src/hooks/use-drop-zone/test/index.js +63 -0
  100. package/tsconfig.tsbuildinfo +1 -1
@@ -50,8 +50,8 @@ const DEFAULT_INIT_WINDOW_SIZE = 30;
50
50
  function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
51
51
  var _options$initWindowSi, _options$useWindowing;
52
52
 
53
- const initWindowSize = (_options$initWindowSi = options === null || options === void 0 ? void 0 : options.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE;
54
- const useWindowing = (_options$useWindowing = options === null || options === void 0 ? void 0 : options.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true;
53
+ const initWindowSize = (_options$initWindowSi = options?.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE;
54
+ const useWindowing = (_options$useWindowing = options?.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true;
55
55
  const [fixedListWindow, setFixedListWindow] = (0, _element.useState)({
56
56
  visibleItems: initWindowSize,
57
57
  start: 0,
@@ -63,8 +63,6 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
63
63
  }
64
64
  });
65
65
  (0, _element.useLayoutEffect)(() => {
66
- var _scrollContainer$owne, _scrollContainer$owne2, _scrollContainer$owne3, _scrollContainer$owne4;
67
-
68
66
  if (!useWindowing) {
69
67
  return;
70
68
  }
@@ -82,7 +80,7 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
82
80
 
83
81
  const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); // Aim to keep opening list view fast, afterward we can optimize for scrolling.
84
82
 
85
- const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options === null || options === void 0 ? void 0 : options.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems;
83
+ const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options?.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems;
86
84
  const firstViewableIndex = Math.floor(scrollContainer.scrollTop / itemHeight);
87
85
  const start = Math.max(0, firstViewableIndex - windowOverscan);
88
86
  const end = Math.min(totalItems - 1, firstViewableIndex + visibleItems + windowOverscan);
@@ -110,19 +108,15 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
110
108
  const debounceMeasureList = (0, _debounce.debounce)(() => {
111
109
  measureWindow();
112
110
  }, 16);
113
- scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener('scroll', debounceMeasureList);
114
- scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne = scrollContainer.ownerDocument) === null || _scrollContainer$owne === void 0 ? void 0 : (_scrollContainer$owne2 = _scrollContainer$owne.defaultView) === null || _scrollContainer$owne2 === void 0 ? void 0 : _scrollContainer$owne2.addEventListener('resize', debounceMeasureList);
115
- scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne3 = scrollContainer.ownerDocument) === null || _scrollContainer$owne3 === void 0 ? void 0 : (_scrollContainer$owne4 = _scrollContainer$owne3.defaultView) === null || _scrollContainer$owne4 === void 0 ? void 0 : _scrollContainer$owne4.addEventListener('resize', debounceMeasureList);
111
+ scrollContainer?.addEventListener('scroll', debounceMeasureList);
112
+ scrollContainer?.ownerDocument?.defaultView?.addEventListener('resize', debounceMeasureList);
113
+ scrollContainer?.ownerDocument?.defaultView?.addEventListener('resize', debounceMeasureList);
116
114
  return () => {
117
- var _scrollContainer$owne5, _scrollContainer$owne6;
118
-
119
- scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('scroll', debounceMeasureList);
120
- scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne5 = scrollContainer.ownerDocument) === null || _scrollContainer$owne5 === void 0 ? void 0 : (_scrollContainer$owne6 = _scrollContainer$owne5.defaultView) === null || _scrollContainer$owne6 === void 0 ? void 0 : _scrollContainer$owne6.removeEventListener('resize', debounceMeasureList);
115
+ scrollContainer?.removeEventListener('scroll', debounceMeasureList);
116
+ scrollContainer?.ownerDocument?.defaultView?.removeEventListener('resize', debounceMeasureList);
121
117
  };
122
118
  }, [itemHeight, elementRef, totalItems]);
123
119
  (0, _element.useLayoutEffect)(() => {
124
- var _scrollContainer$owne7, _scrollContainer$owne8;
125
-
126
120
  if (!useWindowing) {
127
121
  return;
128
122
  }
@@ -135,39 +129,37 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
135
129
  switch (event.keyCode) {
136
130
  case _keycodes.HOME:
137
131
  {
138
- return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
132
+ return scrollContainer?.scrollTo({
139
133
  top: 0
140
134
  });
141
135
  }
142
136
 
143
137
  case _keycodes.END:
144
138
  {
145
- return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
139
+ return scrollContainer?.scrollTo({
146
140
  top: totalItems * itemHeight
147
141
  });
148
142
  }
149
143
 
150
144
  case _keycodes.PAGEUP:
151
145
  {
152
- return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
146
+ return scrollContainer?.scrollTo({
153
147
  top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight
154
148
  });
155
149
  }
156
150
 
157
151
  case _keycodes.PAGEDOWN:
158
152
  {
159
- return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
153
+ return scrollContainer?.scrollTo({
160
154
  top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight
161
155
  });
162
156
  }
163
157
  }
164
158
  };
165
159
 
166
- scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne7 = scrollContainer.ownerDocument) === null || _scrollContainer$owne7 === void 0 ? void 0 : (_scrollContainer$owne8 = _scrollContainer$owne7.defaultView) === null || _scrollContainer$owne8 === void 0 ? void 0 : _scrollContainer$owne8.addEventListener('keydown', handleKeyDown);
160
+ scrollContainer?.ownerDocument?.defaultView?.addEventListener('keydown', handleKeyDown);
167
161
  return () => {
168
- var _scrollContainer$owne9, _scrollContainer$owne10;
169
-
170
- scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne9 = scrollContainer.ownerDocument) === null || _scrollContainer$owne9 === void 0 ? void 0 : (_scrollContainer$owne10 = _scrollContainer$owne9.defaultView) === null || _scrollContainer$owne10 === void 0 ? void 0 : _scrollContainer$owne10.removeEventListener('keydown', handleKeyDown);
162
+ scrollContainer?.ownerDocument?.defaultView?.removeEventListener('keydown', handleKeyDown);
171
163
  };
172
164
  }, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems]);
173
165
  return [fixedListWindow, setFixedListWindow];
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-fixed-window-list/index.js"],"names":["DEFAULT_INIT_WINDOW_SIZE","useFixedWindowList","elementRef","itemHeight","totalItems","options","initWindowSize","useWindowing","fixedListWindow","setFixedListWindow","visibleItems","start","end","itemInView","index","scrollContainer","current","measureWindow","initRender","Math","ceil","clientHeight","windowOverscan","firstViewableIndex","floor","scrollTop","max","min","lastWindow","nextWindow","debounceMeasureList","addEventListener","ownerDocument","defaultView","removeEventListener","handleKeyDown","event","keyCode","HOME","scrollTo","top","END","PAGEUP","PAGEDOWN"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,MAAMA,wBAAwB,GAAG,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,kBAAT,CACdC,UADc,EAEdC,UAFc,EAGdC,UAHc,EAIdC,OAJc,EAKb;AAAA;;AACD,QAAMC,cAAc,4BAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,cAAZ,yEAA8BN,wBAAlD;AACA,QAAMO,YAAY,4BAAGF,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEE,YAAZ,yEAA4B,IAA9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,aAAjB,6GAAgCC,WAAhC,oFAA6CC,mBAA7C,CACC,SADD,EAECC,aAFD;AAIA,KALD;AAMA,GAzCD,EAyCG,CAAE/B,UAAF,EAAcD,UAAd,EAA0BD,UAA1B,EAAsCM,eAAe,CAACE,YAAtD,CAzCH;AA2CA,SAAO,CAAEF,eAAF,EAAmBC,kBAAnB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { PAGEUP, PAGEDOWN, HOME, END } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\nconst DEFAULT_INIT_WINDOW_SIZE = 30;\n\n/**\n * @typedef {Object} WPFixedWindowList\n *\n * @property {number} visibleItems Items visible in the current viewport\n * @property {number} start Start index of the window\n * @property {number} end End index of the window\n * @property {(index:number)=>boolean} itemInView Returns true if item is in the window\n */\n\n/**\n * @typedef {Object} WPFixedWindowListOptions\n *\n * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.\n * @property {boolean} [useWindowing] When false avoids calculating the window size\n * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.\n */\n\n/**\n *\n * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.\n * @param { number } itemHeight Fixed item height in pixels\n * @param { number } totalItems Total items in list\n * @param { WPFixedWindowListOptions } [options] Options object\n * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter\n */\nexport default function useFixedWindowList(\n\telementRef,\n\titemHeight,\n\ttotalItems,\n\toptions\n) {\n\tconst initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;\n\tconst useWindowing = options?.useWindowing ?? true;\n\n\tconst [ fixedListWindow, setFixedListWindow ] = useState( {\n\t\tvisibleItems: initWindowSize,\n\t\tstart: 0,\n\t\tend: initWindowSize,\n\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\treturn index >= 0 && index <= initWindowSize;\n\t\t},\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst measureWindow = (\n\t\t\t/** @type {boolean | undefined} */ initRender\n\t\t) => {\n\t\t\tif ( ! scrollContainer ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst visibleItems = Math.ceil(\n\t\t\t\tscrollContainer.clientHeight / itemHeight\n\t\t\t);\n\t\t\t// Aim to keep opening list view fast, afterward we can optimize for scrolling.\n\t\t\tconst windowOverscan = initRender\n\t\t\t\t? visibleItems\n\t\t\t\t: options?.windowOverscan ?? visibleItems;\n\t\t\tconst firstViewableIndex = Math.floor(\n\t\t\t\tscrollContainer.scrollTop / itemHeight\n\t\t\t);\n\t\t\tconst start = Math.max( 0, firstViewableIndex - windowOverscan );\n\t\t\tconst end = Math.min(\n\t\t\t\ttotalItems - 1,\n\t\t\t\tfirstViewableIndex + visibleItems + windowOverscan\n\t\t\t);\n\t\t\tsetFixedListWindow( ( lastWindow ) => {\n\t\t\t\tconst nextWindow = {\n\t\t\t\t\tvisibleItems,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\t\t\t\treturn start <= index && index <= end;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tif (\n\t\t\t\t\tlastWindow.start !== nextWindow.start ||\n\t\t\t\t\tlastWindow.end !== nextWindow.end ||\n\t\t\t\t\tlastWindow.visibleItems !== nextWindow.visibleItems\n\t\t\t\t) {\n\t\t\t\t\treturn nextWindow;\n\t\t\t\t}\n\t\t\t\treturn lastWindow;\n\t\t\t} );\n\t\t};\n\n\t\tmeasureWindow( true );\n\t\tconst debounceMeasureList = debounce( () => {\n\t\t\tmeasureWindow();\n\t\t}, 16 );\n\t\tscrollContainer?.addEventListener( 'scroll', debounceMeasureList );\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\n\t\treturn () => {\n\t\t\tscrollContainer?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t};\n\t}, [ itemHeight, elementRef, totalItems ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst handleKeyDown = ( /** @type {KeyboardEvent} */ event ) => {\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase HOME: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( { top: 0 } );\n\t\t\t\t}\n\t\t\t\tcase END: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop: totalItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEUP: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop -\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEDOWN: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop +\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'keydown',\n\t\t\thandleKeyDown\n\t\t);\n\t\treturn () => {\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'keydown',\n\t\t\t\thandleKeyDown\n\t\t\t);\n\t\t};\n\t}, [ totalItems, itemHeight, elementRef, fixedListWindow.visibleItems ] );\n\n\treturn [ fixedListWindow, setFixedListWindow ];\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-fixed-window-list/index.js"],"names":["DEFAULT_INIT_WINDOW_SIZE","useFixedWindowList","elementRef","itemHeight","totalItems","options","initWindowSize","useWindowing","fixedListWindow","setFixedListWindow","visibleItems","start","end","itemInView","index","scrollContainer","current","measureWindow","initRender","Math","ceil","clientHeight","windowOverscan","firstViewableIndex","floor","scrollTop","max","min","lastWindow","nextWindow","debounceMeasureList","addEventListener","ownerDocument","defaultView","removeEventListener","handleKeyDown","event","keyCode","HOME","scrollTo","top","END","PAGEUP","PAGEDOWN"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,MAAMA,wBAAwB,GAAG,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,kBAAT,CACdC,UADc,EAEdC,UAFc,EAGdC,UAHc,EAIdC,OAJc,EAKb;AAAA;;AACD,QAAMC,cAAc,4BAAGD,OAAO,EAAEC,cAAZ,yEAA8BN,wBAAlD;AACA,QAAMO,YAAY,4BAAGF,OAAO,EAAEE,YAAZ,yEAA4B,IAA9C;AAEA,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0C,uBAAU;AACzDC,IAAAA,YAAY,EAAEJ,cAD2C;AAEzDK,IAAAA,KAAK,EAAE,CAFkD;AAGzDC,IAAAA,GAAG,EAAEN,cAHoD;AAIzDO,IAAAA,UAAU,EAAE;AA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C,cAAAA,GAAG,EAAEpC,UAAU,GAAGD;AADe,aAA3B,CAAP;AAGA;;AACD,aAAKuC,gBAAL;AAAa;AACZ,mBAAO3B,eAAe,EAAEwB,QAAjB,CAA2B;AACjCC,cAAAA,GAAG,EACFzB,eAAe,CAACU,SAAhB,GACAjB,eAAe,CAACE,YAAhB,GAA+BP;AAHC,aAA3B,CAAP;AAKA;;AACD,aAAKwC,kBAAL;AAAe;AACd,mBAAO5B,eAAe,EAAEwB,QAAjB,CAA2B;AACjCC,cAAAA,GAAG,EACFzB,eAAe,CAACU,SAAhB,GACAjB,eAAe,CAACE,YAAhB,GAA+BP;AAHC,aAA3B,CAAP;AAKA;AAtBF;AAwBA,KAzBD;;AA0BAY,IAAAA,eAAe,EAAEiB,aAAjB,EAAgCC,WAAhC,EAA6CF,gBAA7C,CACC,SADD,EAECI,aAFD;AAIA,WAAO,MAAM;AACZpB,MAAAA,eAAe,EAAEiB,aAAjB,EAAgCC,WAAhC,EAA6CC,mBAA7C,CACC,SADD,EAECC,aAFD;AAIA,KALD;AAMA,GAzCD,EAyCG,CAAE/B,UAAF,EAAcD,UAAd,EAA0BD,UAA1B,EAAsCM,eAAe,CAACE,YAAtD,CAzCH;AA2CA,SAAO,CAAEF,eAAF,EAAmBC,kBAAnB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { PAGEUP, PAGEDOWN, HOME, END } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\nconst DEFAULT_INIT_WINDOW_SIZE = 30;\n\n/**\n * @typedef {Object} WPFixedWindowList\n *\n * @property {number} visibleItems Items visible in the current viewport\n * @property {number} start Start index of the window\n * @property {number} end End index of the window\n * @property {(index:number)=>boolean} itemInView Returns true if item is in the window\n */\n\n/**\n * @typedef {Object} WPFixedWindowListOptions\n *\n * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.\n * @property {boolean} [useWindowing] When false avoids calculating the window size\n * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.\n */\n\n/**\n *\n * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.\n * @param { number } itemHeight Fixed item height in pixels\n * @param { number } totalItems Total items in list\n * @param { WPFixedWindowListOptions } [options] Options object\n * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter\n */\nexport default function useFixedWindowList(\n\telementRef,\n\titemHeight,\n\ttotalItems,\n\toptions\n) {\n\tconst initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;\n\tconst useWindowing = options?.useWindowing ?? true;\n\n\tconst [ fixedListWindow, setFixedListWindow ] = useState( {\n\t\tvisibleItems: initWindowSize,\n\t\tstart: 0,\n\t\tend: initWindowSize,\n\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\treturn index >= 0 && index <= initWindowSize;\n\t\t},\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst measureWindow = (\n\t\t\t/** @type {boolean | undefined} */ initRender\n\t\t) => {\n\t\t\tif ( ! scrollContainer ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst visibleItems = Math.ceil(\n\t\t\t\tscrollContainer.clientHeight / itemHeight\n\t\t\t);\n\t\t\t// Aim to keep opening list view fast, afterward we can optimize for scrolling.\n\t\t\tconst windowOverscan = initRender\n\t\t\t\t? visibleItems\n\t\t\t\t: options?.windowOverscan ?? visibleItems;\n\t\t\tconst firstViewableIndex = Math.floor(\n\t\t\t\tscrollContainer.scrollTop / itemHeight\n\t\t\t);\n\t\t\tconst start = Math.max( 0, firstViewableIndex - windowOverscan );\n\t\t\tconst end = Math.min(\n\t\t\t\ttotalItems - 1,\n\t\t\t\tfirstViewableIndex + visibleItems + windowOverscan\n\t\t\t);\n\t\t\tsetFixedListWindow( ( lastWindow ) => {\n\t\t\t\tconst nextWindow = {\n\t\t\t\t\tvisibleItems,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\t\t\t\treturn start <= index && index <= end;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tif (\n\t\t\t\t\tlastWindow.start !== nextWindow.start ||\n\t\t\t\t\tlastWindow.end !== nextWindow.end ||\n\t\t\t\t\tlastWindow.visibleItems !== nextWindow.visibleItems\n\t\t\t\t) {\n\t\t\t\t\treturn nextWindow;\n\t\t\t\t}\n\t\t\t\treturn lastWindow;\n\t\t\t} );\n\t\t};\n\n\t\tmeasureWindow( true );\n\t\tconst debounceMeasureList = debounce( () => {\n\t\t\tmeasureWindow();\n\t\t}, 16 );\n\t\tscrollContainer?.addEventListener( 'scroll', debounceMeasureList );\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\n\t\treturn () => {\n\t\t\tscrollContainer?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t};\n\t}, [ itemHeight, elementRef, totalItems ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst handleKeyDown = ( /** @type {KeyboardEvent} */ event ) => {\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase HOME: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( { top: 0 } );\n\t\t\t\t}\n\t\t\t\tcase END: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop: totalItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEUP: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop -\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEDOWN: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop +\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'keydown',\n\t\t\thandleKeyDown\n\t\t);\n\t\treturn () => {\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'keydown',\n\t\t\t\thandleKeyDown\n\t\t\t);\n\t\t};\n\t}, [ totalItems, itemHeight, elementRef, fixedListWindow.visibleItems ] );\n\n\treturn [ fixedListWindow, setFixedListWindow ];\n}\n"]}
@@ -34,8 +34,7 @@ var _dom = require("@wordpress/dom");
34
34
  * }
35
35
  * ```
36
36
  */
37
- function useFocusOnMount() {
38
- let focusOnMount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'firstElement';
37
+ function useFocusOnMount(focusOnMount = 'firstElement') {
39
38
  const focusOnMountRef = (0, _element.useRef)(focusOnMount);
40
39
  /**
41
40
  * Sets focus on a DOM element.
@@ -67,13 +66,13 @@ function useFocusOnMount() {
67
66
  };
68
67
  }, []);
69
68
  return (0, _element.useCallback)(node => {
70
- var _node$ownerDocument$a, _node$ownerDocument;
69
+ var _node$ownerDocument$a;
71
70
 
72
71
  if (!node || focusOnMountRef.current === false) {
73
72
  return;
74
73
  }
75
74
 
76
- if (node.contains((_node$ownerDocument$a = (_node$ownerDocument = node.ownerDocument) === null || _node$ownerDocument === void 0 ? void 0 : _node$ownerDocument.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) {
75
+ if (node.contains((_node$ownerDocument$a = node.ownerDocument?.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) {
77
76
  return;
78
77
  }
79
78
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-on-mount/index.js"],"names":["useFocusOnMount","focusOnMount","focusOnMountRef","setFocus","target","focus","preventScroll","timerId","current","clearTimeout","node","contains","ownerDocument","activeElement","setTimeout","firstTabbable","tabbable","find"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,GAA0D;AAAA,MAAhCC,YAAgC,uEAAjB,cAAiB;AACxE,QAAMC,eAAe,GAAG,qBAAQD,YAAR,CAAxB;AAEA;AACD;AACA;AACA;AACA;AACA;;AACC,QAAME,QAAQ,GAAKC,MAAF,IAAc;AAC9BA,IAAAA,MAAM,CAACC,KAAP,CAAc;AACb;AACA;AACA;AACAC,MAAAA,aAAa,EAAE;AAJF,KAAd;AAMA,GAPD;AASA;;;AACA,QAAMC,OAAO,GAAG,sBAAhB;AAEA,0BAAW,MAAM;AAChBL,IAAAA,eAAe,CAACM,OAAhB,GAA0BP,YAA1B;AACA,GAFD,EAEG,CAAEA,YAAF,CAFH;AAIA,0BAAW,MAAM;AAChB,WAAO,MAAM;AACZ,UAAKM,OAAO,CAACC,OAAb,EAAuB;AACtBC,QAAAA,YAAY,CAAEF,OAAO,CAACC,OAAV,CAAZ;AACA;AACD,KAJD;AAKA,GAND,EAMG,EANH;AAQA,SAAO,0BAAeE,IAAF,IAAY;AAAA;;AAC/B,QAAK,CAAEA,IAAF,IAAUR,eAAe,CAACM,OAAhB,KAA4B,KAA3C,EAAmD;AAClD;AACA;;AAED,QAAKE,IAAI,CAACC,QAAL,iDAAeD,IAAI,CAACE,aAApB,wDAAe,oBAAoBC,aAAnC,yEAAoD,IAApD,CAAL,EAAkE;AACjE;AACA;;AAED,QAAKX,eAAe,CAACM,OAAhB,KAA4B,cAAjC,EAAkD;AACjDD,MAAAA,OAAO,CAACC,OAAR,GAAkBM,UAAU,CAAE,MAAM;AACnC,cAAMC,aAAa,GAAGV,WAAMW,QAAN,CAAeC,IAAf,CAAqBP,IAArB,EAA6B,CAA7B,CAAtB;;AAEA,YAAKK,aAAL,EAAqB;AACpBZ,UAAAA,QAAQ;AAAE;AAA6BY,UAAAA,aAA/B,CAAR;AACA;AACD,OAN2B,EAMzB,CANyB,CAA5B;AAQA;AACA;;AAEDZ,IAAAA,QAAQ,CAAEO,IAAF,CAAR;AACA,GAtBM,EAsBJ,EAtBI,CAAP;AAuBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Hook used to focus the first tabbable element on mount.\n *\n * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.\n * @return {import('react').RefCallback<HTMLElement>} Ref callback.\n *\n * @example\n * ```js\n * import { useFocusOnMount } from '@wordpress/compose';\n *\n * const WithFocusOnMount = () => {\n * const ref = useFocusOnMount()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nexport default function useFocusOnMount( focusOnMount = 'firstElement' ) {\n\tconst focusOnMountRef = useRef( focusOnMount );\n\n\t/**\n\t * Sets focus on a DOM element.\n\t *\n\t * @param {HTMLElement} target The DOM element to set focus to.\n\t * @return {void}\n\t */\n\tconst setFocus = ( target ) => {\n\t\ttarget.focus( {\n\t\t\t// When focusing newly mounted dialogs,\n\t\t\t// the position of the popover is often not right on the first render\n\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\tpreventScroll: true,\n\t\t} );\n\t};\n\n\t/** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */\n\tconst timerId = useRef();\n\n\tuseEffect( () => {\n\t\tfocusOnMountRef.current = focusOnMount;\n\t}, [ focusOnMount ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( timerId.current ) {\n\t\t\t\tclearTimeout( timerId.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( ! node || focusOnMountRef.current === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( node.contains( node.ownerDocument?.activeElement ?? null ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( focusOnMountRef.current === 'firstElement' ) {\n\t\t\ttimerId.current = setTimeout( () => {\n\t\t\t\tconst firstTabbable = focus.tabbable.find( node )[ 0 ];\n\n\t\t\t\tif ( firstTabbable ) {\n\t\t\t\t\tsetFocus( /** @type {HTMLElement} */ ( firstTabbable ) );\n\t\t\t\t}\n\t\t\t}, 0 );\n\n\t\t\treturn;\n\t\t}\n\n\t\tsetFocus( node );\n\t}, [] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-on-mount/index.js"],"names":["useFocusOnMount","focusOnMount","focusOnMountRef","setFocus","target","focus","preventScroll","timerId","current","clearTimeout","node","contains","ownerDocument","activeElement","setTimeout","firstTabbable","tabbable","find"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,CAA0BC,YAAY,GAAG,cAAzC,EAA0D;AACxE,QAAMC,eAAe,GAAG,qBAAQD,YAAR,CAAxB;AAEA;AACD;AACA;AACA;AACA;AACA;;AACC,QAAME,QAAQ,GAAKC,MAAF,IAAc;AAC9BA,IAAAA,MAAM,CAACC,KAAP,CAAc;AACb;AACA;AACA;AACAC,MAAAA,aAAa,EAAE;AAJF,KAAd;AAMA,GAPD;AASA;;;AACA,QAAMC,OAAO,GAAG,sBAAhB;AAEA,0BAAW,MAAM;AAChBL,IAAAA,eAAe,CAACM,OAAhB,GAA0BP,YAA1B;AACA,GAFD,EAEG,CAAEA,YAAF,CAFH;AAIA,0BAAW,MAAM;AAChB,WAAO,MAAM;AACZ,UAAKM,OAAO,CAACC,OAAb,EAAuB;AACtBC,QAAAA,YAAY,CAAEF,OAAO,CAACC,OAAV,CAAZ;AACA;AACD,KAJD;AAKA,GAND,EAMG,EANH;AAQA,SAAO,0BAAeE,IAAF,IAAY;AAAA;;AAC/B,QAAK,CAAEA,IAAF,IAAUR,eAAe,CAACM,OAAhB,KAA4B,KAA3C,EAAmD;AAClD;AACA;;AAED,QAAKE,IAAI,CAACC,QAAL,0BAAeD,IAAI,CAACE,aAAL,EAAoBC,aAAnC,yEAAoD,IAApD,CAAL,EAAkE;AACjE;AACA;;AAED,QAAKX,eAAe,CAACM,OAAhB,KAA4B,cAAjC,EAAkD;AACjDD,MAAAA,OAAO,CAACC,OAAR,GAAkBM,UAAU,CAAE,MAAM;AACnC,cAAMC,aAAa,GAAGV,WAAMW,QAAN,CAAeC,IAAf,CAAqBP,IAArB,EAA6B,CAA7B,CAAtB;;AAEA,YAAKK,aAAL,EAAqB;AACpBZ,UAAAA,QAAQ;AAAE;AAA6BY,UAAAA,aAA/B,CAAR;AACA;AACD,OAN2B,EAMzB,CANyB,CAA5B;AAQA;AACA;;AAEDZ,IAAAA,QAAQ,CAAEO,IAAF,CAAR;AACA,GAtBM,EAsBJ,EAtBI,CAAP;AAuBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Hook used to focus the first tabbable element on mount.\n *\n * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.\n * @return {import('react').RefCallback<HTMLElement>} Ref callback.\n *\n * @example\n * ```js\n * import { useFocusOnMount } from '@wordpress/compose';\n *\n * const WithFocusOnMount = () => {\n * const ref = useFocusOnMount()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nexport default function useFocusOnMount( focusOnMount = 'firstElement' ) {\n\tconst focusOnMountRef = useRef( focusOnMount );\n\n\t/**\n\t * Sets focus on a DOM element.\n\t *\n\t * @param {HTMLElement} target The DOM element to set focus to.\n\t * @return {void}\n\t */\n\tconst setFocus = ( target ) => {\n\t\ttarget.focus( {\n\t\t\t// When focusing newly mounted dialogs,\n\t\t\t// the position of the popover is often not right on the first render\n\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\tpreventScroll: true,\n\t\t} );\n\t};\n\n\t/** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */\n\tconst timerId = useRef();\n\n\tuseEffect( () => {\n\t\tfocusOnMountRef.current = focusOnMount;\n\t}, [ focusOnMount ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( timerId.current ) {\n\t\t\t\tclearTimeout( timerId.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( ! node || focusOnMountRef.current === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( node.contains( node.ownerDocument?.activeElement ?? null ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( focusOnMountRef.current === 'firstElement' ) {\n\t\t\ttimerId.current = setTimeout( () => {\n\t\t\t\tconst firstTabbable = focus.tabbable.find( node )[ 0 ];\n\n\t\t\t\tif ( firstTabbable ) {\n\t\t\t\t\tsetFocus( /** @type {HTMLElement} */ ( firstTabbable ) );\n\t\t\t\t}\n\t\t\t}, 0 );\n\n\t\t\treturn;\n\t\t}\n\n\t\tsetFocus( node );\n\t}, [] );\n}\n"]}
@@ -120,8 +120,6 @@ function useFocusOutside(onFocusOutside) {
120
120
  */
121
121
 
122
122
  const queueBlurCheck = (0, _element.useCallback)(event => {
123
- var _event$relatedTarget;
124
-
125
123
  // React does not allow using an event reference asynchronously
126
124
  // due to recycling behavior, except when explicitly persisted.
127
125
  event.persist(); // Skip blur check if clicking button. See `normalizeButtonFocus`.
@@ -139,7 +137,7 @@ function useFocusOutside(onFocusOutside) {
139
137
 
140
138
  const ignoreForRelatedTarget = event.target.getAttribute('data-unstable-ignore-focus-outside-for-relatedtarget');
141
139
 
142
- if (ignoreForRelatedTarget && (_event$relatedTarget = event.relatedTarget) !== null && _event$relatedTarget !== void 0 && _event$relatedTarget.closest(ignoreForRelatedTarget)) {
140
+ if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) {
143
141
  return;
144
142
  }
145
143
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.ts"],"names":["INPUT_BUTTON_TYPES","isFocusNormalizedButton","eventTarget","window","HTMLElement","nodeName","includes","type","useFocusOutside","onFocusOutside","currentOnFocusOutside","current","preventBlurCheck","blurCheckTimeoutId","cancelBlurCheck","clearTimeout","normalizeButtonFocus","event","target","isInteractionEnd","queueBlurCheck","persist","ignoreForRelatedTarget","getAttribute","relatedTarget","closest","setTimeout","document","hasFocus","preventDefault","onFocus","onMouseDown","onMouseUp","onTouchStart","onTouchEnd","onBlur"],"mappings":";;;;;;;AAgBA;;AAhBA;AACA;AACA;;AAWA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CAAE,QAAF,EAAY,QAAZ,CAA3B;AAEA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAT,CACCC,WADD,EAEwC;AACvC,MAAK,EAAIA,WAAW,YAAYC,MAAM,CAACC,WAAlC,CAAL,EAAuD;AACtD,WAAO,KA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,KAA3B;AACA,KAFD,MAEO,IAAKV,uBAAuB,CAAEiB,MAAF,CAA5B,EAAyC;AAC/CN,MAAAA,gBAAgB,CAACD,OAAjB,GAA2B,IAA3B;AACA;AACD,GATD,EASG,EATH,CADD;AAYA;AACD;AACA;AACA;AACA;AACA;AACA;;AACC,QAAMS,cAAiC,GAAG,0BAAeH,KAAF,IAAa;AAAA;;AACnE;AACA;AACAA,IAAAA,KAAK,CAACI,OAAN,GAHmE,CAKnE;;AACA,QAAKT,gBAAgB,CAACD,OAAtB,EAAgC;AAC/B;AACA,KARkE,CAUnE;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,UAAMW,sBAAsB,GAAGL,KAAK,CAACC,MAAN,CAAaK,YAAb,CAC9B,sDAD8B,CAA/B;;AAGA,QACCD,sBAAsB,4BACtBL,KAAK,CAACO,aADgB,iDACtB,qBAAqBC,OAArB,CAA8BH,sBAA9B,CAFD,EAGE;AACD;AACA;;AAEDT,IAAAA,kBAAkB,CAACF,OAAnB,GAA6Be,UAAU,CAAE,MAAM;AAC9C;AACA;AACA;AACA;AACA,UAAK,CAAEC,QAAQ,CAACC,QAAT,EAAP,EAA6B;AAC5BX,QAAAA,KAAK,CAACY,cAAN;AACA;AACA;;AAED,UAAK,eAAe,OAAOnB,qBAAqB,CAACC,OAAjD,EAA2D;AAC1DD,QAAAA,qBAAqB,CAACC,OAAtB,CAA+BM,KAA/B;AACA;AACD,KAbsC,EAapC,CAboC,CAAvC;AAcA,GAzCyC,EAyCvC,EAzCuC,CAA1C;AA2CA,SAAO;AACNa,IAAAA,OAAO,EAAEhB,eADH;AAENiB,IAAAA,WAAW,EAAEf,oBAFP;AAGNgB,IAAAA,SAAS,EAAEhB,oBAHL;AAINiB,IAAAA,YAAY,EAAEjB,oBAJR;AAKNkB,IAAAA,UAAU,EAAElB,oBALN;AAMNmB,IAAAA,MAAM,EAAEf;AANF,GAAP;AAQA","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tFocusEventHandler,\n\tEventHandler,\n\tMouseEventHandler,\n\tTouchEventHandler,\n\tFocusEvent,\n\tMouseEvent,\n\tTouchEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Input types which are classified as button types, for use in considering\n * whether element is a (focus-normalized) button.\n */\nconst INPUT_BUTTON_TYPES = [ 'button', 'submit' ];\n\n/**\n * List of HTML button elements subject to focus normalization\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n */\ntype FocusNormalizedButton =\n\t| HTMLButtonElement\n\t| HTMLLinkElement\n\t| HTMLInputElement;\n\n/**\n * Returns true if the given element is a button element subject to focus\n * normalization, or false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n *\n * @param eventTarget The target from a mouse or touch event.\n *\n * @return Whether the element is a button element subject to focus normalization.\n */\nfunction isFocusNormalizedButton(\n\teventTarget: EventTarget\n): eventTarget is FocusNormalizedButton {\n\tif ( ! ( eventTarget instanceof window.HTMLElement ) ) {\n\t\treturn false;\n\t}\n\tswitch ( eventTarget.nodeName ) {\n\t\tcase 'A':\n\t\tcase 'BUTTON':\n\t\t\treturn true;\n\n\t\tcase 'INPUT':\n\t\t\treturn INPUT_BUTTON_TYPES.includes(\n\t\t\t\t( eventTarget as HTMLInputElement ).type\n\t\t\t);\n\t}\n\n\treturn false;\n}\n\ntype UseFocusOutsideReturn = {\n\tonFocus: FocusEventHandler;\n\tonMouseDown: MouseEventHandler;\n\tonMouseUp: MouseEventHandler;\n\tonTouchStart: TouchEventHandler;\n\tonTouchEnd: TouchEventHandler;\n\tonBlur: FocusEventHandler;\n};\n\n/**\n * A react hook that can be used to check whether focus has moved outside the\n * element the event handlers are bound to.\n *\n * @param onFocusOutside A callback triggered when focus moves outside\n * the element the event handlers are bound to.\n *\n * @return An object containing event handlers. Bind the event handlers to a\n * wrapping element element to capture when focus moves outside that element.\n */\nexport default function useFocusOutside(\n\tonFocusOutside: ( event: FocusEvent ) => void\n): UseFocusOutsideReturn {\n\tconst currentOnFocusOutside = useRef( onFocusOutside );\n\tuseEffect( () => {\n\t\tcurrentOnFocusOutside.current = onFocusOutside;\n\t}, [ onFocusOutside ] );\n\n\tconst preventBlurCheck = useRef( false );\n\n\tconst blurCheckTimeoutId = useRef< number | undefined >();\n\n\t/**\n\t * Cancel a blur check timeout.\n\t */\n\tconst cancelBlurCheck = useCallback( () => {\n\t\tclearTimeout( blurCheckTimeoutId.current );\n\t}, [] );\n\n\t// Cancel blur checks on unmount.\n\tuseEffect( () => {\n\t\treturn () => cancelBlurCheck();\n\t}, [] );\n\n\t// Cancel a blur check if the callback or ref is no longer provided.\n\tuseEffect( () => {\n\t\tif ( ! onFocusOutside ) {\n\t\t\tcancelBlurCheck();\n\t\t}\n\t}, [ onFocusOutside, cancelBlurCheck ] );\n\n\t/**\n\t * Handles a mousedown or mouseup event to respectively assign and\n\t * unassign a flag for preventing blur check on button elements. Some\n\t * browsers, namely Firefox and Safari, do not emit a focus event on\n\t * button elements when clicked, while others do. The logic here\n\t * intends to normalize this as treating click on buttons as focus.\n\t *\n\t * @param event\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\t */\n\tconst normalizeButtonFocus: EventHandler< MouseEvent | TouchEvent > =\n\t\tuseCallback( ( event ) => {\n\t\t\tconst { type, target } = event;\n\t\t\tconst isInteractionEnd = [ 'mouseup', 'touchend' ].includes( type );\n\n\t\t\tif ( isInteractionEnd ) {\n\t\t\t\tpreventBlurCheck.current = false;\n\t\t\t} else if ( isFocusNormalizedButton( target ) ) {\n\t\t\t\tpreventBlurCheck.current = true;\n\t\t\t}\n\t\t}, [] );\n\n\t/**\n\t * A callback triggered when a blur event occurs on the element the handler\n\t * is bound to.\n\t *\n\t * Calls the `onFocusOutside` callback in an immediate timeout if focus has\n\t * move outside the bound element and is still within the document.\n\t */\n\tconst queueBlurCheck: FocusEventHandler = useCallback( ( event ) => {\n\t\t// React does not allow using an event reference asynchronously\n\t\t// due to recycling behavior, except when explicitly persisted.\n\t\tevent.persist();\n\n\t\t// Skip blur check if clicking button. See `normalizeButtonFocus`.\n\t\tif ( preventBlurCheck.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The usage of this attribute should be avoided. The only use case\n\t\t// would be when we load modals that are not React components and\n\t\t// therefore don't exist in the React tree. An example is opening\n\t\t// the Media Library modal from another dialog.\n\t\t// This attribute should contain a selector of the related target\n\t\t// we want to ignore, because we still need to trigger the blur event\n\t\t// on all other cases.\n\t\tconst ignoreForRelatedTarget = event.target.getAttribute(\n\t\t\t'data-unstable-ignore-focus-outside-for-relatedtarget'\n\t\t);\n\t\tif (\n\t\t\tignoreForRelatedTarget &&\n\t\t\tevent.relatedTarget?.closest( ignoreForRelatedTarget )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tblurCheckTimeoutId.current = setTimeout( () => {\n\t\t\t// If document is not focused then focus should remain\n\t\t\t// inside the wrapped component and therefore we cancel\n\t\t\t// this blur event thereby leaving focus in place.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.\n\t\t\tif ( ! document.hasFocus() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( 'function' === typeof currentOnFocusOutside.current ) {\n\t\t\t\tcurrentOnFocusOutside.current( event );\n\t\t\t}\n\t\t}, 0 );\n\t}, [] );\n\n\treturn {\n\t\tonFocus: cancelBlurCheck,\n\t\tonMouseDown: normalizeButtonFocus,\n\t\tonMouseUp: normalizeButtonFocus,\n\t\tonTouchStart: normalizeButtonFocus,\n\t\tonTouchEnd: normalizeButtonFocus,\n\t\tonBlur: queueBlurCheck,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.ts"],"names":["INPUT_BUTTON_TYPES","isFocusNormalizedButton","eventTarget","window","HTMLElement","nodeName","includes","type","useFocusOutside","onFocusOutside","currentOnFocusOutside","current","preventBlurCheck","blurCheckTimeoutId","cancelBlurCheck","clearTimeout","normalizeButtonFocus","event","target","isInteractionEnd","queueBlurCheck","persist","ignoreForRelatedTarget","getAttribute","relatedTarget","closest","setTimeout","document","hasFocus","preventDefault","onFocus","onMouseDown","onMouseUp","onTouchStart","onTouchEnd","onBlur"],"mappings":";;;;;;;AAgBA;;AAhBA;AACA;AACA;;AAWA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CAAE,QAAF,EAAY,QAAZ,CAA3B;AAEA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAT,CACCC,WADD,EAEwC;AACvC,MAAK,EAAIA,WAAW,YAAYC,MAAM,CAACC,WAAlC,CAAL,EAAuD;AACtD,WAAO,KAAP;AACA;;AACD,UAASF,WAAW,CAACG,QAArB;AACC,SAAK,GAAL;AACA,SAAK,QAAL;AACC,aAAO,IAAP;;AAED,SAAK,OAAL;AACC,aAAOL,kBAAkB,CAACM,QAAnB,CACJJ,WAAF,CAAoCK,IAD9B,CAAP;AANF;;AAWA,SAAO,KAAP;AACA;;AAWD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,eAAT,CACdC,cADc,EAEU;AACxB,QAAMC,qBAAqB,GAAG,qBAAQD,cAAR,CAA9B;AACA,0BAAW,MAAM;AAChBC,IAAAA,qBAAqB,CAACC,OAAtB,GAAgCF,cAAhC;AACA,GAFD,EAEG,CAAEA,cAAF,CAFH;AAIA,QAAMG,gBAAgB,GAAG,qBAAQ,KAAR,CAAzB;AAEA,QAAMC,kBAAkB,GAAG,sBAA3B;AAEA;AACD;AACA;;AACC,QAAMC,eAAe,GAAG,0BAAa,MAAM;AAC1CC,IAAAA,YAAY,CAAEF,kBAAkB,CAACF,OAArB,CAAZ;AACA,GAFuB,EAErB,EAFqB,CAA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EC,QAAQ,CAACC,QAAT,EAAP,EAA6B;AAC5BX,QAAAA,KAAK,CAACY,cAAN;AACA;AACA;;AAED,UAAK,eAAe,OAAOnB,qBAAqB,CAACC,OAAjD,EAA2D;AAC1DD,QAAAA,qBAAqB,CAACC,OAAtB,CAA+BM,KAA/B;AACA;AACD,KAbsC,EAapC,CAboC,CAAvC;AAcA,GAzCyC,EAyCvC,EAzCuC,CAA1C;AA2CA,SAAO;AACNa,IAAAA,OAAO,EAAEhB,eADH;AAENiB,IAAAA,WAAW,EAAEf,oBAFP;AAGNgB,IAAAA,SAAS,EAAEhB,oBAHL;AAINiB,IAAAA,YAAY,EAAEjB,oBAJR;AAKNkB,IAAAA,UAAU,EAAElB,oBALN;AAMNmB,IAAAA,MAAM,EAAEf;AANF,GAAP;AAQA","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tFocusEventHandler,\n\tEventHandler,\n\tMouseEventHandler,\n\tTouchEventHandler,\n\tFocusEvent,\n\tMouseEvent,\n\tTouchEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Input types which are classified as button types, for use in considering\n * whether element is a (focus-normalized) button.\n */\nconst INPUT_BUTTON_TYPES = [ 'button', 'submit' ];\n\n/**\n * List of HTML button elements subject to focus normalization\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n */\ntype FocusNormalizedButton =\n\t| HTMLButtonElement\n\t| HTMLLinkElement\n\t| HTMLInputElement;\n\n/**\n * Returns true if the given element is a button element subject to focus\n * normalization, or false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n *\n * @param eventTarget The target from a mouse or touch event.\n *\n * @return Whether the element is a button element subject to focus normalization.\n */\nfunction isFocusNormalizedButton(\n\teventTarget: EventTarget\n): eventTarget is FocusNormalizedButton {\n\tif ( ! ( eventTarget instanceof window.HTMLElement ) ) {\n\t\treturn false;\n\t}\n\tswitch ( eventTarget.nodeName ) {\n\t\tcase 'A':\n\t\tcase 'BUTTON':\n\t\t\treturn true;\n\n\t\tcase 'INPUT':\n\t\t\treturn INPUT_BUTTON_TYPES.includes(\n\t\t\t\t( eventTarget as HTMLInputElement ).type\n\t\t\t);\n\t}\n\n\treturn false;\n}\n\ntype UseFocusOutsideReturn = {\n\tonFocus: FocusEventHandler;\n\tonMouseDown: MouseEventHandler;\n\tonMouseUp: MouseEventHandler;\n\tonTouchStart: TouchEventHandler;\n\tonTouchEnd: TouchEventHandler;\n\tonBlur: FocusEventHandler;\n};\n\n/**\n * A react hook that can be used to check whether focus has moved outside the\n * element the event handlers are bound to.\n *\n * @param onFocusOutside A callback triggered when focus moves outside\n * the element the event handlers are bound to.\n *\n * @return An object containing event handlers. Bind the event handlers to a\n * wrapping element element to capture when focus moves outside that element.\n */\nexport default function useFocusOutside(\n\tonFocusOutside: ( event: FocusEvent ) => void\n): UseFocusOutsideReturn {\n\tconst currentOnFocusOutside = useRef( onFocusOutside );\n\tuseEffect( () => {\n\t\tcurrentOnFocusOutside.current = onFocusOutside;\n\t}, [ onFocusOutside ] );\n\n\tconst preventBlurCheck = useRef( false );\n\n\tconst blurCheckTimeoutId = useRef< number | undefined >();\n\n\t/**\n\t * Cancel a blur check timeout.\n\t */\n\tconst cancelBlurCheck = useCallback( () => {\n\t\tclearTimeout( blurCheckTimeoutId.current );\n\t}, [] );\n\n\t// Cancel blur checks on unmount.\n\tuseEffect( () => {\n\t\treturn () => cancelBlurCheck();\n\t}, [] );\n\n\t// Cancel a blur check if the callback or ref is no longer provided.\n\tuseEffect( () => {\n\t\tif ( ! onFocusOutside ) {\n\t\t\tcancelBlurCheck();\n\t\t}\n\t}, [ onFocusOutside, cancelBlurCheck ] );\n\n\t/**\n\t * Handles a mousedown or mouseup event to respectively assign and\n\t * unassign a flag for preventing blur check on button elements. Some\n\t * browsers, namely Firefox and Safari, do not emit a focus event on\n\t * button elements when clicked, while others do. The logic here\n\t * intends to normalize this as treating click on buttons as focus.\n\t *\n\t * @param event\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\t */\n\tconst normalizeButtonFocus: EventHandler< MouseEvent | TouchEvent > =\n\t\tuseCallback( ( event ) => {\n\t\t\tconst { type, target } = event;\n\t\t\tconst isInteractionEnd = [ 'mouseup', 'touchend' ].includes( type );\n\n\t\t\tif ( isInteractionEnd ) {\n\t\t\t\tpreventBlurCheck.current = false;\n\t\t\t} else if ( isFocusNormalizedButton( target ) ) {\n\t\t\t\tpreventBlurCheck.current = true;\n\t\t\t}\n\t\t}, [] );\n\n\t/**\n\t * A callback triggered when a blur event occurs on the element the handler\n\t * is bound to.\n\t *\n\t * Calls the `onFocusOutside` callback in an immediate timeout if focus has\n\t * move outside the bound element and is still within the document.\n\t */\n\tconst queueBlurCheck: FocusEventHandler = useCallback( ( event ) => {\n\t\t// React does not allow using an event reference asynchronously\n\t\t// due to recycling behavior, except when explicitly persisted.\n\t\tevent.persist();\n\n\t\t// Skip blur check if clicking button. See `normalizeButtonFocus`.\n\t\tif ( preventBlurCheck.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The usage of this attribute should be avoided. The only use case\n\t\t// would be when we load modals that are not React components and\n\t\t// therefore don't exist in the React tree. An example is opening\n\t\t// the Media Library modal from another dialog.\n\t\t// This attribute should contain a selector of the related target\n\t\t// we want to ignore, because we still need to trigger the blur event\n\t\t// on all other cases.\n\t\tconst ignoreForRelatedTarget = event.target.getAttribute(\n\t\t\t'data-unstable-ignore-focus-outside-for-relatedtarget'\n\t\t);\n\t\tif (\n\t\t\tignoreForRelatedTarget &&\n\t\t\tevent.relatedTarget?.closest( ignoreForRelatedTarget )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tblurCheckTimeoutId.current = setTimeout( () => {\n\t\t\t// If document is not focused then focus should remain\n\t\t\t// inside the wrapped component and therefore we cancel\n\t\t\t// this blur event thereby leaving focus in place.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.\n\t\t\tif ( ! document.hasFocus() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( 'function' === typeof currentOnFocusOutside.current ) {\n\t\t\t\tcurrentOnFocusOutside.current( event );\n\t\t\t}\n\t\t}, 0 );\n\t}, [] );\n\n\treturn {\n\t\tonFocus: cancelBlurCheck,\n\t\tonMouseDown: normalizeButtonFocus,\n\t\tonMouseUp: normalizeButtonFocus,\n\t\tonTouchStart: normalizeButtonFocus,\n\t\tonTouchEnd: normalizeButtonFocus,\n\t\tonBlur: queueBlurCheck,\n\t};\n}\n"]}
@@ -56,11 +56,9 @@ function useFocusReturn(onFocusReturn) {
56
56
 
57
57
  focusedBeforeMount.current = node.ownerDocument.activeElement;
58
58
  } else if (focusedBeforeMount.current) {
59
- var _ref$current, _ref$current2, _ref$current3;
59
+ const isFocused = ref.current?.contains(ref.current?.ownerDocument.activeElement);
60
60
 
61
- const isFocused = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.ownerDocument.activeElement);
62
-
63
- if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.isConnected && !isFocused) {
61
+ if (ref.current?.isConnected && !isFocused) {
64
62
  return;
65
63
  } // Defer to the component's own explicit focus return behavior, if
66
64
  // specified. This allows for support that the `onFocusReturn`
@@ -71,10 +69,8 @@ function useFocusReturn(onFocusReturn) {
71
69
  if (onFocusReturnRef.current) {
72
70
  onFocusReturnRef.current();
73
71
  } else {
74
- var _focusedBeforeMount$c;
75
-
76
72
  /** @type {null | HTMLElement} */
77
- (_focusedBeforeMount$c = focusedBeforeMount.current) === null || _focusedBeforeMount$c === void 0 ? void 0 : _focusedBeforeMount$c.focus();
73
+ focusedBeforeMount.current?.focus();
78
74
  }
79
75
  }
80
76
  }, []);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-return/index.js"],"names":["useFocusReturn","onFocusReturn","ref","focusedBeforeMount","onFocusReturnRef","current","node","ownerDocument","activeElement","isFocused","contains","isConnected","focus"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,cAAT,CAAyBC,aAAzB,EAAyC;AACxC;AACA,QAAMC,GAAG,GAAG,qBAAQ,IAAR,CAAZ;AACA;;AACA,QAAMC,kBAAkB,GAAG,qBAAQ,IAAR,CAA3B;AACA,QAAMC,gBAAgB,GAAG,qBAAQH,aAAR,CAAzB;AACA,0BAAW,MAAM;AAChBG,IAAAA,gBAAgB,CAACC,OAAjB,GAA2BJ,aAA3B;AACA,GAFD,EAEG,CAAEA,aAAF,CAFH;AAIA,SAAO,0BAAeK,IAAF,IAAY;AAC/B,QAAKA,IAAL,EAAY;AACX;AACAJ,MAAAA,GAAG,CAACG,OAAJ,GAAcC,IAAd,CAFW,CAIX;;AACA,UAAKH,kBAAkB,CAACE,OAAxB,EAAkC;AACjC;AACA;;AAEDF,MAAAA,kBAAkB,CAACE,OAAnB,GAA6BC,IAAI,CAACC,aAAL,CAAmBC,aAAhD;AACA,KAVD,MAUO,IAAKL,kBAAkB,CAACE,OAAxB,EAAkC;AAAA;;AACxC,YAAMI,SAAS,mBAAGP,GAAG,CAACG,OAAP,iDAAG,aAAaK,QAAb,kBACjBR,GAAG,CAACG,OADa,kDACjB,cAAaE,aAAb,CAA2BC,aADV,CAAlB;;AAIA,UAAK,iBAAAN,GAAG,CAACG,OAAJ,wDAAaM,WAAb,IAA4B,CAAEF,SAAnC,EAA+C;AAC9C;AACA,OAPuC,CASxC;AACA;AACA;AACA;;;AACA,UAAKL,gBAAgB,CAACC,OAAtB,EAAgC;AAC/BD,QAAAA,gBAAgB,CAACC,OAAjB;AACA,OAFD,MAEO;AAAA;;AACN;AAAkC,iCACjCF,kBAAkB,CAACE,OADc,gFAE/BO,KAF+B;AAGlC;AACD;AACD,GAhCM,EAgCJ,EAhCI,CAAP;AAiCA;;eAEcZ,c","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\n/**\n * When opening modals/sidebars/dialogs, the focus\n * must move to the opened area and return to the\n * previously focused element when closed.\n * The current hook implements the returning behavior.\n *\n * @param {() => void} [onFocusReturn] Overrides the default return behavior.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn( onFocusReturn ) {\n\t/** @type {import('react').MutableRefObject<null | HTMLElement>} */\n\tconst ref = useRef( null );\n\t/** @type {import('react').MutableRefObject<null | Element>} */\n\tconst focusedBeforeMount = useRef( null );\n\tconst onFocusReturnRef = useRef( onFocusReturn );\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMount.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfocusedBeforeMount.current = node.ownerDocument.activeElement;\n\t\t} else if ( focusedBeforeMount.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\t/** @type {null | HTMLElement} */ (\n\t\t\t\t\tfocusedBeforeMount.current\n\t\t\t\t)?.focus();\n\t\t\t}\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-return/index.js"],"names":["useFocusReturn","onFocusReturn","ref","focusedBeforeMount","onFocusReturnRef","current","node","ownerDocument","activeElement","isFocused","contains","isConnected","focus"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,cAAT,CAAyBC,aAAzB,EAAyC;AACxC;AACA,QAAMC,GAAG,GAAG,qBAAQ,IAAR,CAAZ;AACA;;AACA,QAAMC,kBAAkB,GAAG,qBAAQ,IAAR,CAA3B;AACA,QAAMC,gBAAgB,GAAG,qBAAQH,aAAR,CAAzB;AACA,0BAAW,MAAM;AAChBG,IAAAA,gBAAgB,CAACC,OAAjB,GAA2BJ,aAA3B;AACA,GAFD,EAEG,CAAEA,aAAF,CAFH;AAIA,SAAO,0BAAeK,IAAF,IAAY;AAC/B,QAAKA,IAAL,EAAY;AACX;AACAJ,MAAAA,GAAG,CAACG,OAAJ,GAAcC,IAAd,CAFW,CAIX;;AACA,UAAKH,kBAAkB,CAACE,OAAxB,EAAkC;AACjC;AACA;;AAEDF,MAAAA,kBAAkB,CAACE,OAAnB,GAA6BC,IAAI,CAACC,aAAL,CAAmBC,aAAhD;AACA,KAVD,MAUO,IAAKL,kBAAkB,CAACE,OAAxB,EAAkC;AACxC,YAAMI,SAAS,GAAGP,GAAG,CAACG,OAAJ,EAAaK,QAAb,CACjBR,GAAG,CAACG,OAAJ,EAAaE,aAAb,CAA2BC,aADV,CAAlB;;AAIA,UAAKN,GAAG,CAACG,OAAJ,EAAaM,WAAb,IAA4B,CAAEF,SAAnC,EAA+C;AAC9C;AACA,OAPuC,CASxC;AACA;AACA;AACA;;;AACA,UAAKL,gBAAgB,CAACC,OAAtB,EAAgC;AAC/BD,QAAAA,gBAAgB,CAACC,OAAjB;AACA,OAFD,MAEO;AACN;AACCF,QAAAA,kBAAkB,CAACE,OADc,EAE/BO,KAF+B;AAGlC;AACD;AACD,GAhCM,EAgCJ,EAhCI,CAAP;AAiCA;;eAEcZ,c","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\n/**\n * When opening modals/sidebars/dialogs, the focus\n * must move to the opened area and return to the\n * previously focused element when closed.\n * The current hook implements the returning behavior.\n *\n * @param {() => void} [onFocusReturn] Overrides the default return behavior.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn( onFocusReturn ) {\n\t/** @type {import('react').MutableRefObject<null | HTMLElement>} */\n\tconst ref = useRef( null );\n\t/** @type {import('react').MutableRefObject<null | Element>} */\n\tconst focusedBeforeMount = useRef( null );\n\tconst onFocusReturnRef = useRef( onFocusReturn );\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMount.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfocusedBeforeMount.current = node.ownerDocument.activeElement;\n\t\t} else if ( focusedBeforeMount.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\t/** @type {null | HTMLElement} */ (\n\t\t\t\t\tfocusedBeforeMount.current\n\t\t\t\t)?.focus();\n\t\t\t}\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"]}
@@ -47,14 +47,13 @@ var _keycodes = require("@wordpress/keycodes");
47
47
  */
48
48
  function useKeyboardShortcut(
49
49
  /* eslint-enable jsdoc/valid-types */
50
- shortcuts, callback) {
51
- let {
52
- bindGlobal = false,
53
- eventName = 'keydown',
54
- isDisabled = false,
55
- // This is important for performance considerations.
56
- target
57
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
50
+ shortcuts, callback, {
51
+ bindGlobal = false,
52
+ eventName = 'keydown',
53
+ isDisabled = false,
54
+ // This is important for performance considerations.
55
+ target
56
+ } = {}) {
58
57
  const currentCallback = (0, _element.useRef)(callback);
59
58
  (0, _element.useEffect)(() => {
60
59
  currentCallback.current = callback;
@@ -88,12 +87,13 @@ shortcuts, callback) {
88
87
 
89
88
  const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; // @ts-ignore `bindGlobal` is an undocumented property
90
89
 
91
- mousetrap[bindFn](shortcut, function () {
92
- return (
93
- /* eslint-enable jsdoc/valid-types */
94
- currentCallback.current(...arguments)
95
- );
96
- }, eventName);
90
+ mousetrap[bindFn](shortcut, (
91
+ /* eslint-disable jsdoc/valid-types */
92
+
93
+ /** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */
94
+ ...args) =>
95
+ /* eslint-enable jsdoc/valid-types */
96
+ currentCallback.current(...args), eventName);
97
97
  });
98
98
  return () => {
99
99
  mousetrap.reset();
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-keyboard-shortcut/index.js"],"names":["useKeyboardShortcut","shortcuts","callback","bindGlobal","eventName","isDisabled","target","currentCallback","current","mousetrap","Mousetrap","document","shortcutsArray","Array","isArray","forEach","shortcut","keys","split","modifiers","Set","filter","value","length","hasAlt","has","hasShift","size","Error","bindFn","reset"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAT;AACC;AACAC,SAFD,EAGCC,QAHD,EAUE;AAAA,MAND;AACCC,IAAAA,UAAU,GAAG,KADd;AAECC,IAAAA,SAAS,GAAG,SAFb;AAGCC,IAAAA,UAAU,GAAG,KAHd;AAGqB;AACpBC,IAAAA;AAJD,GAMC,uEADG,EACH;AACD,QAAMC,eAAe,GAAG,qBAAQL,QAAR,CAAxB;AACA,0BAAW,MAAM;AAChBK,IAAAA,eAAe,CAACC,OAAhB,GAA0BN,QAA1B;AACA,GAFD,EAEG,CAAEA,QAAF,CAFH;AAIA,0BAAW,MAAM;AAChB,QAAKG,UAAL,EAAkB;AACjB;AACA;;AACD,UAAMI,SAAS,GAAG,IAAIC,kBAAJ,CACjBJ,MAAM,IAAIA,MAAM,CAACE,OAAjB,GACGF,MAAM,CAACE,OADV,GAEG;AACA;AACA;;AACA;;AAAyB;AAAyBG,IAAAA,QANpC,CAAlB;AAQA,UAAMC,cAAc,GAAGC,KAAK,CAACC,OAAN,CAAeb,SAAf,IACpBA,SADoB,GAEpB,CAAEA,SAAF,CAFH;AAGAW,IAAAA,cAAc,CAACG,OAAf,CAA0BC,QAAF,IAAgB;AACvC,YAAMC,IAAI,GAAGD,QAAQ,CAACE,KAAT,CAAgB,GAAhB,CAAb,CADuC,CAEvC;AACA;AACA;;AACA,YAAMC,SAAS,GAAG,IAAIC,GAAJ,CACjBH,IAAI,CAACI,MAAL,CAAeC,KAAF,IAAaA,KAAK,CAACC,MAAN,GAAe,CAAzC,CADiB,CAAlB;AAGA,YAAMC,MAAM,GAAGL,SAAS,CAACM,GAAV,CAAe,KAAf,CAAf;AACA,YAAMC,QAAQ,GAAGP,SAAS,CAACM,GAAV,CAAe,OAAf,CAAjB,CATuC,CAWvC;;AACA,UACC,+BACIN,SAAS,CAACQ,IAAV,KAAmB,CAAnB,IAAwBH,MAA1B,IACCL,SAAS,CAACQ,IAAV,KAAmB,CAAnB,IAAwBH,MAAxB,IAAkCE,QAFrC,CADD,EAIE;AACD,cAAM,IAAIE,KAAJ,CACJ,eAAeZ,QAAU,iEADrB,CAAN;AAGA;;AAED,YAAMa,MAAM,GAAG1B,UAAU,GAAG,YAAH,GAAkB,MAA3C,CAtBuC,CAuBvC;;AACAM,MAAAA,SAAS,CAAEoB,MAAF,CAAT,CACCb,QADD,EAEC;AAAA;AAIC;AACAT,UAAAA,eAAe,CAACC,OAAhB,CAAyB,YAAzB;AALD;AAAA,OAFD,EAQCJ,SARD;AAUA,KAlCD;AAoCA,WAAO,MAAM;AACZK,MAAAA,SAAS,CAACqB,KAAV;AACA,KAFD;AAGA,GAtDD,EAsDG,CAAE7B,SAAF,EAAaE,UAAb,EAAyBC,SAAzB,EAAoCE,MAApC,EAA4CD,UAA5C,CAtDH;AAuDA;;eAEcL,mB","sourcesContent":["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * A block selection object.\n *\n * @typedef {Object} WPKeyboardShortcutConfig\n *\n * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.\n * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.\n * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.\n * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Attach a keyboard shortcut handler.\n *\n * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.\n *\n * @param {string[]|string} shortcuts Keyboard Shortcuts.\n * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.\n * @param {WPKeyboardShortcutConfig} options Shortcut options.\n */\nfunction useKeyboardShortcut(\n\t/* eslint-enable jsdoc/valid-types */\n\tshortcuts,\n\tcallback,\n\t{\n\t\tbindGlobal = false,\n\t\teventName = 'keydown',\n\t\tisDisabled = false, // This is important for performance considerations.\n\t\ttarget,\n\t} = {}\n) {\n\tconst currentCallback = useRef( callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = callback;\n\t}, [ callback ] );\n\n\tuseEffect( () => {\n\t\tif ( isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst mousetrap = new Mousetrap(\n\t\t\ttarget && target.current\n\t\t\t\t? target.current\n\t\t\t\t: // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.\n\t\t\t\t // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's\n\t\t\t\t // necessary to maintain the existing behavior.\n\t\t\t\t /** @type {Element} */ ( /** @type {unknown} */ ( document ) )\n\t\t);\n\t\tconst shortcutsArray = Array.isArray( shortcuts )\n\t\t\t? shortcuts\n\t\t\t: [ shortcuts ];\n\t\tshortcutsArray.forEach( ( shortcut ) => {\n\t\t\tconst keys = shortcut.split( '+' );\n\t\t\t// Determines whether a key is a modifier by the length of the string.\n\t\t\t// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that\n\t\t\t// the modifiers are Shift and Cmd because they're not a single character.\n\t\t\tconst modifiers = new Set(\n\t\t\t\tkeys.filter( ( value ) => value.length > 1 )\n\t\t\t);\n\t\t\tconst hasAlt = modifiers.has( 'alt' );\n\t\t\tconst hasShift = modifiers.has( 'shift' );\n\n\t\t\t// This should be better moved to the shortcut registration instead.\n\t\t\tif (\n\t\t\t\tisAppleOS() &&\n\t\t\t\t( ( modifiers.size === 1 && hasAlt ) ||\n\t\t\t\t\t( modifiers.size === 2 && hasAlt && hasShift ) )\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot bind ${ shortcut }. Alt and Shift+Alt modifiers are reserved for character input.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst bindFn = bindGlobal ? 'bindGlobal' : 'bind';\n\t\t\t// @ts-ignore `bindGlobal` is an undocumented property\n\t\t\tmousetrap[ bindFn ](\n\t\t\t\tshortcut,\n\t\t\t\t(\n\t\t\t\t\t/* eslint-disable jsdoc/valid-types */\n\t\t\t\t\t/** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */ ...args\n\t\t\t\t) =>\n\t\t\t\t\t/* eslint-enable jsdoc/valid-types */\n\t\t\t\t\tcurrentCallback.current( ...args ),\n\t\t\t\teventName\n\t\t\t);\n\t\t} );\n\n\t\treturn () => {\n\t\t\tmousetrap.reset();\n\t\t};\n\t}, [ shortcuts, bindGlobal, eventName, target, isDisabled ] );\n}\n\nexport default useKeyboardShortcut;\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-keyboard-shortcut/index.js"],"names":["useKeyboardShortcut","shortcuts","callback","bindGlobal","eventName","isDisabled","target","currentCallback","current","mousetrap","Mousetrap","document","shortcutsArray","Array","isArray","forEach","shortcut","keys","split","modifiers","Set","filter","value","length","hasAlt","has","hasShift","size","Error","bindFn","args","reset"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;A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V,KAAmB,CAAnB,IAAwBH,MAAxB,IAAkCE,QAFrC,CADD,EAIE;AACD,cAAM,IAAIE,KAAJ,CACJ,eAAeZ,QAAU,iEADrB,CAAN;AAGA;;AAED,YAAMa,MAAM,GAAG1B,UAAU,GAAG,YAAH,GAAkB,MAA3C,CAtBuC,CAuBvC;;AACAM,MAAAA,SAAS,CAAEoB,MAAF,CAAT,CACCb,QADD,EAEC;AACC;;AACA;AAA6E,SAAGc,IAFjF;AAIC;AACAvB,MAAAA,eAAe,CAACC,OAAhB,CAAyB,GAAGsB,IAA5B,CAPF,EAQC1B,SARD;AAUA,KAlCD;AAoCA,WAAO,MAAM;AACZK,MAAAA,SAAS,CAACsB,KAAV;AACA,KAFD;AAGA,GAtDD,EAsDG,CAAE9B,SAAF,EAAaE,UAAb,EAAyBC,SAAzB,EAAoCE,MAApC,EAA4CD,UAA5C,CAtDH;AAuDA;;eAEcL,mB","sourcesContent":["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * A block selection object.\n *\n * @typedef {Object} WPKeyboardShortcutConfig\n *\n * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.\n * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.\n * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.\n * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Attach a keyboard shortcut handler.\n *\n * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.\n *\n * @param {string[]|string} shortcuts Keyboard Shortcuts.\n * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.\n * @param {WPKeyboardShortcutConfig} options Shortcut options.\n */\nfunction useKeyboardShortcut(\n\t/* eslint-enable jsdoc/valid-types */\n\tshortcuts,\n\tcallback,\n\t{\n\t\tbindGlobal = false,\n\t\teventName = 'keydown',\n\t\tisDisabled = false, // This is important for performance considerations.\n\t\ttarget,\n\t} = {}\n) {\n\tconst currentCallback = useRef( callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = callback;\n\t}, [ callback ] );\n\n\tuseEffect( () => {\n\t\tif ( isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst mousetrap = new Mousetrap(\n\t\t\ttarget && target.current\n\t\t\t\t? target.current\n\t\t\t\t: // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.\n\t\t\t\t // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's\n\t\t\t\t // necessary to maintain the existing behavior.\n\t\t\t\t /** @type {Element} */ ( /** @type {unknown} */ ( document ) )\n\t\t);\n\t\tconst shortcutsArray = Array.isArray( shortcuts )\n\t\t\t? shortcuts\n\t\t\t: [ shortcuts ];\n\t\tshortcutsArray.forEach( ( shortcut ) => {\n\t\t\tconst keys = shortcut.split( '+' );\n\t\t\t// Determines whether a key is a modifier by the length of the string.\n\t\t\t// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that\n\t\t\t// the modifiers are Shift and Cmd because they're not a single character.\n\t\t\tconst modifiers = new Set(\n\t\t\t\tkeys.filter( ( value ) => value.length > 1 )\n\t\t\t);\n\t\t\tconst hasAlt = modifiers.has( 'alt' );\n\t\t\tconst hasShift = modifiers.has( 'shift' );\n\n\t\t\t// This should be better moved to the shortcut registration instead.\n\t\t\tif (\n\t\t\t\tisAppleOS() &&\n\t\t\t\t( ( modifiers.size === 1 && hasAlt ) ||\n\t\t\t\t\t( modifiers.size === 2 && hasAlt && hasShift ) )\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot bind ${ shortcut }. Alt and Shift+Alt modifiers are reserved for character input.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst bindFn = bindGlobal ? 'bindGlobal' : 'bind';\n\t\t\t// @ts-ignore `bindGlobal` is an undocumented property\n\t\t\tmousetrap[ bindFn ](\n\t\t\t\tshortcut,\n\t\t\t\t(\n\t\t\t\t\t/* eslint-disable jsdoc/valid-types */\n\t\t\t\t\t/** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */ ...args\n\t\t\t\t) =>\n\t\t\t\t\t/* eslint-enable jsdoc/valid-types */\n\t\t\t\t\tcurrentCallback.current( ...args ),\n\t\t\t\teventName\n\t\t\t);\n\t\t} );\n\n\t\treturn () => {\n\t\t\tmousetrap.reset();\n\t\t};\n\t}, [ shortcuts, bindGlobal, eventName, target, isDisabled ] );\n}\n\nexport default useKeyboardShortcut;\n"]}
@@ -51,7 +51,7 @@ function useMediaQuery(query) {
51
51
  getValue() {
52
52
  var _mediaQueryList$match;
53
53
 
54
- return (_mediaQueryList$match = mediaQueryList === null || mediaQueryList === void 0 ? void 0 : mediaQueryList.matches) !== null && _mediaQueryList$match !== void 0 ? _mediaQueryList$match : false;
54
+ return (_mediaQueryList$match = mediaQueryList?.matches) !== null && _mediaQueryList$match !== void 0 ? _mediaQueryList$match : false;
55
55
  }
56
56
 
57
57
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"names":["getMediaQueryList","query","window","matchMedia","useMediaQuery","source","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","matches"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAT,CAA4BC,KAA5B,EAAoC;AACnC,MACCA,KAAK,IACL,OAAOC,MAAP,KAAkB,WADlB,IAEA,OAAOA,MAAM,CAACC,UAAd,KAA6B,UAH9B,EAIE;AACD,WAAOD,MAAM,CAACC,UAAP,CAAmBF,KAAnB,CAAP;AACA;;AAED,SAAO,IAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASG,aAAT,CAAwBH,KAAxB,EAAgC;AAC9C,QAAMI,MAAM,GAAG,sBAAS,MAAM;AAC7B,UAAMC,cAAc,GAAGN,iBAAiB,CAAEC,KAAF,CAAxC;AAEA,WAAO;AACN;AACAM,MAAAA,SAAS,CAAEC,aAAF,EAAkB;AAC1B,YAAK,CAAEF,cAAP,EAAwB;AACvB,iBAAO,MAAM,CAAE,CAAf;AACA;;AAEDA,QAAAA,cAAc,CAACG,gBAAf,CAAiC,QAAjC,EAA2CD,aAA3C;AACA,eAAO,MAAM;AACZF,UAAAA,cAAc,CAACI,mBAAf,CACC,QADD,EAECF,aAFD;AAIA,SALD;AAMA,OAdK;;AAeNG,MAAAA,QAAQ,GAAG;AAAA;;AACV,wCAAOL,cAAP,aAAOA,cAAP,uBAAOA,cAAc,CAAEM,OAAvB,yEAAkC,KAAlC;AACA;;AAjBK,KAAP;AAmBA,GAtBc,EAsBZ,CAAEX,KAAF,CAtBY,CAAf;AAwBA,SAAO,mCACNI,MAAM,CAACE,SADD,EAENF,MAAM,CAACM,QAFD,EAGN,MAAM,KAHA,CAAP;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif (\n\t\tquery &&\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\treturn window.matchMedia( query );\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\tmediaQueryList.addEventListener( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"names":["getMediaQueryList","query","window","matchMedia","useMediaQuery","source","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","matches"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAT,CAA4BC,KAA5B,EAAoC;AACnC,MACCA,KAAK,IACL,OAAOC,MAAP,KAAkB,WADlB,IAEA,OAAOA,MAAM,CAACC,UAAd,KAA6B,UAH9B,EAIE;AACD,WAAOD,MAAM,CAACC,UAAP,CAAmBF,KAAnB,CAAP;AACA;;AAED,SAAO,IAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASG,aAAT,CAAwBH,KAAxB,EAAgC;AAC9C,QAAMI,MAAM,GAAG,sBAAS,MAAM;AAC7B,UAAMC,cAAc,GAAGN,iBAAiB,CAAEC,KAAF,CAAxC;AAEA,WAAO;AACN;AACAM,MAAAA,SAAS,CAAEC,aAAF,EAAkB;AAC1B,YAAK,CAAEF,cAAP,EAAwB;AACvB,iBAAO,MAAM,CAAE,CAAf;AACA;;AAEDA,QAAAA,cAAc,CAACG,gBAAf,CAAiC,QAAjC,EAA2CD,aAA3C;AACA,eAAO,MAAM;AACZF,UAAAA,cAAc,CAACI,mBAAf,CACC,QADD,EAECF,aAFD;AAIA,SALD;AAMA,OAdK;;AAeNG,MAAAA,QAAQ,GAAG;AAAA;;AACV,wCAAOL,cAAc,EAAEM,OAAvB,yEAAkC,KAAlC;AACA;;AAjBK,KAAP;AAmBA,GAtBc,EAsBZ,CAAEX,KAAF,CAtBY,CAAf;AAwBA,SAAO,mCACNI,MAAM,CAACE,SADD,EAENF,MAAM,CAACM,QAFD,EAGN,MAAM,KAHA,CAAP;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif (\n\t\tquery &&\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\treturn window.matchMedia( query );\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\tmediaQueryList.addEventListener( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"]}
@@ -21,10 +21,9 @@ var _reactNativeBridge = require("@wordpress/react-native-bridge");
21
21
  function usePreferredColorScheme() {
22
22
  const [currentColorScheme, setCurrentColorScheme] = (0, _element.useState)(_reactNativeBridge.isInitialColorSchemeDark ? 'dark' : 'light');
23
23
  (0, _element.useEffect)(() => {
24
- (0, _reactNativeBridge.subscribePreferredColorScheme)(_ref => {
25
- let {
26
- isPreferredColorSchemeDark
27
- } = _ref;
24
+ (0, _reactNativeBridge.subscribePreferredColorScheme)(({
25
+ isPreferredColorSchemeDark
26
+ }) => {
28
27
  const colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';
29
28
 
30
29
  if (colorScheme !== currentColorScheme) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.android.js"],"names":["usePreferredColorScheme","currentColorScheme","setCurrentColorScheme","isInitialColorSchemeDark","isPreferredColorSchemeDark","colorScheme"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA,SAASA,uBAAT,GAAmC;AAClC,QAAM,CAAEC,kBAAF,EAAsBC,qBAAtB,IAAgD,uBACrDC,8CAA2B,MAA3B,GAAoC,OADiB,CAAtD;AAGA,0BAAW,MAAM;AAChB,0DAA+B,QAAsC;AAAA,UAApC;AAAEC,QAAAA;AAAF,OAAoC;AACpE,YAAMC,WAAW,GAAGD,0BAA0B,GAAG,MAAH,GAAY,OAA1D;;AACA,UAAKC,WAAW,KAAKJ,kBAArB,EAA0C;AACzCC,QAAAA,qBAAqB,CAAEG,WAAF,CAArB;AACA;AACD,KALD;AAMA,GAPD;AAQA,SAAOJ,kBAAP;AACA;;eAEcD,uB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.android.js"],"names":["usePreferredColorScheme","currentColorScheme","setCurrentColorScheme","isInitialColorSchemeDark","isPreferredColorSchemeDark","colorScheme"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA,SAASA,uBAAT,GAAmC;AAClC,QAAM,CAAEC,kBAAF,EAAsBC,qBAAtB,IAAgD,uBACrDC,8CAA2B,MAA3B,GAAoC,OADiB,CAAtD;AAGA,0BAAW,MAAM;AAChB,0DAA+B,CAAE;AAAEC,MAAAA;AAAF,KAAF,KAAsC;AACpE,YAAMC,WAAW,GAAGD,0BAA0B,GAAG,MAAH,GAAY,OAA1D;;AACA,UAAKC,WAAW,KAAKJ,kBAArB,EAA0C;AACzCC,QAAAA,qBAAqB,CAAEG,WAAF,CAArB;AACA;AACD,KALD;AAMA,GAPD;AAQA,SAAOJ,kBAAP;AACA;;eAEcD,uB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"]}
@@ -115,8 +115,7 @@ const extractSize = (entry, boxProp, sizeType) => {
115
115
  entry[boxProp][sizeType];
116
116
  };
117
117
 
118
- function useResizeObserver() {
119
- let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
118
+ function useResizeObserver(opts = {}) {
120
119
  // Saving the callback as a ref. With this, I don't need to put onResize in the
121
120
  // effect dep array, and just passing in an anonymous function without memoising
122
121
  // will not reinstantiate the hook's ResizeObserver.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.tsx"],"names":["useResolvedElement","subscriber","refOrElement","callbackRefElement","lastReportRef","cleanupRef","callSubscriber","element","current","HTMLElement","reporter","extractSize","entry","boxProp","sizeType","contentRect","undefined","useResizeObserver","opts","onResize","onResizeRef","round","Math","resizeObserverRef","size","setSize","width","height","didUnmount","previous","refCallback","box","instance","ResizeObserver","entries","reportedWidth","reportedHeight","newWidth","newHeight","newSize","observe","unobserve","ref","useResizeAware","sizes","resizeListener","position","top","left","right","bottom","pointerEvents","opacity","overflow","zIndex"],"mappings":";;;;;;;AAQA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAaA;AACA;AACA;AACA;AACA,SAASA,kBAAT,CACCC,UADD,EAECC,YAFD,EAGoB;AACnB,QAAMC,kBAAkB,GAAG,qBAAoB,IAApB,CAA3B;AACA,QAAMC,aAAa,GAAG,qBAGV,IAHU,CAAtB;AAIA,QAAMC,UAAU,GAAG,sBAAnB;AAEA,QAAMC,c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,EAMN,CAAEG,WAAF,EAAeN,IAAI,GAAGA,IAAI,CAACE,KAAR,GAAgB,IAAnC,EAAyCF,IAAI,GAAGA,IAAI,CAACG,MAAR,GAAiB,IAA9D,CANM,CAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASgB,cAAT,GAGb;AACD,QAAM;AAAED,IAAAA,GAAF;AAAOhB,IAAAA,KAAP;AAAcC,IAAAA;AAAd,MAAyBV,iBAAiB,EAAhD;AACA,QAAM2B,KAAK,GAAG,sBAAS,MAAM;AAC5B,WAAO;AAAElB,MAAAA,KAAK,EAAEA,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW,IAAlB;AAAwBC,MAAAA,MAAM,EAAEA,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAY;AAA1C,KAAP;AACA,GAFa,EAEX,CAAED,KAAF,EAASC,MAAT,CAFW,CAAd;AAGA,QAAMkB,cAAc,GACnB;AACC,IAAA,KAAK,EAAG;AACPC,MAAAA,QAAQ,EAAE,UADH;AAEPC,MAAAA,GAAG,EAAE,CAFE;AAGPC,MAAAA,IAAI,EAAE,CAHC;AAIPC,MAAAA,KAAK,EAAE,CAJA;AAKPC,MAAAA,MAAM,EAAE,CALD;AAMPC,MAAAA,aAAa,EAAE,MANR;AAOPC,MAAAA,OAAO,EAAE,CAPF;AAQPC,MAAAA,QAAQ,EAAE,QARH;AASPC,MAAAA,MAAM,EAAE,CAAC;AATF,KADT;AAYC,mBAAY,MAZb;AAaC,IAAA,GAAG,EAAGZ;AAbP,IADD;AAiBA,SAAO,CAAEG,cAAF,EAAkBD,KAAlB,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback, RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseRef,\n\tuseCallback,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\nimport type { WPElement } from '@wordpress/element';\n\ntype SubscriberCleanup = () => void;\ntype SubscriberResponse = SubscriberCleanup | void;\n\n// This of course could've been more streamlined with internal state instead of\n// refs, but then host hooks / components could not opt out of renders.\n// This could've been exported to its own module, but the current build doesn't\n// seem to work with module imports and I had no more time to spend on this...\nfunction useResolvedElement< T extends HTMLElement >(\n\tsubscriber: ( element: T ) => SubscriberResponse,\n\trefOrElement?: T | RefObject< T > | null\n): RefCallback< T > {\n\tconst callbackRefElement = useRef< T | null >( null );\n\tconst lastReportRef = useRef< {\n\t\treporter: () => void;\n\t\telement: T | null;\n\t} | null >( null );\n\tconst cleanupRef = useRef< SubscriberResponse | null >();\n\n\tconst callSubscriber = useCallback( () => {\n\t\tlet element = null;\n\t\tif ( callbackRefElement.current ) {\n\t\t\telement = callbackRefElement.current;\n\t\t} else if ( refOrElement ) {\n\t\t\tif ( refOrElement instanceof HTMLElement ) {\n\t\t\t\telement = refOrElement;\n\t\t\t} else {\n\t\t\t\telement = refOrElement.current;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tlastReportRef.current &&\n\t\t\tlastReportRef.current.element === element &&\n\t\t\tlastReportRef.current.reporter === callSubscriber\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( cleanupRef.current ) {\n\t\t\tcleanupRef.current();\n\t\t\t// Making sure the cleanup is not called accidentally multiple times.\n\t\t\tcleanupRef.current = null;\n\t\t}\n\t\tlastReportRef.current = {\n\t\t\treporter: callSubscriber,\n\t\t\telement,\n\t\t};\n\n\t\t// Only calling the subscriber, if there's an actual element to report.\n\t\tif ( element ) {\n\t\t\tcleanupRef.current = subscriber( element );\n\t\t}\n\t}, [ refOrElement, subscriber ] );\n\n\t// On each render, we check whether a ref changed, or if we got a new raw\n\t// element.\n\tuseEffect( () => {\n\t\t// With this we're *technically* supporting cases where ref objects' current value changes, but only if there's a\n\t\t// render accompanying that change as well.\n\t\t// To guarantee we always have the right element, one must use the ref callback provided instead, but we support\n\t\t// RefObjects to make the hook API more convenient in certain cases.\n\t\tcallSubscriber();\n\t}, [ callSubscriber ] );\n\n\treturn useCallback< RefCallback< T > >(\n\t\t( element ) => {\n\t\t\tcallbackRefElement.current = element;\n\t\t\tcallSubscriber();\n\t\t},\n\t\t[ callSubscriber ]\n\t);\n}\n\ntype ObservedSize = {\n\twidth: number | undefined;\n\theight: number | undefined;\n};\n\ntype ResizeHandler = ( size: ObservedSize ) => void;\n\ntype HookResponse< T extends HTMLElement > = {\n\tref: RefCallback< T >;\n} & ObservedSize;\n\n// Declaring my own type here instead of using the one provided by TS (available since 4.2.2), because this way I'm not\n// forcing consumers to use a specific TS version.\ntype ResizeObserverBoxOptions =\n\t| 'border-box'\n\t| 'content-box'\n\t| 'device-pixel-content-box';\n\ndeclare global {\n\tinterface ResizeObserverEntry {\n\t\treadonly devicePixelContentBoxSize: ReadonlyArray< ResizeObserverSize >;\n\t}\n}\n\n// We're only using the first element of the size sequences, until future versions of the spec solidify on how\n// exactly it'll be used for fragments in multi-column scenarios:\n// From the spec:\n// > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,\n// > which occur in multi-column scenarios. However the current definitions of content rect and border box do not\n// > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single\n// > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.\n// > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)\n//\n// Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,\n// regardless of the \"box\" option.\n// The spec states the following on this:\n// > This does not have any impact on which box dimensions are returned to the defined callback when the event\n// > is fired, it solely defines which box the author wishes to observe layout changes on.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// I'm not exactly clear on what this means, especially when you consider a later section stating the following:\n// > This section is non-normative. An author may desire to observe more than one CSS box.\n// > In this case, author will need to use multiple ResizeObservers.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.\n// For this reason I decided to only return the requested size,\n// even though it seems we have access to results for all box types.\n// This also means that we get to keep the current api, being able to return a simple { width, height } pair,\n// regardless of box option.\nconst extractSize = (\n\tentry: ResizeObserverEntry,\n\tboxProp: 'borderBoxSize' | 'contentBoxSize' | 'devicePixelContentBoxSize',\n\tsizeType: keyof ResizeObserverSize\n): number | undefined => {\n\tif ( ! entry[ boxProp ] ) {\n\t\tif ( boxProp === 'contentBoxSize' ) {\n\t\t\t// The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.\n\t\t\t// See the 6th step in the description for the RO algorithm:\n\t\t\t// https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h\n\t\t\t// > Set this.contentRect to logical this.contentBoxSize given target and observedBox of \"content-box\".\n\t\t\t// In real browser implementations of course these objects differ, but the width/height values should be equivalent.\n\t\t\treturn entry.contentRect[\n\t\t\t\tsizeType === 'inlineSize' ? 'width' : 'height'\n\t\t\t];\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t// A couple bytes smaller than calling Array.isArray() and just as effective here.\n\treturn entry[ boxProp ][ 0 ]\n\t\t? entry[ boxProp ][ 0 ][ sizeType ]\n\t\t: // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's current\n\t\t // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.\n\t\t // @ts-ignore\n\t\t entry[ boxProp ][ sizeType ];\n};\n\ntype RoundingFunction = ( n: number ) => number;\n\nfunction useResizeObserver< T extends HTMLElement >(\n\topts: {\n\t\tref?: RefObject< T > | T | null | undefined;\n\t\tonResize?: ResizeHandler;\n\t\tbox?: ResizeObserverBoxOptions;\n\t\tround?: RoundingFunction;\n\t} = {}\n): HookResponse< T > {\n\t// Saving the callback as a ref. With this, I don't need to put onResize in the\n\t// effect dep array, and just passing in an anonymous function without memoising\n\t// will not reinstantiate the hook's ResizeObserver.\n\tconst onResize = opts.onResize;\n\tconst onResizeRef = useRef< ResizeHandler | undefined >( undefined );\n\tonResizeRef.current = onResize;\n\tconst round = opts.round || Math.round;\n\n\t// Using a single instance throughout the hook's lifetime\n\tconst resizeObserverRef = useRef< {\n\t\tbox?: ResizeObserverBoxOptions;\n\t\tround?: RoundingFunction;\n\t\tinstance: ResizeObserver;\n\t} >();\n\n\tconst [ size, setSize ] = useState< {\n\t\twidth?: number;\n\t\theight?: number;\n\t} >( {\n\t\twidth: undefined,\n\t\theight: undefined,\n\t} );\n\n\t// In certain edge cases the RO might want to report a size change just after\n\t// the component unmounted.\n\tconst didUnmount = useRef( false );\n\tuseEffect( () => {\n\t\tdidUnmount.current = false;\n\t\treturn () => {\n\t\t\tdidUnmount.current = true;\n\t\t};\n\t}, [] );\n\n\t// Using a ref to track the previous width / height to avoid unnecessary renders.\n\tconst previous: {\n\t\tcurrent: {\n\t\t\twidth?: number;\n\t\t\theight?: number;\n\t\t};\n\t} = useRef( {\n\t\twidth: undefined,\n\t\theight: undefined,\n\t} );\n\n\t// This block is kinda like a useEffect, only it's called whenever a new\n\t// element could be resolved based on the ref option. It also has a cleanup\n\t// function.\n\tconst refCallback = useResolvedElement< T >(\n\t\tuseCallback(\n\t\t\t( element ) => {\n\t\t\t\t// We only use a single Resize Observer instance, and we're instantiating it on demand, only once there's something to observe.\n\t\t\t\t// This instance is also recreated when the `box` option changes, so that a new observation is fired if there was a previously observed element with a different box option.\n\t\t\t\tif (\n\t\t\t\t\t! resizeObserverRef.current ||\n\t\t\t\t\tresizeObserverRef.current.box !== opts.box ||\n\t\t\t\t\tresizeObserverRef.current.round !== round\n\t\t\t\t) {\n\t\t\t\t\tresizeObserverRef.current = {\n\t\t\t\t\t\tbox: opts.box,\n\t\t\t\t\t\tround,\n\t\t\t\t\t\tinstance: new ResizeObserver( ( entries ) => {\n\t\t\t\t\t\t\tconst entry = entries[ 0 ];\n\n\t\t\t\t\t\t\tlet boxProp:\n\t\t\t\t\t\t\t\t| 'borderBoxSize'\n\t\t\t\t\t\t\t\t| 'contentBoxSize'\n\t\t\t\t\t\t\t\t| 'devicePixelContentBoxSize' = 'borderBoxSize';\n\t\t\t\t\t\t\tif ( opts.box === 'border-box' ) {\n\t\t\t\t\t\t\t\tboxProp = 'borderBoxSize';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tboxProp =\n\t\t\t\t\t\t\t\t\topts.box === 'device-pixel-content-box'\n\t\t\t\t\t\t\t\t\t\t? 'devicePixelContentBoxSize'\n\t\t\t\t\t\t\t\t\t\t: 'contentBoxSize';\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst reportedWidth = extractSize(\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tboxProp,\n\t\t\t\t\t\t\t\t'inlineSize'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst reportedHeight = extractSize(\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tboxProp,\n\t\t\t\t\t\t\t\t'blockSize'\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst newWidth = reportedWidth\n\t\t\t\t\t\t\t\t? round( reportedWidth )\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\tconst newHeight = reportedHeight\n\t\t\t\t\t\t\t\t? round( reportedHeight )\n\t\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tprevious.current.width !== newWidth ||\n\t\t\t\t\t\t\t\tprevious.current.height !== newHeight\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tconst newSize = {\n\t\t\t\t\t\t\t\t\twidth: newWidth,\n\t\t\t\t\t\t\t\t\theight: newHeight,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tprevious.current.width = newWidth;\n\t\t\t\t\t\t\t\tprevious.current.height = newHeight;\n\t\t\t\t\t\t\t\tif ( onResizeRef.current ) {\n\t\t\t\t\t\t\t\t\tonResizeRef.current( newSize );\n\t\t\t\t\t\t\t\t} else if ( ! didUnmount.current ) {\n\t\t\t\t\t\t\t\t\tsetSize( newSize );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} ),\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tresizeObserverRef.current.instance.observe( element, {\n\t\t\t\t\tbox: opts.box,\n\t\t\t\t} );\n\n\t\t\t\treturn () => {\n\t\t\t\t\tif ( resizeObserverRef.current ) {\n\t\t\t\t\t\tresizeObserverRef.current.instance.unobserve( element );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ opts.box, round ]\n\t\t),\n\t\topts.ref\n\t);\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tref: refCallback,\n\t\t\twidth: size.width,\n\t\t\theight: size.height,\n\t\t} ),\n\t\t[ refCallback, size ? size.width : null, size ? size.height : null ]\n\t);\n}\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n * _Note: `useResizeObserver` will report `null` until after first render.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nexport default function useResizeAware(): [\n\tWPElement,\n\t{ width: number | null; height: number | null }\n] {\n\tconst { ref, width, height } = useResizeObserver();\n\tconst sizes = useMemo( () => {\n\t\treturn { width: width ?? null, height: height ?? null };\n\t}, [ width, height ] );\n\tconst resizeListener = (\n\t\t<div\n\t\t\tstyle={ {\n\t\t\t\tposition: 'absolute',\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\tright: 0,\n\t\t\t\tbottom: 0,\n\t\t\t\tpointerEvents: 'none',\n\t\t\t\topacity: 0,\n\t\t\t\toverflow: 'hidden',\n\t\t\t\tzIndex: -1,\n\t\t\t} }\n\t\t\taria-hidden=\"true\"\n\t\t\tref={ ref }\n\t\t/>\n\t);\n\treturn [ resizeListener, sizes ];\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.tsx"],"names":["useResolvedElement","subscriber","refOrElement","callbackRefElement","lastReportRef","cleanupRef","callSubscriber","element","current","HTMLElement","reporter","extractSize","entry","boxProp","sizeType","contentRect","undefined","useResizeObserver","opts","onResize","onResizeRef","round","Math","resizeObserverRef","size","setSize","width","height","didUnmount","previous","refCallback","box","instance","ResizeObserver","entries","reportedWidth","reportedHeight","newWidth","newHeight","newSize","observe","unobserve","ref","useResizeAware","sizes","resizeListener","position","top","left","right","bottom","pointerEvents","opacity","overflow","zIndex"],"mappings":";;;;;;;AAQA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAaA;AACA;AACA;AACA;AACA,SAASA,kBAAT,CACCC,UADD,EAECC,YAFD,EAGoB;AACnB,QAAMC,kBAAkB,GAAG,qBAAoB,IAApB,CAA3B;AACA,QAAMC,aAAa,GAAG,qBAGV,IAHU,CAAtB;AAIA,QAAMC,UAAU,GAAG,sBAAnB;AAEA,QAAMC,cAAc,GAAG,0BAAa,MAAM;AACzC,QAAIC,OAAO,GAAG,IAAd;;AACA,QAAKJ,kBAAkB,CAACK,OAAxB,EAAkC;AACjCD,MAAAA,OAAO,GAAGJ,kBAAkB,CAACK,OAA7B;AACA,KAFD,MAEO,IAAKN,YAAL,EAAoB;AAC1B,UAAKA,YAAY,YAAYO,WAA7B,EAA2C;AAC1CF,QAAAA,OAAO,GAAGL,YAAV;AACA,OAFD,MAEO;AACNK,QAAAA,OAAO,GAAGL,YAAY,CAACM,OAAvB;AACA;AACD;;AAED,QACCJ,aAAa,CAACI,OAAd,IACAJ,aAAa,CAACI,OAAd,CAAsBD,OAAtB,KAAkCA,OADlC,IAEAH,aAAa,CAACI,OAAd,CAAsBE,QAAtB,KAAmCJ,cAHpC,EAIE;AACD;AACA;;AAED,QAAKD,UAAU,CAACG,OAAhB,EAA0B;AACzBH,MAAAA,UAAU,CAACG,OA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EAEX,CAAED,KAAF,EAASC,MAAT,CAFW,CAAd;AAGA,QAAMkB,cAAc,GACnB;AACC,IAAA,KAAK,EAAG;AACPC,MAAAA,QAAQ,EAAE,UADH;AAEPC,MAAAA,GAAG,EAAE,CAFE;AAGPC,MAAAA,IAAI,EAAE,CAHC;AAIPC,MAAAA,KAAK,EAAE,CAJA;AAKPC,MAAAA,MAAM,EAAE,CALD;AAMPC,MAAAA,aAAa,EAAE,MANR;AAOPC,MAAAA,OAAO,EAAE,CAPF;AAQPC,MAAAA,QAAQ,EAAE,QARH;AASPC,MAAAA,MAAM,EAAE,CAAC;AATF,KADT;AAYC,mBAAY,MAZb;AAaC,IAAA,GAAG,EAAGZ;AAbP,IADD;AAiBA,SAAO,CAAEG,cAAF,EAAkBD,KAAlB,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback, RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseRef,\n\tuseCallback,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\nimport type { WPElement } from '@wordpress/element';\n\ntype SubscriberCleanup = () => void;\ntype SubscriberResponse = SubscriberCleanup | void;\n\n// This of course could've been more streamlined with internal state instead of\n// refs, but then host hooks / components could not opt out of renders.\n// This could've been exported to its own module, but the current build doesn't\n// seem to work with module imports and I had no more time to spend on this...\nfunction useResolvedElement< T extends HTMLElement >(\n\tsubscriber: ( element: T ) => SubscriberResponse,\n\trefOrElement?: T | RefObject< T > | null\n): RefCallback< T > {\n\tconst callbackRefElement = useRef< T | null >( null );\n\tconst lastReportRef = useRef< {\n\t\treporter: () => void;\n\t\telement: T | null;\n\t} | null >( null );\n\tconst cleanupRef = useRef< SubscriberResponse | null >();\n\n\tconst callSubscriber = useCallback( () => {\n\t\tlet element = null;\n\t\tif ( callbackRefElement.current ) {\n\t\t\telement = callbackRefElement.current;\n\t\t} else if ( refOrElement ) {\n\t\t\tif ( refOrElement instanceof HTMLElement ) {\n\t\t\t\telement = refOrElement;\n\t\t\t} else {\n\t\t\t\telement = refOrElement.current;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tlastReportRef.current &&\n\t\t\tlastReportRef.current.element === element &&\n\t\t\tlastReportRef.current.reporter === callSubscriber\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( cleanupRef.current ) {\n\t\t\tcleanupRef.current();\n\t\t\t// Making sure the cleanup is not called accidentally multiple times.\n\t\t\tcleanupRef.current = null;\n\t\t}\n\t\tlastReportRef.current = {\n\t\t\treporter: callSubscriber,\n\t\t\telement,\n\t\t};\n\n\t\t// Only calling the subscriber, if there's an actual element to report.\n\t\tif ( element ) {\n\t\t\tcleanupRef.current = subscriber( element );\n\t\t}\n\t}, [ refOrElement, subscriber ] );\n\n\t// On each render, we check whether a ref changed, or if we got a new raw\n\t// element.\n\tuseEffect( () => {\n\t\t// With this we're *technically* supporting cases where ref objects' current value changes, but only if there's a\n\t\t// render accompanying that change as well.\n\t\t// To guarantee we always have the right element, one must use the ref callback provided instead, but we support\n\t\t// RefObjects to make the hook API more convenient in certain cases.\n\t\tcallSubscriber();\n\t}, [ callSubscriber ] );\n\n\treturn useCallback< RefCallback< T > >(\n\t\t( element ) => {\n\t\t\tcallbackRefElement.current = element;\n\t\t\tcallSubscriber();\n\t\t},\n\t\t[ callSubscriber ]\n\t);\n}\n\ntype ObservedSize = {\n\twidth: number | undefined;\n\theight: number | undefined;\n};\n\ntype ResizeHandler = ( size: ObservedSize ) => void;\n\ntype HookResponse< T extends HTMLElement > = {\n\tref: RefCallback< T >;\n} & ObservedSize;\n\n// Declaring my own type here instead of using the one provided by TS (available since 4.2.2), because this way I'm not\n// forcing consumers to use a specific TS version.\ntype ResizeObserverBoxOptions =\n\t| 'border-box'\n\t| 'content-box'\n\t| 'device-pixel-content-box';\n\ndeclare global {\n\tinterface ResizeObserverEntry {\n\t\treadonly devicePixelContentBoxSize: ReadonlyArray< ResizeObserverSize >;\n\t}\n}\n\n// We're only using the first element of the size sequences, until future versions of the spec solidify on how\n// exactly it'll be used for fragments in multi-column scenarios:\n// From the spec:\n// > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,\n// > which occur in multi-column scenarios. However the current definitions of content rect and border box do not\n// > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single\n// > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.\n// > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)\n//\n// Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,\n// regardless of the \"box\" option.\n// The spec states the following on this:\n// > This does not have any impact on which box dimensions are returned to the defined callback when the event\n// > is fired, it solely defines which box the author wishes to observe layout changes on.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// I'm not exactly clear on what this means, especially when you consider a later section stating the following:\n// > This section is non-normative. An author may desire to observe more than one CSS box.\n// > In this case, author will need to use multiple ResizeObservers.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.\n// For this reason I decided to only return the requested size,\n// even though it seems we have access to results for all box types.\n// This also means that we get to keep the current api, being able to return a simple { width, height } pair,\n// regardless of box option.\nconst extractSize = (\n\tentry: ResizeObserverEntry,\n\tboxProp: 'borderBoxSize' | 'contentBoxSize' | 'devicePixelContentBoxSize',\n\tsizeType: keyof ResizeObserverSize\n): number | undefined => {\n\tif ( ! entry[ boxProp ] ) {\n\t\tif ( boxProp === 'contentBoxSize' ) {\n\t\t\t// The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.\n\t\t\t// See the 6th step in the description for the RO algorithm:\n\t\t\t// https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h\n\t\t\t// > Set this.contentRect to logical this.contentBoxSize given target and observedBox of \"content-box\".\n\t\t\t// In real browser implementations of course these objects differ, but the width/height values should be equivalent.\n\t\t\treturn entry.contentRect[\n\t\t\t\tsizeType === 'inlineSize' ? 'width' : 'height'\n\t\t\t];\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t// A couple bytes smaller than calling Array.isArray() and just as effective here.\n\treturn entry[ boxProp ][ 0 ]\n\t\t? entry[ boxProp ][ 0 ][ sizeType ]\n\t\t: // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's current\n\t\t // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.\n\t\t // @ts-ignore\n\t\t entry[ boxProp ][ sizeType ];\n};\n\ntype RoundingFunction = ( n: number ) => number;\n\nfunction useResizeObserver< T extends HTMLElement >(\n\topts: {\n\t\tref?: RefObject< T > | T | null | undefined;\n\t\tonResize?: ResizeHandler;\n\t\tbox?: ResizeObserverBoxOptions;\n\t\tround?: RoundingFunction;\n\t} = {}\n): HookResponse< T > {\n\t// Saving the callback as a ref. With this, I don't need to put onResize in the\n\t// effect dep array, and just passing in an anonymous function without memoising\n\t// will not reinstantiate the hook's ResizeObserver.\n\tconst onResize = opts.onResize;\n\tconst onResizeRef = useRef< ResizeHandler | undefined >( undefined );\n\tonResizeRef.current = onResize;\n\tconst round = opts.round || Math.round;\n\n\t// Using a single instance throughout the hook's lifetime\n\tconst resizeObserverRef = useRef< {\n\t\tbox?: ResizeObserverBoxOptions;\n\t\tround?: RoundingFunction;\n\t\tinstance: ResizeObserver;\n\t} >();\n\n\tconst [ size, setSize ] = useState< {\n\t\twidth?: number;\n\t\theight?: number;\n\t} >( {\n\t\twidth: undefined,\n\t\theight: undefined,\n\t} );\n\n\t// In certain edge cases the RO might want to report a size change just after\n\t// the component unmounted.\n\tconst didUnmount = useRef( false );\n\tuseEffect( () => {\n\t\tdidUnmount.current = false;\n\t\treturn () => {\n\t\t\tdidUnmount.current = true;\n\t\t};\n\t}, [] );\n\n\t// Using a ref to track the previous width / height to avoid unnecessary renders.\n\tconst previous: {\n\t\tcurrent: {\n\t\t\twidth?: number;\n\t\t\theight?: number;\n\t\t};\n\t} = useRef( {\n\t\twidth: undefined,\n\t\theight: undefined,\n\t} );\n\n\t// This block is kinda like a useEffect, only it's called whenever a new\n\t// element could be resolved based on the ref option. It also has a cleanup\n\t// function.\n\tconst refCallback = useResolvedElement< T >(\n\t\tuseCallback(\n\t\t\t( element ) => {\n\t\t\t\t// We only use a single Resize Observer instance, and we're instantiating it on demand, only once there's something to observe.\n\t\t\t\t// This instance is also recreated when the `box` option changes, so that a new observation is fired if there was a previously observed element with a different box option.\n\t\t\t\tif (\n\t\t\t\t\t! resizeObserverRef.current ||\n\t\t\t\t\tresizeObserverRef.current.box !== opts.box ||\n\t\t\t\t\tresizeObserverRef.current.round !== round\n\t\t\t\t) {\n\t\t\t\t\tresizeObserverRef.current = {\n\t\t\t\t\t\tbox: opts.box,\n\t\t\t\t\t\tround,\n\t\t\t\t\t\tinstance: new ResizeObserver( ( entries ) => {\n\t\t\t\t\t\t\tconst entry = entries[ 0 ];\n\n\t\t\t\t\t\t\tlet boxProp:\n\t\t\t\t\t\t\t\t| 'borderBoxSize'\n\t\t\t\t\t\t\t\t| 'contentBoxSize'\n\t\t\t\t\t\t\t\t| 'devicePixelContentBoxSize' = 'borderBoxSize';\n\t\t\t\t\t\t\tif ( opts.box === 'border-box' ) {\n\t\t\t\t\t\t\t\tboxProp = 'borderBoxSize';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tboxProp =\n\t\t\t\t\t\t\t\t\topts.box === 'device-pixel-content-box'\n\t\t\t\t\t\t\t\t\t\t? 'devicePixelContentBoxSize'\n\t\t\t\t\t\t\t\t\t\t: 'contentBoxSize';\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst reportedWidth = extractSize(\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tboxProp,\n\t\t\t\t\t\t\t\t'inlineSize'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst reportedHeight = extractSize(\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tboxProp,\n\t\t\t\t\t\t\t\t'blockSize'\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst newWidth = reportedWidth\n\t\t\t\t\t\t\t\t? round( reportedWidth )\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\tconst newHeight = reportedHeight\n\t\t\t\t\t\t\t\t? round( reportedHeight )\n\t\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tprevious.current.width !== newWidth ||\n\t\t\t\t\t\t\t\tprevious.current.height !== newHeight\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tconst newSize = {\n\t\t\t\t\t\t\t\t\twidth: newWidth,\n\t\t\t\t\t\t\t\t\theight: newHeight,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tprevious.current.width = newWidth;\n\t\t\t\t\t\t\t\tprevious.current.height = newHeight;\n\t\t\t\t\t\t\t\tif ( onResizeRef.current ) {\n\t\t\t\t\t\t\t\t\tonResizeRef.current( newSize );\n\t\t\t\t\t\t\t\t} else if ( ! didUnmount.current ) {\n\t\t\t\t\t\t\t\t\tsetSize( newSize );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} ),\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tresizeObserverRef.current.instance.observe( element, {\n\t\t\t\t\tbox: opts.box,\n\t\t\t\t} );\n\n\t\t\t\treturn () => {\n\t\t\t\t\tif ( resizeObserverRef.current ) {\n\t\t\t\t\t\tresizeObserverRef.current.instance.unobserve( element );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ opts.box, round ]\n\t\t),\n\t\topts.ref\n\t);\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tref: refCallback,\n\t\t\twidth: size.width,\n\t\t\theight: size.height,\n\t\t} ),\n\t\t[ refCallback, size ? size.width : null, size ? size.height : null ]\n\t);\n}\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n * _Note: `useResizeObserver` will report `null` until after first render.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nexport default function useResizeAware(): [\n\tWPElement,\n\t{ width: number | null; height: number | null }\n] {\n\tconst { ref, width, height } = useResizeObserver();\n\tconst sizes = useMemo( () => {\n\t\treturn { width: width ?? null, height: height ?? null };\n\t}, [ width, height ] );\n\tconst resizeListener = (\n\t\t<div\n\t\t\tstyle={ {\n\t\t\t\tposition: 'absolute',\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\tright: 0,\n\t\t\t\tbottom: 0,\n\t\t\t\tpointerEvents: 'none',\n\t\t\t\topacity: 0,\n\t\t\t\toverflow: 'hidden',\n\t\t\t\tzIndex: -1,\n\t\t\t} }\n\t\t\taria-hidden=\"true\"\n\t\t\tref={ ref }\n\t\t/>\n\t);\n\treturn [ resizeListener, sizes ];\n}\n"]}
@@ -38,10 +38,9 @@ var _reactNative = require("react-native");
38
38
  */
39
39
  const useResizeObserver = () => {
40
40
  const [measurements, setMeasurements] = (0, _element.useState)(null);
41
- const onLayout = (0, _element.useCallback)(_ref => {
42
- let {
43
- nativeEvent
44
- } = _ref;
41
+ const onLayout = (0, _element.useCallback)(({
42
+ nativeEvent
43
+ }) => {
45
44
  const {
46
45
  width,
47
46
  height
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"names":["useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","StyleSheet","absoluteFill"],"mappings":";;;;;;;AAOA;;AAJA;;AAHA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG,MAAM;AAC/B,QAAM,CAAEC,YAAF,EAAgBC,eAAhB,IAAoC,uBAAU,IAAV,CAA1C;AAEA,QAAMC,QAAQ,GAAG,0BAAa,QAAuB;AAAA,QAArB;AAAEC,MAAAA;AAAF,KAAqB;AACpD,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAoBF,WAAW,CAACG,MAAtC;AACAL,IAAAA,eAAe,CAAIM,SAAF,IAAiB;AACjC,UACC,CAAEA,SAAF,IACAA,SAAS,CAACH,KAAV,KAAoBA,KADpB,IAEAG,SAAS,CAACF,MAAV,KAAqBA,MAHtB,EAIE;AACD,eAAO;AACND,UAAAA,KAAK,EAAEI,IAAI,CAACC,KAAL,CAAYL,KAAZ,CADD;AAENC,UAAAA,MAAM,EAAEG,IAAI,CAACC,KAAL,CAAYJ,MAAZ;AAFF,SAAP;AAIA;;AACD,aAAOE,SAAP;AACA,KAZc,CAAf;AAaA,GAfgB,EAed,EAfc,CAAjB;AAiBA,QAAMG,QAAQ,GACb,4BAAC,iBAAD;AACC,IAAA,MAAM,EAAC,iBADR;AAEC,IAAA,KAAK,EAAGC,wBAAWC,YAFpB;AAGC,IAAA,QAAQ,EAAGV;AAHZ,IADD;AAQA,SAAO,CAAEQ,QAAF,EAAYV,YAAZ,CAAP;AACA,CA7BD;;eA+BeD,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { View, StyleSheet } from 'react-native';\n/**\n * WordPress dependencies\n */\nimport { useState, useCallback } from '@wordpress/element';\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<View>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</View>\n * \t);\n * };\n * ```\n *\n */\nconst useResizeObserver = () => {\n\tconst [ measurements, setMeasurements ] = useState( null );\n\n\tconst onLayout = useCallback( ( { nativeEvent } ) => {\n\t\tconst { width, height } = nativeEvent.layout;\n\t\tsetMeasurements( ( prevState ) => {\n\t\t\tif (\n\t\t\t\t! prevState ||\n\t\t\t\tprevState.width !== width ||\n\t\t\t\tprevState.height !== height\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\twidth: Math.floor( width ),\n\t\t\t\t\theight: Math.floor( height ),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn prevState;\n\t\t} );\n\t}, [] );\n\n\tconst observer = (\n\t\t<View\n\t\t\ttestID=\"resize-observer\"\n\t\t\tstyle={ StyleSheet.absoluteFill }\n\t\t\tonLayout={ onLayout }\n\t\t/>\n\t);\n\n\treturn [ observer, measurements ];\n};\n\nexport default useResizeObserver;\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"names":["useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","StyleSheet","absoluteFill"],"mappings":";;;;;;;AAOA;;AAJA;;AAHA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG,MAAM;AAC/B,QAAM,CAAEC,YAAF,EAAgBC,eAAhB,IAAoC,uBAAU,IAAV,CAA1C;AAEA,QAAMC,QAAQ,GAAG,0BAAa,CAAE;AAAEC,IAAAA;AAAF,GAAF,KAAuB;AACpD,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAoBF,WAAW,CAACG,MAAtC;AACAL,IAAAA,eAAe,CAAIM,SAAF,IAAiB;AACjC,UACC,CAAEA,SAAF,IACAA,SAAS,CAACH,KAAV,KAAoBA,KADpB,IAEAG,SAAS,CAACF,MAAV,KAAqBA,MAHtB,EAIE;AACD,eAAO;AACND,UAAAA,KAAK,EAAEI,IAAI,CAACC,KAAL,CAAYL,KAAZ,CADD;AAENC,UAAAA,MAAM,EAAEG,IAAI,CAACC,KAAL,CAAYJ,MAAZ;AAFF,SAAP;AAIA;;AACD,aAAOE,SAAP;AACA,KAZc,CAAf;AAaA,GAfgB,EAed,EAfc,CAAjB;AAiBA,QAAMG,QAAQ,GACb,4BAAC,iBAAD;AACC,IAAA,MAAM,EAAC,iBADR;AAEC,IAAA,KAAK,EAAGC,wBAAWC,YAFpB;AAGC,IAAA,QAAQ,EAAGV;AAHZ,IADD;AAQA,SAAO,CAAEQ,QAAF,EAAYV,YAAZ,CAAP;AACA,CA7BD;;eA+BeD,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { View, StyleSheet } from 'react-native';\n/**\n * WordPress dependencies\n */\nimport { useState, useCallback } from '@wordpress/element';\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<View>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</View>\n * \t);\n * };\n * ```\n *\n */\nconst useResizeObserver = () => {\n\tconst [ measurements, setMeasurements ] = useState( null );\n\n\tconst onLayout = useCallback( ( { nativeEvent } ) => {\n\t\tconst { width, height } = nativeEvent.layout;\n\t\tsetMeasurements( ( prevState ) => {\n\t\t\tif (\n\t\t\t\t! prevState ||\n\t\t\t\tprevState.width !== width ||\n\t\t\t\tprevState.height !== height\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\twidth: Math.floor( width ),\n\t\t\t\t\theight: Math.floor( height ),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn prevState;\n\t\t} );\n\t}, [] );\n\n\tconst observer = (\n\t\t<View\n\t\t\ttestID=\"resize-observer\"\n\t\t\tstyle={ StyleSheet.absoluteFill }\n\t\t\tonLayout={ onLayout }\n\t\t/>\n\t);\n\n\treturn [ observer, measurements ];\n};\n\nexport default useResizeObserver;\n"]}