Skip to content

Commit c662be6

Browse files
committed
fix: migrate custom element from ES5 to ES6
- fix #4416
1 parent 48d1fdf commit c662be6

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

src/renderer.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,20 @@ async function onApiLoaded() {
420420
}
421421
}
422422

423-
/**
424-
* Original still using ES5, so we need to define custom elements using ES5 style
425-
*/
426423
const definePearTransElements = () => {
427-
const PearTrans = function () {};
428-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
429-
PearTrans.prototype = Object.create(HTMLElement.prototype);
430-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
431-
PearTrans.prototype.connectedCallback = function () {
432-
const that = this as HTMLElement;
433-
const key = that.getAttribute('key');
434-
if (key) {
435-
const targetHtml = i18t(key);
436-
(that.innerHTML as string | TrustedHTML) = defaultTrustedTypePolicy
437-
? defaultTrustedTypePolicy.createHTML(targetHtml)
438-
: targetHtml;
439-
}
440-
};
441424
customElements.define(
442425
'pear-trans',
443-
PearTrans as unknown as CustomElementConstructor,
426+
class extends HTMLElement {
427+
connectedCallback() {
428+
const key = this.getAttribute('key');
429+
if (key) {
430+
const targetHtml = i18t(key);
431+
(this.innerHTML as string | TrustedHTML) = defaultTrustedTypePolicy
432+
? defaultTrustedTypePolicy.createHTML(targetHtml)
433+
: targetHtml;
434+
}
435+
}
436+
},
444437
);
445438
};
446439

0 commit comments

Comments
 (0)