Refactoring: remove AsMarkdown() from the old BaseUIElement

This commit is contained in:
Pieter Vander Vennet 2025-07-12 13:19:03 +02:00
parent 54265ba0c6
commit fb48c57e42
5 changed files with 2 additions and 49 deletions

View file

@ -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() { Destroy() {
super.Destroy() super.Destroy()
for (const uiElement of this.uiElements) { for (const uiElement of this.uiElements) {

View file

@ -23,25 +23,6 @@ export default class Table extends BaseUIElement {
this._contents = contents.map((row) => row.map(Translations.W)) 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 { protected InnerConstructElement(): HTMLElement {
const table = document.createElement("table") const table = document.createElement("table")

View file

@ -19,17 +19,6 @@ export class VariableUiElement extends BaseUIElement {
this.isDestroyed = true 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 { protected InnerConstructElement(): HTMLElement {
const el = document.createElement("span") const el = document.createElement("span")
const self = this const self = this

View file

@ -158,10 +158,6 @@ export default abstract class BaseUIElement {
} }
} }
public AsMarkdown(): string {
throw "AsMarkdown is not implemented; implement it in the subclass"
}
public Destroy() { public Destroy() {
this.isDestroyed = true this.isDestroyed = true
} }

View file

@ -1,4 +1,3 @@
import BaseUIElement from "../BaseUIElement"
import { Translation } from "../i18n/Translation" import { Translation } from "../i18n/Translation"
import Translations from "../i18n/Translations" import Translations from "../i18n/Translations"
@ -32,7 +31,7 @@ export abstract class Validator {
constructor( constructor(
name: string, name: string,
explanation: string | BaseUIElement, explanation: string,
inputmode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search", inputmode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search",
textArea?: false | boolean textArea?: false | boolean
) { ) {
@ -45,11 +44,7 @@ export abstract class Validator {
if (this.name.endsWith("textfielddef")) { if (this.name.endsWith("textfielddef")) {
this.name = this.name.substring(0, this.name.length - "TextFieldDef".length) this.name = this.name.substring(0, this.name.length - "TextFieldDef".length)
} }
if (typeof explanation === "string") {
this.explanation = explanation this.explanation = explanation
} else {
this.explanation = explanation.AsMarkdown()
}
} }
/** /**