@makoojs/core 0.4.0 → 0.5.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 +62 -259
- package/README.md +62 -261
- package/dist/adapter/registry.d.ts +5 -0
- package/dist/adapter/types.d.ts +14 -51
- package/dist/component/component.d.ts +5 -0
- package/dist/component/declaration.d.ts +3 -0
- package/dist/component/execution.d.ts +24 -0
- package/dist/component/types.d.ts +37 -0
- package/dist/core/createMakoo.d.ts +2 -0
- package/dist/core/types.d.ts +27 -0
- package/dist/dom/observer.d.ts +4 -0
- package/dist/dom/waitForElement.d.ts +3 -0
- package/dist/dom/watchElement.d.ts +2 -0
- package/dist/error/ErrorCode.d.ts +25 -17
- package/dist/error/MakooError.d.ts +15 -11
- package/dist/index.cjs +5 -5
- package/dist/index.d.ts +10 -19
- package/dist/index.js +800 -1686
- package/dist/listener/attach.d.ts +12 -0
- package/dist/listener/declaration.d.ts +3 -0
- package/dist/listener/execution.d.ts +19 -0
- package/dist/listener/listener.d.ts +42 -0
- package/dist/listener/types.d.ts +31 -0
- package/dist/state/createState.d.ts +5 -0
- package/dist/state/types.d.ts +4 -0
- package/package.json +4 -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/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/README.md
CHANGED
|
@@ -1,289 +1,90 @@
|
|
|
1
1
|
# @makoojs/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@makoojs/core"><img alt="npm" src="https://img.shields.io/npm/v/@makoojs/core?style=flat-square"></a>
|
|
5
|
+
<a href="https://github.com/makoojs/Makoo/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/License-MIT-yellow?style=flat-square"></a>
|
|
6
|
+
</p>
|
|
4
7
|
|
|
5
|
-
>
|
|
6
|
-
|
|
8
|
+
<p>
|
|
9
|
+
<a href="https://makoojs.github.io/Makoo/api/core">API Reference</a> •
|
|
10
|
+
<a href="https://github.com/makoojs/Makoo">Makoo</a> •
|
|
11
|
+
<a href="https://github.com/makoojs/Makoo/blob/main/packages/core/README.CN.md">中文</a>
|
|
12
|
+
</p>
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
The core package of Makoo, running in the browser. You use it to create a Core instance, declare components and page event listeners, then control them and read their status. Waiting for target elements, mounting, recovery after node replacement, and cleanup all happen here.
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
- Create a Makoo runtime with `createMakoo()` and start explicit task declarations.
|
|
12
|
-
- Listen to injection lifecycle events for debugging, analytics, error reporting, or visual devtools.
|
|
13
|
-
- Use low-level tools such as `DOMWatcher` and `createActivityStore` for custom integrations.
|
|
16
|
+
It doesn't depend on any frontend framework; components are mounted through the adapters provided by [`@makoojs/vue`](https://www.npmjs.com/package/@makoojs/vue) or [`@makoojs/react`](https://www.npmjs.com/package/@makoojs/react).
|
|
14
17
|
|
|
15
18
|
## Installation
|
|
16
19
|
|
|
17
|
-
```
|
|
18
|
-
# npm install @makoojs/core
|
|
19
|
-
# yarn add @makoojs/core
|
|
20
|
+
```sh
|
|
20
21
|
pnpm add @makoojs/core
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> Projects created with `pnpm dlx @makoojs/create-makoo` already include it; no separate installation is needed.
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
import {
|
|
27
|
-
createMakoo,
|
|
28
|
-
inject,
|
|
29
|
-
type ResolvableMountAdapter
|
|
30
|
-
} from '@makoojs/core';
|
|
31
|
-
|
|
32
|
-
type TextArtifact = {
|
|
33
|
-
kind: 'text';
|
|
34
|
-
text: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const textAdapter: ResolvableMountAdapter<TextArtifact, HTMLElement> = {
|
|
38
|
-
name: 'text',
|
|
39
|
-
matches(artifact): artifact is TextArtifact {
|
|
40
|
-
return (
|
|
41
|
-
typeof artifact === 'object' &&
|
|
42
|
-
artifact !== null &&
|
|
43
|
-
(artifact as { kind?: unknown }).kind === 'text'
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
mount({ mountPoint, artifact }) {
|
|
47
|
-
const el = document.createElement('span');
|
|
48
|
-
el.textContent = artifact.text;
|
|
49
|
-
mountPoint.appendChild(el);
|
|
50
|
-
|
|
51
|
-
return { handle: el };
|
|
52
|
-
},
|
|
53
|
-
unmount({ handle }) {
|
|
54
|
-
handle.remove();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const makoo = createMakoo({
|
|
59
|
-
defaults: {
|
|
60
|
-
alive: true,
|
|
61
|
-
scope: 'local',
|
|
62
|
-
timeout: 5000
|
|
63
|
-
},
|
|
64
|
-
adapters: [textAdapter]
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
makoo.start([
|
|
68
|
-
inject({
|
|
69
|
-
id: 'text',
|
|
70
|
-
injectAt: '#app',
|
|
71
|
-
artifact: {
|
|
72
|
-
kind: 'text',
|
|
73
|
-
text: 'Hello from Makoo core'
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
]);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Runtime Basics
|
|
80
|
-
|
|
81
|
-
`inject()` and `listen()` declare tasks. They do not touch the DOM or register tasks by themselves. `makoo.start([...])` registers the declarations in the provided batch and immediately schedules those tasks.
|
|
27
|
+
## Usage
|
|
82
28
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
inject({
|
|
87
|
-
id: 'settings-panel',
|
|
88
|
-
injectAt: '#settings',
|
|
89
|
-
artifact: settingsArtifact,
|
|
90
|
-
options: {
|
|
91
|
-
alive: true
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
When `id` is omitted, Makoo infers a task id from the artifact and target selector.
|
|
29
|
+
### Declare Components and Listeners
|
|
97
30
|
|
|
98
31
|
```ts
|
|
99
32
|
import { createMakoo, inject, listen } from '@makoojs/core';
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
id: 'save-tip',
|
|
134
|
-
injectAt: '#save-tip',
|
|
135
|
-
artifact: saveTipArtifact,
|
|
136
|
-
options: {
|
|
137
|
-
on: listen({
|
|
138
|
-
listenAt: '#save',
|
|
139
|
-
type: 'click',
|
|
140
|
-
callback: () => {
|
|
141
|
-
console.log('save clicked');
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
}),
|
|
146
|
-
listen({
|
|
147
|
-
id: 'escape-close',
|
|
148
|
-
listenAt: '#escape',
|
|
149
|
-
type: 'keydown',
|
|
150
|
-
callback: onEscape
|
|
151
|
-
})
|
|
33
|
+
import { createVueAdapter } from '@makoojs/vue';
|
|
34
|
+
import Panel from './Panel.vue';
|
|
35
|
+
|
|
36
|
+
const core = createMakoo();
|
|
37
|
+
core.useAdapter(createVueAdapter());
|
|
38
|
+
|
|
39
|
+
core.apply([
|
|
40
|
+
inject({
|
|
41
|
+
name: 'panel',
|
|
42
|
+
injectAt: '#sidebar',
|
|
43
|
+
adapter: 'vue',
|
|
44
|
+
component: Panel,
|
|
45
|
+
// remount after the site replaces #sidebar
|
|
46
|
+
reinject: true,
|
|
47
|
+
listeners: [
|
|
48
|
+
// attached listener: starts and stops with panel
|
|
49
|
+
listen({
|
|
50
|
+
name: 'search',
|
|
51
|
+
listenAt: '#search-form',
|
|
52
|
+
type: 'submit',
|
|
53
|
+
callback: () => console.log('Search submitted')
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
}),
|
|
57
|
+
// standalone listener: doesn't belong to any component
|
|
58
|
+
listen({
|
|
59
|
+
name: 'escape',
|
|
60
|
+
listenAt: 'body',
|
|
61
|
+
type: 'keydown',
|
|
62
|
+
callback: (event) => {
|
|
63
|
+
if ((event as KeyboardEvent).key === 'Escape') console.log('Escape pressed');
|
|
64
|
+
}
|
|
65
|
+
})
|
|
152
66
|
]);
|
|
153
67
|
```
|
|
154
68
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
```ts
|
|
158
|
-
const toolbar = started.get('toolbar');
|
|
69
|
+
### Control Injections and Read Status
|
|
159
70
|
|
|
160
|
-
|
|
161
|
-
toolbar.disableAlive();
|
|
162
|
-
toolbar.enableAlive();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
started.destroyAll();
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
`started.destroyAll()` only affects tasks created by that start batch. `makoo.destroyAll()` affects the whole runtime.
|
|
169
|
-
|
|
170
|
-
## Adapter Contract
|
|
171
|
-
|
|
172
|
-
core does not care whether an artifact is a Vue component, a React component, or another object. It only requires adapters to implement a unified mounting protocol.
|
|
71
|
+
Every injection's command handle and status handle can be obtained by name:
|
|
173
72
|
|
|
174
73
|
```ts
|
|
175
|
-
|
|
74
|
+
const panel = core.command('panel');
|
|
75
|
+
const status = core.statusHandle('panel');
|
|
176
76
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
matches(artifact): artifact is MyArtifact {
|
|
180
|
-
return isMyArtifact(artifact);
|
|
181
|
-
},
|
|
182
|
-
mount(input) {
|
|
183
|
-
return {
|
|
184
|
-
handle,
|
|
185
|
-
instance
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
unmount(input) {
|
|
189
|
-
// Clean up according to input.reason.
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
`mount(input)` receives the target host, generated mount point, artifact, task ID, selector, and task-scoped `makoo` context.
|
|
195
|
-
|
|
196
|
-
## Listener And Activity Signal
|
|
197
|
-
|
|
198
|
-
Standalone listeners use the object form of `listen()`. Their optional `id` is the task ID;
|
|
199
|
-
use it when later task lookup or control needs a stable identity. A component's `on` listener
|
|
200
|
-
is owned by that component task and does not need its own ID.
|
|
201
|
-
|
|
202
|
-
`capture` defaults to `false`. Set it to `true` to run the listener during the DOM capture phase.
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
import { createActivityStore, createMakoo, listen } from '@makoojs/core';
|
|
206
|
-
|
|
207
|
-
const enabled = createActivityStore(true);
|
|
208
|
-
const makoo = createMakoo();
|
|
209
|
-
|
|
210
|
-
makoo.start([
|
|
211
|
-
listen({
|
|
212
|
-
id: 'save-listener',
|
|
213
|
-
listenAt: '#save',
|
|
214
|
-
type: 'click',
|
|
215
|
-
callback: () => {
|
|
216
|
-
console.log('save clicked');
|
|
217
|
-
},
|
|
218
|
-
activitySignal: () => enabled
|
|
219
|
-
})
|
|
220
|
-
]);
|
|
221
|
-
|
|
222
|
-
enabled.set(false);
|
|
223
|
-
enabled.set(true);
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
## Observation Events
|
|
227
|
-
|
|
228
|
-
core emits observation events during declaration registration, starting, mounting, listener work, alive mode, DOM watching, and task status changes.
|
|
229
|
-
|
|
230
|
-
```ts
|
|
231
|
-
const off = makoo.on('artifact:mountSuccess', (event) => {
|
|
232
|
-
console.log(event.taskId, event.injectAt);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
makoo.onAny((event, ctrl) => {
|
|
236
|
-
if (event.name === 'artifact:mountFail') {
|
|
237
|
-
ctrl.stopPropagation();
|
|
238
|
-
}
|
|
77
|
+
status.subscribe(() => {
|
|
78
|
+
console.log(status.getSnapshot(), status.lastError);
|
|
239
79
|
});
|
|
240
80
|
|
|
241
|
-
|
|
81
|
+
await panel.stop();
|
|
82
|
+
panel.start();
|
|
242
83
|
```
|
|
243
84
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
- `register:start`
|
|
247
|
-
- `register:success`
|
|
248
|
-
- `start:requested`
|
|
249
|
-
- `start:taskScheduled`
|
|
250
|
-
- `artifact:mountStart`
|
|
251
|
-
- `artifact:mountSuccess`
|
|
252
|
-
- `artifact:mountFail`
|
|
253
|
-
- `listener:attached`
|
|
254
|
-
- `alive:enabled`
|
|
255
|
-
- `alive:observerStarted`
|
|
256
|
-
- `task:statusChange`
|
|
257
|
-
- `dom:targetFound`
|
|
258
|
-
- `dom:targetTimeout`
|
|
259
|
-
|
|
260
|
-
The full event name list is available from `OBSERVE_EVENT_NAMES`.
|
|
261
|
-
|
|
262
|
-
## DOMWatcher
|
|
263
|
-
|
|
264
|
-
`DOMWatcher` is core's low-level DOM observation utility. You usually do not need to use it directly because `makoo.start()` and alive mode already wrap target waiting and restoration.
|
|
265
|
-
|
|
266
|
-
## Logging And Errors
|
|
267
|
-
|
|
268
|
-
core uses `Logger` by default and prints logs with the `[Makoo]` prefix. You can pass a custom logger to `createMakoo({ logger })`.
|
|
269
|
-
|
|
270
|
-
core also exports these error-related types:
|
|
271
|
-
|
|
272
|
-
- `MakooError`
|
|
273
|
-
- `AdapterError`
|
|
274
|
-
- `TaskError`
|
|
275
|
-
- `SignalError`
|
|
276
|
-
- `ErrorCode`
|
|
277
|
-
- `MakooIssue`
|
|
278
|
-
|
|
279
|
-
## Public Exports Overview
|
|
85
|
+
## Documentation
|
|
280
86
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
| Lifecycle observation | `ObserverHub`, `OBSERVE_EVENT_NAMES`, `ObserveEvent`, `ObserveHook`, `LifecycleHookMap` |
|
|
286
|
-
| DOM observation | `DOMWatcher` |
|
|
287
|
-
| Listener signal | `createActivityStore`, `ActivitySignalSource` |
|
|
288
|
-
| Logging | `Logger`, `ILogger`, `LoggerLevel` |
|
|
289
|
-
| Errors | `MakooError`, `AdapterError`, `TaskError`, `SignalError`, `ErrorCode` |
|
|
87
|
+
- [Core Instance](https://makoojs.github.io/Makoo/api/instance): `createMakoo()` and the methods on the instance.
|
|
88
|
+
- [Declarations](https://makoojs.github.io/Makoo/api/declarations): all fields of `inject()` and `listen()`.
|
|
89
|
+
- [Commands and Status](https://makoojs.github.io/Makoo/api/status): starting, stopping, removing, and what each status value means.
|
|
90
|
+
- [Errors and Error Codes](https://makoojs.github.io/Makoo/api/errors): error categories and how to handle them.
|
package/dist/adapter/types.d.ts
CHANGED
|
@@ -1,53 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
taskId: string;
|
|
12
|
-
injectAt: string;
|
|
13
|
-
enableAlive: () => void;
|
|
14
|
-
disableAlive: () => void;
|
|
15
|
-
reset: () => void;
|
|
16
|
-
destroy: () => void;
|
|
17
|
-
on: (event: ObserveEventName, hook: ObserveHook) => () => void;
|
|
18
|
-
onTask: (event: ObserveEventName, hook: ObserveHook) => () => void;
|
|
19
|
-
off: (event: ObserveEventName, hook?: ObserveHook) => void;
|
|
20
|
-
offTask: (event?: ObserveEventName, hook?: ObserveHook) => void;
|
|
21
|
-
getLogger: () => ILogger;
|
|
22
|
-
bindListenerSignal: (source: ActivitySignalSource<boolean>) => boolean;
|
|
23
|
-
controlListener: (event: ActionEvent) => boolean;
|
|
24
|
-
};
|
|
25
|
-
export type AdapterMountInput<TArtifact = unknown> = {
|
|
26
|
-
host: HTMLElement;
|
|
27
|
-
mountPoint: HTMLElement;
|
|
28
|
-
artifact: TArtifact;
|
|
29
|
-
taskId: string;
|
|
30
|
-
injectAt: string;
|
|
31
|
-
makoo: MakooContext;
|
|
32
|
-
};
|
|
33
|
-
export type AdapterMountResult<THandle = unknown, TInstance = unknown> = {
|
|
34
|
-
handle: THandle;
|
|
35
|
-
instance?: TInstance;
|
|
36
|
-
};
|
|
37
|
-
export type AdapterUnmountInput<THandle = unknown> = {
|
|
38
|
-
host?: HTMLElement;
|
|
39
|
-
mountPoint: HTMLElement;
|
|
40
|
-
handle: THandle;
|
|
41
|
-
taskId: string;
|
|
42
|
-
injectAt: string;
|
|
43
|
-
reason: AdapterUnmountReason;
|
|
44
|
-
};
|
|
45
|
-
export interface MountAdapter<TArtifact = unknown, THandle = unknown, TInstance = unknown> {
|
|
46
|
-
name: string;
|
|
47
|
-
mount(input: AdapterMountInput<TArtifact>): AdapterMountResult<THandle, TInstance>;
|
|
48
|
-
unmount(input: AdapterUnmountInput<THandle>): void;
|
|
1
|
+
import { ComponentCommand, ComponentStatusHandle } from '../component/types';
|
|
2
|
+
import { ListenerInjection } from '../listener/types';
|
|
3
|
+
export interface AdapterMountParams<TComponent = unknown, TProps = unknown> {
|
|
4
|
+
component: TComponent;
|
|
5
|
+
command: ComponentCommand;
|
|
6
|
+
statusHandle: ComponentStatusHandle;
|
|
7
|
+
props: TProps | undefined;
|
|
8
|
+
container: HTMLElement;
|
|
9
|
+
/** Looks up a standalone listener in the owning Core Instance. */
|
|
10
|
+
globalListener(name: string): Omit<ListenerInjection, 'kind'>;
|
|
49
11
|
}
|
|
50
|
-
export interface
|
|
51
|
-
|
|
12
|
+
export interface MountAdapter<TComponent = unknown, TProps = unknown, THandle = unknown> {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
mount(params: AdapterMountParams<TComponent, TProps>): THandle;
|
|
15
|
+
unmount(mountHandle: THandle): void;
|
|
52
16
|
}
|
|
53
|
-
export type AdapterResolver = (artifact: unknown) => MountAdapter | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AdapterMountParams, MountAdapter } from '../adapter/types';
|
|
2
|
+
import { DOMObserver } from '../dom/observer';
|
|
3
|
+
import { MakooError } from '../error/MakooError';
|
|
4
|
+
import { ComponentInjection, MakooComponentDeclaration } from './types';
|
|
5
|
+
export declare function createComponent(config: MakooComponentDeclaration, adapter: MountAdapter, dom: DOMObserver, onRemoved: () => void, isDisposed: () => boolean, globalListener: AdapterMountParams['globalListener'], onDiagnostic: (name: string, error: MakooError) => void): ComponentInjection;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MakooComponentDeclaration, MakooComponentInput } from './types';
|
|
2
|
+
export declare function inject<TComponent = unknown, TProps = unknown>(input: MakooComponentInput<TComponent, TProps>): MakooComponentDeclaration<TComponent, TProps>;
|
|
3
|
+
export declare function validateComponent(input: unknown): MakooComponentDeclaration;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DOMObserver } from '../dom/observer';
|
|
2
|
+
import { MakooError } from '../error/MakooError';
|
|
3
|
+
import { AttachListener } from '../listener/attach';
|
|
4
|
+
export type ComponentMounter = {
|
|
5
|
+
mount(container: HTMLElement): unknown;
|
|
6
|
+
unmount(mountHandle: unknown): void;
|
|
7
|
+
};
|
|
8
|
+
type ComponentExecutionConfig = {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly injectAt: string;
|
|
11
|
+
readonly timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
export type ComponentExecutionControl = {
|
|
14
|
+
readonly phase: 'pending' | 'mounting' | 'mounted' | 'ended';
|
|
15
|
+
start(): void;
|
|
16
|
+
cancel(): void;
|
|
17
|
+
finish(): Promise<unknown[]>;
|
|
18
|
+
};
|
|
19
|
+
type ExecutionCallbacks = {
|
|
20
|
+
setStatus(nextStatus: 'waiting' | 'mounted'): void;
|
|
21
|
+
ended(reason: 'stopped' | 'detached' | 'failed', error?: MakooError): void;
|
|
22
|
+
};
|
|
23
|
+
export declare function createComponentExecution(config: ComponentExecutionConfig, dom: DOMObserver, mounter: ComponentMounter, attachListeners: ReadonlyMap<string, AttachListener>, callbacks: ExecutionCallbacks): ComponentExecutionControl;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MakooError } from '../error/MakooError';
|
|
2
|
+
import { ListenerStatus, MakooListenerDeclaration } from '../listener/types';
|
|
3
|
+
import { StateView } from '../state/types';
|
|
4
|
+
export interface MakooComponentInput<TComponent = unknown, TProps = unknown> {
|
|
5
|
+
name: string;
|
|
6
|
+
injectAt: string;
|
|
7
|
+
adapter: string;
|
|
8
|
+
component: TComponent;
|
|
9
|
+
props?: TProps;
|
|
10
|
+
/** DOM search budget in milliseconds. Defaults to 15000. */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Recover when the mount target or component container becomes invalid. */
|
|
13
|
+
reinject?: boolean;
|
|
14
|
+
/** Named host-page listeners owned by this component. */
|
|
15
|
+
listeners?: readonly Omit<MakooListenerDeclaration, 'reinject'>[];
|
|
16
|
+
}
|
|
17
|
+
export type MakooComponentDeclaration<TComponent = unknown, TProps = unknown> = Readonly<MakooComponentInput<TComponent, TProps> & {
|
|
18
|
+
kind: 'component';
|
|
19
|
+
}>;
|
|
20
|
+
export type ComponentStatus = 'idle' | 'waiting' | 'mounted' | 'failed';
|
|
21
|
+
export interface ComponentCommand {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
start(): void;
|
|
24
|
+
stop(): Promise<void>;
|
|
25
|
+
remove(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/** Component status handle: own stage plus attached listener status views. */
|
|
28
|
+
export interface ComponentStatusHandle extends StateView<ComponentStatus> {
|
|
29
|
+
readonly lastError: MakooError | undefined;
|
|
30
|
+
readonly attachedListenerNames: readonly string[];
|
|
31
|
+
attachedListener(name: string): StateView<ListenerStatus>;
|
|
32
|
+
}
|
|
33
|
+
export type ComponentInjection = {
|
|
34
|
+
readonly kind: 'component';
|
|
35
|
+
readonly command: ComponentCommand;
|
|
36
|
+
readonly statusHandle: ComponentStatusHandle;
|
|
37
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MountAdapter } from '../adapter/types';
|
|
2
|
+
import { ComponentCommand, ComponentInjection, ComponentStatusHandle, MakooComponentDeclaration } from '../component/types';
|
|
3
|
+
import { MakooError } from '../error/MakooError';
|
|
4
|
+
import { ListenerCommand, ListenerInjection, ListenerStatusHandle, MakooListenerDeclaration } from '../listener/types';
|
|
5
|
+
export type MakooInjectionDeclaration = MakooListenerDeclaration | MakooComponentDeclaration;
|
|
6
|
+
export type Injection = ComponentInjection | ListenerInjection;
|
|
7
|
+
export type InjectionCommand = ComponentCommand | ListenerCommand;
|
|
8
|
+
export type InjectionStatusHandle = ComponentStatusHandle | ListenerStatusHandle;
|
|
9
|
+
export type ObservationNotice = {
|
|
10
|
+
type: 'injection-removed';
|
|
11
|
+
name: string;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'instance-disposed';
|
|
14
|
+
} | {
|
|
15
|
+
type: 'diagnostic';
|
|
16
|
+
name?: string;
|
|
17
|
+
error: MakooError;
|
|
18
|
+
};
|
|
19
|
+
export type ObservationHandler = (notice: ObservationNotice) => void;
|
|
20
|
+
export interface MakooRuntime {
|
|
21
|
+
useAdapter(adapter: MountAdapter): void;
|
|
22
|
+
apply(declarations: readonly MakooInjectionDeclaration[]): void;
|
|
23
|
+
command(name: string): InjectionCommand;
|
|
24
|
+
statusHandle(name: string): InjectionStatusHandle;
|
|
25
|
+
observe(handler: ObservationHandler): () => void;
|
|
26
|
+
dispose(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DOMObserver } from './observer';
|
|
2
|
+
export declare const DEFAULT_DOM_TIMEOUT = 15000;
|
|
3
|
+
export declare function waitForElement(observer: DOMObserver, selector: string, signal: AbortSignal, timeout: number, onFound: (element: Element) => void, onTimeout: () => void, onError: (cause: unknown) => void): void;
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
readonly
|
|
1
|
+
export declare const MakooErrorCode: {
|
|
2
|
+
readonly DECLARATION_INVALID: "MAKOO_DECLARATION_INVALID";
|
|
3
|
+
readonly INJECTION_NAME_CONFLICT: "MAKOO_INJECTION_NAME_CONFLICT";
|
|
4
|
+
readonly ADAPTER_INVALID: "MAKOO_ADAPTER_INVALID";
|
|
5
|
+
readonly ADAPTER_NAME_CONFLICT: "MAKOO_ADAPTER_NAME_CONFLICT";
|
|
3
6
|
readonly ADAPTER_NOT_FOUND: "MAKOO_ADAPTER_NOT_FOUND";
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
7
|
+
readonly INJECTION_NOT_FOUND: "MAKOO_INJECTION_NOT_FOUND";
|
|
8
|
+
readonly LISTENER_NOT_FOUND: "MAKOO_LISTENER_NOT_FOUND";
|
|
9
|
+
readonly INJECTION_REMOVED: "MAKOO_INJECTION_REMOVED";
|
|
10
|
+
readonly INJECTION_CLOSED: "MAKOO_INJECTION_CLOSED";
|
|
11
|
+
readonly INSTANCE_DISPOSED: "MAKOO_INSTANCE_DISPOSED";
|
|
12
|
+
readonly TARGET_WAIT_TIMEOUT: "MAKOO_TARGET_WAIT_TIMEOUT";
|
|
13
|
+
readonly MOUNT_TARGET_DETACHED: "MAKOO_MOUNT_TARGET_DETACHED";
|
|
14
|
+
readonly MOUNT_FAILED: "MAKOO_MOUNT_FAILED";
|
|
15
|
+
readonly LISTENER_TARGET_DETACHED: "MAKOO_LISTENER_TARGET_DETACHED";
|
|
16
|
+
readonly LISTENER_BIND_FAILED: "MAKOO_LISTENER_BIND_FAILED";
|
|
17
|
+
readonly ATTACHED_LISTENER_FAILED: "MAKOO_ATTACHED_LISTENER_FAILED";
|
|
18
|
+
readonly UNMOUNT_FAILED: "MAKOO_UNMOUNT_FAILED";
|
|
19
|
+
readonly CONTAINER_REMOVE_FAILED: "MAKOO_CONTAINER_REMOVE_FAILED";
|
|
20
|
+
readonly LISTENER_UNBIND_FAILED: "MAKOO_LISTENER_UNBIND_FAILED";
|
|
21
|
+
readonly MOUNT_CLEANUP_FAILED: "MAKOO_MOUNT_CLEANUP_FAILED";
|
|
22
|
+
readonly INJECTION_CLEANUP_FAILED: "MAKOO_INJECTION_CLEANUP_FAILED";
|
|
23
|
+
readonly INSTANCE_CLEANUP_FAILED: "MAKOO_INSTANCE_CLEANUP_FAILED";
|
|
24
|
+
readonly LISTENER_CALLBACK_FAILED: "MAKOO_LISTENER_CALLBACK_FAILED";
|
|
25
|
+
readonly STATE_SUBSCRIBER_FAILED: "MAKOO_STATE_SUBSCRIBER_FAILED";
|
|
26
|
+
readonly INSTANCE_OBSERVER_FAILED: "MAKOO_INSTANCE_OBSERVER_FAILED";
|
|
18
27
|
};
|
|
19
|
-
export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ZodError } from 'zod';
|
|
2
|
+
type MakooErrorOptions = {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly cause?: unknown;
|
|
4
5
|
};
|
|
5
|
-
export type MakooErrorContextValue = string | number | boolean | null;
|
|
6
|
-
export type MakooErrorContext = Record<string, MakooErrorContextValue>;
|
|
7
6
|
export declare class MakooError extends Error {
|
|
8
7
|
readonly code: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
readonly
|
|
13
|
-
constructor(
|
|
14
|
-
withContext(context: MakooErrorContext): this;
|
|
8
|
+
constructor(message: string, options: MakooErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
export declare class MakooAggregateError extends MakooError {
|
|
11
|
+
readonly errors: readonly unknown[];
|
|
12
|
+
constructor(errors: readonly unknown[], message: string, options: MakooErrorOptions);
|
|
15
13
|
}
|
|
14
|
+
export declare function declaredName(input: unknown): string | undefined;
|
|
15
|
+
export declare function validationError(summary: string, code: string, error: ZodError): MakooError;
|
|
16
|
+
export declare function stateSubscriberFailed(owner: string, cause: unknown): MakooError;
|
|
17
|
+
export declare function instanceObserverFailed(cause: unknown): MakooError;
|
|
18
|
+
export declare function injectionCleanupFailed(name: string, errors: readonly unknown[]): MakooAggregateError;
|
|
19
|
+
export {};
|