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

Commit 3b579a3

Browse files
authored
Slash commands (#2336)
2 parents 9cb227c + a4a5e0b commit 3b579a3

20 files changed

Lines changed: 2031 additions & 59 deletions

File tree

apps/client/.env.development

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VITE_CKEDITOR_ENABLE_INSPECTOR=false
2+
3+
# The development license key for premium CKEditor features.
4+
# Note: This key is for development purposes only and should not be used in production.
5+
# Expires on: 2025-09-13
6+
VITE_CKEDITOR_KEY=eyJhbGciOiJFUzI1NiJ9.eyJleHAiOjE3NTc3MjE1OTksImp0aSI6IjRmMjdkYmYxLTcwOTEtNDYwZi04ZDZmLTc0NzBiZjQwNjg2MCIsImRpc3RyaWJ1dGlvbkNoYW5uZWwiOlsic2giLCJkcnVwYWwiXSwid2hpdGVMYWJlbCI6dHJ1ZSwibGljZW5zZVR5cGUiOiJkZXZlbG9wbWVudCIsImZlYXR1cmVzIjpbIkRSVVAiLCJDTVQiLCJETyIsIkZQIiwiU0MiLCJUT0MiLCJUUEwiLCJQT0UiLCJDQyIsIk1GIiwiU0VFIiwiRUNIIiwiRUlTIl0sInZjIjoiMjMxYzMwNTEifQ.9Ct5lIKbioC3dM8EFatDTmimEIVOdItE3Uh_ICHlS_A_8ueqIfkZpsN3L4_EqprvteNki9yqbuZVGpZTaQ51xg

apps/client/.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_CKEDITOR_ENABLE_INSPECTOR=false

apps/client/src/services/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ async function openDialog($dialog: JQuery<HTMLElement>, closeActDialog = true) {
332332
}
333333
});
334334

335-
// TODO: Fix once keyboard_actions is ported.
336-
// @ts-ignore
337335
const keyboardActionsService = (await import("./keyboard_actions.js")).default;
338336
keyboardActionsService.updateDisplayedShortcuts($dialog);
339337

apps/client/src/stylesheets/style.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
--bs-body-font-weight: var(--main-font-weight) !important;
2626
--bs-body-color: var(--main-text-color) !important;
2727
--bs-body-bg: var(--main-background-color) !important;
28+
--ck-mention-list-max-height: 500px;
2829
}
2930

3031
.table {
@@ -1273,6 +1274,26 @@ body:not(.mobile) #launcher-pane.horizontal .dropdown-submenu > .dropdown-menu {
12731274
white-space: normal !important;
12741275
}
12751276

1277+
/* Slash commands */
1278+
1279+
.ck.ck-slash-command-button {
1280+
padding: 0.5em 1em !important;
1281+
}
1282+
1283+
.ck.ck-slash-command-button__text-part {
1284+
margin-left: 0.5em;
1285+
line-height: 1.2em !important;
1286+
}
1287+
1288+
.ck.ck-slash-command-button__text-part > span {
1289+
line-height: inherit !important;
1290+
}
1291+
1292+
.ck.ck-slash-command-button__text-part .ck.ck-slash-command-button__description {
1293+
display: block;
1294+
opacity: 0.8;
1295+
}
1296+
12761297
.area-expander {
12771298
display: flex;
12781299
flex-direction: row;

apps/client/src/stylesheets/theme-next/notes/text.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@
201201
color: var(--menu-item-icon-color);
202202
}
203203

