@kaifronsdal/transcript-viewer
Version:
A web-based viewer for AI conversation transcripts with rollback support
1,447 lines (1,433 loc) • 204 kB
JavaScript
import { x as push, G as store_get, M as head, N as ensure_array_like, J as escape_html, F as attr, O as stringify, I as unsubscribe_stores, z as pop, P as attr_class, Q as attr_style, R as spread_props, S as element, q as is_array, T as get_prototype_of, U as object_prototype } from './index-CeukPVPf.js';
import { p as page, n as normalizeClientFilePath, b as buildTranscriptUrl } from './file-utils-D1ajqP8K.js';
import { w as writable, d as derived } from './index2-uppKP1uk.js';
import { S as SCORE_THRESHOLDS } from './constants-C6XQO3qi.js';
import { a as collectScoreDescriptions, b as extractFirstSentence } from './transcript-utils-BY7i01oF.js';
import { compileExpression } from 'filtrex';
import './client-DCZcF6HN.js';
import '@sveltejs/kit/internal';
import './exports-Cv9LZeD1.js';
function functionalUpdate(updater, input) {
return typeof updater === "function" ? updater(input) : updater;
}
function makeStateUpdater(key, instance) {
return (updater) => {
instance.setState((old) => {
return {
...old,
[key]: functionalUpdate(updater, old[key])
};
});
};
}
function isFunction(d) {
return d instanceof Function;
}
function isNumberArray(d) {
return Array.isArray(d) && d.every((val) => typeof val === "number");
}
function flattenBy(arr, getChildren) {
const flat = [];
const recurse = (subArr) => {
subArr.forEach((item) => {
flat.push(item);
const children = getChildren(item);
if (children == null ? void 0 : children.length) {
recurse(children);
}
});
};
recurse(arr);
return flat;
}
function memo$1(getDeps, fn, opts) {
let deps = [];
let result;
return (depArgs) => {
var _a;
let depTime;
if (opts.key && opts.debug) depTime = Date.now();
const newDeps = getDeps(depArgs);
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
if (!depsChanged) {
return result;
}
deps = newDeps;
let resultTime;
if (opts.key && opts.debug) resultTime = Date.now();
result = fn(...newDeps);
(_a = opts == null ? void 0 : opts.onChange) == null ? void 0 : _a.call(opts, result);
if (opts.key && opts.debug) {
if (opts == null ? void 0 : opts.debug()) {
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
const resultFpsPercentage = resultEndTime / 16;
const pad = (str, num) => {
str = String(str);
while (str.length < num) {
str = " " + str;
}
return str;
};
console.info(
`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,
`
font-size: .6rem;
font-weight: bold;
color: hsl(${Math.max(
0,
Math.min(120 - 120 * resultFpsPercentage, 120)
)}deg 100% 31%);`,
opts == null ? void 0 : opts.key
);
}
}
return result;
};
}
function getMemoOptions(tableOptions, debugLevel, key, onChange) {
return {
debug: () => (tableOptions == null ? void 0 : tableOptions.debugAll) ?? tableOptions[debugLevel],
key: process.env.NODE_ENV === "development" && key,
onChange
};
}
function _createCell(table, row, column, columnId) {
const getRenderValue = () => cell.getValue() ?? table.options.renderFallbackValue;
const cell = {
id: `${row.id}_${column.id}`,
row,
column,
getValue: () => row.getValue(columnId),
renderValue: getRenderValue,
getContext: memo$1(
() => [table, column, row, cell],
(table2, column2, row2, cell2) => ({
table: table2,
column: column2,
row: row2,
cell: cell2,
getValue: cell2.getValue,
renderValue: cell2.renderValue
}),
getMemoOptions(table.options, "debugCells", "cell.getContext")
)
};
table._features.forEach((feature) => {
var _a;
(_a = feature._createCell) == null ? void 0 : _a.call(
feature,
cell,
column,
row,
table
);
}, {});
return cell;
}
function _createColumn(table, columnDef, depth, parent) {
var _a;
const defaultColumn = table._getDefaultColumnDef();
const resolvedColumnDef = {
...defaultColumn,
...columnDef
};
const accessorKey = resolvedColumnDef.accessorKey;
let id = resolvedColumnDef.id ?? (accessorKey ? accessorKey.replace(".", "_") : void 0) ?? (typeof resolvedColumnDef.header === "string" ? resolvedColumnDef.header : void 0);
let accessorFn;
if (resolvedColumnDef.accessorFn) {
accessorFn = resolvedColumnDef.accessorFn;
} else if (accessorKey) {
if (accessorKey.includes(".")) {
accessorFn = (originalRow) => {
let result = originalRow;
for (const key of accessorKey.split(".")) {
result = result == null ? void 0 : result[key];
if (process.env.NODE_ENV !== "production" && result === void 0) {
console.warn(
`"${key}" in deeply nested key "${accessorKey}" returned undefined.`
);
}
}
return result;
};
} else {
accessorFn = (originalRow) => originalRow[resolvedColumnDef.accessorKey];
}
}
if (!id) {
if (process.env.NODE_ENV !== "production") {
throw new Error(
resolvedColumnDef.accessorFn ? `Columns require an id when using an accessorFn` : `Columns require an id when using a non-string header`
);
}
throw new Error();
}
let column = {
id: `${String(id)}`,
accessorFn,
parent,
depth,
columnDef: resolvedColumnDef,
columns: [],
getFlatColumns: memo$1(
() => [true],
() => {
var _a2;
return [
column,
...(_a2 = column.columns) == null ? void 0 : _a2.flatMap((d) => d.getFlatColumns())
];
},
getMemoOptions(table.options, "debugColumns", "column.getFlatColumns")
),
getLeafColumns: memo$1(
() => [table._getOrderColumnsFn()],
(orderColumns) => {
var _a2;
if ((_a2 = column.columns) == null ? void 0 : _a2.length) {
let leafColumns = column.columns.flatMap(
(column2) => column2.getLeafColumns()
);
return orderColumns(leafColumns);
}
return [column];
},
getMemoOptions(table.options, "debugColumns", "column.getLeafColumns")
)
};
for (const feature of table._features) {
(_a = feature._createColumn) == null ? void 0 : _a.call(feature, column, table);
}
return column;
}
const debug = "debugHeaders";
function _createHeader(table, column, options) {
const id = options.id ?? column.id;
let header = {
id,
column,
index: options.index,
isPlaceholder: !!options.isPlaceholder,
placeholderId: options.placeholderId,
depth: options.depth,
subHeaders: [],
colSpan: 0,
rowSpan: 0,
headerGroup: null,
getLeafHeaders: () => {
const leafHeaders = [];
const recurseHeader = (h) => {
if (h.subHeaders && h.subHeaders.length) {
h.subHeaders.map(recurseHeader);
}
leafHeaders.push(h);
};
recurseHeader(header);
return leafHeaders;
},
getContext: () => ({
table,
header,
column
})
};
table._features.forEach((feature) => {
var _a;
(_a = feature._createHeader) == null ? void 0 : _a.call(feature, header, table);
});
return header;
}
const Headers = {
_createTable: (table) => {
table.getHeaderGroups = memo$1(
() => [
table.getAllColumns(),
table.getVisibleLeafColumns(),
table.getState().columnPinning.left,
table.getState().columnPinning.right
],
(allColumns, leafColumns, left, right) => {
const leftColumns = (left == null ? void 0 : left.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
const rightColumns = (right == null ? void 0 : right.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
const centerColumns = leafColumns.filter(
(column) => !(left == null ? void 0 : left.includes(column.id)) && !(right == null ? void 0 : right.includes(column.id))
);
const headerGroups = buildHeaderGroups(
allColumns,
[...leftColumns, ...centerColumns, ...rightColumns],
table
);
return headerGroups;
},
getMemoOptions(table.options, debug, "getHeaderGroups")
);
table.getCenterHeaderGroups = memo$1(
() => [
table.getAllColumns(),
table.getVisibleLeafColumns(),
table.getState().columnPinning.left,
table.getState().columnPinning.right
],
(allColumns, leafColumns, left, right) => {
leafColumns = leafColumns.filter(
(column) => !(left == null ? void 0 : left.includes(column.id)) && !(right == null ? void 0 : right.includes(column.id))
);
return buildHeaderGroups(allColumns, leafColumns, table, "center");
},
getMemoOptions(table.options, debug, "getCenterHeaderGroups")
);
table.getLeftHeaderGroups = memo$1(
() => [
table.getAllColumns(),
table.getVisibleLeafColumns(),
table.getState().columnPinning.left
],
(allColumns, leafColumns, left) => {
const orderedLeafColumns = (left == null ? void 0 : left.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
return buildHeaderGroups(allColumns, orderedLeafColumns, table, "left");
},
getMemoOptions(table.options, debug, "getLeftHeaderGroups")
);
table.getRightHeaderGroups = memo$1(
() => [
table.getAllColumns(),
table.getVisibleLeafColumns(),
table.getState().columnPinning.right
],
(allColumns, leafColumns, right) => {
const orderedLeafColumns = (right == null ? void 0 : right.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
return buildHeaderGroups(allColumns, orderedLeafColumns, table, "right");
},
getMemoOptions(table.options, debug, "getRightHeaderGroups")
);
table.getFooterGroups = memo$1(
() => [table.getHeaderGroups()],
(headerGroups) => {
return [...headerGroups].reverse();
},
getMemoOptions(table.options, debug, "getFooterGroups")
);
table.getLeftFooterGroups = memo$1(
() => [table.getLeftHeaderGroups()],
(headerGroups) => {
return [...headerGroups].reverse();
},
getMemoOptions(table.options, debug, "getLeftFooterGroups")
);
table.getCenterFooterGroups = memo$1(
() => [table.getCenterHeaderGroups()],
(headerGroups) => {
return [...headerGroups].reverse();
},
getMemoOptions(table.options, debug, "getCenterFooterGroups")
);
table.getRightFooterGroups = memo$1(
() => [table.getRightHeaderGroups()],
(headerGroups) => {
return [...headerGroups].reverse();
},
getMemoOptions(table.options, debug, "getRightFooterGroups")
);
table.getFlatHeaders = memo$1(
() => [table.getHeaderGroups()],
(headerGroups) => {
return headerGroups.map((headerGroup) => {
return headerGroup.headers;
}).flat();
},
getMemoOptions(table.options, debug, "getFlatHeaders")
);
table.getLeftFlatHeaders = memo$1(
() => [table.getLeftHeaderGroups()],
(left) => {
return left.map((headerGroup) => {
return headerGroup.headers;
}).flat();
},
getMemoOptions(table.options, debug, "getLeftFlatHeaders")
);
table.getCenterFlatHeaders = memo$1(
() => [table.getCenterHeaderGroups()],
(left) => {
return left.map((headerGroup) => {
return headerGroup.headers;
}).flat();
},
getMemoOptions(table.options, debug, "getCenterFlatHeaders")
);
table.getRightFlatHeaders = memo$1(
() => [table.getRightHeaderGroups()],
(left) => {
return left.map((headerGroup) => {
return headerGroup.headers;
}).flat();
},
getMemoOptions(table.options, debug, "getRightFlatHeaders")
);
table.getCenterLeafHeaders = memo$1(
() => [table.getCenterFlatHeaders()],
(flatHeaders) => {
return flatHeaders.filter((header) => {
var _a;
return !((_a = header.subHeaders) == null ? void 0 : _a.length);
});
},
getMemoOptions(table.options, debug, "getCenterLeafHeaders")
);
table.getLeftLeafHeaders = memo$1(
() => [table.getLeftFlatHeaders()],
(flatHeaders) => {
return flatHeaders.filter((header) => {
var _a;
return !((_a = header.subHeaders) == null ? void 0 : _a.length);
});
},
getMemoOptions(table.options, debug, "getLeftLeafHeaders")
);
table.getRightLeafHeaders = memo$1(
() => [table.getRightFlatHeaders()],
(flatHeaders) => {
return flatHeaders.filter((header) => {
var _a;
return !((_a = header.subHeaders) == null ? void 0 : _a.length);
});
},
getMemoOptions(table.options, debug, "getRightLeafHeaders")
);
table.getLeafHeaders = memo$1(
() => [
table.getLeftHeaderGroups(),
table.getCenterHeaderGroups(),
table.getRightHeaderGroups()
],
(left, center, right) => {
var _a, _b, _c;
return [
...((_a = left[0]) == null ? void 0 : _a.headers) ?? [],
...((_b = center[0]) == null ? void 0 : _b.headers) ?? [],
...((_c = right[0]) == null ? void 0 : _c.headers) ?? []
].map((header) => {
return header.getLeafHeaders();
}).flat();
},
getMemoOptions(table.options, debug, "getLeafHeaders")
);
}
};
function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
var _a;
let maxDepth = 0;
const findMaxDepth = (columns, depth = 1) => {
maxDepth = Math.max(maxDepth, depth);
columns.filter((column) => column.getIsVisible()).forEach((column) => {
var _a2;
if ((_a2 = column.columns) == null ? void 0 : _a2.length) {
findMaxDepth(column.columns, depth + 1);
}
}, 0);
};
findMaxDepth(allColumns);
let headerGroups = [];
const createHeaderGroup = (headersToGroup, depth) => {
const headerGroup = {
depth,
id: [headerFamily, `${depth}`].filter(Boolean).join("_"),
headers: []
};
const pendingParentHeaders = [];
headersToGroup.forEach((headerToGroup) => {
const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
let column;
let isPlaceholder = false;
if (isLeafHeader && headerToGroup.column.parent) {
column = headerToGroup.column.parent;
} else {
column = headerToGroup.column;
isPlaceholder = true;
}
if (latestPendingParentHeader && (latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
latestPendingParentHeader.subHeaders.push(headerToGroup);
} else {
const header = _createHeader(table, column, {
id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join("_"),
isPlaceholder,
placeholderId: isPlaceholder ? `${pendingParentHeaders.filter((d) => d.column === column).length}` : void 0,
depth,
index: pendingParentHeaders.length
});
header.subHeaders.push(headerToGroup);
pendingParentHeaders.push(header);
}
headerGroup.headers.push(headerToGroup);
headerToGroup.headerGroup = headerGroup;
});
headerGroups.push(headerGroup);
if (depth > 0) {
createHeaderGroup(pendingParentHeaders, depth - 1);
}
};
const bottomHeaders = columnsToGroup.map(
(column, index) => _createHeader(table, column, {
depth: maxDepth,
index
})
);
createHeaderGroup(bottomHeaders, maxDepth - 1);
headerGroups.reverse();
const recurseHeadersForSpans = (headers) => {
const filteredHeaders = headers.filter(
(header) => header.column.getIsVisible()
);
return filteredHeaders.map((header) => {
let colSpan = 0;
let rowSpan = 0;
let childRowSpans = [0];
if (header.subHeaders && header.subHeaders.length) {
childRowSpans = [];
recurseHeadersForSpans(header.subHeaders).forEach(
({ colSpan: childColSpan, rowSpan: childRowSpan }) => {
colSpan += childColSpan;
childRowSpans.push(childRowSpan);
}
);
} else {
colSpan = 1;
}
const minChildRowSpan = Math.min(...childRowSpans);
rowSpan = rowSpan + minChildRowSpan;
header.colSpan = colSpan;
header.rowSpan = rowSpan;
return { colSpan, rowSpan };
});
};
recurseHeadersForSpans(((_a = headerGroups[0]) == null ? void 0 : _a.headers) ?? []);
return headerGroups;
}
const _createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
var _a;
let row = {
id,
index: rowIndex,
original,
depth,
parentId,
_valuesCache: {},
_uniqueValuesCache: {},
getValue: (columnId) => {
if (row._valuesCache.hasOwnProperty(columnId)) {
return row._valuesCache[columnId];
}
const column = table.getColumn(columnId);
if (!(column == null ? void 0 : column.accessorFn)) {
return void 0;
}
row._valuesCache[columnId] = column.accessorFn(
row.original,
rowIndex
);
return row._valuesCache[columnId];
},
getUniqueValues: (columnId) => {
if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
return row._uniqueValuesCache[columnId];
}
const column = table.getColumn(columnId);
if (!(column == null ? void 0 : column.accessorFn)) {
return void 0;
}
if (!column.columnDef.getUniqueValues) {
row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
return row._uniqueValuesCache[columnId];
}
row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(
row.original,
rowIndex
);
return row._uniqueValuesCache[columnId];
},
renderValue: (columnId) => row.getValue(columnId) ?? table.options.renderFallbackValue,
subRows: [],
getLeafRows: () => flattenBy(row.subRows, (d) => d.subRows),
getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : void 0,
getParentRows: () => {
let parentRows = [];
let currentRow = row;
while (true) {
const parentRow = currentRow.getParentRow();
if (!parentRow) break;
parentRows.push(parentRow);
currentRow = parentRow;
}
return parentRows.reverse();
},
getAllCells: memo$1(
() => [table.getAllLeafColumns()],
(leafColumns) => {
return leafColumns.map((column) => {
return _createCell(table, row, column, column.id);
});
},
getMemoOptions(table.options, "debugRows", "getAllCells")
),
_getAllCellsByColumnId: memo$1(
() => [row.getAllCells()],
(allCells) => {
return allCells.reduce(
(acc, cell) => {
acc[cell.column.id] = cell;
return acc;
},
{}
);
},
getMemoOptions(table.options, "debugRows", "getAllCellsByColumnId")
)
};
for (let i = 0; i < table._features.length; i++) {
const feature = table._features[i];
(_a = feature == null ? void 0 : feature._createRow) == null ? void 0 : _a.call(feature, row, table);
}
return row;
};
const ColumnFaceting = {
_createColumn: (column, table) => {
column._getFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id);
column.getFacetedRowModel = () => {
if (!column._getFacetedRowModel) {
return table.getPreFilteredRowModel();
}
return column._getFacetedRowModel();
};
column._getFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id);
column.getFacetedUniqueValues = () => {
if (!column._getFacetedUniqueValues) {
return /* @__PURE__ */ new Map();
}
return column._getFacetedUniqueValues();
};
column._getFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id);
column.getFacetedMinMaxValues = () => {
if (!column._getFacetedMinMaxValues) {
return void 0;
}
return column._getFacetedMinMaxValues();
};
}
};
const includesString = (row, columnId, filterValue) => {
var _a, _b, _c;
const search = filterValue.toLowerCase();
return Boolean(
(_c = (_b = (_a = row.getValue(columnId)) == null ? void 0 : _a.toString()) == null ? void 0 : _b.toLowerCase()) == null ? void 0 : _c.includes(search)
);
};
includesString.autoRemove = (val) => testFalsey(val);
const includesStringSensitive = (row, columnId, filterValue) => {
var _a, _b;
return Boolean(
(_b = (_a = row.getValue(columnId)) == null ? void 0 : _a.toString()) == null ? void 0 : _b.includes(filterValue)
);
};
includesStringSensitive.autoRemove = (val) => testFalsey(val);
const equalsString = (row, columnId, filterValue) => {
var _a, _b;
return ((_b = (_a = row.getValue(columnId)) == null ? void 0 : _a.toString()) == null ? void 0 : _b.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
};
equalsString.autoRemove = (val) => testFalsey(val);
const arrIncludes = (row, columnId, filterValue) => {
var _a;
return (_a = row.getValue(columnId)) == null ? void 0 : _a.includes(filterValue);
};
arrIncludes.autoRemove = (val) => testFalsey(val) || !(val == null ? void 0 : val.length);
const arrIncludesAll = (row, columnId, filterValue) => {
return !filterValue.some(
(val) => {
var _a;
return !((_a = row.getValue(columnId)) == null ? void 0 : _a.includes(val));
}
);
};
arrIncludesAll.autoRemove = (val) => testFalsey(val) || !(val == null ? void 0 : val.length);
const arrIncludesSome = (row, columnId, filterValue) => {
return filterValue.some(
(val) => {
var _a;
return (_a = row.getValue(columnId)) == null ? void 0 : _a.includes(val);
}
);
};
arrIncludesSome.autoRemove = (val) => testFalsey(val) || !(val == null ? void 0 : val.length);
const equals = (row, columnId, filterValue) => {
return row.getValue(columnId) === filterValue;
};
equals.autoRemove = (val) => testFalsey(val);
const weakEquals = (row, columnId, filterValue) => {
return row.getValue(columnId) == filterValue;
};
weakEquals.autoRemove = (val) => testFalsey(val);
const inNumberRange = (row, columnId, filterValue) => {
let [min, max] = filterValue;
const rowValue = row.getValue(columnId);
return rowValue >= min && rowValue <= max;
};
inNumberRange.resolveFilterValue = (val) => {
let [unsafeMin, unsafeMax] = val;
let parsedMin = typeof unsafeMin !== "number" ? parseFloat(unsafeMin) : unsafeMin;
let parsedMax = typeof unsafeMax !== "number" ? parseFloat(unsafeMax) : unsafeMax;
let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
if (min > max) {
const temp = min;
min = max;
max = temp;
}
return [min, max];
};
inNumberRange.autoRemove = (val) => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
const filterFns = {
includesString,
includesStringSensitive,
equalsString,
arrIncludes,
arrIncludesAll,
arrIncludesSome,
equals,
weakEquals,
inNumberRange
};
function testFalsey(val) {
return val === void 0 || val === null || val === "";
}
const ColumnFiltering = {
_getDefaultColumnDef: () => {
return {
filterFn: "auto"
};
},
_getInitialState: (state) => {
return {
columnFilters: [],
...state
};
},
_getDefaultOptions: (table) => {
return {
onColumnFiltersChange: makeStateUpdater("columnFilters", table),
filterFromLeafRows: false,
maxLeafRowFilterDepth: 100
};
},
_createColumn: (column, table) => {
column.getAutoFilterFn = () => {
const firstRow = table.getCoreRowModel().flatRows[0];
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
if (typeof value === "string") {
return filterFns.includesString;
}
if (typeof value === "number") {
return filterFns.inNumberRange;
}
if (typeof value === "boolean") {
return filterFns.equals;
}
if (value !== null && typeof value === "object") {
return filterFns.equals;
}
if (Array.isArray(value)) {
return filterFns.arrIncludes;
}
return filterFns.weakEquals;
};
column.getFilterFn = () => {
var _a;
return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === "auto" ? column.getAutoFilterFn() : (
// @ts-ignore
((_a = table.options.filterFns) == null ? void 0 : _a[column.columnDef.filterFn]) ?? filterFns[column.columnDef.filterFn]
);
};
column.getCanFilter = () => {
return (column.columnDef.enableColumnFilter ?? true) && (table.options.enableColumnFilters ?? true) && (table.options.enableFilters ?? true) && !!column.accessorFn;
};
column.getIsFiltered = () => column.getFilterIndex() > -1;
column.getFilterValue = () => {
var _a, _b;
return (_b = (_a = table.getState().columnFilters) == null ? void 0 : _a.find((d) => d.id === column.id)) == null ? void 0 : _b.value;
};
column.getFilterIndex = () => {
var _a;
return ((_a = table.getState().columnFilters) == null ? void 0 : _a.findIndex((d) => d.id === column.id)) ?? -1;
};
column.setFilterValue = (value) => {
table.setColumnFilters((old) => {
const filterFn = column.getFilterFn();
const previousFilter = old == null ? void 0 : old.find((d) => d.id === column.id);
const newFilter = functionalUpdate(
value,
previousFilter ? previousFilter.value : void 0
);
if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
return (old == null ? void 0 : old.filter((d) => d.id !== column.id)) ?? [];
}
const newFilterObj = { id: column.id, value: newFilter };
if (previousFilter) {
return (old == null ? void 0 : old.map((d) => {
if (d.id === column.id) {
return newFilterObj;
}
return d;
})) ?? [];
}
if (old == null ? void 0 : old.length) {
return [...old, newFilterObj];
}
return [newFilterObj];
});
};
},
_createRow: (row, _table) => {
row.columnFilters = {};
row.columnFiltersMeta = {};
},
_createTable: (table) => {
table.setColumnFilters = (updater) => {
var _a, _b;
const leafColumns = table.getAllLeafColumns();
const updateFn = (old) => {
var _a2;
return (_a2 = functionalUpdate(updater, old)) == null ? void 0 : _a2.filter((filter) => {
const column = leafColumns.find((d) => d.id === filter.id);
if (column) {
const filterFn = column.getFilterFn();
if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
return false;
}
}
return true;
});
};
(_b = (_a = table.options).onColumnFiltersChange) == null ? void 0 : _b.call(_a, updateFn);
};
table.resetColumnFilters = (defaultState) => {
var _a;
table.setColumnFilters(
defaultState ? [] : ((_a = table.initialState) == null ? void 0 : _a.columnFilters) ?? []
);
};
table.getPreFilteredRowModel = () => table.getCoreRowModel();
table.getFilteredRowModel = () => {
if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
table._getFilteredRowModel = table.options.getFilteredRowModel(table);
}
if (table.options.manualFiltering || !table._getFilteredRowModel) {
return table.getPreFilteredRowModel();
}
return table._getFilteredRowModel();
};
}
};
function shouldAutoRemoveFilter(filterFn, value, column) {
return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === "undefined" || typeof value === "string" && !value;
}
const sum = (columnId, _leafRows, childRows) => {
return childRows.reduce((sum2, next) => {
const nextValue = next.getValue(columnId);
return sum2 + (typeof nextValue === "number" ? nextValue : 0);
}, 0);
};
const min = (columnId, _leafRows, childRows) => {
let min2;
childRows.forEach((row) => {
const value = row.getValue(columnId);
if (value != null && (min2 > value || min2 === void 0 && value >= value)) {
min2 = value;
}
});
return min2;
};
const max = (columnId, _leafRows, childRows) => {
let max2;
childRows.forEach((row) => {
const value = row.getValue(columnId);
if (value != null && (max2 < value || max2 === void 0 && value >= value)) {
max2 = value;
}
});
return max2;
};
const extent = (columnId, _leafRows, childRows) => {
let min2;
let max2;
childRows.forEach((row) => {
const value = row.getValue(columnId);
if (value != null) {
if (min2 === void 0) {
if (value >= value) min2 = max2 = value;
} else {
if (min2 > value) min2 = value;
if (max2 < value) max2 = value;
}
}
});
return [min2, max2];
};
const mean = (columnId, leafRows) => {
let count2 = 0;
let sum2 = 0;
leafRows.forEach((row) => {
let value = row.getValue(columnId);
if (value != null && (value = +value) >= value) {
++count2, sum2 += value;
}
});
if (count2) return sum2 / count2;
return;
};
const median = (columnId, leafRows) => {
if (!leafRows.length) {
return;
}
const values = leafRows.map((row) => row.getValue(columnId));
if (!isNumberArray(values)) {
return;
}
if (values.length === 1) {
return values[0];
}
const mid = Math.floor(values.length / 2);
const nums = values.sort((a, b) => a - b);
return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
};
const unique = (columnId, leafRows) => {
return Array.from(new Set(leafRows.map((d) => d.getValue(columnId))).values());
};
const uniqueCount = (columnId, leafRows) => {
return new Set(leafRows.map((d) => d.getValue(columnId))).size;
};
const count = (_columnId, leafRows) => {
return leafRows.length;
};
const aggregationFns = {
sum,
min,
max,
extent,
mean,
median,
unique,
uniqueCount,
count
};
const ColumnGrouping = {
_getDefaultColumnDef: () => {
return {
aggregatedCell: (props) => {
var _a, _b;
return ((_b = (_a = props.getValue()) == null ? void 0 : _a.toString) == null ? void 0 : _b.call(_a)) ?? null;
},
aggregationFn: "auto"
};
},
_getInitialState: (state) => {
return {
grouping: [],
...state
};
},
_getDefaultOptions: (table) => {
return {
onGroupingChange: makeStateUpdater("grouping", table),
groupedColumnMode: "reorder"
};
},
_createColumn: (column, table) => {
column.toggleGrouping = () => {
table.setGrouping((old) => {
if (old == null ? void 0 : old.includes(column.id)) {
return old.filter((d) => d !== column.id);
}
return [...old ?? [], column.id];
});
};
column.getCanGroup = () => {
return (column.columnDef.enableGrouping ?? true) && (table.options.enableGrouping ?? true) && (!!column.accessorFn || !!column.columnDef.getGroupingValue);
};
column.getIsGrouped = () => {
var _a;
return (_a = table.getState().grouping) == null ? void 0 : _a.includes(column.id);
};
column.getGroupedIndex = () => {
var _a;
return (_a = table.getState().grouping) == null ? void 0 : _a.indexOf(column.id);
};
column.getToggleGroupingHandler = () => {
const canGroup = column.getCanGroup();
return () => {
if (!canGroup) return;
column.toggleGrouping();
};
};
column.getAutoAggregationFn = () => {
const firstRow = table.getCoreRowModel().flatRows[0];
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
if (typeof value === "number") {
return aggregationFns.sum;
}
if (Object.prototype.toString.call(value) === "[object Date]") {
return aggregationFns.extent;
}
};
column.getAggregationFn = () => {
var _a;
if (!column) {
throw new Error();
}
return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === "auto" ? column.getAutoAggregationFn() : ((_a = table.options.aggregationFns) == null ? void 0 : _a[column.columnDef.aggregationFn]) ?? aggregationFns[column.columnDef.aggregationFn];
};
},
_createTable: (table) => {
table.setGrouping = (updater) => {
var _a, _b;
return (_b = (_a = table.options).onGroupingChange) == null ? void 0 : _b.call(_a, updater);
};
table.resetGrouping = (defaultState) => {
var _a;
table.setGrouping(defaultState ? [] : ((_a = table.initialState) == null ? void 0 : _a.grouping) ?? []);
};
table.getPreGroupedRowModel = () => table.getFilteredRowModel();
table.getGroupedRowModel = () => {
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
table._getGroupedRowModel = table.options.getGroupedRowModel(table);
}
if (table.options.manualGrouping || !table._getGroupedRowModel) {
return table.getPreGroupedRowModel();
}
return table._getGroupedRowModel();
};
},
_createRow: (row, table) => {
row.getIsGrouped = () => !!row.groupingColumnId;
row.getGroupingValue = (columnId) => {
if (row._groupingValuesCache.hasOwnProperty(columnId)) {
return row._groupingValuesCache[columnId];
}
const column = table.getColumn(columnId);
if (!(column == null ? void 0 : column.columnDef.getGroupingValue)) {
return row.getValue(columnId);
}
row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(
row.original
);
return row._groupingValuesCache[columnId];
};
row._groupingValuesCache = {};
},
_createCell: (cell, column, row, table) => {
cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
cell.getIsAggregated = () => {
var _a;
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_a = row.subRows) == null ? void 0 : _a.length);
};
}
};
function orderColumns(leafColumns, grouping, groupedColumnMode) {
if (!(grouping == null ? void 0 : grouping.length) || !groupedColumnMode) {
return leafColumns;
}
const nonGroupingColumns = leafColumns.filter(
(col) => !grouping.includes(col.id)
);
if (groupedColumnMode === "remove") {
return nonGroupingColumns;
}
const groupingColumns = grouping.map((g) => leafColumns.find((col) => col.id === g)).filter(Boolean);
return [...groupingColumns, ...nonGroupingColumns];
}
const ColumnVisibility = {
_getInitialState: (state) => {
return {
columnVisibility: {},
...state
};
},
_getDefaultOptions: (table) => {
return {
onColumnVisibilityChange: makeStateUpdater("columnVisibility", table)
};
},
_createColumn: (column, table) => {
column.toggleVisibility = (value) => {
if (column.getCanHide()) {
table.setColumnVisibility((old) => ({
...old,
[column.id]: value ?? !column.getIsVisible()
}));
}
};
column.getIsVisible = () => {
var _a;
const childColumns = column.columns;
return (childColumns.length ? childColumns.some((c) => c.getIsVisible()) : (_a = table.getState().columnVisibility) == null ? void 0 : _a[column.id]) ?? true;
};
column.getCanHide = () => {
return (column.columnDef.enableHiding ?? true) && (table.options.enableHiding ?? true);
};
column.getToggleVisibilityHandler = () => {
return (e) => {
var _a;
(_a = column.toggleVisibility) == null ? void 0 : _a.call(
column,
e.target.checked
);
};
};
},
_createRow: (row, table) => {
row._getAllVisibleCells = memo$1(
() => [row.getAllCells(), table.getState().columnVisibility],
(cells) => {
return cells.filter((cell) => cell.column.getIsVisible());
},
getMemoOptions(table.options, "debugRows", "_getAllVisibleCells")
);
row.getVisibleCells = memo$1(
() => [
row.getLeftVisibleCells(),
row.getCenterVisibleCells(),
row.getRightVisibleCells()
],
(left, center, right) => [...left, ...center, ...right],
getMemoOptions(table.options, "debugRows", "getVisibleCells")
);
},
_createTable: (table) => {
const makeVisibleColumnsMethod = (key, getColumns) => {
return memo$1(
() => [
getColumns(),
getColumns().filter((d) => d.getIsVisible()).map((d) => d.id).join("_")
],
(columns) => {
return columns.filter((d) => {
var _a;
return (_a = d.getIsVisible) == null ? void 0 : _a.call(d);
});
},
getMemoOptions(table.options, "debugColumns", key)
);
};
table.getVisibleFlatColumns = makeVisibleColumnsMethod(
"getVisibleFlatColumns",
() => table.getAllFlatColumns()
);
table.getVisibleLeafColumns = makeVisibleColumnsMethod(
"getVisibleLeafColumns",
() => table.getAllLeafColumns()
);
table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod(
"getLeftVisibleLeafColumns",
() => table.getLeftLeafColumns()
);
table.getRightVisibleLeafColumns = makeVisibleColumnsMethod(
"getRightVisibleLeafColumns",
() => table.getRightLeafColumns()
);
table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod(
"getCenterVisibleLeafColumns",
() => table.getCenterLeafColumns()
);
table.setColumnVisibility = (updater) => {
var _a, _b;
return (_b = (_a = table.options).onColumnVisibilityChange) == null ? void 0 : _b.call(_a, updater);
};
table.resetColumnVisibility = (defaultState) => {
table.setColumnVisibility(
defaultState ? {} : table.initialState.columnVisibility ?? {}
);
};
table.toggleAllColumnsVisible = (value) => {
value = value ?? !table.getIsAllColumnsVisible();
table.setColumnVisibility(
table.getAllLeafColumns().reduce(
(obj, column) => {
var _a;
return {
...obj,
[column.id]: !value ? !((_a = column.getCanHide) == null ? void 0 : _a.call(column)) : value
};
},
{}
)
);
};
table.getIsAllColumnsVisible = () => !table.getAllLeafColumns().some((column) => {
var _a;
return !((_a = column.getIsVisible) == null ? void 0 : _a.call(column));
});
table.getIsSomeColumnsVisible = () => table.getAllLeafColumns().some((column) => {
var _a;
return (_a = column.getIsVisible) == null ? void 0 : _a.call(column);
});
table.getToggleAllColumnsVisibilityHandler = () => {
return (e) => {
var _a;
table.toggleAllColumnsVisible(
(_a = e.target) == null ? void 0 : _a.checked
);
};
};
}
};
function _getVisibleLeafColumns(table, position) {
return !position ? table.getVisibleLeafColumns() : position === "center" ? table.getCenterVisibleLeafColumns() : position === "left" ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
}
const ColumnOrdering = {
_getInitialState: (state) => {
return {
columnOrder: [],
...state
};
},
_getDefaultOptions: (table) => {
return {
onColumnOrderChange: makeStateUpdater("columnOrder", table)
};
},
_createColumn: (column, table) => {
column.getIndex = memo$1(
(position) => [_getVisibleLeafColumns(table, position)],
(columns) => columns.findIndex((d) => d.id === column.id),
getMemoOptions(table.options, "debugColumns", "getIndex")
);
column.getIsFirstColumn = (position) => {
var _a;
const columns = _getVisibleLeafColumns(table, position);
return ((_a = columns[0]) == null ? void 0 : _a.id) === column.id;
};
column.getIsLastColumn = (position) => {
var _a;
const columns = _getVisibleLeafColumns(table, position);
return ((_a = columns[columns.length - 1]) == null ? void 0 : _a.id) === column.id;
};
},
_createTable: (table) => {
table.setColumnOrder = (updater) => {
var _a, _b;
return (_b = (_a = table.options).onColumnOrderChange) == null ? void 0 : _b.call(_a, updater);
};
table.resetColumnOrder = (defaultState) => {
table.setColumnOrder(
defaultState ? [] : table.initialState.columnOrder ?? []
);
};
table._getOrderColumnsFn = memo$1(
() => [
table.getState().columnOrder,
table.getState().grouping,
table.options.groupedColumnMode
],
(columnOrder, grouping, groupedColumnMode) => (columns) => {
let orderedColumns = [];
if (!(columnOrder == null ? void 0 : columnOrder.length)) {
orderedColumns = columns;
} else {
const columnOrderCopy = [...columnOrder];
const columnsCopy = [...columns];
while (columnsCopy.length && columnOrderCopy.length) {
const targetColumnId = columnOrderCopy.shift();
const foundIndex = columnsCopy.findIndex(
(d) => d.id === targetColumnId
);
if (foundIndex > -1) {
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
}
}
orderedColumns = [...orderedColumns, ...columnsCopy];
}
return orderColumns(orderedColumns, grouping, groupedColumnMode);
},
getMemoOptions(table.options, "debugTable", "_getOrderColumnsFn")
);
}
};
const getDefaultColumnPinningState = () => ({
left: [],
right: []
});
const ColumnPinning = {
_getInitialState: (state) => {
return {
columnPinning: getDefaultColumnPinningState(),
...state
};
},
_getDefaultOptions: (table) => {
return {
onColumnPinningChange: makeStateUpdater("columnPinning", table)
};
},
_createColumn: (column, table) => {
column.pin = (position) => {
const columnIds = column.getLeafColumns().map((d) => d.id).filter(Boolean);
table.setColumnPinning((old) => {
if (position === "right") {
return {
left: ((old == null ? void 0 : old.left) ?? []).filter((d) => !(columnIds == null ? void 0 : columnIds.includes(d))),
right: [
...((old == null ? void 0 : old.right) ?? []).filter((d) => !(columnIds == null ? void 0 : columnIds.includes(d))),
...columnIds
]
};
}
if (position === "left") {
return {
left: [
...((old == null ? void 0 : old.left) ?? []).filter((d) => !(columnIds == null ? void 0 : columnIds.includes(d))),
...columnIds
],
right: ((old == null ? void 0 : old.right) ?? []).filter((d) => !(columnIds == null ? void 0 : columnIds.includes(d)))
};
}
return {
left: ((old == null ? void 0 : old.left) ?? []).filter((d) => !(columnIds == null ? void 0 : columnIds.includes(d))),
right: ((old == null ? void 0 : old.right) ?? []).filter((d) => !(columnIds == null ? void 0 : columnIds.includes(d)))
};
});
};
column.getCanPin = () => {
const leafColumns = column.getLeafColumns();
return leafColumns.some(
(d) => (d.columnDef.enablePinning ?? true) && (table.options.enableColumnPinning ?? table.options.enablePinning ?? true)
);
};
column.getIsPinned = () => {
const leafColumnIds = column.getLeafColumns().map((d) => d.id);
const { left, right } = table.getState().columnPinning;
const isLeft = leafColumnIds.some((d) => left == null ? void 0 : left.includes(d));
const isRight = leafColumnIds.some((d) => right == null ? void 0 : right.includes(d));
return isLeft ? "left" : isRight ? "right" : false;
};
column.getPinnedIndex = () => {
var _a, _b;
const position = column.getIsPinned();
return position ? ((_b = (_a = table.getState().columnPinning) == null ? void 0 : _a[position]) == null ? void 0 : _b.indexOf(column.id)) ?? -1 : 0;
};
},
_createRow: (row, table) => {
row.getCenterVisibleCells = memo$1(
() => [
row._getAllVisibleCells(),
table.getState().columnPinning.left,
table.getState().columnPinning.right
],
(allCells, left, right) => {
const leftAndRight = [...left ?? [], ...right ?? []];
return allCells.filter((d) => !leftAndRight.includes(d.column.id));
},
getMemoOptions(table.options, "debugRows", "getCenterVisibleCells")
);
row.getLeftVisibleCells = memo$1(
() => [row._getAllVisibleCells(), table.getState().columnPinning.left],
(allCells, left) => {
const cells = (left ?? []).map((columnId) => allCells.find((cell) => cell.column.id === columnId)).filter(Boolean).map((d) => ({ ...d, position: "left" }));
return cells;
},
getMemoOptions(table.options, "debugRows", "getLeftVisibleCells")
);
row.getRightVisibleCells = memo$1(
() => [row._getAllVisibleCells(), table.getState().columnPinning.right],
(allCells, right) => {
const cells = (right ?? []).map((columnId) => allCells.find((cell) => cell.column.id === columnId)).filter(Boolean).map((d) => ({ ...d, position: "right" }));
return cells;
},
getMemoOptions(table.options, "debugRows", "getRightVisibleCells")
);
},
_createTable: (table) => {
table.setColumnPinning = (updater) => {
var _a, _b;
return (_b = (_a = table.options).onColumnPinningChange) == null ? void 0 : _b.call(_a, updater);
};
table.resetColumnPinning = (defaultState) => {
var _a;
return table.setColumnPinning(
defaultState ? getDefaultColumnPinningState() : ((_a = table.initialState) == null ? void 0 : _a.columnPinning) ?? getDefaultColumnPinningState()
);
};
table.getIsSomeColumnsPinned = (position) => {
var _a, _b, _c;
const pinningState = table.getState().columnPinning;
if (!position) {
return Boolean(((_a = pinningState.left) == null ? void 0 : _a.length) || ((_b = pinningState.right) == null ? void 0 : _b.length));
}
return Boolean((_c = pinningState[position]) == null ? void 0 : _c.length);
};
table.getLeftLeafColumns = memo$1(
() => [table.getAllLeafColumns(), table.getState().columnPinning.left],
(allColumns, left) => {
return (left ?? []).map((columnId) => allColumns.find((column) => column.id === columnId)).filter(Boolean);
},
getMemoOptions(table.options, "debugColumns", "getLeftLeafColumns")
);
table.getRightLeafColumns = memo$1(
() => [table.getAllLeafColumns(), table.getState().columnPinning.right],
(allColumns, right) => {
return (right ?? []).map((columnId) => allColumns.find((column) => column.id === columnId)).filter(Boolean);
},
getMemoOptions(table.options, "debugColumns", "getRightLeafColumns")
);
table.getCenterLeafColumns = memo$1(
() => [
table.getAllLeafColumns(),
table.getState().columnPinning.left,
table.getState().columnPinning.right
],
(allColumns, left, right) => {
const leftAndRight = [...left ?? [], ...right ?? []];
return allColumns.filter((d) => !leftAndRight.includes(d.id));
},
getMemoOptions(table.options, "debugColumns", "getCenterLeafColumns")
);
}
};
const defaultColumnSizing = {
size: 150,
minSize: 20,
maxSize: Number.MAX_SAFE_INTEGER
};
const getDefaultColumnSizingInfoState = () => ({
startOffset: null,
startSize: null,
deltaOffset: null,
deltaPercentage: null,
isResizingColumn: false,
columnSizingStart: []
});
const ColumnSizing = {
_getDefaultColumnDef: () => {
return defaultColumnSizing;
},
_getInitialState: (state) => {
return {
columnSizing: {},
columnSizingInfo: getDefaultColumnSizingInfoState(),
...state
};
},
_getDefaultOptions: (table) => {
return {
columnResizeMode: "onEnd",
columnResizeDirection: "ltr",
onColumnSizingChange: makeStateUpdater("columnSizing", table),
onColumnSizingInfoChange: makeStateUpdater("columnSizingInfo", table)
};
},
_createColumn: (column, table) => {
column.getSize = () => {
const columnSize = table.getState().columnSizing[column.id];
return Math.min(
Math.max(
column.columnDef.minSize ?? defaultColumnSizing.minSize,
columnSize ?? column.columnDef.si