@react-spectrum/card 3.0.0-alpha.9 → 3.0.0-nightly-4980928d3-240906

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 (239) hide show
  1. package/dist/BaseLayout.main.js +213 -0
  2. package/dist/BaseLayout.main.js.map +1 -0
  3. package/dist/BaseLayout.mjs +208 -0
  4. package/dist/BaseLayout.module.js +208 -0
  5. package/dist/BaseLayout.module.js.map +1 -0
  6. package/dist/Card.main.js +51 -0
  7. package/dist/Card.main.js.map +1 -0
  8. package/dist/Card.mjs +42 -0
  9. package/dist/Card.module.js +42 -0
  10. package/dist/Card.module.js.map +1 -0
  11. package/dist/CardBase.main.js +205 -0
  12. package/dist/CardBase.main.js.map +1 -0
  13. package/dist/CardBase.mjs +200 -0
  14. package/dist/CardBase.module.js +200 -0
  15. package/dist/CardBase.module.js.map +1 -0
  16. package/dist/CardView.main.js +240 -0
  17. package/dist/CardView.main.js.map +1 -0
  18. package/dist/CardView.mjs +235 -0
  19. package/dist/CardView.module.js +235 -0
  20. package/dist/CardView.module.js.map +1 -0
  21. package/dist/CardViewContext.main.js +31 -0
  22. package/dist/CardViewContext.main.js.map +1 -0
  23. package/dist/CardViewContext.mjs +21 -0
  24. package/dist/CardViewContext.module.js +21 -0
  25. package/dist/CardViewContext.module.js.map +1 -0
  26. package/dist/GalleryLayout.main.js +229 -0
  27. package/dist/GalleryLayout.main.js.map +1 -0
  28. package/dist/GalleryLayout.mjs +224 -0
  29. package/dist/GalleryLayout.module.js +224 -0
  30. package/dist/GalleryLayout.module.js.map +1 -0
  31. package/dist/GridLayout.main.js +174 -0
  32. package/dist/GridLayout.main.js.map +1 -0
  33. package/dist/GridLayout.mjs +169 -0
  34. package/dist/GridLayout.module.js +169 -0
  35. package/dist/GridLayout.module.js.map +1 -0
  36. package/dist/WaterfallLayout.main.js +181 -0
  37. package/dist/WaterfallLayout.main.js.map +1 -0
  38. package/dist/WaterfallLayout.mjs +176 -0
  39. package/dist/WaterfallLayout.module.js +176 -0
  40. package/dist/WaterfallLayout.module.js.map +1 -0
  41. package/dist/ar-AE.main.js +7 -0
  42. package/dist/ar-AE.main.js.map +1 -0
  43. package/dist/ar-AE.mjs +9 -0
  44. package/dist/ar-AE.module.js +9 -0
  45. package/dist/ar-AE.module.js.map +1 -0
  46. package/dist/bg-BG.main.js +7 -0
  47. package/dist/bg-BG.main.js.map +1 -0
  48. package/dist/bg-BG.mjs +9 -0
  49. package/dist/bg-BG.module.js +9 -0
  50. package/dist/bg-BG.module.js.map +1 -0
  51. package/dist/card_vars_css.main.js +116 -0
  52. package/dist/card_vars_css.main.js.map +1 -0
  53. package/dist/card_vars_css.mjs +118 -0
  54. package/dist/card_vars_css.module.js +118 -0
  55. package/dist/card_vars_css.module.js.map +1 -0
  56. package/dist/cs-CZ.main.js +7 -0
  57. package/dist/cs-CZ.main.js.map +1 -0
  58. package/dist/cs-CZ.mjs +9 -0
  59. package/dist/cs-CZ.module.js +9 -0
  60. package/dist/cs-CZ.module.js.map +1 -0
  61. package/dist/da-DK.main.js +7 -0
  62. package/dist/da-DK.main.js.map +1 -0
  63. package/dist/da-DK.mjs +9 -0
  64. package/dist/da-DK.module.js +9 -0
  65. package/dist/da-DK.module.js.map +1 -0
  66. package/dist/de-DE.main.js +7 -0
  67. package/dist/de-DE.main.js.map +1 -0
  68. package/dist/de-DE.mjs +9 -0
  69. package/dist/de-DE.module.js +9 -0
  70. package/dist/de-DE.module.js.map +1 -0
  71. package/dist/el-GR.main.js +7 -0
  72. package/dist/el-GR.main.js.map +1 -0
  73. package/dist/el-GR.mjs +9 -0
  74. package/dist/el-GR.module.js +9 -0
  75. package/dist/el-GR.module.js.map +1 -0
  76. package/dist/en-US.main.js +7 -0
  77. package/dist/en-US.main.js.map +1 -0
  78. package/dist/en-US.mjs +9 -0
  79. package/dist/en-US.module.js +9 -0
  80. package/dist/en-US.module.js.map +1 -0
  81. package/dist/es-ES.main.js +7 -0
  82. package/dist/es-ES.main.js.map +1 -0
  83. package/dist/es-ES.mjs +9 -0
  84. package/dist/es-ES.module.js +9 -0
  85. package/dist/es-ES.module.js.map +1 -0
  86. package/dist/et-EE.main.js +7 -0
  87. package/dist/et-EE.main.js.map +1 -0
  88. package/dist/et-EE.mjs +9 -0
  89. package/dist/et-EE.module.js +9 -0
  90. package/dist/et-EE.module.js.map +1 -0
  91. package/dist/fi-FI.main.js +7 -0
  92. package/dist/fi-FI.main.js.map +1 -0
  93. package/dist/fi-FI.mjs +9 -0
  94. package/dist/fi-FI.module.js +9 -0
  95. package/dist/fi-FI.module.js.map +1 -0
  96. package/dist/fr-FR.main.js +7 -0
  97. package/dist/fr-FR.main.js.map +1 -0
  98. package/dist/fr-FR.mjs +9 -0
  99. package/dist/fr-FR.module.js +9 -0
  100. package/dist/fr-FR.module.js.map +1 -0
  101. package/dist/he-IL.main.js +7 -0
  102. package/dist/he-IL.main.js.map +1 -0
  103. package/dist/he-IL.mjs +9 -0
  104. package/dist/he-IL.module.js +9 -0
  105. package/dist/he-IL.module.js.map +1 -0
  106. package/dist/hr-HR.main.js +7 -0
  107. package/dist/hr-HR.main.js.map +1 -0
  108. package/dist/hr-HR.mjs +9 -0
  109. package/dist/hr-HR.module.js +9 -0
  110. package/dist/hr-HR.module.js.map +1 -0
  111. package/dist/hu-HU.main.js +7 -0
  112. package/dist/hu-HU.main.js.map +1 -0
  113. package/dist/hu-HU.mjs +9 -0
  114. package/dist/hu-HU.module.js +9 -0
  115. package/dist/hu-HU.module.js.map +1 -0
  116. package/dist/import.mjs +26 -0
  117. package/dist/intlStrings.main.js +108 -0
  118. package/dist/intlStrings.main.js.map +1 -0
  119. package/dist/intlStrings.mjs +110 -0
  120. package/dist/intlStrings.module.js +110 -0
  121. package/dist/intlStrings.module.js.map +1 -0
  122. package/dist/it-IT.main.js +7 -0
  123. package/dist/it-IT.main.js.map +1 -0
  124. package/dist/it-IT.mjs +9 -0
  125. package/dist/it-IT.module.js +9 -0
  126. package/dist/it-IT.module.js.map +1 -0
  127. package/dist/ja-JP.main.js +7 -0
  128. package/dist/ja-JP.main.js.map +1 -0
  129. package/dist/ja-JP.mjs +9 -0
  130. package/dist/ja-JP.module.js +9 -0
  131. package/dist/ja-JP.module.js.map +1 -0
  132. package/dist/ko-KR.main.js +7 -0
  133. package/dist/ko-KR.main.js.map +1 -0
  134. package/dist/ko-KR.mjs +9 -0
  135. package/dist/ko-KR.module.js +9 -0
  136. package/dist/ko-KR.module.js.map +1 -0
  137. package/dist/lt-LT.main.js +7 -0
  138. package/dist/lt-LT.main.js.map +1 -0
  139. package/dist/lt-LT.mjs +9 -0
  140. package/dist/lt-LT.module.js +9 -0
  141. package/dist/lt-LT.module.js.map +1 -0
  142. package/dist/lv-LV.main.js +7 -0
  143. package/dist/lv-LV.main.js.map +1 -0
  144. package/dist/lv-LV.mjs +9 -0
  145. package/dist/lv-LV.module.js +9 -0
  146. package/dist/lv-LV.module.js.map +1 -0
  147. package/dist/main.js +21 -1457
  148. package/dist/main.js.map +1 -1
  149. package/dist/module.js +17 -1442
  150. package/dist/module.js.map +1 -1
  151. package/dist/nb-NO.main.js +7 -0
  152. package/dist/nb-NO.main.js.map +1 -0
  153. package/dist/nb-NO.mjs +9 -0
  154. package/dist/nb-NO.module.js +9 -0
  155. package/dist/nb-NO.module.js.map +1 -0
  156. package/dist/nl-NL.main.js +7 -0
  157. package/dist/nl-NL.main.js.map +1 -0
  158. package/dist/nl-NL.mjs +9 -0
  159. package/dist/nl-NL.module.js +9 -0
  160. package/dist/nl-NL.module.js.map +1 -0
  161. package/dist/pl-PL.main.js +7 -0
  162. package/dist/pl-PL.main.js.map +1 -0
  163. package/dist/pl-PL.mjs +9 -0
  164. package/dist/pl-PL.module.js +9 -0
  165. package/dist/pl-PL.module.js.map +1 -0
  166. package/dist/pt-BR.main.js +7 -0
  167. package/dist/pt-BR.main.js.map +1 -0
  168. package/dist/pt-BR.mjs +9 -0
  169. package/dist/pt-BR.module.js +9 -0
  170. package/dist/pt-BR.module.js.map +1 -0
  171. package/dist/pt-PT.main.js +7 -0
  172. package/dist/pt-PT.main.js.map +1 -0
  173. package/dist/pt-PT.mjs +9 -0
  174. package/dist/pt-PT.module.js +9 -0
  175. package/dist/pt-PT.module.js.map +1 -0
  176. package/dist/ro-RO.main.js +7 -0
  177. package/dist/ro-RO.main.js.map +1 -0
  178. package/dist/ro-RO.mjs +9 -0
  179. package/dist/ro-RO.module.js +9 -0
  180. package/dist/ro-RO.module.js.map +1 -0
  181. package/dist/ru-RU.main.js +7 -0
  182. package/dist/ru-RU.main.js.map +1 -0
  183. package/dist/ru-RU.mjs +9 -0
  184. package/dist/ru-RU.module.js +9 -0
  185. package/dist/ru-RU.module.js.map +1 -0
  186. package/dist/sk-SK.main.js +7 -0
  187. package/dist/sk-SK.main.js.map +1 -0
  188. package/dist/sk-SK.mjs +9 -0
  189. package/dist/sk-SK.module.js +9 -0
  190. package/dist/sk-SK.module.js.map +1 -0
  191. package/dist/sl-SI.main.js +7 -0
  192. package/dist/sl-SI.main.js.map +1 -0
  193. package/dist/sl-SI.mjs +9 -0
  194. package/dist/sl-SI.module.js +9 -0
  195. package/dist/sl-SI.module.js.map +1 -0
  196. package/dist/sr-SP.main.js +7 -0
  197. package/dist/sr-SP.main.js.map +1 -0
  198. package/dist/sr-SP.mjs +9 -0
  199. package/dist/sr-SP.module.js +9 -0
  200. package/dist/sr-SP.module.js.map +1 -0
  201. package/dist/sv-SE.main.js +7 -0
  202. package/dist/sv-SE.main.js.map +1 -0
  203. package/dist/sv-SE.mjs +9 -0
  204. package/dist/sv-SE.module.js +9 -0
  205. package/dist/sv-SE.module.js.map +1 -0
  206. package/dist/tr-TR.main.js +7 -0
  207. package/dist/tr-TR.main.js.map +1 -0
  208. package/dist/tr-TR.mjs +9 -0
  209. package/dist/tr-TR.module.js +9 -0
  210. package/dist/tr-TR.module.js.map +1 -0
  211. package/dist/types.d.ts +35 -33
  212. package/dist/types.d.ts.map +1 -1
  213. package/dist/uk-UA.main.js +7 -0
  214. package/dist/uk-UA.main.js.map +1 -0
  215. package/dist/uk-UA.mjs +9 -0
  216. package/dist/uk-UA.module.js +9 -0
  217. package/dist/uk-UA.module.js.map +1 -0
  218. package/dist/vars.e5a6cd16.css +1671 -0
  219. package/dist/vars.e5a6cd16.css.map +1 -0
  220. package/dist/zh-CN.main.js +7 -0
  221. package/dist/zh-CN.main.js.map +1 -0
  222. package/dist/zh-CN.mjs +9 -0
  223. package/dist/zh-CN.module.js +9 -0
  224. package/dist/zh-CN.module.js.map +1 -0
  225. package/dist/zh-TW.main.js +7 -0
  226. package/dist/zh-TW.main.js.map +1 -0
  227. package/dist/zh-TW.mjs +9 -0
  228. package/dist/zh-TW.module.js +9 -0
  229. package/dist/zh-TW.module.js.map +1 -0
  230. package/package.json +28 -25
  231. package/src/BaseLayout.tsx +35 -32
  232. package/src/CardBase.tsx +3 -3
  233. package/src/CardView.tsx +50 -43
  234. package/src/GalleryLayout.tsx +3 -2
  235. package/src/GridLayout.tsx +6 -39
  236. package/src/WaterfallLayout.tsx +7 -5
  237. package/src/index.ts +10 -5
  238. package/LICENSE +0 -201
  239. package/dist/main.css +0 -1
