Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(ckeditor5/plugins): integrate reference link
Elian Doran2dcd37001f2c
diff --git a/packages/ckeditor5/package.json b/packages/ckeditor5/package.jsonindex 5df27403c9..87ad7b3f46 100644--- a/packages/ckeditor5/package.json+++ b/packages/ckeditor5/package.json@@ -20,5 +20,8 @@},"dependencies": {"ckeditor5": "43.2.0"+ },+ "devDependencies": {+ "@types/jquery": "3.5.32"}}diff --git a/packages/ckeditor5/src/augmentation.ts b/packages/ckeditor5/src/augmentation.tsindex b596592558..4c22bc498d 100644--- a/packages/ckeditor5/src/augmentation.ts+++ b/packages/ckeditor5/src/augmentation.ts@@ -1,14 +1,22 @@import "ckeditor5";declare global {+ interface Component {+ triggerCommand(command: string): void;+ }++ interface EditorComponent extends Component {+ loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string): Promise<void>;+ }+var glob: {- getComponentByEl(el: unknown): {- triggerCommand(command: string): void;- };+ getComponentByEl<T extends Component>(el: unknown): T;getActiveContextNote(): {noteId: string;};getHeaders(): Promise<Record<string, string>>;+ getReferenceLinkTitle(href: string): Promise<string>;+ getReferenceLinkTitleSync(href: string): string;}}diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.tsindex 0fb1c7d0ba..ef0f15e0ec 100644--- a/packages/ckeditor5/src/plugins.ts+++ b/packages/ckeditor5/src/plugins.ts@@ -5,11 +5,13 @@ import UploadimagePlugin from "./plugins/uploadimage.js";import ItalicAsEmPlugin from "./plugins/italic_as_em.js";import StrikethroughAsDel from "./plugins/strikethrough_as_del.js";import InternalLinkPlugin from "./plugins/internallink.js";+import ReferenceLink from "./plugins/referencelink.js";const TRILIUM_PLUGINS: typeof Plugin[] = [CutToNotePlugin,ItalicAsEmPlugin,StrikethroughAsDel,+ ReferenceLink,UploadimagePlugin,InternalLinkPlugin];@@ -71,7 +73,6 @@ export const COMMON_PLUGINS: typeof Plugin[] = [// MarkdownImportPlugin,// MentionCustomization,// IncludeNote,- // ReferenceLink,// indentBlockShortcutPlugin,// removeFormatLinksPlugin,PageBreak,diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.tsindex 16928d3453..895de239ac 100644--- a/packages/ckeditor5/src/plugins/internallink.ts+++ b/packages/ckeditor5/src/plugins/internallink.ts@@ -1,7 +1,13 @@import { ButtonView, Plugin } from 'ckeditor5';import internalLinkIcon from '../icons/trilium.svg?raw';+import ReferenceLink from './referencelink';export default class InternalLinkPlugin extends Plugin {++ static get requires() {+ return [ ReferenceLink ];+ }+init() {const editor = this.editor;diff --git a/_regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/referencelink.js b/packages/ckeditor5/src/plugins/referencelink.tssimilarity index 85%rename from _regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/referencelink.jsrename to packages/ckeditor5/src/plugins/referencelink.tsindex 21b7b76cfd..47662940bf 100644--- a/_regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/referencelink.js+++ b/packages/ckeditor5/src/plugins/referencelink.ts@@ -1,7 +1,4 @@-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';-import { toWidget, viewToModelPositionOutsideModelElement } from '@ckeditor/ckeditor5-widget/src/utils';-import Widget from '@ckeditor/ckeditor5-widget/src/widget';-import Command from '@ckeditor/ckeditor5-core/src/command';+import { Command, Element, Plugin, toWidget, viewToModelPositionOutsideModelElement, Widget } from "ckeditor5";export default class ReferenceLink extends Plugin {static get requires() {@@ -10,7 +7,8 @@ export default class ReferenceLink extends Plugin {}class ReferenceLinkCommand extends Command {- execute( { href } ) {++ execute({ href }: { href: string }) {if (!href?.trim()) {return;}@@ -34,8 +32,7 @@ class ReferenceLinkCommand extends Command {refresh() {const model = this.editor.model;const selection = model.document.selection;-- this.isEnabled = model.schema.checkChild(selection.focus.parent, 'reference');+ this.isEnabled = selection.focus !== null && model.schema.checkChild(selection.focus.parent as Element, 'reference');}}@@ -92,7 +89,7 @@ class ReferenceLinkEditing extends Plugin {conversion.for( 'editingDowncast' ).elementToElement( {model: 'reference',view: ( modelItem, { writer: viewWriter } ) => {- const href = modelItem.getAttribute( 'href' );+ const href = modelItem.getAttribute('href') as string;const referenceLinkView = viewWriter.createContainerElement( 'a', {href,@@ -106,7 +103,7 @@ class ReferenceLinkEditing extends Plugin {const domElement = this.toDomElement( domDocument );const editorEl = editor.editing.view.getDomRoot();- const component = glob.getComponentByEl(editorEl);+ const component = glob.getComponentByEl<EditorComponent>(editorEl);component.loadReferenceLinkTitle($(domElement), href);@@ -123,7 +120,7 @@ class ReferenceLinkEditing extends Plugin {conversion.for( 'dataDowncast' ).elementToElement( {model: 'reference',view: ( modelItem, { writer: viewWriter } ) => {- const href = modelItem.getAttribute( 'href' );+ const href = modelItem.getAttribute('href') as string;const referenceLinkView = viewWriter.createContainerElement( 'a', {href: href,diff --git a/packages/ckeditor5/tsconfig.lib.json b/packages/ckeditor5/tsconfig.lib.jsonindex 360e0c0235..db3c5b0364 100644--- a/packages/ckeditor5/tsconfig.lib.json+++ b/packages/ckeditor5/tsconfig.lib.json@@ -11,7 +11,8 @@"forceConsistentCasingInFileNames": true,"lib": ["DOM", "ES2015"],"types": [- "vite/client"+ "vite/client",+ "jquery"]},"include": [diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f5dc6214e5..755ff75dba 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -374,7 +374,7 @@ importers:version: 1.0.2copy-webpack-plugin:specifier: 13.0.0- version: 13.0.0([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]))+ version: 13.0.0([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected])))electron:specifier: 35.2.2version: 35.2.2@@ -430,7 +430,7 @@ importers:version: 11.0.4copy-webpack-plugin:specifier: 13.0.0- version: 13.0.0([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]))+ version: 13.0.0([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected])))electron:specifier: 35.2.2version: 35.2.2@@ -608,7 +608,7 @@ importers:version: 1.4.7copy-webpack-plugin:specifier: 13.0.0- version: 13.0.0([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]))+ version: 13.0.0([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected])))csrf-csrf:specifier: 3.2.2version: 3.2.2@@ -779,7 +779,7 @@ importers:version: 1.0.1webpack:specifier: 5.99.7- version: 5.99.7(@swc/[email protected](@swc/[email protected]))([email protected])([email protected])+ version: 5.99.7(@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected]))ws:specifier: 8.18.1version: 8.18.1([email protected])([email protected])@@ -801,6 +801,10 @@ importers:ckeditor5:specifier: 43.2.0version: 43.2.0+ devDependencies:+ '@types/jquery':+ specifier: 3.5.32+ version: 3.5.32packages/commons:dependencies:@@ -16953,14 +16957,14 @@ snapshots:serialize-javascript: 6.0.2webpack: 5.98.0(@swc/[email protected](@swc/[email protected]))([email protected])([email protected])- [email protected]([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected])):+ [email protected]([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected]))):dependencies:glob-parent: 6.0.2normalize-path: 3.0.0schema-utils: 4.3.2serialize-javascript: 6.0.2tinyglobby: 0.2.13- webpack: 5.99.7(@swc/[email protected](@swc/[email protected]))([email protected])([email protected])+ webpack: 5.99.7(@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected]))dependencies:@@ -22879,14 +22883,14 @@ snapshots:'@swc/core': 1.5.29(@swc/[email protected])esbuild: 0.25.3- [email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected])):+ [email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected]))):dependencies:'@jridgewell/trace-mapping': 0.3.25jest-worker: 27.5.1schema-utils: 4.3.2serialize-javascript: 6.0.2terser: 5.39.0- webpack: 5.99.7(@swc/[email protected](@swc/[email protected]))([email protected])([email protected])+ webpack: 5.99.7(@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected]))optionalDependencies:'@swc/core': 1.5.29(@swc/[email protected])esbuild: 0.25.3@@ -23668,7 +23672,7 @@ snapshots:- esbuild- uglify-js- [email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]):+ [email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected])):dependencies:'@types/eslint-scope': 3.7.7'@types/estree': 1.0.7@@ -23691,7 +23695,7 @@ snapshots:neo-async: 2.6.2schema-utils: 4.3.2tapable: 2.2.1- terser-webpack-plugin: 5.3.14(@swc/[email protected](@swc/[email protected]))([email protected])([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]))+ terser-webpack-plugin: 5.3.14(@swc/[email protected](@swc/[email protected]))([email protected])([email protected](@swc/[email protected](@swc/[email protected]))([email protected])([email protected]([email protected])))watchpack: 2.4.2webpack-sources: 3.2.3optionalDependencies: