@vite-hub/realtime 0.4.1 → 0.5.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 (43) hide show
  1. package/README.md +8 -4
  2. package/dist/agent.d.ts +1 -1
  3. package/dist/agent.js +1 -2
  4. package/dist/{bus-CKv8gQZf.js → bus-DJ3dOQAZ.js} +11 -22
  5. package/dist/{bus-protocol-wXkXW28q.d.ts → bus-protocol-juNrVJDF.d.ts} +0 -2
  6. package/dist/bus.d.ts +1 -3
  7. package/dist/bus.js +1 -2
  8. package/dist/client/browser.js +3 -3
  9. package/dist/client.d.ts +2 -4
  10. package/dist/client.js +15 -9
  11. package/dist/{conflict-DYC_qXzM.js → conflict-BqdKFrkE.js} +3 -5
  12. package/dist/{conflict-CmZizTYl.d.ts → conflict-C5KRv-J1.d.ts} +0 -2
  13. package/dist/{document-BfMW1zYU.d.ts → document-CbqgNO_0.d.ts} +2 -4
  14. package/dist/document-CfrQbB03.js +1736 -0
  15. package/dist/durability.d.ts +1 -3
  16. package/dist/durability.js +1 -6
  17. package/dist/{editor-BM5-vHqf.js → editor-DzhKM4Gt.js} +2 -5
  18. package/dist/{error-diagnostics-Cd-XWNf7.js → error-diagnostics-we8V1O-X.js} +1 -2
  19. package/dist/index.d.ts +3 -7
  20. package/dist/index.js +3 -3
  21. package/dist/internal/runtime/unavailable.d.ts +1 -3
  22. package/dist/internal/runtime/unavailable.js +1 -2
  23. package/dist/internal/server.d.ts +7 -0
  24. package/dist/internal/server.js +6 -0
  25. package/dist/{keepalive-B4ONG6AD.js → keepalive-BYkk6Ax8.js} +3 -5
  26. package/dist/{layout-DNaxppTZ.js → layout-BQwRLTH0.js} +1 -2
  27. package/dist/{layout-B7i6-FnH.d.ts → layout-BZtKNqiC.d.ts} +1 -3
  28. package/dist/log-NlQi6kow.js +157 -0
  29. package/dist/{object-BgPPDLDE.js → object-DfrneieE.js} +2 -4
  30. package/dist/{presence-B6rvkHqd.js → presence-DZ21pPKm.js} +3 -4
  31. package/dist/{request-C_bQc4NE.js → request-DM6xHTaU.js} +5 -10
  32. package/dist/{request-BwaohsJS.d.ts → request-PrMHOYFK.d.ts} +1 -3
  33. package/dist/server-CLdYV7Md.d.ts +126 -0
  34. package/dist/server-yQp02XNp.js +2599 -0
  35. package/dist/server.d.ts +4 -142
  36. package/dist/server.js +3 -2588
  37. package/dist/{types-Cvm0G3VJ.d.ts → types-oUyN-CJR.d.ts} +1 -27
  38. package/dist/vite.d.ts +4 -15
  39. package/dist/vite.js +64 -63
  40. package/dist/vue.d.ts +2 -7
  41. package/dist/vue.js +47 -40
  42. package/package.json +44 -39
  43. package/dist/document-U5rzg2vG.js +0 -2041
