@tiptap/extension-text-align 2.11.7 → 2.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +9 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/text-align.d.ts +6 -0
- package/dist/text-align.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/text-align.ts +17 -0
package/dist/index.cjs
CHANGED
|
@@ -54,6 +54,15 @@ const TextAlign = core.Extension.create({
|
|
|
54
54
|
.map(type => commands.resetAttributes(type, 'textAlign'))
|
|
55
55
|
.every(response => response);
|
|
56
56
|
},
|
|
57
|
+
toggleTextAlign: alignment => ({ editor, commands }) => {
|
|
58
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (editor.isActive({ textAlign: alignment })) {
|
|
62
|
+
return commands.unsetTextAlign();
|
|
63
|
+
}
|
|
64
|
+
return commands.setTextAlign(alignment);
|
|
65
|
+
},
|
|
57
66
|
};
|
|
58
67
|
},
|
|
59
68
|
addKeyboardShortcuts() {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n /**\n * The types where the text align attribute can be applied.\n * @default []\n * @example ['heading', 'paragraph']\n */\n types: string[],\n\n /**\n * The alignments which are allowed.\n * @default ['left', 'center', 'right', 'justify']\n * @example ['left', 'right']\n */\n alignments: string[],\n\n /**\n * The default alignment.\n * @default null\n * @example 'center'\n */\n defaultAlignment: string | null,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n * @param alignment The alignment\n * @example editor.commands.setTextAlign('left')\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n * @example editor.commands.unsetTextAlign()\n */\n unsetTextAlign: () => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n name: 'textAlign',\n\n addOptions() {\n return {\n types: [],\n alignments: ['left', 'center', 'right', 'justify'],\n defaultAlignment: null,\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n textAlign: {\n default: this.options.defaultAlignment,\n parseHTML: element => {\n const alignment = element.style.textAlign\n\n return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n },\n renderHTML: attributes => {\n if (!attributes.textAlign) {\n return {}\n }\n\n return { style: `text-align: ${attributes.textAlign}` }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setTextAlign: (alignment: string) => ({ commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n return this.options.types\n .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n .every(response => response)\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .every(response => response)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n 'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n }\n },\n})\n"],"names":["Extension"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n /**\n * The types where the text align attribute can be applied.\n * @default []\n * @example ['heading', 'paragraph']\n */\n types: string[],\n\n /**\n * The alignments which are allowed.\n * @default ['left', 'center', 'right', 'justify']\n * @example ['left', 'right']\n */\n alignments: string[],\n\n /**\n * The default alignment.\n * @default null\n * @example 'center'\n */\n defaultAlignment: string | null,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n * @param alignment The alignment\n * @example editor.commands.setTextAlign('left')\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n * @example editor.commands.unsetTextAlign()\n */\n unsetTextAlign: () => ReturnType,\n /**\n * Toggle the text align attribute\n * @param alignment The alignment\n * @example editor.commands.toggleTextAlign('right')\n */\n toggleTextAlign: (alignment: string) => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n name: 'textAlign',\n\n addOptions() {\n return {\n types: [],\n alignments: ['left', 'center', 'right', 'justify'],\n defaultAlignment: null,\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n textAlign: {\n default: this.options.defaultAlignment,\n parseHTML: element => {\n const alignment = element.style.textAlign\n\n return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n },\n renderHTML: attributes => {\n if (!attributes.textAlign) {\n return {}\n }\n\n return { style: `text-align: ${attributes.textAlign}` }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setTextAlign: (alignment: string) => ({ commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n return this.options.types\n .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n .every(response => response)\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .every(response => response)\n },\n\n toggleTextAlign: alignment => ({ editor, commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n if (editor.isActive({ textAlign: alignment })) {\n return commands.unsetTextAlign()\n }\n return commands.setTextAlign(alignment)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n 'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n }\n },\n})\n"],"names":["Extension"],"mappings":";;;;;;AAiDA;;;AAGG;AACU,MAAA,SAAS,GAAGA,cAAS,CAAC,MAAM,CAAmB;AAC1D,IAAA,IAAI,EAAE,WAAW;IAEjB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,KAAK,EAAE,EAAE;YACT,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;AAClD,YAAA,gBAAgB,EAAE,IAAI;SACvB;KACF;IAED,mBAAmB,GAAA;QACjB,OAAO;AACL,YAAA;AACE,gBAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;AACzB,gBAAA,UAAU,EAAE;AACV,oBAAA,SAAS,EAAE;AACT,wBAAA,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;wBACtC,SAAS,EAAE,OAAO,IAAG;AACnB,4BAAA,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS;4BAEzC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB;yBAC/F;wBACD,UAAU,EAAE,UAAU,IAAG;AACvB,4BAAA,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;AACzB,gCAAA,OAAO,EAAE;;4BAGX,OAAO,EAAE,KAAK,EAAE,CAAA,YAAA,EAAe,UAAU,CAAC,SAAS,CAAE,CAAA,EAAE;yBACxD;AACF,qBAAA;AACF,iBAAA;AACF,aAAA;SACF;KACF;IAED,WAAW,GAAA;QACT,OAAO;YACL,YAAY,EAAE,CAAC,SAAiB,KAAK,CAAC,EAAE,QAAQ,EA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AI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC;AAC/D,YAAA,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC;SAClE;KACF;AACF,CAAA;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,15 @@ const TextAlign = Extension.create({
|
|
|
50
50
|
.map(type => commands.resetAttributes(type, 'textAlign'))
|
|
51
51
|
.every(response => response);
|
|
52
52
|
},
|
|
53
|
+
toggleTextAlign: alignment => ({ editor, commands }) => {
|
|
54
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (editor.isActive({ textAlign: alignment })) {
|
|
58
|
+
return commands.unsetTextAlign();
|
|
59
|
+
}
|
|
60
|
+
return commands.setTextAlign(alignment);
|
|
61
|
+
},
|
|
53
62
|
};
|
|
54
63
|
},
|
|
55
64
|
addKeyboardShortcuts() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n /**\n * The types where the text align attribute can be applied.\n * @default []\n * @example ['heading', 'paragraph']\n */\n types: string[],\n\n /**\n * The alignments which are allowed.\n * @default ['left', 'center', 'right', 'justify']\n * @example ['left', 'right']\n */\n alignments: string[],\n\n /**\n * The default alignment.\n * @default null\n * @example 'center'\n */\n defaultAlignment: string | null,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n * @param alignment The alignment\n * @example editor.commands.setTextAlign('left')\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n * @example editor.commands.unsetTextAlign()\n */\n unsetTextAlign: () => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n name: 'textAlign',\n\n addOptions() {\n return {\n types: [],\n alignments: ['left', 'center', 'right', 'justify'],\n defaultAlignment: null,\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n textAlign: {\n default: this.options.defaultAlignment,\n parseHTML: element => {\n const alignment = element.style.textAlign\n\n return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n },\n renderHTML: attributes => {\n if (!attributes.textAlign) {\n return {}\n }\n\n return { style: `text-align: ${attributes.textAlign}` }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setTextAlign: (alignment: string) => ({ commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n return this.options.types\n .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n .every(response => response)\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .every(response => response)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n 'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n }\n },\n})\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n /**\n * The types where the text align attribute can be applied.\n * @default []\n * @example ['heading', 'paragraph']\n */\n types: string[],\n\n /**\n * The alignments which are allowed.\n * @default ['left', 'center', 'right', 'justify']\n * @example ['left', 'right']\n */\n alignments: string[],\n\n /**\n * The default alignment.\n * @default null\n * @example 'center'\n */\n defaultAlignment: string | null,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n * @param alignment The alignment\n * @example editor.commands.setTextAlign('left')\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n * @example editor.commands.unsetTextAlign()\n */\n unsetTextAlign: () => ReturnType,\n /**\n * Toggle the text align attribute\n * @param alignment The alignment\n * @example editor.commands.toggleTextAlign('right')\n */\n toggleTextAlign: (alignment: string) => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n name: 'textAlign',\n\n addOptions() {\n return {\n types: [],\n alignments: ['left', 'center', 'right', 'justify'],\n defaultAlignment: null,\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n textAlign: {\n default: this.options.defaultAlignment,\n parseHTML: element => {\n const alignment = element.style.textAlign\n\n return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n },\n renderHTML: attributes => {\n if (!attributes.textAlign) {\n return {}\n }\n\n return { style: `text-align: ${attributes.textAlign}` }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setTextAlign: (alignment: string) => ({ commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n return this.options.types\n .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n .every(response => response)\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .every(response => response)\n },\n\n toggleTextAlign: alignment => ({ editor, commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n if (editor.isActive({ textAlign: alignment })) {\n return commands.unsetTextAlign()\n }\n return commands.setTextAlign(alignment)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n 'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n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"}
|
package/dist/index.umd.js
CHANGED
|
@@ -54,6 +54,15 @@
|
|
|
54
54
|
.map(type => commands.resetAttributes(type, 'textAlign'))
|
|
55
55
|
.every(response => response);
|
|
56
56
|
},
|
|
57
|
+
toggleTextAlign: alignment => ({ editor, commands }) => {
|
|
58
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (editor.isActive({ textAlign: alignment })) {
|
|
62
|
+
return commands.unsetTextAlign();
|
|
63
|
+
}
|
|
64
|
+
return commands.setTextAlign(alignment);
|
|
65
|
+
},
|
|
57
66
|
};
|
|
58
67
|
},
|
|
59
68
|
addKeyboardShortcuts() {
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n /**\n * The types where the text align attribute can be applied.\n * @default []\n * @example ['heading', 'paragraph']\n */\n types: string[],\n\n /**\n * The alignments which are allowed.\n * @default ['left', 'center', 'right', 'justify']\n * @example ['left', 'right']\n */\n alignments: string[],\n\n /**\n * The default alignment.\n * @default null\n * @example 'center'\n */\n defaultAlignment: string | null,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n * @param alignment The alignment\n * @example editor.commands.setTextAlign('left')\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n * @example editor.commands.unsetTextAlign()\n */\n unsetTextAlign: () => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n name: 'textAlign',\n\n addOptions() {\n return {\n types: [],\n alignments: ['left', 'center', 'right', 'justify'],\n defaultAlignment: null,\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n textAlign: {\n default: this.options.defaultAlignment,\n parseHTML: element => {\n const alignment = element.style.textAlign\n\n return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n },\n renderHTML: attributes => {\n if (!attributes.textAlign) {\n return {}\n }\n\n return { style: `text-align: ${attributes.textAlign}` }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setTextAlign: (alignment: string) => ({ commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n return this.options.types\n .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n .every(response => response)\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .every(response => response)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n 'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n }\n },\n})\n"],"names":["Extension"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n /**\n * The types where the text align attribute can be applied.\n * @default []\n * @example ['heading', 'paragraph']\n */\n types: string[],\n\n /**\n * The alignments which are allowed.\n * @default ['left', 'center', 'right', 'justify']\n * @example ['left', 'right']\n */\n alignments: string[],\n\n /**\n * The default alignment.\n * @default null\n * @example 'center'\n */\n defaultAlignment: string | null,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n * @param alignment The alignment\n * @example editor.commands.setTextAlign('left')\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n * @example editor.commands.unsetTextAlign()\n */\n unsetTextAlign: () => ReturnType,\n /**\n * Toggle the text align attribute\n * @param alignment The alignment\n * @example editor.commands.toggleTextAlign('right')\n */\n toggleTextAlign: (alignment: string) => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n name: 'textAlign',\n\n addOptions() {\n return {\n types: [],\n alignments: ['left', 'center', 'right', 'justify'],\n defaultAlignment: null,\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n textAlign: {\n default: this.options.defaultAlignment,\n parseHTML: element => {\n const alignment = element.style.textAlign\n\n return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n },\n renderHTML: attributes => {\n if (!attributes.textAlign) {\n return {}\n }\n\n return { style: `text-align: ${attributes.textAlign}` }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setTextAlign: (alignment: string) => ({ commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n return this.options.types\n .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n .every(response => response)\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .every(response => response)\n },\n\n toggleTextAlign: alignment => ({ editor, commands }) => {\n if (!this.options.alignments.includes(alignment)) {\n return false\n }\n\n if (editor.isActive({ textAlign: alignment })) {\n return commands.unsetTextAlign()\n }\n return commands.setTextAlign(alignment)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n 'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n }\n },\n})\n"],"names":["Extension"],"mappings":";;;;;;EAiDA;;;EAGG;AACU,QAAA,SAAS,GAAGA,cAAS,CAAC,MAAM,CAAmB;EAC1D,IAAA,IAAI,EAAE,WAAW;MAEjB,UAAU,GAAA;UACR,OAAO;EACL,YA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Type;
|
|
36
|
+
/**
|
|
37
|
+
* Toggle the text align attribute
|
|
38
|
+
* @param alignment The alignment
|
|
39
|
+
* @example editor.commands.toggleTextAlign('right')
|
|
40
|
+
*/
|
|
41
|
+
toggleTextAlign: (alignment: string) => ReturnType;
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
44
|
}
|
package/dist/text-align.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-align.d.ts","sourceRoot":"","sources":["../src/text-align.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;OAIG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,SAAS,EAAE;YACT;;;;eAIG;YACH,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC;YAChD;;;eAGG;YACH,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"text-align.d.ts","sourceRoot":"","sources":["../src/text-align.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;OAIG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,SAAS,EAAE;YACT;;;;eAIG;YACH,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC;YAChD;;;eAGG;YACH,cAAc,EAAE,MAAM,UAAU,CAAC;YACjC;;;;eAIG;YACH,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC;SACpD,CAAA;KACF;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,kCA2EpB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-text-align",
|
|
3
3
|
"description": "text align extension for tiptap",
|
|
4
|
-
"version": "2.11.
|
|
4
|
+
"version": "2.11.9",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tiptap/core": "^2.11.
|
|
32
|
+
"@tiptap/core": "^2.11.9"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@tiptap/core": "^2.7.0"
|
package/src/text-align.ts
CHANGED
|
@@ -37,6 +37,12 @@ declare module '@tiptap/core' {
|
|
|
37
37
|
* @example editor.commands.unsetTextAlign()
|
|
38
38
|
*/
|
|
39
39
|
unsetTextAlign: () => ReturnType,
|
|
40
|
+
/**
|
|
41
|
+
* Toggle the text align attribute
|
|
42
|
+
* @param alignment The alignment
|
|
43
|
+
* @example editor.commands.toggleTextAlign('right')
|
|
44
|
+
*/
|
|
45
|
+
toggleTextAlign: (alignment: string) => ReturnType,
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -98,6 +104,17 @@ export const TextAlign = Extension.create<TextAlignOptions>({
|
|
|
98
104
|
.map(type => commands.resetAttributes(type, 'textAlign'))
|
|
99
105
|
.every(response => response)
|
|
100
106
|
},
|
|
107
|
+
|
|
108
|
+
toggleTextAlign: alignment => ({ editor, commands }) => {
|
|
109
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (editor.isActive({ textAlign: alignment })) {
|
|
114
|
+
return commands.unsetTextAlign()
|
|
115
|
+
}
|
|
116
|
+
return commands.setTextAlign(alignment)
|
|
117
|
+
},
|
|
101
118
|
}
|
|
102
119
|
},
|
|
103
120
|
|