@makoojs/core 0.5.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 +32 -11
- package/README.md +32 -11
- package/dist/adapter/types.d.ts +35 -7
- package/dist/error/MakooError.d.ts +17 -10
- package/dist/error/coreErrors.d.ts +6793 -0
- package/dist/error/defineMakooErrors.d.ts +55 -0
- package/dist/index.cjs +3 -4
- package/dist/index.d.ts +16 -10
- package/dist/index.js +920 -818
- 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/{core → instance}/createMakoo.d.ts +1 -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 -4
- package/dist/adapter/registry.d.ts +0 -5
- package/dist/component/component.d.ts +0 -5
- package/dist/component/declaration.d.ts +0 -3
- package/dist/component/execution.d.ts +0 -24
- package/dist/component/types.d.ts +0 -37
- package/dist/core/types.d.ts +0 -27
- package/dist/dom/observer.d.ts +0 -4
- package/dist/dom/waitForElement.d.ts +0 -3
- package/dist/dom/watchElement.d.ts +0 -2
- package/dist/error/ErrorCode.d.ts +0 -27
- package/dist/listener/attach.d.ts +0 -12
- package/dist/listener/declaration.d.ts +0 -3
- package/dist/listener/execution.d.ts +0 -19
- package/dist/listener/listener.d.ts +0 -42
- package/dist/listener/types.d.ts +0 -31
- package/dist/state/createState.d.ts +0 -5
- package/dist/state/types.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -1,912 +1,1014 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var t = {
|
|
4
|
-
DECLARATION_INVALID: "MAKOO_DECLARATION_INVALID",
|
|
5
|
-
INJECTION_NAME_CONFLICT: "MAKOO_INJECTION_NAME_CONFLICT",
|
|
6
|
-
ADAPTER_INVALID: "MAKOO_ADAPTER_INVALID",
|
|
7
|
-
ADAPTER_NAME_CONFLICT: "MAKOO_ADAPTER_NAME_CONFLICT",
|
|
8
|
-
ADAPTER_NOT_FOUND: "MAKOO_ADAPTER_NOT_FOUND",
|
|
9
|
-
INJECTION_NOT_FOUND: "MAKOO_INJECTION_NOT_FOUND",
|
|
10
|
-
LISTENER_NOT_FOUND: "MAKOO_LISTENER_NOT_FOUND",
|
|
11
|
-
INJECTION_REMOVED: "MAKOO_INJECTION_REMOVED",
|
|
12
|
-
INJECTION_CLOSED: "MAKOO_INJECTION_CLOSED",
|
|
13
|
-
INSTANCE_DISPOSED: "MAKOO_INSTANCE_DISPOSED",
|
|
14
|
-
TARGET_WAIT_TIMEOUT: "MAKOO_TARGET_WAIT_TIMEOUT",
|
|
15
|
-
MOUNT_TARGET_DETACHED: "MAKOO_MOUNT_TARGET_DETACHED",
|
|
16
|
-
MOUNT_FAILED: "MAKOO_MOUNT_FAILED",
|
|
17
|
-
LISTENER_TARGET_DETACHED: "MAKOO_LISTENER_TARGET_DETACHED",
|
|
18
|
-
LISTENER_BIND_FAILED: "MAKOO_LISTENER_BIND_FAILED",
|
|
19
|
-
ATTACHED_LISTENER_FAILED: "MAKOO_ATTACHED_LISTENER_FAILED",
|
|
20
|
-
UNMOUNT_FAILED: "MAKOO_UNMOUNT_FAILED",
|
|
21
|
-
CONTAINER_REMOVE_FAILED: "MAKOO_CONTAINER_REMOVE_FAILED",
|
|
22
|
-
LISTENER_UNBIND_FAILED: "MAKOO_LISTENER_UNBIND_FAILED",
|
|
23
|
-
MOUNT_CLEANUP_FAILED: "MAKOO_MOUNT_CLEANUP_FAILED",
|
|
24
|
-
INJECTION_CLEANUP_FAILED: "MAKOO_INJECTION_CLEANUP_FAILED",
|
|
25
|
-
INSTANCE_CLEANUP_FAILED: "MAKOO_INSTANCE_CLEANUP_FAILED",
|
|
26
|
-
LISTENER_CALLBACK_FAILED: "MAKOO_LISTENER_CALLBACK_FAILED",
|
|
27
|
-
STATE_SUBSCRIBER_FAILED: "MAKOO_STATE_SUBSCRIBER_FAILED",
|
|
28
|
-
INSTANCE_OBSERVER_FAILED: "MAKOO_INSTANCE_OBSERVER_FAILED"
|
|
29
|
-
}, n = class extends Error {
|
|
1
|
+
//#region packages/core/src/error/MakooError.ts
|
|
2
|
+
var e = Symbol.for("makoo.error"), t = class extends Error {
|
|
30
3
|
code;
|
|
31
|
-
constructor(
|
|
32
|
-
super(
|
|
33
|
-
}
|
|
34
|
-
}, r = class extends n {
|
|
35
|
-
errors;
|
|
36
|
-
constructor(e, t, n) {
|
|
37
|
-
super(l(t, e), n), this.name = "MakooAggregateError", this.errors = e;
|
|
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 });
|
|
38
6
|
}
|
|
39
7
|
};
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
let { name: t } = e;
|
|
43
|
-
return typeof t == "string" && t.trim().length > 0 ? t : void 0;
|
|
44
|
-
}
|
|
45
|
-
function a(e, t, r) {
|
|
46
|
-
return new n([e, ...r.issues.map((e) => `${e.path.map(String).join(".") || "(root)"}: ${e.message}`)].join("\n"), {
|
|
47
|
-
code: t,
|
|
48
|
-
cause: r
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function o(e, r) {
|
|
52
|
-
return new n(`State subscriber of ${e} failed`, {
|
|
53
|
-
code: t.STATE_SUBSCRIBER_FAILED,
|
|
54
|
-
cause: r
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function s(e) {
|
|
58
|
-
return new n("Instance observe handler failed", {
|
|
59
|
-
code: t.INSTANCE_OBSERVER_FAILED,
|
|
60
|
-
cause: e
|
|
61
|
-
});
|
|
8
|
+
function n(t) {
|
|
9
|
+
return typeof t == "object" && !!t && t[e] === !0;
|
|
62
10
|
}
|
|
63
|
-
function
|
|
64
|
-
return new r(n, `Cleanup failed for "${e}"`, { code: t.INJECTION_CLEANUP_FAILED });
|
|
65
|
-
}
|
|
66
|
-
function l(e, t) {
|
|
11
|
+
function r(e, t) {
|
|
67
12
|
return [e, ...t.map((e) => {
|
|
68
13
|
let t = e instanceof Error ? e.message : String(e), n = t.indexOf("\n");
|
|
69
14
|
return n === -1 ? t : t.slice(0, n);
|
|
70
15
|
})].join("\n");
|
|
71
16
|
}
|
|
72
17
|
//#endregion
|
|
73
|
-
//#region packages/core/src/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
callback: e.custom((e) => typeof e == "function", "Expected an event handler"),
|
|
86
|
-
capture: e.boolean({ error: "Expected a boolean" }).optional(),
|
|
87
|
-
timeout: e.number({ error: d }).gt(0, d).max(2147483647, d).optional(),
|
|
88
|
-
reinject: e.boolean({ error: "Expected a boolean" }).optional()
|
|
89
|
-
}, { error: (e) => e.code === "invalid_type" ? "Expected a listener declaration" : void 0 });
|
|
90
|
-
function f(e) {
|
|
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
|
|
28
|
+
});
|
|
29
|
+
}
|
|
91
30
|
return {
|
|
92
|
-
|
|
93
|
-
|
|
31
|
+
create: n,
|
|
32
|
+
createThrowable: n,
|
|
33
|
+
createRecorded: n
|
|
94
34
|
};
|
|
95
35
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
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
|
+
});
|
|
104
129
|
//#endregion
|
|
105
|
-
//#region packages/core/src/
|
|
106
|
-
|
|
107
|
-
kind: e.literal("component", { error: "Expected component" }),
|
|
108
|
-
name: m,
|
|
109
|
-
injectAt: m.refine((e) => {
|
|
110
|
-
try {
|
|
111
|
-
return document.createDocumentFragment().querySelector(e), !0;
|
|
112
|
-
} catch {
|
|
113
|
-
return !1;
|
|
114
|
-
}
|
|
115
|
-
}, "Invalid CSS selector"),
|
|
116
|
-
adapter: m,
|
|
117
|
-
component: e.unknown(),
|
|
118
|
-
props: e.unknown().optional(),
|
|
119
|
-
timeout: e.number({ error: h }).gt(0, h).max(2147483647, h).optional(),
|
|
120
|
-
reinject: e.boolean({ error: "Expected a boolean" }).optional(),
|
|
121
|
-
listeners: e.array(e.unknown()).optional()
|
|
122
|
-
}, { error: (e) => e.code === "invalid_type" ? "Expected a component declaration" : void 0 });
|
|
123
|
-
function ne(e) {
|
|
130
|
+
//#region packages/core/src/injections/inject/declaration.ts
|
|
131
|
+
function o(e) {
|
|
124
132
|
return {
|
|
125
133
|
...e,
|
|
126
134
|
kind: "component"
|
|
127
135
|
};
|
|
128
136
|
}
|
|
129
|
-
function g(e) {
|
|
130
|
-
let r = te.safeParse(e);
|
|
131
|
-
if (!r.success) {
|
|
132
|
-
let n = i(e);
|
|
133
|
-
throw a(n ? `Invalid component declaration "${n}"` : "Invalid component declaration", t.DECLARATION_INVALID, r.error);
|
|
134
|
-
}
|
|
135
|
-
let o = /* @__PURE__ */ new Set(), s = r.data.listeners?.map((e, r) => {
|
|
136
|
-
let i;
|
|
137
|
-
try {
|
|
138
|
-
i = p(e);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
throw e instanceof n ? new n(`Invalid attached listener at listeners[${r}]`, {
|
|
141
|
-
code: t.DECLARATION_INVALID,
|
|
142
|
-
cause: e
|
|
143
|
-
}) : e;
|
|
144
|
-
}
|
|
145
|
-
if (o.has(i.name)) throw new n(`Duplicate attached listener "${i.name}" at listeners[${r}]`, { code: t.INJECTION_NAME_CONFLICT });
|
|
146
|
-
if (i.reinject !== void 0) throw new n(`Attached listeners inherit the component recovery setting (listeners[${r}].reinject)`, { code: t.DECLARATION_INVALID });
|
|
147
|
-
return o.add(i.name), i;
|
|
148
|
-
});
|
|
149
|
-
return Object.freeze({
|
|
150
|
-
...r.data,
|
|
151
|
-
listeners: s && Object.freeze(s)
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
137
|
//#endregion
|
|
155
|
-
//#region packages/core/src/
|
|
156
|
-
|
|
157
|
-
name: e.string({ error: "Expected a non-empty string" }).refine((e) => e.trim().length > 0, "Expected a non-empty string"),
|
|
158
|
-
mount: e.custom((e) => typeof e == "function", "Expected a mount function"),
|
|
159
|
-
unmount: e.custom((e) => typeof e == "function", "Expected an unmount function")
|
|
160
|
-
}, { error: (e) => e.code === "invalid_type" ? "Expected an adapter" : void 0 });
|
|
161
|
-
function re() {
|
|
162
|
-
let e = /* @__PURE__ */ new Map();
|
|
138
|
+
//#region packages/core/src/injections/injectEach/declaration.ts
|
|
139
|
+
function s(e) {
|
|
163
140
|
return {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (!o.success) {
|
|
167
|
-
let e = i(r);
|
|
168
|
-
throw a(e ? `Invalid adapter "${e}"` : "Invalid adapter", t.ADAPTER_INVALID, o.error);
|
|
169
|
-
}
|
|
170
|
-
if (e.has(o.data.name)) throw new n(`Adapter "${o.data.name}" is already registered`, { code: t.ADAPTER_NAME_CONFLICT });
|
|
171
|
-
e.set(o.data.name, r);
|
|
172
|
-
},
|
|
173
|
-
require(r) {
|
|
174
|
-
let i = e.get(r);
|
|
175
|
-
if (!i) throw new n(`Unknown adapter "${r}"`, { code: t.ADAPTER_NOT_FOUND });
|
|
176
|
-
return i;
|
|
177
|
-
}
|
|
141
|
+
...e,
|
|
142
|
+
kind: "component-each"
|
|
178
143
|
};
|
|
179
144
|
}
|
|
180
145
|
//#endregion
|
|
181
|
-
//#region packages/core/src/
|
|
182
|
-
function
|
|
183
|
-
let n = e, r = /* @__PURE__ */ new Set();
|
|
146
|
+
//#region packages/core/src/injections/listen/declaration.ts
|
|
147
|
+
function c(e) {
|
|
184
148
|
return {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
subscribe(e) {
|
|
188
|
-
return r.add(e), () => {
|
|
189
|
-
r.delete(e);
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}),
|
|
193
|
-
set(e) {
|
|
194
|
-
if (!Object.is(n, e)) {
|
|
195
|
-
n = e;
|
|
196
|
-
for (let e of [...r]) try {
|
|
197
|
-
e();
|
|
198
|
-
} catch (e) {
|
|
199
|
-
t(e);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
function y(e, t, n, r, i, a, o) {
|
|
206
|
-
if (n.aborted) return;
|
|
207
|
-
let s = !0, c = () => {}, l, u = () => {
|
|
208
|
-
s = !1, c(), clearTimeout(l), n.removeEventListener("abort", u);
|
|
209
|
-
}, d = () => {
|
|
210
|
-
if (!s || n.aborted) return;
|
|
211
|
-
let e;
|
|
212
|
-
try {
|
|
213
|
-
e = document.querySelector(t);
|
|
214
|
-
} catch (e) {
|
|
215
|
-
u(), o(e);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
!s || n.aborted || !e?.isConnected || (u(), i(e));
|
|
149
|
+
...e,
|
|
150
|
+
kind: "listener"
|
|
219
151
|
};
|
|
220
|
-
c = e.subscribe(d, n), n.addEventListener("abort", u, { once: !0 }), l = setTimeout(() => {
|
|
221
|
-
!s || n.aborted || (u(), a());
|
|
222
|
-
}, r), d();
|
|
223
|
-
}
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region packages/core/src/dom/watchElement.ts
|
|
226
|
-
function b(e, t, n, r, i = () => t.isConnected) {
|
|
227
|
-
if (n.aborted) return;
|
|
228
|
-
let a = () => {
|
|
229
|
-
n.aborted || i() || (o(), r());
|
|
230
|
-
}, o = e.subscribe(a, n);
|
|
231
|
-
a();
|
|
232
152
|
}
|
|
233
153
|
//#endregion
|
|
234
|
-
//#region packages/core/src/
|
|
235
|
-
function
|
|
236
|
-
let n = {
|
|
237
|
-
config: e,
|
|
238
|
-
phase: "active",
|
|
239
|
-
abortController: new AbortController(),
|
|
240
|
-
eventListener: (e) => C(n, t, e),
|
|
241
|
-
listenerTarget: null,
|
|
242
|
-
cleanupErrors: []
|
|
243
|
-
};
|
|
244
|
-
return n;
|
|
245
|
-
}
|
|
246
|
-
function S(e, r, i) {
|
|
247
|
-
let { config: a } = e;
|
|
154
|
+
//#region packages/core/src/runtime/selector.ts
|
|
155
|
+
function l(e, t) {
|
|
248
156
|
try {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
},
|
|
252
|
-
e.phase === "active" && i.ended("failed", E(a.name, t));
|
|
253
|
-
}), e.phase === "active" && !e.listenerTarget && i.setStatus("waiting");
|
|
254
|
-
} catch (t) {
|
|
255
|
-
e.phase === "active" && i.ended("failed", E(a.name, t));
|
|
157
|
+
document.createDocumentFragment().querySelector(t);
|
|
158
|
+
} catch {
|
|
159
|
+
throw a.createThrowable("MAKOO_DECLARATION_INVALID", { details: { reason: `${e}: Expected a valid CSS selector, got "${t}"` } });
|
|
256
160
|
}
|
|
257
161
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
162
|
+
//#endregion
|
|
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)
|
|
173
|
+
})
|
|
174
|
+
};
|
|
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
|
+
};
|
|
278
194
|
try {
|
|
279
|
-
e.
|
|
280
|
-
} catch (e) {
|
|
281
|
-
n.push(D(t.name, e));
|
|
282
|
-
}
|
|
283
|
-
if (r) try {
|
|
284
|
-
r.removeEventListener(t.type, e.eventListener, t.capture);
|
|
195
|
+
e.addEventListener(t.type, r, { capture: t.capture });
|
|
285
196
|
} catch (e) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
function C(e, t, n) {
|
|
291
|
-
let { config: r, listenerTarget: i } = e;
|
|
292
|
-
if (!(e.phase !== "active" || !i)) try {
|
|
293
|
-
let e = r.callback.call(i, n);
|
|
294
|
-
e !== void 0 && Promise.resolve(e).catch((e) => t(w(r.name, e)));
|
|
295
|
-
} catch (e) {
|
|
296
|
-
t(w(r.name, e));
|
|
197
|
+
throw a.createRecorded("MAKOO_LISTENER_BIND_FAILED", {
|
|
198
|
+
details: { name: t.name },
|
|
199
|
+
cause: e
|
|
200
|
+
});
|
|
297
201
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
function E(e, r) {
|
|
309
|
-
return new n(`Failed to bind listener "${e}"`, {
|
|
310
|
-
code: t.LISTENER_BIND_FAILED,
|
|
311
|
-
cause: r
|
|
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
|
+
}
|
|
312
211
|
});
|
|
313
212
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
213
|
+
//#endregion
|
|
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);
|
|
318
224
|
});
|
|
319
225
|
}
|
|
320
226
|
//#endregion
|
|
321
|
-
//#region packages/core/src/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
kind: "
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
intent: "stopped",
|
|
331
|
-
executionSlot: {
|
|
332
|
-
kind: "empty",
|
|
333
|
-
cleanupPromise: Promise.resolve()
|
|
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;
|
|
334
236
|
},
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
});
|
|
367
|
-
i.catch(() => {});
|
|
368
|
-
let a = x(e.config, (t) => {
|
|
369
|
-
let n = e.executionSlot;
|
|
370
|
-
(n.kind === "active" || n.kind === "closing") && n.execution === a && (e.lastError = t), console.error(t);
|
|
371
|
-
});
|
|
372
|
-
e.executionSlot = {
|
|
373
|
-
kind: "active",
|
|
374
|
-
execution: a,
|
|
375
|
-
cleanupCompletion: {
|
|
376
|
-
promise: i,
|
|
377
|
-
resolve: n,
|
|
378
|
-
reject: r
|
|
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
|
+
}
|
|
267
|
+
};
|
|
379
268
|
}
|
|
380
|
-
},
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
269
|
+
},
|
|
270
|
+
"component-each": {
|
|
271
|
+
kind: "component-each",
|
|
272
|
+
active: "collecting",
|
|
273
|
+
resolve(e) {
|
|
274
|
+
return l("injectAt", e.injectAt), e;
|
|
384
275
|
},
|
|
385
|
-
|
|
386
|
-
let
|
|
387
|
-
|
|
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
|
+
};
|
|
388
299
|
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
let n = e.executionSlot;
|
|
393
|
-
if (n.kind === "cleanup-failed" || n.kind === "removed") return n.cleanupPromise;
|
|
394
|
-
switch (e.intent !== "removed" && (e.intent = "stopped"), n.kind) {
|
|
395
|
-
case "empty": return e.state.set("idle"), n.cleanupPromise;
|
|
396
|
-
case "closing": return n.cleanupCompletion.promise;
|
|
397
|
-
case "active": return M(e, t, "stopped");
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function j(e, t) {
|
|
401
|
-
let n = e.executionSlot;
|
|
402
|
-
if (n.kind === "cleanup-failed" || n.kind === "removed") return n.cleanupPromise;
|
|
403
|
-
e.intent = "removed";
|
|
404
|
-
let r = A(e, t);
|
|
405
|
-
return e.executionSlot.kind === "empty" && (e.executionSlot = {
|
|
406
|
-
kind: "removed",
|
|
407
|
-
cleanupPromise: r
|
|
408
|
-
}, e.onRemoved()), r;
|
|
409
|
-
}
|
|
410
|
-
function M(e, t, n, r) {
|
|
411
|
-
let i = e.executionSlot;
|
|
412
|
-
switch (i.kind) {
|
|
413
|
-
case "empty":
|
|
414
|
-
case "removed":
|
|
415
|
-
case "cleanup-failed": return i.cleanupPromise;
|
|
416
|
-
case "closing": return i.cleanupCompletion.promise;
|
|
417
|
-
}
|
|
418
|
-
let { execution: a, cleanupCompletion: o } = i;
|
|
419
|
-
e.executionSlot = {
|
|
420
|
-
...i,
|
|
421
|
-
kind: "closing"
|
|
422
|
-
}, ae(a);
|
|
423
|
-
let s = a.cleanupErrors;
|
|
424
|
-
if (s.length > 0 && e.kind === "attach") {
|
|
425
|
-
r && (e.lastError = r), e.executionSlot = {
|
|
426
|
-
kind: "cleanup-failed",
|
|
427
|
-
cleanupPromise: o.promise,
|
|
428
|
-
cleanupErrors: s
|
|
429
|
-
}, o.reject(r ?? s[0]);
|
|
430
|
-
let t = e.executionSlot;
|
|
431
|
-
return e.state.set("failed"), r && e.executionSlot === t && e.onFailed(r), o.promise;
|
|
432
|
-
}
|
|
433
|
-
if (s.length > 0) {
|
|
434
|
-
let t = c(e.config.name, r ? [r, ...s] : s);
|
|
435
|
-
e.lastError = t, e.executionSlot = {
|
|
436
|
-
kind: "cleanup-failed",
|
|
437
|
-
cleanupPromise: o.promise,
|
|
438
|
-
cleanupErrors: s
|
|
439
|
-
}, o.reject(t), console.error(t);
|
|
440
|
-
let n = e.executionSlot;
|
|
441
|
-
return e.state.set("failed"), e.kind === "attach" && e.executionSlot === n && e.onFailed(r ?? t), o.promise;
|
|
442
|
-
}
|
|
443
|
-
if (e.executionSlot = {
|
|
444
|
-
kind: "empty",
|
|
445
|
-
cleanupPromise: o.promise
|
|
446
|
-
}, o.resolve(), e.kind === "listener" && e.intent === "removed") return e.executionSlot = {
|
|
447
|
-
kind: "removed",
|
|
448
|
-
cleanupPromise: o.promise
|
|
449
|
-
}, e.state.set("idle"), e.onRemoved(), o.promise;
|
|
450
|
-
if (e.intent === "running" && (n === "stopped" || n === "detached" && e.config.reinject)) return n === "detached" && e.state.set("waiting"), e.intent === "running" && e.executionSlot.kind === "empty" && (n === "stopped" ? O(e, t) : k(e, t)), o.promise;
|
|
451
|
-
e.intent = "stopped", r && (e.lastError = r, console.error(r));
|
|
452
|
-
let l = e.executionSlot;
|
|
453
|
-
return e.state.set(n === "stopped" ? "idle" : "failed"), r && e.kind === "attach" && e.executionSlot === l && e.onFailed(r), o.promise;
|
|
454
|
-
}
|
|
300
|
+
},
|
|
301
|
+
listener: u
|
|
302
|
+
};
|
|
455
303
|
//#endregion
|
|
456
|
-
//#region packages/core/src/
|
|
457
|
-
function
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
intent: "stopped",
|
|
463
|
-
executionSlot: {
|
|
464
|
-
kind: "empty",
|
|
465
|
-
cleanupPromise: Promise.resolve()
|
|
466
|
-
},
|
|
467
|
-
lastError: void 0,
|
|
468
|
-
onFailed: t
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
async function P(e, t) {
|
|
472
|
-
for (let t of e.values()) {
|
|
473
|
-
t.intent = "stopped";
|
|
474
|
-
let e = t.executionSlot;
|
|
475
|
-
e.kind === "active" && (e.execution.phase = "cancelled");
|
|
476
|
-
}
|
|
477
|
-
let n = [];
|
|
478
|
-
for (let r of e.values()) {
|
|
479
|
-
let e = r.executionSlot;
|
|
480
|
-
switch (e.kind) {
|
|
481
|
-
case "empty":
|
|
482
|
-
r.state.view.getSnapshot() !== "failed" && r.state.set("idle");
|
|
483
|
-
continue;
|
|
484
|
-
case "cleanup-failed":
|
|
485
|
-
n.push(...e.cleanupErrors);
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
let { execution: i } = e;
|
|
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(() => {
|
|
489
310
|
try {
|
|
490
|
-
|
|
491
|
-
} catch {
|
|
492
|
-
|
|
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
|
+
});
|
|
493
336
|
}
|
|
494
|
-
|
|
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
|
+
} };
|
|
495
422
|
}
|
|
496
423
|
//#endregion
|
|
497
|
-
//#region packages/core/src/
|
|
498
|
-
function
|
|
499
|
-
|
|
500
|
-
config: e,
|
|
501
|
-
attachListeners: r,
|
|
502
|
-
domWaitAbortController: new AbortController(),
|
|
503
|
-
phase: "pending",
|
|
504
|
-
componentContainer: null,
|
|
505
|
-
mountedComponent: null,
|
|
506
|
-
cleanupErrors: []
|
|
507
|
-
};
|
|
508
|
-
return {
|
|
509
|
-
get phase() {
|
|
510
|
-
return a.phase;
|
|
511
|
-
},
|
|
512
|
-
start: () => I(a, t, n, i),
|
|
513
|
-
cancel: () => a.domWaitAbortController.abort(),
|
|
514
|
-
finish: () => R(a, t, n)
|
|
515
|
-
};
|
|
424
|
+
//#region packages/core/src/runtime/scope.ts
|
|
425
|
+
function _(e) {
|
|
426
|
+
return x(void 0, e);
|
|
516
427
|
}
|
|
517
|
-
function
|
|
518
|
-
let { config: i, domWaitAbortController: a } = e;
|
|
428
|
+
function v(e, t) {
|
|
519
429
|
try {
|
|
520
|
-
|
|
521
|
-
r.ended("failed", B(i.name));
|
|
522
|
-
}, (t) => r.ended("failed", H(e, t))), e.phase === "pending" && r.setStatus("waiting");
|
|
430
|
+
t();
|
|
523
431
|
} catch (t) {
|
|
524
|
-
|
|
432
|
+
e.addCleanupErrors([t]);
|
|
525
433
|
}
|
|
526
434
|
}
|
|
527
|
-
function
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (e.componentContainer = c, i.append(c), e.phase = "mounting", r.setStatus("waiting"), s.aborted) {
|
|
532
|
-
r.ended("stopped");
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
if (!i.isConnected || !c.isConnected || !i.contains(c)) {
|
|
536
|
-
r.ended("detached", V(a.name));
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
try {
|
|
540
|
-
e.mountedComponent = { mountHandle: n.mount(c) }, e.phase = "mounted";
|
|
541
|
-
} catch (t) {
|
|
542
|
-
r.ended("failed", H(e, t));
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
if (s.aborted) {
|
|
546
|
-
r.ended("stopped");
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
if (!i.isConnected || !c.isConnected || !i.contains(c)) {
|
|
550
|
-
r.ended("detached", V(a.name));
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
for (let n of e.attachListeners.values()) {
|
|
554
|
-
if (O(n, t), s.aborted) return;
|
|
555
|
-
if (!i.isConnected || !c.isConnected || !i.contains(c)) {
|
|
556
|
-
r.ended("detached", V(a.name));
|
|
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);
|
|
557
439
|
return;
|
|
558
440
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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--;
|
|
450
|
+
}
|
|
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);
|
|
566
468
|
}
|
|
567
|
-
function
|
|
568
|
-
let
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
r.
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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);
|
|
475
|
+
},
|
|
476
|
+
onCleanup(e) {
|
|
477
|
+
r.phase.kind === "live" ? r.cleanups.push(e) : r.phase.kind === "ending" ? v(r, e) : e();
|
|
478
|
+
},
|
|
479
|
+
spawn: (e) => x(r, e),
|
|
480
|
+
get isEnded() {
|
|
481
|
+
return r.phase.kind !== "live";
|
|
482
|
+
},
|
|
483
|
+
get isTransitioning() {
|
|
484
|
+
return n.depth > 0;
|
|
485
|
+
},
|
|
486
|
+
get outcome() {
|
|
487
|
+
return r.phase.kind === "sealed" ? r.phase.outcome : void 0;
|
|
488
|
+
},
|
|
489
|
+
phase: {
|
|
490
|
+
kind: "live",
|
|
491
|
+
cleanupErrors: []
|
|
492
|
+
},
|
|
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: []
|
|
509
|
+
}
|
|
510
|
+
}, r;
|
|
511
|
+
e.childScopes.add(r);
|
|
579
512
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
a.push(new n(`Failed to remove container of "${i.name}"`, {
|
|
587
|
-
code: t.CONTAINER_REMOVE_FAILED,
|
|
588
|
-
cause: e
|
|
589
|
-
}));
|
|
590
|
-
}
|
|
513
|
+
n.depth++;
|
|
514
|
+
let i, a = !1;
|
|
515
|
+
try {
|
|
516
|
+
t.setup(r);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
i = e, a = !0;
|
|
591
519
|
}
|
|
592
|
-
return a;
|
|
593
|
-
}
|
|
594
|
-
function B(e) {
|
|
595
|
-
return new n(`Timed out waiting for the mount target of "${e}"`, { code: t.TARGET_WAIT_TIMEOUT });
|
|
596
|
-
}
|
|
597
|
-
function V(e) {
|
|
598
|
-
return new n(`Mount target "${e}" disconnected`, { code: t.MOUNT_TARGET_DETACHED });
|
|
599
|
-
}
|
|
600
|
-
function H(e, i) {
|
|
601
|
-
let a = i instanceof r && i.code === t.MOUNT_CLEANUP_FAILED ? i : void 0;
|
|
602
|
-
return a && e.cleanupErrors.push(...a.errors), new n(`Failed to mount "${e.config.name}"`, {
|
|
603
|
-
code: t.MOUNT_FAILED,
|
|
604
|
-
cause: a ? a.cause : i
|
|
605
|
-
});
|
|
520
|
+
return r.isSettingUp = !1, a && y(r, "failed", i), b(r), n.depth--, r;
|
|
606
521
|
}
|
|
607
522
|
//#endregion
|
|
608
|
-
//#region packages/core/src/
|
|
609
|
-
function
|
|
610
|
-
let
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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
|
+
}
|
|
576
|
+
}
|
|
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();
|
|
638
616
|
});
|
|
617
|
+
e.addHandle(p);
|
|
639
618
|
},
|
|
640
|
-
|
|
641
|
-
t
|
|
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);
|
|
642
632
|
}
|
|
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)));
|
|
653
|
+
}
|
|
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());
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
get root() {
|
|
714
|
+
return l.node;
|
|
643
715
|
},
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}),
|
|
648
|
-
attachListeners: /* @__PURE__ */ new Map(),
|
|
649
|
-
intent: "stopped",
|
|
650
|
-
executionSlot: {
|
|
651
|
-
kind: "empty",
|
|
652
|
-
cleanupPromise: Promise.resolve()
|
|
716
|
+
deliver() {
|
|
717
|
+
l.deliver();
|
|
718
|
+
for (let e of [...s]) e.deliver(), e.isRetired && s.splice(s.indexOf(e), 1);
|
|
653
719
|
},
|
|
720
|
+
stateNode: d
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
function C(e, t) {
|
|
724
|
+
let n = /* @__PURE__ */ new Set(), r = {
|
|
725
|
+
status: "idle",
|
|
654
726
|
lastError: void 0
|
|
655
727
|
};
|
|
656
|
-
for (let t of e.listeners ?? []) c.attachListeners.set(t.name, N({
|
|
657
|
-
...t,
|
|
658
|
-
reinject: e.reinject
|
|
659
|
-
}, (e) => se(c, t.name, e), (n) => {
|
|
660
|
-
let r = o(`"${e.name}" listener "${t.name}"`, n);
|
|
661
|
-
console.error(r), s(e.name, r);
|
|
662
|
-
}));
|
|
663
728
|
return {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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
|
+
}
|
|
746
|
+
}
|
|
667
747
|
};
|
|
668
748
|
}
|
|
669
|
-
function
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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));
|
|
765
|
+
}
|
|
766
|
+
function E(e) {
|
|
767
|
+
return e.some((e) => e.appearances().length > 0);
|
|
768
|
+
}
|
|
769
|
+
function D(e) {
|
|
770
|
+
return e !== void 0 && (e.error !== void 0 || e.cleanupErrors.length > 0);
|
|
771
|
+
}
|
|
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;
|
|
686
777
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
778
|
+
//#endregion
|
|
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));
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
r.operation(() => {
|
|
798
|
+
r.assertOpen(), !c.isRunning && u();
|
|
799
|
+
});
|
|
696
800
|
},
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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));
|
|
815
|
+
});
|
|
709
816
|
}
|
|
710
|
-
},
|
|
711
|
-
|
|
712
|
-
function q(e) {
|
|
713
|
-
let t = e.executionSlot;
|
|
714
|
-
if (t.kind === "cleanup-failed" || t.kind === "removed") return t.cleanupPromise;
|
|
715
|
-
switch (e.intent !== "removed" && (e.intent = "stopped"), t.kind) {
|
|
716
|
-
case "empty": return e.state.set("idle"), t.cleanupPromise;
|
|
717
|
-
case "cancelling":
|
|
718
|
-
case "closing": return t.cleanupCompletion.promise;
|
|
719
|
-
case "active": return t.execution.phase === "mounting" ? (e.executionSlot = {
|
|
720
|
-
...t,
|
|
721
|
-
kind: "cancelling"
|
|
722
|
-
}, t.execution.cancel(), t.cleanupCompletion.promise) : J(e, "stopped");
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
function ce(e) {
|
|
726
|
-
let t = e.executionSlot;
|
|
727
|
-
if (t.kind === "cleanup-failed" || t.kind === "removed") return t.cleanupPromise;
|
|
728
|
-
e.intent = "removed";
|
|
729
|
-
let n = q(e);
|
|
730
|
-
return e.executionSlot.kind === "empty" && (e.executionSlot = {
|
|
731
|
-
kind: "removed",
|
|
732
|
-
cleanupPromise: n
|
|
733
|
-
}, e.onRemoved()), n;
|
|
817
|
+
}, p = c.flatten(f, l.expose);
|
|
818
|
+
return r.track(p, s.deliver), p;
|
|
734
819
|
}
|
|
735
|
-
|
|
736
|
-
let r =
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
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();
|
|
834
|
+
}
|
|
835
|
+
},
|
|
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);
|
|
844
|
+
}
|
|
747
845
|
};
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
if (e.intent === "running" && (t === "stopped" || t === "detached" && e.config.reinject)) {
|
|
767
|
-
t === "detached" && e.state.set("waiting"), e.intent === "running" && e.executionSlot.kind === "empty" && (t === "stopped" ? G(e) : K(e));
|
|
768
|
-
return;
|
|
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
|
+
}
|
|
862
|
+
}
|
|
769
863
|
}
|
|
770
|
-
|
|
864
|
+
return c;
|
|
771
865
|
}
|
|
772
866
|
//#endregion
|
|
773
|
-
//#region packages/core/src/
|
|
774
|
-
function
|
|
775
|
-
let
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
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, {
|
|
781
875
|
subtree: !0,
|
|
782
876
|
childList: !0,
|
|
783
|
-
attributes: !0
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
e.delete(n) && (r.removeEventListener("abort", i), e.size || t?.disconnect());
|
|
877
|
+
attributes: !0
|
|
878
|
+
}), t.add(e);
|
|
879
|
+
let a = () => {
|
|
880
|
+
t.delete(e) && (i.removeEventListener("abort", a), t.size || n?.disconnect());
|
|
788
881
|
};
|
|
789
|
-
return
|
|
882
|
+
return i.addEventListener("abort", a, { once: !0 }), a;
|
|
790
883
|
} };
|
|
791
884
|
}
|
|
792
885
|
//#endregion
|
|
793
|
-
//#region packages/core/src/
|
|
794
|
-
function
|
|
795
|
-
let e = {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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;
|
|
802
895
|
};
|
|
803
|
-
return {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
},
|
|
810
|
-
command: (t) => $(e.injections, t).command,
|
|
811
|
-
statusHandle: (t) => $(e.injections, t).statusHandle,
|
|
812
|
-
observe: (t) => (Q(e), e.observers.add(t), () => {
|
|
813
|
-
e.observers.delete(t);
|
|
814
|
-
}),
|
|
815
|
-
dispose: () => pe(e)
|
|
896
|
+
return (e) => {
|
|
897
|
+
let n = t(e);
|
|
898
|
+
return {
|
|
899
|
+
isLocked: (e) => n.has(e),
|
|
900
|
+
lock: (e) => n.add(e)
|
|
901
|
+
};
|
|
816
902
|
};
|
|
817
903
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
function fe(e, t, n) {
|
|
840
|
-
let { injections: r, dom: i } = e, a = (t, n) => {
|
|
841
|
-
Z(e, {
|
|
842
|
-
type: "diagnostic",
|
|
843
|
-
name: t,
|
|
844
|
-
error: n
|
|
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
|
|
915
|
+
});
|
|
916
|
+
}
|
|
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
|
|
845
924
|
});
|
|
846
|
-
},
|
|
847
|
-
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
let r = s(t);
|
|
862
|
-
console.error(r), n && Z(e, {
|
|
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({
|
|
863
940
|
type: "diagnostic",
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
let a = [];
|
|
879
|
-
for (let t of [...e.injections.values()]) try {
|
|
880
|
-
await t.command.remove();
|
|
881
|
-
} catch (e) {
|
|
882
|
-
a.push(e);
|
|
883
|
-
}
|
|
884
|
-
if (Z(e, { type: "instance-disposed" }), e.observers.clear(), a.length === 0) {
|
|
885
|
-
n();
|
|
886
|
-
return;
|
|
887
|
-
}
|
|
888
|
-
i(new r(a, "Failed to dispose core", { code: t.INSTANCE_CLEANUP_FAILED }));
|
|
889
|
-
})(), a;
|
|
890
|
-
}
|
|
891
|
-
function me(e, r) {
|
|
892
|
-
let i = $(e, r);
|
|
893
|
-
if (i.kind !== "listener") throw new n(`Unknown injection "${r}"`, { code: t.INJECTION_NOT_FOUND });
|
|
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
|
+
};
|
|
894
955
|
return {
|
|
895
|
-
|
|
896
|
-
|
|
956
|
+
apply(e) {
|
|
957
|
+
o(), s.operation(() => u(e));
|
|
958
|
+
},
|
|
959
|
+
injection(e) {
|
|
960
|
+
return o(), p(e);
|
|
961
|
+
},
|
|
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: () => _()
|
|
897
971
|
};
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
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
|
+
}));
|
|
908
1011
|
}
|
|
909
|
-
throw new n("Invalid declaration\nkind: Expected listener or component", { code: t.DECLARATION_INVALID });
|
|
910
1012
|
}
|
|
911
1013
|
//#endregion
|
|
912
|
-
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 };
|