mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(text-snippets): basic integration
This commit is contained in:
parent
3b579a3b7b
commit
af8a905150
@ -7,13 +7,14 @@ import { ensureMimeTypesForHighlighting, isSyntaxHighlightEnabled } from "../../
|
|||||||
import utils from "../../../services/utils.js";
|
import utils from "../../../services/utils.js";
|
||||||
import emojiDefinitionsUrl from "@triliumnext/ckeditor5/emoji_definitions/en.json?url";
|
import emojiDefinitionsUrl from "@triliumnext/ckeditor5/emoji_definitions/en.json?url";
|
||||||
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
|
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
|
||||||
|
import getTemplates from "./snippets.js";
|
||||||
|
|
||||||
const TEXT_FORMATTING_GROUP = {
|
const TEXT_FORMATTING_GROUP = {
|
||||||
label: "Text formatting",
|
label: "Text formatting",
|
||||||
icon: "text"
|
icon: "text"
|
||||||
};
|
};
|
||||||
|
|
||||||
export function buildConfig(): EditorConfig {
|
export async function buildConfig(): Promise<EditorConfig> {
|
||||||
return {
|
return {
|
||||||
image: {
|
image: {
|
||||||
styles: {
|
styles: {
|
||||||
@ -126,6 +127,9 @@ export function buildConfig(): EditorConfig {
|
|||||||
dropdownLimit: Number.MAX_SAFE_INTEGER,
|
dropdownLimit: Number.MAX_SAFE_INTEGER,
|
||||||
extraCommands: buildExtraCommands()
|
extraCommands: buildExtraCommands()
|
||||||
},
|
},
|
||||||
|
template: {
|
||||||
|
definitions: await getTemplates()
|
||||||
|
},
|
||||||
// This value must be kept in sync with the language defined in webpack.config.js.
|
// This value must be kept in sync with the language defined in webpack.config.js.
|
||||||
language: "en"
|
language: "en"
|
||||||
};
|
};
|
||||||
|
19
apps/client/src/widgets/type_widgets/ckeditor/snippets.ts
Normal file
19
apps/client/src/widgets/type_widgets/ckeditor/snippets.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import search from "../../../services/search";
|
||||||
|
import type { TemplateDefinition } from "@triliumnext/ckeditor5";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the list of snippets based on the user's notes to be passed down to the CKEditor configuration.
|
||||||
|
*
|
||||||
|
* @returns the list of templates.
|
||||||
|
*/
|
||||||
|
export default async function getTemplates() {
|
||||||
|
const definitions: TemplateDefinition[] = [];
|
||||||
|
const snippets = await search.searchForNotes("#textSnippet");
|
||||||
|
for (const snippet of snippets) {
|
||||||
|
definitions.push({
|
||||||
|
title: snippet.title,
|
||||||
|
data: await snippet.getContent() ?? ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return definitions;
|
||||||
|
}
|
@ -193,7 +193,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
|
|
||||||
const finalConfig = {
|
const finalConfig = {
|
||||||
...editorConfig,
|
...editorConfig,
|
||||||
...buildConfig(),
|
...(await buildConfig()),
|
||||||
...buildToolbarConfig(isClassicEditor),
|
...buildToolbarConfig(isClassicEditor),
|
||||||
htmlSupport: {
|
htmlSupport: {
|
||||||
allow: JSON.parse(options.get("allowedHtmlTags")),
|
allow: JSON.parse(options.get("allowedHtmlTags")),
|
||||||
|
@ -4,6 +4,7 @@ import { COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins";
|
|||||||
import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } from "ckeditor5";
|
import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } from "ckeditor5";
|
||||||
export { EditorWatchdog } from "ckeditor5";
|
export { EditorWatchdog } from "ckeditor5";
|
||||||
export type { EditorConfig, MentionFeed, MentionFeedObjectItem, Node, Position, Element, WatchdogConfig } from "ckeditor5";
|
export type { EditorConfig, MentionFeed, MentionFeedObjectItem, Node, Position, Element, WatchdogConfig } from "ckeditor5";
|
||||||
|
export type { TemplateDefinition } from "ckeditor5-premium-features";
|
||||||
export { default as buildExtraCommands } from "./extra_slash_commands.js";
|
export { default as buildExtraCommands } from "./extra_slash_commands.js";
|
||||||
|
|
||||||
// Import with sideffects to ensure that type augmentations are present.
|
// Import with sideffects to ensure that type augmentations are present.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Autoformat, AutoLink, BlockQuote, BlockToolbar, Bold, CKFinderUploadAdapter, Clipboard, Code, CodeBlock, Enter, FindAndReplace, Font, FontBackgroundColor, FontColor, GeneralHtmlSupport, Heading, HeadingButtonsUI, HorizontalLine, Image, ImageCaption, ImageInline, ImageResize, ImageStyle, ImageToolbar, ImageUpload, Alignment, Indent, IndentBlock, Italic, Link, List, ListProperties, Mention, PageBreak, Paragraph, ParagraphButtonUI, PasteFromOffice, PictureEditing, RemoveFormat, SelectAll, ShiftEnter, SpecialCharacters, SpecialCharactersEssentials, Strikethrough, Style, Subscript, Superscript, Table, TableCaption, TableCellProperties, TableColumnResize, TableProperties, TableSelection, TableToolbar, TextPartLanguage, TextTransformation, TodoList, Typing, Underline, Undo, Bookmark, Emoji } from "ckeditor5";
|
import { Autoformat, AutoLink, BlockQuote, BlockToolbar, Bold, CKFinderUploadAdapter, Clipboard, Code, CodeBlock, Enter, FindAndReplace, Font, FontBackgroundColor, FontColor, GeneralHtmlSupport, Heading, HeadingButtonsUI, HorizontalLine, Image, ImageCaption, ImageInline, ImageResize, ImageStyle, ImageToolbar, ImageUpload, Alignment, Indent, IndentBlock, Italic, Link, List, ListProperties, Mention, PageBreak, Paragraph, ParagraphButtonUI, PasteFromOffice, PictureEditing, RemoveFormat, SelectAll, ShiftEnter, SpecialCharacters, SpecialCharactersEssentials, Strikethrough, Style, Subscript, Superscript, Table, TableCaption, TableCellProperties, TableColumnResize, TableProperties, TableSelection, TableToolbar, TextPartLanguage, TextTransformation, TodoList, Typing, Underline, Undo, Bookmark, Emoji } from "ckeditor5";
|
||||||
import { SlashCommand } from "ckeditor5-premium-features";
|
import { SlashCommand, Template } from "ckeditor5-premium-features";
|
||||||
import type { Plugin } from "ckeditor5";
|
import type { Plugin } from "ckeditor5";
|
||||||
import CutToNotePlugin from "./plugins/cuttonote.js";
|
import CutToNotePlugin from "./plugins/cuttonote.js";
|
||||||
import UploadimagePlugin from "./plugins/uploadimage.js";
|
import UploadimagePlugin from "./plugins/uploadimage.js";
|
||||||
@ -82,7 +82,8 @@ export const CORE_PLUGINS: typeof Plugin[] = [
|
|||||||
* Plugins that require a premium CKEditor license key to work.
|
* Plugins that require a premium CKEditor license key to work.
|
||||||
*/
|
*/
|
||||||
export const PREMIUM_PLUGINS: typeof Plugin[] = [
|
export const PREMIUM_PLUGINS: typeof Plugin[] = [
|
||||||
SlashCommand
|
SlashCommand,
|
||||||
|
Template
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user