@zayne-labs/toolkit-react 0.11.19 → 0.11.21

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.
Files changed (127) hide show
  1. package/dist/esm/hooks/createCustomContext.d.ts +21 -0
  2. package/dist/esm/hooks/createCustomContext.js +25 -0
  3. package/dist/esm/hooks/createCustomContext.js.map +1 -0
  4. package/dist/esm/hooks/effects/useAfterMountEffect.d.ts +7 -0
  5. package/dist/esm/hooks/effects/useAfterMountEffect.js +19 -0
  6. package/dist/esm/hooks/effects/useAfterMountEffect.js.map +1 -0
  7. package/dist/esm/hooks/effects/useAsyncEffect.d.ts +5 -0
  8. package/dist/esm/hooks/effects/useAsyncEffect.js +20 -0
  9. package/dist/esm/hooks/effects/useAsyncEffect.js.map +1 -0
  10. package/dist/esm/hooks/effects/useEffectOnce.d.ts +5 -0
  11. package/dist/esm/hooks/effects/useEffectOnce.js +17 -0
  12. package/dist/esm/hooks/effects/useEffectOnce.js.map +1 -0
  13. package/dist/esm/hooks/effects/useLifeCycle.d.ts +13 -0
  14. package/dist/esm/hooks/effects/useLifeCycle.js +16 -0
  15. package/dist/esm/hooks/effects/useLifeCycle.js.map +1 -0
  16. package/dist/esm/hooks/effects/useMountEffect.d.ts +5 -0
  17. package/dist/esm/hooks/effects/useMountEffect.js +10 -0
  18. package/dist/esm/hooks/effects/useMountEffect.js.map +1 -0
  19. package/dist/esm/hooks/effects/useUnMountEffect.d.ts +7 -0
  20. package/dist/esm/hooks/effects/useUnMountEffect.js +8 -0
  21. package/dist/esm/hooks/effects/useUnMountEffect.js.map +1 -0
  22. package/dist/esm/hooks/index.d.ts +27 -2
  23. package/dist/esm/hooks/index.js +27 -2
  24. package/dist/esm/hooks/useAnimateElementRefs.d.ts +19 -0
  25. package/dist/esm/hooks/useAnimateElementRefs.js +54 -0
  26. package/dist/esm/hooks/useAnimateElementRefs.js.map +1 -0
  27. package/dist/esm/hooks/useAnimationInterval.d.ts +15 -0
  28. package/dist/esm/hooks/useAnimationInterval.js +27 -0
  29. package/dist/esm/hooks/useAnimationInterval.js.map +1 -0
  30. package/dist/esm/hooks/useCallbackRef.d.ts +13 -0
  31. package/dist/esm/hooks/useCallbackRef.js +19 -0
  32. package/dist/esm/hooks/useCallbackRef.js.map +1 -0
  33. package/dist/esm/hooks/useClickOutside.d.ts +14 -0
  34. package/dist/esm/hooks/useClickOutside.js +25 -0
  35. package/dist/esm/hooks/useClickOutside.js.map +1 -0
  36. package/dist/esm/hooks/useComposeRefs.d.ts +8 -0
  37. package/dist/esm/hooks/useComposeRefs.js +11 -0
  38. package/dist/esm/hooks/useComposeRefs.js.map +1 -0
  39. package/dist/esm/hooks/useConstant.d.ts +6 -0
  40. package/dist/esm/hooks/useConstant.js +17 -0
  41. package/dist/esm/hooks/useConstant.js.map +1 -0
  42. package/dist/esm/hooks/useControllable.d.ts +55 -0
  43. package/dist/esm/hooks/useControllable.js +79 -0
  44. package/dist/esm/hooks/useControllable.js.map +1 -0
  45. package/dist/esm/hooks/useCopyToClipboard.d.ts +15 -0
  46. package/dist/esm/hooks/useCopyToClipboard.js +49 -0
  47. package/dist/esm/hooks/useCopyToClipboard.js.map +1 -0
  48. package/dist/esm/hooks/useDebounce.d.ts +23 -0
  49. package/dist/esm/hooks/useDebounce.js +32 -0
  50. package/dist/esm/hooks/useDebounce.js.map +1 -0
  51. package/dist/esm/hooks/useDisclosure.d.ts +14 -0
  52. package/dist/esm/hooks/useDisclosure.js +42 -0
  53. package/dist/esm/hooks/useDisclosure.js.map +1 -0
  54. package/dist/esm/hooks/useIsHydrated.d.ts +28 -0
  55. package/dist/esm/hooks/useIsHydrated.js +39 -0
  56. package/dist/esm/hooks/useIsHydrated.js.map +1 -0
  57. package/dist/esm/hooks/useLocationState.d.ts +17 -0
  58. package/dist/esm/hooks/useLocationState.js +24 -0
  59. package/dist/esm/hooks/useLocationState.js.map +1 -0
  60. package/dist/esm/hooks/useScrollObserver.d.ts +11 -0
  61. package/dist/esm/hooks/useScrollObserver.js +44 -0
  62. package/dist/esm/hooks/useScrollObserver.js.map +1 -0
  63. package/dist/esm/hooks/useSearch.d.ts +12 -0
  64. package/dist/esm/hooks/useSearch.js +40 -0
  65. package/dist/esm/hooks/useSearch.js.map +1 -0
  66. package/dist/esm/hooks/useSearchParams.d.ts +12 -0
  67. package/dist/esm/hooks/useSearchParams.js +36 -0
  68. package/dist/esm/hooks/useSearchParams.js.map +1 -0
  69. package/dist/esm/hooks/useShallowCompare.d.ts +8 -0
  70. package/dist/esm/hooks/useShallowCompare.js +26 -0
  71. package/dist/esm/hooks/useShallowCompare.js.map +1 -0
  72. package/dist/esm/hooks/useStorageState.d.ts +20 -0
  73. package/dist/esm/hooks/useStorageState.js +54 -0
  74. package/dist/esm/hooks/useStorageState.js.map +1 -0
  75. package/dist/esm/hooks/useStore.d.ts +8 -0
  76. package/dist/esm/hooks/useStore.js +13 -0
  77. package/dist/esm/hooks/useStore.js.map +1 -0
  78. package/dist/esm/hooks/useThrottle.d.ts +15 -0
  79. package/dist/esm/hooks/useThrottle.js +27 -0
  80. package/dist/esm/hooks/useThrottle.js.map +1 -0
  81. package/dist/esm/hooks/useToggle.d.ts +6 -0
  82. package/dist/esm/hooks/useToggle.js +18 -0
  83. package/dist/esm/hooks/useToggle.js.map +1 -0
  84. package/dist/esm/utils/composeEventHandlers.d.ts +8 -0
  85. package/dist/esm/utils/composeEventHandlers.js +36 -0
  86. package/dist/esm/utils/composeEventHandlers.js.map +1 -0
  87. package/dist/esm/utils/composeRefs.d.ts +17 -0
  88. package/dist/esm/utils/composeRefs.js +28 -0
  89. package/dist/esm/utils/composeRefs.js.map +1 -0
  90. package/dist/esm/utils/getSlot/getSlot.d.ts +60 -0
  91. package/dist/esm/utils/getSlot/getSlot.js +78 -0
  92. package/dist/esm/utils/getSlot/getSlot.js.map +1 -0
  93. package/dist/esm/utils/getSlotMap/getSlotMap.d.ts +86 -0
  94. package/dist/esm/utils/getSlotMap/getSlotMap.js +87 -0
  95. package/dist/esm/utils/getSlotMap/getSlotMap.js.map +1 -0
  96. package/dist/esm/utils/index.d.ts +8 -1
  97. package/dist/esm/utils/index.js +6 -1
  98. package/dist/esm/utils/mergeProps.d.ts +20 -0
  99. package/dist/esm/utils/mergeProps.js +31 -0
  100. package/dist/esm/utils/mergeProps.js.map +1 -0
  101. package/dist/esm/utils/mergeTwoProps.d.ts +5 -0
  102. package/dist/esm/utils/mergeTwoProps.js +42 -0
  103. package/dist/esm/utils/mergeTwoProps.js.map +1 -0
  104. package/dist/esm/utils/types/common.d.ts +43 -0
  105. package/dist/esm/utils/types/polymorphism.d.ts +13 -0
  106. package/dist/esm/zustand/createReactZustandStore.js +8 -0
  107. package/dist/esm/zustand/createReactZustandStore.js.map +1 -0
  108. package/dist/esm/zustand/createZustandContext.d.ts +13 -0
  109. package/dist/esm/zustand/createZustandContext.js +21 -0
  110. package/dist/esm/zustand/createZustandContext.js.map +1 -0
  111. package/dist/esm/zustand/createZustandStoreWithCombine.d.ts +12 -0
  112. package/dist/esm/zustand/createZustandStoreWithCombine.js +14 -0
  113. package/dist/esm/zustand/createZustandStoreWithCombine.js.map +1 -0
  114. package/dist/esm/zustand/createZustandStoreWithSubscribe.d.ts +17 -0
  115. package/dist/esm/zustand/createZustandStoreWithSubscribe.js +16 -0
  116. package/dist/esm/zustand/createZustandStoreWithSubscribe.js.map +1 -0
  117. package/dist/esm/zustand/index.d.ts +4 -38
  118. package/dist/esm/zustand/index.js +4 -42
  119. package/dist/esm/zustand/types.d.ts +20 -0
  120. package/package.json +11 -16
  121. package/dist/esm/hooks-iZivekUZ.js +0 -635
  122. package/dist/esm/hooks-iZivekUZ.js.map +0 -1
  123. package/dist/esm/index-DlScRgBk.d.ts +0 -228
  124. package/dist/esm/index-ouFKofvj.d.ts +0 -293
  125. package/dist/esm/utils-Bvs8tFDM.js +0 -279
  126. package/dist/esm/utils-Bvs8tFDM.js.map +0 -1
  127. package/dist/esm/zustand/index.js.map +0 -1
