@lostgradient/cinder 0.24.5 → 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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Json_schema_editor,
3
3
  json_schema_editor_default
4
- } from "../../index.server-tb414d8x.js";
4
+ } from "../../index.server-4entcat5.js";
5
5
  import"../../index.server-sz6y8xqk.js";
6
6
  import"../../index.server-mm728d0w.js";
7
7
  import"../../index.server-w9dtc4a2.js";
@@ -326,7 +326,7 @@ import {
326
326
  import {
327
327
  json_schema_editor_default,
328
328
  useHistory
329
- } from "./index.server-tb414d8x.js";
329
+ } from "./index.server-4entcat5.js";
330
330
  import"./index.server-sz6y8xqk.js";
331
331
  import"./index.server-mm728d0w.js";
332
332
  import"./index.server-w9dtc4a2.js";
@@ -326,7 +326,7 @@ function Property_editor_constraints($$renderer, $$props) {
326
326
 
327
327
  // src/components/json-schema-editor/property-list.svelte
328
328
  import * as $3 from "svelte/internal/server";
329
- import { onDestroy } from "svelte";
329
+ import { onDestroy, tick } from "svelte";
330
330
  import Badge2 from "@lostgradient/cinder/badge";
331
331
  import Collapsible2 from "@lostgradient/cinder/collapsible";
332
332
 
@@ -387,7 +387,7 @@ function Property_list($$renderer, $$props) {
387
387
  return;
388
388
  }
389
389
  renameError = null;
390
- const next = {};
390
+ const next = Object.create(null);
391
391
  for (const k of propertyNames()) {
392
392
  next[k === oldKey ? draft : k] = properties[k];
393
393
  }
@@ -404,9 +404,33 @@ function Property_list($$renderer, $$props) {
404
404
  }
405
405
  onValueChange(next, nextRequired);
406
406
  }
