forked from MapComplete/MapComplete
Fix deployment, fix documentation generation, add a small markdown generator
This commit is contained in:
parent
e480c97676
commit
8e72b70742
27 changed files with 478 additions and 399 deletions
|
@ -32,4 +32,8 @@ export default class Combine extends BaseUIElement {
|
|||
return el;
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
return this.uiElements.map(el => el.AsMarkdown()).join(this.HasClass("flex-col") ? "\n\n" : " ");
|
||||
}
|
||||
|
||||
}
|
|
@ -17,5 +17,9 @@ export class FixedUiElement extends BaseUIElement {
|
|||
e.innerHTML = this._html
|
||||
return e;
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
return this._html;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,5 +30,14 @@ export default class List extends BaseUIElement {
|
|||
|
||||
return el;
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
if(this._ordered){
|
||||
return "\n\n"+this.uiElements.map((el, i) => " "+i+". "+el.AsMarkdown().replace(/\n/g, ' \n') ).join("\n") + "\n"
|
||||
}else{
|
||||
return "\n\n"+this.uiElements.map(el => " - "+el.AsMarkdown().replace(/\n/g, ' \n') ).join("\n")+"\n"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
37
UI/Base/Title.ts
Normal file
37
UI/Base/Title.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import {UIElement} from "../UIElement";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import Translations from "../i18n/Translations";
|
||||
|
||||
export default class Title extends BaseUIElement{
|
||||
private readonly _embedded: BaseUIElement;
|
||||
private readonly _level: number;
|
||||
constructor(embedded: string | BaseUIElement, level: number =3 ) {
|
||||
super()
|
||||
this._embedded = Translations.W(embedded);
|
||||
this._level = level;
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const el = this._embedded.ConstructElement()
|
||||
if(el === undefined){
|
||||
return undefined;
|
||||
}
|
||||
const h = document.createElement("h"+this._level)
|
||||
h.appendChild(el)
|
||||
return h;
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
const embedded = " " +this._embedded.AsMarkdown()+" ";
|
||||
|
||||
if(this._level == 1){
|
||||
return "\n"+embedded+"\n"+"=".repeat(embedded.length)+"\n\n"
|
||||
}
|
||||
|
||||
if(this._level == 2){
|
||||
return "\n"+embedded+"\n"+"-".repeat(embedded.length)+"\n\n"
|
||||
}
|
||||
|
||||
return "\n"+"#".repeat( this._level)+embedded +"\n\n";
|
||||
}
|
||||
}
|
|
@ -26,17 +26,7 @@ export default abstract class BaseUIElement {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public IsHovered(): UIEventSource<boolean> {
|
||||
if (this._onHover !== undefined) {
|
||||
return this._onHover;
|
||||
}
|
||||
// Note: we just save it. 'Update' will register that an eventsource exist and install the necessary hooks
|
||||
this._onHover = new UIEventSource<boolean>(false);
|
||||
return this._onHover;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AttachTo(divId: string) {
|
||||
let element = document.getElementById(divId);
|
||||
if (element === null) {
|
||||
|
@ -84,6 +74,10 @@ export default abstract class BaseUIElement {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public HasClass(clss: string): boolean{
|
||||
return this.clss.has(clss)
|
||||
}
|
||||
|
||||
public SetStyle(style: string): BaseUIElement {
|
||||
this.style = style;
|
||||
|
@ -156,4 +150,8 @@ export default abstract class BaseUIElement {
|
|||
|
||||
return el
|
||||
}
|
||||
|
||||
public AsMarkdown(): string{
|
||||
throw "AsMarkdown is not implemented by "+this.constructor.name
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ export default class PersonalLayersPanel extends UIElement {
|
|||
const self = this;
|
||||
State.state.installedThemes.addCallback(extraThemes => {
|
||||
self.UpdateView(extraThemes.map(layout => layout.layout));
|
||||
self.Update();
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,6 @@ export default class SpecialVisualizations {
|
|||
"In a tagrendering, some special values are substituted by an advanced UI-element. This allows advanced features and visualizations to be reused by custom themes or even to query third-party API's.",
|
||||
"General usage is <b>{func_name()}</b> or <b>{func_name(arg, someotherarg)}</b>. Note that you <i>do not</i> need to use quotes around your arguments, the comma is enough to seperate them. This also implies you cannot use a comma in your args",
|
||||
...helpTexts
|
||||
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -33,27 +33,6 @@ export abstract class UIElement extends BaseUIElement{
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Update(): void {
|
||||
|
||||
}
|
||||
|
||||
Render(): string {
|
||||
return this.InnerRenderAsString()
|
||||
}
|
||||
|
||||
|
||||
public InnerRenderAsString(): string {
|
||||
let rendered = this.InnerRender();
|
||||
if (typeof rendered !== "string") {
|
||||
let html = rendered.ConstructElement()
|
||||
return html.innerHTML
|
||||
}
|
||||
return rendered
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should be overridden for specific HTML functionality
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue