@x-tech-laboratories/x-app 0.104.0 → 0.105.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.md CHANGED
@@ -14,7 +14,7 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
14
14
  | `app/services` | An app's own work beside its calls, run by both hosts: `StartServices` gets a `HostContext` (`kind`, `database()`, `profile`, `device_name`, the server's raw `config`, `plugins_folder`, `declared_file` from `<PREFIX>_DECLARED_FILE` or `/etc/<id>/declared.json`, `announce`, `emit(event, data)` for the page's `on_event`, `side_database(name)` for a never-backed-up file such as `<base>-index.db`, `back_up`) and returns `HostServices` (`before_restore`, `after_restore`, `stop`), stopped before sync and the database. |
15
15
  | `app/links` | `app_link(scheme, route)` and `route_of_link(scheme, link)`: an app's links such as `x-notes://note/<id>` and the page route they open. |
16
16
  | `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window (`default_size` fixed or from the screen's free area, the daemon told while one is in front for its services' `window_in_front`), the tray (`show_tray_icon`, the app's own `tray` rows above Show, Quit and Quit completely, closing the last window leaving the app in it, `--hidden` starting there), the app's `link_scheme` links opening the window on their page (`route_of_link` to map them its own way; the page follows the `open` event), the login entry, a second launch and `--daemon`; the app's own `desktop_settings` switches sit in Settings → Desktop app beside the base's; `run_preload(app, electron)` puts every bridge on the page. Electron is handed in, so neither imports it. |
17
- | `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. The page API's `on_event(name, listener)` hears the named events the app's services `emit`, on the web and the desktop. |
17
+ | `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. The page API's `on_event(name, listener)` hears the named events the app's services `emit`, on the web and the desktop. A page may have an `icon` (the sidebar then shows icon rows), a `use_badge` hook ("Inbox · 3"), `in_sidebar: false` with `active_as` for a page reached only by its route; `default_page` names the page an empty route opens, and the `use_chrome(parts)` hook gives the `sidebar` content under the rows, header `tools` and a `side_pane`. |
18
18
  | `config/vite`, `config/electron_vite`, `config/vitest`, `config/tsconfig/*.json` | An X-app's configs as presets: `web_vite_config({ port })` and `android_vite_config()` for the page, `desktop_vite_config()` for electron-vite's window, daemon, preload and page, `vitest_config()` for tests in `tests/` in UTC with coverage of `src/` to the terminal, merged with the app's own floor so `autoUpdate` still raises it, and `base`, `node`, `web` and `tests` tsconfigs to extend. |
19
19
  | `app_new` | The `x-app-new <X-Name>` command: a new X-app's files written once, laid out as the Application Standard asks, on the base app, the presets, X-App's Nix lib and its CI actions, with an example notes feature; `--port`, `--folder`, `--no-desktop` and `--no-android`. |
20
20
  | `durations` | `parse_duration` for settings such as `"2h30m"`, `format_duration` in months down to seconds and "less than a second" below one, `format_age`, and `format_clock` for a playing time such as `"3:07"`, with `{ hours: "always" }` writing `"0:03:07"` so a column of times lines up and `empty` for no time. |
@@ -35,17 +35,24 @@ function SidebarFoot() {
35
35
  function Pages({ pages, account }) {
36
36
  const { app } = pages;
37
37
  const route = use_route();
38
- const [section = pages.pages[0]?.id ?? "settings", ...rest] = route.parts;
38
+ const [section = pages.default_page ?? pages.pages[0]?.id ?? "settings", ...rest] = route.parts;
39
39
  const shown = pages.pages.find((candidate) => candidate.id === section);
40
40
  const is_account = account !== null && section === "account";
41
41
  const label = shown?.label ?? (is_account ? "Your account" : "Settings");
42
42
  const view_key = route.parts.join("/");
43
+ const chrome = pages.use_chrome?.(route.parts) ?? {};
43
44
  useEffect(() => {
44
45
  document.title = `${label} · ${app.name}`;
45
46
  }, [label, app.name]);
46
- const sections = pages.pages.map((each) => ({ id: each.id, label: each.label, href: `#/${each.id}` }));
47
+ // Each listed page's badge, such as how many things wait, from its hook, called in the same order every time.
48
+ const listed = pages.pages.filter((each) => each.in_sidebar !== false);
49
+ const badges = listed.map((each) => each.use_badge?.() ?? null);
50
+ const row_label = (index) => (badges[index] ? `${listed[index].label} · ${badges[index]}` : listed[index].label);
51
+ const with_icons = listed.some((each) => each.icon);
52
+ const sections = listed.map((each, index) => ({ id: each.id, label: row_label(index), href: `#/${each.id}` }));
53
+ const views = listed.map((each, index) => ({ id: each.id, label: row_label(index), href: `#/${each.id}`, ...(each.icon ? { icon: each.icon } : {}) }));
47
54
  const view = shown ? shown.view(rest) : is_account ? _jsx(AccountPage, { account: account }) : _jsx(SettingsView, { pages: pages, is_admin: account === null || is_admin(account.me) });
48
- return (_jsx(Shell, { brand: app.name, brand_icon: pages.brand_icon ?? "icon.svg", sections: sections, active: section, theme: theme_choice(`${app.id}-theme`), view_key: view_key, user: account ? account.me.name : undefined, user_href: account ? "#/account" : undefined, on_logout: account ? () => void account.sign_out() : undefined, sidebar_foot: _jsx(SidebarFoot, {}), settings: { href: "#/settings" }, children: _jsx(Fragment, { children: view }, view_key) }));
55
+ return (_jsx(Shell, { brand: app.name, brand_icon: pages.brand_icon ?? "icon.svg", ...(with_icons ? { views } : { sections }), active: shown?.active_as ?? section, ...(chrome.sidebar ? { sidebar: chrome.sidebar } : {}), ...(chrome.tools ? { tools: chrome.tools } : {}), ...(chrome.side_pane ? { side_pane: chrome.side_pane } : {}), theme: theme_choice(`${app.id}-theme`), view_key: view_key, user: account ? account.me.name : undefined, user_href: account ? "#/account" : undefined, on_logout: account ? () => void account.sign_out() : undefined, sidebar_foot: _jsx(SidebarFoot, {}), settings: { href: "#/settings" }, children: _jsx(Fragment, { children: view }, view_key) }));
49
56
  }
50
57
  // ── App ──────────────────────────────────────────────────────────────────────
51
58
  // A browser reaches the server's data, so it signs in; the desktop and phone apps keep their own and sign in only to sync.
@@ -1,4 +1,6 @@
1
+ import type { IconGlyph } from "../../web/react/icons.tsx";
1
2
  import { type SettingsSection } from "../../web/react/layout.tsx";
3
+ import type { ShellSidePane } from "../../web/react/shell.tsx";
2
4
  import type { App } from "../define.ts";
3
5
  export interface PageSettingsProps {
4
6
  settings: Record<string, unknown>;
@@ -9,12 +11,23 @@ export interface AppPage {
9
11
  label: string;
10
12
  view: (parts: string[]) => React.ReactNode;
11
13
  settings?: (props: PageSettingsProps) => SettingsSection[];
14
+ icon?: IconGlyph;
15
+ use_badge?: () => number | string | null;
16
+ in_sidebar?: boolean;
17
+ active_as?: string;
18
+ }
19
+ export interface AppChrome {
20
+ sidebar?: React.ReactNode;
21
+ tools?: React.ReactNode;
22
+ side_pane?: ShellSidePane;
12
23
  }
13
24
  export interface AppPages {
14
25
  app: Pick<App, "id" | "name" | "data_name" | "server_example" | "bridges"> & Partial<Pick<App, "desktop_settings">>;
15
26
  pages: readonly AppPage[];
16
27
  general_settings?: (props: PageSettingsProps) => SettingsSection[];
17
28
  brand_icon?: string;
29
+ default_page?: string;
30
+ use_chrome?: (parts: readonly string[]) => AppChrome;
18
31
  }
19
32
  export declare function SettingsView({ pages, is_admin }: {
20
33
  pages: AppPages;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-tech-laboratories/x-app",
3
- "version": "0.104.0",
3
+ "version": "0.105.0",
4
4
  "description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {