@makoojs/core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.CN.md +32 -11
- package/README.md +32 -11
- package/dist/adapter/types.d.ts +35 -7
- package/dist/error/MakooError.d.ts +17 -10
- package/dist/error/coreErrors.d.ts +6793 -0
- package/dist/error/defineMakooErrors.d.ts +55 -0
- package/dist/index.cjs +3 -4
- package/dist/index.d.ts +16 -10
- package/dist/index.js +920 -818
- package/dist/injections/inject/declaration.d.ts +32 -0
- package/dist/injections/inject/inject.d.ts +38 -0
- package/dist/injections/injectEach/declaration.d.ts +25 -0
- package/dist/injections/injectEach/injectEach.d.ts +43 -0
- package/dist/injections/kinds.d.ts +12 -0
- package/dist/injections/listen/declaration.d.ts +34 -0
- package/dist/injections/listen/listen.d.ts +36 -0
- package/dist/injections/mount.d.ts +17 -0
- package/dist/{core → instance}/createMakoo.d.ts +1 -0
- package/dist/instance/residue.d.ts +7 -0
- package/dist/instance/types.d.ts +81 -0
- package/dist/runtime/injection.d.ts +94 -0
- package/dist/runtime/match.d.ts +50 -0
- package/dist/runtime/observer.d.ts +9 -0
- package/dist/runtime/scope.d.ts +28 -0
- package/dist/runtime/selector.d.ts +1 -0
- package/dist/runtime/stateNode.d.ts +51 -0
- package/package.json +1 -4
- package/dist/adapter/registry.d.ts +0 -5
- package/dist/component/component.d.ts +0 -5
- package/dist/component/declaration.d.ts +0 -3
- package/dist/component/execution.d.ts +0 -24
- package/dist/component/types.d.ts +0 -37
- package/dist/core/types.d.ts +0 -27
- package/dist/dom/observer.d.ts +0 -4
- package/dist/dom/waitForElement.d.ts +0 -3
- package/dist/dom/watchElement.d.ts +0 -2
- package/dist/error/ErrorCode.d.ts +0 -27
- package/dist/listener/attach.d.ts +0 -12
- package/dist/listener/declaration.d.ts +0 -3
- package/dist/listener/execution.d.ts +0 -19
- package/dist/listener/listener.d.ts +0 -42
- package/dist/listener/types.d.ts +0 -31
- package/dist/state/createState.d.ts +0 -5
- package/dist/state/types.d.ts +0 -4
package/README.CN.md
CHANGED
|
@@ -30,17 +30,16 @@ pnpm add @makoojs/core
|
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import { createMakoo, inject, listen } from '@makoojs/core';
|
|
33
|
-
import {
|
|
33
|
+
import { vueAdapter } from '@makoojs/vue';
|
|
34
34
|
import Panel from './Panel.vue';
|
|
35
35
|
|
|
36
36
|
const core = createMakoo();
|
|
37
|
-
core.useAdapter(createVueAdapter());
|
|
38
37
|
|
|
39
38
|
core.apply([
|
|
40
39
|
inject({
|
|
41
40
|
name: 'panel',
|
|
42
41
|
injectAt: '#sidebar',
|
|
43
|
-
adapter:
|
|
42
|
+
adapter: vueAdapter,
|
|
44
43
|
component: Panel,
|
|
45
44
|
// 网站替换掉 #sidebar 后重新挂载
|
|
46
45
|
reinject: true,
|
|
@@ -66,25 +65,47 @@ core.apply([
|
|
|
66
65
|
]);
|
|
67
66
|
```
|
|
68
67
|
|
|
68
|
+
### 在每个匹配元素上挂载
|
|
69
|
+
|
|
70
|
+
`injectEach()` 把同一个组件挂载到每个匹配 `injectAt` 的元素上,之后出现的元素也会挂载;一个都没匹配到时会持续监视:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { injectEach } from '@makoojs/core';
|
|
74
|
+
import { vueAdapter } from '@makoojs/vue';
|
|
75
|
+
import Badge from './Badge.vue';
|
|
76
|
+
|
|
77
|
+
core.apply([
|
|
78
|
+
injectEach({
|
|
79
|
+
name: 'badges',
|
|
80
|
+
injectAt: '.comment .author',
|
|
81
|
+
adapter: vueAdapter,
|
|
82
|
+
component: Badge
|
|
83
|
+
})
|
|
84
|
+
]);
|
|
85
|
+
```
|
|
86
|
+
|
|
69
87
|
### 控制注入与读取状态
|
|
70
88
|
|
|
71
|
-
|
|
89
|
+
通过名称获取注入对象:组件注入和 Each 注入使用 `core.injection(name)`,独立监听使用 `core.listener(name)`。可以通过 `kind` 区分组件 (`component`) 和 Each 注入 (`component-each`)。Each 注入会通过 `children` 按文档顺序列出子注入。
|
|
72
90
|
|
|
73
91
|
```ts
|
|
74
|
-
const panel = core.
|
|
75
|
-
const
|
|
92
|
+
const panel = core.injection('panel');
|
|
93
|
+
const escape = core.listener('escape');
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
console.log(status
|
|
95
|
+
panel.subscribe(() => {
|
|
96
|
+
console.log(panel.status, panel.lastError);
|
|
79
97
|
});
|
|
80
98
|
|
|
81
|
-
|
|
99
|
+
panel.stop();
|
|
82
100
|
panel.start();
|
|
101
|
+
escape.stop();
|
|
83
102
|
```
|
|
84
103
|
|
|
104
|
+
顶层注入的 `start()`、`stop()` 和 `remove()` 都不返回结果。`start()` 和 `stop()` 的结果通过 `status` 和 `lastError` 读取;`remove()` 之后,该名称不再注册在实例上。
|
|
105
|
+
|
|
85
106
|
## 文档
|
|
86
107
|
|
|
87
108
|
- [Core 实例](https://makoojs.github.io/Makoo/zh/api/instance):`createMakoo()` 与实例上的方法。
|
|
88
|
-
- [声明](https://makoojs.github.io/Makoo/zh/api/declarations):`inject()` 与 `listen()` 的全部字段。
|
|
89
|
-
- [
|
|
109
|
+
- [声明](https://makoojs.github.io/Makoo/zh/api/declarations):`inject()`、`injectEach()` 与 `listen()` 的全部字段。
|
|
110
|
+
- [控制与状态](https://makoojs.github.io/Makoo/zh/api/status):启动、停止、移除,以及状态值的含义。
|
|
90
111
|
- [错误与错误码](https://makoojs.github.io/Makoo/zh/api/errors):错误的种类和处理方式。
|
package/README.md
CHANGED
|
@@ -30,17 +30,16 @@ pnpm add @makoojs/core
|
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import { createMakoo, inject, listen } from '@makoojs/core';
|
|
33
|
-
import {
|
|
33
|
+
import { vueAdapter } from '@makoojs/vue';
|
|
34
34
|
import Panel from './Panel.vue';
|
|
35
35
|
|
|
36
36
|
const core = createMakoo();
|
|
37
|
-
core.useAdapter(createVueAdapter());
|
|
38
37
|
|
|
39
38
|
core.apply([
|
|
40
39
|
inject({
|
|
41
40
|
name: 'panel',
|
|
42
41
|
injectAt: '#sidebar',
|
|
43
|
-
adapter:
|
|
42
|
+
adapter: vueAdapter,
|
|
44
43
|
component: Panel,
|
|
45
44
|
// remount after the site replaces #sidebar
|
|
46
45
|
reinject: true,
|
|
@@ -66,25 +65,47 @@ core.apply([
|
|
|
66
65
|
]);
|
|
67
66
|
```
|
|
68
67
|
|
|
68
|
+
### Mount on Every Match
|
|
69
|
+
|
|
70
|
+
`injectEach()` mounts the same component on every element matching `injectAt`, including elements that appear later, and keeps watching while nothing matches:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { injectEach } from '@makoojs/core';
|
|
74
|
+
import { vueAdapter } from '@makoojs/vue';
|
|
75
|
+
import Badge from './Badge.vue';
|
|
76
|
+
|
|
77
|
+
core.apply([
|
|
78
|
+
injectEach({
|
|
79
|
+
name: 'badges',
|
|
80
|
+
injectAt: '.comment .author',
|
|
81
|
+
adapter: vueAdapter,
|
|
82
|
+
component: Badge
|
|
83
|
+
})
|
|
84
|
+
]);
|
|
85
|
+
```
|
|
86
|
+
|
|
69
87
|
### Control Injections and Read Status
|
|
70
88
|
|
|
71
|
-
|
|
89
|
+
Get injections by name with `core.injection(name)` for Components and Each Injections, or `core.listener(name)` for Standalone Listeners. Use `kind` to distinguish a Component (`component`) from an Each Injection (`component-each`). An Each Injection lists its Children in document order through `children`.
|
|
72
90
|
|
|
73
91
|
```ts
|
|
74
|
-
const panel = core.
|
|
75
|
-
const
|
|
92
|
+
const panel = core.injection('panel');
|
|
93
|
+
const escape = core.listener('escape');
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
console.log(status
|
|
95
|
+
panel.subscribe(() => {
|
|
96
|
+
console.log(panel.status, panel.lastError);
|
|
79
97
|
});
|
|
80
98
|
|
|
81
|
-
|
|
99
|
+
panel.stop();
|
|
82
100
|
panel.start();
|
|
101
|
+
escape.stop();
|
|
83
102
|
```
|
|
84
103
|
|
|
104
|
+
The top-level injection controls `start()`, `stop()`, and `remove()` return nothing. Read the outcome of `start()` and `stop()` from `status` and `lastError`; after `remove()`, the name is no longer registered on the instance.
|
|
105
|
+
|
|
85
106
|
## Documentation
|
|
86
107
|
|
|
87
108
|
- [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
|
-
- [
|
|
109
|
+
- [Declarations](https://makoojs.github.io/Makoo/api/declarations): all fields of `inject()`, `injectEach()`, and `listen()`.
|
|
110
|
+
- [Control and Status](https://makoojs.github.io/Makoo/api/status): starting, stopping, removing, and what each status value means.
|
|
90
111
|
- [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,16 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentInjection } from '../injections/inject/inject';
|
|
2
|
+
import { ChildInjection } from '../injections/injectEach/injectEach';
|
|
3
|
+
import { ListenerInjection } from '../injections/listen/listen';
|
|
4
|
+
/** What Core passes to {@link MountAdapter.mount} for one mount. */
|
|
3
5
|
export interface AdapterMountParams<TComponent = unknown, TProps = unknown> {
|
|
6
|
+
/** The `component` from the declaration, unchanged. */
|
|
4
7
|
component: TComponent;
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The component injection being mounted; same object as `core.injection(name)` for a
|
|
10
|
+
* top-level injection, or the Child Injection object (without `start`/`remove`) for a mount
|
|
11
|
+
* under an Each Injection.
|
|
12
|
+
*/
|
|
13
|
+
injection: ComponentInjection | ChildInjection;
|
|
14
|
+
/** The `props` from the declaration, unchanged. */
|
|
7
15
|
props: TProps | undefined;
|
|
16
|
+
/** The component container Core created inside the mount target; Core removes it after unmount. */
|
|
8
17
|
container: HTMLElement;
|
|
9
|
-
/**
|
|
10
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Looks up a standalone listener in the owning Core Instance.
|
|
20
|
+
*
|
|
21
|
+
* @throws `MakooError` with `MAKOO_INJECTION_NOT_FOUND` when no standalone listener has that
|
|
22
|
+
* name.
|
|
23
|
+
*/
|
|
24
|
+
listener(name: string): ListenerInjection;
|
|
11
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Integrates a frontend framework with Core's component mounting.
|
|
28
|
+
*
|
|
29
|
+
* @typeParam THandle - Whatever `mount` returns; Core passes it back to `unmount` untouched.
|
|
30
|
+
*/
|
|
12
31
|
export interface MountAdapter<TComponent = unknown, TProps = unknown, THandle = unknown> {
|
|
13
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Mounts the component into `params.container` synchronously; a throw is an execution failure
|
|
34
|
+
* (`MAKOO_MOUNT_FAILED`).
|
|
35
|
+
*/
|
|
14
36
|
mount(params: AdapterMountParams<TComponent, TProps>): THandle;
|
|
37
|
+
/** Unmounts what `mount` created; a throw is a cleanup failure. */
|
|
15
38
|
unmount(mountHandle: THandle): void;
|
|
16
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* What a mounted component can do to its own injection: only the commands meaningful while it
|
|
42
|
+
* is mounted. An Each Child has no `start` / `remove`; `kind` narrows the union.
|
|
43
|
+
*/
|
|
44
|
+
export type MountedInjection = Pick<ComponentInjection, 'kind' | 'name' | 'remove' | 'stop'> | Pick<ChildInjection, 'kind' | 'name' | 'stop'>;
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/** How a Makoo error reaches the user: thrown, written to state, or reported as a diagnostic. */
|
|
2
|
+
export type ErrorCategory = 'configuration' | 'control' | 'execution' | 'cleanup' | 'callback';
|
|
2
3
|
type MakooErrorOptions = {
|
|
3
4
|
readonly code: string;
|
|
5
|
+
readonly category?: ErrorCategory;
|
|
4
6
|
readonly cause?: unknown;
|
|
7
|
+
readonly details?: unknown;
|
|
8
|
+
readonly errors?: readonly unknown[];
|
|
5
9
|
};
|
|
10
|
+
/** The error type Core throws and reports; match on `code`, not on `message`. */
|
|
6
11
|
export declare class MakooError extends Error {
|
|
12
|
+
/** The delivery channel this error belongs to; set when created through an error table. */
|
|
13
|
+
readonly category?: ErrorCategory;
|
|
14
|
+
/** Identifies the problem: a code from the owning package's error table. */
|
|
7
15
|
readonly code: string;
|
|
16
|
+
/** Structured, serializable context for the code; set when created through an error table. */
|
|
17
|
+
readonly details?: unknown;
|
|
18
|
+
/** Collected failures for aggregate codes, in the order they happened. */
|
|
19
|
+
readonly errors?: readonly unknown[];
|
|
8
20
|
constructor(message: string, options: MakooErrorOptions);
|
|
9
21
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
22
|
+
/** Whether the value carries the Makoo error mark; reliable across bundled copies. */
|
|
23
|
+
export declare function isMakooError(value: unknown): value is MakooError;
|
|
24
|
+
/** Appends one line per direct error to the headline of an aggregate error. */
|
|
25
|
+
export declare function aggregateMessage(message: string, errors: readonly unknown[]): string;
|
|
19
26
|
export {};
|