@monolith-forensics/monolith-ui 1.8.0 → 1.8.1-dev.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 (175) hide show
  1. package/dist/BarChart/BarChart.d.ts +3 -0
  2. package/dist/BarChart/BarChart.js +511 -0
  3. package/dist/BarChart/BarChart.lib.d.ts +31 -0
  4. package/dist/BarChart/BarChart.lib.js +136 -0
  5. package/dist/BarChart/BarChart.styled.d.ts +49 -0
  6. package/dist/BarChart/BarChart.styled.js +111 -0
  7. package/dist/BarChart/BarChart.types.d.ts +170 -0
  8. package/dist/BarChart/BarChart.types.js +1 -0
  9. package/dist/BarChart/index.d.ts +3 -0
  10. package/dist/BarChart/index.js +2 -0
  11. package/dist/Button/Button.js +9 -58
  12. package/dist/Calendar/Calendar.d.ts +3 -1
  13. package/dist/Calendar/Calendar.js +134 -33
  14. package/dist/Calendar/CalendarStyles.d.ts +3 -0
  15. package/dist/Calendar/CalendarStyles.js +92 -14
  16. package/dist/Calendar/calendarHelpers.d.ts +5 -1
  17. package/dist/Calendar/calendarHelpers.js +13 -5
  18. package/dist/ChartPrimitives/chartLegend.styled.d.ts +12 -0
  19. package/dist/ChartPrimitives/chartLegend.styled.js +52 -0
  20. package/dist/ChartPrimitives/chartTooltip.styled.d.ts +19 -0
  21. package/dist/ChartPrimitives/chartTooltip.styled.js +61 -0
  22. package/dist/ChartPrimitives/index.d.ts +2 -0
  23. package/dist/ChartPrimitives/index.js +2 -0
  24. package/dist/ChartUtils/chartColors.d.ts +8 -0
  25. package/dist/ChartUtils/chartColors.js +65 -0
  26. package/dist/ChartUtils/chartMath.d.ts +3 -0
  27. package/dist/ChartUtils/chartMath.js +3 -0
  28. package/dist/ChartUtils/index.d.ts +2 -0
  29. package/dist/ChartUtils/index.js +2 -0
  30. package/dist/Charts/BarChart/BarChart.d.ts +5 -0
  31. package/dist/Charts/BarChart/BarChart.js +549 -0
  32. package/dist/Charts/BarChart/BarChart.lib.d.ts +31 -0
  33. package/dist/Charts/BarChart/BarChart.lib.js +136 -0
  34. package/dist/Charts/BarChart/BarChart.styled.d.ts +51 -0
  35. package/dist/Charts/BarChart/BarChart.styled.js +115 -0
  36. package/dist/Charts/BarChart/BarChart.types.d.ts +171 -0
  37. package/dist/Charts/BarChart/BarChart.types.js +1 -0
  38. package/dist/Charts/BarChart/index.d.ts +3 -0
  39. package/dist/Charts/BarChart/index.js +2 -0
  40. package/dist/Charts/ChartPrimitives/ChartExportControl.d.ts +11 -0
  41. package/dist/Charts/ChartPrimitives/ChartExportControl.js +29 -0
  42. package/dist/Charts/ChartPrimitives/chartActions.styled.d.ts +1 -0
  43. package/dist/Charts/ChartPrimitives/chartActions.styled.js +8 -0
  44. package/dist/Charts/ChartPrimitives/chartLegend.styled.d.ts +12 -0
  45. package/dist/Charts/ChartPrimitives/chartLegend.styled.js +52 -0
  46. package/dist/Charts/ChartPrimitives/chartTooltip.styled.d.ts +19 -0
  47. package/dist/Charts/ChartPrimitives/chartTooltip.styled.js +61 -0
  48. package/dist/Charts/ChartPrimitives/index.d.ts +4 -0
  49. package/dist/Charts/ChartPrimitives/index.js +4 -0
  50. package/dist/Charts/ChartUtils/chartColors.d.ts +8 -0
  51. package/dist/Charts/ChartUtils/chartColors.js +65 -0
  52. package/dist/Charts/ChartUtils/chartExport.d.ts +47 -0
  53. package/dist/Charts/ChartUtils/chartExport.js +311 -0
  54. package/dist/Charts/ChartUtils/chartMath.d.ts +3 -0
  55. package/dist/Charts/ChartUtils/chartMath.js +3 -0
  56. package/dist/Charts/ChartUtils/index.d.ts +3 -0
  57. package/dist/Charts/ChartUtils/index.js +3 -0
  58. package/dist/Charts/HeatMap/HeatMap.d.ts +5 -0
  59. package/dist/Charts/HeatMap/HeatMap.js +212 -0
  60. package/dist/Charts/HeatMap/HeatMap.lib.d.ts +30 -0
  61. package/dist/Charts/HeatMap/HeatMap.lib.js +115 -0
  62. package/dist/Charts/HeatMap/HeatMap.styled.d.ts +37 -0
  63. package/dist/Charts/HeatMap/HeatMap.styled.js +91 -0
  64. package/dist/Charts/HeatMap/HeatMap.types.d.ts +80 -0
  65. package/dist/Charts/HeatMap/HeatMap.types.js +1 -0
  66. package/dist/Charts/HeatMap/index.d.ts +3 -0
  67. package/dist/Charts/HeatMap/index.js +2 -0
  68. package/dist/Charts/LineChart/LineChart.d.ts +5 -0
  69. package/dist/Charts/LineChart/LineChart.js +529 -0
  70. package/dist/Charts/LineChart/LineChart.lib.d.ts +24 -0
  71. package/dist/Charts/LineChart/LineChart.lib.js +132 -0
  72. package/dist/Charts/LineChart/LineChart.styled.d.ts +59 -0
  73. package/dist/Charts/LineChart/LineChart.styled.js +147 -0
  74. package/dist/Charts/LineChart/LineChart.types.d.ts +193 -0
  75. package/dist/Charts/LineChart/LineChart.types.js +1 -0
  76. package/dist/Charts/LineChart/index.d.ts +3 -0
  77. package/dist/Charts/LineChart/index.js +2 -0
  78. package/dist/Charts/PieChart/PieChart.d.ts +4 -0
  79. package/dist/Charts/PieChart/PieChart.js +199 -0
  80. package/dist/Charts/PieChart/PieChart.lib.d.ts +5 -0
  81. package/dist/Charts/PieChart/PieChart.lib.js +19 -0
  82. package/dist/Charts/PieChart/PieChart.styled.d.ts +51 -0
  83. package/dist/Charts/PieChart/PieChart.styled.js +163 -0
  84. package/dist/Charts/PieChart/PieChart.types.d.ts +100 -0
  85. package/dist/Charts/PieChart/PieChart.types.js +1 -0
  86. package/dist/Charts/PieChart/index.d.ts +2 -0
  87. package/dist/Charts/PieChart/index.js +1 -0
  88. package/dist/Charts/index.d.ts +5 -0
  89. package/dist/Charts/index.js +4 -0
  90. package/dist/CheckBox/CheckBox.js +2 -16
  91. package/dist/DateInput/DateInput.js +198 -143
  92. package/dist/DropDownMenu/components/MenuComponent.js +2 -1
  93. package/dist/DropDownMenu/components/MenuItem.js +5 -14
  94. package/dist/DropDownMenu/components/MenuItemList.js +7 -24
  95. package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
  96. package/dist/FieldLabel/FieldLabel.js +4 -12
  97. package/dist/FileInputField/FileInputField.js +4 -23
  98. package/dist/FormSection/FormSection.js +5 -25
  99. package/dist/HeatMap/HeatMap.d.ts +3 -0
  100. package/dist/HeatMap/HeatMap.js +174 -0
  101. package/dist/HeatMap/HeatMap.lib.d.ts +30 -0
  102. package/dist/HeatMap/HeatMap.lib.js +115 -0
  103. package/dist/HeatMap/HeatMap.styled.d.ts +34 -0
  104. package/dist/HeatMap/HeatMap.styled.js +83 -0
  105. package/dist/HeatMap/HeatMap.types.d.ts +79 -0
  106. package/dist/HeatMap/HeatMap.types.js +1 -0
  107. package/dist/HeatMap/index.d.ts +3 -0
  108. package/dist/HeatMap/index.js +2 -0
  109. package/dist/IconButton/IconButton.js +2 -16
  110. package/dist/Input/Input.js +7 -56
  111. package/dist/LineChart/LineChart.d.ts +3 -0
  112. package/dist/LineChart/LineChart.js +491 -0
  113. package/dist/LineChart/LineChart.lib.d.ts +24 -0
  114. package/dist/LineChart/LineChart.lib.js +132 -0
  115. package/dist/LineChart/LineChart.styled.d.ts +57 -0
  116. package/dist/LineChart/LineChart.styled.js +150 -0
  117. package/dist/LineChart/LineChart.types.d.ts +192 -0
  118. package/dist/LineChart/LineChart.types.js +1 -0
  119. package/dist/LineChart/index.d.ts +3 -0
  120. package/dist/LineChart/index.js +2 -0
  121. package/dist/PieChart/PieChart.d.ts +2 -0
  122. package/dist/PieChart/PieChart.js +161 -0
  123. package/dist/PieChart/PieChart.lib.d.ts +5 -0
  124. package/dist/PieChart/PieChart.lib.js +19 -0
  125. package/dist/PieChart/PieChart.styled.d.ts +49 -0
  126. package/dist/PieChart/PieChart.styled.js +161 -0
  127. package/dist/PieChart/PieChart.types.d.ts +99 -0
  128. package/dist/PieChart/PieChart.types.js +1 -0
  129. package/dist/PieChart/index.d.ts +2 -0
  130. package/dist/PieChart/index.js +1 -0
  131. package/dist/Pill/Pill.js +8 -79
  132. package/dist/Popover/Popover.context.d.ts +2 -1
  133. package/dist/Popover/Popover.js +5 -2
  134. package/dist/Popover/Popover.styles.d.ts +1 -6
  135. package/dist/Popover/Popover.styles.js +11 -28
  136. package/dist/Popover/Popover.transitions.d.ts +4 -2
  137. package/dist/Popover/Popover.transitions.js +23 -49
  138. package/dist/Popover/PopoverDropdown.js +6 -8
  139. package/dist/Popover/PopoverTarget.js +6 -3
  140. package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
  141. package/dist/SegmentedControl/SegmentedControl.utils.js +3 -30
  142. package/dist/SelectBox/SelectBox.js +3 -3
  143. package/dist/SelectBox/select-box.styled-components.d.ts +3 -1
  144. package/dist/SelectBox/select-box.styled-components.js +10 -48
  145. package/dist/SuperDatePicker/SuperDatePicker.d.ts +74 -0
  146. package/dist/SuperDatePicker/SuperDatePicker.js +557 -0
  147. package/dist/SuperDatePicker/index.d.ts +2 -0
  148. package/dist/SuperDatePicker/index.js +2 -0
  149. package/dist/Switch/Switch.d.ts +2 -2
  150. package/dist/Switch/Switch.js +18 -83
  151. package/dist/Table/StateStorage.d.ts +4 -0
  152. package/dist/Table/StateStorage.js +13 -0
  153. package/dist/Table/Table.js +160 -12
  154. package/dist/Table/TableComponents.d.ts +10 -0
  155. package/dist/Table/TableComponents.js +57 -0
  156. package/dist/Table/TableDefaults.d.ts +7 -0
  157. package/dist/Table/TableDefaults.js +7 -0
  158. package/dist/Table/TableProvider.js +263 -71
  159. package/dist/Table/TableRow.js +15 -10
  160. package/dist/Table/types.d.ts +64 -0
  161. package/dist/TagBox/TagBox.js +18 -76
  162. package/dist/TextArea/TextArea.js +4 -23
  163. package/dist/TextInput/TextInput.js +12 -6
  164. package/dist/Utilities/parseTimestamp.js +11 -6
  165. package/dist/core/ArrowButton.d.ts +2 -0
  166. package/dist/core/ArrowButton.js +7 -3
  167. package/dist/core/ClearButton.d.ts +2 -0
  168. package/dist/core/ClearButton.js +7 -3
  169. package/dist/core/controlSizes.d.ts +34 -0
  170. package/dist/core/controlSizes.js +190 -0
  171. package/dist/core/index.d.ts +1 -0
  172. package/dist/core/index.js +1 -0
  173. package/dist/index.d.ts +1 -0
  174. package/dist/index.js +1 -0
  175. package/package.json +5 -1
