@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.
@@ -4,7 +4,7 @@
4
4
  "modules": [
5
5
  {
6
6
  "kind": "javascript-module",
7
- "path": "sp-grid.ts",
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.ts",
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.ts"
170
+ "module": "src/Grid.js"
171
171
  }
172
172
  }
173
173
  ]
174
174
  },
175
175
  {
176
176
  "kind": "javascript-module",
177
- "path": "src/GridController.ts",
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.ts"
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.8",
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
- ".": "./src/index.js",
24
- "./src/*": "./src/*.js",
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": "./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.0-pre.3",
49
- "@spectrum-web-components/base": "^0.5.8",
50
- "@spectrum-web-components/reactive-controllers": "^0.2.4",
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": "e5cd4a0db2201b8126eb9133ac3c24172d086359"
76
+ "gitHead": "50cac779bbb0d6735c2061f1eceb86b9daf9b22b"
59
77
  }
package/sp-grid.dev.js ADDED
@@ -0,0 +1,3 @@
1
+ import { Grid } from "./src/Grid.dev.js";
2
+ customElements.define("sp-grid", Grid);
3
+ //# sourceMappingURL=sp-grid.dev.js.map
@@ -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
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
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
- {"version":3,"file":"sp-grid.js","sourceRoot":"","sources":["sp-grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC","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"]}
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
+ }
@@ -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": ";;;;;;;;;;;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,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AAAA,EAES,oBAA0B;AAC/B,UAAM,kBAAkB;AACxB,SAAK,iBAAiB,UAAU,KAAK,cAAc,EAAE,SAAS,KAAK,CAAC;AAAA,EACxE;AAAA,EAES,uBAA6B;AAClC,SAAK,oBAAoB,UAAU,KAAK,cAAc;AAAA,MAClD,SAAS;AAAA,IACb,CAAC;AACD,UAAM,qBAAqB;AAAA,EAC/B;AACJ;AAxGW;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GACnB,AANJ,KAMI;AAGA;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GACnB,AATJ,KASI;AAGS;AAAA,EADhB,AAAC,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GACT,AAZb,KAYa;AAGT;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GACnB,AAfJ,KAeI;AA4BA;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GAClB,AA3CJ,KA2CI;",
6
+ "names": []
7
+ }
package/src/Grid.js CHANGED
@@ -1,117 +1,106 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
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 { __decorate } from "tslib";
13
- import { property } from '@spectrum-web-components/base/src/decorators.js';
14
- import { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';
15
- import { grid } from '@lit-labs/virtualizer/layouts/grid.js';
16
- import styles from './grid.css.js';
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
- constructor() {
25
- super(...arguments);
26
- this.gap = '0';
27
- this.items = [];
28
- this.itemSize = {
29
- width: 200,
30
- height: 200,
31
- };
32
- this.selected = [];
33
- this.gridController = new GridController(this, {
34
- elements: () => [],
35
- itemSize: () => this.itemSize,
36
- /* c8 ignore next 1 */
37
- gap: () => this.gap,
38
- });
39
- }
40
- static get styles() {
41
- return [styles];
42
- }
43
- /* c8 ignore next 3 */
44
- get renderItem() {
45
- return super.renderItem;
46
- }
47
- set renderItem(fn) {
48
- super.renderItem = (item, index) => {
49
- const selected = this.selected.includes(item);
50
- return fn(item, index, selected);
51
- };
52
- }
53
- handleChange(event) {
54
- const target = event.target;
55
- const value = this.items[parseFloat(target.getAttribute('key') || '')];
56
- const selected = [...this.selected];
57
- if (!selected.includes(value)) {
58
- selected.push(value);
59
- }
60
- else {
61
- const index = selected.indexOf(value);
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
- disconnectedCallback() {
96
- this.removeEventListener('change', this.handleChange, {
97
- capture: true,
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
- super.disconnectedCallback();
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
- __decorate([
103
- property({ type: String })
104
- ], Grid.prototype, "focusableSelector", void 0);
105
- __decorate([
106
- property({ type: String })
107
- ], Grid.prototype, "gap", void 0);
108
- __decorate([
109
- property({ type: Array })
110
- ], Grid.prototype, "items", void 0);
111
- __decorate([
112
- property({ type: Object })
113
- ], Grid.prototype, "itemSize", void 0);
114
- __decorate([
115
- property({ type: Array })
116
- ], Grid.prototype, "selected", void 0);
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
- {"version":3,"file":"Grid.js","sourceRoot":"","sources":["Grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAOF,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAC7D,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;GAIG;AACH,MAAM,OAA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,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,CAAC;IAEQ,oBAAoB;QACzB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE;YAClD,OAAO,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,KAAK,CAAC,oBAAoB,EAAE,CAAC;IACjC,CAAC;CACJ;AAzGG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CACO;AAGlC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iCACgB;AAG3C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;mCAC4B;AAGtD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAOzB;AAuBF;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;sCACsB","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 = (\n item: Record<string, unknown>,\n index: number\n ): TemplateResult => {\n const selected = this.selected.includes(item);\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"]}
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,Y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