@perses-dev/components 0.55.0-rc.1 → 0.56.0-beta.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 (204) hide show
  1. package/dist/AlignSelector/AlignSelector.js +115 -25
  2. package/dist/AlignSelector/AlignSelector.js.map +1 -1
  3. package/dist/CodeEditor/CodeEditor.d.ts +19 -0
  4. package/dist/CodeEditor/CodeEditor.d.ts.map +1 -0
  5. package/dist/CodeEditor/CodeEditor.js +122 -0
  6. package/dist/CodeEditor/CodeEditor.js.map +1 -0
  7. package/dist/ColorPicker/ColorPicker.js +153 -61
  8. package/dist/ColorPicker/ColorPicker.js.map +1 -1
  9. package/dist/ColorPicker/OptionsColorPicker.js +147 -52
  10. package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
  11. package/dist/ContentWithLegend/ContentWithLegend.js +144 -41
  12. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  13. package/dist/DensitySelector/DensitySelector.js +53 -20
  14. package/dist/DensitySelector/DensitySelector.js.map +1 -1
  15. package/dist/Dialog/Dialog.d.ts +3 -2
  16. package/dist/Dialog/Dialog.d.ts.map +1 -1
  17. package/dist/Dialog/Dialog.js +202 -49
  18. package/dist/Dialog/Dialog.js.map +1 -1
  19. package/dist/Dialog/DiscardChangesConfirmationDialog.js +79 -27
  20. package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
  21. package/dist/DragAndDrop/DragAndDropList.js +184 -113
  22. package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
  23. package/dist/DragAndDrop/DragButton.js +131 -52
  24. package/dist/DragAndDrop/DragButton.js.map +1 -1
  25. package/dist/DragAndDrop/DropIndicator.js +51 -26
  26. package/dist/DragAndDrop/DropIndicator.js.map +1 -1
  27. package/dist/Drawer/Drawer.js +75 -15
  28. package/dist/Drawer/Drawer.js.map +1 -1
  29. package/dist/EChart/EChart.js +179 -90
  30. package/dist/EChart/EChart.js.map +1 -1
  31. package/dist/ErrorAlert.js +14 -4
  32. package/dist/ErrorAlert.js.map +1 -1
  33. package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js +463 -190
  34. package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js.map +1 -1
  35. package/dist/FontSizeSelector/FontSizeSelector.js +82 -50
  36. package/dist/FontSizeSelector/FontSizeSelector.js.map +1 -1
  37. package/dist/FormEditor/FormActions.js +88 -14
  38. package/dist/FormEditor/FormActions.js.map +1 -1
  39. package/dist/FormatControls/FormatControls.js +246 -99
  40. package/dist/FormatControls/FormatControls.js.map +1 -1
  41. package/dist/FormatControls/UnitSelector.js +90 -25
  42. package/dist/FormatControls/UnitSelector.js.map +1 -1
  43. package/dist/InfoTooltip/InfoTooltip.js +105 -42
  44. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  45. package/dist/JSONEditor.d.ts +2 -6
  46. package/dist/JSONEditor.d.ts.map +1 -1
  47. package/dist/JSONEditor.js +24 -37
  48. package/dist/JSONEditor.js.map +1 -1
  49. package/dist/Legend/CompactLegend.js +77 -27
  50. package/dist/Legend/CompactLegend.js.map +1 -1
  51. package/dist/Legend/Legend.js +184 -82
  52. package/dist/Legend/Legend.js.map +1 -1
  53. package/dist/Legend/LegendColorBadge.js +54 -9
  54. package/dist/Legend/LegendColorBadge.js.map +1 -1
  55. package/dist/Legend/ListLegend.js +46 -16
  56. package/dist/Legend/ListLegend.js.map +1 -1
  57. package/dist/Legend/ListLegendItem.js +184 -48
  58. package/dist/Legend/ListLegendItem.js.map +1 -1
  59. package/dist/Legend/TableLegend.d.ts.map +1 -1
  60. package/dist/Legend/TableLegend.js +90 -48
  61. package/dist/Legend/TableLegend.js.map +1 -1
  62. package/dist/Legend/legend-model.d.ts +2 -2
  63. package/dist/Legend/legend-model.d.ts.map +1 -1
  64. package/dist/Legend/legend-model.js.map +1 -1
  65. package/dist/LinksEditor/LinkEditorForm.js +148 -67
  66. package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
  67. package/dist/ModeSelector/ModeSelector.js +61 -19
  68. package/dist/ModeSelector/ModeSelector.js.map +1 -1
  69. package/dist/OptionsEditorLayout/OptionsEditorColumn.js +20 -9
  70. package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
  71. package/dist/OptionsEditorLayout/OptionsEditorControl.js +130 -54
  72. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  73. package/dist/OptionsEditorLayout/OptionsEditorGrid.js +17 -6
  74. package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
  75. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +76 -28
  76. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
  77. package/dist/Overlay/Overlay.js +71 -27
  78. package/dist/Overlay/Overlay.js.map +1 -1
  79. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +96 -38
  80. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
  81. package/dist/RepeatGrid/RepeatGrid.js +117 -45
  82. package/dist/RepeatGrid/RepeatGrid.js.map +1 -1
  83. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +99 -38
  84. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  85. package/dist/SortSelector/SortSelector.js +51 -18
  86. package/dist/SortSelector/SortSelector.js.map +1 -1
  87. package/dist/SortSelector/SortSelectorButtons.js +109 -25
  88. package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
  89. package/dist/Table/InnerTable.js +46 -15
  90. package/dist/Table/InnerTable.js.map +1 -1
  91. package/dist/Table/Table.d.ts +3 -1
  92. package/dist/Table/Table.d.ts.map +1 -1
  93. package/dist/Table/Table.js +410 -158
  94. package/dist/Table/Table.js.map +1 -1
  95. package/dist/Table/TableBody.js +15 -4
  96. package/dist/Table/TableBody.js.map +1 -1
  97. package/dist/Table/TableCell.js +284 -107
  98. package/dist/Table/TableCell.js.map +1 -1
  99. package/dist/Table/TableCheckbox.js +101 -32
  100. package/dist/Table/TableCheckbox.js.map +1 -1
  101. package/dist/Table/TableFoot.js +15 -4
  102. package/dist/Table/TableFoot.js.map +1 -1
  103. package/dist/Table/TableHead.js +15 -4
  104. package/dist/Table/TableHead.js.map +1 -1
  105. package/dist/Table/TableHeaderCell.js +119 -62
  106. package/dist/Table/TableHeaderCell.js.map +1 -1
  107. package/dist/Table/TableRow.js +33 -9
  108. package/dist/Table/TableRow.js.map +1 -1
  109. package/dist/Table/TableToolbar.d.ts +5 -4
  110. package/dist/Table/TableToolbar.d.ts.map +1 -1
  111. package/dist/Table/TableToolbar.js +172 -100
  112. package/dist/Table/TableToolbar.js.map +1 -1
  113. package/dist/Table/VirtualizedTable.d.ts +11 -11
  114. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  115. package/dist/Table/VirtualizedTable.js +387 -219
  116. package/dist/Table/VirtualizedTable.js.map +1 -1
  117. package/dist/Table/VirtualizedTableContainer.js +27 -7
  118. package/dist/Table/VirtualizedTableContainer.js.map +1 -1
  119. package/dist/Table/hooks/useFuzzySearch.d.ts +6 -5
  120. package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -1
  121. package/dist/Table/hooks/useFuzzySearch.js +57 -32
  122. package/dist/Table/hooks/useFuzzySearch.js.map +1 -1
  123. package/dist/Table/hooks/useTableKeyboardNav.js +115 -74
  124. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -1
  125. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +1 -1
  126. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -1
  127. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +74 -53
  128. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -1
  129. package/dist/Table/model/table-model.d.ts +44 -15
  130. package/dist/Table/model/table-model.d.ts.map +1 -1
  131. package/dist/Table/model/table-model.js +33 -1
  132. package/dist/Table/model/table-model.js.map +1 -1
  133. package/dist/ThresholdsEditor/ThresholdInput.js +137 -47
  134. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  135. package/dist/ThresholdsEditor/ThresholdsEditor.js +341 -174
  136. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  137. package/dist/TimeRangeSelector/DateTimeRangePicker.js +368 -162
  138. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  139. package/dist/TimeRangeSelector/TimeRangeSelector.js +580 -209
  140. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  141. package/dist/TimeSeriesTooltip/SeriesInfo.js +189 -65
  142. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  143. package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +168 -78
  144. package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
  145. package/dist/TimeSeriesTooltip/SeriesMarker.js +38 -11
  146. package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
  147. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +229 -72
  148. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  149. package/dist/TimeSeriesTooltip/TooltipContent.js +73 -27
  150. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  151. package/dist/TimeSeriesTooltip/TooltipHeader.js +221 -121
  152. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  153. package/dist/TimeSeriesTooltip/tooltip-model.js +44 -38
  154. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  155. package/dist/TimeZoneSelector.js +131 -36
  156. package/dist/TimeZoneSelector.js.map +1 -1
  157. package/dist/ToolbarIconButton/ToolbarIconButton.js +18 -7
  158. package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  159. package/dist/TransformsEditor/TransformEditor.js +830 -334
  160. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  161. package/dist/TransformsEditor/TransformEditorContainer.js +252 -90
  162. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  163. package/dist/TransformsEditor/TransformsEditor.js +170 -59
  164. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  165. package/dist/ValueMappingEditor/ValueMappingEditor.js +800 -322
  166. package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
  167. package/dist/ValueMappingEditor/ValueMappingsEditor.js +218 -91
  168. package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
  169. package/dist/YAMLEditor/YAMLEditor.d.ts +12 -0
  170. package/dist/YAMLEditor/YAMLEditor.d.ts.map +1 -0
  171. package/dist/YAMLEditor/YAMLEditor.js +41 -0
  172. package/dist/YAMLEditor/YAMLEditor.js.map +1 -0
  173. package/dist/YAMLEditor/index.d.ts +2 -0
  174. package/dist/YAMLEditor/index.d.ts.map +1 -0
  175. package/dist/YAMLEditor/index.js +15 -0
  176. package/dist/YAMLEditor/index.js.map +1 -0
  177. package/dist/YAMLEditor/yaml-utils.d.ts +11 -0
  178. package/dist/YAMLEditor/yaml-utils.d.ts.map +1 -0
  179. package/dist/YAMLEditor/yaml-utils.js +52 -0
  180. package/dist/YAMLEditor/yaml-utils.js.map +1 -0
  181. package/dist/YAxisLabel.js +64 -20
  182. package/dist/YAxisLabel.js.map +1 -1
  183. package/dist/context/ChartsProvider.js +32 -16
  184. package/dist/context/ChartsProvider.js.map +1 -1
  185. package/dist/context/ItemActionsProvider.js +110 -61
  186. package/dist/context/ItemActionsProvider.js.map +1 -1
  187. package/dist/context/SelectionProvider.js +170 -66
  188. package/dist/context/SelectionProvider.js.map +1 -1
  189. package/dist/context/SnackbarProvider.js +101 -44
  190. package/dist/context/SnackbarProvider.js.map +1 -1
  191. package/dist/context/TimeZoneProvider.js +35 -14
  192. package/dist/context/TimeZoneProvider.js.map +1 -1
  193. package/dist/controls/TextField.js +86 -25
  194. package/dist/controls/TextField.js.map +1 -1
  195. package/dist/index.d.ts +1 -0
  196. package/dist/index.d.ts.map +1 -1
  197. package/dist/index.js +1 -0
  198. package/dist/index.js.map +1 -1
  199. package/dist/utils/browser-storage.js +64 -34
  200. package/dist/utils/browser-storage.js.map +1 -1
  201. package/dist/utils/time-series-data.d.ts.map +1 -1
  202. package/dist/utils/time-series-data.js +5 -2
  203. package/dist/utils/time-series-data.js.map +1 -1
  204. package/package.json +13 -7
