From 1554085d7a0bedc59299574ae98f698039e08d5b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 23 Dec 2025 13:06:33 +0200 Subject: [PATCH] chore(scripts/preact): address review --- apps/client/src/services/bundle.ts | 1 - apps/client/src/services/frontend_script_api.ts | 2 -- apps/client/src/services/frontend_script_api_preact.ts | 4 ++-- apps/client/src/widgets/basic_widget.ts | 6 ++---- apps/client/src/widgets/react/FormCheckbox.tsx | 5 ++--- apps/client/src/widgets/sidebar/RightPanelContainer.tsx | 5 ++--- apps/server/src/becca/entities/bnote.ts | 5 ----- apps/server/src/services/script.ts | 7 +++---- 8 files changed, 11 insertions(+), 24 deletions(-) diff --git a/apps/client/src/services/bundle.ts b/apps/client/src/services/bundle.ts index 9dd11b684..a56139d36 100644 --- a/apps/client/src/services/bundle.ts +++ b/apps/client/src/services/bundle.ts @@ -1,6 +1,5 @@ import { h, VNode } from "preact"; -import Component from "../components/component.js"; import BasicWidget, { ReactWrappedWidget } from "../widgets/basic_widget.js"; import RightPanelWidget from "../widgets/right_panel_widget.js"; import froca from "./froca.js"; diff --git a/apps/client/src/services/frontend_script_api.ts b/apps/client/src/services/frontend_script_api.ts index 12d34832d..a76a09d55 100644 --- a/apps/client/src/services/frontend_script_api.ts +++ b/apps/client/src/services/frontend_script_api.ts @@ -538,7 +538,6 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig return `!@#Function: ${p.toString()}`; } return p; - }); } @@ -567,7 +566,6 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig return ret.executionResult; } throw new Error(`server error: ${ret.error}`); - }; this.runOnBackend = async (func, params = []) => { diff --git a/apps/client/src/services/frontend_script_api_preact.ts b/apps/client/src/services/frontend_script_api_preact.ts index e762f04d9..2829ca101 100644 --- a/apps/client/src/services/frontend_script_api_preact.ts +++ b/apps/client/src/services/frontend_script_api_preact.ts @@ -9,9 +9,9 @@ import Collapsible from "../widgets/react/Collapsible"; import Dropdown from "../widgets/react/Dropdown"; import FormCheckbox from "../widgets/react/FormCheckbox"; import FormDropdownList from "../widgets/react/FormDropdownList"; -import { FormFileUploadActionButton,FormFileUploadButton } from "../widgets/react/FormFileUpload"; +import { FormFileUploadActionButton, FormFileUploadButton } from "../widgets/react/FormFileUpload"; import FormGroup from "../widgets/react/FormGroup"; -import { FormDropdownDivider, FormDropdownSubmenu,FormListItem } from "../widgets/react/FormList"; +import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../widgets/react/FormList"; import FormRadioGroup from "../widgets/react/FormRadioGroup"; import FormText from "../widgets/react/FormText"; import FormTextArea from "../widgets/react/FormTextArea"; diff --git a/apps/client/src/widgets/basic_widget.ts b/apps/client/src/widgets/basic_widget.ts index 9b2c03d4e..eb6b55b0d 100644 --- a/apps/client/src/widgets/basic_widget.ts +++ b/apps/client/src/widgets/basic_widget.ts @@ -57,9 +57,8 @@ export class TypedBasicWidget> extends TypedCompon optChild(condition: boolean, ...components: (T | VNode)[]) { if (condition) { return this.child(...components); - } + } return this; - } id(id: string) { @@ -246,9 +245,8 @@ export class TypedBasicWidget> extends TypedCompon getClosestNtxId() { if (this.$widget) { return this.$widget.closest("[data-ntx-id]").attr("data-ntx-id"); - } + } return null; - } cleanup() {} diff --git a/apps/client/src/widgets/react/FormCheckbox.tsx b/apps/client/src/widgets/react/FormCheckbox.tsx index 70fea856f..839fa4b95 100644 --- a/apps/client/src/widgets/react/FormCheckbox.tsx +++ b/apps/client/src/widgets/react/FormCheckbox.tsx @@ -1,7 +1,6 @@ import { Tooltip } from "bootstrap"; -import { ComponentChildren } from "preact"; -import { CSSProperties, memo } from "preact/compat"; -import { useCallback,useEffect, useMemo, useRef } from "preact/hooks"; +import { ComponentChildren, CSSProperties } from "preact"; +import { useCallback, useEffect, useMemo, useRef } from "preact/hooks"; import { escapeQuotes } from "../../services/utils"; import { useUniqueName } from "./hooks"; diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx index a79280645..1ac039406 100644 --- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx +++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx @@ -2,7 +2,7 @@ import "./RightPanelContainer.css"; import Split from "@triliumnext/split.js"; -import { isValidElement, VNode } from "preact"; +import { VNode } from "preact"; import { useEffect, useRef } from "preact/hooks"; import appContext from "../../components/app_context"; @@ -10,7 +10,6 @@ import { WidgetsByParent } from "../../services/bundle"; import { t } from "../../services/i18n"; import options from "../../services/options"; import { DEFAULT_GUTTER_SIZE } from "../../services/resizer"; -import BasicWidget from "../basic_widget"; import Button from "../react/Button"; import { useActiveNoteContext, useLegacyWidget, useNoteProperty, useTriliumOptionBool, useTriliumOptionJson } from "../react/hooks"; import Icon from "../react/Icon"; @@ -67,7 +66,7 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent) { el: , enabled: noteType === "text" && highlightsList.length > 0, }, - ...widgetsByParent.getLegacyWidgets("right-pane").map((widget, i) => ({ + ...widgetsByParent.getLegacyWidgets("right-pane").map((widget) => ({ el: , enabled: true, position: widget.position diff --git a/apps/server/src/becca/entities/bnote.ts b/apps/server/src/becca/entities/bnote.ts index abdeead4b..4eb92c80d 100644 --- a/apps/server/src/becca/entities/bnote.ts +++ b/apps/server/src/becca/entities/bnote.ts @@ -360,7 +360,6 @@ class BNote extends AbstractBeccaEntity { return this.__attributeCache.filter((attr) => attr.name === name); } return this.__attributeCache; - } private __ensureAttributeCacheIsAvailable() { @@ -697,7 +696,6 @@ class BNote extends AbstractBeccaEntity { return this.ownedAttributes.filter((attr) => attr.name === name); } return this.ownedAttributes; - } /** @@ -750,7 +748,6 @@ class BNote extends AbstractBeccaEntity { return 1; } return 0; - }); this.parents = this.parentBranches.map((branch) => branch.parentNote).filter((note) => !!note) as BNote[]; @@ -1183,7 +1180,6 @@ class BNote extends AbstractBeccaEntity { return a.isHidden ? 1 : -1; } return a.notePath.length - b.notePath.length; - }); return notePaths; @@ -1722,7 +1718,6 @@ class BNote extends AbstractBeccaEntity { return "bx bx-data"; } return NOTE_TYPE_ICONS[this.type]; - } // TODO: Deduplicate with fnote diff --git a/apps/server/src/services/script.ts b/apps/server/src/services/script.ts index e6d88d4b6..97dd99898 100644 --- a/apps/server/src/services/script.ts +++ b/apps/server/src/services/script.ts @@ -114,7 +114,6 @@ function getParams(params?: ScriptParams) { return p.substr(13); } return JSON.stringify(p); - }) .join(","); } @@ -227,10 +226,10 @@ export function buildJsx(contentRaw: string | Buffer) { production: true }); - let code = output.code; + let code = output.code; // Rewrite ESM-like exports to `module.exports =`. - code = output.code.replaceAll( + code = code.replaceAll( /\bexports\s*\.\s*default\s*=\s*/g, 'module.exports = ' ); @@ -241,7 +240,7 @@ export function buildJsx(contentRaw: string | Buffer) { 'const $1 = api.preact;' ); - // Rewrite ESM-like imports to internal API, to `const { foo } = api.preact` + // Rewrite ESM-like imports to internal API, to `const { foo } = api` code = code.replaceAll( /(?:var|let|const)\s+(\w+)\s*=\s*require\(['"]trilium:api['"]\);?/g, 'const $1 = api;'