407
- function deleteProperty(key) {
407
+ let actionAnnouncement = "";
408
+ const propertyTriggerElements = new Map;
409
+ let addPropertyElement = undefined;
410
+ function propertyTrigger(element, key) {
411
+ propertyTriggerElements.set(key, element);
412
+ return {
413
+ update(nextKey) {
414
+ if (nextKey === key)
415
+ return;
416
+ propertyTriggerElements.delete(key);
417
+ key = nextKey;
418
+ propertyTriggerElements.set(key, element);
419
+ },
420
+ destroy() {
421
+ propertyTriggerElements.delete(key);
422
+ }
423
+ };
424
+ }
425
+ async function announceAction(message) {
426
+ actionAnnouncement = "";
427
+ await tick();
428
+ actionAnnouncement = message;
429
+ }
430
+ async function deleteProperty(key, index) {
408
431
  if (readonly)
409
432
  return;
433
+ const focusKey = propertyNames()[index + 1] ?? propertyNames()[index - 1];
410
434
  const next = { ...properties };
411
435
  delete next[key];
412
436
  const nextRequired = required.filter((name) => name !== key);
@@ -415,6 +439,10 @@ function Property_list($$renderer, $$props) {
415
439
  const { [key]: _removedChildCount, ...remainingChildCounts } = childValidationCounts;
416
440
  childValidationCounts = remainingChildCounts;
417
441
  onValueChange(next, nextRequired);
442
+ await announceAction(`Deleted ${key} property.`);
443
+ await tick();
444
+ const focusTarget = focusKey ? propertyTriggerElements.get(focusKey) : addPropertyElement?.querySelector("button");
445
+ focusTarget?.focus();
418
446
  }
419
447
  function setChildValidationErrorCount(key, count) {
420
448
  if ((childValidationCounts[key] ?? 0) === count)
@@ -431,19 +459,30 @@ function Property_list($$renderer, $$props) {
431
459
  if (isOpen)
432
460
  setChildValidationErrorCount(key, 0);
433
461
  }
434
- function moveProperty(key, direction) {
435
- if (readonly)
462
+ async function moveProperty(key, direction, index) {
463
+ if (readonly || !canMoveProperty(index, direction))
436
464
  return;
437
- const index = propertyNames().indexOf(key);
438
465
  const target = index + direction;
439
466
  if (target < 0 || target >= propertyNames().length)
440
467
  return;
441
468
  const reordered = [...propertyNames()];
442
469
  [reordered[index], reordered[target]] = [reordered[target], reordered[index]];
443
- const next = {};
470
+ const next = Object.create(null);
444
471
  for (const name of reordered)
445
472
  next[name] = properties[name];
446
473
  onValueChange(next, required);
474
+ await announceAction(`Moved ${key} property to position ${target + 1} of ${reordered.length}.`);
475
+ }
476
+ function canMoveProperty(index, direction) {
477
+ const target = index + direction;
478
+ if (target < 0 || target >= propertyNames().length)
479
+ return false;
480
+ const reordered = [...propertyNames()];
481
+ [reordered[index], reordered[target]] = [reordered[target], reordered[index]];
482
+ const next = Object.create(null);
483
+ for (const name of reordered)
484
+ next[name] = properties[name];
485
+ return Object.keys(next).every((name, nextIndex) => name === reordered[nextIndex]);
447
486
  }
448
487
  function toggleRequired(key) {
449
488
  if (readonly)
@@ -498,7 +537,7 @@ function Property_list($$renderer, $$props) {
498
537
  return;
499
538
  onValueChange(properties, required.filter((entry) => entry !== name));
500
539
  }
501
- $$renderer2.push(`<div class="cinder-jse-property-list">`);
540
+ $$renderer2.push(`<p class="cinder-sr-only" aria-live="polite">${$3.escape(actionAnnouncement)}</p> <div class="cinder-jse-property-list">`);
502
541
  if (renameError) {
503
542
  $$renderer2.push("<!--[0-->");
504
543
  Alert($$renderer2, {
@@ -520,13 +559,13 @@ function Property_list($$renderer, $$props) {
520
559
  }
521
560
  $$renderer2.push(`<!--]--> <!--[-->`);
522
561
  const each_array = $3.ensure_array_like(propertyNames());
523
- for (let $$index = 0, $$length = each_array.length;$$index < $$length; $$index++) {
524
- let key = each_array[$$index];
562
+ for (let index = 0, $$length = each_array.length;index < $$length; index++) {
563
+ let key = each_array[index];
525
564
  const isRequired = required.includes(key);
526
565
  const isOpen = expanded[key] === true;
527
566
  const childValidationErrorCount = childValidationCounts[key] ?? 0;
528
567
  const panelId = `${idPrefix}-${key}-panel`;
529
- $$renderer2.push(`<div class="cinder-jse-property-row"${$3.attr("data-cinder-required", isRequired ? "" : undefined)}${$3.attr("data-cinder-invalid", childValidationErrorCount > 0 ? "" : undefined)}><div class="cinder-jse-property-row__summary"${$3.attr_style(`--cinder-jse-property-depth: ${depth}`)}><button type="button" class="cinder-jse-property-row__trigger"${$3.attr("aria-label", `${isOpen ? "Collapse" : "Expand"} ${key} property${childValidationErrorCount > 0 ? `, ${childValidationErrorCount} validation ${childValidationErrorCount === 1 ? "error" : "errors"}` : ""}`)}${$3.attr("aria-expanded", isOpen)}${$3.attr("aria-controls", panelId)}>`);
568
+ $$renderer2.push(`<div class="cinder-jse-property-row"${$3.attr("data-cinder-required", isRequired ? "" : undefined)}${$3.attr("data-cinder-invalid", childValidationErrorCount > 0 ? "" : undefined)}><div class="cinder-jse-property-row__summary"${$3.attr_style(`--cinder-jse-property-depth: ${depth}`)}><button type="button" class="cinder-jse-property-row__trigger"${$3.attr("aria-label", `${isOpen ? "Collapse" : "Expand"} ${key} property${childValidationErrorCount > 0 ? `, ${childValidationErrorCount} validation ${childValidationErrorCount === 1 ? "error" : "errors"}` : ""}`)}${$3.attr("aria-expanded", isOpen)}${$3.attr("aria-controls", isOpen ? panelId : undefined)}>`);
530
569
  Chevron_down($$renderer2, {
531
570
  class: "cinder-jse-property-row__chevron",
532
571
  size: 14,
@@ -554,7 +593,7 @@ function Property_list($$renderer, $$props) {
554
593
  size: "xs",
555
594
  disabled: readonly,
556
595
  "aria-pressed": isRequired,
557
- "aria-label": isRequired ? "Required (toggle off)" : "Optional (toggle required)",
596
+ "aria-label": `${key}: ${isRequired ? "Required (toggle off)" : "Optional (toggle required)"}`,
558
597
  onclick: () => toggleRequired(key),
559
598
  children: ($$renderer3) => {
560
599
  $$renderer3.push(`<!---->${$3.escape(isRequired ? "Required" : "Optional")}`);
@@ -565,9 +604,9 @@ function Property_list($$renderer, $$props) {
565
604
  Button($$renderer2, {
566
605
  variant: "ghost",
567
606
  size: "xs",
568
- disabled: readonly,
607
+ disabled: readonly || !canMoveProperty(index, -1),
569
608
  "aria-label": `Move ${key} up`,
570
- onclick: () => moveProperty(key, -1),
609
+ onclick: () => moveProperty(key, -1, index),
571
610
  children: ($$renderer3) => {
572
611
  $$renderer3.push(`<!---->↑`);
573
612
  },
@@ -577,9 +616,9 @@ function Property_list($$renderer, $$props) {
577
616
  Button($$renderer2, {
578
617
  variant: "ghost",
579
618
  size: "xs",
580
- disabled: readonly,
619
+ disabled: readonly || !canMoveProperty(index, 1),
581
620
  "aria-label": `Move ${key} down`,
582
- onclick: () => moveProperty(key, 1),
621
+ onclick: () => moveProperty(key, 1, index),
583
622
  children: ($$renderer3) => {
584
623
  $$renderer3.push(`<!---->↓`);
585
624
  },
@@ -591,7 +630,7 @@ function Property_list($$renderer, $$props) {
591
630
  size: "xs",
592
631
  disabled: readonly,
593
632
  "aria-label": `Delete ${key}`,
594
- onclick: () => deleteProperty(key),
633
+ onclick: () => deleteProperty(key, index),
595
634
  children: ($$renderer3) => {
596
635
  $$renderer3.push(`<!---->Delete`);
597
636
  },
@@ -625,7 +664,7 @@ function Property_list($$renderer, $$props) {
625
664
  }
626
665
  $$renderer2.push(`<!--]--></div>`);
627
666
  }
628
- $$renderer2.push(`<!--]--> `);
667
+ $$renderer2.push(`<!--]--> <span class="cinder-jse-property-list__add-property-reference">`);
629
668
  Button($$renderer2, {
630
669
  variant: "secondary",
631
670
  size: "sm",
@@ -636,7 +675,7 @@ function Property_list($$renderer, $$props) {
636
675
  },
637
676
  $$slots: { default: true }
638
677
  });
639
- $$renderer2.push(`<!----> `);
678
+ $$renderer2.push(`<!----></span> `);
640
679
  if (!readonly || requiredOnly().length > 0) {
641
680
  $$renderer2.push("<!--[0-->");
642
681
  Collapsible2($$renderer2, {
@@ -2477,4 +2516,4 @@ function Json_schema_editor($$renderer, $$props) {
2477
2516
  var json_schema_editor_default = Json_schema_editor;
2478
2517
  export { useHistory, Json_schema_editor, json_schema_editor_default };
2479
2518
 
2480
- //# debugId=0B7834071136231A64756E2164756E21
2519
+ //# debugId=400C62C9FEB3D0D164756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lostgradient/cinder",
3
- "version": "0.24.5",
3
+ "version": "0.24.6",
4
4
  "description": "A Svelte 5 component library and design system focused on accessibility, theming, and per-component tree-shaking.",
5
5
  "keywords": [
6
6
  "svelte",
@@ -174,6 +174,10 @@
174
174
  border-top: 0;
175
175
  }
176
176
 
177
+ .cinder-jse-property-list__add-property-reference {
178
+ display: contents;
179
+ }
180
+
177
181
  .cinder-jse-property-row[data-cinder-invalid] {
178
182
  border-inline-start: 2px solid var(--cinder-color-danger-border);
179
183
  }
@@ -4,7 +4,7 @@ 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';
@@ -57,7 +57,7 @@ function commitRename(oldKey) {
57
57
  return;
58
58
  }
59
59
  renameError = null;
60
- const next = {};
60
+ const next = Object.create(null);
61
61
  for (const k of propertyNames) {
62
62
  next[k === oldKey ? draft : k] = properties[k];
63
63
  }
@@ -74,9 +74,33 @@ function commitRename(oldKey) {
74
74
  }
75
75
  onValueChange(next, nextRequired);
76
76
  }
77
- 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) {
78
101
  if (readonly)
79
102
  return;
103
+ const focusKey = propertyNames[index + 1] ?? propertyNames[index - 1];
80
104
  const next = { ...properties };
81
105
  delete next[key];
82
106
  const nextRequired = required.filter((name) => name !== key);
@@ -85,6 +109,12 @@ function deleteProperty(key) {
85
109
  const { [key]: _removedChildCount, ...remainingChildCounts } = childValidationCounts;
86
110
  childValidationCounts = remainingChildCounts;
87
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();
88
118
  }
89
119
  function setChildValidationErrorCount(key, count) {
90
120
  if ((childValidationCounts[key] ?? 0) === count)
@@ -101,19 +131,30 @@ function toggleExpanded(key, isOpen) {
101
131
  if (isOpen)
102
132
  setChildValidationErrorCount(key, 0);
103
133
  }
104
- function moveProperty(key, direction) {
105
- if (readonly)
134
+ async function moveProperty(key, direction, index) {
135
+ if (readonly || !canMoveProperty(index, direction))
106
136
  return;
107
- const index = propertyNames.indexOf(key);
108
137
  const target = index + direction;
109
138
  if (target < 0 || target >= propertyNames.length)
110
139
  return;
111
140
  const reordered = [...propertyNames];
112
141
  [reordered[index], reordered[target]] = [reordered[target], reordered[index]];
113
- const next = {};
142
+ const next = Object.create(null);
114
143
  for (const name of reordered)
115
144
  next[name] = properties[name];
116
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]);
117
158
  }
118
159
  function toggleRequired(key) {
119
160
  if (readonly)
@@ -171,6 +212,8 @@ function removeRequiredOnly(name) {
171
212
  }
172
213
  </script>
173
214
 
215
+ <p class="cinder-sr-only" aria-live="polite">{actionAnnouncement}</p>
216
+
174
217
  <div class="cinder-jse-property-list">
175
218
  {#if renameError}
176
219
  <Alert variant="danger">{renameError}</Alert>
@@ -180,7 +223,7 @@ function removeRequiredOnly(name) {
180
223
  <p class="cinder-jse-property-list__empty">No properties yet.</p>
181
224
  {/if}
182
225
 
183
- {#each propertyNames as key (key)}
226
+ {#each propertyNames as key, index (key)}
184
227
  {@const isRequired = required.includes(key)}
185
228
  {@const isOpen = expanded[key] === true}
186
229
  {@const childValidationErrorCount = childValidationCounts[key] ?? 0}
@@ -198,11 +241,12 @@ function removeRequiredOnly(name) {
198
241
  >
199
242
  <div class="cinder-jse-property-row__summary" style={`--cinder-jse-property-depth: ${depth}`}>
200
243
  <button
244
+ use:propertyTrigger={key}
201
245
  type="button"
202
246
  class="cinder-jse-property-row__trigger"
203
247
  aria-label={`${isOpen ? 'Collapse' : 'Expand'} ${key} property${childValidationErrorCount > 0 ? `, ${childValidationErrorCount} validation ${childValidationErrorCount === 1 ? 'error' : 'errors'}` : ''}`}
204
248
  aria-expanded={isOpen}
205
- aria-controls={panelId}
249
+ aria-controls={isOpen ? panelId : undefined}
206
250
  onclick={() => toggleExpanded(key, isOpen)}
207
251
  >
208
252
  <ChevronDown
@@ -229,7 +273,7 @@ function removeRequiredOnly(name) {
229
273
  size="xs"
230
274
  disabled={readonly}
231
275
  aria-pressed={isRequired}
232
- aria-label={isRequired ? 'Required (toggle off)' : 'Optional (toggle required)'}
276
+ aria-label={`${key}: ${isRequired ? 'Required (toggle off)' : 'Optional (toggle required)'}`}
233
277
  onclick={() => toggleRequired(key)}
234
278
  >
235
279
  {isRequired ? 'Required' : 'Optional'}
@@ -237,18 +281,18 @@ function removeRequiredOnly(name) {
237
281
  <Button
238
282
  variant="ghost"
239
283
  size="xs"
240
- disabled={readonly}
284
+ disabled={readonly || !canMoveProperty(index, -1)}
241
285
  aria-label={`Move ${key} up`}
242
- onclick={() => moveProperty(key, -1)}
286
+ onclick={() => moveProperty(key, -1, index)}
243
287
  >
244
288
  ↑
245
289
  </Button>
246
290
  <Button
247
291
  variant="ghost"
248
292
  size="xs"
249
- disabled={readonly}
293
+ disabled={readonly || !canMoveProperty(index, 1)}
250
294
  aria-label={`Move ${key} down`}
251
- onclick={() => moveProperty(key, 1)}
295
+ onclick={() => moveProperty(key, 1, index)}
252
296
  >
253
297
  ↓
254
298
  </Button>
@@ -257,7 +301,7 @@ function removeRequiredOnly(name) {
257
301
  size="xs"
258
302
  disabled={readonly}
259
303
  aria-label={`Delete ${key}`}
260
- onclick={() => deleteProperty(key)}
304
+ onclick={() => deleteProperty(key, index)}
261
305
  >
262
306
  Delete
263
307
  </Button>
@@ -287,9 +331,11 @@ function removeRequiredOnly(name) {
287
331
  </div>
288
332
  {/each}
289
333
 
290
- <Button variant="secondary" size="sm" disabled={readonly} onclick={addProperty}>
291
- Add property
292
- </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>
293
339
 
294
340
  {#if !readonly || requiredOnly.length > 0}
295
341
  <Collapsible