@mshuja288/aksuicore 0.4.2 → 0.4.4
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/CHANGELOG.md +13 -0
- package/dist/index.cjs +115 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +115 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/patterns/RecordWorkspace.tsx +116 -10
- package/src/primitives/Dialog.tsx +28 -3
package/dist/index.d.cts
CHANGED
|
@@ -237,7 +237,11 @@ declare function RecordWorkspace<T>({ title, columns, items, rowKey, empty, onAd
|
|
|
237
237
|
importBusy?: boolean;
|
|
238
238
|
/** Column checklist in the side rail. Default true. */
|
|
239
239
|
showColumnPicker?: boolean;
|
|
240
|
-
/**
|
|
240
|
+
/**
|
|
241
|
+
* Persist visible column keys in localStorage under this key.
|
|
242
|
+
* Also persists filter values at `${columnPrefsKey}.filters`.
|
|
243
|
+
* Preview + side-rail open/collapsed use a shared key across all tables (`aksui.workspace.chrome`).
|
|
244
|
+
*/
|
|
241
245
|
columnPrefsKey?: string;
|
|
242
246
|
/** Controlled visible column keys. */
|
|
243
247
|
visibleColumnKeys?: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -237,7 +237,11 @@ declare function RecordWorkspace<T>({ title, columns, items, rowKey, empty, onAd
|
|
|
237
237
|
importBusy?: boolean;
|
|
238
238
|
/** Column checklist in the side rail. Default true. */
|
|
239
239
|
showColumnPicker?: boolean;
|
|
240
|
-
/**
|
|
240
|
+
/**
|
|
241
|
+
* Persist visible column keys in localStorage under this key.
|
|
242
|
+
* Also persists filter values at `${columnPrefsKey}.filters`.
|
|
243
|
+
* Preview + side-rail open/collapsed use a shared key across all tables (`aksui.workspace.chrome`).
|
|
244
|
+
*/
|
|
241
245
|
columnPrefsKey?: string;
|
|
242
246
|
/** Controlled visible column keys. */
|
|
243
247
|
visibleColumnKeys?: string[];
|
package/dist/index.js
CHANGED
|
@@ -412,17 +412,35 @@ function Dialog({
|
|
|
412
412
|
children,
|
|
413
413
|
wide = true
|
|
414
414
|
}) {
|
|
415
|
+
const allowBackdropClose = useRef(false);
|
|
416
|
+
useEffect(() => {
|
|
417
|
+
if (!open) {
|
|
418
|
+
allowBackdropClose.current = false;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
allowBackdropClose.current = false;
|
|
422
|
+
const timer = window.setTimeout(() => {
|
|
423
|
+
allowBackdropClose.current = true;
|
|
424
|
+
}, 0);
|
|
425
|
+
return () => window.clearTimeout(timer);
|
|
426
|
+
}, [open]);
|
|
415
427
|
if (!open) {
|
|
416
428
|
return null;
|
|
417
429
|
}
|
|
418
|
-
|
|
430
|
+
function onBackdropMouseDown(event) {
|
|
431
|
+
if (event.target !== event.currentTarget || !allowBackdropClose.current) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
onClose();
|
|
435
|
+
}
|
|
436
|
+
return /* @__PURE__ */ jsx("div", { className: "dialog-backdrop", onMouseDown: onBackdropMouseDown, children: /* @__PURE__ */ jsxs(
|
|
419
437
|
"div",
|
|
420
438
|
{
|
|
421
439
|
className: wide ? "dialog form-dialog" : "dialog",
|
|
422
440
|
role: "dialog",
|
|
423
441
|
"aria-modal": "true",
|
|
424
442
|
"aria-label": title,
|
|
425
|
-
|
|
443
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
426
444
|
children: [
|
|
427
445
|
/* @__PURE__ */ jsxs("div", { className: "dialog-head", children: [
|
|
428
446
|
/* @__PURE__ */ jsx("h2", { children: title }),
|
|
@@ -875,6 +893,37 @@ var BULK_IMPORT_MODE_OPTIONS = [
|
|
|
875
893
|
function defaultVisibleKeys(columns) {
|
|
876
894
|
return columns.filter((column) => column.defaultVisible !== false).map((column) => column.key);
|
|
877
895
|
}
|
|
896
|
+
var WORKSPACE_CHROME_KEY = "aksui.workspace.chrome";
|
|
897
|
+
function readWorkspaceChrome() {
|
|
898
|
+
if (typeof window === "undefined") {
|
|
899
|
+
return { previewEnabled: false, sideOpen: false };
|
|
900
|
+
}
|
|
901
|
+
try {
|
|
902
|
+
const raw = window.localStorage.getItem(WORKSPACE_CHROME_KEY);
|
|
903
|
+
if (!raw) {
|
|
904
|
+
return { previewEnabled: false, sideOpen: false };
|
|
905
|
+
}
|
|
906
|
+
const parsed = JSON.parse(raw);
|
|
907
|
+
return {
|
|
908
|
+
previewEnabled: Boolean(parsed.previewEnabled),
|
|
909
|
+
sideOpen: Boolean(parsed.sideOpen)
|
|
910
|
+
};
|
|
911
|
+
} catch {
|
|
912
|
+
return { previewEnabled: false, sideOpen: false };
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
function writeWorkspaceChrome(chrome) {
|
|
916
|
+
if (typeof window === "undefined") {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
try {
|
|
920
|
+
window.localStorage.setItem(WORKSPACE_CHROME_KEY, JSON.stringify(chrome));
|
|
921
|
+
} catch {
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
function filtersPrefsKey(columnPrefsKey) {
|
|
925
|
+
return columnPrefsKey ? `${columnPrefsKey}.filters` : void 0;
|
|
926
|
+
}
|
|
878
927
|
function readStoredColumnKeys(prefsKey, fallback, allowed) {
|
|
879
928
|
if (!prefsKey || typeof window === "undefined") {
|
|
880
929
|
return fallback;
|
|
@@ -903,6 +952,45 @@ function writeStoredColumnKeys(prefsKey, keys) {
|
|
|
903
952
|
} catch {
|
|
904
953
|
}
|
|
905
954
|
}
|
|
955
|
+
function readStoredFilters(prefsKey, allowed) {
|
|
956
|
+
if (!prefsKey || typeof window === "undefined") {
|
|
957
|
+
return {};
|
|
958
|
+
}
|
|
959
|
+
try {
|
|
960
|
+
const raw = window.localStorage.getItem(prefsKey);
|
|
961
|
+
if (!raw) {
|
|
962
|
+
return {};
|
|
963
|
+
}
|
|
964
|
+
const parsed = JSON.parse(raw);
|
|
965
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
966
|
+
return {};
|
|
967
|
+
}
|
|
968
|
+
const next = {};
|
|
969
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
970
|
+
if (allowed.has(key) && typeof value === "string" && value.trim()) {
|
|
971
|
+
next[key] = value;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
return next;
|
|
975
|
+
} catch {
|
|
976
|
+
return {};
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
function writeStoredFilters(prefsKey, filters) {
|
|
980
|
+
if (!prefsKey || typeof window === "undefined") {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
try {
|
|
984
|
+
const trimmed = {};
|
|
985
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
986
|
+
if (value.trim()) {
|
|
987
|
+
trimmed[key] = value;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
window.localStorage.setItem(prefsKey, JSON.stringify(trimmed));
|
|
991
|
+
} catch {
|
|
992
|
+
}
|
|
993
|
+
}
|
|
906
994
|
function compareColumnValues(column, left, right) {
|
|
907
995
|
const leftRaw = column.display ? column.display(left) : column.value(left);
|
|
908
996
|
const rightRaw = column.display ? column.display(right) : column.value(right);
|
|
@@ -1026,9 +1114,12 @@ function RecordWorkspace({
|
|
|
1026
1114
|
const [internalVisibleKeys, setInternalVisibleKeys] = useState(
|
|
1027
1115
|
() => readStoredColumnKeys(columnPrefsKey, fallbackKeys, allowedKeys)
|
|
1028
1116
|
);
|
|
1029
|
-
const
|
|
1117
|
+
const filterStorageKey = filtersPrefsKey(columnPrefsKey);
|
|
1118
|
+
const [filters, setFilters] = useState(
|
|
1119
|
+
() => readStoredFilters(filterStorageKey, allowedKeys)
|
|
1120
|
+
);
|
|
1030
1121
|
const [sort, setSort] = useState(null);
|
|
1031
|
-
const [sideOpen, setSideOpen] = useState(
|
|
1122
|
+
const [sideOpen, setSideOpen] = useState(() => readWorkspaceChrome().sideOpen);
|
|
1032
1123
|
const [toolsDrawerOpen, setToolsDrawerOpen] = useState(false);
|
|
1033
1124
|
const [downloadOpen, setDownloadOpen] = useState(false);
|
|
1034
1125
|
const [bulkOpen, setBulkOpen] = useState(false);
|
|
@@ -1037,7 +1128,7 @@ function RecordWorkspace({
|
|
|
1037
1128
|
const [bulkReport, setBulkReport] = useState(null);
|
|
1038
1129
|
const bulkFileInputRef = useRef(null);
|
|
1039
1130
|
const [columnsOpen, setColumnsOpen] = useState(false);
|
|
1040
|
-
const [previewEnabled, setPreviewEnabled] = useState(
|
|
1131
|
+
const [previewEnabled, setPreviewEnabled] = useState(() => readWorkspaceChrome().previewEnabled);
|
|
1041
1132
|
const [previewKey, setPreviewKey] = useState(null);
|
|
1042
1133
|
const [tooltip, setTooltip] = useState(null);
|
|
1043
1134
|
const [pageSize, setPageSize] = useState("15");
|
|
@@ -1052,6 +1143,9 @@ function RecordWorkspace({
|
|
|
1052
1143
|
}
|
|
1053
1144
|
setInternalVisibleKeys(readStoredColumnKeys(columnPrefsKey, fallbackKeys, allowedKeys));
|
|
1054
1145
|
}, [allowedKeys, columnPrefsKey, fallbackKeys, isControlled]);
|
|
1146
|
+
useEffect(() => {
|
|
1147
|
+
setFilters(readStoredFilters(filtersPrefsKey(columnPrefsKey), allowedKeys));
|
|
1148
|
+
}, [allowedKeys, columnPrefsKey]);
|
|
1055
1149
|
const resolvedVisibleKeys = useMemo(() => {
|
|
1056
1150
|
const source = isControlled ? visibleColumnKeys : internalVisibleKeys;
|
|
1057
1151
|
const filtered2 = source.filter((key) => allowedKeys.has(key));
|
|
@@ -1212,13 +1306,22 @@ function RecordWorkspace({
|
|
|
1212
1306
|
}
|
|
1213
1307
|
const previewTitle = previewItem && visibleColumns[0] ? cellText(visibleColumns[0], previewItem) : null;
|
|
1214
1308
|
function changeFilter(key, value) {
|
|
1215
|
-
setFilters((current) =>
|
|
1309
|
+
setFilters((current) => {
|
|
1310
|
+
const next = { ...current, [key]: value };
|
|
1311
|
+
writeStoredFilters(filterStorageKey, next);
|
|
1312
|
+
return next;
|
|
1313
|
+
});
|
|
1216
1314
|
setPage(1);
|
|
1217
1315
|
}
|
|
1218
1316
|
function clearFilters() {
|
|
1219
1317
|
setFilters({});
|
|
1318
|
+
writeStoredFilters(filterStorageKey, {});
|
|
1220
1319
|
setPage(1);
|
|
1221
1320
|
}
|
|
1321
|
+
function setSideOpenValue(open) {
|
|
1322
|
+
setSideOpen(open);
|
|
1323
|
+
writeWorkspaceChrome({ previewEnabled, sideOpen: open });
|
|
1324
|
+
}
|
|
1222
1325
|
function toggleSort(column) {
|
|
1223
1326
|
if (column.sortable === false) {
|
|
1224
1327
|
return;
|
|
@@ -1236,6 +1339,7 @@ function RecordWorkspace({
|
|
|
1236
1339
|
}
|
|
1237
1340
|
function setPreviewEnabledValue(enabled) {
|
|
1238
1341
|
setPreviewEnabled(enabled);
|
|
1342
|
+
writeWorkspaceChrome({ previewEnabled: enabled, sideOpen });
|
|
1239
1343
|
setTooltip(null);
|
|
1240
1344
|
if (!enabled) {
|
|
1241
1345
|
setPreviewKey(null);
|
|
@@ -1296,7 +1400,7 @@ function RecordWorkspace({
|
|
|
1296
1400
|
title: "Columns",
|
|
1297
1401
|
"aria-label": "Columns",
|
|
1298
1402
|
onClick: () => {
|
|
1299
|
-
|
|
1403
|
+
setSideOpenValue(true);
|
|
1300
1404
|
setColumnsOpen(true);
|
|
1301
1405
|
},
|
|
1302
1406
|
children: [
|
|
@@ -1314,7 +1418,7 @@ function RecordWorkspace({
|
|
|
1314
1418
|
"aria-label": "Download",
|
|
1315
1419
|
disabled: downloadBusy,
|
|
1316
1420
|
onClick: () => {
|
|
1317
|
-
|
|
1421
|
+
setSideOpenValue(true);
|
|
1318
1422
|
setDownloadOpen(true);
|
|
1319
1423
|
},
|
|
1320
1424
|
children: /* @__PURE__ */ jsx(DownloadIcon, {})
|
|
@@ -1329,7 +1433,7 @@ function RecordWorkspace({
|
|
|
1329
1433
|
"aria-label": "Bulk entry",
|
|
1330
1434
|
disabled: importBusy,
|
|
1331
1435
|
onClick: () => {
|
|
1332
|
-
|
|
1436
|
+
setSideOpenValue(true);
|
|
1333
1437
|
setBulkOpen(true);
|
|
1334
1438
|
},
|
|
1335
1439
|
children: /* @__PURE__ */ jsx(UploadIcon, {})
|
|
@@ -1342,7 +1446,7 @@ function RecordWorkspace({
|
|
|
1342
1446
|
className: "ghost side-rail-icon",
|
|
1343
1447
|
title: "Show filters",
|
|
1344
1448
|
"aria-label": "Show filters",
|
|
1345
|
-
onClick: () =>
|
|
1449
|
+
onClick: () => setSideOpenValue(true),
|
|
1346
1450
|
children: [
|
|
1347
1451
|
/* @__PURE__ */ jsx(FilterIcon, {}),
|
|
1348
1452
|
activeFilterCount > 0 ? /* @__PURE__ */ jsx("span", { className: "filter-badge", children: activeFilterCount }) : null
|
|
@@ -1731,7 +1835,7 @@ function RecordWorkspace({
|
|
|
1731
1835
|
className: "ghost side-rail-toggle",
|
|
1732
1836
|
"aria-expanded": sideOpen,
|
|
1733
1837
|
title: sideOpen ? "Collapse" : "Expand",
|
|
1734
|
-
onClick: () =>
|
|
1838
|
+
onClick: () => setSideOpenValue(!sideOpen),
|
|
1735
1839
|
children: [
|
|
1736
1840
|
/* @__PURE__ */ jsx(ChevronIcon, { open: sideOpen }),
|
|
1737
1841
|
sideOpen ? /* @__PURE__ */ jsx("span", { children: "Collapse" }) : null
|