@tiptap/extension-text-align 3.23.5 → 3.24.0
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.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +17 -18
- package/src/text-align.ts +6 -2
package/dist/index.cjs.map
CHANGED
|
@@ -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 * 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)
|
|
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)\n ? alignment\n : 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 .some(response => response)\n },\n\n unsetTextAlign:\n () =>\n ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .some(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,IAC7C,YACA,KAAK,QAAQ;AAAA,YACnB;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,KAAK,cAAY,QAAQ;AAAA,MAC9B;AAAA,MAEF,gBACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,KAAK,QAAQ,MACjB,IAAI,UAAQ,SAAS,gBAAgB,MAAM,WAAW,CAAC,EACvD,KAAK,cAAY,QAAQ;AAAA,MAC9B;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;;;ADpID,IAAO,gBAAQ;","names":[]}
|
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 * 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)
|
|
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)\n ? alignment\n : 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 .some(response => response)\n },\n\n unsetTextAlign:\n () =>\n ({ commands }) => {\n return this.options.types\n .map(type => commands.resetAttributes(type, 'textAlign'))\n .some(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\nex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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;;;ACpID,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-text-align",
|
|
3
|
+
"version": "3.24.0",
|
|
3
4
|
"description": "text align extension for tiptap",
|
|
4
|
-
"version": "3.23.5",
|
|
5
|
-
"homepage": "https://tiptap.dev",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"tiptap",
|
|
8
7
|
"tiptap extension"
|
|
9
8
|
],
|
|
9
|
+
"homepage": "https://tiptap.dev",
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
14
|
+
"directory": "packages/extension-text-align"
|
|
15
|
+
},
|
|
11
16
|
"funding": {
|
|
12
17
|
"type": "github",
|
|
13
18
|
"url": "https://github.com/sponsors/ueberdosis"
|
|
14
19
|
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
15
24
|
"type": "module",
|
|
25
|
+
"main": "dist/index.cjs",
|
|
26
|
+
"module": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
16
28
|
"exports": {
|
|
17
29
|
".": {
|
|
18
30
|
"types": {
|
|
@@ -23,26 +35,13 @@
|
|
|
23
35
|
"require": "./dist/index.cjs"
|
|
24
36
|
}
|
|
25
37
|
},
|
|
26
|
-
"main": "dist/index.cjs",
|
|
27
|
-
"module": "dist/index.js",
|
|
28
|
-
"types": "dist/index.d.ts",
|
|
29
|
-
"files": [
|
|
30
|
-
"src",
|
|
31
|
-
"dist"
|
|
32
|
-
],
|
|
33
38
|
"devDependencies": {
|
|
34
|
-
"@tiptap/core": "^3.
|
|
39
|
+
"@tiptap/core": "^3.24.0"
|
|
35
40
|
},
|
|
36
41
|
"peerDependencies": {
|
|
37
|
-
"@tiptap/core": "3.
|
|
38
|
-
},
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "https://github.com/ueberdosis/tiptap",
|
|
42
|
-
"directory": "packages/extension-text-align"
|
|
42
|
+
"@tiptap/core": "3.24.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"build": "tsup"
|
|
46
|
-
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
|
|
45
|
+
"build": "tsup"
|
|
47
46
|
}
|
|
48
47
|
}
|
package/src/text-align.ts
CHANGED
|
@@ -72,7 +72,9 @@ export const TextAlign = Extension.create<TextAlignOptions>({
|
|
|
72
72
|
parseHTML: element => {
|
|
73
73
|
const alignment = element.style.textAlign
|
|
74
74
|
|
|
75
|
-
return this.options.alignments.includes(alignment)
|
|
75
|
+
return this.options.alignments.includes(alignment)
|
|
76
|
+
? alignment
|
|
77
|
+
: this.options.defaultAlignment
|
|
76
78
|
},
|
|
77
79
|
renderHTML: attributes => {
|
|
78
80
|
if (!attributes.textAlign) {
|
|
@@ -104,7 +106,9 @@ export const TextAlign = Extension.create<TextAlignOptions>({
|
|
|
104
106
|
unsetTextAlign:
|
|
105
107
|
() =>
|
|
106
108
|
({ commands }) => {
|
|
107
|
-
return this.options.types
|
|
109
|
+
return this.options.types
|
|
110
|
+
.map(type => commands.resetAttributes(type, 'textAlign'))
|
|
111
|
+
.some(response => response)
|
|
108
112
|
},
|
|
109
113
|
|
|
110
114
|
toggleTextAlign:
|