@react-spectrum/card 3.0.0-nightly.3070 → 3.0.0-nightly.3074
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.
- package/dist/main.css +1 -1
- package/dist/main.js +78 -75
- package/dist/main.js.map +1 -1
- package/dist/module.js +78 -75
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -22
- package/src/GalleryLayout.tsx +87 -85
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AE6NA;;GAEG;AACH,OAAA,MAAM;UAAuF,OAAO,cAAc,CAAC;MAAM,YAAY,CAAC;AC9MtI;IACE,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC;IAEzB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,yBAAwB,CAAC,CAAE,SAAQ,OAAO,KAAK,CAAC,CAAC,CAAE,YAAW,gBAAgB;IAC5E,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC;IAC5B,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC5C,SAAS,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC;IAClC,SAAS,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;IAC5C,UAAU,EAAG,eAAe,CAAC,CAAC,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAa;IACnC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;gBAEH,OAAO,GAAE,iBAAsB;IAS3C,QAAQ,CAAC,mBAAmB,EAAE,oBAAoB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC;IAyBnE,eAAe,CAAC,mBAAmB,CAAC,EA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AE,IAAI,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAGD,6BAA6B,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAE,YAAW,gBAAgB;IAC/E,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC;IAC5B,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC;IAC5B,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC;IACzB,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC;gBAExB,OAAO,GAAE,sBAA2B;IAmBhD,IAAI,UAAU,WAEb;IAED,eAAe,CAAC,mBAAmB,EAAE,oBAAoB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC;IA6F1E,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI;IAoBnC,kBAAkB,CAAC,aAAa,KAAA;IAWhC,eAAe,CAAC,GAAG,EAAE,GAAG;IAkBxB,cAAc,CAAC,GAAG,EAAE,GAAG;IAcvB,aAAa,CAAC,GAAG,EAAE,GAAG;IAMtB,YAAY,CAAC,GAAG,EAAE,GAAG;CAKtB;ACzMD,OAAA,IAAI,0IAAyJ,CAAC","sources":["packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/CardViewContext.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/CardBase.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/CardView.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/BaseLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/GalleryLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/GridLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/WaterfallLayout.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/Card.tsx","packages/@react-spectrum/card/src/packages/@react-spectrum/card/src/index.ts","packages/@react-spectrum/card/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,"/*\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\n/// <reference types=\"css-module-types\" />\n\nexport * from './CardView';\nexport * from './GalleryLayout';\nexport * from './GridLayout';\nexport * from './WaterfallLayout';\nexport * from './Card';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/card",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.3074+df9eb3253",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -32,28 +32,28 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.6.2",
|
|
35
|
-
"@react-aria/focus": "3.0.0-nightly.
|
|
36
|
-
"@react-aria/grid": "3.2.1-nightly.
|
|
37
|
-
"@react-aria/i18n": "3.0.0-nightly.
|
|
38
|
-
"@react-aria/interactions": "3.0.0-nightly.
|
|
39
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
40
|
-
"@react-aria/virtualizer": "3.3.6-nightly.
|
|
41
|
-
"@react-spectrum/checkbox": "3.0.0-nightly.
|
|
42
|
-
"@react-spectrum/divider": "3.0.0-nightly.
|
|
43
|
-
"@react-spectrum/layout": "3.2.2-nightly.
|
|
44
|
-
"@react-spectrum/progress": "3.0.0-nightly.
|
|
45
|
-
"@react-spectrum/utils": "3.0.0-nightly.
|
|
46
|
-
"@react-stately/collections": "3.0.0-nightly.
|
|
47
|
-
"@react-stately/grid": "3.1.1-nightly.
|
|
48
|
-
"@react-stately/list": "3.4.2-nightly.
|
|
49
|
-
"@react-stately/utils": "3.0.0-nightly.
|
|
50
|
-
"@react-stately/virtualizer": "3.1.7-nightly.
|
|
51
|
-
"@react-types/card": "3.0.0-nightly.
|
|
52
|
-
"@react-types/provider": "3.3.3-nightly.
|
|
53
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
35
|
+
"@react-aria/focus": "3.0.0-nightly.1383+df9eb3253",
|
|
36
|
+
"@react-aria/grid": "3.2.1-nightly.3074+df9eb3253",
|
|
37
|
+
"@react-aria/i18n": "3.0.0-nightly.1383+df9eb3253",
|
|
38
|
+
"@react-aria/interactions": "3.0.0-nightly.1383+df9eb3253",
|
|
39
|
+
"@react-aria/utils": "3.0.0-nightly.1383+df9eb3253",
|
|
40
|
+
"@react-aria/virtualizer": "3.3.6-nightly.3074+df9eb3253",
|
|
41
|
+
"@react-spectrum/checkbox": "3.0.0-nightly.1383+df9eb3253",
|
|
42
|
+
"@react-spectrum/divider": "3.0.0-nightly.1383+df9eb3253",
|
|
43
|
+
"@react-spectrum/layout": "3.2.2-nightly.3074+df9eb3253",
|
|
44
|
+
"@react-spectrum/progress": "3.0.0-nightly.1383+df9eb3253",
|
|
45
|
+
"@react-spectrum/utils": "3.0.0-nightly.1383+df9eb3253",
|
|
46
|
+
"@react-stately/collections": "3.0.0-nightly.1383+df9eb3253",
|
|
47
|
+
"@react-stately/grid": "3.1.1-nightly.3074+df9eb3253",
|
|
48
|
+
"@react-stately/list": "3.4.2-nightly.3074+df9eb3253",
|
|
49
|
+
"@react-stately/utils": "3.0.0-nightly.1383+df9eb3253",
|
|
50
|
+
"@react-stately/virtualizer": "3.1.7-nightly.3074+df9eb3253",
|
|
51
|
+
"@react-types/card": "3.0.0-nightly.3074+df9eb3253",
|
|
52
|
+
"@react-types/provider": "3.3.3-nightly.3074+df9eb3253",
|
|
53
|
+
"@react-types/shared": "3.0.0-nightly.1383+df9eb3253"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@adobe/spectrum-css-temp": "3.0.0-nightly.
|
|
56
|
+
"@adobe/spectrum-css-temp": "3.0.0-nightly.1383+df9eb3253"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@react-spectrum/provider": "^3.0.0",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "df9eb3253328c2aee23de4ff3d48c63b4d8222e8"
|
|
66
66
|
}
|
package/src/GalleryLayout.tsx
CHANGED
|
@@ -138,105 +138,107 @@ export class GalleryLayout<T> extends BaseLayout<T> {
|
|
|
138
138
|
let y = this.margin;
|
|
139
139
|
let availableWidth = visibleWidth - this.margin * 2;
|
|
140
140
|
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ratio =
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
// If avaliable width is not greater than 0, skip node layout calculations
|
|
142
|
+
if (availableWidth > 0) {
|
|
143
|
+
// Compute aspect ratios for all of the items, and the total width if all items were on in a single row.
|
|
144
|
+
let ratios = [];
|
|
145
|
+
let totalWidth = 0;
|
|
146
|
+
let minRatio = this.minItemSize.width / this.minItemSize.height;
|
|
147
|
+
let maxRatio = availableWidth / this.minItemSize.height;
|
|
148
|
+
|
|
149
|
+
for (let node of this.collection) {
|
|
150
|
+
let ratio = node.props.width / node.props.height;
|
|
151
|
+
if (ratio < minRatio) {
|
|
152
|
+
ratio = minRatio;
|
|
153
|
+
} else if (ratio > maxRatio && ratio !== minRatio) {
|
|
154
|
+
ratio = maxRatio;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let itemWidth = ratio * this.minItemSize.height;
|
|
158
|
+
ratios.push(ratio);
|
|
159
|
+
totalWidth += itemWidth;
|
|
153
160
|
}
|
|
154
161
|
|
|
155
|
-
|
|
156
|
-
ratios.push(ratio);
|
|
157
|
-
totalWidth += itemWidth;
|
|
158
|
-
}
|
|
162
|
+
totalWidth += this.itemSpacing.width * (this.collection.size - 1);
|
|
159
163
|
|
|
160
|
-
|
|
164
|
+
// Determine how many rows we'll need, and partition the items into rows
|
|
165
|
+
// using the aspect ratios as weights.
|
|
166
|
+
let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
|
|
167
|
+
// if the available width can't hold two items, then every item will get its own row
|
|
168
|
+
// this leads to a faster run through linear partition and more dependable output for small row widths
|
|
169
|
+
if (availableWidth <= (this.minItemSize.width * 2) + (this.itemPadding * 2)) {
|
|
170
|
+
rows = this.collection.size;
|
|
171
|
+
}
|
|
161
172
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
let rows = Math.max(1, Math.ceil(totalWidth / availableWidth));
|
|
165
|
-
// if the available width can't hold two items, then every item will get its own row
|
|
166
|
-
// this leads to a faster run through linear partition and more dependable output for small row widths
|
|
167
|
-
if (availableWidth <= (this.minItemSize.width * 2) + (this.itemPadding * 2)) {
|
|
168
|
-
rows = this.collection.size;
|
|
169
|
-
}
|
|
173
|
+
let weightedRatios = ratios.map(ratio => ratio < this.threshold ? ratio + (0.5 * (1 / ratio)) : ratio);
|
|
174
|
+
let partition = linearPartition(weightedRatios, rows);
|
|
170
175
|
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
let index = 0;
|
|
177
|
+
for (let row of partition) {
|
|
178
|
+
// Compute the total weight for this row
|
|
179
|
+
let totalWeight = 0;
|
|
180
|
+
for (let j = index; j < index + row.length; j++) {
|
|
181
|
+
totalWeight += ratios[j];
|
|
182
|
+
}
|
|
173
183
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// Compute the total weight for this row
|
|
177
|
-
let totalWeight = 0;
|
|
178
|
-
for (let j = index; j < index + row.length; j++) {
|
|
179
|
-
totalWeight += ratios[j];
|
|
180
|
-
}
|
|
184
|
+
// Determine the row height based on the total available width and weight of this row.
|
|
185
|
+
let bestRowHeight = (availableWidth - (row.length - 1) * this.itemSpacing.width) / totalWeight;
|
|
181
186
|
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
// if this is the last row and the row height is >2x the ideal row height, then cap to the ideal height
|
|
188
|
+
// probably doing this because if the last row has one extremely tall image, then the row becomes huge
|
|
189
|
+
// though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
|
|
190
|
+
if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) {
|
|
191
|
+
bestRowHeight = this.idealRowHeight;
|
|
192
|
+
}
|
|
193
|
+
let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
|
|
194
|
+
let x = this.margin;
|
|
195
|
+
|
|
196
|
+
// if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
|
|
197
|
+
let widths = [];
|
|
198
|
+
for (let j = index; j < index + row.length; j++) {
|
|
199
|
+
let width = Math.round(bestRowHeight * ratios[j]);
|
|
200
|
+
widths.push([j - index, width]);
|
|
201
|
+
}
|
|
202
|
+
this._distributeWidths(widths);
|
|
203
|
+
|
|
204
|
+
// Create items for this row.
|
|
205
|
+
for (let j = index; j < index + row.length; j++) {
|
|
206
|
+
let node = this.collection.rows[j];
|
|
207
|
+
let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);
|
|
208
|
+
let rect = new Rect(x, y, itemWidth, itemHeight);
|
|
209
|
+
let layoutInfo = new LayoutInfo(node.type, node.key, rect);
|
|
210
|
+
layoutInfo.allowOverflow = true;
|
|
211
|
+
this.layoutInfos.set(node.key, layoutInfo);
|
|
212
|
+
x += itemWidth + this.itemSpacing.width;
|
|
213
|
+
}
|
|
184
214
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// though that can happen anywhere if a row has lots of tall images... so i'm not sure why this one matters
|
|
188
|
-
if (row === partition[partition.length - 1] && bestRowHeight > this.idealRowHeight * 2) {
|
|
189
|
-
bestRowHeight = this.idealRowHeight;
|
|
190
|
-
}
|
|
191
|
-
let itemHeight = Math.round(bestRowHeight) + this.itemPadding;
|
|
192
|
-
let x = this.margin;
|
|
193
|
-
|
|
194
|
-
// if any items are going to end up too small, add a bit of width to them and subtract it from wider objects
|
|
195
|
-
let widths = [];
|
|
196
|
-
for (let j = index; j < index + row.length; j++) {
|
|
197
|
-
let width = Math.round(bestRowHeight * ratios[j]);
|
|
198
|
-
widths.push([j - index, width]);
|
|
199
|
-
}
|
|
200
|
-
this._distributeWidths(widths);
|
|
201
|
-
|
|
202
|
-
// Create items for this row.
|
|
203
|
-
for (let j = index; j < index + row.length; j++) {
|
|
204
|
-
let node = this.collection.rows[j];
|
|
205
|
-
let itemWidth = Math.max(widths[j - index][1], this.minItemSize.width);
|
|
206
|
-
let rect = new Rect(x, y, itemWidth, itemHeight);
|
|
207
|
-
let layoutInfo = new LayoutInfo(node.type, node.key, rect);
|
|
208
|
-
layoutInfo.allowOverflow = true;
|
|
209
|
-
this.layoutInfos.set(node.key, layoutInfo);
|
|
210
|
-
x += itemWidth + this.itemSpacing.width;
|
|
215
|
+
y += itemHeight + this.itemSpacing.height;
|
|
216
|
+
index += row.length;
|
|
211
217
|
}
|
|
212
218
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
219
|
+
if (this.isLoading) {
|
|
220
|
+
let loaderY = y;
|
|
221
|
+
let loaderHeight = 60;
|
|
222
|
+
// If there aren't any items, make loader take all avaliable room and remove margin from y calculation
|
|
223
|
+
// so it doesn't scroll
|
|
224
|
+
if (this.collection.size === 0) {
|
|
225
|
+
loaderY = 0;
|
|
226
|
+
loaderHeight = visibleHeight || 60;
|
|
227
|
+
}
|
|
216
228
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// so it doesn't scroll
|
|
222
|
-
if (this.collection.size === 0) {
|
|
223
|
-
loaderY = 0;
|
|
224
|
-
loaderHeight = visibleHeight || 60;
|
|
229
|
+
let rect = new Rect(0, loaderY, visibleWidth, loaderHeight);
|
|
230
|
+
let loader = new LayoutInfo('loader', 'loader', rect);
|
|
231
|
+
this.layoutInfos.set('loader', loader);
|
|
232
|
+
y = loader.rect.maxY;
|
|
225
233
|
}
|
|
226
234
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (this.collection.size === 0 && !this.isLoading) {
|
|
234
|
-
let rect = new Rect(0, 0, visibleWidth, visibleHeight);
|
|
235
|
-
let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);
|
|
236
|
-
this.layoutInfos.set('placeholder', placeholder);
|
|
237
|
-
y = placeholder.rect.maxY;
|
|
235
|
+
if (this.collection.size === 0 && !this.isLoading) {
|
|
236
|
+
let rect = new Rect(0, 0, visibleWidth, visibleHeight);
|
|
237
|
+
let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);
|
|
238
|
+
this.layoutInfos.set('placeholder', placeholder);
|
|
239
|
+
y = placeholder.rect.maxY;
|
|
240
|
+
}
|
|
238
241
|
}
|
|
239
|
-
|
|
240
242
|
this.contentSize = new Size(visibleWidth, y);
|
|
241
243
|
}
|
|
242
244
|
}
|