@stoa-dev/app-menu 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog — @stoa-dev/app-menu
2
+
3
+ ## 0.2.0
4
+
5
+ - `setupStandardAppMenu(options)`: baut die ganze Menüleiste wie Tauris Standardmenü,
6
+ lädt Name, Version und Icon, meldet auf macOS Fenster- und Hilfe-Menü an und baut
7
+ bei `subscribe`-Meldungen (z. B. Sprachwechsel) der Reihe nach neu auf. Die App
8
+ liefert nur Beschriftungen und optional eigene Ablage-/Bearbeiten-Menüs sowie
9
+ `extraMenus`. Unabhängig von einer Übersetzungsbibliothek.
10
+ - `buildStandardFileMenu`, `buildStandardEditMenu` als Vorlagen.
11
+
12
+ ## 0.1.0
13
+
14
+ - `buildStandardAppMenu`, `buildStandardViewMenu`, `buildStandardWindowMenu`,
15
+ `buildStandardHelpMenu`, `isMac`, `computeShortVersion`, Typ `About`.
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,117 @@
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. `setupStandardAppMenu()` baut die ganze
4
+ Menüleiste so auf wie Tauris Standardmenü (App-Menü auf macOS, Ablage, Bearbeiten,
5
+ Darstellung, Fenster, Hilfe) und baut sie bei Sprachwechseln neu auf. Die App
6
+ liefert nur die Beschriftungen und, wenn sie möchte, eigene Ablage- und
7
+ Bearbeiten-Menüs.
8
+
9
+ ```bash
10
+ npm i @stoa-dev/app-menu
11
+ ```
12
+
13
+ `@tauri-apps/api` (Version 2) ist Peer-Abhängigkeit. Eine Übersetzungsbibliothek
14
+ braucht das Paket nicht: Beschriftungen und Sprachwechsel kommen über Callbacks.
15
+
16
+ ## Schnellstart
17
+
18
+ So sieht `src/lib/menu.ts` einer App damit aus (hier mit i18next):
19
+
20
+ ```ts
21
+ import { setupStandardAppMenu } from '@stoa-dev/app-menu'
22
+ import i18next from 'i18next'
23
+
24
+ const scope = 'common.app.menu'
25
+
26
+ export async function setupAppMenu() {
27
+ if (!i18next.isInitialized)
28
+ await new Promise((resolve) => i18next.on('initialized', resolve))
29
+
30
+ return setupStandardAppMenu({
31
+ labels: ({ mac }) => ({
32
+ file: i18next.t(mac ? `${scope}.fileMac` : `${scope}.file`),
33
+ edit: i18next.t(`${scope}.edit`),
34
+ view: i18next.t(`${scope}.view`),
35
+ window: i18next.t(`${scope}.window`),
36
+ help: i18next.t(`${scope}.help`),
37
+ }),
38
+ // Optional; ohne diese beiden gelten buildStandardFileMenu/-EditMenu.
39
+ fileMenu: ({ labels, mac }) => ({
40
+ text: labels.file,
41
+ items: [{ item: 'CloseWindow' }, ...(mac ? [] : [{ item: 'Quit' } as const])],
42
+ }),
43
+ editMenu: ({ labels }) => ({
44
+ text: labels.edit,
45
+ items: [{ item: 'Undo' }, { item: 'Redo' }, { item: 'Separator' }, { item: 'Cut' }, { item: 'Copy' }, { item: 'Paste' }, { item: 'SelectAll' }],
46
+ }),
47
+ subscribe: (rebuild) => {
48
+ i18next.on('languageChanged', rebuild)
49
+ return () => i18next.off('languageChanged', rebuild)
50
+ },
51
+ })
52
+ }
53
+ ```
54
+
55
+ `setupStandardAppMenu` tut außerhalb von Tauri nichts (Browser-Vorschau), lädt Name,
56
+ Version und Icon der App, setzt das Menü, meldet auf macOS Fenster- und Hilfe-Menü
57
+ an, baut bei jedem `rebuild()` neu auf (der Reihe nach, das alte Menü wird
58
+ geschlossen) und liefert eine Funktion zum Beenden zurück. Weitere Optionen:
59
+ `extraMenus` (eigene Menüs zwischen Bearbeiten und Darstellung), `about`
60
+ (Copyright und Credits), `onError`.
61
+
62
+ ## Inhalt
63
+
64
+ | Export | Zweck |
65
+ |---|---|
66
+ | `setupStandardAppMenu(options)` | ganze Menüleiste setzen und aktuell halten (siehe oben) |
67
+ | `buildStandardFileMenu(text, { mac? })` | Ablage: Fenster schließen, außerhalb von macOS auch Beenden |
68
+ | `buildStandardEditMenu(text)` | Bearbeiten: Widerrufen, Wiederholen, Ausschneiden, Kopieren, Einsetzen, Alles auswählen |
69
+ | `buildStandardAppMenu(about, options?)` | macOS-App-Menü: Über, Dienste, Ausblenden, Andere ausblenden, Beenden |
70
+ | `buildStandardViewMenu(text)` | Darstellung mit „Vollbild“ |
71
+ | `buildStandardWindowMenu(text, { mac? })` | Fenster: Minimieren, Maximieren, Schließen (macOS mit Trennlinie) |
72
+ | `buildStandardHelpMenu(text, about, { mac?, ...options })` | Hilfe: auf macOS leer, sonst mit „Über“ |
73
+ | `isMac()` | `true` auf macOS, `false` ohne `navigator` (Tests) |
74
+ | `computeShortVersion(version)` | `"1.4.2"` → `"1.4"` |
75
+ | `About`, `AboutOptions`, `PlatformOptions`, `AppMenuLabels`, `AppMenuContext`, `StandardAppMenuOptions` | Typen |
76
+
77
+ `options` (`AboutOptions`) überschreibt `copyright` und `credits` im Über-Fenster;
78
+ Standard ist „Copyright © ‹Jahr› STOA“ und „Entwickelt von STOA“. `{ mac }` legt die
79
+ Plattform fest, sonst wird sie aus dem User-Agent gelesen. Jedes Über-Element
80
+ bekommt eine eigene Kopie der Metadaten, weil Tauri `icon` an Ort und Stelle durch
81
+ seine Ressourcen-ID ersetzt.
82
+
83
+ ## Einzelne Bausteine
84
+
85
+ Wer die Menüleiste selbst zusammensetzen will, nutzt die Builder direkt:
86
+
87
+ ```ts
88
+ import { defaultWindowIcon, getName, getVersion } from '@tauri-apps/api/app'
89
+ import { Menu, Submenu } from '@tauri-apps/api/menu'
90
+ import {
91
+ buildStandardAppMenu,
92
+ buildStandardHelpMenu,
93
+ buildStandardViewMenu,
94
+ buildStandardWindowMenu,
95
+ isMac,
96
+ } from '@stoa-dev/app-menu'
97
+
98
+ const [name, version, icon] = await Promise.all([getName(), getVersion(), defaultWindowIcon()])
99
+ const about = { name, version, icon: icon ?? undefined }
100
+ const mac = isMac()
101
+
102
+ const appMenu = mac ? [await Submenu.new(buildStandardAppMenu(about))] : []
103
+ const fileMenu = await Submenu.new({
104
+ text: mac ? 'Ablage' : 'Datei',
105
+ items: [{ item: 'CloseWindow' }, ...(mac ? [] : [{ item: 'Quit' } as const])],
106
+ })
107
+ const viewMenu = mac ? [await Submenu.new(buildStandardViewMenu('Darstellung'))] : []
108
+ const windowMenu = await Submenu.new(buildStandardWindowMenu('Fenster'))
109
+ const helpMenu = await Submenu.new(buildStandardHelpMenu('Hilfe', about))
110
+
111
+ const menu = await Menu.new({ items: [...appMenu, fileMenu, ...viewMenu, windowMenu, helpMenu] })
112
+ await menu.setAsAppMenu()
113
+ if (mac) {
114
+ await windowMenu.setAsWindowsMenuForNSApp()
115
+ await helpMenu.setAsHelpMenuForNSApp()
116
+ }
117
+ ```
@@ -0,0 +1,45 @@
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
+ /**
39
+ * File menu as in the STOA apps: Close Window, plus Quit where there is no
40
+ * macOS app menu to hold it.
41
+ */
42
+ export declare function buildStandardFileMenu(text: string, { mac }?: PlatformOptions): SubmenuOptions;
43
+ /** Edit menu with the native Undo, Redo, Cut, Copy, Paste and Select All. */
44
+ export declare function buildStandardEditMenu(text: string): SubmenuOptions;
45
+ //# sourceMappingURL=builders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.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;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,EAAE,GAAa,EAAE,GAAE,eAAoB,GACrC,cAAc,CAQhB;AAED,6EAA6E;AAC7E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAalE"}
@@ -0,0 +1,98 @@
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
+ /**
71
+ * File menu as in the STOA apps: Close Window, plus Quit where there is no
72
+ * macOS app menu to hold it.
73
+ */
74
+ export function buildStandardFileMenu(text, { mac = isMac() } = {}) {
75
+ return {
76
+ text,
77
+ items: [
78
+ { item: 'CloseWindow' },
79
+ ...(mac ? [] : [{ item: 'Quit' }]),
80
+ ],
81
+ };
82
+ }
83
+ /** Edit menu with the native Undo, Redo, Cut, Copy, Paste and Select All. */
84
+ export function buildStandardEditMenu(text) {
85
+ return {
86
+ text,
87
+ items: [
88
+ { item: 'Undo' },
89
+ { item: 'Redo' },
90
+ { item: 'Separator' },
91
+ { item: 'Cut' },
92
+ { item: 'Copy' },
93
+ { item: 'Paste' },
94
+ { item: 'SelectAll' },
95
+ ],
96
+ };
97
+ }
98
+ //# sourceMappingURL=builders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.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,GA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EAAE;YACjB,EAAE,IAAI,EAAE,WAAW,EAAE;SACrB;KACD,CAAA;AACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './builders';
2
+ export * from './setup';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './builders';
2
+ export * from './setup';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { type SubmenuOptions } from '@tauri-apps/api/menu';
2
+ import { type About, type AboutOptions } from './builders';
3
+ /** Submenu names; re-read on every build so they follow the app language. */
4
+ export type AppMenuLabels = {
5
+ /** Usually "Ablage" on macOS and "Datei" elsewhere. */
6
+ file: string;
7
+ edit: string;
8
+ view: string;
9
+ window: string;
10
+ help: string;
11
+ };
12
+ /** What the app's own menu builders get. */
13
+ export type AppMenuContext = {
14
+ mac: boolean;
15
+ about: About;
16
+ labels: AppMenuLabels;
17
+ };
18
+ export type StandardAppMenuOptions = {
19
+ /** Called before each build, e.g. `() => ({ file: t('menu.file'), … })`. */
20
+ labels: (context: {
21
+ mac: boolean;
22
+ }) => AppMenuLabels;
23
+ /** Defaults to buildStandardFileMenu. */
24
+ fileMenu?: (context: AppMenuContext) => SubmenuOptions;
25
+ /** Defaults to buildStandardEditMenu. */
26
+ editMenu?: (context: AppMenuContext) => SubmenuOptions;
27
+ /** Extra menus between Edit and View, e.g. a "Library" menu. */
28
+ extraMenus?: (context: AppMenuContext) => SubmenuOptions[];
29
+ /** Copyright and credits in the About panel. */
30
+ about?: AboutOptions;
31
+ /**
32
+ * Rebuild trigger, e.g. language changes:
33
+ * `(rebuild) => { i18next.on('languageChanged', rebuild); return () => i18next.off('languageChanged', rebuild) }`
34
+ */
35
+ subscribe?: (rebuild: () => void) => (() => void) | undefined;
36
+ /** Defaults to console.error. */
37
+ onError?: (error: unknown) => void;
38
+ };
39
+ /**
40
+ * Builds and sets the app menu the way Tauri's default menu does
41
+ * (`Menu::default` in tauri 2): an app menu on macOS, then File, Edit, the
42
+ * extra menus, View (macOS only), Window and Help. Only File and Edit are
43
+ * app-specific. Rebuilds when `subscribe` reports a change and closes the
44
+ * previous menu. Outside Tauri it does nothing.
45
+ *
46
+ * Resolves to a function that stops the rebuilds.
47
+ */
48
+ export declare function setupStandardAppMenu({ labels, fileMenu, editMenu, extraMenus, about: aboutOptions, subscribe, onError, }: StandardAppMenuOptions): Promise<() => void>;
49
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EACN,KAAK,KAAK,EACV,KAAK,YAAY,EAQjB,MAAM,YAAY,CAAA;AAEnB,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG;IAC3B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,4CAA4C;AAC5C,MAAM,MAAM,cAAc,GAAG;IAC5B,GAAG,EAAE,OAAO,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;IACZ,MAAM,EAAE,aAAa,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACpC,4EAA4E;IAC5E,MAAM,EAAE,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,KAAK,aAAa,CAAA;IACpD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,cAAc,CAAA;IACtD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,cAAc,CAAA;IACtD,gEAAgE;IAChE,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,cAAc,EAAE,CAAA;IAC1D,gDAAgD;IAChD,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAA;IAC7D,iCAAiC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAClC,CAAA;AAeD;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,EAC1C,MAAM,EACN,QAA2E,EAC3E,QAA6D,EAC7D,UAAU,EACV,KAAK,EAAE,YAAY,EACnB,SAAS,EACT,OAAyE,GACzE,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAgE9C"}
package/dist/setup.js ADDED
@@ -0,0 +1,79 @@
1
+ import { defaultWindowIcon, getName, getVersion } from '@tauri-apps/api/app';
2
+ import { isTauri } from '@tauri-apps/api/core';
3
+ import { Menu, Submenu } from '@tauri-apps/api/menu';
4
+ import { buildStandardAppMenu, buildStandardEditMenu, buildStandardFileMenu, buildStandardHelpMenu, buildStandardViewMenu, buildStandardWindowMenu, isMac, } from './builders';
5
+ async function loadAbout(onError) {
6
+ const [name, version, icon] = await Promise.all([
7
+ getName(),
8
+ getVersion(),
9
+ // The app icon from tauri.conf.json, embedded into the binary at build time.
10
+ defaultWindowIcon().catch((error) => {
11
+ onError(error);
12
+ return null;
13
+ }),
14
+ ]);
15
+ return { name, version, icon: icon ?? undefined };
16
+ }
17
+ /**
18
+ * Builds and sets the app menu the way Tauri's default menu does
19
+ * (`Menu::default` in tauri 2): an app menu on macOS, then File, Edit, the
20
+ * extra menus, View (macOS only), Window and Help. Only File and Edit are
21
+ * app-specific. Rebuilds when `subscribe` reports a change and closes the
22
+ * previous menu. Outside Tauri it does nothing.
23
+ *
24
+ * Resolves to a function that stops the rebuilds.
25
+ */
26
+ export async function setupStandardAppMenu({ labels, fileMenu = ({ labels, mac }) => buildStandardFileMenu(labels.file, { mac }), editMenu = ({ labels }) => buildStandardEditMenu(labels.edit), extraMenus, about: aboutOptions, subscribe, onError = (error) => console.error('Building the app menu failed', error), }) {
27
+ if (!isTauri())
28
+ return () => { };
29
+ const mac = isMac();
30
+ const about = await loadAbout(onError);
31
+ async function build() {
32
+ const context = { mac, about, labels: labels({ mac }) };
33
+ const text = context.labels;
34
+ // macOS: the first submenu becomes the app menu, named after the app.
35
+ const appMenu = mac
36
+ ? [await Submenu.new(buildStandardAppMenu(about, aboutOptions))]
37
+ : [];
38
+ const ownMenus = await Promise.all([
39
+ fileMenu(context),
40
+ editMenu(context),
41
+ ...(extraMenus?.(context) ?? []),
42
+ ].map((options) => Submenu.new(options)));
43
+ const viewMenu = mac
44
+ ? [await Submenu.new(buildStandardViewMenu(text.view))]
45
+ : [];
46
+ const windowMenu = await Submenu.new(buildStandardWindowMenu(text.window, { mac }));
47
+ const helpMenu = await Submenu.new(buildStandardHelpMenu(text.help, about, { mac, ...aboutOptions }));
48
+ const menu = await Menu.new({
49
+ items: [...appMenu, ...ownMenus, ...viewMenu, windowMenu, helpMenu],
50
+ });
51
+ await menu.setAsAppMenu();
52
+ if (mac) {
53
+ // macOS adds the window list to this menu and the search field to Help.
54
+ await windowMenu.setAsWindowsMenuForNSApp();
55
+ await helpMenu.setAsHelpMenuForNSApp();
56
+ }
57
+ return menu;
58
+ }
59
+ let current = await build();
60
+ // Rebuilds run one after another, so a quick series of changes ends with the latest.
61
+ let queue = Promise.resolve();
62
+ let stopped = false;
63
+ const unsubscribe = subscribe?.(() => {
64
+ queue = queue
65
+ .then(async () => {
66
+ if (stopped)
67
+ return;
68
+ const next = await build();
69
+ void current.close();
70
+ current = next;
71
+ })
72
+ .catch(onError);
73
+ });
74
+ return () => {
75
+ stopped = true;
76
+ unsubscribe?.();
77
+ };
78
+ }
79
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAGN,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,GACL,MAAM,YAAY,CAAA;AAuCnB,KAAK,UAAU,SAAS,CAAC,OAAiC;IACzD,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC/C,OAAO,EAAE;QACT,UAAU,EAAE;QACZ,6EAA6E;QAC7E,iBAAiB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,CAAA;YACd,OAAO,IAAI,CAAA;QACZ,CAAC,CAAC;KACF,CAAC,CAAA;IACF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,SAAS,EAAE,CAAA;AAClD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EAC1C,MAAM,EACN,QAAQ,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC,IA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C,CAAA;IAEF,OAAO,GAAG,EAAE;QACX,OAAO,GAAG,IAAI,CAAA;QACd,WAAW,EAAE,EAAE,CAAA;IAChB,CAAC,CAAA;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,53 @@
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.2.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
+ "CHANGELOG.md",
27
+ "LICENSE"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.build.json",
38
+ "typecheck": "tsc --noEmit -p tsconfig.json",
39
+ "test": "vitest run --config vitest.config.ts",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "peerDependencies": {
43
+ "@tauri-apps/api": "^2.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@stoa-dev/tsconfig": "*",
47
+ "@tauri-apps/api": "2.11.0",
48
+ "typescript": "~5.8.3"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }