@redvars/peacock 3.10.0 → 3.11.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/BaseInput-CV0pZgSb.js +58 -0
- package/dist/BaseInput-CV0pZgSb.js.map +1 -0
- package/dist/app-bar.js +16 -16
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.d.ts +66 -0
- package/dist/assets/theme.js +134 -0
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/base-progress-CLZTRveO.js +33 -0
- package/dist/base-progress-CLZTRveO.js.map +1 -0
- package/dist/bottom-sheet.js +1 -1
- package/dist/button-group.js +9 -7
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +225 -187
- package/dist/button.js.map +1 -1
- package/dist/{chart-bar-CapLbc2e.js → chart-bar-D5dGFJfK.js} +2 -2
- package/dist/{chart-bar-CapLbc2e.js.map → chart-bar-D5dGFJfK.js.map} +1 -1
- package/dist/chart-bar.js +1 -1
- package/dist/chart-stacked-bar.js +1 -1
- package/dist/checkbox.js +78 -53
- package/dist/checkbox.js.map +1 -1
- package/dist/chip-set.js +52 -0
- package/dist/chip-set.js.map +1 -0
- package/dist/chip.js +8 -6
- package/dist/chip.js.map +1 -1
- package/dist/circular-progress.js +177 -0
- package/dist/circular-progress.js.map +1 -0
- package/dist/code-editor.js +129 -72
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +2 -38
- package/dist/code-highlighter.js.map +1 -1
- package/dist/color-field.js +309 -0
- package/dist/color-field.js.map +1 -0
- package/dist/color-picker.js +26 -15
- package/dist/color-picker.js.map +1 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +39 -0
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +1 -0
- package/dist/custom-elements-jsdocs.json +1044 -382
- package/dist/custom-elements.json +8620 -4714
- package/dist/date-picker.js +241 -0
- package/dist/date-picker.js.map +1 -0
- package/dist/{element-internals-2CMts_0M.js → delegate-py-Ets8N.js} +2 -43
- package/dist/delegate-py-Ets8N.js.map +1 -0
- package/dist/element-internals-QME0yEz4.js +43 -0
- package/dist/element-internals-QME0yEz4.js.map +1 -0
- package/dist/fab.js +51 -49
- package/dist/fab.js.map +1 -1
- package/dist/field.js +34 -4
- package/dist/field.js.map +1 -1
- package/dist/flow.js +5 -5
- package/dist/form-associated-Bhwwr6dT.js +162 -0
- package/dist/form-associated-Bhwwr6dT.js.map +1 -0
- package/dist/{form-associated-BXADnjOB.js → form-submitter-DPI4L6gj.js} +3 -159
- package/dist/form-submitter-DPI4L6gj.js.map +1 -0
- package/dist/html-editor.js +3 -1
- package/dist/html-editor.js.map +1 -1
- package/dist/icon-button.js +195 -156
- package/dist/icon-button.js.map +1 -1
- package/dist/image.js +2 -2
- package/dist/index.js +32 -8
- package/dist/index.js.map +1 -1
- package/dist/input.js +259 -0
- package/dist/input.js.map +1 -0
- package/dist/item.js +2 -1
- package/dist/item.js.map +1 -1
- package/dist/linear-progress.js +192 -0
- package/dist/linear-progress.js.map +1 -0
- package/dist/{list-AdO-PUq_.js → list-item.js} +12 -222
- package/dist/list-item.js.map +1 -0
- package/dist/list.js +225 -6
- package/dist/list.js.map +1 -1
- package/dist/loader-full.js +31 -8
- package/dist/loader-full.js.map +1 -1
- package/dist/loader.js +52 -12
- package/dist/loader.js.map +1 -1
- package/dist/markdown-editor.js +5 -3
- package/dist/markdown-editor.js.map +1 -1
- package/dist/menu-item.js +30 -30
- package/dist/menu.js +1 -1
- package/dist/navigation-bar-item.js +41 -0
- package/dist/navigation-bar-item.js.map +1 -0
- package/dist/navigation-bar.js +128 -0
- package/dist/navigation-bar.js.map +1 -0
- package/dist/navigation-drawer-item.js +236 -0
- package/dist/navigation-drawer-item.js.map +1 -0
- package/dist/navigation-drawer.js +293 -0
- package/dist/navigation-drawer.js.map +1 -0
- package/dist/navigation-rail.js +1 -1
- package/dist/number-field.js +280 -0
- package/dist/number-field.js.map +1 -0
- package/dist/option.js +17 -0
- package/dist/option.js.map +1 -1
- package/dist/pagination.js +1 -1
- package/dist/radio-group.js +209 -0
- package/dist/radio-group.js.map +1 -0
- package/dist/radio.js +47 -37
- package/dist/radio.js.map +1 -1
- package/dist/segmented-button-group.js +12 -0
- package/dist/segmented-button-group.js.map +1 -1
- package/dist/segmented-button.js +10 -6
- package/dist/segmented-button.js.map +1 -1
- package/dist/select.js +653 -0
- package/dist/select.js.map +1 -0
- package/dist/side-sheet.js +1 -1
- package/dist/sidebar-menu-item.js +273 -0
- package/dist/sidebar-menu-item.js.map +1 -0
- package/dist/sidebar-menu.js +193 -0
- package/dist/sidebar-menu.js.map +1 -0
- package/dist/sidebar-sub-menu.js +301 -0
- package/dist/sidebar-sub-menu.js.map +1 -0
- package/dist/slider.js +76 -24
- package/dist/slider.js.map +1 -1
- package/dist/snackbar.js +3 -3
- package/dist/snackbar.js.map +1 -1
- package/dist/split-button.js +2 -2
- package/dist/src/__internal/utils/size.d.ts +9 -0
- package/dist/src/button/ButtonTypes.d.ts +1 -1
- package/dist/src/checkbox/checkbox.d.ts +28 -22
- package/dist/src/chip/chip/chip.d.ts +3 -0
- package/dist/src/chip/tag/tag.d.ts +5 -1
- package/dist/src/code-editor/code-editor.d.ts +37 -10
- package/dist/src/color-field/color-field.d.ts +55 -0
- package/dist/src/color-field/index.d.ts +1 -0
- package/dist/src/color-picker/color-picker.d.ts +1 -1
- package/dist/src/date-picker/date-picker.d.ts +0 -1
- package/dist/src/field/field.d.ts +2 -0
- package/dist/src/index.d.ts +4 -3
- package/dist/src/input/BaseInput.d.ts +21 -3
- package/dist/src/input/input.d.ts +15 -7
- package/dist/src/navigation-bar/index.d.ts +2 -0
- package/dist/src/navigation-bar/navigation-bar-item.d.ts +23 -0
- package/dist/src/navigation-bar/navigation-bar.d.ts +44 -0
- package/dist/src/navigation-drawer/index.d.ts +2 -0
- package/dist/src/navigation-drawer/navigation-drawer-item.d.ts +48 -0
- package/dist/src/navigation-drawer/navigation-drawer.d.ts +70 -0
- package/dist/src/number-field/number-field.d.ts +0 -1
- package/dist/src/radio/index.d.ts +1 -0
- package/dist/src/radio/radio-group.d.ts +50 -0
- package/dist/src/radio/radio.d.ts +18 -18
- package/dist/src/segmented-button/segmented-button-group.d.ts +5 -0
- package/dist/src/segmented-button/segmented-button.d.ts +2 -1
- package/dist/src/select/select.d.ts +7 -0
- package/dist/src/slider/slider.d.ts +14 -5
- package/dist/src/switch/switch.d.ts +22 -26
- package/dist/src/tabs/tabs.d.ts +3 -0
- package/dist/src/textarea/textarea.d.ts +0 -1
- package/dist/src/time-picker/time-picker.d.ts +0 -1
- package/dist/src/toolbar/toolbar.d.ts +7 -4
- package/dist/src/url-field/url-field.d.ts +0 -1
- package/dist/svg.js +5 -5
- package/dist/switch.js +413 -0
- package/dist/switch.js.map +1 -0
- package/dist/tab.js +2 -1
- package/dist/tab.js.map +1 -1
- package/dist/tabs.js +10 -8
- package/dist/tabs.js.map +1 -1
- package/dist/tag.js +349 -0
- package/dist/tag.js.map +1 -0
- package/dist/test/code-editor.test.d.ts +1 -0
- package/dist/test/color-field.test.d.ts +1 -0
- package/dist/test/color-picker.test.d.ts +1 -0
- package/dist/test/field.test.d.ts +1 -0
- package/dist/test/form-controls.test.d.ts +1 -0
- package/dist/test/icon.test.d.ts +1 -1
- package/dist/test/input.test.d.ts +1 -0
- package/dist/test/navigation.test.d.ts +1 -0
- package/dist/test/segmented-button.test.d.ts +1 -0
- package/dist/test/select.test.d.ts +1 -0
- package/dist/test/slider.test.d.ts +1 -0
- package/dist/textarea.js +237 -0
- package/dist/textarea.js.map +1 -0
- package/dist/time-picker.js +241 -0
- package/dist/time-picker.js.map +1 -0
- package/dist/toolbar.js +26 -9
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/url-field.js +298 -0
- package/dist/url-field.js.map +1 -0
- package/package.json +29 -8
- package/readme.md +2 -2
- package/scss/tokens.css +175 -18
- package/src/__internal/utils/size.ts +23 -0
- package/src/app-bar/app-bar.scss +4 -16
- package/src/bottom-sheet/bottom-sheet.scss +1 -1
- package/src/button/ButtonTypes.ts +2 -0
- package/src/button/button/button-base.scss +84 -84
- package/src/button/button/button-colors.scss +14 -2
- package/src/button/button/button-layers.scss +71 -71
- package/src/button/button/button-shapes.scss +2 -2
- package/src/button/button/button-sizes.scss +35 -35
- package/src/button/button/button.scss +1 -1
- package/src/button/button/button.ts +1 -2
- package/src/button/button-group/button-group.scss +5 -5
- package/src/button/fab/fab-sizes.scss +15 -15
- package/src/button/fab/fab.scss +32 -32
- package/src/button/icon-button/icon-button-sizes.scss +7 -7
- package/src/chart-bar/chart-bar.scss +1 -1
- package/src/checkbox/checkbox.scss +7 -6
- package/src/checkbox/checkbox.ts +92 -40
- package/src/chip/chip/chip.ts +8 -5
- package/src/chip/chip-set/chip-set.ts +2 -0
- package/src/chip/tag/tag-colors.scss +1 -1
- package/src/chip/tag/tag-sizes.scss +9 -0
- package/src/chip/tag/tag.scss +1 -1
- package/src/chip/tag/tag.ts +20 -9
- package/src/code-editor/code-editor.scss +8 -3
- package/src/code-editor/code-editor.ts +148 -79
- package/src/code-highlighter/code-highlighter.scss +1 -1
- package/src/color-field/color-field.scss +48 -0
- package/src/color-field/color-field.ts +239 -0
- package/src/color-field/index.ts +1 -0
- package/src/color-picker/color-picker.scss +33 -15
- package/src/color-picker/color-picker.ts +2 -1
- package/src/date-picker/date-picker.ts +2 -3
- package/src/field/field.scss +31 -0
- package/src/field/field.ts +5 -1
- package/src/flow/flow.scss +5 -5
- package/src/image/image.scss +2 -2
- package/src/index.ts +7 -3
- package/src/input/BaseInput.ts +54 -4
- package/src/input/input.ts +104 -79
- package/src/list/list-item.ts +2 -0
- package/src/loader.ts +28 -6
- package/src/markdown-editor/markdown-editor.scss +2 -2
- package/src/menu/menu/menu.scss +1 -1
- package/src/menu/menu-item/menu-item.scss +30 -30
- package/src/navigation-bar/index.ts +2 -0
- package/src/navigation-bar/navigation-bar-item.ts +25 -0
- package/src/navigation-bar/navigation-bar.scss +27 -0
- package/src/navigation-bar/navigation-bar.ts +96 -0
- package/src/navigation-drawer/index.ts +2 -0
- package/src/navigation-drawer/navigation-drawer-item.scss +82 -0
- package/src/navigation-drawer/navigation-drawer-item.ts +133 -0
- package/src/navigation-drawer/navigation-drawer.scss +99 -0
- package/src/navigation-drawer/navigation-drawer.ts +196 -0
- package/src/navigation-rail/navigation-rail.scss +1 -1
- package/src/number-field/number-field.ts +2 -3
- package/src/pagination/pagination.scss +1 -1
- package/src/progress/circular-progress/circular-progress.ts +2 -0
- package/src/progress/linear-progress/linear-progress.ts +2 -0
- package/src/radio/index.ts +1 -0
- package/src/radio/radio-group.scss +39 -0
- package/src/radio/radio-group.ts +167 -0
- package/src/radio/radio.ts +74 -31
- package/src/segmented-button/segmented-button-group.ts +12 -0
- package/src/segmented-button/segmented-button.ts +12 -6
- package/src/select/option.ts +17 -0
- package/src/select/select.ts +33 -8
- package/src/side-sheet/side-sheet.scss +1 -1
- package/src/sidebar-menu/sidebar-menu-item.scss +1 -1
- package/src/sidebar-menu/sidebar-menu-item.ts +2 -0
- package/src/sidebar-menu/sidebar-menu.ts +2 -0
- package/src/sidebar-menu/sidebar-sub-menu.scss +1 -1
- package/src/sidebar-menu/sidebar-sub-menu.ts +2 -0
- package/src/slider/slider.scss +3 -3
- package/src/slider/slider.ts +119 -31
- package/src/snackbar/snackbar.ts +3 -3
- package/src/split-button/split-button-colors.scss +2 -2
- package/src/svg/svg.scss +5 -5
- package/src/switch/switch.scss +0 -1
- package/src/switch/switch.ts +82 -47
- package/src/tabs/tab.scss +2 -1
- package/src/tabs/tabs.ts +14 -8
- package/src/textarea/textarea.ts +2 -3
- package/src/time-picker/time-picker.ts +2 -3
- package/src/toolbar/toolbar.scss +4 -4
- package/src/toolbar/toolbar.ts +12 -5
- package/src/url-field/url-field.ts +2 -3
- package/dist/BaseInput-CU1zZYKc.js +0 -27
- package/dist/BaseInput-CU1zZYKc.js.map +0 -1
- package/dist/brand-loader.js +0 -358
- package/dist/brand-loader.js.map +0 -1
- package/dist/element-internals-2CMts_0M.js.map +0 -1
- package/dist/form-associated-BXADnjOB.js.map +0 -1
- package/dist/list-AdO-PUq_.js.map +0 -1
- package/dist/select-CnnPbvpQ.js +0 -3955
- package/dist/select-CnnPbvpQ.js.map +0 -1
- package/dist/src/brand-loader/brand-loader.d.ts +0 -33
- package/dist/src/brand-loader/index.d.ts +0 -2
- package/src/brand-loader/brand-loader.scss +0 -270
- package/src/brand-loader/brand-loader.ts +0 -115
- package/src/brand-loader/index.ts +0 -2
- /package/dist/test/{brand-loader.test.d.ts → button.test.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { html, nothing } from 'lit';
|
|
1
|
+
import { html, nothing, PropertyValues } from 'lit';
|
|
2
2
|
import { property, state, query } from 'lit/decorators.js';
|
|
3
3
|
import { classMap } from 'lit/directives/class-map.js';
|
|
4
4
|
import { init } from 'modern-monaco';
|
|
@@ -6,43 +6,17 @@ import IndividualComponent from '@/IndividualComponent.js';
|
|
|
6
6
|
import BaseInput from '../input/BaseInput.js';
|
|
7
7
|
import { observeThemeChange } from '../__internal/utils/observe-theme-change.js';
|
|
8
8
|
import { redispatchEvent } from '../__internal/utils/dispatch-event-utils.js';
|
|
9
|
+
import { copyToClipboard } from '../__internal/utils/copy-to-clipboard.js';
|
|
9
10
|
import { isDarkMode } from '@/__internal/utils/is-dark-mode.js';
|
|
10
11
|
|
|
11
12
|
import styles from './code-editor.scss';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
* @label Code Editor
|
|
15
|
-
* @tag wc-code-editor
|
|
16
|
-
* @rawTag code-editor
|
|
17
|
-
* @summary A code editor component using Monaco Editor.
|
|
18
|
-
* @tags input
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```html
|
|
22
|
-
* <wc-code-editor language="javascript" style="width: 80%;--code-editor-height: 9rem;height: 9rem;" ></wc-code-editor>
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
14
|
+
export type CodeEditorLanguage = 'javascript' | 'json' | 'html' | 'css' | 'scss';
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getWorkerUrl(moduleId: string, label: string) {
|
|
31
|
-
const workersDir = new URL('monaco/workers/', import.meta.url);
|
|
32
|
-
switch (label) {
|
|
33
|
-
case 'json':
|
|
34
|
-
return `${workersDir}json.worker.js`;
|
|
35
|
-
case 'css':
|
|
36
|
-
return `${workersDir}css.worker.js`;
|
|
37
|
-
case 'html':
|
|
38
|
-
return `${workersDir}html.worker.js`;
|
|
39
|
-
case 'typescript':
|
|
40
|
-
case 'javascript':
|
|
41
|
-
return `${workersDir}ts.worker.js`;
|
|
42
|
-
default:
|
|
43
|
-
return `${workersDir}editor.worker.js`;
|
|
44
|
-
}
|
|
45
|
-
},
|
|
16
|
+
const locale = {
|
|
17
|
+
copied: 'Copied',
|
|
18
|
+
copyToClipboard: 'Copy to clipboard',
|
|
19
|
+
readOnly: 'Read Only',
|
|
46
20
|
};
|
|
47
21
|
|
|
48
22
|
/**
|
|
@@ -53,65 +27,105 @@ import styles from './code-editor.scss';
|
|
|
53
27
|
* @summary A Monaco-based code editing component with syntax highlighting and theming.
|
|
54
28
|
* @overview
|
|
55
29
|
* - CodeEditor wraps Monaco Editor as a web component.
|
|
56
|
-
* - Supports
|
|
30
|
+
* - Supports JavaScript, JSON, HTML, CSS and SCSS, read-only mode, line numbers, minimap, and dark/light theme.
|
|
31
|
+
* - Has a copy button; hide it with `hide-copy`.
|
|
57
32
|
* - Emits `change` when content is edited and updates value from property changes.
|
|
58
33
|
*
|
|
34
|
+
* @cssprop --code-editor-height - Height of the editor. Defaults to 300px.
|
|
35
|
+
*
|
|
36
|
+
* @fires {Event} change - Dispatched when the user edits the content.
|
|
37
|
+
* @fires {CustomEvent<{value: string}>} copied - Dispatched after the copy button copies the content.
|
|
38
|
+
*
|
|
59
39
|
* @example
|
|
60
40
|
* ```html
|
|
61
41
|
* <wc-code-editor
|
|
62
|
-
* language="
|
|
42
|
+
* language="css"
|
|
43
|
+
* readonly
|
|
63
44
|
* style="width: 100%; --code-editor-height: 10rem;"
|
|
64
|
-
* value="
|
|
65
|
-
* lineNumbers="on"
|
|
66
|
-
* minimap="false">
|
|
45
|
+
* value=":root { --color-primary: #6341d5; }">
|
|
67
46
|
* </wc-code-editor>
|
|
68
47
|
* ```
|
|
69
48
|
* @tags input, editor
|
|
70
49
|
*/
|
|
71
50
|
@IndividualComponent
|
|
72
51
|
export default class CodeEditor extends BaseInput {
|
|
52
|
+
// ── Static
|
|
53
|
+
|
|
73
54
|
static styles = [styles];
|
|
74
55
|
|
|
75
|
-
|
|
76
|
-
|
|
56
|
+
// ── Properties
|
|
57
|
+
|
|
58
|
+
// `name` (for form use) comes from BaseInput's form association.
|
|
77
59
|
|
|
60
|
+
/** The code shown in the editor. Updated as the user types. */
|
|
78
61
|
@property({ type: String })
|
|
79
62
|
value = '';
|
|
80
63
|
|
|
64
|
+
/** Language used for syntax highlighting. Can be changed after the editor loads. */
|
|
81
65
|
@property({ type: String })
|
|
82
|
-
language:
|
|
66
|
+
language: CodeEditorLanguage = 'javascript';
|
|
83
67
|
|
|
68
|
+
/** Extra source loaded as a separate model, e.g. type definitions for completions. */
|
|
84
69
|
@property({ type: Object })
|
|
85
70
|
libSource: any;
|
|
86
71
|
|
|
72
|
+
/** Whether line numbers show in the gutter. */
|
|
87
73
|
@property({ type: String })
|
|
88
74
|
lineNumbers: 'off' | 'on' = 'on';
|
|
89
75
|
|
|
76
|
+
/** Shows the minimap. Leave the attribute out to hide it. */
|
|
90
77
|
@property({ type: Boolean })
|
|
91
78
|
minimap = false;
|
|
92
79
|
|
|
80
|
+
/** Hides the copy button. */
|
|
81
|
+
@property({ type: Boolean, attribute: 'hide-copy' })
|
|
82
|
+
hideCopy = false;
|
|
83
|
+
|
|
84
|
+
/** Shows a "Read Only" badge while the editor is read-only or disabled. */
|
|
85
|
+
@property({ type: Boolean, attribute: 'show-readonly-badge' })
|
|
86
|
+
showReadonlyBadge = false;
|
|
87
|
+
|
|
88
|
+
/** Whether the page is in dark mode; picks the Monaco theme. */
|
|
93
89
|
@state() private _isDarkMode: boolean = isDarkMode();
|
|
94
90
|
|
|
91
|
+
/** Whether the editor text has focus. */
|
|
95
92
|
@state() private hasFocus = false;
|
|
96
93
|
|
|
97
|
-
|
|
94
|
+
/** Whether the copy button was just used; shows a check for a few seconds. */
|
|
95
|
+
@state() private _copied = false;
|
|
96
|
+
|
|
97
|
+
/** The Monaco editor instance, once loaded. */
|
|
98
98
|
@state() private editorMonacoInstance?: any;
|
|
99
99
|
|
|
100
|
+
// ── Queries
|
|
101
|
+
|
|
100
102
|
@query('.editor') private editorElement!: HTMLElement;
|
|
101
103
|
|
|
104
|
+
// ── Private fields
|
|
105
|
+
|
|
106
|
+
/** The Monaco API returned by modern-monaco's init(). */
|
|
102
107
|
monaco: any;
|
|
103
108
|
|
|
109
|
+
/** Stops listening for theme changes. */
|
|
110
|
+
private __unobserveTheme?: () => void;
|
|
111
|
+
|
|
112
|
+
/** Resets the copied state of the copy button. */
|
|
113
|
+
private __copiedTimer?: ReturnType<typeof setTimeout>;
|
|
114
|
+
|
|
115
|
+
// ── Lifecycle
|
|
116
|
+
|
|
104
117
|
connectedCallback() {
|
|
105
118
|
super.connectedCallback();
|
|
106
|
-
observeThemeChange(() => {
|
|
119
|
+
this.__unobserveTheme = observeThemeChange(() => {
|
|
107
120
|
this._isDarkMode = isDarkMode();
|
|
108
|
-
this.monaco
|
|
121
|
+
this.monaco?.editor.setTheme(this.getTheme());
|
|
109
122
|
});
|
|
110
123
|
}
|
|
111
124
|
|
|
112
|
-
// Cleanup to prevent memory leaks
|
|
113
125
|
disconnectedCallback() {
|
|
114
126
|
super.disconnectedCallback();
|
|
127
|
+
this.__unobserveTheme?.();
|
|
128
|
+
clearTimeout(this.__copiedTimer);
|
|
115
129
|
this.editorMonacoInstance?.dispose();
|
|
116
130
|
}
|
|
117
131
|
|
|
@@ -119,46 +133,33 @@ export default class CodeEditor extends BaseInput {
|
|
|
119
133
|
this.initializeMonaco();
|
|
120
134
|
}
|
|
121
135
|
|
|
122
|
-
protected updated(changedProperties:
|
|
136
|
+
protected updated(changedProperties: PropertyValues<this>) {
|
|
123
137
|
if (changedProperties.has('libSource')) this.libSourceChanged();
|
|
124
138
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
changedProperties.has('readonly')
|
|
128
|
-
) {
|
|
129
|
-
this.editorMonacoInstance?.updateOptions({
|
|
130
|
-
readOnly: this.disabled || this.readonly,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
139
|
+
const editor = this.editorMonacoInstance;
|
|
140
|
+
if (!editor) return;
|
|
133
141
|
|
|
134
|
-
if (changedProperties.has('
|
|
135
|
-
|
|
136
|
-
this.editorMonacoInstance &&
|
|
137
|
-
this.editorMonacoInstance.getValue() !== this.value
|
|
138
|
-
) {
|
|
139
|
-
this.editorMonacoInstance.setValue(this.value || '');
|
|
140
|
-
}
|
|
142
|
+
if (changedProperties.has('disabled') || changedProperties.has('readonly')) {
|
|
143
|
+
editor.updateOptions({ readOnly: this.disabled || this.readonly });
|
|
141
144
|
}
|
|
142
|
-
}
|
|
143
145
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
if (changedProperties.has('lineNumbers') || changedProperties.has('minimap')) {
|
|
147
|
+
editor.updateOptions({
|
|
148
|
+
lineNumbers: this.lineNumbers,
|
|
149
|
+
minimap: { enabled: this.minimap },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
147
152
|
|
|
148
|
-
if (
|
|
153
|
+
if (changedProperties.has('language')) {
|
|
154
|
+
this.monaco.editor.setModelLanguage(editor.getModel(), this.language);
|
|
155
|
+
}
|
|
149
156
|
|
|
150
|
-
if (this.
|
|
151
|
-
|
|
152
|
-
this.libSource,
|
|
153
|
-
this.language,
|
|
154
|
-
this.monaco.Uri.parse(libUri),
|
|
155
|
-
);
|
|
157
|
+
if (changedProperties.has('value') && editor.getValue() !== this.value) {
|
|
158
|
+
editor.setValue(this.value || '');
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
|
|
160
|
-
return this._isDarkMode ? 'github-dark' : 'github-light';
|
|
161
|
-
}
|
|
162
|
+
// ── Public methods
|
|
162
163
|
|
|
163
164
|
async initializeMonaco() {
|
|
164
165
|
this.monaco = await init({
|
|
@@ -210,12 +211,82 @@ export default class CodeEditor extends BaseInput {
|
|
|
210
211
|
); /* Focus hack or use blur if available */
|
|
211
212
|
}
|
|
212
213
|
|
|
214
|
+
// ── Private methods
|
|
215
|
+
|
|
216
|
+
private libSourceChanged() {
|
|
217
|
+
if (!this.monaco) return;
|
|
218
|
+
const libUri = 'java://peacock.redvars.com/lib.java';
|
|
219
|
+
const libModel = this.monaco.editor.getModel(this.monaco.Uri.parse(libUri));
|
|
220
|
+
|
|
221
|
+
if (libModel) libModel.dispose();
|
|
222
|
+
|
|
223
|
+
if (this.libSource) {
|
|
224
|
+
this.monaco.editor.createModel(
|
|
225
|
+
this.libSource,
|
|
226
|
+
this.language,
|
|
227
|
+
this.monaco.Uri.parse(libUri),
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private getTheme() {
|
|
233
|
+
return this._isDarkMode ? 'github-dark' : 'github-light';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private async __handleCopyClick() {
|
|
237
|
+
const value = this.editorMonacoInstance?.getValue() ?? this.value ?? '';
|
|
238
|
+
await copyToClipboard(value);
|
|
239
|
+
this._copied = true;
|
|
240
|
+
clearTimeout(this.__copiedTimer);
|
|
241
|
+
this.__copiedTimer = setTimeout(() => {
|
|
242
|
+
this._copied = false;
|
|
243
|
+
}, 3000);
|
|
244
|
+
this.dispatchEvent(
|
|
245
|
+
new CustomEvent('copied', {
|
|
246
|
+
detail: { value },
|
|
247
|
+
bubbles: true,
|
|
248
|
+
composed: true,
|
|
249
|
+
}),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ── Render helpers
|
|
254
|
+
|
|
255
|
+
private renderToolbar() {
|
|
256
|
+
const showBadge = this.showReadonlyBadge && (this.disabled || this.readonly);
|
|
257
|
+
if (this.hideCopy && !showBadge) return nothing;
|
|
258
|
+
|
|
259
|
+
return html`
|
|
260
|
+
<div class="toolbar">
|
|
261
|
+
${showBadge
|
|
262
|
+
? html`<wc-tag class="read-only-tag" color="red">${locale.readOnly}</wc-tag>`
|
|
263
|
+
: nothing}
|
|
264
|
+
${this.hideCopy
|
|
265
|
+
? nothing
|
|
266
|
+
: html`<wc-icon-button
|
|
267
|
+
class="copy-button"
|
|
268
|
+
color=${this._copied ? 'success' : 'surface'}
|
|
269
|
+
variant="text"
|
|
270
|
+
size="xs"
|
|
271
|
+
aria-label=${this._copied ? locale.copied : locale.copyToClipboard}
|
|
272
|
+
tooltip=${this._copied ? locale.copied : locale.copyToClipboard}
|
|
273
|
+
@click=${this.__handleCopyClick}
|
|
274
|
+
>
|
|
275
|
+
<wc-icon name=${this._copied ? 'check' : 'content_copy'}></wc-icon>
|
|
276
|
+
</wc-icon-button>`}
|
|
277
|
+
</div>
|
|
278
|
+
`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ── Render
|
|
282
|
+
|
|
213
283
|
render() {
|
|
284
|
+
// The field isn't marked read-only: its read-only look dims the
|
|
285
|
+
// container, and a read-only editor is still meant to be read.
|
|
214
286
|
return html`
|
|
215
287
|
<wc-field
|
|
216
288
|
?required=${this.required}
|
|
217
289
|
?disabled=${this.disabled}
|
|
218
|
-
?readonly=${this.readonly}
|
|
219
290
|
?skeleton=${this.skeleton}
|
|
220
291
|
?focused=${this.hasFocus}
|
|
221
292
|
.host=${this}
|
|
@@ -224,9 +295,7 @@ export default class CodeEditor extends BaseInput {
|
|
|
224
295
|
disabled: this.disabled,
|
|
225
296
|
})}"
|
|
226
297
|
>
|
|
227
|
-
${this.
|
|
228
|
-
? html`<wc-tag class="read-only-tag" color="red">Read Only</wc-tag>`
|
|
229
|
-
: nothing}
|
|
298
|
+
${this.renderToolbar()}
|
|
230
299
|
<div class="editor"></div>
|
|
231
300
|
${!this.editorMonacoInstance
|
|
232
301
|
? html`
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
@use '../../scss/mixin';
|
|
2
|
+
|
|
3
|
+
@include mixin.base-styles;
|
|
4
|
+
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.popover {
|
|
10
|
+
display: block;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.swatch {
|
|
14
|
+
@include mixin.reset-button-styles;
|
|
15
|
+
|
|
16
|
+
width: 1.5rem;
|
|
17
|
+
height: 1.5rem;
|
|
18
|
+
border-radius: var(--shape-corner-extra-small);
|
|
19
|
+
background-color: var(--_swatch-color);
|
|
20
|
+
box-shadow: inset 0 0 0 1px var(--color-outline-variant);
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
|
|
23
|
+
&:focus-visible {
|
|
24
|
+
outline: 2px solid var(--color-primary);
|
|
25
|
+
outline-offset: 2px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&:disabled {
|
|
29
|
+
cursor: not-allowed;
|
|
30
|
+
opacity: var(--state-disabled-content-opacity, 0.38);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.input {
|
|
35
|
+
width: 100%;
|
|
36
|
+
min-width: 0;
|
|
37
|
+
padding: 0;
|
|
38
|
+
border: none;
|
|
39
|
+
outline: none;
|
|
40
|
+
background: transparent;
|
|
41
|
+
font: inherit;
|
|
42
|
+
color: inherit;
|
|
43
|
+
text-transform: lowercase;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.picker-panel {
|
|
47
|
+
--popover-content-min-width: auto;
|
|
48
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { property, query, state } from 'lit/decorators.js';
|
|
3
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
4
|
+
import IndividualComponent from '@/IndividualComponent.js';
|
|
5
|
+
import BaseInput from '../input/BaseInput.js';
|
|
6
|
+
import type { Popover } from '../popover/popover.js';
|
|
7
|
+
import styles from './color-field.scss';
|
|
8
|
+
|
|
9
|
+
const HEX_COLOR = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
10
|
+
|
|
11
|
+
/** Normalizes `abc`, `#ABC` or `#aabbcc` to `#aabbcc`; returns null for anything else. */
|
|
12
|
+
function normalizeHex(input: string): string | null {
|
|
13
|
+
const match = input.trim().match(HEX_COLOR);
|
|
14
|
+
if (!match) return null;
|
|
15
|
+
const hex = match[1].toLowerCase();
|
|
16
|
+
return `#${hex.length === 3 ? hex.replace(/./g, c => c + c) : hex}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @label Color Field
|
|
21
|
+
* @tag wc-color-field
|
|
22
|
+
* @rawTag color-field
|
|
23
|
+
*
|
|
24
|
+
* @summary A text field for a hex color, with a swatch that opens a color picker.
|
|
25
|
+
* @overview
|
|
26
|
+
* <p>Color field shows the current color as a swatch next to its hex value. Type a hex value, or
|
|
27
|
+
* click the swatch to pick one with <code>wc-color-picker</code> in a popover.</p>
|
|
28
|
+
* <p>It is form-associated: the hex value is submitted under its <code>name</code>.</p>
|
|
29
|
+
*
|
|
30
|
+
* @fires {CustomEvent<{value: string}>} input - Dispatched while the color changes in the picker.
|
|
31
|
+
* @fires {CustomEvent<{value: string}>} change - Dispatched when a color is committed, from the picker or the text field.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```html
|
|
35
|
+
* <wc-color-field label="Brand color" value="#7c5df0"></wc-color-field>
|
|
36
|
+
* ```
|
|
37
|
+
* @tags input, form
|
|
38
|
+
*/
|
|
39
|
+
@IndividualComponent
|
|
40
|
+
export class ColorField extends BaseInput {
|
|
41
|
+
// ── Static ───────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
static styles = [styles];
|
|
44
|
+
|
|
45
|
+
// ── Properties ───────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
/** The color as a 6-digit hex string, such as `"#7c5df0"`. */
|
|
48
|
+
@property({ type: String, reflect: true }) value = '#7c5df0';
|
|
49
|
+
|
|
50
|
+
/** Label shown above the field. */
|
|
51
|
+
@property({ type: String }) label = '';
|
|
52
|
+
|
|
53
|
+
/** Helper text shown below the field. */
|
|
54
|
+
@property({ type: String, attribute: 'helper-text' }) helperText = '';
|
|
55
|
+
|
|
56
|
+
/** Visual variant of the field. */
|
|
57
|
+
@property({ type: String }) variant: 'filled' | 'outlined' | 'default' =
|
|
58
|
+
'default';
|
|
59
|
+
|
|
60
|
+
/** Where the picker opens, relative to the field. */
|
|
61
|
+
@property({ type: String }) placement: Popover['placement'] = 'bottom-start';
|
|
62
|
+
|
|
63
|
+
// ── State ────────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
/** Text in the hex input; differs from `value` while the user is typing. */
|
|
66
|
+
@state() private draft = '';
|
|
67
|
+
|
|
68
|
+
@state() private focused = false;
|
|
69
|
+
|
|
70
|
+
@state() private pickerOpen = false;
|
|
71
|
+
|
|
72
|
+
/** True after the user typed something that is not a hex color. */
|
|
73
|
+
@state() private invalid = false;
|
|
74
|
+
|
|
75
|
+
// ── Queries ──────────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
@query('wc-popover') private popoverElement?: Popover;
|
|
78
|
+
|
|
79
|
+
@query('.input') private inputElement?: HTMLInputElement;
|
|
80
|
+
|
|
81
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
protected override willUpdate(changed: Map<PropertyKey, unknown>) {
|
|
84
|
+
if (changed.has('value')) {
|
|
85
|
+
this.draft = this.value;
|
|
86
|
+
this.invalid = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ── Public methods ───────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
override focus() {
|
|
93
|
+
this.inputElement?.focus();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Opens the color picker. */
|
|
97
|
+
showPicker() {
|
|
98
|
+
if (this.disabled || this.readonly) return;
|
|
99
|
+
this.popoverElement?.show();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── Private methods ──────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
private commit(value: string) {
|
|
105
|
+
this.value = value;
|
|
106
|
+
this.dispatchEvent(
|
|
107
|
+
new CustomEvent('change', {
|
|
108
|
+
detail: { value },
|
|
109
|
+
bubbles: true,
|
|
110
|
+
composed: true,
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private handleSwatchClick(event: MouseEvent) {
|
|
116
|
+
// Keep the field from moving focus to the text input.
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
if (this.pickerOpen) {
|
|
119
|
+
this.popoverElement?.hide();
|
|
120
|
+
} else {
|
|
121
|
+
this.showPicker();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private handleTextInput(event: InputEvent) {
|
|
126
|
+
this.draft = (event.target as HTMLInputElement).value;
|
|
127
|
+
this.invalid = false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private handleTextChange() {
|
|
131
|
+
const hex = normalizeHex(this.draft);
|
|
132
|
+
if (!hex) {
|
|
133
|
+
this.invalid = this.draft.trim() !== '';
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (hex !== this.value) this.commit(hex);
|
|
137
|
+
else this.draft = hex;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private handleTextKeyDown(event: KeyboardEvent) {
|
|
141
|
+
if (event.key === 'Enter') this.handleTextChange();
|
|
142
|
+
if (event.key === 'ArrowDown' && event.altKey) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
this.showPicker();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private handlePickerInput(event: CustomEvent<{ value: string }>) {
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
this.value = event.detail.value;
|
|
151
|
+
this.dispatchEvent(
|
|
152
|
+
new CustomEvent('input', {
|
|
153
|
+
detail: { value: this.value },
|
|
154
|
+
bubbles: true,
|
|
155
|
+
composed: true,
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private handlePickerChange(event: CustomEvent<{ value: string }>) {
|
|
161
|
+
event.stopPropagation();
|
|
162
|
+
this.commit(event.detail.value);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ── Render ───────────────────────────────────────────────────────────────
|
|
166
|
+
|
|
167
|
+
render() {
|
|
168
|
+
return html`
|
|
169
|
+
<wc-popover
|
|
170
|
+
class="popover"
|
|
171
|
+
trigger="manual"
|
|
172
|
+
placement=${this.placement}
|
|
173
|
+
offset="4"
|
|
174
|
+
@wc-popover--open=${() => {
|
|
175
|
+
this.pickerOpen = true;
|
|
176
|
+
}}
|
|
177
|
+
@wc-popover--close=${() => {
|
|
178
|
+
this.pickerOpen = false;
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<wc-field
|
|
182
|
+
label=${this.label}
|
|
183
|
+
helper-text=${this.helperText}
|
|
184
|
+
variant=${this.variant}
|
|
185
|
+
?required=${this.required}
|
|
186
|
+
?disabled=${this.disabled}
|
|
187
|
+
?readonly=${this.readonly}
|
|
188
|
+
?skeleton=${this.skeleton}
|
|
189
|
+
?error=${this.invalid}
|
|
190
|
+
error-text="Enter a hex color, such as #7c5df0"
|
|
191
|
+
populated
|
|
192
|
+
?focused=${this.focused || this.pickerOpen}
|
|
193
|
+
.host=${this}
|
|
194
|
+
>
|
|
195
|
+
<button
|
|
196
|
+
slot="field-start"
|
|
197
|
+
class="swatch"
|
|
198
|
+
type="button"
|
|
199
|
+
aria-label="Choose color"
|
|
200
|
+
aria-haspopup="dialog"
|
|
201
|
+
aria-expanded=${String(this.pickerOpen)}
|
|
202
|
+
?disabled=${this.disabled || this.readonly}
|
|
203
|
+
style=${styleMap({ '--_swatch-color': this.value })}
|
|
204
|
+
@click=${this.handleSwatchClick}
|
|
205
|
+
></button>
|
|
206
|
+
<input
|
|
207
|
+
class="input"
|
|
208
|
+
name=${this.name}
|
|
209
|
+
spellcheck="false"
|
|
210
|
+
autocomplete="off"
|
|
211
|
+
maxlength="7"
|
|
212
|
+
aria-label=${this.label || 'Hex color'}
|
|
213
|
+
.value=${this.draft}
|
|
214
|
+
?disabled=${this.disabled}
|
|
215
|
+
?readonly=${this.readonly}
|
|
216
|
+
?required=${this.required}
|
|
217
|
+
@input=${this.handleTextInput}
|
|
218
|
+
@change=${this.handleTextChange}
|
|
219
|
+
@keydown=${this.handleTextKeyDown}
|
|
220
|
+
@focus=${() => {
|
|
221
|
+
this.focused = true;
|
|
222
|
+
}}
|
|
223
|
+
@blur=${() => {
|
|
224
|
+
this.focused = false;
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
</wc-field>
|
|
228
|
+
<wc-popover-content class="picker-panel">
|
|
229
|
+
<wc-color-picker
|
|
230
|
+
.value=${this.value}
|
|
231
|
+
?disabled=${this.disabled || this.readonly}
|
|
232
|
+
@input=${this.handlePickerInput}
|
|
233
|
+
@change=${this.handlePickerChange}
|
|
234
|
+
></wc-color-picker>
|
|
235
|
+
</wc-popover-content>
|
|
236
|
+
</wc-popover>
|
|
237
|
+
`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ColorField } from './color-field.js';
|