From 04558b8eabdad0a958f875117b8bbb90b5229cd1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 8 Jul 2024 01:11:16 +0200 Subject: [PATCH 1/4] Add types for js globals --- .eslintrc.yaml | 10 +++++++++- types.d.ts | 9 +++++++++ web_src/js/types.ts | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 web_src/js/types.ts diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 59eff85dc32d0..2d0213c3b2fdd 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -58,7 +58,15 @@ overrides: worker: true rules: no-restricted-globals: [2, addEventListener, blur, close, closed, confirm, defaultStatus, defaultstatus, error, event, external, find, focus, frameElement, frames, history, innerHeight, innerWidth, isFinite, isNaN, length, locationbar, menubar, moveBy, moveTo, name, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, print, removeEventListener, resizeBy, resizeTo, screen, screenLeft, screenTop, screenX, screenY, scroll, scrollbars, scrollBy, scrollTo, scrollX, scrollY, status, statusbar, stop, toolbar, top] - - files: ["*.config.*", "**/*.d.ts"] + - files: ["*.config.*"] + rules: + i/no-unused-modules: [0] + - files: ["**/*.d.ts"] + rules: + i/no-unused-modules: [0] + "@typescript-eslint/consistent-type-definitions": [0] + "@typescript-eslint/consistent-type-imports": [0] + - files: ["web_src/js/types.ts"] rules: i/no-unused-modules: [0] - files: ["**/*.test.*", "web_src/js/test/setup.ts"] diff --git a/types.d.ts b/types.d.ts index 9348424371fbf..550a4391bff6e 100644 --- a/types.d.ts +++ b/types.d.ts @@ -2,3 +2,12 @@ declare module '*.svg' { const value: string; export default value; } + +declare let __webpack_public_path__: string; + +interface Window { + config: import('./web_src/js/types.ts').Config; + $: typeof import('@types/jquery'), + jQuery: typeof import('@types/jquery'), + htmx: typeof import('htmx.org'), +} diff --git a/web_src/js/types.ts b/web_src/js/types.ts new file mode 100644 index 0000000000000..2cdd8cc1817d5 --- /dev/null +++ b/web_src/js/types.ts @@ -0,0 +1,23 @@ +type MentionValue = { + key: string, + value: string, + name: string, + fullname: string, + avatar: string, +} + +export type Config = { + appUrl: string, + appSubUrl: string, + assetVersionEncoded: string, + assetUrlPrefix: string, + runModeIsProd: boolean, + customEmojis: Record, + csrfToken: string, + pageData: Record, + notificationSettings: Record, + enableTimeTracking: boolean, + mentionValues: MentionValue[], + mermaidMaxSourceCharacters: number, + i18n: Record, +} From a578decebaef5f953619f874aec0774159419e8d Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 8 Jul 2024 01:41:01 +0200 Subject: [PATCH 2/4] add export --- web_src/js/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/types.ts b/web_src/js/types.ts index 2cdd8cc1817d5..469cd872f74e9 100644 --- a/web_src/js/types.ts +++ b/web_src/js/types.ts @@ -1,4 +1,4 @@ -type MentionValue = { +export type MentionValue = { key: string, value: string, name: string, From 2b5016bfac6f1251ad2860b8ec73156a1e3a34d0 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 8 Jul 2024 01:42:24 +0200 Subject: [PATCH 3/4] add optional --- web_src/js/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/types.ts b/web_src/js/types.ts index 469cd872f74e9..f69aa92768027 100644 --- a/web_src/js/types.ts +++ b/web_src/js/types.ts @@ -17,7 +17,7 @@ export type Config = { pageData: Record, notificationSettings: Record, enableTimeTracking: boolean, - mentionValues: MentionValue[], + mentionValues?: MentionValue[], mermaidMaxSourceCharacters: number, i18n: Record, } From 3f3f3b08bcd4f24cf4c6ce29fc3b696825f68859 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 10 Jul 2024 01:14:55 +0200 Subject: [PATCH 4/4] htmx fixes --- .eslintrc.yaml | 1 - types.d.ts | 5 +++++ web_src/js/htmx.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 2d0213c3b2fdd..47f4eaa2d2f40 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -47,7 +47,6 @@ overrides: - files: ["web_src/**/*"] globals: __webpack_public_path__: true - htmx: true process: false # https://github.com/webpack/webpack/issues/15833 - files: ["web_src/**/*", "docs/**/*"] env: diff --git a/types.d.ts b/types.d.ts index 550a4391bff6e..ddfe90407fc32 100644 --- a/types.d.ts +++ b/types.d.ts @@ -11,3 +11,8 @@ interface Window { jQuery: typeof import('@types/jquery'), htmx: typeof import('htmx.org'), } + +declare module 'htmx.org/dist/htmx.esm.js' { + const value = await import('htmx.org'); + export default value; +} diff --git a/web_src/js/htmx.ts b/web_src/js/htmx.ts index ac7e540fe4dbe..bfc2147736073 100644 --- a/web_src/js/htmx.ts +++ b/web_src/js/htmx.ts @@ -4,8 +4,8 @@ import {showErrorToast} from './modules/toast.ts'; import 'idiomorph/dist/idiomorph-ext.js'; // https://htmx.org/reference/#config -htmx.config.requestClass = 'is-loading'; -htmx.config.scrollIntoViewOnBoost = false; +window.htmx.config.requestClass = 'is-loading'; +window.htmx.config.scrollIntoViewOnBoost = false; // https://htmx.org/events/#htmx:sendError document.body.addEventListener('htmx:sendError', (event) => {