@lostgradient/cinder 0.24.6 → 0.24.7

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 (239) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/components.json +1 -1
  3. package/dist/components/accordion-item/accordion-item.css +2 -1
  4. package/dist/components/alert-dialog/index.js +52 -5
  5. package/dist/components/approval-card/index.js +52 -5
  6. package/dist/components/area-chart/area-chart.css +4 -2
  7. package/dist/components/autocomplete/index.js +52 -5
  8. package/dist/components/avatar-group/index.js +52 -5
  9. package/dist/components/backdrop/backdrop.css +6 -1
  10. package/dist/components/backdrop/index.js +52 -5
  11. package/dist/components/badge/badge.css +6 -6
  12. package/dist/components/banner/banner.css +13 -0
  13. package/dist/components/bar-chart/bar-chart.css +2 -1
  14. package/dist/components/carousel/carousel.css +14 -1
  15. package/dist/components/carousel/index.js +52 -5
  16. package/dist/components/chip/chip.css +7 -7
  17. package/dist/components/collapsible/collapsible.css +2 -1
  18. package/dist/components/collapsible/index.js +52 -5
  19. package/dist/components/color-swatch-picker/color-swatch-picker.css +14 -0
  20. package/dist/components/combobox/index.js +52 -5
  21. package/dist/components/command-menu/index.js +52 -5
  22. package/dist/components/command-palette/command-palette.css +30 -19
  23. package/dist/components/confirm-dialog/index.js +52 -5
  24. package/dist/components/connection-indicator/connection-indicator.css +7 -3
  25. package/dist/components/context-menu/index.js +52 -5
  26. package/dist/components/date-picker/index.js +52 -5
  27. package/dist/components/date-range-field/index.js +52 -5
  28. package/dist/components/drawer/drawer.css +4 -2
  29. package/dist/components/drawer/index.js +52 -5
  30. package/dist/components/dropdown/dropdown.css +7 -1
  31. package/dist/components/dropdown/index.js +52 -5
  32. package/dist/components/dropdown-menu/index.js +52 -5
  33. package/dist/components/feed/feed.css +2 -1
  34. package/dist/components/file-upload/file-upload.css +4 -2
  35. package/dist/components/hover-card/hover-card.css +2 -1
  36. package/dist/components/hover-card/index.js +52 -5
  37. package/dist/components/invocation-rule-builder/index.js +52 -5
  38. package/dist/components/json-schema-editor/enum-composition.d.ts +35 -0
  39. package/dist/components/json-schema-editor/enum-editor.svelte.d.ts +23 -0
  40. package/dist/components/json-schema-editor/form-view.svelte.d.ts +5 -0
  41. package/dist/components/json-schema-editor/index.js +2178 -1330
  42. package/dist/components/json-schema-editor/json-schema-editor.css +68 -35
  43. package/dist/components/json-schema-editor/json-view.svelte.d.ts +1 -0
  44. package/dist/components/json-schema-editor/property-editor.svelte.d.ts +6 -0
  45. package/dist/components/json-schema-editor/property-list.svelte.d.ts +6 -0
  46. package/dist/components/json-viewer/json-viewer.css +2 -1
  47. package/dist/components/kanban-board/kanban-board.css +14 -2
  48. package/dist/components/line-chart/line-chart.css +2 -1
  49. package/dist/components/load-more/load-more.css +5 -0
  50. package/dist/components/marquee/marquee.css +21 -3
  51. package/dist/components/media-controls/media-controls.css +2 -1
  52. package/dist/components/mega-menu/mega-menu.css +6 -3
  53. package/dist/components/menu-bar/index.js +52 -5
  54. package/dist/components/meter/meter.css +2 -1
  55. package/dist/components/modal/index.js +52 -5
  56. package/dist/components/modal/modal.css +4 -2
  57. package/dist/components/multi-select/index.js +52 -5
  58. package/dist/components/navigation-bar/index.js +52 -5
  59. package/dist/components/navigation-bar/navigation-bar.css +2 -1
  60. package/dist/components/pagination/pagination.css +4 -2
  61. package/dist/components/popover/index.js +52 -5
  62. package/dist/components/popover/popover.css +2 -1
  63. package/dist/components/portal/index.js +52 -5
  64. package/dist/components/progress/progress.css +41 -4
  65. package/dist/components/run-step-timeline/index.js +52 -5
  66. package/dist/components/scroll-area/index.js +52 -5
  67. package/dist/components/scroll-area/scroll-area.css +12 -0
  68. package/dist/components/selection-popover/index.js +52 -5
  69. package/dist/components/selection-popover/selection-popover.css +2 -1
  70. package/dist/components/side-navigation-group/side-navigation-group.css +2 -1
  71. package/dist/components/sidebar/index.js +52 -5
  72. package/dist/components/skeleton/skeleton.css +7 -1
  73. package/dist/components/skip-link/index.js +52 -5
  74. package/dist/components/slider/slider.css +4 -2
  75. package/dist/components/sortable-list/sortable-list.css +6 -3
  76. package/dist/components/sparkbar/sparkbar.css +2 -1
  77. package/dist/components/speed-dial/index.js +52 -5
  78. package/dist/components/speed-dial/speed-dial.css +2 -1
  79. package/dist/components/speed-dial-action/index.js +52 -5
  80. package/dist/components/spinner/spinner.css +15 -2
  81. package/dist/components/spinner/spinner.variables.js +2 -2
  82. package/dist/components/status-dot/status-dot.css +3 -1
  83. package/dist/components/table-of-contents/index.js +52 -5
  84. package/dist/components/table-of-contents/table-of-contents.css +2 -1
  85. package/dist/components/toast-region/index.js +52 -5
  86. package/dist/components/toast-region/toast-region.css +5 -3
  87. package/dist/components/toggle/toggle.css +3 -2
  88. package/dist/components/toolbar/toolbar.css +1 -1
  89. package/dist/components/tooltip/index.js +52 -5
  90. package/dist/components/tooltip/tooltip.css +2 -1
  91. package/dist/index.d.ts +2 -2
  92. package/dist/index.js +11816 -10919
  93. package/dist/server/components/alert-dialog/index.js +3 -3
  94. package/dist/server/components/approval-card/index.js +6 -6
  95. package/dist/server/components/autocomplete/index.js +5 -5
  96. package/dist/server/components/avatar-group/index.js +5 -5
  97. package/dist/server/components/backdrop/index.js +2 -2
  98. package/dist/server/components/carousel/index.js +2 -2
  99. package/dist/server/components/collapsible/index.js +3 -3
  100. package/dist/server/components/combobox/index.js +6 -6
  101. package/dist/server/components/command-menu/index.js +4 -4
  102. package/dist/server/components/confirm-dialog/index.js +3 -3
  103. package/dist/server/components/context-menu/index.js +5 -5
  104. package/dist/server/components/date-picker/index.js +6 -6
  105. package/dist/server/components/date-range-field/index.js +6 -6
  106. package/dist/server/components/drawer/index.js +3 -3
  107. package/dist/server/components/dropdown/index.js +5 -5
  108. package/dist/server/components/dropdown-menu/index.js +5 -5
  109. package/dist/server/components/hover-card/index.js +4 -4
  110. package/dist/server/components/invocation-rule-builder/index.js +6 -6
  111. package/dist/server/components/json-schema-editor/index.js +1 -1
  112. package/dist/server/components/menu-bar/index.js +5 -5
  113. package/dist/server/components/modal/index.js +3 -3
  114. package/dist/server/components/multi-select/index.js +4 -4
  115. package/dist/server/components/navigation-bar/index.js +4 -4
  116. package/dist/server/components/popover/index.js +5 -5
  117. package/dist/server/components/portal/index.js +3 -3
  118. package/dist/server/components/run-step-timeline/index.js +3 -3
  119. package/dist/server/components/scroll-area/index.js +2 -2
  120. package/dist/server/components/selection-popover/index.js +4 -4
  121. package/dist/server/components/sidebar/index.js +3 -3
  122. package/dist/server/components/skip-link/index.js +2 -2
  123. package/dist/server/components/speed-dial/index.js +5 -5
  124. package/dist/server/components/speed-dial-action/index.js +4 -4
  125. package/dist/server/components/table-of-contents/index.js +2 -2
  126. package/dist/server/components/toast-region/index.js +2 -2
  127. package/dist/server/components/tooltip/index.js +5 -5
  128. package/dist/server/index.js +53 -47
  129. package/dist/server/{index.server-mf4dr1kp.js → index.server-05fjyh64.js} +1 -1
  130. package/dist/server/{index.server-9m7bqtev.js → index.server-0sgd56wv.js} +1 -1
  131. package/dist/server/{index.server-8bv9bkm6.js → index.server-0v25zb5x.js} +1 -1
  132. package/dist/server/index.server-0xcc5k8g.js +65 -0
  133. package/dist/server/{index.server-0yrz8ryn.js → index.server-2dx3cghn.js} +1 -1
  134. package/dist/server/{index.server-bw1wbzzk.js → index.server-2yytkmt5.js} +1 -1
  135. package/dist/server/{index.server-0qa6j0gt.js → index.server-30gx9zg5.js} +1 -1
  136. package/dist/server/{index.server-zbgdfzy6.js → index.server-32dx3e3d.js} +1 -1
  137. package/dist/server/{index.server-0d1703dw.js → index.server-43hv4eth.js} +1 -1
  138. package/dist/server/{index.server-aphnpg78.js → index.server-4rref2gd.js} +1 -1
  139. package/dist/server/{index.server-7vzk6qhf.js → index.server-6t4zmzm9.js} +1 -1
  140. package/dist/server/{index.server-6kf969a0.js → index.server-6wj3ce1b.js} +1 -1
  141. package/dist/server/{index.server-6vd98s4m.js → index.server-71y23tjr.js} +1 -1
  142. package/dist/server/{index.server-ppw26tpq.js → index.server-76bazvez.js} +1 -1
  143. package/dist/server/{index.server-4entcat5.js → index.server-780qs6bf.js} +896 -216
  144. package/dist/server/{index.server-w20xg416.js → index.server-993j9d6k.js} +1 -1
  145. package/dist/server/{index.server-dw9bz17h.js → index.server-ahj2t130.js} +1 -1
  146. package/dist/server/{index.server-8xr5tbrn.js → index.server-ce4s0zq6.js} +1 -1
  147. package/dist/server/{index.server-tpny5pjk.js → index.server-crrj0ef1.js} +1 -1
  148. package/dist/server/{index.server-zj0x74bt.js → index.server-d4j8rztt.js} +1 -1
  149. package/dist/server/{index.server-a8gpnzgg.js → index.server-e2jq5490.js} +1 -1
  150. package/dist/server/{index.server-0dny4mhe.js → index.server-ehpdbjjt.js} +1 -1
  151. package/dist/server/{index.server-k21nfvxe.js → index.server-er0ge1w2.js} +3 -3
  152. package/dist/server/{index.server-p69bvf14.js → index.server-etg48ham.js} +1 -1
  153. package/dist/server/{index.server-s4pfz6pb.js → index.server-fdnzb16k.js} +1 -1
  154. package/dist/server/{index.server-b8m7ej8c.js → index.server-g8ehn08w.js} +1 -1
  155. package/dist/server/{index.server-ykvb4rcc.js → index.server-gg1jyyfe.js} +1 -1
  156. package/dist/server/{index.server-emqv9bz6.js → index.server-jd43fwkh.js} +1 -1
  157. package/dist/server/{index.server-zg0981gk.js → index.server-kk17whw8.js} +1 -1
  158. package/dist/server/{index.server-aywvs10h.js → index.server-n2s42qb6.js} +2 -2
  159. package/dist/server/{index.server-kszs0qx5.js → index.server-pp705ba7.js} +1 -1
  160. package/dist/server/{index.server-tkt7wm9w.js → index.server-qe7sgzpf.js} +1 -1
  161. package/dist/server/{index.server-hvp84h1d.js → index.server-qr1nsjzm.js} +1 -1
  162. package/dist/server/{index.server-jxcxe1sp.js → index.server-ras33ac4.js} +1 -1
  163. package/dist/server/{index.server-ye5xkaq2.js → index.server-sf0g2t1a.js} +1 -1
  164. package/dist/server/{index.server-h76gdmj1.js → index.server-tc9n0rwa.js} +1 -1
  165. package/dist/server/{index.server-j6wms88v.js → index.server-v4pecbt0.js} +2 -2
  166. package/dist/server/{index.server-bjj2hpx1.js → index.server-wdy49qrf.js} +1 -1
  167. package/dist/server/{index.server-cmz3t3zw.js → index.server-wk2ms64s.js} +1 -1
  168. package/dist/server/{index.server-spdds2hk.js → index.server-wksxfr9e.js} +1 -1
  169. package/dist/server/{index.server-zkhc16nf.js → index.server-wpdhc0y0.js} +1 -1
  170. package/dist/server/{index.server-c6namd71.js → index.server-wv9xge03.js} +1 -1
  171. package/dist/server/{index.server-d7twz1zm.js → index.server-xdqd2dvc.js} +1 -1
  172. package/dist/server/{index.server-d05m93p4.js → index.server-yty4hdcv.js} +1 -1
  173. package/dist/server/{index.server-936tfc73.js → index.server-zg7ctrjh.js} +1 -1
  174. package/dist/server/{index.server-nsdh6zgh.js → index.server-zwv8mamh.js} +1 -1
  175. package/dist/utilities/use-reduced-motion.svelte.d.ts +12 -1
  176. package/dist/utilities/use-reduced-motion.types.d.ts +1 -0
  177. package/package.json +1 -1
  178. package/src/components/accordion-item/accordion-item.css +2 -1
  179. package/src/components/area-chart/area-chart.css +4 -2
  180. package/src/components/backdrop/backdrop.css +6 -1
  181. package/src/components/badge/badge.css +6 -6
  182. package/src/components/banner/banner.css +13 -0
  183. package/src/components/bar-chart/bar-chart.css +2 -1
  184. package/src/components/carousel/carousel.css +14 -1
  185. package/src/components/chip/chip.css +7 -7
  186. package/src/components/collapsible/collapsible.css +2 -1
  187. package/src/components/color-swatch-picker/color-swatch-picker.css +14 -0
  188. package/src/components/command-palette/command-palette.css +30 -19
  189. package/src/components/connection-indicator/connection-indicator.css +7 -3
  190. package/src/components/drawer/drawer.css +4 -2
  191. package/src/components/dropdown/dropdown.css +7 -1
  192. package/src/components/feed/feed.css +2 -1
  193. package/src/components/file-upload/file-upload.css +4 -2
  194. package/src/components/hover-card/hover-card.css +2 -1
  195. package/src/components/json-schema-editor/enum-composition.ts +77 -0
  196. package/src/components/json-schema-editor/enum-editor.svelte +293 -0
  197. package/src/components/json-schema-editor/form-view.svelte +5 -2
  198. package/src/components/json-schema-editor/json-schema-editor-impl.svelte +17 -1
  199. package/src/components/json-schema-editor/json-schema-editor.css +68 -35
  200. package/src/components/json-schema-editor/json-view.svelte +6 -7
  201. package/src/components/json-schema-editor/property-editor.constants.ts +1 -0
  202. package/src/components/json-schema-editor/property-editor.svelte +182 -23
  203. package/src/components/json-schema-editor/property-list.svelte +201 -130
  204. package/src/components/json-viewer/json-viewer.css +2 -1
  205. package/src/components/kanban-board/kanban-board.css +14 -2
  206. package/src/components/line-chart/line-chart.css +2 -1
  207. package/src/components/load-more/load-more.css +5 -0
  208. package/src/components/marquee/marquee.css +21 -3
  209. package/src/components/media-controls/media-controls.css +2 -1
  210. package/src/components/mega-menu/mega-menu.css +6 -3
  211. package/src/components/meter/meter.css +2 -1
  212. package/src/components/modal/modal.css +4 -2
  213. package/src/components/navigation-bar/navigation-bar.css +2 -1
  214. package/src/components/pagination/pagination.css +4 -2
  215. package/src/components/popover/popover.css +2 -1
  216. package/src/components/progress/progress.css +41 -4
  217. package/src/components/scroll-area/scroll-area.css +12 -0
  218. package/src/components/selection-popover/selection-popover.css +2 -1
  219. package/src/components/side-navigation-group/side-navigation-group.css +2 -1
  220. package/src/components/skeleton/skeleton.css +7 -1
  221. package/src/components/slider/slider.css +4 -2
  222. package/src/components/sortable-list/sortable-list.css +6 -3
  223. package/src/components/sparkbar/sparkbar.css +2 -1
  224. package/src/components/speed-dial/speed-dial.css +2 -1
  225. package/src/components/spinner/spinner.css +15 -2
  226. package/src/components/spinner/spinner.variables.json +1 -1
  227. package/src/components/spinner/spinner.variables.ts +1 -1
  228. package/src/components/status-dot/status-dot.css +3 -1
  229. package/src/components/table-of-contents/table-of-contents.css +2 -1
  230. package/src/components/toast-region/toast-region.css +5 -3
  231. package/src/components/toggle/toggle.css +3 -2
  232. package/src/components/toolbar/toolbar.css +1 -1
  233. package/src/components/tooltip/tooltip.css +2 -1
  234. package/src/index.ts +9 -2
  235. package/src/styles/foundation.css +18 -3
  236. package/src/styles/tokens-base.css +172 -30
  237. package/src/utilities/use-reduced-motion.svelte.ts +63 -4
  238. package/src/utilities/use-reduced-motion.types.ts +2 -0
  239. package/dist/server/index.server-8hdvr9bt.js +0 -18
