@tiptap/extension-highlight 2.0.0-beta.212 → 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 +82 -86
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +78 -89
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +91 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/{index.d.ts → packages/extension-highlight/src/highlight.d.ts} +30 -33
- package/dist/packages/extension-highlight/src/index.d.ts +3 -0
- package/package.json +7 -16
package/dist/index.cjs
CHANGED
|
@@ -1,91 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
4
|
|
|
5
|
+
var core = require('@tiptap/core');
|
|
4
6
|
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
80
|
-
];
|
|
81
|
-
}
|
|
7
|
+
const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
8
|
+
const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
9
|
+
const Highlight = core.Mark.create({
|
|
10
|
+
name: 'highlight',
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
multicolor: false,
|
|
14
|
+
HTMLAttributes: {},
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
addAttributes() {
|
|
18
|
+
if (!this.options.multicolor) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
color: {
|
|
23
|
+
default: null,
|
|
24
|
+
parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
|
|
25
|
+
renderHTML: attributes => {
|
|
26
|
+
if (!attributes.color) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
'data-color': attributes.color,
|
|
31
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
parseHTML() {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
tag: 'mark',
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
renderHTML({ HTMLAttributes }) {
|
|
45
|
+
return ['mark', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
46
|
+
},
|
|
47
|
+
addCommands() {
|
|
48
|
+
return {
|
|
49
|
+
setHighlight: attributes => ({ commands }) => {
|
|
50
|
+
return commands.setMark(this.name, attributes);
|
|
51
|
+
},
|
|
52
|
+
toggleHighlight: attributes => ({ commands }) => {
|
|
53
|
+
return commands.toggleMark(this.name, attributes);
|
|
54
|
+
},
|
|
55
|
+
unsetHighlight: () => ({ commands }) => {
|
|
56
|
+
return commands.unsetMark(this.name);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
addKeyboardShortcuts() {
|
|
61
|
+
return {
|
|
62
|
+
'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
addInputRules() {
|
|
66
|
+
return [
|
|
67
|
+
core.markInputRule({
|
|
68
|
+
find: inputRegex,
|
|
69
|
+
type: this.type,
|
|
70
|
+
}),
|
|
71
|
+
];
|
|
72
|
+
},
|
|
73
|
+
addPasteRules() {
|
|
74
|
+
return [
|
|
75
|
+
core.markPasteRule({
|
|
76
|
+
find: pasteRegex,
|
|
77
|
+
type: this.type,
|
|
78
|
+
}),
|
|
79
|
+
];
|
|
80
|
+
},
|
|
82
81
|
});
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
exports.Highlight = Highlight; exports.default = src_default; exports.inputRegex = inputRegex; exports.pasteRegex = pasteRegex;
|
|
83
|
+
exports.Highlight = Highlight;
|
|
84
|
+
exports["default"] = Highlight;
|
|
85
|
+
exports.inputRegex = inputRegex;
|
|
86
|
+
exports.pasteRegex = pasteRegex;
|
|
87
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Mark,\n markInputRule,\n markPasteRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface HighlightOptions {\n multicolor: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))$/\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))/g\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n addOptions() {\n return {\n multicolor: false,\n HTMLAttributes: {},\n }\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}; color: inherit`,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'mark',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setHighlight: attributes => ({ commands }) => {\n return commands.setMark(this.name, attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;AA+BO,MAAM,UAAU,GAAG,sCAAqC;AACx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
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
find: pasteRegex,
|
|
78
|
-
type: this.type
|
|
79
|
-
})
|
|
80
|
-
];
|
|
81
|
-
}
|
|
1
|
+
import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
4
|
+
const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
5
|
+
const Highlight = Mark.create({
|
|
6
|
+
name: 'highlight',
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
multicolor: false,
|
|
10
|
+
HTMLAttributes: {},
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
addAttributes() {
|
|
14
|
+
if (!this.options.multicolor) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
color: {
|
|
19
|
+
default: null,
|
|
20
|
+
parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
|
|
21
|
+
renderHTML: attributes => {
|
|
22
|
+
if (!attributes.color) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
'data-color': attributes.color,
|
|
27
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
parseHTML() {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
tag: 'mark',
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
},
|
|
40
|
+
renderHTML({ HTMLAttributes }) {
|
|
41
|
+
return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
42
|
+
},
|
|
43
|
+
addCommands() {
|
|
44
|
+
return {
|
|
45
|
+
setHighlight: attributes => ({ commands }) => {
|
|
46
|
+
return commands.setMark(this.name, attributes);
|
|
47
|
+
},
|
|
48
|
+
toggleHighlight: attributes => ({ commands }) => {
|
|
49
|
+
return commands.toggleMark(this.name, attributes);
|
|
50
|
+
},
|
|
51
|
+
unsetHighlight: () => ({ commands }) => {
|
|
52
|
+
return commands.unsetMark(this.name);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
addKeyboardShortcuts() {
|
|
57
|
+
return {
|
|
58
|
+
'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
addInputRules() {
|
|
62
|
+
return [
|
|
63
|
+
markInputRule({
|
|
64
|
+
find: inputRegex,
|
|
65
|
+
type: this.type,
|
|
66
|
+
}),
|
|
67
|
+
];
|
|
68
|
+
},
|
|
69
|
+
addPasteRules() {
|
|
70
|
+
return [
|
|
71
|
+
markPasteRule({
|
|
72
|
+
find: pasteRegex,
|
|
73
|
+
type: this.type,
|
|
74
|
+
}),
|
|
75
|
+
];
|
|
76
|
+
},
|
|
82
77
|
});
|
|
83
78
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export {
|
|
87
|
-
Highlight,
|
|
88
|
-
src_default as default,
|
|
89
|
-
inputRegex,
|
|
90
|
-
pasteRegex
|
|
91
|
-
};
|
|
79
|
+
export { Highlight, Highlight as default, inputRegex, pasteRegex };
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Mark,\n markInputRule,\n markPasteRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface HighlightOptions {\n multicolor: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))$/\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))/g\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n addOptions() {\n return {\n multicolor: false,\n HTMLAttributes: {},\n }\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}; color: inherit`,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'mark',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setHighlight: attributes => ({ commands }) => {\n return commands.setMark(this.name, attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;AA+BO,MAAM,UAAU,GAAG,sCAAqC;AACxD,MAAM,UAAU,GAAG,sCAAqC;AAElD,MAAA,SAAS,GAAG,IAAI,CAAC,MAAM,CAAmB;AACrD,IAAA,IAAI,EAAE,WAAW;IAEjB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,UAAU,EAAE,KAAK;AACjB,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,aAAa,GAAA;AACX,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;AAC5B,YAAA,OAAO,EAAE,CAAA;AACV,SAAA;QAED,OAAO;AACL,YAAA,KAAK,EAAE;AACL,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;gBACzF,UAAU,EAAE,UAAU,IAAG;AACvB,oBAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACrB,wBAAA,OAAO,EAAE,CAAA;AACV,qBAAA;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;AAC9B,wBAAA,KAAK,EAAE,CAAA,kBAAA,EAAqB,UAAU,CAAC,KAAK,CAAkB,gBAAA,CAAA;qBAC/D,CAAA;iBACF;AACF,aAAA;SACF,CAAA;KACF;IAED,SAAS,GAAA;QACP,OAAO;AACL,YAAA;AACE,gBAAA,GAAG,EAAE,MAAM;AACZ,aAAA;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;AAC3B,QAAA,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW,GAAA;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBAC3C,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;aAC/C;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBAC9C,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;aAClD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAI;gBACrC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACrC;SACF,CAAA;KACF;IAED,oBAAoB,GAAA;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAA,aAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAA,aAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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-highlight"] = {}, global.core));
|
|
5
|
+
})(this, (function (exports, core) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
8
|
+
const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
9
|
+
const Highlight = core.Mark.create({
|
|
10
|
+
name: 'highlight',
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
multicolor: false,
|
|
14
|
+
HTMLAttributes: {},
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
addAttributes() {
|
|
18
|
+
if (!this.options.multicolor) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
color: {
|
|
23
|
+
default: null,
|
|
24
|
+
parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
|
|
25
|
+
renderHTML: attributes => {
|
|
26
|
+
if (!attributes.color) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
'data-color': attributes.color,
|
|
31
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
parseHTML() {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
tag: 'mark',
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
renderHTML({ HTMLAttributes }) {
|
|
45
|
+
return ['mark', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
46
|
+
},
|
|
47
|
+
addCommands() {
|
|
48
|
+
return {
|
|
49
|
+
setHighlight: attributes => ({ commands }) => {
|
|
50
|
+
return commands.setMark(this.name, attributes);
|
|
51
|
+
},
|
|
52
|
+
toggleHighlight: attributes => ({ commands }) => {
|
|
53
|
+
return commands.toggleMark(this.name, attributes);
|
|
54
|
+
},
|
|
55
|
+
unsetHighlight: () => ({ commands }) => {
|
|
56
|
+
return commands.unsetMark(this.name);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
addKeyboardShortcuts() {
|
|
61
|
+
return {
|
|
62
|
+
'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
addInputRules() {
|
|
66
|
+
return [
|
|
67
|
+
core.markInputRule({
|
|
68
|
+
find: inputRegex,
|
|
69
|
+
type: this.type,
|
|
70
|
+
}),
|
|
71
|
+
];
|
|
72
|
+
},
|
|
73
|
+
addPasteRules() {
|
|
74
|
+
return [
|
|
75
|
+
core.markPasteRule({
|
|
76
|
+
find: pasteRegex,
|
|
77
|
+
type: this.type,
|
|
78
|
+
}),
|
|
79
|
+
];
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
exports.Highlight = Highlight;
|
|
84
|
+
exports["default"] = Highlight;
|
|
85
|
+
exports.inputRegex = inputRegex;
|
|
86
|
+
exports.pasteRegex = pasteRegex;
|
|
87
|
+
|
|
88
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
89
|
+
|
|
90
|
+
}));
|
|
91
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Mark,\n markInputRule,\n markPasteRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface HighlightOptions {\n multicolor: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))$/\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))/g\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n addOptions() {\n return {\n multicolor: false,\n HTMLAttributes: {},\n }\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}; color: inherit`,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'mark',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setHighlight: attributes => ({ commands }) => {\n return commands.setMark(this.name, attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;AA+BO,QAAM,UAAU,GAAG,sCAAqC;AACxD,QAAM,UAAU,GAAG,sCAAqC;AAElD,QAAA,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;EACrD,IAAA,IAAI,EAAE,WAAW;MAEjB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,UAAU,EAAE,KAAK;EACjB,YAAA,cAAc,EAAE,EAAE;WACnB,CAAA;OACF;MAED,aAAa,GAAA;EACX,QAAA,IAAI,CAAC,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,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;eACrC;WACF,CAAA;OACF;MAED,oBAAoB,GAAA;UAClB,OAAO;cACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;WAC5D,CAAA;OACF;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAAC,kBAAa,CAAC;EACZ,gBAAA,IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;eAChB,CAAC;WACH,CAAA;OACF;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAAC,kBAAa,CAAC;EACZ,gBAAA,IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;eAChB,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;;;"}
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
import { Mark } from '@tiptap/core';
|
|
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
|
-
declare const
|
|
30
|
-
declare const
|
|
31
|
-
declare const Highlight: Mark<HighlightOptions, any>;
|
|
32
|
-
|
|
33
|
-
export { Highlight, HighlightOptions, Highlight as default, inputRegex, pasteRegex };
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
export interface HighlightOptions {
|
|
3
|
+
multicolor: boolean;
|
|
4
|
+
HTMLAttributes: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
declare module '@tiptap/core' {
|
|
7
|
+
interface Commands<ReturnType> {
|
|
8
|
+
highlight: {
|
|
9
|
+
/**
|
|
10
|
+
* Set a highlight mark
|
|
11
|
+
*/
|
|
12
|
+
setHighlight: (attributes?: {
|
|
13
|
+
color: string;
|
|
14
|
+
}) => ReturnType;
|
|
15
|
+
/**
|
|
16
|
+
* Toggle a highlight mark
|
|
17
|
+
*/
|
|
18
|
+
toggleHighlight: (attributes?: {
|
|
19
|
+
color: string;
|
|
20
|
+
}) => ReturnType;
|
|
21
|
+
/**
|
|
22
|
+
* Unset a highlight mark
|
|
23
|
+
*/
|
|
24
|
+
unsetHighlight: () => ReturnType;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export declare const inputRegex: RegExp;
|
|
29
|
+
export declare const pasteRegex: RegExp;
|
|
30
|
+
export declare const Highlight: Mark<HighlightOptions, any>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-highlight",
|
|
3
3
|
"description": "highlight 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-highlight/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-highlight/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-highlight"
|
|
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
|
}
|