wcz-layout
Version:
497 lines (496 loc) • 15.9 kB
JavaScript
import { t as DialogsContext } from "./DialogsContext-DLqA8RJ_.mjs";
import { c } from "react/compiler-runtime";
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Typography, useEventCallback } from "@mui/material";
import dayjs from "dayjs";
import { useContext } from "react";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
import { formatForDisplay } from "@tanstack/react-hotkeys";
import { aggregationFn_count, aggregationFn_extent, aggregationFn_first, aggregationFn_last, aggregationFn_max, aggregationFn_mean, aggregationFn_median, aggregationFn_min, aggregationFn_sum, aggregationFn_unique, aggregationFn_uniqueCount, createExpandedRowModel, createFacetedMinMaxValues, createFacetedRowModel, createFacetedUniqueValues, createFilteredRowModel, createGroupedRowModel, createPaginatedRowModel, createSortedRowModel, createTableHookContexts, filterFn_arrHas, filterFn_arrIncludes, filterFn_arrIncludesAll, filterFn_arrIncludesSome, filterFn_between, filterFn_betweenInclusive, filterFn_empty, filterFn_endsWith, filterFn_equals, filterFn_equalsString, filterFn_equalsStringSensitive, filterFn_greaterThan, filterFn_greaterThanOrEqualTo, filterFn_inDateRange, filterFn_inNumberRange, filterFn_includesString, filterFn_includesStringSensitive, filterFn_lessThan, filterFn_lessThanOrEqualTo, filterFn_notEmpty, filterFn_startsWith, filterFn_weakEquals, metaHelper, sortFn_alphanumeric, sortFn_alphanumericCaseSensitive, sortFn_basic, sortFn_datetime, sortFn_text, sortFn_textCaseSensitive, stockFeatures, tableFeatures } from "@tanstack/react-table";
//#region src/hooks/useDialogs.tsx
function AlertDialog(t0) {
const $ = c(23);
if ($[0] !== "40306a49a490b7e6c84c5f6c47439f8c7b6ee1f8cf1389e00101b53c362d1875") {
for (let $i = 0; $i < 23; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
$[0] = "40306a49a490b7e6c84c5f6c47439f8c7b6ee1f8cf1389e00101b53c362d1875";
}
const { open, payload, onClose } = t0;
const { t } = useTranslation();
let t1;
if ($[1] !== onClose) {
t1 = () => onClose();
$[1] = onClose;
$[2] = t1;
} else t1 = $[2];
let t2;
if ($[3] !== payload.title || $[4] !== t) {
t2 = payload.title ?? t("Layout.Dialog.Alert");
$[3] = payload.title;
$[4] = t;
$[5] = t2;
} else t2 = $[5];
let t3;
if ($[6] !== t2) {
t3 = /* @__PURE__ */ jsx(DialogTitle, { children: t2 });
$[6] = t2;
$[7] = t3;
} else t3 = $[7];
let t4;
if ($[8] !== payload.message) {
t4 = /* @__PURE__ */ jsx(DialogContent, { children: payload.message });
$[8] = payload.message;
$[9] = t4;
} else t4 = $[9];
let t5;
if ($[10] !== onClose) {
t5 = () => onClose();
$[10] = onClose;
$[11] = t5;
} else t5 = $[11];
let t6;
if ($[12] !== t) {
t6 = t("Layout.Dialog.Confirm");
$[12] = t;
$[13] = t6;
} else t6 = $[13];
let t7;
if ($[14] !== t5 || $[15] !== t6) {
t7 = /* @__PURE__ */ jsx(DialogActions, { children: /* @__PURE__ */ jsx(Button, {
onClick: t5,
autoFocus: true,
children: t6
}) });
$[14] = t5;
$[15] = t6;
$[16] = t7;
} else t7 = $[16];
let t8;
if ($[17] !== open || $[18] !== t1 || $[19] !== t3 || $[20] !== t4 || $[21] !== t7) {
t8 = /* @__PURE__ */ jsxs(Dialog, {
maxWidth: "xs",
fullWidth: true,
open,
onClose: t1,
disableRestoreFocus: true,
children: [
t3,
t4,
t7
]
});
$[17] = open;
$[18] = t1;
$[19] = t3;
$[20] = t4;
$[21] = t7;
$[22] = t8;
} else t8 = $[22];
return t8;
}
function ConfirmDialog(t0) {
const $ = c(34);
if ($[0] !== "40306a49a490b7e6c84c5f6c47439f8c7b6ee1f8cf1389e00101b53c362d1875") {
for (let $i = 0; $i < 34; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
$[0] = "40306a49a490b7e6c84c5f6c47439f8c7b6ee1f8cf1389e00101b53c362d1875";
}
const { open, payload, onClose } = t0;
const { t } = useTranslation();
let t1;
if ($[1] !== onClose) {
t1 = () => onClose(false);
$[1] = onClose;
$[2] = t1;
} else t1 = $[2];
let t2;
if ($[3] !== payload.title || $[4] !== t) {
t2 = payload.title ?? t("Layout.Dialog.Confirm");
$[3] = payload.title;
$[4] = t;
$[5] = t2;
} else t2 = $[5];
let t3;
if ($[6] !== t2) {
t3 = /* @__PURE__ */ jsx(DialogTitle, { children: t2 });
$[6] = t2;
$[7] = t3;
} else t3 = $[7];
let t4;
if ($[8] !== payload.message) {
t4 = /* @__PURE__ */ jsx(DialogContent, { children: payload.message });
$[8] = payload.message;
$[9] = t4;
} else t4 = $[9];
let t5;
if ($[10] !== onClose) {
t5 = () => onClose(false);
$[10] = onClose;
$[11] = t5;
} else t5 = $[11];
let t6;
if ($[12] !== payload.cancelText || $[13] !== t) {
t6 = payload.cancelText ?? t("Layout.Dialog.Cancel");
$[12] = payload.cancelText;
$[13] = t;
$[14] = t6;
} else t6 = $[14];
let t7;
if ($[15] !== t5 || $[16] !== t6) {
t7 = /* @__PURE__ */ jsx(Button, {
onClick: t5,
children: t6
});
$[15] = t5;
$[16] = t6;
$[17] = t7;
} else t7 = $[17];
let t8;
if ($[18] !== onClose) {
t8 = () => onClose(true);
$[18] = onClose;
$[19] = t8;
} else t8 = $[19];
let t9;
if ($[20] !== t) {
t9 = t("Layout.Dialog.Confirm");
$[20] = t;
$[21] = t9;
} else t9 = $[21];
let t10;
if ($[22] !== t8 || $[23] !== t9) {
t10 = /* @__PURE__ */ jsx(Button, {
onClick: t8,
autoFocus: true,
children: t9
});
$[22] = t8;
$[23] = t9;
$[24] = t10;
} else t10 = $[24];
let t11;
if ($[25] !== t10 || $[26] !== t7) {
t11 = /* @__PURE__ */ jsxs(DialogActions, { children: [t7, t10] });
$[25] = t10;
$[26] = t7;
$[27] = t11;
} else t11 = $[27];
let t12;
if ($[28] !== open || $[29] !== t1 || $[30] !== t11 || $[31] !== t3 || $[32] !== t4) {
t12 = /* @__PURE__ */ jsxs(Dialog, {
maxWidth: "xs",
fullWidth: true,
open,
onClose: t1,
disableRestoreFocus: true,
children: [
t3,
t4,
t11
]
});
$[28] = open;
$[29] = t1;
$[30] = t11;
$[31] = t3;
$[32] = t4;
$[33] = t12;
} else t12 = $[33];
return t12;
}
function useDialogs() {
const $ = c(10);
if ($[0] !== "40306a49a490b7e6c84c5f6c47439f8c7b6ee1f8cf1389e00101b53c362d1875") {
for (let $i = 0; $i < 10; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
$[0] = "40306a49a490b7e6c84c5f6c47439f8c7b6ee1f8cf1389e00101b53c362d1875";
}
const { open, close } = useContext(DialogsContext);
let t0;
if ($[1] !== open) {
t0 = (message, t1) => {
const { ...options } = t1 === void 0 ? {} : t1;
return open(AlertDialog, {
...options,
message
});
};
$[1] = open;
$[2] = t0;
} else t0 = $[2];
const alert = useEventCallback(t0);
let t1;
if ($[3] !== open) {
t1 = (message_0, t2) => {
const { ...options_0 } = t2 === void 0 ? {} : t2;
return open(ConfirmDialog, {
...options_0,
message: message_0
});
};
$[3] = open;
$[4] = t1;
} else t1 = $[4];
const confirm = useEventCallback(t1);
let t2;
if ($[5] !== alert || $[6] !== close || $[7] !== confirm || $[8] !== open) {
t2 = {
alert,
confirm,
open,
close
};
$[5] = alert;
$[6] = close;
$[7] = confirm;
$[8] = open;
$[9] = t2;
} else t2 = $[9];
return t2;
}
//#endregion
//#region src/components/table/utils.ts
const shortcutLabel = (label, hotkey) => `${label} (${formatForDisplay(hotkey)})`;
const columnLabel = (column) => {
const meta = column.columnDef.meta;
if (meta?.label) return meta.label;
return typeof column.columnDef.header === "string" ? column.columnDef.header : column.id;
};
const hasColumnLabel = (column) => Boolean(column.columnDef.meta?.label) || typeof column.columnDef.header === "string";
const columnAlign = (column) => column.columnDef.meta?.align ?? (hasColumnLabel(column) ? "left" : "center");
const moveColumn = (column, delta) => {
const { table } = column;
const current = table.atoms.columnOrder.get();
const order = current.length ? [...current] : table.getAllLeafColumns().map(({ id }) => id);
const from = order.indexOf(column.id);
const to = from + delta;
if (from < 0 || to < 0 || to >= order.length) return;
order.splice(to, 0, ...order.splice(from, 1));
table.setColumnOrder(order);
};
const pinnedSx = (column, isHeader = false) => {
const pinned = column.getIsPinned();
if (!pinned) return {};
return {
position: "sticky",
zIndex: isHeader ? 4 : 2,
insetInlineStart: pinned === "start" ? column.getStart("start") : void 0,
insetInlineEnd: pinned === "end" ? column.getAfter("end") : void 0,
bgcolor: "background.paper",
...!isHeader && {
".MuiTableRow-root:hover > &": { backgroundImage: (theme) => `linear-gradient(${theme.palette.action.hover}, ${theme.palette.action.hover})` },
".MuiTableRow-root.Mui-selected > &": { backgroundImage: (theme) => `linear-gradient(${theme.palette.action.selected}, ${theme.palette.action.selected})` }
},
...pinned === "start" && column.getIsLastColumn("start") && {
borderInlineEnd: 1,
borderInlineEndStyle: "solid",
borderColor: "divider"
},
...pinned === "end" && column.getIsFirstColumn("end") && {
borderInlineStart: 1,
borderInlineStartStyle: "solid",
borderColor: "divider"
}
};
};
const cellSelectionSx = (cell) => {
if (!cell.getIsSelected()) return {};
const edges = cell.getSelectionEdges();
const outline = (theme) => [
edges.top && `inset 0 2px 0 0 ${theme.palette.primary.main}`,
edges.bottom && `inset 0 -2px 0 0 ${theme.palette.primary.main}`,
edges.left && `inset 2px 0 0 0 ${theme.palette.primary.main}`,
edges.right && `inset -2px 0 0 0 ${theme.palette.primary.main}`
].filter(Boolean).join(", ") || "none";
return {
backgroundImage: (theme) => `linear-gradient(${theme.palette.action.selected}, ${theme.palette.action.selected})`,
boxShadow: outline
};
};
/** Spreadsheet TSV quoting, so a cell holding a tab or a newline stays one cell. */
const quoteTsv = (text) => /["\t\n\r]/.test(text) ? `"${text.replaceAll("\"", "\"\"")}"` : text;
const toClipboardValue = (value) => {
if (value == null) return "";
if (typeof value === "string") return quoteTsv(value);
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return quoteTsv(String(value));
if (value instanceof Date) return quoteTsv(value.toISOString());
return quoteTsv(JSON.stringify(value) ?? "");
};
/**
* Serializes `table.getSelectedCellRangesData()` as TSV, which is what Excel,
* Google Sheets and LibreOffice all paste as a grid. Disjoint selection regions
* are separated by a blank line.
*/
const toClipboardText = (regions) => regions.map((rows) => rows.map((cells) => cells.map(toClipboardValue).join(" ")).join("\n")).join("\n\n");
//#endregion
//#region src/components/table/formatValue.ts
const formatValue = (value, dateFormat = "L LT") => {
if (value === null || value === void 0) return "";
if (value instanceof Date) return dayjs(value).format(dateFormat);
if (typeof value === "string") return value;
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return value.toString();
return JSON.stringify(value) ?? "";
};
//#endregion
//#region src/components/table/context.ts
const layoutTableFeatures = tableFeatures({
...stockFeatures,
columnMeta: metaHelper(),
filteredRowModel: createFilteredRowModel(),
sortedRowModel: createSortedRowModel(),
paginatedRowModel: createPaginatedRowModel(),
expandedRowModel: createExpandedRowModel(),
groupedRowModel: createGroupedRowModel(),
facetedRowModel: createFacetedRowModel(),
facetedUniqueValues: createFacetedUniqueValues(),
facetedMinMaxValues: createFacetedMinMaxValues(),
filterFns: {
arrHas: filterFn_arrHas,
arrIncludes: filterFn_arrIncludes,
arrIncludesAll: filterFn_arrIncludesAll,
arrIncludesSome: filterFn_arrIncludesSome,
between: filterFn_between,
betweenInclusive: filterFn_betweenInclusive,
empty: filterFn_empty,
endsWith: filterFn_endsWith,
equals: filterFn_equals,
equalsString: filterFn_equalsString,
equalsStringSensitive: filterFn_equalsStringSensitive,
greaterThan: filterFn_greaterThan,
greaterThanOrEqualTo: filterFn_greaterThanOrEqualTo,
inDateRange: filterFn_inDateRange,
inNumberRange: filterFn_inNumberRange,
includesString: filterFn_includesString,
includesStringSensitive: filterFn_includesStringSensitive,
lessThan: filterFn_lessThan,
lessThanOrEqualTo: filterFn_lessThanOrEqualTo,
notEmpty: filterFn_notEmpty,
startsWith: filterFn_startsWith,
weakEquals: filterFn_weakEquals
},
sortFns: {
alphanumeric: sortFn_alphanumeric,
alphanumericCaseSensitive: sortFn_alphanumericCaseSensitive,
basic: sortFn_basic,
datetime: sortFn_datetime,
text: sortFn_text,
textCaseSensitive: sortFn_textCaseSensitive
},
aggregationFns: {
sum: aggregationFn_sum,
min: aggregationFn_min,
max: aggregationFn_max,
extent: aggregationFn_extent,
mean: aggregationFn_mean,
median: aggregationFn_median,
unique: aggregationFn_unique,
uniqueCount: aggregationFn_uniqueCount,
count: aggregationFn_count,
first: aggregationFn_first,
last: aggregationFn_last
}
});
const { tableContext, cellContext, headerContext, useTableContext, useCellContext, useHeaderContext } = createTableHookContexts();
//#endregion
//#region src/components/table/cells/formatters/AggregatedCell.tsx
const AggregatedCell = (t0) => {
const $ = c(30);
if ($[0] !== "4277c795cc5aa79cb8c9da3c17c3eca0172b2cb25ae31116d08eb0a5b925c1d5") {
for (let $i = 0; $i < 30; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
$[0] = "4277c795cc5aa79cb8c9da3c17c3eca0172b2cb25ae31116d08eb0a5b925c1d5";
}
let dateFormat;
let options;
let props;
let t1;
if ($[1] !== t0) {
({prefix: t1, options, dateFormat, ...props} = t0);
$[1] = t0;
$[2] = dateFormat;
$[3] = options;
$[4] = props;
$[5] = t1;
} else {
dateFormat = $[2];
options = $[3];
props = $[4];
t1 = $[5];
}
const prefix = t1 === void 0 ? "" : t1;
const cell = useCellContext();
let T0;
let t2;
let t3;
let t4;
let t5;
let t6;
let t7;
let t8;
if ($[6] !== cell || $[7] !== dateFormat || $[8] !== options || $[9] !== prefix || $[10] !== props) {
t8 = Symbol.for("react.early_return_sentinel");
bb0: {
const value = cell.getValue();
if (value === null || value === void 0 || value === "") {
t8 = null;
break bb0;
}
let t9;
if ($[19] !== dateFormat || $[20] !== options) {
t9 = (entry) => typeof entry === "number" ? entry.toLocaleString(void 0, options) : formatValue(entry, dateFormat);
$[19] = dateFormat;
$[20] = options;
$[21] = t9;
} else t9 = $[21];
const format = t9;
T0 = Typography;
t2 = "body2";
t3 = "text.secondary";
t4 = true;
t5 = props;
t6 = prefix;
t7 = Array.isArray(value) ? value.map(format).join(" – ") : format(value);
}
$[6] = cell;
$[7] = dateFormat;
$[8] = options;
$[9] = prefix;
$[10] = props;
$[11] = T0;
$[12] = t2;
$[13] = t3;
$[14] = t4;
$[15] = t5;
$[16] = t6;
$[17] = t7;
$[18] = t8;
} else {
T0 = $[11];
t2 = $[12];
t3 = $[13];
t4 = $[14];
t5 = $[15];
t6 = $[16];
t7 = $[17];
t8 = $[18];
}
if (t8 !== Symbol.for("react.early_return_sentinel")) return t8;
let t9;
if ($[22] !== T0 || $[23] !== t2 || $[24] !== t3 || $[25] !== t4 || $[26] !== t5 || $[27] !== t6 || $[28] !== t7) {
t9 = /* @__PURE__ */ jsxs(T0, {
variant: t2,
color: t3,
noWrap: t4,
...t5,
children: [t6, t7]
});
$[22] = T0;
$[23] = t2;
$[24] = t3;
$[25] = t4;
$[26] = t5;
$[27] = t6;
$[28] = t7;
$[29] = t9;
} else t9 = $[29];
return t9;
};
//#endregion
export { toClipboardText as _, tableContext as a, useTableContext as c, columnAlign as d, columnLabel as f, shortcutLabel as g, pinnedSx as h, layoutTableFeatures as i, formatValue as l, moveColumn as m, cellContext as n, useCellContext as o, hasColumnLabel as p, headerContext as r, useHeaderContext as s, AggregatedCell as t, cellSelectionSx as u, useDialogs as v };
//# sourceMappingURL=AggregatedCell-BtKC5-m6.mjs.map