@kubohiroya/turbowarp-plus-editor-code-views 0.8.1 → 0.9.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 CHANGED
@@ -67,7 +67,7 @@ MPL-2.0。turbowarp-plus-editor の `packages/editor-views` と `packages/editor
67
67
  | `paletteGroupSets(locale, projectSets)` | 「標準」「表現」「変数・リスト」「基本の制御」と、作品のセット |
68
68
  | `attachPaletteMenuButton(menu, getLocale, getItems)` | カテゴリの一覧の末尾(横配置では右端、縦配置では下端)に ▼ のボタンを置く。押すと、ホストが渡す項目のメニューを出す。項目は「ブロックグループの表示・非表示の設定」(`paletteVisibilityMenuLabel`)と、ホストの機能拡張に関する項目 |
69
69
 
70
- `./palette-visibility-dialog` の `openPaletteVisibilityDialog(document, props)` は「パレット内のブロックグループの表示・非表示の設定」の画面を開く。機能拡張の各行は `@kubohiroya/turbowarp-extension-security-dialog/react` の `ExtensionRow` で描くので、拡張の追加の画面と同じ見た目になる。適用すると、出すグループと、この画面で足したセットを `onApply` に渡す。`newSprite` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、見出しの下に「新しいスプライト「名前」」と出す。
70
+ `./palette-visibility-dialog` の `openPaletteVisibilityDialog(document, props)` は「パレット内のブロックグループの表示・非表示の設定」の画面を開く。機能拡張の各行は `@kubohiroya/turbowarp-extension-security-dialog/react` の `ExtensionRow` で描くので、拡張の追加の画面と同じ見た目になる。適用すると、出すグループと、この画面で足したセットを `onApply` に渡す。`newSprite` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、見出しの下に「新しいスプライト「名前」」と出す。あわせて `copySources`(作成済みのスプライトの名前と、それぞれが表示中のグループ)を渡すと、「作成済みのスプライトからコピー」の欄に選ぶ一覧と「コピーして適用」を出す。押すと、選んだスプライトのグループのうちこのスプライトに出せるものを、そのまま `onApply` に渡して閉じる。
71
71
 
72
72
  ホストは `@kubohiroya/turbowarp-extension-security-dialog`(0.9.0 以上)を入れ、その `styles.css` も読み込む。設定を画面状態のスライスとして登録するのはホストの役目である。1つの機能拡張の中を複数のグループに分けて選ぶ機能は、VM がグループごとのカテゴリを作れるようになってから足す。
73
73
 
package/README.md CHANGED
@@ -67,7 +67,7 @@ Each sprite and the stage can choose which block groups the palette shows: the s
67
67
  | `paletteGroupSets(locale, projectSets)` | Standard, Expression, Variables and lists, Basic control, and the project's own sets |
68
68
  | `attachPaletteMenuButton(menu, getLocale, getItems)` | Puts a ▼ button at the end of the category menu (the right end of a horizontal palette, the bottom of a vertical one). Pressing it lists the items the host gives: the group settings (`paletteVisibilityMenuLabel`) and the host's extension items |
69
69
 
70
- `openPaletteVisibilityDialog(document, props)` from `./palette-visibility-dialog` opens the screen that chooses the groups. Each extension is drawn with `ExtensionRow` from `@kubohiroya/turbowarp-extension-security-dialog/react`, so it looks the same as in the screen that adds extensions. Applying passes the groups to show, and the sets added in the screen, to `onApply`. With `newSprite`, the screen asks about a sprite just added and names it as a new sprite.
70
+ `openPaletteVisibilityDialog(document, props)` from `./palette-visibility-dialog` opens the screen that chooses the groups. Each extension is drawn with `ExtensionRow` from `@kubohiroya/turbowarp-extension-security-dialog/react`, so it looks the same as in the screen that adds extensions. Applying passes the groups to show, and the sets added in the screen, to `onApply`. With `newSprite`, the screen asks about a sprite just added and names it as a new sprite. Given `copySources` too (the sprites already in the project, each with the groups it shows), it offers “Copy from an existing sprite”: a list to choose one and “Copy and apply”, which passes that sprite's groups, as far as this sprite is offered them, to `onApply` and closes.
71
71
 
72
72
  The host installs `@kubohiroya/turbowarp-extension-security-dialog` (0.9.0 or later) and loads its `styles.css`, and registers the store as a screen-state slice. Choosing groups inside one extension comes once the VM can make a category per group.
73
73
 
@@ -25,6 +25,14 @@ export interface PaletteVisibilityDialogProps {
25
25
  sets: readonly PaletteGroupSet[];
26
26
  /** Asked for a sprite just added: the screen names it as a new sprite. */
27
27
  newSprite?: boolean;
28
+ /**
29
+ * For a new sprite: the sprites already in the project with the groups each shows. The screen offers to copy
30
+ * one of them and apply it at once.
31
+ */
32
+ copySources?: readonly {
33
+ name: string;
34
+ groups: readonly string[];
35
+ }[];
28
36
  onApply(choice: PaletteVisibilityChoice): void;
29
37
  onCancel(): void;
30
38
  }
@@ -33,6 +41,7 @@ interface DialogState {
33
41
  addedSets: PaletteGroupSet[];
34
42
  naming: boolean;
35
43
  setName: string;
44
+ copySource: number;
36
45
  }
37
46
  /**
38
47
  * The screen that chooses which block groups the palette shows for one sprite or the stage: sets that
@@ -46,6 +55,8 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
46
55
  sprite: (name: string) => string;
47
56
  stage: string;
48
57
  newSprite: (name: string) => string;
58
+ copyFrom: string;
59
+ copyApply: string;
49
60
  sets: string;
50
61
  addSet: string;
51
62
  setName: string;
@@ -63,6 +74,8 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
63
74
  toggle(group: string): void;
64
75
  toggleSet(set: PaletteGroupSet): void;
65
76
  addSet(): void;
77
+ /** Apply the groups another sprite shows, as far as this one is offered them. */
78
+ copyAndApply(): void;
66
79
  apply(): void;
67
80
  render(): React.JSX.Element;
68
81
  }
@@ -16,6 +16,7 @@ const messages = {
16
16
  en: {
17
17
  title: 'Block groups shown in the palette', sprite: (name) => `Sprite “${name}”`, stage: 'Stage',
18
18
  newSprite: (name) => `New sprite “${name}”`,
19
+ copyFrom: 'Copy from an existing sprite', copyApply: 'Copy and apply',
19
20
  sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
20
21
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count) => `In use ${count}`,
21
22
  hiddenInUse: (count) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
@@ -23,6 +24,7 @@ const messages = {
23
24
  ja: {
24
25
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name) => `スプライト「${name}」`, stage: '背景',
25
26
  newSprite: (name) => `新しいスプライト「${name}」`,
27
+ copyFrom: '作成済みのスプライトからコピー', copyApply: 'コピーして適用',
26
28
  sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
27
29
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count) => `使用中 ${count}`,
28
30
  hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
@@ -37,7 +39,7 @@ const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
37
39
  export class PaletteVisibilityDialog extends React.PureComponent {
38
40
  constructor(props) {
39
41
  super(props);
40
- this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '' };
42
+ this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: 0 };
41
43
  }
42
44
  get text() {
43
45
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -86,6 +88,15 @@ export class PaletteVisibilityDialog extends React.PureComponent {
86
88
  .filter(group => this.state.shown.has(group));
87
89
  this.setState(({ addedSets }) => ({ addedSets: [...addedSets, { id, name, groups }], naming: false, setName: '' }));
88
90
  }
91
+ /** Apply the groups another sprite shows, as far as this one is offered them. */
92
+ copyAndApply() {
93
+ const source = this.props.copySources?.[this.state.copySource];
94
+ if (!source)
95
+ return;
96
+ const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
97
+ const groups = new Set(source.groups);
98
+ this.props.onApply({ groups: order.filter(group => groups.has(group)), addedSets: this.state.addedSets });
99
+ }
89
100
  apply() {
90
101
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
91
102
  this.props.onApply({ groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets });
@@ -104,6 +115,11 @@ export class PaletteVisibilityDialog extends React.PureComponent {
104
115
  React.createElement("h2", null, text.title),
105
116
  React.createElement("p", null, isStage ? text.stage : this.props.newSprite ? text.newSprite(targetName) : text.sprite(targetName))),
106
117
  React.createElement("button", { type: "button", className: "tw-palette-visibility-close", "aria-label": text.close, title: text.close, onClick: onCancel }, "\u00D7")),
118
+ this.props.newSprite && (this.props.copySources?.length ?? 0) > 0 && (React.createElement("section", { "aria-label": text.copyFrom },
119
+ React.createElement("h3", null, text.copyFrom),
120
+ React.createElement("div", { className: "tw-palette-visibility-copy" },
121
+ React.createElement("select", { "aria-label": text.copyFrom, value: this.state.copySource, onChange: event => this.setState({ copySource: Number(event.currentTarget.value) }) }, this.props.copySources.map((source, index) => (React.createElement("option", { key: index, value: index }, source.name)))),
122
+ React.createElement("button", { type: "button", className: "tw-palette-visibility-copy-apply", onClick: () => this.copyAndApply() }, text.copyApply)))),
107
123
  React.createElement("section", { "aria-label": text.sets },
108
124
  React.createElement("h3", null, text.sets),
109
125
  React.createElement("div", { className: "tw-palette-visibility-sets" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-code-views",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Code views for TurboWarp Plus Editor: code in tabs and windows, the detached block palette, script layout and block field editing",
5
5
  "type": "module",
6
6
  "license": "MPL-2.0",
@@ -30,6 +30,11 @@ export interface PaletteVisibilityDialogProps {
30
30
  sets: readonly PaletteGroupSet[];
31
31
  /** Asked for a sprite just added: the screen names it as a new sprite. */
32
32
  newSprite?: boolean;
33
+ /**
34
+ * For a new sprite: the sprites already in the project with the groups each shows. The screen offers to copy
35
+ * one of them and apply it at once.
36
+ */
37
+ copySources?: readonly {name: string; groups: readonly string[]}[];
33
38
  onApply(choice: PaletteVisibilityChoice): void;
34
39
  onCancel(): void;
35
40
  }
@@ -48,6 +53,7 @@ const messages = {
48
53
  en: {
49
54
  title: 'Block groups shown in the palette', sprite: (name: string) => `Sprite “${name}”`, stage: 'Stage',
50
55
  newSprite: (name: string) => `New sprite “${name}”`,
56
+ copyFrom: 'Copy from an existing sprite', copyApply: 'Copy and apply',
51
57
  sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
52
58
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count: number) => `In use ${count}`,
53
59
  hiddenInUse: (count: number) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
@@ -55,6 +61,7 @@ const messages = {
55
61
  ja: {
56
62
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name: string) => `スプライト「${name}」`, stage: '背景',
57
63
  newSprite: (name: string) => `新しいスプライト「${name}」`,
64
+ copyFrom: '作成済みのスプライトからコピー', copyApply: 'コピーして適用',
58
65
  sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
59
66
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
60
67
  hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
@@ -67,6 +74,7 @@ interface DialogState {
67
74
  addedSets: PaletteGroupSet[];
68
75
  naming: boolean;
69
76
  setName: string;
77
+ copySource: number;
70
78
  }
71
79
 
72
80
  /**
@@ -77,7 +85,7 @@ interface DialogState {
77
85
  export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibilityDialogProps, DialogState> {
78
86
  constructor(props: PaletteVisibilityDialogProps) {
79
87
  super(props);
80
- this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: ''};
88
+ this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: 0};
81
89
  }
82
90
  get text() {
83
91
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -120,6 +128,14 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
120
128
  .filter(group => this.state.shown.has(group));
121
129
  this.setState(({addedSets}) => ({addedSets: [...addedSets, {id, name, groups}], naming: false, setName: ''}));
122
130
  }
131
+ /** Apply the groups another sprite shows, as far as this one is offered them. */
132
+ copyAndApply() {
133
+ const source = this.props.copySources?.[this.state.copySource];
134
+ if (!source) return;
135
+ const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
136
+ const groups = new Set(source.groups);
137
+ this.props.onApply({groups: order.filter(group => groups.has(group)), addedSets: this.state.addedSets});
138
+ }
123
139
  apply() {
124
140
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
125
141
  this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets});
@@ -144,6 +160,21 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
144
160
  <button type="button" className="tw-palette-visibility-close" aria-label={text.close} title={text.close}
145
161
  onClick={onCancel}>×</button>
146
162
  </header>
163
+ {this.props.newSprite && (this.props.copySources?.length ?? 0) > 0 && (
164
+ <section aria-label={text.copyFrom}>
165
+ <h3>{text.copyFrom}</h3>
166
+ <div className="tw-palette-visibility-copy">
167
+ <select aria-label={text.copyFrom} value={this.state.copySource}
168
+ onChange={event => this.setState({copySource: Number(event.currentTarget.value)})}>
169
+ {this.props.copySources.map((source, index) => (
170
+ <option key={index} value={index}>{source.name}</option>
171
+ ))}
172
+ </select>
173
+ <button type="button" className="tw-palette-visibility-copy-apply"
174
+ onClick={() => this.copyAndApply()}>{text.copyApply}</button>
175
+ </div>
176
+ </section>
177
+ )}
147
178
  <section aria-label={text.sets}>
148
179
  <h3>{text.sets}</h3>
149
180
  <div className="tw-palette-visibility-sets">
package/src/styles.css CHANGED
@@ -917,3 +917,18 @@
917
917
  outline-offset: 1px;
918
918
  }
919
919
 
920
+
921
+ .tw-palette-visibility-copy {
922
+ display: flex;
923
+ flex-wrap: wrap;
924
+ gap: 0.4rem;
925
+ }
926
+
927
+ .tw-palette-visibility select {
928
+ padding: 0.3rem 0.6rem;
929
+ border: 1px solid var(--ui-black-transparent, #80808070);
930
+ border-radius: 0.35rem;
931
+ background: var(--ui-primary, Canvas);
932
+ color: inherit;
933
+ font: inherit;
934
+ }