@kubohiroya/turbowarp-plus-editor-workbench 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,38 @@
1
1
  import { createLayout, createSplitter, splitAxis } from "./index.js";
2
2
  import { createTargetList } from "./targets.js";
3
+ import { availableDrawerViews, createDrawerViewBar, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
3
4
  const isJapanese = locale => /^ja(?:-|$)/i.test(locale);
4
5
  const singleColumnTargetWidth = 108;
6
+ // Views other than the sprite list show file names and commit subjects, so the drawer opens wider for them.
7
+ const drawerViewWidth = 300;
8
+ const minimumDrawerViewWidth = 160;
5
9
  const minimumStandardEditor = 380;
6
10
  export function createStandardLayout(React, { styles, targetStyles, context, LayoutMenu }) {
7
11
  const { createElement: element, useContext, useLayoutEffect, useRef, useState } = React;
8
12
  const SplitLayout = createLayout(React);
9
13
  const Splitter = createSplitter(React);
10
14
  const targets = createTargetList(React, targetStyles);
15
+ const DrawerViewBar = createDrawerViewBar(React, styles);
11
16
  const targetSearch = React.createContext('');
12
17
  const targetTools = React.createContext(null);
13
- function StandardLayout({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false, onPaletteModeChange, windowTools, Container, render, ...props }) {
18
+ function StandardLayout({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false, onPaletteModeChange, windowTools, Container, render, drawerViews = undefined, ...props }) {
14
19
  const [showUndock, setShowUndock] = useState(false);
15
20
  const [targetsPinned, setTargetsPinned] = useState(true);
16
21
  const [showStage, setShowStage] = useState(true);
17
22
  const [stageDrawerOpen, setStageDrawerOpen] = useState(false);
18
23
  const [size, setSize] = useState(null);
19
24
  const [targetRatio, setTargetRatio] = useState(null);
25
+ const [viewRatio, setViewRatio] = useState(null);
20
26
  const [preferredStageWidth, setPreferredStageWidth] = useState(null);
21
27
  const [stageActionMount, setStageActionMount] = useState(null);
28
+ const [preferredDrawerView, setPreferredDrawerView] = useState(() => readDrawerView(props.storage, props.storageKey));
29
+ const hostDrawerViews = availableDrawerViews(drawerViews);
30
+ // A view saved earlier comes back once the host supplies it again.
31
+ const drawerView = hostDrawerViews.some(view => view.id === preferredDrawerView) ? preferredDrawerView : 'sprites';
32
+ const selectDrawerView = view => {
33
+ setPreferredDrawerView(view);
34
+ writeDrawerView(props.storage, props.storageKey, view);
35
+ };
22
36
  const body = useRef(null);
23
37
  const plusLayout = enabled && !props.fullscreen;
24
38
  const stageHidden = plusLayout && !showStage;
@@ -40,9 +54,15 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
40
54
  const stageTools = stageActionEnabled &&
41
55
  element('span', { className: styles.stageActionSlot, ref: setStageActionMount });
42
56
  const bodyWidth = size?.width ?? 1024;
43
- const targetSplit = plusLayout && splitter && size ? splitAxis(bodyWidth, targetRatio, singleColumnTargetWidth, singleColumnTargetWidth, minimumStandardEditor) : null;
57
+ // The sprite list and the other views keep their own widths, so widening one leaves the other as it was.
58
+ const wideDrawer = plusLayout && drawerView !== 'sprites';
59
+ const targetSplit = plusLayout && splitter && size ? (wideDrawer ?
60
+ splitAxis(bodyWidth, viewRatio, drawerViewWidth, minimumDrawerViewWidth, minimumStandardEditor) :
61
+ splitAxis(bodyWidth, targetRatio, singleColumnTargetWidth, singleColumnTargetWidth, minimumStandardEditor)) : null;
62
+ const fixedDrawerWidth = Math.max(singleColumnTargetWidth, Math.min(drawerViewWidth, Math.floor(bodyWidth / 2)));
44
63
  const resizable = targetSplit && targetSplit.maximum > targetSplit.minimum;
45
- const editorSpace = targetsPinned ? (targetSplit?.second ?? bodyWidth - singleColumnTargetWidth) : bodyWidth;
64
+ const editorSpace = targetsPinned ?
65
+ (targetSplit?.second ?? bodyWidth - (wideDrawer ? fixedDrawerWidth : singleColumnTargetWidth)) : bodyWidth;
46
66
  const maximumStageWidth = Math.max(1, Math.floor(Math.min(editorSpace - 24, ((size?.height ?? 640) - 112) * props.stageAspect)));
47
67
  const defaultStageWidth = Math.min(maximumStageWidth, Math.floor(Math.min(props.defaultStageWidth, 360, bodyWidth / 2)));
48
68
  const minimumStageWidth = Math.min(defaultStageWidth, 280);
@@ -94,12 +114,17 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
94
114
  bodyStyle['--plus-target-width'] = `${targetSplit.first}px`;
95
115
  bodyStyle['--plus-target-divider-width'] = `${size.width - targetSplit.available}px`;
96
116
  }
117
+ else if (wideDrawer) {
118
+ bodyStyle['--plus-target-width'] = `${fixedDrawerWidth}px`;
119
+ }
97
120
  // The target list is on the physical left in both text directions.
98
121
  const columnSplitter = targetsPinned && resizable ? element(Splitter, {
99
122
  axis: 'columns', split: targetSplit,
100
- label: japanese ? 'スプライト一覧と編集領域の幅' : 'Sprite list and editor width',
123
+ label: wideDrawer ? (japanese ? 'ドロワーと編集領域の幅' : 'Drawer and editor width') :
124
+ japanese ? 'スプライト一覧と編集領域の幅' : 'Sprite list and editor width',
101
125
  className: `${styles.separator} ${styles.standardSeparator}`,
102
- onChange: setTargetRatio, onReset: () => setTargetRatio(null)
126
+ onChange: wideDrawer ? setViewRatio : setTargetRatio,
127
+ onReset: () => (wideDrawer ? setViewRatio : setTargetRatio)(null)
103
128
  }) : null;
104
129
  return {
105
130
  ...shared,
@@ -133,7 +158,8 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
133
158
  });
134
159
  return element(context.Provider, { value: {
135
160
  showUndock, plusLayout, targetsPinned, setTargetsPinned, stageHidden, setStageVisible: setShowStage, stageResize, stageActionMount,
136
- stageDrawer: plusLayout && stageDrawer, setStageDrawerOpen, locale: props.locale
161
+ stageDrawer: plusLayout && stageDrawer, setStageDrawerOpen, locale: props.locale,
162
+ drawerViews, drawerView, selectDrawerView
137
163
  } }, Container ? element(Container, { locale: props.locale }, layout) : layout);
138
164
  }
139
165
  function EdgeDrawer({ edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '', focusPanelRef = undefined, focusBoundary = undefined, showTrigger = true, children }) {
@@ -240,13 +266,27 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
240
266
  }, { left: '›', right: '‹', bottom: '⌃' }[edge]), element('div', { className: styles.edgePanel, ref: panel, tabIndex: -1, hidden: !open }, children));
