@inflatable-cookie/longhorn-poodle-svelte 0.7.0 → 0.7.1
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/README.md +3 -2
- package/dist/bindings/drop-target.d.ts +13 -0
- package/dist/bindings/drop-target.js +26 -0
- package/dist/bindings/element-geometry.d.ts +2 -0
- package/dist/bindings/element-geometry.js +10 -0
- package/dist/bindings/freeze-projection.d.ts +1 -0
- package/dist/bindings/freeze-projection.js +11 -0
- package/dist/bindings/index.d.ts +4 -0
- package/dist/bindings/index.js +4 -0
- package/dist/bindings/layout.svelte.d.ts +30 -0
- package/dist/bindings/layout.svelte.js +98 -0
- package/dist/bindings/lifecycle.svelte.d.ts +59 -0
- package/dist/bindings/lifecycle.svelte.js +154 -0
- package/dist/bindings/mount.d.ts +2 -0
- package/dist/bindings/mount.js +11 -0
- package/dist/bindings/optimistic.svelte.d.ts +20 -0
- package/dist/bindings/optimistic.svelte.js +67 -0
- package/dist/bindings/sample-controller.svelte.d.ts +4 -0
- package/dist/bindings/sample-controller.svelte.js +12 -0
- package/dist/bindings/scheduler.d.ts +5 -0
- package/dist/bindings/scheduler.js +9 -0
- package/dist/bindings/session-projection.svelte.d.ts +21 -0
- package/dist/bindings/session-projection.svelte.js +80 -0
- package/dist/bindings/start-stop.d.ts +6 -0
- package/dist/bindings/start-stop.js +61 -0
- package/dist/bindings/surface-transfer-actions.d.ts +27 -0
- package/dist/bindings/surface-transfer-actions.js +172 -0
- package/dist/bindings/surface-transfer.svelte.d.ts +47 -0
- package/dist/bindings/surface-transfer.svelte.js +164 -0
- package/dist/bindings/surfaces.svelte.d.ts +33 -0
- package/dist/bindings/surfaces.svelte.js +130 -0
- package/dist/bindings/teardown.d.ts +1 -0
- package/dist/bindings/teardown.js +16 -0
- package/dist/bindings/transfer-actions.d.ts +34 -0
- package/dist/bindings/transfer-actions.js +195 -0
- package/dist/bindings/transfer-model.d.ts +101 -0
- package/dist/bindings/transfer-model.js +24 -0
- package/dist/bindings/transfer.svelte.d.ts +26 -0
- package/dist/bindings/transfer.svelte.js +340 -0
- package/dist/bindings/window-chrome.d.ts +24 -0
- package/{src/bindings/window-chrome.ts → dist/bindings/window-chrome.js} +8 -18
- package/dist/bindings/window-drag.d.ts +32 -0
- package/dist/bindings/window-drag.js +121 -0
- package/{src → dist}/commands/poodle/CommandPaletteBinding.svelte +2 -2
- package/dist/commands/poodle/CommandPaletteBinding.svelte.d.ts +12 -0
- package/{src → dist}/commands/poodle/KeybindingSettings.svelte +1 -1
- package/dist/commands/poodle/KeybindingSettings.svelte.d.ts +22 -0
- package/dist/commands/poodle/projectors.d.ts +5 -0
- package/dist/commands/poodle/projectors.js +23 -0
- package/dist/commands/poodle.d.ts +5 -0
- package/dist/commands/poodle.js +4 -0
- package/dist/commands/svelte/lifecycle.d.ts +2 -0
- package/dist/commands/svelte/lifecycle.js +4 -0
- package/dist/commands/svelte/session.svelte.d.ts +48 -0
- package/dist/commands/svelte/session.svelte.js +142 -0
- package/dist/commands/svelte.d.ts +2 -0
- package/dist/commands/svelte.js +2 -0
- package/{src → dist}/config/poodle/BackupSettingsPage.svelte +3 -3
- package/dist/config/poodle/BackupSettingsPage.svelte.d.ts +4 -0
- package/dist/config/poodle/ConfigSnapshotState.svelte.d.ts +8 -0
- package/{src → dist}/config/poodle/RestoreSettingsPage.svelte +5 -5
- package/dist/config/poodle/RestoreSettingsPage.svelte.d.ts +4 -0
- package/{src → dist}/config/poodle/StorageSettingsPage.svelte +2 -2
- package/dist/config/poodle/StorageSettingsPage.svelte.d.ts +4 -0
- package/dist/config/poodle/format.d.ts +6 -0
- package/dist/config/poodle/format.js +15 -0
- package/dist/config/poodle/page-state.svelte.d.ts +18 -0
- package/dist/config/poodle/page-state.svelte.js +67 -0
- package/dist/config/poodle/restore-model.d.ts +28 -0
- package/dist/config/poodle/restore-model.js +97 -0
- package/dist/config/poodle/types.d.ts +7 -0
- package/dist/config/poodle/types.js +1 -0
- package/dist/config/poodle.d.ts +7 -0
- package/{src/config/poodle.ts → dist/config/poodle.js} +0 -2
- package/dist/failures.d.ts +8 -0
- package/dist/failures.js +13 -0
- package/dist/history/svelte/lifecycle.d.ts +2 -0
- package/dist/history/svelte/lifecycle.js +4 -0
- package/dist/history/svelte/session.svelte.d.ts +40 -0
- package/dist/history/svelte/session.svelte.js +100 -0
- package/dist/history/svelte.d.ts +2 -0
- package/dist/history/svelte.js +2 -0
- package/dist/history-tree/svelte/lifecycle.d.ts +2 -0
- package/dist/history-tree/svelte/lifecycle.js +4 -0
- package/dist/history-tree/svelte/session.svelte.d.ts +46 -0
- package/dist/history-tree/svelte/session.svelte.js +104 -0
- package/dist/history-tree/svelte.d.ts +3 -0
- package/dist/history-tree/svelte.js +2 -0
- package/{src → dist}/licence/poodle/LicenceActivation.svelte +1 -1
- package/dist/licence/poodle/LicenceActivation.svelte.d.ts +18 -0
- package/{src → dist}/licence/poodle/LicenceSeats.svelte +1 -1
- package/dist/licence/poodle/LicenceSeats.svelte.d.ts +20 -0
- package/{src → dist}/licence/poodle/LicenceStatus.svelte +1 -1
- package/dist/licence/poodle/LicenceStatus.svelte.d.ts +15 -0
- package/dist/licence/poodle/LicenceSurface.svelte.d.ts +14 -0
- package/dist/licence/poodle/LicenceSurface.svelte.js +39 -0
- package/dist/licence/poodle.js +3 -0
- package/dist/native-content/index.d.ts +4 -0
- package/dist/native-content/index.js +4 -0
- package/dist/native-content/lifecycle.d.ts +2 -0
- package/dist/native-content/lifecycle.js +4 -0
- package/dist/native-content/session.svelte.d.ts +62 -0
- package/dist/native-content/session.svelte.js +396 -0
- package/dist/native-content/viewport.d.ts +7 -0
- package/dist/native-content/viewport.js +18 -0
- package/dist/native-content/visibility.d.ts +7 -0
- package/dist/native-content/visibility.js +7 -0
- package/{src → dist}/notifications/poodle/NotificationPanel.svelte +3 -3
- package/dist/notifications/poodle/NotificationPanel.svelte.d.ts +12 -0
- package/{src → dist}/notifications/poodle/NotificationToastHost.svelte +2 -2
- package/dist/notifications/poodle/NotificationToastHost.svelte.d.ts +11 -0
- package/{src → dist}/notifications/poodle/NotificationToastStack.svelte +2 -2
- package/dist/notifications/poodle/NotificationToastStack.svelte.d.ts +7 -0
- package/dist/notifications/poodle/projectors.d.ts +16 -0
- package/dist/notifications/poodle/projectors.js +20 -0
- package/dist/notifications/poodle/toasts.d.ts +11 -0
- package/dist/notifications/poodle/toasts.js +28 -0
- package/{src/notifications/poodle.ts → dist/notifications/poodle.d.ts} +1 -1
- package/dist/notifications/poodle.js +4 -0
- package/dist/notifications/svelte/lifecycle.d.ts +2 -0
- package/dist/notifications/svelte/lifecycle.js +4 -0
- package/dist/notifications/svelte/session.svelte.d.ts +50 -0
- package/dist/notifications/svelte/session.svelte.js +97 -0
- package/dist/notifications/svelte.d.ts +2 -0
- package/dist/notifications/svelte.js +2 -0
- package/{src → dist}/operation/poodle/OperationPanel.svelte +3 -3
- package/dist/operation/poodle/OperationPanel.svelte.d.ts +15 -0
- package/dist/operation/poodle/projectors.d.ts +17 -0
- package/dist/operation/poodle/projectors.js +45 -0
- package/{src/operation/poodle.ts → dist/operation/poodle.d.ts} +1 -1
- package/dist/operation/poodle.js +2 -0
- package/dist/operation/svelte/lifecycle.d.ts +2 -0
- package/dist/operation/svelte/lifecycle.js +4 -0
- package/dist/operation/svelte/session.svelte.d.ts +39 -0
- package/dist/operation/svelte/session.svelte.js +83 -0
- package/dist/operation/svelte.d.ts +2 -0
- package/dist/operation/svelte.js +2 -0
- package/{src → dist}/poodle/LayoutDockRegion.svelte +2 -2
- package/dist/poodle/LayoutDockRegion.svelte.d.ts +34 -0
- package/{src → dist}/poodle/LayoutSplitView.svelte +1 -1
- package/dist/poodle/LayoutSplitView.svelte.d.ts +28 -0
- package/{src → dist}/poodle/LayoutTabs.svelte +2 -2
- package/dist/poodle/LayoutTabs.svelte.d.ts +26 -0
- package/dist/poodle/binding.d.ts +23 -0
- package/dist/poodle/binding.js +234 -0
- package/dist/poodle/document.d.ts +12 -0
- package/dist/poodle/document.js +61 -0
- package/{src/poodle/index.ts → dist/poodle/index.d.ts} +2 -2
- package/dist/poodle/index.js +5 -0
- package/dist/poodle/projectors.d.ts +9 -0
- package/dist/poodle/projectors.js +58 -0
- package/dist/poodle/transfer.d.ts +29 -0
- package/dist/poodle/transfer.js +87 -0
- package/dist/poodle/types.d.ts +50 -0
- package/dist/poodle/types.js +18 -0
- package/{src → dist}/settings/poodle/SettingsShell.svelte +3 -3
- package/dist/settings/poodle/SettingsShell.svelte.d.ts +33 -0
- package/{src/settings/poodle.ts → dist/settings/poodle.d.ts} +1 -1
- package/dist/settings/poodle.js +2 -0
- package/dist/settings/svelte/context.d.ts +10 -0
- package/dist/settings/svelte/context.js +25 -0
- package/dist/settings/svelte/document.svelte.d.ts +30 -0
- package/dist/settings/svelte/document.svelte.js +175 -0
- package/dist/settings/svelte/errors.d.ts +35 -0
- package/dist/settings/svelte/errors.js +68 -0
- package/dist/settings/svelte/lifecycle.d.ts +3 -0
- package/dist/settings/svelte/lifecycle.js +12 -0
- package/dist/settings/svelte/page.svelte.d.ts +26 -0
- package/dist/settings/svelte/page.svelte.js +203 -0
- package/dist/settings/svelte/runtime.svelte.d.ts +19 -0
- package/dist/settings/svelte/runtime.svelte.js +220 -0
- package/dist/settings/svelte/scope.svelte.d.ts +22 -0
- package/dist/settings/svelte/scope.svelte.js +86 -0
- package/dist/settings/svelte/session.svelte.d.ts +57 -0
- package/dist/settings/svelte/session.svelte.js +215 -0
- package/dist/settings/svelte/types.d.ts +81 -0
- package/dist/settings/svelte/types.js +1 -0
- package/dist/settings/svelte.d.ts +6 -0
- package/dist/settings/svelte.js +6 -0
- package/{src → dist}/update/poodle/UpdateCentre.svelte +1 -1
- package/dist/update/poodle/UpdateCentre.svelte.d.ts +17 -0
- package/{src → dist}/update/poodle/UpdateSettings.svelte +1 -1
- package/dist/update/poodle/UpdateSettings.svelte.d.ts +16 -0
- package/{src → dist}/update/poodle/UpdateStatus.svelte +1 -1
- package/dist/update/poodle/UpdateStatus.svelte.d.ts +16 -0
- package/dist/update/poodle/UpdateSurface.svelte.d.ts +77 -0
- package/dist/update/poodle/UpdateSurface.svelte.js +119 -0
- package/dist/update/poodle.js +3 -0
- package/package.json +95 -92
- package/src/bindings/drop-target.ts +0 -39
- package/src/bindings/element-geometry.ts +0 -10
- package/src/bindings/freeze-projection.ts +0 -11
- package/src/bindings/index.ts +0 -4
- package/src/bindings/layout.svelte.ts +0 -140
- package/src/bindings/lifecycle.svelte.ts +0 -218
- package/src/bindings/mount.ts +0 -18
- package/src/bindings/optimistic.svelte.ts +0 -86
- package/src/bindings/sample-controller.svelte.ts +0 -19
- package/src/bindings/scheduler.ts +0 -15
- package/src/bindings/session-projection.svelte.ts +0 -98
- package/src/bindings/start-stop.ts +0 -64
- package/src/bindings/surface-transfer-actions.ts +0 -230
- package/src/bindings/surface-transfer.svelte.ts +0 -224
- package/src/bindings/surfaces.svelte.ts +0 -182
- package/src/bindings/teardown.ts +0 -16
- package/src/bindings/transfer-actions.ts +0 -246
- package/src/bindings/transfer-model.ts +0 -112
- package/src/bindings/transfer.svelte.ts +0 -416
- package/src/bindings/window-drag.ts +0 -169
- package/src/commands/poodle/projectors.ts +0 -36
- package/src/commands/poodle.ts +0 -9
- package/src/commands/svelte/lifecycle.ts +0 -6
- package/src/commands/svelte/session.svelte.ts +0 -202
- package/src/commands/svelte.ts +0 -2
- package/src/config/poodle/format.ts +0 -15
- package/src/config/poodle/page-state.svelte.ts +0 -81
- package/src/config/poodle/restore-model.ts +0 -130
- package/src/config/poodle/types.ts +0 -11
- package/src/failures.ts +0 -14
- package/src/history/svelte/lifecycle.ts +0 -6
- package/src/history/svelte/session.svelte.ts +0 -134
- package/src/history/svelte.ts +0 -2
- package/src/history-tree/svelte/lifecycle.ts +0 -6
- package/src/history-tree/svelte/session.svelte.ts +0 -129
- package/src/history-tree/svelte.ts +0 -6
- package/src/licence/poodle/LicenceSurface.svelte.ts +0 -42
- package/src/native-content/index.ts +0 -4
- package/src/native-content/lifecycle.ts +0 -6
- package/src/native-content/session.svelte.ts +0 -491
- package/src/native-content/viewport.ts +0 -29
- package/src/native-content/visibility.ts +0 -19
- package/src/notifications/poodle/projectors.ts +0 -32
- package/src/notifications/poodle/toasts.ts +0 -34
- package/src/notifications/svelte/lifecycle.ts +0 -6
- package/src/notifications/svelte/session.svelte.ts +0 -123
- package/src/notifications/svelte.ts +0 -2
- package/src/operation/poodle/projectors.ts +0 -68
- package/src/operation/svelte/lifecycle.ts +0 -6
- package/src/operation/svelte/session.svelte.ts +0 -113
- package/src/operation/svelte.ts +0 -2
- package/src/poodle/binding.ts +0 -360
- package/src/poodle/document.ts +0 -96
- package/src/poodle/projectors.ts +0 -99
- package/src/poodle/transfer.ts +0 -137
- package/src/poodle/types.ts +0 -82
- package/src/settings/svelte/context.ts +0 -54
- package/src/settings/svelte/document.svelte.ts +0 -234
- package/src/settings/svelte/errors.ts +0 -81
- package/src/settings/svelte/lifecycle.ts +0 -20
- package/src/settings/svelte/page.svelte.ts +0 -260
- package/src/settings/svelte/runtime.svelte.ts +0 -267
- package/src/settings/svelte/scope.svelte.ts +0 -114
- package/src/settings/svelte/session.svelte.ts +0 -294
- package/src/settings/svelte/types.ts +0 -84
- package/src/settings/svelte.ts +0 -6
- package/src/update/poodle/UpdateSurface.svelte.ts +0 -128
- /package/{src → dist}/config/poodle/ConfigSnapshotState.svelte +0 -0
- /package/{src/licence/poodle.ts → dist/licence/poodle.d.ts} +0 -0
- /package/{src/update/poodle.ts → dist/update/poodle.d.ts} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { StartStop } from "./start-stop.js";
|
|
2
|
+
export class SessionProjection {
|
|
3
|
+
#controller;
|
|
4
|
+
#unobserve;
|
|
5
|
+
#observers = new Set();
|
|
6
|
+
#lifetime = new StartStop();
|
|
7
|
+
#current;
|
|
8
|
+
#retryFailure = $state.raw();
|
|
9
|
+
constructor(controller, project) {
|
|
10
|
+
this.#controller = controller;
|
|
11
|
+
this.#current = $state.raw(project());
|
|
12
|
+
this.#unobserve = controller.observe(() => {
|
|
13
|
+
this.#current = project();
|
|
14
|
+
this.#notify();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
get current() {
|
|
18
|
+
return this.#current;
|
|
19
|
+
}
|
|
20
|
+
get retryFailure() {
|
|
21
|
+
return this.#retryFailure;
|
|
22
|
+
}
|
|
23
|
+
observe(observer) {
|
|
24
|
+
this.#observers.add(observer);
|
|
25
|
+
return () => this.#observers.delete(observer);
|
|
26
|
+
}
|
|
27
|
+
#setRetryFailure(failure) {
|
|
28
|
+
if (this.#retryFailure !== failure) {
|
|
29
|
+
this.#retryFailure = failure;
|
|
30
|
+
this.#notify();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
#notify() {
|
|
34
|
+
for (const observer of this.#observers) {
|
|
35
|
+
observer();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
start() {
|
|
39
|
+
return this.#lifetime.start(() => {
|
|
40
|
+
this.#setRetryFailure(undefined);
|
|
41
|
+
return this.#controller.start();
|
|
42
|
+
}, true);
|
|
43
|
+
}
|
|
44
|
+
stop() {
|
|
45
|
+
this.#setRetryFailure(undefined);
|
|
46
|
+
return this.#lifetime.stop(() => this.#controller.stop());
|
|
47
|
+
}
|
|
48
|
+
async retry(previousError) {
|
|
49
|
+
this.#setRetryFailure(undefined);
|
|
50
|
+
const teardown = this.#lifetime.stop(async () => {
|
|
51
|
+
try {
|
|
52
|
+
await this.#controller.stop();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// A checked subscription may repeat its startup failure at teardown.
|
|
56
|
+
if (!Object.is(error, previousError)) {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const start = this.#lifetime.start(() => {
|
|
62
|
+
this.#setRetryFailure(undefined);
|
|
63
|
+
return this.#controller.restart();
|
|
64
|
+
}, true);
|
|
65
|
+
const generation = this.#lifetime.generation;
|
|
66
|
+
try {
|
|
67
|
+
await Promise.all([teardown, start]);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (generation === this.#lifetime.generation) {
|
|
71
|
+
this.#setRetryFailure({ kind: "failed", error });
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async dispose() {
|
|
77
|
+
this.#unobserve();
|
|
78
|
+
await this.stop();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// A stop invalidates both active callbacks and a start waiting for teardown.
|
|
2
|
+
export class StartStop {
|
|
3
|
+
#generation = 0;
|
|
4
|
+
#startTask;
|
|
5
|
+
#stopTask;
|
|
6
|
+
get generation() {
|
|
7
|
+
return this.#generation;
|
|
8
|
+
}
|
|
9
|
+
start(begin, retryOnFailure = false) {
|
|
10
|
+
if (this.#startTask !== undefined) {
|
|
11
|
+
return this.#startTask;
|
|
12
|
+
}
|
|
13
|
+
const generation = ++this.#generation;
|
|
14
|
+
const afterStop = this.#stopTask;
|
|
15
|
+
const { task, invoke } = reserve(async () => {
|
|
16
|
+
try {
|
|
17
|
+
if (afterStop !== undefined) {
|
|
18
|
+
await afterStop;
|
|
19
|
+
}
|
|
20
|
+
if (generation === this.#generation) {
|
|
21
|
+
await begin(generation);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (retryOnFailure && generation === this.#generation) {
|
|
26
|
+
this.#startTask = undefined;
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.#startTask = task;
|
|
32
|
+
invoke();
|
|
33
|
+
return task;
|
|
34
|
+
}
|
|
35
|
+
stop(end) {
|
|
36
|
+
this.#startTask = undefined;
|
|
37
|
+
++this.#generation;
|
|
38
|
+
if (this.#stopTask === undefined) {
|
|
39
|
+
const { task, invoke } = reserve(async () => {
|
|
40
|
+
try {
|
|
41
|
+
await end();
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
this.#stopTask = undefined;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.#stopTask = task;
|
|
48
|
+
invoke();
|
|
49
|
+
return task;
|
|
50
|
+
}
|
|
51
|
+
return this.#stopTask;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// StartStop needs to publish the promise before invoking synchronous hooks.
|
|
55
|
+
function reserve(run) {
|
|
56
|
+
let invoke;
|
|
57
|
+
const task = new Promise((resolve, reject) => {
|
|
58
|
+
invoke = () => void run().then(resolve, reject);
|
|
59
|
+
});
|
|
60
|
+
return { task, invoke };
|
|
61
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SurfaceSessionResponse, SurfaceSessionStartRequest, SurfaceTransferResponse } from "@inflatable-cookie/longhorn/surface-transfer";
|
|
2
|
+
import type { DropSelector } from "./drop-target.js";
|
|
3
|
+
import type { SurfaceTransferState } from "./surface-transfer.svelte.js";
|
|
4
|
+
export type SurfaceDropSelector = DropSelector;
|
|
5
|
+
export interface SurfaceTransferDragOptions {
|
|
6
|
+
readonly state: SurfaceTransferState;
|
|
7
|
+
readonly makeStartRequest: () => SurfaceSessionStartRequest;
|
|
8
|
+
readonly reportError: (error: unknown) => void;
|
|
9
|
+
readonly onPreparation?: (response: SurfaceSessionResponse) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface SurfaceTransferDropOptions {
|
|
12
|
+
readonly state: SurfaceTransferState;
|
|
13
|
+
readonly selector: SurfaceDropSelector;
|
|
14
|
+
readonly nextRequestId: () => string;
|
|
15
|
+
readonly reportError: (error: unknown) => void;
|
|
16
|
+
readonly onResponse?: (response: SurfaceTransferResponse) => void;
|
|
17
|
+
readonly onTerminal?: () => void;
|
|
18
|
+
}
|
|
19
|
+
export interface SurfaceTransferAction<T> {
|
|
20
|
+
update(options: T): void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function surfaceTransferDrag(node: HTMLElement, initialOptions: SurfaceTransferDragOptions): SurfaceTransferAction<SurfaceTransferDragOptions>;
|
|
24
|
+
export declare function surfaceTransferDrop(node: HTMLElement, initialOptions: SurfaceTransferDropOptions): SurfaceTransferAction<SurfaceTransferDropOptions>;
|
|
25
|
+
export declare class StaleSurfaceTransferPreparationError extends Error {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { LONGHORN_TRANSFER_MIME_TYPE, TRANSFER_PROTOCOL_VERSION, parseTransferPayload, serializeTransferPayload, } from "@inflatable-cookie/longhorn/transfer";
|
|
2
|
+
import { notify, reportError, resolveDropSelector } from "./drop-target.js";
|
|
3
|
+
export function surfaceTransferDrag(node, initialOptions) {
|
|
4
|
+
let options = initialOptions;
|
|
5
|
+
let preparationGeneration = 0;
|
|
6
|
+
let armedRequest;
|
|
7
|
+
let removePointerListeners = noop;
|
|
8
|
+
const priorDraggable = node.getAttribute("draggable");
|
|
9
|
+
node.draggable = true;
|
|
10
|
+
function cancel() {
|
|
11
|
+
++preparationGeneration;
|
|
12
|
+
armedRequest = undefined;
|
|
13
|
+
removePointerListeners();
|
|
14
|
+
removePointerListeners = noop;
|
|
15
|
+
void options.state.cancelPreparation().catch((error) => {
|
|
16
|
+
reportError(options.reportError, error);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function handlePointerDown(event) {
|
|
20
|
+
if (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
cancel();
|
|
24
|
+
const generation = ++preparationGeneration;
|
|
25
|
+
const request = options.makeStartRequest();
|
|
26
|
+
armedRequest = request;
|
|
27
|
+
const ownerWindow = node.ownerDocument.defaultView;
|
|
28
|
+
if (ownerWindow) {
|
|
29
|
+
const released = () => cancel();
|
|
30
|
+
ownerWindow.addEventListener("pointerup", released, true);
|
|
31
|
+
ownerWindow.addEventListener("pointercancel", released, true);
|
|
32
|
+
removePointerListeners = () => {
|
|
33
|
+
ownerWindow.removeEventListener("pointerup", released, true);
|
|
34
|
+
ownerWindow.removeEventListener("pointercancel", released, true);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
void options.state
|
|
38
|
+
.prepare(request)
|
|
39
|
+
.then((response) => {
|
|
40
|
+
notify(options.onPreparation, response, options.reportError);
|
|
41
|
+
if (generation === preparationGeneration && response.status !== "started") {
|
|
42
|
+
armedRequest = undefined;
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.catch((error) => {
|
|
46
|
+
if (generation === preparationGeneration) {
|
|
47
|
+
reportError(options.reportError, error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function handleDragStart(event) {
|
|
52
|
+
const request = armedRequest;
|
|
53
|
+
const preparation = options.state.preparation;
|
|
54
|
+
if (!event.dataTransfer ||
|
|
55
|
+
request === undefined ||
|
|
56
|
+
preparation.status !== "prepared" ||
|
|
57
|
+
preparation.response.status !== "started" ||
|
|
58
|
+
preparation.response.session.request_id !== request.request_id) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
cancel();
|
|
61
|
+
reportError(options.reportError, new StaleSurfaceTransferPreparationError());
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
removePointerListeners();
|
|
65
|
+
removePointerListeners = noop;
|
|
66
|
+
event.dataTransfer.setData(LONGHORN_TRANSFER_MIME_TYPE, serializeTransferPayload(preparation.response.session.payload));
|
|
67
|
+
event.dataTransfer.effectAllowed = "move";
|
|
68
|
+
}
|
|
69
|
+
node.addEventListener("pointerdown", handlePointerDown);
|
|
70
|
+
node.addEventListener("dragstart", handleDragStart);
|
|
71
|
+
node.addEventListener("dragend", cancel);
|
|
72
|
+
return {
|
|
73
|
+
update(nextOptions) {
|
|
74
|
+
if (nextOptions.state !== options.state) {
|
|
75
|
+
cancel();
|
|
76
|
+
}
|
|
77
|
+
options = nextOptions;
|
|
78
|
+
},
|
|
79
|
+
destroy() {
|
|
80
|
+
node.removeEventListener("pointerdown", handlePointerDown);
|
|
81
|
+
node.removeEventListener("dragstart", handleDragStart);
|
|
82
|
+
node.removeEventListener("dragend", cancel);
|
|
83
|
+
cancel();
|
|
84
|
+
if (priorDraggable === null) {
|
|
85
|
+
node.removeAttribute("draggable");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
node.setAttribute("draggable", priorDraggable);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function handleDragOver(event) {
|
|
94
|
+
// The drag store exposes types during dragover and payload data on drop.
|
|
95
|
+
const dataTransfer = event.dataTransfer;
|
|
96
|
+
if (!dataTransfer?.types.includes(LONGHORN_TRANSFER_MIME_TYPE)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
dataTransfer.dropEffect = "move";
|
|
101
|
+
}
|
|
102
|
+
export function surfaceTransferDrop(node, initialOptions) {
|
|
103
|
+
let options = initialOptions;
|
|
104
|
+
function handleDrop(event) {
|
|
105
|
+
const payload = readPayload(event.dataTransfer);
|
|
106
|
+
if (payload === null) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
let request;
|
|
111
|
+
try {
|
|
112
|
+
request = {
|
|
113
|
+
protocol_version: TRANSFER_PROTOCOL_VERSION,
|
|
114
|
+
request_id: options.nextRequestId(),
|
|
115
|
+
session_id: payload.session_id,
|
|
116
|
+
selector: resolveDropSelector(options.selector, () => ({
|
|
117
|
+
x: event.screenX,
|
|
118
|
+
y: event.screenY,
|
|
119
|
+
})),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
reportError(options.reportError, error);
|
|
124
|
+
notify(options.onTerminal, undefined, options.reportError);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
void options.state
|
|
128
|
+
.commit(request)
|
|
129
|
+
.then((response) => {
|
|
130
|
+
notify(options.onResponse, response, options.reportError);
|
|
131
|
+
})
|
|
132
|
+
.catch((error) => {
|
|
133
|
+
reportError(options.reportError, error);
|
|
134
|
+
})
|
|
135
|
+
.finally(() => {
|
|
136
|
+
notify(options.onTerminal, undefined, options.reportError);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
node.addEventListener("dragover", handleDragOver);
|
|
140
|
+
node.addEventListener("drop", handleDrop);
|
|
141
|
+
return {
|
|
142
|
+
update(nextOptions) {
|
|
143
|
+
options = nextOptions;
|
|
144
|
+
},
|
|
145
|
+
destroy() {
|
|
146
|
+
node.removeEventListener("dragover", handleDragOver);
|
|
147
|
+
node.removeEventListener("drop", handleDrop);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export class StaleSurfaceTransferPreparationError extends Error {
|
|
152
|
+
constructor() {
|
|
153
|
+
super("Surface dragstart has no matching prepared transfer session");
|
|
154
|
+
this.name = "StaleSurfaceTransferPreparationError";
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function readPayload(dataTransfer) {
|
|
158
|
+
if (dataTransfer === null || dataTransfer === undefined) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const raw = dataTransfer.getData(LONGHORN_TRANSFER_MIME_TYPE);
|
|
162
|
+
if (raw.length === 0) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
return parseTransferPayload(raw);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function noop() { }
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SurfaceTransferClient } from "@inflatable-cookie/longhorn/surface-transfer";
|
|
2
|
+
import type { SurfaceSessionResponse, SurfaceSessionStartRequest, SurfaceTransferCommand, SurfaceTransferResponse } from "@inflatable-cookie/longhorn/surface-transfer";
|
|
3
|
+
import type { DragSessionId } from "@inflatable-cookie/longhorn/transfer";
|
|
4
|
+
import type { ClientStatus } from "./index.js";
|
|
5
|
+
export type SurfaceTransferPreparationState = {
|
|
6
|
+
readonly status: "idle";
|
|
7
|
+
} | {
|
|
8
|
+
readonly status: "preparing";
|
|
9
|
+
readonly request: SurfaceSessionStartRequest;
|
|
10
|
+
} | {
|
|
11
|
+
readonly status: "prepared" | "aborted";
|
|
12
|
+
readonly response: SurfaceSessionResponse;
|
|
13
|
+
} | {
|
|
14
|
+
readonly status: "failed";
|
|
15
|
+
readonly error: unknown;
|
|
16
|
+
};
|
|
17
|
+
export type SurfaceTransferCompletionState = {
|
|
18
|
+
readonly status: "idle";
|
|
19
|
+
} | {
|
|
20
|
+
readonly status: "committing";
|
|
21
|
+
readonly request: SurfaceTransferCommand;
|
|
22
|
+
} | {
|
|
23
|
+
readonly status: "committed" | "aborted";
|
|
24
|
+
readonly response: SurfaceTransferResponse;
|
|
25
|
+
} | {
|
|
26
|
+
readonly status: "failed";
|
|
27
|
+
readonly error: unknown;
|
|
28
|
+
};
|
|
29
|
+
export interface SurfaceTransferStateOptions {
|
|
30
|
+
readonly client?: SurfaceTransferClient;
|
|
31
|
+
readonly unsupportedReason?: string;
|
|
32
|
+
readonly cancelSession: (sessionId: DragSessionId) => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare class SurfaceTransferState {
|
|
35
|
+
#private;
|
|
36
|
+
constructor(options: SurfaceTransferStateOptions);
|
|
37
|
+
get status(): ClientStatus;
|
|
38
|
+
get preparation(): SurfaceTransferPreparationState;
|
|
39
|
+
get completion(): SurfaceTransferCompletionState;
|
|
40
|
+
start(): Promise<void>;
|
|
41
|
+
prepare(request: SurfaceSessionStartRequest): Promise<SurfaceSessionResponse>;
|
|
42
|
+
commit(request: SurfaceTransferCommand): Promise<SurfaceTransferResponse>;
|
|
43
|
+
cancelPreparation(): Promise<void>;
|
|
44
|
+
stop(): Promise<void>;
|
|
45
|
+
destroy(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export * from "./surface-transfer-actions.js";
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { UnsupportedCapabilityError } from "./index.js";
|
|
2
|
+
import { StartStop } from "./start-stop.js";
|
|
3
|
+
import { throwTeardownFailures } from "./teardown.js";
|
|
4
|
+
export class SurfaceTransferState {
|
|
5
|
+
#options;
|
|
6
|
+
#status = $state.raw({ kind: "idle" });
|
|
7
|
+
#preparation = $state.raw({
|
|
8
|
+
status: "idle",
|
|
9
|
+
});
|
|
10
|
+
#completion = $state.raw({
|
|
11
|
+
status: "idle",
|
|
12
|
+
});
|
|
13
|
+
#activeSessionId;
|
|
14
|
+
#generation = 0;
|
|
15
|
+
#tasks = new Set();
|
|
16
|
+
#lifetime = new StartStop();
|
|
17
|
+
#stopped = true;
|
|
18
|
+
#destroyed = false;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.#options = options;
|
|
21
|
+
}
|
|
22
|
+
get status() {
|
|
23
|
+
return this.#status;
|
|
24
|
+
}
|
|
25
|
+
get preparation() {
|
|
26
|
+
return this.#preparation;
|
|
27
|
+
}
|
|
28
|
+
get completion() {
|
|
29
|
+
return this.#completion;
|
|
30
|
+
}
|
|
31
|
+
async start() {
|
|
32
|
+
this.#assertAlive();
|
|
33
|
+
await this.#lifetime.start(async () => {
|
|
34
|
+
this.#stopped = false;
|
|
35
|
+
this.#status =
|
|
36
|
+
this.#options.client === undefined
|
|
37
|
+
? {
|
|
38
|
+
kind: "unsupported",
|
|
39
|
+
reason: this.#options.unsupportedReason ?? "Surface transfer capability is unavailable",
|
|
40
|
+
}
|
|
41
|
+
: { kind: "ready" };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async prepare(request) {
|
|
45
|
+
this.#assertRunning();
|
|
46
|
+
return this.#track(this.#prepare(request));
|
|
47
|
+
}
|
|
48
|
+
async #prepare(request) {
|
|
49
|
+
const client = this.#requireClient();
|
|
50
|
+
const generation = ++this.#generation;
|
|
51
|
+
await this.#cancelActive();
|
|
52
|
+
if (generation === this.#generation) {
|
|
53
|
+
this.#preparation = { status: "preparing", request };
|
|
54
|
+
}
|
|
55
|
+
return client
|
|
56
|
+
.start(request)
|
|
57
|
+
.then(async (response) => {
|
|
58
|
+
if (generation !== this.#generation || this.#stopped) {
|
|
59
|
+
if (response.status === "started") {
|
|
60
|
+
await this.#options.cancelSession(response.session.payload.session_id);
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
64
|
+
this.#preparation = {
|
|
65
|
+
status: response.status === "started" ? "prepared" : "aborted",
|
|
66
|
+
response,
|
|
67
|
+
};
|
|
68
|
+
this.#activeSessionId =
|
|
69
|
+
response.status === "started" ? response.session.payload.session_id : undefined;
|
|
70
|
+
return response;
|
|
71
|
+
})
|
|
72
|
+
.catch((error) => {
|
|
73
|
+
if (generation === this.#generation && !this.#stopped) {
|
|
74
|
+
this.#preparation = { status: "failed", error };
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async commit(request) {
|
|
80
|
+
this.#assertRunning();
|
|
81
|
+
return this.#track(this.#commit(request));
|
|
82
|
+
}
|
|
83
|
+
async #commit(request) {
|
|
84
|
+
const client = this.#requireClient();
|
|
85
|
+
this.#completion = { status: "committing", request };
|
|
86
|
+
try {
|
|
87
|
+
const response = await client.commit(request);
|
|
88
|
+
this.#completion = {
|
|
89
|
+
status: response.status === "committed" ? "committed" : "aborted",
|
|
90
|
+
response,
|
|
91
|
+
};
|
|
92
|
+
if (this.#activeSessionId === request.session_id &&
|
|
93
|
+
(response.status === "committed" || response.abort.session_consumed)) {
|
|
94
|
+
this.#activeSessionId = undefined;
|
|
95
|
+
}
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
this.#completion = { status: "failed", error };
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
cancelPreparation() {
|
|
104
|
+
if (this.#stopped) {
|
|
105
|
+
return Promise.resolve();
|
|
106
|
+
}
|
|
107
|
+
++this.#generation;
|
|
108
|
+
return this.#track(this.#cancelActive());
|
|
109
|
+
}
|
|
110
|
+
stop() {
|
|
111
|
+
return this.#lifetime.stop(async () => {
|
|
112
|
+
this.#stopped = true;
|
|
113
|
+
++this.#generation;
|
|
114
|
+
this.#status = { kind: "idle" };
|
|
115
|
+
const results = await Promise.allSettled([this.#cancelActive(), ...this.#tasks]);
|
|
116
|
+
this.#status = { kind: "idle" };
|
|
117
|
+
this.#preparation = { status: "idle" };
|
|
118
|
+
this.#completion = { status: "idle" };
|
|
119
|
+
throwTeardownFailures(results);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async destroy() {
|
|
123
|
+
this.#destroyed = true;
|
|
124
|
+
await this.stop();
|
|
125
|
+
}
|
|
126
|
+
async #cancelActive() {
|
|
127
|
+
const sessionId = this.#activeSessionId;
|
|
128
|
+
this.#activeSessionId = undefined;
|
|
129
|
+
this.#preparation = { status: "idle" };
|
|
130
|
+
if (sessionId !== undefined) {
|
|
131
|
+
await this.#options.cancelSession(sessionId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
#track(task) {
|
|
135
|
+
this.#tasks.add(task);
|
|
136
|
+
void task
|
|
137
|
+
.finally(() => {
|
|
138
|
+
this.#tasks.delete(task);
|
|
139
|
+
})
|
|
140
|
+
.catch(() => undefined);
|
|
141
|
+
return task;
|
|
142
|
+
}
|
|
143
|
+
#requireClient() {
|
|
144
|
+
if (this.#options.client !== undefined) {
|
|
145
|
+
return this.#options.client;
|
|
146
|
+
}
|
|
147
|
+
const reason = this.#status.kind === "unsupported"
|
|
148
|
+
? this.#status.reason
|
|
149
|
+
: "Surface transfer capability is unavailable";
|
|
150
|
+
throw new UnsupportedCapabilityError(reason);
|
|
151
|
+
}
|
|
152
|
+
#assertAlive() {
|
|
153
|
+
if (this.#destroyed) {
|
|
154
|
+
throw new Error("Surface transfer state has been destroyed");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
#assertRunning() {
|
|
158
|
+
this.#assertAlive();
|
|
159
|
+
if (this.#stopped || this.#status.kind !== "ready") {
|
|
160
|
+
throw new Error("Surface transfer state must be started");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export * from "./surface-transfer-actions.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SurfaceClient } from "@inflatable-cookie/longhorn/surfaces";
|
|
2
|
+
import type { SurfaceMutationRequest, SurfaceMutationResponse, SurfaceSnapshot } from "@inflatable-cookie/longhorn/surfaces";
|
|
3
|
+
import type { ClientStatus, OptimisticProjector } from "./index.js";
|
|
4
|
+
export type SurfaceMutationOperation = {
|
|
5
|
+
readonly requestId: string;
|
|
6
|
+
readonly status: "pending";
|
|
7
|
+
} | {
|
|
8
|
+
readonly requestId: string;
|
|
9
|
+
readonly status: "committed" | "rejected";
|
|
10
|
+
readonly response: SurfaceMutationResponse;
|
|
11
|
+
} | {
|
|
12
|
+
readonly requestId: string;
|
|
13
|
+
readonly status: "failed";
|
|
14
|
+
readonly error: unknown;
|
|
15
|
+
};
|
|
16
|
+
export interface SurfaceStateOptions {
|
|
17
|
+
readonly client?: SurfaceClient;
|
|
18
|
+
readonly unsupportedReason?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SurfaceState {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(options: SurfaceStateOptions);
|
|
23
|
+
get status(): ClientStatus;
|
|
24
|
+
get snapshot(): SurfaceSnapshot | undefined;
|
|
25
|
+
get projectedDocument(): SurfaceSnapshot["document"] | undefined;
|
|
26
|
+
get pendingRequestIds(): ReadonlyArray<string>;
|
|
27
|
+
get operations(): ReadonlyArray<SurfaceMutationOperation>;
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
reconnect(): Promise<void>;
|
|
30
|
+
mutate(request: SurfaceMutationRequest, project: OptimisticProjector<SurfaceSnapshot["document"]>): Promise<SurfaceMutationResponse>;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
destroy(): Promise<void>;
|
|
33
|
+
}
|