zidane-ui 9.5.3 → 9.6.1
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/dist/adapters/index.d.ts +2 -1
- package/dist/adapters/index.js +2 -1
- package/dist/adapters/server-git-host.js +67 -0
- package/dist/adapters/server-host.js +9 -0
- package/dist/adapters/server-oauth-flow.d.ts +2 -2
- package/dist/adapters/server-oauth-flow.js +1 -1
- package/dist/adapters/server-projects.d.ts +53 -2
- package/dist/adapters/server-projects.js +4 -3
- package/dist/adapters/server-session-host.js +112 -4
- package/dist/channels/BindingEditorDialog.js +1 -1
- package/dist/channels/ChannelDefaultsSection.js +1 -1
- package/dist/channels/ChannelsSettingsSection.js +1 -1
- package/dist/channels/ConnectionSetupDialog.js +1 -1
- package/dist/channels/HeldRepliesList.js +1 -1
- package/dist/channels/ProjectChannelsSection.js +1 -1
- package/dist/chat/HostTranscript.js +1 -0
- package/dist/chat/SessionGroupHeader.js +2 -2
- package/dist/chat/composer/ComposerBadges.d.ts +27 -1
- package/dist/chat/composer/ComposerBadges.js +41 -5
- package/dist/chat/composer/ConversationBadges.d.ts +6 -0
- package/dist/chat/composer/ConversationBadges.js +70 -3
- package/dist/chat/composer/DraftPickers.js +4 -0
- package/dist/chat/composer/ServerScopeToggle.d.ts +16 -1
- package/dist/chat/composer/ServerScopeToggle.js +90 -47
- package/dist/chat/composer/index.d.ts +2 -2
- package/dist/chat/composer/use-draft-target.d.ts +18 -2
- package/dist/chat/composer/use-draft-target.js +74 -7
- package/dist/chat/composer/use-new-session-defaults.d.ts +3 -1
- package/dist/chat/composer/use-new-session-defaults.js +19 -14
- package/dist/chat/composer/use-send-prompt.js +2 -2
- package/dist/chat/headless/composer/index.d.ts +2 -2
- package/dist/chat/headless/composer/index.js +2 -2
- package/dist/chat/headless/composer/labels-chrome.d.ts +7 -0
- package/dist/chat/headless/composer/labels-chrome.js +7 -0
- package/dist/chat/headless/composer/labels-editor.d.ts +4 -0
- package/dist/chat/headless/composer/labels-editor.js +4 -0
- package/dist/chat/headless/composer/models.d.ts +2 -0
- package/dist/chat/headless/composer/new-session-defaults.d.ts +12 -1
- package/dist/chat/headless/composer/new-session-defaults.js +30 -1
- package/dist/chat/headless/draft-target.d.ts +27 -6
- package/dist/chat/headless/draft-target.js +36 -3
- package/dist/chat/headless/host.d.ts +7 -0
- package/dist/chat/headless/index.d.ts +4 -4
- package/dist/chat/headless/index.js +26 -26
- package/dist/chat/headless/labels.d.ts +4 -0
- package/dist/chat/headless/send-flow.d.ts +2 -0
- package/dist/chat/headless/send-flow.js +2 -1
- package/dist/chat/headless/session-list.d.ts +4 -0
- package/dist/chat/headless/sidebar/index.d.ts +2 -2
- package/dist/chat/headless/sidebar/labels.d.ts +9 -1
- package/dist/chat/headless/sidebar/labels.js +4 -0
- package/dist/chat/headless/sidebar/rows.d.ts +48 -7
- package/dist/chat/headless/sidebar/rows.js +121 -22
- package/dist/chat/headless/sidebar/types.d.ts +5 -0
- package/dist/chat/headless/transcript/fold-actions.d.ts +8 -3
- package/dist/chat/headless/transcript/fold-actions.js +29 -1
- package/dist/chat/index.d.ts +2 -2
- package/dist/chat/index.js +2 -2
- package/dist/chat/rich-composer/RichComposer.js +58 -11
- package/dist/chat/rich-composer/composer-controls.d.ts +5 -1
- package/dist/chat/rich-composer/composer-controls.js +4 -4
- package/dist/chat/rich-composer/composer-keys.js +2 -2
- package/dist/chat/rich-composer/draft-collab.d.ts +91 -0
- package/dist/chat/rich-composer/draft-collab.js +310 -0
- package/dist/chat/rich-composer/use-composer-editor.d.ts +2 -0
- package/dist/chat/rich-composer/use-draft-collab.d.ts +53 -0
- package/dist/chat/rich-composer/use-draft-collab.js +92 -0
- package/dist/chat/rich-composer/use-draft-mirror.d.ts +11 -0
- package/dist/chat/rich-composer/use-draft-mirror.js +38 -9
- package/dist/chat/sidebar/InboxList.js +1 -1
- package/dist/chat/sidebar/ProjectIcon.d.ts +6 -2
- package/dist/chat/sidebar/ProjectIcon.js +7 -3
- package/dist/chat/sidebar/SessionSidebar.d.ts +30 -1
- package/dist/chat/sidebar/SessionSidebar.js +79 -7
- package/dist/chat/sidebar/SidebarGroupHeader.d.ts +12 -4
- package/dist/chat/sidebar/SidebarGroupHeader.js +70 -28
- package/dist/chat/sidebar/index.d.ts +2 -2
- package/dist/chat/transcript/actions.d.ts +6 -0
- package/dist/chat/transcript/fold.d.ts +2 -1
- package/dist/chat/transcript/fold.js +26 -1
- package/dist/chat/transcript/index.js +3 -3
- package/dist/chat/transcript/notices.d.ts +5 -2
- package/dist/chat/transcript/notices.js +23 -3
- package/dist/chat/transcript/script-input.d.ts +1 -1
- package/dist/components/Avatar.d.ts +36 -0
- package/dist/components/Avatar.js +56 -0
- package/dist/components/AvatarStack.d.ts +58 -0
- package/dist/components/AvatarStack.js +187 -0
- package/dist/components/Tabs.d.ts +6 -1
- package/dist/components/Tabs.js +43 -39
- package/dist/core.css +19 -1
- package/dist/dist/{index-BsoTsm0E.d.ts → index-ChabiHpR.d.ts} +1 -1
- package/dist/dist/index.d.ts +1 -1
- package/dist/git/headless/environment.d.ts +15 -0
- package/dist/git/headless/environment.js +18 -1
- package/dist/git/headless/github.d.ts +11 -0
- package/dist/git/headless/github.js +15 -0
- package/dist/git/headless/host.d.ts +109 -0
- package/dist/git/headless/index.d.ts +5 -4
- package/dist/git/headless/index.js +4 -3
- package/dist/git/headless/labels.d.ts +16 -1
- package/dist/git/headless/labels.js +25 -1
- package/dist/git/testing/contract.d.ts +22 -4
- package/dist/git/testing/contract.js +173 -3
- package/dist/git/testing/index.d.ts +22 -1
- package/dist/git/testing/index.js +135 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/labels.d.ts +4 -0
- package/dist/labels.js +4 -0
- package/dist/onboarding/headless/labels.d.ts +4 -0
- package/dist/session/DraftPeopleStack.d.ts +24 -0
- package/dist/session/DraftPeopleStack.js +48 -0
- package/dist/session/NewProjectDialog.d.ts +28 -8
- package/dist/session/NewProjectDialog.js +225 -40
- package/dist/session/PersonCard.d.ts +29 -0
- package/dist/session/PersonCard.js +199 -0
- package/dist/session/ProjectArtifactsSection.d.ts +4 -1
- package/dist/session/ProjectArtifactsSection.js +149 -34
- package/dist/session/ProjectHome.d.ts +1 -1
- package/dist/session/ProjectHome.js +23 -4
- package/dist/session/ProjectName.d.ts +11 -6
- package/dist/session/ProjectName.js +27 -13
- package/dist/session/ProjectPeopleStack.d.ts +26 -0
- package/dist/session/ProjectPeopleStack.js +56 -0
- package/dist/session/ProjectPublishDialog.js +9 -3
- package/dist/session/ProjectSettingsDialog.d.ts +1 -1
- package/dist/session/ProjectSettingsDialog.js +171 -66
- package/dist/session/ProjectShareDialog.d.ts +1 -1
- package/dist/session/ProjectShareDialog.js +16 -6
- package/dist/session/ProjectToolsSection.js +88 -96
- package/dist/session/ProjectUsage.d.ts +4 -1
- package/dist/session/ProjectUsage.js +13 -4
- package/dist/session/SessionDetailsDialog.d.ts +5 -1
- package/dist/session/SessionDetailsDialog.js +67 -10
- package/dist/session/SessionPeopleStack.js +19 -37
- package/dist/session/SessionProjectPicker.d.ts +54 -0
- package/dist/session/SessionProjectPicker.js +175 -0
- package/dist/session/SessionProvider.d.ts +15 -1
- package/dist/session/SessionProvider.js +28 -6
- package/dist/session/UsageSection.d.ts +2 -4
- package/dist/session/UsageSection.js +57 -55
- package/dist/session/headless/draft-collab.d.ts +55 -0
- package/dist/session/headless/draft-collab.js +127 -0
- package/dist/session/headless/draft-room.d.ts +124 -0
- package/dist/session/headless/draft-room.js +340 -0
- package/dist/session/headless/drafts.d.ts +93 -0
- package/dist/session/headless/drafts.js +79 -0
- package/dist/session/headless/fixture-drafts.d.ts +54 -0
- package/dist/session/headless/fixture-drafts.js +286 -0
- package/dist/session/headless/fixture-host.d.ts +18 -2
- package/dist/session/headless/fixture-host.js +41 -7
- package/dist/session/headless/fixture-projects.d.ts +6 -4
- package/dist/session/headless/fixture-projects.js +25 -4
- package/dist/session/headless/host.d.ts +34 -6
- package/dist/session/headless/index.d.ts +6 -3
- package/dist/session/headless/index.js +6 -3
- package/dist/session/headless/labels.d.ts +47 -2
- package/dist/session/headless/labels.js +17 -1
- package/dist/session/headless/people.d.ts +27 -3
- package/dist/session/headless/people.js +38 -20
- package/dist/session/headless/project-artifact-labels.d.ts +7 -0
- package/dist/session/headless/project-artifact-labels.js +7 -0
- package/dist/session/headless/project-artifacts.d.ts +8 -0
- package/dist/session/headless/project-artifacts.js +15 -1
- package/dist/session/headless/project-labels.d.ts +25 -0
- package/dist/session/headless/project-labels.js +25 -0
- package/dist/session/headless/shared-with.d.ts +28 -0
- package/dist/session/headless/shared-with.js +51 -0
- package/dist/session/host-context.d.ts +11 -0
- package/dist/session/host-context.js +14 -0
- package/dist/session/index.d.ts +7 -3
- package/dist/session/index.js +6 -2
- package/dist/session/new-project-parts.d.ts +67 -0
- package/dist/session/new-project-parts.js +470 -0
- package/dist/session/project-artifact-parts.d.ts +2 -1
- package/dist/session/project-artifact-parts.js +5 -2
- package/dist/session/project-people.d.ts +14 -0
- package/dist/session/project-people.js +86 -0
- package/dist/session/share-people.d.ts +12 -0
- package/dist/session/share-people.js +1 -1
- package/dist/session/testing/contract.d.ts +6 -3
- package/dist/session/testing/contract.js +24 -3
- package/dist/session/testing/drafts.contract.d.ts +30 -0
- package/dist/session/testing/drafts.contract.js +126 -0
- package/dist/session/testing/index.d.ts +2 -1
- package/dist/session/testing/index.js +2 -1
- package/dist/session/use-home-projects.d.ts +11 -2
- package/dist/session/use-home-projects.js +142 -5
- package/dist/session/useDraftCollab.d.ts +24 -0
- package/dist/session/useDraftCollab.js +78 -0
- package/dist/settings/headless/search.d.ts +1 -1
- package/dist/settings/index.js +3 -3
- package/dist/settings/sections/providers/CredentialSources.d.ts +5 -5
- package/dist/settings/sections/providers/CredentialSources.js +5 -22
- package/dist/settings/sections/providers/labels.d.ts +1 -9
- package/dist/settings/sections/providers/labels.js +1 -9
- package/dist/styles.css +20 -9
- package/package.json +4 -3
- package/src/styles/sidebar.css +2 -3
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { writable } from "../../chat/headless/store.js";
|
|
2
|
+
// src/session/headless/draft-room.ts
|
|
3
|
+
/** A push that failed waits this long before the next. */
|
|
4
|
+
const DRAFT_PUSH_RETRY_MS = 1e3;
|
|
5
|
+
const realTimers = {
|
|
6
|
+
setTimeout: (run, ms) => setTimeout(run, ms),
|
|
7
|
+
clearTimeout: (timer) => clearTimeout(timer)
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A room client over the host's calls.
|
|
11
|
+
*
|
|
12
|
+
* @param drafts - The host's draft calls.
|
|
13
|
+
* @param options - The draft, whose it is, and the timers.
|
|
14
|
+
* @param options.sessionId - The session, by its id on this host.
|
|
15
|
+
* @param options.ownerId - Whose draft.
|
|
16
|
+
* @param options.role - `owner`: this window's person's own draft (it joins only while someone else is in it).
|
|
17
|
+
* @param options.timers - The clock (a test). Default: real timers.
|
|
18
|
+
*/
|
|
19
|
+
function createDraftRoomClient(drafts, options) {
|
|
20
|
+
const { sessionId, ownerId, role } = options;
|
|
21
|
+
const timers = options.timers ?? realTimers;
|
|
22
|
+
const view = writable({
|
|
23
|
+
status: "idle",
|
|
24
|
+
people: []
|
|
25
|
+
});
|
|
26
|
+
let clientId = null;
|
|
27
|
+
let binding = null;
|
|
28
|
+
let room = null;
|
|
29
|
+
/** The version the binding has every step up to. */
|
|
30
|
+
let delivered = 0;
|
|
31
|
+
const stash = /* @__PURE__ */ new Map();
|
|
32
|
+
let inflight = false;
|
|
33
|
+
let fetching = false;
|
|
34
|
+
let wantCatchUp = false;
|
|
35
|
+
let blocked = null;
|
|
36
|
+
/** The version of a push that went out and got no answer (the connection dropped): until the steps after it come, the room may hold it. */
|
|
37
|
+
let unsureAt = null;
|
|
38
|
+
/** Bumped by each join and each close: an answer for an older one is dropped. */
|
|
39
|
+
let generation = 0;
|
|
40
|
+
let ended = false;
|
|
41
|
+
/** The owner's window heard someone join while it was letting the room go: it joins again once it has. */
|
|
42
|
+
let invitePending = false;
|
|
43
|
+
const status = () => view.get().status;
|
|
44
|
+
const setView = (patch) => view.set((prev) => ({
|
|
45
|
+
...prev,
|
|
46
|
+
...patch
|
|
47
|
+
}));
|
|
48
|
+
const ready = () => {
|
|
49
|
+
if (!inflight && !fetching && blocked === null) binding?.ready();
|
|
50
|
+
};
|
|
51
|
+
const accept = (batch) => {
|
|
52
|
+
if (status() !== "open" || !binding) return;
|
|
53
|
+
const end = batch.base + batch.steps.length;
|
|
54
|
+
if (end <= delivered) return;
|
|
55
|
+
if (batch.base > delivered) {
|
|
56
|
+
stash.set(batch.base, batch);
|
|
57
|
+
catchUp();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const from = delivered - batch.base;
|
|
61
|
+
const tail = {
|
|
62
|
+
base: delivered,
|
|
63
|
+
steps: batch.steps.slice(from),
|
|
64
|
+
clientIds: batch.clientIds.slice(from)
|
|
65
|
+
};
|
|
66
|
+
delivered = end;
|
|
67
|
+
if (unsureAt !== null && delivered > unsureAt) unsureAt = null;
|
|
68
|
+
binding.steps(tail);
|
|
69
|
+
for (const [base, held] of [...stash]) if (base + held.steps.length <= delivered) stash.delete(base);
|
|
70
|
+
const next = [...stash.entries()].find(([base]) => base <= delivered);
|
|
71
|
+
if (next) {
|
|
72
|
+
stash.delete(next[0]);
|
|
73
|
+
accept(next[1]);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/** The room's state from the start: the binding builds its document again. */
|
|
77
|
+
const install = (state) => {
|
|
78
|
+
room = state.room;
|
|
79
|
+
delivered = state.version;
|
|
80
|
+
stash.clear();
|
|
81
|
+
const unsure = unsureAt !== null && unsureAt < state.version;
|
|
82
|
+
unsureAt = null;
|
|
83
|
+
setView({
|
|
84
|
+
status: "open",
|
|
85
|
+
people: state.people
|
|
86
|
+
});
|
|
87
|
+
binding?.reset(state, { unsure });
|
|
88
|
+
};
|
|
89
|
+
/** Hands the binding's last steps to the room, then a snapshot of them. Fire and forget: a refused one is lost. */
|
|
90
|
+
const sendFinal = async (final, by, atRoom) => {
|
|
91
|
+
if (!final || atRoom === null) return;
|
|
92
|
+
let version = final.version;
|
|
93
|
+
if (final.steps.length > 0) {
|
|
94
|
+
const taken = await drafts.push(sessionId, ownerId, atRoom, final.version, final.steps, by).catch(() => null);
|
|
95
|
+
if (!taken?.ok) return;
|
|
96
|
+
version = taken.version;
|
|
97
|
+
}
|
|
98
|
+
await drafts.snapshot(sessionId, ownerId, atRoom, version, final.doc, final.text).catch(() => void 0);
|
|
99
|
+
};
|
|
100
|
+
/** Lets the binding go, sends what it kept and leaves the room as `by`. */
|
|
101
|
+
const release = async (by) => {
|
|
102
|
+
const final = binding?.end() ?? null;
|
|
103
|
+
binding = null;
|
|
104
|
+
const atRoom = room;
|
|
105
|
+
if (by === null) return;
|
|
106
|
+
await sendFinal(final, by, atRoom);
|
|
107
|
+
await drafts.leave(sessionId, ownerId, by).catch(() => void 0);
|
|
108
|
+
};
|
|
109
|
+
const join = () => {
|
|
110
|
+
if (!clientId || ended) return;
|
|
111
|
+
const asked = ++generation;
|
|
112
|
+
const by = clientId;
|
|
113
|
+
invitePending = false;
|
|
114
|
+
if (status() !== "open") setView({ status: "joining" });
|
|
115
|
+
drafts.join(sessionId, ownerId, by, role === "owner" ? { ifOpen: true } : void 0).then((state) => {
|
|
116
|
+
if (asked !== generation) {
|
|
117
|
+
if (state && ended) drafts.leave(sessionId, ownerId, by).catch(() => void 0);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!state) {
|
|
121
|
+
if (role === "owner" && status() === "open") binding?.end();
|
|
122
|
+
room = null;
|
|
123
|
+
setView(role === "owner" ? {
|
|
124
|
+
status: "idle",
|
|
125
|
+
people: []
|
|
126
|
+
} : {
|
|
127
|
+
status: "closed",
|
|
128
|
+
closed: "gone",
|
|
129
|
+
people: []
|
|
130
|
+
});
|
|
131
|
+
if (role === "owner" && invitePending) join();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (state.room === room && status() === "open") {
|
|
135
|
+
setView({ people: state.people });
|
|
136
|
+
if (state.base <= delivered) {
|
|
137
|
+
accept({
|
|
138
|
+
base: state.base,
|
|
139
|
+
steps: state.steps,
|
|
140
|
+
clientIds: state.clientIds
|
|
141
|
+
});
|
|
142
|
+
ready();
|
|
143
|
+
} else catchUp();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
install(state);
|
|
147
|
+
ready();
|
|
148
|
+
}, (error) => {
|
|
149
|
+
if (asked !== generation) return;
|
|
150
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
151
|
+
setView(role === "owner" ? {
|
|
152
|
+
status: "idle",
|
|
153
|
+
people: [],
|
|
154
|
+
error: message
|
|
155
|
+
} : {
|
|
156
|
+
status: "closed",
|
|
157
|
+
closed: "refused",
|
|
158
|
+
people: [],
|
|
159
|
+
error: message
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
/** Asks the steps after the version delivered last: after a refused push, a gap, or an error. */
|
|
164
|
+
function catchUp() {
|
|
165
|
+
if (inflight || fetching) {
|
|
166
|
+
wantCatchUp = true;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (room === null || status() !== "open") return;
|
|
170
|
+
wantCatchUp = false;
|
|
171
|
+
fetching = true;
|
|
172
|
+
const asked = generation;
|
|
173
|
+
const atRoom = room;
|
|
174
|
+
drafts.since(sessionId, ownerId, atRoom, delivered).then((since) => {
|
|
175
|
+
fetching = false;
|
|
176
|
+
if (asked !== generation) return;
|
|
177
|
+
if (!since) {
|
|
178
|
+
join();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (since.kind === "resync") install(since.state);
|
|
182
|
+
else if (since.room === atRoom) accept(since);
|
|
183
|
+
}, () => {
|
|
184
|
+
fetching = false;
|
|
185
|
+
}).finally(() => {
|
|
186
|
+
if (asked !== generation) return;
|
|
187
|
+
if (wantCatchUp) catchUp();
|
|
188
|
+
ready();
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const offSignal = drafts.onSignal((signal) => {
|
|
192
|
+
if (signal.sessionId !== sessionId || signal.ownerId !== ownerId) return;
|
|
193
|
+
if (signal.kind === "draft:room" && role === "owner" && signal.room !== room) {
|
|
194
|
+
if (!binding) return;
|
|
195
|
+
if (status() === "joining") invitePending = true;
|
|
196
|
+
else join();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (signal.room !== room) return;
|
|
200
|
+
if (signal.kind === "draft:steps") {
|
|
201
|
+
accept({
|
|
202
|
+
base: signal.version,
|
|
203
|
+
steps: signal.steps,
|
|
204
|
+
clientIds: signal.clientIds
|
|
205
|
+
});
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (signal.kind === "draft:reset") {
|
|
209
|
+
++generation;
|
|
210
|
+
binding?.end();
|
|
211
|
+
room = null;
|
|
212
|
+
stash.clear();
|
|
213
|
+
setView(role === "owner" ? {
|
|
214
|
+
status: "idle",
|
|
215
|
+
people: []
|
|
216
|
+
} : {
|
|
217
|
+
status: "closed",
|
|
218
|
+
closed: "sent",
|
|
219
|
+
people: []
|
|
220
|
+
});
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
setView({ people: signal.people });
|
|
224
|
+
const self = drafts.self(sessionId);
|
|
225
|
+
if (role === "guest" && status() === "open" && self !== void 0 && !signal.people.some((person) => person.userId === self)) {
|
|
226
|
+
join();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (role === "owner" && signal.people.every((person) => person.userId === ownerId) && clientId) {
|
|
230
|
+
const by = clientId;
|
|
231
|
+
const kept = binding;
|
|
232
|
+
++generation;
|
|
233
|
+
const final = kept?.end() ?? null;
|
|
234
|
+
const atRoom = room;
|
|
235
|
+
room = null;
|
|
236
|
+
setView({ status: "joining" });
|
|
237
|
+
sendFinal(final, by, atRoom).then(() => drafts.leave(sessionId, ownerId, by).catch(() => void 0)).then(() => {
|
|
238
|
+
if (status() !== "joining" || room !== null) return;
|
|
239
|
+
setView({
|
|
240
|
+
status: "idle",
|
|
241
|
+
people: []
|
|
242
|
+
});
|
|
243
|
+
if (invitePending) join();
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
const offReconnect = drafts.onReconnect?.(() => {
|
|
248
|
+
if (clientId && status() !== "closed") join();
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
sessionId,
|
|
252
|
+
ownerId,
|
|
253
|
+
role,
|
|
254
|
+
view,
|
|
255
|
+
attach(id, next) {
|
|
256
|
+
if (ended) return;
|
|
257
|
+
const before = clientId;
|
|
258
|
+
if (binding && before !== null && before !== id) release(before);
|
|
259
|
+
clientId = id;
|
|
260
|
+
binding = next;
|
|
261
|
+
inflight = false;
|
|
262
|
+
fetching = false;
|
|
263
|
+
join();
|
|
264
|
+
},
|
|
265
|
+
push(version, steps, author) {
|
|
266
|
+
if (status() !== "open" || room === null || !clientId || inflight || fetching || blocked !== null || version !== delivered || steps.length === 0) return false;
|
|
267
|
+
inflight = true;
|
|
268
|
+
const asked = generation;
|
|
269
|
+
const by = author ?? clientId;
|
|
270
|
+
drafts.push(sessionId, ownerId, room, version, steps, by).then((result) => {
|
|
271
|
+
inflight = false;
|
|
272
|
+
if (asked !== generation) return;
|
|
273
|
+
if (result.ok && unsureAt === version) unsureAt = null;
|
|
274
|
+
if (result.ok) accept({
|
|
275
|
+
base: version,
|
|
276
|
+
steps,
|
|
277
|
+
clientIds: steps.map(() => by)
|
|
278
|
+
});
|
|
279
|
+
else catchUp();
|
|
280
|
+
if (wantCatchUp) catchUp();
|
|
281
|
+
ready();
|
|
282
|
+
}, () => {
|
|
283
|
+
inflight = false;
|
|
284
|
+
if (asked !== generation) return;
|
|
285
|
+
unsureAt ??= version;
|
|
286
|
+
blocked = timers.setTimeout(() => {
|
|
287
|
+
blocked = null;
|
|
288
|
+
ready();
|
|
289
|
+
}, DRAFT_PUSH_RETRY_MS);
|
|
290
|
+
catchUp();
|
|
291
|
+
});
|
|
292
|
+
return true;
|
|
293
|
+
},
|
|
294
|
+
snapshot(version, doc, text) {
|
|
295
|
+
if (status() !== "open" || room === null || inflight || version > delivered) return;
|
|
296
|
+
drafts.snapshot(sessionId, ownerId, room, version, doc, text).catch(() => void 0);
|
|
297
|
+
},
|
|
298
|
+
invited() {
|
|
299
|
+
if (role === "owner" && binding && status() === "idle") join();
|
|
300
|
+
},
|
|
301
|
+
detach() {
|
|
302
|
+
if (ended || !binding) return;
|
|
303
|
+
++generation;
|
|
304
|
+
const by = clientId;
|
|
305
|
+
if (status() === "open") release(by);
|
|
306
|
+
else binding = null;
|
|
307
|
+
room = null;
|
|
308
|
+
stash.clear();
|
|
309
|
+
inflight = false;
|
|
310
|
+
fetching = false;
|
|
311
|
+
setView(role === "owner" ? {
|
|
312
|
+
status: "idle",
|
|
313
|
+
people: []
|
|
314
|
+
} : {
|
|
315
|
+
status: "closed",
|
|
316
|
+
closed: "left",
|
|
317
|
+
people: []
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
async close() {
|
|
321
|
+
if (ended) return;
|
|
322
|
+
ended = true;
|
|
323
|
+
++generation;
|
|
324
|
+
offSignal();
|
|
325
|
+
offReconnect?.();
|
|
326
|
+
if (blocked !== null) timers.clearTimeout(blocked);
|
|
327
|
+
const by = clientId;
|
|
328
|
+
const wasOpen = status() === "open";
|
|
329
|
+
setView({
|
|
330
|
+
status: "closed",
|
|
331
|
+
closed: "left",
|
|
332
|
+
people: []
|
|
333
|
+
});
|
|
334
|
+
if (wasOpen) await release(by);
|
|
335
|
+
else binding = null;
|
|
336
|
+
room = null;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
export { DRAFT_PUSH_RETRY_MS, createDraftRoomClient };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collaborative drafts in a shared session (organization mode,
|
|
3
|
+
* docs/MULTIPLAYER.md): who else is drafting in a session (the tabs over the
|
|
4
|
+
* composer), and the calls of a draft room, whose central authority is the
|
|
5
|
+
* server. The host says nothing of ProseMirror: a step is opaque JSON here.
|
|
6
|
+
*
|
|
7
|
+
* Who drafts comes from the server's `members:drafting` signals. They are not
|
|
8
|
+
* replayed, so the store asks who drafts now (`members.drafting`) when a
|
|
9
|
+
* session is first watched and after each reconnect.
|
|
10
|
+
*/
|
|
11
|
+
import { DraftPerson, DraftPushResult, DraftRoomState, DraftSince, DraftingPerson } from "zidane/ipc";
|
|
12
|
+
/** A draft room's signal, with the session id as the host keys it. */
|
|
13
|
+
export type DraftRoomSignal = {
|
|
14
|
+
kind: 'draft:steps';
|
|
15
|
+
sessionId: string;
|
|
16
|
+
ownerId: string;
|
|
17
|
+
room: string;
|
|
18
|
+
version: number;
|
|
19
|
+
steps: unknown[];
|
|
20
|
+
clientIds: string[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'draft:room';
|
|
23
|
+
sessionId: string;
|
|
24
|
+
ownerId: string;
|
|
25
|
+
room: string;
|
|
26
|
+
people: DraftPerson[];
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'draft:reset';
|
|
29
|
+
sessionId: string;
|
|
30
|
+
ownerId: string;
|
|
31
|
+
room: string;
|
|
32
|
+
};
|
|
33
|
+
/** A `members:drafting` signal, with the session id as the host keys it. */
|
|
34
|
+
export interface DraftingSignal {
|
|
35
|
+
/** The session, by its id on this host. */
|
|
36
|
+
sessionId: string;
|
|
37
|
+
/** Their user id in the organization. */
|
|
38
|
+
userId: string;
|
|
39
|
+
/** Their display name, else their email. */
|
|
40
|
+
name: string;
|
|
41
|
+
/** Their avatar's URL. */
|
|
42
|
+
avatar?: string;
|
|
43
|
+
/** When their draft stopped being empty, epoch ms. */
|
|
44
|
+
since: number;
|
|
45
|
+
/** `false`: their draft is empty again. */
|
|
46
|
+
drafting: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** Who else drafts in each session, kept current. */
|
|
49
|
+
export interface SessionDrafting {
|
|
50
|
+
/** Calls `listener` with who drafts in `sessionId` now, newest first, then on every change. Returns the unsubscribe. */
|
|
51
|
+
watch: (sessionId: string, listener: (people: readonly DraftingPerson[]) => void) => () => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Editing a person's draft together (`SessionSharingHost.drafts`). Every call names the session and whose draft
|
|
55
|
+
* (`ownerId`). Absent: no draft tabs, no draft rooms.
|
|
56
|
+
*/
|
|
57
|
+
export interface SessionDrafts {
|
|
58
|
+
/** Who else drafts in a session. */
|
|
59
|
+
drafting: SessionDrafting;
|
|
60
|
+
/** Join a draft (`ifOpen`: your own, only when someone else is in it; `null` then). */
|
|
61
|
+
join: (sessionId: string, ownerId: string, clientId: string, options?: {
|
|
62
|
+
ifOpen?: boolean;
|
|
63
|
+
}) => Promise<DraftRoomState | null>;
|
|
64
|
+
/** Steps made at `version`, as JSON. */
|
|
65
|
+
push: (sessionId: string, ownerId: string, room: string, version: number, steps: readonly unknown[], clientId: string) => Promise<DraftPushResult>;
|
|
66
|
+
/** The steps after `version` (`null`: the room is gone). */
|
|
67
|
+
since: (sessionId: string, ownerId: string, room: string, version: number) => Promise<DraftSince | null>;
|
|
68
|
+
/** The document at `version`, and its text: the owner's stored draft follows it. */
|
|
69
|
+
snapshot: (sessionId: string, ownerId: string, room: string, version: number, doc: unknown, text: string) => Promise<void>;
|
|
70
|
+
/** Leave a draft (`clientId`: that client of this window). */
|
|
71
|
+
leave: (sessionId: string, ownerId: string, clientId: string) => Promise<void>;
|
|
72
|
+
/** Calls `listener` with each signal of the rooms this window is in, and the invitations to its own. Returns the unsubscribe. */
|
|
73
|
+
onSignal: (listener: (signal: DraftRoomSignal) => void) => () => void;
|
|
74
|
+
/** Calls `listener` when the connection to the host came back: a room is joined again. Returns the unsubscribe. */
|
|
75
|
+
onReconnect?: (listener: () => void) => () => void;
|
|
76
|
+
/** The caller's user id on the server of a session (a draft of theirs is their own). `undefined`: not known yet. */
|
|
77
|
+
self: (sessionId: string) => string | undefined;
|
|
78
|
+
}
|
|
79
|
+
/** Where a {@link SessionDrafting} reads who drafts now, besides the signals. */
|
|
80
|
+
export interface SessionDraftingSources {
|
|
81
|
+
/** Who drafts in a session now (`members.drafting`). */
|
|
82
|
+
read: (sessionId: string) => Promise<readonly DraftingPerson[]>;
|
|
83
|
+
/** Calls `listener` when the connection to the host came back. Returns the unsubscribe. */
|
|
84
|
+
onReconnect?: (listener: () => void) => () => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A {@link SessionDrafting} over a host's signals. Listens only while something watches.
|
|
88
|
+
*
|
|
89
|
+
* @param onSignal - Subscribes to the host's `members:drafting` signals; returns the unsubscribe.
|
|
90
|
+
* @param sources - Where to read who drafts now: at the first watch of a session and after a reconnect.
|
|
91
|
+
*/
|
|
92
|
+
export declare function createSessionDrafting(onSignal: (listener: (signal: DraftingSignal) => void) => () => void, sources: SessionDraftingSources): SessionDrafting;
|
|
93
|
+
export type { DraftPerson, DraftPushResult, DraftRoomState, DraftSince, DraftingPerson };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/session/headless/drafts.ts
|
|
2
|
+
const NOBODY = [];
|
|
3
|
+
/**
|
|
4
|
+
* A {@link SessionDrafting} over a host's signals. Listens only while something watches.
|
|
5
|
+
*
|
|
6
|
+
* @param onSignal - Subscribes to the host's `members:drafting` signals; returns the unsubscribe.
|
|
7
|
+
* @param sources - Where to read who drafts now: at the first watch of a session and after a reconnect.
|
|
8
|
+
*/
|
|
9
|
+
function createSessionDrafting(onSignal, sources) {
|
|
10
|
+
const people = /* @__PURE__ */ new Map();
|
|
11
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
12
|
+
let stop = null;
|
|
13
|
+
const versions = /* @__PURE__ */ new Map();
|
|
14
|
+
let version = 0;
|
|
15
|
+
const bump = (sessionId) => {
|
|
16
|
+
versions.set(sessionId, ++version);
|
|
17
|
+
return version;
|
|
18
|
+
};
|
|
19
|
+
const set = (sessionId, next) => {
|
|
20
|
+
if (next.length === 0) people.delete(sessionId);
|
|
21
|
+
else people.set(sessionId, next);
|
|
22
|
+
for (const listener of listeners.get(sessionId) ?? []) listener(next);
|
|
23
|
+
};
|
|
24
|
+
const heard = (signal) => {
|
|
25
|
+
if (!listeners.has(signal.sessionId)) return;
|
|
26
|
+
bump(signal.sessionId);
|
|
27
|
+
const before = people.get(signal.sessionId) ?? NOBODY;
|
|
28
|
+
const others = before.filter((person) => person.userId !== signal.userId);
|
|
29
|
+
if (!signal.drafting) {
|
|
30
|
+
if (others.length !== before.length) set(signal.sessionId, others);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const person = {
|
|
34
|
+
userId: signal.userId,
|
|
35
|
+
name: signal.name,
|
|
36
|
+
...signal.avatar ? { avatar: signal.avatar } : {},
|
|
37
|
+
since: signal.since
|
|
38
|
+
};
|
|
39
|
+
set(signal.sessionId, [person, ...others].sort((a, b) => b.since - a.since));
|
|
40
|
+
};
|
|
41
|
+
const read = (sessionId) => {
|
|
42
|
+
const asked = bump(sessionId);
|
|
43
|
+
sources.read(sessionId).then((answer) => {
|
|
44
|
+
if (versions.get(sessionId) !== asked || !listeners.has(sessionId) || !Array.isArray(answer)) return;
|
|
45
|
+
set(sessionId, answer);
|
|
46
|
+
}, () => {});
|
|
47
|
+
};
|
|
48
|
+
return { watch(sessionId, listener) {
|
|
49
|
+
const watching = listeners.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
50
|
+
const first = watching.size === 0;
|
|
51
|
+
listeners.set(sessionId, watching);
|
|
52
|
+
watching.add(listener);
|
|
53
|
+
if (!stop) {
|
|
54
|
+
const offSignal = onSignal(heard);
|
|
55
|
+
const offReconnect = sources.onReconnect?.(() => {
|
|
56
|
+
for (const watched of listeners.keys()) read(watched);
|
|
57
|
+
});
|
|
58
|
+
stop = () => {
|
|
59
|
+
offSignal();
|
|
60
|
+
offReconnect?.();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (first) read(sessionId);
|
|
64
|
+
listener(people.get(sessionId) ?? NOBODY);
|
|
65
|
+
return () => {
|
|
66
|
+
watching.delete(listener);
|
|
67
|
+
if (watching.size === 0) {
|
|
68
|
+
listeners.delete(sessionId);
|
|
69
|
+
people.delete(sessionId);
|
|
70
|
+
versions.delete(sessionId);
|
|
71
|
+
}
|
|
72
|
+
if (listeners.size === 0 && stop) {
|
|
73
|
+
stop();
|
|
74
|
+
stop = null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
} };
|
|
78
|
+
}
|
|
79
|
+
export { createSessionDrafting };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-memory server of collaborative drafts (docs/MULTIPLAYER.md,
|
|
3
|
+
* Collaborative drafts): the draft rooms and who drafts in each session, as a
|
|
4
|
+
* zidane-server in organization mode keeps them, for the fixture host, the
|
|
5
|
+
* gallery and tests. Each window is a connection (`connect`) with its own
|
|
6
|
+
* {@link SessionDrafts}. Its central authority is zidane's own draft log
|
|
7
|
+
* (`createDraftLog`), so it takes and refuses pushes as the server does.
|
|
8
|
+
*
|
|
9
|
+
* Every answer and signal goes through `deliver` (default: a microtask): a
|
|
10
|
+
* test holds them and runs them in any order, as a busy network would.
|
|
11
|
+
*/
|
|
12
|
+
import { DraftPerson, DraftRoomSignal, DraftRoomState, SessionDrafts } from "./drafts.js";
|
|
13
|
+
import { DraftLogLimits } from "zidane/chat/pure";
|
|
14
|
+
/** What a fixture draft server starts with. */
|
|
15
|
+
export interface FixtureDraftServerOptions {
|
|
16
|
+
/** The organization's people. */
|
|
17
|
+
people: readonly DraftPerson[];
|
|
18
|
+
/** The stored drafts: session id → user id → text. */
|
|
19
|
+
drafts?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
20
|
+
/** Runs each answer and signal. Default: a microtask. */
|
|
21
|
+
deliver?: (run: () => void) => void;
|
|
22
|
+
/** What each room's log keeps (a test of clients that fall behind it). Default: the server's. */
|
|
23
|
+
limits?: DraftLogLimits;
|
|
24
|
+
}
|
|
25
|
+
/** One window's connection to the fixture server. */
|
|
26
|
+
export interface FixtureDraftConnection extends SessionDrafts {
|
|
27
|
+
/** Whose window it is. */
|
|
28
|
+
readonly userId: string;
|
|
29
|
+
/** The connection drops and comes back: its rooms let it go, then it hears the reconnect. */
|
|
30
|
+
reconnect: () => void;
|
|
31
|
+
/** The connection closes: its rooms let it go. */
|
|
32
|
+
close: () => void;
|
|
33
|
+
}
|
|
34
|
+
/** The fixture server. */
|
|
35
|
+
export interface FixtureDraftServer {
|
|
36
|
+
/** A window of `userId`: it edits drafts together from its first `drafting.watch` or join. */
|
|
37
|
+
connect: (userId: string) => FixtureDraftConnection;
|
|
38
|
+
/** A person's stored draft, as they typed it elsewhere: who drafts follows. */
|
|
39
|
+
setDraft: (sessionId: string, userId: string, text: string) => void;
|
|
40
|
+
/** A person's stored draft now. */
|
|
41
|
+
draftOf: (sessionId: string, userId: string) => string;
|
|
42
|
+
/** The room of a person's draft: its state, or `undefined`. */
|
|
43
|
+
roomOf: (sessionId: string, ownerId: string) => DraftRoomState | undefined;
|
|
44
|
+
/** The owner sends their draft: its room ends, the draft empties. */
|
|
45
|
+
send: (sessionId: string, ownerId: string) => void;
|
|
46
|
+
/** Sends a room signal to every window of `userId`, as the server would. */
|
|
47
|
+
emit: (userId: string, signal: DraftRoomSignal) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A fixture server of collaborative drafts.
|
|
51
|
+
*
|
|
52
|
+
* @param options - The people, the stored drafts, and how answers are delivered.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createFixtureDraftServer(options: FixtureDraftServerOptions): FixtureDraftServer;
|