vzcode 1.4.0 → 1.6.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 (32) hide show
  1. package/dist/assets/index-B2OgpmfL.js +157 -0
  2. package/dist/assets/index-BwUWRAvf.js +425 -0
  3. package/dist/assets/{index-ClPo_hzs.css → index-DAYbg783.css} +1 -1
  4. package/dist/assets/{worker-DqNV0IYq.js → worker-Cs0ZU3m1.js} +193 -193
  5. package/dist/index.html +2 -2
  6. package/package.json +24 -20
  7. package/src/client/CodeEditor/json1PresenceDisplay.ts +14 -3
  8. package/src/client/Icons/CssSVG.tsx +16 -0
  9. package/src/client/Icons/FolderSVG.tsx +20 -0
  10. package/src/client/Icons/HtmlSVG.tsx +16 -0
  11. package/src/client/Icons/JavaScriptSVG.tsx +16 -0
  12. package/src/client/Icons/JsonSVG.tsx +16 -0
  13. package/src/client/Icons/MarkdownSVG.tsx +16 -0
  14. package/src/client/Icons/PinSVG.tsx +14 -0
  15. package/src/client/Icons/ReactSVG.tsx +16 -0
  16. package/src/client/Icons/SearchFileSVG.tsx +19 -0
  17. package/src/client/Icons/SearchSVG.tsx +20 -0
  18. package/src/client/Icons/SvelteSVG.tsx +16 -0
  19. package/src/client/Icons/TypeScriptSVG.tsx +16 -0
  20. package/src/client/Icons/index.tsx +11 -0
  21. package/src/client/VZCodeContext.tsx +28 -1
  22. package/src/client/VZSidebar/Search.tsx +242 -0
  23. package/src/client/VZSidebar/index.tsx +164 -111
  24. package/src/client/VZSidebar/styles.scss +101 -10
  25. package/src/client/useActions.ts +61 -1
  26. package/src/client/useFileCRUD.ts +1 -1
  27. package/src/client/vzReducer/createInitialState.ts +2 -0
  28. package/src/client/vzReducer/index.ts +48 -2
  29. package/src/client/vzReducer/searchReducer.ts +114 -0
  30. package/src/types.ts +20 -0
  31. package/dist/assets/index-Bx5B6Xgl.js +0 -400
  32. package/dist/assets/index-wJsFLYuD.js +0 -156
@@ -7,20 +7,25 @@
7
7
  justify-content: space-between;
8
8
 
9
9
  .full-box {
10
- padding: 4px;
10
+ width: 100%;
11
+ height: 100%;
11
12
  display: flex;
12
13
  flex-direction: row;
13
- align-items: center;
14
- justify-content: space-between;
14
+ justify-content: start;
15
+ align-items: start;
15
16
  border-bottom: 2px solid var(--vh-color-neutral-02);
17
+ overflow: hidden;
16
18
  }
17
19
 
18
20
  .files {
19
- overflow: auto;
20
21
  display: flex;
21
- flex-direction: column;
22
+ flex-direction: row;
23
+ justify-content: start;
24
+ align-items: start;
22
25
  flex: 1;
23
26
  outline: none;
27
+ overflow: auto;
28
+ height: 100%;
24
29
  }
25
30
 
26
31
  .file-or-directory {
@@ -30,8 +35,8 @@
30
35
  align-items: center;
31
36
  justify-content: space-between;
32
37
  cursor: pointer;
33
- margin: 0 10px;
34
- padding: 0 4px 0 8px;
38
+ margin: 0 8px;
39
+ padding: 0 4px 0 6px;
35
40
  border-radius: 4px;
36
41
  font-family: var(--vzcode-font-family);
37
42
  font-weight: 500;
@@ -46,14 +51,100 @@
46
51
  }
47
52
 