@@ -11,47 +11,104 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
14
+ import { c as _c } from "react-compiler-runtime";
15
+ import { createContext, useContext, useEffect, useRef, useState } from "react";
15
16
  const SelectionContext = /*#__PURE__*/ createContext(undefined);
16
17
  const defaultGetId = (_item, index)=>index;
17
18
  /**
18
19
  * Provides selection state to descendant components.
19
- */ export function SelectionProvider({ children }) {
20
- const [selectionMap, setSelectionMap] = useState(new Map());
20
+ */ export function SelectionProvider(t0) {
21
+ const $ = _c(14);
22
+ const { children } = t0;
23
+ let t1;
24
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
25
+ t1 = new Map();
26
+ $[0] = t1;
27
+ } else {
28
+ t1 = $[0];
29
+ }
30
+ const [selectionMap, setSelectionMap] = useState(t1);
21
31
  const getIdRef = useRef(defaultGetId);
22
- // Allows consumers to register their own getId function. by default we use the index.
23
- const registerGetId = useCallback((fn)=>{
24
- getIdRef.current = fn;
25
- }, []);
26
- const setSelection = useCallback((items)=>{
27
- const newMap = new Map();
28
- items.forEach(({ item, id })=>newMap.set(id, item));
29
- setSelectionMap(newMap);
30
- }, []);
31
- const toggleSelection = useCallback((item, id)=>{
32
- setSelectionMap((prev)=>{
33
- const newMap = new Map(prev);
34
- if (newMap.has(id)) {
35
- newMap.delete(id);
36
- } else {
37
- newMap.set(id, item);
38
- }
39
- return newMap;
40
- });
41
- }, []);
42
- const removeFromSelection = useCallback((id)=>{
43
- setSelectionMap((prev)=>{
44
- if (!prev.has(id)) return prev;
45
- const newMap = new Map(prev);
46
- newMap.delete(id);
47
- return newMap;
48
- });
49
- }, []);
50
- const clearSelection = useCallback(()=>setSelectionMap(new Map()), []);
51
- const isSelected = useCallback((item, index)=>selectionMap.has(getIdRef.current(item, index)), [
52
- selectionMap
53
- ]);
54
- const ctx = useMemo(()=>({
32
+ let t2;
33
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
34
+ t2 = (fn)=>{
35
+ getIdRef.current = fn;
36
+ };
37
+ $[1] = t2;
38
+ } else {
39
+ t2 = $[1];
40
+ }
41
+ const registerGetId = t2;
42
+ let t3;
43
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
44
+ t3 = (items)=>{
45
+ const newMap = new Map();
46
+ items.forEach((t4)=>{
47
+ const { item, id } = t4;
48
+ return newMap.set(id, item);
49
+ });
50
+ setSelectionMap(newMap);
51
+ };
52
+ $[2] = t3;
53
+ } else {
54
+ t3 = $[2];
55
+ }
56
+ const setSelection = t3;
57
+ let t4;
58
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
59
+ t4 = (item_0, id_0)=>{
60
+ setSelectionMap((prev)=>{
61
+ const newMap_0 = new Map(prev);
62
+ if (newMap_0.has(id_0)) {
63
+ newMap_0.delete(id_0);
64
+ } else {
65
+ newMap_0.set(id_0, item_0);
66
+ }
67
+ return newMap_0;
68
+ });
69
+ };
70
+ $[3] = t4;
71
+ } else {
72
+ t4 = $[3];
73
+ }
74
+ const toggleSelection = t4;
75
+ let t5;
76
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
77
+ t5 = (id_1)=>{
78
+ setSelectionMap((prev_0)=>{
79
+ if (!prev_0.has(id_1)) {
80
+ return prev_0;
81
+ }
82
+ const newMap_1 = new Map(prev_0);
83
+ newMap_1.delete(id_1);
84
+ return newMap_1;
85
+ });
86
+ };
87
+ $[4] = t5;
88
+ } else {
89
+ t5 = $[4];
90
+ }
91
+ const removeFromSelection = t5;
92
+ let t6;
93
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
94
+ t6 = ()=>setSelectionMap(new Map());
95
+ $[5] = t6;
96
+ } else {
97
+ t6 = $[5];
98
+ }
99
+ const clearSelection = t6;
100
+ let t7;
101
+ if ($[6] !== selectionMap) {
102
+ t7 = (item_1, index)=>selectionMap.has(getIdRef.current(item_1, index));
103
+ $[6] = selectionMap;
104
+ $[7] = t7;
105
+ } else {
106
+ t7 = $[7];
107
+ }
108
+ const isSelected = t7;
109
+ let t8;
110
+ if ($[8] !== isSelected || $[9] !== selectionMap) {
111
+ t8 = {
55
112
  selectionMap,
56
113
  setSelection,
57
114
  toggleSelection,
@@ -59,19 +116,27 @@ const defaultGetId = (_item, index)=>index;
59
116
  clearSelection,
60
117
  isSelected,
61
118
  registerGetId
62
- }), [
63
- selectionMap,
64
- setSelection,
65
- toggleSelection,
66
- removeFromSelection,
67
- clearSelection,
68
- isSelected,
69
- registerGetId
70
- ]);
71
- return /*#__PURE__*/ _jsx(SelectionContext.Provider, {
72
- value: ctx,
73
- children: children
74
- });
119
+ };
120
+ $[8] = isSelected;
121
+ $[9] = selectionMap;
122
+ $[10] = t8;
123
+ } else {
124
+ t8 = $[10];
125
+ }
126
+ const ctx = t8;
127
+ let t9;
128
+ if ($[11] !== children || $[12] !== ctx) {
129
+ t9 = /*#__PURE__*/ _jsx(SelectionContext.Provider, {
130
+ value: ctx,
131
+ children: children
132
+ });
133
+ $[11] = children;
134
+ $[12] = ctx;
135
+ $[13] = t9;
136
+ } else {
137
+ t9 = $[13];
138
+ }
139
+ return t9;
75
140
  }
