vzcode 0.75.0 → 0.77.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.
@@ -17,7 +17,7 @@ import { SplitPaneResizeContext } from '../SplitPaneResizeContext';
17
17
  import { BugSVG, GearSVG, NewSVG } from '../Icons';
18
18
  import { Listing } from './Listing';
19
19
  import { VZCodeContext } from '../VZCodeContext';
20
- import { DragAndDrop } from './DragAndDrop';
20
+ import { useDragAndDrop } from './useDragAndDrop';
21
21
  import './styles.scss';
22
22
 
23
23
  // TODO turn this UI back on when we are actually detecting
@@ -84,116 +84,131 @@ export const VZSidebar = ({
84
84
  fileTree.children &&
85
85
  fileTree.children.length > 0;
86
86
 
87
+ const {
88
+ isDragOver,
89
+ handleDragEnter,
90
+ handleDragOver,
91
+ handleDragLeave,
92
+ handleDrop,
93
+ } = useDragAndDrop();
94
+
87
95
  return (
88
96
  <div
89
- className="vz-sidebar"
90
- style={{ width: sidebarWidth + 'px' }}
97
+ className={`drop-zone ${isDragOver ? 'dragover' : ''}`}
98
+ onDragEnter={handleDragEnter}
99
+ onDragOver={handleDragOver}
100
+ onDragLeave={handleDragLeave}
101
+ onDrop={handleDrop}
91
102
  >
92
- <div className="files">
93
- <div className="full-box">
94
- <div className="sidebar-section-hint">
95
- Project Files
96
- </div>
97
- <div className="sidebar-section-buttons">
98
- <OverlayTrigger
99
- placement="left"
100
- overlay={
101
- <Tooltip id="report-bug-tooltip">
102
- {reportBugTooltipText}
103
- </Tooltip>
104
- }
105
- >
106
- <a
107
- href="https://github.com/vizhub-core/vzcode/issues/new"
108
- target="_blank"
109
- rel="noopener noreferrer"
103
+ <div
104
+ className="vz-sidebar"
105
+ style={{ width: sidebarWidth + 'px' }}
106
+ >
107
+ <div className="files">
108
+ <div className="full-box">
109
+ <div className="sidebar-section-hint">
110
+ Project Files
111
+ </div>
112
+ <div className="sidebar-section-buttons">
113
+ <OverlayTrigger
114
+ placement="left"
115
+ overlay={
116
+ <Tooltip id="report-bug-tooltip">
117
+ {reportBugTooltipText}
118
+ </Tooltip>
119
+ }
110
120
  >
111
- <i className="icon-button icon-button-dark">
112
- <BugSVG />
113
- </i>
114
- </a>
115
- </OverlayTrigger>
116
- {disableSettings ? null : (
121
+ <a
122
+ href="https://github.com/vizhub-core/vzcode/issues/new"
123
+ target="_blank"
124
+ rel="noopener noreferrer"
125
+ >
126
+ <i className="icon-button icon-button-dark">
127
+ <BugSVG />
128
+ </i>
129
+ </a>
130
+ </OverlayTrigger>
131
+ {disableSettings ? null : (
132
+ <OverlayTrigger
133
+ placement="left"
134
+ overlay={
135
+ <Tooltip id="open-settings-tooltip">
136
+ {openSettingsTooltipText}
137
+ </Tooltip>
138
+ }
139
+ >
140
+ <i
141
+ onClick={handleSettingsClick}
142
+ className="icon-button icon-button-dark"
143
+ >
144
+ <GearSVG />
145
+ </i>
146
+ </OverlayTrigger>
147
+ )}
117
148
  <OverlayTrigger
118
149
  placement="left"
119
150
  overlay={
120
- <Tooltip id="open-settings-tooltip">
121
- {openSettingsTooltipText}
151
+ <Tooltip id="create-file-tooltip">
152
+ {createFileTooltipText}
122
153
  </Tooltip>
123
154
  }
124
155
  >
125
156
  <i
126
- onClick={handleSettingsClick}
157
+ onClick={handleOpenCreateFileModal}
127
158
  className="icon-button icon-button-dark"
128
159
  >
129
- <GearSVG />
160
+ <NewSVG />
130
161
  </i>
131
162
  </OverlayTrigger>
132
- )}
133
- <OverlayTrigger
134
- placement="left"
135
- overlay={
136
- <Tooltip id="create-file-tooltip">
137
- {createFileTooltipText}
138
- </Tooltip>
139
- }
140
- >
141
- <i
142
- onClick={handleOpenCreateFileModal}
143
- className="icon-button icon-button-dark"
144
- >
145
- <NewSVG />
146
- </i>
147
- </OverlayTrigger>
163
+ </div>
148
164
  </div>
165
+ {filesExist ? (
166
+ fileTree.children.map((entity) => {
167
+ const { fileId } = entity as FileTreeFile;
168
+ const { path } = entity as FileTree;
169
+ const key = fileId ? fileId : path;
170
+ return (
171
+ <Listing
172
+ key={key}
173
+ entity={entity}
174
+ renameFile={renameFile}
175
+ deleteFile={deleteFile}
176
+ renameDirectory={renameDirectory}
177
+ deleteDirectory={deleteDirectory}
178
+ handleFileClick={handleFileClick}
179
+ handleFileDoubleClick={
180
+ handleFileDoubleClick
181
+ }
182
+ isDirectoryOpen={isDirectoryOpen}
183
+ toggleDirectory={toggleDirectory}
184
+ activeFileId={activeFileId}
185
+ />
186
+ );
187
+ })
188
+ ) : (
189
+ <div className="empty">
190
+ <div className="empty-text">
191
+ It looks like you don't have any files yet!
192
+ Click the "Create file" button above to
193
+ create your first file.
194
+ </div>
195
+ </div>
196
+ )}
149
197
  </div>
150
- <DragAndDrop />
151
- {filesExist ? (
152
- fileTree.children.map((entity) => {
153
- const { fileId } = entity as FileTreeFile;
154
- const { path } = entity as FileTree;
155
- const key = fileId ? fileId : path;
156
- return (
157
- <Listing
158
- key={key}
159
- entity={entity}
160
- renameFile={renameFile}
161
- deleteFile={deleteFile}
162
- renameDirectory={renameDirectory}
163
- deleteDirectory={deleteDirectory}
164
- handleFileClick={handleFileClick}
165
- handleFileDoubleClick={
166
- handleFileDoubleClick
167
- }
168
- isDirectoryOpen={isDirectoryOpen}
169
- toggleDirectory={toggleDirectory}
170
- activeFileId={activeFileId}
198
+
199
+ {enableConnectionStatus && (
200
+ <div className="connection-status">
201
+ {connected ? 'Connected' : 'Connection Lost'}
202
+ <div className="connection">
203
+ <div
204
+ className={`connection-status-indicator ${
205
+ connected ? 'connected' : 'disconnected'
206
+ }`}
171
207
  />
172
- );
173
- })
174
- ) : (
175
- <div className="empty">
176
- <div className="empty-text">
177
- It looks like you don't have any files yet!
178
- Click the "Create file" button above to create
179
- your first file.
180
208
  </div>
181
209
  </div>
182
210
  )}
183
211
  </div>
184
-
185
- {enableConnectionStatus && (
186
- <div className="connection-status">
187
- {connected ? 'Connected' : 'Connection Lost'}
188
- <div className="connection">
189
- <div
190
- className={`connection-status-indicator ${
191
- connected ? 'connected' : 'disconnected'
192
- }`}
193
- />
194
- </div>
195
- </div>
196
- )}
197
212
  </div>
198
213
  );
199
214
  };
@@ -154,18 +154,17 @@
154
154
  }
155
155
  }
156
156
  }
