@tiptap/extension-text-align 3.0.0-beta.2 → 3.0.0-beta.22

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 CHANGED
@@ -68,6 +68,15 @@ var TextAlign = import_core.Extension.create({
68
68
  },
69
69
  unsetTextAlign: () => ({ commands }) => {
70
70
  return this.options.types.map((type) => commands.resetAttributes(type, "textAlign")).every((response) => response);
71
+ },
72
+ toggleTextAlign: (alignment) => ({ editor, commands }) => {
73
+ if (!this.options.alignments.includes(alignment)) {
74
+ return false;
75
+ }
76
+ if (editor.isActive({ textAlign: alignment })) {
77
+ return commands.unsetTextAlign();
78
+ }
79
+ return commands.setTextAlign(alignment);
71
80
  }
72
81
  };
73
82
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/text-align.ts"],"sourcesContent":["import { TextAlign } from './text-align.js'\n\nexport * from './text-align.js'\n\nexport default TextAlign\n","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:\n (alignment: string) =>\n ({ 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:\n () =>\n ({ commands }) => {\n return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AA+CnB,IAAM,YAAY,sBAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,MACR,YAAY,CAAC,QAAQ,UAAU,SAAS,SAAS;AAAA,MACjD,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,sBAAsB;AACpB,WAAO;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,WAAW;AAAA,YACT,SAAS,KAAK,QAAQ;AAAA,YACtB,WAAW,aAAW;AACpB,oBAAM,YAAY,QAAQ,MAAM;AAEhC,qBAAO,KAAK,QAAQ,WAAW,SAAS,SAAS,IAAI,YAAY,KAAK,QAAQ;AAAA,YAChF;AAAA,YACA,YAAY,gBAAc;AACxB,kBAAI,CAAC,WAAW,WAAW;AACzB,uBAAO,CAAC;AAAA,cACV;AAEA,qBAAO,EAAE,OAAO,eAAe,WAAW,SAAS,GAAG;AAAA,YACxD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,cACE,CAAC,cACD,CAAC,EAAE,SAAS,MAAM;AAChB,YAAI,CAAC,KAAK,QAAQ,WAAW,SAAS,SAAS,GAAG;AAChD,iBAAO;AAAA,QACT;AAEA,eAAO,KAAK,QAAQ,MACjB,IAAI,UAAQ,SAAS,iBAAiB,MAAM,EAAE,WAAW,UAAU,CAAC,CAAC,EACrE,MAAM,cAAY,QAAQ;AAAA,MAC/B;AAAA,MAEF,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,KAAK,QAAQ,MAAM,IAAI,UAAQ,SAAS,gBAAgB,MAAM,WAAW,CAAC,EAAE,MAAM,cAAY,QAAQ;AAAA,MAC/G;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,MAAM;AAAA,MAC7D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,QAAQ;AAAA,MAC/D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,OAAO;AAAA,MAC9D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,SAAS;AAAA,IAClE;AAAA,EACF;AACF,CAAC;;;AD7GD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/text-align.ts"],"sourcesContent":["import { TextAlign } from './text-align.js'\n\nexport * from './text-align.js'\n\nexport default TextAlign\n","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:\n (alignment: string) =>\n ({ 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:\n () =>\n ({ commands }) => {\n return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).every(response => response)\n },\n\n toggleTextAlign:\n alignment =>\n ({ 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAqDnB,IAAM,YAAY,sBAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,MACR,YAAY,CAAC,QAAQ,UAAU,SAAS,SAAS;AAAA,MACjD,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,sBAAsB;AACpB,WAAO;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,WAAW;AAAA,YACT,SAAS,KAAK,QAAQ;AAAA,YACtB,WAAW,aAAW;AACpB,oBAAM,YAAY,QAAQ,MAAM;AAEhC,qBAAO,KAAK,QAAQ,WAAW,SAAS,SAAS,IAAI,YAAY,KAAK,QAAQ;AAAA,YAChF;AAAA,YACA,YAAY,gBAAc;AACxB,kBAAI,CAAC,WAAW,WAAW;AACzB,uBAAO,CAAC;AAAA,cACV;AAEA,qBAAO,EAAE,OAAO,eAAe,WAAW,SAAS,GAAG;AAAA,YACxD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,cACE,CAAC,cACD,CAAC,EAAE,SAAS,MAAM;AAChB,YAAI,CAAC,KAAK,QAAQ,WAAW,SAAS,SAAS,GAAG;AAChD,iBAAO;AAAA,QACT;AAEA,eAAO,KAAK,QAAQ,MACjB,IAAI,UAAQ,SAAS,iBAAiB,MAAM,EAAE,WAAW,UAAU,CAAC,CAAC,EACrE,MAAM,cAAY,QAAQ;AAAA,MAC/B;AAAA,MAEF,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,KAAK,QAAQ,MAAM,IAAI,UAAQ,SAAS,gBAAgB,MAAM,WAAW,CAAC,EAAE,MAAM,cAAY,QAAQ;AAAA,MAC/G;AAAA,MAEF,iBACE,eACA,CAAC,EAAE,QAAQ,SAAS,MAAM;AACxB,YAAI,CAAC,KAAK,QAAQ,WAAW,SAAS,SAAS,GAAG;AAChD,iBAAO;AAAA,QACT;AAEA,YAAI,OAAO,SAAS,EAAE,WAAW,UAAU,CAAC,GAAG;AAC7C,iBAAO,SAAS,eAAe;AAAA,QACjC;AACA,eAAO,SAAS,aAAa,SAAS;AAAA,MACxC;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,MAAM;AAAA,MAC7D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,QAAQ;AAAA,MAC/D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,OAAO;AAAA,MAC9D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,SAAS;AAAA,IAClE;AAAA,EACF;AACF,CAAC;;;ADhID,IAAO,gBAAQ;","names":[]}
package/dist/index.d.cts CHANGED
@@ -34,6 +34,12 @@ declare module '@tiptap/core' {
34
34
  * @example editor.commands.unsetTextAlign()
35
35
  */
36
36
  unsetTextAlign: () => ReturnType;
37
+ /**
38
+ * Toggle the text align attribute
39
+ * @param alignment The alignment
40
+ * @example editor.commands.toggleTextAlign('right')
41
+ */
42
+ toggleTextAlign: (alignment: string) => ReturnType;
37
43
  };
38
44
  }
39
45
  }
package/dist/index.d.ts CHANGED
@@ -34,6 +34,12 @@ declare module '@tiptap/core' {
34
34
  * @example editor.commands.unsetTextAlign()
35
35
  */
36
36
  unsetTextAlign: () => ReturnType;
37
+ /**
38
+ * Toggle the text align attribute
39
+ * @param alignment The alignment
40
+ * @example editor.commands.toggleTextAlign('right')
41
+ */
42
+ toggleTextAlign: (alignment: string) => ReturnType;
37
43
  };
38
44
  }
39
45
  }
package/dist/index.js CHANGED
@@ -41,6 +41,15 @@ var TextAlign = Extension.create({
41
41
  },
42
42
  unsetTextAlign: () => ({ commands }) => {
43
43
  return this.options.types.map((type) => commands.resetAttributes(type, "textAlign")).every((response) => response);
44
+ },
45
+ toggleTextAlign: (alignment) => ({ editor, commands }) => {
46
+ if (!this.options.alignments.includes(alignment)) {
47
+ return false;
48
+ }
49
+ if (editor.isActive({ textAlign: alignment })) {
50
+ return commands.unsetTextAlign();
51
+ }
52
+ return commands.setTextAlign(alignment);
44
53
  }
45
54
  };
46
55
  },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/text-align.ts","../src/index.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:\n (alignment: string) =>\n ({ 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:\n () =>\n ({ commands }) => {\n return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).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","import { TextAlign } from './text-align.js'\n\nexport * from './text-align.js'\n\nexport default TextAlign\n"],"mappings":";AAAA,SAAS,iBAAiB;AA+CnB,IAAM,YAAY,UAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,MACR,YAAY,CAAC,QAAQ,UAAU,SAAS,SAAS;AAAA,MACjD,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,sBAAsB;AACpB,WAAO;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,WAAW;AAAA,YACT,SAAS,KAAK,QAAQ;AAAA,YACtB,WAAW,aAAW;AACpB,oBAAM,YAAY,QAAQ,MAAM;AAEhC,qBAAO,KAAK,QAAQ,WAAW,SAAS,SAAS,IAAI,YAAY,KAAK,QAAQ;AAAA,YAChF;AAAA,YACA,YAAY,gBAAc;AACxB,kBAAI,CAAC,WAAW,WAAW;AACzB,uBAAO,CAAC;AAAA,cACV;AAEA,qBAAO,EAAE,OAAO,eAAe,WAAW,SAAS,GAAG;AAAA,YACxD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,cACE,CAAC,cACD,CAAC,EAAE,SAAS,MAAM;AAChB,YAAI,CAAC,KAAK,QAAQ,WAAW,SAAS,SAAS,GAAG;AAChD,iBAAO;AAAA,QACT;AAEA,eAAO,KAAK,QAAQ,MACjB,IAAI,UAAQ,SAAS,iBAAiB,MAAM,EAAE,WAAW,UAAU,CAAC,CAAC,EACrE,MAAM,cAAY,QAAQ;AAAA,MAC/B;AAAA,MAEF,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,KAAK,QAAQ,MAAM,IAAI,UAAQ,SAAS,gBAAgB,MAAM,WAAW,CAAC,EAAE,MAAM,cAAY,QAAQ;AAAA,MAC/G;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,MAAM;AAAA,MAC7D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,QAAQ;AAAA,MAC/D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,OAAO;AAAA,MAC9D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,SAAS;AAAA,IAClE;AAAA,EACF;AACF,CAAC;;;AC7GD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/text-align.ts","../src/index.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:\n (alignment: string) =>\n ({ 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:\n () =>\n ({ commands }) => {\n return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).every(response => response)\n },\n\n toggleTextAlign:\n alignment =>\n ({ 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","import { TextAlign } from './text-align.js'\n\nexport * from './text-align.js'\n\nexport default TextAlign\n"],"mappings":";AAAA,SAAS,iBAAiB;AAqDnB,IAAM,YAAY,UAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,MACR,YAAY,CAAC,QAAQ,UAAU,SAAS,SAAS;AAAA,MACjD,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,sBAAsB;AACpB,WAAO;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,WAAW;AAAA,YACT,SAAS,KAAK,QAAQ;AAAA,YACtB,WAAW,aAAW;AACpB,oBAAM,YAAY,QAAQ,MAAM;AAEhC,qBAAO,KAAK,QAAQ,WAAW,SAAS,SAAS,IAAI,YAAY,KAAK,QAAQ;AAAA,YAChF;AAAA,YACA,YAAY,gBAAc;AACxB,kBAAI,CAAC,WAAW,WAAW;AACzB,uBAAO,CAAC;AAAA,cACV;AAEA,qBAAO,EAAE,OAAO,eAAe,WAAW,SAAS,GAAG;AAAA,YACxD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,cACE,CAAC,cACD,CAAC,EAAE,SAAS,MAAM;AAChB,YAAI,CAAC,KAAK,QAAQ,WAAW,SAAS,SAAS,GAAG;AAChD,iBAAO;AAAA,QACT;AAEA,eAAO,KAAK,QAAQ,MACjB,IAAI,UAAQ,SAAS,iBAAiB,MAAM,EAAE,WAAW,UAAU,CAAC,CAAC,EACrE,MAAM,cAAY,QAAQ;AAAA,MAC/B;AAAA,MAEF,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,KAAK,QAAQ,MAAM,IAAI,UAAQ,SAAS,gBAAgB,MAAM,WAAW,CAAC,EAAE,MAAM,cAAY,QAAQ;AAAA,MAC/G;AAAA,MAEF,iBACE,eACA,CAAC,EAAE,QAAQ,SAAS,MAAM;AACxB,YAAI,CAAC,KAAK,QAAQ,WAAW,SAAS,SAAS,GAAG;AAChD,iBAAO;AAAA,QACT;AAEA,YAAI,OAAO,SAAS,EAAE,WAAW,UAAU,CAAC,GAAG;AAC7C,iBAAO,SAAS,eAAe;AAAA,QACjC;AACA,eAAO,SAAS,aAAa,SAAS;AAAA,MACxC;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,MAAM;AAAA,MAC7D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,QAAQ;AAAA,MAC/D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,OAAO;AAAA,MAC9D,eAAe,MAAM,KAAK,OAAO,SAAS,aAAa,SAAS;AAAA,IAClE;AAAA,EACF;AACF,CAAC;;;AChID,IAAO,gBAAQ;","names":[]}
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": "3.0.0-beta.2",
4
+ "version": "3.0.0-beta.22",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -31,10 +31,10 @@
31
31
  "dist"
32
32
  ],
33
33
  "devDependencies": {
34
- "@tiptap/core": "^3.0.0-beta.2"
34
+ "@tiptap/core": "3.0.0-beta.22"
35
35
  },
36
36
  "peerDependencies": {
37
- "@tiptap/core": "^3.0.0-beta.0"
37
+ "@tiptap/core": "3.0.0-beta.22"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
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
  }
@@ -100,6 +106,19 @@ export const TextAlign = Extension.create<TextAlignOptions>({
100
106
  ({ commands }) => {
101
107
  return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).every(response => response)
102
108
  },
109
+
110
+ toggleTextAlign:
111
+ alignment =>
112
+ ({ editor, commands }) => {
113
+ if (!this.options.alignments.includes(alignment)) {
114
+ return false
115
+ }
116
+
117
+ if (editor.isActive({ textAlign: alignment })) {
118
+ return commands.unsetTextAlign()
119
+ }
120
+ return commands.setTextAlign(alignment)
121
+ },
103
122
  }
104
123
  },
105
124