@aweebit/react-essentials 0.10.4 → 0.10.5
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/README.md +85 -28
- package/dist/misc/wrapJSX.d.ts +8 -8
- package/dist/misc/wrapJSX.d.ts.map +1 -1
- package/dist/misc/wrapJSX.js.map +1 -1
- package/package.json +1 -1
- package/src/misc/wrapJSX.tsx +14 -7
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
const useEventListener: UseEventListener;
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Defined in: [hooks/useEventListener.ts:135](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
23
|
+
Defined in: [hooks/useEventListener.ts:135](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L135)
|
|
24
24
|
|
|
25
25
|
Adds `handler` as a listener for the event `eventName` of `target` with the
|
|
26
26
|
provided `options` applied
|
|
@@ -71,7 +71,7 @@ function useReducerWithDeps<S, A>(
|
|
|
71
71
|
): [S, ActionDispatch<A>];
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
Defined in: [hooks/useReducerWithDeps.ts:59](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
74
|
+
Defined in: [hooks/useReducerWithDeps.ts:59](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useReducerWithDeps.ts#L59)
|
|
75
75
|
|
|
76
76
|
`useReducer` hook with an additional dependency array `deps` that resets the
|
|
77
77
|
state to `initialState` when dependencies change
|
|
@@ -214,7 +214,7 @@ function useStateWithDeps<S>(
|
|
|
214
214
|
): [S, Dispatch<SetStateAction<S>>];
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
217
|
+
Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useStateWithDeps.ts#L62)
|
|
218
218
|
|
|
219
219
|
`useState` hook with an additional dependency array `deps` that resets the
|
|
220
220
|
state to `initialState` when dependencies change
|
|
@@ -344,7 +344,7 @@ Dependencies that reset the state to `initialState`
|
|
|
344
344
|
function contextualize(children): ContextualizePipe;
|
|
345
345
|
```
|
|
346
346
|
|
|
347
|
-
Defined in: [misc/contextualize.tsx:79](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
347
|
+
Defined in: [misc/contextualize.tsx:79](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/contextualize.tsx#L79)
|
|
348
348
|
|
|
349
349
|
An alternative way to provide context values to component trees that avoids
|
|
350
350
|
ever-increasing indentation
|
|
@@ -444,7 +444,7 @@ function createSafeContext<T>(): <DisplayName>(displayName) => {
|
|
|
444
444
|
};
|
|
445
445
|
```
|
|
446
446
|
|
|
447
|
-
Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
447
|
+
Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/createSafeContext.ts#L62)
|
|
448
448
|
|
|
449
449
|
For a given type `T`, returns a function that produces both a context of that
|
|
450
450
|
type and a hook that returns the current context value if one was provided,
|
|
@@ -586,10 +586,10 @@ A function that accepts a single string argument `displayName` (e.g.
|
|
|
586
586
|
## wrapJSX()
|
|
587
587
|
|
|
588
588
|
```ts
|
|
589
|
-
function wrapJSX(children): JSXWrapPipe
|
|
589
|
+
function wrapJSX<Children>(children): JSXWrapPipe<Children>;
|
|
590
590
|
```
|
|
591
591
|
|
|
592
|
-
Defined in: [misc/wrapJSX.tsx:
|
|
592
|
+
Defined in: [misc/wrapJSX.tsx:99](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/wrapJSX.tsx#L99)
|
|
593
593
|
|
|
594
594
|
An alternative way to compose JSX that avoids ever-increasing indentation
|
|
595
595
|
|
|
@@ -629,6 +629,25 @@ createRoot(document.getElementById('root')!).render(
|
|
|
629
629
|
);
|
|
630
630
|
```
|
|
631
631
|
|
|
632
|
+
### Type Parameters
|
|
633
|
+
|
|
634
|
+
<table>
|
|
635
|
+
<thead>
|
|
636
|
+
<tr>
|
|
637
|
+
<th>Type Parameter</th>
|
|
638
|
+
</tr>
|
|
639
|
+
</thead>
|
|
640
|
+
<tbody>
|
|
641
|
+
<tr>
|
|
642
|
+
<td>
|
|
643
|
+
|
|
644
|
+
`Children` _extends_ `ReactNode`
|
|
645
|
+
|
|
646
|
+
</td>
|
|
647
|
+
</tr>
|
|
648
|
+
</tbody>
|
|
649
|
+
</table>
|
|
650
|
+
|
|
632
651
|
### Parameters
|
|
633
652
|
|
|
634
653
|
<table>
|
|
@@ -648,7 +667,7 @@ createRoot(document.getElementById('root')!).render(
|
|
|
648
667
|
</td>
|
|
649
668
|
<td>
|
|
650
669
|
|
|
651
|
-
`
|
|
670
|
+
`Children`
|
|
652
671
|
|
|
653
672
|
</td>
|
|
654
673
|
<td>
|
|
@@ -662,7 +681,7 @@ The children to wrap
|
|
|
662
681
|
|
|
663
682
|
### Returns
|
|
664
683
|
|
|
665
|
-
[`JSXWrapPipe`](#jsxwrappipe)
|
|
684
|
+
[`JSXWrapPipe`](#jsxwrappipe)\<`Children`\>
|
|
666
685
|
|
|
667
686
|
An object with the following properties:
|
|
668
687
|
|
|
@@ -685,7 +704,7 @@ type UseEventListener = UseEventListenerWithImplicitWindowTarget &
|
|
|
685
704
|
UseEventListenerWithAnyExplicitTarget;
|
|
686
705
|
```
|
|
687
706
|
|
|
688
|
-
Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
707
|
+
Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L12)
|
|
689
708
|
|
|
690
709
|
The type of [`useEventListener`](#useeventlistener)
|
|
691
710
|
|
|
@@ -704,7 +723,7 @@ The type of [`useEventListener`](#useeventlistener)
|
|
|
704
723
|
type UseEventListenerWithImplicitWindowTarget = <K>(...args) => void;
|
|
705
724
|
```
|
|
706
725
|
|
|
707
|
-
Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
726
|
+
Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L21)
|
|
708
727
|
|
|
709
728
|
### Type Parameters
|
|
710
729
|
|
|
@@ -772,7 +791,7 @@ type UseEventListenerWithExplicitGlobalTarget =
|
|
|
772
791
|
UseEventListenerWithExplicitTarget<MathMLElement, MathMLElementEventMap>;
|
|
773
792
|
```
|
|
774
793
|
|
|
775
|
-
Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
794
|
+
Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L32)
|
|
776
795
|
|
|
777
796
|
### See
|
|
778
797
|
|
|
@@ -789,7 +808,7 @@ type UseEventListenerWithExplicitTarget<Target, EventMap> = <T, K>(
|
|
|
789
808
|
) => void;
|
|
790
809
|
```
|
|
791
810
|
|
|
792
|
-
Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
811
|
+
Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L44)
|
|
793
812
|
|
|
794
813
|
### Type Parameters
|
|
795
814
|
|
|
@@ -888,7 +907,7 @@ type UseEventListenerWithAnyExplicitTarget = UseEventListenerWithExplicitTarget<
|
|
|
888
907
|
>;
|
|
889
908
|
```
|
|
890
909
|
|
|
891
|
-
Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
910
|
+
Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L56)
|
|
892
911
|
|
|
893
912
|
### See
|
|
894
913
|
|
|
@@ -909,7 +928,7 @@ type UseEventListenerWithImplicitWindowTargetArgs<K> =
|
|
|
909
928
|
: never;
|
|
910
929
|
```
|
|
911
930
|
|
|
912
|
-
Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
931
|
+
Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L64)
|
|
913
932
|
|
|
914
933
|
### Type Parameters
|
|
915
934
|
|
|
@@ -954,7 +973,7 @@ type UseEventListenerWithExplicitTargetArgs<EventMap, T, K> = [
|
|
|
954
973
|
];
|
|
955
974
|
```
|
|
956
975
|
|
|
957
|
-
Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
976
|
+
Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L78)
|
|
958
977
|
|
|
959
978
|
### Type Parameters
|
|
960
979
|
|
|
@@ -1004,7 +1023,7 @@ type ContextualizePipe = {
|
|
|
1004
1023
|
};
|
|
1005
1024
|
```
|
|
1006
1025
|
|
|
1007
|
-
Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
1026
|
+
Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/contextualize.tsx#L13)
|
|
1008
1027
|
|
|
1009
1028
|
The return type of [`contextualize`](#contextualize)
|
|
1010
1029
|
|
|
@@ -1058,7 +1077,7 @@ The return type of [`contextualize`](#contextualize)
|
|
|
1058
1077
|
type ContextualizeWith = <T>(Context, value) => ContextualizePipe;
|
|
1059
1078
|
```
|
|
1060
1079
|
|
|
1061
|
-
Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
1080
|
+
Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/contextualize.tsx#L23)
|
|
1062
1081
|
|
|
1063
1082
|
### Type Parameters
|
|
1064
1083
|
|
|
@@ -1130,13 +1149,13 @@ Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essenti
|
|
|
1130
1149
|
## JSXWrapPipe
|
|
1131
1150
|
|
|
1132
1151
|
```ts
|
|
1133
|
-
type JSXWrapPipe = {
|
|
1134
|
-
with: WrapJSXWith
|
|
1135
|
-
end: () =>
|
|
1152
|
+
type JSXWrapPipe<Children> = {
|
|
1153
|
+
with: WrapJSXWith<Children>;
|
|
1154
|
+
end: () => Children;
|
|
1136
1155
|
};
|
|
1137
1156
|
```
|
|
1138
1157
|
|
|
1139
|
-
Defined in: [misc/wrapJSX.tsx:
|
|
1158
|
+
Defined in: [misc/wrapJSX.tsx:19](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/wrapJSX.tsx#L19)
|
|
1140
1159
|
|
|
1141
1160
|
The return type of [`wrapJSX`](#wrapjsx)
|
|
1142
1161
|
|
|
@@ -1145,6 +1164,25 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1145
1164
|
[`wrapJSX`](#wrapjsx),
|
|
1146
1165
|
[`WrapJSXWith`](#wrapjsxwith)
|
|
1147
1166
|
|
|
1167
|
+
### Type Parameters
|
|
1168
|
+
|
|
1169
|
+
<table>
|
|
1170
|
+
<thead>
|
|
1171
|
+
<tr>
|
|
1172
|
+
<th>Type Parameter</th>
|
|
1173
|
+
</tr>
|
|
1174
|
+
</thead>
|
|
1175
|
+
<tbody>
|
|
1176
|
+
<tr>
|
|
1177
|
+
<td>
|
|
1178
|
+
|
|
1179
|
+
`Children` _extends_ `ReactNode`
|
|
1180
|
+
|
|
1181
|
+
</td>
|
|
1182
|
+
</tr>
|
|
1183
|
+
</tbody>
|
|
1184
|
+
</table>
|
|
1185
|
+
|
|
1148
1186
|
### Properties
|
|
1149
1187
|
|
|
1150
1188
|
<table>
|
|
@@ -1163,7 +1201,7 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1163
1201
|
</td>
|
|
1164
1202
|
<td>
|
|
1165
1203
|
|
|
1166
|
-
[`WrapJSXWith`](#wrapjsxwith)
|
|
1204
|
+
[`WrapJSXWith`](#wrapjsxwith)\<`Children`\>
|
|
1167
1205
|
|
|
1168
1206
|
</td>
|
|
1169
1207
|
</tr>
|
|
@@ -1175,7 +1213,7 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1175
1213
|
</td>
|
|
1176
1214
|
<td>
|
|
1177
1215
|
|
|
1178
|
-
() => `
|
|
1216
|
+
() => `Children`
|
|
1179
1217
|
|
|
1180
1218
|
</td>
|
|
1181
1219
|
</tr>
|
|
@@ -1187,10 +1225,29 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1187
1225
|
## WrapJSXWith()
|
|
1188
1226
|
|
|
1189
1227
|
```ts
|
|
1190
|
-
type WrapJSXWith = <C>(...args) => JSXWrapPipe
|
|
1228
|
+
type WrapJSXWith<Children> = <C>(...args) => JSXWrapPipe<ReactElement>;
|
|
1191
1229
|
```
|
|
1192
1230
|
|
|
1193
|
-
Defined in: [misc/wrapJSX.tsx:
|
|
1231
|
+
Defined in: [misc/wrapJSX.tsx:29](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/wrapJSX.tsx#L29)
|
|
1232
|
+
|
|
1233
|
+
### Type Parameters
|
|
1234
|
+
|
|
1235
|
+
<table>
|
|
1236
|
+
<thead>
|
|
1237
|
+
<tr>
|
|
1238
|
+
<th>Type Parameter</th>
|
|
1239
|
+
</tr>
|
|
1240
|
+
</thead>
|
|
1241
|
+
<tbody>
|
|
1242
|
+
<tr>
|
|
1243
|
+
<td>
|
|
1244
|
+
|
|
1245
|
+
`Children` _extends_ `ReactNode`
|
|
1246
|
+
|
|
1247
|
+
</td>
|
|
1248
|
+
</tr>
|
|
1249
|
+
</tbody>
|
|
1250
|
+
</table>
|
|
1194
1251
|
|
|
1195
1252
|
### Type Parameters
|
|
1196
1253
|
|
|
@@ -1229,7 +1286,7 @@ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/bl
|
|
|
1229
1286
|
</td>
|
|
1230
1287
|
<td>
|
|
1231
1288
|
|
|
1232
|
-
\[`C`, `...(Record<never, unknown> extends Omit<ComponentProps<C>, "children"> ? [props?: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">] : [props: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">])`\]
|
|
1289
|
+
\[`"children"` _extends_ keyof `ComponentProps`\<`C`\> ? \[`Children`\] _extends_ \[`ComponentProps`\<`C`\>\[`"children"`\]\] ? `C` : `never` : `never`, `...(Record<never, unknown> extends Omit<ComponentProps<C>, "children"> ? [props?: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">] : [props: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">])`\]
|
|
1233
1290
|
|
|
1234
1291
|
</td>
|
|
1235
1292
|
</tr>
|
|
@@ -1238,7 +1295,7 @@ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/bl
|
|
|
1238
1295
|
|
|
1239
1296
|
### Returns
|
|
1240
1297
|
|
|
1241
|
-
[`JSXWrapPipe`](#jsxwrappipe)
|
|
1298
|
+
[`JSXWrapPipe`](#jsxwrappipe)\<`ReactElement`\>
|
|
1242
1299
|
|
|
1243
1300
|
### See
|
|
1244
1301
|
|
package/dist/misc/wrapJSX.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentProps, JSXElementConstructor, default as React, ReactNode } from 'react';
|
|
1
|
+
import type { ComponentProps, JSXElementConstructor, default as React, ReactElement, ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* The return type of {@linkcode wrapJSX}
|
|
4
4
|
*
|
|
@@ -6,23 +6,23 @@ import type { ComponentProps, JSXElementConstructor, default as React, ReactNode
|
|
|
6
6
|
* {@linkcode wrapJSX},
|
|
7
7
|
* {@linkcode WrapJSXWith}
|
|
8
8
|
*/
|
|
9
|
-
export type JSXWrapPipe = {
|
|
10
|
-
with: WrapJSXWith
|
|
11
|
-
end: () =>
|
|
9
|
+
export type JSXWrapPipe<Children extends ReactNode> = {
|
|
10
|
+
with: WrapJSXWith<Children>;
|
|
11
|
+
end: () => Children;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* @see
|
|
15
15
|
* {@linkcode wrapJSX},
|
|
16
16
|
* {@linkcode JSXWrapPipe}
|
|
17
17
|
*/
|
|
18
|
-
export type WrapJSXWith = <C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>>(...args: [
|
|
19
|
-
Component: C,
|
|
18
|
+
export type WrapJSXWith<Children extends ReactNode> = <C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>>(...args: [
|
|
19
|
+
Component: 'children' extends keyof ComponentProps<C> ? [Children] extends [ComponentProps<C>['children']] ? C : never : never,
|
|
20
20
|
...(Record<never, unknown> extends Omit<ComponentProps<C>, 'children'> ? [
|
|
21
21
|
props?: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
|
|
22
22
|
] : [
|
|
23
23
|
props: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
|
|
24
24
|
])
|
|
25
|
-
]) => JSXWrapPipe
|
|
25
|
+
]) => JSXWrapPipe<ReactElement>;
|
|
26
26
|
/**
|
|
27
27
|
* An alternative way to compose JSX that avoids ever-increasing indentation
|
|
28
28
|
*
|
|
@@ -72,5 +72,5 @@ export type WrapJSXWith = <C extends keyof JSX.IntrinsicElements | JSXElementCon
|
|
|
72
72
|
* @see
|
|
73
73
|
* {@linkcode JSXWrapPipe}
|
|
74
74
|
*/
|
|
75
|
-
export declare function wrapJSX(children:
|
|
75
|
+
export declare function wrapJSX<Children extends ReactNode>(children: Children): JSXWrapPipe<Children>;
|
|
76
76
|
//# sourceMappingURL=wrapJSX.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapJSX.d.ts","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,OAAO,IAAI,KAAK,EAChB,SAAS,EACV,MAAM,OAAO,CAAC;AAKf;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"wrapJSX.d.ts","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,OAAO,IAAI,KAAK,EAChB,YAAY,EACZ,SAAS,EACV,MAAM,OAAO,CAAC;AAKf;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,SAAS,IAAI;IACpD,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,SAAS,IAEhD,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,GAAG,CAAC,EACjE,GAAG,IAAI,EAAE;IACP,SAAS,EAAE,UAAU,SAAS,MAAM,cAAc,CAAC,CAAC,CAAC,GACjD,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,GAChD,CAAC,GACD,KAAK,GACP,KAAK;IACT,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAClE;QACE,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,mBAAmB,GACnC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;KACtC,GACD;QACE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,mBAAmB,GAClC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;KACtC,CAAC;CACP,KACE,WAAW,CAAC,YAAY,CAAC,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,OAAO,CAAC,QAAQ,SAAS,SAAS,EAChD,QAAQ,EAAE,QAAQ,GACjB,WAAW,CAAC,QAAQ,CAAC,CAcvB"}
|
package/dist/misc/wrapJSX.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapJSX.js","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"wrapJSX.js","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":";AAiDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,OAAO,CACrB,QAAkB;IAElB,OAAO;QACL,IAAI,CACF,SAEiC,EACjC,QAAgB,EAAE;YAElB,OAAO,OAAO,CAAC,KAAC,SAAS,OAAK,KAAK,YAAG,QAAQ,GAAa,CAAC,CAAC;QAC/D,CAAC;QACD,GAAG;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/misc/wrapJSX.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
ComponentProps,
|
|
3
3
|
JSXElementConstructor,
|
|
4
4
|
default as React,
|
|
5
|
+
ReactElement,
|
|
5
6
|
ReactNode,
|
|
6
7
|
} from 'react';
|
|
7
8
|
|
|
@@ -15,9 +16,9 @@ import type { contextualize } from './contextualize.js';
|
|
|
15
16
|
* {@linkcode wrapJSX},
|
|
16
17
|
* {@linkcode WrapJSXWith}
|
|
17
18
|
*/
|
|
18
|
-
export type JSXWrapPipe = {
|
|
19
|
-
with: WrapJSXWith
|
|
20
|
-
end: () =>
|
|
19
|
+
export type JSXWrapPipe<Children extends ReactNode> = {
|
|
20
|
+
with: WrapJSXWith<Children>;
|
|
21
|
+
end: () => Children;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -25,11 +26,15 @@ export type JSXWrapPipe = {
|
|
|
25
26
|
* {@linkcode wrapJSX},
|
|
26
27
|
* {@linkcode JSXWrapPipe}
|
|
27
28
|
*/
|
|
28
|
-
export type WrapJSXWith =
|
|
29
|
+
export type WrapJSXWith<Children extends ReactNode> =
|
|
29
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
31
|
<C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>>(
|
|
31
32
|
...args: [
|
|
32
|
-
Component: C
|
|
33
|
+
Component: 'children' extends keyof ComponentProps<C>
|
|
34
|
+
? [Children] extends [ComponentProps<C>['children']]
|
|
35
|
+
? C
|
|
36
|
+
: never
|
|
37
|
+
: never,
|
|
33
38
|
...(Record<never, unknown> extends Omit<ComponentProps<C>, 'children'>
|
|
34
39
|
? [
|
|
35
40
|
props?: React.JSX.IntrinsicAttributes &
|
|
@@ -40,7 +45,7 @@ export type WrapJSXWith =
|
|
|
40
45
|
Omit<ComponentProps<C>, 'children'>,
|
|
41
46
|
]),
|
|
42
47
|
]
|
|
43
|
-
) => JSXWrapPipe
|
|
48
|
+
) => JSXWrapPipe<ReactElement>;
|
|
44
49
|
|
|
45
50
|
/**
|
|
46
51
|
* An alternative way to compose JSX that avoids ever-increasing indentation
|
|
@@ -91,7 +96,9 @@ export type WrapJSXWith =
|
|
|
91
96
|
* @see
|
|
92
97
|
* {@linkcode JSXWrapPipe}
|
|
93
98
|
*/
|
|
94
|
-
export function wrapJSX
|
|
99
|
+
export function wrapJSX<Children extends ReactNode>(
|
|
100
|
+
children: Children,
|
|
101
|
+
): JSXWrapPipe<Children> {
|
|
95
102
|
return {
|
|
96
103
|
with(
|
|
97
104
|
Component:
|