forked from MapComplete/MapComplete
Refactoring: remove AsMarkdown() from the old BaseUIElement
This commit is contained in:
parent
54265ba0c6
commit
fb48c57e42
5 changed files with 2 additions and 49 deletions
|
@ -18,14 +18,6 @@ export default class Combine extends BaseUIElement {
|
|||
})
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
let sep = " "
|
||||
if (this.HasClass("flex-col")) {
|
||||
sep = "\n\n"
|
||||
}
|
||||
return this.uiElements.map((el) => el.AsMarkdown()).join(sep)
|
||||
}
|
||||
|
||||
Destroy() {
|
||||
super.Destroy()
|
||||
for (const uiElement of this.uiElements) {
|
||||
|
|
|
@ -23,25 +23,6 @@ export default class Table extends BaseUIElement {
|
|||
this._contents = contents.map((row) => row.map(Translations.W))
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
const headerMarkdownParts = this._header.map((hel) => hel?.AsMarkdown() ?? " ")
|
||||
const header = Utils.NoNull(headerMarkdownParts).join(" | ")
|
||||
const headerSep = headerMarkdownParts.map((part) => "-".repeat(part.length + 2)).join(" | ")
|
||||
const table = this._contents
|
||||
.map((row) =>
|
||||
row
|
||||
.map(
|
||||
(el) =>
|
||||
el?.AsMarkdown()?.replaceAll("\\", "\\\\")?.replaceAll("|", "\\|") ??
|
||||
" "
|
||||
)
|
||||
.join(" | ")
|
||||
)
|
||||
.join("\n")
|
||||
|
||||
return "\n\n" + [header, headerSep, table, ""].join("\n")
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const table = document.createElement("table")
|
||||
|
||||
|
|
|
@ -19,17 +19,6 @@ 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
|
||||
|
|
|
@ -158,10 +158,6 @@ export default abstract class BaseUIElement {
|
|||
}
|
||||
}
|
||||
|
||||
public AsMarkdown(): string {
|
||||
throw "AsMarkdown is not implemented; implement it in the subclass"
|
||||
}
|
||||
|
||||
public Destroy() {
|
||||
this.isDestroyed = true
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import BaseUIElement from "../BaseUIElement"
|
||||
import { Translation } from "../i18n/Translation"
|
||||
import Translations from "../i18n/Translations"
|
||||
|
||||
|
@ -32,7 +31,7 @@ export abstract class Validator {
|
|||
|
||||
constructor(
|
||||
name: string,
|
||||
explanation: string | BaseUIElement,
|
||||
explanation: string,
|
||||
inputmode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search",
|
||||
textArea?: false | boolean
|
||||
) {
|
||||
|
@ -45,11 +44,7 @@ export abstract class Validator {
|
|||
if (this.name.endsWith("textfielddef")) {
|
||||
this.name = this.name.substring(0, this.name.length - "TextFieldDef".length)
|
||||
}
|
||||
if (typeof explanation === "string") {
|
||||
this.explanation = explanation
|
||||
} else {
|
||||
this.explanation = explanation.AsMarkdown()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue