frontend: Use typescript over javascript

This commit is contained in:
Tom Wiesing 2022-10-06 17:23:39 +02:00
parent 491a356877
commit a070ced312
No known key found for this signature in database
10 changed files with 17 additions and 13 deletions

View file

@ -0,0 +1,3 @@
declare interface Window {
readonly pathbuilders: {[name: string]: string}
}

View file

@ -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)
})
})

View file

@ -1,2 +0,0 @@
import './base/base.js';
import './autolink/autolink.js';

View file

@ -0,0 +1,2 @@
import './base/base.ts';
import './autolink/autolink.ts';

View file

@ -1,2 +0,0 @@
import '../global.js';
import './index.css';

View file

@ -0,0 +1,2 @@
import '../global.ts';
import './index.css';