vzcode 0.29.0 → 0.30.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/assets/{index-c7f894a9.js → index-c3a6c525.js} +17 -17
- package/dist/assets/{worker-a2979249.js → worker-ed0e2778.js} +72 -72
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/client/App/VZCodeContext.tsx +4 -6
- package/src/client/App/index.tsx +2 -0
- package/src/client/App/useShareDB.ts +7 -0
- package/src/client/SplitPaneResizeContext.tsx +8 -5
- package/src/client/useSubmitOperation.ts +16 -19
- package/src/client/useTypeScript/worker.ts +24 -4
package/dist/index.html
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
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-
|
|
27
|
+
<script type="module" crossorigin src="/assets/index-c3a6c525.js"></script>
|
|
28
28
|
<link rel="stylesheet" href="/assets/index-836bdce7.css">
|
|
29
29
|
</head>
|
|
30
30
|
<body>
|
package/package.json
CHANGED
|
@@ -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,
|
package/src/client/App/index.tsx
CHANGED
|
@@ -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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
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<
|
|
8
|
-
): ((
|
|
9
|
-
next: (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
189
|
+
if (data.event === 'lint-request') {
|
|
191
190
|
if (debug) {
|
|
192
191
|
console.log('Lint Request');
|
|
193
192
|
}
|
|
@@ -203,12 +202,33 @@ onmessage = async ({ data }) => {
|
|
|
203
202
|
// Creates an array of diagnostic objects containing
|
|
204
203
|
// both semantic and syntactic diagnostics.
|
|
205
204
|
tsErrors = env.languageService
|
|
206
|
-
.getSemanticDiagnostics(
|
|
205
|
+
.getSemanticDiagnostics(tsFileName)
|
|
207
206
|
.concat(
|
|
208
207
|
env.languageService.getSyntacticDiagnostics(
|
|
209
|
-
|
|
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
|
|