vzcode 0.23.0 → 0.25.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 (30) hide show
  1. package/dist/assets/index-8628ebab.js +111 -0
  2. package/dist/assets/{index-c63b4be7.css → index-cf19de3b.css} +1 -1
  3. package/dist/assets/{worker-d5f0575a.js → worker-b775ddff.js} +1 -1
  4. package/dist/index.html +2 -2
  5. package/package.json +19 -9
  6. package/src/client/App.tsx +111 -30
  7. package/src/client/CodeEditor/getOrCreateEditor.ts +10 -1
  8. package/src/client/CodeEditor/index.tsx +9 -5
  9. package/src/client/CodeEditor/json1PresenceBroadcast.js +2 -0
  10. package/src/client/CodeEditor/json1PresenceDisplay.js +45 -1
  11. package/src/client/CodeEditor/widgets.ts +183 -10
  12. package/src/client/PresenceNotifications/index.tsx +145 -0
  13. package/src/client/PresenceNotifications/style.scss +17 -0
  14. package/src/client/PrettierErrorOverlay/index.tsx +9 -0
  15. package/src/client/PrettierErrorOverlay/style.scss +9 -0
  16. package/src/client/Settings.tsx +11 -1
  17. package/src/client/Sidebar/FileListing.tsx +0 -1
  18. package/src/client/Sidebar/Item.tsx +20 -11
  19. package/src/client/reducer.ts +119 -0
  20. package/src/client/style.scss +3 -0
  21. package/src/client/themes/index.ts +7 -0
  22. package/src/client/{themes.ts → themes/themes.ts} +5 -5
  23. package/src/client/{useDynamicTheme.ts → themes/useDynamicTheme.ts} +1 -1
  24. package/src/client/themes/vizhubTheme/colors.ts +80 -0
  25. package/src/client/themes/vizhubTheme/index.ts +166 -0
  26. package/src/client/usePrettier/index.ts +32 -14
  27. package/src/client/usePrettier/worker.ts +1 -1
  28. package/dist/assets/index-49f71876.js +0 -110
  29. package/src/client/useTabsState.ts +0 -58
  30. package/src/client/vizhubTheme.js +0 -1