157
+ }
157
158
 
158
- .drop-zone {
159
- border: 3px dashed #bdc7dc;
160
- width: auto;
161
- padding: 20px;
162
- color: #bdc7dc;
163
- text-align: center;
164
- font-family: var(--vzcode-font-family);
165
- font-weight: 500;
166
- }
159
+ .drop-zone {
160
+ border: 3px solid #0a1731;
161
+ width: auto;
162
+ color: #bdc7dc;
163
+ text-align: center;
164
+ font-family: var(--vzcode-font-family);
165
+ font-weight: 500;
166
+ }
167
167
 
168
- .drop-zone.dragover {
169
- border-color: #009639;
170
- }
168
+ .drop-zone.dragover {
169
+ border-color: #009639;
171
170
  }
@@ -4,7 +4,7 @@ import './styles.scss';
4
4
 
5
5
  const debug = false;
6
6
 
7
- export const DragAndDrop = () => {
7
+ export const useDragAndDrop = () => {
8
8
  const [isDragOver, setIsDragOver] = useState(false);
9
9
  const { createFile } = useContext(VZCodeContext);
10
10
 
@@ -60,15 +60,11 @@ export const DragAndDrop = () => {
60
60
  [createFile],
61
61
  );
62
62
 
63
- return (
64
- <div
65
- className={`drop-zone ${isDragOver ? 'dragover' : ''}`}
66
- onDragEnter={handleDragEnter}
67
- onDragOver={handleDragOver}
68
- onDragLeave={handleDragLeave}
69
- onDrop={handleDrop}
70
- >
71
- Drag files here
72
- </div>
73
- );
63
+ return {
64
+ isDragOver,
65
+ handleDragEnter,
66
+ handleDragOver,
67
+ handleDragLeave,
68
+ handleDrop,
69
+ };
74
70
  };
@@ -75,20 +75,30 @@ export const useFileCRUD = ({
75
75
  oldName: string,
76
76
  newName: string,
77
77
  ) => {
78
+ console.log(path);
79
+ console.log(oldName);
78
80
  submitOperation((document: VZCodeContent) => {
79
81
  const updatedFiles = Object.keys(
80
82
  document.files,
81
83
  ).reduce((acc, key) => {
82
84
  const file = document.files[key];
83
85
  const fileName = file.name;
84
- if (fileName.includes(path)) {
85
- const oldNamePos = fileName.indexOf(oldName);
86
+ //See if it's actually in directory
87
+ if (fileName.includes(path + '/')) {
88
+ //Create New Name for System
89
+ const pathPart = fileName.substring(
90
+ 0,
91
+ fileName.indexOf(path) + path.length,
92
+ );
93
+ const oldNamePos =
94
+ pathPart.lastIndexOf(oldName);
86
95
  const fileNewName =
87
96
  fileName.substring(0, oldNamePos) +
88
97
  newName +
89
98
  fileName.substring(
90
99
  oldNamePos + oldName.length,
91
100
  );
101
+ //Return with new names
92
102
  acc[key] = { ...file, name: fileNewName };
93
103
  } else {
94
104
  acc[key] = file;
@@ -260,6 +260,10 @@ onmessage = async ({ data }) => {
260
260
  // Not valid in TypeScript, but common in JavaScript.
261
261
  const LINT_ERROR_CODE_NON_EXISTENT_PROPERTY = 2339;
262
262
 
263
+ // "Type 'Set<unknown>' can only be iterated through when using the '--downlevelIteration'
264
+ // flag or with a '--target' of 'es2015' or higher."
265
+ const LINT_ERROR_CODE_ITERATED_THROUGH = 2802;
266
+
263
267
  if (debug) {
264
268
  console.log(tsErrors);
265
269
  }
@@ -271,7 +275,8 @@ onmessage = async ({ data }) => {
271
275
  error.code !== LINT_ERROR_CODE_ANY_TYPE &&
272
276
  error.code !== LINT_ERROR_CODE_ANY_TYPE_KEYS &&
273
277
  error.code !==
274
- LINT_ERROR_CODE_NON_EXISTENT_PROPERTY,
278
+ LINT_ERROR_CODE_NON_EXISTENT_PROPERTY &&
279
+ error.code !== LINT_ERROR_CODE_ITERATED_THROUGH,
275
280
  );
276
281
  // }
277
282
  tsErrors = convertToCodeMirrorDiagnostic(tsErrors);
@@ -8,8 +8,7 @@ import {
8
8
  } from './featureFlags.js';
9
9
  import createIgnore from 'ignore';
10
10
  import { ignoreFilePattern, baseIgnore } from './config.js';
11
-
12
- const isDirectory = (file) => file.endsWith('/');
11
+ import { isDirectory } from './isDirectory.js';
13
12
 
14
13
  /**
15
14
  * @param {string} fullPath - absolut path of the workspace root
@@ -100,10 +100,9 @@ export const generateAIResponse = async ({
100
100
 
101
101
  shareDBDoc.submitOp(op, { source: AISourceName });
102
102
 
103
- // Wait for 500ms
104
103
  if (slowdown) {
105
104
  await new Promise((resolve) => {
106
- setTimeout(resolve, 1000);
105
+ setTimeout(resolve, 2000);
107
106
  });
108
107
  }
109
108
 
@@ -14,6 +14,7 @@ import bodyParser from 'body-parser';
14
14
  import { json1Presence } from '../ot.js';
15
15
  import { computeInitialDocument } from './computeInitialDocument.js';
16
16
  import { handleAIAssist } from './handleAIAssist.js';
17
+ import { isDirectory } from './isDirectory.js';
17
18
 
18
19
  // The time in milliseconds by which auto-saving is debounced.
19
20
  const autoSaveDebounceTimeMS = 800;
@@ -114,6 +115,9 @@ const save = () => {
114
115
  ...currentDocument.files,
115
116
  ...previousDocument.files,
116
117
  });
118
+
119
+ const directoriesToDelete = [];
120
+
117
121
  for (const key of allKeys) {
118
122
  const previous = previousDocument.files[key];
119
123
  const current = currentDocument.files[key];
@@ -125,9 +129,69 @@ const save = () => {
125
129
  fs.writeFileSync(current.name, current.text);
126
130
  }
127
131
 
132
+ // // Handle renaming files.
133
+ // if (previous.name !== current.name) {
134
+
135
+ // const previousPath = previous.name.split('/');
136
+ // const currentPath = current.name.split('/');
137
+
138
+ // // - If the path is length 1 for previous and current,
139
+ // // then this should be true.
140
+ // // - If the path length is the sane for previous and current,
141
+ // // AND all the entries leading up to the last one are the same
142
+ // // between previous and current, AND the last entry in the arrays
143
+ // // (the file name itself) is different between previous and current
144
+ // const onlyFileNameChanged =
145
+ // (previousPath.length === 1 &&
146
+ // currentPath.length === 1) ||
147
+ // (previousPath.length === currentPath.length &&
148
+ // previousPath
149
+ // .slice(0, -1)
150
+ // .every(
151
+ // (val, index) => val === currentPath[index],
152
+ // ) &&
153
+ // previousPath.at(-1) !== currentPath.at(-1));
154
+
155
+ // // This logic works if only the file name itself changes.
156
+ // if (onlyFileNameChanged) {
157
+ // fs.renameSync(previous.name, current.name);
158
+ // }
159
+ // {
160
+ // // If we get here, then the directory may have been renamed,
161
+ // // or the file has been moved between directories.
162
+ // // If we get here, then the directory may have been renamed,
163
+ // // or the file has been moved between directories.
164
+ // const newDir = path.dirname(current.name);
165
+
166
+ // // Check if the new directory exists, if not, create it
167
+ // if (!fs.existsSync(newDir)) {
168
+ // fs.mkdirSync(newDir, { recursive: true });
169
+ // }
170
+
171
+ // // Move the file to the new directory
172
+ // fs.renameSync(previous.name, current.name);
173
+ // }
174
+ // }
128
175
  // Handle renaming files.
129
176
  if (previous.name !== current.name) {
130
- fs.renameSync(previous.name, current.name);
177
+ if (isDirectory(previous.name)) {
178
+ // If the directory itself is being renamed,
179
+ // Phase I: Ignore it, and get the files moved
180
+ // Phase II: Keep track of these, and delete them after
181
+ // all the files moved.
182
+ // directoriesToDelete.push(previous.name)
183
+ directoriesToDelete.push(previous.name);
184
+ } else {
185
+ const newDir = path.dirname(current.name);
186
+
187
+ // Check if the new directory exists, if not, create it
188
+ if (!fs.existsSync(newDir)) {
189
+ fs.mkdirSync(newDir, { recursive: true });
190
+ }
191
+
192
+ // Move the file to the new directory
193
+ fs.renameSync(previous.name, current.name);
194
+ }
131
195
  }
132
196
  }
133
197
 
@@ -158,6 +222,23 @@ const save = () => {
158
222
  fs.writeFileSync(current.name, current.text);
159
223
  }
160
224
  }
225
+ // TODO deleted all directories under directoriesToDelete
226
+
227
+ for (const dir of directoriesToDelete) {
228
+ //Performs directory deletion.
229
+ fs.rm(
230
+ dir,
231
+ {
232
+ recursive: true, //Makes sure that all files in directory are deleted.
233
+ },
234
+ (error) => {
235
+ if (error) {
236
+ console.log(error);
237
+ }
238
+ },
239
+ );
240
+ }
241
+
161
242
  previousDocument = currentDocument;
162
243
  };
163
244
 
@@ -0,0 +1 @@
1
+ export const isDirectory = (file) => file.endsWith('/');