@redvars/peacock 3.10.1 → 3.12.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.
Files changed (325) hide show
  1. package/dist/BaseInput-CV0pZgSb.js +58 -0
  2. package/dist/BaseInput-CV0pZgSb.js.map +1 -0
  3. package/dist/app-bar.js +16 -16
  4. package/dist/assets/styles.css +1 -1
  5. package/dist/assets/styles.css.map +1 -1
  6. package/dist/assets/theme.d.ts +66 -0
  7. package/dist/assets/theme.js +134 -0
  8. package/dist/assets/tokens.css +1 -1
  9. package/dist/assets/tokens.css.map +1 -1
  10. package/dist/base-progress-CLZTRveO.js +33 -0
  11. package/dist/base-progress-CLZTRveO.js.map +1 -0
  12. package/dist/bottom-sheet.js +1 -1
  13. package/dist/button-group.js +9 -7
  14. package/dist/button-group.js.map +1 -1
  15. package/dist/button.js +225 -187
  16. package/dist/button.js.map +1 -1
  17. package/dist/cb-divider.js +7 -6
  18. package/dist/cb-divider.js.map +1 -1
  19. package/dist/cb-group-base-D9gv7SDY.js +114 -0
  20. package/dist/cb-group-base-D9gv7SDY.js.map +1 -0
  21. package/dist/cb-group-base-DsX_2aFl.js +325 -0
  22. package/dist/cb-group-base-DsX_2aFl.js.map +1 -0
  23. package/dist/cb-group.js +96 -0
  24. package/dist/cb-group.js.map +1 -0
  25. package/dist/cb-rule.js +212 -0
  26. package/dist/cb-rule.js.map +1 -0
  27. package/dist/{chart-bar-CapLbc2e.js → chart-bar-D5dGFJfK.js} +2 -2
  28. package/dist/{chart-bar-CapLbc2e.js.map → chart-bar-D5dGFJfK.js.map} +1 -1
  29. package/dist/chart-bar.js +1 -1
  30. package/dist/chart-stacked-bar.js +1 -1
  31. package/dist/checkbox.js +78 -53
  32. package/dist/checkbox.js.map +1 -1
  33. package/dist/chip-set.js +52 -0
  34. package/dist/chip-set.js.map +1 -0
  35. package/dist/chip.js +8 -6
  36. package/dist/chip.js.map +1 -1
  37. package/dist/circular-progress.js +177 -0
  38. package/dist/circular-progress.js.map +1 -0
  39. package/dist/code-editor.js +129 -72
  40. package/dist/code-editor.js.map +1 -1
  41. package/dist/code-highlighter.js +2 -38
  42. package/dist/code-highlighter.js.map +1 -1
  43. package/dist/color-field.js +309 -0
  44. package/dist/color-field.js.map +1 -0
  45. package/dist/color-picker.js +26 -15
  46. package/dist/color-picker.js.map +1 -1
  47. package/dist/condition-builder.js +90 -35
  48. package/dist/condition-builder.js.map +1 -1
  49. package/dist/copy-to-clipboard-upGx-Ueo.js +39 -0
  50. package/dist/copy-to-clipboard-upGx-Ueo.js.map +1 -0
  51. package/dist/custom-elements-jsdocs.json +1140 -398
  52. package/dist/custom-elements.json +9065 -3989
  53. package/dist/date-picker.js +241 -0
  54. package/dist/date-picker.js.map +1 -0
  55. package/dist/{element-internals-2CMts_0M.js → delegate-py-Ets8N.js} +2 -43
  56. package/dist/delegate-py-Ets8N.js.map +1 -0
  57. package/dist/element-internals-QME0yEz4.js +43 -0
  58. package/dist/element-internals-QME0yEz4.js.map +1 -0
  59. package/dist/fab.js +51 -49
  60. package/dist/fab.js.map +1 -1
  61. package/dist/field.js +27 -0
  62. package/dist/field.js.map +1 -1
  63. package/dist/flow.js +5 -5
  64. package/dist/form-associated-Bhwwr6dT.js +162 -0
  65. package/dist/form-associated-Bhwwr6dT.js.map +1 -0
  66. package/dist/{form-associated-BXADnjOB.js → form-submitter-DPI4L6gj.js} +3 -159
  67. package/dist/form-submitter-DPI4L6gj.js.map +1 -0
  68. package/dist/html-editor.js +3 -1
  69. package/dist/html-editor.js.map +1 -1
  70. package/dist/icon-button.js +195 -156
  71. package/dist/icon-button.js.map +1 -1
  72. package/dist/image.js +2 -2
  73. package/dist/index.js +36 -11
  74. package/dist/index.js.map +1 -1
  75. package/dist/input.js +259 -0
  76. package/dist/input.js.map +1 -0
  77. package/dist/item.js +2 -1
  78. package/dist/item.js.map +1 -1
  79. package/dist/linear-progress.js +192 -0
  80. package/dist/linear-progress.js.map +1 -0
  81. package/dist/{list-AdO-PUq_.js → list-item.js} +12 -222
  82. package/dist/list-item.js.map +1 -0
  83. package/dist/list.js +225 -6
  84. package/dist/list.js.map +1 -1
  85. package/dist/loader-full.js +31 -8
  86. package/dist/loader-full.js.map +1 -1
  87. package/dist/loader.js +58 -25
  88. package/dist/loader.js.map +1 -1
  89. package/dist/markdown-editor.js +5 -3
  90. package/dist/markdown-editor.js.map +1 -1
  91. package/dist/menu-item.js +30 -30
  92. package/dist/navigation-bar-item.js +41 -0
  93. package/dist/navigation-bar-item.js.map +1 -0
  94. package/dist/navigation-bar.js +128 -0
  95. package/dist/navigation-bar.js.map +1 -0
  96. package/dist/navigation-drawer-item.js +236 -0
  97. package/dist/navigation-drawer-item.js.map +1 -0
  98. package/dist/navigation-drawer.js +293 -0
  99. package/dist/navigation-drawer.js.map +1 -0
  100. package/dist/navigation-rail.js +1 -1
  101. package/dist/number-field.js +280 -0
  102. package/dist/number-field.js.map +1 -0
  103. package/dist/pagination.js +1 -1
  104. package/dist/radio-group.js +209 -0
  105. package/dist/radio-group.js.map +1 -0
  106. package/dist/radio.js +47 -37
  107. package/dist/radio.js.map +1 -1
  108. package/dist/segmented-button-group.js +12 -0
  109. package/dist/segmented-button-group.js.map +1 -1
  110. package/dist/segmented-button.js +10 -6
  111. package/dist/segmented-button.js.map +1 -1
  112. package/dist/select.js +653 -0
  113. package/dist/select.js.map +1 -0
  114. package/dist/side-sheet.js +1 -1
  115. package/dist/sidebar-menu-item.js +273 -0
  116. package/dist/sidebar-menu-item.js.map +1 -0
  117. package/dist/sidebar-menu.js +193 -0
  118. package/dist/sidebar-menu.js.map +1 -0
  119. package/dist/sidebar-sub-menu.js +301 -0
  120. package/dist/sidebar-sub-menu.js.map +1 -0
  121. package/dist/slider.js +76 -24
  122. package/dist/slider.js.map +1 -1
  123. package/dist/snackbar.js +3 -3
  124. package/dist/snackbar.js.map +1 -1
  125. package/dist/split-button.js +2 -2
  126. package/dist/src/__internal/utils/size.d.ts +9 -0
  127. package/dist/src/button/ButtonTypes.d.ts +1 -1
  128. package/dist/src/checkbox/checkbox.d.ts +28 -22
  129. package/dist/src/chip/chip/chip.d.ts +3 -0
  130. package/dist/src/chip/tag/tag.d.ts +5 -1
  131. package/dist/src/code-editor/code-editor.d.ts +37 -10
  132. package/dist/src/color-field/color-field.d.ts +55 -0
  133. package/dist/src/color-field/index.d.ts +1 -0
  134. package/dist/src/color-picker/color-picker.d.ts +1 -1
  135. package/dist/src/condition-builder/cb-divider.d.ts +3 -1
  136. package/dist/src/condition-builder/cb-drag.d.ts +10 -0
  137. package/dist/src/condition-builder/cb-group-base.d.ts +59 -0
  138. package/dist/src/condition-builder/cb-group.d.ts +34 -0
  139. package/dist/src/condition-builder/cb-rule.d.ts +32 -0
  140. package/dist/src/condition-builder/cb-types.d.ts +13 -0
  141. package/dist/src/condition-builder/condition-builder.d.ts +35 -14
  142. package/dist/src/condition-builder/index.d.ts +3 -3
  143. package/dist/src/date-picker/date-picker.d.ts +0 -1
  144. package/dist/src/index.d.ts +6 -4
  145. package/dist/src/input/BaseInput.d.ts +21 -3
  146. package/dist/src/input/input.d.ts +15 -7
  147. package/dist/src/navigation-bar/index.d.ts +2 -0
  148. package/dist/src/navigation-bar/navigation-bar-item.d.ts +23 -0
  149. package/dist/src/navigation-bar/navigation-bar.d.ts +44 -0
  150. package/dist/src/navigation-drawer/index.d.ts +2 -0
  151. package/dist/src/navigation-drawer/navigation-drawer-item.d.ts +48 -0
  152. package/dist/src/navigation-drawer/navigation-drawer.d.ts +70 -0
  153. package/dist/src/number-field/number-field.d.ts +0 -1
  154. package/dist/src/radio/index.d.ts +1 -0
  155. package/dist/src/radio/radio-group.d.ts +50 -0
  156. package/dist/src/radio/radio.d.ts +18 -18
  157. package/dist/src/segmented-button/segmented-button-group.d.ts +5 -0
  158. package/dist/src/segmented-button/segmented-button.d.ts +2 -1
  159. package/dist/src/select/select.d.ts +6 -0
  160. package/dist/src/slider/slider.d.ts +14 -5
  161. package/dist/src/switch/switch.d.ts +22 -26
  162. package/dist/src/tabs/tabs.d.ts +3 -0
  163. package/dist/src/textarea/textarea.d.ts +0 -1
  164. package/dist/src/time-picker/time-picker.d.ts +0 -1
  165. package/dist/src/toolbar/toolbar.d.ts +7 -4
  166. package/dist/src/url-field/url-field.d.ts +0 -1
  167. package/dist/svg.js +5 -5
  168. package/dist/switch.js +413 -0
  169. package/dist/switch.js.map +1 -0
  170. package/dist/tab.js +2 -1
  171. package/dist/tab.js.map +1 -1
  172. package/dist/tabs.js +10 -8
  173. package/dist/tabs.js.map +1 -1
  174. package/dist/tag.js +349 -0
  175. package/dist/tag.js.map +1 -0
  176. package/dist/test/code-editor.test.d.ts +1 -0
  177. package/dist/test/color-field.test.d.ts +1 -0
  178. package/dist/test/color-picker.test.d.ts +1 -0
  179. package/dist/test/condition-builder.test.d.ts +1 -0
  180. package/dist/test/field.test.d.ts +1 -0
  181. package/dist/test/form-controls.test.d.ts +1 -0
  182. package/dist/test/icon.test.d.ts +1 -1
  183. package/dist/test/input.test.d.ts +1 -0
  184. package/dist/test/navigation.test.d.ts +1 -0
  185. package/dist/test/segmented-button.test.d.ts +1 -0
  186. package/dist/test/slider.test.d.ts +1 -0
  187. package/dist/textarea.js +237 -0
  188. package/dist/textarea.js.map +1 -0
  189. package/dist/time-picker.js +241 -0
  190. package/dist/time-picker.js.map +1 -0
  191. package/dist/toolbar.js +26 -9
  192. package/dist/toolbar.js.map +1 -1
  193. package/dist/tsconfig.tsbuildinfo +1 -1
  194. package/dist/url-field.js +298 -0
  195. package/dist/url-field.js.map +1 -0
  196. package/package.json +29 -8
  197. package/readme.md +2 -2
  198. package/scss/tokens.css +175 -18
  199. package/src/__internal/utils/size.ts +23 -0
  200. package/src/app-bar/app-bar.scss +4 -16
  201. package/src/bottom-sheet/bottom-sheet.scss +1 -1
  202. package/src/button/ButtonTypes.ts +2 -0
  203. package/src/button/button/button-base.scss +84 -84
  204. package/src/button/button/button-colors.scss +14 -2
  205. package/src/button/button/button-layers.scss +71 -71
  206. package/src/button/button/button-shapes.scss +2 -2
  207. package/src/button/button/button-sizes.scss +35 -35
  208. package/src/button/button/button.scss +1 -1
  209. package/src/button/button/button.ts +1 -2
  210. package/src/button/button-group/button-group.scss +5 -5
  211. package/src/button/fab/fab-sizes.scss +15 -15
  212. package/src/button/fab/fab.scss +32 -32
  213. package/src/button/icon-button/icon-button-sizes.scss +7 -7
  214. package/src/chart-bar/chart-bar.scss +1 -1
  215. package/src/checkbox/checkbox.scss +7 -6
  216. package/src/checkbox/checkbox.ts +92 -40
  217. package/src/chip/chip/chip.ts +8 -5
  218. package/src/chip/chip-set/chip-set.ts +2 -0
  219. package/src/chip/tag/tag-colors.scss +1 -1
  220. package/src/chip/tag/tag-sizes.scss +9 -0
  221. package/src/chip/tag/tag.scss +1 -1
  222. package/src/chip/tag/tag.ts +20 -9
  223. package/src/code-editor/code-editor.scss +8 -3
  224. package/src/code-editor/code-editor.ts +148 -79
  225. package/src/code-highlighter/code-highlighter.scss +1 -1
  226. package/src/color-field/color-field.scss +48 -0
  227. package/src/color-field/color-field.ts +239 -0
  228. package/src/color-field/index.ts +1 -0
  229. package/src/color-picker/color-picker.scss +33 -15
  230. package/src/color-picker/color-picker.ts +2 -1
  231. package/src/condition-builder/cb-divider.scss +4 -5
  232. package/src/condition-builder/cb-divider.ts +3 -1
  233. package/src/condition-builder/cb-drag.ts +35 -0
  234. package/src/condition-builder/cb-group-base.scss +97 -0
  235. package/src/condition-builder/cb-group-base.ts +335 -0
  236. package/src/condition-builder/cb-group.scss +21 -0
  237. package/src/condition-builder/cb-group.ts +72 -0
  238. package/src/condition-builder/cb-rule.scss +90 -0
  239. package/src/condition-builder/cb-rule.ts +129 -0
  240. package/src/condition-builder/cb-types.ts +16 -0
  241. package/src/condition-builder/condition-builder.scss +12 -9
  242. package/src/condition-builder/condition-builder.ts +77 -17
  243. package/src/condition-builder/index.ts +7 -3
  244. package/src/date-picker/date-picker.ts +2 -3
  245. package/src/field/field.scss +34 -0
  246. package/src/flow/flow.scss +5 -5
  247. package/src/image/image.scss +2 -2
  248. package/src/index.ts +14 -6
  249. package/src/input/BaseInput.ts +54 -4
  250. package/src/input/input.ts +104 -79
  251. package/src/list/list-item.ts +2 -0
  252. package/src/loader.ts +34 -19
  253. package/src/markdown-editor/markdown-editor.scss +2 -2
  254. package/src/menu/menu-item/menu-item.scss +30 -30
  255. package/src/navigation-bar/index.ts +2 -0
  256. package/src/navigation-bar/navigation-bar-item.ts +25 -0
  257. package/src/navigation-bar/navigation-bar.scss +27 -0
  258. package/src/navigation-bar/navigation-bar.ts +96 -0
  259. package/src/navigation-drawer/index.ts +2 -0
  260. package/src/navigation-drawer/navigation-drawer-item.scss +82 -0
  261. package/src/navigation-drawer/navigation-drawer-item.ts +133 -0
  262. package/src/navigation-drawer/navigation-drawer.scss +99 -0
  263. package/src/navigation-drawer/navigation-drawer.ts +196 -0
  264. package/src/navigation-rail/navigation-rail.scss +1 -1
  265. package/src/number-field/number-field.ts +2 -3
  266. package/src/pagination/pagination.scss +1 -1
  267. package/src/progress/circular-progress/circular-progress.ts +2 -0
  268. package/src/progress/linear-progress/linear-progress.ts +2 -0
  269. package/src/radio/index.ts +1 -0
  270. package/src/radio/radio-group.scss +39 -0
  271. package/src/radio/radio-group.ts +167 -0
  272. package/src/radio/radio.ts +74 -31
  273. package/src/segmented-button/segmented-button-group.ts +12 -0
  274. package/src/segmented-button/segmented-button.ts +12 -6
  275. package/src/select/select.ts +21 -1
  276. package/src/side-sheet/side-sheet.scss +1 -1
  277. package/src/sidebar-menu/sidebar-menu-item.scss +1 -1
  278. package/src/sidebar-menu/sidebar-menu-item.ts +2 -0
  279. package/src/sidebar-menu/sidebar-menu.ts +2 -0
  280. package/src/sidebar-menu/sidebar-sub-menu.scss +1 -1
  281. package/src/sidebar-menu/sidebar-sub-menu.ts +2 -0
  282. package/src/slider/slider.scss +3 -3
  283. package/src/slider/slider.ts +119 -31
  284. package/src/snackbar/snackbar.ts +3 -3
  285. package/src/split-button/split-button-colors.scss +2 -2
  286. package/src/svg/svg.scss +5 -5
  287. package/src/switch/switch.scss +0 -1
  288. package/src/switch/switch.ts +82 -47
  289. package/src/tabs/tab.scss +2 -1
  290. package/src/tabs/tabs.ts +14 -8
  291. package/src/textarea/textarea.ts +2 -3
  292. package/src/time-picker/time-picker.ts +2 -3
  293. package/src/toolbar/toolbar.scss +4 -4
  294. package/src/toolbar/toolbar.ts +12 -5
  295. package/src/url-field/url-field.ts +2 -3
  296. package/dist/BaseInput-CU1zZYKc.js +0 -27
  297. package/dist/BaseInput-CU1zZYKc.js.map +0 -1
  298. package/dist/brand-loader.js +0 -358
  299. package/dist/brand-loader.js.map +0 -1
  300. package/dist/cb-compound-expression.js +0 -133
  301. package/dist/cb-compound-expression.js.map +0 -1
  302. package/dist/cb-expression.js +0 -78
  303. package/dist/cb-expression.js.map +0 -1
  304. package/dist/cb-predicate.js +0 -141
  305. package/dist/cb-predicate.js.map +0 -1
  306. package/dist/element-internals-2CMts_0M.js.map +0 -1
  307. package/dist/form-associated-BXADnjOB.js.map +0 -1
  308. package/dist/list-AdO-PUq_.js.map +0 -1
  309. package/dist/select-DkyRqUTI.js +0 -3955
  310. package/dist/select-DkyRqUTI.js.map +0 -1
  311. package/dist/src/brand-loader/brand-loader.d.ts +0 -33
  312. package/dist/src/brand-loader/index.d.ts +0 -2
  313. package/dist/src/condition-builder/cb-compound-expression.d.ts +0 -30
  314. package/dist/src/condition-builder/cb-expression.d.ts +0 -30
  315. package/dist/src/condition-builder/cb-predicate.d.ts +0 -29
  316. package/src/brand-loader/brand-loader.scss +0 -270
  317. package/src/brand-loader/brand-loader.ts +0 -115
  318. package/src/brand-loader/index.ts +0 -2
  319. package/src/condition-builder/cb-compound-expression.scss +0 -41
  320. package/src/condition-builder/cb-compound-expression.ts +0 -79
  321. package/src/condition-builder/cb-expression.scss +0 -13
  322. package/src/condition-builder/cb-expression.ts +0 -48
  323. package/src/condition-builder/cb-predicate.scss +0 -35
  324. package/src/condition-builder/cb-predicate.ts +0 -101
  325. /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
