@makoojs/core 0.1.0 → 0.2.1

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.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @makoojs/core
2
2
 
3
- `@makoojs/core` is Makoo's framework-agnostic runtime core. It registers and schedules injection tasks, waits for target DOM nodes, mounts artifacts, manages alive reinjection, binds event listeners, and provides lifecycle observation events, logging, and error infrastructure.
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`. The CLI provides the Vite plugin, scans the `injections` directory, resolves manifests, generates userscript entry code, and passes configuration through to [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) for development, build, and install flows. `@makoojs/core` is the lower-level runtime package. You only need to use it directly when you want to leave Makoo's CLI flow and manually integrate the injection runtime. `@makoojs/vue` and `@makoojs/react` are component mounting adapters that connect Vue or React components to the `@makoojs/core` injection flow.
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 an `Injector` directly and register tasks manually without CLI scanning or code generation.
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` to build a more custom runtime integration.
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 { Injector, type ResolvableMountAdapter } from '@makoojs/core';
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,102 @@ const textAdapter: ResolvableMountAdapter<TextArtifact, HTMLElement> = {
55
57
  }
56
58
  };
57
59
 
58
- const injector = new Injector({
59
- alive: true,
60
- scope: 'local',
61
- timeout: 5000
62
- }).applyAdapter(textAdapter);
60
+ const makoo = createMakoo({
61
+ defaults: {
62
+ alive: true,
63
+ scope: 'local',
64
+ timeout: 5000
65
+ },
66
+ adapters: [textAdapter]
67
+ });
68
+
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
+ `inject()` has two forms. The positional form is concise:
82
+
83
+ ```ts
84
+ inject('#toolbar', toolbarArtifact, {
85
+ alive: true
86
+ });
87
+ ```
88
+
89
+ The object form keeps the declaration fields together. Its optional `id` is used as the task id, which is useful when you want to look up or control that task later:
90
+
91
+ ```ts
92
+ inject({
93
+ id: 'settings-panel',
94
+ injectAt: '#settings',
95
+ artifact: settingsArtifact,
96
+ options: {
97
+ alive: true
98
+ }
99
+ });
100
+ ```
101
+
102
+ When `id` is omitted, Makoo infers a task id from the artifact and target selector.
63
103
 
64
- injector.register('#app', {
65
- kind: 'text',
66
- text: 'Hello from Makoo core'
104
+ ```ts
105
+ import { createMakoo, inject, listen } from '@makoojs/core';
106
+
107
+ const makoo = createMakoo({
108
+ defaults: {
109
+ alive: false,
110
+ scope: 'local',
111
+ timeout: 5000
112
+ },
113
+ adapters: [myAdapter],
114
+ hooks: {
115
+ 'start:requested': (event) => {
116
+ console.log(event.name);
117
+ }
118
+ }
67
119
  });
68
120
 
69
- injector.run();
121
+ const started = makoo.start([
122
+ inject('#toolbar', toolbarArtifact, {
123
+ alive: true
124
+ }),
125
+ inject({
126
+ id: 'settings-panel',
127
+ injectAt: '#settings',
128
+ artifact: settingsArtifact,
129
+ options: {
130
+ alive: true
131
+ }
132
+ }),
133
+ inject('#save-tip', saveTipArtifact, {
134
+ on: listen('#save', 'click', () => {
135
+ console.log('save clicked');
136
+ })
137
+ }),
138
+ listen('#escape', 'keydown', onEscape)
139
+ ]);
70
140
  ```
71
141
 
72
- ## Injector Basics
142
+ `start()` returns `StartedTasks` for batch-scoped control:
73
143
 
74
- `Injector` is core's main entry point. It brings together task registration, DOM waiting, adapter resolution, mounting, event binding, and lifecycle control.
144
+ ```ts
145
+ const toolbar = started.get('Toolbar@#toolbar');
75
146
 
76
- Common methods:
147
+ if (toolbar?.kind === 'component') {
148
+ toolbar.disableAlive();
149
+ toolbar.enableAlive();
150
+ }
77
151
 
78
- | Method | Description |
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 |
152
+ started.destroyAll();
153
+ ```
88
154
 
89
- `register()` returns `taskId`, `isSuccess`, and shortcut methods for `enableAlive()` / `disableAlive()` on the current task.
155
+ `started.destroyAll()` only affects tasks created by that start batch. `makoo.destroyAll()` affects the whole runtime.
90
156
 
91
157
  ## Adapter Contract
92
158
 
@@ -101,110 +167,56 @@ const adapter: ResolvableMountAdapter<MyArtifact, MyHandle, MyInstance> = {
101
167
  return isMyArtifact(artifact);
102
168
  },
103
169
  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
170
  return {
108
171
  handle,
109
172
  instance
110
173
  };
111
174
  },
112
175
  unmount(input) {
113
- // Clean up according to input.reason
176
+ // Clean up according to input.reason.
114
177
  }
115
178
  };