@@ -0,0 +1,80 @@
1
+ // import { hcl } from 'd3-color';
2
+
3
+ // This module defines all the colors for the VizHub theme.
4
+ // Ported from the CodeMirror 5 theme defined here:
5
+ // https://github.com/vizhub-core/vizhub-legacy/blob/01cadfb78a2611df32f981b1fd8136b70447de9e/vizhub-v2/packages/neoFrontend/src/pages/VizPage/Body/Editor/themes/vizHub.js
6
+
7
+ // This is how the colors were generated:
8
+ // const sidebarDark = hcl('#3d4b65');
9
+ // const sidebarLight = hcl('#5b677d');
10
+ // const luminaceDifference = sidebarLight.l - sidebarDark.l;
11
+ // const backgroundLuminance =
12
+ // sidebarDark.l - luminaceDifference * 1.1;
13
+ // const luminance = 90;
14
+ // export const backgroundColor = hcl(
15
+ // sidebarDark.h,
16
+ // sidebarDark.c,
17
+ // backgroundLuminance,
18
+ // ).formatHex();
19
+ // export const light = hcl(0, 0, luminance).formatHex();
20
+ // export const dark = hcl(
21
+ // sidebarDark.h,
22
+ // sidebarDark.c,
23
+ // 80,
24
+ // ).formatHex();
25
+ // console.log(
26
+ // JSON.stringify(
27
+ // {
28
+ // backgroundColor,
29
+ // light,
30
+ // dark,
31
+ // },
32
+ // null,
33
+ // 2,
34
+ // ),
35
+ // );
36
+
37
+ // These are inlined from the above code, but the code is kept around for future reference.
38
+ export const backgroundColor = '#202e46';
39
+ export const light = '#e2e2e2';
40
+ export const dark = '#b9c7e6';
41
+
42
+ export const lineNumbers = 'rgba(255,255,255,0.2)';
43
+ export const lineNumbersActive = 'rgba(255,255,255,0.5)';
44
+ export const selectionBackground = '#000';
45
+ export const selectionBackgroundMatch = 'rgba(0,0,0,0.4)';
46
+ export const lineHighlight = 'rgba(0,0,0,0.1)';
47
+ export const caretColor = 'white';
48
+
49
+ // Compute 6 colors that are evenly spaced in terms of hue
50
+ // Keeping this code around for future reference
51
+ // const rotation = 0.397;
52
+ // const numColors = 6;
53
+ // const highlightColors = Array.from(
54
+ // { length: numColors },
55
+ // (_, i) => {
56
+ // let t = (i / numColors + rotation) % 1;
57
+ // return hcl(t * 360, saturation, luminance).formatHex();
58
+ // },
59
+ // );
60
+ // console.log(JSON.stringify(highlightColors));
61
+
62
+ // We inline the colors here, but the code above is how they were generated.
63
+ const highlightColors = [
64
+ '#77fd8c',
65
+ '#00ffff',
66
+ '#66ecff',
67
+ '#ffb9ff',
68
+ '#ffabb3',
69
+ '#ffdb56',
70
+ ];
71
+
72
+ export const MINT = highlightColors[0];
73
+ export const AQUA = highlightColors[1];
74
+ export const SKY = highlightColors[2];
75
+ export const LAVENDER = highlightColors[3];
76
+ export const SALMON = highlightColors[4];
77
+ export const GOLDENROD = highlightColors[5];
78
+
79
+ // Red that's not too bright, for errors
80
+ export const PANIC = '#ff2222';
@@ -0,0 +1,166 @@
1
+ // A CodeMirror 6 theme for the VizHub syntax highlighting colors.
2
+
3
+ // Inspired by https://github.com/uiwjs/react-codemirror/blob/master/themes/vscode/src/index.ts
4
+
5
+ import { tags as t } from '@lezer/highlight';
6
+ import {
7
+ createTheme,
8
+ CreateThemeOptions,
9
+ } from '@uiw/codemirror-themes';
10
+
11
+ import {
12
+ // Colors for various things outside the code itself
13
+ backgroundColor,
14
+ lineHighlight,
15
+ light,
16
+ dark,
17
+ lineNumbers,
18
+ lineNumbersActive,
19
+ selectionBackground,
20
+ selectionBackgroundMatch,
21
+ caretColor,
22
+
23
+ // Syntax highlighting colors
24
+ MINT,
25
+ AQUA,
26
+ SKY,
27
+ LAVENDER,
28
+ SALMON,
29
+ GOLDENROD,
30
+ PANIC,
31
+ } from './colors';
32
+
33
+ const defaultSettingsVizhubTheme: CreateThemeOptions['settings'] =
34
+ {
35
+ background: backgroundColor,
36
+ foreground: light,
37
+ caret: caretColor,
38
+ selection: selectionBackground,
39
+ selectionMatch: selectionBackgroundMatch,
40
+ lineHighlight,
41
+ gutterBackground: backgroundColor,
42
+ gutterForeground: lineNumbers,
43
+ gutterActiveForeground: lineNumbersActive,
44
+ };
45
+
46
+ function vizhubThemeInit(
47
+ options?: Partial<CreateThemeOptions>,
48
+ ) {
49
+ const {
50
+ theme = 'dark',
51
+ settings = {},
52
+ styles = [],
53
+ } = options || {};
54
+ return createTheme({
55
+ theme: theme,
56
+ settings: {
57
+ ...defaultSettingsVizhubTheme,
58
+ ...settings,
59
+ },
60
+ styles: [
61
+ {
62
+ tag: [
63
+ t.keyword,
64
+ t.operatorKeyword,
65
+ t.modifier,
66
+ t.color,
67
+ t.constant(t.name),
68
+ t.standard(t.name),
69
+ t.standard(t.tagName),
70
+ t.special(t.brace),
71
+ t.atom,
72
+ t.bool,
73
+ t.special(t.variableName),
74
+ ],
75
+ color: MINT,
76
+ },
77
+ {
78
+ tag: [t.controlKeyword, t.moduleKeyword],
79
+ color: MINT,
80
+ },
81
+ {
82
+ tag: [
83
+ t.name,
84
+ t.deleted,
85
+ t.character,
86
+ t.macroName,
87
+
88
+ t.variableName,
89
+ t.labelName,
90
+ t.definition(t.name),
91
+ ],
92
+ color: AQUA,
93
+ },
94
+ {
95
+ tag: [t.propertyName],
96
+ color: GOLDENROD,
97
+ },
98
+ {
99
+ tag: t.heading,
100
+ fontWeight: 'bold',
101
+ color: SKY,
102
+ },
103
+ {
104
+ tag: [
105
+ t.typeName,
106
+ t.className,
107
+ t.tagName,
108
+ t.number,
109
+ t.changed,
110
+ t.annotation,
111
+ t.self,
112
+ t.namespace,
113
+ ],
114
+ color: AQUA,
115
+ },
116
+ {
117
+ tag: [
118
+ t.function(t.variableName),
119
+ t.function(t.propertyName),
120
+ ],
121
+ color: AQUA,
122
+ },
123
+ { tag: [t.number], color: SALMON },
124
+ {
125
+ tag: [
126
+ t.operator,
127
+ t.punctuation,
128
+ t.separator,
129
+ t.url,
130
+ t.escape,
131
+ t.regexp,
132
+ ],
133
+ color: light,
134
+ },
135
+ {
136
+ tag: [t.regexp],
137
+ color: LAVENDER,
138
+ },
139
+ {
140
+ tag: [t.special(t.string), t.string, t.inserted],
141
+ color: LAVENDER,
142
+ },
143
+ {
144
+ tag: [t.processingInstruction],
145
+ color: AQUA,
146
+ },
147
+ { tag: [t.angleBracket], color: AQUA },
148
+ { tag: t.strong, fontWeight: 'bold' },
149
+ { tag: t.emphasis, fontStyle: 'italic' },
150
+ {
151
+ tag: t.strikethrough,
152
+ textDecoration: 'line-through',
153
+ },
154
+ { tag: [t.meta, t.comment], color: dark },
155
+ {
156
+ tag: t.link,
157
+ color: GOLDENROD,
158
+ textDecoration: 'underline',
159
+ },
160
+ { tag: t.invalid, color: PANIC },
161
+ ...styles,
162
+ ],
163
+ });
164
+ }
165
+
166
+ export const vizhubTheme = vizhubThemeInit();
@@ -4,7 +4,7 @@ import {
4
4
  ShareDBDoc,
5
5
  VZCodeContent,
6
6
  } from '../../types';
