@spectrum-web-components/grid 0.0.6 → 0.0.9-devmode.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +1 -37
- package/package.json +25 -7
- package/sp-grid.dev.js +3 -0
- package/sp-grid.dev.js.map +7 -0
- package/sp-grid.js +3 -14
- package/sp-grid.js.map +7 -1
- package/src/Grid.dev.js +106 -0
- package/src/Grid.dev.js.map +7 -0
- package/src/Grid.js +101 -112
- package/src/Grid.js.map +7 -1
- package/src/GridController.dev.js +125 -0
- package/src/GridController.dev.js.map +7 -0
- package/src/GridController.js +118 -122
- package/src/GridController.js.map +7 -1
- package/src/grid.css.dev.js +6 -0
- package/src/grid.css.dev.js.map +7 -0
- package/src/grid.css.js +3 -14
- package/src/grid.css.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/stories/grid.stories.js +66 -85
- package/stories/grid.stories.js.map +7 -1
- package/test/benchmark/basic-test.js +5 -16
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/grid.test.js +155 -167
- package/test/grid.test.js.map +7 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ResizeController } from "@lit-labs/observers/resize_controller.js";
|
|
2
|
+
import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
|
|
3
|
+
export class GridController {
|
|
4
|
+
constructor(host, {
|
|
5
|
+
elements,
|
|
6
|
+
itemSize,
|
|
7
|
+
gap
|
|
8
|
+
}) {
|
|
9
|
+
this._first = 0;
|
|
10
|
+
this._last = 0;
|
|
11
|
+
this.handleFocusin = (event) => {
|
|
12
|
+
const doCallbackAfterPaint = (cb) => {
|
|
13
|
+
requestAnimationFrame(() => {
|
|
14
|
+
requestAnimationFrame(() => {
|
|
15
|
+
cb();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const scrollToFirst = () => this.host.scrollToIndex(0);
|
|
20
|
+
const focusIntoGrid = () => {
|
|
21
|
+
this.focus();
|
|
22
|
+
this.host.tabIndex = -1;
|
|
23
|
+
};
|
|
24
|
+
if (event.target === this.host) {
|
|
25
|
+
if (this._first > 0) {
|
|
26
|
+
doCallbackAfterPaint(() => {
|
|
27
|
+
scrollToFirst();
|
|
28
|
+
doCallbackAfterPaint(focusIntoGrid);
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
doCallbackAfterPaint(focusIntoGrid);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.handleFocusout = (event) => {
|
|
36
|
+
if (event.relatedTarget && !this.host.contains(event.relatedTarget)) {
|
|
37
|
+
this.host.tabIndex = 0;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.handleRangeChanged = (event) => {
|
|
41
|
+
this.rovingTabindexController.clearElementCache(event.first);
|
|
42
|
+
};
|
|
43
|
+
this.handleVisibleChanged = (event) => {
|
|
44
|
+
this._first = event.first;
|
|
45
|
+
this._last = event.last;
|
|
46
|
+
};
|
|
47
|
+
this.host = host;
|
|
48
|
+
this.host.addController(this);
|
|
49
|
+
this.applyLayout(itemSize, gap);
|
|
50
|
+
this.resizeController = new ResizeController(this.host, {
|
|
51
|
+
callback: (entries) => {
|
|
52
|
+
entries.forEach((entry) => {
|
|
53
|
+
this.measureDirectionLength(entry.contentRect);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.rovingTabindexController = new RovingTabindexController(this.host, {
|
|
58
|
+
direction: "grid",
|
|
59
|
+
elements,
|
|
60
|
+
focusInIndex: () => {
|
|
61
|
+
const activeElement = this.host.getRootNode().activeElement;
|
|
62
|
+
return activeElement === this.host ? 0 : -1;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
get itemSize() {
|
|
67
|
+
return this._itemSize();
|
|
68
|
+
}
|
|
69
|
+
_itemSize() {
|
|
70
|
+
return {
|
|
71
|
+
width: 100,
|
|
72
|
+
height: 100
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
get gap() {
|
|
76
|
+
return this._gap();
|
|
77
|
+
}
|
|
78
|
+
_gap() {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
focus(options) {
|
|
82
|
+
this.rovingTabindexController.focus(options);
|
|
83
|
+
}
|
|
84
|
+
applyLayout(itemSize, gap) {
|
|
85
|
+
if (typeof itemSize === "object") {
|
|
86
|
+
this._itemSize = () => itemSize;
|
|
87
|
+
} else if (typeof itemSize === "function" && typeof itemSize() !== "undefined") {
|
|
88
|
+
this._itemSize = itemSize;
|
|
89
|
+
}
|
|
90
|
+
if (typeof gap === "string") {
|
|
91
|
+
this._gap = () => gap;
|
|
92
|
+
} else if (typeof gap === "function") {
|
|
93
|
+
this._gap = gap;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
update({
|
|
97
|
+
elements,
|
|
98
|
+
itemSize,
|
|
99
|
+
gap
|
|
100
|
+
}) {
|
|
101
|
+
this.rovingTabindexController.update({ elements });
|
|
102
|
+
this.applyLayout(itemSize, gap);
|
|
103
|
+
const contentRect = this.host.getBoundingClientRect();
|
|
104
|
+
this.measureDirectionLength(contentRect);
|
|
105
|
+
}
|
|
106
|
+
measureDirectionLength(contentRect) {
|
|
107
|
+
const gap = this.gap ? parseFloat(this.gap) : 0;
|
|
108
|
+
this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
|
|
109
|
+
}
|
|
110
|
+
hostConnected() {
|
|
111
|
+
this.host.addEventListener("rangeChanged", this.handleRangeChanged);
|
|
112
|
+
this.host.addEventListener("visibilityChanged", this.handleVisibleChanged);
|
|
113
|
+
this.host.addEventListener("focusin", this.handleFocusin);
|
|
114
|
+
this.host.addEventListener("focusout", this.handleFocusout);
|
|
115
|
+
this.host.tabIndex = 0;
|
|
116
|
+
this.host.style.setProperty("outline", "none", "important");
|
|
117
|
+
}
|
|
118
|
+
hostDisconnected() {
|
|
119
|
+
this.host.removeEventListener("rangeChanged", this.handleRangeChanged);
|
|
120
|
+
this.host.removeEventListener("visibilityChanged", this.handleVisibleChanged);
|
|
121
|
+
this.host.removeEventListener("focusin", this.handleFocusin);
|
|
122
|
+
this.host.removeEventListener("focusout", this.handleFocusout);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=GridController.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["GridController.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: ReactiveElement;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: ReactiveElement,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => (this.host as any).scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAaA;AACA;AAWO,aAAM,eAEb;AAAA,EAkCI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,KAMN;AAzBF,kBAAS;AAYT,iBAAQ;AAqFE,yBAAgB,CAAC,UAA4B;AACnD,YAAM,uBAAuB,CAAC,OAAyB;AACnD,8BAAsB,MAAM;AACxB,gCAAsB,MAAM;AACxB,eAAG;AAAA,UACP,CAAC;AAAA,QACL,CAAC;AAAA,MACL;AACA,YAAM,gBAAgB,MAAa,KAAK,KAAa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,oBAAoB,gBAAgB,KAAK,kBAAkB;AACrE,SAAK,KAAK,oBACN,qBACA,KAAK,oBACT;AACA,SAAK,KAAK,oBAAoB,WAAW,KAAK,aAAa;AAC3D,SAAK,KAAK,oBAAoB,YAAY,KAAK,cAAc;AAAA,EACjE;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/GridController.js
CHANGED
|
@@ -1,129 +1,125 @@
|
|
|
1
|
-
import { ResizeController } from
|
|
2
|
-
import { RovingTabindexController } from
|
|
1
|
+
import { ResizeController } from "@lit-labs/observers/resize_controller.js";
|
|
2
|
+
import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
|
|
3
3
|
export class GridController {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const scrollToFirst = () => this.host.scrollToIndex(0);
|
|
18
|
-
const focusIntoGrid = () => {
|
|
19
|
-
this.focus();
|
|
20
|
-
this.host.tabIndex = -1;
|
|
21
|
-
};
|
|
22
|
-
if (event.target === this.host) {
|
|
23
|
-
if (this._first > 0) {
|
|
24
|
-
doCallbackAfterPaint(() => {
|
|
25
|
-
scrollToFirst();
|
|
26
|
-
doCallbackAfterPaint(focusIntoGrid);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
doCallbackAfterPaint(focusIntoGrid);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
this.handleFocusout = (event) => {
|
|
35
|
-
if (event.relatedTarget &&
|
|
36
|
-
!this.host.contains(event.relatedTarget)) {
|
|
37
|
-
this.host.tabIndex = 0;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
this.handleRangeChanged = (event) => {
|
|
41
|
-
this.rovingTabindexController.clearElementCache(event.first);
|
|
42
|
-
};
|
|
43
|
-
this.handleVisibleChanged = (event) => {
|
|
44
|
-
this._first = event.first;
|
|
45
|
-
this._last = event.last;
|
|
46
|
-
};
|
|
47
|
-
this.host = host;
|
|
48
|
-
this.host.addController(this);
|
|
49
|
-
this.applyLayout(itemSize, gap);
|
|
50
|
-
this.resizeController = new ResizeController(this.host, {
|
|
51
|
-
callback: (entries) => {
|
|
52
|
-
entries.forEach((entry) => {
|
|
53
|
-
this.measureDirectionLength(entry.contentRect);
|
|
54
|
-
});
|
|
55
|
-
},
|
|
4
|
+
constructor(host, {
|
|
5
|
+
elements,
|
|
6
|
+
itemSize,
|
|
7
|
+
gap
|
|
8
|
+
}) {
|
|
9
|
+
this._first = 0;
|
|
10
|
+
this._last = 0;
|
|
11
|
+
this.handleFocusin = (event) => {
|
|
12
|
+
const doCallbackAfterPaint = (cb) => {
|
|
13
|
+
requestAnimationFrame(() => {
|
|
14
|
+
requestAnimationFrame(() => {
|
|
15
|
+
cb();
|
|
16
|
+
});
|
|
56
17
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_itemSize() {
|
|
72
|
-
return {
|
|
73
|
-
width: 100,
|
|
74
|
-
height: 100,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
get gap() {
|
|
78
|
-
return this._gap();
|
|
79
|
-
}
|
|
80
|
-
/* c8 ignore next 3 */
|
|
81
|
-
_gap() {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
focus(options) {
|
|
85
|
-
this.rovingTabindexController.focus(options);
|
|
86
|
-
}
|
|
87
|
-
applyLayout(itemSize, gap) {
|
|
88
|
-
/* c8 ignore next 2 */
|
|
89
|
-
if (typeof itemSize === 'object') {
|
|
90
|
-
this._itemSize = () => itemSize;
|
|
18
|
+
};
|
|
19
|
+
const scrollToFirst = () => this.host.scrollToIndex(0);
|
|
20
|
+
const focusIntoGrid = () => {
|
|
21
|
+
this.focus();
|
|
22
|
+
this.host.tabIndex = -1;
|
|
23
|
+
};
|
|
24
|
+
if (event.target === this.host) {
|
|
25
|
+
if (this._first > 0) {
|
|
26
|
+
doCallbackAfterPaint(() => {
|
|
27
|
+
scrollToFirst();
|
|
28
|
+
doCallbackAfterPaint(focusIntoGrid);
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
doCallbackAfterPaint(focusIntoGrid);
|
|
91
32
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/* c8 ignore next 2 */
|
|
97
|
-
if (typeof gap === 'string') {
|
|
98
|
-
this._gap = () => gap;
|
|
99
|
-
}
|
|
100
|
-
else if (typeof gap === 'function') {
|
|
101
|
-
this._gap = gap;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
update({ elements, itemSize, gap, }) {
|
|
105
|
-
this.rovingTabindexController.update({ elements });
|
|
106
|
-
this.applyLayout(itemSize, gap);
|
|
107
|
-
const contentRect = this.host.getBoundingClientRect();
|
|
108
|
-
this.measureDirectionLength(contentRect);
|
|
109
|
-
}
|
|
110
|
-
measureDirectionLength(contentRect) {
|
|
111
|
-
const gap = this.gap ? parseFloat(this.gap) : 0;
|
|
112
|
-
this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
|
|
113
|
-
}
|
|
114
|
-
hostConnected() {
|
|
115
|
-
this.host.addEventListener('rangeChanged', this.handleRangeChanged);
|
|
116
|
-
this.host.addEventListener('visibilityChanged', this.handleVisibleChanged);
|
|
117
|
-
this.host.addEventListener('focusin', this.handleFocusin);
|
|
118
|
-
this.host.addEventListener('focusout', this.handleFocusout);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.handleFocusout = (event) => {
|
|
36
|
+
if (event.relatedTarget && !this.host.contains(event.relatedTarget)) {
|
|
119
37
|
this.host.tabIndex = 0;
|
|
120
|
-
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.handleRangeChanged = (event) => {
|
|
41
|
+
this.rovingTabindexController.clearElementCache(event.first);
|
|
42
|
+
};
|
|
43
|
+
this.handleVisibleChanged = (event) => {
|
|
44
|
+
this._first = event.first;
|
|
45
|
+
this._last = event.last;
|
|
46
|
+
};
|
|
47
|
+
this.host = host;
|
|
48
|
+
this.host.addController(this);
|
|
49
|
+
this.applyLayout(itemSize, gap);
|
|
50
|
+
this.resizeController = new ResizeController(this.host, {
|
|
51
|
+
callback: (entries) => {
|
|
52
|
+
entries.forEach((entry) => {
|
|
53
|
+
this.measureDirectionLength(entry.contentRect);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.rovingTabindexController = new RovingTabindexController(this.host, {
|
|
58
|
+
direction: "grid",
|
|
59
|
+
elements,
|
|
60
|
+
focusInIndex: () => {
|
|
61
|
+
const activeElement = this.host.getRootNode().activeElement;
|
|
62
|
+
return activeElement === this.host ? 0 : -1;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
get itemSize() {
|
|
67
|
+
return this._itemSize();
|
|
68
|
+
}
|
|
69
|
+
_itemSize() {
|
|
70
|
+
return {
|
|
71
|
+
width: 100,
|
|
72
|
+
height: 100
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
get gap() {
|
|
76
|
+
return this._gap();
|
|
77
|
+
}
|
|
78
|
+
_gap() {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
focus(options) {
|
|
82
|
+
this.rovingTabindexController.focus(options);
|
|
83
|
+
}
|
|
84
|
+
applyLayout(itemSize, gap) {
|
|
85
|
+
if (typeof itemSize === "object") {
|
|
86
|
+
this._itemSize = () => itemSize;
|
|
87
|
+
} else if (typeof itemSize === "function" && typeof itemSize() !== "undefined") {
|
|
88
|
+
this._itemSize = itemSize;
|
|
121
89
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.host.removeEventListener('focusout', this.handleFocusout);
|
|
90
|
+
if (typeof gap === "string") {
|
|
91
|
+
this._gap = () => gap;
|
|
92
|
+
} else if (typeof gap === "function") {
|
|
93
|
+
this._gap = gap;
|
|
127
94
|
}
|
|
95
|
+
}
|
|
96
|
+
update({
|
|
97
|
+
elements,
|
|
98
|
+
itemSize,
|
|
99
|
+
gap
|
|
100
|
+
}) {
|
|
101
|
+
this.rovingTabindexController.update({ elements });
|
|
102
|
+
this.applyLayout(itemSize, gap);
|
|
103
|
+
const contentRect = this.host.getBoundingClientRect();
|
|
104
|
+
this.measureDirectionLength(contentRect);
|
|
105
|
+
}
|
|
106
|
+
measureDirectionLength(contentRect) {
|
|
107
|
+
const gap = this.gap ? parseFloat(this.gap) : 0;
|
|
108
|
+
this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
|
|
109
|
+
}
|
|
110
|
+
hostConnected() {
|
|
111
|
+
this.host.addEventListener("rangeChanged", this.handleRangeChanged);
|
|
112
|
+
this.host.addEventListener("visibilityChanged", this.handleVisibleChanged);
|
|
113
|
+
this.host.addEventListener("focusin", this.handleFocusin);
|
|
114
|
+
this.host.addEventListener("focusout", this.handleFocusout);
|
|
115
|
+
this.host.tabIndex = 0;
|
|
116
|
+
this.host.style.setProperty("outline", "none", "important");
|
|
117
|
+
}
|
|
118
|
+
hostDisconnected() {
|
|
119
|
+
this.host.removeEventListener("rangeChanged", this.handleRangeChanged);
|
|
120
|
+
this.host.removeEventListener("visibilityChanged", this.handleVisibleChanged);
|
|
121
|
+
this.host.removeEventListener("focusin", this.handleFocusin);
|
|
122
|
+
this.host.removeEventListener("focusout", this.handleFocusout);
|
|
123
|
+
}
|
|
128
124
|
}
|
|
129
|
-
//# sourceMappingURL=GridController.js.map
|
|
125
|
+
//# sourceMappingURL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5B,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IACnE,CAAC;CACJ","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"]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["GridController.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: ReactiveElement;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: ReactiveElement,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => (this.host as any).scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\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QAAQ,IACvD;AAAA,EACJ;AAAA,EA6CO,gBAAsB;AACzB,SAAK,KAAK,iBAAiB,gBAAgB,KAAK,kBAAkB;AAClE,SAAK,KAAK,iBACN,qBACA,KAAK,oBACT;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,oBACN,qBACA,KAAK,oBACT;AACA,SAAK,KAAK,oBAAoB,WAAW,KAAK,aAAa;AAC3D,SAAK,KAAK,oBAAoB,YAAY,KAAK,cAAc;AAAA,EACjE;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["grid.css.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{contain:strict;display:block;position:relative}\n`;\nexport default styles;"],
|
|
5
|
+
"mappings": "AAWA;AACA,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/grid.css.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { css } from '@spectrum-web-components/base';
|
|
13
|
-
const styles = css `
|
|
1
|
+
import { css } from "@spectrum-web-components/base";
|
|
2
|
+
const styles = css`
|
|
14
3
|
:host{contain:strict;display:block;position:relative}
|
|
15
4
|
`;
|
|
16
5
|
export default styles;
|
|
17
|
-
//# sourceMappingURL=grid.css.js.map
|
|
6
|
+
//# sourceMappingURL=grid.css.js.map
|
package/src/grid.css.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["grid.css.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{contain:strict;display:block;position:relative}\n`;\nexport default styles;"],
|
|
5
|
+
"mappings": "AAWA;AACA,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/index.dev.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Grid.dev.js'\n"],
|
|
5
|
+
"mappings": "AAYA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
export * from './Grid.js';
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./Grid.js";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Grid.js';\n"],
|
|
5
|
+
"mappings": "AAYA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|