@gridkitjs/core 0.0.0-dev-20261119135354 → 0.0.0-dev-20261120112923

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.
@@ -1337,6 +1337,505 @@ function setColumnVisibility(columns, visibility, columnIds, visible) {
1337
1337
  };
1338
1338
  }
1339
1339
 
1340
+ // src/messages.ts
1341
+ function localeKey(locale) {
1342
+ return typeof locale === "string" ? locale : locale?.join(",") ?? "";
1343
+ }
1344
+ var countFormats = /* @__PURE__ */ new Map();
1345
+ function countFormat(locale) {
1346
+ const key = localeKey(locale);
1347
+ let format = countFormats.get(key);
1348
+ if (format === void 0) {
1349
+ const numberFormat = new Intl.NumberFormat(locale, {
1350
+ maximumFractionDigits: 0
1351
+ });
1352
+ format = (count) => numberFormat.format(count);
1353
+ countFormats.set(key, format);
1354
+ }
1355
+ return format;
1356
+ }
1357
+ function columnCount(n, count, change) {
1358
+ return count === 1 ? `1 column ${change}` : `${n(count)} columns ${change}`;
1359
+ }
1360
+ function searchResults(n, count) {
1361
+ if (count === 0) {
1362
+ return "No rows found";
1363
+ }
1364
+ return count === 1 ? "1 row found" : `${n(count)} rows found`;
1365
+ }
1366
+ function selectedCount(n, count, target) {
1367
+ const noun = target === "rows" ? "row" : "column";
1368
+ if (count === 0) {
1369
+ return `No ${noun}s selected`;
1370
+ }
1371
+ return count === 1 ? `1 ${noun} selected` : `${n(count)} ${noun}s selected`;
1372
+ }
1373
+ var operatorLabels = {
1374
+ eq: "Equals",
1375
+ ne: "Does not equal",
1376
+ contains: "Contains",
1377
+ notContains: "Does not contain",
1378
+ startsWith: "Starts with",
1379
+ endsWith: "Ends with",
1380
+ gt: "Greater than",
1381
+ gte: "Greater than or equal to",
1382
+ lt: "Less than",
1383
+ lte: "Less than or equal to",
1384
+ between: "Between",
1385
+ in: "Is one of",
1386
+ isEmpty: "Is blank",
1387
+ isNotEmpty: "Is not blank"
1388
+ };
1389
+ var dateOperatorLabels = {
1390
+ lt: "Before",
1391
+ lte: "On or before",
1392
+ gt: "After",
1393
+ gte: "On or after"
1394
+ };
1395
+ function filterOperatorLabel(operator, family) {
1396
+ return (family === "date" ? dateOperatorLabels[operator] : void 0) ?? operatorLabels[operator];
1397
+ }
1398
+ function filterSearchFirst(n, total) {
1399
+ return total === 1 ? "Type to search 1 value" : `Type to search ${n(total)} values`;
1400
+ }
1401
+ function filterResults(n, shown, total) {
1402
+ return `${n(shown)} of ${n(total)} ${total === 1 ? "row" : "rows"}`;
1403
+ }
1404
+ var filterValueRequests = {
1405
+ text: "Enter a value",
1406
+ number: "Enter a number",
1407
+ date: "Enter a date",
1408
+ boolean: "Choose a value"
1409
+ };
1410
+ var filterOperatorMenus = {
1411
+ text: "Text filters",
1412
+ number: "Number filters",
1413
+ date: "Date filters",
1414
+ boolean: "Boolean filters"
1415
+ };
1416
+ function copied(n, count, unit) {
1417
+ return count === 1 ? `1 ${unit.slice(0, -1)} copied` : `${n(count)} ${unit} copied`;
1418
+ }
1419
+ function createDefaultMessages(locale) {
1420
+ const n = countFormat(locale);
1421
+ return {
1422
+ pagerLabel: "Pagination",
1423
+ firstPage: "First",
1424
+ previousPage: "Previous",
1425
+ nextPage: "Next",
1426
+ lastPage: "Last",
1427
+ pageSizeLabel: "Rows per page",
1428
+ pageButtonLabel: (page) => `Page ${n(page)}`,
1429
+ pageStatus: (page, pageCount) => `Page ${n(page)} of ${n(pageCount)}`,
1430
+ loadingMore: "Loading more\u2026",
1431
+ loading: "Loading\u2026",
1432
+ noRows: "No rows to show",
1433
+ noMatchingRows: "No rows match the current filter",
1434
+ booleanTrue: "true",
1435
+ booleanFalse: "false",
1436
+ blankGroupValue: "(blank)",
1437
+ groupByBarLabel: "Grouped by",
1438
+ groupByBarPlaceholder: "Drag a column here to group by it",
1439
+ groupByChipLabel: (columnName2, level, levelCount) => levelCount > 1 ? `${columnName2}, level ${n(level)} of ${n(levelCount)}` : columnName2,
1440
+ removeGroupBy: (columnName2) => `Stop grouping by ${columnName2}`,
1441
+ columnResized: (columnName2, width) => `${columnName2}, ${n(width)} pixels wide`,
1442
+ columnMoved: (columnName2, position, columnCount2) => `${columnName2}, column ${n(position)} of ${n(columnCount2)}`,
1443
+ columnSorted: (columnName2, direction, key, keyCount) => {
1444
+ const sorted = `${columnName2} sorted ${direction === "asc" ? "ascending" : "descending"}`;
1445
+ return keyCount > 1 ? `${sorted}, key ${n(key)} of ${n(keyCount)}` : sorted;
1446
+ },
1447
+ sortCleared: (columnName2) => `${columnName2}, sort cleared`,
1448
+ groupedBy: (columnName2, level, levelCount) => levelCount > 1 ? `Grouped by ${columnName2}, level ${n(level)} of ${n(levelCount)}` : `Grouped by ${columnName2}`,
1449
+ groupingRemoved: (columnName2) => `${columnName2}, grouping removed`,
1450
+ groupExpanded: "Group expanded",
1451
+ groupCollapsed: "Group collapsed",
1452
+ allGroupsExpanded: "All groups expanded",
1453
+ allGroupsCollapsed: "All groups collapsed",
1454
+ selectedCount: (count, target) => selectedCount(n, count, target),
1455
+ cellSelected: (columnName2, rowNumber) => `${columnName2}, row ${n(rowNumber)}, selected`,
1456
+ columnHidden: (columnName2) => `${columnName2}, column hidden`,
1457
+ columnShown: (columnName2) => `${columnName2}, column shown`,
1458
+ columnsHidden: (count) => columnCount(n, count, "hidden"),
1459
+ columnsShown: (count) => columnCount(n, count, "shown"),
1460
+ columnPinned: (columnName2, edge) => `${columnName2}, pinned to ${edge}`,
1461
+ columnUnpinned: (columnName2) => `${columnName2}, unpinned`,
1462
+ columnsAutoFitted: (count) => columnCount(n, count, "autofitted"),
1463
+ headerMenuLabel: (columnName2) => `${columnName2} column menu`,
1464
+ cellMenuLabel: "Row menu",
1465
+ groupMenuLabel: "Group menu",
1466
+ bodyMenuLabel: "Grid menu",
1467
+ sortAscending: "Sort ascending",
1468
+ sortDescending: "Sort descending",
1469
+ clearSort: "Clear sort",
1470
+ clearAllSorting: "Clear all sorting",
1471
+ groupByColumn: (columnName2) => `Group by ${columnName2}`,
1472
+ ungroupAll: "Ungroup all",
1473
+ expandAllGroups: "Expand all groups",
1474
+ collapseAllGroups: "Collapse all groups",
1475
+ hideColumn: "Hide column",
1476
+ pinToStart: "Pin to start",
1477
+ pinToEnd: "Pin to end",
1478
+ unpinColumn: "Unpin",
1479
+ autoFitColumn: "Autofit column",
1480
+ autoFitAllColumns: "Autofit all columns",
1481
+ selectAllRows: "Select all rows",
1482
+ clearSelection: "Clear selection",
1483
+ clearFilters: "Clear filters",
1484
+ chooseColumns: "Choose columns",
1485
+ toolbarLabel: "Grid toolbar",
1486
+ searchLabel: "Search",
1487
+ searchPlaceholder: "Search\u2026",
1488
+ moreToolbarItems: "More",
1489
+ searchResults: (count) => searchResults(n, count),
1490
+ columnChooserLabel: "Columns",
1491
+ columnChooserSearchLabel: "Search columns",
1492
+ showAllColumns: "Show all",
1493
+ noMatchingColumns: "No matching columns",
1494
+ filterOperatorLabel,
1495
+ filterBlanks: "(Blanks)",
1496
+ filterSearchFirst: (total) => filterSearchFirst(n, total),
1497
+ filterMoreValues: (count) => `${n(count)} more, refine the search`,
1498
+ openFilter: "Filter\u2026",
1499
+ clearColumnFilter: "Clear filter",
1500
+ filterMenuLabel: (columnName2) => `${columnName2} filter`,
1501
+ columnFiltered: "Filtered",
1502
+ applyFilter: "OK",
1503
+ cancelFilter: "Cancel",
1504
+ customFilter: "Custom filter",
1505
+ filterResults: (shown, total) => filterResults(n, shown, total),
1506
+ filterConditionLabel: (position) => `Condition ${n(position)}`,
1507
+ filterOperatorFieldLabel: "Operator",
1508
+ filterValueLabel: "Value",
1509
+ filterFromLabel: "From",
1510
+ filterToLabel: "To",
1511
+ filterCombinatorLabel: "Combine conditions",
1512
+ filterAnd: "And",
1513
+ filterOr: "Or",
1514
+ filterValueInvalid: (family) => filterValueRequests[family],
1515
+ filterSearchLabel: "Search values",
1516
+ filterSelectAll: "Select all",
1517
+ filterValuesLabel: "Values",
1518
+ filterByCondition: "Filtered by condition",
1519
+ filterOperatorMenu: (family) => filterOperatorMenus[family],
1520
+ filterBackToValues: "Back to values",
1521
+ exportMenu: "Export",
1522
+ exportCsv: "Export to CSV",
1523
+ exportJson: "Export to JSON",
1524
+ exportXlsx: "Export to Excel",
1525
+ exportPdf: "Export to PDF",
1526
+ exportSelectionCsv: "Export selection to CSV",
1527
+ exportSelectionJson: "Export selection to JSON",
1528
+ exportSelectionXlsx: "Export selection to Excel",
1529
+ exportFailed: "Export failed",
1530
+ editCell: "Edit cell",
1531
+ copyCell: "Copy cell",
1532
+ copyRow: "Copy row",
1533
+ copySelection: "Copy selection",
1534
+ copied: (count, unit) => copied(n, count, unit),
1535
+ copyFailed: "Copy failed",
1536
+ print: "Print",
1537
+ printFailed: "Print failed",
1538
+ cellEditUnreadable: (family) => filterValueRequests[family]
1539
+ };
1540
+ }
1541
+ var defaultMessages = createDefaultMessages();
1542
+ var localeDefaults = /* @__PURE__ */ new Map();
1543
+ function defaultsFor(locale) {
1544
+ if (locale === void 0) {
1545
+ return defaultMessages;
1546
+ }
1547
+ const key = localeKey(locale);
1548
+ let defaults = localeDefaults.get(key);
1549
+ if (defaults === void 0) {
1550
+ defaults = createDefaultMessages(locale);
1551
+ localeDefaults.set(key, defaults);
1552
+ }
1553
+ return defaults;
1554
+ }
1555
+ function resolveMessages(messages, locale) {
1556
+ const defaults = defaultsFor(locale);
1557
+ return messages === void 0 ? defaults : { ...defaults, ...messages };
1558
+ }
1559
+
1560
+ // src/filterMenu/operators.ts
1561
+ function filterOperatorFamily(type) {
1562
+ return kindOf(type);
1563
+ }
1564
+ var familyOperators = {
1565
+ text: [
1566
+ "contains",
1567
+ "notContains",
1568
+ "eq",
1569
+ "ne",
1570
+ "startsWith",
1571
+ "endsWith",
1572
+ "isEmpty",
1573
+ "isNotEmpty"
1574
+ ],
1575
+ number: [
1576
+ "eq",
1577
+ "ne",
1578
+ "gt",
1579
+ "gte",
1580
+ "lt",
1581
+ "lte",
1582
+ "between",
1583
+ "isEmpty",
1584
+ "isNotEmpty"
1585
+ ],
1586
+ date: ["eq", "ne", "lt", "gt", "between", "isEmpty", "isNotEmpty"],
1587
+ boolean: ["eq", "isEmpty", "isNotEmpty"]
1588
+ };
1589
+ var instantOperators = [
1590
+ "lt",
1591
+ "gt",
1592
+ "between",
1593
+ "isEmpty",
1594
+ "isNotEmpty"
1595
+ ];
1596
+ function defaultFilterOperators(type) {
1597
+ return type === "dateTime" || type === "time" ? instantOperators : familyOperators[filterOperatorFamily(type)];
1598
+ }
1599
+ function filterOperandArity(operator) {
1600
+ switch (operator) {
1601
+ case "isEmpty":
1602
+ case "isNotEmpty":
1603
+ return 0;
1604
+ case "between":
1605
+ return 2;
1606
+ case "eq":
1607
+ case "ne":
1608
+ case "contains":
1609
+ case "notContains":
1610
+ case "startsWith":
1611
+ case "endsWith":
1612
+ case "gt":
1613
+ case "gte":
1614
+ case "lt":
1615
+ case "lte":
1616
+ case "in":
1617
+ return 1;
1618
+ }
1619
+ }
1620
+ var NUMBER_INPUT = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
1621
+ var DATE_INPUT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?$/;
1622
+ function parseNumber(text) {
1623
+ const value = Number(text);
1624
+ return NUMBER_INPUT.test(text) && Number.isFinite(value) ? value : void 0;
1625
+ }
1626
+ function parseDate(text) {
1627
+ const match = DATE_INPUT.exec(text);
1628
+ if (match === null) {
1629
+ return void 0;
1630
+ }
1631
+ const [
1632
+ ,
1633
+ year,
1634
+ month,
1635
+ day,
1636
+ hours = "0",
1637
+ minutes = "0",
1638
+ seconds = "0",
1639
+ fraction = ""
1640
+ ] = match;
1641
+ if (Number(hours) > 23 || Number(minutes) > 59 || Number(seconds) > 59) {
1642
+ return void 0;
1643
+ }
1644
+ const date = new Date(
1645
+ Number(year),
1646
+ Number(month) - 1,
1647
+ Number(day),
1648
+ Number(hours),
1649
+ Number(minutes),
1650
+ Number(seconds),
1651
+ Number(fraction.padEnd(3, "0"))
1652
+ );
1653
+ return date.getFullYear() === Number(year) && date.getMonth() === Number(month) - 1 && date.getDate() === Number(day) ? date : void 0;
1654
+ }
1655
+ function parseBoolean(text) {
1656
+ if (text === "true") {
1657
+ return true;
1658
+ }
1659
+ return text === "false" ? false : void 0;
1660
+ }
1661
+ function parseFilterOperand(text, type) {
1662
+ if (text === "") {
1663
+ return void 0;
1664
+ }
1665
+ switch (filterOperatorFamily(type)) {
1666
+ case "text":
1667
+ return text;
1668
+ case "number":
1669
+ return parseNumber(text.trim());
1670
+ case "date":
1671
+ return parseDate(text.trim());
1672
+ case "boolean":
1673
+ return parseBoolean(text.trim());
1674
+ }
1675
+ }
1676
+ function pad(value, width = 2) {
1677
+ return String(value).padStart(width, "0");
1678
+ }
1679
+ function dayInput(date) {
1680
+ return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
1681
+ }
1682
+ function momentInput(date) {
1683
+ const minute = `${dayInput(date)}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
1684
+ const seconds = date.getSeconds();
1685
+ const milliseconds = date.getMilliseconds();
1686
+ if (seconds === 0 && milliseconds === 0) {
1687
+ return minute;
1688
+ }
1689
+ const second = `${minute}:${pad(seconds)}`;
1690
+ return milliseconds === 0 ? second : `${second}.${pad(milliseconds, 3)}`;
1691
+ }
1692
+ function formatFilterOperand(value, type) {
1693
+ if (value === null || value === void 0) {
1694
+ return "";
1695
+ }
1696
+ const date = filterOperatorFamily(type) === "date" ? toDate(value) : void 0;
1697
+ if (date === void 0) {
1698
+ return String(value);
1699
+ }
1700
+ return type === "date" ? dayInput(date) : momentInput(date);
1701
+ }
1702
+
1703
+ // src/util/cellText.ts
1704
+ var UNREADABLE = { kind: "unreadable" };
1705
+ function parseCellText(text, type) {
1706
+ if (filterOperatorFamily(type) === "text") {
1707
+ return { kind: "value", value: text };
1708
+ }
1709
+ if (text.trim() === "") {
1710
+ return { kind: "value", value: null };
1711
+ }
1712
+ const value = parseFilterOperand(text, type);
1713
+ return value === void 0 ? UNREADABLE : { kind: "value", value };
1714
+ }
1715
+ function cellDate(value) {
1716
+ if (typeof value === "string") {
1717
+ const local = parseFilterOperand(value.trim(), "date");
1718
+ if (local instanceof Date) {
1719
+ return local;
1720
+ }
1721
+ }
1722
+ return toDate(value);
1723
+ }
1724
+ function formatCellEditText(value, type) {
1725
+ if (isEmptyCell(value)) {
1726
+ return "";
1727
+ }
1728
+ const date = filterOperatorFamily(type) === "date" ? cellDate(value) : void 0;
1729
+ return date === void 0 ? String(value) : formatFilterOperand(date, type);
1730
+ }
1731
+ function sameCellValue(current, next, type) {
1732
+ if (isEmptyCell(current) && isEmptyCell(next)) {
1733
+ return true;
1734
+ }
1735
+ if (filterOperatorFamily(type) === "date") {
1736
+ const a = cellDate(current);
1737
+ const b = cellDate(next);
1738
+ if (a !== void 0 && b !== void 0) {
1739
+ return a.getTime() === b.getTime();
1740
+ }
1741
+ }
1742
+ return Object.is(current, next);
1743
+ }
1744
+
1745
+ // src/util/cellEdit.ts
1746
+ var NO_CELL_EDIT = { kind: "idle" };
1747
+ function settled(state) {
1748
+ return { state, committed: null };
1749
+ }
1750
+ function cellEditReducer(state, action) {
1751
+ if (state.kind === "idle") {
1752
+ return settled(
1753
+ action.type === "start" ? {
1754
+ kind: "editing",
1755
+ rowId: action.rowId,
1756
+ columnId: action.columnId,
1757
+ draft: action.draft
1758
+ } : state
1759
+ );
1760
+ }
1761
+ switch (action.type) {
1762
+ case "start":
1763
+ return settled(state);
1764
+ case "setDraft":
1765
+ return settled({
1766
+ kind: "editing",
1767
+ rowId: state.rowId,
1768
+ columnId: state.columnId,
1769
+ draft: action.draft
1770
+ });
1771
+ case "commit":
1772
+ return commitDraft(state, action);
1773
+ case "cancel":
1774
+ return settled(NO_CELL_EDIT);
1775
+ }
1776
+ }
1777
+ function commitDraft(state, { row, column, messages }) {
1778
+ if (state.draft.kind === "current") {
1779
+ return settled(NO_CELL_EDIT);
1780
+ }
1781
+ const reading = readDraft(state.draft, row.row, column.column, messages);
1782
+ if (reading.kind === "refused") {
1783
+ return settled({ ...state, kind: "invalid", message: reading.message });
1784
+ }
1785
+ const { field, type, validate } = column.column;
1786
+ const previousValue = accessDotted(row.row, field);
1787
+ if (sameCellValue(previousValue, reading.value, type)) {
1788
+ return settled(NO_CELL_EDIT);
1789
+ }
1790
+ const message = validate?.(reading.value, row.row) ?? null;
1791
+ if (message !== null) {
1792
+ return settled({ ...state, kind: "invalid", message });
1793
+ }
1794
+ return {
1795
+ state: NO_CELL_EDIT,
1796
+ committed: {
1797
+ rowId: row.rowId,
1798
+ columnId: column.id,
1799
+ field,
1800
+ row: row.row,
1801
+ value: reading.value,
1802
+ previousValue
1803
+ }
1804
+ };
1805
+ }
1806
+ function readDraft(draft, row, column, messages) {
1807
+ const unreadable = {
1808
+ kind: "refused",
1809
+ message: messages.cellEditUnreadable(filterOperatorFamily(column.type))
1810
+ };
1811
+ switch (draft.kind) {
1812
+ case "value":
1813
+ return { kind: "value", value: draft.value };
1814
+ case "unreadable":
1815
+ return unreadable;
1816
+ case "text": {
1817
+ if (column.valueParser !== void 0) {
1818
+ return { kind: "value", value: column.valueParser(draft.text, row) };
1819
+ }
1820
+ const parsed = parseCellText(draft.text, column.type);
1821
+ return parsed.kind === "value" ? { kind: "value", value: parsed.value } : unreadable;
1822
+ }
1823
+ }
1824
+ }
1825
+ function isColumnEditable(column, row) {
1826
+ const { editable } = column;
1827
+ return typeof editable === "function" ? editable(row) : editable === true;
1828
+ }
1829
+ function isCellEditable(view, cell) {
1830
+ const entry = view.displayDataRows.find(
1831
+ (candidate) => candidate.rowId === cell.rowId
1832
+ );
1833
+ const column = view.columns.find(
1834
+ (candidate) => candidate.id === cell.columnId
1835
+ );
1836
+ return entry !== void 0 && column !== void 0 && isColumnEditable(column.column, entry.row);
1837
+ }
1838
+
1340
1839
  // src/util/format.ts
1341
1840
  var DATE_FIELDS = {
1342
1841
  year: "numeric",
@@ -1373,7 +1872,7 @@ function cached(format, key, create) {
1373
1872
  byKey.set(key, formatter);
1374
1873
  return formatter;
1375
1874
  }
1376
- function localeKey(locale) {
1875
+ function localeKey2(locale) {
1377
1876
  return typeof locale === "string" ? locale : locale?.join(",") ?? "";
1378
1877
  }
1379
1878
  function isNumericType(type) {
@@ -1400,7 +1899,7 @@ function dateOptions(type, format) {
1400
1899
  function formatNumber(value, type, format, locale) {
1401
1900
  const formatter = cached(
1402
1901
  format,
1403
- `number|${type ?? ""}|${localeKey(locale)}`,
1902
+ `number|${type ?? ""}|${localeKey2(locale)}`,
1404
1903
  () => new Intl.NumberFormat(
1405
1904
  locale,
1406
1905
  numberOptions(type, format)
@@ -1414,7 +1913,7 @@ function formatDate(value, type, format, locale) {
1414
1913
  }
1415
1914
  const formatter = cached(
1416
1915
  format,
1417
- `date|${type ?? ""}|${localeKey(locale)}`,
1916
+ `date|${type ?? ""}|${localeKey2(locale)}`,
1418
1917
  () => new Intl.DateTimeFormat(
1419
1918
  locale,
1420
1919
  dateOptions(type, format)
@@ -2011,166 +2510,23 @@ function toJson(table, options = {}) {
2011
2510
  // src/export/writer.ts
2012
2511
  var csvWriter = {
2013
2512
  format: "csv",
2014
- fileExtension: "csv",
2015
- mimeType: "text/csv;charset=utf-8",
2016
- write: (table, { locale, options }) => toCsv(table, { locale, ...options.csv })
2017
- };
2018
- var jsonWriter = {
2019
- format: "json",
2020
- fileExtension: "json",
2021
- mimeType: "application/json",
2022
- write: (table, { options }) => toJson(table, options.json)
2023
- };
2024
- function resolveExportWriters(writers) {
2025
- return new Map(
2026
- [csvWriter, jsonWriter, ...writers ?? []].map((writer) => [
2027
- writer.format,
2028
- writer
2029
- ])
2030
- );
2031
- }
2032
-
2033
- // src/filterMenu/operators.ts
2034
- function filterOperatorFamily(type) {
2035
- return kindOf(type);
2036
- }
2037
- var familyOperators = {
2038
- text: [
2039
- "contains",
2040
- "notContains",
2041
- "eq",
2042
- "ne",
2043
- "startsWith",
2044
- "endsWith",
2045
- "isEmpty",
2046
- "isNotEmpty"
2047
- ],
2048
- number: [
2049
- "eq",
2050
- "ne",
2051
- "gt",
2052
- "gte",
2053
- "lt",
2054
- "lte",
2055
- "between",
2056
- "isEmpty",
2057
- "isNotEmpty"
2058
- ],
2059
- date: ["eq", "ne", "lt", "gt", "between", "isEmpty", "isNotEmpty"],
2060
- boolean: ["eq", "isEmpty", "isNotEmpty"]
2061
- };
2062
- var instantOperators = [
2063
- "lt",
2064
- "gt",
2065
- "between",
2066
- "isEmpty",
2067
- "isNotEmpty"
2068
- ];
2069
- function defaultFilterOperators(type) {
2070
- return type === "dateTime" || type === "time" ? instantOperators : familyOperators[filterOperatorFamily(type)];
2071
- }
2072
- function filterOperandArity(operator) {
2073
- switch (operator) {
2074
- case "isEmpty":
2075
- case "isNotEmpty":
2076
- return 0;
2077
- case "between":
2078
- return 2;
2079
- case "eq":
2080
- case "ne":
2081
- case "contains":
2082
- case "notContains":
2083
- case "startsWith":
2084
- case "endsWith":
2085
- case "gt":
2086
- case "gte":
2087
- case "lt":
2088
- case "lte":
2089
- case "in":
2090
- return 1;
2091
- }
2092
- }
2093
- var NUMBER_INPUT = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
2094
- var DATE_INPUT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?$/;
2095
- function parseNumber(text) {
2096
- const value = Number(text);
2097
- return NUMBER_INPUT.test(text) && Number.isFinite(value) ? value : void 0;
2098
- }
2099
- function parseDate(text) {
2100
- const match = DATE_INPUT.exec(text);
2101
- if (match === null) {
2102
- return void 0;
2103
- }
2104
- const [
2105
- ,
2106
- year,
2107
- month,
2108
- day,
2109
- hours = "0",
2110
- minutes = "0",
2111
- seconds = "0",
2112
- fraction = ""
2113
- ] = match;
2114
- if (Number(hours) > 23 || Number(minutes) > 59 || Number(seconds) > 59) {
2115
- return void 0;
2116
- }
2117
- const date = new Date(
2118
- Number(year),
2119
- Number(month) - 1,
2120
- Number(day),
2121
- Number(hours),
2122
- Number(minutes),
2123
- Number(seconds),
2124
- Number(fraction.padEnd(3, "0"))
2125
- );
2126
- return date.getFullYear() === Number(year) && date.getMonth() === Number(month) - 1 && date.getDate() === Number(day) ? date : void 0;
2127
- }
2128
- function parseBoolean(text) {
2129
- if (text === "true") {
2130
- return true;
2131
- }
2132
- return text === "false" ? false : void 0;
2133
- }
2134
- function parseFilterOperand(text, type) {
2135
- if (text === "") {
2136
- return void 0;
2137
- }
2138
- switch (filterOperatorFamily(type)) {
2139
- case "text":
2140
- return text;
2141
- case "number":
2142
- return parseNumber(text.trim());
2143
- case "date":
2144
- return parseDate(text.trim());
2145
- case "boolean":
2146
- return parseBoolean(text.trim());
2147
- }
2148
- }
2149
- function pad(value, width = 2) {
2150
- return String(value).padStart(width, "0");
2151
- }
2152
- function dayInput(date) {
2153
- return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
2154
- }
2155
- function momentInput(date) {
2156
- const minute = `${dayInput(date)}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
2157
- const seconds = date.getSeconds();
2158
- const milliseconds = date.getMilliseconds();
2159
- if (seconds === 0 && milliseconds === 0) {
2160
- return minute;
2161
- }
2162
- const second = `${minute}:${pad(seconds)}`;
2163
- return milliseconds === 0 ? second : `${second}.${pad(milliseconds, 3)}`;
2164
- }
2165
- function formatFilterOperand(value, type) {
2166
- if (value === null || value === void 0) {
2167
- return "";
2168
- }
2169
- const date = filterOperatorFamily(type) === "date" ? toDate(value) : void 0;
2170
- if (date === void 0) {
2171
- return String(value);
2172
- }
2173
- return type === "date" ? dayInput(date) : momentInput(date);
2513
+ fileExtension: "csv",
2514
+ mimeType: "text/csv;charset=utf-8",
2515
+ write: (table, { locale, options }) => toCsv(table, { locale, ...options.csv })
2516
+ };
2517
+ var jsonWriter = {
2518
+ format: "json",
2519
+ fileExtension: "json",
2520
+ mimeType: "application/json",
2521
+ write: (table, { options }) => toJson(table, options.json)
2522
+ };
2523
+ function resolveExportWriters(writers) {
2524
+ return new Map(
2525
+ [csvWriter, jsonWriter, ...writers ?? []].map((writer) => [
2526
+ writer.format,
2527
+ writer
2528
+ ])
2529
+ );
2174
2530
  }
2175
2531
 
2176
2532
  // src/filterMenu/options.ts
@@ -2195,224 +2551,6 @@ function resolveColumnFilterMenu(options, column) {
2195
2551
  };
2196
2552
  }
2197
2553
 
2198
- // src/messages.ts
2199
- function localeKey2(locale) {
2200
- return typeof locale === "string" ? locale : locale?.join(",") ?? "";
2201
- }
2202
- var countFormats = /* @__PURE__ */ new Map();
2203
- function countFormat(locale) {
2204
- const key = localeKey2(locale);
2205
- let format = countFormats.get(key);
2206
- if (format === void 0) {
2207
- const numberFormat = new Intl.NumberFormat(locale, {
2208
- maximumFractionDigits: 0
2209
- });
2210
- format = (count) => numberFormat.format(count);
2211
- countFormats.set(key, format);
2212
- }
2213
- return format;
2214
- }
2215
- function columnCount(n, count, change) {
2216
- return count === 1 ? `1 column ${change}` : `${n(count)} columns ${change}`;
2217
- }
2218
- function searchResults(n, count) {
2219
- if (count === 0) {
2220
- return "No rows found";
2221
- }
2222
- return count === 1 ? "1 row found" : `${n(count)} rows found`;
2223
- }
2224
- function selectedCount(n, count, target) {
2225
- const noun = target === "rows" ? "row" : "column";
2226
- if (count === 0) {
2227
- return `No ${noun}s selected`;
2228
- }
2229
- return count === 1 ? `1 ${noun} selected` : `${n(count)} ${noun}s selected`;
2230
- }
2231
- var operatorLabels = {
2232
- eq: "Equals",
2233
- ne: "Does not equal",
2234
- contains: "Contains",
2235
- notContains: "Does not contain",
2236
- startsWith: "Starts with",
2237
- endsWith: "Ends with",
2238
- gt: "Greater than",
2239
- gte: "Greater than or equal to",
2240
- lt: "Less than",
2241
- lte: "Less than or equal to",
2242
- between: "Between",
2243
- in: "Is one of",
2244
- isEmpty: "Is blank",
2245
- isNotEmpty: "Is not blank"
2246
- };
2247
- var dateOperatorLabels = {
2248
- lt: "Before",
2249
- lte: "On or before",
2250
- gt: "After",
2251
- gte: "On or after"
2252
- };
2253
- function filterOperatorLabel(operator, family) {
2254
- return (family === "date" ? dateOperatorLabels[operator] : void 0) ?? operatorLabels[operator];
2255
- }
2256
- function filterSearchFirst(n, total) {
2257
- return total === 1 ? "Type to search 1 value" : `Type to search ${n(total)} values`;
2258
- }
2259
- function filterResults(n, shown, total) {
2260
- return `${n(shown)} of ${n(total)} ${total === 1 ? "row" : "rows"}`;
2261
- }
2262
- var filterValueRequests = {
2263
- text: "Enter a value",
2264
- number: "Enter a number",
2265
- date: "Enter a date",
2266
- boolean: "Choose a value"
2267
- };
2268
- var filterOperatorMenus = {
2269
- text: "Text filters",
2270
- number: "Number filters",
2271
- date: "Date filters",
2272
- boolean: "Boolean filters"
2273
- };
2274
- function copied(n, count, unit) {
2275
- return count === 1 ? `1 ${unit.slice(0, -1)} copied` : `${n(count)} ${unit} copied`;
2276
- }
2277
- function createDefaultMessages(locale) {
2278
- const n = countFormat(locale);
2279
- return {
2280
- pagerLabel: "Pagination",
2281
- firstPage: "First",
2282
- previousPage: "Previous",
2283
- nextPage: "Next",
2284
- lastPage: "Last",
2285
- pageSizeLabel: "Rows per page",
2286
- pageButtonLabel: (page) => `Page ${n(page)}`,
2287
- pageStatus: (page, pageCount) => `Page ${n(page)} of ${n(pageCount)}`,
2288
- loadingMore: "Loading more\u2026",
2289
- loading: "Loading\u2026",
2290
- noRows: "No rows to show",
2291
- noMatchingRows: "No rows match the current filter",
2292
- booleanTrue: "true",
2293
- booleanFalse: "false",
2294
- blankGroupValue: "(blank)",
2295
- groupByBarLabel: "Grouped by",
2296
- groupByBarPlaceholder: "Drag a column here to group by it",
2297
- groupByChipLabel: (columnName2, level, levelCount) => levelCount > 1 ? `${columnName2}, level ${n(level)} of ${n(levelCount)}` : columnName2,
2298
- removeGroupBy: (columnName2) => `Stop grouping by ${columnName2}`,
2299
- columnResized: (columnName2, width) => `${columnName2}, ${n(width)} pixels wide`,
2300
- columnMoved: (columnName2, position, columnCount2) => `${columnName2}, column ${n(position)} of ${n(columnCount2)}`,
2301
- columnSorted: (columnName2, direction, key, keyCount) => {
2302
- const sorted = `${columnName2} sorted ${direction === "asc" ? "ascending" : "descending"}`;
2303
- return keyCount > 1 ? `${sorted}, key ${n(key)} of ${n(keyCount)}` : sorted;
2304
- },
2305
- sortCleared: (columnName2) => `${columnName2}, sort cleared`,
2306
- groupedBy: (columnName2, level, levelCount) => levelCount > 1 ? `Grouped by ${columnName2}, level ${n(level)} of ${n(levelCount)}` : `Grouped by ${columnName2}`,
2307
- groupingRemoved: (columnName2) => `${columnName2}, grouping removed`,
2308
- groupExpanded: "Group expanded",
2309
- groupCollapsed: "Group collapsed",
2310
- allGroupsExpanded: "All groups expanded",
2311
- allGroupsCollapsed: "All groups collapsed",
2312
- selectedCount: (count, target) => selectedCount(n, count, target),
2313
- cellSelected: (columnName2, rowNumber) => `${columnName2}, row ${n(rowNumber)}, selected`,
2314
- columnHidden: (columnName2) => `${columnName2}, column hidden`,
2315
- columnShown: (columnName2) => `${columnName2}, column shown`,
2316
- columnsHidden: (count) => columnCount(n, count, "hidden"),
2317
- columnsShown: (count) => columnCount(n, count, "shown"),
2318
- columnPinned: (columnName2, edge) => `${columnName2}, pinned to ${edge}`,
2319
- columnUnpinned: (columnName2) => `${columnName2}, unpinned`,
2320
- columnsAutoFitted: (count) => columnCount(n, count, "autofitted"),
2321
- headerMenuLabel: (columnName2) => `${columnName2} column menu`,
2322
- cellMenuLabel: "Row menu",
2323
- groupMenuLabel: "Group menu",
2324
- bodyMenuLabel: "Grid menu",
2325
- sortAscending: "Sort ascending",
2326
- sortDescending: "Sort descending",
2327
- clearSort: "Clear sort",
2328
- clearAllSorting: "Clear all sorting",
2329
- groupByColumn: (columnName2) => `Group by ${columnName2}`,
2330
- ungroupAll: "Ungroup all",
2331
- expandAllGroups: "Expand all groups",
2332
- collapseAllGroups: "Collapse all groups",
2333
- hideColumn: "Hide column",
2334
- pinToStart: "Pin to start",
2335
- pinToEnd: "Pin to end",
2336
- unpinColumn: "Unpin",
2337
- autoFitColumn: "Autofit column",
2338
- autoFitAllColumns: "Autofit all columns",
2339
- selectAllRows: "Select all rows",
2340
- clearSelection: "Clear selection",
2341
- clearFilters: "Clear filters",
2342
- chooseColumns: "Choose columns",
2343
- toolbarLabel: "Grid toolbar",
2344
- searchLabel: "Search",
2345
- searchPlaceholder: "Search\u2026",
2346
- moreToolbarItems: "More",
2347
- searchResults: (count) => searchResults(n, count),
2348
- columnChooserLabel: "Columns",
2349
- columnChooserSearchLabel: "Search columns",
2350
- showAllColumns: "Show all",
2351
- noMatchingColumns: "No matching columns",
2352
- filterOperatorLabel,
2353
- filterBlanks: "(Blanks)",
2354
- filterSearchFirst: (total) => filterSearchFirst(n, total),
2355
- filterMoreValues: (count) => `${n(count)} more, refine the search`,
2356
- openFilter: "Filter\u2026",
2357
- clearColumnFilter: "Clear filter",
2358
- filterMenuLabel: (columnName2) => `${columnName2} filter`,
2359
- columnFiltered: "Filtered",
2360
- applyFilter: "OK",
2361
- cancelFilter: "Cancel",
2362
- customFilter: "Custom filter",
2363
- filterResults: (shown, total) => filterResults(n, shown, total),
2364
- filterConditionLabel: (position) => `Condition ${n(position)}`,
2365
- filterOperatorFieldLabel: "Operator",
2366
- filterValueLabel: "Value",
2367
- filterFromLabel: "From",
2368
- filterToLabel: "To",
2369
- filterCombinatorLabel: "Combine conditions",
2370
- filterAnd: "And",
2371
- filterOr: "Or",
2372
- filterValueInvalid: (family) => filterValueRequests[family],
2373
- filterSearchLabel: "Search values",
2374
- filterSelectAll: "Select all",
2375
- filterValuesLabel: "Values",
2376
- filterByCondition: "Filtered by condition",
2377
- filterOperatorMenu: (family) => filterOperatorMenus[family],
2378
- filterBackToValues: "Back to values",
2379
- exportMenu: "Export",
2380
- exportCsv: "Export to CSV",
2381
- exportJson: "Export to JSON",
2382
- exportXlsx: "Export to Excel",
2383
- exportPdf: "Export to PDF",
2384
- exportSelectionCsv: "Export selection to CSV",
2385
- exportSelectionJson: "Export selection to JSON",
2386
- exportSelectionXlsx: "Export selection to Excel",
2387
- exportFailed: "Export failed",
2388
- copyCell: "Copy cell",
2389
- copyRow: "Copy row",
2390
- copySelection: "Copy selection",
2391
- copied: (count, unit) => copied(n, count, unit),
2392
- copyFailed: "Copy failed",
2393
- print: "Print",
2394
- printFailed: "Print failed"
2395
- };
2396
- }
2397
- var defaultMessages = createDefaultMessages();
2398
- var localeDefaults = /* @__PURE__ */ new Map();
2399
- function defaultsFor(locale) {
2400
- if (locale === void 0) {
2401
- return defaultMessages;
2402
- }
2403
- const key = localeKey2(locale);
2404
- let defaults = localeDefaults.get(key);
2405
- if (defaults === void 0) {
2406
- defaults = createDefaultMessages(locale);
2407
- localeDefaults.set(key, defaults);
2408
- }
2409
- return defaults;
2410
- }
2411
- function resolveMessages(messages, locale) {
2412
- const defaults = defaultsFor(locale);
2413
- return messages === void 0 ? defaults : { ...defaults, ...messages };
2414
- }
2415
-
2416
2554
  // src/util/filterEditor.ts
