@inflatable-cookie/longhorn-poodle-svelte 0.1.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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/package.json +171 -0
  4. package/src/bindings/index.ts +4 -0
  5. package/src/bindings/layout.svelte.ts +143 -0
  6. package/src/bindings/lifecycle.svelte.ts +246 -0
  7. package/src/bindings/optimistic.svelte.ts +96 -0
  8. package/src/bindings/scheduler.ts +13 -0
  9. package/src/bindings/surface-transfer-actions.ts +281 -0
  10. package/src/bindings/surface-transfer.svelte.ts +230 -0
  11. package/src/bindings/surfaces.svelte.ts +179 -0
  12. package/src/bindings/transfer-actions.ts +240 -0
  13. package/src/bindings/transfer-model.ts +138 -0
  14. package/src/bindings/transfer.svelte.ts +388 -0
  15. package/src/bindings/window-chrome.ts +63 -0
  16. package/src/bindings/window-drag.ts +161 -0
  17. package/src/commands/poodle/CommandPaletteBinding.svelte +51 -0
  18. package/src/commands/poodle/KeybindingSettings.svelte +138 -0
  19. package/src/commands/poodle/projectors.ts +37 -0
  20. package/src/commands/poodle.ts +9 -0
  21. package/src/commands/svelte/lifecycle.ts +13 -0
  22. package/src/commands/svelte/session.svelte.ts +212 -0
  23. package/src/commands/svelte.ts +2 -0
  24. package/src/config/poodle/BackupSettingsPage.svelte +295 -0
  25. package/src/config/poodle/RestoreSettingsPage.svelte +535 -0
  26. package/src/config/poodle/StorageSettingsPage.svelte +361 -0
  27. package/src/config/poodle/restore-model.ts +63 -0
  28. package/src/config/poodle/types.ts +11 -0
  29. package/src/config/poodle.ts +8 -0
  30. package/src/history/svelte/lifecycle.ts +13 -0
  31. package/src/history/svelte/session.svelte.ts +97 -0
  32. package/src/history/svelte.ts +2 -0
  33. package/src/history-tree/svelte/lifecycle.ts +11 -0
  34. package/src/history-tree/svelte/session.svelte.ts +27 -0
  35. package/src/history-tree/svelte.ts +3 -0
  36. package/src/licence/poodle/LicenceActivation.svelte +62 -0
  37. package/src/licence/poodle/LicenceSeats.svelte +57 -0
  38. package/src/licence/poodle/LicenceStatus.svelte +34 -0
  39. package/src/licence/poodle/LicenceSurface.svelte.ts +43 -0
  40. package/src/licence/poodle.ts +3 -0
  41. package/src/native-content/index.ts +4 -0
  42. package/src/native-content/lifecycle.ts +13 -0
  43. package/src/native-content/session.svelte.ts +526 -0
  44. package/src/native-content/viewport.ts +27 -0
  45. package/src/native-content/visibility.ts +19 -0
  46. package/src/notifications/poodle/NotificationPanel.svelte +66 -0
  47. package/src/notifications/poodle/NotificationToastHost.svelte +40 -0
  48. package/src/notifications/poodle/NotificationToastStack.svelte +22 -0
  49. package/src/notifications/poodle/projectors.ts +30 -0
  50. package/src/notifications/poodle.ts +4 -0
  51. package/src/notifications/svelte/lifecycle.ts +11 -0
  52. package/src/notifications/svelte/session.svelte.ts +57 -0
  53. package/src/notifications/svelte.ts +2 -0
  54. package/src/operation/poodle/OperationPanel.svelte +200 -0
  55. package/src/operation/poodle/projectors.ts +78 -0
  56. package/src/operation/poodle.ts +2 -0
  57. package/src/operation/svelte/lifecycle.ts +13 -0
  58. package/src/operation/svelte/session.svelte.ts +80 -0
  59. package/src/operation/svelte.ts +2 -0
  60. package/src/poodle/LayoutDockRegion.svelte +148 -0
  61. package/src/poodle/LayoutSplitView.svelte +120 -0
  62. package/src/poodle/LayoutTabs.svelte +91 -0
  63. package/src/poodle/binding.ts +401 -0
  64. package/src/poodle/document.ts +117 -0
  65. package/src/poodle/index.ts +8 -0
  66. package/src/poodle/projectors.ts +125 -0
  67. package/src/poodle/transfer.ts +188 -0
  68. package/src/poodle/types.ts +89 -0
  69. package/src/settings/poodle/SettingsShell.svelte +382 -0
  70. package/src/settings/poodle.ts +2 -0
  71. package/src/settings/svelte/context.ts +61 -0
  72. package/src/settings/svelte/document.svelte.ts +202 -0
  73. package/src/settings/svelte/errors.ts +84 -0
  74. package/src/settings/svelte/lifecycle.ts +18 -0
  75. package/src/settings/svelte/page.svelte.ts +266 -0
  76. package/src/settings/svelte/runtime.svelte.ts +187 -0
  77. package/src/settings/svelte/scope.svelte.ts +123 -0
  78. package/src/settings/svelte/session.svelte.ts +288 -0
  79. package/src/settings/svelte/types.ts +90 -0
  80. package/src/settings/svelte.ts +6 -0
  81. package/src/svelte.d.ts +6 -0
  82. package/src/update/poodle/UpdateCentre.svelte +64 -0
  83. package/src/update/poodle/UpdateSettings.svelte +64 -0
  84. package/src/update/poodle/UpdateStatus.svelte +51 -0
  85. package/src/update/poodle/UpdateSurface.svelte.ts +88 -0
  86. package/src/update/poodle.ts +3 -0
