@perses-dev/plugin-system 0.37.2 → 0.39.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/cjs/components/OptionsEditorRadios/OptionsEditorRadios.js +74 -0
- package/dist/cjs/components/OptionsEditorRadios/index.js +28 -0
- package/dist/cjs/components/{OptionsEditorTabs/TabPanel.js → OptionsEditorTabPanel/OptionsEditorTabPanel.js} +3 -3
- package/dist/cjs/components/OptionsEditorTabPanel/index.js +28 -0
- package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +2 -2
- package/dist/cjs/components/PluginEditor/PluginEditor.js +4 -2
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +459 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +29 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +102 -0
- package/dist/cjs/components/Variables/index.js +29 -0
- package/dist/cjs/components/Variables/variable-model.js +117 -0
- package/dist/cjs/components/index.js +2 -0
- package/dist/cjs/constants/index.js +28 -0
- package/dist/cjs/constants/user-interface-text.js +25 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +40 -28
- package/dist/cjs/runtime/DataQueriesProvider/model.js +57 -0
- package/dist/cjs/runtime/template-variables.js +62 -0
- package/dist/cjs/test/index.js +1 -0
- package/dist/cjs/test/mock-data.js +55 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +16 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +68 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -0
- package/dist/components/OptionsEditorRadios/index.d.ts +2 -0
- package/dist/components/OptionsEditorRadios/index.d.ts.map +1 -0
- package/dist/components/OptionsEditorRadios/index.js +15 -0
- package/dist/components/OptionsEditorRadios/index.js.map +1 -0
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +9 -0
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -0
- package/dist/components/{OptionsEditorTabs/TabPanel.js → OptionsEditorTabPanel/OptionsEditorTabPanel.js} +2 -2
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -0
- package/dist/components/OptionsEditorTabPanel/index.d.ts +2 -0
- package/dist/components/OptionsEditorTabPanel/index.d.ts.map +1 -0
- package/dist/components/OptionsEditorTabPanel/index.js +15 -0
- package/dist/components/OptionsEditorTabPanel/index.js.map +1 -0
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +2 -2
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +4 -2
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +12 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +414 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts +3 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js +16 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +23 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +90 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
- package/dist/components/Variables/index.d.ts +3 -0
- package/dist/components/Variables/index.d.ts.map +1 -0
- package/dist/components/Variables/index.js +16 -0
- package/dist/components/Variables/index.js.map +1 -0
- package/dist/components/Variables/variable-model.d.ts +17 -0
- package/dist/components/Variables/variable-model.d.ts.map +1 -0
- package/dist/components/Variables/variable-model.js +105 -0
- package/dist/components/Variables/variable-model.js.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -1
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +15 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/user-interface-text.d.ts +5 -0
- package/dist/constants/user-interface-text.d.ts.map +1 -0
- package/dist/constants/user-interface-text.js +19 -0
- package/dist/constants/user-interface-text.js.map +1 -0
- 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/model/plugin-base.d.ts +1 -0
- package/dist/model/plugin-base.d.ts.map +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +5 -5
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +39 -27
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +15 -11
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +47 -1
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/template-variables.d.ts +61 -2
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +63 -0
- package/dist/runtime/template-variables.js.map +1 -1
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +1 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/mock-data.d.ts +3 -0
- package/dist/test/mock-data.d.ts.map +1 -0
- package/dist/test/mock-data.js +49 -0
- package/dist/test/mock-data.js.map +1 -0
- package/package.json +4 -4
- package/dist/components/OptionsEditorTabs/TabPanel.d.ts +0 -9
- package/dist/components/OptionsEditorTabs/TabPanel.d.ts.map +0 -1
- package/dist/components/OptionsEditorTabs/TabPanel.js.map +0 -1
|
@@ -14,3 +14,60 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
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
|
+
transformQueryResults: ()=>transformQueryResults,
|
|
25
|
+
useQueryType: ()=>useQueryType
|
|
26
|
+
});
|
|
27
|
+
const _react = require("react");
|
|
28
|
+
const _pluginRegistry = require("../plugin-registry");
|
|
29
|
+
function transformQueryResults(results, definitions) {
|
|
30
|
+
return results.map(({ data , isFetching , isLoading , refetch , error }, i)=>{
|
|
31
|
+
return {
|
|
32
|
+
definition: definitions[i],
|
|
33
|
+
data,
|
|
34
|
+
isFetching,
|
|
35
|
+
isLoading,
|
|
36
|
+
refetch,
|
|
37
|
+
error
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function useQueryType() {
|
|
42
|
+
const { data: timeSeriesQueryPlugins , isLoading } = (0, _pluginRegistry.useListPluginMetadata)('TimeSeriesQuery');
|
|
43
|
+
const queryTypeMap = (0, _react.useMemo)(()=>{
|
|
44
|
+
const map = {
|
|
45
|
+
TimeSeriesQuery: []
|
|
46
|
+
};
|
|
47
|
+
if (timeSeriesQueryPlugins) {
|
|
48
|
+
timeSeriesQueryPlugins.forEach((plugin)=>{
|
|
49
|
+
var ref;
|
|
50
|
+
(ref = map['TimeSeriesQuery']) === null || ref === void 0 ? void 0 : ref.push(plugin.kind);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return map;
|
|
54
|
+
}, [
|
|
55
|
+
timeSeriesQueryPlugins
|
|
56
|
+
]);
|
|
57
|
+
const getQueryType = (0, _react.useCallback)((pluginKind)=>{
|
|
58
|
+
if (isLoading) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
for(const queryType in queryTypeMap){
|
|
62
|
+
var ref;
|
|
63
|
+
if ((ref = queryTypeMap[queryType]) === null || ref === void 0 ? void 0 : ref.includes(pluginKind)) {
|
|
64
|
+
return queryType;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Unable to determine the query type: ${pluginKind}`);
|
|
68
|
+
}, [
|
|
69
|
+
queryTypeMap,
|
|
70
|
+
isLoading
|
|
71
|
+
]);
|
|
72
|
+
return getQueryType;
|
|
73
|
+
}
|
|
@@ -21,12 +21,74 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
+
VariableStoreStateMap: ()=>VariableStoreStateMap,
|
|
24
25
|
TemplateVariableContext: ()=>TemplateVariableContext,
|
|
25
26
|
useTemplateVariableValues: ()=>useTemplateVariableValues,
|
|
26
27
|
useReplaceVariablesInString: ()=>useReplaceVariablesInString
|
|
27
28
|
});
|
|
28
29
|
const _react = require("react");
|
|
30
|
+
const _immer = require("immer");
|
|
29
31
|
const _utils = require("../utils");
|
|
32
|
+
let _immerable = _immer.immerable;
|
|
33
|
+
class VariableStoreStateMap {
|
|
34
|
+
/**
|
|
35
|
+
* Get variable state by key.
|
|
36
|
+
* @param key
|
|
37
|
+
*/ get(key) {
|
|
38
|
+
return this._sourceStatesOrEmpty(key.source)[key.name];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set variable state by key.
|
|
42
|
+
* @param key
|
|
43
|
+
* @param value
|
|
44
|
+
*/ set(key, value) {
|
|
45
|
+
const sourceName = this._sourceName(key.source);
|
|
46
|
+
if (!this._state[sourceName]) {
|
|
47
|
+
this._state[sourceName] = {};
|
|
48
|
+
}
|
|
49
|
+
this._sourceStatesOrEmpty(key.source)[key.name] = value;
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check presence of variable state by key.
|
|
54
|
+
* @param key
|
|
55
|
+
*/ has(key) {
|
|
56
|
+
return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Delete variable state by key.
|
|
60
|
+
* @param key
|
|
61
|
+
*/ delete(key) {
|
|
62
|
+
var ref;
|
|
63
|
+
const result = this.has(key);
|
|
64
|
+
const sourceName = this._sourceName(key.source);
|
|
65
|
+
const sourceStates = this._state[sourceName];
|
|
66
|
+
// Delete var from source state
|
|
67
|
+
if (sourceStates) {
|
|
68
|
+
delete sourceStates[key.name];
|
|
69
|
+
}
|
|
70
|
+
// Delete source state from state if empty
|
|
71
|
+
if (((ref = Object.keys(sourceStates !== null && sourceStates !== void 0 ? sourceStates : {})) === null || ref === void 0 ? void 0 : ref.length) === 0) {
|
|
72
|
+
delete this._state[sourceName];
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
_sourceName(source) {
|
|
77
|
+
return source !== null && source !== void 0 ? source : this.DEFAULT_LOCAL_SOURCE_NAME;
|
|
78
|
+
}
|
|
79
|
+
_sourceStatesOrEmpty(source) {
|
|
80
|
+
var ref;
|
|
81
|
+
return (ref = this._state[this._sourceName(source)]) !== null && ref !== void 0 ? ref : {};
|
|
82
|
+
}
|
|
83
|
+
constructor(){
|
|
84
|
+
/**
|
|
85
|
+
* "Immerable" is mandatory to be able to use this class in an immer context.
|
|
86
|
+
* Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
|
|
87
|
+
*/ this[_immerable] = true;
|
|
88
|
+
this.DEFAULT_LOCAL_SOURCE_NAME = '';
|
|
89
|
+
this._state = {};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
30
92
|
const TemplateVariableContext = (0, _react.createContext)(undefined);
|
|
31
93
|
function useTemplateVariableContext() {
|
|
32
94
|
const ctx = (0, _react.useContext)(TemplateVariableContext);
|
package/dist/cjs/test/index.js
CHANGED
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./render"), exports);
|
|
18
|
+
_exportStar(require("./mock-data"), exports);
|
|
18
19
|
function _exportStar(from, to) {
|
|
19
20
|
Object.keys(from).forEach(function(k) {
|
|
20
21
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -0,0 +1,55 @@
|
|
|
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, "MOCK_TIME_SERIES_DATA", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>MOCK_TIME_SERIES_DATA
|
|
20
|
+
});
|
|
21
|
+
const MOCK_TIME_SERIES_DATA = {
|
|
22
|
+
timeRange: {
|
|
23
|
+
start: new Date(1666625490000),
|
|
24
|
+
end: new Date(1666625535000)
|
|
25
|
+
},
|
|
26
|
+
stepMs: 24379,
|
|
27
|
+
series: [
|
|
28
|
+
{
|
|
29
|
+
name: 'device="/dev/vda1", env="demo", fstype="ext4", instance="demo.do.prometheus.io:9100", job="node", mountpoint="/"',
|
|
30
|
+
values: [
|
|
31
|
+
[
|
|
32
|
+
1666479357903,
|
|
33
|
+
0.27700745551584494
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
1666479382282,
|
|
37
|
+
0.27701284657366565
|
|
38
|
+
]
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'device="/dev/vda15", env="demo", fstype="vfat", instance="demo.do.prometheus.io:9100", job="node", mountpoint="/boot/efi"',
|
|
43
|
+
values: [
|
|
44
|
+
[
|
|
45
|
+
1666479357903,
|
|
46
|
+
0.08486496097624885
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
1666479382282,
|
|
50
|
+
0.08486496097624885
|
|
51
|
+
]
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type OptionsEditorRadio = {
|
|
3
|
+
label: string;
|
|
4
|
+
/**
|
|
5
|
+
* Content rendered when the tab is active.
|
|
6
|
+
*/
|
|
7
|
+
content: React.ReactNode;
|
|
8
|
+
};
|
|
9
|
+
export declare type OptionsEditorRadiosProps = {
|
|
10
|
+
tabs: OptionsEditorRadio[];
|
|
11
|
+
defaultTab: number;
|
|
12
|
+
onModeChange: (value: number) => void;
|
|
13
|
+
isReadonly?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const OptionsEditorRadios: (props: OptionsEditorRadiosProps) => JSX.Element;
|
|
16
|
+
//# sourceMappingURL=OptionsEditorRadios.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionsEditorRadios.d.ts","sourceRoot":"","sources":["../../../src/components/OptionsEditorRadios/OptionsEditorRadios.tsx"],"names":[],"mappings":";AAiBA,oBAAY,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;CAC1B,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC,IAAI,EAAE,kBAAkB,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,wBAAwB,gBAuClE,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { FormControl, FormControlLabel, Radio, RadioGroup, Box, Typography } from '@mui/material';
|
|
15
|
+
import { useState } from 'react';
|
|
16
|
+
import { OptionsEditorTabPanel } from '../OptionsEditorTabPanel';
|
|
17
|
+
export const OptionsEditorRadios = (props)=>{
|
|
18
|
+
const { tabs , defaultTab , onModeChange , isReadonly } = props;
|
|
19
|
+
const [activeTab, setActiveTab] = useState(defaultTab);
|
|
20
|
+
const handleChange = (_, value)=>{
|
|
21
|
+
const v = parseInt(value);
|
|
22
|
+
setActiveTab(v);
|
|
23
|
+
onModeChange(v);
|
|
24
|
+
};
|
|
25
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
26
|
+
children: [
|
|
27
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
28
|
+
sx: {
|
|
29
|
+
borderBottom: 1,
|
|
30
|
+
borderColor: (theme)=>theme.palette.divider
|
|
31
|
+
},
|
|
32
|
+
children: /*#__PURE__*/ _jsxs(FormControl, {
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
35
|
+
variant: "overline",
|
|
36
|
+
component: "h4",
|
|
37
|
+
children: "Mode:"
|
|
38
|
+
}),
|
|
39
|
+
/*#__PURE__*/ _jsx(RadioGroup, {
|
|
40
|
+
row: true,
|
|
41
|
+
defaultValue: defaultTab,
|
|
42
|
+
value: activeTab,
|
|
43
|
+
onChange: handleChange,
|
|
44
|
+
"aria-labelledby": "Configuration radio",
|
|
45
|
+
children: tabs.map(({ label }, i)=>{
|
|
46
|
+
return /*#__PURE__*/ _jsx(FormControlLabel, {
|
|
47
|
+
disabled: isReadonly,
|
|
48
|
+
value: i,
|
|
49
|
+
control: /*#__PURE__*/ _jsx(Radio, {}),
|
|
50
|
+
label: label
|
|
51
|
+
}, label);
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
})
|
|
56
|
+
}),
|
|
57
|
+
tabs.map(({ label , content }, i)=>{
|
|
58
|
+
return /*#__PURE__*/ _jsx(OptionsEditorTabPanel, {
|
|
59
|
+
value: activeTab,
|
|
60
|
+
index: i,
|
|
61
|
+
children: content
|
|
62
|
+
}, label);
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=OptionsEditorRadios.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/OptionsEditorRadios/OptionsEditorRadios.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 { FormControl, FormControlLabel, Radio, RadioGroup, RadioGroupProps, Box, Typography } from '@mui/material';\nimport { useState } from 'react';\nimport { OptionsEditorTabPanel } from '../OptionsEditorTabPanel';\n\nexport type OptionsEditorRadio = {\n label: string;\n /**\n * Content rendered when the tab is active.\n */\n content: React.ReactNode;\n};\n\nexport type OptionsEditorRadiosProps = {\n tabs: OptionsEditorRadio[];\n defaultTab: number;\n onModeChange: (value: number) => void;\n isReadonly?: boolean;\n};\n\nexport const OptionsEditorRadios = (props: OptionsEditorRadiosProps) => {\n const { tabs, defaultTab, onModeChange, isReadonly } = props;\n const [activeTab, setActiveTab] = useState(defaultTab);\n\n const handleChange: RadioGroupProps['onChange'] = (_, value) => {\n const v = parseInt(value);\n setActiveTab(v);\n onModeChange(v);\n };\n\n return (\n <>\n <Box sx={{ borderBottom: 1, borderColor: (theme) => theme.palette.divider }}>\n <FormControl>\n <Typography variant=\"overline\" component=\"h4\">\n Mode:\n </Typography>\n <RadioGroup\n row\n defaultValue={defaultTab}\n value={activeTab}\n onChange={handleChange}\n aria-labelledby=\"Configuration radio\"\n >\n {tabs.map(({ label }, i) => {\n return <FormControlLabel disabled={isReadonly} key={label} value={i} control={<Radio />} label={label} />;\n })}\n </RadioGroup>\n </FormControl>\n </Box>\n {tabs.map(({ label, content }, i) => {\n return (\n <OptionsEditorTabPanel key={label} value={activeTab} index={i}>\n {content}\n </OptionsEditorTabPanel>\n );\n })}\n </>\n );\n};\n"],"names":["FormControl","FormControlLabel","Radio","RadioGroup","Box","Typography","useState","OptionsEditorTabPanel","OptionsEditorRadios","props","tabs","defaultTab","onModeChange","isReadonly","activeTab","setActiveTab","handleChange","_","value","v","parseInt","sx","borderBottom","borderColor","theme","palette","divider","variant","component","row","defaultValue","onChange","aria-labelledby","map","label","i","disabled","control","content","index"],"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,WAAW,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,UAAU,EAAmBC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACnH,SAASC,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,qBAAqB,QAAQ,0BAA0B,CAAC;AAiBjE,OAAO,MAAMC,mBAAmB,GAAG,CAACC,KAA+B,GAAK;IACtE,MAAM,EAAEC,IAAI,CAAA,EAAEC,UAAU,CAAA,EAAEC,YAAY,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGJ,KAAK,AAAC;IAC7D,MAAM,CAACK,SAAS,EAAEC,YAAY,CAAC,GAAGT,QAAQ,CAACK,UAAU,CAAC,AAAC;IAEvD,MAAMK,YAAY,GAAgC,CAACC,CAAC,EAAEC,KAAK,GAAK;QAC9D,MAAMC,CAAC,GAAGC,QAAQ,CAACF,KAAK,CAA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],"mappings":"AAaA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 * from './OptionsEditorRadios';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/OptionsEditorRadios/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 './OptionsEditorRadios';\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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface OptionsEditorTabPanelProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
index: number;
|
|
5
|
+
value: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function OptionsEditorTabPanel(props: OptionsEditorTabPanelProps): JSX.Element;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=OptionsEditorTabPanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionsEditorTabPanel.d.ts","sourceRoot":"","sources":["../../../src/components/OptionsEditorTabPanel/OptionsEditorTabPanel.tsx"],"names":[],"mappings":";AAeA,UAAU,0BAA0B;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,eAgBtE"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { Box } from '@mui/material';
|
|
15
|
-
export function
|
|
15
|
+
export function OptionsEditorTabPanel(props) {
|
|
16
16
|
const { children , value , index , ...other } = props;
|
|
17
17
|
const isActive = value === index;
|
|
18
18
|
return /*#__PURE__*/ _jsx("div", {
|
|
@@ -28,4 +28,4 @@ export function TabPanel(props) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
//# sourceMappingURL=
|
|
31
|
+
//# sourceMappingURL=OptionsEditorTabPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/OptionsEditorTabPanel/OptionsEditorTabPanel.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 { Box } from '@mui/material';\n\ninterface OptionsEditorTabPanelProps {\n children: React.ReactNode;\n index: number;\n value: number;\n}\n\nexport function OptionsEditorTabPanel(props: OptionsEditorTabPanelProps) {\n const { children, value, index, ...other } = props;\n\n const isActive = value === index;\n\n return (\n <div\n role=\"tabpanel\"\n hidden={!isActive}\n id={`options-editor-tabpanel-${index}`}\n aria-labelledby={`options-editor-tab-${index}`}\n {...other}\n >\n {isActive && <Box mt={2}>{children}</Box>}\n </div>\n );\n}\n"],"names":["Box","OptionsEditorTabPanel","props","children","value","index","other","isActive","div","role","hidden","id","aria-labelledby","mt"],"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,GAAG,QAAQ,eAAe,CAAC;AAQpC,OAAO,SAASC,qBAAqB,CAACC,KAAiC,EAAE;IACvE,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGC,KAAK,EAAE,GAAGJ,KAAK,AAAC;IAEnD,MAAMK,QAAQ,GAAGH,KAAK,KAAKC,KAAK,AAAC;IAEjC,qBACE,KAACG,KAAG;QACFC,IAAI,EAAC,UAAU;QACfC,MAAM,EAAE,CAACH,QAAQ;QACjBI,EAAE,EAAE,CAAC,wBAAwB,EAAEN,KAAK,CAAC,CAAC;QACtCO,iBAAe,EAAE,CAAC,mBAAmB,EAAEP,KAAK,CAAC,CAAC;QAC7C,GAAGC,KAAK;kBAERC,QAAQ,kBAAI,KAACP,GAAG;YAACa,EAAE,EAAE,CAAC;sBAAGV,QAAQ;UAAO;MACrC,CACN;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/OptionsEditorTabPanel/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 * from './OptionsEditorTabPanel';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/OptionsEditorTabPanel/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 './OptionsEditorTabPanel';\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,yBAAyB,CAAC"}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { Tab, Tabs, Box } from '@mui/material';
|
|
15
15
|
import { useState } from 'react';
|
|
16
|
-
import {
|
|
16
|
+
import { OptionsEditorTabPanel } from '../OptionsEditorTabPanel';
|
|
17
17
|
export const OptionsEditorTabs = ({ tabs })=>{
|
|
18
18
|
const [activeTab, setActiveTab] = useState(0);
|
|
19
19
|
const handleChange = (_, newValue)=>{
|
|
@@ -40,7 +40,7 @@ export const OptionsEditorTabs = ({ tabs })=>{
|
|
|
40
40
|
})
|
|
41
41
|
}),
|
|
42
42
|
tabs.map(({ label , content }, i)=>{
|
|
43
|
-
return /*#__PURE__*/ _jsx(
|
|
43
|
+
return /*#__PURE__*/ _jsx(OptionsEditorTabPanel, {
|
|
44
44
|
value: activeTab,
|
|
45
45
|
index: i,
|
|
46
46
|
children: content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/OptionsEditorTabs/OptionsEditorTabs.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 { Tab, Tabs, TabsProps, Box } from '@mui/material';\nimport { useState } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/OptionsEditorTabs/OptionsEditorTabs.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 { Tab, Tabs, TabsProps, Box } from '@mui/material';\nimport { useState } from 'react';\nimport { OptionsEditorTabPanel } from '../OptionsEditorTabPanel';\n\nexport type OptionsEditorTab = {\n label: string;\n /**\n * Content rendered when the tab is active.\n */\n content: React.ReactNode;\n};\n\nexport type OptionsEditorTabsProps = {\n tabs: OptionsEditorTab[];\n};\n\nexport const OptionsEditorTabs = ({ tabs }: OptionsEditorTabsProps) => {\n const [activeTab, setActiveTab] = useState(0);\n\n const handleChange: TabsProps['onChange'] = (_, newValue) => {\n setActiveTab(newValue);\n };\n\n return (\n <>\n <Box sx={{ borderBottom: 1, borderColor: (theme) => theme.palette.divider }}>\n <Tabs value={activeTab} onChange={handleChange} aria-label=\"Panel configuration tabs\">\n {tabs.map(({ label }, i) => {\n return (\n <Tab\n key={label}\n label={label}\n id={`options-editor-tab-${i}`}\n aria-controls={`options-editor-tabpanel-${i}`}\n />\n );\n })}\n </Tabs>\n </Box>\n {tabs.map(({ label, content }, i) => {\n return (\n <OptionsEditorTabPanel key={label} value={activeTab} index={i}>\n {content}\n </OptionsEditorTabPanel>\n );\n })}\n </>\n );\n};\n"],"names":["Tab","Tabs","Box","useState","OptionsEditorTabPanel","OptionsEditorTabs","tabs","activeTab","setActiveTab","handleChange","_","newValue","sx","borderBottom","borderColor","theme","palette","divider","value","onChange","aria-label","map","label","i","id","aria-controls","content","index"],"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,GAAG,EAA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ACH;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eA4BpD"}
|
|
@@ -24,7 +24,7 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
24
24
|
* `usePluginEditor` hook that powers this component.
|
|
25
25
|
*/ export function PluginEditor(props) {
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
27
|
-
const { value , pluginType , pluginKindLabel , onChange: _ , ...others } = props;
|
|
27
|
+
const { value , pluginType , pluginKindLabel , onChange: _ , isReadonly , ...others } = props;
|
|
28
28
|
const { pendingKind , isLoading , error , onKindChange , onSpecChange } = usePluginEditor(props);
|
|
29
29
|
var ref;
|
|
30
30
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
@@ -48,6 +48,7 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
48
48
|
label: pluginKindLabel,
|
|
49
49
|
pluginType: pluginType,
|
|
50
50
|
value: pendingKind !== '' ? pendingKind : value.kind,
|
|
51
|
+
readOnly: isReadonly,
|
|
51
52
|
onChange: onKindChange
|
|
52
53
|
}),
|
|
53
54
|
/*#__PURE__*/ _jsx(FormHelperText, {
|
|
@@ -59,7 +60,8 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
59
60
|
pluginType: pluginType,
|
|
60
61
|
pluginKind: value.kind,
|
|
61
62
|
value: value.spec,
|
|
62
|
-
onChange: onSpecChange
|
|
63
|
+
onChange: onSpecChange,
|
|
64
|
+
isReadonly: isReadonly
|
|
63
65
|
})
|
|
64
66
|
]
|
|
65
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n <PluginSpecEditor
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, isReadonly, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n readOnly={isReadonly}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n <PluginSpecEditor\n pluginType={pluginType}\n pluginKind={value.kind}\n value={value.spec}\n onChange={onSpecChange}\n isReadonly={isReadonly}\n />\n </Box>\n );\n}\n"],"names":["Box","FormControl","FormHelperText","InputLabel","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","value","pluginType","pluginKindLabel","onChange","_","isReadonly","others","pendingKind","isLoading","error","onKindChange","onSpecChange","margin","fullWidth","disabled","sx","mb","id","labelId","label","kind","readOnly","message","pluginKind","spec"],"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,GAAG,EAAEC,WAAW,EAAEC,cAAc,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC7E,SAASC,gBAAgB,QAAQ,qBAAqB,CAAC;AACvD,SAASC,gBAAgB,QAAQ,qBAAqB,CAAC;AACvD,SAA4BC,eAAe,QAAQ,qBAAqB,CAAC;AAEzE;;;;;;;CAOC,GACD,OAAO,SAASC,YAAY,CAACC,KAAwB,EAAE;IACrD,6DAA6D;IAC7D,MAAM,EAAEC,KAAK,CAAA,EAAEC,UAAU,CAAA,EAAEC,eAAe,CAAA,EAAEC,QAAQ,EAAEC,CAAC,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGP,KAAK,AAAC;IACzF,MAAM,EAAEQ,WAAW,CAAA,EAAEC,SAAS,CAAA,EAAEC,KAAK,CAAA,EAAEC,YAAY,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGd,eAAe,CAACE,KAAK,CAAC,AAAC;QActEU,GAAc;IAbrC,qBACE,MAAClB,GAAG;QAAE,GAAGe,MAAM;;0BACb,MAACd,WAAW;gBAACoB,MAAM,EAAC,OAAO;gBAACC,SAAS,EAAE,KAAK;gBAAEC,QAAQ,EAAEN,SAAS;gBAAEC,KAAK,EAAEA,KAAK,KAAK,IAAI;gBAAEM,EAAE,EAAE;oBAAEC,EAAE,EAAE,CAAC;iBAAE;;kCAErG,KAACtB,UAAU;wBAACuB,EAAE,EAAC,mBAAmB;kCAAEf,eAAe;sBAAc;kCACjE,KAACP,gBAAgB;wBACfuB,OAAO,EAAC,mBAAmB;wBAC3BC,KAAK,EAAEjB,eAAe;wBACtBD,UAAU,EAAEA,UAAU;wBACtBD,KAAK,EAAEO,WAAW,KAAK,EAAE,GAAGA,WAAW,GAAGP,KAAK,CAACoB,IAAI;wBACpDC,QAAQ,EAAEhB,UAAU;wBACpBF,QAAQ,EAAEO,YAAY;sBACtB;kCACF,KAACjB,cAAc;kCAAEgB,CAAAA,GAAc,GAAdA,KAAK,aAALA,KAAK,WAAS,GAAdA,KAAAA,CAAc,GAAdA,KAAK,CAAEa,OAAO,cAAdb,GAAc,cAAdA,GAAc,GAAI,EAAE;sBAAkB;;cAC3C;0BACd,KAACb,gBAAgB;gBACfK,UAAU,EAAEA,UAAU;gBACtBsB,UAAU,EAAEvB,KAAK,CAACoB,IAAI;gBACtBpB,KAAK,EAAEA,KAAK,CAACwB,IAAI;gBACjBrB,QAAQ,EAAEQ,YAAY;gBACtBN,UAAU,EAAEA,UAAU;cACtB;;MACE,CACN;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,W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Q,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACnD;AAKD;;GAEG;AACH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IAChG,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;EAqG1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.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 { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PanelPlugin, PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor/PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginType, value, onHideQueryEditorChange = () => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n\n if (pluginType === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, pluginType, value.kind]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n }\n\n if (\n pluginType === 'Panel' &&\n hideQueryState.current[nextKind] !== undefined &&\n hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]\n ) {\n onHideQuery(!!hideQueryState.current[nextKind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n })\n );\n };\n\n return { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange, rememberCurrentSpecState };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onKindChange","e","nextKind","target","previousState","onSpecChange","next","draft","isLo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ClD,CAAC;IACH,CAAC,AAAC;IAEF;;GAEC,GACD,MAAMG,YAAY,GAAsC,CAACC,IAAI,GAAK;QAChE5B,QAAQ,CACNR,OAAO,CAACM,KAAK,EAAE,CAAC+B,KAAK,GAAK;YACxBA,KAAK,CAACzB,IAAI,GAAGwB,IAAI,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEf,WAAW;QAAEiB,SAAS,EAAEb,UAAU;QAAEC,KAAK;QAAEI,YAAY;QAAEK,YAAY;QAAEtB,wBAAwB;KAAE,CAAC;AAC7G,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.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 { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PanelPlugin, PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor/PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n isReadonly?: boolean;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginType, value, onHideQueryEditorChange = () => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n\n if (pluginType === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, pluginType, value.kind]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n }\n\n if (\n pluginType === 'Panel' &&\n hideQueryState.current[nextKind] !== undefined &&\n hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]\n ) {\n onHideQuery(!!hideQueryState.current[nextKind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n })\n );\n };\n\n return { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange, rememberCurrentSpecState };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onKindChange","e","nextK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QAAQ,CAAC,CAAC,CAAC;QAClD,CAAC;IACH,CAAC,AAAC;IAEF;;GAEC,GACD,MAAMG,YAAY,GAAsC,CAACC,IAAI,GAAK;QAChE5B,QAAQ,CACNR,OAAO,CAACM,KAAK,EAAE,CAAC+B,KAAK,GAAK;YACxBA,KAAK,CAACzB,IAAI,GAAGwB,IAAI,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEf,WAAW;QAAEiB,SAAS,EAAEb,UAAU;QAAEC,KAAK;QAAEI,YAAY;QAAEK,YAAY;QAAEtB,wBAAwB;KAAE,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { VariableDefinition } from '@perses-dev/core';
|
|
3
|
+
export declare type Action = 'create' | 'read' | 'update';
|
|
4
|
+
interface VariableEditFormProps {
|
|
5
|
+
initialVariableDefinition: VariableDefinition;
|
|
6
|
+
onChange: (def: VariableDefinition) => void;
|
|
7
|
+
onCancel: () => void;
|
|
8
|
+
action?: Action;
|
|
9
|
+
}
|
|
10
|
+
export declare function VariableEditForm(props: VariableEditFormProps): JSX.Element;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=VariableEditorForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariableEditorForm.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"names":[],"mappings":";AAgCA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,kBAAkB,CAAC;AA6B9E,oBAAY,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAElD,UAAU,qBAAqB;IAC7B,yBAAyB,EAAE,kBAAkB,CAAC;IAC9C,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eAoT5D"}
|