@@ -13,46 +13,22 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import styled from "styled-components";
14
14
  import * as RadixSwitch from "@radix-ui/react-switch";
15
15
  import { FieldLabel } from "..";
16
+ import { DEFAULT_CONTROL_SIZE, getControlSizeTokens } from "../core";
16
17
  import { Themes } from "../theme";
18
+ const getThumbTranslation = (size = DEFAULT_CONTROL_SIZE) => {
19
+ const { switchTrackWidth, switchThumbSize, switchPadding } = getControlSizeTokens(size);
20
+ return `${switchTrackWidth - switchThumbSize - switchPadding * 2}px`;
21
+ };
17
22
  const StyledRoot = styled(RadixSwitch.Root) `
18
23
  all: unset;
19
24
  cursor: pointer;
20
-
21
- height: ${({ size }) => size === "xs"
22
- ? "10px"
23
- : size === "sm"
24
- ? "16px"
25
- : size === "md"
26
- ? "22px"
27
- : size === "lg"
28
- ? "28px"
29
- : size === "xl"
30
- ? "32px"
31
- : "16px"};
32
-
33
- min-width: ${({ size }) => size === "xs"
34
- ? "26px"
35
- : size === "sm"
36
- ? "35px"
37
- : size === "md"
38
- ? "41px"
39
- : size === "lg"
40
- ? "53px"
41
- : size === "xl"
42
- ? "70px"
43
- : "26px"};
44
-
45
- width: ${({ size }) => size === "xs"
46
- ? "26px"
47
- : size === "sm"
48
- ? "35px"
49
- : size === "md"
50
- ? "41px"
51
- : size === "lg"
52
- ? "53px"
53
- : size === "xl"
54
- ? "70px"
55
- : "26px"};
25
+ display: inline-flex;
26
+ align-items: center;
27
+ box-sizing: border-box;
28
+ flex-shrink: 0;
29
+ height: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchTrackHeight}px`};
30
+ min-width: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchTrackWidth}px`};
31
+ width: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchTrackWidth}px`};
56
32
 
