@spectrum-web-components/grid 0.1.0 → 0.1.1

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.
@@ -104,6 +104,16 @@
104
104
  }
105
105
  }
106
106
  ]
107
+ },
108
+ {
109
+ "kind": "method",
110
+ "name": "createRenderRoot",
111
+ "privacy": "public",
112
+ "return": {
113
+ "type": {
114
+ "text": "this"
115
+ }
116
+ }
107
117
  }
108
118
  ],
109
119
  "events": [
@@ -185,7 +195,7 @@
185
195
  "kind": "field",
186
196
  "name": "host",
187
197
  "type": {
188
- "text": "ReactiveElement"
198
+ "text": "Grid"
189
199
  },
190
200
  "default": "host"
191
201
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/grid",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -74,5 +74,5 @@
74
74
  "./sp-*.js",
75
75
  "./**/*.dev.js"
76
76
  ],
77
- "gitHead": "05c81318844160db3f8156144106e643507fef97"
77
+ "gitHead": "1cfea66c39440232b9982509573801b8e3a9f692"
78
78
  }
package/sp-grid.dev.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  import { Grid } from "./src/Grid.dev.js";
2
3
  customElements.define("sp-grid", Grid);
3
4
  //# sourceMappingURL=sp-grid.dev.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["sp-grid.ts"],
4
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;",
5
+ "mappings": ";AAYA,SAAS,YAAY;AAErB,eAAe,OAAO,WAAW,IAAI;",
6
6
  "names": []
7
7
  }
package/sp-grid.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Grid as e}from"./src/Grid.js";customElements.define("sp-grid",e);
1
+ "use strict";import{Grid as e}from"./src/Grid.js";customElements.define("sp-grid",e);
2
2
  //# sourceMappingURL=sp-grid.js.map
package/sp-grid.js.map CHANGED
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["sp-grid.ts"],
4
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,qCAEA,eAAe,OAAO,UAAW,CAAI",
6
- "names": []
5
+ "mappings": "aAYA,OAAS,QAAAA,MAAY,gBAErB,eAAe,OAAO,UAAWA,CAAI",
6
+ "names": ["Grid"]
7
7
  }
