@tiptap/extension-text-align 2.0.0-beta.213 → 2.0.0-beta.214
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 +56 -55
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +53 -57
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +64 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/packages/extension-text-align/src/index.d.ts +3 -0
- package/dist/{index.d.ts → packages/extension-text-align/src/text-align.d.ts} +21 -24
- package/package.json +7 -16
package/dist/index.cjs
CHANGED
|
@@ -1,59 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
var _core = require('@tiptap/core');
|
|
3
|
-
var TextAlign = _core.Extension.create({
|
|
4
|
-
name: "textAlign",
|
|
5
|
-
addOptions() {
|
|
6
|
-
return {
|
|
7
|
-
types: [],
|
|
8
|
-
alignments: ["left", "center", "right", "justify"],
|
|
9
|
-
defaultAlignment: "left"
|
|
10
|
-
};
|
|
11
|
-
},
|
|
12
|
-
addGlobalAttributes() {
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
types: this.options.types,
|
|
16
|
-
attributes: {
|
|
17
|
-
textAlign: {
|
|
18
|
-
default: this.options.defaultAlignment,
|
|
19
|
-
parseHTML: (element) => element.style.textAlign || this.options.defaultAlignment,
|
|
20
|
-
renderHTML: (attributes) => {
|
|
21
|
-
if (attributes.textAlign === this.options.defaultAlignment) {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
24
|
-
return { style: `text-align: ${attributes.textAlign}` };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
},
|
|
31
|
-
addCommands() {
|
|
32
|
-
return {
|
|
33
|
-
setTextAlign: (alignment) => ({ commands }) => {
|
|
34
|
-
if (!this.options.alignments.includes(alignment)) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return this.options.types.every((type) => commands.updateAttributes(type, { textAlign: alignment }));
|
|
38
|
-
},
|
|
39
|
-
unsetTextAlign: () => ({ commands }) => {
|
|
40
|
-
return this.options.types.every((type) => commands.resetAttributes(type, "textAlign"));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
addKeyboardShortcuts() {
|
|
45
|
-
return {
|
|
46
|
-
"Mod-Shift-l": () => this.editor.commands.setTextAlign("left"),
|
|
47
|
-
"Mod-Shift-e": () => this.editor.commands.setTextAlign("center"),
|
|
48
|
-
"Mod-Shift-r": () => this.editor.commands.setTextAlign("right"),
|
|
49
|
-
"Mod-Shift-j": () => this.editor.commands.setTextAlign("justify")
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
});
|
|
1
|
+
'use strict';
|
|
53
2
|
|
|
54
|
-
|
|
55
|
-
var src_default = TextAlign;
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
56
4
|
|
|
5
|
+
var core = require('@tiptap/core');
|
|
57
6
|
|
|
7
|
+
const TextAlign = core.Extension.create({
|
|
8
|
+
name: 'textAlign',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
types: [],
|
|
12
|
+
alignments: ['left', 'center', 'right', 'justify'],
|
|
13
|
+
defaultAlignment: 'left',
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
addGlobalAttributes() {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
types: this.options.types,
|
|
20
|
+
attributes: {
|
|
21
|
+
textAlign: {
|
|
22
|
+
default: this.options.defaultAlignment,
|
|
23
|
+
parseHTML: element => element.style.textAlign || this.options.defaultAlignment,
|
|
24
|
+
renderHTML: attributes => {
|
|
25
|
+
if (attributes.textAlign === this.options.defaultAlignment) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
return { style: `text-align: ${attributes.textAlign}` };
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
},
|
|
35
|
+
addCommands() {
|
|
36
|
+
return {
|
|
37
|
+
setTextAlign: (alignment) => ({ commands }) => {
|
|
38
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment }));
|
|
42
|
+
},
|
|
43
|
+
unsetTextAlign: () => ({ commands }) => {
|
|
44
|
+
return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'));
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
addKeyboardShortcuts() {
|
|
49
|
+
return {
|
|
50
|
+
'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),
|
|
51
|
+
'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),
|
|
52
|
+
'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),
|
|
53
|
+
'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
58
57
|
|
|
59
|
-
exports.TextAlign = TextAlign;
|
|
58
|
+
exports.TextAlign = TextAlign;
|
|
59
|
+
exports["default"] = TextAlign;
|
|
60
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n types: string[],\n alignments: string[],\n defaultAlignment: string,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n */\n unsetTextAlign: () => ReturnType,\n }\n }\n}\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: 'left',\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 => element.style.textAlign || this.options.defaultAlignment,\n renderHTML: attributes => {\n if (attributes.textAlign === this.options.defaultAlignment) {\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.every(type => commands.updateAttributes(type, { textAlign: alignment }))\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'))\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":";;;;;;AAuBa,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,MAAM;SACzB,CAAA;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;AACtC,wBAAA,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI,CA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;AAC/D,YAAA,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC;SAClE,CAAA;KACF;AACF,CAAA;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,59 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
const TextAlign = Extension.create({
|
|
4
|
+
name: 'textAlign',
|
|
5
|
+
addOptions() {
|
|
6
|
+
return {
|
|
7
|
+
types: [],
|
|
8
|
+
alignments: ['left', 'center', 'right', 'justify'],
|
|
9
|
+
defaultAlignment: 'left',
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
addGlobalAttributes() {
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
types: this.options.types,
|
|
16
|
+
attributes: {
|
|
17
|
+
textAlign: {
|
|
18
|
+
default: this.options.defaultAlignment,
|
|
19
|
+
parseHTML: element => element.style.textAlign || this.options.defaultAlignment,
|
|
20
|
+
renderHTML: attributes => {
|
|
21
|
+
if (attributes.textAlign === this.options.defaultAlignment) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
return { style: `text-align: ${attributes.textAlign}` };
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
addCommands() {
|
|
32
|
+
return {
|
|
33
|
+
setTextAlign: (alignment) => ({ commands }) => {
|
|
34
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment }));
|
|
38
|
+
},
|
|
39
|
+
unsetTextAlign: () => ({ commands }) => {
|
|
40
|
+
return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'));
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
addKeyboardShortcuts() {
|
|
45
|
+
return {
|
|
46
|
+
'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),
|
|
47
|
+
'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),
|
|
48
|
+
'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),
|
|
49
|
+
'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
TextAlign,
|
|
58
|
-
src_default as default
|
|
59
|
-
};
|
|
54
|
+
export { TextAlign, TextAlign as default };
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n types: string[],\n alignments: string[],\n defaultAlignment: string,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n */\n unsetTextAlign: () => ReturnType,\n }\n }\n}\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: 'left',\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 => element.style.textAlign || this.options.defaultAlignment,\n renderHTML: attributes => {\n if (attributes.textAlign === this.options.defaultAlignment) {\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.every(type => commands.updateAttributes(type, { textAlign: alignment }))\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'))\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":";;AAuBa,MAAA,SAAS,GAAG,SAAS,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,MAAM;SACzB,CAAA;KACF;IAED,mBAAmB,GAAA;QACjB,OAAO;AACL,YAAA;AACE,gBAAA,KAAK,EAAE,IAAI,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AC,YAAY,CAAC,MAAM,CAAC;AAC9D,YAAA,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC;AAChE,YAAA,aAAa,EAAE,MAAM,IAAI,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,CAAA;KACF;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-text-align"] = {}, global.core));
|
|
5
|
+
})(this, (function (exports, core) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const TextAlign = core.Extension.create({
|
|
8
|
+
name: 'textAlign',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
types: [],
|
|
12
|
+
alignments: ['left', 'center', 'right', 'justify'],
|
|
13
|
+
defaultAlignment: 'left',
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
addGlobalAttributes() {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
types: this.options.types,
|
|
20
|
+
attributes: {
|
|
21
|
+
textAlign: {
|
|
22
|
+
default: this.options.defaultAlignment,
|
|
23
|
+
parseHTML: element => element.style.textAlign || this.options.defaultAlignment,
|
|
24
|
+
renderHTML: attributes => {
|
|
25
|
+
if (attributes.textAlign === this.options.defaultAlignment) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
return { style: `text-align: ${attributes.textAlign}` };
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
},
|
|
35
|
+
addCommands() {
|
|
36
|
+
return {
|
|
37
|
+
setTextAlign: (alignment) => ({ commands }) => {
|
|
38
|
+
if (!this.options.alignments.includes(alignment)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment }));
|
|
42
|
+
},
|
|
43
|
+
unsetTextAlign: () => ({ commands }) => {
|
|
44
|
+
return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'));
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
addKeyboardShortcuts() {
|
|
49
|
+
return {
|
|
50
|
+
'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),
|
|
51
|
+
'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),
|
|
52
|
+
'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),
|
|
53
|
+
'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
exports.TextAlign = TextAlign;
|
|
59
|
+
exports["default"] = TextAlign;
|
|
60
|
+
|
|
61
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
62
|
+
|
|
63
|
+
}));
|
|
64
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/text-align.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n types: string[],\n alignments: string[],\n defaultAlignment: string,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textAlign: {\n /**\n * Set the text align attribute\n */\n setTextAlign: (alignment: string) => ReturnType,\n /**\n * Unset the text align attribute\n */\n unsetTextAlign: () => ReturnType,\n }\n }\n}\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: 'left',\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 => element.style.textAlign || this.options.defaultAlignment,\n renderHTML: attributes => {\n if (attributes.textAlign === this.options.defaultAlignment) {\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.every(type => commands.updateAttributes(type, { textAlign: alignment }))\n },\n\n unsetTextAlign: () => ({ commands }) => {\n return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'))\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":";;;;;;AAuBa,QAAA,SAAS,GAAGA,cAAS,CAAC,MAAM,CAAmB;EAC1D,IAAA,IAAI,EAAE,WAAW;MAEjB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,KAAK,EAAE,EAAE;cACT,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;EAClD,YAAA,gBAAgB,EAAE,MAAM;WACzB,CAAA;OACF;MAED,mBAAmB,GAAA;UACjB,OAAO;EACL,YAAA;EACE,gBAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;EACzB,gBAAA,UAAU,EAAE;EACV,oBAAA,SAAS,EAAE;EACT,wBAAA,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;EACtC,wBAAA,SAAS,EAAE,O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,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC;EAC/D,YAAA,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC;WAClE,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
declare const TextAlign: Extension<TextAlignOptions, any>;
|
|
23
|
-
|
|
24
|
-
export { TextAlign, TextAlignOptions, TextAlign as default };
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
export interface TextAlignOptions {
|
|
3
|
+
types: string[];
|
|
4
|
+
alignments: string[];
|
|
5
|
+
defaultAlignment: string;
|
|
6
|
+
}
|
|
7
|
+
declare module '@tiptap/core' {
|
|
8
|
+
interface Commands<ReturnType> {
|
|
9
|
+
textAlign: {
|
|
10
|
+
/**
|
|
11
|
+
* Set the text align attribute
|
|
12
|
+
*/
|
|
13
|
+
setTextAlign: (alignment: string) => ReturnType;
|
|
14
|
+
/**
|
|
15
|
+
* Unset the text align attribute
|
|
16
|
+
*/
|
|
17
|
+
unsetTextAlign: () => ReturnType;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export declare const TextAlign: Extension<TextAlignOptions, any>;
|
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.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.214",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,14 +15,15 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
18
|
+
"types": "./dist/packages/extension-text-align/src/index.d.ts",
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"require": "./dist/index.cjs"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"main": "dist/index.cjs",
|
|
24
24
|
"module": "dist/index.js",
|
|
25
|
-
"
|
|
25
|
+
"umd": "dist/index.umd.js",
|
|
26
|
+
"types": "dist/packages/extension-text-align/src/index.d.ts",
|
|
26
27
|
"files": [
|
|
27
28
|
"src",
|
|
28
29
|
"dist"
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"@tiptap/core": "^2.0.0-beta.209"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
35
|
+
"@tiptap/core": "^2.0.0-beta.214"
|
|
35
36
|
},
|
|
36
37
|
"repository": {
|
|
37
38
|
"type": "git",
|
|
@@ -39,17 +40,7 @@
|
|
|
39
40
|
"directory": "packages/extension-text-align"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"tsup": {
|
|
45
|
-
"entry": [
|
|
46
|
-
"src/index.ts"
|
|
47
|
-
],
|
|
48
|
-
"dts": true,
|
|
49
|
-
"splitting": true,
|
|
50
|
-
"format": [
|
|
51
|
-
"esm",
|
|
52
|
-
"cjs"
|
|
53
|
-
]
|
|
43
|
+
"clean": "rm -rf dist",
|
|
44
|
+
"build": "npm run clean && rollup -c"
|
|
54
45
|
}
|
|
55
46
|
}
|