- // At module level, outside the class
27
- // @ts-ignore
28
- // At module level, outside the class
29
- (self as any).MonacoEnvironment = {
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 JS/JSON/HTML languages, read-only mode, line numbers, minimap, and dark/light theme.
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="javascript"
42
+ * language="css"
43
+ * readonly
63
44
  * style="width: 100%; --code-editor-height: 10rem;"
64
- * value="function hello() { console.log('Hello'); }"
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
- @property({ type: String })
76
- name = '';
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: 'javascript' | 'json' | 'html' = 'javascript';
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
- // Type the instance correctly using the npm package types
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.editor.setTheme(this.getTheme());
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: any) {
136
+ protected updated(changedProperties: PropertyValues<this>) {
123
137
  if (changedProperties.has('libSource')) this.libSourceChanged();
124
138
 
125
- if (
126
- changedProperties.has('disabled') ||
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('value')) {
135
- if (
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
- private libSourceChanged() {
145
- const libUri = 'java://peacock.redvars.com/lib.java';
146
- const libModel = this.monaco.editor.getModel(this.monaco.Uri.parse(libUri));
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 (libModel) libModel.dispose();
153
+ if (changedProperties.has('language')) {
154
+ this.monaco.editor.setModelLanguage(editor.getModel(), this.language);
155
+ }
149
156
 
150
- if (this.libSource) {
151
- this.monaco.editor.createModel(
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
- private getTheme() {
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.disabled || this.readonly
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`
@@ -36,7 +36,7 @@
36
36
  @include mixin.get-typography(body-medium);
37
37
 
38
38
  .copy-button {
39
- --button-container-shape: 9999px;
39
+ --button-container-shape: var(--shape-corner-full);
40
40
  }
41
41
  }
42
42
 
@@ -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';