Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/main' into standalone

Elian Doran0b1122d9af50
diff --cc apps/client/src/index.ts
index 292138ddc7,720d3eb59c..48a463273f
--- a/apps/client/src/index.ts
+++ b/apps/client/src/index.ts
@@@ -36,37 -38,11 +38,38 @@@ async function setupGlob()
window.global = globalThis; /* fixes https://github.com/webpack/webpack/issues/10035 */
window.glob = {
...json,
- activeDialog: null
+ activeDialog: null,
+ device: json.device || getDevice()
};
+ window.glob.getThemeStyle = getThemeStyle;
}
+function getDevice() {
+ // Respect user's manual override via URL.
+ const urlParams = new URLSearchParams(window.location.search);
+ if (urlParams.has("print")) {
+ return "print";
+ } else if (urlParams.has("desktop")) {
+ return "desktop";
+ } else if (urlParams.has("mobile")) {
+ return "mobile";
+ }
+
+ const deviceCookie = document.cookie.split("; ").find(row => row.startsWith("trilium-device="))?.split("=")[1];
+ if (deviceCookie === "desktop" || deviceCookie === "mobile") return deviceCookie;
+ return isMobile() ? "mobile" : "desktop";
+}
+
+// https://stackoverflow.com/a/73731646/944162
+function isMobile() {
+ const mQ = matchMedia?.("(pointer:coarse)");
+ if (mQ?.media === "(pointer:coarse)") return !!mQ.matches;
+
+ if ("orientation" in window) return true;
+ const userAgentsRegEx = /\b(Android|iPhone|iPad|iPod|Windows Phone|BlackBerry|webOS|IEMobile)\b/i;
+ return userAgentsRegEx.test(navigator.userAgent);
+}
+
async function loadBootstrapCss() {
// We have to selectively import Bootstrap CSS based on text direction.
if (glob.isRtl) {
diff --cc apps/server/package.json
index 5db028dbdb,5801728e65..6f3741ad8e
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@@ -30,16 -30,16 +30,16 @@@
"proxy-nginx-subdir": "docker run --name trilium-nginx-subdir --rm --network=host -v ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro nginx:latest"
},
"dependencies": {
- "@ai-sdk/anthropic": "3.0.64",
- "@ai-sdk/google": "3.0.55",
- "@ai-sdk/openai": "3.0.49",
+ "@ai-sdk/anthropic": "3.0.66",
+ "@ai-sdk/google": "3.0.58",
+ "@ai-sdk/openai": "3.0.50",
"@modelcontextprotocol/sdk": "^1.12.1",
- "ai": "6.0.142",
+ "ai": "6.0.146",
"better-sqlite3": "12.8.0",
"html-to-text": "9.0.5",
+ "i18next-fs-backend": "2.6.3",
+ "i18next": "26.0.3",
"js-yaml": "4.1.1",
- "node-html-parser": "7.1.0",
- "sucrase": "3.35.1",
"unpdf": "1.4.0"
},
"devDependencies": {
@@@ -117,7 -130,9 +117,7 @@@
"time2fa": "1.4.2",
"tmp": "0.2.5",
"turnish": "1.8.0",
- "vite": "8.0.3",
- "unescape": "1.0.1",
+ "vite": "8.0.5",
- "ws": "8.20.0",
"xml2js": "0.6.2",
"yauzl": "3.3.0"
}
diff --cc apps/server/src/routes/index.ts
index 90a502dd61,0eec58bfa7..ddbfaf2b4a
--- a/apps/server/src/routes/index.ts
+++ b/apps/server/src/routes/index.ts
@@@ -1,5 -1,3 +1,5 @@@
+import { BootstrapDefinition } from "@triliumnext/commons";
- import { getSharedBootstrapItems, icon_packs as iconPackService, sql_init } from "@triliumnext/core";
++import { attributes, BNote, getSharedBootstrapItems, icon_packs as iconPackService, sql_init } from "@triliumnext/core";
import type { Request, Response } from "express";
import packageJson from "../../package.json" with { type: "json" };
@@@ -23,32 -29,6 +23,32 @@@ export function bootstrap(req: Request
req.session.csrfInitialized = true;
}
+ const view = getView(req);
+ const isDbInitialized = sql_init.isDbInitialized();
+ const commonItems = {
+ ...getSharedBootstrapItems(assetPath, isDbInitialized),
+ baseApiUrl: "api/",
+ appPath,
+ isStandalone: false,
+ isElectron,
+ isDev,
+ triliumVersion: packageJson.version,
+ device: view,
+ TRILIUM_SAFE_MODE: !!process.env.TRILIUM_SAFE_MODE,
+ instanceName: config.General ? config.General.instanceName : null
+ };
+ if (!isDbInitialized) {
+ res.send({
+ ...commonItems,
+ hasNativeTitleBar: false,
+ hasBackgroundEffects: isElectron && (isWindows11 || isMac),
+ isMainWindow: true,
- appCssNoteIds: [],
++ appCssNoteIds: []
+ } satisfies BootstrapDefinition);
+ return;
+ }
+
+
const csrfToken = generateCsrfToken(req, res, {
overwrite: false,
validateOnReuse: false // if validation fails, generate a new token instead of throwing an error
diff --cc packages/commons/src/lib/server_api.ts
index 5d34e005f6,84b16482bb..115699f448
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@@ -322,75 -321,3 +322,76 @@@ export interface IconRegistry
}[]
}[];
}
+
+export type LabelType = "text" | "textarea" | "number" | "boolean" | "date" | "datetime" | "time" | "url" | "color";
+export type Multiplicity = "single" | "multi";
+
+export interface DefinitionObject {
+ isPromoted?: boolean;
+ labelType?: LabelType;
+ multiplicity?: Multiplicity;
+ numberPrecision?: number;
+ promotedAlias?: string;
+ inverseRelation?: string;
+}
+
+/**
+ * Bootstrap items that the client needs to start up. These are sent by the server in the HTML and made available as `window.glob`.
+ */
+export type BootstrapDefinition = {
+ dbInitialized: boolean;
+ baseApiUrl: string;
+ assetPath: string;
- themeCssUrl: string | false;
- themeUseNextAsBase?: "next" | "next-light" | "next-dark";
++ theme: string;
++ themeBase?: "next" | "next-light" | "next-dark";
++ customThemeCssUrl?: string;
+ iconPackCss: string;
+ iconRegistry: IconRegistry;
+ device: "mobile" | "desktop" | "print" | false;
+ csrfToken?: string;
+ headingStyle: "plain" | "underline" | "markdown";
+ layoutOrientation: "vertical" | "horizontal";
+ platform?: "aix" | "android" | "darwin" | "freebsd" | "haiku" | "linux" | "openbsd" | "sunos" | "win32" | "cygwin" | "netbsd" | "web";
+ isElectron: boolean;
+ isStandalone: boolean;
+ hasNativeTitleBar: boolean;
+ hasBackgroundEffects: boolean;
+ maxEntityChangeIdAtLoad?: number;
+ maxEntityChangeSyncIdAtLoad?: number;
+ instanceName: string | null;
+ appCssNoteIds: string[];
+ isDev: boolean;
+ isMainWindow: boolean;
+ isProtectedSessionAvailable: boolean;
+ triliumVersion: string;
+ appPath: string;
+ currentLocale: Locale;
+ isRtl: boolean;
+ TRILIUM_SAFE_MODE: boolean;
+ componentId?: string;
+};
+
+/**
+ * Response for /api/setup/status.
+ */
+export interface SetupStatusResponse {
+ syncVersion: number;
+ schemaExists: boolean;
+}
+
+/**
+ * Response for /api/setup/sync-seed.
+ */
+export interface SetupSyncSeedResponse {
+ syncVersion: number;
+ options: OptionRow[];
+}
+
+export type SetupSyncFromServerResponse = {
+ result: "success";
+} | {
+ result: "failure";
+ error: string;
+}
+
+export type ScriptParams = any[];
diff --cc packages/trilium-core/src/services/bootstrap_utils.ts
index 9d857145f1,0000000000..a4d435a492
mode 100644,000000..100644
--- a/packages/trilium-core/src/services/bootstrap_utils.ts
+++ b/packages/trilium-core/src/services/bootstrap_utils.ts
@@@ -1,91 -1,0 +1,109 @@@
+import { BootstrapDefinition } from "@triliumnext/commons";
+import { getSql } from "./sql";
+import protected_session from "./protected_session";
+import { generateCss, generateIconRegistry, getIconPacks, MIME_TO_EXTENSION_MAPPINGS } from "./icon_packs";
+import optionService from "./options";
+import { getCurrentLocale } from "./i18n";
+import attributes from "./attributes";
+import BNote from "../becca/entities/bnote";
+import { getPlatform } from "./platform";
+
+export default function getSharedBootstrapItems(assetPath: string, dbInitialized: boolean) {
+ const sql = getSql();
+ const currentLocale = getCurrentLocale();
+
+ const commonItems = {
+ assetPath,
+ dbInitialized,
+ currentLocale,
+ isRtl: !!currentLocale.rtl,
+ isProtectedSessionAvailable: false,
+ layoutOrientation: "vertical" as const,
+ headingStyle: "plain" as const,
+ componentId: "",
+ ...getIconConfig(assetPath)
+ };
+
+ // Setup not yet finished.
+ if (!dbInitialized) {
+ return {
+ ...commonItems,
++ theme: "next",
+ themeCssUrl: false as const,
+ themeUseNextAsBase: "next" as const,
- appCssNoteIds: []
++ appCssNoteIds: [],
+ };
+ }
+
+ // Database initialized.
+ const options = optionService.getOptionMap();
+ const theme = options.theme;
+ const themeNote = attributes.getNoteWithLabel("appTheme", theme);
++ const themeUseNextAsBase = themeNote?.getAttributeValue("label", "appThemeBase") ?? undefined;
++
+ return {
+ ...commonItems,
+ headingStyle: options.headingStyle as "plain" | "underline" | "markdown",
+ layoutOrientation: options.layoutOrientation as "vertical" | "horizontal",
+ maxEntityChangeIdAtLoad: sql.getValue<number>("SELECT COALESCE(MAX(id), 0) FROM entity_changes"),
+ maxEntityChangeSyncIdAtLoad: sql.getValue<number>("SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1"),
+ isProtectedSessionAvailable: protected_session.isProtectedSessionAvailable(),
++ theme,
++ themeBase: themeUseNextAsBase as "next" | "next-light" | "next-dark" | undefined,
++ customThemeCssUrl: getCustomThemeCssUrl(theme, themeNote),
+ themeCssUrl: getThemeCssUrl(theme, commonItems.assetPath, themeNote) as string | false,
+ themeUseNextAsBase: themeNote?.getAttributeValue("label", "appThemeBase") as "next" | "next-light" | "next-dark",
+ appCssNoteIds: getAppCssNoteIds(),
+ }
+}
+
+export function getIconConfig(assetPath: string): Pick<BootstrapDefinition, "iconRegistry" | "iconPackCss"> {
+ const iconPacks = getIconPacks();
+
+ return {
+ iconRegistry: generateIconRegistry(iconPacks),
+ iconPackCss: iconPacks
+ .map(p => generateCss(p, p.builtin
+ ? `${assetPath}/fonts/${p.fontAttachmentId}.${MIME_TO_EXTENSION_MAPPINGS[p.fontMime]}`
+ : `api/attachments/download/${p.fontAttachmentId}`))
+ .filter(Boolean)
+ .join("\n\n"),
+ };
+}
+
+function getAppCssNoteIds() {
+ return attributes.getNotesWithLabel("appCss").map((note) => note.noteId);
+}
+
+function getThemeCssUrl(theme: string, assetPath: string, themeNote: BNote | null) {
+ if (theme === "auto") {
+ return `${assetPath}/stylesheets/theme.css`;
+ } else if (theme === "light") {
+ // light theme is always loaded as baseline
+ return false;
+ } else if (theme === "dark") {
+ return `${assetPath}/stylesheets/theme-dark.css`;
+ } else if (theme === "next") {
+ return `${assetPath}/stylesheets/theme-next.css`;
+ } else if (theme === "next-light") {
+ return `${assetPath}/stylesheets/theme-next-light.css`;
+ } else if (theme === "next-dark") {
+ return `${assetPath}/stylesheets/theme-next-dark.css`;
+ } else if (!getPlatform().getEnv("TRILIUM_SAFE_MODE") && themeNote) {
+ return `api/notes/download/${themeNote.noteId}`;
+ }
+ // baseline light theme
+ return false;
+}
++
++function getCustomThemeCssUrl(theme: string, themeNote: BNote | null) {
++ if (["auto", "light", "dark", "next", "next-light", "next-dark"].includes(theme)) {
++ return undefined;
++ }
++
++ if (!process.env.TRILIUM_SAFE_MODE && themeNote) {
++ return `api/notes/download/${themeNote.noteId}`;
++ }
++
++ return undefined;
++}
diff --cc packages/trilium-core/src/services/migration.ts
index 9ab5cf0cd6,df43e42bd2..a241d6e8db
--- a/packages/trilium-core/src/services/migration.ts
+++ b/packages/trilium-core/src/services/migration.ts
@@@ -57,8 -57,13 +58,13 @@@ async function migrate()
log.info(`Migration to version ${mig.dbVersion} has been successful.`);
} catch (e: any) {
- console.error(e);
- getPlatform().crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack }));
+ if (mig.ignoreErrors) {
+ log.info(`Migration to version ${mig.dbVersion} failed, but ignoreErrors is set. Continuing. Error: ${e.message}`);
+ } else {
+ console.error(e);
- crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack }));
++ getPlatform().crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack }));
+ break; // crash() is sometimes async
+ }
}
}
});
diff --cc pnpm-lock.yaml
index 643feff98f,73a0d466a1..2d29e321e7
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@@ -171,23 -171,16 +171,23 @@@ importers
specifier: 2.0.1
version: 2.0.1
vite:
- specifier: 8.0.3
+ specifier: 8.0.5
vite-plugin-dts:
specifier: 4.5.4
vitest:
specifier: 4.1.2
apps/build-docs:
+ dependencies:
+ '@triliumnext/core':
+ specifier: workspace:*
+ version: link:../../packages/trilium-core
+ '@triliumnext/server':
+ specifier: workspace:*
+ version: link:../server
devDependencies:
'@redocly/cli':
specifier: 2.25.4
@@@ -419,225 -412,8 +419,225 @@@
specifier: 0.7.2
version: 0.7.2
vite-plugin-static-copy:
+ specifier: 4.0.1
+
+ apps/client-standalone:
+ dependencies:
+ '@excalidraw/excalidraw':
+ specifier: 0.18.0
+ '@fullcalendar/core':
+ specifier: 6.1.20
+ version: 6.1.20
+ '@fullcalendar/daygrid':
+ specifier: 6.1.20
+ version: 6.1.20(@fullcalendar/[email protected])
+ '@fullcalendar/interaction':
+ specifier: 6.1.20
+ version: 6.1.20(@fullcalendar/[email protected])
+ '@fullcalendar/list':
+ specifier: 6.1.20
+ version: 6.1.20(@fullcalendar/[email protected])
+ '@fullcalendar/multimonth':
+ specifier: 6.1.20
+ version: 6.1.20(@fullcalendar/[email protected])
+ '@fullcalendar/timegrid':
+ specifier: 6.1.20
+ version: 6.1.20(@fullcalendar/[email protected])
+ '@maplibre/maplibre-gl-leaflet':
+ specifier: 0.1.3
+ '@mermaid-js/layout-elk':
+ specifier: 0.2.1
+ version: 0.2.1([email protected])
+ '@mind-elixir/node-menu':
+ specifier: 5.0.1
+ version: 5.0.1([email protected])
+ '@popperjs/core':
+ specifier: 2.11.8
+ version: 2.11.8
+ '@preact/signals':
+ specifier: 2.9.0
- version: 2.9.0([email protected])
++ version: 2.9.0([email protected])
+ '@sqlite.org/sqlite-wasm':
+ specifier: 3.51.1-build2
+ version: 3.51.1-build2
+ '@triliumnext/ckeditor5':
+ specifier: workspace:*
+ version: link:../../packages/ckeditor5
+ '@triliumnext/codemirror':
+ specifier: workspace:*
+ version: link:../../packages/codemirror
+ '@triliumnext/commons':
+ specifier: workspace:*
+ version: link:../../packages/commons
+ '@triliumnext/core':
+ specifier: workspace:*
+ version: link:../../packages/trilium-core
+ '@triliumnext/highlightjs':
+ specifier: workspace:*
+ version: link:../../packages/highlightjs
+ '@triliumnext/share-theme':
+ specifier: workspace:*
+ version: link:../../packages/share-theme
+ '@triliumnext/split.js':
+ specifier: workspace:*
+ version: link:../../packages/splitjs
+ '@zumer/snapdom':
+ specifier: 2.7.0
+ version: 2.7.0
+ autocomplete.js:
+ specifier: 0.38.1
+ version: 0.38.1
+ bootstrap:
+ specifier: 5.3.8
+ version: 5.3.8(@popperjs/[email protected])
+ boxicons:
+ specifier: 2.1.4
+ version: 2.1.4
+ clsx:
+ specifier: 2.1.1
+ version: 2.1.1
+ color:
+ specifier: 5.0.3
+ version: 5.0.3
+ debounce:
+ specifier: 3.0.0
+ version: 3.0.0
+ draggabilly:
+ specifier: 3.0.0
+ version: 3.0.0
+ fflate:
+ specifier: 0.8.2
+ version: 0.8.2
+ force-graph:
+ specifier: 1.51.2
+ version: 1.51.2
+ globals:
+ specifier: 17.4.0
+ version: 17.4.0
+ i18next:
+ specifier: 26.0.3
+ version: 26.0.3([email protected])
+ i18next-http-backend:
+ specifier: 3.0.4
+ version: 3.0.4([email protected])
+ jquery:
+ specifier: 4.0.0
+ version: 4.0.0
+ jquery.fancytree:
+ specifier: 2.38.5
+ version: 2.38.5([email protected])
+ js-md5:
+ specifier: 0.8.3
+ version: 0.8.3
+ js-sha1:
+ specifier: 0.7.0
+ version: 0.7.0
+ js-sha256:
+ specifier: 0.11.1
+ version: 0.11.1
+ js-sha512:
+ specifier: 0.9.0
+ version: 0.9.0
+ jsplumb:
+ specifier: 2.15.6
+ version: 2.15.6
+ katex:
+ specifier: 0.16.44
+ version: 0.16.44
+ knockout:
+ specifier: 3.5.1
+ version: 3.5.1
+ leaflet:
+ specifier: 1.9.4
+ version: 1.9.4
+ leaflet-gpx:
+ specifier: 2.2.0
+ version: 2.2.0
+ mark.js:
+ specifier: 8.11.1
+ version: 8.11.1
+ marked:
+ specifier: 17.0.5
+ version: 17.0.5
+ mermaid:
+ specifier: 11.14.0
+ version: 11.14.0
+ mind-elixir:
+ specifier: 5.10.0
+ version: 5.10.0
+ normalize.css:
+ specifier: 8.0.1
+ version: 8.0.1
+ panzoom:
+ specifier: 9.4.4
+ version: 9.4.4
+ preact:
- specifier: 10.29.0
- version: 10.29.0
++ specifier: 10.29.1
++ version: 10.29.1
+ react-i18next:
+ specifier: 17.0.2
+ react-window:
+ specifier: 2.2.7
+ reveal.js:
+ specifier: 6.0.0
+ version: 6.0.0
+ svg-pan-zoom:
+ specifier: 3.6.2
+ version: 3.6.2
+ tabulator-tables:
+ specifier: 6.4.0
+ version: 6.4.0
+ vanilla-js-wheel-zoom:
+ specifier: 9.0.4
+ version: 9.0.4
+ devDependencies:
+ '@ckeditor/ckeditor5-inspector':
+ specifier: 5.0.0
+ version: 5.0.0
+ '@preact/preset-vite':
+ specifier: 2.10.2
+ '@types/bootstrap':
+ specifier: 5.2.10
+ version: 5.2.10
+ '@types/jquery':
specifier: 4.0.0
+ version: 4.0.0
+ '@types/leaflet':
+ specifier: 1.9.21
+ version: 1.9.21
+ '@types/leaflet-gpx':
+ specifier: 1.3.8
+ version: 1.3.8
+ '@types/mark.js':
+ specifier: 8.11.12
+ version: 8.11.12
+ '@types/reveal.js':
+ specifier: 5.2.2
+ version: 5.2.2
+ '@types/tabulator-tables':
+ specifier: 6.3.1
+ version: 6.3.1
+ copy-webpack-plugin:
+ specifier: 14.0.0
+ cross-env:
+ specifier: 7.0.3
+ version: 7.0.3
+ happy-dom:
+ specifier: 20.8.9
+ script-loader:
+ specifier: 0.7.2
+ version: 0.7.2
+ vite-plugin-static-copy:
+ specifier: 4.0.1
apps/db-compare:
dependencies:
@@@ -1050,9 -859,15 +1050,9 @@@
turnish:
specifier: 1.8.0
version: 1.8.0
- unescape:
- specifier: 1.0.1
- version: 1.0.1
vite:
- specifier: 8.0.3
+ specifier: 8.0.5
- ws:
- specifier: 8.20.0
xml2js:
specifier: 0.6.2
version: 0.6.2
@@@ -1623,63 -1450,8 +1635,63 @@@
vitest:
specifier: 4.1.2
+ packages/trilium-core:
+ dependencies:
+ '@braintree/sanitize-url':
+ specifier: 7.1.1
+ version: 7.1.1
+ '@triliumnext/commons':
+ specifier: workspace:*
+ version: link:../commons
+ '@triliumnext/turndown-plugin-gfm':
+ specifier: workspace:*
+ version: link:../turndown-plugin-gfm
+ async-mutex:
+ specifier: 0.5.0
+ version: 0.5.0
+ chardet:
+ specifier: 2.1.1
+ version: 2.1.1
+ escape-html:
+ specifier: 1.0.3
+ version: 1.0.3
+ i18next:
+ specifier: 26.0.3
+ version: 26.0.3([email protected])
+ mime-types:
+ specifier: 3.0.2
+ version: 3.0.2
+ node-html-parser:
+ specifier: 7.1.0
+ version: 7.1.0
+ sanitize-filename:
+ specifier: 1.6.4
+ version: 1.6.4
+ sanitize-html:
+ specifier: 2.17.2
+ version: 2.17.2
+ strip-bom:
+ specifier: 5.0.0
+ version: 5.0.0
+ sucrase:
+ specifier: 3.35.1
+ version: 3.35.1
+ unescape:
+ specifier: 1.0.1
+ version: 1.0.1
+ devDependencies:
+ '@types/escape-html':
+ specifier: 1.0.4
+ version: 1.0.4
+ '@types/mime-types':
+ specifier: 3.0.1
+ version: 3.0.1
+ '@types/sanitize-html':
+ specifier: 2.16.1
+ version: 2.16.1
+
packages/turndown-plugin-gfm:
devDependencies:
happy-dom:
@@@ -18093,23 -17893,7 +18165,23 @@@ snapshots
'@popperjs/[email protected]': {}
+ dependencies:
+ '@babel/core': 7.29.0
+ '@babel/plugin-transform-react-jsx': 7.27.1(@babel/[email protected])
+ '@babel/plugin-transform-react-jsx-development': 7.27.1(@babel/[email protected])
+ '@rollup/pluginutils': 4.2.1
+ babel-plugin-transform-hook-names: 1.0.2(@babel/[email protected])
+ debug: 4.4.3
+ picocolors: 1.1.1
+ transitivePeerDependencies:
+ - preact
+ - supports-color
+
dependencies:
'@babel/core': 7.29.0
'@babel/plugin-transform-react-jsx': 7.27.1(@babel/[email protected])
@@@ -19590,10 -19376,8 +19666,10 @@@
dependencies:
- '@types/node': 24.12.0
+ '@types/node': 24.12.2
+ '@types/[email protected]': {}
+
'@types/[email protected]': {}
@@@ -30118,7 -29838,7 +30140,7 @@@
- rollup
- supports-color
dependencies:
chokidar: 3.6.0
p-map: 7.0.4