-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (59 loc) · 1.51 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import "./style.css";
import Alpine from "alpinejs";
window.alpine = Alpine;
import { emitter } from "@lib/emitter";
import { generateMigrations } from "@lib/migrator";
import { detectIfValidSQL } from "@lib/util";
Alpine.store("errors", []);
/**
* @typedef {object} AlpineData
* @property {string} sql
* @property {string[]} migrations
* @property {string} selectedmigration
* @property {string[]} filtered
* @property {function} init
* @property {function} migrate
*/
Alpine.data("migrator", () => ({
sql: "",
migrations: [],
selectedmigration: "",
filtered: [],
search: "",
init() {
console.log("migrator");
},
/**
* Executes migration
* @param {string} text
* @returns {void}
*/
migrate: function (text = "") {
const sql = text || this.sql;
if(sql.length === 0) {
this.migrations = "";
return;
}
if(!detectIfValidSQL(sql)) {
console.log("Invalid SQL");
return;
};
try {
this.migrations = generateMigrations(sql);
} catch (error) {
console.error(error);
}
},
filter: function () {
const splitted = this.search.toLowerCase().split(",");
this.filtered = this.migrations.filter(migration => {
return splitted.some(search => {
return migration.name.toLowerCase().includes(search.trim());
});
});
},
copyToClipboard: function (text) {
navigator.clipboard.writeText(text);
}
}));
Alpine.start();