@tiptap/extension-subscript 2.0.0-beta.10
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/LICENSE.md +21 -0
- package/README.md +14 -0
- package/dist/packages/extension-subscript/src/index.d.ts +3 -0
- package/dist/packages/extension-subscript/src/subscript.d.ts +23 -0
- package/dist/tiptap-extension-subscript.cjs.js +56 -0
- package/dist/tiptap-extension-subscript.cjs.js.map +1 -0
- package/dist/tiptap-extension-subscript.esm.js +51 -0
- package/dist/tiptap-extension-subscript.esm.js.map +1 -0
- package/dist/tiptap-extension-subscript.umd.js +60 -0
- package/dist/tiptap-extension-subscript.umd.js.map +1 -0
- package/package.json +32 -0
- package/src/index.ts +5 -0
- package/src/subscript.ts +77 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021, überdosis GbR
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @tiptap/extension-superscript
|
|
2
|
+
[](https://www.npmjs.com/package/@tiptap/extension-superscript)
|
|
3
|
+
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
|
+
[](https://www.npmjs.com/package/@tiptap/extension-superscript)
|
|
5
|
+
[](https://github.com/sponsors/ueberdosis)
|
|
6
|
+
|
|
7
|
+
## Introduction
|
|
8
|
+
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
|
9
|
+
|
|
10
|
+
## Official Documentation
|
|
11
|
+
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
export interface SubscriptExtensionOptions {
|
|
3
|
+
HTMLAttributes: Object;
|
|
4
|
+
}
|
|
5
|
+
declare module '@tiptap/core' {
|
|
6
|
+
interface Commands<ReturnType> {
|
|
7
|
+
subscript: {
|
|
8
|
+
/**
|
|
9
|
+
* Set a subscript mark
|
|
10
|
+
*/
|
|
11
|
+
setSubscript: () => ReturnType;
|
|
12
|
+
/**
|
|
13
|
+
* Toggle a subscript mark
|
|
14
|
+
*/
|
|
15
|
+
toggleSubscript: () => ReturnType;
|
|
16
|
+
/**
|
|
17
|
+
* Unset a subscript mark
|
|
18
|
+
*/
|
|
19
|
+
unsetSubscript: () => ReturnType;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export declare const Subscript: Mark<SubscriptExtensionOptions, any>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tiptap/core');
|
|
6
|
+
|
|
7
|
+
const Subscript = core.Mark.create({
|
|
8
|
+
name: 'subscript',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
HTMLAttributes: {},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
parseHTML() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
tag: 'sub',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
style: 'vertical-align',
|
|
21
|
+
getAttrs(value) {
|
|
22
|
+
// Don’t match this rule if the vertical align isn’t sub.
|
|
23
|
+
if (value !== 'sub') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// If it falls through we’ll match, and this mark will be applied.
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
renderHTML({ HTMLAttributes }) {
|
|
32
|
+
return ['sub', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
33
|
+
},
|
|
34
|
+
addCommands() {
|
|
35
|
+
return {
|
|
36
|
+
setSubscript: () => ({ commands }) => {
|
|
37
|
+
return commands.setMark(this.name);
|
|
38
|
+
},
|
|
39
|
+
toggleSubscript: () => ({ commands }) => {
|
|
40
|
+
return commands.toggleMark(this.name);
|
|
41
|
+
},
|
|
42
|
+
unsetSubscript: () => ({ commands }) => {
|
|
43
|
+
return commands.unsetMark(this.name);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
addKeyboardShortcuts() {
|
|
48
|
+
return {
|
|
49
|
+
'Mod-,': () => this.editor.commands.toggleSubscript(),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
exports.Subscript = Subscript;
|
|
55
|
+
exports["default"] = Subscript;
|
|
56
|
+
//# sourceMappingURL=tiptap-extension-subscript.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiptap-extension-subscript.cjs.js","sources":["../src/subscript.ts"],"sourcesContent":["import { Mark, mergeAttributes } from '@tiptap/core'\n\nexport interface SubscriptExtensionOptions {\n HTMLAttributes: Object,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n subscript: {\n /**\n * Set a subscript mark\n */\n setSubscript: () => ReturnType,\n /**\n * Toggle a subscript mark\n */\n toggleSubscript: () => ReturnType,\n /**\n * Unset a subscript mark\n */\n unsetSubscript: () => ReturnType,\n }\n }\n}\n\nexport const Subscript = Mark.create<SubscriptExtensionOptions>({\n name: 'subscript',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'sub',\n },\n {\n style: 'vertical-align',\n getAttrs(value) {\n // Don’t match this rule if the vertical align isn’t sub.\n if (value !== 'sub') {\n return false\n }\n\n // If it falls through we’ll match, and this mark will be applied.\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setSubscript: () => ({ commands }) => {\n return commands.setMark(this.name)\n },\n toggleSubscript: () => ({ commands }) => {\n return commands.toggleMark(this.name)\n },\n unsetSubscript: () => ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-,': () => this.editor.commands.toggleSubscript(),\n }\n },\n})\n"],"names":["Mark","mergeAttributes"],"mappings":";;;;;;MAyBa,SAAS,GAAGA,SAAI,CAAC,MAAM,CAA4B;IAC9D,IAAI,EAAE,WAAW;IAEjB,UAAU;QACR,OAAO;YACL,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,KAAK;aACX;YACD;gBACE,KAAK,EAAE,gBAAgB;gBACvB,QAAQ,CAAC,KAAK;;oBAEZ,IAAI,KAAK,KAAK,KAAK,EAAE;wBACnB,OAAO,KAAK,CAAA;qBACb;;iBAGF;aACF;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,KAAK,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KAChF;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACnC;YACD,eAAe,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBAClC,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACtC;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACrC;SACF,CAAA;KACF;IAED,oBAAoB;QAClB,OAAO;YACL,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SACtD,CAAA;KACF;CACF;;;;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Mark, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
const Subscript = Mark.create({
|
|
4
|
+
name: 'subscript',
|
|
5
|
+
addOptions() {
|
|
6
|
+
return {
|
|
7
|
+
HTMLAttributes: {},
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
parseHTML() {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
tag: 'sub',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
style: 'vertical-align',
|
|
17
|
+
getAttrs(value) {
|
|
18
|
+
// Don’t match this rule if the vertical align isn’t sub.
|
|
19
|
+
if (value !== 'sub') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// If it falls through we’ll match, and this mark will be applied.
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
},
|
|
27
|
+
renderHTML({ HTMLAttributes }) {
|
|
28
|
+
return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
29
|
+
},
|
|
30
|
+
addCommands() {
|
|
31
|
+
return {
|
|
32
|
+
setSubscript: () => ({ commands }) => {
|
|
33
|
+
return commands.setMark(this.name);
|
|
34
|
+
},
|
|
35
|
+
toggleSubscript: () => ({ commands }) => {
|
|
36
|
+
return commands.toggleMark(this.name);
|
|
37
|
+
},
|
|
38
|
+
unsetSubscript: () => ({ commands }) => {
|
|
39
|
+
return commands.unsetMark(this.name);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
addKeyboardShortcuts() {
|
|
44
|
+
return {
|
|
45
|
+
'Mod-,': () => this.editor.commands.toggleSubscript(),
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export { Subscript, Subscript as default };
|
|
51
|
+
//# sourceMappingURL=tiptap-extension-subscript.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiptap-extension-subscript.esm.js","sources":["../src/subscript.ts"],"sourcesContent":["import { Mark, mergeAttributes } from '@tiptap/core'\n\nexport interface SubscriptExtensionOptions {\n HTMLAttributes: Object,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n subscript: {\n /**\n * Set a subscript mark\n */\n setSubscript: () => ReturnType,\n /**\n * Toggle a subscript mark\n */\n toggleSubscript: () => ReturnType,\n /**\n * Unset a subscript mark\n */\n unsetSubscript: () => ReturnType,\n }\n }\n}\n\nexport const Subscript = Mark.create<SubscriptExtensionOptions>({\n name: 'subscript',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'sub',\n },\n {\n style: 'vertical-align',\n getAttrs(value) {\n // Don’t match this rule if the vertical align isn’t sub.\n if (value !== 'sub') {\n return false\n }\n\n // If it falls through we’ll match, and this mark will be applied.\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setSubscript: () => ({ commands }) => {\n return commands.setMark(this.name)\n },\n toggleSubscript: () => ({ commands }) => {\n return commands.toggleMark(this.name)\n },\n unsetSubscript: () => ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-,': () => this.editor.commands.toggleSubscript(),\n }\n },\n})\n"],"names":[],"mappings":";;MAyBa,SAAS,GAAG,IAAI,CAAC,MAAM,CAA4B;IAC9D,IAAI,EAAE,WAAW;IAEjB,UAAU;QACR,OAAO;YACL,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,KAAK;aACX;YACD;gBACE,KAAK,EAAE,gBAAgB;gBACvB,QAAQ,CAAC,KAAK;;oBAEZ,IAAI,KAAK,KAAK,KAAK,EAAE;wBACnB,OAAO,KAAK,CAAA;qBACb;;iBAGF;aACF;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KAChF;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACnC;YACD,eAAe,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBAClC,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACtC;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACrC;SACF,CAAA;KACF;IAED,oBAAoB;QAClB,OAAO;YACL,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SACtD,CAAA;KACF;CACF;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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-subscript"] = {}, global.core));
|
|
5
|
+
})(this, (function (exports, core) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const Subscript = core.Mark.create({
|
|
8
|
+
name: 'subscript',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
HTMLAttributes: {},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
parseHTML() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
tag: 'sub',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
style: 'vertical-align',
|
|
21
|
+
getAttrs(value) {
|
|
22
|
+
// Don’t match this rule if the vertical align isn’t sub.
|
|
23
|
+
if (value !== 'sub') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// If it falls through we’ll match, and this mark will be applied.
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
renderHTML({ HTMLAttributes }) {
|
|
32
|
+
return ['sub', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
33
|
+
},
|
|
34
|
+
addCommands() {
|
|
35
|
+
return {
|
|
36
|
+
setSubscript: () => ({ commands }) => {
|
|
37
|
+
return commands.setMark(this.name);
|
|
38
|
+
},
|
|
39
|
+
toggleSubscript: () => ({ commands }) => {
|
|
40
|
+
return commands.toggleMark(this.name);
|
|
41
|
+
},
|
|
42
|
+
unsetSubscript: () => ({ commands }) => {
|
|
43
|
+
return commands.unsetMark(this.name);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
addKeyboardShortcuts() {
|
|
48
|
+
return {
|
|
49
|
+
'Mod-,': () => this.editor.commands.toggleSubscript(),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
exports.Subscript = Subscript;
|
|
55
|
+
exports["default"] = Subscript;
|
|
56
|
+
|
|
57
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
58
|
+
|
|
59
|
+
}));
|
|
60
|
+
//# sourceMappingURL=tiptap-extension-subscript.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiptap-extension-subscript.umd.js","sources":["../src/subscript.ts"],"sourcesContent":["import { Mark, mergeAttributes } from '@tiptap/core'\n\nexport interface SubscriptExtensionOptions {\n HTMLAttributes: Object,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n subscript: {\n /**\n * Set a subscript mark\n */\n setSubscript: () => ReturnType,\n /**\n * Toggle a subscript mark\n */\n toggleSubscript: () => ReturnType,\n /**\n * Unset a subscript mark\n */\n unsetSubscript: () => ReturnType,\n }\n }\n}\n\nexport const Subscript = Mark.create<SubscriptExtensionOptions>({\n name: 'subscript',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'sub',\n },\n {\n style: 'vertical-align',\n getAttrs(value) {\n // Don’t match this rule if the vertical align isn’t sub.\n if (value !== 'sub') {\n return false\n }\n\n // If it falls through we’ll match, and this mark will be applied.\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setSubscript: () => ({ commands }) => {\n return commands.setMark(this.name)\n },\n toggleSubscript: () => ({ commands }) => {\n return commands.toggleMark(this.name)\n },\n unsetSubscript: () => ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-,': () => this.editor.commands.toggleSubscript(),\n }\n },\n})\n"],"names":["Mark","mergeAttributes"],"mappings":";;;;;;QAyBa,SAAS,GAAGA,SAAI,CAAC,MAAM,CAA4B;MAC9D,IAAI,EAAE,WAAW;MAEjB,UAAU;UACR,OAAO;cACL,cAAc,EAAE,EAAE;WACnB,CAAA;OACF;MAED,SAAS;UACP,OAAO;cACL;kBACE,GAAG,EAAE,KAAK;eACX;cACD;kBACE,KAAK,EAAE,gBAAgB;kBACvB,QAAQ,CAAC,KAAK;;sBAEZ,IAAI,KAAK,KAAK,KAAK,EAAE;0BACnB,OAAO,KAAK,CAAA;uBACb;;mBAGF;eACF;WACF,CAAA;OACF;MAED,UAAU,CAAC,EAAE,cAAc,EAAE;UAC3B,OAAO,CAAC,KAAK,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;OAChF;MAED,WAAW;UACT,OAAO;cACL,YAAY,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;kBAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;eACnC;cACD,eAAe,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;kBAClC,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;eACtC;cACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;kBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;eACrC;WACF,CAAA;OACF;MAED,oBAAoB;UAClB,OAAO;cACL,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;WACtD,CAAA;OACF;GACF;;;;;;;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tiptap/extension-subscript",
|
|
3
|
+
"description": "subscript extension for tiptap",
|
|
4
|
+
"version": "2.0.0-beta.10",
|
|
5
|
+
"homepage": "https://tiptap.dev",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tiptap",
|
|
8
|
+
"tiptap extension"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"funding": {
|
|
12
|
+
"type": "github",
|
|
13
|
+
"url": "https://github.com/sponsors/ueberdosis"
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/tiptap-extension-subscript.cjs.js",
|
|
16
|
+
"umd": "dist/tiptap-extension-subscript.umd.js",
|
|
17
|
+
"module": "dist/tiptap-extension-subscript.esm.js",
|
|
18
|
+
"types": "dist/packages/extension-subscript/src/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"src",
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@tiptap/core": "^2.0.0-beta.1"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
29
|
+
"directory": "packages/extension-subscript"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "270543995c92243fc27c4a688af6a93033fb4b7e"
|
|
32
|
+
}
|
package/src/index.ts
ADDED
package/src/subscript.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Mark, mergeAttributes } from '@tiptap/core'
|
|
2
|
+
|
|
3
|
+
export interface SubscriptExtensionOptions {
|
|
4
|
+
HTMLAttributes: Object,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module '@tiptap/core' {
|
|
8
|
+
interface Commands<ReturnType> {
|
|
9
|
+
subscript: {
|
|
10
|
+
/**
|
|
11
|
+
* Set a subscript mark
|
|
12
|
+
*/
|
|
13
|
+
setSubscript: () => ReturnType,
|
|
14
|
+
/**
|
|
15
|
+
* Toggle a subscript mark
|
|
16
|
+
*/
|
|
17
|
+
toggleSubscript: () => ReturnType,
|
|
18
|
+
/**
|
|
19
|
+
* Unset a subscript mark
|
|
20
|
+
*/
|
|
21
|
+
unsetSubscript: () => ReturnType,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Subscript = Mark.create<SubscriptExtensionOptions>({
|
|
27
|
+
name: 'subscript',
|
|
28
|
+
|
|
29
|
+
addOptions() {
|
|
30
|
+
return {
|
|
31
|
+
HTMLAttributes: {},
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
parseHTML() {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
tag: 'sub',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
style: 'vertical-align',
|
|
42
|
+
getAttrs(value) {
|
|
43
|
+
// Don’t match this rule if the vertical align isn’t sub.
|
|
44
|
+
if (value !== 'sub') {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If it falls through we’ll match, and this mark will be applied.
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
renderHTML({ HTMLAttributes }) {
|
|
55
|
+
return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
addCommands() {
|
|
59
|
+
return {
|
|
60
|
+
setSubscript: () => ({ commands }) => {
|
|
61
|
+
return commands.setMark(this.name)
|
|
62
|
+
},
|
|
63
|
+
toggleSubscript: () => ({ commands }) => {
|
|
64
|
+
return commands.toggleMark(this.name)
|
|
65
|
+
},
|
|
66
|
+
unsetSubscript: () => ({ commands }) => {
|
|
67
|
+
return commands.unsetMark(this.name)
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
addKeyboardShortcuts() {
|
|
73
|
+
return {
|
|
74
|
+
'Mod-,': () => this.editor.commands.toggleSubscript(),
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
})
|