pcbjam/tests/collab/build.mjs
Gergő Törcsvári 83b3418778
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-05 13:56:41 +02:00

21 lines
861 B
JavaScript

// Bundle the collab browser entry (reconciler + Yjs + BroadcastChannel transport,
// sourced from the web frontend) into a single IIFE the pl_editor harness loads.
// nodePaths lets esbuild resolve `yjs` from tests/node_modules even though the
// reconciler lives under web/. Output: apps/kicad/collab-bundle.js (global KicadCollab).
import { build } from "esbuild";
import path from "node:path";
import { fileURLToPath } from "node:url";
const testsDir = path.resolve(fileURLToPath(new URL("..", import.meta.url)));
await build({
entryPoints: [path.join(testsDir, "collab/browser-entry.ts")],
bundle: true,
format: "iife",
outfile: path.join(testsDir, "apps/kicad/collab-bundle.js"),
nodePaths: [path.join(testsDir, "node_modules")],
logLevel: "info",
target: "es2020",
});
console.log("collab bundle built → apps/kicad/collab-bundle.js");