@makoojs/core 0.1.0 → 0.2.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 +104 -178
- package/README.md +89 -163
- package/dist/Makoo/createMakoo.d.ts +4 -0
- package/dist/Makoo/types.d.ts +89 -0
- package/dist/Task/TaskContext.d.ts +4 -84
- package/dist/Task/TaskLifeCycle.d.ts +7 -18
- package/dist/Task/TaskRegister.d.ts +15 -16
- package/dist/Task/TaskRunner.d.ts +6 -19
- package/dist/Task/types.d.ts +2 -6
- package/dist/adapter/Adapter.d.ts +2 -6
- package/dist/adapter/types.d.ts +5 -1
- package/dist/error/ErrorCode.d.ts +7 -0
- package/dist/error/SignalError.d.ts +4 -0
- package/dist/hooks/ObserverHub.d.ts +2 -20
- package/dist/hooks/types.d.ts +13 -1
- package/dist/hooks/util.d.ts +1 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1214 -1125
- package/dist/payload/buildRunObservePayload.d.ts +7 -7
- package/dist/runtime/createRuntime.d.ts +3 -0
- package/dist/runtime/types.d.ts +13 -0
- package/dist/signal/observeActivitySignal.d.ts +0 -4
- package/package.json +1 -1
- package/dist/Injector/Injector.d.ts +0 -48
- package/dist/Injector/types.d.ts +0 -29
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @makoojs/core
|
|
2
2
|
|
|
3
|
-
`@makoojs/core` is Makoo's framework-agnostic runtime core. It
|
|
3
|
+
`@makoojs/core` is Makoo's framework-agnostic runtime core. It declares injection tasks, starts task batches, waits for target DOM nodes, mounts artifacts, manages alive reinjection, binds event listeners, and provides lifecycle observation, logging, and error infrastructure.
|
|
4
4
|
|
|
5
|
-
Projects should usually start with `@makoojs/cli`.
|
|
5
|
+
Projects should usually start with `@makoojs/cli`. Use core directly when you want to integrate Makoo's runtime without the CLI-generated entry.
|
|
6
6
|
|
|
7
7
|
> [!NOTE]
|
|
8
8
|
> `@makoojs/core` is the parent package for the rest of Makoo. Other packages depend on its types or runtime capabilities either directly or indirectly.
|
|
@@ -10,9 +10,9 @@ Projects should usually start with `@makoojs/cli`. The CLI provides the Vite plu
|
|
|
10
10
|
## Use Cases
|
|
11
11
|
|
|
12
12
|
- Write a custom `ResolvableMountAdapter` so Makoo can mount a new artifact type.
|
|
13
|
-
- Create
|
|
13
|
+
- Create a Makoo runtime with `createMakoo()` and start explicit task declarations.
|
|
14
14
|
- Listen to injection lifecycle events for debugging, analytics, error reporting, or visual devtools.
|
|
15
|
-
- Use low-level tools such as `DOMWatcher` and `createActivityStore`
|
|
15
|
+
- Use low-level tools such as `DOMWatcher` and `createActivityStore` for custom integrations.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -24,10 +24,12 @@ pnpm add @makoojs/core
|
|
|
24
24
|
|
|
25
25
|
## Minimal Runtime Example
|
|
26
26
|
|
|
27
|
-
The following example shows the basic core flow: create an `Injector`, register an adapter, register an artifact, then call `run()` to wait for the target DOM node and mount it.
|
|
28
|
-
|
|
29
27
|
```ts
|
|
30
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
createMakoo,
|
|
30
|
+
inject,
|
|
31
|
+
type ResolvableMountAdapter
|
|
32
|
+
} from '@makoojs/core';
|
|
31
33
|
|
|
32
34
|
type TextArtifact = {
|
|
33
35
|
kind: 'text';
|
|
@@ -55,38 +57,69 @@ const textAdapter: ResolvableMountAdapter<TextArtifact, HTMLElement> = {
|
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
59
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const makoo = createMakoo({
|
|
61
|
+
defaults: {
|
|
62
|
+
alive: true,
|
|
63
|
+
scope: 'local',
|
|
64
|
+
timeout: 5000
|
|
65
|
+
},
|
|
66
|
+
adapters: [textAdapter]
|
|
67
|
+
});
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
makoo.start([
|
|
70
|
+
inject('#app', {
|
|
71
|
+
kind: 'text',
|
|
72
|
+
text: 'Hello from Makoo core'
|
|
73
|
+
})
|
|
74
|
+
]);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Runtime Basics
|
|
78
|
+
|
|
79
|
+
`inject()` and `listen()` are declaration helpers. They do not touch the DOM and do not register tasks by themselves. `makoo.start([...])` registers the declarations in the provided batch and immediately schedules those tasks.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { createMakoo, inject, listen } from '@makoojs/core';
|
|
83
|
+
|
|
84
|
+
const makoo = createMakoo({
|
|
85
|
+
defaults: {
|
|
86
|
+
alive: false,
|
|
87
|
+
scope: 'local',
|
|
88
|
+
timeout: 5000
|
|
89
|
+
},
|
|
90
|
+
adapters: [myAdapter],
|
|
91
|
+
hooks: {
|
|
92
|
+
'start:requested': (event) => {
|
|
93
|
+
console.log(event.name);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
67
96
|
});
|
|
68
97
|
|
|
69
|
-
|
|
98
|
+
const started = makoo.start([
|
|
99
|
+
inject('#toolbar', toolbarArtifact, {
|
|
100
|
+
alive: true,
|
|
101
|
+
on: listen('#save', 'click', () => {
|
|
102
|
+
console.log('save clicked');
|
|
103
|
+
})
|
|
104
|
+
}),
|
|
105
|
+
listen('#escape', 'keydown', onEscape)
|
|
106
|
+
]);
|
|
70
107
|
```
|
|
71
108
|
|
|
72
|
-
|
|
109
|
+
`start()` returns `StartedTasks` for batch-scoped control:
|
|
73
110
|
|
|
74
|
-
|
|
111
|
+
```ts
|
|
112
|
+
const toolbar = started.get('Toolbar@#toolbar');
|
|
75
113
|
|
|
76
|
-
|
|
114
|
+
if (toolbar?.kind === 'component') {
|
|
115
|
+
toolbar.disableAlive();
|
|
116
|
+
toolbar.enableAlive();
|
|
117
|
+
}
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
| `applyAdapter(adapter)` | Registers a mount adapter that can resolve artifacts |
|
|
81
|
-
| `register(injectAt, artifact, options?)` | Registers a component or other artifact injection task |
|
|
82
|
-
| `registerListener(listenAt, event, callback, activitySignal?)` | Registers a standalone DOM event listener task |
|
|
83
|
-
| `run()` | Starts scheduling registered tasks |
|
|
84
|
-
| `enableAlive(taskId)` / `disableAlive(taskId)` | Enables or disables alive reinjection for a component task |
|
|
85
|
-
| `reset(taskId)` / `destroy(taskId)` | Resets or destroys a single task |
|
|
86
|
-
| `resetAll()` / `destroyAll()` | Resets or destroys all tasks |
|
|
87
|
-
| `on()` / `onTask()` / `onAny()` | Listens to lifecycle observation events |
|
|
119
|
+
started.destroyAll();
|
|
120
|
+
```
|
|
88
121
|
|
|
89
|
-
`
|
|
122
|
+
`started.destroyAll()` only affects tasks created by that start batch. `makoo.destroyAll()` affects the whole runtime.
|
|
90
123
|
|
|
91
124
|
## Adapter Contract
|
|
92
125
|
|
|
@@ -101,110 +134,56 @@ const adapter: ResolvableMountAdapter<MyArtifact, MyHandle, MyInstance> = {
|
|
|
101
134
|
return isMyArtifact(artifact);
|
|
102
135
|
},
|
|
103
136
|
mount(input) {
|
|
104
|
-
// input.host is the host element created by Makoo
|
|
105
|
-
// input.mountPoint is where the adapter should mount content
|
|
106
|
-
// input.makoo contains task-scoped runtime capabilities
|
|
107
137
|
return {
|
|
108
138
|
handle,
|
|
109
139
|
instance
|
|
110
140
|
};
|
|
111
141
|
},
|
|
112
142
|
unmount(input) {
|
|
113
|
-
// Clean up according to input.reason
|
|
143
|
+
// Clean up according to input.reason.
|
|
114
144
|
}
|
|
115
145
|
};
|
|
116
146
|
```
|
|
117
147
|
|
|
118
|
-
`mount(input)` receives
|
|
119
|
-
|
|
120
|
-
| Field | Description |
|
|
121
|
-
| --- | --- |
|
|
122
|
-
| `host` | The host element created and inserted by Makoo |
|
|
123
|
-
| `mountPoint` | The node where the adapter should mount content |
|
|
124
|
-
| `artifact` | The currently registered artifact |
|
|
125
|
-
| `taskId` | Current task ID |
|
|
126
|
-
| `injectAt` | Target selector for the current task |
|
|
127
|
-
| `makoo` | Task-scoped runtime capabilities |
|
|
128
|
-
|
|
129
|
-
The `makoo` context lets adapter internals control the current task:
|
|
130
|
-
|
|
131
|
-
```ts
|
|
132
|
-
mount({ makoo }) {
|
|
133
|
-
const off = makoo.onTask('artifact:mountSuccess', (event) => {
|
|
134
|
-
makoo.getLogger().debug('mounted', event.taskId);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
handle: {
|
|
139
|
-
off
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Lifecycle And Alive Mode
|
|
146
|
-
|
|
147
|
-
`alive` handles cases where the target DOM is re-rendered, removed, and later restored. When enabled, Makoo observes removal of the mounted node and tries to reinject when the target selector appears again.
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
const result = injector.register('#toolbar', artifact, {
|
|
151
|
-
alive: true,
|
|
152
|
-
scope: 'global',
|
|
153
|
-
timeout: 8000
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
result.disableAlive();
|
|
157
|
-
result.enableAlive();
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
`scope` supports:
|
|
161
|
-
|
|
162
|
-
| Value | Description |
|
|
163
|
-
| --- | --- |
|
|
164
|
-
| `local` | Observes DOM changes near the current mount area |
|
|
165
|
-
| `global` | Observes DOM changes across the whole document |
|
|
166
|
-
|
|
167
|
-
`alive` only applies to component or artifact injection tasks. Standalone listener tasks do not use the alive reinjection mechanism.
|
|
148
|
+
`mount(input)` receives the target host, generated mount point, artifact, task ID, selector, and task-scoped `makoo` context.
|
|
168
149
|
|
|
169
150
|
## Listener And Activity Signal
|
|
170
151
|
|
|
171
|
-
|
|
152
|
+
Standalone listeners are declared with `listen()`.
|
|
172
153
|
|
|
173
154
|
```ts
|
|
174
|
-
import { createActivityStore } from '@makoojs/core';
|
|
155
|
+
import { createActivityStore, createMakoo, listen } from '@makoojs/core';
|
|
175
156
|
|
|
176
157
|
const enabled = createActivityStore(true);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
158
|
+
const makoo = createMakoo();
|
|
159
|
+
|
|
160
|
+
makoo.start([
|
|
161
|
+
listen(
|
|
162
|
+
'#save',
|
|
163
|
+
'click',
|
|
164
|
+
() => {
|
|
165
|
+
console.log('save clicked');
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
activitySignal: () => enabled
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
]);
|
|
188
172
|
|
|
189
173
|
enabled.set(false);
|
|
190
174
|
enabled.set(true);
|
|
191
175
|
```
|
|
192
176
|
|
|
193
|
-
`createActivityStore()` returns a small subscribable boolean state. When passed to a listener, Makoo automatically attaches or detaches the event listener based on that state.
|
|
194
|
-
|
|
195
|
-
> [!NOTE]
|
|
196
|
-
> `@makoojs/cli` cannot parse this standalone listener mounting form yet. It only supports the **`component + listener`** form.
|
|
197
|
-
|
|
198
177
|
## Observation Events
|
|
199
178
|
|
|
200
|
-
core emits observation events during registration,
|
|
179
|
+
core emits observation events during declaration registration, starting, mounting, listener work, alive mode, DOM watching, and task status changes.
|
|
201
180
|
|
|
202
181
|
```ts
|
|
203
|
-
const off =
|
|
182
|
+
const off = makoo.on('artifact:mountSuccess', (event) => {
|
|
204
183
|
console.log(event.taskId, event.injectAt);
|
|
205
184
|
});
|
|
206
185
|
|
|
207
|
-
|
|
186
|
+
makoo.onAny((event, ctrl) => {
|
|
208
187
|
if (event.name === 'artifact:mountFail') {
|
|
209
188
|
ctrl.stopPropagation();
|
|
210
189
|
}
|
|
@@ -217,8 +196,8 @@ Common events include:
|
|
|
217
196
|
|
|
218
197
|
- `register:start`
|
|
219
198
|
- `register:success`
|
|
220
|
-
- `
|
|
221
|
-
- `
|
|
199
|
+
- `start:requested`
|
|
200
|
+
- `start:taskScheduled`
|
|
222
201
|
- `artifact:mountStart`
|
|
223
202
|
- `artifact:mountSuccess`
|
|
224
203
|
- `artifact:mountFail`
|
|
@@ -233,46 +212,11 @@ The full event name list is available from `OBSERVE_EVENT_NAMES`.
|
|
|
233
212
|
|
|
234
213
|
## DOMWatcher
|
|
235
214
|
|
|
236
|
-
`DOMWatcher` is core's low-level DOM observation utility. You usually do not need to use it directly because `
|
|
237
|
-
|
|
238
|
-
In a custom runtime, you can use it directly:
|
|
239
|
-
|
|
240
|
-
```ts
|
|
241
|
-
import { DOMWatcher } from '@makoojs/core';
|
|
242
|
-
|
|
243
|
-
const stop = DOMWatcher.onDomReady(
|
|
244
|
-
'#app',
|
|
245
|
-
(el) => {
|
|
246
|
-
console.log('target ready', el);
|
|
247
|
-
},
|
|
248
|
-
document,
|
|
249
|
-
{
|
|
250
|
-
once: true,
|
|
251
|
-
timeout: 5000
|
|
252
|
-
}
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
stop();
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
`DOMWatcher.onDomAlive()` can observe removal and restoration of an existing node, mainly for implementing reinjection behavior.
|
|
215
|
+
`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.
|
|
259
216
|
|
|
260
217
|
## Logging And Errors
|
|
261
218
|
|
|
262
|
-
core uses `Logger` by default and prints logs with the `[Makoo]` prefix. You can pass a custom logger
|
|
263
|
-
|
|
264
|
-
```ts
|
|
265
|
-
import { Injector, type ILogger } from '@makoojs/core';
|
|
266
|
-
|
|
267
|
-
const logger: ILogger = {
|
|
268
|
-
info: console.info,
|
|
269
|
-
warn: console.warn,
|
|
270
|
-
error: console.error,
|
|
271
|
-
debug: console.debug
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const injector = new Injector({ logger });
|
|
275
|
-
```
|
|
219
|
+
core uses `Logger` by default and prints logs with the `[Makoo]` prefix. You can pass a custom logger to `createMakoo({ logger })`.
|
|
276
220
|
|
|
277
221
|
core also exports these error-related types:
|
|
278
222
|
|
|
@@ -282,32 +226,14 @@ core also exports these error-related types:
|
|
|
282
226
|
- `ErrorCode`
|
|
283
227
|
- `MakooIssue`
|
|
284
228
|
|
|
285
|
-
These types are useful for error identification, log grouping, or user-facing messages in custom integrations.
|
|
286
|
-
|
|
287
229
|
## Public Exports Overview
|
|
288
230
|
|
|
289
|
-
The main `@makoojs/core` entry exports these groups of capabilities:
|
|
290
|
-
|
|
291
231
|
| Category | Representative exports |
|
|
292
232
|
| --- | --- |
|
|
293
|
-
|
|
|
233
|
+
| Runtime API | `createMakoo`, `inject`, `listen`, `MakooRuntime`, `StartedTasks` |
|
|
294
234
|
| Adapter protocol | `MountAdapter`, `ResolvableMountAdapter`, `AdapterMountInput`, `AdapterUnmountInput`, `MakooContext` |
|
|
295
235
|
| Lifecycle observation | `ObserverHub`, `OBSERVE_EVENT_NAMES`, `ObserveEvent`, `ObserveHook`, `LifecycleHookMap` |
|
|
296
236
|
| DOM observation | `DOMWatcher` |
|
|
297
237
|
| Listener signal | `createActivityStore`, `ActivitySignalSource` |
|
|
298
238
|
| Logging | `Logger`, `ILogger`, `LoggerLevel` |
|
|
299
239
|
| Errors | `MakooError`, `AdapterError`, `TaskError`, `ErrorCode` |
|
|
300
|
-
|
|
301
|
-
The full API reference will be moved to a dedicated documentation site later.
|
|
302
|
-
|
|
303
|
-
## Relationship To Other Packages
|
|
304
|
-
|
|
305
|
-
| Package | Responsibility |
|
|
306
|
-
| --- | --- |
|
|
307
|
-
| `@makoojs/core` | Framework-agnostic injection runtime core |
|
|
308
|
-
| `@makoojs/vue` | Vue adapter and Vue plugin registration helpers |
|
|
309
|
-
| `@makoojs/react` | React adapter |
|
|
310
|
-
| `@makoojs/cli` | Vite plugin, config resolution, scanning, code generation, and userscript build integration |
|
|
311
|
-
| `@makoojs/create-makoo` | Project scaffold |
|
|
312
|
-
|
|
313
|
-
If you are building a regular userscript project, prefer `@makoojs/cli` + `@makoojs/core`. If you want to extend Makoo's runtime capabilities, use `@makoojs/core` directly.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ArtifactOptions, CreateMakooOptions, MakooInjectionDeclaration, MakooListenerDeclaration, MakooListenerOptions, MakooRuntime } from './types';
|
|
2
|
+
export declare function createMakoo(options?: CreateMakooOptions): MakooRuntime;
|
|
3
|
+
export declare function inject<TArtifact>(injectAt: string, artifact: TArtifact, options?: ArtifactOptions): MakooInjectionDeclaration<TArtifact>;
|
|
4
|
+
export declare function listen(listenAt: string, event: string, callback: EventListener, options?: MakooListenerOptions): MakooListenerDeclaration;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ResolvableMountAdapter } from '../adapter/types';
|
|
2
|
+
import { LifecycleHookMap, ObserveEventName, ObserveHook, ObserverHub } from '../hooks/types';
|
|
3
|
+
import { ILogger } from '../logger/types';
|
|
4
|
+
import { TaskActivitySignal } from '../Task/types';
|
|
5
|
+
export declare enum Action {
|
|
6
|
+
OPEN = "OPEN",
|
|
7
|
+
CLOSE = "CLOSE"
|
|
8
|
+
}
|
|
9
|
+
export type ActionEvent = `${Action}`;
|
|
10
|
+
export type MakooListenerOptions = {
|
|
11
|
+
activitySignal?: TaskActivitySignal;
|
|
12
|
+
};
|
|
13
|
+
export type MakooListenerDeclaration = {
|
|
14
|
+
kind: 'listener';
|
|
15
|
+
listenAt: string;
|
|
16
|
+
event: string;
|
|
17
|
+
type: string;
|
|
18
|
+
callback: EventListener;
|
|
19
|
+
activitySignal?: TaskActivitySignal;
|
|
20
|
+
};
|
|
21
|
+
export type ArtifactOptions = {
|
|
22
|
+
alive?: boolean;
|
|
23
|
+
scope?: 'local' | 'global';
|
|
24
|
+
timeout?: number;
|
|
25
|
+
on?: MakooListenerDeclaration;
|
|
26
|
+
hooks?: LifecycleHookMap;
|
|
27
|
+
};
|
|
28
|
+
export type MakooInjectionDeclaration<TArtifact = unknown> = {
|
|
29
|
+
kind: 'component';
|
|
30
|
+
injectAt: string;
|
|
31
|
+
artifact: TArtifact;
|
|
32
|
+
options?: ArtifactOptions;
|
|
33
|
+
};
|
|
34
|
+
export type MakooTaskDeclaration<TArtifact = unknown> = MakooInjectionDeclaration<TArtifact> | MakooListenerDeclaration;
|
|
35
|
+
export type MakooDefaults = {
|
|
36
|
+
alive: boolean;
|
|
37
|
+
scope: 'local' | 'global';
|
|
38
|
+
timeout: number;
|
|
39
|
+
};
|
|
40
|
+
export type InjectionConfig = MakooDefaults & {
|
|
41
|
+
logger: ILogger;
|
|
42
|
+
observer?: ObserverHub;
|
|
43
|
+
hooks?: LifecycleHookMap;
|
|
44
|
+
};
|
|
45
|
+
export type CreateMakooOptions = {
|
|
46
|
+
defaults?: Partial<MakooDefaults>;
|
|
47
|
+
adapters?: ResolvableMountAdapter[];
|
|
48
|
+
hooks?: LifecycleHookMap;
|
|
49
|
+
logger?: ILogger;
|
|
50
|
+
observer?: ObserverHub;
|
|
51
|
+
};
|
|
52
|
+
export type StartedComponentTask = {
|
|
53
|
+
kind: 'component';
|
|
54
|
+
taskId: string;
|
|
55
|
+
enableAlive(): void;
|
|
56
|
+
disableAlive(): void;
|
|
57
|
+
reset(): void;
|
|
58
|
+
destroy(): void;
|
|
59
|
+
};
|
|
60
|
+
export type StartedListenerTask = {
|
|
61
|
+
kind: 'listener';
|
|
62
|
+
taskId: string;
|
|
63
|
+
open(): boolean;
|
|
64
|
+
close(): boolean;
|
|
65
|
+
destroy(): void;
|
|
66
|
+
};
|
|
67
|
+
export type StartedTask = StartedComponentTask | StartedListenerTask;
|
|
68
|
+
export type StartedTasks = {
|
|
69
|
+
tasks: StartedTask[];
|
|
70
|
+
get(taskId: string): StartedTask | undefined;
|
|
71
|
+
resetAll(): void;
|
|
72
|
+
destroyAll(): void;
|
|
73
|
+
};
|
|
74
|
+
export type MakooRuntime = {
|
|
75
|
+
start(tasks: MakooTaskDeclaration[]): StartedTasks;
|
|
76
|
+
reset(taskId: string): void;
|
|
77
|
+
destroy(taskId: string): void;
|
|
78
|
+
resetAll(): void;
|
|
79
|
+
destroyAll(): void;
|
|
80
|
+
enableAlive(taskId: string): void;
|
|
81
|
+
disableAlive(taskId: string): void;
|
|
82
|
+
on(event: ObserveEventName, hook: ObserveHook): () => void;
|
|
83
|
+
onTask(taskId: string, event: ObserveEventName, hook: ObserveHook): () => void;
|
|
84
|
+
onAny(hook: ObserveHook): () => void;
|
|
85
|
+
off(event: ObserveEventName, hook?: ObserveHook): void;
|
|
86
|
+
offTask(taskId: string, event?: ObserveEventName, hook?: ObserveHook): void;
|
|
87
|
+
offAny(hook: ObserveHook): void;
|
|
88
|
+
getLogger(): ILogger;
|
|
89
|
+
};
|
|
@@ -1,105 +1,25 @@
|
|
|
1
1
|
import { ObserveEmitter } from '../hooks/types';
|
|
2
2
|
import { ILogger } from '../logger/types';
|
|
3
3
|
import { ArtifactTask, ListenerTask, Task, TaskErrorMessage, TaskRecord, TaskStatus } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* This context stores task instances, task records, and transient runtime state
|
|
8
|
-
* (watchers, listeners, component roots, and shared Vue plugins). It also provides
|
|
9
|
-
* unified teardown utilities for single-task and full-context cleanup to avoid
|
|
10
|
-
* memory leaks from unreleased DOM nodes, listeners, and reactive watchers.
|
|
11
|
-
*/
|
|
12
|
-
export declare class TaskContext {
|
|
13
|
-
private readonly logger;
|
|
14
|
-
private readonly emit;
|
|
15
|
-
/**
|
|
16
|
-
* Stores failed task injection messages.
|
|
17
|
-
*
|
|
18
|
-
* Reserved for diagnostics and potential retry mechanisms.
|
|
19
|
-
*/
|
|
20
|
-
taskErrorMessages: Array<TaskErrorMessage>;
|
|
21
|
-
/**
|
|
22
|
-
* Stores lightweight task metadata such as task id and injection location.
|
|
23
|
-
*/
|
|
4
|
+
export type TaskContext = {
|
|
5
|
+
taskErrorMessages: TaskErrorMessage[];
|
|
24
6
|
taskRecords: TaskRecord[];
|
|
25
|
-
/**
|
|
26
|
-
* Maps task id to its full runtime context.
|
|
27
|
-
*/
|
|
28
|
-
private readonly contextMap;
|
|
29
|
-
constructor(emit?: ObserveEmitter, logger?: ILogger);
|
|
30
|
-
/**
|
|
31
|
-
* Registers or replaces a task context by id.
|
|
32
|
-
*
|
|
33
|
-
* @param key Unique task id.
|
|
34
|
-
* @param context Runtime task context object.
|
|
35
|
-
*/
|
|
36
7
|
set(key: string, context: Task): void;
|
|
37
|
-
/**
|
|
38
|
-
* Gets a task context by id.
|
|
39
|
-
*
|
|
40
|
-
* @param key Unique task id.
|
|
41
|
-
* @returns The task context if found, otherwise `undefined`.
|
|
42
|
-
*/
|
|
43
8
|
get(key: string, kind: 'listener'): ListenerTask | undefined;
|
|
44
9
|
get(key: string, kind: 'component'): ArtifactTask | undefined;
|
|
45
10
|
get<T extends Task>(key: string): T | undefined;
|
|
46
11
|
get(key: string): Task | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Checks whether a task context exists.
|
|
49
|
-
*
|
|
50
|
-
* @param key Unique task id.
|
|
51
|
-
* @returns `true` when the task exists.
|
|
52
|
-
*/
|
|
53
12
|
has(key: string): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Returns an iterator over all task ids.
|
|
56
|
-
*
|
|
57
|
-
* @returns Iterator of registered task ids.
|
|
58
|
-
*/
|
|
59
13
|
keys(): IterableIterator<string>;
|
|
60
14
|
getTaskStatus(id: string): TaskStatus | undefined;
|
|
61
15
|
setTaskStatus(id: string, status: TaskStatus): void;
|
|
62
|
-
/**
|
|
63
|
-
* Destroys all resources of a single task.
|
|
64
|
-
*
|
|
65
|
-
* Cleanup order is: watcher -> listener -> component -> dom -> context.
|
|
66
|
-
*
|
|
67
|
-
* @param id Unique task id.
|
|
68
|
-
*/
|
|
69
16
|
destroy(id: string): void;
|
|
70
|
-
/**
|
|
71
|
-
* Destroys all registered tasks and resets shared runtime state.
|
|
72
|
-
*/
|
|
73
17
|
destroyAll(): void;
|
|
74
|
-
/**
|
|
75
|
-
* Unmounts and clears the Vue app instance of a task.
|
|
76
|
-
*
|
|
77
|
-
* @param id Unique task id.
|
|
78
|
-
*/
|
|
79
18
|
releaseComponentInstance(id: string): void;
|
|
80
|
-
/**
|
|
81
|
-
* Removes and clears the task root DOM element.
|
|
82
|
-
*
|
|
83
|
-
* @param id Unique task id.
|
|
84
|
-
*/
|
|
85
19
|
releaseDomElement(id: string): void;
|
|
86
|
-
/**
|
|
87
|
-
* Aborts and clears listener-related runtime fields of a task.
|
|
88
|
-
*
|
|
89
|
-
* @param id Unique task id.
|
|
90
|
-
*/
|
|
91
20
|
releaseListener(id: string): void;
|
|
92
|
-
/**
|
|
93
|
-
* Stops and clears watcher-related runtime fields of a task.
|
|
94
|
-
*
|
|
95
|
-
* @param id Unique task id.
|
|
96
|
-
*/
|
|
97
21
|
releaseWatcher(id: string): void;
|
|
98
|
-
/**
|
|
99
|
-
* Resets one task to an initial reusable state while keeping its map entry.
|
|
100
|
-
*
|
|
101
|
-
* @param id Unique task id.
|
|
102
|
-
*/
|
|
103
22
|
reset(id: string): void;
|
|
104
23
|
resetAll(): void;
|
|
105
|
-
}
|
|
24
|
+
};
|
|
25
|
+
export declare function createTaskContext(emit?: ObserveEmitter, logger?: ILogger): TaskContext;
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private readonly onTargetReady;
|
|
9
|
-
private readonly logger;
|
|
10
|
-
private readonly emit;
|
|
11
|
-
constructor(taskContext: TaskContext, onTargetReady: (targetElement: HTMLElement, taskId: string) => void, injectConfig: InjectionConfig, emitter: ObserveEmitter, logger?: ILogger);
|
|
12
|
-
enableAlive(taskId: string): void;
|
|
13
|
-
disableAlive(taskId: string): void;
|
|
14
|
-
destroy(taskId: string): void;
|
|
15
|
-
destroyAll(): void;
|
|
16
|
-
reset(taskId: string): void;
|
|
17
|
-
resetAll(): void;
|
|
18
|
-
}
|
|
1
|
+
import { MakooRuntimeState } from '../runtime/types';
|
|
2
|
+
export declare function enableAlive(runtime: MakooRuntimeState, taskId: string): void;
|
|
3
|
+
export declare function disableAlive(runtime: MakooRuntimeState, taskId: string): void;
|
|
4
|
+
export declare function destroy(runtime: MakooRuntimeState, taskId: string): void;
|
|
5
|
+
export declare function destroyAll(runtime: MakooRuntimeState): void;
|
|
6
|
+
export declare function reset(runtime: MakooRuntimeState, taskId: string): void;
|
|
7
|
+
export declare function resetAll(runtime: MakooRuntimeState): void;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ArtifactOptions, InjectionConfig } from '../Injector/types';
|
|
4
|
-
import { ILogger } from '../logger/types';
|
|
5
|
-
import { TaskContext } from './TaskContext';
|
|
1
|
+
import { ArtifactOptions } from '../Makoo/types';
|
|
2
|
+
import { MakooRuntimeState } from '../runtime/types';
|
|
6
3
|
import { _RegisterResult, ListenerRegisterResult, TaskActivitySignal } from './types';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
4
|
+
export type InjectionDeclaration<TArtifact = unknown> = {
|
|
5
|
+
injectAt: string;
|
|
6
|
+
artifact: TArtifact;
|
|
7
|
+
options?: ArtifactOptions;
|
|
8
|
+
};
|
|
9
|
+
export type ListenerDeclaration = {
|
|
10
|
+
listenAt: string;
|
|
11
|
+
event: string;
|
|
12
|
+
callback: EventListener;
|
|
13
|
+
activitySignal?: TaskActivitySignal;
|
|
14
|
+
};
|
|
15
|
+
export declare function registerListener(runtime: MakooRuntimeState, declaration: ListenerDeclaration): ListenerRegisterResult;
|
|
16
|
+
export declare function registerInjection<TArtifact>(runtime: MakooRuntimeState, declaration: InjectionDeclaration<TArtifact>): _RegisterResult;
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ActionEvent, InjectionConfig } from '../Injector/types';
|
|
4
|
-
import { ILogger } from '../logger/types';
|
|
1
|
+
import { ActionEvent } from '../Makoo/types';
|
|
2
|
+
import { MakooRuntimeState } from '../runtime/types';
|
|
5
3
|
import { ActivitySignalSource } from '../signal/types';
|
|
6
|
-
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private readonly logger;
|
|
11
|
-
private readonly emit;
|
|
12
|
-
private readonly resolveMakooContext;
|
|
13
|
-
constructor(taskContext: TaskContext, injectConfig: InjectionConfig, emitter: ObserveEmitter, resolveMakooContext: (taskId: string, injectAt: string) => MakooContext, logger?: ILogger);
|
|
14
|
-
run(): void;
|
|
15
|
-
onTargetReady(targetElement: HTMLElement, taskId: string): void;
|
|
16
|
-
bindListenerSignal(taskId: string, source: ActivitySignalSource<boolean>): boolean;
|
|
17
|
-
controlListener(taskId: string, event: ActionEvent): boolean;
|
|
18
|
-
private attachEvent;
|
|
19
|
-
private injectArtifact;
|
|
20
|
-
}
|
|
4
|
+
export declare function startTasks(runtime: MakooRuntimeState, taskIds: string[]): void;
|
|
5
|
+
export declare function onTargetReady(runtime: MakooRuntimeState, targetElement: HTMLElement, taskId: string): void;
|
|
6
|
+
export declare function bindListenerSignal(runtime: MakooRuntimeState, taskId: string, source: ActivitySignalSource<boolean>): boolean;
|
|
7
|
+
export declare function controlListener(runtime: MakooRuntimeState, taskId: string, event: ActionEvent): boolean;
|
package/dist/Task/types.d.ts
CHANGED
|
@@ -61,16 +61,12 @@ export type Task = ArtifactTask | ListenerTask;
|
|
|
61
61
|
export type ListenerRegisterResult = {
|
|
62
62
|
taskId: string;
|
|
63
63
|
isSuccess: boolean;
|
|
64
|
-
|
|
65
|
-
export type RegisterResult = {
|
|
66
|
-
taskId: string;
|
|
67
|
-
isSuccess: boolean;
|
|
68
|
-
enableAlive: () => void;
|
|
69
|
-
disableAlive: () => void;
|
|
64
|
+
isDuplicate?: boolean;
|
|
70
65
|
};
|
|
71
66
|
export type _RegisterResult = {
|
|
72
67
|
taskId: string;
|
|
73
68
|
isSuccess: boolean;
|
|
69
|
+
isDuplicate?: boolean;
|
|
74
70
|
};
|
|
75
71
|
export type _InjectResult = {
|
|
76
72
|
isSuccess: boolean;
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
3
|
-
private readonly adapters;
|
|
4
|
-
resolve(artifact: unknown): MountAdapter | undefined;
|
|
5
|
-
use(adapter: ResolvableMountAdapter): void;
|
|
6
|
-
}
|
|
1
|
+
import { AdapterRegistry } from './types';
|
|
2
|
+
export declare function createAdapterRegistry(): AdapterRegistry;
|