@@ -41,7 +41,9 @@
41
41
  }
42
42
 
43
43
  @media (prefers-reduced-motion: reduce) {
44
- .cinder-connection-indicator[data-cinder-status='live'] .cinder-connection-indicator__dot {
44
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
45
+ .cinder-connection-indicator[data-cinder-status='live']
46
+ .cinder-connection-indicator__dot {
45
47
  animation: none;
46
48
  }
47
49
  }
@@ -78,9 +80,11 @@
78
80
  }
79
81
 
80
82
  @media (prefers-reduced-motion: reduce) {
81
- .cinder-connection-indicator[data-cinder-status='connecting']
83
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
84
+ .cinder-connection-indicator[data-cinder-status='connecting']
82
85
  .cinder-connection-indicator__icon,
83
- .cinder-connection-indicator[data-cinder-status='reconnecting']
86
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
87
+ .cinder-connection-indicator[data-cinder-status='reconnecting']
84
88
  .cinder-connection-indicator__icon {
85
89
  animation: none;
86
90
  }
@@ -268,11 +268,13 @@
268
268
  }
269
269
 
270
270
  @media (prefers-reduced-motion: reduce) {
271
- .cinder-drawer__panel {
271
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
272
+ .cinder-drawer__panel {
272
273
  transition: none;
273
274
  }
274
275
 
275
- .cinder-drawer::backdrop {
276
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
277
+ .cinder-drawer::backdrop {
276
278
  transition: none;
277
279
  }
278
280
  }
@@ -236,7 +236,7 @@
236
236
  .cinder-dropdown-separator {
237
237
  height: 1px;
238
238
  margin-block: var(--cinder-space-1);
239
- background: var(--cinder-border);
239
+ background: var(--cinder-border-faint);
240
240
  }
241
241
 
242
242
  /* ----------------------------------------
@@ -395,4 +395,10 @@
395
395
  }
396
396
  }
397
397
  }
398
+
399
+ :root:is([data-cinder-reduced-motion='false'], [data-reduced-motion='off'])
400
+ .cinder-dropdown__menu {
401
+ animation: cinder-dropdown-enter var(--cinder-duration-fast) var(--cinder-ease-standard)
402
+ forwards;
403
+ }
398
404
  }
@@ -181,7 +181,8 @@
181
181
  }
182
182
 
183
183
  @media (prefers-reduced-motion: reduce) {
184
- .cinder-feed-log__skeleton {
184
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
185
+ .cinder-feed-log__skeleton {
185
186
  animation: none;
186
187
  }
187
188
  }
@@ -319,8 +319,10 @@
319
319
  }
320
320
 
321
321
  @media (prefers-reduced-motion: reduce) {
322
- .cinder-file-upload__dropzone,
323
- .cinder-file-upload__progress-fill {
322
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
323
+ .cinder-file-upload__dropzone,
324
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
325
+ .cinder-file-upload__progress-fill {
324
326
  transition: none;
325
327
  }
326
328
  }
@@ -94,7 +94,8 @@
94
94
  }
95
95
 
96
96
  @media (prefers-reduced-motion: reduce) {
97
- .cinder-hover-card {
97
+ :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
98
+ .cinder-hover-card {
98
99
  transition: none;
99
100
  transform: none;
100
101
  }
@@ -0,0 +1,77 @@
1
+ import type { JsonSchemaObject, JsonSchemaValue } from './json-schema-editor-types.ts';
2
+
3
+ /**
4
+ * A `oneOf` branch that represents one described enum value: `{ const, description? }`
5
+ * and nothing else. Standard JSON Schema `enum` has no per-value description slot, so
6
+ * a described enum value is promoted to this shape instead of a vendor extension.
7
+ */
8
+ export type EnumOneOfBranch = { const: unknown; description?: string };
9
+
10
+ function isEnumOneOfBranch(branch: JsonSchemaValue): branch is EnumOneOfBranch {
11
+ if (typeof branch !== 'object' || branch === null || Array.isArray(branch)) return false;
12
+ const keys = Object.keys(branch);
13
+ if (!keys.includes('const')) return false;
14
+ if (!keys.every((key) => key === 'const' || key === 'description')) return false;
15
+ // A foreign/hand-authored schema could carry `description` as a non-string.
16
+ // Reject it here rather than let it reach `buildEnumPatch`'s `.trim()` later.
17
+ const description = (branch as { description?: unknown }).description;
18
+ return description === undefined || typeof description === 'string';
19
+ }
20
+
21
+ /**
22
+ * True when every branch of `oneOf` is a bare `{ const, description? }` — i.e. the
23
+ * `oneOf` is standing in for a described enum rather than a real composition. A
24
+ * branch with any other keyword means the author wrote a real composition, so the
25
+ * composition section should render it instead of the enum table.
26
+ */
27
+ export function isEnumLikeOneOf(oneOf: JsonSchemaValue[] | undefined): boolean {
28
+ return Array.isArray(oneOf) && oneOf.length > 0 && oneOf.every(isEnumOneOfBranch);
29
+ }
30
+
31
+ export type EnumSource = 'enum' | 'oneOf' | null;
32
+
33
+ /** Which representation (if either) currently holds this schema's enum values. */
34
+ export function detectEnumSource(schema: JsonSchemaObject): EnumSource {
35
+ if (Array.isArray(schema.enum)) return 'enum';
36
+ if (isEnumLikeOneOf(schema.oneOf)) return 'oneOf';
37
+ return null;
38
+ }
39
+
40
+ function enumOneOfBranches(schema: JsonSchemaObject): EnumOneOfBranch[] {
41
+ return (schema.oneOf ?? []).filter(isEnumOneOfBranch);
42
+ }
43
+
44
+ /** Reads the enum values out of whichever representation is active. */
45
+ export function readEnumValues(schema: JsonSchemaObject, source: EnumSource): unknown[] {
46
+ if (source === 'enum') return schema.enum ?? [];
47
+ if (source === 'oneOf') return enumOneOfBranches(schema).map((branch) => branch.const);
48
+ return [];
49
+ }
50
+
51
+ /** Reads the parallel description array; `''` for a value with no description. */
52
+ export function readEnumDescriptions(schema: JsonSchemaObject, source: EnumSource): string[] {
53
+ if (source !== 'oneOf') return readEnumValues(schema, source).map(() => '');
54
+ return enumOneOfBranches(schema).map((branch) => branch.description ?? '');
55
+ }
56
+
57
+ /**
58
+ * Builds the `enum`/`oneOf` patch for a committed values+descriptions pair. A bare
59
+ * `enum` stays bare until a description is present anywhere in the list, at which
60
+ * point every value promotes to a `oneOf` branch; clearing every description demotes
61
+ * back to a bare `enum`. Both keys are always present (possibly `undefined`) so the
62
+ * caller's patch-merge deletes whichever representation is no longer active.
63
+ */
64
+ export function buildEnumPatch(
65
+ values: unknown[],
66
+ descriptions: string[],
67
+ ): { enum: unknown[] | undefined; oneOf: EnumOneOfBranch[] | undefined } {
68
+ const hasAnyDescription = descriptions.some((description) => description.trim() !== '');
69
+ if (!hasAnyDescription) {
70
+ return { enum: values, oneOf: undefined };
71
+ }
72
+ const oneOf: EnumOneOfBranch[] = values.map((value, index) => {
73
+ const description = descriptions[index]?.trim();
74
+ return description ? { const: value, description } : { const: value };
75
+ });
76
+ return { enum: undefined, oneOf };
77
+ }
@@ -0,0 +1,293 @@
1
+ <script lang="ts" module>
2
+ export {};
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { onDestroy, tick } from 'svelte';
7
+ import Button from '@lostgradient/cinder/button';
8
+ import Input from '@lostgradient/cinder/input';
9
+ let { idPrefix, path, values, descriptions = [], drafts = {}, historyRevision = 0, readonly = false, onvalidationErrorcount, onDraftsChange, onValuesChange, } = $props();
10
+ function descriptionAt(index) {
11
+ return descriptions[index] ?? '';
12
+ }
13
+ let localDrafts = $state({});
14
+ let previousDrafts = null;
15
+ let emittedDrafts = null;
16
+ let lastResolvedDuplicateSignature = null;
17
+ let previousHistoryRevision = $state(0);
18
+ const activeDrafts = $derived({ ...drafts, ...localDrafts });
19
+ const invalidValueIndexes = $derived(new Set(Object.keys(activeDrafts).map(Number)));
20
+ let actionAnnouncement = $state('');
21
+ let editorElement = $state();
22
+ $effect(() => onvalidationErrorcount?.(invalidValueIndexes.size));
23
+ onDestroy(() => onvalidationErrorcount?.(0));
24
+ $effect(() => {
25
+ if (historyRevision !== previousHistoryRevision) {
26
+ previousHistoryRevision = historyRevision;
27
+ // Undo/redo can shrink `values` out from under a draft that pointed at a
28
+ // row past the end. Drop drafts whose row no longer exists instead of
29
+ // leaving them stranded with no visible input to correct — this needs
30
+ // to prune both our own local echo AND the persisted `drafts` prop,
31
+ // since undo/redo only bumps `historyRevision` and never re-derives
32
+ // the parent's stored draft record on its own.
33
+ localDrafts = Object.fromEntries(Object.entries(localDrafts).filter(([index]) => Number(index) < values.length));
34
+ const prunedDrafts = Object.fromEntries(Object.entries(drafts).filter(([index]) => Number(index) < values.length));
35
+ if (Object.keys(prunedDrafts).length !== Object.keys(drafts).length) {
36
+ emittedDrafts = prunedDrafts;
37
+ onDraftsChange?.(prunedDrafts);
38
+ }
39
+ return;
40
+ }
41
+ if (drafts !== previousDrafts) {
42
+ if (drafts !== emittedDrafts)
43
+ localDrafts = {};
44
+ previousDrafts = drafts;
45
+ emittedDrafts = null;
46
+ }
47
+ });
48
+ $effect(() => {
49
+ const duplicateSignature = `${values.map(canonicalJson).join('\u0000')}:${JSON.stringify(Object.entries(activeDrafts)
50
+ .filter(([, draft]) => draft.error === 'duplicate')
51
+ .sort(([left], [right]) => Number(left) - Number(right)))}`;
52
+ if (duplicateSignature === lastResolvedDuplicateSignature)
53
+ return;
54
+ const nextValues = [...values];
55
+ const resolvedDuplicateIndexes = [];
56
+ for (const [indexText, draft] of Object.entries(activeDrafts)) {
57
+ if (draft.error !== 'duplicate')
58
+ continue;
59
+ const index = Number(indexText);
60
+ try {
61
+ const nextValue = JSON.parse(draft.text);
62
+ if (hasDuplicateValue(nextValue, index, nextValues))
63
+ continue;
64
+ nextValues[index] = nextValue;
65
+ resolvedDuplicateIndexes.push(index);
66
+ }
67
+ catch {
68
+ // A duplicate draft was previously parseable; retain it if it no longer is.
69
+ }
70
+ }
71
+ if (resolvedDuplicateIndexes.length === 0)
72
+ return;
73
+ lastResolvedDuplicateSignature = duplicateSignature;
74
+ const nextDrafts = { ...activeDrafts };
75
+ for (const index of resolvedDuplicateIndexes) {
76
+ delete nextDrafts[index];
77
+ }
78
+ localDrafts = Object.fromEntries(Object.entries(localDrafts).filter(([index]) => !resolvedDuplicateIndexes.includes(Number(index))));
79
+ emittedDrafts = nextDrafts;
80
+ onDraftsChange?.(nextDrafts);
81
+ onValuesChange(nextValues, descriptions, { label: 'resolve duplicate enum value' });
82
+ });
83
+ function jsonText(value) {
84
+ return JSON.stringify(value) ?? 'null';
85
+ }
86
+ function isJsonValue(value) {
87
+ if (typeof value === 'number')
88
+ return Number.isFinite(value);
89
+ if (Array.isArray(value))
90
+ return value.every(isJsonValue);
91
+ if (value !== null && typeof value === 'object')
92
+ return Object.values(value).every(isJsonValue);
93
+ return value === null || typeof value === 'string' || typeof value === 'boolean';
94
+ }
95
+ function canonicalJson(value) {
96
+ if (Array.isArray(value))
97
+ return `[${value.map(canonicalJson).join(',')}]`;
98
+ if (value !== null && typeof value === 'object') {
99
+ const object = value;
100
+ return `{${Object.keys(object)
101
+ .sort()
102
+ .map((key) => `${JSON.stringify(key)}:${canonicalJson(object[key])}`)
103
+ .join(',')}}`;
104
+ }
105
+ return JSON.stringify(value) ?? 'null';
106
+ }
107
+ function hasDuplicateValue(value, exceptIndex, candidates = values) {
108
+ const encoded = canonicalJson(value);
109
+ return candidates.some((item, index) => index !== exceptIndex && canonicalJson(item) === encoded);
110
+ }
111
+ function focusValue(index) {
112
+ const inputId = `${idPrefix}-value-${index}`;
113
+ Array.from(editorElement?.querySelectorAll('input') ?? [])
114
+ .find((input) => input.id === inputId)
115
+ ?.focus();
116
+ }
117
+ function setDraft(index, draft) {
118
+ if (draft === undefined) {
119
+ const { [index]: _removedLocalDraft, ...remainingLocalDrafts } = localDrafts;
120
+ const { [index]: _removedDraft, ...remainingDrafts } = activeDrafts;
121
+ localDrafts = remainingLocalDrafts;
122
+ emittedDrafts = remainingDrafts;
123
+ onDraftsChange?.(remainingDrafts);
124
+ return;
125
+ }
126
+ localDrafts = { ...localDrafts, [index]: draft };
127
+ emittedDrafts = { ...activeDrafts, [index]: draft };
128
+ onDraftsChange?.(emittedDrafts);
129
+ }
130
+ function errorMessage(index) {
131
+ return activeDrafts[index]?.error === 'duplicate'
132
+ ? 'Enum values must be unique.'
133
+ : 'Enter a valid JSON value.';
134
+ }
135
+ function setValue(index, text) {
136
+ try {
137
+ const nextValue = JSON.parse(text);
138
+ if (!isJsonValue(nextValue)) {
139
+ setDraft(index, { text, error: 'invalid-json' });
140
+ return;
141
+ }
142
+ if (hasDuplicateValue(nextValue, index)) {
143
+ setDraft(index, { text, error: 'duplicate' });
144
+ return;
145
+ }
146
+ const next = [...values];
147
+ next[index] = nextValue;
148
+ setDraft(index, undefined);
149
+ onValuesChange(next, descriptions, {
150
+ coalesceKey: `enum:${path}:${index}`,
151
+ label: 'edit enum value',
152
+ });
153
+ }
154
+ catch {
155
+ setDraft(index, { text, error: 'invalid-json' });
156
+ }
157
+ }
158
+ function setDescription(index, text) {
159
+ if (readonly)
160
+ return;
161
+ const next = [...descriptions];
162
+ next[index] = text;
163
+ onValuesChange(values, next, {
164
+ coalesceKey: `enum-description:${path}:${index}`,
165
+ label: 'edit enum value description',
166
+ });
167
+ }
168
+ async function moveValue(index, direction) {
169
+ const targetIndex = index + direction;
170
+ if (readonly || invalidValueIndexes.size > 0 || targetIndex < 0 || targetIndex >= values.length)
171
+ return;
172
+ const nextValues = [...values];
173
+ [nextValues[index], nextValues[targetIndex]] = [nextValues[targetIndex], nextValues[index]];
174
+ const nextDescriptions = [...descriptions];
175
+ [nextDescriptions[index], nextDescriptions[targetIndex]] = [
176
+ nextDescriptions[targetIndex] ?? '',
177
+ nextDescriptions[index] ?? '',
178
+ ];
179
+ onValuesChange(nextValues, nextDescriptions);
180
+ await tick();
181
+ focusValue(targetIndex);
182
+ // Clear the live region first so two consecutive moves that produce the
183
+ // identical announcement string still trigger a DOM change — otherwise
184
+ // Svelte sees no diff on the second move and assistive technology stays
185
+ // silent.
186
+ actionAnnouncement = '';
187
+ await tick();
188
+ actionAnnouncement = `Moved enum value ${index + 1} to position ${targetIndex + 1} of ${values.length}.`;
189
+ }
190
+ async function removeValue(index) {
191
+ if (readonly || invalidValueIndexes.size > 0 || values.length === 1)
192
+ return;
193
+ const focusIndex = Math.min(index, values.length - 2);
194
+ const remainingCount = values.length - 1;
195
+ onValuesChange(values.filter((_, itemIndex) => itemIndex !== index), descriptions.filter((_, itemIndex) => itemIndex !== index));
196
+ await tick();
197
+ focusValue(focusIndex);
198
+ actionAnnouncement = `Removed enum value ${index + 1}. ${remainingCount} ${remainingCount === 1 ? 'value remains' : 'values remain'}.`;
199
+ }
200
+ async function addValue() {
201
+ if (readonly)
202
+ return;
203
+ const addedIndex = values.length;
204
+ let nextValue = '';
205
+ let suffix = 1;
206
+ while (hasDuplicateValue(nextValue, -1))
207
+ nextValue = `value ${suffix++}`;
208
+ onValuesChange([...values, nextValue], [...descriptions, '']);
209
+ await tick();
210
+ focusValue(addedIndex);
211
+ actionAnnouncement = `Added enum value ${addedIndex + 1} of ${addedIndex + 1}.`;
212
+ }
213
+ </script>
214
+
215
+ <div class="cinder-jse-enum-editor" bind:this={editorElement}>
216
+ <table class="cinder-jse-enum-editor__table" aria-label="Enum values">
217
+ <thead>
218
+ <tr>
219
+ <th scope="col">Value</th>
220
+ <th scope="col">Description</th>
221
+ <th scope="col"><span class="cinder-sr-only">Actions</span></th>
222
+ </tr>
223
+ </thead>
224
+ <tbody>
225
+ {#each values as value, index (index)}
226
+ {@const inputId = `${idPrefix}-value-${index}`}
227
+ {@const errorId = `${inputId}-error`}
228
+ <tr>
229
+ <td>
230
+ <Input
231
+ id={inputId}
232
+ label={`Enum value ${index + 1}`}
233
+ value={activeDrafts[index]?.text ?? jsonText(value)}
234
+ disabled={readonly}
235
+ aria-invalid={invalidValueIndexes.has(index) || undefined}
236
+ aria-describedby={invalidValueIndexes.has(index) ? errorId : undefined}
237
+ oninput={(event: Event) => setValue(index, (event.target as HTMLInputElement).value)}
238
+ />
239
+ {#if invalidValueIndexes.has(index)}
240
+ <p id={errorId} class="cinder-jse-enum-editor__error" role="alert">
241
+ {errorMessage(index)}
242
+ </p>
243
+ {/if}
244
+ </td>
245
+ <td>
246
+ <Input
247
+ id={`${idPrefix}-description-${index}`}
248
+ label={`Enum value ${index + 1} description`}
249
+ value={descriptionAt(index)}
250
+ disabled={readonly}
251
+ oninput={(event: Event) =>
252
+ setDescription(index, (event.target as HTMLInputElement).value)}
253
+ />
254
+ </td>
255
+ <td class="cinder-jse-enum-editor__actions">
256
+ <Button
257
+ variant="ghost"
258
+ size="xs"
259
+ disabled={readonly || invalidValueIndexes.size > 0 || index === 0}
260
+ aria-label={`Move enum value ${index + 1} up`}
261
+ onclick={() => void moveValue(index, -1)}
262
+ >
263
+ Up
264
+ </Button>
265
+ <Button
266
+ id={`${idPrefix}-remove-${index}`}
267
+ variant="ghost"
268
+ size="xs"
269
+ disabled={readonly || invalidValueIndexes.size > 0 || index === values.length - 1}
270
+ aria-label={`Move enum value ${index + 1} down`}
271
+ onclick={() => void moveValue(index, 1)}
272
+ >
273
+ Down
274
+ </Button>
275
+ <Button
276
+ variant="ghost"
277
+ size="xs"
278
+ disabled={readonly || invalidValueIndexes.size > 0 || values.length === 1}
279
+ aria-label={`Remove enum value ${index + 1}`}
280
+ onclick={() => void removeValue(index)}
281
+ >
282
+ Remove
283
+ </Button>
284
+ </td>
285
+ </tr>
286
+ {/each}
287
+ </tbody>
288
+ </table>
289
+ <p class="cinder-sr-only" aria-live="polite">{actionAnnouncement}</p>
290
+ <Button variant="secondary" size="sm" disabled={readonly} onclick={() => void addValue()}
291
+ >Add enum value</Button
292
+ >
293
+ </div>
@@ -8,7 +8,7 @@ import Alert from '../alert/alert.svelte';
8
8
  import Button from '../button/button.svelte';
9
9
  import EmptyState from '../empty-state/empty-state.svelte';
10
10
  import PropertyEditor from './property-editor.svelte';
11
- let { state, idPrefix, onvalidationErrorcount, class: className } = $props();
11
+ let { state, idPrefix, enumDrafts, historyRevision = 0, onvalidationErrorcount, onEnumDraftsChange, onApplyJsonDraft, class: className, } = $props();
12
12
  // Snapshot the committed schema each render so changes propagate via the
13
13
  // value prop on PropertyEditor. We don't pass the live committed schema by
14
14
  // reference; PropertyEditor produces a brand-new object on each commit.
@@ -20,7 +20,7 @@ const rootSchema = $derived(state.committedSchema);
20
20
  <Alert variant="warning">
21
21
  <p>The JSON view has uncommitted changes. Apply or discard them to edit in the form.</p>
22
22
  <div class="cinder-jse-dirty-actions">
23
- <Button variant="primary" size="sm" onclick={() => void state.applyJsonDraft()}>
23
+ <Button variant="primary" size="sm" onclick={() => void onApplyJsonDraft()}>
24
24
  Apply JSON
25
25
  </Button>
26
26
  <Button variant="secondary" size="sm" onclick={() => state.discardJsonDraft()}>
@@ -43,7 +43,10 @@ const rootSchema = $derived(state.committedSchema);
43
43
  depth={0}
44
44
  readonly={state.readonly || state.jsonDraftIsDirty}
45
45
  value={rootSchema}
46
+ {enumDrafts}
47
+ {historyRevision}
46
48
  {onvalidationErrorcount}
49
+ {onEnumDraftsChange}
47
50
  onValueChange={(next, options) => state.commitFromForm(next, options)}
48
51
  />
49
52
  {/if}
@@ -59,6 +59,8 @@ const stateOptions = untrack(() => {
59
59
  return options;
60
60
  });
61
61
  let localValidationErrorCount = $state(0);
62
+ let enumDrafts = $state({});
63
+ let enumDraftHistoryRevision = $state(0);
62
64
  const editorState = createEditorState(stateOptions);
63
65
  const toolbarValidationErrorCount = $derived(view === 'form' ? localValidationErrorCount : 0);
64
66
  // Sync `readonly` into the state container whenever the prop changes.
@@ -99,6 +101,7 @@ $effect(() => {
99
101
  lastSchemaKey = schemaKey;
100
102
  untrack(() => {
101
103
  editorState.reload(schema, original);
104
+ enumDrafts = {};
102
105
  });
103
106
  announcer.announce('Schema reloaded');
104
107
  }
@@ -118,14 +121,21 @@ $effect(() => {
118
121
  });
119
122
  // Action handlers used by the toolbar.
120
123
  function handleUndo() {
124
+ if (editorState.readonly || !editorState.canUndo)
125
+ return;
126
+ enumDraftHistoryRevision += 1;
121
127
  const label = editorState.undo();
122
128
  announcer.announce(label ? `Undid: ${label}` : 'Undid last edit');
123
129
  }
124
130
  function handleRedo() {
131
+ if (editorState.readonly || !editorState.canRedo)
132
+ return;
133
+ enumDraftHistoryRevision += 1;
125
134
  const label = editorState.redo();
126
135
  announcer.announce(label ? `Redid: ${label}` : 'Redid edit');
127
136
  }
128
137
  function handleRevert() {
138
+ enumDrafts = {};
129
139
  editorState.revert();
130
140
  announcer.announce('Reverted to original schema');
131
141
  }
@@ -199,11 +209,17 @@ function onKeyDown(event) {
199
209
  <FormView
200
210
  state={editorState}
201
211
  idPrefix={`${id}-form`}
212
+ {enumDrafts}
213
+ historyRevision={enumDraftHistoryRevision}
202
214
  onvalidationErrorcount={(count) => (localValidationErrorCount = count)}
215
+ onEnumDraftsChange={(next) => (enumDrafts = next)}
216
+ onApplyJsonDraft={async () => {
217
+ if (await editorState.applyJsonDraft()) enumDrafts = {};
218
+ }}
203
219
  />
204
220
  </TabPanel>
205
221
  <TabPanel value="json">
206
- <JsonView state={editorState} idPrefix={`${id}-json`} />
222
+ <JsonView state={editorState} idPrefix={`${id}-json`} onApply={() => (enumDrafts = {})} />
207
223
  </TabPanel>
208
224
  <TabPanel value="diff">
209
225
  <DiffView state={editorState} />