2022-05-08 16:49:09 +03:00
|
|
|
import type { CurriedFunction1 } from 'lodash';
|
2023-01-05 07:17:44 +03:00
|
|
|
import { createStyling } from 'react-base16-styling';
|
|
|
|
import type {
|
2020-08-22 03:13:24 +03:00
|
|
|
Base16Theme,
|
|
|
|
StylingConfig,
|
2023-01-05 07:17:44 +03:00
|
|
|
StylingFunction,
|
|
|
|
Theme,
|
2020-08-22 03:13:24 +03:00
|
|
|
} from 'react-base16-styling';
|
2024-04-08 00:04:45 +03:00
|
|
|
import solarized from './themes/solarized.js';
|
2018-12-21 22:18:05 +03:00
|
|
|
|
2020-08-22 03:13:24 +03:00
|
|
|
const colorMap = (theme: Base16Theme) => ({
|
2018-12-21 22:18:05 +03:00
|
|
|
BACKGROUND_COLOR: theme.base00,
|
|
|
|
TEXT_COLOR: theme.base07,
|
|
|
|
STRING_COLOR: theme.base0B,
|
|
|
|
DATE_COLOR: theme.base0B,
|
|
|
|
NUMBER_COLOR: theme.base09,
|
|
|
|
BOOLEAN_COLOR: theme.base09,
|
|
|
|
NULL_COLOR: theme.base08,
|
|
|
|
UNDEFINED_COLOR: theme.base08,
|
|
|
|
FUNCTION_COLOR: theme.base08,
|
|
|
|
SYMBOL_COLOR: theme.base08,
|
|
|
|
LABEL_COLOR: theme.base0D,
|
|
|
|
ARROW_COLOR: theme.base0D,
|
|
|
|
ITEM_STRING_COLOR: theme.base0B,
|
2020-08-08 23:26:39 +03:00
|
|
|
ITEM_STRING_EXPANDED_COLOR: theme.base03,
|
2018-12-21 22:18:05 +03:00
|
|
|
});
|
|
|
|
|
2020-08-22 03:13:24 +03:00
|
|
|
type Color = keyof ReturnType<typeof colorMap>;
|
|
|
|
type Colors = {
|
|
|
|
[color in Color]: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const valueColorMap = (colors: Colors) => ({
|
2018-12-21 22:18:05 +03:00
|
|
|
String: colors.STRING_COLOR,
|
|
|
|
Date: colors.DATE_COLOR,
|
|
|
|
Number: colors.NUMBER_COLOR,
|
|
|
|
Boolean: colors.BOOLEAN_COLOR,
|
|
|
|
Null: colors.NULL_COLOR,
|
|
|
|
Undefined: colors.UNDEFINED_COLOR,
|
|
|
|
Function: colors.FUNCTION_COLOR,
|
2020-08-08 23:26:39 +03:00
|
|
|
Symbol: colors.SYMBOL_COLOR,
|
2018-12-21 22:18:05 +03:00
|
|
|
});
|
|
|
|
|
2020-08-22 03:13:24 +03:00
|
|
|
const getDefaultThemeStyling = (theme: Base16Theme): StylingConfig => {
|
2018-12-21 22:18:05 +03:00
|
|
|
const colors = colorMap(theme);
|
|
|
|
|
|
|
|
return {
|
|
|
|
tree: {
|
|
|
|
border: 0,
|
|
|
|
padding: 0,
|
|
|
|
marginTop: '0.5em',
|
|
|
|
marginBottom: '0.5em',
|
|
|
|
marginLeft: '0.125em',
|
|
|
|
marginRight: 0,
|
|
|
|
listStyle: 'none',
|
|
|
|
MozUserSelect: 'none',
|
|
|
|
WebkitUserSelect: 'none',
|
2020-08-08 23:26:39 +03:00
|
|
|
backgroundColor: colors.BACKGROUND_COLOR,
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
2021-10-21 22:08:35 +03:00
|
|
|
value: ({ style }, nodeType, keyPath) => ({
|
2018-12-21 22:18:05 +03:00
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
paddingTop: '0.25em',
|
|
|
|
paddingRight: 0,
|
|
|
|
marginLeft: '0.875em',
|
|
|
|
WebkitUserSelect: 'text',
|
|
|
|
MozUserSelect: 'text',
|
|
|
|
wordWrap: 'break-word',
|
2021-10-21 22:08:35 +03:00
|
|
|
paddingLeft: (keyPath as unknown[]).length > 1 ? '2.125em' : '1.25em',
|
2018-12-21 22:18:05 +03:00
|
|
|
textIndent: '-0.5em',
|
2020-08-08 23:26:39 +03:00
|
|
|
wordBreak: 'break-all',
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
label: {
|
|
|
|
display: 'inline-block',
|
2020-08-08 23:26:39 +03:00
|
|
|
color: colors.LABEL_COLOR,
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
valueLabel: {
|
2020-08-08 23:26:39 +03:00
|
|
|
margin: '0 0.5em 0 0',
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
valueText: ({ style }, nodeType) => ({
|
|
|
|
style: {
|
|
|
|
...style,
|
2021-06-18 06:56:36 +03:00
|
|
|
color:
|
|
|
|
valueColorMap(colors)[
|
|
|
|
nodeType as keyof ReturnType<typeof valueColorMap>
|
|
|
|
],
|
2020-08-08 23:26:39 +03:00
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
itemRange: (styling, expanded) => ({
|
|
|
|
style: {
|
|
|
|
paddingTop: expanded ? 0 : '0.25em',
|
|
|
|
cursor: 'pointer',
|
2020-08-08 23:26:39 +03:00
|
|
|
color: colors.LABEL_COLOR,
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
arrow: ({ style }, nodeType, expanded) => ({
|
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
marginLeft: 0,
|
|
|
|
transition: '150ms',
|
|
|
|
WebkitTransition: '150ms',
|
|
|
|
MozTransition: '150ms',
|
|
|
|
WebkitTransform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
|
|
|
|
MozTransform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
|
|
|
|
transform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
|
|
|
|
transformOrigin: '45% 50%',
|
|
|
|
WebkitTransformOrigin: '45% 50%',
|
|
|
|
MozTransformOrigin: '45% 50%',
|
|
|
|
position: 'relative',
|
|
|
|
lineHeight: '1.1em',
|
2020-08-08 23:26:39 +03:00
|
|
|
fontSize: '0.75em',
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
arrowContainer: ({ style }, arrowStyle) => ({
|
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
display: 'inline-block',
|
|
|
|
paddingRight: '0.5em',
|
|
|
|
paddingLeft: arrowStyle === 'double' ? '1em' : 0,
|
2020-08-08 23:26:39 +03:00
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
arrowSign: {
|
2020-08-08 23:26:39 +03:00
|
|
|
color: colors.ARROW_COLOR,
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
arrowSignInner: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
2020-08-08 23:26:39 +03:00
|
|
|
left: '-0.4em',
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
2021-10-21 22:08:35 +03:00
|
|
|
nestedNode: ({ style }, keyPath, nodeType, expanded, expandable) => ({
|
2018-12-21 22:18:05 +03:00
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
position: 'relative',
|
|
|
|
paddingTop: '0.25em',
|
2021-10-21 22:08:35 +03:00
|
|
|
marginLeft: (keyPath as unknown[]).length > 1 ? '0.875em' : 0,
|
2020-08-08 23:26:39 +03:00
|
|
|
paddingLeft: !expandable ? '1.125em' : 0,
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
rootNode: {
|
|
|
|
padding: 0,
|
2020-08-08 23:26:39 +03:00
|
|
|
margin: 0,
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
nestedNodeLabel: ({ style }, keyPath, nodeType, expanded, expandable) => ({
|
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
WebkitUserSelect: expandable ? 'inherit' : 'text',
|
|
|
|
MozUserSelect: expandable ? 'inherit' : 'text',
|
2020-08-08 23:26:39 +03:00
|
|
|
cursor: expandable ? 'pointer' : 'default',
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
nestedNodeItemString: ({ style }, keyPath, nodeType, expanded) => ({
|
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
paddingLeft: '0.5em',
|
|
|
|
cursor: 'default',
|
|
|
|
color: expanded
|
|
|
|
? colors.ITEM_STRING_EXPANDED_COLOR
|
2020-08-08 23:26:39 +03:00
|
|
|
: colors.ITEM_STRING_COLOR,
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
nestedNodeItemType: {
|
|
|
|
marginLeft: '0.3em',
|
2020-08-08 23:26:39 +03:00
|
|
|
marginRight: '0.3em',
|
2018-12-21 22:18:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
nestedNodeChildren: ({ style }, nodeType, expanded) => ({
|
|
|
|
style: {
|
|
|
|
...style,
|
|
|
|
padding: 0,
|
|
|
|
margin: 0,
|
|
|
|
listStyle: 'none',
|
2020-08-08 23:26:39 +03:00
|
|
|
display: expanded ? 'block' : 'none',
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
rootNodeChildren: {
|
|
|
|
padding: 0,
|
|
|
|
margin: 0,
|
2020-08-08 23:26:39 +03:00
|
|
|
listStyle: 'none',
|
|
|
|
},
|
2018-12-21 22:18:05 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-08 16:49:09 +03:00
|
|
|
const createStylingFromTheme: CurriedFunction1<
|
|
|
|
Theme | undefined,
|
|
|
|
StylingFunction
|
|
|
|
> = createStyling(getDefaultThemeStyling, {
|
2020-08-08 23:26:39 +03:00
|
|
|
defaultBase16: solarized,
|
2018-12-21 22:18:05 +03:00
|
|
|
});
|
2022-05-08 16:49:09 +03:00
|
|
|
|
|
|
|
export default createStylingFromTheme;
|