react-children-hooks 0.4.0 → 0.5.0
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 +2 -8
- package/dist/index.cjs +91 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -27
- package/dist/index.d.ts +19 -27
- package/dist/index.js +88 -42
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -222,6 +222,15 @@ declare function useMinimumChildrenByType<T extends ElementType>(children: React
|
|
|
222
222
|
declare function useMinimumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, minimumCount: number, options?: ValidationOptions): T[];
|
|
223
223
|
declare function useMinimumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, minimumCount: number, options?: ValidationOptions): ReactElement[];
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Returns the optional direct callback child from the provided children value, or throws when more than one is found.
|
|
227
|
+
*
|
|
228
|
+
* @param children The direct children value to inspect.
|
|
229
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
230
|
+
* @returns The optional direct callback child from the provided children value, or `null` when none is found.
|
|
231
|
+
*/
|
|
232
|
+
declare function useOptionalCallbackChild<TArguments extends unknown[] = [], TResult = ReactNode>(children: CallbackChildren<TArguments, TResult>, options?: ValidationOptions): CallbackChild<TArguments, TResult> | null;
|
|
233
|
+
|
|
225
234
|
/**
|
|
226
235
|
* Returns the optional direct child element whose React element type exactly matches the provided type, or throws when more than one match is found.
|
|
227
236
|
*
|
|
@@ -273,6 +282,15 @@ declare function useRequiredCallbackChild<TArguments extends unknown[] = [], TRe
|
|
|
273
282
|
declare function useRequiredChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
|
|
274
283
|
declare function useRequiredChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
|
|
275
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Returns the only direct callback child from the provided children value, or throws when the match is not unique.
|
|
287
|
+
*
|
|
288
|
+
* @param children The direct children value to inspect.
|
|
289
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
290
|
+
* @returns The only direct callback child from the provided children value.
|
|
291
|
+
*/
|
|
292
|
+
declare function useUniqueCallbackChild<TArguments extends unknown[] = [], TResult = ReactNode>(children: CallbackChildren<TArguments, TResult>, options?: ValidationOptions): CallbackChild<TArguments, TResult>;
|
|
293
|
+
|
|
276
294
|
/**
|
|
277
295
|
* Returns the only direct child element whose React element type exactly matches the provided type, or throws when the match is not unique.
|
|
278
296
|
*
|
|
@@ -294,30 +312,4 @@ declare function useUniqueChildByType<T extends ElementType>(children: ReactNode
|
|
|
294
312
|
declare function useUniqueChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
|
|
295
313
|
declare function useUniqueChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
|
|
296
314
|
|
|
297
|
-
|
|
298
|
-
* Normalizes a React children value into an array containing valid child elements within the configured depth range.
|
|
299
|
-
*
|
|
300
|
-
* @param children The React children value to normalize.
|
|
301
|
-
* @param options Optional traversal bounds that control which child depths are included.
|
|
302
|
-
* @returns An array of valid React elements from the provided child depths.
|
|
303
|
-
*/
|
|
304
|
-
declare function childrenToElements(children: ReactNode, options?: TraversalOptions): ReactElement[];
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Determines whether a React element exactly matches the provided element or component type.
|
|
308
|
-
*
|
|
309
|
-
* @param element The React element to compare.
|
|
310
|
-
* @param type The element or component type to match.
|
|
311
|
-
* @returns `true` when the element's type exactly matches the provided type; otherwise `false`.
|
|
312
|
-
*/
|
|
313
|
-
declare function isElementOfType<T extends ElementType>(element: ReactElement, type: T): element is ElementOfType<T>;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Determines whether a React node is a valid React element.
|
|
317
|
-
*
|
|
318
|
-
* @param node The React node to check.
|
|
319
|
-
* @returns `true` when the node is a valid React element; otherwise `false`.
|
|
320
|
-
*/
|
|
321
|
-
declare function isReactElement(node: ReactNode): node is ReactElement;
|
|
322
|
-
|
|
323
|
-
export { type CallbackChild, type CallbackChildren, type ChildrenCountBounds, type ElementOfType, type QueryOptions, type TraversalOptions, type ValidationOptions, childrenToElements, isElementOfType, isReactElement, useBoundedChildrenByType, useBoundedChildrenMatching, useCallbackChild, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useOptionalChildByType, useOptionalChildMatching, useRequiredCallbackChild, useRequiredChildByType, useRequiredChildMatching, useUniqueChildByType, useUniqueChildMatching };
|
|
315
|
+
export { type CallbackChild, type CallbackChildren, type ChildrenCountBounds, type ElementOfType, type QueryOptions, type TraversalOptions, type ValidationOptions, useBoundedChildrenByType, useBoundedChildrenMatching, useCallbackChild, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useOptionalCallbackChild, useOptionalChildByType, useOptionalChildMatching, useRequiredCallbackChild, useRequiredChildByType, useRequiredChildMatching, useUniqueCallbackChild, useUniqueChildByType, useUniqueChildMatching };
|
package/dist/index.d.ts
CHANGED
|
@@ -222,6 +222,15 @@ declare function useMinimumChildrenByType<T extends ElementType>(children: React
|
|
|
222
222
|
declare function useMinimumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, minimumCount: number, options?: ValidationOptions): T[];
|
|
223
223
|
declare function useMinimumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, minimumCount: number, options?: ValidationOptions): ReactElement[];
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Returns the optional direct callback child from the provided children value, or throws when more than one is found.
|
|
227
|
+
*
|
|
228
|
+
* @param children The direct children value to inspect.
|
|
229
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
230
|
+
* @returns The optional direct callback child from the provided children value, or `null` when none is found.
|
|
231
|
+
*/
|
|
232
|
+
declare function useOptionalCallbackChild<TArguments extends unknown[] = [], TResult = ReactNode>(children: CallbackChildren<TArguments, TResult>, options?: ValidationOptions): CallbackChild<TArguments, TResult> | null;
|
|
233
|
+
|
|
225
234
|
/**
|
|
226
235
|
* Returns the optional direct child element whose React element type exactly matches the provided type, or throws when more than one match is found.
|
|
227
236
|
*
|
|
@@ -273,6 +282,15 @@ declare function useRequiredCallbackChild<TArguments extends unknown[] = [], TRe
|
|
|
273
282
|
declare function useRequiredChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
|
|
274
283
|
declare function useRequiredChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
|
|
275
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Returns the only direct callback child from the provided children value, or throws when the match is not unique.
|
|
287
|
+
*
|
|
288
|
+
* @param children The direct children value to inspect.
|
|
289
|
+
* @param options Optional reporting metadata used to derive the thrown validation message.
|
|
290
|
+
* @returns The only direct callback child from the provided children value.
|
|
291
|
+
*/
|
|
292
|
+
declare function useUniqueCallbackChild<TArguments extends unknown[] = [], TResult = ReactNode>(children: CallbackChildren<TArguments, TResult>, options?: ValidationOptions): CallbackChild<TArguments, TResult>;
|
|
293
|
+
|
|
276
294
|
/**
|
|
277
295
|
* Returns the only direct child element whose React element type exactly matches the provided type, or throws when the match is not unique.
|
|
278
296
|
*
|
|
@@ -294,30 +312,4 @@ declare function useUniqueChildByType<T extends ElementType>(children: ReactNode
|
|
|
294
312
|
declare function useUniqueChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
|
|
295
313
|
declare function useUniqueChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
|
|
296
314
|
|
|
297
|
-
|
|
298
|
-
* Normalizes a React children value into an array containing valid child elements within the configured depth range.
|
|
299
|
-
*
|
|
300
|
-
* @param children The React children value to normalize.
|
|
301
|
-
* @param options Optional traversal bounds that control which child depths are included.
|
|
302
|
-
* @returns An array of valid React elements from the provided child depths.
|
|
303
|
-
*/
|
|
304
|
-
declare function childrenToElements(children: ReactNode, options?: TraversalOptions): ReactElement[];
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Determines whether a React element exactly matches the provided element or component type.
|
|
308
|
-
*
|
|
309
|
-
* @param element The React element to compare.
|
|
310
|
-
* @param type The element or component type to match.
|
|
311
|
-
* @returns `true` when the element's type exactly matches the provided type; otherwise `false`.
|
|
312
|
-
*/
|
|
313
|
-
declare function isElementOfType<T extends ElementType>(element: ReactElement, type: T): element is ElementOfType<T>;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Determines whether a React node is a valid React element.
|
|
317
|
-
*
|
|
318
|
-
* @param node The React node to check.
|
|
319
|
-
* @returns `true` when the node is a valid React element; otherwise `false`.
|
|
320
|
-
*/
|
|
321
|
-
declare function isReactElement(node: ReactNode): node is ReactElement;
|
|
322
|
-
|
|
323
|
-
export { type CallbackChild, type CallbackChildren, type ChildrenCountBounds, type ElementOfType, type QueryOptions, type TraversalOptions, type ValidationOptions, childrenToElements, isElementOfType, isReactElement, useBoundedChildrenByType, useBoundedChildrenMatching, useCallbackChild, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useOptionalChildByType, useOptionalChildMatching, useRequiredCallbackChild, useRequiredChildByType, useRequiredChildMatching, useUniqueChildByType, useUniqueChildMatching };
|
|
315
|
+
export { type CallbackChild, type CallbackChildren, type ChildrenCountBounds, type ElementOfType, type QueryOptions, type TraversalOptions, type ValidationOptions, useBoundedChildrenByType, useBoundedChildrenMatching, useCallbackChild, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useOptionalCallbackChild, useOptionalChildByType, useOptionalChildMatching, useRequiredCallbackChild, useRequiredChildByType, useRequiredChildMatching, useUniqueCallbackChild, useUniqueChildByType, useUniqueChildMatching };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ var validationMessages = {
|
|
|
22
22
|
UNIQUE_CHILD_MATCHING_PREDICATE_FAILED: "{{ traceCodePrefix }}Unique child validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected exactly 1.",
|
|
23
23
|
REQUIRED_CHILD_MATCHING_PREDICATE_FAILED: "{{ traceCodePrefix }}Required child validation failed{{ childNameSegment }} because no direct child satisfied the provided predicate.",
|
|
24
24
|
REQUIRED_CALLBACK_CHILD_FAILED: "{{ traceCodePrefix }}Required callback child validation failed{{ childNameSegment }} because no direct callback child was found.",
|
|
25
|
+
OPTIONAL_CALLBACK_CHILD_FAILED: "{{ traceCodePrefix }}Optional callback child validation failed{{ childNameSegment }} because {{ actualCount }} direct callback children were found; expected at most 1.",
|
|
26
|
+
UNIQUE_CALLBACK_CHILD_FAILED: "{{ traceCodePrefix }}Unique callback child validation failed{{ childNameSegment }} because {{ actualCount }} direct callback children were found; expected exactly 1.",
|
|
25
27
|
MINIMUM_CHILDREN_MATCHING_PREDICATE_FAILED: "{{ traceCodePrefix }}Minimum children validation failed{{ childNameSegment }} because only {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at least {{ minimumCount }}.",
|
|
26
28
|
MAXIMUM_CHILDREN_MATCHING_PREDICATE_FAILED: "{{ traceCodePrefix }}Maximum children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at most {{ maximumCount }}.",
|
|
27
29
|
EXACT_CHILDREN_MATCHING_PREDICATE_FAILED: "{{ traceCodePrefix }}Exact children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected exactly {{ exactCount }}.",
|
|
@@ -87,10 +89,11 @@ function useChildMatching(children, predicate, options) {
|
|
|
87
89
|
[children, options, predicate]
|
|
88
90
|
);
|
|
89
91
|
}
|
|
92
|
+
var useChildMatching_default = useChildMatching;
|
|
90
93
|
|
|
91
94
|
// src/useChildByType.ts
|
|
92
95
|
function useChildByType(children, type, options) {
|
|
93
|
-
return
|
|
96
|
+
return useChildMatching_default(
|
|
94
97
|
children,
|
|
95
98
|
(element) => isElementOfType(element, type),
|
|
96
99
|
options
|
|
@@ -99,25 +102,26 @@ function useChildByType(children, type, options) {
|
|
|
99
102
|
|
|
100
103
|
// src/useCallbackChild.ts
|
|
101
104
|
import { useMemo as useMemo2 } from "react";
|
|
102
|
-
|
|
105
|
+
|
|
106
|
+
// src/callbackChildrenToArray.ts
|
|
107
|
+
function callbackChildrenToArray(children) {
|
|
103
108
|
if (typeof children === "function") {
|
|
104
|
-
return children;
|
|
109
|
+
return [children];
|
|
105
110
|
}
|
|
106
111
|
if (!Array.isArray(children)) {
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
for (const child of children) {
|
|
110
|
-
const callbackChild = findFirstCallbackChild(
|
|
111
|
-
child
|
|
112
|
-
);
|
|
113
|
-
if (callbackChild) {
|
|
114
|
-
return callbackChild;
|
|
115
|
-
}
|
|
112
|
+
return [];
|
|
116
113
|
}
|
|
117
|
-
return
|
|
114
|
+
return children.flatMap(
|
|
115
|
+
(child) => callbackChildrenToArray(child)
|
|
116
|
+
);
|
|
118
117
|
}
|
|
118
|
+
|
|
119
|
+
// src/useCallbackChild.ts
|
|
119
120
|
function useCallbackChild(children) {
|
|
120
|
-
return useMemo2(
|
|
121
|
+
return useMemo2(
|
|
122
|
+
() => callbackChildrenToArray(children)[0] ?? null,
|
|
123
|
+
[children]
|
|
124
|
+
);
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
// src/useChildrenMatching.ts
|
|
@@ -128,10 +132,11 @@ function useChildrenMatching(children, predicate, options) {
|
|
|
128
132
|
[children, options, predicate]
|
|
129
133
|
);
|
|
130
134
|
}
|
|
135
|
+
var useChildrenMatching_default = useChildrenMatching;
|
|
131
136
|
|
|
132
137
|
// src/useBoundedChildrenMatching.ts
|
|
133
138
|
function useBoundedChildrenMatching(children, predicate, bounds, options) {
|
|
134
|
-
const matchingChildren =
|
|
139
|
+
const matchingChildren = useChildrenMatching_default(children, predicate, options);
|
|
135
140
|
if (matchingChildren.length >= bounds.minimum && matchingChildren.length <= bounds.maximum) {
|
|
136
141
|
return matchingChildren;
|
|
137
142
|
}
|
|
@@ -144,10 +149,11 @@ function useBoundedChildrenMatching(children, predicate, bounds, options) {
|
|
|
144
149
|
maximumCount: bounds.maximum
|
|
145
150
|
});
|
|
146
151
|
}
|
|
152
|
+
var useBoundedChildrenMatching_default = useBoundedChildrenMatching;
|
|
147
153
|
|
|
148
154
|
// src/useBoundedChildrenByType.ts
|
|
149
155
|
function useBoundedChildrenByType(children, type, bounds, options) {
|
|
150
|
-
return
|
|
156
|
+
return useBoundedChildrenMatching_default(
|
|
151
157
|
children,
|
|
152
158
|
(element) => isElementOfType(element, type),
|
|
153
159
|
bounds,
|
|
@@ -157,7 +163,7 @@ function useBoundedChildrenByType(children, type, bounds, options) {
|
|
|
157
163
|
|
|
158
164
|
// src/useChildrenByType.ts
|
|
159
165
|
function useChildrenByType(children, type, options) {
|
|
160
|
-
return
|
|
166
|
+
return useChildrenMatching_default(
|
|
161
167
|
children,
|
|
162
168
|
(element) => isElementOfType(element, type),
|
|
163
169
|
options
|
|
@@ -166,7 +172,7 @@ function useChildrenByType(children, type, options) {
|
|
|
166
172
|
|
|
167
173
|
// src/useExactChildrenMatching.ts
|
|
168
174
|
function useExactChildrenMatching(children, predicate, exactCount, options) {
|
|
169
|
-
const matchingChildren =
|
|
175
|
+
const matchingChildren = useChildrenMatching_default(children, predicate, options);
|
|
170
176
|
if (matchingChildren.length === exactCount) {
|
|
171
177
|
return matchingChildren;
|
|
172
178
|
}
|
|
@@ -178,10 +184,11 @@ function useExactChildrenMatching(children, predicate, exactCount, options) {
|
|
|
178
184
|
exactCount
|
|
179
185
|
});
|
|
180
186
|
}
|
|
187
|
+
var useExactChildrenMatching_default = useExactChildrenMatching;
|
|
181
188
|
|
|
182
189
|
// src/useExactChildrenByType.ts
|
|
183
190
|
function useExactChildrenByType(children, type, exactCount, options) {
|
|
184
|
-
return
|
|
191
|
+
return useExactChildrenMatching_default(
|
|
185
192
|
children,
|
|
186
193
|
(element) => isElementOfType(element, type),
|
|
187
194
|
exactCount,
|
|
@@ -197,10 +204,11 @@ function useHasChildMatching(children, predicate, options) {
|
|
|
197
204
|
[children, options, predicate]
|
|
198
205
|
);
|
|
199
206
|
}
|
|
207
|
+
var useHasChildMatching_default = useHasChildMatching;
|
|
200
208
|
|
|
201
209
|
// src/useMaximumChildrenMatching.ts
|
|
202
210
|
function useMaximumChildrenMatching(children, predicate, maximumCount, options) {
|
|
203
|
-
const matchingChildren =
|
|
211
|
+
const matchingChildren = useChildrenMatching_default(children, predicate, options);
|
|
204
212
|
if (matchingChildren.length <= maximumCount) {
|
|
205
213
|
return matchingChildren;
|
|
206
214
|
}
|
|
@@ -212,10 +220,11 @@ function useMaximumChildrenMatching(children, predicate, maximumCount, options)
|
|
|
212
220
|
maximumCount
|
|
213
221
|
});
|
|
214
222
|
}
|
|
223
|
+
var useMaximumChildrenMatching_default = useMaximumChildrenMatching;
|
|
215
224
|
|
|
216
225
|
// src/useMaximumChildrenByType.ts
|
|
217
226
|
function useMaximumChildrenByType(children, type, maximumCount, options) {
|
|
218
|
-
return
|
|
227
|
+
return useMaximumChildrenMatching_default(
|
|
219
228
|
children,
|
|
220
229
|
(element) => isElementOfType(element, type),
|
|
221
230
|
maximumCount,
|
|
@@ -225,7 +234,7 @@ function useMaximumChildrenByType(children, type, maximumCount, options) {
|
|
|
225
234
|
|
|
226
235
|
// src/useMinimumChildrenMatching.ts
|
|
227
236
|
function useMinimumChildrenMatching(children, predicate, minimumCount, options) {
|
|
228
|
-
const matchingChildren =
|
|
237
|
+
const matchingChildren = useChildrenMatching_default(children, predicate, options);
|
|
229
238
|
if (matchingChildren.length >= minimumCount) {
|
|
230
239
|
return matchingChildren;
|
|
231
240
|
}
|
|
@@ -237,10 +246,11 @@ function useMinimumChildrenMatching(children, predicate, minimumCount, options)
|
|
|
237
246
|
minimumCount
|
|
238
247
|
});
|
|
239
248
|
}
|
|
249
|
+
var useMinimumChildrenMatching_default = useMinimumChildrenMatching;
|
|
240
250
|
|
|
241
251
|
// src/useMinimumChildrenByType.ts
|
|
242
252
|
function useMinimumChildrenByType(children, type, minimumCount, options) {
|
|
243
|
-
return
|
|
253
|
+
return useMinimumChildrenMatching_default(
|
|
244
254
|
children,
|
|
245
255
|
(element) => isElementOfType(element, type),
|
|
246
256
|
minimumCount,
|
|
@@ -248,9 +258,26 @@ function useMinimumChildrenByType(children, type, minimumCount, options) {
|
|
|
248
258
|
);
|
|
249
259
|
}
|
|
250
260
|
|
|
261
|
+
// src/useOptionalCallbackChild.ts
|
|
262
|
+
import { useMemo as useMemo5 } from "react";
|
|
263
|
+
function useOptionalCallbackChild(children, options) {
|
|
264
|
+
const callbackChildren = useMemo5(
|
|
265
|
+
() => callbackChildrenToArray(children),
|
|
266
|
+
[children]
|
|
267
|
+
);
|
|
268
|
+
if (callbackChildren.length <= 1) {
|
|
269
|
+
return callbackChildren[0] ?? null;
|
|
270
|
+
}
|
|
271
|
+
return reporter_default.fail("OPTIONAL_CALLBACK_CHILD_FAILED", {
|
|
272
|
+
traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : "",
|
|
273
|
+
childNameSegment: options?.childName ? ` for ${options.childName}` : "",
|
|
274
|
+
actualCount: callbackChildren.length
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
251
278
|
// src/useOptionalChildMatching.ts
|
|
252
279
|
function useOptionalChildMatching(children, predicate, options) {
|
|
253
|
-
const matchingChildren =
|
|
280
|
+
const matchingChildren = useChildrenMatching_default(children, predicate, options);
|
|
254
281
|
if (matchingChildren.length <= 1) {
|
|
255
282
|
return matchingChildren[0] ?? null;
|
|
256
283
|
}
|
|
@@ -261,10 +288,11 @@ function useOptionalChildMatching(children, predicate, options) {
|
|
|
261
288
|
actualCountPluralSuffix: matchingChildren.length === 1 ? "" : "ren"
|
|
262
289
|
});
|
|
263
290
|
}
|
|
291
|
+
var useOptionalChildMatching_default = useOptionalChildMatching;
|
|
264
292
|
|
|
265
293
|
// src/useOptionalChildByType.ts
|
|
266
294
|
function useOptionalChildByType(children, type, options) {
|
|
267
|
-
return
|
|
295
|
+
return useOptionalChildMatching_default(
|
|
268
296
|
children,
|
|
269
297
|
(element) => isElementOfType(element, type),
|
|
270
298
|
options
|
|
@@ -273,7 +301,7 @@ function useOptionalChildByType(children, type, options) {
|
|
|
273
301
|
|
|
274
302
|
// src/useRequiredChildMatching.ts
|
|
275
303
|
function useRequiredChildMatching(children, predicate, options) {
|
|
276
|
-
const child =
|
|
304
|
+
const child = useChildMatching_default(children, predicate, options);
|
|
277
305
|
if (child !== null) {
|
|
278
306
|
return child;
|
|
279
307
|
}
|
|
@@ -282,10 +310,11 @@ function useRequiredChildMatching(children, predicate, options) {
|
|
|
282
310
|
childNameSegment: options?.childName ? ` for ${options.childName}` : ""
|
|
283
311
|
});
|
|
284
312
|
}
|
|
313
|
+
var useRequiredChildMatching_default = useRequiredChildMatching;
|
|
285
314
|
|
|
286
315
|
// src/useRequiredChildByType.ts
|
|
287
316
|
function useRequiredChildByType(children, type, options) {
|
|
288
|
-
return
|
|
317
|
+
return useRequiredChildMatching_default(
|
|
289
318
|
children,
|
|
290
319
|
(element) => isElementOfType(element, type),
|
|
291
320
|
options
|
|
@@ -305,9 +334,26 @@ function useRequiredCallbackChild(children, options) {
|
|
|
305
334
|
});
|
|
306
335
|
}
|
|
307
336
|
|
|
337
|
+
// src/useUniqueCallbackChild.ts
|
|
338
|
+
import { useMemo as useMemo6 } from "react";
|
|
339
|
+
function useUniqueCallbackChild(children, options) {
|
|
340
|
+
const callbackChildren = useMemo6(
|
|
341
|
+
() => callbackChildrenToArray(children),
|
|
342
|
+
[children]
|
|
343
|
+
);
|
|
344
|
+
if (callbackChildren.length === 1) {
|
|
345
|
+
return callbackChildren[0];
|
|
346
|
+
}
|
|
347
|
+
return reporter_default.fail("UNIQUE_CALLBACK_CHILD_FAILED", {
|
|
348
|
+
traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : "",
|
|
349
|
+
childNameSegment: options?.childName ? ` for ${options.childName}` : "",
|
|
350
|
+
actualCount: callbackChildren.length
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
308
354
|
// src/useUniqueChildMatching.ts
|
|
309
355
|
function useUniqueChildMatching(children, predicate, options) {
|
|
310
|
-
const matchingChildren =
|
|
356
|
+
const matchingChildren = useChildrenMatching_default(children, predicate, options);
|
|
311
357
|
if (matchingChildren.length === 1) {
|
|
312
358
|
return matchingChildren[0];
|
|
313
359
|
}
|
|
@@ -318,39 +364,39 @@ function useUniqueChildMatching(children, predicate, options) {
|
|
|
318
364
|
actualCountPluralSuffix: matchingChildren.length === 1 ? "" : "ren"
|
|
319
365
|
});
|
|
320
366
|
}
|
|
367
|
+
var useUniqueChildMatching_default = useUniqueChildMatching;
|
|
321
368
|
|
|
322
369
|
// src/useUniqueChildByType.ts
|
|
323
370
|
function useUniqueChildByType(children, type, options) {
|
|
324
|
-
return
|
|
371
|
+
return useUniqueChildMatching_default(
|
|
325
372
|
children,
|
|
326
373
|
(element) => isElementOfType(element, type),
|
|
327
374
|
options
|
|
328
375
|
);
|
|
329
376
|
}
|
|
330
377
|
export {
|
|
331
|
-
childrenToElements,
|
|
332
|
-
isElementOfType,
|
|
333
|
-
isReactElement,
|
|
334
378
|
useBoundedChildrenByType,
|
|
335
|
-
useBoundedChildrenMatching,
|
|
379
|
+
useBoundedChildrenMatching_default as useBoundedChildrenMatching,
|
|
336
380
|
useCallbackChild,
|
|
337
381
|
useChildByType,
|
|
338
|
-
useChildMatching,
|
|
382
|
+
useChildMatching_default as useChildMatching,
|
|
339
383
|
useChildrenByType,
|
|
340
|
-
useChildrenMatching,
|
|
384
|
+
useChildrenMatching_default as useChildrenMatching,
|
|
341
385
|
useExactChildrenByType,
|
|
342
|
-
useExactChildrenMatching,
|
|
343
|
-
useHasChildMatching,
|
|
386
|
+
useExactChildrenMatching_default as useExactChildrenMatching,
|
|
387
|
+
useHasChildMatching_default as useHasChildMatching,
|
|
344
388
|
useMaximumChildrenByType,
|
|
345
|
-
useMaximumChildrenMatching,
|
|
389
|
+
useMaximumChildrenMatching_default as useMaximumChildrenMatching,
|
|
346
390
|
useMinimumChildrenByType,
|
|
347
|
-
useMinimumChildrenMatching,
|
|
391
|
+
useMinimumChildrenMatching_default as useMinimumChildrenMatching,
|
|
392
|
+
useOptionalCallbackChild,
|
|
348
393
|
useOptionalChildByType,
|
|
349
|
-
useOptionalChildMatching,
|
|
394
|
+
useOptionalChildMatching_default as useOptionalChildMatching,
|
|
350
395
|
useRequiredCallbackChild,
|
|
351
396
|
useRequiredChildByType,
|
|
352
|
-
useRequiredChildMatching,
|
|
397
|
+
useRequiredChildMatching_default as useRequiredChildMatching,
|
|
398
|
+
useUniqueCallbackChild,
|
|
353
399
|
useUniqueChildByType,
|
|
354
|
-
useUniqueChildMatching
|
|
400
|
+
useUniqueChildMatching_default as useUniqueChildMatching
|
|
355
401
|
};
|
|
356
402
|
//# sourceMappingURL=index.js.map
|