vzcode 2.0.0 → 2.3.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 (218) hide show
  1. package/dist/assets/{buildWorker-Dsx6rOdK.js → buildWorker-wLkQ0yz1.js} +64 -64
  2. package/dist/assets/{index-BM8tDh6M.css → index-BoFeK4GL.css} +1 -1
  3. package/dist/assets/{index-BgqNq-ww.js → index-DuUjtrt6.js} +107 -107
  4. package/dist/assets/{worker-BeBZGG1n.js → worker-DHxSPM7N.js} +78 -78
  5. package/dist/cli.js +113 -0
  6. package/dist/index.html +2 -2
  7. package/{src/ot.ts → dist/ot.js} +2 -14
  8. package/{src/randomId.ts → dist/randomId.js} +5 -6
  9. package/dist/runCode.js +20 -0
  10. package/dist/server/aiChatHandler/aiEditing.js +89 -0
  11. package/dist/server/aiChatHandler/chatOperations.js +360 -0
  12. package/dist/server/aiChatHandler/errorHandling.js +49 -0
  13. package/dist/server/aiChatHandler/index.js +112 -0
  14. package/dist/server/aiChatHandler/llmStreaming.js +284 -0
  15. package/dist/server/aiChatHandler/validation.js +19 -0
  16. package/dist/server/computeInitialDocument.js +146 -0
  17. package/{src/server/config.ts → dist/server/config.js} +4 -7
  18. package/{src/server/featureFlags.ts → dist/server/featureFlags.js} +0 -3
  19. package/dist/server/generateAIResponse.js +129 -0
  20. package/dist/server/handleAIAssist.js +39 -0
  21. package/dist/server/handleAICopilot.js +81 -0
  22. package/dist/server/index.js +297 -0
  23. package/dist/server/livekit.js +17 -0
  24. package/dist/server/prettier.js +90 -0
  25. package/{src/server/setupEnv.ts → dist/server/setupEnv.js} +1 -2
  26. package/dist/submitOperation.js +14 -0
  27. package/dist/types.js +1 -0
  28. package/dist/utils/fileDiff.js +66 -0
  29. package/package.json +23 -22
  30. package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
  31. package/src/client/AIAssist/AIAssistWidget/index.tsx +0 -135
  32. package/src/client/AIAssist/AIAssistWidget/style.scss +0 -47
  33. package/src/client/AIAssist/Spinner.jsx +0 -76
  34. package/src/client/AIAssist/formatFile.ts +0 -27
  35. package/src/client/AIAssist/generateFilesContext.ts +0 -25
  36. package/src/client/AIAssist/index.ts +0 -2
  37. package/src/client/AIAssist/startAIAssist.ts +0 -95
  38. package/src/client/App/index.tsx +0 -153
  39. package/src/client/App/style.scss +0 -82
  40. package/src/client/App/usePending.ts +0 -51
  41. package/src/client/App/useShareDB.ts +0 -161
  42. package/src/client/CodeEditor/Copilot/index.ts +0 -74
  43. package/src/client/CodeEditor/InteractiveWidgets/boolToggler.ts +0 -12
  44. package/src/client/CodeEditor/InteractiveWidgets/colorPicker.ts +0 -68
  45. package/src/client/CodeEditor/InteractiveWidgets/colorsInTextPlugin.ts +0 -174
  46. package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
  47. package/src/client/CodeEditor/InteractiveWidgets/index.ts +0 -44
  48. package/src/client/CodeEditor/InteractiveWidgets/markdownCheckboxToggler.ts +0 -12
  49. package/src/client/CodeEditor/InteractiveWidgets/numberDragger.ts +0 -20
  50. package/src/client/CodeEditor/InteractiveWidgets/rotateWidget.ts +0 -143
  51. package/src/client/CodeEditor/InteractiveWidgets/urlClicker.test.ts +0 -48
  52. package/src/client/CodeEditor/InteractiveWidgets/urlClicker.ts +0 -12
  53. package/src/client/CodeEditor/InteractiveWidgets/vec2Slider.ts +0 -25
  54. package/src/client/CodeEditor/basicSetup.ts +0 -73
  55. package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -615
  56. package/src/client/CodeEditor/index.tsx +0 -202
  57. package/src/client/CodeEditor/json1PresenceBroadcast.ts +0 -41
  58. package/src/client/CodeEditor/json1PresenceDisplay.ts +0 -350
  59. package/src/client/CodeEditor/rainbowBrackets.ts +0 -122
  60. package/src/client/CodeEditor/style.scss +0 -156
  61. package/src/client/CodeEditor/typescriptExtension/worker.ts +0 -32
  62. package/src/client/CodeErrorOverlay/index.tsx +0 -77
  63. package/src/client/CodeErrorOverlay/style.scss +0 -33
  64. package/src/client/Fonts/fonts.ts +0 -8
  65. package/src/client/Icons/AdjustmentSVG.tsx +0 -19
  66. package/src/client/Icons/BugSVG.tsx +0 -20
  67. package/src/client/Icons/CloseSVG.tsx +0 -19
  68. package/src/client/Icons/CssSVG.tsx +0 -16
  69. package/src/client/Icons/DirectoryArrowSVG.tsx +0 -19
  70. package/src/client/Icons/EditSVG.tsx +0 -19
  71. package/src/client/Icons/FileSVG.tsx +0 -19
  72. package/src/client/Icons/FolderSVG.tsx +0 -20
  73. package/src/client/Icons/GearSVG.tsx +0 -16
  74. package/src/client/Icons/HtmlSVG.tsx +0 -16
  75. package/src/client/Icons/JavaScriptSVG.tsx +0 -16
  76. package/src/client/Icons/JsonSVG.tsx +0 -16
  77. package/src/client/Icons/MarkdownSVG.tsx +0 -16
  78. package/src/client/Icons/MicSVG.tsx +0 -25
  79. package/src/client/Icons/NewSVG.tsx +0 -19
  80. package/src/client/Icons/PinSVG.tsx +0 -14
  81. package/src/client/Icons/PlaySVG.tsx +0 -16
  82. package/src/client/Icons/QuestionMarkSVG.tsx +0 -18
  83. package/src/client/Icons/ReactSVG.tsx +0 -16
  84. package/src/client/Icons/SearchSVG.tsx +0 -20
  85. package/src/client/Icons/SparklesSVG.tsx +0 -23
  86. package/src/client/Icons/SplitEditorSVG.tsx +0 -34
  87. package/src/client/Icons/StopSVG.tsx +0 -15
  88. package/src/client/Icons/SvelteSVG.tsx +0 -16
  89. package/src/client/Icons/TrashSVG.tsx +0 -19
  90. package/src/client/Icons/TypeScriptSVG.tsx +0 -16
  91. package/src/client/Icons/index.tsx +0 -24
  92. package/src/client/ImageViewer/index.tsx +0 -91
  93. package/src/client/ImageViewer/style.scss +0 -41
  94. package/src/client/PresenceNotifications/PresenceNotifications.test.ts +0 -134
  95. package/src/client/PresenceNotifications/index.tsx +0 -158
  96. package/src/client/PresenceNotifications/style.scss +0 -17
  97. package/src/client/RunCodeWidget/index.tsx +0 -117
  98. package/src/client/RunCodeWidget/style.scss +0 -24
  99. package/src/client/SplitPaneResizeContext.tsx +0 -159
  100. package/src/client/TabList/Tab.tsx +0 -73
  101. package/src/client/TabList/index.tsx +0 -35
  102. package/src/client/TabList/style.scss +0 -51
  103. package/src/client/VZCodeContext/index.tsx +0 -29
  104. package/src/client/VZCodeContext/types.ts +0 -249
  105. package/src/client/VZCodeContext/useVZCodeState.ts +0 -584
  106. package/src/client/VZKeyboardShortcutsDoc.tsx +0 -148
  107. package/src/client/VZLeft.tsx +0 -28
  108. package/src/client/VZMiddle.tsx +0 -172
  109. package/src/client/VZResizer/index.tsx +0 -128
  110. package/src/client/VZResizer/styles.scss +0 -33
  111. package/src/client/VZRight.tsx +0 -113
  112. package/src/client/VZSettings.tsx +0 -275
  113. package/src/client/VZSidebar/AIChat/ChatInput.tsx +0 -196
  114. package/src/client/VZSidebar/AIChat/DiffView.scss +0 -136
  115. package/src/client/VZSidebar/AIChat/DiffView.tsx +0 -176
  116. package/src/client/VZSidebar/AIChat/Message.tsx +0 -143
  117. package/src/client/VZSidebar/AIChat/MessageList.tsx +0 -205
  118. package/src/client/VZSidebar/AIChat/StreamingMessage.tsx +0 -35
  119. package/src/client/VZSidebar/AIChat/ThinkingScratchpad.tsx +0 -156
  120. package/src/client/VZSidebar/AIChat/TypingIndicator.tsx +0 -19
  121. package/src/client/VZSidebar/AIChat/index.tsx +0 -273
  122. package/src/client/VZSidebar/AIChat/styles.scss +0 -627
  123. package/src/client/VZSidebar/CreateDirModal.tsx +0 -111
  124. package/src/client/VZSidebar/CreateFileModal.tsx +0 -111
  125. package/src/client/VZSidebar/DeleteConfirmationModal.tsx +0 -76
  126. package/src/client/VZSidebar/DirectoryListing.tsx +0 -89
  127. package/src/client/VZSidebar/EmptyState.tsx +0 -11
  128. package/src/client/VZSidebar/FileListing.tsx +0 -91
  129. package/src/client/VZSidebar/FileTypeIcon.tsx +0 -49
  130. package/src/client/VZSidebar/Item.tsx +0 -237
  131. package/src/client/VZSidebar/Listing.tsx +0 -47
  132. package/src/client/VZSidebar/Search.tsx +0 -527
  133. package/src/client/VZSidebar/VisualEditor.tsx +0 -295
  134. package/src/client/VZSidebar/VoiceChatModal.tsx +0 -121
  135. package/src/client/VZSidebar/aiCopyPaste.ts +0 -199
  136. package/src/client/VZSidebar/index.tsx +0 -728
  137. package/src/client/VZSidebar/styles.scss +0 -612
  138. package/src/client/VZSidebar/useDragAndDrop.tsx +0 -408
  139. package/src/client/bootstrap.ts +0 -26
  140. package/src/client/buildWorker.ts +0 -3
  141. package/src/client/featureFlags.ts +0 -8
  142. package/src/client/generateRequestId.ts +0 -6
  143. package/src/client/getFileTree.ts +0 -53
  144. package/src/client/index.ts +0 -19
  145. package/src/client/main.jsx +0 -10
  146. package/src/client/presenceColor.ts +0 -8
  147. package/src/client/shouldTriggerRun.ts +0 -31
  148. package/src/client/sortFileTree.ts +0 -21
  149. package/src/client/tabsSearchParameters.test.ts +0 -79
  150. package/src/client/tabsSearchParameters.ts +0 -137
  151. package/src/client/themes/index.ts +0 -7
  152. package/src/client/themes/themes.ts +0 -77
  153. package/src/client/themes/uiwImports.ts +0 -32
  154. package/src/client/themes/useDynamicTheme.ts +0 -29
  155. package/src/client/themes/vizhubTheme/colors.ts +0 -80
  156. package/src/client/themes/vizhubTheme/index.ts +0 -193
  157. package/src/client/useActions.ts +0 -288
  158. package/src/client/useESLint/index.ts +0 -72
  159. package/src/client/useESLint/worker.ts +0 -113
  160. package/src/client/useEditorCache.ts +0 -35
  161. package/src/client/useFileCRUD.ts +0 -228
  162. package/src/client/useKeyboardShortcuts.ts +0 -451
  163. package/src/client/useOpenDirectories.ts +0 -99
  164. package/src/client/usePresenceAutoFollow.ts +0 -85
  165. package/src/client/usePrettier/index.ts +0 -178
  166. package/src/client/usePrettier/worker.ts +0 -109
  167. package/src/client/useRunCode.tsx +0 -15
  168. package/src/client/useRuntimeError.ts +0 -32
  169. package/src/client/useSubmitOperation.ts +0 -15
  170. package/src/client/useURLSync.ts +0 -137
  171. package/src/client/usernameLocalStorage.ts +0 -43
  172. package/src/client/utils/fileExtension.ts +0 -10
  173. package/src/client/utils/isImageFile.ts +0 -12
  174. package/src/client/vzReducer/aiChatReducer.ts +0 -44
  175. package/src/client/vzReducer/closeTabReducer.test.ts +0 -205
  176. package/src/client/vzReducer/closeTabsReducer.ts +0 -96
  177. package/src/client/vzReducer/createInitialState.ts +0 -38
  178. package/src/client/vzReducer/editorNoLongerWantsFocusReducer.ts +0 -9
  179. package/src/client/vzReducer/findPane.ts +0 -19
  180. package/src/client/vzReducer/index.ts +0 -250
  181. package/src/client/vzReducer/openTabReducer.test.ts +0 -127
  182. package/src/client/vzReducer/openTabReducer.ts +0 -74
  183. package/src/client/vzReducer/searchReducer.test.ts +0 -292
  184. package/src/client/vzReducer/searchReducer.ts +0 -181
  185. package/src/client/vzReducer/setActiveFileIdReducer.ts +0 -28
  186. package/src/client/vzReducer/setActiveFileLeftRightReducer.ts +0 -76
  187. package/src/client/vzReducer/setIsDocOpenReducer.ts +0 -9
  188. package/src/client/vzReducer/setIsSettingsOpenReducer.ts +0 -9
  189. package/src/client/vzReducer/setThemeReducer.ts +0 -9
  190. package/src/client/vzReducer/setUsernameReducer.ts +0 -9
  191. package/src/client/vzReducer/splitCurrentPaneReducer.ts +0 -66
  192. package/src/client/vzReducer/toggleAutoFollowReducer.ts +0 -12
  193. package/src/client/vzReducer/updatePane.ts +0 -40
  194. package/src/client/vzReducer/updatePresenceIndicatorReducer.ts +0 -30
  195. package/src/client/vzReducer/visualEditorReducer.ts +0 -9
  196. package/src/reactRouterExports.ts +0 -15
  197. package/src/runCode.ts +0 -27
  198. package/src/server/aiChatHandler/aiEditing.ts +0 -152
  199. package/src/server/aiChatHandler/chatOperations.ts +0 -510
  200. package/src/server/aiChatHandler/errorHandling.ts +0 -66
  201. package/src/server/aiChatHandler/index.ts +0 -200
  202. package/src/server/aiChatHandler/llmStreaming.ts +0 -419
  203. package/src/server/aiChatHandler/undoHandler.ts +0 -97
  204. package/src/server/aiChatHandler/validation.ts +0 -24
  205. package/src/server/computeInitialDocument.ts +0 -220
  206. package/src/server/generateAIResponse.ts +0 -188
  207. package/src/server/handleAIAssist.ts +0 -53
  208. package/src/server/handleAIChatUndo.ts +0 -2
  209. package/src/server/handleAICopilot.ts +0 -97
  210. package/src/server/index.ts +0 -388
  211. package/src/server/livekit.ts +0 -24
  212. package/src/server/prettier.ts +0 -115
  213. package/src/submitOperation.ts +0 -25
  214. package/src/types.ts +0 -205
  215. package/src/utils/fileDiff.ts +0 -117
  216. package/src/vite-env.d.ts +0 -10
  217. /package/{src/server/handleAIChatMessage.ts → dist/server/handleAIChatMessage.js} +0 -0
  218. /package/{src/server/isDirectory.ts → dist/server/isDirectory.js} +0 -0
