@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.
- package/dist/ai-agent-settings.d.ts +2 -1
- package/dist/ai-agent-settings.js +2 -2
- package/dist/ai-agents.d.ts +6 -1
- package/dist/ai-agents.js +32 -21
- package/dist/desktop-ai-agents.d.ts +1 -1
- package/dist/desktop-ai-agents.js +2 -1
- 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 +3 -2
- package/src/ai-agents.ts +30 -18
- package/src/desktop-ai-agents.ts +3 -1
- package/src/document-workspace.ts +52 -3
- package/src/drawer-views.ts +17 -6
- package/src/editor.css +41 -11
- package/src/sprite-tabs.ts +82 -11
- package/src/standard-layout.ts +85 -31
package/src/sprite-tabs.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {SpriteSearchResult} from '@kubohiroya/turbowarp-plus-editor-sprite-
|
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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();
|
package/src/standard-layout.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {createLayout, createSplitter, splitAxis} from './index.ts';
|
|
2
2
|
import {createTargetList} from './targets.ts';
|
|
3
|
-
import type {DrawerViews} from './drawer-views.ts';
|
|
4
|
-
import {availableDrawerViews, createDrawerViewBar, drawerPinIcon, hasDrawerBar, readDrawerView, writeDrawerView} from './drawer-views.ts';
|
|
3
|
+
import type {DrawerView, DrawerViews} from './drawer-views.ts';
|
|
4
|
+
import {availableDrawerViews, createDrawerViewBar, drawerLabel, drawerPinIcon, hasDrawerBar, readDrawerView, writeDrawerView} from './drawer-views.ts';
|
|
5
5
|
import {attachStageDrawerDrag} from './stage-drawer-drag.ts';
|
|
6
6
|
import type {StageDrawerLayout, StageDrawerPosition} from './workspace-layout.ts';
|
|
7
7
|
|
|
@@ -15,7 +15,16 @@ const drawerViewWidth = 300;
|
|
|
15
15
|
const minimumDrawerViewWidth = 160;
|
|
16
16
|
const minimumStandardEditor = 380;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
type DrawerPanel = (props: {
|
|
19
|
+
id: DrawerView['id'];
|
|
20
|
+
title: string;
|
|
21
|
+
locale: string;
|
|
22
|
+
dockRequest: number;
|
|
23
|
+
renderHeading(undock: import('react').ReactNode): import('react').ReactNode;
|
|
24
|
+
renderContent(detached: boolean): import('react').ReactNode;
|
|
25
|
+
}) => import('react').ReactNode;
|
|
26
|
+
|
|
27
|
+
export function createStandardLayout(React, {styles, targetStyles, context, LayoutMenu, DrawerPanel = undefined as DrawerPanel | undefined}) {
|
|
19
28
|
const {createElement: element, useContext, useLayoutEffect, useRef, useState} = React;
|
|
20
29
|
const SplitLayout = createLayout(React);
|
|
21
30
|
const Splitter = createSplitter(React);
|
|
@@ -44,12 +53,17 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
44
53
|
const hostDrawerViews = availableDrawerViews(drawerViews);
|
|
45
54
|
// A view saved earlier comes back once the host supplies it again.
|
|
46
55
|
const drawerView = hostDrawerViews.some(view => view.id === preferredDrawerView) ? preferredDrawerView : 'sprites';
|
|
47
|
-
const selectDrawerView = view => {
|
|
56
|
+
const selectDrawerView = React.useCallback(view => {
|
|
48
57
|
setPreferredDrawerView(view);
|
|
49
58
|
writeDrawerView(props.storage, props.storageKey, view);
|
|
50
|
-
};
|
|
59
|
+
}, [props.storage, props.storageKey]);
|
|
51
60
|
const body = useRef(null);
|
|
52
61
|
const plusLayout = enabled && !props.fullscreen;
|
|
62
|
+
const reportDrawerSelection = drawerViews?.onSelectionChange;
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
reportDrawerSelection?.(plusLayout ? drawerView : 'sprites');
|
|
65
|
+
return () => reportDrawerSelection?.('sprites');
|
|
66
|
+
}, [reportDrawerSelection, plusLayout, drawerView]);
|
|
53
67
|
const stageHidden = plusLayout && !showStage;
|
|
54
68
|
const stageDrawerPinned = updateStageDrawer ? stageDrawerLayout?.pinned !== false : localStageDrawerPinned;
|
|
55
69
|
const setStageDrawerPinned = (pinned: boolean) => {
|
|
@@ -398,11 +412,21 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
398
412
|
function TargetLayout({compact, render}) {
|
|
399
413
|
const {plusLayout, targetsPinned, locale, drawerViews, drawerView = 'sprites', selectDrawerView} = useContext(context);
|
|
400
414
|
const tools = useState(null);
|
|
415
|
+
const focusDrawer = useRef(null);
|
|
416
|
+
const [reveal, setReveal] = useState(null as {id: DrawerView['id']; request: number} | null);
|
|
417
|
+
useLayoutEffect(() => {
|
|
418
|
+
if (!plusLayout) return;
|
|
419
|
+
return drawerViews?.registerReveal?.(id => {
|
|
420
|
+
selectDrawerView(id);
|
|
421
|
+
setReveal(previous => ({id, request: (previous?.request ?? 0) + 1}));
|
|
422
|
+
focusDrawer.current?.();
|
|
423
|
+
});
|
|
424
|
+
}, [plusLayout, drawerViews, selectDrawerView]);
|
|
401
425
|
const panel = render(plusLayout || compact);
|
|
402
426
|
if (!plusLayout) return panel;
|
|
403
427
|
const content = element(targetTools.Provider, {value: tools}, panel);
|
|
404
428
|
const drawer = children => element(EdgeDrawer, {
|
|
405
|
-
edge: 'left', pinned: targetsPinned,
|
|
429
|
+
edge: 'left', pinned: targetsPinned, focusPanelRef: focusDrawer,
|
|
406
430
|
label: isJapanese(locale) ? 'スプライト一覧を展開' : 'Reveal sprite list'
|
|
407
431
|
}, children);
|
|
408
432
|
// Without host views the drawer keeps the sprite list as its only, unwrapped content.
|
|
@@ -412,14 +436,10 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
412
436
|
return drawer(element(React.Fragment, null,
|
|
413
437
|
element(DrawerViewBar, {locale, views, agents: drawerViews.agents, selected: active ? active.id : 'sprites',
|
|
414
438
|
onSelect: selectDrawerView}),
|
|
415
|
-
// Pinning belongs to the drawer, so every view keeps the pin button the sprite list shows.
|
|
416
|
-
active && element('div', {className: styles.drawerViewTools},
|
|
417
|
-
active.tools?.({locale}),
|
|
418
|
-
element(DrawerPinButton, {label: isJapanese(locale) ? 'このパネルを固定表示' : 'Pin this panel'})),
|
|
419
439
|
// The GUI's target pane stays mounted, so its file inputs and library keep working while hidden.
|
|
420
440
|
element('div', {className: styles.drawerSprites, hidden: Boolean(active)}, content),
|
|
421
|
-
|
|
422
|
-
|
|
441
|
+
views.map(view => element(HostDrawerView, {key: view.id, view, locale, active: view === active,
|
|
442
|
+
dockRequest: reveal?.id === view.id ? reveal.request : 0}))));
|
|
423
443
|
}
|
|
424
444
|
|
|
425
445
|
function SpriteGrid(props) {
|
|
@@ -469,16 +489,11 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
469
489
|
drawerPinIcon(element, targetsPinned));
|
|
470
490
|
}
|
|
471
491
|
|
|
472
|
-
function
|
|
473
|
-
const {locale} = useContext(context);
|
|
474
|
-
const [mount] = useContext(targetTools) ?? [];
|
|
492
|
+
function useDrawerTools(searchLabel?: string) {
|
|
475
493
|
const [searching, setSearching] = useState(false);
|
|
476
494
|
const [query, setQuery] = useState('');
|
|
477
495
|
const searchButton = useRef(null);
|
|
478
496
|
const searchInput = useRef(null);
|
|
479
|
-
const japanese = isJapanese(locale);
|
|
480
|
-
const pinLabel = japanese ? 'スプライト一覧を固定表示' : 'Pin sprite list';
|
|
481
|
-
const searchLabel = japanese ? 'スプライトを検索' : 'Search sprites';
|
|
482
497
|
useLayoutEffect(() => {
|
|
483
498
|
if (searching) searchInput.current?.focus({preventScroll: true});
|
|
484
499
|
}, [searching]);
|
|
@@ -487,18 +502,20 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
487
502
|
setQuery('');
|
|
488
503
|
searchButton.current?.focus();
|
|
489
504
|
};
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
element('
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
505
|
+
const render = ({label, pinLabel, openAction, tools}: {
|
|
506
|
+
label: string; pinLabel?: string; openAction?: import('react').ReactNode; tools?: import('react').ReactNode;
|
|
507
|
+
}) => element(React.Fragment, null,
|
|
508
|
+
element('div', {className: styles.targetListTools, role: 'group', 'aria-label': label},
|
|
509
|
+
tools,
|
|
510
|
+
searchLabel && element('button', {type: 'button', ref: searchButton, 'aria-label': searchLabel,
|
|
511
|
+
'aria-expanded': searching, title: searchLabel, onClick: () => searching ? closeSearch() : setSearching(true)},
|
|
512
|
+
element('svg', {'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
|
|
513
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round'},
|
|
514
|
+
element('circle', {cx: 6.5, cy: 6.5, r: 4}), element('path', {d: 'm9.5 9.5 4 4'}))),
|
|
515
|
+
pinLabel && element(DrawerPinButton, {label: pinLabel}),
|
|
516
|
+
openAction),
|
|
517
|
+
searching && element('input', {type: 'search', className: styles.targetListSearch,
|
|
518
|
+
'aria-label': searchLabel, ref: searchInput, placeholder: searchLabel, value: query,
|
|
502
519
|
onChange: event => setQuery(event.currentTarget.value),
|
|
503
520
|
onKeyDown: event => {
|
|
504
521
|
if (event.key === 'Escape') {
|
|
@@ -506,8 +523,45 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
506
523
|
closeSearch();
|
|
507
524
|
}
|
|
508
525
|
}}));
|
|
526
|
+
return {query, render};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function HostDrawerView({view, locale, active, dockRequest}: {
|
|
530
|
+
view: DrawerView; locale: string; active: boolean; dockRequest: number;
|
|
531
|
+
}) {
|
|
532
|
+
const title = view.label ?? drawerLabel(view.id, locale);
|
|
533
|
+
const japanese = isJapanese(locale);
|
|
534
|
+
const label = japanese ? `${title}の操作` : `${title} tools`;
|
|
535
|
+
const {query, render} = useDrawerTools(view.searchLabel?.(locale));
|
|
536
|
+
const renderHeading = openAction => render({
|
|
537
|
+
label,
|
|
538
|
+
pinLabel: japanese ? 'このパネルを固定表示' : 'Pin this panel',
|
|
539
|
+
openAction,
|
|
540
|
+
tools: view.tools?.({locale, query})
|
|
541
|
+
});
|
|
542
|
+
const renderContent = detached => (active || detached) && element('div', {
|
|
543
|
+
className: styles.drawerViewContent, 'data-drawer-content': view.id
|
|
544
|
+
},
|
|
545
|
+
detached && view.searchLabel && render({label}),
|
|
546
|
+
view.render({locale, query}));
|
|
547
|
+
if (!DrawerPanel && !active) return null;
|
|
548
|
+
return element('div', {className: styles.drawerHostView, hidden: !active}, DrawerPanel ?
|
|
549
|
+
element(DrawerPanel, {id: view.id, title, locale, dockRequest, renderHeading, renderContent}) :
|
|
550
|
+
element(React.Fragment, null, renderHeading(null), renderContent(false)));
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function useSpriteListTools() {
|
|
554
|
+
const {locale} = useContext(context);
|
|
555
|
+
const [mount] = useContext(targetTools) ?? [];
|
|
556
|
+
const japanese = isJapanese(locale);
|
|
557
|
+
const {query, render} = useDrawerTools(japanese ? 'スプライトを検索' : 'Search sprites');
|
|
509
558
|
return {
|
|
510
|
-
mount, query,
|
|
559
|
+
mount, query,
|
|
560
|
+
renderTools: openAction => render({
|
|
561
|
+
label: japanese ? 'スプライト一覧の操作' : 'Sprite list tools',
|
|
562
|
+
pinLabel: japanese ? 'スプライト一覧を固定表示' : 'Pin sprite list',
|
|
563
|
+
openAction
|
|
564
|
+
}),
|
|
511
565
|
title: japanese ? 'スプライト一覧' : 'Sprite list',
|
|
512
566
|
openLabel: japanese ? 'アンドック' : 'Undock sprite list'
|
|
513
567
|
};
|