@kubohiroya/turbowarp-title-menu 0.2.1 → 0.2.3
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 +2 -2
- package/dist/extension-manifest.json +1 -1
- package/dist/turbowarp-title-menu.js +49 -7
- package/package.json +2 -2
- package/src/block-definitions.json +1 -1
- package/src/extension.ts +8 -1
package/README.ja.md
CHANGED
|
@@ -33,7 +33,7 @@ IndexedDBはoriginごとに分かれます。TurboWarp Web、TurboWarp Desktop
|
|
|
33
33
|
## インストール
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
pnpm add --save-exact @kubohiroya/turbowarp-title-menu@0.2.
|
|
36
|
+
pnpm add --save-exact @kubohiroya/turbowarp-title-menu@0.2.3
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
TurboWarpでは `dist/turbowarp-title-menu.js` をCustom Extensionとして読み込み、sandboxなしの実行を許可します。
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ The reviewed JavaScript build is committed to this repository, so users do not n
|
|
|
48
48
|
Install an exact version that you have reviewed:
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
pnpm add --save-exact @kubohiroya/turbowarp-title-menu@0.2.
|
|
51
|
+
pnpm add --save-exact @kubohiroya/turbowarp-title-menu@0.2.3
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Load the standalone bundle from:
|
|
@@ -60,7 +60,7 @@ node_modules/@kubohiroya/turbowarp-title-menu/dist/turbowarp-title-menu.js
|
|
|
60
60
|
A version-pinned CDN URL is:
|
|
61
61
|
|
|
62
62
|
```text
|
|
63
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-title-menu@0.2.
|
|
63
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-title-menu@0.2.3/dist/turbowarp-title-menu.js
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
## Quick start
|
|
@@ -237,6 +237,41 @@
|
|
|
237
237
|
const scalars = [...text];
|
|
238
238
|
return scalars.length <= limit ? text : `${scalars.slice(0, limit - 1).join("")}...`;
|
|
239
239
|
}
|
|
240
|
+
function applicationMenuGrid(count) {
|
|
241
|
+
const columns = count <= 4 ? 2 : count <= 12 ? 3 : 4;
|
|
242
|
+
const rows = Math.ceil(count / columns);
|
|
243
|
+
const top = 25.5556;
|
|
244
|
+
const bottom = rows <= 2 ? 80 : 90;
|
|
245
|
+
const gapX = columns === 2 ? 6.6667 : 3.3333;
|
|
246
|
+
const gapY = rows <= 2 ? 5.5556 : 2.7778;
|
|
247
|
+
const width = (80 - (columns - 1) * gapX) / columns;
|
|
248
|
+
const height = (bottom - top - (rows - 1) * gapY) / rows;
|
|
249
|
+
const scale = Math.min(1, width / 36.6667, height / 24.4444);
|
|
250
|
+
const percent = (value) => `${Number(value.toFixed(4))}%`;
|
|
251
|
+
return {
|
|
252
|
+
cell(index) {
|
|
253
|
+
const row = Math.floor(index / columns);
|
|
254
|
+
const column = index % columns;
|
|
255
|
+
if (count <= 4) {
|
|
256
|
+
return {
|
|
257
|
+
left: column === 0 ? "10%" : "53.3333%",
|
|
258
|
+
top: `${25.5556 + row * 30}%`,
|
|
259
|
+
width: "36.6667%",
|
|
260
|
+
height: "24.4444%"
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
left: percent(10 + column * (width + gapX)),
|
|
265
|
+
top: percent(top + row * (height + gapY)),
|
|
266
|
+
width: percent(width),
|
|
267
|
+
height: percent(height)
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
cqw(size) {
|
|
271
|
+
return `${count <= 4 ? size : Number((size * scale).toFixed(4))}cqw`;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
240
275
|
function createAppShellApplicationMenu(options) {
|
|
241
276
|
if (!isRecord$1(options))
|
|
242
277
|
throw new TypeError("application menu options must be an object.");
|
|
@@ -273,6 +308,7 @@
|
|
|
273
308
|
const buttons = /* @__PURE__ */ new Map();
|
|
274
309
|
const seen = /* @__PURE__ */ new Set();
|
|
275
310
|
let locale = optionalString(options.initialLocale, "initialLocale") ?? resolveAppShellLocale();
|
|
311
|
+
const grid = applicationMenuGrid(options.actions.length);
|
|
276
312
|
for (const [index, definition] of options.actions.entries()) {
|
|
277
313
|
if (!isRecord$1(definition))
|
|
278
314
|
throw new TypeError(`actions.${index} must be an object.`);
|
|
@@ -294,17 +330,16 @@
|
|
|
294
330
|
const button = document.createElement("button");
|
|
295
331
|
const iconElement = document.createElement("span");
|
|
296
332
|
const label = document.createElement("span");
|
|
297
|
-
const
|
|
298
|
-
const column = index % 2;
|
|
333
|
+
const cell = grid.cell(index);
|
|
299
334
|
button.type = "button";
|
|
300
335
|
button.setAttribute("data-turbowarp-app-shell-menu-action", id);
|
|
301
|
-
button.style.cssText = `position:absolute;left:${
|
|
336
|
+
button.style.cssText = `position:absolute;left:${cell.left};top:${cell.top};width:${cell.width};height:${cell.height};display:flex;min-width:0;min-height:0;align-items:center;justify-content:center;flex-direction:column;gap:.4167cqw;border:.4167cqw solid #005f50;border-radius:2.9167cqw;background:#007d66;color:#fff;box-shadow:0 .625cqw 1.6667cqw rgba(0,0,0,.2);cursor:pointer;font:inherit;`;
|
|
302
337
|
button.style.cursor = "pointer";
|
|
303
338
|
applyTestId(button, testId);
|
|
304
339
|
applyAttributes(button, actionAttributes);
|
|
305
340
|
iconElement.setAttribute("aria-hidden", "true");
|
|
306
|
-
iconElement.style.cssText =
|
|
307
|
-
label.style.cssText =
|
|
341
|
+
iconElement.style.cssText = `display:inline-flex;width:${grid.cqw(10)};height:${grid.cqw(10)};align-items:center;justify-content:center;line-height:1;font-size:${grid.cqw(6)};`;
|
|
342
|
+
label.style.cssText = `font-size:${grid.cqw(3.8)};line-height:1.15;text-align:center;`;
|
|
308
343
|
button.appendChild(iconElement);
|
|
309
344
|
button.appendChild(label);
|
|
310
345
|
const onClick = (event) => {
|
|
@@ -1183,7 +1218,7 @@
|
|
|
1183
1218
|
});
|
|
1184
1219
|
}
|
|
1185
1220
|
const extensionName = "TurboWarp Title Menu";
|
|
1186
|
-
const menus = { "menuActions": { "acceptReporters":
|
|
1221
|
+
const menus = { "menuActions": { "acceptReporters": false, "items": "menuActionItems" } };
|
|
1187
1222
|
const blocks = [{ "opcode": "showTitle", "blockType": "COMMAND", "text": "show title dialog", "description": "Shows the configured title dialog above the TurboWarp stage." }, { "opcode": "showMenu", "blockType": "COMMAND", "text": "show application menu", "description": "Shows the application menu above the TurboWarp stage." }, { "opcode": "addAppMenuAction", "blockType": "COMMAND", "text": "add app menu action [ACTION] labelled [LABEL]", "description": "Adds an application menu action this project owns, or relabels one it already added.", "arguments": { "ACTION": { "type": "STRING", "defaultValue": "start" }, "LABEL": { "type": "STRING", "defaultValue": "Start" } } }, { "opcode": "clearAppMenuActions", "blockType": "COMMAND", "text": "clear app menu actions", "description": "Removes every application menu action, including the built-in ones, so a project can define its own set." }, { "opcode": "setAppMenuActionEnabled", "blockType": "COMMAND", "text": "set app menu action [ACTION] enabled [ENABLED]", "description": "Enables or disables one application menu action.", "arguments": { "ACTION": { "type": "STRING", "menu": "menuActions" }, "ENABLED": { "type": "BOOLEAN", "defaultValue": true } } }, { "opcode": "whenAppMenuActionSelected", "blockType": "HAT", "text": "when app menu action [ACTION] selected", "description": "Runs when the operator selects the named application menu action.", "arguments": { "ACTION": { "type": "STRING", "menu": "menuActions" } } }, { "opcode": "showDslFiles", "blockType": "COMMAND", "text": "show DSL file manager", "description": "Shows the dialog that adds, opens, renames, deletes, and sorts stored DSL files." }, { "opcode": "whenDslSourceOpened", "blockType": "HAT", "text": "when a DSL source is opened", "description": "Runs after the operator opens a stored DSL file, or after the opened source is announced again." }, { "opcode": "reloadOpenedDsl", "blockType": "COMMAND", "text": "reload the opened DSL source", "description": "Announces the currently opened DSL source again without showing a dialog." }, { "opcode": "openedDslName", "blockType": "REPORTER", "text": "opened DSL file name", "description": "Returns the name of the DSL file that is currently open, or an empty string." }, { "opcode": "openedDslSource", "blockType": "REPORTER", "text": "opened DSL source", "description": "Returns the text of the DSL file that is currently open, or an empty string." }, { "opcode": "hasSavedDsl", "blockType": "BOOLEAN", "text": "has a saved DSL file?", "description": "Reports whether at least one DSL file is stored in IndexedDB." }, { "opcode": "savedDslCount", "blockType": "REPORTER", "text": "saved DSL file count", "description": "Returns how many DSL files are stored in IndexedDB." }, { "opcode": "lastDslError", "blockType": "REPORTER", "text": "last DSL storage error", "description": "Returns the most recent DSL storage failure in the interface language, or an empty string." }];
|
|
1188
1223
|
const definitions = {
|
|
1189
1224
|
extensionName,
|
|
@@ -1319,7 +1354,14 @@
|
|
|
1319
1354
|
this.ensureApplicationMenu().show(this.locale());
|
|
1320
1355
|
this.menuVisible = true;
|
|
1321
1356
|
}
|
|
1322
|
-
/**
|
|
1357
|
+
/**
|
|
1358
|
+
* Backs the dynamic `menuActions` dropdown, so it always lists what the project registered.
|
|
1359
|
+
*
|
|
1360
|
+
* The menu must refuse reporters. Scratch turns a reporter-accepting menu argument into an input
|
|
1361
|
+
* holding a shadow block, and `startHats` matches a hat against its *fields*, so the action hat
|
|
1362
|
+
* would never fire for a specific action. Refusing reporters keeps the argument an inline
|
|
1363
|
+
* dropdown, which is what the match reads.
|
|
1364
|
+
*/
|
|
1323
1365
|
menuActionItems() {
|
|
1324
1366
|
if (this.menuActions.length === 0) return [{ text: "—", value: "" }];
|
|
1325
1367
|
const locale = this.locale();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-title-menu",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Reusable title, application menu, and DSL source storage controls for TurboWarp.",
|
|
5
5
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -79,6 +79,6 @@
|
|
|
79
79
|
"vitest": "^4.1.10"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@kubohiroya/turbowarp-app-shell": "0.2.
|
|
82
|
+
"@kubohiroya/turbowarp-app-shell": "0.2.1"
|
|
83
83
|
}
|
|
84
84
|
}
|
package/src/extension.ts
CHANGED
|
@@ -94,7 +94,14 @@ export class TurboWarpTitleMenuExtension implements TurboWarpExtension {
|
|
|
94
94
|
this.menuVisible = true;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Backs the dynamic `menuActions` dropdown, so it always lists what the project registered.
|
|
99
|
+
*
|
|
100
|
+
* The menu must refuse reporters. Scratch turns a reporter-accepting menu argument into an input
|
|
101
|
+
* holding a shadow block, and `startHats` matches a hat against its *fields*, so the action hat
|
|
102
|
+
* would never fire for a specific action. Refusing reporters keeps the argument an inline
|
|
103
|
+
* dropdown, which is what the match reads.
|
|
104
|
+
*/
|
|
98
105
|
public menuActionItems(): Array<{text: string; value: string}> {
|
|
99
106
|
if (this.menuActions.length === 0) return [{text: '\u2014', value: ''}];
|
|
100
107
|
const locale = this.locale();
|