From 0712c416259e4860ff1910c4a5bcd7b37da6b237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 31 Oct 2021 21:18:37 +0100 Subject: lib. --- static/clock.ts | 2 ++ static/globals.ts | 1 + static/jcal.ts | 1 + static/lib.ts | 48 ++++++++++++++++++++++++++++-------------------- static/script.ts | 1 + static/tsconfig.json | 2 +- static/vevent.ts | 1 + 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/static/clock.ts b/static/clock.ts index 27c3e4e1..9171b8a8 100644 --- a/static/clock.ts +++ b/static/clock.ts @@ -1,5 +1,7 @@ export { SmallcalCellHighlight, Timebar } +import { makeElement, date_to_percent } from './lib' + class Clock { update(now: Date) { } diff --git a/static/globals.ts b/static/globals.ts index 0ca2e3de..9045d4a9 100644 --- a/static/globals.ts +++ b/static/globals.ts @@ -19,6 +19,7 @@ export { import { close_popup, toggle_popup } from './popup' import { VEvent, xml_to_vcal } from './vevent' import { bind_popup_control } from './dragable' +import { uid, parseDate, gensym, to_local, boolean, makeElement } from './lib' "use strict"; diff --git a/static/jcal.ts b/static/jcal.ts index 51a1130b..327a560d 100644 --- a/static/jcal.ts +++ b/static/jcal.ts @@ -1,5 +1,6 @@ export { jcal_to_xcal } import { ical_type, JCalProperty, JCal } from './types' +import { xcal, asList } from './lib' function jcal_type_to_xcal(doc: Document, type: ical_type, value: any): Element { let el = doc.createElementNS(xcal, type); diff --git a/static/lib.ts b/static/lib.ts index e3d99007..fe5ef1bd 100644 --- a/static/lib.ts +++ b/static/lib.ts @@ -1,34 +1,42 @@ +export { + makeElement, date_to_percent, uid, + parseDate, gensym, to_local, boolean, + xcal, asList, round_time +} 'use strict'; /* General procedures which in theory could be used anywhere. */ -interface Object { - format: (fmt: string) => string -} +declare global { + interface Object { + format: (fmt: string) => string + } -interface HTMLElement { - _addEventListener: (name: string, proc: (e: Event) => void) => void - listeners: Record void)[]> -} + interface HTMLElement { + _addEventListener: (name: string, proc: (e: Event) => void) => void + listeners: Record void)[]> + } -interface Date { - dateonly: boolean - utc: boolean - type: 'date' | 'date-time' -} + interface Date { + format: (fmt: string) => string + dateonly: boolean + utc: boolean + type: 'date' | 'date-time' + } -interface DOMTokenList { - find: (regex: string) => [number, string] | undefined -} + interface DOMTokenList { + find: (regex: string) => [number, string] | undefined + } -interface HTMLCollection { - forEach: (proc: ((el: Element) => void)) => void -} + interface HTMLCollection { + forEach: (proc: ((el: Element) => void)) => void + } -interface HTMLCollectionOf { - forEach: (proc: ((el: T) => void)) => void + interface HTMLCollectionOf { + forEach: (proc: ((el: T) => void)) => void + } } type uid = string diff --git a/static/script.ts b/static/script.ts index 7d98a28a..7762173e 100644 --- a/static/script.ts +++ b/static/script.ts @@ -3,6 +3,7 @@ import { close_all_popups } from './popup' import { VEvent } from './vevent' import { SmallcalCellHighlight, Timebar } from './clock' +import { makeElement, parseDate, gensym, round_time } from './lib' /* calp specific stuff diff --git a/static/tsconfig.json b/static/tsconfig.json index 090e2b59..82359e01 100644 --- a/static/tsconfig.json +++ b/static/tsconfig.json @@ -8,7 +8,7 @@ "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ /* Modules */ - "module": "none", /* Specify what module code is generated. */ + "module": "CommonJS", /* Specify what module code is generated. */ /* JavaScript Support */ "allowJs": false, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ diff --git a/static/vevent.ts b/static/vevent.ts index f25c5341..0fef9685 100644 --- a/static/vevent.ts +++ b/static/vevent.ts @@ -1,4 +1,5 @@ import { ical_type, valid_input_types, JCal } from './types' +import { uid, parseDate } from './lib' export { VEvent, xml_to_vcal } "use strict"; -- cgit v1.2.3