vzcode 2.2.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 (220) 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-CpxqGhXj.js → index-DuUjtrt6.js} +150 -150
  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 +22 -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/MicOffSVG.tsx +0 -35
  79. package/src/client/Icons/MicSVG.tsx +0 -25
  80. package/src/client/Icons/NewSVG.tsx +0 -19
  81. package/src/client/Icons/PinSVG.tsx +0 -14
  82. package/src/client/Icons/PlaySVG.tsx +0 -16
  83. package/src/client/Icons/QuestionMarkSVG.tsx +0 -18
  84. package/src/client/Icons/ReactSVG.tsx +0 -16
  85. package/src/client/Icons/SearchSVG.tsx +0 -20
  86. package/src/client/Icons/SparklesSVG.tsx +0 -23
  87. package/src/client/Icons/SplitEditorSVG.tsx +0 -34
  88. package/src/client/Icons/StopSVG.tsx +0 -15
  89. package/src/client/Icons/SvelteSVG.tsx +0 -16
  90. package/src/client/Icons/TrashSVG.tsx +0 -19
  91. package/src/client/Icons/TypeScriptSVG.tsx +0 -16
  92. package/src/client/Icons/index.tsx +0 -26
  93. package/src/client/ImageViewer/index.tsx +0 -91
  94. package/src/client/ImageViewer/style.scss +0 -41
  95. package/src/client/PresenceNotifications/PresenceNotifications.test.ts +0 -134
  96. package/src/client/PresenceNotifications/index.tsx +0 -158
  97. package/src/client/PresenceNotifications/style.scss +0 -17
  98. package/src/client/RunCodeWidget/index.tsx +0 -117
  99. package/src/client/RunCodeWidget/style.scss +0 -24
  100. package/src/client/SplitPaneResizeContext.tsx +0 -159
  101. package/src/client/TabList/Tab.tsx +0 -73
  102. package/src/client/TabList/index.tsx +0 -35
  103. package/src/client/TabList/style.scss +0 -51
  104. package/src/client/VZCodeContext/index.tsx +0 -29
  105. package/src/client/VZCodeContext/types.ts +0 -249
  106. package/src/client/VZCodeContext/useVZCodeState.ts +0 -584
  107. package/src/client/VZKeyboardShortcutsDoc.tsx +0 -148
  108. package/src/client/VZLeft.tsx +0 -28
  109. package/src/client/VZMiddle.tsx +0 -172
  110. package/src/client/VZResizer/index.tsx +0 -128
  111. package/src/client/VZResizer/styles.scss +0 -33
  112. package/src/client/VZRight.tsx +0 -113
  113. package/src/client/VZSettings.tsx +0 -275
  114. package/src/client/VZSidebar/AIChat/ChatInput.tsx +0 -239
  115. package/src/client/VZSidebar/AIChat/DiffView.scss +0 -136
  116. package/src/client/VZSidebar/AIChat/DiffView.tsx +0 -176
  117. package/src/client/VZSidebar/AIChat/Message.tsx +0 -143
  118. package/src/client/VZSidebar/AIChat/MessageList.tsx +0 -205
  119. package/src/client/VZSidebar/AIChat/StreamingMessage.tsx +0 -35
  120. package/src/client/VZSidebar/AIChat/ThinkingScratchpad.tsx +0 -156
  121. package/src/client/VZSidebar/AIChat/TypingIndicator.tsx +0 -19
  122. package/src/client/VZSidebar/AIChat/index.tsx +0 -273
  123. package/src/client/VZSidebar/AIChat/styles.scss +0 -627
  124. package/src/client/VZSidebar/AIChat/useSpeechRecognition.ts +0 -117
  125. package/src/client/VZSidebar/CreateDirModal.tsx +0 -111
  126. package/src/client/VZSidebar/CreateFileModal.tsx +0 -111
  127. package/src/client/VZSidebar/DeleteConfirmationModal.tsx +0 -76
  128. package/src/client/VZSidebar/DirectoryListing.tsx +0 -89
  129. package/src/client/VZSidebar/EmptyState.tsx +0 -11
  130. package/src/client/VZSidebar/FileListing.tsx +0 -91
  131. package/src/client/VZSidebar/FileTypeIcon.tsx +0 -49
  132. package/src/client/VZSidebar/Item.tsx +0 -237
  133. package/src/client/VZSidebar/Listing.tsx +0 -47
  134. package/src/client/VZSidebar/Search.tsx +0 -527
  135. package/src/client/VZSidebar/VisualEditor.tsx +0 -282
  136. package/src/client/VZSidebar/VoiceChatModal.tsx +0 -121
  137. package/src/client/VZSidebar/aiCopyPaste.ts +0 -199
  138. package/src/client/VZSidebar/index.tsx +0 -728
  139. package/src/client/VZSidebar/styles.scss +0 -612
  140. package/src/client/VZSidebar/useDragAndDrop.tsx +0 -408
  141. package/src/client/bootstrap.ts +0 -26
  142. package/src/client/buildWorker.ts +0 -3
  143. package/src/client/featureFlags.ts +0 -8
  144. package/src/client/generateRequestId.ts +0 -6
  145. package/src/client/getFileTree.ts +0 -53
  146. package/src/client/index.ts +0 -19
  147. package/src/client/main.jsx +0 -10
  148. package/src/client/presenceColor.ts +0 -8
  149. package/src/client/shouldTriggerRun.ts +0 -31
  150. package/src/client/sortFileTree.ts +0 -21
  151. package/src/client/tabsSearchParameters.test.ts +0 -79
  152. package/src/client/tabsSearchParameters.ts +0 -137
  153. package/src/client/themes/index.ts +0 -7
  154. package/src/client/themes/themes.ts +0 -77
  155. package/src/client/themes/uiwImports.ts +0 -32
  156. package/src/client/themes/useDynamicTheme.ts +0 -29
  157. package/src/client/themes/vizhubTheme/colors.ts +0 -80
  158. package/src/client/themes/vizhubTheme/index.ts +0 -193
  159. package/src/client/useActions.ts +0 -288
  160. package/src/client/useESLint/index.ts +0 -72
  161. package/src/client/useESLint/worker.ts +0 -113
  162. package/src/client/useEditorCache.ts +0 -35
  163. package/src/client/useFileCRUD.ts +0 -228
  164. package/src/client/useKeyboardShortcuts.ts +0 -451
  165. package/src/client/useOpenDirectories.ts +0 -99
  166. package/src/client/usePresenceAutoFollow.ts +0 -85
  167. package/src/client/usePrettier/index.ts +0 -178
  168. package/src/client/usePrettier/worker.ts +0 -109
  169. package/src/client/useRunCode.tsx +0 -15
  170. package/src/client/useRuntimeError.ts +0 -32
  171. package/src/client/useSubmitOperation.ts +0 -15
  172. package/src/client/useURLSync.ts +0 -137
  173. package/src/client/usernameLocalStorage.ts +0 -43
  174. package/src/client/utils/fileExtension.ts +0 -10
  175. package/src/client/utils/isImageFile.ts +0 -12
  176. package/src/client/vzReducer/aiChatReducer.ts +0 -44
  177. package/src/client/vzReducer/closeTabReducer.test.ts +0 -205
  178. package/src/client/vzReducer/closeTabsReducer.ts +0 -96
  179. package/src/client/vzReducer/createInitialState.ts +0 -38
  180. package/src/client/vzReducer/editorNoLongerWantsFocusReducer.ts +0 -9
  181. package/src/client/vzReducer/findPane.ts +0 -19
  182. package/src/client/vzReducer/index.ts +0 -250
  183. package/src/client/vzReducer/openTabReducer.test.ts +0 -127
  184. package/src/client/vzReducer/openTabReducer.ts +0 -74
  185. package/src/client/vzReducer/searchReducer.test.ts +0 -292
  186. package/src/client/vzReducer/searchReducer.ts +0 -181
  187. package/src/client/vzReducer/setActiveFileIdReducer.ts +0 -28
  188. package/src/client/vzReducer/setActiveFileLeftRightReducer.ts +0 -76
  189. package/src/client/vzReducer/setIsDocOpenReducer.ts +0 -9
  190. package/src/client/vzReducer/setIsSettingsOpenReducer.ts +0 -9
  191. package/src/client/vzReducer/setThemeReducer.ts +0 -9
  192. package/src/client/vzReducer/setUsernameReducer.ts +0 -9
  193. package/src/client/vzReducer/splitCurrentPaneReducer.ts +0 -66
  194. package/src/client/vzReducer/toggleAutoFollowReducer.ts +0 -12
  195. package/src/client/vzReducer/updatePane.ts +0 -40
  196. package/src/client/vzReducer/updatePresenceIndicatorReducer.ts +0 -30
  197. package/src/client/vzReducer/visualEditorReducer.ts +0 -9
  198. package/src/reactRouterExports.ts +0 -15
  199. package/src/runCode.ts +0 -27
  200. package/src/server/aiChatHandler/aiEditing.ts +0 -152
  201. package/src/server/aiChatHandler/chatOperations.ts +0 -510
  202. package/src/server/aiChatHandler/errorHandling.ts +0 -66
  203. package/src/server/aiChatHandler/index.ts +0 -200
  204. package/src/server/aiChatHandler/llmStreaming.ts +0 -419
  205. package/src/server/aiChatHandler/undoHandler.ts +0 -97
  206. package/src/server/aiChatHandler/validation.ts +0 -24
  207. package/src/server/computeInitialDocument.ts +0 -220
  208. package/src/server/generateAIResponse.ts +0 -188
  209. package/src/server/handleAIAssist.ts +0 -53
  210. package/src/server/handleAIChatUndo.ts +0 -2
  211. package/src/server/handleAICopilot.ts +0 -97
  212. package/src/server/index.ts +0 -388
  213. package/src/server/livekit.ts +0 -24
  214. package/src/server/prettier.ts +0 -115
  215. package/src/submitOperation.ts +0 -25
  216. package/src/types.ts +0 -205
  217. package/src/utils/fileDiff.ts +0 -117
  218. package/src/vite-env.d.ts +0 -10
  219. /package/{src/server/handleAIChatMessage.ts → dist/server/handleAIChatMessage.js} +0 -0
  220. /package/{src/server/isDirectory.ts → dist/server/isDirectory.js} +0 -0
