@perses-dev/components 0.55.0 → 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.
- package/dist/AlignSelector/AlignSelector.js +115 -25
- package/dist/AlignSelector/AlignSelector.js.map +1 -1
- package/dist/CodeEditor/CodeEditor.d.ts +19 -0
- package/dist/CodeEditor/CodeEditor.d.ts.map +1 -0
- package/dist/CodeEditor/CodeEditor.js +122 -0
- package/dist/CodeEditor/CodeEditor.js.map +1 -0
- package/dist/ColorPicker/ColorPicker.js +153 -61
- package/dist/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js +147 -52
- package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +144 -41
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/DensitySelector/DensitySelector.js +53 -20
- package/dist/DensitySelector/DensitySelector.js.map +1 -1
- package/dist/Dialog/Dialog.d.ts +3 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +202 -49
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js +79 -27
- package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/DragAndDrop/DragAndDropList.js +184 -113
- package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
- package/dist/DragAndDrop/DragButton.js +131 -52
- package/dist/DragAndDrop/DragButton.js.map +1 -1
- package/dist/DragAndDrop/DropIndicator.js +51 -26
- package/dist/DragAndDrop/DropIndicator.js.map +1 -1
- package/dist/Drawer/Drawer.js +75 -15
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/EChart/EChart.js +179 -90
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/ErrorAlert.js +14 -4
- package/dist/ErrorAlert.js.map +1 -1
- package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js +463 -190
- package/dist/ExemplarMetadata/ExemplarMetadataTooltip.js.map +1 -1
- package/dist/FontSizeSelector/FontSizeSelector.js +82 -50
- package/dist/FontSizeSelector/FontSizeSelector.js.map +1 -1
- package/dist/FormEditor/FormActions.js +88 -14
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.js +246 -99
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.js +90 -25
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +105 -42
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/JSONEditor.d.ts +2 -6
- package/dist/JSONEditor.d.ts.map +1 -1
- package/dist/JSONEditor.js +24 -37
- package/dist/JSONEditor.js.map +1 -1
- package/dist/Legend/CompactLegend.js +77 -27
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.js +184 -82
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/LegendColorBadge.js +54 -9
- package/dist/Legend/LegendColorBadge.js.map +1 -1
- package/dist/Legend/ListLegend.js +46 -16
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.js +184 -48
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +90 -48
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +2 -2
- package/dist/Legend/legend-model.d.ts.map +1 -1
- package/dist/Legend/legend-model.js.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.js +148 -67
- package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
- package/dist/ModeSelector/ModeSelector.js +61 -19
- package/dist/ModeSelector/ModeSelector.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +20 -9
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +130 -54
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +17 -6
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +76 -28
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
- package/dist/Overlay/Overlay.js +71 -27
- package/dist/Overlay/Overlay.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +96 -38
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/RepeatGrid/RepeatGrid.js +117 -45
- package/dist/RepeatGrid/RepeatGrid.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +99 -38
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
- package/dist/SortSelector/SortSelector.js +51 -18
- package/dist/SortSelector/SortSelector.js.map +1 -1
- package/dist/SortSelector/SortSelectorButtons.js +109 -25
- package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
- package/dist/Table/InnerTable.js +46 -15
- package/dist/Table/InnerTable.js.map +1 -1
- package/dist/Table/Table.d.ts +3 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +410 -158
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableBody.js +15 -4
- package/dist/Table/TableBody.js.map +1 -1
- package/dist/Table/TableCell.js +284 -107
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +101 -32
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableFoot.js +15 -4
- package/dist/Table/TableFoot.js.map +1 -1
- package/dist/Table/TableHead.js +15 -4
- package/dist/Table/TableHead.js.map +1 -1
- package/dist/Table/TableHeaderCell.js +119 -62
- package/dist/Table/TableHeaderCell.js.map +1 -1
- package/dist/Table/TableRow.js +33 -9
- package/dist/Table/TableRow.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +5 -4
- package/dist/Table/TableToolbar.d.ts.map +1 -1
- package/dist/Table/TableToolbar.js +172 -100
- package/dist/Table/TableToolbar.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts +11 -11
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +387 -219
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +27 -7
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +6 -5
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.js +57 -32
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -1
- package/dist/Table/hooks/useTableKeyboardNav.js +115 -74
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -1
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +74 -53
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +44 -15
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +33 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +137 -47
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +341 -174
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +368 -162
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +580 -209
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +189 -65
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +168 -78
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js +38 -11
- package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +229 -72
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +73 -27
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +221 -121
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +44 -38
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeZoneSelector.js +131 -36
- package/dist/TimeZoneSelector.js.map +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js +18 -7
- package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js +830 -334
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +252 -90
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js +170 -59
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js +800 -322
- package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js +218 -91
- package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
- package/dist/YAMLEditor/YAMLEditor.d.ts +12 -0
- package/dist/YAMLEditor/YAMLEditor.d.ts.map +1 -0
- package/dist/YAMLEditor/YAMLEditor.js +41 -0
- package/dist/YAMLEditor/YAMLEditor.js.map +1 -0
- package/dist/YAMLEditor/index.d.ts +2 -0
- package/dist/YAMLEditor/index.d.ts.map +1 -0
- package/dist/YAMLEditor/index.js +15 -0
- package/dist/YAMLEditor/index.js.map +1 -0
- package/dist/YAMLEditor/yaml-utils.d.ts +11 -0
- package/dist/YAMLEditor/yaml-utils.d.ts.map +1 -0
- package/dist/YAMLEditor/yaml-utils.js +52 -0
- package/dist/YAMLEditor/yaml-utils.js.map +1 -0
- package/dist/YAxisLabel.js +64 -20
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/context/ChartsProvider.js +32 -16
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/context/ItemActionsProvider.js +110 -61
- package/dist/context/ItemActionsProvider.js.map +1 -1
- package/dist/context/SelectionProvider.js +170 -66
- package/dist/context/SelectionProvider.js.map +1 -1
- package/dist/context/SnackbarProvider.js +101 -44
- package/dist/context/SnackbarProvider.js.map +1 -1
- package/dist/context/TimeZoneProvider.js +35 -14
- package/dist/context/TimeZoneProvider.js.map +1 -1
- package/dist/controls/TextField.js +86 -25
- package/dist/controls/TextField.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/browser-storage.js +64 -34
- package/dist/utils/browser-storage.js.map +1 -1
- package/package.json +12 -6
|
@@ -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 {
|
|
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(
|
|
20
|
-
const
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
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","
|
|
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
|
|
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(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
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
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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"
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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"
|
|
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"}
|