tiptap-essentials 2.0.0-beta.3 → 2.0.0-beta.4
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/baseline-shift.d.ts +15 -0
- package/dist/baseline-shift.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/samples.d.ts +1 -0
- package/dist/samples.js +1 -0
- package/dist/subscript.d.ts +4 -0
- package/dist/subscript.js +16 -0
- package/dist/superscript.d.ts +4 -0
- package/dist/superscript.js +16 -0
- package/dist/tiptap-essentials.d.ts +3 -1
- package/dist/tiptap-essentials.js +7 -2
- package/package.json +2 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChainedCommands } from '@tiptap/core';
|
|
2
|
+
import type { MarkType } from '@tiptap/pm/model';
|
|
3
|
+
/**
|
|
4
|
+
* The group of the marks that shift text off its baseline, subscript and
|
|
5
|
+
* superscript. Each of them excludes the group, so text is lowered or raised
|
|
6
|
+
* but never both: setting one takes the other off.
|
|
7
|
+
*/
|
|
8
|
+
export declare const BASELINE_SHIFT = "baselineShift";
|
|
9
|
+
/**
|
|
10
|
+
* Takes every other shift off the text, in a chain, ahead of setting `type`.
|
|
11
|
+
* ProseMirror would take them off as `type` went on, but Tiptap's `setMark`
|
|
12
|
+
* and `toggleMark` would answer that they had done nothing, which leaves
|
|
13
|
+
* their key to the browser: on a Mac, Cmd+, would open its settings as well.
|
|
14
|
+
*/
|
|
15
|
+
export declare function unsetOtherShifts(chain: ChainedCommands, type: MarkType): ChainedCommands;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The group of the marks that shift text off its baseline, subscript and
|
|
3
|
+
* superscript. Each of them excludes the group, so text is lowered or raised
|
|
4
|
+
* but never both: setting one takes the other off.
|
|
5
|
+
*/
|
|
6
|
+
export const BASELINE_SHIFT = 'baselineShift';
|
|
7
|
+
/**
|
|
8
|
+
* Takes every other shift off the text, in a chain, ahead of setting `type`.
|
|
9
|
+
* ProseMirror would take them off as `type` went on, but Tiptap's `setMark`
|
|
10
|
+
* and `toggleMark` would answer that they had done nothing, which leaves
|
|
11
|
+
* their key to the browser: on a Mac, Cmd+, would open its settings as well.
|
|
12
|
+
*/
|
|
13
|
+
export function unsetOtherShifts(chain, type) {
|
|
14
|
+
for (const other of Object.values(type.schema.marks)) {
|
|
15
|
+
if (other !== type && type.excludes(other)) {
|
|
16
|
+
chain.unsetMark(other);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return chain;
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export type { ImageAttributes, PictureSource } from './image.js';
|
|
|
13
13
|
export { LineHeight } from './line-height.js';
|
|
14
14
|
export type { LineHeightOptions } from './line-height.js';
|
|
15
15
|
export { PlainSpaces } from './plain-spaces.js';
|
|
16
|
+
export { Subscript } from './subscript.js';
|
|
17
|
+
export { Superscript } from './superscript.js';
|
|
16
18
|
export { Table } from './table.js';
|
|
17
19
|
export type { TableOptions } from './table.js';
|
|
18
20
|
export { TextStyle } from './text-style.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export { Highlight } from './highlight.js';
|
|
|
6
6
|
export { Image } from './image.js';
|
|
7
7
|
export { LineHeight } from './line-height.js';
|
|
8
8
|
export { PlainSpaces } from './plain-spaces.js';
|
|
9
|
+
export { Subscript } from './subscript.js';
|
|
10
|
+
export { Superscript } from './superscript.js';
|
|
9
11
|
export { Table } from './table.js';
|
|
10
12
|
export { TextStyle } from './text-style.js';
|
|
11
13
|
export { Youtube } from './youtube.js';
|
package/dist/samples.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare const size = "<p><span style=\"font-size: var(--lg-font-size);\">
|
|
|
10
10
|
export declare const color = "<p><span style=\"color: var(--tiptap-text-red);\">Red</span> text</p>";
|
|
11
11
|
export declare const highlight: string;
|
|
12
12
|
export declare const spacing: string;
|
|
13
|
+
export declare const subscript = "<p>H<sub>2</sub>O</p>";
|
package/dist/samples.js
CHANGED
|
@@ -20,3 +20,4 @@ export const highlight = '<p><mark data-color="var(--tiptap-highlight-yellow)" '
|
|
|
20
20
|
'style="background-color: var(--tiptap-highlight-yellow); color: inherit;">Marked</mark> text</p>';
|
|
21
21
|
export const spacing = '<p style="line-height: var(--tiptap-line-height-150); margin-top: var(--space-40); ' +
|
|
22
22
|
'margin-bottom: var(--space-40);">Spaced</p>';
|
|
23
|
+
export const subscript = '<p>H<sub>2</sub>O</p>';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Subscript as TiptapSubscript } from '@tiptap/extension-subscript';
|
|
2
|
+
import { BASELINE_SHIFT, unsetOtherShifts } from './baseline-shift.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tiptap's subscript, taking superscript off the text it lowers.
|
|
5
|
+
*/
|
|
6
|
+
export const Subscript = TiptapSubscript.extend({
|
|
7
|
+
group: BASELINE_SHIFT,
|
|
8
|
+
excludes: BASELINE_SHIFT,
|
|
9
|
+
addCommands() {
|
|
10
|
+
return {
|
|
11
|
+
...this.parent(),
|
|
12
|
+
setSubscript: () => ({ chain }) => unsetOtherShifts(chain(), this.type).setMark(this.type).run(),
|
|
13
|
+
toggleSubscript: () => ({ chain }) => unsetOtherShifts(chain(), this.type).toggleMark(this.type).run()
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Superscript as TiptapSuperscript } from '@tiptap/extension-superscript';
|
|
2
|
+
import { BASELINE_SHIFT, unsetOtherShifts } from './baseline-shift.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tiptap's superscript, taking subscript off the text it raises.
|
|
5
|
+
*/
|
|
6
|
+
export const Superscript = TiptapSuperscript.extend({
|
|
7
|
+
group: BASELINE_SHIFT,
|
|
8
|
+
excludes: BASELINE_SHIFT,
|
|
9
|
+
addCommands() {
|
|
10
|
+
return {
|
|
11
|
+
...this.parent(),
|
|
12
|
+
setSuperscript: () => ({ chain }) => unsetOtherShifts(chain(), this.type).setMark(this.type).run(),
|
|
13
|
+
toggleSuperscript: () => ({ chain }) => unsetOtherShifts(chain(), this.type).toggleMark(this.type).run()
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/core';
|
|
2
2
|
import type { ImageOptions } from '@tiptap/extension-image';
|
|
3
|
-
import {
|
|
3
|
+
import type { SubscriptExtensionOptions } from '@tiptap/extension-subscript';
|
|
4
|
+
import type { SuperscriptExtensionOptions } from '@tiptap/extension-superscript';
|
|
4
5
|
import { type TableKitOptions } from '@tiptap/extension-table';
|
|
5
6
|
import { type TextAlignOptions } from '@tiptap/extension-text-align';
|
|
6
7
|
import { type TextStyleKitOptions } from '@tiptap/extension-text-style';
|
|
@@ -32,6 +33,7 @@ export interface TiptapEssentialsOptions {
|
|
|
32
33
|
blockSpacing: Part<BlockSpacingOptions>;
|
|
33
34
|
textAlign: Part<TextAlignOptions>;
|
|
34
35
|
superscript: Part<SuperscriptExtensionOptions>;
|
|
36
|
+
subscript: Part<SubscriptExtensionOptions>;
|
|
35
37
|
image: Part<ImageOptions>;
|
|
36
38
|
youtube: Part<YoutubeOptions>;
|
|
37
39
|
plainSpaces: Record<string, never> | false;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/core';
|
|
2
|
-
import Superscript, {} from '@tiptap/extension-superscript';
|
|
3
2
|
import { TableKit } from '@tiptap/extension-table';
|
|
4
3
|
import TextAlign, {} from '@tiptap/extension-text-align';
|
|
5
4
|
import { TextStyleKit } from '@tiptap/extension-text-style';
|
|
@@ -11,6 +10,8 @@ import { Highlight } from './highlight.js';
|
|
|
11
10
|
import { Image } from './image.js';
|
|
12
11
|
import { LineHeight } from './line-height.js';
|
|
13
12
|
import { PlainSpaces } from './plain-spaces.js';
|
|
13
|
+
import { Subscript } from './subscript.js';
|
|
14
|
+
import { Superscript } from './superscript.js';
|
|
14
15
|
import { Table } from './table.js';
|
|
15
16
|
import { TextStyle } from './text-style.js';
|
|
16
17
|
import { Youtube } from './youtube.js';
|
|
@@ -32,13 +33,14 @@ export const TiptapEssentials = Extension.create({
|
|
|
32
33
|
highlight: {},
|
|
33
34
|
blockSpacing: {},
|
|
34
35
|
superscript: {},
|
|
36
|
+
subscript: {},
|
|
35
37
|
image: {},
|
|
36
38
|
youtube: {},
|
|
37
39
|
plainSpaces: {}
|
|
38
40
|
};
|
|
39
41
|
},
|
|
40
42
|
addExtensions() {
|
|
41
|
-
const { starterKit, tableKit, textStyleKit, highlight, blockSpacing, textAlign, superscript, image, youtube, plainSpaces } = this.options;
|
|
43
|
+
const { starterKit, tableKit, textStyleKit, highlight, blockSpacing, textAlign, superscript, subscript, image, youtube, plainSpaces } = this.options;
|
|
42
44
|
const extensions = [];
|
|
43
45
|
if (starterKit !== false) {
|
|
44
46
|
extensions.push(StarterKit.configure(starterKit));
|
|
@@ -84,6 +86,9 @@ export const TiptapEssentials = Extension.create({
|
|
|
84
86
|
if (superscript !== false) {
|
|
85
87
|
extensions.push(Superscript.configure(superscript));
|
|
86
88
|
}
|
|
89
|
+
if (subscript !== false) {
|
|
90
|
+
extensions.push(Subscript.configure(subscript));
|
|
91
|
+
}
|
|
87
92
|
if (image !== false) {
|
|
88
93
|
extensions.push(Image.configure(image));
|
|
89
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiptap-essentials",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.4",
|
|
4
4
|
"description": "Essential extensions of Tiptap",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@tiptap/extension-highlight": "^3.35.0",
|
|
37
37
|
"@tiptap/extension-image": "^3.35.0",
|
|
38
|
+
"@tiptap/extension-subscript": "^3.35.0",
|
|
38
39
|
"@tiptap/extension-superscript": "^3.35.0",
|
|
39
40
|
"@tiptap/extension-table": "^3.35.0",
|
|
40
41
|
"@tiptap/extension-text-align": "^3.35.0",
|