@kubohiroya/turbowarp-plus-editor-workbench 0.10.0 → 0.11.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.
@@ -86,6 +86,7 @@ export interface AgentSettingsDialogOptions {
86
86
  returnFocus?: HTMLElement | null;
87
87
  onSave?(settings: AgentSettings): void;
88
88
  desktop?: DesktopAiAgentsPort | null;
89
+ onDesktopSave?(): void;
89
90
  }
90
91
  export interface AgentSettingsDialog {
91
92
  element: HTMLElement;
@@ -95,5 +96,5 @@ export interface AgentSettingsDialog {
95
96
  * The settings dialog: turns the presets on and off, replaces their address, and adds or removes the
96
97
  * user's own services. It is plain DOM so that any part of the Editor can open it, with or without React.
97
98
  */
98
- export declare function openAgentSettingsDialog({ document: doc, locale, styles, storage, storageKey, returnFocus, onSave, desktop }: AgentSettingsDialogOptions): AgentSettingsDialog;
99
+ export declare function openAgentSettingsDialog({ document: doc, locale, styles, storage, storageKey, returnFocus, onSave, desktop, onDesktopSave }: AgentSettingsDialogOptions): AgentSettingsDialog;
99
100
  export {};
@@ -137,7 +137,7 @@ const urlProblems = { empty: 'urlEmpty', invalid: 'urlInvalid', 'not-https': 'ur
137
137
  * The settings dialog: turns the presets on and off, replaces their address, and adds or removes the
138
138
  * user's own services. It is plain DOM so that any part of the Editor can open it, with or without React.
139
139
  */
140
- export function openAgentSettingsDialog({ document: doc = globalThis.document, locale, styles = {}, storage = browserStorage(), storageKey = agentSettingsKey, returnFocus, onSave, desktop }) {
140
+ export function openAgentSettingsDialog({ document: doc = globalThis.document, locale, styles = {}, storage = browserStorage(), storageKey = agentSettingsKey, returnFocus, onSave, desktop, onDesktopSave }) {
141
141
  if (openDialog?.element.isConnected) {
142
142
  openDialog.element.querySelector(focusable)?.focus();
143
143
  return openDialog;
@@ -235,7 +235,7 @@ export function openAgentSettingsDialog({ document: doc = globalThis.document, l
235
235
  const status = make('p', { role: 'alert', class: styles.aiAgentDialogError, hidden: '' });
236
236
  const cancel = make('button', { type: 'button', class: styles.aiAgentDialogButton }, text('cancel'));
237
237
  const save = make('button', { type: 'submit', class: `${styles.aiAgentDialogButton ?? ''} ${styles.aiAgentDialogPrimary ?? ''}`.trim() }, text('save'));
238
- const form = make('form', { novalidate: '', class: styles.aiAgentDialogForm }, presetGroup, customGroup, desktop && desktopAgentSettings(doc, desktop, locale, styles), status, make('div', { class: styles.aiAgentDialogActions }, cancel, save));
238
+ const form = make('form', { novalidate: '', class: styles.aiAgentDialogForm }, presetGroup, customGroup, desktop && desktopAgentSettings(doc, desktop, locale, styles, onDesktopSave), status, make('div', { class: styles.aiAgentDialogActions }, cancel, save));
239
239
  const element = make('div', {
240
240
  role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': `${prefix}-title`,
241
241
  'aria-describedby': `${prefix}-description`, class: styles.aiAgentDialog
@@ -18,9 +18,14 @@ export interface AiAgentsOptions {
18
18
  */
19
19
  export declare function createAiAgents(React: any, { styles, storage, storageKey, open, desktop }?: AiAgentsOptions): {
20
20
  drawerMenu: DrawerMenu;
21
- openSettings: ({ locale, returnFocus }: {
21
+ renderPanel: ({ locale }: {
22
+ locale: string;
23
+ }) => any;
24
+ openSettings: ({ locale, returnFocus, onSave, onDesktopSave }: {
22
25
  locale: string;
23
26
  returnFocus?: HTMLElement | null;
27
+ onSave?: () => void;
28
+ onDesktopSave?: () => void;
24
29
  }) => import("./ai-agent-settings.ts").AgentSettingsDialog;
25
30
  settingsIcon: () => any;
26
31
  serviceIcon: (service?: AgentService) => any;
package/dist/ai-agents.js CHANGED
@@ -28,23 +28,29 @@ export function createAiAgents(React, { styles = {}, storage = browserStorage(),
28
28
  return svg(element('circle', { cx: 8, cy: 8, r: 6.25 }), element('path', { d: 'M1.75 8h12.5M8 1.75c-3 3.4-3 9.1 0 12.5M8 1.75c3 3.4 3 9.1 0 12.5' }));
29
29
  };
30
30
  const settingsIcon = () => svg(element('path', { d: agentsIconPath }));
31
- const openSettings = ({ locale, returnFocus }) => openAgentSettingsDialog({ document, locale, styles, storage, storageKey, returnFocus, desktop });
32
- function AgentMenu({ locale, close }) {
33
- const [services] = useState(() => enabledAgentServices(readAgentSettings(storage, storageKey)));
31
+ const openSettings = ({ locale, returnFocus, onSave, onDesktopSave }) => openAgentSettingsDialog({ document: returnFocus?.ownerDocument ?? document, locale, styles, storage,
32
+ storageKey, returnFocus, onSave, desktop, onDesktopSave });
33
+ function AgentList({ locale, close }) {
34
+ const [services, setServices] = useState(() => enabledAgentServices(readAgentSettings(storage, storageKey)));
34
35
  const [applications, setApplications] = useState([]);
35
36
  const [error, setError] = useState(null);
36
37
  const active = useRef(true);
38
+ const refreshApplications = async () => {
39
+ if (!desktop)
40
+ return;
41
+ const result = await agentRequest(() => desktop.list());
42
+ if (!active.current)
43
+ return;
44
+ if ('value' in result) {
45
+ setApplications(result.value.entries);
46
+ setError(null);
47
+ }
48
+ else
49
+ setError({ code: result.code });
50
+ };
37
51
  useEffect(() => {
38
52
  active.current = true;
39
- if (desktop)
40
- void agentRequest(() => desktop.list()).then(result => {
41
- if (!active.current)
42
- return;
43
- if ('value' in result)
44
- setApplications(result.value.entries);
45
- else
46
- setError({ code: result.code });
47
- });
53
+ void refreshApplications();
48
54
  return () => { active.current = false; };
49
55
  }, []);
50
56
  const list = useRef(null);
@@ -71,7 +77,7 @@ export function createAiAgents(React, { styles = {}, storage = browserStorage(),
71
77
  items[next]?.focus();
72
78
  };
73
79
  const item = (key, icon, text, onClick, title) => element('button', {
74
- key, type: 'button', role: 'menuitem', tabIndex: -1, className: styles.aiAgentMenuItem, title, onClick
80
+ key, type: 'button', role: close ? 'menuitem' : undefined, tabIndex: close ? -1 : undefined, className: styles.aiAgentMenuItem, title, onClick
75
81
  }, icon, element('span', null, text));
76
82
  const hasEntries = services.length + applications.length > 0;
77
83
  const launch = async (application) => {
@@ -80,29 +86,34 @@ export function createAiAgents(React, { styles = {}, storage = browserStorage(),
80
86
  if (!active.current)
81
87
  return;
82
88
  if ('value' in result)
83
- close();
89
+ close?.();
84
90
  else {
85
91
  const checked = checkAgentUrl(application.url);
86
92
  setError({ code: result.code, ...('url' in checked ? checked : {}) });
87
93
  }
88
94
  };
89
95
  return element(React.Fragment, null, error && element('p', { role: 'alert', className: styles.aiAgentMenuHint }, desktopAgentError(error.code, locale)), !hasEntries && element('p', { id: hintId.current, className: styles.aiAgentMenuHint }, agentText('empty', locale)), element('div', {
90
- role: 'menu', 'aria-label': label, ref: list, className: styles.aiAgentMenu, onKeyDown: move,
96
+ role: close ? 'menu' : 'group', 'aria-label': label, ref: list, className: styles.aiAgentMenu,
97
+ onKeyDown: close ? move : undefined,
91
98
  'aria-describedby': hasEntries ? undefined : hintId.current
92
99
  }, services.map(service => item(service.id, serviceIcon(service), service.name, () => {
93
100
  openAgentService(service, open);
94
- close();
101
+ close?.();
95
102
  }, newTab)), applications.map(application => item(`desktop-${application.id}`, settingsIcon(), application.name, () => void launch(application), desktopAgentText('opensApp', locale))), error?.url && item('fallback', serviceIcon(), desktopAgentText('openFallback', locale), () => {
96
103
  open(error.url, '_blank', 'noopener,noreferrer');
97
- close();
104
+ close?.();
98
105
  }, newTab), hasEntries && element('div', { role: 'separator', className: styles.aiAgentMenuSeparator }), item('settings', settingsIcon(), agentText('settings', locale), () => {
99
- close();
100
- openSettings({ locale, returnFocus: document.activeElement });
106
+ const doc = list.current.ownerDocument;
107
+ close?.();
108
+ openSettings({ locale, returnFocus: doc.activeElement,
109
+ onSave: close ? undefined : () => setServices(enabledAgentServices(readAgentSettings(storage, storageKey))),
110
+ onDesktopSave: close ? undefined : () => { void refreshApplications(); } });
101
111
  })));
102
112
  }
103
113
  const drawerMenu = {
104
- renderMenu: props => element(AgentMenu, props)
114
+ renderMenu: props => element(AgentList, props)
105
115
  };
106
- return { drawerMenu, openSettings, settingsIcon, serviceIcon };
116
+ return { drawerMenu, renderPanel: ({ locale }) => element(AgentList, { locale }),
117
+ openSettings, settingsIcon, serviceIcon };
107
118
  }
108
119
  let nextId = 0;
@@ -76,5 +76,5 @@ export declare const desktopAgentText: (key: keyof typeof strings, locale: strin
76
76
  export declare const desktopAgentError: (code: string, locale: string) => "プロジェクトフォルダ" | "Project folder" | "Desktop applications" | "デスクトップアプリ" | "Launches a desktop application" | "デスクトップアプリを起動します" | "Add an application" | "アプリを追加" | "Name" | "名前" | "Application" | "アプリ" | "Choose…" | "選択…" | "No application selected" | "アプリが選択されていません" | "Arguments (one per line)" | "引数(1 行に 1 つ)" | "Working directory" | "作業ディレクトリ" | "Fallback website (optional)" | "代わりに開く Web サイト(任意)" | "Open the website" | "Web サイトを開く" | "Enter an HTTPS address for the fallback website." | "代わりに開く Web サイトには HTTPS の URL を入力してください。" | "Available placeholders: {projectFolder}, {repository}, {branch}." | "使える置き換えは {projectFolder}・{repository}・{branch} です。" | "Choose project folder…" | "プロジェクトフォルダを選択…" | "Choose Git repository…" | "Git リポジトリを選択…" | "Git repository" | "Git リポジトリ" | "Branch" | "ブランチ" | "Expanded arguments" | "置き換え後の引数" | "Move up" | "上へ移動" | "Move down" | "下へ移動" | "Remove application" | "アプリを削除" | "Save applications" | "アプリの設定を保存" | "Application settings saved." | "アプリの設定を保存しました。" | "Try launching" | "試しに起動" | "Save the application before trying it." | "試しに起動するには、先にアプリの設定を保存してください。" | "Launch requested." | "アプリを起動しました。" | "Enter a name and choose an application for each entry." | "各項目の名前を入力し、アプリを選択してください。" | "The application settings changed. Reopen the settings and try again." | "アプリの設定が変更されました。設定を開き直してからやり直してください。" | "Another application operation is in progress." | "別のアプリ操作を実行中です。" | "The operation was cancelled." | "操作をキャンセルしました。" | "This application is no longer registered." | "このアプリは登録されていません。" | "Choose the folder or repository used by the launch arguments. A branch is required for {branch}." | "引数で使うフォルダまたはリポジトリを選択してください。{branch} にはブランチが必要です。" | "The working directory is unavailable." | "作業ディレクトリを利用できません。" | "The selected application is missing or cannot run." | "選択したアプリが見つからないか、起動できません。" | "The application could not start." | "アプリを起動できませんでした。" | "Desktop application settings are unavailable." | "デスクトップアプリの設定を利用できません。";
77
77
  export declare function agentRequest<T>(request: () => Promise<Result<T>>): Promise<Result<T>>;
78
78
  /** An optional section of the existing settings dialog. Its changes are saved by the Desktop host. */
79
- export declare function desktopAgentSettings(doc: Document, port: DesktopAiAgentsPort, locale: string, styles: Record<string, string>): HTMLFieldSetElement;
79
+ export declare function desktopAgentSettings(doc: Document, port: DesktopAiAgentsPort, locale: string, styles: Record<string, string>, onSave?: () => void): HTMLFieldSetElement;
80
80
  export {};
@@ -52,7 +52,7 @@ export async function agentRequest(request) {
52
52
  }
53
53
  }
54
54
  /** An optional section of the existing settings dialog. Its changes are saved by the Desktop host. */
55
- export function desktopAgentSettings(doc, port, locale, styles) {
55
+ export function desktopAgentSettings(doc, port, locale, styles, onSave) {
56
56
  const text = (key) => desktopAgentText(key, locale);
57
57
  const make = (tag, className, content) => {
58
58
  const node = doc.createElement(tag);
@@ -127,6 +127,7 @@ export function desktopAgentSettings(doc, port, locale, styles) {
127
127
  entries = value.entries.map(entry => ({ ...entry }));
128
128
  render();
129
129
  status.textContent = text('saved');
130
+ onSave?.();
130
131
  });
131
132
  });
132
133
  function render() {
@@ -1,3 +1,15 @@
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
+ }
1
13
  export interface DocumentPanelRequest {
2
14
  reference: {
3
15
  providerId: string;
@@ -7,6 +19,8 @@ export interface DocumentPanelRequest {
7
19
  /** What the tab shows. Without it the tab names the file and where it comes from. */
8
20
  title?: string;
9
21
  transient?: boolean;
22
+ /** Keeps this utility tab first while the host enables the project folder drawer. */
23
+ pinWithProjectFolder?: boolean;
10
24
  /**
11
25
  * Opens the tab beside the other open tabs of the same area, in one split panel. The first tab of an area
12
26
  * opens in a new split to the right of the active panel, so the area does not mix with the sprite tabs.
@@ -24,10 +38,7 @@ export interface DocumentPanelRequest {
24
38
  };
25
39
  /** Opens the tab behind the active one, as when many tabs are opened at once. */
26
40
  inactive?: boolean;
27
- mount(element: HTMLElement, close: () => void): {
28
- requestClose(): void;
29
- dispose(): void;
30
- };
41
+ mount(element: HTMLElement, close: () => void, onSaveAvailable?: () => void): DocumentPanelSession;
31
42
  }
32
43
  export declare const documentPanelTitle: ({ title, filename, reference: { providerId, documentId } }: DocumentPanelRequest) => string;
33
44
  interface DocumentPanelSource {
@@ -36,7 +47,20 @@ interface DocumentPanelSource {
36
47
  }
37
48
  export declare function getDocumentWorkspace(vm: object): {
38
49
  open(request: DocumentPanelRequest): boolean;
39
- connect(handler: NonNullable<(request: DocumentPanelRequest) => void>): () => void;
50
+ connect(handler: NonNullable<(request: DocumentPanelRequest) => void>, getActiveSession?: NonNullable<() => DocumentPanelSession | undefined>, getSessions?: NonNullable<() => Iterable<DocumentPanelSession | undefined>>): () => void;
51
+ setSaveScope(scope: "project" | "tab"): void;
52
+ readonly saveScope: "project" | "tab";
53
+ readonly canSaveActive: boolean;
54
+ saveActive(): void | Promise<void>;
55
+ fileEdits(): {
56
+ directory: FileSystemDirectoryHandle;
57
+ path: string;
58
+ isDirty(): boolean;
59
+ readUnsaved?(): Uint8Array | undefined;
60
+ save(): Promise<void>;
61
+ }[];
62
+ notifySave: () => void;
63
+ subscribeSave(listener: () => void): () => void;
40
64
  connectSource(next: DocumentPanelSource): () => void;
41
65
  resolve(reference: DocumentPanelRequest["reference"]): DocumentPanelRequest;
42
66
  subscribe(listener: () => void): () => void;
@@ -3,6 +3,11 @@ function createDocumentWorkspace() {
3
3
  let open;
4
4
  let source;
5
5
  const listeners = new Set();
6
+ let saveScope = 'project';
7
+ let activeSession;
8
+ let sessions;
9
+ const saveListeners = new Set();
10
+ const notifySave = () => saveListeners.forEach(listener => listener());
6
11
  const notify = () => listeners.forEach(listener => listener());
7
12
  return {
8
13
  open(request) {
@@ -11,10 +16,39 @@ function createDocumentWorkspace() {
11
16
  open(request);
12
17
  return true;
13
18
  },
14
- connect(handler) {
19
+ connect(handler, getActiveSession, getSessions) {
15
20
  open = handler;
16
- return () => { if (open === handler)
17
- open = undefined; };
21
+ activeSession = getActiveSession;
22
+ sessions = getSessions;
23
+ notifySave();
24
+ return () => {
25
+ if (open !== handler)
26
+ return;
27
+ open = undefined;
28
+ activeSession = undefined;
29
+ sessions = undefined;
30
+ notifySave();
31
+ };
32
+ },
33
+ setSaveScope(scope) {
34
+ if (scope === saveScope)
35
+ return;
36
+ saveScope = scope;
37
+ notifySave();
38
+ },
39
+ get saveScope() { return saveScope; },
40
+ get canSaveActive() { return Boolean(activeSession?.()?.save); },
41
+ saveActive() { return activeSession?.()?.save?.(); },
42
+ fileEdits() {
43
+ return Array.from(sessions?.() ?? []).flatMap(session => {
44
+ const file = session?.fileEdit;
45
+ return file?.isDirty() ? [file] : [];
46
+ });
47
+ },
48
+ notifySave,
49
+ subscribeSave(listener) {
50
+ saveListeners.add(listener);
51
+ return () => { saveListeners.delete(listener); };
18
52
  },
19
53
  connectSource(next) {
20
54
  source = next;
@@ -1,11 +1,13 @@
1
1
  import type { ReactNode } from 'react';
2
2
  /** The contents the left drawer can show. `sprites` is the GUI's sprite list and backdrop, always available. */
3
- export type DrawerViewId = 'sprites' | 'project' | 'git-history';
3
+ export type DrawerViewId = 'sprites' | 'project' | 'git-history' | 'agents';
4
4
  /** The contents a host supplies. */
5
5
  export type HostDrawerViewId = Exclude<DrawerViewId, 'sprites'>;
6
6
  export interface DrawerRenderProps {
7
7
  /** The Editor locale, for example `ja` or `en`. */
8
8
  locale: string;
9
+ /** The search text supplied by the drawer's search field. */
10
+ query?: string;
9
11
  }
10
12
  /** A drawer content supplied by the host. Its button appears only while the host supplies it. */
11
13
  export interface DrawerView {
@@ -18,6 +20,8 @@ export interface DrawerView {
18
20
  render(props: DrawerRenderProps): ReactNode;
19
21
  /** The view's own tools, shown where the sprite list shows search, pin and undock. */
20
22
  tools?(props: DrawerRenderProps): ReactNode;
23
+ /** The accessible name of the search field, if this view supports search. */
24
+ searchLabel?(locale: string): string;
21
25
  }
22
26
  export interface DrawerMenuRenderProps extends DrawerRenderProps {
23
27
  /** Close the menu and return focus to its button. */
@@ -34,6 +38,10 @@ export interface DrawerMenu {
34
38
  export interface DrawerViews {
35
39
  views?: readonly DrawerView[];
36
40
  agents?: DrawerMenu;
41
+ /** Reports the drawer view presented by the standard layout. */
42
+ onSelectionChange?(view: DrawerViewId): void;
43
+ /** Exposes the drawer's reveal action to other panels in the same Editor. */
44
+ registerReveal?(reveal: (id: HostDrawerViewId) => void): () => void;
37
45
  }
38
46
  export declare const drawerViewIds: readonly DrawerViewId[];
39
47
  declare const names: {
@@ -57,6 +65,7 @@ export declare const drawerViewKey: (storageKey: string) => string;
57
65
  /** The view selected last time, or `sprites`. The caller falls back to `sprites` while that view is unavailable. */
58
66
  export declare function readDrawerView(storage: DrawerStorage | null | undefined, storageKey: string | undefined): DrawerViewId;
59
67
  export declare function writeDrawerView(storage: DrawerStorage | null | undefined, storageKey: string | undefined, view: DrawerViewId): void;
68
+ export declare const projectFolderIconPath = "M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z";
60
69
  export declare function createDrawerViewBar(React: any, styles: any): ({ locale, views, agents, selected, onSelect }: {
61
70
  locale: any;
62
71
  views: any;
@@ -1,4 +1,4 @@
1
- export const drawerViewIds = ['sprites', 'project', 'git-history'];
1
+ export const drawerViewIds = ['sprites', 'project', 'git-history', 'agents'];
2
2
  const hostIds = new Set(drawerViewIds.slice(1));
3
3
  const names = {
4
4
  sprites: ['スプライト一覧', 'Sprites'],
@@ -51,6 +51,7 @@ export function writeDrawerView(storage, storageKey, view) {
51
51
  // Keep the drawer usable when persistence is denied.
52
52
  }
53
53
  }
54
+ export const projectFolderIconPath = 'M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z';
54
55
  let nextMenuId = 0;
55
56
  export function createDrawerViewBar(React, styles) {
56
57
  const { createElement: element, useLayoutEffect, useRef, useState } = React;
@@ -60,7 +61,7 @@ export function createDrawerViewBar(React, styles) {
60
61
  }, ...children);
61
62
  const icons = {
62
63
  sprites: () => svg(element('rect', { x: 2, y: 2, width: 5, height: 5, rx: 1 }), element('rect', { x: 9, y: 2, width: 5, height: 5, rx: 1 }), element('rect', { x: 2, y: 9, width: 12, height: 5, rx: 1 })),
63
- project: () => svg(element('path', { d: 'M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z' })),
64
+ project: () => svg(element('path', { d: projectFolderIconPath })),
64
65
  'git-history': () => svg(element('circle', { cx: 5, cy: 3.5, r: 1.5 }), element('circle', { cx: 5, cy: 12.5, r: 1.5 }), element('circle', { cx: 11, cy: 6.5, r: 1.5 }), element('path', { d: 'M5 5v6M11 8c0 2.5-6 1.5-6 3' })),
65
66
  agents: () => svg(element('path', { d: agentsIconPath }))
66
67
  };
@@ -116,7 +117,8 @@ export function createDrawerViewBar(React, styles) {
116
117
  ...views.map(view => ({ id: view.id, label: view.label ?? drawerLabel(view.id, locale),
117
118
  icon: view.icon ?? icons[view.id]() }))
118
119
  ];
119
- const count = entries.length + (agents ? 1 : 0);
120
+ const menu = entries.some(entry => entry.id === 'agents') ? undefined : agents;
121
+ const count = entries.length + (menu ? 1 : 0);
120
122
  const [focused, setFocused] = useState(() => Math.max(0, entries.findIndex(entry => entry.id === selected)));
121
123
  const current = Math.min(focused, count - 1);
122
124
  const move = (event, index) => {
@@ -146,8 +148,8 @@ export function createDrawerViewBar(React, styles) {
146
148
  onFocus: () => setFocused(index),
147
149
  onClick: () => onSelect(entry.id),
148
150
  onKeyDown: event => move(event, index)
149
- }, entry.icon)), agents && element(AgentMenu, {
150
- menu: agents, locale, button: agentButton,
151
+ }, entry.icon)), menu && element(AgentMenu, {
152
+ menu, locale, button: agentButton,
151
153
  tabIndex: current === entries.length ? 0 : -1,
152
154
  onFocus: () => setFocused(entries.length),
153
155
  onKeyDown: event => move(event, entries.length)
@@ -5,6 +5,7 @@ import { createSpriteLayoutMenu } from "./sprite-layout-menu.js";
5
5
  import { NativeAssetPanel, SpriteAssetPane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
6
6
  import { SpriteEditorToolbar, spriteEditorSections } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-editor-toolbar';
7
7
  import { documentPanelTitle, getDocumentWorkspace } from "./document-workspace.js";
8
+ import { projectFolderIconPath } from "./drawer-views.js";
8
9
  import { dockPopoutGroups, positionOnScreen, readWorkspaceLayout, workspaceWithoutTransientPanels } from "./workspace-layout.js";
9
10
  import { createWorkspaceLayoutStore } from "./workspace-layout-store.js";
10
11
  import { SpriteMessagePane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
@@ -70,12 +71,27 @@ const projectSignature = (targets) => JSON.stringify(targets
70
71
  .sort());
71
72
  class SpriteTab extends DefaultTab {
72
73
  icon;
74
+ folderIcon;
73
75
  constructor(document) {
74
76
  super();
75
77
  this.icon = document.createElement('img');
76
78
  this.icon.className = 'tw-plus-sprite-tab-icon';
77
79
  this.icon.alt = '';
78
80
  this.icon.draggable = false;
81
+ const svg = 'http://www.w3.org/2000/svg';
82
+ this.folderIcon = document.createElementNS(svg, 'svg');
83
+ this.folderIcon.classList.add('tw-plus-sprite-tab-icon', 'tw-plus-folder-tab-icon');
84
+ this.folderIcon.setAttribute('viewBox', '0 0 16 16');
85
+ this.folderIcon.setAttribute('fill', 'none');
86
+ this.folderIcon.setAttribute('stroke', 'currentColor');
87
+ this.folderIcon.setAttribute('stroke-width', '1.3');
88
+ this.folderIcon.setAttribute('stroke-linecap', 'round');
89
+ this.folderIcon.setAttribute('stroke-linejoin', 'round');
90
+ this.folderIcon.setAttribute('aria-hidden', 'true');
91
+ const path = document.createElementNS(svg, 'path');
92
+ path.setAttribute('d', projectFolderIconPath);
93
+ this.folderIcon.append(path);
94
+ this.element.prepend(this.folderIcon);
79
95
  this.element.prepend(this.icon);
80
96
  }
81
97
  init(options) {
@@ -83,6 +99,10 @@ class SpriteTab extends DefaultTab {
83
99
  this.update(options);
84
100
  }
85
101
  update({ params }) {
102
+ this.element.toggleAttribute('data-fixed-project-tab', Boolean(params.fixedProjectTab));
103
+ const close = this.element.querySelector('.dv-default-tab-action');
104
+ if (close)
105
+ close.style.display = params.fixedProjectTab ? 'none' : '';
86
106
  this.icon.hidden = !params.icon;
87
107
  if (params.icon)
88
108
  this.icon.src = params.icon;
@@ -133,7 +153,7 @@ export function mountSpriteTabs(root, content, options) {
133
153
  let initialShape;
134
154
  let disposed = false;
135
155
  const window = document.defaultView;
136
- const documentWorkspace = multiView && getDocumentWorkspace(vm);
156
+ const documentWorkspace = multiView ? getDocumentWorkspace(vm) : undefined;
137
157
  let pendingRestore = Boolean(persistence);
138
158
  let drawerEditedDuringRestore = false;
139
159
  let restoreFrame;
@@ -168,7 +188,7 @@ export function mountSpriteTabs(root, content, options) {
168
188
  } },
169
189
  { label: chipText.closeAll, action: () => {
170
190
  for (const panel of [...group.panels])
171
- if (documents.has(panel.id))
191
+ if (documents.has(panel.id) && !fixedProjectTab(panel.id))
172
192
  panel.api.close();
173
193
  } }
174
194
  ],
@@ -206,7 +226,8 @@ export function mountSpriteTabs(root, content, options) {
206
226
  const item = documents.get(componentId);
207
227
  element.dataset.providerId = item.request.reference.providerId;
208
228
  element.dataset.documentId = item.request.reference.documentId;
209
- item.session = item.request.mount(element, () => api.close());
229
+ item.session = item.request.mount(element, () => api.close(), documentWorkspace?.notifySave);
230
+ documentWorkspace?.notifySave();
210
231
  } };
211
232
  }
212
233
  if (name === stagePanelId) {
@@ -295,14 +316,17 @@ export function mountSpriteTabs(root, content, options) {
295
316
  preventSplit(event);
296
317
  return;
297
318
  }
298
- if (event.group?.api.location.type !== 'popout')
299
- return;
300
319
  const transfer = event.getData();
301
320
  const ids = transfer?.panelId ? [transfer.panelId] :
302
321
  dockview.groups.find(group => group.id === transfer?.groupId)?.panels.map(panel => panel.id) ?? [];
303
- if (ids.some(id => documents.has(id)))
322
+ if (ids.some(fixedProjectTab) ||
323
+ event.group?.api.location.type === 'popout' && ids.some(id => documents.has(id)))
304
324
  event.preventDefault();
305
325
  });
326
+ const dragFixedTab = dockview.onWillDragPanel(({ panel, nativeEvent }) => {
327
+ if (fixedProjectTab(panel.id))
328
+ nativeEvent.preventDefault();
329
+ });
306
330
  function createLayoutMenu(group) {
307
331
  const popouts = options.popouts;
308
332
  const canOpenPanel = () => group.api.location.type === 'grid' &&
@@ -636,7 +660,40 @@ export function mountSpriteTabs(root, content, options) {
636
660
  select(target.id);
637
661
  }
638
662
  }
663
+ function fixedProjectTab(id) {
664
+ return documentWorkspace?.saveScope === 'tab' && documents.get(id)?.request.pinWithProjectFolder === true;
665
+ }
666
+ function leftmostGroup() {
667
+ return dockview.groups.filter(group => group.api.location.type === 'grid')
668
+ .map(group => ({ group, rect: group.element.getBoundingClientRect() }))
669
+ .sort((a, b) => a.rect.left - b.rect.left || a.rect.top - b.rect.top)[0]?.group;
670
+ }
671
+ function syncFixedProjectTab() {
672
+ if (disposed || syncing)
673
+ return;
674
+ for (const [id, { request }] of documents) {
675
+ if (!request.pinWithProjectFolder)
676
+ continue;
677
+ const panel = dockview.getPanel(id);
678
+ if (!panel)
679
+ continue;
680
+ const fixed = fixedProjectTab(id);
681
+ if (panel.api.getParameters().fixedProjectTab !== fixed)
682
+ panel.api.updateParameters({ fixedProjectTab: fixed });
683
+ const group = fixed && leftmostGroup();
684
+ if (group && group.panels[0]?.id !== id)
685
+ panel.api.moveTo({ group, index: 0, skipSetActive: !panel.api.isActive });
686
+ }
687
+ }
639
688
  function openDocument(request) {
689
+ // An automatically opened utility must not interrupt a project's saved layout restoration.
690
+ if (pendingRestore && request.inactive && request.pinWithProjectFolder) {
691
+ void layoutSettled().then(() => {
692
+ if (!disposed && documentWorkspace?.saveScope === 'tab')
693
+ openDocument(request);
694
+ });
695
+ return;
696
+ }
640
697
  if (pendingRestore)
641
698
  finishRestore();
642
699
  const { providerId, documentId } = request.reference;
@@ -652,11 +709,13 @@ export function mountSpriteTabs(root, content, options) {
652
709
  id = 'document-view-' + ++nextView;
653
710
  } while (views.has(id) || documents.has(id) || vm.runtime.targets.some(target => target.id === id));
654
711
  const title = documentPanelTitle(request);
655
- const position = documentPosition(request);
712
+ const fixed = request.pinWithProjectFolder && documentWorkspace?.saveScope === 'tab';
713
+ const group = fixed && leftmostGroup();
714
+ const position = group ? { referenceGroup: group, index: 0 } : documentPosition(request);
656
715
  documents.set(id, { request });
657
716
  try {
658
717
  dockview.addPanel({ id, title, component: documentComponent, renderer: 'always',
659
- inactive: request.inactive, ...(position && { position }) });
718
+ inactive: request.inactive, params: { fixedProjectTab: Boolean(fixed) }, ...(position && { position }) });
660
719
  }
661
720
  catch (error) {
662
721
  documents.get(id)?.session?.dispose();
@@ -693,7 +752,10 @@ export function mountSpriteTabs(root, content, options) {
693
752
  function guardDocumentClose(event) {
694
753
  const element = event.target;
695
754
  const tab = element.closest('[data-tab-panel-id]');
696
- const item = documents.get(tab?.dataset.tabPanelId);
755
+ const id = tab?.dataset.tabPanelId;
756
+ if (!id)
757
+ return;
758
+ const item = documents.get(id);
697
759
  if (!item)
698
760
  return;
699
761
  const close = event.type === 'click' ? Boolean(element.closest('.dv-default-tab-action')) :
@@ -702,7 +764,8 @@ export function mountSpriteTabs(root, content, options) {
702
764
  return;
703
765
  event.preventDefault();
704
766
  event.stopPropagation();
705
- item.session?.requestClose();
767
+ if (!fixedProjectTab(id))
768
+ item.session?.requestClose();
706
769
  }
707
770
  function canCloseGroup(group) {
708
771
  return dockview.groups.length > 1 && group.panels.every(panel => !documents.has(panel.id));
@@ -1124,6 +1187,7 @@ export function mountSpriteTabs(root, content, options) {
1124
1187
  views.delete(view.id);
1125
1188
  }
1126
1189
  const selection = dockview.onDidActivePanelChange(({ panel }) => {
1190
+ documentWorkspace?.notifySave();
1127
1191
  if (syncing)
1128
1192
  return;
1129
1193
  syncing = true;
@@ -1140,6 +1204,7 @@ export function mountSpriteTabs(root, content, options) {
1140
1204
  if (item) {
1141
1205
  documents.delete(panel.id);
1142
1206
  item.session?.dispose();
1207
+ documentWorkspace?.notifySave();
1143
1208
  return;
1144
1209
  }
1145
1210
  if (panel.id === stagePanelId) {
@@ -1156,10 +1221,20 @@ export function mountSpriteTabs(root, content, options) {
1156
1221
  closed.add(view.target);
1157
1222
  });
1158
1223
  const layout = multiView && dockview.onDidLayoutChange(() => {
1224
+ syncFixedProjectTab();
1159
1225
  refreshSurfaces();
1160
1226
  scheduleSave();
1161
1227
  });
1162
- const disconnectDocuments = documentWorkspace && documentWorkspace.connect(openDocument);
1228
+ const disconnectDocuments = documentWorkspace && documentWorkspace.connect(openDocument, () => documents.get(dockview.activePanel?.id)?.session, function* () { for (const item of documents.values())
1229
+ yield item.session; });
1230
+ let previousScope = documentWorkspace?.saveScope;
1231
+ const unsubscribeFixedProjectTab = documentWorkspace?.subscribeSave(() => {
1232
+ const scope = documentWorkspace.saveScope;
1233
+ if (scope === previousScope)
1234
+ return;
1235
+ previousScope = scope;
1236
+ syncFixedProjectTab();
1237
+ });
1163
1238
  const unsubscribeDocuments = persistence && documentWorkspace && documentWorkspace.subscribe(scheduleRestore);
1164
1239
  projectLoading = Boolean(persistence && persistence.isProjectLoading?.());
1165
1240
  const unsubscribeProject = persistence && persistence.subscribeProject?.(projectChanged);
@@ -1208,6 +1283,7 @@ export function mountSpriteTabs(root, content, options) {
1208
1283
  window.removeEventListener('pagehide', flushLayout);
1209
1284
  if (unsubscribeDocuments)
1210
1285
  unsubscribeDocuments();
1286
+ unsubscribeFixedProjectTab?.();
1211
1287
  if (unsubscribeProject)
1212
1288
  unsubscribeProject();
1213
1289
  if (unsubscribeDrawer)
@@ -1228,6 +1304,7 @@ export function mountSpriteTabs(root, content, options) {
1228
1304
  if (overlay)
1229
1305
  overlay.dispose();
1230
1306
  drop.dispose();
1307
+ dragFixedTab.dispose();
1231
1308
  if (layout)
1232
1309
  layout.dispose();
1233
1310
  for (const view of views.values())
@@ -1,11 +1,20 @@
1
- import type { DrawerViews } from './drawer-views.ts';
1
+ import type { DrawerView, DrawerViews } from './drawer-views.ts';
2
2
  import type { StageDrawerLayout } from './workspace-layout.ts';
3
3
  export type { DrawerMenu, DrawerMenuRenderProps, DrawerRenderProps, DrawerView, DrawerViewId, DrawerViews, HostDrawerViewId } from './drawer-views.ts';
4
- export declare function createStandardLayout(React: any, { styles, targetStyles, context, LayoutMenu }: {
4
+ type DrawerPanel = (props: {
5
+ id: DrawerView['id'];
6
+ title: string;
7
+ locale: string;
8
+ dockRequest: number;
9
+ renderHeading(undock: import('react').ReactNode): import('react').ReactNode;
10
+ renderContent(detached: boolean): import('react').ReactNode;
11
+ }) => import('react').ReactNode;
12
+ export declare function createStandardLayout(React: any, { styles, targetStyles, context, LayoutMenu, DrawerPanel }: {
5
13
  styles: any;
6
14
  targetStyles: any;
7
15
  context: any;
8
16
  LayoutMenu: any;
17
+ DrawerPanel?: DrawerPanel;
9
18
  }): {
10
19
  StandardLayout: ({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer, onPaletteModeChange, windowTools, Container, render, drawerViews, stageDrawerLayout, updateStageDrawer, ...props }: {
11
20
  [x: string]: any;