@aweebit/react-essentials 0.10.4 → 0.10.6
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 +131 -36
- package/dist/misc/contextualize.d.ts +5 -5
- package/dist/misc/contextualize.d.ts.map +1 -1
- package/dist/misc/contextualize.js.map +1 -1
- 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/contextualize.tsx +7 -5
- 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.6/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.6/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.6/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
|
|
@@ -341,10 +341,10 @@ Dependencies that reset the state to `initialState`
|
|
|
341
341
|
## contextualize()
|
|
342
342
|
|
|
343
343
|
```ts
|
|
344
|
-
function contextualize(children): ContextualizePipe
|
|
344
|
+
function contextualize<Children>(children): ContextualizePipe<Children>;
|
|
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.6/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
|
|
@@ -386,6 +386,25 @@ return contextualize(jsx)
|
|
|
386
386
|
.end();
|
|
387
387
|
```
|
|
388
388
|
|
|
389
|
+
### Type Parameters
|
|
390
|
+
|
|
391
|
+
<table>
|
|
392
|
+
<thead>
|
|
393
|
+
<tr>
|
|
394
|
+
<th>Type Parameter</th>
|
|
395
|
+
</tr>
|
|
396
|
+
</thead>
|
|
397
|
+
<tbody>
|
|
398
|
+
<tr>
|
|
399
|
+
<td>
|
|
400
|
+
|
|
401
|
+
`Children` _extends_ `ReactNode`
|
|
402
|
+
|
|
403
|
+
</td>
|
|
404
|
+
</tr>
|
|
405
|
+
</tbody>
|
|
406
|
+
</table>
|
|
407
|
+
|
|
389
408
|
### Parameters
|
|
390
409
|
|
|
391
410
|
<table>
|
|
@@ -405,7 +424,7 @@ return contextualize(jsx)
|
|
|
405
424
|
</td>
|
|
406
425
|
<td>
|
|
407
426
|
|
|
408
|
-
`
|
|
427
|
+
`Children`
|
|
409
428
|
|
|
410
429
|
</td>
|
|
411
430
|
<td>
|
|
@@ -419,7 +438,7 @@ The children to contextualize
|
|
|
419
438
|
|
|
420
439
|
### Returns
|
|
421
440
|
|
|
422
|
-
[`ContextualizePipe`](#contextualizepipe)
|
|
441
|
+
[`ContextualizePipe`](#contextualizepipe)\<`Children`\>
|
|
423
442
|
|
|
424
443
|
An object with the following properties:
|
|
425
444
|
|
|
@@ -444,7 +463,7 @@ function createSafeContext<T>(): <DisplayName>(displayName) => {
|
|
|
444
463
|
};
|
|
445
464
|
```
|
|
446
465
|
|
|
447
|
-
Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
466
|
+
Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/createSafeContext.ts#L62)
|
|
448
467
|
|
|
449
468
|
For a given type `T`, returns a function that produces both a context of that
|
|
450
469
|
type and a hook that returns the current context value if one was provided,
|
|
@@ -586,10 +605,10 @@ A function that accepts a single string argument `displayName` (e.g.
|
|
|
586
605
|
## wrapJSX()
|
|
587
606
|
|
|
588
607
|
```ts
|
|
589
|
-
function wrapJSX(children): JSXWrapPipe
|
|
608
|
+
function wrapJSX<Children>(children): JSXWrapPipe<Children>;
|
|
590
609
|
```
|
|
591
610
|
|
|
592
|
-
Defined in: [misc/wrapJSX.tsx:
|
|
611
|
+
Defined in: [misc/wrapJSX.tsx:99](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/wrapJSX.tsx#L99)
|
|
593
612
|
|
|
594
613
|
An alternative way to compose JSX that avoids ever-increasing indentation
|
|
595
614
|
|
|
@@ -629,6 +648,25 @@ createRoot(document.getElementById('root')!).render(
|
|
|
629
648
|
);
|
|
630
649
|
```
|
|
631
650
|
|
|
651
|
+
### Type Parameters
|
|
652
|
+
|
|
653
|
+
<table>
|
|
654
|
+
<thead>
|
|
655
|
+
<tr>
|
|
656
|
+
<th>Type Parameter</th>
|
|
657
|
+
</tr>
|
|
658
|
+
</thead>
|
|
659
|
+
<tbody>
|
|
660
|
+
<tr>
|
|
661
|
+
<td>
|
|
662
|
+
|
|
663
|
+
`Children` _extends_ `ReactNode`
|
|
664
|
+
|
|
665
|
+
</td>
|
|
666
|
+
</tr>
|
|
667
|
+
</tbody>
|
|
668
|
+
</table>
|
|
669
|
+
|
|
632
670
|
### Parameters
|
|
633
671
|
|
|
634
672
|
<table>
|
|
@@ -648,7 +686,7 @@ createRoot(document.getElementById('root')!).render(
|
|
|
648
686
|
</td>
|
|
649
687
|
<td>
|
|
650
688
|
|
|
651
|
-
`
|
|
689
|
+
`Children`
|
|
652
690
|
|
|
653
691
|
</td>
|
|
654
692
|
<td>
|
|
@@ -662,7 +700,7 @@ The children to wrap
|
|
|
662
700
|
|
|
663
701
|
### Returns
|
|
664
702
|
|
|
665
|
-
[`JSXWrapPipe`](#jsxwrappipe)
|
|
703
|
+
[`JSXWrapPipe`](#jsxwrappipe)\<`Children`\>
|
|
666
704
|
|
|
667
705
|
An object with the following properties:
|
|
668
706
|
|
|
@@ -685,7 +723,7 @@ type UseEventListener = UseEventListenerWithImplicitWindowTarget &
|
|
|
685
723
|
UseEventListenerWithAnyExplicitTarget;
|
|
686
724
|
```
|
|
687
725
|
|
|
688
|
-
Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
726
|
+
Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L12)
|
|
689
727
|
|
|
690
728
|
The type of [`useEventListener`](#useeventlistener)
|
|
691
729
|
|
|
@@ -704,7 +742,7 @@ The type of [`useEventListener`](#useeventlistener)
|
|
|
704
742
|
type UseEventListenerWithImplicitWindowTarget = <K>(...args) => void;
|
|
705
743
|
```
|
|
706
744
|
|
|
707
|
-
Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
745
|
+
Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L21)
|
|
708
746
|
|
|
709
747
|
### Type Parameters
|
|
710
748
|
|
|
@@ -772,7 +810,7 @@ type UseEventListenerWithExplicitGlobalTarget =
|
|
|
772
810
|
UseEventListenerWithExplicitTarget<MathMLElement, MathMLElementEventMap>;
|
|
773
811
|
```
|
|
774
812
|
|
|
775
|
-
Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
813
|
+
Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L32)
|
|
776
814
|
|
|
777
815
|
### See
|
|
778
816
|
|
|
@@ -789,7 +827,7 @@ type UseEventListenerWithExplicitTarget<Target, EventMap> = <T, K>(
|
|
|
789
827
|
) => void;
|
|
790
828
|
```
|
|
791
829
|
|
|
792
|
-
Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
830
|
+
Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L44)
|
|
793
831
|
|
|
794
832
|
### Type Parameters
|
|
795
833
|
|
|
@@ -888,7 +926,7 @@ type UseEventListenerWithAnyExplicitTarget = UseEventListenerWithExplicitTarget<
|
|
|
888
926
|
>;
|
|
889
927
|
```
|
|
890
928
|
|
|
891
|
-
Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
929
|
+
Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L56)
|
|
892
930
|
|
|
893
931
|
### See
|
|
894
932
|
|
|
@@ -909,7 +947,7 @@ type UseEventListenerWithImplicitWindowTargetArgs<K> =
|
|
|
909
947
|
: never;
|
|
910
948
|
```
|
|
911
949
|
|
|
912
|
-
Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
950
|
+
Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L64)
|
|
913
951
|
|
|
914
952
|
### Type Parameters
|
|
915
953
|
|
|
@@ -954,7 +992,7 @@ type UseEventListenerWithExplicitTargetArgs<EventMap, T, K> = [
|
|
|
954
992
|
];
|
|
955
993
|
```
|
|
956
994
|
|
|
957
|
-
Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
995
|
+
Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L78)
|
|
958
996
|
|
|
959
997
|
### Type Parameters
|
|
960
998
|
|
|
@@ -998,13 +1036,13 @@ Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-esse
|
|
|
998
1036
|
## ContextualizePipe
|
|
999
1037
|
|
|
1000
1038
|
```ts
|
|
1001
|
-
type ContextualizePipe = {
|
|
1039
|
+
type ContextualizePipe<Children> = {
|
|
1002
1040
|
with: ContextualizeWith;
|
|
1003
|
-
end: () =>
|
|
1041
|
+
end: () => Children;
|
|
1004
1042
|
};
|
|
1005
1043
|
```
|
|
1006
1044
|
|
|
1007
|
-
Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
1045
|
+
Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/contextualize.tsx#L13)
|
|
1008
1046
|
|
|
1009
1047
|
The return type of [`contextualize`](#contextualize)
|
|
1010
1048
|
|
|
@@ -1013,6 +1051,25 @@ The return type of [`contextualize`](#contextualize)
|
|
|
1013
1051
|
[`contextualize`](#contextualize),
|
|
1014
1052
|
[`ContextualizeWith`](#contextualizewith)
|
|
1015
1053
|
|
|
1054
|
+
### Type Parameters
|
|
1055
|
+
|
|
1056
|
+
<table>
|
|
1057
|
+
<thead>
|
|
1058
|
+
<tr>
|
|
1059
|
+
<th>Type Parameter</th>
|
|
1060
|
+
</tr>
|
|
1061
|
+
</thead>
|
|
1062
|
+
<tbody>
|
|
1063
|
+
<tr>
|
|
1064
|
+
<td>
|
|
1065
|
+
|
|
1066
|
+
`Children` _extends_ `ReactNode`
|
|
1067
|
+
|
|
1068
|
+
</td>
|
|
1069
|
+
</tr>
|
|
1070
|
+
</tbody>
|
|
1071
|
+
</table>
|
|
1072
|
+
|
|
1016
1073
|
### Properties
|
|
1017
1074
|
|
|
1018
1075
|
<table>
|
|
@@ -1043,7 +1100,7 @@ The return type of [`contextualize`](#contextualize)
|
|
|
1043
1100
|
</td>
|
|
1044
1101
|
<td>
|
|
1045
1102
|
|
|
1046
|
-
() => `
|
|
1103
|
+
() => `Children`
|
|
1047
1104
|
|
|
1048
1105
|
</td>
|
|
1049
1106
|
</tr>
|
|
@@ -1055,10 +1112,10 @@ The return type of [`contextualize`](#contextualize)
|
|
|
1055
1112
|
## ContextualizeWith()
|
|
1056
1113
|
|
|
1057
1114
|
```ts
|
|
1058
|
-
type ContextualizeWith = <T>(Context, value) => ContextualizePipe
|
|
1115
|
+
type ContextualizeWith = <T>(Context, value) => ContextualizePipe<ReactElement>;
|
|
1059
1116
|
```
|
|
1060
1117
|
|
|
1061
|
-
Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.
|
|
1118
|
+
Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/contextualize.tsx#L23)
|
|
1062
1119
|
|
|
1063
1120
|
### Type Parameters
|
|
1064
1121
|
|
|
@@ -1118,7 +1175,7 @@ Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essenti
|
|
|
1118
1175
|
|
|
1119
1176
|
### Returns
|
|
1120
1177
|
|
|
1121
|
-
[`ContextualizePipe`](#contextualizepipe)
|
|
1178
|
+
[`ContextualizePipe`](#contextualizepipe)\<`ReactElement`\>
|
|
1122
1179
|
|
|
1123
1180
|
### See
|
|
1124
1181
|
|
|
@@ -1130,13 +1187,13 @@ Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essenti
|
|
|
1130
1187
|
## JSXWrapPipe
|
|
1131
1188
|
|
|
1132
1189
|
```ts
|
|
1133
|
-
type JSXWrapPipe = {
|
|
1134
|
-
with: WrapJSXWith
|
|
1135
|
-
end: () =>
|
|
1190
|
+
type JSXWrapPipe<Children> = {
|
|
1191
|
+
with: WrapJSXWith<Children>;
|
|
1192
|
+
end: () => Children;
|
|
1136
1193
|
};
|
|
1137
1194
|
```
|
|
1138
1195
|
|
|
1139
|
-
Defined in: [misc/wrapJSX.tsx:
|
|
1196
|
+
Defined in: [misc/wrapJSX.tsx:19](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/wrapJSX.tsx#L19)
|
|
1140
1197
|
|
|
1141
1198
|
The return type of [`wrapJSX`](#wrapjsx)
|
|
1142
1199
|
|
|
@@ -1145,6 +1202,25 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1145
1202
|
[`wrapJSX`](#wrapjsx),
|
|
1146
1203
|
[`WrapJSXWith`](#wrapjsxwith)
|
|
1147
1204
|
|
|
1205
|
+
### Type Parameters
|
|
1206
|
+
|
|
1207
|
+
<table>
|
|
1208
|
+
<thead>
|
|
1209
|
+
<tr>
|
|
1210
|
+
<th>Type Parameter</th>
|
|
1211
|
+
</tr>
|
|
1212
|
+
</thead>
|
|
1213
|
+
<tbody>
|
|
1214
|
+
<tr>
|
|
1215
|
+
<td>
|
|
1216
|
+
|
|
1217
|
+
`Children` _extends_ `ReactNode`
|
|
1218
|
+
|
|
1219
|
+
</td>
|
|
1220
|
+
</tr>
|
|
1221
|
+
</tbody>
|
|
1222
|
+
</table>
|
|
1223
|
+
|
|
1148
1224
|
### Properties
|
|
1149
1225
|
|
|
1150
1226
|
<table>
|
|
@@ -1163,7 +1239,7 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1163
1239
|
</td>
|
|
1164
1240
|
<td>
|
|
1165
1241
|
|
|
1166
|
-
[`WrapJSXWith`](#wrapjsxwith)
|
|
1242
|
+
[`WrapJSXWith`](#wrapjsxwith)\<`Children`\>
|
|
1167
1243
|
|
|
1168
1244
|
</td>
|
|
1169
1245
|
</tr>
|
|
@@ -1175,7 +1251,7 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1175
1251
|
</td>
|
|
1176
1252
|
<td>
|
|
1177
1253
|
|
|
1178
|
-
() => `
|
|
1254
|
+
() => `Children`
|
|
1179
1255
|
|
|
1180
1256
|
</td>
|
|
1181
1257
|
</tr>
|
|
@@ -1187,10 +1263,29 @@ The return type of [`wrapJSX`](#wrapjsx)
|
|
|
1187
1263
|
## WrapJSXWith()
|
|
1188
1264
|
|
|
1189
1265
|
```ts
|
|
1190
|
-
type WrapJSXWith = <C>(...args) => JSXWrapPipe
|
|
1266
|
+
type WrapJSXWith<Children> = <C>(...args) => JSXWrapPipe<ReactElement>;
|
|
1191
1267
|
```
|
|
1192
1268
|
|
|
1193
|
-
Defined in: [misc/wrapJSX.tsx:
|
|
1269
|
+
Defined in: [misc/wrapJSX.tsx:29](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/wrapJSX.tsx#L29)
|
|
1270
|
+
|
|
1271
|
+
### Type Parameters
|
|
1272
|
+
|
|
1273
|
+
<table>
|
|
1274
|
+
<thead>
|
|
1275
|
+
<tr>
|
|
1276
|
+
<th>Type Parameter</th>
|
|
1277
|
+
</tr>
|
|
1278
|
+
</thead>
|
|
1279
|
+
<tbody>
|
|
1280
|
+
<tr>
|
|
1281
|
+
<td>
|
|
1282
|
+
|
|
1283
|
+
`Children` _extends_ `ReactNode`
|
|
1284
|
+
|
|
1285
|
+
</td>
|
|
1286
|
+
</tr>
|
|
1287
|
+
</tbody>
|
|
1288
|
+
</table>
|
|
1194
1289
|
|
|
1195
1290
|
### Type Parameters
|
|
1196
1291
|
|
|
@@ -1229,7 +1324,7 @@ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/bl
|
|
|
1229
1324
|
</td>
|
|
1230
1325
|
<td>
|
|
1231
1326
|
|
|
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">])`\]
|
|
1327
|
+
\[`"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
1328
|
|
|
1234
1329
|
</td>
|
|
1235
1330
|
</tr>
|
|
@@ -1238,7 +1333,7 @@ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/bl
|
|
|
1238
1333
|
|
|
1239
1334
|
### Returns
|
|
1240
1335
|
|
|
1241
|
-
[`JSXWrapPipe`](#jsxwrappipe)
|
|
1336
|
+
[`JSXWrapPipe`](#jsxwrappipe)\<`ReactElement`\>
|
|
1242
1337
|
|
|
1243
1338
|
### See
|
|
1244
1339
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context, ReactNode } from 'react';
|
|
1
|
+
import type { Context, ReactElement, ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* The return type of {@linkcode contextualize}
|
|
4
4
|
*
|
|
@@ -6,16 +6,16 @@ import type { Context, ReactNode } from 'react';
|
|
|
6
6
|
* {@linkcode contextualize},
|
|
7
7
|
* {@linkcode ContextualizeWith}
|
|
8
8
|
*/
|
|
9
|
-
export type ContextualizePipe = {
|
|
9
|
+
export type ContextualizePipe<Children extends ReactNode> = {
|
|
10
10
|
with: ContextualizeWith;
|
|
11
|
-
end: () =>
|
|
11
|
+
end: () => Children;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* @see
|
|
15
15
|
* {@linkcode contextualize},
|
|
16
16
|
* {@linkcode ContextualizePipe}
|
|
17
17
|
*/
|
|
18
|
-
export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => ContextualizePipe
|
|
18
|
+
export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => ContextualizePipe<ReactElement>;
|
|
19
19
|
/**
|
|
20
20
|
* An alternative way to provide context values to component trees that avoids
|
|
21
21
|
* ever-increasing indentation
|
|
@@ -67,5 +67,5 @@ export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => C
|
|
|
67
67
|
* @see
|
|
68
68
|
* {@linkcode ContextualizePipe}
|
|
69
69
|
*/
|
|
70
|
-
export declare function contextualize(children:
|
|
70
|
+
export declare function contextualize<Children extends ReactNode>(children: Children): ContextualizePipe<Children>;
|
|
71
71
|
//# sourceMappingURL=contextualize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextualize.d.ts","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"contextualize.d.ts","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK9D;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,CAAC,QAAQ,SAAS,SAAS,IAAI;IAC1D,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,MAAM,QAAQ,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KACd,iBAAiB,CAAC,YAAY,CAAC,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,aAAa,CAAC,QAAQ,SAAS,SAAS,EACtD,QAAQ,EAAE,QAAQ,GACjB,iBAAiB,CAAC,QAAQ,CAAC,CAW7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,aAAa,
|
|
1
|
+
{"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAkB;IAElB,OAAO;QACL,IAAI,CAAI,OAAmB,EAAE,KAAQ;YACnC,OAAO,aAAa,CAClB,KAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAoB,CAC9D,CAAC;QACJ,CAAC;QACD,GAAG;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context, ReactNode } from 'react';
|
|
1
|
+
import type { Context, ReactElement, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
4
|
import type { wrapJSX } from './wrapJSX.js';
|
|
@@ -10,9 +10,9 @@ import type { wrapJSX } from './wrapJSX.js';
|
|
|
10
10
|
* {@linkcode contextualize},
|
|
11
11
|
* {@linkcode ContextualizeWith}
|
|
12
12
|
*/
|
|
13
|
-
export type ContextualizePipe = {
|
|
13
|
+
export type ContextualizePipe<Children extends ReactNode> = {
|
|
14
14
|
with: ContextualizeWith;
|
|
15
|
-
end: () =>
|
|
15
|
+
end: () => Children;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -23,7 +23,7 @@ export type ContextualizePipe = {
|
|
|
23
23
|
export type ContextualizeWith = <T>(
|
|
24
24
|
Context: Context<T>,
|
|
25
25
|
value: NoInfer<T>,
|
|
26
|
-
) => ContextualizePipe
|
|
26
|
+
) => ContextualizePipe<ReactElement>;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* An alternative way to provide context values to component trees that avoids
|
|
@@ -76,7 +76,9 @@ export type ContextualizeWith = <T>(
|
|
|
76
76
|
* @see
|
|
77
77
|
* {@linkcode ContextualizePipe}
|
|
78
78
|
*/
|
|
79
|
-
export function contextualize
|
|
79
|
+
export function contextualize<Children extends ReactNode>(
|
|
80
|
+
children: Children,
|
|
81
|
+
): ContextualizePipe<Children> {
|
|
80
82
|
return {
|
|
81
83
|
with<T>(Context: Context<T>, value: T) {
|
|
82
84
|
return contextualize(
|
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:
|