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/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)); 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..5a69f6f --- /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: ["meta", ","], + 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..89374bf --- /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: ["meta", "."], + action: (editor: Editor) => + extendMarkRangeIfUnselected(editor, "superscript").toggleSuperscript().run(), + disabled: (editor: Editor) => + !editor.can().chain().focus().toggleSuperscript().run(), + active: (editor: Editor) => editor.isActive("superscript"), +});