vzcode 0.29.0 → 0.31.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.
package/dist/index.html CHANGED
@@ -24,11 +24,10 @@
24
24
  href="https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css"
25
25
  rel="stylesheet"
26
26
  />
27
- <script type="module" crossorigin src="/assets/index-c7f894a9.js"></script>
28
- <link rel="stylesheet" href="/assets/index-836bdce7.css">
27
+ <script type="module" crossorigin src="/assets/index-29gn4hve.js"></script>
28
+ <link rel="stylesheet" crossorigin href="/assets/index-esdlTXtH.css">
29
29
  </head>
30
30
  <body>
31
31
  <div id="root"></div>
32
-
33
32
  </body>
34
33
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -54,7 +54,7 @@
54
54
  "@codemirror/state": "^6.3.1",
55
55
  "@codemirror/theme-one-dark": "^6.1.2",
56
56
  "@codemirror/view": "^6.22.0",
57
- "@lezer/highlight": "^1.1.6",
57
+ "@lezer/highlight": "^1.2.0",
58
58
  "@replit/codemirror-interact": "^6.3.0",
59
59
  "@teamwork/websocket-json-stream": "^2.0.0",
60
60
  "@typescript/vfs": "^1.5.0",
@@ -78,7 +78,7 @@
78
78
  "json0-ot-diff": "^1.1.2",
79
79
  "ngrok": "^4.3.3",
80
80
  "open": "^9.1.0",
81
- "openai": "^4.17.4",
81
+ "openai": "^4.19.0",
82
82
  "ot-json1": "^1.0.2",
83
83
  "react": "^18.2.0",
84
84
  "react-bootstrap": "^2.9.1",
@@ -91,11 +91,11 @@
91
91
  "devDependencies": {
92
92
  "@types/react": "^18.2.37",
93
93
  "@types/react-dom": "^18.2.15",
94
- "@vitejs/plugin-react": "^4.1.1",
95
- "prettier": "^3.0.3",
94
+ "@vitejs/plugin-react": "^4.2.0",
95
+ "prettier": "^3.1.0",
96
96
  "sass": "^1.69.5",
97
97
  "typescript": "^5.2.2",
98
- "vite": "^4.5.0",
98
+ "vite": "^5.0.0",
99
99
  "vitest": "^0.34.6"
100
100
  }
101
101
  }
