Fix working of Gefes IDs

This commit is contained in:
FullGreaM 2026-04-27 02:56:03 +03:00
parent 8877f3e4af
commit bbbfc0f043
2 changed files with 6 additions and 3 deletions

View File

@ -62,6 +62,7 @@ export abstract class GefestElement {
*/
constructor (content : (GefestElement | string)[] | string = []) {
this.gefestId = GefestEngine.register(this);
this.attributes["data-gefest-id"] = this.gefestId;
this.content = content;
}
@ -93,7 +94,7 @@ export abstract class GefestElement {
* @param key The attribute key.
*/
checkReservedAttribute(key: string): void {
if (({ "style": true, "class": true })[key])
if (({ "style": true, "class": true, "data-gefest-id": true })[key])
throw new Error(`The attribute "${
key
}" is reserved. Use the setPersonalStyle method for styles and setClass method for classes.`);

View File

@ -7,8 +7,10 @@ export class GefestEngine {
static register (element: GefestElement) : string {
elements.add(element);
// Generate GefestID for the element
const gefestId = `gefest-${Math.random().toString(36).substr(2, 9)}`;
element.setAttribute('data-gefest-id', gefestId);
let gefestId : string;
do {
gefestId = `gefest-${Math.random().toString(36).substr(2, 9)}`;
} while(!!elementsMapping.get(gefestId));
elementsMapping.set(gefestId, element);
return gefestId;