@happyvertical/smrt-svelte 0.51.4 → 0.51.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.
@@ -0,0 +1,651 @@
1
+ import { createDataSurfaceRegistry, createDataTableController, } from '@happyvertical/smrt-ui/data';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ import { mountListDataSurface, } from '../list-data-surface.svelte.js';
4
+ const identity = {
5
+ surfaceId: 'custom-list',
6
+ kind: 'list',
7
+ };
8
+ function descriptor(overrides = {}) {
9
+ return {
10
+ version: 1,
11
+ identity,
12
+ schemaVersion: 1,
13
+ label: 'Custom list',
14
+ rowKey: 'id',
15
+ columns: [
16
+ { id: 'id', label: 'ID', capabilities: ['read', 'project'] },
17
+ {
18
+ id: 'title',
19
+ label: 'Title',
20
+ capabilities: ['read', 'search', 'filter', 'sort', 'project'],
21
+ operators: { filter: ['contains'] },
22
+ },
23
+ ],
24
+ query: {
25
+ modes: ['rows', 'count'],
26
+ projectableColumnIds: ['id', 'title'],
27
+ filterableColumnIds: ['title'],
28
+ sortableColumnIds: ['title'],
29
+ },
30
+ controls: [
31
+ { id: 'set-filters', label: 'Filter' },
32
+ { id: 'refresh', label: 'Refresh' },
33
+ { id: 'retry', label: 'Retry' },
34
+ { id: 'focus', label: 'Focus' },
35
+ { id: 'reveal', label: 'Reveal' },
36
+ { id: 'highlight', label: 'Highlight' },
37
+ { id: 'star', label: 'Star selected' },
38
+ ],
39
+ actions: [],
40
+ limits: { maxQueryRows: 50, maxQueryBytes: 10_000, maxSelectionSize: 2 },
41
+ ...overrides,
42
+ };
43
+ }
44
+ function context(overrides = {}) {
45
+ return {
46
+ totalRows: 2,
47
+ queryFingerprint: 'query-1',
48
+ ...overrides,
49
+ };
50
+ }
51
+ describe('mountListDataSurface', () => {
52
+ it('registers a custom list, mirrors controller commands, and unregisters on destroy', async () => {
53
+ const registry = createDataSurfaceRegistry();
54
+ const controller = createDataTableController();
55
+ const handle = mountListDataSurface({
56
+ registry,
57
+ descriptor: descriptor(),
58
+ controller,
59
+ context: context(),
60
+ });
61
+ const before = registry.inspect(identity);
62
+ expect(before?.state.totalRows).toBe(2);
63
+ const result = await registry.execute({
64
+ version: 1,
65
+ commandId: 'set-filter-1',
66
+ identity,
67
+ expectedRevision: before?.revision ?? 0,
68
+ controlId: 'set-filters',
69
+ payload: {
70
+ filters: [{ columnId: 'title', operator: 'contains', value: 'x' }],
71
+ },
72
+ });
73
+ expect(result.ok).toBe(true);
74
+ expect(controller.getState().filters).toEqual([
75
+ { columnId: 'title', operator: 'contains', value: 'x' },
76
+ ]);
77
+ expect(result.revision).toBeGreaterThan(before?.revision ?? -1);
78
+ handle.destroy();
79
+ expect(registry.inspect(identity)).toBeUndefined();
80
+ });
81
+ it('routes the fixed refresh/retry/focus/reveal/highlight controls to page callbacks', async () => {
82
+ const registry = createDataSurfaceRegistry();
83
+ const controller = createDataTableController();
84
+ const refresh = vi.fn().mockResolvedValue(true);
85
+ const focus = vi.fn();
86
+ const handle = mountListDataSurface({
87
+ registry,
88
+ descriptor: descriptor(),
89
+ controller,
90
+ context: context(),
91
+ refresh,
92
+ focus,
93
+ });
94
+ await expect(registry.execute({
95
+ version: 1,
96
+ commandId: 'do-refresh',
97
+ identity,
98
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
99
+ controlId: 'refresh',
100
+ })).resolves.toMatchObject({ ok: true });
101
+ expect(refresh).toHaveBeenCalledOnce();
102
+ await expect(registry.execute({
103
+ version: 1,
104
+ commandId: 'do-focus',
105
+ identity,
106
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
107
+ controlId: 'focus',
108
+ })).resolves.toMatchObject({ ok: true });
109
+ expect(focus).toHaveBeenCalledOnce();
110
+ // retry has no callback wired: denied rather than throwing.
111
+ await expect(registry.execute({
112
+ version: 1,
113
+ commandId: 'do-retry',
114
+ identity,
115
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
116
+ controlId: 'retry',
117
+ })).resolves.toMatchObject({ ok: false });
118
+ handle.destroy();
119
+ });
120
+ it('dispatches unrecognized controls through onControl, denying by default', async () => {
121
+ const registry = createDataSurfaceRegistry();
122
+ const controller = createDataTableController();
123
+ const onControl = vi.fn().mockResolvedValue(true);
124
+ const handle = mountListDataSurface({
125
+ registry,
126
+ descriptor: descriptor(),
127
+ controller,
128
+ context: context(),
129
+ onControl,
130
+ });
131
+ await expect(registry.execute({
132
+ version: 1,
133
+ commandId: 'star-1',
134
+ identity,
135
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
136
+ controlId: 'star',
137
+ payload: { rowId: 'a' },
138
+ })).resolves.toMatchObject({ ok: true });
139
+ expect(onControl).toHaveBeenCalledWith('star', { rowId: 'a' });
140
+ const registryTwo = createDataSurfaceRegistry();
141
+ const controllerTwo = createDataTableController();
142
+ const noHandler = mountListDataSurface({
143
+ registry: registryTwo,
144
+ descriptor: descriptor({
145
+ identity: { surfaceId: 'no-handler', kind: 'list' },
146
+ }),
147
+ controller: controllerTwo,
148
+ context: context(),
149
+ });
150
+ await expect(registryTwo.execute({
151
+ version: 1,
152
+ commandId: 'star-2',
153
+ identity: { surfaceId: 'no-handler', kind: 'list' },
154
+ expectedRevision: registryTwo.inspect({ surfaceId: 'no-handler', kind: 'list' })
155
+ ?.revision ?? 0,
156
+ controlId: 'star',
157
+ })).resolves.toMatchObject({ ok: false });
158
+ handle.destroy();
159
+ noHandler.destroy();
160
+ });
161
+ it('treats a void onControl return as success and passes the raw payload through', async () => {
162
+ const registry = createDataSurfaceRegistry();
163
+ const controller = createDataTableController();
164
+ let received;
165
+ const onControl = vi.fn((_controlId, payload) => {
166
+ received = payload;
167
+ // Intentionally no return (void) — must still count as success.
168
+ });
169
+ const handle = mountListDataSurface({
170
+ registry,
171
+ descriptor: descriptor(),
172
+ controller,
173
+ context: context(),
174
+ onControl,
175
+ });
176
+ await expect(registry.execute({
177
+ version: 1,
178
+ commandId: 'star-void',
179
+ identity,
180
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
181
+ controlId: 'star',
182
+ payload: ['a', 'b'],
183
+ })).resolves.toMatchObject({ ok: true });
184
+ expect(received).toEqual(['a', 'b']);
185
+ handle.destroy();
186
+ });
187
+ it('denies a fixed control with no page callback even when onControl is supplied', async () => {
188
+ const registry = createDataSurfaceRegistry();
189
+ const controller = createDataTableController();
190
+ const onControl = vi.fn().mockResolvedValue(true);
191
+ const handle = mountListDataSurface({
192
+ registry,
193
+ descriptor: descriptor(),
194
+ controller,
195
+ context: context(),
196
+ onControl,
197
+ // No `refresh` callback wired.
198
+ });
199
+ await expect(registry.execute({
200
+ version: 1,
201
+ commandId: 'refresh-no-callback',
202
+ identity,
203
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
204
+ controlId: 'refresh',
205
+ })).resolves.toMatchObject({ ok: false });
206
+ expect(onControl).not.toHaveBeenCalled();
207
+ handle.destroy();
208
+ });
209
+ it('rejects the reserved "table" context key at mount and on update()', () => {
210
+ const registry = createDataSurfaceRegistry();
211
+ const controller = createDataTableController();
212
+ expect(() => mountListDataSurface({
213
+ registry,
214
+ descriptor: descriptor(),
215
+ controller,
216
+ context: context({ table: 'nope' }),
217
+ })).toThrow(/reserved key "table"/);
218
+ const handle = mountListDataSurface({
219
+ registry,
220
+ descriptor: descriptor(),
221
+ controller,
222
+ context: context(),
223
+ });
224
+ expect(() => handle.update(context({ table: 'nope' }))).toThrow(/reserved key "table"/);
225
+ handle.destroy();
226
+ });
227
+ it('denies a declared table control whose payload fails to translate, never reaching onControl', async () => {
228
+ const registry = createDataSurfaceRegistry();
229
+ const controller = createDataTableController();
230
+ const onControl = vi.fn().mockResolvedValue(true);
231
+ const handle = mountListDataSurface({
232
+ registry,
233
+ descriptor: descriptor(),
234
+ controller,
235
+ context: context(),
236
+ onControl,
237
+ });
238
+ // `filters` must be an array; a string fails
239
+ // `dataTableCommandFromDataSurfaceCommand`'s translation and returns null.
240
+ await expect(registry.execute({
241
+ version: 1,
242
+ commandId: 'malformed-filters',
243
+ identity,
244
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
245
+ controlId: 'set-filters',
246
+ payload: { filters: 'not-an-array' },
247
+ })).resolves.toMatchObject({ ok: false });
248
+ expect(onControl).not.toHaveBeenCalled();
249
+ expect(controller.getState().filters).toEqual([]);
250
+ handle.destroy();
251
+ });
252
+ it('does not leak a controller subscription or corrupt the shared revision counter when register() throws', async () => {
253
+ const registry = createDataSurfaceRegistry();
254
+ const controller = createDataTableController();
255
+ // A duplicate identity makes registry.register() throw synchronously.
256
+ const first = mountListDataSurface({
257
+ registry,
258
+ descriptor: descriptor({ identity: { surfaceId: 'dup', kind: 'list' } }),
259
+ controller: createDataTableController(),
260
+ context: context(),
261
+ });
262
+ expect(() => mountListDataSurface({
263
+ registry,
264
+ descriptor: descriptor({
265
+ identity: { surfaceId: 'dup', kind: 'list' },
266
+ }),
267
+ controller,
268
+ context: context(),
269
+ })).toThrow();
270
+ // The failed mount must not have subscribed to this controller: dispatching
271
+ // through it must not advance any registry-visible revision for 'dup'.
272
+ const before = registry.inspect({
273
+ surfaceId: 'dup',
274
+ kind: 'list',
275
+ })?.revision;
276
+ controller.dispatch({ type: 'setSearch', search: 'x' });
277
+ const after = registry.inspect({
278
+ surfaceId: 'dup',
279
+ kind: 'list',
280
+ })?.revision;
281
+ expect(after).toBe(before);
282
+ // A later, successful mount of the same identity starts strictly above
283
+ // the last revision the first (still-live) registration published.
284
+ first.destroy();
285
+ const rebound = mountListDataSurface({
286
+ registry,
287
+ descriptor: descriptor({ identity: { surfaceId: 'dup', kind: 'list' } }),
288
+ controller,
289
+ context: context(),
290
+ });
291
+ const reboundRevision = registry.inspect({
292
+ surfaceId: 'dup',
293
+ kind: 'list',
294
+ })?.revision;
295
+ expect(reboundRevision).toBeGreaterThan(before ?? -1);
296
+ rebound.destroy();
297
+ });
298
+ it('rejects a registry-forbidden boundary key at update() instead of deferring the failure to a later read', async () => {
299
+ const registry = createDataSurfaceRegistry();
300
+ const controller = createDataTableController();
301
+ const handle = mountListDataSurface({
302
+ registry,
303
+ descriptor: descriptor(),
304
+ controller,
305
+ context: context(),
306
+ });
307
+ const before = registry.inspect(identity);
308
+ // `tenantId` is one of the registry's own boundary-forbidden keys
309
+ // (FORBIDDEN_BOUNDARY_KEYS in @happyvertical/smrt-ui/data) — not
310
+ // something this module hand-copies. update() must throw here, not
311
+ // leave the surface poisoned for a later inspect()/execute().
312
+ expect(() => handle.update(context({ tenantId: 'nope' }))).toThrow();
313
+ // The surface must be unaffected: still readable, at the same revision.
314
+ const after = registry.inspect(identity);
315
+ expect(after).toEqual(before);
316
+ handle.destroy();
317
+ });
318
+ it('denies a table command on a controlled controller when the settled state does not converge', async () => {
319
+ const registry = createDataSurfaceRegistry();
320
+ const controlledState = { filters: [] };
321
+ const controller = createDataTableController({
322
+ state: controlledState,
323
+ onStateChange: () => {
324
+ // Simulate a host that never feeds the proposed state back.
325
+ },
326
+ });
327
+ const handle = mountListDataSurface({
328
+ registry,
329
+ descriptor: descriptor(),
330
+ controller,
331
+ context: context(),
332
+ // No applyControlledState supplied — the proposal is never settled.
333
+ });
334
+ await expect(registry.execute({
335
+ version: 1,
336
+ commandId: 'controlled-unsettled',
337
+ identity,
338
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
339
+ controlId: 'set-filters',
340
+ payload: {
341
+ filters: [{ columnId: 'title', operator: 'contains', value: 'x' }],
342
+ },
343
+ })).resolves.toMatchObject({ ok: false });
344
+ // The controller's own state must be unaffected — dispatch on a
345
+ // controlled controller never applies state on its own.
346
+ expect(controller.getState().filters).toEqual([]);
347
+ handle.destroy();
348
+ });
349
+ it('acknowledges a table command on a controlled controller once applyControlledState settles it', async () => {
350
+ const registry = createDataSurfaceRegistry();
351
+ const controller = createDataTableController({
352
+ state: { filters: [] },
353
+ });
354
+ const handle = mountListDataSurface({
355
+ registry,
356
+ descriptor: descriptor(),
357
+ controller,
358
+ context: context(),
359
+ applyControlledState: (state) => {
360
+ // Simulate a host that immediately accepts and feeds back the
361
+ // proposed state.
362
+ return state;
363
+ },
364
+ });
365
+ await expect(registry.execute({
366
+ version: 1,
367
+ commandId: 'controlled-settled',
368
+ identity,
369
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
370
+ controlId: 'set-filters',
371
+ payload: {
372
+ filters: [{ columnId: 'title', operator: 'contains', value: 'x' }],
373
+ },
374
+ })).resolves.toMatchObject({ ok: true });
375
+ expect(controller.getState().filters).toEqual([
376
+ { columnId: 'title', operator: 'contains', value: 'x' },
377
+ ]);
378
+ handle.destroy();
379
+ });
380
+ it('merges update() context over the previous published state instead of replacing it', () => {
381
+ const registry = createDataSurfaceRegistry();
382
+ const controller = createDataTableController();
383
+ const handle = mountListDataSurface({
384
+ registry,
385
+ descriptor: descriptor(),
386
+ controller,
387
+ context: context({ totalRows: 2, queryFingerprint: 'query-1' }),
388
+ });
389
+ handle.update({ totalRows: 5 });
390
+ const after = registry.inspect(identity);
391
+ expect(after?.state.totalRows).toBe(5);
392
+ // queryFingerprint was not mentioned in this update() call and must be
393
+ // retained, not dropped.
394
+ expect(after?.state.queryFingerprint).toBe('query-1');
395
+ handle.update({ queryFingerprint: undefined });
396
+ const cleared = registry.inspect(identity);
397
+ expect(cleared?.state.queryFingerprint).toBeUndefined();
398
+ expect(cleared?.state.totalRows).toBe(5);
399
+ handle.destroy();
400
+ });
401
+ it('bumps the revision when app-owned context changes via update()', async () => {
402
+ const registry = createDataSurfaceRegistry();
403
+ const controller = createDataTableController();
404
+ const handle = mountListDataSurface({
405
+ registry,
406
+ descriptor: descriptor(),
407
+ controller,
408
+ context: context(),
409
+ });
410
+ const before = registry.inspect(identity)?.revision ?? 0;
411
+ handle.update(context({ totalRows: 5 }));
412
+ const after = registry.inspect(identity);
413
+ expect(after?.revision).toBeGreaterThan(before);
414
+ expect(after?.state.totalRows).toBe(5);
415
+ handle.destroy();
416
+ });
417
+ it('ignores update() called after destroy() instead of corrupting a later mount of the same identity', () => {
418
+ const registry = createDataSurfaceRegistry();
419
+ const controllerA = createDataTableController();
420
+ const surfaceIdentity = { surfaceId: 'reused', kind: 'list' };
421
+ const first = mountListDataSurface({
422
+ registry,
423
+ descriptor: descriptor({ identity: surfaceIdentity }),
424
+ controller: controllerA,
425
+ context: context(),
426
+ });
427
+ first.destroy();
428
+ const controllerB = createDataTableController();
429
+ const second = mountListDataSurface({
430
+ registry,
431
+ descriptor: descriptor({ identity: surfaceIdentity }),
432
+ controller: controllerB,
433
+ context: context(),
434
+ });
435
+ const beforeStaleUpdate = registry.inspect(surfaceIdentity)?.revision ?? 0;
436
+ // A callback captured by `first` (e.g. an async refresh) resolves late,
437
+ // after `first.destroy()` and after `second` has already mounted the
438
+ // same identity. It must be a no-op, not resurrect the shared revision
439
+ // counter for an identity `first` no longer owns.
440
+ expect(() => first.update(context({ totalRows: 999 }))).not.toThrow();
441
+ expect(registry.inspect(surfaceIdentity)?.revision).toBe(beforeStaleUpdate);
442
+ expect(registry.inspect(surfaceIdentity)?.state.totalRows).not.toBe(999);
443
+ second.destroy();
444
+ });
445
+ describe('commandAllowed descriptor-driven refusal', () => {
446
+ async function expectDeniedUnchanged(extra = {}, buildCommand) {
447
+ const registry = createDataSurfaceRegistry();
448
+ const controller = createDataTableController();
449
+ const handle = mountListDataSurface({
450
+ registry,
451
+ descriptor: descriptor(),
452
+ controller,
453
+ context: context(),
454
+ ...extra,
455
+ });
456
+ const before = controller.snapshot();
457
+ const rev = registry.inspect(identity)?.revision ?? 0;
458
+ const result = await registry.execute(buildCommand(rev));
459
+ expect(result.ok).toBe(false);
460
+ expect(controller.snapshot()).toEqual(before);
461
+ handle.destroy();
462
+ }
463
+ it('denies set-filters on a column outside filterableColumnIds', async () => {
464
+ await expectDeniedUnchanged({}, (rev) => ({
465
+ version: 1,
466
+ commandId: 'deny-1',
467
+ identity,
468
+ expectedRevision: rev,
469
+ controlId: 'set-filters',
470
+ payload: {
471
+ filters: [{ columnId: 'id', operator: 'contains', value: 'x' }],
472
+ },
473
+ }));
474
+ });
475
+ it('denies set-filters with an operator outside the column allowlist', async () => {
476
+ await expectDeniedUnchanged({}, (rev) => ({
477
+ version: 1,
478
+ commandId: 'deny-2',
479
+ identity,
480
+ expectedRevision: rev,
481
+ controlId: 'set-filters',
482
+ payload: {
483
+ filters: [{ columnId: 'title', operator: 'notContains', value: 'x' }],
484
+ },
485
+ }));
486
+ });
487
+ it('denies set-sorting on a column outside sortableColumnIds', async () => {
488
+ await expectDeniedUnchanged({}, (rev) => ({
489
+ version: 1,
490
+ commandId: 'deny-3',
491
+ identity,
492
+ expectedRevision: rev,
493
+ controlId: 'set-sorting',
494
+ payload: { sorting: [{ columnId: 'id', direction: 'asc' }] },
495
+ }));
496
+ });
497
+ it('denies toggle-sorting on a column outside sortableColumnIds', async () => {
498
+ await expectDeniedUnchanged({}, (rev) => ({
499
+ version: 1,
500
+ commandId: 'deny-4',
501
+ identity,
502
+ expectedRevision: rev,
503
+ controlId: 'toggle-sorting',
504
+ payload: { columnId: 'id' },
505
+ }));
506
+ });
507
+ it('denies set-selected-rows over maxSelectionSize', async () => {
508
+ await expectDeniedUnchanged({}, (rev) => ({
509
+ version: 1,
510
+ commandId: 'deny-5',
511
+ identity,
512
+ expectedRevision: rev,
513
+ controlId: 'set-selected-rows',
514
+ payload: { rowIds: ['a', 'b', 'c'] },
515
+ }));
516
+ });
517
+ it('denies toggle-row-selection that would exceed maxSelectionSize', async () => {
518
+ const registry = createDataSurfaceRegistry();
519
+ const controller = createDataTableController();
520
+ controller.dispatch({ type: 'setSelectedRows', rowIds: ['a', 'b'] });
521
+ const handle = mountListDataSurface({
522
+ registry,
523
+ descriptor: descriptor(),
524
+ controller,
525
+ context: context(),
526
+ });
527
+ const before = controller.snapshot();
528
+ await expect(registry.execute({
529
+ version: 1,
530
+ commandId: 'deny-6',
531
+ identity,
532
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
533
+ controlId: 'toggle-row-selection',
534
+ payload: { rowId: 'c' },
535
+ })).resolves.toMatchObject({ ok: false });
536
+ expect(controller.snapshot()).toEqual(before);
537
+ handle.destroy();
538
+ });
539
+ it('denies set-column-order naming an unreadable column', async () => {
540
+ await expectDeniedUnchanged({}, (rev) => ({
541
+ version: 1,
542
+ commandId: 'deny-7',
543
+ identity,
544
+ expectedRevision: rev,
545
+ controlId: 'set-column-order',
546
+ payload: { columnIds: ['missing-column'] },
547
+ }));
548
+ });
549
+ it('denies set-column-visibility naming an unreadable column', async () => {
550
+ await expectDeniedUnchanged({}, (rev) => ({
551
+ version: 1,
552
+ commandId: 'deny-8',
553
+ identity,
554
+ expectedRevision: rev,
555
+ controlId: 'set-column-visibility',
556
+ payload: { columns: [{ columnId: 'missing-column', visible: false }] },
557
+ }));
558
+ });
559
+ it('denies set-page-size of 0', async () => {
560
+ await expectDeniedUnchanged({}, (rev) => ({
561
+ version: 1,
562
+ commandId: 'deny-9',
563
+ identity,
564
+ expectedRevision: rev,
565
+ controlId: 'set-page-size',
566
+ payload: { pageSize: 0 },
567
+ }));
568
+ });
569
+ it('denies an otherwise-allowed table command when acceptsTableCommand refuses it', async () => {
570
+ await expectDeniedUnchanged({ acceptsTableCommand: () => false }, (rev) => ({
571
+ version: 1,
572
+ commandId: 'deny-10',
573
+ identity,
574
+ expectedRevision: rev,
575
+ controlId: 'set-filters',
576
+ payload: {
577
+ filters: [{ columnId: 'title', operator: 'contains', value: 'x' }],
578
+ },
579
+ }));
580
+ });
581
+ });
582
+ it('routes reveal and highlight to their page callbacks', async () => {
583
+ const registry = createDataSurfaceRegistry();
584
+ const controller = createDataTableController();
585
+ const reveal = vi.fn();
586
+ const highlight = vi.fn();
587
+ const handle = mountListDataSurface({
588
+ registry,
589
+ descriptor: descriptor(),
590
+ controller,
591
+ context: context(),
592
+ reveal,
593
+ highlight,
594
+ });
595
+ await expect(registry.execute({
596
+ version: 1,
597
+ commandId: 'do-reveal',
598
+ identity,
599
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
600
+ controlId: 'reveal',
601
+ })).resolves.toMatchObject({ ok: true });
602
+ expect(reveal).toHaveBeenCalledOnce();
603
+ await expect(registry.execute({
604
+ version: 1,
605
+ commandId: 'do-highlight',
606
+ identity,
607
+ expectedRevision: registry.inspect(identity)?.revision ?? 0,
608
+ controlId: 'highlight',
609
+ })).resolves.toMatchObject({ ok: true });
610
+ expect(highlight).toHaveBeenCalledOnce();
611
+ handle.destroy();
612
+ });
613
+ it('seeds and reports the mounted revision via initialRevision/onRevision', () => {
614
+ const registry = createDataSurfaceRegistry();
615
+ const controller = createDataTableController();
616
+ const onRevision = vi.fn();
617
+ const handle = mountListDataSurface({
618
+ registry,
619
+ descriptor: descriptor(),
620
+ controller,
621
+ context: context(),
622
+ initialRevision: 41,
623
+ onRevision,
624
+ });
625
+ expect(registry.inspect(identity)?.revision).toBe(41);
626
+ expect(onRevision).toHaveBeenCalledWith(41);
627
+ handle.destroy();
628
+ });
629
+ it('keeps two mounted lists independently addressable', async () => {
630
+ const registry = createDataSurfaceRegistry();
631
+ const first = mountListDataSurface({
632
+ registry,
633
+ descriptor: descriptor({ identity: { surfaceId: 'a', kind: 'list' } }),
634
+ controller: createDataTableController(),
635
+ context: context(),
636
+ });
637
+ const second = mountListDataSurface({
638
+ registry,
639
+ descriptor: descriptor({ identity: { surfaceId: 'b', kind: 'list' } }),
640
+ controller: createDataTableController(),
641
+ context: context({ totalRows: 9 }),
642
+ });
643
+ expect(registry
644
+ .list()
645
+ .map((entry) => entry.identity.surfaceId)
646
+ .sort()).toEqual(['a', 'b']);
647
+ expect(registry.inspect({ surfaceId: 'b', kind: 'list' })?.state.totalRows).toBe(9);
648
+ first.destroy();
649
+ second.destroy();
650
+ });
651
+ });
@@ -15,6 +15,7 @@
15
15
  * @packageDocumentation
