warqadui 0.0.31 → 0.0.33

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.d.mts CHANGED
@@ -351,7 +351,7 @@ interface PhoneInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElemen
351
351
  }
352
352
  declare const PhoneInput: React$1.ForwardRefExoticComponent<PhoneInputProps & React$1.RefAttributes<any>>;
353
353
 
354
- interface InputProps<T extends FieldValues> extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "name" | "form"> {
354
+ interface InputProps<T extends FieldValues> extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "name" | "form" | "onChange"> {
355
355
  label?: string;
356
356
  icon?: React.ReactNode;
357
357
  error?: string;
@@ -360,6 +360,7 @@ interface InputProps<T extends FieldValues> extends Omit<React.InputHTMLAttribut
360
360
  form?: UseFormReturn<T>;
361
361
  type?: "text" | "number" | "email" | "password";
362
362
  variant?: "ghost" | "default";
363
+ onChange?: (value: any) => void;
363
364
  }
364
365
  declare const Input: <T extends FieldValues>(props: InputProps<T> & {
365
366
  ref?: React.ForwardedRef<HTMLInputElement>;
@@ -442,17 +443,18 @@ interface PostTableActions {
442
443
  focus: (columnId: string) => void;
443
444
  setError: (columnId: string, error: boolean | string) => void;
444
445
  }
446
+ interface PostTableChangeParams<TData> {
447
+ entryData: Partial<TData>;
448
+ actions: PostTableActions;
449
+ actionType: "add" | "edit" | "delete";
450
+ fullData: TData[];
451
+ }
445
452
  interface PostTableProps<TData> {
446
453
  columns: (ColumnDef<TData, any> & {
447
454
  key?: string;
448
455
  })[];
449
456
  data?: TData[];
450
- onChange?: (params: {
451
- entryData: Partial<TData>;
452
- actions: PostTableActions;
453
- actionType: "add" | "edit" | "delete";
454
- fullData: TData[];
455
- }) => void | Promise<void | boolean>;
457
+ onChange?: (params: PostTableChangeParams<TData>) => void | Promise<void | boolean>;
456
458
  isLoading?: boolean;
457
459
  className?: string;
458
460
  verticalLines?: boolean;
@@ -466,9 +468,12 @@ interface PostTableProps<TData> {
466
468
  hasSubComponent?: (row: TData) => boolean;
467
469
  defaultExpanded?: boolean;
468
470
  submitLoading?: boolean;
471
+ onCancel?: () => void;
472
+ onEdit?: (row: TData) => void;
473
+ onDelete?: (row: TData) => void;
469
474
  }
470
475
  declare function PostTable<TData extends Record<string, any>>({ columns: userColumns, data: controlledData, onChange, isLoading, className, verticalLines, rowPadding, index, renderAddButton, renderSubComponent, hasSubComponent, // default to true if renderSubComponent is provided
471
- defaultExpanded, submitLoading, }: PostTableProps<TData>): react_jsx_runtime.JSX.Element;
476
+ defaultExpanded, submitLoading, onCancel, onEdit, onDelete, }: PostTableProps<TData>): react_jsx_runtime.JSX.Element;
472
477
 
473
478
  type SimpleTableColumn<TData> = ColumnDef<TData, any> & {
474
479
  key?: string;
@@ -703,4 +708,4 @@ interface StorageManager {
703
708
  */
704
709
  declare const storage: StorageManager;
705
710
 
706
- export { A4DataView, Badge, type BadgeProps, Branding, type BrandingProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ClassicSpin, CodeBlock, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, type FetchFunction, type FetchProps, Fields, InfoGrid, Input, type InputProps, LoadingBox, LoadingSpin, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PutFunction, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, type UseModalReturn, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, generatePdf, storage, useA4StatementView, useApi, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig };
711
+ export { A4DataView, Badge, type BadgeProps, Branding, type BrandingProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ClassicSpin, CodeBlock, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, type FetchFunction, type FetchProps, Fields, InfoGrid, Input, type InputProps, LoadingBox, LoadingSpin, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PostTableChangeParams, type PutFunction, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, type UseModalReturn, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, generatePdf, storage, useA4StatementView, useApi, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig };
package/dist/index.d.ts CHANGED
@@ -351,7 +351,7 @@ interface PhoneInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElemen
351
351
  }
352
352
  declare const PhoneInput: React$1.ForwardRefExoticComponent<PhoneInputProps & React$1.RefAttributes<any>>;
353
353
 
354
- interface InputProps<T extends FieldValues> extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "name" | "form"> {
354
+ interface InputProps<T extends FieldValues> extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "name" | "form" | "onChange"> {
355
355
  label?: string;
356
356
  icon?: React.ReactNode;
357
357
  error?: string;
@@ -360,6 +360,7 @@ interface InputProps<T extends FieldValues> extends Omit<React.InputHTMLAttribut
360
360
  form?: UseFormReturn<T>;
361
361
  type?: "text" | "number" | "email" | "password";
362
362
  variant?: "ghost" | "default";
363
+ onChange?: (value: any) => void;
363
364
  }
364
365
  declare const Input: <T extends FieldValues>(props: InputProps<T> & {
365
366
  ref?: React.ForwardedRef<HTMLInputElement>;
@@ -442,17 +443,18 @@ interface PostTableActions {
442
443
  focus: (columnId: string) => void;
443
444
  setError: (columnId: string, error: boolean | string) => void;
444
445
  }
446
+ interface PostTableChangeParams<TData> {
447
+ entryData: Partial<TData>;
448
+ actions: PostTableActions;
449
+ actionType: "add" | "edit" | "delete";
450
+ fullData: TData[];
451
+ }
445
452
  interface PostTableProps<TData> {
446
453
  columns: (ColumnDef<TData, any> & {
447
454
  key?: string;
448
455
  })[];
449
456
  data?: TData[];
450
- onChange?: (params: {
451
- entryData: Partial<TData>;
452
- actions: PostTableActions;
453
- actionType: "add" | "edit" | "delete";
454
- fullData: TData[];
455
- }) => void | Promise<void | boolean>;
457
+ onChange?: (params: PostTableChangeParams<TData>) => void | Promise<void | boolean>;
456
458
  isLoading?: boolean;
457
459
  className?: string;
458
460
  verticalLines?: boolean;
@@ -466,9 +468,12 @@ interface PostTableProps<TData> {
466
468
  hasSubComponent?: (row: TData) => boolean;
467
469
  defaultExpanded?: boolean;
468
470
  submitLoading?: boolean;
471
+ onCancel?: () => void;
472
+ onEdit?: (row: TData) => void;
473
+ onDelete?: (row: TData) => void;
469
474
  }
470
475
  declare function PostTable<TData extends Record<string, any>>({ columns: userColumns, data: controlledData, onChange, isLoading, className, verticalLines, rowPadding, index, renderAddButton, renderSubComponent, hasSubComponent, // default to true if renderSubComponent is provided
471
- defaultExpanded, submitLoading, }: PostTableProps<TData>): react_jsx_runtime.JSX.Element;
476
+ defaultExpanded, submitLoading, onCancel, onEdit, onDelete, }: PostTableProps<TData>): react_jsx_runtime.JSX.Element;
472
477
 
473
478
  type SimpleTableColumn<TData> = ColumnDef<TData, any> & {
474
479
  key?: string;
@@ -703,4 +708,4 @@ interface StorageManager {
703
708
  */
704
709
  declare const storage: StorageManager;
705
710
 
706
- export { A4DataView, Badge, type BadgeProps, Branding, type BrandingProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ClassicSpin, CodeBlock, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, type FetchFunction, type FetchProps, Fields, InfoGrid, Input, type InputProps, LoadingBox, LoadingSpin, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PutFunction, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, type UseModalReturn, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, generatePdf, storage, useA4StatementView, useApi, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig };
711
+ export { A4DataView, Badge, type BadgeProps, Branding, type BrandingProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ClassicSpin, CodeBlock, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, type FetchFunction, type FetchProps, Fields, InfoGrid, Input, type InputProps, LoadingBox, LoadingSpin, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PostTableChangeParams, type PutFunction, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, type UseModalReturn, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, generatePdf, storage, useA4StatementView, useApi, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig };
package/dist/index.js CHANGED
@@ -1157,6 +1157,14 @@ var Input = (0, import_react8.forwardRef)(
1157
1157
  const [showPassword, setShowPassword] = (0, import_react8.useState)(false);
1158
1158
  const { theme } = useWarqadConfig();
1159
1159
  const primaryColor = theme?.primaryColor;
1160
+ (0, import_react8.useEffect)(() => {
1161
+ if (form && name && props.value !== void 0 && props.value !== null && props.value !== "") {
1162
+ const currentFormValue = form.getValues(name);
1163
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1164
+ form.setValue(name, props.value);
1165
+ }
1166
+ }
1167
+ }, [props.value, name, form]);
1160
1168
  let message = error;
1161
1169
  if (form && name) {
1162
1170
  const {
@@ -1239,39 +1247,62 @@ var Input = (0, import_react8.forwardRef)(
1239
1247
  {
1240
1248
  control: form.control,
1241
1249
  name,
1242
- render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => renderInput(
1243
- {
1244
- ref: fieldRef,
1245
- onBlur: () => {
1246
- onBlur2();
1247
- },
1248
- value: value ? String(value).split(".").map(
1249
- (part, index) => index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
1250
- ).join(".") : "",
1251
- onChange: (e) => {
1252
- const rawValue = e.target.value.replace(/,/g, "");
1253
- if (!/^\d*\.?\d*$/.test(rawValue)) return;
1254
- if (rawValue === "") {
1255
- onChange("");
1256
- } else {
1257
- const numValue = Number(rawValue);
1258
- if (!isNaN(numValue) && String(numValue) === rawValue) {
1259
- onChange(numValue);
1250
+ render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => {
1251
+ const hasValue = value !== void 0 && value !== null && value !== "";
1252
+ const hasPropsValue = props.value !== void 0 && props.value !== null && props.value !== "";
1253
+ const displayValue = hasValue ? value : hasPropsValue ? props.value : "";
1254
+ return renderInput(
1255
+ {
1256
+ ref: fieldRef,
1257
+ onBlur: () => {
1258
+ onBlur2();
1259
+ },
1260
+ value: displayValue !== "" ? String(displayValue).split(".").map(
1261
+ (part, index) => index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
1262
+ ).join(".") : "",
1263
+ onChange: (e) => {
1264
+ const rawValue = e.target.value.replace(/,/g, "");
1265
+ if (!/^\d*\.?\d*$/.test(rawValue)) return;
1266
+ if (rawValue === "") {
1267
+ onChange("");
1268
+ props.onChange?.("");
1260
1269
  } else {
1261
- onChange(rawValue);
1270
+ const numValue = Number(rawValue);
1271
+ if (!isNaN(numValue) && String(numValue) === rawValue) {
1272
+ onChange(numValue);
1273
+ props.onChange?.(numValue);
1274
+ } else {
1275
+ onChange(rawValue);
1276
+ props.onChange?.(rawValue);
1277
+ }
1262
1278
  }
1263
1279
  }
1264
- props.onChange?.(e);
1265
- }
1266
- },
1267
- "text"
1268
- )
1280
+ },
1281
+ "text"
1282
+ );
1283
+ }
1269
1284
  }
1270
1285
  );
1271
1286
  }
1272
- let inputPropsObj = form && name ? form.register(name, type === "number" ? { valueAsNumber: true } : {}) : {};
1287
+ let inputPropsObj = {};
1288
+ const originalOnChange = props.onChange;
1289
+ if (form && name) {
1290
+ const registeredProps = form.register(
1291
+ name,
1292
+ type === "number" ? { valueAsNumber: true } : {}
1293
+ );
1294
+ inputPropsObj = {
1295
+ ...registeredProps,
1296
+ onChange: (e) => {
1297
+ registeredProps.onChange(e);
1298
+ const rawValue = e.target.value.replace(/,/g, "");
1299
+ originalOnChange?.(
1300
+ type === "number" ? rawValue === "" ? "" : Number(rawValue) : e.target.value
1301
+ );
1302
+ }
1303
+ };
1304
+ }
1273
1305
  if (type === "number" && (!form || !name)) {
1274
- const originalOnChange = props.onChange;
1275
1306
  inputPropsObj = {
1276
1307
  ...inputPropsObj,
1277
1308
  value: props.value !== void 0 && props.value !== null ? String(props.value).split(".").map(
@@ -1281,20 +1312,20 @@ var Input = (0, import_react8.forwardRef)(
1281
1312
  const rawValue = e.target.value.replace(/,/g, "");
1282
1313
  if (!/^\d*\.?\d*$/.test(rawValue)) return;
1283
1314
  if (originalOnChange) {
1284
- const fakeEvent = {
1285
- ...e,
1286
- target: {
1287
- ...e.target,
1288
- value: rawValue,
1289
- valueAsNumber: rawValue === "" ? NaN : Number(rawValue)
1290
- }
1291
- };
1292
- originalOnChange(fakeEvent);
1315
+ originalOnChange(rawValue === "" ? "" : Number(rawValue));
1293
1316
  }
1294
1317
  }
1295
1318
  };
1296
1319
  return renderInput(inputPropsObj, "text");
1297
1320
  }
1321
+ if (!form || !name) {
1322
+ inputPropsObj = {
1323
+ ...inputPropsObj,
1324
+ onChange: (e) => {
1325
+ originalOnChange?.(e.target.value);
1326
+ }
1327
+ };
1328
+ }
1298
1329
  return renderInput(inputPropsObj, type === "number" ? "text" : type);
1299
1330
  }
1300
1331
  );
@@ -1412,6 +1443,14 @@ var useSelectContext = () => {
1412
1443
  };
1413
1444
  var Select = (0, import_react10.forwardRef)((props, ref) => {
1414
1445
  const { form, name, onChange, value, children, options = [] } = props;
1446
+ (0, import_react10.useEffect)(() => {
1447
+ if (form && name && value !== void 0 && value !== null && value !== "") {
1448
+ const currentFormValue = form.getValues(name);
1449
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1450
+ form.setValue(name, value);
1451
+ }
1452
+ }
1453
+ }, [value, name, form]);
1415
1454
  if (form && name) {
1416
1455
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1417
1456
  import_react_hook_form3.Controller,
@@ -1866,30 +1905,47 @@ var Textarea = (0, import_react11.forwardRef)(
1866
1905
  ) }),
1867
1906
  message && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-sm text-red-600 dark:text-red-400", children: message })
1868
1907
  ] });
1908
+ (0, import_react11.useEffect)(() => {
1909
+ if (form && name && props.value !== void 0 && props.value !== null && props.value !== "") {
1910
+ const currentFormValue = form.getValues(name);
1911
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1912
+ form.setValue(name, props.value);
1913
+ }
1914
+ }
1915
+ }, [props.value, name, form]);
1869
1916
  if (form && name) {
1870
1917
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1871
1918
  import_react_hook_form4.Controller,
1872
1919
  {
1873
1920
  control: form.control,
1874
1921
  name,
1875
- render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => renderInput(
1876
- {
1877
- value: value || "",
1878
- // Ensure controlled input doesn't warn about uncontrolled
1879
- onChange: (e) => {
1880
- onChange(e);
1881
- props.onChange?.(e);
1922
+ render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => {
1923
+ const displayValue = value !== void 0 && value !== null && value !== "" ? value : props.value;
1924
+ return renderInput(
1925
+ {
1926
+ value: displayValue || "",
1927
+ onChange: (e) => {
1928
+ onChange(e);
1929
+ props.onChange?.(e);
1930
+ },
1931
+ onBlur: () => {
1932
+ onBlur2();
1933
+ }
1882
1934
  },
1883
- onBlur: () => {
1884
- onBlur2();
1885
- }
1886
- },
1887
- fieldRef
1888
- )
1935
+ fieldRef
1936
+ );
1937
+ }
1889
1938
  }
1890
1939
  );
1891
1940
  }
1892
- return renderInput({}, ref);
1941
+ return renderInput(
1942
+ {
1943
+ onChange: (e) => {
1944
+ props.onChange?.(e);
1945
+ }
1946
+ },
1947
+ ref
1948
+ );
1893
1949
  }
1894
1950
  );
1895
1951
 
@@ -2081,6 +2137,14 @@ var useSearchApiContext = () => {
2081
2137
  var SearchApi = (0, import_react13.forwardRef)(
2082
2138
  (props, _) => {
2083
2139
  const { form, name, onChange, onSelect, onClear, value, children, ...restProps } = props;
2140
+ (0, import_react13.useEffect)(() => {
2141
+ if (form && name && value !== void 0 && value !== null && value !== "") {
2142
+ const currentFormValue = form.getValues(name);
2143
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
2144
+ form.setValue(name, value);
2145
+ }
2146
+ }
2147
+ }, [value, name, form]);
2084
2148
  if (form && name) {
2085
2149
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2086
2150
  import_react_hook_form5.Controller,
@@ -2209,12 +2273,12 @@ var SearchApiRoot = ({
2209
2273
  }
2210
2274
  }, [isOpen]);
2211
2275
  (0, import_react13.useEffect)(() => {
2212
- if (currentValue && !selectedObject) {
2276
+ if (currentValue !== void 0 && currentValue !== null && currentValue !== "" && !selectedObject) {
2213
2277
  setHasAttemptedHydration(false);
2214
2278
  fetchOptions(currentValue).finally(() => {
2215
2279
  setHasAttemptedHydration(true);
2216
2280
  });
2217
- } else if (!currentValue) {
2281
+ } else if (currentValue === void 0 || currentValue === null || currentValue === "") {
2218
2282
  setHasAttemptedHydration(true);
2219
2283
  if (selectedObject) setSelectedObject(void 0);
2220
2284
  }
@@ -2226,7 +2290,7 @@ var SearchApiRoot = ({
2226
2290
  return option[valueKey];
2227
2291
  };
2228
2292
  (0, import_react13.useEffect)(() => {
2229
- if (currentValue && !selectedObject && options.length > 0) {
2293
+ if (currentValue !== void 0 && currentValue !== null && currentValue !== "" && !selectedObject && options.length > 0) {
2230
2294
  const found = options.find((o) => getOptionValue(o) === currentValue);
2231
2295
  if (found) {
2232
2296
  setSelectedObject(found);
@@ -2279,13 +2343,13 @@ var SearchApiRoot = ({
2279
2343
  }, [fieldInternalProps]);
2280
2344
  const getDisplayValue = () => {
2281
2345
  if (selectedObject) return selectedObject[labelKey];
2282
- if (options.length > 0 && currentValue) {
2346
+ if (options.length > 0 && (currentValue !== void 0 && currentValue !== null && currentValue !== "")) {
2283
2347
  const found = options.find((o) => getOptionValue(o) === currentValue);
2284
2348
  if (found) return found[labelKey];
2285
2349
  }
2286
- if (isLoading || currentValue && !hasAttemptedHydration)
2350
+ if (isLoading || currentValue !== void 0 && currentValue !== null && currentValue !== "" && !hasAttemptedHydration)
2287
2351
  return "Loading...";
2288
- return currentValue || "";
2352
+ return currentValue !== void 0 && currentValue !== null && currentValue !== "" ? currentValue : "";
2289
2353
  };
2290
2354
  const handleSelect = (option) => {
2291
2355
  const val = getOptionValue(option);
@@ -2540,7 +2604,7 @@ var SearchApiInput = (0, import_react13.forwardRef)(
2540
2604
  }
2541
2605
  };
2542
2606
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
2543
- !isOpen && selectedValue && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "absolute inset-0 flex items-center ms-1 truncate select-none", children: getDisplayValue() }),
2607
+ !isOpen && (selectedValue !== void 0 && selectedValue !== null && selectedValue !== "") && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "absolute inset-0 flex items-center ms-1 truncate select-none", children: getDisplayValue() }),
2544
2608
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2545
2609
  "input",
2546
2610
  {
@@ -3240,7 +3304,10 @@ function PostTable({
3240
3304
  hasSubComponent = () => true,
3241
3305
  // default to true if renderSubComponent is provided
3242
3306
  defaultExpanded = false,
3243
- submitLoading = false
3307
+ submitLoading = false,
3308
+ onCancel,
3309
+ onEdit,
3310
+ onDelete
3244
3311
  }) {
3245
3312
  const { theme } = useWarqadConfig();
3246
3313
  const primaryColor = theme?.primaryColor;
@@ -3295,7 +3362,10 @@ function PostTable({
3295
3362
  isSavingAsync,
3296
3363
  submitLoading,
3297
3364
  fieldErrors,
3298
- onChange
3365
+ onChange,
3366
+ onCancel,
3367
+ onEdit,
3368
+ onDelete
3299
3369
  });
3300
3370
  (0, import_react16.useEffect)(() => {
3301
3371
  latestStateRef.current = {
@@ -3305,7 +3375,10 @@ function PostTable({
3305
3375
  isSavingAsync,
3306
3376
  submitLoading,
3307
3377
  fieldErrors,
3308
- onChange
3378
+ onChange,
3379
+ onCancel,
3380
+ onEdit,
3381
+ onDelete
3309
3382
  };
3310
3383
  });
3311
3384
  const handleSaveField = (0, import_react16.useCallback)(async () => {
@@ -3378,80 +3451,92 @@ function PostTable({
3378
3451
  }
3379
3452
  }, []);
3380
3453
  const handleCancelEdit = (0, import_react16.useCallback)(() => {
3454
+ const { onCancel: onCancel2 } = latestStateRef.current;
3381
3455
  setEditingIndex(null);
3382
3456
  setEntryData({});
3383
3457
  setFieldErrors({});
3458
+ if (onCancel2) onCancel2();
3384
3459
  }, []);
3385
3460
  const handleEdit = (0, import_react16.useCallback)((index2, rowOriginal) => {
3461
+ const { onEdit: onEdit2 } = latestStateRef.current;
3386
3462
  setEditingIndex(index2);
3387
3463
  setEntryData(rowOriginal);
3464
+ if (onEdit2) onEdit2(rowOriginal);
3388
3465
  }, []);
3389
- const handleDelete = (0, import_react16.useCallback)((index2) => {
3390
- const { data: data2, editingIndex: editingIndex2, onChange: onChange2 } = latestStateRef.current;
3391
- const newData = data2.filter((_, i) => i !== index2);
3392
- setData(newData);
3393
- const actions = {
3394
- focus: (columnId) => {
3395
- if (entryRowRef.current) {
3396
- const td = entryRowRef.current.querySelector(
3397
- `td[data-column-id="${columnId}"]`
3398
- );
3399
- if (td) {
3400
- const input = td.querySelector(
3401
- `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3466
+ const handleDelete = (0, import_react16.useCallback)(
3467
+ (index2) => {
3468
+ const { data: data2, editingIndex: editingIndex2, onChange: onChange2, onDelete: onDelete2 } = latestStateRef.current;
3469
+ const rowToDelete = data2[index2];
3470
+ const newData = data2.filter((_, i) => i !== index2);
3471
+ setData(newData);
3472
+ if (onDelete2) onDelete2(rowToDelete);
3473
+ const actions = {
3474
+ focus: (columnId) => {
3475
+ if (entryRowRef.current) {
3476
+ const td = entryRowRef.current.querySelector(
3477
+ `td[data-column-id="${columnId}"]`
3402
3478
  );
3403
- if (input) input.focus();
3479
+ if (td) {
3480
+ const input = td.querySelector(
3481
+ `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3482
+ );
3483
+ if (input) input.focus();
3484
+ }
3404
3485
  }
3486
+ },
3487
+ setError: (columnId, error) => {
3488
+ setFieldErrors((prev) => ({
3489
+ ...prev,
3490
+ [columnId]: error
3491
+ }));
3405
3492
  }
3406
- },
3407
- setError: (columnId, error) => {
3408
- setFieldErrors((prev) => ({
3409
- ...prev,
3410
- [columnId]: error
3411
- }));
3493
+ };
3494
+ onChange2?.({
3495
+ entryData: data2[index2],
3496
+ actions,
3497
+ actionType: "delete",
3498
+ fullData: newData
3499
+ });
3500
+ if (editingIndex2 === index2) {
3501
+ handleCancelEdit();
3502
+ } else if (editingIndex2 !== null && editingIndex2 > index2) {
3503
+ setEditingIndex(editingIndex2 - 1);
3412
3504
  }
3413
- };
3414
- onChange2?.({
3415
- entryData: data2[index2],
3416
- actions,
3417
- actionType: "delete",
3418
- fullData: newData
3419
- });
3420
- if (editingIndex2 === index2) {
3421
- handleCancelEdit();
3422
- } else if (editingIndex2 !== null && editingIndex2 > index2) {
3423
- setEditingIndex(editingIndex2 - 1);
3424
- }
3425
- }, [handleCancelEdit]);
3426
- const actionColumn = (0, import_react16.useMemo)(() => ({
3427
- id: "actions",
3428
- header: "Actions",
3429
- cell: ({ row, table: table2 }) => {
3430
- const { handleEdit: handleEdit2, handleDelete: handleDelete2, submitLoading: submitLoading2, isSavingAsync: isSavingAsync2 } = table2.options.meta;
3431
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center gap-2", children: [
3432
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3433
- "button",
3434
- {
3435
- onClick: () => handleEdit2(row.index, row.original),
3436
- disabled: submitLoading2 || isSavingAsync2,
3437
- className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-(--theme-primary) dark:hover:text-(--theme-primary) transition-colors disabled:opacity-50",
3438
- title: "Edit",
3439
- children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Loader2, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Edit2, { size: 16 })
3440
- }
3441
- ),
3442
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3443
- "button",
3444
- {
3445
- onClick: () => handleDelete2(row.index),
3446
- disabled: submitLoading2 || isSavingAsync2,
3447
- className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors disabled:opacity-50",
3448
- title: "Delete",
3449
- children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Loader2, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Trash2, { size: 16 })
3450
- }
3451
- )
3452
- ] });
3453
- }
3454
- }), []);
3505
+ },
3506
+ [handleCancelEdit]
3507
+ );
3508
+ const actionColumn = (0, import_react16.useMemo)(
3509
+ () => ({
3510
+ id: "actions",
3511
+ header: "Actions",
3512
+ cell: ({ row, table: table2 }) => {
3513
+ const { handleEdit: handleEdit2, handleDelete: handleDelete2, submitLoading: submitLoading2, isSavingAsync: isSavingAsync2 } = table2.options.meta;
3514
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex items-center gap-2", children: [
3515
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3516
+ "button",
3517
+ {
3518
+ onClick: () => handleEdit2(row.index, row.original),
3519
+ disabled: submitLoading2 || isSavingAsync2,
3520
+ className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-(--theme-primary) dark:hover:text-(--theme-primary) transition-colors disabled:opacity-50",
3521
+ title: "Edit",
3522
+ children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Loader2, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Edit2, { size: 16 })
3523
+ }
3524
+ ),
3525
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3526
+ "button",
3527
+ {
3528
+ onClick: () => handleDelete2(row.index),
3529
+ disabled: submitLoading2 || isSavingAsync2,
3530
+ className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors disabled:opacity-50",
3531
+ title: "Delete",
3532
+ children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Loader2, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Trash2, { size: 16 })
3533
+ }
3534
+ )
3535
+ ] });
3536
+ }
3537
+ }),
3538
+ []
3539
+ );
3455
3540
  const columns = (0, import_react16.useMemo)(() => {
3456
3541
  const mappedUserColumns = userColumns.map((col) => ({
3457
3542
  ...col,
@@ -3610,7 +3695,13 @@ function PostTable({
3610
3695
  disabled: isSavingAsync || submitLoading,
3611
3696
  className: "flex-1 h-8 flex items-center justify-center rounded-lg bg-green-500/10 text-green-600 dark:bg-emerald-500/20 dark:text-emerald-400 hover:bg-green-500 hover:text-white dark:hover:bg-emerald-500 transition-colors shadow-sm active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",
3612
3697
  title: "Update",
3613
- children: isSavingAsync || submitLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Loader2, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Check, { size: 16, strokeWidth: 2.5 })
3698
+ children: isSavingAsync || submitLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3699
+ import_lucide_react11.Loader2,
3700
+ {
3701
+ size: 16,
3702
+ className: "animate-spin"
3703
+ }
3704
+ ) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Check, { size: 16, strokeWidth: 2.5 })
3614
3705
  }
3615
3706
  ),
3616
3707
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
@@ -3638,7 +3729,13 @@ function PostTable({
3638
3729
  },
3639
3730
  title: "Add Row",
3640
3731
  children: [
3641
- isSavingAsync || submitLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Loader2, { size: 14, className: "animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Plus, { size: 14, strokeWidth: 2.5 }),
3732
+ isSavingAsync || submitLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3733
+ import_lucide_react11.Loader2,
3734
+ {
3735
+ size: 14,
3736
+ className: "animate-spin"
3737
+ }
3738
+ ) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_lucide_react11.Plus, { size: 14, strokeWidth: 2.5 }),
3642
3739
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: isSavingAsync || submitLoading ? "Adding..." : "Add" })
3643
3740
  ]