7
- import { useEffect, useRef } from 'react';
7
+ import { useEffect, useRef, useState } from 'react';
8
8
 
9
9
  // The time in milliseconds by which auto-saving is debounced.
10
10
  const autoPrettierDebounceTimeMS = 1200;
@@ -31,6 +31,14 @@ export const usePrettier = (
31
31
  // since the last Prettier run.
32
32
  const dirtyFiles: Set<FileId> = new Set<FileId>();
33
33
 
34
+ // State to hold the error from Prettier
35
+ // `null` means no errors
36
+ // If this is a string, it's the
37
+ // error message from Prettier.
38
+ const [prettierError, setPrettierError] = useState<
39
+ string | null
40
+ >(null);
41
+
34
42
  // A ref to keep track of whether an op is being applied.
35
43
  // This is used to prevent Prettier from running
36
44
  // when the op is coming from Prettier itself.
@@ -46,9 +54,18 @@ export const usePrettier = (
46
54
  const handleMessage = (event) => {
47
55
  const { fileId, error, fileTextPrettified } =
48
56
  event.data;
57
+
58
+ // Handle syntax errors
49
59
  if (error) {
50
- console.log(error);
60
+ // If there's an error, set the error state
61
+ setPrettierError(error);
62
+
63
+ // Return early as there is no text change to apply.
51
64
  return;
65
+ } else {
66
+ // Make sure the error overlay goes away
67
+ // when Prettier runs successfully with no errors.
68
+ setPrettierError(null);
52
69
  }
53
70
 
54
71
  isApplyingOpRef.current = true;
@@ -159,19 +176,20 @@ export const usePrettier = (
159
176
  } else {
160
177
  // console.log('ignoring op from remote', op, isLocal);
161
178
  }
162
-
163
- // In the event that the component unmounts,
164
- return () => {
165
- // Remove the event listener
166
- prettierWorker.removeEventListener(
167
- 'message',
168
- handleMessage,
169
- );
170
-
171
- // Clear the timeout
172
- clearTimeout(debounceTimeout);
173
- };
174
179
  },
175
180
  );
181
+
182
+ // In the event that the component unmounts,
183
+ return () => {
184
+ // Remove the event listener
185
+ prettierWorker.removeEventListener(
186
+ 'message',
187
+ handleMessage,
188
+ );
189
+
190
+ // Clear the timeout
191
+ clearTimeout(debounceTimeout);
192
+ };
176
193
  }, [shareDBDoc]);
194
+ return { prettierError }; // Return the errors for use in other files
177
195
  };
@@ -90,7 +90,7 @@ onmessage = async ({
90
90
  } catch (error) {
91
91
  postMessage({
92
92
  fileId,
93
- error,
93
+ error: error.toString(),
94
94
  });
95
95
  }
96
96
  };