@@ -1,148 +0,0 @@
1
- import React, { useCallback, useContext } from 'react';
2
- import { Button, Modal, Form } from './bootstrap';
3
- import { ThemeLabel, themes } from './themes';
4
- import { VZCodeContext } from './VZCodeContext';
5
-
6
- export const VZKeyboardShortcutsDoc = ({
7
- enableUsernameField = true,
8
- }: {
9
- // Feature flag to enable/disable username field
10
- enableUsernameField?: boolean;
11
- }) => {
12
- const {
13
- isDocOpen,
14
- closeDoc,
15
-
16
- setTheme,
17
-
18
- setUsername,
19
- } = useContext(VZCodeContext);
20
-
21
- const handleThemeChange = useCallback(
22
- (event: React.ChangeEvent<HTMLSelectElement>) => {
23
- setTheme(event.target.value as ThemeLabel);
24
- },
25
- [],
26
- );
27
-
28
- return isDocOpen ? (
29
- <Modal
30
- className="vz-settings"
31
- show={isDocOpen}
32
- onHide={closeDoc}
33
- animation={false}
34
- >
35
- <Modal.Header closeButton>
36
- <Modal.Title>Keyboard Shortcuts</Modal.Title>
37
- </Modal.Header>
38
- <Modal.Body className="pt-1">
39
- <Form.Group className="mb-3">
40
- <Form.Text className="text-muted">
41
- Keyboard shortcuts and interactive widgets for
42
- quick actions
43
- </Form.Text>
44
- </Form.Group>
45
- <Form.Group>
46
- {/* <Form.Label>WINDOWS</Form.Label> */}
47
- <ul>
48
- <li>
49
- <strong>
50
- <kbd>Ctrl</kbd> + <kbd>S</kbd>
51
- </strong>{' '}
52
- or{' '}
53
- <strong>
54
- <kbd>Shift↑</kbd> + <kbd>Enter←</kbd>
55
- </strong>{' '}
56
- <br />
57
- <span>Run and format code</span>
58
- </li>
59
- <li>
60
- <strong>
61
- <kbd>Alt</kbd> + Drag on a number
62
- </strong>
63
- <br />
64
- <span>
65
- Modify the number by dragging left or right
66
- </span>
67
- </li>
68
- <li>
69
- <strong>
70
- <kbd>Alt</kbd> + Click on a hex color
71
- </strong>
72
- <br />
73
- <span>
74
- Open a color picker to modify the color
75
- </span>
76
- </li>
77
- <li>
78
- <strong>
79
- <kbd>Alt</kbd> + <kbd>W</kbd>
80
- </strong>{' '}
81
- <br />
82
- <span>Close the current tab</span>
83
- </li>
84
- <li>
85
- <strong>
86
- <kbd>Alt</kbd> + <kbd>N</kbd>
87
- </strong>{' '}
88
- or{' '}
89
- <strong>
90
- <kbd>Ctrl</kbd> + <kbd>Shift↑</kbd> +{' '}
91
- <kbd>N</kbd>
92
- </strong>{' '}
93
- <br />
94
- <span>Open the create file modal</span>
95
- </li>
96
- <li>
97
- <strong>
98
- <kbd>Alt</kbd> + <kbd>PgUp↑</kbd>
99
- </strong>{' '}
100
- <br />
101
- <span>
102
- Change the active tab to the previous one
103
- </span>
104
- </li>
105
- <li>
106
- <strong>
107
- <kbd>Alt</kbd> + <kbd>PgDn↓</kbd>
108
- </strong>{' '}
109
- <br />
110
- <span>
111
- Change the active tab to the next one
112
- </span>
113
- </li>
114
- <li>
115
- <strong>Most VSCode Shortcuts</strong> <br />
116
- See VSCode docs:{' '}
117
- <a
118
- href="https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf"
119
- target="_blank"
120
- >
121
- Windows
122
- </a>
123
- ,{' '}
124
- <a
125
- href="https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf"
126
- target="_blank"
127
- >
128
- MacOS
129
- </a>
130
- ,{' '}
131
- <a
132
- href="https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf"
133
- target="_blank"
134
- >
135
- Linux
136
- </a>
137
- </li>
138
- </ul>
139
- </Form.Group>
140
- </Modal.Body>
141
- <Modal.Footer>
142
- <Button variant="primary" onClick={closeDoc}>
143
- Done
144
- </Button>
145
- </Modal.Footer>
146
- </Modal>
147
- ) : null;
148
- };
@@ -1,28 +0,0 @@
1
- import { enableLiveKit } from './featureFlags';
2
- import { VZKeyboardShortcutsDoc } from './VZKeyboardShortcutsDoc';
3
- import { VZSettings } from './VZSettings';
4
- import { VZSidebar } from './VZSidebar';
5
- import { CreateDirModal } from './VZSidebar/CreateDirModal';
6
- import { CreateFileModal } from './VZSidebar/CreateFileModal';
7
- import { VoiceChatModal } from './VZSidebar/VoiceChatModal';
8
-
9
- // The middle portion of the VZCode environment, containing:
10
- // * The sidebar
11
- // * The settings modal
12
- // * The create file modal
13
- export const VZLeft = ({ enableUsernameField = true }) => {
14
- return (
15
- <div className="left">
16
- <VZSidebar />
17
- <VZSettings
18
- enableUsernameField={enableUsernameField}
19
- />
20
- <VZKeyboardShortcutsDoc
21
- enableUsernameField={enableUsernameField}
22
- />
23
- <CreateFileModal />
24
- <CreateDirModal />
25
- {enableLiveKit && <VoiceChatModal />}
26
- </div>
27
- );
28
- };
@@ -1,172 +0,0 @@
1
- import { useContext, useEffect, useState } from 'react';
2
- import { SplitPaneResizeContext } from './SplitPaneResizeContext';
3
- import { TabList } from './TabList';
4
- import { CodeEditor } from './CodeEditor';
5
- import { ImageViewer } from './ImageViewer';
6
- import { CodeErrorOverlay } from './CodeErrorOverlay';
7
- import { PresenceNotifications } from './PresenceNotifications';
8
- import { AIAssistWidget } from './AIAssist/AIAssistWidget';
9
- import { VZCodeContext } from './VZCodeContext';
10
- import { RunCodeWidget } from './RunCodeWidget';
11
- import { InteractRule } from '@replit/codemirror-interact';
12
- import { EditorView } from '@codemirror/view';
13
- import { Diagnostic } from '@codemirror/lint';
14
- import { VizContent } from '@vizhub/viz-types';
15
- import { LeafPane } from '../types';
16
- import { isImageFile } from './utils/isImageFile';
17
-
18
- // TODO modify this to handle the SplitPane type
19
- // Recursive structure?
20
- // SplitPaneView
21
- // LeafPaneView
22
- const PaneView = ({
23
- pane,
24
- content,
25
- customInteractRules,
26
- enableAIAssist,
27
- aiAssistEndpoint,
28
- aiAssistOptions,
29
- aiAssistTooltipText,
30
- aiAssistClickOverride,
31
- aiCopilotEndpoint,
32
- esLintSource,
33
- }) => {
34
- // This prevents the CodeEditor from rendering
35
- // during SSR.
36
- const [isClient, setIsClient] = useState(false);
37
- useEffect(() => {
38
- setIsClient(true);
39
- }, []);
40
-
41
- // TODO something like
42
- // return pane.type === 'leafPane' ? (
43
- // <LeafPaneView />
44
- // ) : (
45
- // <SplitPaneView />
46
- // );
47
-
48
- // This should go in LeafPaneView
49
- return (
50
- <>
51
- <TabList
52
- activeFileId={pane.activeFileId}
53
- tabList={pane.tabList}
54
- />
55
- {isClient &&
56
- content &&
57
- pane.activeFileId &&
58
- (() => {
59
- // Get the active file to determine if it's an image
60
- const activeFile =
61
- content.files[pane.activeFileId];
62
- const shouldShowImageViewer =
63
- activeFile && isImageFile(activeFile.name);
64
-
65
- return shouldShowImageViewer ? (
66
- <ImageViewer />
67
- ) : (
68
- <CodeEditor
69
- customInteractRules={customInteractRules}
70
- aiCopilotEndpoint={aiCopilotEndpoint}
71
- esLintSource={esLintSource}
72
- />
73
- );
74
- })()}
75
- {isClient &&
76
- enableAIAssist &&
77
- content &&
78
- pane.activeFileId ? (
79
- <AIAssistWidget
80
- aiAssistEndpoint={aiAssistEndpoint}
81
- aiAssistOptions={aiAssistOptions}
82
- aiAssistTooltipText={aiAssistTooltipText}
83
- aiAssistClickOverride={aiAssistClickOverride}
84
- paneId={pane.id}
85
- activeFileId={pane.activeFileId}
86
- tabList={pane.tabList}
87
- />
88
- ) : null}
89
- <RunCodeWidget />
90
- </>
91
- );
92
- };
93
-
94
- // The middle portion of the VZCode environment, containing:
95
- // * The list of tabs at the top
96
- // * The code editor itself
97
- // * The code error overlay
98
- // * The presence notifications
99
- // * The UI for AI Assist
100
- export const VZMiddle = ({
101
- enableAIAssist = false,
102
- aiAssistEndpoint,
103
- aiAssistOptions,
104
- aiAssistTooltipText,
105
- aiAssistClickOverride,
106
- aiCopilotEndpoint,
107
- aiChatEndpoint,
108
- aiChatOptions,
109
- customInteractRules,
110
- esLintSource,
111
- }: {
112
- enableAIAssist?: boolean;
113
- aiAssistEndpoint?: string;
114
- aiAssistOptions?: { [key: string]: string };
115
- aiAssistTooltipText?: string;
116
- aiAssistClickOverride?: () => void;
117
- aiCopilotEndpoint?: string;
118
- aiChatEndpoint?: string;
119
- aiChatOptions?: { [key: string]: any };
120
- customInteractRules?: Array<InteractRule>;
121
- esLintSource: (
122
- view: EditorView,
123
- ) => Promise<readonly Diagnostic[]>;
124
- }) => {
125
- const { codeEditorWidth } = useContext(
126
- SplitPaneResizeContext,
127
- );
128
-
129
- const {
130
- content,
131
- localPresence,
132
- docPresence,
133
- pane,
134
- activePane,
135
- errorMessage,
136
- } = useContext(VZCodeContext);
137
-
138
- if (activePane.type !== 'leafPane') {
139
- throw new Error('Expected leafPane');
140
- }
141
- // True if the editor panes should be shown.
142
- const shouldShowEditorPanes: boolean =
143
- activePane.activeFileId !== null;
144
-
145
- return shouldShowEditorPanes ? (
146
- <div
147
- className="middle"
148
- style={{ width: codeEditorWidth + 'px' }}
149
- >
150
- <PaneView
151
- pane={pane}
152
- content={content}
153
- customInteractRules={customInteractRules}
154
- enableAIAssist={enableAIAssist}
155
- aiAssistEndpoint={aiAssistEndpoint}
156
- aiAssistOptions={aiAssistOptions}
157
- aiAssistTooltipText={aiAssistTooltipText}
158
- aiAssistClickOverride={aiAssistClickOverride}
159
- aiCopilotEndpoint={aiCopilotEndpoint}
160
- esLintSource={esLintSource}
161
- />
162
- <CodeErrorOverlay
163
- errorMessage={errorMessage}
164
- content={content}
165
- />
166
- <PresenceNotifications
167
- docPresence={docPresence}
168
- localPresence={localPresence}
169
- />
170
- </div>
171
- ) : null;
172
- };
@@ -1,128 +0,0 @@
1
- // The split pane resizer component.
2
- // This is what users drag to resize the split pane.
3
- import {
4
- useContext,
5
- useEffect,
6
- useCallback,
7
- useRef,
8
- } from 'react';
9
- import {
10
- Side,
11
- SplitPaneResizeContext,
12
- } from '../SplitPaneResizeContext';
13
- import { VZCodeContext } from '../VZCodeContext';
14
- import './styles.scss';
15
-
16
- // This is the width of the resizer interaction surface.
17
- // On this surface, the cursor changes to a resize cursor.
18
- const resizerInteractionSurfaceWidth = 20;
19
-
20
- // Expand while dragging to make it easier to hit.
21
- // Without this, various sidebar elements get hovered on and change style.
22
- const resizerInteractionSurfaceWidthWhileDragging = 200;
23
-
24
- // This is the width of the resizer visible area.
25
- // This is the part of the resizer that is visible to the user.
26
- const resizerThumbWidth = 4;
27
-
28
- export const VZResizer = ({
29
- side,
30
- isSidebarVisible = true,
31
- }: {
32
- side: Side;
33
- isSidebarVisible?: boolean;
34
- }) => {
35
- const {
36
- sidebarWidth,
37
- codeEditorWidth,
38
- moveSplitPane,
39
- isDraggingRight,
40
- isDraggingLeft,
41
- setIsDragging,
42
- } = useContext(SplitPaneResizeContext);
43
-
44
- // If there is no active file, don't render the resizer
45
- // for the right side.
46
- const { activePane } = useContext(VZCodeContext);
47
-
48
- const shouldRenderResizer =
49
- side === 'left' || activePane.activeFileId;
50
-
51
- const previousClientX = useRef<number>(0);
52
-
53
- const onMouseDown = useCallback(
54
- (event: React.MouseEvent) => {
55
- event.preventDefault();
56
- previousClientX.current = event.clientX;
57
- setIsDragging(true, side);
58
- document.body.style.cursor = 'col-resize';
59
- },
60
- [setIsDragging, side],
61
- );
62
-
63
- const onMouseMove = useCallback(
64
- (event: MouseEvent) => {
65
- event.preventDefault();
66
- const movementX =
67
- event.clientX - previousClientX.current;
68
- previousClientX.current = event.clientX;
69
- moveSplitPane(movementX, side);
70
- },
71
- [moveSplitPane, side],
72
- );
73
-
74
- const onMouseUp = useCallback(() => {
75
- setIsDragging(false, side);
76
- document.body.style.cursor = 'default';
77
- }, [setIsDragging, side]);
78
-
79
- // Is the resizer currently being dragged?
80
- const isDragging =
81
- (side === 'left' && isDraggingLeft) ||
82
- (side === 'right' && isDraggingRight);
83
-
84
- useEffect(() => {
85
- if (isDragging) {
86
- document.addEventListener('mousemove', onMouseMove);
87
- document.addEventListener('mouseup', onMouseUp);
88
- return () => {
89
- document.removeEventListener(
90
- 'mousemove',
91
- onMouseMove,
92
- );
93
- document.removeEventListener('mouseup', onMouseUp);
94
- };
95
- }
96
- }, [isDragging, onMouseMove, onMouseUp]);
97
-
98
- const resizerWidth = isDragging
99
- ? resizerInteractionSurfaceWidthWhileDragging
100
- : resizerInteractionSurfaceWidth;
101
-
102
- const left =
103
- (side === 'left'
104
- ? sidebarWidth
105
- : isSidebarVisible
106
- ? sidebarWidth + codeEditorWidth
107
- : codeEditorWidth) -
108
- resizerWidth / 2;
109
-
110
- return shouldRenderResizer ? (
111
- <div
112
- className="vz-resizer"
113
- onMouseDown={onMouseDown}
114
- style={{
115
- left: left + resizerWidth / 2 - 1.5,
116
- width: resizerWidth,
117
- }}
118
- >
119
- <div
120
- className="vz-resizer-thumb"
121
- style={{
122
- left: resizerThumbWidth / 2 - 1.5,
123
- width: resizerThumbWidth,
124
- }}
125
- />
126
- </div>
127
- ) : null;
128
- };
@@ -1,33 +0,0 @@
1
- .vz-resizer {
2
- position: absolute;
3
- top: 0;
4
- left: 0;
5
- bottom: 0;
6
-
7
- // Needed in order to make the resizer hoverable
8
- // when there is another div on top of it.
9
- z-index: 1;
10
-
11
- // Useful for debugging:
12
- // background-color: #ffd0007c;
13
- }
14
-
15
- .vz-resizer:hover {
16
- cursor: col-resize;
17
- }
18
-
19
- .vz-resizer .vz-resizer-thumb {
20
- position: absolute;
21
- top: 0;
22
- bottom: 0;
23
-
24
- // Transition the background color after a delay.
25
- // First value is the duration of the transition,
26
- // second value is the delay before the transition starts.
27
- // Tuned to roughly match VSCode's resizer.
28
- transition: background-color 0.15s 0.25s;
29
- }
30
-
31
- .vz-resizer:hover .vz-resizer-thumb {
32
- background-color: #0078d4;
33
- }
@@ -1,113 +0,0 @@
1
- import {
2
- useContext,
3
- useEffect,
4
- useMemo,
5
- useRef,
6
- } from 'react';
7
- import {
8
- createRuntime,
9
- VizHubRuntime,
10
- } from '@vizhub/runtime';
11
- import BuildWorker from './buildWorker?worker';
12
- import { VZCodeContext } from './VZCodeContext';
13
- import { vizFilesToFileCollection } from '@vizhub/viz-utils';
14
- import { VizContent } from '@vizhub/viz-types';
15
-
16
- // Extend VizContent type to include hardRerun property
17
- type ExtendedVizContent = VizContent & {
18
- // TODO remove this, use the runId property from VizContent instead.
19
- // If `VizContent.runId` changes, it will trigger a hard rerun.
20
- hardRerun?: boolean;
21
- };
22
-
23
- const enableIframe = true;
24
-
25
- export const VZRight = () => {
26
- const runtimeRef = useRef<VizHubRuntime | null>(null);
27
- const isFirstRunRef = useRef(true);
28
- const lastRunIdRef = useRef<string | undefined>(
29
- undefined,
30
- );
31
-
32
- // Get access to the current files.
33
- const {
34
- content,
35
- handleRuntimeError,
36
- clearRuntimeError,
37
- iframeRef,
38
- } = useContext(VZCodeContext);
39
-
40
- const files = useMemo(
41
- () =>
42
- content
43
- ? vizFilesToFileCollection(content.files)
44
- : null,
45
- [content?.files],
46
- );
47
-
48
- const isInteracting = content?.isInteracting || false;
49
- const runId = content?.runId;
50
- const hardRerun =
51
- (content as ExtendedVizContent)?.hardRerun || false;
52
-
53
- // Check if runId has changed
54
- const runIdChanged = runId !== lastRunIdRef.current;
55
- if (runIdChanged) {
56
- lastRunIdRef.current = runId;
57
- }
58
-
59
- useEffect(() => {
60
- if (!files) return;
61
-
62
- // Initialize the runtime only once
63
- if (!runtimeRef.current && iframeRef.current) {
64
- const worker = new BuildWorker();
65
- runtimeRef.current = createRuntime({
66
- iframe: iframeRef.current,
67
- worker,
68
- setBuildErrorMessage: (error) => {
69
- if (error) {
70
- console.error('Build error:', error);
71
- }
72
- },
73
- handleRuntimeError,
74
- });
75
- }
76
-
77
- // Run code in the iframe when:
78
- // 1. First run
79
- // 2. User is interacting with widgets
80
- // 3. runId changed (indicating AI finished or other trigger)
81
- if (
82
- isFirstRunRef.current ||
83
- isInteracting ||
84
- runIdChanged
85
- ) {
86
- // Clear runtime errors when new code runs
87
- clearRuntimeError();
88
-
89
- runtimeRef.current?.run({
90
- files,
91
- // Enable hot reloading when interacting, disable when runId changed without interaction
92
- enableHotReloading: isInteracting,
93
- enableSourcemap: true,
94
- vizId: 'example-viz',
95
- });
96
- isFirstRunRef.current = false;
97
- }
98
-
99
- // TODO use refs, and cleanup on unmount
100
- // return () => {
101
- // runtime.cleanup();
102
- // worker.terminate();
103
- // };
104
- }, [files, isInteracting, runIdChanged, hardRerun]);
105
-
106
- return (
107
- <div className="right">
108
- {enableIframe ? (
109
- <iframe ref={iframeRef}></iframe>
110
- ) : null}
111
- </div>
112
- );
113
- };