vzcode 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -20,7 +20,7 @@
20
20
  href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap"
21
21
  rel="stylesheet"
22
22
  />
23
- <script type="module" crossorigin src="/assets/index-BRLn2sA_.js"></script>
23
+ <script type="module" crossorigin src="/assets/index-BSuijdti.js"></script>
24
24
  <link rel="stylesheet" crossorigin href="/assets/index-BKRpkJER.css">
25
25
  </head>
26
26
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -140,14 +140,14 @@
140
140
  "json0-ot-diff": "^1.1.2",
141
141
  "ngrok": "^4.3.3",
142
142
  "open": "^10.1.0",
143
- "openai": "^4.52.3",
143
+ "openai": "^4.52.5",
144
144
  "prettier-plugin-svelte": "^3.2.5",
145
145
  "react": "^18.3.1",
146
146
  "react-bootstrap": "^2.10.4",
147
147
  "react-dom": "^18.3.1",
148
148
  "react-router-dom": "^6.24.1",
149
149
  "sharedb": "^5.0.2",
150
- "sharedb-client-browser": "^5.0.1",
150
+ "sharedb-client-browser": "^5.0.2",
151
151
  "vizhub-ui": "^3.23.0",
152
152
  "ws": "^8.18.0"
153
153
  },
@@ -157,13 +157,13 @@
157
157
  "@vitejs/plugin-react": "^4.3.1",
158
158
  "concurrently": "^8.2.2",
159
159
  "prettier": "^3.3.2",
160
- "sass": "^1.77.6",
160
+ "sass": "^1.77.7",
161
161
  "typescript": "^5.5.3",
162
162
  "vite": "^5.3.3",
163
- "vitest": "^1.6.0"
163
+ "vitest": "^2.0.2"
164
164
  },
165
165
  "optionalDependencies": {
166
- "@rollup/rollup-darwin-arm64": "^4.18.0",
167
- "@rollup/rollup-win32-x64-msvc": "^4.18.0"
166
+ "@rollup/rollup-darwin-arm64": "^4.18.1",
167
+ "@rollup/rollup-win32-x64-msvc": "^4.18.1"
168
168
  }
169
169
  }
@@ -40,6 +40,9 @@ import { keymap } from '@codemirror/view';
40
40
  import { basicSetup } from './basicSetup';
41
41
  import { InteractRule } from '@replit/codemirror-interact';
42
42
  import rainbowBrackets from '../CodeEditor/rainbowBrackets';
43
+ import { TabState } from '../vzReducer';
44
+ import { cssLanguage } from '@codemirror/lang-css';
45
+ import { javascriptLanguage } from '@codemirror/lang-javascript';
43
46
 
44
47
  // Feature flag to enable TypeScript completions & TypeScript Linter.
45
48
  const enableTypeScriptCompletions = true;
@@ -49,6 +52,26 @@ const enableTypeScriptLinter = true;
49
52
  const tsx = () =>
50
53
  javascript({ jsx: true, typescript: true });
51
54
 
55
+ const htmlConfig = {
56
+ matchClosingTags: true,
57
+ selfClosingTags: false,
58
+ autoCloseTags: true,
59
+ extraTags: {},
60
+ extraGlobalAttributes: {},
61
+ nestedLanguages: [
62
+ {
63
+ tag: 'script',
64
+ language: javascript,
65
+ parser: javascriptLanguage.parser,
66
+ },
67
+ {
68
+ tag: 'style',
69
+ language: css,
70
+ parser: cssLanguage.parser,
71
+ },
72
+ ],
73
+ nestedAttributes: [],
74
+ };
52
75
  // Language extensions for CodeMirror.
53
76
  // Keys are file extensions.
54
77
  // Values are CodeMirror extensions.
