@aweebit/react-essentials 0.10.3 → 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 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.3/src/hooks/useEventListener.ts#L135)
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.3/src/hooks/useReducerWithDeps.ts#L59)
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.3/src/hooks/useStateWithDeps.ts#L62)
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
@@ -341,10 +341,10 @@ Dependencies that reset the state to `initialState`
341
341
  ## contextualize()
342
342
 
343
343
  ```ts
344
- function contextualize(jsx): ContextualizePipe;
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.3/src/misc/contextualize.tsx#L79)
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
@@ -400,17 +400,17 @@ return contextualize(jsx)
400
400
  <tr>
401
401
  <td>
402
402
 
403
- `jsx`
403
+ `children`
404
404
 
405
405
  </td>
406
406
  <td>
407
407
 
408
- `Element`
408
+ `ReactNode`
409
409
 
410
410
  </td>
411
411
  <td>
412
412
 
413
- The JSX to contextualize
413
+ The children to contextualize
414
414
 
415
415
  </td>
416
416
  </tr>
@@ -425,8 +425,8 @@ An object with the following properties:
425
425
 
426
426
  - `with`: a function that accepts a context `Context` and a value `value` for
427
427
  it as arguments and returns
428
- `contextualize(<Context.Provider value={value}>{jsx}</Context.Provider>)`
429
- - `end`: a function that returns `jsx`
428
+ `contextualize(<Context.Provider value={value}>{children}</Context.Provider>)`
429
+ - `end`: a function that returns `children`
430
430
 
431
431
  ### See
432
432
 
@@ -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.3/src/misc/createSafeContext.ts#L62)
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(jsx): JSXWrapPipe;
589
+ function wrapJSX<Children>(children): JSXWrapPipe<Children>;
590
590
  ```
591
591
 
