PluginProbe
The Innovative Form Builder – IvyForms / 0.5
The Innovative Form Builder – IvyForms v0.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / views / _components / html-editor / extensions / indent.ts

indent.ts in The Innovative Form Builder – IvyForms 0.5, at frontend/src/views/_components/html-editor/extensions/indent.ts

80 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Extension } from '@tiptap/core'
2 import { createIndentCommand, IndentProps } from '../utils/indentUtil.ts'
3
4 export interface IndentOptions {
5 types: string[]
6 minIndent: number
7 maxIndent: number
8 }
9
10 declare module '@tiptap/core' {
11 interface Commands<ReturnType> {
12 indent: {
13 indent: () => ReturnType
14 outdent: () => ReturnType
15 }
16 }
17 }
18
19 const Indent = Extension.create<IndentOptions>({
20 name: 'indent',
21
22 addOptions() {
23 return {
24 buttonIcon: ['', ''],
25 types: ['paragraph', 'heading', 'blockquote'],
26 minIndent: IndentProps.min,
27 maxIndent: IndentProps.max,
28 }
29 },
30
31 addGlobalAttributes() {
32 return [
33 {
34 types: this.options.types,
35 attributes: {
36 indent: {
37 default: 0,
38 parseHTML: (element) => {
39 const indent = element.style.textIndent
40
41 return (indent ? parseInt(indent, 10) : 0) || 0
42 },
43 renderHTML: (attributes) => {
44 if (!attributes.indent) {
45 return {}
46 }
47
48 return { style: `text-indent: ${attributes.indent}rem;` }
49 },
50 },
51 },
52 },
53 ]
54 },
55
56 addCommands() {
57 return {
58 indent: () =>
59 createIndentCommand({
60 delta: IndentProps.more,
61 types: this.options.types,
62 }),
63 outdent: () =>
64 createIndentCommand({
65 delta: IndentProps.less,
66 types: this.options.types,
67 }),
68 }
69 },
70
71 addKeyboardShortcuts() {
72 return {
73 Tab: () => this.editor.commands.indent(),
74 'Shift-Tab': () => this.editor.commands.outdent(),
75 }
76 },
77 })
78
79 export default Indent
80