@alloy-js/core 0.17.0 → 0.18.0-dev.2
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/dist/src/binder.d.ts +2 -1
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +2 -2
- package/dist/src/code.d.ts +1 -1
- package/dist/src/code.d.ts.map +1 -1
- package/dist/src/components/Block.d.ts +1 -1
- package/dist/src/components/Block.d.ts.map +1 -1
- package/dist/src/components/Declaration.d.ts +1 -1
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +1 -1
- package/dist/src/components/For.d.ts +1 -1
- package/dist/src/components/For.d.ts.map +1 -1
- package/dist/src/components/For.js +1 -1
- package/dist/src/components/Indent.d.ts +1 -1
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/List.d.ts +1 -1
- package/dist/src/components/List.d.ts.map +1 -1
- package/dist/src/components/List.js +2 -1
- package/dist/src/components/MemberDeclaration.d.ts +2 -2
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +2 -1
- package/dist/src/components/MemberScope.d.ts +2 -2
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/Output.d.ts +1 -1
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +1 -1
- package/dist/src/components/Prose.d.ts +1 -1
- package/dist/src/components/Prose.d.ts.map +1 -1
- package/dist/src/components/ReferenceOrContent.d.ts +1 -1
- package/dist/src/components/ReferenceOrContent.d.ts.map +1 -1
- package/dist/src/components/Scope.d.ts +1 -1
- package/dist/src/components/Scope.d.ts.map +1 -1
- package/dist/src/components/Show.d.ts +1 -1
- package/dist/src/components/Show.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.d.ts +1 -1
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -1
- package/dist/src/components/SourceFile.d.ts +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +1 -1
- package/dist/src/components/StatementList.d.ts +1 -1
- package/dist/src/components/StatementList.d.ts.map +1 -1
- package/dist/src/components/Switch.d.ts +2 -2
- package/dist/src/components/Switch.d.ts.map +1 -1
- package/dist/src/components/Switch.js +2 -1
- package/dist/src/components/Wrap.d.ts +1 -1
- package/dist/src/components/Wrap.d.ts.map +1 -1
- package/dist/src/context/binder.d.ts +1 -1
- package/dist/src/context/binder.d.ts.map +1 -1
- package/dist/src/context/source-file.d.ts +1 -1
- package/dist/src/context/source-file.d.ts.map +1 -1
- package/dist/src/context.d.ts +2 -2
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +1 -1
- package/dist/src/debug.d.ts +1 -0
- package/dist/src/debug.d.ts.map +1 -1
- package/dist/src/debug.js +4 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -1
- package/dist/src/jsx-runtime.d.ts +4 -281
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +3 -319
- package/dist/src/props-combinators.d.ts +19 -0
- package/dist/src/props-combinators.d.ts.map +1 -0
- package/dist/src/props-combinators.js +108 -0
- package/dist/src/reactive-union-set.d.ts.map +1 -1
- package/dist/src/reactive-union-set.js +1 -1
- package/dist/src/reactivity.d.ts +75 -0
- package/dist/src/reactivity.d.ts.map +1 -0
- package/dist/src/reactivity.js +141 -0
- package/dist/src/render.d.ts +5 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +68 -15
- package/dist/src/runtime/component.d.ts +24 -0
- package/dist/src/runtime/component.d.ts.map +1 -0
- package/dist/src/runtime/component.js +19 -0
- package/dist/src/runtime/intrinsic.d.ts +168 -0
- package/dist/src/runtime/intrinsic.d.ts.map +1 -0
- package/dist/src/runtime/intrinsic.js +11 -0
- package/dist/src/slot.d.ts +2 -2
- package/dist/src/slot.d.ts.map +1 -1
- package/dist/src/slot.js +1 -1
- package/dist/src/stc.d.ts +1 -1
- package/dist/src/stc.d.ts.map +1 -1
- package/dist/src/sti.d.ts +7 -6
- package/dist/src/sti.d.ts.map +1 -1
- package/dist/src/sti.js +1 -1
- package/dist/src/symbols/flags.d.ts +70 -0
- package/dist/src/symbols/flags.d.ts.map +1 -0
- package/dist/src/symbols/flags.js +72 -0
- package/dist/src/symbols/index.d.ts +1 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +1 -0
- package/dist/src/symbols/output-scope.d.ts +2 -24
- package/dist/src/symbols/output-scope.d.ts.map +1 -1
- package/dist/src/symbols/output-scope.js +1 -25
- package/dist/src/symbols/output-symbol.d.ts +2 -47
- package/dist/src/symbols/output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/output-symbol.js +2 -48
- package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
- package/dist/src/symbols/symbol-flow.js +2 -2
- package/dist/src/symbols/symbol-slot.d.ts +1 -1
- package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
- package/dist/src/symbols/symbol-slot.js +1 -1
- package/dist/src/symbols/symbol-table.d.ts +3 -3
- package/dist/src/symbols/symbol-table.d.ts.map +1 -1
- package/dist/src/tap.d.ts +1 -1
- package/dist/src/tap.d.ts.map +1 -1
- package/dist/src/tracer.d.ts +60 -3
- package/dist/src/tracer.d.ts.map +1 -1
- package/dist/src/tracer.js +60 -5
- package/dist/src/utils.d.ts +4 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +2 -1
- package/dist/test/props-with-defaults.test.js +1 -1
- package/dist/test/reactive-union-set.test.js +1 -1
- package/dist/test/reactivity/cleanup.test.js +2 -1
- package/dist/test/reactivity/memo.test.js +1 -1
- package/dist/test/reactivity/untrack.test.js +1 -1
- package/dist/test/rendering/memoization.test.js +2 -1
- package/dist/test/split-props.test.js +1 -1
- package/dist/test/symbols/output-scope.test.js +2 -1
- package/dist/test/symbols/output-symbol.test.js +4 -3
- package/dist/test/symbols/resolution.test.js +2 -1
- package/dist/test/symbols/utils.d.ts +3 -2
- package/dist/test/symbols/utils.d.ts.map +1 -1
- package/dist/test/symbols/utils.js +2 -1
- package/dist/testing/extend-expect.d.ts +15 -0
- package/dist/testing/extend-expect.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +2 -1
- package/dist/testing/render.d.ts +1 -1
- package/dist/testing/render.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -24
- package/src/binder.ts +3 -5
- package/src/code.ts +1 -1
- package/src/components/Block.tsx +1 -1
- package/src/components/Declaration.tsx +2 -1
- package/src/components/For.tsx +2 -1
- package/src/components/Indent.tsx +1 -1
- package/src/components/List.tsx +3 -1
- package/src/components/MemberDeclaration.tsx +4 -3
- package/src/components/MemberScope.tsx +2 -2
- package/src/components/Output.tsx +2 -1
- package/src/components/Prose.tsx +1 -1
- package/src/components/ReferenceOrContent.tsx +1 -1
- package/src/components/Scope.tsx +1 -1
- package/src/components/Show.tsx +1 -1
- package/src/components/SourceDirectory.tsx +2 -1
- package/src/components/SourceFile.tsx +2 -1
- package/src/components/StatementList.tsx +1 -1
- package/src/components/Switch.tsx +2 -1
- package/src/components/Wrap.tsx +1 -1
- package/src/context/binder.ts +1 -1
- package/src/context/source-file.ts +1 -1
- package/src/context.ts +3 -7
- package/src/debug.ts +5 -1
- package/src/index.ts +4 -1
- package/src/jsx-runtime.ts +15 -690
- package/src/props-combinators.ts +148 -0
- package/src/reactive-union-set.ts +1 -1
- package/src/reactivity.ts +230 -0
- package/src/render.ts +97 -26
- package/src/runtime/component.ts +67 -0
- package/src/runtime/intrinsic.ts +199 -0
- package/src/slot.ts +3 -4
- package/src/stc.ts +2 -2
- package/src/sti.ts +11 -11
- package/src/symbols/flags.ts +82 -0
- package/src/symbols/index.ts +1 -0
- package/src/symbols/output-scope.ts +2 -29
- package/src/symbols/output-symbol.ts +2 -55
- package/src/symbols/symbol-flow.ts +3 -7
- package/src/symbols/symbol-slot.tsx +2 -1
- package/src/symbols/symbol-table.ts +3 -3
- package/src/tap.ts +1 -1
- package/src/tracer.ts +38 -4
- package/src/utils.tsx +7 -5
- package/temp/api.json +984 -1261
- package/test/props-with-defaults.test.ts +1 -1
- package/test/reactive-union-set.test.tsx +1 -1
- package/test/reactivity/cleanup.test.tsx +2 -1
- package/test/reactivity/memo.test.tsx +1 -1
- package/test/reactivity/untrack.test.ts +1 -1
- package/test/rendering/basic.test.tsx +1 -1
- package/test/rendering/memoization.test.tsx +1 -1
- package/test/split-props.test.ts +1 -1
- package/test/symbols/output-scope.test.ts +2 -4
- package/test/symbols/output-symbol.test.ts +4 -7
- package/test/symbols/resolution.test.ts +2 -4
- package/test/symbols/utils.ts +3 -5
- package/test/utils.test.tsx +1 -1
- package/testing/extend-expect.ts +16 -0
- package/testing/render.ts +1 -2
- package/LICENSE +0 -7
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { computed, isReactive, proxyRefs, toRefs } from "@vue/reactivity";
|
|
2
|
+
import { untrack } from "./reactivity.js";
|
|
3
|
+
export function mergeProps(...sources) {
|
|
4
|
+
const target = {};
|
|
5
|
+
for (let i = 0; i < sources.length; i++) {
|
|
6
|
+
let source = sources[i];
|
|
7
|
+
if (typeof source === "function") source = source();
|
|
8
|
+
if (source) {
|
|
9
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
10
|
+
for (const key in descriptors) {
|
|
11
|
+
if (key in target) continue;
|
|
12
|
+
Object.defineProperty(target, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get() {
|
|
15
|
+
for (let i = sources.length - 1; i >= 0; i--) {
|
|
16
|
+
let s = sources[i];
|
|
17
|
+
if (typeof s === "function") s = s();
|
|
18
|
+
const v = (s || {})[key];
|
|
19
|
+
if (v !== undefined) return v;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
export function splitProps(props, ...keys) {
|
|
29
|
+
if (isReactive(props)) {
|
|
30
|
+
const refs = untrack(() => toRefs(props));
|
|
31
|
+
const remainingKeys = new Set(Object.keys(refs));
|
|
32
|
+
const result = keys.map(keySet => {
|
|
33
|
+
const resultSet = {};
|
|
34
|
+
for (const key of keySet) {
|
|
35
|
+
resultSet[key] = refs[key];
|
|
36
|
+
remainingKeys.delete(key);
|
|
37
|
+
}
|
|
38
|
+
return proxyRefs(resultSet);
|
|
39
|
+
});
|
|
40
|
+
const remaining = {};
|
|
41
|
+
for (const key of remainingKeys) {
|
|
42
|
+
remaining[key] = refs[key];
|
|
43
|
+
}
|
|
44
|
+
return [...result, proxyRefs(remaining)];
|
|
45
|
+
}
|
|
46
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
47
|
+
const remainingKeys = new Set(Object.keys(descriptors));
|
|
48
|
+
const result = keys.map(keySet => {
|
|
49
|
+
const resultSet = {};
|
|
50
|
+
for (const key of keySet) {
|
|
51
|
+
if (key in descriptors) {
|
|
52
|
+
Object.defineProperty(resultSet, key, descriptors[key]);
|
|
53
|
+
remainingKeys.delete(key);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return resultSet;
|
|
57
|
+
});
|
|
58
|
+
const remaining = {};
|
|
59
|
+
for (const key of remainingKeys) {
|
|
60
|
+
Object.defineProperty(remaining, key, descriptors[key]);
|
|
61
|
+
}
|
|
62
|
+
return [...result, remaining];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Applies default values to a props object. Reactive props are handled properly
|
|
67
|
+
* by ensuring that their value is not accessed by `defaultProps`, avoiding any
|
|
68
|
+
* unintended side effects.
|
|
69
|
+
*/
|
|
70
|
+
export function defaultProps(props, defaults) {
|
|
71
|
+
if (isReactive(props)) {
|
|
72
|
+
const refs = untrack(() => toRefs(props));
|
|
73
|
+
for (const key in defaults) {
|
|
74
|
+
const originalRef = refs[key];
|
|
75
|
+
refs[key] = computed(() => originalRef.value === undefined ? defaults[key] : originalRef.value);
|
|
76
|
+
}
|
|
77
|
+
return proxyRefs(refs);
|
|
78
|
+
}
|
|
79
|
+
const withDefaults = {};
|
|
80
|
+
const copied = new Set();
|
|
81
|
+
for (const key in defaults) {
|
|
82
|
+
copied.add(key);
|
|
83
|
+
const desc = Object.getOwnPropertyDescriptor(props, key);
|
|
84
|
+
if (!desc) {
|
|
85
|
+
withDefaults[key] = defaults[key];
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (desc.get) {
|
|
89
|
+
const originalGet = desc.get;
|
|
90
|
+
desc.get = function () {
|
|
91
|
+
const value = originalGet.call(this);
|
|
92
|
+
return value === undefined ? defaults[key] : value;
|
|
93
|
+
};
|
|
94
|
+
Object.defineProperty(withDefaults, key, desc);
|
|
95
|
+
} else {
|
|
96
|
+
desc.value = desc.value === undefined ? defaults[key] : desc.value;
|
|
97
|
+
Object.defineProperty(withDefaults, key, desc);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
101
|
+
for (const key in descriptors) {
|
|
102
|
+
if (copied.has(key)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
Object.defineProperty(withDefaults, key, descriptors[key]);
|
|
106
|
+
}
|
|
107
|
+
return withDefaults;
|
|
108
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive-union-set.d.ts","sourceRoot":"","sources":["../../src/reactive-union-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactive-union-set.d.ts","sourceRoot":"","sources":["../../src/reactive-union-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EAOd,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,2BAA2B,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAChE,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAE1D,qBAAa,gBAAgB,CAAC,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,MAAM,CAAC,CAA8B;IAC7C,OAAO,CAAC,SAAS,CAAC,CAAiC;IACnD,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,QAAQ,CAA6D;IAE7E,CAAC,aAAa,CAAC,WAAW,CAAC,UAAQ;IAEnC,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,aAAa;gBAYT,OAAO,GAAE,uBAAuB,CAAC,CAAC,CAAM;IAUpD,IAAI,IAAI,WAGP;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC;IAKnC,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC;IAKtB,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC;IAKxB,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAK9B,GAAG,CAAC,IAAI,EAAE,CAAC;IAaX,MAAM,CAAC,IAAI,EAAE,CAAC;IAkBd,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,uBAAuB,CAAC,CAAC,CAAM;IAsClE,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IAsDjD,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;CA4BjE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { effect } from "@alloy-js/core/jsx-runtime";
|
|
2
1
|
import { ITERATE_KEY, ReactiveFlags, shallowReactive, shallowReadonly, track, TrackOpTypes, trigger, TriggerOpTypes } from "@vue/reactivity";
|
|
2
|
+
import { effect } from "./reactivity.js";
|
|
3
3
|
export class ReactiveUnionSet extends Set {
|
|
4
4
|
_refcounts = new Map();
|
|
5
5
|
_indexes = [];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ShallowReactive } from "@vue/reactivity";
|
|
2
|
+
import type { RenderedTextTree } from "./render.js";
|
|
3
|
+
import type { Children, ComponentCreator } from "./runtime/component.js";
|
|
4
|
+
import type { OutputSymbol } from "./symbols/output-symbol.js";
|
|
5
|
+
export declare function getElementCache(): ElementCache;
|
|
6
|
+
export type ElementCacheKey = ComponentCreator | (() => unknown) | CustomContext;
|
|
7
|
+
export type ElementCache = Map<ElementCacheKey, RenderedTextTree>;
|
|
8
|
+
export interface Disposable {
|
|
9
|
+
(): void;
|
|
10
|
+
}
|
|
11
|
+
export interface Context {
|
|
12
|
+
disposables: Disposable[];
|
|
13
|
+
owner: Context | null;
|
|
14
|
+
context?: Record<symbol, unknown>;
|
|
15
|
+
meta?: Record<string, any>;
|
|
16
|
+
/**
|
|
17
|
+
* A cache of RenderTextTree nodes created within this context,
|
|
18
|
+
* indexed by the component or function which created them.
|
|
19
|
+
*/
|
|
20
|
+
elementCache: ElementCache;
|
|
21
|
+
/**
|
|
22
|
+
* When this context was created by a component, this will
|
|
23
|
+
* be the component that created it.
|
|
24
|
+
*/
|
|
25
|
+
componentOwner?: ComponentCreator<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this context will take an emitted symbol.
|
|
28
|
+
*/
|
|
29
|
+
takesSymbols: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The symbol that this component has taken.
|
|
32
|
+
*/
|
|
33
|
+
takenSymbols?: ShallowReactive<Set<OutputSymbol>>;
|
|
34
|
+
}
|
|
35
|
+
export declare function getContext(): Context | null;
|
|
36
|
+
export interface RootOptions {
|
|
37
|
+
componentOwner?: ComponentCreator<any>;
|
|
38
|
+
}
|
|
39
|
+
export declare function root<T>(fn: (d: Disposable) => T, options?: RootOptions): T;
|
|
40
|
+
export declare function untrack<T>(fn: () => T): T;
|
|
41
|
+
export declare function memo<T>(fn: () => T, equal?: boolean): () => T;
|
|
42
|
+
export declare function effect<T>(fn: (prev?: T) => T, current?: T): void;
|
|
43
|
+
/**
|
|
44
|
+
* Register a cleanup function which is called when the current reactive scope
|
|
45
|
+
* is recalculated or disposed. This is useful to clean up any side effects
|
|
46
|
+
* created in the reactive scope.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
*
|
|
50
|
+
* When onCleanup is called inside a component definition, the provided function
|
|
51
|
+
* is called when the component is removed from the tree. This can be useful to
|
|
52
|
+
* clean up any side effects created as a result of rendering the component. For
|
|
53
|
+
* example, if rendering a component creates a symbol, `onCleanup` can be used
|
|
54
|
+
* to remove the symbol when the component is removed from the tree.
|
|
55
|
+
*
|
|
56
|
+
* When onCleanup is called inside a memo or effect, the function is called when
|
|
57
|
+
* the effect is refreshed (e.g. when a memo or computed recalculates) or
|
|
58
|
+
* disposed (e.g. it is no longer needed because it is attached to a component
|
|
59
|
+
* which was removed).
|
|
60
|
+
*/
|
|
61
|
+
export declare function onCleanup(fn: Disposable): void;
|
|
62
|
+
/**
|
|
63
|
+
* Create a custom reactive context for the children returned by
|
|
64
|
+
* the provided context.
|
|
65
|
+
*/
|
|
66
|
+
export interface CustomContext {
|
|
67
|
+
[CUSTOM_CONTEXT_SYM]: true;
|
|
68
|
+
useCustomContext: (useCb: CustomContextChildrenCallback) => void;
|
|
69
|
+
}
|
|
70
|
+
export type CustomContextChildrenCallback = (child: Children) => void;
|
|
71
|
+
declare const CUSTOM_CONTEXT_SYM: unique symbol;
|
|
72
|
+
export declare function createCustomContext(useCallback: (useChildren: CustomContextChildrenCallback) => void): CustomContext;
|
|
73
|
+
export declare function isCustomContext(child: Children): child is CustomContext;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=reactivity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactivity.d.ts","sourceRoot":"","sources":["../../src/reactivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAW/D,wBAAgB,eAAe,iBAE9B;AAED,MAAM,MAAM,eAAe,GACvB,gBAAgB,GAChB,CAAC,MAAM,OAAO,CAAC,GACf,aAAa,CAAC;AAElB,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;AAElE,MAAM,WAAW,UAAU;IACzB,IAAI,IAAI,CAAC;CACV;AAED,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAGtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAGlC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3B;;;OAGG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;;OAGG;IACH,cAAc,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE3C;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;CACnD;AAGD,wBAAgB,UAAU,mBAEzB;AAED,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;CACxC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,CA0B1E;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAKzC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,CAS7D;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,QAiDzD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,UAAU,QAIvC;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC;IAC3B,gBAAgB,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,IAAI,CAAC;CAClE;AAED,MAAM,MAAM,6BAA6B,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AACtE,QAAA,MAAM,kBAAkB,eAAW,CAAC;AAEpC,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,CAAC,WAAW,EAAE,6BAA6B,KAAK,IAAI,GAChE,aAAa,CAOf;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,IAAI,aAAa,CAMvE"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { pauseTracking, resetTracking, shallowRef, stop, effect as vueEffect } from "@vue/reactivity";
|
|
2
|
+
import { scheduler } from "./scheduler.js";
|
|
3
|
+
import { trace, TracePhase } from "./tracer.js";
|
|
4
|
+
|
|
5
|
+
// check for multiple versions of alloy here.
|
|
6
|
+
if (globalThis.__ALLOY__) {
|
|
7
|
+
throw new Error("Multiple versions of Alloy are loaded for this project. This will likely cause undesirable behavior.");
|
|
8
|
+
}
|
|
9
|
+
globalThis.__ALLOY__ = true;
|
|
10
|
+
export function getElementCache() {
|
|
11
|
+
return getContext().elementCache;
|
|
12
|
+
}
|
|
13
|
+
let globalContext = null;
|
|
14
|
+
export function getContext() {
|
|
15
|
+
return globalContext;
|
|
16
|
+
}
|
|
17
|
+
export function root(fn, options) {
|
|
18
|
+
const context = {
|
|
19
|
+
componentOwner: options?.componentOwner,
|
|
20
|
+
disposables: [],
|
|
21
|
+
owner: globalContext,
|
|
22
|
+
context: {},
|
|
23
|
+
elementCache: new Map(),
|
|
24
|
+
takesSymbols: false,
|
|
25
|
+
takenSymbols: undefined
|
|
26
|
+
};
|
|
27
|
+
globalContext = context;
|
|
28
|
+
let ret;
|
|
29
|
+
try {
|
|
30
|
+
ret = untrack(() => fn(() => {
|
|
31
|
+
for (const d of context.disposables) {
|
|
32
|
+
d();
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
} finally {
|
|
36
|
+
globalContext = globalContext.owner;
|
|
37
|
+
}
|
|
38
|
+
return ret;
|
|
39
|
+
}
|
|
40
|
+
export function untrack(fn) {
|
|
41
|
+
pauseTracking();
|
|
42
|
+
const v = fn();
|
|
43
|
+
resetTracking();
|
|
44
|
+
return v;
|
|
45
|
+
}
|
|
46
|
+
export function memo(fn, equal) {
|
|
47
|
+
const o = shallowRef();
|
|
48
|
+
effect(prev => {
|
|
49
|
+
const res = fn();
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
51
|
+
(!equal || prev !== res) && (o.value = res);
|
|
52
|
+
return res;
|
|
53
|
+
}, undefined);
|
|
54
|
+
return () => o.value;
|
|
55
|
+
}
|
|
56
|
+
export function effect(fn, current) {
|
|
57
|
+
const context = {
|
|
58
|
+
context: {},
|
|
59
|
+
disposables: [],
|
|
60
|
+
owner: globalContext,
|
|
61
|
+
elementCache: new Map(),
|
|
62
|
+
takesSymbols: false,
|
|
63
|
+
takenSymbols: undefined
|
|
64
|
+
};
|
|
65
|
+
const cleanupFn = final => {
|
|
66
|
+
const d = context.disposables;
|
|
67
|
+
context.disposables = [];
|
|
68
|
+
for (let k = 0, len = d.length; k < len; k++) d[k]();
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
71
|
+
final && stop(runner);
|
|
72
|
+
};
|
|
73
|
+
onCleanup(() => cleanupFn(true));
|
|
74
|
+
const runner = vueEffect(() => {
|
|
75
|
+
cleanupFn(false);
|
|
76
|
+
const oldContext = globalContext;
|
|
77
|
+
globalContext = context;
|
|
78
|
+
try {
|
|
79
|
+
current = fn(current);
|
|
80
|
+
} finally {
|
|
81
|
+
globalContext = oldContext;
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
84
|
+
scheduler: scheduler(() => runner),
|
|
85
|
+
onTrack(event) {
|
|
86
|
+
trace(TracePhase.effect.track, () => {
|
|
87
|
+
return `tracking ${event.target}, ${event.key}`;
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
onTrigger(event) {
|
|
91
|
+
trace(TracePhase.effect.trigger, () => {
|
|
92
|
+
return `triggering ${event.target}, ${event.key}`;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// allow recursive effects (recursive option does nothing, possible bug)
|
|
98
|
+
runner.effect.flags |= 1 << 5;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Register a cleanup function which is called when the current reactive scope
|
|
103
|
+
* is recalculated or disposed. This is useful to clean up any side effects
|
|
104
|
+
* created in the reactive scope.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
*
|
|
108
|
+
* When onCleanup is called inside a component definition, the provided function
|
|
109
|
+
* is called when the component is removed from the tree. This can be useful to
|
|
110
|
+
* clean up any side effects created as a result of rendering the component. For
|
|
111
|
+
* example, if rendering a component creates a symbol, `onCleanup` can be used
|
|
112
|
+
* to remove the symbol when the component is removed from the tree.
|
|
113
|
+
*
|
|
114
|
+
* When onCleanup is called inside a memo or effect, the function is called when
|
|
115
|
+
* the effect is refreshed (e.g. when a memo or computed recalculates) or
|
|
116
|
+
* disposed (e.g. it is no longer needed because it is attached to a component
|
|
117
|
+
* which was removed).
|
|
118
|
+
*/
|
|
119
|
+
export function onCleanup(fn) {
|
|
120
|
+
if (globalContext != null) {
|
|
121
|
+
globalContext.disposables.push(fn);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Create a custom reactive context for the children returned by
|
|
127
|
+
* the provided context.
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
const CUSTOM_CONTEXT_SYM = Symbol();
|
|
131
|
+
export function createCustomContext(useCallback) {
|
|
132
|
+
return {
|
|
133
|
+
[CUSTOM_CONTEXT_SYM]: true,
|
|
134
|
+
useCustomContext(useCb) {
|
|
135
|
+
useCallback(useCb);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function isCustomContext(child) {
|
|
140
|
+
return typeof child === "object" && child !== null && Object.hasOwn(child, CUSTOM_CONTEXT_SYM);
|
|
141
|
+
}
|
package/dist/src/render.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Doc } from "prettier";
|
|
2
|
-
import {
|
|
2
|
+
import { Context } from "./reactivity.js";
|
|
3
|
+
import { Children, Component, Props } from "./runtime/component.js";
|
|
3
4
|
/**
|
|
4
5
|
* Turning components into source text involves three different trees produced
|
|
5
6
|
* sequentially:
|
|
@@ -119,4 +120,7 @@ export interface PrintTreeOptions {
|
|
|
119
120
|
tabWidth?: number;
|
|
120
121
|
}
|
|
121
122
|
export declare function printTree(tree: RenderedTextTree, options?: PrintTreeOptions): string;
|
|
123
|
+
export declare function pushStack(component: Component<any>, props: Props): void;
|
|
124
|
+
export declare function popStack(): void;
|
|
125
|
+
export declare function printRenderStack(): void;
|
|
122
126
|
//# sourceMappingURL=render.d.ts.map
|
package/dist/src/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAO,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAO,MAAM,UAAU,CAAC;AAKpC,OAAO,EACL,OAAO,EAQR,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,QAAQ,EACR,SAAS,EAET,KAAK,EACN,MAAM,wBAAwB,CAAC;AA0BhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AAEH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,CAAC,eAAe,GAAG,UAAU,CAAC,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAID,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,gBAAgB,uBAE7D;AAED,eAAO,MAAM,YAAY,eAAW,CAAC;AAErC,MAAM,WAAW,SAAS;IACxB,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;IACrB,SAAS,CAAC,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;IACrD,KAAK,CAAC,CACJ,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,GAAG,GACxC,GAAG,CAAC;IACP,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,YAAY,GAAG,SAAS,CAAC,GACtD,SAAS,CAMX;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,SAAS,CAE5D;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC,EAAE,CAAC;AAEzE,wBAAgB,MAAM,CACpB,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,gBAAgB,GACzB,eAAe,CAuFjB;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,oBAY5C;AA4QD,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAOD,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,gBAAgB,UAc3E;AA2BD,wBAAgB,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,QAGhE;AAED,wBAAgB,QAAQ,SAGvB;AAED,wBAAgB,gBAAgB,SAU/B"}
|
package/dist/src/render.js
CHANGED
|
@@ -3,9 +3,13 @@ import { doc } from "prettier";
|
|
|
3
3
|
import prettier from "prettier/doc.js";
|
|
4
4
|
import { useContext } from "./context.js";
|
|
5
5
|
import { SourceFileContext } from "./context/source-file.js";
|
|
6
|
-
import {
|
|
6
|
+
import { shouldDebug } from "./debug.js";
|
|
7
|
+
import { effect, getContext, getElementCache, isCustomContext, root, untrack } from "./reactivity.js";
|
|
7
8
|
import { isRefkey } from "./refkey.js";
|
|
9
|
+
import { isComponentCreator } from "./runtime/component.js";
|
|
10
|
+
import { isIntrinsicElement } from "./runtime/intrinsic.js";
|
|
8
11
|
import { flushJobs } from "./scheduler.js";
|
|
12
|
+
import { trace, TracePhase } from "./tracer.js";
|
|
9
13
|
const {
|
|
10
14
|
builders: {
|
|
11
15
|
align,
|
|
@@ -122,10 +126,6 @@ export function createRenderTreeHook(subtree, hooks) {
|
|
|
122
126
|
export function isPrintHook(type) {
|
|
123
127
|
return typeof type === "object" && type !== null && printHookTag in type;
|
|
124
128
|
}
|
|
125
|
-
function traceRender(phase, message) {
|
|
126
|
-
return false;
|
|
127
|
-
//console.log(`[\x1b[34m${phase}\x1b[0m]: ${message()}`);
|
|
128
|
-
}
|
|
129
129
|
export function render(children, options) {
|
|
130
130
|
const tree = renderTree(children);
|
|
131
131
|
flushJobs();
|
|
@@ -197,7 +197,10 @@ export function renderTree(children) {
|
|
|
197
197
|
return rootElem;
|
|
198
198
|
}
|
|
199
199
|
function renderWorker(node, children) {
|
|
200
|
-
|
|
200
|
+
if (!getContext()) {
|
|
201
|
+
throw new Error("Cannot render without a context. Make sure you are using the Output component.");
|
|
202
|
+
}
|
|
203
|
+
trace(TracePhase.render.worker, () => dumpChildren(children));
|
|
201
204
|
if (Array.isArray(node)) {
|
|
202
205
|
nodesToContext.set(node, getContext());
|
|
203
206
|
}
|
|
@@ -210,19 +213,19 @@ function renderWorker(node, children) {
|
|
|
210
213
|
}
|
|
211
214
|
}
|
|
212
215
|
function appendChild(node, rawChild) {
|
|
213
|
-
|
|
216
|
+
trace(TracePhase.render.appendChild, () => debugPrintChild(rawChild));
|
|
214
217
|
const child = normalizeChild(rawChild);
|
|
215
218
|
if (typeof child === "string") {
|
|
216
219
|
node.push(child);
|
|
217
220
|
} else {
|
|
218
221
|
const cache = getElementCache();
|
|
219
222
|
if (cache.has(child)) {
|
|
220
|
-
|
|
223
|
+
trace(TracePhase.render.appendChild, () => "Cached: " + debugPrintChild(child));
|
|
221
224
|
node.push(cache.get(child));
|
|
222
225
|
return;
|
|
223
226
|
}
|
|
224
227
|
if (isCustomContext(child)) {
|
|
225
|
-
|
|
228
|
+
trace(TracePhase.render.appendChild, () => "CustomContext: " + debugPrintChild(child));
|
|
226
229
|
child.useCustomContext(children => {
|
|
227
230
|
const newNode = [];
|
|
228
231
|
renderWorker(newNode, children);
|
|
@@ -230,8 +233,8 @@ function appendChild(node, rawChild) {
|
|
|
230
233
|
cache.set(child, newNode);
|
|
231
234
|
});
|
|
232
235
|
} else if (isIntrinsicElement(child)) {
|
|
236
|
+
trace(TracePhase.render.appendChild, () => "IntrinsicElement: " + debugPrintChild(child));
|
|
233
237
|
// don't need a new context here because intrinsics are never reactive
|
|
234
|
-
traceRender("appendChild:intrinsic-element", () => debugPrintChild(child));
|
|
235
238
|
const newNode = [];
|
|
236
239
|
function formatHookWithChildren(command) {
|
|
237
240
|
node.push(createRenderTreeHook(newNode, {
|
|
@@ -322,20 +325,20 @@ function appendChild(node, rawChild) {
|
|
|
322
325
|
}
|
|
323
326
|
} else if (isComponentCreator(child)) {
|
|
324
327
|
effect(() => {
|
|
325
|
-
|
|
328
|
+
trace(TracePhase.render.appendChild, () => "Component: " + debugPrintChild(child));
|
|
326
329
|
const componentRoot = [];
|
|
327
330
|
pushStack(child.component, child.props);
|
|
328
331
|
renderWorker(componentRoot, untrack(child));
|
|
329
332
|
popStack();
|
|
330
333
|
node.push(componentRoot);
|
|
331
334
|
cache.set(child, componentRoot);
|
|
332
|
-
|
|
335
|
+
trace(TracePhase.render.appendChild, () => "Component done: " + debugPrintChild(child));
|
|
333
336
|
});
|
|
334
337
|
} else if (typeof child === "function") {
|
|
335
|
-
|
|
338
|
+
trace(TracePhase.render.appendChild, () => "Memo: " + child.toString());
|
|
336
339
|
const index = node.length;
|
|
337
340
|
effect(() => {
|
|
338
|
-
|
|
341
|
+
trace(TracePhase.render.renderEffect, () => "");
|
|
339
342
|
let res = child();
|
|
340
343
|
while (typeof res === "function" && !isComponentCreator(res)) {
|
|
341
344
|
res = res();
|
|
@@ -346,7 +349,6 @@ function appendChild(node, rawChild) {
|
|
|
346
349
|
cache.set(child, newNodes);
|
|
347
350
|
return newNodes;
|
|
348
351
|
});
|
|
349
|
-
traceRender("appendChild:memo-done", () => "");
|
|
350
352
|
} else {
|
|
351
353
|
throw new Error("Unexpected child type");
|
|
352
354
|
}
|
|
@@ -392,6 +394,8 @@ function debugPrintChild(child) {
|
|
|
392
394
|
return "$memo";
|
|
393
395
|
} else if (isRef(child)) {
|
|
394
396
|
return "$ref";
|
|
397
|
+
} else if (isIntrinsicElement(child)) {
|
|
398
|
+
return `<${child.name}>`;
|
|
395
399
|
} else {
|
|
396
400
|
return JSON.stringify(child);
|
|
397
401
|
}
|
|
@@ -424,4 +428,53 @@ function printTreeWorker(tree) {
|
|
|
424
428
|
}
|
|
425
429
|
}
|
|
426
430
|
return doc;
|
|
431
|
+
}
|
|
432
|
+
// debugging utilities
|
|
433
|
+
const renderStack = [];
|
|
434
|
+
export function pushStack(component, props) {
|
|
435
|
+
if (!shouldDebug()) return;
|
|
436
|
+
renderStack.push({
|
|
437
|
+
component,
|
|
438
|
+
props
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
export function popStack() {
|
|
442
|
+
if (!shouldDebug()) return;
|
|
443
|
+
renderStack.pop();
|
|
444
|
+
}
|
|
445
|
+
export function printRenderStack() {
|
|
446
|
+
if (!shouldDebug()) return;
|
|
447
|
+
|
|
448
|
+
// eslint-disable-next-line no-console
|
|
449
|
+
console.error("Error rendering:");
|
|
450
|
+
for (let i = renderStack.length - 1; i >= 0; i--) {
|
|
451
|
+
const {
|
|
452
|
+
component,
|
|
453
|
+
props
|
|
454
|
+
} = renderStack[i];
|
|
455
|
+
// eslint-disable-next-line no-console
|
|
456
|
+
console.error(` at ${component.name}(${inspectProps(props)})`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function inspectProps(props) {
|
|
460
|
+
return JSON.stringify(Object.fromEntries(Object.entries(props).map(([key, value]) => {
|
|
461
|
+
let safeValue;
|
|
462
|
+
switch (typeof value) {
|
|
463
|
+
case "string":
|
|
464
|
+
case "number":
|
|
465
|
+
case "boolean":
|
|
466
|
+
safeValue = value;
|
|
467
|
+
break;
|
|
468
|
+
case "undefined":
|
|
469
|
+
safeValue = "undefined";
|
|
470
|
+
break;
|
|
471
|
+
case "object":
|
|
472
|
+
safeValue = value ? "{...}" : null;
|
|
473
|
+
break;
|
|
474
|
+
case "function":
|
|
475
|
+
safeValue = "function";
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
return [key, safeValue];
|
|
479
|
+
})));
|
|
427
480
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Ref } from "@vue/reactivity";
|
|
2
|
+
import { CustomContext } from "../reactivity.js";
|
|
3
|
+
import { Refkey } from "../refkey.js";
|
|
4
|
+
import { IntrinsicElement } from "./intrinsic.js";
|
|
5
|
+
export type Child = string | boolean | number | undefined | null | void | (() => Children) | Ref | Refkey | CustomContext | IntrinsicElement;
|
|
6
|
+
export type Children = Child | Children[];
|
|
7
|
+
export type Props = Record<string, any>;
|
|
8
|
+
export interface ComponentDefinition<TProps = Props> {
|
|
9
|
+
(props: TProps): Children;
|
|
10
|
+
}
|
|
11
|
+
export interface Component<TProps = Props> {
|
|
12
|
+
(props: TProps): Children;
|
|
13
|
+
tag?: symbol;
|
|
14
|
+
}
|
|
15
|
+
export interface ComponentCreator<TProps = Props> {
|
|
16
|
+
component: Component<TProps>;
|
|
17
|
+
(): Children;
|
|
18
|
+
props: TProps;
|
|
19
|
+
tag?: symbol;
|
|
20
|
+
}
|
|
21
|
+
export declare function isComponentCreator<TProps = any>(item: unknown, component?: Component<TProps>): item is ComponentCreator<TProps>;
|
|
22
|
+
export declare function createComponent<TProps extends Props = Props>(C: Component<TProps>, props: TProps): ComponentCreator<TProps>;
|
|
23
|
+
export declare function taggedComponent<TProps = Props>(tag: symbol, component: Component<TProps>): Component<TProps> & Required<Pick<Component<TProps>, "tag">>;
|
|
24
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/runtime/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,MAAM,KAAK,GACb,MAAM,GACN,OAAO,GACP,MAAM,GACN,SAAS,GACT,IAAI,GACJ,IAAI,GACJ,CAAC,MAAM,QAAQ,CAAC,GAChB,GAAG,GACH,MAAM,GACN,aAAa,GACb,gBAAgB,CAAC;AAErB,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,QAAQ,EAAE,CAAC;AAC1C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExC,MAAM,WAAW,mBAAmB,CAAC,MAAM,GAAG,KAAK;IACjD,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC3B;AACD,MAAM,WAAW,SAAS,CAAC,MAAM,GAAG,KAAK;IACvC,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB,CAAC,MAAM,GAAG,KAAK;IAC9C,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,QAAQ,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,kBAAkB,CAAC,MAAM,GAAG,GAAG,EAC7C,IAAI,EAAE,OAAO,EACb,SAAS,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAC5B,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAKlC;AAED,wBAAgB,eAAe,CAAC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC1D,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,KAAK,EAAE,MAAM,GACZ,gBAAgB,CAAC,MAAM,CAAC,CAS1B;AAED,wBAAgB,eAAe,CAAC,MAAM,GAAG,KAAK,EAC5C,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,GAC3B,SAAS,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,CAG9D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function isComponentCreator(item, component) {
|
|
2
|
+
if (!component) {
|
|
3
|
+
return typeof item === "function" && item.component;
|
|
4
|
+
}
|
|
5
|
+
return typeof item === "function" && item.component === component;
|
|
6
|
+
}
|
|
7
|
+
export function createComponent(C, props) {
|
|
8
|
+
const creator = () => /* */C(props);
|
|
9
|
+
creator.props = props;
|
|
10
|
+
creator.component = C;
|
|
11
|
+
if (C.tag) {
|
|
12
|
+
creator.tag = C.tag;
|
|
13
|
+
}
|
|
14
|
+
return creator;
|
|
15
|
+
}
|
|
16
|
+
export function taggedComponent(tag, component) {
|
|
17
|
+
component.tag = tag;
|
|
18
|
+
return component;
|
|
19
|
+
}
|