@react-spectrum/card 3.0.0-nightly.4552 → 3.0.0-nightly.4558

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 (94) hide show
  1. package/dist/BaseLayout.main.js +218 -0
  2. package/dist/BaseLayout.main.js.map +1 -0
  3. package/dist/BaseLayout.mjs +213 -0
  4. package/dist/BaseLayout.module.js +213 -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 +232 -0
  17. package/dist/CardView.main.js.map +1 -0
  18. package/dist/CardView.mjs +227 -0
  19. package/dist/CardView.module.js +227 -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 +198 -0
  32. package/dist/GridLayout.main.js.map +1 -0
  33. package/dist/GridLayout.mjs +193 -0
  34. package/dist/GridLayout.module.js +193 -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.mjs +1 -1
  42. package/dist/bg-BG.mjs +1 -1
  43. package/dist/card_vars_css.main.js +116 -0
  44. package/dist/card_vars_css.main.js.map +1 -0
  45. package/dist/card_vars_css.mjs +118 -0
  46. package/dist/card_vars_css.module.js +118 -0
  47. package/dist/card_vars_css.module.js.map +1 -0
  48. package/dist/cs-CZ.mjs +1 -1
  49. package/dist/da-DK.mjs +1 -1
  50. package/dist/de-DE.mjs +1 -1
  51. package/dist/el-GR.mjs +1 -1
  52. package/dist/en-US.mjs +1 -1
  53. package/dist/es-ES.mjs +1 -1
  54. package/dist/et-EE.mjs +1 -1
  55. package/dist/fi-FI.mjs +1 -1
  56. package/dist/fr-FR.mjs +1 -1
  57. package/dist/he-IL.mjs +1 -1
  58. package/dist/hr-HR.mjs +1 -1
  59. package/dist/hu-HU.mjs +1 -1
  60. package/dist/import.mjs +5 -1458
  61. package/dist/intlStrings.main.js +108 -0
  62. package/dist/intlStrings.main.js.map +1 -0
  63. package/dist/intlStrings.mjs +110 -0
  64. package/dist/intlStrings.module.js +110 -0
  65. package/dist/intlStrings.module.js.map +1 -0
  66. package/dist/it-IT.mjs +1 -1
  67. package/dist/ja-JP.mjs +1 -1
  68. package/dist/ko-KR.mjs +1 -1
  69. package/dist/lt-LT.mjs +1 -1
  70. package/dist/lv-LV.mjs +1 -1
  71. package/dist/main.js +10 -1459
  72. package/dist/main.js.map +1 -1
  73. package/dist/module.js +5 -1458
  74. package/dist/module.js.map +1 -1
  75. package/dist/nb-NO.mjs +1 -1
  76. package/dist/nl-NL.mjs +1 -1
  77. package/dist/pl-PL.mjs +1 -1
  78. package/dist/pt-BR.mjs +1 -1
  79. package/dist/pt-PT.mjs +1 -1
  80. package/dist/ro-RO.mjs +1 -1
  81. package/dist/ru-RU.mjs +1 -1
  82. package/dist/sk-SK.mjs +1 -1
  83. package/dist/sl-SI.mjs +1 -1
  84. package/dist/sr-SP.mjs +1 -1
  85. package/dist/sv-SE.mjs +1 -1
  86. package/dist/tr-TR.mjs +1 -1
  87. package/dist/uk-UA.mjs +1 -1
  88. package/dist/{main.css → vars.e5a6cd16.css} +1 -1
  89. package/dist/{main.css.map → vars.e5a6cd16.css.map} +1 -1
  90. package/dist/zh-CN.mjs +1 -1
  91. package/dist/zh-TW.mjs +1 -1
  92. package/package.json +19 -19
  93. package/dist/module.css +0 -1671
  94. package/dist/module.css.map +0 -1
