@nanahoshi/mona-ui 0.39.1 → 0.40.0

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.
Files changed (61) hide show
  1. package/docs/api/grid.md +214 -17
  2. package/docs/api/i18n.md +2 -0
  3. package/docs/api/locales.md +14 -14
  4. package/docs/grid-selection.md +134 -9
  5. package/docs/grid-state-export.md +56 -6
  6. package/docs/grid-tree.md +279 -0
  7. package/fesm2022/{nanahoshi-mona-ui-grid-grid-colgroup.component-Lv3GunpV.mjs → nanahoshi-mona-ui-grid-grid-colgroup.component-DpszxgFY.mjs} +2 -2
  8. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-BYH9XbCV.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-CpvzAcX8.mjs} +4 -3
  9. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BoSXXLKQ.mjs → nanahoshi-mona-ui-grid-grid-list.component-tRmEWiQR.mjs} +5 -5
  10. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Df2gfS0X.mjs → nanahoshi-mona-ui-grid-grid-row.component-eET6dh2Q.mjs} +52 -35
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-xjrcCXXF.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-8h2EMexB.mjs} +5 -5
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs → nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs} +646 -20
  13. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1663 -22
  14. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +8 -0
  15. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +2 -0
  16. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +8 -0
  17. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +8 -0
  18. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +8 -0
  19. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +2 -0
  20. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +8 -0
  21. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +2 -0
  22. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +2 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +2 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +8 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +2 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +2 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +2 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +2 -0
  29. package/i18n/catalogs/en-US.messages.json +2 -0
  30. package/llms.txt +4 -3
  31. package/locales/ar-sa/ar-sa.messages.json +2 -0
  32. package/locales/de-de/de-de.messages.json +2 -0
  33. package/locales/es-es/es-es.messages.json +2 -0
  34. package/locales/fr-fr/fr-fr.messages.json +2 -0
  35. package/locales/id-id/id-id.messages.json +2 -0
  36. package/locales/it-it/it-it.messages.json +2 -0
  37. package/locales/ja-jp/ja-jp.messages.json +2 -0
  38. package/locales/ko-kr/ko-kr.messages.json +2 -0
  39. package/locales/pl-pl/pl-pl.messages.json +2 -0
  40. package/locales/pt-br/pt-br.messages.json +2 -0
  41. package/locales/ru-ru/ru-ru.messages.json +2 -0
  42. package/locales/tr-tr/tr-tr.messages.json +2 -0
  43. package/locales/zh-cn/zh-cn.messages.json +2 -0
  44. package/locales/zh-tw/zh-tw.messages.json +2 -0
  45. package/package.json +1 -1
  46. package/types/nanahoshi-mona-ui-grid.d.ts +305 -3
  47. package/types/nanahoshi-mona-ui-i18n.d.ts +4 -0
  48. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +2 -0
  49. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +2 -0
  50. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +2 -0
  51. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +2 -0
  52. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +2 -0
  53. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +2 -0
  54. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +2 -0
  55. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +2 -0
  56. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +2 -0
  57. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +2 -0
  58. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +2 -0
  59. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +2 -0
  60. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +2 -0
  61. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +2 -0
@@ -1,9 +1,9 @@
1
1
  import { PreventableEvent, deepEquals } from "@nanahoshi/mona-ui/common";
2
2
  import * as i0 from "@angular/core";
3
- import { DOCUMENT, DestroyRef, Directive, ElementRef, Injectable, Injector, PLATFORM_ID, afterNextRender, afterRenderEffect, computed, effect, inject, input, isDevMode, output, signal, untracked } from "@angular/core";
4
- import { MonaI18nService, formatNumber } from "@nanahoshi/mona-ui/i18n";
3
+ import { DOCUMENT, DestroyRef, Directive, ElementRef, Injectable, Injector, LOCALE_ID, PLATFORM_ID, afterNextRender, afterRenderEffect, computed, effect, inject, input, isDevMode, output, signal, untracked } from "@angular/core";
4
+ import { MonaI18nService, formatGregorianDateToLocaleString, formatNumber, parseLocalizedNumber } from "@nanahoshi/mona-ui/i18n";
5
5
  import { v4 } from "uuid";
6
- import { DOCUMENT as DOCUMENT$1, isPlatformBrowser } from "@angular/common";
6
+ import { DOCUMENT as DOCUMENT$1, formatDate, isPlatformBrowser } from "@angular/common";
7
7
  import { Dictionary, ImmutableDictionary, ImmutableList, ImmutableSet, KeyValuePair, select } from "@mirei/ts-collections";
8
8
  import { BehaviorSubject, Subject, fromEvent } from "rxjs";
9
9
  import { takeUntilDestroyed, toObservable } from "@angular/core/rxjs-interop";
