@arcgis/lumina 4.33.0-next.1 → 4.33.0-next.100
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/dist/Controller-CZ8Djohh.js +627 -0
- package/dist/LitElement.d.ts +36 -29
- package/dist/config.js +13 -6
- package/dist/context.d.ts +13 -3
- package/dist/controllers/Controller.d.ts +153 -0
- package/dist/controllers/ControllerInternals.d.ts +59 -0
- package/dist/controllers/ControllerManager.d.ts +83 -0
- package/dist/controllers/accessor/index.d.ts +2 -0
- package/dist/controllers/accessor/index.js +259 -0
- package/dist/controllers/accessor/reEmitEvent.d.ts +10 -0
- package/dist/controllers/accessor/useAccessor.d.ts +74 -0
- package/dist/controllers/functional.d.ts +19 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +263 -0
- package/dist/controllers/load.d.ts +6 -0
- package/dist/controllers/proxyExports.d.ts +27 -0
- package/dist/controllers/tests/autoDestroyMock.d.ts +5 -0
- package/dist/controllers/tests/utils.d.ts +1 -0
- package/dist/controllers/toFunction.d.ts +8 -0
- package/dist/controllers/trackKey.d.ts +8 -0
- package/dist/controllers/trackPropKey.d.ts +21 -0
- package/dist/controllers/trackPropertyKey.d.ts +29 -0
- package/dist/controllers/types.d.ts +152 -0
- package/dist/controllers/useDirection.d.ts +11 -0
- package/dist/controllers/useMedia.d.ts +8 -0
- package/dist/controllers/usePropertyChange.d.ts +12 -0
- package/dist/controllers/useT9n.d.ts +48 -0
- package/dist/controllers/useWatchAttributes.d.ts +7 -0
- package/dist/controllers/utils.d.ts +15 -0
- package/dist/createEvent.d.ts +7 -2
- package/dist/decorators.d.ts +2 -2
- package/dist/devOnlyDetectIncorrectLazyUsages.d.ts +1 -1
- package/dist/hmrSupport.d.ts +1 -1
- package/dist/hmrSupport.js +1 -7
- package/dist/index.d.ts +17 -16
- package/dist/index.js +386 -150
- package/dist/jsx/baseTypes.d.ts +13 -9
- package/dist/jsx/directives.d.ts +25 -7
- package/dist/jsx/generatedTypes.d.ts +6 -10
- package/dist/jsx/types.d.ts +5 -32
- package/dist/lazyLoad.d.ts +18 -18
- package/dist/lifecycleSupport.d.ts +1 -1
- package/dist/makeRuntime.d.ts +109 -0
- package/dist/proxyExports-CK5BLFLO.js +60 -0
- package/dist/render.d.ts +5 -0
- package/dist/runtime.d.ts +4 -107
- package/dist/stencilSsrCompatibility/index.d.ts +2 -6
- package/dist/stencilSsrCompatibility/index.js +2 -3
- package/dist/typings/importMeta.d.ts +2 -2
- package/dist/{chunk-6HCCSL5F.js → utils-DBdf1Dqp.js} +67 -80
- package/package.json +4 -3
- package/dist/chunk-PGHUBTOM.js +0 -21
- package/dist/wrappersUtils.test.d.ts +0 -1
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { isEsriInternalEnv, safeCall, Deferred, safeAsyncCall } from "@arcgis/components-utils";
|
|
2
|
+
import { nothing } from "lit";
|
|
3
|
+
const controllerSymbol = Symbol.for("controller");
|
|
4
|
+
const name = "@arcgis/lumina";
|
|
5
|
+
const isController = (value) => typeof value === "object" && value !== null && (controllerSymbol in value || "hostConnected" in value || "hostDisconnected" in value || "hostUpdate" in value || "hostUpdated" in value);
|
|
6
|
+
const devOnlySetPersistentControllerData = process.env.NODE_ENV !== "production" && isEsriInternalEnv() ? (controller, data) => {
|
|
7
|
+
const controllers = controller.component._controllers;
|
|
8
|
+
const index = Array.from(controllers).indexOf(controller);
|
|
9
|
+
if (index === -1) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const devOnlyControllerData = Symbol.for(`${name}: devOnlyControllerData`);
|
|
13
|
+
const el = controller.component.el;
|
|
14
|
+
el[devOnlyControllerData] ??= {};
|
|
15
|
+
el[devOnlyControllerData][index] = data;
|
|
16
|
+
} : void 0;
|
|
17
|
+
const devOnlyGetPersistentControllerData = process.env.NODE_ENV !== "production" && isEsriInternalEnv() ? (controller) => {
|
|
18
|
+
const manager = controller.component.manager;
|
|
19
|
+
const controllers = "_controllers" in manager ? manager._controllers : void 0;
|
|
20
|
+
if (controllers === void 0) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
const index = Array.from(controllers).indexOf(controller);
|
|
24
|
+
const devOnlyControllerData = Symbol.for(`${name}: devOnlyControllerData`);
|
|
25
|
+
const el = controller.component.el;
|
|
26
|
+
return el[devOnlyControllerData]?.[index];
|
|
27
|
+
} : void 0;
|
|
28
|
+
function isPromise(arg) {
|
|
29
|
+
return typeof arg?.then === "function";
|
|
30
|
+
}
|
|
31
|
+
let ambientComponent;
|
|
32
|
+
function setAmbientComponent(component) {
|
|
33
|
+
if (ambientComponent === component) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
ambientComponent = component;
|
|
37
|
+
queueMicrotask(() => {
|
|
38
|
+
if (ambientComponent === component) {
|
|
39
|
+
ambientComponent = void 0;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function retrieveComponent(name2) {
|
|
44
|
+
if (process.env.NODE_ENV !== "production" && ambientComponent === void 0) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
[
|
|
47
|
+
`Unable to find out which component ${name2 || "this"} controller `,
|
|
48
|
+
"belongs to. Possible causes:\n",
|
|
49
|
+
"- You might have multiple versions of ",
|
|
50
|
+
"@arcgis/lumina package installed\n",
|
|
51
|
+
...isEsriInternalEnv() ? [
|
|
52
|
+
"- You tried to create controller outside the component. If so, ",
|
|
53
|
+
"please wrap your controller definition in an arrow function (like",
|
|
54
|
+
"`const myController = ()=>makeController(...);`) and call that",
|
|
55
|
+
"function inside the component (`my = myController();`), or ",
|
|
56
|
+
"define your controller using makeGenericController/GenericController ",
|
|
57
|
+
"instead.\n",
|
|
58
|
+
"- You tried to create a controller inside an async function. ",
|
|
59
|
+
"This is allowed without calling controller.use(). Make sure you ",
|
|
60
|
+
"use it like `await controller.use(useController())`."
|
|
61
|
+
] : []
|
|
62
|
+
].join("")
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return ambientComponent;
|
|
66
|
+
}
|
|
67
|
+
let ambientControllers = [];
|
|
68
|
+
function setParentController(controller) {
|
|
69
|
+
if (controller === void 0) {
|
|
70
|
+
ambientControllers = [];
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const index = ambientControllers.indexOf(controller);
|
|
74
|
+
ambientControllers = index === -1 ? [...ambientControllers, controller] : ambientControllers.slice(0, index + 1);
|
|
75
|
+
queueMicrotask(() => {
|
|
76
|
+
ambientControllers = [];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function retrieveParentControllers() {
|
|
80
|
+
return ambientControllers;
|
|
81
|
+
}
|
|
82
|
+
let ambientChildController;
|
|
83
|
+
function setAmbientChildController(controller) {
|
|
84
|
+
if (ambientChildController === controller) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
ambientChildController = controller;
|
|
88
|
+
queueMicrotask(() => {
|
|
89
|
+
if (ambientChildController === controller) {
|
|
90
|
+
ambientChildController = void 0;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function retrieveAmbientChildController() {
|
|
95
|
+
const controller = ambientChildController;
|
|
96
|
+
ambientChildController = void 0;
|
|
97
|
+
return controller;
|
|
98
|
+
}
|
|
99
|
+
const use = async (value, watchExports) => {
|
|
100
|
+
const controller = useRefSync(value);
|
|
101
|
+
if (controller === void 0) {
|
|
102
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && typeof watchExports === "function") {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Unable to resolve a controller from the provided value, so can't watch it's exports. The value you passed is not a controller and not a controller exports. If your controller exports a literal value, try making your controller export an object instead`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
await controller.ready;
|
|
110
|
+
if (typeof watchExports === "function") {
|
|
111
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && controller.watchExports === void 0) {
|
|
112
|
+
throw new Error(`The controller must implement watchExports method to support watching exports`);
|
|
113
|
+
}
|
|
114
|
+
const unsubscribe = controller.watchExports(
|
|
115
|
+
(exports) => watchExports(exports, unsubscribe)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return controller.exports;
|
|
119
|
+
};
|
|
120
|
+
const useRef = async (value) => {
|
|
121
|
+
const controller = useRefSync(value);
|
|
122
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && controller === void 0) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Unable to resolve a controller from the provided value. The value you passed is not a controller and not a controller exports. If your controller exports a literal value, try making your controller export an object instead`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
await controller.ready;
|
|
128
|
+
return controller;
|
|
129
|
+
};
|
|
130
|
+
const useRefSync = (value) => {
|
|
131
|
+
const component = retrieveComponent();
|
|
132
|
+
const controller = component.manager._resolveExports(value);
|
|
133
|
+
if (controller !== void 0) {
|
|
134
|
+
return controller;
|
|
135
|
+
}
|
|
136
|
+
if (isController(value)) {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
const ambientChildController2 = retrieveAmbientChildController();
|
|
140
|
+
if (ambientChildController2 !== void 0) {
|
|
141
|
+
return ambientChildController2;
|
|
142
|
+
}
|
|
143
|
+
return void 0;
|
|
144
|
+
};
|
|
145
|
+
let shouldBypassGetter = false;
|
|
146
|
+
let shouldBypassReadOnly = false;
|
|
147
|
+
function bypassReadOnly(callback) {
|
|
148
|
+
shouldBypassReadOnly = true;
|
|
149
|
+
try {
|
|
150
|
+
return callback();
|
|
151
|
+
} finally {
|
|
152
|
+
shouldBypassReadOnly = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const bypassSetter = bypassReadOnly;
|
|
156
|
+
function bypassGetter(callback) {
|
|
157
|
+
shouldBypassGetter = true;
|
|
158
|
+
try {
|
|
159
|
+
return callback();
|
|
160
|
+
} finally {
|
|
161
|
+
shouldBypassGetter = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function trackPropertyKey(object, onResolved, defaultValue) {
|
|
165
|
+
const keys = Object.keys(object);
|
|
166
|
+
const keyCount = keys.length;
|
|
167
|
+
if (keyTrackMap === void 0) {
|
|
168
|
+
queueMicrotask(keyTrackResolve);
|
|
169
|
+
}
|
|
170
|
+
keyTrackMap ??= /* @__PURE__ */ new Map();
|
|
171
|
+
let pendingTrackers = keyTrackMap.get(object);
|
|
172
|
+
if (pendingTrackers === void 0) {
|
|
173
|
+
pendingTrackers = { callbacks: [], keyCount };
|
|
174
|
+
keyTrackMap.set(object, pendingTrackers);
|
|
175
|
+
}
|
|
176
|
+
if (pendingTrackers.keyCount !== keyCount) {
|
|
177
|
+
pendingTrackers.callbacks.forEach((resolve) => resolve(keys));
|
|
178
|
+
pendingTrackers.callbacks = [];
|
|
179
|
+
pendingTrackers.keyCount = keyCount;
|
|
180
|
+
}
|
|
181
|
+
pendingTrackers.callbacks.push((keys2) => {
|
|
182
|
+
const callback = (key2) => safeCall(onResolved, null, key2);
|
|
183
|
+
const key = keys2[keyCount];
|
|
184
|
+
if (key === void 0) {
|
|
185
|
+
callback(void 0);
|
|
186
|
+
} else if (object[key] === defaultValue) {
|
|
187
|
+
callback(key);
|
|
188
|
+
} else {
|
|
189
|
+
callback(void 0);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return defaultValue;
|
|
193
|
+
}
|
|
194
|
+
let keyTrackMap = void 0;
|
|
195
|
+
function keyTrackResolve() {
|
|
196
|
+
keyTrackMap?.forEach(({ callbacks }, object) => {
|
|
197
|
+
const keys = Object.keys(object);
|
|
198
|
+
callbacks.forEach((commit) => commit(keys));
|
|
199
|
+
});
|
|
200
|
+
keyTrackMap = void 0;
|
|
201
|
+
}
|
|
202
|
+
function trackPropKey(component, onResolved, defaultValue) {
|
|
203
|
+
const manager = component.manager;
|
|
204
|
+
if (manager._trackedValue !== nothing && manager._trackedValue !== defaultValue) {
|
|
205
|
+
manager._firePropTrackers(void 0, void 0);
|
|
206
|
+
}
|
|
207
|
+
if (manager._keyTrackers.length === 0) {
|
|
208
|
+
queueMicrotask(() => manager._firePropTrackers(void 0, void 0));
|
|
209
|
+
}
|
|
210
|
+
manager._trackedValue = defaultValue;
|
|
211
|
+
manager._keyTrackers.push((key, value) => safeCall(onResolved, void 0, defaultValue === value ? key : void 0));
|
|
212
|
+
return defaultValue;
|
|
213
|
+
}
|
|
214
|
+
function trackKey(hostsCandidates = [
|
|
215
|
+
retrieveComponent(),
|
|
216
|
+
...retrieveParentControllers()
|
|
217
|
+
], onResolved, defaultValue) {
|
|
218
|
+
const candidateHosts = Array.isArray(hostsCandidates) ? hostsCandidates : [hostsCandidates];
|
|
219
|
+
let leftToResolve = candidateHosts.length + 1;
|
|
220
|
+
const resolved = (resolution) => {
|
|
221
|
+
leftToResolve -= 1;
|
|
222
|
+
if (resolution !== void 0) {
|
|
223
|
+
leftToResolve = Math.min(leftToResolve, 0);
|
|
224
|
+
}
|
|
225
|
+
if (leftToResolve === 0) {
|
|
226
|
+
onResolved(resolution);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
candidateHosts.forEach(
|
|
230
|
+
(host) => trackPropertyKey(
|
|
231
|
+
host,
|
|
232
|
+
(key) => resolved(key === void 0 ? void 0 : { key, host, isReactive: false }),
|
|
233
|
+
defaultValue
|
|
234
|
+
)
|
|
235
|
+
);
|
|
236
|
+
for (const host of candidateHosts) {
|
|
237
|
+
if ("manager" in host && typeof host.manager === "object" && host.manager.component === host) {
|
|
238
|
+
trackPropKey(
|
|
239
|
+
host,
|
|
240
|
+
(key) => resolved(key === void 0 ? void 0 : { key, host, isReactive: true }),
|
|
241
|
+
defaultValue
|
|
242
|
+
);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return defaultValue;
|
|
247
|
+
}
|
|
248
|
+
const createEventFactory = (eventName = "", options = {}, component = retrieveComponent()) => {
|
|
249
|
+
const emitter = {
|
|
250
|
+
emit: (payload) => {
|
|
251
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && !component.el.isConnected) {
|
|
252
|
+
console.warn(`Trying to emit an ${eventName} event on a disconnected element ${component.el.localName}`);
|
|
253
|
+
}
|
|
254
|
+
if (eventName === "") {
|
|
255
|
+
keyTrackResolve();
|
|
256
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && eventName === "") {
|
|
257
|
+
throw new Error("Unable to resolve event name from property name");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const event = new CustomEvent(eventName, {
|
|
261
|
+
detail: payload,
|
|
262
|
+
cancelable: true,
|
|
263
|
+
bubbles: true,
|
|
264
|
+
composed: true,
|
|
265
|
+
...options
|
|
266
|
+
});
|
|
267
|
+
component.el.dispatchEvent(event);
|
|
268
|
+
return event;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
if (eventName === "") {
|
|
272
|
+
trackKey(
|
|
273
|
+
void 0,
|
|
274
|
+
(resolution) => {
|
|
275
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && resolution === void 0) {
|
|
276
|
+
throw new Error(`createEvent must be called in property default value only`);
|
|
277
|
+
}
|
|
278
|
+
eventName = resolution.key;
|
|
279
|
+
},
|
|
280
|
+
emitter
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
return emitter;
|
|
284
|
+
};
|
|
285
|
+
const createEvent = createEventFactory.bind(null, "");
|
|
286
|
+
var _a;
|
|
287
|
+
_a = controllerSymbol;
|
|
288
|
+
class Controller {
|
|
289
|
+
constructor(component) {
|
|
290
|
+
this._callbacks = {
|
|
291
|
+
hostConnected: [],
|
|
292
|
+
hostDisconnected: [],
|
|
293
|
+
hostLoad: [],
|
|
294
|
+
hostLoaded: [],
|
|
295
|
+
hostUpdate: [],
|
|
296
|
+
hostUpdated: [],
|
|
297
|
+
hostDestroy: [],
|
|
298
|
+
hostLifecycle: []
|
|
299
|
+
};
|
|
300
|
+
this._ready = new Deferred();
|
|
301
|
+
this._lifecycleCleanups = [];
|
|
302
|
+
this.connectedCalled = false;
|
|
303
|
+
this._loadCalled = false;
|
|
304
|
+
this.loadedCalled = false;
|
|
305
|
+
this[_a] = true;
|
|
306
|
+
this.ready = this._ready.promise;
|
|
307
|
+
this._exports = makeProvisionalValue(this);
|
|
308
|
+
this._exportWatchers = /* @__PURE__ */ new Set();
|
|
309
|
+
const resolvedComponent = component ?? retrieveComponent(new.target.name);
|
|
310
|
+
if (process.env.NODE_ENV !== "production") {
|
|
311
|
+
Object.defineProperty(this, "component", {
|
|
312
|
+
writable: false,
|
|
313
|
+
enumerable: false,
|
|
314
|
+
configurable: true,
|
|
315
|
+
value: resolvedComponent
|
|
316
|
+
});
|
|
317
|
+
if ("hostDestroy" in this) {
|
|
318
|
+
this.component.manager._ensureHasDestroy?.();
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
this.component = resolvedComponent;
|
|
322
|
+
}
|
|
323
|
+
this.component.addController(this);
|
|
324
|
+
const manager = this.component.manager;
|
|
325
|
+
const isInControllerManager = manager === void 0;
|
|
326
|
+
if (!isInControllerManager) {
|
|
327
|
+
setParentController(this);
|
|
328
|
+
queueMicrotask(() => this.catchUpLifecycle());
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* If controller is being added dynamically, after the component
|
|
333
|
+
* construction, then trigger connected and load right away
|
|
334
|
+
*/
|
|
335
|
+
catchUpLifecycle() {
|
|
336
|
+
const { manager } = this.component;
|
|
337
|
+
const connectedWillStillHappen = !manager.connectedCalled;
|
|
338
|
+
if (!connectedWillStillHappen && !this.connectedCalled) {
|
|
339
|
+
this.triggerConnected();
|
|
340
|
+
}
|
|
341
|
+
const loadWillStillHappen = !manager._loadCalled;
|
|
342
|
+
if (loadWillStillHappen) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
this.triggerLoad().then(() => {
|
|
346
|
+
const loadedWillStillHappen = !manager.loadedCalled;
|
|
347
|
+
if (loadedWillStillHappen) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
this.triggerLoaded();
|
|
351
|
+
}).catch(console.error);
|
|
352
|
+
}
|
|
353
|
+
get exports() {
|
|
354
|
+
return this._exports;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Set controller's exports property (for usage with proxyExports()) and mark
|
|
358
|
+
* controller as ready (for usage in other controllers). Also, triggers
|
|
359
|
+
* re-render of the component
|
|
360
|
+
*/
|
|
361
|
+
set exports(exports) {
|
|
362
|
+
const oldExports = this._exports;
|
|
363
|
+
if (oldExports !== exports) {
|
|
364
|
+
this._exports = exports;
|
|
365
|
+
this._exportWatchers.forEach(safeCall);
|
|
366
|
+
if (this.connectedCalled && this.assignedProperty !== false) {
|
|
367
|
+
this.component.requestUpdate(this.assignedProperty, oldExports);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
this._ready.resolve(exports);
|
|
371
|
+
}
|
|
372
|
+
setProvisionalExports(exports, proxy = true) {
|
|
373
|
+
this._exports = proxy ? makeProvisionalValue(exports) : exports;
|
|
374
|
+
this._exportWatchers.forEach(safeCall);
|
|
375
|
+
}
|
|
376
|
+
watchExports(callback) {
|
|
377
|
+
const safeCallback = () => callback(this._exports);
|
|
378
|
+
this._exportWatchers.add(safeCallback);
|
|
379
|
+
return () => void this._exportWatchers.delete(safeCallback);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* A flexible utility for making sure a controller is loaded before it's used,
|
|
383
|
+
* regardless of how or where a controller was defined:
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* makeGenericController(async (component, controller) => {
|
|
387
|
+
* // Await some controller from the component:
|
|
388
|
+
* await controller.use(component.someController);
|
|
389
|
+
* // Initialize new controllers
|
|
390
|
+
* await controller.use(load(importCoreReactiveUtils));
|
|
391
|
+
* await controller.use(new ViewModelController(component,newWidgetsHomeHomeViewModel));
|
|
392
|
+
* await controller.use(someController(component));
|
|
393
|
+
* });
|
|
394
|
+
*
|
|
395
|
+
* @remarks
|
|
396
|
+
* If your controller is not async, and you are not creating it async, then
|
|
397
|
+
* you are not required to use controller.use - you can use it directly.
|
|
398
|
+
* Similarly, accessing controllers after componentWillLoad callback does not
|
|
399
|
+
* require awaiting them as they are guaranteed to be loaded by then.
|
|
400
|
+
*/
|
|
401
|
+
get use() {
|
|
402
|
+
setAmbientComponent(this.component);
|
|
403
|
+
return use;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Just like controller.use, but returns the controller itself, rather than it's
|
|
407
|
+
* exports
|
|
408
|
+
*
|
|
409
|
+
* Use cases:
|
|
410
|
+
* - You have a controller and you want to make sure it's loaded before you
|
|
411
|
+
* try to use it
|
|
412
|
+
* - Your controller is not using exports, so you wish to access some props on
|
|
413
|
+
* it directly
|
|
414
|
+
* - You have a controller exports only, and you want to retrieve the
|
|
415
|
+
* controller itself. This is useful if you wish to call .watchExports() or
|
|
416
|
+
* some other method on the controller
|
|
417
|
+
*/
|
|
418
|
+
get useRef() {
|
|
419
|
+
setAmbientComponent(this.component);
|
|
420
|
+
return useRef;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Like useRef, but doesn't wait for the controller to get ready
|
|
424
|
+
*
|
|
425
|
+
* @private
|
|
426
|
+
*/
|
|
427
|
+
get useRefSync() {
|
|
428
|
+
setAmbientComponent(this.component);
|
|
429
|
+
return useRefSync;
|
|
430
|
+
}
|
|
431
|
+
controllerRemoved() {
|
|
432
|
+
if (this.component.el.isConnected) {
|
|
433
|
+
this.triggerDisconnected();
|
|
434
|
+
}
|
|
435
|
+
this.triggerDestroy();
|
|
436
|
+
}
|
|
437
|
+
// Register a lifecycle callback
|
|
438
|
+
onConnected(callback) {
|
|
439
|
+
this._callbacks.hostConnected.push(callback);
|
|
440
|
+
}
|
|
441
|
+
onDisconnected(callback) {
|
|
442
|
+
this._callbacks.hostDisconnected.push(callback);
|
|
443
|
+
}
|
|
444
|
+
onLoad(callback) {
|
|
445
|
+
this._callbacks.hostLoad.push(callback);
|
|
446
|
+
}
|
|
447
|
+
onLoaded(callback) {
|
|
448
|
+
this._callbacks.hostLoaded.push(callback);
|
|
449
|
+
}
|
|
450
|
+
onUpdate(callback) {
|
|
451
|
+
this._callbacks.hostUpdate.push(callback);
|
|
452
|
+
}
|
|
453
|
+
onUpdated(callback) {
|
|
454
|
+
this._callbacks.hostUpdated.push(callback);
|
|
455
|
+
}
|
|
456
|
+
onDestroy(callback) {
|
|
457
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
|
|
458
|
+
this.component.manager._ensureHasDestroy?.();
|
|
459
|
+
}
|
|
460
|
+
this._callbacks.hostDestroy.push(callback);
|
|
461
|
+
}
|
|
462
|
+
onLifecycle(callback) {
|
|
463
|
+
this._callbacks.hostLifecycle.push(callback);
|
|
464
|
+
if (this.connectedCalled && this.component.el.isConnected) {
|
|
465
|
+
this._callLifecycle(callback);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// Call each lifecycle hook
|
|
469
|
+
/** @private */
|
|
470
|
+
triggerConnected() {
|
|
471
|
+
const genericController = this;
|
|
472
|
+
if (genericController.hostConnected) {
|
|
473
|
+
safeCall(genericController.hostConnected, genericController);
|
|
474
|
+
}
|
|
475
|
+
this._callbacks.hostConnected.forEach(safeCall);
|
|
476
|
+
this.triggerLifecycle();
|
|
477
|
+
this.connectedCalled = true;
|
|
478
|
+
}
|
|
479
|
+
/** @private */
|
|
480
|
+
triggerDisconnected() {
|
|
481
|
+
const genericController = this;
|
|
482
|
+
if (genericController.hostDisconnected) {
|
|
483
|
+
safeCall(genericController.hostDisconnected, genericController);
|
|
484
|
+
}
|
|
485
|
+
this._callbacks.hostDisconnected.forEach(safeCall);
|
|
486
|
+
this._lifecycleCleanups.forEach(safeCall);
|
|
487
|
+
this._lifecycleCleanups = [];
|
|
488
|
+
}
|
|
489
|
+
/** @private */
|
|
490
|
+
async triggerLoad() {
|
|
491
|
+
if (this._loadCalled) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
this._loadCalled = true;
|
|
495
|
+
const genericController = this;
|
|
496
|
+
if (genericController.hostLoad) {
|
|
497
|
+
await safeAsyncCall(genericController.hostLoad, genericController);
|
|
498
|
+
}
|
|
499
|
+
if (this._callbacks.hostLoad.length > 0) {
|
|
500
|
+
await Promise.allSettled(this._callbacks.hostLoad.map(safeAsyncCall));
|
|
501
|
+
}
|
|
502
|
+
this._ready.resolve(this._exports);
|
|
503
|
+
}
|
|
504
|
+
/** @private */
|
|
505
|
+
triggerLoaded() {
|
|
506
|
+
if (this.loadedCalled) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const genericController = this;
|
|
510
|
+
if (genericController.hostLoaded) {
|
|
511
|
+
safeCall(genericController.hostLoaded, genericController);
|
|
512
|
+
}
|
|
513
|
+
this._callbacks.hostLoaded.forEach(safeCall);
|
|
514
|
+
this.loadedCalled = true;
|
|
515
|
+
}
|
|
516
|
+
/** @private */
|
|
517
|
+
triggerUpdate(changes) {
|
|
518
|
+
const genericController = this;
|
|
519
|
+
if (genericController.hostUpdate) {
|
|
520
|
+
safeCall(genericController.hostUpdate, genericController, changes);
|
|
521
|
+
}
|
|
522
|
+
this._callbacks.hostUpdate.forEach(callUpdate, changes);
|
|
523
|
+
}
|
|
524
|
+
/** @private */
|
|
525
|
+
triggerUpdated(changes) {
|
|
526
|
+
const genericController = this;
|
|
527
|
+
if (genericController.hostUpdated) {
|
|
528
|
+
safeCall(genericController.hostUpdated, genericController, changes);
|
|
529
|
+
}
|
|
530
|
+
this._callbacks.hostUpdated.forEach(callUpdate, changes);
|
|
531
|
+
}
|
|
532
|
+
/** @private */
|
|
533
|
+
triggerDestroy() {
|
|
534
|
+
const genericController = this;
|
|
535
|
+
if (genericController.hostDestroy) {
|
|
536
|
+
safeCall(genericController.hostDestroy, genericController);
|
|
537
|
+
}
|
|
538
|
+
this._callbacks.hostDestroy.forEach(safeCall);
|
|
539
|
+
}
|
|
540
|
+
/** @private */
|
|
541
|
+
triggerLifecycle() {
|
|
542
|
+
const genericController = this;
|
|
543
|
+
if (genericController.hostLifecycle) {
|
|
544
|
+
this._callLifecycle(() => genericController.hostLifecycle());
|
|
545
|
+
}
|
|
546
|
+
this._callbacks.hostLifecycle.forEach(this._callLifecycle, this);
|
|
547
|
+
}
|
|
548
|
+
_callLifecycle(callback) {
|
|
549
|
+
setAmbientComponent(this.component);
|
|
550
|
+
const cleanupRaw = safeCall(callback);
|
|
551
|
+
const cleanup = Array.isArray(cleanupRaw) ? cleanupRaw : [cleanupRaw];
|
|
552
|
+
cleanup.forEach((cleanup2) => {
|
|
553
|
+
if (typeof cleanup2 === "function") {
|
|
554
|
+
this._lifecycleCleanups.push(cleanup2);
|
|
555
|
+
} else if (typeof cleanup2 === "object" && typeof cleanup2.remove === "function") {
|
|
556
|
+
this._lifecycleCleanups.push(cleanup2.remove);
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function callUpdate(callback) {
|
|
562
|
+
safeCall(callback, void 0, this);
|
|
563
|
+
}
|
|
564
|
+
const GenericController = Controller;
|
|
565
|
+
function makeProvisionalValue(base) {
|
|
566
|
+
if (typeof base !== "object" && typeof base !== "function" || base === null) {
|
|
567
|
+
return base;
|
|
568
|
+
}
|
|
569
|
+
const proxy = new Proxy(base, {
|
|
570
|
+
get(target, prop, receiver) {
|
|
571
|
+
if ((prop === "exports" || prop === "_exports") && prop in target && target[prop] === proxy) {
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
if (prop in target || prop in Promise.prototype || typeof prop === "symbol") {
|
|
575
|
+
return typeof target === "function" ? target[prop] : Reflect.get(target, prop, receiver);
|
|
576
|
+
}
|
|
577
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
|
|
578
|
+
if (process.env.NODE_ENV === "test" && (prop.startsWith("$$") || prop.startsWith("@@") || prop === "nodeType" || prop === "tagName" || prop === "toJSON" || prop === "hasAttribute")) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
console.error(
|
|
582
|
+
`Trying to access "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
return void 0;
|
|
586
|
+
},
|
|
587
|
+
set: (target, prop, newValue, receiver) => {
|
|
588
|
+
if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
|
|
589
|
+
console.error(`Trying to set "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
|
|
590
|
+
}
|
|
591
|
+
return Reflect.set(target, prop, newValue, receiver);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
return proxy;
|
|
595
|
+
}
|
|
596
|
+
const accessBeforeLoad = process.env.NODE_ENV !== "production" && isEsriInternalEnv() ? [
|
|
597
|
+
"This might be the case if you are trying to access an async controller in ",
|
|
598
|
+
"connectedCallback(). Or, if you are using it inside of ",
|
|
599
|
+
"componentWillLoad()/another controller without controller.use. Example correct ",
|
|
600
|
+
"usage:\n",
|
|
601
|
+
"makeController(async (component, controller)=>{ await controller.use(someOtherController); });"
|
|
602
|
+
].join("") : void 0;
|
|
603
|
+
export {
|
|
604
|
+
Controller as C,
|
|
605
|
+
GenericController as G,
|
|
606
|
+
shouldBypassGetter as a,
|
|
607
|
+
shouldBypassReadOnly as b,
|
|
608
|
+
controllerSymbol as c,
|
|
609
|
+
createEvent as d,
|
|
610
|
+
setParentController as e,
|
|
611
|
+
retrieveParentControllers as f,
|
|
612
|
+
createEventFactory as g,
|
|
613
|
+
bypassGetter as h,
|
|
614
|
+
isPromise as i,
|
|
615
|
+
bypassSetter as j,
|
|
616
|
+
keyTrackResolve as k,
|
|
617
|
+
bypassReadOnly as l,
|
|
618
|
+
trackPropertyKey as m,
|
|
619
|
+
trackPropKey as n,
|
|
620
|
+
isController as o,
|
|
621
|
+
devOnlySetPersistentControllerData as p,
|
|
622
|
+
devOnlyGetPersistentControllerData as q,
|
|
623
|
+
retrieveComponent as r,
|
|
624
|
+
setAmbientComponent as s,
|
|
625
|
+
trackKey as t,
|
|
626
|
+
setAmbientChildController as u
|
|
627
|
+
};
|