dssoca 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +3 -3
  2. package/dist/components/Accordion.svelte +23 -52
  3. package/dist/components/BottomNav.svelte +18 -28
  4. package/dist/components/BoxPlot.svelte +7 -6
  5. package/dist/components/BumpChart.svelte +9 -12
  6. package/dist/components/Chart.svelte +9 -12
  7. package/dist/components/Checkbox.svelte +210 -0
  8. package/dist/components/Checkbox.svelte.d.ts +38 -0
  9. package/dist/components/FileDrop.svelte +52 -83
  10. package/dist/components/FileDrop.svelte.d.ts +6 -2
  11. package/dist/components/Heatmap.svelte +8 -8
  12. package/dist/components/Image.svelte +44 -44
  13. package/dist/components/Input.svelte +8 -3
  14. package/dist/components/LogStream.svelte +15 -25
  15. package/dist/components/Menu.svelte +69 -94
  16. package/dist/components/Menu.svelte.d.ts +6 -0
  17. package/dist/components/Modal.svelte +61 -14
  18. package/dist/components/Modal.svelte.d.ts +7 -2
  19. package/dist/components/NumberField.svelte +18 -19
  20. package/dist/components/Pagination.svelte +47 -37
  21. package/dist/components/Pagination.svelte.d.ts +6 -2
  22. package/dist/components/Popover.svelte +247 -0
  23. package/dist/components/Popover.svelte.d.ts +36 -0
  24. package/dist/components/RadioGroup.svelte +227 -0
  25. package/dist/components/RadioGroup.svelte.d.ts +42 -0
  26. package/dist/components/ScatterPlot.svelte +11 -13
  27. package/dist/components/SearchPalette.svelte +124 -120
  28. package/dist/components/SearchPalette.svelte.d.ts +6 -4
  29. package/dist/components/SegmentedControl.svelte +41 -62
  30. package/dist/components/SegmentedControl.svelte.d.ts +7 -2
  31. package/dist/components/ShortcutsHelp.svelte +48 -47
  32. package/dist/components/Sidebar.svelte +48 -60
  33. package/dist/components/Switch.svelte +20 -10
  34. package/dist/components/Switch.svelte.d.ts +6 -2
  35. package/dist/components/Table.svelte +15 -37
  36. package/dist/components/Tabs.svelte +223 -0
  37. package/dist/components/Tabs.svelte.d.ts +51 -0
  38. package/dist/components/TierList.svelte +38 -38
  39. package/dist/components/TierList.svelte.d.ts +7 -3
  40. package/dist/components/Toaster.svelte +29 -29
  41. package/dist/components/Tooltip.svelte +37 -21
  42. package/dist/components/Topbar.svelte +13 -38
  43. package/dist/core/accordion.d.ts +32 -0
  44. package/dist/core/accordion.js +53 -0
  45. package/dist/core/behaviors/focusable.d.ts +5 -0
  46. package/dist/core/behaviors/focusable.js +14 -0
  47. package/dist/core/behaviors/roving.d.ts +13 -0
  48. package/dist/core/behaviors/roving.js +29 -0
  49. package/dist/core/bottom-nav.d.ts +36 -0
  50. package/dist/core/bottom-nav.js +33 -0
  51. package/dist/core/chart-nav.d.ts +53 -0
  52. package/dist/{chart-nav.js → core/chart-nav.js} +27 -0
  53. package/dist/core/checkbox.d.ts +36 -0
  54. package/dist/core/checkbox.js +29 -0
  55. package/dist/core/file-drop.d.ts +75 -0
  56. package/dist/core/file-drop.js +101 -0
  57. package/dist/core/image.d.ts +59 -0
  58. package/dist/core/image.js +64 -0
  59. package/dist/core/input.d.ts +21 -0
  60. package/dist/core/input.js +17 -0
  61. package/dist/core/log-stream.d.ts +51 -0
  62. package/dist/core/log-stream.js +50 -0
  63. package/dist/core/menu.d.ts +70 -0
  64. package/dist/core/menu.js +84 -0
  65. package/dist/core/modal.d.ts +59 -0
  66. package/dist/core/modal.js +44 -0
  67. package/dist/core/number-field.d.ts +47 -0
  68. package/dist/core/number-field.js +64 -0
  69. package/dist/core/pagination.d.ts +59 -0
  70. package/dist/core/pagination.js +65 -0
  71. package/dist/core/popover.d.ts +68 -0
  72. package/dist/core/popover.js +55 -0
  73. package/dist/core/radio.d.ts +36 -0
  74. package/dist/core/radio.js +48 -0
  75. package/dist/core/search-palette.d.ts +124 -0
  76. package/dist/core/search-palette.js +149 -0
  77. package/dist/core/segmented.d.ts +46 -0
  78. package/dist/core/segmented.js +66 -0
  79. package/dist/core/shortcuts-help.d.ts +56 -0
  80. package/dist/core/shortcuts-help.js +50 -0
  81. package/dist/core/sidebar.d.ts +63 -0
  82. package/dist/core/sidebar.js +84 -0
  83. package/dist/core/switch.d.ts +19 -0
  84. package/dist/core/switch.js +11 -0
  85. package/dist/core/table.d.ts +40 -0
  86. package/dist/core/table.js +57 -0
  87. package/dist/core/tabs.d.ts +84 -0
  88. package/dist/core/tabs.js +90 -0
  89. package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +62 -0
  90. package/dist/{tierlist-core.js → core/tierlist.js} +34 -0
  91. package/dist/core/toast.d.ts +112 -0
  92. package/dist/{toast-core.js → core/toast.js} +48 -2
  93. package/dist/core/tooltip.d.ts +47 -0
  94. package/dist/core/tooltip.js +51 -0
  95. package/dist/core/topbar.d.ts +41 -0
  96. package/dist/core/topbar.js +52 -0
  97. package/dist/dssoca.config.d.ts +1 -1
  98. package/dist/dssoca.config.js +4 -0
  99. package/dist/index.d.ts +14 -1
  100. package/dist/index.js +9 -1
  101. package/dist/theme.css +47 -0
  102. package/dist/toast.svelte.d.ts +2 -2
  103. package/dist/toast.svelte.js +1 -1
  104. package/dist/tokens.css +47 -0
  105. package/dist/vanilla/accordion.js +28 -29
  106. package/dist/vanilla/checkbox.d.ts +8 -0
  107. package/dist/vanilla/checkbox.js +43 -0
  108. package/dist/vanilla/delegate.d.ts +2 -0
  109. package/dist/vanilla/delegate.js +9 -0
  110. package/dist/vanilla/fields.js +37 -32
  111. package/dist/vanilla/index.d.ts +4 -0
  112. package/dist/vanilla/index.js +16 -3
  113. package/dist/vanilla/menu.js +92 -86
  114. package/dist/vanilla/modal.d.ts +3 -1
  115. package/dist/vanilla/modal.js +65 -15
  116. package/dist/vanilla/popover.d.ts +10 -0
  117. package/dist/vanilla/popover.js +129 -0
  118. package/dist/vanilla/radio.d.ts +3 -0
  119. package/dist/vanilla/radio.js +54 -0
  120. package/dist/vanilla/segmented.js +49 -51
  121. package/dist/vanilla/switch.d.ts +2 -1
  122. package/dist/vanilla/switch.js +13 -8
  123. package/dist/vanilla/tabs.d.ts +2 -0
  124. package/dist/vanilla/tabs.js +87 -0
  125. package/dist/vanilla/tierlist.d.ts +1 -1
  126. package/dist/vanilla/tierlist.js +29 -25
  127. package/dist/vanilla/toast.d.ts +2 -2
  128. package/dist/vanilla/toast.js +16 -14
  129. package/dist/vanilla/tooltip.js +35 -23
  130. package/dist/vanilla.css +349 -42
  131. package/package.json +1 -1
  132. package/dist/chart-nav.d.ts +0 -13
  133. package/dist/toast-core.d.ts +0 -61