57
33
  background-color: ${({ theme }) => theme.name === Themes.DARK ? "#383838" : "#e3e3e3"};
58
34
  transition: background-color 100ms;
@@ -60,17 +36,7 @@ const StyledRoot = styled(RadixSwitch.Root) `
60
36
  border: 1px solid
61
37
  ${({ theme }) => theme.name === Themes.DARK ? theme.palette.input.border : "#e3e3e3"};
62
38
  position: relative;
63
- padding: ${({ size }) => size === "xs"
64
- ? "2px"
65
- : size === "sm"
66
- ? "2px"
67
- : size === "md"
68
- ? "2px 9px 2px 3px"
69
- : size === "lg"
70
- ? "2px 9px 2px 3px"
71
- : size === "xl"
72
- ? "2px 4px"
73
- : "2px"};
39
+ padding: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchPadding}px`};
74
40
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
75
41
 
76
42
  &[data-state="checked"] {
@@ -85,29 +51,8 @@ const StyledRoot = styled(RadixSwitch.Root) `
85
51
  `;
86
52
  const StyledThumb = styled(RadixSwitch.Thumb) `
87
53
  display: block;
88
- width: ${({ size }) => size === "xs"
89
- ? "9px"
90
- : size === "sm"
91
- ? "14px"
92
- : size === "md"
93
- ? "22px"
94
- : size === "lg"
95
- ? "28px"
96
- : size === "xl"
97
- ? "28px"
98
- : "14px"};
99
-
100
- height: ${({ size }) => size === "xs"
101
- ? "9px"
102
- : size === "sm"
103
- ? "14px"
104
- : size === "md"
105
- ? "22px"
106
- : size === "lg"
107
- ? "28px"
108
- : size === "xl"
109
- ? "28px"
110
- : "14px"};
54
+ width: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchThumbSize}px`};
55
+ height: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchThumbSize}px`};
111
56
 
112
57
  background-color: white;
113
58
  border: none;
@@ -117,25 +62,15 @@ const StyledThumb = styled(RadixSwitch.Thumb) `
117
62
  will-change: transform;
