@redvars/peacock 3.15.0 → 3.17.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/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.js +19 -19
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/card-content.js +8 -7
- package/dist/card-content.js.map +1 -1
- package/dist/card.js +142 -98
- package/dist/card.js.map +1 -1
- package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
- package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
- package/dist/chart-area.js +78 -0
- package/dist/chart-area.js.map +1 -0
- package/dist/chart-bar.js +283 -213
- package/dist/chart-bar.js.map +1 -1
- package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
- package/dist/chart-base-C2qRMF48.js.map +1 -0
- package/dist/chart-doughnut.js +55 -287
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +626 -0
- package/dist/chart-line.js.map +1 -0
- package/dist/chart-pie.js +637 -195
- package/dist/chart-pie.js.map +1 -1
- package/dist/code-editor.js +704 -131
- package/dist/code-editor.js.map +1 -1
- package/dist/code-group.js +188 -0
- package/dist/code-group.js.map +1 -0
- package/dist/code-highlighter.js +895 -257
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +2278 -677
- package/dist/custom-elements.json +13962 -3690
- package/dist/image.js +5 -1
- package/dist/image.js.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/loader-full.js +1 -1
- package/dist/loader.js +9 -3
- package/dist/loader.js.map +1 -1
- package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
- package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
- package/dist/pagination.js +408 -110
- package/dist/pagination.js.map +1 -1
- package/dist/path-CJ0Arqcy.js +166 -0
- package/dist/path-CJ0Arqcy.js.map +1 -0
- package/dist/snackbar.js +89 -34
- package/dist/snackbar.js.map +1 -1
- package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
- package/dist/src/__internal/chart/chart-base.d.ts +113 -0
- package/dist/src/__internal/chart/paths.d.ts +5 -0
- package/dist/src/__internal/chart/types.d.ts +42 -0
- package/dist/src/card/card-content.d.ts +2 -3
- package/dist/src/card/card.d.ts +31 -17
- package/dist/src/chart-area/chart-area.d.ts +54 -0
- package/dist/src/chart-area/index.d.ts +1 -0
- package/dist/src/chart-bar/chart-bar.d.ts +44 -33
- package/dist/src/chart-bar/index.d.ts +0 -1
- package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
- package/dist/src/chart-line/chart-line.d.ts +69 -0
- package/dist/src/chart-line/index.d.ts +1 -0
- package/dist/src/chart-pie/chart-pie.d.ts +63 -28
- package/dist/src/code-editor/code-editor.d.ts +52 -13
- package/dist/src/code-editor/editor-theme.d.ts +60 -0
- package/dist/src/code-highlighter/code-group.d.ts +52 -0
- package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
- package/dist/src/code-highlighter/index.d.ts +1 -0
- package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
- package/dist/src/code-highlighter/local.d.ts +4 -1
- package/dist/src/code-highlighter/token-colors.d.ts +8 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/pagination/page-items.d.ts +14 -0
- package/dist/src/pagination/pagination.d.ts +46 -7
- package/dist/src/snackbar/snackbar.d.ts +13 -1
- package/dist/src/table/table.d.ts +125 -27
- package/dist/src/toolbar/toolbar.d.ts +56 -51
- package/dist/table.js +1007 -338
- package/dist/table.js.map +1 -1
- package/dist/test/chart.test.d.ts +1 -0
- package/dist/test/code-highlighter.test.d.ts +1 -0
- package/dist/test/pagination.test.d.ts +1 -0
- package/dist/test/table.test.d.ts +1 -0
- package/dist/token-colors-0TFHWbcq.js +81 -0
- package/dist/token-colors-0TFHWbcq.js.map +1 -0
- package/dist/toolbar.js +195 -184
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/readme.md +7 -6
- package/scss/_code-block.scss +139 -0
- package/scss/tokens.css +24 -0
- package/src/__internal/chart/cartesian-chart.ts +404 -0
- package/src/__internal/chart/chart-base.scss +252 -0
- package/src/__internal/chart/chart-base.ts +474 -0
- package/src/__internal/chart/paths.ts +28 -0
- package/src/__internal/chart/types.ts +49 -0
- package/src/card/card-content.ts +12 -9
- package/src/card/card.scss +66 -54
- package/src/card/card.ts +109 -73
- package/src/chart-area/chart-area.ts +82 -0
- package/src/chart-area/index.ts +1 -0
- package/src/chart-bar/chart-bar.ts +336 -250
- package/src/chart-bar/index.ts +0 -1
- package/src/chart-doughnut/chart-doughnut.ts +62 -262
- package/src/chart-doughnut/demo/index.html +14 -22
- package/src/chart-line/chart-line.scss +25 -0
- package/src/chart-line/chart-line.ts +346 -0
- package/src/chart-line/index.ts +1 -0
- package/src/chart-pie/chart-pie.scss +35 -16
- package/src/chart-pie/chart-pie.ts +282 -188
- package/src/chart-pie/demo/index.html +13 -21
- package/src/code-editor/code-editor.scss +132 -36
- package/src/code-editor/code-editor.ts +308 -88
- package/src/code-editor/demo/index.html +39 -12
- package/src/code-editor/editor-theme.ts +213 -0
- package/src/code-highlighter/code-group.scss +34 -0
- package/src/code-highlighter/code-group.ts +173 -0
- package/src/code-highlighter/code-highlighter.scss +226 -111
- package/src/code-highlighter/code-highlighter.ts +554 -199
- package/src/code-highlighter/demo/index.html +68 -4
- package/src/code-highlighter/index.ts +1 -0
- package/src/code-highlighter/line-ranges.ts +81 -0
- package/src/code-highlighter/local.ts +9 -3
- package/src/code-highlighter/token-colors.ts +42 -0
- package/src/index.ts +4 -2
- package/src/loader.ts +8 -2
- package/src/pagination/page-items.ts +50 -0
- package/src/pagination/pagination.scss +159 -44
- package/src/pagination/pagination.ts +275 -74
- package/src/snackbar/demo/index.html +39 -4
- package/src/snackbar/snackbar.scss +27 -10
- package/src/snackbar/snackbar.ts +80 -37
- package/src/table/table.scss +337 -109
- package/src/table/table.ts +812 -272
- package/src/toolbar/toolbar-colors.scss +6 -7
- package/src/toolbar/toolbar.scss +35 -106
- package/src/toolbar/toolbar.ts +180 -80
- package/dist/array-D5vjT2Xm.js +0 -14
- package/dist/array-D5vjT2Xm.js.map +0 -1
- package/dist/chart-bar-D5dGFJfK.js.map +0 -1
- package/dist/chart-stacked-bar.js +0 -403
- package/dist/chart-stacked-bar.js.map +0 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
- package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
- package/dist/pie-Dz0IDiPt.js +0 -537
- package/dist/pie-Dz0IDiPt.js.map +0 -1
- package/dist/pierre-dark-DFWl0m-C.js +0 -4
- package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
- package/dist/pierre-light-BEkAPImt.js +0 -4
- package/dist/pierre-light-BEkAPImt.js.map +0 -1
- package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
- package/dist/src/code-highlighter/constants.d.ts +0 -1
- package/dist/transform-DSwFSqzD.js.map +0 -1
- package/src/chart-bar/chart-bar.scss +0 -58
- package/src/chart-bar/chart-stacked-bar.ts +0 -398
- package/src/chart-doughnut/chart-donut.scss +0 -37
- package/src/code-highlighter/constants.ts +0 -117
- /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html lang="en-GB"
|
|
2
|
+
<html lang="en-GB">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta
|
|
@@ -14,29 +14,56 @@
|
|
|
14
14
|
|
|
15
15
|
<style>
|
|
16
16
|
body {
|
|
17
|
+
display: grid;
|
|
18
|
+
gap: 1.5rem;
|
|
19
|
+
max-width: 48rem;
|
|
20
|
+
margin: 2rem auto;
|
|
21
|
+
padding: 0 1rem;
|
|
17
22
|
background: var(--color-surface);
|
|
23
|
+
color: var(--color-on-surface);
|
|
18
24
|
}
|
|
19
25
|
</style>
|
|
20
26
|
</head>
|
|
21
27
|
<body>
|
|
22
|
-
<
|
|
23
|
-
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
onclick="document.documentElement.dataset.theme = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'"
|
|
31
|
+
>
|
|
32
|
+
Toggle dark theme
|
|
33
|
+
</button>
|
|
34
|
+
|
|
35
|
+
<wc-code-editor
|
|
24
36
|
id="business-rule-editor"
|
|
37
|
+
label="business-rule.js"
|
|
25
38
|
language="javascript"
|
|
26
|
-
|
|
39
|
+
wrap-toggle
|
|
40
|
+
>
|
|
41
|
+
<wc-icon slot="icon" name="description"></wc-icon>
|
|
42
|
+
</wc-code-editor>
|
|
43
|
+
|
|
44
|
+
<wc-code-editor
|
|
45
|
+
id="read-only-editor"
|
|
46
|
+
language="css"
|
|
47
|
+
readonly
|
|
48
|
+
show-readonly-badge
|
|
49
|
+
style="--code-editor-height: 8rem"
|
|
50
|
+
></wc-code-editor>
|
|
27
51
|
|
|
28
52
|
<script type="module">
|
|
29
53
|
import '/dist/loader.js';
|
|
30
54
|
|
|
31
55
|
document.getElementById('business-rule-editor').value = `/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
* Sample Code
|
|
57
|
+
*/
|
|
58
|
+
function myBusinessRuleFunction() {
|
|
59
|
+
const a = 1;
|
|
60
|
+
const b = 2;
|
|
61
|
+
let c = a + b;
|
|
62
|
+
console.log(c);
|
|
63
|
+
}`;
|
|
64
|
+
document.getElementById('read-only-editor').value = `:root {
|
|
65
|
+
--color-primary: var(--color-primary-40);
|
|
66
|
+
}`;
|
|
40
67
|
</script>
|
|
41
68
|
</body>
|
|
42
69
|
</html>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { tokenColor } from '../code-highlighter/token-colors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The colors the editor theme is built from: Peacock color roles, plus the syntax colors
|
|
5
|
+
* wc-code-highlighter uses, so the two show code alike. Monaco takes hex colors only, so these
|
|
6
|
+
* are resolved on the page and converted.
|
|
7
|
+
*/
|
|
8
|
+
export const PALETTE_SOURCES = {
|
|
9
|
+
surface: 'var(--color-surface)',
|
|
10
|
+
surfaceContainerHigh: 'var(--color-surface-container-high)',
|
|
11
|
+
surfaceContainerHighest: 'var(--color-surface-container-highest)',
|
|
12
|
+
onSurface: 'var(--color-on-surface)',
|
|
13
|
+
onSurfaceVariant: 'var(--color-on-surface-variant)',
|
|
14
|
+
outline: 'var(--color-outline)',
|
|
15
|
+
outlineVariant: 'var(--color-outline-variant)',
|
|
16
|
+
primary: 'var(--color-primary)',
|
|
17
|
+
secondary: 'var(--color-secondary)',
|
|
18
|
+
tertiary: 'var(--color-tertiary)',
|
|
19
|
+
secondaryContainer: 'var(--color-secondary-container)',
|
|
20
|
+
onSecondaryContainer: 'var(--color-on-secondary-container)',
|
|
21
|
+
error: 'var(--color-error)',
|
|
22
|
+
warning: 'var(--color-warning)',
|
|
23
|
+
info: 'var(--color-blue)',
|
|
24
|
+
foreground: tokenColor('foreground'),
|
|
25
|
+
keyword: tokenColor('token-keyword'),
|
|
26
|
+
string: tokenColor('token-string'),
|
|
27
|
+
func: tokenColor('token-function'),
|
|
28
|
+
constant: tokenColor('token-constant'),
|
|
29
|
+
comment: tokenColor('token-comment'),
|
|
30
|
+
punctuation: tokenColor('token-punctuation'),
|
|
31
|
+
parameter: tokenColor('token-parameter'),
|
|
32
|
+
link: tokenColor('token-link'),
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
export type EditorPalette = Record<keyof typeof PALETTE_SOURCES, string>;
|
|
36
|
+
|
|
37
|
+
/** Monaco's standalone theme data, as `monaco.editor.defineTheme` takes it. */
|
|
38
|
+
export type EditorThemeData = {
|
|
39
|
+
base: 'vs' | 'vs-dark';
|
|
40
|
+
inherit: boolean;
|
|
41
|
+
rules: { token: string; foreground?: string; fontStyle?: string }[];
|
|
42
|
+
colors: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let context: CanvasRenderingContext2D | null | undefined;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Converts any CSS color the browser understands (`rgb()`, `oklch()`, `color()`, …) to
|
|
49
|
+
* `#rrggbb`, or `#rrggbbaa` when it is not opaque, by painting one pixel.
|
|
50
|
+
*/
|
|
51
|
+
export function cssColorToHex(color: string): string {
|
|
52
|
+
context ??= document
|
|
53
|
+
.createElement('canvas')
|
|
54
|
+
.getContext('2d', { willReadFrequently: true });
|
|
55
|
+
if (!context) return '#000000';
|
|
56
|
+
context.clearRect(0, 0, 1, 1);
|
|
57
|
+
context.fillStyle = '#000000';
|
|
58
|
+
context.fillStyle = color;
|
|
59
|
+
context.fillRect(0, 0, 1, 1);
|
|
60
|
+
const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data;
|
|
61
|
+
const hex = [r, g, b, ...(a < 255 ? [a] : [])]
|
|
62
|
+
.map(value => value.toString(16).padStart(2, '0'))
|
|
63
|
+
.join('');
|
|
64
|
+
return `#${hex}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolves the palette where `probe` sits, so it follows the theme around the editor:
|
|
69
|
+
* `data-theme`, the system color scheme, or a custom theme.
|
|
70
|
+
*/
|
|
71
|
+
export function resolvePalette(probe: HTMLElement): EditorPalette {
|
|
72
|
+
const palette = {} as EditorPalette;
|
|
73
|
+
for (const [key, value] of Object.entries(PALETTE_SOURCES)) {
|
|
74
|
+
// eslint-disable-next-line no-param-reassign
|
|
75
|
+
probe.style.color = value;
|
|
76
|
+
palette[key as keyof EditorPalette] = cssColorToHex(
|
|
77
|
+
getComputedStyle(probe).color,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
// eslint-disable-next-line no-param-reassign
|
|
81
|
+
probe.style.color = '';
|
|
82
|
+
return palette;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** `#rrggbb` with an alpha from 0 to 1. */
|
|
86
|
+
function alpha(hex: string, opacity: number): string {
|
|
87
|
+
const value = Math.round(Math.min(1, Math.max(0, opacity)) * 255);
|
|
88
|
+
return `${hex.slice(0, 7)}${value.toString(16).padStart(2, '0')}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Whether a `#rrggbb` color is dark, by relative luminance. */
|
|
92
|
+
export function isDark(hex: string): boolean {
|
|
93
|
+
const [r, g, b] = [1, 3, 5].map(index => {
|
|
94
|
+
const channel = parseInt(hex.slice(index, index + 2), 16) / 255;
|
|
95
|
+
return channel <= 0.04045
|
|
96
|
+
? channel / 12.92
|
|
97
|
+
: ((channel + 0.055) / 1.055) ** 2.4;
|
|
98
|
+
});
|
|
99
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b < 0.18;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Monaco rules take colors without the `#`. */
|
|
103
|
+
const bare = (hex: string) => hex.slice(1, 7);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Builds the editor theme from a palette. The editor background is transparent, so the frame
|
|
107
|
+
* around it shows through; widgets such as suggestions and hovers sit on surface containers.
|
|
108
|
+
*/
|
|
109
|
+
export function buildEditorTheme(p: EditorPalette): EditorThemeData {
|
|
110
|
+
return {
|
|
111
|
+
base: isDark(p.surface) ? 'vs-dark' : 'vs',
|
|
112
|
+
// Not inherited: Monaco's own rules are more specific than these (`string.value.json`,
|
|
113
|
+
// `keyword.flow`, …) and would keep its stock colors.
|
|
114
|
+
inherit: false,
|
|
115
|
+
rules: [
|
|
116
|
+
{ token: '', foreground: bare(p.foreground) },
|
|
117
|
+
{ token: 'comment', foreground: bare(p.comment), fontStyle: 'italic' },
|
|
118
|
+
{ token: 'keyword', foreground: bare(p.keyword) },
|
|
119
|
+
{ token: 'string', foreground: bare(p.string) },
|
|
120
|
+
{ token: 'string.escape', foreground: bare(p.constant) },
|
|
121
|
+
{ token: 'string.key.json', foreground: bare(p.keyword) },
|
|
122
|
+
{ token: 'string.link', foreground: bare(p.link) },
|
|
123
|
+
{ token: 'number', foreground: bare(p.constant) },
|
|
124
|
+
{ token: 'constant', foreground: bare(p.constant) },
|
|
125
|
+
{ token: 'regexp', foreground: bare(p.string) },
|
|
126
|
+
{ token: 'type', foreground: bare(p.func) },
|
|
127
|
+
{ token: 'identifier', foreground: bare(p.foreground) },
|
|
128
|
+
{ token: 'variable', foreground: bare(p.parameter) },
|
|
129
|
+
{ token: 'predefined', foreground: bare(p.func) },
|
|
130
|
+
{ token: 'annotation', foreground: bare(p.func) },
|
|
131
|
+
{ token: 'delimiter', foreground: bare(p.punctuation) },
|
|
132
|
+
{ token: 'operator', foreground: bare(p.punctuation) },
|
|
133
|
+
{ token: 'tag', foreground: bare(p.string) },
|
|
134
|
+
{ token: 'metatag', foreground: bare(p.keyword) },
|
|
135
|
+
{ token: 'attribute.name', foreground: bare(p.func) },
|
|
136
|
+
{ token: 'attribute.value', foreground: bare(p.string) },
|
|
137
|
+
{ token: 'tag.css', foreground: bare(p.func) },
|
|
138
|
+
{ token: 'attribute.name.css', foreground: bare(p.constant) },
|
|
139
|
+
{ token: 'attribute.value.css', foreground: bare(p.foreground) },
|
|
140
|
+
{ token: 'attribute.value.number.css', foreground: bare(p.constant) },
|
|
141
|
+
{ token: 'attribute.value.unit.css', foreground: bare(p.constant) },
|
|
142
|
+
{ token: 'attribute.value.hex.css', foreground: bare(p.constant) },
|
|
143
|
+
{ token: 'strong', fontStyle: 'bold' },
|
|
144
|
+
{ token: 'emphasis', fontStyle: 'italic' },
|
|
145
|
+
{ token: 'keyword.json', foreground: bare(p.constant) },
|
|
146
|
+
{ token: 'invalid', foreground: bare(p.error) },
|
|
147
|
+
],
|
|
148
|
+
colors: {
|
|
149
|
+
foreground: p.onSurface,
|
|
150
|
+
focusBorder: p.primary,
|
|
151
|
+
'editor.background': '#00000000',
|
|
152
|
+
'editor.foreground': p.foreground,
|
|
153
|
+
'editorGutter.background': '#00000000',
|
|
154
|
+
'editorLineNumber.foreground': p.onSurfaceVariant,
|
|
155
|
+
'editorLineNumber.activeForeground': p.onSurface,
|
|
156
|
+
'editor.lineHighlightBackground': alpha(p.onSurface, 0.05),
|
|
157
|
+
'editor.lineHighlightBorder': '#00000000',
|
|
158
|
+
'editorCursor.foreground': p.primary,
|
|
159
|
+
'editor.selectionBackground': alpha(p.primary, 0.24),
|
|
160
|
+
'editor.inactiveSelectionBackground': alpha(p.primary, 0.12),
|
|
161
|
+
'editor.selectionHighlightBackground': alpha(p.primary, 0.12),
|
|
162
|
+
'editor.wordHighlightBackground': alpha(p.primary, 0.1),
|
|
163
|
+
'editor.wordHighlightStrongBackground': alpha(p.primary, 0.16),
|
|
164
|
+
'editor.findMatchBackground': alpha(p.warning, 0.4),
|
|
165
|
+
'editor.findMatchHighlightBackground': alpha(p.warning, 0.2),
|
|
166
|
+
'editorBracketMatch.background': alpha(p.primary, 0.12),
|
|
167
|
+
'editorBracketMatch.border': alpha(p.primary, 0.5),
|
|
168
|
+
'editorIndentGuide.background1': alpha(p.outlineVariant, 0.6),
|
|
169
|
+
'editorIndentGuide.activeBackground1': p.outline,
|
|
170
|
+
'editorWhitespace.foreground': p.outlineVariant,
|
|
171
|
+
'editorError.foreground': p.error,
|
|
172
|
+
'editorWarning.foreground': p.warning,
|
|
173
|
+
'editorInfo.foreground': p.info,
|
|
174
|
+
'editorOverviewRuler.border': '#00000000',
|
|
175
|
+
'editorOverviewRuler.errorForeground': p.error,
|
|
176
|
+
'editorOverviewRuler.warningForeground': p.warning,
|
|
177
|
+
'editorWidget.background': p.surfaceContainerHigh,
|
|
178
|
+
'editorWidget.foreground': p.onSurface,
|
|
179
|
+
'editorWidget.border': p.outlineVariant,
|
|
180
|
+
'editorSuggestWidget.background': p.surfaceContainerHigh,
|
|
181
|
+
'editorSuggestWidget.border': p.outlineVariant,
|
|
182
|
+
'editorSuggestWidget.foreground': p.onSurface,
|
|
183
|
+
'editorSuggestWidget.highlightForeground': p.primary,
|
|
184
|
+
'editorSuggestWidget.selectedBackground': p.secondaryContainer,
|
|
185
|
+
'editorSuggestWidget.selectedForeground': p.onSecondaryContainer,
|
|
186
|
+
'editorHoverWidget.background': p.surfaceContainerHigh,
|
|
187
|
+
'editorHoverWidget.foreground': p.onSurface,
|
|
188
|
+
'editorHoverWidget.border': p.outlineVariant,
|
|
189
|
+
'input.background': p.surfaceContainerHighest,
|
|
190
|
+
'input.foreground': p.onSurface,
|
|
191
|
+
'input.border': p.outlineVariant,
|
|
192
|
+
'inputOption.activeBorder': p.primary,
|
|
193
|
+
'list.hoverBackground': alpha(p.onSurface, 0.08),
|
|
194
|
+
'list.activeSelectionBackground': p.secondaryContainer,
|
|
195
|
+
'list.activeSelectionForeground': p.onSecondaryContainer,
|
|
196
|
+
'list.highlightForeground': p.primary,
|
|
197
|
+
'scrollbar.shadow': '#00000000',
|
|
198
|
+
'scrollbarSlider.background': alpha(p.onSurface, 0.16),
|
|
199
|
+
'scrollbarSlider.hoverBackground': alpha(p.onSurface, 0.28),
|
|
200
|
+
'scrollbarSlider.activeBackground': alpha(p.onSurface, 0.38),
|
|
201
|
+
'minimap.background': '#00000000',
|
|
202
|
+
'widget.shadow': alpha('#000000', 0.2),
|
|
203
|
+
// Bracket pairs cycle through the theme's accent roles.
|
|
204
|
+
'editorBracketHighlight.foreground1': p.primary,
|
|
205
|
+
'editorBracketHighlight.foreground2': p.tertiary,
|
|
206
|
+
'editorBracketHighlight.foreground3': p.secondary,
|
|
207
|
+
'editorBracketHighlight.foreground4': p.primary,
|
|
208
|
+
'editorBracketHighlight.foreground5': p.tertiary,
|
|
209
|
+
'editorBracketHighlight.foreground6': p.secondary,
|
|
210
|
+
'editorBracketHighlight.unexpectedBracket.foreground': p.error,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@use '../../scss/mixin';
|
|
2
|
+
|
|
3
|
+
@include mixin.base-styles;
|
|
4
|
+
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
min-width: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// The group draws the frame the blocks would otherwise draw, with the same
|
|
11
|
+
// public custom properties, so a themed block and a themed group match.
|
|
12
|
+
.code-group {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
min-width: 0;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
background: var(
|
|
18
|
+
--code-highlighter-background,
|
|
19
|
+
var(--color-surface-container-low)
|
|
20
|
+
);
|
|
21
|
+
border: 1px solid
|
|
22
|
+
var(--code-highlighter-border-color, var(--color-outline-variant));
|
|
23
|
+
border-radius: var(--code-highlighter-shape, var(--shape-corner-medium));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.header {
|
|
27
|
+
min-width: 0;
|
|
28
|
+
overflow-x: auto;
|
|
29
|
+
scrollbar-width: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
::slotted([hidden]) {
|
|
33
|
+
display: none !important;
|
|
34
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { html, LitElement } from 'lit';
|
|
2
|
+
import { property, state } from 'lit/decorators.js';
|
|
3
|
+
import IndividualComponent from '@/IndividualComponent.js';
|
|
4
|
+
import styles from './code-group.scss';
|
|
5
|
+
|
|
6
|
+
/** Minimal shape of a grouped `wc-code-highlighter`. */
|
|
7
|
+
type CodeBlockElement = HTMLElement & { label?: string; language?: string };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @label Code Group
|
|
11
|
+
* @tag wc-code-group
|
|
12
|
+
* @rawTag code-group
|
|
13
|
+
*
|
|
14
|
+
* @summary Shows several code blocks in one frame, with a tab for each block.
|
|
15
|
+
* @overview
|
|
16
|
+
* <p>Put <code>wc-code-highlighter</code> elements inside. Each block's <code>label</code> names its tab,
|
|
17
|
+
* and only the selected block is shown. The group draws the frame, so the blocks drop their own
|
|
18
|
+
* border and header, and their actions float at the top end.</p>
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```html
|
|
22
|
+
* <wc-code-group>
|
|
23
|
+
* <wc-code-highlighter label="greeting.ts" language="typescript"><pre><code>
|
|
24
|
+
* export const greeting = 'Hello';</code></pre></wc-code-highlighter>
|
|
25
|
+
* <wc-code-highlighter label="greeting.css" language="css"><pre><code>
|
|
26
|
+
* p { color: var(--color-primary); }</code></pre></wc-code-highlighter>
|
|
27
|
+
* </wc-code-group>
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @slot - `wc-code-highlighter` elements, one per tab.
|
|
31
|
+
*
|
|
32
|
+
* @csspart container - The outer frame.
|
|
33
|
+
* @csspart header - The tab bar.
|
|
34
|
+
*
|
|
35
|
+
* @fires {CustomEvent<{index: number}>} change - Dispatched when the user selects another tab.
|
|
36
|
+
*
|
|
37
|
+
* @tags display
|
|
38
|
+
*/
|
|
39
|
+
@IndividualComponent
|
|
40
|
+
export class CodeGroup extends LitElement {
|
|
41
|
+
// ── Static ────────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
static styles = [styles];
|
|
44
|
+
|
|
45
|
+
// ── Properties ────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
/** Index of the shown block. */
|
|
48
|
+
@property({ attribute: 'selected-index', type: Number, reflect: true })
|
|
49
|
+
selectedIndex: number = 0;
|
|
50
|
+
|
|
51
|
+
/** The grouped code blocks, in slot order. */
|
|
52
|
+
@state() private _blocks: CodeBlockElement[] = [];
|
|
53
|
+
|
|
54
|
+
// ── Private fields ────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
/** Re-renders the tabs when a block's label changes. */
|
|
57
|
+
private __labelObserver?: MutationObserver;
|
|
58
|
+
|
|
59
|
+
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
connectedCallback() {
|
|
62
|
+
super.connectedCallback();
|
|
63
|
+
this.__labelObserver = new MutationObserver(() => this.requestUpdate());
|
|
64
|
+
this.__labelObserver.observe(this, {
|
|
65
|
+
subtree: true,
|
|
66
|
+
attributes: true,
|
|
67
|
+
attributeFilter: ['label', 'language'],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
disconnectedCallback() {
|
|
72
|
+
this.__labelObserver?.disconnect();
|
|
73
|
+
super.disconnectedCallback();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected updated(changed: Map<PropertyKey, unknown>) {
|
|
77
|
+
if (changed.has('selectedIndex') || changed.has('_blocks')) {
|
|
78
|
+
this.__syncBlocks();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── Private methods ───────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
/** The selected index, kept within the blocks. */
|
|
85
|
+
private get __activeIndex(): number {
|
|
86
|
+
const last = this._blocks.length - 1;
|
|
87
|
+
return Math.min(Math.max(0, this.selectedIndex || 0), Math.max(0, last));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Marks every block as grouped and shows only the selected one. */
|
|
91
|
+
private __syncBlocks() {
|
|
92
|
+
const active = this.__activeIndex;
|
|
93
|
+
this._blocks.forEach((block, index) => {
|
|
94
|
+
block.setAttribute('grouped', '');
|
|
95
|
+
block.toggleAttribute('hidden', index !== active);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private __handleSlotChange(event: Event) {
|
|
100
|
+
const slot = event.target as HTMLSlotElement;
|
|
101
|
+
const blocks = slot
|
|
102
|
+
.assignedElements({ flatten: true })
|
|
103
|
+
.filter(
|
|
104
|
+
element => element.localName === 'wc-code-highlighter',
|
|
105
|
+
) as CodeBlockElement[];
|
|
106
|
+
|
|
107
|
+
// Blocks moved out of the group get their own frame back.
|
|
108
|
+
for (const block of this._blocks) {
|
|
109
|
+
if (!blocks.includes(block)) {
|
|
110
|
+
block.removeAttribute('grouped');
|
|
111
|
+
block.removeAttribute('hidden');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
this._blocks = blocks;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private __handleTabChange(event: CustomEvent<{ index: number }>) {
|
|
118
|
+
event.stopPropagation();
|
|
119
|
+
const { index } = event.detail;
|
|
120
|
+
if (index < 0 || index === this.__activeIndex) return;
|
|
121
|
+
this.selectedIndex = index;
|
|
122
|
+
this.dispatchEvent(
|
|
123
|
+
new CustomEvent('change', {
|
|
124
|
+
detail: { index },
|
|
125
|
+
bubbles: true,
|
|
126
|
+
composed: true,
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// eslint-disable-next-line class-methods-use-this
|
|
132
|
+
private __stopEvent(event: Event) {
|
|
133
|
+
event.stopPropagation();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ── Render helpers ────────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line class-methods-use-this
|
|
139
|
+
private __tabLabel(block: CodeBlockElement, index: number): string {
|
|
140
|
+
return (
|
|
141
|
+
block.label ||
|
|
142
|
+
block.getAttribute('label') ||
|
|
143
|
+
block.language ||
|
|
144
|
+
`${index + 1}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ── Render ────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
render() {
|
|
151
|
+
const active = this.__activeIndex;
|
|
152
|
+
return html`
|
|
153
|
+
<div class="code-group" part="container">
|
|
154
|
+
<div class="header" part="header">
|
|
155
|
+
<wc-tabs
|
|
156
|
+
class="tabs"
|
|
157
|
+
variant="secondary"
|
|
158
|
+
@change=${this.__handleTabChange}
|
|
159
|
+
@tab-click=${this.__stopEvent}
|
|
160
|
+
>
|
|
161
|
+
${this._blocks.map(
|
|
162
|
+
(block, index) =>
|
|
163
|
+
html`<wc-tab .active=${index === active}
|
|
164
|
+
>${this.__tabLabel(block, index)}</wc-tab
|
|
165
|
+
>`,
|
|
166
|
+
)}
|
|
167
|
+
</wc-tabs>
|
|
168
|
+
</div>
|
|
169
|
+
<slot @slotchange=${this.__handleSlotChange}></slot>
|
|
170
|
+
</div>
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
}
|