@kubohiroya/turbowarp-plus-editor-workbench 0.18.0 → 0.19.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.
@@ -21,6 +21,11 @@ export interface WorkspaceLayoutSession {
21
21
  readonly exact: boolean;
22
22
  /** Whether the project has a saved layout, or a change was written in this session. */
23
23
  readonly saved: boolean;
24
+ /**
25
+ * When the saved layout was last changed, in milliseconds since the epoch. Missing for records written before
26
+ * it was kept, which count as older than any layout saved in a project file.
27
+ */
28
+ readonly savedAt?: number;
24
29
  /** Save the layout. The project's own record is updated, so it never adds a record per change. */
25
30
  write(layout: string, signature: string): Promise<void>;
26
31
  }
@@ -69,6 +74,8 @@ interface LayoutRecord {
69
74
  signature: string;
70
75
  layout: string;
71
76
  lastUsedAt: number;
77
+ /** When the layout changed. Opening a project only updates `lastUsedAt`. */
78
+ savedAt?: number;
72
79
  }
73
80
 
74
81
  const result = <T>(request: IDBRequest<T>) => new Promise<T>((resolve, reject) => {
@@ -194,18 +201,21 @@ export function createWorkspaceLayoutStore({indexedDB: factory = globalThis.inde
194
201
  const found = await find(opened, identity, signature);
195
202
  let id = found?.id;
196
203
  let written = false;
204
+ let savedAt = found?.savedAt;
197
205
  if (id !== undefined) await enqueue(() => touch(opened, id!, now()));
198
206
  const fields = identityFields(identity);
199
207
  return {
200
208
  layout: found?.layout,
201
209
  exact: Boolean(found) && identity.kind !== 'anonymous',
202
210
  get saved() { return id !== undefined || written; },
211
+ get savedAt() { return savedAt; },
203
212
  write(layout, nextSignature) {
204
213
  if (bytes(layout) > maxBytes) return Promise.resolve();
205
214
  written = true;
215
+ const time = savedAt = now();
206
216
  return enqueue(async () => {
207
217
  id = await save(opened, {...fields, ...(id !== undefined && {id}), signature: nextSignature, layout,
208
- lastUsedAt: now()}, limit);
218
+ lastUsedAt: time, savedAt: time}, limit);
209
219
  });
210
220
  }
211
221
  };
@@ -4,8 +4,17 @@ import type {DocumentPanelRequest} from './document-workspace.ts';
4
4
 
5
5
  type Grid = SerializedDockview['grid'];
6
6
  type Node = Grid['root'];
7
+ /** What a sprite tab showed inside its panes. Every field is optional, and a missing one keeps the default. */
8
+ export interface SpritePaneState {
9
+ /** The index of the costume or sound the tab had selected in that list. */
10
+ costume?: number;
11
+ sound?: number;
12
+ /** The code area as the host's tab adapter serialized it, such as its scroll position and zoom. */
13
+ code?: unknown;
14
+ }
15
+
7
16
  export type PanelReference =
8
- | {kind: 'sprite'; name: string; stage: boolean; section: number; number?: number}
17
+ | {kind: 'sprite'; name: string; stage: boolean; section: number; number?: number; pane?: SpritePaneState}
9
18
  | {kind: 'stage'}
10
19
  | ({kind: 'document'} & DocumentPanelRequest['reference']);
11
20
 
@@ -189,8 +198,9 @@ export function readWorkspaceLayout(raw: string, project?: string): WorkspaceLay
189
198
  typeof panel.section === 'number' && Number.isInteger(panel.section) && panel.section >= 0 && panel.section <= 4) {
190
199
  const number = panel.number;
191
200
  if (number !== undefined && (typeof number !== 'number' || !Number.isSafeInteger(number) || number < 2)) return;
201
+ const pane = readPaneState(panel.pane);
192
202
  panels[id] = {kind: 'sprite', name: panel.name, stage: panel.stage, section: panel.section,
193
- ...(typeof number === 'number' && {number})};
203
+ ...(typeof number === 'number' && {number}), ...(pane && {pane})};
194
204
  } else if (panel.kind === 'stage' && !hasStage) {
195
205
  hasStage = true;
196
206
  panels[id] = {kind: 'stage'};
@@ -212,6 +222,19 @@ export function readWorkspaceLayout(raw: string, project?: string): WorkspaceLay
212
222
  ...(popouts.length && {popouts})};
213
223
  }
214
224
 
225
+ const assetIndex = (value: unknown): value is number =>
226
+ typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 && value <= 100000;
227
+
228
+ /** Keep only the fields of a pane state that have the right shape. The code state is checked by the host. */
229
+ function readPaneState(input: unknown): SpritePaneState | undefined {
230
+ if (!record(input)) return;
231
+ const pane: SpritePaneState = {};
232
+ if (assetIndex(input.costume)) pane.costume = input.costume;
233
+ if (assetIndex(input.sound)) pane.sound = input.sound;
234
+ if (record(input.code)) pane.code = input.code;
235
+ return Object.keys(pane).length ? pane : undefined;
236
+ }
237
+
215
238
  function readStageDrawer(input: unknown): StageDrawerLayout | undefined {
216
239
  if (!record(input) || typeof input.open !== 'boolean' || typeof input.selected !== 'boolean') return;
217
240
  const {position, width, pinned} = input;