116
179
  ```
117
180
 
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.
181
+ `mount(input)` receives the target host, generated mount point, artifact, task ID, selector, and task-scoped `makoo` context.
168
182
 
169
183
  ## Listener And Activity Signal
170
184
 
171
- Besides mounting artifacts, `Injector` can also register standalone DOM event listener tasks.
185
+ Standalone listeners are declared with `listen()`.
172
186
 
173
187
  ```ts
174
- import { createActivityStore } from '@makoojs/core';
188
+ import { createActivityStore, createMakoo, listen } from '@makoojs/core';
175
189
 
176
190
  const enabled = createActivityStore(true);
177
-
178
- injector.registerListener(
179
- '#save',
180
- 'click',
181
- () => {
182
- console.log('save clicked');
183
- },
184
- () => enabled
185
- );
186
-
187
- injector.run();
191
+ const makoo = createMakoo();
192
+
193
+ makoo.start([
194
+ listen(
195
+ '#save',
196
+ 'click',
197
+ () => {
198
+ console.log('save clicked');
199
+ },
200
+ {
201
+ activitySignal: () => enabled
202
+ }
203
+ )
204
+ ]);
188
205
 
189
206
  enabled.set(false);
190
207
  enabled.set(true);
191
208
  ```
192
209
 
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
210
  ## Observation Events
199
211
 
200
- core emits observation events during registration, running, mounting, listener work, alive mode, DOM watching, and task status changes. You can listen to them with `on()`, `onTask()`, or `onAny()`.
212
+ core emits observation events during declaration registration, starting, mounting, listener work, alive mode, DOM watching, and task status changes.
201
213
 
202
214
  ```ts