@@ -0,0 +1,213 @@
1
+ var $kQhHy$reactstatelycollections = require("@react-stately/collections");
2
+ var $kQhHy$reactstatelyvirtualizer = require("@react-stately/virtualizer");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "BaseLayout", () => $5ee605f09afaa4de$export$64943d2e59d72a29);
10
+ /*
11
+ * Copyright 2021 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ class $5ee605f09afaa4de$export$64943d2e59d72a29 extends (0, $kQhHy$reactstatelyvirtualizer.Layout) {
23
+ update(invalidationContext) {
24
+ var _invalidationContext_layoutOptions, _invalidationContext_layoutOptions1;
25
+ this.collection = this.virtualizer.collection;
26
+ this.isLoading = ((_invalidationContext_layoutOptions = invalidationContext.layoutOptions) === null || _invalidationContext_layoutOptions === void 0 ? void 0 : _invalidationContext_layoutOptions.isLoading) || false;
27
+ this.direction = ((_invalidationContext_layoutOptions1 = invalidationContext.layoutOptions) === null || _invalidationContext_layoutOptions1 === void 0 ? void 0 : _invalidationContext_layoutOptions1.direction) || 'ltr';
28
+ this.buildCollection(invalidationContext);
29
+ // Remove layout info that doesn't exist in new collection
30
+ if (this.lastCollection) {
31
+ for (let key of this.lastCollection.getKeys())if (!this.collection.getItem(key)) this.layoutInfos.delete(key);
32
+ if (!this.isLoading) this.layoutInfos.delete('loader');
33
+ if (this.collection.size > 0) this.layoutInfos.delete('placeholder');
34
+ }
35
+ this.lastCollection = this.collection;
36
+ }
37
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ buildCollection(invalidationContext) {}
39
+ getContentSize() {
40
+ return this.contentSize;
41
+ }
42
+ getLayoutInfo(key) {
43
+ return this.layoutInfos.get(key);
44
+ }
45
+ getVisibleLayoutInfos(rect, excludePersistedKeys = false) {
46
+ let res = [];
47
+ for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect, excludePersistedKeys)) res.push(layoutInfo);
48
+ return res;
49
+ }
50
+ isVisible(layoutInfo, rect, excludePersistedKeys) {
51
+ if (layoutInfo.rect.intersects(rect)) return true;
52
+ if (!excludePersistedKeys) return this.virtualizer.isPersistedKey(layoutInfo.key);
53
+ return false;
54
+ }
55
+ _findClosestLayoutInfo(target, rect) {
56
+ let layoutInfos = this.getVisibleLayoutInfos(rect, true);
57
+ let best = null;
58
+ let bestDistance = Infinity;
59
+ // Calculates distance as the distance between the center of 2 rects.
60
+ for (let cur of layoutInfos)if (cur.type === 'item') {
61
+ let curRect = cur.rect;
62
+ let targetMidX = (target.x + target.maxX) / 2;
63
+ let targetMidY = (target.y + target.maxY) / 2;
64
+ let curMidX = (curRect.x + curRect.maxX) / 2;
65
+ let curMidY = (curRect.y + curRect.maxY) / 2;
66
+ let dist = Math.pow(targetMidX - curMidX, 2) + Math.pow(targetMidY - curMidY, 2);
67
+ if (dist < bestDistance) {
68
+ best = cur;
69
+ bestDistance = dist;
70
+ }
71
+ }
72
+ return best;
73
+ }
74
+ _findClosest(target, rect) {
75
+ let best = this._findClosestLayoutInfo(target, rect);
76
+ return best || null;
77
+ }
78
+ getKeyBelow(key) {
79
+ var _this__findClosest, _getFirstItem;
80
+ // Expected key is the currently focused cell so we need the parent row key
81
+ let parentRowKey = this.collection.getItem(key).parentKey;
82
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
83
+ let rect = new (0, $kQhHy$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, layoutInfo.rect.maxY + 1, layoutInfo.rect.width, this.virtualizer.visibleRect.height);
84
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
85
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
86
+ }
87
+ getKeyAbove(key) {
88
+ var _this__findClosest, _getFirstItem;
89
+ // Expected key is the currently focused cell so we need the parent row key
90
+ let parentRowKey = this.collection.getItem(key).parentKey;
91
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
92
+ let rect = new (0, $kQhHy$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, 0, layoutInfo.rect.width, layoutInfo.rect.y - 1);
93
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
94
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
95
+ }
96
+ getKeyRightOf(key) {
97
+ // Expected key is the currently focused cell so we need the parent row key
98
+ let parentRowKey = this.collection.getItem(key).parentKey;
99
+ key = this.direction === 'rtl' ? this.collection.getKeyBefore(parentRowKey) : this.collection.getKeyAfter(parentRowKey);
100
+ while(key != null){
101
+ var _getFirstItem;
102
+ let item = this.collection.getItem(key);
103
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
104
+ if (item.type === 'item') return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
105
+ key = this.direction === 'rtl' ? this.collection.getKeyBefore(key) : this.collection.getKeyAfter(key);
106
+ }
107
+ }
108
+ getKeyLeftOf(key) {
109
+ // Expected key is the currently focused cell so we need the parent row key
110
+ let parentRowKey = this.collection.getItem(key).parentKey;
111
+ key = this.direction === 'rtl' ? this.collection.getKeyAfter(parentRowKey) : this.collection.getKeyBefore(parentRowKey);
112
+ while(key != null){
113
+ var _getFirstItem;
114
+ let item = this.collection.getItem(key);
115
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
116
+ if (item.type === 'item') return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
117
+ key = this.direction === 'rtl' ? this.collection.getKeyAfter(key) : this.collection.getKeyBefore(key);
118
+ }
119
+ }
120
+ getFirstKey() {
121
+ var _getFirstItem;
122
+ let firstRow = this.collection.getItem(this.collection.getFirstKey());
123
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(firstRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
124
+ }
125
+ getLastKey() {
126
+ var _getFirstItem;
127
+ let lastRow = this.collection.getItem(this.collection.getLastKey());
128
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(lastRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
129
+ }
130
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
131
+ // Perhaps have layoutInfo store childKey as well so we don't need to do this? Or maybe make the layoutInfos be the cells instead of the rows?
132
+ getKeyPageAbove(key) {
133
+ // Expected key is the currently focused cell so we need the parent row key
134
+ let parentRowKey = this.collection.getItem(key).parentKey;
135
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
136
+ if (layoutInfo) {
137
+ var _this_collection_getItem;
138
+ let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);
139
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately above
140
+ // Otherwise keep going up until we exceed a single page height worth of nodes
141
+ let keyAbove = (_this_collection_getItem = this.collection.getItem(this.getKeyAbove(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
142
+ layoutInfo = this.getLayoutInfo(keyAbove);
143
+ if (layoutInfo && layoutInfo.rect.y > pageY) while(layoutInfo && layoutInfo.rect.y > pageY){
144
+ var _getFirstItem, _this_collection_getItem1;
145
+ let childKey = (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
146
+ let keyAbove = (_this_collection_getItem1 = this.collection.getItem(this.getKeyAbove(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
147
+ layoutInfo = this.getLayoutInfo(keyAbove);
148
+ }
149
+ if (layoutInfo) {
150
+ var _getFirstItem1;
151
+ let childKey = (_getFirstItem1 = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key;
152
+ return childKey;
153
+ }
154
+ }
155
+ return this.getFirstKey();
156
+ }
157
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
158
+ // Perhaps have layoutInfo store childKey as well so we don't need to do this?
159
+ getKeyPageBelow(key) {
160
+ // Expected key is the currently focused cell so we need the parent row key
161
+ let parentRowKey = this.collection.getItem(key).parentKey;
162
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
163
+ if (layoutInfo) {
164
+ var _this_collection_getItem;
165
+ let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);
166
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately below
167
+ // Otherwise keep going up until we exceed a single page height worth of nodes
168
+ let keyBelow = (_this_collection_getItem = this.collection.getItem(this.getKeyBelow(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
169
+ layoutInfo = this.getLayoutInfo(keyBelow);
170
+ if (layoutInfo && layoutInfo.rect.y < pageY) while(layoutInfo && layoutInfo.rect.y < pageY){
171
+ var _getFirstItem, _this_collection_getItem1;
172
+ let childKey = (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
173
+ let keyBelow = (_this_collection_getItem1 = this.collection.getItem(this.getKeyBelow(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
174
+ layoutInfo = this.getLayoutInfo(keyBelow);
175
+ }
176
+ if (layoutInfo) {
177
+ var _getFirstItem1;
178
+ let childKey = (_getFirstItem1 = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key;
179
+ return childKey;
180
+ }
181
+ }
182
+ return this.getLastKey();
183
+ }
184
+ getKeyForSearch(search, fromKey) {
185
+ if (!this.collator) return null;
186
+ let collection = this.collection;
187
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
188
+ let startItem = collection.getItem(key);
189
+ key = startItem.parentKey;
190
+ while(key != null){
191
+ let item = collection.getItem(key);
192
+ if (item.textValue) {
193
+ var _getFirstItem;
194
+ let substring = item.textValue.slice(0, search.length);
195
+ if (this.collator.compare(substring, search) === 0) return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
196
+ }
197
+ key = this.collection.getKeyAfter(key);
198
+ }
199
+ return null;
200
+ }
201
+ constructor(options = {}){
202
+ super();
203
+ this.disabledKeys = new Set();
204
+ this.layoutInfos = new Map();
205
+ this.collator = options.collator;
206
+ this.lastCollection = null;
207
+ this.scale = options.scale || 'medium';
208
+ this.margin = options.margin || 24;
209
+ }
210
+ }
211
+
212
+
213
+ //# sourceMappingURL=BaseLayout.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAwBM,MAAM,kDAAsB,CAAA,GAAA,qCAAK;IAqBtC,OAAO,mBAA+D,EAAE;YAErD,oCACA;QAFjB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU;QAC7C,IAAI,CAAC,SAAS,GAAG,EAAA,qCAAA,oBAAo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;YACT;QACF;QAEA,OAAO,IAAI,CAAC,UAAU;IACxB;IAEA,gBAAgB,MAAc,EAAE,OAAa,EAAE;QAC7C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,OAAO;QAGT,IAAI,aAAa,IAAI,CAAC,UAAU;QAChC,IAAI,MAAM,oBAAA,qBAAA,UAAW,IAAI,CAAC,WAAW;QAErC,IAAI,YAAY,WAAW,OAAO,CAAC;QACnC,MAAM,UAAU,SAAS;QAEzB,MAAO,OAAO,KAAM;YAClB,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,KAAK,SAAS,EAAE;oBAGT;gBAFT,IAAI,YAAY,KAAK,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,MAAM;gBACrD,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,YAAY,GAC/C,QAAO,gBAAA,CAAA,GAAA,2CAAW,EAAE,CAAA,GAAA,4CAAY,EAAE,MAAM,IAAI,CAAC,UAAU,gBAAhD,oCAAA,cAAoD,GAAG;YAElE;YAEA,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QACpC;QAEA,OAAO;IACT;IAjPA,YAAY,UAA6B,CAAC,CAAC,CAAE;QAC3C,KAAK;aANP,eAAyB,IAAI;QAO3B,IAAI,CAAC,WAAW,GAAG,IAAI;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ;QAChC,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,CAAC,KAAK,GAAG,QAAQ,KAAK,IAAI;QAC9B,IAAI,CAAC,MAAM,GAAG,QAAQ,MAAM,IAAI;IAClC;AA2OF","sources":["packages/@react-spectrum/card/src/BaseLayout.tsx"],"sourcesContent":["/*\n * Copyright 2021 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 {Direction, Key, KeyboardDelegate, Node} from '@react-types/shared';\nimport {getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {GridCollection} from '@react-stately/grid';\nimport {InvalidationContext, Layout, LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\nimport {Scale} from '@react-types/provider';\n\nexport interface BaseLayoutOptions {\n collator?: Intl.Collator,\n // TODO: is this valid or is scale a spectrum specific thing that should be left out of the layouts?\n scale?: Scale,\n /**\n * The margin around the grid view between the edges and the items.\n * @default 24\n */\n margin?: number\n}\n\ninterface CardViewLayoutOptions {\n isLoading: boolean,\n direction: Direction\n}\n\nexport class BaseLayout<T> extends Layout<Node<T>, CardViewLayoutOptions> implements KeyboardDelegate {\n protected contentSize: Size;\n protected layoutInfos: Map<Key, LayoutInfo>;\n protected collator: Intl.Collator;\n protected lastCollection: GridCollection<T>;\n collection: GridCollection<T>;\n isLoading: boolean;\n disabledKeys: Set<Key> = new Set();\n direction: Direction;\n scale: Scale;\n margin: number;\n\n constructor(options: BaseLayoutOptions = {}) {\n super();\n this.layoutInfos = new Map();\n this.collator = options.collator;\n this.lastCollection = null;\n this.scale = options.scale || 'medium';\n this.margin = options.margin || 24;\n }\n\n update(invalidationContext: InvalidationContext<CardViewLayoutOptions>) {\n this.collection = this.virtualizer.collection as GridCollection<T>;\n this.isLoading = invalidationContext.layoutOptions?.isLoading || false;\n this.direction = invalidationContext.layoutOptions?.direction || 'ltr';\n this.buildCollection(invalidationContext);\n\n // Remove layout info that doesn't exist in new collection\n if (this.lastCollection) {\n for (let key of this.lastCollection.getKeys()) {\n if (!this.collection.getItem(key)) {\n this.layoutInfos.delete(key);\n }\n }\n\n if (!this.isLoading) {\n this.layoutInfos.delete('loader');\n }\n\n if (this.collection.size > 0) {\n this.layoutInfos.delete('placeholder');\n }\n }\n\n this.lastCollection = this.collection;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n buildCollection(invalidationContext?: InvalidationContext) {}\n\n getContentSize() {\n return this.contentSize;\n }\n\n getLayoutInfo(key: Key) {\n return this.layoutInfos.get(key)!;\n }\n\n getVisibleLayoutInfos(rect: Rect, excludePersistedKeys = false) {\n let res: LayoutInfo[] = [];\n\n for (let layoutInfo of this.layoutInfos.values()) {\n if (this.isVisible(layoutInfo, rect, excludePersistedKeys)) {\n res.push(layoutInfo);\n }\n }\n\n return res;\n }\n\n isVisible(layoutInfo: LayoutInfo, rect: Rect, excludePersistedKeys: boolean) {\n if (layoutInfo.rect.intersects(rect)) {\n return true;\n }\n\n if (!excludePersistedKeys) {\n return this.virtualizer.isPersistedKey(layoutInfo.key);\n }\n\n return false;\n }\n\n _findClosestLayoutInfo(target: Rect, rect: Rect) {\n let layoutInfos = this.getVisibleLayoutInfos(rect, true);\n let best = null;\n let bestDistance = Infinity;\n\n // Calculates distance as the distance between the center of 2 rects.\n for (let cur of layoutInfos) {\n if (cur.type === 'item') {\n let curRect = cur.rect;\n let targetMidX = (target.x + target.maxX) / 2;\n let targetMidY = (target.y + target.maxY) / 2;\n let curMidX = (curRect.x + curRect.maxX) / 2;\n let curMidY = (curRect.y + curRect.maxY) / 2;\n let dist = Math.pow(targetMidX - curMidX, 2) + Math.pow(targetMidY - curMidY, 2);\n if (dist < bestDistance) {\n best = cur;\n bestDistance = dist;\n }\n }\n }\n\n return best;\n }\n\n _findClosest(target: Rect, rect: Rect) {\n let best = this._findClosestLayoutInfo(target, rect);\n return best || null;\n }\n\n getKeyBelow(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let layoutInfo = this.getLayoutInfo(parentRowKey);\n let rect = new Rect(layoutInfo.rect.x, layoutInfo.rect.maxY + 1, layoutInfo.rect.width, this.virtualizer.visibleRect.height);\n let closestRow = this.collection.getItem(this._findClosest(layoutInfo.rect, rect)?.key);\n return getFirstItem(getChildNodes(closestRow, this.collection))?.key;\n }\n\n getKeyAbove(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let layoutInfo = this.getLayoutInfo(parentRowKey);\n let rect = new Rect(layoutInfo.rect.x, 0, layoutInfo.rect.width, layoutInfo.rect.y - 1);\n let closestRow = this.collection.getItem(this._findClosest(layoutInfo.rect, rect)?.key);\n return getFirstItem(getChildNodes(closestRow, this.collection))?.key;\n }\n\n getKeyRightOf(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n key = this.direction === 'rtl' ? this.collection.getKeyBefore(parentRowKey) : this.collection.getKeyAfter(parentRowKey);\n\n while (key != null) {\n let item = this.collection.getItem(key);\n // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)\n if (item.type === 'item') {\n return getFirstItem(getChildNodes(item, this.collection))?.key;\n }\n key = this.direction === 'rtl' ? this.collection.getKeyBefore(key) : this.collection.getKeyAfter(key);\n }\n }\n\n getKeyLeftOf(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n key = this.direction === 'rtl' ? this.collection.getKeyAfter(parentRowKey) : this.collection.getKeyBefore(parentRowKey);\n while (key != null) {\n let item = this.collection.getItem(key);\n // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)\n if (item.type === 'item') {\n return getFirstItem(getChildNodes(item, this.collection))?.key;\n }\n\n key = this.direction === 'rtl' ? this.collection.getKeyAfter(key) : this.collection.getKeyBefore(key);\n }\n }\n\n getFirstKey() {\n let firstRow = this.collection.getItem(this.collection.getFirstKey());\n return getFirstItem(getChildNodes(firstRow, this.collection))?.key;\n }\n\n getLastKey() {\n let lastRow = this.collection.getItem(this.collection.getLastKey());\n return getFirstItem(getChildNodes(lastRow, this.collection))?.key;\n }\n\n // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key\n // Perhaps have layoutInfo store childKey as well so we don't need to do this? Or maybe make the layoutInfos be the cells instead of the rows?\n getKeyPageAbove(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let layoutInfo = this.getLayoutInfo(parentRowKey);\n\n if (layoutInfo) {\n let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);\n // If the node is so large that it spans multiple page heights, return the key of the item immediately above\n // Otherwise keep going up until we exceed a single page height worth of nodes\n let keyAbove = this.collection.getItem(this.getKeyAbove(key))?.parentKey;\n layoutInfo = this.getLayoutInfo(keyAbove);\n\n if (layoutInfo && layoutInfo.rect.y > pageY) {\n while (layoutInfo && layoutInfo.rect.y > pageY) {\n let childKey = getFirstItem(getChildNodes(this.collection.getItem(layoutInfo.key), this.collection))?.key;\n let keyAbove = this.collection.getItem(this.getKeyAbove(childKey))?.parentKey;\n layoutInfo = this.getLayoutInfo(keyAbove);\n }\n }\n\n if (layoutInfo) {\n let childKey = getFirstItem(getChildNodes(this.collection.getItem(layoutInfo.key), this.collection))?.key;\n return childKey;\n }\n }\n\n return this.getFirstKey();\n }\n\n // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key\n // Perhaps have layoutInfo store childKey as well so we don't need to do this?\n getKeyPageBelow(key: Key) {\n // Expected key is the currently focused cell so we need the parent row key\n let parentRowKey = this.collection.getItem(key).parentKey;\n let layoutInfo = this.getLayoutInfo(parentRowKey);\n if (layoutInfo) {\n let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);\n // If the node is so large that it spans multiple page heights, return the key of the item immediately below\n // Otherwise keep going up until we exceed a single page height worth of nodes\n let keyBelow = this.collection.getItem(this.getKeyBelow(key))?.parentKey;\n layoutInfo = this.getLayoutInfo(keyBelow);\n if (layoutInfo && layoutInfo.rect.y < pageY) {\n while (layoutInfo && layoutInfo.rect.y < pageY) {\n let childKey = getFirstItem(getChildNodes(this.collection.getItem(layoutInfo.key), this.collection))?.key;\n let keyBelow = this.collection.getItem(this.getKeyBelow(childKey))?.parentKey;\n layoutInfo = this.getLayoutInfo(keyBelow);\n }\n }\n\n if (layoutInfo) {\n let childKey = getFirstItem(getChildNodes(this.collection.getItem(layoutInfo.key), this.collection))?.key;\n return childKey;\n }\n }\n\n return this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey ?? this.getFirstKey();\n\n let startItem = collection.getItem(key);\n key = startItem.parentKey;\n\n while (key != null) {\n let item = collection.getItem(key);\n if (item.textValue) {\n let substring = item.textValue.slice(0, search.length);\n if (this.collator.compare(substring, search) === 0) {\n return getFirstItem(getChildNodes(item, this.collection))?.key;\n }\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"BaseLayout.main.js.map"}
@@ -0,0 +1,208 @@
1
+ import {getFirstItem as $1JdnP$getFirstItem, getChildNodes as $1JdnP$getChildNodes} from "@react-stately/collections";
2
+ import {Rect as $1JdnP$Rect, Layout as $1JdnP$Layout} from "@react-stately/virtualizer";
3
+
4
+ /*
5
+ * Copyright 2021 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ class $3d424c147206bac9$export$64943d2e59d72a29 extends (0, $1JdnP$Layout) {
17
+ update(invalidationContext) {
18
+ var _invalidationContext_layoutOptions, _invalidationContext_layoutOptions1;
19
+ this.collection = this.virtualizer.collection;
20
+ this.isLoading = ((_invalidationContext_layoutOptions = invalidationContext.layoutOptions) === null || _invalidationContext_layoutOptions === void 0 ? void 0 : _invalidationContext_layoutOptions.isLoading) || false;
21
+ this.direction = ((_invalidationContext_layoutOptions1 = invalidationContext.layoutOptions) === null || _invalidationContext_layoutOptions1 === void 0 ? void 0 : _invalidationContext_layoutOptions1.direction) || 'ltr';
22
+ this.buildCollection(invalidationContext);
23
+ // Remove layout info that doesn't exist in new collection
24
+ if (this.lastCollection) {
25
+ for (let key of this.lastCollection.getKeys())if (!this.collection.getItem(key)) this.layoutInfos.delete(key);
26
+ if (!this.isLoading) this.layoutInfos.delete('loader');
27
+ if (this.collection.size > 0) this.layoutInfos.delete('placeholder');
28
+ }
29
+ this.lastCollection = this.collection;
30
+ }
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ buildCollection(invalidationContext) {}
33
+ getContentSize() {
34
+ return this.contentSize;
35
+ }
36
+ getLayoutInfo(key) {
37
+ return this.layoutInfos.get(key);
38
+ }
39
+ getVisibleLayoutInfos(rect, excludePersistedKeys = false) {
40
+ let res = [];
41
+ for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect, excludePersistedKeys)) res.push(layoutInfo);
42
+ return res;
43
+ }
44
+ isVisible(layoutInfo, rect, excludePersistedKeys) {
45
+ if (layoutInfo.rect.intersects(rect)) return true;
46
+ if (!excludePersistedKeys) return this.virtualizer.isPersistedKey(layoutInfo.key);
47
+ return false;
48
+ }
49
+ _findClosestLayoutInfo(target, rect) {
50
+ let layoutInfos = this.getVisibleLayoutInfos(rect, true);
51
+ let best = null;
52
+ let bestDistance = Infinity;
53
+ // Calculates distance as the distance between the center of 2 rects.
54
+ for (let cur of layoutInfos)if (cur.type === 'item') {
55
+ let curRect = cur.rect;
56
+ let targetMidX = (target.x + target.maxX) / 2;
57
+ let targetMidY = (target.y + target.maxY) / 2;
58
+ let curMidX = (curRect.x + curRect.maxX) / 2;
59
+ let curMidY = (curRect.y + curRect.maxY) / 2;
60
+ let dist = Math.pow(targetMidX - curMidX, 2) + Math.pow(targetMidY - curMidY, 2);
61
+ if (dist < bestDistance) {
62
+ best = cur;
63
+ bestDistance = dist;
64
+ }
65
+ }
66
+ return best;
67
+ }
68
+ _findClosest(target, rect) {
69
+ let best = this._findClosestLayoutInfo(target, rect);
70
+ return best || null;
71
+ }
72
+ getKeyBelow(key) {
73
+ var _this__findClosest, _getFirstItem;
74
+ // Expected key is the currently focused cell so we need the parent row key
75
+ let parentRowKey = this.collection.getItem(key).parentKey;
76
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
77
+ let rect = new (0, $1JdnP$Rect)(layoutInfo.rect.x, layoutInfo.rect.maxY + 1, layoutInfo.rect.width, this.virtualizer.visibleRect.height);
78
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
79
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
80
+ }
81
+ getKeyAbove(key) {
82
+ var _this__findClosest, _getFirstItem;
83
+ // Expected key is the currently focused cell so we need the parent row key
84
+ let parentRowKey = this.collection.getItem(key).parentKey;
85
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
86
+ let rect = new (0, $1JdnP$Rect)(layoutInfo.rect.x, 0, layoutInfo.rect.width, layoutInfo.rect.y - 1);
87
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
88
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
89
+ }
90
+ getKeyRightOf(key) {
91
+ // Expected key is the currently focused cell so we need the parent row key
92
+ let parentRowKey = this.collection.getItem(key).parentKey;
93
+ key = this.direction === 'rtl' ? this.collection.getKeyBefore(parentRowKey) : this.collection.getKeyAfter(parentRowKey);
94
+ while(key != null){
95
+ var _getFirstItem;
96
+ let item = this.collection.getItem(key);
97
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
98
+ if (item.type === 'item') return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
99
+ key = this.direction === 'rtl' ? this.collection.getKeyBefore(key) : this.collection.getKeyAfter(key);
100
+ }
101
+ }
102
+ getKeyLeftOf(key) {
103
+ // Expected key is the currently focused cell so we need the parent row key
104
+ let parentRowKey = this.collection.getItem(key).parentKey;
105
+ key = this.direction === 'rtl' ? this.collection.getKeyAfter(parentRowKey) : this.collection.getKeyBefore(parentRowKey);
106
+ while(key != null){
107
+ var _getFirstItem;
108
+ let item = this.collection.getItem(key);
109
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
110
+ if (item.type === 'item') return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
111
+ key = this.direction === 'rtl' ? this.collection.getKeyAfter(key) : this.collection.getKeyBefore(key);
112
+ }
113
+ }
114
+ getFirstKey() {
115
+ var _getFirstItem;
116
+ let firstRow = this.collection.getItem(this.collection.getFirstKey());
117
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(firstRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
118
+ }
119
+ getLastKey() {
120
+ var _getFirstItem;
121
+ let lastRow = this.collection.getItem(this.collection.getLastKey());
122
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(lastRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
123
+ }
124
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
125
+ // Perhaps have layoutInfo store childKey as well so we don't need to do this? Or maybe make the layoutInfos be the cells instead of the rows?
126
+ getKeyPageAbove(key) {
127
+ // Expected key is the currently focused cell so we need the parent row key
128
+ let parentRowKey = this.collection.getItem(key).parentKey;
129
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
130
+ if (layoutInfo) {
131
+ var _this_collection_getItem;
132
+ let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);
133
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately above
134
+ // Otherwise keep going up until we exceed a single page height worth of nodes
135
+ let keyAbove = (_this_collection_getItem = this.collection.getItem(this.getKeyAbove(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
136
+ layoutInfo = this.getLayoutInfo(keyAbove);
137
+ if (layoutInfo && layoutInfo.rect.y > pageY) while(layoutInfo && layoutInfo.rect.y > pageY){
138
+ var _getFirstItem, _this_collection_getItem1;
139
+ let childKey = (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
140
+ let keyAbove = (_this_collection_getItem1 = this.collection.getItem(this.getKeyAbove(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
141
+ layoutInfo = this.getLayoutInfo(keyAbove);
142
+ }
143
+ if (layoutInfo) {
144
+ var _getFirstItem1;
145
+ let childKey = (_getFirstItem1 = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key;
146
+ return childKey;
147
+ }
148
+ }
149
+ return this.getFirstKey();
150
+ }
151
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
152
+ // Perhaps have layoutInfo store childKey as well so we don't need to do this?
153
+ getKeyPageBelow(key) {
154
+ // Expected key is the currently focused cell so we need the parent row key
155
+ let parentRowKey = this.collection.getItem(key).parentKey;
156
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
157
+ if (layoutInfo) {
158
+ var _this_collection_getItem;
159
+ let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);
160
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately below
161
+ // Otherwise keep going up until we exceed a single page height worth of nodes
162
+ let keyBelow = (_this_collection_getItem = this.collection.getItem(this.getKeyBelow(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
163
+ layoutInfo = this.getLayoutInfo(keyBelow);
164
+ if (layoutInfo && layoutInfo.rect.y < pageY) while(layoutInfo && layoutInfo.rect.y < pageY){
165
+ var _getFirstItem, _this_collection_getItem1;
166
+ let childKey = (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
167
+ let keyBelow = (_this_collection_getItem1 = this.collection.getItem(this.getKeyBelow(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
168
+ layoutInfo = this.getLayoutInfo(keyBelow);
169
+ }
170
+ if (layoutInfo) {
171
+ var _getFirstItem1;
172
+ let childKey = (_getFirstItem1 = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key;
173
+ return childKey;
174
+ }
175
+ }
176
+ return this.getLastKey();
177
+ }
178
+ getKeyForSearch(search, fromKey) {
179
+ if (!this.collator) return null;
180
+ let collection = this.collection;
181
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
182
+ let startItem = collection.getItem(key);
183
+ key = startItem.parentKey;
184
+ while(key != null){
185
+ let item = collection.getItem(key);
186
+ if (item.textValue) {
187
+ var _getFirstItem;
188
+ let substring = item.textValue.slice(0, search.length);
189
+ if (this.collator.compare(substring, search) === 0) return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
190
+ }
191
+ key = this.collection.getKeyAfter(key);
192
+ }
193
+ return null;
194
+ }
195
+ constructor(options = {}){
196
+ super();
197
+ this.disabledKeys = new Set();
198
+ this.layoutInfos = new Map();
199
+ this.collator = options.collator;
200
+ this.lastCollection = null;
201
+ this.scale = options.scale || 'medium';
202
+ this.margin = options.margin || 24;
203
+ }
204
+ }
205
+
206
+
207
+ export {$3d424c147206bac9$export$64943d2e59d72a29 as BaseLayout};
208
+ //# sourceMappingURL=BaseLayout.module.js.map