@tangle-network/ui 11.10.0 → 11.11.0

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 (130) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/active-sessions-store-Gt1R0rFG.js +262 -0
  3. package/dist/{active-sessions-store-CeOmXgv5.d.ts → active-sessions-store-nl70ZnMC.d.ts} +40 -41
  4. package/dist/artifact-pane-BL_DFWNl.d.ts +32 -0
  5. package/dist/artifact-pane-DMXT9a8U.js +70 -0
  6. package/dist/auth-DixfCMCk.js +154 -0
  7. package/dist/auth.d.ts +2 -74
  8. package/dist/auth.js +2 -16
  9. package/dist/branding-26d5ARIr.d.ts +14 -0
  10. package/dist/button-uhNnwdsD.js +78 -0
  11. package/dist/button-yoIv77e2.d.ts +16 -0
  12. package/dist/chat-CPLL0Fd9.js +667 -0
  13. package/dist/chat.d.ts +2 -201
  14. package/dist/chat.js +2 -31
  15. package/dist/code-block-B9miUPht.d.ts +23 -0
  16. package/dist/code-block-CngSn37j.js +165 -0
  17. package/dist/diff-preview-cySuqowW.js +533 -0
  18. package/dist/document-editor-pane-BcoABlhn.d.ts +131 -0
  19. package/dist/document-editor-pane-Cz6oEF1o.js +1287 -0
  20. package/dist/dropdown-menu-BpcLa5vF.js +101 -0
  21. package/dist/editor.d.ts +76 -78
  22. package/dist/editor.js +2 -34
  23. package/dist/file-format-BgXbr-Ib.js +160 -0
  24. package/dist/files-CYlOo0mE.js +743 -0
  25. package/dist/files.d.ts +2 -243
  26. package/dist/files.js +3 -41
  27. package/dist/focus-Cw02pNSr.js +56 -0
  28. package/dist/format-DfcLWqMa.js +54 -0
  29. package/dist/hooks.d.ts +30 -37
  30. package/dist/hooks.js +111 -46
  31. package/dist/index-2UntyjBb.d.ts +52 -0
  32. package/dist/index-COgqsFAQ.d.ts +42 -0
  33. package/dist/index-CPDET_s1.d.ts +549 -0
  34. package/dist/index-CUhfHT_V.d.ts +204 -0
  35. package/dist/index-Cg6gYAqh.d.ts +73 -0
  36. package/dist/index-Cq-EJzqW.d.ts +16 -0
  37. package/dist/index-DhYmSaLF.d.ts +245 -0
  38. package/dist/index-DjKxO357.d.ts +128 -0
  39. package/dist/index-b56ew9aF.d.ts +107 -0
  40. package/dist/index.d.ts +26 -43
  41. package/dist/index.js +35 -472
  42. package/dist/markdown-BprL96Gl.js +45 -0
  43. package/dist/markdown.d.ts +3 -18
  44. package/dist/markdown.js +3 -15
  45. package/dist/message-vhUI0c5G.d.ts +16 -0
  46. package/dist/nav.d.ts +6 -8
  47. package/dist/nav.js +29 -11
  48. package/dist/openui-artifact-renderer-D3E5bIAI.d.ts +114 -0
  49. package/dist/openui-artifact-renderer-DT4xbvWt.js +266 -0
  50. package/dist/openui.d.ts +2 -115
  51. package/dist/openui.js +2 -13
  52. package/dist/parts-5mhy9yJ3.d.ts +37 -0
  53. package/dist/primitives-DE-blUz-.js +1239 -0
  54. package/dist/primitives.d.ts +5 -525
  55. package/dist/primitives.js +9 -212
  56. package/dist/redaction-CGGB2ENG.js +74 -0
  57. package/dist/redaction.d.ts +2 -42
  58. package/dist/redaction.js +2 -7
  59. package/dist/run-OyWmIDqu.d.ts +41 -0
  60. package/dist/run-ZsIKPA6J.js +17 -0
  61. package/dist/run-group-D1InSdQu.js +410 -0
  62. package/dist/run.d.ts +3 -126
  63. package/dist/run.js +5 -40
  64. package/dist/sdk-hooks.d.ts +2 -285
  65. package/dist/sdk-hooks.js +3 -36
  66. package/dist/stores.d.ts +13 -14
  67. package/dist/stores.js +34 -76
  68. package/dist/table-DHyqDPbU.js +146 -0
  69. package/dist/tabs-ujuqAdtb.js +40 -0
  70. package/dist/text-shimmer-BUUo6I-g.js +64 -0
  71. package/dist/tool-call-feed-BeB1_4pX.d.ts +47 -0
  72. package/dist/tool-call-feed-C1W1N54c.js +109 -0
  73. package/dist/tool-call-step-Bi3_YJRV.js +434 -0
  74. package/dist/tool-display-BAuAVa43.js +158 -0
  75. package/dist/{tool-display-z4JcDmMQ.d.ts → tool-display-DgmL5rIU.d.ts} +16 -16
  76. package/dist/tool-previews.d.ts +2 -48
  77. package/dist/tool-previews.js +2 -23
  78. package/dist/types.d.ts +6 -19
  79. package/dist/types.js +0 -1
  80. package/dist/use-auto-scroll-C5Pjeqon.js +153 -0
  81. package/dist/use-sse-stream-BjVBDbxK.js +884 -0
  82. package/dist/use-sse-stream-Dm6R5YWz.d.ts +282 -0
  83. package/dist/utils-Bl_CZ0Qp.js +37 -0
  84. package/dist/{chunk-RQHJBTEU.js → utils-C_uf36nf.js} +4 -6
  85. package/dist/utils.d.ts +2 -104
  86. package/dist/utils.js +6 -44
  87. package/package.json +39 -41
  88. package/dist/artifact-pane-DpuWcAiF.d.ts +0 -33
  89. package/dist/button-CMQuQEW_.d.ts +0 -17
  90. package/dist/chunk-34A66VBG.js +0 -214
  91. package/dist/chunk-3OI2QKFD.js +0 -0
  92. package/dist/chunk-3XXBZL53.js +0 -174
  93. package/dist/chunk-42PAH5D2.js +0 -112
  94. package/dist/chunk-4CLN43XT.js +0 -45
  95. package/dist/chunk-55WHV7SS.js +0 -1604
  96. package/dist/chunk-565EATZZ.js +0 -156
  97. package/dist/chunk-5Z5ZYMOJ.js +0 -0
  98. package/dist/chunk-6BGQA4BQ.js +0 -0
  99. package/dist/chunk-BEBXZPHW.js +0 -299
  100. package/dist/chunk-C5WF4WMV.js +0 -734
  101. package/dist/chunk-HFL6R6IF.js +0 -37
  102. package/dist/chunk-HGML45QH.js +0 -104
  103. package/dist/chunk-HMAPIH7L.js +0 -595
  104. package/dist/chunk-K5XFRUS4.js +0 -1401
  105. package/dist/chunk-KFQGHD73.js +0 -198
  106. package/dist/chunk-L57WRIND.js +0 -59
  107. package/dist/chunk-LTEKI7YJ.js +0 -59
  108. package/dist/chunk-M3QZK62R.js +0 -233
  109. package/dist/chunk-ND3ZFXQK.js +0 -179
  110. package/dist/chunk-OEX7NZE3.js +0 -321
  111. package/dist/chunk-OL5GYLHV.js +0 -60
  112. package/dist/chunk-QGFYBNSO.js +0 -133
  113. package/dist/chunk-R7B3UWPF.js +0 -550
  114. package/dist/chunk-R7SUY4E3.js +0 -65
  115. package/dist/chunk-REJESC5U.js +0 -117
  116. package/dist/chunk-RQGKSCEZ.js +0 -0
  117. package/dist/chunk-SNLR2AEA.js +0 -40
  118. package/dist/chunk-WKWBTL2V.js +0 -15
  119. package/dist/chunk-X7CU776B.js +0 -1048
  120. package/dist/chunk-XU3HB5QL.js +0 -127
  121. package/dist/chunk-YTO5V6QS.js +0 -19
  122. package/dist/chunk-YU4E5J2N.js +0 -437
  123. package/dist/chunk-YZ6AK25N.js +0 -886
  124. package/dist/code-block-0kSpWMnf.d.ts +0 -25
  125. package/dist/document-editor-pane-IAEQn_Dl.d.ts +0 -128
  126. package/dist/document-editor-pane-QHDOBA43.js +0 -13
  127. package/dist/message-BHWbxBtT.d.ts +0 -15
  128. package/dist/parts-dj7AcUg0.d.ts +0 -36
  129. package/dist/run-PfLmDAox.d.ts +0 -41
  130. package/dist/tool-call-feed-D9iofJgW.d.ts +0 -46
