@stoa-dev/app-menu 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ruben Giannotti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,65 @@
1
- # Temporary Holding Version
1
+ # @stoa-dev/app-menu
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Standard-Anwendungsmenüs für Tauri-2-Apps: App-Menü (macOS), Darstellung, Fenster
4
+ und Hilfe. Die Bausteine liefern `SubmenuOptions` für `Submenu.new()` aus
5
+ `@tauri-apps/api/menu` und sind in allen STOA-Apps gleich; App-spezifisch bleiben
6
+ Ablage, Bearbeiten und eigene Einträge.
7
+
8
+ ```bash
9
+ npm i @stoa-dev/app-menu
10
+ ```
11
+
12
+ `@tauri-apps/api` (Version 2) ist Peer-Abhängigkeit und wird nur für die Typen
13
+ gebraucht; das Paket selbst hat keine Laufzeit-Abhängigkeiten.
14
+
15
+ ## Inhalt
16
+
17
+ | Export | Zweck |
18
+ |---|---|
19
+ | `buildStandardAppMenu(about, options?)` | macOS-App-Menü: Über, Dienste, Ausblenden, Andere ausblenden, Beenden |
20
+ | `buildStandardViewMenu(text)` | Darstellung mit „Vollbild“ |
21
+ | `buildStandardWindowMenu(text, { mac? })` | Fenster: Minimieren, Maximieren, Schließen (macOS mit Trennlinie) |
22
+ | `buildStandardHelpMenu(text, about, { mac?, ...options })` | Hilfe: auf macOS leer, sonst mit „Über“ |
23
+ | `isMac()` | `true` auf macOS, `false` ohne `navigator` (Tests) |
24
+ | `computeShortVersion(version)` | `"1.4.2"` → `"1.4"` |
25
+ | `About`, `AboutOptions`, `PlatformOptions` | Typen |
26
+
27
+ `options` (`AboutOptions`) überschreibt `copyright` und `credits` im Über-Fenster;
28
+ Standard ist „Copyright © ‹Jahr› STOA“ und „Entwickelt von STOA“. `{ mac }` legt die
29
+ Plattform fest, sonst wird sie aus dem User-Agent gelesen. Jedes Über-Element
30
+ bekommt eine eigene Kopie der Metadaten, weil Tauri `icon` an Ort und Stelle durch
31
+ seine Ressourcen-ID ersetzt.
32
+
33
+ ## Beispiel
34
+
35
+ ```ts
36
+ import { defaultWindowIcon, getName, getVersion } from '@tauri-apps/api/app'
37
+ import { Menu, Submenu } from '@tauri-apps/api/menu'
38
+ import {
39
+ buildStandardAppMenu,
40
+ buildStandardHelpMenu,
41
+ buildStandardViewMenu,
42
+ buildStandardWindowMenu,
43
+ isMac,
44
+ } from '@stoa-dev/app-menu'
45
+
46
+ const [name, version, icon] = await Promise.all([getName(), getVersion(), defaultWindowIcon()])
47
+ const about = { name, version, icon: icon ?? undefined }
48
+ const mac = isMac()
49
+
50
+ const appMenu = mac ? [await Submenu.new(buildStandardAppMenu(about))] : []
51
+ const fileMenu = await Submenu.new({
52
+ text: mac ? 'Ablage' : 'Datei',
53
+ items: [{ item: 'CloseWindow' }, ...(mac ? [] : [{ item: 'Quit' } as const])],
54
+ })
55
+ const viewMenu = mac ? [await Submenu.new(buildStandardViewMenu('Darstellung'))] : []
56
+ const windowMenu = await Submenu.new(buildStandardWindowMenu('Fenster'))
57
+ const helpMenu = await Submenu.new(buildStandardHelpMenu('Hilfe', about))
58
+
59
+ const menu = await Menu.new({ items: [...appMenu, fileMenu, ...viewMenu, windowMenu, helpMenu] })
60
+ await menu.setAsAppMenu()
61
+ if (mac) {
62
+ await windowMenu.setAsWindowsMenuForNSApp()
63
+ await helpMenu.setAsHelpMenuForNSApp()
64
+ }
65
+ ```
@@ -0,0 +1,38 @@
1
+ import type { Image } from '@tauri-apps/api/image';
2
+ import type { SubmenuOptions } from '@tauri-apps/api/menu';
3
+ /** What the About panel shows. */
4
+ export type About = {
5
+ name: string;
6
+ version: string;
7
+ icon?: Image;
8
+ };
9
+ /** Overrides for the About panel; defaults name STOA. */
10
+ export type AboutOptions = {
11
+ /** Defaults to "Copyright © <current year> STOA". */
12
+ copyright?: string;
13
+ /** Defaults to "Entwickelt von STOA\nhttps://stoa.berlin". */
14
+ credits?: string;
15
+ };
16
+ /** Pins the platform instead of reading the user agent, e.g. in tests. */
17
+ export type PlatformOptions = {
18
+ mac?: boolean;
19
+ };
20
+ /** True on macOS; false where there is no `navigator` (tests, SSR). */
21
+ export declare function isMac(): boolean;
22
+ /** "1.2.3" → "1.2", "4" → "4". */
23
+ export declare function computeShortVersion(longVersion: string): string;
24
+ /**
25
+ * The macOS app menu (the first submenu, named after the app): About,
26
+ * Services, Hide, Hide Others and Quit.
27
+ */
28
+ export declare function buildStandardAppMenu(about: About, options?: AboutOptions): SubmenuOptions;
29
+ /** View menu with the native full screen toggle (macOS). */
30
+ export declare function buildStandardViewMenu(text: string): SubmenuOptions;
31
+ /** Window menu: Minimize, Maximize and Close; macOS adds a separator. */
32
+ export declare function buildStandardWindowMenu(text: string, { mac }?: PlatformOptions): SubmenuOptions;
33
+ /**
34
+ * Help menu. macOS shows "About" in the app menu, so it stays empty there
35
+ * (the OS adds its search field); elsewhere it holds the About item.
36
+ */
37
+ export declare function buildStandardHelpMenu(text: string, about: About, { mac, ...options }?: PlatformOptions & AboutOptions): SubmenuOptions;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAEzE,kCAAkC;AAClC,MAAM,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,KAAK,CAAA;CACZ,CAAA;AAED,yDAAyD;AACzD,MAAM,MAAM,YAAY,GAAG;IAC1B,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG;IAC7B,GAAG,CAAC,EAAE,OAAO,CAAA;CACb,CAAA;AAED,uEAAuE;AACvE,wBAAgB,KAAK,YAEpB;AAED,kCAAkC;AAClC,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,UAGtD;AAmBD;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,YAAiB,GACxB,cAAc,CAchB;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAKlE;AAED,yEAAyE;AACzE,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,EAAE,GAAa,EAAE,GAAE,eAAoB,GACrC,cAAc,CAUhB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,EACZ,EAAE,GAAa,EAAE,GAAG,OAAO,EAAE,GAAE,eAAe,GAAG,YAAiB,GAChE,cAAc,CAKhB"}
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ /** True on macOS; false where there is no `navigator` (tests, SSR). */
2
+ export function isMac() {
3
+ return typeof navigator !== 'undefined' && navigator.userAgent.includes('Mac');
4
+ }
5
+ /** "1.2.3" → "1.2", "4" → "4". */
6
+ export function computeShortVersion(longVersion) {
7
+ const [major, minor] = longVersion.split('.');
8
+ return minor === undefined ? major : `${major}.${minor}`;
9
+ }
10
+ /**
11
+ * About metadata as a fresh object: Tauri's JS replaces `icon` in place with
12
+ * its resource id, so every About item needs its own copy.
13
+ */
14
+ function aboutMetadata(about, options = {}) {
15
+ return {
16
+ ...about,
17
+ shortVersion: computeShortVersion(about.version),
18
+ copyright: options.copyright ?? `Copyright © ${new Date().getFullYear()} STOA`,
19
+ credits: options.credits ?? 'Entwickelt von STOA\nhttps://stoa.berlin',
20
+ };
21
+ }
22
+ /**
23
+ * The macOS app menu (the first submenu, named after the app): About,
24
+ * Services, Hide, Hide Others and Quit.
25
+ */
26
+ export function buildStandardAppMenu(about, options = {}) {
27
+ return {
28
+ text: about.name,
29
+ items: [
30
+ { item: { About: aboutMetadata(about, options) } },
31
+ { item: 'Separator' },
32
+ { item: 'Services' },
33
+ { item: 'Separator' },
34
+ { item: 'Hide' },
35
+ { item: 'HideOthers' },
36
+ { item: 'Separator' },
37
+ { item: 'Quit' },
38
+ ],
39
+ };
40
+ }
41
+ /** View menu with the native full screen toggle (macOS). */
42
+ export function buildStandardViewMenu(text) {
43
+ return {
44
+ text,
45
+ items: [{ item: 'Fullscreen' }],
46
+ };
47
+ }
48
+ /** Window menu: Minimize, Maximize and Close; macOS adds a separator. */
49
+ export function buildStandardWindowMenu(text, { mac = isMac() } = {}) {
50
+ return {
51
+ text,
52
+ items: [
53
+ { item: 'Minimize' },
54
+ { item: 'Maximize' },
55
+ ...(mac ? [{ item: 'Separator' }] : []),
56
+ { item: 'CloseWindow' },
57
+ ],
58
+ };
59
+ }
60
+ /**
61
+ * Help menu. macOS shows "About" in the app menu, so it stays empty there
62
+ * (the OS adds its search field); elsewhere it holds the About item.
63
+ */
64
+ export function buildStandardHelpMenu(text, about, { mac = isMac(), ...options } = {}) {
65
+ return {
66
+ text,
67
+ items: mac ? [] : [{ item: { About: aboutMetadata(about, options) } }],
68
+ };
69
+ }
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,uEAAuE;AACvE,MAAM,UAAU,KAAK;IACpB,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC/E,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,mBAAmB,CAAC,WAAmB;IACtD,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC7C,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,KAAK,EAAE,CAAA;AACzD,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CACrB,KAAY,EACZ,UAAwB,EAAE;IAE1B,OAAO;QACN,GAAG,KAAK;QACR,YAAY,EAAE,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC;QAChD,SAAS,EACR,OAAO,CAAC,SAAS,IAAI,eAAe,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,OAAO;QACpE,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,0CAA0C;KACtE,CAAA;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,C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AAC,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;KACtE,CAAA;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@stoa-dev/app-menu",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Standard Tauri 2 application menus (app, view, window, help) for STOA apps",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/giannotr/stoa-dev.git",
9
+ "directory": "packages/app-menu"
10
+ },
11
+ "homepage": "https://github.com/giannotr/stoa-dev/tree/main/packages/app-menu#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/giannotr/stoa-dev/issues"
14
+ },
15
+ "keywords": [
16
+ "tauri",
17
+ "menu",
18
+ "app-menu",
19
+ "stoa"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -p tsconfig.build.json",
37
+ "typecheck": "tsc --noEmit -p tsconfig.json",
38
+ "test": "vitest run --config vitest.config.ts",
39
+ "prepublishOnly": "npm run build"
40
+ },
41
+ "peerDependencies": {
42
+ "@tauri-apps/api": "^2.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@stoa-dev/tsconfig": "*",
46
+ "@tauri-apps/api": "2.11.0",
47
+ "typescript": "~5.8.3"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }