@kubohiroya/turbowarp-plus-editor-workbench 0.10.0 → 0.11.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.
@@ -1,9 +1,24 @@
1
+ interface DocumentPanelSession {
2
+ requestClose(): void;
3
+ dispose(): void;
4
+ save?(): void | Promise<void>;
5
+ readonly fileEdit?: {
6
+ directory: FileSystemDirectoryHandle;
7
+ path: string;
8
+ isDirty(): boolean;
9
+ readUnsaved?(): Uint8Array | undefined;
10
+ save(): Promise<void>;
11
+ };
12
+ }
13
+
1
14
  export interface DocumentPanelRequest {
2
15
  reference: {providerId: string; documentId: string};
3
16
  filename: string;
4
17
  /** What the tab shows. Without it the tab names the file and where it comes from. */
5
18
  title?: string;
6
19
  transient?: boolean;
20
+ /** Keeps this utility tab first while the host enables the project folder drawer. */
21
+ pinWithProjectFolder?: boolean;
7
22
  /**
8
23
  * Opens the tab beside the other open tabs of the same area, in one split panel. The first tab of an area
9
24
  * opens in a new split to the right of the active panel, so the area does not mix with the sprite tabs.
@@ -16,7 +31,7 @@ export interface DocumentPanelRequest {
16
31
  tabGroup?: {id: string; label: string; color?: string; collapsed?: boolean};
17
32
  /** Opens the tab behind the active one, as when many tabs are opened at once. */
18
33
  inactive?: boolean;
19
- mount(element: HTMLElement, close: () => void): {requestClose(): void; dispose(): void};
34
+ mount(element: HTMLElement, close: () => void, onSaveAvailable?: () => void): DocumentPanelSession;
20
35
  }
21
36
 
22
37
  export const documentPanelTitle = ({title, filename, reference: {providerId, documentId}}: DocumentPanelRequest) =>