package/src/Grid.d.ts CHANGED
@@ -20,6 +20,8 @@ export declare class Grid extends LitVirtualizer {
20
20
  selected: Record<string, unknown>[];
21
21
  gridController: GridController<HTMLElement>;
22
22
  protected handleChange(event: Event): void;
23
+ createRenderRoot(): this;
24
+ render(): TemplateResult;
23
25
  protected update(changes: PropertyValues<this>): void;
24
26
  connectedCallback(): void;
25
27
  disconnectedCallback(): void;
package/src/Grid.dev.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __decorateClass = (decorators, target, key, kind) => {
@@ -9,6 +10,11 @@ var __decorateClass = (decorators, target, key, kind) => {
9
10
  __defProp(target, key, result);
10
11
  return result;
11
12
  };
13
+ import {
14
+ adoptStyles,
15
+ html,
16
+ render
17
+ } from "@spectrum-web-components/base";
12
18
  import { property } from "@spectrum-web-components/base/src/decorators.js";
13
19
  import { LitVirtualizer } from "@lit-labs/virtualizer/LitVirtualizer.js";
14
20
  import { grid } from "@lit-labs/virtualizer/layouts/grid.js";
@@ -38,7 +44,9 @@ export class Grid extends LitVirtualizer {
38
44
  }
39
45
  set renderItem(fn) {
40
46
  super.renderItem = (item, index) => {
41
- const selected = this.selected.includes(item);
47
+ const selected = this.selected.includes(
48
+ item
49
+ );
42
50
  return fn(item, index, selected);
43
51
  };
44
52
  }
@@ -56,12 +64,30 @@ export class Grid extends LitVirtualizer {
56
64
  }
57
65
  this.selected = selected;
58
66
  }
67
+ createRenderRoot() {
68
+ var _a;
69
+ const renderRoot = (_a = this.shadowRoot) != null ? _a : this.attachShadow(
70
+ this.constructor.shadowRootOptions
71
+ );
72
+ adoptStyles(
73
+ renderRoot,
74
+ this.constructor.elementStyles
75
+ );
76
+ return renderRoot;
77
+ }
78
+ render() {
79
+ return html`
80
+ <slot></slot>
81
+ `;
82
+ }
59
83
  update(changes) {
60
84
  if (changes.has("itemSize") || changes.has("gap") || changes.has("focusableSelector")) {
61
85
  this.updateComplete.then(() => {
62
86
  this.gridController.update({
63
87
  elements: () => [
64
- ...this.querySelectorAll(this.focusableSelector)
88
+ ...this.querySelectorAll(
89
+ this.focusableSelector
90
+ )
65
91
  ],
66
92
  itemSize: () => this.itemSize,
67
93
  gap: () => this.gap
@@ -75,6 +101,9 @@ export class Grid extends LitVirtualizer {
75
101
  gap: this.gap
76
102
  });
77
103
  }
104
+ if (this.isConnected) {
105
+ render(super.render(), this);
106
+ }
78
107
  super.update(changes);
79
108
  }
80
109
  connectedCallback() {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,CA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AA,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;",
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 adoptStyles,\n CSSResultArray,\n html,\n PropertyValues,\n ReactiveElement,\n render,\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 public override createRenderRoot(): this {\n const renderRoot =\n this.shadowRoot ??\n this.attachShadow(\n (this.constructor as typeof ReactiveElement).shadowRootOptions\n );\n adoptStyles(\n renderRoot,\n (this.constructor as typeof ReactiveElement).elementStyles\n );\n return renderRoot as unknown as this;\n }\n\n public override render(): TemplateResult {\n return html`\n <slot></slot>\n `;\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 if (this.isConnected) {\n render(super.render(), this);\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": ";;;;;;;;;;;;AAYA;AAAA,EACI;AAAA,EAEA;AAAA,EAGA;AAAA,OAEG;AACP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,sBAAsB;AAOxB,aAAM,aAAa,eAAe;AAAA,EAAlC;AAAA;AASH,SAAO,MAAgC;AAGvC,SAAgB,QAAmC,CAAC;AAGpD,SAAO,WAGH;AAAA,MACA,OAAO;AAAA,MACP,QAAQ;AAAA,IACZ;AAsBA,SAAO,WAAsC,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,EAjDD,WAA2B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,EAqBA,IAAa,aAGO;AAChB,WAAO,MAAM;AAAA,EACjB;AAAA,EAEA,IAAa,WACT,IACF;AACE,UAAM,aAAa,CAAC,MAAM,UAAkC;AACxD,YAAM,WAAW,KAAK,SAAS;AAAA,QAC3B;AAAA,MACJ;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,K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B,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;AA9HW;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GALjB,KAMF;AAGA;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GARjB,KASF;AAGS;AAAA,EADf,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GAXhB,KAYO;AAGT;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAdjB,KAeF;AA4BA;AAAA,EADN,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GA1ChB,KA2CF;",
6
6
  "names": []
7
7
  }
package/src/Grid.js CHANGED
@@ -1,2 +1,4 @@
1
- var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var s=(o,t,i,r)=>{for(var e=r>1?void 0:r?p(t,i):t,n=o.length-1,a;n>=0;n--)(a=o[n])&&(e=(r?a(t,i,e):a(e))||e);return r&&e&&d(t,i,e),e};import{property as l}from"@spectrum-web-components/base/src/decorators.js";import{LitVirtualizer as u}from"@lit-labs/virtualizer/LitVirtualizer.js";import{grid as c}from"@lit-labs/virtualizer/layouts/grid.js";import m from"./grid.css.js";import{GridController as h}from"./GridController.js";export class Grid extends u{constructor(){super(...arguments);this.gap="0";this.items=[];this.itemSize={width:200,height:200};this.selected=[];this.gridController=new h(this,{elements:()=>[],itemSize:()=>this.itemSize,gap:()=>this.gap})}static get styles(){return[m]}get renderItem(){return super.renderItem}set renderItem(t){super.renderItem=(i,r)=>{const e=this.selected.includes(i);return t(i,r,e)}}handleChange(t){const i=t.target,r=this.items[parseFloat(i.getAttribute("key")||"")],e=[...this.selected];if(!e.includes(r))e.push(r);else{const n=e.indexOf(r);n>-1&&e.splice(n,1)}this.selected=e}update(t){(t.has("itemSize")||t.has("gap")||t.has("focusableSelector"))&&(this.updateComplete.then(()=>{this.gridController.update({elements:()=>[...this.querySelectorAll(this.focusableSelector)],itemSize:()=>this.itemSize,gap:()=>this.gap})}),this.layout=c({itemSize:{width:`${this.itemSize.width}px`,height:`${this.itemSize.height}px`},gap:this.gap})),super.update(t)}connectedCallback(){super.connectedCallback(),this.addEventListener("change",this.handleChange,{capture:!0})}disconnectedCallback(){this.removeEventListener("change",this.handleChange,{capture:!0}),super.disconnectedCallback()}}s([l({type:String})],Grid.prototype,"focusableSelector",2),s([l({type:String})],Grid.prototype,"gap",2),s([l({type:Array})],Grid.prototype,"items",2),s([l({type:Object})],Grid.prototype,"itemSize",2),s([l({type:Array})],Grid.prototype,"selected",2);
1
+ "use strict";var d=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var n=(a,o,e,r)=>{for(var t=r>1?void 0:r?c(o,e):o,i=a.length-1,s;i>=0;i--)(s=a[i])&&(t=(r?s(o,e,t):s(t))||t);return r&&t&&d(o,e,t),t};import{adoptStyles as u,html as p,render as h}from"@spectrum-web-components/base";import{property as l}from"@spectrum-web-components/base/src/decorators.js";import{LitVirtualizer as m}from"@lit-labs/virtualizer/LitVirtualizer.js";import{grid as g}from"@lit-labs/virtualizer/layouts/grid.js";import b from"./grid.css.js";import{GridController as S}from"./GridController.js";export class Grid extends m{constructor(){super(...arguments);this.gap="0";this.items=[];this.itemSize={width:200,height:200};this.selected=[];this.gridController=new S(this,{elements:()=>[],itemSize:()=>this.itemSize,gap:()=>this.gap})}static get styles(){return[b]}get renderItem(){return super.renderItem}set renderItem(e){super.renderItem=(r,t)=>{const i=this.selected.includes(r);return e(r,t,i)}}handleChange(e){const r=e.target,t=this.items[parseFloat(r.getAttribute("key")||"")],i=[...this.selected];if(!i.includes(t))i.push(t);else{const s=i.indexOf(t);s>-1&&i.splice(s,1)}this.selected=i}createRenderRoot(){var r;const e=(r=this.shadowRoot)!=null?r:this.attachShadow(this.constructor.shadowRootOptions);return u(e,this.constructor.elementStyles),e}render(){return p`
2
+ <slot></slot>
3
+ `}update(e){(e.has("itemSize")||e.has("gap")||e.has("focusableSelector"))&&(this.updateComplete.then(()=>{this.gridController.update({elements:()=>[...this.querySelectorAll(this.focusableSelector)],itemSize:()=>this.itemSize,gap:()=>this.gap})}),this.layout=g({itemSize:{width:`${this.itemSize.width}px`,height:`${this.itemSize.height}px`},gap:this.gap})),this.isConnected&&h(super.render(),this),super.update(e)}connectedCallback(){super.connectedCallback(),this.addEventListener("change",this.handleChange,{capture:!0})}disconnectedCallback(){this.removeEventListener("change",this.handleChange,{capture:!0}),super.disconnectedCallback()}}n([l({type:String})],Grid.prototype,"focusableSelector",2),n([l({type:String})],Grid.prototype,"gap",2),n([l({type:Array})],Grid.prototype,"items",2),n([l({type:Object})],Grid.prototype,"itemSize",2),n([l({type:Array})],Grid.prototype,"selected",2);
2
4
  //# sourceMappingURL=Grid.js.map
package/src/Grid.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": "wMAiBA,2EACA,yEACA,6DACA,6BACA,qDAOO,aAAM,YAAa,EAAe,CAAlC,kCASI,SAAgC,IAGvB,WAAmC,CAAC,EAG7C,cAGH,CACA,MAAO,IACP,OAAQ,GACZ,EAsBO,cAAsC,CAAC,EAE9C,oBAAiB,GAAI,GAA4B,KAAM,CACnD,SAAU,IAAM,CAAC,EACjB,SAAU,IAAM,KAAK,SAErB,IAAK,IAAM,KAAK,GACpB,CAAC,YAjD0B,SAAyB,CAChD,MAAO,CAAC,CAAM,CAClB,IAqBa,aAGO,CAChB,MAAO,OAAM,UACjB,IAEa,YACT,EACF,CACE,MAAM,WAAa,CAAC,EAAM,IAAkC,CACxD,KAAM,GAAW,KAAK,SAAS,SAC3B,CACJ,EACA,MAAO,GAAG,EAAM,EAAO,CAAQ,CACnC,CACJ,CAYU,aAAa,EAAoB,CACvC,KAAM,GAAS,EAAM,OACf,EAAQ,KAAK,MACf,WAAW,EAAO,aAAa,KAAK,GAAK,EAAE,GAEzC,EAAsC,CAAC,GAAG,KAAK,QAAQ,EAC7D,GAAI,CAAC,EAAS,SAAS,CAAK,EACxB,EAAS,KAAK,CAAK,MAChB,CACH,KAAM,GAAQ,EAAS,QAAQ,CAAK,EACpC,AAAI,EAAQ,IACR,EAAS,OAAO,EAAO,CAAC,CAEhC,CACA,KAAK,SAAW,CACpB,CAEmB,OAAO,EAAqC,CAC3D,AACI,GAAQ,IAAI,UAAU,GACtB,EAAQ,IAAI,KAAK,GACjB,EAAQ,IAAI,mBAAmB,IAE/B,MAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,eAAe,OAAO,CACvB,SAAU,IAAM,CACZ,GAAG,KAAK,iBACJ,KAAK,iBACT,CACJ,EACA,SAAU,IAAM,KAAK,SACrB,IAAK,IAAM,KAAK,GACpB,CAAC,CACL,CAAC,EAED,KAAK,OAAS,EAAK,CACf,SAAU,CACN,MAAO,GAAG,KAAK,SAAS,UACxB,OAAQ,GAAG,KAAK,SAAS,UAC7B,EACA,IAAK,KAAK,GACd,CAAC,GAGL,MAAM,OAAO,CAAO,CACxB,CAES,mBAA0B,CAC/B,MAAM,kBAAkB,EACxB,KAAK,iBAAiB,SAAU,KAAK,aAAc,CAAE,QAAS,EAAK,CAAC,CACxE,CAES,sBAA6B,CAClC,KAAK,oBAAoB,SAAU,KAAK,aAAc,CAClD,QAAS,EACb,CAAC,EACD,MAAM,qBAAqB,CAC/B,CACJ,CAxGW,GADP,AAAC,EAAS,CAAE,KAAM,MAAO,CAAC,GACnB,AANJ,KAMI,iCAGA,GADP,AAAC,EAAS,CAAE,KAAM,MAAO,CAAC,GACnB,AATJ,KASI,mBAGS,GADhB,AAAC,EAAS,CAAE,KAAM,KAAM,CAAC,GACT,AAZb,KAYa,qBAGT,GADP,AAAC,EAAS,CAAE,KAAM,MAAO,CAAC,GACnB,AAfJ,KAeI,wBA4BA,GADP,AAAC,EAAS,CAAE,KAAM,KAAM,CAAC,GAClB,AA3CJ,KA2CI",
6
- "names": []
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 adoptStyles,\n CSSResultArray,\n html,\n PropertyValues,\n ReactiveElement,\n render,\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 public override createRenderRoot(): this {\n const renderRoot =\n this.shadowRoot ??\n this.attachShadow(\n (this.constructor as typeof ReactiveElement).shadowRootOptions\n );\n adoptStyles(\n renderRoot,\n (this.constructor as typeof ReactiveElement).elementStyles\n );\n return renderRoot as unknown as this;\n }\n\n public override render(): TemplateResult {\n return html`\n <slot></slot>\n `;\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 if (this.isConnected) {\n render(super.render(), this);\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": "qNAYA,OACI,eAAAA,EAEA,QAAAC,EAGA,UAAAC,MAEG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,kBAAAC,MAAsB,0CAC/B,OAAS,QAAAC,MAAY,wCACrB,OAAOC,MAAY,gBACnB,OAAS,kBAAAC,MAAsB,sBAOxB,aAAM,aAAaH,CAAe,CAAlC,kCASH,KAAO,IAAgC,IAGvC,KAAgB,MAAmC,CAAC,EAGpD,KAAO,SAGH,CACA,MAAO,IACP,OAAQ,GACZ,EAsBA,KAAO,SAAsC,CAAC,EAE9C,oBAAiB,IAAIG,EAA4B,KAAM,CACnD,SAAU,IAAM,CAAC,EACjB,SAAU,IAAM,KAAK,SAErB,IAAK,IAAM,KAAK,GACpB,CAAC,EAjDD,WAA2B,QAAyB,CAChD,MAAO,CAACD,CAAM,CAClB,CAqBA,IAAa,YAGO,CAChB,OAAO,MAAM,UACjB,CAEA,IAAa,WACTE,EACF,CACE,MAAM,WAAa,CAACC,EAAMC,IAAkC,CACxD,MAAMC,EAAW,KAAK,SAAS,SAC3BF,CACJ,EACA,OAAOD,EAAGC,EAAMC,EAAOC,CAAQ,CACnC,CACJ,CAYU,aAAaC,EAAoB,CACvC,MAAMC,EAASD,EAAM,OACfE,EAAQ,KAAK,MACf,WAAWD,EAAO,aAAa,KAAK,GAAK,EAAE,GAEzCF,EAAsC,CAA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,KAAM,MAAO,CAAC,GARjB,KASF,mBAGSe,EAAA,CADff,EAAS,CAAE,KAAM,KAAM,CAAC,GAXhB,KAYO,qBAGTe,EAAA,CADNf,EAAS,CAAE,KAAM,MAAO,CAAC,GAdjB,KAeF,wBA4BAe,EAAA,CADNf,EAAS,CAAE,KAAM,KAAM,CAAC,GA1ChB,KA2CF",
6
+ "names": ["adoptStyles", "html", "render", "property", "LitVirtualizer", "grid", "styles", "GridController", "fn", "item", "index", "selected", "event", "target", "value", "_a", "renderRoot", "changes", "__decorateClass"]
7
7
  }
@@ -1,13 +1,14 @@
1
- import type { ReactiveController, ReactiveElement } from 'lit';
1
+ import type { ReactiveController } from 'lit';
2
2
  import { ResizeController } from '@lit-labs/observers/resize_controller.js';
3
3
  import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
4
4
  import { RangeChangedEvent, VisibilityChangedEvent } from '@lit-labs/virtualizer/Virtualizer.js';
5
+ import { Grid } from './Grid.js';
5
6
  interface ItemSize {
6
7
  width: number;
7
8
  height: number;
8
9
  }
9
10
  export declare class GridController<T extends HTMLElement> implements ReactiveController {
10
- host: ReactiveElement;
11
+ host: Grid;
11
12
  resizeController: ResizeController;
12
13
  rovingTabindexController: RovingTabindexController<T>;
13
14
  get itemSize(): ItemSize;
@@ -16,7 +17,7 @@ export declare class GridController<T extends HTMLElement> implements ReactiveCo
16
17
  get gap(): string | undefined;
17
18
  private _gap;
18
19
  _last: number;
19
- constructor(host: ReactiveElement, { elements, itemSize, gap, }: {
20
+ constructor(host: Grid, { elements, itemSize, gap, }: {
20
21
  elements: () => T[];
21
22
  itemSize: ItemSize | (() => ItemSize);
22
23
  gap?: string | (() => string);
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  import { ResizeController } from "@lit-labs/observers/resize_controller.js";
2
3
  import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
3
4
  export class GridController {
@@ -33,7 +34,7 @@ export class GridController {
33
34
  }
34
35
  };
35
36
  this.handleFocusout = (event) => {
36
- if (event.relatedTarget && !this.host.contains(event.relatedTarget)) {
37
+ if (!event.relatedTarget || !this.host.contains(event.relatedTarget)) {
37
38
  this.host.tabIndex = 0;
38
39
  }
39
40
  };
@@ -54,14 +55,17 @@ export class GridController {
54
55
  });
55
56
  }
56
57
  });
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;
58
+ this.rovingTabindexController = new RovingTabindexController(
59
+ this.host,
60
+ {
61
+ direction: "grid",
62
+ elements,
63
+ focusInIndex: () => {
64
+ const activeElement = this.host.getRootNode().activeElement;
65
+ return activeElement === this.host ? 0 : -1;
66
+ }
63
67
  }
64
- });
68
+ );
65
69
  }
66
70
  get itemSize() {
67
71
  return this._itemSize();
@@ -105,11 +109,16 @@ export class GridController {
105
109
  }
106
110
  measureDirectionLength(contentRect) {
107
111
  const gap = this.gap ? parseFloat(this.gap) : 0;
108
- this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
112
+ this.rovingTabindexController.directionLength = Math.floor(
113
+ (contentRect.width - gap) / (this.itemSize.width + gap)
114
+ );
109
115
  }
110
116
  hostConnected() {
111
117
  this.host.addEventListener("rangeChanged", this.handleRangeChanged);
112
- this.host.addEventListener("visibilityChanged", this.handleVisibleChanged);
118
+ this.host.addEventListener(
119
+ "visibilityChanged",
120
+ this.handleVisibleChanged
121
+ );
113
122
  this.host.addEventListener("focusin", this.handleFocusin);
114
123
  this.host.addEventListener("focusout", this.handleFocusout);
115
124
  this.host.tabIndex = 0;
@@ -117,7 +126,10 @@ export class GridController {
117
126
  }
118
127
  hostDisconnected() {
119
128
  this.host.removeEventListener("rangeChanged", this.handleRangeChanged);
120
- this.host.removeEventListener("visibilityChanged", this.handleVisibleChanged);
129
+ this.host.removeEventListener(
130
+ "visibilityChanged",
131
+ this.handleVisibleChanged
132
+ );
121
133
  this.host.removeEventListener("focusin", this.handleFocusin);
122
134
  this.host.removeEventListener("focusout", this.handleFocusout);
123
135
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,CAAC;AAAA,QACL,CAAC;AAAA,MACL;AACA,YAAM,gBAAgB,MAAa,KAAK,KAAa,cAAc,CAAC;AACpE,YAAM,gBAAgB,MAAY;AAC9B,aAAK,MAAM;AACX,aAAK,KAAK,WAAW;AAAA,MACzB;AACA,UAAK,MAAM,WAA2B,KAAK,MAAM;AAC7C,YAAI,KAAK,SAAS,GAAG;AACjB,+BAAqB,MAAM;AACvB,0BAAc;AACd,iCAAqB,aAAa;AAAA,UACtC,CAAC;AAAA,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ensed 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 } 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';\nimport { Grid } from './Grid.dev.js'\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: Grid;\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: Grid,\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.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,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AAYlC,aAAM,eAEb;AAAA,EAkCI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,EACJ,GAKF;AAzBF,kBAAS;AAYT,iBAAQ;AAqFR,SAAU,gBAAgB,CAAC,UAA4B;AACnD,YAAM,uBAAuB,CAAC,OAAyB;AACnD,8BAAsB,MAAM;AACxB,gCAAsB,MAAM;AACxB,eAAG;AAAA,UACP,CAAC;AAAA,QACL,CAAC;AAAA,MACL;AACA,YAAM,gBAAgB,MAAY,KAAK,KAAK,cAAc,CAAC;AAC3D,YAAM,gBAAgB,MAAY;AAC9B,aAAK,MAAM;AACX,aAAK,KAAK,WAAW;AAAA,MACzB;AACA,UAAK,MAAM,WAA2B,KAAK,MAAM;AAC7C,YAAI,KAAK,SAAS,GAAG;AACjB,+BAAqB,MAAM;AACvB,0BAAc;AACd,iCAAqB,aAAa;AAAA,UACtC,CAAC;AAAA,QACL,OAAO;AACH,+BAAqB,aAAa;AAAA,QACtC;AAAA,MACJ;AAAA,IACJ;AAEA,SAAU,iBAAiB,CAAC,UAA4B;AACpD,UACI,CAAC,MAAM,iBACP,CAAC,KAAK,KAAK,SAAS,MAAM,aAA4B,GACxD;AACE,a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AAAA,IACrB;AAEA,QAAI,OAAO,QAAQ,UAAU;AACzB,WAAK,OAAO,MAAM;AAAA,IACtB,WAAW,OAAO,QAAQ,YAAY;AAClC,WAAK,OAAO;AAAA,IAChB;AAAA,EACJ;AAAA,EAEO,OAAO;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACJ,GAIS;AACL,SAAK,yBAAyB,OAAO,EAAE,SAAS,CAAC;AACjD,SAAK,YAAY,UAAU,GAAG;AAC9B,UAAM,cAAc,KAAK,KAAK,sBAAsB;AACpD,SAAK,uBAAuB,WAAW;AAAA,EAC3C;AAAA,EAEU,uBAAuB,aAA4B;AACzD,UAAM,MAAM,KAAK,MAAM,WAAW,KAAK,GAAG,IAAI;AAC9C,SAAK,yBAAyB,kBAAkB,KAAK;AAAA,OAChD,YAAY,QAAQ,QAAQ,KAAK,SAAS,QAAQ;AAAA,IACvD;AAAA,EACJ;AAAA,EA6CO,gBAAsB;AACzB,SAAK,KAAK,iBAAiB,gBAAgB,KAAK,kBAAkB;AAClE,SAAK,KAAK;AAAA,MACN;AAAA,MACA,KAAK;AAAA,IACT;AACA,SAAK,KAAK,iBAAiB,WAAW,KAAK,aAAa;AACxD,SAAK,KAAK,iBAAiB,YAAY,KAAK,cAAc;AAC1D,SAAK,KAAK,WAAW;AACrB,SAAK,KAAK,MAAM,YAAY,WAAW,QAAQ,WAAW;AAAA,EAC9D;AAAA,EAEO,mBAAyB;AAC5B,SAAK,KAAK,oBAAoB,gBAAgB,KAAK,kBAAkB;AACrE,SAAK,KAAK;AAAA,MACN;AAAA,MACA,KAAK;AAAA,IACT;AACA,SAAK,KAAK,oBAAoB,WAAW,KAAK,aAAa;AAC3D,SAAK,KAAK,oBAAoB,YAAY,KAAK,cAAc;AAAA,EACjE;AACJ;",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ResizeController as r}from"@lit-labs/observers/resize_controller.js";import{RovingTabindexController as h}from"@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";export class GridController{constructor(e,{elements:t,itemSize:n,gap:i}){this._first=0;this._last=0;this.handleFocusin=e=>{const t=o=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{o()})})},n=()=>this.host.scrollToIndex(0),i=()=>{this.focus(),this.host.tabIndex=-1};e.target===this.host&&(this._first>0?t(()=>{n(),t(i)}):t(i))};this.handleFocusout=e=>{e.relatedTarget&&!this.host.contains(e.relatedTarget)&&(this.host.tabIndex=0)};this.handleRangeChanged=e=>{this.rovingTabindexController.clearElementCache(e.first)};this.handleVisibleChanged=e=>{this._first=e.first,this._last=e.last};this.host=e,this.host.addController(this),this.applyLayout(n,i),this.resizeController=new r(this.host,{callback:o=>{o.forEach(s=>{this.measureDirectionLength(s.contentRect)})}}),this.rovingTabindexController=new h(this.host,{direction:"grid",elements:t,focusInIndex:()=>this.host.getRootNode().activeElement===this.host?0:-1})}get itemSize(){return this._itemSize()}_itemSize(){return{width:100,height:100}}get gap(){return this._gap()}_gap(){}focus(e){this.rovingTabindexController.focus(e)}applyLayout(e,t){typeof e=="object"?this._itemSize=()=>e:typeof e=="function"&&typeof e()!="undefined"&&(this._itemSize=e),typeof t=="string"?this._gap=()=>t:typeof t=="function"&&(this._gap=t)}update({elements:e,itemSize:t,gap:n}){this.rovingTabindexController.update({elements:e}),this.applyLayout(t,n);const i=this.host.getBoundingClientRect();this.measureDirectionLength(i)}measureDirectionLength(e){const t=this.gap?parseFloat(this.gap):0;this.rovingTabindexController.directionLength=Math.floor((e.width-t)/(this.itemSize.width+t))}hostConnected(){this.host.addEventListener("rangeChanged",this.handleRangeChanged),this.host.addEventListener("visibilityChanged",this.handleVisibleChanged),this.host.addEventListener("focusin",this.handleFocusin),this.host.addEventListener("focusout",this.handleFocusout),this.host.tabIndex=0,this.host.style.setProperty("outline","none","important")}hostDisconnected(){this.host.removeEventListener("rangeChanged",this.handleRangeChanged),this.host.removeEventListener("visibilityChanged",this.handleVisibleChanged),this.host.removeEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout)}}
1
+ "use strict";import{ResizeController as r}from"@lit-labs/observers/resize_controller.js";import{RovingTabindexController as h}from"@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";export class GridController{constructor(t,{elements:e,itemSize:n,gap:i}){this._first=0;this._last=0;this.handleFocusin=t=>{const e=o=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{o()})})},n=()=>this.host.scrollToIndex(0),i=()=>{this.focus(),this.host.tabIndex=-1};t.target===this.host&&(this._first>0?e(()=>{n(),e(i)}):e(i))};this.handleFocusout=t=>{(!t.relatedTarget||!this.host.contains(t.relatedTarget))&&(this.host.tabIndex=0)};this.handleRangeChanged=t=>{this.rovingTabindexController.clearElementCache(t.first)};this.handleVisibleChanged=t=>{this._first=t.first,this._last=t.last};this.host=t,this.host.addController(this),this.applyLayout(n,i),this.resizeController=new r(this.host,{callback:o=>{o.forEach(s=>{this.measureDirectionLength(s.contentRect)})}}),this.rovingTabindexController=new h(this.host,{direction:"grid",elements:e,focusInIndex:()=>this.host.getRootNode().activeElement===this.host?0:-1})}get itemSize(){return this._itemSize()}_itemSize(){return{width:100,height:100}}get gap(){return this._gap()}_gap(){}focus(t){this.rovingTabindexController.focus(t)}applyLayout(t,e){typeof t=="object"?this._itemSize=()=>t:typeof t=="function"&&typeof t()!="undefined"&&(this._itemSize=t),typeof e=="string"?this._gap=()=>e:typeof e=="function"&&(this._gap=e)}update({elements:t,itemSize:e,gap:n}){this.rovingTabindexController.update({elements:t}),this.applyLayout(e,n);const i=this.host.getBoundingClientRect();this.measureDirectionLength(i)}measureDirectionLength(t){const e=this.gap?parseFloat(this.gap):0;this.rovingTabindexController.directionLength=Math.floor((t.width-e)/(this.itemSize.width+e))}hostConnected(){this.host.addEventListener("rangeChanged",this.handleRangeChanged),this.host.addEventListener("visibilityChanged",this.handleVisibleChanged),this.host.addEventListener("focusin",this.handleFocusin),this.host.addEventListener("focusout",this.handleFocusout),this.host.tabIndex=0,this.host.style.setProperty("outline","none","important")}hostDisconnected(){this.host.removeEventListener("rangeChanged",this.handleRangeChanged),this.host.removeEventListener("visibilityChanged",this.handleVisibleChanged),this.host.removeEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout)}}
2
2
  //# sourceMappingURL=GridController.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,4EACA,+GAWO,aAAM,cAEb,CAkCI,YACI,EACA,CACI,WACA,WACA,OAMN,CAzBF,YAAS,EAYT,WAAQ,EAqFE,mBAAgB,AAAC,GAA4B,CACnD,KAAM,GAAuB,AAAC,GAAyB,CACnD,sBAAsB,IAAM,CACxB,sBAAsB,IAAM,CACxB,EAAG,CACP,CAAC,CACL,CAAC,CACL,EACM,EAAgB,IAAa,KAAK,KAAa,cAAc,CAAC,EAC9D,EAAgB,IAAY,CAC9B,KAAK,MAAM,EACX,KAAK,KAAK,SAAW,EACzB,EACA,AAAK,EAAM,SAA2B,KAAK,MACvC,CAAI,KAAK,OAAS,EACd,EAAqB,IAAM,CACvB,EAAc,EACd,EAAqB,CAAa,CACtC,CAAC,EAED,EAAqB,CAAa,EAG9C,E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U,CAAG,EAC9B,KAAM,GAAc,KAAK,KAAK,sBAAsB,EACpD,KAAK,uBAAuB,CAAW,CAC3C,CAEU,uBAAuB,EAA4B,CACzD,KAAM,GAAM,KAAK,IAAM,WAAW,KAAK,GAAG,EAAI,EAC9C,KAAK,yBAAyB,gBAAkB,KAAK,MAChD,GAAY,MAAQ,GAAQ,MAAK,SAAS,MAAQ,EACvD,CACJ,CA6CO,eAAsB,CACzB,KAAK,KAAK,iBAAiB,eAAgB,KAAK,kBAAkB,EAClE,KAAK,KAAK,iBACN,oBACA,KAAK,oBACT,EACA,KAAK,KAAK,iBAAiB,UAAW,KAAK,aAAa,EACxD,KAAK,KAAK,iBAAiB,WAAY,KAAK,cAAc,EAC1D,KAAK,KAAK,SAAW,EACrB,KAAK,KAAK,MAAM,YAAY,UAAW,OAAQ,WAAW,CAC9D,CAEO,kBAAyB,CAC5B,KAAK,KAAK,oBAAoB,eAAgB,KAAK,kBAAkB,EACrE,KAAK,KAAK,oBACN,oBACA,KAAK,oBACT,EACA,KAAK,KAAK,oBAAoB,UAAW,KAAK,aAAa,EAC3D,KAAK,KAAK,oBAAoB,WAAY,KAAK,cAAc,CACjE,CACJ",
6
- "names": []
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 } 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';\nimport { Grid } from './Grid.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: Grid;\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: Grid,\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.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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,KAAK,oBACN,oBACA,KAAK,oBACT,EACA,KAAK,KAAK,oBAAoB,UAAW,KAAK,aAAa,EAC3D,KAAK,KAAK,oBAAoB,WAAY,KAAK,cAAc,CACjE,CACJ",
6
+ "names": ["ResizeController", "RovingTabindexController", "host", "elements", "itemSize", "gap", "event", "doCallbackAfterPaint", "cb", "scrollToFirst", "focusIntoGrid", "entries", "entry", "options", "contentRect"]
7
7
  }
@@ -1,6 +1,7 @@
1
+ "use strict";
1
2
  import { css } from "@spectrum-web-components/base";
2
3
  const styles = css`
3
- :host{contain:strict;display:block;position:relative}
4
+ :host{contain:strict;display:block;pointer-events:none;position:relative}::slotted(*){pointer-events:all}
4
5
  `;
5
6
  export default styles;
6
7
  //# sourceMappingURL=grid.css.dev.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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;",
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;pointer-events:none;position:relative}::slotted(*){pointer-events:all}\n`;\nexport default styles;"],
5
+ "mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
6
6
  "names": []
7
7
  }
package/src/grid.css.js CHANGED
@@ -1,4 +1,4 @@
1
- import{css as t}from"@spectrum-web-components/base";const o=t`
2
- :host{contain:strict;display:block;position:relative}
3
- `;export default o;
1
+ "use strict";import{css as t}from"@spectrum-web-components/base";const e=t`
2
+ :host{contain:strict;display:block;pointer-events:none;position:relative}::slotted(*){pointer-events:all}
3
+ `;export default e;
4
4
  //# sourceMappingURL=grid.css.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,oDACA,KAAM,GAAS;AAAA;AAAA,EAGf,cAAe",
6
- "names": []
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;pointer-events:none;position:relative}::slotted(*){pointer-events:all}\n`;\nexport default styles;"],
5
+ "mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA,EAGf,eAAeC",
6
+ "names": ["css", "styles"]
7
7
  }
package/src/index.dev.js CHANGED
@@ -1,2 +1,3 @@
1
+ "use strict";
1
2
  export * from "./Grid.dev.js";
2
3
  //# sourceMappingURL=index.dev.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
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;",
5
+ "mappings": ";AAYA,cAAc;",
6
6
  "names": []
7
7
  }
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export*from"./Grid.js";
1
+ "use strict";export*from"./Grid.js";
2
2
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
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",
5
+ "mappings": "aAYA,WAAc",
6
6
  "names": []
7
7
  }
@@ -1,34 +1,80 @@
1
- import{html as r}from"@spectrum-web-components/base";import"@spectrum-web-components/grid/sp-grid.js";import"@spectrum-web-components/action-bar/sp-action-bar.js";import"@spectrum-web-components/card/sp-card.js";import"@spectrum-web-components/checkbox/sp-checkbox.js";import"@spectrum-web-components/action-button/sp-action-button.js";import"@spectrum-web-components/action-group/sp-action-group.js";import"@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js";import"@spectrum-web-components/icons-workflow/icons/sp-icon-more.js";export default{title:"Grid",component:"sp-grid"};function a(o){const s=[];for(;o;)o-=1,s.unshift({id:o});return s}export const Default=()=>{const o=a(1e3);return r`
2
- <h1>Random before content that is focusable</h1>
3
- <input id="first-input" />
4
- <sp-grid
5
- @change=${e=>{const t=document.querySelector("sp-action-bar"),n=document.querySelector(".selected"),i=document.querySelector(".ids");t.open=!!e.currentTarget.selected.length,t.style.setProperty("display",e.currentTarget.selected.length?"flex":"none"),n.textContent=""+e.currentTarget.selected.length,i.textContent=""+e.currentTarget.selected.map(c=>c.id).join(", ")}}
6
- .items=${o}
7
- .focusableSelector=${"sp-card"}
8
- .renderItem=${(e,t,n)=>r`
1
+ "use strict";
2
+ import { html } from "@spectrum-web-components/base";
3
+ import "@spectrum-web-components/grid/sp-grid.js";
4
+ import "@spectrum-web-components/action-bar/sp-action-bar.js";
5
+ import "@spectrum-web-components/card/sp-card.js";
6
+ import "@spectrum-web-components/checkbox/sp-checkbox.js";
7
+ import "@spectrum-web-components/action-button/sp-action-button.js";
8
+ import "@spectrum-web-components/action-group/sp-action-group.js";
9
+ import "@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js";
10
+ import "@spectrum-web-components/icons-workflow/icons/sp-icon-more.js";
11
+ export default {
12
+ title: "Grid",
13
+ component: "sp-grid"
14
+ };
15
+ function generateItems(count) {
16
+ const items = [];
17
+ while (count) {
18
+ count -= 1;
19
+ items.unshift({ id: count });
20
+ }
21
+ return items;
22
+ }
23
+ export const Default = () => {
24
+ const items = generateItems(1e3);
25
+ const renderItem = (item, index, selected) => {
26
+ return html`
9
27
  <sp-card
10
28
  toggles
11
29
  variant="quiet"
12
- heading="Card Heading ${e.id}"
30
+ heading="Card Heading ${item.id}"
13
31
  subheading="JPG Photo"
14
32
  style="contain: strict; padding: 1px;"
15
- value="card-${e.id}"
16
- .selected=${n}
17
- key=${t}
33
+ value="card-${item.id}"
34
+ .selected=${selected}
35
+ key=${index}
18
36
  >
19
37
  <img
20
38
  alt=""
21
39
  slot="preview"
22
- src="https://picsum.photos/id/${e.id}/200/300"
40
+ src="https://picsum.photos/id/${item.id}/200/300"
23
41
  decoding="async"
24
42
  />
25
43
  <div slot="description">10/15/18</div>
26
44
  <div slot="footer">Footer</div>
27
45
  </sp-card>
28
- `}
46
+ `;
47
+ };
48
+ const handleChange = (event) => {
49
+ const actionbar = document.querySelector("sp-action-bar");
50
+ const selected = document.querySelector(".selected");
51
+ const ids = document.querySelector(".ids");
52
+ actionbar.open = !!event.currentTarget.selected.length;
53
+ actionbar.style.setProperty(
54
+ "display",
55
+ !!event.currentTarget.selected.length ? "flex" : "none"
56
+ );
57
+ selected.textContent = "" + event.currentTarget.selected.length;
58
+ ids.textContent = "" + event.currentTarget.selected.map((selection) => selection.id).join(", ");
59
+ };
60
+ const handleActionBarChange = (event) => {
61
+ event.preventDefault();
62
+ const grid = document.querySelector("sp-grid");
63
+ const actionbar = document.querySelector("sp-action-bar");
64
+ actionbar.open = false;
65
+ grid.selected = [];
66
+ };
67
+ return html`
68
+ <h1>Random before content that is focusable</h1>
69
+ <input id="first-input" />
70
+ <sp-grid
71
+ @change=${handleChange}
72
+ .items=${items}
73
+ .focusableSelector=${"sp-card"}
74
+ .renderItem=${renderItem}
29
75
  ></sp-grid>
30
76
  <sp-action-bar variant="fixed" style="display: none">
31
- <sp-checkbox @click=${e=>{e.preventDefault();const t=document.querySelector("sp-grid"),n=document.querySelector("sp-action-bar");n.open=!1,t.selected=[]}} checked>
77
+ <sp-checkbox @click=${handleActionBarChange} checked>
32
78
  <span class="selected"></span>
33
79
  Selected
34
80
  <span class="ids"></span>
@@ -44,39 +90,68 @@ import{html as r}from"@spectrum-web-components/base";import"@spectrum-web-compon
44
90
  </sp-action-bar>
45
91
  <h2>Random after content that is focusable</h2>
46
92
  <input id="last-input" />
47
- `},sized=()=>{const o=a(1e3);return r`
48
- <h1>Random before content that is focusable</h1>
49
- <input id="first-input" />
50
- <sp-grid
51
- @change=${e=>{const t=document.querySelector("sp-action-bar"),n=document.querySelector(".selected"),i=document.querySelector(".ids");t.open=!!e.currentTarget.selected.length,t.style.setProperty("display",e.currentTarget.selected.length?"flex":"none"),n.textContent=""+e.currentTarget.selected.length,i.textContent=""+e.currentTarget.selected.map(c=>c.id).join(", ")}}
52
- .items=${o}
53
- .focusableSelector=${"sp-card"}
54
- .renderItem=${(e,t,n)=>r`
93
+ `;
94
+ };
95
+ export const sized = () => {
96
+ const items = generateItems(1e3);
97
+ const renderItem = (item, index, selected) => {
98
+ return html`
55
99
  <sp-card
56
100
  toggles
57
101
  variant="quiet"
58
- heading="Card Heading ${e.id}"
102
+ heading="Card Heading ${item.id}"
59
103
  subheading="JPG Photo"
60
104
  style="contain: strict; padding: 1px;"
61
- value="card-${e.id}"
62
- .selected=${n}
63
- key=${t}
105
+ value="card-${item.id}"
106
+ .selected=${selected}
107
+ key=${index}
64
108
  >
65
109
  <img
66
110
  alt=""
67
111
  slot="preview"
68
- src="https://picsum.photos/id/${e.id}/200/300"
112
+ src="https://picsum.photos/id/${item.id}/200/300"
69
113
  decoding="async"
70
114
  />
71
115
  <div slot="description">10/15/18</div>
72
116
  <div slot="footer">Footer</div>
73
117
  </sp-card>
74
- `}
75
- .itemSize=${{width:200,height:300}}
118
+ `;
119
+ };
120
+ const handleChange = (event) => {
121
+ const actionbar = document.querySelector("sp-action-bar");
122
+ const selected = document.querySelector(".selected");
123
+ const ids = document.querySelector(".ids");
124
+ actionbar.open = !!event.currentTarget.selected.length;
125
+ actionbar.style.setProperty(
126
+ "display",
127
+ !!event.currentTarget.selected.length ? "flex" : "none"
128
+ );
129
+ selected.textContent = "" + event.currentTarget.selected.length;
130
+ ids.textContent = "" + event.currentTarget.selected.map((selection) => selection.id).join(", ");
131
+ };
132
+ const handleActionBarChange = (event) => {
133
+ event.preventDefault();
134
+ const grid = document.querySelector("sp-grid");
135
+ const actionbar = document.querySelector("sp-action-bar");
136
+ actionbar.open = false;
137
+ grid.selected = [];
138
+ };
139
+ return html`
140
+ <h1>Random before content that is focusable</h1>
141
+ <input id="first-input" />
142
+ <sp-grid
143
+ @change=${handleChange}
144
+ .items=${items}
145
+ .focusableSelector=${"sp-card"}
146
+ .renderItem=${renderItem}
147
+ .itemSize=${{
148
+ width: 200,
149
+ height: 300
150
+ }}
76
151
  .gap=${"10px"}
77
152
  ></sp-grid>
78
153
  <sp-action-bar variant="fixed" style="display: none">
79
- <sp-checkbox @click=${e=>{e.preventDefault();const t=document.querySelector("sp-grid"),n=document.querySelector("sp-action-bar");n.open=!1,t.selected=[]}} checked>
154
+ <sp-checkbox @click=${handleActionBarChange} checked>
80
155
  <span class="selected"></span>
81
156
  Selected
82
157
  <span class="ids"></span>
@@ -92,5 +167,6 @@ import{html as r}from"@spectrum-web-components/base";import"@spectrum-web-compon
92
167
  </sp-action-bar>
93
168
  <h2>Random after content that is focusable</h2>
94
169
  <input id="last-input" />
95
- `};
170
+ `;
171
+ };
96
172
  //# sourceMappingURL=grid.stories.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["grid.stories.ts"],
4
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 { html, TemplateResult } from '@spectrum-web-components/base';\n\nimport '@spectrum-web-components/grid/sp-grid.js';\nimport '@spectrum-web-components/action-bar/sp-action-bar.js';\nimport '@spectrum-web-components/card/sp-card.js';\nimport '@spectrum-web-components/checkbox/sp-checkbox.js';\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-edit.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-more.js';\nimport type { ActionBar } from '@spectrum-web-components/action-bar';\nimport type { Grid } from '@spectrum-web-components/grid';\n\nexport default {\n title: 'Grid',\n component: 'sp-grid',\n};\n\ninterface Item extends Record<string, unknown> {\n id: number;\n}\n\nfunction generateItems(count: number): Item[] {\n const items: Item[] = [];\n while (count) {\n count -= 1;\n items.unshift({ id: count });\n }\n return items;\n}\n\nexport const Default = (): TemplateResult => {\n const items = generateItems(1000);\n\n const renderItem = (\n item: Item,\n index: number,\n selected: boolean\n ): TemplateResult => {\n return html`\n <sp-card\n toggles\n variant=\"quiet\"\n heading=\"Card Heading ${item.id}\"\n subheading=\"JPG Photo\"\n style=\"contain: strict; padding: 1px;\"\n value=\"card-${item.id}\"\n .selected=${selected}\n key=${index}\n >\n <img\n alt=\"\"\n slot=\"preview\"\n src=\"https://picsum.photos/id/${item.id}/200/300\"\n decoding=\"async\"\n />\n <div slot=\"description\">10/15/18</div>\n <div slot=\"footer\">Footer</div>\n </sp-card>\n `;\n };\n const handleChange = (event: Event & { currentTarget: Grid }): void => {\n const actionbar = document.querySelector('sp-action-bar') as ActionBar;\n const selected = document.querySelector('.selected') as HTMLElement;\n const ids = document.querySelector('.ids') as HTMLElement;\n actionbar.open = !!event.currentTarget.selected.length;\n actionbar.style.setProperty(\n 'display',\n !!event.currentTarget.selected.length ? 'flex' : 'none'\n );\n selected.textContent = '' + event.currentTarget.selected.length;\n ids.textContent =\n '' +\n event.currentTarget.selected\n .map((selection) => selection.id)\n .join(', ');\n };\n const handleActionBarChange = (event: Event): void => {\n event.preventDefault();\n const grid = document.querySelector('sp-grid') as Grid;\n const actionbar = document.querySelector('sp-action-bar') as ActionBar;\n actionbar.open = false;\n grid.selected = [];\n };\n return html`\n <h1>Random before content that is focusable</h1>\n <input id=\"first-input\" />\n <sp-grid\n @change=${handleChange}\n .items=${items}\n .focusableSelector=${'sp-card'}\n .renderItem=${renderItem}\n ></sp-grid>\n <sp-action-bar variant=\"fixed\" style=\"display: none\">\n <sp-checkbox @click=${handleActionBarChange} checked>\n <span class=\"selected\"></span>\n Selected\n <span class=\"ids\"></span>\n </sp-checkbox>\n <sp-action-group quiet>\n <sp-action-button>\n <sp-icon-edit slot=\"icon\" label=\"Edit\"></sp-icon-edit>\n </sp-action-button>\n <sp-action-button>\n <sp-icon-more slot=\"icon\" label=\"More\"></sp-icon-more>\n </sp-action-button>\n </sp-action-group>\n </sp-action-bar>\n <h2>Random after content that is focusable</h2>\n <input id=\"last-input\" />\n `;\n};\n\nexport const sized = (): TemplateResult => {\n const items = generateItems(1000);\n\n const renderItem = (\n item: Item,\n index: number,\n selected: boolean\n ): TemplateResult => {\n return html`\n <sp-card\n toggles\n variant=\"quiet\"\n heading=\"Card Heading ${item.id}\"\n subheading=\"JPG Photo\"\n style=\"contain: strict; padding: 1px;\"\n value=\"card-${item.id}\"\n .selected=${selected}\n key=${index}\n >\n <img\n alt=\"\"\n slot=\"preview\"\n src=\"https://picsum.photos/id/${item.id}/200/300\"\n decoding=\"async\"\n />\n <div slot=\"description\">10/15/18</div>\n <div slot=\"footer\">Footer</div>\n </sp-card>\n `;\n };\n const handleChange = (event: Event & { currentTarget: Grid }): void => {\n const actionbar = document.querySelector('sp-action-bar') as ActionBar;\n const selected = document.querySelector('.selected') as HTMLElement;\n const ids = document.querySelector('.ids') as HTMLElement;\n actionbar.open = !!event.currentTarget.selected.length;\n actionbar.style.setProperty(\n 'display',\n !!event.currentTarget.selected.length ? 'flex' : 'none'\n );\n selected.textContent = '' + event.currentTarget.selected.length;\n ids.textContent =\n '' +\n event.currentTarget.selected\n .map((selection) => selection.id)\n .join(', ');\n };\n const handleActionBarChange = (event: Event): void => {\n event.preventDefault();\n const grid = document.querySelector('sp-grid') as Grid;\n const actionbar = document.querySelector('sp-action-bar') as ActionBar;\n actionbar.open = false;\n grid.selected = [];\n };\n return html`\n <h1>Random before content that is focusable</h1>\n <input id=\"first-input\" />\n <sp-grid\n @change=${handleChange}\n .items=${items}\n .focusableSelector=${'sp-card'}\n .renderItem=${renderItem}\n .itemSize=${{\n width: 200,\n height: 300,\n }}\n .gap=${'10px'}\n ></sp-grid>\n <sp-action-bar variant=\"fixed\" style=\"display: none\">\n <sp-checkbox @click=${handleActionBarChange} checked>\n <span class=\"selected\"></span>\n Selected\n <span class=\"ids\"></span>\n </sp-checkbox>\n <sp-action-group quiet>\n <sp-action-button>\n <sp-icon-edit slot=\"icon\" label=\"Edit\"></sp-icon-edit>\n </sp-action-button>\n <sp-action-button>\n <sp-icon-more slot=\"icon\" label=\"More\"></sp-icon-more>\n </sp-action-button>\n </sp-action-group>\n </sp-action-bar>\n <h2>Random after content that is focusable</h2>\n <input id=\"last-input\" />\n `;\n};\n"],
5
- "mappings": "AAYA,qDAEA,iDACA,6DACA,iDACA,yDACA,mEACA,iEACA,sEACA,sEAIA,cAAe,CACX,MAAO,OACP,UAAW,SACf,EAMA,WAAuB,EAAuB,CAC1C,KAAM,GAAgB,CAAC,EACvB,KAAO,GACH,GAAS,EACT,EAAM,QAAQ,CAAE,GAAI,CAAM,CAAC,EAE/B,MAAO,EACX,CAEO,YAAM,SAAU,IAAsB,CACzC,KAAM,GAAQ,EAAc,GAAI,EAoDhC,MA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UAAiD;AACnE,UAAM,YAAY,SAAS,cAAc,eAAe;AACxD,UAAM,WAAW,SAAS,cAAc,WAAW;AACnD,UAAM,MAAM,SAAS,cAAc,MAAM;AACzC,cAAU,OAAO,CAAC,CAAC,MAAM,cAAc,SAAS;AAChD,cAAU,MAAM;AAAA,MACZ;AAAA,MACA,CAAC,CAAC,MAAM,cAAc,SAAS,SAAS,SAAS;AAAA,IACrD;AACA,aAAS,cAAc,KAAK,MAAM,cAAc,SAAS;AACzD,QAAI,cACA,KACA,MAAM,cAAc,SACf,IAAI,CAAC,cAAc,UAAU,EAAE,EAC/B,KAAK,IAAI;AAAA,EACtB;AACA,QAAM,wBAAwB,CAAC,UAAuB;AAClD,UAAM,eAAe;AACrB,UAAM,OAAO,SAAS,cAAc,SAAS;AAC7C,UAAM,YAAY,SAAS,cAAc,eAAe;AACxD,cAAU,OAAO;AACjB,SAAK,WAAW,CAAC;AAAA,EACrB;AACA,SAAO;AAAA;AAAA;AAAA;AAAA,sBAIW;AAAA,qBACD;AAAA,iCACY;AAAA,0BACP;AAAA,wBACF;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,EACZ;AAAA,mBACO;AAAA;AAAA;AAAA,kCAGe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBlC;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,8 @@
1
- import"@spectrum-web-components/grid/sp-grid.js";import{html as r}from"@spectrum-web-components/base";import{measureFixtureCreation as i}from"../../../../test/benchmark/helpers.js";i(r`
1
+ "use strict";
2
+ import "@spectrum-web-components/grid/sp-grid.js";
3
+ import { html } from "@spectrum-web-components/base";
4
+ import { measureFixtureCreation } from "../../../../test/benchmark/helpers.js";
5
+ measureFixtureCreation(html`
2
6
  <sp-grid></sp-grid>
3
7
  `);
4
8
  //# sourceMappingURL=basic-test.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["basic-test.ts"],
4
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 '@spectrum-web-components/grid/sp-grid.js';\nimport { html } from '@spectrum-web-components/base';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-grid></sp-grid>\n`);\n"],
5
- "mappings": "AAYA,iDACA,qDACA,+EAEA,EAAuB;AAAA;AAAA,CAEtB",
5
+ "mappings": ";AAYA,OAAO;AACP,SAAS,YAAY;AACrB,SAAS,8BAA8B;AAEvC,uBAAuB;AAAA;AAAA,CAEtB;",
6
6
  "names": []
7
7
  }
package/test/grid.test.js CHANGED
@@ -1,16 +1,246 @@
1
- import{elementUpdated as o,expect as a,fixture as c,nextFrame as r}from"@open-wc/testing";import{html as l}from"@spectrum-web-components/base";import"@spectrum-web-components/grid/sp-grid.js";import{Default as u}from"../stories/grid.stories.js";import{sendKeys as i}from"@web/test-runner-commands";import{testForLitDevWarnings as n}from"../../../test/testing-helpers.js";describe("Grid",()=>{n(async()=>await c(l`
2
- <div>${u()}</div>
3
- `)),it("loads default grid accessibly",async()=>{const e=(await c(l`
4
- <div>${u()}</div>
5
- `)).querySelector("sp-grid");await o(e),await a(e).to.be.accessible()}),it("accepts focus",async()=>{const e=(await c(l`
6
- <div>${u()}</div>
7
- `)).querySelector("sp-grid");await o(e),a(e.tabIndex).to.equal(0),e.focus(),await r(),await r(),a(e.querySelector(e.focusableSelector)===document.activeElement).to.be.true}),it("allows to tab in and out",async()=>{const s=await c(l`
8
- <div>${u()}</div>
9
- `),e=s.querySelector("sp-grid"),t=s.querySelector("#first-input"),d=s.querySelector("#last-input");await o(e),a(e.tabIndex).to.equal(0),t.focus(),a(t===document.activeElement).to.be.true,a(e.tabIndex).to.equal(0),await i({press:"Tab"}),await r(),await r(),a(e.querySelector(e.focusableSelector)===document.activeElement).to.be.true,a(e.tabIndex).to.equal(-1),await i({press:"Tab"}),await r(),await r(),await o(e),a(d===document.activeElement).to.be.true,a(e.tabIndex).to.equal(0),await i({press:"Shift+Tab"}),await r(),await r(),await r(),await r(),a(e.querySelector(e.focusableSelector)===document.activeElement).to.be.true,a(e.tabIndex).to.equal(-1)}),it("manages roving tabindex",async()=>{const e=(await c(l`
10
- <div>${u()}</div>
11
- `)).querySelector("sp-grid");await o(e),a(e.tabIndex).to.equal(0),e.focus(),await r(),await r();let t=e.querySelector(e.focusableSelector);await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"ArrowRight"}),t=e.querySelector(`${e.focusableSelector}:nth-child(2)`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"ArrowDown"}),t=e.querySelector(`${e.focusableSelector}:nth-child(5)`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"ArrowLeft"}),t=e.querySelector(`${e.focusableSelector}:nth-child(4)`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"ArrowUp"}),t=e.querySelector(`${e.focusableSelector}`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true}),it("manages selection",async()=>{const e=(await c(l`
12
- <div>${u()}</div>
13
- `)).querySelector("sp-grid");await o(e),a(e.tabIndex).to.equal(0),e.focus(),await r(),await r();let t=e.querySelector(e.focusableSelector);await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"ArrowRight"}),t=e.querySelector(`${e.focusableSelector}:nth-child(2)`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"Space"}),await o(e),a(e.selected).to.deep.equal([{id:1}]),await i({press:"ArrowDown"}),t=e.querySelector(`${e.focusableSelector}:nth-child(5)`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"Space"}),await o(e),a(e.selected).to.deep.equal([{id:1},{id:4}]),await i({press:"ArrowUp"}),t=e.querySelector(`${e.focusableSelector}:nth-child(2)`),await o(t),a(t===document.activeElement).to.be.true,a(t.focused).to.be.true,await i({press:"Space"}),await o(e),a(e.selected).to.deep.equal([{id:4}])}),it("does not claim lit-virtualizer on the global registry",async()=>{const e=(await c(l`
14
- <div>${u()}</div>
15
- `)).querySelector("sp-grid");await o(e),customElements.define("lit-virtualizer",class extends HTMLElement{}),a(()=>{customElements.define("lit-virtualizer",class extends HTMLElement{})}).to.throw()})});
1
+ "use strict";
2
+ import { elementUpdated, expect, fixture, nextFrame } from "@open-wc/testing";
3
+ import { html } from "@spectrum-web-components/base";
4
+ import "@spectrum-web-components/theme/sp-theme.js";
5
+ import "@spectrum-web-components/theme/scale-medium.js";
6
+ import "@spectrum-web-components/theme/theme-light.js";
7
+ import "@spectrum-web-components/grid/sp-grid.js";
8
+ import { Default } from "../stories/grid.stories.js";
9
+ import { sendKeys, sendMouse } from "@web/test-runner-commands";
10
+ import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
11
+ describe("Grid", () => {
12
+ testForLitDevWarnings(
13
+ async () => await fixture(
14
+ html`
15
+ <div>${Default()}</div>
16
+ `
17
+ )
18
+ );
19
+ it("loads default grid accessibly", async () => {
20
+ const test = await fixture(
21
+ html`
22
+ <div>${Default()}</div>
23
+ `
24
+ );
25
+ const el = test.querySelector("sp-grid");
26
+ await elementUpdated(el);
27
+ await expect(el).to.be.accessible();
28
+ });
29
+ it("accepts focus", async () => {
30
+ const test = await fixture(
31
+ html`
32
+ <div>${Default()}</div>
33
+ `
34
+ );
35
+ const el = test.querySelector("sp-grid");
36
+ await elementUpdated(el);
37
+ expect(el.tabIndex).to.equal(0);
38
+ el.focus();
39
+ await nextFrame();
40
+ await nextFrame();
41
+ expect(
42
+ el.querySelector(el.focusableSelector) === document.activeElement
43
+ ).to.be.true;
44
+ });
45
+ it("does not focus when clicking grid", async () => {
46
+ const test = await fixture(
47
+ html`
48
+ <sp-theme color="light" scale="medium">${Default()}</sp-theme>
49
+ `
50
+ );
51
+ const el = test.querySelector("sp-grid");
52
+ await elementUpdated(el);
53
+ expect(el.tabIndex).to.equal(0);
54
+ el.focus();
55
+ await nextFrame();
56
+ await nextFrame();
57
+ const firstItem = el.querySelector(el.focusableSelector);
58
+ expect(firstItem === document.activeElement).to.be.true;
59
+ const firstRect = firstItem == null ? void 0 : firstItem.getBoundingClientRect();
60
+ const position = [
61
+ Math.round(firstRect.x + firstRect.width + 2),
62
+ Math.round(firstRect.y + 2)
63
+ ];
64
+ await sendMouse({
65
+ type: "click",
66
+ position
67
+ });
68
+ await nextFrame();
69
+ await nextFrame();
70
+ expect(
71
+ el.querySelector(el.focusableSelector) === document.activeElement
72
+ ).to.be.false;
73
+ });
74
+ it("allows to tab in and out", async () => {
75
+ const test = await fixture(
76
+ html`
77
+ <div>${Default()}</div>
78
+ `
79
+ );
80
+ const el = test.querySelector("sp-grid");
81
+ const firstInput = test.querySelector("#first-input");
82
+ const lastInput = test.querySelector("#last-input");
83
+ await elementUpdated(el);
84
+ expect(el.tabIndex).to.equal(0);
85
+ firstInput.focus();
86
+ expect(firstInput === document.activeElement).to.be.true;
87
+ expect(el.tabIndex).to.equal(0);
88
+ await sendKeys({
89
+ press: "Tab"
90
+ });
91
+ await nextFrame();
92
+ await nextFrame();
93
+ expect(
94
+ el.querySelector(el.focusableSelector) === document.activeElement
95
+ ).to.be.true;
96
+ expect(el.tabIndex).to.equal(-1);
97
+ await sendKeys({
98
+ press: "Tab"
99
+ });
100
+ await nextFrame();
101
+ await nextFrame();
102
+ await elementUpdated(el);
103
+ expect(lastInput === document.activeElement).to.be.true;
104
+ expect(el.tabIndex).to.equal(0);
105
+ await sendKeys({
106
+ press: "Shift+Tab"
107
+ });
108
+ await nextFrame();
109
+ await nextFrame();
110
+ await nextFrame();
111
+ await nextFrame();
112
+ expect(
113
+ el.querySelector(el.focusableSelector) === document.activeElement
114
+ ).to.be.true;
115
+ expect(el.tabIndex).to.equal(-1);
116
+ });
117
+ it("manages roving tabindex", async () => {
118
+ const test = await fixture(
119
+ html`
120
+ <div>${Default()}</div>
121
+ `
122
+ );
123
+ const el = test.querySelector("sp-grid");
124
+ await elementUpdated(el);
125
+ expect(el.tabIndex).to.equal(0);
126
+ el.focus();
127
+ await nextFrame();
128
+ await nextFrame();
129
+ let focused = el.querySelector(el.focusableSelector);
130
+ await elementUpdated(focused);
131
+ expect(focused === document.activeElement).to.be.true;
132
+ expect(focused.focused).to.be.true;
133
+ await sendKeys({
134
+ press: "ArrowRight"
135
+ });
136
+ focused = el.querySelector(
137
+ `${el.focusableSelector}:nth-child(2)`
138
+ );
139
+ await elementUpdated(focused);
140
+ expect(focused === document.activeElement).to.be.true;
141
+ expect(focused.focused).to.be.true;
142
+ await sendKeys({
143
+ press: "ArrowDown"
144
+ });
145
+ focused = el.querySelector(
146
+ `${el.focusableSelector}:nth-child(5)`
147
+ );
148
+ await elementUpdated(focused);
149
+ expect(focused === document.activeElement).to.be.true;
150
+ expect(focused.focused).to.be.true;
151
+ await sendKeys({
152
+ press: "ArrowLeft"
153
+ });
154
+ focused = el.querySelector(
155
+ `${el.focusableSelector}:nth-child(4)`
156
+ );
157
+ await elementUpdated(focused);
158
+ expect(focused === document.activeElement).to.be.true;
159
+ expect(focused.focused).to.be.true;
160
+ await sendKeys({
161
+ press: "ArrowUp"
162
+ });
163
+ focused = el.querySelector(`${el.focusableSelector}`);
164
+ await elementUpdated(focused);
165
+ expect(focused === document.activeElement).to.be.true;
166
+ expect(focused.focused).to.be.true;
167
+ });
168
+ it("manages selection", async () => {
169
+ const test = await fixture(
170
+ html`
171
+ <div>${Default()}</div>
172
+ `
173
+ );
174
+ const el = test.querySelector("sp-grid");
175
+ await elementUpdated(el);
176
+ expect(el.tabIndex).to.equal(0);
177
+ el.focus();
178
+ await nextFrame();
179
+ await nextFrame();
180
+ let focused = el.querySelector(el.focusableSelector);
181
+ await elementUpdated(focused);
182
+ expect(focused === document.activeElement).to.be.true;
183
+ expect(focused.focused).to.be.true;
184
+ await sendKeys({
185
+ press: "ArrowRight"
186
+ });
187
+ focused = el.querySelector(
188
+ `${el.focusableSelector}:nth-child(2)`
189
+ );
190
+ await elementUpdated(focused);
191
+ expect(focused === document.activeElement).to.be.true;
192
+ expect(focused.focused).to.be.true;
193
+ await sendKeys({
194
+ press: "Space"
195
+ });
196
+ await elementUpdated(el);
197
+ expect(el.selected).to.deep.equal([{ id: 1 }]);
198
+ await sendKeys({
199
+ press: "ArrowDown"
200
+ });
201
+ focused = el.querySelector(
202
+ `${el.focusableSelector}:nth-child(5)`
203
+ );
204
+ await elementUpdated(focused);
205
+ expect(focused === document.activeElement).to.be.true;
206
+ expect(focused.focused).to.be.true;
207
+ await sendKeys({
208
+ press: "Space"
209
+ });
210
+ await elementUpdated(el);
211
+ expect(el.selected).to.deep.equal([{ id: 1 }, { id: 4 }]);
212
+ await sendKeys({
213
+ press: "ArrowUp"
214
+ });
215
+ focused = el.querySelector(
216
+ `${el.focusableSelector}:nth-child(2)`
217
+ );
218
+ await elementUpdated(focused);
219
+ expect(focused === document.activeElement).to.be.true;
220
+ expect(focused.focused).to.be.true;
221
+ await sendKeys({
222
+ press: "Space"
223
+ });
224
+ await elementUpdated(el);
225
+ expect(el.selected).to.deep.equal([{ id: 4 }]);
226
+ });
227
+ it("does not claim lit-virtualizer on the global registry", async () => {
228
+ const test = await fixture(
229
+ html`
230
+ <div>${Default()}</div>
231
+ `
232
+ );
233
+ const el = test.querySelector("sp-grid");
234
+ await elementUpdated(el);
235
+ customElements.define("lit-virtualizer", class extends HTMLElement {
236
+ });
237
+ expect(() => {
238
+ customElements.define(
239
+ "lit-virtualizer",
240
+ class extends HTMLElement {
241
+ }
242
+ );
243
+ }).to.throw();
244
+ });
245
+ });
16
246
  //# sourceMappingURL=grid.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["grid.test.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 { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { html } from '@spectrum-web-components/base';\nimport { Card } from '@spectrum-web-components/card';\n\nimport '@spectrum-web-components/grid/sp-grid.js';\nimport { Grid } from '@spectrum-web-components/grid';\nimport { Default } from '../stories/grid.stories.js';\nimport { sendKeys } from '@web/test-runner-commands';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\n\ndescribe('Grid', () => {\n testForLitDevWarnings(\n async () =>\n await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n )\n );\n it('loads default grid accessibly', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('accepts focus', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n });\n it('allows to tab in and out', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n const firstInput = test.querySelector('#first-input') as HTMLElement;\n const lastInput = test.querySelector('#last-input') as HTMLElement;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n firstInput.focus();\n expect(firstInput === document.activeElement).to.be.true;\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({\n press: 'Tab',\n });\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n expect(el.tabIndex).to.equal(-1);\n\n await sendKeys({\n press: 'Tab',\n });\n\n await nextFrame();\n await nextFrame();\n\n await elementUpdated(el);\n expect(lastInput === document.activeElement).to.be.true;\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({\n press: 'Shift+Tab',\n });\n\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n expect(el.tabIndex).to.equal(-1);\n });\n it('manages roving tabindex', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n let focused = el.querySelector(el.focusableSelector) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(5)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(4)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowUp',\n });\n\n focused = el.querySelector(`${el.focusableSelector}`) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n });\n it('manages selection', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n let focused = el.querySelector(el.focusableSelector) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 1 }]);\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(5)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 1 }, { id: 4 }]);\n\n await sendKeys({\n press: 'ArrowUp',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 4 }]);\n });\n it('does not claim lit-virtualizer on the global registry', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n customElements.define('lit-virtualizer', class extends HTMLElement {});\n\n // make sure we also don't prevent *any* registration of lit-virtualizer\n expect(() => {\n customElements.define(\n 'lit-virtualizer',\n class extends HTMLElement {}\n );\n }).to.throw();\n });\n});\n"],