76
141
  /**
77
142
  * No-op functions and empty map for when there is no context available.
@@ -95,25 +160,64 @@ const defaultState = {
95
160
  * @param options Optional configuration for the selection hook.
96
161
  * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.
97
162
  */ export function useSelection(options) {
163
+ const $ = _c(10);
98
164
  const ctx = useContext(SelectionContext);
99
- useEffect(()=>{
100
- if (ctx && options?.getId) {
101
- ctx.registerGetId(options.getId);
102
- }
103
- }, [
104
- ctx,
105
- options?.getId
106
- ]);
107
- const memoizedResult = useMemo(()=>{
108
- if (!ctx) return defaultState;
109
- const { registerGetId: _, ...rest } = ctx;
110
- return {
111
- ...rest,
112
- hasContext: true
165
+ let t0;
166
+ if ($[0] !== ctx || $[1] !== options) {
167
+ t0 = ()=>{
168
+ if (ctx && options?.getId) {
169
+ ctx.registerGetId(options.getId);
170
+ }
113
171
  };
114
- }, [
115
- ctx
116
- ]);
172
+ $[0] = ctx;
173
+ $[1] = options;
174
+ $[2] = t0;
175
+ } else {
176
+ t0 = $[2];
177
+ }
178
+ const t1 = options?.getId;
179
+ let t2;
180
+ if ($[3] !== ctx || $[4] !== t1) {
181
+ t2 = [
182
+ ctx,
183
+ t1
184
+ ];
185
+ $[3] = ctx;
186
+ $[4] = t1;
187
+ $[5] = t2;
188
+ } else {
189
+ t2 = $[5];
190
+ }
191
+ useEffect(t0, t2);
192
+ let t3;
193
+ bb0: {
194
+ if (!ctx) {
195
+ t3 = defaultState;
196
+ break bb0;
197
+ }
198
+ let rest;
199
+ if ($[6] !== ctx) {
200
+ const { registerGetId: _, ...t4 } = ctx;
201
+ rest = t4;
202
+ $[6] = ctx;
203
+ $[7] = rest;
204
+ } else {
205
+ rest = $[7];
206
+ }
207
+ let t4;
208
+ if ($[8] !== rest) {
209
+ t4 = {
210
+ ...rest,
211
+ hasContext: true
212
+ };
213
+ $[8] = rest;
214
+ $[9] = t4;
215
+ } else {
216
+ t4 = $[9];
217
+ }
218
+ t3 = t4;
219
+ }
220
+ const memoizedResult = t3;
117
221
  return memoizedResult;
118
222
  }
119
223
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/SelectionProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { ReactElement, ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\n\nexport type GetIdFn<T, Id> = (item: T, index: number) => Id;\n\nexport interface SelectionState<T, Id = unknown> {\n selectionMap: Map<Id, T>;\n setSelection: (items: Array<{ id: Id; item: T }>) => void;\n toggleSelection: (item: T, id: Id) => void;\n removeFromSelection: (id: Id) => void;\n clearSelection: () => void;\n isSelected: (item: T, index: number) => boolean;\n}\n\nexport interface SelectionProviderProps {\n children: ReactNode;\n}\n\nexport interface UseSelectionOptions<T, Id = string | number> {\n getId?: GetIdFn<T, Id>;\n}\n\ninterface InternalState<T, Id> extends SelectionState<T, Id> {\n registerGetId: (fn: GetIdFn<T, Id>) => void;\n}\n\nconst SelectionContext = createContext<InternalState<unknown, unknown> | undefined>(undefined);\n\nconst defaultGetId = (_item: unknown, index: number): unknown => index;\n\n/**\n * Provides selection state to descendant components.\n */\nexport function SelectionProvider({ children }: SelectionProviderProps): ReactElement {\n const [selectionMap, setSelectionMap] = useState(new Map<unknown, unknown>());\n const getIdRef = useRef<GetIdFn<unknown, unknown>>(defaultGetId);\n\n // Allows consumers to register their own getId function. by default we use the index.\n const registerGetId = useCallback((fn: GetIdFn<unknown, unknown>) => {\n getIdRef.current = fn;\n }, []);\n\n const setSelection = useCallback((items: Array<{ id: unknown; item: unknown }>) => {\n const newMap = new Map<unknown, unknown>();\n items.forEach(({ item, id }) => newMap.set(id, item));\n setSelectionMap(newMap);\n }, []);\n\n const toggleSelection = useCallback((item: unknown, id: unknown) => {\n setSelectionMap((prev) => {\n const newMap = new Map(prev);\n if (newMap.has(id)) {\n newMap.delete(id);\n } else {\n newMap.set(id, item);\n }\n return newMap;\n });\n }, []);\n\n const removeFromSelection = useCallback((id: unknown) => {\n setSelectionMap((prev) => {\n if (!prev.has(id)) return prev;\n const newMap = new Map(prev);\n newMap.delete(id);\n return newMap;\n });\n }, []);\n\n const clearSelection = useCallback(() => setSelectionMap(new Map()), []);\n\n const isSelected = useCallback(\n (item: unknown, index: number) => selectionMap.has(getIdRef.current(item, index)),\n [selectionMap],\n );\n\n const ctx = useMemo<InternalState<unknown, unknown>>(\n () => ({\n selectionMap,\n setSelection,\n toggleSelection,\n removeFromSelection,\n clearSelection,\n isSelected,\n registerGetId,\n }),\n [selectionMap, setSelection, toggleSelection, removeFromSelection, clearSelection, isSelected, registerGetId],\n );\n\n return <SelectionContext.Provider value={ctx}>{children}</SelectionContext.Provider>;\n}\n\n/**\n * No-op functions and empty map for when there is no context available.\n * This allows components to use the hook without crashing given the optional nature of the provider.\n */\nconst noOp = (): void => {};\nconst noOpIsSelected = (): boolean => false;\nconst emptyMap = new Map<unknown, unknown>();\nconst defaultState: SelectionState<unknown, unknown> & { hasContext: false } = {\n selectionMap: emptyMap,\n setSelection: noOp,\n toggleSelection: noOp,\n removeFromSelection: noOp,\n clearSelection: noOp,\n isSelected: noOpIsSelected,\n hasContext: false,\n};\n\n/**\n * Hook to access selection state from context.\n * If used outside of a SelectionProvider, returns no-op functions and an empty selection map.\n *\n * @param options Optional configuration for the selection hook.\n * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.\n */\nexport function useSelection<T, Id = string | number>(\n options?: UseSelectionOptions<T, Id>,\n): SelectionState<T, Id> & { hasContext: boolean } {\n const ctx = useContext(SelectionContext);\n\n useEffect(() => {\n if (ctx && options?.getId) {\n ctx.registerGetId(options.getId as GetIdFn<unknown, unknown>);\n }\n }, [ctx, options?.getId]);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as SelectionState<T, Id> & { hasContext: false };\n\n const { registerGetId: _, ...rest } = ctx;\n return { ...rest, hasContext: true } as SelectionState<T, Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","SelectionContext","undefined","defaultGetId","_item","index","SelectionProvider","children","selectionMap","setSelectionMap","Map","getIdRef","registerGetId","fn","current","setSelection","items","newMap","forEach","item","id","set","toggleSelection","prev","has","delete","removeFromSelection","clearSelection","isSelected","ctx","Provider","value","noOp","noOpIsSelected","emptyMap","defaultState","hasContext","useSelection","options","getId","memoizedResult","_","rest"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAyBrG,MAAMC,iCAAmBP,cAA2DQ;AAEpF,MAAMC,eAAe,CAACC,OAAgBC,QAA2BA;AAEjE;;CAEC,GACD,OAAO,SAASC,kBAAkB,EAAEC,QAAQ,EAA0B;IACpE,MAAM,CAACC,cAAcC,gBAAgB,GAAGT,SAAS,IAAIU;IACrD,MAAMC,WAAWZ,OAAkCI;IAEnD,sFAAsF;IACtF,MAAMS,gBAAgBjB,YAAY,CAACkB;QACjCF,SAASG,OAAO,GAAGD;IACrB,GAAG,EAAE;IAEL,MAAME,eAAepB,YAAY,CAACqB;QAChC,MAAMC,SAAS,IAAIP;QACnBM,MAAME,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAEC,EAAE,EAAE,GAAKH,OAAOI,GAAG,CAACD,IAAID;QAC/CV,gBAAgBQ;IAClB,GAAG,EAAE;IAEL,MAAMK,kBAAkB3B,YAAY,CAACwB,MAAeC;QAClDX,gBAAgB,CAACc;YACf,MAAMN,SAAS,IAAIP,IAAIa;YACvB,IAAIN,OAAOO,GAAG,CAACJ,KAAK;gBAClBH,OAAOQ,MAAM,CAACL;YAChB,OAAO;gBACLH,OAAOI,GAAG,CAACD,IAAID;YACjB;YACA,OAAOF;QACT;IACF,GAAG,EAAE;IAEL,MAAMS,sBAAsB/B,YAAY,CAACyB;QACvCX,gBAAgB,CAACc;YACf,IAAI,CAACA,KAAKC,GAAG,CAACJ,KAAK,OAAOG;YAC1B,MAAMN,SAAS,IAAIP,IAAIa;YACvBN,OAAOQ,MAAM,CAACL;YACd,OAAOH;QACT;IACF,GAAG,EAAE;IAEL,MAAMU,iBAAiBhC,YAAY,IAAMc,gBAAgB,IAAIC,QAAQ,EAAE;IAEvE,MAAMkB,aAAajC,YACjB,CAACwB,MAAed,QAAkBG,aAAagB,GAAG,CAACb,SAASG,OAAO,CAACK,MAAMd,SAC1E;QAACG;KAAa;IAGhB,MAAMqB,MAAM/B,QACV,IAAO,CAAA;YACLU;YACAO;YACAO;YACAI;YACAC;YACAC;YACAhB;QACF,CAAA,GACA;QAACJ;QAAcO;QAAcO;QAAiBI;QAAqBC;QAAgBC;QAAYhB;KAAc;IAG/G,qBAAO,KAACX,iBAAiB6B,QAAQ;QAACC,OAAOF;kBAAMtB;;AACjD;AAEA;;;CAGC,GACD,MAAMyB,OAAO,KAAa;AAC1B,MAAMC,iBAAiB,IAAe;AACtC,MAAMC,WAAW,IAAIxB;AACrB,MAAMyB,eAAyE;IAC7E3B,cAAc0B;IACdnB,cAAciB;IACdV,iBAAiBU;IACjBN,qBAAqBM;IACrBL,gBAAgBK;IAChBJ,YAAYK;IACZG,YAAY;AACd;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,aACdC,OAAoC;IAEpC,MAAMT,MAAMjC,WAAWK;IAEvBJ,UAAU;QACR,IAAIgC,OAAOS,SAASC,OAAO;YACzBV,IAAIjB,aAAa,CAAC0B,QAAQC,KAAK;QACjC;IACF,GAAG;QAACV;QAAKS,SAASC;KAAM;IAExB,MAAMC,iBAAiB1C,QAAQ;QAC7B,IAAI,CAAC+B,KAAK,OAAOM;QAEjB,MAAM,EAAEvB,eAAe6B,CAAC,EAAE,GAAGC,MAAM,GAAGb;QACtC,OAAO;YAAE,GAAGa,IAAI;YAAEN,YAAY;QAAK;IACrC,GAAG;QAACP;KAAI;IAER,OAAOW;AACT"}
1
+ {"version":3,"sources":["../../src/context/SelectionProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { ReactElement, ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\n\nexport type GetIdFn<T, Id> = (item: T, index: number) => Id;\n\nexport interface SelectionState<T, Id = unknown> {\n selectionMap: Map<Id, T>;\n setSelection: (items: Array<{ id: Id; item: T }>) => void;\n toggleSelection: (item: T, id: Id) => void;\n removeFromSelection: (id: Id) => void;\n clearSelection: () => void;\n isSelected: (item: T, index: number) => boolean;\n}\n\nexport interface SelectionProviderProps {\n children: ReactNode;\n}\n\nexport interface UseSelectionOptions<T, Id = string | number> {\n getId?: GetIdFn<T, Id>;\n}\n\ninterface InternalState<T, Id> extends SelectionState<T, Id> {\n registerGetId: (fn: GetIdFn<T, Id>) => void;\n}\n\nconst SelectionContext = createContext<InternalState<unknown, unknown> | undefined>(undefined);\n\nconst defaultGetId = (_item: unknown, index: number): unknown => index;\n\n/**\n * Provides selection state to descendant components.\n */\nexport function SelectionProvider({ children }: SelectionProviderProps): ReactElement {\n const [selectionMap, setSelectionMap] = useState(new Map<unknown, unknown>());\n const getIdRef = useRef<GetIdFn<unknown, unknown>>(defaultGetId);\n\n // Allows consumers to register their own getId function. by default we use the index.\n const registerGetId = useCallback((fn: GetIdFn<unknown, unknown>) => {\n getIdRef.current = fn;\n }, []);\n\n const setSelection = useCallback((items: Array<{ id: unknown; item: unknown }>) => {\n const newMap = new Map<unknown, unknown>();\n items.forEach(({ item, id }) => newMap.set(id, item));\n setSelectionMap(newMap);\n }, []);\n\n const toggleSelection = useCallback((item: unknown, id: unknown) => {\n setSelectionMap((prev) => {\n const newMap = new Map(prev);\n if (newMap.has(id)) {\n newMap.delete(id);\n } else {\n newMap.set(id, item);\n }\n return newMap;\n });\n }, []);\n\n const removeFromSelection = useCallback((id: unknown) => {\n setSelectionMap((prev) => {\n if (!prev.has(id)) return prev;\n const newMap = new Map(prev);\n newMap.delete(id);\n return newMap;\n });\n }, []);\n\n const clearSelection = useCallback(() => setSelectionMap(new Map()), []);\n\n const isSelected = useCallback(\n (item: unknown, index: number) => selectionMap.has(getIdRef.current(item, index)),\n [selectionMap],\n );\n\n const ctx = useMemo<InternalState<unknown, unknown>>(\n () => ({\n selectionMap,\n setSelection,\n toggleSelection,\n removeFromSelection,\n clearSelection,\n isSelected,\n registerGetId,\n }),\n [selectionMap, setSelection, toggleSelection, removeFromSelection, clearSelection, isSelected, registerGetId],\n );\n\n return <SelectionContext.Provider value={ctx}>{children}</SelectionContext.Provider>;\n}\n\n/**\n * No-op functions and empty map for when there is no context available.\n * This allows components to use the hook without crashing given the optional nature of the provider.\n */\nconst noOp = (): void => {};\nconst noOpIsSelected = (): boolean => false;\nconst emptyMap = new Map<unknown, unknown>();\nconst defaultState: SelectionState<unknown, unknown> & { hasContext: false } = {\n selectionMap: emptyMap,\n setSelection: noOp,\n toggleSelection: noOp,\n removeFromSelection: noOp,\n clearSelection: noOp,\n isSelected: noOpIsSelected,\n hasContext: false,\n};\n\n/**\n * Hook to access selection state from context.\n * If used outside of a SelectionProvider, returns no-op functions and an empty selection map.\n *\n * @param options Optional configuration for the selection hook.\n * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.\n */\nexport function useSelection<T, Id = string | number>(\n options?: UseSelectionOptions<T, Id>,\n): SelectionState<T, Id> & { hasContext: boolean } {\n const ctx = useContext(SelectionContext);\n\n useEffect(() => {\n if (ctx && options?.getId) {\n ctx.registerGetId(options.getId as GetIdFn<unknown, unknown>);\n }\n }, [ctx, options?.getId]);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as SelectionState<T, Id> & { hasContext: false };\n\n const { registerGetId: _, ...rest } = ctx;\n return { ...rest, hasContext: true } as SelectionState<T, Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useContext","useEffect","useRef","useState","SelectionContext","undefined","defaultGetId","_item","index","noOp","noOpIsSelected","emptyMap","Map","defaultState","selectionMap","setSelection","toggleSelection","removeFromSelection","clearSelection","isSelected","hasContext"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAGjC,SAASA,aAAa,EAAeC,UAAU,EAAEC,SAAS,EAAWC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAyBrG,MAAMC,iCAAmBL,cAA2DM;AAEpF,MAAMC,eAAe,CAACC,OAAgBC,QAA2BA;AAEjE;;CAEC,GACD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DP;;;CAGC,GACD,MAAMC,OAAO,KAAa;AAC1B,MAAMC,iBAAiB,IAAe;AACtC,MAAMC,WAAW,IAAIC;AACrB,MAAMC,eAAyE;IAC7EC,cAAcH;IACdI,cAAcN;IACdO,iBAAiBP;IACjBQ,qBAAqBR;IACrBS,gBAAgBT;IAChBU,YAAYT;IACZU,YAAY;AACd;AAEA;;;;;;CAMC,GACD,OAAO"}
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { c as _c } from "react-compiler-runtime";
2
3
  // Copyright The Perses Authors
3
4
  // Licensed under the Apache License, Version 2.0 (the "License");
4
5
  // you may not use this file except in compliance with the License.
@@ -13,62 +14,118 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
14
  // limitations under the License.
14
15
  import { styled } from "@mui/material/styles";
15
16
  import { SnackbarProvider as NotistackProvider, useSnackbar as useNotistack, MaterialDesignContent } from "notistack";
16
- import React, { useCallback } from "react";
17
+ import React from "react";
17
18
  /**
18
19
  * Application-wide provider for showing snackbars/toasts.
19
20
  * Customized to preserve formatting in error messages.
20
- */ export function SnackbarProvider({ children, ...props }) {
21
- return /*#__PURE__*/ _jsx(NotistackProvider, {
22
- ...props,
23
- Components: {
24
- error: styled(MaterialDesignContent)(()=>({
25
- '&.notistack-MuiContent-error': {
26
- whiteSpace: 'pre-wrap'
27
- }
28
- }))
29
- },
30
- children: children
31
- });
21
+ */ export function SnackbarProvider(t0) {
22
+ const $ = _c(7);
23
+ let children;
24
+ let props;
25
+ if ($[0] !== t0) {
26
+ ({ children, ...props } = t0);
27
+ $[0] = t0;
28
+ $[1] = children;
29
+ $[2] = props;
30
+ } else {
31
+ children = $[1];
32
+ props = $[2];
33
+ }
34
+ let t1;
35
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
36
+ t1 = {
37
+ error: styled(MaterialDesignContent)(_temp)
38
+ };
39
+ $[3] = t1;
40
+ } else {
41
+ t1 = $[3];
42
+ }
43
+ let t2;
44
+ if ($[4] !== children || $[5] !== props) {
45
+ t2 = /*#__PURE__*/ _jsx(NotistackProvider, {
46
+ ...props,
47
+ Components: t1,
48
+ children: children
49
+ });
50
+ $[4] = children;
51
+ $[5] = props;
52
+ $[6] = t2;
53
+ } else {
54
+ t2 = $[6];
55
+ }
56
+ return t2;
57
+ }
58
+ function _temp() {
59
+ return {
60
+ "&.notistack-MuiContent-error": {
61
+ whiteSpace: "pre-wrap"
62
+ }
63
+ };
32
64
  }
33
65
  /**
34
66
  * Gets the SnackbarContext with methods for displaying snackbars/toasts.
35
67
  */ export function useSnackbar() {
68
+ const $ = _c(10);
36
69
  const { enqueueSnackbar, closeSnackbar } = useNotistack();
37
- // Create variant-specific callbacks
38
- const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');
39
- const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');
40
- const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');
41
- const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');
42
- const exceptionSnackbar = useCallback((error, options)=>{
43
- // Try to use message prop, but fallback to a default message that
44
- // will just stringify the error provided
45
- const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;
46
- return errorSnackbar(message, options);
47
- }, [
48
- errorSnackbar
49
- ]);
50
- return {
51
- enqueueSnackbar,
52
- closeSnackbar,
53
- errorSnackbar,
54
- infoSnackbar,
55
- warningSnackbar,
56
- successSnackbar,
57
- exceptionSnackbar
58
- };
70
+ const errorSnackbar = useEnqueueFunction(enqueueSnackbar, "error");
71
+ const infoSnackbar = useEnqueueFunction(enqueueSnackbar, "info");
72
+ const warningSnackbar = useEnqueueFunction(enqueueSnackbar, "warning");
73
+ const successSnackbar = useEnqueueFunction(enqueueSnackbar, "success");
74
+ let t0;
75
+ if ($[0] !== errorSnackbar) {
76
+ t0 = (error, options)=>{
77
+ const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;
78
+ return errorSnackbar(message, options);
79
+ };
80
+ $[0] = errorSnackbar;
81
+ $[1] = t0;
82
+ } else {
83
+ t0 = $[1];
84
+ }
85
+ const exceptionSnackbar = t0;
86
+ let t1;
87
+ if ($[2] !== closeSnackbar || $[3] !== enqueueSnackbar || $[4] !== errorSnackbar || $[5] !== exceptionSnackbar || $[6] !== infoSnackbar || $[7] !== successSnackbar || $[8] !== warningSnackbar) {
88
+ t1 = {
89
+ enqueueSnackbar,
90
+ closeSnackbar,
91
+ errorSnackbar,
92
+ infoSnackbar,
93
+ warningSnackbar,
94
+ successSnackbar,
95
+ exceptionSnackbar
96
+ };
97
+ $[2] = closeSnackbar;
98
+ $[3] = enqueueSnackbar;
99
+ $[4] = errorSnackbar;
100
+ $[5] = exceptionSnackbar;
101
+ $[6] = infoSnackbar;
102
+ $[7] = successSnackbar;
103
+ $[8] = warningSnackbar;
104
+ $[9] = t1;
105
+ } else {
106
+ t1 = $[9];
107
+ }
108
+ return t1;
59
109
  }
60
110
  // Helper to create a variant-specific enqueue function
61
111
  function useEnqueueFunction(enqueueSnackbar, variant) {
62
- return useCallback((message, options)=>{
63
- const allOptions = {
64
- ...options,
65
- variant
112
+ const $ = _c(3);
113
+ let t0;
114
+ if ($[0] !== enqueueSnackbar || $[1] !== variant) {
115
+ t0 = (message, options)=>{
116
+ const allOptions = {
117
+ ...options,
118
+ variant
119
+ };
120
+ return enqueueSnackbar(message, allOptions);
66
121
  };
67
- return enqueueSnackbar(message, allOptions);
68
- }, [
69
- enqueueSnackbar,
70
- variant
71
- ]);
122
+ $[0] = enqueueSnackbar;
123
+ $[1] = variant;
124
+ $[2] = t0;
125
+ } else {
126
+ t0 = $[2];
127
+ }
128
+ return t0;
72
129
  }
73
130
 
74
131
  //# sourceMappingURL=SnackbarProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/SnackbarProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { styled } from '@mui/material/styles';\nimport type { ProviderContext as NotistackContext, SnackbarMessage, OptionsObject, SnackbarKey } from 'notistack';\nimport { SnackbarProvider as NotistackProvider, useSnackbar as useNotistack, MaterialDesignContent } from 'notistack';\nimport React, { useCallback } from 'react';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar],\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant'],\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant],\n );\n}\n"],"names":["styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","React","useCallback","children","props","Components","error","whiteSpace","enqueueSnackbar","closeSnackbar","errorSnackbar","useEnqueueFunction","infoSnackbar","warningSnackbar","successSnackbar","exceptionSnackbar","options","message","Error","variant","allOptions"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAQ,uBAAuB;AAE9C,SAASC,oBAAoBC,iBAAiB,EAAEC,eAAeC,YAAY,EAAEC,qBAAqB,QAAQ,YAAY;AACtH,OAAOC,SAASC,WAAW,QAAQ,QAAQ;AAmB3C;;;CAGC,GACD,OAAO,SAASN,iBAAiB,EAC/BO,QAAQ,EACR,GAAGC,OAC4C;IAC/C,qBACE,KAACP;QACE,GAAGO,KAAK;QACTC,YAAY;YACVC,OAAOX,OAAOK,uBAAuB,IAAO,CAAA;oBAC1C,gCAAgC;wBAC9BO,YAAY;oBACd;gBACF,CAAA;QACF;kBAECJ;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASL;IACd,MAAM,EAAEU,eAAe,EAAEC,aAAa,EAAE,GAAGV;IAE3C,oCAAoC;IACpC,MAAMW,gBAAgBC,mBAAmBH,iBAAiB;IAC1D,MAAMI,eAAeD,mBAAmBH,iBAAiB;IACzD,MAAMK,kBAAkBF,mBAAmBH,iBAAiB;IAC5D,MAAMM,kBAAkBH,mBAAmBH,iBAAiB;IAE5D,MAAMO,oBAA0Db,YAC9D,CAACI,OAAOU;QACN,kEAAkE;QAClE,yCAAyC;QACzC,MAAMC,UAAUX,iBAAiBY,QAAQZ,MAAMW,OAAO,GAAG,CAAC,8BAA8B,EAAEX,OAAO;QAEjG,OAAOI,cAAcO,SAASD;IAChC,GACA;QAACN;KAAc;IAGjB,OAAO;QACLF;QACAC;QACAC;QACAE;QACAC;QACAC;QACAC;IACF;AACF;AAEA,uDAAuD;AACvD,SAASJ,mBACPH,eAAoD,EACpDW,OAAiC;IAEjC,OAAOjB,YACL,CAACe,SAASD;QACR,MAAMI,aAA4B;YAChC,GAAGJ,OAAO;YACVG;QACF;QACA,OAAOX,gBAAgBS,SAASG;IAClC,GACA;QAACZ;QAAiBW;KAAQ;AAE9B"}
1
+ {"version":3,"sources":["../../src/context/SnackbarProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { styled } from '@mui/material/styles';\nimport type { ProviderContext as NotistackContext, SnackbarMessage, OptionsObject, SnackbarKey } from 'notistack';\nimport { SnackbarProvider as NotistackProvider, useSnackbar as useNotistack, MaterialDesignContent } from 'notistack';\nimport React, { useCallback } from 'react';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar],\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant'],\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant],\n );\n}\n"],"names":["styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","React"],"mappings":";;AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAQ,uBAAuB;AAE9C,SAASC,oBAAoBC,iBAAiB,EAAEC,eAAeC,YAAY,EAAEC,qBAAqB,QAAQ,YAAY;AACtH,OAAOC,WAA4B,QAAQ;AAmB3C;;;CAGC,GACD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBP;;CAEC,GACD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BP,uDAAuD;AACvD"}
@@ -11,28 +11,49 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { c as _c } from "react-compiler-runtime";
14
15
  import React, { createContext, useContext } from "react";
15
16
  import { formatWithTimeZone, dateFormatOptionsWithTimeZone } from "../utils/index.js";
16
17
  export const TimeZoneContext = /*#__PURE__*/ createContext(undefined);
17
18
  export function TimeZoneProvider(props) {
19
+ const $ = _c(3);
18
20
  const { children, timeZone } = props;
19
- return /*#__PURE__*/ _jsx(TimeZoneContext.Provider, {
20
- value: timeZone,
21
- children: children
22
- });
21
+ let t0;
22
+ if ($[0] !== children || $[1] !== timeZone) {
23
+ t0 = /*#__PURE__*/ _jsx(TimeZoneContext.Provider, {
24
+ value: timeZone,
25
+ children: children
26
+ });
27
+ $[0] = children;
28
+ $[1] = timeZone;
29
+ $[2] = t0;
30
+ } else {
31
+ t0 = $[2];
32
+ }
33
+ return t0;
23
34
  }
24
35
  export function useTimeZone() {
36
+ const $ = _c(3);
25
37
  const timeZone = useContext(TimeZoneContext);
26
- return {
27
- // fallback to "local" timezone if TimeZoneProvider is not present in the React tree
28
- timeZone: timeZone ?? 'local',
29
- formatWithUserTimeZone (date, formatString) {
30
- return formatWithTimeZone(date, formatString, timeZone);
31
- },
32
- dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
33
- return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);
34
- }
35
- };
38
+ const t0 = timeZone ?? "local";
39
+ let t1;
40
+ if ($[0] !== t0 || $[1] !== timeZone) {
41
+ t1 = {
42
+ timeZone: t0,
43
+ formatWithUserTimeZone (date, formatString) {
44
+ return formatWithTimeZone(date, formatString, timeZone);
45
+ },
46
+ dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
47
+ return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);
48
+ }
49
+ };
50
+ $[0] = t0;
51
+ $[1] = timeZone;
52
+ $[2] = t1;
53
+ } else {
54
+ t1 = $[2];
55
+ }
56
+ return t1;
36
57
  }
37
58
 
38
59
  //# sourceMappingURL=TimeZoneProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/TimeZoneProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { ReactElement } from 'react';\nimport React, { createContext, useContext } from 'react';\n\nimport { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps): ReactElement {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone(): {\n timeZone: string;\n formatWithUserTimeZone: (date: Date, formatString: string) => string;\n dateFormatOptionsWithUserTimeZone: (dateFormatOptions: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;\n} {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string): string {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined","TimeZoneProvider","props","children","timeZone","Provider","value","useTimeZone","formatWithUserTimeZone","date","formatString","dateFormatOptionsWithUserTimeZone","dateFormatOptions"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,OAAOA,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAEzD,SAASC,kBAAkB,EAAEC,6BAA6B,QAAQ,oBAAW;AAE7E,OAAO,MAAMC,gCAAkBJ,cAAkCK,WAAW;AAO5E,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGF;IAC/B,qBAAO,KAACH,gBAAgBM,QAAQ;QAACC,OAAOF;kBAAWD;;AACrD;AAEA,OAAO,SAASI;IAKd,MAAMH,WAAWR,WAAWG;IAC5B,OAAO;QACL,oFAAoF;QACpFK,UAAUA,YAAY;QACtBI,wBAAuBC,IAAU,EAAEC,YAAoB;YACrD,OAAOb,mBAAmBY,MAAMC,cAAcN;QAChD;QACAO,mCAAkCC,iBAA6C;YAC7E,OAAOd,8BAA8Bc,mBAAmBR;QAC1D;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/context/TimeZoneProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { ReactElement } from 'react';\nimport React, { createContext, useContext } from 'react';\n\nimport { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps): ReactElement {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone(): {\n timeZone: string;\n formatWithUserTimeZone: (date: Date, formatString: string) => string;\n dateFormatOptionsWithUserTimeZone: (dateFormatOptions: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;\n} {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string): string {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAGjC,OAAOA,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAEzD,SAASC,kBAAkB,EAAEC,6BAA6B,QAAQ,oBAAW;AAE7E,OAAO,MAAMC,gCAAkBJ,cAAkCK,WAAW;AAO5E,OAAO;;;;;;;;;;;;;;;;;AAKP,OAAO"}