@kitionstage/sdk 0.0.0-stage → 0.5.2-stage.13
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 +73 -2
- package/dist/LICENSE +177 -0
- package/dist/THIRD_PARTY_NOTICES +28 -0
- package/dist/lib/assets/kitEngine.worker-3iMvwtlI.js +12732 -0
- package/dist/lib/assets/loro_wasm_bg-Gulzks_0.wasm +0 -0
- package/dist/lib/chunks/batch-BWpAyHvP.js +789 -0
- package/dist/lib/chunks/canonical-BIWfVCL-.js +87 -0
- package/dist/lib/chunks/envelope-D6MGY-ZN.js +61 -0
- package/dist/lib/chunks/replica-D8w3I4sn.js +2472 -0
- package/dist/lib/chunks/runtime-BVJHE1Pg.js +997 -0
- package/dist/lib/chunks/session-BqXC9a1-.js +281 -0
- package/dist/lib/chunks/toolIds-BCeSGHpV.js +821 -0
- package/dist/lib/chunks/workspaceTree-Destqupf.js +23 -0
- package/dist/lib/convergence/index.js +1035 -0
- package/dist/lib/convergence/node.js +8 -0
- package/dist/lib/embed-server/callbacks.js +37 -0
- package/dist/lib/embed-server/cli.js +19 -0
- package/dist/lib/embed-server/index.js +272 -0
- package/dist/lib/extensions/index.js +439 -0
- package/dist/lib/extensions/panel.html +208 -0
- package/dist/lib/extensions/runtime.js +198 -0
- package/dist/lib/extensions/sandbox.html +35 -0
- package/dist/lib/kdm/index.js +437 -0
- package/dist/lib/kit-dev-host/checkUiIds.mjs +44 -0
- package/dist/lib/kit-dev-host/index.js +308 -0
- package/dist/lib/kit-dev-host/lineRow.mjs +47 -0
- package/dist/lib/kit-dev-host/modeSmoke.mjs +178 -0
- package/dist/lib/kit-editor/index.js +6481 -0
- package/dist/lib/kit-editor/styles.css +807 -0
- package/dist/lib/kit-editor/workspaceTree.js +1 -0
- package/dist/lib/kit-engine/index.js +7 -0
- package/dist/lib/kit-host/index.js +530 -0
- package/dist/lib/kit-ui-protocol/index.js +336 -0
- package/dist/lib/node-only/embed-server-callbacks.js +2 -0
- package/dist/lib/node-only/embed-server.js +2 -0
- package/dist/lib/sync/index.js +1008 -0
- package/dist/lib/sync/openToken.js +201 -0
- package/dist/lib/sync/replicaVersions.js +51 -0
- package/dist/standalone/chunks/batch-CAGYk6m4.js +789 -0
- package/dist/standalone/chunks/client-B9xkOcvf.js +772 -0
- package/dist/standalone/chunks/collab-CTQZ9h7J.js +1022 -0
- package/dist/standalone/chunks/comment-Ds9t8xSE.js +94 -0
- package/dist/standalone/chunks/comments-uVDS8Wxp.js +41 -0
- package/dist/standalone/chunks/document-B5MMuYyN.js +324 -0
- package/dist/standalone/chunks/envelope-GX4Cynkx.js +7612 -0
- package/dist/standalone/chunks/index-BEgEEnhU.js +287 -0
- package/dist/standalone/chunks/index-EEl8hGbP.js +1967 -0
- package/dist/standalone/chunks/kits-Cp51mDlw.js +9 -0
- package/dist/standalone/chunks/replica-Di2iCPiD.js +3281 -0
- package/dist/standalone/chunks/replicaVersions-C3rJxnk9.js +50 -0
- package/dist/standalone/chunks/touched-T9jKJjxn.js +78 -0
- package/dist/standalone/index.js +12 -0
- package/dist/standalone/script/index.js +339 -0
- package/dist/standalone/script/kits/board.js +5 -0
- package/dist/standalone/script/kits/cad.js +5 -0
- package/dist/standalone/script/kits/design.js +5 -0
- package/dist/standalone/script/kits/doc.js +5 -0
- package/dist/standalone/script/kits/film.js +5 -0
- package/dist/standalone/script/kits/html.js +5 -0
- package/dist/standalone/script/kits/index.js +38 -0
- package/dist/standalone/script/kits/layout.js +5 -0
- package/dist/standalone/script/kits/motion.js +5 -0
- package/dist/standalone/script/kits/note.js +5 -0
- package/dist/standalone/script/kits/pdf.js +5 -0
- package/dist/standalone/script/kits/photo.js +5 -0
- package/dist/standalone/script/kits/scene.js +5 -0
- package/dist/standalone/script/kits/sheet.js +5 -0
- package/dist/standalone/script/kits/slide.js +5 -0
- package/dist/standalone/script/kits/table.js +5 -0
- package/dist/standalone/script/kits/vector.js +5 -0
- package/dist/standalone/script/node.js +401 -0
- package/dist/standalone/script/proxy.js +254 -0
- package/dist/types/convergence/src/adapter.d.ts +131 -0
- package/dist/types/convergence/src/engine.d.ts +66 -0
- package/dist/types/convergence/src/index.d.ts +21 -0
- package/dist/types/convergence/src/net.d.ts +52 -0
- package/dist/types/convergence/src/node.d.ts +6 -0
- package/dist/types/convergence/src/report.d.ts +56 -0
- package/dist/types/convergence/src/rng.d.ts +12 -0
- package/dist/types/convergence/src/scenarios.d.ts +15 -0
- package/dist/types/convergence/src/state.d.ts +67 -0
- package/dist/types/embed/src/agent.d.ts +88 -0
- package/dist/types/embed/src/blobs.d.ts +2 -0
- package/dist/types/embed/src/collab.d.ts +250 -0
- package/dist/types/embed/src/comments.d.ts +30 -0
- package/dist/types/embed/src/errors.d.ts +24 -0
- package/dist/types/embed/src/handlers.d.ts +92 -0
- package/dist/types/embed/src/index.d.ts +20 -0
- package/dist/types/embed/src/mount.d.ts +39 -0
- package/dist/types/embed/src/replicaStore.d.ts +3 -0
- package/dist/types/embed/src/rooms.d.ts +40 -0
- package/dist/types/embed/src/schemas.d.ts +7 -0
- package/dist/types/embed/src/syncClients.d.ts +28 -0
- package/dist/types/embed/src/theme.d.ts +7 -0
- package/dist/types/embed/src/types.d.ts +596 -0
- package/dist/types/embed/src/ui.d.ts +33 -0
- package/dist/types/embed/src/version.d.ts +2 -0
- package/dist/types/embed-server/src/callbacks.d.ts +30 -0
- package/dist/types/embed-server/src/cli.d.ts +1 -0
- package/dist/types/embed-server/src/index.d.ts +19 -0
- package/dist/types/embed-server/src/page.d.ts +15 -0
- package/dist/types/embed-server/src/server.d.ts +39 -0
- package/dist/types/embed-server/src/session.d.ts +22 -0
- package/dist/types/extensions/src/gate.d.ts +17 -0
- package/dist/types/extensions/src/generated/runtime.d.ts +8 -0
- package/dist/types/extensions/src/host.d.ts +135 -0
- package/dist/types/extensions/src/index.d.ts +13 -0
- package/dist/types/extensions/src/manifest.d.ts +82 -0
- package/dist/types/extensions/src/protocol.d.ts +159 -0
- package/dist/types/extensions/src/rpc.d.ts +52 -0
- package/dist/types/extensions/src/runtime/document.d.ts +40 -0
- package/dist/types/extensions/src/runtime/index.d.ts +10 -0
- package/dist/types/extensions/src/runtime/panel.d.ts +19 -0
- package/dist/types/extensions/src/runtime/runtime.d.ts +54 -0
- package/dist/types/extensions/src/runtime/worker.d.ts +1 -0
- package/dist/types/extensions/src/sandbox.d.ts +41 -0
- package/dist/types/kdm/src/args.d.ts +12 -0
- package/dist/types/kdm/src/batch.d.ts +118 -0
- package/dist/types/kdm/src/canonical.d.ts +25 -0
- package/dist/types/kdm/src/comment.d.ts +114 -0
- package/dist/types/kdm/src/diff.d.ts +125 -0
- package/dist/types/kdm/src/envelope.d.ts +27 -0
- package/dist/types/kdm/src/errors.d.ts +28 -0
- package/dist/types/kdm/src/footprint.d.ts +21 -0
- package/dist/types/kdm/src/ids.d.ts +57 -0
- package/dist/types/kdm/src/index.d.ts +18 -0
- package/dist/types/kdm/src/marks.d.ts +32 -0
- package/dist/types/kdm/src/op.d.ts +124 -0
- package/dist/types/kdm/src/origin.d.ts +41 -0
- package/dist/types/kdm/src/overlay.d.ts +92 -0
- package/dist/types/kdm/src/projection.d.ts +29 -0
- package/dist/types/kdm/src/read.d.ts +90 -0
- package/dist/types/kdm/src/replica.d.ts +403 -0
- package/dist/types/kdm/src/schema.d.ts +185 -0
- package/dist/types/kdm/src/testing.d.ts +28 -0
- package/dist/types/kdm/src/toolIds.d.ts +61 -0
- package/dist/types/kdm/src/touched.d.ts +24 -0
- package/dist/types/kdm/src/tx.d.ts +215 -0
- package/dist/types/kdm/src/value.d.ts +23 -0
- package/dist/types/kit-dev-host/src/checkNoPaths.d.ts +19 -0
- package/dist/types/kit-dev-host/src/checkUiIds.d.mts +2 -0
- package/dist/types/kit-dev-host/src/index.d.ts +179 -0
- package/dist/types/kit-dev-host/src/lineRow.d.mts +14 -0
- package/dist/types/kit-dev-host/src/memoryFiles.d.ts +15 -0
- package/dist/types/kit-dev-host/src/modeSmoke.d.mts +8 -0
- package/dist/types/kit-editor/src/CommandDialog.d.ts +22 -0
- package/dist/types/kit-editor/src/CommentsPanel.d.ts +45 -0
- package/dist/types/kit-editor/src/CustomizeDialog.d.ts +32 -0
- package/dist/types/kit-editor/src/HostButtons.d.ts +11 -0
- package/dist/types/kit-editor/src/RenderFailure.d.ts +7 -0
- package/dist/types/kit-editor/src/TextSink.d.ts +6 -0
- package/dist/types/kit-editor/src/brand.d.ts +2 -0
- package/dist/types/kit-editor/src/catalogMenus.d.ts +27 -0
- package/dist/types/kit-editor/src/chart.d.ts +138 -0
- package/dist/types/kit-editor/src/conflicts.d.ts +12 -0
- package/dist/types/kit-editor/src/drawing.d.ts +83 -0
- package/dist/types/kit-editor/src/editor.d.ts +544 -0
- package/dist/types/kit-editor/src/engine/KitCanvas.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/backdrop.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/createKitFile.d.ts +12 -0
- package/dist/types/kit-editor/src/engine/decorations.d.ts +14 -0
- package/dist/types/kit-editor/src/engine/engineOverlays.d.ts +197 -0
- package/dist/types/kit-editor/src/engine/engineTools.d.ts +116 -0
- package/dist/types/kit-editor/src/engine/kitDraft.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/kitEngine.d.ts +390 -0
- package/dist/types/kit-editor/src/engine/kitEngine.worker.d.ts +30 -0
- package/dist/types/kit-editor/src/engine/kitHost.d.ts +41 -0
- package/dist/types/kit-editor/src/engine/kitModel.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitModelRunner.d.ts +99 -0
- package/dist/types/kit-editor/src/engine/kitModule.d.ts +185 -0
- package/dist/types/kit-editor/src/engine/kitShortcuts.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitTools.d.ts +79 -0
- package/dist/types/kit-editor/src/engine/lazyFonts.d.ts +34 -0
- package/dist/types/kit-editor/src/engine/lentFiles.d.ts +29 -0
- package/dist/types/kit-editor/src/engine/rasterViewport.d.ts +178 -0
- package/dist/types/kit-editor/src/engine/readOnly.d.ts +78 -0
- package/dist/types/kit-editor/src/engine/refusal.d.ts +39 -0
- package/dist/types/kit-editor/src/engine/replica.d.ts +23 -0
- package/dist/types/kit-editor/src/engine/useKitDocument.d.ts +154 -0
- package/dist/types/kit-editor/src/engine/workerRelay.d.ts +62 -0
- package/dist/types/kit-editor/src/files.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/EditorFrame.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/FocusBar.d.ts +10 -0
- package/dist/types/kit-editor/src/frame/MenuNodes.d.ts +20 -0
- package/dist/types/kit-editor/src/frame/MenuRibbon.d.ts +8 -0
- package/dist/types/kit-editor/src/frame/ModeButton.d.ts +7 -0
- package/dist/types/kit-editor/src/frame/menus.d.ts +64 -0
- package/dist/types/kit-editor/src/frame/modes.d.ts +51 -0
- package/dist/types/kit-editor/src/frame/useFrameLayout.d.ts +34 -0
- package/dist/types/kit-editor/src/host.d.ts +127 -0
- package/dist/types/kit-editor/src/index.d.ts +85 -0
- package/dist/types/kit-editor/src/ink.d.ts +26 -0
- package/dist/types/kit-editor/src/lease.d.ts +53 -0
- package/dist/types/kit-editor/src/oneInFlight.d.ts +7 -0
- package/dist/types/kit-editor/src/phrases.d.ts +25 -0
- package/dist/types/kit-editor/src/presence.d.ts +79 -0
- package/dist/types/kit-editor/src/strings.d.ts +6 -0
- package/dist/types/kit-editor/src/toolIcons.d.ts +32 -0
- package/dist/types/kit-editor/src/uiCatalog.d.ts +59 -0
- package/dist/types/kit-editor/src/uiConfig.d.ts +53 -0
- package/dist/types/kit-editor/src/uiContext.d.ts +65 -0
- package/dist/types/kit-editor/src/uiStore.d.ts +20 -0
- package/dist/types/kit-editor/src/useCommentAnchors.d.ts +29 -0
- package/dist/types/kit-editor/src/useKitSession.d.ts +115 -0
- package/dist/types/kit-editor/src/workspaceTree.d.ts +5 -0
- package/dist/types/kit-engine/src/contract.d.ts +154 -0
- package/dist/types/kit-engine/src/index.d.ts +2 -0
- package/dist/types/kit-engine/src/session.d.ts +133 -0
- package/dist/types/kit-host/src/files.d.ts +163 -0
- package/dist/types/kit-host/src/index.d.ts +315 -0
- package/dist/types/kit-ui-protocol/src/index.d.ts +1145 -0
- package/dist/types/loro-crdt.d.ts +9 -0
- package/dist/types/script/kits/board.d.ts +534 -0
- package/dist/types/script/kits/cad.d.ts +2937 -0
- package/dist/types/script/kits/design.d.ts +3213 -0
- package/dist/types/script/kits/doc.d.ts +2575 -0
- package/dist/types/script/kits/film.d.ts +4067 -0
- package/dist/types/script/kits/html.d.ts +38 -0
- package/dist/types/script/kits/index.d.ts +20 -0
- package/dist/types/script/kits/layout.d.ts +3483 -0
- package/dist/types/script/kits/motion.d.ts +4826 -0
- package/dist/types/script/kits/note.d.ts +631 -0
- package/dist/types/script/kits/pdf.d.ts +829 -0
- package/dist/types/script/kits/photo.d.ts +7574 -0
- package/dist/types/script/kits/scene.d.ts +2962 -0
- package/dist/types/script/kits/sheet.d.ts +2419 -0
- package/dist/types/script/kits/slide.d.ts +1894 -0
- package/dist/types/script/kits/table.d.ts +654 -0
- package/dist/types/script/kits/vector.d.ts +5167 -0
- package/dist/types/script/src/agentRelay.d.ts +48 -0
- package/dist/types/script/src/capabilities.d.ts +21 -0
- package/dist/types/script/src/document.d.ts +87 -0
- package/dist/types/script/src/drafts.d.ts +141 -0
- package/dist/types/script/src/exchange.d.ts +30 -0
- package/dist/types/script/src/headless.d.ts +190 -0
- package/dist/types/script/src/index.d.ts +15 -0
- package/dist/types/script/src/kitModel.d.ts +17 -0
- package/dist/types/script/src/kits.d.ts +8 -0
- package/dist/types/script/src/node.d.ts +42 -0
- package/dist/types/script/src/port.d.ts +89 -0
- package/dist/types/script/src/proxy.d.ts +132 -0
- package/dist/types/script/src/room.d.ts +162 -0
- package/dist/types/script/src/sources.d.ts +73 -0
- package/dist/types/sync/src/backoff.d.ts +9 -0
- package/dist/types/sync/src/blobSection.d.ts +23 -0
- package/dist/types/sync/src/capabilities.d.ts +20 -0
- package/dist/types/sync/src/client.d.ts +253 -0
- package/dist/types/sync/src/framing.d.ts +35 -0
- package/dist/types/sync/src/hash.d.ts +2 -0
- package/dist/types/sync/src/index.d.ts +19 -0
- package/dist/types/sync/src/leases.d.ts +82 -0
- package/dist/types/sync/src/openToken.d.ts +104 -0
- package/dist/types/sync/src/protocol.d.ts +484 -0
- package/dist/types/sync/src/relay.d.ts +52 -0
- package/dist/types/sync/src/replicaVersions.d.ts +17 -0
- package/dist/types/sync/src/saveMachine.d.ts +83 -0
- package/dist/types/sync/src/saveRun.d.ts +52 -0
- package/dist/types/sync/src/transport.d.ts +19 -0
- package/package.json +229 -4
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { type KitConnection, type KitLease } from '../../kit-host/src/index.js';
|
|
2
|
+
import { type SaveTrigger, type ReplicaVersions, type TransportFactory } from '../../sync/src/index.js';
|
|
3
|
+
import { type NamedFile } from './handlers.js';
|
|
4
|
+
import type { CollabState, EmbedSaveInfo, EmbedCollaboration, EmbedEvents, EmbedKit, IdentityProvider, PermissionMode, ReplicaStore, StorageProvider } from './types.js';
|
|
5
|
+
export type CollabHost = {
|
|
6
|
+
kit: EmbedKit;
|
|
7
|
+
file: NamedFile;
|
|
8
|
+
storage: StorageProvider;
|
|
9
|
+
identity: IdentityProvider;
|
|
10
|
+
collaboration: EmbedCollaboration;
|
|
11
|
+
replicas: ReplicaStore;
|
|
12
|
+
emit: <E extends keyof EmbedEvents>(event: E, value: EmbedEvents[E]) => void;
|
|
13
|
+
/** Opens the kit again read-only (`comment`: still taking comments), carrying its unsaved changes. */
|
|
14
|
+
reopenReadOnly: (mode: Exclude<PermissionMode, 'edit'>) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Opens the kit again from the stored file and replica, carrying nothing: a viewer that opened
|
|
17
|
+
* a managed file before it had a room opens the room's document once it has one.
|
|
18
|
+
*/
|
|
19
|
+
reopen?: () => void;
|
|
20
|
+
/** The file's version moved: another session of the room saved it (D3), so this editor's saves go over it. */
|
|
21
|
+
onVersion?: (version: string) => void;
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
createTransport?: TransportFactory;
|
|
24
|
+
versions?: ReplicaVersions;
|
|
25
|
+
};
|
|
26
|
+
export declare class CollabSession {
|
|
27
|
+
private readonly host;
|
|
28
|
+
/** The page's client this session co-edits through, from `connect` on (the first step of `prepare`). */
|
|
29
|
+
private client;
|
|
30
|
+
private release;
|
|
31
|
+
private readonly records;
|
|
32
|
+
private readonly versions;
|
|
33
|
+
private stopState;
|
|
34
|
+
private user;
|
|
35
|
+
/** The agent working for the person in this editor (an open agent port), shown in presence (A20). */
|
|
36
|
+
private agent;
|
|
37
|
+
private joinedDoc;
|
|
38
|
+
/** The room `adoptRoom` joined to catch its snapshot up, until a relay takes the membership over. */
|
|
39
|
+
private adoptJoined;
|
|
40
|
+
/** The file generation (`doc_key`) of the room joined: the token may name a later one since (1.3). */
|
|
41
|
+
private joinedDocKey;
|
|
42
|
+
private move;
|
|
43
|
+
private record;
|
|
44
|
+
private relay;
|
|
45
|
+
private stopPresence;
|
|
46
|
+
/** The kit's leases on the room's scopes, while attached (Kit UI protocol capability `lease`). */
|
|
47
|
+
private leases;
|
|
48
|
+
private stopLeases;
|
|
49
|
+
/** The latest `attach`, which `shareLink` waits for. */
|
|
50
|
+
private attached;
|
|
51
|
+
/** Counts `attach` calls: a start that an `attach` or `detach` replaced stops where it is. */
|
|
52
|
+
private generation;
|
|
53
|
+
private closed;
|
|
54
|
+
/** The `openDocuments` key this session holds. */
|
|
55
|
+
private claimed;
|
|
56
|
+
/** Renews the seed claim of a managed room while the kit opens (RM5). */
|
|
57
|
+
private claimRenewal;
|
|
58
|
+
/** A managed editor found no room and no claim in time: it opens read-only (section 2.2, step 4). */
|
|
59
|
+
private unavailable;
|
|
60
|
+
/** This session's connection is its own identity provider's: its token is an open token (KitCollab 1.4). */
|
|
61
|
+
private managed;
|
|
62
|
+
/** The open token's claims, read (and with `openKeys` verified) when the session connected. */
|
|
63
|
+
private claims;
|
|
64
|
+
/** The kit this session relays, while attached, and the mode it opened in. */
|
|
65
|
+
private connection;
|
|
66
|
+
private mode;
|
|
67
|
+
/** What starts the kit's next save (D3): the person's Save unless the session asks for one itself. */
|
|
68
|
+
private trigger;
|
|
69
|
+
private autosave;
|
|
70
|
+
private stopSave;
|
|
71
|
+
private stopResolved;
|
|
72
|
+
private saveWaiters;
|
|
73
|
+
/** The room's changes this replica holds: every one up to `seenSeq`, and the ones it pushed after it. */
|
|
74
|
+
private seenSeq;
|
|
75
|
+
private pushedSeqs;
|
|
76
|
+
/** A saved version the kit is still to hear it holds (`document/held`), once the replica holds its `savedSeq`. */
|
|
77
|
+
private heldPending;
|
|
78
|
+
private heldSent;
|
|
79
|
+
state: CollabState;
|
|
80
|
+
constructor(host: CollabHost);
|
|
81
|
+
/**
|
|
82
|
+
* Takes the page's client for the server. The identity provider is always asked for the token
|
|
83
|
+
* first (managed-collab.md RM8, I8): an open token gets a connection of its own identity
|
|
84
|
+
* provider for its file, never one another editor opened; a sync token joins the one editors
|
|
85
|
+
* with sync tokens share for the server, or opens it with that token. A token that cannot be
|
|
86
|
+
* had now is asked again by the client, which keeps retrying; it never joins a shared
|
|
87
|
+
* connection, which could be another person's.
|
|
88
|
+
*/
|
|
89
|
+
private connect;
|
|
90
|
+
/** The open token's claims, verified against `collaboration.openKeys` when the page gives them (OT2). */
|
|
91
|
+
private readClaims;
|
|
92
|
+
/**
|
|
93
|
+
* In a managed room: what the kit opens with from the token, with the
|
|
94
|
+
* permissions as the sync server read them when it said (it verified the token), and the watermark.
|
|
95
|
+
*/
|
|
96
|
+
get openDocument(): {
|
|
97
|
+
permissions: {
|
|
98
|
+
download: boolean;
|
|
99
|
+
export: boolean;
|
|
100
|
+
share: boolean;
|
|
101
|
+
};
|
|
102
|
+
watermark: {
|
|
103
|
+
text: string;
|
|
104
|
+
} | null;
|
|
105
|
+
} | null;
|
|
106
|
+
/** What the room lets this person do, once known: `view` for a viewer, `comment` for a commenter. */
|
|
107
|
+
get roleMode(): PermissionMode | null;
|
|
108
|
+
/** Before the kit opens: resolves the given room, and makes its replica the one the kit opens. */
|
|
109
|
+
prepare(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Before the kit opens, for a managed room (an open token, KitCollab 1.4; managed-collab.md
|
|
112
|
+
* section 2.2): finds the room of the token's file generation, and when it has none, takes the
|
|
113
|
+
* seed claim (an editor) so exactly one session seeds it, from the file's checkpoint when the
|
|
114
|
+
* host keeps one for this version (CK2), else from the kit once it opens (`attach`). An editor
|
|
115
|
+
* that finds another seeding waits for it.
|
|
116
|
+
*/
|
|
117
|
+
private prepareManaged;
|
|
118
|
+
/** Resolves when the file generation's room appears or after a poll interval. */
|
|
119
|
+
private roomOrPoll;
|
|
120
|
+
private renewClaim;
|
|
121
|
+
private stopClaim;
|
|
122
|
+
/**
|
|
123
|
+
* Seeds the managed room from the file's checkpoint (the replica the host keeps with the file)
|
|
124
|
+
* when it is the replica of the file as it is now (CK2): the room keeps the document's id after
|
|
125
|
+
* Kition Server lost it. Answers the room's id, or `null` when there is no such checkpoint.
|
|
126
|
+
*/
|
|
127
|
+
private seedFromCheckpoint;
|
|
128
|
+
/**
|
|
129
|
+
* Makes `docId`'s room the one the kit opens: its state becomes the stored replica unless the
|
|
130
|
+
* one stored already is the room's document for the file as it is now (its stamp).
|
|
131
|
+
*/
|
|
132
|
+
private adoptRoom;
|
|
133
|
+
/**
|
|
134
|
+
* The room's state to store as the file's replica, and the `seq` it holds every change up to.
|
|
135
|
+
* `snapshot/get` answers the room's last snapshot (its creation, or a compaction's), which can
|
|
136
|
+
* be older than the file: in a managed room the file is the room's state at its last save
|
|
137
|
+
* (`savedSeq`; a generation's file changes only through the room's saves, managed-collab.md
|
|
138
|
+
* 1.3). Such a snapshot is brought up to the save: the room is joined from the snapshot's `seq`
|
|
139
|
+
* (the relay joins it again, from the `seq` this answers, once the kit has opened) and the
|
|
140
|
+
* changes up to `savedSeq` are imported into a copy of the snapshot, read with a schema of the
|
|
141
|
+
* comment types alone, which reads any of the kit's documents. A catch-up that cannot be cut at
|
|
142
|
+
* `savedSeq` (one the server answered from a compacted snapshot) is taken whole: the room's
|
|
143
|
+
* latest state, which holds the file too.
|
|
144
|
+
*/
|
|
145
|
+
private roomState;
|
|
146
|
+
/** Once the kit has opened (again): relays its replica. Failures are reported as `error` events. */
|
|
147
|
+
attach(connection: KitConnection, mode: PermissionMode): Promise<void>;
|
|
148
|
+
/** Stops relaying (the kit is about to close or reopen). */
|
|
149
|
+
detach(): void;
|
|
150
|
+
/** `host/leaseAcquire`: holds `scope` in the room; `{ lease: null }` before the room is joined or while offline. */
|
|
151
|
+
acquireLease({ scope, ttl }: {
|
|
152
|
+
scope: string;
|
|
153
|
+
ttl?: number;
|
|
154
|
+
}): Promise<{
|
|
155
|
+
lease: KitLease | null;
|
|
156
|
+
}>;
|
|
157
|
+
releaseLease({ scope }: {
|
|
158
|
+
scope: string;
|
|
159
|
+
}): Promise<void>;
|
|
160
|
+
listLeases(): KitLease[];
|
|
161
|
+
/**
|
|
162
|
+
* Once the kit has opened: holds the document its replica names for this session, refusing it
|
|
163
|
+
* (`EmbedError` `document-open`) when another editor on the page co-edits it. A kit without a
|
|
164
|
+
* replica id is left for `attach` to report.
|
|
165
|
+
*/
|
|
166
|
+
claimOpened(connection: KitConnection): Promise<void>;
|
|
167
|
+
private claim;
|
|
168
|
+
private unclaim;
|
|
169
|
+
close(): void;
|
|
170
|
+
/** A link to the room granting `role`: the room's own link for its owner, a new one otherwise. */
|
|
171
|
+
shareLink(role?: 'editor' | 'viewer'): Promise<string>;
|
|
172
|
+
private start;
|
|
173
|
+
/** Records `role` as this person's role in `docId`'s room. */
|
|
174
|
+
private takeRole;
|
|
175
|
+
/** Opens the kit again read-only when `role` allows less than the kit was opened with (`mode`). */
|
|
176
|
+
private reopenFor;
|
|
177
|
+
/**
|
|
178
|
+
* A managed viewer whose file had no room: when an editor makes it, the room's document becomes
|
|
179
|
+
* the stored replica and the kit opens it again, live.
|
|
180
|
+
*/
|
|
181
|
+
private waitForRoom;
|
|
182
|
+
/**
|
|
183
|
+
* In a managed room: follows its save state (D3), moves this editor's file version along with
|
|
184
|
+
* every session's saves, autosaves an editor's unsaved changes (SV2), and saves first when the
|
|
185
|
+
* room waits for one (`must-save`, SV4).
|
|
186
|
+
*/
|
|
187
|
+
private followSaves;
|
|
188
|
+
/** Whether this replica holds every change of the room up to `seq`. */
|
|
189
|
+
private holds;
|
|
190
|
+
/**
|
|
191
|
+
* Tells the kit a saved version holds nothing it lacks (`document/held`), once its replica holds
|
|
192
|
+
* the room's changes up to the save's `seq`: a co-editor's save is no file "changed on disk".
|
|
193
|
+
*/
|
|
194
|
+
private offerHeld;
|
|
195
|
+
private saveChanged;
|
|
196
|
+
/**
|
|
197
|
+
* Has the kit save, as started by `trigger` (its own Save is the person's). Failures are
|
|
198
|
+
* reported, never thrown. A room waiting for a save (`must-save`) whose kit has not caught up
|
|
199
|
+
* with the room's changes yet (nothing to save) is asked again a few times.
|
|
200
|
+
*/
|
|
201
|
+
saveNow(trigger: SaveTrigger, attempt?: number): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* The save coordinator the editor's handlers run every save of a managed room through
|
|
204
|
+
* (managed-collab.md section 3); `null` before the room is joined or outside a managed room.
|
|
205
|
+
*/
|
|
206
|
+
/** Whether this session co-edits a managed room (an open token's, KitCollab 1.4). */
|
|
207
|
+
isManaged(): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Whether the file moved to a later co-editing generation since this session joined its room
|
|
210
|
+
* (managed-collab.md 1.3): the host changed the file outside the room, and the token now names
|
|
211
|
+
* the next `doc_key`. The room joined can save no more.
|
|
212
|
+
*/
|
|
213
|
+
generationMoved(): boolean;
|
|
214
|
+
/** Whether the token's file generation has a room already (someone opened the new version live). */
|
|
215
|
+
nextGenerationHasRoom(): Promise<boolean>;
|
|
216
|
+
/**
|
|
217
|
+
* After the person's copy became the file's content (SV5): waits for the host to start the
|
|
218
|
+
* generation that write makes (its token names a new `doc_key`), then prepares that generation's
|
|
219
|
+
* room and opens the kit on it, live.
|
|
220
|
+
*/
|
|
221
|
+
moveToNextGeneration(before: string | null): Promise<void>;
|
|
222
|
+
/** The move to the next generation under way (SV5): saves wait for it, then go through the new room. */
|
|
223
|
+
moving(): Promise<void> | null;
|
|
224
|
+
private runMove;
|
|
225
|
+
/** The `doc_key` the token names now. */
|
|
226
|
+
currentDocKey(): string | null;
|
|
227
|
+
coordinator(): ((write: (save: EmbedSaveInfo) => Promise<string>) => Promise<string>) | null;
|
|
228
|
+
/** Waits until the client is online again, then a moment for its rooms to be joined again. */
|
|
229
|
+
private rejoined;
|
|
230
|
+
private saveEnded;
|
|
231
|
+
/** CK1: after a saved version, the room's state becomes the file's checkpoint for it. */
|
|
232
|
+
private checkpoint;
|
|
233
|
+
/** Makes the document's room from its whole history, its blobs uploaded first. */
|
|
234
|
+
private createRoom;
|
|
235
|
+
/** Stores `exported` as the file's replica unless the one stored is already this document's, for the file as it is. */
|
|
236
|
+
private keepReplica;
|
|
237
|
+
/**
|
|
238
|
+
* The server `seq` to join from: the one an earlier session saw, if the replica still holds the
|
|
239
|
+
* version it had then; otherwise from the room's snapshot.
|
|
240
|
+
*/
|
|
241
|
+
private resumeSeq;
|
|
242
|
+
/** An agent started (a name) or stopped (`null`) working for the person here (`KitAgent 1.4` A20). */
|
|
243
|
+
setAgent(agent: {
|
|
244
|
+
name: string;
|
|
245
|
+
} | null): void;
|
|
246
|
+
private sendPresence;
|
|
247
|
+
private setState;
|
|
248
|
+
}
|
|
249
|
+
/** Starts an editor's collaboration session, up to the point the kit may open. */
|
|
250
|
+
export declare function openCollabSession(host: CollabHost): Promise<CollabSession>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The document's comment threads for the page (`comments` events, `KitEmbed 1.1`), read from the
|
|
3
|
+
* kit's replica. Comment threads are objects of the reserved types `CommentThread` and `Comment`
|
|
4
|
+
* (KitModel rule M23), the same in every kit, so a copy of the replica read with a schema of
|
|
5
|
+
* only those two types finds them without knowing the kit, as a sync server checks a commenter's
|
|
6
|
+
* push. The copy follows the replica's changes (`replica/export` since its version); it loads the
|
|
7
|
+
* CRDT engine, so it is made only while someone listens.
|
|
8
|
+
*/
|
|
9
|
+
import { type CommentThread, type Schema } from '../../kdm/src/index.js';
|
|
10
|
+
/** The replica as the copy reads it: the kit's `replica/export`. */
|
|
11
|
+
export type CommentSource = {
|
|
12
|
+
exportChanges: (since: ArrayBuffer) => Promise<{
|
|
13
|
+
changes: ArrayBuffer;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A schema of the comment types alone, for `kit`'s documents of any schema version: it loads any
|
|
18
|
+
* of the kit's documents and takes their changes without knowing the kit's own types.
|
|
19
|
+
*/
|
|
20
|
+
export declare function commentSchema(kit: string): Schema;
|
|
21
|
+
/** Follows one kit's replica and answers its comment threads. */
|
|
22
|
+
export declare class CommentReader {
|
|
23
|
+
private readonly schema;
|
|
24
|
+
private copy;
|
|
25
|
+
constructor(kit: string);
|
|
26
|
+
/** The threads as the replica holds them now. */
|
|
27
|
+
threads(source: CommentSource): Promise<CommentThread[]>;
|
|
28
|
+
/** Forgets the copy, for a kit opened again. */
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** An editor refused or failed for a reason the page can act on; `code` names it. */
|
|
2
|
+
export declare class EmbedError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* `document-open`: another editor on this page already co-edits the document; `conflict`: see
|
|
5
|
+
* `EmbedConflictError`; `unsupported`: the kit does not offer it (drafts); `read-only`: the
|
|
6
|
+
* person may not do it (also: share a room that grants access by sync token only); `no-draft`:
|
|
7
|
+
* there is no draft to merge or discard.
|
|
8
|
+
*/
|
|
9
|
+
readonly code: 'document-open' | 'conflict' | 'unsupported' | 'read-only' | 'no-draft';
|
|
10
|
+
constructor(
|
|
11
|
+
/**
|
|
12
|
+
* `document-open`: another editor on this page already co-edits the document; `conflict`: see
|
|
13
|
+
* `EmbedConflictError`; `unsupported`: the kit does not offer it (drafts); `read-only`: the
|
|
14
|
+
* person may not do it (also: share a room that grants access by sync token only); `no-draft`:
|
|
15
|
+
* there is no draft to merge or discard.
|
|
16
|
+
*/
|
|
17
|
+
code: 'document-open' | 'conflict' | 'unsupported' | 'read-only' | 'no-draft', message: string);
|
|
18
|
+
}
|
|
19
|
+
/** A write refused because the file changed since the editor read it (its version moved on). */
|
|
20
|
+
export declare class EmbedConflictError extends EmbedError {
|
|
21
|
+
readonly fileId: string;
|
|
22
|
+
readonly currentVersion: string | null;
|
|
23
|
+
constructor(fileId: string, currentVersion?: string | null);
|
|
24
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Kit UI protocol's host calls (`host/*`) answered with the integrator's providers. The kit
|
|
3
|
+
* sees one file, its document, under the file's name: it reads, stamps, and saves only that
|
|
4
|
+
* (UI-H2); what it writes under another name (an export, a new file) becomes a new file through
|
|
5
|
+
* `storage.create`; and it keeps its replica (capability `replica`) only when the editor serves one.
|
|
6
|
+
*/
|
|
7
|
+
import { type KitHostHandlers } from '../../kit-host/src/index.js';
|
|
8
|
+
import { EmbedConflictError } from './errors.js';
|
|
9
|
+
import type { DocumentChange, EmbedNotice, EmbedSaveInfo, ReplicaStore, StorageProvider } from './types.js';
|
|
10
|
+
/** The document once named: by the page, or by the storage's `info`. */
|
|
11
|
+
export type NamedFile = {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
export type DocumentFiles = {
|
|
16
|
+
file: NamedFile;
|
|
17
|
+
storage: StorageProvider;
|
|
18
|
+
/** Where the document's replica is kept; `null`: the editor serves no `replica` capability. */
|
|
19
|
+
replicas: ReplicaStore | null;
|
|
20
|
+
readOnly: boolean;
|
|
21
|
+
/** The file's version as the editor last read or wrote it, shared by every mount of the editor. */
|
|
22
|
+
version: DocumentVersion;
|
|
23
|
+
onSaved: (version: string) => void;
|
|
24
|
+
onChanged: (change: DocumentChange) => void;
|
|
25
|
+
onNotify?: (notice: EmbedNotice) => void;
|
|
26
|
+
/** A save was refused: the file changed elsewhere since it was read. */
|
|
27
|
+
onConflict?: (error: EmbedConflictError) => void;
|
|
28
|
+
/**
|
|
29
|
+
* In a managed room (KitCollab 1.4): runs each save through the room's save state machine
|
|
30
|
+
* (managed-collab.md section 3), calling `write` with what the version holds; answers the version
|
|
31
|
+
* the document is at afterwards (the one written, or the one another session wrote). Read when a
|
|
32
|
+
* save starts, so a session that starts later still coordinates the kit's saves.
|
|
33
|
+
*/
|
|
34
|
+
coordinate?: () => ((write: (save: EmbedSaveInfo) => Promise<string>) => Promise<string>) | null;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the editor co-edits a managed room (KitCollab 1.4). Until the room is joined a save
|
|
37
|
+
* writes nothing and answers the current version: the room's own save writes the changes (SV1).
|
|
38
|
+
*/
|
|
39
|
+
managedRoom?: () => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* In a managed room: the file moved to a later co-editing generation since the room was joined
|
|
42
|
+
* (managed-collab.md 1.3), and what to do about a save then (SV5): `occupied` tells whether the
|
|
43
|
+
* new generation has a room already; `moved` runs after the person's copy became the file's
|
|
44
|
+
* content, with the `doc_key` from before that write.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* The editor moving to the file's next generation after a kept copy (SV5): a save the kit sends
|
|
48
|
+
* meanwhile is from the kit being replaced, so it is refused once the move is over.
|
|
49
|
+
*/
|
|
50
|
+
moving?: () => Promise<void> | null;
|
|
51
|
+
nextGeneration?: () => {
|
|
52
|
+
occupied: () => Promise<boolean>;
|
|
53
|
+
moved: (before: string | null) => void;
|
|
54
|
+
docKey: () => string | null;
|
|
55
|
+
} | null;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the person just made a gesture in the kit (OP1, OP6). Default: the page's transient
|
|
58
|
+
* user activation, which a click in the kit's frame gives its parent too; true where the browser
|
|
59
|
+
* does not tell.
|
|
60
|
+
*/
|
|
61
|
+
gesture?: () => boolean;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The document's version as the editor knows it, shared by every mount of the editor. Saves go to
|
|
65
|
+
* the storage one after another (`saving`), each over the version the one before it wrote, and
|
|
66
|
+
* the bytes the last one wrote are kept (`written`), so the same bytes again are not written again.
|
|
67
|
+
*/
|
|
68
|
+
export type DocumentVersion = {
|
|
69
|
+
current: string | null;
|
|
70
|
+
/** The save in progress; the next one waits for it. */
|
|
71
|
+
saving?: Promise<unknown>;
|
|
72
|
+
/** What the last save wrote, and the version the storage answered for it. */
|
|
73
|
+
written?: {
|
|
74
|
+
version: string;
|
|
75
|
+
bytes: Uint8Array;
|
|
76
|
+
} | null;
|
|
77
|
+
/** The bytes the file is known to hold: what the editor read, or the last save wrote. */
|
|
78
|
+
known?: Uint8Array | null;
|
|
79
|
+
/**
|
|
80
|
+
* The version a kept copy was written as (SV5): the kit's replica stored after it would be the
|
|
81
|
+
* earlier generation's document under the new version's stamp, so it is not kept.
|
|
82
|
+
*/
|
|
83
|
+
carriedOver?: string | null;
|
|
84
|
+
/** A save made before a managed room was joined, written through the room once it is (SV1). */
|
|
85
|
+
pending?: Promise<unknown> | null;
|
|
86
|
+
};
|
|
87
|
+
/** A kit's path as the editor compares it: `/`-separated, without empty or `.` segments. */
|
|
88
|
+
export declare function normalizePath(path: string): string;
|
|
89
|
+
export declare function toArrayBuffer(bytes: ArrayBuffer | Uint8Array): ArrayBuffer;
|
|
90
|
+
/** The file's version without its bytes: `storage.stamp`, else the version `storage.info` tells. */
|
|
91
|
+
export declare function stampOf(storage: StorageProvider, fileId: string): Promise<string | null>;
|
|
92
|
+
export declare function createHandlers(files: DocumentFiles): KitHostHandlers;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EmbedEditor, EmbedOptions } from './types.js';
|
|
2
|
+
export { relayAgentPort } from './agent.js';
|
|
3
|
+
export { EmbedConflictError, EmbedError } from './errors.js';
|
|
4
|
+
export { EMBED_CAPABILITY_SETS, FRAME_ALLOW, FRAME_SANDBOX } from './mount.js';
|
|
5
|
+
export { ROOMS_KEY } from './rooms.js';
|
|
6
|
+
export { EMBED_VERSION } from './version.js';
|
|
7
|
+
export type * from './types.js';
|
|
8
|
+
export declare const KitionEmbed: {
|
|
9
|
+
/**
|
|
10
|
+
* Mounts the kit's editor for `options.file` in `element` (which it fills); `ready()` tells when
|
|
11
|
+
* it shows the document.
|
|
12
|
+
*
|
|
13
|
+
* Co-editing editors with sync tokens on one page share one connection per sync server, which
|
|
14
|
+
* the first of them opens with its `identity`; an editor with an open token (KitCollab 1.4) has
|
|
15
|
+
* its own. Every editor asks its identity for a token before it connects. One document
|
|
16
|
+
* (one room) co-edits in one editor per page: another editor of the same document fails
|
|
17
|
+
* `ready()` with an `EmbedError` whose `code` is `document-open`.
|
|
18
|
+
*/
|
|
19
|
+
mount: (element: HTMLElement, options: EmbedOptions) => Promise<EmbedEditor>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `KitionEmbed.mount`: a kit's editor in a cross-origin iframe inside the integrator's element,
|
|
3
|
+
* over the Kit UI protocol (`mountKit`), with the integrator's storage behind the kit's file calls
|
|
4
|
+
* (`handlers.ts`) and, when asked, a collaboration session (`collab.ts`).
|
|
5
|
+
*
|
|
6
|
+
* The frame comes from the kit package's own origin (`kit.url`), and the protocol's handshake is
|
|
7
|
+
* bound to exactly that origin. Tokens, the sync connection, and the storage stay in this page;
|
|
8
|
+
* the kit sees only its document's bytes and replica changes (E5).
|
|
9
|
+
*/
|
|
10
|
+
import { type KitConnection, type KitDocumentInit, type MountOptions } from '../../kit-host/src/index.js';
|
|
11
|
+
import type { ReplicaVersions, TransportFactory } from '../../sync/src/index.js';
|
|
12
|
+
import type { EmbedEditor, EmbedOptions, ReplicaStore } from './types.js';
|
|
13
|
+
/** The capability sets this embed serves (Kition platform `docs/platform/index.md` section 3). */
|
|
14
|
+
export declare const EMBED_CAPABILITY_SETS: readonly ["KitModel 1.1", "KitObjectModel 1.0", "KitEmbed 1.3"];
|
|
15
|
+
/** The kit frame's sandbox: its own origin (workers, storage), its forms (a comment composer), downloads, and popups, nothing more. */
|
|
16
|
+
export declare const FRAME_SANDBOX = "allow-scripts allow-same-origin allow-forms allow-downloads allow-popups";
|
|
17
|
+
export declare const FRAME_ALLOW = "clipboard-read; clipboard-write; fullscreen";
|
|
18
|
+
/** What `mount` uses, replaceable in tests. */
|
|
19
|
+
export type EmbedDependencies = {
|
|
20
|
+
mountKit: (frame: HTMLIFrameElement, options: MountOptions) => Promise<KitConnection>;
|
|
21
|
+
/** The replica store of a collaboration session whose storage has none. */
|
|
22
|
+
replicaStore: () => ReplicaStore;
|
|
23
|
+
createTransport?: TransportFactory;
|
|
24
|
+
versions?: ReplicaVersions;
|
|
25
|
+
/**
|
|
26
|
+
* Reads the KDM schema a kit package ships (`model/schema.json` at the URL given); without it, a
|
|
27
|
+
* draft's review and the agent's object-model calls use the page's or the bundled kit's schema.
|
|
28
|
+
*/
|
|
29
|
+
packageSchema?: (url: string) => Promise<object | undefined>;
|
|
30
|
+
};
|
|
31
|
+
/** The kit package's origin, its base URL (with its trailing `/`), and the UI entry in it. */
|
|
32
|
+
export declare function kitLocation(kit: EmbedOptions['kit'], base?: string): {
|
|
33
|
+
origin: string;
|
|
34
|
+
base: string;
|
|
35
|
+
entry: string;
|
|
36
|
+
};
|
|
37
|
+
/** `storage.lend`'s answer as the Kit UI protocol's `document.lend`: an http(s) URL ending in `/`, the document's folder at its root. */
|
|
38
|
+
export declare function lendLocation(url: string | URL | null | undefined, base?: string): KitDocumentInit['lend'] | undefined;
|
|
39
|
+
export declare function mountEmbed(element: HTMLElement, options: EmbedOptions, dependencies?: EmbedDependencies): Promise<EmbedEditor>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an editor remembers of each room it co-edits, keyed by the room's document id in the
|
|
3
|
+
* integrator's `storage.state` (by default one `localStorage` entry, `kition.embed.rooms.v1`):
|
|
4
|
+
* the file it belongs to, this person's role, a share link, and how far the room and the replica
|
|
5
|
+
* have caught up with each other (`lastSent`, `seen`), so a later session sends and pulls only
|
|
6
|
+
* what is new.
|
|
7
|
+
*/
|
|
8
|
+
import type { Role } from '../../sync/src/index.js';
|
|
9
|
+
import type { EmbedState } from './types.js';
|
|
10
|
+
export declare const ROOMS_KEY = "kition.embed.rooms.v1";
|
|
11
|
+
export type RoomRecord = {
|
|
12
|
+
docId: string;
|
|
13
|
+
fileId: string;
|
|
14
|
+
kit: string;
|
|
15
|
+
role: Role;
|
|
16
|
+
/** The link this editor made or opened the room with, if any. */
|
|
17
|
+
shareLink?: string;
|
|
18
|
+
/** The replica version the room is known to hold from this side (lowercase hex). */
|
|
19
|
+
lastSent?: string;
|
|
20
|
+
/** The last server `seq` this side had every change up to, and its replica version then (hex). */
|
|
21
|
+
seen?: {
|
|
22
|
+
seq: number;
|
|
23
|
+
version: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** `storage.state`'s default: every record in one `localStorage` entry, or memory without one. */
|
|
27
|
+
export declare function localState(storage?: Storage | null): EmbedState;
|
|
28
|
+
/** The records in `state`; changes are made one at a time, so none is lost to another. */
|
|
29
|
+
export declare class RoomRecords {
|
|
30
|
+
private readonly state;
|
|
31
|
+
private queue;
|
|
32
|
+
constructor(state: EmbedState);
|
|
33
|
+
read(docId: string): Promise<RoomRecord | null>;
|
|
34
|
+
write(record: RoomRecord): Promise<void>;
|
|
35
|
+
/** Changes the record of `docId`, if there is one. */
|
|
36
|
+
update(docId: string, patch: Partial<Omit<RoomRecord, 'docId'>>): Promise<void>;
|
|
37
|
+
private run;
|
|
38
|
+
}
|
|
39
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
40
|
+
export declare function fromHex(hex: string | undefined): Uint8Array<ArrayBuffer>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The schema a kit package ships at `url`, or `undefined` when it ships none or it cannot be read. */
|
|
2
|
+
export declare function fetchPackageSchema(url: string): Promise<object | undefined>;
|
|
3
|
+
/**
|
|
4
|
+
* The schema for `kitId`: the page's, else the kit package's (`fromPackage`, when it names this
|
|
5
|
+
* kit), else the generated kit's, else `undefined` (the kit describes its own).
|
|
6
|
+
*/
|
|
7
|
+
export declare function kitSchemaLoader(kitId: string, given?: object, fromPackage?: () => Promise<object | undefined>): () => Promise<object | undefined>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's connections to sync servers, connected while an editor uses them; the token is asked
|
|
3
|
+
* for on every connection, so it can be refreshed.
|
|
4
|
+
*
|
|
5
|
+
* - Editors with sync tokens share one `SyncClient` per server URL; the first editor's identity
|
|
6
|
+
* answers its token.
|
|
7
|
+
* - An editor with an open token (KitCollab 1.4) has a client of its identity provider's
|
|
8
|
+
* (`owner`): a host opens each file with its own provider, whose token names that file, so
|
|
9
|
+
* each file has its own connection, reconnecting with its own token and role, and closing one
|
|
10
|
+
* never hands its callback to another (managed-collab.md RM8, MC-02 to MC-04).
|
|
11
|
+
*/
|
|
12
|
+
import { SyncClient, type TransportFactory } from '../../sync/src/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* The page's client for `server` (or, with `owner`, that identity provider's own client for it and
|
|
15
|
+
* the open token's `file`),
|
|
16
|
+
* connecting it on first use with `token`; `release` when done with it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function acquireSyncClient(server: string, token: () => string | Promise<string>, createTransport?: TransportFactory, owner?: object, file?: string): {
|
|
19
|
+
client: SyncClient;
|
|
20
|
+
release: () => void;
|
|
21
|
+
};
|
|
22
|
+
/** The client editors with sync tokens share for `server`, acquired, when one is open; else `null`. */
|
|
23
|
+
export declare function sharedSyncClient(server: string): {
|
|
24
|
+
client: SyncClient;
|
|
25
|
+
release: () => void;
|
|
26
|
+
} | null;
|
|
27
|
+
/** Resolves once `client` is online; rejects when `signal` aborts first. */
|
|
28
|
+
export declare function whenOnline(client: SyncClient, signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Kit UI protocol's theme (protocol section 4) from an integrator's `EmbedTheme`: the tokens
|
|
3
|
+
* it sets over the defaults for its color scheme, so a kit always has every token it styles with.
|
|
4
|
+
*/
|
|
5
|
+
import type { KitTheme } from '../../kit-ui-protocol/src/index.js';
|
|
6
|
+
import type { EmbedTheme } from './types.js';
|
|
7
|
+
export declare function kitTheme(theme: EmbedTheme | undefined): KitTheme;
|