@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.
- package/LICENSE +21 -0
- package/README.md +37 -0
- package/package.json +171 -0
- package/src/bindings/index.ts +4 -0
- package/src/bindings/layout.svelte.ts +143 -0
- package/src/bindings/lifecycle.svelte.ts +246 -0
- package/src/bindings/optimistic.svelte.ts +96 -0
- package/src/bindings/scheduler.ts +13 -0
- package/src/bindings/surface-transfer-actions.ts +281 -0
- package/src/bindings/surface-transfer.svelte.ts +230 -0
- package/src/bindings/surfaces.svelte.ts +179 -0
- package/src/bindings/transfer-actions.ts +240 -0
- package/src/bindings/transfer-model.ts +138 -0
- package/src/bindings/transfer.svelte.ts +388 -0
- package/src/bindings/window-chrome.ts +63 -0
- package/src/bindings/window-drag.ts +161 -0
- package/src/commands/poodle/CommandPaletteBinding.svelte +51 -0
- package/src/commands/poodle/KeybindingSettings.svelte +138 -0
- package/src/commands/poodle/projectors.ts +37 -0
- package/src/commands/poodle.ts +9 -0
- package/src/commands/svelte/lifecycle.ts +13 -0
- package/src/commands/svelte/session.svelte.ts +212 -0
- package/src/commands/svelte.ts +2 -0
- package/src/config/poodle/BackupSettingsPage.svelte +295 -0
- package/src/config/poodle/RestoreSettingsPage.svelte +535 -0
- package/src/config/poodle/StorageSettingsPage.svelte +361 -0
- package/src/config/poodle/restore-model.ts +63 -0
- package/src/config/poodle/types.ts +11 -0
- package/src/config/poodle.ts +8 -0
- package/src/history/svelte/lifecycle.ts +13 -0
- package/src/history/svelte/session.svelte.ts +97 -0
- package/src/history/svelte.ts +2 -0
- package/src/history-tree/svelte/lifecycle.ts +11 -0
- package/src/history-tree/svelte/session.svelte.ts +27 -0
- package/src/history-tree/svelte.ts +3 -0
- package/src/licence/poodle/LicenceActivation.svelte +62 -0
- package/src/licence/poodle/LicenceSeats.svelte +57 -0
- package/src/licence/poodle/LicenceStatus.svelte +34 -0
- package/src/licence/poodle/LicenceSurface.svelte.ts +43 -0
- package/src/licence/poodle.ts +3 -0
- package/src/native-content/index.ts +4 -0
- package/src/native-content/lifecycle.ts +13 -0
- package/src/native-content/session.svelte.ts +526 -0
- package/src/native-content/viewport.ts +27 -0
- package/src/native-content/visibility.ts +19 -0
- package/src/notifications/poodle/NotificationPanel.svelte +66 -0
- package/src/notifications/poodle/NotificationToastHost.svelte +40 -0
- package/src/notifications/poodle/NotificationToastStack.svelte +22 -0
- package/src/notifications/poodle/projectors.ts +30 -0
- package/src/notifications/poodle.ts +4 -0
- package/src/notifications/svelte/lifecycle.ts +11 -0
- package/src/notifications/svelte/session.svelte.ts +57 -0
- package/src/notifications/svelte.ts +2 -0
- package/src/operation/poodle/OperationPanel.svelte +200 -0
- package/src/operation/poodle/projectors.ts +78 -0
- package/src/operation/poodle.ts +2 -0
- package/src/operation/svelte/lifecycle.ts +13 -0
- package/src/operation/svelte/session.svelte.ts +80 -0
- package/src/operation/svelte.ts +2 -0
- package/src/poodle/LayoutDockRegion.svelte +148 -0
- package/src/poodle/LayoutSplitView.svelte +120 -0
- package/src/poodle/LayoutTabs.svelte +91 -0
- package/src/poodle/binding.ts +401 -0
- package/src/poodle/document.ts +117 -0
- package/src/poodle/index.ts +8 -0
- package/src/poodle/projectors.ts +125 -0
- package/src/poodle/transfer.ts +188 -0
- package/src/poodle/types.ts +89 -0
- package/src/settings/poodle/SettingsShell.svelte +382 -0
- package/src/settings/poodle.ts +2 -0
- package/src/settings/svelte/context.ts +61 -0
- package/src/settings/svelte/document.svelte.ts +202 -0
- package/src/settings/svelte/errors.ts +84 -0
- package/src/settings/svelte/lifecycle.ts +18 -0
- package/src/settings/svelte/page.svelte.ts +266 -0
- package/src/settings/svelte/runtime.svelte.ts +187 -0
- package/src/settings/svelte/scope.svelte.ts +123 -0
- package/src/settings/svelte/session.svelte.ts +288 -0
- package/src/settings/svelte/types.ts +90 -0
- package/src/settings/svelte.ts +6 -0
- package/src/svelte.d.ts +6 -0
- package/src/update/poodle/UpdateCentre.svelte +64 -0
- package/src/update/poodle/UpdateSettings.svelte +64 -0
- package/src/update/poodle/UpdateStatus.svelte +51 -0
- package/src/update/poodle/UpdateSurface.svelte.ts +88 -0
- package/src/update/poodle.ts +3 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TransferClient,
|
|
3
|
+
type DragSessionId,
|
|
4
|
+
type PanelSessionStartRequest,
|
|
5
|
+
type PanelTransferCommand,
|
|
6
|
+
type PanelTransferResponse,
|
|
7
|
+
type TransferCancelRequest,
|
|
8
|
+
type TransferCancelResponse,
|
|
9
|
+
type TransferClientSnapshot,
|
|
10
|
+
type TransferLeaseRequest,
|
|
11
|
+
type TransferLeaseResponse,
|
|
12
|
+
type TransferSessionResponse,
|
|
13
|
+
} from "@inflatable-cookie/longhorn/transfer";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
ReactiveClientState,
|
|
17
|
+
UnsupportedCapabilityError,
|
|
18
|
+
type ClientStatus,
|
|
19
|
+
} from "./index.ts";
|
|
20
|
+
import {
|
|
21
|
+
systemTimerScheduler,
|
|
22
|
+
} from "./scheduler.ts";
|
|
23
|
+
import {
|
|
24
|
+
InvalidLeaseReleaseRequestError,
|
|
25
|
+
LeaseReleaseRejectedError,
|
|
26
|
+
LeaseReleaseUnavailableError,
|
|
27
|
+
TransferStateNotStartedError,
|
|
28
|
+
type TransferCancellationState,
|
|
29
|
+
type TransferCompletionState,
|
|
30
|
+
type TransferLeaseState,
|
|
31
|
+
type TransferPreparationState,
|
|
32
|
+
type TransferStateOptions,
|
|
33
|
+
} from "./transfer-model.ts";
|
|
34
|
+
|
|
35
|
+
export * from "./transfer-model.ts";
|
|
36
|
+
export * from "./transfer-actions.ts";
|
|
37
|
+
export type { TimerScheduler } from "./scheduler.ts";
|
|
38
|
+
|
|
39
|
+
export class TransferState {
|
|
40
|
+
readonly #client: TransferClient | undefined;
|
|
41
|
+
readonly #options: TransferStateOptions;
|
|
42
|
+
readonly #lifecycle: ReactiveClientState<TransferClientSnapshot>;
|
|
43
|
+
#preparation = $state.raw<TransferPreparationState>({ status: "idle" });
|
|
44
|
+
#lease = $state.raw<TransferLeaseState>({ status: "idle" });
|
|
45
|
+
#completion = $state.raw<TransferCompletionState>({ status: "idle" });
|
|
46
|
+
#cancellation = $state.raw<TransferCancellationState>({ status: "idle" });
|
|
47
|
+
#activeSessionId: DragSessionId | undefined;
|
|
48
|
+
#preparationGeneration = 0;
|
|
49
|
+
#preparationTimer: unknown;
|
|
50
|
+
#preparationTasks = new Set<Promise<unknown>>();
|
|
51
|
+
#stopTask: Promise<void> | undefined;
|
|
52
|
+
#stopped = true;
|
|
53
|
+
|
|
54
|
+
constructor(options: TransferStateOptions) {
|
|
55
|
+
this.#options = options;
|
|
56
|
+
const client = options.client;
|
|
57
|
+
this.#client = client;
|
|
58
|
+
this.#lifecycle = new ReactiveClientState({
|
|
59
|
+
capability:
|
|
60
|
+
client === undefined
|
|
61
|
+
? {
|
|
62
|
+
kind: "unsupported",
|
|
63
|
+
reason:
|
|
64
|
+
options.unsupportedReason ??
|
|
65
|
+
"transfer capability is unavailable",
|
|
66
|
+
}
|
|
67
|
+
: {
|
|
68
|
+
kind: "supported",
|
|
69
|
+
connect: (listener, onFailure) =>
|
|
70
|
+
client.connect(listener, onFailure),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get status(): ClientStatus {
|
|
76
|
+
return this.#lifecycle.status;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get snapshot(): TransferClientSnapshot | undefined {
|
|
80
|
+
return this.#lifecycle.snapshot;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get preparation(): TransferPreparationState {
|
|
84
|
+
return this.#preparation;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get lease(): TransferLeaseState {
|
|
88
|
+
return this.#lease;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get completion(): TransferCompletionState {
|
|
92
|
+
return this.#completion;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get cancellation(): TransferCancellationState {
|
|
96
|
+
return this.#cancellation;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async start(): Promise<void> {
|
|
100
|
+
this.#stopped = false;
|
|
101
|
+
try {
|
|
102
|
+
await this.#lifecycle.start();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
this.#stopped = true;
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async reconnect(): Promise<void> {
|
|
110
|
+
this.#stopped = false;
|
|
111
|
+
try {
|
|
112
|
+
await this.#lifecycle.reconnect();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
this.#stopped = true;
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async preparePanel(
|
|
120
|
+
request: PanelSessionStartRequest,
|
|
121
|
+
): Promise<TransferSessionResponse> {
|
|
122
|
+
this.#assertRunning();
|
|
123
|
+
const client = this.#requireClient();
|
|
124
|
+
await this.#supersedePreparation();
|
|
125
|
+
|
|
126
|
+
const generation = ++this.#preparationGeneration;
|
|
127
|
+
this.#preparation = { status: "preparing", request };
|
|
128
|
+
this.#schedulePreparationTimeout(generation, request.request_id);
|
|
129
|
+
|
|
130
|
+
const task = client.startPanel(request).then(async (response) => {
|
|
131
|
+
if (
|
|
132
|
+
generation !== this.#preparationGeneration ||
|
|
133
|
+
this.#stopped
|
|
134
|
+
) {
|
|
135
|
+
if (response.status === "started") {
|
|
136
|
+
await this.#cancelSession(response.session.payload.session_id);
|
|
137
|
+
}
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.#clearPreparationTimer();
|
|
142
|
+
this.#preparation =
|
|
143
|
+
response.status === "started"
|
|
144
|
+
? { status: "prepared", response }
|
|
145
|
+
: { status: "aborted", response };
|
|
146
|
+
this.#activeSessionId =
|
|
147
|
+
response.status === "started"
|
|
148
|
+
? response.session.payload.session_id
|
|
149
|
+
: undefined;
|
|
150
|
+
return response;
|
|
151
|
+
}).catch((error) => {
|
|
152
|
+
if (generation === this.#preparationGeneration && !this.#stopped) {
|
|
153
|
+
this.#clearPreparationTimer();
|
|
154
|
+
this.#preparation = { status: "failed", error };
|
|
155
|
+
this.#lifecycle.fail(error);
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
});
|
|
159
|
+
this.#trackPreparation(task);
|
|
160
|
+
return task;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async publishLease(
|
|
164
|
+
request: TransferLeaseRequest,
|
|
165
|
+
): Promise<TransferLeaseResponse> {
|
|
166
|
+
this.#assertRunning();
|
|
167
|
+
const client = this.#requireClient();
|
|
168
|
+
this.#lease = { status: "publishing", request };
|
|
169
|
+
try {
|
|
170
|
+
const response = await client.publishLease(request);
|
|
171
|
+
this.#lease =
|
|
172
|
+
response.status === "published"
|
|
173
|
+
? { status: "published", response }
|
|
174
|
+
: { status: "aborted", response };
|
|
175
|
+
return response;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
this.#lease = { status: "failed", error };
|
|
178
|
+
this.#lifecycle.fail(error);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async commitPanel(
|
|
184
|
+
request: PanelTransferCommand,
|
|
185
|
+
): Promise<PanelTransferResponse> {
|
|
186
|
+
this.#assertRunning();
|
|
187
|
+
const client = this.#requireClient();
|
|
188
|
+
this.#completion = { status: "committing", request };
|
|
189
|
+
try {
|
|
190
|
+
const response = await client.commitPanel(request);
|
|
191
|
+
this.#completion =
|
|
192
|
+
response.status === "committed"
|
|
193
|
+
? { status: "committed", response }
|
|
194
|
+
: { status: "aborted", response };
|
|
195
|
+
if (
|
|
196
|
+
response.status === "committed" ||
|
|
197
|
+
response.abort.session_consumed
|
|
198
|
+
) {
|
|
199
|
+
this.#activeSessionId = undefined;
|
|
200
|
+
}
|
|
201
|
+
return response;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
this.#completion = { status: "failed", error };
|
|
204
|
+
this.#lifecycle.fail(error);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async cancel(
|
|
210
|
+
request: TransferCancelRequest,
|
|
211
|
+
): Promise<TransferCancelResponse> {
|
|
212
|
+
this.#assertRunning();
|
|
213
|
+
return this.#cancelRequest(request);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
cancelPreparation(): Promise<void> {
|
|
217
|
+
return this.#supersedePreparation();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
releaseLease(): Promise<void> {
|
|
221
|
+
return this.#releaseLease();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
stop(): Promise<void> {
|
|
225
|
+
if (this.#stopTask !== undefined) {
|
|
226
|
+
return this.#stopTask;
|
|
227
|
+
}
|
|
228
|
+
if (this.#stopped && this.#lifecycle.status.kind === "idle") {
|
|
229
|
+
return Promise.resolve();
|
|
230
|
+
}
|
|
231
|
+
this.#stopTask = this.#performStop().finally(() => {
|
|
232
|
+
this.#stopTask = undefined;
|
|
233
|
+
});
|
|
234
|
+
return this.#stopTask;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async #performStop(): Promise<void> {
|
|
238
|
+
this.#stopped = true;
|
|
239
|
+
++this.#preparationGeneration;
|
|
240
|
+
this.#clearPreparationTimer();
|
|
241
|
+
|
|
242
|
+
const sessionId = this.#activeSessionId;
|
|
243
|
+
this.#activeSessionId = undefined;
|
|
244
|
+
if (sessionId !== undefined) {
|
|
245
|
+
await this.#cancelSession(sessionId);
|
|
246
|
+
}
|
|
247
|
+
await Promise.allSettled([...this.#preparationTasks]);
|
|
248
|
+
await this.#releaseLease();
|
|
249
|
+
await this.#lifecycle.stop();
|
|
250
|
+
|
|
251
|
+
this.#preparation = { status: "idle" };
|
|
252
|
+
this.#lease = { status: "idle" };
|
|
253
|
+
this.#completion = { status: "idle" };
|
|
254
|
+
this.#cancellation = { status: "idle" };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async destroy(): Promise<void> {
|
|
258
|
+
await this.stop();
|
|
259
|
+
await this.#lifecycle.destroy();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async #supersedePreparation(): Promise<void> {
|
|
263
|
+
++this.#preparationGeneration;
|
|
264
|
+
this.#clearPreparationTimer();
|
|
265
|
+
const sessionId = this.#activeSessionId;
|
|
266
|
+
this.#activeSessionId = undefined;
|
|
267
|
+
if (sessionId !== undefined) {
|
|
268
|
+
await this.#cancelSession(sessionId);
|
|
269
|
+
}
|
|
270
|
+
this.#preparation = { status: "idle" };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
#schedulePreparationTimeout(
|
|
274
|
+
generation: number,
|
|
275
|
+
requestId: string,
|
|
276
|
+
): void {
|
|
277
|
+
const timeoutMs = this.#options.preparationTimeoutMs;
|
|
278
|
+
if (timeoutMs === undefined) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
282
|
+
throw new RangeError("preparation timeout must be finite and non-negative");
|
|
283
|
+
}
|
|
284
|
+
const scheduler = this.#options.scheduler ?? systemTimerScheduler;
|
|
285
|
+
this.#preparationTimer = scheduler.set(timeoutMs, () => {
|
|
286
|
+
if (generation !== this.#preparationGeneration || this.#stopped) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
++this.#preparationGeneration;
|
|
290
|
+
this.#preparationTimer = undefined;
|
|
291
|
+
this.#preparation = { status: "timed_out", requestId };
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
#clearPreparationTimer(): void {
|
|
296
|
+
if (this.#preparationTimer === undefined) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const scheduler = this.#options.scheduler ?? systemTimerScheduler;
|
|
300
|
+
scheduler.clear(this.#preparationTimer);
|
|
301
|
+
this.#preparationTimer = undefined;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
#trackPreparation(task: Promise<unknown>): void {
|
|
305
|
+
this.#preparationTasks.add(task);
|
|
306
|
+
void task.finally(() => {
|
|
307
|
+
this.#preparationTasks.delete(task);
|
|
308
|
+
}).catch(() => undefined);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#cancelSession(sessionId: DragSessionId): Promise<TransferCancelResponse> {
|
|
312
|
+
return this.#cancelRequest(
|
|
313
|
+
this.#options.makeCancellationRequest(sessionId),
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async #cancelRequest(
|
|
318
|
+
request: TransferCancelRequest,
|
|
319
|
+
): Promise<TransferCancelResponse> {
|
|
320
|
+
const client = this.#requireClient();
|
|
321
|
+
this.#cancellation = { status: "cancelling", request };
|
|
322
|
+
try {
|
|
323
|
+
const response = await client.cancel(request);
|
|
324
|
+
this.#cancellation =
|
|
325
|
+
response.status === "cancelled"
|
|
326
|
+
? { status: "cancelled", response }
|
|
327
|
+
: { status: "aborted", response };
|
|
328
|
+
if (
|
|
329
|
+
response.status === "cancelled" ||
|
|
330
|
+
response.abort.session_consumed
|
|
331
|
+
) {
|
|
332
|
+
this.#activeSessionId = undefined;
|
|
333
|
+
}
|
|
334
|
+
return response;
|
|
335
|
+
} catch (error) {
|
|
336
|
+
this.#cancellation = { status: "failed", error };
|
|
337
|
+
this.#lifecycle.fail(error);
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async #releaseLease(): Promise<void> {
|
|
343
|
+
if (this.#lease.status !== "published") {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const makeRequest = this.#options.makeLeaseReleaseRequest;
|
|
347
|
+
const snapshot = this.#lifecycle.snapshot;
|
|
348
|
+
if (makeRequest === undefined || snapshot === undefined) {
|
|
349
|
+
throw new LeaseReleaseUnavailableError();
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const receipt = this.#lease.response.lease;
|
|
353
|
+
if (receipt.zone_count === 0) {
|
|
354
|
+
this.#lease = { status: "idle" };
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const request = makeRequest(snapshot, receipt);
|
|
358
|
+
if (
|
|
359
|
+
request.zones.length !== 0 ||
|
|
360
|
+
request.generation <= receipt.generation
|
|
361
|
+
) {
|
|
362
|
+
throw new InvalidLeaseReleaseRequestError();
|
|
363
|
+
}
|
|
364
|
+
const response = await this.#requireClient().publishLease(request);
|
|
365
|
+
if (response.status !== "published") {
|
|
366
|
+
this.#lease = { status: "aborted", response };
|
|
367
|
+
throw new LeaseReleaseRejectedError();
|
|
368
|
+
}
|
|
369
|
+
this.#lease = { status: "idle" };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
#requireClient(): TransferClient {
|
|
373
|
+
if (this.#client !== undefined) {
|
|
374
|
+
return this.#client;
|
|
375
|
+
}
|
|
376
|
+
const reason =
|
|
377
|
+
this.#lifecycle.status.kind === "unsupported"
|
|
378
|
+
? this.#lifecycle.status.reason
|
|
379
|
+
: "transfer capability is unavailable";
|
|
380
|
+
throw new UnsupportedCapabilityError(reason);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
#assertRunning(): void {
|
|
384
|
+
if (this.#stopped || this.#lifecycle.status.kind !== "ready") {
|
|
385
|
+
throw new TransferStateNotStartedError();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Where macOS puts the traffic lights under `titleBarStyle: "Overlay"`.
|
|
2
|
+
//
|
|
3
|
+
// With the overlay style the window keeps its native frame -- rounded corners,
|
|
4
|
+
// shadow, real traffic lights -- and the application draws the bar behind them.
|
|
5
|
+
// The lights then have to be placed against a header only the application knows
|
|
6
|
+
// the height of, and every consumer arrived at the same convention by hand:
|
|
7
|
+
// hard left at x 18, vertically centred on the header.
|
|
8
|
+
//
|
|
9
|
+
// Observed before this was written down, across five applications:
|
|
10
|
+
//
|
|
11
|
+
// header 35.2px -> y 18 header 48px -> y 25
|
|
12
|
+
// header 48px -> y 25 header 62px -> y 31
|
|
13
|
+
// header 72px -> y 37
|
|
14
|
+
//
|
|
15
|
+
// Tauri's `trafficLightPosition.y` is the centre of the button group rather
|
|
16
|
+
// than its top edge, which is why these are half the header rather than
|
|
17
|
+
// half-minus-the-button. The one comment that recorded any of this lives in
|
|
18
|
+
// figmatic's TitleBar.svelte: "keep it at half this height (62px -> y: 31)".
|
|
19
|
+
//
|
|
20
|
+
// This is set when the window is created -- `tauri.conf.json`, or
|
|
21
|
+
// `WebviewWindowBuilder` -- and cannot be changed afterwards. Tauri 2.10.3 has
|
|
22
|
+
// `set_traffic_light_position` on the `tauri-runtime` dispatch trait but does
|
|
23
|
+
// not surface it on `Window` or `WebviewWindow`, and the JavaScript API only
|
|
24
|
+
// accepts `trafficLightPosition` in `WindowOptions`. So nothing can move these
|
|
25
|
+
// in response to a header that resizes at runtime.
|
|
26
|
+
|
|
27
|
+
/** Hard left, the same in every consumer. */
|
|
28
|
+
export const TRAFFIC_LIGHT_INSET_X = 18;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The optical correction. Geometric centring sits a pixel high against the
|
|
32
|
+
* window's top border, so the group is nudged down by one. This is a judgement
|
|
33
|
+
* about how it looks, not a measurement, which is why it is named rather than
|
|
34
|
+
* folded into the arithmetic.
|
|
35
|
+
*/
|
|
36
|
+
export const TRAFFIC_LIGHT_OPTICAL_OFFSET = 1;
|
|
37
|
+
|
|
38
|
+
export interface TrafficLightPosition {
|
|
39
|
+
readonly x: number;
|
|
40
|
+
readonly y: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns the `trafficLightPosition` for a titlebar of the given height.
|
|
45
|
+
*
|
|
46
|
+
* `headerHeight` is in logical pixels — the CSS height of the bar the lights
|
|
47
|
+
* sit in, so a `2.2rem` header is `35.2`, not `2.2`.
|
|
48
|
+
*
|
|
49
|
+
* Applies only where the titlebar spans the window's left edge. A layout whose
|
|
50
|
+
* bar starts after a rail leaves the lights over the rail instead, and should
|
|
51
|
+
* pass the height of whatever they actually sit against.
|
|
52
|
+
*/
|
|
53
|
+
export function trafficLightPosition(headerHeight: number): TrafficLightPosition {
|
|
54
|
+
if (!Number.isFinite(headerHeight) || headerHeight <= 0) {
|
|
55
|
+
throw new RangeError(
|
|
56
|
+
`titlebar height must be a positive number of logical pixels, got ${headerHeight}`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
x: TRAFFIC_LIGHT_INSET_X,
|
|
61
|
+
y: Math.round(headerHeight / 2) + TRAFFIC_LIGHT_OPTICAL_OFFSET,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// The whole titlebar gesture set: drag to move, double click to zoom.
|
|
2
|
+
//
|
|
3
|
+
// This deliberately replaces Tauri's `data-tauri-drag-region`, and the two must
|
|
4
|
+
// not both be applied to one element. Tauri's injected handler reads the
|
|
5
|
+
// attribute off the event target only, so it never checks modifiers and never
|
|
6
|
+
// looks at ancestors; leaving the attribute in place alongside this action
|
|
7
|
+
// means Tauri answers the gesture first, `start_dragging` is invoked twice, and
|
|
8
|
+
// the modifier and interactive-descendant exclusions below are all defeated.
|
|
9
|
+
//
|
|
10
|
+
// What this adds over the attribute is the exclusions: a header drags as a
|
|
11
|
+
// whole except where the operator meant to click. Tauri's version needs the
|
|
12
|
+
// attribute placed on each draggable element, which is why consumers grew
|
|
13
|
+
// dedicated `aria-hidden` spacer divs to drag by.
|
|
14
|
+
//
|
|
15
|
+
// What it owes the attribute is macOS fidelity, and the zoom below is ported
|
|
16
|
+
// from Tauri's `drag.js` rather than reinvented. See tauri-apps/tauri#8306:
|
|
17
|
+
// on macOS the zoom lands on pointer up and is cancelled if the pointer moved,
|
|
18
|
+
// so an accidental double click can be taken back. Elsewhere it lands on the
|
|
19
|
+
// second press.
|
|
20
|
+
|
|
21
|
+
const INTERACTIVE_SELECTOR = [
|
|
22
|
+
"button",
|
|
23
|
+
"a",
|
|
24
|
+
"input",
|
|
25
|
+
"textarea",
|
|
26
|
+
"select",
|
|
27
|
+
"[role='button']",
|
|
28
|
+
"[data-no-window-drag]",
|
|
29
|
+
].join(",");
|
|
30
|
+
|
|
31
|
+
/** Matches the platform vocabulary the command domain already generates. */
|
|
32
|
+
export type WindowDragPlatform = "macOs" | "windows" | "linux";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Zoom is configured as a unit so the platform cannot be forgotten.
|
|
36
|
+
*
|
|
37
|
+
* A bare `toggleMaximize` would need a platform default, and either default is
|
|
38
|
+
* wrong somewhere: assume macOS and Windows zooms on an unmovable gesture,
|
|
39
|
+
* assume otherwise and macOS loses the cancel its operators expect.
|
|
40
|
+
*/
|
|
41
|
+
export interface WindowZoomOptions {
|
|
42
|
+
readonly toggleMaximize: () => void | Promise<void>;
|
|
43
|
+
readonly platform: WindowDragPlatform;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface WindowDragOptions {
|
|
47
|
+
readonly startDragging: () => void | Promise<void>;
|
|
48
|
+
readonly reportError: (error: unknown) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Omit to leave a double click inert, which is what a drag handle that is not
|
|
51
|
+
* a titlebar wants.
|
|
52
|
+
*
|
|
53
|
+
* macOS lets the operator remap this gesture to minimise or to nothing at
|
|
54
|
+
* all, and no Tauri API reports that preference, so this cannot honour it.
|
|
55
|
+
* Zoom is the default and the setting most operators never change; a host
|
|
56
|
+
* that knows better passes its own function.
|
|
57
|
+
*/
|
|
58
|
+
readonly zoom?: WindowZoomOptions;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface WindowDragAction {
|
|
62
|
+
update(options: WindowDragOptions): void;
|
|
63
|
+
destroy(): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function windowDrag(
|
|
67
|
+
node: HTMLElement,
|
|
68
|
+
initialOptions: WindowDragOptions,
|
|
69
|
+
): WindowDragAction {
|
|
70
|
+
let options = initialOptions;
|
|
71
|
+
// Where the deferred macOS zoom was pressed. Null whenever none is pending.
|
|
72
|
+
let pendingZoomAt: { x: number; y: number } | null = null;
|
|
73
|
+
|
|
74
|
+
// One eligibility test for every gesture: primary button, no modifiers, and
|
|
75
|
+
// not on something the operator meant to click.
|
|
76
|
+
function isChromeGesture(event: MouseEvent): boolean {
|
|
77
|
+
return (
|
|
78
|
+
event.button === 0 &&
|
|
79
|
+
!event.altKey &&
|
|
80
|
+
!event.ctrlKey &&
|
|
81
|
+
!event.metaKey &&
|
|
82
|
+
!event.shiftKey &&
|
|
83
|
+
event.target instanceof Element &&
|
|
84
|
+
!event.target.closest(INTERACTIVE_SELECTOR)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function invoke(action: () => void | Promise<void>): void {
|
|
89
|
+
try {
|
|
90
|
+
void Promise.resolve(action()).catch(report);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
report(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function report(error: unknown): void {
|
|
97
|
+
try {
|
|
98
|
+
options.reportError(error);
|
|
99
|
+
} catch {
|
|
100
|
+
// Reporting failure must not become an unhandled drag failure.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleMouseDown(event: MouseEvent): void {
|
|
105
|
+
pendingZoomAt = null;
|
|
106
|
+
if (!isChromeGesture(event)) return;
|
|
107
|
+
|
|
108
|
+
// `detail` counts clicks in the sequence, so the second press of a double
|
|
109
|
+
// click is a zoom rather than the start of another drag.
|
|
110
|
+
const isSecondPress = event.detail === 2;
|
|
111
|
+
const { zoom } = options;
|
|
112
|
+
|
|
113
|
+
if (isSecondPress) {
|
|
114
|
+
if (!zoom) return;
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
if (zoom.platform === "macOs") {
|
|
117
|
+
pendingZoomAt = { x: event.clientX, y: event.clientY };
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
invoke(zoom.toggleMaximize);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
invoke(options.startDragging);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function handleMouseUp(event: MouseEvent): void {
|
|
129
|
+
const at = pendingZoomAt;
|
|
130
|
+
pendingZoomAt = null;
|
|
131
|
+
const { zoom } = options;
|
|
132
|
+
if (
|
|
133
|
+
!at ||
|
|
134
|
+
!zoom ||
|
|
135
|
+
zoom.platform !== "macOs" ||
|
|
136
|
+
event.button !== 0 ||
|
|
137
|
+
event.detail !== 2 ||
|
|
138
|
+
// Moving between press and release cancels it, which is how macOS lets
|
|
139
|
+
// an accidental double click be taken back.
|
|
140
|
+
event.clientX !== at.x ||
|
|
141
|
+
event.clientY !== at.y
|
|
142
|
+
) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
invoke(zoom.toggleMaximize);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Both are registered unconditionally and `zoom` is read at dispatch, so
|
|
149
|
+
// `update()` can add or remove it without rebinding.
|
|
150
|
+
node.addEventListener("mousedown", handleMouseDown);
|
|
151
|
+
node.addEventListener("mouseup", handleMouseUp);
|
|
152
|
+
return {
|
|
153
|
+
update(nextOptions) {
|
|
154
|
+
options = nextOptions;
|
|
155
|
+
},
|
|
156
|
+
destroy() {
|
|
157
|
+
node.removeEventListener("mousedown", handleMouseDown);
|
|
158
|
+
node.removeEventListener("mouseup", handleMouseUp);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { CommandPalette } from "@inflatable-cookie/poodle-svelte";
|
|
3
|
+
|
|
4
|
+
import type { CommandSession } from "../svelte/session.svelte.ts";
|
|
5
|
+
import {
|
|
6
|
+
toPoodleCommandItems,
|
|
7
|
+
toPoodleDiscoveryState,
|
|
8
|
+
} from "./projectors.ts";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
session: CommandSession;
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string | null;
|
|
14
|
+
invocationHint?: string | null;
|
|
15
|
+
categoryLabel?: (categoryPath: readonly string[]) => string | null;
|
|
16
|
+
onOpenChange?: (open: boolean) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
session,
|
|
21
|
+
title = "Command palette",
|
|
22
|
+
description = null,
|
|
23
|
+
invocationHint = null,
|
|
24
|
+
categoryLabel = undefined,
|
|
25
|
+
onOpenChange = undefined,
|
|
26
|
+
}: Props = $props();
|
|
27
|
+
|
|
28
|
+
let records = $derived(session.paletteRecords);
|
|
29
|
+
let items = $derived(toPoodleCommandItems(records, categoryLabel));
|
|
30
|
+
let state = $derived(
|
|
31
|
+
toPoodleDiscoveryState(session.status, session.query, items.length),
|
|
32
|
+
);
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<CommandPalette
|
|
36
|
+
open={session.open}
|
|
37
|
+
query={session.query}
|
|
38
|
+
{items}
|
|
39
|
+
{state}
|
|
40
|
+
{title}
|
|
41
|
+
{description}
|
|
42
|
+
{invocationHint}
|
|
43
|
+
onOpenChange={(open) => {
|
|
44
|
+
session.setOpen(open);
|
|
45
|
+
onOpenChange?.(open);
|
|
46
|
+
}}
|
|
47
|
+
onQueryChange={(query) => void session.setQuery(query)}
|
|
48
|
+
onCommandSelect={(commandId) => {
|
|
49
|
+
void session.select(commandId);
|
|
50
|
+
}}
|
|
51
|
+
/>
|