@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.
- package/CHANGELOG.md +18 -0
- package/components.json +1 -1
- package/dist/components/accordion-item/accordion-item.css +2 -1
- package/dist/components/alert-dialog/index.js +52 -5
- package/dist/components/approval-card/index.js +52 -5
- package/dist/components/area-chart/area-chart.css +4 -2
- package/dist/components/autocomplete/index.js +52 -5
- package/dist/components/avatar-group/index.js +52 -5
- package/dist/components/backdrop/backdrop.css +6 -1
- package/dist/components/backdrop/index.js +52 -5
- package/dist/components/badge/badge.css +6 -6
- package/dist/components/banner/banner.css +13 -0
- package/dist/components/bar-chart/bar-chart.css +2 -1
- package/dist/components/carousel/carousel.css +14 -1
- package/dist/components/carousel/index.js +52 -5
- package/dist/components/chip/chip.css +7 -7
- package/dist/components/collapsible/collapsible.css +2 -1
- package/dist/components/collapsible/index.js +52 -5
- package/dist/components/color-swatch-picker/color-swatch-picker.css +14 -0
- package/dist/components/combobox/index.js +52 -5
- package/dist/components/command-menu/index.js +52 -5
- package/dist/components/command-palette/command-palette.css +30 -19
- package/dist/components/confirm-dialog/index.js +52 -5
- package/dist/components/connection-indicator/connection-indicator.css +7 -3
- package/dist/components/context-menu/index.js +52 -5
- package/dist/components/date-picker/index.js +52 -5
- package/dist/components/date-range-field/index.js +52 -5
- package/dist/components/drawer/drawer.css +4 -2
- package/dist/components/drawer/index.js +52 -5
- package/dist/components/dropdown/dropdown.css +7 -1
- package/dist/components/dropdown/index.js +52 -5
- package/dist/components/dropdown-menu/index.js +52 -5
- package/dist/components/feed/feed.css +2 -1
- package/dist/components/file-upload/file-upload.css +4 -2
- package/dist/components/hover-card/hover-card.css +2 -1
- package/dist/components/hover-card/index.js +52 -5
- package/dist/components/invocation-rule-builder/index.js +52 -5
- package/dist/components/json-schema-editor/enum-composition.d.ts +35 -0
- package/dist/components/json-schema-editor/enum-editor.svelte.d.ts +23 -0
- package/dist/components/json-schema-editor/form-view.svelte.d.ts +5 -0
- package/dist/components/json-schema-editor/index.js +2178 -1330
- package/dist/components/json-schema-editor/json-schema-editor.css +68 -35
- package/dist/components/json-schema-editor/json-view.svelte.d.ts +1 -0
- package/dist/components/json-schema-editor/property-editor.svelte.d.ts +6 -0
- package/dist/components/json-schema-editor/property-list.svelte.d.ts +6 -0
- package/dist/components/json-viewer/json-viewer.css +2 -1
- package/dist/components/kanban-board/kanban-board.css +14 -2
- package/dist/components/line-chart/line-chart.css +2 -1
- package/dist/components/load-more/load-more.css +5 -0
- package/dist/components/marquee/marquee.css +21 -3
- package/dist/components/media-controls/media-controls.css +2 -1
- package/dist/components/mega-menu/mega-menu.css +6 -3
- package/dist/components/menu-bar/index.js +52 -5
- package/dist/components/meter/meter.css +2 -1
- package/dist/components/modal/index.js +52 -5
- package/dist/components/modal/modal.css +4 -2
- package/dist/components/multi-select/index.js +52 -5
- package/dist/components/navigation-bar/index.js +52 -5
- package/dist/components/navigation-bar/navigation-bar.css +2 -1
- package/dist/components/pagination/pagination.css +4 -2
- package/dist/components/popover/index.js +52 -5
- package/dist/components/popover/popover.css +2 -1
- package/dist/components/portal/index.js +52 -5
- package/dist/components/progress/progress.css +41 -4
- package/dist/components/run-step-timeline/index.js +52 -5
- package/dist/components/scroll-area/index.js +52 -5
- package/dist/components/scroll-area/scroll-area.css +12 -0
- package/dist/components/selection-popover/index.js +52 -5
- package/dist/components/selection-popover/selection-popover.css +2 -1
- package/dist/components/side-navigation-group/side-navigation-group.css +2 -1
- package/dist/components/sidebar/index.js +52 -5
- package/dist/components/skeleton/skeleton.css +7 -1
- package/dist/components/skip-link/index.js +52 -5
- package/dist/components/slider/slider.css +4 -2
- package/dist/components/sortable-list/sortable-list.css +6 -3
- package/dist/components/sparkbar/sparkbar.css +2 -1
- package/dist/components/speed-dial/index.js +52 -5
- package/dist/components/speed-dial/speed-dial.css +2 -1
- package/dist/components/speed-dial-action/index.js +52 -5
- package/dist/components/spinner/spinner.css +15 -2
- package/dist/components/spinner/spinner.variables.js +2 -2
- package/dist/components/status-dot/status-dot.css +3 -1
- package/dist/components/table-of-contents/index.js +52 -5
- package/dist/components/table-of-contents/table-of-contents.css +2 -1
- package/dist/components/toast-region/index.js +52 -5
- package/dist/components/toast-region/toast-region.css +5 -3
- package/dist/components/toggle/toggle.css +3 -2
- package/dist/components/toolbar/toolbar.css +1 -1
- package/dist/components/tooltip/index.js +52 -5
- package/dist/components/tooltip/tooltip.css +2 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11816 -10919
- package/dist/server/components/alert-dialog/index.js +3 -3
- package/dist/server/components/approval-card/index.js +6 -6
- package/dist/server/components/autocomplete/index.js +5 -5
- package/dist/server/components/avatar-group/index.js +5 -5
- package/dist/server/components/backdrop/index.js +2 -2
- package/dist/server/components/carousel/index.js +2 -2
- package/dist/server/components/collapsible/index.js +3 -3
- package/dist/server/components/combobox/index.js +6 -6
- package/dist/server/components/command-menu/index.js +4 -4
- package/dist/server/components/confirm-dialog/index.js +3 -3
- package/dist/server/components/context-menu/index.js +5 -5
- package/dist/server/components/date-picker/index.js +6 -6
- package/dist/server/components/date-range-field/index.js +6 -6
- package/dist/server/components/drawer/index.js +3 -3
- package/dist/server/components/dropdown/index.js +5 -5
- package/dist/server/components/dropdown-menu/index.js +5 -5
- package/dist/server/components/hover-card/index.js +4 -4
- package/dist/server/components/invocation-rule-builder/index.js +6 -6
- package/dist/server/components/json-schema-editor/index.js +1 -1
- package/dist/server/components/menu-bar/index.js +5 -5
- package/dist/server/components/modal/index.js +3 -3
- package/dist/server/components/multi-select/index.js +4 -4
- package/dist/server/components/navigation-bar/index.js +4 -4
- package/dist/server/components/popover/index.js +5 -5
- package/dist/server/components/portal/index.js +3 -3
- package/dist/server/components/run-step-timeline/index.js +3 -3
- package/dist/server/components/scroll-area/index.js +2 -2
- package/dist/server/components/selection-popover/index.js +4 -4
- package/dist/server/components/sidebar/index.js +3 -3
- package/dist/server/components/skip-link/index.js +2 -2
- package/dist/server/components/speed-dial/index.js +5 -5
- package/dist/server/components/speed-dial-action/index.js +4 -4
- package/dist/server/components/table-of-contents/index.js +2 -2
- package/dist/server/components/toast-region/index.js +2 -2
- package/dist/server/components/tooltip/index.js +5 -5
- package/dist/server/index.js +53 -47
- package/dist/server/{index.server-mf4dr1kp.js → index.server-05fjyh64.js} +1 -1
- package/dist/server/{index.server-9m7bqtev.js → index.server-0sgd56wv.js} +1 -1
- package/dist/server/{index.server-8bv9bkm6.js → index.server-0v25zb5x.js} +1 -1
- package/dist/server/index.server-0xcc5k8g.js +65 -0
- package/dist/server/{index.server-0yrz8ryn.js → index.server-2dx3cghn.js} +1 -1
- package/dist/server/{index.server-bw1wbzzk.js → index.server-2yytkmt5.js} +1 -1
- package/dist/server/{index.server-0qa6j0gt.js → index.server-30gx9zg5.js} +1 -1
- package/dist/server/{index.server-zbgdfzy6.js → index.server-32dx3e3d.js} +1 -1
- package/dist/server/{index.server-0d1703dw.js → index.server-43hv4eth.js} +1 -1
- package/dist/server/{index.server-aphnpg78.js → index.server-4rref2gd.js} +1 -1
- package/dist/server/{index.server-7vzk6qhf.js → index.server-6t4zmzm9.js} +1 -1
- package/dist/server/{index.server-6kf969a0.js → index.server-6wj3ce1b.js} +1 -1
- package/dist/server/{index.server-6vd98s4m.js → index.server-71y23tjr.js} +1 -1
- package/dist/server/{index.server-ppw26tpq.js → index.server-76bazvez.js} +1 -1
- package/dist/server/{index.server-4entcat5.js → index.server-780qs6bf.js} +896 -216
- package/dist/server/{index.server-w20xg416.js → index.server-993j9d6k.js} +1 -1
- package/dist/server/{index.server-dw9bz17h.js → index.server-ahj2t130.js} +1 -1
- package/dist/server/{index.server-8xr5tbrn.js → index.server-ce4s0zq6.js} +1 -1
- package/dist/server/{index.server-tpny5pjk.js → index.server-crrj0ef1.js} +1 -1
- package/dist/server/{index.server-zj0x74bt.js → index.server-d4j8rztt.js} +1 -1
- package/dist/server/{index.server-a8gpnzgg.js → index.server-e2jq5490.js} +1 -1
- package/dist/server/{index.server-0dny4mhe.js → index.server-ehpdbjjt.js} +1 -1
- package/dist/server/{index.server-k21nfvxe.js → index.server-er0ge1w2.js} +3 -3
- package/dist/server/{index.server-p69bvf14.js → index.server-etg48ham.js} +1 -1
- package/dist/server/{index.server-s4pfz6pb.js → index.server-fdnzb16k.js} +1 -1
- package/dist/server/{index.server-b8m7ej8c.js → index.server-g8ehn08w.js} +1 -1
- package/dist/server/{index.server-ykvb4rcc.js → index.server-gg1jyyfe.js} +1 -1
- package/dist/server/{index.server-emqv9bz6.js → index.server-jd43fwkh.js} +1 -1
- package/dist/server/{index.server-zg0981gk.js → index.server-kk17whw8.js} +1 -1
- package/dist/server/{index.server-aywvs10h.js → index.server-n2s42qb6.js} +2 -2
- package/dist/server/{index.server-kszs0qx5.js → index.server-pp705ba7.js} +1 -1
- package/dist/server/{index.server-tkt7wm9w.js → index.server-qe7sgzpf.js} +1 -1
- package/dist/server/{index.server-hvp84h1d.js → index.server-qr1nsjzm.js} +1 -1
- package/dist/server/{index.server-jxcxe1sp.js → index.server-ras33ac4.js} +1 -1
- package/dist/server/{index.server-ye5xkaq2.js → index.server-sf0g2t1a.js} +1 -1
- package/dist/server/{index.server-h76gdmj1.js → index.server-tc9n0rwa.js} +1 -1
- package/dist/server/{index.server-j6wms88v.js → index.server-v4pecbt0.js} +2 -2
- package/dist/server/{index.server-bjj2hpx1.js → index.server-wdy49qrf.js} +1 -1
- package/dist/server/{index.server-cmz3t3zw.js → index.server-wk2ms64s.js} +1 -1
- package/dist/server/{index.server-spdds2hk.js → index.server-wksxfr9e.js} +1 -1
- package/dist/server/{index.server-zkhc16nf.js → index.server-wpdhc0y0.js} +1 -1
- package/dist/server/{index.server-c6namd71.js → index.server-wv9xge03.js} +1 -1
- package/dist/server/{index.server-d7twz1zm.js → index.server-xdqd2dvc.js} +1 -1
- package/dist/server/{index.server-d05m93p4.js → index.server-yty4hdcv.js} +1 -1
- package/dist/server/{index.server-936tfc73.js → index.server-zg7ctrjh.js} +1 -1
- package/dist/server/{index.server-nsdh6zgh.js → index.server-zwv8mamh.js} +1 -1
- package/dist/utilities/use-reduced-motion.svelte.d.ts +12 -1
- package/dist/utilities/use-reduced-motion.types.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/accordion-item/accordion-item.css +2 -1
- package/src/components/area-chart/area-chart.css +4 -2
- package/src/components/backdrop/backdrop.css +6 -1
- package/src/components/badge/badge.css +6 -6
- package/src/components/banner/banner.css +13 -0
- package/src/components/bar-chart/bar-chart.css +2 -1
- package/src/components/carousel/carousel.css +14 -1
- package/src/components/chip/chip.css +7 -7
- package/src/components/collapsible/collapsible.css +2 -1
- package/src/components/color-swatch-picker/color-swatch-picker.css +14 -0
- package/src/components/command-palette/command-palette.css +30 -19
- package/src/components/connection-indicator/connection-indicator.css +7 -3
- package/src/components/drawer/drawer.css +4 -2
- package/src/components/dropdown/dropdown.css +7 -1
- package/src/components/feed/feed.css +2 -1
- package/src/components/file-upload/file-upload.css +4 -2
- package/src/components/hover-card/hover-card.css +2 -1
- package/src/components/json-schema-editor/enum-composition.ts +77 -0
- package/src/components/json-schema-editor/enum-editor.svelte +293 -0
- package/src/components/json-schema-editor/form-view.svelte +5 -2
- package/src/components/json-schema-editor/json-schema-editor-impl.svelte +17 -1
- package/src/components/json-schema-editor/json-schema-editor.css +68 -35
- package/src/components/json-schema-editor/json-view.svelte +6 -7
- package/src/components/json-schema-editor/property-editor.constants.ts +1 -0
- package/src/components/json-schema-editor/property-editor.svelte +182 -23
- package/src/components/json-schema-editor/property-list.svelte +201 -130
- package/src/components/json-viewer/json-viewer.css +2 -1
- package/src/components/kanban-board/kanban-board.css +14 -2
- package/src/components/line-chart/line-chart.css +2 -1
- package/src/components/load-more/load-more.css +5 -0
- package/src/components/marquee/marquee.css +21 -3
- package/src/components/media-controls/media-controls.css +2 -1
- package/src/components/mega-menu/mega-menu.css +6 -3
- package/src/components/meter/meter.css +2 -1
- package/src/components/modal/modal.css +4 -2
- package/src/components/navigation-bar/navigation-bar.css +2 -1
- package/src/components/pagination/pagination.css +4 -2
- package/src/components/popover/popover.css +2 -1
- package/src/components/progress/progress.css +41 -4
- package/src/components/scroll-area/scroll-area.css +12 -0
- package/src/components/selection-popover/selection-popover.css +2 -1
- package/src/components/side-navigation-group/side-navigation-group.css +2 -1
- package/src/components/skeleton/skeleton.css +7 -1
- package/src/components/slider/slider.css +4 -2
- package/src/components/sortable-list/sortable-list.css +6 -3
- package/src/components/sparkbar/sparkbar.css +2 -1
- package/src/components/speed-dial/speed-dial.css +2 -1
- package/src/components/spinner/spinner.css +15 -2
- package/src/components/spinner/spinner.variables.json +1 -1
- package/src/components/spinner/spinner.variables.ts +1 -1
- package/src/components/status-dot/status-dot.css +3 -1
- package/src/components/table-of-contents/table-of-contents.css +2 -1
- package/src/components/toast-region/toast-region.css +5 -3
- package/src/components/toggle/toggle.css +3 -2
- package/src/components/toolbar/toolbar.css +1 -1
- package/src/components/tooltip/tooltip.css +2 -1
- package/src/index.ts +9 -2
- package/src/styles/foundation.css +18 -3
- package/src/styles/tokens-base.css +172 -30
- package/src/utilities/use-reduced-motion.svelte.ts +63 -4
- package/src/utilities/use-reduced-motion.types.ts +2 -0
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -319,8 +319,10 @@
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
@media (prefers-reduced-motion: reduce) {
|
|
322
|
-
|
|
323
|
-
|
|
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
|
}
|
|
@@ -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
|
|
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} />
|