3644
3741
  }
package/dist/index.mjs CHANGED
@@ -1079,6 +1079,14 @@ var Input = forwardRef(
1079
1079
  const [showPassword, setShowPassword] = useState7(false);
1080
1080
  const { theme } = useWarqadConfig();
1081
1081
  const primaryColor = theme?.primaryColor;
1082
+ useEffect5(() => {
1083
+ if (form && name && props.value !== void 0 && props.value !== null && props.value !== "") {
1084
+ const currentFormValue = form.getValues(name);
1085
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1086
+ form.setValue(name, props.value);
1087
+ }
1088
+ }
1089
+ }, [props.value, name, form]);
1082
1090
  let message = error;
1083
1091
  if (form && name) {
1084
1092
  const {
@@ -1161,39 +1169,62 @@ var Input = forwardRef(
1161
1169
  {
1162
1170
  control: form.control,
1163
1171
  name,
1164
- render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => renderInput(
1165
- {
1166
- ref: fieldRef,
1167
- onBlur: () => {
1168
- onBlur2();
1169
- },
1170
- value: value ? String(value).split(".").map(
1171
- (part, index) => index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
1172
- ).join(".") : "",
1173
- onChange: (e) => {
1174
- const rawValue = e.target.value.replace(/,/g, "");
1175
- if (!/^\d*\.?\d*$/.test(rawValue)) return;
1176
- if (rawValue === "") {
1177
- onChange("");
1178
- } else {
1179
- const numValue = Number(rawValue);
1180
- if (!isNaN(numValue) && String(numValue) === rawValue) {
1181
- onChange(numValue);
1172
+ render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => {
1173
+ const hasValue = value !== void 0 && value !== null && value !== "";
1174
+ const hasPropsValue = props.value !== void 0 && props.value !== null && props.value !== "";
1175
+ const displayValue = hasValue ? value : hasPropsValue ? props.value : "";
1176
+ return renderInput(
1177
+ {
1178
+ ref: fieldRef,
1179
+ onBlur: () => {
1180
+ onBlur2();
1181
+ },
1182
+ value: displayValue !== "" ? String(displayValue).split(".").map(
1183
+ (part, index) => index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
1184
+ ).join(".") : "",
1185
+ onChange: (e) => {
1186
+ const rawValue = e.target.value.replace(/,/g, "");
1187
+ if (!/^\d*\.?\d*$/.test(rawValue)) return;
1188
+ if (rawValue === "") {
1189
+ onChange("");
1190
+ props.onChange?.("");
1182
1191
  } else {
1183
- onChange(rawValue);
1192
+ const numValue = Number(rawValue);
1193
+ if (!isNaN(numValue) && String(numValue) === rawValue) {
1194
+ onChange(numValue);
1195
+ props.onChange?.(numValue);
1196
+ } else {
1197
+ onChange(rawValue);
1198
+ props.onChange?.(rawValue);
1199
+ }
1184
1200
  }
1185
1201
  }
1186
- props.onChange?.(e);
1187
- }
1188
- },
1189
- "text"
1190
- )
1202
+ },
1203
+ "text"
1204
+ );
1205
+ }
1191
1206
  }
1192
1207
  );
1193
1208
  }
1194
- let inputPropsObj = form && name ? form.register(name, type === "number" ? { valueAsNumber: true } : {}) : {};
1209
+ let inputPropsObj = {};
1210
+ const originalOnChange = props.onChange;
1211
+ if (form && name) {
1212
+ const registeredProps = form.register(
1213
+ name,
1214
+ type === "number" ? { valueAsNumber: true } : {}
1215
+ );
1216
+ inputPropsObj = {
1217
+ ...registeredProps,
1218
+ onChange: (e) => {
1219
+ registeredProps.onChange(e);
1220
+ const rawValue = e.target.value.replace(/,/g, "");
1221
+ originalOnChange?.(
1222
+ type === "number" ? rawValue === "" ? "" : Number(rawValue) : e.target.value
1223
+ );
1224
+ }
1225
+ };
1226
+ }
1195
1227
  if (type === "number" && (!form || !name)) {
1196
- const originalOnChange = props.onChange;
1197
1228
  inputPropsObj = {
1198
1229
  ...inputPropsObj,
1199
1230
  value: props.value !== void 0 && props.value !== null ? String(props.value).split(".").map(
@@ -1203,20 +1234,20 @@ var Input = forwardRef(
1203
1234
  const rawValue = e.target.value.replace(/,/g, "");
1204
1235
  if (!/^\d*\.?\d*$/.test(rawValue)) return;
1205
1236
  if (originalOnChange) {
1206
- const fakeEvent = {
1207
- ...e,
1208
- target: {
1209
- ...e.target,
1210
- value: rawValue,
1211
- valueAsNumber: rawValue === "" ? NaN : Number(rawValue)
1212
- }
1213
- };
1214
- originalOnChange(fakeEvent);
1237
+ originalOnChange(rawValue === "" ? "" : Number(rawValue));
1215
1238
  }
1216
1239
  }
1217
1240
  };
1218
1241
  return renderInput(inputPropsObj, "text");
1219
1242
  }
1243
+ if (!form || !name) {
1244
+ inputPropsObj = {
1245
+ ...inputPropsObj,
1246
+ onChange: (e) => {
1247
+ originalOnChange?.(e.target.value);
1248
+ }
1249
+ };
1250
+ }
1220
1251
  return renderInput(inputPropsObj, type === "number" ? "text" : type);
1221
1252
  }
1222
1253
  );
@@ -1343,6 +1374,14 @@ var useSelectContext = () => {
1343
1374
  };
1344
1375
  var Select = forwardRef3((props, ref) => {
1345
1376
  const { form, name, onChange, value, children, options = [] } = props;
1377
+ useEffect6(() => {
1378
+ if (form && name && value !== void 0 && value !== null && value !== "") {
1379
+ const currentFormValue = form.getValues(name);
1380
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1381
+ form.setValue(name, value);
1382
+ }
1383
+ }
1384
+ }, [value, name, form]);
1346
1385
  if (form && name) {
1347
1386
  return /* @__PURE__ */ jsx19(
1348
1387
  Controller3,
@@ -1735,7 +1774,7 @@ var SelectItem = forwardRef3(
1735
1774
  SelectItem.displayName = "SelectItem";
1736
1775
 
1737
1776
  // src/components/Fields/textArea.tsx
1738
- import { forwardRef as forwardRef4, useState as useState10 } from "react";
1777
+ import { forwardRef as forwardRef4, useEffect as useEffect7, useState as useState10 } from "react";
1739
1778
  import {
1740
1779
  Controller as Controller4
1741
1780
  } from "react-hook-form";
@@ -1799,30 +1838,47 @@ var Textarea = forwardRef4(
1799
1838
  ) }),
1800
1839
  message && /* @__PURE__ */ jsx20("p", { className: "text-sm text-red-600 dark:text-red-400", children: message })
1801
1840
  ] });
1841
+ useEffect7(() => {
1842
+ if (form && name && props.value !== void 0 && props.value !== null && props.value !== "") {
1843
+ const currentFormValue = form.getValues(name);
1844
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
1845
+ form.setValue(name, props.value);
1846
+ }
1847
+ }
1848
+ }, [props.value, name, form]);
1802
1849
  if (form && name) {
1803
1850
  return /* @__PURE__ */ jsx20(
1804
1851
  Controller4,
1805
1852
  {
1806
1853
  control: form.control,
1807
1854
  name,
1808
- render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => renderInput(
1809
- {
1810
- value: value || "",
1811
- // Ensure controlled input doesn't warn about uncontrolled
1812
- onChange: (e) => {
1813
- onChange(e);
1814
- props.onChange?.(e);
1855
+ render: ({ field: { onChange, value, ref: fieldRef, onBlur: onBlur2 } }) => {
1856
+ const displayValue = value !== void 0 && value !== null && value !== "" ? value : props.value;
1857
+ return renderInput(
1858
+ {
1859
+ value: displayValue || "",
1860
+ onChange: (e) => {
1861
+ onChange(e);
1862
+ props.onChange?.(e);
1863
+ },
1864
+ onBlur: () => {
1865
+ onBlur2();
1866
+ }
1815
1867
  },
1816
- onBlur: () => {
1817
- onBlur2();
1818
- }
1819
- },
1820
- fieldRef
1821
- )
1868
+ fieldRef
1869
+ );
1870
+ }
1822
1871
  }
1823
1872
  );
1824
1873
  }
1825
- return renderInput({}, ref);
1874
+ return renderInput(
1875
+ {
1876
+ onChange: (e) => {
1877
+ props.onChange?.(e);
1878
+ }
1879
+ },
1880
+ ref
1881
+ );
1826
1882
  }
