Core

/client/src/client.ts (2.1 KB)

 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
import "./client.css";{{{ if .HasModule "jsx" }}}
import {JSX} from "./jsx"; // eslint-disable-line @typescript-eslint/no-unused-vars{{{ end }}}
import {audit} from "./audit";
import {menuInit} from "./menu";
import {modeInit} from "./mode";
import {flashInit} from "./flash";
import {linkInit} from "./link";
import {timeInit} from "./time";
import {autocompleteInit} from "./autocomplete";
import {modalInit} from "./modal";
import {tagsInit} from "./tags";
import {editorInit} from "./editor";
import {formInit} from "./form";
import {themeInit} from "./theme";{{{ if .HasModule "websocket" }}}
import {socketInit} from "./socket";{{{ end }}}
import {appInit} from "./app";

declare global {
interface Window { // eslint-disable-line @typescript-eslint/consistent-type-definitions
"{{{ .CleanKey }}}": {
relativeTime: (time: string, el?: HTMLElement) => string;
autocomplete: (el: HTMLInputElement, url: string, field: string, title: (x: unknown) => string, val: (x: unknown) => string) => void;
setSiblingToNull: (el: HTMLElement) => void;
initForm: (frm: HTMLFormElement) => void;
flash: (key: string, level: "success" | "error", msg: string) => void;
tags: (el: HTMLElement) => void;{{{ if .HasModule "websocket" }}}
Socket: unknown;{{{ end }}}
};
audit: (s: string, ...args: any) => void; // eslint-disable-line @typescript-eslint/no-explicit-any{{{ if .HasModule "jsx" }}}
JSX: (tag: string, attrs: unknown[]) => HTMLElement;{{{ end }}}
}
}

export function init(): void {
const [s, i] = formInit();
window.{{{ .CleanKey }}} = {
relativeTime: timeInit(),
autocomplete: autocompleteInit(),
setSiblingToNull: s,
initForm: i,
flash: flashInit(),
tags: tagsInit(){{{ if .HasModule "websocket" }}},
Socket: socketInit(){{{ end }}}
};
menuInit();
modeInit();
linkInit();
modalInit();
themeInit();
editorInit();
window.audit = audit;{{{ if .HasModule "jsx" }}}
window.JSX = JSX;{{{ end }}}
appInit();
}

document.addEventListener("DOMContentLoaded", init);