@zayne-labs/toolkit-react 0.8.37 → 0.8.38

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.
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { RefCallback } from 'react';
3
- import { AnyFunction } from '@zayne-labs/toolkit-type-helpers';
3
+ import { AnyFunction, Prettify } from '@zayne-labs/toolkit-type-helpers';
4
4
 
5
5
  type PossibleRef<TRef> = React.Ref<TRef> | undefined;
6
6
  /**
@@ -43,10 +43,9 @@ type MyCustomCss<TExtra extends Record<string, string> = NonNullable<unknown>> =
43
43
  * @description Represents a set of props that can be used to render a component conditionally based on a discriminated union type.
44
44
  * This type allows for the use of either a render prop or children prop, but not both at the same time.
45
45
  * If both are provided, a TypeScript error will be thrown.
46
- * @template TRenderPropType The type of the function that will be called to render the component when using the render prop.
47
46
  * @template TMessage A message to display when the render prop is not used and the children prop is instead used.
48
47
  */
49
- type DiscriminatedRenderProps<TRenderPropType extends AnyFunction, TMessage extends string = "Hey, Sorry but since you're currently using the children prop, the render prop is therefore redundant"> = {
48
+ type DiscriminatedRenderProps<TRenderPropType, TMessage extends string = "Hey, Sorry but since you're currently using the children prop, the render prop is therefore redundant"> = {
50
49
  children: TRenderPropType;
51
50
  render?: TMessage;
52
51
  } | {
@@ -57,8 +56,8 @@ type DiscriminatedRenderProps<TRenderPropType extends AnyFunction, TMessage exte
57
56
  type AsProp<TElement extends React.ElementType> = {
58
57
  as?: TElement;
59
58
  };
60
- type PropsWithOptionalAs<TElement extends React.ElementType, TProps> = "as" extends keyof TProps ? TProps : AsProp<TElement> & TProps;
61
- type InferOtherProps<TElement extends React.ElementType, TProps> = Omit<React.ComponentPropsWithRef<TElement>, keyof PropsWithOptionalAs<TElement, TProps>>;
62
- type PolymorphicProps<TElement extends React.ElementType, TProps extends Record<keyof any, any> = AsProp<TElement>> = InferOtherProps<TElement, TProps> & PropsWithOptionalAs<TElement, TProps>;
59
+ type InferRestOfProps<TElement extends React.ElementType, TProps> = Omit<React.ComponentPropsWithRef<TElement>, keyof TProps>;
60
+ type MergedPropsWithAs<TElement extends React.ElementType, TProps> = Omit<AsProp<TElement>, keyof TProps> & TProps;
61
+ type PolymorphicProps<TElement extends React.ElementType, TProps extends Record<keyof any, any>> = InferRestOfProps<TElement, TProps> & Prettify<MergedPropsWithAs<TElement, TProps>>;
63
62
 
64
63
  export { type AsProp, type DiscriminatedRenderProps, type ForwardedRefType, type InferProps, type MyCustomCss, type PolymorphicProps, type StateSetter, composeRefs, getOtherChildren, getSlotElement, isSlotElement, mergeProps, mergeTwoProps, setRef };
@@ -6,7 +6,7 @@ import { a as CustomContextOptions } from '../createCustomContext-CWNyhkUi.js';
6
6
 
7
7
  declare const createZustandContext: <TState extends Record<string, unknown>, TUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>>(options?: CustomContextOptions<TUseBoundStore, true>) => [ZustandProvider: (props: {
8
8
  children: React.ReactNode;
9
- createStore: () => TUseBoundStore;
9
+ storeCreator: () => TUseBoundStore;
10
10
  } | {
11
11
  children: React.ReactNode;
12
12
  value: TUseBoundStore;
@@ -7,7 +7,7 @@ var createZustandContext = (options) => {
7
7
  function ZustandProvider(props) {
8
8
  const { children, ...restOfProps } = props;
9
9
  const useZustandStore = useConstant(
10
- () => "createStore" in restOfProps ? restOfProps.createStore() : restOfProps.value
10
+ () => "storeCreator" in restOfProps ? restOfProps.storeCreator() : restOfProps.value
11
11
  );
12
12
  return createElement(Provider, { value: useZustandStore }, children);
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts"],"names":[],"mappings":";;;;AAKM,IAAA,oBAAA,GAAuB,CAI5B,OACI,KAAA;AACJ,EAAA,MAAM,CAAC,QAAA,EAAU,gBAAgB,CAAA,GAAI,oBAAoB,OAAO,CAAA;AAYhE,EAAA,SAAS,gBAAgB,KAA6B,EAAA;AACrD,IAAA,MAAM,EAAE,QAAA,EAAU,GAAG,WAAA,EAAgB,GAAA,KAAA;AAErC,IAAA,MAAM,eAAkB,GAAA,WAAA;AAAA,MAAY,MACnC,aAAiB,IAAA,WAAA,GAAc,WAAY,CAAA,WAAA,KAAgB,WAAY,CAAA;AAAA,KACxE;AAEA,IAAA,OAAO,cAAc,QAAU,EAAA,EAAE,KAAO,EAAA,eAAA,IAAmB,QAAQ,CAAA;AAAA;AAGpE,EAAA,MAAM,aAAgB,GAAA,CAAU,QAA0C,KAAA,gBAAA,GAAmB,QAAQ,CAAA;AAErG,EAAO,OAAA,CAAC,iBAAiB,aAAa,CAAA;AAIvC;AC1Ba,IAAA,OAAA,GACZ,CAAC,YAAc,EAAA,YAAA;AAAA;AAAA,EAEf,IAAI,MAAY,MAAA;AAAA,IACf,GAAG,YAAA;AAAA,IACH,GAAI,YAA6B,CAAA,GAAG,MAAM;AAAA,GAC3C;AAAA;AAEM,IAAM,yBAAyB,CAClC,GAAA,MAAA,KACC,YAAY,OAAQ,CAAA,GAAG,MAAM,CAAC;AAE5B,IAAM,oBAAoB,CAC7B,GAAA,MAAA,KACC,OAAO,OAAQ,CAAA,GAAG,MAAM,CAAC","file":"index.js","sourcesContent":["import type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps =\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tcreateStore: () => TUseBoundStore;\n\t\t }\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tvalue: TUseBoundStore;\n\t\t };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, ...restOfProps } = props;\n\n\t\tconst useZustandStore = useConstant(() =>\n\t\t\t\"createStore\" in restOfProps ? restOfProps.createStore() : restOfProps.value\n\t\t);\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult>(selector: SelectorFn<TState, TResult>) => useCustomContext()(selector);\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\nexport type Combine = <\n\tTInitialState extends AnyObject,\n\tTExtraState extends AnyObject,\n\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n>(\n\tinitialState: TInitialState,\n\tadditionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n) => StateCreator<TExtraState & TInitialState>;\n\nexport const combine: Combine =\n\t(initialState, storeCreator) =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n"]}
1
+ {"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts"],"names":[],"mappings":";;;;AAKM,IAAA,oBAAA,GAAuB,CAI5B,OACI,KAAA;AACJ,EAAA,MAAM,CAAC,QAAA,EAAU,gBAAgB,CAAA,GAAI,oBAAoB,OAAO,CAAA;AAYhE,EAAA,SAAS,gBAAgB,KAA6B,EAAA;AACrD,IAAA,MAAM,EAAE,QAAA,EAAU,GAAG,WAAA,EAAgB,GAAA,KAAA;AAErC,IAAA,MAAM,eAAkB,GAAA,WAAA;AAAA,MAAY,MACnC,cAAkB,IAAA,WAAA,GAAc,WAAY,CAAA,YAAA,KAAiB,WAAY,CAAA;AAAA,KAC1E;AAEA,IAAA,OAAO,cAAc,QAAU,EAAA,EAAE,KAAO,EAAA,eAAA,IAAmB,QAAQ,CAAA;AAAA;AAGpE,EAAA,MAAM,aAAgB,GAAA,CAAU,QAA0C,KAAA,gBAAA,GAAmB,QAAQ,CAAA;AAErG,EAAO,OAAA,CAAC,iBAAiB,aAAa,CAAA;AAIvC;AC1Ba,IAAA,OAAA,GACZ,CAAC,YAAc,EAAA,YAAA;AAAA;AAAA,EAEf,IAAI,MAAY,MAAA;AAAA,IACf,GAAG,YAAA;AAAA,IACH,GAAI,YAA6B,CAAA,GAAG,MAAM;AAAA,GAC3C;AAAA;AAEM,IAAM,yBAAyB,CAClC,GAAA,MAAA,KACC,YAAY,OAAQ,CAAA,GAAG,MAAM,CAAC;AAE5B,IAAM,oBAAoB,CAC7B,GAAA,MAAA,KACC,OAAO,OAAQ,CAAA,GAAG,MAAM,CAAC","file":"index.js","sourcesContent":["import type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps =\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tstoreCreator: () => TUseBoundStore;\n\t\t }\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tvalue: TUseBoundStore;\n\t\t };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, ...restOfProps } = props;\n\n\t\tconst useZustandStore = useConstant(() =>\n\t\t\t\"storeCreator\" in restOfProps ? restOfProps.storeCreator() : restOfProps.value\n\t\t);\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult>(selector: SelectorFn<TState, TResult>) => useCustomContext()(selector);\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\nexport type Combine = <\n\tTInitialState extends AnyObject,\n\tTExtraState extends AnyObject,\n\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n>(\n\tinitialState: TInitialState,\n\tadditionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n) => StateCreator<TExtraState & TInitialState>;\n\nexport const combine: Combine =\n\t(initialState, storeCreator) =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/toolkit-react",
3
3
  "type": "module",
4
- "version": "0.8.37",
4
+ "version": "0.8.38",
5
5
  "description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -50,25 +50,25 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@zayne-labs/toolkit-core": "0.8.37",
54
- "@zayne-labs/toolkit-type-helpers": "0.8.37"
53
+ "@zayne-labs/toolkit-core": "0.8.38",
54
+ "@zayne-labs/toolkit-type-helpers": "0.8.38"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@arethetypeswrong/cli": "^0.17.3",
58
- "@changesets/cli": "^2.27.12",
59
- "@size-limit/esbuild-why": "^11.1.6",
60
- "@size-limit/preset-small-lib": "^11.1.6",
58
+ "@changesets/cli": "^2.28.1",
59
+ "@size-limit/esbuild-why": "^11.2.0",
60
+ "@size-limit/preset-small-lib": "^11.2.0",
61
61
  "@total-typescript/ts-reset": "^0.6.1",
62
62
  "@types/node": "^22.13.4",
63
- "@types/react": "^19.0.8",
64
- "@types/react-dom": "^19.0.3",
63
+ "@types/react": "^19.0.10",
64
+ "@types/react-dom": "^19.0.4",
65
65
  "@zayne-labs/tsconfig": "0.2.1",
66
66
  "concurrently": "^9.1.2",
67
67
  "cross-env": "^7.0.3",
68
- "publint": "^0.3.5",
68
+ "publint": "^0.3.6",
69
69
  "react": "^19.0.0",
70
70
  "react-dom": "^19.0.0",
71
- "size-limit": "^11.1.6",
71
+ "size-limit": "^11.2.0",
72
72
  "terser": "^5.39.0",
73
73
  "tsup": "^8.3.6",
74
74
  "typescript": "5.7.3",