@tsrx/preact 0.1.22 → 0.1.25
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/package.json +6 -2
- package/src/dynamic.js +9 -0
- package/src/index.js +1 -1
- package/src/transform.js +1 -4
- package/types/dynamic.d.ts +32 -0
- package/types/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Preact compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.25",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./types/error-boundary.d.ts",
|
|
23
23
|
"default": "./src/error-boundary.js"
|
|
24
24
|
},
|
|
25
|
+
"./dynamic": {
|
|
26
|
+
"types": "./types/dynamic.d.ts",
|
|
27
|
+
"default": "./src/dynamic.js"
|
|
28
|
+
},
|
|
25
29
|
"./ref": {
|
|
26
30
|
"types": "./types/ref.d.ts",
|
|
27
31
|
"default": "./src/ref.js"
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
"dependencies": {
|
|
35
39
|
"esrap": "^2.2.8",
|
|
36
40
|
"zimmerframe": "^1.1.2",
|
|
37
|
-
"@tsrx/core": "0.1.
|
|
41
|
+
"@tsrx/core": "0.1.25"
|
|
38
42
|
},
|
|
39
43
|
"peerDependencies": {
|
|
40
44
|
"preact": ">=10"
|
package/src/dynamic.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {{ is: import('preact').ComponentType<any> | string | null | undefined | false, [key: string]: any }} props
|
|
5
|
+
* @returns {import('preact').VNode | null}
|
|
6
|
+
*/
|
|
7
|
+
export function Dynamic({ is, ...props }) {
|
|
8
|
+
return is ? h(is, props) : null;
|
|
9
|
+
}
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { createVolarMappingsResult, dedupeMappings, parseModule } from '@tsrx/core';
|
|
6
6
|
import { DEFAULT_SUSPENSE_SOURCE, transform } from './transform.js';
|
|
7
7
|
|
|
8
|
+
export { Dynamic } from './dynamic.js';
|
|
8
9
|
export { DEFAULT_SUSPENSE_SOURCE };
|
|
9
10
|
export { isRefProp } from './ref.js';
|
|
10
11
|
|
|
@@ -70,7 +71,6 @@ export function compile_to_volar_mappings(source, filename, options) {
|
|
|
70
71
|
...options,
|
|
71
72
|
collect: true,
|
|
72
73
|
loose: !!options?.loose,
|
|
73
|
-
moduleScopedHookComponents: false,
|
|
74
74
|
typeOnly: true,
|
|
75
75
|
errors,
|
|
76
76
|
comments,
|
package/src/transform.js
CHANGED
|
@@ -32,6 +32,7 @@ const preact_platform = {
|
|
|
32
32
|
imports: {
|
|
33
33
|
fragment: 'preact',
|
|
34
34
|
suspense: DEFAULT_SUSPENSE_SOURCE,
|
|
35
|
+
dynamic: '@tsrx/preact/dynamic',
|
|
35
36
|
errorBoundary: '@tsrx/preact/error-boundary',
|
|
36
37
|
mergeRefs: '@tsrx/preact/ref',
|
|
37
38
|
refProp: '@tsrx/preact/ref',
|
|
@@ -44,10 +45,6 @@ const preact_platform = {
|
|
|
44
45
|
validation: {
|
|
45
46
|
requireUseServerForAwait: false,
|
|
46
47
|
},
|
|
47
|
-
hooks: {
|
|
48
|
-
moduleScopedHookComponents: true,
|
|
49
|
-
componentBodyHookHelpers: true,
|
|
50
|
-
},
|
|
51
48
|
};
|
|
52
49
|
|
|
53
50
|
export const transform = createJsxTransform(preact_platform);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ComponentType, JSX, VNode } from 'preact';
|
|
2
|
+
|
|
3
|
+
type DynamicIntrinsicElements = JSX.IntrinsicElements;
|
|
4
|
+
export type DynamicElementType =
|
|
5
|
+
| keyof DynamicIntrinsicElements
|
|
6
|
+
| ComponentType<any>
|
|
7
|
+
| (string & {});
|
|
8
|
+
type DynamicTarget<T> = Exclude<T, null | undefined | false>;
|
|
9
|
+
type DynamicComponentProps<T> = [T] extends [never]
|
|
10
|
+
? Record<string, unknown>
|
|
11
|
+
: T extends ComponentType<infer P>
|
|
12
|
+
? Omit<P, 'is'>
|
|
13
|
+
: T extends keyof DynamicIntrinsicElements
|
|
14
|
+
? DynamicIntrinsicElements[T]
|
|
15
|
+
: Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
export type DynamicProps<T extends DynamicElementType> = DynamicComponentProps<
|
|
18
|
+
DynamicTarget<NoInfer<T>>
|
|
19
|
+
> & {
|
|
20
|
+
is: T | null | undefined | false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function Dynamic<T extends keyof DynamicIntrinsicElements>(
|
|
24
|
+
props: DynamicIntrinsicElements[T] & {
|
|
25
|
+
is: T | null | undefined | false;
|
|
26
|
+
},
|
|
27
|
+
): VNode | null;
|
|
28
|
+
export function Dynamic<T extends DynamicElementType>(
|
|
29
|
+
props: DynamicComponentProps<DynamicTarget<NoInfer<T>>> & {
|
|
30
|
+
is: T | null | undefined | false;
|
|
31
|
+
},
|
|
32
|
+
): VNode | null;
|
package/types/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export const DEFAULT_SUSPENSE_SOURCE: string;
|
|
|
9
9
|
|
|
10
10
|
export function parse(source: string, filename?: string, options?: ParseOptions): Program;
|
|
11
11
|
|
|
12
|
+
export { Dynamic, type DynamicElementType, type DynamicProps } from './dynamic.js';
|
|
12
13
|
export { isRefProp } from './ref.js';
|
|
13
14
|
|
|
14
15
|
export const compile: CompileFn<CompileOptions & BaseCompileOptions>;
|