@x-tech-laboratories/x-app 0.112.0 → 0.114.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 +10 -7
- package/dist/api_schemas.d.ts +8 -0
- package/dist/api_schemas.js +17 -0
- package/dist/app/define.d.ts +11 -0
- package/dist/app/define.js +25 -0
- package/dist/app/desktop.js +10 -1
- package/dist/app/item_history.d.ts +48 -0
- package/dist/app/item_history.js +117 -0
- package/dist/app/server.js +20 -2
- package/dist/app/web/android.d.ts +10 -0
- package/dist/app/web/android.js +31 -2
- package/dist/app/web/app_page.d.ts +1 -1
- package/dist/app/web/app_page.js +17 -7
- package/dist/app/web/item_history.d.ts +12 -0
- package/dist/app/web/item_history.js +87 -0
- package/dist/app/web/settings_page.d.ts +7 -0
- package/dist/caller.d.ts +5 -0
- package/dist/caller.js +11 -5
- package/dist/config/vitest.js +5 -2
- package/dist/dates.d.ts +2 -0
- package/dist/dates.js +9 -0
- package/dist/node_caller_scope.d.ts +2 -0
- package/dist/node_caller_scope.js +8 -0
- package/dist/web/react/day.d.ts +10 -0
- package/dist/web/react/day.js +32 -0
- package/dist/web/react/forms.d.ts +27 -0
- package/dist/web/react/forms.js +51 -0
- package/dist/web/react/lookup.d.ts +19 -0
- package/dist/web/react/lookup.js +33 -0
- package/dist/web/react/row_actions.d.ts +15 -0
- package/dist/web/react/row_actions.js +19 -0
- package/dist/web/react/toasts.d.ts +3 -0
- package/dist/web/react/toasts.js +22 -1
- package/dist/web/react/unit_number.d.ts +19 -0
- package/dist/web/react/unit_number.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
9
9
|
|
|
10
10
|
| Import | What it holds |
|
|
11
11
|
| ---------------------------------------- | ----------------------------------------------------------------------------- |
|
|
12
|
-
| `app/define` | The base app: `define_app` puts an X-app's name, ports, files, its own settings and its `define_feature` features (tables, migrations, calls, `api_spec`, settings, histories) together into one store every device keeps (`open_store` calling each feature's `on_open`, `needs_upgrade`, `bind_methods(database, on_change, caller)` running each call as its `caller`, calling each feature's `after_write`, recording versions and announcing writes, `is_read_only`), `page_only` (the specs' `page_only` calls and the writes of `user_only` settings, refused with `page_only_refusal`), its sync engine, its backups' names and schedule, and its bridges named after the app; `AppMethodsOf<typeof app>` types the app's calls. `history_days` sets how far an app's history reaches back until the user chooses (365 unless set); what opening changed is recorded as this device's version. |
|
|
13
|
-
| `app/server`, `app/daemon` | `run_server(app, { web_folder })`: the web server from `<PREFIX>_CONFIG` with accounts in `accounts.db` (moved there once from the data's own file, tokens starting with the app's `token_prefix`), the calls, OpenAPI, MCP, the server's backups and its sync peer, a token or MCP client refused the app's `page_only` calls and the `user_only_backup_calls` (restore, remove, schedule) and its calls run as the `program` caller; `run_daemon(app)`: the desktop daemon from `<PREFIX>_DB` with sync, letting devices connect, backups, certificates and the desktop settings; Both take the app's `services` (see `app/services`), `run_daemon(app, env, { services })`. `build_server`, `start_daemon`, `open_app_database` (with `on_restore` hooks) and `register_app_calls` for tests and apps that add their own. |
|
|
12
|
+
| `app/define` | The base app: `define_app` puts an X-app's name, ports, files, its own settings and its `define_feature` features (tables, migrations, calls, `api_spec`, settings, histories) together into one store every device keeps (`open_store` calling each feature's `on_open`, `needs_upgrade`, `bind_methods(database, on_change, caller)` running each call as its `caller`, calling each feature's `after_write`, recording versions and announcing writes, `is_read_only`), `page_only` (the specs' `page_only` calls and the writes of `user_only` settings, refused with `page_only_refusal`), its sync engine, its backups' names and schedule, and its bridges named after the app; `AppMethodsOf<typeof app>` types the app's calls. `history_days` sets how far an app's history reaches back until the user chooses (365 unless set); what opening changed is recorded as this device's version, and old versions are pruned on opening and after a write once a day. `settings_knows(key)` lets an import take keys without a spec of their own, such as `diet.target_protein`; `upgrade_layout: { needed, run }` brings a database an older version laid out its own way, such as a versions table keyed another way, in line before any migration, backed up first; `adopt_backup_schedule(database, saved)` moves a schedule an older version kept elsewhere into the setting once. |
|
|
13
|
+
| `app/server`, `app/daemon` | `run_server(app, { web_folder })`: the web server from `<PREFIX>_CONFIG` with accounts in `accounts.db` (moved there once from the data's own file, tokens starting with the app's `token_prefix`), the calls, OpenAPI, MCP, the server's backups and its sync peer, a token or MCP client refused the app's `page_only` calls and the `user_only_backup_calls` (restore, remove, schedule) and its calls run as the `program` caller; `run_daemon(app)`: the desktop daemon from `<PREFIX>_DB` with sync, letting devices connect, backups, certificates and the desktop settings; Both take the app's `services` (see `app/services`), `run_daemon(app, env, { services })`. A `backup-schedule.json` an older version kept beside the database moves into this device's setting on opening. `build_server`, `start_daemon`, `open_app_database` (with `on_restore` hooks) and `register_app_calls` for tests and apps that add their own. |
|
|
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
|
-
| `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. An app with `local_mcp: { default_port }` serves its calls as MCP on 127.0.0.1 from the desktop daemon (`electron/mcp`, page-only calls left out, calls run as `program`), turned on under Settings → MCP server. |
|
|
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, a write a row makes reaching every window at once, 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. An app with `local_mcp: { default_port }` serves its calls as MCP on 127.0.0.1 from the desktop daemon (`electron/mcp`, page-only calls left out, calls run as `program`), turned on under Settings → MCP server. |
|
|
17
17
|
| `app/window_size` | `fit_window_size(work_area)`: a first window of most of the screen's free area, between 960×640 and 1800×1200 and never past the screen; hand it to `run_desktop` as `default_size`. |
|
|
18
|
-
| `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`. `settings_categories(props)` adds the app's own Settings categories after General, for settings no one page owns. |
|
|
18
|
+
| `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`. `settings_categories(props)` adds the app's own Settings categories after General, for settings no one page owns. A page's `children` fold open under its row in the sidebar (`#/diet/foods`, the title "Foods · Diet", the first shown when none is named, a single child leaving the page one row), and `phone_services` loads the app's own work on the phone only there, such as reminders handed to Android, told of every write, every change from another device and each return to the app; an older version's backup schedule in the page's storage moves into the setting. |
|
|
19
19
|
| `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. The page presets stand in for Capacitor where the app has none installed (`config/capacitor`'s `capacitor_stand_in`), so a web and desktop app needs no phone packages, and the dev server proxies `/api/`, leaving the page's own `api.ts` to Vite. |
|
|
20
20
|
| `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`. |
|
|
21
21
|
| `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. |
|
|
@@ -33,7 +33,7 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
33
33
|
| `mcp_servers` | The MCP servers a user adds, as a page and a server both see them, with nothing of Node: `McpServerTarget` (streamable HTTP at an address with an optional token, or a local command with its arguments and the variables passed), `McpTransport`, `McpToolRecord` (a listed tool with its read-only mark and input schema), `McpListing` (the tools and the server's instructions), and `sends_outside`, true unless the server is a local command or answers on a loopback address. `server/mcp_client` reaches them. |
|
|
34
34
|
| `endpoint_models` | `list_endpoint_models(endpoint, api_key, signal, fetcher)`: the models an OpenAI-compatible endpoint lists at GET /models, each once, at most 500, with a llama.cpp router's load state (`state_of`), never throwing: a failure is no list and a `problem` in words that never hold the key; `models_of` reads an answer, `model_label` says "qwen3 (loaded)", and `may_load` whether the next request may wait while the server loads the model. |
|
|
35
35
|
| `embeddings` | `embeddings_client(settings, { api_key, fetcher, words })`: any OpenAI-compatible embeddings endpoint, Ollama's on this computer unless set: `embed(texts)` one vector per text in order, checked against the `dimensions` set (768 unless set), `embed_query` with the `query_prefix` before it, `is_local`, the key asked for on each call, its failures thrown as `PlainFailure` through `explain_endpoint_failure`. |
|
|
36
|
-
| `dates` | Local dates as `"2026-06-10"` or `"2026-06-10T09:30"`: reading, writing, adding days and months, overdue, and Yesterday/Today/Tomorrow labels; days and months as text, such as `today`, `shift_day`, `month_of`, `shift_month`, `months_from` and `format_month` for `"June 2026"`, the month taken from the text so a time zone never moves the 1st. |
|
|
36
|
+
| `dates` | Local dates as `"2026-06-10"` or `"2026-06-10T09:30"`: reading, writing, adding days and months, overdue, and Yesterday/Today/Tomorrow labels; days and months as text, such as `today`, `shift_day`, `month_of`, `shift_month`, `months_from` and `format_month` for `"June 2026"`, the month taken from the text so a time zone never moves the 1st; `epoch_of_day` and `day_of_epoch` turn a day into a chart point's seconds and back in UTC. |
|
|
37
37
|
| `date_ranges` | Spans of time named from now as day.js rules: a date `is_before`, `is_after` or `is_between` (with a chosen inclusivity) points such as now or the start or end of last, this or next day, week, month or year; `resolve_rule` works the points out with the week starting on a chosen day, `matches_rule` places a plain date at the end of its day, and `DATE_POINTS` with `date_point_label` feed a picker. |
|
|
38
38
|
| `units` | `convert`, `to_shown`, `to_stored` and `format_measure`; `GramUnit` with `from_grams`, `to_grams` and `format_grams` for small amounts kept in grams and shown in g, mg or µg, such as a food's nutrients; weights, lengths, distances and energy kept in kg, cm, km and kcal and shown in the unit each person picks, such as `"225 lb"`; `format_number`, whole numbers whole and the rest to a tenth, and `format_change`, a signed difference such as `"+1.5 kg"`. |
|
|
39
39
|
| `categories` | Categories nested by `/` paths such as `"Protein/Meat"`: normalizing, depth, leaf and parents, `is_in_category`, `all_categories` with the parents paths imply, `rename_in_categories` moving the subtree and merging onto a name in use, `drop_from_categories` taking the subtree, `filter_by_category` with descendants or the uncategorised, and `group_by_category` for grouped lists and selects. |
|
|
@@ -42,7 +42,7 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
42
42
|
| `i18n` | Words in the reader's language: `create_translator` looks each key up in catalogs in turn, so a missing translation falls back to the next, with `{name}` placeholders filled; `merge_messages`; `best_locale`, the available locale that best fits the reader's preferred ones, an exact tag before the same language; `text_direction` for the `dir` attribute. |
|
|
43
43
|
| `sql` | `SqlDatabase`, the part of a synchronous SQLite connection the apps use, met by node:sqlite and by `web/sqlite_wasm`; `in_transaction`, and `migrate`, each step once in its own transaction, through `user_version` or, with an `owner` such as a feature or plugin, its own row in `schema_versions`. |
|
|
44
44
|
| `settings` | An app's settings feature: one synced `settings (key, value)` table of JSON values, the same table and first step (`settings_migration` under the owner `"settings"`) every app already ran. Each feature declares a `SettingSpec` per key (`default`, `user_only`, `local` for this device alone, `secret` for another service's key, or its own `hide` and `keep`), `settings_of` giving every key of a defaults table the same spec; `create_settings_store(tables, { app })` merges them, refusing a key declared twice, and gives the migration, the synced table entry with its `local_keys`, `defaults`, the `user_only` set, `is_user_only_call` for `page_only_calls` (a user-only write, an import holding one, an export with secrets), `is_device_only` for `register_sync_routes`, `value_of`, and `get_settings`, `set_setting`, `export_settings` and `import_settings` with their api specs. Secrets read as `hidden_secret` and are kept when it comes back; the settings file is the standard's `{ app, kind: "settings", version, exported_at, settings }`, an import ignoring unknown keys and those of one device. `read_setting`, `write_setting` and `read_stored_settings` reach rows directly. No `node:` or DOM imports. |
|
|
45
|
-
| `caller`
|
|
45
|
+
| `caller`, `node_caller_scope` | Who is making the call in hand: `as_caller("page" \| "program" \| "engine", work)` around a call, `current_caller()` read by a store, and `caller_of(request)` (a token is a program). With a `CallerScope` in use (`use_caller_scope`), the caller holds across the call's awaits; the base app's server and daemon use `node_caller_scope()`, Node's `AsyncLocalStorage`, and without one, as on a phone, it holds for the call's synchronous part. |
|
|
46
46
|
| `api_spec` | An app's calls described once for other programs: `ApiSpec` gives each method its words and a JSON Schema per argument, so a method without one fails to compile; `input_schema` takes the arguments as one object, `positional_args` puts named arguments back in the method's order from a spec or any `NamedParams`, `openapi_document` writes an OpenAPI 3.1 document with one POST per call, and `route_openapi_document` one for REST routes such as `server/mcp`'s `route_tools` serves, each under its own path and verb with its path, query and body arguments; `check_known_ids` refuses a call naming an id that does not exist, such as "no such track a1", before it acts, `unknown_ids` lists them, and `keep_known_ids` cuts a remembered list, such as picked columns, down to the ids that still exist. A spec marked `page_only: true` is a call only the user may make at the app's own page (a signed-in browser, or a desktop window through its daemon's socket), such as approving what an assistant proposed: `page_only_calls(api, { rule?, refusal? })` gives the `PageOnlyCalls` the other modules take (`is_page_only(method)` for the marks, `is_page_only_call(method, args)` adding the app's `rule(method, args)` such as a write to some settings, `is_page_only_request(method, body)` for arguments as a list or by name, unchecked so a call with wrong names is left to refuse them itself, and the `refusal` text, `default_page_only_refusal` unless set), and both OpenAPI documents mark such a call with `x-page-only: true` and a 403. |
|
|
47
47
|
| `filter`, `filter_sql` | Filters as one JSON tree of conditions under and, or and not, over fields the app lists in a catalogue (`define_catalogue`): a column, an SQL expression over the row, a related table matched when any of its rows matches, a set of values in a link table, kept as they are or once in a table of their own, or a `custom` field; tables and columns named as text or as the Drizzle schema's own objects. `compile_filter` makes one parameterised query for any `SqlDatabase` (`query_rows`), missing values last whichever way it sorts and ties broken by id so pages never shift, and a `random` sort key's whole-number `seed` giving the same shuffle each time, in SQL and in memory (`shuffle_position`); `compile_group_by` counts and sums each value of a field for panes; `evaluate` and `select_ids` check records in memory and `sort_records` sorts them, with exactly the same answers and order, which a property test holds them to; text, number, set and date operators, `top` and `bottom`, `in_last` in milliseconds, seconds or ISO dates, `in_filter` for a saved filter with `find_cycle`, the app's own `operators` such as full-text search, `regexp_matches` for the REGEXP a `regex` calls, and `FilterStack`, the removable chips a view shows. |
|
|
48
48
|
| `filter_query` | `parse_filter_query`: search text such as `artist:beatles rating:>3 year:1965..1970 -live played:<30d` read into one filter over the fields the app lists (text, set, number or date, each with the names users type), so one search box serves every field. A text field takes `:` for contains, `=` for exact, `a,b` for either and `/pattern/` (matched with case, as `regex` is); a set field finds its listed values whatever their case; numbers take `>`, `>=`, `<`, `<=` and `a..b` through the field's own `parse_number`, such as stars into a rating; dates take `<30d` and `>6m` (h, d, w, m, y) and whole years, months or days such as `2024-03`, in the field's clock. A leading `-` leaves a term out. Each term comes back with where it is, its filter and a label for a chip, and `without_term` takes one out of the text; anything not readable as a field's condition is searched as words through the app's own text filter, never an error. |
|
|
@@ -64,6 +64,8 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
64
64
|
| `phone_notices` | `keep_phone_notices`: notices handed to a phone ahead of time through Capacitor's local notifications, the app passing its own `LocalNotifications`, since a phone has no daemon; `refresh` takes back every pending notice and sets the soonest 64 of the next 14 days again, `ask_permission` asks once, `show` puts a notice up at once with no alarm (`isExactNotification: false`), so a notice for now never needs Android's exact-alarm leave or opens its settings screen, `exact: false` lets the notices set ahead ring inexactly too, and a tap hands the notice's `extra` back, such as a link to open. `notice_id` names a key as Android's number. |
|
|
65
65
|
| `phone_service` | `phone_service`: work a phone app keeps doing while it is closed, such as staying reachable, in an Android foreground service run by X-App's plugin `XLibsForegroundService`, which `cap sync` adds by itself: the service loads the app's own worker page (such as `worker.html` from its page files) in a WebView it owns, so the work outlives the app's window, a killed process (Android starts it again) and, with `start_at_boot`, a reboot; `start`, `stop`, `is_running`, `post` and `on_message` for the page, and `worker_host` for the worker's side, the messages crossing as JSON. The app declares the service and the boot receiver in its own manifest, with the `connectedDevice` foreground service permissions, as the module's opening comment shows, so no other app gets them. |
|
|
66
66
|
| `phone_sockets` | `phone_sockets()`: UDP and TCP sockets for a `phone_service` worker, answered by X-App's Android side: `udp_open` (with `broadcast`, holding Android's multicast lock), `tcp_listen`, `tcp_connect` and `list_interfaces`; a TCP socket reads nothing until `read_line` takes one line or `start_reading` everything after, so `start_tls` can follow plain text in either TLS role, as KDE Connect's identity line does, with the app's PEM certificate and key, letting any peer through and handing back its certificate for the worker to pin; `pause` and `resume` for a slow reader, and `write` settling once sent. Events that arrive before a listener are kept for it. Needs `CHANGE_WIFI_MULTICAST_STATE` and `WAKE_LOCK` in the app's manifest; each event keeps the phone awake a few seconds so the worker can answer. |
|
|
67
|
+
| `app/item_history`, `app/web/item_history` | A history for each kind of item made of rows across tables, such as a workout with its exercises and sets: `item_history_feature(kinds)` keeps each kind's versions (an `ItemLevel` list read by `read_snapshot` and put back by `apply_snapshot`, a deleted item coming back whole) and adds `list_item_history`, `list_recent_changes` and `restore_item_version` with their specs; on the page, `HistoryView` lists the latest changes, `HistoryButton` and `open_item_history` open one item's versions, each restorable after a confirm. |
|
|
68
|
+
| `api_schemas` | The argument shapes many calls share as JSON Schema: `text(description)`, `number(description)`, `id_of("workout")`, a local `day`, a `moment`, a `json_file`'s text and a `step` of -1 or 1. |
|
|
67
69
|
| `history` | Every change to an app's items kept as versions in SQLite: `create_history` sets triggers on the tables that change an item, `record` saves one version of each item touched, and `restore` brings a version back, a deleted item with what was deleted under it; the versions table syncs, `read_changed_since` gives the newest version of each item changed after a moment, oldest first, and `history_methods` are the page's calls. Its tables are made only where missing, so an app with its own older versions table keeps it, naming its item column with `item_column`. A table that reaches its item only through another, such as a workout's sets through its exercises, names it with `item_lookup`, a query from the row. |
|
|
68
70
|
| `items` | The four read-only calls every app answers about its items for other apps ([Items for other apps](#items-for-other-apps)): `item_calls` turns the app's own kinds, search, get and changes into `list_item_kinds`, `search_items`, `get_items` and `list_item_changes` with their `api_spec` entries, every item in one shape (`Item`, `DeletedItem`, `ItemChange`) with its snippet clipped to 200 characters, limits defaulted and capped, and changes oldest first; `item_link` and `parse_item_link` for `x-<app>://<kind>/<id>` links with the id percent-encoded; `history_item_changes` answers the changes from `create_history` versions; a source with `text` adds the optional `get_item_texts`, each item's full text (`ItemText`) as plain text or Markdown cut to 256 KB by `clip_item_text`, and `has_text` on each kind. |
|
|
69
71
|
| `item_client` | Reading another app through its item calls: `item_client(app)` makes `list_item_kinds`, `search_items`, `get_items`, `list_item_changes` and `get_item_texts` at `POST /api/call/<method>`, falling back to the older `/api/<method>` and remembering which answered, ids sent a page at a time, `get_item_texts` null for an app that does not answer it (`ItemCallMissing`), and failures in plain words that never hold the token. |
|
|
@@ -171,7 +173,8 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
171
173
|
| `web/react/outcome_log` | `OutcomeLog`: what happened to each item of a run, such as each file of a scan or each row of an import, on `DataTable` with `virtual` rows: a `StateBadge` per outcome, the item and why on one line each, cut off with an ellipsis and whole in their hover text, a filter of the outcomes that happened with their tallies, held by the log or the app, and a Follow switch keeping the newest in view while entries arrive until the reader scrolls up; its scrolling box takes Halon's `following-output` height unless `wrap_class` gives another. |
|
|
172
174
|
| `web/react/shortcuts` | `use_shortcuts` for keys such as `"mod+z"`, quiet while typing or while a dialog or popover is open; `describe_keys` for help text. |
|
|
173
175
|
| `web/react/tree` | `Tree`: nested rows that fold, walk with the arrow keys, reorder by dragging or with Alt and the arrow keys, show several picked, and take drops from outside; `has_children` gives a row a fold button before its children are listed, so an app can load them once it opens, such as in a large graph. |
|
|
174
|
-
| `web/react/
|
|
176
|
+
| `web/react/forms`, `unit_number`, `day`, `row_actions`, `lookup` | Small pieces lists share: `AddNameForm` adds a typed name from a toolbar, keeping it typed when adding failed, `RenameField` and `use_rename` rename in place (Enter or leaving saves, Escape gives up), `FormButtons` and `DialogButtons` are Save and Cancel; `UnitNumber` is a `NumberField` showing a stored value in the unit shown, such as kilograms as pounds, empty at 0 unless `show_zero`, bare or in a `FormRow` or `SettingRow`; `use_day` keeps a page's day, remembered for the tab's session under a key, with `DayStepper`; `row_actions_column` is a table's Edit, own buttons, History, trailing buttons and Delete column, each labelled with the row's name, and `confirm_delete` asks with a red Delete; `LookupPanel` searches an online source, listing results, each source's failure and an empty line, and hands the picked one over. |
|
|
177
|
+
| `web/react/toasts`, `dialog`, `menus`, `split` | Toasts with a link or Undo that say how they closed, `undoable` actions that commit or undo exactly once, and `attempt`, which shows a failed call's words as a bad toast, with `attempt_value(work, done?)` giving the answer back (or undefined once the failure is shown), `succeeds(work, done?)` saying whether it went through, and `show_error`; modal dialogs with a subtitle, header actions, a full-window size and a `form` whose submit button sends it, and confirm and text dialogs, openable from anywhere; context menus and popovers worked by keyboard, openable from anywhere, their keep-open items ticking at once; resize handles and splits. `SettingsDialogRow` is a settings row with a name, a short status and an Open button whose dialog holds that group's settings. |
|
|
175
178
|
| `web/react/page_view` | `PageView`: a full-window page over the app on the Dialog, such as Settings or an item's properties, with a Close button, actions beside it and section tabs that stay put while the body scrolls. |
|
|
176
179
|
| `web/react/charts` | `LineChart` of readings over time as lines or dots, with dashed limits such as a goal, a scale from zero or fitted around the readings, and dots from a single reading; `moving_average` for its trend line; `BarChart`, naming each bar under it when asked, `StackedBarChart`, `Meters` with ticks and a lighter fill behind, `Donut` with its headline in the middle, `Timeline` of spans and instants per lane, `Sparkline` from zero or fitted to its readings, a pass/fail `Strip`, a `Gauge` ring beside a stat's value that can link like a `Tile`, a `DonutTile`, a stat tile drawn as a full ring with its value in the middle, a `ShareBar` with each part's value in its legend, and a `Treemap` of tiles sized by value on `squarify` that hands back the one clicked: small charts colored from Halon's tokens. |
|
|
177
180
|
| `web/react/graph` | `GraphView`: a graph of nodes and links drawn by force, such as a knowledge graph: each node a shape and colour role by its `kind` (`GraphKind`: Halon's accent, a status or a `--series-*` token, read again when the theme changes), with an optional glyph and drawn faded when asked; each link solid or `dashed`, with an arrow when `directed` and a label shown near the selection or zoomed in. Selecting a node rings it and lights its neighbours; a click selects, a double-click opens (`on_activate`), a link click calls `on_link_select`; dragging pans, the wheel zooms, Fit, + and − in the toolbar beside the app's own `tools`; `focus_id` centres on a node, such as one a search found; a legend of kinds and link styles, an empty state, and every node with its links as a `Tree` under the drawing, so it is all reachable from the keyboard (arrow keys pan the drawing, + and − zoom, 0 fits, Enter opens the selection). On force-graph (MIT), loaded only when a graph is shown, which keeps a few thousand nodes moving on a canvas; X-App adds Halon's colours, the list, the keyboard path and selection. |
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JsonSchema } from "./api_spec.ts";
|
|
2
|
+
export declare function text(description: string): JsonSchema;
|
|
3
|
+
export declare function number(description: string): JsonSchema;
|
|
4
|
+
export declare function id_of(thing: string): JsonSchema;
|
|
5
|
+
export declare const day: JsonSchema;
|
|
6
|
+
export declare const moment: JsonSchema;
|
|
7
|
+
export declare const json_file: JsonSchema;
|
|
8
|
+
export declare const step: JsonSchema;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The argument shapes many calls share, as JSON Schema, for the specs other programs read through MCP and OpenAPI.
|
|
2
|
+
// ── Shapes ───────────────────────────────────────────────────────────────────
|
|
3
|
+
export function text(description) {
|
|
4
|
+
return { type: "string", description };
|
|
5
|
+
}
|
|
6
|
+
export function number(description) {
|
|
7
|
+
return { type: "number", description };
|
|
8
|
+
}
|
|
9
|
+
// An item's id, such as id_of("workout"): "The workout's id, as a list or get call gives it."
|
|
10
|
+
export function id_of(thing) {
|
|
11
|
+
return { type: "string", description: `The ${thing}'s id, as a list or get call gives it.` };
|
|
12
|
+
}
|
|
13
|
+
export const day = { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$", description: "A local day, such as 2026-11-10." };
|
|
14
|
+
export const moment = { type: "string", description: "A moment as an ISO 8601 timestamp, such as 2026-11-10T18:30:00.000Z." };
|
|
15
|
+
export const json_file = { type: "string", description: "The whole file's text." };
|
|
16
|
+
// One step through a list: -1 moves it up, 1 down.
|
|
17
|
+
export const step = { type: "integer", enum: [-1, 1], description: "-1 moves it one place earlier, 1 one place later." };
|
package/dist/app/define.d.ts
CHANGED
|
@@ -53,6 +53,11 @@ export interface AppOptions<Features extends readonly Feature[]> {
|
|
|
53
53
|
settings?: Record<string, SettingSpec>;
|
|
54
54
|
settings_descriptions?: SettingsStoreOptions["descriptions"];
|
|
55
55
|
setting_key_example?: string;
|
|
56
|
+
settings_knows?: (key: string) => boolean;
|
|
57
|
+
upgrade_layout?: {
|
|
58
|
+
needed: (database: SqlDatabase) => boolean;
|
|
59
|
+
run: (database: SqlDatabase) => void;
|
|
60
|
+
};
|
|
56
61
|
page_only_refusal?: string;
|
|
57
62
|
token_prefix?: string;
|
|
58
63
|
history_days?: number;
|
|
@@ -107,6 +112,11 @@ export declare function define_app<const Features extends readonly Feature[]>(op
|
|
|
107
112
|
settings?: Record<string, SettingSpec>;
|
|
108
113
|
settings_descriptions?: SettingsStoreOptions["descriptions"];
|
|
109
114
|
setting_key_example?: string;
|
|
115
|
+
settings_knows?: (key: string) => boolean;
|
|
116
|
+
upgrade_layout?: {
|
|
117
|
+
needed: (database: SqlDatabase) => boolean;
|
|
118
|
+
run: (database: SqlDatabase) => void;
|
|
119
|
+
};
|
|
110
120
|
page_only_refusal?: string;
|
|
111
121
|
token_prefix?: string;
|
|
112
122
|
history_days?: number;
|
|
@@ -146,6 +156,7 @@ export declare function define_app<const Features extends readonly Feature[]>(op
|
|
|
146
156
|
bind_methods: (database: () => SqlDatabase, on_change: () => void, caller?: Caller) => Bound<SettingsMethods & UnionToIntersection<Features[number]["methods"]>>;
|
|
147
157
|
backup_naming: BackupNaming;
|
|
148
158
|
read_backup_schedule: (database: SqlDatabase) => BackupSchedule;
|
|
159
|
+
adopt_backup_schedule: (database: SqlDatabase, saved: unknown) => void;
|
|
149
160
|
backup_methods: (kept: Restorable, database: () => SqlDatabase, check_schedule: () => void) => BackupMethods;
|
|
150
161
|
bridges: AppBridges<Bound<SettingsMethods & UnionToIntersection<Features[number]["methods"]>>>;
|
|
151
162
|
};
|
package/dist/app/define.js
CHANGED
|
@@ -46,6 +46,7 @@ export function define_app(options) {
|
|
|
46
46
|
app: { id: options.id, name: options.name },
|
|
47
47
|
...(options.settings_descriptions ? { descriptions: options.settings_descriptions } : {}),
|
|
48
48
|
...(options.setting_key_example ? { key_example: options.setting_key_example } : {}),
|
|
49
|
+
...(options.settings_knows ? { knows: options.settings_knows } : {}),
|
|
49
50
|
});
|
|
50
51
|
const settings_feature = { id: settings_store.id, migrations: settings_store.migrations, tables: settings_store.tables, methods: { ...settings_store.methods }, api: settings_store.api };
|
|
51
52
|
const features = [settings_feature, ...options.features];
|
|
@@ -59,6 +60,8 @@ export function define_app(options) {
|
|
|
59
60
|
// ── Opening ──────────────────────────────────────────────────────────
|
|
60
61
|
// Whether a database already holding data has steps to run, so it can be backed up before its schema is upgraded.
|
|
61
62
|
function needs_upgrade(database) {
|
|
63
|
+
if (options.upgrade_layout?.needed(database))
|
|
64
|
+
return true;
|
|
62
65
|
const has_versions = database.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'schema_versions'").get();
|
|
63
66
|
if (!has_versions)
|
|
64
67
|
return false;
|
|
@@ -70,6 +73,8 @@ export function define_app(options) {
|
|
|
70
73
|
// Brings an open connection up to date and sets sync to stamp every change; run once each time the database opens.
|
|
71
74
|
function open_store(database) {
|
|
72
75
|
database.exec("PRAGMA foreign_keys = ON");
|
|
76
|
+
if (options.upgrade_layout?.needed(database))
|
|
77
|
+
options.upgrade_layout.run(database);
|
|
73
78
|
// Each feature keeps its own schema version, so features grow apart without renumbering each other's steps.
|
|
74
79
|
for (const feature of features)
|
|
75
80
|
migrate(database, feature.migrations, { owner: feature.id });
|
|
@@ -82,6 +87,7 @@ export function define_app(options) {
|
|
|
82
87
|
for (const history of histories)
|
|
83
88
|
history.record(database);
|
|
84
89
|
prune_history(database);
|
|
90
|
+
pruned_at.set(database, Date.now());
|
|
85
91
|
}
|
|
86
92
|
// Versions older than the days set go, each item keeping its newest; 0 keeps them all.
|
|
87
93
|
function prune_history(database) {
|
|
@@ -92,6 +98,16 @@ export function define_app(options) {
|
|
|
92
98
|
for (const history of histories)
|
|
93
99
|
history.prune(database, cutoff);
|
|
94
100
|
}
|
|
101
|
+
// When each connection's history was last pruned, so a server that runs for weeks still prunes once a day.
|
|
102
|
+
const pruned_at = new WeakMap();
|
|
103
|
+
const prune_every_ms = 24 * 60 * 60 * 1000;
|
|
104
|
+
function prune_daily(database) {
|
|
105
|
+
const last = pruned_at.get(database);
|
|
106
|
+
if (last !== undefined && Date.now() - last < prune_every_ms)
|
|
107
|
+
return;
|
|
108
|
+
pruned_at.set(database, Date.now());
|
|
109
|
+
prune_history(database);
|
|
110
|
+
}
|
|
95
111
|
// ── Calls ────────────────────────────────────────────────────────────
|
|
96
112
|
const all_methods = Object.assign({}, ...features.map((feature) => feature.methods));
|
|
97
113
|
const method_names = Object.keys(all_methods);
|
|
@@ -114,6 +130,7 @@ export function define_app(options) {
|
|
|
114
130
|
feature.after_write?.(database());
|
|
115
131
|
for (const history of histories)
|
|
116
132
|
history.record(database());
|
|
133
|
+
prune_daily(database());
|
|
117
134
|
on_change();
|
|
118
135
|
return value;
|
|
119
136
|
};
|
|
@@ -131,6 +148,13 @@ export function define_app(options) {
|
|
|
131
148
|
const stored = read_setting(database, backup_schedule_key);
|
|
132
149
|
return is_backup_schedule(stored) ? stored : default_backup_schedule;
|
|
133
150
|
}
|
|
151
|
+
// A schedule an older version kept apart from the database, such as in backup-schedule.json, moves into the setting
|
|
152
|
+
// once, unless the setting holds one already; a damaged one is dropped.
|
|
153
|
+
function adopt_backup_schedule(database, saved) {
|
|
154
|
+
if (read_setting(database, backup_schedule_key) !== undefined || !is_backup_schedule(saved))
|
|
155
|
+
return;
|
|
156
|
+
write_setting(database, backup_schedule_key, { automatic: saved.automatic, to_keep: saved.to_keep });
|
|
157
|
+
}
|
|
134
158
|
// The page's backup calls on any host's backups; a new schedule is checked at once, such as to take a first daily backup.
|
|
135
159
|
function backup_methods(kept, database, check_schedule) {
|
|
136
160
|
return {
|
|
@@ -182,6 +206,7 @@ export function define_app(options) {
|
|
|
182
206
|
bind_methods,
|
|
183
207
|
backup_naming: naming,
|
|
184
208
|
read_backup_schedule,
|
|
209
|
+
adopt_backup_schedule,
|
|
185
210
|
backup_methods,
|
|
186
211
|
bridges,
|
|
187
212
|
};
|
package/dist/app/desktop.js
CHANGED
|
@@ -144,6 +144,15 @@ export function run_desktop(app, electron, options) {
|
|
|
144
144
|
electron.app.quit();
|
|
145
145
|
}
|
|
146
146
|
// ── Tray ───────────────────────────────────────────────────────────
|
|
147
|
+
// A write from a tray row reaches every window and the tray at once, as the daemon tells this process of no change it made.
|
|
148
|
+
async function tray_call(method, args = []) {
|
|
149
|
+
const result = await call(`call/${method}`, args);
|
|
150
|
+
if (!app.is_read_only(method)) {
|
|
151
|
+
app.bridges.events.emit(windows(), "changed", null);
|
|
152
|
+
void tray?.refresh();
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
147
156
|
// The app's rows above Show, Quit and Quit completely; its calls go to the daemon the window works on.
|
|
148
157
|
const { Tray, Menu, nativeImage } = electron;
|
|
149
158
|
const tray = Tray && Menu && nativeImage
|
|
@@ -153,7 +162,7 @@ export function run_desktop(app, electron, options) {
|
|
|
153
162
|
on_click: () => show_window(),
|
|
154
163
|
on_error: (error) => console.error(error),
|
|
155
164
|
read: async () => {
|
|
156
|
-
const own = options.tray ? await options.tray({ call:
|
|
165
|
+
const own = options.tray ? await options.tray({ call: tray_call, open: (route) => show_window(route) }) : { rows: [] };
|
|
157
166
|
const quit = () => {
|
|
158
167
|
router.quitting();
|
|
159
168
|
electron.app.quit();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Feature } from "./define.ts";
|
|
2
|
+
import { type History, type HistoryWatch, type VersionKind } from "../history.ts";
|
|
3
|
+
import type { SqlDatabase } from "../sql.ts";
|
|
4
|
+
export type Snapshot = Record<string, Record<string, unknown>[]>;
|
|
5
|
+
export interface ItemLevel {
|
|
6
|
+
table: string;
|
|
7
|
+
column: string;
|
|
8
|
+
from?: {
|
|
9
|
+
level: number;
|
|
10
|
+
column: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function read_snapshot(database: SqlDatabase, levels: readonly ItemLevel[], item_id: string): Snapshot | null;
|
|
14
|
+
export declare function apply_snapshot(database: SqlDatabase, levels: readonly ItemLevel[], item_id: string, snapshot: Snapshot): void;
|
|
15
|
+
export interface ItemKind {
|
|
16
|
+
kind: string;
|
|
17
|
+
label: string;
|
|
18
|
+
item_table: string;
|
|
19
|
+
item_key?: string;
|
|
20
|
+
levels: readonly ItemLevel[];
|
|
21
|
+
watches: readonly HistoryWatch[];
|
|
22
|
+
name_of: (snapshot: Snapshot) => string;
|
|
23
|
+
summary: (snapshot: Snapshot) => string;
|
|
24
|
+
history_name?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ItemChange {
|
|
27
|
+
id: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
kind_label: string;
|
|
30
|
+
item_id: string;
|
|
31
|
+
item_name: string;
|
|
32
|
+
summary: string;
|
|
33
|
+
changed_at: string;
|
|
34
|
+
change: VersionKind;
|
|
35
|
+
origin: "here" | "elsewhere";
|
|
36
|
+
}
|
|
37
|
+
export type ItemHistoryMethods = {
|
|
38
|
+
list_item_history: (database: SqlDatabase, kind: string, item_id: string) => ItemChange[];
|
|
39
|
+
list_recent_changes: (database: SqlDatabase, limit: number) => ItemChange[];
|
|
40
|
+
restore_item_version: (database: SqlDatabase, kind: string, version_id: string) => void;
|
|
41
|
+
};
|
|
42
|
+
export interface ItemHistoryOptions {
|
|
43
|
+
id?: string;
|
|
44
|
+
item_id_description?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare function item_history_feature(kinds: readonly ItemKind[], options?: ItemHistoryOptions): Feature<ItemHistoryMethods> & {
|
|
47
|
+
histories: readonly History<Snapshot>[];
|
|
48
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Every change to the things a person makes and edits, such as a workout with its sets or a recipe with its
|
|
2
|
+
// ingredients, kept as versions through `history`: each kind of item is its rows across one or more tables, read and
|
|
3
|
+
// put back level by level. The feature's calls list one item's versions and the latest changes to every item, and
|
|
4
|
+
// restore any version, a deleted item coming back with what was deleted along with it.
|
|
5
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
6
|
+
import { define_feature } from "./define.js";
|
|
7
|
+
import { create_history } from "../history.js";
|
|
8
|
+
function read_levels(database, levels, item_id) {
|
|
9
|
+
const found = [];
|
|
10
|
+
for (const level of levels) {
|
|
11
|
+
const values = level.from ? found[level.from.level].map((row) => row[level.from.column]) : [item_id];
|
|
12
|
+
const rows = values.length
|
|
13
|
+
? database.prepare(`SELECT * FROM ${level.table} WHERE ${level.column} IN (${values.map(() => "?").join(", ")}) ORDER BY rowid`).all(...values)
|
|
14
|
+
: [];
|
|
15
|
+
found.push(rows.map((row) => ({ ...row })));
|
|
16
|
+
}
|
|
17
|
+
return found;
|
|
18
|
+
}
|
|
19
|
+
// The item's rows at every level, or null once none are left.
|
|
20
|
+
export function read_snapshot(database, levels, item_id) {
|
|
21
|
+
const found = read_levels(database, levels, item_id);
|
|
22
|
+
if (found.every((rows) => rows.length === 0))
|
|
23
|
+
return null;
|
|
24
|
+
return Object.fromEntries(levels.map((level, index) => [level.table, found[index]]));
|
|
25
|
+
}
|
|
26
|
+
// Puts an item's rows back as the snapshot has them: its rows now go, children first, and the snapshot's go in. A
|
|
27
|
+
// version made before a column was dropped puts back only the columns the table still has.
|
|
28
|
+
export function apply_snapshot(database, levels, item_id, snapshot) {
|
|
29
|
+
const current = read_levels(database, levels, item_id);
|
|
30
|
+
for (let index = levels.length - 1; index >= 0; index--) {
|
|
31
|
+
const level = levels[index];
|
|
32
|
+
const values = level.from ? current[level.from.level].map((row) => row[level.from.column]) : [item_id];
|
|
33
|
+
if (values.length)
|
|
34
|
+
database.prepare(`DELETE FROM ${level.table} WHERE ${level.column} IN (${values.map(() => "?").join(", ")})`).run(...values);
|
|
35
|
+
}
|
|
36
|
+
for (const level of levels) {
|
|
37
|
+
const existing = new Set(database.prepare(`SELECT name FROM pragma_table_info('${level.table}')`).all().map((column) => column.name));
|
|
38
|
+
for (const row of snapshot[level.table] ?? []) {
|
|
39
|
+
const columns = Object.keys(row).filter((column) => existing.has(column));
|
|
40
|
+
database.prepare(`INSERT INTO ${level.table} (${columns.join(", ")}) VALUES (${columns.map(() => "?").join(", ")})`).run(...columns.map((column) => row[column]));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// ── Feature ──────────────────────────────────────────────────────────────────
|
|
45
|
+
// The feature keeping a history of each kind of item, with its calls described for the API and MCP.
|
|
46
|
+
export function item_history_feature(kinds, options = {}) {
|
|
47
|
+
const histories = new Map(kinds.map((item) => [
|
|
48
|
+
item.kind,
|
|
49
|
+
create_history({
|
|
50
|
+
name: item.history_name ?? `${item.kind}_history`,
|
|
51
|
+
item_table: item.item_table,
|
|
52
|
+
...(item.item_key ? { item_key: item.item_key } : {}),
|
|
53
|
+
watches: item.watches,
|
|
54
|
+
read: (database, item_id) => read_snapshot(database, item.levels, item_id),
|
|
55
|
+
apply: (database, item_id, snapshot) => apply_snapshot(database, item.levels, item_id, snapshot),
|
|
56
|
+
}),
|
|
57
|
+
]));
|
|
58
|
+
function kind_of(kind) {
|
|
59
|
+
const item = kinds.find((each) => each.kind === kind);
|
|
60
|
+
const history = histories.get(kind);
|
|
61
|
+
if (!item || !history)
|
|
62
|
+
throw new Error(`There is no history of ${kind}.`);
|
|
63
|
+
return { item, history };
|
|
64
|
+
}
|
|
65
|
+
const as_change = (item, version) => ({
|
|
66
|
+
id: version.id,
|
|
67
|
+
kind: item.kind,
|
|
68
|
+
kind_label: item.label,
|
|
69
|
+
item_id: version.item_id,
|
|
70
|
+
item_name: item.name_of(version.snapshot),
|
|
71
|
+
summary: item.summary(version.snapshot),
|
|
72
|
+
changed_at: version.changed_at,
|
|
73
|
+
change: version.kind,
|
|
74
|
+
origin: version.origin,
|
|
75
|
+
});
|
|
76
|
+
const kind_schema = { type: "string", enum: kinds.map((item) => item.kind), description: "What the item is." };
|
|
77
|
+
return {
|
|
78
|
+
...define_feature({
|
|
79
|
+
id: options.id ?? "history",
|
|
80
|
+
migrations: [],
|
|
81
|
+
tables: [],
|
|
82
|
+
histories: [...histories.values()],
|
|
83
|
+
methods: {
|
|
84
|
+
list_item_history: (database, kind, item_id) => {
|
|
85
|
+
const { item, history } = kind_of(kind);
|
|
86
|
+
return history.read_versions(database, item_id).map((version) => as_change(item, version));
|
|
87
|
+
},
|
|
88
|
+
list_recent_changes: (database, limit) => kinds
|
|
89
|
+
.flatMap((item) => kind_of(item.kind).history.read_recent(database, limit).map((version) => as_change(item, version)))
|
|
90
|
+
.sort((first, second) => second.changed_at.localeCompare(first.changed_at))
|
|
91
|
+
.slice(0, limit),
|
|
92
|
+
restore_item_version: (database, kind, version_id) => kind_of(kind).history.restore(database, version_id),
|
|
93
|
+
},
|
|
94
|
+
api: {
|
|
95
|
+
list_item_history: {
|
|
96
|
+
description: "Lists one item's versions, newest first: when each was made, whether it was created, edited, deleted or restored, and on this device or another.",
|
|
97
|
+
params: [
|
|
98
|
+
{ name: "kind", schema: kind_schema },
|
|
99
|
+
{ name: "item_id", schema: { type: "string", description: options.item_id_description ?? "The item's id, as a list or get call gives it." } },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
list_recent_changes: {
|
|
103
|
+
description: "Lists the latest changes to every item, newest first, deleted items included.",
|
|
104
|
+
params: [{ name: "limit", schema: { type: "integer", minimum: 1, description: "How many changes at most." } }],
|
|
105
|
+
},
|
|
106
|
+
restore_item_version: {
|
|
107
|
+
description: "Brings an item back to one of its versions, or a deleted item back with what was deleted along with it.",
|
|
108
|
+
params: [
|
|
109
|
+
{ name: "kind", schema: kind_schema },
|
|
110
|
+
{ name: "version_id", schema: { type: "string", description: "The version's id from list_item_history or list_recent_changes." } },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
histories: [...histories.values()],
|
|
116
|
+
};
|
|
117
|
+
}
|
package/dist/app/server.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// OpenAPI and MCP, the server's backups and its own sync peer, all on one database. run_server starts it from the
|
|
3
3
|
// app's config, as `npm start` and the NixOS module run it.
|
|
4
4
|
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
5
|
-
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
6
6
|
import { hostname } from "node:os";
|
|
7
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
8
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -12,7 +12,8 @@ import { openapi_document, positional_args } from "../api_spec.js";
|
|
|
12
12
|
import { keep_backing_up } from "../backups.js";
|
|
13
13
|
import { backup_method_names } from "../backups.js";
|
|
14
14
|
import { calls_under, register_accounts } from "../server/account_sign_in.js";
|
|
15
|
-
import { caller_of } from "../caller.js";
|
|
15
|
+
import { caller_of, use_caller_scope } from "../caller.js";
|
|
16
|
+
import { node_caller_scope } from "../node_caller_scope.js";
|
|
16
17
|
import { AccountStore, holds_accounts, move_accounts } from "../server/account_store.js";
|
|
17
18
|
import { register_call_table } from "../server/call_table.js";
|
|
18
19
|
import { read_server_config } from "../server/config.js";
|
|
@@ -26,6 +27,8 @@ import { register_web_folder } from "../server/web_folder.js";
|
|
|
26
27
|
import { file_sync_storage } from "../sync_file_storage.js";
|
|
27
28
|
import { create_sync_peer, sync_device_methods } from "../sync_peer.js";
|
|
28
29
|
import { declared_file_of, no_services, side_databases } from "./services.js";
|
|
30
|
+
// The server and the daemon run on Node, so a call's caller holds across its awaits.
|
|
31
|
+
use_caller_scope(node_caller_scope());
|
|
29
32
|
// The app's database as the server and the desktop daemon keep it: a file opened and brought up to date, backed up
|
|
30
33
|
// before its schema is upgraded, before another copy replaces it, and daily, and restored from a backup.
|
|
31
34
|
export function open_app_database(app, path, backups_folder) {
|
|
@@ -59,6 +62,7 @@ export function open_app_database(app, path, backups_folder) {
|
|
|
59
62
|
}
|
|
60
63
|
mkdirSync(backups_folder, { recursive: true });
|
|
61
64
|
start(database);
|
|
65
|
+
adopt_schedule_file(app, database, join(dirname(path), "backup-schedule.json"));
|
|
62
66
|
const keeper = keep_backing_up(kept, () => app.read_backup_schedule(database));
|
|
63
67
|
return {
|
|
64
68
|
database: () => database,
|
|
@@ -71,6 +75,20 @@ export function open_app_database(app, path, backups_folder) {
|
|
|
71
75
|
},
|
|
72
76
|
};
|
|
73
77
|
}
|
|
78
|
+
// An older version kept this device's backup schedule in a file beside the database; it moves into the setting once.
|
|
79
|
+
function adopt_schedule_file(app, database, file) {
|
|
80
|
+
if (!existsSync(file))
|
|
81
|
+
return;
|
|
82
|
+
let saved = null;
|
|
83
|
+
try {
|
|
84
|
+
saved = JSON.parse(readFileSync(file, "utf8"));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// A damaged file holds no schedule worth keeping.
|
|
88
|
+
}
|
|
89
|
+
app.adopt_backup_schedule(database, saved);
|
|
90
|
+
rmSync(file, { force: true });
|
|
91
|
+
}
|
|
74
92
|
// ── Calls ────────────────────────────────────────────────────────────────────
|
|
75
93
|
// An import arrives as one call's argument.
|
|
76
94
|
export const call_body_limit = 32 * 1024 * 1024;
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { type BackupFolderPlugin } from "../../phone_backups.ts";
|
|
2
2
|
import { type FileStore } from "../../web/sqlite_wasm.ts";
|
|
3
|
+
import type { SqlDatabase } from "../../sql.ts";
|
|
3
4
|
import type { App } from "../define.ts";
|
|
4
5
|
import type { PageApi } from "../protocol.ts";
|
|
5
6
|
export interface PhoneLifecycle {
|
|
6
7
|
addListener(event: "pause", listener: () => void): unknown;
|
|
7
8
|
addListener(event: "resume", listener: () => void): unknown;
|
|
8
9
|
}
|
|
10
|
+
export interface PhoneContext {
|
|
11
|
+
database: () => SqlDatabase;
|
|
12
|
+
}
|
|
13
|
+
export interface PhoneServices {
|
|
14
|
+
changed?: () => void;
|
|
15
|
+
}
|
|
16
|
+
export type StartPhoneServices = (context: PhoneContext) => PhoneServices | Promise<PhoneServices>;
|
|
9
17
|
export interface PhoneOptions {
|
|
10
18
|
lifecycle?: PhoneLifecycle;
|
|
11
19
|
files?: FileStore;
|
|
12
20
|
folder?: BackupFolderPlugin;
|
|
21
|
+
services?: StartPhoneServices;
|
|
22
|
+
storage?: Pick<Storage, "getItem" | "removeItem">;
|
|
13
23
|
}
|
|
14
24
|
export declare function android_api(app: App, options?: PhoneOptions): Promise<PageApi>;
|
package/dist/app/web/android.js
CHANGED
|
@@ -8,6 +8,28 @@ import { phone_certificates } from "../../phone_certificates.js";
|
|
|
8
8
|
import { create_sync_peer, sync_device_methods } from "../../sync_peer.js";
|
|
9
9
|
import { indexed_db_files, open_wasm_database } from "../../web/sqlite_wasm.js";
|
|
10
10
|
import { local_sync_storage } from "../../web/sync_storage.js";
|
|
11
|
+
// An older version kept the phone's backup schedule in the page's storage; it moves into the setting once.
|
|
12
|
+
function adopt_stored_schedule(app, database, storage) {
|
|
13
|
+
const key = `${app.id}-backup-schedule`;
|
|
14
|
+
try {
|
|
15
|
+
const saved = storage?.getItem(key);
|
|
16
|
+
if (saved === null || saved === undefined)
|
|
17
|
+
return;
|
|
18
|
+
app.adopt_backup_schedule(database, JSON.parse(saved));
|
|
19
|
+
storage.removeItem(key);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// No storage here, or a damaged schedule, which holds nothing worth keeping.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function page_storage() {
|
|
26
|
+
try {
|
|
27
|
+
return globalThis.localStorage;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
11
33
|
// Each call runs straight on the database in this page; answers are promises, as they are on the other hosts.
|
|
12
34
|
function as_client(methods) {
|
|
13
35
|
const entries = Object.entries(methods).map(([name, method]) => [name, async (...args) => method(...args)]);
|
|
@@ -32,12 +54,15 @@ export async function android_api(app, options = {}) {
|
|
|
32
54
|
if (app.needs_upgrade(database.connection) && (await has_folder()))
|
|
33
55
|
await kept.create();
|
|
34
56
|
app.open_store(database.connection);
|
|
57
|
+
adopt_stored_schedule(app, database.connection, options.storage ?? page_storage());
|
|
35
58
|
await database.save_now();
|
|
36
59
|
const keeper = keep_backing_up(kept, () => app.read_backup_schedule(database.connection));
|
|
60
|
+
const services = options.services ? await options.services({ database: () => database.connection }) : {};
|
|
37
61
|
const listeners = new Set();
|
|
38
62
|
const announce = () => {
|
|
39
63
|
for (const listener of listeners)
|
|
40
64
|
listener();
|
|
65
|
+
services.changed?.();
|
|
41
66
|
};
|
|
42
67
|
// The paired devices and keys stay in the app's private storage; before another copy replaces this one the data is
|
|
43
68
|
// backed up to the folder, or beside the database while there is none.
|
|
@@ -47,11 +72,15 @@ export async function android_api(app, options = {}) {
|
|
|
47
72
|
const sync = create_sync_peer({ app: app.id, engine: app.sync_engine, database: () => database.connection, storage, device_name: `${app.name} on Android`, on_remote_change: announce });
|
|
48
73
|
// A phone may close the app at any moment once it is in the background, so the database is saved straight away.
|
|
49
74
|
lifecycle.addListener("pause", () => void database.save_now());
|
|
50
|
-
lifecycle.addListener("resume", () =>
|
|
75
|
+
lifecycle.addListener("resume", () => {
|
|
76
|
+
void sync.sync_now();
|
|
77
|
+
services.changed?.();
|
|
78
|
+
});
|
|
51
79
|
sync.start();
|
|
52
80
|
return {
|
|
53
81
|
host: "android",
|
|
54
|
-
|
|
82
|
+
// The page tells its own views of its writes, so a write here tells only the app's services.
|
|
83
|
+
calls: as_client(app.bind_methods(() => database.connection, () => services.changed?.())),
|
|
55
84
|
device: as_client(sync_device_methods(sync)),
|
|
56
85
|
certificates: phone_certificates(),
|
|
57
86
|
backups: as_client(app.backup_methods(kept, () => database.connection, () => void keeper.check())),
|
|
@@ -2,7 +2,7 @@ import "@x-tech-laboratories/halon/halon-tokens.css";
|
|
|
2
2
|
import "@x-tech-laboratories/halon/halon.css";
|
|
3
3
|
import type { App } from "../define.ts";
|
|
4
4
|
import { type AppPages } from "./settings_page.tsx";
|
|
5
|
-
export type { AppPage, AppPages, PageSettingsProps } from "./settings_page.tsx";
|
|
5
|
+
export type { AppPage, AppPages, AppSubpage, PageSettingsProps } from "./settings_page.tsx";
|
|
6
6
|
export declare function AppView({ pages }: {
|
|
7
7
|
pages: AppPages;
|
|
8
8
|
}): import("react").JSX.Element;
|
package/dist/app/web/app_page.js
CHANGED
|
@@ -38,7 +38,10 @@ function Pages({ pages, account }) {
|
|
|
38
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
|
+
// A page with pages of its own shows the one the route names, or its first; with only one it is the page itself.
|
|
42
|
+
const children = shown?.children && shown.children.length > 1 ? shown.children : [];
|
|
43
|
+
const subpage = children.find((child) => child.id === rest[0]) ?? children[0];
|
|
44
|
+
const label = shown ? (subpage ? `${subpage.label} · ${shown.label}` : shown.label) : is_account ? "Your account" : "Settings";
|
|
42
45
|
const view_key = route.parts.join("/");
|
|
43
46
|
const chrome = pages.use_chrome?.(route.parts) ?? {};
|
|
44
47
|
useEffect(() => {
|
|
@@ -49,10 +52,15 @@ function Pages({ pages, account }) {
|
|
|
49
52
|
const badges = listed.map((each) => each.use_badge?.() ?? null);
|
|
50
53
|
const row_label = (index) => (badges[index] ? `${listed[index].label} · ${badges[index]}` : listed[index].label);
|
|
51
54
|
const with_icons = listed.some((each) => each.icon);
|
|
52
|
-
const sections = listed.map((each, index) => ({
|
|
55
|
+
const sections = listed.map((each, index) => ({
|
|
56
|
+
id: each.id,
|
|
57
|
+
label: row_label(index),
|
|
58
|
+
href: `#/${each.id}`,
|
|
59
|
+
...(each.children && each.children.length > 1 ? { children: each.children.map((child) => ({ id: child.id, label: child.label, href: `#/${each.id}/${child.id}` })) } : {}),
|
|
60
|
+
}));
|
|
53
61
|
const views = listed.map((each, index) => ({ id: each.id, label: row_label(index), href: `#/${each.id}`, ...(each.icon ? { icon: each.icon } : {}) }));
|
|
54
62
|
const view = shown ? shown.view(rest) : is_account ? _jsx(AccountPage, { account: account }) : _jsx(SettingsView, { pages: pages, is_admin: account === null || is_admin(account.me) });
|
|
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) }));
|
|
63
|
+
return (_jsx(Shell, { brand: app.name, brand_icon: pages.brand_icon ?? "icon.svg", ...(with_icons ? { views } : { sections }), active: shown?.active_as ?? section, active_item: subpage?.id ?? null, sections_pref: `${app.id}-sidebar-collapsed`, ...(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) }));
|
|
56
64
|
}
|
|
57
65
|
// ── App ──────────────────────────────────────────────────────────────────────
|
|
58
66
|
// 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.
|
|
@@ -74,16 +82,18 @@ export function AppView({ pages }) {
|
|
|
74
82
|
}
|
|
75
83
|
// ── Start ────────────────────────────────────────────────────────────────────
|
|
76
84
|
// The phone's code loads only on the phone, so a browser never fetches SQLite.
|
|
77
|
-
async function host_api(app) {
|
|
85
|
+
async function host_api(app, phone_services) {
|
|
78
86
|
if (is_desktop(app))
|
|
79
87
|
return desktop_api(app);
|
|
80
|
-
if (is_android())
|
|
81
|
-
|
|
88
|
+
if (is_android()) {
|
|
89
|
+
const { android_api } = await import("./android.js");
|
|
90
|
+
return android_api(app, phone_services ? { services: await phone_services() } : {});
|
|
91
|
+
}
|
|
82
92
|
return web_api(app);
|
|
83
93
|
}
|
|
84
94
|
// Starts the page on whichever host it runs: the desktop app, the phone app or a browser.
|
|
85
95
|
export async function render_app(pages, root = document.getElementById("app")) {
|
|
86
|
-
const api = await host_api(pages.app);
|
|
96
|
+
const api = await host_api(pages.app, pages.phone_services);
|
|
87
97
|
set_page_api(api);
|
|
88
98
|
// A link the desktop app was opened with, or a tray row, opens its page.
|
|
89
99
|
api.on_event?.("open", (route) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { VersionKind } from "../../history.ts";
|
|
2
|
+
import { type Tone } from "../../web/react/badges.tsx";
|
|
3
|
+
export declare const change_labels: Record<VersionKind, [text: string, tone: Tone]>;
|
|
4
|
+
export declare function open_item_history(kind: string, item_id: string, name: string): void;
|
|
5
|
+
export declare function HistoryButton({ kind, item_id, name }: {
|
|
6
|
+
kind: string;
|
|
7
|
+
item_id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export declare function HistoryView({ subtitle }: {
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// History on the page, for an app whose items keep versions through `app/item_history`: the latest changes to every
|
|
3
|
+
// item on a page of their own, and one item's versions in a dialog opened from the item, each version restorable.
|
|
4
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { StateBadge } from "../../web/react/badges.js";
|
|
7
|
+
import { Select } from "../../web/react/controls.js";
|
|
8
|
+
import { confirm_dialog, Dialog, open_dialog } from "../../web/react/dialog.js";
|
|
9
|
+
import { PageHeading, Toolbar } from "../../web/react/layout.js";
|
|
10
|
+
import { Empty, Loaded } from "../../web/react/states.js";
|
|
11
|
+
import { DataTable } from "../../web/react/table.js";
|
|
12
|
+
import { succeeds } from "../../web/react/toasts.js";
|
|
13
|
+
import { calls, use_data } from "./page.js";
|
|
14
|
+
const history_calls = () => calls();
|
|
15
|
+
// ── Wording ──────────────────────────────────────────────────────────────────
|
|
16
|
+
export const change_labels = {
|
|
17
|
+
first_seen: ["Already here", "none"],
|
|
18
|
+
created: ["Created", "good"],
|
|
19
|
+
edited: ["Edited", "info"],
|
|
20
|
+
deleted: ["Deleted", "bad"],
|
|
21
|
+
restored: ["Restored", "warn"],
|
|
22
|
+
};
|
|
23
|
+
function when(changed_at) {
|
|
24
|
+
return new Date(changed_at).toLocaleString();
|
|
25
|
+
}
|
|
26
|
+
// Brings the version back after a confirm, since the item's current state becomes a version of its own.
|
|
27
|
+
function restore(change, on_done) {
|
|
28
|
+
const deleted = change.change === "deleted";
|
|
29
|
+
confirm_dialog({
|
|
30
|
+
title: deleted ? `Bring back ${change.item_name}?` : `Restore ${change.item_name}?`,
|
|
31
|
+
message: deleted ? "It comes back as it was when deleted, with what was deleted along with it." : `It goes back to how it was on ${when(change.changed_at)}; the way it is now stays in its history.`,
|
|
32
|
+
confirm_label: deleted ? "Bring back" : "Restore",
|
|
33
|
+
run: async () => {
|
|
34
|
+
if (await succeeds(() => history_calls().restore_item_version(change.kind, change.id), `${change.item_name} is back as it was`))
|
|
35
|
+
on_done?.();
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// ── One item ─────────────────────────────────────────────────────────────────
|
|
40
|
+
function ItemHistoryDialog({ kind, item_id, name, on_close }) {
|
|
41
|
+
const versions = use_data(() => history_calls().list_item_history(kind, item_id), [kind, item_id]);
|
|
42
|
+
// The newest version is how the item is now, so only the ones before it are offered.
|
|
43
|
+
const newest = versions.data?.[0]?.id;
|
|
44
|
+
const columns = [
|
|
45
|
+
{ label: "When", cell: (change) => when(change.changed_at) },
|
|
46
|
+
{ label: "Change", cell: (change) => _jsx(StateBadge, { labels: change_labels, state: change.change }) },
|
|
47
|
+
{ label: "Was", cell: (change) => _jsxs(_Fragment, { children: [change.item_name, " ", _jsx("span", { className: "muted small", children: change.summary })] }) },
|
|
48
|
+
{ label: "Made", cell: (change) => (change.origin === "here" ? "Here" : "On another device") },
|
|
49
|
+
{
|
|
50
|
+
label: "Actions",
|
|
51
|
+
id: "actions",
|
|
52
|
+
header: _jsx("span", { className: "visually-hidden", children: "Actions" }),
|
|
53
|
+
class: "actions-cell",
|
|
54
|
+
cell: (change) => (change.change === "deleted" || change.id === newest ? null : _jsx("button", { type: "button", onClick: () => restore(change, on_close), children: "Restore" })),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
return (_jsx(Dialog, { title: `History of ${name}`, on_close: on_close, children: _jsx(Loaded, { resource: versions, children: (list) => (list.length === 0 ? _jsx(Empty, { title: "No history yet." }) : _jsx(DataTable, { caption: `History of ${name}`, columns: columns, rows: list, row_key: (change) => change.id })) }) }));
|
|
58
|
+
}
|
|
59
|
+
// Opens an item's versions, such as from a workout's or a food's row.
|
|
60
|
+
export function open_item_history(kind, item_id, name) {
|
|
61
|
+
open_dialog((close) => _jsx(ItemHistoryDialog, { kind: kind, item_id: item_id, name: name, on_close: close }));
|
|
62
|
+
}
|
|
63
|
+
export function HistoryButton({ kind, item_id, name }) {
|
|
64
|
+
return (_jsx("button", { type: "button", "aria-label": `History of ${name}`, title: "History", onClick: () => open_item_history(kind, item_id, name), children: "History" }));
|
|
65
|
+
}
|
|
66
|
+
// ── Page ─────────────────────────────────────────────────────────────────────
|
|
67
|
+
const limits = [[50, "Last 50"], [200, "Last 200"], [1000, "Last 1000"]];
|
|
68
|
+
// The latest changes to every item, each opening its own history and a deleted one brought back from here.
|
|
69
|
+
export function HistoryView({ subtitle }) {
|
|
70
|
+
const [limit, set_limit] = useState(50);
|
|
71
|
+
const changes = use_data(() => history_calls().list_recent_changes(limit), [limit]);
|
|
72
|
+
const columns = [
|
|
73
|
+
{ label: "When", cell: (change) => when(change.changed_at) },
|
|
74
|
+
{ label: "What", cell: (change) => change.kind_label },
|
|
75
|
+
{ label: "Item", cell: (change) => _jsxs(_Fragment, { children: [change.item_name, " ", _jsx("span", { className: "muted small", children: change.summary })] }) },
|
|
76
|
+
{ label: "Change", cell: (change) => _jsx(StateBadge, { labels: change_labels, state: change.change }) },
|
|
77
|
+
{ label: "Made", cell: (change) => (change.origin === "here" ? "Here" : "On another device") },
|
|
78
|
+
{
|
|
79
|
+
label: "Actions",
|
|
80
|
+
id: "actions",
|
|
81
|
+
header: _jsx("span", { className: "visually-hidden", children: "Actions" }),
|
|
82
|
+
class: "actions-cell",
|
|
83
|
+
cell: (change) => (_jsxs("div", { className: "row-actions", children: [_jsx("button", { type: "button", onClick: () => open_item_history(change.kind, change.item_id, change.item_name), children: "History" }), change.change === "deleted" && _jsx("button", { type: "button", onClick: () => restore(change), children: "Bring back" })] })),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
return (_jsxs(_Fragment, { children: [_jsx(PageHeading, { title: "History", ...(subtitle ? { subtitle } : {}) }), _jsx(Toolbar, { children: _jsx(Select, { label: "Changes shown", options: limits, value: limit, on_change: set_limit }) }), _jsx(Loaded, { resource: changes, children: (list) => (list.length === 0 ? _jsx(Empty, { title: "No changes yet." }) : _jsx(DataTable, { caption: "Latest changes", columns: columns, rows: list, row_key: (change) => `${change.kind}:${change.id}` })) })] }));
|
|
87
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { IconGlyph } from "../../web/react/icons.tsx";
|
|
|
2
2
|
import { type SettingsCategory, type SettingsSection } from "../../web/react/layout.tsx";
|
|
3
3
|
import type { ShellSidePane } from "../../web/react/shell.tsx";
|
|
4
4
|
import type { App } from "../define.ts";
|
|
5
|
+
import type { StartPhoneServices } from "./android.ts";
|
|
5
6
|
export interface PageSettingsProps {
|
|
6
7
|
settings: Record<string, unknown>;
|
|
7
8
|
set_setting: (key: string, value: unknown) => Promise<void>;
|
|
@@ -15,6 +16,11 @@ export interface AppPage {
|
|
|
15
16
|
use_badge?: () => number | string | null;
|
|
16
17
|
in_sidebar?: boolean;
|
|
17
18
|
active_as?: string;
|
|
19
|
+
children?: readonly AppSubpage[];
|
|
20
|
+
}
|
|
21
|
+
export interface AppSubpage {
|
|
22
|
+
id: string;
|
|
23
|
+
label: string;
|
|
18
24
|
}
|
|
19
25
|
export interface AppChrome {
|
|
20
26
|
sidebar?: React.ReactNode;
|
|
@@ -29,6 +35,7 @@ export interface AppPages {
|
|
|
29
35
|
brand_icon?: string;
|
|
30
36
|
default_page?: string;
|
|
31
37
|
use_chrome?: (parts: readonly string[]) => AppChrome;
|
|
38
|
+
phone_services?: () => Promise<StartPhoneServices>;
|
|
32
39
|
}
|
|
33
40
|
export declare function SettingsView({ pages, is_admin }: {
|
|
34
41
|
pages: AppPages;
|
package/dist/caller.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export type Caller = "page" | "program" | "engine";
|
|
2
|
+
export interface CallerScope {
|
|
3
|
+
run<Result>(caller: Caller, work: () => Result): Result;
|
|
4
|
+
get(): Caller | undefined;
|
|
5
|
+
}
|
|
6
|
+
export declare function use_caller_scope(next: CallerScope | null): void;
|
|
2
7
|
export declare function as_caller<Result>(caller: Caller, work: () => Result): Result;
|
|
3
8
|
export declare function current_caller(): Caller;
|
|
4
9
|
export declare function caller_of(request: object): Caller;
|
package/dist/caller.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
// Who is making the call in hand: the user at the app's own page (a signed-in browser or the desktop window), the
|
|
2
|
-
// app's own assistant or background work acting on its own, or another program through a token or MCP.
|
|
3
|
-
//
|
|
2
|
+
// app's own assistant or background work acting on its own, or another program through a token or MCP. Where a caller
|
|
3
|
+
// scope is in use, as on a server or desktop daemon, it holds for the whole call, awaits included; elsewhere, such as a
|
|
4
|
+
// phone's page, for the call's synchronous part, which is where a store should read it.
|
|
4
5
|
let current = "page";
|
|
5
|
-
|
|
6
|
+
let scope = null;
|
|
7
|
+
// Uses the scope given from now on, or none again for null.
|
|
8
|
+
export function use_caller_scope(next) {
|
|
9
|
+
scope = next;
|
|
10
|
+
}
|
|
11
|
+
// Runs the work as the caller given; without a scope, the caller before comes back once its synchronous part ends.
|
|
6
12
|
export function as_caller(caller, work) {
|
|
7
13
|
const before = current;
|
|
8
14
|
current = caller;
|
|
9
15
|
try {
|
|
10
|
-
return work();
|
|
16
|
+
return scope ? scope.run(caller, work) : work();
|
|
11
17
|
}
|
|
12
18
|
finally {
|
|
13
19
|
current = before;
|
|
14
20
|
}
|
|
15
21
|
}
|
|
16
22
|
export function current_caller() {
|
|
17
|
-
return current;
|
|
23
|
+
return scope?.get() ?? current;
|
|
18
24
|
}
|
|
19
25
|
// The caller a server request is: a token is a program, a browser signed in itself or through a proxy is the user.
|
|
20
26
|
export function caller_of(request) {
|
package/dist/config/vitest.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// The base app's Vitest config: tests in tests/, coverage of src/ reported to the
|
|
2
|
-
// runs. An app merges its own coverage floor into it, kept in its vitest.config.ts
|
|
1
|
+
// The base app's Vitest config: tests in tests/, the base page run through Vite, coverage of src/ reported to the
|
|
2
|
+
// terminal, and one time zone for all runs. An app merges its own coverage floor into it, kept in its vitest.config.ts
|
|
3
|
+
// so autoUpdate can raise it there.
|
|
3
4
|
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
4
5
|
import react from "@vitejs/plugin-react";
|
|
5
6
|
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
@@ -10,6 +11,8 @@ export function vitest_config() {
|
|
|
10
11
|
plugins: [react()],
|
|
11
12
|
test: {
|
|
12
13
|
include: ["tests/**/*.test.ts", "tests/**/*.test.tsx"],
|
|
14
|
+
// The base app's page imports Halon's stylesheets, which only Vite can load, so it runs through Vite.
|
|
15
|
+
server: { deps: { inline: [/x-app\/dist\/app\/web/] } },
|
|
13
16
|
coverage: { provider: "v8", include: ["src/**/*.{ts,tsx}"], reporter: ["text"] },
|
|
14
17
|
},
|
|
15
18
|
};
|
package/dist/dates.d.ts
CHANGED
|
@@ -16,3 +16,5 @@ export declare function months_from(first: string, last: string): string[];
|
|
|
16
16
|
export declare function format_month(month: string, locale?: string, short?: boolean): string;
|
|
17
17
|
export declare function is_overdue(local_date: string, now?: Date): boolean;
|
|
18
18
|
export declare function relative_day_label(local_date: string, now?: Date, locale?: string): string;
|
|
19
|
+
export declare function epoch_of_day(day: string): number;
|
|
20
|
+
export declare function day_of_epoch(epoch: number): string;
|
package/dist/dates.js
CHANGED
|
@@ -96,3 +96,12 @@ export function relative_day_label(local_date, now = new Date(), locale) {
|
|
|
96
96
|
function capitalised(text, locale) {
|
|
97
97
|
return text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
|
|
98
98
|
}
|
|
99
|
+
// ── Charts ───────────────────────────────────────────────────────────────────
|
|
100
|
+
// A day such as "2026-11-10" as the seconds since 1970 a chart point takes, read in UTC so a time zone never moves it.
|
|
101
|
+
export function epoch_of_day(day) {
|
|
102
|
+
return Date.parse(`${day}T00:00:00Z`) / 1000;
|
|
103
|
+
}
|
|
104
|
+
// A chart point's seconds since 1970 as the day it stands for, read in UTC.
|
|
105
|
+
export function day_of_epoch(epoch) {
|
|
106
|
+
return new Date(epoch * 1000).toISOString().slice(0, 10);
|
|
107
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The caller scope on Node, so a call's caller holds across its awaits on a server or a desktop daemon.
|
|
2
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
// ── Scope ────────────────────────────────────────────────────────────────────
|
|
5
|
+
export function node_caller_scope() {
|
|
6
|
+
const storage = new AsyncLocalStorage();
|
|
7
|
+
return { run: (caller, work) => storage.run(caller, work), get: () => storage.getStore() };
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface DayOptions {
|
|
2
|
+
initial?: string;
|
|
3
|
+
remember?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function use_day({ initial, remember }?: DayOptions): [day: string, set_day: (day: string) => void];
|
|
6
|
+
export declare function DayStepper({ day, on_change }: {
|
|
7
|
+
day: string;
|
|
8
|
+
on_change: (day: string) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// The day a page shows, today to begin with, and the stepper that moves it a day at a time.
|
|
3
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { is_day, today } from "../../dates.js";
|
|
6
|
+
import { PeriodStepper } from "./controls.js";
|
|
7
|
+
import { read_pref, write_pref } from "../prefs.js";
|
|
8
|
+
// ── Day ──────────────────────────────────────────────────────────────────────
|
|
9
|
+
// This tab's session storage, or nothing where there is none or it may not be touched.
|
|
10
|
+
function session_storage() {
|
|
11
|
+
try {
|
|
12
|
+
return globalThis.sessionStorage;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function use_day({ initial, remember } = {}) {
|
|
19
|
+
const [day, set_state] = useState(() => {
|
|
20
|
+
const first = initial ?? today();
|
|
21
|
+
return remember ? read_pref(session_storage(), remember, first, is_day) : first;
|
|
22
|
+
});
|
|
23
|
+
function set_day(next) {
|
|
24
|
+
set_state(next);
|
|
25
|
+
if (remember)
|
|
26
|
+
write_pref(session_storage(), remember, next);
|
|
27
|
+
}
|
|
28
|
+
return [day, set_day];
|
|
29
|
+
}
|
|
30
|
+
export function DayStepper({ day, on_change }) {
|
|
31
|
+
return _jsx(PeriodStepper, { label: "Day", period: "day", value: day, on_change: on_change });
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface AddNameFormProps {
|
|
2
|
+
label: string;
|
|
3
|
+
button: string;
|
|
4
|
+
on_add: (name: string) => Promise<boolean>;
|
|
5
|
+
class_name?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function AddNameForm({ label, button, on_add, class_name }: AddNameFormProps): import("react").JSX.Element;
|
|
8
|
+
export declare function RenameField({ label, value, on_done }: {
|
|
9
|
+
label: string;
|
|
10
|
+
value: string;
|
|
11
|
+
on_done: (name: string | null) => void;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
export declare function use_rename<Key>(save: (key: Key, name: string) => void): {
|
|
14
|
+
renaming: Key | null;
|
|
15
|
+
start: (key: Key) => void;
|
|
16
|
+
field: (key: Key, name: string) => import("react").JSX.Element;
|
|
17
|
+
};
|
|
18
|
+
export declare function FormButtons({ can_save, on_cancel }: {
|
|
19
|
+
can_save: boolean;
|
|
20
|
+
on_cancel: () => void;
|
|
21
|
+
}): import("react").JSX.Element;
|
|
22
|
+
export declare function DialogButtons({ can_save, on_save, on_cancel }: {
|
|
23
|
+
can_save?: boolean;
|
|
24
|
+
on_save: () => void;
|
|
25
|
+
on_cancel: () => void;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The small form pieces lists share: a toolbar form that adds an item by name, a name renamed in place, and the
|
|
3
|
+
// Save and Cancel buttons under a form or a dialog.
|
|
4
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
// A name typed into a toolbar and added with its button or Enter.
|
|
7
|
+
export function AddNameForm({ label, button, on_add, class_name = "toolbar" }) {
|
|
8
|
+
const [draft, set_draft] = useState("");
|
|
9
|
+
return (_jsxs("form", { className: class_name, onSubmit: (event) => {
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
const name = draft.trim();
|
|
12
|
+
if (name)
|
|
13
|
+
void on_add(name).then((added) => added && set_draft(""));
|
|
14
|
+
}, children: [_jsx("input", { type: "text", "aria-label": label, placeholder: `${label}…`, value: draft, onChange: (event) => set_draft(event.currentTarget.value) }), _jsx("button", { type: "submit", className: "accent solid", disabled: !draft.trim(), children: button })] }));
|
|
15
|
+
}
|
|
16
|
+
// ── Renaming ─────────────────────────────────────────────────────────────────
|
|
17
|
+
// A name edited in place: Enter or leaving saves it, Escape gives up.
|
|
18
|
+
export function RenameField({ label, value, on_done }) {
|
|
19
|
+
const [draft, set_draft] = useState(value);
|
|
20
|
+
const keyed = (event) => {
|
|
21
|
+
if (event.key === "Enter") {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
on_done(draft);
|
|
24
|
+
}
|
|
25
|
+
else if (event.key === "Escape") {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
on_done(null);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return _jsx("input", { type: "text", "aria-label": label, autoFocus: true, value: draft, onChange: (event) => set_draft(event.currentTarget.value), onKeyDown: keyed, onBlur: () => on_done(draft) });
|
|
31
|
+
}
|
|
32
|
+
// Which item of a list is being renamed, and the field that renames it; a name left blank or unchanged saves nothing.
|
|
33
|
+
export function use_rename(save) {
|
|
34
|
+
const [renaming, set_renaming] = useState(null);
|
|
35
|
+
const field = (key, name) => (_jsx(RenameField, { label: `Rename ${name}`, value: name, on_done: (next) => {
|
|
36
|
+
set_renaming(null);
|
|
37
|
+
const target = next?.trim() ?? "";
|
|
38
|
+
if (target && target !== name)
|
|
39
|
+
save(key, target);
|
|
40
|
+
} }));
|
|
41
|
+
return { renaming, start: (key) => set_renaming(() => key), field };
|
|
42
|
+
}
|
|
43
|
+
// ── Saving ───────────────────────────────────────────────────────────────────
|
|
44
|
+
// Save and Cancel under a form on its own page, Save sending the form.
|
|
45
|
+
export function FormButtons({ can_save, on_cancel }) {
|
|
46
|
+
return (_jsxs("div", { className: "form-actions inline-row", children: [_jsx("button", { type: "submit", className: "accent solid", disabled: !can_save, children: "Save" }), _jsx("button", { type: "button", onClick: on_cancel, children: "Cancel" })] }));
|
|
47
|
+
}
|
|
48
|
+
// Cancel and Save at the foot of a dialog.
|
|
49
|
+
export function DialogButtons({ can_save = true, on_save, on_cancel }) {
|
|
50
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: on_cancel, children: "Cancel" }), _jsx("button", { type: "button", className: "accent solid", disabled: !can_save, onClick: on_save, children: "Save" })] }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface LookupFound<Result> {
|
|
3
|
+
results: Result[];
|
|
4
|
+
errors?: string[];
|
|
5
|
+
}
|
|
6
|
+
interface LookupPanelProps<Result> {
|
|
7
|
+
label: string;
|
|
8
|
+
results_label: string;
|
|
9
|
+
search: (query: string) => Promise<LookupFound<Result>>;
|
|
10
|
+
failure_text?: (reason: string) => string;
|
|
11
|
+
empty_text: string;
|
|
12
|
+
key_of: (result: Result) => string | number;
|
|
13
|
+
row: (result: Result, pick: () => void) => ReactNode;
|
|
14
|
+
on_pick: (result: Result) => void;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
class_name?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function LookupPanel<Result>({ label, results_label, search, failure_text, empty_text, key_of, row, on_pick, children, class_name }: LookupPanelProps<Result>): import("react").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A search of an online database above a form: a search box, what went wrong, and the results, one of which is picked to
|
|
3
|
+
// fill the form in; nothing is saved until the form is.
|
|
4
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { describe_error } from "../errors.js";
|
|
7
|
+
import { SearchBox } from "./controls.js";
|
|
8
|
+
export function LookupPanel({ label, results_label, search, failure_text = (reason) => reason, empty_text, key_of, row, on_pick, children, class_name = "stack tight" }) {
|
|
9
|
+
const [found, set_found] = useState(null);
|
|
10
|
+
const [searching, set_searching] = useState(false);
|
|
11
|
+
const [failure, set_failure] = useState("");
|
|
12
|
+
async function run(query) {
|
|
13
|
+
if (!query.trim())
|
|
14
|
+
return set_found(null);
|
|
15
|
+
set_searching(true);
|
|
16
|
+
set_failure("");
|
|
17
|
+
try {
|
|
18
|
+
set_found(await search(query));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
set_failure(failure_text(describe_error(error)));
|
|
22
|
+
set_found(null);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
set_searching(false);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const errors = [failure, ...(found?.errors ?? [])].filter(Boolean);
|
|
29
|
+
return (_jsxs("div", { className: class_name, children: [_jsx(SearchBox, { label: label, value: "", submit_label: "Search", on_submit: (query) => void run(query) }), children, searching && (_jsx("p", { className: "muted", role: "status", children: "Searching\u2026" })), errors.map((error) => (_jsx("p", { className: "tone-bad", role: "alert", children: error }, error))), found && !searching && found.results.length === 0 && _jsx("p", { className: "muted small", children: empty_text }), found && !searching && found.results.length > 0 && (_jsx("ul", { className: "plain-list result-list", "aria-label": results_label, children: found.results.map((result) => (_jsx("li", { children: row(result, () => {
|
|
30
|
+
on_pick(result);
|
|
31
|
+
set_found(null);
|
|
32
|
+
}) }, key_of(result)))) }))] }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TableColumn } from "./table.tsx";
|
|
3
|
+
export declare function confirm_delete(title: string, message: ReactNode, run: () => Promise<unknown>): void;
|
|
4
|
+
export interface RowActionsOptions<Row> {
|
|
5
|
+
name: (row: Row) => string;
|
|
6
|
+
edit?: (row: Row) => void;
|
|
7
|
+
buttons?: (row: Row) => ReactNode;
|
|
8
|
+
history?: (row: Row) => ReactNode;
|
|
9
|
+
trailing?: (row: Row) => ReactNode;
|
|
10
|
+
remove?: (row: Row) => void;
|
|
11
|
+
remove_text?: string;
|
|
12
|
+
width?: number;
|
|
13
|
+
hideable?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function row_actions_column<Row>({ name, edit, buttons, history, trailing, remove, remove_text, width, hideable }: RowActionsOptions<Row>): TableColumn<Row>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { confirm_dialog } from "./dialog.js";
|
|
3
|
+
// ── Deleting ─────────────────────────────────────────────────────────────────
|
|
4
|
+
// Asks before deleting, with a red Delete that runs the call.
|
|
5
|
+
export function confirm_delete(title, message, run) {
|
|
6
|
+
confirm_dialog({ title, message, confirm_label: "Delete", danger: true, run: async () => void (await run()) });
|
|
7
|
+
}
|
|
8
|
+
// A table's last column with each row's buttons, in the same order and with the same labels in every list.
|
|
9
|
+
export function row_actions_column({ name, edit, buttons, history, trailing, remove, remove_text = "Delete", width, hideable }) {
|
|
10
|
+
return {
|
|
11
|
+
label: "Actions",
|
|
12
|
+
id: "actions",
|
|
13
|
+
header: _jsx("span", { className: "visually-hidden", children: "Actions" }),
|
|
14
|
+
class: "actions-cell",
|
|
15
|
+
...(width !== undefined ? { width } : {}),
|
|
16
|
+
...(hideable !== undefined ? { hideable } : {}),
|
|
17
|
+
cell: (row) => (_jsxs("div", { className: "row-actions", children: [edit && (_jsx("button", { type: "button", "aria-label": `Edit ${name(row)}`, onClick: () => edit(row), children: "Edit" })), buttons?.(row), history?.(row), trailing?.(row), remove && (_jsx("button", { type: "button", className: "danger", "aria-label": `${remove_text} ${name(row)}`, onClick: () => remove(row), children: remove_text }))] })),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -15,6 +15,9 @@ export interface ToastOptions {
|
|
|
15
15
|
export type ToastCloseReason = "timeout" | "dismissed" | "action" | "closed";
|
|
16
16
|
export declare function toast(message: string, options?: ToastOptions): () => void;
|
|
17
17
|
export declare function attempt(work: Promise<unknown>): void;
|
|
18
|
+
export declare function show_error(error: unknown): void;
|
|
19
|
+
export declare function attempt_value<Result>(work: () => Promise<Result>, done?: string): Promise<Result | undefined>;
|
|
20
|
+
export declare function succeeds(work: () => Promise<unknown>, done?: string): Promise<boolean>;
|
|
18
21
|
export interface UndoableOptions {
|
|
19
22
|
commit: () => void;
|
|
20
23
|
undo: () => void;
|
package/dist/web/react/toasts.js
CHANGED
|
@@ -28,7 +28,28 @@ export function toast(message, options = {}) {
|
|
|
28
28
|
}
|
|
29
29
|
// Runs work the user started, such as a save, and shows its failure, if any, as a bad toast in plain words.
|
|
30
30
|
export function attempt(work) {
|
|
31
|
-
work.catch((error) =>
|
|
31
|
+
work.catch((error) => show_error(error));
|
|
32
|
+
}
|
|
33
|
+
// Shows anything thrown as a bad toast in plain words.
|
|
34
|
+
export function show_error(error) {
|
|
35
|
+
toast(describe_error(error), { tone: "bad" });
|
|
36
|
+
}
|
|
37
|
+
// Runs a call and gives back its answer, or undefined once its failure is shown; done, when given, is toasted on success.
|
|
38
|
+
export async function attempt_value(work, done) {
|
|
39
|
+
try {
|
|
40
|
+
const result = await work();
|
|
41
|
+
if (done)
|
|
42
|
+
toast(done, { tone: "good" });
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
show_error(error);
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Whether a call went through, its failure shown; done, when given, is toasted on success.
|
|
51
|
+
export async function succeeds(work, done) {
|
|
52
|
+
return (await attempt_value(async () => (await work(), true), done)) === true;
|
|
32
53
|
}
|
|
33
54
|
// Shows the message with an Undo button, then either undoes or commits the action, exactly once.
|
|
34
55
|
export function undoable(message, { commit, undo, duration_in_milliseconds = 8000, undo_label = "Undo" }) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
interface UnitNumberProps {
|
|
3
|
+
label: string;
|
|
4
|
+
value: number;
|
|
5
|
+
on_change: (value: number) => void;
|
|
6
|
+
to_shown?: (value: number) => number;
|
|
7
|
+
to_stored?: (shown: number) => number;
|
|
8
|
+
unit?: string;
|
|
9
|
+
step?: number;
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
show_zero?: boolean;
|
|
13
|
+
form_row?: string;
|
|
14
|
+
setting_row?: boolean;
|
|
15
|
+
hint?: ReactNode;
|
|
16
|
+
bare?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function UnitNumber({ label, value, on_change, to_shown, to_stored, unit, step, min, max, show_zero, form_row, setting_row, hint, bare }: UnitNumberProps): import("react").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { NumberField } from "./controls.js";
|
|
3
|
+
import { FormRow, SettingRow } from "./layout.js";
|
|
4
|
+
export function UnitNumber({ label, value, on_change, to_shown = (stored) => stored, to_stored = (shown) => shown, unit, step, min, max, show_zero = false, form_row, setting_row = false, hint, bare = false }) {
|
|
5
|
+
const shown = value !== 0 || show_zero ? to_shown(value) : null;
|
|
6
|
+
const field = (_jsx(NumberField, { bare: bare || form_row !== undefined || setting_row, label: label, value: shown, min: min, max: max, step: step, unit: unit, on_change: (next) => {
|
|
7
|
+
if (next !== shown)
|
|
8
|
+
on_change(next ? to_stored(next) : 0);
|
|
9
|
+
} }));
|
|
10
|
+
if (form_row !== undefined)
|
|
11
|
+
return _jsx(FormRow, { label: label, id: form_row, hint: hint, children: field });
|
|
12
|
+
if (setting_row)
|
|
13
|
+
return _jsx(SettingRow, { label: label, hint: hint, children: field });
|
|
14
|
+
return field;
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.114.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": {
|