Skip to content

Commit

Permalink
Merge pull request #46 from gbicou/subscript-superscript-extensions
Browse files Browse the repository at this point in the history
add subscript and superscript extensions
formfcw authored Jul 23, 2024
2 parents 0980a9a + bc258f4 commit 5606bfc
Showing 8 changed files with 84 additions and 2 deletions.
30 changes: 28 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
4 changes: 4 additions & 0 deletions shared/extensions.ts
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 2 additions & 0 deletions src/interface/i18n/custom-messages.ts
Original file line number Diff line number Diff line change
@@ -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",
6 changes: 6 additions & 0 deletions src/interface/interface.vue
Original file line number Diff line number Diff line change
@@ -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));
4 changes: 4 additions & 0 deletions src/interface/tools/index.ts
Original file line number Diff line number Diff line change
@@ -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,
19 changes: 19 additions & 0 deletions src/interface/tools/subscript.ts
Original file line number Diff line number Diff line change
@@ -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"),
});
19 changes: 19 additions & 0 deletions src/interface/tools/superscript.ts
Original file line number Diff line number Diff line change
@@ -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"),
});

0 comments on commit 5606bfc

Please sign in to comment.