@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.js
CHANGED
|
@@ -27891,7 +27891,7 @@ function useLazyDropdown(config) {
|
|
|
27891
27891
|
if (!configRef.current.apiUrl) return [];
|
|
27892
27892
|
const limit = PAGE_SIZE;
|
|
27893
27893
|
const params = { page: pageNum, limit };
|
|
27894
|
-
if (term) params[configRef.current.dataLabel
|
|
27894
|
+
if (term) params[configRef.current.dataLabel ? `${configRef.current.dataLabel}[ilike]` : "search[ilike]"] = term;
|
|
27895
27895
|
const axiosClient = configRef.current.axiosInstance ?? import_axios.default;
|
|
27896
27896
|
const res = await axiosClient.get(configRef.current.apiUrl, {
|
|
27897
27897
|
params,
|
|
@@ -27945,8 +27945,20 @@ function useLazyDropdown(config) {
|
|
|
27945
27945
|
try {
|
|
27946
27946
|
setLoading(true);
|
|
27947
27947
|
const axiosClient = configRef.current.axiosInstance ?? import_axios.default;
|
|
27948
|
+
let params = {
|
|
27949
|
+
[configRef.current.dataKey]: configRef.current.value
|
|
27950
|
+
};
|
|
27951
|
+
if (Array.isArray(configRef.current.value)) {
|
|
27952
|
+
if (configRef.current.value.length === 0) {
|
|
27953
|
+
setLoading(false);
|
|
27954
|
+
return;
|
|
27955
|
+
}
|
|
27956
|
+
params = {
|
|
27957
|
+
[`${configRef.current.dataKey}[in]`]: configRef.current.value.join(",")
|
|
27958
|
+
};
|
|
27959
|
+
}
|
|
27948
27960
|
const res = await axiosClient.get(configRef.current.apiUrl, {
|
|
27949
|
-
params
|
|
27961
|
+
params,
|
|
27950
27962
|
withCredentials: true
|
|
27951
27963
|
});
|
|
27952
27964
|
if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
|
|
@@ -27962,8 +27974,8 @@ function useLazyDropdown(config) {
|
|
|
27962
27974
|
(0, import_react19.useEffect)(() => {
|
|
27963
27975
|
const cfg = configRef.current;
|
|
27964
27976
|
if (!cfg.enabled || !cfg.value || cfg.dataSource !== "api" || !cfg.apiUrl) return;
|
|
27965
|
-
if (
|
|
27966
|
-
const values =
|
|
27977
|
+
if (cfg.isMultiSelect) {
|
|
27978
|
+
const values = Array.isArray(cfg.value) ? cfg.value.map((v) => v.trim()) : [];
|
|
27967
27979
|
const valueExists = values.every((val) => options.some((opt) => opt.value === val));
|
|
27968
27980
|
if (valueExists) return;
|
|
27969
27981
|
} else {
|
|
@@ -27971,19 +27983,19 @@ function useLazyDropdown(config) {
|
|
|
27971
27983
|
if (valueExists) return;
|
|
27972
27984
|
}
|
|
27973
27985
|
fetchValueItem();
|
|
27974
|
-
}, [config.value, config.dataKey, config.apiUrl, config.dataSource
|
|
27986
|
+
}, [JSON.stringify(config.value), config.dataKey, config.apiUrl, config.dataSource]);
|
|
27975
27987
|
const loadMore = (0, import_react19.useCallback)(() => {
|
|
27976
27988
|
if (!loading && hasMore) {
|
|
27977
27989
|
loadPage(page + 1, searchTerm);
|
|
27978
27990
|
}
|
|
27979
|
-
}, [loading, hasMore, page, searchTerm
|
|
27991
|
+
}, [loading, hasMore, page, searchTerm]);
|
|
27980
27992
|
const search = (0, import_react19.useCallback)((term) => {
|
|
27981
27993
|
setSearchTerm(term);
|
|
27982
27994
|
if (debounceTimer.current) clearTimeout(debounceTimer.current);
|
|
27983
27995
|
debounceTimer.current = setTimeout(() => {
|
|
27984
27996
|
loadPage(1, term);
|
|
27985
27997
|
}, 300);
|
|
27986
|
-
}, [
|
|
27998
|
+
}, []);
|
|
27987
27999
|
const reset = (0, import_react19.useCallback)(() => {
|
|
27988
28000
|
setSearchTerm("");
|
|
27989
28001
|
setPage(1);
|
|
@@ -27993,7 +28005,7 @@ function useLazyDropdown(config) {
|
|
|
27993
28005
|
allDataRef.current = config.initialData;
|
|
27994
28006
|
loadPage(1, "");
|
|
27995
28007
|
}
|
|
27996
|
-
}, [config.initialData
|
|
28008
|
+
}, [config.initialData]);
|
|
27997
28009
|
(0, import_react19.useEffect)(() => {
|
|
27998
28010
|
return () => {
|
|
27999
28011
|
if (debounceTimer.current) clearTimeout(debounceTimer.current);
|
|
@@ -28875,6 +28887,22 @@ function LazyMultiSelectDropdown({
|
|
|
28875
28887
|
const [searchTerm, setSearchTerm] = (0, import_react29.useState)("");
|
|
28876
28888
|
const dropdownRef = (0, import_react29.useRef)(null);
|
|
28877
28889
|
const observerTarget = (0, import_react29.useRef)(null);
|
|
28890
|
+
const ensureUnique = (arr) => {
|
|
28891
|
+
return Array.from(new Set(arr));
|
|
28892
|
+
};
|
|
28893
|
+
const normalizeInput = (value2) => {
|
|
28894
|
+
let arr = [];
|
|
28895
|
+
if (Array.isArray(value2)) {
|
|
28896
|
+
arr = value2;
|
|
28897
|
+
} else if (typeof value2 === "string") {
|
|
28898
|
+
if (!value2.trim()) return [];
|
|
28899
|
+
if (value2.includes(";")) arr = value2.split(";").map((v) => v.trim());
|
|
28900
|
+
else if (value2.includes(",")) arr = value2.split(",").map((v) => v.trim());
|
|
28901
|
+
else arr = [value2.trim()];
|
|
28902
|
+
}
|
|
28903
|
+
return ensureUnique(arr);
|
|
28904
|
+
};
|
|
28905
|
+
const normalizedValue = normalizeInput(value);
|
|
28878
28906
|
const {
|
|
28879
28907
|
options: lazyOptions,
|
|
28880
28908
|
loading,
|
|
@@ -28891,13 +28919,10 @@ function LazyMultiSelectDropdown({
|
|
|
28891
28919
|
dataKey,
|
|
28892
28920
|
dataLabel,
|
|
28893
28921
|
initialData: options || [],
|
|
28894
|
-
value,
|
|
28922
|
+
value: normalizedValue,
|
|
28895
28923
|
axiosInstance,
|
|
28896
28924
|
isMultiSelect: true
|
|
28897
28925
|
});
|
|
28898
|
-
const ensureUnique = (arr) => {
|
|
28899
|
-
return Array.from(new Set(arr));
|
|
28900
|
-
};
|
|
28901
28926
|
const convertOutput = (values) => {
|
|
28902
28927
|
const unique = ensureUnique(values);
|
|
28903
28928
|
switch (outputFormat) {
|
|
@@ -28909,19 +28934,6 @@ function LazyMultiSelectDropdown({
|
|
|
28909
28934
|
return unique;
|
|
28910
28935
|
}
|
|
28911
28936
|
};
|
|
28912
|
-
const normalizeInput = (value2) => {
|
|
28913
|
-
let arr = [];
|
|
28914
|
-
if (Array.isArray(value2)) {
|
|
28915
|
-
arr = value2;
|
|
28916
|
-
} else if (typeof value2 === "string") {
|
|
28917
|
-
if (!value2.trim()) return [];
|
|
28918
|
-
if (value2.includes(";")) arr = value2.split(";").map((v) => v.trim());
|
|
28919
|
-
else if (value2.includes(",")) arr = value2.split(",").map((v) => v.trim());
|
|
28920
|
-
else arr = [value2.trim()];
|
|
28921
|
-
}
|
|
28922
|
-
return ensureUnique(arr);
|
|
28923
|
-
};
|
|
28924
|
-
const normalizedValue = normalizeInput(value);
|
|
28925
28937
|
const selectedOptions = (0, import_react29.useMemo)(() => {
|
|
28926
28938
|
return lazyOptions.filter((opt) => normalizedValue.includes(opt.value));
|
|
28927
28939
|
}, [lazyOptions, normalizedValue]);
|
|
@@ -29168,7 +29180,7 @@ var dayjs_setup_default = import_dayjs.default;
|
|
|
29168
29180
|
// src/lib/table/valueFormatter.ts
|
|
29169
29181
|
var valueFormatter = (value, format2, customFormatters = {}) => {
|
|
29170
29182
|
if (!format2) return value;
|
|
29171
|
-
if (value == null) return "";
|
|
29183
|
+
if (value == null || value === "" || value === void 0) return "-";
|
|
29172
29184
|
if (format2.startsWith("custom:")) {
|
|
29173
29185
|
const key = format2.replace("custom:", "");
|
|
29174
29186
|
return customFormatters[key] ? customFormatters[key](value) : value;
|
|
@@ -29258,19 +29270,20 @@ var sanitizeValue = (val) => {
|
|
|
29258
29270
|
};
|
|
29259
29271
|
var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers = {}, format2, customFormatters = {}) => {
|
|
29260
29272
|
const formattedValue = valueFormatter(value, format2, customFormatters);
|
|
29273
|
+
const rowValue = row?.[rendererProps?.rowField];
|
|
29261
29274
|
switch (renderer) {
|
|
29262
29275
|
/* -------------------- BASIC -------------------- */
|
|
29263
29276
|
case "text":
|
|
29264
|
-
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { children:
|
|
29277
|
+
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { children: rowValue || formattedValue });
|
|
29265
29278
|
case "number":
|
|
29266
|
-
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { className: "tabular-nums text-right", children: valueFormatter(
|
|
29279
|
+
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { className: "tabular-nums text-right", children: valueFormatter(rowValue || value, "number:2") });
|
|
29267
29280
|
case "date":
|
|
29268
|
-
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { children: valueFormatter(
|
|
29281
|
+
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { children: valueFormatter(rowValue || value, format2) });
|
|
29269
29282
|
case "link":
|
|
29270
29283
|
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
|
|
29271
29284
|
"a",
|
|
29272
29285
|
{
|
|
29273
|
-
href: `${rendererProps?.prefix || ""}${
|
|
29286
|
+
href: `${rendererProps?.prefix || ""}${rowValue || formattedValue}`,
|
|
29274
29287
|
target: "_blank",
|
|
29275
29288
|
rel: "noreferrer",
|
|
29276
29289
|
className: `text-blue-500 underline ${rendererProps?.className || ""}`,
|
|
@@ -29282,7 +29295,7 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29282
29295
|
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className: "relative", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
|
|
29283
29296
|
import_image3.default,
|
|
29284
29297
|
{
|
|
29285
|
-
src:
|
|
29298
|
+
src: rowValue || formattedValue || rendererProps?.fallback || "/placeholder.png",
|
|
29286
29299
|
alt: rendererProps?.alt || "",
|
|
29287
29300
|
width: rendererProps?.width || 40,
|
|
29288
29301
|
height: rendererProps?.height || 40,
|
|
@@ -29342,7 +29355,7 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29342
29355
|
{
|
|
29343
29356
|
onClick: () => rendererProps?.onClick?.(row, formattedValue),
|
|
29344
29357
|
className: `px-2 py-1 rounded text-white bg-blue-600 hover:bg-blue-700 ${rendererProps?.className || ""}`,
|
|
29345
|
-
children:
|
|
29358
|
+
children: rowValue || rendererProps.value || formattedValue
|
|
29346
29359
|
}
|
|
29347
29360
|
);
|
|
29348
29361
|
case "switch":
|
|
@@ -29363,11 +29376,11 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29363
29376
|
"div",
|
|
29364
29377
|
{
|
|
29365
29378
|
className: "bg-blue-600 h-2 rounded-full transition-all",
|
|
29366
|
-
style: { width: `${
|
|
29379
|
+
style: { width: `${rowValue || formattedValue || 0}%` }
|
|
29367
29380
|
}
|
|
29368
29381
|
) });
|
|
29369
29382
|
case "rating": {
|
|
29370
|
-
const stars = Math.round(Number(
|
|
29383
|
+
const stars = Math.round(Number(rowValue || formattedValue) || 0);
|
|
29371
29384
|
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className: "flex items-center", children: Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
|
|
29372
29385
|
Star,
|
|
29373
29386
|
{
|
|
@@ -29394,7 +29407,7 @@ var cellRendererFactory = (renderer, rendererProps, value, row, customRenderers
|
|
|
29394
29407
|
}
|
|
29395
29408
|
/* -------------------- DEFAULT -------------------- */
|
|
29396
29409
|
default:
|
|
29397
|
-
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { children: formattedValue });
|
|
29410
|
+
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("span", { children: formattedValue || "-" });
|
|
29398
29411
|
}
|
|
29399
29412
|
};
|
|
29400
29413
|
|
|
@@ -29419,7 +29432,7 @@ var useDynamicColumns = (config, customRenderers = {}, customFormatters = {}) =>
|
|
|
29419
29432
|
};
|
|
29420
29433
|
return columnHelper.accessor(accessorFn, {
|
|
29421
29434
|
...col,
|
|
29422
|
-
size: col.size > 0 ? col.size : 180,
|
|
29435
|
+
size: col.size && col.size > 0 ? col.size : 180,
|
|
29423
29436
|
id: col.id ?? accessorKey,
|
|
29424
29437
|
header: col.header,
|
|
29425
29438
|
cell: (info) => {
|
|
@@ -29478,7 +29491,7 @@ function DataTable({
|
|
|
29478
29491
|
...paginationMode === "server" ? {
|
|
29479
29492
|
pagination: {
|
|
29480
29493
|
pageIndex: controlledPageIndex ?? 0,
|
|
29481
|
-
pageSize
|
|
29494
|
+
pageSize: localPageSize
|
|
29482
29495
|
}
|
|
29483
29496
|
} : {}
|
|
29484
29497
|
},
|
|
@@ -29488,7 +29501,7 @@ function DataTable({
|
|
|
29488
29501
|
getFilteredRowModel: (0, import_react_table2.getFilteredRowModel)(),
|
|
29489
29502
|
getPaginationRowModel: pagination && paginationMode === "client" ? (0, import_react_table2.getPaginationRowModel)() : void 0,
|
|
29490
29503
|
manualPagination: paginationMode === "server",
|
|
29491
|
-
pageCount: paginationMode === "server" ? Math.ceil(totalRecords /
|
|
29504
|
+
pageCount: paginationMode === "server" ? Math.ceil(totalRecords / localPageSize) : void 0,
|
|
29492
29505
|
...paginationMode === "server" ? {
|
|
29493
29506
|
onPaginationChange: (updater) => {
|
|
29494
29507
|
const prev = table.getState().pagination;
|