@@ -0,0 +1,218 @@
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
+ validate(invalidationContext) {
24
+ this.collection = this.virtualizer.collection;
25
+ this.buildCollection(invalidationContext);
26
+ // Remove layout info that doesn't exist in new collection
27
+ if (this.lastCollection) {
28
+ for (let key of this.lastCollection.getKeys())if (!this.collection.getItem(key)) this.layoutInfos.delete(key);
29
+ if (!this.isLoading) this.layoutInfos.delete("loader");
30
+ if (this.collection.size > 0) this.layoutInfos.delete("placeholder");
31
+ }
32
+ this.lastCollection = this.collection;
33
+ }
34
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
35
+ buildCollection(invalidationContext) {}
36
+ getContentSize() {
37
+ return this.contentSize;
38
+ }
39
+ getLayoutInfo(key) {
40
+ return this.layoutInfos.get(key);
41
+ }
42
+ getVisibleLayoutInfos(rect) {
43
+ let res = [];
44
+ for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
45
+ return res;
46
+ }
47
+ isVisible(layoutInfo, rect) {
48
+ return layoutInfo.rect.intersects(rect);
49
+ }
50
+ getInitialLayoutInfo(layoutInfo) {
51
+ layoutInfo.opacity = 0;
52
+ layoutInfo.transform = "scale3d(0.8, 0.8, 0.8)";
53
+ return layoutInfo;
54
+ }
55
+ getFinalLayoutInfo(layoutInfo) {
56
+ layoutInfo.opacity = 0;
57
+ layoutInfo.transform = "scale3d(0.8, 0.8, 0.8)";
58
+ return layoutInfo;
59
+ }
60
+ _findClosestLayoutInfo(target, rect) {
61
+ let layoutInfos = this.getVisibleLayoutInfos(rect);
62
+ let best = null;
63
+ let bestDistance = Infinity;
64
+ // Calculates distance as the distance between the center of 2 rects.
65
+ for (let cur of layoutInfos)if (cur.type === "item") {
66
+ let curRect = cur.rect;
67
+ let targetMidX = (target.x + target.maxX) / 2;
68
+ let targetMidY = (target.y + target.maxY) / 2;
69
+ let curMidX = (curRect.x + curRect.maxX) / 2;
70
+ let curMidY = (curRect.y + curRect.maxY) / 2;
71
+ let dist = Math.pow(targetMidX - curMidX, 2) + Math.pow(targetMidY - curMidY, 2);
72
+ if (dist < bestDistance) {
73
+ best = cur;
74
+ bestDistance = dist;
75
+ }
76
+ }
77
+ return best;
78
+ }
79
+ _findClosest(target, rect) {
80
+ let best = this._findClosestLayoutInfo(target, rect);
81
+ return best || null;
82
+ }
83
+ getKeyBelow(key) {
84
+ var _this__findClosest, _getFirstItem;
85
+ // Expected key is the currently focused cell so we need the parent row key
86
+ let parentRowKey = this.collection.getItem(key).parentKey;
87
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
88
+ let rect = new (0, $kQhHy$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, layoutInfo.rect.maxY + 1, layoutInfo.rect.width, this.virtualizer.visibleRect.height);
89
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
90
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
91
+ }
92
+ getKeyAbove(key) {
93
+ var _this__findClosest, _getFirstItem;
94
+ // Expected key is the currently focused cell so we need the parent row key
95
+ let parentRowKey = this.collection.getItem(key).parentKey;
96
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
97
+ let rect = new (0, $kQhHy$reactstatelyvirtualizer.Rect)(layoutInfo.rect.x, 0, layoutInfo.rect.width, layoutInfo.rect.y - 1);
98
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
99
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
100
+ }
101
+ getKeyRightOf(key) {
102
+ // Expected key is the currently focused cell so we need the parent row key
103
+ let parentRowKey = this.collection.getItem(key).parentKey;
104
+ key = this.direction === "rtl" ? this.collection.getKeyBefore(parentRowKey) : this.collection.getKeyAfter(parentRowKey);
105
+ while(key != null){
106
+ var _getFirstItem;
107
+ let item = this.collection.getItem(key);
108
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
109
+ 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;
110
+ key = this.direction === "rtl" ? this.collection.getKeyBefore(key) : this.collection.getKeyAfter(key);
111
+ }
112
+ }
113
+ getKeyLeftOf(key) {
114
+ // Expected key is the currently focused cell so we need the parent row key
115
+ let parentRowKey = this.collection.getItem(key).parentKey;
116
+ key = this.direction === "rtl" ? this.collection.getKeyAfter(parentRowKey) : this.collection.getKeyBefore(parentRowKey);
117
+ while(key != null){
118
+ var _getFirstItem;
119
+ let item = this.collection.getItem(key);
120
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
121
+ 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;
122
+ key = this.direction === "rtl" ? this.collection.getKeyAfter(key) : this.collection.getKeyBefore(key);
123
+ }
124
+ }
125
+ getFirstKey() {
126
+ var _getFirstItem;
127
+ let firstRow = this.collection.getItem(this.collection.getFirstKey());
128
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(firstRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
129
+ }
130
+ getLastKey() {
131
+ var _getFirstItem;
132
+ let lastRow = this.collection.getItem(this.collection.getLastKey());
133
+ return (_getFirstItem = (0, $kQhHy$reactstatelycollections.getFirstItem)((0, $kQhHy$reactstatelycollections.getChildNodes)(lastRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
134
+ }
135
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
136
+ // 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?
137
+ getKeyPageAbove(key) {
138
+ // Expected key is the currently focused cell so we need the parent row key
139
+ let parentRowKey = this.collection.getItem(key).parentKey;
140
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
141
+ if (layoutInfo) {
142
+ var _this_collection_getItem;
143
+ let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);
144
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately above
145
+ // Otherwise keep going up until we exceed a single page height worth of nodes
146
+ let keyAbove = (_this_collection_getItem = this.collection.getItem(this.getKeyAbove(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
147
+ layoutInfo = this.getLayoutInfo(keyAbove);
148
+ if (layoutInfo && layoutInfo.rect.y > pageY) while(layoutInfo && layoutInfo.rect.y > pageY){
149
+ var _getFirstItem, _this_collection_getItem1;
150
+ 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;
151
+ let keyAbove = (_this_collection_getItem1 = this.collection.getItem(this.getKeyAbove(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
152
+ layoutInfo = this.getLayoutInfo(keyAbove);
153
+ }
154
+ if (layoutInfo) {
155
+ var _getFirstItem1;
156
+ 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;
157
+ return childKey;
158
+ }
159
+ }
160
+ return this.getFirstKey();
161
+ }
162
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
163
+ // Perhaps have layoutInfo store childKey as well so we don't need to do this?
164
+ getKeyPageBelow(key) {
165
+ // Expected key is the currently focused cell so we need the parent row key
166
+ let parentRowKey = this.collection.getItem(key).parentKey;
167
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
168
+ if (layoutInfo) {
169
+ var _this_collection_getItem;
170
+ let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);
171
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately below
172
+ // Otherwise keep going up until we exceed a single page height worth of nodes
173
+ let keyBelow = (_this_collection_getItem = this.collection.getItem(this.getKeyBelow(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
174
+ layoutInfo = this.getLayoutInfo(keyBelow);
175
+ if (layoutInfo && layoutInfo.rect.y < pageY) while(layoutInfo && layoutInfo.rect.y < pageY){
176
+ var _getFirstItem, _this_collection_getItem1;
177
+ 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;
178
+ let keyBelow = (_this_collection_getItem1 = this.collection.getItem(this.getKeyBelow(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
179
+ layoutInfo = this.getLayoutInfo(keyBelow);
180
+ }
181
+ if (layoutInfo) {
182
+ var _getFirstItem1;
183
+ 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;
184
+ return childKey;
185
+ }
186
+ }
187
+ return this.getLastKey();
188
+ }
189
+ getKeyForSearch(search, fromKey) {
190
+ if (!this.collator) return null;
191
+ let collection = this.collection;
192
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
193
+ let startItem = collection.getItem(key);
194
+ key = startItem.parentKey;
195
+ while(key != null){
196
+ let item = collection.getItem(key);
197
+ if (item.textValue) {
198
+ var _getFirstItem;
199
+ let substring = item.textValue.slice(0, search.length);
200
+ 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;
201
+ }
202
+ key = this.collection.getKeyAfter(key);
203
+ }
204
+ return null;
205
+ }
206
+ constructor(options = {}){
207
+ super();
208
+ this.disabledKeys = new Set();
209
+ this.layoutInfos = new Map();
210
+ this.collator = options.collator;
211
+ this.lastCollection = null;
212
+ this.scale = options.scale || "medium";
213
+ this.margin = options.margin || 24;
214
+ }
215
+ }
216
+
217
+
218
+ //# sourceMappingURL=BaseLayout.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAmBM,MAAM,kDAAsB,CAAA,GAAA,qCAAK;IAqBtC,SAAS,mBAA0D,EAAE;QACnE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU;QAC7C,IAAI,CAAC,eAAe,CAAC;QAErB,0DAA0D;QAC1D,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,KAAK,IAAI,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,GACzC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAC3B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;YAI5B,IAAI,CAAC,IAAI,CAAC,SAAS,EACjB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;YAG1B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,GACzB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAE5B;QAEA,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU;IACvC;IAEA,6DAA6D;IAC7D,gBAAgB,mBAA2D,EAAE,CAAC;IAE9E,iBAAiB;QACf,OAAO,IAAI,CAAC,WAAW;IACzB;IAEA,cAAc,GAAQ,EAAE;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,GAA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Y,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;AA6OF","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\nexport class BaseLayout<T> extends Layout<Node<T>> 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 validate(invalidationContext: InvalidationContext<Node<T>, unknown>) {\n this.collection = this.virtualizer.collection as GridCollection<T>;\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<Node<T>, unknown>) {}\n\n getContentSize() {\n return this.contentSize;\n }\n\n getLayoutInfo(key: Key) {\n return this.layoutInfos.get(key);\n }\n\n getVisibleLayoutInfos(rect) {\n let res: LayoutInfo[] = [];\n\n for (let layoutInfo of this.layoutInfos.values()) {\n if (this.isVisible(layoutInfo, rect)) {\n res.push(layoutInfo);\n }\n }\n\n return res;\n }\n\n isVisible(layoutInfo: LayoutInfo, rect: Rect) {\n return layoutInfo.rect.intersects(rect);\n }\n\n getInitialLayoutInfo(layoutInfo: LayoutInfo) {\n layoutInfo.opacity = 0;\n layoutInfo.transform = 'scale3d(0.8, 0.8, 0.8)';\n return layoutInfo;\n }\n\n getFinalLayoutInfo(layoutInfo: LayoutInfo) {\n layoutInfo.opacity = 0;\n layoutInfo.transform = 'scale3d(0.8, 0.8, 0.8)';\n return layoutInfo;\n }\n\n _findClosestLayoutInfo(target: Rect, rect: Rect) {\n let layoutInfos = this.getVisibleLayoutInfos(rect);\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,213 @@
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
+ validate(invalidationContext) {
18
+ this.collection = this.virtualizer.collection;
19
+ this.buildCollection(invalidationContext);
20
+ // Remove layout info that doesn't exist in new collection
21
+ if (this.lastCollection) {
22
+ for (let key of this.lastCollection.getKeys())if (!this.collection.getItem(key)) this.layoutInfos.delete(key);
23
+ if (!this.isLoading) this.layoutInfos.delete("loader");
24
+ if (this.collection.size > 0) this.layoutInfos.delete("placeholder");
25
+ }
26
+ this.lastCollection = this.collection;
27
+ }
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ buildCollection(invalidationContext) {}
30
+ getContentSize() {
31
+ return this.contentSize;
32
+ }
33
+ getLayoutInfo(key) {
34
+ return this.layoutInfos.get(key);
35
+ }
36
+ getVisibleLayoutInfos(rect) {
37
+ let res = [];
38
+ for (let layoutInfo of this.layoutInfos.values())if (this.isVisible(layoutInfo, rect)) res.push(layoutInfo);
39
+ return res;
40
+ }
41
+ isVisible(layoutInfo, rect) {
42
+ return layoutInfo.rect.intersects(rect);
43
+ }
44
+ getInitialLayoutInfo(layoutInfo) {
45
+ layoutInfo.opacity = 0;
46
+ layoutInfo.transform = "scale3d(0.8, 0.8, 0.8)";
47
+ return layoutInfo;
48
+ }
49
+ getFinalLayoutInfo(layoutInfo) {
50
+ layoutInfo.opacity = 0;
51
+ layoutInfo.transform = "scale3d(0.8, 0.8, 0.8)";
52
+ return layoutInfo;
53
+ }
54
+ _findClosestLayoutInfo(target, rect) {
55
+ let layoutInfos = this.getVisibleLayoutInfos(rect);
56
+ let best = null;
57
+ let bestDistance = Infinity;
58
+ // Calculates distance as the distance between the center of 2 rects.
59
+ for (let cur of layoutInfos)if (cur.type === "item") {
60
+ let curRect = cur.rect;
61
+ let targetMidX = (target.x + target.maxX) / 2;
62
+ let targetMidY = (target.y + target.maxY) / 2;
63
+ let curMidX = (curRect.x + curRect.maxX) / 2;
64
+ let curMidY = (curRect.y + curRect.maxY) / 2;
65
+ let dist = Math.pow(targetMidX - curMidX, 2) + Math.pow(targetMidY - curMidY, 2);
66
+ if (dist < bestDistance) {
67
+ best = cur;
68
+ bestDistance = dist;
69
+ }
70
+ }
71
+ return best;
72
+ }
73
+ _findClosest(target, rect) {
74
+ let best = this._findClosestLayoutInfo(target, rect);
75
+ return best || null;
76
+ }
77
+ getKeyBelow(key) {
78
+ var _this__findClosest, _getFirstItem;
79
+ // Expected key is the currently focused cell so we need the parent row key
80
+ let parentRowKey = this.collection.getItem(key).parentKey;
81
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
82
+ let rect = new (0, $1JdnP$Rect)(layoutInfo.rect.x, layoutInfo.rect.maxY + 1, layoutInfo.rect.width, this.virtualizer.visibleRect.height);
83
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
84
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
85
+ }
86
+ getKeyAbove(key) {
87
+ var _this__findClosest, _getFirstItem;
88
+ // Expected key is the currently focused cell so we need the parent row key
89
+ let parentRowKey = this.collection.getItem(key).parentKey;
90
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
91
+ let rect = new (0, $1JdnP$Rect)(layoutInfo.rect.x, 0, layoutInfo.rect.width, layoutInfo.rect.y - 1);
92
+ let closestRow = this.collection.getItem((_this__findClosest = this._findClosest(layoutInfo.rect, rect)) === null || _this__findClosest === void 0 ? void 0 : _this__findClosest.key);
93
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(closestRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
94
+ }
95
+ getKeyRightOf(key) {
96
+ // Expected key is the currently focused cell so we need the parent row key
97
+ let parentRowKey = this.collection.getItem(key).parentKey;
98
+ key = this.direction === "rtl" ? this.collection.getKeyBefore(parentRowKey) : this.collection.getKeyAfter(parentRowKey);
99
+ while(key != null){
100
+ var _getFirstItem;
101
+ let item = this.collection.getItem(key);
102
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
103
+ if (item.type === "item") return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
104
+ key = this.direction === "rtl" ? this.collection.getKeyBefore(key) : this.collection.getKeyAfter(key);
105
+ }
106
+ }
107
+ getKeyLeftOf(key) {
108
+ // Expected key is the currently focused cell so we need the parent row key
109
+ let parentRowKey = this.collection.getItem(key).parentKey;
110
+ key = this.direction === "rtl" ? this.collection.getKeyAfter(parentRowKey) : this.collection.getKeyBefore(parentRowKey);
111
+ while(key != null){
112
+ var _getFirstItem;
113
+ let item = this.collection.getItem(key);
114
+ // Don't check if item is disabled because we want to be able to focus disabled items in a grid (double check this)
115
+ if (item.type === "item") return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
116
+ key = this.direction === "rtl" ? this.collection.getKeyAfter(key) : this.collection.getKeyBefore(key);
117
+ }
118
+ }
119
+ getFirstKey() {
120
+ var _getFirstItem;
121
+ let firstRow = this.collection.getItem(this.collection.getFirstKey());
122
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(firstRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
123
+ }
124
+ getLastKey() {
125
+ var _getFirstItem;
126
+ let lastRow = this.collection.getItem(this.collection.getLastKey());
127
+ return (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(lastRow, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
128
+ }
129
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
130
+ // 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?
131
+ getKeyPageAbove(key) {
132
+ // Expected key is the currently focused cell so we need the parent row key
133
+ let parentRowKey = this.collection.getItem(key).parentKey;
134
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
135
+ if (layoutInfo) {
136
+ var _this_collection_getItem;
137
+ let pageY = Math.max(0, layoutInfo.rect.y + layoutInfo.rect.height - this.virtualizer.visibleRect.height);
138
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately above
139
+ // Otherwise keep going up until we exceed a single page height worth of nodes
140
+ let keyAbove = (_this_collection_getItem = this.collection.getItem(this.getKeyAbove(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
141
+ layoutInfo = this.getLayoutInfo(keyAbove);
142
+ if (layoutInfo && layoutInfo.rect.y > pageY) while(layoutInfo && layoutInfo.rect.y > pageY){
143
+ var _getFirstItem, _this_collection_getItem1;
144
+ let childKey = (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
145
+ let keyAbove = (_this_collection_getItem1 = this.collection.getItem(this.getKeyAbove(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
146
+ layoutInfo = this.getLayoutInfo(keyAbove);
147
+ }
148
+ if (layoutInfo) {
149
+ var _getFirstItem1;
150
+ let childKey = (_getFirstItem1 = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key;
151
+ return childKey;
152
+ }
153
+ }
154
+ return this.getFirstKey();
155
+ }
156
+ // TODO: pretty unwieldy because it needs to bounce back and forth between the parent key and the child key
157
+ // Perhaps have layoutInfo store childKey as well so we don't need to do this?
158
+ getKeyPageBelow(key) {
159
+ // Expected key is the currently focused cell so we need the parent row key
160
+ let parentRowKey = this.collection.getItem(key).parentKey;
161
+ let layoutInfo = this.getLayoutInfo(parentRowKey);
162
+ if (layoutInfo) {
163
+ var _this_collection_getItem;
164
+ let pageY = Math.min(this.virtualizer.contentSize.height, layoutInfo.rect.y - layoutInfo.rect.height + this.virtualizer.visibleRect.height);
165
+ // If the node is so large that it spans multiple page heights, return the key of the item immediately below
166
+ // Otherwise keep going up until we exceed a single page height worth of nodes
167
+ let keyBelow = (_this_collection_getItem = this.collection.getItem(this.getKeyBelow(key))) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.parentKey;
168
+ layoutInfo = this.getLayoutInfo(keyBelow);
169
+ if (layoutInfo && layoutInfo.rect.y < pageY) while(layoutInfo && layoutInfo.rect.y < pageY){
170
+ var _getFirstItem, _this_collection_getItem1;
171
+ let childKey = (_getFirstItem = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key;
172
+ let keyBelow = (_this_collection_getItem1 = this.collection.getItem(this.getKeyBelow(childKey))) === null || _this_collection_getItem1 === void 0 ? void 0 : _this_collection_getItem1.parentKey;
173
+ layoutInfo = this.getLayoutInfo(keyBelow);
174
+ }
175
+ if (layoutInfo) {
176
+ var _getFirstItem1;
177
+ let childKey = (_getFirstItem1 = (0, $1JdnP$getFirstItem)((0, $1JdnP$getChildNodes)(this.collection.getItem(layoutInfo.key), this.collection))) === null || _getFirstItem1 === void 0 ? void 0 : _getFirstItem1.key;
178
+ return childKey;
179
+ }
180
+ }
181
+ return this.getLastKey();
182
+ }
183
+ getKeyForSearch(search, fromKey) {
184
+ if (!this.collator) return null;
185
+ let collection = this.collection;
186
+ let key = fromKey !== null && fromKey !== void 0 ? fromKey : this.getFirstKey();
187
+ let startItem = collection.getItem(key);
188
+ key = startItem.parentKey;
189
+ while(key != null){
190
+ let item = collection.getItem(key);
191
+ if (item.textValue) {
192
+ var _getFirstItem;
193
+ let substring = item.textValue.slice(0, search.length);
194
+ 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;
195
+ }
196
+ key = this.collection.getKeyAfter(key);
197
+ }
198
+ return null;
199
+ }
200
+ constructor(options = {}){
201
+ super();
202
+ this.disabledKeys = new Set();
203
+ this.layoutInfos = new Map();
204
+ this.collator = options.collator;
205
+ this.lastCollection = null;
206
+ this.scale = options.scale || "medium";
207
+ this.margin = options.margin || 24;
208
+ }
209
+ }
210
+
211
+
212
+ export {$3d424c147206bac9$export$64943d2e59d72a29 as BaseLayout};
213
+ //# sourceMappingURL=BaseLayout.mjs.map