@inflatable-cookie/longhorn-poodle-svelte 0.6.0 → 0.7.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.
- package/package.json +4 -4
- package/src/bindings/drop-target.ts +39 -0
- package/src/bindings/element-geometry.ts +10 -0
- package/src/bindings/freeze-projection.ts +11 -0
- package/src/bindings/layout.svelte.ts +14 -3
- package/src/bindings/lifecycle.svelte.ts +30 -52
- package/src/bindings/mount.ts +18 -0
- package/src/bindings/sample-controller.svelte.ts +19 -0
- package/src/bindings/session-projection.svelte.ts +98 -0
- package/src/bindings/start-stop.ts +64 -0
- package/src/bindings/surface-transfer-actions.ts +16 -62
- package/src/bindings/surface-transfer.svelte.ts +50 -44
- package/src/bindings/surfaces.svelte.ts +19 -10
- package/src/bindings/teardown.ts +16 -0
- package/src/bindings/transfer-actions.ts +26 -11
- package/src/bindings/transfer.svelte.ts +129 -71
- package/src/commands/poodle/CommandPaletteBinding.svelte +71 -7
- package/src/commands/poodle/KeybindingSettings.svelte +166 -69
- package/src/commands/svelte/lifecycle.ts +2 -11
- package/src/config/poodle/BackupSettingsPage.svelte +66 -98
- package/src/config/poodle/ConfigSnapshotState.svelte +26 -0
- package/src/config/poodle/RestoreSettingsPage.svelte +90 -125
- package/src/config/poodle/StorageSettingsPage.svelte +77 -104
- package/src/config/poodle/page-state.svelte.ts +81 -0
- package/src/config/poodle/restore-model.ts +78 -0
- package/src/history/svelte/lifecycle.ts +2 -11
- package/src/history/svelte/session.svelte.ts +78 -41
- package/src/history-tree/svelte/lifecycle.ts +3 -10
- package/src/history-tree/svelte/session.svelte.ts +62 -34
- package/src/licence/poodle/LicenceActivation.svelte +47 -6
- package/src/licence/poodle/LicenceSurface.svelte.ts +14 -48
- package/src/native-content/lifecycle.ts +2 -11
- package/src/native-content/session.svelte.ts +47 -80
- package/src/notifications/poodle/NotificationPanel.svelte +33 -10
- package/src/notifications/poodle/NotificationToastHost.svelte +12 -33
- package/src/notifications/poodle/NotificationToastStack.svelte +7 -22
- package/src/notifications/poodle/toasts.ts +34 -0
- package/src/notifications/svelte/lifecycle.ts +2 -11
- package/src/notifications/svelte/session.svelte.ts +84 -46
- package/src/operation/poodle/OperationPanel.svelte +16 -9
- package/src/operation/svelte/lifecycle.ts +2 -11
- package/src/operation/svelte/session.svelte.ts +69 -36
- package/src/poodle/transfer.ts +10 -65
- package/src/settings/poodle/SettingsShell.svelte +102 -33
- package/src/settings/svelte/document.svelte.ts +24 -8
- package/src/settings/svelte/page.svelte.ts +19 -10
- package/src/settings/svelte/runtime.svelte.ts +69 -67
- package/src/settings/svelte/scope.svelte.ts +44 -52
- package/src/update/poodle/UpdateCentre.svelte +4 -6
- package/src/update/poodle/UpdateSettings.svelte +3 -2
- package/src/update/poodle/UpdateStatus.svelte +2 -0
- package/src/update/poodle/UpdateSurface.svelte.ts +31 -80
|
@@ -9,6 +9,8 @@ import type { DragSessionId } from "@inflatable-cookie/longhorn/transfer";
|
|
|
9
9
|
|
|
10
10
|
import { UnsupportedCapabilityError } from "./index.ts";
|
|
11
11
|
import type { ClientStatus } from "./index.ts";
|
|
12
|
+
import { StartStop } from "./start-stop.ts";
|
|
13
|
+
import { throwTeardownFailures } from "./teardown.ts";
|
|
12
14
|
|
|
13
15
|
export type SurfaceTransferPreparationState =
|
|
14
16
|
| { readonly status: "idle" }
|
|
@@ -48,8 +50,8 @@ export class SurfaceTransferState {
|
|
|
48
50
|
});
|
|
49
51
|
#activeSessionId: DragSessionId | undefined;
|
|
50
52
|
#generation = 0;
|
|
51
|
-
#tasks = new Set<Promise<unknown>>();
|
|
52
|
-
#
|
|
53
|
+
readonly #tasks = new Set<Promise<unknown>>();
|
|
54
|
+
readonly #lifetime = new StartStop();
|
|
53
55
|
#stopped = true;
|
|
54
56
|
#destroyed = false;
|
|
55
57
|
|
|
@@ -71,24 +73,33 @@ export class SurfaceTransferState {
|
|
|
71
73
|
|
|
72
74
|
async start(): Promise<void> {
|
|
73
75
|
this.#assertAlive();
|
|
74
|
-
this.#
|
|
75
|
-
|
|
76
|
-
this.#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
await this.#lifetime.start(async () => {
|
|
77
|
+
this.#stopped = false;
|
|
78
|
+
this.#status =
|
|
79
|
+
this.#options.client === undefined
|
|
80
|
+
? {
|
|
81
|
+
kind: "unsupported",
|
|
82
|
+
reason:
|
|
83
|
+
this.#options.unsupportedReason ?? "Surface transfer capability is unavailable",
|
|
84
|
+
}
|
|
85
|
+
: { kind: "ready" };
|
|
86
|
+
});
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
async prepare(request: SurfaceSessionStartRequest): Promise<SurfaceSessionResponse> {
|
|
85
90
|
this.#assertRunning();
|
|
91
|
+
return this.#track(this.#prepare(request));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async #prepare(request: SurfaceSessionStartRequest): Promise<SurfaceSessionResponse> {
|
|
86
95
|
const client = this.#requireClient();
|
|
87
|
-
await this.#cancelActive();
|
|
88
96
|
const generation = ++this.#generation;
|
|
89
|
-
this.#
|
|
97
|
+
await this.#cancelActive();
|
|
98
|
+
if (generation === this.#generation) {
|
|
99
|
+
this.#preparation = { status: "preparing", request };
|
|
100
|
+
}
|
|
90
101
|
|
|
91
|
-
|
|
102
|
+
return client
|
|
92
103
|
.start(request)
|
|
93
104
|
.then(async (response) => {
|
|
94
105
|
if (generation !== this.#generation || this.#stopped) {
|
|
@@ -108,16 +119,17 @@ export class SurfaceTransferState {
|
|
|
108
119
|
.catch((error: unknown) => {
|
|
109
120
|
if (generation === this.#generation && !this.#stopped) {
|
|
110
121
|
this.#preparation = { status: "failed", error };
|
|
111
|
-
this.#status = { kind: "failed", error };
|
|
112
122
|
}
|
|
113
123
|
throw error;
|
|
114
124
|
});
|
|
115
|
-
this.#track(task);
|
|
116
|
-
return task;
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
async commit(request: SurfaceTransferCommand): Promise<SurfaceTransferResponse> {
|
|
120
128
|
this.#assertRunning();
|
|
129
|
+
return this.#track(this.#commit(request));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async #commit(request: SurfaceTransferCommand): Promise<SurfaceTransferResponse> {
|
|
121
133
|
const client = this.#requireClient();
|
|
122
134
|
this.#completion = { status: "committing", request };
|
|
123
135
|
try {
|
|
@@ -126,68 +138,62 @@ export class SurfaceTransferState {
|
|
|
126
138
|
status: response.status === "committed" ? "committed" : "aborted",
|
|
127
139
|
response,
|
|
128
140
|
};
|
|
129
|
-
if (
|
|
141
|
+
if (
|
|
142
|
+
this.#activeSessionId === request.session_id &&
|
|
143
|
+
(response.status === "committed" || response.abort.session_consumed)
|
|
144
|
+
) {
|
|
130
145
|
this.#activeSessionId = undefined;
|
|
131
146
|
}
|
|
132
147
|
return response;
|
|
133
148
|
} catch (error) {
|
|
134
149
|
this.#completion = { status: "failed", error };
|
|
135
|
-
this.#status = { kind: "failed", error };
|
|
136
150
|
throw error;
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
cancelPreparation(): Promise<void> {
|
|
141
|
-
++this.#generation;
|
|
142
|
-
return this.#cancelActive();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
stop(): Promise<void> {
|
|
146
|
-
if (this.#stopTask !== undefined) {
|
|
147
|
-
return this.#stopTask;
|
|
148
|
-
}
|
|
149
155
|
if (this.#stopped) {
|
|
150
156
|
return Promise.resolve();
|
|
151
157
|
}
|
|
152
|
-
this.#
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
return this.#stopTask;
|
|
158
|
+
++this.#generation;
|
|
159
|
+
return this.#track(this.#cancelActive());
|
|
156
160
|
}
|
|
157
161
|
|
|
158
|
-
|
|
159
|
-
this.#
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
stop(): Promise<void> {
|
|
163
|
+
return this.#lifetime.stop(async () => {
|
|
164
|
+
this.#stopped = true;
|
|
165
|
+
++this.#generation;
|
|
166
|
+
this.#status = { kind: "idle" };
|
|
167
|
+
const results = await Promise.allSettled([this.#cancelActive(), ...this.#tasks]);
|
|
168
|
+
this.#status = { kind: "idle" };
|
|
169
|
+
this.#preparation = { status: "idle" };
|
|
170
|
+
this.#completion = { status: "idle" };
|
|
171
|
+
throwTeardownFailures(results);
|
|
172
|
+
});
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
async destroy(): Promise<void> {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.#destroyed = true;
|
|
172
|
-
}
|
|
176
|
+
this.#destroyed = true;
|
|
177
|
+
await this.stop();
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
async #cancelActive(): Promise<void> {
|
|
176
181
|
const sessionId = this.#activeSessionId;
|
|
177
182
|
this.#activeSessionId = undefined;
|
|
183
|
+
this.#preparation = { status: "idle" };
|
|
178
184
|
if (sessionId !== undefined) {
|
|
179
185
|
await this.#options.cancelSession(sessionId);
|
|
180
186
|
}
|
|
181
|
-
this.#preparation = { status: "idle" };
|
|
182
187
|
}
|
|
183
188
|
|
|
184
|
-
#track(task: Promise<
|
|
189
|
+
#track<Result>(task: Promise<Result>): Promise<Result> {
|
|
185
190
|
this.#tasks.add(task);
|
|
186
191
|
void task
|
|
187
192
|
.finally(() => {
|
|
188
193
|
this.#tasks.delete(task);
|
|
189
194
|
})
|
|
190
195
|
.catch(() => undefined);
|
|
196
|
+
return task;
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
#requireClient(): SurfaceTransferClient {
|
|
@@ -30,6 +30,8 @@ export interface SurfaceStateOptions {
|
|
|
30
30
|
readonly unsupportedReason?: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
const RECENT_OPERATION_LIMIT = 32;
|
|
34
|
+
|
|
33
35
|
export class SurfaceState {
|
|
34
36
|
readonly #client: SurfaceClient | undefined;
|
|
35
37
|
readonly #lifecycle: ReactiveClientState<SurfaceSnapshot>;
|
|
@@ -109,16 +111,20 @@ export class SurfaceState {
|
|
|
109
111
|
|
|
110
112
|
const epoch = this.#epoch;
|
|
111
113
|
this.#projection.begin(request.request_id, project);
|
|
112
|
-
|
|
114
|
+
const pending = {
|
|
113
115
|
requestId: request.request_id,
|
|
114
116
|
status: "pending",
|
|
115
|
-
}
|
|
117
|
+
} satisfies SurfaceMutationOperation;
|
|
118
|
+
this.#setOperation(pending);
|
|
116
119
|
try {
|
|
117
120
|
const response = await client.mutate(request);
|
|
118
121
|
const document =
|
|
119
122
|
response.status === "committed"
|
|
120
123
|
? response.receipt.authoritative_document
|
|
121
124
|
: response.rejection.authoritative_document;
|
|
125
|
+
if (!this.#operations.includes(pending)) {
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
122
128
|
if (epoch !== undefined && this.#epoch === epoch) {
|
|
123
129
|
this.#projection.settle(request.request_id, document);
|
|
124
130
|
} else {
|
|
@@ -131,13 +137,10 @@ export class SurfaceState {
|
|
|
131
137
|
});
|
|
132
138
|
return response;
|
|
133
139
|
} catch (error) {
|
|
134
|
-
this.#
|
|
135
|
-
|
|
136
|
-
requestId: request.request_id,
|
|
137
|
-
|
|
138
|
-
error,
|
|
139
|
-
});
|
|
140
|
-
this.#lifecycle.fail(error);
|
|
140
|
+
if (this.#operations.includes(pending)) {
|
|
141
|
+
this.#projection.cancel(request.request_id);
|
|
142
|
+
this.#setOperation({ requestId: request.request_id, status: "failed", error });
|
|
143
|
+
}
|
|
141
144
|
throw error;
|
|
142
145
|
}
|
|
143
146
|
}
|
|
@@ -165,9 +168,15 @@ export class SurfaceState {
|
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
#setOperation(operation: SurfaceMutationOperation): void {
|
|
168
|
-
|
|
171
|
+
const operations = [
|
|
169
172
|
...this.#operations.filter(({ requestId }) => requestId !== operation.requestId),
|
|
170
173
|
operation,
|
|
171
174
|
];
|
|
175
|
+
const settled = operations.filter(({ status }) => status !== "pending");
|
|
176
|
+
if (settled.length > RECENT_OPERATION_LIMIT) {
|
|
177
|
+
const oldest = operations.findIndex(({ status }) => status !== "pending");
|
|
178
|
+
operations.splice(oldest, 1);
|
|
179
|
+
}
|
|
180
|
+
this.#operations = operations;
|
|
172
181
|
}
|
|
173
182
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Attempt every cleanup step and preserve the original error when only one fails.
|
|
2
|
+
export function throwTeardownFailures(results: ReadonlyArray<PromiseSettledResult<unknown>>): void {
|
|
3
|
+
const failures: Array<unknown> = [];
|
|
4
|
+
for (const result of results) {
|
|
5
|
+
if (result.status === "rejected") {
|
|
6
|
+
failures.push(result.reason);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
if (failures.length === 1) {
|
|
10
|
+
// Preserve the host rejection, including serialized failures.
|
|
11
|
+
throw failures[0];
|
|
12
|
+
}
|
|
13
|
+
if (failures.length > 1) {
|
|
14
|
+
throw new AggregateError(failures, "Multiple cleanup steps failed");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
TransferLeaseResponse,
|
|
6
6
|
} from "@inflatable-cookie/longhorn/transfer";
|
|
7
7
|
|
|
8
|
+
import { observeViewportMovement } from "./element-geometry.ts";
|
|
8
9
|
import type { TransferState } from "./transfer.svelte.ts";
|
|
9
10
|
|
|
10
11
|
export type DropZoneDefinition = Omit<ClientDropZone, "bounds">;
|
|
@@ -34,6 +35,7 @@ export class DropZoneLeaseRegistry {
|
|
|
34
35
|
readonly #zones = new Map<string, RegisteredZone>();
|
|
35
36
|
#tail: Promise<unknown> = Promise.resolve();
|
|
36
37
|
#active = false;
|
|
38
|
+
#publicationScheduled = false;
|
|
37
39
|
#destroyed = false;
|
|
38
40
|
#lastGeneration = 0;
|
|
39
41
|
|
|
@@ -107,10 +109,12 @@ export class DropZoneLeaseRegistry {
|
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
#schedulePublication(): void {
|
|
110
|
-
if (!this.#active || this.#destroyed) {
|
|
112
|
+
if (!this.#active || this.#destroyed || this.#publicationScheduled) {
|
|
111
113
|
return;
|
|
112
114
|
}
|
|
115
|
+
this.#publicationScheduled = true;
|
|
113
116
|
void this.#serialize(async () => {
|
|
117
|
+
this.#publicationScheduled = false;
|
|
114
118
|
if (!this.#active || this.#destroyed) {
|
|
115
119
|
return;
|
|
116
120
|
}
|
|
@@ -124,13 +128,20 @@ export class DropZoneLeaseRegistry {
|
|
|
124
128
|
throw new DropZoneLeaseSnapshotUnavailableError();
|
|
125
129
|
}
|
|
126
130
|
const generation = nextGeneration(this.#lastGeneration);
|
|
131
|
+
const zones: Array<ClientDropZone> = [];
|
|
132
|
+
for (const registration of this.#zones.values()) {
|
|
133
|
+
const zone = measureZone(registration);
|
|
134
|
+
if (zone !== undefined) {
|
|
135
|
+
zones.push(zone);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
127
138
|
const request: TransferLeaseRequest = {
|
|
128
139
|
protocol_version: TRANSFER_PROTOCOL_VERSION,
|
|
129
140
|
request_id: this.#options.nextRequestId(),
|
|
130
141
|
client_id: snapshot.client_id,
|
|
131
142
|
client_epoch: snapshot.client_epoch,
|
|
132
143
|
generation,
|
|
133
|
-
zones
|
|
144
|
+
zones,
|
|
134
145
|
};
|
|
135
146
|
const response = await this.#options.state.publishLease(request);
|
|
136
147
|
if (response.status === "published") {
|
|
@@ -194,15 +205,18 @@ export class DropZoneLeaseDestroyedError extends Error {
|
|
|
194
205
|
}
|
|
195
206
|
}
|
|
196
207
|
|
|
197
|
-
function measureZone(registration: RegisteredZone): ClientDropZone {
|
|
208
|
+
function measureZone(registration: RegisteredZone): ClientDropZone | undefined {
|
|
198
209
|
const rect = registration.node.getBoundingClientRect();
|
|
199
210
|
for (const value of [rect.left, rect.top, rect.width, rect.height]) {
|
|
200
211
|
if (!Number.isFinite(value)) {
|
|
201
212
|
throw new RangeError("drop-zone geometry must be finite");
|
|
202
213
|
}
|
|
203
214
|
}
|
|
204
|
-
if (rect.width
|
|
205
|
-
throw new RangeError("drop-zone geometry must have
|
|
215
|
+
if (rect.width < 0 || rect.height < 0) {
|
|
216
|
+
throw new RangeError("drop-zone geometry must have non-negative extent");
|
|
217
|
+
}
|
|
218
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
219
|
+
return undefined;
|
|
206
220
|
}
|
|
207
221
|
return {
|
|
208
222
|
...registration.definition,
|
|
@@ -222,10 +236,11 @@ function nextGeneration(lastGeneration: number): number {
|
|
|
222
236
|
}
|
|
223
237
|
|
|
224
238
|
function observeElementGeometry(node: HTMLElement, changed: () => void): () => void {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(changed);
|
|
240
|
+
observer?.observe(node);
|
|
241
|
+
const stopMovement = observeViewportMovement(node, changed);
|
|
242
|
+
return () => {
|
|
243
|
+
observer?.disconnect();
|
|
244
|
+
stopMovement();
|
|
245
|
+
};
|
|
231
246
|
}
|