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.
Files changed (200) hide show
  1. package/dist/adapters/index.d.ts +2 -1
  2. package/dist/adapters/index.js +2 -1
  3. package/dist/adapters/server-git-host.js +67 -0
  4. package/dist/adapters/server-host.js +9 -0
  5. package/dist/adapters/server-oauth-flow.d.ts +2 -2
  6. package/dist/adapters/server-oauth-flow.js +1 -1
  7. package/dist/adapters/server-projects.d.ts +53 -2
  8. package/dist/adapters/server-projects.js +4 -3
  9. package/dist/adapters/server-session-host.js +112 -4
  10. package/dist/channels/BindingEditorDialog.js +1 -1
  11. package/dist/channels/ChannelDefaultsSection.js +1 -1
  12. package/dist/channels/ChannelsSettingsSection.js +1 -1
  13. package/dist/channels/ConnectionSetupDialog.js +1 -1
  14. package/dist/channels/HeldRepliesList.js +1 -1
  15. package/dist/channels/ProjectChannelsSection.js +1 -1
  16. package/dist/chat/HostTranscript.js +1 -0
  17. package/dist/chat/SessionGroupHeader.js +2 -2
  18. package/dist/chat/composer/ComposerBadges.d.ts +27 -1
  19. package/dist/chat/composer/ComposerBadges.js +41 -5
  20. package/dist/chat/composer/ConversationBadges.d.ts +6 -0
  21. package/dist/chat/composer/ConversationBadges.js +70 -3
  22. package/dist/chat/composer/DraftPickers.js +4 -0
  23. package/dist/chat/composer/ServerScopeToggle.d.ts +16 -1
  24. package/dist/chat/composer/ServerScopeToggle.js +90 -47
  25. package/dist/chat/composer/index.d.ts +2 -2
  26. package/dist/chat/composer/use-draft-target.d.ts +18 -2
  27. package/dist/chat/composer/use-draft-target.js +74 -7
  28. package/dist/chat/composer/use-new-session-defaults.d.ts +3 -1
  29. package/dist/chat/composer/use-new-session-defaults.js +19 -14
  30. package/dist/chat/composer/use-send-prompt.js +2 -2
  31. package/dist/chat/headless/composer/index.d.ts +2 -2
  32. package/dist/chat/headless/composer/index.js +2 -2
  33. package/dist/chat/headless/composer/labels-chrome.d.ts +7 -0
  34. package/dist/chat/headless/composer/labels-chrome.js +7 -0
  35. package/dist/chat/headless/composer/labels-editor.d.ts +4 -0
  36. package/dist/chat/headless/composer/labels-editor.js +4 -0
  37. package/dist/chat/headless/composer/models.d.ts +2 -0
  38. package/dist/chat/headless/composer/new-session-defaults.d.ts +12 -1
  39. package/dist/chat/headless/composer/new-session-defaults.js +30 -1
  40. package/dist/chat/headless/draft-target.d.ts +27 -6
  41. package/dist/chat/headless/draft-target.js +36 -3
  42. package/dist/chat/headless/host.d.ts +7 -0
  43. package/dist/chat/headless/index.d.ts +4 -4
  44. package/dist/chat/headless/index.js +26 -26
  45. package/dist/chat/headless/labels.d.ts +4 -0
  46. package/dist/chat/headless/send-flow.d.ts +2 -0
  47. package/dist/chat/headless/send-flow.js +2 -1
  48. package/dist/chat/headless/session-list.d.ts +4 -0
  49. package/dist/chat/headless/sidebar/index.d.ts +2 -2
  50. package/dist/chat/headless/sidebar/labels.d.ts +9 -1
  51. package/dist/chat/headless/sidebar/labels.js +4 -0
  52. package/dist/chat/headless/sidebar/rows.d.ts +48 -7
  53. package/dist/chat/headless/sidebar/rows.js +121 -22
  54. package/dist/chat/headless/sidebar/types.d.ts +5 -0
  55. package/dist/chat/headless/transcript/fold-actions.d.ts +8 -3
  56. package/dist/chat/headless/transcript/fold-actions.js +29 -1
  57. package/dist/chat/index.d.ts +2 -2
  58. package/dist/chat/index.js +2 -2
  59. package/dist/chat/rich-composer/RichComposer.js +58 -11
  60. package/dist/chat/rich-composer/composer-controls.d.ts +5 -1
  61. package/dist/chat/rich-composer/composer-controls.js +4 -4
  62. package/dist/chat/rich-composer/composer-keys.js +2 -2
  63. package/dist/chat/rich-composer/draft-collab.d.ts +91 -0
  64. package/dist/chat/rich-composer/draft-collab.js +310 -0
  65. package/dist/chat/rich-composer/use-composer-editor.d.ts +2 -0
  66. package/dist/chat/rich-composer/use-draft-collab.d.ts +53 -0
  67. package/dist/chat/rich-composer/use-draft-collab.js +92 -0
  68. package/dist/chat/rich-composer/use-draft-mirror.d.ts +11 -0
  69. package/dist/chat/rich-composer/use-draft-mirror.js +38 -9
  70. package/dist/chat/sidebar/InboxList.js +1 -1
  71. package/dist/chat/sidebar/ProjectIcon.d.ts +6 -2
  72. package/dist/chat/sidebar/ProjectIcon.js +7 -3
  73. package/dist/chat/sidebar/SessionSidebar.d.ts +30 -1
  74. package/dist/chat/sidebar/SessionSidebar.js +79 -7
  75. package/dist/chat/sidebar/SidebarGroupHeader.d.ts +12 -4
  76. package/dist/chat/sidebar/SidebarGroupHeader.js +70 -28
  77. package/dist/chat/sidebar/index.d.ts +2 -2
  78. package/dist/chat/transcript/actions.d.ts +6 -0
  79. package/dist/chat/transcript/fold.d.ts +2 -1
  80. package/dist/chat/transcript/fold.js +26 -1
  81. package/dist/chat/transcript/index.js +3 -3
  82. package/dist/chat/transcript/notices.d.ts +5 -2
  83. package/dist/chat/transcript/notices.js +23 -3
  84. package/dist/chat/transcript/script-input.d.ts +1 -1
  85. package/dist/components/Avatar.d.ts +36 -0
  86. package/dist/components/Avatar.js +56 -0
  87. package/dist/components/AvatarStack.d.ts +58 -0
  88. package/dist/components/AvatarStack.js +187 -0
  89. package/dist/components/Tabs.d.ts +6 -1
  90. package/dist/components/Tabs.js +43 -39
  91. package/dist/core.css +19 -1
  92. package/dist/dist/{index-BsoTsm0E.d.ts → index-ChabiHpR.d.ts} +1 -1
  93. package/dist/dist/index.d.ts +1 -1
  94. package/dist/git/headless/environment.d.ts +15 -0
  95. package/dist/git/headless/environment.js +18 -1
  96. package/dist/git/headless/github.d.ts +11 -0
  97. package/dist/git/headless/github.js +15 -0
  98. package/dist/git/headless/host.d.ts +109 -0
  99. package/dist/git/headless/index.d.ts +5 -4
  100. package/dist/git/headless/index.js +4 -3
  101. package/dist/git/headless/labels.d.ts +16 -1
  102. package/dist/git/headless/labels.js +25 -1
  103. package/dist/git/testing/contract.d.ts +22 -4
  104. package/dist/git/testing/contract.js +173 -3
  105. package/dist/git/testing/index.d.ts +22 -1
  106. package/dist/git/testing/index.js +135 -1
  107. package/dist/index.d.ts +3 -1
  108. package/dist/index.js +3 -1
  109. package/dist/labels.d.ts +4 -0
  110. package/dist/labels.js +4 -0
  111. package/dist/onboarding/headless/labels.d.ts +4 -0
  112. package/dist/session/DraftPeopleStack.d.ts +24 -0
  113. package/dist/session/DraftPeopleStack.js +48 -0
  114. package/dist/session/NewProjectDialog.d.ts +28 -8
  115. package/dist/session/NewProjectDialog.js +225 -40
  116. package/dist/session/PersonCard.d.ts +29 -0
  117. package/dist/session/PersonCard.js +199 -0
  118. package/dist/session/ProjectArtifactsSection.d.ts +4 -1
  119. package/dist/session/ProjectArtifactsSection.js +149 -34
  120. package/dist/session/ProjectHome.d.ts +1 -1
  121. package/dist/session/ProjectHome.js +23 -4
  122. package/dist/session/ProjectName.d.ts +11 -6
  123. package/dist/session/ProjectName.js +27 -13
  124. package/dist/session/ProjectPeopleStack.d.ts +26 -0
  125. package/dist/session/ProjectPeopleStack.js +56 -0
  126. package/dist/session/ProjectPublishDialog.js +9 -3
  127. package/dist/session/ProjectSettingsDialog.d.ts +1 -1
  128. package/dist/session/ProjectSettingsDialog.js +171 -66
  129. package/dist/session/ProjectShareDialog.d.ts +1 -1
  130. package/dist/session/ProjectShareDialog.js +16 -6
  131. package/dist/session/ProjectToolsSection.js +88 -96
  132. package/dist/session/ProjectUsage.d.ts +4 -1
  133. package/dist/session/ProjectUsage.js +13 -4
  134. package/dist/session/SessionDetailsDialog.d.ts +5 -1
  135. package/dist/session/SessionDetailsDialog.js +67 -10
  136. package/dist/session/SessionPeopleStack.js +19 -37
  137. package/dist/session/SessionProjectPicker.d.ts +54 -0
  138. package/dist/session/SessionProjectPicker.js +175 -0
  139. package/dist/session/SessionProvider.d.ts +15 -1
  140. package/dist/session/SessionProvider.js +28 -6
  141. package/dist/session/UsageSection.d.ts +2 -4
  142. package/dist/session/UsageSection.js +57 -55
  143. package/dist/session/headless/draft-collab.d.ts +55 -0
  144. package/dist/session/headless/draft-collab.js +127 -0
  145. package/dist/session/headless/draft-room.d.ts +124 -0
  146. package/dist/session/headless/draft-room.js +340 -0
  147. package/dist/session/headless/drafts.d.ts +93 -0
  148. package/dist/session/headless/drafts.js +79 -0
  149. package/dist/session/headless/fixture-drafts.d.ts +54 -0
  150. package/dist/session/headless/fixture-drafts.js +286 -0
  151. package/dist/session/headless/fixture-host.d.ts +18 -2
  152. package/dist/session/headless/fixture-host.js +41 -7
  153. package/dist/session/headless/fixture-projects.d.ts +6 -4
  154. package/dist/session/headless/fixture-projects.js +25 -4
  155. package/dist/session/headless/host.d.ts +34 -6
  156. package/dist/session/headless/index.d.ts +6 -3
  157. package/dist/session/headless/index.js +6 -3
  158. package/dist/session/headless/labels.d.ts +47 -2
  159. package/dist/session/headless/labels.js +17 -1
  160. package/dist/session/headless/people.d.ts +27 -3
  161. package/dist/session/headless/people.js +38 -20
  162. package/dist/session/headless/project-artifact-labels.d.ts +7 -0
  163. package/dist/session/headless/project-artifact-labels.js +7 -0
  164. package/dist/session/headless/project-artifacts.d.ts +8 -0
  165. package/dist/session/headless/project-artifacts.js +15 -1
  166. package/dist/session/headless/project-labels.d.ts +25 -0
  167. package/dist/session/headless/project-labels.js +25 -0
  168. package/dist/session/headless/shared-with.d.ts +28 -0
  169. package/dist/session/headless/shared-with.js +51 -0
  170. package/dist/session/host-context.d.ts +11 -0
  171. package/dist/session/host-context.js +14 -0
  172. package/dist/session/index.d.ts +7 -3
  173. package/dist/session/index.js +6 -2
  174. package/dist/session/new-project-parts.d.ts +67 -0
  175. package/dist/session/new-project-parts.js +470 -0
  176. package/dist/session/project-artifact-parts.d.ts +2 -1
  177. package/dist/session/project-artifact-parts.js +5 -2
  178. package/dist/session/project-people.d.ts +14 -0
  179. package/dist/session/project-people.js +86 -0
  180. package/dist/session/share-people.d.ts +12 -0
  181. package/dist/session/share-people.js +1 -1
  182. package/dist/session/testing/contract.d.ts +6 -3
  183. package/dist/session/testing/contract.js +24 -3
  184. package/dist/session/testing/drafts.contract.d.ts +30 -0
  185. package/dist/session/testing/drafts.contract.js +126 -0
  186. package/dist/session/testing/index.d.ts +2 -1
  187. package/dist/session/testing/index.js +2 -1
  188. package/dist/session/use-home-projects.d.ts +11 -2
  189. package/dist/session/use-home-projects.js +142 -5
  190. package/dist/session/useDraftCollab.d.ts +24 -0
  191. package/dist/session/useDraftCollab.js +78 -0
  192. package/dist/settings/headless/search.d.ts +1 -1
  193. package/dist/settings/index.js +3 -3
  194. package/dist/settings/sections/providers/CredentialSources.d.ts +5 -5
  195. package/dist/settings/sections/providers/CredentialSources.js +5 -22
  196. package/dist/settings/sections/providers/labels.d.ts +1 -9
  197. package/dist/settings/sections/providers/labels.js +1 -9
  198. package/dist/styles.css +20 -9
  199. package/package.json +4 -3
  200. package/src/styles/sidebar.css +2 -3
