@inflatable-cookie/longhorn-poodle-svelte 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/package.json +171 -0
  4. package/src/bindings/index.ts +4 -0
  5. package/src/bindings/layout.svelte.ts +143 -0
  6. package/src/bindings/lifecycle.svelte.ts +246 -0
  7. package/src/bindings/optimistic.svelte.ts +96 -0
  8. package/src/bindings/scheduler.ts +13 -0
  9. package/src/bindings/surface-transfer-actions.ts +281 -0
  10. package/src/bindings/surface-transfer.svelte.ts +230 -0
  11. package/src/bindings/surfaces.svelte.ts +179 -0
  12. package/src/bindings/transfer-actions.ts +240 -0
  13. package/src/bindings/transfer-model.ts +138 -0
  14. package/src/bindings/transfer.svelte.ts +388 -0
  15. package/src/bindings/window-chrome.ts +63 -0
  16. package/src/bindings/window-drag.ts +161 -0
  17. package/src/commands/poodle/CommandPaletteBinding.svelte +51 -0
  18. package/src/commands/poodle/KeybindingSettings.svelte +138 -0
  19. package/src/commands/poodle/projectors.ts +37 -0
  20. package/src/commands/poodle.ts +9 -0
  21. package/src/commands/svelte/lifecycle.ts +13 -0
  22. package/src/commands/svelte/session.svelte.ts +212 -0
  23. package/src/commands/svelte.ts +2 -0
  24. package/src/config/poodle/BackupSettingsPage.svelte +295 -0
  25. package/src/config/poodle/RestoreSettingsPage.svelte +535 -0
  26. package/src/config/poodle/StorageSettingsPage.svelte +361 -0
  27. package/src/config/poodle/restore-model.ts +63 -0
  28. package/src/config/poodle/types.ts +11 -0
  29. package/src/config/poodle.ts +8 -0
  30. package/src/history/svelte/lifecycle.ts +13 -0
  31. package/src/history/svelte/session.svelte.ts +97 -0
  32. package/src/history/svelte.ts +2 -0
  33. package/src/history-tree/svelte/lifecycle.ts +11 -0
  34. package/src/history-tree/svelte/session.svelte.ts +27 -0
  35. package/src/history-tree/svelte.ts +3 -0
  36. package/src/licence/poodle/LicenceActivation.svelte +62 -0
  37. package/src/licence/poodle/LicenceSeats.svelte +57 -0
  38. package/src/licence/poodle/LicenceStatus.svelte +34 -0
  39. package/src/licence/poodle/LicenceSurface.svelte.ts +43 -0
  40. package/src/licence/poodle.ts +3 -0
  41. package/src/native-content/index.ts +4 -0
  42. package/src/native-content/lifecycle.ts +13 -0
  43. package/src/native-content/session.svelte.ts +526 -0
  44. package/src/native-content/viewport.ts +27 -0
  45. package/src/native-content/visibility.ts +19 -0
  46. package/src/notifications/poodle/NotificationPanel.svelte +66 -0
  47. package/src/notifications/poodle/NotificationToastHost.svelte +40 -0
  48. package/src/notifications/poodle/NotificationToastStack.svelte +22 -0
  49. package/src/notifications/poodle/projectors.ts +30 -0
  50. package/src/notifications/poodle.ts +4 -0
  51. package/src/notifications/svelte/lifecycle.ts +11 -0
  52. package/src/notifications/svelte/session.svelte.ts +57 -0
  53. package/src/notifications/svelte.ts +2 -0
  54. package/src/operation/poodle/OperationPanel.svelte +200 -0
  55. package/src/operation/poodle/projectors.ts +78 -0
  56. package/src/operation/poodle.ts +2 -0
  57. package/src/operation/svelte/lifecycle.ts +13 -0
  58. package/src/operation/svelte/session.svelte.ts +80 -0
  59. package/src/operation/svelte.ts +2 -0
  60. package/src/poodle/LayoutDockRegion.svelte +148 -0
  61. package/src/poodle/LayoutSplitView.svelte +120 -0
  62. package/src/poodle/LayoutTabs.svelte +91 -0
  63. package/src/poodle/binding.ts +401 -0
  64. package/src/poodle/document.ts +117 -0
  65. package/src/poodle/index.ts +8 -0
  66. package/src/poodle/projectors.ts +125 -0
  67. package/src/poodle/transfer.ts +188 -0
  68. package/src/poodle/types.ts +89 -0
  69. package/src/settings/poodle/SettingsShell.svelte +382 -0
  70. package/src/settings/poodle.ts +2 -0
  71. package/src/settings/svelte/context.ts +61 -0
  72. package/src/settings/svelte/document.svelte.ts +202 -0
  73. package/src/settings/svelte/errors.ts +84 -0
  74. package/src/settings/svelte/lifecycle.ts +18 -0
  75. package/src/settings/svelte/page.svelte.ts +266 -0
  76. package/src/settings/svelte/runtime.svelte.ts +187 -0
  77. package/src/settings/svelte/scope.svelte.ts +123 -0
  78. package/src/settings/svelte/session.svelte.ts +288 -0
  79. package/src/settings/svelte/types.ts +90 -0
  80. package/src/settings/svelte.ts +6 -0
  81. package/src/svelte.d.ts +6 -0
  82. package/src/update/poodle/UpdateCentre.svelte +64 -0
  83. package/src/update/poodle/UpdateSettings.svelte +64 -0
  84. package/src/update/poodle/UpdateStatus.svelte +51 -0
  85. package/src/update/poodle/UpdateSurface.svelte.ts +88 -0
  86. package/src/update/poodle.ts +3 -0