5
- "mappings": "AAYA,0FACA,qDAGA,iDAEA,qDACA,qDACA,yEAEA,SAAS,OAAQ,IAAM,CACnB,EACI,SACI,KAAM,GACF;AAAA,2BACW,EAAQ;AAAA,iBAEvB,CACR,EACA,GAAG,gCAAiC,SAAY,CAM5C,KAAM,GAAK,AALE,MAAM,GACf;AAAA,uBACW,EAAQ;AAAA,aAEvB,GACgB,cAAc,SAAS,EAEvC,KAAM,GAAe,CAAE,EAEvB,KAAM,GAAO,CAAE,EAAE,GAAG,GAAG,WAAW,CACtC,CAAC,EACD,GAAG,gBAAiB,SAAY,CAM5B,KAAM,GAAK,AALE,MAAM,GACf;AAAA,uBACW,EAAQ;AAAA,aAEvB,GACgB,cAAc,SAAS,EAEvC,KAAM,GAAe,CAAE,EAEvB,EAAO,EAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,EAE9B,EAAG,MAAM,EAET,KAAM,GAAU,EAChB,KAAM,GAAU,EAEhB,EACI,EAAG,cAAc,EAAG,iBAAiB,IAAM,SAAS,aACxD,EAAE,GAAG,GAAG,IACZ,CAAC,EACD,GAAG,2BAA4B,SAAY,CACvC,KAAM,GAAO,KAAM,GACf;AAAA,uBACW,EAAQ;AAAA,aAEvB,EACM,EAAK,EAAK,cAAc,SAAS,EACjC,EAAa,EAAK,cAAc,cAAc,EAC9C,EAAY,EAAK,cAAc,aAAa,EAElD,KAAM,GAAe,CAAE,EAEvB,EAAO,EAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,EAE9B,EAAW,MAAM,EACjB,EAAO,IAAe,SAAS,aAAa,EAAE,GAAG,GAAG,KACpD,EAAO,EAAG,QAAQ,EAAE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ved.\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 { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { html } from '@spectrum-web-components/base';\nimport { Card } from '@spectrum-web-components/card';\n\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/scale-medium.js';\nimport '@spectrum-web-components/theme/theme-light.js';\nimport '@spectrum-web-components/grid/sp-grid.js';\nimport { Grid } from '@spectrum-web-components/grid';\nimport { Default } from '../stories/grid.stories.js';\nimport { sendKeys, sendMouse } from '@web/test-runner-commands';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\n\ndescribe('Grid', () => {\n testForLitDevWarnings(\n async () =>\n await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n )\n );\n it('loads default grid accessibly', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('accepts focus', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n });\n it('does not focus when clicking grid', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <sp-theme color=\"light\" scale=\"medium\">${Default()}</sp-theme>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n const firstItem = el.querySelector(el.focusableSelector) as HTMLElement;\n\n expect(firstItem === document.activeElement).to.be.true;\n\n const firstRect = firstItem?.getBoundingClientRect();\n const position = [\n Math.round(firstRect.x + firstRect.width + 2),\n Math.round(firstRect.y + 2),\n ] as [number, number];\n await sendMouse({\n type: 'click',\n position,\n });\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.false;\n });\n it('allows to tab in and out', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n const firstInput = test.querySelector('#first-input') as HTMLElement;\n const lastInput = test.querySelector('#last-input') as HTMLElement;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n firstInput.focus();\n expect(firstInput === document.activeElement).to.be.true;\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({\n press: 'Tab',\n });\n\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n expect(el.tabIndex).to.equal(-1);\n\n await sendKeys({\n press: 'Tab',\n });\n\n await nextFrame();\n await nextFrame();\n\n await elementUpdated(el);\n expect(lastInput === document.activeElement).to.be.true;\n expect(el.tabIndex).to.equal(0);\n\n await sendKeys({\n press: 'Shift+Tab',\n });\n\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n expect(\n el.querySelector(el.focusableSelector) === document.activeElement\n ).to.be.true;\n expect(el.tabIndex).to.equal(-1);\n });\n it('manages roving tabindex', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n let focused = el.querySelector(el.focusableSelector) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(5)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowLeft',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(4)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowUp',\n });\n\n focused = el.querySelector(`${el.focusableSelector}`) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n });\n it('manages selection', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n expect(el.tabIndex).to.equal(0);\n\n el.focus();\n\n await nextFrame();\n await nextFrame();\n\n let focused = el.querySelector(el.focusableSelector) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'ArrowRight',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 1 }]);\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(5)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 1 }, { id: 4 }]);\n\n await sendKeys({\n press: 'ArrowUp',\n });\n\n focused = el.querySelector(\n `${el.focusableSelector}:nth-child(2)`\n ) as Card;\n await elementUpdated(focused);\n expect(focused === document.activeElement).to.be.true;\n expect(focused.focused).to.be.true;\n\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([{ id: 4 }]);\n });\n it('does not claim lit-virtualizer on the global registry', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>${Default()}</div>\n `\n );\n const el = test.querySelector('sp-grid') as Grid;\n\n await elementUpdated(el);\n\n customElements.define('lit-virtualizer', class extends HTMLElement {});\n\n // make sure we also don't prevent *any* registration of lit-virtualizer\n expect(() => {\n customElements.define(\n 'lit-virtualizer',\n class extends HTMLElement {}\n );\n }).to.throw();\n });\n});\n"],
5
+ "mappings": ";AAYA,SAAS,gBAAgB,QAAQ,SAAS,iBAAiB;AAC3D,SAAS,YAAY;AAGrB,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AAEP,SAAS,eAAe;AACxB,SAAS,UAAU,iBAAiB;AACpC,SAAS,6BAA6B;AAEtC,SAAS,QAAQ,MAAM;AACnB;AAAA,IACI,YACI,MAAM;AAAA,MACF;AAAA,2BACW,QAAQ;AAAA;AAAA,IAEvB;AAAA,EACR;AACA,KAAG,iCAAiC,YAAY;AAC5C,UAAM,OAAO,MAAM;AAAA,MACf;AAAA,uBACW,QAAQ;AAAA;AAAA,IAEvB;AACA,UAAM,KAAK,KAAK,cAAc,SAAS;AAEvC,UAAM,eAAe,EAAE;AAEvB,UAAM,OAAO,EAAE,EAAE,GAAG,GAAG,WAAW;AAAA,EACtC,CAAC;AACD,KAAG,iBAAiB,YAAY;AAC5B,UAAM,OAAO,MAAM;AAAA,MACf;AAAA,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