118
63
 
119
64
  &[data-state="checked"] {
120
- transform: ${({ size }) => size === "xs"
121
- ? "translateX(17px)"
122
- : size === "sm"
123
- ? "translateX(20px)"
124
- : size === "md"
125
- ? "translateX(26px)"
126
- : size === "lg"
127
- ? "translateX(32px)"
128
- : size === "xl"
129
- ? "translateX(42px)"
130
- : "translateX(17px)"};
65
+ transform: ${({ size = DEFAULT_CONTROL_SIZE }) => `translateX(${getThumbTranslation(size)})`};
131
66
  }
132
67
  `;
133
68
  export const Switch = styled((_a) => {
134
- var { className, onChange, size = "xs", label, labelPosition = "right", description, error, required, disabled = false, defaultValue, value, style = {} } = _a, other = __rest(_a, ["className", "onChange", "size", "label", "labelPosition", "description", "error", "required", "disabled", "defaultValue", "value", "style"]);
69
+ var { className, onChange, size = DEFAULT_CONTROL_SIZE, label, labelPosition = "right", description, error, required, disabled = false, defaultValue, value, style = {} } = _a, other = __rest(_a, ["className", "onChange", "size", "label", "labelPosition", "description", "error", "required", "disabled", "defaultValue", "value", "style"]);
135
70
  return (_jsxs("div", { className: className, children: [label && labelPosition === "left" && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, style: { margin: 0 }, children: label })), _jsx(StyledRoot, Object.assign({ size: size, className: "SwitchRoot", onCheckedChange: onChange, defaultChecked: defaultValue, checked: value, disabled: disabled, style: style }, other, { children: _jsx(StyledThumb, { size: size, className: "SwitchThumb" }) })), label && labelPosition === "right" && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, style: { margin: 0 }, children: label }))] }));
136
71
  }) `