204+
/* Slash commands */
205+
.ck.ck-slash-command-button__text-part .ck.ck-button__label {
206+
font-weight: bold;
207+
}
208+
204209
/* Separator */
205210
:root .ck .ck-list__separator {
206211
margin: .5em 0;

apps/client/src/vite-env.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference types="vite/client" />
2+
3+
interface ViteTypeOptions {
4+
strictImportMetaEnv: unknown
5+
}
6+
7+
interface ImportMetaEnv {
8+
/** The license key for CKEditor premium features. */
9+
readonly VITE_CKEDITOR_KEY?: string;
10+
/** Whether to enable the CKEditor inspector (see https://ckeditor.com/docs/ckeditor5/latest/framework/develpment-tools/inspector.html). */
11+
readonly VITE_CKEDITOR_ENABLE_INSPECTOR?: "true" | "false";
12+
}
13+
14+
interface ImportMeta {
15+
readonly env: ImportMetaEnv
16+
}

apps/client/src/widgets/dialogs/add_link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class AddLinkDialog extends BasicWidget {
111111

112112
this.updateTitleSettingsVisibility();
113113

114-
utils.openDialog(this.$widget);
114+
await utils.openDialog(this.$widget);
115115

116116
this.$autoComplete.val("");
117117
this.$linkTitle.val("");

apps/client/src/widgets/type_widgets/ckeditor/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ALLOWED_PROTOCOLS } from "../../../services/link.js";
22
import { MIME_TYPE_AUTO } from "@triliumnext/commons";
3-
import type { EditorConfig } from "@triliumnext/ckeditor5";
3+
import { buildExtraCommands, type EditorConfig } from "@triliumnext/ckeditor5";
44
import { getHighlightJsNameForMime } from "../../../services/mime_types.js";
55
import options from "../../../services/options.js";
66
import { ensureMimeTypesForHighlighting, isSyntaxHighlightEnabled } from "../../../services/syntax_highlight.js";
@@ -121,6 +121,11 @@ export function buildConfig(): EditorConfig {
121121
clipboard: {
122122
copy: copyTextWithToast
123123
},
124+
slashCommand: {
125+
removeCommands: [],
126+
dropdownLimit: Number.MAX_SAFE_INTEGER,
127+
extraCommands: buildExtraCommands()
128+
},
124129
// This value must be kept in sync with the language defined in webpack.config.js.
125130
language: "en"
126131
};

apps/client/src/widgets/type_widgets/editable_text.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import { PopupEditor, ClassicEditor, EditorWatchdog, type CKTextEditor, type Men
1919
import "@triliumnext/ckeditor5/index.css";
2020
import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons";
2121

22-
const ENABLE_INSPECTOR = false;
23-
2422
const mentionSetup: MentionFeed[] = [
2523
{
2624
marker: "@",
@@ -203,7 +201,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
203201
classes: true,
204202
attributes: true
205203
},
206-
licenseKey: "GPL"
204+
licenseKey: getLicenseKey()
207205
};
208206

209207
const contentLanguage = this.note?.getLabelValue("language");
@@ -278,7 +276,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
278276

279277
editor.model.document.on("change:data", () => this.spacedUpdate.scheduleUpdate());
280278

281-
if (glob.isDev && ENABLE_INSPECTOR) {
279+
if (import.meta.env.VITE_CKEDITOR_ENABLE_INSPECTOR === "true") {
282280
const CKEditorInspector = (await import("@ckeditor/ckeditor5-inspector")).default;
283281
CKEditorInspector.attach(editor);
284282
}
@@ -640,3 +638,13 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
640638
}
641639

642640
}
641+
642+
function getLicenseKey() {
643+
const premiumLicenseKey = import.meta.env.VITE_CKEDITOR_KEY;
644+
if (!premiumLicenseKey) {
645+
logError("CKEditor license key is not set, premium features will not be available.");
646+
return "GPL";
647+
}
648+
649+
return premiumLicenseKey;
650+
}

packages/ckeditor5-admonition/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import "../theme/blockquote.css";
44

55
export { default as Admonition } from './admonition.js';
66
export { default as AdmonitionEditing } from './admonitionediting.js';
7-
export { default as AdmonitionUI } from './admonitionui.js';
7+
export { default as AdmonitionUI, ADMONITION_TYPES } from './admonitionui.js';
88
export { default as AdmonitionAutoformat } from './admonitionautoformat.js';
9-
export type { default as AdmonitionCommand } from './admonitioncommand.js';
9+
export type { default as AdmonitionCommand, AdmonitionType } from './admonitioncommand.js';
1010

1111
export const icons = {
1212
admonitionIcon

0 commit comments

Comments
 (0)