@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inflatable-cookie/longhorn-poodle-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -151,9 +151,9 @@
|
|
|
151
151
|
"LICENSE"
|
|
152
152
|
],
|
|
153
153
|
"peerDependencies": {
|
|
154
|
-
"@inflatable-cookie/longhorn": "0.
|
|
155
|
-
"@inflatable-cookie/poodle-core": ">=0.
|
|
156
|
-
"@inflatable-cookie/poodle-svelte": ">=0.
|
|
154
|
+
"@inflatable-cookie/longhorn": "0.7.0",
|
|
155
|
+
"@inflatable-cookie/poodle-core": ">=0.5.0 <0.6",
|
|
156
|
+
"@inflatable-cookie/poodle-svelte": ">=0.5.0 <0.6",
|
|
157
157
|
"svelte": ">=5.56.8 <6"
|
|
158
158
|
},
|
|
159
159
|
"peerDependenciesMeta": {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TransferCommitSelector } from "@inflatable-cookie/longhorn/transfer";
|
|
2
|
+
|
|
3
|
+
export type DropSelector =
|
|
4
|
+
| { readonly kind: "explicit_zone"; readonly dropZoneId: string }
|
|
5
|
+
| { readonly kind: "screen_point" };
|
|
6
|
+
|
|
7
|
+
export function resolveDropSelector(
|
|
8
|
+
selector: DropSelector,
|
|
9
|
+
screenPoint: (() => { readonly x: number; readonly y: number }) | undefined,
|
|
10
|
+
): TransferCommitSelector {
|
|
11
|
+
if (selector.kind === "explicit_zone") {
|
|
12
|
+
return { kind: "explicit_zone", drop_zone_id: selector.dropZoneId };
|
|
13
|
+
}
|
|
14
|
+
const point = screenPoint?.();
|
|
15
|
+
if (point === undefined || !Number.isSafeInteger(point.x) || !Number.isSafeInteger(point.y)) {
|
|
16
|
+
throw new RangeError("drop screen point must use integer screen DIPs");
|
|
17
|
+
}
|
|
18
|
+
return { kind: "screen_point", point: { x: point.x, y: point.y } };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function reportError(reporter: (error: unknown) => void, error: unknown): void {
|
|
22
|
+
try {
|
|
23
|
+
reporter(error);
|
|
24
|
+
} catch {
|
|
25
|
+
// Reporting failure must not escape an event callback.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function notify<Value>(
|
|
30
|
+
listener: ((value: Value) => void) | undefined,
|
|
31
|
+
value: Value,
|
|
32
|
+
reporter: (error: unknown) => void,
|
|
33
|
+
): void {
|
|
34
|
+
try {
|
|
35
|
+
listener?.(value);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
reportError(reporter, error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Client rect origins can move when the window or a nested scroller scrolls. */
|
|
2
|
+
export function observeViewportMovement(node: HTMLElement, changed: () => void): () => void {
|
|
3
|
+
const view = node.ownerDocument.defaultView;
|
|
4
|
+
view?.addEventListener("scroll", changed, { capture: true, passive: true });
|
|
5
|
+
view?.addEventListener("resize", changed);
|
|
6
|
+
return () => {
|
|
7
|
+
view?.removeEventListener("scroll", changed, true);
|
|
8
|
+
view?.removeEventListener("resize", changed);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Only call this on owned protocol data. Errors and other caller values stay opaque.
|
|
2
|
+
export function freezeProjection<Value>(value: Value): Value {
|
|
3
|
+
if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
|
|
4
|
+
Object.freeze(value);
|
|
5
|
+
const children: Array<unknown> = Object.values(value);
|
|
6
|
+
for (const child of children) {
|
|
7
|
+
freezeProjection(child);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
@@ -29,6 +29,7 @@ export class LayoutState {
|
|
|
29
29
|
);
|
|
30
30
|
#status = $state.raw<ClientStatus>({ kind: "idle" });
|
|
31
31
|
#destroyed = false;
|
|
32
|
+
#generation = 0;
|
|
32
33
|
|
|
33
34
|
constructor(options: LayoutStateOptions) {
|
|
34
35
|
this.#options = options;
|
|
@@ -64,7 +65,7 @@ export class LayoutState {
|
|
|
64
65
|
accept(document: SurfaceDocument): boolean {
|
|
65
66
|
this.#assertAlive();
|
|
66
67
|
const accepted = this.#projection.accept(document);
|
|
67
|
-
if (accepted) {
|
|
68
|
+
if (accepted && this.#status.kind !== "unsupported") {
|
|
68
69
|
this.#status = { kind: "ready" };
|
|
69
70
|
}
|
|
70
71
|
return accepted;
|
|
@@ -72,6 +73,9 @@ export class LayoutState {
|
|
|
72
73
|
|
|
73
74
|
reconnecting(): void {
|
|
74
75
|
this.#assertAlive();
|
|
76
|
+
if (this.#status.kind === "unsupported") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
75
79
|
this.#status =
|
|
76
80
|
this.#projection.authoritative === undefined ? { kind: "loading" } : { kind: "reconnecting" };
|
|
77
81
|
}
|
|
@@ -88,9 +92,13 @@ export class LayoutState {
|
|
|
88
92
|
throw new UnsupportedCapabilityError(reason);
|
|
89
93
|
}
|
|
90
94
|
|
|
95
|
+
const generation = this.#generation;
|
|
91
96
|
this.#projection.begin(request.request_id, project);
|
|
92
97
|
try {
|
|
93
98
|
const result = await dispatch(request);
|
|
99
|
+
if (generation !== this.#generation) {
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
94
102
|
const document =
|
|
95
103
|
result.status === "committed"
|
|
96
104
|
? result.receipt.authoritative_document
|
|
@@ -99,8 +107,10 @@ export class LayoutState {
|
|
|
99
107
|
this.#status = { kind: "ready" };
|
|
100
108
|
return result;
|
|
101
109
|
} catch (error) {
|
|
102
|
-
this.#
|
|
103
|
-
|
|
110
|
+
if (generation === this.#generation) {
|
|
111
|
+
this.#projection.cancel(request.request_id);
|
|
112
|
+
this.#status = { kind: "failed", error };
|
|
113
|
+
}
|
|
104
114
|
throw error;
|
|
105
115
|
}
|
|
106
116
|
}
|
|
@@ -110,6 +120,7 @@ export class LayoutState {
|
|
|
110
120
|
}
|
|
111
121
|
|
|
112
122
|
async stop(): Promise<void> {
|
|
123
|
+
++this.#generation;
|
|
113
124
|
this.#projection.clear();
|
|
114
125
|
this.#status = { kind: "idle" };
|
|
115
126
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSessionLifecycle } from "./mount.ts";
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
ConnectionFailure,
|
|
5
5
|
ConnectionFailureReporter,
|
|
6
6
|
} from "@inflatable-cookie/longhorn/core";
|
|
7
7
|
|
|
8
|
+
import { StartStop } from "./start-stop.ts";
|
|
9
|
+
|
|
8
10
|
export type ClientStatus =
|
|
9
11
|
| { readonly kind: "idle" }
|
|
10
12
|
| { readonly kind: "loading" }
|
|
@@ -47,9 +49,7 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
47
49
|
#status = $state.raw<ClientStatus>({ kind: "idle" });
|
|
48
50
|
#snapshot = $state.raw<Snapshot | undefined>(undefined);
|
|
49
51
|
#connection: ReactiveConnection<Snapshot> | undefined;
|
|
50
|
-
#
|
|
51
|
-
#stopTask: Promise<void> | undefined;
|
|
52
|
-
#generation = 0;
|
|
52
|
+
readonly #lifecycle = new StartStop();
|
|
53
53
|
#destroyed = false;
|
|
54
54
|
|
|
55
55
|
constructor(options: ReactiveClientStateOptions<Snapshot>) {
|
|
@@ -68,14 +68,7 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
68
68
|
if (this.#destroyed) {
|
|
69
69
|
return Promise.reject(new ClientStateDestroyedError());
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
return this.#startTask;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const afterStop = this.#stopTask;
|
|
76
|
-
this.#startTask =
|
|
77
|
-
afterStop === undefined ? this.#begin(false) : afterStop.then(() => this.#begin(false));
|
|
78
|
-
return this.#startTask;
|
|
71
|
+
return this.#lifecycle.start((generation) => this.#begin(generation, false), true);
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
reconnect(): Promise<void> {
|
|
@@ -86,9 +79,8 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
86
79
|
return Promise.resolve();
|
|
87
80
|
}
|
|
88
81
|
|
|
89
|
-
|
|
90
|
-
this.#
|
|
91
|
-
return task;
|
|
82
|
+
void this.#stop(false).catch(() => undefined);
|
|
83
|
+
return this.#lifecycle.start((generation) => this.#begin(generation, true), true);
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
stop(): Promise<void> {
|
|
@@ -96,10 +88,6 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
async destroy(): Promise<void> {
|
|
99
|
-
if (this.#destroyed) {
|
|
100
|
-
await this.#stopTask;
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
91
|
this.#destroyed = true;
|
|
104
92
|
await this.#stop(true);
|
|
105
93
|
}
|
|
@@ -110,7 +98,7 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
110
98
|
}
|
|
111
99
|
}
|
|
112
100
|
|
|
113
|
-
async #begin(reconnecting: boolean): Promise<void> {
|
|
101
|
+
async #begin(generation: number, reconnecting: boolean): Promise<void> {
|
|
114
102
|
const capability = this.#options.capability;
|
|
115
103
|
if (capability.kind === "unsupported") {
|
|
116
104
|
this.#status = {
|
|
@@ -120,7 +108,6 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
120
108
|
return;
|
|
121
109
|
}
|
|
122
110
|
|
|
123
|
-
const generation = ++this.#generation;
|
|
124
111
|
this.#status =
|
|
125
112
|
reconnecting || this.#snapshot !== undefined ? { kind: "reconnecting" } : { kind: "loading" };
|
|
126
113
|
|
|
@@ -128,26 +115,28 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
128
115
|
try {
|
|
129
116
|
connection = capability.connect(
|
|
130
117
|
(snapshot) => {
|
|
131
|
-
if (generation === this.#generation && !this.#destroyed) {
|
|
118
|
+
if (generation === this.#lifecycle.generation && !this.#destroyed) {
|
|
132
119
|
this.#accept(snapshot);
|
|
133
120
|
}
|
|
134
121
|
},
|
|
135
122
|
(failure) => {
|
|
136
|
-
if (generation === this.#generation && !this.#destroyed) {
|
|
123
|
+
if (generation === this.#lifecycle.generation && !this.#destroyed) {
|
|
137
124
|
this.#status = { kind: "failed", error: failure.error };
|
|
138
125
|
this.#options.onFailure?.(failure);
|
|
139
126
|
}
|
|
140
127
|
},
|
|
141
128
|
);
|
|
142
129
|
} catch (error) {
|
|
143
|
-
this.#
|
|
130
|
+
if (generation === this.#lifecycle.generation) {
|
|
131
|
+
this.#status = { kind: "failed", error };
|
|
132
|
+
}
|
|
144
133
|
throw error;
|
|
145
134
|
}
|
|
146
135
|
this.#connection = connection;
|
|
147
136
|
|
|
148
137
|
try {
|
|
149
138
|
await connection.ready;
|
|
150
|
-
if (generation !== this.#generation || this.#destroyed) {
|
|
139
|
+
if (generation !== this.#lifecycle.generation || this.#destroyed) {
|
|
151
140
|
return;
|
|
152
141
|
}
|
|
153
142
|
const snapshot = connection.current();
|
|
@@ -160,13 +149,14 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
160
149
|
this.#status = { kind: "ready" };
|
|
161
150
|
}
|
|
162
151
|
} catch (error) {
|
|
163
|
-
if (generation === this.#generation
|
|
152
|
+
if (generation === this.#lifecycle.generation) {
|
|
164
153
|
this.#status = { kind: "failed", error };
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
154
|
+
this.#connection = undefined;
|
|
155
|
+
try {
|
|
156
|
+
await connection.dispose();
|
|
157
|
+
} catch {
|
|
158
|
+
// The connection retains exact teardown failure evidence.
|
|
159
|
+
}
|
|
170
160
|
}
|
|
171
161
|
throw error;
|
|
172
162
|
}
|
|
@@ -179,30 +169,23 @@ export class ReactiveClientState<Snapshot> implements StartableClientState {
|
|
|
179
169
|
}
|
|
180
170
|
|
|
181
171
|
#stop(clearSnapshot: boolean): Promise<void> {
|
|
182
|
-
if (this.#stopTask !== undefined) {
|
|
183
|
-
return this.#stopTask;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const connection = this.#connection;
|
|
187
|
-
this.#connection = undefined;
|
|
188
|
-
this.#startTask = undefined;
|
|
189
|
-
++this.#generation;
|
|
190
172
|
if (clearSnapshot) {
|
|
191
173
|
this.#snapshot = undefined;
|
|
192
174
|
}
|
|
193
|
-
this.#status = { kind: "idle" };
|
|
194
|
-
|
|
195
|
-
|
|
175
|
+
this.#status = { kind: clearSnapshot ? "idle" : "reconnecting" };
|
|
176
|
+
return this.#lifecycle.stop(async () => {
|
|
177
|
+
// A synchronous connect callback can call stop before connect returns.
|
|
178
|
+
// Capture its connection after that call has finished publishing it.
|
|
179
|
+
await Promise.resolve();
|
|
180
|
+
const connection = this.#connection;
|
|
181
|
+
this.#connection = undefined;
|
|
196
182
|
try {
|
|
197
183
|
await connection?.dispose();
|
|
198
184
|
} catch (error) {
|
|
199
185
|
this.#status = { kind: "failed", error };
|
|
200
186
|
throw error;
|
|
201
|
-
} finally {
|
|
202
|
-
this.#stopTask = undefined;
|
|
203
187
|
}
|
|
204
|
-
})
|
|
205
|
-
return this.#stopTask;
|
|
188
|
+
});
|
|
206
189
|
}
|
|
207
190
|
}
|
|
208
191
|
|
|
@@ -231,10 +214,5 @@ export function useClientState(
|
|
|
231
214
|
state: StartableClientState,
|
|
232
215
|
reportFailure?: (error: unknown) => void,
|
|
233
216
|
): void {
|
|
234
|
-
|
|
235
|
-
void state.start().catch((error: unknown) => reportFailure?.(error));
|
|
236
|
-
return () => {
|
|
237
|
-
void state.stop().catch((error: unknown) => reportFailure?.(error));
|
|
238
|
-
};
|
|
239
|
-
});
|
|
217
|
+
useSessionLifecycle(() => state, reportFailure, reportFailure);
|
|
240
218
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { onMount } from "svelte";
|
|
2
|
+
|
|
3
|
+
import { reportFailure } from "../failures.ts";
|
|
4
|
+
import type { StartableClientState } from "./lifecycle.svelte.ts";
|
|
5
|
+
|
|
6
|
+
export function useSessionLifecycle(
|
|
7
|
+
getSession: () => StartableClientState,
|
|
8
|
+
onStartFailure: (error: unknown) => void = () => undefined,
|
|
9
|
+
onStopFailure: (error: unknown) => void = reportFailure,
|
|
10
|
+
): void {
|
|
11
|
+
onMount(() => {
|
|
12
|
+
const session = getSession();
|
|
13
|
+
void session.start().catch(onStartFailure);
|
|
14
|
+
return () => {
|
|
15
|
+
void session.stop().catch(onStopFailure);
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { untrack } from "svelte";
|
|
2
|
+
|
|
3
|
+
/** Track reads from a plain controller. The owner manages its start and stop. */
|
|
4
|
+
export function sampleController<Controller extends { observe(callback: () => void): () => void }>(
|
|
5
|
+
getController: () => Controller,
|
|
6
|
+
): () => Controller {
|
|
7
|
+
let revision = $state(0);
|
|
8
|
+
|
|
9
|
+
$effect(() =>
|
|
10
|
+
getController().observe(() => {
|
|
11
|
+
revision = untrack(() => revision) + 1;
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
void revision;
|
|
17
|
+
return getController();
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { StartStop } from "./start-stop.ts";
|
|
2
|
+
|
|
3
|
+
interface ObservableController {
|
|
4
|
+
observe(listener: () => void): () => void;
|
|
5
|
+
start(): Promise<void>;
|
|
6
|
+
stop(): Promise<void>;
|
|
7
|
+
restart(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class SessionProjection<Projection> {
|
|
11
|
+
readonly #controller: ObservableController;
|
|
12
|
+
readonly #unobserve: () => void;
|
|
13
|
+
readonly #observers = new Set<() => void>();
|
|
14
|
+
readonly #lifetime = new StartStop();
|
|
15
|
+
#current: Projection;
|
|
16
|
+
#retryFailure = $state.raw<{ readonly kind: "failed"; readonly error: unknown }>();
|
|
17
|
+
|
|
18
|
+
constructor(controller: ObservableController, project: () => Projection) {
|
|
19
|
+
this.#controller = controller;
|
|
20
|
+
this.#current = $state.raw(project());
|
|
21
|
+
this.#unobserve = controller.observe(() => {
|
|
22
|
+
this.#current = project();
|
|
23
|
+
this.#notify();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get current(): Projection {
|
|
28
|
+
return this.#current;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get retryFailure() {
|
|
32
|
+
return this.#retryFailure;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
observe(observer: () => void): () => void {
|
|
36
|
+
this.#observers.add(observer);
|
|
37
|
+
return () => this.#observers.delete(observer);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#setRetryFailure(
|
|
41
|
+
failure: { readonly kind: "failed"; readonly error: unknown } | undefined,
|
|
42
|
+
): void {
|
|
43
|
+
if (this.#retryFailure !== failure) {
|
|
44
|
+
this.#retryFailure = failure;
|
|
45
|
+
this.#notify();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#notify(): void {
|
|
50
|
+
for (const observer of this.#observers) {
|
|
51
|
+
observer();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
start(): Promise<void> {
|
|
56
|
+
return this.#lifetime.start(() => {
|
|
57
|
+
this.#setRetryFailure(undefined);
|
|
58
|
+
return this.#controller.start();
|
|
59
|
+
}, true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
stop(): Promise<void> {
|
|
63
|
+
this.#setRetryFailure(undefined);
|
|
64
|
+
return this.#lifetime.stop(() => this.#controller.stop());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async retry(previousError: unknown): Promise<void> {
|
|
68
|
+
this.#setRetryFailure(undefined);
|
|
69
|
+
const teardown = this.#lifetime.stop(async () => {
|
|
70
|
+
try {
|
|
71
|
+
await this.#controller.stop();
|
|
72
|
+
} catch (error) {
|
|
73
|
+
// A checked subscription may repeat its startup failure at teardown.
|
|
74
|
+
if (!Object.is(error, previousError)) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const start = this.#lifetime.start(() => {
|
|
80
|
+
this.#setRetryFailure(undefined);
|
|
81
|
+
return this.#controller.restart();
|
|
82
|
+
}, true);
|
|
83
|
+
const generation = this.#lifetime.generation;
|
|
84
|
+
try {
|
|
85
|
+
await Promise.all([teardown, start]);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (generation === this.#lifetime.generation) {
|
|
88
|
+
this.#setRetryFailure({ kind: "failed", error });
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async dispose(): Promise<void> {
|
|
95
|
+
this.#unobserve();
|
|
96
|
+
await this.stop();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// A stop invalidates both active callbacks and a start waiting for teardown.
|
|
2
|
+
export class StartStop {
|
|
3
|
+
#generation = 0;
|
|
4
|
+
#startTask: Promise<void> | undefined;
|
|
5
|
+
#stopTask: Promise<void> | undefined;
|
|
6
|
+
|
|
7
|
+
get generation(): number {
|
|
8
|
+
return this.#generation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
start(begin: (generation: number) => Promise<void>, retryOnFailure = false): Promise<void> {
|
|
12
|
+
if (this.#startTask !== undefined) {
|
|
13
|
+
return this.#startTask;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const generation = ++this.#generation;
|
|
17
|
+
const afterStop = this.#stopTask;
|
|
18
|
+
const { task, invoke } = reserve(async () => {
|
|
19
|
+
try {
|
|
20
|
+
if (afterStop !== undefined) {
|
|
21
|
+
await afterStop;
|
|
22
|
+
}
|
|
23
|
+
if (generation === this.#generation) {
|
|
24
|
+
await begin(generation);
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (retryOnFailure && generation === this.#generation) {
|
|
28
|
+
this.#startTask = undefined;
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.#startTask = task;
|
|
34
|
+
invoke();
|
|
35
|
+
return task;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
stop(end: () => Promise<void>): Promise<void> {
|
|
39
|
+
this.#startTask = undefined;
|
|
40
|
+
++this.#generation;
|
|
41
|
+
if (this.#stopTask === undefined) {
|
|
42
|
+
const { task, invoke } = reserve(async () => {
|
|
43
|
+
try {
|
|
44
|
+
await end();
|
|
45
|
+
} finally {
|
|
46
|
+
this.#stopTask = undefined;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.#stopTask = task;
|
|
50
|
+
invoke();
|
|
51
|
+
return task;
|
|
52
|
+
}
|
|
53
|
+
return this.#stopTask;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// StartStop needs to publish the promise before invoking synchronous hooks.
|
|
58
|
+
function reserve(run: () => Promise<void>) {
|
|
59
|
+
let invoke!: () => void;
|
|
60
|
+
const task = new Promise<void>((resolve, reject) => {
|
|
61
|
+
invoke = () => void run().then(resolve, reject);
|
|
62
|
+
});
|
|
63
|
+
return { task, invoke };
|
|
64
|
+
}
|
|
@@ -10,16 +10,12 @@ import {
|
|
|
10
10
|
parseTransferPayload,
|
|
11
11
|
serializeTransferPayload,
|
|
12
12
|
} from "@inflatable-cookie/longhorn/transfer";
|
|
13
|
-
import
|
|
13
|
+
import { notify, reportError, resolveDropSelector } from "./drop-target.ts";
|
|
14
|
+
import type { DropSelector } from "./drop-target.ts";
|
|
14
15
|
|
|
15
16
|
import type { SurfaceTransferState } from "./surface-transfer.svelte.ts";
|
|
16
17
|
|
|
17
|
-
export type SurfaceDropSelector =
|
|
18
|
-
| {
|
|
19
|
-
readonly kind: "explicit_zone";
|
|
20
|
-
readonly dropZoneId: string;
|
|
21
|
-
}
|
|
22
|
-
| { readonly kind: "screen_point" };
|
|
18
|
+
export type SurfaceDropSelector = DropSelector;
|
|
23
19
|
|
|
24
20
|
export interface SurfaceTransferDragOptions {
|
|
25
21
|
readonly state: SurfaceTransferState;
|
|
@@ -126,7 +122,9 @@ export function surfaceTransferDrag(
|
|
|
126
122
|
|
|
127
123
|
return {
|
|
128
124
|
update(nextOptions) {
|
|
129
|
-
|
|
125
|
+
if (nextOptions.state !== options.state) {
|
|
126
|
+
cancel();
|
|
127
|
+
}
|
|
130
128
|
options = nextOptions;
|
|
131
129
|
},
|
|
132
130
|
destroy() {
|
|
@@ -144,13 +142,13 @@ export function surfaceTransferDrag(
|
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
function handleDragOver(event: DragEvent): void {
|
|
147
|
-
|
|
145
|
+
// The drag store exposes types during dragover and payload data on drop.
|
|
146
|
+
const dataTransfer = event.dataTransfer;
|
|
147
|
+
if (!dataTransfer?.types.includes(LONGHORN_TRANSFER_MIME_TYPE)) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
event.preventDefault();
|
|
151
|
-
|
|
152
|
-
event.dataTransfer.dropEffect = "move";
|
|
153
|
-
}
|
|
151
|
+
dataTransfer.dropEffect = "move";
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
export function surfaceTransferDrop(
|
|
@@ -171,11 +169,14 @@ export function surfaceTransferDrop(
|
|
|
171
169
|
protocol_version: TRANSFER_PROTOCOL_VERSION,
|
|
172
170
|
request_id: options.nextRequestId(),
|
|
173
171
|
session_id: payload.session_id,
|
|
174
|
-
selector:
|
|
172
|
+
selector: resolveDropSelector(options.selector, () => ({
|
|
173
|
+
x: event.screenX,
|
|
174
|
+
y: event.screenY,
|
|
175
|
+
})),
|
|
175
176
|
};
|
|
176
177
|
} catch (error) {
|
|
177
178
|
reportError(options.reportError, error);
|
|
178
|
-
|
|
179
|
+
notify(options.onTerminal, undefined, options.reportError);
|
|
179
180
|
return;
|
|
180
181
|
}
|
|
181
182
|
void options.state
|
|
@@ -187,7 +188,7 @@ export function surfaceTransferDrop(
|
|
|
187
188
|
reportError(options.reportError, error);
|
|
188
189
|
})
|
|
189
190
|
.finally(() => {
|
|
190
|
-
|
|
191
|
+
notify(options.onTerminal, undefined, options.reportError);
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
194
|
|
|
@@ -226,51 +227,4 @@ function readPayload(dataTransfer: DataTransfer | null | undefined) {
|
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
function resolveSelector(selector: SurfaceDropSelector, event: DragEvent): TransferCommitSelector {
|
|
230
|
-
if (selector.kind === "explicit_zone") {
|
|
231
|
-
return {
|
|
232
|
-
kind: "explicit_zone",
|
|
233
|
-
drop_zone_id: selector.dropZoneId,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
if (!Number.isSafeInteger(event.screenX) || !Number.isSafeInteger(event.screenY)) {
|
|
237
|
-
throw new RangeError("drop screen point must use integer screen DIPs");
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
kind: "screen_point",
|
|
241
|
-
point: { x: event.screenX, y: event.screenY },
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function reportError(reporter: (error: unknown) => void, error: unknown): void {
|
|
246
|
-
try {
|
|
247
|
-
reporter(error);
|
|
248
|
-
} catch {
|
|
249
|
-
// Reporting failure must not escape an event callback.
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function notify<T>(
|
|
254
|
-
listener: ((value: T) => void) | undefined,
|
|
255
|
-
value: T,
|
|
256
|
-
reporter: (error: unknown) => void,
|
|
257
|
-
): void {
|
|
258
|
-
try {
|
|
259
|
-
listener?.(value);
|
|
260
|
-
} catch (error) {
|
|
261
|
-
reportError(reporter, error);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function notifyTerminal(
|
|
266
|
-
listener: (() => void) | undefined,
|
|
267
|
-
reporter: (error: unknown) => void,
|
|
268
|
-
): void {
|
|
269
|
-
try {
|
|
270
|
-
listener?.();
|
|
271
|
-
} catch (error) {
|
|
272
|
-
reportError(reporter, error);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
230
|
function noop(): void {}
|