@kopexa/react-utils 2.0.3 → 2.0.4

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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets only the valid children of a component,
3
+ * and ignores any nullish or falsy child.
4
+ *
5
+ * @param children the children
6
+ */
7
+ declare function getValidChildren(children: React.ReactNode): React.ReactElement[];
8
+
9
+ export { getValidChildren };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets only the valid children of a component,
3
+ * and ignores any nullish or falsy child.
4
+ *
5
+ * @param children the children
6
+ */
7
+ declare function getValidChildren(children: React.ReactNode): React.ReactElement[];
8
+
9
+ export { getValidChildren };
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/children.ts
22
+ var children_exports = {};
23
+ __export(children_exports, {
24
+ getValidChildren: () => getValidChildren
25
+ });
26
+ module.exports = __toCommonJS(children_exports);
27
+ var import_react = require("react");
28
+ function getValidChildren(children) {
29
+ return import_react.Children.toArray(children).filter(
30
+ (child) => (0, import_react.isValidElement)(child)
31
+ );
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ getValidChildren
36
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ getValidChildren
4
+ } from "./chunk-KGECMVHS.mjs";
5
+ export {
6
+ getValidChildren
7
+ };
@@ -0,0 +1,13 @@
1
+ "use client";
2
+
3
+ // src/children.ts
4
+ import { Children, isValidElement } from "react";
5
+ function getValidChildren(children) {
6
+ return Children.toArray(children).filter(
7
+ (child) => isValidElement(child)
8
+ );
9
+ }
10
+
11
+ export {
12
+ getValidChildren
13
+ };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ export { getValidChildren } from './children.mjs';
1
2
  export { createContext } from './context.mjs';
2
3
  export { mergeRefs } from './dom.mjs';
4
+ export { DOMAttributes, DOMElement, Merge, PropGetter } from './types.mjs';
3
5
  import 'react';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { getValidChildren } from './children.js';
1
2
  export { createContext } from './context.js';
2
3
  export { mergeRefs } from './dom.js';
4
+ export { DOMAttributes, DOMElement, Merge, PropGetter } from './types.js';
3
5
  import 'react';
package/dist/index.js CHANGED
@@ -22,12 +22,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
24
  createContext: () => createContext,
25
+ getValidChildren: () => getValidChildren,
25
26
  mergeRefs: () => mergeRefs
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
28
29
 
29
- // src/context.ts
30
+ // src/children.ts
30
31
  var import_react = require("react");
32
+ function getValidChildren(children) {
33
+ return import_react.Children.toArray(children).filter(
34
+ (child) => (0, import_react.isValidElement)(child)
35
+ );
36
+ }
37
+
38
+ // src/context.ts
39
+ var import_react2 = require("react");
31
40
  function getErrorMessage(hook, provider) {
32
41
  return `${hook} returned \`undefined\`. Seems you forgot to wrap component within ${provider}`;
33
42
  }
@@ -40,11 +49,11 @@ function createContext(options = {}) {
40
49
  errorMessage,
41
50
  defaultValue
42
51
  } = options;
43
- const Context = (0, import_react.createContext)(defaultValue);
52
+ const Context = (0, import_react2.createContext)(defaultValue);
44
53
  Context.displayName = name;
45
54
  function useContext() {
46
55
  var _a;
47
- const context = (0, import_react.useContext)(Context);
56
+ const context = (0, import_react2.useContext)(Context);
48
57
  if (!context && strict) {
49
58
  const error = new Error(
50
59
  errorMessage != null ? errorMessage : getErrorMessage(hookName, providerName)
@@ -78,5 +87,6 @@ function mergeRefs(...inputRefs) {
78
87
  // Annotate the CommonJS export names for ESM import in node:
79
88
  0 && (module.exports = {
80
89
  createContext,
90
+ getValidChildren,
81
91
  mergeRefs
82
92
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  "use client";
2
+ import {
3
+ getValidChildren
4
+ } from "./chunk-KGECMVHS.mjs";
2
5
  import {
3
6
  createContext
4
7
  } from "./chunk-2DAVPPDT.mjs";
@@ -7,5 +10,6 @@ import {
7
10
  } from "./chunk-FGSQ5KEN.mjs";
8
11
  export {
9
12
  createContext,
13
+ getValidChildren,
10
14
  mergeRefs
11
15
  };
@@ -0,0 +1,16 @@
1
+ /** biome-ignore-all lint/suspicious/noExplicitAny: utility file */
2
+ interface DOMElement extends Element, HTMLOrSVGElement {
3
+ }
4
+ type DataAttributes = {
5
+ [dataAttr: string]: any;
6
+ };
7
+ type DOMAttributes<T = DOMElement> = React.AriaAttributes & React.DOMAttributes<T> & DataAttributes & {
8
+ id?: string;
9
+ role?: React.AriaRole;
10
+ tabIndex?: number;
11
+ style?: React.CSSProperties;
12
+ };
13
+ type Merge<M, N> = N extends Record<string, unknown> ? M : Omit<M, keyof N> & N;
14
+ type PropGetter<P = Record<string, unknown>, R = DOMAttributes> = (props?: Merge<DOMAttributes, P>, ref?: React.Ref<any>) => R & React.RefAttributes<any>;
15
+
16
+ export type { DOMAttributes, DOMElement, Merge, PropGetter };
@@ -0,0 +1,16 @@
1
+ /** biome-ignore-all lint/suspicious/noExplicitAny: utility file */
2
+ interface DOMElement extends Element, HTMLOrSVGElement {
3
+ }
4
+ type DataAttributes = {
5
+ [dataAttr: string]: any;
6
+ };
7
+ type DOMAttributes<T = DOMElement> = React.AriaAttributes & React.DOMAttributes<T> & DataAttributes & {
8
+ id?: string;
9
+ role?: React.AriaRole;
10
+ tabIndex?: number;
11
+ style?: React.CSSProperties;
12
+ };
13
+ type Merge<M, N> = N extends Record<string, unknown> ? M : Omit<M, keyof N> & N;
14
+ type PropGetter<P = Record<string, unknown>, R = DOMAttributes> = (props?: Merge<DOMAttributes, P>, ref?: React.Ref<any>) => R & React.RefAttributes<any>;
15
+
16
+ export type { DOMAttributes, DOMElement, Merge, PropGetter };
package/dist/types.js ADDED
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/types.ts
18
+ var types_exports = {};
19
+ module.exports = __toCommonJS(types_exports);
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ "use client";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopexa/react-utils",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "A set of utilities for react on client side",
5
5
  "keywords": [
6
6
  "react-utils"
@@ -28,7 +28,7 @@
28
28
  "react": ">=19.0.0-rc.0"
29
29
  },
30
30
  "dependencies": {
31
- "@kopexa/shared-utils": "1.1.3"
31
+ "@kopexa/shared-utils": "1.1.4"
32
32
  },
33
33
  "clean-package": "../../../clean-package.config.json",
34
34
  "module": "dist/index.mjs",