@codeinkit/dom-trigger 0.0.0-stage → 0.2.0-alpha.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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +400 -2
- package/dist/cjs/dom-trigger.js +409 -0
- package/dist/cjs/emitter.js +48 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/modules.js +48 -0
- package/dist/cjs/names.js +22 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/dom-trigger.js +405 -0
- package/dist/esm/emitter.js +44 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/modules.js +45 -0
- package/dist/esm/names.js +16 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/types/dom-trigger.d.ts +77 -0
- package/dist/types/emitter.d.ts +24 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/modules.d.ts +10 -0
- package/dist/types/names.d.ts +8 -0
- package/dist/types/types.d.ts +99 -0
- package/package.json +61 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type Concurrency = 'drop' | 'latest' | 'queue' | 'parallel';
|
|
2
|
+
/** one item of a flow module's `triggers` export */
|
|
3
|
+
export interface TriggerDef {
|
|
4
|
+
type: 'dom';
|
|
5
|
+
/** event name without the prefix, e.g. `booking.submit` */
|
|
6
|
+
event: string;
|
|
7
|
+
/** what to do with an event that arrives while a run of this trigger is active. Default `'drop'` */
|
|
8
|
+
concurrency?: Concurrency;
|
|
9
|
+
}
|
|
10
|
+
/** anything zod-like: `safeParse` is preferred, `parse` (throws when invalid) is the fallback */
|
|
11
|
+
export interface SchemaLike<T = unknown> {
|
|
12
|
+
safeParse?(value: unknown): {
|
|
13
|
+
success: boolean;
|
|
14
|
+
data?: T;
|
|
15
|
+
error?: unknown;
|
|
16
|
+
};
|
|
17
|
+
parse?(value: unknown): T;
|
|
18
|
+
}
|
|
19
|
+
export interface ExecuteOptions {
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
runId?: string;
|
|
22
|
+
}
|
|
23
|
+
/** the part of a `Flows` instance the trigger uses. Both `@codeinkit/flows` and `@codeinkit/flows/core` fit */
|
|
24
|
+
export interface FlowsLike {
|
|
25
|
+
execute(name: string, input: any, scope?: any, options?: ExecuteOptions): Promise<unknown>;
|
|
26
|
+
registerModules?(modules: Record<string, unknown>, options?: {
|
|
27
|
+
base?: string;
|
|
28
|
+
}): string[];
|
|
29
|
+
}
|
|
30
|
+
/** the data a UI flow starts with */
|
|
31
|
+
export interface DomTriggerData<D = unknown> {
|
|
32
|
+
event: string;
|
|
33
|
+
detail: D;
|
|
34
|
+
runId: string;
|
|
35
|
+
source: {
|
|
36
|
+
flowId: string;
|
|
37
|
+
route?: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export type RunStatusName = 'running' | 'done' | 'error' | 'cancelled' | 'dropped' | 'invalid';
|
|
41
|
+
export interface RunStatus {
|
|
42
|
+
status: RunStatusName;
|
|
43
|
+
flowId: string;
|
|
44
|
+
event: string;
|
|
45
|
+
runId: string;
|
|
46
|
+
/** the flow's output, on `done` */
|
|
47
|
+
output?: unknown;
|
|
48
|
+
/** the rejection on `error`, the schema error on `invalid`, the abort reason on `cancelled` */
|
|
49
|
+
error?: unknown;
|
|
50
|
+
}
|
|
51
|
+
export interface RunInfo {
|
|
52
|
+
status: 'error' | 'invalid';
|
|
53
|
+
flowId: string;
|
|
54
|
+
event: string;
|
|
55
|
+
runId: string;
|
|
56
|
+
}
|
|
57
|
+
export interface DomTriggerOptions {
|
|
58
|
+
/** where to listen. Default: `globalThis.document`, resolved in `start()`; without one `start()` is a no-op (SSR) */
|
|
59
|
+
target?: EventTarget;
|
|
60
|
+
/** default `'flows:'` */
|
|
61
|
+
prefix?: string;
|
|
62
|
+
/** the unsafe scope of each run, default `{}`. Never put ports here, they belong to `new Flows({ ports })` */
|
|
63
|
+
scope?: () => Record<string, unknown> | undefined;
|
|
64
|
+
/** called for `error` and `invalid`. Default: `console.error` */
|
|
65
|
+
onError?: (error: unknown, info: RunInfo) => void;
|
|
66
|
+
/** default: `globalThis.location?.pathname` */
|
|
67
|
+
route?: () => string | undefined;
|
|
68
|
+
/** default: `crypto.randomUUID()` when available */
|
|
69
|
+
runId?: () => string;
|
|
70
|
+
}
|
|
71
|
+
/** picks flows: a flow id prefix (`'booking/'`), an array of flow ids, or a predicate */
|
|
72
|
+
export type FlowSelector = string | ReadonlyArray<string> | ((flowId: string) => boolean);
|
|
73
|
+
export interface RegisterOptions {
|
|
74
|
+
/** validates (and may transform) the event's `detail` before the flow runs */
|
|
75
|
+
input?: SchemaLike;
|
|
76
|
+
/** only listen while a `trigger.scope(selector)` that selects this flow is held. Default `false` */
|
|
77
|
+
scoped?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface RegisterModulesOptions {
|
|
80
|
+
/** directory prefix removed from every key, e.g. './flows'. Default: the longest directory common to all keys */
|
|
81
|
+
base?: string;
|
|
82
|
+
/** also call `flows.registerModules(modules, { base })` */
|
|
83
|
+
registerFlows?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* `true`: every flow of the glob only listens while a `trigger.scope(selector)` holds it.
|
|
86
|
+
* A selector: only the flows it selects are scoped, the others listen as usual. Default `false`
|
|
87
|
+
*/
|
|
88
|
+
scoped?: boolean | FlowSelector;
|
|
89
|
+
}
|
|
90
|
+
export type EventMap = Record<string, unknown>;
|
|
91
|
+
/** an event map as a type alias or as an interface (an interface has no index signature, so it is not an `EventMap`) */
|
|
92
|
+
export type EventMapLike = object;
|
|
93
|
+
/**
|
|
94
|
+
* DOM event types of an event map, to augment `DocumentEventMap`:
|
|
95
|
+
* `declare global { interface DocumentEventMap extends DomEventMap<AppEvents> {} }`
|
|
96
|
+
*/
|
|
97
|
+
export type DomEventMap<M, P extends string = 'flows:'> = {
|
|
98
|
+
[K in keyof M & string as `${P}${K}`]: CustomEvent<M[K]>;
|
|
99
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeinkit/dom-trigger",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
|
+
"description": "DOM CustomEvent trigger for @codeinkit/flows: run UI flows from `flows:domain.verb` events dispatched on the document.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "codeinkit dev team",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/amitmtrn/dom-trigger.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/amitmtrn/dom-trigger/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/amitmtrn/dom-trigger#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"flows",
|
|
17
|
+
"trigger",
|
|
18
|
+
"dom",
|
|
19
|
+
"customevent",
|
|
20
|
+
"ui"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/cjs/index.js",
|
|
24
|
+
"module": "./dist/esm/index.js",
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"import": "./dist/esm/index.js",
|
|
30
|
+
"require": "./dist/cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"CHANGELOG.md"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"clean": "node scripts/clean.cjs",
|
|
45
|
+
"build": "npm run clean && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && node scripts/postbuild.cjs",
|
|
46
|
+
"typecheck": "tsc --noEmit -p . && tsc --noEmit -p tsconfig.test.json",
|
|
47
|
+
"test": "jest",
|
|
48
|
+
"prepublishOnly": "npm run typecheck && npm run build && npm test"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@codeinkit/flows": "^4.0.0-alpha.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@codeinkit/flows": "4.0.0-alpha.1",
|
|
55
|
+
"@codeinkit/flows-hoa": "0.2.0-alpha.0",
|
|
56
|
+
"@types/jest": "^29.5.14",
|
|
57
|
+
"@types/node": "^22.10.0",
|
|
58
|
+
"jest": "^29.7.0",
|
|
59
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
60
|
+
"ts-jest": "^29.2.5",
|
|
61
|
+
"typescript": "^5.6.3"
|
|
62
|
+
}
|
|
63
|
+
}
|