@kubohiroya/turbowarp-plus-editor-code-views 0.7.2 → 0.8.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.
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/palette-visibility-dialog.d.ts +1 -5
- package/dist/palette-visibility-dialog.js +4 -8
- package/dist/sprite-restore-history.js +15 -6
- package/package.json +1 -1
- package/src/palette-visibility-dialog.tsx +5 -16
- package/src/sprite-restore-history.ts +12 -4
- package/src/styles.css +0 -7
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` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、見出しの下に「新しいスプライト「名前」」と出す。
|
|
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
|
|
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.
|
|
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
|
|
|
@@ -12,8 +12,6 @@ export interface PaletteVisibilityChoice {
|
|
|
12
12
|
groups: string[];
|
|
13
13
|
/** Sets added in this dialog, to keep with the project. */
|
|
14
14
|
addedSets: PaletteGroupSet[];
|
|
15
|
-
/** For a new sprite: start the next new sprites with these groups instead of asking. */
|
|
16
|
-
dontAskAgain?: boolean;
|
|
17
15
|
}
|
|
18
16
|
export interface PaletteVisibilityDialogProps {
|
|
19
17
|
locale?: string;
|
|
@@ -25,7 +23,7 @@ export interface PaletteVisibilityDialogProps {
|
|
|
25
23
|
used: ReadonlyMap<string, number>;
|
|
26
24
|
extensions: readonly PaletteExtension[];
|
|
27
25
|
sets: readonly PaletteGroupSet[];
|
|
28
|
-
/** Asked for a sprite just added:
|
|
26
|
+
/** Asked for a sprite just added: the screen names it as a new sprite. */
|
|
29
27
|
newSprite?: boolean;
|
|
30
28
|
onApply(choice: PaletteVisibilityChoice): void;
|
|
31
29
|
onCancel(): void;
|
|
@@ -35,7 +33,6 @@ interface DialogState {
|
|
|
35
33
|
addedSets: PaletteGroupSet[];
|
|
36
34
|
naming: boolean;
|
|
37
35
|
setName: string;
|
|
38
|
-
dontAskAgain: boolean;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* The screen that chooses which block groups the palette shows for one sprite or the stage: sets that
|
|
@@ -49,7 +46,6 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
|
|
|
49
46
|
sprite: (name: string) => string;
|
|
50
47
|
stage: string;
|
|
51
48
|
newSprite: (name: string) => string;
|
|
52
|
-
dontAskAgain: string;
|
|
53
49
|
sets: string;
|
|
54
50
|
addSet: string;
|
|
55
51
|
setName: string;
|
|
@@ -15,14 +15,14 @@ const standardColors = {
|
|
|
15
15
|
const messages = {
|
|
16
16
|
en: {
|
|
17
17
|
title: 'Block groups shown in the palette', sprite: (name) => `Sprite “${name}”`, stage: 'Stage',
|
|
18
|
-
newSprite: (name) => `New sprite “${name}”`,
|
|
18
|
+
newSprite: (name) => `New sprite “${name}”`,
|
|
19
19
|
sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
|
|
20
20
|
standard: 'Standard block groups', extensions: 'Extension block groups', used: (count) => `In use ${count}`,
|
|
21
21
|
hiddenInUse: (count) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
|
|
22
22
|
},
|
|
23
23
|
ja: {
|
|
24
24
|
title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name) => `スプライト「${name}」`, stage: '背景',
|
|
25
|
-
newSprite: (name) => `新しいスプライト「${name}」`,
|
|
25
|
+
newSprite: (name) => `新しいスプライト「${name}」`,
|
|
26
26
|
sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
|
|
27
27
|
standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count) => `使用中 ${count}`,
|
|
28
28
|
hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
|
|
@@ -37,7 +37,7 @@ const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
|
|
|
37
37
|
export class PaletteVisibilityDialog extends React.PureComponent {
|
|
38
38
|
constructor(props) {
|
|
39
39
|
super(props);
|
|
40
|
-
this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: ''
|
|
40
|
+
this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '' };
|
|
41
41
|
}
|
|
42
42
|
get text() {
|
|
43
43
|
return isJapanese(this.props.locale) ? messages.ja : messages.en;
|
|
@@ -88,8 +88,7 @@ export class PaletteVisibilityDialog extends React.PureComponent {
|
|
|
88
88
|
}
|
|
89
89
|
apply() {
|
|
90
90
|
const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
|
|
91
|
-
this.props.onApply({ groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets
|
|
92
|
-
...this.props.newSprite ? { dontAskAgain: this.state.dontAskAgain } : {} });
|
|
91
|
+
this.props.onApply({ groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets });
|
|
93
92
|
}
|
|
94
93
|
render() {
|
|
95
94
|
const { locale, targetName, isStage, used, extensions, onCancel } = this.props;
|
|
@@ -134,9 +133,6 @@ export class PaletteVisibilityDialog extends React.PureComponent {
|
|
|
134
133
|
React.createElement("ul", { className: "twextsec-rows" }, extensions.map(extension => (React.createElement(ExtensionRow, { key: extension.id, metadata: extension.metadata, ids: [extension.id], locale: locale, itemProps: { 'data-group': extension.id }, pick: { checked: shown.has(extension.id), onToggle: () => this.toggle(extension.id) } }, usedBadge(extension.id)))))))),
|
|
135
134
|
React.createElement("footer", { className: "tw-palette-visibility-footer" },
|
|
136
135
|
React.createElement("span", { role: "status" }, hiddenInUse > 0 ? text.hiddenInUse(hiddenInUse) : ''),
|
|
137
|
-
this.props.newSprite && (React.createElement("label", { className: "tw-palette-visibility-dont-ask" },
|
|
138
|
-
React.createElement("input", { type: "checkbox", checked: this.state.dontAskAgain, onChange: () => this.setState(({ dontAskAgain }) => ({ dontAskAgain: !dontAskAgain })) }),
|
|
139
|
-
text.dontAskAgain)),
|
|
140
136
|
React.createElement("span", null,
|
|
141
137
|
React.createElement("button", { type: "button", onClick: onCancel }, text.cancel),
|
|
142
138
|
React.createElement("button", { type: "button", className: "tw-palette-visibility-apply", onClick: () => this.apply() }, text.apply)))));
|
|
@@ -29,16 +29,25 @@ export function attachSpriteRestoreHistory({ store, vm, limit = spriteRestoreLim
|
|
|
29
29
|
const previous = last;
|
|
30
30
|
last = current;
|
|
31
31
|
if (current.restoreFun) {
|
|
32
|
-
if (current.deletedItem
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
if (current.deletedItem !== sprite)
|
|
33
|
+
return;
|
|
34
|
+
const index = stack.indexOf(current.restoreFun);
|
|
35
|
+
if (index >= 0) {
|
|
36
|
+
// A restore function already kept came back to the slot: TurboWarp's delete
|
|
37
|
+
// confirmation puts the slot back as it was when the user cancels. The ones kept
|
|
38
|
+
// after it belong to deletions that did not happen.
|
|
39
|
+
stack.splice(index + 1);
|
|
40
|
+
return;
|
|
36
41
|
}
|
|
42
|
+
stack.push(current.restoreFun);
|
|
43
|
+
if (stack.length > Math.max(1, limit))
|
|
44
|
+
stack.splice(0, stack.length - Math.max(1, limit));
|
|
37
45
|
return;
|
|
38
46
|
}
|
|
39
47
|
// The menu restored what the slot held and cleared it.
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
const used = previous.restoreFun ? stack.indexOf(previous.restoreFun) : -1;
|
|
49
|
+
if (used >= 0)
|
|
50
|
+
stack.splice(used, 1);
|
|
42
51
|
const next = stack.at(-1);
|
|
43
52
|
if (next)
|
|
44
53
|
store.dispatch({ type: RESTORE_UPDATE, state: { restoreFun: next, deletedItem: sprite } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-code-views",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|
|
@@ -16,8 +16,6 @@ export interface PaletteVisibilityChoice {
|
|
|
16
16
|
groups: string[];
|
|
17
17
|
/** Sets added in this dialog, to keep with the project. */
|
|
18
18
|
addedSets: PaletteGroupSet[];
|
|
19
|
-
/** For a new sprite: start the next new sprites with these groups instead of asking. */
|
|
20
|
-
dontAskAgain?: boolean;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export interface PaletteVisibilityDialogProps {
|
|
@@ -30,7 +28,7 @@ export interface PaletteVisibilityDialogProps {
|
|
|
30
28
|
used: ReadonlyMap<string, number>;
|
|
31
29
|
extensions: readonly PaletteExtension[];
|
|
32
30
|
sets: readonly PaletteGroupSet[];
|
|
33
|
-
/** Asked for a sprite just added:
|
|
31
|
+
/** Asked for a sprite just added: the screen names it as a new sprite. */
|
|
34
32
|
newSprite?: boolean;
|
|
35
33
|
onApply(choice: PaletteVisibilityChoice): void;
|
|
36
34
|
onCancel(): void;
|
|
@@ -49,14 +47,14 @@ const standardColors: Record<string, string> = {
|
|
|
49
47
|
const messages = {
|
|
50
48
|
en: {
|
|
51
49
|
title: 'Block groups shown in the palette', sprite: (name: string) => `Sprite “${name}”`, stage: 'Stage',
|
|
52
|
-
newSprite: (name: string) => `New sprite “${name}”`,
|
|
50
|
+
newSprite: (name: string) => `New sprite “${name}”`,
|
|
53
51
|
sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
|
|
54
52
|
standard: 'Standard block groups', extensions: 'Extension block groups', used: (count: number) => `In use ${count}`,
|
|
55
53
|
hiddenInUse: (count: number) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
|
|
56
54
|
},
|
|
57
55
|
ja: {
|
|
58
56
|
title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name: string) => `スプライト「${name}」`, stage: '背景',
|
|
59
|
-
newSprite: (name: string) => `新しいスプライト「${name}」`,
|
|
57
|
+
newSprite: (name: string) => `新しいスプライト「${name}」`,
|
|
60
58
|
sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
|
|
61
59
|
standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
|
|
62
60
|
hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
|
|
@@ -69,7 +67,6 @@ interface DialogState {
|
|
|
69
67
|
addedSets: PaletteGroupSet[];
|
|
70
68
|
naming: boolean;
|
|
71
69
|
setName: string;
|
|
72
|
-
dontAskAgain: boolean;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
/**
|
|
@@ -80,7 +77,7 @@ interface DialogState {
|
|
|
80
77
|
export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibilityDialogProps, DialogState> {
|
|
81
78
|
constructor(props: PaletteVisibilityDialogProps) {
|
|
82
79
|
super(props);
|
|
83
|
-
this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: ''
|
|
80
|
+
this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: ''};
|
|
84
81
|
}
|
|
85
82
|
get text() {
|
|
86
83
|
return isJapanese(this.props.locale) ? messages.ja : messages.en;
|
|
@@ -125,8 +122,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
|
|
|
125
122
|
}
|
|
126
123
|
apply() {
|
|
127
124
|
const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
|
|
128
|
-
this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets
|
|
129
|
-
...this.props.newSprite ? {dontAskAgain: this.state.dontAskAgain} : {}});
|
|
125
|
+
this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets});
|
|
130
126
|
}
|
|
131
127
|
render() {
|
|
132
128
|
const {locale, targetName, isStage, used, extensions, onCancel} = this.props;
|
|
@@ -210,13 +206,6 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
|
|
|
210
206
|
)}
|
|
211
207
|
<footer className="tw-palette-visibility-footer">
|
|
212
208
|
<span role="status">{hiddenInUse > 0 ? text.hiddenInUse(hiddenInUse) : ''}</span>
|
|
213
|
-
{this.props.newSprite && (
|
|
214
|
-
<label className="tw-palette-visibility-dont-ask">
|
|
215
|
-
<input type="checkbox" checked={this.state.dontAskAgain}
|
|
216
|
-
onChange={() => this.setState(({dontAskAgain}) => ({dontAskAgain: !dontAskAgain}))} />
|
|
217
|
-
{text.dontAskAgain}
|
|
218
|
-
</label>
|
|
219
|
-
)}
|
|
220
209
|
<span>
|
|
221
210
|
<button type="button" onClick={onCancel}>{text.cancel}</button>
|
|
222
211
|
<button type="button" className="tw-palette-visibility-apply" onClick={() => this.apply()}>
|
|
@@ -54,14 +54,22 @@ export function attachSpriteRestoreHistory({store, vm, limit = spriteRestoreLimi
|
|
|
54
54
|
const previous = last;
|
|
55
55
|
last = current;
|
|
56
56
|
if (current.restoreFun) {
|
|
57
|
-
if (current.deletedItem
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
if (current.deletedItem !== sprite) return;
|
|
58
|
+
const index = stack.indexOf(current.restoreFun);
|
|
59
|
+
if (index >= 0) {
|
|
60
|
+
// A restore function already kept came back to the slot: TurboWarp's delete
|
|
61
|
+
// confirmation puts the slot back as it was when the user cancels. The ones kept
|
|
62
|
+
// after it belong to deletions that did not happen.
|
|
63
|
+
stack.splice(index + 1);
|
|
64
|
+
return;
|
|
60
65
|
}
|
|
66
|
+
stack.push(current.restoreFun);
|
|
67
|
+
if (stack.length > Math.max(1, limit)) stack.splice(0, stack.length - Math.max(1, limit));
|
|
61
68
|
return;
|
|
62
69
|
}
|
|
63
70
|
// The menu restored what the slot held and cleared it.
|
|
64
|
-
|
|
71
|
+
const used = previous.restoreFun ? stack.indexOf(previous.restoreFun) : -1;
|
|
72
|
+
if (used >= 0) stack.splice(used, 1);
|
|
65
73
|
const next = stack.at(-1);
|
|
66
74
|
if (next) store.dispatch({type: RESTORE_UPDATE, state: {restoreFun: next, deletedItem: sprite}});
|
|
67
75
|
};
|