@react-aria/test-utils 1.0.0-beta.1 → 1.0.0-beta.3

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 (133) hide show
  1. package/dist/import.mjs +5 -5
  2. package/dist/main.js +9 -9
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +5 -5
  5. package/dist/module.js.map +1 -1
  6. package/dist/private/checkboxgroup.cjs +104 -0
  7. package/dist/private/checkboxgroup.cjs.map +1 -0
  8. package/dist/private/checkboxgroup.js +99 -0
  9. package/dist/private/checkboxgroup.js.map +1 -0
  10. package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
  11. package/dist/private/combobox.cjs.map +1 -0
  12. package/dist/{combobox.mjs → private/combobox.js} +35 -35
  13. package/dist/private/combobox.js.map +1 -0
  14. package/dist/private/dialog.cjs +105 -0
  15. package/dist/private/dialog.cjs.map +1 -0
  16. package/dist/private/dialog.js +100 -0
  17. package/dist/private/dialog.js.map +1 -0
  18. package/dist/{events.main.js → private/events.cjs} +32 -34
  19. package/dist/private/events.cjs.map +1 -0
  20. package/dist/{events.mjs → private/events.js} +29 -31
  21. package/dist/private/events.js.map +1 -0
  22. package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
  23. package/dist/private/gridlist.cjs.map +1 -0
  24. package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
  25. package/dist/private/gridlist.js.map +1 -0
  26. package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
  27. package/dist/private/listbox.cjs.map +1 -0
  28. package/dist/{listbox.mjs → private/listbox.js} +24 -24
  29. package/dist/private/listbox.js.map +1 -0
  30. package/dist/{menu.main.js → private/menu.cjs} +46 -48
  31. package/dist/private/menu.cjs.map +1 -0
  32. package/dist/{menu.mjs → private/menu.js} +46 -48
  33. package/dist/private/menu.js.map +1 -0
  34. package/dist/private/radiogroup.cjs +120 -0
  35. package/dist/private/radiogroup.cjs.map +1 -0
  36. package/dist/private/radiogroup.js +115 -0
  37. package/dist/private/radiogroup.js.map +1 -0
  38. package/dist/{select.main.js → private/select.cjs} +31 -29
  39. package/dist/private/select.cjs.map +1 -0
  40. package/dist/{select.mjs → private/select.js} +31 -29
  41. package/dist/private/select.js.map +1 -0
  42. package/dist/{table.main.js → private/table.cjs} +82 -57
  43. package/dist/private/table.cjs.map +1 -0
  44. package/dist/{table.module.js → private/table.js} +82 -57
  45. package/dist/private/table.js.map +1 -0
  46. package/dist/{tabs.main.js → private/tabs.cjs} +24 -26
  47. package/dist/private/tabs.cjs.map +1 -0
  48. package/dist/{tabs.mjs → private/tabs.js} +24 -26
  49. package/dist/private/tabs.js.map +1 -0
  50. package/dist/private/testSetup.cjs +87 -0
  51. package/dist/private/testSetup.cjs.map +1 -0
  52. package/dist/private/testSetup.js +81 -0
  53. package/dist/private/testSetup.js.map +1 -0
  54. package/dist/{tree.main.js → private/tree.cjs} +34 -35
  55. package/dist/private/tree.cjs.map +1 -0
  56. package/dist/{tree.mjs → private/tree.js} +34 -35
  57. package/dist/private/tree.js.map +1 -0
  58. package/dist/private/user.cjs +85 -0
  59. package/dist/private/user.cjs.map +1 -0
  60. package/dist/private/user.js +76 -0
  61. package/dist/private/user.js.map +1 -0
  62. package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
  63. package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
  64. package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
  65. package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
  66. package/dist/types/src/checkboxgroup.d.ts +45 -0
  67. package/dist/types/src/combobox.d.ts +75 -0
  68. package/dist/types/src/dialog.d.ts +36 -0
  69. package/dist/types/src/events.d.ts +25 -0
  70. package/dist/types/src/gridlist.d.ts +51 -0
  71. package/dist/types/src/index.d.ts +16 -0
  72. package/dist/types/src/listbox.d.ts +80 -0
  73. package/dist/types/src/menu.d.ts +102 -0
  74. package/dist/types/src/radiogroup.d.ts +46 -0
  75. package/dist/types/src/select.d.ts +67 -0
  76. package/dist/types/src/table.d.ts +104 -0
  77. package/dist/types/src/tabs.d.ts +58 -0
  78. package/dist/types/src/testSetup.d.ts +6 -0
  79. package/dist/types/src/tree.d.ts +57 -0
  80. package/dist/types/src/types.d.ts +136 -0
  81. package/dist/types/src/user.d.ts +47 -0
  82. package/dist/types/src/userEventMaps.d.ts +2 -0
  83. package/package.json +7 -7
  84. package/src/checkboxgroup.ts +158 -0
  85. package/src/dialog.ts +143 -0
  86. package/src/index.ts +11 -0
  87. package/src/radiogroup.ts +176 -0
  88. package/src/select.ts +10 -2
  89. package/src/table.ts +46 -1
  90. package/src/tabs.ts +7 -2
  91. package/src/testSetup.ts +30 -28
  92. package/src/types.ts +21 -0
  93. package/src/user.ts +25 -7
  94. package/dist/combobox.main.js.map +0 -1
  95. package/dist/combobox.module.js +0 -167
  96. package/dist/combobox.module.js.map +0 -1
  97. package/dist/events.main.js.map +0 -1
  98. package/dist/events.module.js +0 -112
  99. package/dist/events.module.js.map +0 -1
  100. package/dist/gridlist.main.js.map +0 -1
  101. package/dist/gridlist.module.js +0 -149
  102. package/dist/gridlist.module.js.map +0 -1
  103. package/dist/listbox.main.js.map +0 -1
  104. package/dist/listbox.module.js +0 -138
  105. package/dist/listbox.module.js.map +0 -1
  106. package/dist/menu.main.js.map +0 -1
  107. package/dist/menu.module.js +0 -269
  108. package/dist/menu.module.js.map +0 -1
  109. package/dist/select.main.js.map +0 -1
  110. package/dist/select.module.js +0 -158
  111. package/dist/select.module.js.map +0 -1
  112. package/dist/table.main.js.map +0 -1
  113. package/dist/table.mjs +0 -290
  114. package/dist/table.module.js.map +0 -1
  115. package/dist/tabs.main.js.map +0 -1
  116. package/dist/tabs.module.js +0 -128
  117. package/dist/tabs.module.js.map +0 -1
  118. package/dist/testSetup.main.js +0 -78
  119. package/dist/testSetup.main.js.map +0 -1
  120. package/dist/testSetup.mjs +0 -72
  121. package/dist/testSetup.module.js +0 -72
  122. package/dist/testSetup.module.js.map +0 -1
  123. package/dist/tree.main.js.map +0 -1
  124. package/dist/tree.module.js +0 -179
  125. package/dist/tree.module.js.map +0 -1
  126. package/dist/types.d.ts +0 -694
  127. package/dist/types.d.ts.map +0 -1
  128. package/dist/user.main.js +0 -76
  129. package/dist/user.main.js.map +0 -1
  130. package/dist/user.mjs +0 -67
  131. package/dist/user.module.js +0 -67
  132. package/dist/user.module.js.map +0 -1
  133. package/dist/userEventMaps.module.js +0 -38
