From c235bf73a8be78277000123a085bd6a8a4632e7b Mon Sep 17 00:00:00 2001 From: FullGreaM Date: Sun, 3 May 2026 02:36:32 +0300 Subject: [PATCH] Restructurized the structure --- frontend/src/modules/Gefest/element.ts | 76 +++++++++++++------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/frontend/src/modules/Gefest/element.ts b/frontend/src/modules/Gefest/element.ts index 9117b1b..d17360e 100644 --- a/frontend/src/modules/Gefest/element.ts +++ b/frontend/src/modules/Gefest/element.ts @@ -17,6 +17,44 @@ export abstract class GefestElement { protected clickHandler: (() => void) | null = null; + /** + * Creates a new instance of the element from an HTML string. + * @param html The HTML string to parse. + * @returns The created GefestElement. + */ + static fromHTML(html: string): GefestElement { + console.warn("Legacy and experiemental function!"); + + const htmlElement = new DOMParser().parseFromString(html, 'text/html').body.firstChild as HTMLElement; + const element = new (class extends GefestElement { + protected wrapHTML(content: string): string { + return content; + } + })(htmlElement.innerHTML); + + for (const attr of htmlElement.attributes) { + try { + element.setAttribute(attr.name, attr.value); + } catch (_) {} + } + + for (const className of htmlElement.classList) { + element.addClass(className); + } + + return element; + } + + /** + * Creates a new instance of the element. + * @param content The content for the element. Can be a string, an array of strings, an array of GefestElements or a combination of both. + */ + constructor (content : (GefestElement | string)[] | string = []) { + this.gefestId = GefestEngine.register(this); + this.attributes["data-gefest-id"] = this.gefestId; + this.content = content; + } + emit(event: GefestElementEvents, data: unknown = undefined) { for (let handler of this.eventHandlers) new Promise((rs) => rs(handler(event, data))); @@ -60,44 +98,6 @@ export abstract class GefestElement { }; } - /** - * Creates a new instance of the element from an HTML string. - * @param html The HTML string to parse. - * @returns The created GefestElement. - */ - static fromHTML(html: string): GefestElement { - console.warn("Legacy and experiemental function!"); - - const htmlElement = new DOMParser().parseFromString(html, 'text/html').body.firstChild as HTMLElement; - const element = new (class extends GefestElement { - protected wrapHTML(content: string): string { - return content; - } - })(htmlElement.innerHTML); - - for (const attr of htmlElement.attributes) { - try { - element.setAttribute(attr.name, attr.value); - } catch (_) {} - } - - for (const className of htmlElement.classList) { - element.addClass(className); - } - - return element; - } - - /** - * Creates a new instance of the element. - * @param content The content for the element. Can be a string, an array of strings, an array of GefestElements or a combination of both. - */ - constructor (content : (GefestElement | string)[] | string = []) { - this.gefestId = GefestEngine.register(this); - this.attributes["data-gefest-id"] = this.gefestId; - this.content = content; - } - /** * Call to GefestEngine for rerender element */