Skip to content

Build your personal knowledge base with Trilium Notes

fix(build): remove usage of global

Elian Doran56bb2b0bb811
diff --git a/src/autoformatmath.ts b/src/autoformatmath.ts
index 7962472340..3aa7697c43 100644
--- a/src/autoformatmath.ts
+++ b/src/autoformatmath.ts
@@ -35,7 +35,7 @@ export default class AutoformatMath extends Plugin {
command.display = true;
// Wait until selection is removed.
- global.window.setTimeout(
+ window.setTimeout(
() => {
const mathUIInstance = editor.plugins.get( 'MathUI' );
if ( mathUIInstance instanceof MathUI ) {
diff --git a/src/automath.ts b/src/automath.ts
index 1183ab1fa6..e8eb5e9c1e 100644
--- a/src/automath.ts
+++ b/src/automath.ts
@@ -57,7 +57,7 @@ export default class AutoMath extends Plugin {
editor.commands.get( 'undo' )?.on( 'execute', () => {
if ( this._timeoutId ) {
- global.window.clearTimeout( this._timeoutId );
+ window.clearTimeout( this._timeoutId );
this._positionToInsert?.detach();
this._timeoutId = null;
@@ -104,7 +104,7 @@ export default class AutoMath extends Plugin {
this._positionToInsert = LivePosition.fromPosition( leftPosition );
// With timeout user can undo conversation if want use plain text
- this._timeoutId = global.window.setTimeout( () => {
+ this._timeoutId = window.setTimeout( () => {
editor.model.change( writer => {
this._timeoutId = null;
diff --git a/src/mathui.ts b/src/mathui.ts
index 7a588ead31..7cc76f9907 100644
--- a/src/mathui.ts
+++ b/src/mathui.ts
@@ -44,7 +44,7 @@ export default class MathUI extends Plugin {
this.formView?.destroy();
// Destroy preview element
- const previewEl = global.document.getElementById( this._previewUid );
+ const previewEl = document.getElementById( this._previewUid );
if ( previewEl ) {
previewEl.parentNode?.removeChild( previewEl );
}
@@ -149,7 +149,7 @@ export default class MathUI extends Plugin {
}
// Show preview element
- const previewEl = global.document.getElementById( this._previewUid );
+ const previewEl = document.getElementById( this._previewUid );
if ( previewEl && this.formView.previewEnabled ) {
// Force refresh preview
this.formView.mathView?.updateMath();
@@ -194,7 +194,7 @@ export default class MathUI extends Plugin {
this._balloon.remove( this.formView );
// Hide preview element
- const previewEl = global.document.getElementById( this._previewUid );
+ const previewEl = document.getElementById( this._previewUid );
if ( previewEl ) {
previewEl.style.visibility = 'hidden';
}
diff --git a/src/utils.ts b/src/utils.ts
index baef7d5bfa..79be614e38 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -113,7 +113,7 @@ export async function renderEquation(
previewClassName,
el => {
// Fixme: MathJax typesetting cause occasionally math processing error without asynchronous call
- global.window.setTimeout( () => {
+ window.setTimeout( () => {
renderMathJax2( equation, el, display );
// Move and scale after rendering
@@ -154,9 +154,9 @@ export async function renderEquation(
} else {
if ( lazyLoad != null ) {
try {
- global.window.CKEDITOR_MATH_LAZY_LOAD ??= lazyLoad();
+ window.CKEDITOR_MATH_LAZY_LOAD ??= lazyLoad();
element.innerHTML = equation;
- await global.window.CKEDITOR_MATH_LAZY_LOAD;
+ await window.CKEDITOR_MATH_LAZY_LOAD;
await renderEquation(
equation,
element,
@@ -293,20 +293,20 @@ function getPreviewElement(
previewUid: string,
previewClassName: Array<string>
) {
- let previewEl = global.document.getElementById( previewUid );
+ let previewEl = document.getElementById( previewUid );
// Create if not found
if ( !previewEl ) {
- previewEl = global.document.createElement( 'div' );
+ previewEl = document.createElement( 'div' );
previewEl.setAttribute( 'id', previewUid );
previewEl.classList.add( ...previewClassName );
previewEl.style.visibility = 'hidden';
- global.document.body.appendChild( previewEl );
+ document.body.appendChild( previewEl );
let ticking = false;
const renderTransformation = () => {
if ( !ticking ) {
- global.window.requestAnimationFrame( () => {
+ window.requestAnimationFrame( () => {
if ( previewEl ) {
moveElement( element, previewEl );
ticking = false;
@@ -318,8 +318,8 @@ function getPreviewElement(
};
// Create scroll listener for following
- global.window.addEventListener( 'resize', renderTransformation );
- global.window.addEventListener( 'scroll', renderTransformation );
+ window.addEventListener( 'resize', renderTransformation );
+ window.addEventListener( 'scroll', renderTransformation );
}
return previewEl;
}
@@ -336,8 +336,8 @@ function moveAndScaleElement( parent: HTMLElement, child: HTMLElement ) {
function moveElement( parent: HTMLElement, child: HTMLElement ) {
const domRect = parent.getBoundingClientRect();
- const left = global.window.scrollX + domRect.left;
- const top = global.window.scrollY + domRect.top;
+ const left = window.scrollX + domRect.left;
+ const top = window.scrollY + domRect.top;
child.style.position = 'absolute';
child.style.left = left + 'px';
child.style.top = top + 'px';
diff --git a/tests/automath.ts b/tests/automath.ts
index 3e856bfaeb..ac93b1e550 100644
--- a/tests/automath.ts
+++ b/tests/automath.ts
@@ -14,8 +14,8 @@ describe( 'AutoMath - integration', () => {
let editorElement: HTMLDivElement, editor: ClassicEditor;
beforeEach( async () => {
- editorElement = global.document.createElement( 'div' );
- global.document.body.appendChild( editorElement );
+ editorElement = document.createElement( 'div' );
+ document.body.appendChild( editorElement );
return ClassicEditor
.create( editorElement, {
diff --git a/tests/math.ts b/tests/math.ts
index 3d3308f5e7..b539931a6b 100644
--- a/tests/math.ts
+++ b/tests/math.ts
@@ -11,8 +11,8 @@ describe( 'Math', () => {
let editorElement: HTMLDivElement, editor: ClassicEditor;
beforeEach( async () => {
- editorElement = global.document.createElement( 'div' );
- global.document.body.appendChild( editorElement );
+ editorElement = document.createElement( 'div' );
+ document.body.appendChild( editorElement );
return ClassicEditor
.create( editorElement, {