@joewinke/jatui 0.1.31 → 0.1.33

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.
@@ -58,22 +58,34 @@
58
58
  * state (e.g. a `SvelteSet` of ids, with the id interpolating the row's own id) —
59
59
  * one action instance attaches per row element.
60
60
  */
61
- const DEFAULTS = { threshold: 120, expanded: false, fadeStart: 55, epsilon: 4 };
62
- export function collapse(node, options = {}) {
63
- let opts = { ...DEFAULTS, ...options };
64
- let collapsible = false;
65
- let rafId = 0;
66
- let applied = false;
61
+ var __assign = (this && this.__assign) || function () {
62
+ __assign = Object.assign || function(t) {
63
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
64
+ s = arguments[i];
65
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
66
+ t[p] = s[p];
67
+ }
68
+ return t;
69
+ };
70
+ return __assign.apply(this, arguments);
71
+ };
72
+ var DEFAULTS = { threshold: 120, expanded: false, fadeStart: 55, epsilon: 4 };
73
+ export function collapse(node, options) {
74
+ if (options === void 0) { options = {}; }
75
+ var opts = __assign(__assign({}, DEFAULTS), options);
76
+ var collapsible = false;
77
+ var rafId = 0;
78
+ var applied = false;
67
79
  function gradient() {
68
- return `linear-gradient(to bottom, black ${opts.fadeStart}%, transparent 100%)`;
80
+ return "linear-gradient(to bottom, black ".concat(opts.fadeStart, "%, transparent 100%)");
69
81
  }
70
82
  function apply() {
71
- const shouldCollapse = collapsible && !opts.expanded;
83
+ var shouldCollapse = collapsible && !opts.expanded;
72
84
  if (shouldCollapse === applied)
73
85
  return; // idempotent — avoids RO feedback loops
74
86
  applied = shouldCollapse;
75
87
  if (shouldCollapse) {
76
- node.style.maxHeight = `${opts.threshold}px`;
88
+ node.style.maxHeight = "".concat(opts.threshold, "px");
77
89
  node.style.overflow = 'hidden';
78
90
  node.style.maskImage = gradient();
79
91
  node.style.webkitMaskImage = gradient();
@@ -86,11 +98,12 @@ export function collapse(node, options = {}) {
86
98
  }
87
99
  }
88
100
  function measure() {
101
+ var _a;
89
102
  // scrollHeight is the full content height even while collapsed.
90
- const next = node.scrollHeight > opts.threshold + opts.epsilon;
103
+ var next = node.scrollHeight > opts.threshold + opts.epsilon;
91
104
  if (next !== collapsible) {
92
105
  collapsible = next;
93
- opts.onCollapsible?.(collapsible);
106
+ (_a = opts.onCollapsible) === null || _a === void 0 ? void 0 : _a.call(opts, collapsible);
94
107
  }
95
108
  apply();
96
109
  }
@@ -99,12 +112,13 @@ export function collapse(node, options = {}) {
99
112
  rafId = requestAnimationFrame(measure);
100
113
  }
101
114
  // Re-measure when the content's natural size changes (streaming, {@html}, lazy images).
102
- const ro = new ResizeObserver(scheduleMeasure);
115
+ var ro = new ResizeObserver(scheduleMeasure);
103
116
  ro.observe(node);
104
117
  scheduleMeasure();
105
118
  return {
106
- update(next = {}) {
107
- opts = { ...DEFAULTS, ...next };
119
+ update: function (next) {
120
+ if (next === void 0) { next = {}; }
121
+ opts = __assign(__assign({}, DEFAULTS), next);
108
122
  // expanded/threshold/fade may have changed — re-measure and let
109
123
  // apply() compare the freshly computed shouldCollapse against the
110
124
  // real last-applied state. (Force-flipping `applied` here used to make
@@ -112,7 +126,7 @@ export function collapse(node, options = {}) {
112
126
  // silently skipping the style update.)
113
127
  scheduleMeasure();
114
128
  },
115
- destroy() {
129
+ destroy: function () {
116
130
  cancelAnimationFrame(rafId);
117
131
  ro.disconnect();
118
132
  },
@@ -56,21 +56,32 @@
56
56
  * // ...page-specific shortcuts
57
57
  * }
58
58
  */
59
+ var __assign = (this && this.__assign) || function () {
60
+ __assign = Object.assign || function(t) {
61
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
62
+ s = arguments[i];
63
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
64
+ t[p] = s[p];
65
+ }
66
+ return t;
67
+ };
68
+ return __assign.apply(this, arguments);
69
+ };
59
70
  /** How long a half-typed motion (count prefix, pending `g`, pending `z`) waits
60
71
  * for its completion before resetting. Matches Vim's default `timeoutlen`. */
61
- const MOTION_BUFFER_TIMEOUT_MS = 1500;
72
+ var MOTION_BUFFER_TIMEOUT_MS = 1500;
62
73
  /** Upper cap so `99999j` can't produce pathological math. Above any list size
63
74
  * you'd reasonably navigate with j/k. */
64
- const MAX_COUNT = 99999;
75
+ var MAX_COUNT = 99999;
65
76
  /** Fallback half-page size when we can't measure the viewport (SSR, jsdom
66
77
  * without layout, items not yet attached). */
67
- const DEFAULT_HALF_PAGE = 5;
78
+ var DEFAULT_HALF_PAGE = 5;
68
79
  function isTypingTarget(target) {
69
80
  if (typeof HTMLElement === 'undefined')
70
81
  return false;
71
82
  if (!(target instanceof HTMLElement))
72
83
  return false;
73
- const tag = target.tagName;
84
+ var tag = target.tagName;
74
85
  if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT')
75
86
  return true;
76
87
  return target.isContentEditable;
@@ -79,10 +90,10 @@ function hasModifier(e) {
79
90
  return e.ctrlKey || e.metaKey || e.altKey;
80
91
  }
81
92
  function resolveItems(optsRef) {
82
- const getItems = optsRef.current.getItems;
93
+ var getItems = optsRef.current.getItems;
83
94
  if (!getItems)
84
95
  return [];
85
- const result = getItems();
96
+ var result = getItems();
86
97
  return Array.isArray(result) ? result : Array.from(result);
87
98
  }
88
99
  function wrapIndex(next, length, wrap) {
@@ -100,16 +111,17 @@ function wrapIndex(next, length, wrap) {
100
111
  * when layout isn't available (SSR, jsdom, detached elements).
101
112
  */
102
113
  function getHalfPageSize(items, currentIdx) {
114
+ var _a, _b;
103
115
  if (items.length === 0)
104
116
  return 0;
105
117
  try {
106
- const pivot = items[Math.max(0, Math.min(items.length - 1, currentIdx))] ?? items[0];
118
+ var pivot = (_a = items[Math.max(0, Math.min(items.length - 1, currentIdx))]) !== null && _a !== void 0 ? _a : items[0];
107
119
  if (!pivot || typeof window === 'undefined')
108
120
  return DEFAULT_HALF_PAGE;
109
121
  // Walk up looking for an ancestor that is actually scrolling.
110
- let scroller = pivot.parentElement;
122
+ var scroller = pivot.parentElement;
111
123
  while (scroller) {
112
- const cs = window.getComputedStyle(scroller);
124
+ var cs = window.getComputedStyle(scroller);
113
125
  if ((cs.overflowY === 'auto' || cs.overflowY === 'scroll') &&
114
126
  scroller.clientHeight > 0 &&
115
127
  scroller.clientHeight < scroller.scrollHeight) {
@@ -117,34 +129,34 @@ function getHalfPageSize(items, currentIdx) {
117
129
  }
118
130
  scroller = scroller.parentElement;
119
131
  }
120
- const viewportHeight = scroller?.clientHeight ?? window.innerHeight;
121
- const itemHeight = pivot.getBoundingClientRect().height;
132
+ var viewportHeight = (_b = scroller === null || scroller === void 0 ? void 0 : scroller.clientHeight) !== null && _b !== void 0 ? _b : window.innerHeight;
133
+ var itemHeight = pivot.getBoundingClientRect().height;
122
134
  if (viewportHeight > 0 && itemHeight > 0) {
123
- const fullPage = Math.max(1, Math.floor(viewportHeight / itemHeight));
135
+ var fullPage = Math.max(1, Math.floor(viewportHeight / itemHeight));
124
136
  return Math.max(1, Math.floor(fullPage / 2));
125
137
  }
126
138
  }
127
- catch {
139
+ catch (_c) {
128
140
  // Fall through to default.
129
141
  }
130
142
  return DEFAULT_HALF_PAGE;
131
143
  }
132
144
  function makeController(optsRef) {
133
- let focused = -1;
134
- let lastEl = null;
145
+ var focused = -1;
146
+ var lastEl = null;
135
147
  // Motion-buffer state. A motion is 'pending' until its follow-up key
136
148
  // arrives (e.g. the second `g` in `gg`) or the buffer times out.
137
- let pendingCount = null;
138
- let pendingG = false;
139
- let pendingZ = false;
140
- let bufferTimer = null;
149
+ var pendingCount = null;
150
+ var pendingG = false;
151
+ var pendingZ = false;
152
+ var bufferTimer = null;
141
153
  // Selection state. `selected` holds stable ids (from getItemId / data-nav-id)
142
154
  // rather than indices, since list filters can shift indices but ids persist.
143
155
  // `visualMode` flips on/off via V; while on, j/k extends the range from
144
156
  // `visualAnchor` (the index where V was first pressed) to current focus.
145
- const selected = new Set();
146
- let visualMode = false;
147
- let visualAnchor = -1;
157
+ var selected = new Set();
158
+ var visualMode = false;
159
+ var visualAnchor = -1;
148
160
  function clearBufferTimer() {
149
161
  if (bufferTimer !== null) {
150
162
  clearTimeout(bufferTimer);
@@ -164,22 +176,25 @@ function makeController(optsRef) {
164
176
  }
165
177
  }
166
178
  function focusedClass() {
167
- return optsRef.current.focusedClass ?? 'jk-focused';
179
+ var _a;
180
+ return (_a = optsRef.current.focusedClass) !== null && _a !== void 0 ? _a : 'jk-focused';
168
181
  }
169
182
  function selectedClass() {
170
- return optsRef.current.selectedClass ?? 'jk-selected';
183
+ var _a;
184
+ return (_a = optsRef.current.selectedClass) !== null && _a !== void 0 ? _a : 'jk-selected';
171
185
  }
172
186
  function getId(el) {
173
187
  if (!el)
174
188
  return null;
175
- const resolver = optsRef.current.getItemId;
176
- const raw = resolver ? resolver(el) : el.dataset.navId;
189
+ var resolver = optsRef.current.getItemId;
190
+ var raw = resolver ? resolver(el) : el.dataset.navId;
177
191
  return raw == null ? null : String(raw);
178
192
  }
179
193
  function applySelectionClasses(items) {
180
- const cls = selectedClass();
181
- for (const el of items) {
182
- const id = getId(el);
194
+ var cls = selectedClass();
195
+ for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
196
+ var el = items_1[_i];
197
+ var id = getId(el);
183
198
  if (id !== null && selected.has(id))
184
199
  el.classList.add(cls);
185
200
  else
@@ -187,21 +202,23 @@ function makeController(optsRef) {
187
202
  }
188
203
  }
189
204
  function emitSelectionChange() {
205
+ var _a, _b;
190
206
  applySelectionClasses(resolveItems(optsRef));
191
- optsRef.current.onSelectionChange?.(new Set(selected));
207
+ (_b = (_a = optsRef.current).onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(_a, new Set(selected));
192
208
  }
193
209
  function apply(items, idx) {
194
- const cls = focusedClass();
195
- const next = items[idx] ?? null;
210
+ var _a, _b, _c, _d;
211
+ var cls = focusedClass();
212
+ var next = (_a = items[idx]) !== null && _a !== void 0 ? _a : null;
196
213
  if (lastEl && lastEl !== next)
197
214
  lastEl.classList.remove(cls);
198
215
  if (next) {
199
216
  next.classList.add(cls);
200
- next.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
217
+ (_b = next.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(next, { block: 'nearest', inline: 'nearest' });
201
218
  }
202
219
  lastEl = next;
203
220
  focused = next ? idx : -1;
204
- optsRef.current.onFocusChange?.(next, focused);
221
+ (_d = (_c = optsRef.current).onFocusChange) === null || _d === void 0 ? void 0 : _d.call(_c, next, focused);
205
222
  }
206
223
  /**
207
224
  * Re-derive the selected set from the inclusive range [anchor..focus] while
@@ -209,15 +226,16 @@ function makeController(optsRef) {
209
226
  * V was pressed are preserved (additive — Vim's `V` extends, doesn't reset).
210
227
  */
211
228
  function extendVisualRange(items) {
229
+ var _a;
212
230
  if (!visualMode || visualAnchor < 0 || focused < 0)
213
231
  return;
214
- const lo = Math.min(visualAnchor, focused);
215
- const hi = Math.max(visualAnchor, focused);
232
+ var lo = Math.min(visualAnchor, focused);
233
+ var hi = Math.max(visualAnchor, focused);
216
234
  // Add every id in [lo..hi]. Items outside the range are left alone so
217
235
  // existing pre-V selections survive moving the anchor to a new region.
218
- let mutated = false;
219
- for (let i = lo; i <= hi; i++) {
220
- const id = getId(items[i] ?? null);
236
+ var mutated = false;
237
+ for (var i = lo; i <= hi; i++) {
238
+ var id = getId((_a = items[i]) !== null && _a !== void 0 ? _a : null);
221
239
  if (id !== null && !selected.has(id)) {
222
240
  selected.add(id);
223
241
  mutated = true;
@@ -229,7 +247,7 @@ function makeController(optsRef) {
229
247
  applySelectionClasses(items);
230
248
  }
231
249
  function focus(idx) {
232
- const items = resolveItems(optsRef);
250
+ var items = resolveItems(optsRef);
233
251
  if (items.length === 0)
234
252
  return;
235
253
  apply(items, Math.max(0, Math.min(items.length - 1, idx)));
@@ -238,27 +256,28 @@ function makeController(optsRef) {
238
256
  focus(0);
239
257
  }
240
258
  function focusLast() {
241
- const items = resolveItems(optsRef);
259
+ var items = resolveItems(optsRef);
242
260
  if (items.length)
243
261
  apply(items, items.length - 1);
244
262
  }
245
263
  function clear() {
264
+ var _a, _b;
246
265
  if (lastEl)
247
266
  lastEl.classList.remove(focusedClass());
248
267
  lastEl = null;
249
268
  focused = -1;
250
269
  clearPending();
251
- optsRef.current.onFocusChange?.(null, -1);
270
+ (_b = (_a = optsRef.current).onFocusChange) === null || _b === void 0 ? void 0 : _b.call(_a, null, -1);
252
271
  }
253
272
  function refresh() {
254
- const items = resolveItems(optsRef);
273
+ var items = resolveItems(optsRef);
255
274
  if (items.length === 0) {
256
275
  clear();
257
276
  return;
258
277
  }
259
278
  // Re-home the focused element if the old node has been removed.
260
279
  if (lastEl && !items.includes(lastEl)) {
261
- const newIdx = Math.min(focused, items.length - 1);
280
+ var newIdx = Math.min(focused, items.length - 1);
262
281
  apply(items, Math.max(0, newIdx));
263
282
  }
264
283
  else if (focused >= 0 && focused < items.length) {
@@ -269,7 +288,8 @@ function makeController(optsRef) {
269
288
  applySelectionClasses(items);
270
289
  }
271
290
  function toggleSelectionByIndex(items, idx) {
272
- const id = getId(items[idx] ?? null);
291
+ var _a;
292
+ var id = getId((_a = items[idx]) !== null && _a !== void 0 ? _a : null);
273
293
  if (id === null)
274
294
  return;
275
295
  if (selected.has(id))
@@ -283,14 +303,15 @@ function makeController(optsRef) {
283
303
  visualAnchor = -1;
284
304
  }
285
305
  function handleKeydown(e) {
286
- const opts = optsRef.current;
306
+ var _a, _b, _c, _d, _e, _f, _g;
307
+ var opts = optsRef.current;
287
308
  if (opts.enabled === false)
288
309
  return false;
289
310
  if (isTypingTarget(e.target))
290
311
  return false;
291
- const items = resolveItems(optsRef);
292
- const wrap = opts.wraparound ?? true;
293
- const selectable = opts.selectable === true;
312
+ var items = resolveItems(optsRef);
313
+ var wrap = (_a = opts.wraparound) !== null && _a !== void 0 ? _a : true;
314
+ var selectable = opts.selectable === true;
294
315
  // --- Selection layer (opt-in) ----------------------------------------
295
316
  // These keys are only owned by the controller when `selectable` is true,
296
317
  // so existing pages without a selection model keep their bindings.
@@ -313,7 +334,7 @@ function makeController(optsRef) {
313
334
  toggleSelectionByIndex(items, focused);
314
335
  // If the toggle deselected the anchor, re-add it — entering
315
336
  // visual mode should always include the anchor.
316
- const anchorId = getId(items[focused] ?? null);
337
+ var anchorId = getId((_b = items[focused]) !== null && _b !== void 0 ? _b : null);
317
338
  if (anchorId !== null && !selected.has(anchorId)) {
318
339
  selected.add(anchorId);
319
340
  emitSelectionChange();
@@ -336,20 +357,25 @@ function makeController(optsRef) {
336
357
  if (items.length === 0)
337
358
  return false;
338
359
  e.preventDefault();
339
- const allIds = [];
340
- for (const el of items) {
341
- const id = getId(el);
360
+ var allIds = [];
361
+ for (var _i = 0, items_2 = items; _i < items_2.length; _i++) {
362
+ var el = items_2[_i];
363
+ var id = getId(el);
342
364
  if (id !== null)
343
365
  allIds.push(id);
344
366
  }
345
- const allSelected = allIds.length > 0 && allIds.every((id) => selected.has(id));
367
+ var allSelected = allIds.length > 0 && allIds.every(function (id) { return selected.has(id); });
346
368
  if (allSelected) {
347
- for (const id of allIds)
369
+ for (var _h = 0, allIds_1 = allIds; _h < allIds_1.length; _h++) {
370
+ var id = allIds_1[_h];
348
371
  selected.delete(id);
372
+ }
349
373
  }
350
374
  else {
351
- for (const id of allIds)
375
+ for (var _j = 0, allIds_2 = allIds; _j < allIds_2.length; _j++) {
376
+ var id = allIds_2[_j];
352
377
  selected.add(id);
378
+ }
353
379
  }
354
380
  emitSelectionChange();
355
381
  clearPending();
@@ -362,14 +388,14 @@ function makeController(optsRef) {
362
388
  if (items.length === 0)
363
389
  return false;
364
390
  e.preventDefault();
365
- const dir = e.key === 'J' ? 1 : -1;
366
- const before = focused < 0 ? (dir > 0 ? 0 : items.length - 1) : focused;
367
- const beforeId = getId(items[before] ?? null);
391
+ var dir = e.key === 'J' ? 1 : -1;
392
+ var before = focused < 0 ? (dir > 0 ? 0 : items.length - 1) : focused;
393
+ var beforeId = getId((_c = items[before]) !== null && _c !== void 0 ? _c : null);
368
394
  if (beforeId !== null)
369
395
  selected.add(beforeId);
370
- const afterIdx = Math.max(0, Math.min(items.length - 1, before + dir));
396
+ var afterIdx = Math.max(0, Math.min(items.length - 1, before + dir));
371
397
  apply(items, afterIdx);
372
- const afterId = getId(items[afterIdx] ?? null);
398
+ var afterId = getId((_d = items[afterIdx]) !== null && _d !== void 0 ? _d : null);
373
399
  if (afterId !== null)
374
400
  selected.add(afterId);
375
401
  emitSelectionChange();
@@ -381,14 +407,14 @@ function makeController(optsRef) {
381
407
  // Ctrl/Meta/Alt bailout so vim half-page works; every other modifier
382
408
  // combination still falls through untouched.
383
409
  if (e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey) {
384
- const lower = e.key.toLowerCase();
410
+ var lower = e.key.toLowerCase();
385
411
  if (lower === 'd' || lower === 'u') {
386
412
  if (items.length === 0)
387
413
  return false;
388
414
  e.preventDefault();
389
- const half = getHalfPageSize(items, focused);
390
- const dir = lower === 'd' ? 1 : -1;
391
- const start = focused < 0 ? (dir > 0 ? 0 : items.length - 1) : focused;
415
+ var half = getHalfPageSize(items, focused);
416
+ var dir = lower === 'd' ? 1 : -1;
417
+ var start = focused < 0 ? (dir > 0 ? 0 : items.length - 1) : focused;
392
418
  apply(items, wrapIndex(start + dir * half, items.length, wrap));
393
419
  clearPending();
394
420
  return true;
@@ -403,7 +429,7 @@ function makeController(optsRef) {
403
429
  if (pendingCount === null && e.key === '0')
404
430
  return false;
405
431
  e.preventDefault();
406
- pendingCount = (pendingCount ?? 0) * 10 + Number(e.key);
432
+ pendingCount = (pendingCount !== null && pendingCount !== void 0 ? pendingCount : 0) * 10 + Number(e.key);
407
433
  if (pendingCount > MAX_COUNT)
408
434
  pendingCount = MAX_COUNT;
409
435
  pendingG = false;
@@ -419,7 +445,7 @@ function makeController(optsRef) {
419
445
  }
420
446
  e.preventDefault();
421
447
  if (pendingG) {
422
- const target = pendingCount !== null
448
+ var target = pendingCount !== null
423
449
  ? Math.max(0, Math.min(items.length - 1, pendingCount - 1))
424
450
  : 0;
425
451
  apply(items, target);
@@ -439,7 +465,7 @@ function makeController(optsRef) {
439
465
  return false;
440
466
  }
441
467
  e.preventDefault();
442
- const target = pendingCount !== null
468
+ var target = pendingCount !== null
443
469
  ? Math.max(0, Math.min(items.length - 1, pendingCount - 1))
444
470
  : items.length - 1;
445
471
  apply(items, target);
@@ -450,8 +476,8 @@ function makeController(optsRef) {
450
476
  if (e.key === 'z' && !e.shiftKey) {
451
477
  e.preventDefault();
452
478
  if (pendingZ) {
453
- const el = lastEl ?? items[focused] ?? null;
454
- el?.scrollIntoView?.({ block: 'center', inline: 'nearest' });
479
+ var el = (_e = lastEl !== null && lastEl !== void 0 ? lastEl : items[focused]) !== null && _e !== void 0 ? _e : null;
480
+ (_f = el === null || el === void 0 ? void 0 : el.scrollIntoView) === null || _f === void 0 ? void 0 : _f.call(el, { block: 'center', inline: 'nearest' });
455
481
  clearPending();
456
482
  }
457
483
  else {
@@ -467,10 +493,10 @@ function makeController(optsRef) {
467
493
  if (items.length === 0)
468
494
  return false;
469
495
  e.preventDefault();
470
- const step = pendingCount ?? 1;
496
+ var step = pendingCount !== null && pendingCount !== void 0 ? pendingCount : 1;
471
497
  // From an unfocused state, `{n}j` selects the n-th item
472
498
  // (1-indexed) so it mirrors `{n}G` from the top.
473
- const target = focused < 0 ? step - 1 : focused + step;
499
+ var target = focused < 0 ? step - 1 : focused + step;
474
500
  apply(items, wrapIndex(target, items.length, wrap));
475
501
  clearPending();
476
502
  if (selectable && visualMode)
@@ -482,8 +508,8 @@ function makeController(optsRef) {
482
508
  if (items.length === 0)
483
509
  return false;
484
510
  e.preventDefault();
485
- const step = pendingCount ?? 1;
486
- const target = focused < 0 ? items.length - step : focused - step;
511
+ var step = pendingCount !== null && pendingCount !== void 0 ? pendingCount : 1;
512
+ var target = focused < 0 ? items.length - step : focused - step;
487
513
  apply(items, wrapIndex(target, items.length, wrap));
488
514
  clearPending();
489
515
  if (selectable && visualMode)
@@ -494,12 +520,12 @@ function makeController(optsRef) {
494
520
  case ' ': {
495
521
  if (focused < 0)
496
522
  return false;
497
- const el = items[focused];
523
+ var el = items[focused];
498
524
  if (!el)
499
525
  return false;
500
526
  e.preventDefault();
501
527
  clearPending();
502
- opts.onSelect?.(el, focused);
528
+ (_g = opts.onSelect) === null || _g === void 0 ? void 0 : _g.call(opts, el, focused);
503
529
  return true;
504
530
  }
505
531
  case 'Escape': {
@@ -541,16 +567,16 @@ function makeController(optsRef) {
541
567
  return false;
542
568
  }
543
569
  return {
544
- handleKeydown,
545
- focusedIndex: () => focused,
546
- focus,
547
- focusFirst,
548
- focusLast,
549
- clear,
550
- refresh,
551
- selectedIds: () => new Set(selected),
552
- toggleSelection: (navId) => {
553
- const items = resolveItems(optsRef);
570
+ handleKeydown: handleKeydown,
571
+ focusedIndex: function () { return focused; },
572
+ focus: focus,
573
+ focusFirst: focusFirst,
574
+ focusLast: focusLast,
575
+ clear: clear,
576
+ refresh: refresh,
577
+ selectedIds: function () { return new Set(selected); },
578
+ toggleSelection: function (navId) {
579
+ var items = resolveItems(optsRef);
554
580
  if (navId === undefined) {
555
581
  if (focused < 0)
556
582
  return;
@@ -563,29 +589,32 @@ function makeController(optsRef) {
563
589
  selected.add(navId);
564
590
  emitSelectionChange();
565
591
  },
566
- setSelection: (ids) => {
592
+ setSelection: function (ids) {
567
593
  selected.clear();
568
- for (const id of ids)
594
+ for (var _i = 0, ids_1 = ids; _i < ids_1.length; _i++) {
595
+ var id = ids_1[_i];
569
596
  selected.add(id);
597
+ }
570
598
  emitSelectionChange();
571
599
  },
572
- clearSelection: () => {
600
+ clearSelection: function () {
573
601
  if (selected.size === 0 && !visualMode)
574
602
  return;
575
603
  selected.clear();
576
604
  exitVisualMode();
577
605
  emitSelectionChange();
578
606
  },
579
- selectAll: () => {
580
- const items = resolveItems(optsRef);
581
- for (const el of items) {
582
- const id = getId(el);
607
+ selectAll: function () {
608
+ var items = resolveItems(optsRef);
609
+ for (var _i = 0, items_3 = items; _i < items_3.length; _i++) {
610
+ var el = items_3[_i];
611
+ var id = getId(el);
583
612
  if (id !== null)
584
613
  selected.add(id);
585
614
  }
586
615
  emitSelectionChange();
587
616
  },
588
- isSelecting: () => visualMode,
617
+ isSelecting: function () { return visualMode; },
589
618
  };
590
619
  }
591
620
  /**
@@ -593,17 +622,18 @@ function makeController(optsRef) {
593
622
  * listNav to decide whether to consume the event.
594
623
  */
595
624
  export function createListNav(options) {
596
- const ref = { current: options };
625
+ var ref = { current: options };
597
626
  return makeController(ref);
598
627
  }
599
628
  /**
600
629
  * Svelte action — attaches a keydown listener (window by default) and handles
601
630
  * j/k/ArrowDown/ArrowUp/Enter/Space/Escape navigation over children of `node`.
602
631
  */
603
- export const listNav = (node, initial = {}) => {
604
- const ref = { current: withDefaultGetItems(node, initial) };
605
- const controller = makeController(ref);
606
- let target = ref.current.global === false ? node : window;
632
+ export var listNav = function (node, initial) {
633
+ if (initial === void 0) { initial = {}; }
634
+ var ref = { current: withDefaultGetItems(node, initial) };
635
+ var controller = makeController(ref);
636
+ var target = ref.current.global === false ? node : window;
607
637
  function onKeydown(e) {
608
638
  controller.handleKeydown(e);
609
639
  }
@@ -616,28 +646,27 @@ export const listNav = (node, initial = {}) => {
616
646
  }
617
647
  attach();
618
648
  return {
619
- update(next = {}) {
620
- const wasGlobal = ref.current.global !== false;
649
+ update: function (next) {
650
+ if (next === void 0) { next = {}; }
651
+ var wasGlobal = ref.current.global !== false;
621
652
  ref.current = withDefaultGetItems(node, next);
622
- const isGlobal = ref.current.global !== false;
653
+ var isGlobal = ref.current.global !== false;
623
654
  if (wasGlobal !== isGlobal) {
624
655
  detach();
625
656
  attach();
626
657
  }
627
658
  controller.refresh();
628
659
  },
629
- destroy() {
660
+ destroy: function () {
630
661
  detach();
631
662
  controller.clear();
632
663
  },
633
664
  };
634
665
  };
635
666
  function withDefaultGetItems(node, options) {
667
+ var _a;
636
668
  if (options.getItems)
637
669
  return options;
638
- const selector = options.itemSelector ?? '[data-nav-id]';
639
- return {
640
- ...options,
641
- getItems: () => Array.from(node.querySelectorAll(selector)),
642
- };
670
+ var selector = (_a = options.itemSelector) !== null && _a !== void 0 ? _a : '[data-nav-id]';
671
+ return __assign(__assign({}, options), { getItems: function () { return Array.from(node.querySelectorAll(selector)); } });
643
672
  }