package/dist/vue.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as realtimeErrorDiagnostics } from "./error-diagnostics-Cd-XWNf7.js";
2
- import { n as resolveRealtimeApplicationPath, t as keepRealtimeSocketAlive } from "./keepalive-B4ONG6AD.js";
3
- import { _ as realtimeReadOnlyCode, b as realtimeSyncPendingCode, i as decodeRealtimeControlPayload, l as encodeWorkspaceChange, m as realtimeInvalidDocumentCode, n as isRecord, o as decodeWorkspaceChangePayload, u as isRetryableRealtimeRequestCode, x as workspaceRoomId, y as realtimeSourceChangedCode } from "./object-BgPPDLDE.js";
4
- import { n as realtimeDocumentLayout, t as readRealtimeStatus } from "./layout-DNaxppTZ.js";
5
- import { n as getRealtimePeople, t as createRealtimeIdentity } from "./presence-B6rvkHqd.js";
6
- import { t as createRealtimeEditorExtensions } from "./editor-BM5-vHqf.js";
7
- import { _ as yCursorPlugin, b as yUndoPlugin, f as absolutePositionToRelativePosition, g as undo, h as relativePositionToAbsolutePosition, m as redo, o as readRealtimeYDoc, p as defaultSelectionBuilder, v as ySyncPlugin, x as yUndoPluginKey, y as ySyncPluginKey } from "./document-U5rzg2vG.js";
1
+ import { _ as yCursorPlugin, b as yUndoPlugin, f as absolutePositionToRelativePosition, g as undo, h as relativePositionToAbsolutePosition, m as redo, o as readRealtimeYDoc, p as defaultSelectionBuilder, v as ySyncPlugin, x as yUndoPluginKey, y as ySyncPluginKey } from "./document-CfrQbB03.js";
2
+ import { n as resolveRealtimeApplicationPath, t as keepRealtimeSocketAlive } from "./keepalive-BYkk6Ax8.js";
3
+ import { t as createRealtimeEditorExtensions } from "./editor-DzhKM4Gt.js";
4
+ import { n as realtimeDocumentLayout, t as readRealtimeStatus } from "./layout-BQwRLTH0.js";
5
+ import { _ as realtimeReadOnlyCode, b as realtimeSyncPendingCode, i as decodeRealtimeControlPayload, l as encodeWorkspaceChange, m as realtimeInvalidDocumentCode, n as isRecord, o as decodeWorkspaceChangePayload, u as isRetryableRealtimeRequestCode, x as workspaceRoomId, y as realtimeSourceChangedCode } from "./object-DfrneieE.js";
6
+ import { n as getRealtimePeople, t as createRealtimeIdentity } from "./presence-DZ21pPKm.js";
7
+ import { t as realtimeErrorDiagnostics } from "./error-diagnostics-we8V1O-X.js";
8
8
  import "lib0/decoding";
9
9
  import * as encoding from "lib0/encoding";
10
10
  import * as awarenessProtocol from "y-protocols/awareness";
@@ -14,7 +14,7 @@ import { Extension, MappablePosition, getUpdatedPosition } from "@tiptap/core";
14
14
  import { Plugin, PluginKey } from "@tiptap/pm/state";
15
15
  import { useUserSession } from "@vite-hub/auth/vue";
16
16
  import { computed, getCurrentInstance, markRaw, onMounted, onScopeDispose, ref, shallowRef, toValue, watch } from "vue";
17
- //#region ../../node_modules/.pnpm/@tiptap+extension-collaboration@3.31.4_@tiptap+core@3.31.4_@tiptap+pm@3.31.4__@tiptap+p_85015a5a825a0d4859fbb90094e145d9/node_modules/@tiptap/extension-collaboration/dist/index.js
17
+ // ../../node_modules/.pnpm/@tiptap+extension-collaboration@3.35.0_@tiptap+core@3.35.0_@tiptap+pm@3.35.0__@tiptap+p_d75d2d6e96a1dd569ff00a6acb5ce82e/node_modules/@tiptap/extension-collaboration/dist/index.js
18
18
  /**
19
19
  * Checks if a transaction was originated from a Yjs change.
20
20
  * @param {Transaction} transaction - The transaction to check.
@@ -30,16 +30,22 @@ function isChangeOrigin(transaction) {
30
30
  * Converts a Y.js relative position to a position in the Tiptap document.
31
31
  */
32
32
  function getYAbsolutePosition(state, relativePos) {
33
- const ystate = ySyncPluginKey.getState(state);
33
+ if (relativePos === null) return 0;
34
+ const ystate = getSyncState(state);
34
35
  return relativePositionToAbsolutePosition(ystate.doc, ystate.type, relativePos, ystate.binding.mapping) || 0;
35
36
  }