241
267
  }
242
268
  function TargetLayout({ compact, render }) {
243
- const { plusLayout, targetsPinned, locale } = useContext(context);
269
+ const { plusLayout, targetsPinned, locale, drawerViews, drawerView = 'sprites', selectDrawerView } = useContext(context);
244
270
  const tools = useState(null);
245
271
  const panel = render(plusLayout || compact);
246
- return plusLayout ? element(EdgeDrawer, {
272
+ if (!plusLayout)
273
+ return panel;
274
+ const content = element(targetTools.Provider, { value: tools }, panel);
275
+ const drawer = children => element(EdgeDrawer, {
247
276
  edge: 'left', pinned: targetsPinned,
248
277
  label: isJapanese(locale) ? 'スプライト一覧を展開' : 'Reveal sprite list'
249
- }, element(targetTools.Provider, { value: tools }, panel)) : panel;
278
+ }, children);
279
+ // Without host views the drawer keeps the sprite list as its only, unwrapped content.
280
+ if (!hasDrawerBar(drawerViews))
281
+ return drawer(content);
282
+ const views = availableDrawerViews(drawerViews);
283
+ const active = views.find(view => view.id === drawerView);
284
+ return drawer(element(React.Fragment, null, element(DrawerViewBar, { locale, views, agents: drawerViews.agents, selected: active ? active.id : 'sprites',
285
+ onSelect: selectDrawerView }),
286
+ // Pinning belongs to the drawer, so every view keeps the pin button the sprite list shows.
287
+ active && element('div', { className: styles.drawerViewTools }, active.tools?.({ locale }), element(DrawerPinButton, { label: isJapanese(locale) ? 'このパネルを固定表示' : 'Pin this panel' })),
288
+ // The GUI's target pane stays mounted, so its file inputs and library keep working while hidden.
289
+ element('div', { className: styles.drawerSprites, hidden: Boolean(active) }, content), active && element('div', { className: styles.drawerViewContent, 'data-drawer-content': active.id }, active.render({ locale }))));
250
290
  }
251
291
  function SpriteGrid(props) {
252
292
  const { plusLayout } = useContext(context);
@@ -281,8 +321,14 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
281
321
  onClick: () => setExpanded(open => !open)
282
322
  }, isJapanese(locale) ? 'スプライト' : 'Sprite'), element('div', { ref: tools?.[1] }), !inEditor && element('div', { className: styles.spritePropertiesContent, hidden: !expanded }, children)) : fallback;
