@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,187 @@
1
+ import type { ConnectionFailure } from "@inflatable-cookie/longhorn/core";
2
+
3
+ import type { SettingsClient } from "@inflatable-cookie/longhorn/settings";
4
+ import type {
5
+ SettingsRegistrySnapshot,
6
+ SettingsRequestId,
7
+ } from "@inflatable-cookie/longhorn/settings/protocol";
8
+ import type { SettingsSubscription } from "@inflatable-cookie/longhorn/settings";
9
+ import { SettingsRendererResolverUnavailableError } from "./errors.ts";
10
+ import { SettingsSessionDocument } from "./document.svelte.ts";
11
+ import type {
12
+ SettingsRendererResolver,
13
+ SettingsRoute,
14
+ SettingsSessionStatus,
15
+ } from "./types.ts";
16
+
17
+ export interface SettingsRuntimeOptions {
18
+ readonly client: SettingsClient;
19
+ readonly nextRequestId: () => SettingsRequestId;
20
+ readonly initialRoute?: SettingsRoute;
21
+ readonly onError: (error: unknown) => void;
22
+ }
23
+
24
+ export class SettingsSessionRuntime {
25
+ readonly document: SettingsSessionDocument;
26
+ readonly #options: SettingsRuntimeOptions;
27
+ #status = $state.raw<SettingsSessionStatus>({ kind: "idle" });
28
+ #subscription:
29
+ | SettingsSubscription<SettingsRegistrySnapshot>
30
+ | undefined;
31
+ #resolver: SettingsRendererResolver | undefined;
32
+ #startTask: Promise<void> | undefined;
33
+ #stopTask: Promise<void> | undefined;
34
+ #generation = 0;
35
+
36
+ constructor(options: SettingsRuntimeOptions) {
37
+ this.#options = options;
38
+ this.document = new SettingsSessionDocument({
39
+ client: options.client,
40
+ nextRequestId: options.nextRequestId,
41
+ onScopeFailure: (error) => this.#fail(error),
42
+ onMutationError: options.onError,
43
+ });
44
+ }
45
+
46
+ get status(): SettingsSessionStatus {
47
+ return this.#status;
48
+ }
49
+
50
+ start(resolver: SettingsRendererResolver): Promise<void> {
51
+ if (this.#startTask !== undefined) return this.#startTask;
52
+ this.#resolver = resolver;
53
+ const afterStop = this.#stopTask;
54
+ this.#startTask =
55
+ afterStop === undefined
56
+ ? this.#begin()
57
+ : afterStop.then(() => this.#begin());
58
+ return this.#startTask;
59
+ }
60
+
61
+ stop(): Promise<void> {
62
+ if (this.#stopTask !== undefined) return this.#stopTask;
63
+ const subscription = this.#subscription;
64
+ const priorFailure =
65
+ this.#status.kind === "failed" ? this.#status.error : undefined;
66
+ this.#subscription = undefined;
67
+ this.#startTask = undefined;
68
+ ++this.#generation;
69
+ this.#status = { kind: "idle" };
70
+ this.#stopTask = (async () => {
71
+ try {
72
+ await Promise.all([
73
+ subscription?.dispose().catch((error) => {
74
+ if (error !== priorFailure) throw error;
75
+ }),
76
+ this.document.stop(),
77
+ ]);
78
+ } finally {
79
+ this.#stopTask = undefined;
80
+ }
81
+ })();
82
+ return this.#stopTask;
83
+ }
84
+
85
+ async reconnect(): Promise<void> {
86
+ const resolver = this.#requiredResolver();
87
+ const registry = this.document.registry;
88
+ if (registry === undefined) {
89
+ await this.stop();
90
+ await this.start(resolver);
91
+ return;
92
+ }
93
+ const route = this.document.route;
94
+ this.#status = { kind: "reconnecting" };
95
+ try {
96
+ await this.document.clearAuthority();
97
+ await this.#install(registry, resolver, route);
98
+ } catch (error) {
99
+ this.#fail(error);
100
+ throw error;
101
+ }
102
+ }
103
+
104
+ async #begin(): Promise<void> {
105
+ const generation = ++this.#generation;
106
+ this.#status = { kind: "loading" };
107
+ const subscription = this.#options.client.connectRegistry(
108
+ (registry) => {
109
+ const current = this.document.registry;
110
+ if (
111
+ generation === this.#generation &&
112
+ current !== undefined &&
113
+ registry.generation > current.generation
114
+ ) {
115
+ void this.#replace(registry, generation);
116
+ }
117
+ },
118
+ (failure: ConnectionFailure) => {
119
+ if (generation === this.#generation) {
120
+ this.#fail(failure.error);
121
+ }
122
+ },
123
+ );
124
+ this.#subscription = subscription;
125
+ try {
126
+ const registry = await subscription.ready;
127
+ if (generation === this.#generation) {
128
+ await this.#install(
129
+ registry,
130
+ this.#requiredResolver(),
131
+ this.#options.initialRoute,
132
+ );
133
+ }
134
+ } catch (error) {
135
+ if (generation === this.#generation) this.#fail(error);
136
+ throw error;
137
+ }
138
+ }
139
+
140
+ async #replace(
141
+ registry: SettingsRegistrySnapshot,
142
+ generation: number,
143
+ ): Promise<void> {
144
+ this.#status = { kind: "reconnecting" };
145
+ try {
146
+ const route = this.document.route;
147
+ await this.document.clearAuthority();
148
+ if (generation === this.#generation) {
149
+ await this.#install(registry, this.#requiredResolver(), route);
150
+ }
151
+ } catch (error) {
152
+ if (generation === this.#generation) this.#fail(error);
153
+ }
154
+ }
155
+
156
+ async #install(
157
+ registry: SettingsRegistrySnapshot,
158
+ resolver: SettingsRendererResolver,
159
+ route?: SettingsRoute,
160
+ ): Promise<void> {
161
+ const result = await this.document.installRegistry(
162
+ registry,
163
+ resolver,
164
+ route,
165
+ );
166
+ this.#status =
167
+ result === "ready"
168
+ ? { kind: "ready" }
169
+ : {
170
+ kind: "unsupported",
171
+ reason: "settings registry has no admitted pages",
172
+ };
173
+ }
174
+
175
+ #requiredResolver(): SettingsRendererResolver {
176
+ if (this.#resolver === undefined) {
177
+ throw new SettingsRendererResolverUnavailableError();
178
+ }
179
+ return this.#resolver;
180
+ }
181
+
182
+ #fail(error: unknown): void {
183
+ if (this.#status.kind === "failed" && this.#status.error === error) return;
184
+ this.#status = { kind: "failed", error };
185
+ this.#options.onError(error);
186
+ }
187
+ }
@@ -0,0 +1,123 @@
1
+ import type { ConnectionFailure } from "@inflatable-cookie/longhorn/core";
2
+
3
+ import type { SettingsClient } from "@inflatable-cookie/longhorn/settings";
4
+ import type {
5
+ SettingsRegistrySnapshot,
6
+ SettingsRequestId,
7
+ SettingsScopeId,
8
+ SettingsScopeSnapshot,
9
+ } from "@inflatable-cookie/longhorn/settings/protocol";
10
+ import type { SettingsSubscription } from "@inflatable-cookie/longhorn/settings";
11
+ import type { SettingsScopeStatus } from "./types.ts";
12
+
13
+ export interface SettingsScopeStateOptions {
14
+ readonly client: SettingsClient;
15
+ readonly registry: SettingsRegistrySnapshot;
16
+ readonly scopeId: SettingsScopeId;
17
+ readonly nextRequestId: () => SettingsRequestId;
18
+ readonly onFailure?: (failure: ConnectionFailure) => void;
19
+ }
20
+
21
+ export class SettingsScopeState {
22
+ readonly #options: SettingsScopeStateOptions;
23
+ #status = $state.raw<SettingsScopeStatus>({ kind: "idle" });
24
+ #snapshot = $state.raw<SettingsScopeSnapshot | undefined>(undefined);
25
+ #subscription:
26
+ | SettingsSubscription<SettingsScopeSnapshot>
27
+ | undefined;
28
+ #startTask: Promise<void> | undefined;
29
+ #stopTask: Promise<void> | undefined;
30
+ #generation = 0;
31
+
32
+ constructor(options: SettingsScopeStateOptions) {
33
+ this.#options = options;
34
+ }
35
+
36
+ get scopeId(): SettingsScopeId {
37
+ return this.#options.scopeId;
38
+ }
39
+
40
+ get status(): SettingsScopeStatus {
41
+ return this.#status;
42
+ }
43
+
44
+ get snapshot(): SettingsScopeSnapshot | undefined {
45
+ return this.#snapshot;
46
+ }
47
+
48
+ start(): Promise<void> {
49
+ if (this.#startTask !== undefined) {
50
+ return this.#startTask;
51
+ }
52
+ const afterStop = this.#stopTask;
53
+ this.#startTask =
54
+ afterStop === undefined
55
+ ? this.#begin()
56
+ : afterStop.then(() => this.#begin());
57
+ return this.#startTask;
58
+ }
59
+
60
+ accept(snapshot: SettingsScopeSnapshot): void {
61
+ this.#snapshot = snapshot;
62
+ this.#status = { kind: "ready" };
63
+ }
64
+
65
+ stop(): Promise<void> {
66
+ if (this.#stopTask !== undefined) {
67
+ return this.#stopTask;
68
+ }
69
+ const subscription = this.#subscription;
70
+ const priorFailure =
71
+ this.#status.kind === "failed" ? this.#status.error : undefined;
72
+ this.#subscription = undefined;
73
+ this.#startTask = undefined;
74
+ ++this.#generation;
75
+ this.#snapshot = undefined;
76
+ this.#status = { kind: "idle" };
77
+ this.#stopTask = (async () => {
78
+ try {
79
+ try {
80
+ await subscription?.dispose();
81
+ } catch (error) {
82
+ if (error !== priorFailure) throw error;
83
+ }
84
+ } finally {
85
+ this.#stopTask = undefined;
86
+ }
87
+ })();
88
+ return this.#stopTask;
89
+ }
90
+
91
+ async #begin(): Promise<void> {
92
+ const generation = ++this.#generation;
93
+ this.#status = { kind: "loading" };
94
+ const subscription = this.#options.client.connectScope({
95
+ registry: this.#options.registry,
96
+ scopeId: this.#options.scopeId,
97
+ nextRequestId: this.#options.nextRequestId,
98
+ onSnapshot: (snapshot) => {
99
+ if (generation === this.#generation) {
100
+ this.accept(snapshot);
101
+ }
102
+ },
103
+ onFailure: (failure) => {
104
+ if (generation === this.#generation) {
105
+ this.#status = { kind: "failed", error: failure.error };
106
+ this.#options.onFailure?.(failure);
107
+ }
108
+ },
109
+ });
110
+ this.#subscription = subscription;
111
+ try {
112
+ const snapshot = await subscription.ready;
113
+ if (generation === this.#generation) {
114
+ this.accept(snapshot);
115
+ }
116
+ } catch (error) {
117
+ if (generation === this.#generation) {
118
+ this.#status = { kind: "failed", error };
119
+ }
120
+ throw error;
121
+ }
122
+ }
123
+ }
@@ -0,0 +1,288 @@
1
+ import type {
2
+ SettingsActivationRequirement,
3
+ SettingsApplyUnitId,
4
+ SettingsEntryId,
5
+ SettingsPageDefinition,
6
+ SettingsRegistrySnapshot,
7
+ SettingsRequestId,
8
+ SettingsScopeId,
9
+ SettingsScopeSnapshot,
10
+ } from "@inflatable-cookie/longhorn/settings/protocol";
11
+ import {
12
+ resolveSettingsDeepLink,
13
+ searchSettingsRegistry,
14
+ type SettingsRegistryProjection,
15
+ type SettingsSearchResult,
16
+ } from "@inflatable-cookie/longhorn/settings";
17
+ import type { SettingsClient } from "@inflatable-cookie/longhorn/settings";
18
+ import { createSettingsPageRenderContext } from "./context.ts";
19
+ import { SettingsPageUnavailableError } from "./errors.ts";
20
+ import type { SettingsPageSession } from "./page.svelte.ts";
21
+ import { SettingsSessionRuntime } from "./runtime.svelte.ts";
22
+ import type {
23
+ SettingsGuard,
24
+ SettingsGuardResolution,
25
+ SettingsPageRenderContext,
26
+ SettingsPageRenderer,
27
+ SettingsRendererResolver,
28
+ SettingsResetRequest,
29
+ SettingsRoute,
30
+ SettingsSessionStatus,
31
+ SettingsUnitStatus,
32
+ } from "./types.ts";
33
+
34
+ export interface SettingsSessionOptions {
35
+ readonly client: SettingsClient;
36
+ readonly nextRequestId: () => SettingsRequestId;
37
+ readonly initialRoute?: SettingsRoute;
38
+ readonly onClose?: () => void;
39
+ readonly onError?: (error: unknown) => void;
40
+ }
41
+
42
+ export class SettingsSession {
43
+ readonly #options: SettingsSessionOptions;
44
+ readonly #runtime: SettingsSessionRuntime;
45
+ #guard = $state.raw<SettingsGuard | undefined>(undefined);
46
+ #resetRequest = $state.raw<SettingsResetRequest | undefined>(undefined);
47
+
48
+ constructor(options: SettingsSessionOptions) {
49
+ this.#options = options;
50
+ this.#runtime = new SettingsSessionRuntime({
51
+ client: options.client,
52
+ nextRequestId: options.nextRequestId,
53
+ initialRoute: options.initialRoute,
54
+ onError: (error) => options.onError?.(error),
55
+ });
56
+ }
57
+
58
+ get status(): SettingsSessionStatus {
59
+ return this.#runtime.status;
60
+ }
61
+
62
+ get registry(): SettingsRegistrySnapshot | undefined {
63
+ return this.#runtime.document.registry;
64
+ }
65
+
66
+ get navigation(): SettingsRegistryProjection | undefined {
67
+ return this.#runtime.document.projection;
68
+ }
69
+
70
+ get route(): SettingsRoute | undefined {
71
+ return this.#runtime.document.route;
72
+ }
73
+
74
+ get guard(): SettingsGuard | undefined {
75
+ return this.#guard;
76
+ }
77
+
78
+ get resetRequest(): SettingsResetRequest | undefined {
79
+ return this.#resetRequest;
80
+ }
81
+
82
+ get focusRevision(): number {
83
+ return this.#runtime.document.focusRevision;
84
+ }
85
+
86
+ get currentPage(): SettingsPageDefinition | undefined {
87
+ return this.#runtime.document.currentPage;
88
+ }
89
+
90
+ get currentRenderer(): SettingsPageRenderer | undefined {
91
+ return this.#runtime.document.currentRenderer;
92
+ }
93
+
94
+ get currentPageSession(): SettingsPageSession | undefined {
95
+ return this.#runtime.document.currentPageSession;
96
+ }
97
+
98
+ get currentContext(): SettingsPageRenderContext | undefined {
99
+ const page = this.currentPage;
100
+ const route = this.route;
101
+ const session = this.currentPageSession;
102
+ return page === undefined || route === undefined || session === undefined
103
+ ? undefined
104
+ : createSettingsPageRenderContext(this, page, route, session);
105
+ }
106
+
107
+ get dirty(): boolean {
108
+ return this.currentPageSession?.dirty ?? false;
109
+ }
110
+
111
+ get busy(): boolean {
112
+ return this.currentPageSession?.busy ?? false;
113
+ }
114
+
115
+ /**
116
+ * Whether leaving the current page would be refused.
117
+ *
118
+ * The same question `requestClose` and `navigate` answer, asked without
119
+ * raising a guard. A shell needs it *before* the attempt: Poodle's shell
120
+ * decides whether to close itself, then tells us, and by then setting the
121
+ * state back is too late -- the value has already gone false and true
122
+ * within one tick, so nothing downstream observes a change.
123
+ */
124
+ get canLeaveCurrent(): boolean {
125
+ return this.#canLeave();
126
+ }
127
+
128
+ get draftCount(): number {
129
+ return this.currentPageSession?.drafts.length ?? 0;
130
+ }
131
+
132
+ get canApplyCurrent(): boolean {
133
+ return this.draftCount === 1 && !this.busy;
134
+ }
135
+
136
+ get activationRequirements(): readonly SettingsActivationRequirement[] {
137
+ return this.#runtime.document.currentScopes().flatMap(
138
+ ({ snapshot }) => snapshot?.activationRequirements ?? [],
139
+ );
140
+ }
141
+
142
+ get recovery() {
143
+ return (
144
+ this.#runtime.document
145
+ .currentScopes()
146
+ .map(({ snapshot }) => snapshot?.recovery)
147
+ .find((value) => value != null) ?? null
148
+ );
149
+ }
150
+
151
+ get primaryUnitStatus(): SettingsUnitStatus {
152
+ const page = this.currentPage;
153
+ const session = this.currentPageSession;
154
+ if (page === undefined || session === undefined) {
155
+ return { kind: "idle" };
156
+ }
157
+ const statuses = page.writableApplyUnitIds.map((id) =>
158
+ session.status(id),
159
+ );
160
+ return (
161
+ statuses.find(({ kind }) => kind === "pending") ??
162
+ statuses.find(({ kind }) => kind === "failed") ??
163
+ statuses.find(({ kind }) => kind === "conflict") ??
164
+ statuses.find(({ kind }) => kind === "rejected") ??
165
+ statuses.find(({ kind }) => kind === "saved") ??
166
+ { kind: "idle" }
167
+ );
168
+ }
169
+
170
+ start(rendererResolver: SettingsRendererResolver): Promise<void> {
171
+ return this.#runtime.start(rendererResolver);
172
+ }
173
+
174
+ async stop(): Promise<void> {
175
+ this.#guard = undefined;
176
+ this.#resetRequest = undefined;
177
+ await this.#runtime.stop();
178
+ }
179
+
180
+ search(query: string): readonly SettingsSearchResult[] {
181
+ return this.registry === undefined
182
+ ? []
183
+ : searchSettingsRegistry(this.registry, query);
184
+ }
185
+
186
+ async navigate(route: SettingsRoute): Promise<boolean> {
187
+ resolveSettingsDeepLink(this.#runtime.document.requiredRegistry(), route);
188
+ if (!this.#canLeave()) {
189
+ this.#guard = { kind: "navigate", route };
190
+ return false;
191
+ }
192
+ await this.#runtime.document.installRoute(route);
193
+ return true;
194
+ }
195
+
196
+ requestClose(): boolean {
197
+ if (!this.#canLeave()) {
198
+ this.#guard = { kind: "close" };
199
+ return false;
200
+ }
201
+ this.#options.onClose?.();
202
+ return true;
203
+ }
204
+
205
+ async resolveGuard(resolution: SettingsGuardResolution): Promise<boolean> {
206
+ const guard = this.#guard;
207
+ const page = this.currentPageSession;
208
+ if (guard === undefined) return true;
209
+ if (resolution === "stay") {
210
+ this.#guard = undefined;
211
+ return false;
212
+ }
213
+ if (page === undefined) {
214
+ this.#guard = undefined;
215
+ return false;
216
+ }
217
+ if (page.busy) return false;
218
+ if (resolution === "apply") {
219
+ if (!(await page.applyOnlyDraft())) return false;
220
+ } else {
221
+ page.cancel();
222
+ }
223
+ this.#guard = undefined;
224
+ if (guard.kind === "navigate") {
225
+ await this.#runtime.document.installRoute(guard.route);
226
+ } else {
227
+ this.#options.onClose?.();
228
+ }
229
+ return true;
230
+ }
231
+
232
+ cancelCurrent(): void {
233
+ this.currentPageSession?.cancel();
234
+ }
235
+
236
+ async applyCurrent(): Promise<boolean> {
237
+ return (await this.currentPageSession?.applyOnlyDraft()) ?? true;
238
+ }
239
+
240
+ async requestReset(
241
+ applyUnitId: SettingsApplyUnitId,
242
+ entryIds: readonly SettingsEntryId[],
243
+ ): Promise<void> {
244
+ const page = this.currentPage;
245
+ if (page === undefined) throw new SettingsPageUnavailableError();
246
+ const request = {
247
+ pageId: page.id,
248
+ applyUnitId,
249
+ entryIds: [...entryIds],
250
+ };
251
+ if (page.features.confirmation) {
252
+ this.#resetRequest = request;
253
+ } else {
254
+ await this.#executeReset(request);
255
+ }
256
+ }
257
+
258
+ async resolveReset(confirmed: boolean): Promise<void> {
259
+ const request = this.#resetRequest;
260
+ this.#resetRequest = undefined;
261
+ if (confirmed && request !== undefined) {
262
+ await this.#executeReset(request);
263
+ }
264
+ }
265
+
266
+ scopeSnapshot(scopeId: SettingsScopeId): SettingsScopeSnapshot | undefined {
267
+ return this.#runtime.document.scopeSnapshot(scopeId);
268
+ }
269
+
270
+ reconnect(): Promise<void> {
271
+ return this.#runtime.reconnect();
272
+ }
273
+
274
+ #canLeave(): boolean {
275
+ const page = this.currentPageSession;
276
+ return page === undefined || (!page.dirty && !page.busy);
277
+ }
278
+
279
+ async #executeReset(request: SettingsResetRequest): Promise<void> {
280
+ if (request.pageId !== this.currentPage?.id) {
281
+ throw new SettingsPageUnavailableError();
282
+ }
283
+ await this.currentPageSession?.reset(
284
+ request.applyUnitId,
285
+ request.entryIds,
286
+ );
287
+ }
288
+ }
@@ -0,0 +1,90 @@
1
+ import type { Snippet } from "svelte";
2
+
3
+ import type {
4
+ SettingsActivationRequirement,
5
+ SettingsApplyUnitId,
6
+ SettingsAnchorId,
7
+ SettingsConflict,
8
+ SettingsMutationReceipt,
9
+ SettingsOpaqueValue,
10
+ SettingsPageDefinition,
11
+ SettingsPageId,
12
+ SettingsRecoveryState,
13
+ SettingsRejection,
14
+ SettingsRendererId,
15
+ SettingsScopeId,
16
+ SettingsScopeSnapshot,
17
+ } from "@inflatable-cookie/longhorn/settings/protocol";
18
+
19
+ export type SettingsSessionStatus =
20
+ | { readonly kind: "idle" }
21
+ | { readonly kind: "loading" }
22
+ | { readonly kind: "ready" }
23
+ | { readonly kind: "reconnecting" }
24
+ | { readonly kind: "unsupported"; readonly reason: string }
25
+ | { readonly kind: "failed"; readonly error: unknown };
26
+
27
+ export type SettingsScopeStatus =
28
+ | { readonly kind: "idle" }
29
+ | { readonly kind: "loading" }
30
+ | { readonly kind: "ready" }
31
+ | { readonly kind: "failed"; readonly error: unknown };
32
+
33
+ export type SettingsUnitStatus =
34
+ | { readonly kind: "idle" }
35
+ | { readonly kind: "pending" }
36
+ | { readonly kind: "saved"; readonly receipt: SettingsMutationReceipt }
37
+ | { readonly kind: "conflict"; readonly conflict: SettingsConflict }
38
+ | { readonly kind: "rejected"; readonly rejection: SettingsRejection }
39
+ | { readonly kind: "failed"; readonly error: unknown };
40
+
41
+ export interface SettingsRoute {
42
+ readonly pageId: SettingsPageId;
43
+ readonly anchorId?: SettingsAnchorId;
44
+ }
45
+
46
+ export interface SettingsDraft {
47
+ readonly applyUnitId: SettingsApplyUnitId;
48
+ readonly intent: SettingsOpaqueValue;
49
+ }
50
+
51
+ export type SettingsGuard =
52
+ | { readonly kind: "navigate"; readonly route: SettingsRoute }
53
+ | { readonly kind: "close" };
54
+
55
+ export type SettingsGuardResolution = "apply" | "discard" | "stay";
56
+
57
+ export interface SettingsResetRequest {
58
+ readonly pageId: SettingsPageId;
59
+ readonly applyUnitId: SettingsApplyUnitId;
60
+ readonly entryIds: readonly string[];
61
+ }
62
+
63
+ export interface SettingsPageRenderContext {
64
+ readonly page: SettingsPageDefinition;
65
+ readonly route: SettingsRoute;
66
+ readonly dirty: boolean;
67
+ readonly busy: boolean;
68
+ readonly activationRequirements: readonly SettingsActivationRequirement[];
69
+ readonly recovery: SettingsRecoveryState | null;
70
+ snapshot(scopeId: SettingsScopeId): SettingsScopeSnapshot | undefined;
71
+ unitStatus(applyUnitId: SettingsApplyUnitId): SettingsUnitStatus;
72
+ draft(applyUnitId: SettingsApplyUnitId): SettingsDraft | undefined;
73
+ change(
74
+ applyUnitId: SettingsApplyUnitId,
75
+ intent: SettingsOpaqueValue,
76
+ ): Promise<void>;
77
+ apply(applyUnitId: SettingsApplyUnitId): Promise<void>;
78
+ cancel(): void;
79
+ requestReset(
80
+ applyUnitId: SettingsApplyUnitId,
81
+ entryIds: readonly string[],
82
+ ): Promise<void>;
83
+ }
84
+
85
+ export type SettingsPageRenderer = Snippet<[SettingsPageRenderContext]>;
86
+
87
+ export type SettingsRendererResolver = (
88
+ rendererId: SettingsRendererId,
89
+ page: SettingsPageDefinition,
90
+ ) => SettingsPageRenderer | undefined;
@@ -0,0 +1,6 @@
1
+ export * from "./svelte/types.ts";
2
+ export * from "./svelte/errors.ts";
3
+ export * from "./svelte/scope.svelte.ts";
4
+ export * from "./svelte/page.svelte.ts";
5
+ export * from "./svelte/session.svelte.ts";
6
+ export * from "./svelte/lifecycle.ts";
@@ -0,0 +1,6 @@
1
+ declare module "*.svelte" {
2
+ import type { Component } from "svelte";
3
+
4
+ const component: Component<Record<string, unknown>>;
5
+ export default component;
6
+ }