js-kompo-utils 1.0.36 → 1.0.38
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.
|
@@ -297,10 +297,11 @@ export default {
|
|
|
297
297
|
mounted() {
|
|
298
298
|
// Close dropdown when clicking outside
|
|
299
299
|
document.addEventListener('click', this.handleClickOutside)
|
|
300
|
-
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
-
|
|
300
|
+
|
|
301
|
+
// `component` is not guaranteed to be bound when data() runs — see phoneValue's `?.` — and
|
|
302
|
+
// a country read as undefined there would send us asking an IP service we don't need.
|
|
303
|
+
this.selectedCountryCode = this.selectedCountryCode || this.$_config('country') || this.$_config('defaultCountry')
|
|
304
|
+
|
|
304
305
|
// A stored number always decides its own country; an empty field may ask the IP.
|
|
305
306
|
if (this.phoneValue) {
|
|
306
307
|
this.autoDetectCountryFromPhone(this.phoneValue)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { installGlobalLoading } from './loading/globalLoading.js';
|
|
2
|
+
|
|
1
3
|
export class KompoJsConfigBuilder {
|
|
2
4
|
components = {};
|
|
3
5
|
bootstrapCallback = null;
|
|
@@ -13,6 +15,7 @@ export class KompoJsConfigBuilder {
|
|
|
13
15
|
appSelector = '#app';
|
|
14
16
|
includeBroadcasting = false;
|
|
15
17
|
echoBroadcasterConfig = null;
|
|
18
|
+
includeGlobalLoading = true;
|
|
16
19
|
|
|
17
20
|
beforeStepCallbacks = {};
|
|
18
21
|
afterStepCallbacks = {};
|
|
@@ -138,6 +141,16 @@ export class KompoJsConfigBuilder {
|
|
|
138
141
|
return this;
|
|
139
142
|
}
|
|
140
143
|
|
|
144
|
+
withGlobalLoading() {
|
|
145
|
+
this.includeGlobalLoading = true;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
withoutGlobalLoading() {
|
|
150
|
+
this.includeGlobalLoading = false;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
141
154
|
withBroadcasting(config) {
|
|
142
155
|
this.includeBroadcasting = true;
|
|
143
156
|
this.echoBroadcasterConfig = {
|
|
@@ -231,6 +244,8 @@ export class KompoJsInitializer {
|
|
|
231
244
|
|
|
232
245
|
this._callStep('bootVue');
|
|
233
246
|
|
|
247
|
+
this._callStep('bootGlobalLoadingIfRequired');
|
|
248
|
+
|
|
234
249
|
this._callStep('decorateWindow');
|
|
235
250
|
|
|
236
251
|
this._callStep('bootCkEditorIfRequired');
|
|
@@ -311,6 +326,12 @@ export class KompoJsInitializer {
|
|
|
311
326
|
}
|
|
312
327
|
}
|
|
313
328
|
|
|
329
|
+
bootGlobalLoadingIfRequired() {
|
|
330
|
+
if (this.config.includeGlobalLoading) {
|
|
331
|
+
installGlobalLoading(this.window, this.window.document);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
314
335
|
decorateWindow() {
|
|
315
336
|
for (const [key, value] of Object.entries(this.config.windowUtilsObject)) {
|
|
316
337
|
if (!this.window.utils) {
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const HOST_ID = 'vl-global-loading'
|
|
2
|
+
const HOST_CLASS = 'vlGlobalLoading'
|
|
3
|
+
const LEGACY_ID = 'vl-spinner'
|
|
4
|
+
const LEGACY_KEY = '__legacy__'
|
|
5
|
+
const DEFAULT_WATCHDOG_MS = 20000
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Ref-counted full-screen loading, owned by us.
|
|
9
|
+
* Writes only .vlGlobalLoading — .vlPanelLoading stays vue-kompo's (->withLoadingIn).
|
|
10
|
+
*/
|
|
11
|
+
export function installGlobalLoading(win, doc, options = {}) {
|
|
12
|
+
if (!win || !win._kompo || win._kompo.loading) return
|
|
13
|
+
|
|
14
|
+
const watchdogMs = options.watchdogMs || DEFAULT_WATCHDOG_MS
|
|
15
|
+
const keys = new Map()
|
|
16
|
+
let seq = 0
|
|
17
|
+
|
|
18
|
+
const host = () => doc.getElementById(HOST_ID)
|
|
19
|
+
|
|
20
|
+
// kompo::scripts emits the <script> tags BEFORE @includeIf('kompo.scripts'),
|
|
21
|
+
// so neither the host nor #vl-spinner exists yet when we install. Resolve
|
|
22
|
+
// both lazily on every render instead of once at install time.
|
|
23
|
+
const hideLegacySpinner = () => {
|
|
24
|
+
const el = doc.getElementById(LEGACY_ID)
|
|
25
|
+
if (el) el.style.display = 'none'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const render = () => {
|
|
29
|
+
hideLegacySpinner()
|
|
30
|
+
const el = host()
|
|
31
|
+
if (!el) return
|
|
32
|
+
if (keys.size) el.classList.add(HOST_CLASS)
|
|
33
|
+
else el.classList.remove(HOST_CLASS)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const end = (key) => {
|
|
37
|
+
if (!keys.has(key)) return
|
|
38
|
+
clearTimeout(keys.get(key))
|
|
39
|
+
keys.delete(key)
|
|
40
|
+
render()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const begin = (key, timeoutMs) => {
|
|
44
|
+
const k = key || `k${++seq}`
|
|
45
|
+
if (keys.has(k)) clearTimeout(keys.get(k))
|
|
46
|
+
keys.set(k, setTimeout(() => end(k), timeoutMs || watchdogMs))
|
|
47
|
+
render()
|
|
48
|
+
return k
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const clear = () => {
|
|
52
|
+
keys.forEach(t => clearTimeout(t))
|
|
53
|
+
keys.clear()
|
|
54
|
+
render()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
win._kompo.loading = { begin, end, clear, active: () => keys.size > 0 }
|
|
58
|
+
|
|
59
|
+
// Route TurboClick / Layout / $k.loading through the same host, ref-counted.
|
|
60
|
+
// Layout.$_state fires toggleSpinner('none') on unrelated state writes, so a
|
|
61
|
+
// legacy hide must only drop the legacy slot, never keys opened by begin().
|
|
62
|
+
const rawToggle = win._kompo.toggleSpinner
|
|
63
|
+
win._kompo.toggleSpinner = function (display) {
|
|
64
|
+
if (display === 'block') begin(LEGACY_KEY)
|
|
65
|
+
else end(LEGACY_KEY)
|
|
66
|
+
}
|
|
67
|
+
win._kompo.toggleSpinnerRaw = rawToggle
|
|
68
|
+
|
|
69
|
+
// ->submit() never reaches applyLoadingPanel (Action.js submitFormAction),
|
|
70
|
+
// so tear down on the form lifecycle events instead.
|
|
71
|
+
const bus = win.Vue && win.Vue.prototype && win.Vue.prototype.$kompo
|
|
72
|
+
if (bus) {
|
|
73
|
+
const onSuccess = bus.vlSubmitSuccess
|
|
74
|
+
const onError = bus.vlSubmitError
|
|
75
|
+
bus.vlSubmitSuccess = function (...args) { clear(); return onSuccess.apply(this, args) }
|
|
76
|
+
bus.vlSubmitError = function (...args) { clear(); return onError.apply(this, args) }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
render()
|
|
80
|
+
}
|