chore(right_pane): address requested changes

This commit is contained in:
Elian Doran 2025-12-20 12:29:43 +02:00
parent b248805905
commit ea76fd797c
No known key found for this signature in database
2 changed files with 48 additions and 53 deletions

View File

@ -1,8 +1,7 @@
import { dayjs } from "@triliumnext/commons";
import { snapdom } from "@zumer/snapdom";
import FNote from "../entities/fnote";
import type { ViewMode, ViewScope } from "./link.js";
import FNote from "../entities/fnote";
import { snapdom } from "@zumer/snapdom";
const SVG_MIME = "image/svg+xml";
@ -114,9 +113,9 @@ function formatDateISO(date: Date) {
export function formatDateTime(date: Date, userSuppliedFormat?: string): string {
if (userSuppliedFormat?.trim()) {
return dayjs(date).format(userSuppliedFormat);
}
return `${formatDate(date)} ${formatTime(date)}`;
} else {
return `${formatDate(date)} ${formatTime(date)}`;
}
}
function localNowDateTime() {
@ -192,9 +191,9 @@ export function formatSize(size: number | null | undefined) {
if (size < 1024) {
return `${size} KiB`;
}
return `${Math.round(size / 102.4) / 10} MiB`;
} else {
return `${Math.round(size / 102.4) / 10} MiB`;
}
}
function toObject<T, R>(array: T[], fn: (arg0: T) => [key: string, value: R]) {
@ -298,18 +297,18 @@ function formatHtml(html: string) {
let indent = "\n";
const tab = "\t";
let i = 0;
const pre: { indent: string; tag: string }[] = [];
let pre: { indent: string; tag: string }[] = [];
html = html
.replace(new RegExp("<pre>([\\s\\S]+?)?</pre>"), (x) => {
.replace(new RegExp("<pre>([\\s\\S]+?)?</pre>"), function (x) {
pre.push({ indent: "", tag: x });
return `<--TEMPPRE${ i++ }/-->`;
return "<--TEMPPRE" + i++ + "/-->";
})
.replace(new RegExp("<[^<>]+>[^<]?", "g"), (x) => {
.replace(new RegExp("<[^<>]+>[^<]?", "g"), function (x) {
let ret;
const tagRegEx = /<\/?([^\s/>]+)/.exec(x);
const tag = tagRegEx ? tagRegEx[1] : "";
const p = new RegExp("<--TEMPPRE(\\d+)/-->").exec(x);
let tag = tagRegEx ? tagRegEx[1] : "";
let p = new RegExp("<--TEMPPRE(\\d+)/-->").exec(x);
if (p) {
const pInd = parseInt(p[1]);
@ -319,22 +318,24 @@ function formatHtml(html: string) {
if (["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"].indexOf(tag) >= 0) {
// self closing tag
ret = indent + x;
} else if (x.indexOf("</") < 0) {
//open tag
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + tab + x.substr(x.length - 1, x.length);
else ret = indent + x;
!p && (indent += tab);
} else {
//close tag
indent = indent.substr(0, indent.length - 1);
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + x.substr(x.length - 1, x.length);
else ret = indent + x;
if (x.indexOf("</") < 0) {
//open tag
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + tab + x.substr(x.length - 1, x.length);
else ret = indent + x;
!p && (indent += tab);
} else {
//close tag
indent = indent.substr(0, indent.length - 1);
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + x.substr(x.length - 1, x.length);
else ret = indent + x;
}
}
return ret;
});
for (i = pre.length; i--;) {
html = html.replace(`<--TEMPPRE${ i }/-->`, pre[i].tag.replace("<pre>", "<pre>\n").replace("</pre>", `${pre[i].indent }</pre>`));
html = html.replace("<--TEMPPRE" + i + "/-->", pre[i].tag.replace("<pre>", "<pre>\n").replace("</pre>", pre[i].indent + "</pre>"));
}
return html.charAt(0) === "\n" ? html.substr(1, html.length - 1) : html;
@ -363,11 +364,11 @@ type dynamicRequireMappings = {
export function dynamicRequire<T extends keyof dynamicRequireMappings>(moduleName: T): Awaited<dynamicRequireMappings[T]>{
if (typeof __non_webpack_require__ !== "undefined") {
return __non_webpack_require__(moduleName);
}
// explicitly pass as string and not as expression to suppress webpack warning
// 'Critical dependency: the request of a dependency is an expression'
return require(`${moduleName}`);
} else {
// explicitly pass as string and not as expression to suppress webpack warning
// 'Critical dependency: the request of a dependency is an expression'
return require(`${moduleName}`);
}
}
function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: string) {
@ -508,8 +509,8 @@ export function escapeRegExp(str: string) {
function areObjectsEqual(...args: unknown[]) {
let i;
let l;
let leftChain: object[];
let rightChain: object[];
let leftChain: Object[];
let rightChain: Object[];
function compare2Objects(x: unknown, y: unknown) {
let p;
@ -694,9 +695,9 @@ async function downloadAsSvg(nameWithoutExtension: string, svgSource: string | S
try {
const result = await snapdom(element, {
backgroundColor: "transparent",
scale: 2
});
backgroundColor: "transparent",
scale: 2
});
triggerDownload(`${nameWithoutExtension}.svg`, result.url);
} finally {
cleanup();
@ -732,9 +733,9 @@ async function downloadAsPng(nameWithoutExtension: string, svgSource: string | S
try {
const result = await snapdom(element, {
backgroundColor: "transparent",
scale: 2
});
backgroundColor: "transparent",
scale: 2
});
const pngImg = await result.toPng();
await triggerDownload(`${nameWithoutExtension}.png`, pngImg.src);
} finally {
@ -762,11 +763,11 @@ export function getSizeFromSvg(svgContent: string) {
return {
width: parseFloat(width),
height: parseFloat(height)
};
}
console.warn("SVG export error", svgDocument.documentElement);
return null;
}
} else {
console.warn("SVG export error", svgDocument.documentElement);
return null;
}
}
/**
@ -895,9 +896,9 @@ export function mapToKeyValueArray<K extends string | number | symbol, V>(map: R
export function getErrorMessage(e: unknown) {
if (e && typeof e === "object" && "message" in e && typeof e.message === "string") {
return e.message;
}
return "Unknown error";
} else {
return "Unknown error";
}
}
/**
@ -912,12 +913,6 @@ export function handleRightToLeftPlacement<T extends string>(placement: T) {
return placement;
}
export function clamp(value: number, min: number, max: number) {
if (value < min) return min;
if (value > max) return max;
return value;
}
export default {
reloadFrontendApp,
restartDesktopApp,

View File

@ -636,7 +636,7 @@ export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, {
parentContainer.replaceChildren();
renderedWidget.appendTo(parentContainer);
}
});
}, [ renderedWidget ]);
// Inject the note context.
useEffect(() => {