137
72
  display: flex;
138
73
  flex-direction: row;
139
74
  align-items: center;
140
- gap: 10px;
75
+ gap: ${({ size = DEFAULT_CONTROL_SIZE }) => `${getControlSizeTokens(size).switchGap}px`};
141
76
  `;
@@ -11,6 +11,8 @@ type GetSearchStateFn = (key: string) => string;
11
11
  type SetSearchStateFn = (key: string, value: string) => void;
12
12
  type GetFilterStateFn = (key: string) => Query | undefined;
13
13
  type SetFilterStateFn = (key: string, value?: Query | null) => void;
14
+ type GetExpandedKeysFn = (key: string) => string[] | undefined;
15
+ type SetExpandedKeysFn = (key: string, value: string[]) => void;
14
16
  declare const StateStorage: {
15
17
  getTableState: GetTableStateFn;
16
18
  getColumnState: GetColumnStateFn;
@@ -23,5 +25,7 @@ declare const StateStorage: {
23
25
  setSearchState: SetSearchStateFn;
24
26
  getFilterState: GetFilterStateFn;
25
27
  setFilterState: SetFilterStateFn;
28
+ getExpandedKeys: GetExpandedKeysFn;
29
+ setExpandedKeys: SetExpandedKeysFn;
26
30
  };
27
31
  export default StateStorage;
@@ -82,6 +82,17 @@ const setFilterState = (key, value) => {
82
82
  const newState = Object.assign(Object.assign({}, previousState), { filterState: value });
83
83
  set(key, newState);
84
84
  };
85
+ const getExpandedKeys = (key) => {
86
+ const data = getTableState(key);
87
+ return data.expandedKeys;
88
+ };
89
+ const setExpandedKeys = (key, value) => {
90
+ // get previous state
91
+ const previousState = getTableState(key);
92
+ // merge previous state with new state
93
+ const newState = Object.assign(Object.assign({}, previousState), { expandedKeys: value });
94
+ set(key, newState);
95
+ };
85
96
  const StateStorage = {
86
97
  getTableState,
87
98
  getColumnState,
@@ -94,5 +105,7 @@ const StateStorage = {
94
105
  setSearchState,
95
106
  getFilterState,
96
107
  setFilterState,
108
+ getExpandedKeys,
109
+ setExpandedKeys,
97
110
  };
98
111
  export default StateStorage;
@@ -22,6 +22,7 @@ import TableMenu from "./TableMenu";
22
22
  import useTable from "./useTable";
23
23
  import LoadingIndicator from "./LoadingIndicator";
24
24
  import styled from "styled-components";
25
+ import TableDefaults from "./TableDefaults";
25
26
  const StyledTableContainer = styled.div `
26
27
  display: flex;
27
28
  flex-direction: column;
@@ -40,8 +41,20 @@ const TableContent = ({ children, }) => {
40
41
  }, ref: tableElement, "data-compact": compactState, children: [_jsx(LoadingIndicator, { visible: loading }), _jsx(TableHeader, { headerRowElm: headerRowElm }), visibleColumnCount === 0 && _jsx("div", { children: "No columns visible" }), virtualized === true ? (_jsx(VirtualizedRows, { tableDimensions: tableDimensions, targetElm: targetElm, listElm: listElm, rowHeight: rowHeight, headerRowHeight: headerRowHeight })) : (_jsx(StaticRows, { targetElm: targetElm, listElm: listElm }))] })] }));
41
42
  };
