@lostgradient/cinder 0.24.4 → 0.24.6

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 (26) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/components.json +1 -1
  3. package/dist/components/json-schema-editor/index.js +2147 -5517
  4. package/dist/components/json-schema-editor/json-schema-editor-state.svelte.d.ts +1 -0
  5. package/dist/components/json-schema-editor/json-schema-editor.css +8 -0
  6. package/dist/components/waveform/index.js +17 -5
  7. package/dist/components/waveform/waveform.css +27 -0
  8. package/dist/index.js +510 -428
  9. package/dist/server/components/json-schema-editor/index.js +2 -10
  10. package/dist/server/components/waveform/index.js +1 -1
  11. package/dist/server/index.js +2 -2
  12. package/dist/server/{index.server-7h3nmj3g.js → index.server-4entcat5.js} +119 -76
  13. package/dist/server/{index.server-tdrncj5e.js → index.server-qhfya7fx.js} +10 -3
  14. package/package.json +2 -1
  15. package/src/components/json-schema-editor/diff-view.svelte +1 -1
  16. package/src/components/json-schema-editor/json-schema-editor-impl.svelte +2 -2
  17. package/src/components/json-schema-editor/json-schema-editor-state.svelte.ts +26 -16
  18. package/src/components/json-schema-editor/json-schema-editor.css +8 -0
  19. package/src/components/json-schema-editor/json-schema-toolbar.svelte +2 -2
  20. package/src/components/json-schema-editor/json-schema-validator.ts +17 -3
  21. package/src/components/json-schema-editor/property-editor.constants.ts +0 -1
  22. package/src/components/json-schema-editor/property-editor.svelte +4 -10
  23. package/src/components/json-schema-editor/property-list.svelte +83 -22
  24. package/src/components/waveform/waveform.css +27 -0
  25. package/src/components/waveform/waveform.svelte +28 -15
  26. package/src/styles/tokens-base.css +3 -3
