Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Text snippets #2344

Merged
merged 16 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(text-snippets): basic integration
  • Loading branch information
eliandoran committed Jun 17, 2025
commit af8a9051507391231d566fab5545e8de41b6826a
6 changes: 5 additions & 1 deletion apps/client/src/widgets/type_widgets/ckeditor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { ensureMimeTypesForHighlighting, isSyntaxHighlightEnabled } from "../../
import utils from "../../../services/utils.js";
import emojiDefinitionsUrl from "@triliumnext/ckeditor5/emoji_definitions/en.json?url";
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
import getTemplates from "./snippets.js";

const TEXT_FORMATTING_GROUP = {
label: "Text formatting",
icon: "text"
};

export function buildConfig(): EditorConfig {
export async function buildConfig(): Promise<EditorConfig> {
return {
image: {
styles: {
Expand Down Expand Up @@ -126,6 +127,9 @@ export function buildConfig(): EditorConfig {
dropdownLimit: Number.MAX_SAFE_INTEGER,
extraCommands: buildExtraCommands()
},
template: {
definitions: await getTemplates()
},
// This value must be kept in sync with the language defined in webpack.config.js.
language: "en"
};
Expand Down
19 changes: 19 additions & 0 deletions apps/client/src/widgets/type_widgets/ckeditor/snippets.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion apps/client/src/widgets/type_widgets/editable_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {

const finalConfig = {
...editorConfig,
...buildConfig(),
...(await buildConfig()),
...buildToolbarConfig(isClassicEditor),
htmlSupport: {
allow: JSON.parse(options.get("allowedHtmlTags")),
Expand Down
1 change: 1 addition & 0 deletions packages/ckeditor5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins";
import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } from "ckeditor5";
export { EditorWatchdog } 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";

// Import with sideffects to ensure that type augmentations are present.
Expand Down
5 changes: 3 additions & 2 deletions packages/ckeditor5/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -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 { SlashCommand } from "ckeditor5-premium-features";
import { SlashCommand, Template } from "ckeditor5-premium-features";
import type { Plugin } from "ckeditor5";
import CutToNotePlugin from "./plugins/cuttonote.js";
import UploadimagePlugin from "./plugins/uploadimage.js";
Expand Down Expand Up @@ -82,7 +82,8 @@ export const CORE_PLUGINS: typeof Plugin[] = [
* Plugins that require a premium CKEditor license key to work.
*/
export const PREMIUM_PLUGINS: typeof Plugin[] = [
SlashCommand
SlashCommand,
Template
];

/**
Expand Down