@spectrum-web-components/grid 0.0.8 → 0.0.9
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/custom-elements.json +5 -5
- package/package.json +26 -8
- package/sp-grid.dev.js +3 -0
- package/sp-grid.dev.js.map +7 -0
- package/sp-grid.js +3 -14
- package/sp-grid.js.map +7 -1
- package/src/Grid.dev.js +106 -0
- package/src/Grid.dev.js.map +7 -0
- package/src/Grid.js +101 -112
- package/src/Grid.js.map +7 -1
- package/src/GridController.dev.js +125 -0
- package/src/GridController.dev.js.map +7 -0
- package/src/GridController.js +118 -122
- package/src/GridController.js.map +7 -1
- package/src/grid.css.dev.js +6 -0
- package/src/grid.css.dev.js.map +7 -0
- package/src/grid.css.js +3 -14
- package/src/grid.css.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/stories/grid.stories.js +66 -85
- package/stories/grid.stories.js.map +7 -1
- package/test/benchmark/basic-test.js +5 -16
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/grid.test.js +159 -167
- package/test/grid.test.js.map +7 -1
package/custom-elements.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"modules": [
|
|
5
5
|
{
|
|
6
6
|
"kind": "javascript-module",
|
|
7
|
-
"path": "sp-grid.
|
|
7
|
+
"path": "sp-grid.js",
|
|
8
8
|
"declarations": [],
|
|
9
9
|
"exports": [
|
|
10
10
|
{
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"kind": "javascript-module",
|
|
22
|
-
"path": "src/Grid.
|
|
22
|
+
"path": "src/Grid.js",
|
|
23
23
|
"declarations": [
|
|
24
24
|
{
|
|
25
25
|
"kind": "class",
|
|
@@ -167,14 +167,14 @@
|
|
|
167
167
|
"name": "Grid",
|
|
168
168
|
"declaration": {
|
|
169
169
|
"name": "Grid",
|
|
170
|
-
"module": "src/Grid.
|
|
170
|
+
"module": "src/Grid.js"
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
]
|
|
174
174
|
},
|
|
175
175
|
{
|
|
176
176
|
"kind": "javascript-module",
|
|
177
|
-
"path": "src/GridController.
|
|
177
|
+
"path": "src/GridController.js",
|
|
178
178
|
"declarations": [
|
|
179
179
|
{
|
|
180
180
|
"kind": "class",
|
|
@@ -366,7 +366,7 @@
|
|
|
366
366
|
"name": "GridController",
|
|
367
367
|
"declaration": {
|
|
368
368
|
"name": "GridController",
|
|
369
|
-
"module": "src/GridController.
|
|
369
|
+
"module": "src/GridController.js"
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/grid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,11 +20,29 @@
|
|
|
20
20
|
"module": "src/index.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
28
|
+
"./src/Grid.js": {
|
|
29
|
+
"development": "./src/Grid.dev.js",
|
|
30
|
+
"default": "./src/Grid.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/GridController.js": {
|
|
33
|
+
"development": "./src/GridController.dev.js",
|
|
34
|
+
"default": "./src/GridController.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/grid.css.js": "./src/grid.css.js",
|
|
37
|
+
"./src/index.js": {
|
|
38
|
+
"development": "./src/index.dev.js",
|
|
39
|
+
"default": "./src/index.js"
|
|
40
|
+
},
|
|
26
41
|
"./sp-grid": "./sp-grid.js",
|
|
27
|
-
"./sp-grid.js":
|
|
42
|
+
"./sp-grid.js": {
|
|
43
|
+
"development": "./sp-grid.dev.js",
|
|
44
|
+
"default": "./sp-grid.js"
|
|
45
|
+
}
|
|
28
46
|
},
|
|
29
47
|
"scripts": {
|
|
30
48
|
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
@@ -45,9 +63,9 @@
|
|
|
45
63
|
],
|
|
46
64
|
"dependencies": {
|
|
47
65
|
"@lit-labs/observers": "^1.0.1",
|
|
48
|
-
"@lit-labs/virtualizer": "0.7.
|
|
49
|
-
"@spectrum-web-components/base": "^0.
|
|
50
|
-
"@spectrum-web-components/reactive-controllers": "^0.2.
|
|
66
|
+
"@lit-labs/virtualizer": "0.7.1",
|
|
67
|
+
"@spectrum-web-components/base": "^0.6.0",
|
|
68
|
+
"@spectrum-web-components/reactive-controllers": "^0.2.5",
|
|
51
69
|
"tslib": "^2.0.0"
|
|
52
70
|
},
|
|
53
71
|
"types": "./src/index.d.ts",
|
|
@@ -55,5 +73,5 @@
|
|
|
55
73
|
"sideEffects": [
|
|
56
74
|
"./sp-*.js"
|
|
57
75
|
],
|
|
58
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "50cac779bbb0d6735c2061f1eceb86b9daf9b22b"
|
|
59
77
|
}
|
package/sp-grid.dev.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Grid } from './src/Grid.dev.js'\n\ncustomElements.define('sp-grid', Grid);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-grid': Grid;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,WAAW,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-grid.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { Grid } from './src/Grid.js';
|
|
13
|
-
customElements.define('sp-grid', Grid);
|
|
14
|
-
//# sourceMappingURL=sp-grid.js.map
|
|
1
|
+
import { Grid } from "./src/Grid.js";
|
|
2
|
+
customElements.define("sp-grid", Grid);
|
|
3
|
+
//# sourceMappingURL=sp-grid.js.map
|
package/sp-grid.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Grid } from './src/Grid.js';\n\ncustomElements.define('sp-grid', Grid);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-grid': Grid;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,WAAW,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/Grid.dev.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
13
|
+
import { LitVirtualizer } from "@lit-labs/virtualizer/LitVirtualizer.js";
|
|
14
|
+
import { grid } from "@lit-labs/virtualizer/layouts/grid.js";
|
|
15
|
+
import styles from "./grid.css.js";
|
|
16
|
+
import { GridController } from "./GridController.dev.js";
|
|
17
|
+
export class Grid extends LitVirtualizer {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.gap = "0";
|
|
21
|
+
this.items = [];
|
|
22
|
+
this.itemSize = {
|
|
23
|
+
width: 200,
|
|
24
|
+
height: 200
|
|
25
|
+
};
|
|
26
|
+
this.selected = [];
|
|
27
|
+
this.gridController = new GridController(this, {
|
|
28
|
+
elements: () => [],
|
|
29
|
+
itemSize: () => this.itemSize,
|
|
30
|
+
gap: () => this.gap
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static get styles() {
|
|
34
|
+
return [styles];
|
|
35
|
+
}
|
|
36
|
+
get renderItem() {
|
|
37
|
+
return super.renderItem;
|
|
38
|
+
}
|
|
39
|
+
set renderItem(fn) {
|
|
40
|
+
super.renderItem = (item, index) => {
|
|
41
|
+
const selected = this.selected.includes(item);
|
|
42
|
+
return fn(item, index, selected);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
handleChange(event) {
|
|
46
|
+
const target = event.target;
|
|
47
|
+
const value = this.items[parseFloat(target.getAttribute("key") || "")];
|
|
48
|
+
const selected = [...this.selected];
|
|
49
|
+
if (!selected.includes(value)) {
|
|
50
|
+
selected.push(value);
|
|
51
|
+
} else {
|
|
52
|
+
const index = selected.indexOf(value);
|
|
53
|
+
if (index > -1) {
|
|
54
|
+
selected.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this.selected = selected;
|
|
58
|
+
}
|
|
59
|
+
update(changes) {
|
|
60
|
+
if (changes.has("itemSize") || changes.has("gap") || changes.has("focusableSelector")) {
|
|
61
|
+
this.updateComplete.then(() => {
|
|
62
|
+
this.gridController.update({
|
|
63
|
+
elements: () => [
|
|
64
|
+
...this.querySelectorAll(this.focusableSelector)
|
|
65
|
+
],
|
|
66
|
+
itemSize: () => this.itemSize,
|
|
67
|
+
gap: () => this.gap
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
this.layout = grid({
|
|
71
|
+
itemSize: {
|
|
72
|
+
width: `${this.itemSize.width}px`,
|
|
73
|
+
height: `${this.itemSize.height}px`
|
|
74
|
+
},
|
|
75
|
+
gap: this.gap
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
super.update(changes);
|
|
79
|
+
}
|
|
80
|
+
connectedCallback() {
|
|
81
|
+
super.connectedCallback();
|
|
82
|
+
this.addEventListener("change", this.handleChange, { capture: true });
|
|
83
|
+
}
|
|
84
|
+
disconnectedCallback() {
|
|
85
|
+
this.removeEventListener("change", this.handleChange, {
|
|
86
|
+
capture: true
|
|
87
|
+
});
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
__decorateClass([
|
|
92
|
+
property({ type: String })
|
|
93
|
+
], Grid.prototype, "focusableSelector", 2);
|
|
94
|
+
__decorateClass([
|
|
95
|
+
property({ type: String })
|
|
96
|
+
], Grid.prototype, "gap", 2);
|
|
97
|
+
__decorateClass([
|
|
98
|
+
property({ type: Array })
|
|
99
|
+
], Grid.prototype, "items", 2);
|
|
100
|
+
__decorateClass([
|
|
101
|
+
property({ type: Object })
|
|
102
|
+
], Grid.prototype, "itemSize", 2);
|
|
103
|
+
__decorateClass([
|
|
104
|
+
property({ type: Array })
|
|
105
|
+
], Grid.prototype, "selected", 2);
|
|
106
|
+
//# sourceMappingURL=Grid.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["Grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';\nimport { grid } from '@lit-labs/virtualizer/layouts/grid.js';\nimport styles from './grid.css.js';\nimport { GridController } from './GridController.dev.js'\n\n/**\n * @element sp-grid\n *\n * @fires change - Announces that the value of `selected` has changed\n */\nexport class Grid extends LitVirtualizer {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: String })\n public focusableSelector!: string;\n\n @property({ type: String })\n public gap: `${'0' | `${number}px`}` = '0';\n\n @property({ type: Array })\n public override items: Record<string, unknown>[] = [];\n\n @property({ type: Object })\n public itemSize: {\n width: number;\n height: number;\n } = {\n width: 200,\n height: 200,\n };\n\n /* c8 ignore next 3 */\n override get renderItem(): (\n item: unknown,\n index: number\n ) => TemplateResult {\n return super.renderItem;\n }\n\n override set renderItem(\n fn: (item: unknown, index: number, selected: boolean) => TemplateResult\n ) {\n super.renderItem = (item, index: number): TemplateResult => {\n const selected = this.selected.includes(\n item as Record<string, unknown>\n );\n return fn(item, index, selected);\n };\n }\n\n @property({ type: Array })\n public selected: Record<string, unknown>[] = [];\n\n gridController = new GridController<HTMLElement>(this, {\n elements: () => [],\n itemSize: () => this.itemSize,\n /* c8 ignore next 1 */\n gap: () => this.gap,\n });\n\n protected handleChange(event: Event): void {\n const target = event.target as HTMLElement;\n const value = this.items[\n parseFloat(target.getAttribute('key') || '')\n ] as Record<string, unknown>;\n const selected: Record<string, unknown>[] = [...this.selected];\n if (!selected.includes(value)) {\n selected.push(value);\n } else {\n const index = selected.indexOf(value);\n if (index > -1) {\n selected.splice(index, 1);\n }\n }\n this.selected = selected;\n }\n\n protected override update(changes: PropertyValues<this>): void {\n if (\n changes.has('itemSize') ||\n changes.has('gap') ||\n changes.has('focusableSelector')\n ) {\n this.updateComplete.then(() => {\n this.gridController.update({\n elements: () => [\n ...this.querySelectorAll<HTMLElement>(\n this.focusableSelector\n ),\n ],\n itemSize: () => this.itemSize,\n gap: () => this.gap,\n });\n });\n\n this.layout = grid({\n itemSize: {\n width: `${this.itemSize.width}px`,\n height: `${this.itemSize.height}px`,\n },\n gap: this.gap,\n });\n }\n\n super.update(changes);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('change', this.handleChange, { capture: true });\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('change', this.handleChange, {\n capture: true,\n });\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
+
"mappings":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import {
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import { GridController } from './GridController.js';
|
|
18
|
-
/**
|
|
19
|
-
* @element sp-grid
|
|
20
|
-
*
|
|
21
|
-
* @fires change - Announces that the value of `selected` has changed
|
|
22
|
-
*/
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
13
|
+
import { LitVirtualizer } from "@lit-labs/virtualizer/LitVirtualizer.js";
|
|
14
|
+
import { grid } from "@lit-labs/virtualizer/layouts/grid.js";
|
|
15
|
+
import styles from "./grid.css.js";
|
|
16
|
+
import { GridController } from "./GridController.js";
|
|
23
17
|
export class Grid extends LitVirtualizer {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (index > -1) {
|
|
63
|
-
selected.splice(index, 1);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.selected = selected;
|
|
67
|
-
}
|
|
68
|
-
update(changes) {
|
|
69
|
-
if (changes.has('itemSize') ||
|
|
70
|
-
changes.has('gap') ||
|
|
71
|
-
changes.has('focusableSelector')) {
|
|
72
|
-
this.updateComplete.then(() => {
|
|
73
|
-
this.gridController.update({
|
|
74
|
-
elements: () => [
|
|
75
|
-
...this.querySelectorAll(this.focusableSelector),
|
|
76
|
-
],
|
|
77
|
-
itemSize: () => this.itemSize,
|
|
78
|
-
gap: () => this.gap,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
this.layout = grid({
|
|
82
|
-
itemSize: {
|
|
83
|
-
width: `${this.itemSize.width}px`,
|
|
84
|
-
height: `${this.itemSize.height}px`,
|
|
85
|
-
},
|
|
86
|
-
gap: this.gap,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
super.update(changes);
|
|
90
|
-
}
|
|
91
|
-
connectedCallback() {
|
|
92
|
-
super.connectedCallback();
|
|
93
|
-
this.addEventListener('change', this.handleChange, { capture: true });
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.gap = "0";
|
|
21
|
+
this.items = [];
|
|
22
|
+
this.itemSize = {
|
|
23
|
+
width: 200,
|
|
24
|
+
height: 200
|
|
25
|
+
};
|
|
26
|
+
this.selected = [];
|
|
27
|
+
this.gridController = new GridController(this, {
|
|
28
|
+
elements: () => [],
|
|
29
|
+
itemSize: () => this.itemSize,
|
|
30
|
+
gap: () => this.gap
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static get styles() {
|
|
34
|
+
return [styles];
|
|
35
|
+
}
|
|
36
|
+
get renderItem() {
|
|
37
|
+
return super.renderItem;
|
|
38
|
+
}
|
|
39
|
+
set renderItem(fn) {
|
|
40
|
+
super.renderItem = (item, index) => {
|
|
41
|
+
const selected = this.selected.includes(item);
|
|
42
|
+
return fn(item, index, selected);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
handleChange(event) {
|
|
46
|
+
const target = event.target;
|
|
47
|
+
const value = this.items[parseFloat(target.getAttribute("key") || "")];
|
|
48
|
+
const selected = [...this.selected];
|
|
49
|
+
if (!selected.includes(value)) {
|
|
50
|
+
selected.push(value);
|
|
51
|
+
} else {
|
|
52
|
+
const index = selected.indexOf(value);
|
|
53
|
+
if (index > -1) {
|
|
54
|
+
selected.splice(index, 1);
|
|
55
|
+
}
|
|
94
56
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
57
|
+
this.selected = selected;
|
|
58
|
+
}
|
|
59
|
+
update(changes) {
|
|
60
|
+
if (changes.has("itemSize") || changes.has("gap") || changes.has("focusableSelector")) {
|
|
61
|
+
this.updateComplete.then(() => {
|
|
62
|
+
this.gridController.update({
|
|
63
|
+
elements: () => [
|
|
64
|
+
...this.querySelectorAll(this.focusableSelector)
|
|
65
|
+
],
|
|
66
|
+
itemSize: () => this.itemSize,
|
|
67
|
+
gap: () => this.gap
|
|
98
68
|
});
|
|
99
|
-
|
|
69
|
+
});
|
|
70
|
+
this.layout = grid({
|
|
71
|
+
itemSize: {
|
|
72
|
+
width: `${this.itemSize.width}px`,
|
|
73
|
+
height: `${this.itemSize.height}px`
|
|
74
|
+
},
|
|
75
|
+
gap: this.gap
|
|
76
|
+
});
|
|
100
77
|
}
|
|
78
|
+
super.update(changes);
|
|
79
|
+
}
|
|
80
|
+
connectedCallback() {
|
|
81
|
+
super.connectedCallback();
|
|
82
|
+
this.addEventListener("change", this.handleChange, { capture: true });
|
|
83
|
+
}
|
|
84
|
+
disconnectedCallback() {
|
|
85
|
+
this.removeEventListener("change", this.handleChange, {
|
|
86
|
+
capture: true
|
|
87
|
+
});
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
}
|
|
101
90
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
], Grid.prototype, "focusableSelector",
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
], Grid.prototype, "gap",
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
], Grid.prototype, "items",
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
], Grid.prototype, "itemSize",
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
], Grid.prototype, "selected",
|
|
117
|
-
//# sourceMappingURL=Grid.js.map
|
|
91
|
+
__decorateClass([
|
|
92
|
+
property({ type: String })
|
|
93
|
+
], Grid.prototype, "focusableSelector", 2);
|
|
94
|
+
__decorateClass([
|
|
95
|
+
property({ type: String })
|
|
96
|
+
], Grid.prototype, "gap", 2);
|
|
97
|
+
__decorateClass([
|
|
98
|
+
property({ type: Array })
|
|
99
|
+
], Grid.prototype, "items", 2);
|
|
100
|
+
__decorateClass([
|
|
101
|
+
property({ type: Object })
|
|
102
|
+
], Grid.prototype, "itemSize", 2);
|
|
103
|
+
__decorateClass([
|
|
104
|
+
property({ type: Array })
|
|
105
|
+
], Grid.prototype, "selected", 2);
|
|
106
|
+
//# sourceMappingURL=Grid.js.map
|
package/src/Grid.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["Grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';\nimport { grid } from '@lit-labs/virtualizer/layouts/grid.js';\nimport styles from './grid.css.js';\nimport { GridController } from './GridController.js';\n\n/**\n * @element sp-grid\n *\n * @fires change - Announces that the value of `selected` has changed\n */\nexport class Grid extends LitVirtualizer {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: String })\n public focusableSelector!: string;\n\n @property({ type: String })\n public gap: `${'0' | `${number}px`}` = '0';\n\n @property({ type: Array })\n public override items: Record<string, unknown>[] = [];\n\n @property({ type: Object })\n public itemSize: {\n width: number;\n height: number;\n } = {\n width: 200,\n height: 200,\n };\n\n /* c8 ignore next 3 */\n override get renderItem(): (\n item: unknown,\n index: number\n ) => TemplateResult {\n return super.renderItem;\n }\n\n override set renderItem(\n fn: (item: unknown, index: number, selected: boolean) => TemplateResult\n ) {\n super.renderItem = (item, index: number): TemplateResult => {\n const selected = this.selected.includes(\n item as Record<string, unknown>\n );\n return fn(item, index, selected);\n };\n }\n\n @property({ type: Array })\n public selected: Record<string, unknown>[] = [];\n\n gridController = new GridController<HTMLElement>(this, {\n elements: () => [],\n itemSize: () => this.itemSize,\n /* c8 ignore next 1 */\n gap: () => this.gap,\n });\n\n protected handleChange(event: Event): void {\n const target = event.target as HTMLElement;\n const value = this.items[\n parseFloat(target.getAttribute('key') || '')\n ] as Record<string, unknown>;\n const selected: Record<string, unknown>[] = [...this.selected];\n if (!selected.includes(value)) {\n selected.push(value);\n } else {\n const index = selected.indexOf(value);\n if (index > -1) {\n selected.splice(index, 1);\n }\n }\n this.selected = selected;\n }\n\n protected override update(changes: PropertyValues<this>): void {\n if (\n changes.has('itemSize') ||\n changes.has('gap') ||\n changes.has('focusableSelector')\n ) {\n this.updateComplete.then(() => {\n this.gridController.update({\n elements: () => [\n ...this.querySelectorAll<HTMLElement>(\n this.focusableSelector\n ),\n ],\n itemSize: () => this.itemSize,\n gap: () => this.gap,\n });\n });\n\n this.layout = grid({\n itemSize: {\n width: `${this.itemSize.width}px`,\n height: `${this.itemSize.height}px`,\n },\n gap: this.gap,\n });\n }\n\n super.update(changes);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('change', this.handleChange, { capture: true });\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('change', this.handleChange, {\n capture: true,\n });\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAiBA;AACA;AACA;AACA;AACA;AAOO,aAAM,aAAa,eAAe;AAAA,EAAlC;AAAA;AASI,eAAgC;AAGvB,iBAAmC,CAAC;AAG7C,oBAGH;AAAA,MACA,OAAO;AAAA,MACP,QAAQ;AAAA,IACZ;AAsBO,oBAAsC,CAAC;AAE9C,0BAAiB,IAAI,eAA4B,MAAM;AAAA,MACnD,UAAU,MAAM,CAAC;AAAA,MACjB,UAAU,MAAM,KAAK;AAAA,MAErB,KAAK,MAAM,KAAK;AAAA,IACpB,CAAC;AAAA;AAAA,aAjD0B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,MAqBa,aAGO;AAChB,WAAO,MAAM;AAAA,EACjB;AAAA,MAEa,WACT,IACF;AACE,UAAM,aAAa,CAAC,MAAM,UAAkC;AACxD,YAAM,WAAW,KAAK,SAAS,SAC3B,IACJ;AACA,aAAO,GAAG,MAAM,OAAO,QAAQ;AAAA,IACnC;AAAA,EACJ;AAAA,EAYU,aAAa,OAAoB;AACvC,UAAM,SAAS,MAAM;AACrB,UAAM,QAAQ,KAAK,MACf,WAAW,OAAO,aAAa,KAAK,KAAK,EAAE;AAE/C,UAAM,WAAsC,CAAC,GAAG,KAAK,QAAQ;AAC7D,QAAI,CAAC,SAAS,SAAS,KAAK,GAAG;AAC3B,eAAS,KAAK,KAAK;AAAA,IACvB,OAAO;AACH,YAAM,QAAQ,SAAS,QAAQ,KAAK;AACpC,UAAI,QAAQ,IAAI;AACZ,iBAAS,OAAO,OAAO,CAAC;AAAA,MAC5B;AAAA,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