42
43
  export const Table = (_a) => {
43
- var { data, columnProps, children } = _a, props = __rest(_a, ["data", "columnProps", "children"]) // pass through props straight to table context
44
+ var { data, columnProps, children, treeOptions } = _a, props = __rest(_a, ["data", "columnProps", "children", "treeOptions"]) // pass through props straight to table context
44
45
  ;
46
+ const resolvedTreeOptions = useMemo(() => {
47
+ var _a, _b, _c, _d, _e, _f;
48
+ return ({
49
+ enabled: (_a = treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.enabled) !== null && _a !== void 0 ? _a : false,
50
+ mode: (_b = treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.mode) !== null && _b !== void 0 ? _b : TableDefaults.tree.defaultMode,
51
+ childrenField: (_c = treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.childrenField) !== null && _c !== void 0 ? _c : TableDefaults.tree.defaultChildrenField,
52
+ parentIdField: (_d = treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.parentIdField) !== null && _d !== void 0 ? _d : TableDefaults.tree.defaultParentIdField,
53
+ idField: treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.idField,
54
+ indentPx: (_e = treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.indentPx) !== null && _e !== void 0 ? _e : TableDefaults.tree.indentPx,
55
+ autoExpandOnMatch: (_f = treeOptions === null || treeOptions === void 0 ? void 0 : treeOptions.autoExpandOnMatch) !== null && _f !== void 0 ? _f : true,
56
+ });
57
+ }, [treeOptions]);
45
58
  const tableElement = useRef(null);
46
59
  const targetElm = useRef(null);
47
60
  const listElm = useRef(null);
@@ -113,18 +126,153 @@ export const Table = (_a) => {
113
126
  // Uses a WeakMap so entries are automatically garbage collected
114
127
  // when their corresponding row objects are no longer referenced.
115
128
  const uuidCache = useRef(new WeakMap());
116
- // Augment each row with a stable __key (UUID) and __index.
117
- // The WeakMap ensures that the same row object always receives
118
- // the same UUID across re-renders, preventing unnecessary DOM
119
- // reconciliation. useMemo preserves referential stability of
120
- // the output array when the data reference hasn't changed.
121
- const __data = useMemo(() => data === null || data === void 0 ? void 0 : data.map((d, i) => {
122
- let key = uuidCache.current.get(d);
129
+ const getOrAssignKey = (row) => {
130
+ let key = uuidCache.current.get(row);
123
131
  if (!key) {
124
132
  key = shortUUID.uuid();
125
- uuidCache.current.set(d, key);
133
+ uuidCache.current.set(row, key);
134
+ }
135
+ return key;
136
+ };
137
+ // Augment each row with stable metadata. When tree mode is disabled,
138
+ // produces a flat 1:1 mapping with __key and __index. When enabled,
139
+ // walks the input (nested or flat) into a flat depth-first array
140
+ // and adds tree metadata (__level, __parentKey, __hasChildren, __childKeys).
141
+ const { rows: __data, treeMeta } = useMemo(() => {
142
+ const parentKeyMap = new Map();
143
+ const childrenKeyMap = new Map();
144
+ const expandableKeys = [];
145
+ if (!data) {
146
+ return {
147
+ rows: [],
148
+ treeMeta: { parentKeyMap, childrenKeyMap, expandableKeys },
149
+ };
150
+ }
151
+ if (!resolvedTreeOptions.enabled) {
152
+ const rows = data.map((d, i) => (Object.assign(Object.assign({}, d), { __key: getOrAssignKey(d), __index: i })));
153
+ return {
154
+ rows,
155
+ treeMeta: { parentKeyMap, childrenKeyMap, expandableKeys },
156
+ };
126
157
  }
127
- return Object.assign(Object.assign({}, d), { __key: key, __index: i });
128
- }), [data]);
129
- return (_jsx(TableProvider, Object.assign({ columns: columnProps, data: __data, tableElement: tableElement, headerRowElm: headerRowElm, tableDimensions: tableDimensions, targetElm: targetElm, listElm: listElm }, props, { children: _jsx(TableContent, { children: children }) })));
158
+ const rows = [];
159
+ let counter = 0;
160
+ if (resolvedTreeOptions.mode === "nested") {
161
+ const childrenField = resolvedTreeOptions.childrenField;
162
+ const walk = (node, level, parentKey) => {
163
+ const key = getOrAssignKey(node);
164
+ const rawChildren = node === null || node === void 0 ? void 0 : node[childrenField];
165
+ const children = Array.isArray(rawChildren) ? rawChildren : [];
166
+ const childKeys = children.map((c) => getOrAssignKey(c));
167
+ // Strip the nested children field from the augmented copy to avoid
168
+ // memory bloat and prevent accidental iteration of the raw tree.
169
+ const _a = node, _b = childrenField, _stripped = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
170
+ const augmented = Object.assign(Object.assign({}, rest), { __key: key, __index: counter++, __level: level, __parentKey: parentKey, __hasChildren: children.length > 0, __childKeys: childKeys });
171
+ rows.push(augmented);
172
+ parentKeyMap.set(key, parentKey);
173
+ if (children.length > 0) {
174
+ childrenKeyMap.set(key, childKeys);
175
+ expandableKeys.push(key);
176
+ }
177
+ for (const child of children) {
178
+ walk(child, level + 1, key);
179
+ }
180
+ };
181
+ const rootKeys = [];
182
+ for (const root of data) {
183
+ rootKeys.push(getOrAssignKey(root));
184
+ walk(root, 0, undefined);
185
+ }
186
+ childrenKeyMap.set(undefined, rootKeys);
187
+ }
188
+ else {
189
+ // flat mode
190
+ const idField = resolvedTreeOptions.idField || props.keyField;
191
+ if (!idField) {
192
+ throw new Error('Table treeOptions.mode="flat" requires either treeOptions.idField or keyField to be set so the table can resolve parent-child relationships against a stable id.');
193
+ }
194
+ const parentIdField = resolvedTreeOptions.parentIdField;
195
+ // Pass 1: assign __key, build idToKey
196
+ const idToKey = new Map();
197
+ const idToRow = new Map();
198
+ for (const d of data) {
199
+ const id = d === null || d === void 0 ? void 0 : d[idField];
200
+ if (id === undefined || id === null)
201
+ continue;
202
+ idToKey.set(id, getOrAssignKey(d));
203
+ idToRow.set(id, d);
204
+ }
205
+ // Pass 2: build parent->children id map. Roots = parentId null/undefined
206
+ // OR parentId points at a non-existent row.
207
+ const parentToChildIds = new Map();
208
+ const rootIds = [];
209
+ let warnedOrphan = false;
210
+ for (const d of data) {
211
+ const id = d === null || d === void 0 ? void 0 : d[idField];
212
+ if (id === undefined || id === null)
213
+ continue;
214
+ const parentId = d === null || d === void 0 ? void 0 : d[parentIdField];
215
+ if (parentId === undefined || parentId === null) {
216
+ rootIds.push(id);
217
+ continue;
218
+ }
219
+ if (!idToRow.has(parentId)) {
220
+ if (!warnedOrphan) {
221
+ // eslint-disable-next-line no-console
222
+ console.warn(`Table tree (flat mode): row id "${id}" references missing parentId "${parentId}"; treating as root.`);
223
+ warnedOrphan = true;
224
+ }
225
+ rootIds.push(id);
226
+ continue;
227
+ }
228
+ if (!parentToChildIds.has(parentId))
229
+ parentToChildIds.set(parentId, []);
230
+ parentToChildIds.get(parentId).push(id);
231
+ }
232
+ // Pass 3: DFS from roots with cycle detection
233
+ const visiting = new Set();
234
+ let warnedCycle = false;
235
+ const walkFlat = (id, level, parentKey) => {
236
+ if (visiting.has(id)) {
237
+ if (!warnedCycle) {
238
+ // eslint-disable-next-line no-console
239
+ console.warn(`Table tree (flat mode): cycle detected at row id "${id}"; truncating subtree.`);
240
+ warnedCycle = true;
241
+ }
242
+ return;
243
+ }
244
+ visiting.add(id);
245
+ const node = idToRow.get(id);
246
+ const key = idToKey.get(id);
247
+ const childIds = parentToChildIds.get(id) || [];
248
+ const childKeys = childIds
249
+ .map((cid) => idToKey.get(cid))
250
+ .filter((k) => !!k);
251
+ const augmented = Object.assign(Object.assign({}, node), { __key: key, __index: counter++, __level: level, __parentKey: parentKey, __hasChildren: childIds.length > 0, __childKeys: childKeys });
252
+ rows.push(augmented);
253
+ parentKeyMap.set(key, parentKey);
254
+ if (childIds.length > 0) {
255
+ childrenKeyMap.set(key, childKeys);
256
+ expandableKeys.push(key);
257
+ }
258
+ for (const cid of childIds) {
259
+ walkFlat(cid, level + 1, key);
260
+ }
261
+ visiting.delete(id);
262
+ };
263
+ const rootKeys = [];
264
+ for (const id of rootIds) {
265
+ const k = idToKey.get(id);
266
+ if (k)
267
+ rootKeys.push(k);
268
+ walkFlat(id, 0, undefined);
269
+ }
270
+ childrenKeyMap.set(undefined, rootKeys);
271
+ }
272
+ return {
273
+ rows,
274
+ treeMeta: { parentKeyMap, childrenKeyMap, expandableKeys },
275
+ };
276
+ }, [data, resolvedTreeOptions, props.keyField]);
277
+ return (_jsx(TableProvider, Object.assign({ columns: columnProps, data: __data, tableElement: tableElement, headerRowElm: headerRowElm, tableDimensions: tableDimensions, targetElm: targetElm, listElm: listElm, treeOptions: resolvedTreeOptions, treeMeta: treeMeta }, props, { children: _jsx(TableContent, { children: children }) })));
130
278
  };
@@ -6,6 +6,16 @@ export declare const THR: import("styled-components/dist/types").IStyledComponen
6
6
  export declare const TD: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, TDProps>> & string;
7
7
  export declare const TH: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof TDProps> & TDProps, never>> & string;
8
8
  export declare const InnerCellContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
9
+ export declare const TreeCellWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
10
+ export declare const TreeIndentSpacer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
11
+ $level: number;
12
+ $indentPx: number;
13
+ }>> & string;
14
+ export declare const TreeChevronButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {
15
+ $expanded: boolean;
16
+ }>> & string;
17
+ export declare const TreeChevronPlaceholder: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
18
+ export declare const TreeCellContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
9
19
  export declare const TableViewPort: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