@@ -1,4 +1,4 @@
1
- import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library/react";
1
+ import {fireEvent as $bWe3B$fireEvent, act as $bWe3B$act} from "@testing-library/react";
2
2
 
3
3
  /*
4
4
  * Copyright 2023 Adobe. All rights reserved.
@@ -11,12 +11,11 @@ import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library
11
11
  * OF ANY KIND, either express or implied. See the License for the specific language
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
- const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
- function $5d1eca18f92ad0e6$var$testPlatform(re) {
16
- var _window_navigator_userAgentData;
17
- return typeof window !== 'undefined' && window.navigator != null ? re.test(((_window_navigator_userAgentData = window.navigator['userAgentData']) === null || _window_navigator_userAgentData === void 0 ? void 0 : _window_navigator_userAgentData.platform) || window.navigator.platform) : false;
14
+ const $22d7d9b763402afa$export$4bd1d2d5ba6f5eaf = 500;
15
+ function $22d7d9b763402afa$var$testPlatform(re) {
16
+ return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform) : false;
18
17
  }
19
- function $5d1eca18f92ad0e6$var$cached(fn) {
18
+ function $22d7d9b763402afa$var$cached(fn) {
20
19
  if (process.env.NODE_ENV === 'test') return fn;
21
20
  let res = null;
22
21
  return ()=>{
@@ -24,29 +23,28 @@ function $5d1eca18f92ad0e6$var$cached(fn) {
24
23
  return res;
25
24
  };
26
25
  }
27
- const $5d1eca18f92ad0e6$var$isMac = $5d1eca18f92ad0e6$var$cached(function() {
28
- return $5d1eca18f92ad0e6$var$testPlatform(/^Mac/i);
26
+ const $22d7d9b763402afa$var$isMac = $22d7d9b763402afa$var$cached(function() {
27
+ return $22d7d9b763402afa$var$testPlatform(/^Mac/i);
29
28
  });
30
- function $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d() {
31
- return $5d1eca18f92ad0e6$var$isMac() ? 'Alt' : 'ControlLeft';
29
+ function $22d7d9b763402afa$export$6fc0ccaebd758b9d() {
30
+ return $22d7d9b763402afa$var$isMac() ? 'Alt' : 'ControlLeft';
32
31
  }
33
- function $5d1eca18f92ad0e6$export$7943c508934e27ce() {
34
- return $5d1eca18f92ad0e6$var$isMac() ? 'MetaLeft' : 'ControlLeft';
32
+ function $22d7d9b763402afa$export$7943c508934e27ce() {
33
+ return $22d7d9b763402afa$var$isMac() ? 'MetaLeft' : 'ControlLeft';
35
34
  }
36
- async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
35
+ async function $22d7d9b763402afa$export$3a22a5a9bc0fd3b(opts) {
37
36
  // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
38
37
  // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
39
38
  // util before first render. Will need to document it well
40
39
  let { element: element, advanceTimer: advanceTimer, pointerOpts: pointerOpts = {} } = opts;
41
- var _pointerOpts_pointerType;
42
- let pointerType = (_pointerOpts_pointerType = pointerOpts.pointerType) !== null && _pointerOpts_pointerType !== void 0 ? _pointerOpts_pointerType : 'mouse';
43
- let shouldFireCompatibilityEvents = (0, $hhVmT$fireEvent).pointerDown(element, {
40
+ let pointerType = pointerOpts.pointerType ?? 'mouse';
41
+ let shouldFireCompatibilityEvents = (0, $bWe3B$fireEvent).pointerDown(element, {
44
42
  pointerType: pointerType,
45
43
  ...pointerOpts
46
44
  });
47
45
  let shouldFocus = true;
48
46
  if (shouldFireCompatibilityEvents) {
49
- if (pointerType === 'touch') shouldFocus = shouldFireCompatibilityEvents = (0, $hhVmT$fireEvent).touchStart(element, {
47
+ if (pointerType === 'touch') shouldFocus = shouldFireCompatibilityEvents = (0, $bWe3B$fireEvent).touchStart(element, {
50
48
  targetTouches: [
51
49
  {
52
50
  identifier: pointerOpts.pointerId,
@@ -56,18 +54,18 @@ async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
56
54
  ]
57
55
  });
58
56
  else if (pointerType === 'mouse') {
59
- shouldFocus = (0, $hhVmT$fireEvent).mouseDown(element, pointerOpts);
60
- if (shouldFocus) (0, $hhVmT$act)(()=>element.focus());
57
+ shouldFocus = (0, $bWe3B$fireEvent).mouseDown(element, pointerOpts);
58
+ if (shouldFocus) (0, $bWe3B$act)(()=>element.focus());
61
59
  }
62
60
  }
63
- await (0, $hhVmT$act)(async ()=>await advanceTimer($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf));
64
- (0, $hhVmT$fireEvent).pointerUp(element, {
61
+ await (0, $bWe3B$act)(async ()=>await advanceTimer($22d7d9b763402afa$export$4bd1d2d5ba6f5eaf));
62
+ (0, $bWe3B$fireEvent).pointerUp(element, {
65
63
  pointerType: pointerType,
66
64
  ...pointerOpts
67
65
  });
68
66
  if (shouldFireCompatibilityEvents) {
69
67
  if (pointerType === 'touch') {
70
- shouldFocus = (0, $hhVmT$fireEvent).touchEnd(element, {
68
+ shouldFocus = (0, $bWe3B$fireEvent).touchEnd(element, {
71
69
  targetTouches: [
72
70
  {
73
71
  identifier: pointerOpts.pointerId,
@@ -76,17 +74,17 @@ async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
76
74
  }
77
75
  ]
78
76
  });
79
- shouldFocus = (0, $hhVmT$fireEvent).mouseDown(element, pointerOpts);
80
- if (shouldFocus) (0, $hhVmT$act)(()=>element.focus());
81
- (0, $hhVmT$fireEvent).mouseUp(element, pointerOpts);
82
- } else if (pointerType === 'mouse') (0, $hhVmT$fireEvent).mouseUp(element, pointerOpts);
77
+ shouldFocus = (0, $bWe3B$fireEvent).mouseDown(element, pointerOpts);
78
+ if (shouldFocus) (0, $bWe3B$act)(()=>element.focus());
79
+ (0, $bWe3B$fireEvent).mouseUp(element, pointerOpts);
80
+ } else if (pointerType === 'mouse') (0, $bWe3B$fireEvent).mouseUp(element, pointerOpts);
83
81
  }
84
- (0, $hhVmT$fireEvent).click(element, {
82
+ (0, $bWe3B$fireEvent).click(element, {
85
83
  detail: 1,
86
84
  ...pointerOpts
87
85
  });
88
86
  }
89
- async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interactionType) {
87
+ async function $22d7d9b763402afa$export$6ffa3eb717517feb(user, element, interactionType) {
90
88
  if (interactionType === 'mouse') // Add coords with pressure so this isn't detected as a virtual click
91
89
  await user.pointer({
92
90
  target: element,
@@ -99,7 +97,7 @@ async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interact
99
97
  // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
100
98
  // stick to simulting an actual user's keyboard operations as closely as possible
101
99
  // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.
102
- (0, $hhVmT$act)(()=>element.focus());
100
+ (0, $bWe3B$act)(()=>element.focus());
103
101
  await user.keyboard('[Space]');
104
102
  } else if (interactionType === 'touch') await user.pointer({
105
103
  target: element,
@@ -108,5 +106,5 @@ async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interact
108
106
  }
109
107
 
110
108
 
111
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d as getAltKey, $5d1eca18f92ad0e6$export$7943c508934e27ce as getMetaKey, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
112
- //# sourceMappingURL=events.module.js.map
109
+ export {$22d7d9b763402afa$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $22d7d9b763402afa$export$6fc0ccaebd758b9d as getAltKey, $22d7d9b763402afa$export$7943c508934e27ce as getMetaKey, $22d7d9b763402afa$export$3a22a5a9bc0fd3b as triggerLongPress, $22d7d9b763402afa$export$6ffa3eb717517feb as pressElement};
110
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AACvC,SAAS,mCAAa,EAAU;IAC9B,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS,IAAI,OACxD,GAAG,IAAI,CAAC,OAAO,SAAS,CAAC,gBAAgB,EAAE,YAAY,OAAO,SAAS,CAAC,QAAQ,IAChF;AACN;AAEA,SAAS,6BAAO,EAAiB;IAC/B,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAC3B,OAAO;IAGT,IAAI,MAAsB;IAC1B,OAAO;QACL,IAAI,OAAO,MACT,MAAM;QAER,OAAO;IACT;AACF;AAEA,MAAM,8BAAQ,6BAAO;IACnB,OAAO,mCAAa;AACtB;AAEO,SAAS;IACd,OAAO,gCAAU,QAAQ;AAC3B;AAEO,SAAS;IACd,OAAO,gCAAU,aAAa;AAChC;AASO,eAAe,yCAAiB,IAA2H;IAChK,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,IAAI,cAAc,YAAY,WAAW,IAAI;IAC7C,IAAI,gCAAgC,CAAA,GAAA,gBAAQ,EAAE,WAAW,CAAC,SAAS;qBAAC;QAAa,GAAG,WAAW;IAAA;IAC/F,IAAI,cAAc;IAClB,IAAI,+BAA+B;QACjC,IAAI,gBAAgB,SAClB,cAAc,gCAAgC,CAAA,GAAA,gBAAQ,EAAE,UAAU,CAAC,SAAS;YAAC,eAAe;gBAAC;oBAAC,YAA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M,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\nfunction testPlatform(re: RegExp) {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === 'test') {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(function () {\n return testPlatform(/^Mac/i);\n});\n\nexport function getAltKey(): 'Alt' | 'ControlLeft' {\n return isMac() ? 'Alt' : 'ControlLeft';\n}\n\nexport function getMetaKey(): 'MetaLeft' | 'ControlLeft' {\n return isMac() ? 'MetaLeft' : 'ControlLeft';\n}\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string, coords?: any}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n // Add coords with pressure so this isn't detected as a virtual click\n await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: .5}});\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.js.map"}
@@ -1,12 +1,12 @@
1
- var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
- var $cgwRb$testinglibraryreact = require("@testing-library/react");
1
+ var $01a4eeee86094c77$exports = require("./events.cjs");
2
+ var $aoGu7$testinglibraryreact = require("@testing-library/react");
3
3
 
4
4
 
5
5
  function $parcel$export(e, n, v, s) {
6
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
7
  }
8
8
 
9
- $parcel$export(module.exports, "GridListTester", () => $30ee8e379774bea4$export$93a85aaed9fabd83);
9
+ $parcel$export(module.exports, "GridListTester", function () { return $31bb3cd1e8c56ca2$export$93a85aaed9fabd83; });
10
10
  /*
11
11
  * Copyright 2024 Adobe. All rights reserved.
12
12
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,14 @@ $parcel$export(module.exports, "GridListTester", () => $30ee8e379774bea4$export$
19
19
  * governing permissions and limitations under the License.
20
20
  */
