vzcode 0.0.5 → 0.1.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/README.md +2 -0
- package/cli.js +45 -8
- package/dist/assets/index-0b6fa7f4.css +1 -0
- package/dist/assets/index-96166106.js +73 -0
- package/dist/index.html +2 -2
- package/package.json +16 -13
- package/dist/assets/index-480eb572.css +0 -1
- package/dist/assets/index-6112ced9.js +0 -69
package/README.md
CHANGED
package/cli.js
CHANGED
|
@@ -18,7 +18,6 @@ const files = fs
|
|
|
18
18
|
.filter((dirent) => dirent.isFile())
|
|
19
19
|
.map((dirent) => dirent.name);
|
|
20
20
|
|
|
21
|
-
// Compute our initial document by reading the file system.
|
|
22
21
|
const initialDocument = {};
|
|
23
22
|
files.forEach((file) => {
|
|
24
23
|
const id = Math.floor(Math.random() * 10000000000);
|
|
@@ -28,18 +27,15 @@ files.forEach((file) => {
|
|
|
28
27
|
};
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
console.log('Welcome to VZCode!');
|
|
32
|
-
|
|
33
30
|
ShareDB.types.register(json1.type);
|
|
34
31
|
|
|
35
32
|
const app = express();
|
|
36
|
-
const port =
|
|
33
|
+
const port = 3030;
|
|
37
34
|
|
|
35
|
+
// Use ShareDB over WebSocket
|
|
38
36
|
const shareDBBackend = new ShareDB();
|
|
39
|
-
const shareDBConnection = shareDBBackend.connect();
|
|
40
37
|
const server = http.createServer(app);
|
|
41
38
|
const wss = new WebSocketServer({ server });
|
|
42
|
-
|
|
43
39
|
wss.on('connection', (ws) => {
|
|
44
40
|
shareDBBackend.listen(new WebSocketJSONStream(ws));
|
|
45
41
|
});
|
|
@@ -48,13 +44,54 @@ wss.on('connection', (ws) => {
|
|
|
48
44
|
const __filename = fileURLToPath(import.meta.url);
|
|
49
45
|
const __dirname = path.dirname(__filename);
|
|
50
46
|
const dir = path.join(__dirname, '/dist');
|
|
51
|
-
|
|
52
47
|
app.use(express.static(dir));
|
|
53
48
|
|
|
54
|
-
// Create initial document
|
|
49
|
+
// Create the initial "document",
|
|
50
|
+
// which is a representation of files on disk.
|
|
51
|
+
const shareDBConnection = shareDBBackend.connect();
|
|
55
52
|
const shareDBDoc = shareDBConnection.get('documents', '1');
|
|
56
53
|
shareDBDoc.create(initialDocument, json1.type.uri);
|
|
57
54
|
|
|
55
|
+
// The time in milliseconds by which auto-saving is debounced.
|
|
56
|
+
const autoSaveDebounceTimeMS = 800;
|
|
57
|
+
|
|
58
|
+
// The state of the document when files were last auto-saved.
|
|
59
|
+
let previousDocument = initialDocument;
|
|
60
|
+
|
|
61
|
+
// Saves the files that changed.
|
|
62
|
+
const save = () => {
|
|
63
|
+
const currentDocument = shareDBDoc.data;
|
|
64
|
+
|
|
65
|
+
// Take a look at each file that we have currently.
|
|
66
|
+
for (const key of Object.keys(currentDocument)) {
|
|
67
|
+
// Handle changing of text content.
|
|
68
|
+
if (previousDocument[key].text !== currentDocument[key].text) {
|
|
69
|
+
const { name, text } = currentDocument[key];
|
|
70
|
+
fs.writeFileSync(name, text);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Handle renaming files.
|
|
74
|
+
const oldPath = previousDocument[key].name;
|
|
75
|
+
const newPath = currentDocument[key].name;
|
|
76
|
+
if (oldPath !== newPath) {
|
|
77
|
+
fs.renameSync(oldPath, newPath);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// TODO handle creating files
|
|
81
|
+
// TODO handle deleting files
|
|
82
|
+
}
|
|
83
|
+
previousDocument = currentDocument;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Listen for when users modify files.
|
|
87
|
+
let timeout;
|
|
88
|
+
shareDBDoc.subscribe(() => {
|
|
89
|
+
shareDBDoc.on('op', (op) => {
|
|
90
|
+
clearTimeout(timeout);
|
|
91
|
+
timeout = setTimeout(save, autoSaveDebounceTimeMS);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
58
95
|
server.listen(port, () => {
|
|
59
96
|
console.log(`Editor is live at http://localhost:${port}`);
|
|
60
97
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import"https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap";@import"https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css";*{margin:0;padding:0;box-sizing:border-box}:root{--main-font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace}body{background:rgb(41,44,52);font-family:Poppins,sans-serif}.tab{width:max-content;height:30px;background:rgb(45,45,45);text-align:center;color:#fff;font-family:var(--main-font-family);justify-content:center;align-items:center;display:flex;padding-left:10px;padding-right:10px;border-top-left-radius:10px;border-top-right-radius:10px;margin-top:5px;margin-left:2px;margin-right:2px;cursor:pointer}.tab.active{background-color:#292c34}.tab-close{display:flex;cursor:pointer;margin-left:5px;justify-content:center;align-items:center}.tab-close:hover{border-radius:30%;background-color:#252526}.Editor{position:fixed;margin-left:200px;width:100%;height:100%;top:30px;bottom:0;background-color:#292c34;color:#fff;font-family:var(--main-font-family)}.tabList{position:fixed;display:flex;flex-direction:row;top:0;left:200px;height:35px;width:100%;background:rgb(37,37,38);z-index:100;transition:all .5s ease}.bottomBar{position:absolute;bottom:0;left:0;height:20px;width:100%;background:rgb(45,45,45);z-index:100;transition:all .5s ease}.sidebar{position:fixed;top:0;left:0;height:100%;width:200px;background:rgb(92,92,92);z-index:100;transition:all .5s ease}.sidebar.close{width:78px}.sidebar .nav-links{height:100%;padding:0 0 150px;overflow:auto}.sidebar.close .nav-links{overflow:visible}.sidebar .nav-links::-webkit-scrollbar{display:none}.sidebar .nav-links li{position:relative;list-style:none;transition:all .4s ease}.sidebar .nav-links li:hover{background:rgb(92,92,92)}.sidebar .nav-links li .icon-link{display:flex;align-items:center;justify-content:space-between}.sidebar.close .nav-links li .icon-link{display:block}.sidebar .nav-links li i{height:50px;min-width:78px;text-align:center;line-height:50px;color:#fff;font-size:20px;cursor:pointer;transition:all .3s ease}.sidebar .nav-links li.showMenu i.arrow{transform:rotate(-180deg)}.sidebar.close .nav-links i.arrow{display:none}.sidebar .nav-links li a{display:flex;align-items:center;text-decoration:none}.sidebar .nav-links li a .link_name{font-size:18px;font-weight:400;color:#fff;transition:all .4s ease}.sidebar.close .nav-links li a .link_name{opacity:0;pointer-events:none}.sidebar .nav-links li .sub-menu{padding:6px 6px 14px 80px;margin-top:-10px;background:rgb(92,92,92);display:none}.sidebar .nav-links li.showMenu .sub-menu{display:block}.sidebar .nav-links li .sub-menu a{color:#fff;font-size:15px;padding:5px 0;white-space:nowrap;opacity:.6;transition:all .3s ease;cursor:pointer;user-select:none}.sidebar .nav-links li .sub-menu a:hover{opacity:1}.sidebar.close .nav-links li .sub-menu{position:absolute;left:100%;top:-10px;margin-top:0;padding:10px 20px;border-radius:0 6px 6px 0;opacity:0;display:block;pointer-events:none;transition:0s}.sidebar.close .nav-links li:hover .sub-menu{top:0;opacity:1;pointer-events:auto;transition:all .4s ease}.sidebar .nav-links li .sub-menu .link_name{display:none}.sidebar.close .nav-links li .sub-menu .link_name{font-size:18px;opacity:1;display:block}.sidebar .nav-links li .sub-menu.blank{opacity:1;pointer-events:auto;padding:3px 20px 6px 16px;opacity:0;pointer-events:none}.sidebar .nav-links li:hover .sub-menu.blank{top:50%;transform:translateY(-50%)}.sidebar .profile-details{position:fixed;bottom:0;width:200px;display:flex;align-items:center;justify-content:space-between;background:rgb(92,92,92);padding:12px 0;transition:all .5s ease}.sidebar.close .profile-details{background:none}.sidebar.close .profile-details{width:78px}.sidebar .profile-details .profile-content{display:flex;align-items:center}.sidebar .profile-details img{height:52px;width:52px;object-fit:cover;border-radius:16px;margin:0 14px 0 12px;background:rgb(92,92,92);transition:all .5s ease}.sidebar.close .profile-details img{padding:10px}.sidebar .profile-details .profile_name,.sidebar .profile-details .job{color:#fff;font-size:18px;font-weight:500;white-space:nowrap}.sidebar .profile-details .job{font-size:12px}.sidebar.close~.home-section{left:78px;width:calc(100% - 78px)}
|