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,292 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { setSearchResultsReducer } from './searchReducer';
3
- import { VZAction, VZState, createInitialState } from '.';
4
- import { defaultTheme } from '../themes';
5
- import { ShareDBDoc } from '../../types';
6
- import { VizContent } from '@vizhub/viz-types';
7
-
8
- // Mock ShareDBDoc for testing
9
- const createMockShareDBDoc = (
10
- files: any,
11
- ): ShareDBDoc<VizContent> => ({
12
- data: { files, id: 'mock-id' },
13
- ingestSnapshot: (snapshot: any, callback: any) => {
14
- // No-op for testing
15
- if (callback) callback();
16
- },
17
- subscribe: (callback: any) => {
18
- // No-op for testing
19
- if (callback) callback();
20
- },
21
- on: (
22
- event: string,
23
- callback: (op: any, source: boolean) => void,
24
- ) => {
25
- // No-op for testing
26
- },
27
- off: (
28
- event: string,
29
- callback: (op: any, source: boolean) => void,
30
- ) => {
31
- // No-op for testing
32
- },
33
- removeListener: (
34
- event: string,
35
- callback: (op: any, source: boolean) => void,
36
- ) => {
37
- // No-op for testing
38
- },
39
- submitOp: (
40
- op: any,
41
- options?: any,
42
- callback?: () => void,
43
- ) => {
44
- // No-op for testing
45
- if (callback) callback();
46
- },
47
- whenNothingPending: (callback: () => void) => {
48
- // No-op for testing
49
- if (callback) callback();
50
- },
51
- });
52
-
53
- const initialState: VZState = createInitialState({
54
- defaultTheme,
55
- });
56
-
57
- describe('searchReducer', () => {
58
- describe('setSearchResultsReducer', () => {
59
- it('should find case-insensitive matches', () => {
60
- const mockFiles = {
61
- 'file1.js': {
62
- name: 'file1.js',
63
- text: 'const Hello = "world";\nconst goodbye = "HELLO";',
64
- },
65
- 'file2.js': {
66
- name: 'file2.js',
67
- text: 'function hello() {\n return "Hello World";\n}',
68
- },
69
- };
70
-
71
- const stateWithSearch = {
72
- ...initialState,
73
- search: {
74
- ...initialState.search,
75
- pattern: 'hello', // lowercase search pattern
76
- },
77
- };
78
-
79
- const action: VZAction = {
80
- type: 'set_search_results',
81
- files: createMockShareDBDoc(mockFiles),
82
- };
83
-
84
- const newState = setSearchResultsReducer(
85
- stateWithSearch,
86
- action,
87
- );
88
-
89
- // Should find matches in both files despite different cases
90
- expect(
91
- Object.keys(newState.search.results),
92
- ).toHaveLength(2);
93
-
94
- // Check file1.js results
95
- const file1Results =
96
- newState.search.results['file1.js'];
97
- expect(file1Results).toBeDefined();
98
- expect(file1Results.matches).toHaveLength(2); // "Hello" and "HELLO"
99
- expect(file1Results.matches[0].line).toBe(1);
100
- expect(file1Results.matches[0].index).toBe(6); // position of "Hello"
101
- expect(file1Results.matches[1].line).toBe(2);
102
- expect(file1Results.matches[1].index).toBe(17); // position of "HELLO"
103
-
104
- // Check file2.js results
105
- const file2Results =
106
- newState.search.results['file2.js'];
107
- expect(file2Results).toBeDefined();
108
- expect(file2Results.matches).toHaveLength(2); // "hello" and "Hello"
109
- expect(file2Results.matches[0].line).toBe(1);
110
- expect(file2Results.matches[0].index).toBe(9); // position of "hello"
111
- expect(file2Results.matches[1].line).toBe(2);
112
- expect(file2Results.matches[1].index).toBe(10); // position of "Hello"
113
- });
114
-
115
- it('should find exact case matches', () => {
116
- const mockFiles = {
117
- 'file1.js': {
118
- name: 'file1.js',
119
- text: 'const hello = "world";',
120
- },
121
- };
122
-
123
- const stateWithSearch = {
124
- ...initialState,
125
- search: {
126
- ...initialState.search,
127
- pattern: 'hello', // exact case match
128
- },
129
- };
130
-
131
- const action: VZAction = {
132
- type: 'set_search_results',
133
- files: createMockShareDBDoc(mockFiles),
134
- };
135
-
136
- const newState = setSearchResultsReducer(
137
- stateWithSearch,
138
- action,
139
- );
140
-
141
- expect(
142
- Object.keys(newState.search.results),
143
- ).toHaveLength(1);
144
- const file1Results =
145
- newState.search.results['file1.js'];
146
- expect(file1Results.matches).toHaveLength(1);
147
- expect(file1Results.matches[0].line).toBe(1);
148
- expect(file1Results.matches[0].index).toBe(6);
149
- });
150
-
151
- it('should not find matches when pattern does not exist', () => {
152
- const mockFiles = {
153
- 'file1.js': {
154
- name: 'file1.js',
155
- text: 'const world = "test";',
156
- },
157
- };
158
-
159
- const stateWithSearch = {
160
- ...initialState,
161
- search: {
162
- ...initialState.search,
163
- pattern: 'hello',
164
- },
165
- };
166
-
167
- const action: VZAction = {
168
- type: 'set_search_results',
169
- files: createMockShareDBDoc(mockFiles),
170
- };
171
-
172
- const newState = setSearchResultsReducer(
173
- stateWithSearch,
174
- action,
175
- );
176
-
177
- expect(
178
- Object.keys(newState.search.results),
179
- ).toHaveLength(0);
180
- });
181
-
182
- it('should handle uppercase search pattern', () => {
183
- const mockFiles = {
184
- 'file1.js': {
185
- name: 'file1.js',
186
- text: 'const Hello = "world";\nfunction hello() {}',
187
- },
188
- };
189
-
190
- const stateWithSearch = {
191
- ...initialState,
192
- search: {
193
- ...initialState.search,
194
- pattern: 'HELLO', // uppercase search pattern
195
- },
196
- };
197
-
198
- const action: VZAction = {
199
- type: 'set_search_results',
200
- files: createMockShareDBDoc(mockFiles),
201
- };
202
-
203
- const newState = setSearchResultsReducer(
204
- stateWithSearch,
205
- action,
206
- );
207
-
208
- expect(
209
- Object.keys(newState.search.results),
210
- ).toHaveLength(1);
211
- const file1Results =
212
- newState.search.results['file1.js'];
213
- expect(file1Results.matches).toHaveLength(2); // Should find both "Hello" and "hello"
214
- });
215
-
216
- it('should handle mixed case search pattern', () => {
217
- const mockFiles = {
218
- 'file1.js': {
219
- name: 'file1.js',
220
- text: 'const HeLLo = "world";\nconst hello = "test";\nconst HELLO = "end";',
221
- },
222
- };
223
-
224
- const stateWithSearch = {
225
- ...initialState,
226
- search: {
227
- ...initialState.search,
228
- pattern: 'HeLLo', // mixed case search pattern
229
- },
230
- };
231
-
232
- const action: VZAction = {
233
- type: 'set_search_results',
234
- files: createMockShareDBDoc(mockFiles),
235
- };
236
-
237
- const newState = setSearchResultsReducer(
238
- stateWithSearch,
239
- action,
240
- );
241
-
242
- expect(
243
- Object.keys(newState.search.results),
244
- ).toHaveLength(1);
245
- const file1Results =
246
- newState.search.results['file1.js'];
247
- expect(file1Results.matches).toHaveLength(3); // Should find all three variations
248
- });
249
-
250
- it('should skip files without text content', () => {
251
- const mockFiles = {
252
- 'file1.js': {
253
- name: 'file1.js',
254
- text: 'const hello = "world";',
255
- },
256
- 'file2.js': {
257
- name: 'file2.js',
258
- // no text property
259
- },
260
- };
261
-
262
- const stateWithSearch = {
263
- ...initialState,
264
- search: {
265
- ...initialState.search,
266
- pattern: 'hello',
267
- },
268
- };
269
-
270
- const action: VZAction = {
271
- type: 'set_search_results',
272
- files: createMockShareDBDoc(mockFiles),
273
- };
274
-
275
- const newState = setSearchResultsReducer(
276
- stateWithSearch,
277
- action,
278
- );
279
-
280
- // Should only find results in file1.js
281
- expect(
282
- Object.keys(newState.search.results),
283
- ).toHaveLength(1);
284
- expect(
285
- newState.search.results['file1.js'],
286
- ).toBeDefined();
287
- expect(
288
- newState.search.results['file2.js'],
289
- ).toBeUndefined();
290
- });
291
- });
292
- });
@@ -1,181 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
- import {
3
- SearchFile,
4
- SearchFileVisibility,
5
- SearchResult,
6
- ShareDBDoc,
7
- } from '../../types';
8
- import { VizContent } from '@vizhub/viz-types';
9
-
10
- function searchPattern(
11
- shareDBDoc: ShareDBDoc<VizContent>,
12
- pattern: string,
13
- ): SearchResult {
14
- const files = shareDBDoc.data.files;
15
- const fileIds = Object.keys(shareDBDoc.data.files);
16
- let results: { [id: string]: SearchFile } = {};
17
-
18
- for (let i = 0; i < fileIds.length; i++) {
19
- const file = files[fileIds[i]];
20
-
21
- if (files[fileIds[i]].text) {
22
- const fileName = file.name;
23
- const lines = file.text.split('\n');
24
- const matches = [];
25
-
26
- for (let j = 0; j < lines.length; j++) {
27
- const index = lines[j]
28
- .toLowerCase()
29
- .indexOf(pattern.toLowerCase());
30
-
31
- if (index !== -1) {
32
- matches.push({
33
- line: j + 1,
34
- index: index,
35
- text: lines[j],
36
- isClosed: false,
37
- });
38
- }
39
- }
40
-
41
- if (matches.length > 0) {
42
- results[fileIds[i]] = {
43
- name: fileName,
44
- matches: matches,
45
- visibility: 'open',
46
- };
47
- }
48
- }
49
- }
50
-
51
- return results;
52
- }
53
-
54
- function updateSearchFileVisibility(
55
- results: SearchResult,
56
- id: string,
57
- visibility: SearchFileVisibility,
58
- ): SearchResult {
59
- return {
60
- ...results,
61
- [id]: { ...results[id], visibility: visibility },
62
- };
63
- }
64
-
65
- export const setIsSearchOpenReducer = (
66
- state: VZState,
67
- action: VZAction,
68
- ): VZState =>
69
- action.type === 'set_is_search_open'
70
- ? { ...state, isSearchOpen: action.value }
71
- : state;
72
-
73
- export const setSearchReducer = (
74
- state: VZState,
75
- action: VZAction,
76
- ): VZState =>
77
- action.type === 'set_search'
78
- ? {
79
- ...state,
80
- search: {
81
- ...state.search,
82
- pattern: action.value,
83
- results: {},
84
- focusedIndex: 0,
85
- focusedChildIndex: null,
86
- focused: true,
87
- },
88
- }
89
- : state;
90
-
91
- export const setSearchResultsReducer = (
92
- state: VZState,
93
- action: VZAction,
94
- ): VZState =>
95
- action.type === 'set_search_results'
96
- ? {
97
- ...state,
98
- search: {
99
- ...state.search,
100
- pattern: state.search.pattern,
101
- results: searchPattern(
102
- action.files,
103
- state.search.pattern,
104
- ),
105
- focused: state.search.focused,
106
- },
107
- }
108
- : state;
109
-
110
- export const setSearchFileVisibilityReducer = (
111
- state: VZState,
112
- action: VZAction,
113
- ): VZState =>
114
- action.type === 'set_search_file_visibility'
115
- ? {
116
- ...state,
117
- search: {
118
- ...state.search,
119
- pattern: state.search.pattern,
120
- results: updateSearchFileVisibility(
121
- state.search.results,
122
- action.id,
123
- action.visibility,
124
- ),
125
- },
126
- }
127
- : state;
128
-
129
- export const setSearchLineVisibilityReducer = (
130
- state: VZState,
131
- action: VZAction,
132
- ): VZState =>
133
- action.type === 'hide_search_results_line'
134
- ? {
135
- ...state,
136
- search: {
137
- ...state.search,
138
- results: {
139
- ...state.search.results,
140
- [action.id]: {
141
- ...state.search.results[action.id],
142
- matches: state.search.results[
143
- action.id
144
- ].matches.filter(
145
- (match, index) =>
146
- match.line !== action.line,
147
- ),
148
- },
149
- },
150
- },
151
- }
152
- : state;
153
-
154
- export const setSearchFocusedIndexReducer = (
155
- state: VZState,
156
- action: VZAction,
157
- ): VZState =>
158
- action.type === 'set_active_search_index'
159
- ? {
160
- ...state,
161
- search: {
162
- ...state.search,
163
- focusedIndex: action.focusedIndex,
164
- focusedChildIndex: action.childIndex,
165
- },
166
- }
167
- : state;
168
-
169
- export const toggleSearchFocusedReducer = (
170
- state: VZState,
171
- action: VZAction,
172
- ): VZState =>
173
- action.type === 'toggle_search_focused'
174
- ? {
175
- ...state,
176
- search: {
177
- ...state.search,
178
- focused: !state.search.focused,
179
- },
180
- }
181
- : state;
@@ -1,28 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
- import { Pane } from '../../types';
3
- import { findPane } from './findPane';
4
- import { updatePane } from './updatePane';
5
-
6
- export const setActiveFileIdReducer = (
7
- state: VZState,
8
- action: VZAction,
9
- ): VZState => {
10
- if (action.type !== 'set_active_file_id') return state;
11
-
12
- const { pane, activePaneId } = state;
13
- const activePane: Pane = findPane(pane, activePaneId);
14
-
15
- if (activePane.type !== 'leafPane') {
16
- throw new Error(
17
- 'closeTabsReducer: activePane is not a leafPane',
18
- );
19
- }
20
- return {
21
- ...state,
22
- pane: updatePane({
23
- pane,
24
- activePaneId,
25
- newActiveFileId: action.activeFileId,
26
- }),
27
- };
28
- };
@@ -1,76 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
- import { Pane } from '../../types';
3
- import { findPane } from './findPane';
4
- import { updatePane } from './updatePane';
5
-
6
- export const setActiveFileLeftReducer = (
7
- state: VZState,
8
- action: VZAction,
9
- ): VZState => {
10
- if (action.type !== 'set_active_file_left') {
11
- return state;
12
- }
13
-
14
- const { pane, activePaneId } = state;
15
- const activePane: Pane = findPane(pane, activePaneId);
16
-
17
- if (activePane.type !== 'leafPane') {
18
- throw new Error(
19
- 'closeTabsReducer: activePane is not a leafPane',
20
- );
21
- }
22
-
23
- let index = activePane.tabList.findIndex(
24
- (tab) => tab.fileId === activePane.activeFileId,
25
- );
26
-
27
- index -= 1;
28
- if (index < 0) {
29
- index = activePane.tabList.length - 1;
30
- }
31
-
32
- return {
33
- ...state,
34
- pane: updatePane({
35
- pane,
36
- activePaneId,
37
- newActiveFileId: activePane.tabList[index].fileId,
38
- }),
39
- };
40
- };
41
-
42
- export const setActiveFileRightReducer = (
43
- state: VZState,
44
- action: VZAction,
45
- ): VZState => {
46
- if (action.type !== 'set_active_file_right') {
47
- return state;
48
- }
49
-
50
- const { pane, activePaneId } = state;
51
- const activePane: Pane = findPane(pane, activePaneId);
52
-
53
- if (activePane.type !== 'leafPane') {
54
- throw new Error(
55
- 'closeTabsReducer: activePane is not a leafPane',
56
- );
57
- }
58
-
59
- let index = activePane.tabList.findIndex(
60
- (tab) => tab.fileId === activePane.activeFileId,
61
- );
62
-
63
- index += 1;
64
- if (index > activePane.tabList.length - 1) {
65
- index = 0;
66
- }
67
-
68
- return {
69
- ...state,
70
- pane: updatePane({
71
- pane,
72
- activePaneId,
73
- newActiveFileId: activePane.tabList[index].fileId,
74
- }),
75
- };
76
- };
@@ -1,9 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
-
3
- export const setIsDocOpenReducer = (
4
- state: VZState,
5
- action: VZAction,
6
- ): VZState =>
7
- action.type === 'set_is_doc_open'
8
- ? { ...state, isDocOpen: action.value }
9
- : state;
@@ -1,9 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
-
3
- export const setIsSettingsOpenReducer = (
4
- state: VZState,
5
- action: VZAction,
6
- ): VZState =>
7
- action.type === 'set_is_settings_open'
8
- ? { ...state, isSettingsOpen: action.value }
9
- : state;
@@ -1,9 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
-
3
- export const setThemeReducer = (
4
- state: VZState,
5
- action: VZAction,
6
- ): VZState =>
7
- action.type === 'set_theme'
8
- ? { ...state, theme: action.themeLabel }
9
- : state;
@@ -1,9 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
-
3
- export const setUsernameReducer = (
4
- state: VZState,
5
- action: VZAction,
6
- ): VZState =>
7
- action.type === 'set_username'
8
- ? { ...state, username: action.username }
9
- : state;
@@ -1,66 +0,0 @@
1
- import { PaneId, Pane } from '../../types';
2
- import { VZAction, VZState } from '.';
3
- import { updatePane } from './updatePane';
4
-
5
- export const splitCurrentPaneReducer = (
6
- state: VZState,
7
- action: VZAction,
8
- ): VZState => {
9
- // console.log('splitCurrentPaneReducer');
10
- if (action.type !== 'split_current_pane') {
11
- return state;
12
- }
13
-
14
- const activePaneId = state.activePaneId;
15
-
16
- const newLeafPane1: Pane = {
17
- id: `${activePaneId}-1`, // Generate unique IDs for new panes
18
- type: 'leafPane',
19
- tabList: [],
20
- activeFileId: null,
21
- };
22
-
23
- const newLeafPane2: Pane = {
24
- id: `${activePaneId}-2`,
25
- type: 'leafPane',
26
- tabList: [],
27
- activeFileId: null,
28
- };
29
-
30
- const newSplitPane: Pane = {
31
- id: activePaneId,
32
- type: 'splitPane',
33
- orientation: 'horizontal',
34
- children: [newLeafPane1, newLeafPane2],
35
- };
36
-
37
- const updatedPane = updatePane({
38
- pane: state.pane,
39
- activePaneId,
40
- newTabList: undefined,
41
- newActiveFileId: undefined,
42
- });
43
-
44
- const updateSplitPane = (pane: Pane, id: PaneId): Pane =>
45
- pane.id === id
46
- ? newSplitPane
47
- : pane.type === 'splitPane'
48
- ? {
49
- ...pane,
50
- children: pane.children.map((child) =>
51
- updateSplitPane(child, id),
52
- ),
53
- }
54
- : pane;
55
-
56
- const finalPane = updateSplitPane(
57
- updatedPane,
58
- activePaneId,
59
- );
60
-
61
- return {
62
- ...state,
63
- pane: finalPane,
64
- activePaneId: newLeafPane1.id,
65
- };
66
- };
@@ -1,12 +0,0 @@
1
- import { VZAction, VZState } from '.';
2
-
3
- export const toggleAutoFollowReducer = (
4
- state: VZState,
5
- action: VZAction,
6
- ): VZState =>
7
- action.type === 'toggle_auto_follow'
8
- ? {
9
- ...state,
10
- enableAutoFollow: !state.enableAutoFollow,
11
- }
12
- : state;