21
21
 
22
- class $30ee8e379774bea4$export$93a85aaed9fabd83 {
22
+ class $31bb3cd1e8c56ca2$export$93a85aaed9fabd83 {
23
+ constructor(opts){
24
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
25
+ this.user = user;
26
+ this._interactionType = interactionType || 'mouse';
27
+ this._advanceTimer = advanceTimer;
28
+ this._gridlist = root;
29
+ }
23
30
  /**
24
31
  * Set the interaction type used by the gridlist tester.
25
32
  */ setInteractionType(type) {
@@ -31,17 +38,17 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
31
38
  let { rowIndexOrText: rowIndexOrText } = opts;
32
39
  let row;
33
40
  if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
34
- else if (typeof rowIndexOrText === 'string') row = (0, $cgwRb$testinglibraryreact.within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
41
+ else if (typeof rowIndexOrText === 'string') row = (0, $aoGu7$testinglibraryreact.within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
35
42
  return row;
36
43
  }
37
44
  // TODO: RTL
38
45
  async keyboardNavigateToRow(opts) {
39
46
  let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
40
- let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
47
+ let altKey = (0, $01a4eeee86094c77$exports.getAltKey)();
41
48
  let rows = this.rows;
42
49
  let targetIndex = rows.indexOf(row);
43
50
  if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
44
- if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $cgwRb$testinglibraryreact.act)(()=>this._gridlist.focus());
51
+ if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $aoGu7$testinglibraryreact.act)(()=>this._gridlist.focus());
45
52
  if (document.activeElement === this._gridlist) await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
46
53
  else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
47
54
  while (document.activeElement.getAttribute('role') !== 'row');
@@ -57,16 +64,16 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
57
64
  * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.
58
65
  */ async toggleRowSelection(opts) {
59
66
  let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
60
- let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
61
- let metaKey = (0, $5a8bfe1663b8366d$exports.getMetaKey)();
67
+ let altKey = (0, $01a4eeee86094c77$exports.getAltKey)();
68
+ let metaKey = (0, $01a4eeee86094c77$exports.getMetaKey)();
62
69
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
63
70
  rowIndexOrText: row
64
71
  });
65
72
  if (!row) throw new Error('Target row not found in the gridlist.');
66
- let rowCheckbox = (0, $cgwRb$testinglibraryreact.within)(row).queryByRole('checkbox');
73
+ let rowCheckbox = (0, $aoGu7$testinglibraryreact.within)(row).queryByRole('checkbox');
67
74
  // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually
68
75
  // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
69
- if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
76
+ if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) return;
70
77
  // this would be better than the check to do nothing in events.ts
71
78
  // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
72
79
  if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
@@ -79,13 +86,13 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
79
86
  if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
80
87
  return;
81
88
  }
