@grafana/scenes 4.29.1--canary.765.9461208757.0 → 4.29.1--canary.765.9462062093.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/services/UrlSyncManager.js +72 -30
- package/dist/esm/services/UrlSyncManager.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.js +91 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
@@ -2,20 +2,42 @@ import { locationService } from '@grafana/runtime';
|
|
2
2
|
import { SceneObjectStateChangedEvent } from '../core/events.js';
|
3
3
|
import { writeSceneLog } from '../utils/writeSceneLog.js';
|
4
4
|
import { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper.js';
|
5
|
-
import {
|
5
|
+
import { syncStateFromUrl, getUrlState, isUrlValueEqual } from './utils.js';
|
6
6
|
|
7
|
+
var __accessCheck = (obj, member, msg) => {
|
8
|
+
if (!member.has(obj))
|
9
|
+
throw TypeError("Cannot " + msg);
|
10
|
+
};
|
11
|
+
var __privateGet = (obj, member, getter) => {
|
12
|
+
__accessCheck(obj, member, "read from private field");
|
13
|
+
return getter ? getter.call(obj) : member.get(obj);
|
14
|
+
};
|
15
|
+
var __privateAdd = (obj, member, value) => {
|
16
|
+
if (member.has(obj))
|
17
|
+
throw TypeError("Cannot add the same private member more than once");
|
18
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
19
|
+
};
|
20
|
+
var __privateSet = (obj, member, value, setter) => {
|
21
|
+
__accessCheck(obj, member, "write to private field");
|
22
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
23
|
+
return value;
|
24
|
+
};
|
25
|
+
var _urlKeyMapper, _sceneRoot, _stateSub, _lastLocation, _paramsCache, _onStateChanged, _cache, _location;
|
7
26
|
class UrlSyncManager {
|
8
27
|
constructor() {
|
9
|
-
this
|
10
|
-
this
|
11
|
-
this
|
28
|
+
__privateAdd(this, _urlKeyMapper, new UniqueUrlKeyMapper());
|
29
|
+
__privateAdd(this, _sceneRoot, void 0);
|
30
|
+
__privateAdd(this, _stateSub, null);
|
31
|
+
__privateAdd(this, _lastLocation, void 0);
|
32
|
+
__privateAdd(this, _paramsCache, new UrlParamsCache());
|
33
|
+
__privateAdd(this, _onStateChanged, ({ payload }) => {
|
12
34
|
const changedObject = payload.changedObject;
|
13
35
|
if (changedObject.urlSync) {
|
14
36
|
const newUrlState = changedObject.urlSync.getUrlState();
|
15
37
|
const searchParams = locationService.getSearch();
|
16
38
|
const mappedUpdated = {};
|
17
39
|
for (const [key, newUrlValue] of Object.entries(newUrlState)) {
|
18
|
-
const uniqueKey = this
|
40
|
+
const uniqueKey = __privateGet(this, _urlKeyMapper).getUniqueKey(key, changedObject);
|
19
41
|
const currentUrlValue = searchParams.getAll(uniqueKey);
|
20
42
|
if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {
|
21
43
|
mappedUpdated[uniqueKey] = newUrlValue;
|
@@ -24,63 +46,83 @@ class UrlSyncManager {
|
|
24
46
|
if (Object.keys(mappedUpdated).length > 0) {
|
25
47
|
writeSceneLog("UrlSyncManager", "onStateChange updating URL");
|
26
48
|
locationService.partial(mappedUpdated, true);
|
27
|
-
this
|
28
|
-
this._urlParams = new URLSearchParams(this._lastLocation.search);
|
49
|
+
__privateSet(this, _lastLocation, locationService.getLocation());
|
29
50
|
}
|
30
51
|
}
|
31
|
-
};
|
52
|
+
});
|
32
53
|
}
|
33
54
|
initSync(root) {
|
34
55
|
var _a;
|
35
|
-
if (this
|
36
|
-
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = this
|
37
|
-
this
|
56
|
+
if (__privateGet(this, _stateSub)) {
|
57
|
+
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = __privateGet(this, _sceneRoot)) == null ? void 0 : _a.state.key);
|
58
|
+
__privateGet(this, _stateSub).unsubscribe();
|
38
59
|
}
|
39
60
|
writeSceneLog("UrlSyncManager", "init", root.state.key);
|
40
|
-
this
|
41
|
-
this
|
42
|
-
this
|
43
|
-
this
|
44
|
-
this.
|
45
|
-
this.handleNewObject(this._sceneRoot);
|
61
|
+
__privateSet(this, _sceneRoot, root);
|
62
|
+
__privateSet(this, _stateSub, root.subscribeToEvent(SceneObjectStateChangedEvent, __privateGet(this, _onStateChanged)));
|
63
|
+
__privateGet(this, _urlKeyMapper).clear();
|
64
|
+
__privateSet(this, _lastLocation, locationService.getLocation());
|
65
|
+
this.handleNewObject(__privateGet(this, _sceneRoot));
|
46
66
|
}
|
47
67
|
cleanUp(root) {
|
48
|
-
if (this
|
68
|
+
if (__privateGet(this, _sceneRoot) !== root) {
|
49
69
|
return;
|
50
70
|
}
|
51
71
|
writeSceneLog("UrlSyncManager", "Clean up");
|
52
|
-
if (this
|
53
|
-
this
|
54
|
-
this
|
72
|
+
if (__privateGet(this, _stateSub)) {
|
73
|
+
__privateGet(this, _stateSub).unsubscribe();
|
74
|
+
__privateSet(this, _stateSub, null);
|
55
75
|
writeSceneLog(
|
56
76
|
"UrlSyncManager",
|
57
77
|
"Root deactived, unsub to state",
|
58
78
|
"same key",
|
59
|
-
this
|
79
|
+
__privateGet(this, _sceneRoot).state.key === root.state.key
|
60
80
|
);
|
61
81
|
}
|
62
|
-
this
|
63
|
-
this
|
82
|
+
__privateSet(this, _sceneRoot, void 0);
|
83
|
+
__privateSet(this, _lastLocation, void 0);
|
64
84
|
}
|
65
85
|
handleNewLocation(location) {
|
66
|
-
if (!this
|
86
|
+
if (!__privateGet(this, _sceneRoot) || __privateGet(this, _lastLocation) === location) {
|
67
87
|
return;
|
68
88
|
}
|
69
89
|
writeSceneLog("UrlSyncManager", "handleNewLocation");
|
70
|
-
this
|
71
|
-
this.
|
72
|
-
syncStateFromUrl(this._sceneRoot, this._urlParams, this._urlKeyMapper);
|
90
|
+
__privateSet(this, _lastLocation, location);
|
91
|
+
syncStateFromUrl(__privateGet(this, _sceneRoot), __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
73
92
|
}
|
74
93
|
handleNewObject(sceneObj) {
|
75
|
-
if (!this
|
94
|
+
if (!__privateGet(this, _sceneRoot)) {
|
76
95
|
return;
|
77
96
|
}
|
78
|
-
syncStateFromUrl(sceneObj, this.
|
97
|
+
syncStateFromUrl(sceneObj, __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
79
98
|
}
|
80
99
|
getUrlState(root) {
|
81
100
|
return getUrlState(root);
|
82
101
|
}
|
83
102
|
}
|
103
|
+
_urlKeyMapper = new WeakMap();
|
104
|
+
_sceneRoot = new WeakMap();
|
105
|
+
_stateSub = new WeakMap();
|
106
|
+
_lastLocation = new WeakMap();
|
107
|
+
_paramsCache = new WeakMap();
|
108
|
+
_onStateChanged = new WeakMap();
|
109
|
+
class UrlParamsCache {
|
110
|
+
constructor() {
|
111
|
+
__privateAdd(this, _cache, void 0);
|
112
|
+
__privateAdd(this, _location, void 0);
|
113
|
+
}
|
114
|
+
getParams() {
|
115
|
+
const location = locationService.getLocation();
|
116
|
+
if (__privateGet(this, _location) === location) {
|
117
|
+
return __privateGet(this, _cache);
|
118
|
+
}
|
119
|
+
__privateSet(this, _location, location);
|
120
|
+
__privateSet(this, _cache, new URLSearchParams(location.search));
|
121
|
+
return __privateGet(this, _cache);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
_cache = new WeakMap();
|
125
|
+
_location = new WeakMap();
|
84
126
|
let urlSyncManager;
|
85
127
|
function getUrlSyncManager() {
|
86
128
|
if (!urlSyncManager) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"UrlSyncManager.js","sources":["../../../src/services/UrlSyncManager.ts"],"sourcesContent":["import { Location } from 'history';\n\nimport { locationService } from '@grafana/runtime';\n\nimport { SceneObjectStateChangedEvent } from '../core/events';\nimport { SceneObject, SceneObjectUrlValues } from '../core/types';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { Unsubscribable } from 'rxjs';\nimport { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper';\nimport { getUrlState, isUrlValueEqual, syncStateFromUrl } from './utils';\n\nexport interface UrlSyncManagerLike {\n initSync(root: SceneObject): void;\n cleanUp(root: SceneObject): void;\n getUrlState(root: SceneObject): SceneObjectUrlValues;\n handleNewLocation(location: Location): void;\n handleNewObject(sceneObj: SceneObject): void;\n}\n\nexport class UrlSyncManager implements UrlSyncManagerLike {\n
|
1
|
+
{"version":3,"file":"UrlSyncManager.js","sources":["../../../src/services/UrlSyncManager.ts"],"sourcesContent":["import { Location } from 'history';\n\nimport { locationService } from '@grafana/runtime';\n\nimport { SceneObjectStateChangedEvent } from '../core/events';\nimport { SceneObject, SceneObjectUrlValues } from '../core/types';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { Unsubscribable } from 'rxjs';\nimport { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper';\nimport { getUrlState, isUrlValueEqual, syncStateFromUrl } from './utils';\n\nexport interface UrlSyncManagerLike {\n initSync(root: SceneObject): void;\n cleanUp(root: SceneObject): void;\n getUrlState(root: SceneObject): SceneObjectUrlValues;\n handleNewLocation(location: Location): void;\n handleNewObject(sceneObj: SceneObject): void;\n}\n\nexport class UrlSyncManager implements UrlSyncManagerLike {\n #urlKeyMapper = new UniqueUrlKeyMapper();\n #sceneRoot?: SceneObject;\n #stateSub: Unsubscribable | null = null;\n #lastLocation: Location | undefined;\n #paramsCache = new UrlParamsCache();\n\n /**\n * Updates the current scene state to match URL state.\n */\n public initSync(root: SceneObject) {\n if (this.#stateSub) {\n writeSceneLog('UrlSyncManager', 'Unregister previous scene state subscription', this.#sceneRoot?.state.key);\n this.#stateSub.unsubscribe();\n }\n\n writeSceneLog('UrlSyncManager', 'init', root.state.key);\n\n this.#sceneRoot = root;\n this.#stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, this.#onStateChanged);\n\n this.#urlKeyMapper.clear();\n this.#lastLocation = locationService.getLocation();\n\n this.handleNewObject(this.#sceneRoot);\n }\n\n public cleanUp(root: SceneObject) {\n // Ignore this if we have a new or different root\n if (this.#sceneRoot !== root) {\n return;\n }\n\n writeSceneLog('UrlSyncManager', 'Clean up');\n\n if (this.#stateSub) {\n this.#stateSub.unsubscribe();\n this.#stateSub = null;\n writeSceneLog(\n 'UrlSyncManager',\n 'Root deactived, unsub to state',\n 'same key',\n this.#sceneRoot.state.key === root.state.key\n );\n }\n\n this.#sceneRoot = undefined;\n this.#lastLocation = undefined;\n }\n\n public handleNewLocation(location: Location) {\n if (!this.#sceneRoot || this.#lastLocation === location) {\n return;\n }\n\n writeSceneLog('UrlSyncManager', 'handleNewLocation');\n\n this.#lastLocation = location;\n\n // Sync scene state tree from url\n syncStateFromUrl(this.#sceneRoot!, this.#paramsCache.getParams(), this.#urlKeyMapper);\n }\n\n public handleNewObject(sceneObj: SceneObject) {\n if (!this.#sceneRoot) {\n return;\n }\n\n syncStateFromUrl(sceneObj, this.#paramsCache.getParams(), this.#urlKeyMapper);\n }\n\n #onStateChanged = ({ payload }: SceneObjectStateChangedEvent) => {\n const changedObject = payload.changedObject;\n\n if (changedObject.urlSync) {\n const newUrlState = changedObject.urlSync.getUrlState();\n\n const searchParams = locationService.getSearch();\n const mappedUpdated: SceneObjectUrlValues = {};\n\n for (const [key, newUrlValue] of Object.entries(newUrlState)) {\n const uniqueKey = this.#urlKeyMapper.getUniqueKey(key, changedObject);\n const currentUrlValue = searchParams.getAll(uniqueKey);\n\n if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {\n mappedUpdated[uniqueKey] = newUrlValue;\n }\n }\n\n if (Object.keys(mappedUpdated).length > 0) {\n writeSceneLog('UrlSyncManager', 'onStateChange updating URL');\n locationService.partial(mappedUpdated, true);\n\n /// Mark the location already handled\n this.#lastLocation = locationService.getLocation();\n }\n }\n };\n\n public getUrlState(root: SceneObject): SceneObjectUrlValues {\n return getUrlState(root);\n }\n}\n\nclass UrlParamsCache {\n #cache: URLSearchParams | undefined;\n #location: Location | undefined;\n\n public getParams(): URLSearchParams {\n const location = locationService.getLocation();\n\n if (this.#location === location) {\n return this.#cache!;\n }\n\n this.#location = location;\n this.#cache = new URLSearchParams(location.search);\n\n return this.#cache;\n }\n}\n\nlet urlSyncManager: UrlSyncManagerLike | undefined;\n\nexport function getUrlSyncManager(): UrlSyncManagerLike {\n if (!urlSyncManager) {\n urlSyncManager = new UrlSyncManager();\n }\n\n return urlSyncManager;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,aAAA,EAAA,UAAA,EAAA,SAAA,EAAA,aAAA,EAAA,YAAA,EAAA,eAAA,EAAA,MAAA,EAAA,SAAA,CAAA;AAmBO,MAAM,cAA6C,CAAA;AAAA,EAAnD,WAAA,GAAA;AACL,IAAA,YAAA,CAAA,IAAA,EAAA,aAAA,EAAgB,IAAI,kBAAmB,EAAA,CAAA,CAAA;AACvC,IAAA,YAAA,CAAA,IAAA,EAAA,UAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AACA,IAAmC,YAAA,CAAA,IAAA,EAAA,SAAA,EAAA,IAAA,CAAA,CAAA;AACnC,IAAA,YAAA,CAAA,IAAA,EAAA,aAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AACA,IAAA,YAAA,CAAA,IAAA,EAAA,YAAA,EAAe,IAAI,cAAe,EAAA,CAAA,CAAA;AAkElC,IAAkB,YAAA,CAAA,IAAA,EAAA,eAAA,EAAA,CAAC,EAAE,OAAA,EAA4C,KAAA;AAC/D,MAAA,MAAM,gBAAgB,OAAQ,CAAA,aAAA,CAAA;AAE9B,MAAA,IAAI,cAAc,OAAS,EAAA;AACzB,QAAM,MAAA,WAAA,GAAc,aAAc,CAAA,OAAA,CAAQ,WAAY,EAAA,CAAA;AAEtD,QAAM,MAAA,YAAA,GAAe,gBAAgB,SAAU,EAAA,CAAA;AAC/C,QAAA,MAAM,gBAAsC,EAAC,CAAA;AAE7C,QAAA,KAAA,MAAW,CAAC,GAAK,EAAA,WAAW,KAAK,MAAO,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AAC5D,UAAA,MAAM,SAAY,GAAA,YAAA,C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AK,SAAY,EAAA,QAAA,CAAA,CAAA;AACjB,IAAA,YAAA,CAAA,IAAA,EAAK,MAAS,EAAA,IAAI,eAAgB,CAAA,QAAA,CAAS,MAAM,CAAA,CAAA,CAAA;AAEjD,IAAA,OAAO,YAAK,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAAA,GACd;AACF,CAAA;AAfE,MAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,SAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAgBF,IAAI,cAAA,CAAA;AAEG,SAAS,iBAAwC,GAAA;AACtD,EAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,IAAA,cAAA,GAAiB,IAAI,cAAe,EAAA,CAAA;AAAA,GACtC;AAEA,EAAO,OAAA,cAAA,CAAA;AACT;;;;"}
|
package/dist/index.d.ts
CHANGED
@@ -1572,11 +1572,7 @@ interface UrlSyncManagerLike {
|
|
1572
1572
|
handleNewObject(sceneObj: SceneObject): void;
|
1573
1573
|
}
|
1574
1574
|
declare class UrlSyncManager implements UrlSyncManagerLike {
|
1575
|
-
private
|
1576
|
-
private _sceneRoot?;
|
1577
|
-
private _stateSub;
|
1578
|
-
private _lastLocation;
|
1579
|
-
private _urlParams;
|
1575
|
+
#private;
|
1580
1576
|
/**
|
1581
1577
|
* Updates the current scene state to match URL state.
|
1582
1578
|
*/
|
@@ -1584,7 +1580,6 @@ declare class UrlSyncManager implements UrlSyncManagerLike {
|
|
1584
1580
|
cleanUp(root: SceneObject): void;
|
1585
1581
|
handleNewLocation(location: Location): void;
|
1586
1582
|
handleNewObject(sceneObj: SceneObject): void;
|
1587
|
-
private _onStateChanged;
|
1588
1583
|
getUrlState(root: SceneObject): SceneObjectUrlValues;
|
1589
1584
|
}
|
1590
1585
|
declare function getUrlSyncManager(): UrlSyncManagerLike;
|
package/dist/index.js
CHANGED
@@ -188,32 +188,32 @@ class UserActionEvent extends data.BusEventWithPayload {
|
|
188
188
|
}
|
189
189
|
UserActionEvent.type = "scene-object-user-action";
|
190
190
|
|
191
|
-
var __accessCheck$
|
191
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
192
192
|
if (!member.has(obj))
|
193
193
|
throw TypeError("Cannot " + msg);
|
194
194
|
};
|
195
|
-
var __privateGet$
|
196
|
-
__accessCheck$
|
195
|
+
var __privateGet$2 = (obj, member, getter) => {
|
196
|
+
__accessCheck$2(obj, member, "read from private field");
|
197
197
|
return getter ? getter.call(obj) : member.get(obj);
|
198
198
|
};
|
199
|
-
var __privateAdd$
|
199
|
+
var __privateAdd$2 = (obj, member, value) => {
|
200
200
|
if (member.has(obj))
|
201
201
|
throw TypeError("Cannot add the same private member more than once");
|
202
202
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
203
203
|
};
|
204
|
-
var __privateSet = (obj, member, value, setter) => {
|
205
|
-
__accessCheck$
|
204
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
205
|
+
__accessCheck$2(obj, member, "write to private field");
|
206
206
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
207
207
|
return value;
|
208
208
|
};
|
209
209
|
var _ref;
|
210
210
|
class SceneObjectRef {
|
211
211
|
constructor(ref) {
|
212
|
-
__privateAdd$
|
213
|
-
__privateSet(this, _ref, ref);
|
212
|
+
__privateAdd$2(this, _ref, void 0);
|
213
|
+
__privateSet$1(this, _ref, ref);
|
214
214
|
}
|
215
215
|
resolve() {
|
216
|
-
return __privateGet$
|
216
|
+
return __privateGet$2(this, _ref);
|
217
217
|
}
|
218
218
|
}
|
219
219
|
_ref = new WeakMap();
|
@@ -1741,15 +1741,15 @@ function isDataLayer(obj) {
|
|
1741
1741
|
return "isDataLayer" in obj;
|
1742
1742
|
}
|
1743
1743
|
|
1744
|
-
var __accessCheck = (obj, member, msg) => {
|
1744
|
+
var __accessCheck$1 = (obj, member, msg) => {
|
1745
1745
|
if (!member.has(obj))
|
1746
1746
|
throw TypeError("Cannot " + msg);
|
1747
1747
|
};
|
1748
|
-
var __privateGet = (obj, member, getter) => {
|
1749
|
-
__accessCheck(obj, member, "read from private field");
|
1748
|
+
var __privateGet$1 = (obj, member, getter) => {
|
1749
|
+
__accessCheck$1(obj, member, "read from private field");
|
1750
1750
|
return getter ? getter.call(obj) : member.get(obj);
|
1751
1751
|
};
|
1752
|
-
var __privateAdd = (obj, member, value) => {
|
1752
|
+
var __privateAdd$1 = (obj, member, value) => {
|
1753
1753
|
if (member.has(obj))
|
1754
1754
|
throw TypeError("Cannot add the same private member more than once");
|
1755
1755
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
@@ -1762,25 +1762,25 @@ class SceneQueryController extends SceneObjectBase {
|
|
1762
1762
|
constructor() {
|
1763
1763
|
super({ isRunning: false });
|
1764
1764
|
this.isQueryController = true;
|
1765
|
-
__privateAdd(this, _running, /* @__PURE__ */ new Set());
|
1765
|
+
__privateAdd$1(this, _running, /* @__PURE__ */ new Set());
|
1766
1766
|
this.addActivationHandler(() => {
|
1767
|
-
return () => __privateGet(this, _running).clear();
|
1767
|
+
return () => __privateGet$1(this, _running).clear();
|
1768
1768
|
});
|
1769
1769
|
}
|
1770
1770
|
queryStarted(entry) {
|
1771
|
-
__privateGet(this, _running).add(entry);
|
1771
|
+
__privateGet$1(this, _running).add(entry);
|
1772
1772
|
this.changeRunningQueryCount(1);
|
1773
1773
|
if (!this.state.isRunning) {
|
1774
1774
|
this.setState({ isRunning: true });
|
1775
1775
|
}
|
1776
1776
|
}
|
1777
1777
|
queryCompleted(entry) {
|
1778
|
-
if (!__privateGet(this, _running).has(entry)) {
|
1778
|
+
if (!__privateGet$1(this, _running).has(entry)) {
|
1779
1779
|
return;
|
1780
1780
|
}
|
1781
|
-
__privateGet(this, _running).delete(entry);
|
1781
|
+
__privateGet$1(this, _running).delete(entry);
|
1782
1782
|
this.changeRunningQueryCount(-1);
|
1783
|
-
if (__privateGet(this, _running).size === 0) {
|
1783
|
+
if (__privateGet$1(this, _running).size === 0) {
|
1784
1784
|
this.setState({ isRunning: false });
|
1785
1785
|
}
|
1786
1786
|
}
|
@@ -1790,7 +1790,7 @@ class SceneQueryController extends SceneObjectBase {
|
|
1790
1790
|
}
|
1791
1791
|
cancelAll() {
|
1792
1792
|
var _a;
|
1793
|
-
for (const entry of __privateGet(this, _running).values()) {
|
1793
|
+
for (const entry of __privateGet$1(this, _running).values()) {
|
1794
1794
|
(_a = entry.cancel) == null ? void 0 : _a.call(entry);
|
1795
1795
|
}
|
1796
1796
|
}
|
@@ -7780,18 +7780,40 @@ IntervalVariable.Component = ({ model }) => {
|
|
7780
7780
|
});
|
7781
7781
|
};
|
7782
7782
|
|
7783
|
+
var __accessCheck = (obj, member, msg) => {
|
7784
|
+
if (!member.has(obj))
|
7785
|
+
throw TypeError("Cannot " + msg);
|
7786
|
+
};
|
7787
|
+
var __privateGet = (obj, member, getter) => {
|
7788
|
+
__accessCheck(obj, member, "read from private field");
|
7789
|
+
return getter ? getter.call(obj) : member.get(obj);
|
7790
|
+
};
|
7791
|
+
var __privateAdd = (obj, member, value) => {
|
7792
|
+
if (member.has(obj))
|
7793
|
+
throw TypeError("Cannot add the same private member more than once");
|
7794
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
7795
|
+
};
|
7796
|
+
var __privateSet = (obj, member, value, setter) => {
|
7797
|
+
__accessCheck(obj, member, "write to private field");
|
7798
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
7799
|
+
return value;
|
7800
|
+
};
|
7801
|
+
var _urlKeyMapper, _sceneRoot, _stateSub, _lastLocation, _paramsCache, _onStateChanged, _cache, _location;
|
7783
7802
|
class UrlSyncManager {
|
7784
7803
|
constructor() {
|
7785
|
-
this
|
7786
|
-
this
|
7787
|
-
this
|
7804
|
+
__privateAdd(this, _urlKeyMapper, new UniqueUrlKeyMapper());
|
7805
|
+
__privateAdd(this, _sceneRoot, void 0);
|
7806
|
+
__privateAdd(this, _stateSub, null);
|
7807
|
+
__privateAdd(this, _lastLocation, void 0);
|
7808
|
+
__privateAdd(this, _paramsCache, new UrlParamsCache());
|
7809
|
+
__privateAdd(this, _onStateChanged, ({ payload }) => {
|
7788
7810
|
const changedObject = payload.changedObject;
|
7789
7811
|
if (changedObject.urlSync) {
|
7790
7812
|
const newUrlState = changedObject.urlSync.getUrlState();
|
7791
7813
|
const searchParams = runtime.locationService.getSearch();
|
7792
7814
|
const mappedUpdated = {};
|
7793
7815
|
for (const [key, newUrlValue] of Object.entries(newUrlState)) {
|
7794
|
-
const uniqueKey = this
|
7816
|
+
const uniqueKey = __privateGet(this, _urlKeyMapper).getUniqueKey(key, changedObject);
|
7795
7817
|
const currentUrlValue = searchParams.getAll(uniqueKey);
|
7796
7818
|
if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {
|
7797
7819
|
mappedUpdated[uniqueKey] = newUrlValue;
|
@@ -7800,63 +7822,83 @@ class UrlSyncManager {
|
|
7800
7822
|
if (Object.keys(mappedUpdated).length > 0) {
|
7801
7823
|
writeSceneLog("UrlSyncManager", "onStateChange updating URL");
|
7802
7824
|
runtime.locationService.partial(mappedUpdated, true);
|
7803
|
-
this
|
7804
|
-
this._urlParams = new URLSearchParams(this._lastLocation.search);
|
7825
|
+
__privateSet(this, _lastLocation, runtime.locationService.getLocation());
|
7805
7826
|
}
|
7806
7827
|
}
|
7807
|
-
};
|
7828
|
+
});
|
7808
7829
|
}
|
7809
7830
|
initSync(root) {
|
7810
7831
|
var _a;
|
7811
|
-
if (this
|
7812
|
-
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = this
|
7813
|
-
this
|
7832
|
+
if (__privateGet(this, _stateSub)) {
|
7833
|
+
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = __privateGet(this, _sceneRoot)) == null ? void 0 : _a.state.key);
|
7834
|
+
__privateGet(this, _stateSub).unsubscribe();
|
7814
7835
|
}
|
7815
7836
|
writeSceneLog("UrlSyncManager", "init", root.state.key);
|
7816
|
-
this
|
7817
|
-
this
|
7818
|
-
this
|
7819
|
-
this
|
7820
|
-
this.
|
7821
|
-
this.handleNewObject(this._sceneRoot);
|
7837
|
+
__privateSet(this, _sceneRoot, root);
|
7838
|
+
__privateSet(this, _stateSub, root.subscribeToEvent(SceneObjectStateChangedEvent, __privateGet(this, _onStateChanged)));
|
7839
|
+
__privateGet(this, _urlKeyMapper).clear();
|
7840
|
+
__privateSet(this, _lastLocation, runtime.locationService.getLocation());
|
7841
|
+
this.handleNewObject(__privateGet(this, _sceneRoot));
|
7822
7842
|
}
|
7823
7843
|
cleanUp(root) {
|
7824
|
-
if (this
|
7844
|
+
if (__privateGet(this, _sceneRoot) !== root) {
|
7825
7845
|
return;
|
7826
7846
|
}
|
7827
7847
|
writeSceneLog("UrlSyncManager", "Clean up");
|
7828
|
-
if (this
|
7829
|
-
this
|
7830
|
-
this
|
7848
|
+
if (__privateGet(this, _stateSub)) {
|
7849
|
+
__privateGet(this, _stateSub).unsubscribe();
|
7850
|
+
__privateSet(this, _stateSub, null);
|
7831
7851
|
writeSceneLog(
|
7832
7852
|
"UrlSyncManager",
|
7833
7853
|
"Root deactived, unsub to state",
|
7834
7854
|
"same key",
|
7835
|
-
this
|
7855
|
+
__privateGet(this, _sceneRoot).state.key === root.state.key
|
7836
7856
|
);
|
7837
7857
|
}
|
7838
|
-
this
|
7839
|
-
this
|
7858
|
+
__privateSet(this, _sceneRoot, void 0);
|
7859
|
+
__privateSet(this, _lastLocation, void 0);
|
7840
7860
|
}
|
7841
7861
|
handleNewLocation(location) {
|
7842
|
-
if (!this
|
7862
|
+
if (!__privateGet(this, _sceneRoot) || __privateGet(this, _lastLocation) === location) {
|
7843
7863
|
return;
|
7844
7864
|
}
|
7845
7865
|
writeSceneLog("UrlSyncManager", "handleNewLocation");
|
7846
|
-
this
|
7847
|
-
this.
|
7848
|
-
syncStateFromUrl(this._sceneRoot, this._urlParams, this._urlKeyMapper);
|
7866
|
+
__privateSet(this, _lastLocation, location);
|
7867
|
+
syncStateFromUrl(__privateGet(this, _sceneRoot), __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
7849
7868
|
}
|
7850
7869
|
handleNewObject(sceneObj) {
|
7851
|
-
if (!this
|
7870
|
+
if (!__privateGet(this, _sceneRoot)) {
|
7852
7871
|
return;
|
7853
7872
|
}
|
7854
|
-
syncStateFromUrl(sceneObj, this.
|
7873
|
+
syncStateFromUrl(sceneObj, __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
7855
7874
|
}
|
7856
7875
|
getUrlState(root) {
|
7857
7876
|
return getUrlState(root);
|
7858
7877
|
}
|
7859
7878
|
}
|
7879
|
+
_urlKeyMapper = new WeakMap();
|
7880
|
+
_sceneRoot = new WeakMap();
|
7881
|
+
_stateSub = new WeakMap();
|
7882
|
+
_lastLocation = new WeakMap();
|
7883
|
+
_paramsCache = new WeakMap();
|
7884
|
+
_onStateChanged = new WeakMap();
|
7885
|
+
class UrlParamsCache {
|
7886
|
+
constructor() {
|
7887
|
+
__privateAdd(this, _cache, void 0);
|
7888
|
+
__privateAdd(this, _location, void 0);
|
7889
|
+
}
|
7890
|
+
getParams() {
|
7891
|
+
const location = runtime.locationService.getLocation();
|
7892
|
+
if (__privateGet(this, _location) === location) {
|
7893
|
+
return __privateGet(this, _cache);
|
7894
|
+
}
|
7895
|
+
__privateSet(this, _location, location);
|
7896
|
+
__privateSet(this, _cache, new URLSearchParams(location.search));
|
7897
|
+
return __privateGet(this, _cache);
|
7898
|
+
}
|
7899
|
+
}
|
7900
|
+
_cache = new WeakMap();
|
7901
|
+
_location = new WeakMap();
|
7860
7902
|
let urlSyncManager;
|
7861
7903
|
function getUrlSyncManager() {
|
7862
7904
|
if (!urlSyncManager) {
|