@@ -63,7 +63,7 @@ $effect(() => {
63
63
  // when participation changes.
64
64
  void editorState.canUndo;
65
65
  void editorState.canRedo;
66
- void editorState.hasChanges;
66
+ void editorState.hasDiffChanges;
67
67
  void editorState.readonly;
68
68
  void editorState.copyValue;
69
69
  // Track `rovingIndex` too so a keydown/focusin handler moving the roved
@@ -175,7 +175,7 @@ function handleRightFocusin(event) {
175
175
  size="sm"
176
176
  iconOnly
177
177
  label="Revert"
178
- disabled={!editorState.hasChanges || editorState.readonly}
178
+ disabled={!editorState.hasDiffChanges || editorState.readonly}
179
179
  onclick={() => onRevert?.()}
180
180
  >
181
181
  <RotateCcw class="cinder-icon-sm" />
@@ -19,6 +19,7 @@
19
19
  */
20
20
 
21
21
  import type Ajv from 'ajv';
22
+ import type { FormatsPlugin } from 'ajv-formats';
22
23
  import type Ajv2019 from 'ajv/dist/2019.js';
23
24
  import type Ajv2020 from 'ajv/dist/2020.js';
24
25
 
@@ -83,6 +84,15 @@ const loadAjv2019 = createRetryingLoaderCache(() =>
83
84
  const loadAjv2020 = createRetryingLoaderCache(() =>
84
85
  import('ajv/dist/2020.js').then((module) => module.default),
85
86
  );
87
+ const loadAjvFormats = createRetryingLoaderCache(() =>
88
+ import('ajv-formats').then((module) => module.default),
89
+ );
90
+
91
+ async function registerStandardFormats(ajv: Ajv | Ajv2019 | Ajv2020) {
92
+ const formats: FormatsPlugin = await loadAjvFormats();
93
+ formats(ajv);
94
+ return ajv;
95
+ }
86
96
 
87
97
  // Long-lived meta-schema validators. Safe to share — they don't compile the
88
98
  // user's schema, only validate against the meta-schema.
@@ -192,13 +202,17 @@ export async function tryCompile(
192
202
  let ajv: Ajv | Ajv2020 | Ajv2019;
193
203
  if (resolved === '2020-12') {
194
204
  const Ajv2020Class = await loadAjv2020();
195
- ajv = new Ajv2020Class({ strict: false, addUsedSchema: false });
205
+ ajv = await registerStandardFormats(
206
+ new Ajv2020Class({ strict: false, addUsedSchema: false }),
207
+ );
196
208
  } else if (resolved === '2019-09') {
197
209
  const Ajv2019Class = await loadAjv2019();
198
- ajv = new Ajv2019Class({ strict: false, addUsedSchema: false });
210
+ ajv = await registerStandardFormats(
211
+ new Ajv2019Class({ strict: false, addUsedSchema: false }),
212
+ );
199
213
  } else {
200
214
  const AjvClass = await loadAjv();
201
- ajv = new AjvClass({ strict: false, addUsedSchema: false });
215
+ ajv = await registerStandardFormats(new AjvClass({ strict: false, addUsedSchema: false }));
202
216
  }
203
217
 
204
218
  ajv.compile(schema);
@@ -18,7 +18,6 @@ export const EDITABLE_KEYWORDS = new Set([
18
18
  'default',
19
19
  'examples',
20
20
  'const',
21
- 'enum',
22
21
  'minLength',
23
22
  'maxLength',
24
23
  'pattern',
@@ -14,7 +14,6 @@ import Button from '../button/button.svelte';
14
14
  import Checkbox from '../checkbox/checkbox.svelte';
15
15
  import Collapsible from '@lostgradient/cinder/collapsible';
16
16
  import Input from '../input/input.svelte';
17
- import Tooltip from '../tooltip/tooltip.svelte';
18
17
  import { reconcileCompositionBranchKeys } from './composition-branch-keys.ts';
19
18
  import { DEFAULT_COLLAPSE_DEPTH, EDITABLE_KEYWORDS, MAX_RENDER_DEPTH, PRIMITIVE_TYPES, } from './property-editor.constants.ts';
20
19
  import PropertyEditor from './property-editor.svelte';
@@ -416,19 +415,14 @@ function addCompositionBranch(keyword) {
416
415
  >
417
416
  Add $ref
418
417
  </Button>
419
- {#if preservedKeys.length > 0}
420
- <Tooltip text={`Preserved keys: ${preservedKeys.join(', ')}`}>
421
- <Badge variant="info">+{preservedKeys.length} preserved</Badge>
422
- </Tooltip>
423
- {/if}
424
418
  </div>
425
419
  {/if}
426
420
 
427
- <!-- Preserved-keywords badge for the readonly case (Add $ref is hidden). -->
428
- {#if readonly && objectValue.$ref === undefined && preservedKeys.length > 0}
429
- <Tooltip text={`Preserved keys: ${preservedKeys.join(', ')}`}>
421
+ {#if preservedKeys.length > 0}
422
+ <div class="cinder-jse-advanced-row">
430
423
  <Badge variant="info">+{preservedKeys.length} preserved</Badge>
431
- </Tooltip>
424
+ <span>Preserved keywords: {preservedKeys.join(', ')}</span>
425
+ </div>
432
426
  {/if}
433
427
  {/if}
434
428
  </div>
@@ -4,10 +4,11 @@ export {};
4
4
 
5
5
  <script lang="ts">
6
6
  import ChevronDown from 'lucide-svelte/icons/chevron-down';
7
- import { onDestroy } from 'svelte';
7
+ import { onDestroy, tick } from 'svelte';
8
8
  import Alert from '../alert/alert.svelte';
9
9
  import Button from '../button/button.svelte';
10
10
  import Chip from '../chip/chip.svelte';
11
+ import Badge from '@lostgradient/cinder/badge';
11
12
  import Collapsible from '@lostgradient/cinder/collapsible';
12
13
  import Input from '../input/input.svelte';
13
14
  import PropertyEditor from './property-editor.svelte';
@@ -56,7 +57,7 @@ function commitRename(oldKey) {
56
57
  return;
57
58
  }
58
59
  renameError = null;
59
- const next = {};
60
+ const next = Object.create(null);
60
61
  for (const k of propertyNames) {
61
62
  next[k === oldKey ? draft : k] = properties[k];
62
63
  }
@@ -73,9 +74,33 @@ function commitRename(oldKey) {
73
74
  }
74
75
  onValueChange(next, nextRequired);
75
76
  }
76
- function deleteProperty(key) {
77
+ let actionAnnouncement = $state('');
78
+ const propertyTriggerElements = new Map();
79
+ let addPropertyElement = $state();
80
+ function propertyTrigger(element, key) {
81
+ propertyTriggerElements.set(key, element);
82
+ return {
83
+ update(nextKey) {
84
+ if (nextKey === key)
85
+ return;
86
+ propertyTriggerElements.delete(key);
87
+ key = nextKey;
88
+ propertyTriggerElements.set(key, element);
89
+ },
90
+ destroy() {
91
+ propertyTriggerElements.delete(key);
92
+ },
93
+ };
94
+ }
95
+ async function announceAction(message) {
96
+ actionAnnouncement = '';
97
+ await tick();
98
+ actionAnnouncement = message;
99
+ }
100
+ async function deleteProperty(key, index) {
77
101
  if (readonly)
78
102
  return;
103
+ const focusKey = propertyNames[index + 1] ?? propertyNames[index - 1];
79
104
  const next = { ...properties };
80
105
  delete next[key];
81
106
  const nextRequired = required.filter((name) => name !== key);
@@ -84,6 +109,12 @@ function deleteProperty(key) {
84
109
  const { [key]: _removedChildCount, ...remainingChildCounts } = childValidationCounts;
85
110
  childValidationCounts = remainingChildCounts;
86
111
  onValueChange(next, nextRequired);
112
+ await announceAction(`Deleted ${key} property.`);
113
+ await tick();
114
+ const focusTarget = focusKey
115
+ ? propertyTriggerElements.get(focusKey)
116
+ : addPropertyElement?.querySelector('button');
117
+ focusTarget?.focus();
87
118
  }
88
119
  function setChildValidationErrorCount(key, count) {
89
120
  if ((childValidationCounts[key] ?? 0) === count)
@@ -100,19 +131,30 @@ function toggleExpanded(key, isOpen) {
100
131
  if (isOpen)
101
132
  setChildValidationErrorCount(key, 0);
102
133
  }
103
- function moveProperty(key, direction) {
104
- if (readonly)
134
+ async function moveProperty(key, direction, index) {
135
+ if (readonly || !canMoveProperty(index, direction))
105
136
  return;
106
- const index = propertyNames.indexOf(key);
107
137
  const target = index + direction;
108
138
  if (target < 0 || target >= propertyNames.length)
109
139
  return;
110
140
  const reordered = [...propertyNames];
111
141
  [reordered[index], reordered[target]] = [reordered[target], reordered[index]];
112
- const next = {};
142
+ const next = Object.create(null);
113
143
  for (const name of reordered)
114
144
  next[name] = properties[name];
115
145
  onValueChange(next, required);
146
+ await announceAction(`Moved ${key} property to position ${target + 1} of ${reordered.length}.`);
147
+ }
148
+ function canMoveProperty(index, direction) {
149
+ const target = index + direction;
150
+ if (target < 0 || target >= propertyNames.length)
151
+ return false;
152
+ const reordered = [...propertyNames];
153
+ [reordered[index], reordered[target]] = [reordered[target], reordered[index]];
154
+ const next = Object.create(null);
155
+ for (const name of reordered)
156
+ next[name] = properties[name];
157
+ return Object.keys(next).every((name, nextIndex) => name === reordered[nextIndex]);
116
158
  }
117
159
  function toggleRequired(key) {
118
160
  if (readonly)
@@ -170,6 +212,8 @@ function removeRequiredOnly(name) {
170
212
  }
171
213
  </script>
172
214
 
215
+ <p class="cinder-sr-only" aria-live="polite">{actionAnnouncement}</p>
216
+
173
217
  <div class="cinder-jse-property-list">
174
218
  {#if renameError}
175
219
  <Alert variant="danger">{renameError}</Alert>
@@ -179,9 +223,10 @@ function removeRequiredOnly(name) {
179
223
  <p class="cinder-jse-property-list__empty">No properties yet.</p>
180
224
  {/if}
181
225
 
182
- {#each propertyNames as key (key)}
226
+ {#each propertyNames as key, index (key)}
183
227
  {@const isRequired = required.includes(key)}
184
228
  {@const isOpen = expanded[key] === true}
229
+ {@const childValidationErrorCount = childValidationCounts[key] ?? 0}
185
230
  {@const panelId = `${idPrefix}-${key}-panel`}
186
231
  <!--
187
232
  Custom disclosure (not <details>/<summary>) so the action buttons can
@@ -189,14 +234,19 @@ function removeRequiredOnly(name) {
189
234
  <button> inside <summary> creates an ARIA "interactive within
190
235
  interactive" violation.
191
236
  -->
192
- <div class="cinder-jse-property-row" data-cinder-required={isRequired ? '' : undefined}>
237
+ <div
238
+ class="cinder-jse-property-row"
239
+ data-cinder-required={isRequired ? '' : undefined}
240
+ data-cinder-invalid={childValidationErrorCount > 0 ? '' : undefined}
241
+ >
193
242
  <div class="cinder-jse-property-row__summary" style={`--cinder-jse-property-depth: ${depth}`}>
194
243
  <button
244
+ use:propertyTrigger={key}
195
245
  type="button"
196
246
  class="cinder-jse-property-row__trigger"
197
- aria-label={`${isOpen ? 'Collapse' : 'Expand'} ${key} property`}
247
+ aria-label={`${isOpen ? 'Collapse' : 'Expand'} ${key} property${childValidationErrorCount > 0 ? `, ${childValidationErrorCount} validation ${childValidationErrorCount === 1 ? 'error' : 'errors'}` : ''}`}
198
248
  aria-expanded={isOpen}
199
- aria-controls={panelId}
249
+ aria-controls={isOpen ? panelId : undefined}
200
250
  onclick={() => toggleExpanded(key, isOpen)}
201
251
  >
202
252
  <ChevronDown
@@ -207,6 +257,15 @@ function removeRequiredOnly(name) {
207
257
  />
208
258
  <span class="cinder-jse-property-row__name">{key}</span>
209
259
  <span class="cinder-jse-property-row__type">{summariseType(properties[key] ?? {})}</span>
260
+ {#if childValidationErrorCount > 0}
261
+ <Badge
262
+ variant="danger"
263
+ aria-label={`${childValidationErrorCount} validation ${childValidationErrorCount === 1 ? 'error' : 'errors'} in ${key}`}
264
+ >
265
+ {childValidationErrorCount}{' '}
266
+ {childValidationErrorCount === 1 ? 'error' : 'errors'}
267
+ </Badge>
268
+ {/if}
210
269
  </button>
211
270
  <span class="cinder-jse-property-row__spacer"></span>
212
271
  <Button
@@ -214,7 +273,7 @@ function removeRequiredOnly(name) {
214
273
  size="xs"
215
274
  disabled={readonly}
216
275
  aria-pressed={isRequired}
217
- aria-label={isRequired ? 'Required (toggle off)' : 'Optional (toggle required)'}
276
+ aria-label={`${key}: ${isRequired ? 'Required (toggle off)' : 'Optional (toggle required)'}`}
218
277
  onclick={() => toggleRequired(key)}
219
278
  >
220
279
  {isRequired ? 'Required' : 'Optional'}
@@ -222,18 +281,18 @@ function removeRequiredOnly(name) {
222
281
  <Button
223
282
  variant="ghost"
224
283
  size="xs"
225
- disabled={readonly}
226
- aria-label="Move up"
227
- onclick={() => moveProperty(key, -1)}
284
+ disabled={readonly || !canMoveProperty(index, -1)}
285
+ aria-label={`Move ${key} up`}
286
+ onclick={() => moveProperty(key, -1, index)}
228
287
  >
229
288
  ↑
230
289
  </Button>
231
290
  <Button
232
291
  variant="ghost"
233
292
  size="xs"
234
- disabled={readonly}
235
- aria-label="Move down"
236
- onclick={() => moveProperty(key, 1)}
293
+ disabled={readonly || !canMoveProperty(index, 1)}
294
+ aria-label={`Move ${key} down`}
295
+ onclick={() => moveProperty(key, 1, index)}
237
296
  >
238
297
  ↓
239
298
  </Button>
@@ -242,7 +301,7 @@ function removeRequiredOnly(name) {
242
301
  size="xs"
243
302
  disabled={readonly}
244
303
  aria-label={`Delete ${key}`}
245
- onclick={() => deleteProperty(key)}
304
+ onclick={() => deleteProperty(key, index)}
246
305
  >
247
306
  Delete
248
307
  </Button>
@@ -272,9 +331,11 @@ function removeRequiredOnly(name) {
272
331
  </div>
273
332
  {/each}
274
333
 
275
- <Button variant="secondary" size="sm" disabled={readonly} onclick={addProperty}>
276
- Add property
277
- </Button>
334
+ <span class="cinder-jse-property-list__add-property-reference" bind:this={addPropertyElement}>
335
+ <Button variant="secondary" size="sm" disabled={readonly} onclick={addProperty}>
336
+ Add property
337
+ </Button>
338
+ </span>
278
339
 
279
340
  {#if !readonly || requiredOnly.length > 0}
280
341
  <Collapsible
@@ -3,6 +3,8 @@
3
3
  .cinder-waveform {
4
4
  display: grid;
5
5
  gap: var(--cinder-space-2);
6
+ min-inline-size: 0;
7
+ max-inline-size: 100%;
6
8
  color: var(--_cinder-chart-foreground, currentColor);
7
9
  background: var(--_cinder-chart-background, transparent);
8
10
  }
@@ -17,6 +19,31 @@
17
19
  position: relative;
18
20
  }
19
21
 
22
+ .cinder-waveform__table-scroll {
23
+ inline-size: 100%;
24
+ max-inline-size: 100%;
25
+ overflow-x: auto;
26
+ overscroll-behavior-inline: contain;
27
+ -webkit-overflow-scrolling: touch;
28
+ }
29
+
30
+ .cinder-waveform__table-scroll > table {
31
+ min-inline-size: max-content;
32
+ }
33
+
34
+ .cinder-waveform__table-scroll:focus-visible {
35
+ outline: var(--cinder-ring-width) solid transparent;
36
+ box-shadow: var(--_cinder-focus-ring-shadow);
37
+ }
38
+
39
+ @media (forced-colors: active) {
40
+ .cinder-waveform__table-scroll:focus-visible {
41
+ outline: var(--cinder-ring-width) solid ButtonText;
42
+ outline-offset: 2px;
43
+ box-shadow: none;
44
+ }
45
+ }
46
+
20
47
  .cinder-waveform svg {
21
48
  display: block;
22
49
  inline-size: 100%;
@@ -227,22 +227,35 @@ const tableCaption = $derived.by(() => {
227
227
  </svg>
228
228
  </div>
229
229
  {#if hasDataTable}
230
- <table class={dataTableClass(dataTableVisibility)}>
231
- <caption>{tableCaption}</caption>
232
- <thead>
233
- <tr>
234
- <th scope="col">Sample index</th>
235
- <th scope="col">Amplitude</th>
236
- </tr>
237
- </thead>
238
- <tbody>
239
- {#each tableSamples as sample (sample.index)}
230
+ <div
231
+ class={dataTableVisibility === 'screen-reader-only'
232
+ ? 'cinder-sr-only'
233
+ : 'cinder-waveform__table-scroll'}
234
+ {...dataTableVisibility === 'visible'
235
+ ? { role: 'region', 'aria-label': `${label} data table`, tabindex: 0 }
236
+ : {}}
237
+ >
238
+ <table
239
+ class={dataTableClass(
240
+ dataTableVisibility === 'screen-reader-only' ? 'visible' : dataTableVisibility,
241
+ )}
242
+ >
243
+ <caption>{tableCaption}</caption>
244
+ <thead>
240
245
  <tr>
241
- <td>{sample.index}</td>
242
- <td>{sample.value.toFixed(4)}</td>
246
+ <th scope="col">Sample index</th>
247
+ <th scope="col">Amplitude</th>
243
248
  </tr>
244
- {/each}
245
- </tbody>
246
- </table>
249
+ </thead>
250
+ <tbody>
251
+ {#each tableSamples as sample (sample.index)}
252
+ <tr>
253
+ <td>{sample.index}</td>
254
+ <td>{sample.value.toFixed(4)}</td>
255
+ </tr>
256
+ {/each}
257
+ </tbody>
258
+ </table>
259
+ </div>
247
260
  {/if}
248
261
  </figure>
@@ -478,7 +478,7 @@
478
478
  * accent (≥5:1) and the dark page bg (≥18:1). Used by FloatingAction
479
479
  * primary variant. Raw oklch is legitimate here (tokens-base.css is the
480
480
  * one place raw colors are allowed). */
481
- --cinder-ring-on-accent: light-dark(oklch(20% 0.02 245), oklch(95% 0.01 245));
481
+ --cinder-ring-on-accent: light-dark(oklch(15% 0.035 245), oklch(100% 0 0));
482
482
 
483
483
  /* Focus ring.
484
484
  *
@@ -694,7 +694,7 @@
694
694
  --cinder-scrollbar-thumb: oklch(100% 0 0 / 0.45);
695
695
  --cinder-scrollbar-thumb-hover: oklch(100% 0 0 / 0.65);
696
696
  --cinder-ring-offset-color: var(--cinder-surface-raised);
697
- --cinder-ring-on-accent: oklch(95% 0.01 245);
697
+ --cinder-ring-on-accent: oklch(100% 0 0);
698
698
  --cinder-ring-color: oklch(from var(--cinder-accent) 0.7 0.14 h);
699
699
  --cinder-button-bg: var(--cinder-surface-raised);
700
700
  --cinder-button-fg: var(--cinder-text);
@@ -782,7 +782,7 @@
782
782
  --cinder-scrollbar-thumb: oklch(0% 0 0 / 0.45);
783
783
  --cinder-scrollbar-thumb-hover: oklch(0% 0 0 / 0.65);
784
784
  --cinder-ring-offset-color: var(--cinder-surface-raised);
785
- --cinder-ring-on-accent: oklch(20% 0.02 245);
785
+ --cinder-ring-on-accent: oklch(15% 0.035 245);
786
786
  --cinder-ring-color: oklch(from var(--cinder-accent) 0.55 0.16 h);
787
787
  --cinder-button-bg: var(--cinder-surface-raised);
788
788
  --cinder-button-fg: var(--cinder-text);