mirror of
https://github.com/zadam/trilium.git
synced 2025-12-22 15:24:24 +01:00
chore(right_pane): address requested changes
This commit is contained in:
parent
b248805905
commit
ea76fd797c
@ -1,8 +1,7 @@
|
|||||||
import { dayjs } from "@triliumnext/commons";
|
import { dayjs } from "@triliumnext/commons";
|
||||||
import { snapdom } from "@zumer/snapdom";
|
|
||||||
|
|
||||||
import FNote from "../entities/fnote";
|
|
||||||
import type { ViewMode, ViewScope } from "./link.js";
|
import type { ViewMode, ViewScope } from "./link.js";
|
||||||
|
import FNote from "../entities/fnote";
|
||||||
|
import { snapdom } from "@zumer/snapdom";
|
||||||
|
|
||||||
const SVG_MIME = "image/svg+xml";
|
const SVG_MIME = "image/svg+xml";
|
||||||
|
|
||||||
@ -114,9 +113,9 @@ function formatDateISO(date: Date) {
|
|||||||
export function formatDateTime(date: Date, userSuppliedFormat?: string): string {
|
export function formatDateTime(date: Date, userSuppliedFormat?: string): string {
|
||||||
if (userSuppliedFormat?.trim()) {
|
if (userSuppliedFormat?.trim()) {
|
||||||
return dayjs(date).format(userSuppliedFormat);
|
return dayjs(date).format(userSuppliedFormat);
|
||||||
}
|
} else {
|
||||||
return `${formatDate(date)} ${formatTime(date)}`;
|
return `${formatDate(date)} ${formatTime(date)}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function localNowDateTime() {
|
function localNowDateTime() {
|
||||||
@ -192,9 +191,9 @@ export function formatSize(size: number | null | undefined) {
|
|||||||
|
|
||||||
if (size < 1024) {
|
if (size < 1024) {
|
||||||
return `${size} KiB`;
|
return `${size} KiB`;
|
||||||
}
|
} else {
|
||||||
return `${Math.round(size / 102.4) / 10} MiB`;
|
return `${Math.round(size / 102.4) / 10} MiB`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toObject<T, R>(array: T[], fn: (arg0: T) => [key: string, value: R]) {
|
function toObject<T, R>(array: T[], fn: (arg0: T) => [key: string, value: R]) {
|
||||||
@ -298,18 +297,18 @@ function formatHtml(html: string) {
|
|||||||
let indent = "\n";
|
let indent = "\n";
|
||||||
const tab = "\t";
|
const tab = "\t";
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const pre: { indent: string; tag: string }[] = [];
|
let pre: { indent: string; tag: string }[] = [];
|
||||||
|
|
||||||
html = html
|
html = html
|
||||||
.replace(new RegExp("<pre>([\\s\\S]+?)?</pre>"), (x) => {
|
.replace(new RegExp("<pre>([\\s\\S]+?)?</pre>"), function (x) {
|
||||||
pre.push({ indent: "", tag: 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;
|
let ret;
|
||||||
const tagRegEx = /<\/?([^\s/>]+)/.exec(x);
|
const tagRegEx = /<\/?([^\s/>]+)/.exec(x);
|
||||||
const tag = tagRegEx ? tagRegEx[1] : "";
|
let tag = tagRegEx ? tagRegEx[1] : "";
|
||||||
const p = new RegExp("<--TEMPPRE(\\d+)/-->").exec(x);
|
let p = new RegExp("<--TEMPPRE(\\d+)/-->").exec(x);
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
const pInd = parseInt(p[1]);
|
const pInd = parseInt(p[1]);
|
||||||
@ -319,7 +318,8 @@ 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) {
|
if (["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"].indexOf(tag) >= 0) {
|
||||||
// self closing tag
|
// self closing tag
|
||||||
ret = indent + x;
|
ret = indent + x;
|
||||||
} else if (x.indexOf("</") < 0) {
|
} else {
|
||||||
|
if (x.indexOf("</") < 0) {
|
||||||
//open tag
|
//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);
|
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;
|
else ret = indent + x;
|
||||||
@ -330,11 +330,12 @@ function formatHtml(html: string) {
|
|||||||
if (x.charAt(x.length - 1) !== ">") ret = indent + x.substr(0, x.length - 1) + indent + x.substr(x.length - 1, x.length);
|
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;
|
else ret = indent + x;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (i = pre.length; i--;) {
|
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;
|
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]>{
|
export function dynamicRequire<T extends keyof dynamicRequireMappings>(moduleName: T): Awaited<dynamicRequireMappings[T]>{
|
||||||
if (typeof __non_webpack_require__ !== "undefined") {
|
if (typeof __non_webpack_require__ !== "undefined") {
|
||||||
return __non_webpack_require__(moduleName);
|
return __non_webpack_require__(moduleName);
|
||||||
}
|
} else {
|
||||||
// explicitly pass as string and not as expression to suppress webpack warning
|
// explicitly pass as string and not as expression to suppress webpack warning
|
||||||
// 'Critical dependency: the request of a dependency is an expression'
|
// 'Critical dependency: the request of a dependency is an expression'
|
||||||
return require(`${moduleName}`);
|
return require(`${moduleName}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: string) {
|
function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: string) {
|
||||||
@ -508,8 +509,8 @@ export function escapeRegExp(str: string) {
|
|||||||
function areObjectsEqual(...args: unknown[]) {
|
function areObjectsEqual(...args: unknown[]) {
|
||||||
let i;
|
let i;
|
||||||
let l;
|
let l;
|
||||||
let leftChain: object[];
|
let leftChain: Object[];
|
||||||
let rightChain: object[];
|
let rightChain: Object[];
|
||||||
|
|
||||||
function compare2Objects(x: unknown, y: unknown) {
|
function compare2Objects(x: unknown, y: unknown) {
|
||||||
let p;
|
let p;
|
||||||
@ -762,11 +763,11 @@ export function getSizeFromSvg(svgContent: string) {
|
|||||||
return {
|
return {
|
||||||
width: parseFloat(width),
|
width: parseFloat(width),
|
||||||
height: parseFloat(height)
|
height: parseFloat(height)
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
console.warn("SVG export error", svgDocument.documentElement);
|
console.warn("SVG export error", svgDocument.documentElement);
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -895,9 +896,9 @@ export function mapToKeyValueArray<K extends string | number | symbol, V>(map: R
|
|||||||
export function getErrorMessage(e: unknown) {
|
export function getErrorMessage(e: unknown) {
|
||||||
if (e && typeof e === "object" && "message" in e && typeof e.message === "string") {
|
if (e && typeof e === "object" && "message" in e && typeof e.message === "string") {
|
||||||
return e.message;
|
return e.message;
|
||||||
}
|
} else {
|
||||||
return "Unknown error";
|
return "Unknown error";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -912,12 +913,6 @@ export function handleRightToLeftPlacement<T extends string>(placement: T) {
|
|||||||
return placement;
|
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 {
|
export default {
|
||||||
reloadFrontendApp,
|
reloadFrontendApp,
|
||||||
restartDesktopApp,
|
restartDesktopApp,
|
||||||
|
|||||||
@ -636,7 +636,7 @@ export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, {
|
|||||||
parentContainer.replaceChildren();
|
parentContainer.replaceChildren();
|
||||||
renderedWidget.appendTo(parentContainer);
|
renderedWidget.appendTo(parentContainer);
|
||||||
}
|
}
|
||||||
});
|
}, [ renderedWidget ]);
|
||||||
|
|
||||||
// Inject the note context.
|
// Inject the note context.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user