mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
chore(client/ts): port editable_text
This commit is contained in:
parent
1f69259a93
commit
5b82b750dc
64
src/public/app/types.d.ts
vendored
64
src/public/app/types.d.ts
vendored
@ -176,17 +176,50 @@ declare global {
|
|||||||
}>
|
}>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface CKCodeBlockLanguage {
|
||||||
|
language: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CKWatchdog {
|
||||||
|
constructor(editorClass: CKEditorInstance, opts: {
|
||||||
|
minimumNonErrorTimePeriod: number;
|
||||||
|
crashNumberLimit: number,
|
||||||
|
saveInterval: number
|
||||||
|
});
|
||||||
|
on(event: string, callback: () => void);
|
||||||
|
state: string;
|
||||||
|
crashes: unknown[];
|
||||||
|
editor: TextEditor;
|
||||||
|
setCreator(callback: (elementOrData, editorConfig) => void);
|
||||||
|
create(el: HTMLElement, opts: {
|
||||||
|
placeholder: string,
|
||||||
|
mention: MentionConfig,
|
||||||
|
codeBlock: {
|
||||||
|
languages: CKCodeBlockLanguage[]
|
||||||
|
},
|
||||||
|
math: {
|
||||||
|
engine: string,
|
||||||
|
outputType: string,
|
||||||
|
lazyLoad: () => Promise<void>,
|
||||||
|
forceOutputType: boolean,
|
||||||
|
enablePreview: boolean
|
||||||
|
},
|
||||||
|
mermaid: {
|
||||||
|
lazyLoad: () => Promise<void>,
|
||||||
|
config: MermaidConfig
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var CKEditor: {
|
var CKEditor: {
|
||||||
BalloonEditor: {
|
BalloonEditor: CKEditorInstance;
|
||||||
create(el: HTMLElement, config: {
|
DecoupledEditor: CKEditorInstance;
|
||||||
removePlugins?: string[];
|
EditorWatchdog: typeof CKWatchdog;
|
||||||
toolbar: {
|
};
|
||||||
items: any[];
|
|
||||||
},
|
var CKEditorInspector: {
|
||||||
placeholder: string;
|
attach(editor: TextEditor);
|
||||||
mention: MentionConfig
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var CodeMirror: {
|
var CodeMirror: {
|
||||||
@ -257,6 +290,7 @@ declare global {
|
|||||||
setAttribute(name: string, value: string, el: TextEditorElement);
|
setAttribute(name: string, value: string, el: TextEditorElement);
|
||||||
createPositionAt(el: TextEditorElement, opt?: "end");
|
createPositionAt(el: TextEditorElement, opt?: "end");
|
||||||
setSelection(pos: number, pos?: number);
|
setSelection(pos: number, pos?: number);
|
||||||
|
insertText(text: string, opts: Record<string, unknown> | undefined, position?: TextPosition);
|
||||||
}
|
}
|
||||||
interface TextNode {
|
interface TextNode {
|
||||||
previousSibling?: TextNode;
|
previousSibling?: TextNode;
|
||||||
@ -275,6 +309,15 @@ declare global {
|
|||||||
compareWith(pos: TextPosition): string;
|
compareWith(pos: TextPosition): string;
|
||||||
}
|
}
|
||||||
interface TextEditor {
|
interface TextEditor {
|
||||||
|
create(el: HTMLElement, config: {
|
||||||
|
removePlugins?: string[];
|
||||||
|
toolbar: {
|
||||||
|
items: any[];
|
||||||
|
},
|
||||||
|
placeholder: string;
|
||||||
|
mention: MentionConfig
|
||||||
|
});
|
||||||
|
enableReadOnlyMode(reason: string);
|
||||||
model: {
|
model: {
|
||||||
document: {
|
document: {
|
||||||
on(event: string, cb: () => void);
|
on(event: string, cb: () => void);
|
||||||
@ -308,6 +351,7 @@ declare global {
|
|||||||
}
|
}
|
||||||
change(cb: (writer: Writer) => void);
|
change(cb: (writer: Writer) => void);
|
||||||
scrollToTheSelection(): void;
|
scrollToTheSelection(): void;
|
||||||
|
focus(): void;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
|
@ -16,14 +16,15 @@ import toast from "../../services/toast.js";
|
|||||||
import { getMermaidConfig } from "../mermaid.js";
|
import { getMermaidConfig } from "../mermaid.js";
|
||||||
import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js";
|
import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js";
|
||||||
import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js";
|
import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
const ENABLE_INSPECTOR = false;
|
const ENABLE_INSPECTOR = false;
|
||||||
|
|
||||||
const mentionSetup = {
|
const mentionSetup: MentionConfig = {
|
||||||
feeds: [
|
feeds: [
|
||||||
{
|
{
|
||||||
marker: "@",
|
marker: "@",
|
||||||
feed: (queryText) => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
|
feed: (queryText: string) => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
|
||||||
itemRenderer: (item) => {
|
itemRenderer: (item) => {
|
||||||
const itemElement = document.createElement("button");
|
const itemElement = document.createElement("button");
|
||||||
|
|
||||||
@ -118,6 +119,12 @@ function buildListOfLanguages() {
|
|||||||
* - Decoupled mode, in which the editing toolbar is actually added on the client side (in {@link ClassicEditorToolbar}), see https://ckeditor.com/docs/ckeditor5/latest/examples/framework/bottom-toolbar-editor.html for an example on how the decoupled editor works.
|
* - Decoupled mode, in which the editing toolbar is actually added on the client side (in {@link ClassicEditorToolbar}), see https://ckeditor.com/docs/ckeditor5/latest/examples/framework/bottom-toolbar-editor.html for an example on how the decoupled editor works.
|
||||||
*/
|
*/
|
||||||
export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
||||||
|
|
||||||
|
private contentLanguage?: string | null;
|
||||||
|
private watchdog!: CKWatchdog;
|
||||||
|
|
||||||
|
private $editor!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "editableText";
|
return "editableText";
|
||||||
}
|
}
|
||||||
@ -195,7 +202,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const contentLanguage = this.note.getLabelValue("language");
|
const contentLanguage = this.note?.getLabelValue("language");
|
||||||
if (contentLanguage) {
|
if (contentLanguage) {
|
||||||
finalConfig.language = {
|
finalConfig.language = {
|
||||||
ui: (typeof finalConfig.language === "string" ? finalConfig.language : "en"),
|
ui: (typeof finalConfig.language === "string" ? finalConfig.language : "en"),
|
||||||
@ -277,7 +284,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
async doRefresh(note: FNote) {
|
||||||
const blob = await note.getBlob();
|
const blob = await note.getBlob();
|
||||||
|
|
||||||
await this.spacedUpdate.allowUpdateWithoutChange(async () => {
|
await this.spacedUpdate.allowUpdateWithoutChange(async () => {
|
||||||
@ -334,7 +341,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
this.addTextToEditor(dateString);
|
this.addTextToEditor(dateString);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addLinkToEditor(linkHref, linkTitle) {
|
async addLinkToEditor(linkHref: string, linkTitle: string) {
|
||||||
await this.initialized;
|
await this.initialized;
|
||||||
|
|
||||||
this.watchdog.editor.model.change((writer) => {
|
this.watchdog.editor.model.change((writer) => {
|
||||||
@ -343,7 +350,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async addTextToEditor(text) {
|
async addTextToEditor(text: string) {
|
||||||
await this.initialized;
|
await this.initialized;
|
||||||
|
|
||||||
this.watchdog.editor.model.change((writer) => {
|
this.watchdog.editor.model.change((writer) => {
|
Loading…
x
Reference in New Issue
Block a user