@alloy-js/core 0.4.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/CHANGELOG.md +53 -0
- package/babel.config.cjs +4 -1
- package/dist/src/binder.d.ts +20 -13
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +33 -15
- package/dist/src/binder.js.map +1 -1
- package/dist/src/code.d.ts +2 -2
- package/dist/src/code.d.ts.map +1 -1
- package/dist/src/code.js +4 -4
- package/dist/src/code.js.map +1 -1
- package/dist/src/components/Block.d.ts +25 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +25 -0
- package/dist/src/components/Block.js.map +1 -0
- 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 +4 -0
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/For.d.ts +44 -0
- package/dist/src/components/For.d.ts.map +1 -0
- package/dist/src/components/For.js +41 -0
- package/dist/src/components/For.js.map +1 -0
- package/dist/src/components/Indent.d.ts +6 -10
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/Indent.js +7 -18
- package/dist/src/components/Indent.js.map +1 -1
- package/dist/src/components/List.d.ts +38 -0
- package/dist/src/components/List.d.ts.map +1 -0
- package/dist/src/components/List.js +40 -0
- package/dist/src/components/List.js.map +1 -0
- package/dist/src/components/MemberDeclaration.d.ts +1 -1
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/MemberName.d.ts +1 -1
- package/dist/src/components/MemberName.d.ts.map +1 -1
- package/dist/src/components/MemberName.js +1 -1
- package/dist/src/components/MemberName.js.map +1 -1
- package/dist/src/components/MemberScope.d.ts +1 -1
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js.map +1 -1
- package/dist/src/components/Name.d.ts +1 -1
- package/dist/src/components/Name.d.ts.map +1 -1
- package/dist/src/components/Name.js +1 -1
- package/dist/src/components/Name.js.map +1 -1
- package/dist/src/components/Output.d.ts +3 -2
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +12 -2
- package/dist/src/components/Output.js.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/Scope.js.map +1 -1
- package/dist/src/components/Show.d.ts +8 -0
- package/dist/src/components/Show.d.ts.map +1 -0
- package/dist/src/components/Show.js +4 -0
- package/dist/src/components/Show.js.map +1 -0
- package/dist/src/components/SourceDirectory.d.ts +2 -2
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -0
- package/dist/src/components/SourceDirectory.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +4 -8
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +6 -13
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/StatementList.d.ts +9 -0
- package/dist/src/components/StatementList.d.ts.map +1 -0
- package/dist/src/components/StatementList.js +17 -0
- package/dist/src/components/StatementList.js.map +1 -0
- package/dist/src/components/Switch.d.ts +41 -0
- package/dist/src/components/Switch.d.ts.map +1 -0
- package/dist/src/components/Switch.js +41 -0
- package/dist/src/components/Switch.js.map +1 -0
- package/dist/src/components/Wrap.d.ts +20 -0
- package/dist/src/components/Wrap.d.ts.map +1 -0
- package/dist/src/components/Wrap.js +15 -0
- package/dist/src/components/Wrap.js.map +1 -0
- package/dist/src/components/index.d.ts +8 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +89 -18
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +17 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/context/index.d.ts +0 -1
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +0 -1
- package/dist/src/context/index.js.map +1 -1
- package/dist/src/context/member-declaration.d.ts +1 -0
- package/dist/src/context/member-declaration.d.ts.map +1 -1
- package/dist/src/context/member-declaration.js +4 -1
- package/dist/src/context/member-declaration.js.map +1 -1
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +3 -3
- package/dist/src/context.js.map +1 -1
- package/dist/src/index.browser.d.ts +3 -0
- package/dist/src/index.browser.d.ts.map +1 -0
- package/dist/src/index.browser.js +3 -0
- package/dist/src/index.browser.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/jsx-runtime.d.ts +151 -7
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +113 -12
- package/dist/src/jsx-runtime.js.map +1 -1
- package/dist/src/render.d.ts +107 -132
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +272 -178
- package/dist/src/render.js.map +1 -1
- package/dist/src/stc.d.ts +14 -0
- package/dist/src/stc.d.ts.map +1 -0
- package/dist/src/stc.js +52 -0
- package/dist/src/stc.js.map +1 -0
- package/dist/src/tap.d.ts +19 -0
- package/dist/src/tap.d.ts.map +1 -0
- package/dist/src/tap.js +39 -0
- package/dist/src/tap.js.map +1 -0
- package/dist/src/utils.d.ts +22 -15
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +95 -59
- package/dist/src/utils.js.map +1 -1
- package/dist/test/browser-build.test.d.ts +2 -0
- package/dist/test/browser-build.test.d.ts.map +1 -0
- package/dist/test/components/block.test.d.ts +2 -0
- package/dist/test/components/block.test.d.ts.map +1 -0
- package/dist/test/components/declaration.test.d.ts +2 -0
- package/dist/test/components/declaration.test.d.ts.map +1 -0
- package/dist/test/components/list.test.d.ts +2 -0
- package/dist/test/components/list.test.d.ts.map +1 -0
- package/dist/test/components/wrap.test.d.ts +2 -0
- package/dist/test/components/wrap.test.d.ts.map +1 -0
- package/dist/test/control-flow/for.test.d.ts +2 -0
- package/dist/test/control-flow/for.test.d.ts.map +1 -0
- package/dist/test/control-flow/match.test.d.ts +2 -0
- package/dist/test/control-flow/match.test.d.ts.map +1 -0
- package/dist/test/control-flow/show.test.d.ts +2 -0
- package/dist/test/control-flow/show.test.d.ts.map +1 -0
- package/dist/test/reactivity/cleanup.test.d.ts +2 -0
- package/dist/test/reactivity/cleanup.test.d.ts.map +1 -0
- package/dist/test/reactivity/memo.test.d.ts +2 -0
- package/dist/test/reactivity/memo.test.d.ts.map +1 -0
- package/dist/test/reactivity/untrack.test.d.ts +2 -0
- package/dist/test/reactivity/untrack.test.d.ts.map +1 -0
- package/dist/test/rendering/formatting.test.d.ts +2 -0
- package/dist/test/rendering/formatting.test.d.ts.map +1 -0
- package/dist/test/rendering/memoization.test.d.ts +2 -0
- package/dist/test/rendering/memoization.test.d.ts.map +1 -0
- package/dist/test/split-props.test.d.ts +2 -0
- package/dist/test/split-props.test.d.ts.map +1 -0
- package/dist/test/stc.test.d.ts.map +1 -1
- package/dist/test/utils.test.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +4 -4
- package/dist/testing/extend-expect.js.map +1 -1
- package/dist/testing/render.d.ts +2 -3
- package/dist/testing/render.d.ts.map +1 -1
- package/dist/testing/render.js +2 -4
- package/dist/testing/render.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -9
- package/src/binder.ts +60 -50
- package/src/code.ts +17 -12
- package/src/components/Block.tsx +44 -0
- package/src/components/Declaration.tsx +10 -4
- package/src/components/For.tsx +81 -0
- package/src/components/Indent.tsx +20 -27
- package/src/components/List.tsx +94 -0
- package/src/components/MemberDeclaration.tsx +9 -6
- package/src/components/MemberScope.tsx +4 -2
- package/src/components/Output.tsx +27 -14
- package/src/components/Scope.tsx +4 -2
- package/src/components/Show.tsx +11 -0
- package/src/components/SourceDirectory.tsx +6 -2
- package/src/components/SourceFile.tsx +13 -17
- package/src/components/StatementList.tsx +16 -0
- package/src/components/Switch.tsx +62 -0
- package/src/components/Wrap.tsx +29 -0
- package/src/components/index.tsx +8 -1
- package/src/components/stc/index.ts +18 -1
- package/src/context/index.ts +0 -1
- package/src/context/member-declaration.ts +9 -1
- package/src/context.ts +2 -3
- package/src/index.browser.ts +2 -0
- package/src/index.ts +2 -0
- package/src/jsx-runtime.ts +265 -23
- package/src/render.ts +382 -200
- package/src/stc.ts +95 -0
- package/src/tap.ts +69 -0
- package/src/utils.ts +162 -95
- package/temp/api.json +8042 -1886
- package/test/browser-build.test.ts +91 -0
- package/test/children.test.tsx +8 -10
- package/test/components/block.test.tsx +48 -0
- package/test/components/declaration.test.tsx +37 -0
- package/test/components/list.test.tsx +91 -0
- package/test/components/slot.test.tsx +31 -25
- package/test/components/source-file.test.tsx +11 -31
- package/test/components/wrap.test.tsx +42 -0
- package/test/control-flow/for.test.tsx +194 -0
- package/test/control-flow/match.test.tsx +49 -0
- package/test/control-flow/show.test.tsx +25 -0
- package/test/name-policy.test.tsx +5 -5
- package/test/reactivity/cleanup.test.tsx +91 -0
- package/test/reactivity/memo.test.tsx +17 -0
- package/test/reactivity/ref-rendering.test.tsx +3 -8
- package/test/reactivity/test.test.tsx +7 -6
- package/test/reactivity/untrack.test.ts +33 -0
- package/test/rendering/basic.test.tsx +25 -47
- package/test/rendering/code.test.tsx +3 -3
- package/test/rendering/formatting.test.tsx +487 -0
- package/test/rendering/indent.test.tsx +42 -529
- package/test/rendering/memoization.test.tsx +30 -0
- package/test/split-props.test.ts +87 -0
- package/test/stc.test.tsx +29 -8
- package/test/symbols.test.ts +132 -3
- package/test/utils.test.tsx +129 -20
- package/testing/extend-expect.ts +14 -4
- package/testing/render.ts +2 -4
- package/testing/vitest.d.ts +6 -1
- package/vitest.config.ts +1 -1
- package/dist/src/context/indent.d.ts +0 -5
- package/dist/src/context/indent.d.ts.map +0 -1
- package/dist/src/context/indent.js +0 -8
- package/dist/src/context/indent.js.map +0 -1
- package/dist/test/rendering/linebreaks.test.d.ts +0 -2
- package/dist/test/rendering/linebreaks.test.d.ts.map +0 -1
- package/src/context/indent.ts +0 -17
- package/test/rendering/linebreaks.test.tsx +0 -72
package/src/jsx-runtime.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
// Much of the implementations in this file are inspired by vuerx-js
|
|
2
2
|
// See: https://github.com/ryansolid/vuerx-jsx.
|
|
3
3
|
import {
|
|
4
|
+
isReactive,
|
|
4
5
|
pauseTracking,
|
|
6
|
+
proxyRefs,
|
|
5
7
|
Ref,
|
|
6
8
|
resetTracking,
|
|
7
9
|
shallowRef,
|
|
8
10
|
stop,
|
|
11
|
+
toRefs,
|
|
9
12
|
effect as vueEffect,
|
|
10
13
|
} from "@vue/reactivity";
|
|
11
14
|
import { Refkey } from "./refkey.js";
|
|
15
|
+
import { RenderedTextTree } from "./render.js";
|
|
12
16
|
|
|
13
17
|
if ((globalThis as any).ALLOY) {
|
|
14
18
|
throw new Error(
|
|
@@ -31,6 +35,11 @@ export interface Context {
|
|
|
31
35
|
// store random info about the node
|
|
32
36
|
meta?: Record<string, any>;
|
|
33
37
|
|
|
38
|
+
/**
|
|
39
|
+
* A cache of RenderTextTree nodes created within this context,
|
|
40
|
+
* indexed by the component or function which created them.
|
|
41
|
+
*/
|
|
42
|
+
elementCache: ElementCache;
|
|
34
43
|
/**
|
|
35
44
|
* When this context was created by a component, this will
|
|
36
45
|
* be the component that created it.
|
|
@@ -43,21 +52,35 @@ export function getContext() {
|
|
|
43
52
|
return globalContext;
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
export function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
export function getElementCache() {
|
|
56
|
+
return getContext()!.elementCache;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type ElementCacheKey =
|
|
60
|
+
| ComponentCreator
|
|
61
|
+
| (() => unknown)
|
|
62
|
+
| CustomContext;
|
|
63
|
+
export type ElementCache = Map<ElementCacheKey, RenderedTextTree>;
|
|
64
|
+
|
|
65
|
+
export interface RootOptions {
|
|
66
|
+
componentOwner?: ComponentCreator<any>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function root<T>(fn: (d: Disposable) => T, options?: RootOptions): T {
|
|
70
|
+
const context: Context = {
|
|
71
|
+
componentOwner: options?.componentOwner,
|
|
52
72
|
disposables: [],
|
|
53
73
|
owner: globalContext,
|
|
54
74
|
context: {},
|
|
75
|
+
elementCache: new Map(),
|
|
55
76
|
};
|
|
77
|
+
|
|
78
|
+
globalContext = context;
|
|
56
79
|
let ret;
|
|
57
80
|
try {
|
|
58
81
|
ret = untrack(() =>
|
|
59
82
|
fn(() => {
|
|
60
|
-
for (const d of
|
|
83
|
+
for (const d of context!.disposables) {
|
|
61
84
|
d();
|
|
62
85
|
}
|
|
63
86
|
}),
|
|
@@ -83,28 +106,31 @@ export function memo<T>(fn: () => T, equal?: boolean): () => T {
|
|
|
83
106
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
84
107
|
(!equal || prev !== res) && (o.value = res);
|
|
85
108
|
return res;
|
|
86
|
-
});
|
|
109
|
+
}, undefined as T);
|
|
87
110
|
return () => o.value;
|
|
88
111
|
}
|
|
89
112
|
|
|
90
113
|
export function effect<T>(fn: (prev?: T) => T, current?: T) {
|
|
91
|
-
const context = {
|
|
92
|
-
src: "effect",
|
|
114
|
+
const context: Context = {
|
|
93
115
|
context: {},
|
|
94
116
|
disposables: [] as (() => void)[],
|
|
95
117
|
owner: globalContext,
|
|
96
|
-
|
|
118
|
+
elementCache: new Map(),
|
|
119
|
+
};
|
|
97
120
|
|
|
98
121
|
const cleanupFn = (final: boolean) => {
|
|
99
122
|
const d = context.disposables;
|
|
100
123
|
context.disposables = [];
|
|
101
124
|
for (let k = 0, len = d.length; k < len; k++) d[k]();
|
|
125
|
+
|
|
102
126
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
103
127
|
final && stop(c);
|
|
104
128
|
};
|
|
105
129
|
|
|
130
|
+
onCleanup(() => cleanupFn(true));
|
|
106
131
|
const c = vueEffect(() => {
|
|
107
132
|
cleanupFn(false);
|
|
133
|
+
|
|
108
134
|
const oldContext = globalContext;
|
|
109
135
|
globalContext = context;
|
|
110
136
|
try {
|
|
@@ -112,41 +138,90 @@ export function effect<T>(fn: (prev?: T) => T, current?: T) {
|
|
|
112
138
|
} finally {
|
|
113
139
|
globalContext = oldContext;
|
|
114
140
|
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
cleanup(() => cleanupFn(true));
|
|
141
|
+
}, {});
|
|
118
142
|
}
|
|
119
143
|
|
|
120
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Register a cleanup function which is called when the current reactive scope
|
|
146
|
+
* is recalculated or disposed. This is useful to clean up any side effects
|
|
147
|
+
* created in the reactive scope.
|
|
148
|
+
*
|
|
149
|
+
* @remarks
|
|
150
|
+
*
|
|
151
|
+
* When onCleanup is called inside a component definition, the provided function
|
|
152
|
+
* is called when the component is removed from the tree. This can be useful to
|
|
153
|
+
* clean up any side effects created as a result of rendering the component. For
|
|
154
|
+
* example, if rendering a component creates a symbol, `onCleanup` can be used
|
|
155
|
+
* to remove the symbol when the component is removed from the tree.
|
|
156
|
+
*
|
|
157
|
+
* When onCleanup is called inside a memo or effect, the function is called when
|
|
158
|
+
* the effect is refreshed (e.g. when a memo or computed recalculates) or
|
|
159
|
+
* disposed (e.g. it is no longer needed because it is attached to a component
|
|
160
|
+
* which was removed).
|
|
161
|
+
*/
|
|
162
|
+
export function onCleanup(fn: Disposable) {
|
|
121
163
|
if (globalContext != null) {
|
|
122
164
|
globalContext.disposables.push(fn);
|
|
123
165
|
}
|
|
124
166
|
}
|
|
125
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Create a custom reactive context for the children returned by
|
|
170
|
+
* the provided context.
|
|
171
|
+
*/
|
|
172
|
+
export interface CustomContext {
|
|
173
|
+
[CUSTOM_CONTEXT_SYM]: true;
|
|
174
|
+
useCustomContext: (useCb: CustomContextChildrenCallback) => void;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type CustomContextChildrenCallback = (child: Children) => void;
|
|
178
|
+
const CUSTOM_CONTEXT_SYM = Symbol();
|
|
179
|
+
|
|
180
|
+
export function createCustomContext(
|
|
181
|
+
useCallback: (useChildren: CustomContextChildrenCallback) => void,
|
|
182
|
+
): CustomContext {
|
|
183
|
+
return {
|
|
184
|
+
[CUSTOM_CONTEXT_SYM]: true,
|
|
185
|
+
useCustomContext(useCb: (children: Children) => void): void {
|
|
186
|
+
useCallback(useCb);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function isCustomContext(child: Children): child is CustomContext {
|
|
192
|
+
return (
|
|
193
|
+
typeof child === "object" &&
|
|
194
|
+
child !== null &&
|
|
195
|
+
Object.hasOwn(child, CUSTOM_CONTEXT_SYM)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
126
199
|
export type Child =
|
|
127
200
|
| string
|
|
128
201
|
| boolean
|
|
129
202
|
| number
|
|
130
203
|
| undefined
|
|
131
204
|
| null
|
|
132
|
-
|
|
|
133
|
-
|
|
|
205
|
+
| void
|
|
206
|
+
| (() => Children)
|
|
134
207
|
| Ref
|
|
135
|
-
| Refkey
|
|
208
|
+
| Refkey
|
|
209
|
+
| CustomContext
|
|
210
|
+
| IntrinsicElement;
|
|
136
211
|
|
|
137
|
-
export type Children = Child |
|
|
138
|
-
export type Props = Record<string,
|
|
212
|
+
export type Children = Child | Children[];
|
|
213
|
+
export type Props = Record<string, any>;
|
|
139
214
|
|
|
140
215
|
export interface ComponentDefinition<TProps = Props> {
|
|
141
|
-
(props: TProps):
|
|
216
|
+
(props: TProps): Children;
|
|
142
217
|
}
|
|
143
218
|
export interface Component<TProps = Props> {
|
|
144
|
-
(props: TProps):
|
|
219
|
+
(props: TProps): Children;
|
|
145
220
|
tag?: symbol;
|
|
146
221
|
}
|
|
147
222
|
export interface ComponentCreator<TProps = Props> {
|
|
148
223
|
component: Component<TProps>;
|
|
149
|
-
():
|
|
224
|
+
(): Children;
|
|
150
225
|
props: Props;
|
|
151
226
|
tag?: symbol;
|
|
152
227
|
}
|
|
@@ -212,6 +287,51 @@ export function isComponentCreator(item: unknown): item is ComponentCreator {
|
|
|
212
287
|
return typeof item === "function" && (item as any).component;
|
|
213
288
|
}
|
|
214
289
|
|
|
290
|
+
/**
|
|
291
|
+
* This namespace is predominantly for interop with React tooling in VSCode
|
|
292
|
+
* and controls the type of JSX elements, components, and the like.
|
|
293
|
+
*/
|
|
294
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
295
|
+
export namespace JSX {
|
|
296
|
+
export interface IntrinsicElements {
|
|
297
|
+
group: { shouldBreak?: boolean; id?: symbol; children: Children };
|
|
298
|
+
line: {};
|
|
299
|
+
br: {};
|
|
300
|
+
hardline: {};
|
|
301
|
+
hbr: {};
|
|
302
|
+
softline: {};
|
|
303
|
+
sbr: {};
|
|
304
|
+
literalline: {};
|
|
305
|
+
lbr: {};
|
|
306
|
+
indent: { children: Children };
|
|
307
|
+
fill: { children: Children };
|
|
308
|
+
breakParent: {};
|
|
309
|
+
ifBreak: { children: Children; flatContents?: Children; groupId?: symbol };
|
|
310
|
+
lineSuffix: { children: Children };
|
|
311
|
+
lineSuffixBoundary: {};
|
|
312
|
+
dedent: { children: Children };
|
|
313
|
+
align:
|
|
314
|
+
| { children: Children; width: number }
|
|
315
|
+
| { children: Children; string: string };
|
|
316
|
+
markAsRoot: { children: Children };
|
|
317
|
+
dedentToRoot: { children: Children };
|
|
318
|
+
}
|
|
319
|
+
export type ElementType = string | ComponentDefinition<any>;
|
|
320
|
+
export type Element = Children;
|
|
321
|
+
export interface ElementChildrenAttribute {
|
|
322
|
+
children: {};
|
|
323
|
+
}
|
|
324
|
+
export interface ElementAttributesProperty {
|
|
325
|
+
props: {};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function jsx(type: Component<any>, props: Record<string, unknown>) {
|
|
330
|
+
return createComponent(type, props);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export const jsxs = jsx;
|
|
334
|
+
|
|
215
335
|
export function createComponent<TProps extends Props = Props>(
|
|
216
336
|
C: Component<TProps>,
|
|
217
337
|
props: TProps,
|
|
@@ -234,6 +354,73 @@ export function taggedComponent<TProps = Props>(
|
|
|
234
354
|
return component;
|
|
235
355
|
}
|
|
236
356
|
|
|
357
|
+
export const intrinsicElementKey = Symbol();
|
|
358
|
+
|
|
359
|
+
export type IndentIntrinsicElement = IntrinsicElementBase<"indent">;
|
|
360
|
+
export type BrIntrinsicElement = IntrinsicElementBase<"br">;
|
|
361
|
+
export type LineIntrinsicElement = IntrinsicElementBase<"line">;
|
|
362
|
+
export type HbrIntrinsicElement = IntrinsicElementBase<"hbr">;
|
|
363
|
+
export type HardlineIntrinsicElement = IntrinsicElementBase<"hardline">;
|
|
364
|
+
export type SbrIntrinsicElement = IntrinsicElementBase<"sbr">;
|
|
365
|
+
export type SoftlineIntrinsicElement = IntrinsicElementBase<"softline">;
|
|
366
|
+
export type GroupIntrinsicElement = IntrinsicElementBase<"group">;
|
|
367
|
+
export type AlignIntrinsicElement = IntrinsicElementBase<"align">;
|
|
368
|
+
export type FillIntrinsicElement = IntrinsicElementBase<"fill">;
|
|
369
|
+
export type BreakParentIntrinsicElement = IntrinsicElementBase<"breakParent">;
|
|
370
|
+
export type LineSuffixIntrinsicElement = IntrinsicElementBase<"lineSuffix">;
|
|
371
|
+
export type LineSuffixBoundaryIntrinsicElement =
|
|
372
|
+
IntrinsicElementBase<"lineSuffixBoundary">;
|
|
373
|
+
export type DedentIntrinsicElement = IntrinsicElementBase<"dedent">;
|
|
374
|
+
export type DedentToRootIntrinsicElement = IntrinsicElementBase<"dedentToRoot">;
|
|
375
|
+
export type MarkAsRootIntrinsicElement = IntrinsicElementBase<"markAsRoot">;
|
|
376
|
+
export type LiterallineIntrinsicElement = IntrinsicElementBase<"literalline">;
|
|
377
|
+
export type LbrIntrinsicElement = IntrinsicElementBase<"lbr">;
|
|
378
|
+
export type IfBreakIntrinsicElement = IntrinsicElementBase<"ifBreak">;
|
|
379
|
+
|
|
380
|
+
export type IntrinsicElement =
|
|
381
|
+
| IndentIntrinsicElement
|
|
382
|
+
| BrIntrinsicElement
|
|
383
|
+
| LineIntrinsicElement
|
|
384
|
+
| HbrIntrinsicElement
|
|
385
|
+
| HardlineIntrinsicElement
|
|
386
|
+
| SbrIntrinsicElement
|
|
387
|
+
| SoftlineIntrinsicElement
|
|
388
|
+
| GroupIntrinsicElement
|
|
389
|
+
| AlignIntrinsicElement
|
|
390
|
+
| FillIntrinsicElement
|
|
391
|
+
| BreakParentIntrinsicElement
|
|
392
|
+
| LineSuffixIntrinsicElement
|
|
393
|
+
| LineSuffixBoundaryIntrinsicElement
|
|
394
|
+
| DedentIntrinsicElement
|
|
395
|
+
| LiterallineIntrinsicElement
|
|
396
|
+
| LbrIntrinsicElement
|
|
397
|
+
| DedentToRootIntrinsicElement
|
|
398
|
+
| MarkAsRootIntrinsicElement
|
|
399
|
+
| IfBreakIntrinsicElement;
|
|
400
|
+
|
|
401
|
+
export interface IntrinsicElementBase<
|
|
402
|
+
TKey extends keyof JSX.IntrinsicElements = keyof JSX.IntrinsicElements,
|
|
403
|
+
> {
|
|
404
|
+
[intrinsicElementKey]: true;
|
|
405
|
+
name: TKey;
|
|
406
|
+
props: JSX.IntrinsicElements[TKey];
|
|
407
|
+
}
|
|
408
|
+
export function createIntrinsic<TKey extends keyof JSX.IntrinsicElements>(
|
|
409
|
+
name: TKey,
|
|
410
|
+
props: JSX.IntrinsicElements[TKey],
|
|
411
|
+
): IntrinsicElementBase<TKey> {
|
|
412
|
+
return {
|
|
413
|
+
[intrinsicElementKey]: true,
|
|
414
|
+
name,
|
|
415
|
+
props,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export function isIntrinsicElement(type: unknown): type is IntrinsicElement {
|
|
420
|
+
return (
|
|
421
|
+
typeof type === "object" && type !== null && intrinsicElementKey in type
|
|
422
|
+
);
|
|
423
|
+
}
|
|
237
424
|
export function mergeProps<T, U>(source: T, source1: U): T & U;
|
|
238
425
|
export function mergeProps<T, U, V>(
|
|
239
426
|
source: T,
|
|
@@ -272,6 +459,61 @@ export function mergeProps(...sources: any): any {
|
|
|
272
459
|
return target;
|
|
273
460
|
}
|
|
274
461
|
|
|
462
|
+
export type SplitProps<T, K extends (readonly (keyof T)[])[]> = [
|
|
463
|
+
...{
|
|
464
|
+
[P in keyof K]: P extends `${number}` ?
|
|
465
|
+
Pick<T, Extract<K[P], readonly (keyof T)[]>[number]>
|
|
466
|
+
: never;
|
|
467
|
+
},
|
|
468
|
+
{ [P in keyof T as Exclude<P, K[number][number]>]: T[P] },
|
|
469
|
+
];
|
|
470
|
+
|
|
471
|
+
export function splitProps<
|
|
472
|
+
T extends Record<any, any>,
|
|
473
|
+
K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]],
|
|
474
|
+
>(props: T, ...keys: K): SplitProps<T, K> {
|
|
475
|
+
if (isReactive(props)) {
|
|
476
|
+
const refs = untrack(() => toRefs(props));
|
|
477
|
+
const remainingKeys = new Set(Object.keys(refs));
|
|
478
|
+
|
|
479
|
+
const result: any = keys.map((keySet) => {
|
|
480
|
+
const resultSet: any = {};
|
|
481
|
+
for (const key of keySet) {
|
|
482
|
+
resultSet[key] = refs[key];
|
|
483
|
+
remainingKeys.delete(key as string);
|
|
484
|
+
}
|
|
485
|
+
return proxyRefs(resultSet);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
const remaining: any = {};
|
|
489
|
+
for (const key of remainingKeys) {
|
|
490
|
+
remaining[key] = refs[key];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return [...result, proxyRefs(remaining)] as any;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const descriptors = Object.getOwnPropertyDescriptors(props);
|
|
497
|
+
const remainingKeys = new Set(Object.keys(descriptors));
|
|
498
|
+
const result: any = keys.map((keySet) => {
|
|
499
|
+
const resultSet: any = {};
|
|
500
|
+
for (const key of keySet) {
|
|
501
|
+
if (key in descriptors) {
|
|
502
|
+
Object.defineProperty(resultSet, key, descriptors[key]);
|
|
503
|
+
remainingKeys.delete(key as string);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return resultSet;
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const remaining: any = {};
|
|
510
|
+
for (const key of remainingKeys) {
|
|
511
|
+
Object.defineProperty(remaining, key, descriptors[key]);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return [...result, remaining] as any;
|
|
515
|
+
}
|
|
516
|
+
|
|
275
517
|
function shouldDebug() {
|
|
276
518
|
return typeof process !== "undefined" && !!process.env?.ALLOY_DEBUG;
|
|
277
519
|
}
|