Full code cleanup

This commit is contained in:
Pieter Vander Vennet 2022-01-26 21:40:38 +01:00
parent 3a4a2a2016
commit fa971ffbbf
300 changed files with 16352 additions and 19284 deletions

View file

@ -31,6 +31,10 @@ export default class Combine extends BaseUIElement {
}
}
public getElements(): BaseUIElement[] {
return this.uiElements
}
protected InnerConstructElement(): HTMLElement {
const el = document.createElement("span")
try {
@ -57,9 +61,5 @@ export default class Combine extends BaseUIElement {
return el;
}
public getElements(): BaseUIElement[] {
return this.uiElements
}
}

View file

@ -29,6 +29,18 @@ export default class Img extends BaseUIElement {
return `<img class="${css_class}" style="${style}" alt="" src="${Img.AsData(source)}">`;
}
AsMarkdown(): string {
if (this._rawSvg === true) {
console.warn("Converting raw svgs to markdown is not supported");
return undefined
}
let src = this._src
if (this._src.startsWith("./")) {
src = "https://mapcomplete.osm.be/" + src
}
return "![](" + src + ")";
}
protected InnerConstructElement(): HTMLElement {
const self = this;
if (this._rawSvg) {
@ -53,17 +65,5 @@ export default class Img extends BaseUIElement {
}
return el;
}
AsMarkdown(): string {
if (this._rawSvg === true) {
console.warn("Converting raw svgs to markdown is not supported");
return undefined
}
let src = this._src
if (this._src.startsWith("./")) {
src = "https://mapcomplete.osm.be/" + src
}
return "![](" + src + ")";
}
}

View file

@ -2,15 +2,15 @@ import BaseUIElement from "../BaseUIElement";
import Combine from "./Combine";
import BackToIndex from "../BigComponents/BackToIndex";
export default class LeftIndex extends Combine{
constructor(leftContents: BaseUIElement[], mainContent: BaseUIElement, options?:{
hideBackButton : false | boolean
} ) {
let back : BaseUIElement = undefined;
if(options?.hideBackButton ?? true){
export default class LeftIndex extends Combine {
constructor(leftContents: BaseUIElement[], mainContent: BaseUIElement, options?: {
hideBackButton: false | boolean
}) {
let back: BaseUIElement = undefined;
if (options?.hideBackButton ?? true) {
back = new BackToIndex()
}
super([
@ -21,5 +21,5 @@ export default class LeftIndex extends Combine{
])
this.SetClass("h-full block md:flex")
}
}

View file

@ -19,6 +19,17 @@ export default class Link extends BaseUIElement {
}
public static OsmWiki(key: string, value?: string, hideKey = false) {
if (value !== undefined) {
let k = "";
if (!hideKey) {
k = key + "="
}
return new Link(k + value, `https://wiki.openstreetmap.org/wiki/Tag:${key}%3D${value}`)
}
return new Link(key, "https://wiki.openstreetmap.org/wiki/Key:" + key)
}
AsMarkdown(): string {
// @ts-ignore
return `[${this._embeddedShow.AsMarkdown()}](${this._href.data ?? this._href})`;
@ -44,15 +55,4 @@ export default class Link extends BaseUIElement {
return el;
}
public static OsmWiki(key: string, value?: string, hideKey = false) {
if (value !== undefined) {
let k = "";
if (!hideKey) {
k = key + "="
}
return new Link(k + value, `https://wiki.openstreetmap.org/wiki/Tag:${key}%3D${value}`)
}
return new Link(key, "https://wiki.openstreetmap.org/wiki/Key:" + key)
}
}

View file

@ -34,6 +34,9 @@ export default class Minimap {
* importing leaflet crashes node-ts, which is pretty annoying considering the fact that a lot of scripts use it
*/
private constructor() {
}
/**
* Construct a minimap
*/
@ -41,8 +44,5 @@ export default class Minimap {
throw "CreateMinimap hasn't been initialized yet. Please call MinimapImplementation.initialize()"
}
private constructor() {
}
}

View file

@ -16,15 +16,15 @@ import AvailableBaseLayersImplementation from "../../Logic/Actors/AvailableBaseL
export default class MinimapImplementation extends BaseUIElement implements MinimapObj {
private static _nextId = 0;
public readonly leafletMap: UIEventSource<Map>
public readonly location: UIEventSource<Loc>;
public readonly bounds: UIEventSource<BBox> | undefined;
private readonly _id: string;
private readonly _background: UIEventSource<BaseLayer>;
public readonly location: UIEventSource<Loc>;
private _isInited = false;
private _allowMoving: boolean;
private readonly _leafletoptions: any;
private readonly _onFullyLoaded: (leaflet: L.Map) => void
private readonly _attribution: BaseUIElement | boolean;
public readonly bounds: UIEventSource<BBox> | undefined;
private readonly _addLayerControl: boolean;
private readonly _options: MinimapOptions;

View file

@ -43,7 +43,7 @@ export default class ScrollableFullScreen extends UIElement {
const self = this;
Hash.hash.addCallback(h => {
if(h === undefined){
if (h === undefined) {
isShown.setData(false)
}
})
@ -55,18 +55,17 @@ export default class ScrollableFullScreen extends UIElement {
self.Activate();
} else {
// Some cleanup...
const fs = document.getElementById("fullscreen");
if(fs !== null){
if (fs !== null) {
ScrollableFullScreen.empty.AttachTo("fullscreen")
fs.classList.add("hidden")
}
ScrollableFullScreen._currentlyOpen?.isShown?.setData(false);
}
})
}

View file

@ -22,7 +22,7 @@ export default class TableOfContents extends Combine {
} else {
titles = elements ?? []
}
let els: { level: number, content: BaseUIElement }[] = []
for (const title of titles) {
let content: BaseUIElement
@ -33,9 +33,9 @@ export default class TableOfContents extends Combine {
content = new FixedUiElement(title.title.content)
} else if (Utils.runningFromConsole) {
content = new FixedUiElement(title.AsMarkdown())
} else if(title["title"] !== undefined) {
} else if (title["title"] !== undefined) {
content = new FixedUiElement(title.title.ConstructElement().innerText)
}else{
} else {
console.log("Not generating a title for ", title)
continue
}

View file

@ -3,12 +3,11 @@ import {FixedUiElement} from "./FixedUiElement";
import {Utils} from "../../Utils";
export default class Title extends BaseUIElement {
private static readonly defaultClassesPerLevel = ["", "text-3xl font-bold", "text-2xl font-bold", "text-xl font-bold", "text-lg font-bold"]
public readonly title: BaseUIElement;
public readonly level: number;
public readonly id: string
private static readonly defaultClassesPerLevel = ["", "text-3xl font-bold", "text-2xl font-bold", "text-xl font-bold", "text-lg font-bold"]
constructor(embedded: string | BaseUIElement, level: number = 3) {
super()
if (embedded === undefined) {

View file

@ -33,19 +33,19 @@ export default class Toggleable extends Combine {
title.SetClass("background-subtle rounded-lg")
const self = this
this.onClick(() => {
if(self.isVisible.data){
if(options?.closeOnClick ?? true){
if (self.isVisible.data) {
if (options?.closeOnClick ?? true) {
self.isVisible.setData(false)
}
}else{
} else {
self.isVisible.setData(true)
}
})
const contentElement = content.ConstructElement()
if(title instanceof Combine){
for(const el of title.getElements()){
if(el instanceof Title){
if (title instanceof Combine) {
for (const el of title.getElements()) {
if (el instanceof Title) {
title = el;
break;
}
@ -54,7 +54,7 @@ export default class Toggleable extends Combine {
if (title instanceof Title) {
Hash.hash.addCallbackAndRun(h => {
if (h === (<Title> title).id) {
if (h === (<Title>title).id) {
self.isVisible.setData(true)
content.RemoveClass("border-gray-300")
content.SetClass("border-red-300")
@ -82,9 +82,9 @@ export default class Toggleable extends Combine {
})
}
public Collapse() : Toggleable{
public Collapse(): Toggleable {
this.isVisible.setData(false)
return this;
}
}

View file

@ -15,6 +15,17 @@ export class VariableUiElement extends BaseUIElement {
this.isDestroyed = true;
}
AsMarkdown(): string {
const d = this._contents.data;
if (typeof d === "string") {
return d;
}
if (d instanceof BaseUIElement) {
return d.AsMarkdown()
}
return new Combine(<BaseUIElement[]>d).AsMarkdown()
}
protected InnerConstructElement(): HTMLElement {
const el = document.createElement("span");
const self = this;
@ -47,15 +58,4 @@ export class VariableUiElement extends BaseUIElement {
});
return el;
}
AsMarkdown(): string {
const d = this._contents.data;
if (typeof d === "string") {
return d;
}
if (d instanceof BaseUIElement) {
return d.AsMarkdown()
}
return new Combine(<BaseUIElement[]>d).AsMarkdown()
}
}