@fluid-topics/ft-wc-utils 1.3.12 → 1.3.14
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/build/CacheRegistry.d.ts +1 -0
- package/build/CacheRegistry.js +10 -11
- package/build/directives/index.d.ts +1 -0
- package/build/directives/index.js +1 -0
- package/build/directives/whenSize.d.ts +24 -0
- package/build/directives/whenSize.js +55 -0
- package/build/globals.min.js +23 -16
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +2 -2
package/build/CacheRegistry.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class CacheRegistry extends WithEventBus {
|
|
|
20
20
|
register(key: string, loader: () => Promise<any>, final?: boolean): void;
|
|
21
21
|
registerFinal(key: string, loader: () => Promise<any>): void;
|
|
22
22
|
clearAll(dispatchEvent?: boolean): string[];
|
|
23
|
+
clearMatching(matcher: (key: string) => boolean, dispatchEvent?: boolean): string[];
|
|
23
24
|
clear(key: string, dispatchEvent?: boolean): string | undefined;
|
|
24
25
|
private forceClear;
|
|
25
26
|
private clearClearTimeout;
|
package/build/CacheRegistry.js
CHANGED
|
@@ -18,16 +18,15 @@ export class CacheRegistry extends WithEventBus {
|
|
|
18
18
|
this.content[key] = { ...content, loader, final, status };
|
|
19
19
|
}
|
|
20
20
|
registerFinal(key, loader) {
|
|
21
|
-
this.forceClear(key); // Force the final content to be reloaded when the loader changes
|
|
22
21
|
this.register(key, loader, true);
|
|
23
22
|
}
|
|
24
23
|
clearAll(dispatchEvent = true) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
return this.clearMatching(() => true, dispatchEvent);
|
|
25
|
+
}
|
|
26
|
+
clearMatching(matcher, dispatchEvent = true) {
|
|
27
|
+
const clearedKeys = Object.keys(this.content)
|
|
28
|
+
.filter(matcher)
|
|
29
|
+
.filter((key) => this.clear(key, false) != undefined);
|
|
31
30
|
if (dispatchEvent && clearedKeys.length > 0) {
|
|
32
31
|
this.dispatchEvent(new ClearCacheEvent(clearedKeys));
|
|
33
32
|
}
|
|
@@ -92,7 +91,7 @@ export class CacheRegistry extends WithEventBus {
|
|
|
92
91
|
content.status = "LOADING";
|
|
93
92
|
content.promise = cancelable(loader());
|
|
94
93
|
return content.promise
|
|
95
|
-
.then(value => {
|
|
94
|
+
.then((value) => {
|
|
96
95
|
content.status = "RESOLVED";
|
|
97
96
|
content.value = value;
|
|
98
97
|
if (ttl != null) {
|
|
@@ -101,7 +100,7 @@ export class CacheRegistry extends WithEventBus {
|
|
|
101
100
|
}
|
|
102
101
|
return value;
|
|
103
102
|
})
|
|
104
|
-
.catch(error => {
|
|
103
|
+
.catch((error) => {
|
|
105
104
|
var _a;
|
|
106
105
|
if (!((_a = content.promise) === null || _a === void 0 ? void 0 : _a.isCanceled)) {
|
|
107
106
|
content.status = "ERROR";
|
|
@@ -123,10 +122,10 @@ export class CacheRegistry extends WithEventBus {
|
|
|
123
122
|
return ((_a = this.content[key]) === null || _a === void 0 ? void 0 : _a.status) !== undefined && ((_b = this.content[key]) === null || _b === void 0 ? void 0 : _b.status) !== "REGISTERED";
|
|
124
123
|
}
|
|
125
124
|
resolvedKeys() {
|
|
126
|
-
return Object.keys(this.content).filter(key => { var _a; return ((_a = this.content[key]) === null || _a === void 0 ? void 0 : _a.status) === "RESOLVED"; });
|
|
125
|
+
return Object.keys(this.content).filter((key) => { var _a; return ((_a = this.content[key]) === null || _a === void 0 ? void 0 : _a.status) === "RESOLVED"; });
|
|
127
126
|
}
|
|
128
127
|
resolvedValues() {
|
|
129
|
-
return this.resolvedKeys().map(key => this.content[key].value);
|
|
128
|
+
return this.resolvedKeys().map((key) => this.content[key].value);
|
|
130
129
|
}
|
|
131
130
|
keys() {
|
|
132
131
|
return Object.keys(this.content);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./whenSize";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./whenSize";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AsyncDirective, PartInfo } from "lit/async-directive.js";
|
|
2
|
+
import { Part } from "lit";
|
|
3
|
+
export declare enum Breakpoint {
|
|
4
|
+
sm = "sm",
|
|
5
|
+
md = "md",
|
|
6
|
+
lg = "lg",
|
|
7
|
+
xl = "xl"
|
|
8
|
+
}
|
|
9
|
+
export declare class WhenSizeDirective extends AsyncDirective {
|
|
10
|
+
private size;
|
|
11
|
+
private lastArgs?;
|
|
12
|
+
constructor(partInfo: PartInfo);
|
|
13
|
+
disconnected(): void;
|
|
14
|
+
reconnected(): void;
|
|
15
|
+
private readonly onResize;
|
|
16
|
+
update(_: Part, [threshold, aboveRenderer, belowRenderer]: Parameters<WhenSizeDirective["render"]>): unknown;
|
|
17
|
+
render(thresholdOrBreakpoint: number | Breakpoint, aboveRenderer: () => unknown, maybeBelowRenderer?: () => unknown): unknown;
|
|
18
|
+
private resolveThreshold;
|
|
19
|
+
}
|
|
20
|
+
export interface WhenSizeDirectiveFn {
|
|
21
|
+
(threshold: number, aboveRenderer: () => unknown, belowRenderer?: () => unknown): unknown;
|
|
22
|
+
(breakpoint: Breakpoint, aboveRenderer: () => unknown, belowRenderer?: () => unknown): unknown;
|
|
23
|
+
}
|
|
24
|
+
export declare const whenSize: WhenSizeDirectiveFn;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AsyncDirective, directive } from "lit/async-directive.js";
|
|
2
|
+
import { nothing } from "lit";
|
|
3
|
+
export var Breakpoint;
|
|
4
|
+
(function (Breakpoint) {
|
|
5
|
+
Breakpoint["sm"] = "sm";
|
|
6
|
+
Breakpoint["md"] = "md";
|
|
7
|
+
Breakpoint["lg"] = "lg";
|
|
8
|
+
Breakpoint["xl"] = "xl";
|
|
9
|
+
})(Breakpoint || (Breakpoint = {}));
|
|
10
|
+
const BREAKPOINT_THRESHOLDS = {
|
|
11
|
+
sm: 640,
|
|
12
|
+
md: 768,
|
|
13
|
+
lg: 1024,
|
|
14
|
+
xl: 1280,
|
|
15
|
+
};
|
|
16
|
+
export class WhenSizeDirective extends AsyncDirective {
|
|
17
|
+
constructor(partInfo) {
|
|
18
|
+
super(partInfo);
|
|
19
|
+
this.size = 0;
|
|
20
|
+
this.onResize = () => {
|
|
21
|
+
const newSize = window.innerWidth;
|
|
22
|
+
if (this.size !== newSize) {
|
|
23
|
+
this.size = newSize;
|
|
24
|
+
// Force the directive to re-render
|
|
25
|
+
if (this.lastArgs) {
|
|
26
|
+
this.setValue(this.render(...this.lastArgs));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.size = window.innerWidth;
|
|
31
|
+
window.addEventListener("resize", this.onResize);
|
|
32
|
+
}
|
|
33
|
+
disconnected() {
|
|
34
|
+
window.removeEventListener("resize", this.onResize);
|
|
35
|
+
}
|
|
36
|
+
reconnected() {
|
|
37
|
+
window.addEventListener("resize", this.onResize);
|
|
38
|
+
}
|
|
39
|
+
update(_, [threshold, aboveRenderer, belowRenderer]) {
|
|
40
|
+
this.lastArgs = [threshold, aboveRenderer, belowRenderer];
|
|
41
|
+
return this.render(threshold, aboveRenderer, belowRenderer);
|
|
42
|
+
}
|
|
43
|
+
render(thresholdOrBreakpoint, aboveRenderer, maybeBelowRenderer) {
|
|
44
|
+
const threshold = this.resolveThreshold(thresholdOrBreakpoint);
|
|
45
|
+
const belowRenderer = maybeBelowRenderer !== null && maybeBelowRenderer !== void 0 ? maybeBelowRenderer : (() => nothing);
|
|
46
|
+
return this.size > threshold ? aboveRenderer() : belowRenderer();
|
|
47
|
+
}
|
|
48
|
+
resolveThreshold(arg) {
|
|
49
|
+
if (typeof arg === "number") {
|
|
50
|
+
return arg;
|
|
51
|
+
}
|
|
52
|
+
return BREAKPOINT_THRESHOLDS[arg];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export const whenSize = directive(WhenSizeDirective);
|