@perses-dev/components 0.52.0 → 0.53.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +2 -3
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +2 -3
- package/dist/cjs/context/SnackbarProvider.js +58 -2
- package/dist/cjs/utils/browser-storage.js +62 -0
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/memo.js +64 -0
- package/dist/context/SnackbarProvider.d.ts +4 -1
- package/dist/context/SnackbarProvider.d.ts.map +1 -1
- package/dist/context/SnackbarProvider.js +18 -3
- package/dist/context/SnackbarProvider.js.map +1 -1
- package/dist/theme/theme.d.ts +2 -2
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js.map +1 -1
- package/dist/utils/browser-storage.d.ts +9 -0
- package/dist/utils/browser-storage.d.ts.map +1 -0
- package/dist/utils/browser-storage.js +58 -0
- package/dist/utils/browser-storage.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/memo.d.ts +13 -0
- package/dist/utils/memo.d.ts.map +1 -0
- package/dist/utils/memo.js +50 -0
- package/dist/utils/memo.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshIntervalPicker.d.ts","sourceRoot":"","sources":["../../src/RefreshIntervalPicker/RefreshIntervalPicker.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,UAAU,0BAA0B;IAClC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"RefreshIntervalPicker.d.ts","sourceRoot":"","sources":["../../src/RefreshIntervalPicker/RefreshIntervalPicker.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,UAAU,0BAA0B;IAClC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,GAAG,YAAY,CAqCrF"}
|
|
@@ -15,7 +15,6 @@ import { Box, FormControl, MenuItem, Select } from '@mui/material';
|
|
|
15
15
|
import { useMemo } from 'react';
|
|
16
16
|
export function RefreshIntervalPicker(props) {
|
|
17
17
|
const { value, onChange, timeOptions, height } = props;
|
|
18
|
-
const formattedValue = value;
|
|
19
18
|
// If the dashboard refresh interval is not provided in timeOptions, it will create a specific option for the select
|
|
20
19
|
const customInterval = useMemo(()=>{
|
|
21
20
|
if (value && !timeOptions.some((option)=>option.value.pastDuration === value)) {
|
|
@@ -32,13 +31,13 @@ export function RefreshIntervalPicker(props) {
|
|
|
32
31
|
children: /*#__PURE__*/ _jsx(Box, {
|
|
33
32
|
children: /*#__PURE__*/ _jsxs(Select, {
|
|
34
33
|
id: "refreshInterval",
|
|
35
|
-
value:
|
|
34
|
+
value: value,
|
|
36
35
|
onChange: (event)=>{
|
|
37
36
|
const duration = event.target.value;
|
|
38
37
|
onChange(duration);
|
|
39
38
|
},
|
|
40
39
|
inputProps: {
|
|
41
|
-
'aria-label': `Select refresh interval. Currently set to ${
|
|
40
|
+
'aria-label': `Select refresh interval. Currently set to ${value}`
|
|
42
41
|
},
|
|
43
42
|
sx: {
|
|
44
43
|
'.MuiSelect-select': height ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/RefreshIntervalPicker/RefreshIntervalPicker.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, MenuItem, Select } from '@mui/material';\nimport { DurationString } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport { TimeOption } from '../model';\n\ninterface RefreshIntervalPickerProps {\n timeOptions: TimeOption[];\n value?: DurationString;\n onChange: (value: DurationString) => void;\n height?: string;\n}\n\nexport function RefreshIntervalPicker(props: RefreshIntervalPickerProps): ReactElement {\n const { value, onChange, timeOptions, height } = props;\n
|
|
1
|
+
{"version":3,"sources":["../../src/RefreshIntervalPicker/RefreshIntervalPicker.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, MenuItem, Select } from '@mui/material';\nimport { DurationString } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport { TimeOption } from '../model';\n\ninterface RefreshIntervalPickerProps {\n timeOptions: TimeOption[];\n value?: DurationString;\n onChange: (value: DurationString) => void;\n height?: string;\n}\n\nexport function RefreshIntervalPicker(props: RefreshIntervalPickerProps): ReactElement {\n const { value, onChange, timeOptions, height } = props;\n\n // If the dashboard refresh interval is not provided in timeOptions, it will create a specific option for the select\n const customInterval = useMemo(() => {\n if (value && !timeOptions.some((option) => option.value.pastDuration === value)) {\n return <MenuItem value={value}>{value}</MenuItem>;\n }\n }, [timeOptions, value]);\n\n return (\n <FormControl>\n <Box>\n <Select\n id=\"refreshInterval\"\n value={value}\n onChange={(event) => {\n const duration = event.target.value as DurationString;\n onChange(duration);\n }}\n inputProps={{\n 'aria-label': `Select refresh interval. Currently set to ${value}`,\n }}\n sx={{\n '.MuiSelect-select': height ? { lineHeight: height, paddingY: 0 } : {},\n }}\n >\n {timeOptions.map((item, idx) => (\n <MenuItem key={idx} value={item.value.pastDuration}>\n {item.display}\n </MenuItem>\n ))}\n {customInterval}\n </Select>\n </Box>\n </FormControl>\n );\n}\n"],"names":["Box","FormControl","MenuItem","Select","useMemo","RefreshIntervalPicker","props","value","onChange","timeOptions","height","customInterval","some","option","pastDuration","id","event","duration","target","inputProps","sx","lineHeight","paddingY","map","item","idx","display"],"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,SAASA,GAAG,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,gBAAgB;AAEnE,SAAuBC,OAAO,QAAQ,QAAQ;AAU9C,OAAO,SAASC,sBAAsBC,KAAiC;IACrE,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,MAAM,EAAE,GAAGJ;IAEjD,oHAAoH;IACpH,MAAMK,iBAAiBP,QAAQ;QAC7B,IAAIG,SAAS,CAACE,YAAYG,IAAI,CAAC,CAACC,SAAWA,OAAON,KAAK,CAACO,YAAY,KAAKP,QAAQ;YAC/E,qBAAO,KAACL;gBAASK,OAAOA;0BAAQA;;QAClC;IACF,GAAG;QAACE;QAAaF;KAAM;IAEvB,qBACE,KAACN;kBACC,cAAA,KAACD;sBACC,cAAA,MAACG;gBACCY,IAAG;gBACHR,OAAOA;gBACPC,UAAU,CAACQ;oBACT,MAAMC,WAAWD,MAAME,MAAM,CAACX,KAAK;oBACnCC,SAASS;gBACX;gBACAE,YAAY;oBACV,cAAc,CAAC,0CAA0C,EAAEZ,OAAO;gBACpE;gBACAa,IAAI;oBACF,qBAAqBV,SAAS;wBAAEW,YAAYX;wBAAQY,UAAU;oBAAE,IAAI,CAAC;gBACvE;;oBAECb,YAAYc,GAAG,CAAC,CAACC,MAAMC,oBACtB,KAACvB;4BAAmBK,OAAOiB,KAAKjB,KAAK,CAACO,YAAY;sCAC/CU,KAAKE,OAAO;2BADAD;oBAIhBd;;;;;AAKX"}
|
|
@@ -25,7 +25,6 @@ const _material = require("@mui/material");
|
|
|
25
25
|
const _react = require("react");
|
|
26
26
|
function RefreshIntervalPicker(props) {
|
|
27
27
|
const { value, onChange, timeOptions, height } = props;
|
|
28
|
-
const formattedValue = value;
|
|
29
28
|
// If the dashboard refresh interval is not provided in timeOptions, it will create a specific option for the select
|
|
30
29
|
const customInterval = (0, _react.useMemo)(()=>{
|
|
31
30
|
if (value && !timeOptions.some((option)=>option.value.pastDuration === value)) {
|
|
@@ -42,13 +41,13 @@ function RefreshIntervalPicker(props) {
|
|
|
42
41
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
43
42
|
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Select, {
|
|
44
43
|
id: "refreshInterval",
|
|
45
|
-
value:
|
|
44
|
+
value: value,
|
|
46
45
|
onChange: (event)=>{
|
|
47
46
|
const duration = event.target.value;
|
|
48
47
|
onChange(duration);
|
|
49
48
|
},
|
|
50
49
|
inputProps: {
|
|
51
|
-
'aria-label': `Select refresh interval. Currently set to ${
|
|
50
|
+
'aria-label': `Select refresh interval. Currently set to ${value}`
|
|
52
51
|
},
|
|
53
52
|
sx: {
|
|
54
53
|
'.MuiSelect-select': height ? {
|
|
@@ -22,14 +22,70 @@ function _export(target, all) {
|
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
24
|
SnackbarProvider: function() {
|
|
25
|
-
return
|
|
25
|
+
return SnackbarProvider;
|
|
26
26
|
},
|
|
27
27
|
useSnackbar: function() {
|
|
28
28
|
return useSnackbar;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
const
|
|
31
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
32
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
33
|
+
const _styles = require("@mui/material/styles");
|
|
32
34
|
const _notistack = require("notistack");
|
|
35
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
36
|
+
if (typeof WeakMap !== "function") return null;
|
|
37
|
+
var cacheBabelInterop = new WeakMap();
|
|
38
|
+
var cacheNodeInterop = new WeakMap();
|
|
39
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
40
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
41
|
+
})(nodeInterop);
|
|
42
|
+
}
|
|
43
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
44
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
48
|
+
return {
|
|
49
|
+
default: obj
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
53
|
+
if (cache && cache.has(obj)) {
|
|
54
|
+
return cache.get(obj);
|
|
55
|
+
}
|
|
56
|
+
var newObj = {
|
|
57
|
+
__proto__: null
|
|
58
|
+
};
|
|
59
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
60
|
+
for(var key in obj){
|
|
61
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
62
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
63
|
+
if (desc && (desc.get || desc.set)) {
|
|
64
|
+
Object.defineProperty(newObj, key, desc);
|
|
65
|
+
} else {
|
|
66
|
+
newObj[key] = obj[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
newObj.default = obj;
|
|
71
|
+
if (cache) {
|
|
72
|
+
cache.set(obj, newObj);
|
|
73
|
+
}
|
|
74
|
+
return newObj;
|
|
75
|
+
}
|
|
76
|
+
function SnackbarProvider({ children, ...props }) {
|
|
77
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_notistack.SnackbarProvider, {
|
|
78
|
+
...props,
|
|
79
|
+
Components: {
|
|
80
|
+
error: (0, _styles.styled)(_notistack.MaterialDesignContent)(()=>({
|
|
81
|
+
'&.notistack-MuiContent-error': {
|
|
82
|
+
whiteSpace: 'pre-wrap'
|
|
83
|
+
}
|
|
84
|
+
}))
|
|
85
|
+
},
|
|
86
|
+
children: children
|
|
87
|
+
});
|
|
88
|
+
}
|
|
33
89
|
function useSnackbar() {
|
|
34
90
|
const { enqueueSnackbar, closeSnackbar } = (0, _notistack.useSnackbar)();
|
|
35
91
|
// Create variant-specific callbacks
|
|
@@ -0,0 +1,62 @@
|
|
|
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, "useLocalStorage", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return useLocalStorage;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
function useLocalStorage(key, initialValue) {
|
|
25
|
+
const { value, setValueAndStore } = useStorage(window.localStorage, key, initialValue);
|
|
26
|
+
return [
|
|
27
|
+
value,
|
|
28
|
+
setValueAndStore
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
// Common functionality used by all storage hooks
|
|
32
|
+
function useStorage(storage, key, initialValue) {
|
|
33
|
+
// Use state so that changes cause the page to re-render
|
|
34
|
+
const [value, setValue] = (0, _react.useState)(()=>{
|
|
35
|
+
try {
|
|
36
|
+
const json = storage.getItem(key);
|
|
37
|
+
if (json !== null) {
|
|
38
|
+
return JSON.parse(json);
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// No-op
|
|
42
|
+
}
|
|
43
|
+
// Either the value isn't in storage yet or JSON parsing failed, so
|
|
44
|
+
// set to the initial value in both places
|
|
45
|
+
storage.setItem(key, JSON.stringify(initialValue));
|
|
46
|
+
return initialValue;
|
|
47
|
+
});
|
|
48
|
+
// Set in both places
|
|
49
|
+
const setValueAndStore = (0, _react.useCallback)((val)=>{
|
|
50
|
+
setValue(val);
|
|
51
|
+
storage.setItem(key, JSON.stringify(val));
|
|
52
|
+
}, [
|
|
53
|
+
setValue,
|
|
54
|
+
storage,
|
|
55
|
+
key
|
|
56
|
+
]);
|
|
57
|
+
return {
|
|
58
|
+
value,
|
|
59
|
+
setValue,
|
|
60
|
+
setValueAndStore
|
|
61
|
+
};
|
|
62
|
+
}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -15,11 +15,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./axis"), exports);
|
|
18
|
+
_export_star(require("./browser-storage"), exports);
|
|
18
19
|
_export_star(require("./chart-actions"), exports);
|
|
19
20
|
_export_star(require("./combine-sx"), exports);
|
|
20
21
|
_export_star(require("./component-ids"), exports);
|
|
21
22
|
_export_star(require("./format"), exports);
|
|
22
23
|
_export_star(require("./theme-gen"), exports);
|
|
24
|
+
_export_star(require("./memo"), exports);
|
|
23
25
|
function _export_star(from, to) {
|
|
24
26
|
Object.keys(from).forEach(function(k) {
|
|
25
27
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
useDeepMemo: function() {
|
|
25
|
+
return useDeepMemo;
|
|
26
|
+
},
|
|
27
|
+
useMemoized: function() {
|
|
28
|
+
return useMemoized;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _react = require("react");
|
|
32
|
+
const _isEqual = /*#__PURE__*/ _interop_require_default(require("lodash/isEqual"));
|
|
33
|
+
function _interop_require_default(obj) {
|
|
34
|
+
return obj && obj.__esModule ? obj : {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function useMemoized(factory, deps) {
|
|
39
|
+
const ref = (0, _react.useRef)();
|
|
40
|
+
let areEqual = true;
|
|
41
|
+
for(let i = 0; i < deps.length; i++){
|
|
42
|
+
if (ref.current?.deps[i] !== deps[i]) {
|
|
43
|
+
areEqual = false;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (ref.current === undefined || areEqual === false) {
|
|
48
|
+
ref.current = {
|
|
49
|
+
value: factory(),
|
|
50
|
+
deps: deps
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return ref.current.value;
|
|
54
|
+
}
|
|
55
|
+
function useDeepMemo(factory, deps) {
|
|
56
|
+
const ref = (0, _react.useRef)();
|
|
57
|
+
if (ref.current === undefined || (0, _isEqual.default)(deps, ref.current.deps) === false) {
|
|
58
|
+
ref.current = {
|
|
59
|
+
value: factory(),
|
|
60
|
+
deps
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return ref.current.value;
|
|
64
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { SnackbarProvider as NotistackProvider, ProviderContext as NotistackContext, SnackbarMessage, OptionsObject, SnackbarKey } from 'notistack';
|
|
2
3
|
export interface SnackbarContext extends NotistackContext {
|
|
3
4
|
errorSnackbar: EnqueueFunction;
|
|
@@ -14,10 +15,12 @@ type EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) =>
|
|
|
14
15
|
type SnackbarOptions = Omit<OptionsObject, 'variant'>;
|
|
15
16
|
/**
|
|
16
17
|
* Application-wide provider for showing snackbars/toasts.
|
|
18
|
+
* Customized to preserve formatting in error messages.
|
|
17
19
|
*/
|
|
18
|
-
export {
|
|
20
|
+
export declare function SnackbarProvider({ children, ...props }: React.ComponentProps<typeof NotistackProvider>): React.ReactElement;
|
|
19
21
|
/**
|
|
20
22
|
* Gets the SnackbarContext with methods for displaying snackbars/toasts.
|
|
21
23
|
*/
|
|
22
24
|
export declare function useSnackbar(): SnackbarContext;
|
|
25
|
+
export {};
|
|
23
26
|
//# sourceMappingURL=SnackbarProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnackbarProvider.d.ts","sourceRoot":"","sources":["../../src/context/SnackbarProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SnackbarProvider.d.ts","sourceRoot":"","sources":["../../src/context/SnackbarProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAE3C,OAAO,EACL,gBAAgB,IAAI,iBAAiB,EACrC,eAAe,IAAI,gBAAgB,EAEnC,eAAe,EACf,aAAa,EACb,WAAW,EAEZ,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,aAAa,EAAE,eAAe,CAAC;IAC/B,YAAY,EAAE,eAAe,CAAC;IAC9B,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,EAAE,eAAe,CAAC;IAEjC;;;OAGG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,WAAW,CAAC;CAC/E;AAED,KAAK,eAAe,GAAG,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,WAAW,CAAC;AAE5F,KAAK,eAAe,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,iBAAiB,CAAC,GAAG,KAAK,CAAC,YAAY,CAerE;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,eAAe,CA6B7C"}
|
|
@@ -10,11 +10,26 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import React, { useCallback } from 'react';
|
|
15
|
+
import { styled } from '@mui/material/styles';
|
|
16
|
+
import { SnackbarProvider as NotistackProvider, useSnackbar as useNotistack, MaterialDesignContent } from 'notistack';
|
|
15
17
|
/**
|
|
16
18
|
* Application-wide provider for showing snackbars/toasts.
|
|
17
|
-
|
|
19
|
+
* Customized to preserve formatting in error messages.
|
|
20
|
+
*/ export function SnackbarProvider({ children, ...props }) {
|
|
21
|
+
return /*#__PURE__*/ _jsx(NotistackProvider, {
|
|
22
|
+
...props,
|
|
23
|
+
Components: {
|
|
24
|
+
error: styled(MaterialDesignContent)(()=>({
|
|
25
|
+
'&.notistack-MuiContent-error': {
|
|
26
|
+
whiteSpace: 'pre-wrap'
|
|
27
|
+
}
|
|
28
|
+
}))
|
|
29
|
+
},
|
|
30
|
+
children: children
|
|
31
|
+
});
|
|
32
|
+
}
|
|
18
33
|
/**
|
|
19
34
|
* Gets the SnackbarContext with methods for displaying snackbars/toasts.
|
|
20
35
|
*/ export function useSnackbar() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/SnackbarProvider.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 { useCallback } from 'react';\nimport {\n SnackbarProvider as NotistackProvider,\n ProviderContext as NotistackContext,\n useSnackbar as useNotistack,\n SnackbarMessage,\n OptionsObject,\n SnackbarKey,\n} from 'notistack';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n */\nexport { NotistackProvider
|
|
1
|
+
{"version":3,"sources":["../../src/context/SnackbarProvider.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 React, { useCallback } from 'react';\nimport { styled } from '@mui/material/styles';\nimport {\n SnackbarProvider as NotistackProvider,\n ProviderContext as NotistackContext,\n useSnackbar as useNotistack,\n SnackbarMessage,\n OptionsObject,\n SnackbarKey,\n MaterialDesignContent,\n} from 'notistack';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar]\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant']\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant]\n );\n}\n"],"names":["React","useCallback","styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","children","props","Components","error","whiteSpace","enqueueSnackbar","closeSnackbar","errorSnackbar","useEnqueueFunction","infoSnackbar","warningSnackbar","successSnackbar","exceptionSnackbar","options","message","Error","variant","allOptions"],"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,OAAOA,SAASC,WAAW,QAAQ,QAAQ;AAC3C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SACEC,oBAAoBC,iBAAiB,EAErCC,eAAeC,YAAY,EAI3BC,qBAAqB,QAChB,YAAY;AAmBnB;;;CAGC,GACD,OAAO,SAASJ,iBAAiB,EAC/BK,QAAQ,EACR,GAAGC,OAC4C;IAC/C,qBACE,KAACL;QACE,GAAGK,KAAK;QACTC,YAAY;YACVC,OAAOT,OAAOK,uBAAuB,IAAO,CAAA;oBAC1C,gCAAgC;wBAC9BK,YAAY;oBACd;gBACF,CAAA;QACF;kBAECJ;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASH;IACd,MAAM,EAAEQ,eAAe,EAAEC,aAAa,EAAE,GAAGR;IAE3C,oCAAoC;IACpC,MAAMS,gBAAgBC,mBAAmBH,iBAAiB;IAC1D,MAAMI,eAAeD,mBAAmBH,iBAAiB;IACzD,MAAMK,kBAAkBF,mBAAmBH,iBAAiB;IAC5D,MAAMM,kBAAkBH,mBAAmBH,iBAAiB;IAE5D,MAAMO,oBAA0DnB,YAC9D,CAACU,OAAOU;QACN,kEAAkE;QAClE,yCAAyC;QACzC,MAAMC,UAAUX,iBAAiBY,QAAQZ,MAAMW,OAAO,GAAG,CAAC,8BAA8B,EAAEX,OAAO;QAEjG,OAAOI,cAAcO,SAASD;IAChC,GACA;QAACN;KAAc;IAGjB,OAAO;QACLF;QACAC;QACAC;QACAE;QACAC;QACAC;QACAC;IACF;AACF;AAEA,uDAAuD;AACvD,SAASJ,mBACPH,eAAoD,EACpDW,OAAiC;IAEjC,OAAOvB,YACL,CAACqB,SAASD;QACR,MAAMI,aAA4B;YAChC,GAAGJ,OAAO;YACVG;QACF;QACA,OAAOX,gBAAgBS,SAASG;IAClC,GACA;QAACZ;QAAiBW;KAAQ;AAE9B"}
|
package/dist/theme/theme.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createTheme, PaletteMode, Theme } from '@mui/material';
|
|
2
2
|
/**
|
|
3
3
|
* Gets theme used by all components for the provided mode. For more details, see:
|
|
4
4
|
* - Base colors, typography, sizing - go/chrono-ui-theme
|
|
@@ -9,5 +9,5 @@ import { PaletteMode, ThemeOptions, Theme } from '@mui/material';
|
|
|
9
9
|
* Need to reinstantiate the theme everytime to support switching between light and dark themes
|
|
10
10
|
* https://github.com/mui-org/material-ui/issues/18831
|
|
11
11
|
*/
|
|
12
|
-
export declare function getTheme(mode: PaletteMode, options?:
|
|
12
|
+
export declare function getTheme(mode: PaletteMode, options?: Parameters<typeof createTheme>[0]): Theme;
|
|
13
13
|
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AAuB9E;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,GAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAM,GAAG,KAAK,CAQlG"}
|
package/dist/theme/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/theme.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 { createTheme, PaletteMode, ThemeOptions, Theme } from '@mui/material';\nimport { MuiAlert } from './component-overrides/alert';\nimport { MuiPaper } from './component-overrides/paper';\nimport { getPaletteOptions } from './palette';\nimport { typography } from './typography';\n\nconst getModalBackgroundStyle = ({\n theme,\n}: {\n theme: Omit<Theme, 'components'>;\n}): { backgroundImage?: string; backgroundColor?: string } => {\n const backgroundStyle =\n theme.palette.mode === 'light'\n ? {}\n : {\n backgroundImage: 'unset',\n backgroundColor: theme.palette.designSystem.grey[800],\n };\n return {\n ...backgroundStyle,\n };\n};\n\n/**\n * Gets theme used by all components for the provided mode. For more details, see:\n * - Base colors, typography, sizing - go/chrono-ui-theme\n * - Material UI defaults: https://material-ui.com/customization/default-theme/\n * - Material UI variables: https://material-ui.com/customization/theming/#theme-configuration-variables\n * - Material UI global overrides and default props: https://material-ui.com/customization/globals/#css\n *\n * Need to reinstantiate the theme everytime to support switching between light and dark themes\n * https://github.com/mui-org/material-ui/issues/18831\n */\nexport function getTheme(mode: PaletteMode, options:
|
|
1
|
+
{"version":3,"sources":["../../src/theme/theme.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 { createTheme, PaletteMode, ThemeOptions, Theme } from '@mui/material';\nimport { MuiAlert } from './component-overrides/alert';\nimport { MuiPaper } from './component-overrides/paper';\nimport { getPaletteOptions } from './palette';\nimport { typography } from './typography';\n\nconst getModalBackgroundStyle = ({\n theme,\n}: {\n theme: Omit<Theme, 'components'>;\n}): { backgroundImage?: string; backgroundColor?: string } => {\n const backgroundStyle =\n theme.palette.mode === 'light'\n ? {}\n : {\n backgroundImage: 'unset',\n backgroundColor: theme.palette.designSystem.grey[800],\n };\n return {\n ...backgroundStyle,\n };\n};\n\n/**\n * Gets theme used by all components for the provided mode. For more details, see:\n * - Base colors, typography, sizing - go/chrono-ui-theme\n * - Material UI defaults: https://material-ui.com/customization/default-theme/\n * - Material UI variables: https://material-ui.com/customization/theming/#theme-configuration-variables\n * - Material UI global overrides and default props: https://material-ui.com/customization/globals/#css\n *\n * Need to reinstantiate the theme everytime to support switching between light and dark themes\n * https://github.com/mui-org/material-ui/issues/18831\n */\nexport function getTheme(mode: PaletteMode, options: Parameters<typeof createTheme>[0] = {}): Theme {\n return createTheme({\n palette: getPaletteOptions(mode),\n typography,\n mixins: {},\n components,\n ...options,\n });\n}\n\n// Overrides for component default prop values and styles go here\nconst components: ThemeOptions['components'] = {\n MuiAlert,\n MuiFormControl: {\n defaultProps: {\n size: 'small',\n },\n },\n MuiPaper,\n MuiTextField: {\n defaultProps: {\n size: 'small',\n },\n },\n MuiDrawer: {\n styleOverrides: {\n paper: getModalBackgroundStyle,\n },\n },\n MuiDialog: {\n styleOverrides: {\n paper: getModalBackgroundStyle,\n },\n },\n MuiPopover: {\n styleOverrides: {\n paper: getModalBackgroundStyle,\n },\n },\n};\n"],"names":["createTheme","MuiAlert","MuiPaper","getPaletteOptions","typography","getModalBackgroundStyle","theme","backgroundStyle","palette","mode","backgroundImage","backgroundColor","designSystem","grey","getTheme","options","mixins","components","MuiFormControl","defaultProps","size","MuiTextField","MuiDrawer","styleOverrides","paper","MuiDialog","MuiPopover"],"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,SAASA,WAAW,QAA0C,gBAAgB;AAC9E,SAASC,QAAQ,QAAQ,8BAA8B;AACvD,SAASC,QAAQ,QAAQ,8BAA8B;AACvD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,UAAU,QAAQ,eAAe;AAE1C,MAAMC,0BAA0B,CAAC,EAC/BC,KAAK,EAGN;IACC,MAAMC,kBACJD,MAAME,OAAO,CAACC,IAAI,KAAK,UACnB,CAAC,IACD;QACEC,iBAAiB;QACjBC,iBAAiBL,MAAME,OAAO,CAACI,YAAY,CAACC,IAAI,CAAC,IAAI;IACvD;IACN,OAAO;QACL,GAAGN,eAAe;IACpB;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASO,SAASL,IAAiB,EAAEM,UAA6C,CAAC,CAAC;IACzF,OAAOf,YAAY;QACjBQ,SAASL,kBAAkBM;QAC3BL;QACAY,QAAQ,CAAC;QACTC;QACA,GAAGF,OAAO;IACZ;AACF;AAEA,iEAAiE;AACjE,MAAME,aAAyC;IAC7ChB;IACAiB,gBAAgB;QACdC,cAAc;YACZC,MAAM;QACR;IACF;IACAlB;IACAmB,cAAc;QACZF,cAAc;YACZC,MAAM;QACR;IACF;IACAE,WAAW;QACTC,gBAAgB;YACdC,OAAOnB;QACT;IACF;IACAoB,WAAW;QACTF,gBAAgB;YACdC,OAAOnB;QACT;IACF;IACAqB,YAAY;QACVH,gBAAgB;YACdC,OAAOnB;QACT;IACF;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type StorageTuple<T> = [T, (next: T) => void];
|
|
2
|
+
/**
|
|
3
|
+
* Just like useState but gets/sets the value in the browser's local storage.
|
|
4
|
+
* 'key' should be a constant string. 'initialValue' is returned when local
|
|
5
|
+
* storage does not have any data yet.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useLocalStorage<T>(key: string, initialValue: T): StorageTuple<T>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=browser-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-storage.d.ts","sourceRoot":"","sources":["../../src/utils/browser-storage.ts"],"names":[],"mappings":"AAeA,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAGhF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { useState, useCallback } from 'react';
|
|
14
|
+
/**
|
|
15
|
+
* Just like useState but gets/sets the value in the browser's local storage.
|
|
16
|
+
* 'key' should be a constant string. 'initialValue' is returned when local
|
|
17
|
+
* storage does not have any data yet.
|
|
18
|
+
*/ export function useLocalStorage(key, initialValue) {
|
|
19
|
+
const { value, setValueAndStore } = useStorage(window.localStorage, key, initialValue);
|
|
20
|
+
return [
|
|
21
|
+
value,
|
|
22
|
+
setValueAndStore
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
// Common functionality used by all storage hooks
|
|
26
|
+
function useStorage(storage, key, initialValue) {
|
|
27
|
+
// Use state so that changes cause the page to re-render
|
|
28
|
+
const [value, setValue] = useState(()=>{
|
|
29
|
+
try {
|
|
30
|
+
const json = storage.getItem(key);
|
|
31
|
+
if (json !== null) {
|
|
32
|
+
return JSON.parse(json);
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
// No-op
|
|
36
|
+
}
|
|
37
|
+
// Either the value isn't in storage yet or JSON parsing failed, so
|
|
38
|
+
// set to the initial value in both places
|
|
39
|
+
storage.setItem(key, JSON.stringify(initialValue));
|
|
40
|
+
return initialValue;
|
|
41
|
+
});
|
|
42
|
+
// Set in both places
|
|
43
|
+
const setValueAndStore = useCallback((val)=>{
|
|
44
|
+
setValue(val);
|
|
45
|
+
storage.setItem(key, JSON.stringify(val));
|
|
46
|
+
}, [
|
|
47
|
+
setValue,
|
|
48
|
+
storage,
|
|
49
|
+
key
|
|
50
|
+
]);
|
|
51
|
+
return {
|
|
52
|
+
value,
|
|
53
|
+
setValue,
|
|
54
|
+
setValueAndStore
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=browser-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/browser-storage.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 { useState, useCallback } from 'react';\n\ntype StorageTuple<T> = [T, (next: T) => void];\n\n/**\n * Just like useState but gets/sets the value in the browser's local storage.\n * 'key' should be a constant string. 'initialValue' is returned when local\n * storage does not have any data yet.\n */\nexport function useLocalStorage<T>(key: string, initialValue: T): StorageTuple<T> {\n const { value, setValueAndStore } = useStorage(window.localStorage, key, initialValue);\n return [value, setValueAndStore];\n}\n\n// Common functionality used by all storage hooks\nfunction useStorage<T>(\n storage: Storage,\n key: string,\n initialValue: T\n): {\n setValueAndStore: (value: T) => void;\n setValue: (value: T) => void;\n value: T;\n} {\n // Use state so that changes cause the page to re-render\n const [value, setValue] = useState<T>(() => {\n try {\n const json = storage.getItem(key);\n if (json !== null) {\n return JSON.parse(json);\n }\n } catch {\n // No-op\n }\n\n // Either the value isn't in storage yet or JSON parsing failed, so\n // set to the initial value in both places\n storage.setItem(key, JSON.stringify(initialValue));\n return initialValue;\n });\n\n // Set in both places\n const setValueAndStore = useCallback(\n (val: T) => {\n setValue(val);\n storage.setItem(key, JSON.stringify(val));\n },\n [setValue, storage, key]\n );\n\n return { value, setValue, setValueAndStore };\n}\n"],"names":["useState","useCallback","useLocalStorage","key","initialValue","value","setValueAndStore","useStorage","window","localStorage","storage","setValue","json","getItem","JSON","parse","setItem","stringify","val"],"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,SAASA,QAAQ,EAAEC,WAAW,QAAQ,QAAQ;AAI9C;;;;CAIC,GACD,OAAO,SAASC,gBAAmBC,GAAW,EAAEC,YAAe;IAC7D,MAAM,EAAEC,KAAK,EAAEC,gBAAgB,EAAE,GAAGC,WAAWC,OAAOC,YAAY,EAAEN,KAAKC;IACzE,OAAO;QAACC;QAAOC;KAAiB;AAClC;AAEA,iDAAiD;AACjD,SAASC,WACPG,OAAgB,EAChBP,GAAW,EACXC,YAAe;IAMf,wDAAwD;IACxD,MAAM,CAACC,OAAOM,SAAS,GAAGX,SAAY;QACpC,IAAI;YACF,MAAMY,OAAOF,QAAQG,OAAO,CAACV;YAC7B,IAAIS,SAAS,MAAM;gBACjB,OAAOE,KAAKC,KAAK,CAACH;YACpB;QACF,EAAE,OAAM;QACN,QAAQ;QACV;QAEA,mEAAmE;QACnE,0CAA0C;QAC1CF,QAAQM,OAAO,CAACb,KAAKW,KAAKG,SAAS,CAACb;QACpC,OAAOA;IACT;IAEA,qBAAqB;IACrB,MAAME,mBAAmBL,YACvB,CAACiB;QACCP,SAASO;QACTR,QAAQM,OAAO,CAACb,KAAKW,KAAKG,SAAS,CAACC;IACtC,GACA;QAACP;QAAUD;QAASP;KAAI;IAG1B,OAAO;QAAEE;QAAOM;QAAUL;IAAiB;AAC7C"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './axis';
|
|
2
|
+
export * from './browser-storage';
|
|
2
3
|
export * from './chart-actions';
|
|
3
4
|
export * from './combine-sx';
|
|
4
5
|
export * from './component-ids';
|
|
5
6
|
export * from './format';
|
|
6
7
|
export * from './theme-gen';
|
|
8
|
+
export * from './memo';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './axis';
|
|
14
|
+
export * from './browser-storage';
|
|
14
15
|
export * from './chart-actions';
|
|
15
16
|
export * from './combine-sx';
|
|
16
17
|
export * from './component-ids';
|
|
17
18
|
export * from './format';
|
|
18
19
|
export * from './theme-gen';
|
|
20
|
+
export * from './memo';
|
|
19
21
|
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/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 './axis';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './format';\nexport * from './theme-gen';\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,SAAS;AACvB,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,WAAW;AACzB,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/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 './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './format';\nexport * from './theme-gen';\nexport * from './memo';\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,SAAS;AACvB,cAAc,oBAAoB;AAClC,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,SAAS"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Like React's useMemo, but guarantees the value will only be recalulated if
|
|
4
|
+
* a dependency changes. Uses strict equality (===) for comparison. (React's
|
|
5
|
+
* useMemo does not offer this guarantee, it's only a performance optimization).
|
|
6
|
+
*/
|
|
7
|
+
export declare function useMemoized<T>(factory: () => T, deps: DependencyList): T;
|
|
8
|
+
/**
|
|
9
|
+
* Like React's useMemo, except it does a deep equality comparison with lodash's
|
|
10
|
+
* isEqual on the dependency list.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useDeepMemo<T>(factory: () => T, deps: DependencyList): T;
|
|
13
|
+
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/utils/memo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAU,cAAc,EAAE,MAAM,OAAO,CAAC;AAQ/C;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,CAAC,CAgBxE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,CAAC,CAMxE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 { useRef } from 'react';
|
|
14
|
+
import isEqual from 'lodash/isEqual';
|
|
15
|
+
/**
|
|
16
|
+
* Like React's useMemo, but guarantees the value will only be recalulated if
|
|
17
|
+
* a dependency changes. Uses strict equality (===) for comparison. (React's
|
|
18
|
+
* useMemo does not offer this guarantee, it's only a performance optimization).
|
|
19
|
+
*/ export function useMemoized(factory, deps) {
|
|
20
|
+
const ref = useRef();
|
|
21
|
+
let areEqual = true;
|
|
22
|
+
for(let i = 0; i < deps.length; i++){
|
|
23
|
+
if (ref.current?.deps[i] !== deps[i]) {
|
|
24
|
+
areEqual = false;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (ref.current === undefined || areEqual === false) {
|
|
29
|
+
ref.current = {
|
|
30
|
+
value: factory(),
|
|
31
|
+
deps: deps
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return ref.current.value;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Like React's useMemo, except it does a deep equality comparison with lodash's
|
|
38
|
+
* isEqual on the dependency list.
|
|
39
|
+
*/ export function useDeepMemo(factory, deps) {
|
|
40
|
+
const ref = useRef();
|
|
41
|
+
if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {
|
|
42
|
+
ref.current = {
|
|
43
|
+
value: factory(),
|
|
44
|
+
deps
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return ref.current.value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/memo.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 { useRef, DependencyList } from 'react';\nimport isEqual from 'lodash/isEqual';\n\ntype MemoRef<T> = {\n value: T;\n deps: DependencyList;\n};\n\n/**\n * Like React's useMemo, but guarantees the value will only be recalulated if\n * a dependency changes. Uses strict equality (===) for comparison. (React's\n * useMemo does not offer this guarantee, it's only a performance optimization).\n */\nexport function useMemoized<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n\n let areEqual = true;\n for (let i = 0; i < deps.length; i++) {\n if (ref.current?.deps[i] !== deps[i]) {\n areEqual = false;\n break;\n }\n }\n\n if (ref.current === undefined || areEqual === false) {\n ref.current = { value: factory(), deps: deps };\n }\n\n return ref.current.value;\n}\n\n/**\n * Like React's useMemo, except it does a deep equality comparison with lodash's\n * isEqual on the dependency list.\n */\nexport function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {\n ref.current = { value: factory(), deps };\n }\n return ref.current.value;\n}\n"],"names":["useRef","isEqual","useMemoized","factory","deps","ref","areEqual","i","length","current","undefined","value","useDeepMemo"],"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,SAASA,MAAM,QAAwB,QAAQ;AAC/C,OAAOC,aAAa,iBAAiB;AAOrC;;;;CAIC,GACD,OAAO,SAASC,YAAeC,OAAgB,EAAEC,IAAoB;IACnE,MAAMC,MAAML;IAEZ,IAAIM,WAAW;IACf,IAAK,IAAIC,IAAI,GAAGA,IAAIH,KAAKI,MAAM,EAAED,IAAK;QACpC,IAAIF,IAAII,OAAO,EAAEL,IAAI,CAACG,EAAE,KAAKH,IAAI,CAACG,EAAE,EAAE;YACpCD,WAAW;YACX;QACF;IACF;IAEA,IAAID,IAAII,OAAO,KAAKC,aAAaJ,aAAa,OAAO;QACnDD,IAAII,OAAO,GAAG;YAAEE,OAAOR;YAAWC,MAAMA;QAAK;IAC/C;IAEA,OAAOC,IAAII,OAAO,CAACE,KAAK;AAC1B;AAEA;;;CAGC,GACD,OAAO,SAASC,YAAeT,OAAgB,EAAEC,IAAoB;IACnE,MAAMC,MAAML;IACZ,IAAIK,IAAII,OAAO,KAAKC,aAAaT,QAAQG,MAAMC,IAAII,OAAO,CAACL,IAAI,MAAM,OAAO;QAC1EC,IAAII,OAAO,GAAG;YAAEE,OAAOR;YAAWC;QAAK;IACzC;IACA,OAAOC,IAAII,OAAO,CAACE,KAAK;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0-beta.1",
|
|
4
4
|
"description": "Common UI components used across Perses features",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@codemirror/lang-json": "^6.0.1",
|
|
34
34
|
"@fontsource/lato": "^4.5.10",
|
|
35
35
|
"@mui/x-date-pickers": "^7.23.1",
|
|
36
|
-
"@perses-dev/core": "0.
|
|
36
|
+
"@perses-dev/core": "0.53.0-beta.1",
|
|
37
37
|
"@tanstack/react-table": "^8.20.5",
|
|
38
38
|
"@uiw/react-codemirror": "^4.19.1",
|
|
39
39
|
"date-fns": "^4.1.0",
|