mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
chore(ckeditor5): integrate ckeditor5-admonition
This commit is contained in:
parent
b0169d58ae
commit
a494ff1169
@ -1,6 +1,5 @@
|
||||
import { Plugin, ButtonView } from 'ckeditor5';
|
||||
import { Plugin } from 'ckeditor5';
|
||||
|
||||
import admonitionIcon from '../theme/icons/admonition.svg';
|
||||
import AdmonitionEditing from './admonitionediting.js';
|
||||
import AdmonitionUI from './admonitionui.js';
|
||||
import AdmonitionAutoformat from './admonitionautoformat.js';
|
||||
@ -15,33 +14,4 @@ export default class Admonition extends Plugin {
|
||||
return 'Admonition' as const;
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
const editor = this.editor;
|
||||
const t = editor.t;
|
||||
const model = editor.model;
|
||||
|
||||
// Register the "admonition" button, so it can be displayed in the toolbar.
|
||||
editor.ui.componentFactory.add( 'admonition', locale => {
|
||||
const view = new ButtonView( locale );
|
||||
|
||||
view.set( {
|
||||
label: t( 'Admonition' ),
|
||||
icon: admonitionIcon,
|
||||
tooltip: true
|
||||
} );
|
||||
|
||||
// Insert a text into the editor after clicking the button.
|
||||
this.listenTo( view, 'execute', () => {
|
||||
model.change( writer => {
|
||||
const textNode = writer.createText( 'Hello CKEditor 5!' );
|
||||
|
||||
model.insertContent( textNode );
|
||||
} );
|
||||
|
||||
editor.editing.view.focus();
|
||||
} );
|
||||
|
||||
return view;
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ckeditor from './../theme/icons/ckeditor.svg';
|
||||
import admonitionIcon from '../theme/icons/admonition.svg';
|
||||
import './augmentation.js';
|
||||
import "../theme/blockquote.css";
|
||||
|
||||
@ -9,5 +9,5 @@ export { default as AdmonitionAutoformat } from './admonitionautoformat.js';
|
||||
export type { default as AdmonitionCommand } from './admonitioncommand.js';
|
||||
|
||||
export const icons = {
|
||||
ckeditor
|
||||
admonitionIcon
|
||||
};
|
||||
|
@ -1,56 +0,0 @@
|
||||
import { describe, expect, it, beforeEach, afterEach } from 'vitest';
|
||||
import { ClassicEditor, Essentials, Paragraph, Heading } from 'ckeditor5';
|
||||
import Admonition from '../src/admonition.js';
|
||||
|
||||
describe( 'Admonition', () => {
|
||||
it( 'should be named', () => {
|
||||
expect( Admonition.pluginName ).to.equal( 'Admonition' );
|
||||
} );
|
||||
|
||||
describe( 'init()', () => {
|
||||
let domElement: HTMLElement, editor: ClassicEditor;
|
||||
|
||||
beforeEach( async () => {
|
||||
domElement = document.createElement( 'div' );
|
||||
document.body.appendChild( domElement );
|
||||
|
||||
editor = await ClassicEditor.create( domElement, {
|
||||
licenseKey: 'GPL',
|
||||
plugins: [
|
||||
Paragraph,
|
||||
Heading,
|
||||
Essentials,
|
||||
Admonition
|
||||
],
|
||||
toolbar: [
|
||||
'admonition'
|
||||
]
|
||||
} );
|
||||
} );
|
||||
|
||||
afterEach( () => {
|
||||
domElement.remove();
|
||||
return editor.destroy();
|
||||
} );
|
||||
|
||||
it( 'should load Admonition', () => {
|
||||
const myPlugin = editor.plugins.get( 'Admonition' );
|
||||
|
||||
expect( myPlugin ).to.be.an.instanceof( Admonition );
|
||||
} );
|
||||
|
||||
it( 'should add an icon to the toolbar', () => {
|
||||
expect( editor.ui.componentFactory.has( 'admonition' ) ).to.equal( true );
|
||||
} );
|
||||
|
||||
it( 'should add a text into the editor after clicking the icon', () => {
|
||||
const icon = editor.ui.componentFactory.create( 'admonition' );
|
||||
|
||||
expect( editor.getData() ).to.equal( '' );
|
||||
|
||||
icon.fire( 'execute' );
|
||||
|
||||
expect( editor.getData() ).to.equal( '<p>Hello CKEditor 5!</p>' );
|
||||
} );
|
||||
} );
|
||||
} );
|
@ -1,17 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { Admonition as AdmonitionDll, icons } from '../src/index.js';
|
||||
import Admonition from '../src/admonition.js';
|
||||
|
||||
import ckeditor from './../theme/icons/ckeditor.svg';
|
||||
|
||||
describe( 'CKEditor5 Admonition DLL', () => {
|
||||
it( 'exports Admonition', () => {
|
||||
expect( AdmonitionDll ).to.equal( Admonition );
|
||||
} );
|
||||
|
||||
describe( 'icons', () => {
|
||||
it( 'exports the "ckeditor" icon', () => {
|
||||
expect( icons.ckeditor ).to.equal( ckeditor );
|
||||
} );
|
||||
} );
|
||||
} );
|
@ -17,6 +17,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitOverride": true,
|
||||
"composite": true,
|
||||
"strict": true,
|
||||
"target": "es2019",
|
||||
"sourceMap": true,
|
||||
|
@ -21,7 +21,8 @@
|
||||
"dependencies": {
|
||||
"ckeditor5": "43.2.0",
|
||||
"@triliumnext/ckeditor5-keyboard-marker": "workspace:*",
|
||||
"@triliumnext/ckeditor5-mermaid": "workspace:*"
|
||||
"@triliumnext/ckeditor5-mermaid": "workspace:*",
|
||||
"@triliumnext/ckeditor5-admonition": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jquery": "3.5.32"
|
||||
|
@ -15,8 +15,10 @@ import IncludeNote from "./plugins/includenote.js";
|
||||
import Uploadfileplugin from "./plugins/file_upload/uploadfileplugin.js";
|
||||
import { Kbd } from "@triliumnext/ckeditor5-keyboard-marker";
|
||||
import { Mermaid } from "@triliumnext/ckeditor5-mermaid";
|
||||
import { Admonition } from "@triliumnext/ckeditor5-admonition";
|
||||
|
||||
import "@triliumnext/ckeditor5-mermaid/index.css";
|
||||
import "@triliumnext/ckeditor5-admonition/index.css";
|
||||
|
||||
const TRILIUM_PLUGINS: typeof Plugin[] = [
|
||||
CutToNotePlugin,
|
||||
@ -36,7 +38,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
|
||||
|
||||
const EXTERNAL_PLUGINS: typeof Plugin[] = [
|
||||
Kbd,
|
||||
Mermaid
|
||||
Mermaid,
|
||||
Admonition
|
||||
];
|
||||
|
||||
export const COMMON_PLUGINS: typeof Plugin[] = [
|
||||
@ -102,8 +105,7 @@ export const COMMON_PLUGINS: typeof Plugin[] = [
|
||||
// External plugins
|
||||
// Math,
|
||||
// AutoformatMath,
|
||||
// Footnotes,
|
||||
// Admonition
|
||||
// Footnotes
|
||||
];
|
||||
|
||||
export const COMMON_SETTINGS = { };
|
||||
|
@ -3,6 +3,9 @@
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "../ckeditor5-admonition"
|
||||
},
|
||||
{
|
||||
"path": "../ckeditor5-mermaid"
|
||||
},
|
||||
|
@ -19,6 +19,9 @@
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../ckeditor5-admonition"
|
||||
},
|
||||
{
|
||||
"path": "../ckeditor5-mermaid"
|
||||
},
|
||||
|
87
pnpm-lock.yaml
generated
87
pnpm-lock.yaml
generated
@ -801,6 +801,9 @@ importers:
|
||||
|
||||
packages/ckeditor5:
|
||||
dependencies:
|
||||
'@triliumnext/ckeditor5-admonition':
|
||||
specifier: workspace:*
|
||||
version: link:../ckeditor5-admonition
|
||||
'@triliumnext/ckeditor5-keyboard-marker':
|
||||
specifier: workspace:*
|
||||
version: link:../ckeditor5-keyboard-marker
|
||||
@ -948,7 +951,7 @@ importers:
|
||||
version: 1.4.1(typescript@5.0.4)(vite@6.3.2(@types/node@22.15.3)(jiti@2.4.2)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)(tsx@4.19.4)(yaml@2.7.1))
|
||||
vitest:
|
||||
specifier: ^2.0.5
|
||||
version: 2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2(vitest@3.1.2))(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
version: 2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2)(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
webdriverio:
|
||||
specifier: ^9.0.7
|
||||
version: 9.12.7(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
@ -1024,7 +1027,7 @@ importers:
|
||||
version: 1.4.1(typescript@5.0.4)(vite@6.3.2(@types/node@22.15.3)(jiti@2.4.2)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)(tsx@4.19.4)(yaml@2.7.1))
|
||||
vitest:
|
||||
specifier: ^2.0.5
|
||||
version: 2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2(vitest@3.1.2))(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
version: 2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2)(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
webdriverio:
|
||||
specifier: ^9.0.7
|
||||
version: 9.12.7(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
@ -18815,7 +18818,7 @@ snapshots:
|
||||
msw: 2.7.5(@types/node@22.15.3)(typescript@5.0.4)
|
||||
sirv: 3.0.1
|
||||
tinyrainbow: 1.2.0
|
||||
vitest: 2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2(vitest@3.1.2))(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
vitest: 2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2)(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
ws: 8.18.1(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
optionalDependencies:
|
||||
playwright: 1.52.0
|
||||
@ -28808,45 +28811,6 @@ snapshots:
|
||||
tsx: 4.19.4
|
||||
yaml: 2.7.1
|
||||
|
||||
vitest@2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2(vitest@3.1.2))(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0):
|
||||
dependencies:
|
||||
'@vitest/expect': 2.1.9
|
||||
'@vitest/mocker': 2.1.9(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(vite@5.4.19(@types/node@22.15.3)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0))
|
||||
'@vitest/pretty-format': 2.1.9
|
||||
'@vitest/runner': 2.1.9
|
||||
'@vitest/snapshot': 2.1.9
|
||||
'@vitest/spy': 2.1.9
|
||||
'@vitest/utils': 2.1.9
|
||||
chai: 5.2.0
|
||||
debug: 4.4.0(supports-color@8.1.1)
|
||||
expect-type: 1.2.1
|
||||
magic-string: 0.30.17
|
||||
pathe: 1.1.2
|
||||
std-env: 3.9.0
|
||||
tinybench: 2.9.0
|
||||
tinyexec: 0.3.2
|
||||
tinypool: 1.0.2
|
||||
tinyrainbow: 1.2.0
|
||||
vite: 5.4.19(@types/node@22.15.3)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
vite-node: 2.1.9(@types/node@22.15.3)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
why-is-node-running: 2.3.0
|
||||
optionalDependencies:
|
||||
'@types/node': 22.15.3
|
||||
'@vitest/browser': 2.1.9(@types/node@22.15.3)(bufferutil@4.0.9)(playwright@1.52.0)(typescript@5.0.4)(utf-8-validate@6.0.5)(vite@6.3.2(@types/node@22.15.3)(jiti@2.4.2)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)(tsx@4.19.4)(yaml@2.7.1))(vitest@2.1.9)(webdriverio@9.12.7(bufferutil@4.0.9)(utf-8-validate@6.0.5))
|
||||
'@vitest/ui': 3.1.2(vitest@3.1.2)
|
||||
happy-dom: 17.4.6
|
||||
jsdom: 26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
transitivePeerDependencies:
|
||||
- less
|
||||
- lightningcss
|
||||
- msw
|
||||
- sass
|
||||
- sass-embedded
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
vitest@2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2)(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@7.0.39))(terser@5.39.0):
|
||||
dependencies:
|
||||
'@vitest/expect': 2.1.9
|
||||
@ -28886,6 +28850,45 @@ snapshots:
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
vitest@2.1.9(@types/node@22.15.3)(@vitest/browser@2.1.9)(@vitest/ui@3.1.2)(happy-dom@17.4.6)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0):
|
||||
dependencies:
|
||||
'@vitest/expect': 2.1.9
|
||||
'@vitest/mocker': 2.1.9(msw@2.7.5(@types/node@22.15.3)(typescript@5.0.4))(vite@5.4.19(@types/node@22.15.3)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0))
|
||||
'@vitest/pretty-format': 2.1.9
|
||||
'@vitest/runner': 2.1.9
|
||||
'@vitest/snapshot': 2.1.9
|
||||
'@vitest/spy': 2.1.9
|
||||
'@vitest/utils': 2.1.9
|
||||
chai: 5.2.0
|
||||
debug: 4.4.0(supports-color@8.1.1)
|
||||
expect-type: 1.2.1
|
||||
magic-string: 0.30.17
|
||||
pathe: 1.1.2
|
||||
std-env: 3.9.0
|
||||
tinybench: 2.9.0
|
||||
tinyexec: 0.3.2
|
||||
tinypool: 1.0.2
|
||||
tinyrainbow: 1.2.0
|
||||
vite: 5.4.19(@types/node@22.15.3)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
vite-node: 2.1.9(@types/node@22.15.3)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)
|
||||
why-is-node-running: 2.3.0
|
||||
optionalDependencies:
|
||||
'@types/node': 22.15.3
|
||||
'@vitest/browser': 2.1.9(@types/node@22.15.3)(bufferutil@4.0.9)(playwright@1.52.0)(typescript@5.0.4)(utf-8-validate@6.0.5)(vite@6.3.2(@types/node@22.15.3)(jiti@2.4.2)(less@4.1.3)(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)(tsx@4.19.4)(yaml@2.7.1))(vitest@2.1.9)(webdriverio@9.12.7(bufferutil@4.0.9)(utf-8-validate@6.0.5))
|
||||
'@vitest/ui': 3.1.2(vitest@3.1.2)
|
||||
happy-dom: 17.4.6
|
||||
jsdom: 26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
transitivePeerDependencies:
|
||||
- less
|
||||
- lightningcss
|
||||
- msw
|
||||
- sass
|
||||
- sass-embedded
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.3)(@vitest/ui@3.1.2)(happy-dom@17.4.6)(jiti@2.4.2)(jsdom@22.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(less@4.1.3)(msw@2.7.5(@types/node@22.15.3)(typescript@5.7.3))(sass-embedded@1.87.0)(sass@1.87.0)(stylus@0.64.0)(sugarss@4.0.1(postcss@8.5.3))(terser@5.39.0)(tsx@4.19.4)(yaml@2.7.1):
|
||||
dependencies:
|
||||
'@vitest/expect': 3.1.2
|
||||
|
@ -41,6 +41,9 @@
|
||||
},
|
||||
{
|
||||
"path": "./packages/ckeditor5-mermaid"
|
||||
},
|
||||
{
|
||||
"path": "./packages/ckeditor5-admonition"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user