@@ -139,6 +139,8 @@ const GRID_DEFAULT_MESSAGES = {
139
139
  cancel: "Cancel",
140
140
  cancelNewRow: "Cancel new row",
141
141
  cancelRowEdit: (rowNumber) => `Cancel editing row ${localizeNumber(rowNumber)}`,
142
+ cellsCopied: (count) => count === 1 ? `Copied ${localizeNumber(count)} cell` : `Copied ${localizeNumber(count)} cells`,
143
+ cellsPasted: (count) => count === 0 ? "No cells pasted" : count === 1 ? `Pasted ${localizeNumber(count)} cell` : `Pasted ${localizeNumber(count)} cells`,
142
144
  clearFilter: (column) => `Clear filter for ${column}`,
143
145
  collapseDetail: (rowNumber) => `Collapse details of row ${localizeNumber(rowNumber)}`,
144
146
  columnGrouped: (column) => `Grouped by ${column}`,
@@ -228,6 +230,12 @@ var GridNavigationService = class GridNavigationService {
228
230
  target.value.startEdit?.();
229
231
  return true;
230
232
  }
233
+ focusBodyCell(rowUid, columnId) {
234
+ const cell = this.#cells().firstOrDefault((e) => e.value.section === "body" && e.value.rowUid === rowUid && e.value.columnId === columnId);
235
+ if (!cell) return false;
236
+ this.#focusCell(cell.key, cell.value);
237
+ return true;
238
+ }
231
239
  focusFirstCell() {
232
240
  const firstCell = this.#findFirstHeaderCell() ?? this.#findFirstCell();
233
241
  if (firstCell) this.#focusCell(firstCell.key, firstCell.value);
@@ -238,6 +246,11 @@ var GridNavigationService = class GridNavigationService {
238
246
  this.#focusCell(cell.key, cell.value);
239
247
  return true;
240
248
  }
249
+ getCellAt(target) {
250
+ const element = target?.closest("td, th");
251
+ if (element == null) return null;
252
+ return this.#cells().firstOrDefault((e) => e.value.element === element)?.value ?? null;
253
+ }
241
254
  getFocusedCell() {
242
255
  return this.#getFocusedCell()?.value ?? null;
243
256
  }
@@ -674,6 +687,146 @@ var RowReorderEvent = class extends PreventableEvent {
674
687
  return this.#options.rowData;
675
688
  }
676
689
  };
690
+ function formatGridCellValue(value, rowData, column, locales) {
691
+ const format = column.format;
692
+ if (format == null) return column.dataType === "date" && value instanceof Date && !Number.isNaN(value.getTime()) ? formatGregorianDateToLocaleString(value, locales.localeId, {
693
+ day: "2-digit",
694
+ month: "2-digit",
695
+ year: "numeric"
696
+ }) : value;
697
+ if (typeof format === "function") return format(value, rowData, column);
698
+ if (column.dataType === "date") return formatDateValue(value, format, locales.angularLocale);
699
+ return value;
700
+ }
701
+ function getGridCellText(rowData, column, locales) {
702
+ const formatted = formatGridCellValue(rowData[column.field], rowData, column, locales);
703
+ return formatted == null ? "" : String(formatted);
704
+ }
705
+ function formatDateValue(value, format, locale) {
706
+ if (value == null) return value;
707
+ if (value instanceof Date || typeof value === "number" || typeof value === "string") try {
708
+ return formatDate(value, format, locale);
709
+ } catch {
710
+ return value;
711
+ }
712
+ return value;
713
+ }
714
+ function toClipboardText(rows) {
715
+ return rows.map((row) => row.map(quoteCell).join(" ")).join("\r\n");
716
+ }
717
+ function parseClipboardText(text) {
718
+ const rows = [];
719
+ let row = [];
720
+ let cell = "";
721
+ let index = 0;
722
+ const length = text.length;
723
+ while (index < length) {
724
+ const char = text[index];
725
+ if (char === "\"" && cell === "") {
726
+ let end = index + 1;
727
+ let value = "";
728
+ let closed = false;
729
+ while (end < length) {
730
+ if (text[end] === "\"") {
731
+ if (text[end + 1] === "\"") {
732
+ value += "\"";
733
+ end += 2;
734
+ continue;
735
+ }
736
+ closed = true;
737
+ break;
738
+ }
739
+ value += text[end];
740
+ end++;
741
+ }
742
+ const next = text[end + 1];
743
+ if (closed && (next === void 0 || next === " " || next === "\r" || next === "\n")) {
744
+ cell = value;
745
+ index = end + 1;
746
+ continue;
747
+ }
748
+ }
749
+ if (char === " ") {
750
+ row.push(cell);
751
+ cell = "";
752
+ } else if (char === "\r" || char === "\n") {
753
+ row.push(cell);
754
+ rows.push(row);
755
+ row = [];
756
+ cell = "";
757
+ if (char === "\r" && text[index + 1] === "\n") index++;
758
+ } else cell += char;
759
+ index++;
760
+ }
761
+ if (cell !== "" || row.length > 0) {
762
+ row.push(cell);
763
+ rows.push(row);
764
+ }
765
+ return rows;
766
+ }
767
+ function parsePastedValue(text, dataType, localeId) {
768
+ const trimmed = text.trim();
769
+ switch (dataType) {
770
+ case "number": {
771
+ if (trimmed === "") return { value: null };
772
+ const value = parseLocalizedNumber(trimmed, localeId);
773
+ return value == null ? null : { value };
774
+ }
775
+ case "boolean":
776
+ if (trimmed === "") return { value: null };
777
+ if (/^(true|yes|1)$/i.test(trimmed)) return { value: true };
778
+ return /^(false|no|0)$/i.test(trimmed) ? { value: false } : null;
779
+ case "date": {
780
+ if (trimmed === "") return { value: null };
781
+ const value = parseIsoDate(trimmed) ?? parseLocaleNumericDate(trimmed, localeId);
782
+ return value == null ? null : { value };
783
+ }
784
+ default: return { value: text };
785
+ }
786
+ }
787
+ function parseLocaleNumericDate(text, localeId) {
788
+ const groups = normalizeDigits(text, localeId).match(/\d+/g);
789
+ if (groups == null || groups.length !== 3) return null;
790
+ let order;
791
+ try {
792
+ order = new Intl.DateTimeFormat(localeId, {
793
+ calendar: "gregory",
794
+ day: "2-digit",
795
+ month: "2-digit",
796
+ year: "numeric"
797
+ }).formatToParts(new Date(2001, 10, 22)).map((part) => part.type).filter((type) => type === "day" || type === "month" || type === "year");
798
+ } catch {
799
+ return null;
800
+ }
801
+ if (order.length !== 3) return null;
802
+ const parts = new Map(order.map((type, index) => [type, Number(groups[index])]));
803
+ return toLocalDate(parts.get("year"), parts.get("month"), parts.get("day"));
804
+ }
805
+ function parseIsoDate(text) {
806
+ const match = /^(\d{4})-(\d{2})-(\d{2})(?:[T ][\d:.]+(?:Z|[+-]\d{2}:?\d{2})?)?$/.exec(text);
807
+ return match == null ? null : toLocalDate(Number(match[1]), Number(match[2]), Number(match[3]));
808
+ }
809
+ function normalizeDigits(text, localeId) {
810
+ let digits;
811
+ try {
812
+ const format = new Intl.NumberFormat(localeId, { useGrouping: false });
813
+ digits = Array.from({ length: 10 }, (_, digit) => format.format(digit));
814
+ } catch {
815
+ return text;
816
+ }
817
+ return Array.from(text, (char) => {
818
+ const digit = digits.indexOf(char);
819
+ return digit < 0 ? char : String(digit);
820
+ }).join("");
821
+ }
822
+ function quoteCell(text) {
823
+ return /[\t\r\n"]/.test(text) ? `"${text.replace(/"/g, "\"\"")}"` : text;
824
+ }
825
+ function toLocalDate(year, month, day) {
826
+ if (year < 1 || month < 1 || month > 12 || day < 1 || day > 31) return null;
827
+ const date = new Date(year, month - 1, day);
828
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day ? date : null;
829
+ }
677
830
  function buildHeaderGroupRows(layout) {
678
831
  const depth = getColumnGroupDepth(layout.flatMap((layoutColumn) => layoutColumn.kind === "column" ? [layoutColumn.column] : []));
679
832
  const rows = [];
@@ -1121,6 +1274,102 @@ function isStateCompositeFilter(value) {
1121
1274
  return isRecord(child) && typeof child["field"] === "string" && child["field"] !== "" && child["operator"] !== "function" && isKnownFilterOperator(child["operator"]);
1122
1275
  });
1123
1276
  }
1277
+ function buildGridTreeStructure(rows, getParentUid) {
1278
+ const rowList = Array.from(rows);
1279
+ const known = new Set(rowList.map((row) => row.uid));
1280
+ const declared = /* @__PURE__ */ new Map();
1281
+ for (const row of rowList) {
1282
+ const parentUid = getParentUid(row);
1283
+ declared.set(row.uid, parentUid != null && parentUid !== row.uid && known.has(parentUid) ? parentUid : null);
1284
+ }
1285
+ const inCycle = findCycleMembers(declared);
1286
+ const parents = /* @__PURE__ */ new Map();
1287
+ const children = /* @__PURE__ */ new Map();
1288
+ for (const row of rowList) {
1289
+ const parentUid = inCycle.has(row.uid) ? null : declared.get(row.uid);
1290
+ parents.set(row.uid, parentUid);
1291
+ const siblings = children.get(parentUid);
1292
+ if (siblings == null) children.set(parentUid, [row]);
1293
+ else siblings.push(row);
1294
+ }
1295
+ return {
1296
+ children,
1297
+ parents
1298
+ };
1299
+ }
1300
+ function buildGridTreeView(structure, options) {
1301
+ const included = options.matches == null ? null : withAncestors(options.matches, structure.parents);
1302
+ const allRows = [];
1303
+ const rows = [];
1304
+ const info = /* @__PURE__ */ new Map();
1305
+ const childrenOf = (parentUid) => {
1306
+ const children = structure.children.get(parentUid) ?? [];
1307
+ return included == null ? children : children.filter((child) => included.has(child.uid));
1308
+ };
1309
+ const stack = [];
1310
+ const visit = (parentUid, level, shown) => {
1311
+ const siblings = options.sort(childrenOf(parentUid));
1312
+ for (let index = siblings.length - 1; index >= 0; index--) {
1313
+ const row = siblings[index];
1314
+ const hasChildren = childrenOf(row.uid).length > 0;
1315
+ info.set(row.uid, {
1316
+ expanded: hasChildren && options.isExpanded(row),
1317
+ hasChildren,
1318
+ level,
1319
+ parentUid,
1320
+ posInSet: index + 1,
1321
+ setSize: siblings.length
1322
+ });
1323
+ stack.push({
1324
+ level,
1325
+ row,
1326
+ shown
1327
+ });
1328
+ }
1329
+ };
1330
+ visit(null, 1, true);
1331
+ while (stack.length > 0) {
1332
+ const { level, row, shown } = stack.pop();
1333
+ const rowInfo = info.get(row.uid);
1334
+ allRows.push(row);
1335
+ if (shown) rows.push(row);
1336
+ if (rowInfo.hasChildren) visit(row.uid, level + 1, shown && rowInfo.expanded);
1337
+ }
1338
+ return {
1339
+ allRows,
1340
+ info,
1341
+ rows
1342
+ };
1343
+ }
1344
+ function getGridTreeAncestorUids(uids, parents) {
1345
+ const ancestors = /* @__PURE__ */ new Set();
1346
+ for (const uid of uids) for (let parent = parents.get(uid) ?? null; parent != null; parent = parents.get(parent) ?? null) {
1347
+ if (ancestors.has(parent)) break;
1348
+ ancestors.add(parent);
1349
+ }
1350
+ return [...ancestors];
1351
+ }
1352
+ function findCycleMembers(parents) {
1353
+ const members = /* @__PURE__ */ new Set();
1354
+ const state = /* @__PURE__ */ new Map();
1355
+ for (const start of parents.keys()) {
1356
+ const path = [];
1357
+ let uid = start;
1358
+ while (uid != null && !state.has(uid)) {
1359
+ state.set(uid, 1);
1360
+ path.push(uid);
1361
+ uid = parents.get(uid) ?? null;
1362
+ }
1363
+ if (uid != null && state.get(uid) === 1) for (const member of path.slice(path.indexOf(uid))) members.add(member);
1364
+ for (const visited of path) state.set(visited, 2);
1365
+ }
1366
+ return members;
1367
+ }
1368
+ function withAncestors(uids, parents) {
1369
+ const result = new Set(uids);
1370
+ for (const ancestor of getGridTreeAncestorUids(uids, parents)) result.add(ancestor);
1371
+ return result;
1372
+ }
1124
1373
  const GRID_STATE_VERSION = 1;
1125
1374
  const TEXT_MEASURE_CACHE_LIMIT = 1e3;
1126
1375
  const AGGREGATE_COLUMN_KEYS = [
@@ -1182,7 +1431,10 @@ var GridService = class GridService {
1182
1431
  #i18n;
1183
1432
  #injector;
1184
1433
  #liveAnnouncer;
1434
+ #locale;
1185
1435
  #platformId;
1436
+ #rangeColumnIndexById;
1437
+ #rangeRowIndexByUid;
1186
1438
  #reorderableOptions;
1187
1439
  #resizableOptions;
1188
1440
  #rowFlattener;
@@ -1197,10 +1449,15 @@ var GridService = class GridService {
1197
1449
  #serverTotal;
1198
1450
  #sortDescriptors;
1199
1451
  #textMeasureCache;
1452
+ #treeMatches;
1453
+ #treeOptions;
1454
+ #treeParents;
1455
+ #treeStructure;
1200
1456
  #viewRowIndexByUid;
1201
1457
  #dataStateEmissionPending;
1202
1458
  #groupRequest;
1203
1459
  #loadedSelectedKeys;
1460
+ #rowSource;
1204
1461
  constructor() {
1205
1462
  this.#anchorRowKey = signal(null, ...ngDevMode ? [{ debugName: "#anchorRowKey" }] : /* istanbul ignore next */ []);
1206
1463
  this.#bulkSelectionRowKeys = computed(() => {
@@ -1228,7 +1485,15 @@ var GridService = class GridService {
1228
1485
  this.#i18n = inject(MonaI18nService);
1229
1486
  this.#injector = inject(Injector);
1230
1487
  this.#liveAnnouncer = injectLiveAnnouncer();
1488
+ this.#locale = inject(LOCALE_ID);
1231
1489
  this.#platformId = inject(PLATFORM_ID);
1490
+ this.#rangeColumnIndexById = computed(() => new Map(this.rangeColumns().map((column, index) => [column.id, index])), ...ngDevMode ? [{ debugName: "#rangeColumnIndexById" }] : /* istanbul ignore next */ []);
1491
+ this.#rangeRowIndexByUid = computed(() => {
1492
+ const indices = /* @__PURE__ */ new Map();
1493
+ let index = 0;
1494
+ for (const row of this.rangeRows()) indices.set(row.uid, index++);
1495
+ return indices;
1496
+ }, ...ngDevMode ? [{ debugName: "#rangeRowIndexByUid" }] : /* istanbul ignore next */ []);
1232
1497
  this.#reorderableOptions = signal({ enabled: false }, ...ngDevMode ? [{ debugName: "#reorderableOptions" }] : /* istanbul ignore next */ []);
1233
1498
  this.#resizableOptions = signal({ enabled: false }, ...ngDevMode ? [{ debugName: "#resizableOptions" }] : /* istanbul ignore next */ []);
1234
1499
  this.#rowFlattener = inject(GridRowFlattenerService);
@@ -1243,6 +1508,33 @@ var GridService = class GridService {
1243
1508
  this.#serverTotal = signal(0, ...ngDevMode ? [{ debugName: "#serverTotal" }] : /* istanbul ignore next */ []);
1244
1509
  this.#sortDescriptors = signal([], ...ngDevMode ? [{ debugName: "#sortDescriptors" }] : /* istanbul ignore next */ []);
1245
1510
  this.#textMeasureCache = /* @__PURE__ */ new Map();
1511
+ this.#treeMatches = computed(() => {
1512
+ if (this.#treeOptions() == null || this.serverBindingEnabled()) return null;
1513
+ const filters = this.getFilterDescriptors();
1514
+ if (filters.length === 0) return null;
1515
+ let query = Query.from(this.rows(), { locale: this.#i18n.localeId() });
1516
+ for (const filter of filters) query = query.filter(filter, (row) => row.data);
1517
+ return new Set(Array.from(query.run(), (row) => row.uid));
1518
+ }, ...ngDevMode ? [{ debugName: "#treeMatches" }] : /* istanbul ignore next */ []);
1519
+ this.#treeOptions = signal(null, ...ngDevMode ? [{ debugName: "#treeOptions" }] : /* istanbul ignore next */ []);
1520
+ this.#treeParents = signal(/* @__PURE__ */ new Map(), ...ngDevMode ? [{ debugName: "#treeParents" }] : /* istanbul ignore next */ []);
1521
+ this.#treeStructure = computed(() => {
1522
+ const options = this.#treeOptions();
1523
+ const rows = this.rows();
1524
+ if (options?.children != null) {
1525
+ const parents = this.#treeParents();
1526
+ return buildGridTreeStructure(rows, (row) => parents.get(row.uid) ?? null);
1527
+ }
1528
+ const parentKey = options?.parentKey;
1529
+ if (!parentKey) return buildGridTreeStructure(rows, () => null);
1530
+ const rowKey = this.rowKey();
1531
+ const uidByKey = /* @__PURE__ */ new Map();
1532
+ for (const row of rows) uidByKey.set(this.getRowUidKey(row.data, rowKey) ?? row.data, row.uid);
1533
+ return buildGridTreeStructure(rows, (row) => {
1534
+ const key = this.getRowUidKey(row.data, parentKey);
1535
+ return key == null ? null : uidByKey.get(key) ?? null;
1536
+ });
1537
+ }, ...ngDevMode ? [{ debugName: "#treeStructure" }] : /* istanbul ignore next */ []);
1246
1538
  this.#viewRowIndexByUid = computed(() => {
1247
1539
  const indices = /* @__PURE__ */ new Map();
1248
1540
  let index = 0;
@@ -1252,6 +1544,7 @@ var GridService = class GridService {
1252
1544
  this.#dataStateEmissionPending = false;
1253
1545
  this.#groupRequest = [];
1254
1546
  this.#loadedSelectedKeys = null;
1547
+ this.#rowSource = null;
1255
1548
  this.add$ = new Subject();
1256
1549
  this.addRowData = computed(() => {
1257
1550
  const session = this.#editSession();
@@ -1265,9 +1558,9 @@ var GridService = class GridService {
1265
1558
  this.aggregateMap = computed(() => {
1266
1559
  const aggregateColumns = this.aggregateColumns();
1267
1560
  if (!aggregateColumns.any()) return ImmutableDictionary.create();
1268
- return this.createAggregateMap(this.viewRows().toArray(), aggregateColumns.toArray());
1561
+ return this.createAggregateMap(this.getAggregateSourceRows(), aggregateColumns.toArray());
1269
1562
  }, ...ngDevMode ? [{ debugName: "aggregateMap" }] : /* istanbul ignore next */ []);
1270
- this.aggregateRows = computed(() => this.viewRows().select((row) => row.data).toArray(), ...ngDevMode ? [{ debugName: "aggregateRows" }] : /* istanbul ignore next */ []);
1563
+ this.aggregateRows = computed(() => this.getAggregateSourceRows().map((row) => row.data), ...ngDevMode ? [{ debugName: "aggregateRows" }] : /* istanbul ignore next */ []);
1271
1564
  this.allBulkSelectionRowsSelected = computed(() => {
1272
1565
  const scopeSize = this.#bulkSelectionRowKeys().size;
1273
1566
  return scopeSize > 0 && this.#bulkSelectionSelectedCount() === scopeSize;
@@ -1282,6 +1575,25 @@ var GridService = class GridService {
1282
1575
  }, ...ngDevMode ? [{ debugName: "bulkSelectionRows" }] : /* istanbul ignore next */ []);
1283
1576
  this.cancel$ = new Subject();
1284
1577
  this.cellEdit$ = new Subject();
1578
+ this.cellRange = signal(null, ...ngDevMode ? [{ debugName: "cellRange" }] : /* istanbul ignore next */ []);
1579
+ this.cellRangeBounds = computed(() => {
1580
+ const range = this.cellRange();
1581
+ if (range == null) return null;
1582
+ const rowIndices = this.#rangeRowIndexByUid();
1583
+ const columnIndices = this.#rangeColumnIndexById();
1584
+ const anchorRow = rowIndices.get(range.anchor.rowUid);
1585
+ const focusRow = rowIndices.get(range.focus.rowUid);
1586
+ const anchorColumn = columnIndices.get(range.anchor.columnId);
1587
+ const focusColumn = columnIndices.get(range.focus.columnId);
1588
+ if (anchorRow == null || focusRow == null || anchorColumn == null || focusColumn == null) return null;
1589
+ return {
1590
+ firstColumn: Math.min(anchorColumn, focusColumn),
1591
+ firstRow: Math.min(anchorRow, focusRow),
1592
+ lastColumn: Math.max(anchorColumn, focusColumn),
1593
+ lastRow: Math.max(anchorRow, focusRow)
1594
+ };
1595
+ }, ...ngDevMode ? [{ debugName: "cellRangeBounds" }] : /* istanbul ignore next */ []);
1596
+ this.cellRangeChange$ = new Subject();
1285
1597
  this.collapsedGroupKeys = signal(ImmutableSet.create(), ...ngDevMode ? [{ debugName: "collapsedGroupKeys" }] : /* istanbul ignore next */ []);
1286
1598
  this.columnReorder$ = new Subject();
1287
1599
  this.columnResize$ = new Subject();
@@ -1331,6 +1643,7 @@ var GridService = class GridService {
1331
1643
  this.groupChange$ = new Subject();
1332
1644
  this.groupColumnWidth = 36;
1333
1645
  this.groupColumns = computed(() => {
1646
+ if (this.#treeOptions() != null) return ImmutableList.create();
1334
1647
  const columnsById = new Map(this.columns().select((column) => [column.id, column]));
1335
1648
  return this.#groupColumnIds().select((id) => columnsById.get(id)).where((column) => column != null).toImmutableList();
1336
1649
  }, {
@@ -1436,6 +1749,9 @@ var GridService = class GridService {
1436
1749
  skip: 0,
1437
1750
  take: 10
1438
1751
  }, ...ngDevMode ? [{ debugName: "paginationState" }] : /* istanbul ignore next */ []);
1752
+ this.rangeColumns = computed(() => this.visibleColumns().where((column) => column.kind === "data").toArray(), ...ngDevMode ? [{ debugName: "rangeColumns" }] : /* istanbul ignore next */ []);
1753
+ this.rangeRows = computed(() => this.virtualScrollOptions().enabled ? this.viewRows() : this.viewPageRows(), ...ngDevMode ? [{ debugName: "rangeRows" }] : /* istanbul ignore next */ []);
1754
+ this.rangeSelectionEnabled = signal(false, ...ngDevMode ? [{ debugName: "rangeSelectionEnabled" }] : /* istanbul ignore next */ []);
1439
1755
  this.remove$ = new Subject();
1440
1756
  this.renderedBodyRowCount = signal(0, ...ngDevMode ? [{ debugName: "renderedBodyRowCount" }] : /* istanbul ignore next */ []);
1441
1757
  this.reorderableOptions = this.#reorderableOptions.asReadonly();
@@ -1445,7 +1761,7 @@ var GridService = class GridService {
1445
1761
  this.rowEdit$ = new Subject();
1446
1762
  this.rowKey = signal(null, ...ngDevMode ? [{ debugName: "rowKey" }] : /* istanbul ignore next */ []);
1447
1763
  this.rowReorder$ = new Subject();
1448
- this.rowReorderColumnVisible = computed(() => this.rowReorderableOptions().enabled === true, ...ngDevMode ? [{ debugName: "rowReorderColumnVisible" }] : /* istanbul ignore next */ []);
1764
+ this.rowReorderColumnVisible = computed(() => this.rowReorderableOptions().enabled === true && this.#treeOptions() == null, ...ngDevMode ? [{ debugName: "rowReorderColumnVisible" }] : /* istanbul ignore next */ []);
1449
1765
  this.rowReorderColumnWidth = 36;
1450
1766
  this.rowReorderDisabledReason = computed(() => {
1451
1767
  if (!this.rowReorderableOptions().enabled) return "disabled";
@@ -1534,6 +1850,32 @@ var GridService = class GridService {
1534
1850
  const dataWidth = columns.aggregate((acc, c) => acc + this.getColumnWidth(c), 0);
1535
1851
  return this.normalizeRenderedWidth(dataWidth + this.leadingStructuralWidth());
1536
1852
  }, ...ngDevMode ? [{ debugName: "tableWidth" }] : /* istanbul ignore next */ []);
1853
+ this.treeColumnId = computed(() => {
1854
+ if (this.#treeOptions() == null) return null;
1855
+ const dataColumns = this.visibleColumns().where((column) => column.kind === "data");
1856
+ return (dataColumns.firstOrDefault((column) => column.expandable === true) ?? dataColumns.firstOrDefault())?.id ?? null;
1857
+ }, ...ngDevMode ? [{ debugName: "treeColumnId" }] : /* istanbul ignore next */ []);
1858
+ this.treeEnabled = computed(() => this.#treeOptions() != null, ...ngDevMode ? [{ debugName: "treeEnabled" }] : /* istanbul ignore next */ []);
1859
+ this.treeExpandedKeys = signal(ImmutableSet.create(), ...ngDevMode ? [{ debugName: "treeExpandedKeys" }] : /* istanbul ignore next */ []);
1860
+ this.treeExpandedKeysChange$ = new Subject();
1861
+ this.treeMatchAncestorUids = computed(() => {
1862
+ const matches = this.#treeMatches();
1863
+ return matches == null ? [] : getGridTreeAncestorUids(matches, this.#treeStructure().parents);
1864
+ }, {
1865
+ ...ngDevMode ? { debugName: "treeMatchAncestorUids" } : /* istanbul ignore next */ {},
1866
+ equal: (left, right) => left.length === right.length && left.every((uid, index) => uid === right[index])
1867
+ });
1868
+ this.treeView = computed(() => {
1869
+ if (this.#treeOptions() == null) return null;
1870
+ const locale = this.#i18n.localeId();
1871
+ const sorts = this.serverBindingEnabled() ? [] : this.#sortDescriptors();
1872
+ const expandedKeys = this.treeExpandedKeys();
1873
+ return buildGridTreeView(this.#treeStructure(), {
1874
+ isExpanded: (row) => expandedKeys.contains(this.getRowIdentityKey(row)),
1875
+ matches: this.#treeMatches(),
1876
+ sort: (rows) => sorts.length === 0 ? rows : Array.from(Query.from(rows, { locale }).sort(sorts, (row) => row.data).run())
1877
+ });
1878
+ }, ...ngDevMode ? [{ debugName: "treeView" }] : /* istanbul ignore next */ []);
1537
1879
  this.viewPageRows = computed(() => {
1538
1880
  if (this.serverBindingEnabled()) return this.viewRows();
1539
1881
  const skip = this.paginationState().skip;
@@ -1544,6 +1886,8 @@ var GridService = class GridService {
1544
1886
  }, ...ngDevMode ? [{ debugName: "viewPageRows" }] : /* istanbul ignore next */ []);
1545
1887
  this.viewRowCount = computed(() => this.viewRows().size(), ...ngDevMode ? [{ debugName: "viewRowCount" }] : /* istanbul ignore next */ []);
1546
1888
  this.viewRows = computed(() => {
1889
+ const tree = this.treeView();
1890
+ if (tree != null) return ImmutableList.create(tree.rows);
1547
1891
  const rows = this.rows();
1548
1892
  if (this.serverBindingEnabled()) return rows;
1549
1893
  let queryEnumerable = Query.from(rows, { locale: this.#i18n.localeId() });
@@ -1705,6 +2049,11 @@ var GridService = class GridService {
1705
2049
  if (options.persistPageSize !== false) state.pageSize = this.paginationState().take;
1706
2050
  return state;
1707
2051
  }
2052
+ clearCellRange() {
2053
+ if (this.cellRange() == null) return;
2054
+ this.cellRange.set(null);
2055
+ this.cellRangeChange$.next();
2056
+ }
1708
2057
  clearCollapsedGroups(predicate) {
1709
2058
  if (predicate) this.collapsedGroupKeys.update((keys) => keys.where((k) => !predicate(k)).toImmutableSet());
1710
2059
  else this.collapsedGroupKeys.update((keys) => keys.clear());
@@ -1756,6 +2105,13 @@ var GridService = class GridService {
1756
2105
  endEdit() {
1757
2106
  this.clearEditSession();
1758
2107
  }
2108
+ expandTreeRows(uids) {
2109
+ const rowsByUid = new Map(this.rows().select((row) => [row.uid, row]));
2110
+ const keys = Array.from(uids, (uid) => rowsByUid.get(uid)).filter((row) => row != null).map((row) => this.getRowIdentityKey(row)).filter((key) => !this.treeExpandedKeys().contains(key));
2111
+ if (keys.length === 0) return;
2112
+ this.treeExpandedKeys.update((current) => current.addAll(keys));
2113
+ this.treeExpandedKeysChange$.next(this.treeExpandedKeys().toArray());
2114
+ }
1759
2115
  findTextWidthOfColumn(column, element) {
1760
2116
  if (!isPlatformBrowser(this.#platformId)) return 0;
1761
2117
  let longestValue = this.findLongestCellContentOfColumn(column);
@@ -1793,6 +2149,25 @@ var GridService = class GridService {
1793
2149
  indices
1794
2150
  };
1795
2151
  }
2152
+ getCellRange() {
2153
+ const bounds = this.cellRangeBounds();
2154
+ if (bounds == null) return null;
2155
+ return {
2156
+ columns: this.rangeColumns().slice(bounds.firstColumn, bounds.lastColumn + 1),
2157
+ rows: this.rangeRows().skip(bounds.firstRow).take(bounds.lastRow - bounds.firstRow + 1).toArray()
2158
+ };
2159
+ }
2160
+ getCellRangeText() {
2161
+ const range = this.getCellRange();
2162
+ if (range == null) return null;
2163
+ const locales = {
2164
+ angularLocale: this.#locale,
2165
+ localeId: this.#i18n.localeId()
2166
+ };
2167
+ const text = toClipboardText(range.rows.map((row) => range.columns.map((column) => getGridCellText(row.data, column, locales))));
2168
+ this.#liveAnnouncer.announce(this.messages().cellsCopied(range.rows.length * range.columns.length), "polite");
2169
+ return text;
2170
+ }
1796
2171
  getColumnStateId(column) {
1797
2172
  return column.stateKey || column.field || null;
1798
2173
  }
@@ -1808,6 +2183,9 @@ var GridService = class GridService {
1808
2183
  filter: this.getFilterDescriptors().map((filter) => this.cloneFilter(filter))
1809
2184
  };
1810
2185
  }
2186
+ getExportRows() {
2187
+ return this.treeView()?.allRows ?? this.viewRows().toArray();
2188
+ }
1811
2189
  getFilterDescriptors() {
1812
2190
  return [...this.appliedFilters().values().select((state) => state.filter).where((filter) => filter != null).toArray(), ...this.#externalFilters()];
1813
2191
  }
@@ -1839,6 +2217,12 @@ var GridService = class GridService {
1839
2217
  getSortDescriptors() {
1840
2218
  return this.#sortDescriptors().map((sort) => ({ ...sort }));
1841
2219
  }
2220
+ getTreeParentUid(rowUid) {
2221
+ return this.treeView()?.info.get(rowUid)?.parentUid ?? null;
2222
+ }
2223
+ getTreeRowInfo(row) {
2224
+ return this.treeView()?.info.get(row.uid) ?? null;
2225
+ }
1842
2226
  handleMultipleSelection(event, row) {
1843
2227
  if (event.shiftKey) {
1844
2228
  this.selectRowRange(row);
@@ -1868,6 +2252,13 @@ var GridService = class GridService {
1868
2252
  this.deselectAllRows();
1869
2253
  this.selectRow(row);
1870
2254
  }
2255
+ isCellInRange(rowUid, columnId) {
2256
+ const bounds = this.cellRangeBounds();
2257
+ if (bounds == null) return false;
2258
+ const row = this.#rangeRowIndexByUid().get(rowUid);
2259
+ const column = this.#rangeColumnIndexById().get(columnId);
2260
+ return row != null && column != null && row >= bounds.firstRow && row <= bounds.lastRow && column >= bounds.firstColumn && column <= bounds.lastColumn;
2261
+ }
1871
2262
  isGroupCollapsed(groupKey) {
1872
2263
  return this.collapsedGroupKeys().contains(groupKey);
1873
2264
  }
@@ -1944,6 +2335,11 @@ var GridService = class GridService {
1944
2335
  this.#sortDescriptors.set([...byField.values()]);
1945
2336
  this.syncColumnSortState();
1946
2337
  }
2338
+ loadTreeExpandedKeys(keys) {
2339
+ const next = ImmutableSet.create(keys ?? []);
2340
+ const current = this.treeExpandedKeys();
2341
+ if (next.size() !== current.size() || !next.all((key) => current.contains(key))) this.treeExpandedKeys.set(next);
2342
+ }
1947
2343
  moveGroupColumn(column, moveAs) {
1948
2344
  const previous = this.#groupColumnIds();
1949
2345
  this.#groupColumnIds.update((ids) => {
@@ -1962,6 +2358,70 @@ var GridService = class GridService {
1962
2358
  const devicePixelRatio = this.#document.defaultView?.devicePixelRatio ?? 1;
1963
2359
  return Math.max(0, Math.round(width * devicePixelRatio) / devicePixelRatio);
1964
2360
  }
2361
+ pasteIntoCells(text, at) {
2362
+ if (!this.rangeSelectionEnabled() || this.editableOptions().enabled !== true || this.isInEditMode()) return null;
2363
+ const values = parseClipboardText(text);
2364
+ const rows = this.rangeRows().toArray();
2365
+ const columns = this.rangeColumns();
2366
+ const bounds = this.cellRangeBounds() ?? (at == null ? null : {
2367
+ firstColumn: this.#rangeColumnIndexById().get(at.columnId) ?? -1,
2368
+ firstRow: this.#rangeRowIndexByUid().get(at.rowUid) ?? -1,
2369
+ lastColumn: this.#rangeColumnIndexById().get(at.columnId) ?? -1,
2370
+ lastRow: this.#rangeRowIndexByUid().get(at.rowUid) ?? -1
2371
+ });
2372
+ if (values.length === 0 || bounds == null || bounds.firstRow < 0 || bounds.firstColumn < 0) return null;
2373
+ const fill = values.length === 1 && values[0].length === 1;
2374
+ const lastRow = fill ? bounds.lastRow : Math.min(rows.length - 1, bounds.firstRow + values.length - 1);
2375
+ const width = fill ? 1 : Math.max(...values.map((line) => line.length));
2376
+ const lastColumn = fill ? bounds.lastColumn : Math.min(columns.length - 1, bounds.firstColumn + width - 1);
2377
+ const localeId = this.#i18n.localeId();
2378
+ const changes = [];
2379
+ let skippedCells = 0;
2380
+ let pastedCells = 0;
2381
+ for (let rowIndex = bounds.firstRow; rowIndex <= lastRow; rowIndex++) {
2382
+ const row = rows[rowIndex];
2383
+ const line = fill ? values[0] : values[rowIndex - bounds.firstRow];
2384
+ const rowData = { ...row.data };
2385
+ const fields = [];
2386
+ for (let columnIndex = bounds.firstColumn; columnIndex <= lastColumn; columnIndex++) {
2387
+ const column = columns[columnIndex];
2388
+ const cellText = fill ? line[0] : line[columnIndex - bounds.firstColumn];
2389
+ if (cellText === void 0) continue;
2390
+ const parsed = column.editable ? parsePastedValue(cellText, column.dataType, localeId) : null;
2391
+ if (parsed == null) {
2392
+ skippedCells++;
2393
+ continue;
2394
+ }
2395
+ if (!sameCellValue(row.data[column.field], parsed.value)) {
2396
+ rowData[column.field] = parsed.value;
2397
+ fields.push(column.field);
2398
+ }
2399
+ pastedCells++;
2400
+ }
2401
+ if (fields.length > 0) changes.push({
2402
+ fields,
2403
+ originalRowData: row.data,
2404
+ rowData
2405
+ });
2406
+ }
2407
+ this.cellRange.set({
2408
+ anchor: {
2409
+ columnId: columns[bounds.firstColumn].id,
2410
+ rowUid: rows[bounds.firstRow].uid
2411
+ },
2412
+ focus: {
2413
+ columnId: columns[lastColumn].id,
2414
+ rowUid: rows[lastRow].uid
2415
+ }
2416
+ });
2417
+ this.cellRangeChange$.next();
2418
+ this.#liveAnnouncer.announce(this.messages().cellsPasted(pastedCells), "polite");
2419
+ return {
2420
+ changes,
2421
+ skippedCells,
2422
+ text
2423
+ };
2424
+ }
1965
2425
  reconcileEditSession() {
1966
2426
  const context = this.#editContext();
1967
2427
  const session = this.#editSession();
@@ -2083,6 +2543,19 @@ var GridService = class GridService {
2083
2543
  this.clearEditSession();
2084
2544
  return true;
2085
2545
  }
2546
+ selectAllCells() {
2547
+ const rows = this.rangeRows();
2548
+ const columns = this.rangeColumns();
2549
+ if (!this.rangeSelectionEnabled() || !rows.any() || columns.length === 0) return false;
2550
+ this.setCellRange({
2551
+ columnId: columns[0].id,
2552
+ rowUid: rows.first().uid
2553
+ }, {
2554
+ columnId: columns[columns.length - 1].id,
2555
+ rowUid: rows.last().uid
2556
+ });
2557
+ return true;
2558
+ }
2086
2559
  selectAllRowsFromKeyboard() {
2087
2560
  const options = this.selectableOptions();
2088
2561
  if (!options.enabled || options.mode !== "multiple") return false;
@@ -2109,6 +2582,13 @@ var GridService = class GridService {
2109
2582
  }, row);
2110
2583
  return true;
2111
2584
  }
2585
+ setAllTreeRowsExpanded(expanded) {
2586
+ const tree = this.treeView();
2587
+ if (tree == null) return;
2588
+ const keys = expanded ? tree.allRows.filter((row) => tree.info.get(row.uid)?.hasChildren).map((row) => this.getRowIdentityKey(row)) : [];
2589
+ this.treeExpandedKeys.set(ImmutableSet.create(keys));
2590
+ this.treeExpandedKeysChange$.next(keys);
2591
+ }
2112
2592
  setBulkSelection(selected) {
2113
2593
  if (this.selectableOptions().mode !== "multiple") return;
2114
2594
  const keys = this.bulkSelectionRows().select((row) => this.getRowSelectionKey(row)).toArray();
@@ -2128,6 +2608,15 @@ var GridService = class GridService {
2128
2608
  calculatedWidth: widthByColumnId.get(column.id) ?? null
2129
2609
  } : column);
2130
2610
  }
2611
+ setCellRange(anchor, focus) {
2612
+ const current = this.cellRange();
2613
+ if (current != null && sameAddress(current.anchor, anchor) && sameAddress(current.focus, focus)) return;
2614
+ this.cellRange.set({
2615
+ anchor,
2616
+ focus
2617
+ });
2618
+ this.cellRangeChange$.next();
2619
+ }
2131
2620
  setColumnDefinitions(configs) {
2132
2621
  const currentColumns = this.columns().toArray();
2133
2622
  const currentById = new Map(currentColumns.map((column) => [column.id, column]));
@@ -2217,6 +2706,10 @@ var GridService = class GridService {
2217
2706
  page
2218
2707
  });
2219
2708
  }
2709
+ setRangeSelectionEnabled(enabled) {
2710
+ this.rangeSelectionEnabled.set(enabled);
2711
+ if (!enabled) this.clearCellRange();
2712
+ }
2220
2713
  setReorderableOptions(options) {
2221
2714
  this.#reorderableOptions.set({
2222
2715
  ...options,
@@ -2261,17 +2754,39 @@ var GridService = class GridService {
2261
2754
  this.selectedKeys.update((keys) => keys.remove(key));
2262
2755
  }
2263
2756
  setRows(value, rowKey = null) {
2757
+ this.#rowSource = {
2758
+ data: value,
2759
+ rowKey
2760
+ };
2264
2761
  const occurrences = /* @__PURE__ */ new Map();
2265
2762
  let duplicateKey = false;
2266
2763
  const rows = [];
2267
- for (const data of value) {
2268
- const uid = this.getRowUid(data, rowKey);
2269
- const occurrence = (occurrences.get(uid) ?? 0) + 1;
2270
- occurrences.set(uid, occurrence);
2271
- if (occurrence > 1 && rowKey) duplicateKey = true;
2272
- rows.push(new Row(data, occurrence === 1 ? uid : `${uid}#${occurrence}`));
2273
- }
2764
+ const parents = /* @__PURE__ */ new Map();
2765
+ const children = this.#treeOptions()?.children ?? null;
2766
+ const path = /* @__PURE__ */ new Set();
2767
+ const addRows = (items, parentUid) => {
2768
+ for (const data of items) {
2769
+ if (path.has(data)) continue;
2770
+ const uid = this.getRowUid(data, rowKey);
2771
+ const occurrence = (occurrences.get(uid) ?? 0) + 1;
2772
+ occurrences.set(uid, occurrence);
2773
+ if (occurrence > 1 && rowKey) duplicateKey = true;
2774
+ const row = new Row(data, occurrence === 1 ? uid : `${uid}#${occurrence}`);
2775
+ rows.push(row);
2776
+ if (children != null) {
2777
+ parents.set(row.uid, parentUid);
2778
+ const childItems = getTreeChildren(data, children);
2779
+ if (childItems != null) {
2780
+ path.add(data);
2781
+ addRows(childItems, row.uid);
2782
+ path.delete(data);
2783
+ }
2784
+ }
2785
+ }
2786
+ };
2787
+ addRows(value, null);
2274
2788
  if (duplicateKey && isDevMode()) console.warn("mona-grid: several rows have the same rowKey value. Selection, editing and detail rows follow the key, so give every row a unique key.");
2789
+ this.#treeParents.set(parents);
2275
2790
  this.rows.set(ImmutableList.create(rows));
2276
2791
  }
2277
2792
  setScrollEndThreshold(threshold) {
@@ -2315,6 +2830,20 @@ var GridService = class GridService {
2315
2830
  enabled: options.enabled !== false
2316
2831
  });
2317
2832
  }
2833
+ setTreeOptions(options) {
2834
+ const current = this.#treeOptions();
2835
+ if (current === options || current != null && options != null && deepEquals(current, options)) return;
2836
+ this.#treeOptions.set(options);
2837
+ const source = this.#rowSource;
2838
+ if (source != null) this.setRows(source.data, source.rowKey);
2839
+ }
2840
+ setTreeRowExpanded(row, expanded) {
2841
+ if (this.getTreeRowInfo(row)?.hasChildren !== true) return;
2842
+ const key = this.getRowIdentityKey(row);
2843
+ if (this.treeExpandedKeys().contains(key) === expanded) return;
2844
+ this.treeExpandedKeys.update((keys) => expanded ? keys.add(key) : keys.remove(key));
2845
+ this.treeExpandedKeysChange$.next(this.treeExpandedKeys().toArray());
2846
+ }
2318
2847
  setVirtualScrollOptions(options) {
2319
2848
  const height = options.height ?? this.virtualScrollOptions().height ?? 36;
2320
2849
  if (!Number.isFinite(height) || height <= 0) throw new Error("monaGridVirtualScroll: height must be finite and greater than zero.");
@@ -2456,6 +2985,9 @@ var GridService = class GridService {
2456
2985
  toggleGroupCollapse(groupKey) {
2457
2986
  this.collapsedGroupKeys.update((keys) => keys.contains(groupKey) ? keys.remove(groupKey) : keys.add(groupKey));
2458
2987
  }
2988
+ toggleTreeRow(row) {
2989
+ this.setTreeRowExpanded(row, this.getTreeRowInfo(row)?.expanded !== true);
2990
+ }
2459
2991
  updateColumn(columnId, patch) {
2460
2992
  this.updateColumns((column) => {
2461
2993
  if (column.id !== columnId) return column;
@@ -2624,6 +3156,9 @@ var GridService = class GridService {
2624
3156
  }
2625
3157
  return longestValue;
2626
3158
  }
3159
+ getAggregateSourceRows() {
3160
+ return [...this.treeView()?.allRows ?? this.viewRows()];
3161
+ }
2627
3162
  getColumnById(columnId) {
2628
3163
  return this.columns().firstOrDefault((column) => column.id === columnId);
2629
3164
  }
@@ -2924,6 +3459,14 @@ i0.ɵɵngDeclareClassMetadata({
2924
3459
  decorators: [{ type: Injectable }],
2925
3460
  ctorParameters: () => []
2926
3461
  });
3462
+ function sameAddress(left, right) {
3463
+ return left.rowUid === right.rowUid && left.columnId === right.columnId;
3464
+ }
3465
+ function getTreeChildren(data, children) {
3466
+ const value = typeof children === "string" ? data[children] : children(data);
3467
+ if (value == null || typeof value !== "object" || !(Symbol.iterator in value)) return null;
3468
+ return value;
3469
+ }
2927
3470
  const STICKY_EDGE_BORDER = "1px solid var(--color-border)";
2928
3471
  var GridLockedCellDirective = class GridLockedCellDirective {
2929
3472
  constructor() {
@@ -3121,6 +3664,16 @@ function removeTabStop(node) {
3121
3664
  if (node.matches(LOGICAL_CELL_SELECTOR) || node.getAttribute("tabindex") === "-1") return;
3122
3665
  if (node.parentElement?.closest(LOGICAL_CELL_SELECTOR) != null) node.setAttribute("tabindex", "-1");
3123
3666
  }
3667
+ const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
3668
+ "ArrowDown",
3669
+ "ArrowLeft",
3670
+ "ArrowRight",
3671
+ "ArrowUp",
3672
+ "End",
3673
+ "Home",
3674
+ "PageDown",
3675
+ "PageUp"
3676
+ ]);
3124
3677
  const PAGE_TABBABLE_SELECTOR = `${GRID_CELL_FOCUSABLE_SELECTOR}, summary, [contenteditable]`;
3125
3678
  var GridLogicalCellDirective = class GridLogicalCellDirective {
3126
3679
  #cellData;
@@ -3164,6 +3717,12 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3164
3717
  if (!key) return false;
3165
3718
  return this.#gridNavigationService.isFocused(key);
3166
3719
  }, ...ngDevMode ? [{ debugName: "focused" }] : /* istanbul ignore next */ []);
3720
+ this.rangeSelected = computed(() => {
3721
+ const rowUid = this.rowUid();
3722
+ const columnId = this.columnId();
3723
+ if (!this.#gridService.rangeSelectionEnabled() || this.resolvedSection() !== "body" || this.resolvedCellKind() !== "data" || rowUid == null || columnId == null) return null;
3724
+ return this.#gridService.isCellInRange(rowUid, columnId);
3725
+ }, ...ngDevMode ? [{ debugName: "rangeSelected" }] : /* istanbul ignore next */ []);
3167
3726
  this.resolvedAriaColIndex = computed(() => this.ariaColIndex() ?? this.colIndex() + this.#gridService.groupColumns().length + 1, ...ngDevMode ? [{ debugName: "resolvedAriaColIndex" }] : /* istanbul ignore next */ []);
3168
3727
  this.resolvedCellKind = computed(() => {
3169
3728
  const cellKind = this.cellKind();
@@ -3195,6 +3754,7 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3195
3754
  this.rowUid = input(...ngDevMode ? [void 0, { debugName: "rowUid" }] : /* istanbul ignore next */ []);
3196
3755
  this.section = input(null, ...ngDevMode ? [{ debugName: "section" }] : /* istanbul ignore next */ []);
3197
3756
  this.toggleExpand = output();
3757
+ this.treeCell = input(false, ...ngDevMode ? [{ debugName: "treeCell" }] : /* istanbul ignore next */ []);
3198
3758
  afterRenderEffect({ mixedReadWrite: () => {
3199
3759
  const data = this.#cellData();
3200
3760
  untracked(() => {
@@ -3227,6 +3787,12 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3227
3787
  if (this.rowIndex() < 0 || this.#gridService.isInEditMode()) return;
3228
3788
  const selection = this.#hostElementRef.nativeElement.ownerDocument.getSelection();
3229
3789
  if (selection != null && !selection.isCollapsed && selection.toString() !== "") return;
3790
+ const rangeText = this.#gridService.cellRangeBounds() == null ? null : this.#gridService.getCellRangeText();
3791
+ if (rangeText != null) {
3792
+ event.preventDefault();
3793
+ this.#clipboard.copy(rangeText);
3794
+ return;
3795
+ }
3230
3796
  const host = this.#hostElementRef.nativeElement;
3231
3797
  const text = (host.innerText ?? host.textContent ?? "").trim();
3232
3798
  if (text) this.#clipboard.copy(text);
@@ -3249,6 +3815,13 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3249
3815
  targets[nextIndex].focus();
3250
3816
  return true;
3251
3817
  }
3818
+ #focusTreeParent() {
3819
+ const rowUid = this.rowUid();
3820
+ const columnId = this.columnId();
3821
+ if (!this.treeCell() || rowUid == null || columnId == null) return false;
3822
+ const parentUid = this.#gridService.getTreeParentUid(rowUid);
3823
+ return parentUid != null && this.#gridNavigationService.focusBodyCell(parentUid, columnId);
3824
+ }
3252
3825
  #getInnerFocusableTargets() {
3253
3826
  const host = this.#hostElementRef.nativeElement;
3254
3827
  return Array.from(host.querySelectorAll(GRID_CELL_FOCUSABLE_SELECTOR)).filter((target) => target !== host && !this.#isElementDisabled(target) && !this.#isElementHidden(target));
@@ -3278,6 +3851,33 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3278
3851
  this.#focusNextInnerTarget(target, true, true);
3279
3852
  }
3280
3853
  }
3854
+ #handleRangeKey(event) {
3855
+ const rowUid = this.rowUid();
3856
+ const columnId = this.columnId();
3857
+ if (!this.#gridService.rangeSelectionEnabled() || this.resolvedSection() !== "body" || this.resolvedCellKind() !== "data" || rowUid == null || columnId == null) return false;
3858
+ if ((event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey && event.code === "KeyA") {
3859
+ if (this.#gridService.selectAllCells()) event.preventDefault();
3860
+ return true;
3861
+ }
3862
+ if (event.key === "Escape" && this.#gridService.cellRange() != null) {
3863
+ event.preventDefault();
3864
+ this.#gridService.clearCellRange();
3865
+ return true;
3866
+ }
3867
+ if (!event.shiftKey || event.altKey || event.ctrlKey || event.metaKey || !event.key.startsWith("Arrow")) return false;
3868
+ event.preventDefault();
3869
+ const anchor = this.#gridService.cellRange()?.anchor ?? {
3870
+ columnId,
3871
+ rowUid
3872
+ };
3873
+ if (!this.#navigate(this.#toLogicalArrowKey(event.key))) return true;
3874
+ const next = this.#gridNavigationService.getFocusedCell();
3875
+ if (next?.section === "body" && next.cellKind === "data" && next.rowUid != null && next.columnId != null) this.#gridService.setCellRange(anchor, {
3876
+ columnId: next.columnId,
3877
+ rowUid: next.rowUid
3878
+ });
3879
+ return true;
3880
+ }
3281
3881
  #handleSelectionKey(event) {
3282
3882
  const rowUid = this.rowUid();
3283
3883
  if (this.resolvedSection() !== "body" || this.groupHeader() || rowUid == null) return false;
@@ -3334,8 +3934,9 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3334
3934
  return;
3335
3935
  }
3336
3936
  this.#copyCellText(event);
3337
- if (this.#handleSelectionKey(event)) return;
3937
+ if (this.#handleRangeKey(event) || this.#handleSelectionKey(event)) return;
3338
3938
  const command = event.ctrlKey || event.metaKey;
3939
+ if (NAVIGATION_KEYS.has(event.key)) this.#gridService.clearCellRange();
3339
3940
  switch (event.key) {
3340
3941
  case "ArrowDown":
3341
3942
  event.preventDefault();
@@ -3353,12 +3954,12 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3353
3954
  case "ArrowRight": {
3354
3955
  const key = this.#toLogicalArrowKey(event.key);
3355
3956
  const expanded = this.expanded();
3356
- if (this.groupHeader() && expanded === (key === "ArrowLeft")) {
3957
+ if ((this.groupHeader() || this.treeCell()) && expanded === (key === "ArrowLeft")) {
3357
3958
  event.preventDefault();
3358
3959
  this.toggleExpand.emit();
3359
3960
  return;
3360
3961
  }
3361
- if (this.#navigate(key)) event.preventDefault();
3962
+ if (this.#navigate(key) || key === "ArrowLeft" && this.#focusTreeParent()) event.preventDefault();
3362
3963
  return;
3363
3964
  }
3364
3965
  case "Enter":
@@ -3527,6 +4128,13 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3527
4128
  isSignal: true,
3528
4129
  isRequired: false,
3529
4130
  transformFunction: null
4131
+ },
4132
+ treeCell: {
4133
+ classPropertyName: "treeCell",
4134
+ publicName: "treeCell",
4135
+ isSignal: true,
4136
+ isRequired: false,
4137
+ transformFunction: null
3530
4138
  }
3531
4139
  },
3532
4140
  outputs: {
@@ -3537,7 +4145,8 @@ var GridLogicalCellDirective = class GridLogicalCellDirective {
3537
4145
  host: { properties: {
3538
4146
  "attr.tabindex": "focused() ? 0 : -1",
3539
4147
  "attr.aria-colindex": "resolvedAriaColIndex()",
3540
- "attr.aria-readonly": "readOnly()"
4148
+ "attr.aria-readonly": "readOnly()",
4149
+ "attr.aria-selected": "rangeSelected()"
3541
4150
  } },
3542
4151
  ngImport: i0
3543
4152
  });
@@ -3555,7 +4164,8 @@ i0.ɵɵngDeclareClassMetadata({
3555
4164
  host: {
3556
4165
  "[attr.tabindex]": "focused() ? 0 : -1",
3557
4166
  "[attr.aria-colindex]": "resolvedAriaColIndex()",
3558
- "[attr.aria-readonly]": "readOnly()"
4167
+ "[attr.aria-readonly]": "readOnly()",
4168
+ "[attr.aria-selected]": "rangeSelected()"
3559
4169
  }
3560
4170
  }]
3561
4171
  }],
@@ -3692,6 +4302,14 @@ i0.ɵɵngDeclareClassMetadata({
3692
4302
  toggleExpand: [{
3693
4303
  type: i0.Output,
3694
4304
  args: ["toggleExpand"]
4305
+ }],
4306
+ treeCell: [{
4307
+ type: i0.Input,
4308
+ args: [{
4309
+ isSignal: true,
4310
+ alias: "treeCell",
4311
+ required: false
4312
+ }]
3695
4313
  }]
3696
4314
  }
3697
4315
  });
@@ -3769,6 +4387,11 @@ const gridCellEditorInputThemeVariants = cva(`
3769
4387
  const gridCellTextThemeVariants = cva(`
3770
4388
  truncate cursor-default select-none
3771
4389
  `);
4390
+ const gridTreeToggleThemeVariants = cva(`
4391
+ me-1 inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm
4392
+ hover:bg-hover
4393
+ `);
4394
+ const gridTreeLeafSpacerThemeVariants = cva("me-1 size-5 shrink-0");
3772
4395
  const gridSelectAllCellThemeVariants = cva(`
3773
4396
  absolute inset-0 flex h-full w-full items-center justify-center
3774
4397
  `);
@@ -3952,6 +4575,9 @@ const gridListTableCellThemeVariants = cva(`
3952
4575
  after:content-[''] after:block
3953
4576
  after:absolute after:inset-0 after:pointer-events-none
3954
4577
  focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-focus-indicator
4578
+ aria-selected:bg-(--color-selected) aria-selected:text-(--color-selected-foreground)
4579
+ forced-colors:aria-selected:bg-[Highlight] forced-colors:aria-selected:text-[HighlightText]
4580
+ forced-colors:aria-selected:forced-color-adjust-none
3955
4581
  `, {
3956
4582
  variants: {
3957
4583
  virtual: {
@@ -3973,6 +4599,6 @@ const gridNoDataThemeVariants = cva(`
3973
4599
  flex items-center justify-center h-full
3974
4600
  text-muted-foreground border-t border-t-border-subtle
3975
4601
  `);
3976
- export { GridSaveEvent as $, gridHeaderThemeVariants as A, GridLogicalCellDirective as B, gridHeaderGroupTableRowThemeVariants as C, gridHeaderTableColumnWrapThemeVariants as D, gridHeaderTableColumnTitleThemeVariants as E, gridNoDataThemeVariants as F, GridService as G, isKeyboardEntryElement as H, gridRowDragPreviewThemeVariants as I, getColumnStepTarget as J, getColumnGroupDepth as K, gridRowReorderHandleThemeVariants as L, gridListTableCellThemeVariants as M, gridListTableRowThemeVariants as N, gridHeaderTableRowThemeVariants as O, gridListTableThemeVariants as P, GRID_DEFAULT_MESSAGES as Q, gridSelectAllCellThemeVariants as R, gridHeaderGroupSpacerCellThemeVariants as S, gridHeaderTableCellThemeVariants as T, observeGridCellTabStops as U, GRID_CELL_FOCUSABLE_SELECTOR as V, GridLockedCellDirective as W, RowReorderEvent as X, getSiblingRuns as Y, GridNavigationService as Z, gridFooterThemeVariants as _, gridCellEditorBaseThemeVariants as a, CellEditEvent as at, gridGroupRowThemeVariants as b, gridColumnActionsThemeVariants as c, gridColumnResizerThemeVariants as d, GridRemoveEvent as et, gridFilterRowCellThemeVariants as f, gridFooterTableThemeVariants as g, gridFooterTableRowThemeVariants as h, gridCellDirtyIndicatorThemeVariants as i, RowEditEvent as it, gridListBaseThemeVariants as j, gridHeaderTableThemeVariants as k, gridColumnDragPreviewThemeVariants as l, gridFooterTableCellThemeVariants as m, gridCellBaseThemeVariants as n, GridCancelEvent as nt, gridCellEditorInputThemeVariants as o, gridFilterRowHeaderCellThemeVariants as p, getColumnGroups as q, gridCellContainerThemeVariants as r, GridAddEvent as rt, gridCellTextThemeVariants as s, gridBaseThemeVariants as t, GridEditEvent as tt, gridColumnDropHintThemeVariants as u, gridGroupPanelPlaceholderThemeVariants as v, gridHeaderGroupTitleThemeVariants as w, gridHeaderGroupCellThemeVariants as x, gridGroupPanelThemeVariants as y, gridSelectionCellThemeVariants as z };
4602
+ export { getGridCellText as $, gridHeaderThemeVariants as A, gridTreeLeafSpacerThemeVariants as B, gridHeaderGroupTableRowThemeVariants as C, gridHeaderTableColumnWrapThemeVariants as D, gridHeaderTableColumnTitleThemeVariants as E, gridNoDataThemeVariants as F, observeGridCellTabStops as G, GridLogicalCellDirective as H, gridRowDragPreviewThemeVariants as I, getColumnGroupDepth as J, GridLockedCellDirective as K, gridRowReorderHandleThemeVariants as L, gridListTableCellThemeVariants as M, gridListTableRowThemeVariants as N, gridHeaderTableRowThemeVariants as O, gridListTableThemeVariants as P, formatGridCellValue as Q, gridSelectAllCellThemeVariants as R, gridHeaderGroupSpacerCellThemeVariants as S, gridHeaderTableCellThemeVariants as T, GRID_CELL_FOCUSABLE_SELECTOR as U, gridTreeToggleThemeVariants as V, isKeyboardEntryElement as W, getColumnStepTarget as X, getColumnGroups as Y, getSiblingRuns as Z, gridFooterThemeVariants as _, gridCellEditorBaseThemeVariants as a, GridEditEvent as at, gridGroupRowThemeVariants as b, gridColumnActionsThemeVariants as c, RowEditEvent as ct, gridColumnResizerThemeVariants as d, RowReorderEvent as et, gridFilterRowCellThemeVariants as f, gridFooterTableThemeVariants as g, gridFooterTableRowThemeVariants as h, gridCellDirtyIndicatorThemeVariants as i, GridRemoveEvent as it, gridListBaseThemeVariants as j, gridHeaderTableThemeVariants as k, gridColumnDragPreviewThemeVariants as l, CellEditEvent as lt, gridFooterTableCellThemeVariants as m, gridCellBaseThemeVariants as n, GRID_DEFAULT_MESSAGES as nt, gridCellEditorInputThemeVariants as o, GridCancelEvent as ot, gridFilterRowHeaderCellThemeVariants as p, GridService as q, gridCellContainerThemeVariants as r, GridSaveEvent as rt, gridCellTextThemeVariants as s, GridAddEvent as st, gridBaseThemeVariants as t, GridNavigationService as tt, gridColumnDropHintThemeVariants as u, gridGroupPanelPlaceholderThemeVariants as v, gridHeaderGroupTitleThemeVariants as w, gridHeaderGroupCellThemeVariants as x, gridGroupPanelThemeVariants as y, gridSelectionCellThemeVariants as z };
3977
4603
 
3978
- //# sourceMappingURL=nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs.map
4604
+ //# sourceMappingURL=nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs.map