@@ -59,7 +82,7 @@ const languageExtensions = {
59
82
  js: tsx,
60
83
  jsx: tsx,
61
84
  ts: tsx,
62
- html,
85
+ html: () => html(htmlConfig),
63
86
  css,
64
87
  md: markdown,
65
88
  svelte,
@@ -93,6 +116,7 @@ export const getOrCreateEditor = ({
93
116
  customInteractRules,
94
117
  allowGlobals,
95
118
  enableAutoFollowRef,
119
+ openTab,
96
120
  }: {
97
121
  fileId: FileId;
98
122
 
@@ -126,6 +150,7 @@ export const getOrCreateEditor = ({
126
150
  // Ref to a boolean that determines whether to
127
151
  // enable auto-following the cursors of remote users.
128
152
  enableAutoFollowRef: React.MutableRefObject<boolean>;
153
+ openTab: (tabState: TabState) => void;
129
154
  }): EditorCacheValue => {
130
155
  // Cache hit
131
156
  if (editorCache.has(fileId)) {
@@ -146,6 +171,7 @@ export const getOrCreateEditor = ({
146
171
  let themeCompartment = new Compartment();
147
172
 
148
173
  // The CodeMirror extensions to use.
174
+ // const extensions = [autocompletion(), html(htmlConfig)]
149
175
  const extensions = [];
150
176
 
151
177
  // This plugin implements multiplayer editing,
@@ -179,6 +205,7 @@ export const getOrCreateEditor = ({
179
205
  path: textPath,
180
206
  docPresence,
181
207
  enableAutoFollowRef,
208
+ openTab,
182
209
  }),
183
210
  );
184
211
  }
@@ -266,18 +293,28 @@ export const getOrCreateEditor = ({
266
293
  // );
267
294
 
268
295
  // Add the extension that provides TypeScript completions.
269
- if (enableTypeScriptCompletions) {
270
- extensions.push(
271
- autocompletion({
272
- override: [
273
- typeScriptCompletions({
274
- typeScriptWorker,
275
- fileName: name,
276
- }),
277
- ],
278
- }),
279
- );
280
- }
296
+ // only add this if it's TS-compatible (.js, .jsx, .ts, .tsx)
297
+ const isTypeScript =
298
+ fileExtension === 'js' ||
299
+ fileExtension === 'jsx' ||
300
+ fileExtension === 'ts' ||
301
+ fileExtension === 'tsx';
302
+
303
+ extensions.push(
304
+ autocompletion(
305
+ isTypeScript
306
+ ? {
307
+ override: [
308
+ typeScriptCompletions({
309
+ typeScriptWorker,
310
+ fileName: name,
311
+ }),
312
+ ],
313
+ }
314
+ : undefined,
315
+ ),
316
+ );
317
+
281
318
  if (shareDBDoc && enableTypeScriptLinter) {
282
319
  extensions.push(
283
320
  linter(
@@ -38,6 +38,7 @@ export const CodeEditor = ({
38
38
  theme,
39
39
  codeEditorRef,
40
40
  enableAutoFollow,
41
+ openTab,
41
42
  } = useContext(VZCodeContext);
42
43
 
43
44
  // Set `doc.data.isInteracting` to `true` when the user is interacting
@@ -97,6 +98,7 @@ export const CodeEditor = ({
97
98
  customInteractRules,
98
99
  allowGlobals,
99
100
  enableAutoFollowRef,
101
+ openTab,
100
102
  }),
101
103
  [
102
104
  activeFileId,
@@ -6,7 +6,13 @@ import {
6
6
  } from '@codemirror/view';
7
7
  import { Annotation, RangeSet } from '@codemirror/state';
8
8
  import ColorHash from 'color-hash';
9
- import { Username } from '../../types';
9
+ import {
10
+ FileId,
11
+ Presence,
12
+ PresenceId,
13
+ Username,
14
+ } from '../../types';
15
+ import { TabState } from '../vzReducer';
10
16
 
11
17
  const debug = false;
12
18
 
@@ -26,6 +32,12 @@ export const json1PresenceDisplay = ({
26
32
  path,
27
33
  docPresence,
28
34
  enableAutoFollowRef,
35
+ openTab,
36
+ }: {
37
+ path: Array<string>;
38
+ docPresence: any;
39
+ enableAutoFollowRef: React.MutableRefObject<boolean>;
40
+ openTab: (tabState: TabState) => void;
29
41
  }) => [
30
42
  ViewPlugin.fromClass(
31
43
  class {
@@ -44,113 +56,139 @@ export const json1PresenceDisplay = ({
44
56
  // Mutable state local to this closure representing aggregated presence.
45
57
  // * Keys are presence ids
46
58
  // * Values are presence objects as defined by ot-json1-presence
47
- const presenceState = {};
59
+ const presenceState: Record<PresenceId, Presence> =
60
+ {};
48
61
 
49
62
  // Add the scroll event listener
50
63
  //This runs for the arrow key scrolling, it should result in the users scrolling to eachother's location.
51
- view.dom.addEventListener('scroll', () => {
52
- this.scrollToCursor(view);
53
- });
64
+ // view.dom.addEventListener('scroll', () => {
65
+ // this.scrollToCursor(view);
66
+ // });
54
67
  // Receive remote presence changes.
55
- docPresence.on('receive', (id, presence) => {
56
- if (debug) {
57
- console.log(
58
- `Received presence for id ${id}`,
68
+ docPresence.on(
69
+ 'receive',
70
+ (id: PresenceId, presence: Presence) => {
71
+ if (debug) {
72
+ console.log(
73
+ `Received presence for id ${id}`,
74
+ presence,
75
+ ); // Debug statement
76
+ }
77
+
78
+ // If presence === null, the user has disconnected / exited
79
+ if (!presence) {
80
+ delete presenceState[id];
81
+ return;
82
+ }
83
+
84
+ // Check if the presence is for the current file or not.
85
+ const isPresenceInCurrentFile = pathMatches(
86
+ path,
59
87
  presence,
60
- ); // Debug statement
61
- }
62
- // If presence === null, the user has disconnected / exited
63
- // We also check if the presence is for the current file or not.
64
- if (presence && pathMatches(path, presence)) {
65
- presenceState[id] = presence;
66
- } else {
67
- delete presenceState[id];
68
- }
69
- // Update decorations to reflect new presence state.
70
- // TODO consider mutating this rather than recomputing it on each change.
88
+ );
89
+
90
+ // If the presence is in the current file, update the presence state.
91
+ if (isPresenceInCurrentFile) {
92
+ presenceState[id] = presence;
93
+ } else if (presence) {
94
+ // Otherwise, delete the presence state.
95
+ delete presenceState[id];
71
96
 
72
- const presenceDecorations = [];
97
+ // If auto-follow is enabled, and the presence is NOT
98
+ // in the current file, then open the tab of the other user.
99
+ if (enableAutoFollowRef.current) {
100
+ openTab({
101
+ fileId: presence.start[1] as FileId,
102
+ isTransient: true,
103
+ });
104
+ }
105
+ }
106
+ // Update decorations to reflect new presence state.
107
+ // TODO consider mutating this rather than recomputing it on each change.
73
108
 
74
- // Object.keys(presenceState).map((id) => {
75
- for (const id of Object.keys(presenceState)) {
76
- const presence = presenceState[id];
77
- const { start, end } = presence;
78
- const from = start[start.length - 1];
79
- const to = end[end.length - 1];
80
- const userColor = new ColorHash({
81
- lightness: 0.75,
82
- }).rgb(id);
83
- const { username } = presence;
109
+ const presenceDecorations = [];
84
110
 
85
- presenceDecorations.push({
86
- from,
87
- to: from,
88
- value: Decoration.widget({
89
- side: -1,
90
- block: false,
91
- widget: new PresenceWidget(
92
- // TODO see if we can figure out why
93
- // updateDOM was not being called when passing
94
- // the presence id as the id
95
- // id,
96
- '' + Math.random(),
97
- userColor,
98
- username,
99
- ),
100
- }),
101
- });
111
+ // Object.keys(presenceState).map((id) => {
112
+ for (const id of Object.keys(presenceState)) {
113
+ const presence: Presence = presenceState[id];
114
+ const { start, end } = presence;
115
+ const from = +start[start.length - 1];
116
+ const to = +end[end.length - 1];
117
+ const userColor = new ColorHash({
118
+ lightness: 0.75,
119
+ }).rgb(id);
120
+ const { username } = presence;
102
121
 
103
- // This is `true` when the presence is a cursor,
104
- // with no selection.
105
- if (from !== to) {
106
- // This is the case when the presence is a selection.
107
122
  presenceDecorations.push({
108
123
  from,
109
- to,
110
- value: Decoration.mark({
111
- class: 'cm-json1-presence',
112
- attributes: {
113
- style: `
124
+ to: from,
125
+ value: Decoration.widget({
126
+ side: -1,
127
+ block: false,
128
+ widget: new PresenceWidget(
129
+ // TODO see if we can figure out why
130
+ // updateDOM was not being called when passing
131
+ // the presence id as the id
132
+ // id,
133
+ '' + Math.random(),
134
+ userColor,
135
+ username,
136
+ ),
137
+ }),
138
+ });
139
+
140
+ // This is `true` when the presence is a cursor,
141
+ // with no selection.
142
+ if (from !== to) {
143
+ // This is the case when the presence is a selection.
144
+ presenceDecorations.push({
145
+ from,
146
+ to,
147
+ value: Decoration.mark({
148
+ class: 'cm-json1-presence',
149
+ attributes: {
150
+ style: `
114
151
  background-color: rgba(${userColor}, 0.75);
115
152
  mix-blend-mode: luminosity;
116
153
  `,
117
- },
118
- }),
119
- });
154
+ },
155
+ }),
156
+ });
157
+ }
158
+ if (view.state.doc.length >= from) {
159
+ // Ensure position is valid
160
+ this.cursorPosition[id] = from; // Store the cursor position, important to run if we cant get the regular scroll to work
161
+ // console.log(`Stored cursor position for id ${id}: ${from}`); // Debug statement
162
+ } else {
163
+ // console.warn(`Invalid cursor position for id ${id}: ${from}`); // Debug statement
164
+ }
120
165
  }
121
- if (view.state.doc.length >= from) {
122
- // Ensure position is valid
123
- this.cursorPosition[id] = from; // Store the cursor position, important to run if we cant get the regular scroll to work
124
- // console.log(`Stored cursor position for id ${id}: ${from}`); // Debug statement
125
- } else {
126
- // console.warn(`Invalid cursor position for id ${id}: ${from}`); // Debug statement
127
- }
128
- }
129
166
 
130
- this.decorations = Decoration.set(
131
- presenceDecorations,
132
- // Without this argument, we get the following error:
133
- // Uncaught Error: Ranges must be added sorted by `from` position and `startSide`
134
- true,
135
- );
167
+ this.decorations = Decoration.set(
168
+ presenceDecorations,
169
+ // Without this argument, we get the following error:
170
+ // Uncaught Error: Ranges must be added sorted by `from` position and `startSide`
171
+ true,
172
+ );
136
173
 
137
- // Somehow this triggers re-rendering of the Decorations.
138
- // Not sure if this is the correct usage of the API.
139
- // Inspired by https://github.com/yjs/y-codemirror.next/blob/main/src/y-remote-selections.js
140
- // Set timeout so that the current CodeMirror update finishes
141
- // before the next ones that render presence begin.
142
- setTimeout(() => {
143
- view.dispatch({
144
- annotations: [presenceAnnotation.of(true)],
145
- });
146
- }, 0);
174
+ // Somehow this triggers re-rendering of the Decorations.
175
+ // Not sure if this is the correct usage of the API.
176
+ // Inspired by https://github.com/yjs/y-codemirror.next/blob/main/src/y-remote-selections.js
177
+ // Set timeout so that the current CodeMirror update finishes
178
+ // before the next ones that render presence begin.
179
+ setTimeout(() => {
180
+ view.dispatch({
181
+ annotations: [presenceAnnotation.of(true)],
182
+ });
183
+ }, 0);
147
184
 
148
- // Auto-follow all users when their presence is broadcast
149
- // by scrolling them into view.
150
- if (enableAutoFollowRef.current) {
151
- this.scrollToCursor(view);
152
- }
153
- });
185
+ // Auto-follow all users when their presence is broadcast
186
+ // by scrolling them into view.
187
+ if (enableAutoFollowRef.current) {
188
+ this.scrollToCursor(view);
189
+ }
190
+ },
191
+ );
154
192
  }
155
193
  // Method to scroll the view to keep the cursor in view
156
194
  scrollToCursor(view) {
@@ -13,7 +13,6 @@ export { QuestionMarkSVG } from './QuestionMarkSVG';
13
13
  export { PinSVG } from './PinSVG';
14
14
  export { FolderSVG } from './FolderSVG';
15
15
  export { SearchSVG } from './SearchSVG';
16
- export { SearchFileSVG } from './SearchFileSVG';
17
16
  export { JavaScriptSVG } from './JavaScriptSVG';
18
17
  export { TypeScriptSVG } from './TypeScriptSVG';
19
18
  export { ReactSVG } from './ReactSVG';
@@ -52,7 +52,9 @@ export type VZCodeContextValue = {
52
52
  submitOperation: (
53
53
  next: (content: VZCodeContent) => VZCodeContent,
54
54
  ) => void;
55
+ // TODO pull in this type from ShareDB if possible
55
56
  localPresence: any;
57
+ // TODO pull in this type from ShareDB if possible
56
58
  docPresence: any;
57
59
 
58
60
  files: Files | null;
@@ -76,13 +78,7 @@ export type VZCodeContextValue = {
76
78
  setActiveFileRight: () => void;
77
79
 
78
80
  tabList: Array<TabState>;
79
- openTab: ({
80
- fileId,
81
- isTransient,
82
- }: {
83
- fileId: string;
84
- isTransient?: boolean;
85
- }) => void;
81
+ openTab: (tabState: TabState) => void;
86
82
  closeTabs: (fileIds: string[]) => void;
87
83
 
88
84
  isSettingsOpen: boolean;
@@ -1,9 +1,45 @@
1
1
  import { useCallback, useContext } from 'react';
2
2
  import { Item } from './Item';
3
3
  import { FileId } from '../../types';
4
- import { FileSVG } from '../Icons';
4
+ import {
5
+ FileSVG,
6
+ JavaScriptSVG,
7
+ TypeScriptSVG,
8
+ ReactSVG,
9
+ SvelteSVG,
10
+ JsonSVG,
11
+ MarkdownSVG,
12
+ HtmlSVG,
13
+ CssSVG,
14
+ } from '../Icons';
5
15
  import { VZCodeContext } from '../VZCodeContext';
6
16
 
17
+ export function getExtensionIcon(fileName: string) {
18
+ const extension = fileName.split('.');
19
+
20
+ switch (extension[extension.length - 1]) {
21
+ case 'jsx':
22
+ case 'tsx':
23
+ return <ReactSVG />;
24
+ case 'js':
25
+ return <JavaScriptSVG />;
26
+ case 'ts':
27
+ return <TypeScriptSVG />;
28
+ case 'json':
29
+ return <JsonSVG />;
30
+ case 'md':
31
+ return <MarkdownSVG />;
32
+ case 'html':
33
+ return <HtmlSVG />;
34
+ case 'css':
35
+ return <CssSVG />;
36
+ case 'svelte':
37
+ return <SvelteSVG />;
38
+ default:
39
+ return <FileSVG />;
40
+ }
41
+ }
42
+
7
43
  export const FileListing = ({
8
44
  name,
9
45
  fileId,
@@ -49,9 +85,7 @@ export const FileListing = ({
49
85
  handleRenameClick={handleRenameClick}
50
86
  isActive={isActive}
51
87
  >
52
- <i className="file-icon">
53
- <FileSVG />
54
- </i>
88
+ <i className="file-icon">{getExtensionIcon(name)}</i>
55
89
  {name}
56
90
  </Item>
57
91
  );
@@ -12,6 +12,7 @@ import { Tooltip, OverlayTrigger } from '../bootstrap';
12
12
  import { DeleteConfirmationModal } from './DeleteConfirmationModal';
13
13
  import { VZCodeContext } from '../VZCodeContext';
14
14
  import { ItemId } from '../../types';
15
+ import { getExtensionIcon } from './FileListing';
15
16
 
16
17
  // TODO support renaming directories
17
18
  // See https://github.com/vizhub-core/vzcode/issues/103
@@ -169,7 +170,7 @@ export const Item = ({
169
170
  {isRenaming ? (
170
171
  <>
171
172
  <i className="file-icon">
172
- <FileSVG />
173
+ {getExtensionIcon(renameValue)}
173
174
  </i>
174
175
  <input
175
176
  className="rename-input"
@@ -1,16 +1,3 @@
1
- import {
2
- JavaScriptSVG,
3
- TypeScriptSVG,
4
- ReactSVG,
5
- SvelteSVG,
6
- JsonSVG,
7
- MarkdownSVG,
8
- HtmlSVG,
9
- CssSVG,
10
- SearchFileSVG,
11
- DirectoryArrowSVG,
12
- CloseSVG,
13
- } from '../Icons';
14
1
  import {
15
2
  useRef,
16
3
  useEffect,
@@ -21,30 +8,8 @@ import { Form } from '../bootstrap';
21
8
  import { VZCodeContext } from '../VZCodeContext';
22
9
  import { SearchFile } from '../../types';
23
10
  import { EditorView } from 'codemirror';
24
-
25
- function getExtensionIcon(extension: string) {
26
- switch (extension) {
27
- case 'jsx':
28
- case 'tsx':
29
- return <ReactSVG />;
30
- case 'js':
31
- return <JavaScriptSVG />;
32
- case 'ts':
33
- return <TypeScriptSVG />;
34
- case 'json':
35
- return <JsonSVG />;
36
- case 'md':
37
- return <MarkdownSVG />;
38
- case 'html':
39
- return <HtmlSVG />;
40
- case 'css':
41
- return <CssSVG />;
42
- case 'svelte':
43
- return <SvelteSVG />;
44
- default:
45
- return <SearchFileSVG />;
46
- }
47
- }
11
+ import { getExtensionIcon } from './FileListing';
12
+ import { CloseSVG, DirectoryArrowSVG } from '../Icons';
48
13
 
49
14
  function jumpToPattern(
50
15
  editor: EditorView,
@@ -102,6 +67,7 @@ export const Search = () => {
102
67
  return () => clearTimeout(delaySearch);
103
68
  } else {
104
69
  setIsMounted(true);
70
+ inputRef.current.focus();
105
71
  }
106
72
  }, [pattern]);
107
73
 
@@ -151,9 +117,7 @@ export const Search = () => {
151
117
  <DirectoryArrowSVG />
152
118
  </div>
153
119
  <div className="search-file-name">
154
- {getExtensionIcon(
155
- file.name.split('.')[1],
156
- )}
120
+ {getExtensionIcon(file.name)}
157
121
  <h5>{file.name}</h5>
158
122
  </div>
159
123
  </div>