@@ -0,0 +1,86 @@
1
+ import { CallbackFn, EmptyObject, Prettify, UnionToIntersection, UnknownObject } from "@zayne-labs/toolkit-type-helpers";
2
+
3
+ //#region src/utils/getSlotMap/getSlotMap.d.ts
4
+ type GetSlotName<TSlotComponentProps extends GetSlotComponentProps> = string extends TSlotComponentProps["name"] ? never : "default" extends TSlotComponentProps["name"] ? never : TSlotComponentProps["name"];
5
+ type GetSpecificSlotsType<TSlotComponentProps extends GetSlotComponentProps> = { [TName in keyof TSlotComponentProps as GetSlotName<TSlotComponentProps>]: Extract<TSlotComponentProps["children"], React.ReactNode> };
6
+ /**
7
+ * Maps slot names to their corresponding children types
8
+ */
9
+ type GetSlotMapResult<TSlotComponentProps extends GetSlotComponentProps> = UnionToIntersection<GetSpecificSlotsType<TSlotComponentProps>> & {
10
+ default: React.ReactNode[];
11
+ };
12
+ /**
13
+ * Symbol used to identify SlotComponent instances
14
+ */
15
+ declare const slotComponentSymbol: unique symbol;
16
+ /**
17
+ * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,
18
+ * with a default slot for unmatched children.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import { type GetSlotComponentProps, SlotComponent } from "@zayne-labs/toolkit-react/utils"
23
+ *
24
+ * type SlotProps = GetSlotComponentProps<"header" | "footer">;
25
+ *
26
+ * function Parent({ children }: { children: React.ReactNode }) {
27
+ * const slots = getSlotMap<SlotProps>(children);
28
+ *
29
+ * return (
30
+ * <div>
31
+ * <header>{slots.header}</header>
32
+ * <main>{slots.default}</main>
33
+ * <footer>{slots.footer}</footer>
34
+ * </div>
35
+ * );
36
+ * }
37
+ * ```
38
+ *
39
+ * Usage:
40
+ * ```tsx
41
+ * <Parent>
42
+ * <SlotComponent name="header">Header Content</SlotComponent>
43
+ * <div>Random stuff</div>
44
+ * <SlotComponent name="footer">Footer Content</SlotComponent>
45
+ * </Parent>
46
+ * ```
47
+ */
48
+ declare const getSlotMap: <TSlotComponentProps extends GetSlotComponentProps>(children: React.ReactNode) => Prettify<GetSlotMapResult<TSlotComponentProps>>;
49
+ /**
50
+ * @description Produce props for the SlotComponent
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // Pattern One (slot or slots have same children type, which is just React.ReactNode by default)
55
+ * type SlotProps = GetSlotComponentProps<"header" | "content" | "footer">;
56
+ *
57
+ * // Pattern Two (some slots can have different children type)
58
+ * type SlotProps = GetSlotComponentProps<"header", React.ReactNode> | GetSlotComponentProps<"header", (renderProp: RenderProp) => React.ReactNode>;
59
+ * ```
60
+ */
61
+ type GetSlotComponentProps<TName extends string = string, TChildren extends CallbackFn<never, React.ReactNode> | React.ReactNode = CallbackFn<never, React.ReactNode> | React.ReactNode> = {
62
+ children: TChildren;
63
+ /**
64
+ * Name of the slot where content should be rendered
65
+ */
66
+ name: TName;
67
+ };
68
+ /**
69
+ * @description Creates a slot component
70
+ */
71
+ declare const createSlotComponent: <TSlotComponentProps extends GetSlotComponentProps>() => {
72
+ (props: TSlotComponentProps): React.ReactNode;
73
+ slotSymbol: typeof slotComponentSymbol;
74
+ };
75
+ type SlotWithNameAndSymbol<TSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps, TOtherProps extends UnknownObject = EmptyObject> = {
76
+ (props: Pick<TSlotComponentProps, "children"> & TOtherProps): React.ReactNode;
77
+ readonly slotName?: TSlotComponentProps["name"];
78
+ readonly slotSymbol?: symbol;
79
+ };
80
+ /**
81
+ * @description Adds a slot symbol and name to a slot component passed in
82
+ */
83
+ declare const withSlotNameAndSymbol: <TSlotComponentProps extends GetSlotComponentProps, TOtherProps extends UnknownObject = EmptyObject>(name: TSlotComponentProps["name"], SlotComponent?: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>) => SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>;
84
+ //#endregion
85
+ export { GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol };
86
+ //# sourceMappingURL=getSlotMap.d.ts.map
@@ -0,0 +1,87 @@
1
+ import { Fragment, isValidElement } from "react";
2
+ import { toArray } from "@zayne-labs/toolkit-core";
3
+ import { isFunction } from "@zayne-labs/toolkit-type-helpers";
4
+
5
+ //#region src/utils/getSlotMap/getSlotMap.ts
6
+ /**
7
+ * Symbol used to identify SlotComponent instances
8
+ */
9
+ const slotComponentSymbol = Symbol("slot-component");
10
+ /**
11
+ * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,
12
+ * with a default slot for unmatched children.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { type GetSlotComponentProps, SlotComponent } from "@zayne-labs/toolkit-react/utils"
17
+ *
18
+ * type SlotProps = GetSlotComponentProps<"header" | "footer">;
19
+ *
20
+ * function Parent({ children }: { children: React.ReactNode }) {
21
+ * const slots = getSlotMap<SlotProps>(children);
22
+ *
23
+ * return (
24
+ * <div>
25
+ * <header>{slots.header}</header>
26
+ * <main>{slots.default}</main>
27
+ * <footer>{slots.footer}</footer>
28
+ * </div>
29
+ * );
30
+ * }
31
+ * ```
32
+ *
33
+ * Usage:
34
+ * ```tsx
35
+ * <Parent>
36
+ * <SlotComponent name="header">Header Content</SlotComponent>
37
+ * <div>Random stuff</div>
38
+ * <SlotComponent name="footer">Footer Content</SlotComponent>
39
+ * </Parent>
40
+ * ```
41
+ */
42
+ const getSlotMap = (children) => {
43
+ const slots = { default: [] };
44
+ const actualChildren = isValidElement(children) && children.type === Fragment ? children.props.children : children;
45
+ const childrenArray = toArray(actualChildren);
46
+ for (const child of childrenArray) {
47
+ if (!isValidElement(child) || !isFunction(child.type)) {
48
+ slots.default.push(child);
49
+ continue;
50
+ }
51
+ const childType = child.type;
52
+ if (!(childType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name))) {
53
+ slots.default.push(child);
54
+ continue;
55
+ }
56
+ const slotName = childType.slotName ?? child.props.name;
57
+ if (slotName === "default") {
58
+ slots.default.push(child);
59
+ continue;
60
+ }
61
+ slots[slotName] = child;
62
+ }
63
+ return slots;
64
+ };
65
+ /**
66
+ * @description Creates a slot component
67
+ */
68
+ const createSlotComponent = () => {
69
+ const SlotComponent = (props) => props.children;
70
+ SlotComponent.slotSymbol = slotComponentSymbol;
71
+ return SlotComponent;
72
+ };
73
+ function DefaultSlotComponent(props) {
74
+ return props.children;
75
+ }
76
+ /**
77
+ * @description Adds a slot symbol and name to a slot component passed in
78
+ */
79
+ const withSlotNameAndSymbol = (name, SlotComponent = DefaultSlotComponent) => {
80
+ SlotComponent.slotSymbol = slotComponentSymbol;
81
+ SlotComponent.slotName = name;
82
+ return SlotComponent;
83
+ };
84
+
85
+ //#endregion
86
+ export { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol };
87
+ //# sourceMappingURL=getSlotMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSlotMap.js","names":["slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] }","ReactFragment"],"sources":["../../../../src/utils/getSlotMap/getSlotMap.ts"],"sourcesContent":["import { toArray } from \"@zayne-labs/toolkit-core\";\nimport {\n\ttype CallbackFn,\n\ttype EmptyObject,\n\tisFunction,\n\ttype Prettify,\n\ttype UnionToIntersection,\n\ttype UnknownObject,\n} from \"@zayne-labs/toolkit-type-helpers\";\nimport { isValidElement, Fragment as ReactFragment } from \"react\";\nimport type { InferProps } from \"../types\";\n\ntype GetSlotName<TSlotComponentProps extends GetSlotComponentProps> =\n\tstring extends TSlotComponentProps[\"name\"] ? never\n\t: \"default\" extends TSlotComponentProps[\"name\"] ? never\n\t: TSlotComponentProps[\"name\"];\n\ntype GetSpecificSlotsType<TSlotComponentProps extends GetSlotComponentProps> = {\n\t// This conditional before the remapping will prevent an Indexed Record type from showing up if the props are not passed, enhancing type safety\n\t[TName in keyof TSlotComponentProps as GetSlotName<TSlotComponentProps>]: Extract<\n\t\tTSlotComponentProps[\"children\"],\n\t\tReact.ReactNode\n\t>;\n};\n\n/**\n * Maps slot names to their corresponding children types\n */\nexport type GetSlotMapResult<TSlotComponentProps extends GetSlotComponentProps> = UnionToIntersection<\n\tGetSpecificSlotsType<TSlotComponentProps>\n> & { default: React.ReactNode[] };\n\n/**\n * Symbol used to identify SlotComponent instances\n */\nexport const slotComponentSymbol = Symbol(\"slot-component\");\n\n/**\n * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,\n * with a default slot for unmatched children.\n *\n * @example\n * ```tsx\n * import { type GetSlotComponentProps, SlotComponent } from \"@zayne-labs/toolkit-react/utils\"\n *\n * type SlotProps = GetSlotComponentProps<\"header\" | \"footer\">;\n *\n * function Parent({ children }: { children: React.ReactNode }) {\n * const slots = getSlotMap<SlotProps>(children);\n *\n * return (\n * <div>\n * <header>{slots.header}</header>\n * <main>{slots.default}</main>\n * <footer>{slots.footer}</footer>\n * </div>\n * );\n * }\n * ```\n *\n * Usage:\n * ```tsx\n * <Parent>\n * <SlotComponent name=\"header\">Header Content</SlotComponent>\n * <div>Random stuff</div>\n * <SlotComponent name=\"footer\">Footer Content</SlotComponent>\n * </Parent>\n * ```\n */\nexport const getSlotMap = <TSlotComponentProps extends GetSlotComponentProps>(\n\tchildren: React.ReactNode\n): Prettify<GetSlotMapResult<TSlotComponentProps>> => {\n\tconst slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] } = {\n\t\tdefault: [],\n\t};\n\n\tconst isFragment = isValidElement<InferProps<HTMLElement>>(children) && children.type === ReactFragment;\n\n\tconst actualChildren = isFragment ? children.props.children : children;\n\n\tconst childrenArray = toArray<React.ReactNode>(actualChildren);\n\n\tfor (const child of childrenArray) {\n\t\tif (!isValidElement<TSlotComponentProps>(child) || !isFunction(child.type)) {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst childType = child.type as SlotWithNameAndSymbol;\n\n\t\tconst isSlotElement =\n\t\t\tchildType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name);\n\n\t\tif (!isSlotElement) {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst slotName = childType.slotName ?? child.props.name;\n\n\t\tif (slotName === \"default\") {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tslots[slotName] = child;\n\t}\n\n\treturn slots as GetSlotMapResult<TSlotComponentProps>;\n};\n\n/**\n * @description Produce props for the SlotComponent\n *\n * @example\n * ```ts\n * // Pattern One (slot or slots have same children type, which is just React.ReactNode by default)\n * type SlotProps = GetSlotComponentProps<\"header\" | \"content\" | \"footer\">;\n *\n * // Pattern Two (some slots can have different children type)\n * type SlotProps = GetSlotComponentProps<\"header\", React.ReactNode> | GetSlotComponentProps<\"header\", (renderProp: RenderProp) => React.ReactNode>;\n * ```\n */\nexport type GetSlotComponentProps<\n\tTName extends string = string,\n\tTChildren extends CallbackFn<never, React.ReactNode> | React.ReactNode =\n\t\t| CallbackFn<never, React.ReactNode>\n\t\t| React.ReactNode,\n> = {\n\tchildren: TChildren;\n\t/**\n\t * Name of the slot where content should be rendered\n\t */\n\tname: TName;\n};\n\n/**\n * @description Creates a slot component\n */\nexport const createSlotComponent = <TSlotComponentProps extends GetSlotComponentProps>() => {\n\tconst SlotComponent = (props: TSlotComponentProps) => props.children as React.ReactNode;\n\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\n\treturn SlotComponent;\n};\n\ntype SlotWithNameAndSymbol<\n\tTSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps,\n\tTOtherProps extends UnknownObject = EmptyObject,\n> = {\n\t(props: Pick<TSlotComponentProps, \"children\"> & TOtherProps): React.ReactNode;\n\treadonly slotName?: TSlotComponentProps[\"name\"];\n\treadonly slotSymbol?: symbol;\n};\n\nfunction DefaultSlotComponent(props: Pick<GetSlotComponentProps, \"children\">): React.ReactNode {\n\treturn props.children as React.ReactNode;\n}\n\n/**\n * @description Adds a slot symbol and name to a slot component passed in\n */\nexport const withSlotNameAndSymbol = <\n\tTSlotComponentProps extends GetSlotComponentProps,\n\tTOtherProps extends UnknownObject = EmptyObject,\n>(\n\tname: TSlotComponentProps[\"name\"],\n\tSlotComponent: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps> = DefaultSlotComponent\n) => {\n\t/* eslint-disable no-param-reassign -- This is necessary */\n\t// @ts-expect-error -- This is necessary for the time being, to prevent type errors and accidental overrides on consumer side\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\t// @ts-expect-error -- This is necessary for the time being, to prevent type errors and accidental overrides on consumer side\n\tSlotComponent.slotName = name;\n\n\t/* eslint-enable no-param-reassign -- This is necessary */\n\n\treturn SlotComponent;\n};\n"],"mappings":";;;;;;;;AAmCA,MAAa,sBAAsB,OAAO,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkC3D,MAAa,cACZ,aACqD;CACrD,MAAMA,QAA0F,EAC/F,SAAS,EAAE,EACX;CAID,MAAM,iBAFa,eAAwC,SAAS,IAAI,SAAS,SAASC,WAEtD,SAAS,MAAM,WAAW;CAE9D,MAAM,gBAAgB,QAAyB,eAAe;AAE9D,MAAK,MAAM,SAAS,eAAe;AAClC,MAAI,CAAC,eAAoC,MAAM,IAAI,CAAC,WAAW,MAAM,KAAK,EAAE;AAC3E,SAAM,QAAQ,KAAK,MAAM;AACzB;;EAGD,MAAM,YAAY,MAAM;AAKxB,MAAI,EAFH,UAAU,eAAe,uBAAuB,QAAQ,UAAU,YAAY,MAAM,MAAM,KAAK,GAE5E;AACnB,SAAM,QAAQ,KAAK,MAAM;AACzB;;EAGD,MAAM,WAAW,UAAU,YAAY,MAAM,MAAM;AAEnD,MAAI,aAAa,WAAW;AAC3B,SAAM,QAAQ,KAAK,MAAM;AACzB;;AAGD,QAAM,YAAY;;AAGnB,QAAO;;;;;AA+BR,MAAa,4BAA+E;CAC3F,MAAM,iBAAiB,UAA+B,MAAM;AAE5D,eAAc,aAAa;AAE3B,QAAO;;AAYR,SAAS,qBAAqB,OAAiE;AAC9F,QAAO,MAAM;;;;;AAMd,MAAa,yBAIZ,MACA,gBAAyE,yBACrE;AAGJ,eAAc,aAAa;AAE3B,eAAc,WAAW;AAIzB,QAAO"}
@@ -1,2 +1,9 @@
1
- import { AsProp, CssWithCustomProperties, DefaultRenderErrorMessages, DefaultRenderItemErrorMessages, DiscriminatedRenderItemProps, DiscriminatedRenderProps, ForwardedRefType, FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, InferProps, InferPropsStrict, PolymorphicProps, PolymorphicPropsStrict, PossibleRef, StateSetter, composeEventHandlers, composeRefs, composeTwoEventHandlers, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, mergeProps, mergeTwoProps, setRef, slotComponentSymbol, withSlotNameAndSymbol } from "../index-DlScRgBk.js";
1
+ import { composeEventHandlers, composeTwoEventHandlers } from "./composeEventHandlers.js";
2
+ import { PossibleRef, composeRefs, setRef } from "./composeRefs.js";
3
+ import { FunctionalComponent, getMultipleSlots, getRegularChildren, getSingleSlot, matchesAnySlotComponent, matchesSlotComponent } from "./getSlot/getSlot.js";
4
+ import { GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol } from "./getSlotMap/getSlotMap.js";
5
+ import { mergeProps } from "./mergeProps.js";
6
+ import { mergeTwoProps } from "./mergeTwoProps.js";
7
+ import { CssWithCustomProperties, DefaultRenderErrorMessages, DefaultRenderItemErrorMessages, DiscriminatedRenderItemProps, DiscriminatedRenderProps, ForwardedRefType, InferProps, InferPropsStrict, StateSetter } from "./types/common.js";
8
+ import { AsProp, PolymorphicProps, PolymorphicPropsStrict } from "./types/polymorphism.js";
2
9
  export { AsProp, CssWithCustomProperties, DefaultRenderErrorMessages, DefaultRenderItemErrorMessages, DiscriminatedRenderItemProps, DiscriminatedRenderProps, ForwardedRefType, FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, InferProps, InferPropsStrict, PolymorphicProps, PolymorphicPropsStrict, PossibleRef, StateSetter, composeEventHandlers, composeRefs, composeTwoEventHandlers, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, mergeProps, mergeTwoProps, setRef, slotComponentSymbol, withSlotNameAndSymbol };