283
323
  }
324
+ function DrawerPinButton({ label }) {
325
+ const { targetsPinned, setTargetsPinned } = useContext(context);
326
+ return element('button', { type: 'button', className: styles.drawerPin, 'aria-label': label, 'aria-pressed': targetsPinned,
327
+ title: label, onClick: () => setTargetsPinned(value => !value) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
328
+ fill: targetsPinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round' }, element('path', { d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z' }), element('path', { d: 'm7.5 8.5-4 4' }), !targetsPinned && element('path', { d: 'M2 2l12 12', strokeLinecap: 'round' })));
329
+ }
284
330
  function useSpriteListTools() {
285
- const { locale, targetsPinned, setTargetsPinned } = useContext(context);
331
+ const { locale } = useContext(context);
286
332
  const [mount] = useContext(targetTools) ?? [];
287
333
  const [searching, setSearching] = useState(false);
288
334
  const [query, setQuery] = useState('');
@@ -303,9 +349,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
303
349
  const renderTools = openAction => element(React.Fragment, null, element('div', { className: styles.targetListTools, role: 'group',
304
350
  'aria-label': japanese ? 'スプライト一覧の操作' : 'Sprite list tools' }, element('button', { type: 'button', ref: searchButton, 'aria-label': searchLabel, 'aria-expanded': searching,
305
351
  title: searchLabel, onClick: () => searching ? closeSearch() : setSearching(true) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
306
- 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('button', { type: 'button', className: styles.drawerPin, 'aria-label': pinLabel, 'aria-pressed': targetsPinned,
307
- title: pinLabel, onClick: () => setTargetsPinned(value => !value) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
308
- fill: targetsPinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round' }, element('path', { d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z' }), element('path', { d: 'm7.5 8.5-4 4' }), !targetsPinned && element('path', { d: 'M2 2l12 12', strokeLinecap: 'round' }))), openAction), searching && element('input', { type: 'search', className: styles.targetListSearch, 'aria-label': searchLabel,
352
+ 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,
309
353
  ref: searchInput, placeholder: japanese ? '名前' : 'Name', value: query,
310
354
  onChange: event => setQuery(event.currentTarget.value),
311
355
  onKeyDown: event => {
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import type { IContextMenuItemRenderer } from 'dockview';
3
+ interface TargetTabs {
4
+ locale: string;
5
+ list(id?: string): readonly {
6
+ id: string;
7
+ title: string;
8
+ }[];
9
+ select(id?: string): void;
10
+ activate(id: string): void;
11
+ }
12
+ interface MenuPrimitives {
13
+ MenuItem: React.ElementType;
14
+ SubMenu: React.ElementType;
15
+ menuClassName: string;
16
+ itemClassName: string;
17
+ }
18
+ export declare const spriteRenameLabel: (locale: string) => "スプライト名の変更" | "Rename sprite";
19
+ export declare const SpriteTargetTabsContext: React.Context<TargetTabs>;
20
+ export declare function createRenameMenuItem(document: Document, title: string, rename: (id: string) => void): IContextMenuItemRenderer;
21
+ export declare function useTargetTabMenu(): {
22
+ onShow(id?: string): void;
23
+ select: (id?: string) => void;
24
+ render({ MenuItem, SubMenu, menuClassName, itemClassName }: MenuPrimitives, id?: string, rename?: (event: React.MouseEvent) => void): {
25
+ open: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
26
+ rename: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
27
+ };
28
+ };
29
+ export {};
@@ -0,0 +1,76 @@
1
+ import React from 'react';
2
+ const pencil = 'm4 16-1 5 5-1L21 7l-4-4L4 16Zm10-10 4 4';
3
+ const open = 'M13 4h7v7m0-7-9 9m-1-8H4v15h15v-6';
4
+ const iconClass = 'tw-plus-target-menu-icon';
5
+ const svgNamespace = 'http://www.w3.org/2000/svg';
6
+ const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale);
7
+ export const spriteRenameLabel = (locale) => isJapanese(locale) ? 'スプライト名の変更' : 'Rename sprite';
8
+ export const SpriteTargetTabsContext = React.createContext(null);
9
+ export function createRenameMenuItem(document, title, rename) {
10
+ const element = document.createElement('button');
11
+ element.type = 'button';
12
+ element.className = 'dv-context-menu-item tw-plus-target-menu-button';
13
+ element.setAttribute('role', 'menuitem');
14
+ const icon = document.createElementNS(svgNamespace, 'svg');
15
+ icon.setAttribute('class', iconClass);
16
+ icon.setAttribute('viewBox', '0 0 24 24');
17
+ icon.setAttribute('aria-hidden', 'true');
18
+ const path = document.createElementNS(svgNamespace, 'path');
19
+ path.setAttribute('d', pencil);
20
+ icon.append(path);
21
+ element.append(icon, title);
22
+ return {
23
+ element,
24
+ init(props) {
25
+ if (!('panel' in props))
26
+ return;
27
+ element.onclick = () => {
28
+ props.close();
29
+ rename(props.panel.id);
30
+ };
31
+ },
32
+ dispose() {
33
+ element.onclick = null;
34
+ }
35
+ };
36
+ }
37
+ const itemLabel = (path, label) => React.createElement(React.Fragment, null, React.createElement('svg', { className: iconClass, 'aria-hidden': true, viewBox: '0 0 24 24' }, React.createElement('path', { d: path })), label);
38
+ export function useTargetTabMenu() {
39
+ const tabs = React.useContext(SpriteTargetTabsContext);
40
+ const [shown, setShown] = React.useState();
41
+ if (!tabs)
42
+ return null;
43
+ return {
44
+ onShow(id) {
45
+ // Read the live order even if the last move did not change the selection.
46
+ setShown({ id, views: tabs.list(id) });
47
+ },
48
+ select: tabs.select,
49
+ render({ MenuItem, SubMenu, menuClassName, itemClassName }, id, rename) {
50
+ const views = shown?.id === id ? shown?.views ?? [] : [];
51
+ const label = itemLabel(open, isJapanese(tabs.locale) ? '開く' : 'Open');
52
+ const attributes = { className: itemClassName, 'data-tw-plus-menu-icon': '' };
53
+ const openItem = views.length > 1 ? React.createElement(SubMenu, {
54
+ title: React.createElement(React.Fragment, null, label, React.createElement('span', { className: 'tw-plus-target-submenu-arrow', 'aria-hidden': true }, '›')),
55
+ className: `${menuClassName} tw-plus-target-submenu`,
56
+ attributes
57
+ }, views.map(view => React.createElement(MenuItem, {
58
+ key: view.id, attributes: { className: itemClassName },
59
+ onClick: (event) => {
60
+ event.stopPropagation();
61
+ tabs.activate(view.id);
62
+ }
63
+ }, view.title))) : React.createElement(MenuItem, {
64
+ attributes,
65
+ onClick: (event) => {
66
+ event.stopPropagation();
67
+ tabs.select(id);
68
+ }
69
+ }, label);
70
+ return {
71
+ open: openItem,
72
+ rename: rename && React.createElement(MenuItem, { attributes, onClick: rename }, itemLabel(pencil, spriteRenameLabel(tabs.locale)))
73
+ };
74
+ }
75
+ };
76
+ }
@@ -6,6 +6,7 @@ export type PanelReference = {
6
6
  name: string;
7
7
  stage: boolean;
8
8
  section: number;
9
+ number?: number;
9
10
  } | {
10
11
  kind: 'stage';
11
12
  } | ({
@@ -158,8 +158,12 @@ export function readWorkspaceLayout(raw, project) {
158
158
  if (!Object.hasOwn(input.panels, id) || !record(panel))
159
159
  return;
160
160
  if (panel.kind === 'sprite' && validId(panel.name) && typeof panel.stage === 'boolean' &&
161
- typeof panel.section === 'number' && Number.isInteger(panel.section) && panel.section >= 0 && panel.section <= 3) {
162
- panels[id] = { kind: 'sprite', name: panel.name, stage: panel.stage, section: panel.section };
161
+ typeof panel.section === 'number' && Number.isInteger(panel.section) && panel.section >= 0 && panel.section <= 4) {
162
+ const number = panel.number;
163
+ if (number !== undefined && (typeof number !== 'number' || !Number.isSafeInteger(number) || number < 2))
164
+ return;
165
+ panels[id] = { kind: 'sprite', name: panel.name, stage: panel.stage, section: panel.section,
166
+ ...(typeof number === 'number' && { number }) };
163
167
  }
164
168
  else if (panel.kind === 'stage' && !hasStage) {
165
169
  hasStage = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-workbench",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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",
@@ -34,6 +34,10 @@
34
34
  "default": "./dist/debugger-panel.js"
35
35
  },
36
36
  "./debugger-panel.css": "./src/debugger-panel.css",
37
+ "./ai-agents": {
38
+ "types": "./dist/ai-agents.d.ts",
39
+ "default": "./dist/ai-agents.js"
40
+ },
37
41
  "./extension-file-menu": {
38
42
  "types": "./dist/extension-file-menu.d.ts",
39
43
  "default": "./dist/extension-file-menu.js"