@makoojs/core 0.4.0 → 0.6.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/README.CN.md +76 -252
- package/README.md +76 -254
- package/dist/adapter/types.d.ts +42 -51
- package/dist/error/MakooError.d.ts +22 -11
- package/dist/error/coreErrors.d.ts +6793 -0
- package/dist/error/defineMakooErrors.d.ts +55 -0
- package/dist/index.cjs +4 -5
- package/dist/index.d.ts +16 -19
- package/dist/index.js +923 -1707
- package/dist/injections/inject/declaration.d.ts +32 -0
- package/dist/injections/inject/inject.d.ts +38 -0
- package/dist/injections/injectEach/declaration.d.ts +25 -0
- package/dist/injections/injectEach/injectEach.d.ts +43 -0
- package/dist/injections/kinds.d.ts +12 -0
- package/dist/injections/listen/declaration.d.ts +34 -0
- package/dist/injections/listen/listen.d.ts +36 -0
- package/dist/injections/mount.d.ts +17 -0
- package/dist/instance/createMakoo.d.ts +3 -0
- package/dist/instance/residue.d.ts +7 -0
- package/dist/instance/types.d.ts +81 -0
- package/dist/runtime/injection.d.ts +94 -0
- package/dist/runtime/match.d.ts +50 -0
- package/dist/runtime/observer.d.ts +9 -0
- package/dist/runtime/scope.d.ts +28 -0
- package/dist/runtime/selector.d.ts +1 -0
- package/dist/runtime/stateNode.d.ts +51 -0
- package/package.json +1 -1
- package/dist/Makoo/createMakoo.d.ts +0 -4
- package/dist/Makoo/types.d.ts +0 -103
- package/dist/Task/TaskContext.d.ts +0 -25
- package/dist/Task/TaskLifeCycle.d.ts +0 -7
- package/dist/Task/TaskRegister.d.ts +0 -19
- package/dist/Task/TaskRunner.d.ts +0 -7
- package/dist/Task/types.d.ts +0 -76
- package/dist/Task/util.d.ts +0 -11
- package/dist/adapter/Adapter.d.ts +0 -2
- package/dist/error/AdapterError.d.ts +0 -4
- package/dist/error/ErrorCode.d.ts +0 -19
- package/dist/error/SignalError.d.ts +0 -4
- package/dist/error/TaskError.d.ts +0 -4
- package/dist/error/formatMakooError.d.ts +0 -2
- package/dist/hooks/ObserverHub.d.ts +0 -3
- package/dist/hooks/types.d.ts +0 -39
- package/dist/hooks/util.d.ts +0 -5
- package/dist/logger/Logger.d.ts +0 -14
- package/dist/logger/types.d.ts +0 -7
- package/dist/payload/buildAliveObservePayload.d.ts +0 -51
- package/dist/payload/buildDomObservePayload.d.ts +0 -46
- package/dist/payload/buildInjectObservePayload.d.ts +0 -54
- package/dist/payload/buildListenerObservePayload.d.ts +0 -44
- package/dist/payload/buildObservePayload.d.ts +0 -10
- package/dist/payload/buildRegisterObservePayload.d.ts +0 -44
- package/dist/payload/buildResourceObservePayload.d.ts +0 -45
- package/dist/payload/buildRunObservePayload.d.ts +0 -57
- package/dist/payload/buildTaskObservePayload.d.ts +0 -44
- package/dist/payload/createDomObserveEmitFactory.d.ts +0 -12
- package/dist/runtime/createRuntime.d.ts +0 -3
- package/dist/runtime/types.d.ts +0 -13
- package/dist/signal/observeActivitySignal.d.ts +0 -4
- package/dist/signal/types.d.ts +0 -15
- package/dist/util/getArtifactName.d.ts +0 -1
- package/dist/util/uuid.d.ts +0 -1
- package/dist/watcher/DomWatcher.d.ts +0 -13
- package/dist/watcher/types.d.ts +0 -15
package/dist/index.js
CHANGED
|
@@ -1,1798 +1,1014 @@
|
|
|
1
|
-
//#region packages/core/src/error/
|
|
2
|
-
var e = {
|
|
3
|
-
UNKNOWN: "MAKOO_UNKNOWN",
|
|
4
|
-
ADAPTER_NOT_FOUND: "MAKOO_ADAPTER_NOT_FOUND",
|
|
5
|
-
ADAPTER_MOUNT_FAIL: "MAKOO_ADAPTER_MOUNT_FAIL",
|
|
6
|
-
ADAPTER_UNMOUNT_FAIL: "MAKOO_ADAPTER_UNMOUNT_FAIL",
|
|
7
|
-
TASK_NO_REGISTERED: "MAKOO_TASK_NO_REGISTERED",
|
|
8
|
-
TASK_NOT_FOUND: "MAKOO_TASK_NOT_FOUND",
|
|
9
|
-
TASK_INJECT_FAIL: "MAKOO_TASK_INJECT_FAIL",
|
|
10
|
-
TASK_ALREADY_MOUNTED: "MAKOO_TASK_ALREADY_MOUNTED",
|
|
11
|
-
TASK_TARGET_DETACHED: "MAKOO_TASK_TARGET_DETACHED",
|
|
12
|
-
TASK_LISTENER_ATTACH_FAIL: "MAKOO_TASK_LISTENER_ATTACH_FAIL",
|
|
13
|
-
TASK_ROOT_REMOVE_FAIL: "MAKOO_TASK_ROOT_REMOVE_FAIL",
|
|
14
|
-
TASK_LISTENER_ABORT_FAIL: "MAKOO_TASK_LISTENER_ABORT_FAIL",
|
|
15
|
-
TASK_WATCHER_STOP_FAIL: "MAKOO_TASK_WATCHER_STOP_FAIL",
|
|
16
|
-
TASK_SIGNAL_INVALID: "MAKOO_TASK_SIGNAL_INVALID",
|
|
17
|
-
TASK_SIGNAL_BIND_FAIL: "MAKOO_TASK_SIGNAL_BIND_FAIL",
|
|
18
|
-
HOOK_EXECUTION_FAIL: "MAKOO_HOOK_EXECUTION_FAIL"
|
|
19
|
-
}, t = class extends Error {
|
|
1
|
+
//#region packages/core/src/error/MakooError.ts
|
|
2
|
+
var e = Symbol.for("makoo.error"), t = class extends Error {
|
|
20
3
|
code;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
context = {};
|
|
24
|
-
cause;
|
|
25
|
-
constructor(t, n, r = e.UNKNOWN, i) {
|
|
26
|
-
let a = [`[makoo] ${t}`];
|
|
27
|
-
if (n?.length) for (let e of n) a.push(` - ${e.path}: ${e.message}`);
|
|
28
|
-
super(a.join("\n")), this.name = "MakooError", this.code = r, this.issues = n ?? [], this.summary = t, i && (this.cause = i);
|
|
4
|
+
constructor(t, n) {
|
|
5
|
+
super(t), this.name = "MakooError", this.code = n.code, n.category !== void 0 && (this.category = n.category), n.cause !== void 0 && (this.cause = n.cause), n.details !== void 0 && (this.details = n.details), n.errors !== void 0 && (this.errors = n.errors), Object.defineProperty(this, e, { value: !0 });
|
|
29
6
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
super(t, n, r, i), this.name = "SignalError";
|
|
40
|
-
}
|
|
41
|
-
}, i = class extends t {
|
|
42
|
-
constructor(t, n, r = e.TASK_NO_REGISTERED, i) {
|
|
43
|
-
super(t, n, r, i), this.name = "TaskError";
|
|
44
|
-
}
|
|
45
|
-
}, a = (e) => typeof e == "string" ? JSON.stringify(e) : String(e), o = (e) => e.split("\n").map((e) => ` ${e}`).join("\n");
|
|
46
|
-
function s(e) {
|
|
47
|
-
let t = [`${e.name} [${e.code}]:`, e.summary];
|
|
48
|
-
if (e.issues.length > 0) for (let n of e.issues) t.push(` - ${n.path}: ${n.message}`);
|
|
49
|
-
let n = Object.entries(e.context);
|
|
50
|
-
return n.length > 0 && t.push(`(${n.map(([e, t]) => `${e}: ${a(t)}`).join(", ")})`), e.cause?.stack && t.push("", o(e.cause.stack)), t.join("\n");
|
|
7
|
+
};
|
|
8
|
+
function n(t) {
|
|
9
|
+
return typeof t == "object" && !!t && t[e] === !0;
|
|
10
|
+
}
|
|
11
|
+
function r(e, t) {
|
|
12
|
+
return [e, ...t.map((e) => {
|
|
13
|
+
let t = e instanceof Error ? e.message : String(e), n = t.indexOf("\n");
|
|
14
|
+
return n === -1 ? t : t.slice(0, n);
|
|
15
|
+
})].join("\n");
|
|
51
16
|
}
|
|
52
17
|
//#endregion
|
|
53
|
-
//#region packages/core/src/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
constructor(e = "info") {
|
|
64
|
-
this.level = e;
|
|
65
|
-
}
|
|
66
|
-
setLevel(e) {
|
|
67
|
-
this.level = e;
|
|
68
|
-
}
|
|
69
|
-
getLevel() {
|
|
70
|
-
return this.level;
|
|
71
|
-
}
|
|
72
|
-
log(t, n, ...r) {
|
|
73
|
-
let i = (/* @__PURE__ */ new Date()).toISOString(), a = e.LEVELS.indexOf(t), o = e.LEVELS.indexOf(this.level);
|
|
74
|
-
a === -1 || o === -1 || a < o || console[t](`${e.PREFIX}[${t.toUpperCase()}][${i}] ${n}`, ...r);
|
|
75
|
-
}
|
|
76
|
-
info(e, ...t) {
|
|
77
|
-
this.log("info", e, ...t);
|
|
78
|
-
}
|
|
79
|
-
error(e, ...t) {
|
|
80
|
-
this.log("error", e, ...t);
|
|
81
|
-
}
|
|
82
|
-
warn(e, ...t) {
|
|
83
|
-
this.log("warn", e, ...t);
|
|
84
|
-
}
|
|
85
|
-
debug(e, ...t) {
|
|
86
|
-
this.log("debug", e, ...t);
|
|
87
|
-
}
|
|
88
|
-
}, l = () => {};
|
|
89
|
-
function u(e) {
|
|
90
|
-
return e ? (t, n = {}) => {
|
|
91
|
-
e.emit({
|
|
92
|
-
name: t,
|
|
93
|
-
ts: Date.now(),
|
|
94
|
-
...n
|
|
18
|
+
//#region packages/core/src/error/defineMakooErrors.ts
|
|
19
|
+
function i(e) {
|
|
20
|
+
function n(n, ...i) {
|
|
21
|
+
let a = e[n], o = i[0], s = o?.details, c = a.message(s);
|
|
22
|
+
return o?.errors?.length && (c = r(c, o.errors)), new t(c, {
|
|
23
|
+
category: a.category,
|
|
24
|
+
cause: o?.cause,
|
|
25
|
+
code: n,
|
|
26
|
+
details: s,
|
|
27
|
+
errors: o?.errors
|
|
95
28
|
});
|
|
96
|
-
} : l;
|
|
97
|
-
}
|
|
98
|
-
function d(e, t, n) {
|
|
99
|
-
if (t) for (let [r, i] of Object.entries(t)) {
|
|
100
|
-
if (!i) continue;
|
|
101
|
-
let t = Array.isArray(i) ? i : [i];
|
|
102
|
-
for (let i of t) n ? e.onTask(n, r, i) : e.on(r, i);
|
|
103
29
|
}
|
|
104
|
-
}
|
|
105
|
-
function f() {
|
|
106
|
-
let e = !1, t = !1;
|
|
107
30
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
stopImmediatePropagation() {
|
|
113
|
-
e = !0, t = !0;
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
isPropagationStopped() {
|
|
117
|
-
return e;
|
|
118
|
-
},
|
|
119
|
-
isImmediatePropagationStopped() {
|
|
120
|
-
return t;
|
|
121
|
-
}
|
|
31
|
+
create: n,
|
|
32
|
+
createThrowable: n,
|
|
33
|
+
createRecorded: n
|
|
122
34
|
};
|
|
123
35
|
}
|
|
36
|
+
var a = i({
|
|
37
|
+
MAKOO_CALL_OUTSIDE_MATCH: {
|
|
38
|
+
category: "configuration",
|
|
39
|
+
message: (e) => `${e.call}() must be called synchronously inside a match callback`
|
|
40
|
+
},
|
|
41
|
+
MAKOO_CALL_OUTSIDE_SETUP: {
|
|
42
|
+
category: "configuration",
|
|
43
|
+
message: (e) => `${e.call}() must be called synchronously inside a setup`
|
|
44
|
+
},
|
|
45
|
+
MAKOO_DECLARATION_INVALID: {
|
|
46
|
+
category: "configuration",
|
|
47
|
+
message: (e) => e.reason
|
|
48
|
+
},
|
|
49
|
+
MAKOO_INJECTION_NAME_CONFLICT: {
|
|
50
|
+
category: "configuration",
|
|
51
|
+
message: (e) => `Injection name "${e.name}" is already occupied${e.at === void 0 ? "" : ` (${e.at})`}`
|
|
52
|
+
},
|
|
53
|
+
MAKOO_STATE_NODE_ALREADY_BOUND: {
|
|
54
|
+
category: "configuration",
|
|
55
|
+
message: (e) => `State node "${e.name}" is already bound`
|
|
56
|
+
},
|
|
57
|
+
MAKOO_INJECTION_NOT_FOUND: {
|
|
58
|
+
category: "control",
|
|
59
|
+
message: (e) => `Unknown injection "${e.name}"`
|
|
60
|
+
},
|
|
61
|
+
MAKOO_INJECTION_REMOVED: {
|
|
62
|
+
category: "control",
|
|
63
|
+
message: (e) => `Injection "${e.name}" was removed`
|
|
64
|
+
},
|
|
65
|
+
MAKOO_INSTANCE_DISPOSED: {
|
|
66
|
+
category: "control",
|
|
67
|
+
message: () => "Core instance is disposed"
|
|
68
|
+
},
|
|
69
|
+
MAKOO_ATTACHED_LISTENER_FAILED: {
|
|
70
|
+
category: "execution",
|
|
71
|
+
message: (e) => `"${e.name}" stopped because listener "${e.listener}" failed`
|
|
72
|
+
},
|
|
73
|
+
MAKOO_LISTENER_BIND_FAILED: {
|
|
74
|
+
category: "execution",
|
|
75
|
+
message: (e) => `Failed to bind listener "${e.name}"`
|
|
76
|
+
},
|
|
77
|
+
MAKOO_MOUNT_FAILED: {
|
|
78
|
+
category: "execution",
|
|
79
|
+
message: (e) => `Failed to mount "${e.name}"`
|
|
80
|
+
},
|
|
81
|
+
MAKOO_TARGET_DETACHED: {
|
|
82
|
+
category: "execution",
|
|
83
|
+
message: (e) => `Target "${e.selector}" of "${e.name}" disconnected`
|
|
84
|
+
},
|
|
85
|
+
MAKOO_TARGET_WAIT_TIMEOUT: {
|
|
86
|
+
category: "execution",
|
|
87
|
+
message: (e) => `Timed out waiting for target "${e.selector}" of "${e.name}"` + (e.lockedSkipped ? ` (${e.lockedSkipped} matching element${e.lockedSkipped === 1 ? "" : "s"} skipped: locked after a failed cleanup)` : "")
|
|
88
|
+
},
|
|
89
|
+
MAKOO_CONTAINER_REMOVE_FAILED: {
|
|
90
|
+
category: "cleanup",
|
|
91
|
+
message: (e) => `Failed to remove container of "${e.name}"`
|
|
92
|
+
},
|
|
93
|
+
MAKOO_INJECTION_CLEANUP_FAILED: {
|
|
94
|
+
category: "cleanup",
|
|
95
|
+
aggregate: !0,
|
|
96
|
+
message: (e) => `Cleanup failed for "${e.name}"`
|
|
97
|
+
},
|
|
98
|
+
MAKOO_INSTANCE_CLEANUP_FAILED: {
|
|
99
|
+
category: "cleanup",
|
|
100
|
+
aggregate: !0,
|
|
101
|
+
message: () => "Failed to dispose core"
|
|
102
|
+
},
|
|
103
|
+
MAKOO_LISTENER_UNBIND_FAILED: {
|
|
104
|
+
category: "cleanup",
|
|
105
|
+
message: (e) => `Failed to unbind listener "${e.name}"`
|
|
106
|
+
},
|
|
107
|
+
MAKOO_MOUNT_CLEANUP_FAILED: {
|
|
108
|
+
category: "cleanup",
|
|
109
|
+
aggregate: !0,
|
|
110
|
+
message: (e) => `Cleanup after mount of "${e.name}" failed`
|
|
111
|
+
},
|
|
112
|
+
MAKOO_UNMOUNT_FAILED: {
|
|
113
|
+
category: "cleanup",
|
|
114
|
+
message: (e) => `Failed to unmount "${e.name}"`
|
|
115
|
+
},
|
|
116
|
+
MAKOO_INSTANCE_OBSERVER_FAILED: {
|
|
117
|
+
category: "callback",
|
|
118
|
+
message: () => "Instance observe handler failed"
|
|
119
|
+
},
|
|
120
|
+
MAKOO_LISTENER_CALLBACK_FAILED: {
|
|
121
|
+
category: "callback",
|
|
122
|
+
message: (e) => `Callback of listener "${e.name}" failed`
|
|
123
|
+
},
|
|
124
|
+
MAKOO_STATE_SUBSCRIBER_FAILED: {
|
|
125
|
+
category: "callback",
|
|
126
|
+
message: (e) => `State subscriber of ${e.owner} failed`
|
|
127
|
+
}
|
|
128
|
+
});
|
|
124
129
|
//#endregion
|
|
125
|
-
//#region packages/core/src/
|
|
126
|
-
function
|
|
127
|
-
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
|
|
128
|
-
function o(e, t) {
|
|
129
|
-
if (t) {
|
|
130
|
-
let n = r.get(e);
|
|
131
|
-
if (!n) return;
|
|
132
|
-
n.delete(t), n.size === 0 && r.delete(e);
|
|
133
|
-
} else r.delete(e);
|
|
134
|
-
}
|
|
135
|
-
function l(e, t, n) {
|
|
136
|
-
let r = i.get(e);
|
|
137
|
-
if (!r) return;
|
|
138
|
-
if (!t) {
|
|
139
|
-
i.delete(e);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (!n) {
|
|
143
|
-
r.delete(t), r.size === 0 && i.delete(e);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
let a = r.get(t);
|
|
147
|
-
a && (a.delete(n), a.size === 0 && r.delete(t), r.size === 0 && i.delete(e));
|
|
148
|
-
}
|
|
149
|
-
function u(e) {
|
|
150
|
-
a.delete(e);
|
|
151
|
-
}
|
|
152
|
-
function d(e, t, n) {
|
|
153
|
-
if (!(!e || e.size === 0)) for (let r of [...e]) {
|
|
154
|
-
if (n.isImmediatePropagationStopped()) return;
|
|
155
|
-
p(r, t, n.ctrl);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function p(r, i, a) {
|
|
159
|
-
try {
|
|
160
|
-
r(i, a);
|
|
161
|
-
} catch (r) {
|
|
162
|
-
let a = r instanceof t ? r : new t(`Hook execution failed for event "${i.name}"`, void 0, e.HOOK_EXECUTION_FAIL, r instanceof Error ? r : Error(String(r)));
|
|
163
|
-
a.withContext({
|
|
164
|
-
event: i.name,
|
|
165
|
-
taskId: i.taskId ?? null
|
|
166
|
-
}), n.error(s(a));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function m(e, t) {
|
|
170
|
-
let n = t.taskId === e ? t : {
|
|
171
|
-
...t,
|
|
172
|
-
taskId: e
|
|
173
|
-
}, o = i.get(e)?.get(n.name), s = r.get(n.name), c = !!(o && o.size > 0), l = !!(s && s.size > 0);
|
|
174
|
-
if (!c && !l && a.size === 0) return;
|
|
175
|
-
let u = f();
|
|
176
|
-
d(o, n, u), !u.isPropagationStopped() && (d(s, n, u), !u.isPropagationStopped() && d(a, n, u));
|
|
177
|
-
}
|
|
130
|
+
//#region packages/core/src/injections/inject/declaration.ts
|
|
131
|
+
function o(e) {
|
|
178
132
|
return {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
o(e, t);
|
|
182
|
-
};
|
|
183
|
-
},
|
|
184
|
-
onTask(e, t, n) {
|
|
185
|
-
i.has(e) || i.set(e, /* @__PURE__ */ new Map());
|
|
186
|
-
let r = i.get(e);
|
|
187
|
-
return r?.has(t) || r?.set(t, /* @__PURE__ */ new Set()), r?.get(t)?.add(n), () => {
|
|
188
|
-
l(e, t, n);
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
onAny(e) {
|
|
192
|
-
return a.add(e), () => {
|
|
193
|
-
u(e);
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
|
-
off: o,
|
|
197
|
-
offTask: l,
|
|
198
|
-
offAny: u,
|
|
199
|
-
clear() {
|
|
200
|
-
r.clear(), a.clear(), i.clear();
|
|
201
|
-
},
|
|
202
|
-
hasHooks(e) {
|
|
203
|
-
if (e) {
|
|
204
|
-
let t = r.get(e);
|
|
205
|
-
if (t && t.size > 0 || a.size > 0) return !0;
|
|
206
|
-
for (let t of i.values()) {
|
|
207
|
-
let n = t.get(e);
|
|
208
|
-
if (n && n.size > 0) return !0;
|
|
209
|
-
}
|
|
210
|
-
return !1;
|
|
211
|
-
}
|
|
212
|
-
if (a.size > 0) return !0;
|
|
213
|
-
for (let e of r.values()) if (e.size > 0) return !0;
|
|
214
|
-
for (let e of i.values()) for (let t of e.values()) if (t.size > 0) return !0;
|
|
215
|
-
return !1;
|
|
216
|
-
},
|
|
217
|
-
emit(e) {
|
|
218
|
-
if (e.taskId) {
|
|
219
|
-
m(e.taskId, e);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
let t = f();
|
|
223
|
-
d(r.get(e.name), e, t), !t.isPropagationStopped() && d(a, e, t);
|
|
224
|
-
},
|
|
225
|
-
emitOnTask: m
|
|
133
|
+
...e,
|
|
134
|
+
kind: "component"
|
|
226
135
|
};
|
|
227
136
|
}
|
|
228
137
|
//#endregion
|
|
229
|
-
//#region packages/core/src/
|
|
230
|
-
|
|
231
|
-
//#endregion
|
|
232
|
-
//#region packages/core/src/adapter/Adapter.ts
|
|
233
|
-
function h() {
|
|
234
|
-
let e = [];
|
|
138
|
+
//#region packages/core/src/injections/injectEach/declaration.ts
|
|
139
|
+
function s(e) {
|
|
235
140
|
return {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
},
|
|
239
|
-
use(t) {
|
|
240
|
-
e.includes(t) || e.push(t);
|
|
241
|
-
}
|
|
141
|
+
...e,
|
|
142
|
+
kind: "component-each"
|
|
242
143
|
};
|
|
243
144
|
}
|
|
244
145
|
//#endregion
|
|
245
|
-
//#region packages/core/src/
|
|
246
|
-
function
|
|
247
|
-
return
|
|
146
|
+
//#region packages/core/src/injections/listen/declaration.ts
|
|
147
|
+
function c(e) {
|
|
148
|
+
return {
|
|
149
|
+
...e,
|
|
150
|
+
kind: "listener"
|
|
151
|
+
};
|
|
248
152
|
}
|
|
249
153
|
//#endregion
|
|
250
|
-
//#region packages/core/src/
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
meta: { resource: "watcher" }
|
|
258
|
-
}),
|
|
259
|
-
"resource:listenerReleased": (e) => ({
|
|
260
|
-
taskId: e.taskId,
|
|
261
|
-
kind: e.kind,
|
|
262
|
-
injectAt: e.injectAt,
|
|
263
|
-
status: e.status,
|
|
264
|
-
meta: {
|
|
265
|
-
resource: "listener",
|
|
266
|
-
listenerEvent: e.listenerEvent,
|
|
267
|
-
listenAt: e.listenAt
|
|
268
|
-
}
|
|
269
|
-
}),
|
|
270
|
-
"artifact:unmounted": (e) => ({
|
|
271
|
-
taskId: e.taskId,
|
|
272
|
-
kind: e.kind,
|
|
273
|
-
injectAt: e.injectAt,
|
|
274
|
-
status: e.status,
|
|
275
|
-
meta: {
|
|
276
|
-
resource: "component",
|
|
277
|
-
artifactName: e.artifactName
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
};
|
|
281
|
-
function v(e, t) {
|
|
282
|
-
return g(e, t, _);
|
|
154
|
+
//#region packages/core/src/runtime/selector.ts
|
|
155
|
+
function l(e, t) {
|
|
156
|
+
try {
|
|
157
|
+
document.createDocumentFragment().querySelector(t);
|
|
158
|
+
} catch {
|
|
159
|
+
throw a.createThrowable("MAKOO_DECLARATION_INVALID", { details: { reason: `${e}: Expected a valid CSS selector, got "${t}"` } });
|
|
160
|
+
}
|
|
283
161
|
}
|
|
284
162
|
//#endregion
|
|
285
|
-
//#region packages/core/src/
|
|
286
|
-
var
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
taskId: e.taskId,
|
|
296
|
-
kind: e.kind,
|
|
297
|
-
injectAt: e.injectAt,
|
|
298
|
-
status: e.status
|
|
299
|
-
}),
|
|
300
|
-
"task:afterReset": (e) => ({
|
|
301
|
-
taskId: e.taskId,
|
|
302
|
-
kind: e.kind,
|
|
303
|
-
injectAt: e.injectAt,
|
|
304
|
-
status: e.status,
|
|
305
|
-
preStatus: e.preStatus
|
|
306
|
-
}),
|
|
307
|
-
"task:beforeDestroy": (e) => ({
|
|
308
|
-
taskId: e.taskId,
|
|
309
|
-
kind: e.kind,
|
|
310
|
-
injectAt: e.injectAt,
|
|
311
|
-
status: e.status
|
|
312
|
-
}),
|
|
313
|
-
"task:afterDestroy": (e) => ({
|
|
314
|
-
taskId: e.taskId,
|
|
315
|
-
kind: e.kind,
|
|
316
|
-
injectAt: e.injectAt,
|
|
317
|
-
preStatus: e.preStatus
|
|
163
|
+
//#region packages/core/src/injections/listen/listen.ts
|
|
164
|
+
var u = {
|
|
165
|
+
kind: "listener",
|
|
166
|
+
active: "bound",
|
|
167
|
+
resolve(e) {
|
|
168
|
+
return l("listenAt", e.listenAt), e;
|
|
169
|
+
},
|
|
170
|
+
create: (e) => ({
|
|
171
|
+
expose: {},
|
|
172
|
+
setup: (t) => d(t, e)
|
|
318
173
|
})
|
|
319
174
|
};
|
|
320
|
-
function
|
|
321
|
-
|
|
175
|
+
function d(e, t) {
|
|
176
|
+
e.match("first", t.listenAt, t, (n) => f(n, t, e));
|
|
177
|
+
}
|
|
178
|
+
function f(e, t, n) {
|
|
179
|
+
let r = (r) => {
|
|
180
|
+
let i = (e) => {
|
|
181
|
+
let r = a.create("MAKOO_LISTENER_CALLBACK_FAILED", {
|
|
182
|
+
details: { name: t.name },
|
|
183
|
+
cause: e
|
|
184
|
+
});
|
|
185
|
+
console.error(r), n.diagnostic(r);
|
|
186
|
+
};
|
|
187
|
+
try {
|
|
188
|
+
let n = t.callback.call(e, r);
|
|
189
|
+
n !== void 0 && Promise.resolve(n).catch(i);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
i(e);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
try {
|
|
195
|
+
e.addEventListener(t.type, r, { capture: t.capture });
|
|
196
|
+
} catch (e) {
|
|
197
|
+
throw a.createRecorded("MAKOO_LISTENER_BIND_FAILED", {
|
|
198
|
+
details: { name: t.name },
|
|
199
|
+
cause: e
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
n.onCleanup(() => {
|
|
203
|
+
try {
|
|
204
|
+
e.removeEventListener(t.type, r, { capture: t.capture });
|
|
205
|
+
} catch (e) {
|
|
206
|
+
throw a.createRecorded("MAKOO_LISTENER_UNBIND_FAILED", {
|
|
207
|
+
details: { name: t.name },
|
|
208
|
+
cause: e
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|
|
322
212
|
}
|
|
323
213
|
//#endregion
|
|
324
|
-
//#region packages/core/src/
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
message: "must provide get() and subscribe() methods"
|
|
336
|
-
}], e.TASK_SIGNAL_INVALID);
|
|
214
|
+
//#region packages/core/src/injections/inject/inject.ts
|
|
215
|
+
function p(e) {
|
|
216
|
+
let t = /* @__PURE__ */ new Set();
|
|
217
|
+
e.listeners?.forEach((e, n) => {
|
|
218
|
+
if (t.has(e.name)) throw a.createThrowable("MAKOO_INJECTION_NAME_CONFLICT", { details: {
|
|
219
|
+
name: e.name,
|
|
220
|
+
at: `listeners[${n}]`
|
|
221
|
+
} });
|
|
222
|
+
if ("reinject" in e && e.reinject !== void 0) throw a.createThrowable("MAKOO_DECLARATION_INVALID", { details: { reason: `Attached listeners inherit the component recovery setting (listeners[${n}].reinject)` } });
|
|
223
|
+
t.add(e.name);
|
|
224
|
+
});
|
|
337
225
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region packages/core/src/injections/kinds.ts
|
|
228
|
+
var m = {
|
|
229
|
+
component: {
|
|
230
|
+
kind: "component",
|
|
231
|
+
active: "mounted",
|
|
232
|
+
resolve(e) {
|
|
233
|
+
return l("injectAt", e.injectAt), p(e), e.listeners?.forEach((e, t) => {
|
|
234
|
+
l(`listeners[${t}].listenAt`, e.listenAt);
|
|
235
|
+
}), e;
|
|
348
236
|
},
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
237
|
+
create(e, t) {
|
|
238
|
+
let n = (e.listeners ?? []).map((n) => {
|
|
239
|
+
let r = {
|
|
240
|
+
...n,
|
|
241
|
+
reinject: e.reinject
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
declaration: r,
|
|
245
|
+
node: t.stateNode({
|
|
246
|
+
name: r.name,
|
|
247
|
+
active: "bound"
|
|
248
|
+
}),
|
|
249
|
+
escalateAs: (t) => a.createRecorded("MAKOO_ATTACHED_LISTENER_FAILED", {
|
|
250
|
+
details: {
|
|
251
|
+
name: e.name,
|
|
252
|
+
listener: r.name
|
|
253
|
+
},
|
|
254
|
+
cause: t
|
|
255
|
+
})
|
|
256
|
+
};
|
|
257
|
+
}), r = Object.create(null);
|
|
258
|
+
for (let e of n) r[e.declaration.name] = e.node.view;
|
|
259
|
+
return {
|
|
260
|
+
expose: { attachedListeners: Object.freeze(r) },
|
|
261
|
+
setup(t) {
|
|
262
|
+
t.match("first", e.injectAt, e, () => {
|
|
263
|
+
t.mount(e);
|
|
264
|
+
for (let e of n) e.node.launch((t) => d(t, e.declaration), e.escalateAs);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
352
267
|
};
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
"component-each": {
|
|
271
|
+
kind: "component-each",
|
|
272
|
+
active: "collecting",
|
|
273
|
+
resolve(e) {
|
|
274
|
+
return l("injectAt", e.injectAt), e;
|
|
353
275
|
},
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
276
|
+
create(e, t) {
|
|
277
|
+
let n = /* @__PURE__ */ new Map(), r = 0;
|
|
278
|
+
return {
|
|
279
|
+
expose: { get children() {
|
|
280
|
+
return [...n.entries()].sort(([e], [t]) => e.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1).map(([, e]) => e);
|
|
281
|
+
} },
|
|
282
|
+
setup(i) {
|
|
283
|
+
i.match("all", e.injectAt, (a) => {
|
|
284
|
+
let o = t.stateNode({
|
|
285
|
+
name: `${e.name}#${r++}`,
|
|
286
|
+
active: "mounted",
|
|
287
|
+
waiting: "idle"
|
|
288
|
+
}), s = o.flatten({
|
|
289
|
+
kind: "component-child",
|
|
290
|
+
name: o.name,
|
|
291
|
+
stop: o.stop
|
|
292
|
+
});
|
|
293
|
+
o.bind(s), i.mount(e), n.set(a, s), i.onCleanup(() => {
|
|
294
|
+
n.delete(a);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
};
|
|
359
299
|
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
300
|
+
},
|
|
301
|
+
listener: u
|
|
302
|
+
};
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region packages/core/src/injections/mount.ts
|
|
305
|
+
function h(e, t) {
|
|
306
|
+
let { appearance: r, name: i } = e, { element: o, scope: s } = r, c = e.injection, { adapter: l, component: u, listener: d, observer: f, props: p } = t, m = document.createElement("div");
|
|
307
|
+
o.append(m), r.exclude(m);
|
|
308
|
+
let h = new AbortController();
|
|
309
|
+
s.onCleanup(() => h.abort()), s.onCleanup(() => {
|
|
310
|
+
try {
|
|
311
|
+
m.remove();
|
|
312
|
+
} catch (e) {
|
|
313
|
+
throw a.createRecorded("MAKOO_CONTAINER_REMOVE_FAILED", {
|
|
314
|
+
details: { name: i },
|
|
315
|
+
cause: e
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}), f.subscribe(() => {
|
|
319
|
+
s.isEnded || (!m.isConnected || !o.contains(m)) && r.leave();
|
|
320
|
+
}, h.signal);
|
|
321
|
+
let g;
|
|
322
|
+
try {
|
|
323
|
+
g = l.mount({
|
|
324
|
+
component: u,
|
|
325
|
+
injection: c,
|
|
326
|
+
props: p,
|
|
327
|
+
container: m,
|
|
328
|
+
listener: d
|
|
329
|
+
});
|
|
330
|
+
} catch (e) {
|
|
331
|
+
let t = n(e) && e.code === "MAKOO_MOUNT_CLEANUP_FAILED" ? e : void 0;
|
|
332
|
+
throw t?.errors && s.addCleanupErrors(t.errors), a.createRecorded("MAKOO_MOUNT_FAILED", {
|
|
333
|
+
details: { name: i },
|
|
334
|
+
cause: t ? t.cause : e
|
|
335
|
+
});
|
|
370
336
|
}
|
|
371
|
-
|
|
337
|
+
s.onCleanup(() => {
|
|
338
|
+
try {
|
|
339
|
+
l.unmount(g);
|
|
340
|
+
} catch (e) {
|
|
341
|
+
throw a.createRecorded("MAKOO_UNMOUNT_FAILED", {
|
|
342
|
+
details: { name: i },
|
|
343
|
+
cause: e
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}), !s.isEnded && (!o.isConnected || !m.isConnected || !o.contains(m)) && r.leave();
|
|
347
|
+
}
|
|
348
|
+
function g(e, t, n, r, i) {
|
|
349
|
+
let o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), c = 0, l = /* @__PURE__ */ new WeakSet(), u = new AbortController(), d, f = () => {
|
|
350
|
+
for (let e of o.values()) if (m(e)) return !0;
|
|
351
|
+
return !1;
|
|
352
|
+
}, p = (e) => {
|
|
353
|
+
for (let t = e; t; t = t.parentElement) if (s.has(t)) return !0;
|
|
354
|
+
return !1;
|
|
355
|
+
}, m = (e) => e !== "failed" && !e.scope.isEnded, h = () => {
|
|
356
|
+
if (!e.isEnded) {
|
|
357
|
+
for (let [e, t] of [...o]) e.isConnected || (t === "failed" ? o.delete(e) : t.leave());
|
|
358
|
+
if (c = 0, n.mode !== "first" || !f()) for (let i of document.querySelectorAll(t)) {
|
|
359
|
+
if (e.isEnded) return;
|
|
360
|
+
if (!(!i.isConnected || o.has(i) || l.has(i) || p(i))) {
|
|
361
|
+
if (r.isLocked(i)) {
|
|
362
|
+
c++;
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (g(i), n.mode === "first" && f()) break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
v();
|
|
369
|
+
}
|
|
370
|
+
}, g = (t) => {
|
|
371
|
+
let a = !1, c;
|
|
372
|
+
e.spawn({
|
|
373
|
+
setup: (e) => {
|
|
374
|
+
c = {
|
|
375
|
+
element: t,
|
|
376
|
+
scope: e,
|
|
377
|
+
exclude(t) {
|
|
378
|
+
s.add(t), e.onCleanup(() => s.delete(t));
|
|
379
|
+
},
|
|
380
|
+
leave() {
|
|
381
|
+
e.isEnded || (a = !0, e.stop());
|
|
382
|
+
}
|
|
383
|
+
}, i(c);
|
|
384
|
+
},
|
|
385
|
+
supervision: n.mode === "all" ? "isolate" : "escalate",
|
|
386
|
+
ended: (e) => _(t, a ? {
|
|
387
|
+
...e,
|
|
388
|
+
reason: "left"
|
|
389
|
+
} : e)
|
|
390
|
+
}), !(!c || c.scope.isEnded) && (o.set(t, c), r.changed());
|
|
391
|
+
}, _ = (i, s) => {
|
|
392
|
+
n.mode === "all" && s.reason === "failed" ? o.set(i, "failed") : o.delete(i), n.mode === "all" && s.reason === "stopped" && l.add(i), s.cleanupErrors.length && r.lock(i), r.ended(i, s), r.changed(), n.mode === "first" && s.reason === "left" && !s.cleanupErrors.length && !e.isEnded && (n.reinject ? h() : e.fail(a.createRecorded("MAKOO_TARGET_DETACHED", { details: {
|
|
393
|
+
name: r.name,
|
|
394
|
+
selector: t
|
|
395
|
+
} })));
|
|
396
|
+
}, v = () => {
|
|
397
|
+
if (n.mode !== "first") return;
|
|
398
|
+
if (f() || e.isEnded) {
|
|
399
|
+
clearTimeout(d), d = void 0;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (d !== void 0) return;
|
|
403
|
+
let i = n.timeout ?? 15e3;
|
|
404
|
+
d = setTimeout(() => {
|
|
405
|
+
d = void 0, r.operation(() => {
|
|
406
|
+
e.isEnded || f() || e.fail(a.createRecorded("MAKOO_TARGET_WAIT_TIMEOUT", { details: {
|
|
407
|
+
name: r.name,
|
|
408
|
+
selector: t,
|
|
409
|
+
timeout: i,
|
|
410
|
+
...c ? { lockedSkipped: c } : {}
|
|
411
|
+
} }));
|
|
412
|
+
});
|
|
413
|
+
}, i);
|
|
414
|
+
};
|
|
415
|
+
return e.onCleanup(() => {
|
|
416
|
+
u.abort(), clearTimeout(d);
|
|
417
|
+
}), r.observer.subscribe(h, u.signal), h(), { appearances() {
|
|
418
|
+
let e = [];
|
|
419
|
+
for (let [t, n] of o) m(n) && e.push(t);
|
|
420
|
+
return e.sort((e, t) => e.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
421
|
+
} };
|
|
372
422
|
}
|
|
373
423
|
//#endregion
|
|
374
|
-
//#region packages/core/src/
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return e.kind === "component";
|
|
378
|
-
}
|
|
379
|
-
function T(e) {
|
|
380
|
-
return w(e) ? e.injectAt : e.listenAt;
|
|
381
|
-
}
|
|
382
|
-
function E(e) {
|
|
383
|
-
if (!e.withEvent) return;
|
|
384
|
-
let t = w(e) ? e.listener : e;
|
|
385
|
-
if (!(!t?.listenAt || !t.event || !t.callback)) return t;
|
|
424
|
+
//#region packages/core/src/runtime/scope.ts
|
|
425
|
+
function _(e) {
|
|
426
|
+
return x(void 0, e);
|
|
386
427
|
}
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (i) {
|
|
393
|
-
let n = `${t.artifactName}#${i}@${t.injectAt}`, r = e.taskContext.get(n);
|
|
394
|
-
if (r && w(r) && r.artifact === t.artifact) return n;
|
|
395
|
-
}
|
|
396
|
-
if (!r) return n;
|
|
397
|
-
let a = O(t.artifact), o = `${t.artifactName}#${a}@${t.injectAt}`, s = 2;
|
|
398
|
-
for (;;) {
|
|
399
|
-
let n = e.taskContext.get(o);
|
|
400
|
-
if (!n || w(n) && n.artifact === t.artifact) return o;
|
|
401
|
-
o = `${t.artifactName}#${a}-${s}@${t.injectAt}`, s++;
|
|
428
|
+
function v(e, t) {
|
|
429
|
+
try {
|
|
430
|
+
t();
|
|
431
|
+
} catch (t) {
|
|
432
|
+
e.addCleanupErrors([t]);
|
|
402
433
|
}
|
|
403
434
|
}
|
|
404
|
-
function
|
|
405
|
-
if (
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
let
|
|
418
|
-
|
|
435
|
+
function y(e, t, n) {
|
|
436
|
+
if (e.phase.kind !== "sealed") {
|
|
437
|
+
if (e.phase.kind === "ending") {
|
|
438
|
+
n !== void 0 && e.phase.error === void 0 && (e.phase.reason = "failed", e.phase.error = n);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
e.phase = {
|
|
442
|
+
kind: "ending",
|
|
443
|
+
reason: t,
|
|
444
|
+
error: n,
|
|
445
|
+
cleanupErrors: e.phase.cleanupErrors
|
|
446
|
+
}, e.isTearingDown = !0, e.tree.depth++;
|
|
447
|
+
for (let t of [...e.childScopes]) y(t, "stopped", void 0);
|
|
448
|
+
for (let t of e.cleanups.reverse()) v(e, t);
|
|
449
|
+
e.isTearingDown = !1, b(e), e.tree.depth--;
|
|
419
450
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
451
|
+
}
|
|
452
|
+
function b(e) {
|
|
453
|
+
if (e.phase.kind !== "ending" || e.isSettingUp || e.isTearingDown || e.childScopes.size > 0) return;
|
|
454
|
+
let t = {
|
|
455
|
+
reason: e.phase.reason,
|
|
456
|
+
error: e.phase.error,
|
|
457
|
+
cleanupErrors: [...e.phase.cleanupErrors]
|
|
458
|
+
};
|
|
459
|
+
e.phase = {
|
|
460
|
+
kind: "sealed",
|
|
461
|
+
outcome: t
|
|
462
|
+
}, e.ended?.(t);
|
|
463
|
+
let n = e.parent;
|
|
464
|
+
if (!n) return;
|
|
465
|
+
n.childScopes.delete(e);
|
|
466
|
+
let r = e.supervision === "escalate" && (t.error !== void 0 || t.cleanupErrors.length > 0);
|
|
467
|
+
(n.phase.kind === "ending" || n.phase.kind === "live" && r) && n.addCleanupErrors(t.cleanupErrors), r && (n.phase.kind === "live" || n.phase.kind === "ending" && t.error !== void 0 && n.phase.error === void 0) && y(n, "failed", t.error !== void 0 && e.errorHandles.escalateAs ? e.errorHandles.escalateAs(t.error) : t.error), b(n);
|
|
468
|
+
}
|
|
469
|
+
function x(e, t) {
|
|
470
|
+
let n = e?.tree ?? { depth: 0 }, r = {
|
|
471
|
+
fail: (e) => y(r, "failed", e),
|
|
472
|
+
stop: () => y(r, "stopped", void 0),
|
|
473
|
+
addCleanupErrors(e) {
|
|
474
|
+
r.phase.kind !== "sealed" && r.phase.cleanupErrors.push(...e);
|
|
425
475
|
},
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
return o.has(e);
|
|
476
|
+
onCleanup(e) {
|
|
477
|
+
r.phase.kind === "live" ? r.cleanups.push(e) : r.phase.kind === "ending" ? v(r, e) : e();
|
|
429
478
|
},
|
|
430
|
-
|
|
431
|
-
|
|
479
|
+
spawn: (e) => x(r, e),
|
|
480
|
+
get isEnded() {
|
|
481
|
+
return r.phase.kind !== "live";
|
|
432
482
|
},
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return t ? t.taskStatus : void 0;
|
|
483
|
+
get isTransitioning() {
|
|
484
|
+
return n.depth > 0;
|
|
436
485
|
},
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (!r) {
|
|
440
|
-
a.warn(`Task "${e}" not found, may already be destroyed`);
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
if (r.taskStatus === n) return;
|
|
444
|
-
let i = r.taskStatus;
|
|
445
|
-
r.taskStatus = n;
|
|
446
|
-
let s = T(r);
|
|
447
|
-
t("task:statusChange", y("task:statusChange", {
|
|
448
|
-
taskId: e,
|
|
449
|
-
kind: r.kind,
|
|
450
|
-
injectAt: s,
|
|
451
|
-
status: n,
|
|
452
|
-
preStatus: i
|
|
453
|
-
}));
|
|
486
|
+
get outcome() {
|
|
487
|
+
return r.phase.kind === "sealed" ? r.phase.outcome : void 0;
|
|
454
488
|
},
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
a.warn(`Task "${e}" not found, may already be destroyed`);
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
d.setTaskStatus(e, "idle"), d.taskRecords = d.taskRecords.filter((t) => t.taskId !== e), d.taskErrorMessages = d.taskErrorMessages.filter((t) => t.taskId !== e), d.releaseWatcher(e), d.releaseListener(e), w(t) && (d.releaseComponentInstance(e), d.releaseDomElement(e)), o.delete(e);
|
|
462
|
-
},
|
|
463
|
-
destroyAll() {
|
|
464
|
-
let e = Array.from(o.keys());
|
|
465
|
-
for (let t of e) d.releaseWatcher(t);
|
|
466
|
-
for (let t of e) {
|
|
467
|
-
d.releaseListener(t);
|
|
468
|
-
let e = o.get(t);
|
|
469
|
-
e && w(e) && (d.releaseComponentInstance(t), d.releaseDomElement(t));
|
|
470
|
-
}
|
|
471
|
-
o.clear(), d.taskRecords = [], d.taskErrorMessages = [], a.info("All tasks destroyed");
|
|
472
|
-
},
|
|
473
|
-
releaseComponentInstance(r) {
|
|
474
|
-
let i = o.get(r);
|
|
475
|
-
if (i && w(i) && i.mountHandle && i.appRoot) try {
|
|
476
|
-
i.adapter.unmount({
|
|
477
|
-
host: i.hostElement,
|
|
478
|
-
mountPoint: i.appRoot,
|
|
479
|
-
handle: i.mountHandle,
|
|
480
|
-
taskId: r,
|
|
481
|
-
injectAt: i.injectAt,
|
|
482
|
-
reason: "destroy"
|
|
483
|
-
}), i.mountHandle = void 0, i.instance = void 0, t("artifact:unmounted", v("artifact:unmounted", {
|
|
484
|
-
taskId: r,
|
|
485
|
-
kind: "component",
|
|
486
|
-
injectAt: i.injectAt,
|
|
487
|
-
status: i.taskStatus,
|
|
488
|
-
artifactName: i.artifactName
|
|
489
|
-
}));
|
|
490
|
-
} catch (t) {
|
|
491
|
-
let o = t instanceof n ? t : new n("Failed to unmount component", void 0, e.ADAPTER_UNMOUNT_FAIL, t instanceof Error ? t : Error(String(t)));
|
|
492
|
-
o.withContext({
|
|
493
|
-
taskId: r,
|
|
494
|
-
artifact: i.artifactName,
|
|
495
|
-
injectAt: i.injectAt,
|
|
496
|
-
adapter: i.adapter.name,
|
|
497
|
-
reason: "destroy"
|
|
498
|
-
}), a.error(s(o));
|
|
499
|
-
}
|
|
500
|
-
else a.warn(`Component for task "${r}" already unmounted`);
|
|
489
|
+
phase: {
|
|
490
|
+
kind: "live",
|
|
491
|
+
cleanupErrors: []
|
|
501
492
|
},
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
493
|
+
isSettingUp: !0,
|
|
494
|
+
isTearingDown: !1,
|
|
495
|
+
childScopes: /* @__PURE__ */ new Set(),
|
|
496
|
+
parent: e,
|
|
497
|
+
tree: n,
|
|
498
|
+
cleanups: [],
|
|
499
|
+
ended: t.ended,
|
|
500
|
+
errorHandles: t.errorHandles ?? {},
|
|
501
|
+
supervision: t.supervision ?? "escalate"
|
|
502
|
+
};
|
|
503
|
+
if (e) {
|
|
504
|
+
if (e.phase.kind !== "live") return r.phase = {
|
|
505
|
+
kind: "sealed",
|
|
506
|
+
outcome: {
|
|
507
|
+
reason: "stopped",
|
|
508
|
+
cleanupErrors: []
|
|
507
509
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
510
|
+
}, r;
|
|
511
|
+
e.childScopes.add(r);
|
|
512
|
+
}
|
|
513
|
+
n.depth++;
|
|
514
|
+
let i, a = !1;
|
|
515
|
+
try {
|
|
516
|
+
t.setup(r);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
i = e, a = !0;
|
|
519
|
+
}
|
|
520
|
+
return r.isSettingUp = !1, a && y(r, "failed", i), b(r), n.depth--, r;
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region packages/core/src/runtime/stateNode.ts
|
|
524
|
+
function S(e) {
|
|
525
|
+
let t, { active: n, changed: r, host: i, name: o } = e, s = [], c = (e) => i.diagnostic(e, o), l = (() => {
|
|
526
|
+
let e, i = [], a, s = () => w(a, () => E(i), n, n === "collecting" ? n : "waiting"), l = C(`"${o}"`, () => ({
|
|
527
|
+
status: s(),
|
|
528
|
+
lastError: e
|
|
529
|
+
}));
|
|
530
|
+
return {
|
|
531
|
+
deliver: () => l.deliver(c),
|
|
532
|
+
node: {
|
|
533
|
+
get hasErrors() {
|
|
534
|
+
return D(a?.outcome);
|
|
535
|
+
},
|
|
536
|
+
get isRunning() {
|
|
537
|
+
return a !== void 0 && !a.isEnded;
|
|
538
|
+
},
|
|
539
|
+
get isTransitioning() {
|
|
540
|
+
return a?.isTransitioning ?? !1;
|
|
541
|
+
},
|
|
542
|
+
get scope() {
|
|
543
|
+
return a;
|
|
544
|
+
},
|
|
545
|
+
consume() {
|
|
546
|
+
a = void 0;
|
|
547
|
+
},
|
|
548
|
+
flatten: (...t) => T(t, s, () => e, l),
|
|
549
|
+
run(n, s) {
|
|
550
|
+
e = void 0, i = [];
|
|
551
|
+
let c = {
|
|
552
|
+
lockKey: [o],
|
|
553
|
+
name: o,
|
|
554
|
+
addHandle: (e) => i.push(e)
|
|
555
|
+
};
|
|
556
|
+
_({
|
|
557
|
+
setup: (e) => {
|
|
558
|
+
a = e;
|
|
559
|
+
let r = t;
|
|
560
|
+
t = {
|
|
561
|
+
injection: s,
|
|
562
|
+
round: c,
|
|
563
|
+
scope: e
|
|
564
|
+
};
|
|
565
|
+
try {
|
|
566
|
+
n(u(c));
|
|
567
|
+
} finally {
|
|
568
|
+
t = r;
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
ended: (t) => {
|
|
572
|
+
D(t) && (e = O(t, o), console.error(e)), r();
|
|
573
|
+
}
|
|
574
|
+
}), r();
|
|
575
|
+
}
|
|
511
576
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
577
|
+
};
|
|
578
|
+
})();
|
|
579
|
+
function u(e) {
|
|
580
|
+
let n = i.getLocks(e.lockKey);
|
|
581
|
+
return {
|
|
582
|
+
diagnostic: c,
|
|
583
|
+
match(o, s, ...c) {
|
|
584
|
+
let l = t;
|
|
585
|
+
if (l?.round !== e) throw a.createThrowable("MAKOO_CALL_OUTSIDE_SETUP", { details: { call: "match" } });
|
|
586
|
+
let [u, d] = o === "first" ? c : [{}, c[0]], f = /* @__PURE__ */ new Map(), p = g(l.scope, s, o === "first" ? {
|
|
587
|
+
mode: o,
|
|
588
|
+
reinject: u.reinject,
|
|
589
|
+
timeout: u.timeout
|
|
590
|
+
} : { mode: o }, {
|
|
591
|
+
changed: r,
|
|
592
|
+
ended(e, t) {
|
|
593
|
+
let n = f.get(e);
|
|
594
|
+
n && (f.delete(e), n.settle(t, o === "all" && !l.scope.isEnded));
|
|
595
|
+
},
|
|
596
|
+
isLocked: n.isLocked,
|
|
597
|
+
lock: n.lock,
|
|
598
|
+
name: e.name,
|
|
599
|
+
observer: i.observer,
|
|
600
|
+
operation: i.operation
|
|
601
|
+
}, (n) => {
|
|
602
|
+
let r = t;
|
|
603
|
+
t = {
|
|
604
|
+
bound: (e) => f.set(n.element, e),
|
|
605
|
+
injection: l.injection,
|
|
606
|
+
round: e,
|
|
607
|
+
scope: n.scope,
|
|
608
|
+
appearance: n
|
|
609
|
+
};
|
|
610
|
+
try {
|
|
611
|
+
d(n.element);
|
|
612
|
+
} finally {
|
|
613
|
+
t = r;
|
|
614
|
+
}
|
|
615
|
+
f.get(n.element)?.markReady();
|
|
520
616
|
});
|
|
521
|
-
|
|
617
|
+
e.addHandle(p);
|
|
618
|
+
},
|
|
619
|
+
mount(n) {
|
|
620
|
+
let r = t;
|
|
621
|
+
if (r?.round !== e) throw a.createThrowable("MAKOO_CALL_OUTSIDE_SETUP", { details: { call: "mount" } });
|
|
622
|
+
if (!r.appearance) throw a.createThrowable("MAKOO_CALL_OUTSIDE_MATCH", { details: { call: "mount" } });
|
|
623
|
+
i.mount({
|
|
624
|
+
appearance: r.appearance,
|
|
625
|
+
injection: r.injection,
|
|
626
|
+
name: e.name
|
|
627
|
+
}, n);
|
|
628
|
+
},
|
|
629
|
+
onCleanup(n) {
|
|
630
|
+
if (t?.round !== e) throw a.createThrowable("MAKOO_CALL_OUTSIDE_SETUP", { details: { call: "onCleanup" } });
|
|
631
|
+
t.scope.onCleanup(n);
|
|
522
632
|
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
let
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
function d(e) {
|
|
636
|
+
let n = e.name, l = e.waiting ?? "waiting", d, f, p = () => {
|
|
637
|
+
let t = f;
|
|
638
|
+
return t?.kind === "bound" ? w(t.appearance.scope, () => t.isReady, e.active, l) : w(t?.scope, () => E(t?.handles ?? []), e.active, l);
|
|
639
|
+
}, m = C(`"${n}" in "${o}"`, () => ({
|
|
640
|
+
status: p(),
|
|
641
|
+
lastError: d
|
|
642
|
+
})), h = {
|
|
643
|
+
name: n,
|
|
644
|
+
get isRetired() {
|
|
645
|
+
return f?.kind === "bound" && f.appearance.scope.isEnded;
|
|
646
|
+
},
|
|
647
|
+
deliver: () => m.deliver(c),
|
|
648
|
+
markReady() {
|
|
649
|
+
f?.kind === "bound" && (f.isReady = !0);
|
|
650
|
+
},
|
|
651
|
+
settle(e, t) {
|
|
652
|
+
D(e) && (d = O(e, n), t && (console.error(d), i.diagnostic(d, o, n)));
|
|
537
653
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
654
|
+
};
|
|
655
|
+
return s.push(h), {
|
|
656
|
+
name: n,
|
|
657
|
+
view: T([], p, () => d, m),
|
|
658
|
+
bind(e) {
|
|
659
|
+
let r = t;
|
|
660
|
+
if (!r) throw a.createThrowable("MAKOO_CALL_OUTSIDE_SETUP", { details: { call: "bind" } });
|
|
661
|
+
if (!r.appearance) throw a.createThrowable("MAKOO_CALL_OUTSIDE_MATCH", { details: { call: "bind" } });
|
|
662
|
+
if (f?.kind === "bound") throw a.createThrowable("MAKOO_STATE_NODE_ALREADY_BOUND", { details: { name: n } });
|
|
663
|
+
f = {
|
|
664
|
+
appearance: r.appearance,
|
|
665
|
+
isReady: !1,
|
|
666
|
+
kind: "bound"
|
|
667
|
+
}, r.injection = e, r.bound?.(h);
|
|
668
|
+
},
|
|
669
|
+
flatten: (e) => T([e], p, () => d, m),
|
|
670
|
+
launch(e, i) {
|
|
671
|
+
let o = t;
|
|
672
|
+
if (!o) throw a.createThrowable("MAKOO_CALL_OUTSIDE_SETUP", { details: { call: "launch" } });
|
|
673
|
+
if (o.scope.isEnded) return;
|
|
674
|
+
d = void 0;
|
|
675
|
+
let s = [], c = {
|
|
676
|
+
lockKey: [...o.round.lockKey, n],
|
|
677
|
+
name: n,
|
|
678
|
+
addHandle: (e) => s.push(e)
|
|
679
|
+
};
|
|
680
|
+
o.scope.spawn({
|
|
681
|
+
setup: (n) => {
|
|
682
|
+
f = {
|
|
683
|
+
handles: s,
|
|
684
|
+
kind: "launched",
|
|
685
|
+
scope: n
|
|
686
|
+
};
|
|
687
|
+
let r = t;
|
|
688
|
+
t = {
|
|
689
|
+
injection: o.injection,
|
|
690
|
+
round: c,
|
|
691
|
+
scope: n
|
|
692
|
+
};
|
|
693
|
+
try {
|
|
694
|
+
e(u(c));
|
|
695
|
+
} finally {
|
|
696
|
+
t = r;
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
ended: (e) => {
|
|
700
|
+
D(e) && (d = O(e, n)), r();
|
|
701
|
+
},
|
|
702
|
+
errorHandles: { escalateAs: i }
|
|
703
|
+
}), r();
|
|
704
|
+
},
|
|
705
|
+
stop() {
|
|
706
|
+
i.operation(() => {
|
|
707
|
+
f && (f.kind === "bound" ? f.appearance.scope.stop() : f.scope.stop());
|
|
562
708
|
});
|
|
563
|
-
a.error(s(o));
|
|
564
709
|
}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
get root() {
|
|
714
|
+
return l.node;
|
|
565
715
|
},
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
let c = !1;
|
|
570
|
-
if (w(i) && i.mountHandle && i.appRoot) try {
|
|
571
|
-
i.adapter.unmount({
|
|
572
|
-
host: i.hostElement,
|
|
573
|
-
mountPoint: i.appRoot,
|
|
574
|
-
handle: i.mountHandle,
|
|
575
|
-
taskId: r,
|
|
576
|
-
injectAt: i.injectAt,
|
|
577
|
-
reason: "reset"
|
|
578
|
-
}), c = !0;
|
|
579
|
-
} catch (t) {
|
|
580
|
-
let o = t instanceof n ? t : new n("Failed to unmount component", void 0, e.ADAPTER_UNMOUNT_FAIL, t instanceof Error ? t : Error(String(t)));
|
|
581
|
-
o.withContext({
|
|
582
|
-
taskId: r,
|
|
583
|
-
artifact: i.artifactName,
|
|
584
|
-
injectAt: i.injectAt,
|
|
585
|
-
adapter: i.adapter.name,
|
|
586
|
-
reason: "reset"
|
|
587
|
-
}), a.warn(s(o));
|
|
588
|
-
}
|
|
589
|
-
d.setTaskStatus(r, "idle"), c && w(i) && t("artifact:unmounted", v("artifact:unmounted", {
|
|
590
|
-
taskId: r,
|
|
591
|
-
kind: "component",
|
|
592
|
-
injectAt: i.injectAt,
|
|
593
|
-
status: i.taskStatus,
|
|
594
|
-
artifactName: i.artifactName
|
|
595
|
-
})), w(i) && (i.mountHandle = void 0, i.instance = void 0, i.hostElement = void 0, i.appRoot?.remove(), i.appRoot = void 0, i.isObserver = !1), i.watcher && d.releaseWatcher(r);
|
|
596
|
-
let l = E(i), u = l?.event, f = l?.listenAt;
|
|
597
|
-
l?.controller && (l.controller.abort(), l.controller = void 0), l && t("resource:listenerReleased", v("resource:listenerReleased", {
|
|
598
|
-
taskId: r,
|
|
599
|
-
kind: i.kind,
|
|
600
|
-
injectAt: T(i),
|
|
601
|
-
status: i.taskStatus,
|
|
602
|
-
listenerEvent: u,
|
|
603
|
-
listenAt: f
|
|
604
|
-
}));
|
|
716
|
+
deliver() {
|
|
717
|
+
l.deliver();
|
|
718
|
+
for (let e of [...s]) e.deliver(), e.isRetired && s.splice(s.indexOf(e), 1);
|
|
605
719
|
},
|
|
606
|
-
|
|
607
|
-
for (let e of o.keys()) d.reset(e);
|
|
608
|
-
}
|
|
720
|
+
stateNode: d
|
|
609
721
|
};
|
|
610
|
-
return d;
|
|
611
|
-
}
|
|
612
|
-
//#endregion
|
|
613
|
-
//#region packages/core/src/payload/buildAliveObservePayload.ts
|
|
614
|
-
var oe = {
|
|
615
|
-
"alive:enabled": (e) => ({
|
|
616
|
-
taskId: e.taskId,
|
|
617
|
-
kind: e.kind,
|
|
618
|
-
injectAt: e.injectAt,
|
|
619
|
-
status: e.status,
|
|
620
|
-
meta: { scope: e.scope }
|
|
621
|
-
}),
|
|
622
|
-
"alive:disabled": (e) => ({
|
|
623
|
-
taskId: e.taskId,
|
|
624
|
-
kind: e.kind,
|
|
625
|
-
injectAt: e.injectAt,
|
|
626
|
-
status: e.status,
|
|
627
|
-
meta: { scope: e.scope }
|
|
628
|
-
}),
|
|
629
|
-
"alive:observerStarted": (e) => ({
|
|
630
|
-
taskId: e.taskId,
|
|
631
|
-
kind: e.kind,
|
|
632
|
-
injectAt: e.injectAt,
|
|
633
|
-
status: e.status,
|
|
634
|
-
meta: {
|
|
635
|
-
scope: e.scope,
|
|
636
|
-
observerMode: e.observerMode
|
|
637
|
-
}
|
|
638
|
-
}),
|
|
639
|
-
"alive:observerStopped": (e) => ({
|
|
640
|
-
taskId: e.taskId,
|
|
641
|
-
kind: e.kind,
|
|
642
|
-
injectAt: e.injectAt,
|
|
643
|
-
status: e.status,
|
|
644
|
-
meta: {
|
|
645
|
-
scope: e.scope,
|
|
646
|
-
observerMode: e.observerMode
|
|
647
|
-
}
|
|
648
|
-
})
|
|
649
|
-
};
|
|
650
|
-
function k(e, t) {
|
|
651
|
-
return g(e, t, oe);
|
|
652
722
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
injectAt: e.injectAt,
|
|
658
|
-
taskId: e.taskId,
|
|
659
|
-
kind: e.kind,
|
|
660
|
-
durationMs: e.durationMs,
|
|
661
|
-
meta: { root: e.root }
|
|
662
|
-
}),
|
|
663
|
-
"dom:targetTimeout": (e) => ({
|
|
664
|
-
injectAt: e.injectAt,
|
|
665
|
-
taskId: e.taskId,
|
|
666
|
-
kind: e.kind,
|
|
667
|
-
durationMs: e.durationMs,
|
|
668
|
-
meta: { root: e.root }
|
|
669
|
-
}),
|
|
670
|
-
"dom:targetRemoved": (e) => ({
|
|
671
|
-
injectAt: e.injectAt,
|
|
672
|
-
taskId: e.taskId,
|
|
673
|
-
kind: e.kind,
|
|
674
|
-
meta: { phase: "removed" }
|
|
675
|
-
}),
|
|
676
|
-
"dom:targetRestored": (e) => ({
|
|
677
|
-
injectAt: e.injectAt,
|
|
678
|
-
taskId: e.taskId,
|
|
679
|
-
kind: e.kind,
|
|
680
|
-
durationMs: e.durationMs
|
|
681
|
-
})
|
|
682
|
-
};
|
|
683
|
-
function A(e, t) {
|
|
684
|
-
return g(e, t, se);
|
|
685
|
-
}
|
|
686
|
-
//#endregion
|
|
687
|
-
//#region packages/core/src/payload/createDomObserveEmitFactory.ts
|
|
688
|
-
function j(e) {
|
|
689
|
-
let t = Date.now(), n, r = e.root instanceof Document ? "document" : "element";
|
|
690
|
-
return (i) => {
|
|
691
|
-
if (i === "dom:targetFound") {
|
|
692
|
-
e.emit("dom:targetFound", A("dom:targetFound", {
|
|
693
|
-
injectAt: e.injectAt,
|
|
694
|
-
taskId: e.taskId,
|
|
695
|
-
kind: e.kind,
|
|
696
|
-
durationMs: Date.now() - t,
|
|
697
|
-
root: r
|
|
698
|
-
}));
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
if (i === "dom:targetTimeout") {
|
|
702
|
-
e.emit("dom:targetTimeout", A("dom:targetTimeout", {
|
|
703
|
-
injectAt: e.injectAt,
|
|
704
|
-
taskId: e.taskId,
|
|
705
|
-
kind: e.kind,
|
|
706
|
-
durationMs: Date.now() - t,
|
|
707
|
-
root: r
|
|
708
|
-
}));
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
if (i === "dom:targetRemoved") {
|
|
712
|
-
n = Date.now(), e.emit("dom:targetRemoved", A("dom:targetRemoved", {
|
|
713
|
-
injectAt: e.injectAt,
|
|
714
|
-
taskId: e.taskId,
|
|
715
|
-
kind: e.kind
|
|
716
|
-
}));
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
e.emit("dom:targetRestored", A("dom:targetRestored", {
|
|
720
|
-
injectAt: e.injectAt,
|
|
721
|
-
taskId: e.taskId,
|
|
722
|
-
kind: e.kind,
|
|
723
|
-
durationMs: Date.now() - (n ?? t)
|
|
724
|
-
}));
|
|
723
|
+
function C(e, t) {
|
|
724
|
+
let n = /* @__PURE__ */ new Set(), r = {
|
|
725
|
+
status: "idle",
|
|
726
|
+
lastError: void 0
|
|
725
727
|
};
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
728
|
+
return {
|
|
729
|
+
subscribe(e) {
|
|
730
|
+
return n.add(e), () => n.delete(e);
|
|
731
|
+
},
|
|
732
|
+
deliver(i) {
|
|
733
|
+
let o = t();
|
|
734
|
+
if (r.status !== o.status || r.lastError !== o.lastError) {
|
|
735
|
+
r = o;
|
|
736
|
+
for (let t of [...n]) try {
|
|
737
|
+
t();
|
|
738
|
+
} catch (t) {
|
|
739
|
+
let n = a.create("MAKOO_STATE_SUBSCRIBER_FAILED", {
|
|
740
|
+
details: { owner: e },
|
|
741
|
+
cause: t
|
|
742
|
+
});
|
|
743
|
+
console.error(n), i(n);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
738
746
|
}
|
|
739
|
-
}, u = (n, a) => {
|
|
740
|
-
i.emit("dom:targetFound"), t(n, a), r?.once && (s(), i.logger.info(`Element "${e}" found, observer disconnected`));
|
|
741
|
-
};
|
|
742
|
-
return ((t) => {
|
|
743
|
-
o || (le(t, e, u), !o && ue(t, e, a, u));
|
|
744
|
-
})(n), r?.timeout && setTimeout(() => {
|
|
745
|
-
o || (s(), i.emit("dom:targetTimeout"), i.logger.warn(`Element "${e}" not found within ${r.timeout}ms, observer disconnected`));
|
|
746
|
-
}, r.timeout), s;
|
|
747
|
-
}
|
|
748
|
-
function ce(e, t, n, r, i = document, a, o = {
|
|
749
|
-
logger: new c(),
|
|
750
|
-
emit: l
|
|
751
|
-
}) {
|
|
752
|
-
let s = !0, u, d = de(e, () => {
|
|
753
|
-
o.emit("dom:targetRemoved"), n(), s && (u = M(t, (e) => {
|
|
754
|
-
s && (o.emit("dom:targetRestored"), r(e));
|
|
755
|
-
}, document, a, o));
|
|
756
|
-
}, i, o.logger);
|
|
757
|
-
return () => {
|
|
758
|
-
s && (s = !1, d?.disconnect(), u?.(), o.logger.info(`Alive observer for "${t}" stopped`));
|
|
759
747
|
};
|
|
760
748
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
subtree: !0
|
|
778
|
-
}), n.push(i));
|
|
779
|
-
}
|
|
780
|
-
function de(e, t, n, r) {
|
|
781
|
-
let i = P(n), a = i instanceof HTMLBodyElement;
|
|
782
|
-
if (i === null) return r.error("Failed to set up removal observer: no valid observation target found"), null;
|
|
783
|
-
if (!a && !i.isConnected) return r.error("Failed to set up removal observer: observation target is detached from DOM"), null;
|
|
784
|
-
let o = a ? i : i.parentElement || i;
|
|
785
|
-
if (!o) return t(), null;
|
|
786
|
-
let s = new MutationObserver((n, r) => {
|
|
787
|
-
for (let i of n) i.removedNodes.forEach((n) => {
|
|
788
|
-
n === e && (t(r), r.disconnect());
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
return s.observe(o, {
|
|
792
|
-
childList: !0,
|
|
793
|
-
subtree: !!a
|
|
794
|
-
}), r.info("Removal observer started", o), s;
|
|
795
|
-
}
|
|
796
|
-
function fe(e, t, n, r) {
|
|
797
|
-
let i = e.matches(t) ? e : e.querySelector(t);
|
|
798
|
-
i && r(i, n);
|
|
799
|
-
}
|
|
800
|
-
function P(e) {
|
|
801
|
-
return (e instanceof Document ? e.body : e) || document.body;
|
|
749
|
+
function w(e, t, n, r) {
|
|
750
|
+
return e && !e.isEnded ? t() ? n : r : D(e?.outcome) ? "failed" : "idle";
|
|
751
|
+
}
|
|
752
|
+
function T(e, t, n, r) {
|
|
753
|
+
let i = {};
|
|
754
|
+
for (let t of e) Object.assign(i, Object.getOwnPropertyDescriptors(t));
|
|
755
|
+
return i.status = {
|
|
756
|
+
enumerable: !0,
|
|
757
|
+
get: t
|
|
758
|
+
}, i.lastError = {
|
|
759
|
+
enumerable: !0,
|
|
760
|
+
get: n
|
|
761
|
+
}, i.subscribe = {
|
|
762
|
+
enumerable: !0,
|
|
763
|
+
value: r.subscribe
|
|
764
|
+
}, Object.freeze(Object.defineProperties({}, i));
|
|
802
765
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
var F = /* @__PURE__ */ function(e) {
|
|
806
|
-
return e.OPEN = "OPEN", e.CLOSE = "CLOSE", e;
|
|
807
|
-
}({}), I = {
|
|
808
|
-
"artifact:mountStart": (e) => ({
|
|
809
|
-
taskId: e.taskId,
|
|
810
|
-
kind: e.kind,
|
|
811
|
-
injectAt: e.injectAt,
|
|
812
|
-
status: e.status,
|
|
813
|
-
meta: {
|
|
814
|
-
artifactName: e.artifactName,
|
|
815
|
-
alive: e.alive,
|
|
816
|
-
scope: e.scope,
|
|
817
|
-
withEvent: e.withEvent
|
|
818
|
-
}
|
|
819
|
-
}),
|
|
820
|
-
"artifact:mountSuccess": (e) => ({
|
|
821
|
-
taskId: e.taskId,
|
|
822
|
-
kind: e.kind,
|
|
823
|
-
injectAt: e.injectAt,
|
|
824
|
-
status: e.status,
|
|
825
|
-
meta: {
|
|
826
|
-
artifactName: e.artifactName,
|
|
827
|
-
alive: e.alive,
|
|
828
|
-
scope: e.scope
|
|
829
|
-
}
|
|
830
|
-
}),
|
|
831
|
-
"artifact:mountFail": (e) => ({
|
|
832
|
-
taskId: e.taskId,
|
|
833
|
-
kind: e.kind,
|
|
834
|
-
injectAt: e.injectAt,
|
|
835
|
-
status: "idle",
|
|
836
|
-
error: e.error,
|
|
837
|
-
meta: { artifactName: e.artifactName }
|
|
838
|
-
})
|
|
839
|
-
};
|
|
840
|
-
function L(e, t) {
|
|
841
|
-
return g(e, t, I);
|
|
766
|
+
function E(e) {
|
|
767
|
+
return e.some((e) => e.appearances().length > 0);
|
|
842
768
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
var R = {
|
|
846
|
-
"listener:attached": (e) => ({
|
|
847
|
-
taskId: e.taskId,
|
|
848
|
-
kind: e.kind,
|
|
849
|
-
injectAt: e.injectAt,
|
|
850
|
-
status: e.status,
|
|
851
|
-
meta: {
|
|
852
|
-
listenerEvent: e.listenerEvent,
|
|
853
|
-
listenAt: e.listenAt
|
|
854
|
-
}
|
|
855
|
-
}),
|
|
856
|
-
"listener:detached": (e) => ({
|
|
857
|
-
taskId: e.taskId,
|
|
858
|
-
kind: e.kind,
|
|
859
|
-
injectAt: e.injectAt,
|
|
860
|
-
status: e.status,
|
|
861
|
-
meta: {
|
|
862
|
-
listenerEvent: e.listenerEvent,
|
|
863
|
-
listenAt: e.listenAt
|
|
864
|
-
}
|
|
865
|
-
}),
|
|
866
|
-
"listener:attachFail": (e) => ({
|
|
867
|
-
taskId: e.taskId,
|
|
868
|
-
kind: e.kind,
|
|
869
|
-
injectAt: e.injectAt,
|
|
870
|
-
status: e.status,
|
|
871
|
-
error: e.error,
|
|
872
|
-
meta: {
|
|
873
|
-
listenerEvent: e.listenerEvent,
|
|
874
|
-
listenAt: e.listenAt
|
|
875
|
-
}
|
|
876
|
-
})
|
|
877
|
-
};
|
|
878
|
-
function z(e, t) {
|
|
879
|
-
return g(e, t, R);
|
|
769
|
+
function D(e) {
|
|
770
|
+
return e !== void 0 && (e.error !== void 0 || e.cleanupErrors.length > 0);
|
|
880
771
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
idleTasks: e.idleTasks,
|
|
887
|
-
pendingTasks: e.pendingTasks,
|
|
888
|
-
activeTasks: e.activeTasks
|
|
889
|
-
} }),
|
|
890
|
-
"start:taskScheduled": (e) => ({
|
|
891
|
-
taskId: e.taskId,
|
|
892
|
-
kind: e.kind,
|
|
893
|
-
injectAt: e.injectAt,
|
|
894
|
-
status: e.status,
|
|
895
|
-
preStatus: e.preStatus,
|
|
896
|
-
meta: { timeout: e.timeout }
|
|
897
|
-
}),
|
|
898
|
-
"start:taskSkipped": (e) => ({
|
|
899
|
-
taskId: e.taskId,
|
|
900
|
-
kind: e.kind,
|
|
901
|
-
injectAt: e.injectAt,
|
|
902
|
-
status: e.status,
|
|
903
|
-
meta: { skipReason: e.skipReason }
|
|
904
|
-
}),
|
|
905
|
-
"task:targetReady": (e) => ({
|
|
906
|
-
taskId: e.taskId,
|
|
907
|
-
kind: e.kind,
|
|
908
|
-
injectAt: e.injectAt,
|
|
909
|
-
status: e.status
|
|
910
|
-
})
|
|
911
|
-
};
|
|
912
|
-
function V(e, t) {
|
|
913
|
-
return g(e, t, B);
|
|
772
|
+
function O(e, t) {
|
|
773
|
+
return e.cleanupErrors.length ? a.createRecorded("MAKOO_INJECTION_CLEANUP_FAILED", {
|
|
774
|
+
details: { name: t },
|
|
775
|
+
errors: [e.error, ...e.cleanupErrors].filter((e) => e !== void 0)
|
|
776
|
+
}) : e.error;
|
|
914
777
|
}
|
|
915
778
|
//#endregion
|
|
916
|
-
//#region packages/core/src/
|
|
917
|
-
function
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
pendingTasks: 0,
|
|
933
|
-
activeTasks: 0
|
|
934
|
-
});
|
|
935
|
-
if (t.emit("start:requested", V("start:requested", o)), a.length === 0) throw new i("No registered tasks found, call start() with tasks before starting", [], e.TASK_NO_REGISTERED);
|
|
936
|
-
a.forEach(({ taskId: e, injectAt: n }) => {
|
|
937
|
-
let r = t.taskContext.getTaskStatus(e), i = t.taskContext.get(e);
|
|
938
|
-
if (!(!i || !r)) {
|
|
939
|
-
if (r === "active" || r === "pending") {
|
|
940
|
-
t.emit("start:taskSkipped", V("start:taskSkipped", {
|
|
941
|
-
taskId: e,
|
|
942
|
-
kind: i.kind,
|
|
943
|
-
injectAt: n,
|
|
944
|
-
status: r,
|
|
945
|
-
skipReason: r === "active" ? "already-active" : "already-pending"
|
|
946
|
-
}));
|
|
779
|
+
//#region packages/core/src/runtime/injection.ts
|
|
780
|
+
function k(e, t, n, r) {
|
|
781
|
+
let i = !1, o = !1, s = S({
|
|
782
|
+
active: t.active,
|
|
783
|
+
changed: () => r.dirty(p),
|
|
784
|
+
host: r,
|
|
785
|
+
name: n
|
|
786
|
+
}), c = s.root, l = t.create(e, { stateNode: s.stateNode }), u = () => c.run(l.setup, p), d = () => {
|
|
787
|
+
i && (i = !1, !(o || c.isRunning || c.hasErrors) && (r.assertOpen(), u()));
|
|
788
|
+
}, f = {
|
|
789
|
+
kind: t.kind,
|
|
790
|
+
name: n,
|
|
791
|
+
start() {
|
|
792
|
+
if (r.assertOpen(), o) throw a.createThrowable("MAKOO_INJECTION_REMOVED", { details: { name: n } });
|
|
793
|
+
if (c.isTransitioning) {
|
|
794
|
+
i || (i = !0, r.defer(d));
|
|
947
795
|
return;
|
|
948
796
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
timeout: i.timeout
|
|
968
|
-
})));
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
function W(t, n, r) {
|
|
973
|
-
let a = t.taskContext.get(r);
|
|
974
|
-
if (!a) {
|
|
975
|
-
let n = new i("Task not found, unable to proceed with injection", void 0, e.TASK_NOT_FOUND).withContext({ taskId: r });
|
|
976
|
-
t.logger.error(s(n));
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
if (t.emit("task:targetReady", V("task:targetReady", {
|
|
980
|
-
taskId: r,
|
|
981
|
-
kind: a.kind,
|
|
982
|
-
injectAt: T(a),
|
|
983
|
-
status: a.taskStatus
|
|
984
|
-
})), a.taskStatus === "active") return;
|
|
985
|
-
let o = T(a);
|
|
986
|
-
if (w(a)) {
|
|
987
|
-
t.emit("artifact:mountStart", L("artifact:mountStart", {
|
|
988
|
-
taskId: r,
|
|
989
|
-
kind: "component",
|
|
990
|
-
injectAt: a.injectAt,
|
|
991
|
-
status: a.taskStatus,
|
|
992
|
-
artifactName: a.artifactName,
|
|
993
|
-
alive: a.alive,
|
|
994
|
-
scope: a.scope,
|
|
995
|
-
withEvent: a.withEvent
|
|
996
|
-
}));
|
|
997
|
-
let o = q(t, n, r);
|
|
998
|
-
if (!o.isSuccess) {
|
|
999
|
-
t.taskContext.setTaskStatus(r, "idle"), t.emit("artifact:mountFail", L("artifact:mountFail", {
|
|
1000
|
-
taskId: r,
|
|
1001
|
-
kind: "component",
|
|
1002
|
-
injectAt: a.injectAt,
|
|
1003
|
-
status: "idle",
|
|
1004
|
-
error: o.error ?? new i(`Component inject failed for task "${r}"`, [{
|
|
1005
|
-
path: "taskId",
|
|
1006
|
-
message: r
|
|
1007
|
-
}], e.TASK_INJECT_FAIL),
|
|
1008
|
-
artifactName: a.artifactName
|
|
1009
|
-
}));
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
t.emit("artifact:mountSuccess", L("artifact:mountSuccess", {
|
|
1013
|
-
taskId: r,
|
|
1014
|
-
kind: "component",
|
|
1015
|
-
injectAt: a.injectAt,
|
|
1016
|
-
status: a.taskStatus,
|
|
1017
|
-
artifactName: a.artifactName,
|
|
1018
|
-
alive: a.alive,
|
|
1019
|
-
scope: a.scope
|
|
1020
|
-
}));
|
|
1021
|
-
}
|
|
1022
|
-
if (a.withEvent) {
|
|
1023
|
-
let n = null, s = E(a);
|
|
1024
|
-
if (n = s?.activitySignal ? G(t, r, s.activitySignal()) : K(t, r, F.OPEN), n === !1) {
|
|
1025
|
-
t.taskContext.setTaskStatus(r, "idle");
|
|
1026
|
-
let n = E(a);
|
|
1027
|
-
t.emit("listener:attachFail", z("listener:attachFail", {
|
|
1028
|
-
taskId: r,
|
|
1029
|
-
kind: a.kind,
|
|
1030
|
-
injectAt: o,
|
|
1031
|
-
status: "idle",
|
|
1032
|
-
error: new i(`Listener attach failed for task "${r}"`, [{
|
|
1033
|
-
path: "taskId",
|
|
1034
|
-
message: r
|
|
1035
|
-
}], e.TASK_LISTENER_ATTACH_FAIL),
|
|
1036
|
-
listenerEvent: n?.event,
|
|
1037
|
-
listenAt: n?.listenAt
|
|
1038
|
-
}));
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
t.taskContext.setTaskStatus(r, "active");
|
|
1043
|
-
}
|
|
1044
|
-
function G(t, n, a) {
|
|
1045
|
-
let o = t.taskContext.get(n);
|
|
1046
|
-
if (!o) {
|
|
1047
|
-
let r = new i("Task not found, unable to bind activity signal", void 0, e.TASK_NOT_FOUND).withContext({
|
|
1048
|
-
taskId: n,
|
|
1049
|
-
signal: "activitySignal"
|
|
1050
|
-
});
|
|
1051
|
-
return t.logger.error(s(r)), !1;
|
|
1052
|
-
}
|
|
1053
|
-
o.watcher &&= (x(o.watcher.watcher), void 0);
|
|
1054
|
-
try {
|
|
1055
|
-
return o.watcher = {
|
|
1056
|
-
watcher: ie(a, (e) => {
|
|
1057
|
-
K(t, n, e ? F.OPEN : F.CLOSE);
|
|
1058
|
-
}),
|
|
1059
|
-
watchSource: a
|
|
1060
|
-
}, !0;
|
|
1061
|
-
} catch (i) {
|
|
1062
|
-
let a = i instanceof r ? i : new r("Failed to bind activity signal", void 0, e.TASK_SIGNAL_BIND_FAIL, i instanceof Error ? i : Error(String(i)));
|
|
1063
|
-
return a.withContext({
|
|
1064
|
-
taskId: n,
|
|
1065
|
-
signal: "activitySignal"
|
|
1066
|
-
}), t.logger.error(s(a)), !1;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
function K(t, n, r) {
|
|
1070
|
-
let a = t.taskContext.get(n);
|
|
1071
|
-
if (!a) {
|
|
1072
|
-
let r = new i("Task not found, unable to manage listener state", void 0, e.TASK_NOT_FOUND).withContext({ taskId: n });
|
|
1073
|
-
return t.logger.error(s(r)), !1;
|
|
1074
|
-
}
|
|
1075
|
-
let o = E(a);
|
|
1076
|
-
if (!o) return t.logger.warn(`Task "${n}" has no event binding configured`), !1;
|
|
1077
|
-
switch (r) {
|
|
1078
|
-
case F.OPEN: {
|
|
1079
|
-
if (o.controller) return !1;
|
|
1080
|
-
let r = pe(t, n, a.kind, o.listenAt, o.event, o.callback, o.capture);
|
|
1081
|
-
if (r) o.controller = r, t.emit("listener:attached", z("listener:attached", {
|
|
1082
|
-
taskId: n,
|
|
1083
|
-
kind: a.kind,
|
|
1084
|
-
injectAt: o.listenAt,
|
|
1085
|
-
status: a.taskStatus,
|
|
1086
|
-
listenerEvent: o.event,
|
|
1087
|
-
listenAt: o.listenAt
|
|
1088
|
-
}));
|
|
1089
|
-
else {
|
|
1090
|
-
let r = new i(`Failed to attach event "${o.event}" for task "${n}"`, void 0, e.TASK_LISTENER_ATTACH_FAIL).withContext({
|
|
1091
|
-
taskId: n,
|
|
1092
|
-
event: o.event,
|
|
1093
|
-
listenAt: o.listenAt
|
|
1094
|
-
});
|
|
1095
|
-
return t.logger.error(s(r)), t.emit("listener:attachFail", z("listener:attachFail", {
|
|
1096
|
-
taskId: n,
|
|
1097
|
-
kind: a.kind,
|
|
1098
|
-
injectAt: o.listenAt,
|
|
1099
|
-
status: a.taskStatus,
|
|
1100
|
-
error: r,
|
|
1101
|
-
listenerEvent: o.event,
|
|
1102
|
-
listenAt: o.listenAt
|
|
1103
|
-
})), !1;
|
|
1104
|
-
}
|
|
1105
|
-
break;
|
|
1106
|
-
}
|
|
1107
|
-
case F.CLOSE:
|
|
1108
|
-
if (!o.controller) return !1;
|
|
1109
|
-
o.controller.abort(), o.controller = void 0, t.logger.info(`Event "${o.event}" detached from task "${n}"`), t.emit("listener:detached", z("listener:detached", {
|
|
1110
|
-
taskId: n,
|
|
1111
|
-
kind: a.kind,
|
|
1112
|
-
injectAt: o.listenAt,
|
|
1113
|
-
status: a.taskStatus,
|
|
1114
|
-
listenerEvent: o.event,
|
|
1115
|
-
listenAt: o.listenAt
|
|
1116
|
-
}));
|
|
1117
|
-
break;
|
|
1118
|
-
default: return t.logger.warn(`Unknown action type "${r}" for task "${n}"`), !1;
|
|
1119
|
-
}
|
|
1120
|
-
return !0;
|
|
1121
|
-
}
|
|
1122
|
-
function pe(e, t, n, r, i, a, o = !1) {
|
|
1123
|
-
let s = document.querySelector(r);
|
|
1124
|
-
if (s) {
|
|
1125
|
-
let n = new AbortController();
|
|
1126
|
-
return s.addEventListener(i, a, {
|
|
1127
|
-
capture: o,
|
|
1128
|
-
signal: n.signal
|
|
1129
|
-
}), e.logger.info(`Event "${i}" attached at "${r}" (task: ${t})`), n;
|
|
1130
|
-
}
|
|
1131
|
-
let c = new AbortController();
|
|
1132
|
-
return N.onDomReady(r, (n) => {
|
|
1133
|
-
c.signal.aborted || (n.addEventListener(i, a, {
|
|
1134
|
-
capture: o,
|
|
1135
|
-
signal: c.signal
|
|
1136
|
-
}), e.logger.info(`Event "${i}" attached at "${r}" (task: ${t})`));
|
|
1137
|
-
}, document, {
|
|
1138
|
-
once: !0,
|
|
1139
|
-
timeout: e.config.timeout
|
|
1140
|
-
}, {
|
|
1141
|
-
logger: e.logger,
|
|
1142
|
-
emit: j({
|
|
1143
|
-
emit: e.emit,
|
|
1144
|
-
taskId: t,
|
|
1145
|
-
kind: n,
|
|
1146
|
-
injectAt: r,
|
|
1147
|
-
root: document
|
|
1148
|
-
})
|
|
1149
|
-
}), c;
|
|
1150
|
-
}
|
|
1151
|
-
function q(t, r, a) {
|
|
1152
|
-
let o = t.taskContext.get(a);
|
|
1153
|
-
if (!o || !w(o)) {
|
|
1154
|
-
let n = new i(`Task "${a}" context missing, injection aborted`, void 0, e.TASK_NOT_FOUND).withContext({ taskId: a });
|
|
1155
|
-
return t.logger.error(s(n)), {
|
|
1156
|
-
isSuccess: !1,
|
|
1157
|
-
error: n
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
if (!o.taskId) {
|
|
1161
|
-
let n = new i(`No artifact found for task "${a}", injection aborted`, void 0, e.TASK_INJECT_FAIL).withContext({
|
|
1162
|
-
taskId: a,
|
|
1163
|
-
artifact: o.artifactName,
|
|
1164
|
-
injectAt: o.injectAt,
|
|
1165
|
-
adapter: o.adapter.name
|
|
1166
|
-
});
|
|
1167
|
-
return t.logger.error(s(n)), {
|
|
1168
|
-
isSuccess: !1,
|
|
1169
|
-
error: n
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
if (o.mountHandle) {
|
|
1173
|
-
let n = new i(`Task "${a}" is already mounted, skipping`, void 0, e.TASK_ALREADY_MOUNTED).withContext({
|
|
1174
|
-
taskId: a,
|
|
1175
|
-
artifact: o.artifactName,
|
|
1176
|
-
injectAt: o.injectAt,
|
|
1177
|
-
adapter: o.adapter.name
|
|
1178
|
-
});
|
|
1179
|
-
return t.logger.warn(s(n)), {
|
|
1180
|
-
isSuccess: !1,
|
|
1181
|
-
error: n
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
let c = o.injectAt, l = r.ownerDocument || document, u = l.createElement("div");
|
|
1185
|
-
if (u.id = `implant-root-${H()}`, u.style.display = "contents", u.style.zIndex = "999999", r.isConnected) r.appendChild(u);
|
|
1186
|
-
else {
|
|
1187
|
-
let n = new i(`Target element for task "${a}" is detached from DOM, injection skipped`, void 0, e.TASK_TARGET_DETACHED).withContext({
|
|
1188
|
-
taskId: a,
|
|
1189
|
-
artifact: o.artifactName,
|
|
1190
|
-
injectAt: o.injectAt,
|
|
1191
|
-
adapter: o.adapter.name
|
|
1192
|
-
});
|
|
1193
|
-
return t.logger.warn(s(n)), {
|
|
1194
|
-
isSuccess: !1,
|
|
1195
|
-
error: n
|
|
1196
|
-
};
|
|
1197
|
-
}
|
|
1198
|
-
try {
|
|
1199
|
-
let e = o.adapter.mount({
|
|
1200
|
-
host: r,
|
|
1201
|
-
mountPoint: u,
|
|
1202
|
-
artifact: o.artifact,
|
|
1203
|
-
taskId: a,
|
|
1204
|
-
injectAt: c,
|
|
1205
|
-
makoo: t.makooContext(a, c)
|
|
1206
|
-
});
|
|
1207
|
-
if (o.mountHandle = e.handle, o.hostElement = r, o.instance = e.instance, o.appRoot = u, t.logger.info(`Artifact "${o.artifactName}" injected at "${c}"`), o.alive && !o.isObserver) {
|
|
1208
|
-
let n = N.onDomAlive(r, c, () => {
|
|
1209
|
-
t.taskContext.reset(a);
|
|
1210
|
-
}, (e) => W(t, e, a), o.scope === "global" ? l : r, {
|
|
1211
|
-
once: !0,
|
|
1212
|
-
timeout: t.config.timeout
|
|
1213
|
-
}, {
|
|
1214
|
-
logger: t.logger,
|
|
1215
|
-
emit: j({
|
|
1216
|
-
emit: t.emit,
|
|
1217
|
-
taskId: a,
|
|
1218
|
-
kind: o.kind,
|
|
1219
|
-
injectAt: c,
|
|
1220
|
-
root: o.scope === "global" ? l : r
|
|
1221
|
-
})
|
|
797
|
+
r.operation(() => {
|
|
798
|
+
r.assertOpen(), !c.isRunning && u();
|
|
799
|
+
});
|
|
800
|
+
},
|
|
801
|
+
stop() {
|
|
802
|
+
r.operation(() => {
|
|
803
|
+
if (!o) {
|
|
804
|
+
if (i = !1, c.scope?.outcome !== void 0) {
|
|
805
|
+
c.isTransitioning || (c.consume(), r.dirty(p));
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
c.scope?.stop();
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
},
|
|
812
|
+
remove() {
|
|
813
|
+
r.operation(() => {
|
|
814
|
+
o || (o = !0, i = !1, c.scope?.outcome === void 0 ? c.scope?.stop() : (c.consume(), r.dirty(p)), r.removed(p));
|
|
1222
815
|
});
|
|
1223
|
-
!o.alive || o.mountHandle !== e.handle ? n() : (o.disableAlive = n, o.isObserver = !0, t.emit("alive:observerStarted", k("alive:observerStarted", {
|
|
1224
|
-
taskId: a,
|
|
1225
|
-
kind: "component",
|
|
1226
|
-
injectAt: c,
|
|
1227
|
-
status: o.taskStatus,
|
|
1228
|
-
scope: o.scope,
|
|
1229
|
-
observerMode: "mounted"
|
|
1230
|
-
})), t.logger.info(`Task "${a}" alive observer activated`));
|
|
1231
816
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
let i = r instanceof n ? r : new n(`Failed to mount artifact at "${c}"`, void 0, e.ADAPTER_MOUNT_FAIL, r instanceof Error ? r : Error(String(r)));
|
|
1235
|
-
return i.withContext({
|
|
1236
|
-
taskId: a,
|
|
1237
|
-
artifact: o.artifactName,
|
|
1238
|
-
injectAt: c,
|
|
1239
|
-
adapter: o.adapter.name
|
|
1240
|
-
}), t.logger.error(s(i)), u.remove(), {
|
|
1241
|
-
isSuccess: !1,
|
|
1242
|
-
error: i
|
|
1243
|
-
};
|
|
1244
|
-
}
|
|
817
|
+
}, p = c.flatten(f, l.expose);
|
|
818
|
+
return r.track(p, s.deliver), p;
|
|
1245
819
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
t.logger.warn(`Task "${n}" already has an active alive observer`);
|
|
1261
|
-
return;
|
|
1262
|
-
}
|
|
1263
|
-
if (r.alive = !0, r.isObserver = !1, t.emit("alive:enabled", k("alive:enabled", {
|
|
1264
|
-
taskId: n,
|
|
1265
|
-
kind: "component",
|
|
1266
|
-
injectAt: r.injectAt,
|
|
1267
|
-
status: r.taskStatus,
|
|
1268
|
-
scope: r.scope
|
|
1269
|
-
})), r.disableAlive = () => {}, r.mountHandle && r.appRoot?.isConnected) {
|
|
1270
|
-
let e = r.hostElement ?? r.appRoot.parentElement;
|
|
1271
|
-
if (!e) {
|
|
1272
|
-
t.logger.warn(`Task "${n}": host element not found, unable to activate alive observer`);
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
let i = e.ownerDocument || document, a = r.injectAt, o = N.onDomAlive(e, a, () => {
|
|
1276
|
-
t.taskContext.reset(n);
|
|
1277
|
-
}, (e) => W(t, e, n), r.scope === "global" ? i : e, {
|
|
1278
|
-
once: !0,
|
|
1279
|
-
timeout: t.config.timeout
|
|
1280
|
-
}, {
|
|
1281
|
-
logger: t.logger,
|
|
1282
|
-
emit: j({
|
|
1283
|
-
emit: t.emit,
|
|
1284
|
-
taskId: n,
|
|
1285
|
-
kind: "component",
|
|
1286
|
-
injectAt: a,
|
|
1287
|
-
root: r.scope === "global" ? i : e
|
|
1288
|
-
})
|
|
1289
|
-
});
|
|
1290
|
-
if (!r.alive) {
|
|
1291
|
-
o();
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
r.disableAlive = o, r.isObserver = !0, t.emit("alive:observerStarted", k("alive:observerStarted", {
|
|
1295
|
-
taskId: n,
|
|
1296
|
-
kind: "component",
|
|
1297
|
-
injectAt: a,
|
|
1298
|
-
status: r.taskStatus,
|
|
1299
|
-
scope: r.scope,
|
|
1300
|
-
observerMode: "mounted"
|
|
1301
|
-
})), t.logger.info(`Task "${n}" alive observer activated`);
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
if (r.mountHandle && !r.appRoot?.isConnected && t.taskContext.reset(n), !r.mountHandle) {
|
|
1305
|
-
let e = !1, i = N.onDomReady(r.injectAt, (i) => {
|
|
1306
|
-
if (e || !r.alive) {
|
|
1307
|
-
t.logger.warn(`Task "${n}" alive state changed before element appears`);
|
|
1308
|
-
return;
|
|
820
|
+
function A(e, t) {
|
|
821
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = !1, a = 0, o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map(), c = {
|
|
822
|
+
defer(e) {
|
|
823
|
+
n.push(e);
|
|
824
|
+
},
|
|
825
|
+
dirty(e) {
|
|
826
|
+
r.add(e), l();
|
|
827
|
+
},
|
|
828
|
+
operation(e) {
|
|
829
|
+
a++;
|
|
830
|
+
try {
|
|
831
|
+
return e();
|
|
832
|
+
} finally {
|
|
833
|
+
a--, l();
|
|
1309
834
|
}
|
|
1310
|
-
W(t, i, n);
|
|
1311
|
-
}, document, {
|
|
1312
|
-
once: !0,
|
|
1313
|
-
timeout: t.config.timeout
|
|
1314
|
-
}, {
|
|
1315
|
-
logger: t.logger,
|
|
1316
|
-
emit: j({
|
|
1317
|
-
emit: t.emit,
|
|
1318
|
-
taskId: n,
|
|
1319
|
-
kind: "component",
|
|
1320
|
-
injectAt: r.injectAt,
|
|
1321
|
-
root: document
|
|
1322
|
-
})
|
|
1323
|
-
});
|
|
1324
|
-
r.disableAlive = () => {
|
|
1325
|
-
e || (e = !0, t.emit("alive:observerStopped", k("alive:observerStopped", {
|
|
1326
|
-
taskId: n,
|
|
1327
|
-
kind: "component",
|
|
1328
|
-
injectAt: r.injectAt,
|
|
1329
|
-
status: r.taskStatus,
|
|
1330
|
-
scope: r.scope,
|
|
1331
|
-
observerMode: "await-target"
|
|
1332
|
-
})), i());
|
|
1333
|
-
}, r.isObserver = !0, t.emit("alive:observerStarted", k("alive:observerStarted", {
|
|
1334
|
-
taskId: n,
|
|
1335
|
-
kind: "component",
|
|
1336
|
-
injectAt: r.injectAt,
|
|
1337
|
-
status: r.taskStatus,
|
|
1338
|
-
scope: r.scope,
|
|
1339
|
-
observerMode: "await-target"
|
|
1340
|
-
})), t.logger.info(`Task "${n}" awaiting target element for re-injection`);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
function Y(t, n) {
|
|
1344
|
-
let r = t.taskContext.get(n);
|
|
1345
|
-
if (!r) {
|
|
1346
|
-
let r = new i("Task not found", void 0, e.TASK_NOT_FOUND).withContext({ taskId: n });
|
|
1347
|
-
t.logger.error(s(r));
|
|
1348
|
-
return;
|
|
1349
|
-
}
|
|
1350
|
-
if (!w(r)) {
|
|
1351
|
-
t.logger.warn(`disableAlive is not applicable to non-component task "${n}"`);
|
|
1352
|
-
return;
|
|
1353
|
-
}
|
|
1354
|
-
if (!r.alive) {
|
|
1355
|
-
t.logger.warn(`Task "${n}" has no active alive observer to stop`);
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
let a = r.disableAlive;
|
|
1359
|
-
r.alive = !1, r.isObserver = !1, r.disableAlive = void 0, a?.(), t.emit("alive:disabled", k("alive:disabled", {
|
|
1360
|
-
taskId: n,
|
|
1361
|
-
kind: "component",
|
|
1362
|
-
injectAt: r.injectAt,
|
|
1363
|
-
status: r.taskStatus,
|
|
1364
|
-
scope: r.scope
|
|
1365
|
-
})), t.emit("alive:observerStopped", k("alive:observerStopped", {
|
|
1366
|
-
taskId: n,
|
|
1367
|
-
kind: "component",
|
|
1368
|
-
injectAt: r.injectAt,
|
|
1369
|
-
status: r.taskStatus,
|
|
1370
|
-
scope: r.scope,
|
|
1371
|
-
observerMode: r.mountHandle ? "mounted" : "await-target"
|
|
1372
|
-
}));
|
|
1373
|
-
}
|
|
1374
|
-
function X(t, n) {
|
|
1375
|
-
let r = t.taskContext.get(n);
|
|
1376
|
-
if (!r) {
|
|
1377
|
-
let r = new i("Task not found", void 0, e.TASK_NOT_FOUND).withContext({ taskId: n });
|
|
1378
|
-
t.logger.error(s(r));
|
|
1379
|
-
return;
|
|
1380
|
-
}
|
|
1381
|
-
let a = r.taskStatus, o = T(r);
|
|
1382
|
-
t.emit("task:beforeDestroy", y("task:beforeDestroy", {
|
|
1383
|
-
taskId: n,
|
|
1384
|
-
kind: r.kind,
|
|
1385
|
-
injectAt: o,
|
|
1386
|
-
status: a
|
|
1387
|
-
})), w(r) && r.alive && Y(t, n), t.taskContext.destroy(n), t.emit("task:afterDestroy", y("task:afterDestroy", {
|
|
1388
|
-
taskId: n,
|
|
1389
|
-
kind: r.kind,
|
|
1390
|
-
injectAt: o,
|
|
1391
|
-
preStatus: a
|
|
1392
|
-
}));
|
|
1393
|
-
}
|
|
1394
|
-
function me(e) {
|
|
1395
|
-
for (let t of [...e.taskContext.keys()]) X(e, t);
|
|
1396
|
-
}
|
|
1397
|
-
function Z(t, n) {
|
|
1398
|
-
let r = t.taskContext.get(n);
|
|
1399
|
-
if (!r) {
|
|
1400
|
-
let r = new i("Task not found", void 0, e.TASK_NOT_FOUND).withContext({ taskId: n });
|
|
1401
|
-
t.logger.error(s(r));
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1404
|
-
let a = r.taskStatus, o = T(r);
|
|
1405
|
-
t.emit("task:beforeReset", y("task:beforeReset", {
|
|
1406
|
-
taskId: n,
|
|
1407
|
-
kind: r.kind,
|
|
1408
|
-
injectAt: o,
|
|
1409
|
-
status: a
|
|
1410
|
-
})), w(r) && r.alive && Y(t, n), t.taskContext.reset(n), t.emit("task:afterReset", y("task:afterReset", {
|
|
1411
|
-
taskId: n,
|
|
1412
|
-
kind: r.kind,
|
|
1413
|
-
injectAt: o,
|
|
1414
|
-
status: r.taskStatus,
|
|
1415
|
-
preStatus: a
|
|
1416
|
-
}));
|
|
1417
|
-
}
|
|
1418
|
-
function he(e) {
|
|
1419
|
-
for (let t of e.taskContext.keys()) {
|
|
1420
|
-
let n = e.taskContext.get(t);
|
|
1421
|
-
n && w(n) && n.alive && Y(e, t);
|
|
1422
|
-
}
|
|
1423
|
-
e.taskContext.resetAll();
|
|
1424
|
-
}
|
|
1425
|
-
//#endregion
|
|
1426
|
-
//#region packages/core/src/runtime/createRuntime.ts
|
|
1427
|
-
var ge = {
|
|
1428
|
-
alive: !1,
|
|
1429
|
-
scope: "local",
|
|
1430
|
-
timeout: 5e3
|
|
1431
|
-
};
|
|
1432
|
-
function _e(e = {}) {
|
|
1433
|
-
let t = e.logger ?? new c(), n = e.observer ?? p(t), r = u(n), i = ae(r, t), a = h();
|
|
1434
|
-
for (let t of e.adapters ?? []) a.use(t);
|
|
1435
|
-
let o = {
|
|
1436
|
-
config: {
|
|
1437
|
-
...ge,
|
|
1438
|
-
...e.defaults,
|
|
1439
|
-
logger: t,
|
|
1440
|
-
observer: n,
|
|
1441
|
-
hooks: e.hooks
|
|
1442
835
|
},
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
836
|
+
removed(e) {
|
|
837
|
+
o.add(e);
|
|
838
|
+
},
|
|
839
|
+
track(e, t) {
|
|
840
|
+
s.set(e, t);
|
|
841
|
+
},
|
|
842
|
+
isRemoved(e) {
|
|
843
|
+
return o.has(e);
|
|
1449
844
|
}
|
|
1450
845
|
};
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
controlListener: (n) => K(e, t, n)
|
|
1468
|
-
};
|
|
1469
|
-
}
|
|
1470
|
-
//#endregion
|
|
1471
|
-
//#region packages/core/src/payload/buildRegisterObservePayload.ts
|
|
1472
|
-
var ye = {
|
|
1473
|
-
"register:start": (e) => ({
|
|
1474
|
-
taskId: e.taskId,
|
|
1475
|
-
kind: e.kind,
|
|
1476
|
-
injectAt: e.injectAt,
|
|
1477
|
-
status: e.status,
|
|
1478
|
-
meta: {
|
|
1479
|
-
artifactName: e.artifactName,
|
|
1480
|
-
listenerEvent: e.listenerEvent,
|
|
1481
|
-
listenAt: e.listenAt,
|
|
1482
|
-
alive: e.alive,
|
|
1483
|
-
scope: e.scope,
|
|
1484
|
-
timeout: e.timeout,
|
|
1485
|
-
withEvent: e.withEvent
|
|
1486
|
-
}
|
|
1487
|
-
}),
|
|
1488
|
-
"register:success": (e) => ({
|
|
1489
|
-
taskId: e.taskId,
|
|
1490
|
-
kind: e.kind,
|
|
1491
|
-
injectAt: e.injectAt,
|
|
1492
|
-
status: e.status,
|
|
1493
|
-
meta: {
|
|
1494
|
-
artifactName: e.artifactName,
|
|
1495
|
-
listenerEvent: e.listenerEvent,
|
|
1496
|
-
listenAt: e.listenAt,
|
|
1497
|
-
alive: e.alive,
|
|
1498
|
-
scope: e.scope,
|
|
1499
|
-
timeout: e.timeout,
|
|
1500
|
-
withEvent: e.withEvent
|
|
846
|
+
function l() {
|
|
847
|
+
if (!(a > 0 || i)) {
|
|
848
|
+
i = !0;
|
|
849
|
+
try {
|
|
850
|
+
for (; n.length || o.size || r.size;) {
|
|
851
|
+
for (; n.length;) c.operation(n.shift());
|
|
852
|
+
let t = [];
|
|
853
|
+
for (let n of o) o.delete(n), t.push(n), e(n);
|
|
854
|
+
for (let [e, t] of s) r.delete(e) && t();
|
|
855
|
+
for (let e of t) s.delete(e);
|
|
856
|
+
for (let e of r) s.has(e) || r.delete(e);
|
|
857
|
+
}
|
|
858
|
+
t();
|
|
859
|
+
} finally {
|
|
860
|
+
i = !1;
|
|
861
|
+
}
|
|
1501
862
|
}
|
|
1502
|
-
}),
|
|
1503
|
-
"register:duplicate": (e) => ({
|
|
1504
|
-
taskId: e.taskId,
|
|
1505
|
-
kind: e.kind,
|
|
1506
|
-
injectAt: e.injectAt,
|
|
1507
|
-
status: e.status,
|
|
1508
|
-
meta: Q(e)
|
|
1509
|
-
}),
|
|
1510
|
-
"register:error": (e) => ({
|
|
1511
|
-
taskId: e.taskId,
|
|
1512
|
-
kind: e.kind,
|
|
1513
|
-
injectAt: e.injectAt,
|
|
1514
|
-
status: e.status,
|
|
1515
|
-
error: e.error,
|
|
1516
|
-
meta: Q(e)
|
|
1517
|
-
})
|
|
1518
|
-
};
|
|
1519
|
-
function Q(e) {
|
|
1520
|
-
return e.artifactName === void 0 ? e.listenerEvent === void 0 ? {} : { listenerEvent: e.listenerEvent } : { artifactName: e.artifactName };
|
|
1521
|
-
}
|
|
1522
|
-
function $(e, t) {
|
|
1523
|
-
return g(e, t, ye);
|
|
1524
|
-
}
|
|
1525
|
-
//#endregion
|
|
1526
|
-
//#region packages/core/src/util/getArtifactName.ts
|
|
1527
|
-
var be = /* @__PURE__ */ new WeakMap();
|
|
1528
|
-
function xe(e, t, n, r) {
|
|
1529
|
-
let i = e?.name || e?.__name;
|
|
1530
|
-
if (i) return i;
|
|
1531
|
-
if (typeof e == "string") return e;
|
|
1532
|
-
if (typeof e == "object" || typeof e == "function") {
|
|
1533
|
-
let r = e, i = t.get(r);
|
|
1534
|
-
if (i) return i;
|
|
1535
|
-
let a = `${n}-${H()}`;
|
|
1536
|
-
return t.set(r, a), a;
|
|
1537
863
|
}
|
|
1538
|
-
return
|
|
1539
|
-
}
|
|
1540
|
-
function Se(e) {
|
|
1541
|
-
return xe(e, be, "artifact", "artifact-anonymous");
|
|
864
|
+
return c;
|
|
1542
865
|
}
|
|
1543
866
|
//#endregion
|
|
1544
|
-
//#region packages/core/src/
|
|
1545
|
-
function
|
|
1546
|
-
let
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
taskId: c,
|
|
1559
|
-
kind: "listener",
|
|
1560
|
-
injectAt: r,
|
|
1561
|
-
status: e.taskContext.getTaskStatus(c) ?? "idle",
|
|
1562
|
-
listenerEvent: i
|
|
1563
|
-
})), {
|
|
1564
|
-
taskId: c,
|
|
1565
|
-
isSuccess: !0,
|
|
1566
|
-
isDuplicate: !0
|
|
1567
|
-
};
|
|
1568
|
-
let t = {
|
|
1569
|
-
taskId: c,
|
|
1570
|
-
kind: "listener",
|
|
1571
|
-
taskStatus: "idle",
|
|
1572
|
-
timeout: e.config.timeout,
|
|
1573
|
-
withEvent: !0,
|
|
1574
|
-
listenAt: r,
|
|
1575
|
-
event: i,
|
|
1576
|
-
callback: a
|
|
1577
|
-
};
|
|
1578
|
-
return o !== void 0 && (t.capture = o), s && (t.activitySignal = s), e.taskContext.set(c, t), e.taskContext.taskRecords.push({
|
|
1579
|
-
taskId: c,
|
|
1580
|
-
injectAt: r
|
|
1581
|
-
}), e.logger.info(`Listener "${c}" registered`), e.emit("register:success", $("register:success", {
|
|
1582
|
-
taskId: c,
|
|
1583
|
-
kind: "listener",
|
|
1584
|
-
injectAt: r,
|
|
1585
|
-
status: "idle",
|
|
1586
|
-
listenerEvent: i,
|
|
1587
|
-
listenAt: r,
|
|
1588
|
-
withEvent: !0
|
|
1589
|
-
})), {
|
|
1590
|
-
taskId: c,
|
|
1591
|
-
isSuccess: !0
|
|
1592
|
-
};
|
|
1593
|
-
} catch (t) {
|
|
1594
|
-
return e.emit("register:error", $("register:error", {
|
|
1595
|
-
taskId: c,
|
|
1596
|
-
kind: "listener",
|
|
1597
|
-
injectAt: r,
|
|
1598
|
-
status: e.taskContext.getTaskStatus(c) ?? "idle",
|
|
1599
|
-
error: t,
|
|
1600
|
-
listenerEvent: i
|
|
1601
|
-
})), {
|
|
1602
|
-
taskId: c,
|
|
1603
|
-
isSuccess: !1
|
|
1604
|
-
};
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
function we(t, r) {
|
|
1608
|
-
let { id: i, injectAt: a, artifact: o, options: s } = r, c = Se(o), l = D(t, {
|
|
1609
|
-
id: i,
|
|
1610
|
-
artifactName: c,
|
|
1611
|
-
injectAt: a,
|
|
1612
|
-
artifact: o
|
|
1613
|
-
}), u = !!s?.on, f = s?.on?.type, p = s?.on?.listenAt, m = s?.alive ?? t.config.alive, h = s?.scope ?? t.config.scope, g = s?.timeout ?? t.config.timeout, _ = t.adapterRegistry.resolve(o);
|
|
1614
|
-
if (!_) throw new n(`No adapter found for artifact: ${c}`, [{
|
|
1615
|
-
path: "artifact",
|
|
1616
|
-
message: c
|
|
1617
|
-
}], e.ADAPTER_NOT_FOUND);
|
|
1618
|
-
t.emit("register:start", $("register:start", {
|
|
1619
|
-
taskId: l,
|
|
1620
|
-
kind: "component",
|
|
1621
|
-
injectAt: a,
|
|
1622
|
-
status: "idle",
|
|
1623
|
-
artifactName: c,
|
|
1624
|
-
listenerEvent: f,
|
|
1625
|
-
listenAt: p,
|
|
1626
|
-
alive: m,
|
|
1627
|
-
scope: h,
|
|
1628
|
-
timeout: g,
|
|
1629
|
-
withEvent: u
|
|
1630
|
-
}));
|
|
1631
|
-
try {
|
|
1632
|
-
if (t.taskContext.has(l)) return t.logger.warn(`Task "${l}" is already registered, skipping`), t.emit("register:duplicate", $("register:duplicate", {
|
|
1633
|
-
taskId: l,
|
|
1634
|
-
kind: "component",
|
|
1635
|
-
injectAt: a,
|
|
1636
|
-
status: t.taskContext.getTaskStatus(l) ?? "idle",
|
|
1637
|
-
artifactName: c
|
|
1638
|
-
})), {
|
|
1639
|
-
taskId: l,
|
|
1640
|
-
isSuccess: !0,
|
|
1641
|
-
isDuplicate: !0
|
|
1642
|
-
};
|
|
1643
|
-
let e = {
|
|
1644
|
-
taskId: l,
|
|
1645
|
-
taskStatus: "idle",
|
|
1646
|
-
kind: "component",
|
|
1647
|
-
artifactName: c,
|
|
1648
|
-
injectAt: a,
|
|
1649
|
-
artifact: o,
|
|
1650
|
-
adapter: _,
|
|
1651
|
-
withEvent: !1,
|
|
1652
|
-
alive: m,
|
|
1653
|
-
scope: h,
|
|
1654
|
-
timeout: g,
|
|
1655
|
-
isObserver: !1,
|
|
1656
|
-
hooks: s?.hooks
|
|
1657
|
-
};
|
|
1658
|
-
if (s?.on) {
|
|
1659
|
-
let t = {
|
|
1660
|
-
listenAt: s.on.listenAt,
|
|
1661
|
-
event: s.on.type,
|
|
1662
|
-
callback: s.on.callback
|
|
1663
|
-
};
|
|
1664
|
-
e.withEvent = !0, s.on.capture !== void 0 && (t.capture = s.on.capture), s.on.activitySignal && (t.activitySignal = s.on.activitySignal), e.listener = t;
|
|
1665
|
-
}
|
|
1666
|
-
return t.config.observer && s?.hooks && d(t.config.observer, s.hooks, l), t.taskContext.set(l, e), t.taskContext.taskRecords.push({
|
|
1667
|
-
taskId: l,
|
|
1668
|
-
injectAt: a
|
|
1669
|
-
}), t.logger.info(`Task "${l}" registered`), t.emit("register:success", $("register:success", {
|
|
1670
|
-
taskId: l,
|
|
1671
|
-
kind: "component",
|
|
1672
|
-
injectAt: a,
|
|
1673
|
-
status: "idle",
|
|
1674
|
-
artifactName: c,
|
|
1675
|
-
listenerEvent: f,
|
|
1676
|
-
listenAt: p,
|
|
1677
|
-
alive: m,
|
|
1678
|
-
scope: h,
|
|
1679
|
-
timeout: g,
|
|
1680
|
-
withEvent: u
|
|
1681
|
-
})), {
|
|
1682
|
-
taskId: l,
|
|
1683
|
-
isSuccess: !0
|
|
1684
|
-
};
|
|
1685
|
-
} catch (e) {
|
|
1686
|
-
return t.emit("register:error", $("register:error", {
|
|
1687
|
-
taskId: l,
|
|
1688
|
-
kind: "component",
|
|
1689
|
-
injectAt: a,
|
|
1690
|
-
status: t.taskContext.getTaskStatus(l) ?? "idle",
|
|
1691
|
-
error: e,
|
|
1692
|
-
artifactName: c
|
|
1693
|
-
})), {
|
|
1694
|
-
taskId: l,
|
|
1695
|
-
isSuccess: !1
|
|
867
|
+
//#region packages/core/src/runtime/observer.ts
|
|
868
|
+
function j(e) {
|
|
869
|
+
let t = /* @__PURE__ */ new Set(), n, r = () => e(() => {
|
|
870
|
+
for (let e of [...t]) t.has(e) && e();
|
|
871
|
+
});
|
|
872
|
+
return { subscribe(e, i) {
|
|
873
|
+
if (i.aborted) return () => {};
|
|
874
|
+
n ??= new MutationObserver(r), t.size || n.observe(document, {
|
|
875
|
+
subtree: !0,
|
|
876
|
+
childList: !0,
|
|
877
|
+
attributes: !0
|
|
878
|
+
}), t.add(e);
|
|
879
|
+
let a = () => {
|
|
880
|
+
t.delete(e) && (i.removeEventListener("abort", a), t.size || n?.disconnect());
|
|
1696
881
|
};
|
|
1697
|
-
|
|
882
|
+
return i.addEventListener("abort", a, { once: !0 }), a;
|
|
883
|
+
} };
|
|
1698
884
|
}
|
|
1699
885
|
//#endregion
|
|
1700
|
-
//#region packages/core/src/
|
|
1701
|
-
function
|
|
1702
|
-
let t =
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
reset: (e) => Z(t, e),
|
|
1710
|
-
destroy: (e) => X(t, e),
|
|
1711
|
-
resetAll: () => he(t),
|
|
1712
|
-
destroyAll: () => me(t),
|
|
1713
|
-
enableAlive: (e) => J(t, e),
|
|
1714
|
-
disableAlive: (e) => Y(t, e),
|
|
1715
|
-
on: (e, n) => t.config.observer?.on(e, n) ?? (() => {}),
|
|
1716
|
-
onTask: (e, n, r) => t.config.observer?.onTask(e, n, r) ?? (() => {}),
|
|
1717
|
-
onAny: (e) => t.config.observer?.onAny(e) ?? (() => {}),
|
|
1718
|
-
off: (e, n) => t.config.observer?.off(e, n),
|
|
1719
|
-
offTask: (e, n, r) => t.config.observer?.offTask(e, n, r),
|
|
1720
|
-
offAny: (e) => t.config.observer?.offAny(e),
|
|
1721
|
-
getLogger: () => t.logger
|
|
886
|
+
//#region packages/core/src/instance/residue.ts
|
|
887
|
+
function M() {
|
|
888
|
+
let e = { children: /* @__PURE__ */ new Map() }, t = (t) => {
|
|
889
|
+
let n = typeof t == "string" ? [t] : t, r = e;
|
|
890
|
+
for (let e of n) {
|
|
891
|
+
let t = r.children.get(e);
|
|
892
|
+
t || (t = { children: /* @__PURE__ */ new Map() }, r.children.set(e, t)), r = t;
|
|
893
|
+
}
|
|
894
|
+
return r.elements || (r.elements = /* @__PURE__ */ new WeakSet()), r.elements;
|
|
1722
895
|
};
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
artifact: e.artifact,
|
|
1730
|
-
...e.options ? { options: e.options } : {}
|
|
1731
|
-
};
|
|
1732
|
-
}
|
|
1733
|
-
function De(e) {
|
|
1734
|
-
return {
|
|
1735
|
-
kind: "listener",
|
|
1736
|
-
...e.id ? { id: e.id } : {},
|
|
1737
|
-
listenAt: e.listenAt,
|
|
1738
|
-
event: e.type,
|
|
1739
|
-
type: e.type,
|
|
1740
|
-
callback: e.callback,
|
|
1741
|
-
...e.capture === void 0 ? {} : { capture: e.capture },
|
|
1742
|
-
...e.activitySignal ? { activitySignal: e.activitySignal } : {}
|
|
896
|
+
return (e) => {
|
|
897
|
+
let n = t(e);
|
|
898
|
+
return {
|
|
899
|
+
isLocked: (e) => n.has(e),
|
|
900
|
+
lock: (e) => n.add(e)
|
|
901
|
+
};
|
|
1743
902
|
};
|
|
1744
903
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region packages/core/src/instance/createMakoo.ts
|
|
906
|
+
function N() {
|
|
907
|
+
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set(), n = !1, r, i = (e) => {
|
|
908
|
+
for (let n of [...t]) try {
|
|
909
|
+
n(e);
|
|
910
|
+
} catch (t) {
|
|
911
|
+
let n = a.create("MAKOO_INSTANCE_OBSERVER_FAILED", { cause: t });
|
|
912
|
+
console.error(n), e.type !== "diagnostic" && i({
|
|
913
|
+
type: "diagnostic",
|
|
914
|
+
error: n
|
|
1754
915
|
});
|
|
1755
|
-
t.isSuccess && !t.isDuplicate && n.push(Ae(e, t.taskId));
|
|
1756
|
-
continue;
|
|
1757
916
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
917
|
+
}, o = () => {
|
|
918
|
+
if (n) throw a.createThrowable("MAKOO_INSTANCE_DISPOSED");
|
|
919
|
+
}, s = A((t) => {
|
|
920
|
+
e.get(t.name) === t && e.delete(t.name), r && t.status === "failed" && r.push(t.lastError), i({
|
|
921
|
+
type: "injection-removed",
|
|
922
|
+
name: t.name,
|
|
923
|
+
injection: t
|
|
924
|
+
});
|
|
925
|
+
}, () => {
|
|
926
|
+
if (!r) return;
|
|
927
|
+
let e = r.length ? a.createRecorded("MAKOO_INSTANCE_CLEANUP_FAILED", { errors: r }) : void 0;
|
|
928
|
+
r = void 0, e && console.error(e), i({
|
|
929
|
+
type: "instance-disposed",
|
|
930
|
+
...e ? { error: e } : {}
|
|
931
|
+
}), t.clear();
|
|
932
|
+
}), c = j((e) => s.operation(e)), l = {
|
|
933
|
+
defer: s.defer,
|
|
934
|
+
dirty: s.dirty,
|
|
935
|
+
operation: s.operation,
|
|
936
|
+
removed: s.removed,
|
|
937
|
+
track: s.track,
|
|
938
|
+
assertOpen: o,
|
|
939
|
+
diagnostic: (e, t, n) => i({
|
|
940
|
+
type: "diagnostic",
|
|
941
|
+
...t === void 0 ? {} : { name: t },
|
|
942
|
+
...n === void 0 ? {} : { child: n },
|
|
943
|
+
error: e
|
|
944
|
+
}),
|
|
945
|
+
getLocks: M(),
|
|
946
|
+
mount: (e, t) => h(e, {
|
|
947
|
+
adapter: t.adapter,
|
|
948
|
+
component: t.component,
|
|
949
|
+
listener: (e) => g(e),
|
|
950
|
+
observer: c,
|
|
951
|
+
props: t.props
|
|
952
|
+
}),
|
|
953
|
+
observer: c
|
|
954
|
+
};
|
|
1765
955
|
return {
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
return e.taskContext.has(t) ? n.get(t) : void 0;
|
|
956
|
+
apply(e) {
|
|
957
|
+
o(), s.operation(() => u(e));
|
|
1769
958
|
},
|
|
1770
|
-
|
|
1771
|
-
|
|
959
|
+
injection(e) {
|
|
960
|
+
return o(), p(e);
|
|
1772
961
|
},
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
enableAlive: () => J(e, t),
|
|
1783
|
-
disableAlive: () => Y(e, t),
|
|
1784
|
-
reset: () => Z(e, t),
|
|
1785
|
-
destroy: () => X(e, t)
|
|
1786
|
-
};
|
|
1787
|
-
}
|
|
1788
|
-
function je(e, t) {
|
|
1789
|
-
return {
|
|
1790
|
-
kind: "listener",
|
|
1791
|
-
taskId: t,
|
|
1792
|
-
open: () => K(e, t, F.OPEN),
|
|
1793
|
-
close: () => K(e, t, F.CLOSE),
|
|
1794
|
-
destroy: () => X(e, t)
|
|
962
|
+
listener(e) {
|
|
963
|
+
return o(), g(e);
|
|
964
|
+
},
|
|
965
|
+
observe(e) {
|
|
966
|
+
return o(), t.add(e), () => {
|
|
967
|
+
t.delete(e);
|
|
968
|
+
};
|
|
969
|
+
},
|
|
970
|
+
dispose: () => _()
|
|
1795
971
|
};
|
|
972
|
+
function u(t) {
|
|
973
|
+
if (t.length === 0) throw a.createThrowable("MAKOO_DECLARATION_INVALID", { details: { reason: "Expected a non-empty array of declarations" } });
|
|
974
|
+
let n = t.map(d), r = /* @__PURE__ */ new Set();
|
|
975
|
+
for (let [t, n] of e) s.isRemoved(n) || r.add(t);
|
|
976
|
+
for (let e of n) {
|
|
977
|
+
if (r.has(e.name)) throw a.createThrowable("MAKOO_INJECTION_NAME_CONFLICT", { details: { name: e.name } });
|
|
978
|
+
r.add(e.name);
|
|
979
|
+
}
|
|
980
|
+
for (let e of n.map(f)) e.start();
|
|
981
|
+
}
|
|
982
|
+
function d(e) {
|
|
983
|
+
let t = m[e.kind];
|
|
984
|
+
if (!t) throw a.createThrowable("MAKOO_DECLARATION_INVALID", { details: { reason: "Invalid declaration\nkind: Expected listener, component, or component-each" } });
|
|
985
|
+
return {
|
|
986
|
+
kind: t,
|
|
987
|
+
resolved: t.resolve(e),
|
|
988
|
+
name: e.name
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
function f(t) {
|
|
992
|
+
let n = k(t.resolved, t.kind, t.name, l);
|
|
993
|
+
return e.set(t.name, n), { start() {
|
|
994
|
+
e.get(t.name) === n && !s.isRemoved(n) && n.start();
|
|
995
|
+
} };
|
|
996
|
+
}
|
|
997
|
+
function p(t) {
|
|
998
|
+
let n = e.get(t);
|
|
999
|
+
if (n?.kind === "component" || n?.kind === "component-each") return n;
|
|
1000
|
+
throw a.createThrowable("MAKOO_INJECTION_NOT_FOUND", { details: { name: t } });
|
|
1001
|
+
}
|
|
1002
|
+
function g(t) {
|
|
1003
|
+
let n = e.get(t);
|
|
1004
|
+
if (n?.kind !== "listener") throw a.createThrowable("MAKOO_INJECTION_NOT_FOUND", { details: { name: t } });
|
|
1005
|
+
return n;
|
|
1006
|
+
}
|
|
1007
|
+
function _() {
|
|
1008
|
+
n || (n = !0, r = [], s.operation(() => {
|
|
1009
|
+
for (let t of [...e.values()]) t.remove();
|
|
1010
|
+
}));
|
|
1011
|
+
}
|
|
1796
1012
|
}
|
|
1797
1013
|
//#endregion
|
|
1798
|
-
export {
|
|
1014
|
+
export { t as MakooError, a as coreErrors, N as createMakoo, i as defineMakooErrors, o as inject, s as injectEach, n as isMakooError, c as listen };
|