zidane-ui 9.5.2 → 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 (201) 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 +29 -29
  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-DPbpsCtl.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 +9 -9
  194. package/dist/settings/sections/index.js +1 -1
  195. package/dist/settings/sections/providers/CredentialSources.d.ts +5 -5
  196. package/dist/settings/sections/providers/CredentialSources.js +5 -22
  197. package/dist/settings/sections/providers/labels.d.ts +1 -9
  198. package/dist/settings/sections/providers/labels.js +1 -9
  199. package/dist/styles.css +20 -9
  200. package/package.json +4 -3
  201. package/src/styles/sidebar.css +2 -3
@@ -1,4 +1,5 @@
1
1
  import { useOptionalConfirm } from "../app/useConfirm.js";
2
+ import { BrandMark, hasBrandMark } from "../components/BrandMark.js";
2
3
  import { BTN_SECONDARY } from "../components/button.js";
3
4
  import { MetaChip } from "../components/Form.js";
4
5
  import { Notice } from "../components/Notice.js";
@@ -6,7 +7,7 @@ import { useProviderUsage } from "./ProviderUsageProvider.js";
6
7
  import { useSessionLabels } from "./useSessionLabels.js";
7
8
  import { useState } from "react";
8
9
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
- import { formatBalance, formatUsagePercent, resetLabel, showsAccount, updatedLabel, usageTone } from "zidane/chat/pure";
10
+ import { formatBalance, formatUsagePercent, providerBrand, resetLabel, showsAccount, updatedLabel, usageTone } from "zidane/chat/pure";
10
11
  // src/session/UsageSection.tsx
11
12
  const TONE_CLS = {
12
13
  ok: "text-[var(--zg-text)]",
@@ -22,9 +23,9 @@ const BAR_CLS = {
22
23
  * Renders the subscription windows of every signed-in provider and GitHub, with a Refresh: the body of
23
24
  * Settings › Accounts › Usage (`panels.usage` of `SettingsRowsPage`).
24
25
  *
25
- * @param props - `activeProviderKey`, `autoLoad`, `className` and `style`.
26
+ * @param props - `autoLoad`, `className` and `style`.
26
27
  */
27
- function UsageSection({ activeProviderKey = null, autoLoad = true, className = "", style }) {
28
+ function UsageSection({ autoLoad = true, className = "", style }) {
28
29
  const labels = useSessionLabels();
29
30
  const { snapshots, github, loading, loaded, refresh, redeemReset } = useProviderUsage();
30
31
  const empty = snapshots.length === 0 && github.length === 0;
@@ -53,15 +54,13 @@ function UsageSection({ activeProviderKey = null, autoLoad = true, className = "
53
54
  children: snapshots.map((snapshot) => /* @__PURE__ */ jsx(ProviderRow, {
54
55
  snapshot,
55
56
  account: showsAccount(snapshot, snapshots) ? snapshot.account : null,
56
- active: snapshot.providerKey === activeProviderKey && snapshot.activeCredential,
57
57
  onRedeemReset: redeemReset
58
58
  }, snapshot.credentialKey))
59
59
  }), github.length > 0 && /* @__PURE__ */ jsx(UsageGroup, {
60
60
  label: labels.usageGithub,
61
61
  children: github.map((snapshot) => /* @__PURE__ */ jsx(ProviderRow, {
62
62
  snapshot,
63
- account: null,
64
- active: false
63
+ account: null
65
64
  }, snapshot.credentialKey))
66
65
  })] })]
67
66
  });
@@ -74,69 +73,72 @@ function UsageGroup({ label, children }) {
74
73
  className: "m-0 px-1 text-zg-meta text-[var(--zg-text-muted)]",
75
74
  children: label
76
75
  }), /* @__PURE__ */ jsx("ul", {
77
- className: "zg-tray rounded-zg-lg flex flex-col p-1 m-0 list-none",
76
+ className: "zg-tray rounded-zg-lg flex flex-col gap-0.5 p-1 m-0 list-none",
78
77
  children
79
78
  })]
80
79
  });
81
80
  }
