tiptap-essentials 2.0.0-beta.1 → 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/block-spacing.d.ts +28 -0
- package/dist/block-spacing.js +52 -0
- package/dist/color.d.ts +13 -0
- package/dist/color.js +37 -0
- package/dist/font-size.d.ts +14 -4
- package/dist/font-size.js +23 -16
- package/dist/highlight.d.ts +19 -0
- package/dist/highlight.js +69 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +8 -1
- package/dist/line-height.d.ts +15 -0
- package/dist/line-height.js +43 -0
- package/dist/listed.d.ts +5 -0
- package/dist/listed.js +10 -0
- package/dist/samples.d.ts +4 -0
- package/dist/samples.js +6 -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/text-style.d.ts +7 -0
- package/dist/text-style.js +38 -0
- package/dist/tiptap-essentials.d.ts +18 -4
- package/dist/tiptap-essentials.js +37 -9
- package/package.json +3 -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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
export interface BlockSpacingOptions {
|
|
3
|
+
/** The blocks that can be spaced apart from those around them. */
|
|
4
|
+
types: string[];
|
|
5
|
+
/**
|
|
6
|
+
* The margin space before or after a block takes, as a body writes it:
|
|
7
|
+
* `var(--space-40)`. No space is read or set where null.
|
|
8
|
+
*/
|
|
9
|
+
space: string | null;
|
|
10
|
+
}
|
|
11
|
+
declare module '@tiptap/core' {
|
|
12
|
+
interface Commands<ReturnType> {
|
|
13
|
+
blockSpacing: {
|
|
14
|
+
/** Sets every block selected apart from the one before it. */
|
|
15
|
+
addSpaceBefore: () => ReturnType;
|
|
16
|
+
removeSpaceBefore: () => ReturnType;
|
|
17
|
+
/** Sets every block selected apart from the one after it. */
|
|
18
|
+
addSpaceAfter: () => ReturnType;
|
|
19
|
+
removeSpaceAfter: () => ReturnType;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Space before and after a block, as a word processor adds it: one more
|
|
25
|
+
* margin above or below a paragraph or a heading, the one its `space` names.
|
|
26
|
+
* A margin pasted in of any other size is read as none.
|
|
27
|
+
*/
|
|
28
|
+
export declare const BlockSpacing: Extension<BlockSpacingOptions, any>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Extension, getStyleProperty } from '@tiptap/core';
|
|
2
|
+
const MARGINS = {
|
|
3
|
+
spaceBefore: 'margin-top',
|
|
4
|
+
spaceAfter: 'margin-bottom'
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Space before and after a block, as a word processor adds it: one more
|
|
8
|
+
* margin above or below a paragraph or a heading, the one its `space` names.
|
|
9
|
+
* A margin pasted in of any other size is read as none.
|
|
10
|
+
*/
|
|
11
|
+
export const BlockSpacing = Extension.create({
|
|
12
|
+
name: 'blockSpacing',
|
|
13
|
+
addOptions() {
|
|
14
|
+
return {
|
|
15
|
+
types: ['paragraph', 'heading'],
|
|
16
|
+
space: null
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
addGlobalAttributes() {
|
|
20
|
+
const { types, space } = this.options;
|
|
21
|
+
const attribute = (side) => ({
|
|
22
|
+
default: null,
|
|
23
|
+
parseHTML: (element) => space !== null && getStyleProperty(element, MARGINS[side]) === space
|
|
24
|
+
? space
|
|
25
|
+
: null,
|
|
26
|
+
renderHTML: (attributes) => attributes[side]
|
|
27
|
+
? { style: `${MARGINS[side]}: ${attributes[side]}` }
|
|
28
|
+
: {}
|
|
29
|
+
});
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
types,
|
|
33
|
+
attributes: {
|
|
34
|
+
spaceBefore: attribute('spaceBefore'),
|
|
35
|
+
spaceAfter: attribute('spaceAfter')
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
},
|
|
40
|
+
addCommands() {
|
|
41
|
+
const set = (side, value) => () => ({ commands }) => this.options.space !== null &&
|
|
42
|
+
this.options.types
|
|
43
|
+
.map((type) => commands.updateAttributes(type, { [side]: value }))
|
|
44
|
+
.some((response) => response);
|
|
45
|
+
return {
|
|
46
|
+
addSpaceBefore: set('spaceBefore', this.options.space),
|
|
47
|
+
removeSpaceBefore: set('spaceBefore', null),
|
|
48
|
+
addSpaceAfter: set('spaceAfter', this.options.space),
|
|
49
|
+
removeSpaceAfter: set('spaceAfter', null)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ColorOptions as TiptapColorOptions } from '@tiptap/extension-text-style';
|
|
2
|
+
export interface ColorOptions extends TiptapColorOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The colours a text may take, as a body writes them:
|
|
5
|
+
* `var(--tiptap-text-red)`. Any colour where null.
|
|
6
|
+
*/
|
|
7
|
+
colors: string[] | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tiptap's text colour, held to a palette: a colour pasted in that is not one
|
|
11
|
+
* of it is read as none, and none is set.
|
|
12
|
+
*/
|
|
13
|
+
export declare const Color: import("@tiptap/core").Extension<ColorOptions, any>;
|
package/dist/color.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Color as TiptapColor } from '@tiptap/extension-text-style';
|
|
2
|
+
import { ifListed } from './listed.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tiptap's text colour, held to a palette: a colour pasted in that is not one
|
|
5
|
+
* of it is read as none, and none is set.
|
|
6
|
+
*/
|
|
7
|
+
export const Color = TiptapColor.extend({
|
|
8
|
+
addOptions() {
|
|
9
|
+
return {
|
|
10
|
+
...this.parent(),
|
|
11
|
+
colors: null
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
addGlobalAttributes() {
|
|
15
|
+
const { colors } = this.options;
|
|
16
|
+
return (this.parent?.() ?? []).map(({ types, attributes }) => {
|
|
17
|
+
const { color } = attributes;
|
|
18
|
+
return {
|
|
19
|
+
types,
|
|
20
|
+
attributes: {
|
|
21
|
+
color: {
|
|
22
|
+
...color,
|
|
23
|
+
parseHTML: (element) => ifListed(color?.parseHTML?.(element), colors)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
addCommands() {
|
|
30
|
+
const commands = this.parent();
|
|
31
|
+
return {
|
|
32
|
+
...commands,
|
|
33
|
+
setColor: (color) => (props) => ifListed(color, this.options.colors) !== null &&
|
|
34
|
+
commands.setColor(color)(props)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
package/dist/font-size.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
|
|
1
|
+
import { type FontSizeOptions as TiptapFontSizeOptions } from '@tiptap/extension-text-style';
|
|
2
|
+
export interface FontSizeOptions extends TiptapFontSizeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The sizes a text may take, as a body writes them: `var(--lg-font-size)`.
|
|
5
|
+
* Any where null.
|
|
6
|
+
*/
|
|
7
|
+
fontSizes: string[] | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tiptap's font size, held to a set of sizes, and reading 1.x's size classes
|
|
11
|
+
* as the sizes they stood for: a size pasted in that is not one of the set is
|
|
12
|
+
* read as none, and none is set.
|
|
13
|
+
*/
|
|
14
|
+
export declare const FontSize: import("@tiptap/core").Extension<FontSizeOptions, any>;
|
package/dist/font-size.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FontSize as TiptapFontSize
|
|
1
|
+
import { FontSize as TiptapFontSize } from '@tiptap/extension-text-style';
|
|
2
|
+
import { ifListed } from './listed.js';
|
|
2
3
|
// 1.x wrote a size as a span of one of these classes, each standing for one
|
|
3
4
|
// of the site's size properties.
|
|
4
5
|
const CLASS_SIZES = {
|
|
@@ -11,22 +12,20 @@ function classSize(element) {
|
|
|
11
12
|
const name = Array.from(element.classList).find((name) => name in CLASS_SIZES);
|
|
12
13
|
return name ? CLASS_SIZES[name] : null;
|
|
13
14
|
}
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
tag: 'span',
|
|
21
|
-
consuming: false,
|
|
22
|
-
getAttrs: (element) => (classSize(element) ? {} : false)
|
|
23
|
-
}
|
|
24
|
-
];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
/** Tiptap's font size, reading 1.x's size classes as the sizes they stood for. */
|
|
15
|
+
/**
|
|
16
|
+
* Tiptap's font size, held to a set of sizes, and reading 1.x's size classes
|
|
17
|
+
* as the sizes they stood for: a size pasted in that is not one of the set is
|
|
18
|
+
* read as none, and none is set.
|
|
19
|
+
*/
|
|
28
20
|
export const FontSize = TiptapFontSize.extend({
|
|
21
|
+
addOptions() {
|
|
22
|
+
return {
|
|
23
|
+
...this.parent(),
|
|
24
|
+
fontSizes: null
|
|
25
|
+
};
|
|
26
|
+
},
|
|
29
27
|
addGlobalAttributes() {
|
|
28
|
+
const { fontSizes } = this.options;
|
|
30
29
|
return (this.parent?.() ?? []).map(({ types, attributes }) => {
|
|
31
30
|
const { fontSize } = attributes;
|
|
32
31
|
return {
|
|
@@ -34,10 +33,18 @@ export const FontSize = TiptapFontSize.extend({
|
|
|
34
33
|
attributes: {
|
|
35
34
|
fontSize: {
|
|
36
35
|
...fontSize,
|
|
37
|
-
parseHTML: (element) => fontSize?.parseHTML?.(element) || classSize(element)
|
|
36
|
+
parseHTML: (element) => ifListed(fontSize?.parseHTML?.(element) || classSize(element), fontSizes)
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
};
|
|
41
40
|
});
|
|
41
|
+
},
|
|
42
|
+
addCommands() {
|
|
43
|
+
const commands = this.parent();
|
|
44
|
+
return {
|
|
45
|
+
...commands,
|
|
46
|
+
setFontSize: (fontSize) => (props) => ifListed(fontSize, this.options.fontSizes) !== null &&
|
|
47
|
+
commands.setFontSize(fontSize)(props)
|
|
48
|
+
};
|
|
42
49
|
}
|
|
43
50
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type HighlightOptions as TiptapHighlightOptions } from '@tiptap/extension-highlight';
|
|
2
|
+
export interface HighlightOptions extends TiptapHighlightOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The colours a highlight may take, as a body writes them:
|
|
5
|
+
* `var(--tiptap-highlight-yellow)`. Any colour where null.
|
|
6
|
+
*/
|
|
7
|
+
colors: string[] | null;
|
|
8
|
+
/**
|
|
9
|
+
* The colour of a highlight asked for without one, as its key and
|
|
10
|
+
* `==text==` ask. A highlight of no colour where null, which a browser
|
|
11
|
+
* draws in a yellow of its own.
|
|
12
|
+
*/
|
|
13
|
+
defaultColor: string | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Tiptap's highlight in many colours, held to a palette: a `mark` pasted in
|
|
17
|
+
* that is not of one of its colours is read as its text, and none is set.
|
|
18
|
+
*/
|
|
19
|
+
export declare const Highlight: import("@tiptap/core").Mark<HighlightOptions, any>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getStyleProperty, markInputRule, markPasteRule } from '@tiptap/core';
|
|
2
|
+
import { Highlight as TiptapHighlight, inputRegex, pasteRegex } from '@tiptap/extension-highlight';
|
|
3
|
+
import { ifListed } from './listed.js';
|
|
4
|
+
// Where Tiptap's highlight reads its colour from, the first it finds.
|
|
5
|
+
function colorOf(element) {
|
|
6
|
+
return (element.getAttribute('data-color') ||
|
|
7
|
+
getStyleProperty(element, 'background-color') ||
|
|
8
|
+
element.style.backgroundColor);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Tiptap's highlight in many colours, held to a palette: a `mark` pasted in
|
|
12
|
+
* that is not of one of its colours is read as its text, and none is set.
|
|
13
|
+
*/
|
|
14
|
+
export const Highlight = TiptapHighlight.extend({
|
|
15
|
+
addOptions() {
|
|
16
|
+
return {
|
|
17
|
+
...this.parent(),
|
|
18
|
+
multicolor: true,
|
|
19
|
+
colors: null,
|
|
20
|
+
defaultColor: null
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
parseHTML() {
|
|
24
|
+
const { colors } = this.options;
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
tag: 'mark',
|
|
28
|
+
getAttrs: (element) => colors === null || ifListed(colorOf(element), colors) !== null
|
|
29
|
+
? null
|
|
30
|
+
: false
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
},
|
|
34
|
+
addCommands() {
|
|
35
|
+
const commands = this.parent();
|
|
36
|
+
const { colors, defaultColor } = this.options;
|
|
37
|
+
const colored = (attributes) => attributes ?? (defaultColor ? { color: defaultColor } : undefined);
|
|
38
|
+
const allowed = (attributes) => colors === null || ifListed(attributes?.color, colors) !== null;
|
|
39
|
+
return {
|
|
40
|
+
...commands,
|
|
41
|
+
setHighlight: (attributes) => (props) => allowed(colored(attributes)) &&
|
|
42
|
+
commands.setHighlight(colored(attributes))(props),
|
|
43
|
+
toggleHighlight: (attributes) => (props) => allowed(colored(attributes)) &&
|
|
44
|
+
commands.toggleHighlight(colored(attributes))(props)
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
addInputRules() {
|
|
48
|
+
return [
|
|
49
|
+
markInputRule({
|
|
50
|
+
find: inputRegex,
|
|
51
|
+
type: this.type,
|
|
52
|
+
getAttributes: this.options.defaultColor
|
|
53
|
+
? { color: this.options.defaultColor }
|
|
54
|
+
: undefined
|
|
55
|
+
})
|
|
56
|
+
];
|
|
57
|
+
},
|
|
58
|
+
addPasteRules() {
|
|
59
|
+
return [
|
|
60
|
+
markPasteRule({
|
|
61
|
+
find: pasteRegex,
|
|
62
|
+
type: this.type,
|
|
63
|
+
getAttributes: this.options.defaultColor
|
|
64
|
+
? { color: this.options.defaultColor }
|
|
65
|
+
: undefined
|
|
66
|
+
})
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
export { TiptapEssentials } from './tiptap-essentials.js';
|
|
2
2
|
export type { TiptapEssentialsOptions } from './tiptap-essentials.js';
|
|
3
|
-
export {
|
|
3
|
+
export { BlockSpacing } from './block-spacing.js';
|
|
4
|
+
export type { BlockSpacingOptions } from './block-spacing.js';
|
|
5
|
+
export { Color } from './color.js';
|
|
6
|
+
export type { ColorOptions } from './color.js';
|
|
7
|
+
export { FontSize } from './font-size.js';
|
|
8
|
+
export type { FontSizeOptions } from './font-size.js';
|
|
9
|
+
export { Highlight } from './highlight.js';
|
|
10
|
+
export type { HighlightOptions } from './highlight.js';
|
|
4
11
|
export { Image } from './image.js';
|
|
5
12
|
export type { ImageAttributes, PictureSource } from './image.js';
|
|
13
|
+
export { LineHeight } from './line-height.js';
|
|
14
|
+
export type { LineHeightOptions } from './line-height.js';
|
|
6
15
|
export { PlainSpaces } from './plain-spaces.js';
|
|
16
|
+
export { Subscript } from './subscript.js';
|
|
17
|
+
export { Superscript } from './superscript.js';
|
|
7
18
|
export { Table } from './table.js';
|
|
8
19
|
export type { TableOptions } from './table.js';
|
|
20
|
+
export { TextStyle } from './text-style.js';
|
|
9
21
|
export { Youtube } from './youtube.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export { TiptapEssentials } from './tiptap-essentials.js';
|
|
2
|
-
export {
|
|
2
|
+
export { BlockSpacing } from './block-spacing.js';
|
|
3
|
+
export { Color } from './color.js';
|
|
4
|
+
export { FontSize } from './font-size.js';
|
|
5
|
+
export { Highlight } from './highlight.js';
|
|
3
6
|
export { Image } from './image.js';
|
|
7
|
+
export { LineHeight } from './line-height.js';
|
|
4
8
|
export { PlainSpaces } from './plain-spaces.js';
|
|
9
|
+
export { Subscript } from './subscript.js';
|
|
10
|
+
export { Superscript } from './superscript.js';
|
|
5
11
|
export { Table } from './table.js';
|
|
12
|
+
export { TextStyle } from './text-style.js';
|
|
6
13
|
export { Youtube } from './youtube.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type LineHeightOptions as TiptapLineHeightOptions } from '@tiptap/extension-text-style';
|
|
2
|
+
export interface LineHeightOptions extends TiptapLineHeightOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The line heights a block may take, as a body writes them:
|
|
5
|
+
* `var(--tiptap-line-height-150)`. Any where null.
|
|
6
|
+
*/
|
|
7
|
+
lineHeights: string[] | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tiptap's line height, on paragraphs and headings rather than a span, and
|
|
11
|
+
* held to a set of steps: one pasted in that is not a step is read as none.
|
|
12
|
+
* Tiptap's commands style a span inside the blocks, so these style the blocks
|
|
13
|
+
* themselves, every one the selection touches.
|
|
14
|
+
*/
|
|
15
|
+
export declare const LineHeight: import("@tiptap/core").Extension<LineHeightOptions, any>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LineHeight as TiptapLineHeight } from '@tiptap/extension-text-style';
|
|
2
|
+
import { ifListed } from './listed.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tiptap's line height, on paragraphs and headings rather than a span, and
|
|
5
|
+
* held to a set of steps: one pasted in that is not a step is read as none.
|
|
6
|
+
* Tiptap's commands style a span inside the blocks, so these style the blocks
|
|
7
|
+
* themselves, every one the selection touches.
|
|
8
|
+
*/
|
|
9
|
+
export const LineHeight = TiptapLineHeight.extend({
|
|
10
|
+
addOptions() {
|
|
11
|
+
return {
|
|
12
|
+
...this.parent(),
|
|
13
|
+
types: ['paragraph', 'heading'],
|
|
14
|
+
lineHeights: null
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
addGlobalAttributes() {
|
|
18
|
+
const { lineHeights } = this.options;
|
|
19
|
+
return (this.parent?.() ?? []).map(({ types, attributes }) => {
|
|
20
|
+
const { lineHeight } = attributes;
|
|
21
|
+
return {
|
|
22
|
+
types,
|
|
23
|
+
attributes: {
|
|
24
|
+
lineHeight: {
|
|
25
|
+
...lineHeight,
|
|
26
|
+
parseHTML: (element) => ifListed(lineHeight?.parseHTML?.(element), lineHeights)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
addCommands() {
|
|
33
|
+
return {
|
|
34
|
+
setLineHeight: (lineHeight) => ({ commands }) => ifListed(lineHeight, this.options.lineHeights) !== null &&
|
|
35
|
+
this.options.types
|
|
36
|
+
.map((type) => commands.updateAttributes(type, { lineHeight }))
|
|
37
|
+
.some((response) => response),
|
|
38
|
+
unsetLineHeight: () => ({ commands }) => this.options.types
|
|
39
|
+
.map((type) => commands.resetAttributes(type, 'lineHeight'))
|
|
40
|
+
.some((response) => response)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
package/dist/listed.d.ts
ADDED
package/dist/listed.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value read from a body, kept only where the list of the values it may take
|
|
3
|
+
* names it as it is written. Without a list, any value is kept.
|
|
4
|
+
*/
|
|
5
|
+
export function ifListed(value, list) {
|
|
6
|
+
if (typeof value !== 'string') {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return list === null || list.includes(value) ? value : null;
|
|
10
|
+
}
|
package/dist/samples.d.ts
CHANGED
|
@@ -7,3 +7,7 @@ export declare const picture: string;
|
|
|
7
7
|
export declare const table: string;
|
|
8
8
|
export declare const video: string;
|
|
9
9
|
export declare const size = "<p><span style=\"font-size: var(--lg-font-size);\">Large</span> text</p>";
|
|
10
|
+
export declare const color = "<p><span style=\"color: var(--tiptap-text-red);\">Red</span> text</p>";
|
|
11
|
+
export declare const highlight: string;
|
|
12
|
+
export declare const spacing: string;
|
|
13
|
+
export declare const subscript = "<p>H<sub>2</sub>O</p>";
|
package/dist/samples.js
CHANGED
|
@@ -15,3 +15,9 @@ export const table = '<div class="table-responsive" role="region" tabindex="0" a
|
|
|
15
15
|
export const video = '<div data-youtube-video=""><iframe width="640" height="480" allowfullscreen="true" ' +
|
|
16
16
|
'src="https://www.youtube.com/embed/M7lc1UVf-VE?start=90&rel=1" title="A talk"></iframe></div>';
|
|
17
17
|
export const size = '<p><span style="font-size: var(--lg-font-size);">Large</span> text</p>';
|
|
18
|
+
export const color = '<p><span style="color: var(--tiptap-text-red);">Red</span> text</p>';
|
|
19
|
+
export const highlight = '<p><mark data-color="var(--tiptap-highlight-yellow)" ' +
|
|
20
|
+
'style="background-color: var(--tiptap-highlight-yellow); color: inherit;">Marked</mark> text</p>';
|
|
21
|
+
export const spacing = '<p style="line-height: var(--tiptap-line-height-150); margin-top: var(--space-40); ' +
|
|
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
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiptap's text style, reading a span only where a style a text keeps is on
|
|
3
|
+
* it — a colour of the palette, one of the sizes. A span whose every style is
|
|
4
|
+
* dropped, a colour off the palette or a font, is read as its text, where
|
|
5
|
+
* Tiptap's would keep it as a bare span.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TextStyle: import("@tiptap/core").Mark<import("@tiptap/extension-text-style").TextStyleOptions, any>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getAttributesFromExtensions } from '@tiptap/core';
|
|
2
|
+
import { TextStyle as TiptapTextStyle } from '@tiptap/extension-text-style';
|
|
3
|
+
/**
|
|
4
|
+
* Tiptap's text style, reading a span only where a style a text keeps is on
|
|
5
|
+
* it — a colour of the palette, one of the sizes. A span whose every style is
|
|
6
|
+
* dropped, a colour off the palette or a font, is read as its text, where
|
|
7
|
+
* Tiptap's would keep it as a bare span.
|
|
8
|
+
*/
|
|
9
|
+
export const TextStyle = TiptapTextStyle.extend({
|
|
10
|
+
parseHTML() {
|
|
11
|
+
const { editor, name } = this;
|
|
12
|
+
const [styled] = (this.parent?.() ?? []);
|
|
13
|
+
let styles;
|
|
14
|
+
// The text's styles are read as a body is, the editor built by then.
|
|
15
|
+
const keepsAStyle = (element) => {
|
|
16
|
+
if (!editor) {
|
|
17
|
+
return element.hasAttribute('style');
|
|
18
|
+
}
|
|
19
|
+
styles ??= getAttributesFromExtensions(editor.extensionManager.extensions).filter(({ type }) => type === name);
|
|
20
|
+
return styles.some(({ attribute }) => {
|
|
21
|
+
const value = attribute.parseHTML?.(element);
|
|
22
|
+
return typeof value === 'string' ? value.trim() !== '' : value != null;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
tag: 'span',
|
|
28
|
+
consuming: false,
|
|
29
|
+
getAttrs: (element) => {
|
|
30
|
+
// Tiptap's reading of a styled span hands the styles of a span
|
|
31
|
+
// inside it on to that span, which is read on its own.
|
|
32
|
+
styled?.getAttrs?.(element);
|
|
33
|
+
return keepsAStyle(element) ? {} : false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -1,11 +1,17 @@
|
|
|
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
|
-
import { type
|
|
7
|
+
import { type TextStyleKitOptions } from '@tiptap/extension-text-style';
|
|
7
8
|
import type { YoutubeOptions } from '@tiptap/extension-youtube';
|
|
8
9
|
import { type StarterKitOptions } from '@tiptap/starter-kit';
|
|
10
|
+
import { type BlockSpacingOptions } from './block-spacing.js';
|
|
11
|
+
import { type ColorOptions } from './color.js';
|
|
12
|
+
import { type FontSizeOptions } from './font-size.js';
|
|
13
|
+
import { type HighlightOptions } from './highlight.js';
|
|
14
|
+
import { type LineHeightOptions } from './line-height.js';
|
|
9
15
|
import { type TableOptions } from './table.js';
|
|
10
16
|
type Part<Options> = Partial<Options> | false;
|
|
11
17
|
export interface TiptapEssentialsOptions {
|
|
@@ -14,12 +20,20 @@ export interface TiptapEssentialsOptions {
|
|
|
14
20
|
tableKit: (Partial<Omit<TableKitOptions, 'table'>> & {
|
|
15
21
|
table?: Part<TableOptions>;
|
|
16
22
|
}) | false;
|
|
17
|
-
/**
|
|
18
|
-
|
|
23
|
+
/**
|
|
24
|
+
* TextStyleKit's options, its text style, font size, colour and line height
|
|
25
|
+
* being the library's.
|
|
26
|
+
*/
|
|
27
|
+
textStyleKit: (Partial<Omit<TextStyleKitOptions, 'fontSize' | 'color' | 'lineHeight'>> & {
|
|
19
28
|
fontSize?: Part<FontSizeOptions>;
|
|
29
|
+
color?: Part<ColorOptions>;
|
|
30
|
+
lineHeight?: Part<LineHeightOptions>;
|
|
20
31
|
}) | false;
|
|
32
|
+
highlight: Part<HighlightOptions>;
|
|
33
|
+
blockSpacing: Part<BlockSpacingOptions>;
|
|
21
34
|
textAlign: Part<TextAlignOptions>;
|
|
22
35
|
superscript: Part<SuperscriptExtensionOptions>;
|
|
36
|
+
subscript: Part<SubscriptExtensionOptions>;
|
|
23
37
|
image: Part<ImageOptions>;
|
|
24
38
|
youtube: Part<YoutubeOptions>;
|
|
25
39
|
plainSpaces: Record<string, never> | false;
|
|
@@ -1,13 +1,19 @@
|
|
|
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
|
-
import {
|
|
4
|
+
import { TextStyleKit } from '@tiptap/extension-text-style';
|
|
6
5
|
import StarterKit, {} from '@tiptap/starter-kit';
|
|
7
|
-
import {
|
|
6
|
+
import { BlockSpacing } from './block-spacing.js';
|
|
7
|
+
import { Color } from './color.js';
|
|
8
|
+
import { FontSize } from './font-size.js';
|
|
9
|
+
import { Highlight } from './highlight.js';
|
|
8
10
|
import { Image } from './image.js';
|
|
11
|
+
import { LineHeight } from './line-height.js';
|
|
9
12
|
import { PlainSpaces } from './plain-spaces.js';
|
|
13
|
+
import { Subscript } from './subscript.js';
|
|
14
|
+
import { Superscript } from './superscript.js';
|
|
10
15
|
import { Table } from './table.js';
|
|
16
|
+
import { TextStyle } from './text-style.js';
|
|
11
17
|
import { Youtube } from './youtube.js';
|
|
12
18
|
/**
|
|
13
19
|
* Tiptap's kits and the library's own parts as one extension, each part
|
|
@@ -24,14 +30,17 @@ export const TiptapEssentials = Extension.create({
|
|
|
24
30
|
types: ['heading', 'paragraph'],
|
|
25
31
|
alignments: ['start', 'end', 'left', 'center', 'right', 'justify']
|
|
26
32
|
},
|
|
33
|
+
highlight: {},
|
|
34
|
+
blockSpacing: {},
|
|
27
35
|
superscript: {},
|
|
36
|
+
subscript: {},
|
|
28
37
|
image: {},
|
|
29
38
|
youtube: {},
|
|
30
39
|
plainSpaces: {}
|
|
31
40
|
};
|
|
32
41
|
},
|
|
33
42
|
addExtensions() {
|
|
34
|
-
const { starterKit, tableKit, textStyleKit, textAlign, superscript, image, youtube, plainSpaces } = this.options;
|
|
43
|
+
const { starterKit, tableKit, textStyleKit, highlight, blockSpacing, textAlign, superscript, subscript, image, youtube, plainSpaces } = this.options;
|
|
35
44
|
const extensions = [];
|
|
36
45
|
if (starterKit !== false) {
|
|
37
46
|
extensions.push(StarterKit.configure(starterKit));
|
|
@@ -44,16 +53,32 @@ export const TiptapEssentials = Extension.create({
|
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
if (textStyleKit !== false) {
|
|
47
|
-
const { fontSize = {}, textStyle = {}, ...rest } = textStyleKit;
|
|
48
|
-
extensions.push(TextStyleKit.configure({
|
|
56
|
+
const { fontSize = {}, color = {}, lineHeight = {}, textStyle = {}, ...rest } = textStyleKit;
|
|
57
|
+
extensions.push(TextStyleKit.configure({
|
|
58
|
+
...rest,
|
|
59
|
+
fontSize: false,
|
|
60
|
+
color: false,
|
|
61
|
+
lineHeight: false,
|
|
62
|
+
textStyle: false
|
|
63
|
+
}));
|
|
49
64
|
if (textStyle !== false) {
|
|
50
|
-
|
|
51
|
-
const style = fontSize === false ? TiptapTextStyle : TextStyle;
|
|
52
|
-
extensions.push(style.configure(textStyle));
|
|
65
|
+
extensions.push(TextStyle.configure(textStyle));
|
|
53
66
|
}
|
|
54
67
|
if (fontSize !== false) {
|
|
55
68
|
extensions.push(FontSize.configure(fontSize));
|
|
56
69
|
}
|
|
70
|
+
if (color !== false) {
|
|
71
|
+
extensions.push(Color.configure(color));
|
|
72
|
+
}
|
|
73
|
+
if (lineHeight !== false) {
|
|
74
|
+
extensions.push(LineHeight.configure(lineHeight));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (highlight !== false) {
|
|
78
|
+
extensions.push(Highlight.configure(highlight));
|
|
79
|
+
}
|
|
80
|
+
if (blockSpacing !== false) {
|
|
81
|
+
extensions.push(BlockSpacing.configure(blockSpacing));
|
|
57
82
|
}
|
|
58
83
|
if (textAlign !== false) {
|
|
59
84
|
extensions.push(TextAlign.configure(textAlign));
|
|
@@ -61,6 +86,9 @@ export const TiptapEssentials = Extension.create({
|
|
|
61
86
|
if (superscript !== false) {
|
|
62
87
|
extensions.push(Superscript.configure(superscript));
|
|
63
88
|
}
|
|
89
|
+
if (subscript !== false) {
|
|
90
|
+
extensions.push(Subscript.configure(subscript));
|
|
91
|
+
}
|
|
64
92
|
if (image !== false) {
|
|
65
93
|
extensions.push(Image.configure(image));
|
|
66
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": {
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"@tiptap/pm": "^3.35.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@tiptap/extension-highlight": "^3.35.0",
|
|
36
37
|
"@tiptap/extension-image": "^3.35.0",
|
|
38
|
+
"@tiptap/extension-subscript": "^3.35.0",
|
|
37
39
|
"@tiptap/extension-superscript": "^3.35.0",
|
|
38
40
|
"@tiptap/extension-table": "^3.35.0",
|
|
39
41
|
"@tiptap/extension-text-align": "^3.35.0",
|