@makoojs/core 0.3.1 → 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 +78 -706
- package/README.md +78 -702
- 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 -31
- package/dist/error/MakooError.d.ts +15 -6
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +10 -19
- package/dist/index.js +801 -1655
- 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/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,714 +1,90 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Returns
|
|
67
|
-
|
|
68
|
-
Returns `MakooRuntime`:
|
|
69
|
-
|
|
70
|
-
| Method | Returns | Description |
|
|
71
|
-
| --- | --- | --- |
|
|
72
|
-
| `start(tasks)` | `StartedTasks` | Registers and starts a batch of `MakooTaskDeclaration`; an empty array throws `TaskError` |
|
|
73
|
-
| `reset(taskId)` | `void` | Resets a task and releases its current resources |
|
|
74
|
-
| `destroy(taskId)` | `void` | Destroys and removes a task |
|
|
75
|
-
| `resetAll()` | `void` | Resets every task in the runtime |
|
|
76
|
-
| `destroyAll()` | `void` | Destroys every task in the runtime |
|
|
77
|
-
| `enableAlive(taskId)` | `void` | Enables alive observation for a component task |
|
|
78
|
-
| `disableAlive(taskId)` | `void` | Disables alive observation for a component task |
|
|
79
|
-
| `on(event, hook)` | `() => void` | Subscribes to an event and returns an unsubscribe function |
|
|
80
|
-
| `onTask(taskId, event, hook)` | `() => void` | Subscribes to an event for one task and returns an unsubscribe function |
|
|
81
|
-
| `onAny(hook)` | `() => void` | Subscribes to all events and returns an unsubscribe function |
|
|
82
|
-
| `off(event, hook?)` | `void` | Removes one or all hooks for an event |
|
|
83
|
-
| `offTask(taskId, event?, hook?)` | `void` | Removes task hooks |
|
|
84
|
-
| `offAny(hook)` | `void` | Removes a hook registered with `onAny()` |
|
|
85
|
-
| `getLogger()` | `ILogger` | Returns the current logger |
|
|
86
|
-
|
|
87
|
-
Duplicate task IDs are skipped and are not included in the `StartedTasks.tasks` returned by that `start()` call.
|
|
88
|
-
|
|
89
|
-
### Example
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
const makoo = createMakoo({
|
|
93
|
-
adapters: [adapter]
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const started = makoo.start([
|
|
97
|
-
inject({ injectAt: '#app', artifact })
|
|
1
|
+
# @makoojs/core
|
|
2
|
+
|
|
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>
|
|
7
|
+
|
|
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>
|
|
13
|
+
|
|
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.
|
|
15
|
+
|
|
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).
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm add @makoojs/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> Projects created with `pnpm dlx @makoojs/create-makoo` already include it; no separate installation is needed.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Declare Components and Listeners
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createMakoo, inject, listen } from '@makoojs/core';
|
|
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
|
+
})
|
|
98
66
|
]);
|
|
99
67
|
```
|
|
100
68
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Creates a component task declaration. `inject()` does not register or start the task; pass its result to `MakooRuntime.start()`.
|
|
104
|
-
|
|
105
|
-
### Type
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
function inject<TArtifact>(
|
|
109
|
-
input: MakooInjectionInput<TArtifact>
|
|
110
|
-
): MakooInjectionDeclaration<TArtifact>;
|
|
111
|
-
```
|
|
69
|
+
### Control Injections and Read Status
|
|
112
70
|
|
|
113
|
-
|
|
71
|
+
Every injection's command handle and status handle can be obtained by name:
|
|
114
72
|
|
|
115
73
|
```ts
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
injectAt: string;
|
|
119
|
-
artifact: TArtifact;
|
|
120
|
-
options?: ArtifactOptions;
|
|
121
|
-
};
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
When `id` is omitted, the runtime derives a task ID from the artifact and `injectAt`.
|
|
125
|
-
|
|
126
|
-
#### `ArtifactOptions`
|
|
127
|
-
|
|
128
|
-
| Field | Type | Description |
|
|
129
|
-
| --- | --- | --- |
|
|
130
|
-
| `alive` | `boolean` | Attempts to mount again after the target is replaced |
|
|
131
|
-
| `scope` | `'local' \| 'global'` | Observation scope used by alive mode |
|
|
132
|
-
| `timeout` | `number` | Milliseconds to wait for the target element |
|
|
133
|
-
| `on` | `MakooListenerDeclaration` | Event listener registered with the component |
|
|
134
|
-
| `hooks` | `LifecycleHookMap` | Lifecycle hooks for this task |
|
|
135
|
-
|
|
136
|
-
### Returns
|
|
74
|
+
const panel = core.command('panel');
|
|
75
|
+
const status = core.statusHandle('panel');
|
|
137
76
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
### Example
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
const declaration = inject({
|
|
144
|
-
id: 'settings-panel',
|
|
145
|
-
injectAt: '#settings',
|
|
146
|
-
artifact: settingsPanel,
|
|
147
|
-
options: {
|
|
148
|
-
alive: true,
|
|
149
|
-
scope: 'global'
|
|
150
|
-
}
|
|
77
|
+
status.subscribe(() => {
|
|
78
|
+
console.log(status.getSnapshot(), status.lastError);
|
|
151
79
|
});
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## `listen()`
|
|
155
|
-
|
|
156
|
-
Creates a listener task declaration. `listen()` does not register or start the task. Pass its result to `MakooRuntime.start()` or use it as `ArtifactOptions.on`.
|
|
157
|
-
|
|
158
|
-
### Type
|
|
159
80
|
|
|
160
|
-
|
|
161
|
-
|
|
81
|
+
await panel.stop();
|
|
82
|
+
panel.start();
|
|
162
83
|
```
|
|
163
84
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
```ts
|
|
167
|
-
type MakooListenerInput = {
|
|
168
|
-
id?: string;
|
|
169
|
-
listenAt: string;
|
|
170
|
-
type: string;
|
|
171
|
-
callback: EventListener;
|
|
172
|
-
capture?: boolean;
|
|
173
|
-
activitySignal?: () => ActivitySignalSource<boolean>;
|
|
174
|
-
};
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
When `id` is omitted, the runtime uses `listener-${listenAt}-${type}` as the task ID.
|
|
178
|
-
`capture` selects the DOM capture phase when `true`; it defaults to the browser behavior of
|
|
179
|
-
`false` (the bubbling phase). Makoo continues to manage the listener's abort signal internally.
|
|
180
|
-
|
|
181
|
-
### Returns
|
|
182
|
-
|
|
183
|
-
Returns `MakooListenerDeclaration`. It can be started as a standalone task or assigned to `ArtifactOptions.on`.
|
|
85
|
+
## Documentation
|
|
184
86
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
id: 'escape-close',
|
|
190
|
-
listenAt: 'body',
|
|
191
|
-
type: 'keydown',
|
|
192
|
-
capture: true,
|
|
193
|
-
callback: onEscape
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## `createObserverHub()`
|
|
198
|
-
|
|
199
|
-
Creates an event hub. `logger` defaults to `new Logger()`.
|
|
200
|
-
|
|
201
|
-
### Type
|
|
202
|
-
|
|
203
|
-
```ts
|
|
204
|
-
function createObserverHub(logger?: ILogger): ObserverHub;
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### Parameters
|
|
208
|
-
|
|
209
|
-
- `logger`: optional `ILogger`. A `Logger` is created when omitted.
|
|
210
|
-
|
|
211
|
-
### Returns
|
|
212
|
-
|
|
213
|
-
Returns `ObserverHub`:
|
|
214
|
-
|
|
215
|
-
| Method | Returns | Description |
|
|
216
|
-
| --- | --- | --- |
|
|
217
|
-
| `on(event, hook)` | `() => void` | Registers a hook for an event |
|
|
218
|
-
| `onTask(taskId, event, hook)` | `() => void` | Registers a task-specific hook |
|
|
219
|
-
| `onAny(hook)` | `() => void` | Registers a hook for every event |
|
|
220
|
-
| `off(event, hook?)` | `void` | Removes event hooks |
|
|
221
|
-
| `offTask(taskId, event?, hook?)` | `void` | Removes task hooks |
|
|
222
|
-
| `offAny(hook)` | `void` | Removes a global hook |
|
|
223
|
-
| `clear()` | `void` | Removes all hooks |
|
|
224
|
-
| `hasHooks(event?)` | `boolean` | Checks whether any or a specific event has hooks |
|
|
225
|
-
| `emit(event)` | `void` | Emits an event |
|
|
226
|
-
| `emitOnTask(taskId, event)` | `void` | Emits an event for a task |
|
|
227
|
-
|
|
228
|
-
Task events run task hooks, same-name event hooks, and `onAny()` hooks in that order. `stopPropagation()` prevents the next group from running. `stopImmediatePropagation()` also stops the remaining hooks in the current group. If a hook throws, the error is logged and the other hooks continue.
|
|
229
|
-
|
|
230
|
-
### Example
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
const observer = createObserverHub();
|
|
234
|
-
const off = observer.on('artifact:mountSuccess', (event) => {
|
|
235
|
-
console.log(event.taskId);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
off();
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## `createActivityStore()`
|
|
242
|
-
|
|
243
|
-
Creates readable, subscribable, and writable state.
|
|
244
|
-
|
|
245
|
-
### Type
|
|
246
|
-
|
|
247
|
-
```ts
|
|
248
|
-
function createActivityStore<T>(initialValue: T): {
|
|
249
|
-
get(): T;
|
|
250
|
-
subscribe(listener: (value: T) => void): SignalUnsubscribe;
|
|
251
|
-
set(value: T): void;
|
|
252
|
-
update(updater: (value: T) => T): void;
|
|
253
|
-
};
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
### Parameters
|
|
257
|
-
|
|
258
|
-
- `initialValue`: the initial state value.
|
|
259
|
-
|
|
260
|
-
### Returns
|
|
261
|
-
|
|
262
|
-
Returns an object with `get()`, `subscribe()`, `set()`, and `update()`.
|
|
263
|
-
|
|
264
|
-
### Details
|
|
265
|
-
|
|
266
|
-
`set()` and `update()` compare the new and current values with `Object.is()` and do not notify subscribers when the value is unchanged.
|
|
267
|
-
|
|
268
|
-
### Example
|
|
269
|
-
|
|
270
|
-
```ts
|
|
271
|
-
const active = createActivityStore(true);
|
|
272
|
-
const unsubscribe = active.subscribe((value) => {
|
|
273
|
-
console.log(value);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
active.set(false);
|
|
277
|
-
active.update((value) => !value);
|
|
278
|
-
unsubscribe();
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
## `DOMWatcher`
|
|
282
|
-
|
|
283
|
-
### `DOMWatcher.onDomReady()`
|
|
284
|
-
|
|
285
|
-
Finds an existing matching element and observes subsequently added elements with `MutationObserver`.
|
|
286
|
-
|
|
287
|
-
#### Type
|
|
288
|
-
|
|
289
|
-
```ts
|
|
290
|
-
DOMWatcher.onDomReady(
|
|
291
|
-
selector: string,
|
|
292
|
-
callback: (element: HTMLElement, observer?: MutationObserver) => void,
|
|
293
|
-
root: Document | HTMLElement = document,
|
|
294
|
-
options: { once: boolean; timeout?: number } | { once?: boolean; timeout: number },
|
|
295
|
-
runtime?: {
|
|
296
|
-
logger: ILogger;
|
|
297
|
-
emit: (name:
|
|
298
|
-
| 'dom:targetFound'
|
|
299
|
-
| 'dom:targetTimeout'
|
|
300
|
-
| 'dom:targetRemoved'
|
|
301
|
-
| 'dom:targetRestored'
|
|
302
|
-
) => void;
|
|
303
|
-
}
|
|
304
|
-
): () => void;
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
#### Details
|
|
308
|
-
|
|
309
|
-
- Calls `callback` when an element is found.
|
|
310
|
-
- Stops after the first match when `once: true`.
|
|
311
|
-
- Stops when `timeout` expires.
|
|
312
|
-
- Returns a function that stops observation.
|
|
313
|
-
|
|
314
|
-
### `DOMWatcher.onDomAlive()`
|
|
315
|
-
|
|
316
|
-
Observes removal of `target` and calls `onRestore` when a new element matching `selector` appears.
|
|
317
|
-
|
|
318
|
-
#### Type
|
|
319
|
-
|
|
320
|
-
```ts
|
|
321
|
-
DOMWatcher.onDomAlive(
|
|
322
|
-
target: HTMLElement,
|
|
323
|
-
selector: string,
|
|
324
|
-
onRemove: () => void,
|
|
325
|
-
onRestore: (element: HTMLElement, observer?: MutationObserver) => void,
|
|
326
|
-
root: Document | HTMLElement = document,
|
|
327
|
-
options: { once: boolean; timeout?: number } | { once?: boolean; timeout: number },
|
|
328
|
-
runtime?: {
|
|
329
|
-
logger: ILogger;
|
|
330
|
-
emit: (name:
|
|
331
|
-
| 'dom:targetFound'
|
|
332
|
-
| 'dom:targetTimeout'
|
|
333
|
-
| 'dom:targetRemoved'
|
|
334
|
-
| 'dom:targetRestored'
|
|
335
|
-
) => void;
|
|
336
|
-
}
|
|
337
|
-
): () => void;
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
#### Returns
|
|
341
|
-
|
|
342
|
-
Returns a function that stops both removal and restoration observation.
|
|
343
|
-
|
|
344
|
-
## `Logger`
|
|
345
|
-
|
|
346
|
-
Makoo's default logger implementation.
|
|
347
|
-
|
|
348
|
-
### Type
|
|
349
|
-
|
|
350
|
-
```ts
|
|
351
|
-
class Logger implements ILogger {
|
|
352
|
-
static readonly PREFIX = '[Makoo]';
|
|
353
|
-
|
|
354
|
-
constructor(level?: LoggerLevel);
|
|
355
|
-
setLevel(level: LoggerLevel): void;
|
|
356
|
-
getLevel(): LoggerLevel;
|
|
357
|
-
log(level: LoggerLevel, message: string, ...args: unknown[]): void;
|
|
358
|
-
debug(message: string, ...args: unknown[]): void;
|
|
359
|
-
info(message: string, ...args: unknown[]): void;
|
|
360
|
-
warn(message: string, ...args: unknown[]): void;
|
|
361
|
-
error(message: string, ...args: unknown[]): void;
|
|
362
|
-
}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
The default level is `info`. Level order is `debug`, `info`, `warn`, and `error`; messages below the current level are not emitted.
|
|
366
|
-
|
|
367
|
-
## Error classes
|
|
368
|
-
|
|
369
|
-
### `MakooError`
|
|
370
|
-
|
|
371
|
-
```ts
|
|
372
|
-
class MakooError extends Error {
|
|
373
|
-
readonly code: string;
|
|
374
|
-
readonly issues: MakooIssue[];
|
|
375
|
-
override readonly cause?: Error;
|
|
376
|
-
|
|
377
|
-
constructor(
|
|
378
|
-
message: string,
|
|
379
|
-
issues?: MakooIssue[],
|
|
380
|
-
code?: string,
|
|
381
|
-
cause?: Error
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
`message` receives a `[makoo]` prefix and includes the `issues` and `cause` error chain.
|
|
387
|
-
|
|
388
|
-
### `AdapterError`
|
|
389
|
-
|
|
390
|
-
```ts
|
|
391
|
-
class AdapterError extends MakooError;
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
Default code: `ErrorCode.ADAPTER_NOT_FOUND`.
|
|
395
|
-
|
|
396
|
-
### `SignalError`
|
|
397
|
-
|
|
398
|
-
```ts
|
|
399
|
-
class SignalError extends MakooError;
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
Default code: `ErrorCode.TASK_SIGNAL_INVALID`.
|
|
403
|
-
|
|
404
|
-
### `TaskError`
|
|
405
|
-
|
|
406
|
-
```ts
|
|
407
|
-
class TaskError extends MakooError;
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
Default code: `ErrorCode.TASK_NO_REGISTERED`.
|
|
411
|
-
|
|
412
|
-
## Constants
|
|
413
|
-
|
|
414
|
-
### `Action`
|
|
415
|
-
|
|
416
|
-
```ts
|
|
417
|
-
enum Action {
|
|
418
|
-
OPEN = 'OPEN',
|
|
419
|
-
CLOSE = 'CLOSE'
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
type ActionEvent = `${Action}`;
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### `OBSERVE_EVENT_NAMES`
|
|
426
|
-
|
|
427
|
-
```ts
|
|
428
|
-
const OBSERVE_EVENT_NAMES = [
|
|
429
|
-
'register:start',
|
|
430
|
-
'register:success',
|
|
431
|
-
'register:duplicate',
|
|
432
|
-
'register:error',
|
|
433
|
-
'start:requested',
|
|
434
|
-
'start:taskScheduled',
|
|
435
|
-
'start:taskSkipped',
|
|
436
|
-
'artifact:mountStart',
|
|
437
|
-
'artifact:mountSuccess',
|
|
438
|
-
'artifact:mountFail',
|
|
439
|
-
'listener:attached',
|
|
440
|
-
'listener:detached',
|
|
441
|
-
'listener:attachFail',
|
|
442
|
-
'alive:enabled',
|
|
443
|
-
'alive:disabled',
|
|
444
|
-
'alive:observerStarted',
|
|
445
|
-
'alive:observerStopped',
|
|
446
|
-
'task:targetReady',
|
|
447
|
-
'task:statusChange',
|
|
448
|
-
'task:beforeReset',
|
|
449
|
-
'task:afterReset',
|
|
450
|
-
'task:beforeDestroy',
|
|
451
|
-
'task:afterDestroy',
|
|
452
|
-
'signal:watcherReleased',
|
|
453
|
-
'resource:listenerReleased',
|
|
454
|
-
'artifact:unmounted',
|
|
455
|
-
'dom:targetFound',
|
|
456
|
-
'dom:targetTimeout',
|
|
457
|
-
'dom:targetRemoved',
|
|
458
|
-
'dom:targetRestored'
|
|
459
|
-
] as const;
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### `ErrorCode`
|
|
463
|
-
|
|
464
|
-
| Field | Value |
|
|
465
|
-
| --- | --- |
|
|
466
|
-
| `UNKNOWN` | `MAKOO_UNKNOWN` |
|
|
467
|
-
| `ADAPTER_NOT_FOUND` | `MAKOO_ADAPTER_NOT_FOUND` |
|
|
468
|
-
| `ADAPTER_MOUNT_FAIL` | `MAKOO_ADAPTER_MOUNT_FAIL` |
|
|
469
|
-
| `ADAPTER_UNMOUNT_FAIL` | `MAKOO_ADAPTER_UNMOUNT_FAIL` |
|
|
470
|
-
| `TASK_NO_REGISTERED` | `MAKOO_TASK_NO_REGISTERED` |
|
|
471
|
-
| `TASK_NOT_FOUND` | `MAKOO_TASK_NOT_FOUND` |
|
|
472
|
-
| `TASK_INJECT_FAIL` | `MAKOO_TASK_INJECT_FAIL` |
|
|
473
|
-
| `TASK_ALREADY_MOUNTED` | `MAKOO_TASK_ALREADY_MOUNTED` |
|
|
474
|
-
| `TASK_TARGET_DETACHED` | `MAKOO_TASK_TARGET_DETACHED` |
|
|
475
|
-
| `TASK_LISTENER_ATTACH_FAIL` | `MAKOO_TASK_LISTENER_ATTACH_FAIL` |
|
|
476
|
-
| `TASK_SIGNAL_INVALID` | `MAKOO_TASK_SIGNAL_INVALID` |
|
|
477
|
-
| `TASK_SIGNAL_BIND_FAIL` | `MAKOO_TASK_SIGNAL_BIND_FAIL` |
|
|
478
|
-
| `CLI_SOURCE_DIR_NOT_FOUND` | `MAKOO_CLI_SOURCE_DIR_NOT_FOUND` |
|
|
479
|
-
| `CLI_MANIFEST_LOAD_FAIL` | `MAKOO_CLI_MANIFEST_LOAD_FAIL` |
|
|
480
|
-
| `CLI_MODULE_MANIFEST_LOAD_FAIL` | `MAKOO_CLI_MODULE_MANIFEST_LOAD_FAIL` |
|
|
481
|
-
| `CLI_MANIFEST_NOT_FOUND` | `MAKOO_CLI_MANIFEST_NOT_FOUND` |
|
|
482
|
-
| `CLI_MANIFEST_BINDING_NOT_FOUND` | `MAKOO_CLI_MANIFEST_BINDING_NOT_FOUND` |
|
|
483
|
-
| `CLI_MANIFEST_IMPORT_NOT_FOUND` | `MAKOO_CLI_MANIFEST_IMPORT_NOT_FOUND` |
|
|
484
|
-
| `CLI_FUNCTION_SERIALIZATION_UNSUPPORTED` | `MAKOO_CLI_FUNCTION_SERIALIZATION_UNSUPPORTED` |
|
|
485
|
-
| `CLI_NO_ENABLED_TASKS` | `MAKOO_CLI_NO_ENABLED_TASKS` |
|
|
486
|
-
| `CLI_COMPONENT_NOT_FOUND` | `MAKOO_CLI_COMPONENT_NOT_FOUND` |
|
|
487
|
-
| `CLI_CONFIG_INVALID` | `MAKOO_CLI_CONFIG_INVALID` |
|
|
488
|
-
| `CLI_UNKNOWN_FRAMEWORK` | `MAKOO_CLI_UNKNOWN_FRAMEWORK` |
|
|
489
|
-
| `CLI_UNSUPPORTED_FRAMEWORK` | `MAKOO_CLI_UNSUPPORTED_FRAMEWORK` |
|
|
490
|
-
| `CLI_MODULE_ALREADY_EXISTS` | `MAKOO_CLI_MODULE_ALREADY_EXISTS` |
|
|
491
|
-
| `CLI_MANIFEST_VALIDATION_FAIL` | `MAKOO_CLI_MANIFEST_VALIDATION_FAIL` |
|
|
492
|
-
| `CLI_VITE_CONFIG_NOT_FOUND` | `MAKOO_CLI_VITE_CONFIG_NOT_FOUND` |
|
|
493
|
-
| `CLI_PLUGIN_NOT_FOUND` | `MAKOO_CLI_PLUGIN_NOT_FOUND` |
|
|
494
|
-
| `CLI_RUNTIME_SETUP_NOT_FOUND` | `MAKOO_CLI_RUNTIME_SETUP_NOT_FOUND` |
|
|
495
|
-
|
|
496
|
-
## Adapter types
|
|
497
|
-
|
|
498
|
-
### `MountAdapter`
|
|
499
|
-
|
|
500
|
-
```ts
|
|
501
|
-
interface MountAdapter<TArtifact = unknown, THandle = unknown, TInstance = unknown> {
|
|
502
|
-
name: string;
|
|
503
|
-
mount(input: AdapterMountInput<TArtifact>): AdapterMountResult<THandle, TInstance>;
|
|
504
|
-
unmount(input: AdapterUnmountInput<THandle>): void;
|
|
505
|
-
}
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
### `ResolvableMountAdapter`
|
|
509
|
-
|
|
510
|
-
```ts
|
|
511
|
-
interface ResolvableMountAdapter<TArtifact = unknown, THandle = unknown, TInstance = unknown>
|
|
512
|
-
extends MountAdapter<TArtifact, THandle, TInstance> {
|
|
513
|
-
matches(artifact: unknown): artifact is TArtifact;
|
|
514
|
-
}
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
### `AdapterMountInput`
|
|
518
|
-
|
|
519
|
-
| Field | Type |
|
|
520
|
-
| --- | --- |
|
|
521
|
-
| `host` | `HTMLElement` |
|
|
522
|
-
| `mountPoint` | `HTMLElement` |
|
|
523
|
-
| `artifact` | `TArtifact` |
|
|
524
|
-
| `taskId` | `string` |
|
|
525
|
-
| `injectAt` | `string` |
|
|
526
|
-
| `makoo` | `MakooContext` |
|
|
527
|
-
|
|
528
|
-
### `AdapterMountResult`
|
|
529
|
-
|
|
530
|
-
```ts
|
|
531
|
-
type AdapterMountResult<THandle = unknown, TInstance = unknown> = {
|
|
532
|
-
handle: THandle;
|
|
533
|
-
instance?: TInstance;
|
|
534
|
-
};
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
### `AdapterUnmountInput`
|
|
538
|
-
|
|
539
|
-
| Field | Type |
|
|
540
|
-
| --- | --- |
|
|
541
|
-
| `host` | `HTMLElement \| undefined` |
|
|
542
|
-
| `mountPoint` | `HTMLElement` |
|
|
543
|
-
| `handle` | `THandle` |
|
|
544
|
-
| `taskId` | `string` |
|
|
545
|
-
| `injectAt` | `string` |
|
|
546
|
-
| `reason` | `AdapterUnmountReason` |
|
|
547
|
-
|
|
548
|
-
```ts
|
|
549
|
-
type AdapterUnmountReason = 'destroy' | 'reset' | 'remount' | 'manual';
|
|
550
|
-
type AdapterResolver = (artifact: unknown) => MountAdapter | undefined;
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
### `MakooContext`
|
|
554
|
-
|
|
555
|
-
```ts
|
|
556
|
-
type MakooContext = {
|
|
557
|
-
taskId: string;
|
|
558
|
-
injectAt: string;
|
|
559
|
-
enableAlive(): void;
|
|
560
|
-
disableAlive(): void;
|
|
561
|
-
reset(): void;
|
|
562
|
-
destroy(): void;
|
|
563
|
-
on(event: ObserveEventName, hook: ObserveHook): () => void;
|
|
564
|
-
onTask(event: ObserveEventName, hook: ObserveHook): () => void;
|
|
565
|
-
off(event: ObserveEventName, hook?: ObserveHook): void;
|
|
566
|
-
offTask(event?: ObserveEventName, hook?: ObserveHook): void;
|
|
567
|
-
getLogger(): ILogger;
|
|
568
|
-
bindListenerSignal(source: ActivitySignalSource<boolean>): boolean;
|
|
569
|
-
controlListener(event: ActionEvent): boolean;
|
|
570
|
-
};
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
## Task types
|
|
574
|
-
|
|
575
|
-
```ts
|
|
576
|
-
type MakooDefaults = {
|
|
577
|
-
alive: boolean;
|
|
578
|
-
scope: 'local' | 'global';
|
|
579
|
-
timeout: number;
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
type MakooInjectionDeclaration<TArtifact = unknown> = {
|
|
583
|
-
kind: 'component';
|
|
584
|
-
id?: string;
|
|
585
|
-
injectAt: string;
|
|
586
|
-
artifact: TArtifact;
|
|
587
|
-
options?: ArtifactOptions;
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
type MakooListenerDeclaration = {
|
|
591
|
-
kind: 'listener';
|
|
592
|
-
id?: string;
|
|
593
|
-
listenAt: string;
|
|
594
|
-
event: string;
|
|
595
|
-
type: string;
|
|
596
|
-
callback: EventListener;
|
|
597
|
-
capture?: boolean;
|
|
598
|
-
activitySignal?: () => ActivitySignalSource<boolean>;
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
type MakooTaskDeclaration<TArtifact = unknown> =
|
|
602
|
-
| MakooInjectionDeclaration<TArtifact>
|
|
603
|
-
| MakooListenerDeclaration;
|
|
604
|
-
```
|
|
605
|
-
|
|
606
|
-
### `StartedTasks`
|
|
607
|
-
|
|
608
|
-
```ts
|
|
609
|
-
type StartedComponentTask = {
|
|
610
|
-
kind: 'component';
|
|
611
|
-
taskId: string;
|
|
612
|
-
enableAlive(): void;
|
|
613
|
-
disableAlive(): void;
|
|
614
|
-
reset(): void;
|
|
615
|
-
destroy(): void;
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
type StartedListenerTask = {
|
|
619
|
-
kind: 'listener';
|
|
620
|
-
taskId: string;
|
|
621
|
-
open(): boolean;
|
|
622
|
-
close(): boolean;
|
|
623
|
-
destroy(): void;
|
|
624
|
-
};
|
|
625
|
-
|
|
626
|
-
type StartedTask = StartedComponentTask | StartedListenerTask;
|
|
627
|
-
|
|
628
|
-
type StartedTasks = {
|
|
629
|
-
tasks: StartedTask[];
|
|
630
|
-
get(taskId: string): StartedTask | undefined;
|
|
631
|
-
resetAll(): void;
|
|
632
|
-
destroyAll(): void;
|
|
633
|
-
};
|
|
634
|
-
```
|
|
635
|
-
|
|
636
|
-
`StartedTasks.resetAll()` and `StartedTasks.destroyAll()` only affect the task batch returned by that `start()` call.
|
|
637
|
-
|
|
638
|
-
### `InjectionConfig`
|
|
639
|
-
|
|
640
|
-
```ts
|
|
641
|
-
type InjectionConfig = MakooDefaults & {
|
|
642
|
-
logger: ILogger;
|
|
643
|
-
observer?: ObserverHub;
|
|
644
|
-
hooks?: LifecycleHookMap;
|
|
645
|
-
};
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
## Observer types
|
|
649
|
-
|
|
650
|
-
```ts
|
|
651
|
-
type ObserveEventName = (typeof OBSERVE_EVENT_NAMES)[number];
|
|
652
|
-
|
|
653
|
-
type ObserveEvent = {
|
|
654
|
-
name: ObserveEventName;
|
|
655
|
-
ts: number;
|
|
656
|
-
taskId?: string;
|
|
657
|
-
kind?: 'component' | 'listener';
|
|
658
|
-
injectAt?: string;
|
|
659
|
-
status?: 'idle' | 'pending' | 'active';
|
|
660
|
-
durationMs?: number;
|
|
661
|
-
error?: unknown;
|
|
662
|
-
preStatus?: 'idle' | 'pending' | 'active';
|
|
663
|
-
meta?: Record<string, unknown>;
|
|
664
|
-
};
|
|
665
|
-
|
|
666
|
-
type ObserveHook = (
|
|
667
|
-
event: ObserveEvent,
|
|
668
|
-
ctrl: {
|
|
669
|
-
stopPropagation(): void;
|
|
670
|
-
stopImmediatePropagation(): void;
|
|
671
|
-
}
|
|
672
|
-
) => void;
|
|
673
|
-
|
|
674
|
-
type LifecycleHookMap = Partial<
|
|
675
|
-
Record<ObserveEventName, ObserveHook | ObserveHook[]>
|
|
676
|
-
>;
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
## Signal types
|
|
680
|
-
|
|
681
|
-
```ts
|
|
682
|
-
type SignalUnsubscribe = (() => void) | { unsubscribe(): void };
|
|
683
|
-
|
|
684
|
-
type ActivitySignalSource<T = boolean> = {
|
|
685
|
-
get(): T;
|
|
686
|
-
subscribe(listener: (value: T) => void): SignalUnsubscribe;
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
type ActivitySignalSubscribable<T = boolean> = ActivitySignalSource<T>;
|
|
690
|
-
```
|
|
691
|
-
|
|
692
|
-
## Logger types
|
|
693
|
-
|
|
694
|
-
```ts
|
|
695
|
-
type LoggerLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
696
|
-
|
|
697
|
-
interface ILogger {
|
|
698
|
-
info(message: string, ...args: unknown[]): void;
|
|
699
|
-
warn(message: string, ...args: unknown[]): void;
|
|
700
|
-
error(message: string, ...args: unknown[]): void;
|
|
701
|
-
debug(message: string, ...args: unknown[]): void;
|
|
702
|
-
}
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
## Error types
|
|
706
|
-
|
|
707
|
-
```ts
|
|
708
|
-
type MakooIssue = {
|
|
709
|
-
path: string;
|
|
710
|
-
message: string;
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
714
|
-
```
|
|
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.
|