frontend: Use typescript over javascript
This commit is contained in:
parent
491a356877
commit
a070ced312
10 changed files with 17 additions and 13 deletions
3
internal/component/static/src/control/index.d.ts
vendored
Normal file
3
internal/component/static/src/control/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
declare interface Window {
|
||||
readonly pathbuilders: {[name: string]: string}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import '../global.js';
|
||||
import '../global.ts';
|
||||
import './index.css';
|
||||
|
||||
const types = {
|
||||
|
||||
const types: Record<string, (element: HTMLElement) => HTMLElement | string> = {
|
||||
"date": (element) => {
|
||||
return (new Date(element.innerText)).toISOString()
|
||||
},
|
||||
|
|
@ -9,7 +10,7 @@ const types = {
|
|||
const text = element.innerText.split("/");
|
||||
return text[text.length - 1];
|
||||
},
|
||||
"pathbuilders": (element) => {
|
||||
"pathbuilders": () => {
|
||||
const pathbuilders = window.pathbuilders; // read from context!
|
||||
const wrapper = document.createElement("span");
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ const types = {
|
|||
}
|
||||
}
|
||||
|
||||
const make_download_link = (filename, title, content, type) => {
|
||||
const make_download_link = (filename: string, title: string, content: string, type: string) => {
|
||||
const blob = new Blob(
|
||||
[content],
|
||||
{
|
||||
|
|
@ -53,7 +54,7 @@ const make_download_link = (filename, title, content, type) => {
|
|||
|
||||
Object.keys(types).forEach(key => {
|
||||
const f = types[key];
|
||||
const elements = document.querySelectorAll("code." + key)
|
||||
const elements = document.querySelectorAll("code." + key) as NodeListOf<HTMLElement>
|
||||
elements.forEach(element => {
|
||||
const newElement = f(element)
|
||||
if (typeof newElement === 'string') {
|
||||
|
|
@ -62,6 +63,6 @@ Object.keys(types).forEach(key => {
|
|||
return
|
||||
}
|
||||
|
||||
element.parentNode.replaceChild(newElement, element)
|
||||
element.parentNode!.replaceChild(newElement, element)
|
||||
})
|
||||
})
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
import './base/base.js';
|
||||
import './autolink/autolink.js';
|
||||
2
internal/component/static/src/global.ts
Normal file
2
internal/component/static/src/global.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import './base/base.ts';
|
||||
import './autolink/autolink.ts';
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
import '../global.js';
|
||||
import './index.css';
|
||||
2
internal/component/static/src/home/index.ts
Normal file
2
internal/component/static/src/home/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import '../global.ts';
|
||||
import './index.css';
|
||||
Loading…
Add table
Add a link
Reference in a new issue