@tsrx/react 0.2.22 → 0.2.24

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "React compiler built on @tsrx/core",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.22",
6
+ "version": "0.2.24",
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.22"
41
+ "@tsrx/core": "0.1.24"
38
42
  },
39
43
  "peerDependencies": {
40
44
  "react": ">=18"
package/src/dynamic.js ADDED
@@ -0,0 +1,9 @@
1
+ import { createElement } from 'react';
2
+
3
+ /**
4
+ * @param {{ is: import('react').ElementType | null | undefined | false, [key: string]: any }} props
5
+ * @returns {import('react').ReactElement | null}
6
+ */
7
+ export function Dynamic({ is, ...props }) {
8
+ return is ? createElement(is, props) : null;
9
+ }
package/src/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { createVolarMappingsResult, dedupeMappings, parseModule } from '@tsrx/core';
5
5
  import { transform } from './transform.js';
6
6
 
7
+ export { Dynamic } from './dynamic.js';
7
8
  export { isRefProp } from './ref.js';
8
9
 
9
10
  /**
package/src/transform.js CHANGED
@@ -15,6 +15,7 @@ const react_platform = {
15
15
  imports: {
16
16
  fragment: 'react',
17
17
  suspense: 'react',
18
+ dynamic: '@tsrx/react/dynamic',
18
19
  errorBoundary: '@tsrx/react/error-boundary',
19
20
  mergeRefs: '@tsrx/react/ref',
20
21
  refProp: '@tsrx/react/ref',
@@ -0,0 +1,38 @@
1
+ import type { JSX, JSXElementConstructor, ReactElement } from 'react';
2
+
3
+ type DataAttributes = {
4
+ [Key in `data-${string}`]?: string | number | boolean | null | undefined;
5
+ };
6
+
7
+ type DynamicIntrinsicElements = JSX.IntrinsicElements;
8
+ export type DynamicElementType =
9
+ | keyof DynamicIntrinsicElements
10
+ | JSXElementConstructor<any>
11
+ | (string & {});
12
+ type DynamicTarget<T> = Exclude<T, null | undefined | false>;
13
+ type DynamicIntrinsicProps = {
14
+ [T in keyof DynamicIntrinsicElements]: DynamicIntrinsicElements[T] &
15
+ DataAttributes & {
16
+ is: T | null | undefined | false;
17
+ };
18
+ }[keyof DynamicIntrinsicElements];
19
+ type DynamicComponentProps<T> = [T] extends [never]
20
+ ? Record<string, unknown>
21
+ : T extends JSXElementConstructor<infer P>
22
+ ? Omit<P, 'is'>
23
+ : T extends keyof DynamicIntrinsicElements
24
+ ? DynamicIntrinsicElements[T] & DataAttributes
25
+ : Record<string, unknown>;
26
+
27
+ export type DynamicProps<T extends DynamicElementType> = DynamicComponentProps<
28
+ DynamicTarget<NoInfer<T>>
29
+ > & {
30
+ is: T | null | undefined | false;
31
+ };
32
+
33
+ export function Dynamic(props: DynamicIntrinsicProps): ReactElement | null;
34
+ export function Dynamic<T extends DynamicElementType>(
35
+ props: DynamicComponentProps<DynamicTarget<NoInfer<T>>> & {
36
+ is: T | null | undefined | false;
37
+ },
38
+ ): ReactElement | null;
package/types/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { CompileFn, ParseOptions, VolarCompileFn } from '@tsrx/core/types';
3
3
 
4
4
  export function parse(source: string, filename?: string, options?: ParseOptions): Program;
5
5
 
6
+ export { Dynamic, type DynamicProps } from './dynamic.js';
6
7
  export { isRefProp } from './ref.js';
7
8
 
8
9
  export const compile: CompileFn;