@kubohiroya/turbowarp-plus-editor-workbench 0.9.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.
- package/README.ja.md +1 -0
- package/README.md +1 -0
- package/dist/ai-agent-settings.d.ts +8 -5
- package/dist/ai-agent-settings.js +14 -11
- package/dist/ai-agents.d.ts +11 -3
- package/dist/ai-agents.js +61 -17
- package/dist/desktop-ai-agents.d.ts +80 -0
- package/dist/desktop-ai-agents.js +236 -0
- package/dist/document-workspace.d.ts +29 -5
- package/dist/document-workspace.js +37 -3
- package/dist/drawer-views.d.ts +10 -1
- package/dist/drawer-views.js +7 -5
- package/dist/sprite-tabs.js +88 -11
- package/dist/standard-layout.d.ts +11 -2
- package/dist/standard-layout.js +61 -20
- package/package.json +1 -1
- package/src/ai-agent-settings.ts +18 -12
- package/src/ai-agents.ts +65 -19
- package/src/desktop-ai-agents.ts +265 -0
- package/src/document-workspace.ts +52 -3
- package/src/drawer-views.ts +17 -6
- package/src/editor.css +43 -12
- package/src/sprite-tabs.ts +82 -11
- package/src/standard-layout.ts +85 -31
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { isJapanese } from "./drawer-views.js";
|
|
2
|
+
const defaultDirectory = '{projectFolder}';
|
|
3
|
+
const variables = /\{(projectFolder|repository|branch)\}/gu;
|
|
4
|
+
const strings = {
|
|
5
|
+
section: ['Desktop applications', 'デスクトップアプリ'],
|
|
6
|
+
opensApp: ['Launches a desktop application', 'デスクトップアプリを起動します'],
|
|
7
|
+
add: ['Add an application', 'アプリを追加'],
|
|
8
|
+
name: ['Name', '名前'],
|
|
9
|
+
application: ['Application', 'アプリ'],
|
|
10
|
+
choose: ['Choose…', '選択…'],
|
|
11
|
+
unselected: ['No application selected', 'アプリが選択されていません'],
|
|
12
|
+
args: ['Arguments (one per line)', '引数(1 行に 1 つ)'],
|
|
13
|
+
cwd: ['Working directory', '作業ディレクトリ'],
|
|
14
|
+
url: ['Fallback website (optional)', '代わりに開く Web サイト(任意)'],
|
|
15
|
+
openFallback: ['Open the website', 'Web サイトを開く'],
|
|
16
|
+
'invalid-url': ['Enter an HTTPS address for the fallback website.', '代わりに開く Web サイトには HTTPS の URL を入力してください。'],
|
|
17
|
+
variables: ['Available placeholders: {projectFolder}, {repository}, {branch}.', '使える置き換えは {projectFolder}・{repository}・{branch} です。'],
|
|
18
|
+
chooseProject: ['Choose project folder…', 'プロジェクトフォルダを選択…'],
|
|
19
|
+
chooseRepository: ['Choose Git repository…', 'Git リポジトリを選択…'],
|
|
20
|
+
projectFolder: ['Project folder', 'プロジェクトフォルダ'],
|
|
21
|
+
repository: ['Git repository', 'Git リポジトリ'],
|
|
22
|
+
branch: ['Branch', 'ブランチ'],
|
|
23
|
+
preview: ['Expanded arguments', '置き換え後の引数'],
|
|
24
|
+
up: ['Move up', '上へ移動'],
|
|
25
|
+
down: ['Move down', '下へ移動'],
|
|
26
|
+
remove: ['Remove application', 'アプリを削除'],
|
|
27
|
+
save: ['Save applications', 'アプリの設定を保存'],
|
|
28
|
+
saved: ['Application settings saved.', 'アプリの設定を保存しました。'],
|
|
29
|
+
test: ['Try launching', '試しに起動'],
|
|
30
|
+
saveFirst: ['Save the application before trying it.', '試しに起動するには、先にアプリの設定を保存してください。'],
|
|
31
|
+
launched: ['Launch requested.', 'アプリを起動しました。'],
|
|
32
|
+
invalid: ['Enter a name and choose an application for each entry.', '各項目の名前を入力し、アプリを選択してください。'],
|
|
33
|
+
conflict: ['The application settings changed. Reopen the settings and try again.', 'アプリの設定が変更されました。設定を開き直してからやり直してください。'],
|
|
34
|
+
busy: ['Another application operation is in progress.', '別のアプリ操作を実行中です。'],
|
|
35
|
+
cancelled: ['The operation was cancelled.', '操作をキャンセルしました。'],
|
|
36
|
+
unknown: ['This application is no longer registered.', 'このアプリは登録されていません。'],
|
|
37
|
+
'missing-context': ['Choose the folder or repository used by the launch arguments. A branch is required for {branch}.',
|
|
38
|
+
'引数で使うフォルダまたはリポジトリを選択してください。{branch} にはブランチが必要です。'],
|
|
39
|
+
'invalid-directory': ['The working directory is unavailable.', '作業ディレクトリを利用できません。'],
|
|
40
|
+
'app-missing': ['The selected application is missing or cannot run.', '選択したアプリが見つからないか、起動できません。'],
|
|
41
|
+
'launch-failed': ['The application could not start.', 'アプリを起動できませんでした。'],
|
|
42
|
+
unavailable: ['Desktop application settings are unavailable.', 'デスクトップアプリの設定を利用できません。']
|
|
43
|
+
};
|
|
44
|
+
export const desktopAgentText = (key, locale) => strings[key][isJapanese(locale) ? 1 : 0];
|
|
45
|
+
export const desktopAgentError = (code, locale) => desktopAgentText(Object.hasOwn(strings, code) ? code : 'unavailable', locale);
|
|
46
|
+
export async function agentRequest(request) {
|
|
47
|
+
try {
|
|
48
|
+
return await request();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return { ok: false, code: 'unavailable' };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
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, onSave) {
|
|
56
|
+
const text = (key) => desktopAgentText(key, locale);
|
|
57
|
+
const make = (tag, className, content) => {
|
|
58
|
+
const node = doc.createElement(tag);
|
|
59
|
+
if (className)
|
|
60
|
+
node.className = className;
|
|
61
|
+
if (content)
|
|
62
|
+
node.textContent = content;
|
|
63
|
+
return node;
|
|
64
|
+
};
|
|
65
|
+
const button = (key, action) => {
|
|
66
|
+
const node = make('button', styles.aiAgentDialogButton, text(key));
|
|
67
|
+
node.type = 'button';
|
|
68
|
+
node.addEventListener('click', action);
|
|
69
|
+
return node;
|
|
70
|
+
};
|
|
71
|
+
const field = (key, input) => {
|
|
72
|
+
const label = make('label', styles.aiAgentDialogField, text(key));
|
|
73
|
+
label.append(input);
|
|
74
|
+
return label;
|
|
75
|
+
};
|
|
76
|
+
const list = make('div', styles.aiAgentDialogList);
|
|
77
|
+
const status = make('p', styles.aiAgentDialogNote);
|
|
78
|
+
status.setAttribute('role', 'status');
|
|
79
|
+
const section = make('fieldset', styles.aiAgentDialogSection);
|
|
80
|
+
let entries = [];
|
|
81
|
+
let saved = { revision: null, entries: [] };
|
|
82
|
+
let context = null;
|
|
83
|
+
const previews = new Map();
|
|
84
|
+
const run = async (request, done) => {
|
|
85
|
+
const focused = doc.activeElement;
|
|
86
|
+
section.disabled = true;
|
|
87
|
+
status.textContent = '';
|
|
88
|
+
const result = await agentRequest(request);
|
|
89
|
+
if (!section.isConnected)
|
|
90
|
+
return;
|
|
91
|
+
section.disabled = false;
|
|
92
|
+
if ('code' in result)
|
|
93
|
+
status.textContent = desktopAgentError(result.code, locale);
|
|
94
|
+
else
|
|
95
|
+
done(result.value);
|
|
96
|
+
if (doc.activeElement === doc.body && focused?.isConnected && section.contains(focused))
|
|
97
|
+
focused.focus();
|
|
98
|
+
};
|
|
99
|
+
const contextSummary = make('p', styles.aiAgentDialogNote);
|
|
100
|
+
contextSummary.style.overflowWrap = 'anywhere';
|
|
101
|
+
const refreshPreviews = () => {
|
|
102
|
+
contextSummary.textContent = ['projectFolder', 'repository', 'branch']
|
|
103
|
+
.map(key => `${text(key)} ${context?.[key] ?? '—'}`).join(' · ');
|
|
104
|
+
previews.forEach(render => render());
|
|
105
|
+
};
|
|
106
|
+
const chooseContext = (kind) => {
|
|
107
|
+
void run(() => port.chooseContext(kind), value => {
|
|
108
|
+
if (value)
|
|
109
|
+
context = value;
|
|
110
|
+
refreshPreviews();
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const add = button('add', () => {
|
|
114
|
+
const entry = { id: globalThis.crypto.randomUUID(), name: '', application: '', args: [], cwd: defaultDirectory };
|
|
115
|
+
entries.push(entry);
|
|
116
|
+
render();
|
|
117
|
+
list.lastElementChild?.querySelector('input')?.focus();
|
|
118
|
+
});
|
|
119
|
+
const toDraft = ({ id, name, args, cwd, selection, url }) => ({ id, name, args, cwd, ...(selection ? { selection } : {}), ...(url?.trim() ? { url: url.trim() } : {}) });
|
|
120
|
+
const save = button('save', () => {
|
|
121
|
+
if (entries.some(entry => !entry.name.trim() || !entry.application)) {
|
|
122
|
+
status.textContent = text('invalid');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
void run(() => port.save(saved.revision, entries.map(toDraft)), value => {
|
|
126
|
+
saved = value;
|
|
127
|
+
entries = value.entries.map(entry => ({ ...entry }));
|
|
128
|
+
render();
|
|
129
|
+
status.textContent = text('saved');
|
|
130
|
+
onSave?.();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
function render() {
|
|
134
|
+
previews.clear();
|
|
135
|
+
list.replaceChildren();
|
|
136
|
+
for (const [index, entry] of entries.entries()) {
|
|
137
|
+
const row = make('div', styles.aiAgentDialogRow);
|
|
138
|
+
row.setAttribute('role', 'group');
|
|
139
|
+
row.setAttribute('aria-label', entry.name || text('application'));
|
|
140
|
+
const name = make('input');
|
|
141
|
+
name.maxLength = 120;
|
|
142
|
+
name.value = entry.name;
|
|
143
|
+
name.oninput = () => {
|
|
144
|
+
entry.name = name.value;
|
|
145
|
+
row.setAttribute('aria-label', entry.name || text('application'));
|
|
146
|
+
};
|
|
147
|
+
const application = make('p', styles.aiAgentDialogNote, entry.application || text('unselected'));
|
|
148
|
+
const choose = button('choose', () => {
|
|
149
|
+
void run(() => port.chooseApp(), value => {
|
|
150
|
+
if (value)
|
|
151
|
+
Object.assign(entry, value);
|
|
152
|
+
application.textContent = entry.application || text('unselected');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
choose.setAttribute('aria-label', `${text('application')} ${text('choose')}`);
|
|
156
|
+
const args = make('textarea');
|
|
157
|
+
args.rows = 3;
|
|
158
|
+
args.value = entry.args.join('\n');
|
|
159
|
+
const cwd = make('input');
|
|
160
|
+
cwd.placeholder = defaultDirectory;
|
|
161
|
+
cwd.maxLength = 1024;
|
|
162
|
+
cwd.value = entry.cwd;
|
|
163
|
+
const url = make('input');
|
|
164
|
+
url.type = 'url';
|
|
165
|
+
url.maxLength = 2048;
|
|
166
|
+
url.value = entry.url ?? '';
|
|
167
|
+
url.oninput = () => { entry.url = url.value; };
|
|
168
|
+
const preview = make('p', styles.aiAgentDialogNote);
|
|
169
|
+
const updatePreview = () => {
|
|
170
|
+
const expand = (value) => value.replace(variables, (match, key) => context?.[key] ?? match);
|
|
171
|
+
const directory = (entry.cwd.trim() || defaultDirectory);
|
|
172
|
+
preview.textContent = `${text('preview')} ${JSON.stringify(entry.args.map(expand))}\n${text('cwd')} ${directory === defaultDirectory && !context?.projectFolder ? '—' : expand(directory)}`;
|
|
173
|
+
};
|
|
174
|
+
preview.style.whiteSpace = 'pre-wrap';
|
|
175
|
+
preview.style.overflowWrap = 'anywhere';
|
|
176
|
+
previews.set(entry.id, updatePreview);
|
|
177
|
+
updatePreview();
|
|
178
|
+
args.oninput = () => {
|
|
179
|
+
entry.args = args.value ? args.value.split('\n') : [];
|
|
180
|
+
updatePreview();
|
|
181
|
+
};
|
|
182
|
+
cwd.oninput = () => {
|
|
183
|
+
entry.cwd = cwd.value;
|
|
184
|
+
updatePreview();
|
|
185
|
+
};
|
|
186
|
+
const move = (offset) => {
|
|
187
|
+
entries.splice(index, 1);
|
|
188
|
+
entries.splice(index + offset, 0, entry);
|
|
189
|
+
render();
|
|
190
|
+
list.children[index + offset].querySelector('input')?.focus();
|
|
191
|
+
};
|
|
192
|
+
const up = button('up', () => move(-1));
|
|
193
|
+
const down = button('down', () => move(1));
|
|
194
|
+
up.disabled = index === 0;
|
|
195
|
+
down.disabled = index === entries.length - 1;
|
|
196
|
+
const remove = button('remove', () => {
|
|
197
|
+
entries.splice(index, 1);
|
|
198
|
+
render();
|
|
199
|
+
(list.children[Math.min(index, entries.length - 1)]?.querySelector('input') ?? add).focus();
|
|
200
|
+
});
|
|
201
|
+
const tryLaunch = button('test', () => {
|
|
202
|
+
const original = saved.entries.find(item => item.id === entry.id);
|
|
203
|
+
if (!original || JSON.stringify(toDraft(original)) !== JSON.stringify(toDraft(entry))) {
|
|
204
|
+
status.textContent = text('saveFirst');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
void run(() => port.launch(entry.id), () => { status.textContent = text('launched'); });
|
|
208
|
+
});
|
|
209
|
+
row.append(field('name', name), application, choose, field('args', args), field('cwd', cwd), preview, field('url', url), up, down, remove, tryLaunch);
|
|
210
|
+
list.append(row);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
section.addEventListener('keydown', event => {
|
|
214
|
+
if (event.key === 'Enter' && event.target.tagName === 'INPUT')
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
});
|
|
217
|
+
section.append(make('legend', undefined, text('section')), make('p', styles.aiAgentDialogNote, text('variables')), button('chooseProject', () => chooseContext('project')), button('chooseRepository', () => chooseContext('repository')), contextSummary, list, add, save, status);
|
|
218
|
+
section.disabled = true;
|
|
219
|
+
// The dialog attaches this section to the document before the requests resolve.
|
|
220
|
+
void Promise.all([agentRequest(() => port.list()), agentRequest(() => port.context())]).then(([settings, current]) => {
|
|
221
|
+
if (!section.isConnected)
|
|
222
|
+
return;
|
|
223
|
+
if ('code' in settings) {
|
|
224
|
+
status.textContent = desktopAgentError(settings.code, locale);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
saved = settings.value;
|
|
228
|
+
entries = saved.entries.map(entry => ({ ...entry }));
|
|
229
|
+
if ('value' in current)
|
|
230
|
+
context = current.value;
|
|
231
|
+
refreshPreviews();
|
|
232
|
+
section.disabled = false;
|
|
233
|
+
render();
|
|
234
|
+
});
|
|
235
|
+
return section;
|
|
236
|
+
}
|
|
@@ -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
|
|
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
|
-
|
|
17
|
-
|
|
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;
|
package/dist/drawer-views.d.ts
CHANGED
|
@@ -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;
|
package/dist/drawer-views.js
CHANGED
|
@@ -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:
|
|
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
|
|
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)),
|
|
150
|
-
menu
|
|
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)
|
package/dist/sprite-tabs.js
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
|
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
|
|
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
|
-
|
|
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())
|