36
37
  /**
37
38
  * Converts a position in the Tiptap document to a Y.js relative position.
38
39
  */
39
40
  function getYRelativePosition(state, absolutePos) {
40
- const ystate = ySyncPluginKey.getState(state);
41
+ const ystate = getSyncState(state);
41
42
  return absolutePositionToRelativePosition(absolutePos, ystate.type, ystate.binding.mapping);
42
43
  }
44
+ function getSyncState(state) {
45
+ const syncState = ySyncPluginKey.getState(state);
46
+ if (!syncState) throw new Error("Collaboration requires the Yjs sync plugin");
47
+ return syncState;
48
+ }
43
49
  /**
44
50
  * A MappablePosition subclass that includes Y.js relative position information
45
51
  * to track positions in collaborative transactions.
@@ -76,7 +82,7 @@ function createMappablePosition(position, state) {
76
82
  * Returns the new position after applying a transaction. Handles both Y.js
77
83
  * transactions and regular transactions.
78
84
  */
79
- function getUpdatedPosition$1(position, transaction, state) {
85
+ function getUpdatedPosition$2(position, transaction, state) {
80
86
  const yRelativePosition = position instanceof CollaborationMappablePosition ? position.yRelativePosition : null;
81
87
  if (isChangeOrigin(transaction) && yRelativePosition) return {
82
88
  position: new CollaborationMappablePosition(getYAbsolutePosition(state, yRelativePosition), yRelativePosition),
@@ -89,6 +95,11 @@ function getUpdatedPosition$1(position, transaction, state) {
89
95
  mapResult: result.mapResult
90
96
  };
91
97
  }
98
+ function getUndoManager(state) {
99
+ const undoState = yUndoPluginKey.getState(state);
100
+ if (!undoState) throw new Error("Collaboration requires the Yjs undo plugin");
101
+ return undoState.undoManager;
102
+ }
92
103
  var src_default = Extension.create({
93
104
  name: "collaboration",
94
105
  priority: 1e3,
@@ -107,22 +118,24 @@ var src_default = Extension.create({
107
118
  if (this.editor.extensionManager.extensions.find((extension) => extension.name === "undoRedo")) console.warn("[tiptap warn]: \"@tiptap/extension-collaboration\" comes with its own history support and is not compatible with \"@tiptap/extension-undo-redo\".");
108
119
  },
109
120
  onBeforeCreate() {
110
- this.editor.utils.getUpdatedPosition = (position, transaction) => getUpdatedPosition$1(position, transaction, this.editor.state);
121
+ this.editor.utils.getUpdatedPosition = (position, transaction) => getUpdatedPosition$2(position, transaction, this.editor.state);
111
122
  this.editor.utils.createMappablePosition = (position) => createMappablePosition(position, this.editor.state);
112
123
  },
113
124
  addCommands() {
114
125
  return {
115
126
  undo: () => ({ tr, state, dispatch }) => {
127
+ var _undo;
116
128
  tr.setMeta("preventDispatch", true);
117
- if (yUndoPluginKey.getState(state).undoManager.undoStack.length === 0) return false;
129
+ if (getUndoManager(state).undoStack.length === 0) return false;
118
130
  if (!dispatch) return true;
119
- return undo(state);
131
+ return (_undo = undo(state)) !== null && _undo !== void 0 ? _undo : false;
120
132
  },
121
133
  redo: () => ({ tr, state, dispatch }) => {
134
+ var _redo;
122
135
  tr.setMeta("preventDispatch", true);
123
- if (yUndoPluginKey.getState(state).undoManager.redoStack.length === 0) return false;
136
+ if (getUndoManager(state).redoStack.length === 0) return false;
124
137
  if (!dispatch) return true;
125
- return redo(state);
138
+ return (_redo = redo(state)) !== null && _redo !== void 0 ? _redo : false;
126
139
  }
127
140
  };
128
141
  },
@@ -138,7 +151,7 @@ var src_default = Extension.create({
138
151
  const yUndoPluginInstance = yUndoPlugin(this.options.yUndoOptions);
139
152
  const originalUndoPluginView = yUndoPluginInstance.spec.view;
140
153
  yUndoPluginInstance.spec.view = (view) => {
141
- const { undoManager } = yUndoPluginKey.getState(view.state);
154
+ const undoManager = getUndoManager(view.state);
142
155
  if (undoManager.restore) {
143
156
  undoManager.restore();
144
157
  undoManager.restore = () => {};
@@ -159,11 +172,22 @@ var src_default = Extension.create({
159
172
  ...this.options.ySyncOptions,
160
173
  onFirstRender: this.options.onFirstRender
161
174
  };
175
+ if (this.editor.options.enableContentCheck) ySyncPluginOptions.onInvalidContent = (error) => {
176
+ this.editor.emit("contentError", {
177
+ error,
178
+ editor: this.editor,
179
+ disableCollaboration: () => {
180
+ var _fragment$doc;
181
+ this.storage.isDisabled = true;
182
+ (_fragment$doc = fragment.doc) === null || _fragment$doc === void 0 || _fragment$doc.destroy();
183
+ }
184
+ });
185
+ };
162
186
  return [
163
187
  ySyncPlugin(fragment, ySyncPluginOptions),
164
188
  yUndoPluginInstance,
165
189
  new Plugin({ filterTransaction: (transaction, state) => {
166
- if (transaction.getMeta("inputRule")) yUndoPluginKey.getState(state).undoManager.stopCapturing();
190
+ if (transaction.getMeta("inputRule")) getUndoManager(state).stopCapturing();
167
191
  return true;
168
192
  } }),
169
193
  this.editor.options.enableContentCheck && new Plugin({
@@ -181,19 +205,18 @@ var src_default = Extension.create({
181
205
  error,
182
206
  editor: this.editor,
183
207
  disableCollaboration: () => {
184
- var _fragment$doc;
185
- (_fragment$doc = fragment.doc) === null || _fragment$doc === void 0 || _fragment$doc.destroy();
208
+ var _fragment$doc2;
209
+ (_fragment$doc2 = fragment.doc) === null || _fragment$doc2 === void 0 || _fragment$doc2.destroy();
186
210
  }
187
211
  });
188
212
  return true;
189
213
  }
190
214
  }
191
215
  })
192
- ].filter(Boolean);
216
+ ].filter((plugin) => plugin !== false);
193
217
  }
194
218
  });
195
- //#endregion
196
- //#region src/caret.ts
219
+ // src/caret.ts
197
220
  const validColor = /^#[0-9a-f]{6}$/i;
198
221
  /**
199
222
  * Other people's carets and selections, drawn from the room's awareness. It renders what TipTap's CollaborationCaret
@@ -237,9 +260,7 @@ const RealtimeCaret = Extension.create({
237
260
  })];
238
261
  }
239
262
  });
240
- //#endregion
241
- //#region src/vue.ts
242
- /** The error for a code that the server put in `data.code` of a refused request, so the app can tell the reasons apart. */
263
+ // src/vue.ts
243
264
  function serverRequestError(code, action) {
244
265
  switch (code) {
245
266
  case realtimeInvalidDocumentCode: return realtimeErrorDiagnostics.REALTIME_INVALID_DOCUMENT({ action });
@@ -531,10 +552,6 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
531
552
  if (error) return [error, void 0];
532
553
  return accepts(data) ? [void 0, data] : [realtimeErrorDiagnostics.REALTIME_INVALID_RESPONSE({ action }), void 0];
533
554
  }
534
- /**
535
- * Saves the room through its document adapter now, including every edit this client has sent.
536
- * Returns `[error, saved]`; `error.code` is a `RealtimeRequestErrorCode`; `REALTIME_REQUEST_FAILED` has the HTTP status in `error.data.status`.
537
- */
538
555
  async function save() {
539
556
  if (!enabled()) return [realtimeErrorDiagnostics.REALTIME_DISABLED({ action: "save" }), void 0];
540
557
  saveRequests.value++;
@@ -544,10 +561,6 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
544
561
  saveRequests.value--;
545
562
  }
546
563
  }
547
- /**
548
- * Saves the room and records a durable history entry through the document adapter.
549
- * Returns `[error, checkpoint]`; `error.code` is a `RealtimeRequestErrorCode`; `REALTIME_REQUEST_FAILED` has the HTTP status in `error.data.status`.
550
- */
551
564
  async function checkpoint() {
552
565
  if (!enabled()) return [realtimeErrorDiagnostics.REALTIME_DISABLED({ action: "checkpoint" }), void 0];
553
566
  checkpointRequests.value++;
@@ -557,10 +570,6 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
557
570
  checkpointRequests.value--;
558
571
  }
559
572
  }
560
- /**
561
- * Asks the room to compare its seed with the stored document. A changed source resets every client.
562
- * Returns `[error, result]`; `error.code` is a `RealtimeRequestErrorCode`; `REALTIME_REQUEST_FAILED` has the HTTP status in `error.data.status`.
563
- */
564
573
  async function refresh() {
565
574
  return await requestResult("refresh", isRefreshResult);
566
575
  }
@@ -602,7 +611,6 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
602
611
  fields: computed(() => document.value?.getMap(realtimeDocumentLayout.fields)),
603
612
  people,
604
613
  provider,
605
- /** The server rejects edits from this connection. `readOnlyReason` tells why; `saveStatus` holds the details. */
606
614
  readOnly: computed(() => readOnlyReason.value !== null),
607
615
  readOnlyReason,
608
616
  refresh,
@@ -623,5 +631,4 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
623
631
  destroy
624
632
  };
625
633
  }
626
- //#endregion
627
634
  export { RealtimeCaret, readRealtimeYDoc, useRealtimeTiptap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/realtime",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Realtime document primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "collaboration",
@@ -67,6 +67,11 @@
67
67
  "import": "./dist/internal/runtime/unavailable.js",
68
68
  "default": "./dist/internal/runtime/unavailable.js"
69
69
  },
70
+ "./internal/server": {
71
+ "types": "./dist/internal/server.d.ts",
72
+ "import": "./dist/internal/server.js",
73
+ "default": "./dist/internal/server.js"
74
+ },
70
75
  "./server": {
71
76
  "types": "./dist/server.d.ts",
72
77
  "import": "./dist/server.js",
@@ -89,66 +94,66 @@
89
94
  }
90
95
  },
91
96
  "dependencies": {
92
- "@tiptap/extension-collaboration": "^3.31.4",
93
- "@tiptap/y-tiptap": "^3.0.9",
94
- "@vite-hub/auth": "0.4.1",
95
- "@vite-hub/workspace": "0.4.1",
97
+ "@tiptap/extension-collaboration": "^3.35.0",
98
+ "@tiptap/y-tiptap": "^3.3.1",
99
+ "@vite-hub/auth": "0.5.1",
100
+ "@vite-hub/workspace": "0.5.1",
96
101
  "h3": "^2.0.8",
97
- "ioredis": "^5.11.1",
98
- "lib0": "^0.2.119",
102
+ "ioredis": "^6.1.0",
103
+ "lib0": "^0.2.120",
99
104
  "marked": "17.0.6",
100
105
  "nostics": "1.4.0",
101
106
  "postgres": "^3.4.9",
102
- "prosemirror-model": "^1.25.12",
107
+ "prosemirror-model": "^1.25.13",
103
108
  "prosemirror-state": "^1.4.4",
104
- "prosemirror-transform": "^1.12.2",
105
- "prosemirror-view": "^1.42.3",
109
+ "prosemirror-transform": "^1.12.7",
110
+ "prosemirror-view": "^1.43.0",
106
111
  "y-protocols": "^1.0.7",
107
112
  "y-websocket": "^3.1.0",
108
- "@vite-hub/runtime": "0.4.1"
113
+ "@vite-hub/runtime": "0.5.1"
109
114
  },