16
16
  */
17
17
  export { type ActivityFeedHandle, type ActivityFeedMap, type ActivityFeedOptions, activityFeed, type ShellActivityInput, } from './activity-feed.svelte.js';
18
+ export { type ListDataSurfaceContext, type ListDataSurfaceContextPatch, type ListDataSurfaceControlResult, type ListDataSurfaceHandle, type MountListDataSurfaceOptions, mountListDataSurface, } from './list-data-surface.svelte.js';
18
19
  export { type LiveCollection, type LiveCollectionMutation, type LiveCollectionOptions, type LiveCollectionStatus, liveCollection, } from './live-collection.svelte.js';
19
20
  export { type RemoteQueryBinding, remoteQuery, } from './remote-query.svelte.js';
20
21
  export { type UpdateAvailableView, type UseUpdateAvailableOptions, useUpdateAvailable, } from './update-available.svelte.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,YAAY,EACZ,KAAK,kBAAkB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,cAAc,GACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,kBAAkB,EACvB,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,4BAA4B,EACjC,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,YAAY,EACZ,KAAK,kBAAkB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,cAAc,GACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,kBAAkB,EACvB,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,4BAA4B,EACjC,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC"}
package/dist/web/index.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * @packageDocumentation
16
16
  */
17
17
  export { activityFeed, } from './activity-feed.svelte.js';
18
+ export { mountListDataSurface, } from './list-data-surface.svelte.js';
18
19
  export { liveCollection, } from './live-collection.svelte.js';
19
20
  export { remoteQuery, } from './remote-query.svelte.js';
20
21
  export { useUpdateAvailable, } from './update-available.svelte.js';