48
53
  .sidebar-section-buttons {
54
+ border-right: 2px solid var(--vh-color-neutral-02);
55
+ height: 100%;
49
56
  display: flex;
50
- flex-direction: row;
57
+ flex-direction: column;
51
58
  align-items: center;
52
- a {
59
+ gap: 6px;
60
+ padding: 6px;
61
+
62
+ * {
63
+ color: inherit;
64
+ }
65
+ }
66
+
67
+ .sidebar-files,
68
+ .sidebar-search {
69
+ width: 100%;
70
+ }
71
+
72
+ .sidebar-search {
73
+ padding: 10px;
74
+
75
+ * {
53
76
  color: inherit;
54
77
  }
55
78
  }
56
79
 
80
+ .search-result-lines {
81
+ margin-top: 10px;
82
+ margin-left: 20px;
83
+ }
84
+
85
+ .search-file-heading {
86
+ display: flex;
87
+ justify-content: space-between;
88
+ align-items: center;
89
+
90
+ * {
91
+ margin: 0px;
92
+ }
93
+ }
94
+
95
+ .search-file-title,
96
+ .search-file-name,
97
+ .search-file-info {
98
+ display: flex;
99
+ justify-content: center;
100
+ align-items: center;
101
+ gap: 10px;
102
+ }
103
+
104
+ .search-file-name {
105
+ font-size: inherit;
106
+ }
107
+
108
+ .search-file-count {
109
+ width: 18px;
110
+ height: 18px;
111
+ display: flex;
112
+ align-items: center;
113
+ justify-content: center;
114
+ margin: 0px;
115
+ font-size: 12px;
116
+ font-weight: bold;
117
+ text-align: center;
118
+ background: var(--vh-color-neutral-04);
119
+ color: var(--vh-color-neutral-01);
120
+ border-radius: 100%;
121
+ }
122
+
123
+ .search-results {
124
+ padding: 10px;
125
+ }
126
+
127
+ .search-file-lines {
128
+ font-size: inherit;
129
+ margin: 15px 0px 0px 30px;
130
+ }
131
+
132
+ .search-line,
133
+ .arrow-wrapper,
134
+ .search-file-close {
135
+ &:hover {
136
+ opacity: 0.7;
137
+ cursor: pointer;
138
+ }
139
+ }
140
+
141
+ .search-file-lines .search-pattern {
142
+ background: var(--vh-color-neutral-04);
143
+ color: var(--vh-color-neutral-01);
144
+ margin: 0.5px;
145
+ padding: 1px;
146
+ }
147
+
57
148
  .new-btn {
58
149
  justify-content: right;
59
150
  margin-right: 10px;
@@ -82,7 +173,7 @@
82
173
  align-items: center;
83
174
  white-space: nowrap;
84
175
  overflow: hidden;
85
- gap: 8px;
176
+ gap: 6px;
86
177
  .file-icon,
87
178
  .arrow-wrapper {
88
179
  opacity: 0.5;
@@ -1,6 +1,12 @@
1
1
  import { useCallback } from 'react';
2
2
  import { ThemeLabel } from './themes';
3
- import { FileId, Username } from '../types';
3
+ import {
4
+ FileId,
5
+ SearchFileVisibility,
6
+ ShareDBDoc,
7
+ Username,
8
+ VZCodeContent,
9
+ } from '../types';
4
10
  import { TabState, VZAction } from './vzReducer';
5
11
 
6
12
  // This is a custom hook that returns a set of functions
@@ -57,6 +63,56 @@ export const useActions = (
57
63
  [dispatch],
58
64
  );
59
65
 
66
+ // True to show the settings modal.
67
+ const setIsSearchOpen = useCallback(
68
+ (value: boolean) => {
69
+ dispatch({
70
+ type: 'set_is_search_open',
71
+ value: value,
72
+ });
73
+ },
74
+ [dispatch],
75
+ );
76
+
77
+ // Update search pattern
78
+ const setSearch = useCallback(
79
+ (pattern: string) => {
80
+ dispatch({
81
+ type: 'set_search',
82
+ value: pattern,
83
+ });
84
+ },
85
+ [dispatch],
86
+ );
87
+
88
+ // Update search results based on current pattern
89
+ const setSearchResults = useCallback(
90
+ (files: ShareDBDoc<VZCodeContent>) => {
91
+ dispatch({
92
+ type: 'set_search_results',
93
+ files: files,
94
+ });
95
+ },
96
+ [dispatch],
97
+ );
98
+
99
+ // Update search results file visibility based on current pattern
100
+ const setSearchFileVisibility = useCallback(
101
+ (
102
+ files: ShareDBDoc<VZCodeContent>,
103
+ id: string,
104
+ visibility: SearchFileVisibility,
105
+ ) => {
106
+ dispatch({
107
+ type: 'set_search_file_visibility',
108
+ files: files,
109
+ id: id,
110
+ visibility: visibility,
111
+ });
112
+ },
113
+ [dispatch],
114
+ );
115
+
60
116
  // True to show the settings modal.
61
117
  const setIsSettingsOpen = useCallback(
62
118
  (value: boolean) => {
@@ -109,6 +165,10 @@ export const useActions = (
109
165
  openTab,
110
166
  closeTabs,
111
167
  setTheme,
168
+ setIsSearchOpen,
169
+ setSearch,
170
+ setSearchResults,
171
+ setSearchFileVisibility,
112
172
  setIsSettingsOpen,
113
173
  setIsDocOpen,
114
174
  closeSettings,
@@ -1,4 +1,4 @@
1
- import { useCallback, useState } from 'react';
1
+ import { useCallback } from 'react';
2
2
  import {
3
3
  FileId,
4
4
  FileTreePath,
@@ -12,6 +12,8 @@ export const createInitialState = ({
12
12
  tabList: [],
13
13
  activeFileId: null,
14
14
  theme: defaultTheme,
15
+ search: { pattern: '', results: {} },
16
+ isSearchOpen: false,
15
17
  isSettingsOpen: false,
16
18
  isDocOpen: false,
17
19
  editorWantsFocus: false,
@@ -1,4 +1,11 @@
1
- import { FileId, Username } from '../../types';
1
+ import {
2
+ FileId,
3
+ SearchFileVisibility,
4
+ SearchResults,
5
+ ShareDBDoc,
6
+ Username,
7
+ VZCodeContent,
8
+ } from '../../types';
2
9
  import { ThemeLabel } from '../themes';
3
10
  import { closeTabsReducer } from './closeTabsReducer';
4
11
  import { openTabReducer } from './openTabReducer';
@@ -12,7 +19,12 @@ import { setIsDocOpenReducer } from './setIsDocOpenReducer';
12
19
  import { setThemeReducer } from './setThemeReducer';
13
20
  import { editorNoLongerWantsFocusReducer } from './editorNoLongerWantsFocusReducer';
14
21
  import { setUsernameReducer } from './setUsernameReducer';
15
-
22
+ import {
23
+ setIsSearchOpenReducer,
24
+ setSearchReducer,
25
+ setSearchResultsReducer,
26
+ setSearchFileVisibilityReducer,
27
+ } from './searchReducer';
16
28
  export { createInitialState } from './createInitialState';
17
29
 
18
30
  // The shape of the state managed by the reducer.
@@ -27,6 +39,12 @@ export type VZState = {
27
39
  // The theme that is currently active.
28
40
  theme: ThemeLabel;
29
41
 
42
+ // Search pattern and most recent results based on the current pattern
43
+ search: SearchResults;
44
+
45
+ // True to show the search instead of files
46
+ isSearchOpen: boolean;
47
+
30
48
  // True to show the settings modal.
31
49
  isSettingsOpen: boolean;
32
50
 
@@ -73,6 +91,30 @@ export type VZAction =
73
91
  | { type: 'set_is_settings_open'; value: boolean }
74
92
  | { type: 'set_is_doc_open'; value: boolean }
75
93
 
94
+ // `set_is_search_open`
95
+ // * Sets whether the search tab is open.
96
+ | { type: 'set_is_search_open'; value: boolean }
97
+
98
+ // `set_search`
99
+ // * Sets the current search pattern
100
+ | { type: 'set_search'; value: string }
101
+
102
+ // `set_search_results`
103
+ // * Sets the current search pattern
104
+ | {
105
+ type: 'set_search_results';
106
+ files: ShareDBDoc<VZCodeContent>;
107
+ }
108
+
109
+ // `set_search_results_visibility`
110
+ // * Sets the visibility of a current search pattern file
111
+ | {
112
+ type: 'set_search_file_visibility';
113
+ files: ShareDBDoc<VZCodeContent>;
114
+ id: string;
115
+ visibility: SearchFileVisibility;
116
+ }
117
+
76
118
  // `editor_no_longer_wants_focus`
77
119
  // * Sets `editorWantsFocus` to `false`.
78
120
  | { type: 'editor_no_longer_wants_focus' }
@@ -107,6 +149,10 @@ const reducers = [
107
149
  openTabReducer,
108
150
  closeTabsReducer,
109
151
  setThemeReducer,
152
+ setSearchReducer,
153
+ setSearchResultsReducer,
154
+ setSearchFileVisibilityReducer,
155
+ setIsSearchOpenReducer,
110
156
  setIsSettingsOpenReducer,
111
157
  setIsDocOpenReducer,
112
158
  editorNoLongerWantsFocusReducer,
@@ -0,0 +1,114 @@
1
+ import { VZAction, VZState } from '.';
2
+ import {
3
+ SearchFile,
4
+ SearchFileVisibility,
5
+ SearchResult,
6
+ ShareDBDoc,
7
+ VZCodeContent,
8
+ } from '../../types';
9
+
10
+ function searchPattern(
11
+ shareDBDoc: ShareDBDoc<VZCodeContent>,
12
+ pattern: string,
13
+ ): SearchResult {
14
+ const files = shareDBDoc.data.files;
15
+ const fileIds = Object.keys(shareDBDoc.data.files);
16
+ let results: { [id: string]: SearchFile } = {};
17
+
18
+ for (let i = 0; i < fileIds.length; i++) {
19
+ const file = files[fileIds[i]];
20
+
21
+ if (files[fileIds[i]].text) {
22
+ const fileName = file.name;
23
+ const lines = file.text.split('\n');
24
+ const matches = [];
25
+
26
+ for (let j = 0; j < lines.length; j++) {
27
+ const index = lines[j].indexOf(pattern);
28
+
29
+ if (index !== -1) {
30
+ matches.push({
31
+ line: j + 1,
32
+ index: index,
33
+ text: lines[j],
34
+ });
35
+ }
36
+ }
37
+
38
+ if (matches.length > 0) {
39
+ results[fileIds[i]] = {
40
+ name: fileName,
41
+ matches: matches,
42
+ visibility: 'open',
43
+ };
44
+ }
45
+ }
46
+ }
47
+
48
+ return results;
49
+ }
50
+
51
+ function updateSearchFileVisibility(
52
+ results: SearchResult,
53
+ id: string,
54
+ visibility: SearchFileVisibility,
55
+ ): SearchResult {
56
+ return {
57
+ ...results,
58
+ [id]: { ...results[id], visibility: visibility },
59
+ };
60
+ }
61
+
62
+ export const setIsSearchOpenReducer = (
63
+ state: VZState,
64
+ action: VZAction,
65
+ ): VZState =>
66
+ action.type === 'set_is_search_open'
67
+ ? { ...state, isSearchOpen: action.value }
68
+ : state;
69
+
70
+ export const setSearchReducer = (
71
+ state: VZState,
72
+ action: VZAction,
73
+ ): VZState =>
74
+ action.type === 'set_search'
75
+ ? {
76
+ ...state,
77
+ search: { pattern: action.value, results: {} },
78
+ }
79
+ : state;
80
+
81
+ export const setSearchResultsReducer = (
82
+ state: VZState,
83
+ action: VZAction,
84
+ ): VZState =>
85
+ action.type === 'set_search_results'
86
+ ? {
87
+ ...state,
88
+ search: {
89
+ pattern: state.search.pattern,
90
+ results: searchPattern(
91
+ action.files,
92
+ state.search.pattern,
93
+ ),
94
+ },
95
+ }
96
+ : state;
97
+
98
+ export const setSearchFileVisibilityReducer = (
99
+ state: VZState,
100
+ action: VZAction,
101
+ ): VZState =>
102
+ action.type === 'set_search_file_visibility'
103
+ ? {
104
+ ...state,
105
+ search: {
106
+ pattern: state.search.pattern,
107
+ results: updateSearchFileVisibility(
108
+ state.search.results,
109
+ action.id,
110
+ action.visibility,
111
+ ),
112
+ },
113
+ }
114
+ : state;
package/src/types.ts CHANGED
@@ -61,6 +61,26 @@ export interface FileTreeFile {
61
61
  file: File;
62
62
  fileId: FileId;
63
63
  }
64
+ export type SearchMatch = Array<{
65
+ line: number;
66
+ index: number;
67
+ text: string;
68
+ }>;
69
+ export type SearchFileVisibility =
70
+ | 'open'
71
+ | 'flattened'
72
+ | 'closed';
73
+ export type SearchResult = { [id: string]: SearchFile };
74
+
75
+ export interface SearchFile {
76
+ name: string;
77
+ matches: SearchMatch;
78
+ visibility: SearchFileVisibility;
79
+ }
80
+ export interface SearchResults {
81
+ pattern: string;
82
+ results: SearchResult;
83
+ }
64
84
 
65
85
  export type JSONOp = any;
66
86