@react-spectrum/card 3.0.0-alpha.4 → 3.0.0-alpha.41

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 (240) 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 +52 -0
  7. package/dist/Card.main.js.map +1 -0
  8. package/dist/Card.mjs +43 -0
  9. package/dist/Card.module.js +43 -0
  10. package/dist/Card.module.js.map +1 -0
  11. package/dist/CardBase.main.js +203 -0
  12. package/dist/CardBase.main.js.map +1 -0
  13. package/dist/CardBase.mjs +198 -0
  14. package/dist/CardBase.module.js +198 -0
  15. package/dist/CardBase.module.js.map +1 -0
  16. package/dist/CardView.main.js +238 -0
  17. package/dist/CardView.main.js.map +1 -0
  18. package/dist/CardView.mjs +233 -0
  19. package/dist/CardView.module.js +233 -0
  20. package/dist/CardView.module.js.map +1 -0
  21. package/dist/CardViewContext.main.js +32 -0
  22. package/dist/CardViewContext.main.js.map +1 -0
  23. package/dist/CardViewContext.mjs +22 -0
  24. package/dist/CardViewContext.module.js +22 -0
  25. package/dist/CardViewContext.module.js.map +1 -0
  26. package/dist/GalleryLayout.main.js +230 -0
  27. package/dist/GalleryLayout.main.js.map +1 -0
  28. package/dist/GalleryLayout.mjs +225 -0
  29. package/dist/GalleryLayout.module.js +225 -0
  30. package/dist/GalleryLayout.module.js.map +1 -0
  31. package/dist/GridLayout.main.js +175 -0
  32. package/dist/GridLayout.main.js.map +1 -0
  33. package/dist/GridLayout.mjs +170 -0
  34. package/dist/GridLayout.module.js +170 -0
  35. package/dist/GridLayout.module.js.map +1 -0
  36. package/dist/WaterfallLayout.main.js +182 -0
  37. package/dist/WaterfallLayout.main.js.map +1 -0
  38. package/dist/WaterfallLayout.mjs +177 -0
  39. package/dist/WaterfallLayout.module.js +177 -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 -1447
  148. package/dist/main.js.map +1 -1
  149. package/dist/module.js +17 -1432
  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 +38 -36
  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.02438011.css +1671 -0
  219. package/dist/vars.02438011.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 +26 -23
  231. package/src/BaseLayout.tsx +36 -32
  232. package/src/Card.tsx +1 -0
  233. package/src/CardBase.tsx +9 -11
  234. package/src/CardView.tsx +71 -51
  235. package/src/CardViewContext.tsx +1 -0
  236. package/src/GalleryLayout.tsx +4 -2
  237. package/src/GridLayout.tsx +7 -39
  238. package/src/WaterfallLayout.tsx +8 -5
  239. package/src/index.ts +10 -5
  240. package/dist/main.css +0 -1