@@ -1,288 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { ThemeLabel } from './themes';
3
- import {
4
- PresenceIndicator,
5
- SearchFileVisibility,
6
- ShareDBDoc,
7
- TabState,
8
- Username,
9
- } from '../types';
10
- import { VizFileId, VizContent } from '@vizhub/viz-types';
11
- import { VZAction } from './vzReducer';
12
-
13
- // This is a custom hook that returns a set of functions
14
- // that can be used to dispatch actions to the reducer.
15
- export const useActions = (
16
- dispatch: (action: VZAction) => void,
17
- ) => {
18
- const setActiveFileId = useCallback(
19
- (activeFileId: VizFileId) => {
20
- dispatch({
21
- type: 'set_active_file_id',
22
- activeFileId,
23
- });
24
- },
25
- [dispatch],
26
- );
27
-
28
- const setActiveFileLeft = useCallback(() => {
29
- dispatch({ type: 'set_active_file_left' });
30
- }, [dispatch]);
31
-
32
- const setActiveFileRight = useCallback(() => {
33
- dispatch({ type: 'set_active_file_right' });
34
- }, [dispatch]);
35
-
36
- const openTab = useCallback(
37
- (tabState: TabState): void => {
38
- dispatch({
39
- type: 'open_tab',
40
- fileId: tabState.fileId,
41
- isTransient: tabState.isTransient,
42
- });
43
- },
44
- [dispatch],
45
- );
46
-
47
- const closeTabs = useCallback(
48
- (fileIdsToClose: Array<VizFileId>) => {
49
- dispatch({
50
- type: 'close_tabs',
51
- fileIdsToClose,
52
- });
53
- },
54
- [dispatch],
55
- );
56
-
57
- const setTheme = useCallback(
58
- (themeLabel: ThemeLabel) => {
59
- dispatch({
60
- type: 'set_theme',
61
- themeLabel: themeLabel,
62
- });
63
- },
64
- [dispatch],
65
- );
66
-
67
- // True to show the visual editor
68
- const setIsVisualEditorOpen = useCallback(
69
- (value: boolean) => {
70
- dispatch({
71
- type: 'set_is_visual_editor_open',
72
- value: value,
73
- });
74
- },
75
- [dispatch],
76
- );
77
-
78
- // True to show the settings modal.
79
- const setIsSearchOpen = useCallback(
80
- (value: boolean) => {
81
- dispatch({
82
- type: 'set_is_search_open',
83
- value: value,
84
- });
85
- },
86
- [dispatch],
87
- );
88
-
89
- // Update search pattern
90
- const setSearch = useCallback(
91
- (pattern: string) => {
92
- dispatch({
93
- type: 'set_search',
94
- value: pattern,
95
- });
96
- },
97
- [dispatch],
98
- );
99
-
100
- // Update search results based on current pattern
101
- const setSearchResults = useCallback(
102
- (files: ShareDBDoc<VizContent>) => {
103
- dispatch({
104
- type: 'set_search_results',
105
- files: files,
106
- });
107
- },
108
- [dispatch],
109
- );
110
-
111
- // Update search results file visibility based on current pattern
112
- const setSearchFileVisibility = useCallback(
113
- (
114
- files: ShareDBDoc<VizContent>,
115
- id: string,
116
- visibility: SearchFileVisibility,
117
- ) => {
118
- dispatch({
119
- type: 'set_search_file_visibility',
120
- files: files,
121
- id: id,
122
- visibility: visibility,
123
- });
124
- },
125
- [dispatch],
126
- );
127
-
128
- // Update search results file matching line visibility to be
129
- const setSearchLineVisibility = useCallback(
130
- (
131
- files: ShareDBDoc<VizContent>,
132
- id: string,
133
- line: number,
134
- ) => {
135
- dispatch({
136
- type: 'hide_search_results_line',
137
- files: files,
138
- id: id,
139
- line: line,
140
- });
141
- },
142
- [dispatch],
143
- );
144
-
145
- // Update search results active element
146
- const setSearchFocusedIndex = useCallback(
147
- (focusedIndex: number, childIndex: number) => {
148
- dispatch({
149
- type: 'set_active_search_index',
150
- focusedIndex: focusedIndex,
151
- childIndex: childIndex,
152
- });
153
- },
154
- [dispatch],
155
- );
156
-
157
- // Toggle the focused variable, which should focus the search input
158
- const toggleSearchFocused = useCallback(() => {
159
- dispatch({
160
- type: 'toggle_search_focused',
161
- });
162
- }, [dispatch]);
163
-
164
- // True to show the AI chat instead of files
165
- const setIsAIChatOpen = useCallback(
166
- (value: boolean) => {
167
- dispatch({
168
- type: 'set_is_ai_chat_open',
169
- value: value,
170
- });
171
- },
172
- [dispatch],
173
- );
174
-
175
- // Toggle the focused variable, which should focus the AI chat input
176
- const toggleAIChatFocused = useCallback(() => {
177
- dispatch({
178
- type: 'toggle_ai_chat_focused',
179
- });
180
- }, [dispatch]);
181
-
182
- // Set the AI chat mode (ask or edit)
183
- const setAIChatMode = useCallback(
184
- (mode: 'ask' | 'edit') => {
185
- dispatch({
186
- type: 'set_ai_chat_mode',
187
- mode,
188
- });
189
- },
190
- [dispatch],
191
- );
192
-
193
- // True to show the settings modal.
194
- const setIsSettingsOpen = useCallback(
195
- (value: boolean) => {
196
- dispatch({
197
- type: 'set_is_settings_open',
198
- value: value,
199
- });
200
- },
201
- [dispatch],
202
- );
203
-
204
- const setIsDocOpen = useCallback(
205
- (value: boolean) => {
206
- dispatch({
207
- type: 'set_is_doc_open',
208
- value: value,
209
- });
210
- },
211
- [dispatch],
212
- );
213
-
214
- const closeSettings = useCallback(() => {
215
- setIsSettingsOpen(false);
216
- }, [setIsSettingsOpen]);
217
-
218
- const closeDoc = useCallback(() => {
219
- setIsDocOpen(false);
220
- }, [setIsDocOpen]);
221
-
222
- const editorNoLongerWantsFocus = useCallback(() => {
223
- dispatch({
224
- type: 'editor_no_longer_wants_focus',
225
- });
226
- }, [dispatch]);
227
-
228
- const setUsername = useCallback(
229
- (username: Username) => {
230
- dispatch({
231
- type: 'set_username',
232
- username,
233
- });
234
- },
235
- [dispatch],
236
- );
237
-
238
- const toggleAutoFollow = useCallback(() => {
239
- dispatch({
240
- type: 'toggle_auto_follow',
241
- });
242
- }, [dispatch]);
243
-
244
- const updatePresenceIndicator = useCallback(
245
- (presenceIndicator: PresenceIndicator) => {
246
- dispatch({
247
- type: 'update_presence_indicator',
248
- presenceIndicator,
249
- });
250
- },
251
- [dispatch],
252
- );
253
-
254
- const splitCurrentPane = useCallback(() => {
255
- dispatch({
256
- type: 'split_current_pane',
257
- });
258
- }, [dispatch]);
259
-
260
- return {
261
- setActiveFileId,
262
- setActiveFileLeft,
263
- setActiveFileRight,
264
- openTab,
265
- closeTabs,
266
- setTheme,
267
- setIsVisualEditorOpen,
268
- setIsSearchOpen,
269
- setSearch,
270
- setSearchResults,
271
- setSearchFileVisibility,
272
- setSearchLineVisibility,
273
- setSearchFocusedIndex,
274
- toggleSearchFocused,
275
- setIsAIChatOpen,
276
- toggleAIChatFocused,
277
- setAIChatMode,
278
- setIsSettingsOpen,
279
- setIsDocOpen,
280
- closeSettings,
281
- closeDoc,
282
- editorNoLongerWantsFocus,
283
- setUsername,
284
- toggleAutoFollow,
285
- updatePresenceIndicator,
286
- splitCurrentPane,
287
- };
288
- };
@@ -1,72 +0,0 @@
1
- import { useState, useEffect, useCallback } from 'react';
2
- import { EditorView } from '@codemirror/view';
3
- import { Diagnostic } from '@codemirror/lint';
4
- // @ts-ignore - Worker import
5
- import ESLintWorker from './worker?worker';
6
- import { enableESLint } from '../../server/featureFlags';
7
- import { fileNameStateField } from '../CodeEditor/getOrCreateEditor';
8
-
9
- let requestCounter = 0;
10
- const pendingRequests = new Map();
11
-
12
- export const useESLint = () => {
13
- const [worker, setWorker] = useState(null);
14
-
15
- // Initialize the work in an effect so it does not run during SSR.
16
- useEffect(() => {
17
- setWorker(new ESLintWorker());
18
- }, []);
19
-
20
- useEffect(() => {
21
- // Wait for the worker to be initialized
22
- if (!worker) return;
23
-
24
- const handleMessage = (event: MessageEvent) => {
25
- const { diagnostics, requestId, error } = event.data;
26
-
27
- if (error) {
28
- console.error('[ESLint] Error:', error);
29
- }
30
-
31
- const resolve = pendingRequests.get(requestId);
32
- if (resolve) {
33
- resolve(diagnostics);
34
- pendingRequests.delete(requestId);
35
- }
36
- };
37
-
38
- worker.addEventListener('message', handleMessage);
39
-
40
- return () => {
41
- worker.removeEventListener('message', handleMessage);
42
- worker.terminate();
43
- };
44
- }, [worker]);
45
-
46
- const esLintSource = useCallback(
47
- async (
48
- view: EditorView,
49
- ): Promise<readonly Diagnostic[]> => {
50
- if (!enableESLint) return [];
51
-
52
- // Retrieve the file name from the editor's state
53
- const fileName = view.state.field(fileNameStateField);
54
-
55
- try {
56
- const code = view.state.doc.toString();
57
- const requestId = requestCounter++;
58
-
59
- return new Promise<Diagnostic[]>((resolve) => {
60
- pendingRequests.set(requestId, resolve);
61
- worker.postMessage({ code, requestId, fileName });
62
- });
63
- } catch (e) {
64
- console.error('[ESLint] Error in linter:', e);
65
- return [];
66
- }
67
- },
68
- [worker],
69
- );
70
-
71
- return { esLintSource };
72
- };
@@ -1,113 +0,0 @@
1
- import * as eslint from 'eslint-linter-browserify';
2
- import globals from 'globals';
3
-
4
- // Feature flag to enable or disable JSX linting
5
- // It's disabled for now since it doesn't work.
6
- // See issue:
7
- // https://github.com/vizhub-core/vzcode/issues/921
8
- const enableJSXLinting = false;
9
-
10
- const linter = new eslint.Linter();
11
-
12
- const config = {
13
- languageOptions: {
14
- globals: {
15
- ...globals.browser,
16
- ...globals.es2021,
17
- },
18
- parserOptions: {
19
- ecmaVersion: 2022,
20
- sourceType: 'module',
21
- ecmaFeatures: {
22
- // Add this to enable JSX parsing
23
- jsx: true,
24
- },
25
- },
26
- },
27
- rules: {
28
- 'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
29
- 'no-undef': 'error',
30
- semi: 'off',
31
- },
32
- };
33
-
34
- // Helper function to convert line/column to character offset
35
- function getOffset(
36
- docLines: string[],
37
- line: number,
38
- column: number,
39
- ): number {
40
- let offset = 0;
41
- for (let i = 0; i < line - 1; i++) {
42
- offset += (docLines[i] ? docLines[i].length : 0) + 1; // +1 for newline
43
- }
44
- return offset + column - 1;
45
- }
46
-
47
- self.onmessage = (event) => {
48
- const { code, requestId, fileName } = event.data;
49
- if (typeof code !== 'string') {
50
- self.postMessage({
51
- diagnostics: [],
52
- requestId,
53
- error: 'Invalid code received',
54
- });
55
- return;
56
- }
57
-
58
- // Only lint .js files, and .jsx files if enableJSXLinting is true
59
- if (!fileName) {
60
- self.postMessage({ diagnostics: [], requestId });
61
- return;
62
- }
63
-
64
- const isJsFile = /\.js$/i.test(fileName);
65
- const isJsxFile = /\.jsx$/i.test(fileName);
66
-
67
- if (!isJsFile && (!isJsxFile || !enableJSXLinting)) {
68
- self.postMessage({ diagnostics: [], requestId });
69
- return;
70
- }
71
-
72
- try {
73
- const messages = linter.verify(code, config as any);
74
- const docLines = code.split('\n');
75
-
76
- const diagnostics = messages.map((msg) => {
77
- const from = getOffset(
78
- docLines,
79
- msg.line,
80
- msg.column,
81
- );
82
- // endLine and endColumn may not always exist
83
- const to =
84
- msg.endLine && msg.endColumn
85
- ? getOffset(docLines, msg.endLine, msg.endColumn)
86
- : from +
87
- (msg.fix?.range[1] - msg.fix?.range[0] || 1);
88
-
89
- return {
90
- from,
91
- to,
92
- severity:
93
- msg.severity === 2
94
- ? 'error'
95
- : msg.severity === 1
96
- ? 'warning'
97
- : 'info',
98
- message: msg.message,
99
- source: msg.ruleId
100
- ? `eslint(${msg.ruleId})`
101
- : 'eslint',
102
- };
103
- });
104
- self.postMessage({ diagnostics, requestId });
105
- } catch (e: any) {
106
- console.error('Error linting in ESLint worker:', e);
107
- self.postMessage({
108
- error: e.message,
109
- diagnostics: [],
110
- requestId,
111
- });
112
- }
113
- };
@@ -1,35 +0,0 @@
1
- import { useRef } from 'react';
2
- import { VizFileId } from '@vizhub/viz-types';
3
- import { PaneId } from '../types';
4
- import { EditorView } from 'codemirror';
5
-
6
- export type EditorCacheValue = {
7
- editor: EditorView;
8
- themeCompartment: any;
9
- languageCompartment?: any;
10
- scrollPosition?: number;
11
- };
12
-
13
- export type EditorCacheKey = string;
14
-
15
- export const editorCacheKey = (
16
- fileId: VizFileId,
17
- paneId: PaneId,
18
- ): EditorCacheKey => fileId + '|' + paneId;
19
-
20
- export type EditorCache = Map<
21
- EditorCacheKey,
22
- EditorCacheValue
23
- >;
24
-
25
- export const useEditorCache = () => {
26
- // Singleton cache of CodeMirror instances
27
- // These are created, but never destroyed.
28
- // TODO consider invalidating this cache at some point.
29
- // Right now these editor instances just keep accumulating,
30
- // and they all retain their connections to ShareDB.
31
- // This has not been an issue so far, but it could become one.
32
- const editorCacheRef = useRef<EditorCache>(new Map());
33
-
34
- return editorCacheRef.current;
35
- };