@algorithm-shift/design-system 1.2.43 → 1.2.45

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/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -28,8 +29,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
30
 
30
31
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
32
+ var src_exports = {};
33
+ __export(src_exports, {
33
34
  BarChart: () => BarChart_default,
34
35
  Breadcrumb: () => Breadcrumb_default,
35
36
  Button: () => Button_default,
@@ -43,8 +44,6 @@ __export(index_exports, {
43
44
  EmailComposer: () => EmailComposer,
44
45
  FileInput: () => FileInput_default,
45
46
  FlexLayout: () => Flex_default,
46
- Form: () => Form_default,
47
- FormWrapper: () => Wrapper_default,
48
47
  GridLayout: () => Grid_default,
49
48
  Image: () => Image_default,
50
49
  Modal: () => Modal_default,
@@ -61,7 +60,6 @@ __export(index_exports, {
61
60
  Shape: () => Shape_default,
62
61
  Spacer: () => Spacer_default,
63
62
  Stages: () => Stages_default,
64
- StateProvider: () => StateProvider,
65
63
  SwitchToggle: () => SwitchToggle_default,
66
64
  Table: () => Table_default,
67
65
  Tabs: () => Tabs_default,
@@ -72,11 +70,9 @@ __export(index_exports, {
72
70
  URL: () => UrlInput_default,
73
71
  cn: () => cn,
74
72
  getInitials: () => getInitials,
75
- showSonnerToast: () => showSonnerToast,
76
- stateReducer: () => stateReducer,
77
- useAppState: () => useAppState
73
+ showSonnerToast: () => showSonnerToast
78
74
  });
79
- module.exports = __toCommonJS(index_exports);
75
+ module.exports = __toCommonJS(src_exports);
80
76
 
81
77
  // src/components/Layout/Modal.tsx
82
78
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -2844,293 +2840,6 @@ function showSonnerToast({
2844
2840
  (0, import_sonner.toast)(title, options);
2845
2841
  }
2846
2842
  }
2847
-
2848
- // src/components/StateManagment/StateContext.tsx
2849
- var import_react8 = require("react");
2850
-
2851
- // src/components/StateManagment/stateReducer.ts
2852
- function stateReducer(state, action) {
2853
- switch (action.type) {
2854
- case "SET_STATE":
2855
- return { ...state, [action.key]: action.value };
2856
- default:
2857
- return state;
2858
- }
2859
- }
2860
-
2861
- // src/components/StateManagment/StateContext.tsx
2862
- var import_jsx_runtime56 = require("react/jsx-runtime");
2863
- var StateContext = (0, import_react8.createContext)(null);
2864
- function StateProvider({ children }) {
2865
- const [state, dispatch] = (0, import_react8.useReducer)(stateReducer, {});
2866
- return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(StateContext.Provider, { value: { state, dispatch }, children });
2867
- }
2868
- function useAppState() {
2869
- return (0, import_react8.useContext)(StateContext);
2870
- }
2871
-
2872
- // src/components/Form/Form.tsx
2873
- var import_react9 = __toESM(require("react"));
2874
- var import_zod = require("@hookform/resolvers/zod");
2875
- var import_react_hook_form = require("react-hook-form");
2876
- var import_zod2 = require("zod");
2877
- var import_jsx_runtime57 = require("react/jsx-runtime");
2878
- function generateZodSchema(data) {
2879
- const fields = data.reduce((acc, f) => {
2880
- const name = f.name || "unnamed";
2881
- const message = f.message || `${name} is invalid`;
2882
- const passwordLen = f.passwordLength;
2883
- let fieldSchema = import_zod2.z.string({ message });
2884
- switch (f.type) {
2885
- case "Text":
2886
- case "Search":
2887
- fieldSchema = import_zod2.z.string({ message });
2888
- if (f?.min && f?.min !== "") fieldSchema = fieldSchema.min(f.min);
2889
- else if (f.isRequired) fieldSchema = fieldSchema.min(1, { message: `${message}. Cannot be empty` });
2890
- if (f?.max && f?.max !== "") fieldSchema = fieldSchema.max(f.max);
2891
- if (f?.email) fieldSchema = fieldSchema.email();
2892
- if (f?.url) fieldSchema = fieldSchema.url();
2893
- if (f?.regex) fieldSchema = fieldSchema.regex(new RegExp(f.regex));
2894
- break;
2895
- case "Email":
2896
- fieldSchema = import_zod2.z.email({ message });
2897
- break;
2898
- case "Password":
2899
- fieldSchema = import_zod2.z.string({ message }).min(passwordLen, { message: `Password must be at least ${passwordLen} characters long` });
2900
- break;
2901
- case "Phone":
2902
- fieldSchema = import_zod2.z.string().transform((val) => val.replace(/\D/g, "")).transform((val) => val.slice(-10)).refine((val) => {
2903
- return val.length === 10;
2904
- }, {
2905
- message: "Phone number must be 10 digits long"
2906
- });
2907
- break;
2908
- case "DatePicker":
2909
- fieldSchema = import_zod2.z.iso.date({ message });
2910
- break;
2911
- case "FileInput":
2912
- fieldSchema = import_zod2.z.instanceof(File, { message: "Please select a file" });
2913
- if (f?.maxSize) {
2914
- fieldSchema = fieldSchema.refine(
2915
- (file) => file.size <= f.maxSize,
2916
- { message: `File size must be less than ${f.maxSize / 1024 / 1024}MB` }
2917
- );
2918
- }
2919
- if (f?.acceptedTypes) {
2920
- fieldSchema = fieldSchema.refine(
2921
- (file) => f.acceptedTypes.includes(file.type),
2922
- { message: `File type must be one of: ${f.acceptedTypes.join(", ")}` }
2923
- );
2924
- }
2925
- break;
2926
- case "Checkbox":
2927
- fieldSchema = import_zod2.z.boolean({ message });
2928
- break;
2929
- case "Dropdown":
2930
- fieldSchema = import_zod2.z.string({ message });
2931
- break;
2932
- case "NumberInput":
2933
- fieldSchema = import_zod2.z.number({ message });
2934
- if (f?.min !== void 0) fieldSchema = fieldSchema.min(f.min);
2935
- if (f?.max !== void 0) fieldSchema = fieldSchema.max(f.max);
2936
- break;
2937
- default:
2938
- fieldSchema = import_zod2.z.any();
2939
- }
2940
- if (!f.isRequired) fieldSchema = fieldSchema.optional();
2941
- acc[name] = fieldSchema;
2942
- return acc;
2943
- }, {});
2944
- return import_zod2.z.object(fields);
2945
- }
2946
- var Form = ({
2947
- validation,
2948
- defaultValues,
2949
- children,
2950
- onSubmit,
2951
- onReset
2952
- }) => {
2953
- const schema = (0, import_react9.useMemo)(() => {
2954
- if (!validation || validation.length === 0) return null;
2955
- return generateZodSchema(validation);
2956
- }, [validation]);
2957
- const {
2958
- handleSubmit,
2959
- control,
2960
- formState: { errors },
2961
- reset
2962
- } = (0, import_react_hook_form.useForm)({
2963
- resolver: schema ? (0, import_zod.zodResolver)(schema) : void 0,
2964
- defaultValues
2965
- });
2966
- const formSubmit = (data) => {
2967
- if (onSubmit) onSubmit(data);
2968
- };
2969
- const handleReset = () => {
2970
- reset();
2971
- if (onReset) onReset();
2972
- };
2973
- return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
2974
- "form",
2975
- {
2976
- onSubmit: handleSubmit(formSubmit),
2977
- onReset: handleReset,
2978
- className: cn(
2979
- "space-y-4 min-h-[100px] h-auto flex justify-between flex-col"
2980
- ),
2981
- children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)("div", { className: "min-h-[50px]", children: import_react9.default.Children.map(children, (child) => {
2982
- const processChild = (child2) => {
2983
- if (import_react9.default.isValidElement(child2)) {
2984
- const node = child2.props?.node;
2985
- if (node?.category === "Form Controls") {
2986
- const name = node.properties?.name || "unnamed";
2987
- return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)("div", { className: "flex flex-col", children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
2988
- import_react_hook_form.Controller,
2989
- {
2990
- name,
2991
- control,
2992
- render: ({ field: controllerField }) => {
2993
- const childElement = child2;
2994
- return import_react9.default.cloneElement(childElement, {
2995
- input: {
2996
- ...controllerField,
2997
- value: controllerField.value || "",
2998
- hasFormContainer: true,
2999
- validateOnMount: true,
3000
- errorMessage: errors[name]?.message || null
3001
- },
3002
- children: void 0
3003
- });
3004
- }
3005
- }
3006
- ) }, node.id);
3007
- }
3008
- if (child2.props?.children) {
3009
- const childElement = child2;
3010
- return import_react9.default.cloneElement(childElement, {
3011
- children: import_react9.default.Children.map(childElement.props.children, processChild)
3012
- });
3013
- }
3014
- return import_react9.default.cloneElement(child2);
3015
- }
3016
- return child2;
3017
- };
3018
- return processChild(child);
3019
- }) })
3020
- }
3021
- );
3022
- };
3023
- var Form_default = Form;
3024
-
3025
- // src/components/Form/Wrapper.tsx
3026
- var import_react10 = require("react");
3027
- var import_zod3 = require("@hookform/resolvers/zod");
3028
- var import_react_hook_form2 = require("react-hook-form");
3029
- var import_zod4 = require("zod");
3030
- var import_jsx_runtime58 = require("react/jsx-runtime");
3031
- function generateZodSchema2(data) {
3032
- const fields = data.reduce((acc, f) => {
3033
- const name = f.name || "unnamed";
3034
- const message = f.message || `${name} is invalid`;
3035
- const passwordLen = f.passwordLength;
3036
- let fieldSchema = import_zod4.z.string({ message });
3037
- switch (f.type) {
3038
- case "Text":
3039
- case "Search":
3040
- fieldSchema = import_zod4.z.string({ message });
3041
- if (f?.min && f?.min !== "") fieldSchema = fieldSchema.min(f.min);
3042
- else if (f.isRequired) fieldSchema = fieldSchema.min(1, { message: `${message}. Cannot be empty` });
3043
- if (f?.max && f?.max !== "") fieldSchema = fieldSchema.max(f.max);
3044
- if (f?.email) fieldSchema = fieldSchema.email();
3045
- if (f?.url) fieldSchema = fieldSchema.url();
3046
- if (f?.regex) fieldSchema = fieldSchema.regex(new RegExp(f.regex));
3047
- break;
3048
- case "Email":
3049
- fieldSchema = import_zod4.z.email({ message });
3050
- break;
3051
- case "Password":
3052
- fieldSchema = import_zod4.z.string({ message }).min(passwordLen, { message: `Password must be at least ${passwordLen} characters long` });
3053
- break;
3054
- case "Phone":
3055
- fieldSchema = import_zod4.z.string().transform((val) => val.replace(/\D/g, "")).transform((val) => val.slice(-10)).refine((val) => {
3056
- return val.length === 10;
3057
- }, {
3058
- message: "Phone number must be 10 digits long"
3059
- });
3060
- break;
3061
- case "DatePicker":
3062
- fieldSchema = import_zod4.z.iso.date({ message });
3063
- break;
3064
- case "FileInput":
3065
- fieldSchema = import_zod4.z.instanceof(File, { message: "Please select a file" });
3066
- if (f?.maxSize) {
3067
- fieldSchema = fieldSchema.refine(
3068
- (file) => file.size <= f.maxSize,
3069
- { message: `File size must be less than ${f.maxSize / 1024 / 1024}MB` }
3070
- );
3071
- }
3072
- if (f?.acceptedTypes) {
3073
- fieldSchema = fieldSchema.refine(
3074
- (file) => f.acceptedTypes.includes(file.type),
3075
- { message: `File type must be one of: ${f.acceptedTypes.join(", ")}` }
3076
- );
3077
- }
3078
- break;
3079
- case "Checkbox":
3080
- fieldSchema = import_zod4.z.boolean({ message });
3081
- break;
3082
- case "Dropdown":
3083
- fieldSchema = import_zod4.z.string({ message });
3084
- break;
3085
- case "NumberInput":
3086
- fieldSchema = import_zod4.z.number({ message });
3087
- if (f?.min !== void 0) fieldSchema = fieldSchema.min(f.min);
3088
- if (f?.max !== void 0) fieldSchema = fieldSchema.max(f.max);
3089
- break;
3090
- default:
3091
- fieldSchema = import_zod4.z.any();
3092
- }
3093
- if (!f.isRequired) fieldSchema = fieldSchema.optional();
3094
- acc[name] = fieldSchema;
3095
- return acc;
3096
- }, {});
3097
- return import_zod4.z.object(fields);
3098
- }
3099
- var FormWrapper = ({
3100
- validation,
3101
- defaultValues,
3102
- children,
3103
- onSubmit,
3104
- onReset
3105
- }) => {
3106
- const schema = (0, import_react10.useMemo)(() => {
3107
- if (!validation || validation.length === 0) return null;
3108
- return generateZodSchema2(validation);
3109
- }, [validation]);
3110
- const form = (0, import_react_hook_form2.useForm)({
3111
- resolver: schema ? (0, import_zod3.zodResolver)(schema) : void 0,
3112
- defaultValues
3113
- });
3114
- const formSubmit = (data) => {
3115
- if (onSubmit) onSubmit(data);
3116
- };
3117
- const handleReset = () => {
3118
- form.reset();
3119
- if (onReset) onReset();
3120
- };
3121
- return /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
3122
- "form",
3123
- {
3124
- onSubmit: form.handleSubmit(formSubmit),
3125
- onReset: handleReset,
3126
- className: cn(
3127
- "space-y-4 min-h-[100px] h-auto flex justify-between flex-col"
3128
- ),
3129
- children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)("div", { className: "min-h-[50px]", children: typeof children === "function" ? children(form) : children })
3130
- }
3131
- );
3132
- };
3133
- var Wrapper_default = FormWrapper;
3134
2843
  // Annotate the CommonJS export names for ESM import in node:
3135
2844
  0 && (module.exports = {
3136
2845
  BarChart,
@@ -3146,8 +2855,6 @@ var Wrapper_default = FormWrapper;
3146
2855
  EmailComposer,
3147
2856
  FileInput,
3148
2857
  FlexLayout,
3149
- Form,
3150
- FormWrapper,
3151
2858
  GridLayout,
3152
2859
  Image,
3153
2860
  Modal,
@@ -3164,7 +2871,6 @@ var Wrapper_default = FormWrapper;
3164
2871
  Shape,
3165
2872
  Spacer,
3166
2873
  Stages,
3167
- StateProvider,
3168
2874
  SwitchToggle,
3169
2875
  Table,
3170
2876
  Tabs,
@@ -3175,9 +2881,7 @@ var Wrapper_default = FormWrapper;
3175
2881
  URL,
3176
2882
  cn,
3177
2883
  getInitials,
3178
- showSonnerToast,
3179
- stateReducer,
3180
- useAppState
2884
+ showSonnerToast
3181
2885
  });
3182
2886
  /*! Bundled license information:
3183
2887