@octanejs/aria 0.0.5 → 0.0.6

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 (120) hide show
  1. package/package.json +3 -3
  2. package/src/components/Table.ts +2618 -0
  3. package/src/components/Tree.ts +1450 -0
  4. package/src/components/TreeDropTargetDelegate.ts +363 -0
  5. package/src/components/index.ts +57 -0
  6. package/src/grid/GridKeyboardDelegate.ts +514 -0
  7. package/src/grid/useGrid.ts +263 -0
  8. package/src/grid/useGridCell.ts +346 -0
  9. package/src/grid/useGridRow.ts +108 -0
  10. package/src/grid/useGridRowGroup.ts +29 -0
  11. package/src/grid/utils.ts +24 -0
  12. package/src/index.ts +38 -0
  13. package/src/intl/autocomplete/index.ts +9 -2
  14. package/src/intl/breadcrumbs/index.ts +9 -2
  15. package/src/intl/combobox/index.ts +9 -2
  16. package/src/intl/compileMessages.ts +356 -0
  17. package/src/intl/grid/index.ts +9 -2
  18. package/src/intl/gridlist/index.ts +9 -2
  19. package/src/intl/menu/index.ts +9 -2
  20. package/src/intl/numberfield/index.ts +9 -2
  21. package/src/intl/overlays/index.ts +9 -2
  22. package/src/intl/searchfield/index.ts +9 -2
  23. package/src/intl/spinbutton/index.ts +9 -2
  24. package/src/intl/table/ar-AE.json +13 -0
  25. package/src/intl/table/bg-BG.json +13 -0
  26. package/src/intl/table/cs-CZ.json +13 -0
  27. package/src/intl/table/da-DK.json +13 -0
  28. package/src/intl/table/de-DE.json +13 -0
  29. package/src/intl/table/el-GR.json +13 -0
  30. package/src/intl/table/en-US.json +13 -0
  31. package/src/intl/table/es-ES.json +13 -0
  32. package/src/intl/table/et-EE.json +13 -0
  33. package/src/intl/table/fi-FI.json +13 -0
  34. package/src/intl/table/fr-FR.json +13 -0
  35. package/src/intl/table/he-IL.json +13 -0
  36. package/src/intl/table/hr-HR.json +13 -0
  37. package/src/intl/table/hu-HU.json +13 -0
  38. package/src/intl/table/index.ts +82 -0
  39. package/src/intl/table/it-IT.json +13 -0
  40. package/src/intl/table/ja-JP.json +13 -0
  41. package/src/intl/table/ko-KR.json +13 -0
  42. package/src/intl/table/lt-LT.json +13 -0
  43. package/src/intl/table/lv-LV.json +13 -0
  44. package/src/intl/table/nb-NO.json +13 -0
  45. package/src/intl/table/nl-NL.json +13 -0
  46. package/src/intl/table/pl-PL.json +13 -0
  47. package/src/intl/table/pt-BR.json +13 -0
  48. package/src/intl/table/pt-PT.json +13 -0
  49. package/src/intl/table/ro-RO.json +13 -0
  50. package/src/intl/table/ru-RU.json +13 -0
  51. package/src/intl/table/sk-SK.json +13 -0
  52. package/src/intl/table/sl-SI.json +13 -0
  53. package/src/intl/table/sr-SP.json +13 -0
  54. package/src/intl/table/sv-SE.json +13 -0
  55. package/src/intl/table/tr-TR.json +13 -0
  56. package/src/intl/table/uk-UA.json +13 -0
  57. package/src/intl/table/zh-CN.json +13 -0
  58. package/src/intl/table/zh-TW.json +13 -0
  59. package/src/intl/tag/index.ts +9 -2
  60. package/src/intl/tree/ar-AE.json +4 -0
  61. package/src/intl/tree/bg-BG.json +4 -0
  62. package/src/intl/tree/cs-CZ.json +4 -0
  63. package/src/intl/tree/da-DK.json +4 -0
  64. package/src/intl/tree/de-DE.json +4 -0
  65. package/src/intl/tree/el-GR.json +4 -0
  66. package/src/intl/tree/en-US.json +4 -0
  67. package/src/intl/tree/es-ES.json +4 -0
  68. package/src/intl/tree/et-EE.json +4 -0
  69. package/src/intl/tree/fi-FI.json +4 -0
  70. package/src/intl/tree/fr-FR.json +4 -0
  71. package/src/intl/tree/he-IL.json +4 -0
  72. package/src/intl/tree/hr-HR.json +4 -0
  73. package/src/intl/tree/hu-HU.json +4 -0
  74. package/src/intl/tree/index.ts +82 -0
  75. package/src/intl/tree/it-IT.json +4 -0
  76. package/src/intl/tree/ja-JP.json +4 -0
  77. package/src/intl/tree/ko-KR.json +4 -0
  78. package/src/intl/tree/lt-LT.json +4 -0
  79. package/src/intl/tree/lv-LV.json +4 -0
  80. package/src/intl/tree/nb-NO.json +4 -0
  81. package/src/intl/tree/nl-NL.json +4 -0
  82. package/src/intl/tree/pl-PL.json +4 -0
  83. package/src/intl/tree/pt-BR.json +4 -0
  84. package/src/intl/tree/pt-PT.json +4 -0
  85. package/src/intl/tree/ro-RO.json +4 -0
  86. package/src/intl/tree/ru-RU.json +4 -0
  87. package/src/intl/tree/sk-SK.json +4 -0
  88. package/src/intl/tree/sl-SI.json +4 -0
  89. package/src/intl/tree/sr-SP.json +4 -0
  90. package/src/intl/tree/sv-SE.json +4 -0
  91. package/src/intl/tree/tr-TR.json +4 -0
  92. package/src/intl/tree/uk-UA.json +4 -0
  93. package/src/intl/tree/zh-CN.json +4 -0
  94. package/src/intl/tree/zh-TW.json +4 -0
  95. package/src/stately/grid/GridCollection.ts +200 -0
  96. package/src/stately/grid/useGridState.ts +160 -0
  97. package/src/stately/index.ts +43 -0
  98. package/src/stately/table/Cell.ts +49 -0
  99. package/src/stately/table/Column.ts +121 -0
  100. package/src/stately/table/Row.ts +145 -0
  101. package/src/stately/table/TableBody.ts +66 -0
  102. package/src/stately/table/TableCollection.ts +390 -0
  103. package/src/stately/table/TableColumnLayout.ts +148 -0
  104. package/src/stately/table/TableHeader.ts +65 -0
  105. package/src/stately/table/TableUtils.ts +269 -0
  106. package/src/stately/table/useTableColumnResizeState.ts +202 -0
  107. package/src/stately/table/useTableState.ts +235 -0
  108. package/src/stately/table/useTreeGridState.ts +248 -0
  109. package/src/table/TableKeyboardDelegate.ts +205 -0
  110. package/src/table/useTable.ts +175 -0
  111. package/src/table/useTableCell.ts +81 -0
  112. package/src/table/useTableColumnHeader.ts +155 -0
  113. package/src/table/useTableColumnResize.ts +374 -0
  114. package/src/table/useTableHeaderRow.ts +57 -0
  115. package/src/table/useTableRow.ts +198 -0
  116. package/src/table/useTableRowGroup.ts +13 -0
  117. package/src/table/useTableSelectionCheckbox.ts +105 -0
  118. package/src/table/utils.ts +42 -0
  119. package/src/tree/useTree.ts +76 -0
  120. package/src/tree/useTreeItem.ts +109 -0
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "vzostupne",
3
+ "ascendingSort": "zoradené zostupne podľa stĺpca {columnName}",
4
+ "columnSize": "Počet pixelov: {value}",
5
+ "descending": "zostupne",
6
+ "descendingSort": "zoradené zostupne podľa stĺpca {columnName}",
7
+ "resizerDescription": "Stlačením klávesu Enter začnete zmenu veľkosti",
8
+ "select": "Vybrať",
9
+ "selectAll": "Vybrať všetko",
10
+ "sortable": "zoraditeľný stĺpec",
11
+ "collapse": "Zbaliť",
12
+ "expand": "Rozbaliť"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "naraščajoče",
3
+ "ascendingSort": "razvrščeno po stolpcu {columnName} v naraščajočem vrstnem redu",
4
+ "columnSize": "{value} slikovnih pik",
5
+ "descending": "padajoče",
6
+ "descendingSort": "razvrščeno po stolpcu {columnName} v padajočem vrstnem redu",
7
+ "resizerDescription": "Pritisnite tipko Enter da začnete spreminjati velikost",
8
+ "select": "Izberite",
9
+ "selectAll": "Izberite vse",
10
+ "sortable": "razvrstljivi stolpec",
11
+ "collapse": "Strni",
12
+ "expand": "Razširi"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "rastući",
3
+ "ascendingSort": "sortirano po kolonama {columnName} rastućim redosledom",
4
+ "columnSize": "{value} piksela",
5
+ "descending": "padajući",
6
+ "descendingSort": "sortirano po kolonama {columnName} padajućim redosledom",
7
+ "resizerDescription": "Pritisnite Enter da biste započeli promenu veličine",
8
+ "select": "Izaberite",
9
+ "selectAll": "Izaberite sve",
10
+ "sortable": "kolona koja se može sortirati",
11
+ "collapse": " Skupi",
12
+ "expand": "Proširi"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "stigande",
3
+ "ascendingSort": "sorterat på kolumn {columnName} i stigande ordning",
4
+ "columnSize": "{value} pixlar",
5
+ "descending": "fallande",
6
+ "descendingSort": "sorterat på kolumn {columnName} i fallande ordning",
7
+ "resizerDescription": "Tryck på Retur för att börja ändra storlek",
8
+ "select": "Markera",
9
+ "selectAll": "Markera allt",
10
+ "sortable": "sorterbar kolumn",
11
+ "collapse": "Dölj",
12
+ "expand": "Expandera"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "artan sırada",
3
+ "ascendingSort": "{columnName} sütuna göre artan düzende sırala",
4
+ "columnSize": "{value} piksel",
5
+ "descending": "azalan sırada",
6
+ "descendingSort": "{columnName} sütuna göre azalan düzende sırala",
7
+ "resizerDescription": "Yeniden boyutlandırmak için Enter'a basın",
8
+ "select": "Seç",
9
+ "selectAll": "Tümünü Seç",
10
+ "sortable": "Sıralanabilir sütun",
11
+ "collapse": "Daralt",
12
+ "expand": "Genişlet"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "висхідний",
3
+ "ascendingSort": "відсортовано за стовпцем {columnName} у висхідному порядку",
4
+ "columnSize": "{value} пікс.",
5
+ "descending": "низхідний",
6
+ "descendingSort": "відсортовано за стовпцем {columnName} у низхідному порядку",
7
+ "resizerDescription": "Натисніть Enter, щоб почати зміну розміру",
8
+ "select": "Вибрати",
9
+ "selectAll": "Вибрати все",
10
+ "sortable": "сортувальний стовпець",
11
+ "collapse": "Згорнути",
12
+ "expand": "Розгорнути"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "升序",
3
+ "ascendingSort": "按列 {columnName} 升序排序",
4
+ "columnSize": "{value} 像素",
5
+ "descending": "降序",
6
+ "descendingSort": "按列 {columnName} 降序排序",
7
+ "resizerDescription": "按“输入”键开始调整大小。",
8
+ "select": "选择",
9
+ "selectAll": "全选",
10
+ "sortable": "可排序的列",
11
+ "collapse": "折叠",
12
+ "expand": "扩展"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ascending": "遞增",
3
+ "ascendingSort": "已依據「{columnName}」欄遞增排序",
4
+ "columnSize": "{value} 像素",
5
+ "descending": "遞減",
6
+ "descendingSort": "已依據「{columnName}」欄遞減排序",
7
+ "resizerDescription": "按 Enter 鍵以開始調整大小",
8
+ "select": "選取",
9
+ "selectAll": "全選",
10
+ "sortable": "可排序的欄",
11
+ "collapse": "收合",
12
+ "expand": "展開"
13
+ }
@@ -2,6 +2,13 @@
2
2
  // upstream's Parcel glob import (`import intlMessages from '../../intl/tag/*.json'`).