@@ -0,0 +1,310 @@
1
+ import { Selection, TextSelection } from "@tiptap/pm/state";
2
+ import { Step, Transform } from "@tiptap/pm/transform";
3
+ import { collab, getVersion, receiveTransaction, sendableSteps } from "prosemirror-collab";
4
+ // src/chat/rich-composer/draft-collab.ts
5
+ /** Local steps wait this long, batched, before they go out. */
6
+ const DRAFT_FLUSH_MS = 30;
7
+ /** A snapshot goes out once the draft rests this long. */
8
+ const DRAFT_SNAPSHOT_IDLE_MS = 1500;
9
+ /** A snapshot goes out after this many steps, rest or not. */
10
+ const DRAFT_SNAPSHOT_STEPS = 100;
11
+ /** The meta key of a transaction the room made (its state, its steps): not the user's typing. */
12
+ const DRAFT_REMOTE_META = "zgDraftRemote";
13
+ const realTimers = {
14
+ setTimeout: (run, ms) => setTimeout(run, ms),
15
+ clearTimeout: (timer) => clearTimeout(timer)
16
+ };
17
+ /** The steps that turn `from` into `to`: one replace over the range where they differ, else the whole document. */
18
+ function diffSteps(from, to) {
19
+ const start = from.content.findDiffStart(to.content);
20
+ if (start === null) return [];
21
+ let { a: endA, b: endB } = from.content.findDiffEnd(to.content);
22
+ const overlap = start - Math.min(endA, endB);
23
+ if (overlap > 0) {
24
+ endA += overlap;
25
+ endB += overlap;
26
+ }
27
+ const tr = new Transform(from).replace(start, endA, to.slice(start, endB));
28
+ return tr.doc.eq(to) ? tr.steps : new Transform(from).replaceWith(0, from.content.size, to.content).steps;
29
+ }
30
+ const isCollab = (plugin) => plugin.key.startsWith("collab$");
31
+ const isHistory = (plugin) => plugin.key.startsWith("history$");
32
+ /**
33
+ * The composer's Tiptap editor as a {@link CollabEditor}.
34
+ *
35
+ * @param editor - The editor.
36
+ */
37
+ function tiptapCollabEditor(editor) {
38
+ return {
39
+ state: () => editor.state,
40
+ dispatch: (tr) => editor.view.dispatch(tr),
41
+ reconfigure: (plugins) => {
42
+ if (!editor.isDestroyed) editor.view.updateState(editor.state.reconfigure({ plugins: plugins(editor.state.plugins) }));
43
+ },
44
+ composing: () => !editor.isDestroyed && editor.view.composing,
45
+ onTransaction: (listener) => {
46
+ const handler = ({ transaction }) => listener(transaction);
47
+ editor.on("transaction", handler);
48
+ return () => {
49
+ editor.off("transaction", handler);
50
+ };
51
+ },
52
+ onCompositionEnd: (listener) => {
53
+ const dom = editor.view.dom;
54
+ dom.addEventListener("compositionend", listener);
55
+ return () => dom.removeEventListener("compositionend", listener);
56
+ },
57
+ destroyed: () => editor.isDestroyed
58
+ };
59
+ }
60
+ /**
61
+ * Binds `editor` to `room`: from now on the editor holds the room's draft.
62
+ *
63
+ * @param editor - The editor.
64
+ * @param room - The room's client.
65
+ * @param options - The client id, the role, and how text maps to a document.
66
+ */
67
+ function bindDraftCollab(editor, room, options) {
68
+ const timers = options.timers ?? realTimers;
69
+ let plugin = null;
70
+ /** Batches that wait for a composition to end, and a state that does. */
71
+ const queue = [];
72
+ let pendingReset = null;
73
+ /** A reset that waits came with a push of this editor's unanswered. */
74
+ let unsureReset = false;
75
+ let flushTimer = null;
76
+ let idleTimer = null;
77
+ let stepsSinceSnapshot = 0;
78
+ let installed = false;
79
+ /** The editor no longer listens (`stop`): nothing more is applied or sent. */
80
+ let stopped = false;
81
+ /**
82
+ * The collab client id of this install. A new one at each reset: steps this editor sent before it, which the room
83
+ * may still take, then come back as someone else's and are applied, never taken for its own unsent ones.
84
+ */
85
+ let author = options.clientId;
86
+ let installs = 0;
87
+ const live = () => !stopped && !editor.destroyed();
88
+ /** A fresh history: undo never reaches across the room's edge. */
89
+ const withPlugins = (collabPlugin) => {
90
+ const history = editor.state().plugins.find(isHistory);
91
+ const rest = (current) => current.filter((p) => !isCollab(p) && p !== history);
92
+ editor.reconfigure(rest);
93
+ editor.reconfigure((current) => [
94
+ ...current,
95
+ ...collabPlugin ? [collabPlugin] : [],
96
+ ...history ? [history] : []
97
+ ]);
98
+ };
99
+ const clearTimer = (timer) => {
100
+ if (timer !== null) timers.clearTimeout(timer);
101
+ return null;
102
+ };
103
+ /** The room's steps no longer apply here: what this editor has unsent is not sent, and it joins again. */
104
+ let poisoned = false;
105
+ const diverged = (error) => {
106
+ if (stopped || poisoned) return;
107
+ poisoned = true;
108
+ options.onDiverged?.(error);
109
+ };
110
+ function flush() {
111
+ flushTimer = clearTimer(flushTimer);
112
+ if (!live() || !plugin || poisoned || editor.composing() || queue.length > 0 || pendingReset) return;
113
+ const sendable = sendableSteps(editor.state());
114
+ if (!sendable) return;
115
+ room.push(sendable.version, sendable.steps.map((step) => step.toJSON()), author);
116
+ }
117
+ const scheduleFlush = () => {
118
+ if (flushTimer === null && live()) flushTimer = timers.setTimeout(flush, 30);
119
+ };
120
+ function snapshot() {
121
+ idleTimer = clearTimer(idleTimer);
122
+ if (!live() || !plugin) return;
123
+ const state = editor.state();
124
+ if (editor.composing() || queue.length > 0 || pendingReset || sendableSteps(state)) {
125
+ idleTimer = timers.setTimeout(snapshot, DRAFT_SNAPSHOT_IDLE_MS);
126
+ return;
127
+ }
128
+ stepsSinceSnapshot = 0;
129
+ room.snapshot(getVersion(state), state.doc.toJSON(), options.textOf(state.doc));
130
+ }
131
+ const changed = (steps) => {
132
+ stepsSinceSnapshot += steps;
133
+ idleTimer = clearTimer(idleTimer);
134
+ if (stepsSinceSnapshot >= 100 && !sendableSteps(editor.state())) snapshot();
135
+ else idleTimer = timers.setTimeout(snapshot, DRAFT_SNAPSHOT_IDLE_MS);
136
+ };
137
+ function install(state, unsure = false) {
138
+ if (options.accepts && !options.accepts()) {
139
+ options.onWrongSchema?.();
140
+ return;
141
+ }
142
+ const schema = editor.state().schema;
143
+ let base;
144
+ try {
145
+ base = schema.nodeFromJSON(state.doc ?? options.docFromText(state.text));
146
+ for (const json of state.steps) {
147
+ const applied = Step.fromJSON(schema, json).apply(base);
148
+ if (!applied.doc) throw new Error(applied.failed ?? "A step of the draft does not apply.");
149
+ base = applied.doc;
150
+ }
151
+ } catch (error) {
152
+ diverged(error);
153
+ return;
154
+ }
155
+ const before = editor.state();
156
+ const local = before.doc;
157
+ const { anchor, head } = before.selection;
158
+ const keepLocal = options.role === "owner" && !installed && state.base === 0 && state.doc === null && state.steps.length === 0;
159
+ const resync = plugin !== null;
160
+ const unsent = resync && !unsure ? plugin.getState(before)?.unconfirmed ?? [] : [];
161
+ if (plugin) withPlugins(null);
162
+ plugin = null;
163
+ const swap = editor.state().tr.replaceWith(0, editor.state().doc.content.size, base.content);
164
+ swap.setMeta("addToHistory", false).setMeta(DRAFT_REMOTE_META, true);
165
+ editor.dispatch(swap);
166
+ poisoned = false;
167
+ author = installs++ === 0 ? options.clientId : `${options.clientId}.${installs}`;
168
+ plugin = collab({
169
+ version: state.version,
170
+ clientID: author
171
+ });
172
+ withPlugins(plugin);
173
+ installed = true;
174
+ if (keepLocal) {
175
+ const mine = editor.state().tr;
176
+ for (const step of diffSteps(mine.doc, local)) mine.step(step);
177
+ if (mine.docChanged) editor.dispatch(mine.setMeta("addToHistory", false));
178
+ }
179
+ let caret = {
180
+ anchor,
181
+ head
182
+ };
183
+ if (resync) {
184
+ const over = new Transform(local);
185
+ for (let i = unsent.length - 1; i >= 0; i--) over.step(unsent[i].inverted);
186
+ for (const step of diffSteps(over.doc, base)) over.step(step);
187
+ const mirrors = over.mapping;
188
+ const mine = editor.state().tr;
189
+ for (let i = 0, mapFrom = unsent.length; i < unsent.length; i++) {
190
+ const mapped = unsent[i].step.map(over.mapping.slice(mapFrom));
191
+ mapFrom--;
192
+ if (mapped && !over.maybeStep(mapped).failed) {
193
+ mirrors.setMirror(mapFrom, over.steps.length - 1);
194
+ mine.maybeStep(mapped);
195
+ }
196
+ }
197
+ if (mine.docChanged) editor.dispatch(mine.setMeta("addToHistory", false));
198
+ caret = {
199
+ anchor: over.mapping.map(anchor),
200
+ head: over.mapping.map(head)
201
+ };
202
+ }
203
+ const doc = editor.state().doc;
204
+ const size = doc.content.size;
205
+ const selection = options.role === "owner" || resync ? TextSelection.between(doc.resolve(Math.min(caret.anchor, size)), doc.resolve(Math.min(caret.head, size))) : Selection.atEnd(doc);
206
+ editor.dispatch(editor.state().tr.setSelection(selection).setMeta("addToHistory", false).setMeta(DRAFT_REMOTE_META, true));
207
+ scheduleFlush();
208
+ changed(0);
209
+ }
210
+ function apply(batch) {
211
+ const state = editor.state();
212
+ const schema = state.schema;
213
+ try {
214
+ const steps = batch.steps.map((json) => Step.fromJSON(schema, json));
215
+ const tr = receiveTransaction(state, steps, batch.clientIds, { mapSelectionBackward: true });
216
+ editor.dispatch(tr.setMeta(DRAFT_REMOTE_META, true));
217
+ } catch (error) {
218
+ diverged(error);
219
+ return;
220
+ }
221
+ changed(batch.steps.length);
222
+ }
223
+ /** What waited for a composition to end, now. */
224
+ const drain = () => {
225
+ if (!live() || editor.composing()) return;
226
+ const reset = pendingReset;
227
+ pendingReset = null;
228
+ if (reset) {
229
+ const unsure = unsureReset;
230
+ unsureReset = false;
231
+ install(reset, unsure);
232
+ }
233
+ while (queue.length > 0 && live()) apply(queue.shift());
234
+ scheduleFlush();
235
+ };
236
+ const binding = {
237
+ reset(state, options) {
238
+ if (!live()) return;
239
+ queue.length = 0;
240
+ unsureReset ||= options?.unsure === true;
241
+ if (editor.composing()) {
242
+ pendingReset = state;
243
+ return;
244
+ }
245
+ pendingReset = null;
246
+ const unsure = unsureReset;
247
+ unsureReset = false;
248
+ install(state, unsure);
249
+ },
250
+ steps(batch) {
251
+ if (!live() || !plugin && !pendingReset) return;
252
+ if (editor.composing() || pendingReset || queue.length > 0) {
253
+ queue.push(batch);
254
+ return;
255
+ }
256
+ apply(batch);
257
+ scheduleFlush();
258
+ },
259
+ ready: () => scheduleFlush(),
260
+ end() {
261
+ queue.length = 0;
262
+ pendingReset = null;
263
+ unsureReset = false;
264
+ flushTimer = clearTimer(flushTimer);
265
+ idleTimer = clearTimer(idleTimer);
266
+ if (!plugin) return null;
267
+ if (poisoned) {
268
+ if (!editor.destroyed()) withPlugins(null);
269
+ plugin = null;
270
+ return null;
271
+ }
272
+ let final = null;
273
+ try {
274
+ const state = editor.state();
275
+ const sendable = sendableSteps(state);
276
+ final = {
277
+ version: sendable?.version ?? getVersion(state),
278
+ steps: sendable ? sendable.steps.map((step) => step.toJSON()) : [],
279
+ doc: state.doc.toJSON(),
280
+ text: options.textOf(state.doc)
281
+ };
282
+ if (!editor.destroyed()) withPlugins(null);
283
+ } catch {
284
+ final = null;
285
+ }
286
+ plugin = null;
287
+ return final;
288
+ }
289
+ };
290
+ const offTransaction = editor.onTransaction((tr) => {
291
+ if (!plugin || stopped) return;
292
+ if (tr.docChanged && tr.getMeta("zgDraftRemote") !== true) {
293
+ changed(tr.steps.length);
294
+ scheduleFlush();
295
+ }
296
+ if (queue.length > 0 || pendingReset) drain();
297
+ });
298
+ const offComposition = editor.onCompositionEnd(() => {
299
+ timers.setTimeout(drain, 0);
300
+ });
301
+ room.attach(options.clientId, binding);
302
+ return { stop: () => {
303
+ stopped = true;
304
+ offTransaction();
305
+ offComposition();
306
+ flushTimer = clearTimer(flushTimer);
307
+ idleTimer = clearTimer(idleTimer);
308
+ } };
309
+ }
310
+ export { DRAFT_FLUSH_MS, DRAFT_REMOTE_META, DRAFT_SNAPSHOT_IDLE_MS, DRAFT_SNAPSHOT_STEPS, bindDraftCollab, tiptapCollabEditor };
@@ -55,5 +55,7 @@ export interface ComposerEditorOptions {
55
55
  } | null) => void;
