@perses-dev/components 0.33.0 → 0.35.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/ContentWithLegend/ContentWithLegend.js +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +3 -3
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +12 -3
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/Drawer/Drawer.js +1 -1
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/EChart/EChart.d.ts +2 -1
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +15 -3
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +6 -3
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +1 -1
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +1 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +8 -3
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +4 -3
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +1 -1
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +1 -1
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +1 -1
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts +3 -2
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +10 -2
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/Legend/index.d.ts +1 -0
- package/dist/Legend/index.d.ts.map +1 -1
- package/dist/Legend/index.js +1 -0
- package/dist/Legend/index.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +24 -0
- package/dist/Legend/legend-model.d.ts.map +1 -0
- package/dist/Legend/legend-model.js +19 -0
- package/dist/Legend/legend-model.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +2 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +3 -2
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.js +1 -1
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
- package/dist/SettingsAutocomplete/index.d.ts +2 -0
- package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
- package/dist/{LegendOptionsEditor → SettingsAutocomplete}/index.js +1 -1
- package/dist/SettingsAutocomplete/index.js.map +1 -0
- package/dist/StatChart/StatChart.d.ts +2 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +74 -21
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/StatChart/calculateFontSize.d.ts +14 -0
- package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
- package/dist/StatChart/calculateFontSize.js +47 -0
- package/dist/StatChart/calculateFontSize.js.map +1 -0
- package/dist/Table/Table.js +1 -1
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableCell.d.ts +6 -3
- package/dist/Table/TableCell.d.ts.map +1 -1
- package/dist/Table/TableCell.js +5 -2
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +11 -5
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +16 -2
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +18 -7
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +4 -2
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +10 -22
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/YAxisLabel.js +1 -1
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +1 -1
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +13 -4
- package/dist/cjs/Drawer/Drawer.js +1 -1
- package/dist/cjs/EChart/EChart.js +22 -5
- package/dist/cjs/GaugeChart/GaugeChart.js +6 -3
- package/dist/cjs/Legend/CompactLegend.js +2 -2
- package/dist/cjs/Legend/Legend.js +5 -4
- package/dist/cjs/Legend/ListLegend.js +2 -2
- package/dist/cjs/Legend/TableLegend.js +10 -2
- package/dist/cjs/Legend/index.js +1 -0
- package/dist/cjs/Legend/legend-model.js +25 -0
- package/dist/cjs/LineChart/LineChart.js +3 -2
- package/dist/cjs/LineChart/utils.js +7 -2
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
- package/dist/cjs/{LegendOptionsEditor → SettingsAutocomplete}/index.js +1 -1
- package/dist/cjs/StatChart/StatChart.js +79 -21
- package/dist/cjs/StatChart/calculateFontSize.js +51 -0
- package/dist/cjs/Table/Table.js +1 -1
- package/dist/cjs/Table/TableCell.js +5 -2
- package/dist/cjs/Table/VirtualizedTable.js +11 -5
- package/dist/cjs/Table/model/table-model.js +18 -7
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +4 -2
- package/dist/cjs/UnitSelector/UnitSelector.js +9 -21
- package/dist/cjs/YAxisLabel.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/model/index.js +0 -1
- package/dist/cjs/utils/theme-gen.js +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +1 -1
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +0 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/theme.d.ts +3 -2
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/utils/theme-gen.js +1 -1
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +4 -4
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +0 -8
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +0 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +0 -109
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +0 -1
- package/dist/LegendOptionsEditor/index.d.ts +0 -2
- package/dist/LegendOptionsEditor/index.d.ts.map +0 -1
- package/dist/LegendOptionsEditor/index.js.map +0 -1
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +0 -115
- package/dist/cjs/model/legend.js +0 -102
- package/dist/model/legend.d.ts +0 -36
- package/dist/model/legend.d.ts.map +0 -1
- package/dist/model/legend.js +0 -81
- package/dist/model/legend.js.map +0 -1
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import { Autocomplete, Switch, TextField } from '@mui/material';
|
|
15
|
-
import { ErrorAlert } from '../ErrorAlert';
|
|
16
|
-
import { DEFAULT_LEGEND, getLegendPosition, validateLegendSpec, LEGEND_POSITIONS_CONFIG, LEGEND_MODE_CONFIG, getLegendMode } from '../model';
|
|
17
|
-
import { OptionsEditorControl } from '../OptionsEditorLayout';
|
|
18
|
-
const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
|
|
19
|
-
return {
|
|
20
|
-
id: id,
|
|
21
|
-
...config
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
const MODE_OPTIONS = Object.entries(LEGEND_MODE_CONFIG).map(([id, config])=>{
|
|
25
|
-
return {
|
|
26
|
-
id: id,
|
|
27
|
-
...config
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
export function LegendOptionsEditor({ value , onChange }) {
|
|
31
|
-
const handleLegendShowChange = (_, checked)=>{
|
|
32
|
-
// legend is hidden when legend obj is undefined
|
|
33
|
-
const legendValue = checked === true ? {
|
|
34
|
-
position: DEFAULT_LEGEND.position
|
|
35
|
-
} : undefined;
|
|
36
|
-
onChange(legendValue);
|
|
37
|
-
};
|
|
38
|
-
const handleLegendPositionChange = (_, newValue)=>{
|
|
39
|
-
onChange({
|
|
40
|
-
...value,
|
|
41
|
-
position: newValue.id
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const handleLegendModeChange = (_, newValue)=>{
|
|
45
|
-
onChange({
|
|
46
|
-
...value,
|
|
47
|
-
position: currentPosition,
|
|
48
|
-
mode: newValue.id
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const isValidLegend = validateLegendSpec(value);
|
|
52
|
-
const currentPosition = getLegendPosition(value === null || value === void 0 ? void 0 : value.position);
|
|
53
|
-
const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
54
|
-
const currentMode = getLegendMode(value === null || value === void 0 ? void 0 : value.mode);
|
|
55
|
-
const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];
|
|
56
|
-
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
57
|
-
children: [
|
|
58
|
-
!isValidLegend && /*#__PURE__*/ _jsx(ErrorAlert, {
|
|
59
|
-
error: {
|
|
60
|
-
name: 'invalid-legend',
|
|
61
|
-
message: 'Invalid legend spec'
|
|
62
|
-
}
|
|
63
|
-
}),
|
|
64
|
-
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
65
|
-
label: "Show",
|
|
66
|
-
control: /*#__PURE__*/ _jsx(Switch, {
|
|
67
|
-
checked: value !== undefined,
|
|
68
|
-
onChange: handleLegendShowChange
|
|
69
|
-
})
|
|
70
|
-
}),
|
|
71
|
-
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
72
|
-
label: "Position",
|
|
73
|
-
control: /*#__PURE__*/ _jsx(Autocomplete, {
|
|
74
|
-
value: {
|
|
75
|
-
...legendPositionConfig,
|
|
76
|
-
id: currentPosition
|
|
77
|
-
},
|
|
78
|
-
options: POSITION_OPTIONS,
|
|
79
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
80
|
-
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
81
|
-
...params
|
|
82
|
-
}),
|
|
83
|
-
onChange: handleLegendPositionChange,
|
|
84
|
-
disabled: value === undefined,
|
|
85
|
-
disableClearable: true
|
|
86
|
-
})
|
|
87
|
-
}),
|
|
88
|
-
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
89
|
-
label: "Mode",
|
|
90
|
-
control: /*#__PURE__*/ _jsx(Autocomplete, {
|
|
91
|
-
value: {
|
|
92
|
-
...legendModeConfig,
|
|
93
|
-
id: currentMode
|
|
94
|
-
},
|
|
95
|
-
options: MODE_OPTIONS,
|
|
96
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
97
|
-
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
98
|
-
...params
|
|
99
|
-
}),
|
|
100
|
-
onChange: handleLegendModeChange,
|
|
101
|
-
disabled: value === undefined,
|
|
102
|
-
disableClearable: true
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
]
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
//# sourceMappingURL=LegendOptionsEditor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.tsx"],"sourcesContent":["// Copyright 2023 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 { Autocomplete, Switch, SwitchProps, TextField } from '@mui/material';\nimport { ErrorAlert } from '../ErrorAlert';\nimport {\n DEFAULT_LEGEND,\n getLegendPosition,\n validateLegendSpec,\n LEGEND_POSITIONS_CONFIG,\n LegendOptions,\n LegendSingleSelectConfig,\n LEGEND_MODE_CONFIG,\n getLegendMode,\n} from '../model';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendOptions['position'],\n ...config,\n };\n});\n\ntype LegendModeOption = LegendSingleSelectConfig & { id: LegendOptions['mode'] };\n\nconst MODE_OPTIONS: LegendModeOption[] = Object.entries(LEGEND_MODE_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendOptions['mode'],\n ...config,\n };\n});\n\nexport interface LegendOptionsEditorProps {\n value?: LegendOptions;\n onChange: (legend?: LegendOptions) => void;\n}\n\nexport function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps) {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption) => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendModeChange = (_: unknown, newValue: LegendModeOption) => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue.id,\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];\n\n return (\n <>\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl\n label=\"Show\"\n control={<Switch checked={value !== undefined} onChange={handleLegendShowChange} />}\n />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <Autocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></Autocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <Autocomplete\n value={{\n ...legendModeConfig,\n id: currentMode,\n }}\n options={MODE_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleLegendModeChange}\n disabled={value === undefined}\n disableClearable\n ></Autocomplete>\n }\n />\n </>\n );\n}\n"],"names":["Autocomplete","Switch","TextField","ErrorAlert","DEFAULT_LEGEND","getLegendPosition","validateLegendSpec","LEGEND_POSITIONS_CONFIG","LEGEND_MODE_CONFIG","getLegendMode","OptionsEditorControl","POSITION_OPTIONS","Object","entries","map","id","config","MODE_OPTIONS","LegendOptionsEditor","value","onChange","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendModeChange","currentPosition","mode","isValidLegend","legendPositionConfig","currentMode","legendModeConfig","error","name","message","label","control","options","isOptionEqualToValue","option","renderInput","params","disabled","disableClearable"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,YAAY,EAAEC,MAAM,EAAeC,SAAS,QAAQ,eAAe,CAAC;AAC7E,SAASC,UAAU,QAAQ,eAAe,CAAC;AAC3C,SACEC,cAAc,EACdC,iBAAiB,EACjBC,kBAAkB,EAClBC,uBAAuB,EAGvBC,kBAAkB,EAClBC,aAAa,QACR,UAAU,CAAC;AAClB,SAASC,oBAAoB,QAAQ,wBAAwB,CAAC;AAI9D,MAAMC,gBAAgB,GAA2BC,MAAM,CAACC,OAAO,CAACN,uBAAuB,CAAC,CAACO,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC7G,OAAO;QACLD,EAAE,EAAEA,EA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AK,GAAKwB,MAAM,CAAC5B,EAAE,KAAKI,KAAK,CAACJ,EAAE;oBAC/D6B,WAAW,EAAE,CAACC,MAAM,iBAAK,KAAC3C,SAAS;4BAAE,GAAG2C,MAAM;0BAAI;oBAClDzB,QAAQ,EAAES,sBAAsB;oBAChCiB,QAAQ,EAAE3B,KAAK,KAAKO,SAAS;oBAC7BqB,gBAAgB;kBACF;cAElB;;MACD,CACH;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/LegendOptionsEditor/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LegendOptionsEditor/index.ts"],"sourcesContent":["// Copyright 2023 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\nexport * from './LegendOptionsEditor';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "LegendOptionsEditor", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: ()=>LegendOptionsEditor
|
|
20
|
-
});
|
|
21
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _material = require("@mui/material");
|
|
23
|
-
const _errorAlert = require("../ErrorAlert");
|
|
24
|
-
const _model = require("../model");
|
|
25
|
-
const _optionsEditorLayout = require("../OptionsEditorLayout");
|
|
26
|
-
const POSITION_OPTIONS = Object.entries(_model.LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
|
|
27
|
-
return {
|
|
28
|
-
id: id,
|
|
29
|
-
...config
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config])=>{
|
|
33
|
-
return {
|
|
34
|
-
id: id,
|
|
35
|
-
...config
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
function LegendOptionsEditor({ value , onChange }) {
|
|
39
|
-
const handleLegendShowChange = (_, checked)=>{
|
|
40
|
-
// legend is hidden when legend obj is undefined
|
|
41
|
-
const legendValue = checked === true ? {
|
|
42
|
-
position: _model.DEFAULT_LEGEND.position
|
|
43
|
-
} : undefined;
|
|
44
|
-
onChange(legendValue);
|
|
45
|
-
};
|
|
46
|
-
const handleLegendPositionChange = (_, newValue)=>{
|
|
47
|
-
onChange({
|
|
48
|
-
...value,
|
|
49
|
-
position: newValue.id
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const handleLegendModeChange = (_, newValue)=>{
|
|
53
|
-
onChange({
|
|
54
|
-
...value,
|
|
55
|
-
position: currentPosition,
|
|
56
|
-
mode: newValue.id
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
const isValidLegend = (0, _model.validateLegendSpec)(value);
|
|
60
|
-
const currentPosition = (0, _model.getLegendPosition)(value === null || value === void 0 ? void 0 : value.position);
|
|
61
|
-
const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
62
|
-
const currentMode = (0, _model.getLegendMode)(value === null || value === void 0 ? void 0 : value.mode);
|
|
63
|
-
const legendModeConfig = _model.LEGEND_MODE_CONFIG[currentMode];
|
|
64
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
65
|
-
children: [
|
|
66
|
-
!isValidLegend && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_errorAlert.ErrorAlert, {
|
|
67
|
-
error: {
|
|
68
|
-
name: 'invalid-legend',
|
|
69
|
-
message: 'Invalid legend spec'
|
|
70
|
-
}
|
|
71
|
-
}),
|
|
72
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
73
|
-
label: "Show",
|
|
74
|
-
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
|
|
75
|
-
checked: value !== undefined,
|
|
76
|
-
onChange: handleLegendShowChange
|
|
77
|
-
})
|
|
78
|
-
}),
|
|
79
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
80
|
-
label: "Position",
|
|
81
|
-
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
82
|
-
value: {
|
|
83
|
-
...legendPositionConfig,
|
|
84
|
-
id: currentPosition
|
|
85
|
-
},
|
|
86
|
-
options: POSITION_OPTIONS,
|
|
87
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
88
|
-
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
89
|
-
...params
|
|
90
|
-
}),
|
|
91
|
-
onChange: handleLegendPositionChange,
|
|
92
|
-
disabled: value === undefined,
|
|
93
|
-
disableClearable: true
|
|
94
|
-
})
|
|
95
|
-
}),
|
|
96
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
97
|
-
label: "Mode",
|
|
98
|
-
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
99
|
-
value: {
|
|
100
|
-
...legendModeConfig,
|
|
101
|
-
id: currentMode
|
|
102
|
-
},
|
|
103
|
-
options: MODE_OPTIONS,
|
|
104
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
105
|
-
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
106
|
-
...params
|
|
107
|
-
}),
|
|
108
|
-
onChange: handleLegendModeChange,
|
|
109
|
-
disabled: value === undefined,
|
|
110
|
-
disableClearable: true
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
}
|
package/dist/cjs/model/legend.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
function _export(target, all) {
|
|
18
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: all[name]
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
_export(exports, {
|
|
24
|
-
legendPositions: ()=>legendPositions,
|
|
25
|
-
legendModes: ()=>legendModes,
|
|
26
|
-
LEGEND_POSITIONS_CONFIG: ()=>LEGEND_POSITIONS_CONFIG,
|
|
27
|
-
LEGEND_MODE_CONFIG: ()=>LEGEND_MODE_CONFIG,
|
|
28
|
-
DEFAULT_LEGEND: ()=>DEFAULT_LEGEND,
|
|
29
|
-
getLegendPosition: ()=>getLegendPosition,
|
|
30
|
-
isValidLegendPosition: ()=>isValidLegendPosition,
|
|
31
|
-
isValidLegendMode: ()=>isValidLegendMode,
|
|
32
|
-
getLegendMode: ()=>getLegendMode,
|
|
33
|
-
validateLegendSpec: ()=>validateLegendSpec,
|
|
34
|
-
isLegendItemVisuallySelected: ()=>isLegendItemVisuallySelected
|
|
35
|
-
});
|
|
36
|
-
const legendPositions = [
|
|
37
|
-
'Bottom',
|
|
38
|
-
'Right'
|
|
39
|
-
];
|
|
40
|
-
const legendModes = [
|
|
41
|
-
'List',
|
|
42
|
-
'Table'
|
|
43
|
-
];
|
|
44
|
-
const LEGEND_POSITIONS_CONFIG = {
|
|
45
|
-
Bottom: {
|
|
46
|
-
label: 'Bottom'
|
|
47
|
-
},
|
|
48
|
-
Right: {
|
|
49
|
-
label: 'Right'
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const LEGEND_MODE_CONFIG = {
|
|
53
|
-
List: {
|
|
54
|
-
label: 'List'
|
|
55
|
-
},
|
|
56
|
-
Table: {
|
|
57
|
-
label: 'Table'
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const DEFAULT_LEGEND = {
|
|
61
|
-
position: 'Bottom',
|
|
62
|
-
mode: 'List'
|
|
63
|
-
};
|
|
64
|
-
function getLegendPosition(position) {
|
|
65
|
-
if (position === undefined) {
|
|
66
|
-
return DEFAULT_LEGEND.position;
|
|
67
|
-
}
|
|
68
|
-
if (isValidLegendPosition(position)) {
|
|
69
|
-
return position;
|
|
70
|
-
}
|
|
71
|
-
return DEFAULT_LEGEND.position;
|
|
72
|
-
}
|
|
73
|
-
function isValidLegendPosition(position) {
|
|
74
|
-
return legendPositions.includes(position);
|
|
75
|
-
}
|
|
76
|
-
function isValidLegendMode(mode) {
|
|
77
|
-
return legendModes.includes(mode);
|
|
78
|
-
}
|
|
79
|
-
function getLegendMode(mode) {
|
|
80
|
-
if (!mode || !isValidLegendMode(mode)) {
|
|
81
|
-
return DEFAULT_LEGEND.mode;
|
|
82
|
-
}
|
|
83
|
-
return mode;
|
|
84
|
-
}
|
|
85
|
-
function validateLegendSpec(legend) {
|
|
86
|
-
if (legend === undefined) {
|
|
87
|
-
// undefined is valid since this is how legend is hidden by default
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
if (!isValidLegendPosition(legend.position)) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if (legend.mode && !isValidLegendMode(legend.mode)) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
function isLegendItemVisuallySelected(item, selectedItems) {
|
|
99
|
-
// In the "ALL" case, technically all legend items are selected, but we do
|
|
100
|
-
// not render them differently.
|
|
101
|
-
return selectedItems !== 'ALL' && !!selectedItems[item.id];
|
|
102
|
-
}
|
package/dist/model/legend.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { MouseEventHandler } from 'react';
|
|
2
|
-
export declare const legendPositions: readonly ["Bottom", "Right"];
|
|
3
|
-
export declare type LegendPositions = (typeof legendPositions)[number];
|
|
4
|
-
export declare const legendModes: readonly ["List", "Table"];
|
|
5
|
-
export declare type LegendMode = (typeof legendModes)[number];
|
|
6
|
-
export interface LegendOptions {
|
|
7
|
-
position: LegendPositions;
|
|
8
|
-
mode?: LegendMode;
|
|
9
|
-
}
|
|
10
|
-
export interface LegendItem {
|
|
11
|
-
id: string;
|
|
12
|
-
label: string;
|
|
13
|
-
color: string;
|
|
14
|
-
onClick?: MouseEventHandler<HTMLElement>;
|
|
15
|
-
}
|
|
16
|
-
export declare type LegendSingleSelectConfig = {
|
|
17
|
-
label: string;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* State of selected items in the legend.
|
|
21
|
-
* - When "ALL", all legend items are selected, but not visually highlighted.
|
|
22
|
-
* - Otherwise, it is a Record that associates legend item ids with a boolean
|
|
23
|
-
* value. When the associated entry for a legend item is `true`, that item
|
|
24
|
-
* will be treated as selected and visually highlighted.
|
|
25
|
-
*/
|
|
26
|
-
export declare type SelectedLegendItemState = Record<LegendItem['id'], boolean> | 'ALL';
|
|
27
|
-
export declare const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>>;
|
|
28
|
-
export declare const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>>;
|
|
29
|
-
export declare const DEFAULT_LEGEND: Required<LegendOptions>;
|
|
30
|
-
export declare function getLegendPosition(position?: LegendPositions): "Bottom" | "Right";
|
|
31
|
-
export declare function isValidLegendPosition(position: LegendPositions): boolean;
|
|
32
|
-
export declare function isValidLegendMode(mode: LegendMode): boolean;
|
|
33
|
-
export declare function getLegendMode(mode?: LegendMode): "List" | "Table";
|
|
34
|
-
export declare function validateLegendSpec(legend?: LegendOptions): boolean;
|
|
35
|
-
export declare function isLegendItemVisuallySelected(item: LegendItem, selectedItems: SelectedLegendItemState): boolean;
|
|
36
|
-
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":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;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,aAAa,WAaxD;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,uBAAuB,WAIpG"}
|
package/dist/model/legend.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
export const legendPositions = [
|
|
14
|
-
'Bottom',
|
|
15
|
-
'Right'
|
|
16
|
-
];
|
|
17
|
-
export const legendModes = [
|
|
18
|
-
'List',
|
|
19
|
-
'Table'
|
|
20
|
-
];
|
|
21
|
-
export const LEGEND_POSITIONS_CONFIG = {
|
|
22
|
-
Bottom: {
|
|
23
|
-
label: 'Bottom'
|
|
24
|
-
},
|
|
25
|
-
Right: {
|
|
26
|
-
label: 'Right'
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export const LEGEND_MODE_CONFIG = {
|
|
30
|
-
List: {
|
|
31
|
-
label: 'List'
|
|
32
|
-
},
|
|
33
|
-
Table: {
|
|
34
|
-
label: 'Table'
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
export const DEFAULT_LEGEND = {
|
|
38
|
-
position: 'Bottom',
|
|
39
|
-
mode: 'List'
|
|
40
|
-
};
|
|
41
|
-
export function getLegendPosition(position) {
|
|
42
|
-
if (position === undefined) {
|
|
43
|
-
return DEFAULT_LEGEND.position;
|
|
44
|
-
}
|
|
45
|
-
if (isValidLegendPosition(position)) {
|
|
46
|
-
return position;
|
|
47
|
-
}
|
|
48
|
-
return DEFAULT_LEGEND.position;
|
|
49
|
-
}
|
|
50
|
-
export function isValidLegendPosition(position) {
|
|
51
|
-
return legendPositions.includes(position);
|
|
52
|
-
}
|
|
53
|
-
export function isValidLegendMode(mode) {
|
|
54
|
-
return legendModes.includes(mode);
|
|
55
|
-
}
|
|
56
|
-
export function getLegendMode(mode) {
|
|
57
|
-
if (!mode || !isValidLegendMode(mode)) {
|
|
58
|
-
return DEFAULT_LEGEND.mode;
|
|
59
|
-
}
|
|
60
|
-
return mode;
|
|
61
|
-
}
|
|
62
|
-
export function validateLegendSpec(legend) {
|
|
63
|
-
if (legend === undefined) {
|
|
64
|
-
// undefined is valid since this is how legend is hidden by default
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
if (!isValidLegendPosition(legend.position)) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
if (legend.mode && !isValidLegendMode(legend.mode)) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
export function isLegendItemVisuallySelected(item, selectedItems) {
|
|
76
|
-
// In the "ALL" case, technically all legend items are selected, but we do
|
|
77
|
-
// not render them differently.
|
|
78
|
-
return selectedItems !== 'ALL' && !!selectedItems[item.id];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//# sourceMappingURL=legend.js.map
|
package/dist/model/legend.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 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 { MouseEventHandler } from 'react';\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport const legendModes = ['List', 'Table'] as const;\nexport type LegendMode = (typeof legendModes)[number];\n\nexport interface LegendOptions {\n position: LegendPositions;\n mode?: LegendMode;\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n color: string;\n onClick?: MouseEventHandler<HTMLElement>;\n}\n\nexport type LegendSingleSelectConfig = {\n label: string;\n};\n\n/**\n * State of selected items in the legend.\n * - When \"ALL\", all legend items are selected, but not visually highlighted.\n * - Otherwise, it is a Record that associates legend item ids with a boolean\n * value. When the associated entry for a legend item is `true`, that item\n * will be treated as selected and visually highlighted.\n */\nexport type SelectedLegendItemState = Record<LegendItem['id'], boolean> | 'ALL';\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>> = {\n List: { label: 'List' },\n Table: { label: 'Table' },\n};\n\nexport const DEFAULT_LEGEND: Required<LegendOptions> = {\n position: 'Bottom',\n mode: 'List',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function isValidLegendMode(mode: LegendMode) {\n return (legendModes as readonly string[]).includes(mode);\n}\n\nexport function getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n\nexport function validateLegendSpec(legend?: LegendOptions) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n if (legend.mode && !isValidLegendMode(legend.mode)) {\n return false;\n }\n\n return true;\n}\n\nexport function isLegendItemVisuallySelected(item: LegendItem, selectedItems: SelectedLegendItemState) {\n // In the \"ALL\" case, technically all legend items are selected, but we do\n // not render them differently.\n return selectedItems !== 'ALL' && !!selectedItems[item.id];\n}\n"],"names":["legendPositions","legendModes","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","LEGEND_MODE_CONFIG","List","Table","DEFAULT_LEGEND","position","mode","getLegendPosition","undefined","isValidLegendPosition","includes","isValidLegendMode","getLegendMode","validateLegendSpec","legend","isLegendItemVisuallySelected","item","selectedItems","id"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAG5D,OAAO,MAAMC,WAAW,GAAG;IAAC,MAAM;IAAE,OAAO;CAAC,AAAS,CAAC;AA4BtD,OAAO,MAAMC,uBAAuB,GAAgE;IAClGC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,kBAAkB,GAA2D;IACxFC,IAAI,EAAE;QAAEH,KAAK,EAAE,MAAM;KAAE;IACvBI,KAAK,EAAE;QAAEJ,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAMK,cAAc,GAA4B;IACrDC,QAAQ,EAAE,QAAQ;IAClBC,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,OAAO,SAASC,iBAAiB,CAACF,Q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