@@ -2,15 +2,14 @@
2
2
  * TierList (DS-0159) — plain-HTML behaviour for the markup `TierList.svelte` renders: pointer
3
3
  * drag between/within rows (Pointer Events, so touch works) and the keyboard path (Space picks
4
4
  * a tile up, arrows move it, Space drops, Escape cancels) with a polite live region. The move
5
- * math and the wording come from `../tierlist-core.js`, shared with the Svelte component.
6
- * Emits `ss:change` on the root with `{ placements }` (tier id → item ids; the tray is
7
- * implicit). `data-ss-readonly` on the root makes the list inert.
5
+ * math and the wording come from `../core/tierlist.js`, shared with the Svelte component.
6
+ * Emits `ss:change` on the root with `{ placements, reason }` (tier id → item ids; the tray is
7
+ * implicit; `reason` is `'pointer'` or `'keyboard'`). `data-ss-readonly` on the root makes the list inert.
8
8
  */
9
9
  import { on, emit, all } from './delegate.js';
10
- import { TRAY, announceText, insertionIndex, keyMoveFor, keyboardTarget, } from '../tierlist-core.js';
10
+ import { TRAY, announceText, insertionIndex, keyboardTarget, tierListDragStarts, tierListPressArmsDrag, tierListTileKey, } from '../core/tierlist.js';
11
11
  const ROOT = '.ss-tierlist';