@@ -0,0 +1,225 @@
1
+ import {BaseLayout as $3d424c147206bac9$export$64943d2e59d72a29} from "./BaseLayout.module.js";
2
+ import {Size as $lQvIB$Size, Rect as $lQvIB$Rect, LayoutInfo as $lQvIB$LayoutInfo} from "@react-stately/virtualizer";
3
+
4
+ // @ts-nocheck
5
+ /*
6
+ * Copyright 2021 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+ const $c0ba81539c443916$var$DEFAULT_OPTIONS = {
18
+ S: {
19
+ idealRowHeight: 112,
20
+ minItemSize: new (0, $lQvIB$Size)(96, 96),
21
+ itemSpacing: new (0, $lQvIB$Size)(8, 16),
22
+ itemPadding: 24,
23
+ dropSpacing: 50,
24
+ margin: 8
25
+ },
26
+ L: {
27
+ idealRowHeight: 208,
28
+ minItemSize: new (0, $lQvIB$Size)(136, 136),
29
+ itemSpacing: new (0, $lQvIB$Size)(18, 18),
30
+ itemPadding: {
31
+ 'medium': 78,
32
+ 'large': 99
33
+ },
34
+ dropSpacing: 100,
35
+ margin: 24
36
+ }
37
+ };
38
+ class $c0ba81539c443916$export$8e52095834484b61 extends (0, $3d424c147206bac9$export$64943d2e59d72a29) {
39
+ get layoutType() {
40
+ return 'gallery';
41
+ }
42
+ /**
43
+ * Takes a row of widths and if there are any widths smaller than the min-width, leech width starting from
44
+ * the widest in the row until it can't give anymore, then move to the second widest and so forth.
45
+ * Do this until all assets meet the min-width.
46
+ * */ _distributeWidths(widths) {
47
+ // create a copy of the widths array and sort it largest to smallest
48
+ let sortedWidths = widths.concat().sort((a, b)=>a[1] > b[1] ? -1 : 1);
49
+ for (let width of widths)// for each width, if it's smaller than the min width
50
+ if (width[1] < this.minItemSize.width) {
51
+ // then figure out how much smaller
52
+ let delta = this.minItemSize.width - width[1];
53
+ for (let item of sortedWidths)// go from the largest width in the row to the smallest
54
+ // if the width is greater than the min width
55
+ if (widths[item[0]][1] > this.minItemSize.width) {
56
+ // subtract the delta from the width, if it's still greater than the min width
57
+ // then we have finished, subtract the delta permanently from that width
58
+ // eslint-disable-next-line max-depth
59
+ if (widths[item[0]][1] - delta > this.minItemSize.width) {
60
+ widths[item[0]][1] -= delta;
61
+ delta = 0;
62
+ break;
63
+ } else {
64
+ // otherwise, we take as much as we can from the current width and then move on to
65
+ // the next largest and take some width from it
66
+ let maxChange = widths[item[0]][1] - this.minItemSize.width;
67
+ delta -= maxChange;
68
+ widths[item[0]][1] -= maxChange;
69
+ }
70
+ }
71
+ if (delta > 0) return false;
72
+ // force the width to be the min width that we just rebalanced for
73
+ width[1] = this.minItemSize.width;
74
+ }
75
+ return true;
76
+ }
77
+ buildCollection() {
78
+ let visibleWidth = this.virtualizer.visibleRect.width;
79
+ let visibleHeight = this.virtualizer.visibleRect.height;
80
+ let y = this.margin;
81
+ let availableWidth = visibleWidth - this.margin * 2;
82
+ // If available width is not greater than 0, skip node layout calculations
83
+ if (availableWidth > 0) {
84
+ // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.
85
+ let ratios = [];
86
+ let totalWidth = 0;
87
+ let minRatio = this.minItemSize.width / this.minItemSize.height;
88
+ let maxRatio = availableWidth / this.minItemSize.height;
89
+ for (let node of this.collection){
90
+ let ratio = node.props.width / node.props.height;
91
+ if (ratio < minRatio) ratio = minRatio;
92
+ else if (ratio > maxRatio && ratio !== minRatio) ratio = maxRatio;
93
+ let itemWidth = ratio * this.minItemSize.height;
94
+ ratios.push(ratio);
95
+ totalWidth += itemWidth;
96
+ }
97
+ totalWidth += this.itemSpacing.width * (this.collection.size - 1);
98
+ // Determine how many rows we'll need, and partition the items into rows
99
+ // using the aspect ratios as weights.
100
+ let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
101
+ // if the available width can't hold two items, then every item will get its own row
102
+ // this leads to a faster run through linear partition and more dependable output for small row widths
103
+ if (availableWidth <= this.minItemSize.width * 2 + this.itemPadding * 2) rows = this.collection.size;
104
+ let weightedRatios = ratios.map((ratio)=>ratio < this.threshold ? ratio + 0.5 * (1 / ratio) : ratio);
105
+ let partition = $c0ba81539c443916$var$linearPartition(weightedRatios, rows);
106
+ let index = 0;
107
+ for (let row of partition){
108
+ // Compute the total weight for this row
109
+ let totalWeight = 0;
110
+ for(let j = index; j < index + row.length; j++)totalWeight += ratios[j];
111
+ // Determine the row height based on the total available width and weight of this row.
112
+ let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;
113
+ // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height
114
+ // probably doing this because if the last row has one extremely tall image, then the row becomes huge
115
+ // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
116
+ if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) bestRowHeight = this.idealRowHeight;
117
+ let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
118
+ let x = this.margin;
119
+ // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
120
+ let widths = [];
121
+ for(let j = index; j < index + row.length; j++){
122
+ let width = Math.round(bestRowHeight * ratios[j]);
123
+ widths.push([
124
+ j - index,
125
+ width
126
+ ]);
127
+ }
128
+ this._distributeWidths(widths);
129
+ // Create items for this row.
130
+ for(let j = index; j < index + row.length; j++){
131
+ let node = this.collection.rows[j];
132
+ let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);
133
+ let rect = new (0, $lQvIB$Rect)(x, y, itemWidth, itemHeight);
134
+ let layoutInfo = new (0, $lQvIB$LayoutInfo)(node.type, node.key, rect);
135
+ layoutInfo.allowOverflow = true;
136
+ this.layoutInfos.set(node.key, layoutInfo);
137
+ x += itemWidth + this.itemSpacing.width;
138
+ }
139
+ y += itemHeight + this.itemSpacing.height;
140
+ index += row.length;
141
+ }
142
+ if (this.isLoading) {
143
+ let loaderY = y;
144
+ let loaderHeight = 60;
145
+ // If there aren't any items, make loader take all available room and remove margin from y calculation
146
+ // so it doesn't scroll
147
+ if (this.collection.size === 0) {
148
+ loaderY = 0;
149
+ loaderHeight = visibleHeight || 60;
150
+ }
151
+ let rect = new (0, $lQvIB$Rect)(0, loaderY, visibleWidth, loaderHeight);
152
+ let loader = new (0, $lQvIB$LayoutInfo)('loader', 'loader', rect);
153
+ this.layoutInfos.set('loader', loader);
154
+ y = loader.rect.maxY;
155
+ }
156
+ if (this.collection.size === 0 && !this.isLoading) {
157
+ let rect = new (0, $lQvIB$Rect)(0, 0, visibleWidth, visibleHeight);
158
+ let placeholder = new (0, $lQvIB$LayoutInfo)('placeholder', 'placeholder', rect);
159
+ this.layoutInfos.set('placeholder', placeholder);
160
+ y = placeholder.rect.maxY;
161
+ }
162
+ }
163
+ this.contentSize = new (0, $lQvIB$Size)(visibleWidth, y);
164
+ }
165
+ constructor(options = {}){
166
+ super(options);
167
+ let cardSize = 'L';
168
+ this.idealRowHeight = options.idealRowHeight || $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].idealRowHeight;
169
+ this.itemSpacing = options.itemSpacing || $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].itemSpacing;
170
+ this.itemPadding = options.itemPadding != null ? options.itemPadding : $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].itemPadding[this.scale];
171
+ this.minItemSize = options.minItemSize || $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].minItemSize;
172
+ this.threshold = options.threshold || 1;
173
+ this.margin = options.margin != null ? options.margin : $c0ba81539c443916$var$DEFAULT_OPTIONS[cardSize].margin;
174
+ }
175
+ }
176
+ // https://www8.cs.umu.se/kurser/TDBA77/VT06/algorithms/BOOK/BOOK2/NODE45.HTM
177
+ function $c0ba81539c443916$var$linearPartition(seq, k) {
178
+ let n = seq.length;
179
+ if (k <= 0) return [];
180
+ if (k >= n) return seq.map((x)=>[
181
+ x
182
+ ]);
183
+ if (n === 1) return [
184
+ seq
185
+ ];
186
+ let table = Array(n).fill(0).map(()=>Array(k).fill(0));
187
+ let solution = Array(n - 1).fill(0).map(()=>Array(k - 1).fill(0));
188
+ for(let i = 0; i < n; i++)table[i][0] = seq[i] + (i > 0 ? table[i - 1][0] : 0);
189
+ for(let i = 0; i < k; i++)table[0][i] = seq[0];
190
+ for(let i = 1; i < n; i++)for(let j = 1; j < k; j++){
191
+ let currentMin = 0;
192
+ let minX = Infinity;
193
+ for(let x = 0; x < i; x++){
194
+ let c1 = table[x][j - 1];
195
+ let c2 = table[i][0] - table[x][0];
196
+ let cost = Math.max(c1, c2);
197
+ if (!x || cost < currentMin) {
198
+ currentMin = cost;
199
+ minX = x;
200
+ }
201
+ }
202
+ table[i][j] = currentMin;
203
+ solution[i - 1][j - 1] = minX;
204
+ }
205
+ n = n - 1;
206
+ k = k - 2;
207
+ let result = [];
208
+ while(k >= 0){
209
+ if (n >= 1) {
210
+ let row = [];
211
+ for(let i = solution[n - 1][k] + 1; i < n + 1; i++)row.push(seq[i]);
212
+ result.unshift(row);
213
+ n = solution[n - 1][k];
214
+ }
215
+ k--;
216
+ }
217
+ let row = [];
218
+ for(let i = 0; i < n + 1; i++)row.push(seq[i]);
219
+ result.unshift(row);
220
+ return result;
221
+ }
222
+
223
+
224
+ export {$c0ba81539c443916$export$8e52095834484b61 as GalleryLayout};
225
+ //# sourceMappingURL=GalleryLayout.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA,cAAc;AACd;;;;;;;;;;CAUC;;AAsCD,MAAM,wCAAkB;IACtB,GAAG;QACD,gBAAgB;QAChB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;QAC1B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,GAAG;QACzB,aAAa;QACb,aAAa;QACb,QAAQ;IACV;IACA,GAAG;QACD,gBAAgB;QAChB,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,KAAK;QAC3B,aAAa,IAAI,CAAA,GAAA,WAAG,EAAE,IAAI;QAC1B,aAAa;YACX,UAAU;YACV,SAAS;QACX;QACA,aAAa;QACb,QAAQ;IACV;AACF;AAEO,MAAM,kDAAyB,CAAA,GAAA,yCAAS;IAkB7C,IAAI,aAAa;QACf,OAAO;IACT;IAEA;;;;KAIG,GACH,kBAAkB,MAAM,EAAE;QACxB,oEAAoE;QACpE,IAAI,eAAe,OAAO,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,IAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK;QACrE,KAAK,IAAI,SAAS,OAChB,qDAAqD;QACrD,IAAI,KAAK,CAAC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GAAG,CAAC,IAAI;YAExB,IAAI,CAAC,KAAK,OAAO,YAAY;gBAC3B,aAAa;gBACb,OAAO;YACT;QACF;QAEA,KAAK,CAAC,EAAE,CAAC,EAAE,GAAG;QACd,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG;IAC3B;IAGF,IAAI,IAAI;IACR,IAAI,IAAI;IAER,IAAI,SAAS,EAAE;IACf,MAAO,KAAK,EAAG;QACb,IAAI,KAAK,GAAG;YACV,IAAI,MAAM,EAAE;YACZ,IAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,IAC9C,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;YAGjB,OAAO,OAAO,CAAC;YACf,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE;QACxB;QAEA;IACF;IAEA,IAAI,MAAM,EAAE;IACZ,IAAK,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,IACzB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;IAGjB,OAAO,OAAO,CAAC;IAEf,OAAO;AACT","sources":["packages/@react-spectrum/card/src/GalleryLayout.tsx"],"sourcesContent":["// @ts-nocheck\n/*\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 {BaseLayout, BaseLayoutOptions} from './BaseLayout';\nimport {LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GalleryLayoutOptions extends BaseLayoutOptions {\n // /**\n // * The card size in the grid.\n // */\n // cardSize?: 'S' | 'M' | 'L',\n /**\n * The the default row height. Note this must be larger than the min item height.\n * @default 208\n */\n idealRowHeight?: number,\n /**\n * The spacing between items.\n * @default 18 x 18\n */\n itemSpacing?: Size,\n /**\n * The vertical padding for an item.\n * @default 78\n */\n itemPadding?: number,\n /**\n * Minimum size for a item in the grid.\n * @default 136 x 136\n */\n minItemSize?: Size,\n /**\n * Target for adding extra weight to elements during linear partitioning. Anything with an aspect ratio smaler than this value\n * will be targeted.\n * @type {number}\n */\n threshold?: number\n}\n\nconst DEFAULT_OPTIONS = {\n S: {\n idealRowHeight: 112,\n minItemSize: new Size(96, 96),\n itemSpacing: new Size(8, 16),\n itemPadding: 24,\n dropSpacing: 50,\n margin: 8\n },\n L: {\n idealRowHeight: 208,\n minItemSize: new Size(136, 136),\n itemSpacing: new Size(18, 18),\n itemPadding: {\n 'medium': 78,\n 'large': 99\n },\n dropSpacing: 100,\n margin: 24\n }\n};\n\nexport class GalleryLayout<T> extends BaseLayout<T> {\n protected idealRowHeight: number;\n protected itemSpacing: Size;\n itemPadding: number;\n protected minItemSize: Size;\n protected threshold: number;\n\n constructor(options: GalleryLayoutOptions = {}) {\n super(options);\n let cardSize = 'L';\n this.idealRowHeight = options.idealRowHeight || DEFAULT_OPTIONS[cardSize].idealRowHeight;\n this.itemSpacing = options.itemSpacing || DEFAULT_OPTIONS[cardSize].itemSpacing;\n this.itemPadding = options.itemPadding != null ? options.itemPadding : DEFAULT_OPTIONS[cardSize].itemPadding[this.scale];\n this.minItemSize = options.minItemSize || DEFAULT_OPTIONS[cardSize].minItemSize;\n this.threshold = options.threshold || 1;\n this.margin = options.margin != null ? options.margin : DEFAULT_OPTIONS[cardSize].margin;\n }\n\n get layoutType() {\n return 'gallery';\n }\n\n /**\n * Takes a row of widths and if there are any widths smaller than the min-width, leech width starting from\n * the widest in the row until it can't give anymore, then move to the second widest and so forth.\n * Do this until all assets meet the min-width.\n * */\n _distributeWidths(widths) {\n // create a copy of the widths array and sort it largest to smallest\n let sortedWidths = widths.concat().sort((a, b) => a[1] > b[1] ? -1 : 1);\n for (let width of widths) {\n // for each width, if it's smaller than the min width\n if (width[1] < this.minItemSize.width) {\n // then figure out how much smaller\n let delta = this.minItemSize.width - width[1];\n for (let item of sortedWidths) {\n // go from the largest width in the row to the smallest\n // if the width is greater than the min width\n if (widths[item[0]][1] > this.minItemSize.width) {\n // subtract the delta from the width, if it's still greater than the min width\n // then we have finished, subtract the delta permanently from that width\n // eslint-disable-next-line max-depth\n if (widths[item[0]][1] - delta > this.minItemSize.width) {\n widths[item[0]][1] -= delta;\n delta = 0;\n break;\n } else {\n // otherwise, we take as much as we can from the current width and then move on to\n // the next largest and take some width from it\n let maxChange = widths[item[0]][1] - this.minItemSize.width;\n delta -= maxChange;\n widths[item[0]][1] -= maxChange;\n }\n }\n }\n if (delta > 0) {\n return false;\n }\n // force the width to be the min width that we just rebalanced for\n width[1] = this.minItemSize.width;\n }\n }\n return true;\n }\n\n buildCollection() {\n let visibleWidth = this.virtualizer.visibleRect.width;\n let visibleHeight = this.virtualizer.visibleRect.height;\n let y = this.margin;\n let availableWidth = visibleWidth - this.margin * 2;\n\n // If available width is not greater than 0, skip node layout calculations\n if (availableWidth > 0) {\n // Compute aspect ratios for all of the items, and the total width if all items were on in a single row.\n let ratios = [];\n let totalWidth = 0;\n let minRatio = this.minItemSize.width / this.minItemSize.height;\n let maxRatio = availableWidth / this.minItemSize.height;\n\n for (let node of this.collection) {\n let ratio = node.props.width / node.props.height;\n if (ratio < minRatio) {\n ratio = minRatio;\n } else if (ratio > maxRatio && ratio !== minRatio) {\n ratio = maxRatio;\n }\n\n let itemWidth = ratio * this.minItemSize.height;\n ratios.push(ratio);\n totalWidth += itemWidth;\n }\n\n totalWidth += this.itemSpacing.width * (this.collection.size - 1);\n\n // Determine how many rows we'll need, and partition the items into rows\n // using the aspect ratios as weights.\n let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));\n // if the available width can't hold two items, then every item will get its own row\n // this leads to a faster run through linear partition and more dependable output for small row widths\n if (availableWidth <= (this.minItemSize.width * 2) + (this.itemPadding * 2)) {\n rows = this.collection.size;\n }\n\n let weightedRatios = ratios.map(ratio => ratio < this.threshold ? ratio + (0.5 * (1 / ratio)) : ratio);\n let partition = linearPartition(weightedRatios, rows);\n\n let index = 0;\n for (let row of partition) {\n // Compute the total weight for this row\n let totalWeight = 0;\n for (let j = index; j < index + row.length; j++) {\n totalWeight += ratios[j];\n }\n\n // Determine the row height based on the total available width and weight of this row.\n let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;\n\n // if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height\n // probably doing this because if the last row has one extremely tall image, then the row becomes huge\n // though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters\n if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) {\n bestRowHeight = this.idealRowHeight;\n }\n let itemHeight = Math.round(bestRowHeight) + this.itemPadding;\n let x = this.margin;\n\n // if any items are going to end up too small, add a bit of width to them and subtract it from wider objects\n let widths = [];\n for (let j = index; j < index + row.length; j++) {\n let width = Math.round(bestRowHeight * ratios[j]);\n widths.push([j - index, width]);\n }\n this._distributeWidths(widths);\n\n // Create items for this row.\n for (let j = index; j < index + row.length; j++) {\n let node = this.collection.rows[j];\n let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);\n let rect = new Rect(x, y, itemWidth, itemHeight);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.allowOverflow = true;\n this.layoutInfos.set(node.key, layoutInfo);\n x += itemWidth + this.itemSpacing.width;\n }\n\n y += itemHeight + this.itemSpacing.height;\n index += row.length;\n }\n\n if (this.isLoading) {\n let loaderY = y;\n let loaderHeight = 60;\n // If there aren't any items, make loader take all available room and remove margin from y calculation\n // so it doesn't scroll\n if (this.collection.size === 0) {\n loaderY = 0;\n loaderHeight = visibleHeight || 60;\n }\n\n let rect = new Rect(0, loaderY, visibleWidth, loaderHeight);\n let loader = new LayoutInfo('loader', 'loader', rect);\n this.layoutInfos.set('loader', loader);\n y = loader.rect.maxY;\n }\n\n if (this.collection.size === 0 && !this.isLoading) {\n let rect = new Rect(0, 0, visibleWidth, visibleHeight);\n let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);\n this.layoutInfos.set('placeholder', placeholder);\n y = placeholder.rect.maxY;\n }\n }\n this.contentSize = new Size(visibleWidth, y);\n }\n}\n\n// https://www8.cs.umu.se/kurser/TDBA77/VT06/algorithms/BOOK/BOOK2/NODE45.HTM\nfunction linearPartition(seq, k) {\n let n = seq.length;\n if (k <= 0) {\n return [];\n }\n\n if (k >= n) {\n return seq.map(x => [x]);\n }\n\n if (n === 1) {\n return [seq];\n }\n\n let table = Array(n).fill(0).map(() => Array(k).fill(0));\n let solution = Array(n - 1).fill(0).map(() => Array(k - 1).fill(0));\n\n for (let i = 0; i < n; i++) {\n table[i][0] = seq[i] + (i > 0 ? table[i - 1][0] : 0);\n }\n\n for (let i = 0; i < k; i++) {\n table[0][i] = seq[0];\n }\n\n for (let i = 1; i < n; i++) {\n for (let j = 1; j < k; j++) {\n let currentMin = 0;\n let minX = Infinity;\n\n for (let x = 0; x < i; x++) {\n let c1 = table[x][j - 1];\n let c2 = table[i][0] - table[x][0];\n let cost = Math.max(c1, c2);\n\n if (!x || cost < currentMin) {\n currentMin = cost;\n minX = x;\n }\n }\n\n table[i][j] = currentMin;\n solution[i - 1][j - 1] = minX;\n }\n }\n\n n = n - 1;\n k = k - 2;\n\n let result = [];\n while (k >= 0) {\n if (n >= 1) {\n let row = [];\n for (let i = solution[n - 1][k] + 1; i < n + 1; i++) {\n row.push(seq[i]);\n }\n\n result.unshift(row);\n n = solution[n - 1][k];\n }\n\n k--;\n }\n\n let row = [];\n for (let i = 0; i < n + 1; i++) {\n row.push(seq[i]);\n }\n\n result.unshift(row);\n\n return result;\n}\n"],"names":[],"version":3,"file":"GalleryLayout.module.js.map"}
@@ -0,0 +1,175 @@
1
+ var $5ee605f09afaa4de$exports = require("./BaseLayout.main.js");
2
+ var $fkKx7$reactstatelycollections = require("@react-stately/collections");
3
+ var $fkKx7$reactstatelyvirtualizer = require("@react-stately/virtualizer");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "GridLayout", () => $71b727f94b595b1a$export$7d2b12578154a735);
11
+ // @ts-nocheck
12
+ /*
13
+ * Copyright 2021 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+ const $71b727f94b595b1a$var$DEFAULT_OPTIONS = {
26
+ S: {
27
+ itemPadding: 20,
28
+ minItemSize: {
29
+ 'vertical': new (0, $fkKx7$reactstatelyvirtualizer.Size)(96, 96)
30
+ },
31
+ maxItemSize: new (0, $fkKx7$reactstatelyvirtualizer.Size)(Infinity, Infinity),
32
+ margin: 8,
33
+ minSpace: new (0, $fkKx7$reactstatelyvirtualizer.Size)(6, 6),
34
+ maxColumns: Infinity,
35
+ dropSpacing: 50
36
+ },
37
+ L: {
38
+ itemPadding: {
39
+ 'vertical': {
40
+ 'medium': 78,
41
+ 'large': 98
42
+ },
43
+ 'horizontal': {
44
+ 'medium': 150,
45
+ 'large': 170
46
+ }
47
+ },
48
+ minItemSize: {
49
+ 'vertical': new (0, $fkKx7$reactstatelyvirtualizer.Size)(208, 208),
50
+ 'horizontal': new (0, $fkKx7$reactstatelyvirtualizer.Size)(102, 102)
51
+ },
52
+ maxItemSize: new (0, $fkKx7$reactstatelyvirtualizer.Size)(Infinity, Infinity),
53
+ margin: 24,
54
+ minSpace: new (0, $fkKx7$reactstatelyvirtualizer.Size)(18, 18),
55
+ maxColumns: Infinity,
56
+ dropSpacing: 100
57
+ }
58
+ };
59
+ class $71b727f94b595b1a$export$7d2b12578154a735 extends (0, $5ee605f09afaa4de$exports.BaseLayout) {
60
+ get layoutType() {
61
+ return 'grid';
62
+ }
63
+ getIndexAtPoint(x, y, allowInsertingAtEnd = false) {
64
+ let itemHeight = this.itemSize.height + this.minSpace.height;
65
+ let itemWidth = this.itemSize.width + this.horizontalSpacing;
66
+ return Math.max(0, Math.min(this.collection.size - (allowInsertingAtEnd ? 0 : 1), Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
67
+ }
68
+ buildCollection() {
69
+ let visibleWidth = this.virtualizer.visibleRect.width;
70
+ let visibleHeight = this.virtualizer.visibleRect.height;
71
+ let horizontalItemPadding = this.cardOrientation === 'horizontal' ? this.itemPadding : 0;
72
+ let verticalItemPadding = this.cardOrientation === 'vertical' ? this.itemPadding : 0;
73
+ let minCardWidth = this.minItemSize.width + horizontalItemPadding;
74
+ // Compute the number of rows and columns needed to display the content
75
+ let availableWidth = visibleWidth - this.margin * 2;
76
+ let columns = Math.floor((availableWidth + this.minSpace.width) / (minCardWidth + this.minSpace.width));
77
+ this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));
78
+ this.numRows = Math.ceil(this.collection.size / this.numColumns);
79
+ // Compute the available width (minus the space between items)
80
+ let width = availableWidth - this.minSpace.width * Math.max(0, this.numColumns - 1);
81
+ // Compute the item width based on the space available
82
+ let itemWidth = Math.floor(width / this.numColumns);
83
+ itemWidth = Math.max(minCardWidth, Math.min(this.maxItemSize.width, itemWidth));
84
+ // Compute the item height, which is proportional to the item width
85
+ let t = (itemWidth - minCardWidth) / minCardWidth;
86
+ let itemHeight = Math.floor(this.minItemSize.height + this.minItemSize.height * t);
87
+ itemHeight = Math.max(this.minItemSize.height, Math.min(this.maxItemSize.height, itemHeight)) + verticalItemPadding;
88
+ this.itemSize = new (0, $fkKx7$reactstatelyvirtualizer.Size)(itemWidth, itemHeight);
89
+ // Compute the horizontal spacing and content height
90
+ this.horizontalSpacing = this.numColumns < 2 ? 0 : Math.floor((availableWidth - this.numColumns * this.itemSize.width) / (this.numColumns - 1));
91
+ let y = this.margin;
92
+ let index = 0;
93
+ for (let node of this.collection){
94
+ let layoutInfo = this.buildChild(node, y, index);
95
+ y = layoutInfo.rect.maxY;
96
+ index++;
97
+ }
98
+ if (this.isLoading) {
99
+ let loaderY = y;
100
+ let loaderHeight = 60;
101
+ // If there aren't any items, make loader take all avaliable room and remove margin from y calculation
102
+ // so it doesn't scroll
103
+ if (this.collection.size === 0) {
104
+ loaderY = 0;
105
+ loaderHeight = visibleHeight || 60;
106
+ }
107
+ let rect = new (0, $fkKx7$reactstatelyvirtualizer.Rect)(0, loaderY, visibleWidth, loaderHeight);
108
+ let loader = new (0, $fkKx7$reactstatelyvirtualizer.LayoutInfo)('loader', 'loader', rect);
109
+ this.layoutInfos.set('loader', loader);
110
+ y = loader.rect.maxY;
111
+ }
112
+ if (this.collection.size === 0 && !this.isLoading) {
113
+ let rect = new (0, $fkKx7$reactstatelyvirtualizer.Rect)(0, 0, visibleWidth, visibleHeight);
114
+ let placeholder = new (0, $fkKx7$reactstatelyvirtualizer.LayoutInfo)('placeholder', 'placeholder', rect);
115
+ this.layoutInfos.set('placeholder', placeholder);
116
+ y = placeholder.rect.maxY;
117
+ }
118
+ this.contentSize = new (0, $fkKx7$reactstatelyvirtualizer.Size)(visibleWidth, y);
119
+ }
120
+ buildChild(node, y, index) {
121
+ let row = Math.floor(index / this.numColumns);
122
+ let column = index % this.numColumns;
123
+ let x = this.margin + column * (this.itemSize.width + this.horizontalSpacing);
124
+ y = this.margin + row * (this.itemSize.height + this.minSpace.height);
125
+ let rect = new (0, $fkKx7$reactstatelyvirtualizer.Rect)(x, y, this.itemSize.width, this.itemSize.height);
126
+ // TODO: Perhaps have it so that the child key for each row is stored with the layoutInfo?
127
+ let layoutInfo = new (0, $fkKx7$reactstatelyvirtualizer.LayoutInfo)(node.type, node.key, rect);
128
+ layoutInfo.allowOverflow = true;
129
+ this.layoutInfos.set(node.key, layoutInfo);
130
+ return layoutInfo;
131
+ }
132
+ // Since the collection doesn't represent the visual layout, need to calculate what row and column the current key is in,
133
+ // then return the key that occupies the row + column below. This can be done by figuring out how many cards exist per column then dividing the
134
+ // collection contents by that number (which will give us the row distribution)
135
+ getKeyBelow(key) {
136
+ var _getFirstItem;
137
+ // Expected key is the currently focused cell so we need the parent row key
138
+ let parentRowKey = this.collection.getItem(key).parentKey;
139
+ let indexRowBelow;
140
+ let index = this.collection.rows.findIndex((card)=>card.key === parentRowKey);
141
+ if (index !== -1) indexRowBelow = index + this.numColumns;
142
+ else return null;
143
+ let row = this.collection.rows[indexRowBelow];
144
+ return row ? (_getFirstItem = (0, $fkKx7$reactstatelycollections.getFirstItem)((0, $fkKx7$reactstatelycollections.getChildNodes)(row, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key : null;
145
+ }
146
+ getKeyAbove(key) {
147
+ var _getFirstItem;
148
+ // Expected key is the currently focused cell so we need the parent row key
149
+ let parentRowKey = this.collection.getItem(key).parentKey;
150
+ let indexRowAbove;
151
+ let index = this.collection.rows.findIndex((card)=>card.key === parentRowKey);
152
+ if (index !== -1) indexRowAbove = index - this.numColumns;
153
+ else return null;
154
+ let row = this.collection.rows[indexRowAbove];
155
+ return row ? (_getFirstItem = (0, $fkKx7$reactstatelycollections.getFirstItem)((0, $fkKx7$reactstatelycollections.getChildNodes)(row, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key : null;
156
+ }
157
+ constructor(options = {}){
158
+ super(options);
159
+ let cardSize = 'L';
160
+ this.cardOrientation = options.cardOrientation || 'vertical';
161
+ this.minItemSize = options.minItemSize || $71b727f94b595b1a$var$DEFAULT_OPTIONS[cardSize].minItemSize[this.cardOrientation];
162
+ this.maxItemSize = options.maxItemSize || $71b727f94b595b1a$var$DEFAULT_OPTIONS[cardSize].maxItemSize;
163
+ this.margin = options.margin != null ? options.margin : $71b727f94b595b1a$var$DEFAULT_OPTIONS[cardSize].margin;
164
+ this.minSpace = options.minSpace || $71b727f94b595b1a$var$DEFAULT_OPTIONS[cardSize].minSpace;
165
+ this.maxColumns = options.maxColumns || $71b727f94b595b1a$var$DEFAULT_OPTIONS[cardSize].maxColumns;
166
+ this.itemPadding = options.itemPadding != null ? options.itemPadding : $71b727f94b595b1a$var$DEFAULT_OPTIONS[cardSize].itemPadding[this.cardOrientation][this.scale];
167
+ this.itemSize = null;
168
+ this.numColumns = 0;
169
+ this.numRows = 0;
170
+ this.horizontalSpacing = 0;
171
+ }
172
+ }
173
+
174
+
175
+ //# sourceMappingURL=GridLayout.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA,cAAc;AACd;;;;;;;;;;CAUC;;;AA4CD,MAAM,wCAAkB;IACtB,GAAG;QACD,aAAa;QACb,aAAa;YACX,YAAY,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QAC3B;QACA,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;QAChC,QAAQ;QACR,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,GAAG;QACtB,YAAY;QACZ,aAAa;IACf;IACA,GAAG;QACD,aAAa;YACX,YAAY;gBACV,UAAU;gBACV,SAAS;YACX;YACA,cAAc;gBACZ,UAAU;gBACV,SAAS;YACX;QACF;QACA,aAAa;YACX,YAAY,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;YAC1B,cAAc,IAAI,CAAA,GAAA,mCAAG,EAAE,KAAK;QAC9B;QACA,aAAa,IAAI,CAAA,GAAA,mCAAG,EAAE,UAAU;QAChC,QAAQ;QACR,UAAU,IAAI,CAAA,GAAA,mCAAG,EAAE,IAAI;QACvB,YAAY;QACZ,aAAa;IACf;AACF;AAEO,MAAM,kDAAsB,CAAA,GAAA,oCAAS;IA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A1IA,YAAY,UAA6B,CAAC,CAAC,CAAE;QAC3C,KAAK,CAAC;QACN,IAAI,WAAW;QACf,IAAI,CAAC,eAAe,GAAG,QAAQ,eAAe,IAAI;QAClD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,qCAAe,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC;QACrG,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,qCAAe,CAAC,SAAS,CAAC,WAAW;QAC/E,IAAI,CAAC,MAAM,GAAG,QAAQ,MAAM,IAAI,OAAO,QAAQ,MAAM,GAAG,qCAAe,CAAC,SAAS,CAAC,MAAM;QACxF,IAAI,CAAC,QAAQ,GAAG,QAAQ,QAAQ,IAAI,qCAAe,CAAC,SAAS,CAAC,QAAQ;QACtE,IAAI,CAAC,UAAU,GAAG,QAAQ,UAAU,IAAI,qCAAe,CAAC,SAAS,CAAC,UAAU;QAC5E,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI,OAAO,QAAQ,WAAW,GAAG,qCAAe,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9I,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,iBAAiB,GAAG;IAC3B;AA6HF","sources":["packages/@react-spectrum/card/src/GridLayout.tsx"],"sourcesContent":["// @ts-nocheck\n/*\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 {BaseLayout, BaseLayoutOptions} from './BaseLayout';\nimport {getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {Key, Node, Orientation} from '@react-types/shared';\nimport {LayoutInfo, Rect, Size} from '@react-stately/virtualizer';\n\nexport interface GridLayoutOptions extends BaseLayoutOptions {\n // /**\n // * The card size in the grid.\n // */\n // cardSize?: 'S' | 'M' | 'L',\n /**\n * The minimum item size.\n * @default 208 x 208 for horizontal card orientation. 102 x 102 for vertical card orientation.\n */\n minItemSize?: Size,\n /**\n * The maximum item size.\n * @default Infinity\n */\n maxItemSize?: Size,\n /**\n * The minimum space required between items.\n * @default 18 x 18\n */\n minSpace?: Size,\n /**\n * The maximum number of columns.\n * @default Infinity\n */\n maxColumns?: number,\n /**\n * The additional padding along the card's main axis. Affects the sizing of the content area following the card image.\n * @default 95\n */\n itemPadding?: number,\n /**\n * The orientation of the cards withn the grid.\n * @default vertical\n */\n cardOrientation?: Orientation\n}\n\nconst DEFAULT_OPTIONS = {\n S: {\n itemPadding: 20,\n minItemSize: {\n 'vertical': new Size(96, 96)\n },\n maxItemSize: new Size(Infinity, Infinity),\n margin: 8,\n minSpace: new Size(6, 6),\n maxColumns: Infinity,\n dropSpacing: 50\n },\n L: {\n itemPadding: {\n 'vertical': {\n 'medium': 78,\n 'large': 98\n },\n 'horizontal': {\n 'medium': 150,\n 'large': 170\n }\n },\n minItemSize: {\n 'vertical': new Size(208, 208),\n 'horizontal': new Size(102, 102)\n },\n maxItemSize: new Size(Infinity, Infinity),\n margin: 24,\n minSpace: new Size(18, 18),\n maxColumns: Infinity,\n dropSpacing: 100\n }\n};\n\nexport class GridLayout<T> extends BaseLayout<T> {\n protected minItemSize: Size;\n protected maxItemSize: Size;\n protected minSpace: Size;\n protected maxColumns: number;\n itemPadding: number;\n cardOrientation: Orientation;\n protected itemSize: Size;\n protected numColumns: number;\n protected numRows: number;\n protected horizontalSpacing: number;\n\n constructor(options: GridLayoutOptions = {}) {\n super(options);\n let cardSize = 'L';\n this.cardOrientation = options.cardOrientation || 'vertical';\n this.minItemSize = options.minItemSize || DEFAULT_OPTIONS[cardSize].minItemSize[this.cardOrientation];\n this.maxItemSize = options.maxItemSize || DEFAULT_OPTIONS[cardSize].maxItemSize;\n this.margin = options.margin != null ? options.margin : DEFAULT_OPTIONS[cardSize].margin;\n this.minSpace = options.minSpace || DEFAULT_OPTIONS[cardSize].minSpace;\n this.maxColumns = options.maxColumns || DEFAULT_OPTIONS[cardSize].maxColumns;\n this.itemPadding = options.itemPadding != null ? options.itemPadding : DEFAULT_OPTIONS[cardSize].itemPadding[this.cardOrientation][this.scale];\n this.itemSize = null;\n this.numColumns = 0;\n this.numRows = 0;\n this.horizontalSpacing = 0;\n }\n\n get layoutType() {\n return 'grid';\n }\n\n getIndexAtPoint(x, y, allowInsertingAtEnd = false) {\n let itemHeight = this.itemSize.height + this.minSpace.height;\n let itemWidth = this.itemSize.width + this.horizontalSpacing;\n return Math.max(0,\n Math.min(\n this.collection.size - (allowInsertingAtEnd ? 0 : 1),\n Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)\n )\n );\n }\n\n buildCollection() {\n let visibleWidth = this.virtualizer.visibleRect.width;\n let visibleHeight = this.virtualizer.visibleRect.height;\n let horizontalItemPadding = this.cardOrientation === 'horizontal' ? this.itemPadding : 0;\n let verticalItemPadding = this.cardOrientation === 'vertical' ? this.itemPadding : 0;\n let minCardWidth = this.minItemSize.width + horizontalItemPadding;\n\n // Compute the number of rows and columns needed to display the content\n let availableWidth = visibleWidth - this.margin * 2;\n let columns = Math.floor((availableWidth + this.minSpace.width) / (minCardWidth + this.minSpace.width));\n this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));\n this.numRows = Math.ceil(this.collection.size / this.numColumns);\n\n // Compute the available width (minus the space between items)\n let width = availableWidth - (this.minSpace.width * Math.max(0, this.numColumns - 1));\n\n // Compute the item width based on the space available\n let itemWidth = Math.floor(width / this.numColumns);\n itemWidth = Math.max(minCardWidth, Math.min(this.maxItemSize.width, itemWidth));\n // Compute the item height, which is proportional to the item width\n let t = ((itemWidth - minCardWidth) / minCardWidth);\n let itemHeight = Math.floor(this.minItemSize.height + this.minItemSize.height * t);\n itemHeight = Math.max(this.minItemSize.height, Math.min(this.maxItemSize.height, itemHeight)) + verticalItemPadding;\n this.itemSize = new Size(itemWidth, itemHeight);\n\n // Compute the horizontal spacing and content height\n this.horizontalSpacing = this.numColumns < 2 ? 0 : Math.floor((availableWidth - this.numColumns * this.itemSize.width) / (this.numColumns - 1));\n\n let y = this.margin;\n let index = 0;\n for (let node of this.collection) {\n let layoutInfo = this.buildChild(node, y, index);\n y = layoutInfo.rect.maxY;\n index++;\n }\n\n if (this.isLoading) {\n let loaderY = y;\n let loaderHeight = 60;\n // If there aren't any items, make loader take all avaliable room and remove margin from y calculation\n // so it doesn't scroll\n if (this.collection.size === 0) {\n loaderY = 0;\n loaderHeight = visibleHeight || 60;\n }\n\n let rect = new Rect(0, loaderY, visibleWidth, loaderHeight);\n let loader = new LayoutInfo('loader', 'loader', rect);\n this.layoutInfos.set('loader', loader);\n y = loader.rect.maxY;\n }\n\n if (this.collection.size === 0 && !this.isLoading) {\n let rect = new Rect(0, 0, visibleWidth, visibleHeight);\n let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);\n this.layoutInfos.set('placeholder', placeholder);\n y = placeholder.rect.maxY;\n }\n\n this.contentSize = new Size(visibleWidth, y);\n }\n\n buildChild(node: Node<T>, y: number, index: number): LayoutInfo {\n let row = Math.floor(index / this.numColumns);\n let column = index % this.numColumns;\n let x = this.margin + column * (this.itemSize.width + this.horizontalSpacing);\n y = this.margin + row * (this.itemSize.height + this.minSpace.height);\n\n let rect = new Rect(x, y, this.itemSize.width, this.itemSize.height);\n // TODO: Perhaps have it so that the child key for each row is stored with the layoutInfo?\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.allowOverflow = true;\n this.layoutInfos.set(node.key, layoutInfo);\n return layoutInfo;\n }\n\n // Since the collection doesn't represent the visual layout, need to calculate what row and column the current key is in,\n // then return the key that occupies the row + column below. This can be done by figuring out how many cards exist per column then dividing the\n // collection contents by that number (which will give us the row distribution)\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 indexRowBelow;\n let index = this.collection.rows.findIndex(card => card.key === parentRowKey);\n if (index !== -1) {\n indexRowBelow = index + this.numColumns;\n } else {\n return null;\n }\n\n let row = this.collection.rows[indexRowBelow];\n return row ? getFirstItem(getChildNodes(row, this.collection))?.key : null;\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 indexRowAbove;\n let index = this.collection.rows.findIndex(card => card.key === parentRowKey);\n if (index !== -1) {\n indexRowAbove = index - this.numColumns;\n } else {\n return null;\n }\n\n let row = this.collection.rows[indexRowAbove];\n return row ? getFirstItem(getChildNodes(row, this.collection))?.key : null;\n }\n}\n"],"names":[],"version":3,"file":"GridLayout.main.js.map"}
@@ -0,0 +1,170 @@
1
+ import {BaseLayout as $3d424c147206bac9$export$64943d2e59d72a29} from "./BaseLayout.mjs";
2
+ import {getFirstItem as $QsHQE$getFirstItem, getChildNodes as $QsHQE$getChildNodes} from "@react-stately/collections";
3
+ import {Size as $QsHQE$Size, Rect as $QsHQE$Rect, LayoutInfo as $QsHQE$LayoutInfo} from "@react-stately/virtualizer";
4
+
5
+ // @ts-nocheck
6
+ /*
7
+ * Copyright 2021 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+ const $ed42fd44b9b9b664$var$DEFAULT_OPTIONS = {
20
+ S: {
21
+ itemPadding: 20,
22
+ minItemSize: {
23
+ 'vertical': new (0, $QsHQE$Size)(96, 96)
24
+ },
25
+ maxItemSize: new (0, $QsHQE$Size)(Infinity, Infinity),
26
+ margin: 8,
27
+ minSpace: new (0, $QsHQE$Size)(6, 6),
28
+ maxColumns: Infinity,
29
+ dropSpacing: 50
30
+ },
31
+ L: {
32
+ itemPadding: {
33
+ 'vertical': {
34
+ 'medium': 78,
35
+ 'large': 98
36
+ },
37
+ 'horizontal': {
38
+ 'medium': 150,
39
+ 'large': 170
40
+ }
41
+ },
42
+ minItemSize: {
43
+ 'vertical': new (0, $QsHQE$Size)(208, 208),
44
+ 'horizontal': new (0, $QsHQE$Size)(102, 102)
45
+ },
46
+ maxItemSize: new (0, $QsHQE$Size)(Infinity, Infinity),
47
+ margin: 24,
48
+ minSpace: new (0, $QsHQE$Size)(18, 18),
49
+ maxColumns: Infinity,
50
+ dropSpacing: 100
51
+ }
52
+ };
53
+ class $ed42fd44b9b9b664$export$7d2b12578154a735 extends (0, $3d424c147206bac9$export$64943d2e59d72a29) {
54
+ get layoutType() {
55
+ return 'grid';
56
+ }
57
+ getIndexAtPoint(x, y, allowInsertingAtEnd = false) {
58
+ let itemHeight = this.itemSize.height + this.minSpace.height;
59
+ let itemWidth = this.itemSize.width + this.horizontalSpacing;
60
+ return Math.max(0, Math.min(this.collection.size - (allowInsertingAtEnd ? 0 : 1), Math.floor(y / itemHeight) * this.numColumns + Math.floor((x - this.horizontalSpacing) / itemWidth)));
61
+ }
62
+ buildCollection() {
63
+ let visibleWidth = this.virtualizer.visibleRect.width;
64
+ let visibleHeight = this.virtualizer.visibleRect.height;
65
+ let horizontalItemPadding = this.cardOrientation === 'horizontal' ? this.itemPadding : 0;
66
+ let verticalItemPadding = this.cardOrientation === 'vertical' ? this.itemPadding : 0;
67
+ let minCardWidth = this.minItemSize.width + horizontalItemPadding;
68
+ // Compute the number of rows and columns needed to display the content
69
+ let availableWidth = visibleWidth - this.margin * 2;
70
+ let columns = Math.floor((availableWidth + this.minSpace.width) / (minCardWidth + this.minSpace.width));
71
+ this.numColumns = Math.max(1, Math.min(this.maxColumns, columns));
72
+ this.numRows = Math.ceil(this.collection.size / this.numColumns);
73
+ // Compute the available width (minus the space between items)
74
+ let width = availableWidth - this.minSpace.width * Math.max(0, this.numColumns - 1);
75
+ // Compute the item width based on the space available
76
+ let itemWidth = Math.floor(width / this.numColumns);
77
+ itemWidth = Math.max(minCardWidth, Math.min(this.maxItemSize.width, itemWidth));
78
+ // Compute the item height, which is proportional to the item width
79
+ let t = (itemWidth - minCardWidth) / minCardWidth;
80
+ let itemHeight = Math.floor(this.minItemSize.height + this.minItemSize.height * t);
81
+ itemHeight = Math.max(this.minItemSize.height, Math.min(this.maxItemSize.height, itemHeight)) + verticalItemPadding;
82
+ this.itemSize = new (0, $QsHQE$Size)(itemWidth, itemHeight);
83
+ // Compute the horizontal spacing and content height
84
+ this.horizontalSpacing = this.numColumns < 2 ? 0 : Math.floor((availableWidth - this.numColumns * this.itemSize.width) / (this.numColumns - 1));
85
+ let y = this.margin;
86
+ let index = 0;
87
+ for (let node of this.collection){
88
+ let layoutInfo = this.buildChild(node, y, index);
89
+ y = layoutInfo.rect.maxY;
90
+ index++;
91
+ }
92
+ if (this.isLoading) {
93
+ let loaderY = y;
94
+ let loaderHeight = 60;
95
+ // If there aren't any items, make loader take all avaliable room and remove margin from y calculation
96
+ // so it doesn't scroll
97
+ if (this.collection.size === 0) {
98
+ loaderY = 0;
99
+ loaderHeight = visibleHeight || 60;
100
+ }
101
+ let rect = new (0, $QsHQE$Rect)(0, loaderY, visibleWidth, loaderHeight);
102
+ let loader = new (0, $QsHQE$LayoutInfo)('loader', 'loader', rect);
103
+ this.layoutInfos.set('loader', loader);
104
+ y = loader.rect.maxY;
105
+ }
106
+ if (this.collection.size === 0 && !this.isLoading) {
107
+ let rect = new (0, $QsHQE$Rect)(0, 0, visibleWidth, visibleHeight);
108
+ let placeholder = new (0, $QsHQE$LayoutInfo)('placeholder', 'placeholder', rect);
109
+ this.layoutInfos.set('placeholder', placeholder);
110
+ y = placeholder.rect.maxY;
111
+ }
112
+ this.contentSize = new (0, $QsHQE$Size)(visibleWidth, y);
113
+ }
114
+ buildChild(node, y, index) {
115
+ let row = Math.floor(index / this.numColumns);
116
+ let column = index % this.numColumns;
117
+ let x = this.margin + column * (this.itemSize.width + this.horizontalSpacing);
118
+ y = this.margin + row * (this.itemSize.height + this.minSpace.height);
119
+ let rect = new (0, $QsHQE$Rect)(x, y, this.itemSize.width, this.itemSize.height);
120
+ // TODO: Perhaps have it so that the child key for each row is stored with the layoutInfo?
121
+ let layoutInfo = new (0, $QsHQE$LayoutInfo)(node.type, node.key, rect);
122
+ layoutInfo.allowOverflow = true;
123
+ this.layoutInfos.set(node.key, layoutInfo);
124
+ return layoutInfo;
125
+ }
126
+ // Since the collection doesn't represent the visual layout, need to calculate what row and column the current key is in,
127
+ // then return the key that occupies the row + column below. This can be done by figuring out how many cards exist per column then dividing the
128
+ // collection contents by that number (which will give us the row distribution)
129
+ getKeyBelow(key) {
130
+ var _getFirstItem;
131
+ // Expected key is the currently focused cell so we need the parent row key
132
+ let parentRowKey = this.collection.getItem(key).parentKey;
133
+ let indexRowBelow;
134
+ let index = this.collection.rows.findIndex((card)=>card.key === parentRowKey);
135
+ if (index !== -1) indexRowBelow = index + this.numColumns;
136
+ else return null;
137
+ let row = this.collection.rows[indexRowBelow];
138
+ return row ? (_getFirstItem = (0, $QsHQE$getFirstItem)((0, $QsHQE$getChildNodes)(row, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key : null;
139
+ }
140
+ getKeyAbove(key) {
141
+ var _getFirstItem;
142
+ // Expected key is the currently focused cell so we need the parent row key
143
+ let parentRowKey = this.collection.getItem(key).parentKey;
144
+ let indexRowAbove;
145
+ let index = this.collection.rows.findIndex((card)=>card.key === parentRowKey);
146
+ if (index !== -1) indexRowAbove = index - this.numColumns;
147
+ else return null;
148
+ let row = this.collection.rows[indexRowAbove];
149
+ return row ? (_getFirstItem = (0, $QsHQE$getFirstItem)((0, $QsHQE$getChildNodes)(row, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key : null;
150
+ }
151
+ constructor(options = {}){
152
+ super(options);
153
+ let cardSize = 'L';
154
+ this.cardOrientation = options.cardOrientation || 'vertical';
155
+ this.minItemSize = options.minItemSize || $ed42fd44b9b9b664$var$DEFAULT_OPTIONS[cardSize].minItemSize[this.cardOrientation];
156
+ this.maxItemSize = options.maxItemSize || $ed42fd44b9b9b664$var$DEFAULT_OPTIONS[cardSize].maxItemSize;
157
+ this.margin = options.margin != null ? options.margin : $ed42fd44b9b9b664$var$DEFAULT_OPTIONS[cardSize].margin;
158
+ this.minSpace = options.minSpace || $ed42fd44b9b9b664$var$DEFAULT_OPTIONS[cardSize].minSpace;
159
+ this.maxColumns = options.maxColumns || $ed42fd44b9b9b664$var$DEFAULT_OPTIONS[cardSize].maxColumns;
160
+ this.itemPadding = options.itemPadding != null ? options.itemPadding : $ed42fd44b9b9b664$var$DEFAULT_OPTIONS[cardSize].itemPadding[this.cardOrientation][this.scale];
161
+ this.itemSize = null;
162
+ this.numColumns = 0;
163
+ this.numRows = 0;
164
+ this.horizontalSpacing = 0;
165
+ }
166
+ }
167
+
168
+
169
+ export {$ed42fd44b9b9b664$export$7d2b12578154a735 as GridLayout};
170
+ //# sourceMappingURL=GridLayout.module.js.map