@@ -87,6 +87,7 @@ export type VZCodeContextValue = {
87
87
  export const VZCodeProvider = ({
88
88
  content,
89
89
  shareDBDoc,
90
+ submitOperation,
90
91
  localPresence,
91
92
  docPresence,
92
93
  prettierWorker,
@@ -97,6 +98,9 @@ export const VZCodeProvider = ({
97
98
  }: {
98
99
  content: VZCodeContent;
99
100
  shareDBDoc: ShareDBDoc<VZCodeContent>;
101
+ submitOperation: (
102
+ next: (content: VZCodeContent) => VZCodeContent,
103
+ ) => void;
100
104
  localPresence: any;
101
105
  docPresence: any;
102
106
  prettierWorker: Worker;
@@ -105,12 +109,6 @@ export const VZCodeProvider = ({
105
109
  children: React.ReactNode;
106
110
  codeError?: string | null;
107
111
  }) => {
108
- // A convenience function for mutating the ShareDB document
109
- // based submitting OT ops generated by diffing the JSON.
110
- const submitOperation: (
111
- next: (content: VZCodeContent) => VZCodeContent,
112
- ) => void = useSubmitOperation(shareDBDoc);
113
-
114
112
  // Auto-run Pretter after local changes.
115
113
  const {
116
114
  prettierError,
@@ -60,6 +60,7 @@ function App() {
60
60
  content,
61
61
  localPresence,
62
62
  docPresence,
63
+ submitOperation,
63
64
  } = useShareDB({
64
65
  connection,
65
66
  });
@@ -80,6 +81,7 @@ function App() {
80
81
  <VZCodeProvider
81
82
  content={content}
82
83
  shareDBDoc={shareDBDoc}
84
+ submitOperation={submitOperation}
83
85
  localPresence={localPresence}
84
86
  docPresence={docPresence}
85
87
  prettierWorker={prettierWorker}
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { randomId } from '../../randomId';
3
3
  import { ShareDBDoc, VZCodeContent } from '../../types';
4
+ import { useSubmitOperation } from '../useSubmitOperation';
4
5
 
5
6
  // Set up the connection to ShareDB.
6
7
  export const useShareDB = ({
@@ -94,10 +95,16 @@ export const useShareDB = ({
94
95
  };
95
96
  }, []);
96
97
 
98
+ // A convenience function for mutating the ShareDB document
99
+ // based submitting OT ops generated by diffing the JSON.
100
+ const submitOperation =
101
+ useSubmitOperation<VZCodeContent>(shareDBDoc);
102
+
97
103
  return {
98
104
  shareDBDoc,
99
105
  content,
100
106
  localPresence,
101
107
  docPresence,
108
+ submitOperation,
102
109
  };
103
110
  };
@@ -194,11 +194,14 @@ export const SplitPaneResizeProvider = ({ children }) => {
194
194
  } = state;
195
195
 
196
196
  // Logic around initializing from localStorage.
197
- useLayoutEffect(() => {
198
- if (needsInitialization && !isInitialized) {
199
- dispatch({ type: 'initialize' });
200
- }
201
- }, [isInitialized]);
197
+ // Only run this on the client.
198
+ if (typeof window !== 'undefined') {
199
+ useLayoutEffect(() => {
200
+ if (needsInitialization && !isInitialized) {
201
+ dispatch({ type: 'initialize' });
202
+ }
203
+ }, [isInitialized]);
204
+ }
202
205
 
203
206
  // Logic around storing the values in localStorage.
204
207
  useEffect(() => {
@@ -1,25 +1,22 @@
1
1
  import { useCallback } from 'react';
2
- import { ShareDBDoc, VZCodeContent } from '../types';
2
+ import { ShareDBDoc } from '../types'; // Assuming ShareDBDoc is already generic
3
3
  import { diff } from './diff';
4
4
 
5
- // A helper function to submit diff-based operations to ShareDB
6
- export const useSubmitOperation = (
7
- shareDBDoc: ShareDBDoc<VZCodeContent>,
8
- ): ((
9
- next: (content: VZCodeContent) => VZCodeContent,
10
- ) => void) => {
11
- const submitOperation: (
12
- next: (content: VZCodeContent) => VZCodeContent,
13
- ) => void = useCallback(
14
- (next) => {
15
- const content: VZCodeContent = shareDBDoc.data;
16
- const op = diff(content, next(content));
17
- if (op && shareDBDoc) {
18
- shareDBDoc.submitOp(op);
19
- }
20
- },
21
- [shareDBDoc],
22
- );
5
+ // A generic helper function to submit diff-based operations to ShareDB
6
+ export const useSubmitOperation = <T>(
7
+ shareDBDoc: ShareDBDoc<T>,
8
+ ): ((next: (data: T) => T) => void) => {
9
+ const submitOperation: (next: (data: T) => T) => void =
10
+ useCallback(
11
+ (next) => {
12
+ const data: T = shareDBDoc.data;
13
+ const op = diff(data, next(data));
14
+ if (op && shareDBDoc) {
15
+ shareDBDoc.submitOp(op);
16
+ }
17
+ },
18
+ [shareDBDoc],
19
+ );
23
20
 
24
21
  return submitOperation;
25
22
  };
@@ -121,7 +121,6 @@ onmessage = async ({ data }) => {
121
121
  const files: Files = content.files;
122
122
 
123
123
  // Iterate over the files
124
-
125
124
  for (const fileId of Object.keys(files)) {
126
125
  const file: File = files[fileId];
127
126
  const { name, text } = file;
@@ -187,7 +186,7 @@ onmessage = async ({ data }) => {
187
186
  postMessage(autocompleteResponse);
188
187
  }
189
188
 
190
- if (data.event == 'lint-request') {
189
+ if (data.event === 'lint-request') {
191
190
  if (debug) {
192
191
  console.log('Lint Request');
193
192
  }
@@ -196,19 +195,40 @@ onmessage = async ({ data }) => {
196
195
  linterRequest;
197
196
 
198
197
  const tsFileName = getTSFileName(fileName);
199
- let tsErrors = null;
198
+ let tsErrors = [];
200
199
  // Since we are also updating the server when we autocomplete we do not need to update
201
200
  if (isTS(tsFileName)) {
202
201
  setFile(tsFileName, fileContent);
203
202
  // Creates an array of diagnostic objects containing
204
203
  // both semantic and syntactic diagnostics.
205
204
  tsErrors = env.languageService
206
- .getSemanticDiagnostics(fileName)
205
+ .getSemanticDiagnostics(tsFileName)
207
206
  .concat(
208
207
  env.languageService.getSyntacticDiagnostics(
209
- fileName,
208
+ tsFileName,
210
209
  ),
211
210
  );
211
+
212
+ // Be less aggressive for non-TS files,
213
+ // e.g. files that end in .js or .jsx.
214
+ if (!isTS(fileName)) {
215
+ // This code is for errors like:
216
+ // "Binding element 'data' implicitly has an 'any' type."
217
+ const LINT_ERROR_CODE_ANY = 7031;
218
+
219
+ // This code is for errors like:
220
+ // "Cannot find module 'd3' or its corresponding type declarations."
221
+ const LINT_ERROR_CODE_IMPORT = 2307;
222
+
223
+ if (debug) {
224
+ console.log(tsErrors);
225
+ }
226
+ tsErrors = tsErrors.filter(
227
+ (error: { code: number }) =>
228
+ error.code !== LINT_ERROR_CODE_ANY &&
229
+ error.code !== LINT_ERROR_CODE_IMPORT,
230
+ );
231
+ }
212
232
  tsErrors = convertToCodeMirrorDiagnostic(tsErrors);
213
233
  }
214
234
 
@@ -1,5 +1,7 @@
1
1
  import OpenAI from 'openai';
2
- import { editOp, type, replaceOp } from 'ot-json1';
2
+ import json1 from 'ot-json1';
3
+
4
+ const { editOp, type, replaceOp } = json1;
3
5
 
4
6
  // Feature flag to slow down AI for development/testing
5
7
  const slowdown = false;