From 6e020ee1f30c7b5705bd290af9eba54638cdffc7 Mon Sep 17 00:00:00 2001 From: Benjamin VIELLARD Date: Thu, 11 Jul 2024 23:56:57 +0200 Subject: [PATCH 1/3] add subscript and superscript extensions --- package-lock.json | 30 +++++++++++++++++++++++++-- package.json | 2 ++ shared/extensions.ts | 4 ++++ src/interface/i18n/custom-messages.ts | 2 ++ src/interface/tools/index.ts | 4 ++++ src/interface/tools/subscript.ts | 19 +++++++++++++++++ src/interface/tools/superscript.ts | 19 +++++++++++++++++ 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/interface/tools/subscript.ts create mode 100644 src/interface/tools/superscript.ts diff --git a/package-lock.json b/package-lock.json index ba59fc8..45b3228 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "directus-extension-flexible-editor", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "directus-extension-flexible-editor", - "version": "1.6.0", + "version": "1.6.1", "license": "GPL-3.0", "dependencies": { "@tiptap/core": "^2.2.4", @@ -30,6 +30,8 @@ "@tiptap/extension-paragraph": "^2.2.4", "@tiptap/extension-placeholder": "^2.2.4", "@tiptap/extension-strike": "^2.2.4", + "@tiptap/extension-subscript": "^2.2.4", + "@tiptap/extension-superscript": "^2.2.4", "@tiptap/extension-table": "^2.2.4", "@tiptap/extension-table-cell": "^2.2.4", "@tiptap/extension-table-header": "^2.2.4", @@ -1460,6 +1462,30 @@ "@tiptap/core": "^2.0.0" } }, + "node_modules/@tiptap/extension-subscript": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@tiptap/extension-subscript/-/extension-subscript-2.4.0.tgz", + "integrity": "sha512-exLSmSFmYN6AVww5oyroFL3KCwstT0U+ojvVhRD6DQ+Hc81d++lBKANfsWAcllXjZVGPWeMNdE66bV7oFCtQcQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "^2.0.0" + } + }, + "node_modules/@tiptap/extension-superscript": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@tiptap/extension-superscript/-/extension-superscript-2.4.0.tgz", + "integrity": "sha512-s+GsbbERNQCn/hyaw5/82y3wHQ7o5byc/eFAKYo1p3p5eESlDaHY/xVYPt3CGOX2TJWZalgSFEFqBVdTSI8mUQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "^2.0.0" + } + }, "node_modules/@tiptap/extension-table": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@tiptap/extension-table/-/extension-table-2.4.0.tgz", diff --git a/package.json b/package.json index 3c3667c..30991d4 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,8 @@ "@tiptap/extension-paragraph": "^2.2.4", "@tiptap/extension-placeholder": "^2.2.4", "@tiptap/extension-strike": "^2.2.4", + "@tiptap/extension-subscript": "^2.2.4", + "@tiptap/extension-superscript": "^2.2.4", "@tiptap/extension-table": "^2.2.4", "@tiptap/extension-table-cell": "^2.2.4", "@tiptap/extension-table-header": "^2.2.4", diff --git a/shared/extensions.ts b/shared/extensions.ts index 1c89e73..8ef2a79 100644 --- a/shared/extensions.ts +++ b/shared/extensions.ts @@ -17,6 +17,8 @@ import Bold from "@tiptap/extension-bold"; import Italic from "@tiptap/extension-italic"; import Strike from "@tiptap/extension-strike"; import Code from "@tiptap/extension-code"; +import { Subscript } from "@tiptap/extension-subscript"; +import { Superscript } from "@tiptap/extension-superscript"; import { Table } from "@tiptap/extension-table"; import { TableHeader } from "@tiptap/extension-table-header"; import { TableRow } from "@tiptap/extension-table-row"; @@ -40,6 +42,8 @@ export default [ Italic, Strike, Code, + Subscript, + Superscript, Table, TableHeader, TableRow, diff --git a/src/interface/i18n/custom-messages.ts b/src/interface/i18n/custom-messages.ts index 4766f99..532b53a 100644 --- a/src/interface/i18n/custom-messages.ts +++ b/src/interface/i18n/custom-messages.ts @@ -36,6 +36,8 @@ export default { italic: "$t:wysiwyg_options.italic", strike: "$t:wysiwyg_options.strikethrough", code: "Code", + subscript: "$t:wysiwyg_options.subscript", + superscript: "$t:wysiwyg_options.superscript", link: "$t:field_options.directus_roles.fields.link_name", unlink: "$t:wysiwyg_options.unlink", autolink: "Autolink", diff --git a/src/interface/tools/index.ts b/src/interface/tools/index.ts index 2bc245c..3a514cd 100644 --- a/src/interface/tools/index.ts +++ b/src/interface/tools/index.ts @@ -9,6 +9,8 @@ import bold from "./bold"; import italic from "./italic"; import strike from "./strike"; import code from "./code"; +import subscript from "./subscript"; +import superscript from "./superscript"; import link from "./link"; import hardBreak from "./hard-break"; import horizontalRule from "./horizontal-rule"; @@ -35,6 +37,8 @@ const tools: Tool[] = [ italic, strike, code, + subscript, + superscript, link.add, link.remove, link.auto, diff --git a/src/interface/tools/subscript.ts b/src/interface/tools/subscript.ts new file mode 100644 index 0000000..b4b407a --- /dev/null +++ b/src/interface/tools/subscript.ts @@ -0,0 +1,19 @@ +// https://tiptap.dev/api/marks/subscript + +import Subscript from "@tiptap/extension-subscript"; +import { defineTool, extendMarkRangeIfUnselected } from "../lib"; +import customMessages from "../i18n/custom-messages"; +import type { Editor } from "@tiptap/core"; + +export default defineTool({ + key: "subscript", + name: customMessages.tools.subscript, + icon: "subscript", + extension: [Subscript], + shortcut: [], + action: (editor: Editor) => + extendMarkRangeIfUnselected(editor, "subscript").toggleSubscript().run(), + disabled: (editor: Editor) => + !editor.can().chain().focus().toggleSubscript().run(), + active: (editor: Editor) => editor.isActive("subscript"), +}); diff --git a/src/interface/tools/superscript.ts b/src/interface/tools/superscript.ts new file mode 100644 index 0000000..aa45409 --- /dev/null +++ b/src/interface/tools/superscript.ts @@ -0,0 +1,19 @@ +// https://tiptap.dev/api/marks/superscript + +import Superscript from "@tiptap/extension-superscript"; +import { defineTool, extendMarkRangeIfUnselected } from "../lib"; +import customMessages from "../i18n/custom-messages"; +import type { Editor } from "@tiptap/core"; + +export default defineTool({ + key: "superscript", + name: customMessages.tools.superscript, + icon: "superscript", + extension: [Superscript], + shortcut: [], + action: (editor: Editor) => + extendMarkRangeIfUnselected(editor, "superscript").toggleSuperscript().run(), + disabled: (editor: Editor) => + !editor.can().chain().focus().toggleSuperscript().run(), + active: (editor: Editor) => editor.isActive("superscript"), +}); From 9e72a4b4f0bbfdc3541446195898d04a600ebe2a Mon Sep 17 00:00:00 2001 From: Benjamin VIELLARD Date: Fri, 12 Jul 2024 16:08:26 +0200 Subject: [PATCH 2/3] add subscript and superscript shortcuts --- src/interface/tools/subscript.ts | 2 +- src/interface/tools/superscript.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface/tools/subscript.ts b/src/interface/tools/subscript.ts index b4b407a..5a69f6f 100644 --- a/src/interface/tools/subscript.ts +++ b/src/interface/tools/subscript.ts @@ -10,7 +10,7 @@ export default defineTool({ name: customMessages.tools.subscript, icon: "subscript", extension: [Subscript], - shortcut: [], + shortcut: ["meta", ","], action: (editor: Editor) => extendMarkRangeIfUnselected(editor, "subscript").toggleSubscript().run(), disabled: (editor: Editor) => diff --git a/src/interface/tools/superscript.ts b/src/interface/tools/superscript.ts index aa45409..89374bf 100644 --- a/src/interface/tools/superscript.ts +++ b/src/interface/tools/superscript.ts @@ -10,7 +10,7 @@ export default defineTool({ name: customMessages.tools.superscript, icon: "superscript", extension: [Superscript], - shortcut: [], + shortcut: ["meta", "."], action: (editor: Editor) => extendMarkRangeIfUnselected(editor, "superscript").toggleSuperscript().run(), disabled: (editor: Editor) => From bc258f4fea475fbd879ae7cc6a5710ca60c21de5 Mon Sep 17 00:00:00 2001 From: formfcw Date: Tue, 23 Jul 2024 13:45:51 +0200 Subject: [PATCH 3/3] add styles --- src/interface/interface.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/interface/interface.vue b/src/interface/interface.vue index e7dce8e..d78a255 100644 --- a/src/interface/interface.vue +++ b/src/interface/interface.vue @@ -391,6 +391,12 @@ border-radius: var(--theme--border-radius, var(--border-radius)); } + .flexible-editor :deep(sub), + .flexible-editor :deep(sup) { + font-size: 0.75em; + line-height: 1em; + } + .flexible-editor :deep(pre) { background-color: var(--theme--background-normal, var(--background-normal)); padding: var(--theme--form--field--input--padding, var(--input-padding));