@@ -1,1401 +0,0 @@
1
- import {
2
- Tabs,
3
- TabsContent,
4
- TabsList,
5
- TabsTrigger
6
- } from "./chunk-R7SUY4E3.js";
7
- import {
8
- ArtifactPane
9
- } from "./chunk-LTEKI7YJ.js";
10
- import {
11
- Markdown
12
- } from "./chunk-OL5GYLHV.js";
13
- import {
14
- focusRing
15
- } from "./chunk-WKWBTL2V.js";
16
- import {
17
- cn
18
- } from "./chunk-RQHJBTEU.js";
19
-
20
- // src/editor/document-editor-pane.tsx
21
- import { useEffect as useEffect5, useMemo as useMemo4, useState as useState3 } from "react";
22
- import { PencilLine, Save, Users, Wifi, WifiOff } from "lucide-react";
23
-
24
- // src/editor/tiptap-editor.tsx
25
- import { Suspense as Suspense2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
26
-
27
- // src/editor/editor-provider.tsx
28
- import {
29
- createContext,
30
- Suspense,
31
- useCallback,
32
- useContext,
33
- useEffect,
34
- useMemo,
35
- useRef,
36
- useState
37
- } from "react";
38
-
39
- // src/editor/editor-lazy.ts
40
- import { lazy } from "react";
41
-
42
- // src/editor/editor-peers.ts
43
- var DOCUMENT_PEERS_MISSING = "@tangle-network/ui/editor needs its optional editor peers. Install @tiptap/react and @tiptap/starter-kit.";
44
- var PROVIDER_PEERS_MISSING = "@tangle-network/ui/editor needs its optional collaboration transport peers. Install @hocuspocus/provider and yjs.";
45
- var COLLABORATION_PEERS_MISSING = "@tangle-network/ui/editor needs its optional collaboration peers. Install @tiptap/react, @tiptap/starter-kit, @tiptap/extension-collaboration, @tiptap/extension-collaboration-caret, @hocuspocus/provider and yjs.";
46
- var MissingEditorPeersError = class extends Error {
47
- constructor(message, options) {
48
- super(message, options);
49
- this.name = "MissingEditorPeersError";
50
- }
51
- };
52
- function isMissingEditorPeersError(error) {
53
- return error instanceof Error && error.name === "MissingEditorPeersError";
54
- }
55
- var RESOLUTION_FAILURE = /could not resolve|cannot find (?:module|package)|can't resolve|failed to resolve|module not found/i;
56
- function isMissingPeerError(error) {
57
- return error instanceof Error && RESOLUTION_FAILURE.test(error.message);
58
- }
59
- function rethrow(error) {
60
- throw error;
61
- }
62
- var DEFERRED_PEERS = [
63
- "@tiptap/core",
64
- "@tiptap/react",
65
- "@tiptap/starter-kit",
66
- "@tiptap/extension-collaboration",
67
- "@tiptap/extension-collaboration-caret",
68
- "@hocuspocus/provider",
69
- "yjs"
70
- ];
71
- function unresolvedPeersFrom(error) {
72
- if (!(error instanceof Error)) return [];
73
- const named = DEFERRED_PEERS.filter((name) => error.message.includes(name));
74
- return named.filter(
75
- (name) => !named.some((other) => other !== name && other.includes(name))
76
- );
77
- }
78
- function asMissingEditorPeersError(error, missingMessage) {
79
- if (!isMissingPeerError(error)) return error;
80
- const unresolved = unresolvedPeersFrom(error);
81
- if (unresolved.length === 0) return error;
82
- const detail = unresolved.length === 1 ? ` ${unresolved[0]} did not resolve.` : "";
83
- return new MissingEditorPeersError(missingMessage + detail, { cause: error });
84
- }
85
- async function loadPeers(load, missingMessage) {
86
- try {
87
- return await load();
88
- } catch (error) {
89
- throw asMissingEditorPeersError(error, missingMessage);
90
- }
91
- }
92
- function isConfigurableExtension(value) {
93
- return typeof value?.configure === "function";
94
- }
95
- function assertDocumentEditorPeers(peers, missingMessage) {
96
- if (typeof peers.react.useEditor !== "function" || peers.react.EditorContent === void 0 || !isConfigurableExtension(peers.starterKit.default)) {
97
- throw new MissingEditorPeersError(missingMessage);
98
- }
99
- }
100
- function assertEditorProviderPeers(peers, missingMessage) {
101
- if (typeof peers.hocuspocus.HocuspocusProvider !== "function" || typeof peers.yjs.Doc !== "function") {
102
- throw new MissingEditorPeersError(missingMessage);
103
- }
104
- }
105
- function assertCollaborationPeers(peers) {
106
- assertDocumentEditorPeers(peers, COLLABORATION_PEERS_MISSING);
107
- assertEditorProviderPeers(peers, COLLABORATION_PEERS_MISSING);
108
- if (!isConfigurableExtension(peers.collaboration.default) || !isConfigurableExtension(peers.collaborationCaret.default)) {
109
- throw new MissingEditorPeersError(COLLABORATION_PEERS_MISSING);
110
- }
111
- }
112
- async function importDocumentEditorPeers() {
113
- const [react, starterKit] = await Promise.all([
114
- import("@tiptap/react").catch(rethrow),
115
- import("@tiptap/starter-kit").catch(rethrow)
116
- ]);
117
- return { react, starterKit };
118
- }
119
- async function importEditorProviderPeers() {
120
- const [hocuspocus, yjs] = await Promise.all([
121
- import("@hocuspocus/provider").catch(rethrow),
122
- import("yjs").catch(rethrow)
123
- ]);
124
- return { hocuspocus, yjs };
125
- }
126
- async function loadEditorProviderPeers() {
127
- const peers = await loadPeers(importEditorProviderPeers, PROVIDER_PEERS_MISSING);
128
- assertEditorProviderPeers(peers, PROVIDER_PEERS_MISSING);
129
- return peers;
130
- }
131
- async function loadDocumentEditorPeers() {
132
- const peers = await loadPeers(importDocumentEditorPeers, DOCUMENT_PEERS_MISSING);
133
- assertDocumentEditorPeers(peers, DOCUMENT_PEERS_MISSING);
134
- return peers;
135
- }
136
- async function loadCollaborationPeers() {
137
- const peers = await loadPeers(async () => {
138
- const [documentPeers, providerPeers, collaboration, collaborationCaret] = await Promise.all([
139
- importDocumentEditorPeers(),
140
- importEditorProviderPeers(),
141
- import("@tiptap/extension-collaboration").catch(rethrow),
142
- import("@tiptap/extension-collaboration-caret").catch(rethrow)
143
- ]);
144
- return { ...documentPeers, ...providerPeers, collaboration, collaborationCaret };
145
- }, COLLABORATION_PEERS_MISSING);
146
- assertCollaborationPeers(peers);
147
- return peers;
148
- }
149
-
150
- // src/editor/editor-lazy.ts
151
- function retryableLazyEditor(loadComponent) {
152
- function build() {
153
- return lazy(async () => {
154
- try {
155
- return { default: await loadComponent() };
156
- } catch (error) {
157
- if (!isMissingEditorPeersError(error)) {
158
- current = build();
159
- }
160
- throw error;
161
- }
162
- });
163
- }
164
- let current = build();
165
- return () => current;
166
- }
167
-
168
- // src/editor/editor-provider.tsx
169
- import { jsx } from "react/jsx-runtime";
170
- var EditorContext = createContext(null);
171
- function generateUserColor() {
172
- const colors = [
173
- "#FF6B6B",
174
- // Red
175
- "#4ECDC4",
176
- // Teal
177
- "#45B7D1",
178
- // Blue
179
- "#96CEB4",
180
- // Green
181
- "#FFEAA7",
182
- // Yellow
183
- "#DDA0DD",
184
- // Plum
185
- "#98D8C8",
186
- // Mint
187
- "#F7DC6F",
188
- // Gold
189
- "#BB8FCE",
190
- // Purple
191
- "#85C1E9"
192
- // Sky
193
- ];
194
- return colors[Math.floor(Math.random() * colors.length)];
195
- }
196
- function createEditorProvider(peers) {
197
- const { Doc } = peers.yjs;
198
- const { HocuspocusProvider } = peers.hocuspocus;
199
- return function EditorProvider2({
200
- websocketUrl,
201
- documentName,
202
- token,
203
- tokenExpiresAt,
204
- user,
205
- autoConnect = true,
206
- autoReconnect = true,
207
- maxReconnectAttempts = 5,
208
- onConnectionChange,
209
- onSync,
210
- onAuthError,
211
- onRefreshToken,
212
- children
213
- }) {
214
- const [connectionState, setConnectionState] = useState("disconnected");
215
- const [collaborators, setCollaborators] = useState([]);
216
- const [isSynced, setIsSynced] = useState(false);
217
- const docRef = useRef(null);
218
- const providerRef = useRef(null);
219
- const reconnectAttemptsRef = useRef(0);
220
- const tokenRef = useRef(token);
221
- const tokenExpiryRef = useRef(tokenExpiresAt);
222
- const refreshPromiseRef = useRef(null);
223
- const refreshTimerRef = useRef(null);
224
- tokenRef.current = token;
225
- tokenExpiryRef.current = tokenExpiresAt;
226
- if (!docRef.current) {
227
- docRef.current = new Doc();
228
- }
229
- const doc = docRef.current;
230
- const userColor = useMemo(
231
- () => user.color ?? generateUserColor(),
232
- [user.color]
233
- );
234
- const updateConnectionState = useCallback(
235
- (state) => {
236
- setConnectionState(state);
237
- onConnectionChange?.(state);
238
- },
239
- [onConnectionChange]
240
- );
241
- const updateCollaborators = useCallback(
242
- (awareness) => {
243
- if (!awareness) return;
244
- const states = awareness.getStates();
245
- const collabs = [];
246
- states.forEach((state, clientId) => {
247
- if (clientId === awareness.clientID) return;
248
- if (state.user) {
249
- collabs.push({
250
- clientId,
251
- user: state.user
252
- });
253
- }
254
- });
255
- setCollaborators(collabs);
256
- },
257
- []
258
- );
259
- const clearRefreshTimer = useCallback(() => {
260
- if (refreshTimerRef.current != null) {
261
- window.clearTimeout(refreshTimerRef.current);
262
- refreshTimerRef.current = null;
263
- }
264
- }, []);
265
- const refreshToken = useCallback(async () => {
266
- if (!onRefreshToken) {
267
- return null;
268
- }
269
- if (refreshPromiseRef.current) {
270
- return refreshPromiseRef.current;
271
- }
272
- const refreshPromise = (async () => {
273
- const next = await onRefreshToken();
274
- const resolvedToken = typeof next === "string" ? next : next.token;
275
- const resolvedExpiry = typeof next === "string" ? void 0 : next.expiresAt;
276
- tokenRef.current = resolvedToken;
277
- tokenExpiryRef.current = resolvedExpiry;
278
- return resolvedToken;
279
- })().catch((error) => {
280
- onAuthError?.(
281
- error instanceof Error ? error : new Error(String(error))
282
- );
283
- return null;
284
- }).finally(() => {
285
- refreshPromiseRef.current = null;
286
- });
287
- refreshPromiseRef.current = refreshPromise;
288
- return refreshPromise;
289
- }, [onAuthError, onRefreshToken]);
290
- const scheduleTokenRefresh = useCallback(() => {
291
- clearRefreshTimer();
292
- if (!tokenExpiryRef.current || !onRefreshToken || typeof window === "undefined") {
293
- return;
294
- }
295
- const refreshAtMs = tokenExpiryRef.current * 1e3 - 6e4;
296
- const delay = refreshAtMs - Date.now();
297
- if (delay <= 0) {
298
- void refreshToken();
299
- return;
300
- }
301
- refreshTimerRef.current = window.setTimeout(() => {
302
- void refreshToken();
303
- }, delay);
304
- }, [clearRefreshTimer, onRefreshToken, refreshToken]);
305
- const connect = useCallback(() => {
306
- if (providerRef.current) {
307
- providerRef.current.connect();
308
- return;
309
- }
310
- updateConnectionState("connecting");
311
- const provider = new HocuspocusProvider({
312
- url: websocketUrl,
313
- name: documentName,
314
- document: doc,
315
- token: async () => tokenRef.current,
316
- onConnect: () => {
317
- reconnectAttemptsRef.current = 0;
318
- updateConnectionState("connected");
319
- scheduleTokenRefresh();
320
- },
321
- onSynced: () => {
322
- setIsSynced(true);
323
- updateConnectionState("synced");
324
- onSync?.();
325
- },
326
- onDisconnect: () => {
327
- updateConnectionState("disconnected");
328
- setIsSynced(false);
329
- clearRefreshTimer();
330
- if (autoReconnect && reconnectAttemptsRef.current < maxReconnectAttempts) {
331
- reconnectAttemptsRef.current += 1;
332
- const delay = Math.min(
333
- 1e3 * 2 ** reconnectAttemptsRef.current,
334
- 3e4
335
- );
336
- setTimeout(() => {
337
- if (providerRef.current && !providerRef.current.isConnected) {
338
- providerRef.current.connect();
339
- }
340
- }, delay);
341
- }
342
- },
343
- onAuthenticationFailed: ({ reason }) => {
344
- const error = new Error(reason ?? "Authentication failed");
345
- updateConnectionState("disconnected");
346
- clearRefreshTimer();
347
- if (onRefreshToken) {
348
- void refreshToken().then((nextToken) => {
349
- if (nextToken && providerRef.current) {
350
- providerRef.current.connect();
351
- return;
352
- }
353
- onAuthError?.(error);
354
- });
355
- return;
356
- }
357
- onAuthError?.(error);
358
- },
359
- onAwarenessUpdate: () => {
360
- updateCollaborators(provider.awareness);
361
- }
362
- });
363
- provider.awareness?.setLocalStateField("user", {
364
- name: user.name,
365
- color: userColor,
366
- userId: user.userId
367
- });
368
- providerRef.current = provider;
369
- }, [
370
- websocketUrl,
371
- documentName,
372
- doc,
373
- user.name,
374
- user.userId,
375
- userColor,
376
- autoReconnect,
377
- maxReconnectAttempts,
378
- clearRefreshTimer,
379
- updateConnectionState,
380
- updateCollaborators,
381
- onSync,
382
- onAuthError,
383
- onRefreshToken,
384
- refreshToken,
385
- scheduleTokenRefresh
386
- ]);
387
- const disconnect = useCallback(() => {
388
- if (providerRef.current) {
389
- providerRef.current.disconnect();
390
- updateConnectionState("disconnected");
391
- }
392
- }, [updateConnectionState]);
393
- useEffect(() => {
394
- if (autoConnect) {
395
- connect();
396
- }
397
- return () => {
398
- clearRefreshTimer();
399
- if (providerRef.current) {
400
- providerRef.current.destroy();
401
- providerRef.current = null;
402
- }
403
- };
404
- }, [autoConnect, clearRefreshTimer, connect]);
405
- const contextValue = useMemo(
406
- () => ({
407
- doc,
408
- provider: providerRef.current,
409
- connectionState,
410
- collaborators,
411
- isSynced,
412
- connect,
413
- disconnect
414
- }),
415
- [doc, connectionState, collaborators, isSynced, connect, disconnect]
416
- );
417
- return /* @__PURE__ */ jsx(EditorContext.Provider, { value: contextValue, children });
418
- };
419
- }
420
- var lazyEditorProvider = retryableLazyEditor(
421
- async () => createEditorProvider(await loadEditorProviderPeers())
422
- );
423
- function EditorProvider(props) {
424
- const LazyEditorProvider = lazyEditorProvider();
425
- return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(LazyEditorProvider, { ...props }) });
426
- }
427
- function useEditorContext() {
428
- const context = useContext(EditorContext);
429
- if (!context) {
430
- throw new Error("useEditorContext must be used within an EditorProvider");
431
- }
432
- return context;
433
- }
434
-
435
- // src/editor/editor-loading.tsx
436
- import { jsx as jsx2 } from "react/jsx-runtime";
437
- function EditorLoadingPlaceholder({ className }) {
438
- return /* @__PURE__ */ jsx2(
439
- "div",
440
- {
441
- role: "status",
442
- "aria-live": "polite",
443
- className: cn(
444
- "flex w-full items-center justify-center rounded-lg border border-border border-dashed bg-muted text-muted-foreground text-sm",
445
- className
446
- ),
447
- children: "Loading editor\u2026"
448
- }
449
- );
450
- }
451
-
452
- // src/editor/editor-toolbar.tsx
453
- import { jsx as jsx3 } from "react/jsx-runtime";
454
- function EditorToolbar({
455
- editor,
456
- className
457
- }) {
458
- if (!editor) {
459
- return null;
460
- }
461
- const buttons = [
462
- {
463
- id: "bold",
464
- label: "Bold",
465
- action: () => editor.chain().focus().toggleBold().run(),
466
- isActive: editor.isActive("bold"),
467
- shortcut: "Ctrl+B"
468
- },
469
- {
470
- id: "italic",
471
- label: "Italic",
472
- action: () => editor.chain().focus().toggleItalic().run(),
473
- isActive: editor.isActive("italic"),
474
- shortcut: "Ctrl+I"
475
- },
476
- {
477
- id: "strike",
478
- label: "Strike",
479
- action: () => editor.chain().focus().toggleStrike().run(),
480
- isActive: editor.isActive("strike"),
481
- shortcut: "Ctrl+Shift+X"
482
- },
483
- {
484
- id: "code",
485
- label: "Code",
486
- action: () => editor.chain().focus().toggleCode().run(),
487
- isActive: editor.isActive("code"),
488
- shortcut: "Ctrl+E"
489
- },
490
- { id: "sep-1", type: "separator" },
491
- {
492
- id: "h1",
493
- label: "H1",
494
- action: () => editor.chain().focus().toggleHeading({ level: 1 }).run(),
495
- isActive: editor.isActive("heading", { level: 1 })
496
- },
497
- {
498
- id: "h2",
499
- label: "H2",
500
- action: () => editor.chain().focus().toggleHeading({ level: 2 }).run(),
501
- isActive: editor.isActive("heading", { level: 2 })
502
- },
503
- {
504
- id: "h3",
505
- label: "H3",
506
- action: () => editor.chain().focus().toggleHeading({ level: 3 }).run(),
507
- isActive: editor.isActive("heading", { level: 3 })
508
- },
509
- { id: "sep-2", type: "separator" },
510
- {
511
- id: "bullet-list",
512
- label: "Bullet List",
513
- action: () => editor.chain().focus().toggleBulletList().run(),
514
- isActive: editor.isActive("bulletList")
515
- },
516
- {
517
- id: "ordered-list",
518
- label: "Ordered List",
519
- action: () => editor.chain().focus().toggleOrderedList().run(),
520
- isActive: editor.isActive("orderedList")
521
- },
522
- {
523
- id: "code-block",
524
- label: "Code Block",
525
- action: () => editor.chain().focus().toggleCodeBlock().run(),
526
- isActive: editor.isActive("codeBlock")
527
- },
528
- {
529
- id: "blockquote",
530
- label: "Blockquote",
531
- action: () => editor.chain().focus().toggleBlockquote().run(),
532
- isActive: editor.isActive("blockquote")
533
- }
534
- ];
535
- return /* @__PURE__ */ jsx3(
536
- "div",
537
- {
538
- className: cn(
539
- "flex items-center gap-1 border-border border-b bg-card p-2",
540
- className
541
- ),
542
- children: buttons.map((button) => {
543
- if ("type" in button && button.type === "separator") {
544
- return /* @__PURE__ */ jsx3("div", { className: "mx-1 h-6 w-px bg-border" }, button.id);
545
- }
546
- return /* @__PURE__ */ jsx3(
547
- "button",
548
- {
549
- onClick: button.action,
550
- type: "button",
551
- title: "shortcut" in button ? `${button.label} (${button.shortcut})` : button.label,
552
- className: cn(
553
- "rounded px-2 py-1 font-medium text-xs transition-colors",
554
- "hover:bg-accent hover:text-accent-foreground",
555
- button.isActive && "bg-accent text-accent-foreground"
556
- ),
557
- children: button.label
558
- },
559
- button.id
560
- );
561
- })
562
- }
563
- );
564
- }
565
-
566
- // src/editor/tiptap-editor.tsx
567
- import { jsx as jsx4, jsxs } from "react/jsx-runtime";
568
- var cursorColors = {
569
- "#FF6B6B": { background: "#FF6B6B", text: "#FFFFFF" },
570
- "#4ECDC4": { background: "#4ECDC4", text: "#000000" },
571
- "#45B7D1": { background: "#45B7D1", text: "#000000" },
572
- "#96CEB4": { background: "#96CEB4", text: "#000000" },
573
- "#FFEAA7": { background: "#FFEAA7", text: "#000000" },
574
- "#DDA0DD": { background: "#DDA0DD", text: "#000000" },
575
- "#98D8C8": { background: "#98D8C8", text: "#000000" },
576
- "#F7DC6F": { background: "#F7DC6F", text: "#000000" },
577
- "#BB8FCE": { background: "#BB8FCE", text: "#000000" },
578
- "#85C1E9": { background: "#85C1E9", text: "#000000" }
579
- };
580
- function getCursorColors(color) {
581
- return cursorColors[color] ?? { background: color, text: "#FFFFFF" };
582
- }
583
- function createTiptapEditor(peers) {
584
- const { EditorContent, useEditor } = peers.react;
585
- const StarterKit = peers.starterKit.default;
586
- const Collaboration = peers.collaboration.default;
587
- const CollaborationCaret = peers.collaborationCaret.default;
588
- return function TiptapEditor2({
589
- initialContent,
590
- placeholder = "Start writing...",
591
- readOnly = false,
592
- autoFocus = false,
593
- className,
594
- contentClassName,
595
- onUpdate,
596
- onSelectionUpdate,
597
- onReady
598
- }) {
599
- const { doc, provider, connectionState } = useEditorContext();
600
- const fragment = useMemo2(() => doc.getXmlFragment("prosemirror"), [doc]);
601
- const extensions = useMemo2(() => {
602
- const baseExtensions = [
603
- StarterKit.configure({
604
- // Disable history - Y.js handles undo/redo
605
- ...{ history: false },
606
- // Configure code block for syntax highlighting placeholder
607
- codeBlock: {
608
- HTMLAttributes: {
609
- class: "hljs"
610
- }
611
- }
612
- }),
613
- Collaboration.configure({
614
- fragment
615
- })
616
- ];
617
- if (provider?.awareness) {
618
- baseExtensions.push(
619
- CollaborationCaret.configure({
620
- provider,
621
- user: provider.awareness.getLocalState()?.user ?? {
622
- name: "Anonymous",
623
- color: "#808080"
624
- },
625
- render: (user) => {
626
- const { background, text } = getCursorColors(user.color);
627
- const cursor = document.createElement("span");
628
- cursor.className = "collaboration-cursor";
629
- cursor.style.borderColor = background;
630
- const label = document.createElement("span");
631
- label.className = "collaboration-cursor-label";
632
- label.style.backgroundColor = background;
633
- label.style.color = text;
634
- label.textContent = user.name;
635
- cursor.appendChild(label);
636
- return cursor;
637
- }
638
- })
639
- );
640
- }
641
- return baseExtensions;
642
- }, [fragment, provider]);
643
- const editor = useEditor({
644
- extensions,
645
- editable: !readOnly,
646
- autofocus: autoFocus,
647
- editorProps: {
648
- attributes: {
649
- class: cn(
650
- "prose prose-sm sm:prose-base dark:prose-invert max-w-none",
651
- "focus:outline-none",
652
- contentClassName
653
- ),
654
- "data-placeholder": placeholder
655
- }
656
- },
657
- onUpdate: ({ editor: ed }) => {
658
- onUpdate?.(ed);
659
- },
660
- onSelectionUpdate: ({ editor: ed }) => {
661
- onSelectionUpdate?.(ed);
662
- },
663
- onCreate: ({ editor: ed }) => {
664
- onReady?.(ed);
665
- }
666
- });
667
- useEffect2(() => {
668
- if (editor) {
669
- editor.setEditable(!readOnly);
670
- }
671
- }, [editor, readOnly]);
672
- useEffect2(() => {
673
- if (editor && initialContent && connectionState === "synced" && editor.isEmpty) {
674
- editor.commands.setContent(initialContent);
675
- }
676
- }, [editor, initialContent, connectionState]);
677
- return /* @__PURE__ */ jsxs(
678
- "div",
679
- {
680
- className: cn(
681
- "relative min-h-[200px] w-full rounded-lg border border-border",
682
- "bg-background",
683
- className
684
- ),
685
- children: [
686
- /* @__PURE__ */ jsx4("div", { className: "absolute top-2 right-2 z-10", children: /* @__PURE__ */ jsx4(ConnectionIndicator, { state: connectionState }) }),
687
- /* @__PURE__ */ jsx4("div", { className: "p-4 pt-10", children: /* @__PURE__ */ jsx4(EditorContent, { editor }) }),
688
- /* @__PURE__ */ jsx4("style", { children: `
689
- .ProseMirror p.is-editor-empty:first-child::before {
690
- content: attr(data-placeholder);
691
- float: left;
692
- color: var(--muted-foreground, #999);
693
- pointer-events: none;
694
- height: 0;
695
- }
696
-
697
- .collaboration-cursor {
698
- position: relative;
699
- border-left: 2px solid;
700
- margin-left: -1px;
701
- margin-right: -1px;
702
- pointer-events: none;
703
- word-break: normal;
704
- }
705
-
706
- .collaboration-cursor-label {
707
- position: absolute;
708
- top: -1.4em;
709
- left: -1px;
710
- font-size: 12px;
711
- font-style: normal;
712
- font-weight: 600;
713
- line-height: normal;
714
- padding: 2px 6px;
715
- border-radius: 4px 4px 4px 0;
716
- white-space: nowrap;
717
- user-select: none;
718
- }
719
-
720
- .ProseMirror pre {
721
- background: var(--muted, #f4f4f5);
722
- border-radius: 0.375rem;
723
- padding: 0.75rem 1rem;
724
- font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
725
- font-size: 0.875rem;
726
- overflow-x: auto;
727
- }
728
-
729
- .dark .ProseMirror pre {
730
- background: var(--muted, #27272a);
731
- }
732
-
733
- .ProseMirror code {
734
- background: var(--muted, #f4f4f5);
735
- border-radius: 0.25rem;
736
- padding: 0.125rem 0.25rem;
737
- font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
738
- font-size: 0.875em;
739
- }
740
-
741
- .dark .ProseMirror code {
742
- background: var(--muted, #27272a);
743
- }
744
-
745
- .ProseMirror pre code {
746
- background: transparent;
747
- padding: 0;
748
- font-size: inherit;
749
- }
750
- ` })
751
- ]
752
- }
753
- );
754
- };
755
- }
756
- var lazyTiptapEditor = retryableLazyEditor(
757
- async () => createTiptapEditor(await loadCollaborationPeers())
758
- );
759
- function TiptapEditor(props) {
760
- const LazyTiptapEditor = lazyTiptapEditor();
761
- return /* @__PURE__ */ jsx4(
762
- Suspense2,
763
- {
764
- fallback: /* @__PURE__ */ jsx4(EditorLoadingPlaceholder, { className: cn("min-h-[200px]", props.className) }),
765
- children: /* @__PURE__ */ jsx4(LazyTiptapEditor, { ...props })
766
- }
767
- );
768
- }
769
- function ConnectionIndicator({
770
- state
771
- }) {
772
- const config = {
773
- disconnected: {
774
- color: "bg-red-500",
775
- label: "Disconnected"
776
- },
777
- connecting: {
778
- color: "bg-yellow-500 animate-pulse",
779
- label: "Connecting..."
780
- },
781
- connected: {
782
- color: "bg-blue-500",
783
- label: "Connected"
784
- },
785
- synced: {
786
- color: "bg-green-500",
787
- label: "Synced"
788
- }
789
- }[state];
790
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-muted-foreground text-xs", children: [
791
- /* @__PURE__ */ jsx4("span", { className: cn("h-2 w-2 rounded-full", config.color) }),
792
- /* @__PURE__ */ jsx4("span", { children: config.label })
793
- ] });
794
- }
795
- function CollaboratorsList({
796
- collaborators,
797
- className
798
- }) {
799
- if (collaborators.length === 0) {
800
- return null;
801
- }
802
- return /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-1", className), children: [
803
- collaborators.slice(0, 5).map((collab) => /* @__PURE__ */ jsx4(
804
- "div",
805
- {
806
- className: "flex h-6 w-6 items-center justify-center rounded-full font-medium text-xs",
807
- style: { backgroundColor: collab.user.color },
808
- title: collab.user.name,
809
- children: collab.user.name.charAt(0).toUpperCase()
810
- },
811
- collab.clientId
812
- )),
813
- collaborators.length > 5 && /* @__PURE__ */ jsxs("div", { className: "flex h-6 w-6 items-center justify-center rounded-full bg-muted font-medium text-xs", children: [
814
- "+",
815
- collaborators.length - 5
816
- ] })
817
- ] });
818
- }
819
-
820
- // src/editor/markdown-document-editor.tsx
821
- import { Suspense as Suspense3, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef2 } from "react";
822
-
823
- // src/editor/markdown-conversion.ts
824
- import { marked } from "marked";
825
- import TurndownService from "turndown";
826
- var turndown = new TurndownService({
827
- bulletListMarker: "-",
828
- codeBlockStyle: "fenced",
829
- emDelimiter: "*",
830
- headingStyle: "atx"
831
- });
832
- function markdownToHtml(markdown) {
833
- return String(marked.parse(markdown, { async: false, gfm: true }));
834
- }
835
- function htmlToMarkdown(html) {
836
- return turndown.turndown(html);
837
- }
838
- function normalizeMarkdown(markdown) {
839
- return markdown.replace(/\r\n/g, "\n").trimEnd();
840
- }
841
-
842
- // src/editor/markdown-document-editor.tsx
843
- import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
844
- function createMarkdownDocumentEditor(peers) {
845
- const { EditorContent, useEditor } = peers.react;
846
- const StarterKit = peers.starterKit.default;
847
- return function MarkdownDocumentEditor2({
848
- value = "",
849
- placeholder = "Start writing...",
850
- readOnly = false,
851
- autoFocus = false,
852
- className,
853
- contentClassName,
854
- onChange,
855
- onReady
856
- }) {
857
- const initialHtml = useMemo3(() => markdownToHtml(value), []);
858
- const lastAppliedMarkdownRef = useRef2(normalizeMarkdown(value));
859
- const editor = useEditor({
860
- extensions: [
861
- StarterKit.configure({
862
- codeBlock: {
863
- HTMLAttributes: {
864
- class: "hljs"
865
- }
866
- }
867
- })
868
- ],
869
- content: initialHtml,
870
- editable: !readOnly,
871
- autofocus: autoFocus,
872
- editorProps: {
873
- attributes: {
874
- class: cn(
875
- "prose prose-sm sm:prose-base max-w-none focus:outline-none",
876
- "prose-headings:text-foreground prose-p:text-foreground prose-li:text-foreground",
877
- "prose-strong:text-foreground prose-code:text-foreground prose-pre:text-foreground",
878
- contentClassName
879
- ),
880
- "data-placeholder": placeholder
881
- }
882
- },
883
- onUpdate: ({ editor: currentEditor }) => {
884
- const nextMarkdown = normalizeMarkdown(htmlToMarkdown(currentEditor.getHTML()));
885
- lastAppliedMarkdownRef.current = nextMarkdown;
886
- onChange?.(nextMarkdown, currentEditor);
887
- },
888
- onCreate: ({ editor: currentEditor }) => {
889
- onReady?.(currentEditor);
890
- }
891
- });
892
- useEffect3(() => {
893
- if (editor) {
894
- editor.setEditable(!readOnly);
895
- }
896
- }, [editor, readOnly]);
897
- useEffect3(() => {
898
- if (!editor) {
899
- return;
900
- }
901
- const normalizedValue = normalizeMarkdown(value);
902
- if (normalizedValue === lastAppliedMarkdownRef.current) {
903
- return;
904
- }
905
- editor.commands.setContent(markdownToHtml(value), { emitUpdate: false });
906
- lastAppliedMarkdownRef.current = normalizedValue;
907
- }, [editor, value]);
908
- return /* @__PURE__ */ jsxs2(
909
- "div",
910
- {
911
- className: cn(
912
- "flex min-h-[14rem] w-full flex-col overflow-hidden rounded-lg border border-border bg-background",
913
- className
914
- ),
915
- children: [
916
- /* @__PURE__ */ jsx5(
917
- EditorToolbar,
918
- {
919
- editor,
920
- className: "border-border bg-card px-2 py-2"
921
- }
922
- ),
923
- /* @__PURE__ */ jsx5("div", { className: "min-h-0 flex-1 overflow-auto px-5 py-4", children: /* @__PURE__ */ jsx5(EditorContent, { editor }) }),
924
- /* @__PURE__ */ jsx5("style", { children: `
925
- .ProseMirror p.is-editor-empty:first-child::before {
926
- content: attr(data-placeholder);
927
- float: left;
928
- color: hsl(var(--muted-foreground));
929
- pointer-events: none;
930
- height: 0;
931
- }
932
-
933
- .ProseMirror pre {
934
- background: hsl(var(--muted));
935
- border: 1px solid hsl(var(--border));
936
- border-radius: 0.75rem;
937
- padding: 0.875rem 1rem;
938
- overflow-x: auto;
939
- }
940
-
941
- .ProseMirror code {
942
- background: hsl(var(--muted));
943
- border-radius: 0.35rem;
944
- padding: 0.12rem 0.3rem;
945
- }
946
-
947
- .ProseMirror pre code {
948
- background: transparent;
949
- padding: 0;
950
- }
951
- ` })
952
- ]
953
- }
954
- );
955
- };
956
- }
957
- var lazyMarkdownDocumentEditor = retryableLazyEditor(
958
- async () => createMarkdownDocumentEditor(await loadDocumentEditorPeers())
959
- );
960
- function MarkdownDocumentEditor(props) {
961
- const LazyMarkdownDocumentEditor = lazyMarkdownDocumentEditor();
962
- return /* @__PURE__ */ jsx5(
963
- Suspense3,
964
- {
965
- fallback: /* @__PURE__ */ jsx5(EditorLoadingPlaceholder, { className: cn("min-h-[14rem]", props.className) }),
966
- children: /* @__PURE__ */ jsx5(LazyMarkdownDocumentEditor, { ...props })
967
- }
968
- );
969
- }
970
-
971
- // src/editor/use-editor.ts
972
- import { useCallback as useCallback2, useEffect as useEffect4, useState as useState2 } from "react";
973
- function useEditorConnection() {
974
- const { connectionState, isSynced, connect, disconnect } = useEditorContext();
975
- const isConnected = connectionState === "connected" || connectionState === "synced";
976
- const isConnecting = connectionState === "connecting";
977
- const isDisconnected = connectionState === "disconnected";
978
- return {
979
- /** Current connection state string */
980
- state: connectionState,
981
- /** Whether connected to the server (connected or synced) */
982
- isConnected,
983
- /** Whether currently attempting to connect */
984
- isConnecting,
985
- /** Whether disconnected from the server */
986
- isDisconnected,
987
- /** Whether the document is synced with the server */
988
- isSynced,
989
- /** Connect to the collaboration server */
990
- connect,
991
- /** Disconnect from the collaboration server */
992
- disconnect
993
- };
994
- }
995
- function useCollaborators() {
996
- const { collaborators } = useEditorContext();
997
- const count = collaborators.length;
998
- const hasOthers = count > 0;
999
- return {
1000
- /** List of active collaborators (excluding self) */
1001
- collaborators,
1002
- /** Number of other collaborators */
1003
- count,
1004
- /** Whether there are other collaborators present */
1005
- hasOthers
1006
- };
1007
- }
1008
- function useCollaboratorPresence(userId) {
1009
- const { collaborators } = useEditorContext();
1010
- return collaborators.find((c) => c.user.userId === userId) ?? null;
1011
- }
1012
- function useYjsState(key, initialValue) {
1013
- const { doc } = useEditorContext();
1014
- const [value, setLocalValue] = useState2(initialValue);
1015
- const metaMap = doc.getMap("metadata");
1016
- useEffect4(() => {
1017
- const updateValue = () => {
1018
- const stored = metaMap.get(key);
1019
- if (stored !== void 0) {
1020
- setLocalValue(stored);
1021
- }
1022
- };
1023
- updateValue();
1024
- metaMap.observe(updateValue);
1025
- return () => {
1026
- metaMap.unobserve(updateValue);
1027
- };
1028
- }, [metaMap, key]);
1029
- const setValue = useCallback2(
1030
- (newValue) => {
1031
- doc.transact(() => {
1032
- metaMap.set(key, newValue);
1033
- });
1034
- },
1035
- [doc, metaMap, key]
1036
- );
1037
- return [value, setValue];
1038
- }
1039
- function useDocumentChanges(onSave) {
1040
- const { doc } = useEditorContext();
1041
- const [isDirty, setIsDirty] = useState2(false);
1042
- const [isSaving, setIsSaving] = useState2(false);
1043
- const [lastSaved, setLastSaved] = useState2(null);
1044
- useEffect4(() => {
1045
- const handleUpdate = () => {
1046
- setIsDirty(true);
1047
- };
1048
- doc.on("update", handleUpdate);
1049
- return () => {
1050
- doc.off("update", handleUpdate);
1051
- };
1052
- }, [doc]);
1053
- const save = useCallback2(async () => {
1054
- if (!onSave || isSaving) return;
1055
- setIsSaving(true);
1056
- try {
1057
- await onSave();
1058
- setIsDirty(false);
1059
- setLastSaved(/* @__PURE__ */ new Date());
1060
- } finally {
1061
- setIsSaving(false);
1062
- }
1063
- }, [onSave, isSaving]);
1064
- return {
1065
- /** Whether there are unsaved changes */
1066
- isDirty,
1067
- /** Whether save is in progress */
1068
- isSaving,
1069
- /** When the document was last saved */
1070
- lastSaved,
1071
- /** Save the document */
1072
- save
1073
- };
1074
- }
1075
- function useAwareness() {
1076
- const { provider } = useEditorContext();
1077
- const [localState, setLocalStateValue] = useState2(
1078
- {}
1079
- );
1080
- const awareness = provider?.awareness;
1081
- useEffect4(() => {
1082
- if (!awareness) return;
1083
- const updateState = () => {
1084
- setLocalStateValue(awareness.getLocalState() ?? {});
1085
- };
1086
- updateState();
1087
- awareness.on("change", updateState);
1088
- return () => {
1089
- awareness.off("change", updateState);
1090
- };
1091
- }, [awareness]);
1092
- const setLocalState = useCallback2(
1093
- (state) => {
1094
- if (!awareness) return;
1095
- const current = awareness.getLocalState() ?? {};
1096
- awareness.setLocalState({ ...current, ...state });
1097
- },
1098
- [awareness]
1099
- );
1100
- const setLocalStateField = useCallback2(
1101
- (field, value) => {
1102
- if (!awareness) return;
1103
- awareness.setLocalStateField(field, value);
1104
- },
1105
- [awareness]
1106
- );
1107
- return {
1108
- /** Current local awareness state */
1109
- localState,
1110
- /** Set the entire local state (merges with existing) */
1111
- setLocalState,
1112
- /** Set a single field in the local state */
1113
- setLocalStateField,
1114
- /** The raw awareness instance */
1115
- awareness
1116
- };
1117
- }
1118
-
1119
- // src/editor/document-editor-pane.tsx
1120
- import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
1121
- function connectionTone(state) {
1122
- switch (state) {
1123
- case "synced":
1124
- return "text-[var(--surface-success-text)] border-[var(--surface-success-border)] bg-[var(--surface-success-bg)]";
1125
- case "connected":
1126
- case "connecting":
1127
- return "text-[var(--surface-info-text)] border-[var(--surface-info-border)] bg-[var(--surface-info-bg)]";
1128
- case "disconnected":
1129
- default:
1130
- return "text-[var(--surface-warning-text)] border-[var(--surface-warning-border)] bg-[var(--surface-warning-bg)]";
1131
- }
1132
- }
1133
- function connectionLabel(state) {
1134
- switch (state) {
1135
- case "synced":
1136
- return "Live synced";
1137
- case "connected":
1138
- return "Connected";
1139
- case "connecting":
1140
- return "Connecting";
1141
- case "disconnected":
1142
- default:
1143
- return "Offline";
1144
- }
1145
- }
1146
- function connectionDescription(state, collaborators, readOnly) {
1147
- if (readOnly) {
1148
- return state === "disconnected" ? "Live access is paused. You can keep reading while the editor reconnects." : "You are viewing the live document in read-only mode.";
1149
- }
1150
- switch (state) {
1151
- case "synced":
1152
- return collaborators > 0 ? `You and ${collaborators} collaborator${collaborators === 1 ? "" : "s"} are editing the same document.` : "You are editing the live document. Changes sync automatically.";
1153
- case "connected":
1154
- case "connecting":
1155
- return "Connecting the live document. Local edits stay in place while sync catches up.";
1156
- case "disconnected":
1157
- default:
1158
- return "Live updates are paused. You can keep editing and reconnect when the transport is healthy again.";
1159
- }
1160
- }
1161
- function CollaborativeDocumentSurface({
1162
- markdown,
1163
- placeholder,
1164
- autoFocus,
1165
- readOnly,
1166
- className,
1167
- onChange
1168
- }) {
1169
- const { state } = useEditorConnection();
1170
- const { collaborators } = useCollaborators();
1171
- const initialContent = useMemo4(() => markdownToHtml(markdown), [markdown]);
1172
- const collaboratorCount = collaborators.length + 1;
1173
- return /* @__PURE__ */ jsxs3("div", { className: cn("flex h-full min-h-0 flex-col gap-3", className), children: [
1174
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-[var(--radius-lg)] border border-border bg-card px-3 py-2", children: [
1175
- /* @__PURE__ */ jsxs3("div", { className: "min-w-0 space-y-2", children: [
1176
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-2 text-xs text-muted-foreground", children: [
1177
- /* @__PURE__ */ jsxs3(
1178
- "span",
1179
- {
1180
- className: cn(
1181
- "inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 font-medium",
1182
- connectionTone(state)
1183
- ),
1184
- children: [
1185
- state === "disconnected" ? /* @__PURE__ */ jsx6(WifiOff, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx6(Wifi, { className: "h-3.5 w-3.5" }),
1186
- connectionLabel(state)
1187
- ]
1188
- }
1189
- ),
1190
- /* @__PURE__ */ jsxs3("span", { className: "inline-flex items-center gap-1.5 rounded-full border border-border bg-background px-2.5 py-1", children: [
1191
- /* @__PURE__ */ jsx6(Users, { className: "h-3.5 w-3.5" }),
1192
- collaborators.length === 0 ? "Solo editing" : `${collaboratorCount} active`
1193
- ] })
1194
- ] }),
1195
- /* @__PURE__ */ jsx6("p", { className: "text-xs text-muted-foreground", children: connectionDescription(state, collaborators.length, readOnly) })
1196
- ] }),
1197
- /* @__PURE__ */ jsx6(CollaboratorsList, { collaborators })
1198
- ] }),
1199
- /* @__PURE__ */ jsx6(
1200
- TiptapEditor,
1201
- {
1202
- initialContent,
1203
- placeholder,
1204
- autoFocus,
1205
- readOnly,
1206
- className: cn("h-full min-h-[16rem]", className),
1207
- onUpdate: (editor) => {
1208
- onChange?.(normalizeMarkdown(htmlToMarkdown(editor.getHTML())));
1209
- }
1210
- }
1211
- )
1212
- ] });
1213
- }
1214
- function DocumentEditorPane({
1215
- eyebrow,
1216
- title,
1217
- subtitle,
1218
- meta,
1219
- headerActions,
1220
- footer,
1221
- className,
1222
- contentClassName,
1223
- headerClassName,
1224
- hideTitleBlock,
1225
- tabs,
1226
- toolbar,
1227
- markdown = "",
1228
- mode,
1229
- defaultMode = "preview",
1230
- onModeChange,
1231
- backend = "local",
1232
- placeholder = "Start writing...",
1233
- autoFocus = false,
1234
- readOnly = false,
1235
- onChange,
1236
- onSave,
1237
- saving = false,
1238
- saveLabel = "Save changes",
1239
- previewClassName,
1240
- editorClassName,
1241
- collaboration
1242
- }) {
1243
- const [draft, setDraft] = useState3(markdown);
1244
- const [uncontrolledMode, setUncontrolledMode] = useState3(defaultMode);
1245
- const activeMode = mode ?? uncontrolledMode;
1246
- const isCollaborative = backend === "collaborative" && Boolean(collaboration);
1247
- const isDirty = normalizeMarkdown(draft) !== normalizeMarkdown(markdown);
1248
- const saveStateLabel = readOnly ? "Read only" : isCollaborative ? isDirty ? "Snapshot pending" : "Live document current" : isDirty ? "Unsaved changes" : "Saved";
1249
- useEffect5(() => {
1250
- setDraft(markdown);
1251
- }, [markdown]);
1252
- useEffect5(() => {
1253
- if (mode === void 0) {
1254
- setUncontrolledMode(defaultMode);
1255
- }
1256
- }, [defaultMode, mode]);
1257
- const setMode = (nextMode) => {
1258
- if (mode === void 0) {
1259
- setUncontrolledMode(nextMode);
1260
- }
1261
- onModeChange?.(nextMode);
1262
- };
1263
- const handleChange = (nextMarkdown) => {
1264
- setDraft(nextMarkdown);
1265
- onChange?.(nextMarkdown);
1266
- };
1267
- const editorToolbar = /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
1268
- /* @__PURE__ */ jsxs3(
1269
- TabsList,
1270
- {
1271
- variant: "underline",
1272
- className: "h-auto gap-4 border-0 bg-transparent p-0 text-muted-foreground",
1273
- children: [
1274
- /* @__PURE__ */ jsx6(
1275
- TabsTrigger,
1276
- {
1277
- value: "preview",
1278
- variant: "underline",
1279
- className: "pb-2 data-[state=active]:border-primary data-[state=active]:text-foreground",
1280
- children: "Preview"
1281
- }
1282
- ),
1283
- /* @__PURE__ */ jsxs3(
1284
- TabsTrigger,
1285
- {
1286
- value: "edit",
1287
- variant: "underline",
1288
- className: "flex items-center gap-2 pb-2 data-[state=active]:border-primary data-[state=active]:text-foreground",
1289
- children: [
1290
- /* @__PURE__ */ jsx6(PencilLine, { className: "h-3.5 w-3.5" }),
1291
- isCollaborative ? "Live edit" : "Edit"
1292
- ]
1293
- }
1294
- )
1295
- ]
1296
- }
1297
- ),
1298
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-2 text-xs text-muted-foreground", children: [
1299
- toolbar,
1300
- /* @__PURE__ */ jsx6("span", { className: "rounded-full border border-border bg-card px-2.5 py-1 font-medium", children: isCollaborative ? "Live document" : "Local draft" }),
1301
- /* @__PURE__ */ jsx6("span", { className: "rounded-full border border-border bg-background px-2.5 py-1", children: saveStateLabel }),
1302
- onSave && !readOnly && /* @__PURE__ */ jsxs3(
1303
- "button",
1304
- {
1305
- type: "button",
1306
- onClick: () => void onSave(draft),
1307
- disabled: saving || !isDirty,
1308
- className: cn(
1309
- "inline-flex items-center gap-2 rounded-[var(--radius-full)] border border-border bg-card px-3 py-1.5 text-xs font-semibold text-foreground transition-colors hover:border-[var(--border-strong)] hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",
1310
- focusRing
1311
- ),
1312
- children: [
1313
- /* @__PURE__ */ jsx6(Save, { className: "h-3.5 w-3.5" }),
1314
- saving ? "Saving..." : saveLabel
1315
- ]
1316
- }
1317
- )
1318
- ] })
1319
- ] });
1320
- const preview = /* @__PURE__ */ jsx6(
1321
- "div",
1322
- {
1323
- className: cn(
1324
- // The outer margin is the card's gutter (rather than padding on the tab
1325
- // panel) so `previewClassName` can govern the whole box — gutter, border,
1326
- // surface, and inner padding — e.g. to render the document full-bleed.
1327
- "m-4 rounded-[var(--radius-lg)] border border-border bg-card p-5",
1328
- previewClassName
1329
- ),
1330
- children: /* @__PURE__ */ jsx6(Markdown, { children: draft })
1331
- }
1332
- );
1333
- const localEditor = /* @__PURE__ */ jsx6(
1334
- MarkdownDocumentEditor,
1335
- {
1336
- value: draft,
1337
- placeholder,
1338
- autoFocus,
1339
- readOnly,
1340
- onChange: (nextMarkdown) => {
1341
- handleChange(nextMarkdown);
1342
- },
1343
- className: editorClassName
1344
- }
1345
- );
1346
- const collaborativeEditor = collaboration ? /* @__PURE__ */ jsx6(EditorProvider, { ...collaboration, children: /* @__PURE__ */ jsx6(
1347
- CollaborativeDocumentSurface,
1348
- {
1349
- markdown: draft,
1350
- placeholder,
1351
- autoFocus,
1352
- readOnly,
1353
- className: editorClassName,
1354
- onChange: handleChange
1355
- }
1356
- ) }, collaboration.documentName) : localEditor;
1357
- return /* @__PURE__ */ jsx6(
1358
- Tabs,
1359
- {
1360
- value: activeMode,
1361
- onValueChange: (nextValue) => setMode(nextValue),
1362
- className: "h-full",
1363
- children: /* @__PURE__ */ jsxs3(
1364
- ArtifactPane,
1365
- {
1366
- eyebrow,
1367
- title,
1368
- subtitle,
1369
- meta,
1370
- headerActions,
1371
- footer,
1372
- tabs,
1373
- className,
1374
- contentClassName,
1375
- headerClassName,
1376
- toolbar: editorToolbar,
1377
- hideTitleBlock,
1378
- children: [
1379
- /* @__PURE__ */ jsx6(TabsContent, { value: "preview", className: "mt-0 h-full", children: preview }),
1380
- /* @__PURE__ */ jsx6(TabsContent, { value: "edit", className: "mt-0 h-full px-4 py-4", children: isCollaborative ? collaborativeEditor : localEditor })
1381
- ]
1382
- }
1383
- )
1384
- }
1385
- );
1386
- }
1387
-
1388
- export {
1389
- EditorProvider,
1390
- useEditorContext,
1391
- EditorToolbar,
1392
- TiptapEditor,
1393
- CollaboratorsList,
1394
- useEditorConnection,
1395
- useCollaborators,
1396
- useCollaboratorPresence,
1397
- useYjsState,
1398
- useDocumentChanges,
1399
- useAwareness,
1400
- DocumentEditorPane
1401
- };