pcbjam/web/standalone/src/wasm/collab/debug.ts

23 lines
775 B
TypeScript
Raw Normal View History

feat(pl_editor): Yjs collaborative bridge — differ/apply + generic reconciler (yjs-bridge commit 2) Bidirectional bridge between pl_editor's DS_DATA_MODEL and a Yjs doc, two same-origin tabs syncing over BroadcastChannel. Full architecture in features/yjs-bridge/0001-0002. C++ (wasm layer, wasm/bindings/pl_editor_embind.cpp — public DS_DATA_MODEL API only, zero added fork divergence beyond the OnModify hook): - snapshot-differ ChangeSource: diff model vs last-emitted snapshot on OnModify, emit per-item delta JSON via EM_ASM window.kicadCollab.onDelta - kicadCollabApply(json): apply remote delta by uuid — scalars (text/segment/rect) by field, polygon/bitmap via SetPageLayout-append blob; reseed snapshot + HardRedraw - kicadCollabSnapshot() (seed/baseline), s_applyingRemote echo guard, and a kicadCollabTestAddText() PoC local-edit hook - wire format: {added:[item],changed:[item],removed:[uuid]}, item = {id,type,...fields} JS (web/apps/frontend/src/wasm/collab/, generic + schema-agnostic): - reconciler: uuid-keyed Y.Map of per-item Y.Map; down = onDelta→Y, up = observe→apply, origin-tagged echo suppression; seed-once join adopts the doc authoritatively - broadcast-transport: minimal BroadcastChannel Yjs provider (query/state catch-up) - WasmTool wiring behind ?collab=1 (pl_editor only); gated debug logging Tests: tests/kicad/pl_editor-collab.spec.ts — single-page C++ contract (snapshot/apply changed+removed+added/echo-suppression) + two-tab BroadcastChannel A<->B propagation. Reconciler+yjs bundled via esbuild (tests/collab/build.mjs, npm run build:collab). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 14:25:22 +02:00
// Lightweight collab debug logging to the BROWSER DEVTOOLS console (not the in-app
// log panel). On by default while we bring the bridge up; silence with
// `window.__COLLAB_DEBUG = false` (or `localStorage.collabDebug = "0"`).
function on(): boolean {
const w = window as unknown as { __COLLAB_DEBUG?: boolean };
if (typeof w.__COLLAB_DEBUG === "boolean") return w.__COLLAB_DEBUG;
try {
if (localStorage.getItem("collabDebug") === "0") return false;
} catch {
/* ignore */
}
return true;
}
const STYLE = "color:#0bd;font-weight:bold";
export function clog(...args: unknown[]): void {
if (on()) console.log("%c[collab]", STYLE, ...args);
}
export function cwarn(...args: unknown[]): void {
if (on()) console.warn("%c[collab]", STYLE, ...args);
}