-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (71 loc) · 1.9 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
75
76
77
78
79
80
81
82
let snippet = {
name: "",
prefix: "",
desc: "",
body: "",
parse: (body) => {
body = body.replace(/^\s+|\s+$/g, "");
var indented = indent.js(body, { tabString: "\t" });
snippet.body = indented;
let lines = indented.split("\r\n");
x = lines
.map((e) => {
e = e.replace(/\t/g, "\\t");
return `\t"${e}",`;
})
.join("\n");
return `[
${x}
]`;
},
toString: () => {
return `"${snippet.name}": {
"prefix": "${snippet.prefix}",
"body": ${snippet.parse(snippet.body)},
"description": "${snippet.desc}"
}`;
},
};
function renderSnippet() {
document.getElementById("snippets").innerText = snippet.toString();
hljs.highlightAll();
const repoUrl = "https://github.com/Esri/arcgis-js-vscode-snippets";
const title = encodeURIComponent(`Snippet proposal: ${snippet.name}`);
const body = encodeURIComponent(`
Please specify which type of snippet it is: JavaScript snippet (*.js), TypeScript snippet (*.ts), HTML snippet (*.html), ...
---
**Prefix**: ${snippet.prefix}
**Description**: ${snippet.desc}
**Snippet**:
\`\`\`js
${snippet.body}
\`\`\`
Code:
\`\`\`js
${snippet.toString()}
\`\`\`
`);
document.querySelector(
"calcite-button"
).href = `${repoUrl}/issues/new?title=${title}&body=${body}`;
}
document.querySelectorAll("calcite-input").forEach((item) => {
item.addEventListener("keyup", (evt) => {
snippet[evt.target.closest("calcite-input").id] = evt.target.value.replace(
/\"/g,
'\\"'
);
renderSnippet();
});
});
document.querySelectorAll(".popover").forEach((item) => {
item.addEventListener("mouseenter", (evt) => {
el = document.querySelector(`[reference-element="${evt.target.id}"]`);
el.toggleAttribute("open");
});
item.addEventListener("mouseleave", (evt) => {
el = document.querySelector(`[reference-element="${evt.target.id}"]`);
el.toggleAttribute("open");
});
});
renderSnippet();