@@ -0,0 +1,27 @@
1
+ import type { NativeContentSession } from "./session.svelte.ts";
2
+
3
+ export interface NativeContentViewportAction {
4
+ update(session: NativeContentSession): void;
5
+ destroy(): void;
6
+ }
7
+
8
+ /** Binds the exact consumer-owned element used as the native viewport. */
9
+ export function nativeContentViewport(
10
+ node: HTMLElement,
11
+ session: NativeContentSession,
12
+ ): NativeContentViewportAction {
13
+ let current = session;
14
+ let unbind = current.bindViewport(node);
15
+
16
+ return {
17
+ update(next) {
18
+ if (next === current) return;
19
+ unbind();
20
+ current = next;
21
+ unbind = current.bindViewport(node);
22
+ },
23
+ destroy() {
24
+ unbind();
25
+ },
26
+ };
27
+ }
@@ -0,0 +1,19 @@
1
+ import type {
2
+ DesiredVisibility,
3
+ VisibilityReasonId,
4
+ } from "@inflatable-cookie/longhorn/native-content";
5
+
6
+ export interface NativeContentVisibilityInhibitor {
7
+ readonly reason: VisibilityReasonId;
8
+ readonly active: boolean;
9
+ }
10
+
11
+ /** Resolves explicit consumer policy. Earlier inhibitors have precedence. */
12
+ export function resolveNativeContentVisibility(
13
+ inhibitors: readonly NativeContentVisibilityInhibitor[],
14
+ ): DesiredVisibility {
15
+ const inhibitor = inhibitors.find(({ active }) => active);
16
+ return inhibitor === undefined
17
+ ? { state: "visible" }
18
+ : { state: "hidden", reason: inhibitor.reason };
19
+ }
@@ -0,0 +1,66 @@
1
+ <script lang="ts">
2
+ import { Button, Callout, InlineListSection, Stack, StatusIndicator } from "@inflatable-cookie/poodle-svelte";
3
+ import type { Snippet } from "svelte";
4
+
5
+ import type { NotificationRecordProjection } from "@inflatable-cookie/longhorn/notifications/protocol";
6
+ import type { NotificationSession } from "../svelte/session.svelte.ts";
7
+ import { notificationStatusLabel, notificationStatusTone } from "./projectors.ts";
8
+
9
+ let {
10
+ session,
11
+ title = "Notifications",
12
+ emptyMessage = "No notifications.",
13
+ detail,
14
+ }: {
15
+ session: NotificationSession;
16
+ title?: string;
17
+ emptyMessage?: string;
18
+ detail?: Snippet<[NotificationRecordProjection]>;
19
+ } = $props();
20
+
21
+ const failure = $derived(session.status.kind === "failed" ? (session.status.error instanceof Error ? session.status.error.message : String(session.status.error)) : null);
22
+
23
+ function toggle(record: NotificationRecordProjection): void {
24
+ session.select(session.selectedNotificationId === record.notificationId ? undefined : record.notificationId);
25
+ if (record.readState === "unseen") void session.markSeen(record.notificationId).catch(() => undefined);
26
+ }
27
+ </script>
28
+
29
+ <Stack gap="md" ariaLabel={title}>
30
+ {#if failure}
31
+ <Callout tone="danger" title="Notifications unavailable" message={failure} announceMode="polite" />
32
+ {:else}
33
+ {#if session.commandRejection}
34
+ <Callout tone="warning" title="Notification action rejected" message={session.commandRejection.rejection.detail} announceMode="polite" />
35
+ {:else if session.commandFailure}
36
+ <Callout tone="danger" title="Notification action failed" message={session.commandFailure.error instanceof Error ? session.commandFailure.error.message : String(session.commandFailure.error)} announceMode="polite" />
37
+ {/if}
38
+
39
+ <InlineListSection {title} items={session.records} count={session.snapshot?.retainedCount ?? session.records.length} {emptyMessage} framed={false}>
40
+ {#snippet item(notification)}
41
+ <Stack gap="sm">
42
+ <Stack direction="row" gap="sm" justify="between">
43
+ <Button variant={session.selectedNotificationId === notification.notificationId ? "primary" : "secondary"} pressed={session.selectedNotificationId === notification.notificationId} onClick={() => toggle(notification)}>
44
+ {notification.draft.title}
45
+ </Button>
46
+ <StatusIndicator status={notificationStatusTone(notification.draft.severity)} label={notificationStatusLabel(notification)} />
47
+ </Stack>
48
+ <span>{notification.draft.summary}</span>
49
+ <Stack direction="row" gap="sm">
50
+ {#each notification.draft.actions as action (action.referenceId)}
51
+ <Button variant="ghost" loading={session.isPending(notification.notificationId, "action")} disabled={session.isPending(notification.notificationId, "action")} onClick={() => void session.invokeAction(notification.notificationId, action.referenceId).catch(() => undefined)}>{action.label}</Button>
52
+ {/each}
53
+ <Button variant="ghost" loading={session.isPending(notification.notificationId, "dismiss")} disabled={session.isPending(notification.notificationId, "dismiss")} onClick={() => void session.dismiss(notification.notificationId).catch(() => undefined)}>Dismiss</Button>
54
+ </Stack>
55
+ {#if detail && session.selectedNotificationId === notification.notificationId}
56
+ {@render detail(notification)}
57
+ {/if}
58
+ </Stack>
59
+ {/snippet}
60
+ </InlineListSection>
61
+
62
+ {#if session.hasMore}
63
+ <Button variant="secondary" onClick={() => void session.loadMore().catch(() => undefined)}>Load older</Button>
64
+ {/if}
65
+ {/if}
66
+ </Stack>
@@ -0,0 +1,40 @@
1
+ <script lang="ts">
2
+ import { ToastHost, type ToastHostPlacement, type ToastHostStore, type ToastHostStoreItem } from "@inflatable-cookie/poodle-svelte";
3
+ import { readable } from "svelte/store";
4
+
5
+ import type { NotificationSession } from "../svelte/session.svelte.ts";
6
+
7
+ let {
8
+ session,
9
+ autoDismissMs = 6000,
10
+ stickyTones = ["danger"],
11
+ placement = "bottom-end",
12
+ }: {
13
+ session: NotificationSession;
14
+ autoDismissMs?: number;
15
+ stickyTones?: ToastHostStoreItem["tone"][];
16
+ placement?: ToastHostPlacement;
17
+ } = $props();
18
+
19
+ const store: ToastHostStore = {
20
+ toasts: readable<ToastHostStoreItem[]>([], (set) => {
21
+ const sync = () => set(session.toasts.map((toast) => ({
22
+ id: toast.id,
23
+ title: toast.title,
24
+ message: toast.description,
25
+ tone: toast.tone,
26
+ actionLabel: toast.action?.label ?? null,
27
+ })));
28
+ sync();
29
+ return session.observe(sync);
30
+ }),
31
+ dismiss: (id) => session.dismissToast(id),
32
+ };
33
+
34
+ function act(id: string): void {
35
+ const toast = session.toasts.find((candidate) => candidate.id === id);
36
+ if (toast?.action !== undefined) void session.invokeAction(toast.notificationId, toast.action.referenceId).catch(() => undefined);
37
+ }
38
+ </script>
39
+
40
+ <ToastHost {store} {autoDismissMs} {stickyTones} {placement} onAction={act} />
@@ -0,0 +1,22 @@
1
+ <script lang="ts">
2
+ import { ToastStack, type ToastItem } from "@inflatable-cookie/poodle-svelte";
3
+
4
+ import type { NotificationSession } from "../svelte/session.svelte.ts";
5
+
6
+ let { session }: { session: NotificationSession } = $props();
7
+
8
+ const items = $derived<ToastItem[]>(session.toasts.map((toast) => ({
9
+ id: toast.id,
10
+ title: toast.title,
11
+ message: toast.description,
12
+ tone: toast.tone,
13
+ actionLabel: toast.action?.label ?? null,
14
+ })));
15
+
16
+ function act(id: string): void {
17
+ const toast = session.toasts.find((candidate) => candidate.id === id);
18
+ if (toast?.action !== undefined) void session.invokeAction(toast.notificationId, toast.action.referenceId).catch(() => undefined);
19
+ }
20
+ </script>
21
+
22
+ <ToastStack {items} onDismiss={(id) => session.dismissToast(id)} onAction={act} />
@@ -0,0 +1,30 @@
1
+ import {
2
+ NOTIFICATION_SEVERITY_LABELS,
3
+ notificationSeverityTone,
4
+ type NotificationRecordProjection,
5
+ type NotificationSeverityProjection,
6
+ type NotificationStatusTone,
7
+ } from "@inflatable-cookie/longhorn/notifications";
8
+
9
+ /**
10
+ * Re-exported from the client tier, where the rule lives so that
11
+ * `NotificationController.projectToast` and this projector cannot disagree.
12
+ */
13
+ export function notificationStatusTone(
14
+ severity: NotificationSeverityProjection,
15
+ ): NotificationStatusTone {
16
+ return notificationSeverityTone(severity);
17
+ }
18
+
19
+ /**
20
+ * The severity's operator-facing name, from the generated map.
21
+ *
22
+ * Previously this returned `record.draft.severity` — the serde wire form, so
23
+ * an operator read `critical` in lowercase (memo 022, D1) — and appended
24
+ * ", unseen" for an unread record. Read state now belongs to the notification
25
+ * centre alone: a toast appears *because* something just happened, so marking
26
+ * it unseen says nothing. Memo 022, D7.
27
+ */
28
+ export function notificationStatusLabel(record: NotificationRecordProjection): string {
29
+ return NOTIFICATION_SEVERITY_LABELS[record.draft.severity];
30
+ }
@@ -0,0 +1,4 @@
1
+ export { default as NotificationPanel } from "./poodle/NotificationPanel.svelte";
2
+ export { default as NotificationToastHost } from "./poodle/NotificationToastHost.svelte";
3
+ export { default as NotificationToastStack } from "./poodle/NotificationToastStack.svelte";
4
+ export * from "./poodle/projectors.ts";
@@ -0,0 +1,11 @@
1
+ import { onMount } from "svelte";
2
+
3
+ import type { NotificationSession } from "./session.svelte.ts";
4
+
5
+ export function useNotificationSession(getSession: () => NotificationSession): void {
6
+ onMount(() => {
7
+ const session = getSession();
8
+ void session.start().catch(() => undefined);
9
+ return () => { void session.stop(); };
10
+ });
11
+ }
@@ -0,0 +1,57 @@
1
+ import {
2
+ NotificationController,
3
+ type NotificationCommandFailure,
4
+ type NotificationCommandRejection,
5
+ type NotificationControllerOptions,
6
+ type NotificationControllerStatus,
7
+ type NotificationPendingCommand,
8
+ type NotificationPendingKind,
9
+ type NotificationToastProjection,
10
+ } from "@inflatable-cookie/longhorn/notifications";
11
+ import type { NotificationId, NotificationMutationResult, NotificationRecordProjection, NotificationSnapshot } from "@inflatable-cookie/longhorn/notifications/protocol";
12
+
13
+ export class NotificationSession {
14
+ readonly controller: NotificationController;
15
+ readonly unobserve: () => void;
16
+ status = $state<NotificationControllerStatus>({ kind: "idle" });
17
+ snapshot = $state<NotificationSnapshot | undefined>();
18
+ records = $state<NotificationRecordProjection[]>([]);
19
+ toasts = $state<NotificationToastProjection[]>([]);
20
+ selectedNotificationId = $state<NotificationId | undefined>();
21
+ selected = $state<NotificationRecordProjection | undefined>();
22
+ pendingCommands = $state<NotificationPendingCommand[]>([]);
23
+ commandRejection = $state<NotificationCommandRejection | undefined>();
24
+ commandFailure = $state<NotificationCommandFailure | undefined>();
25
+ hasMore = $state(false);
26
+
27
+ constructor(options: NotificationControllerOptions) {
28
+ this.controller = new NotificationController(options);
29
+ this.unobserve = this.controller.observe(() => this.sync());
30
+ this.sync();
31
+ }
32
+
33
+ start(): Promise<void> { return this.controller.start(); }
34
+ stop(): Promise<void> { return this.controller.stop(); }
35
+ async dispose(): Promise<void> { this.unobserve(); await this.controller.stop(); }
36
+ observe(observer: () => void): () => void { return this.controller.observe(observer); }
37
+ select(notificationId: NotificationId | undefined): void { this.controller.select(notificationId); }
38
+ loadMore(): Promise<void> { return this.controller.loadMore(); }
39
+ markSeen(notificationId: NotificationId): Promise<NotificationMutationResult> { return this.controller.markSeen(notificationId); }
40
+ dismiss(notificationId: NotificationId): Promise<NotificationMutationResult> { return this.controller.dismiss(notificationId); }
41
+ dismissToast(id: string): void { this.controller.dismissToast(id); }
42
+ invokeAction(notificationId: NotificationId, referenceId: string): Promise<void> { return this.controller.invokeAction(notificationId, referenceId); }
43
+ isPending(notificationId: NotificationId, kind: NotificationPendingKind): boolean { return this.controller.isPending(notificationId, kind); }
44
+
45
+ private sync(): void {
46
+ this.status = this.controller.status;
47
+ this.snapshot = this.controller.snapshot;
48
+ this.records = [...this.controller.records];
49
+ this.toasts = [...this.controller.toasts];
50
+ this.selectedNotificationId = this.controller.selectedNotificationId;
51
+ this.selected = this.controller.selected;
52
+ this.pendingCommands = [...this.controller.pendingCommands];
53
+ this.commandRejection = this.controller.commandRejection;
54
+ this.commandFailure = this.controller.commandFailure;
55
+ this.hasMore = this.controller.hasMore;
56
+ }
57
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./svelte/session.svelte.ts";
2
+ export * from "./svelte/lifecycle.ts";
@@ -0,0 +1,200 @@
1
+ <script lang="ts">
2
+ import {
3
+ AlertDialog,
4
+ Button,
5
+ Callout,
6
+ InlineListSection,
7
+ Progress,
8
+ Spinner,
9
+ Stack,
10
+ StatusIndicator,
11
+ } from "@inflatable-cookie/poodle-svelte";
12
+ import type { Snippet } from "svelte";
13
+
14
+ import type { OperationEntryProjection } from "@inflatable-cookie/longhorn/operation/protocol";
15
+ import type { OperationSession } from "../svelte/session.svelte.ts";
16
+ import {
17
+ canCancelOperation,
18
+ operationProgressView,
19
+ operationStateLabel,
20
+ operationStatusTone,
21
+ } from "./projectors.ts";
22
+
23
+ let {
24
+ session,
25
+ title = "Operations",
26
+ activeTitle = "Active",
27
+ recentTitle = "Recent",
28
+ activeEmptyMessage = "No active operations.",
29
+ recentEmptyMessage = "No recent operations.",
30
+ detail,
31
+ }: {
32
+ session: OperationSession;
33
+ title?: string;
34
+ activeTitle?: string;
35
+ recentTitle?: string;
36
+ activeEmptyMessage?: string;
37
+ recentEmptyMessage?: string;
38
+ detail?: Snippet<[OperationEntryProjection]>;
39
+ } = $props();
40
+
41
+ let cancellationTarget = $state<OperationEntryProjection | undefined>();
42
+ const loading = $derived(session.status.kind === "loading");
43
+ const failure = $derived(
44
+ session.status.kind === "failed"
45
+ ? session.status.error instanceof Error
46
+ ? session.status.error.message
47
+ : String(session.status.error)
48
+ : null,
49
+ );
50
+
51
+ function select(operation: OperationEntryProjection): void {
52
+ session.select(
53
+ session.selectedOperationId === operation.operationId
54
+ ? undefined
55
+ : operation.operationId,
56
+ );
57
+ }
58
+
59
+ async function confirmCancellation(): Promise<void> {
60
+ const operation = cancellationTarget;
61
+ if (operation === undefined) return;
62
+ await session.cancel(operation.operationId);
63
+ cancellationTarget = undefined;
64
+ }
65
+
66
+ function dismiss(operation: OperationEntryProjection): void {
67
+ void session.dismiss(operation.operationId).catch(() => undefined);
68
+ }
69
+ </script>
70
+
71
+ {#snippet operationRow(operation: OperationEntryProjection, terminal: boolean)}
72
+ {@const progress = operationProgressView(operation.progress.overall)}
73
+ <Stack gap="sm">
74
+ <Stack direction="row" gap="sm" justify="between">
75
+ <Button
76
+ variant={session.selectedOperationId === operation.operationId
77
+ ? "primary"
78
+ : "secondary"}
79
+ pressed={session.selectedOperationId === operation.operationId}
80
+ onClick={() => select(operation)}
81
+ >
82
+ {operation.label}
83
+ </Button>
84
+ <StatusIndicator
85
+ status={operationStatusTone(operation.state)}
86
+ label={operationStateLabel(operation.state)}
87
+ />
88
+ </Stack>
89
+
90
+ <Progress
91
+ indeterminate={progress.indeterminate}
92
+ value={progress.value}
93
+ max={progress.max}
94
+ valueText={progress.valueText}
95
+ ariaLabel={`${operation.label} progress`}
96
+ size="sm"
97
+ />
98
+
99
+ {#if operation.progress.phase}
100
+ <span>{operation.progress.phase.label}</span>
101
+ {/if}
102
+
103
+ {#if terminal}
104
+ <Button
105
+ variant="ghost"
106
+ loading={session.isDismissalPending(operation.operationId)}
107
+ disabled={session.isDismissalPending(operation.operationId)}
108
+ ariaLabel={`Dismiss ${operation.label}`}
109
+ onClick={() => dismiss(operation)}
110
+ >
111
+ Dismiss
112
+ </Button>
113
+ {:else if canCancelOperation(operation)}
114
+ <Button
115
+ variant="ghost"
116
+ loading={session.isCancellationPending(operation.operationId)}
117
+ disabled={session.isCancellationPending(operation.operationId)}
118
+ ariaLabel={`Cancel ${operation.label}`}
119
+ onClick={() => (cancellationTarget = operation)}
120
+ >
121
+ Cancel
122
+ </Button>
123
+ {/if}
124
+ </Stack>
125
+ {/snippet}
126
+
127
+ <Stack gap="md" ariaLabel={title}>
128
+ {#if loading}
129
+ <Spinner ariaLabel="Loading operations" />
130
+ {:else if failure}
131
+ <Callout
132
+ tone="danger"
133
+ title="Operations unavailable"
134
+ message={failure}
135
+ announceMode="polite"
136
+ />
137
+ {:else}
138
+ {#if session.commandRejection}
139
+ <Callout
140
+ tone="warning"
141
+ title="Operation action rejected"
142
+ message={session.commandRejection.rejection.detail}
143
+ announceMode="polite"
144
+ />
145
+ {:else if session.commandFailure}
146
+ <Callout
147
+ tone="danger"
148
+ title="Operation action failed"
149
+ message={session.commandFailure.error instanceof Error
150
+ ? session.commandFailure.error.message
151
+ : String(session.commandFailure.error)}
152
+ announceMode="polite"
153
+ />
154
+ {/if}
155
+
156
+ <InlineListSection
157
+ title={activeTitle}
158
+ items={session.active}
159
+ count={session.active.length}
160
+ emptyMessage={activeEmptyMessage}
161
+ framed={false}
162
+ >
163
+ {#snippet item(operation)}
164
+ {@render operationRow(operation, false)}
165
+ {/snippet}
166
+ </InlineListSection>
167
+
168
+ <InlineListSection
169
+ title={recentTitle}
170
+ items={session.recent}
171
+ count={session.recent.length}
172
+ emptyMessage={recentEmptyMessage}
173
+ framed={false}
174
+ >
175
+ {#snippet item(operation)}
176
+ {@render operationRow(operation, true)}
177
+ {/snippet}
178
+ </InlineListSection>
179
+
180
+ {#if detail && session.selected}
181
+ {@render detail(session.selected)}
182
+ {/if}
183
+ {/if}
184
+ </Stack>
185
+
186
+ <AlertDialog
187
+ open={cancellationTarget !== undefined}
188
+ title="Cancel operation?"
189
+ description="Cancellation is a request. Work may finish before it stops."
190
+ itemLabel="Operation"
191
+ itemValue={cancellationTarget?.label ?? null}
192
+ tone="warning"
193
+ confirmLabel="Request cancellation"
194
+ workingLabel="Requesting…"
195
+ onConfirm={confirmCancellation}
196
+ onCancel={() => (cancellationTarget = undefined)}
197
+ onOpenChange={(open) => {
198
+ if (!open) cancellationTarget = undefined;
199
+ }}
200
+ />
@@ -0,0 +1,78 @@
1
+ import {
2
+ OPERATION_STATE_LABELS,
3
+ type OperationEntryProjection,
4
+ type OperationOverallProgressProjection,
5
+ type OperationStateProjection,
6
+ } from "@inflatable-cookie/longhorn/operation";
7
+
8
+ export type OperationStatusTone =
9
+ | "neutral"
10
+ | "info"
11
+ | "success"
12
+ | "warning"
13
+ | "danger"
14
+ | "pending";
15
+
16
+ export interface OperationProgressView {
17
+ readonly indeterminate: boolean;
18
+ readonly value: number | null;
19
+ readonly max: number;
20
+ readonly valueText: string | null;
21
+ }
22
+
23
+ const stateTones: Record<OperationStateProjection, OperationStatusTone> = {
24
+ queued: "pending",
25
+ running: "info",
26
+ cancelling: "warning",
27
+ succeeded: "success",
28
+ failed: "danger",
29
+ cancelled: "neutral",
30
+ interrupted: "warning",
31
+ };
32
+
33
+ /**
34
+ * Generated from Rust, where the wording lives on the enum that owns it.
35
+ * A label added to the union and missing from the map is a type error here
36
+ * rather than a blank on screen. See memo 022, D2.
37
+ */
38
+ export function operationStateLabel(state: OperationStateProjection): string {
39
+ return OPERATION_STATE_LABELS[state];
40
+ }
41
+
42
+ export function operationStatusTone(
43
+ state: OperationStateProjection,
44
+ ): OperationStatusTone {
45
+ return stateTones[state];
46
+ }
47
+
48
+ export function operationProgressView(
49
+ progress: OperationOverallProgressProjection,
50
+ ): OperationProgressView {
51
+ switch (progress.kind) {
52
+ case "indeterminate":
53
+ return { indeterminate: true, value: null, max: 100, valueText: null };
54
+ case "units":
55
+ return {
56
+ indeterminate: false,
57
+ value: progress.completed,
58
+ max: progress.total,
59
+ valueText: `${progress.completed} of ${progress.total}`,
60
+ };
61
+ case "normalized":
62
+ return {
63
+ indeterminate: false,
64
+ value: progress.value,
65
+ max: 1,
66
+ valueText: `${Math.round(progress.value * 100)}%`,
67
+ };
68
+ }
69
+ }
70
+
71
+ export function canCancelOperation(
72
+ operation: OperationEntryProjection,
73
+ ): boolean {
74
+ return (
75
+ operation.cancellationSupport === "supported" &&
76
+ (operation.state === "queued" || operation.state === "running")
77
+ );
78
+ }
@@ -0,0 +1,2 @@
1
+ export { default as OperationPanel } from "./poodle/OperationPanel.svelte";
2
+ export * from "./poodle/projectors.ts";
@@ -0,0 +1,13 @@
1
+ import { onMount } from "svelte";
2
+
3
+ import type { OperationSession } from "./session.svelte.ts";
4
+
5
+ export function useOperationSession(getSession: () => OperationSession): void {
6
+ onMount(() => {
7
+ const session = getSession();
8
+ void session.start().catch(() => undefined);
9
+ return () => {
10
+ void session.stop();
11
+ };
12
+ });
13
+ }
@@ -0,0 +1,80 @@
1
+ import {
2
+ OperationController,
3
+ type OperationCommandFailure,
4
+ type OperationCommandRejection,
5
+ type OperationControllerOptions,
6
+ type OperationControllerStatus,
7
+ type OperationPendingCommand,
8
+ } from "@inflatable-cookie/longhorn/operation";
9
+ import type {
10
+ OperationCancellationResult,
11
+ OperationEntryProjection,
12
+ OperationId,
13
+ OperationMutationResult,
14
+ OperationSnapshot,
15
+ } from "@inflatable-cookie/longhorn/operation/protocol";
16
+
17
+ export class OperationSession {
18
+ readonly #controller: OperationController;
19
+ readonly #unobserve: () => void;
20
+ status = $state<OperationControllerStatus>({ kind: "idle" });
21
+ snapshot = $state<OperationSnapshot | undefined>();
22
+ active = $state<OperationEntryProjection[]>([]);
23
+ recent = $state<OperationEntryProjection[]>([]);
24
+ selectedOperationId = $state<OperationId | undefined>();
25
+ selected = $state<OperationEntryProjection | undefined>();
26
+ pendingCommands = $state<OperationPendingCommand[]>([]);
27
+ commandRejection = $state<OperationCommandRejection | undefined>();
28
+ commandFailure = $state<OperationCommandFailure | undefined>();
29
+
30
+ constructor(options: OperationControllerOptions) {
31
+ this.#controller = new OperationController(options);
32
+ this.#unobserve = this.#controller.observe(() => this.#sync());
33
+ this.#sync();
34
+ }
35
+
36
+ start(): Promise<void> {
37
+ return this.#controller.start();
38
+ }
39
+
40
+ stop(): Promise<void> {
41
+ return this.#controller.stop();
42
+ }
43
+
44
+ async dispose(): Promise<void> {
45
+ this.#unobserve();
46
+ await this.#controller.stop();
47
+ }
48
+
49
+ select(operationId: OperationId | undefined): void {
50
+ this.#controller.select(operationId);
51
+ }
52
+
53
+ cancel(operationId: OperationId): Promise<OperationCancellationResult> {
54
+ return this.#controller.cancel(operationId);
55
+ }
56
+
57
+ dismiss(operationId: OperationId): Promise<OperationMutationResult> {
58
+ return this.#controller.dismiss(operationId);
59
+ }
60
+
61
+ isCancellationPending(operationId: OperationId): boolean {
62
+ return this.#controller.isCancellationPending(operationId);
63
+ }
64
+
65
+ isDismissalPending(operationId: OperationId): boolean {
66
+ return this.#controller.isDismissalPending(operationId);
67
+ }
68
+
69
+ #sync(): void {
70
+ this.status = this.#controller.status;
71
+ this.snapshot = this.#controller.snapshot;
72
+ this.active = [...this.#controller.active];
73
+ this.recent = [...this.#controller.recent];
74
+ this.selectedOperationId = this.#controller.selectedOperationId;
75
+ this.selected = this.#controller.selected;
76
+ this.pendingCommands = [...this.#controller.pendingCommands];
77
+ this.commandRejection = this.#controller.commandRejection;
78
+ this.commandFailure = this.#controller.commandFailure;
79
+ }
80
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./svelte/session.svelte.ts";
2
+ export * from "./svelte/lifecycle.ts";