56
56
  /** The commands' fixed argument values (what the `/` popover learns, the command badge shows). */
57
57
  commandArgs: ComposerCommandArgs | undefined;
58
+ /** The draft is edited together now (`use-draft-collab.ts`): no prompt modes, no history recall. */
59
+ collab?: () => 'owner' | 'guest' | null;
58
60
  }
59
61
  export declare function useComposerEditor(options: ComposerEditorOptions): Editor | null;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The composer's collaborative draft (docs/MULTIPLAYER.md, Collaborative
3
+ * drafts), in two halves around the editor's creation:
4
+ *
5
+ * - {@link useComposerCollab} reads what the composer shows (your draft, or
6
+ * someone's you joined from a tab) and its room, before the editor is made:
7
+ * a draft edited together uses the plain schema, the same for everyone in
8
+ * the room, so the editor is built plain while it lasts.
9
+ * - {@link useComposerCollabBinding} binds the editor to the room
10
+ * (`draft-collab.ts`): a new client id for each editor, the room let go when
11
+ * the composer shows another draft.
12
+ *
13
+ * Nothing here re-renders on a keystroke: the room's state changes when
14
+ * someone joins or leaves, never while text is typed.
15
+ */
16
+ import { DraftComposerState } from "../../session/headless/draft-collab.js";
17
+ import { DraftRoomClient } from "../../session/headless/draft-room.js";
18
+ import { Editor } from "@tiptap/react";
19
+ /** What the composer reads of its collaborative draft. */
20
+ export interface ComposerCollab {
21
+ /** The composer shows someone else's draft: you edit it, its owner sends it. */
22
+ guest: boolean;
23
+ /** Whose draft it shows, when `guest`: their user id and name. */
24
+ ownerId: string | null;
25
+ ownerName: string | null;
26
+ /** The room is open: its document is in the editor. */
27
+ open: boolean;
28
+ /** The last draft you were in that ended without you leaving it, and why. */
29
+ ended: DraftComposerState['ended'];
30
+ /** The draft has a live room now (yours with someone in it, or theirs). */
31
+ live: boolean;
32
+ /** The editor is built plain while this holds. */
33
+ plain: boolean;
34
+ /** The room the composer edits in (idle for your own while nobody else is in it). */
35
+ room: DraftRoomClient | null;
36
+ /** Read at any time, by callbacks: `guest`, `owner` (your draft's room is live) or `null`. */
37
+ role: () => 'owner' | 'guest' | null;
38
+ /** The editor has the wrong schema for a room that opened: build it plain. */
39
+ needPlain: () => void;
40
+ }
41
+ /**
42
+ * The composer's collaborative draft for a session, before its editor is built.
43
+ *
44
+ * @param sessionId - The session the composer shows (`null`: a new chat: none).
45
+ */
46
+ export declare function useComposerCollab(sessionId: string | null): ComposerCollab;
47
+ /**
48
+ * Binds the composer's editor to its room.
49
+ *
50
+ * @param editor - The composer's editor.
51
+ * @param collab - The composer's collaborative draft ({@link useComposerCollab}).
52
+ */
53
+ export declare function useComposerCollabBinding(editor: Editor | null, collab: ComposerCollab): void;
@@ -0,0 +1,92 @@
1
+ import { useDraftCollab, useDraftComposer, useDraftRoomView } from "../../session/useDraftCollab.js";
2
+ import { draftTextToDocJson, draftWireText } from "../headless/composer/draft-sync.js";
3
+ import { bindDraftCollab, tiptapCollabEditor } from "./draft-collab.js";
4
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
5
+ // src/chat/rich-composer/use-draft-collab.ts
6
+ let clientCounter = 0;
7
+ /** A client id for one editor in one room: unique in this window, never reused. */
8
+ function newClientId() {
9
+ clientCounter += 1;
10
+ return `${typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID().slice(0, 8) : Math.random().toString(36).slice(2, 10)}-${clientCounter}`;
11
+ }
12
+ /** Whether an editor has the plain schema: no lists and no code. */
13
+ const isPlain = (editor) => editor.schema.nodes.codeBlock === void 0 && editor.schema.nodes.bulletList === void 0;
14
+ /**
15
+ * The composer's collaborative draft for a session, before its editor is built.
16
+ *
17
+ * @param sessionId - The session the composer shows (`null`: a new chat: none).
18
+ */
19
+ function useComposerCollab(sessionId) {
20
+ const collab = useDraftCollab();
21
+ const composer = useDraftComposer(sessionId);
22
+ const view = useDraftRoomView(composer.room);
23
+ const [plainWanted, setPlainWanted] = useState(false);
24
+ useEffect(() => {
25
+ if (!collab || !sessionId) return void 0;
26
+ return collab.mount(sessionId);
27
+ }, [collab, sessionId]);
28
+ const guest = composer.viewing !== null;
29
+ const ownerLive = composer.room?.role === "owner" && view.status === "open";
30
+ const live = guest || ownerLive;
31
+ useEffect(() => {
32
+ if (!live && view.status !== "joining") setPlainWanted(false);
33
+ }, [live, view.status]);
34
+ const latest = useRef(composer);
35
+ useLayoutEffect(() => {
36
+ latest.current = composer;
37
+ });
38
+ const role = useCallback(() => {
39
+ const now = latest.current;
40
+ if (now.viewing !== null) return "guest";
41
+ return now.room?.role === "owner" && now.room.view.get().status === "open" ? "owner" : null;
42
+ }, []);
43
+ const needPlain = useCallback(() => setPlainWanted(true), []);
44
+ const owner = guest ? view.people.find((person) => person.userId === composer.viewing) : void 0;
45
+ return {
46
+ guest,
47
+ ownerId: composer.viewing,
48
+ ownerName: owner?.name ?? null,
49
+ open: view.status === "open",
50
+ ended: composer.ended,
51
+ live,
52
+ plain: guest || ownerLive || plainWanted,
53
+ room: composer.room,
54
+ role,
55
+ needPlain
56
+ };
57
+ }
58
+ /**
59
+ * Binds the composer's editor to its room.
60
+ *
61
+ * @param editor - The composer's editor.
62
+ * @param collab - The composer's collaborative draft ({@link useComposerCollab}).
63
+ */
64
+ function useComposerCollabBinding(editor, collab) {
65
+ const { room, needPlain } = collab;
66
+ const plain = useRef(collab.plain);
67
+ useLayoutEffect(() => {
68
+ plain.current = collab.plain;
69
+ });
70
+ const [rebind, setRebind] = useState(0);
71
+ useEffect(() => {
72
+ if (!editor || editor.isDestroyed || !room) return void 0;
73
+ if (plain.current && !isPlain(editor)) return void 0;
74
+ const binding = bindDraftCollab(tiptapCollabEditor(editor), room, {
75
+ clientId: newClientId(),
76
+ role: room.role,
77
+ docFromText: (text) => draftTextToDocJson(text, { structure: false }),
78
+ textOf: (doc) => draftWireText(doc.toJSON()),
79
+ accepts: () => isPlain(editor),
80
+ onWrongSchema: needPlain,
81
+ onDiverged: () => setRebind((n) => n + 1)
82
+ });
83
+ return () => binding.stop();
84
+ }, [
85
+ editor,
86
+ room,
87
+ needPlain,
88
+ rebind
89
+ ]);
90
+ useEffect(() => room ? () => room.detach() : void 0, [room]);
91
+ }
92
+ export { useComposerCollab, useComposerCollabBinding };
@@ -73,6 +73,11 @@ export interface DraftMirrorOptions {
73
73
  applyMode: (next: ComposerMode) => void;
74
74
  /** The session switched away: the "history N/M" indicator belongs to the old one. */
75
75
  resetHistoryStatus: () => void;
76
+ /**
77
+ * The draft is edited together now (`use-draft-collab.ts`): `guest` (someone else's draft: nothing of it is kept or
78
+ * published as yours) or `owner` (your own, its room keeps it: nothing published, nothing applied). `null`: neither.
79
+ */
80
+ collab?: () => 'owner' | 'guest' | null;
76
81
  }
77
82
  export interface DraftMirror {
78
83
  /** Put a draft in the buffer as the shared draft's value (not published back). */
@@ -81,6 +86,12 @@ export interface DraftMirror {
81
86
  promoteNewChat: (on: boolean) => void;
82
87
  /** The buffer was sent: its draft is gone from the book. */
83
88
  dropStash: () => void;
89
+ /** The composer shows someone else's draft from now on: yours is kept in the book, its files with it. */
90
+ suspendForGuest: () => void;
91
+ /** The composer shows your draft again, as the book kept it. */
92
+ resumeFromGuest: () => void;
93
+ /** Your draft's room let it go: the shared draft hears the buffer now. */
94
+ publishNow: () => void;
84
95
  }
85
96
  export declare function useDraftMirror(options: DraftMirrorOptions): DraftMirror;
86
97
  export {};
@@ -51,12 +51,14 @@ function useDraftMirror(options) {
51
51
  const book = useDraftBook();
52
52
  const latest = useRef({
53
53
  ...options,
54
- book
54
+ book,
55
+ drafts
55
56
  });
56
57
  useLayoutEffect(() => {
57
58
  latest.current = {
58
59
  ...options,
59
- book
60
+ book,
61
+ drafts
60
62
  };
61
63
  });
62
64
  const lastSyncedDraftRef = useRef(null);
@@ -73,7 +75,7 @@ function useDraftMirror(options) {
73
75
  };
74
76
  const applyDraft = (text, shell) => {
75
77
  const ed = liveEditor();
76
- if (!ed || modeRef.current === "search") return;
78
+ if (!ed || modeRef.current === "search" || latest.current.collab?.()) return;
77
79
  const next = {
78
80
  text,
79
81
  shell
@@ -94,20 +96,24 @@ function useDraftMirror(options) {
94
96
  };
95
97
  };
96
98
  const applyAttachments = (wire) => {
99
+ if (latest.current.collab?.() === "guest") return;
97
100
  const key = attachmentsWireKey(wire);
98
101
  if (key === lastSyncedAttachmentsRef.current) return;
99
102
  lastSyncedAttachmentsRef.current = key;
100
103
  latest.current.staged.replace(wireToChatAttachments(wire));
101
104
  };
102
- /** Saves the buffer under the draft it holds. Not while it is a search query, nor from an editor that holds no draft. */
103
- const save = (from = liveEditor()) => {
105
+ /**
106
+ * Saves the buffer under the draft it holds. Not while it is a search query, nor from an editor that holds no draft,
107
+ * nor while it holds someone else's (`yours`: it is still yours, the composer is about to show theirs).
108
+ */
109
+ const save = (from = liveEditor(), yours = false) => {
104
110
  if (bookSave.current) {
105
111
  clearTimeout(bookSave.current);
106
112
  bookSave.current = null;
107
113
  }
108
114
  const loaded = loadedRef.current;
109
115
  const ed = from;
110
- if (!loaded || !ed || ed !== loaded.editor || modeRef.current === "search") return;
116
+ if (!loaded || !ed || ed !== loaded.editor || modeRef.current === "search" || !yours && latest.current.collab?.() === "guest") return;
111
117
  const { attachments, exitingIds } = latest.current.staged;
112
118
  const empty = ed.isEmpty;
113
119
  latest.current.book.put(loaded.key, {
@@ -150,6 +156,29 @@ function useDraftMirror(options) {
150
156
  }
151
157
  const loaded = loadedRef.current;
152
158
  if (loaded) latest.current.book.put(loaded.key, null);
159
+ },
160
+ suspendForGuest: () => {
161
+ save(liveEditor(), true);
162
+ latest.current.applyMode("normal");
163
+ latest.current.staged.replace([]);
164
+ },
165
+ resumeFromGuest: () => {
166
+ const ed = liveEditor();
167
+ const shown = shownKeyRef.current;
168
+ if (!shown) return;
169
+ latest.current.staged.replace([...latest.current.book.get(shown.key)?.attachments ?? []]);
170
+ if (ed) showText(ed, shown.key, true);
171
+ },
172
+ publishNow: () => {
173
+ const sessionId = latest.current.activeSessionId;
174
+ const ed = liveEditor();
175
+ if (!sessionId || !ed || draftSyncSessionRef.current !== sessionId || modeRef.current === "search" || latest.current.collab?.()) return;
176
+ const next = {
177
+ text: serializeDraftText(ed),
178
+ shell: modeRef.current === "shell"
179
+ };
180
+ lastSyncedDraftRef.current = next;
181
+ latest.current.drafts?.set(sessionId, next.text, next.shell).catch(() => void 0);
153
182
  }
154
183
  }
155
184
  };
@@ -289,7 +318,7 @@ function useDraftMirror(options) {
289
318
  if (!sessionId) return;
290
319
  const run = () => {
291
320
  draftPublish.current = null;
292
- if (draftSyncSessionRef.current !== sessionId || modeRef.current === "search") return;
321
+ if (draftSyncSessionRef.current !== sessionId || modeRef.current === "search" || latest.current.collab?.()) return;
293
322
  const ed = mirror.liveEditor();
294
323
  const next = {
295
324
  text: ed ? serializeDraftText(ed) : "",
@@ -301,7 +330,7 @@ function useDraftMirror(options) {
301
330
  drafts?.set(sessionId, next.text, next.shell).catch(() => void 0);
302
331
  };
303
332
  const schedule = () => {
304
- if (draftSyncSessionRef.current !== sessionId || modeRef.current === "search") return;
333
+ if (draftSyncSessionRef.current !== sessionId || modeRef.current === "search" || latest.current.collab?.()) return;
305
334
  if (draftPublish.current) clearTimeout(draftPublish.current.timer);
306
335
  draftPublish.current = {
307
336
  timer: setTimeout(run, DRAFT_PUBLISH_MS),
@@ -330,7 +359,7 @@ function useDraftMirror(options) {
330
359
  }, [activeSessionId]);
331
360
  useEffect(() => {
332
361
  const sessionId = activeSessionId;
333
- if (!sessionId || draftSyncSessionRef.current !== sessionId) return;
362
+ if (!sessionId || draftSyncSessionRef.current !== sessionId || latest.current.collab?.() === "guest") return;
334
363
  const wire = chatAttachmentsToWire(attachments);
335
364
  const key = attachmentsWireKey(wire);
336
365
  if (key === lastSyncedAttachmentsRef.current) return;
@@ -13,7 +13,7 @@ const SHELF_ICONS = {
13
13
  archived: "i-ph-archive"
14
14
  };
15
15
  const HEAD = "zg-sticky-head zg-no-drag group flex items-center gap-1.5 -mx-2 px-3 pt-3 pb-1 text-sm text-[var(--zg-text-muted)] select-none";
16
- const HEAD_BUTTON = "zg-press-soft flex flex-1 items-center gap-1.5 min-w-0 bg-transparent border-0 cursor-pointer p-0 font-medium text-[var(--zg-sidebar-label-fg,var(--zg-text-muted))] hover:text-[var(--zg-text)] transition-colors";
16
+ const HEAD_BUTTON = "zg-press-soft flex flex-1 items-center gap-1.5 min-w-0 bg-transparent border-0 cursor-pointer p-0 text-[var(--zg-sidebar-label-fg,var(--zg-text-muted))] hover:text-[var(--zg-text)] transition-colors";
17
17
  /** Draws the inbox rows as `<li>` children of the sidebar's list. */
18
18
  function InboxList({ rows, renderSession, onToggleShelf, onToggleFolder, onShowMore, onNewSessionIn, projectIcons, onAssignIcon, onOpenProject, openProject, onOpenChats, chatsOpen = false, projectRecords, onOpenProjectRecord, openProjectId = null, onSetProjectIcon }) {
19
19
  const labels = useSidebarLabels();
@@ -41,6 +41,8 @@ export interface ProjectIconGlyphProps {
41
41
  isGitRepo?: boolean;
42
42
  /** Default glyph class when nothing is assigned; overrides the folder choice. */
43
43
  defaultGlyph?: string;
44
+ /** A server's project: with nothing assigned, a cloud, not a folder. */
45
+ server?: boolean;
44
46
  /** `xs`: a menu row's 16px icon slot. `sm`: the sidebar's 18px slot. `lg`: a heading's 28px slot (the project home). */
45
47
  size?: 'xs' | 'sm' | 'lg';
46
48
  /** Extra classes on the slot. */
@@ -53,7 +55,7 @@ export interface ProjectIconGlyphProps {
53
55
  *
54
56
  * @param props - The {@link ProjectIconGlyphProps}.
55
57
  */
56
- export declare function ProjectIconGlyph({ icon, isGitRepo, defaultGlyph, size, className, style }: ProjectIconGlyphProps): import("react").JSX.Element;
58
+ export declare function ProjectIconGlyph({ icon, isGitRepo, defaultGlyph, server, size, className, style }: ProjectIconGlyphProps): import("react").JSX.Element;
57
59
  /** Props of {@link ProjectIconButton}. */
58
60
  export interface ProjectIconButtonProps {
59
61
  /**
@@ -75,6 +77,8 @@ export interface ProjectIconButtonProps {
75
77
  * choice; the pinned Main row uses a home icon here.
76
78
  */
77
79
  defaultGlyph?: string;
80
+ /** A server's project: the default glyph is the server's (a cloud), as on {@link ProjectIconGlyph}. */
81
+ server?: boolean;
78
82
  /** Tooltip on the trigger; defaults to the project wording. */
79
83
  title?: string;
80
84
  /** Assigns (or, with `null`, resets) the folder's icon. */
@@ -94,7 +98,7 @@ export declare const ICON_PICKER_WIDTH = 232;
94
98
  *
95
99
  * @param props - The {@link ProjectIconButtonProps}.
96
100
  */
97
- export declare function ProjectIconButton({ fullPath, label, icon, isGitRepo, defaultGlyph, title, onAssign, className, style }: ProjectIconButtonProps): import("react").JSX.Element;
101
+ export declare function ProjectIconButton({ fullPath, label, icon, isGitRepo, defaultGlyph: defaultGlyphProp, server, title, onAssign, className, style }: ProjectIconButtonProps): import("react").JSX.Element;
98
102
  /** Props of {@link IconPicker}. */
99
103
  export interface IconPickerProps {
100
104
  /** An icon is set: the reset row shows. */