1827
1883
  );
1828
1884
 
@@ -1832,7 +1888,7 @@ import {
1832
1888
  useContext as useContext4,
1833
1889
  useState as useState12,
1834
1890
  useRef as useRef4,
1835
- useEffect as useEffect7,
1891
+ useEffect as useEffect8,
1836
1892
  forwardRef as forwardRef5
1837
1893
  } from "react";
1838
1894
  import { createPortal as createPortal2 } from "react-dom";
@@ -2021,6 +2077,14 @@ var useSearchApiContext = () => {
2021
2077
  var SearchApi = forwardRef5(
2022
2078
  (props, _) => {
2023
2079
  const { form, name, onChange, onSelect, onClear, value, children, ...restProps } = props;
2080
+ useEffect8(() => {
2081
+ if (form && name && value !== void 0 && value !== null && value !== "") {
2082
+ const currentFormValue = form.getValues(name);
2083
+ if (currentFormValue === void 0 || currentFormValue === "" || currentFormValue === 0) {
2084
+ form.setValue(name, value);
2085
+ }
2086
+ }
2087
+ }, [value, name, form]);
2024
2088
  if (form && name) {
2025
2089
  return /* @__PURE__ */ jsx21(
2026
2090
  Controller5,
@@ -2135,7 +2199,7 @@ var SearchApiRoot = ({
2135
2199
  setOptions([]);
2136
2200
  }
2137
2201
  };
2138
- useEffect7(() => {
2202
+ useEffect8(() => {
2139
2203
  const timer = setTimeout(() => {
2140
2204
  if (isOpen) {
2141
2205
  fetchOptions(searchTerm);
@@ -2143,18 +2207,18 @@ var SearchApiRoot = ({
2143
2207
  }, 300);
2144
2208
  return () => clearTimeout(timer);
2145
2209
  }, [searchTerm, api, isOpen]);
2146
- useEffect7(() => {
2210
+ useEffect8(() => {
2147
2211
  if (isOpen && options.length === 0) {
2148
2212
  fetchOptions("");
2149
2213
  }
2150
2214
  }, [isOpen]);
2151
- useEffect7(() => {
2152
- if (currentValue && !selectedObject) {
2215
+ useEffect8(() => {
2216
+ if (currentValue !== void 0 && currentValue !== null && currentValue !== "" && !selectedObject) {
2153
2217
  setHasAttemptedHydration(false);
2154
2218
  fetchOptions(currentValue).finally(() => {
2155
2219
  setHasAttemptedHydration(true);
2156
2220
  });
2157
- } else if (!currentValue) {
2221
+ } else if (currentValue === void 0 || currentValue === null || currentValue === "") {
2158
2222
  setHasAttemptedHydration(true);
2159
2223
  if (selectedObject) setSelectedObject(void 0);
2160
2224
  }
@@ -2165,8 +2229,8 @@ var SearchApiRoot = ({
2165
2229
  }
2166
2230
  return option[valueKey];
2167
2231
  };
2168
- useEffect7(() => {
2169
- if (currentValue && !selectedObject && options.length > 0) {
2232
+ useEffect8(() => {
2233
+ if (currentValue !== void 0 && currentValue !== null && currentValue !== "" && !selectedObject && options.length > 0) {
2170
2234
  const found = options.find((o) => getOptionValue(o) === currentValue);
2171
2235
  if (found) {
2172
2236
  setSelectedObject(found);
@@ -2179,7 +2243,7 @@ var SearchApiRoot = ({
2179
2243
  }
2180
2244
  }
2181
2245
  }, [currentValue, options, obj]);
2182
- useEffect7(() => {
2246
+ useEffect8(() => {
2183
2247
  if (prevApiRef.current !== api) {
2184
2248
  prevApiRef.current = api;
2185
2249
  setSearchTerm("");
@@ -2204,7 +2268,7 @@ var SearchApiRoot = ({
2204
2268
  fetchOptions("");
2205
2269
  }
2206
2270
  }, [api, name, obj]);
2207
- useEffect7(() => {
2271
+ useEffect8(() => {
2208
2272
  const handleClickOutside = (event) => {
2209
2273
  const target = event.target;
2210
2274
  if (containerRef.current && !containerRef.current.contains(target) && !(dropdownContentRef.current && dropdownContentRef.current.contains(target))) {
@@ -2219,13 +2283,13 @@ var SearchApiRoot = ({
2219
2283
  }, [fieldInternalProps]);
2220
2284
  const getDisplayValue = () => {
2221
2285
  if (selectedObject) return selectedObject[labelKey];
2222
- if (options.length > 0 && currentValue) {
2286
+ if (options.length > 0 && (currentValue !== void 0 && currentValue !== null && currentValue !== "")) {
2223
2287
  const found = options.find((o) => getOptionValue(o) === currentValue);
2224
2288
  if (found) return found[labelKey];
2225
2289
  }
2226
- if (isLoading || currentValue && !hasAttemptedHydration)
2290
+ if (isLoading || currentValue !== void 0 && currentValue !== null && currentValue !== "" && !hasAttemptedHydration)
2227
2291
  return "Loading...";
2228
- return currentValue || "";
2292
+ return currentValue !== void 0 && currentValue !== null && currentValue !== "" ? currentValue : "";
2229
2293
  };
2230
2294
  const handleSelect = (option) => {
2231
2295
  const val = getOptionValue(option);
@@ -2480,7 +2544,7 @@ var SearchApiInput = forwardRef5(
2480
2544
  }
2481
2545
  };
2482
2546
  return /* @__PURE__ */ jsxs15(Fragment4, { children: [
2483
- !isOpen && selectedValue && /* @__PURE__ */ jsx21("div", { className: "absolute inset-0 flex items-center ms-1 truncate select-none", children: getDisplayValue() }),
2547
+ !isOpen && (selectedValue !== void 0 && selectedValue !== null && selectedValue !== "") && /* @__PURE__ */ jsx21("div", { className: "absolute inset-0 flex items-center ms-1 truncate select-none", children: getDisplayValue() }),
2484
2548
  /* @__PURE__ */ jsx21(
2485
2549
  "input",
2486
2550
  {
@@ -2554,7 +2618,7 @@ var SearchApiContent = forwardRef5(
2554
2618
  setDropdownStyle(newStyle);
2555
2619
  }
2556
2620
  };
2557
- useEffect7(() => {
2621
+ useEffect8(() => {
2558
2622
  if (isOpen) {
2559
2623
  updateDropdownPosition();
2560
2624
  window.addEventListener("scroll", updateDropdownPosition, true);
@@ -2774,7 +2838,7 @@ var Fields = {
2774
2838
  var Fields_default = Fields;
2775
2839
 
2776
2840
  // src/components/tables/DataTable.tsx
2777
- import React8, { useState as useState14, useMemo as useMemo3, useEffect as useEffect8 } from "react";
2841
+ import React8, { useState as useState14, useMemo as useMemo3, useEffect as useEffect9 } from "react";
2778
2842
  import {
2779
2843
  useReactTable,
2780
2844
  getCoreRowModel,
@@ -2829,7 +2893,7 @@ function DataTable({
2829
2893
  pageIndex: 0,
2830
2894
  pageSize: pageRows || 10
2831
2895
  });
2832
- useEffect8(() => {
2896
+ useEffect9(() => {
2833
2897
  if (pageRows) {
2834
2898
  setPagination((prev) => ({ ...prev, pageSize: pageRows }));
2835
2899
  }
@@ -2895,7 +2959,7 @@ function DataTable({
2895
2959
  },
2896
2960
  manualPagination: false
2897
2961
  });
2898
- useEffect8(() => {
2962
+ useEffect9(() => {
2899
2963
  if (onChange) {
2900
2964
  onChange({
2901
2965
  pagination: {
@@ -3093,7 +3157,13 @@ function DataTable({
3093
3157
  }
3094
3158
 
3095
3159
  // src/components/tables/PostTable.tsx
3096
- import React9, { useState as useState15, useMemo as useMemo4, useEffect as useEffect9, useRef as useRef5, useCallback as useCallback2 } from "react";
3160
+ import React9, {
3161
+ useState as useState15,
3162
+ useMemo as useMemo4,
3163
+ useEffect as useEffect10,
3164
+ useRef as useRef5,
3165
+ useCallback as useCallback2
3166
+ } from "react";
3097
3167
  import {
3098
3168
  useReactTable as useReactTable2,
3099
3169
  getCoreRowModel as getCoreRowModel2,
@@ -3102,7 +3172,15 @@ import {
3102
3172
  getExpandedRowModel as getExpandedRowModel2,
3103
3173
  flexRender as flexRender2
3104
3174
  } from "@tanstack/react-table";
3105
- import { Plus, Edit2, Trash2, Check as Check4, X as X3, ChevronDown as ChevronDown5, Loader2 as Loader23 } from "lucide-react";
3175
+ import {
3176
+ Plus,
3177
+ Edit2,
3178
+ Trash2,
3179
+ Check as Check4,
3180
+ X as X3,
3181
+ ChevronDown as ChevronDown5,
3182
+ Loader2 as Loader23
3183
+ } from "lucide-react";
3106
3184
  import { Fragment as Fragment6, jsx as jsx24, jsxs as jsxs18 } from "react/jsx-runtime";
3107
3185
  var TableCell = React9.memo(
3108
3186
  ({
@@ -3197,7 +3275,10 @@ function PostTable({
3197
3275
  hasSubComponent = () => true,
3198
3276
  // default to true if renderSubComponent is provided
3199
3277
  defaultExpanded = false,
3200
- submitLoading = false
3278
+ submitLoading = false,
3279
+ onCancel,
3280
+ onEdit,
3281
+ onDelete
3201
3282
  }) {
3202
3283
  const { theme } = useWarqadConfig();
3203
3284
  const primaryColor = theme?.primaryColor;
@@ -3233,10 +3314,10 @@ function PostTable({
3233
3314
  }
3234
3315
  }, 50);
3235
3316
  };
3236
- useEffect9(() => {
3317
+ useEffect10(() => {
3237
3318
  focusAndScrollEntryRow();
3238
3319
  }, []);
3239
- useEffect9(() => {
3320
+ useEffect10(() => {
3240
3321
  if (controlledData) {
3241
3322
  setData(controlledData);
3242
3323
  }
@@ -3252,9 +3333,12 @@ function PostTable({
3252
3333
  isSavingAsync,
3253
3334
  submitLoading,
3254
3335
  fieldErrors,
3255
- onChange
3336
+ onChange,
3337
+ onCancel,
3338
+ onEdit,
3339
+ onDelete
3256
3340
  });
3257
- useEffect9(() => {
3341
+ useEffect10(() => {
3258
3342
  latestStateRef.current = {
3259
3343
  data,
3260
3344
  entryData,
@@ -3262,7 +3346,10 @@ function PostTable({
3262
3346
  isSavingAsync,
3263
3347
  submitLoading,
3264
3348
  fieldErrors,
3265
- onChange
3349
+ onChange,
3350
+ onCancel,
3351
+ onEdit,
3352
+ onDelete
3266
3353
  };
3267
3354
  });
3268
3355
  const handleSaveField = useCallback2(async () => {
@@ -3335,80 +3422,92 @@ function PostTable({
3335
3422
  }
3336
3423
  }, []);
3337
3424
  const handleCancelEdit = useCallback2(() => {
3425
+ const { onCancel: onCancel2 } = latestStateRef.current;
3338
3426
  setEditingIndex(null);
3339
3427
  setEntryData({});
3340
3428
  setFieldErrors({});
3429
+ if (onCancel2) onCancel2();
3341
3430
  }, []);
3342
3431
  const handleEdit = useCallback2((index2, rowOriginal) => {
3432
+ const { onEdit: onEdit2 } = latestStateRef.current;
3343
3433
  setEditingIndex(index2);
3344
3434
  setEntryData(rowOriginal);
3435
+ if (onEdit2) onEdit2(rowOriginal);
3345
3436
  }, []);
3346
- const handleDelete = useCallback2((index2) => {
3347
- const { data: data2, editingIndex: editingIndex2, onChange: onChange2 } = latestStateRef.current;
3348
- const newData = data2.filter((_, i) => i !== index2);
3349
- setData(newData);
3350
- const actions = {
3351
- focus: (columnId) => {
3352
- if (entryRowRef.current) {
3353
- const td = entryRowRef.current.querySelector(
3354
- `td[data-column-id="${columnId}"]`
3355
- );
3356
- if (td) {
3357
- const input = td.querySelector(
3358
- `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3437
+ const handleDelete = useCallback2(
3438
+ (index2) => {
3439
+ const { data: data2, editingIndex: editingIndex2, onChange: onChange2, onDelete: onDelete2 } = latestStateRef.current;
3440
+ const rowToDelete = data2[index2];
3441
+ const newData = data2.filter((_, i) => i !== index2);
3442
+ setData(newData);
3443
+ if (onDelete2) onDelete2(rowToDelete);
3444
+ const actions = {
3445
+ focus: (columnId) => {
3446
+ if (entryRowRef.current) {
3447
+ const td = entryRowRef.current.querySelector(
3448
+ `td[data-column-id="${columnId}"]`
3359
3449
  );
3360
- if (input) input.focus();
3450
+ if (td) {
3451
+ const input = td.querySelector(
3452
+ `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3453
+ );
3454
+ if (input) input.focus();
3455
+ }
3361
3456
  }
3457
+ },
3458
+ setError: (columnId, error) => {
3459
+ setFieldErrors((prev) => ({
3460
+ ...prev,
3461
+ [columnId]: error
3462
+ }));
3362
3463
  }
3363
- },
3364
- setError: (columnId, error) => {
3365
- setFieldErrors((prev) => ({
3366
- ...prev,
3367
- [columnId]: error
3368
- }));
3464
+ };
3465
+ onChange2?.({
3466
+ entryData: data2[index2],
3467
+ actions,
3468
+ actionType: "delete",
3469
+ fullData: newData
3470
+ });
3471
+ if (editingIndex2 === index2) {
3472
+ handleCancelEdit();
3473
+ } else if (editingIndex2 !== null && editingIndex2 > index2) {
3474
+ setEditingIndex(editingIndex2 - 1);
3369
3475
  }
3370
- };
3371
- onChange2?.({
3372
- entryData: data2[index2],
3373
- actions,
3374
- actionType: "delete",
3375
- fullData: newData
3376
- });
3377
- if (editingIndex2 === index2) {
3378
- handleCancelEdit();
3379
- } else if (editingIndex2 !== null && editingIndex2 > index2) {
3380
- setEditingIndex(editingIndex2 - 1);
3381
- }
3382
- }, [handleCancelEdit]);
3383
- const actionColumn = useMemo4(() => ({
3384
- id: "actions",
3385
- header: "Actions",
3386
- cell: ({ row, table: table2 }) => {
3387
- const { handleEdit: handleEdit2, handleDelete: handleDelete2, submitLoading: submitLoading2, isSavingAsync: isSavingAsync2 } = table2.options.meta;
3388
- return /* @__PURE__ */ jsxs18("div", { className: "flex items-center gap-2", children: [
3389
- /* @__PURE__ */ jsx24(
3390
- "button",
3391
- {
3392
- onClick: () => handleEdit2(row.index, row.original),
3393
- disabled: submitLoading2 || isSavingAsync2,
3394
- className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-(--theme-primary) dark:hover:text-(--theme-primary) transition-colors disabled:opacity-50",
3395
- title: "Edit",
3396
- children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Edit2, { size: 16 })
3397
- }
3398
- ),
3399
- /* @__PURE__ */ jsx24(
3400
- "button",
3401
- {
3402
- onClick: () => handleDelete2(row.index),
3403
- disabled: submitLoading2 || isSavingAsync2,
3404
- className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors disabled:opacity-50",
3405
- title: "Delete",
3406
- children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Trash2, { size: 16 })
3407
- }
3408
- )
3409
- ] });
3410
- }
3411
- }), []);
3476
+ },
3477
+ [handleCancelEdit]
3478
+ );
3479
+ const actionColumn = useMemo4(
3480
+ () => ({
3481
+ id: "actions",
3482
+ header: "Actions",
3483
+ cell: ({ row, table: table2 }) => {
3484
+ const { handleEdit: handleEdit2, handleDelete: handleDelete2, submitLoading: submitLoading2, isSavingAsync: isSavingAsync2 } = table2.options.meta;
3485
+ return /* @__PURE__ */ jsxs18("div", { className: "flex items-center gap-2", children: [
3486
+ /* @__PURE__ */ jsx24(
3487
+ "button",
3488
+ {
3489
+ onClick: () => handleEdit2(row.index, row.original),
3490
+ disabled: submitLoading2 || isSavingAsync2,
3491
+ className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-(--theme-primary) dark:hover:text-(--theme-primary) transition-colors disabled:opacity-50",
3492
+ title: "Edit",
3493
+ children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Edit2, { size: 16 })
3494
+ }
3495
+ ),
3496
+ /* @__PURE__ */ jsx24(
3497
+ "button",
3498
+ {
3499
+ onClick: () => handleDelete2(row.index),
3500
+ disabled: submitLoading2 || isSavingAsync2,
3501
+ className: "p-1 px-2 rounded-md hover:bg-gray-100 dark:hover:bg-zinc-800 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors disabled:opacity-50",
3502
+ title: "Delete",
3503
+ children: submitLoading2 || isSavingAsync2 ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Trash2, { size: 16 })
3504
+ }
3505
+ )
3506
+ ] });
3507
+ }
3508
+ }),
3509
+ []
3510
+ );
3412
3511
  const columns = useMemo4(() => {
3413
3512
  const mappedUserColumns = userColumns.map((col) => ({
3414
3513
  ...col,
@@ -3567,7 +3666,13 @@ function PostTable({
3567
3666
  disabled: isSavingAsync || submitLoading,
3568
3667
  className: "flex-1 h-8 flex items-center justify-center rounded-lg bg-green-500/10 text-green-600 dark:bg-emerald-500/20 dark:text-emerald-400 hover:bg-green-500 hover:text-white dark:hover:bg-emerald-500 transition-colors shadow-sm active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",
3569
3668
  title: "Update",
3570
- children: isSavingAsync || submitLoading ? /* @__PURE__ */ jsx24(Loader23, { size: 16, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Check4, { size: 16, strokeWidth: 2.5 })
3669
+ children: isSavingAsync || submitLoading ? /* @__PURE__ */ jsx24(
3670
+ Loader23,
3671
+ {
3672
+ size: 16,
3673
+ className: "animate-spin"
3674
+ }
3675
+ ) : /* @__PURE__ */ jsx24(Check4, { size: 16, strokeWidth: 2.5 })
3571
3676
  }
3572
3677
  ),
3573
3678
  /* @__PURE__ */ jsx24(
@@ -3595,7 +3700,13 @@ function PostTable({
3595
3700
  },
3596
3701
  title: "Add Row",
3597
3702
  children: [
3598
- isSavingAsync || submitLoading ? /* @__PURE__ */ jsx24(Loader23, { size: 14, className: "animate-spin" }) : /* @__PURE__ */ jsx24(Plus, { size: 14, strokeWidth: 2.5 }),
3703
+ isSavingAsync || submitLoading ? /* @__PURE__ */ jsx24(
3704
+ Loader23,
3705
+ {
3706
+ size: 14,
3707
+ className: "animate-spin"
3708
+ }
3709
+ ) : /* @__PURE__ */ jsx24(Plus, { size: 14, strokeWidth: 2.5 }),
3599
3710
  /* @__PURE__ */ jsx24("span", { children: isSavingAsync || submitLoading ? "Adding..." : "Add" })
3600
3711
  ]
3601
3712
  }
@@ -3937,7 +4048,7 @@ var Branding = ({
3937
4048
  };
3938
4049
 
3939
4050
  // src/hooks/Fetches/useA4DataView.tsx
3940
- import { useEffect as useEffect10, useRef as useRef6, useState as useState16 } from "react";
4051
+ import { useEffect as useEffect11, useRef as useRef6, useState as useState16 } from "react";
3941
4052
  import { useReactToPrint } from "react-to-print";
3942
4053
  import { RefreshCw, Printer, AlertCircle, FileX } from "lucide-react";
3943
4054
  import { jsx as jsx28, jsxs as jsxs20 } from "react/jsx-runtime";
@@ -3952,7 +4063,7 @@ var useA4StatementView = ({
3952
4063
  const reactToPrintFn = useReactToPrint({
3953
4064
  contentRef
3954
4065
  });
3955
- useEffect10(() => {
4066
+ useEffect11(() => {
3956
4067
  if (url) {
3957
4068
  get({ url, v, params, delay });
3958
4069
  }
@@ -4029,7 +4140,7 @@ var useA4StatementView = ({
4029
4140
  renderFooter: c.renderFooter ? c.renderFooter.toString() : ""
4030
4141
  }))
4031
4142
  });
4032
- useEffect10(() => {
4143
+ useEffect11(() => {
4033
4144
  if (filteredDisplayData && filteredDisplayData.length > 0) {
4034
4145
  setIsMeasuring(true);
4035
4146
  setPages((prev) => prev.length === 0 ? [[]] : prev);
@@ -4040,7 +4151,7 @@ var useA4StatementView = ({
4040
4151
  );
4041
4152
  }
4042
4153
  }, [depsString]);
4043
- useEffect10(() => {
4154
+ useEffect11(() => {
4044
4155
  if (!isMeasuring || filteredDisplayData.length === 0) return;
4045
4156
  const timer = setTimeout(() => {
4046
4157
  if (!measureContainerRef.current) return;
@@ -4258,7 +4369,7 @@ var A4DataView = (props) => {
4258
4369
  var useA4DataView_default = useA4StatementView;
4259
4370
 
4260
4371
  // src/hooks/Fetches/useTransaction.tsx
4261
- import { useEffect as useEffect11, useState as useState17 } from "react";
4372
+ import { useEffect as useEffect12, useState as useState17 } from "react";
4262
4373
  import { AlertCircle as AlertCircle2, FileX as FileX2, Plus as Plus2, RefreshCw as RefreshCw2 } from "lucide-react";
4263
4374
  import moment from "moment";
4264
4375
  import { jsx as jsx29, jsxs as jsxs21 } from "react/jsx-runtime";
@@ -4285,7 +4396,7 @@ var useTransaction = ({
4285
4396
  delay
4286
4397
  });
4287
4398
  };
4288
- useEffect11(() => {
4399
+ useEffect12(() => {
4289
4400
  getData();
4290
4401
  }, [url, v, JSON.stringify(params), delay, date]);
4291
4402
  const TransactionViewComponent = ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warqadui",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -18,7 +18,8 @@
18
18
  "scripts": {
19
19
  "build": "tsup src/index.ts src/styles.css --format esm,cjs --dts --injectStyle",
20
20
  "dev": "tsup src/index.ts src/styles.css --format esm,cjs --dts --watch --injectStyle",
21
- "prepublish": "npm run build"
21
+ "prepublish": "npm run build",
22
+ "release": "npm run build && npm version patch && npm publish"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "@tanstack/react-table": "^8.12.0",