2417
2555
  function touchesColumn(entry, columnId) {
2418
2556
  return entry.kind === "group" ? entry.entries.some((nested) => touchesColumn(nested, columnId)) : entry.columnId === columnId;
@@ -2831,6 +2969,10 @@ function exportCommand({
2831
2969
  }
2832
2970
  };
2833
2971
  }
2972
+ function editableCell(context) {
2973
+ const { target } = context;
2974
+ return target.area === "cell" && isCellEditable(context.view, target) ? target : null;
2975
+ }
2834
2976
  function cellRequest(context, kind) {
2835
2977
  const { target } = context;
2836
2978
  if (target.area !== "cell") {
@@ -3087,6 +3229,20 @@ function builtInCommands() {
3087
3229
  label: ({ exportSelectionXlsx }) => exportSelectionXlsx,
3088
3230
  selection: true
3089
3231
  }),
3232
+ // Shown only on a cell an edit could start on, so a grid with no
3233
+ // editable column lists nothing new.
3234
+ {
3235
+ id: "edit.cell",
3236
+ label: ({ messages }) => messages.editCell,
3237
+ shortcut: "F2",
3238
+ isVisible: (context) => editableCell(context) !== null,
3239
+ execute: (context) => {
3240
+ const target = editableCell(context);
3241
+ if (target !== null) {
3242
+ context.actions.startCellEdit(target);
3243
+ }
3244
+ }
3245
+ },
3090
3246
  copyCommand({
3091
3247
  id: "copy.cell",
3092
3248
  label: ({ copyCell }) => copyCell,
@@ -3279,6 +3435,8 @@ var defaultContextMenu = {
3279
3435
  "column.unpin"
3280
3436
  ],
3281
3437
  cell: [
3438
+ "edit.cell",
3439
+ "separator",
3282
3440
  "copy.cell",
3283
3441
  "copy.row",
3284
3442
  "copy.selection",
@@ -3526,6 +3684,20 @@ export {
3526
3684
  isColumnVisible,
3527
3685
  applyColumnVisibility,
3528
3686
  setColumnVisibility,
3687
+ createDefaultMessages,
3688
+ defaultMessages,
3689
+ resolveMessages,
3690
+ filterOperatorFamily,
3691
+ defaultFilterOperators,
3692
+ filterOperandArity,
3693
+ parseFilterOperand,
3694
+ formatFilterOperand,
3695
+ parseCellText,
3696
+ formatCellEditText,
3697
+ NO_CELL_EDIT,
3698
+ cellEditReducer,
3699
+ isColumnEditable,
3700
+ isCellEditable,
3529
3701
  formatCellValue,
3530
3702
  formatAggregateValue,
3531
3703
  formatGroupValue,
@@ -3541,16 +3713,8 @@ export {
3541
3713
  csvWriter,
3542
3714
  jsonWriter,
3543
3715
  resolveExportWriters,
3544
- filterOperatorFamily,
3545
- defaultFilterOperators,
3546
- filterOperandArity,
3547
- parseFilterOperand,
3548
- formatFilterOperand,
3549
3716
  DEFAULT_FILTER_VALUE_LIMIT,
3550
3717
  resolveColumnFilterMenu,
3551
- createDefaultMessages,
3552
- defaultMessages,
3553
- resolveMessages,
3554
3718
  touchesColumn,
3555
3719
  describeColumnFilter,
3556
3720
  isColumnFiltered,
@@ -3580,4 +3744,4 @@ export {
3580
3744
  clampFocus,
3581
3745
  nextFocusForKey
3582
3746
  };
3583
- //# sourceMappingURL=chunk-RYMILPCT.js.map
3747
+ //# sourceMappingURL=chunk-EUYR2GJH.js.map