10
20
  export declare const TableListElement: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
11
21
  export declare const TableWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
@@ -115,6 +115,55 @@ export const InnerCellContent = styled.div `
115
115
  overflow: hidden;
116
116
  text-overflow: ellipsis;
117
117
  `;
118
+ export const TreeCellWrapper = styled.div `
119
+ display: flex;
120
+ flex-direction: row;
121
+ align-items: center;
122
+ flex: 1 1 auto;
123
+ min-width: 0;
124
+ `;
125
+ export const TreeIndentSpacer = styled.div `
126
+ flex: 0 0 auto;
127
+ width: ${({ $level, $indentPx }) => $level * $indentPx}px;
128
+ `;
129
+ export const TreeChevronButton = styled.button `
130
+ flex: 0 0 auto;
131
+ width: 14px;
132
+ height: 16px;
133
+ padding: 0;
134
+ margin: 0 8px 0 0;
135
+ display: inline-flex;
136
+ align-items: center;
137
+ justify-content: flex-start;
138
+ background: transparent;
139
+ border: none;
140
+ cursor: pointer;
141
+ color: ${({ theme }) => theme.palette.text.secondary};
142
+ transition: transform 120ms ease;
143
+ transform: rotate(${({ $expanded }) => ($expanded ? "90deg" : "0deg")});
144
+
145
+ &:hover {
146
+ color: ${({ theme }) => theme.palette.text.primary};
147
+ }
148
+
149
+ &:focus-visible {
150
+ outline: 1px solid ${({ theme }) => theme.palette.primary.main};
151
+ outline-offset: 1px;
152
+ }
153
+ `;
154
+ export const TreeChevronPlaceholder = styled.div `
155
+ flex: 0 0 auto;
156
+ width: 12px;
157
+ height: 16px;
158
+ margin: 0 10px 0 0;
159
+ `;
160
+ export const TreeCellContent = styled.div `
161
+ flex: 1 1 auto;
162
+ min-width: 0;
163
+ overflow: hidden;
164
+ text-overflow: ellipsis;
165
+ white-space: nowrap;
166
+ `;
118
167
  export const TableViewPort = styled.div `
119
168
  display: flex;
120
169
  flex-direction: column;
@@ -148,6 +197,14 @@ export const StyledTable = styled.div `
148
197
  font-size: ${TableDefaults.td.fontSize.compact}px !important;
