Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TextAlign tool #38

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions package-lock.json

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

55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"devDependencies": {
"@directus/extensions-sdk": "11.0.1",
"@directus/utils": "^11.0.4",
"@tiptap/pm": "^2.2.2",
"@tiptap/vue-3": "^2.2.2",
"@tiptap/pm": "^2.2.4",
"@tiptap/vue-3": "^2.2.4",
"@types/lodash": "^4.14.195",
"@types/node": "^20.11.17",
"@types/uuid": "^9.0.2",
Expand All @@ -80,31 +80,32 @@
"vue-i18n": "^9.4.0"
},
"dependencies": {
"@tiptap/core": "^2.2.2",
"@tiptap/extension-blockquote": "^2.2.2",
"@tiptap/extension-bold": "^2.2.2",
"@tiptap/extension-bullet-list": "^2.2.2",
"@tiptap/extension-code": "^2.2.2",
"@tiptap/extension-code-block": "^2.2.2",
"@tiptap/extension-document": "^2.2.2",
"@tiptap/extension-dropcursor": "^2.2.2",
"@tiptap/extension-gapcursor": "^2.2.2",
"@tiptap/extension-hard-break": "^2.2.2",
"@tiptap/extension-heading": "^2.2.2",
"@tiptap/extension-history": "^2.2.2",
"@tiptap/extension-horizontal-rule": "^2.2.2",
"@tiptap/extension-italic": "^2.2.2",
"@tiptap/extension-link": "^2.2.2",
"@tiptap/extension-list-item": "^2.2.2",
"@tiptap/extension-ordered-list": "^2.2.2",
"@tiptap/extension-paragraph": "^2.2.2",
"@tiptap/extension-placeholder": "^2.2.2",
"@tiptap/extension-strike": "^2.2.2",
"@tiptap/extension-table": "^2.2.2",
"@tiptap/extension-table-cell": "^2.2.2",
"@tiptap/extension-table-header": "^2.2.2",
"@tiptap/extension-table-row": "^2.2.2",
"@tiptap/extension-text": "^2.2.2",
"@tiptap/core": "^2.2.4",
"@tiptap/extension-blockquote": "^2.2.4",
"@tiptap/extension-bold": "^2.2.4",
"@tiptap/extension-bullet-list": "^2.2.4",
"@tiptap/extension-code": "^2.2.4",
"@tiptap/extension-code-block": "^2.2.4",
"@tiptap/extension-document": "^2.2.4",
"@tiptap/extension-dropcursor": "^2.2.4",
"@tiptap/extension-gapcursor": "^2.2.4",
"@tiptap/extension-hard-break": "^2.2.4",
"@tiptap/extension-heading": "^2.2.4",
"@tiptap/extension-history": "^2.2.4",
"@tiptap/extension-horizontal-rule": "^2.2.4",
"@tiptap/extension-italic": "^2.2.4",
"@tiptap/extension-link": "^2.2.4",
"@tiptap/extension-list-item": "^2.2.4",
"@tiptap/extension-ordered-list": "^2.2.4",
"@tiptap/extension-paragraph": "^2.2.4",
"@tiptap/extension-placeholder": "^2.2.4",
"@tiptap/extension-strike": "^2.2.4",
"@tiptap/extension-table": "^2.2.4",
"@tiptap/extension-table-cell": "^2.2.4",
"@tiptap/extension-table-header": "^2.2.4",
"@tiptap/extension-table-row": "^2.2.4",
"@tiptap/extension-text": "^2.2.4",
"@tiptap/extension-text-align": "^2.2.4",
"tiptap-render-view": "^1.0.2"
}
}
4 changes: 4 additions & 0 deletions shared/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Table } from "@tiptap/extension-table";
import { TableHeader } from "@tiptap/extension-table-header";
import { TableRow } from "@tiptap/extension-table-row";
import { TableCell } from "@tiptap/extension-table-cell";
import TextAlign from "@tiptap/extension-text-align";

export default [
Document,
Expand All @@ -43,4 +44,7 @@ export default [
TableHeader,
TableRow,
TableCell,
TextAlign.configure({
types: ['paragraph', 'heading'],
}),
];
4 changes: 4 additions & 0 deletions src/interface/i18n/custom-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default {
},
tools: {
relation_block: "Blocks",
align_left: "Align Left",
align_center: "Align Center",
align_right: "Align Right",
align_justify: "Justify",
paragraph: "Paragraph",
code_block: "Code Block",
h1: "$t:wysiwyg_options.h1",
Expand Down
18 changes: 18 additions & 0 deletions src/interface/interface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import Placeholder from '@tiptap/extension-placeholder'
import Dropcursor from '@tiptap/extension-dropcursor'
import Gapcursor from '@tiptap/extension-gapcursor'
import TextAlign from '@tiptap/extension-text-align'
import RelationBlock from "./nodes/relation-block";
import { toolsExtensions, interfaceOptionsDefault, selectedTools } from './tools'
import { useSyncRelationNodes } from "./composables/use-sync-relation-nodes"
Expand Down Expand Up @@ -111,6 +112,9 @@
Placeholder.configure({ placeholder: props.placeholder }),
Dropcursor,
Gapcursor,
TextAlign.configure({
types: ['paragraph', 'heading'],
}),
RelationBlock,
...toolsExtensions(props.tools)
],
Expand Down Expand Up @@ -427,6 +431,20 @@
.flexible-editor :deep(.ProseMirror .ProseMirror-gapcursor:last-child:after) {
bottom: 0;
}

.flexible-editor .ProseMirror [textAlign="left"] {
text-align: left;
}
.flexible-editor .ProseMirror [textAlign="center"] {
text-align: center;
}
.flexible-editor .ProseMirror [textAlign="right"] {
text-align: right;
}
.flexible-editor .ProseMirror [textAlign="justify"] {
text-align: justify;
}

</style>


Expand Down
2 changes: 2 additions & 0 deletions src/interface/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// NOTE: [guide] Add a `Tool` by creating a new file in this directory, importing it and adding it to the `tools: Tool[]` array below! If you import a tiptap extension that also renders content, make sure to add it to /shared/extensions.ts as well!

import { textAlignTools } from "./textAlign";
import heading from "./heading";
import history from "./history";
import relationBlock from "./relation-block";
Expand All @@ -20,6 +21,7 @@ import type { AnyExtension } from "@tiptap/core";
import type { Tool, ToolSelection, InterfaceOption } from "../types";

const tools: Tool[] = [
...textAlignTools,
relationBlock,
paragraph,
codeBlock,
Expand Down
18 changes: 18 additions & 0 deletions src/interface/tools/textAlign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://tiptap.dev/api/extensions/text-align
import TextAlign from "@tiptap/extension-text-align";
import customMessages from "../i18n/custom-messages";
import type { Editor } from "@tiptap/core";
import type { Tool } from "../types";

const textAlignOptions = ['left', 'center', 'right', 'justify'];

export const textAlignTools = textAlignOptions.map((alignment) => ({
key: `align_${alignment}`,
name: (customMessages.tools as any)[`align_${alignment}`],
icon: `format_align_${alignment}`,
extension: [TextAlign],
action: (editor: Editor) => editor.chain().focus().setTextAlign(alignment).run(),
disabled: (editor: Editor) => !editor.can().chain().focus().setTextAlign(alignment).run(),
active: (editor: Editor) => editor.isActive('textStyle', { textAlign: alignment }),
})) as Tool[];