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,174 +0,0 @@
1
- import { Extension, RangeSet } from '@codemirror/state';
2
- import {
3
- Decoration,
4
- EditorView,
5
- ViewPlugin,
6
- WidgetType,
7
- } from '@codemirror/view';
8
- import { colorPickerRegex } from './colorPicker';
9
-
10
- const colorCircleTheme = EditorView.baseTheme({
11
- '.color-circle-parent': {
12
- display: 'inline-block',
13
- cursor: 'inherit',
14
- },
15
- });
16
-
17
- class ColorWidget extends WidgetType {
18
- color: string;
19
- constructor(color: string) {
20
- super();
21
- this.color = color;
22
- }
23
-
24
- eq(widget: ColorWidget): boolean {
25
- return widget.color === this.color;
26
- }
27
-
28
- toDOM(): HTMLElement {
29
- const parent = document.createElement('div');
30
- const size = 20;
31
- const innerSize = 14;
32
-
33
- parent.setAttribute(
34
- 'style',
35
- `width:${size}px;height:${size}px;position:relative;`,
36
- // Position relative for the hovering tool tip to work
37
- );
38
- parent.className = 'color-circle-parent';
39
- const svg = document.createElementNS(
40
- 'http://www.w3.org/2000/svg',
41
- 'svg',
42
- );
43
- const colorCircle = document.createElementNS(
44
- 'http://www.w3.org/2000/svg',
45
- 'circle',
46
- );
47
- colorCircle.setAttributeNS(
48
- null,
49
- 'fill',
50
- this.color.replace(/["']/g, ''),
51
- );
52
- colorCircle.setAttributeNS(null, 'stroke', 'white');
53
- colorCircle.setAttributeNS(
54
- null,
55
- 'stroke-width',
56
- '0.75',
57
- );
58
- colorCircle.setAttributeNS(
59
- null,
60
- 'r',
61
- '' + innerSize / 2,
62
- );
63
- colorCircle.setAttributeNS(null, 'cx', '' + size / 2);
64
- colorCircle.setAttributeNS(
65
- null,
66
- 'cy',
67
- '' + (size / 2 - 1),
68
- );
69
-
70
- svg.setAttributeNS(null, 'width', '' + size);
71
- svg.setAttributeNS(null, 'height', '' + size);
72
-
73
- svg.appendChild(colorCircle);
74
-
75
- parent.appendChild(svg);
76
-
77
- // Hovering tool tip shortcut for when users hover over color circle
78
- const hoveringTooltip = document.createElement('div');
79
-
80
- // Set class for tooltip to use CSS styles
81
- hoveringTooltip.className = 'tooltip_hover_circle';
82
-
83
- hoveringTooltip.innerHTML = `<strong>Alt + Click on a hex color</strong><br />
84
- <div>Open a color picker to modify the color</div>`;
85
-
86
- parent.appendChild(hoveringTooltip);
87
-
88
- // Timer to prevent constant pop-ups when scrolling through code
89
- let hoverTimeout: number;
90
-
91
- // Fade in and fade out effect for when user hovers over the circle
92
- // Mouse Event to set y and x of the tool tip pop up to prevent overlap onto circle
93
- parent.addEventListener(
94
- 'mouseenter',
95
- (event: MouseEvent) => {
96
- hoverTimeout = window.setTimeout(() => {
97
- hoveringTooltip.style.top = `${event.clientY - 60}px`;
98
- hoveringTooltip.style.left = `${event.clientX}px`;
99
- hoveringTooltip.style.opacity = '1';
100
- }, 700);
101
- },
102
- );
103
-
104
- parent.addEventListener('mouseleave', () => {
105
- clearTimeout(hoverTimeout);
106
- hoveringTooltip.style.opacity = '0';
107
- });
108
-
109
- return parent;
110
- }
111
-
112
- ignoreEvent() {
113
- return false;
114
- }
115
- }
116
-
117
- export const colorsInTextPlugin: Extension = [
118
- ViewPlugin.fromClass(
119
- class {
120
- decorations: any;
121
- view: EditorView;
122
- constructor(view: EditorView) {
123
- this.decorations = RangeSet.of([]);
124
- this.view = view;
125
- }
126
- },
127
- {
128
- decorations: (v) => {
129
- const colorInfos = [];
130
-
131
- const lines = v.view.state.doc.iter();
132
- let line = lines.next();
133
-
134
- // Offset is the number of characters before the hex
135
- // so the circle can be placed properly.
136
- let offset = 0;
137
- while (!line.done) {
138
- if (line.value === '\n') {
139
- offset++;
140
- line = lines.next();
141
- continue;
142
- }
143
- const hexColorOccurences = line.value.matchAll(
144
- colorPickerRegex,
145
- );
146
- let hexOccurance = hexColorOccurences.next();
147
- while (!hexOccurance.done) {
148
- const offsetColorInfo = hexOccurance.value;
149
- offsetColorInfo.index += offset;
150
- colorInfos.push(offsetColorInfo);
151
- hexOccurance = hexColorOccurences.next();
152
- }
153
- offset += line.value.length;
154
- line = lines.next();
155
- }
156
-
157
- return Decoration.set(
158
- colorInfos.map((colorInfo) => {
159
- return {
160
- // 7 is the length of the hex color string
161
- from: colorInfo.index + 7,
162
- to: colorInfo.index + 7,
163
- value: Decoration.widget({
164
- side: -1,
165
- widget: new ColorWidget(colorInfo[0]),
166
- }),
167
- };
168
- }),
169
- );
170
- },
171
- },
172
- ),
173
- colorCircleTheme,
174
- ];
@@ -1,79 +0,0 @@
1
- // TODO - This file is not being used.
2
- // It was an attempt to highlight the interactive widgets in the editor.
3
- // It is a good idea to keep this file for future reference, as it's
4
- // pretty close to what we need to implement. It suffers from the following
5
- // issues:
6
- // - Hardcoded regexes for interactive widgets - we can pull from the various modules
7
- // - The highlight is not working properly - it's not un-highlighting
8
- // when the Alt key is released. This is likely due to the fact that the
9
- // plugin is not being updated when the key is released.
10
-
11
- // export const highlightWidgets = ViewPlugin.fromClass(
12
- // class {
13
- // showHighlight: boolean;
14
- // view: EditorView;
15
- // constructor(view: EditorView) {
16
- // this.showHighlight = false;
17
- // this.view = view;
18
- // }
19
- // },
20
- // {
21
- // decorations: (v) => {
22
- // if (!v.showHighlight) {
23
- // return Decoration.none;
24
- // }
25
-
26
- // const interactOpportunities = [];
27
- // const lines = v.view.state.doc.iter();
28
- // let line = lines.next();
29
-
30
- // //Offset is the number of characters before the regex so the highlighting can be placed properly.
31
- // let offset = 0;
32
- // while (!line.done) {
33
- // if (line.value === '\n') {
34
- // offset++;
35
- // line = lines.next();
36
- // continue;
37
- // }
38
- // const interactiveOccurances = line.value.matchAll(
39
- // //The below line contains all of the Regexes for all of the interactive widgets.
40
- // /\"\#([0-9]|[A-F]|[a-f]){6}\"|rotate\(-?\d*\.?\d*\)|https?:\/\/[^ "]+|vec2\(-?\b\d+\.?\d*\b\s*(,\s*-?\b\d+\.?\d*\b)?\)|true|false|(?<!\#)-?\b\d+\.?\d*\b|rgb\(.*\)/dg,
41
- // );
42
- // let interactOccurance =
43
- // interactiveOccurances.next();
44
- // while (!interactOccurance.done) {
45
- // const offsetInteract = interactOccurance.value;
46
- // offsetInteract.indices[0][0] += offset;
47
- // offsetInteract.indices[0][1] += offset;
48
- // interactOpportunities.push(offsetInteract);
49
- // interactOccurance = interactiveOccurances.next();
50
- // }
51
- // offset += line.value.length;
52
- // line = lines.next();
53
- // }
54
- // return Decoration.set(
55
- // interactOpportunities.map((opportunity) => {
56
- // return {
57
- // from: opportunity.indices[0][0],
58
- // to: opportunity.indices[0][1],
59
- // value: Decoration.mark({
60
- // class: 'cm-interact ',
61
- // }),
62
- // };
63
- // }),
64
- // );
65
- // },
66
- // eventHandlers: {
67
- // keydown(event, view) {
68
- // if (event.key == 'Alt') {
69
- // this.showHighlight = true;
70
- // }
71
- // },
72
- // keyup(event, view) {
73
- // if (event.key == 'Alt') {
74
- // this.showHighlight = false;
75
- // }
76
- // },
77
- // },
78
- // },
79
- // );
@@ -1,44 +0,0 @@
1
- import interact, {
2
- InteractRule,
3
- } from '@replit/codemirror-interact';
4
- import { urlClicker } from './urlClicker';
5
- import { colorPicker } from './colorPicker';
6
- import { numberDragger } from './numberDragger';
7
- import { boolToggler } from './boolToggler';
8
- import { vec2Slider } from './vec2Slider';
9
- import { rotateWidget } from './rotateWidget';
10
- import { markdownCheckboxToggler } from './markdownCheckboxToggler';
11
-
12
- // Additional supporting CodeMirror plugins.
13
- export { colorsInTextPlugin } from './colorsInTextPlugin';
14
- export { rotationIndicator } from './rotateWidget';
15
-
16
- // Interactive code widgets.
17
- // * Number dragger
18
- // * Boolean toggler
19
- // * URL clicker
20
- // * color picker
21
- // Inspired by:
22
- // https://github.com/replit/codemirror-interact/blob/master/dev/index.ts
23
- // `onInteract` is called when the user interacts with a widget.
24
- export const widgets = ({
25
- onInteract,
26
- customInteractRules,
27
- }: {
28
- onInteract?: () => void;
29
- customInteractRules?: Array<InteractRule>;
30
- }) => {
31
- const rules: Array<InteractRule> = [
32
- colorPicker(onInteract),
33
- numberDragger(onInteract),
34
- markdownCheckboxToggler(onInteract),
35
- boolToggler(onInteract),
36
- vec2Slider(onInteract),
37
- rotateWidget(onInteract),
38
- urlClicker,
39
- ];
40
- if (customInteractRules) {
41
- rules.push(...customInteractRules);
42
- }
43
- return interact({ rules });
44
- };
@@ -1,12 +0,0 @@
1
- import { InteractRule } from '@replit/codemirror-interact';
2
-
3
- export const markdownCheckboxToggler = (
4
- onInteract?: () => void,
5
- ): InteractRule => ({
6
- regexp: /\[[ x]\]/g, // Matches [ ], [x], [X]
7
- cursor: 'pointer',
8
- onClick: (text, setText) => {
9
- setText(text === '[ ]' ? '[x]' : '[ ]');
10
- if (onInteract) onInteract();
11
- },
12
- });
@@ -1,20 +0,0 @@
1
- import { InteractRule } from '@replit/codemirror-interact';
2
-
3
- const numberDraggerRegex = /(?<!\#)-?\b\d+\.?\d*\b/g;
4
-
5
- // a rule for a number dragger
6
- export const numberDragger = (
7
- onInteract?: () => void,
8
- ): InteractRule => ({
9
- // the regexp matching the value
10
- regexp: numberDraggerRegex,
11
- // set cursor to "ew-resize" on hover
12
- cursor: 'ew-resize',
13
- // change number value based on mouse X movement on drag
14
- onDrag: (text, setText, e) => {
15
- const newVal = Number(text) + e.movementX;
16
- if (isNaN(newVal)) return;
17
- setText(newVal.toString());
18
- if (onInteract) onInteract();
19
- },
20
- });
@@ -1,143 +0,0 @@
1
- import {
2
- Decoration,
3
- EditorView,
4
- ViewPlugin,
5
- WidgetType,
6
- } from '@codemirror/view';
7
- import { InteractRule } from '@replit/codemirror-interact';
8
-
9
- let rotationOrigin: { x: number; y: number } = null;
10
- // Set rotation to the angle between the x-axis and a line
11
- // from the word "rotate" to the mouse pointer (while dragging).
12
- // The rotation is in range (-180,180]
13
- export const rotateWidget = (
14
- onInteract?: () => void,
15
- ): InteractRule => ({
16
- regexp: /rotate\(-?\d*\.?\d*\)/g,
17
- cursor: 'move',
18
- onDragStart(text, setText, e) {
19
- rotationOrigin = { x: e.clientX, y: e.clientY };
20
- },
21
-
22
- onDrag(text, setText, e) {
23
- if (rotationOrigin == null) return;
24
- const rotationDegree = Math.round(
25
- (Math.atan2(
26
- rotationOrigin.y - e.clientY,
27
- e.clientX - rotationOrigin.x,
28
- ) *
29
- 180) /
30
- Math.PI,
31
- );
32
- //Calculate the angle between the x axis and a line from where the user first clicks to the current location of the mouse.
33
- setText(`rotate(${rotationDegree})`);
34
- const updateDragEvent = new CustomEvent(
35
- 'updateRotateDrag',
36
- { detail: rotationDegree },
37
- );
38
-
39
- document.dispatchEvent(updateDragEvent);
40
-
41
- if (onInteract) onInteract();
42
- },
43
- onDragEnd() {
44
- rotationOrigin = null;
45
- },
46
- });
47
-
48
- export const rotationIndicator = ViewPlugin.fromClass(
49
- class {
50
- view: EditorView;
51
- textPosition?: number;
52
- rotation: number;
53
- constructor(view) {
54
- this.view = view;
55
- this.textPosition = null;
56
- this.rotation = 0;
57
-
58
- document.addEventListener(
59
- 'updateRotateDrag',
60
- (e: CustomEvent) => {
61
- this.textPosition = this.view.posAtCoords(
62
- rotationOrigin,
63
- false,
64
- );
65
-
66
- this.rotation = e.detail;
67
- },
68
- );
69
- }
70
- },
71
- {
72
- decorations: (v) => {
73
- if (rotationOrigin === null) {
74
- return Decoration.none;
75
- }
76
- return Decoration.set([
77
- {
78
- from: v.textPosition,
79
- to: v.textPosition,
80
- value: Decoration.widget({
81
- side: -1,
82
- widget: new RotationCircle(v.rotation),
83
- }),
84
- },
85
- ]);
86
- },
87
- },
88
- );
89
-
90
- class RotationCircle extends WidgetType {
91
- angle: number;
92
- constructor(angle: number) {
93
- super();
94
- this.angle = angle;
95
- }
96
-
97
- toDOM(view: EditorView): HTMLElement {
98
- const parent = document.createElement('div');
99
-
100
- parent.setAttribute('style', 'width:20px;height:20px');
101
- parent.className = 'color-circle-parent';
102
- const svg = document.createElementNS(
103
- 'http://www.w3.org/2000/svg',
104
- 'svg',
105
- );
106
- const colorCircle = document.createElementNS(
107
- 'http://www.w3.org/2000/svg',
108
- 'circle',
109
- );
110
- colorCircle.setAttributeNS(null, 'fill', '#808080');
111
- colorCircle.setAttributeNS(null, 'r', '5');
112
- colorCircle.setAttributeNS(null, 'cx', '5');
113
- colorCircle.setAttributeNS(null, 'cy', '5');
114
-
115
- const indicatorLine = document.createElementNS(
116
- 'http://www.w3.org/2000/svg',
117
- 'line',
118
- );
119
- indicatorLine.setAttributeNS(null, 'x1', '10');
120
- indicatorLine.setAttributeNS(null, 'x2', '5');
121
- indicatorLine.setAttributeNS(null, 'y1', '5');
122
- indicatorLine.setAttributeNS(null, 'y2', '5');
123
- indicatorLine.setAttributeNS(null, 'stroke', 'black');
124
- indicatorLine.setAttributeNS(
125
- null,
126
- 'transform',
127
- `rotate(${360 - this.angle},5,5)`,
128
- );
129
-
130
- svg.setAttributeNS(null, 'viewBox', '0 0 10 10');
131
- svg.setAttributeNS(null, 'width', '20');
132
- svg.setAttributeNS(null, 'height', '20');
133
-
134
- svg.appendChild(colorCircle);
135
- svg.appendChild(indicatorLine);
136
-
137
- parent.appendChild(svg);
138
- return parent;
139
- }
140
- ignoreEvent() {
141
- return false;
142
- }
143
- }
@@ -1,48 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { urlClickerRegex } from './urlClicker';
3
-
4
- describe('URL regex', () => {
5
- test.each([
6
- {
7
- name: 'standard URL',
8
- input:
9
- 'Visit https://example.com for more information.',
10
- expected: ['https://example.com'],
11
- },
12
- {
13
- name: 'URL with single quote at the end',
14
- input: "Click here: https://example.com';",
15
- expected: ['https://example.com'],
16
- },
17
- {
18
- name: 'multiple URLs',
19
- input:
20
- 'Check out https://site1.com and https://site2.com.',
21
- expected: ['https://site1.com', 'https://site2.com'],
22
- },
23
- {
24
- name: 'URL with query parameters',
25
- input:
26
- 'Visit https://example.com?param1=value1&param2=value2.',
27
- expected: [
28
- 'https://example.com?param1=value1&param2=value2',
29
- ],
30
- },
31
- {
32
- name: 'URL with parentheses',
33
- input:
34
- 'See the map at https://example.com/maps?location=(123,456).',
35
- expected: [
36
- 'https://example.com/maps?location=(123,456)',
37
- ],
38
- },
39
- {
40
- name: 'no URL present',
41
- input: 'This text does not contain a URL.',
42
- expected: [],
43
- },
44
- ])('$name', ({ input, expected }) => {
45
- const matches = input.match(urlClickerRegex) || [];
46
- expect(matches).toEqual(expected);
47
- });
48
- });
@@ -1,12 +0,0 @@
1
- import { InteractRule } from '@replit/codemirror-interact';
2
-
3
- export const urlClickerRegex =
4
- /https?:\/\/[^\s'")]*([^\s'",;.]|\([^\s'")]*\)|\b)/g;
5
-
6
- export const urlClicker: InteractRule = {
7
- regexp: urlClickerRegex,
8
- cursor: 'pointer',
9
- onClick: (text: string) => {
10
- window.open(text);
11
- },
12
- };
@@ -1,25 +0,0 @@
1
- // vec2 slider
2
- // Inspired by: https://github.com/replit/codemirror-interact/blob/master/dev/index.ts#L61
3
-
4
- import { InteractRule } from '@replit/codemirror-interact';
5
-
6
- export const vec2Slider = (
7
- onInteract?: () => void,
8
- ): InteractRule => ({
9
- regexp:
10
- /vec2\(-?\b\d+\.?\d*\b\s*(,\s*-?\b\d+\.?\d*\b)?\)/g,
11
- cursor: 'move',
12
-
13
- onDrag: (text, setText, e) => {
14
- const res =
15
- /vec2\((?<x>-?\b\d+\.?\d*\b)\s*(,\s*(?<y>-?\b\d+\.?\d*\b))?\)/.exec(
16
- text,
17
- );
18
- const x = Number(res?.groups?.x);
19
- let y = Number(res?.groups?.y);
20
- if (isNaN(x)) return;
21
- if (isNaN(y)) y = x;
22
- setText(`vec2(${x + e.movementX}, ${y - e.movementY})`);
23
- if (onInteract) onInteract();
24
- },
25
- });
@@ -1,73 +0,0 @@
1
- // Customized "basic setup" for CodeMirror.
2
- // Mainly customized to remove keymaps, for compatibility with
3
- // codemirror-vscode-keymap.
4
- //
5
- // Inspired by
6
- // https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts
7
- // https://github.com/replit/codemirror-vscode-keymap/blob/master/dev/basicSetupNoKeymap.ts
8
- import {
9
- highlightSpecialChars,
10
- drawSelection,
11
- highlightActiveLine,
12
- dropCursor,
13
- rectangularSelection,
14
- crosshairCursor,
15
- lineNumbers,
16
- highlightActiveLineGutter,
17
- } from '@codemirror/view';
18
- import { Extension, EditorState } from '@codemirror/state';
19
- import {
20
- defaultHighlightStyle,
21
- syntaxHighlighting,
22
- indentOnInput,
23
- bracketMatching,
24
- } from '@codemirror/language';
25
- import { history } from '@codemirror/commands';
26
- import { highlightSelectionMatches } from '@codemirror/search';
27
- import {
28
- autocompletion,
29
- closeBrackets,
30
- } from '@codemirror/autocomplete';
31
-
32
- export const basicSetup: Extension = (() => [
33
- lineNumbers(),
34
- highlightActiveLineGutter(),
35
- highlightSpecialChars(),
36
- history(),
37
-
38
- // Not really a fan of foldGutter.
39
- // Unclear if it's really useful.
40
- // If we ever want to use it, we should
41
- // make sure the styling is decent.
42
- // foldGutter(),
43
- drawSelection(),
44
- dropCursor(),
45
- EditorState.allowMultipleSelections.of(true),
46
- indentOnInput(),
47
- syntaxHighlighting(defaultHighlightStyle, {
48
- fallback: true,
49
- }),
50
- bracketMatching(),
51
- closeBrackets(),
52
- // We set this to `false` because that is prescribed by
53
- // https://github.com/replit/codemirror-vscode-keymap
54
- autocompletion({ defaultKeymap: false }),
55
-
56
- rectangularSelection(),
57
- crosshairCursor(),
58
- highlightActiveLine(),
59
- highlightSelectionMatches(),
60
-
61
- // All of these keymaps are disabled because we use
62
- // codemirror-vscode-keymap, which provides its own
63
- // keymaps for all of these things.
64
- // keymap.of([
65
- // ...closeBracketsKeymap,
66
- // ...defaultKeymap,
67
- // ...searchKeymap,
68
- // ...historyKeymap,
69
- // // ...foldKeymap,
70
- // ...completionKeymap,
71
- // ...lintKeymap,
72
- // ]),
73
- ])();