@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.
@@ -1,6 +1,6 @@
1
1
  import { createLayout, createSplitter, splitAxis } from "./index.js";
2
2
  import { createTargetList } from "./targets.js";
3
- import { availableDrawerViews, createDrawerViewBar, drawerPinIcon, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
3
+ import { availableDrawerViews, createDrawerViewBar, drawerLabel, drawerPinIcon, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
4
4
  import { attachStageDrawerDrag } from "./stage-drawer-drag.js";
5
5
  const isJapanese = locale => /^ja(?:-|$)/i.test(locale);
6
6
  const singleColumnTargetWidth = 108;
@@ -8,7 +8,7 @@ const singleColumnTargetWidth = 108;
8
8
  const drawerViewWidth = 300;
9
9
  const minimumDrawerViewWidth = 160;
10
10
  const minimumStandardEditor = 380;
11
- export function createStandardLayout(React, { styles, targetStyles, context, LayoutMenu }) {
11
+ export function createStandardLayout(React, { styles, targetStyles, context, LayoutMenu, DrawerPanel = undefined }) {
12
12
  const { createElement: element, useContext, useLayoutEffect, useRef, useState } = React;
13
13
  const SplitLayout = createLayout(React);
14
14
  const Splitter = createSplitter(React);
@@ -31,12 +31,17 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
31
31
  const hostDrawerViews = availableDrawerViews(drawerViews);
32
32
  // A view saved earlier comes back once the host supplies it again.
33
33
  const drawerView = hostDrawerViews.some(view => view.id === preferredDrawerView) ? preferredDrawerView : 'sprites';
34
- const selectDrawerView = view => {
34
+ const selectDrawerView = React.useCallback(view => {
35
35
  setPreferredDrawerView(view);
36
36
  writeDrawerView(props.storage, props.storageKey, view);
37
- };
37
+ }, [props.storage, props.storageKey]);
38
38
  const body = useRef(null);
39
39
  const plusLayout = enabled && !props.fullscreen;
40
+ const reportDrawerSelection = drawerViews?.onSelectionChange;
41
+ useLayoutEffect(() => {
42
+ reportDrawerSelection?.(plusLayout ? drawerView : 'sprites');
43
+ return () => reportDrawerSelection?.('sprites');
44
+ }, [reportDrawerSelection, plusLayout, drawerView]);
40
45
  const stageHidden = plusLayout && !showStage;
41
46
  const stageDrawerPinned = updateStageDrawer ? stageDrawerLayout?.pinned !== false : localStageDrawerPinned;
42
47
  const setStageDrawerPinned = (pinned) => {
@@ -385,12 +390,23 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
385
390
  function TargetLayout({ compact, render }) {
386
391
  const { plusLayout, targetsPinned, locale, drawerViews, drawerView = 'sprites', selectDrawerView } = useContext(context);
387
392
  const tools = useState(null);
393
+ const focusDrawer = useRef(null);
394
+ const [reveal, setReveal] = useState(null);
395
+ useLayoutEffect(() => {
396
+ if (!plusLayout)
397
+ return;
398
+ return drawerViews?.registerReveal?.(id => {
399
+ selectDrawerView(id);
400
+ setReveal(previous => ({ id, request: (previous?.request ?? 0) + 1 }));
401
+ focusDrawer.current?.();
402
+ });
403
+ }, [plusLayout, drawerViews, selectDrawerView]);
388
404
  const panel = render(plusLayout || compact);
389
405
  if (!plusLayout)
390
406
  return panel;
391
407
  const content = element(targetTools.Provider, { value: tools }, panel);
392
408
  const drawer = children => element(EdgeDrawer, {
393
- edge: 'left', pinned: targetsPinned,
409
+ edge: 'left', pinned: targetsPinned, focusPanelRef: focusDrawer,
394
410
  label: isJapanese(locale) ? 'スプライト一覧を展開' : 'Reveal sprite list'
395
411
  }, children);
396
412
  // Without host views the drawer keeps the sprite list as its only, unwrapped content.
@@ -400,10 +416,9 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
400
416
  const active = views.find(view => view.id === drawerView);
401
417
  return drawer(element(React.Fragment, null, element(DrawerViewBar, { locale, views, agents: drawerViews.agents, selected: active ? active.id : 'sprites',
402
418
  onSelect: selectDrawerView }),
403
- // Pinning belongs to the drawer, so every view keeps the pin button the sprite list shows.
404
- active && element('div', { className: styles.drawerViewTools }, active.tools?.({ locale }), element(DrawerPinButton, { label: isJapanese(locale) ? 'このパネルを固定表示' : 'Pin this panel' })),
405
419
  // The GUI's target pane stays mounted, so its file inputs and library keep working while hidden.
406
- element('div', { className: styles.drawerSprites, hidden: Boolean(active) }, content), active && element('div', { className: styles.drawerViewContent, 'data-drawer-content': active.id }, active.render({ locale }))));
420
+ element('div', { className: styles.drawerSprites, hidden: Boolean(active) }, content), views.map(view => element(HostDrawerView, { key: view.id, view, locale, active: view === active,
421
+ dockRequest: reveal?.id === view.id ? reveal.request : 0 }))));
407
422
  }
408
423
  function SpriteGrid(props) {
409
424
  const { plusLayout } = useContext(context);
@@ -443,16 +458,11 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
443
458
  return element('button', { type: 'button', className: styles.drawerPin, 'aria-label': label, 'aria-pressed': targetsPinned,
444
459
  title: label, onClick: () => setTargetsPinned(value => !value) }, drawerPinIcon(element, targetsPinned));
445
460
  }
446
- function useSpriteListTools() {
447
- const { locale } = useContext(context);
448
- const [mount] = useContext(targetTools) ?? [];
461
+ function useDrawerTools(searchLabel) {
449
462
  const [searching, setSearching] = useState(false);
450
463
  const [query, setQuery] = useState('');
451
464
  const searchButton = useRef(null);
452
465
  const searchInput = useRef(null);
453
- const japanese = isJapanese(locale);
454
- const pinLabel = japanese ? 'スプライト一覧を固定表示' : 'Pin sprite list';
455
- const searchLabel = japanese ? 'スプライトを検索' : 'Search sprites';
456
466
  useLayoutEffect(() => {
457
467
  if (searching)
458
468
  searchInput.current?.focus({ preventScroll: true });
@@ -462,11 +472,10 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
462
472
  setQuery('');
463
473
  searchButton.current?.focus();
464
474
  };
465
- const renderTools = openAction => element(React.Fragment, null, element('div', { className: styles.targetListTools, role: 'group',
466
- 'aria-label': japanese ? 'スプライト一覧の操作' : 'Sprite list tools' }, element('button', { type: 'button', ref: searchButton, 'aria-label': searchLabel, 'aria-expanded': searching,
467
- title: searchLabel, onClick: () => searching ? closeSearch() : setSearching(true) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
468
- fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }, element('circle', { cx: 6.5, cy: 6.5, r: 4 }), element('path', { d: 'm9.5 9.5 4 4' }))), element(DrawerPinButton, { label: pinLabel }), openAction), searching && element('input', { type: 'search', className: styles.targetListSearch, 'aria-label': searchLabel,
469
- ref: searchInput, placeholder: japanese ? '名前' : 'Name', value: query,
475
+ const render = ({ label, pinLabel, openAction, tools }) => element(React.Fragment, null, element('div', { className: styles.targetListTools, role: 'group', 'aria-label': label }, tools, searchLabel && element('button', { type: 'button', ref: searchButton, 'aria-label': searchLabel,
476
+ 'aria-expanded': searching, title: searchLabel, onClick: () => searching ? closeSearch() : setSearching(true) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
477
+ fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }, element('circle', { cx: 6.5, cy: 6.5, r: 4 }), element('path', { d: 'm9.5 9.5 4 4' }))), pinLabel && element(DrawerPinButton, { label: pinLabel }), openAction), searching && element('input', { type: 'search', className: styles.targetListSearch,
478
+ 'aria-label': searchLabel, ref: searchInput, placeholder: searchLabel, value: query,
470
479
  onChange: event => setQuery(event.currentTarget.value),
471
480
  onKeyDown: event => {
472
481
  if (event.key === 'Escape') {
@@ -474,8 +483,40 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
474
483
  closeSearch();
475
484
  }
476
485
  } }));
486
+ return { query, render };
487
+ }
488
+ function HostDrawerView({ view, locale, active, dockRequest }) {
489
+ const title = view.label ?? drawerLabel(view.id, locale);
490
+ const japanese = isJapanese(locale);
491
+ const label = japanese ? `${title}の操作` : `${title} tools`;
492
+ const { query, render } = useDrawerTools(view.searchLabel?.(locale));
493
+ const renderHeading = openAction => render({
494
+ label,
495
+ pinLabel: japanese ? 'このパネルを固定表示' : 'Pin this panel',
496
+ openAction,
497
+ tools: view.tools?.({ locale, query })
498
+ });
499
+ const renderContent = detached => (active || detached) && element('div', {
500
+ className: styles.drawerViewContent, 'data-drawer-content': view.id
501
+ }, detached && view.searchLabel && render({ label }), view.render({ locale, query }));
502
+ if (!DrawerPanel && !active)
503
+ return null;
504
+ return element('div', { className: styles.drawerHostView, hidden: !active }, DrawerPanel ?
505
+ element(DrawerPanel, { id: view.id, title, locale, dockRequest, renderHeading, renderContent }) :
506
+ element(React.Fragment, null, renderHeading(null), renderContent(false)));
507
+ }
508
+ function useSpriteListTools() {
509
+ const { locale } = useContext(context);
510
+ const [mount] = useContext(targetTools) ?? [];
511
+ const japanese = isJapanese(locale);
512
+ const { query, render } = useDrawerTools(japanese ? 'スプライトを検索' : 'Search sprites');
477
513
  return {
478
- mount, query, renderTools,
514
+ mount, query,
515
+ renderTools: openAction => render({
516
+ label: japanese ? 'スプライト一覧の操作' : 'Sprite list tools',
517
+ pinLabel: japanese ? 'スプライト一覧を固定表示' : 'Pin sprite list',
518
+ openAction
519
+ }),
479
520
  title: japanese ? 'スプライト一覧' : 'Sprite list',
480
521
  openLabel: japanese ? 'アンドック' : 'Undock sprite list'
481
522
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-workbench",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "The TurboWarp Plus Editor workbench: layout, dockable sprite tabs, stage, debugger tab and file menu",
5
5
  "type": "module",
6
6
  "license": "MPL-2.0",
@@ -176,6 +176,7 @@ export interface AgentSettingsDialogOptions {
176
176
  returnFocus?: HTMLElement | null;
177
177
  onSave?(settings: AgentSettings): void;
178
178
  desktop?: DesktopAiAgentsPort | null;
179
+ onDesktopSave?(): void;
179
180
  }
180
181
 
181
182
  export interface AgentSettingsDialog {
@@ -201,7 +202,7 @@ const urlProblems = {empty: 'urlEmpty', invalid: 'urlInvalid', 'not-https': 'url
201
202
  * user's own services. It is plain DOM so that any part of the Editor can open it, with or without React.
202
203
  */
203
204
  export function openAgentSettingsDialog({document: doc = globalThis.document, locale, styles = {}, storage = browserStorage(),
204
- storageKey = agentSettingsKey, returnFocus, onSave, desktop}: AgentSettingsDialogOptions): AgentSettingsDialog {
205
+ storageKey = agentSettingsKey, returnFocus, onSave, desktop, onDesktopSave}: AgentSettingsDialogOptions): AgentSettingsDialog {
205
206
  if (openDialog?.element.isConnected) {
206
207
  (openDialog.element.querySelector(focusable) as HTMLElement)?.focus();
207
208
  return openDialog;
@@ -306,7 +307,7 @@ export function openAgentSettingsDialog({document: doc = globalThis.document, lo
306
307
  const save = make('button', {type: 'submit', class: `${styles.aiAgentDialogButton ?? ''} ${styles.aiAgentDialogPrimary ?? ''}`.trim()},
307
308
  text('save'));
308
309
  const form = make('form', {novalidate: '', class: styles.aiAgentDialogForm}, presetGroup, customGroup,
309
- desktop && desktopAgentSettings(doc, desktop, locale, styles), status,
310
+ desktop && desktopAgentSettings(doc, desktop, locale, styles, onDesktopSave), status,
310
311
  make('div', {class: styles.aiAgentDialogActions}, cancel, save));
311
312
  const element = make('div', {
312
313
  role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': `${prefix}-title`,
package/src/ai-agents.ts CHANGED
@@ -48,21 +48,28 @@ export function createAiAgents(React, {styles = {}, storage = browserStorage(),
48
48
  };
49
49
  const settingsIcon = () => svg(element('path', {d: agentsIconPath}));
50
50
 
51
- const openSettings = ({locale, returnFocus}: {locale: string; returnFocus?: HTMLElement | null}) =>
52
- openAgentSettingsDialog({document, locale, styles, storage, storageKey, returnFocus, desktop});
51
+ const openSettings = ({locale, returnFocus, onSave, onDesktopSave}: {
52
+ locale: string; returnFocus?: HTMLElement | null; onSave?: () => void; onDesktopSave?: () => void;
53
+ }) => openAgentSettingsDialog({document: returnFocus?.ownerDocument ?? document, locale, styles, storage,
54
+ storageKey, returnFocus, onSave, desktop, onDesktopSave});
53
55
 
54
- function AgentMenu({locale, close}: DrawerMenuRenderProps) {
55
- const [services] = useState(() => enabledAgentServices(readAgentSettings(storage, storageKey)));
56
+ function AgentList({locale, close}: Omit<DrawerMenuRenderProps, 'close'> & {close?: () => void}) {
57
+ const [services, setServices] = useState(() => enabledAgentServices(readAgentSettings(storage, storageKey)));
56
58
  const [applications, setApplications] = useState([] as DesktopAgent[]);
57
59
  const [error, setError] = useState(null as {code: string; url?: string} | null);
58
60
  const active = useRef(true);
61
+ const refreshApplications = async () => {
62
+ if (!desktop) return;
63
+ const result = await agentRequest(() => desktop.list());
64
+ if (!active.current) return;
65
+ if ('value' in result) {
66
+ setApplications(result.value.entries);
67
+ setError(null);
68
+ } else setError({code: result.code});
69
+ };
59
70
  useEffect(() => {
60
71
  active.current = true;
61
- if (desktop) void agentRequest(() => desktop.list()).then(result => {
62
- if (!active.current) return;
63
- if ('value' in result) setApplications(result.value.entries);
64
- else setError({code: result.code});
65
- });
72
+ void refreshApplications();
66
73
  return () => { active.current = false; };
67
74
  }, []);
68
75
  const list = useRef(null);
@@ -83,14 +90,14 @@ export function createAiAgents(React, {styles = {}, storage = browserStorage(),
83
90
  items[next]?.focus();
84
91
  };
85
92
  const item = (key: string, icon, text: string, onClick: () => void, title?: string) => element('button', {
86
- key, type: 'button', role: 'menuitem', tabIndex: -1, className: styles.aiAgentMenuItem, title, onClick
93
+ key, type: 'button', role: close ? 'menuitem' : undefined, tabIndex: close ? -1 : undefined, className: styles.aiAgentMenuItem, title, onClick
87
94
  }, icon, element('span', null, text));
88
95
  const hasEntries = services.length + applications.length > 0;
89
96
  const launch = async (application: DesktopAgent) => {
90
97
  setError(null);
91
98
  const result = await agentRequest(() => desktop.launch(application.id));
92
99
  if (!active.current) return;
93
- if ('value' in result) close();
100
+ if ('value' in result) close?.();
94
101
  else {
95
102
  const checked = checkAgentUrl(application.url);
96
103
  setError({code: result.code, ...('url' in checked ? checked : {})});
@@ -100,30 +107,35 @@ export function createAiAgents(React, {styles = {}, storage = browserStorage(),
100
107
  error && element('p', {role: 'alert', className: styles.aiAgentMenuHint}, desktopAgentError(error.code, locale)),
101
108
  !hasEntries && element('p', {id: hintId.current, className: styles.aiAgentMenuHint}, agentText('empty', locale)),
102
109
  element('div', {
103
- role: 'menu', 'aria-label': label, ref: list, className: styles.aiAgentMenu, onKeyDown: move,
110
+ role: close ? 'menu' : 'group', 'aria-label': label, ref: list, className: styles.aiAgentMenu,
111
+ onKeyDown: close ? move : undefined,
104
112
  'aria-describedby': hasEntries ? undefined : hintId.current
105
113
  },
106
114
  services.map(service => item(service.id, serviceIcon(service), service.name, () => {
107
115
  openAgentService(service, open);
108
- close();
116
+ close?.();
109
117
  }, newTab)),
110
118
  applications.map(application => item(`desktop-${application.id}`, settingsIcon(), application.name,
111
119
  () => void launch(application), desktopAgentText('opensApp', locale))),
112
120
  error?.url && item('fallback', serviceIcon(), desktopAgentText('openFallback', locale), () => {
113
121
  open(error.url, '_blank', 'noopener,noreferrer');
114
- close();
122
+ close?.();
115
123
  }, newTab),
116
124
  hasEntries && element('div', {role: 'separator', className: styles.aiAgentMenuSeparator}),
117
125
  item('settings', settingsIcon(), agentText('settings', locale), () => {
118
- close();
119
- openSettings({locale, returnFocus: document.activeElement as HTMLElement});
126
+ const doc = list.current.ownerDocument;
127
+ close?.();
128
+ openSettings({locale, returnFocus: doc.activeElement as HTMLElement,
129
+ onSave: close ? undefined : () => setServices(enabledAgentServices(readAgentSettings(storage, storageKey))),
130
+ onDesktopSave: close ? undefined : () => { void refreshApplications(); }});
120
131
  })));
121
132
  }
122
133
 
123
134
  const drawerMenu: DrawerMenu = {
124
- renderMenu: props => element(AgentMenu, props)
135
+ renderMenu: props => element(AgentList, props)
125
136
  };
126
- return {drawerMenu, openSettings, settingsIcon, serviceIcon};
137
+ return {drawerMenu, renderPanel: ({locale}: {locale: string}) => element(AgentList, {locale}),
138
+ openSettings, settingsIcon, serviceIcon};
127
139
  }
128
140
 
129
141
  let nextId = 0;
@@ -83,7 +83,8 @@ export async function agentRequest<T>(request: () => Promise<Result<T>>): Promis
83
83
  }
84
84
 
85
85
  /** An optional section of the existing settings dialog. Its changes are saved by the Desktop host. */
86
- export function desktopAgentSettings(doc: Document, port: DesktopAiAgentsPort, locale: string, styles: Record<string, string>) {
86
+ export function desktopAgentSettings(doc: Document, port: DesktopAiAgentsPort, locale: string,
87
+ styles: Record<string, string>, onSave?: () => void) {
87
88
  const text = (key: keyof typeof strings) => desktopAgentText(key, locale);
88
89
  const make = <K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, content?: string) => {
89
90
  const node = doc.createElement(tag);
@@ -153,6 +154,7 @@ export function desktopAgentSettings(doc: Document, port: DesktopAiAgentsPort, l
153
154
  entries = value.entries.map(entry => ({...entry}));
154
155
  render();
155
156
  status.textContent = text('saved');
157
+ onSave?.();
156
158
  });
157
159
  });
158
160
 
@@ -1,9 +1,24 @@
1
+ interface DocumentPanelSession {
2
+ requestClose(): void;
3
+ dispose(): void;
4
+ save?(): void | Promise<void>;
5
+ readonly fileEdit?: {
6
+ directory: FileSystemDirectoryHandle;
7
+ path: string;
8
+ isDirty(): boolean;
9
+ readUnsaved?(): Uint8Array | undefined;
10
+ save(): Promise<void>;
11
+ };
12
+ }
13
+
1
14
  export interface DocumentPanelRequest {
2
15
  reference: {providerId: string; documentId: string};
3
16
  filename: string;
4
17
  /** What the tab shows. Without it the tab names the file and where it comes from. */
5
18
  title?: string;
6
19
  transient?: boolean;
20
+ /** Keeps this utility tab first while the host enables the project folder drawer. */
21
+ pinWithProjectFolder?: boolean;
7
22
  /**
8
23
  * Opens the tab beside the other open tabs of the same area, in one split panel. The first tab of an area
9
24
  * opens in a new split to the right of the active panel, so the area does not mix with the sprite tabs.
@@ -16,7 +31,7 @@ export interface DocumentPanelRequest {
16
31
  tabGroup?: {id: string; label: string; color?: string; collapsed?: boolean};
17
32
  /** Opens the tab behind the active one, as when many tabs are opened at once. */
18
33
  inactive?: boolean;
19
- mount(element: HTMLElement, close: () => void): {requestClose(): void; dispose(): void};
34
+ mount(element: HTMLElement, close: () => void, onSaveAvailable?: () => void): DocumentPanelSession;
20
35
  }
21
36
 
22
37
  export const documentPanelTitle = ({title, filename, reference: {providerId, documentId}}: DocumentPanelRequest) =>
@@ -31,6 +46,11 @@ function createDocumentWorkspace() {
31
46
  let open: ((request: DocumentPanelRequest) => void) | undefined;
32
47
  let source: DocumentPanelSource | undefined;
33
48
  const listeners = new Set<() => void>();
49
+ let saveScope: 'project' | 'tab' = 'project';
50
+ let activeSession: (() => DocumentPanelSession | undefined) | undefined;
51
+ let sessions: (() => Iterable<DocumentPanelSession | undefined>) | undefined;
52
+ const saveListeners = new Set<() => void>();
53
+ const notifySave = () => saveListeners.forEach(listener => listener());
34
54
  const notify = () => listeners.forEach(listener => listener());
35
55
  return {
36
56
  open(request: DocumentPanelRequest) {
@@ -38,9 +58,38 @@ function createDocumentWorkspace() {
38
58
  open(request);
39
59
  return true;
40
60
  },
41
- connect(handler: NonNullable<typeof open>) {
61
+ connect(handler: NonNullable<typeof open>, getActiveSession?: NonNullable<typeof activeSession>,
62
+ getSessions?: NonNullable<typeof sessions>) {
42
63
  open = handler;
43
- return () => { if (open === handler) open = undefined; };
64
+ activeSession = getActiveSession;
65
+ sessions = getSessions;
66
+ notifySave();
67
+ return () => {
68
+ if (open !== handler) return;
69
+ open = undefined;
70
+ activeSession = undefined;
71
+ sessions = undefined;
72
+ notifySave();
73
+ };
74
+ },
75
+ setSaveScope(scope: typeof saveScope) {
76
+ if (scope === saveScope) return;
77
+ saveScope = scope;
78
+ notifySave();
79
+ },
80
+ get saveScope() {return saveScope;},
81
+ get canSaveActive() {return Boolean(activeSession?.()?.save);},
82
+ saveActive() {return activeSession?.()?.save?.();},
83
+ fileEdits() {
84
+ return Array.from(sessions?.() ?? []).flatMap(session => {
85
+ const file = session?.fileEdit;
86
+ return file?.isDirty() ? [file] : [];
87
+ });
88
+ },
89
+ notifySave,
90
+ subscribeSave(listener: () => void) {
91
+ saveListeners.add(listener);
92
+ return () => {saveListeners.delete(listener);};
44
93
  },
45
94
  connectSource(next: DocumentPanelSource) {
46
95
  source = next;
@@ -1,13 +1,15 @@
1
1
  import type {ReactNode} from 'react';
2
2
 
3
3
  /** The contents the left drawer can show. `sprites` is the GUI's sprite list and backdrop, always available. */
4
- export type DrawerViewId = 'sprites' | 'project' | 'git-history';
4
+ export type DrawerViewId = 'sprites' | 'project' | 'git-history' | 'agents';
5
5
  /** The contents a host supplies. */
6
6
  export type HostDrawerViewId = Exclude<DrawerViewId, 'sprites'>;
7
7
 
8
8
  export interface DrawerRenderProps {
9
9
  /** The Editor locale, for example `ja` or `en`. */
10
10
  locale: string;
11
+ /** The search text supplied by the drawer's search field. */
12
+ query?: string;
11
13
  }
12
14
 
13
15
  /** A drawer content supplied by the host. Its button appears only while the host supplies it. */
@@ -21,6 +23,8 @@ export interface DrawerView {
21
23
  render(props: DrawerRenderProps): ReactNode;
22
24
  /** The view's own tools, shown where the sprite list shows search, pin and undock. */
23
25
  tools?(props: DrawerRenderProps): ReactNode;
26
+ /** The accessible name of the search field, if this view supports search. */
27
+ searchLabel?(locale: string): string;
24
28
  }
25
29
 
26
30
  export interface DrawerMenuRenderProps extends DrawerRenderProps {
@@ -40,9 +44,13 @@ export interface DrawerMenu {
40
44
  export interface DrawerViews {
41
45
  views?: readonly DrawerView[];
42
46
  agents?: DrawerMenu;
47
+ /** Reports the drawer view presented by the standard layout. */
48
+ onSelectionChange?(view: DrawerViewId): void;
49
+ /** Exposes the drawer's reveal action to other panels in the same Editor. */
50
+ registerReveal?(reveal: (id: HostDrawerViewId) => void): () => void;
43
51
  }
44
52
 
45
- export const drawerViewIds: readonly DrawerViewId[] = ['sprites', 'project', 'git-history'];
53
+ export const drawerViewIds: readonly DrawerViewId[] = ['sprites', 'project', 'git-history', 'agents'];
46
54
  const hostIds = new Set<string>(drawerViewIds.slice(1));
47
55
 
48
56
  const names = {
@@ -104,6 +112,8 @@ export function writeDrawerView(storage: DrawerStorage | null | undefined, stora
104
112
  }
105
113
  }
106
114
 
115
+ export const projectFolderIconPath = 'M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z';
116
+
107
117
  let nextMenuId = 0;
108
118
 
109
119
  export function createDrawerViewBar(React, styles) {
@@ -116,7 +126,7 @@ export function createDrawerViewBar(React, styles) {
116
126
  sprites: () => svg(element('rect', {x: 2, y: 2, width: 5, height: 5, rx: 1}),
117
127
  element('rect', {x: 9, y: 2, width: 5, height: 5, rx: 1}),
118
128
  element('rect', {x: 2, y: 9, width: 12, height: 5, rx: 1})),
119
- project: () => svg(element('path', {d: 'M1.5 4V13h13V5.5H8L6.5 3.5h-4A1 1 0 0 0 1.5 4.5Z'})),
129
+ project: () => svg(element('path', {d: projectFolderIconPath})),
120
130
  'git-history': () => svg(element('circle', {cx: 5, cy: 3.5, r: 1.5}), element('circle', {cx: 5, cy: 12.5, r: 1.5}),
121
131
  element('circle', {cx: 11, cy: 6.5, r: 1.5}), element('path', {d: 'M5 5v6M11 8c0 2.5-6 1.5-6 3'})),
122
132
  agents: () => svg(element('path', {d: agentsIconPath}))
@@ -172,7 +182,8 @@ export function createDrawerViewBar(React, styles) {
172
182
  ...views.map(view => ({id: view.id, label: view.label ?? drawerLabel(view.id, locale),
173
183
  icon: view.icon ?? icons[view.id]()}))
174
184
  ];
175
- const count = entries.length + (agents ? 1 : 0);
185
+ const menu = entries.some(entry => entry.id === 'agents') ? undefined : agents;
186
+ const count = entries.length + (menu ? 1 : 0);
176
187
  const [focused, setFocused] = useState(() => Math.max(0, entries.findIndex(entry => entry.id === selected)));
177
188
  const current = Math.min(focused, count - 1);
178
189
  const move = (event, index) => {
@@ -200,8 +211,8 @@ export function createDrawerViewBar(React, styles) {
200
211
  onClick: () => onSelect(entry.id),
201
212
  onKeyDown: event => move(event, index)
202
213
  }, entry.icon)),
203
- agents && element(AgentMenu, {
204
- menu: agents, locale, button: agentButton,
214
+ menu && element(AgentMenu, {
215
+ menu, locale, button: agentButton,
205
216
  tabIndex: current === entries.length ? 0 : -1,
206
217
  onFocus: () => setFocused(entries.length),
207
218
  onKeyDown: event => move(event, entries.length)
package/src/editor.css CHANGED
@@ -717,8 +717,10 @@ details.layout-menu button {
717
717
  .target-list-tools {
718
718
  display: flex;
719
719
  align-items: center;
720
- justify-content: space-evenly;
721
- padding-block: 0.125rem;
720
+ justify-content: flex-end;
721
+ flex: none;
722
+ gap: 0.25rem;
723
+ padding: 0.125rem 0.25rem;
722
724
  }
723
725
 
724
726
  .target-list-tools button,
@@ -728,19 +730,22 @@ details.layout-menu button {
728
730
  min-width: 1.5rem;
729
731
  min-height: 1.5rem;
730
732
  padding: 0.125rem;
731
- border: 1px solid transparent;
733
+ border: 0;
732
734
  border-radius: 0.25rem;
733
735
  background: transparent;
734
736
  color: var(--text-primary);
735
737
  cursor: pointer;
736
738
  }
737
739
 
738
- .target-list-tools button:hover,
739
- .target-list-tools button:focus-visible {
740
- border-color: var(--ui-black-transparent);
740
+ .target-list-tools button:hover {
741
741
  background: var(--ui-primary);
742
742
  }
743
743
 
744
+ .target-list-tools button:focus-visible {
745
+ outline: 2px solid var(--looks-secondary);
746
+ outline-offset: -2px;
747
+ }
748
+
744
749
  .target-list-tools svg {
745
750
  width: 0.875rem;
746
751
  height: 0.875rem;
@@ -1004,12 +1009,23 @@ details.layout-menu button {
1004
1009
  color: #fff;
1005
1010
  }
1006
1011
 
1007
- .drawer-view-tools {
1012
+ .drawer-host-view {
1008
1013
  display: flex;
1009
- flex: none;
1010
- align-items: center;
1011
- justify-content: space-evenly;
1012
- padding-block: 0.125rem;
1014
+ flex: 1;
1015
+ flex-direction: column;
1016
+ min-block-size: 0;
1017
+ min-inline-size: 0;
1018
+ }
1019
+
1020
+ .drawer-host-view[hidden] {
1021
+ display: none;
1022
+ }
1023
+
1024
+ .drawer-host-view > .basic-panel {
1025
+ display: flex;
1026
+ flex: 1;
1027
+ flex-direction: column;
1028
+ min-block-size: 0;
1013
1029
  }
1014
1030
 
1015
1031
  .drawer-sprites {
@@ -1119,6 +1135,20 @@ details.layout-menu button {
1119
1135
  object-fit: contain;
1120
1136
  }
1121
1137
 
1138
+ :global(.tw-plus-folder-tab-icon) {
1139
+ display: none;
1140
+ }
1141
+
1142
+ :global([data-fixed-project-tab] .tw-plus-folder-tab-icon) {
1143
+ display: block;
1144
+ color: var(--looks-secondary, #855cd6);
1145
+ }
1146
+
1147
+ :global([data-fixed-project-tab] .dv-default-tab-action),
1148
+ :global([data-fixed-project-tab] img.tw-plus-sprite-tab-icon[hidden]) {
1149
+ display: none;
1150
+ }
1151
+
1122
1152
  .sprite-tabs :global(.tw-plus-sprite-rename) {
1123
1153
  border: 1px solid var(--ui-black-transparent);
1124
1154
  border-radius: 0.5rem;