@@ -0,0 +1,401 @@
1
+ import type {
2
+ LayoutMutationCommand,
3
+ LayoutMutationRequest,
4
+ LayoutSchemaDefinition,
5
+ PanelDefinition,
6
+ PanelInstanceId,
7
+ RegionVisibility,
8
+ RegionDefinition,
9
+ RegionId,
10
+ RegionState,
11
+ SizingSlotId,
12
+ } from "@inflatable-cookie/longhorn/layout";
13
+ import type {
14
+ SurfaceRecord,
15
+ SurfaceId,
16
+ SurfaceDocument,
17
+ } from "@inflatable-cookie/longhorn/surfaces";
18
+ import { projectOrdinaryRegionVisibility } from "@inflatable-cookie/longhorn/layout";
19
+
20
+ import {
21
+ findContainer,
22
+ findPanelInstance,
23
+ findPanelLocation,
24
+ findRegion,
25
+ selectorMatches,
26
+ } from "./document.ts";
27
+ import {
28
+ projectActivate,
29
+ projectClose,
30
+ projectCollapsed,
31
+ projectMove,
32
+ projectReorder,
33
+ projectSizingSlot,
34
+ type LayoutProjector,
35
+ } from "./projectors.ts";
36
+ import {
37
+ MissingSurfaceDocumentError,
38
+ MissingLayoutMemberError,
39
+ MissingPanelPresentationError,
40
+ type PanelPresentationResolver,
41
+ type PanelRenderContext,
42
+ type PoodleLayoutBindingOptions,
43
+ type RegionProjection,
44
+ type SizingSlotProjection,
45
+ } from "./types.ts";
46
+
47
+ export type { PanelPresentation } from "./types.ts";
48
+
49
+ export class PoodleLayoutBinding {
50
+ readonly #options: PoodleLayoutBindingOptions;
51
+ readonly #schemas: ReadonlyMap<string, LayoutSchemaDefinition>;
52
+ readonly #panels: ReadonlyMap<string, PanelDefinition>;
53
+ #mutationTail = Promise.resolve();
54
+
55
+ constructor(options: PoodleLayoutBindingOptions) {
56
+ this.#options = options;
57
+ this.#schemas = uniqueMap(options.definitions.schemas, "layout schema");
58
+ this.#panels = uniqueMap(options.definitions.panels, "panel definition");
59
+ }
60
+
61
+ get document(): SurfaceDocument {
62
+ const document = this.#options.state.projected;
63
+ if (!document) {
64
+ throw new MissingSurfaceDocumentError();
65
+ }
66
+ return document;
67
+ }
68
+
69
+ region(
70
+ containerId: SurfaceId,
71
+ regionId: RegionId,
72
+ resolvePresentation: PanelPresentationResolver,
73
+ ): RegionProjection {
74
+ const document = this.document;
75
+ const container = findContainer(document, containerId);
76
+ const state = findRegion(container, regionId);
77
+ const definition = this.#regionDefinition(container, regionId);
78
+ const panels = new Map<PanelInstanceId, PanelRenderContext>();
79
+ const items = state.panel_instance_ids.map((panelInstanceId) => {
80
+ const instance = findPanelInstance(document, panelInstanceId);
81
+ const panelDefinition = this.#panelDefinition(instance.definition_id);
82
+ const presentation = resolvePresentation(instance);
83
+ if (!presentation) {
84
+ throw new MissingPanelPresentationError(instance.id);
85
+ }
86
+ if (presentation.label.trim().length === 0) {
87
+ throw new TypeError(
88
+ `panel presentation label is empty: ${panelInstanceId}`,
89
+ );
90
+ }
91
+ panels.set(panelInstanceId, {
92
+ instance,
93
+ definition: panelDefinition,
94
+ presentation,
95
+ });
96
+ return {
97
+ value: panelInstanceId,
98
+ label: presentation.label,
99
+ icon: presentation.icon,
100
+ closable: panelDefinition.closeable,
101
+ };
102
+ });
103
+
104
+ let active: PanelRenderContext | null = null;
105
+ if (state.active_panel_instance_id !== null) {
106
+ active = panels.get(state.active_panel_instance_id) ?? null;
107
+ if (!active) {
108
+ throw new MissingLayoutMemberError(
109
+ "active panel projection",
110
+ state.active_panel_instance_id,
111
+ );
112
+ }
113
+ }
114
+
115
+ return {
116
+ container,
117
+ definition,
118
+ state,
119
+ items,
120
+ panels,
121
+ active,
122
+ };
123
+ }
124
+
125
+ regionState(
126
+ containerId: SurfaceId,
127
+ regionId: RegionId,
128
+ ): RegionState {
129
+ return findRegion(findContainer(this.document, containerId), regionId);
130
+ }
131
+
132
+ regionDefinition(
133
+ containerId: SurfaceId,
134
+ regionId: RegionId,
135
+ ): RegionDefinition {
136
+ const container = findContainer(this.document, containerId);
137
+ return this.#regionDefinition(container, regionId);
138
+ }
139
+
140
+ collapsibleRegionState(
141
+ containerId: SurfaceId,
142
+ regionId: RegionId,
143
+ ): RegionState {
144
+ const definition = this.regionDefinition(containerId, regionId);
145
+ const state = this.regionState(containerId, regionId);
146
+ if (!definition.collapsible || state.collapsed === null) {
147
+ throw new TypeError(`region does not support collapse: ${regionId}`);
148
+ }
149
+ return state;
150
+ }
151
+
152
+ sizingSlot(
153
+ containerId: SurfaceId,
154
+ sizingSlotId: SizingSlotId,
155
+ ): SizingSlotProjection {
156
+ const container = findContainer(this.document, containerId);
157
+ const schema = this.#schema(container.schema_id);
158
+ const definition = schema.sizing_slots.find(
159
+ ({ id }) => id === sizingSlotId,
160
+ );
161
+ const state = container.sizing_slots.find(
162
+ ({ sizing_slot_id }) => sizing_slot_id === sizingSlotId,
163
+ );
164
+ if (!definition || !state) {
165
+ throw new MissingLayoutMemberError("sizing slot", sizingSlotId);
166
+ }
167
+ return { definition, ratio: state.ratio };
168
+ }
169
+
170
+ canMove(
171
+ panelInstanceId: PanelInstanceId,
172
+ targetContainerId: SurfaceId,
173
+ targetRegionId: RegionId,
174
+ ): boolean {
175
+ const document = this.document;
176
+ const instance = findPanelInstance(document, panelInstanceId);
177
+ const definition = this.#panelDefinition(instance.definition_id);
178
+ if (!definition.movable) return false;
179
+
180
+ const source = findPanelLocation(document, panelInstanceId);
181
+ if (
182
+ source.container.id === targetContainerId &&
183
+ source.region.region_id === targetRegionId
184
+ ) {
185
+ return false;
186
+ }
187
+
188
+ const target = findContainer(document, targetContainerId);
189
+ const targetRegion = this.#regionDefinition(target, targetRegionId);
190
+ if (
191
+ !definition.allowed_placements.some((selector) =>
192
+ selectorMatches(selector, targetRegion),
193
+ )
194
+ ) {
195
+ return false;
196
+ }
197
+
198
+ const peerCount = document.panel_instances.filter((candidate) => {
199
+ if (
200
+ candidate.id === panelInstanceId ||
201
+ candidate.definition_id !== instance.definition_id
202
+ ) {
203
+ return false;
204
+ }
205
+ return findPanelLocation(document, candidate.id).container.id === target.id;
206
+ }).length;
207
+
208
+ switch (definition.instance_policy.kind) {
209
+ case "one_per_container":
210
+ return peerCount === 0;
211
+ case "bounded":
212
+ return peerCount < definition.instance_policy.maximum_per_surface;
213
+ case "singleton":
214
+ case "multiple":
215
+ return true;
216
+ }
217
+ }
218
+
219
+ regionVisibilities(
220
+ containerId: SurfaceId,
221
+ movingPanelInstanceId?: PanelInstanceId,
222
+ ): readonly RegionVisibility[] {
223
+ const document = this.document;
224
+ const container = findContainer(document, containerId);
225
+ const schema = this.#schema(container.schema_id);
226
+
227
+ return schema.regions.map((definition) => {
228
+ const state = findRegion(container, definition.id);
229
+ const ordinary = projectOrdinaryRegionVisibility(definition, state);
230
+ if (
231
+ ordinary.state === "hidden" &&
232
+ movingPanelInstanceId !== undefined &&
233
+ this.canMove(movingPanelInstanceId, containerId, definition.id)
234
+ ) {
235
+ return {
236
+ region_id: definition.id,
237
+ state: "transiently_revealed",
238
+ };
239
+ }
240
+ return ordinary;
241
+ });
242
+ }
243
+
244
+ activate(panelInstanceId: PanelInstanceId): void {
245
+ this.#submit(
246
+ { kind: "activate_panel", panel_instance_id: panelInstanceId },
247
+ projectActivate(panelInstanceId),
248
+ );
249
+ }
250
+
251
+ close(panelInstanceId: PanelInstanceId): void {
252
+ this.#submit(
253
+ { kind: "close_panel", panel_instance_id: panelInstanceId },
254
+ projectClose(panelInstanceId),
255
+ );
256
+ }
257
+
258
+ reorder(
259
+ containerId: SurfaceId,
260
+ regionId: RegionId,
261
+ panelInstanceIds: readonly PanelInstanceId[],
262
+ ): void {
263
+ this.#submit(
264
+ {
265
+ kind: "reorder_region",
266
+ surface_id: containerId,
267
+ region_id: regionId,
268
+ panel_instance_ids: [...panelInstanceIds],
269
+ },
270
+ projectReorder(containerId, regionId, panelInstanceIds),
271
+ );
272
+ }
273
+
274
+ move(
275
+ panelInstanceId: PanelInstanceId,
276
+ targetContainerId: SurfaceId,
277
+ targetRegionId: RegionId,
278
+ insertionIndex: number,
279
+ ): void {
280
+ this.#submit(
281
+ {
282
+ kind: "move_panel",
283
+ panel_instance_id: panelInstanceId,
284
+ target_surface_id: targetContainerId,
285
+ target_region_id: targetRegionId,
286
+ insertion_index: insertionIndex,
287
+ },
288
+ projectMove(
289
+ panelInstanceId,
290
+ targetContainerId,
291
+ targetRegionId,
292
+ insertionIndex,
293
+ ),
294
+ );
295
+ }
296
+
297
+ setCollapsed(
298
+ containerId: SurfaceId,
299
+ regionId: RegionId,
300
+ collapsed: boolean,
301
+ ): void {
302
+ this.#submit(
303
+ {
304
+ kind: "set_region_collapsed",
305
+ surface_id: containerId,
306
+ region_id: regionId,
307
+ collapsed,
308
+ },
309
+ projectCollapsed(containerId, regionId, collapsed),
310
+ );
311
+ }
312
+
313
+ setSizingSlot(
314
+ containerId: SurfaceId,
315
+ sizingSlotId: SizingSlotId,
316
+ ratio: number,
317
+ ): void {
318
+ this.#submit(
319
+ {
320
+ kind: "set_sizing_slot",
321
+ surface_id: containerId,
322
+ sizing_slot_id: sizingSlotId,
323
+ ratio,
324
+ },
325
+ projectSizingSlot(containerId, sizingSlotId, ratio),
326
+ );
327
+ }
328
+
329
+ #submit(
330
+ command: LayoutMutationCommand,
331
+ project: LayoutProjector,
332
+ ): void {
333
+ this.#mutationTail = this.#mutationTail.then(async () => {
334
+ const request: LayoutMutationRequest = {
335
+ request_id: this.#options.nextRequestId(),
336
+ expected_revision: this.document.revision,
337
+ command,
338
+ };
339
+ const result = await this.#options.state.dispatch(request, project);
340
+ this.#options.onResult?.(result);
341
+ }).catch((error) => {
342
+ try {
343
+ this.#options.onError(error);
344
+ } catch {
345
+ // Error reporting cannot poison later queued mutations.
346
+ }
347
+ });
348
+ }
349
+
350
+ #schema(schemaId: string): LayoutSchemaDefinition {
351
+ const schema = this.#schemas.get(schemaId);
352
+ if (!schema) {
353
+ throw new MissingLayoutMemberError("layout schema", schemaId);
354
+ }
355
+ return schema;
356
+ }
357
+
358
+ #regionDefinition(
359
+ container: SurfaceRecord,
360
+ regionId: RegionId,
361
+ ): RegionDefinition {
362
+ const definition = this.#schema(container.schema_id).regions.find(
363
+ ({ id }) => id === regionId,
364
+ );
365
+ if (!definition) {
366
+ throw new MissingLayoutMemberError("region definition", regionId);
367
+ }
368
+ return definition;
369
+ }
370
+
371
+ #panelDefinition(panelDefinitionId: string): PanelDefinition {
372
+ const definition = this.#panels.get(panelDefinitionId);
373
+ if (!definition) {
374
+ throw new MissingLayoutMemberError(
375
+ "panel definition",
376
+ panelDefinitionId,
377
+ );
378
+ }
379
+ return definition;
380
+ }
381
+ }
382
+
383
+ export function createPoodleLayoutBinding(
384
+ options: PoodleLayoutBindingOptions,
385
+ ): PoodleLayoutBinding {
386
+ return new PoodleLayoutBinding(options);
387
+ }
388
+
389
+ function uniqueMap<T extends { readonly id: string }>(
390
+ values: readonly T[],
391
+ kind: string,
392
+ ): ReadonlyMap<string, T> {
393
+ const result = new Map<string, T>();
394
+ for (const value of values) {
395
+ if (result.has(value.id)) {
396
+ throw new TypeError(`duplicate ${kind}: ${value.id}`);
397
+ }
398
+ result.set(value.id, value);
399
+ }
400
+ return result;
401
+ }
@@ -0,0 +1,117 @@
1
+ import type {
2
+ PanelInstance,
3
+ PanelInstanceId,
4
+ PlacementSelector,
5
+ RegionDefinition,
6
+ RegionId,
7
+ RegionState,
8
+ } from "@inflatable-cookie/longhorn/layout";
9
+ import type {
10
+ SurfaceRecord,
11
+ SurfaceId,
12
+ SurfaceDocument,
13
+ } from "@inflatable-cookie/longhorn/surfaces";
14
+
15
+ import { MissingLayoutMemberError } from "./types.ts";
16
+
17
+ export function findContainer(
18
+ document: SurfaceDocument,
19
+ containerId: SurfaceId,
20
+ ): SurfaceRecord {
21
+ const container = document.surfaces.find(({ id }) => id === containerId);
22
+ if (!container) {
23
+ throw new MissingLayoutMemberError("layout container", containerId);
24
+ }
25
+ return container;
26
+ }
27
+
28
+ export function findRegion(
29
+ container: SurfaceRecord,
30
+ regionId: RegionId,
31
+ ): RegionState {
32
+ const region = container.regions.find(
33
+ ({ region_id }) => region_id === regionId,
34
+ );
35
+ if (!region) {
36
+ throw new MissingLayoutMemberError("region state", regionId);
37
+ }
38
+ return region;
39
+ }
40
+
41
+ export function findPanelInstance(
42
+ document: SurfaceDocument,
43
+ panelInstanceId: PanelInstanceId,
44
+ ): PanelInstance {
45
+ const instance = document.panel_instances.find(
46
+ ({ id }) => id === panelInstanceId,
47
+ );
48
+ if (!instance) {
49
+ throw new MissingLayoutMemberError("panel instance", panelInstanceId);
50
+ }
51
+ return instance;
52
+ }
53
+
54
+ export function findPanelLocation(
55
+ document: SurfaceDocument,
56
+ panelInstanceId: PanelInstanceId,
57
+ ): { container: SurfaceRecord; region: RegionState } {
58
+ for (const container of document.surfaces) {
59
+ for (const region of container.regions) {
60
+ if (region.panel_instance_ids.includes(panelInstanceId)) {
61
+ return { container, region };
62
+ }
63
+ }
64
+ }
65
+ throw new MissingLayoutMemberError("panel placement", panelInstanceId);
66
+ }
67
+
68
+ export function selectorMatches(
69
+ selector: PlacementSelector,
70
+ region: RegionDefinition,
71
+ ): boolean {
72
+ return selector.kind === "region"
73
+ ? selector.id === region.id
74
+ : selector.id === region.family_id;
75
+ }
76
+
77
+ export function updateRegion(
78
+ document: SurfaceDocument,
79
+ containerId: SurfaceId,
80
+ regionId: RegionId,
81
+ update: (region: RegionState) => RegionState,
82
+ ): SurfaceDocument {
83
+ return {
84
+ ...document,
85
+ surfaces: document.surfaces.map((container) =>
86
+ container.id === containerId
87
+ ? {
88
+ ...container,
89
+ regions: container.regions.map((region) =>
90
+ region.region_id === regionId ? update(region) : region,
91
+ ),
92
+ }
93
+ : container,
94
+ ),
95
+ };
96
+ }
97
+
98
+ export function removePanel(
99
+ region: RegionState,
100
+ panelInstanceId: PanelInstanceId,
101
+ ): RegionState {
102
+ const index = region.panel_instance_ids.indexOf(panelInstanceId);
103
+ if (index < 0) return region;
104
+
105
+ const panelInstanceIds = region.panel_instance_ids.filter(
106
+ (id) => id !== panelInstanceId,
107
+ );
108
+ const activePanelInstanceId =
109
+ region.active_panel_instance_id === panelInstanceId
110
+ ? (panelInstanceIds[index] ?? panelInstanceIds.at(-1) ?? null)
111
+ : region.active_panel_instance_id;
112
+ return {
113
+ ...region,
114
+ panel_instance_ids: panelInstanceIds,
115
+ active_panel_instance_id: activePanelInstanceId,
116
+ };
117
+ }
@@ -0,0 +1,8 @@
1
+ export { default as LayoutDockRegion } from "./LayoutDockRegion.svelte";
2
+ export { default as LayoutSplitView } from "./LayoutSplitView.svelte";
3
+ export { default as LayoutTabs } from "./LayoutTabs.svelte";
4
+ export {
5
+ PoodleLayoutBinding,
6
+ createPoodleLayoutBinding,
7
+ } from "./binding.ts";
8
+ export * from "./types.ts";
@@ -0,0 +1,125 @@
1
+ import type {
2
+ PanelInstanceId,
3
+ RegionId,
4
+ SizingSlotId,
5
+ } from "@inflatable-cookie/longhorn/layout";
6
+ import type {
7
+ SurfaceId,
8
+ SurfaceDocument,
9
+ } from "@inflatable-cookie/longhorn/surfaces";
10
+
11
+ import { findPanelLocation, removePanel, updateRegion } from "./document.ts";
12
+
13
+ export type LayoutProjector = (document: SurfaceDocument) => SurfaceDocument;
14
+
15
+ export function projectActivate(
16
+ panelInstanceId: PanelInstanceId,
17
+ ): LayoutProjector {
18
+ return (document) => {
19
+ const location = findPanelLocation(document, panelInstanceId);
20
+ return updateRegion(
21
+ document,
22
+ location.container.id,
23
+ location.region.region_id,
24
+ (region) => ({
25
+ ...region,
26
+ active_panel_instance_id: panelInstanceId,
27
+ }),
28
+ );
29
+ };
30
+ }
31
+
32
+ export function projectClose(
33
+ panelInstanceId: PanelInstanceId,
34
+ ): LayoutProjector {
35
+ return (document) => {
36
+ const location = findPanelLocation(document, panelInstanceId);
37
+ return {
38
+ ...updateRegion(
39
+ document,
40
+ location.container.id,
41
+ location.region.region_id,
42
+ (region) => removePanel(region, panelInstanceId),
43
+ ),
44
+ panel_instances: document.panel_instances.filter(
45
+ ({ id }) => id !== panelInstanceId,
46
+ ),
47
+ };
48
+ };
49
+ }
50
+
51
+ export function projectReorder(
52
+ containerId: SurfaceId,
53
+ regionId: RegionId,
54
+ panelInstanceIds: readonly PanelInstanceId[],
55
+ ): LayoutProjector {
56
+ const order = [...panelInstanceIds];
57
+ return (document) =>
58
+ updateRegion(document, containerId, regionId, (region) => ({
59
+ ...region,
60
+ panel_instance_ids: order,
61
+ }));
62
+ }
63
+
64
+ export function projectMove(
65
+ panelInstanceId: PanelInstanceId,
66
+ targetContainerId: SurfaceId,
67
+ targetRegionId: RegionId,
68
+ insertionIndex: number,
69
+ ): LayoutProjector {
70
+ return (document) => {
71
+ const source = findPanelLocation(document, panelInstanceId);
72
+ const withoutSource = updateRegion(
73
+ document,
74
+ source.container.id,
75
+ source.region.region_id,
76
+ (region) => removePanel(region, panelInstanceId),
77
+ );
78
+ return updateRegion(
79
+ withoutSource,
80
+ targetContainerId,
81
+ targetRegionId,
82
+ (region) => {
83
+ const panelInstanceIds = [...region.panel_instance_ids];
84
+ panelInstanceIds.splice(insertionIndex, 0, panelInstanceId);
85
+ return {
86
+ ...region,
87
+ panel_instance_ids: panelInstanceIds,
88
+ active_panel_instance_id: panelInstanceId,
89
+ };
90
+ },
91
+ );
92
+ };
93
+ }
94
+
95
+ export function projectCollapsed(
96
+ containerId: SurfaceId,
97
+ regionId: RegionId,
98
+ collapsed: boolean,
99
+ ): LayoutProjector {
100
+ return (document) =>
101
+ updateRegion(document, containerId, regionId, (region) => ({
102
+ ...region,
103
+ collapsed,
104
+ }));
105
+ }
106
+
107
+ export function projectSizingSlot(
108
+ containerId: SurfaceId,
109
+ sizingSlotId: SizingSlotId,
110
+ ratio: number,
111
+ ): LayoutProjector {
112
+ return (document) => ({
113
+ ...document,
114
+ surfaces: document.surfaces.map((container) =>
115
+ container.id === containerId
116
+ ? {
117
+ ...container,
118
+ sizing_slots: container.sizing_slots.map((slot) =>
119
+ slot.sizing_slot_id === sizingSlotId ? { ...slot, ratio } : slot,
120
+ ),
121
+ }
122
+ : container,
123
+ ),
124
+ });
125
+ }