82
- if (rowCheckbox && checkboxSelection) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
89
+ if (rowCheckbox && checkboxSelection) await (0, $01a4eeee86094c77$exports.pressElement)(this.user, rowCheckbox, interactionType);
83
90
  else {
84
- let cell = (0, $cgwRb$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
91
+ let cell = (0, $aoGu7$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
85
92
  if (needsLongPress && interactionType === 'touch') {
86
93
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
87
94
  // Note that long press interactions with rows is strictly touch only for grid rows
88
- await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
95
+ await (0, $01a4eeee86094c77$exports.triggerLongPress)({
89
96
  element: cell,
90
97
  advanceTimer: this._advanceTimer,
91
98
  pointerOpts: {
@@ -94,7 +101,7 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
94
101
  });
95
102
  } else {
96
103
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
97
- await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
104
+ await (0, $01a4eeee86094c77$exports.pressElement)(this.user, row, interactionType);
98
105
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
99
106
  }
100
107
  }
@@ -111,13 +118,13 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
111
118
  if (!row) throw new Error('Target row not found in the gridlist.');
112
119
  if (needsDoubleClick) await this.user.dblClick(row);
113
120
  else if (interactionType === 'keyboard') {
114
- if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
121
+ if (row?.getAttribute('aria-disabled') === 'true') return;
115
122
  await this.keyboardNavigateToRow({
116
123
  row: row,
117
124
  selectionOnNav: 'none'
118
125
  });
119
126
  await this.user.keyboard('[Enter]');
120
- } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
127
+ } else await (0, $01a4eeee86094c77$exports.pressElement)(this.user, row, interactionType);
121
128
  }
122
129
  /**
123
130
  * Returns the gridlist.
@@ -127,8 +134,7 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
127
134
  /**
128
135
  * Returns the gridlist's rows if any.
129
136
  */ get rows() {
130
- var _this;
131
- return (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
137
+ return (0, $aoGu7$testinglibraryreact.within)(this?.gridlist).queryAllByRole('row');
132
138
  }
133
139
  /**
134
140
  * Returns the gridlist's selected rows if any.
@@ -139,16 +145,9 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
139
145
  * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.
140
146
  */ cells(opts = {}) {
141
147
  let { element: element = this.gridlist } = opts;
142
- return (0, $cgwRb$testinglibraryreact.within)(element).queryAllByRole('gridcell');
143
- }
144
- constructor(opts){
145
- let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
146
- this.user = user;
147
- this._interactionType = interactionType || 'mouse';
148
- this._advanceTimer = advanceTimer;
149
- this._gridlist = root;
148
+ return (0, $aoGu7$testinglibraryreact.within)(element).queryAllByRole('gridcell');
150
149
  }
151
150
  }
152
151
 
153
152
 
154
- //# sourceMappingURL=gridlist.main.js.map
153
+ //# sourceMappingURL=gridlist.cjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAMX,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe;aAC1B,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,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I,CAAC,qBAAqB,CAAC;qBAAC;gBAAK,gBAAgB;YAAM;YAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;IAEvC;IAEA;;GAEC,GACD,IAAI,WAAwB;QAC1B,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA;;GAEC,GACD,IAAI,OAAsB;QACxB,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,EAAE,UAAU,cAAc,CAAC;IAC/C;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,EAAC,GAAG;QAChC,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;AACF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n\n if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getAltKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, row, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.cjs.map"}
@@ -1,5 +1,5 @@
1
- import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
2
- import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
1
+ import {getAltKey as $22d7d9b763402afa$export$6fc0ccaebd758b9d, getMetaKey as $22d7d9b763402afa$export$7943c508934e27ce, pressElement as $22d7d9b763402afa$export$6ffa3eb717517feb, triggerLongPress as $22d7d9b763402afa$export$3a22a5a9bc0fd3b} from "./events.js";
2
+ import {within as $g8PMJ$within, act as $g8PMJ$act} from "@testing-library/react";
3
3
 
4
4
  /*
5
5
  * Copyright 2024 Adobe. All rights reserved.
@@ -13,7 +13,14 @@ import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react
13
13
  * governing permissions and limitations under the License.
14
14
  */
15
15
 
16
- class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
16
+ class $ed42840525c46506$export$93a85aaed9fabd83 {
17
+ constructor(opts){
18
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
19
+ this.user = user;
20
+ this._interactionType = interactionType || 'mouse';
21
+ this._advanceTimer = advanceTimer;
22
+ this._gridlist = root;
23
+ }
17
24
  /**
18
25
  * Set the interaction type used by the gridlist tester.
19
26
  */ setInteractionType(type) {
@@ -25,17 +32,17 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
25
32
  let { rowIndexOrText: rowIndexOrText } = opts;
26
33
  let row;
27
34
  if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
28
- else if (typeof rowIndexOrText === 'string') row = (0, $haOzD$within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
35
+ else if (typeof rowIndexOrText === 'string') row = (0, $g8PMJ$within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
29
36
  return row;
30
37
  }
31
38
  // TODO: RTL
32
39
  async keyboardNavigateToRow(opts) {
33
40
  let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
34
- let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
41
+ let altKey = (0, $22d7d9b763402afa$export$6fc0ccaebd758b9d)();
35
42
  let rows = this.rows;
36
43
  let targetIndex = rows.indexOf(row);
37
44
  if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
38
- if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
45
+ if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $g8PMJ$act)(()=>this._gridlist.focus());
39
46
  if (document.activeElement === this._gridlist) await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
40
47
  else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
41
48
  while (document.activeElement.getAttribute('role') !== 'row');
@@ -51,16 +58,16 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
51
58
  * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.
52
59
  */ async toggleRowSelection(opts) {
53
60
  let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
54
- let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
55
- let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
61
+ let altKey = (0, $22d7d9b763402afa$export$6fc0ccaebd758b9d)();
62
+ let metaKey = (0, $22d7d9b763402afa$export$7943c508934e27ce)();
56
63
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
57
64
  rowIndexOrText: row
58
65
  });
59
66
  if (!row) throw new Error('Target row not found in the gridlist.');
60
- let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
67
+ let rowCheckbox = (0, $g8PMJ$within)(row).queryByRole('checkbox');
61
68
  // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually
62
69
  // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
63
- if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
70
+ if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) return;
64
71
  // this would be better than the check to do nothing in events.ts
65
72
  // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
66
73
  if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
@@ -73,13 +80,13 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
73
80
  if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
74
81
  return;
75
82
  }
76
- if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
83
+ if (rowCheckbox && checkboxSelection) await (0, $22d7d9b763402afa$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
77
84
  else {
78
- let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
85
+ let cell = (0, $g8PMJ$within)(row).getAllByRole('gridcell')[0];
79
86
  if (needsLongPress && interactionType === 'touch') {
80
87
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
81
88
  // Note that long press interactions with rows is strictly touch only for grid rows
82
- await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
89
+ await (0, $22d7d9b763402afa$export$3a22a5a9bc0fd3b)({
83
90
  element: cell,
84
91
  advanceTimer: this._advanceTimer,
85
92
  pointerOpts: {
@@ -88,7 +95,7 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
88
95
  });
89
96
  } else {
90
97
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
91
- await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
98
+ await (0, $22d7d9b763402afa$export$6ffa3eb717517feb)(this.user, row, interactionType);
92
99
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
93
100
  }
94
101
  }
@@ -105,13 +112,13 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
105
112
  if (!row) throw new Error('Target row not found in the gridlist.');
106
113
  if (needsDoubleClick) await this.user.dblClick(row);
107
114
  else if (interactionType === 'keyboard') {
108
- if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
115
+ if (row?.getAttribute('aria-disabled') === 'true') return;
109
116
  await this.keyboardNavigateToRow({
110
117
  row: row,
111
118
  selectionOnNav: 'none'
112
119
  });
113
120
  await this.user.keyboard('[Enter]');
114
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
121
+ } else await (0, $22d7d9b763402afa$export$6ffa3eb717517feb)(this.user, row, interactionType);
115
122
  }
116
123
  /**
117
124
  * Returns the gridlist.
@@ -121,8 +128,7 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
121
128
  /**
122
129
  * Returns the gridlist's rows if any.
123
130
  */ get rows() {
124
- var _this;
125
- return (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
131
+ return (0, $g8PMJ$within)(this?.gridlist).queryAllByRole('row');
126
132
  }
127
133
  /**
128
134
  * Returns the gridlist's selected rows if any.
@@ -133,17 +139,10 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
133
139
  * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.
134
140
  */ cells(opts = {}) {
135
141
  let { element: element = this.gridlist } = opts;
136
- return (0, $haOzD$within)(element).queryAllByRole('gridcell');
137
- }
138
- constructor(opts){
139
- let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
140
- this.user = user;
141
- this._interactionType = interactionType || 'mouse';
142
- this._advanceTimer = advanceTimer;
143
- this._gridlist = root;
142
+ return (0, $g8PMJ$within)(element).queryAllByRole('gridcell');
144
143
  }
145
144
  }
146
145
 
147
146
 
148
- export {$5ca9e9228f508f75$export$93a85aaed9fabd83 as GridListTester};
149
- //# sourceMappingURL=gridlist.module.js.map
147
+ export {$ed42840525c46506$export$93a85aaed9fabd83 as GridListTester};
148
+ //# sourceMappingURL=gridlist.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAMX,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe;aAC1B,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,QAAQ,EAAG,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGlE,OAAO;IACT;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,yCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAA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I,OAAsB;QACxB,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,EAAE,UAAU,cAAc,CAAC;IAC/C;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,EAAC,GAAG;QAChC,OAAO,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;IACxC;AACF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n\n if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getAltKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, row, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.js.map"}