mirror of
https://github.com/meshtastic/web.git
synced 2026-07-31 06:56:28 -04:00
Replaces the (broken) web changeRegistry with a section-grain editor that
lives on the SDK. Per-connection state, signal-backed, exposed via
client.config.editor.
ConfigEditor (domain):
- baseline = what the device most recently sent. Updated automatically
from onConfigPacket / onModuleConfigPacket / onChannelPacket.
- working = UI edits. setRadioSection / setModuleSection / setChannel.
- dirtyRadioSections / dirtyModuleSections / dirtyChannels signals plus
an aggregate isDirty signal.
- Inbound baseline updates do NOT discard pending working changes — if a
section is already dirty, the new baseline is recorded but working stays
put; dirty bookkeeping recomputes against the updated baseline.
- reset() restores working = baseline.
- commit() wraps beginEditSettings → setConfig per dirty radio variant +
setModuleConfig per dirty module variant + setChannel per dirty channel
→ commitEditSettings, then optimistically promotes working to baseline.
- Disconnect clears both baseline and working so a stale working copy can
never leak across reconnects.
Domain types:
- RadioConfig and ModuleConfig are now derived directly from the proto
Config / ModuleConfig payloadVariant union (Extract<{case: V}> shape) so
new variants stay typed without manual list maintenance. This adds
deviceUi (radio) and statusmessage (module) automatically.
sdk-react:
- New useConfigEditor() hook returns the editor for the active client, or
undefined when no client is active. Components subscribe to the editor's
signals via the existing useSignal helper.
Tests:
- 5 new ConfigEditor tests covering: clean start, dirty tracking, multi-
section dirty, reset, mid-edit baseline update preservation, and
disconnect-clears-state. SDK suite 49 passing.
This commit is scaffolding only — no web settings page rewires yet. The
~25 settings pages move to editor.set* / editor.commit() in follow-up
commits, replacing setChange / commitEditSettings call sites and unblocking
deletion of changeRegistry from the device store.
@meshtastic/sdk-react
React hooks and provider for @meshtastic/sdk.
Install
pnpm add @meshtastic/sdk @meshtastic/sdk-react @meshtastic/transport-web-serial
Quickstart
import { MeshClient } from "@meshtastic/sdk";
import { MeshProvider, useDevice, useChat } from "@meshtastic/sdk-react";
import { TransportWebSerial } from "@meshtastic/transport-web-serial";
import { ChannelNumber } from "@meshtastic/sdk";
const transport = await TransportWebSerial.create({ baudRate: 115200 });
const client = new MeshClient({ transport });
await client.connect();
function App() {
return (
<MeshProvider client={client}>
<Status />
</MeshProvider>
);
}
function Status() {
const { status, myNodeNum } = useDevice();
const { messages, send } = useChat(ChannelNumber.Primary);
return <div>{status} / {myNodeNum} / {messages.length} msgs</div>;
}
All hooks are read-only against a single MeshClient instance supplied through context. Commands are returned as stable functions.
License
GPL-3.0-only.