/// // Browser-integration fixture for cf-iframe's real CellHandle bridge. The // surrounding pattern exposes scoped cells as sibling readouts while the // sandboxed guest performs every mutation through the bridge. The guest also // joins the presence room of the space-scoped cell on command, and reports // the room to the page that embeds the piece. import { action, cfSqlite, computed, type Default, pattern, type PerSession, type PerSpace, type PerUser, sqliteDatabase, type SqliteDb, UI, type VNode, type Writable, } from "commonfabric"; export type TextCell = Writable>; export type RevisionCell = Writable>; export interface BridgeFixtureInput { shared?: PerSpace; user?: PerUser; session?: PerSession; databaseRows?: PerSession; userDatabaseRows?: PerSession; sessionDatabaseRows?: PerSession; reloadRevision?: PerSession; } interface IframeContextInput { shared: TextCell; user: TextCell; session: TextCell; databaseRows: TextCell; userDatabaseRows: TextCell; sessionDatabaseRows: TextCell; database: SqliteDb; userDatabase: SqliteDb; sessionDatabase: SqliteDb; room: TextCell; } export interface IframeContextOutput extends IframeContextInput {} export interface BridgeFixtureOutput { [UI]: VNode; } const IframeContext = pattern( (state) => state, ); // This deliberately uses the bridge wire protocol directly. The guest helper // and React hooks have their own focused tests; this fixture pins the browser // product boundary without requiring a module server inside the opaque guest. const GUEST_HTML = `
connecting
`; export default pattern((state) => { const { table } = cfSqlite; const tables = { bridge_items: table({ id: "integer primary key", value: "text", }), }; const database = sqliteDatabase({ tables }); const userDatabase: PerUser = sqliteDatabase({ tables }); const sessionDatabase: PerSession = sqliteDatabase( { tables }, ); const context = IframeContext({ shared: state.shared, user: state.user, session: state.session, databaseRows: state.databaseRows, userDatabaseRows: state.userDatabaseRows, sessionDatabaseRows: state.sessionDatabaseRows, database, userDatabase, sessionDatabase, // A presence room is the one derived from its cell's resolved field, and // a space-scoped field is the same for every session of every identity. room: state.shared, }); const source = computed(() => GUEST_HTML + '' ); const reloadGuest = action(() => { state.reloadRevision.set(state.reloadRevision.get() + 1); }); return { [UI]: (
{context.shared}
{context.user}
{context.session}
{context.databaseRows}
{context.userDatabaseRows}
{context.sessionDatabaseRows}
Reload guest
), }; });