110
115
  "devDependencies": {
111
- "@tiptap/core": "^3.31.4",
112
- "@tiptap/extension-blockquote": "^3.31.4",
113
- "@tiptap/extension-code": "^3.31.4",
114
- "@tiptap/extension-document": "^3.31.4",
115
- "@tiptap/extension-image": "^3.31.4",
116
- "@tiptap/extension-table": "^3.31.4",
117
- "@tiptap/markdown": "^3.31.4",
118
- "@tiptap/pm": "^3.31.4",
119
- "@tiptap/starter-kit": "^3.31.4",
116
+ "@tiptap/core": "^3.35.0",
117
+ "@tiptap/extension-blockquote": "^3.35.0",
118
+ "@tiptap/extension-code": "^3.35.0",
119
+ "@tiptap/extension-document": "^3.35.0",
120
+ "@tiptap/extension-image": "^3.35.0",
121
+ "@tiptap/extension-table": "^3.35.0",
122
+ "@tiptap/markdown": "^3.35.0",
123
+ "@tiptap/pm": "^3.35.0",
124
+ "@tiptap/starter-kit": "^3.35.0",
120
125
  "@types/json-schema": "^7.0.15",
121
- "@types/node": "^24.19.1",
122
- "@vite-hub/database": "0.4.1",
126
+ "@types/node": "^24.19.2",
127
+ "@vite-hub/database": "0.5.1",
123
128
  "@vite-hub/internal": "0.0.1",
124
- "happy-dom": "21.0.3",
125
- "linkedom": "^0.18.13",
129
+ "happy-dom": "21.0.4",
130
+ "linkedom": "^0.18.15",
126
131
  "nitro": "^3.0.261103-rc",
127
132
  "publint": "^0.3.25",
128
133
  "typescript": "^6.0.3",
129
- "vite": "^8.2.2",
130
- "vite-plus": "^0.3.3",
131
- "vitest": "^4.1.11",
132
- "vue": "3.5.44",
134
+ "vite": "^8.3.8",
135
+ "vite-plus": "^1.7.0",
136
+ "vitest": "5.1.0",
137
+ "vue": "3.5.46",
133
138
  "miniflare": "4.20260730.0",
134
- "drizzle-orm": "1.0.0-rc.5",
139
+ "drizzle-orm": "1.0.0-rc.6",
135
140
  "yjs": "^13.6.33"
136
141
  },
137
142
  "peerDependencies": {
138
- "@tiptap/core": "^3.31.4",
139
- "@tiptap/extension-blockquote": "^3.31.4",
140
- "@tiptap/extension-code": "^3.31.4",
141
- "@tiptap/extension-document": "^3.31.4",
142
- "@tiptap/extension-image": "^3.31.4",
143
- "@tiptap/extension-table": "^3.31.4",
144
- "@tiptap/markdown": "^3.31.4",
145
- "@tiptap/pm": "^3.31.4",
146
- "@tiptap/starter-kit": "^3.31.4",
143
+ "@tiptap/core": "^3.35.0",
144
+ "@tiptap/extension-blockquote": "^3.35.0",
145
+ "@tiptap/extension-code": "^3.35.0",
146
+ "@tiptap/extension-document": "^3.35.0",
147
+ "@tiptap/extension-image": "^3.35.0",
148
+ "@tiptap/extension-table": "^3.35.0",
149
+ "@tiptap/markdown": "^3.35.0",
150
+ "@tiptap/pm": "^3.35.0",
151
+ "@tiptap/starter-kit": "^3.35.0",
147
152
  "@types/json-schema": "^7.0.15",
148
153
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
149
154
  "vite": ">=8.0.0",
150
155
  "vue": "^3.5.0",
151
- "drizzle-orm": "1.0.0-rc.5 || ^1.0.0",
156
+ "drizzle-orm": "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0",
152
157
  "yjs": "^13.6.33"
153
158
  },
154
159
  "peerDependenciesMeta": {