12
12
  const TILE = `${ROOT} .tile[data-item]`;
13
- const DRAG_THRESHOLD = 4;
14
13
  function rootOf(el) {
15
14
  return el.closest(ROOT);
16
15
  }
@@ -85,8 +84,8 @@ function describe(root, tile) {
85
84
  count: cells.length,
86
85
  };
87
86
  }
88
- function change(root) {
89
- emit(root, 'ss:change', { placements: readPlacements(root) });
87
+ function change(root, reason) {
88
+ emit(root, 'ss:change', { placements: readPlacements(root), reason });
90
89
  }
91
90
  const grabs = new WeakMap();
92
91
  /** Read at event time: `dir` may sit on any ancestor and change after install. */
@@ -114,7 +113,7 @@ export function toggleGrab(tile) {
114
113
  grabs.delete(root);
115
114
  setGrabbed(root, null);
116
115
  announce(root, announceText('drop', describe(root, tile)));
117
- change(root);
116
+ change(root, 'keyboard');
118
117
  return;
119
118
  }
120
119
  const d = describe(root, tile);
@@ -210,30 +209,32 @@ function endDrag(d, cancelled) {
210
209
  const now = describe(d.root, d.tile);
211
210
  if (zoneKey(d.cell.parentElement) !== d.zone || now.index !== d.index) {
212
211
  announce(d.root, announceText('drop', now));
213
- change(d.root);
212
+ change(d.root, 'pointer');
214
213
  }
215
214
  }
216
215
  export function installTierlist() {
217
216
  on('keydown', TILE, (tile, e) => {
218
217
  const root = rootOf(tile);
219
- if (!root || isReadonly(root))
218
+ if (!root)
220
219
  return;
221
- const grab = grabs.get(root);
222
- if (e.key === ' ' || (e.key === 'Enter' && !tile.hasAttribute('data-ss-activate'))) {
223
- e.preventDefault();
224
- toggleGrab(tile);
220
+ const result = tierListTileKey({
221
+ readonly: isReadonly(root),
222
+ grabbed: grabs.get(root)?.tile === tile,
223
+ // An activatable tile keeps Enter for the host: its native click does the activating.
224
+ select: tile.hasAttribute('data-ss-activate') ? 'native' : 'none',
225
+ rtl: isRtl(tile),
226
+ }, e.key);
227
+ if (!result)
225
228
  return;
226
- }
227
- if (e.key === 'Escape' && grab?.tile === tile) {
229
+ if (result.preventDefault)
228
230
  e.preventDefault();
231
+ const { action } = result;
232
+ if (action.type === 'toggle')
233
+ toggleGrab(tile);
234
+ else if (action.type === 'cancel')
229
235
  cancelGrab(root, true);
230
- return;
231
- }
232
- const move = keyMoveFor(e.key, isRtl(tile));
233
- if (move && grab?.tile === tile) {
234
- e.preventDefault();
235
- keyMove(root, tile, move);
236
- }
236
+ else if (action.type === 'move')
237
+ keyMove(root, tile, action.move);
237
238
  });
238
239
  // Cancel when focus has really left a grabbed tile — checked a beat later, because moving
239
240
  // the node (a row change re-inserts it) blurs it in some browsers before it is re-focused.
@@ -250,7 +251,10 @@ export function installTierlist() {
250
251
  });
251
252
  on('pointerdown', TILE, (tile, e) => {
252
253
  const root = rootOf(tile);
253
- if (!root || isReadonly(root) || e.button !== 0 || grabs.has(root))
254
+ if (!root)
255
+ return;
256
+ const press = { readonly: isReadonly(root), button: e.button, grabbing: grabs.has(root) };
257
+ if (!tierListPressArmsDrag(press))
254
258
  return;
255
259
  const cell = tile.closest('.cell');
256
260
  const zone = cell.parentElement;
@@ -274,7 +278,7 @@ export function installTierlist() {
274
278
  if (!drag)
275
279
  return;
276
280
  if (!drag.dragging) {
277
- if (Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < DRAG_THRESHOLD)
281
+ if (!tierListDragStarts(e.clientX - drag.startX, e.clientY - drag.startY))
278
282
  return;
279
283
  startDrag(drag);
280
284
  }
@@ -17,8 +17,8 @@
17
17
  * renders; author them in the markup or they are added on DOM ready / first use). Each visible
18
18
  * toast mirrors its message into one of them; the toasts themselves carry no live role.
19
19
  */
20
- import { type Toast, type ToastKind, type ToastOptions, type ToastPatch, type PromiseMessages } from '../toast-core.js';
21
- export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from '../toast-core.js';
20
+ import { type Toast, type ToastKind, type ToastOptions, type ToastPatch, type PromiseMessages } from '../core/toast.js';
21
+ export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from '../core/toast.js';
22
22
  declare class VanillaToastStore {
23
23
  #private;
24
24
  max: number;
@@ -17,7 +17,7 @@
17
17
  * renders; author them in the markup or they are added on DOM ready / first use). Each visible
18
18
  * toast mirrors its message into one of them; the toasts themselves carry no live role.
19
19
  */
20
- import { DEFAULT_TIMEOUT, isSticky, resolveTimeout, normalizeOptions, ToastTimer, } from '../toast-core.js';
20
+ import { DEFAULT_TIMEOUT, isSticky, resolveTimeout, normalizeOptions, toastActionDismisses, toastFocusAfterDismiss, toastKey, toastShouldResume, ToastTimer, } from '../core/toast.js';
21
21
  const GLYPH = { success: '✓', error: '✕', info: 'i', loading: '' };
22
22
  const LEAVE_FALLBACK_MS = 400;
23
23
  /** Screen readers need a moment to register a fresh live region before it changes. */
@@ -129,22 +129,24 @@ class VanillaToastStore {
129
129
  live.hovered = true;
130
130
  this.pause(t.id);
131
131
  });
132
+ const resumeIfFree = (focused) => {
133
+ if (toastShouldResume({ hovered: live.hovered, focused }))
134
+ this.resume(t.id);
135
+ };
132
136
  el.addEventListener('pointerleave', () => {
133
137
  live.hovered = false;
134
- if (!el.contains(document.activeElement))
135
- this.resume(t.id);
138
+ resumeIfFree(holdsFocus(live));
136
139
  });
137
140
  el.addEventListener('focusin', () => this.pause(t.id));
138
- el.addEventListener('focusout', (e) => {
139
- if (el.contains(e.relatedTarget) || live.hovered)
140
- return;
141
- this.resume(t.id);
142
- });
141
+ // Focus is only leaving when it lands outside the toast.
142
+ el.addEventListener('focusout', (e) => resumeIfFree(el.contains(e.relatedTarget)));
143
143
  el.addEventListener('keydown', (e) => {
144
- if (e.key === 'Escape') {
144
+ const result = toastKey(e.key);
145
+ if (!result)
146
+ return;
147
+ if (result.stopPropagation)
145
148
  e.stopPropagation();
146
- this.dismiss(t.id);
147
- }
149
+ this.dismiss(t.id);
148
150
  });
149
151
  el.addEventListener('click', (e) => {
150
152
  const btn = e.target.closest('button');
@@ -153,8 +155,7 @@ class VanillaToastStore {
153
155
  if (btn.classList.contains('x'))
154
156
  this.dismiss(t.id);
155
157
  else if (btn.classList.contains('action')) {
156
- const keep = this.#find(t.id)?.toast.action?.onClick() === false;
157
- if (!keep)
158
+ if (toastActionDismisses(this.#find(t.id)?.toast.action?.onClick()))
158
159
  this.dismiss(t.id);
159
160
  }
160
161
  });
@@ -238,7 +239,8 @@ class VanillaToastStore {
238
239
  }
239
240
  /** Move focus off the toast at `i` (about to be removed): next toast, previous, or origin. */
240
241
  #moveFocusFrom(i) {
241
- const next = this.#live[i + 1] ?? this.#live[i - 1];
242
+ const order = this.#live.map((l) => l.toast.id);
243
+ const next = this.#find(toastFocusAfterDismiss(order, order[i]) ?? -1);
242
244
  if (next)
243
245
  next.el.focus();
244
246
  else if (this.#returnFocus?.isConnected) {
@@ -5,9 +5,11 @@
5
5
  * hides any open tip wherever focus is (WCAG 1.4.13). While open the focusable trigger inside
6
6
  * `.trigger` (not the wrapper) carries `aria-describedby` → the tip (an id is generated when
7
7
  * the markup has none); the token is added alongside any description the trigger already has
8
- * (DS-0163).
8
+ * (DS-0163). Which event shows or hides a tip is decided in `core/tooltip.ts`, the same
9
+ * functions Tooltip.svelte calls.
9
10
  */
10
11
  import { on, all } from './delegate.js';
12
+ import { tooltipDescribedBy, tooltipFocusIn, tooltipFocusOut, tooltipKey, tooltipPointerEnter, tooltipPointerLeave, } from '../core/tooltip.js';
11
13
  const ROOT = '.ss-tooltip';
12
14
  const FOCUSABLE = 'a[href], button, input, select, textarea, summary, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
13
15
  let seq = 0;
@@ -27,19 +29,36 @@ function describedTarget(root, from) {
27
29
  trigger.firstElementChild ??
28
30
  trigger);
29
31
  }
30
- function ids(el) {
31
- return (el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
32
+ function setDescribedBy(el, tipId, open) {
33
+ const value = tooltipDescribedBy(el.getAttribute('aria-describedby'), tipId, open);
34
+ if (value === undefined)
35
+ el.removeAttribute('aria-describedby');
36
+ else
37
+ el.setAttribute('aria-describedby', value);
38
+ }
39
+ /** The core's state, read from the DOM. */
40
+ function stateOf(root) {
41
+ return { open: Boolean(tipOf(root)?.classList.contains('open')) };
42
+ }
43
+ /** The other end of a pointer or focus move is still inside `root`. */
44
+ function within(root, node) {
45
+ return node instanceof Node && root.contains(node);
46
+ }
47
+ /** Apply a core action to the DOM. */
48
+ function run(root, action, from) {
49
+ if (!action)
50
+ return;
51
+ if (action.type === 'show')
52
+ showTooltip(root, from);
53
+ else
54
+ hideTooltip(root);
32
55
  }
33
56
  function undescribe(root, tipId) {
34
57
  const el = described.get(root);
35
58
  described.delete(root);
36
59
  if (!el)
37
60
  return;
38
- const rest = ids(el).filter((id) => id !== tipId);
39
- if (rest.length)
40
- el.setAttribute('aria-describedby', rest.join(' '));
41
- else
42
- el.removeAttribute('aria-describedby');
61
+ setDescribedBy(el, tipId, false);
43
62
  }
44
63
  /**
45
64
  * Open `root`'s tip. `from` is the element that triggered it (the focused element on
@@ -56,9 +75,7 @@ export function showTooltip(root, from) {
56
75
  const target = describedTarget(root, from);
57
76
  if (described.get(root) !== target) {
58
77
  undescribe(root, tip.id);
59
- const cur = ids(target);
60
- if (!cur.includes(tip.id))
61
- target.setAttribute('aria-describedby', [...cur, tip.id].join(' '));
78
+ setDescribedBy(target, tip.id, true);
62
79
  described.set(root, target);
63
80
  }
64
81
  }
@@ -73,29 +90,24 @@ export function hideTooltip(root) {
73
90
  export function installTooltip() {
74
91
  // mouseenter/leave don't bubble; mouseover/out do — filter by relatedTarget.
75
92
  on('mouseover', ROOT, (root, e) => {
76
- const from = e.relatedTarget;
77
- if (!from || !root.contains(from))
78
- showTooltip(root);
93
+ run(root, tooltipPointerEnter(stateOf(root), { within: within(root, e.relatedTarget) }));
79
94
  });
80
95
  on('mouseout', ROOT, (root, e) => {
81
- const to = e.relatedTarget;
82
- if (!to || !root.contains(to))
83
- hideTooltip(root);
96
+ run(root, tooltipPointerLeave(stateOf(root), { within: within(root, e.relatedTarget) }));
84
97
  });
85
- on('focusin', ROOT, (root, e) => showTooltip(root, e.target));
98
+ on('focusin', ROOT, (root, e) => run(root, tooltipFocusIn(stateOf(root)), e.target));
86
99
  on('focusout', ROOT, (root, e) => {
87
- const to = e.relatedTarget;
88
- if (!to || !root.contains(to))
89
- hideTooltip(root);
100
+ run(root, tooltipFocusOut(stateOf(root), { within: within(root, e.relatedTarget) }));
90
101
  });
91
102
  // Document-level Escape: a tip opened by hover closes even when focus is elsewhere.
92
103
  document.addEventListener('keydown', (e) => {
93
- if (e.key !== 'Escape')
104
+ // Cheap exit for every key that could not dismiss a tip, before touching the DOM.
105
+ if (!tooltipKey({ open: true }, e.key))
94
106
  return;
95
107
  for (const tip of all(document, `${ROOT} > .tip.open`)) {
96
108
  const root = tip.parentElement;
97
109
  if (root)
98
- hideTooltip(root);
110
+ run(root, tooltipKey(stateOf(root), e.key));
99
111
  }
100
112
  });
101
113
  }