- Delete old Vite+Svelte frontend - Initialize new SvelteKit project with TypeScript - Configure Tailwind CSS v4 + DaisyUI - Implement JWT authentication with auto-refresh - Create login page with form validation (Zod) - Add protected route guards - Update Docker configuration for single-stage build - Add E2E tests with Playwright (6/11 passing) - Fix Svelte 5 reactivity with $state() runes Known issues: - 5 E2E tests failing (timing/async issues) - Token refresh implementation needs debugging - Validation error display timing
65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
import BrowserErrorCaptureEnum from '../../browser/enums/BrowserErrorCaptureEnum.js';
|
|
import WindowBrowserContext from '../../window/WindowBrowserContext.js';
|
|
import * as PropertySymbol from '../../PropertySymbol.js';
|
|
/**
|
|
* ECMAScript module compiler.
|
|
*/
|
|
export default class ElementEventAttributeUtility {
|
|
/**
|
|
* Evaluates code in attribute and returns event listener.
|
|
*
|
|
* @param element
|
|
* @param property Property.
|
|
* @returns Result.
|
|
*/
|
|
static getEventListener(element, property) {
|
|
const cached = element[PropertySymbol.propertyEventListeners].get(property);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
const window = element[PropertySymbol.ownerDocument][PropertySymbol.defaultView];
|
|
const browserSettings = new WindowBrowserContext(window).getSettings();
|
|
if (!browserSettings) {
|
|
return null;
|
|
}
|
|
const code = element.getAttribute(property);
|
|
if (!code) {
|
|
return null;
|
|
}
|
|
let newCode = `(function anonymous($happy_dom, event) {\n//# sourceURL=${window.location.href}\n`;
|
|
if (browserSettings &&
|
|
!browserSettings.disableErrorCapturing &&
|
|
browserSettings.errorCapture === BrowserErrorCaptureEnum.tryAndCatch) {
|
|
newCode += 'try {\n';
|
|
}
|
|
newCode += code;
|
|
if (browserSettings &&
|
|
!browserSettings.disableErrorCapturing &&
|
|
browserSettings.errorCapture === BrowserErrorCaptureEnum.tryAndCatch) {
|
|
newCode += '\n} catch(e) { $happy_dom.dispatchError(e); }\n';
|
|
}
|
|
newCode += '})';
|
|
let listener = null;
|
|
try {
|
|
listener = window.eval(newCode).bind(element, {
|
|
dispatchError: window[PropertySymbol.dispatchError]
|
|
});
|
|
}
|
|
catch (e) {
|
|
const error = new window.SyntaxError(`Failed to read the '${property}' property from '${element.constructor.name}': ${e.message}`);
|
|
if (browserSettings.disableErrorCapturing ||
|
|
browserSettings.errorCapture !== BrowserErrorCaptureEnum.tryAndCatch) {
|
|
throw error;
|
|
}
|
|
else {
|
|
window[PropertySymbol.dispatchError](error);
|
|
return null;
|
|
}
|
|
}
|
|
if (listener) {
|
|
element[PropertySymbol.propertyEventListeners].set(property, listener);
|
|
}
|
|
return listener;
|
|
}
|
|
}
|
|
//# sourceMappingURL=ElementEventAttributeUtility.js.map
|