@algorithm-shift/design-system 1.2.966 → 1.2.967
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 +51 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -27796,7 +27796,7 @@ function useLazyDropdown(config) {
|
|
|
27796
27796
|
if (!configRef.current.apiUrl) return [];
|
|
27797
27797
|
const limit = PAGE_SIZE;
|
|
27798
27798
|
const params = { page: pageNum, limit };
|
|
27799
|
-
if (term) params[configRef.current.dataLabel
|
|
27799
|
+
if (term) params[configRef.current.dataLabel ? `${configRef.current.dataLabel}[ilike]` : "search[ilike]"] = term;
|
|
27800
27800
|
const axiosClient = configRef.current.axiosInstance ?? axios;
|
|
27801
27801
|
const res = await axiosClient.get(configRef.current.apiUrl, {
|
|
27802
27802
|
params,
|
|
@@ -27850,8 +27850,20 @@ function useLazyDropdown(config) {
|
|
|
27850
27850
|
try {
|
|
27851
27851
|
setLoading(true);
|
|
27852
27852
|
const axiosClient = configRef.current.axiosInstance ?? axios;
|
|
27853
|
+
let params = {
|
|
27854
|
+
[configRef.current.dataKey]: configRef.current.value
|
|
27855
|
+
};
|
|
27856
|
+
if (Array.isArray(configRef.current.value)) {
|
|
27857
|
+
if (configRef.current.value.length === 0) {
|
|
27858
|
+
setLoading(false);
|
|
27859
|
+
return;
|
|
27860
|
+
}
|
|
27861
|
+
params = {
|
|
27862
|
+
[`${configRef.current.dataKey}[in]`]: configRef.current.value.join(",")
|
|
27863
|
+
};
|
|
27864
|
+
}
|
|
27853
27865
|
const res = await axiosClient.get(configRef.current.apiUrl, {
|
|
27854
|
-
params
|
|
27866
|
+
params,
|
|
27855
27867
|
withCredentials: true
|
|
27856
27868
|
});
|
|
27857
27869
|
if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
|
|
@@ -27867,8 +27879,8 @@ function useLazyDropdown(config) {
|
|
|
27867
27879
|
useEffect13(() => {
|
|
27868
27880
|
const cfg = configRef.current;
|
|
27869
27881
|
if (!cfg.enabled || !cfg.value || cfg.dataSource !== "api" || !cfg.apiUrl) return;
|
|
27870
|
-
if (
|
|
27871
|
-
const values =
|
|
27882
|
+
if (cfg.isMultiSelect) {
|
|
27883
|
+
const values = Array.isArray(cfg.value) ? cfg.value.map((v) => v.trim()) : [];
|
|
27872
27884
|
const valueExists = values.every((val) => options.some((opt) => opt.value === val));
|
|
27873
27885
|
if (valueExists) return;
|
|
27874
27886
|
} else {
|
|
@@ -27876,19 +27888,19 @@ function useLazyDropdown(config) {
|
|
|
27876
27888
|
if (valueExists) return;
|
|
27877
27889
|
}
|
|
27878
27890
|
fetchValueItem();
|
|
27879
|
-
}, [config.value, config.dataKey, config.apiUrl, config.dataSource
|
|
27891
|
+
}, [JSON.stringify(config.value), config.dataKey, config.apiUrl, config.dataSource]);
|
|
27880
27892
|
const loadMore = useCallback2(() => {
|
|
27881
27893
|
if (!loading && hasMore) {
|
|
27882
27894
|
loadPage(page + 1, searchTerm);
|
|
27883
27895
|
}
|
|
27884
|
-
}, [loading, hasMore, page, searchTerm
|
|
27896
|
+
}, [loading, hasMore, page, searchTerm]);
|
|
27885
27897
|
const search = useCallback2((term) => {
|
|
27886
27898
|
setSearchTerm(term);
|
|
27887
27899
|
if (debounceTimer.current) clearTimeout(debounceTimer.current);
|
|
27888
27900
|
debounceTimer.current = setTimeout(() => {
|
|
27889
27901
|
loadPage(1, term);
|
|
27890
27902
|
}, 300);
|
|
27891
|
-
}, [
|
|
27903
|
+
}, []);
|
|
27892
27904
|
const reset = useCallback2(() => {
|
|
27893
27905
|
setSearchTerm("");
|
|
27894
27906
|
setPage(1);
|
|
@@ -27898,7 +27910,7 @@ function useLazyDropdown(config) {
|
|
|
27898
27910
|
allDataRef.current = config.initialData;
|
|
27899
27911
|
loadPage(1, "");
|
|
27900
27912
|
}
|
|
27901
|
-
}, [config.initialData
|
|
27913
|
+
}, [config.initialData]);
|
|
27902
27914
|
useEffect13(() => {
|
|
27903
27915
|
return () => {
|
|
27904
27916
|
if (debounceTimer.current) clearTimeout(debounceTimer.current);
|
|
@@ -28780,6 +28792,22 @@ function LazyMultiSelectDropdown({
|
|
|
28780
28792
|
const [searchTerm, setSearchTerm] = useState6("");
|
|
28781
28793
|
const dropdownRef = useRef6(null);
|
|
28782
28794
|
const observerTarget = useRef6(null);
|
|
28795
|
+
const ensureUnique = (arr) => {
|
|
28796
|
+
return Array.from(new Set(arr));
|
|
28797
|
+
};
|
|
28798
|
+
const normalizeInput = (value2) => {
|
|
28799
|
+
let arr = [];
|
|
28800
|
+
if (Array.isArray(value2)) {
|
|
28801
|
+
arr = value2;
|
|
28802
|
+
} else if (typeof value2 === "string") {
|
|
28803
|
+
if (!value2.trim()) return [];
|
|
28804
|
+
if (value2.includes(";")) arr = value2.split(";").map((v) => v.trim());
|
|
28805
|
+
else if (value2.includes(",")) arr = value2.split(",").map((v) => v.trim());
|
|
28806
|
+
else arr = [value2.trim()];
|
|
28807
|
+
}
|
|
28808
|
+
return ensureUnique(arr);
|
|
28809
|
+
};
|
|
28810
|
+
const normalizedValue = normalizeInput(value);
|
|
28783
28811
|
const {
|
|
28784
28812
|
options: lazyOptions,
|
|
28785
28813
|
loading,
|
|
@@ -28796,13 +28824,10 @@ function LazyMultiSelectDropdown({
|
|
|
28796
28824
|
dataKey,
|
|
28797
28825
|
dataLabel,
|
|
28798
28826
|
initialData: options || [],
|
|
28799
|
-
value,
|
|
28827
|
+
value: normalizedValue,
|
|
28800
28828
|
axiosInstance,
|
|
28801
28829
|
isMultiSelect: true
|
|
28802
28830
|
});
|
|
28803
|
-
const ensureUnique = (arr) => {
|
|
28804
|
-
return Array.from(new Set(arr));
|
|
28805
|
-
};
|
|
28806
28831
|
const convertOutput = (values) => {
|
|
28807
28832
|
const unique = ensureUnique(values);
|
|
28808
28833
|
switch (outputFormat) {
|
|
@@ -28814,19 +28839,6 @@ function LazyMultiSelectDropdown({
|
|
|
28814
28839
|
return unique;
|
|
28815
28840
|
}
|
|
28816
28841
|
};
|
|
28817
|
-
const normalizeInput = (value2) => {
|
|
28818
|
-
let arr = [];
|
|
28819
|
-
if (Array.isArray(value2)) {
|
|
28820
|
-
arr = value2;
|
|
28821
|
-
} else if (typeof value2 === "string") {
|
|
28822
|
-
if (!value2.trim()) return [];
|
|
28823
|
-
if (value2.includes(";")) arr = value2.split(";").map((v) => v.trim());
|
|
28824
|
-
else if (value2.includes(",")) arr = value2.split(",").map((v) => v.trim());
|
|
28825
|
-
else arr = [value2.trim()];
|
|
28826
|
-
}
|
|
28827
|
-
return ensureUnique(arr);
|
|
28828
|
-
};
|
|
28829
|
-
const normalizedValue = normalizeInput(value);
|
|
28830
28842
|
const selectedOptions = useMemo4(() => {
|
|
28831
28843
|
return lazyOptions.filter((opt) => normalizedValue.includes(opt.value));
|
|
28832
28844
|
}, [lazyOptions, normalizedValue]);
|
|
@@ -29079,7 +29091,7 @@ var dayjs_setup_default = dayjs;
|
|
|
29079
29091
|
// src/lib/table/valueFormatter.ts
|
|
29080
29092
|
var valueFormatter = (value, format2, customFormatters = {}) => {
|
|
29081
29093
|
if (!format2) return value;
|
|
29082
|
-
if (value == null) return "";
|
|
29094
|
+
if (value == null || value === "" || value === void 0) return "-";
|
|
29083
29095
|
if (format2.startsWith("custom:")) {
|
|
29084
29096
|
const key = format2.replace("custom:", "");
|
|
29085
29097
|
return customFormatters[key] ? customFormatters[key](value) : value;
|
|
@@ -29169,19 +29181,20 @@ var sanitizeValue = (val) => {
|
|
|
29169
29181
|
};
|
|
29170
29182
|
var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers = {}, format2, customFormatters = {}) => {
|
|
29171
29183
|
const formattedValue = valueFormatter(value, format2, customFormatters);
|
|
29184
|
+
const rowValue = row?.[rendererProps?.rowField];
|
|
29172
29185
|
switch (renderer) {
|
|
29173
29186
|
/* -------------------- BASIC -------------------- */
|
|
29174
29187
|
case "text":
|
|
29175
|
-
return /* @__PURE__ */ jsx50("span", { children:
|
|
29188
|
+
return /* @__PURE__ */ jsx50("span", { children: rowValue || formattedValue });
|
|
29176
29189
|
case "number":
|
|
29177
|
-
return /* @__PURE__ */ jsx50("span", { className: "tabular-nums text-right", children: valueFormatter(
|
|
29190
|
+
return /* @__PURE__ */ jsx50("span", { className: "tabular-nums text-right", children: valueFormatter(rowValue || value, "number:2") });
|
|
29178
29191
|
case "date":
|
|
29179
|
-
return /* @__PURE__ */ jsx50("span", { children: valueFormatter(
|
|
29192
|
+
return /* @__PURE__ */ jsx50("span", { children: valueFormatter(rowValue || value, format2) });
|
|
29180
29193
|
case "link":
|
|
29181
29194
|
return /* @__PURE__ */ jsx50(
|
|
29182
29195
|
"a",
|
|
29183
29196
|
{
|
|
29184
|
-
href: `${rendererProps?.prefix || ""}${
|
|
29197
|
+
href: `${rendererProps?.prefix || ""}${rowValue || formattedValue}`,
|
|
29185
29198
|
target: "_blank",
|
|
29186
29199
|
rel: "noreferrer",
|
|
29187
29200
|
className: `text-blue-500 underline ${rendererProps?.className || ""}`,
|
|
@@ -29193,7 +29206,7 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29193
29206
|
return /* @__PURE__ */ jsx50("div", { className: "relative", children: /* @__PURE__ */ jsx50(
|
|
29194
29207
|
Image2,
|
|
29195
29208
|
{
|
|
29196
|
-
src:
|
|
29209
|
+
src: rowValue || formattedValue || rendererProps?.fallback || "/placeholder.png",
|
|
29197
29210
|
alt: rendererProps?.alt || "",
|
|
29198
29211
|
width: rendererProps?.width || 40,
|
|
29199
29212
|
height: rendererProps?.height || 40,
|
|
@@ -29253,7 +29266,7 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29253
29266
|
{
|
|
29254
29267
|
onClick: () => rendererProps?.onClick?.(row, formattedValue),
|
|
29255
29268
|
className: `px-2 py-1 rounded text-white bg-blue-600 hover:bg-blue-700 ${rendererProps?.className || ""}`,
|
|
29256
|
-
children:
|
|
29269
|
+
children: rowValue || rendererProps.value || formattedValue
|
|
29257
29270
|
}
|
|
29258
29271
|
);
|
|
29259
29272
|
case "switch":
|
|
@@ -29274,11 +29287,11 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29274
29287
|
"div",
|
|
29275
29288
|
{
|
|
29276
29289
|
className: "bg-blue-600 h-2 rounded-full transition-all",
|
|
29277
|
-
style: { width: `${
|
|
29290
|
+
style: { width: `${rowValue || formattedValue || 0}%` }
|
|
29278
29291
|
}
|
|
29279
29292
|
) });
|
|
29280
29293
|
case "rating": {
|
|
29281
|
-
const stars = Math.round(Number(
|
|
29294
|
+
const stars = Math.round(Number(rowValue || formattedValue) || 0);
|
|
29282
29295
|
return /* @__PURE__ */ jsx50("div", { className: "flex items-center", children: Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ jsx50(
|
|
29283
29296
|
Star,
|
|
29284
29297
|
{
|
|
@@ -29305,7 +29318,7 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29305
29318
|
}
|
|
29306
29319
|
/* -------------------- DEFAULT -------------------- */
|
|
29307
29320
|
default:
|
|
29308
|
-
return /* @__PURE__ */ jsx50("span", { children: formattedValue });
|
|
29321
|
+
return /* @__PURE__ */ jsx50("span", { children: formattedValue || "-" });
|
|
29309
29322
|
}
|
|
29310
29323
|
};
|
|
29311
29324
|
|
|
@@ -29330,7 +29343,7 @@ var useDynamicColumns = (config, customRenderers = {}, customFormatters = {}) =>
|
|
|
29330
29343
|
};
|
|
29331
29344
|
return columnHelper.accessor(accessorFn, {
|
|
29332
29345
|
...col,
|
|
29333
|
-
size: col.size > 0 ? col.size : 180,
|
|
29346
|
+
size: col.size && col.size > 0 ? col.size : 180,
|
|
29334
29347
|
id: col.id ?? accessorKey,
|
|
29335
29348
|
header: col.header,
|
|
29336
29349
|
cell: (info) => {
|
|
@@ -29389,7 +29402,7 @@ function DataTable({
|
|
|
29389
29402
|
...paginationMode === "server" ? {
|
|
29390
29403
|
pagination: {
|
|
29391
29404
|
pageIndex: controlledPageIndex ?? 0,
|
|
29392
|
-
pageSize
|
|
29405
|
+
pageSize: localPageSize
|
|
29393
29406
|
}
|
|
29394
29407
|
} : {}
|
|
29395
29408
|
},
|
|
@@ -29399,7 +29412,7 @@ function DataTable({
|
|
|
29399
29412
|
getFilteredRowModel: getFilteredRowModel(),
|
|
29400
29413
|
getPaginationRowModel: pagination && paginationMode === "client" ? getPaginationRowModel() : void 0,
|
|
29401
29414
|
manualPagination: paginationMode === "server",
|
|
29402
|
-
pageCount: paginationMode === "server" ? Math.ceil(totalRecords /
|
|
29415
|
+
pageCount: paginationMode === "server" ? Math.ceil(totalRecords / localPageSize) : void 0,
|
|
29403
29416
|
...paginationMode === "server" ? {
|
|
29404
29417
|
onPaginationChange: (updater) => {
|
|
29405
29418
|
const prev = table.getState().pagination;
|