82
- function ProviderRow({ snapshot, account, active, onRedeemReset = null }) {
81
+ function ProviderRow({ snapshot, account, onRedeemReset = null }) {
83
82
  const labels = useSessionLabels();
84
83
  const looseCredits = snapshot.windows.some((win) => win.id === "credits") ? null : snapshot.credits;
84
+ const brand = providerBrand(snapshot.providerKey) ?? (hasBrandMark(snapshot.providerKey) ? snapshot.providerKey : void 0);
85
85
  return /* @__PURE__ */ jsxs("li", {
86
- className: "flex flex-col gap-1.5 px-3 py-2.5",
87
- children: [
88
- /* @__PURE__ */ jsxs("div", {
89
- className: "flex items-center gap-1.5 min-w-0",
90
- children: [
91
- /* @__PURE__ */ jsx("span", {
92
- className: "text-zg-ui font-medium text-[var(--zg-text)] truncate",
93
- children: snapshot.label
86
+ className: "zg-list-item flex items-start gap-3 px-3 py-2.5",
87
+ children: [/* @__PURE__ */ jsx(BrandMark, {
88
+ brand,
89
+ label: snapshot.label,
90
+ className: "shrink-0"
91
+ }), /* @__PURE__ */ jsxs("div", {
92
+ className: "flex flex-col gap-1.5 flex-1 min-w-0",
93
+ children: [
94
+ /* @__PURE__ */ jsxs("div", {
95
+ className: "flex items-center gap-1.5 min-w-0 min-h-7",
96
+ children: [
97
+ /* @__PURE__ */ jsx("span", {
98
+ className: "text-sm font-medium text-[var(--zg-text)] truncate",
99
+ children: snapshot.label
100
+ }),
101
+ account && /* @__PURE__ */ jsx(MetaChip, { children: account }),
102
+ snapshot.plan && /* @__PURE__ */ jsx(MetaChip, { children: snapshot.plan })
103
+ ]
104
+ }),
105
+ snapshot.status === "ok" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
106
+ snapshot.windows.map((win) => /* @__PURE__ */ jsx(WindowRow, {
107
+ win,
108
+ trailing: win.id === "credits" && snapshot.credits ? formatBalance(snapshot.credits) : resetLabel(win.resetsAt)
109
+ }, win.id)),
110
+ looseCredits && /* @__PURE__ */ jsxs("div", {
111
+ className: "flex items-center gap-3 text-zg-label",
112
+ children: [/* @__PURE__ */ jsx("span", {
113
+ className: "w-16 shrink-0 text-[var(--zg-text-muted)]",
114
+ children: labels.usageCredits
115
+ }), /* @__PURE__ */ jsx("span", {
116
+ className: "tabular-nums text-[var(--zg-text)]",
117
+ children: formatBalance(looseCredits)
118
+ })]
94
119
  }),
95
- account && /* @__PURE__ */ jsx(MetaChip, { children: account }),
96
- snapshot.plan && /* @__PURE__ */ jsx(MetaChip, { children: snapshot.plan }),
97
- active && /* @__PURE__ */ jsx(MetaChip, {
98
- tone: "accent",
99
- className: "ml-auto",
100
- children: labels.usageInUse
120
+ snapshot.resets && /* @__PURE__ */ jsx(ResetsRow, {
121
+ snapshot,
122
+ resets: snapshot.resets,
123
+ account: account ?? null,
124
+ onRedeem: onRedeemReset
101
125
  })
102
- ]
103
- }),
104
- snapshot.status === "ok" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
105
- snapshot.windows.map((win) => /* @__PURE__ */ jsx(WindowRow, {
106
- win,
107
- trailing: win.id === "credits" && snapshot.credits ? formatBalance(snapshot.credits) : resetLabel(win.resetsAt)
108
- }, win.id)),
109
- looseCredits && /* @__PURE__ */ jsxs("div", {
110
- className: "flex items-center gap-3 text-zg-label",
126
+ ] }) : /* @__PURE__ */ jsxs("div", {
127
+ className: "flex items-center gap-1.5 text-zg-label text-[var(--zg-text-muted)] min-w-0",
111
128
  children: [/* @__PURE__ */ jsx("span", {
112
- className: "w-16 shrink-0 text-[var(--zg-text-muted)]",
113
- children: labels.usageCredits
129
+ "aria-hidden": true,
130
+ className: `i-ph-warning-circle shrink-0 text-zg-ui ${snapshot.status === "unauthorized" ? "text-zg-warn" : ""}`
114
131
  }), /* @__PURE__ */ jsx("span", {
115
- className: "tabular-nums text-[var(--zg-text)]",
116
- children: formatBalance(looseCredits)
132
+ className: "truncate",
133
+ children: labels.usageUnavailable(snapshot.status === "unauthorized", snapshot.error)
117
134
  })]
118
135
  }),
119
- snapshot.resets && /* @__PURE__ */ jsx(ResetsRow, {
120
- snapshot,
121
- resets: snapshot.resets,
122
- account: account ?? null,
123
- onRedeem: onRedeemReset
136
+ snapshot.note && /* @__PURE__ */ jsx("span", {
137
+ className: "text-zg-label text-[var(--zg-text-muted)]",
138
+ children: snapshot.note
124
139
  })
125
- ] }) : /* @__PURE__ */ jsxs("div", {
126
- className: "flex items-center gap-1.5 text-zg-label text-[var(--zg-text-muted)] min-w-0",
127
- children: [/* @__PURE__ */ jsx("span", {
128
- "aria-hidden": true,
129
- className: `i-ph-warning-circle shrink-0 text-zg-ui ${snapshot.status === "unauthorized" ? "text-zg-warn" : ""}`
130
- }), /* @__PURE__ */ jsx("span", {
131
- className: "truncate",
132
- children: labels.usageUnavailable(snapshot.status === "unauthorized", snapshot.error)
133
- })]
134
- }),
135
- snapshot.note && /* @__PURE__ */ jsx("span", {
136
- className: "text-zg-label text-[var(--zg-text-muted)]",
137
- children: snapshot.note
138
- })
139
- ]
140
+ ]
141
+ })]
140
142
  });
141
143
  }
142
144
  /** Days before expiry when a reset's dates turn to the warning tone. */
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Which draft each composer of this window shows, and its rooms
3
+ * (docs/MULTIPLAYER.md, Collaborative drafts). Per session: the person whose
4
+ * draft the composer shows (`viewing`, `null` for your own), and the room
5
+ * client the composer edits in: a guest's while it shows someone's draft,
6
+ * else the one of your own draft (idle while nobody else is in it).
7
+ *
8
+ * The tabs over the composer call {@link DraftCollab.view}; the composer
9
+ * calls {@link DraftCollab.mount} while it shows a session. A guest's room
10
+ * that ends (its owner sent the draft, it went away, it refused you) gives
11
+ * the composer back to your own draft. One store per host
12
+ * (`draftCollabOf`), so every component of a window shares it. React-free.
13
+ */
14
+ import { Readable } from "../../chat/headless/store.js";
15
+ import { DraftRoomClient, DraftRoomClosed, DraftRoomTimers } from "./draft-room.js";
16
+ import { SessionDrafting, SessionDrafts } from "./drafts.js";
17
+ /** What one session's composer shows. */
18
+ export interface DraftComposerState {
19
+ /** Whose draft the composer shows: `null` for your own. */
20
+ viewing: string | null;
21
+ /** The room the composer edits in: the guest's while `viewing`, else your own draft's. `null`: none. */
22
+ room: DraftRoomClient | null;
23
+ /** The last draft you were in that ended without you leaving it, and why. */
24
+ ended?: {
25
+ ownerId: string;
26
+ closed: Exclude<DraftRoomClosed, 'left'>;
27
+ error?: string;
28
+ };
29
+ }
30
+ /** The window's collaborative drafts. */
31
+ export interface DraftCollab {
32
+ /** Who else drafts in each session. */
33
+ readonly drafting: SessionDrafting;
34
+ /** This window's person on the session's server. */
35
+ self: (sessionId: string) => string | undefined;
36
+ /** What a session's composer shows. The same store for the same session. */
37
+ composer: (sessionId: string) => Readable<DraftComposerState>;
38
+ /** Show someone's draft in a session's composer (`null`, or your own id: your own). */
39
+ view: (sessionId: string, ownerId: string | null) => void;
40
+ /** A composer shows the session: your own draft's room comes to it. Returns the release; the last one leaves the rooms. */
41
+ mount: (sessionId: string) => () => void;
42
+ }
43
+ /**
44
+ * The collaborative drafts of a window over the host's calls.
45
+ *
46
+ * @param drafts - The host's draft calls.
47
+ * @param timers - The clock of the rooms (a test). Default: real timers.
48
+ */
49
+ export declare function createDraftCollab(drafts: SessionDrafts, timers?: DraftRoomTimers): DraftCollab;
50
+ /**
51
+ * The window's {@link DraftCollab} over a host's draft calls: one per host, whoever asks.
52
+ *
53
+ * @param drafts - The host's draft calls (`SessionSharingHost.drafts`).
54
+ */
55
+ export declare function draftCollabOf(drafts: SessionDrafts): DraftCollab;
@@ -0,0 +1,127 @@
1
+ import { writable } from "../../chat/headless/store.js";
2
+ import { createDraftRoomClient } from "./draft-room.js";
3
+ // src/session/headless/draft-collab.ts
4
+ const EMPTY = {
5
+ viewing: null,
6
+ room: null
7
+ };
8
+ /**
9
+ * The collaborative drafts of a window over the host's calls.
10
+ *
11
+ * @param drafts - The host's draft calls.
12
+ * @param timers - The clock of the rooms (a test). Default: real timers.
13
+ */
14
+ function createDraftCollab(drafts, timers) {
15
+ const entries = /* @__PURE__ */ new Map();
16
+ const entryOf = (sessionId) => {
17
+ let entry = entries.get(sessionId);
18
+ if (!entry) {
19
+ entry = {
20
+ store: writable(EMPTY),
21
+ mounts: 0,
22
+ own: null,
23
+ guest: null,
24
+ offGuest: null
25
+ };
26
+ entries.set(sessionId, entry);
27
+ }
28
+ return entry;
29
+ };
30
+ const publish = (entry, ended) => {
31
+ const viewing = entry.guest?.ownerId ?? null;
32
+ const prev = entry.store.get();
33
+ entry.store.set({
34
+ viewing,
35
+ room: entry.guest ?? entry.own,
36
+ ...ended ? { ended } : prev.ended ? { ended: prev.ended } : {}
37
+ });
38
+ };
39
+ const dropGuest = (entry) => {
40
+ entry.offGuest?.();
41
+ entry.offGuest = null;
42
+ const guest = entry.guest;
43
+ entry.guest = null;
44
+ guest?.close();
45
+ };
46
+ const room = (sessionId, ownerId, role) => createDraftRoomClient(drafts, {
47
+ sessionId,
48
+ ownerId,
49
+ role,
50
+ ...timers ? { timers } : {}
51
+ });
52
+ /** Your own draft's room client, once the server says who you are. */
53
+ const ensureOwn = (sessionId, entry, self = drafts.self(sessionId)) => {
54
+ if (entry.own || self === void 0 || entry.mounts === 0) return entry.own;
55
+ entry.own = room(sessionId, self, "owner");
56
+ publish(entry);
57
+ return entry.own;
58
+ };
59
+ drafts.onSignal((signal) => {
60
+ if (signal.kind !== "draft:room") return;
61
+ const entry = entries.get(signal.sessionId);
62
+ if (!entry || entry.own || entry.mounts === 0 || entry.guest?.ownerId === signal.ownerId) return;
63
+ ensureOwn(signal.sessionId, entry, drafts.self(signal.sessionId) ?? signal.ownerId)?.invited();
64
+ });
65
+ return {
66
+ drafting: drafts.drafting,
67
+ self: drafts.self,
68
+ composer: (sessionId) => entryOf(sessionId).store,
69
+ view(sessionId, ownerId) {
70
+ const entry = entryOf(sessionId);
71
+ const self = drafts.self(sessionId);
72
+ const target = ownerId === null || ownerId === self ? null : ownerId;
73
+ if ((entry.guest?.ownerId ?? null) === target) return;
74
+ dropGuest(entry);
75
+ if (target !== null) {
76
+ const guest = room(sessionId, target, "guest");
77
+ entry.guest = guest;
78
+ entry.offGuest = guest.view.subscribe(() => {
79
+ const now = guest.view.get();
80
+ if (now.status !== "closed" || entry.guest !== guest || now.closed === "left" || now.closed === void 0) return;
81
+ entry.offGuest?.();
82
+ entry.offGuest = null;
83
+ entry.guest = null;
84
+ publish(entry, {
85
+ ownerId: target,
86
+ closed: now.closed,
87
+ ...now.error ? { error: now.error } : {}
88
+ });
89
+ guest.close();
90
+ });
91
+ }
92
+ publish(entry);
93
+ },
94
+ mount(sessionId) {
95
+ const entry = entryOf(sessionId);
96
+ entry.mounts++;
97
+ ensureOwn(sessionId, entry);
98
+ let released = false;
99
+ return () => {
100
+ if (released) return;
101
+ released = true;
102
+ entry.mounts--;
103
+ if (entry.mounts > 0) return;
104
+ dropGuest(entry);
105
+ const own = entry.own;
106
+ entry.own = null;
107
+ own?.close();
108
+ entry.store.set(EMPTY);
109
+ };
110
+ }
111
+ };
112
+ }
113
+ const collabs = /* @__PURE__ */ new WeakMap();
114
+ /**
115
+ * The window's {@link DraftCollab} over a host's draft calls: one per host, whoever asks.
116
+ *
117
+ * @param drafts - The host's draft calls (`SessionSharingHost.drafts`).
118
+ */
119
+ function draftCollabOf(drafts) {
120
+ let collab = collabs.get(drafts);
121
+ if (!collab) {
122
+ collab = createDraftCollab(drafts);
123
+ collabs.set(drafts, collab);
124
+ }
125
+ return collab;
126
+ }
127
+ export { createDraftCollab, draftCollabOf };
@@ -0,0 +1,124 @@
1
+ /**
2
+ * One window's client of one draft room (docs/MULTIPLAYER.md, Collaborative
3
+ * drafts), React-free and blind to ProseMirror: steps are opaque JSON. It
4
+ * joins the room, hands the editor binding the room's state and every batch
5
+ * of steps in version order (its own pushes included, once taken), and keeps
6
+ * at most one push in flight. A refused push, a gap in the signals, or a
7
+ * reconnect makes it ask the steps it missed (`since`); a client behind what
8
+ * the server keeps starts again from the snapshot (`reset`), its unsent steps
9
+ * rebased onto it.
10
+ *
11
+ * The owner's client asks with `ifOpen`: it stays `idle` while nobody else is
12
+ * in their draft, opens when someone joins (`draft:room`), and goes back to
13
+ * `idle` when they are alone again, after a last push and snapshot. A guest's
14
+ * client closes when the room ends (`sent`), goes away (`gone`) or refuses
15
+ * them (`refused`, also when the room lets them go: they may no longer prompt).
16
+ *
17
+ * The editor side (`zidane-ui/chat`, `chat/rich-composer/draft-collab.ts`)
18
+ * implements {@link DraftRoomBinding}.
19
+ */
20
+ import { Readable } from "../../chat/headless/store.js";
21
+ import { DraftPerson, DraftRoomState, SessionDrafts } from "./drafts.js";
22
+ /** Steps the authority took, in order: `steps[i]` made version `base + i + 1`. */
23
+ export interface DraftBatch {
24
+ /** The version the steps follow. */
25
+ base: number;
26
+ /** The steps, as JSON, in order. */
27
+ steps: readonly unknown[];
28
+ /** The client that made each step. */
29
+ clientIds: readonly string[];
30
+ }
31
+ /** What an editor hands back when it lets go of a room: its unsent steps and its document. */
32
+ export interface DraftFinal {
33
+ /** The version the unsent steps were made at. */
34
+ version: number;
35
+ /** The unsent steps, as JSON. */
36
+ steps: readonly unknown[];
37
+ /** The document with them (ProseMirror JSON), and its text. */
38
+ doc: unknown;
39
+ /** The document's plain text. */
40
+ text: string;
41
+ }
42
+ /** The editor side of a room. */
43
+ export interface DraftRoomBinding {
44
+ /**
45
+ * The room's state: build the document from it (the snapshot, then its steps). Again after a resync, with the steps
46
+ * the editor has unsent rebased onto it, unless `unsure`: a push of them went out unanswered, so the room may hold
47
+ * them already.
48
+ */
49
+ reset: (state: DraftRoomState, options?: {
50
+ unsure?: boolean;
51
+ }) => void;
52
+ /** Steps after the version delivered last, in order. */
53
+ steps: (batch: DraftBatch) => void;
54
+ /** Nothing waits on the network now: push what is unsent. */
55
+ ready: () => void;
56
+ /** Let go of the room: what is unsent and the document now (`null`: nothing to keep). */
57
+ end: () => DraftFinal | null;
58
+ }
59
+ /** Where a room client stands. */
60
+ export type DraftRoomStatus = 'idle' | 'joining' | 'open' | 'closed';
61
+ /** Why a room client closed. */
62
+ export type DraftRoomClosed = 'sent' | 'gone' | 'refused' | 'left';
63
+ /** What the composer and its avatars read of a room. */
64
+ export interface DraftRoomView {
65
+ /** Where the client stands. */
66
+ status: DraftRoomStatus;
67
+ /** Who is in the room, its owner first (this window's person included). */
68
+ people: readonly DraftPerson[];
69
+ /** Why it closed. */
70
+ closed?: DraftRoomClosed;
71
+ /** The host's words, when it refused. */
72
+ error?: string;
73
+ }
74
+ /** One window's client of one room. */
75
+ export interface DraftRoomClient {
76
+ /** The session, by its id on this host. */
77
+ readonly sessionId: string;
78
+ /** Whose draft. */
79
+ readonly ownerId: string;
80
+ /** `owner`: this window's person's own draft; `guest`: someone else's. */
81
+ readonly role: 'owner' | 'guest';
82
+ /** What the composer and its avatars read, kept current. */
83
+ readonly view: Readable<DraftRoomView>;
84
+ /** An editor takes the room (`clientId`: its own, new for each editor). One that held it before lets go first. */
85
+ attach: (clientId: string, binding: DraftRoomBinding) => void;
86
+ /**
87
+ * Steps made at `version` by the editor's collab client `by` (absent: the attached client id). `false`: one is in
88
+ * flight, or the version is not the one delivered last.
89
+ */
90
+ push: (version: number, steps: readonly unknown[], by?: string) => boolean;
91
+ /** The document at `version`, when the editor has nothing unsent. */
92
+ snapshot: (version: number, doc: unknown, text: string) => void;
93
+ /** The owner's window: someone joined their draft. Joins it when it is not in it. */
94
+ invited: () => void;
95
+ /** The editor lets go (the composer shows another draft): its last steps go out and the client leaves the room, ready to join again. */
96
+ detach: () => void;
97
+ /** Leave the room for good: the editor lets go, its last steps go out, then it leaves. */
98
+ close: () => Promise<void>;
99
+ }
100
+ /** Timers a client waits on: a retry after a refused push. */
101
+ export interface DraftRoomTimers {
102
+ /** Runs `run` after `ms`; returns the timer. */
103
+ setTimeout: (run: () => void, ms: number) => unknown;
104
+ /** Cancels a timer `setTimeout` returned. */
105
+ clearTimeout: (timer: unknown) => void;
106
+ }
107
+ /** A push that failed waits this long before the next. */
108
+ export declare const DRAFT_PUSH_RETRY_MS = 1000;
109
+ /**
110
+ * A room client over the host's calls.
111
+ *
112
+ * @param drafts - The host's draft calls.
113
+ * @param options - The draft, whose it is, and the timers.
114
+ * @param options.sessionId - The session, by its id on this host.
115
+ * @param options.ownerId - Whose draft.
116
+ * @param options.role - `owner`: this window's person's own draft (it joins only while someone else is in it).
117
+ * @param options.timers - The clock (a test). Default: real timers.
118
+ */
119
+ export declare function createDraftRoomClient(drafts: SessionDrafts, options: {
120
+ sessionId: string;
121
+ ownerId: string;
122
+ role: 'owner' | 'guest';
123
+ timers?: DraftRoomTimers;
124
+ }): DraftRoomClient;