@spectrum-web-components/grid 0.0.7 → 0.0.9-devmode.31

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.
@@ -1,129 +1,125 @@
1
- import { ResizeController } from '@lit-labs/observers/resize_controller.js';
2
- import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
1
+ import { ResizeController } from "@lit-labs/observers/resize_controller.js";
2
+ import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
3
3
  export class GridController {
4
- constructor(host, { elements, itemSize, gap, }) {
5
- // First visible element
6
- this._first = 0;
7
- // Last visible element
8
- this._last = 0;
9
- this.handleFocusin = (event) => {
10
- const doCallbackAfterPaint = (cb) => {
11
- requestAnimationFrame(() => {
12
- requestAnimationFrame(() => {
13
- cb();
14
- });
15
- });
16
- };
17
- const scrollToFirst = () => this.host.scrollToIndex(0);
18
- const focusIntoGrid = () => {
19
- this.focus();
20
- this.host.tabIndex = -1;
21
- };
22
- if (event.target === this.host) {
23
- if (this._first > 0) {
24
- doCallbackAfterPaint(() => {
25
- scrollToFirst();
26
- doCallbackAfterPaint(focusIntoGrid);
27
- });
28
- }
29
- else {
30
- doCallbackAfterPaint(focusIntoGrid);
31
- }
32
- }
33
- };
34
- this.handleFocusout = (event) => {
35
- if (event.relatedTarget &&
36
- !this.host.contains(event.relatedTarget)) {
37
- this.host.tabIndex = 0;
38
- }
39
- };
40
- this.handleRangeChanged = (event) => {
41
- this.rovingTabindexController.clearElementCache(event.first);
42
- };
43
- this.handleVisibleChanged = (event) => {
44
- this._first = event.first;
45
- this._last = event.last;
46
- };
47
- this.host = host;
48
- this.host.addController(this);
49
- this.applyLayout(itemSize, gap);
50
- this.resizeController = new ResizeController(this.host, {
51
- callback: (entries) => {
52
- entries.forEach((entry) => {
53
- this.measureDirectionLength(entry.contentRect);
54
- });
55
- },
4
+ constructor(host, {
5
+ elements,
6
+ itemSize,
7
+ gap
8
+ }) {
9
+ this._first = 0;
10
+ this._last = 0;
11
+ this.handleFocusin = (event) => {
12
+ const doCallbackAfterPaint = (cb) => {
13
+ requestAnimationFrame(() => {
14
+ requestAnimationFrame(() => {
15
+ cb();
16
+ });
56
17
  });
57
- this.rovingTabindexController = new RovingTabindexController(this.host, {
58
- direction: 'grid',
59
- elements,
60
- focusInIndex: () => {
61
- const activeElement = this.host.getRootNode()
62
- .activeElement;
63
- return activeElement === this.host ? 0 : -1;
64
- },
65
- });
66
- }
67
- get itemSize() {
68
- return this._itemSize();
69
- }
70
- /* c8 ignore next 6 */
71
- _itemSize() {
72
- return {
73
- width: 100,
74
- height: 100,
75
- };
76
- }
77
- get gap() {
78
- return this._gap();
79
- }
80
- /* c8 ignore next 3 */
81
- _gap() {
82
- return undefined;
83
- }
84
- focus(options) {
85
- this.rovingTabindexController.focus(options);
86
- }
87
- applyLayout(itemSize, gap) {
88
- /* c8 ignore next 2 */
89
- if (typeof itemSize === 'object') {
90
- this._itemSize = () => itemSize;
18
+ };
19
+ const scrollToFirst = () => this.host.scrollToIndex(0);
20
+ const focusIntoGrid = () => {
21
+ this.focus();
22
+ this.host.tabIndex = -1;
23
+ };
24
+ if (event.target === this.host) {
25
+ if (this._first > 0) {
26
+ doCallbackAfterPaint(() => {
27
+ scrollToFirst();
28
+ doCallbackAfterPaint(focusIntoGrid);
29
+ });
30
+ } else {
31
+ doCallbackAfterPaint(focusIntoGrid);
91
32
  }
92
- else if (typeof itemSize === 'function' &&
93
- typeof itemSize() !== 'undefined') {
94
- this._itemSize = itemSize;
95
- }
96
- /* c8 ignore next 2 */
97
- if (typeof gap === 'string') {
98
- this._gap = () => gap;
99
- }
100
- else if (typeof gap === 'function') {
101
- this._gap = gap;
102
- }
103
- }
104
- update({ elements, itemSize, gap, }) {
105
- this.rovingTabindexController.update({ elements });
106
- this.applyLayout(itemSize, gap);
107
- const contentRect = this.host.getBoundingClientRect();
108
- this.measureDirectionLength(contentRect);
109
- }
110
- measureDirectionLength(contentRect) {
111
- const gap = this.gap ? parseFloat(this.gap) : 0;
112
- this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
113
- }
114
- hostConnected() {
115
- this.host.addEventListener('rangeChanged', this.handleRangeChanged);
116
- this.host.addEventListener('visibilityChanged', this.handleVisibleChanged);
117
- this.host.addEventListener('focusin', this.handleFocusin);
118
- this.host.addEventListener('focusout', this.handleFocusout);
33
+ }
34
+ };
35
+ this.handleFocusout = (event) => {
36
+ if (event.relatedTarget && !this.host.contains(event.relatedTarget)) {
119
37
  this.host.tabIndex = 0;
120
- this.host.style.setProperty('outline', 'none', 'important');
38
+ }
39
+ };
40
+ this.handleRangeChanged = (event) => {
41
+ this.rovingTabindexController.clearElementCache(event.first);
42
+ };
43
+ this.handleVisibleChanged = (event) => {
44
+ this._first = event.first;
45
+ this._last = event.last;
46
+ };
47
+ this.host = host;
48
+ this.host.addController(this);
49
+ this.applyLayout(itemSize, gap);
50
+ this.resizeController = new ResizeController(this.host, {
51
+ callback: (entries) => {
52
+ entries.forEach((entry) => {
53
+ this.measureDirectionLength(entry.contentRect);
54
+ });
55
+ }
56
+ });
57
+ this.rovingTabindexController = new RovingTabindexController(this.host, {
58
+ direction: "grid",
59
+ elements,
60
+ focusInIndex: () => {
61
+ const activeElement = this.host.getRootNode().activeElement;
62
+ return activeElement === this.host ? 0 : -1;
63
+ }
64
+ });
65
+ }
66
+ get itemSize() {
67
+ return this._itemSize();
68
+ }
69
+ _itemSize() {
70
+ return {
71
+ width: 100,
72
+ height: 100
73
+ };
74
+ }
75
+ get gap() {
76
+ return this._gap();
77
+ }
78
+ _gap() {
79
+ return void 0;
80
+ }
81
+ focus(options) {
82
+ this.rovingTabindexController.focus(options);
83
+ }
84
+ applyLayout(itemSize, gap) {
85
+ if (typeof itemSize === "object") {
86
+ this._itemSize = () => itemSize;
87
+ } else if (typeof itemSize === "function" && typeof itemSize() !== "undefined") {
88
+ this._itemSize = itemSize;
121
89
  }
122
- hostDisconnected() {
123
- this.host.removeEventListener('rangeChanged', this.handleRangeChanged);
124
- this.host.removeEventListener('visibilityChanged', this.handleVisibleChanged);
125
- this.host.removeEventListener('focusin', this.handleFocusin);
126
- this.host.removeEventListener('focusout', this.handleFocusout);
90
+ if (typeof gap === "string") {
91
+ this._gap = () => gap;
92
+ } else if (typeof gap === "function") {
93
+ this._gap = gap;
127
94
  }
95
+ }
96
+ update({
97
+ elements,
98
+ itemSize,
99
+ gap
100
+ }) {
101
+ this.rovingTabindexController.update({ elements });
102
+ this.applyLayout(itemSize, gap);
103
+ const contentRect = this.host.getBoundingClientRect();
104
+ this.measureDirectionLength(contentRect);
105
+ }
106
+ measureDirectionLength(contentRect) {
107
+ const gap = this.gap ? parseFloat(this.gap) : 0;
108
+ this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
109
+ }
110
+ hostConnected() {
111
+ this.host.addEventListener("rangeChanged", this.handleRangeChanged);
112
+ this.host.addEventListener("visibilityChanged", this.handleVisibleChanged);
113
+ this.host.addEventListener("focusin", this.handleFocusin);
114
+ this.host.addEventListener("focusout", this.handleFocusout);
115
+ this.host.tabIndex = 0;
116
+ this.host.style.setProperty("outline", "none", "important");
117
+ }
118
+ hostDisconnected() {
119
+ this.host.removeEventListener("rangeChanged", this.handleRangeChanged);
120
+ this.host.removeEventListener("visibilityChanged", this.handleVisibleChanged);
121
+ this.host.removeEventListener("focusin", this.handleFocusin);
122
+ this.host.removeEventListener("focusout", this.handleFocusout);
123
+ }
128
124
  }
129
- //# sourceMappingURL=GridController.js.map
125
+ //# sourceMappingURL=GridController.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"GridController.js","sourceRoot":"","sources":["GridController.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,qEAAqE,CAAC;AAW/G,MAAM,OAAO,cAAc;IAoCvB,YACI,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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*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: ReactiveElement;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: ReactiveElement,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => (this.host as any).scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n }\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["GridController.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*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: ReactiveElement;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: ReactiveElement,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => (this.host as any).scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n }\n}\n"],
5
+ "mappings": "AAaA;AACA;AAWO,aAAM,eAEb;AAAA,EAkCI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,KAMN;AAzBF,kBAAS;AAYT,iBAAQ;AAqFE,yBAAgB,CAAC,UAA4B;AACnD,YAAM,uBAAuB,CAAC,OAAyB;AACnD,8BAAsB,MAAM;AACxB,gCAAsB,MAAM;AACxB,eAAG;AAAA,UACP,CAA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,QAAQ,WAAW;AAAA,EAC9D;AAAA,EAEO,mBAAyB;AAC5B,SAAK,KAAK,oBAAoB,gBAAgB,KAAK,kBAAkB;AACrE,SAAK,KAAK,oBACN,qBACA,KAAK,oBACT;AACA,SAAK,KAAK,oBAAoB,WAAW,KAAK,aAAa;AAC3D,SAAK,KAAK,oBAAoB,YAAY,KAAK,cAAc;AAAA,EACjE;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import { css } from "@spectrum-web-components/base";
2
+ const styles = css`
3
+ :host{contain:strict;display:block;position:relative}
4
+ `;
5
+ export default styles;
6
+ //# sourceMappingURL=grid.css.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["grid.css.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 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*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{contain:strict;display:block;position:relative}\n`;\nexport default styles;"],
5
+ "mappings": "AAWA;AACA,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
6
+ "names": []
7
+ }
package/src/grid.css.js CHANGED
@@ -1,17 +1,6 @@
1
- /*
2
- Copyright 2022 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 { css } from '@spectrum-web-components/base';
13
- const styles = css `
1
+ import { css } from "@spectrum-web-components/base";
2
+ const styles = css`
14
3
  :host{contain:strict;display:block;position:relative}
15
4
  `;
16
5
  export default styles;
17
- //# sourceMappingURL=grid.css.js.map
6
+ //# sourceMappingURL=grid.css.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"grid.css.js","sourceRoot":"","sources":["grid.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;CAEjB,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["/*\nCopyright 2022 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*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{contain:strict;display:block;position:relative}\n`;\nexport default styles;"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["grid.css.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 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*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{contain:strict;display:block;position:relative}\n`;\nexport default styles;"],
5
+ "mappings": "AAWA;AACA,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Grid.dev.js";
2
+ //# sourceMappingURL=index.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.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\nexport * from './Grid.dev.js'\n"],
5
+ "mappings": "AAYA;",
6
+ "names": []
7
+ }
package/src/index.js CHANGED
@@ -1,13 +1,2 @@
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
- export * from './Grid.js';
13
- //# sourceMappingURL=index.js.map
1
+ export * from "./Grid.js";
2
+ //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,WAAW,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\nexport * from './Grid.js';\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.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\nexport * from './Grid.js';\n"],
5
+ "mappings": "AAYA;",
6
+ "names": []
7
+ }
@@ -1,39 +1,28 @@
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 { html } from '@spectrum-web-components/base';
13
- import '../sp-grid.js';
14
- import '@spectrum-web-components/action-bar/sp-action-bar.js';
15
- import '@spectrum-web-components/card/sp-card.js';
16
- import '@spectrum-web-components/checkbox/sp-checkbox.js';
17
- import '@spectrum-web-components/action-button/sp-action-button.js';
18
- import '@spectrum-web-components/action-group/sp-action-group.js';
19
- import '@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js';
20
- import '@spectrum-web-components/icons-workflow/icons/sp-icon-more.js';
1
+ import { html } from "@spectrum-web-components/base";
2
+ import "@spectrum-web-components/grid/sp-grid.js";
3
+ import "@spectrum-web-components/action-bar/sp-action-bar.js";
4
+ import "@spectrum-web-components/card/sp-card.js";
5
+ import "@spectrum-web-components/checkbox/sp-checkbox.js";
6
+ import "@spectrum-web-components/action-button/sp-action-button.js";
7
+ import "@spectrum-web-components/action-group/sp-action-group.js";
8
+ import "@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js";
9
+ import "@spectrum-web-components/icons-workflow/icons/sp-icon-more.js";
21
10
  export default {
22
- title: 'Grid',
23
- component: 'sp-grid',
11
+ title: "Grid",
12
+ component: "sp-grid"
24
13
  };
25
14
  function generateItems(count) {
26
- const items = [];
27
- while (count) {
28
- count -= 1;
29
- items.unshift({ id: count });
30
- }
31
- return items;
15
+ const items = [];
16
+ while (count) {
17
+ count -= 1;
18
+ items.unshift({ id: count });
19
+ }
20
+ return items;
32
21
  }
33
22
  export const Default = () => {
34
- const items = generateItems(1000);
35
- const renderItem = (item, index, selected) => {
36
- return html `
23
+ const items = generateItems(1e3);
24
+ const renderItem = (item, index, selected) => {
25
+ return html`
37
26
  <sp-card
38
27
  toggles
39
28
  variant="quiet"
@@ -54,34 +43,30 @@ export const Default = () => {
54
43
  <div slot="footer">Footer</div>
55
44
  </sp-card>
56
45
  `;
57
- };
58
- const handleChange = (event) => {
59
- const actionbar = document.querySelector('sp-action-bar');
60
- const selected = document.querySelector('.selected');
61
- const ids = document.querySelector('.ids');
62
- actionbar.open = !!event.currentTarget.selected.length;
63
- actionbar.style.setProperty('display', !!event.currentTarget.selected.length ? 'flex' : 'none');
64
- selected.textContent = '' + event.currentTarget.selected.length;
65
- ids.textContent =
66
- '' +
67
- event.currentTarget.selected
68
- .map((selection) => selection.id)
69
- .join(', ');
70
- };
71
- const handleActionBarChange = (event) => {
72
- event.preventDefault();
73
- const grid = document.querySelector('sp-grid');
74
- const actionbar = document.querySelector('sp-action-bar');
75
- actionbar.open = false;
76
- grid.selected = [];
77
- };
78
- return html `
46
+ };
47
+ const handleChange = (event) => {
48
+ const actionbar = document.querySelector("sp-action-bar");
49
+ const selected = document.querySelector(".selected");
50
+ const ids = document.querySelector(".ids");
51
+ actionbar.open = !!event.currentTarget.selected.length;
52
+ actionbar.style.setProperty("display", !!event.currentTarget.selected.length ? "flex" : "none");
53
+ selected.textContent = "" + event.currentTarget.selected.length;
54
+ ids.textContent = "" + event.currentTarget.selected.map((selection) => selection.id).join(", ");
55
+ };
56
+ const handleActionBarChange = (event) => {
57
+ event.preventDefault();
58
+ const grid = document.querySelector("sp-grid");
59
+ const actionbar = document.querySelector("sp-action-bar");
60
+ actionbar.open = false;
61
+ grid.selected = [];
62
+ };
63
+ return html`
79
64
  <h1>Random before content that is focusable</h1>
80
65
  <input id="first-input" />
81
66
  <sp-grid
82
67
  @change=${handleChange}
83
68
  .items=${items}
84
- .focusableSelector=${'sp-card'}
69
+ .focusableSelector=${"sp-card"}
85
70
  .renderItem=${renderItem}
86
71
  ></sp-grid>
87
72
  <sp-action-bar variant="fixed" style="display: none">
@@ -104,9 +89,9 @@ export const Default = () => {
104
89
  `;
105
90
  };
106
91
  export const sized = () => {
107
- const items = generateItems(1000);
108
- const renderItem = (item, index, selected) => {
109
- return html `
92
+ const items = generateItems(1e3);
93
+ const renderItem = (item, index, selected) => {
94
+ return html`
110
95
  <sp-card
111
96
  toggles
112
97
  variant="quiet"
@@ -127,40 +112,36 @@ export const sized = () => {
127
112
  <div slot="footer">Footer</div>
128
113
  </sp-card>
129
114
  `;
130
- };
131
- const handleChange = (event) => {
132
- const actionbar = document.querySelector('sp-action-bar');
133
- const selected = document.querySelector('.selected');
134
- const ids = document.querySelector('.ids');
135
- actionbar.open = !!event.currentTarget.selected.length;
136
- actionbar.style.setProperty('display', !!event.currentTarget.selected.length ? 'flex' : 'none');
137
- selected.textContent = '' + event.currentTarget.selected.length;
138
- ids.textContent =
139
- '' +
140
- event.currentTarget.selected
141
- .map((selection) => selection.id)
142
- .join(', ');
143
- };
144
- const handleActionBarChange = (event) => {
145
- event.preventDefault();
146
- const grid = document.querySelector('sp-grid');
147
- const actionbar = document.querySelector('sp-action-bar');
148
- actionbar.open = false;
149
- grid.selected = [];
150
- };
151
- return html `
115
+ };
116
+ const handleChange = (event) => {
117
+ const actionbar = document.querySelector("sp-action-bar");
118
+ const selected = document.querySelector(".selected");
119
+ const ids = document.querySelector(".ids");
120
+ actionbar.open = !!event.currentTarget.selected.length;
121
+ actionbar.style.setProperty("display", !!event.currentTarget.selected.length ? "flex" : "none");
122
+ selected.textContent = "" + event.currentTarget.selected.length;
123
+ ids.textContent = "" + event.currentTarget.selected.map((selection) => selection.id).join(", ");
124
+ };
125
+ const handleActionBarChange = (event) => {
126
+ event.preventDefault();
127
+ const grid = document.querySelector("sp-grid");
128
+ const actionbar = document.querySelector("sp-action-bar");
129
+ actionbar.open = false;
130
+ grid.selected = [];
131
+ };
132
+ return html`
152
133
  <h1>Random before content that is focusable</h1>
153
134
  <input id="first-input" />
154
135
  <sp-grid
155
136
  @change=${handleChange}
156
137
  .items=${items}
157
- .focusableSelector=${'sp-card'}
138
+ .focusableSelector=${"sp-card"}
158
139
  .renderItem=${renderItem}
159
140
  .itemSize=${{
160
- width: 200,
161
- height: 300,
162
- }}
163
- .gap=${'10px'}
141
+ width: 200,
142
+ height: 300
143
+ }}
144
+ .gap=${"10px"}
164
145
  ></sp-grid>
165
146
  <sp-action-bar variant="fixed" style="display: none">
166
147
  <sp-checkbox @click=${handleActionBarChange} checked>
@@ -181,4 +162,4 @@ export const sized = () => {
181
162
  <input id="last-input" />
182
163
  `;
183
164
  };
184
- //# sourceMappingURL=grid.stories.js.map
165
+ //# sourceMappingURL=grid.stories.js.map