unifyedx-storybook-new 0.1.71 → 0.1.73

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.
@@ -75254,22 +75254,20 @@ function SectionRenderer({ item, data: initialData, updateHandler, validationErr
75254
75254
  const sectionData = initialData && initialData[item.key] || (item.type === "datatable" ? [] : {});
75255
75255
  return sectionData;
75256
75256
  });
75257
- const getOptions = React__default.useCallback((field) => {
75258
- if (field.optionsFrom) {
75257
+ const getDynamicOptions = (field) => {
75258
+ if (field.optionsFrom && initialData) {
75259
75259
  const { config, valueField, labelField } = field.optionsFrom;
75260
- const configData = initialData[config];
75260
+ const configData = initialData[config] || [];
75261
75261
  if (Array.isArray(configData)) {
75262
75262
  return configData.map((item2) => ({
75263
- id: item2[valueField],
75264
- // Add id for backward compatibility
75265
- value: item2[valueField],
75266
- label: item2[labelField]
75263
+ id: item2[valueField] || "",
75264
+ value: item2[valueField] || "",
75265
+ label: item2[labelField] || ""
75267
75266
  }));
75268
75267
  }
75269
- return [];
75270
75268
  }
75271
75269
  return field.options || [];
75272
- }, [initialData]);
75270
+ };
75273
75271
  const handleFieldChange = React__default.useCallback((fieldKey, value) => {
75274
75272
  setData((prevData) => {
75275
75273
  const newData = { ...prevData, [fieldKey]: value };
@@ -75415,7 +75413,23 @@ function SectionRenderer({ item, data: initialData, updateHandler, validationErr
75415
75413
  name: field.key,
75416
75414
  value: data[field.key] || field.default || "",
75417
75415
  onChange: (value) => handleFieldChange(field.key, value),
75418
- options: getOptions(field),
75416
+ options: field.options || [],
75417
+ placeholder: field.placeholder || `Select ${field.label}`,
75418
+ required: field.required,
75419
+ disabled: field.disabled ? field.disabled : false,
75420
+ className: `w-full ${validationErrors[section.key]?.[field.key] ? "border-red-500" : ""}`
75421
+ }
75422
+ ),
75423
+ validationErrors[section.key]?.[field.key] && /* @__PURE__ */ jsx("div", { style: { color: "#ef4444", fontSize: "12px", marginTop: "2px" }, children: validationErrors[section.key][field.key] })
75424
+ ] }),
75425
+ field.fieldtype === "selectDynamic" && /* @__PURE__ */ jsxs("div", { children: [
75426
+ /* @__PURE__ */ jsx(
75427
+ Select,
75428
+ {
75429
+ name: field.key,
75430
+ value: data[field.key] || field.default || "",
75431
+ onChange: (value) => handleFieldChange(field.key, value),
75432
+ options: getDynamicOptions(field),
75419
75433
  placeholder: field.placeholder || `Select ${field.label}`,
75420
75434
  required: field.required,
75421
75435
  disabled: field.disabled ? field.disabled : false,
@@ -75718,12 +75732,7 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75718
75732
  useEffect(() => {
75719
75733
  const existingData = initialData && initialData[section.key] || [];
75720
75734
  const newData = existingData.length > 0 ? existingData : [{ id: 0 }];
75721
- setData((prevData) => {
75722
- if (JSON.stringify(prevData) !== JSON.stringify(newData)) {
75723
- return newData;
75724
- }
75725
- return prevData;
75726
- });
75735
+ setData((prevData) => JSON.stringify(prevData) !== JSON.stringify(newData) ? newData : prevData);
75727
75736
  }, [initialData, section.key]);
75728
75737
  const debounce = useCallback((func, delay) => {
75729
75738
  let timeoutId;
@@ -75734,9 +75743,7 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75734
75743
  }, []);
75735
75744
  const debouncedUpdate = useCallback(
75736
75745
  debounce((newData) => {
75737
- if (updateHandler && typeof updateHandler === "function") {
75738
- updateHandler(section.key, newData);
75739
- }
75746
+ if (updateHandler) updateHandler(section.key, newData);
75740
75747
  }, 300),
75741
75748
  [section.key, updateHandler, debounce]
75742
75749
  );
@@ -75761,20 +75768,6 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75761
75768
  const error = getFieldError(field, rowIndex);
75762
75769
  return error ? /* @__PURE__ */ jsx("div", { className: "text-red-500 text-xs mt-1", children: error }) : null;
75763
75770
  }, [getFieldError]);
75764
- const getDynamicOptions = useCallback((field) => {
75765
- if (field.optionsFrom && initialData) {
75766
- const { config, valueField, labelField } = field.optionsFrom;
75767
- const configData = initialData[config] || [];
75768
- if (Array.isArray(configData)) {
75769
- return configData.map((item2) => ({
75770
- id: item2[valueField] || "",
75771
- value: item2[valueField] || "",
75772
- label: item2[labelField] || ""
75773
- }));
75774
- }
75775
- }
75776
- return field.options || [];
75777
- }, [initialData]);
75778
75771
  const getFieldRenderer = useCallback((field) => {
75779
75772
  switch (field.fieldtype) {
75780
75773
  case "text":
@@ -75821,58 +75814,22 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75821
75814
  ),
75822
75815
  renderError(field, rowIndex)
75823
75816
  ] });
75824
- case "email":
75817
+ case "select":
75818
+ case "dropdown":
75825
75819
  return (props, rowIndex) => /* @__PURE__ */ jsxs("div", { children: [
75826
75820
  /* @__PURE__ */ jsx(
75827
- Input$1,
75821
+ Select,
75828
75822
  {
75829
- type: "email",
75830
75823
  value: props[field.key] || "",
75831
- onChange: (e) => updateFieldValue(field, rowIndex, e.target.value),
75832
- placeholder: field.placeholder || "Enter email address",
75824
+ onChange: (value) => updateFieldValue(field, rowIndex, value),
75825
+ options: field.options || [],
75826
+ placeholder: field.placeholder || `Select ${field.label}`,
75833
75827
  required: field.required,
75834
75828
  className: `w-full ${getFieldError(field, rowIndex) ? "border-red-500" : ""}`
75835
75829
  }
75836
75830
  ),
75837
75831
  renderError(field, rowIndex)
75838
75832
  ] });
75839
- case "select":
75840
- case "dropdown":
75841
- return (props, rowIndex) => {
75842
- const [options, setOptions] = useState([]);
75843
- const handleOpen = () => {
75844
- setOptions(getDynamicOptions(field));
75845
- };
75846
- return /* @__PURE__ */ jsxs("div", { children: [
75847
- /* @__PURE__ */ jsx(
75848
- Select,
75849
- {
75850
- value: props[field.key] || "",
75851
- onChange: (value) => updateFieldValue(field, rowIndex, value),
75852
- options,
75853
- onOpen: handleOpen,
75854
- placeholder: field.placeholder || `Select ${field.label}`,
75855
- required: field.required,
75856
- className: `w-full ${getFieldError(field, rowIndex) ? "border-red-500" : ""}`
75857
- }
75858
- ),
75859
- renderError(field, rowIndex)
75860
- ] });
75861
- };
75862
- case "multiselect":
75863
- return (props, rowIndex) => {
75864
- const currentValue = props[field.key] || [];
75865
- return /* @__PURE__ */ jsx(
75866
- MultiSelect$1,
75867
- {
75868
- selectedItems: currentValue,
75869
- onSelectionChange: (selectedItems) => updateFieldValue(field, rowIndex, selectedItems),
75870
- options: field.options || [],
75871
- placeholder: field.placeholder || `Select ${field.label}`,
75872
- className: "w-full"
75873
- }
75874
- );
75875
- };
75876
75833
  case "checkbox":
75877
75834
  case "boolean":
75878
75835
  return (props, rowIndex) => /* @__PURE__ */ jsx(
@@ -75884,27 +75841,6 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75884
75841
  className: "w-full"
75885
75842
  }
75886
75843
  );
75887
- case "toggle":
75888
- case "switch":
75889
- return (props, rowIndex) => /* @__PURE__ */ jsx(
75890
- ToggleSwitch,
75891
- {
75892
- isOn: Boolean(props[field.key]),
75893
- onToggle: (isOn) => updateFieldValue(field, rowIndex, isOn),
75894
- label: field.placeholder || field.label,
75895
- className: "w-full"
75896
- }
75897
- );
75898
- case "date":
75899
- return (props, rowIndex) => /* @__PURE__ */ jsx(
75900
- DatePicker$1,
75901
- {
75902
- selectedDate: props[field.key] ? new Date(props[field.key]) : null,
75903
- onDateChange: (date) => updateFieldValue(field, rowIndex, date ? date.toISOString().split("T")[0] : ""),
75904
- placeholder: field.placeholder || "Select date",
75905
- className: "w-full"
75906
- }
75907
- );
75908
75844
  default:
75909
75845
  return (props, rowIndex) => /* @__PURE__ */ jsxs("div", { children: [
75910
75846
  /* @__PURE__ */ jsx(
@@ -75920,24 +75856,14 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75920
75856
  renderError(field, rowIndex)
75921
75857
  ] });
75922
75858
  }
75923
- }, [updateFieldValue, getDynamicOptions, getFieldError, renderError]);
75859
+ }, [updateFieldValue, getFieldError, renderError]);
75924
75860
  const addBlankRow = useCallback(() => {
75925
75861
  isStructuralChangeRef.current = true;
75926
75862
  setData((prevData) => {
75927
75863
  const blankRow = { id: prevData.length };
75928
- section.fields.forEach((field) => {
75929
- if (field.fieldtype === "audience") {
75930
- blankRow[field.key] = { users: [], groups: [], roles: [] };
75931
- } else {
75932
- blankRow[field.key] = "";
75933
- }
75934
- });
75864
+ section.fields.forEach((field) => blankRow[field.key] = field.fieldtype === "audience" ? { users: [], groups: [], roles: [] } : "");
75935
75865
  const newData = [...prevData, blankRow];
75936
- setTimeout(() => {
75937
- if (updateHandler && typeof updateHandler === "function") {
75938
- updateHandler(section.key, newData);
75939
- }
75940
- }, 0);
75866
+ setTimeout(() => updateHandler?.(section.key, newData), 0);
75941
75867
  return newData;
75942
75868
  });
75943
75869
  }, [section.fields, updateHandler, section.key]);
@@ -75947,11 +75873,7 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75947
75873
  if (prevData.length <= 1) return prevData;
75948
75874
  const newData = [...prevData];
75949
75875
  newData.splice(index, 1);
75950
- setTimeout(() => {
75951
- if (updateHandler && typeof updateHandler === "function") {
75952
- updateHandler(section.key, newData);
75953
- }
75954
- }, 0);
75876
+ setTimeout(() => updateHandler?.(section.key, newData), 0);
75955
75877
  return newData;
75956
75878
  });
75957
75879
  }, [updateHandler, section.key]);
@@ -75970,9 +75892,9 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75970
75892
  if (draggedIndex === null || draggedIndex === dropIndex) return;
75971
75893
  setData((prevData) => {
75972
75894
  const newData = [...prevData];
75973
- const draggedItem = newData[draggedIndex];
75895
+ const item2 = newData[draggedIndex];
75974
75896
  newData.splice(draggedIndex, 1);
75975
- newData.splice(dropIndex, 0, draggedItem);
75897
+ newData.splice(dropIndex, 0, item2);
75976
75898
  return newData;
75977
75899
  });
75978
75900
  setDraggedIndex(null);
@@ -75985,9 +75907,9 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
75985
75907
  const newData = [...prevData];
75986
75908
  if (audienceRowId !== null && audienceFieldName && newData[audienceRowId]) {
75987
75909
  const pendingInvites = selectedEntities.pendingInvites || [];
75988
- const users = pendingInvites.filter((invite) => invite.type === "User");
75989
- const groups = pendingInvites.filter((invite) => invite.type === "Group");
75990
- const roles = pendingInvites.filter((invite) => invite.type === "Role");
75910
+ const users = pendingInvites.filter((i) => i.type === "User");
75911
+ const groups = pendingInvites.filter((i) => i.type === "Group");
75912
+ const roles = pendingInvites.filter((i) => i.type === "Role");
75991
75913
  newData[audienceRowId][audienceFieldName] = {
75992
75914
  users: [...newData[audienceRowId][audienceFieldName]?.users || [], ...users],
75993
75915
  groups: [...newData[audienceRowId][audienceFieldName]?.groups || [], ...groups],
@@ -76030,28 +75952,16 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
76030
75952
  onDrop: (e) => handleDrop(e, rowIndex),
76031
75953
  onDragEnd: handleDragEnd,
76032
75954
  children: [
76033
- /* @__PURE__ */ jsx("td", { className: "px-4 py-2 ", children: /* @__PURE__ */ jsx("div", { className: "cursor-move text-gray-400 hover:text-gray-600", children: /* @__PURE__ */ jsx(GripVertical, { size: 16 }) }) }),
76034
- section.fields.map((field, fieldIndex) => /* @__PURE__ */ jsx("td", { className: "px-4 py-2 ", children: getFieldRenderer(field)(row, rowIndex) }, `field-${rowIndex}-${fieldIndex}-${field.key}`)),
76035
- /* @__PURE__ */ jsx("td", { className: "px-4 py-2 ", children: /* @__PURE__ */ jsx(
76036
- "button",
76037
- {
76038
- onClick: () => removeRow(rowIndex),
76039
- className: "text-red-500 hover:text-red-700",
76040
- title: "Delete row",
76041
- children: /* @__PURE__ */ jsx(Trash, { size: 16 })
76042
- }
76043
- ) })
75955
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: /* @__PURE__ */ jsx("div", { className: "cursor-move text-gray-400 hover:text-gray-600", children: /* @__PURE__ */ jsx(GripVertical, { size: 16 }) }) }),
75956
+ section.fields.map((field, fieldIndex) => /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: getFieldRenderer(field)(row, rowIndex) }, `field-${rowIndex}-${fieldIndex}-${field.key}`)),
75957
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: /* @__PURE__ */ jsx("button", { onClick: () => removeRow(rowIndex), className: "text-red-500 hover:text-red-700", title: "Delete row", children: /* @__PURE__ */ jsx(Trash, { size: 16 }) }) })
76044
75958
  ]
