@spark-ui/internal-utils 7.1.1 → 7.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [7.2.0](https://github.com/adevinta/spark/compare/v7.1.1...v7.2.0) (2024-11-26)
7
+
8
+ ### Features
9
+
10
+ - **internal-utils:** add "useEvent" internal util ([9b495a1](https://github.com/adevinta/spark/commit/9b495a1f25f3d98e5cc0f74bc4a03943670350f8))
11
+
6
12
  ## [7.1.1](https://github.com/adevinta/spark/compare/v7.1.0...v7.1.1) (2024-11-26)
7
13
 
8
14
  **Note:** Version bump only for package @spark-ui/internal-utils
package/dist/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * as variantConstants from './variants/constants';
5
5
  export { deepFind } from './react-children-utilities/deepFind';
6
6
  export { createSplitProps } from './create-split-props';
7
7
  export { omit } from './object/omit';
8
+ export { useEvent } from './use-event';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),c=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),u=Object.freeze(Object.defineProperty({__proto__:null,designs:["filled","outlined","tinted","ghost","contrast","dashed"],intents:["current","main","support","success","error","info","alert","danger","neutral","surface","accent","basic"],shapes:["rounded","square","pill"],sizes:["current","sm","md","lg","xl"]},Symbol.toStringTag,{value:"Module"}));function a(e){return s.isValidElement(e)&&function(n){return s.isValidElement(n)&&!!n.props.children}(e)&&s.Children.toArray(e.props.children).reduce((n,r)=>n||s.isValidElement(r),!1)}exports.VariantTypes=c,exports.createSplitProps=()=>(e,n)=>n.reduce((r,i)=>{const[t,o]=r,l=i;return o[l]!==void 0&&(t[l]=o[l]),delete o[l],[t,o]},[{},{...e}]),exports.deepFind=function e(n,r){let i;return s.Children.toArray(n).find((t,o,l)=>r(t,o,l)?(i=t,!0):!(!s.isValidElement(t)||!a(t))&&(i=e(t.props.children,r),i!==void 0)),i},exports.makeVariants=function(e){return e},exports.omit=function(e,n){const r={};return Object.keys(e).forEach(i=>{const t=i;n.includes(t)||(r[t]=e[t])}),r},exports.tw=function(e){return e},exports.variantConstants=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),c=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),l=Object.freeze(Object.defineProperty({__proto__:null,designs:["filled","outlined","tinted","ghost","contrast","dashed"],intents:["current","main","support","success","error","info","alert","danger","neutral","surface","accent","basic"],shapes:["rounded","square","pill"],sizes:["current","sm","md","lg","xl"]},Symbol.toStringTag,{value:"Module"}));function a(n){return s.isValidElement(n)&&function(t){return s.isValidElement(t)&&!!t.props.children}(n)&&s.Children.toArray(n.props.children).reduce((t,r)=>t||s.isValidElement(r),!1)}exports.VariantTypes=c,exports.createSplitProps=()=>(n,t)=>t.reduce((r,o)=>{const[e,i]=r,u=o;return i[u]!==void 0&&(e[u]=i[u]),delete i[u],[e,i]},[{},{...n}]),exports.deepFind=function n(t,r){let o;return s.Children.toArray(t).find((e,i,u)=>r(e,i,u)?(o=e,!0):!(!s.isValidElement(e)||!a(e))&&(o=n(e.props.children,r),o!==void 0)),o},exports.makeVariants=function(n){return n},exports.omit=function(n,t){const r={};return Object.keys(n).forEach(o=>{const e=o;t.includes(e)||(r[e]=n[e])}),r},exports.tw=function(n){return n},exports.useEvent=function(n,t={}){const{sync:r=!1}=t,o=function(e){const i=s.useRef(e);return i.current=e,i}(n);return s.useCallback((...e)=>r?queueMicrotask(()=>o.current?.(...e)):o.current?.(...e),[r,o])},exports.variantConstants=l;
package/dist/index.mjs CHANGED
@@ -1,37 +1,45 @@
1
- import { isValidElement as i, Children as c } from "react";
2
- function p(e) {
1
+ import { isValidElement as c, Children as u, useCallback as i, useRef as l } from "react";
2
+ function m(e) {
3
3
  return e;
4
4
  }
5
- function f(e) {
5
+ function b(e) {
6
6
  return e;
7
7
  }
8
- const m = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), b = Object.freeze(Object.defineProperty({ __proto__: null, designs: ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"], intents: ["current", "main", "support", "success", "error", "info", "alert", "danger", "neutral", "surface", "accent", "basic"], shapes: ["rounded", "square", "pill"], sizes: ["current", "sm", "md", "lg", "xl"] }, Symbol.toStringTag, { value: "Module" }));
9
- function u(e) {
10
- return i(e) && function(t) {
11
- return i(t) && !!t.props.children;
12
- }(e) && c.toArray(e.props.children).reduce((t, n) => t || i(n), !1);
8
+ const y = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), g = Object.freeze(Object.defineProperty({ __proto__: null, designs: ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"], intents: ["current", "main", "support", "success", "error", "info", "alert", "danger", "neutral", "surface", "accent", "basic"], shapes: ["rounded", "square", "pill"], sizes: ["current", "sm", "md", "lg", "xl"] }, Symbol.toStringTag, { value: "Module" }));
9
+ function d(e) {
10
+ return c(e) && function(r) {
11
+ return c(r) && !!r.props.children;
12
+ }(e) && u.toArray(e.props.children).reduce((r, t) => r || c(t), !1);
13
13
  }
14
- function l(e, t) {
15
- let n;
16
- return c.toArray(e).find((r, o, s) => t(r, o, s) ? (n = r, !0) : !(!i(r) || !u(r)) && (n = l(r.props.children, t), n !== void 0)), n;
14
+ function f(e, r) {
15
+ let t;
16
+ return u.toArray(e).find((o, n, s) => r(o, n, s) ? (t = o, !0) : !(!c(o) || !d(o)) && (t = f(o.props.children, r), t !== void 0)), t;
17
17
  }
18
- const g = () => (e, t) => t.reduce((n, r) => {
19
- const [o, s] = n, a = r;
20
- return s[a] !== void 0 && (o[a] = s[a]), delete s[a], [o, s];
18
+ const h = () => (e, r) => r.reduce((t, o) => {
19
+ const [n, s] = t, a = o;
20
+ return s[a] !== void 0 && (n[a] = s[a]), delete s[a], [n, s];
21
21
  }, [{}, { ...e }]);
22
- function h(e, t) {
23
- const n = {};
24
- return Object.keys(e).forEach((r) => {
25
- const o = r;
26
- t.includes(o) || (n[o] = e[o]);
27
- }), n;
22
+ function _(e, r) {
23
+ const t = {};
24
+ return Object.keys(e).forEach((o) => {
25
+ const n = o;
26
+ r.includes(n) || (t[n] = e[n]);
27
+ }), t;
28
+ }
29
+ function v(e, r = {}) {
30
+ const { sync: t = !1 } = r, o = function(n) {
31
+ const s = l(n);
32
+ return s.current = n, s;
33
+ }(e);
34
+ return i((...n) => t ? queueMicrotask(() => o.current?.(...n)) : o.current?.(...n), [t, o]);
28
35
  }
29
36
  export {
30
- m as VariantTypes,
31
- g as createSplitProps,
32
- l as deepFind,
33
- f as makeVariants,
34
- h as omit,
35
- p as tw,
36
- b as variantConstants
37
+ y as VariantTypes,
38
+ h as createSplitProps,
39
+ f as deepFind,
40
+ b as makeVariants,
41
+ _ as omit,
42
+ m as tw,
43
+ v as useEvent,
44
+ g as variantConstants
37
45
  };
@@ -0,0 +1,12 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ interface Options {
3
+ /**
4
+ * Whether to use queueMicrotask or not
5
+ */
6
+ sync?: boolean;
7
+ }
8
+ /**
9
+ * Returns a memoized callback that will queueMicrotask the callback if sync is true
10
+ */
11
+ declare function useEvent<T extends AnyFunction>(callback: T | undefined, opts?: Options): T;
12
+ export { useEvent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/internal-utils",
3
- "version": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "description": "package for sharing reusable code and resources across the codebase",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -34,5 +34,5 @@
34
34
  },
35
35
  "homepage": "https://sparkui.vercel.app",
36
36
  "license": "MIT",
37
- "gitHead": "2c7e5e010f9503d68405dd24e4cc40fab7dd7cdd"
37
+ "gitHead": "819bc8f1d05c1fdd206165218e12b1bfa62376f7"
38
38
  }