From e280968271e253e5cded3f6dc872405c44f97c09 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 19 Jun 2025 18:53:39 +0300 Subject: [PATCH] feat(ckeditor): allow use of GPL license --- .../widgets/type_widgets/ckeditor/config.ts | 21 ++++++++++++++++--- .../Note Types/Text/Premium features.md | 4 +++- packages/ckeditor5/src/index.ts | 2 +- packages/ckeditor5/src/plugins.ts | 7 +++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/ckeditor/config.ts b/apps/client/src/widgets/type_widgets/ckeditor/config.ts index 771a0ea33..809354e22 100644 --- a/apps/client/src/widgets/type_widgets/ckeditor/config.ts +++ b/apps/client/src/widgets/type_widgets/ckeditor/config.ts @@ -8,6 +8,9 @@ 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"; +import { PREMIUM_PLUGINS } from "../../../../../../packages/ckeditor5/src/plugins.js"; + +const OPEN_SOURCE_LICENSE_KEY = "GPL"; const TEXT_FORMATTING_GROUP = { label: "Text formatting", @@ -15,8 +18,11 @@ const TEXT_FORMATTING_GROUP = { }; export async function buildConfig(): Promise { - return { - licenseKey: getLicenseKey(), + const licenseKey = getLicenseKey(); + const hasPremiumLicense = (licenseKey !== OPEN_SOURCE_LICENSE_KEY); + + const config: EditorConfig = { + licenseKey, image: { styles: { options: [ @@ -134,6 +140,15 @@ export async function buildConfig(): Promise { // This value must be kept in sync with the language defined in webpack.config.js. language: "en" }; + + // Enable premium plugins. + if (hasPremiumLicense) { + config.extraPlugins = [ + ...PREMIUM_PLUGINS + ]; + } + + return config; } export function buildToolbarConfig(isClassicToolbar: boolean) { @@ -282,7 +297,7 @@ function getLicenseKey() { const premiumLicenseKey = import.meta.env.VITE_CKEDITOR_KEY; if (!premiumLicenseKey) { logError("CKEditor license key is not set, premium features will not be available."); - return "GPL"; + return OPEN_SOURCE_LICENSE_KEY; } return premiumLicenseKey; diff --git a/docs/User Guide/User Guide/Note Types/Text/Premium features.md b/docs/User Guide/User Guide/Note Types/Text/Premium features.md index 1e2dd43e2..5777f59c0 100644 --- a/docs/User Guide/User Guide/Note Types/Text/Premium features.md +++ b/docs/User Guide/User Guide/Note Types/Text/Premium features.md @@ -9,4 +9,6 @@ The license key is stored in the application and it enables the use of the previ ## Can I opt out of these features? -At this moment there is no way to disable this features, apart from manually modifying the source code. If this is a problem, [let us know](../../Troubleshooting/Reporting%20issues.md). \ No newline at end of file +At this moment there is no way to disable these features, apart from manually modifying the source code. If this is a problem, [let us know](../../Troubleshooting/Reporting%20issues.md). + +If you have the possibility of rebuilding the source code (e.g. if a package maintainer), then modify `VITE_CKEDITOR_KEY` in `apps/client/.env` to be `GPL`. \ No newline at end of file diff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.ts index 932c12d1d..1bdaed5be 100644 --- a/packages/ckeditor5/src/index.ts +++ b/packages/ckeditor5/src/index.ts @@ -1,6 +1,6 @@ import "ckeditor5/ckeditor5.css"; import "./theme/code_block_toolbar.css"; -import { COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins"; +import { COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS, PREMIUM_PLUGINS } from "./plugins"; import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } from "ckeditor5"; import "./translation_overrides.js"; export { EditorWatchdog } from "ckeditor5"; diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts index 1911c9e64..fae78f40b 100644 --- a/packages/ckeditor5/src/plugins.ts +++ b/packages/ckeditor5/src/plugins.ts @@ -1,4 +1,4 @@ -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, Notification } from "ckeditor5"; import { SlashCommand, Template } from "ckeditor5-premium-features"; import type { Plugin } from "ckeditor5"; import CutToNotePlugin from "./plugins/cuttonote.js"; @@ -148,8 +148,7 @@ export const COMMON_PLUGINS: typeof Plugin[] = [ Emoji, ...TRILIUM_PLUGINS, - ...EXTERNAL_PLUGINS, - ...PREMIUM_PLUGINS + ...EXTERNAL_PLUGINS ]; /** @@ -157,5 +156,5 @@ export const COMMON_PLUGINS: typeof Plugin[] = [ */ export const POPUP_EDITOR_PLUGINS: typeof Plugin[] = [ ...COMMON_PLUGINS, - BlockToolbar + BlockToolbar, ];