mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-18 08:13:40 +08:00
chore(client/ts): port read_only_text
This commit is contained in:
parent
f150ec15bc
commit
115c3bbeb0
17
src/public/app/types.d.ts
vendored
17
src/public/app/types.d.ts
vendored
@ -5,6 +5,7 @@ import utils from "./services/utils.ts";
|
|||||||
import appContext from "./components/app_context.ts";
|
import appContext from "./components/app_context.ts";
|
||||||
import server from "./services/server.ts";
|
import server from "./services/server.ts";
|
||||||
import library_loader, { Library } from "./services/library_loader.ts";
|
import library_loader, { Library } from "./services/library_loader.ts";
|
||||||
|
import type { init } from "i18next";
|
||||||
|
|
||||||
interface ElectronProcess {
|
interface ElectronProcess {
|
||||||
type: string;
|
type: string;
|
||||||
@ -139,10 +140,26 @@ declare global {
|
|||||||
}
|
}
|
||||||
interface MermaidLoader {
|
interface MermaidLoader {
|
||||||
|
|
||||||
|
}
|
||||||
|
interface MermaidChartConfig {
|
||||||
|
useMaxWidth: boolean;
|
||||||
|
}
|
||||||
|
interface MermaidConfig {
|
||||||
|
theme: string;
|
||||||
|
securityLevel: "antiscript",
|
||||||
|
flow: MermaidChartConfig;
|
||||||
|
sequence: MermaidChartConfig;
|
||||||
|
gantt: MermaidChartConfig;
|
||||||
|
class: MermaidChartConfig;
|
||||||
|
state: MermaidChartConfig;
|
||||||
|
pie: MermaidChartConfig;
|
||||||
|
journey: MermaidChartConfig;
|
||||||
|
git: MermaidChartConfig;
|
||||||
}
|
}
|
||||||
var mermaid: {
|
var mermaid: {
|
||||||
mermaidAPI: MermaidApi;
|
mermaidAPI: MermaidApi;
|
||||||
registerLayoutLoaders(loader: MermaidLoader);
|
registerLayoutLoaders(loader: MermaidLoader);
|
||||||
|
init(config: MermaidConfig, el: HTMLElement | JQuery<HTMLElement>);
|
||||||
parse(content: string, opts: {
|
parse(content: string, opts: {
|
||||||
suppressErrors: true
|
suppressErrors: true
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
|
@ -143,7 +143,7 @@ export default class MermaidWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMermaidConfig() {
|
export function getMermaidConfig(): MermaidConfig {
|
||||||
const documentStyle = window.getComputedStyle(document.documentElement);
|
const documentStyle = window.getComputedStyle(document.documentElement);
|
||||||
const mermaidTheme = documentStyle.getPropertyValue("--mermaid-theme");
|
const mermaidTheme = documentStyle.getPropertyValue("--mermaid-theme");
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
|
|||||||
import libraryLoader from "../../services/library_loader.js";
|
import libraryLoader from "../../services/library_loader.js";
|
||||||
import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
|
import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
|
||||||
import { getMermaidConfig } from "../mermaid.js";
|
import { getMermaidConfig } from "../mermaid.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
import type { EventData } from "../../components/app_context.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="note-detail-readonly-text note-detail-printable">
|
<div class="note-detail-readonly-text note-detail-printable">
|
||||||
@ -71,6 +73,9 @@ const TPL = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
||||||
|
|
||||||
|
private $content!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "readOnlyText";
|
return "readOnlyText";
|
||||||
}
|
}
|
||||||
@ -89,7 +94,7 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
this.$content.html("");
|
this.$content.html("");
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
async doRefresh(note: FNote) {
|
||||||
// we load CKEditor also for read only notes because they contain content styles required for correct rendering of even read only notes
|
// we load CKEditor also for read only notes because they contain content styles required for correct rendering of even read only notes
|
||||||
// we could load just ckeditor-content.css but that causes CSS conflicts when both build CSS and this content CSS is loaded at the same time
|
// we could load just ckeditor-content.css but that causes CSS conflicts when both build CSS and this content CSS is loaded at the same time
|
||||||
// (see https://github.com/zadam/trilium/issues/1590 for example of such conflict)
|
// (see https://github.com/zadam/trilium/issues/1590 for example of such conflict)
|
||||||
@ -97,13 +102,13 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
|
|
||||||
const blob = await note.getBlob();
|
const blob = await note.getBlob();
|
||||||
|
|
||||||
this.$content.html(blob.content);
|
this.$content.html(blob?.content ?? "");
|
||||||
|
|
||||||
this.$content.find("a.reference-link").each(async (_, el) => {
|
this.$content.find("a.reference-link").each((_, el) => {
|
||||||
this.loadReferenceLinkTitle($(el));
|
this.loadReferenceLinkTitle($(el));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$content.find("section").each(async (_, el) => {
|
this.$content.find("section").each((_, el) => {
|
||||||
const noteId = $(el).attr("data-note-id");
|
const noteId = $(el).attr("data-note-id");
|
||||||
|
|
||||||
this.loadIncludedNote(noteId, $(el));
|
this.loadIncludedNote(noteId, $(el));
|
||||||
@ -135,11 +140,11 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
mermaid.init(getMermaidConfig(), this.$content.find(".mermaid-diagram"));
|
mermaid.init(getMermaidConfig(), this.$content.find(".mermaid-diagram"));
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshIncludedNoteEvent({ noteId }) {
|
async refreshIncludedNoteEvent({ noteId }: EventData<"refreshIncludedNote">) {
|
||||||
this.refreshIncludedNote(this.$content, noteId);
|
this.refreshIncludedNote(this.$content, noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeWithContentElementEvent({ resolve, ntxId }) {
|
async executeWithContentElementEvent({ resolve, ntxId }: EventData<"executeWithContentElement">) {
|
||||||
if (!this.isNoteContext(ntxId)) {
|
if (!this.isNoteContext(ntxId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user