@@ -31,6 +46,11 @@ function createDocumentWorkspace() {
31
46
  let open: ((request: DocumentPanelRequest) => void) | undefined;
32
47
  let source: DocumentPanelSource | undefined;
33
48
  const listeners = new Set<() => void>();
49
+ let saveScope: 'project' | 'tab' = 'project';
50
+ let activeSession: (() => DocumentPanelSession | undefined) | undefined;
51
+ let sessions: (() => Iterable<DocumentPanelSession | undefined>) | undefined;
52
+ const saveListeners = new Set<() => void>();
53
+ const notifySave = () => saveListeners.forEach(listener => listener());
34
54
  const notify = () => listeners.forEach(listener => listener());
35
55
  return {
36
56
  open(request: DocumentPanelRequest) {
@@ -38,9 +58,38 @@ function createDocumentWorkspace() {
38
58
  open(request);
39
59
  return true;
40
60
  },
41
- connect(handler: NonNullable<typeof open>) {
61
+ connect(handler: NonNullable<typeof open>, getActiveSession?: NonNullable<typeof activeSession>,
62
+ getSessions?: NonNullable<typeof sessions>) {
42
63
  open = handler;
43
- return () => { if (open === handler) open = undefined; };
64
+ activeSession = getActiveSession;
65
+ sessions = getSessions;
66
+ notifySave();
67
+ return () => {
68
+ if (open !== handler) return;
69
+ open = undefined;
70
+ activeSession = undefined;
71
+ sessions = undefined;
72
+ notifySave();
73
+ };
74
+ },
75
+ setSaveScope(scope: typeof saveScope) {
76
+ if (scope === saveScope) return;
77
+ saveScope = scope;
78
+ notifySave();
79
+ },
80
+ get saveScope() {return saveScope;},
81
+ get canSaveActive() {return Boolean(activeSession?.()?.save);},
82
+ saveActive() {return activeSession?.()?.save?.();},
83
+ fileEdits() {
84
+ return Array.from(sessions?.() ?? []).flatMap(session => {
85
+ const file = session?.fileEdit;
86
+ return file?.isDirty() ? [file] : [];
87
+ });
88
+ },
89
+ notifySave,
90
+ subscribeSave(listener: () => void) {
91
+ saveListeners.add(listener);
92
+ return () => {saveListeners.delete(listener);};
44
93
  },
45
94
  connectSource(next: DocumentPanelSource) {
46
95
  source = next;
@@ -1,13 +1,15 @@
1
1
  import type {ReactNode} from 'react';
2
2
 
3
3
  /** The contents the left drawer can show. `sprites` is the GUI's sprite list and backdrop, always available. */
4
- export type DrawerViewId = 'sprites' | 'project' | 'git-history';
4
+ export type DrawerViewId = 'sprites' | 'project' | 'git-history' | 'agents';
5
5
  /** The contents a host supplies. */
6
6
  export type HostDrawerViewId = Exclude<DrawerViewId, 'sprites'>;
7
7
 
8
8
  export interface DrawerRenderProps {
9
9
  /** The Editor locale, for example `ja` or `en`. */
10
10
  locale: string;
11
+ /** The search text supplied by the drawer's search field. */
12
+ query?: string;
11
13
  }
12
14
 
13
15
  /** A drawer content supplied by the host. Its button appears only while the host supplies it. */
@@ -21,6 +23,8 @@ export interface DrawerView {
21
23
  render(props: DrawerRenderProps): ReactNode;
22
24
  /** The view's own tools, shown where the sprite list shows search, pin and undock. */
23
25
  tools?(props: DrawerRenderProps): ReactNode;
26
+ /** The accessible name of the search field, if this view supports search. */
27
+ searchLabel?(locale: string): string;
24
28
  }
25
29
 
26
30
  export interface DrawerMenuRenderProps extends DrawerRenderProps {
@@ -40,9 +44,13 @@ export interface DrawerMenu {
40
44
  export interface DrawerViews {
41
45
  views?: readonly DrawerView[];
42
46
  agents?: DrawerMenu;
47
+ /** Reports the drawer view presented by the standard layout. */
48
+ onSelectionChange?(view: DrawerViewId): void;
49
+ /** Exposes the drawer's reveal action to other panels in the same Editor. */
50
+ registerReveal?(reveal: (id: HostDrawerViewId) => void): () => void;
43
51
  }
44
52
 
45
- export const drawerViewIds: readonly DrawerViewId[] = ['sprites', 'project', 'git-history'];
53
+ export const drawerViewIds: readonly DrawerViewId[] = ['sprites', 'project', 'git-history', 'agents'];
46
54
  const hostIds = new Set<string>(drawerViewIds.slice(1));
47
55
 
48
56
  const names = {
@@ -104,6 +112,8 @@ export function writeDrawerView(storage: DrawerStorage | null | undefined, stora
104
112
  }
105
113
  }
106
114
 
115
+ export const projectFolderIconPath = 'M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z';
116
+
107
117
  let nextMenuId = 0;
108
118
 
109
119
  export function createDrawerViewBar(React, styles) {
@@ -116,7 +126,7 @@ export function createDrawerViewBar(React, styles) {
116
126
  sprites: () => svg(element('rect', {x: 2, y: 2, width: 5, height: 5, rx: 1}),
117
127
  element('rect', {x: 9, y: 2, width: 5, height: 5, rx: 1}),
118
128
  element('rect', {x: 2, y: 9, width: 12, height: 5, rx: 1})),
119
- project: () => svg(element('path', {d: 'M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z'})),
129
+ project: () => svg(element('path', {d: projectFolderIconPath})),
120
130
  'git-history': () => svg(element('circle', {cx: 5, cy: 3.5, r: 1.5}), element('circle', {cx: 5, cy: 12.5, r: 1.5}),
121
131
  element('circle', {cx: 11, cy: 6.5, r: 1.5}), element('path', {d: 'M5 5v6M11 8c0 2.5-6 1.5-6 3'})),
122
132
  agents: () => svg(element('path', {d: agentsIconPath}))
@@ -172,7 +182,8 @@ export function createDrawerViewBar(React, styles) {
172
182
  ...views.map(view => ({id: view.id, label: view.label ?? drawerLabel(view.id, locale),
173
183
  icon: view.icon ?? icons[view.id]()}))
174
184
  ];
175
- const count = entries.length + (agents ? 1 : 0);
185
+ const menu = entries.some(entry => entry.id === 'agents') ? undefined : agents;
186
+ const count = entries.length + (menu ? 1 : 0);
176
187
  const [focused, setFocused] = useState(() => Math.max(0, entries.findIndex(entry => entry.id === selected)));
177
188
  const current = Math.min(focused, count - 1);
178
189
  const move = (event, index) => {
@@ -200,8 +211,8 @@ export function createDrawerViewBar(React, styles) {
200
211
  onClick: () => onSelect(entry.id),
201
212
  onKeyDown: event => move(event, index)
202
213
  }, entry.icon)),
203
- agents && element(AgentMenu, {
204
- menu: agents, locale, button: agentButton,
214
+ menu && element(AgentMenu, {
215
+ menu, locale, button: agentButton,
205
216
  tabIndex: current === entries.length ? 0 : -1,
206
217
  onFocus: () => setFocused(entries.length),
207
218
  onKeyDown: event => move(event, entries.length)
package/src/editor.css CHANGED
@@ -717,8 +717,10 @@ details.layout-menu button {
717
717
  .target-list-tools {
718
718
  display: flex;
719
719
  align-items: center;
720
- justify-content: space-evenly;
721
- padding-block: 0.125rem;
720
+ justify-content: flex-end;
721
+ flex: none;
722
+ gap: 0.25rem;
723
+ padding: 0.125rem 0.25rem;
722
724
  }
723
725
 
724
726
  .target-list-tools button,
@@ -728,19 +730,22 @@ details.layout-menu button {
728
730
  min-width: 1.5rem;
729
731
  min-height: 1.5rem;
730
732
  padding: 0.125rem;
731
- border: 1px solid transparent;
733
+ border: 0;
732
734
  border-radius: 0.25rem;
733
735
  background: transparent;
734
736
  color: var(--text-primary);
735
737
  cursor: pointer;
736
738
  }
737
739
 
738
- .target-list-tools button:hover,
739
- .target-list-tools button:focus-visible {
740
- border-color: var(--ui-black-transparent);
740
+ .target-list-tools button:hover {
741
741
  background: var(--ui-primary);
742
742
  }
743
743
 
744
+ .target-list-tools button:focus-visible {
745
+ outline: 2px solid var(--looks-secondary);
746
+ outline-offset: -2px;
747
+ }
748
+
744
749
  .target-list-tools svg {
745
750
  width: 0.875rem;
746
751
  height: 0.875rem;
@@ -1004,12 +1009,23 @@ details.layout-menu button {
1004
1009
  color: #fff;
1005
1010
  }
1006
1011
 
1007
- .drawer-view-tools {
1012
+ .drawer-host-view {
1008
1013
  display: flex;
1009
- flex: none;
1010
- align-items: center;
1011
- justify-content: space-evenly;
1012
- padding-block: 0.125rem;
1014
+ flex: 1;
1015
+ flex-direction: column;
1016
+ min-block-size: 0;
1017
+ min-inline-size: 0;
1018
+ }
1019
+
1020
+ .drawer-host-view[hidden] {
1021
+ display: none;
1022
+ }
1023
+
1024
+ .drawer-host-view > .basic-panel {
1025
+ display: flex;
1026
+ flex: 1;
1027
+ flex-direction: column;
1028
+ min-block-size: 0;
1013
1029
  }
1014
1030
 
1015
1031
  .drawer-sprites {
@@ -1119,6 +1135,20 @@ details.layout-menu button {
1119
1135
  object-fit: contain;
1120
1136
  }
1121
1137
 
1138
+ :global(.tw-plus-folder-tab-icon) {
1139
+ display: none;
1140
+ }
1141
+
1142
+ :global([data-fixed-project-tab] .tw-plus-folder-tab-icon) {
1143
+ display: block;
1144
+ color: var(--looks-secondary, #855cd6);
1145
+ }
1146
+
1147
+ :global([data-fixed-project-tab] .dv-default-tab-action),
1148
+ :global([data-fixed-project-tab] img.tw-plus-sprite-tab-icon[hidden]) {
1149
+ display: none;
1150
+ }
1151
+
1122
1152
  .sprite-tabs :global(.tw-plus-sprite-rename) {
1123
1153
  border: 1px solid var(--ui-black-transparent);
1124
1154
  border-radius: 0.5rem;
@@ -5,13 +5,14 @@ import type {DockviewGroupPanel, GroupPanelPartInitParameters, IDockviewPanel, S
5
5
  import {createSpriteLayoutMenu} from './sprite-layout-menu.ts';
6
6
  import {NativeAssetPanel, SpriteAssetPane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
7
7
  import type {NativeAssetPanelRenderer, NativeAssetSelector, SpriteAssetKind, SpriteAssetLayout, SpriteAssetPreviewItem,
8
- SpriteVariable} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
8
+ SpriteVariable, SpriteVariablePaneProps} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
9
9
  import type {SpritePropertiesPanelProps} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-properties';
10
10
  import {SpriteEditorToolbar, spriteEditorSections} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-editor-toolbar';
11
11
  import type {SpriteSearchResult} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-editor-toolbar';
12
12
  import type {DockviewStagePane} from './dockview-stage.ts';
13
13
  import {documentPanelTitle, getDocumentWorkspace} from './document-workspace.ts';
14
14
  import type {DocumentPanelRequest} from './document-workspace.ts';
15
+ import {projectFolderIconPath} from './drawer-views.ts';
15
16
  import {dockPopoutGroups, positionOnScreen, readWorkspaceLayout, workspaceWithoutTransientPanels}
16
17
  from './workspace-layout.ts';
17
18
  import type {PanelReference, SavedPopout, WorkspaceLayout} from './workspace-layout.ts';
@@ -220,6 +221,7 @@ const projectSignature = (targets: readonly Target[]) => JSON.stringify(targets
220
221
 
221
222
  class SpriteTab extends DefaultTab {
222
223
  private readonly icon: HTMLImageElement;
224
+ private readonly folderIcon: SVGSVGElement;
223
225
 
224
226
  constructor(document: Document) {
225
227
  super();
@@ -227,6 +229,20 @@ class SpriteTab extends DefaultTab {
227
229
  this.icon.className = 'tw-plus-sprite-tab-icon';
228
230
  this.icon.alt = '';
229
231
  this.icon.draggable = false;
232
+ const svg = 'http://www.w3.org/2000/svg';
233
+ this.folderIcon = document.createElementNS(svg, 'svg');
234
+ this.folderIcon.classList.add('tw-plus-sprite-tab-icon', 'tw-plus-folder-tab-icon');
235
+ this.folderIcon.setAttribute('viewBox', '0 0 16 16');
236
+ this.folderIcon.setAttribute('fill', 'none');
237
+ this.folderIcon.setAttribute('stroke', 'currentColor');
238
+ this.folderIcon.setAttribute('stroke-width', '1.3');
239
+ this.folderIcon.setAttribute('stroke-linecap', 'round');
240
+ this.folderIcon.setAttribute('stroke-linejoin', 'round');
241
+ this.folderIcon.setAttribute('aria-hidden', 'true');
242
+ const path = document.createElementNS(svg, 'path');
243
+ path.setAttribute('d', projectFolderIconPath);
244
+ this.folderIcon.append(path);
245
+ this.element.prepend(this.folderIcon);
230
246
  this.element.prepend(this.icon);
231
247
  }
232
248
 
@@ -235,7 +251,10 @@ class SpriteTab extends DefaultTab {
235
251
  this.update(options);
236
252
  }
237
253
 
238
- update({params}: {params: {icon?: string}}) {
254
+ update({params}: {params: {icon?: string; fixedProjectTab?: boolean}}) {
255
+ this.element.toggleAttribute('data-fixed-project-tab', Boolean(params.fixedProjectTab));
256
+ const close = this.element.querySelector<HTMLElement>('.dv-default-tab-action');
257
+ if (close) close.style.display = params.fixedProjectTab ? 'none' : '';
239
258
  this.icon.hidden = !params.icon;
240
259
  if (params.icon) this.icon.src = params.icon;
241
260
  else this.icon.removeAttribute('src');
@@ -285,7 +304,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
285
304
  let initialShape: string | undefined;
286
305
  let disposed = false;
287
306
  const window = document.defaultView;
288
- const documentWorkspace = multiView && getDocumentWorkspace(vm);
307
+ const documentWorkspace = multiView ? getDocumentWorkspace(vm) : undefined;
289
308
  let pendingRestore = Boolean(persistence);
290
309
  let drawerEditedDuringRestore = false;
291
310
  let restoreFrame: number | undefined;
@@ -319,7 +338,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
319
338
  for (const id of [...tabGroup.panelIds]) dockview.getPanel(id)?.api.close();
320
339
  }},
321
340
  {label: chipText.closeAll, action: () => {
322
- for (const panel of [...group.panels]) if (documents.has(panel.id)) panel.api.close();
341
+ for (const panel of [...group.panels]) if (documents.has(panel.id) && !fixedProjectTab(panel.id)) panel.api.close();
323
342
  }}
324
343
  ],
325
344
  getTabContextMenuItems: ({panel}) => {
@@ -352,7 +371,8 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
352
371
  const item = documents.get(componentId);
353
372
  element.dataset.providerId = item.request.reference.providerId;
354
373
  element.dataset.documentId = item.request.reference.documentId;
355
- item.session = item.request.mount(element, () => api.close());
374
+ item.session = item.request.mount(element, () => api.close(), documentWorkspace?.notifySave);
375
+ documentWorkspace?.notifySave();
356
376
  }};
357
377
  }
358
378
  if (name === stagePanelId) {
@@ -434,11 +454,14 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
434
454
  preventSplit(event);
435
455
  return;
436
456
  }
437
- if (event.group?.api.location.type !== 'popout') return;
438
457
  const transfer = event.getData();
439
458
  const ids = transfer?.panelId ? [transfer.panelId] :
440
459
  dockview.groups.find(group => group.id === transfer?.groupId)?.panels.map(panel => panel.id) ?? [];
441
- if (ids.some(id => documents.has(id))) event.preventDefault();
460
+ if (ids.some(fixedProjectTab) ||
461
+ event.group?.api.location.type === 'popout' && ids.some(id => documents.has(id))) event.preventDefault();
462
+ });
463
+ const dragFixedTab = dockview.onWillDragPanel(({panel, nativeEvent}) => {
464
+ if (fixedProjectTab(panel.id)) nativeEvent.preventDefault();
442
465
  });
443
466
 
444
467
  function createLayoutMenu(group: DockviewGroupPanel) {
@@ -757,7 +780,37 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
757
780
  }
758
781
  }
759
782
 
783
+ function fixedProjectTab(id: string) {
784
+ return documentWorkspace?.saveScope === 'tab' && documents.get(id)?.request.pinWithProjectFolder === true;
785
+ }
786
+
787
+ function leftmostGroup() {
788
+ return dockview.groups.filter(group => group.api.location.type === 'grid')
789
+ .map(group => ({group, rect: group.element.getBoundingClientRect()}))
790
+ .sort((a, b) => a.rect.left - b.rect.left || a.rect.top - b.rect.top)[0]?.group;
791
+ }
792
+
793
+ function syncFixedProjectTab() {
794
+ if (disposed || syncing) return;
795
+ for (const [id, {request}] of documents) {
796
+ if (!request.pinWithProjectFolder) continue;
797
+ const panel = dockview.getPanel(id);
798
+ if (!panel) continue;
799
+ const fixed = fixedProjectTab(id);
800
+ if (panel.api.getParameters().fixedProjectTab !== fixed) panel.api.updateParameters({fixedProjectTab: fixed});
801
+ const group = fixed && leftmostGroup();
802
+ if (group && group.panels[0]?.id !== id) panel.api.moveTo({group, index: 0, skipSetActive: !panel.api.isActive});
803
+ }
804
+ }
805
+
760
806
  function openDocument(request: DocumentPanelRequest) {
807
+ // An automatically opened utility must not interrupt a project's saved layout restoration.
808
+ if (pendingRestore && request.inactive && request.pinWithProjectFolder) {
809
+ void layoutSettled().then(() => {
810
+ if (!disposed && documentWorkspace?.saveScope === 'tab') openDocument(request);
811
+ });
812
+ return;
813
+ }
761
814
  if (pendingRestore) finishRestore();
762
815
  const {providerId, documentId} = request.reference;
763
816
  for (const [id, {request: opened}] of documents) {
@@ -771,11 +824,13 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
771
824
  id = 'document-view-' + ++nextView;
772
825
  } while (views.has(id) || documents.has(id) || vm.runtime.targets.some(target => target.id === id));
773
826
  const title = documentPanelTitle(request);
774
- const position = documentPosition(request);
827
+ const fixed = request.pinWithProjectFolder && documentWorkspace?.saveScope === 'tab';
828
+ const group = fixed && leftmostGroup();
829
+ const position = group ? {referenceGroup: group, index: 0} : documentPosition(request);
775
830
  documents.set(id, {request});
776
831
  try {
777
832
  dockview.addPanel({id, title, component: documentComponent, renderer: 'always',
778
- inactive: request.inactive, ...(position && {position})});
833
+ inactive: request.inactive, params: {fixedProjectTab: Boolean(fixed)}, ...(position && {position})});
779
834
  } catch (error) {
780
835
  documents.get(id)?.session?.dispose();
781
836
  documents.delete(id);
@@ -809,14 +864,16 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
809
864
  function guardDocumentClose(event: MouseEvent | KeyboardEvent) {
810
865
  const element = event.target as HTMLElement;
811
866
  const tab = element.closest<HTMLElement>('[data-tab-panel-id]');
812
- const item = documents.get(tab?.dataset.tabPanelId);
867
+ const id = tab?.dataset.tabPanelId;
868
+ if (!id) return;
869
+ const item = documents.get(id);
813
870
  if (!item) return;
814
871
  const close = event.type === 'click' ? Boolean(element.closest('.dv-default-tab-action')) :
815
872
  event.target === tab && ['Delete', 'Backspace'].includes((event as KeyboardEvent).key);
816
873
  if (!close) return;
817
874
  event.preventDefault();
818
875
  event.stopPropagation();
819
- item.session?.requestClose();
876
+ if (!fixedProjectTab(id)) item.session?.requestClose();
820
877
  }
821
878
 
822
879
  function canCloseGroup(group: DockviewGroupPanel) {
@@ -1205,6 +1262,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
1205
1262
  }
1206
1263
 
1207
1264
  const selection = dockview.onDidActivePanelChange(({panel}) => {
1265
+ documentWorkspace?.notifySave();
1208
1266
  if (syncing) return;
1209
1267
  syncing = true;
1210
1268
  try {
@@ -1219,6 +1277,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
1219
1277
  if (item) {
1220
1278
  documents.delete(panel.id);
1221
1279
  item.session?.dispose();
1280
+ documentWorkspace?.notifySave();
1222
1281
  return;
1223
1282
  }
1224
1283
  if (panel.id === stagePanelId) {
@@ -1232,10 +1291,20 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
1232
1291
  if (![...views.values()].some(item => item.target === view.target)) closed.add(view.target);
1233
1292
  });
1234
1293
  const layout = multiView && dockview.onDidLayoutChange(() => {
1294
+ syncFixedProjectTab();
1235
1295
  refreshSurfaces();
1236
1296
  scheduleSave();
1237
1297
  });
1238
- const disconnectDocuments = documentWorkspace && documentWorkspace.connect(openDocument);
1298
+ const disconnectDocuments = documentWorkspace && documentWorkspace.connect(openDocument,
1299
+ () => documents.get(dockview.activePanel?.id)?.session,
1300
+ function* () {for (const item of documents.values()) yield item.session;});
1301
+ let previousScope = documentWorkspace?.saveScope;
1302
+ const unsubscribeFixedProjectTab = documentWorkspace?.subscribeSave(() => {
1303
+ const scope = documentWorkspace.saveScope;
1304
+ if (scope === previousScope) return;
1305
+ previousScope = scope;
1306
+ syncFixedProjectTab();
1307
+ });
1239
1308
  const unsubscribeDocuments = persistence && documentWorkspace && documentWorkspace.subscribe(scheduleRestore);
1240
1309
  projectLoading = Boolean(persistence && persistence.isProjectLoading?.());
1241
1310
  const unsubscribeProject = persistence && persistence.subscribeProject?.(projectChanged);
@@ -1277,6 +1346,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
1277
1346
  window.clearTimeout(restoreTimeout);
1278
1347
  if (persistence) window.removeEventListener('pagehide', flushLayout);
1279
1348
  if (unsubscribeDocuments) unsubscribeDocuments();
1349
+ unsubscribeFixedProjectTab?.();
1280
1350
  if (unsubscribeProject) unsubscribeProject();
1281
1351
  if (unsubscribeDrawer) unsubscribeDrawer();
1282
1352
  if (disconnectDocuments) disconnectDocuments();
@@ -1292,6 +1362,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
1292
1362
  removal.dispose();
1293
1363
  if (overlay) overlay.dispose();
1294
1364
  drop.dispose();
1365
+ dragFixedTab.dispose();
1295
1366
  if (layout) layout.dispose();
1296
1367
  for (const view of views.values()) disposeView(view);
1297
1368
  content.remove();
@@ -1319,6 +1390,9 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
1319
1390
  writeProperties?: SpritePropertiesPanelProps['onChange'];
1320
1391
  writeVariable?(targetId: string, id: string, value: SpriteVariable['value']): void;
1321
1392
  editVariable?(targetId: string, edit: SpriteVariableEdit): SpriteVariableEditError | void;
1393
+ /** Wrap a variables pane while receiving its docked view and original target identities. */
1394
+ wrapVariablePane?(viewId: string, targetId: string, editable: boolean,
1395
+ pane: React.ReactElement<SpriteVariablePaneProps>): React.ReactNode;
1322
1396
  /** What this target sends and receives. `scanTargetMessages` builds it from the runtime. */
1323
1397
  getMessages?(targetId: string): TargetMessages;
1324
1398
  /** Open the block that sends or receives a message. */
@@ -1506,7 +1580,7 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1506
1580
  if (section === 'code') props.openCodeSearchResult?.(view.targetId, result.id);
1507
1581
  else if (section === 'variables') {
1508
1582
  const field = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
1509
- [...(field?.querySelectorAll<HTMLInputElement>('input[data-variable-id]') ?? [])]
1583
+ [...(field?.querySelectorAll<HTMLElement>('[data-variable-id]') ?? [])]
1510
1584
  .find(input => input.dataset.variableId === result.id)?.focus();
1511
1585
  } else if (section === 'messages') {
1512
1586
  const pane = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
@@ -1527,22 +1601,28 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1527
1601
  if (!result) workspace?.refreshSurfaces();
1528
1602
  return result;
1529
1603
  })
1530
- }) : kind === 'variables' ? React.createElement(SpriteAssetPane, {
1531
- kind, locale: props.locale, editable, variables: props.getVariables?.(targetId) ?? [],
1532
- properties: props.getProperties?.(targetId),
1533
- targetId,
1534
- onWriteProperties(id: string, patch: Parameters<SpritePropertiesPanelProps['onChange']>[1]) {
1535
- props.writeProperties?.(id, patch);
1536
- workspace?.refreshSurfaces();
1537
- },
1538
- onWrite(variableId, value) {
1539
- props.writeVariable?.(targetId, variableId, value);
1540
- workspace?.refreshSurfaces();
1541
- },
1542
- onEdit: props.editVariable && (edit => props.editVariable!(targetId, edit))
1543
- }) : props.getAssetPreview && React.createElement(AssetPreview, {
1544
- locale: props.locale, kind, selected, renderLayout, scrollTop, data: props.getAssetPreview(targetId, kind)
1545
- }), element, id)));
1604
+ }) : kind === 'variables' ? renderVariablePane(id, targetId, editable) :
1605
+ props.getAssetPreview && React.createElement(AssetPreview, {
1606
+ locale: props.locale, kind, selected, renderLayout, scrollTop, data: props.getAssetPreview(targetId, kind)
1607
+ }), element, id)));
1608
+
1609
+ function renderVariablePane(id: string, targetId: string, editable: boolean) {
1610
+ const pane = React.createElement<SpriteVariablePaneProps>(SpriteAssetPane, {
1611
+ kind: 'variables', locale: props.locale, editable, variables: props.getVariables?.(targetId) ?? [],
1612
+ properties: props.getProperties?.(targetId),
1613
+ targetId,
1614
+ onWriteProperties(id: string, patch: Parameters<SpritePropertiesPanelProps['onChange']>[1]) {
1615
+ props.writeProperties?.(id, patch);
1616
+ workspace?.refreshSurfaces();
1617
+ },
1618
+ onWrite(variableId, value) {
1619
+ props.writeVariable?.(targetId, variableId, value);
1620
+ workspace?.refreshSurfaces();
1621
+ },
1622
+ onEdit: props.editVariable && (edit => props.editVariable!(targetId, edit))
1623
+ });
1624
+ return props.wrapVariablePane?.(id, targetId, editable, pane) ?? pane;
1625
+ }
1546
1626
  }
1547
1627
 
1548
1628
  export function useSpriteTabs<Snapshot>({available, enabled, locale, ...props}: