vzcode 1.10.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/assets/{index-DXNuoOqQ.js → index-BSuijdti.js} +9 -9
- package/dist/index.html +1 -1
- package/package.json +4 -4
- package/src/client/CodeEditor/getOrCreateEditor.ts +4 -0
- package/src/client/CodeEditor/index.tsx +2 -0
- package/src/client/CodeEditor/json1PresenceDisplay.ts +128 -90
- package/src/client/VZCodeContext.tsx +3 -7
- package/src/types.ts +7 -70
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-
|
|
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.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Multiplayer code editor system",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
"json0-ot-diff": "^1.1.2",
|
|
141
141
|
"ngrok": "^4.3.3",
|
|
142
142
|
"open": "^10.1.0",
|
|
143
|
-
"openai": "^4.52.
|
|
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",
|
|
@@ -157,10 +157,10 @@
|
|
|
157
157
|
"@vitejs/plugin-react": "^4.3.1",
|
|
158
158
|
"concurrently": "^8.2.2",
|
|
159
159
|
"prettier": "^3.3.2",
|
|
160
|
-
"sass": "^1.77.
|
|
160
|
+
"sass": "^1.77.7",
|
|
161
161
|
"typescript": "^5.5.3",
|
|
162
162
|
"vite": "^5.3.3",
|
|
163
|
-
"vitest": "^2.0.
|
|
163
|
+
"vitest": "^2.0.2"
|
|
164
164
|
},
|
|
165
165
|
"optionalDependencies": {
|
|
166
166
|
"@rollup/rollup-darwin-arm64": "^4.18.1",
|
|
@@ -40,6 +40,7 @@ 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';
|
|
43
44
|
import { cssLanguage } from '@codemirror/lang-css';
|
|
44
45
|
import { javascriptLanguage } from '@codemirror/lang-javascript';
|
|
45
46
|
|
|
@@ -115,6 +116,7 @@ export const getOrCreateEditor = ({
|
|
|
115
116
|
customInteractRules,
|
|
116
117
|
allowGlobals,
|
|
117
118
|
enableAutoFollowRef,
|
|
119
|
+
openTab,
|
|
118
120
|
}: {
|
|
119
121
|
fileId: FileId;
|
|
120
122
|
|
|
@@ -148,6 +150,7 @@ export const getOrCreateEditor = ({
|
|
|
148
150
|
// Ref to a boolean that determines whether to
|
|
149
151
|
// enable auto-following the cursors of remote users.
|
|
150
152
|
enableAutoFollowRef: React.MutableRefObject<boolean>;
|
|
153
|
+
openTab: (tabState: TabState) => void;
|
|
151
154
|
}): EditorCacheValue => {
|
|
152
155
|
// Cache hit
|
|
153
156
|
if (editorCache.has(fileId)) {
|
|
@@ -202,6 +205,7 @@ export const getOrCreateEditor = ({
|
|
|
202
205
|
path: textPath,
|
|
203
206
|
docPresence,
|
|
204
207
|
enableAutoFollowRef,
|
|
208
|
+
openTab,
|
|
205
209
|
}),
|
|
206
210
|
);
|
|
207
211
|
}
|
|
@@ -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 {
|
|
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
|
-
|
|
53
|
-
});
|
|
64
|
+
// view.dom.addEventListener('scroll', () => {
|
|
65
|
+
// this.scrollToCursor(view);
|
|
66
|
+
// });
|
|
54
67
|
// Receive remote presence changes.
|
|
55
|
-
docPresence.on(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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) {
|
|
@@ -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;
|
package/src/types.ts
CHANGED
|
@@ -115,57 +115,6 @@ export type ShareDBDoc<T> = {
|
|
|
115
115
|
// Generated by the client.
|
|
116
116
|
export type AIStreamId = string;
|
|
117
117
|
|
|
118
|
-
// // TODO define this interface.
|
|
119
|
-
// export type AIStreamStatus = {
|
|
120
|
-
// // This field is managed by the client.
|
|
121
|
-
// // * `true` if the client wants the server to start the generation.
|
|
122
|
-
// // * `false` if the client does not want the server to start the generation.
|
|
123
|
-
// clientWantsToStart: boolean;
|
|
124
|
-
|
|
125
|
-
// // This field is managed by the server.
|
|
126
|
-
// // * `true` if the server is running the generation.
|
|
127
|
-
// // * `false` if the server is not running the generation.
|
|
128
|
-
// serverIsRunning: boolean;
|
|
129
|
-
|
|
130
|
-
// text: string;
|
|
131
|
-
|
|
132
|
-
// startingInsertionCursor: number;
|
|
133
|
-
// fileId: FileId;
|
|
134
|
-
// };
|
|
135
|
-
|
|
136
|
-
/// Alternative universe
|
|
137
|
-
|
|
138
|
-
// // // If the generation started yet or not
|
|
139
|
-
// // // * If not, the server will start it.
|
|
140
|
-
// // started: boolean;
|
|
141
|
-
|
|
142
|
-
// // Required?
|
|
143
|
-
// // aiStreamId: AIStreamId
|
|
144
|
-
|
|
145
|
-
// // The generation status
|
|
146
|
-
// // * "running" if the generation is running
|
|
147
|
-
// // * "finished" if the generation is finished
|
|
148
|
-
// // * "error" if the generation errored
|
|
149
|
-
// // * "stopped" if the generation was stopped
|
|
150
|
-
// status:
|
|
151
|
-
// | 'unstarted'
|
|
152
|
-
// | 'running'
|
|
153
|
-
// | 'finished'
|
|
154
|
-
// | 'error'
|
|
155
|
-
// | 'stopped';
|
|
156
|
-
|
|
157
|
-
// // Possible states:
|
|
158
|
-
// // * { started: 'unstarted' } - client added this,
|
|
159
|
-
// // It should trigger the server to start the generation.
|
|
160
|
-
// // * { status: 'running' } - server added this,
|
|
161
|
-
// // It indicates that the generation is running.
|
|
162
|
-
// // * { status: 'finished' } - server added this,
|
|
163
|
-
// // It indicates that the generation is finished.
|
|
164
|
-
// // * { status: 'stopped' } - server added this,
|
|
165
|
-
// // It indicates that the generation was stopped.
|
|
166
|
-
// //
|
|
167
|
-
// // After `status` transitions to `finished` or `stopped`,
|
|
168
|
-
|
|
169
118
|
// The ShareDB document type for VZCode.
|
|
170
119
|
export type VZCodeContent = {
|
|
171
120
|
// `files`
|
|
@@ -179,25 +128,13 @@ export type VZCodeContent = {
|
|
|
179
128
|
// * `false` or `undefined` when they are not (e.g. normal typing)
|
|
180
129
|
// * Hot reloading is debounced when this is `false`.
|
|
181
130
|
isInteracting?: boolean;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// client and server.
|
|
190
|
-
// * This can power the transition of the icon from
|
|
191
|
-
// lightning bolt to stop sign and back (when stream finishes)
|
|
192
|
-
// aiStreams?: {
|
|
193
|
-
// // These need to be removed at some point?
|
|
194
|
-
// [aiStreamId: AIStreamId]: {
|
|
195
|
-
// AIStreamStatus: AIStreamStatus;
|
|
196
|
-
// };
|
|
197
|
-
// };
|
|
198
|
-
|
|
199
|
-
// TODO consider is there a way to replace the HTTP request to
|
|
200
|
-
// the AIAssist endpoint with a manipulation of the ShareDB document?
|
|
131
|
+
};
|
|
132
|
+
// Example Presence object, from ShareDB:
|
|
133
|
+
// {"start":["files","69064344","text",183],"end":["files","69064344","text",183],"username":"Jim"}
|
|
134
|
+
export type Presence = {
|
|
135
|
+
start: Array<string | number>;
|
|
136
|
+
end: Array<string | number>;
|
|
137
|
+
username: Username;
|
|
201
138
|
};
|
|
202
139
|
|
|
203
140
|
// An id used for presence.
|