76045
75959
  },
76046
75960
  `row-${rowIndex}-${row.id || "empty"}`
76047
75961
  )) })
76048
75962
  ] }) }),
76049
75963
  audienceRowId !== null && (() => {
76050
- const existingAudienceData = data[audienceRowId] && data[audienceRowId][audienceFieldName] ? {
76051
- users: data[audienceRowId][audienceFieldName].users || [],
76052
- groups: data[audienceRowId][audienceFieldName].groups || [],
76053
- roles: data[audienceRowId][audienceFieldName].roles || []
76054
- } : { users: [], groups: [], roles: [] };
75964
+ const existingAudienceData = data[audienceRowId]?.[audienceFieldName] || { users: [], groups: [], roles: [] };
76055
75965
  return /* @__PURE__ */ jsx(
76056
75966
  AddUserGroupsRolesModal,
76057
75967
  {
@@ -76068,9 +75978,7 @@ function DataTableRenderer({ item, data: initialData, updateHandler, validationE
76068
75978
  })()
76069
75979
  ] });
76070
75980
  }
76071
- const DataTableRenderer$1 = React__default.memo(DataTableRenderer, (prevProps, nextProps) => {
76072
- return prevProps.item === nextProps.item && prevProps.initialData === nextProps.initialData && prevProps.validationErrors === nextProps.validationErrors;
76073
- });
75981
+ const DataTableRenderer$1 = React__default.memo(DataTableRenderer, (prevProps, nextProps) => prevProps.item === nextProps.item && prevProps.initialData === nextProps.initialData && prevProps.validationErrors === nextProps.validationErrors);
76074
75982
 
76075
75983
  function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
76076
75984