@perses-dev/components 0.55.1 → 0.56.0-beta.1
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 +294 -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 +442 -204
- 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 +86 -69
- 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 -210
- 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 +15 -8
|
@@ -11,32 +11,122 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { c as _c } from "react-compiler-runtime";
|
|
14
15
|
import { Button, ButtonGroup } from "@mui/material";
|
|
15
|
-
export function AlignSelector(
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
...props
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
]
|
|
39
|
-
}
|
|
16
|
+
export function AlignSelector(t0) {
|
|
17
|
+
const $ = _c(26);
|
|
18
|
+
let onChange;
|
|
19
|
+
let props;
|
|
20
|
+
let t1;
|
|
21
|
+
if ($[0] !== t0) {
|
|
22
|
+
({ onChange, value: t1, ...props } = t0);
|
|
23
|
+
$[0] = t0;
|
|
24
|
+
$[1] = onChange;
|
|
25
|
+
$[2] = props;
|
|
26
|
+
$[3] = t1;
|
|
27
|
+
} else {
|
|
28
|
+
onChange = $[1];
|
|
29
|
+
props = $[2];
|
|
30
|
+
t1 = $[3];
|
|
31
|
+
}
|
|
32
|
+
const value = t1 === undefined ? "left" : t1;
|
|
33
|
+
let t2;
|
|
34
|
+
if ($[4] !== onChange) {
|
|
35
|
+
t2 = (option)=>{
|
|
36
|
+
onChange(option);
|
|
37
|
+
};
|
|
38
|
+
$[4] = onChange;
|
|
39
|
+
$[5] = t2;
|
|
40
|
+
} else {
|
|
41
|
+
t2 = $[5];
|
|
42
|
+
}
|
|
43
|
+
const handleSortChange = t2;
|
|
44
|
+
let t3;
|
|
45
|
+
if ($[6] !== handleSortChange) {
|
|
46
|
+
t3 = ()=>handleSortChange("left");
|
|
47
|
+
$[6] = handleSortChange;
|
|
48
|
+
$[7] = t3;
|
|
49
|
+
} else {
|
|
50
|
+
t3 = $[7];
|
|
51
|
+
}
|
|
52
|
+
const t4 = value === "left" ? "contained" : "outlined";
|
|
53
|
+
let t5;
|
|
54
|
+
if ($[8] !== t3 || $[9] !== t4) {
|
|
55
|
+
t5 = /*#__PURE__*/ _jsx(Button, {
|
|
56
|
+
onClick: t3,
|
|
57
|
+
variant: t4,
|
|
58
|
+
children: "Left"
|
|
59
|
+
}, "left");
|
|
60
|
+
$[8] = t3;
|
|
61
|
+
$[9] = t4;
|
|
62
|
+
$[10] = t5;
|
|
63
|
+
} else {
|
|
64
|
+
t5 = $[10];
|
|
65
|
+
}
|
|
66
|
+
let t6;
|
|
67
|
+
if ($[11] !== handleSortChange) {
|
|
68
|
+
t6 = ()=>handleSortChange("center");
|
|
69
|
+
$[11] = handleSortChange;
|
|
70
|
+
$[12] = t6;
|
|
71
|
+
} else {
|
|
72
|
+
t6 = $[12];
|
|
73
|
+
}
|
|
74
|
+
const t7 = value === "center" ? "contained" : "outlined";
|
|
75
|
+
let t8;
|
|
76
|
+
if ($[13] !== t6 || $[14] !== t7) {
|
|
77
|
+
t8 = /*#__PURE__*/ _jsx(Button, {
|
|
78
|
+
onClick: t6,
|
|
79
|
+
variant: t7,
|
|
80
|
+
children: "Center"
|
|
81
|
+
}, "center");
|
|
82
|
+
$[13] = t6;
|
|
83
|
+
$[14] = t7;
|
|
84
|
+
$[15] = t8;
|
|
85
|
+
} else {
|
|
86
|
+
t8 = $[15];
|
|
87
|
+
}
|
|
88
|
+
let t9;
|
|
89
|
+
if ($[16] !== handleSortChange) {
|
|
90
|
+
t9 = ()=>handleSortChange("right");
|
|
91
|
+
$[16] = handleSortChange;
|
|
92
|
+
$[17] = t9;
|
|
93
|
+
} else {
|
|
94
|
+
t9 = $[17];
|
|
95
|
+
}
|
|
96
|
+
const t10 = value === "right" ? "contained" : "outlined";
|
|
97
|
+
let t11;
|
|
98
|
+
if ($[18] !== t10 || $[19] !== t9) {
|
|
99
|
+
t11 = /*#__PURE__*/ _jsx(Button, {
|
|
100
|
+
onClick: t9,
|
|
101
|
+
variant: t10,
|
|
102
|
+
children: "Right"
|
|
103
|
+
}, "right");
|
|
104
|
+
$[18] = t10;
|
|
105
|
+
$[19] = t9;
|
|
106
|
+
$[20] = t11;
|
|
107
|
+
} else {
|
|
108
|
+
t11 = $[20];
|
|
109
|
+
}
|
|
110
|
+
let t12;
|
|
111
|
+
if ($[21] !== props || $[22] !== t11 || $[23] !== t5 || $[24] !== t8) {
|
|
112
|
+
t12 = /*#__PURE__*/ _jsxs(ButtonGroup, {
|
|
113
|
+
"aria-label": "Alignement",
|
|
114
|
+
...props,
|
|
115
|
+
children: [
|
|
116
|
+
t5,
|
|
117
|
+
t8,
|
|
118
|
+
t11
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
$[21] = props;
|
|
122
|
+
$[22] = t11;
|
|
123
|
+
$[23] = t5;
|
|
124
|
+
$[24] = t8;
|
|
125
|
+
$[25] = t12;
|
|
126
|
+
} else {
|
|
127
|
+
t12 = $[25];
|
|
128
|
+
}
|
|
129
|
+
return t12;
|
|
40
130
|
}
|
|
41
131
|
|
|
42
132
|
//# sourceMappingURL=AlignSelector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AlignSelector/AlignSelector.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 { ButtonGroupProps } from '@mui/material';\nimport { Button, ButtonGroup } from '@mui/material';\nimport type { ReactElement } from 'react';\n\nexport type AlignOption = 'left' | 'center' | 'right';\n\nexport interface AlignSelectorProps extends Omit<ButtonGroupProps, 'onChange'> {\n onChange: (align: AlignOption) => void;\n value?: AlignOption;\n}\n\nexport function AlignSelector({ onChange, value = 'left', ...props }: AlignSelectorProps): ReactElement {\n const handleSortChange = (option: AlignOption): void => {\n onChange(option);\n };\n\n return (\n <ButtonGroup aria-label=\"Alignement\" {...props}>\n <Button key=\"left\" onClick={() => handleSortChange('left')} variant={value === 'left' ? 'contained' : 'outlined'}>\n Left\n </Button>\n <Button\n key=\"center\"\n onClick={() => handleSortChange('center')}\n variant={value === 'center' ? 'contained' : 'outlined'}\n >\n Center\n </Button>\n <Button\n key=\"right\"\n onClick={() => handleSortChange('right')}\n variant={value === 'right' ? 'contained' : 'outlined'}\n >\n Right\n </Button>\n </ButtonGroup>\n );\n}\n"],"names":["Button","ButtonGroup"
|
|
1
|
+
{"version":3,"sources":["../../src/AlignSelector/AlignSelector.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 { ButtonGroupProps } from '@mui/material';\nimport { Button, ButtonGroup } from '@mui/material';\nimport type { ReactElement } from 'react';\n\nexport type AlignOption = 'left' | 'center' | 'right';\n\nexport interface AlignSelectorProps extends Omit<ButtonGroupProps, 'onChange'> {\n onChange: (align: AlignOption) => void;\n value?: AlignOption;\n}\n\nexport function AlignSelector({ onChange, value = 'left', ...props }: AlignSelectorProps): ReactElement {\n const handleSortChange = (option: AlignOption): void => {\n onChange(option);\n };\n\n return (\n <ButtonGroup aria-label=\"Alignement\" {...props}>\n <Button key=\"left\" onClick={() => handleSortChange('left')} variant={value === 'left' ? 'contained' : 'outlined'}>\n Left\n </Button>\n <Button\n key=\"center\"\n onClick={() => handleSortChange('center')}\n variant={value === 'center' ? 'contained' : 'outlined'}\n >\n Center\n </Button>\n <Button\n key=\"right\"\n onClick={() => handleSortChange('right')}\n variant={value === 'right' ? 'contained' : 'outlined'}\n >\n Right\n </Button>\n </ButtonGroup>\n );\n}\n"],"names":["Button","ButtonGroup"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,wEAAwE;AACxE,qEAAqE;AACrE,6EAA6E;AAC7E,sEAAsE;AACtE,iCAAiC;;;AAGjC,SAASA,MAAM,EAAEC,WAAW,QAAQ,gBAAgB;AAUpD,OAAO"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Extension, ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export type CodeEditorProps<T> = Omit<ReactCodeMirrorProps, 'onBlur' | 'theme' | 'extensions' | 'onChange' | 'value'> & {
|
|
4
|
+
value: T;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
onChange?: (next: string) => void;
|
|
7
|
+
};
|
|
8
|
+
type InternalCodeEditorProps<T> = CodeEditorProps<T> & {
|
|
9
|
+
/** Language specific CodeMirror extensions. Must be stable across renders. */
|
|
10
|
+
extensions: Extension[];
|
|
11
|
+
/** Convert the initial value into the text displayed by the editor. */
|
|
12
|
+
serialize: (value: T) => string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Internal base for the language specific editors (JSONEditor, YAMLEditor). Not exported from the package.
|
|
16
|
+
*/
|
|
17
|
+
export declare function CodeEditor<T>(props: InternalCodeEditorProps<T>): ReactElement;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=CodeEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../src/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,IAAI,CACnC,oBAAoB,EACpB,QAAQ,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,CACzD,GAAG;IACF,KAAK,EAAE,CAAC,CAAC;IACT,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,CAAC;AAEF,KAAK,uBAAuB,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG;IACrD,8EAA8E;IAC9E,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,uEAAuE;IACvE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,YAAY,CAkC7E"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { c as _c } from "react-compiler-runtime";
|
|
3
|
+
// Copyright The Perses Authors
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
import { useTheme } from "@mui/material";
|
|
16
|
+
import CodeMirror from "@uiw/react-codemirror";
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
/**
|
|
19
|
+
* Internal base for the language specific editors (JSONEditor, YAMLEditor). Not exported from the package.
|
|
20
|
+
*/ export function CodeEditor(props) {
|
|
21
|
+
const $ = _c(26);
|
|
22
|
+
let extensions;
|
|
23
|
+
let initialValue;
|
|
24
|
+
let onChange;
|
|
25
|
+
let rest;
|
|
26
|
+
let serialize;
|
|
27
|
+
if ($[0] !== props) {
|
|
28
|
+
({ value: initialValue, serialize, extensions, onChange, ...rest } = props);
|
|
29
|
+
$[0] = props;
|
|
30
|
+
$[1] = extensions;
|
|
31
|
+
$[2] = initialValue;
|
|
32
|
+
$[3] = onChange;
|
|
33
|
+
$[4] = rest;
|
|
34
|
+
$[5] = serialize;
|
|
35
|
+
} else {
|
|
36
|
+
extensions = $[1];
|
|
37
|
+
initialValue = $[2];
|
|
38
|
+
onChange = $[3];
|
|
39
|
+
rest = $[4];
|
|
40
|
+
serialize = $[5];
|
|
41
|
+
}
|
|
42
|
+
const theme = useTheme();
|
|
43
|
+
const isDarkMode = theme.palette.mode === "dark";
|
|
44
|
+
let t0;
|
|
45
|
+
if ($[6] !== initialValue || $[7] !== serialize) {
|
|
46
|
+
t0 = ()=>serialize(initialValue);
|
|
47
|
+
$[6] = initialValue;
|
|
48
|
+
$[7] = serialize;
|
|
49
|
+
$[8] = t0;
|
|
50
|
+
} else {
|
|
51
|
+
t0 = $[8];
|
|
52
|
+
}
|
|
53
|
+
const [value, setValue] = useState(t0);
|
|
54
|
+
const [lastProcessedValue, setLastProcessedValue] = useState(value);
|
|
55
|
+
const t1 = `1px solid ${theme.palette.divider}`;
|
|
56
|
+
let t2;
|
|
57
|
+
if ($[9] !== t1) {
|
|
58
|
+
t2 = {
|
|
59
|
+
border: t1
|
|
60
|
+
};
|
|
61
|
+
$[9] = t1;
|
|
62
|
+
$[10] = t2;
|
|
63
|
+
} else {
|
|
64
|
+
t2 = $[10];
|
|
65
|
+
}
|
|
66
|
+
const t3 = isDarkMode ? "dark" : "light";
|
|
67
|
+
let t4;
|
|
68
|
+
if ($[11] !== onChange) {
|
|
69
|
+
t4 = (newValue)=>{
|
|
70
|
+
setValue(newValue);
|
|
71
|
+
if (onChange) {
|
|
72
|
+
onChange(newValue);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
$[11] = onChange;
|
|
76
|
+
$[12] = t4;
|
|
77
|
+
} else {
|
|
78
|
+
t4 = $[12];
|
|
79
|
+
}
|
|
80
|
+
let t5;
|
|
81
|
+
if ($[13] !== lastProcessedValue || $[14] !== onChange || $[15] !== value) {
|
|
82
|
+
t5 = ()=>{
|
|
83
|
+
if (lastProcessedValue !== value && onChange !== undefined) {
|
|
84
|
+
onChange(value);
|
|
85
|
+
setLastProcessedValue(value);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
$[13] = lastProcessedValue;
|
|
89
|
+
$[14] = onChange;
|
|
90
|
+
$[15] = value;
|
|
91
|
+
$[16] = t5;
|
|
92
|
+
} else {
|
|
93
|
+
t5 = $[16];
|
|
94
|
+
}
|
|
95
|
+
let t6;
|
|
96
|
+
if ($[17] !== extensions || $[18] !== props.placeholder || $[19] !== rest || $[20] !== t2 || $[21] !== t3 || $[22] !== t4 || $[23] !== t5 || $[24] !== value) {
|
|
97
|
+
t6 = /*#__PURE__*/ _jsx(CodeMirror, {
|
|
98
|
+
...rest,
|
|
99
|
+
style: t2,
|
|
100
|
+
theme: t3,
|
|
101
|
+
extensions: extensions,
|
|
102
|
+
value: value,
|
|
103
|
+
onChange: t4,
|
|
104
|
+
onBlur: t5,
|
|
105
|
+
placeholder: props.placeholder
|
|
106
|
+
});
|
|
107
|
+
$[17] = extensions;
|
|
108
|
+
$[18] = props.placeholder;
|
|
109
|
+
$[19] = rest;
|
|
110
|
+
$[20] = t2;
|
|
111
|
+
$[21] = t3;
|
|
112
|
+
$[22] = t4;
|
|
113
|
+
$[23] = t5;
|
|
114
|
+
$[24] = value;
|
|
115
|
+
$[25] = t6;
|
|
116
|
+
} else {
|
|
117
|
+
t6 = $[25];
|
|
118
|
+
}
|
|
119
|
+
return t6;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=CodeEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/CodeEditor/CodeEditor.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 { useTheme } from '@mui/material';\nimport type { Extension, ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport CodeMirror from '@uiw/react-codemirror';\nimport type { ReactElement } from 'react';\nimport { useState } from 'react';\n\nexport type CodeEditorProps<T> = Omit<\n ReactCodeMirrorProps,\n 'onBlur' | 'theme' | 'extensions' | 'onChange' | 'value'\n> & {\n value: T;\n placeholder?: string;\n onChange?: (next: string) => void;\n};\n\ntype InternalCodeEditorProps<T> = CodeEditorProps<T> & {\n /** Language specific CodeMirror extensions. Must be stable across renders. */\n extensions: Extension[];\n /** Convert the initial value into the text displayed by the editor. */\n serialize: (value: T) => string;\n};\n\n/**\n * Internal base for the language specific editors (JSONEditor, YAMLEditor). Not exported from the package.\n */\nexport function CodeEditor<T>(props: InternalCodeEditorProps<T>): ReactElement {\n const { value: initialValue, serialize, extensions, onChange, ...rest } = props;\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const [value, setValue] = useState(() => serialize(initialValue));\n const [lastProcessedValue, setLastProcessedValue] = useState<string>(value);\n\n return (\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n extensions={extensions}\n value={value}\n onChange={(newValue) => {\n setValue(newValue);\n // Trigger the provided onChange callback in real-time\n if (onChange) {\n onChange(newValue);\n }\n }}\n onBlur={() => {\n // Don't trigger the provided onChange if the last processed value is equal to the current value.\n // This prevents e.g CTRL+F to trigger value refresh downstream, which would cause the embedded\n // find & replace interface to close immediately.\n if (lastProcessedValue !== value && onChange !== undefined) {\n onChange(value);\n setLastProcessedValue(value);\n }\n }}\n placeholder={props.placeholder}\n />\n );\n}\n"],"names":["useTheme","CodeMirror","useState"],"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,QAAQ,QAAQ,gBAAgB;AAEzC,OAAOC,gBAAgB,wBAAwB;AAE/C,SAASC,QAAQ,QAAQ,QAAQ;AAkBjC;;CAEC,GACD,OAAO"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } 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.
|
|
@@ -16,68 +17,159 @@ import CircleIcon from "mdi-material-ui/Circle";
|
|
|
16
17
|
import DeleteIcon from "mdi-material-ui/Delete";
|
|
17
18
|
import { useState } from "react";
|
|
18
19
|
import { HexColorPicker } from "react-colorful";
|
|
19
|
-
export const ColorPicker = (
|
|
20
|
-
|
|
20
|
+
export const ColorPicker = (t0)=>{
|
|
21
|
+
const $ = _c(26);
|
|
22
|
+
const { color, onChange, onClear, palette } = t0;
|
|
21
23
|
const [value, setValue] = useState(color);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
onChange
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
24
|
+
let t1;
|
|
25
|
+
if ($[0] !== onChange) {
|
|
26
|
+
t1 = (color_0)=>{
|
|
27
|
+
setValue(color_0);
|
|
28
|
+
onChange?.(color_0);
|
|
29
|
+
};
|
|
30
|
+
$[0] = onChange;
|
|
31
|
+
$[1] = t1;
|
|
32
|
+
} else {
|
|
33
|
+
t1 = $[1];
|
|
34
|
+
}
|
|
35
|
+
const handleColorChange = t1;
|
|
36
|
+
let t2;
|
|
37
|
+
if ($[2] !== onChange) {
|
|
38
|
+
t2 = (e)=>{
|
|
39
|
+
const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, "").substring(0, 8);
|
|
40
|
+
setValue(`#${inputValue}`);
|
|
41
|
+
if (isValidHex(e.target.value)) {
|
|
42
|
+
onChange?.(e.target.value);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
$[2] = onChange;
|
|
46
|
+
$[3] = t2;
|
|
47
|
+
} else {
|
|
48
|
+
t2 = $[3];
|
|
49
|
+
}
|
|
50
|
+
const handleInputChange = t2;
|
|
51
|
+
let t3;
|
|
52
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
53
|
+
t3 = {
|
|
54
|
+
width: "100%"
|
|
55
|
+
};
|
|
56
|
+
$[4] = t3;
|
|
57
|
+
} else {
|
|
58
|
+
t3 = $[4];
|
|
59
|
+
}
|
|
60
|
+
let t4;
|
|
61
|
+
if ($[5] !== color || $[6] !== handleColorChange) {
|
|
62
|
+
t4 = /*#__PURE__*/ _jsx(HexColorPicker, {
|
|
63
|
+
color: color,
|
|
64
|
+
onChange: handleColorChange,
|
|
65
|
+
style: t3
|
|
66
|
+
});
|
|
67
|
+
$[5] = color;
|
|
68
|
+
$[6] = handleColorChange;
|
|
69
|
+
$[7] = t4;
|
|
70
|
+
} else {
|
|
71
|
+
t4 = $[7];
|
|
72
|
+
}
|
|
73
|
+
let t5;
|
|
74
|
+
if ($[8] !== handleColorChange || $[9] !== palette) {
|
|
75
|
+
t5 = palette && palette.map((color_1, i)=>/*#__PURE__*/ _jsx(IconButton, {
|
|
76
|
+
size: "small",
|
|
77
|
+
"aria-label": `change color to ${color_1}`,
|
|
78
|
+
sx: {
|
|
79
|
+
color: color_1
|
|
80
|
+
},
|
|
81
|
+
onClick: ()=>handleColorChange(color_1),
|
|
82
|
+
children: /*#__PURE__*/ _jsx(CircleIcon, {})
|
|
83
|
+
}, i));
|
|
84
|
+
$[8] = handleColorChange;
|
|
85
|
+
$[9] = palette;
|
|
86
|
+
$[10] = t5;
|
|
87
|
+
} else {
|
|
88
|
+
t5 = $[10];
|
|
89
|
+
}
|
|
90
|
+
let t6;
|
|
91
|
+
if ($[11] !== t5) {
|
|
92
|
+
t6 = /*#__PURE__*/ _jsx(Stack, {
|
|
93
|
+
direction: "row",
|
|
94
|
+
flexWrap: "wrap",
|
|
95
|
+
justifyContent: "space-evenly",
|
|
96
|
+
width: "200px",
|
|
97
|
+
children: t5
|
|
98
|
+
});
|
|
99
|
+
$[11] = t5;
|
|
100
|
+
$[12] = t6;
|
|
101
|
+
} else {
|
|
102
|
+
t6 = $[12];
|
|
103
|
+
}
|
|
104
|
+
let t7;
|
|
105
|
+
if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
|
|
106
|
+
t7 = {
|
|
107
|
+
"aria-label": "enter hex color"
|
|
108
|
+
};
|
|
109
|
+
$[13] = t7;
|
|
110
|
+
} else {
|
|
111
|
+
t7 = $[13];
|
|
112
|
+
}
|
|
113
|
+
let t8;
|
|
114
|
+
if ($[14] !== handleInputChange || $[15] !== value) {
|
|
115
|
+
t8 = /*#__PURE__*/ _jsx(TextField, {
|
|
116
|
+
inputProps: t7,
|
|
117
|
+
fullWidth: true,
|
|
118
|
+
value: value,
|
|
119
|
+
onChange: handleInputChange
|
|
120
|
+
});
|
|
121
|
+
$[14] = handleInputChange;
|
|
122
|
+
$[15] = value;
|
|
123
|
+
$[16] = t8;
|
|
124
|
+
} else {
|
|
125
|
+
t8 = $[16];
|
|
126
|
+
}
|
|
127
|
+
let t9;
|
|
128
|
+
if ($[17] !== onClear) {
|
|
129
|
+
t9 = onClear && /*#__PURE__*/ _jsx(IconButton, {
|
|
130
|
+
onClick: onClear,
|
|
131
|
+
children: /*#__PURE__*/ _jsx(DeleteIcon, {})
|
|
132
|
+
});
|
|
133
|
+
$[17] = onClear;
|
|
134
|
+
$[18] = t9;
|
|
135
|
+
} else {
|
|
136
|
+
t9 = $[18];
|
|
137
|
+
}
|
|
138
|
+
let t10;
|
|
139
|
+
if ($[19] !== t8 || $[20] !== t9) {
|
|
140
|
+
t10 = /*#__PURE__*/ _jsxs(Stack, {
|
|
141
|
+
direction: "row",
|
|
142
|
+
gap: 1,
|
|
143
|
+
alignItems: "center",
|
|
144
|
+
children: [
|
|
145
|
+
t8,
|
|
146
|
+
t9
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
$[19] = t8;
|
|
150
|
+
$[20] = t9;
|
|
151
|
+
$[21] = t10;
|
|
152
|
+
} else {
|
|
153
|
+
t10 = $[21];
|
|
154
|
+
}
|
|
155
|
+
let t11;
|
|
156
|
+
if ($[22] !== t10 || $[23] !== t4 || $[24] !== t6) {
|
|
157
|
+
t11 = /*#__PURE__*/ _jsxs(Stack, {
|
|
158
|
+
spacing: 1,
|
|
159
|
+
children: [
|
|
160
|
+
t4,
|
|
161
|
+
t6,
|
|
162
|
+
t10
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
$[22] = t10;
|
|
166
|
+
$[23] = t4;
|
|
167
|
+
$[24] = t6;
|
|
168
|
+
$[25] = t11;
|
|
169
|
+
} else {
|
|
170
|
+
t11 = $[25];
|
|
171
|
+
}
|
|
172
|
+
return t11;
|
|
81
173
|
};
|
|
82
174
|
const isValidHex = (value, alpha)=>{
|
|
83
175
|
const matcher = /^#?([0-9A-F]{3,8})$/i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ColorPicker/ColorPicker.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 { IconButton, Stack, TextField } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport DeleteIcon from 'mdi-material-ui/Delete';\nimport type { ChangeEvent, ReactElement } from 'react';\nimport { useState } from 'react';\nimport { HexColorPicker } from 'react-colorful';\n\ninterface ColorPickerProps {\n color: string;\n onChange?: (color: string) => void;\n onClear?: () => void;\n /**\n * Preset color palette\n */\n palette?: string[];\n}\n\nexport const ColorPicker = ({ color, onChange, onClear, palette }: ColorPickerProps): ReactElement => {\n // value is the visible value for the controlled text input\n const [value, setValue] = useState(color);\n\n const handleColorChange = (color: string): void => {\n setValue(color);\n onChange?.(color);\n };\n\n // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>): void => {\n const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);\n setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format\n // only set color if input value is a valid hex color\n if (isValidHex(e.target.value)) {\n onChange?.(e.target.value);\n }\n };\n\n return (\n <Stack spacing={1}>\n <HexColorPicker color={color} onChange={handleColorChange} style={{ width: '100%' }} />\n <Stack direction=\"row\" flexWrap=\"wrap\" justifyContent=\"space-evenly\" width=\"200px\">\n {palette &&\n palette.map((color, i) => (\n <IconButton\n key={i}\n size=\"small\"\n aria-label={`change color to ${color}`}\n sx={{ color }}\n onClick={() => handleColorChange(color)}\n >\n <CircleIcon />\n </IconButton>\n ))}\n </Stack>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <TextField\n inputProps={{ 'aria-label': 'enter hex color' }}\n fullWidth\n value={value}\n onChange={handleInputChange}\n />\n {onClear && (\n <IconButton onClick={onClear}>\n <DeleteIcon />\n </IconButton>\n )}\n </Stack>\n </Stack>\n );\n};\n\nconst isValidHex = (value: string, alpha?: boolean): boolean => {\n const matcher = /^#?([0-9A-F]{3,8})$/i;\n const match = matcher.exec(value);\n const length = match && match[1] ? match[1].length : 0;\n return (\n length === 3 || // '#rgb' format\n length === 6 || // '#rrggbb' format\n (!!alpha && length === 4) || // '#rgba' format\n (!!alpha && length === 8) // '#rrggbbaa' format\n );\n};\n"],"names":["IconButton","Stack","TextField","CircleIcon","DeleteIcon","useState","HexColorPicker","ColorPicker","
|
|
1
|
+
{"version":3,"sources":["../../src/ColorPicker/ColorPicker.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 { IconButton, Stack, TextField } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport DeleteIcon from 'mdi-material-ui/Delete';\nimport type { ChangeEvent, ReactElement } from 'react';\nimport { useState } from 'react';\nimport { HexColorPicker } from 'react-colorful';\n\ninterface ColorPickerProps {\n color: string;\n onChange?: (color: string) => void;\n onClear?: () => void;\n /**\n * Preset color palette\n */\n palette?: string[];\n}\n\nexport const ColorPicker = ({ color, onChange, onClear, palette }: ColorPickerProps): ReactElement => {\n // value is the visible value for the controlled text input\n const [value, setValue] = useState(color);\n\n const handleColorChange = (color: string): void => {\n setValue(color);\n onChange?.(color);\n };\n\n // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>): void => {\n const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);\n setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format\n // only set color if input value is a valid hex color\n if (isValidHex(e.target.value)) {\n onChange?.(e.target.value);\n }\n };\n\n return (\n <Stack spacing={1}>\n <HexColorPicker color={color} onChange={handleColorChange} style={{ width: '100%' }} />\n <Stack direction=\"row\" flexWrap=\"wrap\" justifyContent=\"space-evenly\" width=\"200px\">\n {palette &&\n palette.map((color, i) => (\n <IconButton\n key={i}\n size=\"small\"\n aria-label={`change color to ${color}`}\n sx={{ color }}\n onClick={() => handleColorChange(color)}\n >\n <CircleIcon />\n </IconButton>\n ))}\n </Stack>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <TextField\n inputProps={{ 'aria-label': 'enter hex color' }}\n fullWidth\n value={value}\n onChange={handleInputChange}\n />\n {onClear && (\n <IconButton onClick={onClear}>\n <DeleteIcon />\n </IconButton>\n )}\n </Stack>\n </Stack>\n );\n};\n\nconst isValidHex = (value: string, alpha?: boolean): boolean => {\n const matcher = /^#?([0-9A-F]{3,8})$/i;\n const match = matcher.exec(value);\n const length = match && match[1] ? match[1].length : 0;\n return (\n length === 3 || // '#rgb' format\n length === 6 || // '#rrggbb' format\n (!!alpha && length === 4) || // '#rgba' format\n (!!alpha && length === 8) // '#rrggbbaa' format\n );\n};\n"],"names":["IconButton","Stack","TextField","CircleIcon","DeleteIcon","useState","HexColorPicker","ColorPicker","isValidHex","value","alpha","matcher","match","exec","length"],"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,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC7D,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,gBAAgB,yBAAyB;AAEhD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,cAAc,QAAQ,iBAAiB;AAYhD,OAAO,MAAMC,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDzB;AAEF,MAAMC,aAAa,CAACC,OAAeC;IACjC,MAAMC,UAAU;IAChB,MAAMC,QAAQD,QAAQE,IAAI,CAACJ;IAC3B,MAAMK,SAASF,SAASA,KAAM,CAAA,EAAC,AAAC,GAAGA,KAAM,CAAA,EAAC,AAAC,CAACE,MAAM,GAAG;IACrD,OACEA,WAAW,KAAK,gBAAgB;IAChCA,WAAW,KAAK,mBAAmB;IAClC,CAAC,CAACJ,SAASI,WAAW,KAAM,iBAAiB;IAC7C,CAAC,CAACJ,SAASI,WAAW,EAAG,qBAAqB;;AAEnD"}
|