@@ -1,3 +1,8 @@
1
- import { composeEventHandlers, composeRefs, composeTwoEventHandlers, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, mergeProps, mergeTwoProps, setRef, slotComponentSymbol, withSlotNameAndSymbol } from "../utils-Bvs8tFDM.js";
1
+ import { composeEventHandlers, composeTwoEventHandlers } from "./composeEventHandlers.js";
2
+ import { composeRefs, setRef } from "./composeRefs.js";
3
+ import { getMultipleSlots, getRegularChildren, getSingleSlot, matchesAnySlotComponent, matchesSlotComponent } from "./getSlot/getSlot.js";
4
+ import { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol } from "./getSlotMap/getSlotMap.js";
5
+ import { mergeTwoProps } from "./mergeTwoProps.js";
6
+ import { mergeProps } from "./mergeProps.js";
2
7
 
3
8
  export { composeEventHandlers, composeRefs, composeTwoEventHandlers, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, mergeProps, mergeTwoProps, setRef, slotComponentSymbol, withSlotNameAndSymbol };
@@ -0,0 +1,20 @@
1
+ //#region src/utils/mergeProps.d.ts
2
+ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : "") extends ((param: infer TParam) => void) ? TParam : "";
3
+ /**
4
+ * Merges multiple sets of React props.
5
+ *
6
+ * - It follows the Object.assign pattern where the rightmost object's fields overwrite
7
+ * the conflicting ones from others. This doesn't apply to event handlers, `className` and `style` props.
8
+ * - Event handlers are merged such that they are called in sequence (the rightmost one being called first),
9
+ * and allows the user to prevent the previous event handlers from being executed by calling the `preventDefault` method.
10
+ * - It also merges the `className` and `style` props, whereby the classes are concatenated
11
+ * and the rightmost styles overwrite the previous ones.
12
+ *
13
+ * @important **`ref` is not merged.**
14
+ * @param props props to merge.
15
+ * @returns the merged props.
16
+ */
17
+ declare const mergeProps: <TProps extends Record<never, never>>(...propsObjectArray: Array<TProps | undefined>) => UnionToIntersection<TProps>;
18
+ //#endregion
19
+ export { mergeProps };
20
+ //# sourceMappingURL=mergeProps.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { mergeTwoProps } from "./mergeTwoProps.js";
2
+
3
+ //#region src/utils/mergeProps.ts
4
+ /**
5
+ * Merges multiple sets of React props.
6
+ *
7
+ * - It follows the Object.assign pattern where the rightmost object's fields overwrite
8
+ * the conflicting ones from others. This doesn't apply to event handlers, `className` and `style` props.
9
+ * - Event handlers are merged such that they are called in sequence (the rightmost one being called first),
10
+ * and allows the user to prevent the previous event handlers from being executed by calling the `preventDefault` method.
11
+ * - It also merges the `className` and `style` props, whereby the classes are concatenated
12
+ * and the rightmost styles overwrite the previous ones.
13
+ *
14
+ * @important **`ref` is not merged.**
15
+ * @param props props to merge.
16
+ * @returns the merged props.
17
+ */
18
+ const mergeProps = (...propsObjectArray) => {
19
+ if (propsObjectArray.length === 0) return {};
20
+ if (propsObjectArray.length === 1) return propsObjectArray[0];
21
+ let accumulatedProps = {};
22
+ for (const propsObject of propsObjectArray) {
23
+ if (!propsObject) continue;
24
+ accumulatedProps = mergeTwoProps(accumulatedProps, propsObject);
25
+ }
26
+ return accumulatedProps;
27
+ };
28
+
29
+ //#endregion
30
+ export { mergeProps };
31
+ //# sourceMappingURL=mergeProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeProps.js","names":["accumulatedProps: Record<string, unknown>"],"sources":["../../../src/utils/mergeProps.ts"],"sourcesContent":["import { mergeTwoProps } from \"./mergeTwoProps\";\n\ntype UnionToIntersection<TUnion> =\n\t(TUnion extends unknown ? (param: TUnion) => void : \"\") extends (param: infer TParam) => void ? TParam\n\t:\t\"\";\n\n/**\n * Merges multiple sets of React props.\n *\n * - It follows the Object.assign pattern where the rightmost object's fields overwrite\n * the conflicting ones from others. This doesn't apply to event handlers, `className` and `style` props.\n * - Event handlers are merged such that they are called in sequence (the rightmost one being called first),\n * and allows the user to prevent the previous event handlers from being executed by calling the `preventDefault` method.\n * - It also merges the `className` and `style` props, whereby the classes are concatenated\n * and the rightmost styles overwrite the previous ones.\n *\n * @important **`ref` is not merged.**\n * @param props props to merge.\n * @returns the merged props.\n */\n\nconst mergeProps = <TProps extends Record<never, never>>(\n\t...propsObjectArray: Array<TProps | undefined>\n): UnionToIntersection<TProps> => {\n\tif (propsObjectArray.length === 0) {\n\t\treturn {} as never;\n\t}\n\n\tif (propsObjectArray.length === 1) {\n\t\treturn propsObjectArray[0] as never;\n\t}\n\n\tlet accumulatedProps: Record<string, unknown> = {};\n\n\tfor (const propsObject of propsObjectArray) {\n\t\tif (!propsObject) continue;\n\n\t\taccumulatedProps = mergeTwoProps(accumulatedProps, propsObject);\n\t}\n\n\treturn accumulatedProps as never;\n};\n\nexport { mergeProps };\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,MAAM,cACL,GAAG,qBAC8B;AACjC,KAAI,iBAAiB,WAAW,EAC/B,QAAO,EAAE;AAGV,KAAI,iBAAiB,WAAW,EAC/B,QAAO,iBAAiB;CAGzB,IAAIA,mBAA4C,EAAE;AAElD,MAAK,MAAM,eAAe,kBAAkB;AAC3C,MAAI,CAAC,YAAa;AAElB,qBAAmB,cAAc,kBAAkB,YAAY;;AAGhE,QAAO"}
@@ -0,0 +1,5 @@
1
+ //#region src/utils/mergeTwoProps.d.ts
2
+ declare const mergeTwoProps: <TProps extends Record<never, never>>(formerProps: TProps | undefined, latterProps: TProps | undefined) => TProps;
3
+ //#endregion
4
+ export { mergeTwoProps };
5
+ //# sourceMappingURL=mergeTwoProps.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { composeTwoEventHandlers } from "./composeEventHandlers.js";
2
+ import { isFunction } from "@zayne-labs/toolkit-type-helpers";
3
+
4
+ //#region src/utils/mergeTwoProps.ts
5
+ const isEventHandler = (key, value) => {
6
+ const thirdCharCode = key.codePointAt(2);
7
+ if (!isFunction(value) || thirdCharCode === void 0) return false;
8
+ return key.startsWith("on") && thirdCharCode >= 65 && thirdCharCode <= 90;
9
+ };
10
+ const mergeTwoClassNames = (formerClassName, latterClassName) => {
11
+ if (!latterClassName || !formerClassName) return latterClassName || formerClassName;
12
+ return formerClassName + " " + latterClassName;
13
+ };
14
+ const mergeTwoProps = (formerProps, latterProps) => {
15
+ if (!latterProps || !formerProps) return latterProps ?? formerProps ?? {};
16
+ const propsAccumulator = { ...formerProps };
17
+ for (const latterPropName of Object.keys(latterProps)) {
18
+ const formerPropValue = formerProps[latterPropName];
19
+ const latterPropValue = latterProps[latterPropName];
20
+ if (latterPropName === "className" || latterPropName === "class") {
21
+ propsAccumulator[latterPropName] = mergeTwoClassNames(formerPropValue, latterPropValue);
22
+ continue;
23
+ }
24
+ if (latterPropName === "style") {
25
+ propsAccumulator[latterPropName] = {
26
+ ...formerPropValue,
27
+ ...latterPropValue
28
+ };
29
+ continue;
30
+ }
31
+ if (isEventHandler(latterPropName, latterPropValue)) {
32
+ propsAccumulator[latterPropName] = composeTwoEventHandlers(formerPropValue, latterPropValue);
33
+ continue;
34
+ }
35
+ propsAccumulator[latterPropName] = latterPropValue;
36
+ }
37
+ return propsAccumulator;
38
+ };
39
+
40
+ //#endregion
41
+ export { mergeTwoProps };
42
+ //# sourceMappingURL=mergeTwoProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeTwoProps.js","names":[],"sources":["../../../src/utils/mergeTwoProps.ts"],"sourcesContent":["import { type AnyFunction, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { composeTwoEventHandlers } from \"./composeEventHandlers\";\n\n// == This approach is more efficient than using a regex.\nconst isEventHandler = (key: string, value: unknown): value is AnyFunction => {\n\tconst thirdCharCode = key.codePointAt(2);\n\n\tif (!isFunction(value) || thirdCharCode === undefined) {\n\t\treturn false;\n\t}\n\n\tconst isHandler = key.startsWith(\"on\") && thirdCharCode >= 65 /* A */ && thirdCharCode <= 90; /* Z */\n\n\treturn isHandler;\n};\n\nconst mergeTwoClassNames = (formerClassName: string | undefined, latterClassName: string | undefined) => {\n\tif (!latterClassName || !formerClassName) {\n\t\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- Logical OR is fit for this case\n\t\treturn latterClassName || formerClassName;\n\t}\n\n\t// eslint-disable-next-line prefer-template -- String concatenation is more performant than template literals in this case\n\treturn formerClassName + \" \" + latterClassName;\n};\n\nexport const mergeTwoProps = <TProps extends Record<never, never>>(\n\tformerProps: TProps | undefined,\n\tlatterProps: TProps | undefined\n): TProps => {\n\t// == If no props are provided, return an empty object\n\tif (!latterProps || !formerProps) {\n\t\treturn latterProps ?? formerProps ?? ({} as TProps);\n\t}\n\n\tconst propsAccumulator = { ...formerProps } as Record<string, unknown>;\n\n\tfor (const latterPropName of Object.keys(latterProps)) {\n\t\tconst formerPropValue = (formerProps as Record<string, unknown>)[latterPropName];\n\t\tconst latterPropValue = (latterProps as Record<string, unknown>)[latterPropName];\n\n\t\t// == If the prop is `className` or `class`, we merge them\n\t\tif (latterPropName === \"className\" || latterPropName === \"class\") {\n\t\t\tpropsAccumulator[latterPropName] = mergeTwoClassNames(\n\t\t\t\tformerPropValue as string,\n\t\t\t\tlatterPropValue as string\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == If the prop is `style`, we merge them\n\t\tif (latterPropName === \"style\") {\n\t\t\tpropsAccumulator[latterPropName] = {\n\t\t\t\t...(formerPropValue as object),\n\t\t\t\t...(latterPropValue as object),\n\t\t\t};\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == If the handler exists on both, we compose them\n\t\tif (isEventHandler(latterPropName, latterPropValue)) {\n\t\t\tpropsAccumulator[latterPropName] = composeTwoEventHandlers(\n\t\t\t\tformerPropValue as AnyFunction | undefined,\n\t\t\t\tlatterPropValue\n\t\t\t);\n\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == latterProps override by default\n\t\tpropsAccumulator[latterPropName] = latterPropValue;\n\t}\n\n\treturn propsAccumulator as TProps;\n};\n"],"mappings":";;;;AAIA,MAAM,kBAAkB,KAAa,UAAyC;CAC7E,MAAM,gBAAgB,IAAI,YAAY,EAAE;AAExC,KAAI,CAAC,WAAW,MAAM,IAAI,kBAAkB,OAC3C,QAAO;AAKR,QAFkB,IAAI,WAAW,KAAK,IAAI,iBAAiB,MAAc,iBAAiB;;AAK3F,MAAM,sBAAsB,iBAAqC,oBAAwC;AACxG,KAAI,CAAC,mBAAmB,CAAC,gBAExB,QAAO,mBAAmB;AAI3B,QAAO,kBAAkB,MAAM;;AAGhC,MAAa,iBACZ,aACA,gBACY;AAEZ,KAAI,CAAC,eAAe,CAAC,YACpB,QAAO,eAAe,eAAgB,EAAE;CAGzC,MAAM,mBAAmB,EAAE,GAAG,aAAa;AAE3C,MAAK,MAAM,kBAAkB,OAAO,KAAK,YAAY,EAAE;EACtD,MAAM,kBAAmB,YAAwC;EACjE,MAAM,kBAAmB,YAAwC;AAGjE,MAAI,mBAAmB,eAAe,mBAAmB,SAAS;AACjE,oBAAiB,kBAAkB,mBAClC,iBACA,gBACA;AACD;;AAID,MAAI,mBAAmB,SAAS;AAC/B,oBAAiB,kBAAkB;IAClC,GAAI;IACJ,GAAI;IACJ;AACD;;AAID,MAAI,eAAe,gBAAgB,gBAAgB,EAAE;AACpD,oBAAiB,kBAAkB,wBAClC,iBACA,gBACA;AAED;;AAID,mBAAiB,kBAAkB;;AAGpC,QAAO"}
@@ -0,0 +1,43 @@
1
+ import { UnionDiscriminator } from "@zayne-labs/toolkit-type-helpers";
2
+
3
+ //#region src/utils/types/common.d.ts
4
+ type ValidElementType = HTMLElement | React.ElementType;
5
+ type ForwardedRefType<TElement extends ValidElementType> = TElement extends React.ElementType ? React.ForwardedRef<React.Ref<TElement>> : React.ForwardedRef<TElement>;
6
+ type InferProps<TElement extends ValidElementType> = TElement extends React.ElementType ? React.ComponentProps<TElement> : React.HTMLAttributes<TElement>;
7
+ type RemoveStringSignature<TObject extends object> = { [Key in keyof TObject as string extends Key ? never : Key]: TObject[Key] };
8
+ type InferPropsStrict<TElement extends ValidElementType> = RemoveStringSignature<InferProps<TElement>>;
9
+ type StateSetter<TSetter = unknown> = React.Dispatch<React.SetStateAction<TSetter>>;
10
+ type CssWithCustomProperties<TExtra extends Record<string, string> = NonNullable<unknown>> = React.CSSProperties & Record<`--${string}`, string> & TExtra;
11
+ type DefaultRenderItemErrorMessages = {
12
+ children: "Hey, Sorry but the children prop is redundant since you're currently using the render prop to do the same thing";
13
+ renderItem: "Hey, Sorry but the renderItem prop is redundant since you're currently using the children prop to do the same thing";
14
+ };
15
+ /**
16
+ * @description Represents a set of props that can be used to render a component conditionally based on a discriminated union type.
17
+ * This type allows for the use of either a render prop or children prop, but not both at the same time.
18
+ * If both are provided, a TypeScript error will be thrown.
19
+ * @template TErrorMessages An object of custom messages to display on the disallowed property.
20
+ */
21
+ type DiscriminatedRenderItemProps<TRenderItemPropType, TErrorMessages extends Record<keyof DefaultRenderItemErrorMessages, string> = DefaultRenderItemErrorMessages> = UnionDiscriminator<[{
22
+ children: TRenderItemPropType;
23
+ }, {
24
+ renderItem: TRenderItemPropType;
25
+ }], TErrorMessages>;
26
+ type DefaultRenderErrorMessages = {
27
+ children: "Hey, Sorry but the children prop is redundant since you're currently using the render prop to do the same thing";
28
+ render: "Hey, Sorry but the render prop is redundant since you're currently using the children prop to do the same thing";
29
+ };
30
+ /**
31
+ * @description Represents a set of props that can be used to render a component conditionally based on a discriminated union type.
32
+ * This type allows for the use of either a render prop or children prop, but not both at the same time.
33
+ * If both are provided, a TypeScript error will be thrown.
34
+ * @template TErrorMessages An object of custom messages to display on the disallowed property.
35
+ */
36
+ type DiscriminatedRenderProps<TRenderPropType, TErrorMessages extends Record<keyof DefaultRenderErrorMessages, string> = DefaultRenderErrorMessages> = UnionDiscriminator<[{
37
+ children: TRenderPropType;
38
+ }, {
39
+ render: TRenderPropType;
40
+ }], TErrorMessages>;
41
+ //#endregion
42
+ export { CssWithCustomProperties, DefaultRenderErrorMessages, DefaultRenderItemErrorMessages, DiscriminatedRenderItemProps, DiscriminatedRenderProps, ForwardedRefType, InferProps, InferPropsStrict, StateSetter };
43
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { InferProps, InferPropsStrict } from "./common.js";
2
+ import { AnyObject } from "@zayne-labs/toolkit-type-helpers";
3
+
4
+ //#region src/utils/types/polymorphism.d.ts
5
+ type AsProp<TElement extends React.ElementType> = {
6
+ as?: TElement;
7
+ };
8
+ type MergedGivenPropsWithAs<TElement extends React.ElementType, TProps> = Omit<AsProp<TElement>, keyof TProps> & TProps;
9
+ type PolymorphicProps<TElement extends React.ElementType, TProps extends AnyObject = NonNullable<unknown>> = MergedGivenPropsWithAs<TElement, TProps> & Omit<InferProps<TElement>, keyof TProps>;
10
+ type PolymorphicPropsStrict<TElement extends React.ElementType, TProps extends AnyObject = NonNullable<unknown>> = MergedGivenPropsWithAs<TElement, TProps> & Omit<InferPropsStrict<TElement>, keyof TProps>;
11
+ //#endregion
12
+ export { AsProp, PolymorphicProps, PolymorphicPropsStrict };
13
+ //# sourceMappingURL=polymorphism.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { createStore } from "@zayne-labs/toolkit-core";
2
+
3
+ //#region src/zustand/createReactZustandStore.ts
4
+ const createReactZustandStore = ((stateInitializer) => stateInitializer ? createStore(stateInitializer) : createStore);
5
+
6
+ //#endregion
7
+ export { createReactZustandStore };
8
+ //# sourceMappingURL=createReactZustandStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createReactZustandStore.js","names":[],"sources":["../../../src/zustand/createReactZustandStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore } from \"./types\";\n\ntype Create = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n};\n\nexport const createReactZustandStore = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createStore(stateInitializer) : createStore) as Create;\n"],"mappings":";;;AAYA,MAAa,4BAAoC,qBAChD,mBAAmB,YAAY,iBAAiB,GAAG"}
@@ -0,0 +1,13 @@
1
+ import { CustomContextOptions } from "../hooks/createCustomContext.js";
2
+ import * as react11 from "react";
3
+ import { StoreApi } from "@zayne-labs/toolkit-core";
4
+ import { SelectorFn } from "@zayne-labs/toolkit-type-helpers";
5
+
6
+ //#region src/zustand/createZustandContext.d.ts
7
+ declare const createZustandContext: <TState extends Record<string, unknown>, TStore extends StoreApi<TState> = StoreApi<TState>>(options?: CustomContextOptions<TStore, true>) => [ZustandStoreContextProvider: (props: {
8
+ children: React.ReactNode;
9
+ store: TStore;
10
+ }) => react11.FunctionComponentElement<react11.ProviderProps<TStore>>, useZustandStoreContext: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
11
+ //#endregion
12
+ export { createZustandContext };
13
+ //# sourceMappingURL=createZustandContext.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { createCustomContext } from "../hooks/createCustomContext.js";
2
+ import { useStore } from "../hooks/useStore.js";
3
+ import { createElement } from "react";
4
+
5
+ //#region src/zustand/createZustandContext.ts
6
+ const createZustandContext = (options) => {
7
+ const [Provider, useCustomContext] = createCustomContext(options);
8
+ function ZustandStoreContextProvider(props) {
9
+ const { children, store } = props;
10
+ return createElement(Provider, { value: store }, children);
11
+ }
12
+ const useZustandStoreContext = (selector) => {
13
+ const zustandStore = useCustomContext();
14
+ return useStore(zustandStore, selector);
15
+ };
16
+ return [ZustandStoreContextProvider, useZustandStoreContext];
17
+ };
18
+
19
+ //#endregion
20
+ export { createZustandContext };
21
+ //# sourceMappingURL=createZustandContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createZustandContext.js","names":[],"sources":["../../../src/zustand/createZustandContext.ts"],"sourcesContent":["import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type CustomContextOptions, createCustomContext, useStore } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandStoreContextProviderProps = {\n\t\tchildren: React.ReactNode;\n\t\tstore: TStore;\n\t};\n\n\tfunction ZustandStoreContextProvider(props: ZustandStoreContextProviderProps) {\n\t\tconst { children, store } = props;\n\n\t\treturn createElement(Provider, { value: store }, children);\n\t}\n\n\tconst useZustandStoreContext = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst zustandStore = useCustomContext();\n\n\t\treturn useStore(zustandStore, selector);\n\t};\n\n\treturn [ZustandStoreContextProvider, useZustandStoreContext] as [\n\t\tZustandStoreContextProvider: typeof ZustandStoreContextProvider,\n\t\tuseZustandStoreContext: typeof useZustandStoreContext,\n\t];\n};\n\nexport { createZustandContext };\n"],"mappings":";;;;;AAKA,MAAM,wBAIL,YACI;CACJ,MAAM,CAAC,UAAU,oBAAoB,oBAAoB,QAAQ;CAOjE,SAAS,4BAA4B,OAAyC;EAC7E,MAAM,EAAE,UAAU,UAAU;AAE5B,SAAO,cAAc,UAAU,EAAE,OAAO,OAAO,EAAE,SAAS;;CAG3D,MAAM,0BAA4C,aAAoD;EACrG,MAAM,eAAe,kBAAkB;AAEvC,SAAO,SAAS,cAAc,SAAS;;AAGxC,QAAO,CAAC,6BAA6B,uBAAuB"}
@@ -0,0 +1,12 @@
1
+ import { StateCreator, StoreMutatorIdentifier, UseBoundStore } from "./types.js";
2
+ import * as _zayne_labs_toolkit_core7 from "@zayne-labs/toolkit-core";
3
+ import { AnyObject, Prettify } from "@zayne-labs/toolkit-type-helpers";
4
+
5
+ //#region src/zustand/createZustandStoreWithCombine.d.ts
6
+ type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
7
+ declare const combine: <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>) => StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs>;
8
+ declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => _zayne_labs_toolkit_core7.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>;
9
+ declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => UseBoundStore<_zayne_labs_toolkit_core7.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>>;
10
+ //#endregion
11
+ export { combine, createStoreWithCombine, createWithCombine };
12
+ //# sourceMappingURL=createZustandStoreWithCombine.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { createReactZustandStore } from "./createReactZustandStore.js";
2
+ import { createStore } from "@zayne-labs/toolkit-core";
3
+
4
+ //#region src/zustand/createZustandStoreWithCombine.ts
5
+ const combine = (initialState, storeCreator) => (...params) => ({
6
+ ...initialState,
7
+ ...storeCreator(...params)
8
+ });
9
+ const createStoreWithCombine = (...params) => createStore(combine(...params));
10
+ const createWithCombine = (...params) => createReactZustandStore(combine(...params));
11
+
12
+ //#endregion
13
+ export { combine, createStoreWithCombine, createWithCombine };
14
+ //# sourceMappingURL=createZustandStoreWithCombine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createZustandStoreWithCombine.js","names":[],"sources":["../../../src/zustand/createZustandStoreWithCombine.ts"],"sourcesContent":["import { createStore } from \"@zayne-labs/toolkit-core\";\nimport type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createReactZustandStore } from \"./createReactZustandStore\";\nimport type { StateCreator, StoreMutatorIdentifier } from \"./types\";\n\ntype Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;\n\nexport const combine =\n\t<\n\t\tTInitialState extends AnyObject,\n\t\tTExtraState extends AnyObject,\n\t\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t>(\n\t\tinitialState: TInitialState,\n\t\tstoreCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n\t): StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs> =>\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) => createReactZustandStore(combine(...params));\n"],"mappings":";;;;AAOA,MAAa,WAOX,cACA,kBAGA,GAAG,YAAY;CACf,GAAG;CACH,GAAI,aAA6B,GAAG,OAAO;CAC3C;AAEF,MAAa,0BACZ,GAAG,WACC,YAAY,QAAQ,GAAG,OAAO,CAAC;AAEpC,MAAa,qBACZ,GAAG,WACC,wBAAwB,QAAQ,GAAG,OAAO,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore } from "./types.js";
2
+ import { StoreApi } from "@zayne-labs/toolkit-core";
3
+
4
+ //#region src/zustand/createZustandStoreWithSubscribe.d.ts
5
+ type CreateStoreWithSubscribe = {
6
+ <T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
7
+ <T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
8
+ };
9
+ declare const createStoreWithSubscribe: CreateStoreWithSubscribe;
10
+ type CreateWithSubscribe = {
11
+ <T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
12
+ <T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
13
+ };
14
+ declare const createWithSubscribe: CreateWithSubscribe;
15
+ //#endregion
16
+ export { createStoreWithSubscribe, createWithSubscribe };
17
+ //# sourceMappingURL=createZustandStoreWithSubscribe.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { useStore } from "../hooks/useStore.js";
2
+ import { createStore } from "@zayne-labs/toolkit-core";
3
+
4
+ //#region src/zustand/createZustandStoreWithSubscribe.ts
5
+ const createStoreWithSubscribe = ((stateInitializer) => stateInitializer ? createStore(stateInitializer) : createStore);
6
+ const createWithSubscribeImpl = (createState) => {
7
+ const store = createStore(createState);
8
+ const useBoundStore = (selector) => useStore(store, selector);
9
+ Object.assign(useBoundStore, store);
10
+ return useBoundStore;
11
+ };
12
+ const createWithSubscribe = ((stateInitializer) => stateInitializer ? createWithSubscribeImpl(stateInitializer) : createWithSubscribeImpl);
13
+
14
+ //#endregion
15
+ export { createStoreWithSubscribe, createWithSubscribe };
16
+ //# sourceMappingURL=createZustandStoreWithSubscribe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createZustandStoreWithSubscribe.js","names":[],"sources":["../../../src/zustand/createZustandStoreWithSubscribe.ts"],"sourcesContent":["import { createStore, type StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useStore } from \"../hooks\";\nimport type { Mutate, StateCreator, StoreMutatorIdentifier, UseBoundStore } from \"./types\";\n\ntype CreateStoreWithSubscribe = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): Mutate<StoreApi<T>, Mos>;\n\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => Mutate<StoreApi<T>, Mos>;\n};\n\nexport const createStoreWithSubscribe = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createStore(stateInitializer) : createStore) as CreateStoreWithSubscribe;\n\ntype CreateWithSubscribe = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n};\n\nconst createWithSubscribeImpl = <TState>(createState: StateCreator<TState>) => {\n\tconst store = createStore(createState);\n\n\tconst useBoundStore = (selector?: SelectorFn<TState, unknown>) => useStore(store, selector);\n\n\tObject.assign(useBoundStore, store);\n\n\treturn useBoundStore;\n};\n\nexport const createWithSubscribe = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ?\n\t\tcreateWithSubscribeImpl(stateInitializer)\n\t:\tcreateWithSubscribeImpl) as CreateWithSubscribe;\n"],"mappings":";;;;AAeA,MAAa,6BAAqC,qBACjD,mBAAmB,YAAY,iBAAiB,GAAG;AAWpD,MAAM,2BAAmC,gBAAsC;CAC9E,MAAM,QAAQ,YAAY,YAAY;CAEtC,MAAM,iBAAiB,aAA2C,SAAS,OAAO,SAAS;AAE3F,QAAO,OAAO,eAAe,MAAM;AAEnC,QAAO;;AAGR,MAAa,wBAAgC,qBAC5C,mBACC,wBAAwB,iBAAiB,GACxC"}
@@ -1,38 +1,4 @@
1
- import { CustomContextOptions } from "../index-ouFKofvj.js";
2
- import "../index-DlScRgBk.js";
3
- import * as react0 from "react";
4
- import { StoreApi } from "@zayne-labs/toolkit-core";
5
- import { AnyObject, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
6
- import * as zustand0 from "zustand";
7
- import { Mutate, StateCreator as StateCreator$1, StoreMutatorIdentifier, UseBoundStore } from "zustand";
8
-
9
- //#region src/zustand/createZustandContext.d.ts
10
- declare const createZustandContext: <TState extends Record<string, unknown>, TStore extends StoreApi<TState> = StoreApi<TState>>(options?: CustomContextOptions<TStore, true>) => [ZustandStoreContextProvider: (props: {
11
- children: React.ReactNode;
12
- store: TStore;
13
- }) => react0.FunctionComponentElement<react0.ProviderProps<TStore>>, useZustandStoreContext: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
14
- //#endregion
15
- //#region src/zustand/createZustandStoreWithCombine.d.ts
16
- type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
17
- declare const combine: <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, storeCreator: StateCreator$1<TInitialState, Mps, Mcs, TExtraState>) => StateCreator$1<Write<TInitialState, TExtraState>, Mps, Mcs>;
18
- declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand0.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>;
19
- declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand0.UseBoundStore<zustand0.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: T[Key] } : never>>;
20
- //#endregion
21
- //#region src/zustand/createZustandStoreWithSubscribe.d.ts
22
- type Get<T, K, F> = K extends keyof T ? T[K] : F;
23
- type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
24
- $$storeMutators?: Mos;
25
- } & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
26
- type CreateStoreWithSubscribe = {
27
- <T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
28
- <T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
29
- };
30
- declare const createStoreWithSubscribe: CreateStoreWithSubscribe;
31
- type CreateWithSubscribe = {
32
- <T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
33
- <T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
34
- };
35
- declare const createWithSubscribe: CreateWithSubscribe;
36
- //#endregion
37
- export { StateCreator, combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
38
- //# sourceMappingURL=index.d.ts.map
1
+ import { createZustandContext } from "./createZustandContext.js";
2
+ import { combine, createStoreWithCombine, createWithCombine } from "./createZustandStoreWithCombine.js";
3
+ import { createStoreWithSubscribe, createWithSubscribe } from "./createZustandStoreWithSubscribe.js";
4
+ export { combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };