vzcode 0.28.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-836bdce7.css +1 -0
- package/dist/assets/index-c3a6c525.js +115 -0
- package/dist/assets/worker-ed0e2778.js +366 -0
- package/dist/index.html +2 -2
- package/package.json +10 -6
- package/src/client/AIAssist.ts +110 -19
- package/src/client/AIAssistWidget/index.tsx +101 -0
- package/src/client/AIAssistWidget/style.scss +10 -0
- package/src/client/App/VZCodeContext.tsx +249 -0
- package/src/client/App/VZLeft.tsx +56 -0
- package/src/client/App/VZMiddle.tsx +91 -0
- package/src/client/App/VZRight.tsx +15 -0
- package/src/client/App/index.tsx +106 -0
- package/src/client/{style.scss → App/style.scss} +14 -3
- package/src/client/App/useShareDB.ts +110 -0
- package/src/client/CodeEditor/getOrCreateEditor.ts +54 -6
- package/src/client/CodeEditor/index.tsx +9 -0
- package/src/client/CodeEditor/json1PresenceDisplay.ts +38 -9
- package/src/client/CodeEditor/typeScriptCompletions.ts +108 -0
- package/src/client/CodeEditor/typeScriptLinter.ts +45 -0
- package/src/client/CodeErrorOverlay/index.tsx +27 -1
- package/src/client/CodeErrorOverlay/style.scss +11 -11
- package/src/client/SplitPaneResizeContext.tsx +198 -39
- package/src/client/TabList/index.tsx +1 -27
- package/src/client/{Resizer → VZResizer}/index.tsx +37 -13
- package/src/client/VZSettings.tsx +1 -1
- package/src/client/VZSidebar/CreateFileModal.tsx +93 -0
- package/src/client/VZSidebar/DeleteConfirmationModal.tsx +42 -24
- package/src/client/VZSidebar/index.tsx +69 -9
- package/src/client/useFileCRUD.ts +19 -19
- package/src/client/useOpenDirectories.ts +12 -8
- package/src/client/usePrettier/index.ts +13 -1
- package/src/client/useSubmitOperation.ts +16 -19
- package/src/client/useTypeScript/index.ts +44 -0
- package/src/client/useTypeScript/requestTypes.ts +29 -0
- package/src/client/useTypeScript/worker.ts +242 -0
- package/src/client/usernameLocalStorage.ts +1 -1
- package/src/client/vzReducer/createInitialState.ts +4 -5
- package/src/index.ts +5 -1
- package/src/server/handleAIAssist.js +76 -12
- package/src/server/index.js +55 -2
- package/src/types.ts +78 -1
- package/dist/assets/index-a9585cbc.js +0 -111
- package/dist/assets/index-d30c9f1b.css +0 -1
- package/src/client/App.tsx +0 -286
- /package/src/client/{Resizer → VZResizer}/styles.scss +0 -0
package/src/client/App.tsx
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useReducer } from 'react';
|
|
2
|
-
import ShareDBClient from 'sharedb-client-browser/dist/sharedb-client-umd.cjs';
|
|
3
|
-
import { json1Presence } from '../ot';
|
|
4
|
-
import { randomId } from '../randomId';
|
|
5
|
-
import { CodeEditor } from './CodeEditor';
|
|
6
|
-
import { VZSettings } from './VZSettings';
|
|
7
|
-
import { VZSidebar } from './VZSidebar';
|
|
8
|
-
import {
|
|
9
|
-
Files,
|
|
10
|
-
ShareDBDoc,
|
|
11
|
-
Username,
|
|
12
|
-
VZCodeContent,
|
|
13
|
-
} from '../types';
|
|
14
|
-
import { TabList } from './TabList';
|
|
15
|
-
import { useOpenDirectories } from './useOpenDirectories';
|
|
16
|
-
import { defaultTheme, useDynamicTheme } from './themes';
|
|
17
|
-
import {
|
|
18
|
-
EditorCache,
|
|
19
|
-
useEditorCache,
|
|
20
|
-
} from './useEditorCache';
|
|
21
|
-
import { usePrettier } from './usePrettier';
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
import PrettierWorker from './usePrettier/worker?worker';
|
|
24
|
-
import { SplitPaneResizeProvider } from './SplitPaneResizeContext';
|
|
25
|
-
import { Resizer } from './Resizer';
|
|
26
|
-
import { PresenceNotifications } from './PresenceNotifications';
|
|
27
|
-
import { CodeErrorOverlay } from './CodeErrorOverlay';
|
|
28
|
-
import { vzReducer, createInitialState } from './vzReducer';
|
|
29
|
-
import { useActions } from './useActions';
|
|
30
|
-
import { useFileCRUD } from './useFileCRUD';
|
|
31
|
-
import { useSubmitOperation } from './useSubmitOperation';
|
|
32
|
-
import {
|
|
33
|
-
useInitialUsername,
|
|
34
|
-
usePersistUsername,
|
|
35
|
-
} from './usernameLocalStorage';
|
|
36
|
-
import './style.scss';
|
|
37
|
-
|
|
38
|
-
// Instantiate the Prettier worker.
|
|
39
|
-
const prettierWorker = new PrettierWorker();
|
|
40
|
-
|
|
41
|
-
// Register our custom JSON1 OT type that supports presence.
|
|
42
|
-
// See https://github.com/vizhub-core/json1-presence
|
|
43
|
-
ShareDBClient.types.register(json1Presence.type);
|
|
44
|
-
|
|
45
|
-
// Establish the singleton ShareDB connection over WebSockets.
|
|
46
|
-
// TODO consider using reconnecting WebSocket
|
|
47
|
-
const { Connection } = ShareDBClient;
|
|
48
|
-
const wsProtocol =
|
|
49
|
-
window.location.protocol === 'https:'
|
|
50
|
-
? 'wss://'
|
|
51
|
-
: 'ws://';
|
|
52
|
-
const socket = new WebSocket(
|
|
53
|
-
wsProtocol + window.location.host + '/ws',
|
|
54
|
-
);
|
|
55
|
-
const connection = new Connection(socket);
|
|
56
|
-
|
|
57
|
-
function App() {
|
|
58
|
-
// The ShareDB document.
|
|
59
|
-
const [shareDBDoc, setShareDBDoc] =
|
|
60
|
-
useState<ShareDBDoc<VZCodeContent> | null>(null);
|
|
61
|
-
|
|
62
|
-
// Local ShareDB presence, for broadcasting our cursor position
|
|
63
|
-
// so other clients can see it.
|
|
64
|
-
// See https://share.github.io/sharedb/api/local-presence
|
|
65
|
-
const [localPresence, setLocalPresence] = useState(null);
|
|
66
|
-
|
|
67
|
-
// The document-level presence object, which emits
|
|
68
|
-
// changes in remote presence.
|
|
69
|
-
const [docPresence, setDocPresence] = useState(null);
|
|
70
|
-
|
|
71
|
-
// The `doc.data` part of the ShareDB document,
|
|
72
|
-
// updated on each change to decouple rendering from ShareDB.
|
|
73
|
-
// Starts out as `null` until the document is loaded.
|
|
74
|
-
const [content, setContent] =
|
|
75
|
-
useState<VZCodeContent | null>(null);
|
|
76
|
-
|
|
77
|
-
// Set up the connection to ShareDB.
|
|
78
|
-
// TODO move this logic to a hook called `useShareDB`
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
// Since there is only ever a single document,
|
|
81
|
-
// these things are pretty arbitrary.
|
|
82
|
-
// * `collection` - the ShareDB collection to use
|
|
83
|
-
// * `id` - the id of the ShareDB document to use
|
|
84
|
-
const collection = 'documents';
|
|
85
|
-
const id = '1';
|
|
86
|
-
|
|
87
|
-
// Initialize the ShareDB document.
|
|
88
|
-
const shareDBDoc = connection.get(collection, id);
|
|
89
|
-
|
|
90
|
-
// Subscribe to the document to get updates.
|
|
91
|
-
// This callback gets called once only.
|
|
92
|
-
shareDBDoc.subscribe(() => {
|
|
93
|
-
// Expose ShareDB doc to downstream logic.
|
|
94
|
-
setShareDBDoc(shareDBDoc);
|
|
95
|
-
|
|
96
|
-
// Set initial data.
|
|
97
|
-
setContent(shareDBDoc.data);
|
|
98
|
-
|
|
99
|
-
// Listen for all changes and update `data`.
|
|
100
|
-
// This decouples rendering logic from ShareDB.
|
|
101
|
-
// This callback gets called on each change.
|
|
102
|
-
shareDBDoc.on('op', () => {
|
|
103
|
-
// TODO consider excluding file contents from this,
|
|
104
|
-
// because currently we are re-rendering the entire
|
|
105
|
-
// document on each file change (each keystroke while editing).
|
|
106
|
-
// This is not required, because no part of the app outside
|
|
107
|
-
// of the CodeMirror integration uses those file contents.
|
|
108
|
-
// The Sidebar only needs to know file names, not contents.
|
|
109
|
-
setContent(shareDBDoc.data);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Set up presence.
|
|
113
|
-
// See https://github.com/share/sharedb/blob/master/examples/rich-text-presence/client.js#L53
|
|
114
|
-
const docPresence = connection.getDocPresence(
|
|
115
|
-
collection,
|
|
116
|
-
id,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Subscribe to receive remote presence updates.
|
|
120
|
-
docPresence.subscribe(function (error) {
|
|
121
|
-
if (error) throw error;
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Set up our local presence for broadcasting this client's presence.
|
|
125
|
-
const generateTimestampedId = () => {
|
|
126
|
-
const timestamp = Date.now().toString(36);
|
|
127
|
-
const randomPart = randomId();
|
|
128
|
-
return `${timestamp}-${randomPart}`;
|
|
129
|
-
};
|
|
130
|
-
setLocalPresence(
|
|
131
|
-
docPresence.create(generateTimestampedId()),
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// Store docPresence so child components can listen for changes.
|
|
135
|
-
setDocPresence(docPresence);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// TODO unsubscribe from presence
|
|
139
|
-
// TODO unsubscribe from doc
|
|
140
|
-
return () => {
|
|
141
|
-
// shareDBDoc.destroy();
|
|
142
|
-
// docPresence.destroy();
|
|
143
|
-
};
|
|
144
|
-
}, []);
|
|
145
|
-
|
|
146
|
-
// Get the initial username from localStorage.
|
|
147
|
-
const initialUsername: Username = useInitialUsername();
|
|
148
|
-
|
|
149
|
-
const submitOperation: (
|
|
150
|
-
next: (content: VZCodeContent) => VZCodeContent,
|
|
151
|
-
) => void = useSubmitOperation(shareDBDoc);
|
|
152
|
-
|
|
153
|
-
// Auto-run Pretter after local changes.
|
|
154
|
-
const {
|
|
155
|
-
prettierError,
|
|
156
|
-
}: {
|
|
157
|
-
prettierError: string | null;
|
|
158
|
-
} = usePrettier(
|
|
159
|
-
shareDBDoc,
|
|
160
|
-
submitOperation,
|
|
161
|
-
prettierWorker,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// https://react.dev/reference/react/useReducer
|
|
165
|
-
const [state, dispatch] = useReducer(
|
|
166
|
-
vzReducer,
|
|
167
|
-
{ defaultTheme, initialUsername },
|
|
168
|
-
createInitialState,
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
// Unpack state.
|
|
172
|
-
const {
|
|
173
|
-
tabList,
|
|
174
|
-
activeFileId,
|
|
175
|
-
theme,
|
|
176
|
-
isSettingsOpen,
|
|
177
|
-
editorWantsFocus,
|
|
178
|
-
username,
|
|
179
|
-
} = state;
|
|
180
|
-
|
|
181
|
-
// Functions for dispatching actions to the reducer.
|
|
182
|
-
const {
|
|
183
|
-
setActiveFileId,
|
|
184
|
-
openTab,
|
|
185
|
-
closeTabs,
|
|
186
|
-
setTheme,
|
|
187
|
-
setIsSettingsOpen,
|
|
188
|
-
closeSettings,
|
|
189
|
-
editorNoLongerWantsFocus,
|
|
190
|
-
setUsername,
|
|
191
|
-
} = useActions(dispatch);
|
|
192
|
-
|
|
193
|
-
// The set of open directories.
|
|
194
|
-
// TODO move this into reducer/useActions
|
|
195
|
-
const { isDirectoryOpen, toggleDirectory } =
|
|
196
|
-
useOpenDirectories();
|
|
197
|
-
|
|
198
|
-
usePersistUsername(username);
|
|
199
|
-
|
|
200
|
-
// Cache of CodeMirror editors by file id.
|
|
201
|
-
const editorCache: EditorCache = useEditorCache();
|
|
202
|
-
|
|
203
|
-
// Handle dynamic theme changes.
|
|
204
|
-
useDynamicTheme(editorCache, theme);
|
|
205
|
-
|
|
206
|
-
// Handle file CRUD operations.
|
|
207
|
-
const {
|
|
208
|
-
createFile,
|
|
209
|
-
renameFile,
|
|
210
|
-
deleteFile,
|
|
211
|
-
deleteDirectory,
|
|
212
|
-
} = useFileCRUD({
|
|
213
|
-
submitOperation,
|
|
214
|
-
closeTabs,
|
|
215
|
-
openTab,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// Isolate the files object from the document.
|
|
219
|
-
const files: Files | null = content
|
|
220
|
-
? content.files
|
|
221
|
-
: null;
|
|
222
|
-
|
|
223
|
-
return (
|
|
224
|
-
<SplitPaneResizeProvider>
|
|
225
|
-
<div className="app">
|
|
226
|
-
<div className="left">
|
|
227
|
-
<VZSidebar
|
|
228
|
-
files={files}
|
|
229
|
-
createFile={createFile}
|
|
230
|
-
renameFile={renameFile}
|
|
231
|
-
deleteFile={deleteFile}
|
|
232
|
-
deleteDirectory={deleteDirectory}
|
|
233
|
-
openTab={openTab}
|
|
234
|
-
setIsSettingsOpen={setIsSettingsOpen}
|
|
235
|
-
isDirectoryOpen={isDirectoryOpen}
|
|
236
|
-
toggleDirectory={toggleDirectory}
|
|
237
|
-
activeFileId={activeFileId}
|
|
238
|
-
/>
|
|
239
|
-
<VZSettings
|
|
240
|
-
show={isSettingsOpen}
|
|
241
|
-
onClose={closeSettings}
|
|
242
|
-
theme={theme}
|
|
243
|
-
setTheme={setTheme}
|
|
244
|
-
username={username}
|
|
245
|
-
setUsername={setUsername}
|
|
246
|
-
/>
|
|
247
|
-
</div>
|
|
248
|
-
<div className="right">
|
|
249
|
-
<TabList
|
|
250
|
-
files={files}
|
|
251
|
-
tabList={tabList}
|
|
252
|
-
activeFileId={activeFileId}
|
|
253
|
-
setActiveFileId={setActiveFileId}
|
|
254
|
-
openTab={openTab}
|
|
255
|
-
closeTabs={closeTabs}
|
|
256
|
-
createFile={createFile}
|
|
257
|
-
/>
|
|
258
|
-
{content && activeFileId ? (
|
|
259
|
-
<CodeEditor
|
|
260
|
-
shareDBDoc={shareDBDoc}
|
|
261
|
-
submitOperation={submitOperation}
|
|
262
|
-
localPresence={localPresence}
|
|
263
|
-
docPresence={docPresence}
|
|
264
|
-
activeFileId={activeFileId}
|
|
265
|
-
theme={theme}
|
|
266
|
-
editorCache={editorCache}
|
|
267
|
-
editorWantsFocus={editorWantsFocus}
|
|
268
|
-
editorNoLongerWantsFocus={
|
|
269
|
-
editorNoLongerWantsFocus
|
|
270
|
-
}
|
|
271
|
-
username={username}
|
|
272
|
-
/>
|
|
273
|
-
) : null}
|
|
274
|
-
<CodeErrorOverlay errorMessage={prettierError} />
|
|
275
|
-
<PresenceNotifications
|
|
276
|
-
docPresence={docPresence}
|
|
277
|
-
localPresence={localPresence}
|
|
278
|
-
/>
|
|
279
|
-
</div>
|
|
280
|
-
<Resizer />
|
|
281
|
-
</div>
|
|
282
|
-
</SplitPaneResizeProvider>
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export default App;
|
|
File without changes
|