@leavittsoftware/web 6.17.0 → 6.18.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leavittsoftware/web",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.18.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"files": [
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"url": "https://github.com/LeavittSoftware/titanium-elements/issues"
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/LeavittSoftware/titanium-elements/#readme",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "d8f0da546c56d904beb979d456b2cb3e7e375c0e"
|
|
48
48
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PendingStateEvent } from '../types/pending-state-event';
|
|
2
|
+
export const PendingStateCatcher = (base) => class extends base {
|
|
3
|
+
static get properties() {
|
|
4
|
+
return {
|
|
5
|
+
stateIsPending: { type: Boolean },
|
|
6
|
+
pendingStateCatcherTarget: { type: HTMLElement },
|
|
7
|
+
pendingStateCatcherLoadingStartDelay: { type: Number },
|
|
8
|
+
pendingStateCatcherMinTimeOpen: { type: Number },
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
#stateIsPending_accessor_storage;
|
|
12
|
+
/**
|
|
13
|
+
* !! Handled by the pending state catcher !!
|
|
14
|
+
*/
|
|
15
|
+
get stateIsPending() { return this.#stateIsPending_accessor_storage; }
|
|
16
|
+
set stateIsPending(value) { this.#stateIsPending_accessor_storage = value; }
|
|
17
|
+
#pendingStateCatcherLoadingStartDelay_accessor_storage = 75;
|
|
18
|
+
/**
|
|
19
|
+
* Promises faster than this do not cause stateIsPending to be set to true at all
|
|
20
|
+
* Prevents flicker for fast promises
|
|
21
|
+
*/
|
|
22
|
+
get pendingStateCatcherLoadingStartDelay() { return this.#pendingStateCatcherLoadingStartDelay_accessor_storage; }
|
|
23
|
+
set pendingStateCatcherLoadingStartDelay(value) { this.#pendingStateCatcherLoadingStartDelay_accessor_storage = value; }
|
|
24
|
+
#pendingStateCatcherMinTimeOpen_accessor_storage = 350;
|
|
25
|
+
/**
|
|
26
|
+
* min time stateIsPending must remain true
|
|
27
|
+
*/
|
|
28
|
+
get pendingStateCatcherMinTimeOpen() { return this.#pendingStateCatcherMinTimeOpen_accessor_storage; }
|
|
29
|
+
set pendingStateCatcherMinTimeOpen(value) { this.#pendingStateCatcherMinTimeOpen_accessor_storage = value; }
|
|
30
|
+
#pendingStateCatcherTarget_accessor_storage;
|
|
31
|
+
/**
|
|
32
|
+
* async reference to the element that will be used to listen for pending state events
|
|
33
|
+
* defaults to window
|
|
34
|
+
*/
|
|
35
|
+
get pendingStateCatcherTarget() { return this.#pendingStateCatcherTarget_accessor_storage; }
|
|
36
|
+
set pendingStateCatcherTarget(value) { this.#pendingStateCatcherTarget_accessor_storage = value; }
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
#loadingDelayTimer;
|
|
41
|
+
#closeDelayTimer;
|
|
42
|
+
#openCount = 0;
|
|
43
|
+
#timeStampOfLoadingStart;
|
|
44
|
+
async connectedCallback() {
|
|
45
|
+
super.connectedCallback();
|
|
46
|
+
const target = (await this.pendingStateCatcherTarget) || window;
|
|
47
|
+
target.addEventListener(PendingStateEvent.eventType, this.#handlePendingStateEvent.bind(this));
|
|
48
|
+
}
|
|
49
|
+
disconnectedCallback() {
|
|
50
|
+
super.disconnectedCallback();
|
|
51
|
+
window.removeEventListener(PendingStateEvent.eventType, this.#handlePendingStateEvent);
|
|
52
|
+
}
|
|
53
|
+
async #handlePendingStateEvent(e) {
|
|
54
|
+
this.#loadingStarted();
|
|
55
|
+
this.#openCount++;
|
|
56
|
+
try {
|
|
57
|
+
await e.detail.promise;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Do nothing, this will be handled by others
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
this.#openCount--;
|
|
64
|
+
if (this.#openCount === 0) {
|
|
65
|
+
this.#loadingStopped();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
#loadingStarted() {
|
|
70
|
+
window.clearTimeout(this.#loadingDelayTimer);
|
|
71
|
+
//If new event is received while close timer is running, prevent the close
|
|
72
|
+
window.clearTimeout(this.#closeDelayTimer);
|
|
73
|
+
this.#loadingDelayTimer = window.setTimeout(() => {
|
|
74
|
+
this.#timeStampOfLoadingStart = performance.now();
|
|
75
|
+
this.stateIsPending = true;
|
|
76
|
+
}, this.pendingStateCatcherLoadingStartDelay);
|
|
77
|
+
}
|
|
78
|
+
#loadingStopped() {
|
|
79
|
+
window.clearTimeout(this.#loadingDelayTimer);
|
|
80
|
+
const totalTimeOpened = performance.now() - this.#timeStampOfLoadingStart;
|
|
81
|
+
const loadingStopDelay = Math.max(this.pendingStateCatcherMinTimeOpen - totalTimeOpened, 0);
|
|
82
|
+
this.#closeDelayTimer = window.setTimeout(() => {
|
|
83
|
+
this.stateIsPending = false;
|
|
84
|
+
}, loadingStopDelay);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=pending-state-catcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-state-catcher.js","sourceRoot":"","sources":["pending-state-catcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAoC,IAAO,EAAE,EAAE,CAChF,KAAM,SAAQ,IAAI;IAChB,MAAM,KAAK,UAAU;QACnB,OAAO;YACL,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;YACjC,yBAAyB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAChD,oCA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