592
- Defined in: [misc/wrapJSX.tsx:93](https://github.com/aweebit/react-essentials/blob/v0.10.3/src/misc/wrapJSX.tsx#L93)
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>
@@ -643,17 +662,17 @@ createRoot(document.getElementById('root')!).render(
643
662
  <tr>
644
663
  <td>
645
664
 
646
- `jsx`
665
+ `children`
647
666
 
648
667
  </td>
649
668
  <td>
650
669
 
651
- `Element`
670
+ `Children`
652
671
 
653
672
  </td>
654
673
  <td>
655
674
 
656
- The JSX to wrap
675
+ The children to wrap
657
676
 
658
677
  </td>
659
678
  </tr>
@@ -662,14 +681,14 @@ The JSX 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
 
669
688
  - `with`: a function that accepts a component `Component` and props `props`
670
689
  for it as arguments and returns
671
- `wrapJSX(<Component {...props}>{jsx}</Component>)`
672
- - `end`: a function that returns `jsx`
690
+ `wrapJSX(<Component {...props}>{children}</Component>)`
691
+ - `end`: a function that returns `children`
673
692
 
674
693
  ### See
675
694
 
@@ -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.3/src/hooks/useEventListener.ts#L12)
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.3/src/hooks/useEventListener.ts#L21)
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.3/src/hooks/useEventListener.ts#L32)
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.3/src/hooks/useEventListener.ts#L44)
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.3/src/hooks/useEventListener.ts#L56)
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.3/src/hooks/useEventListener.ts#L64)
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.3/src/hooks/useEventListener.ts#L78)
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
 
@@ -1000,11 +1019,11 @@ Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-esse
1000
1019
  ```ts
1001
1020
  type ContextualizePipe = {
1002
1021
  with: ContextualizeWith;
1003
- end: () => React.JSX.Element;
1022
+ end: () => ReactNode;
1004
1023
  };
1005
1024
  ```
1006
1025
 
1007
- Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.3/src/misc/contextualize.tsx#L13)
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
 
@@ -1043,7 +1062,7 @@ The return type of [`contextualize`](#contextualize)
1043
1062
  </td>
1044
1063
  <td>
1045
1064
 
1046
- () => `React.JSX.Element`
1065
+ () => `ReactNode`
1047
1066
 
1048
1067
  </td>
1049
1068
  </tr>
@@ -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.3/src/misc/contextualize.tsx#L23)
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: () => React.JSX.Element;
1152
+ type JSXWrapPipe<Children> = {
1153
+ with: WrapJSXWith<Children>;
1154
+ end: () => Children;
1136
1155
  };
1137
1156
  ```
1138
1157
 
1139
- Defined in: [misc/wrapJSX.tsx:17](https://github.com/aweebit/react-essentials/blob/v0.10.3/src/misc/wrapJSX.tsx#L17)
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
- () => `React.JSX.Element`
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:27](https://github.com/aweebit/react-essentials/blob/v0.10.3/src/misc/wrapJSX.tsx#L27)
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:27](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:27](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
 
@@ -1,4 +1,4 @@
1
- import type { Context, default as React } from 'react';
1
+ import type { Context, ReactNode } from 'react';
2
2
  /**
3
3
  * The return type of {@linkcode contextualize}
4
4
  *
@@ -8,7 +8,7 @@ import type { Context, default as React } from 'react';
8
8
  */
9
9
  export type ContextualizePipe = {
10
10
  with: ContextualizeWith;
11
- end: () => React.JSX.Element;
11
+ end: () => ReactNode;
12
12
  };
13
13
  /**
14
14
  * @see
@@ -56,16 +56,16 @@ export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => C
56
56
  * .end();
57
57
  * ```
58
58
  *
59
- * @param jsx The JSX to contextualize
59
+ * @param children The children to contextualize
60
60
  *
61
61
  * @returns An object with the following properties:
62
62
  * - `with`: a function that accepts a context `Context` and a value `value` for
63
63
  * it as arguments and returns
64
- * `contextualize(<Context.Provider value={value}>{jsx}</Context.Provider>)`
65
- * - `end`: a function that returns `jsx`
64
+ * `contextualize(<Context.Provider value={value}>{children}</Context.Provider>)`
65
+ * - `end`: a function that returns `children`
66
66
  *
67
67
  * @see
68
68
  * {@linkcode ContextualizePipe}
69
69
  */
70
- export declare function contextualize(jsx: React.JSX.Element): ContextualizePipe;
70
+ export declare function contextualize(children: ReactNode): ContextualizePipe;
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,OAAO,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC;AAKvD;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;CAC9B,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;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,iBAAiB,CAWvE"}
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;AAKhD;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,MAAM,SAAS,CAAC;CACtB,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;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,GAAG,iBAAiB,CAWpE"}
@@ -39,24 +39,24 @@ import { jsx as _jsx } from "react/jsx-runtime";
39
39
  * .end();
40
40
  * ```
41
41
  *
42
- * @param jsx The JSX to contextualize
42
+ * @param children The children to contextualize
43
43
  *
44
44
  * @returns An object with the following properties:
45
45
  * - `with`: a function that accepts a context `Context` and a value `value` for
46
46
  * it as arguments and returns
47
- * `contextualize(<Context.Provider value={value}>{jsx}</Context.Provider>)`
48
- * - `end`: a function that returns `jsx`
47
+ * `contextualize(<Context.Provider value={value}>{children}</Context.Provider>)`
48
+ * - `end`: a function that returns `children`
49
49
  *
50
50
  * @see
51
51
  * {@linkcode ContextualizePipe}
52
52
  */
53
- export function contextualize(jsx) {
53
+ export function contextualize(children) {
54
54
  return {
55
55
  with(Context, value) {
56
- return contextualize(_jsx(Context.Provider, { value: value, children: jsx }));
56
+ return contextualize(_jsx(Context.Provider, { value: value, children: children }));
57
57
  },
58
58
  end() {
59
- return jsx;
59
+ return children;
60
60
  },
61
61
  };
62
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,aAAa,CAAC,GAAsB;IAClD,OAAO;QACL,IAAI,CAAI,OAAmB,EAAE,KAAQ;YACnC,OAAO,aAAa,CAClB,KAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,GAAG,GAAoB,CACzD,CAAC;QACJ,CAAC;QACD,GAAG;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,aAAa,CAAC,QAAmB;IAC/C,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"}
@@ -1,4 +1,4 @@
1
- import type { ComponentProps, JSXElementConstructor, default as React } 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 } from 're
6
6
  * {@linkcode wrapJSX},
7
7
  * {@linkcode WrapJSXWith}
8
8
  */
9
- export type JSXWrapPipe = {
10
- with: WrapJSXWith;
11
- end: () => React.JSX.Element;
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
  *
@@ -61,16 +61,16 @@ export type WrapJSXWith = <C extends keyof JSX.IntrinsicElements | JSXElementCon
61
61
  * );
62
62
  * ```
63
63
  *
64
- * @param jsx The JSX to wrap
64
+ * @param children The children to wrap
65
65
  *
66
66
  * @returns An object with the following properties:
67
67
  * - `with`: a function that accepts a component `Component` and props `props`
68
68
  * for it as arguments and returns
69
- * `wrapJSX(<Component {...props}>{jsx}</Component>)`
70
- * - `end`: a function that returns `jsx`
69
+ * `wrapJSX(<Component {...props}>{children}</Component>)`
70
+ * - `end`: a function that returns `children`
71
71
  *
72
72
  * @see
73
73
  * {@linkcode JSXWrapPipe}
74
74
  */
75
- export declare function wrapJSX(jsx: React.JSX.Element): JSXWrapPipe;
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,EACjB,MAAM,OAAO,CAAC;AAKf;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAErB,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,GAAG,CAAC,EACjE,GAAG,IAAI,EAAE;IACP,SAAS,EAAE,CAAC;IACZ,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;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,WAAW,CAc3D"}
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"}
@@ -37,24 +37,24 @@ import { jsx as _jsx } from "react/jsx-runtime";
37
37
  * );
38
38
  * ```
39
39
  *
40
- * @param jsx The JSX to wrap
40
+ * @param children The children to wrap
41
41
  *
42
42
  * @returns An object with the following properties:
43
43
  * - `with`: a function that accepts a component `Component` and props `props`
44
44
  * for it as arguments and returns
45
- * `wrapJSX(<Component {...props}>{jsx}</Component>)`
46
- * - `end`: a function that returns `jsx`
45
+ * `wrapJSX(<Component {...props}>{children}</Component>)`
46
+ * - `end`: a function that returns `children`
47
47
  *
48
48
  * @see
49
49
  * {@linkcode JSXWrapPipe}
50
50
  */
51
- export function wrapJSX(jsx) {
51
+ export function wrapJSX(children) {
52
52
  return {
53
53
  with(Component, props = {}) {
54
- return wrapJSX(_jsx(Component, { ...props, children: jsx }));
54
+ return wrapJSX(_jsx(Component, { ...props, children: children }));
55
55
  },
56
56
  end() {
57
- return jsx;
57
+ return children;
58
58
  },
59
59
  };
60
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wrapJSX.js","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":";AA2CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,OAAO,CAAC,GAAsB;IAC5C,OAAO;QACL,IAAI,CACF,SAEiC,EACjC,QAAgB,EAAE;YAElB,OAAO,OAAO,CAAC,KAAC,SAAS,OAAK,KAAK,YAAG,GAAG,GAAa,CAAC,CAAC;QAC1D,CAAC;QACD,GAAG;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@aweebit/react-essentials",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "type": "module",
5
5
  "repository": "github:aweebit/react-essentials",
6
6
  "main": "dist/index.js",
@@ -1,4 +1,4 @@
1
- import type { Context, default as React } from 'react';
1
+ import type { Context, ReactNode } from 'react';
2
2
 
3
3
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
4
  import type { wrapJSX } from './wrapJSX.js';
@@ -12,7 +12,7 @@ import type { wrapJSX } from './wrapJSX.js';
12
12
  */
13
13
  export type ContextualizePipe = {
14
14
  with: ContextualizeWith;
15
- end: () => React.JSX.Element;
15
+ end: () => ReactNode;
16
16
  };
17
17
 
18
18
  /**
@@ -65,26 +65,26 @@ export type ContextualizeWith = <T>(
65
65
  * .end();
66
66
  * ```
67
67
  *
68
- * @param jsx The JSX to contextualize
68
+ * @param children The children to contextualize
69
69
  *
70
70
  * @returns An object with the following properties:
71
71
  * - `with`: a function that accepts a context `Context` and a value `value` for
72
72
  * it as arguments and returns
73
- * `contextualize(<Context.Provider value={value}>{jsx}</Context.Provider>)`
74
- * - `end`: a function that returns `jsx`
73
+ * `contextualize(<Context.Provider value={value}>{children}</Context.Provider>)`
74
+ * - `end`: a function that returns `children`
75
75
  *
76
76
  * @see
77
77
  * {@linkcode ContextualizePipe}
78
78
  */
79
- export function contextualize(jsx: React.JSX.Element): ContextualizePipe {
79
+ export function contextualize(children: ReactNode): ContextualizePipe {
80
80
  return {
81
81
  with<T>(Context: Context<T>, value: T) {
82
82
  return contextualize(
83
- <Context.Provider value={value}>{jsx}</Context.Provider>,
83
+ <Context.Provider value={value}>{children}</Context.Provider>,
84
84
  );
85
85
  },
86
86
  end() {
87
- return jsx;
87
+ return children;
88
88
  },
89
89
  };
90
90
  }
@@ -2,6 +2,8 @@ import type {
2
2
  ComponentProps,
3
3
  JSXElementConstructor,
4
4
  default as React,
5
+ ReactElement,
6
+ ReactNode,
5
7
  } from 'react';
6
8
 
7
9
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -14,9 +16,9 @@ import type { contextualize } from './contextualize.js';
14
16
  * {@linkcode wrapJSX},
15
17
  * {@linkcode WrapJSXWith}
16
18
  */
17
- export type JSXWrapPipe = {
18
- with: WrapJSXWith;
19
- end: () => React.JSX.Element;
19
+ export type JSXWrapPipe<Children extends ReactNode> = {
20
+ with: WrapJSXWith<Children>;
21
+ end: () => Children;
20
22
  };
21
23
 
22
24
  /**
@@ -24,11 +26,15 @@ export type JSXWrapPipe = {
24
26
  * {@linkcode wrapJSX},
25
27
  * {@linkcode JSXWrapPipe}
26
28
  */
27
- export type WrapJSXWith =
29
+ export type WrapJSXWith<Children extends ReactNode> =
28
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
31
  <C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>>(
30
32
  ...args: [
31
- Component: C,
33
+ Component: 'children' extends keyof ComponentProps<C>
34
+ ? [Children] extends [ComponentProps<C>['children']]
35
+ ? C
36
+ : never
37
+ : never,
32
38
  ...(Record<never, unknown> extends Omit<ComponentProps<C>, 'children'>
33
39
  ? [
34
40
  props?: React.JSX.IntrinsicAttributes &
@@ -39,7 +45,7 @@ export type WrapJSXWith =
39
45
  Omit<ComponentProps<C>, 'children'>,
40
46
  ]),
41
47
  ]
42
- ) => JSXWrapPipe;
48
+ ) => JSXWrapPipe<ReactElement>;
43
49
 
44
50
  /**
45
51
  * An alternative way to compose JSX that avoids ever-increasing indentation
@@ -79,18 +85,20 @@ export type WrapJSXWith =
79
85
  * );
80
86
  * ```
81
87
  *
82
- * @param jsx The JSX to wrap
88
+ * @param children The children to wrap
83
89
  *
84
90
  * @returns An object with the following properties:
85
91
  * - `with`: a function that accepts a component `Component` and props `props`
86
92
  * for it as arguments and returns
87
- * `wrapJSX(<Component {...props}>{jsx}</Component>)`
88
- * - `end`: a function that returns `jsx`
93
+ * `wrapJSX(<Component {...props}>{children}</Component>)`
94
+ * - `end`: a function that returns `children`
89
95
  *
90
96
  * @see
91
97
  * {@linkcode JSXWrapPipe}
92
98
  */
93
- export function wrapJSX(jsx: React.JSX.Element): JSXWrapPipe {
99
+ export function wrapJSX<Children extends ReactNode>(
100
+ children: Children,
101
+ ): JSXWrapPipe<Children> {
94
102
  return {
95
103
  with(
96
104
  Component:
@@ -98,10 +106,10 @@ export function wrapJSX(jsx: React.JSX.Element): JSXWrapPipe {
98
106
  | JSXElementConstructor<object>,
99
107
  props: object = {},
100
108
  ) {
101
- return wrapJSX(<Component {...props}>{jsx}</Component>);
109
+ return wrapJSX(<Component {...props}>{children}</Component>);
102
110
  },
103
111
  end() {
104
- return jsx;
112
+ return children;
105
113
  },
106
114
  };
107
115
  }