149
198
  }
150
199
 
200
+ .mfui-td[data-tree-cell="true"] {
201
+ padding-left: ${TableDefaults.td.padding.normal - 3}px;
202
+ }
203
+
204
+ &[data-compact="true"] .mfui-td[data-tree-cell="true"] {
205
+ padding-left: ${TableDefaults.td.padding.compact - 3}px !important;
206
+ }
207
+
151
208
  .os-scrollbar {
152
209
  pointer-events: auto;
153
210
  visibility: visible;
@@ -21,5 +21,12 @@ declare const TableDefaults: {
21
21
  minWidth: number;
22
22
  maxWidth: number;
23
23
  };
24
+ tree: {
25
+ indentPx: number;
26
+ chevronWidth: number;
27
+ defaultMode: "nested";
28
+ defaultChildrenField: string;
29
+ defaultParentIdField: string;
30
+ };
24
31
  };
25
32
  export default TableDefaults;
@@ -21,5 +21,12 @@ const TableDefaults = {
21
21
  minWidth: 35,
22
22
  maxWidth: 35,
23
23
  },
24
+ tree: {
25
+ indentPx: 16,
26
+ chevronWidth: 16,
27
+ defaultMode: "nested",
28
+ defaultChildrenField: "children",
29
+ defaultParentIdField: "parentId",
30
+ },
24
31
  };
25
32
  export default TableDefaults;