3
3
  // The JSON files are copied VERBATIM from .react-spectrum/packages/react-aria/intl/tag/;
4
4
  // refresh them from the pinned checkout on version bumps, never hand-edit.
5
+ //
6
+ // Upstream's Parcel build additionally compiles each message through
7
+ // @internationalized/string-compiler, so `{variable}` placeholders and plural/select
8
+ // ICU arguments become message FUNCTIONS (LocalizedStringFormatter interpolates only
9
+ // function messages — plain strings are returned verbatim). `compileDictionaries`
10
+ // applies the equivalent compile step here at module init.
11
+ import { compileDictionaries } from '../compileMessages';
5
12
  import ar_AE from './ar-AE.json';
6
13
  import bg_BG from './bg-BG.json';
7
14
  import cs_CZ from './cs-CZ.json';
@@ -37,7 +44,7 @@ import uk_UA from './uk-UA.json';
37
44
  import zh_CN from './zh-CN.json';
38
45
  import zh_TW from './zh-TW.json';
39
46
 
40
- export default {
47
+ export default compileDictionaries({
41
48
  'ar-AE': ar_AE,
42
49
  'bg-BG': bg_BG,
43
50
  'cs-CZ': cs_CZ,
@@ -72,4 +79,4 @@ export default {
72
79
  'uk-UA': uk_UA,
73
80
  'zh-CN': zh_CN,
74
81
  'zh-TW': zh_TW,
75
- } as Record<string, Record<string, string>>;
82
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "طي",
3
+ "expand": "تمديد"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Свиване",
3
+ "expand": "Разширяване"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Sbalit",
3
+ "expand": "Roztáhnout"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Skjul",
3
+ "expand": "Udvid"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Reduzieren",
3
+ "expand": "Erweitern"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Σύμπτυξη",
3
+ "expand": "Ανάπτυξη"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "expand": "Expand",
3
+ "collapse": "Collapse"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Contraer",
3
+ "expand": "Ampliar"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Ahenda",
3
+ "expand": "Laienda"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Pienennä",
3
+ "expand": "Laajenna"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Réduire",
3
+ "expand": "Développer"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "כווץ",
3
+ "expand": "הרחב"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Sažmi",
3
+ "expand": "Proširi"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Összecsukás",
3
+ "expand": "Kibontás"
4
+ }
@@ -0,0 +1,82 @@
1
+ // Generated locale-dictionary index for the tree area — the octane equivalent of
2
+ // upstream's Parcel glob import (`import intlMessages from '../../intl/tree/*.json'`).
3
+ // The JSON files are copied VERBATIM from .react-spectrum/packages/react-aria/intl/tree/;
4
+ // refresh them from the pinned checkout on version bumps, never hand-edit.
5
+ //
6
+ // Upstream's Parcel build additionally compiles each message through
7
+ // @internationalized/string-compiler, so `{variable}` placeholders and plural/select
8
+ // ICU arguments become message FUNCTIONS (LocalizedStringFormatter interpolates only
9
+ // function messages — plain strings are returned verbatim). `compileDictionaries`
10
+ // applies the equivalent compile step here at module init.
11
+ import { compileDictionaries } from '../compileMessages';
12
+ import ar_AE from './ar-AE.json';
13
+ import bg_BG from './bg-BG.json';
14
+ import cs_CZ from './cs-CZ.json';
15
+ import da_DK from './da-DK.json';
16
+ import de_DE from './de-DE.json';
17
+ import el_GR from './el-GR.json';
18
+ import en_US from './en-US.json';
19
+ import es_ES from './es-ES.json';
20
+ import et_EE from './et-EE.json';
21
+ import fi_FI from './fi-FI.json';
22
+ import fr_FR from './fr-FR.json';
23
+ import he_IL from './he-IL.json';
24
+ import hr_HR from './hr-HR.json';
25
+ import hu_HU from './hu-HU.json';
26
+ import it_IT from './it-IT.json';
27
+ import ja_JP from './ja-JP.json';
28
+ import ko_KR from './ko-KR.json';
29
+ import lt_LT from './lt-LT.json';
30
+ import lv_LV from './lv-LV.json';
31
+ import nb_NO from './nb-NO.json';
32
+ import nl_NL from './nl-NL.json';
33
+ import pl_PL from './pl-PL.json';
34
+ import pt_BR from './pt-BR.json';
35
+ import pt_PT from './pt-PT.json';
36
+ import ro_RO from './ro-RO.json';
37
+ import ru_RU from './ru-RU.json';
38
+ import sk_SK from './sk-SK.json';
39
+ import sl_SI from './sl-SI.json';
40
+ import sr_SP from './sr-SP.json';
41
+ import sv_SE from './sv-SE.json';
42
+ import tr_TR from './tr-TR.json';
43
+ import uk_UA from './uk-UA.json';
44
+ import zh_CN from './zh-CN.json';
45
+ import zh_TW from './zh-TW.json';
46
+
47
+ export default compileDictionaries({
48
+ 'ar-AE': ar_AE,
49
+ 'bg-BG': bg_BG,
50
+ 'cs-CZ': cs_CZ,
51
+ 'da-DK': da_DK,
52
+ 'de-DE': de_DE,
53
+ 'el-GR': el_GR,
54
+ 'en-US': en_US,
55
+ 'es-ES': es_ES,
56
+ 'et-EE': et_EE,
57
+ 'fi-FI': fi_FI,
58
+ 'fr-FR': fr_FR,
59
+ 'he-IL': he_IL,
60
+ 'hr-HR': hr_HR,
61
+ 'hu-HU': hu_HU,
62
+ 'it-IT': it_IT,
63
+ 'ja-JP': ja_JP,
64
+ 'ko-KR': ko_KR,
65
+ 'lt-LT': lt_LT,
66
+ 'lv-LV': lv_LV,
67
+ 'nb-NO': nb_NO,
68
+ 'nl-NL': nl_NL,
69
+ 'pl-PL': pl_PL,
70
+ 'pt-BR': pt_BR,
71
+ 'pt-PT': pt_PT,
72
+ 'ro-RO': ro_RO,
73
+ 'ru-RU': ru_RU,
74
+ 'sk-SK': sk_SK,
75
+ 'sl-SI': sl_SI,
76
+ 'sr-SP': sr_SP,
77
+ 'sv-SE': sv_SE,
78
+ 'tr-TR': tr_TR,
79
+ 'uk-UA': uk_UA,
80
+ 'zh-CN': zh_CN,
81
+ 'zh-TW': zh_TW,
82
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Comprimi",
3
+ "expand": "Espandi"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "折りたたむ",
3
+ "expand": "展開"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "접기",
3
+ "expand": "펼치기"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Sutraukti",
3
+ "expand": "Išskleisti"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Sakļaut",
3
+ "expand": "Izvērst"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Skjul",
3
+ "expand": "Utvid"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Samenvouwen",
3
+ "expand": "Uitvouwen"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Zwiń",
3
+ "expand": "Rozwiń"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Recolher",
3
+ "expand": "Expandir"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Colapsar",
3
+ "expand": "Expandir"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Restrângeți",
3
+ "expand": "Extindeți"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Свернуть",
3
+ "expand": "Развернуть"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Zbaliť",
3
+ "expand": "Rozbaliť"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Strni",
3
+ "expand": "Razširi"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": " Skupi",
3
+ "expand": "Proširi"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Dölj",
3
+ "expand": "Expandera"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Daralt",
3
+ "expand": "Genişlet"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "Згорнути",
3
+ "expand": "Розгорнути"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "折叠",
3
+ "expand": "扩展"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collapse": "收合",
3
+ "expand": "展開"
4
+ }
@@ -0,0 +1,200 @@
1
+ // Ported from react-stately (source: .react-spectrum/packages/react-stately/src/grid/GridCollection.ts).
2
+ // Verbatim (no React surface).
3
+ import type { Collection, Key, Node } from '@react-types/shared';
4
+
5
+ export interface IGridCollection<T> extends Collection<GridNode<T>> {
6
+ /** The number of columns in the grid. */
7
+ columnCount: number;
8
+ /** A list of rows in the grid. */
9
+ rows: GridNode<T>[];
10
+ }
11
+
12
+ export interface GridRow<T> extends Partial<GridNode<T>> {
13
+ key?: Key;
14
+ type: string;
15
+ childNodes: Iterable<Node<T>>;
16
+ }
17
+
18
+ export interface GridNode<T> extends Node<T> {
19
+ column?: GridNode<T>;
20
+ /**
21
+ * The number of columns spanned by this cell. Use `colSpan` instead.
22
+ *
23
+ * @deprecated
24
+ */
25
+ colspan?: number;
26
+ /** The number of columns spanned by this cell. */
27
+ colSpan?: number | null;
28
+ /** The column index of this cell, accounting for any colSpans. */
29
+ colIndex?: number | null;
30
+ /** The index of this node within its parent, ignoring sibling nodes that aren't of the same type. */
31
+ indexOfType?: number;
32
+ }
33
+
34
+ interface GridCollectionOptions<T> {
35
+ columnCount: number;
36
+ items: GridRow<T>[];
37
+ visitNode?: (cell: GridNode<T>) => GridNode<T>;
38
+ }
39
+
40
+ export class GridCollection<T> implements IGridCollection<T> {
41
+ keyMap: Map<Key, GridNode<T>> = new Map();
42
+ columnCount: number;
43
+ rows: GridNode<T>[];
44
+
45
+ constructor(opts: GridCollectionOptions<T>) {
46
+ this.keyMap = new Map();
47
+ this.columnCount = opts?.columnCount;
48
+ this.rows = [];
49
+
50
+ let visit = (node: GridNode<T>) => {
51
+ // If the node is the same object as the previous node for the same key,
52
+ // we can skip this node and its children. We always visit columns though,
53
+ // because we depend on order to build the columns array.
54
+ let prevNode = this.keyMap.get(node.key);
55
+ if (opts.visitNode) {
56
+ node = opts.visitNode(node);
57
+ }
58
+
59
+ this.keyMap.set(node.key, node);
60
+
61
+ let childKeys = new Set();
62
+ let last: GridNode<T> | null = null;
63
+ let rowHasCellWithColSpan = false;
64
+
65
+ if (node.type === 'item') {
66
+ for (let child of node.childNodes) {
67
+ if (child.props?.colSpan !== undefined) {
68
+ rowHasCellWithColSpan = true;
69
+ break;
70
+ }
71
+ }
72
+ }
73
+
74
+ for (let child of node.childNodes as Iterable<GridNode<T>>) {
75
+ if (child.type === 'cell' && rowHasCellWithColSpan) {
76
+ child.colspan = child.props?.colSpan;
77
+ child.colSpan = child.props?.colSpan;
78
+ child.colIndex = !last
79
+ ? child.index
80
+ : (last.colIndex ?? last.index) + (last.colSpan ?? 1);
81
+ }
82
+
83
+ if (child.type === 'cell' && child.parentKey == null) {
84
+ // if child is a cell parent key isn't already established by the collection, match child node to parent row
85
+ child.parentKey = node.key;
86
+ }
87
+ childKeys.add(child.key);
88
+
89
+ if (last) {
90
+ last.nextKey = child.key;
91
+ child.prevKey = last.key;
92
+ } else {
93
+ child.prevKey = null;
94
+ }
95
+
96
+ visit(child);
97
+ last = child;
98
+ }
99
+
100
+ if (last) {
101
+ last.nextKey = null;
102
+ }
103
+
104
+ // Remove deleted nodes and their children from the key map
105
+ if (prevNode) {
106
+ for (let child of prevNode.childNodes) {
107
+ if (!childKeys.has(child.key)) {
108
+ remove(child);
109
+ }
110
+ }
111
+ }
112
+ };
113
+
114
+ let remove = (node: GridNode<T>) => {
115
+ this.keyMap.delete(node.key);
116
+ for (let child of node.childNodes) {
117
+ if (this.keyMap.get(child.key) === child) {
118
+ remove(child);
119
+ }
120
+ }
121
+ };
122
+
123
+ let last: GridNode<T> | null = null;
124
+ for (let [i, node] of opts.items.entries()) {
125
+ let rowNode: GridNode<T> = {
126
+ ...node,
127
+ level: node.level ?? 0,
128
+ key: node.key ?? 'row-' + i,
129
+ type: node.type ?? 'row',
130
+ value: node.value ?? null,
131
+ hasChildNodes: true,
132
+ childNodes: [...node.childNodes],
133
+ rendered: node.rendered,
134
+ textValue: node.textValue ?? '',
135
+ index: node.index ?? i,
136
+ };
137
+
138
+ if (last) {
139
+ last.nextKey = rowNode.key;
140
+ rowNode.prevKey = last.key;
141
+ } else {
142
+ rowNode.prevKey = null;
143
+ }
144
+
145
+ this.rows.push(rowNode);
146
+ visit(rowNode);
147
+
148
+ last = rowNode;
149
+ }
150
+
151
+ if (last) {
152
+ last.nextKey = null;
153
+ }
154
+ }
155
+
156
+ *[Symbol.iterator](): IterableIterator<GridNode<T>> {
157
+ yield* [...this.rows];
158
+ }
159
+
160
+ get size(): number {
161
+ return [...this.rows].length;
162
+ }
163
+
164
+ getKeys(): IterableIterator<Key> {
165
+ return this.keyMap.keys();
166
+ }
167
+
168
+ getKeyBefore(key: Key): Key | null {
169
+ let node = this.keyMap.get(key);
170
+ return node ? (node.prevKey ?? null) : null;
171
+ }
172
+
173
+ getKeyAfter(key: Key): Key | null {
174
+ let node = this.keyMap.get(key);
175
+ return node ? (node.nextKey ?? null) : null;
176
+ }
177
+
178
+ getFirstKey(): Key | null {
179
+ return [...this.rows][0]?.key;
180
+ }
181
+
182
+ getLastKey(): Key | null {
183
+ let rows = [...this.rows];
184
+ return rows[rows.length - 1]?.key;
185
+ }
186
+
187
+ getItem(key: Key): GridNode<T> | null {
188
+ return this.keyMap.get(key) ?? null;
189
+ }
190
+
191
+ at(idx: number): GridNode<T> | null {
192
+ const keys = [...this.getKeys()];
193
+ return this.getItem(keys[idx]);
194
+ }
195
+
196
+ getChildren(key: Key): Iterable<GridNode<T>> {
197
+ let node = this.keyMap.get(key);
198
+ return node?.childNodes || [];
199
+ }
200
+ }