203
- const off = injector.on('artifact:mountSuccess', (event) => {
215
+ const off = makoo.on('artifact:mountSuccess', (event) => {
204
216
  console.log(event.taskId, event.injectAt);
205
217
  });
206
218
 
207
- injector.onAny((event, ctrl) => {
219
+ makoo.onAny((event, ctrl) => {
208
220
  if (event.name === 'artifact:mountFail') {
209
221
  ctrl.stopPropagation();
210
222
  }
@@ -217,8 +229,8 @@ Common events include:
217
229
 
218
230
  - `register:start`
219
231
  - `register:success`
220
- - `run:start`
221
- - `run:taskScheduled`
232
+ - `start:requested`
233
+ - `start:taskScheduled`
222
234
  - `artifact:mountStart`
223
235
  - `artifact:mountSuccess`
224
236
  - `artifact:mountFail`
@@ -233,46 +245,11 @@ The full event name list is available from `OBSERVE_EVENT_NAMES`.
233
245
 
234
246
  ## DOMWatcher
235
247
 
236
- `DOMWatcher` is core's low-level DOM observation utility. You usually do not need to use it directly because `Injector.run()` and alive mode already wrap target waiting and restoration.
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.
248
+ `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
249
 
260
250
  ## Logging And Errors
261
251
 
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
- ```
252
+ core uses `Logger` by default and prints logs with the `[Makoo]` prefix. You can pass a custom logger to `createMakoo({ logger })`.
276
253
 
277
254
  core also exports these error-related types:
278
255
 
@@ -282,32 +259,14 @@ core also exports these error-related types:
282
259
  - `ErrorCode`
283
260
  - `MakooIssue`
284
261
 
285
- These types are useful for error identification, log grouping, or user-facing messages in custom integrations.
286
-
287
262
  ## Public Exports Overview
288
263
 
289
- The main `@makoojs/core` entry exports these groups of capabilities:
290
-
291
264
  | Category | Representative exports |
292
265
  | --- | --- |
293
- | Injection scheduling | `Injector`, `InjectionConfig`, `ArtifactOptions` |
266
+ | Runtime API | `createMakoo`, `inject`, `listen`, `MakooRuntime`, `StartedTasks` |
294
267
  | Adapter protocol | `MountAdapter`, `ResolvableMountAdapter`, `AdapterMountInput`, `AdapterUnmountInput`, `MakooContext` |
295
268
  | Lifecycle observation | `ObserverHub`, `OBSERVE_EVENT_NAMES`, `ObserveEvent`, `ObserveHook`, `LifecycleHookMap` |
296
269
  | DOM observation | `DOMWatcher` |
297
270
  | Listener signal | `createActivityStore`, `ActivitySignalSource` |
298
271
  | Logging | `Logger`, `ILogger`, `LoggerLevel` |
299
272
  | 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,5 @@
1
+ import { ArtifactOptions, CreateMakooOptions, MakooInjectionDeclaration, MakooInjectionInput, 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 inject<TArtifact>(input: MakooInjectionInput<TArtifact>): MakooInjectionDeclaration<TArtifact>;
5
+ export declare function listen(listenAt: string, event: string, callback: EventListener, options?: MakooListenerOptions): MakooListenerDeclaration;
@@ -0,0 +1,96 @@
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 MakooInjectionInput<TArtifact = unknown> = {
29
+ id?: string;
30
+ injectAt: string;
31
+ artifact: TArtifact;
32
+ options?: ArtifactOptions;
33
+ };
34
+ export type MakooInjectionDeclaration<TArtifact = unknown> = {
35
+ kind: 'component';
36
+ id?: string;
37
+ injectAt: string;
38
+ artifact: TArtifact;
39
+ options?: ArtifactOptions;
40
+ };
41
+ export type MakooTaskDeclaration<TArtifact = unknown> = MakooInjectionDeclaration<TArtifact> | MakooListenerDeclaration;
42
+ export type MakooDefaults = {
43
+ alive: boolean;
44
+ scope: 'local' | 'global';
45
+ timeout: number;
46
+ };
47
+ export type InjectionConfig = MakooDefaults & {
48
+ logger: ILogger;
49
+ observer?: ObserverHub;
50
+ hooks?: LifecycleHookMap;
51
+ };
52
+ export type CreateMakooOptions = {
53
+ defaults?: Partial<MakooDefaults>;
54
+ adapters?: ResolvableMountAdapter[];
55
+ hooks?: LifecycleHookMap;
56
+ logger?: ILogger;
57
+ observer?: ObserverHub;
58
+ };
59
+ export type StartedComponentTask = {
60
+ kind: 'component';
61
+ taskId: string;
62
+ enableAlive(): void;
63
+ disableAlive(): void;
64
+ reset(): void;
65
+ destroy(): void;
66
+ };
67
+ export type StartedListenerTask = {
68
+ kind: 'listener';
69
+ taskId: string;
70
+ open(): boolean;
71
+ close(): boolean;
72
+ destroy(): void;
73
+ };
74
+ export type StartedTask = StartedComponentTask | StartedListenerTask;
75
+ export type StartedTasks = {
76
+ tasks: StartedTask[];
77
+ get(taskId: string): StartedTask | undefined;
78
+ resetAll(): void;
79
+ destroyAll(): void;
80
+ };
81
+ export type MakooRuntime = {
82
+ start(tasks: MakooTaskDeclaration[]): StartedTasks;
83
+ reset(taskId: string): void;
84
+ destroy(taskId: string): void;
85
+ resetAll(): void;
86
+ destroyAll(): void;
87
+ enableAlive(taskId: string): void;
88
+ disableAlive(taskId: string): void;
89
+ on(event: ObserveEventName, hook: ObserveHook): () => void;
90
+ onTask(taskId: string, event: ObserveEventName, hook: ObserveHook): () => void;
91
+ onAny(hook: ObserveHook): () => void;
92
+ off(event: ObserveEventName, hook?: ObserveHook): void;
93
+ offTask(taskId: string, event?: ObserveEventName, hook?: ObserveHook): void;
94
+ offAny(hook: ObserveHook): void;
95
+ getLogger(): ILogger;
96
+ };
@@ -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
- * Central runtime registry for all injection tasks.
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 { ObserveEmitter } from '../hooks/types';
2
- import { InjectionConfig } from '../Injector/types';
3
- import { ILogger } from '../logger/types';
4
- import { TaskContext } from './TaskContext';
5
- export declare class TaskLifeCycle {
6
- private readonly taskContext;
7
- private readonly injectConfig;
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,17 @@
1
- import { AdapterResolver } from '../adapter/types';
2
- import { ObserveEmitter } from '../hooks/types';
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 declare class TaskRegister {
8
- private readonly taskContext;
9
- private readonly injectConfig;
10
- private readonly logger;
11
- private readonly emit;
12
- private readonly resolveMountAdapter;
13
- constructor(taskContext: TaskContext, injectConfig: InjectionConfig, emitter: ObserveEmitter, adapterResolver: AdapterResolver, logger?: ILogger);
14
- private getTaskId;
15
- registerListener(listenAt: string, event: string, callback: EventListener, activitySignal?: TaskActivitySignal): ListenerRegisterResult;
16
- register<TArtifact>(injectAt: string, artifact: TArtifact, option?: ArtifactOptions): _RegisterResult;
17
- }
4
+ export type InjectionDeclaration<TArtifact = unknown> = {
5
+ id?: string;
6
+ injectAt: string;
7
+ artifact: TArtifact;
8
+ options?: ArtifactOptions;
9
+ };
10
+ export type ListenerDeclaration = {
11
+ listenAt: string;
12
+ event: string;
13
+ callback: EventListener;
14
+ activitySignal?: TaskActivitySignal;
15
+ };
16
+ export declare function registerListener(runtime: MakooRuntimeState, declaration: ListenerDeclaration): ListenerRegisterResult;
17
+ export declare function registerInjection<TArtifact>(runtime: MakooRuntimeState, declaration: InjectionDeclaration<TArtifact>): _RegisterResult;