@tiptap/extension-highlight 2.0.0-beta.9 → 2.0.0-rc.2

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/README.md CHANGED
@@ -5,10 +5,10 @@
5
5
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
6
 
7
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*.
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
9
 
10
- ## Offical Documentation
11
- Documentation can be found on the [tiptap website](https://tiptap.dev).
10
+ ## Official Documentation
11
+ Documentation can be found on the [Tiptap website](https://tiptap.dev).
12
12
 
13
13
  ## License
14
- tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
14
+ Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
@@ -4,13 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@tiptap/core');
6
6
 
7
- const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm;
8
- const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm;
7
+ const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
8
+ const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
9
9
  const Highlight = core.Mark.create({
10
10
  name: 'highlight',
11
- defaultOptions: {
12
- multicolor: false,
13
- HTMLAttributes: {},
11
+ addOptions() {
12
+ return {
13
+ multicolor: false,
14
+ HTMLAttributes: {},
15
+ };
14
16
  },
15
17
  addAttributes() {
16
18
  if (!this.options.multicolor) {
@@ -19,18 +21,14 @@ const Highlight = core.Mark.create({
19
21
  return {
20
22
  color: {
21
23
  default: null,
22
- parseHTML: element => {
23
- return {
24
- color: element.getAttribute('data-color') || element.style.backgroundColor,
25
- };
26
- },
24
+ parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
27
25
  renderHTML: attributes => {
28
26
  if (!attributes.color) {
29
27
  return {};
30
28
  }
31
29
  return {
32
30
  'data-color': attributes.color,
33
- style: `background-color: ${attributes.color}`,
31
+ style: `background-color: ${attributes.color}; color: inherit`,
34
32
  };
35
33
  },
36
34
  },
@@ -49,13 +47,13 @@ const Highlight = core.Mark.create({
49
47
  addCommands() {
50
48
  return {
51
49
  setHighlight: attributes => ({ commands }) => {
52
- return commands.setMark('highlight', attributes);
50
+ return commands.setMark(this.name, attributes);
53
51
  },
54
52
  toggleHighlight: attributes => ({ commands }) => {
55
- return commands.toggleMark('highlight', attributes);
53
+ return commands.toggleMark(this.name, attributes);
56
54
  },
57
55
  unsetHighlight: () => ({ commands }) => {
58
- return commands.unsetMark('highlight');
56
+ return commands.unsetMark(this.name);
59
57
  },
60
58
  };
61
59
  },
@@ -66,18 +64,24 @@ const Highlight = core.Mark.create({
66
64
  },
67
65
  addInputRules() {
68
66
  return [
69
- core.markInputRule(inputRegex, this.type),
67
+ core.markInputRule({
68
+ find: inputRegex,
69
+ type: this.type,
70
+ }),
70
71
  ];
71
72
  },
72
73
  addPasteRules() {
73
74
  return [
74
- core.markPasteRule(inputRegex, this.type),
75
+ core.markPasteRule({
76
+ find: pasteRegex,
77
+ type: this.type,
78
+ }),
75
79
  ];
76
80
  },
77
81
  });
78
82
 
79
83
  exports.Highlight = Highlight;
80
- exports.default = Highlight;
84
+ exports["default"] = Highlight;
81
85
  exports.inputRegex = inputRegex;
82
86
  exports.pasteRegex = pasteRegex;
83
- //# sourceMappingURL=tiptap-extension-highlight.cjs.js.map
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;AACxD,MAAM,UAAU,GAAG,sCAAqC;AAElD,MAAA,SAAS,GAAGA,SAAI,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,EAAEC,oBAAe,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,YAAAC,kBAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAAC,kBAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;;;"}
@@ -1,12 +1,14 @@
1
1
  import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';
2
2
 
3
- const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm;
4
- const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm;
3
+ const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
4
+ const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
5
5
  const Highlight = Mark.create({
6
6
  name: 'highlight',
7
- defaultOptions: {
8
- multicolor: false,
9
- HTMLAttributes: {},
7
+ addOptions() {
8
+ return {
9
+ multicolor: false,
10
+ HTMLAttributes: {},
11
+ };
10
12
  },
11
13
  addAttributes() {
12
14
  if (!this.options.multicolor) {
@@ -15,18 +17,14 @@ const Highlight = Mark.create({
15
17
  return {
16
18
  color: {
17
19
  default: null,
18
- parseHTML: element => {
19
- return {
20
- color: element.getAttribute('data-color') || element.style.backgroundColor,
21
- };
22
- },
20
+ parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
23
21
  renderHTML: attributes => {
24
22
  if (!attributes.color) {
25
23
  return {};
26
24
  }
27
25
  return {
28
26
  'data-color': attributes.color,
29
- style: `background-color: ${attributes.color}`,
27
+ style: `background-color: ${attributes.color}; color: inherit`,
30
28
  };
31
29
  },
32
30
  },
@@ -45,13 +43,13 @@ const Highlight = Mark.create({
45
43
  addCommands() {
46
44
  return {
47
45
  setHighlight: attributes => ({ commands }) => {
48
- return commands.setMark('highlight', attributes);
46
+ return commands.setMark(this.name, attributes);
49
47
  },
50
48
  toggleHighlight: attributes => ({ commands }) => {
51
- return commands.toggleMark('highlight', attributes);
49
+ return commands.toggleMark(this.name, attributes);
52
50
  },
53
51
  unsetHighlight: () => ({ commands }) => {
54
- return commands.unsetMark('highlight');
52
+ return commands.unsetMark(this.name);
55
53
  },
56
54
  };
57
55
  },
@@ -62,16 +60,21 @@ const Highlight = Mark.create({
62
60
  },
63
61
  addInputRules() {
64
62
  return [
65
- markInputRule(inputRegex, this.type),
63
+ markInputRule({
64
+ find: inputRegex,
65
+ type: this.type,
66
+ }),
66
67
  ];
67
68
  },
68
69
  addPasteRules() {
69
70
  return [
70
- markPasteRule(inputRegex, this.type),
71
+ markPasteRule({
72
+ find: pasteRegex,
73
+ type: this.type,
74
+ }),
71
75
  ];
72
76
  },
73
77
  });
74
78
 
75
- export default Highlight;
76
- export { Highlight, inputRegex, pasteRegex };
77
- //# sourceMappingURL=tiptap-extension-highlight.esm.js.map
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;;;;"}
@@ -1,16 +1,18 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
3
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';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-highlight"] = {}, global.core));
5
+ })(this, (function (exports, core) { 'use strict';
6
6
 
7
- const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm;
8
- const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm;
7
+ const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
8
+ const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
9
9
  const Highlight = core.Mark.create({
10
10
  name: 'highlight',
11
- defaultOptions: {
12
- multicolor: false,
13
- HTMLAttributes: {},
11
+ addOptions() {
12
+ return {
13
+ multicolor: false,
14
+ HTMLAttributes: {},
15
+ };
14
16
  },
15
17
  addAttributes() {
16
18
  if (!this.options.multicolor) {
@@ -19,18 +21,14 @@
19
21
  return {
20
22
  color: {
21
23
  default: null,
22
- parseHTML: element => {
23
- return {
24
- color: element.getAttribute('data-color') || element.style.backgroundColor,
25
- };
26
- },
24
+ parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
27
25
  renderHTML: attributes => {
28
26
  if (!attributes.color) {
29
27
  return {};
30
28
  }
31
29
  return {
32
30
  'data-color': attributes.color,
33
- style: `background-color: ${attributes.color}`,
31
+ style: `background-color: ${attributes.color}; color: inherit`,
34
32
  };
35
33
  },
36
34
  },
@@ -49,13 +47,13 @@
49
47
  addCommands() {
50
48
  return {
51
49
  setHighlight: attributes => ({ commands }) => {
52
- return commands.setMark('highlight', attributes);
50
+ return commands.setMark(this.name, attributes);
53
51
  },
54
52
  toggleHighlight: attributes => ({ commands }) => {
55
- return commands.toggleMark('highlight', attributes);
53
+ return commands.toggleMark(this.name, attributes);
56
54
  },
57
55
  unsetHighlight: () => ({ commands }) => {
58
- return commands.unsetMark('highlight');
56
+ return commands.unsetMark(this.name);
59
57
  },
60
58
  };
61
59
  },
@@ -66,22 +64,28 @@
66
64
  },
67
65
  addInputRules() {
68
66
  return [
69
- core.markInputRule(inputRegex, this.type),
67
+ core.markInputRule({
68
+ find: inputRegex,
69
+ type: this.type,
70
+ }),
70
71
  ];
71
72
  },
72
73
  addPasteRules() {
73
74
  return [
74
- core.markPasteRule(inputRegex, this.type),
75
+ core.markPasteRule({
76
+ find: pasteRegex,
77
+ type: this.type,
78
+ }),
75
79
  ];
76
80
  },
77
81
  });
78
82
 
79
83
  exports.Highlight = Highlight;
80
- exports.default = Highlight;
84
+ exports["default"] = Highlight;
81
85
  exports.inputRegex = inputRegex;
82
86
  exports.pasteRegex = pasteRegex;
83
87
 
84
88
  Object.defineProperty(exports, '__esModule', { value: true });
85
89
 
86
- })));
87
- //# sourceMappingURL=tiptap-extension-highlight.umd.js.map
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,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;EAC5B,YAAA,OAAO,EAAE,CAAA;EACV,SAAA;UAED,OAAO;EACL,YAAA,KAAK,EAAE;EACL,gBAAA,OAAO,EAAE,IAAI;EACb,gBAAA,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;kBACzF,UAAU,EAAE,UAAU,IAAG;EACvB,oBAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;EACrB,wBAAA,OAAO,EAAE,CAAA;EACV,qBAAA;sBAED,OAAO;0BACL,YAAY,EAAE,UAAU,CAAC,KAAK;EAC9B,wBAAA,KAAK,EAAE,CAAA,kBAAA,EAAqB,UAAU,CAAC,KAAK,CAAkB,gBAAA,CAAA;uBAC/D,CAAA;mBACF;EACF,aAAA;WACF,CAAA;OACF;MAED,SAAS,GAAA;UACP,OAAO;EACL,YAAA;EACE,gBAAA,GAAG,EAAE,MAAM;EACZ,aAAA;WACF,CAAA;OACF;MAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;EAC3B,QAAA,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;OACjF;MAED,WAAW,GAAA;UACT,OAAO;cACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;kBAC3C,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;eAC/C;cACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;kBAC9C,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;eAClD;cACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAI;kBACrC,OAAO,QAAQ,CAAC,SAAS,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,30 +1,30 @@
1
- import { Command, Mark } from '@tiptap/core';
1
+ import { Mark } from '@tiptap/core';
2
2
  export interface HighlightOptions {
3
3
  multicolor: boolean;
4
4
  HTMLAttributes: Record<string, any>;
5
5
  }
6
6
  declare module '@tiptap/core' {
7
- interface Commands {
7
+ interface Commands<ReturnType> {
8
8
  highlight: {
9
9
  /**
10
10
  * Set a highlight mark
11
11
  */
12
12
  setHighlight: (attributes?: {
13
13
  color: string;
14
- }) => Command;
14
+ }) => ReturnType;
15
15
  /**
16
16
  * Toggle a highlight mark
17
17
  */
18
18
  toggleHighlight: (attributes?: {
19
19
  color: string;
20
- }) => Command;
20
+ }) => ReturnType;
21
21
  /**
22
22
  * Unset a highlight mark
23
23
  */
24
- unsetHighlight: () => Command;
24
+ unsetHighlight: () => ReturnType;
25
25
  };
26
26
  }
27
27
  }
28
28
  export declare const inputRegex: RegExp;
29
29
  export declare const pasteRegex: RegExp;
30
- export declare const Highlight: Mark<HighlightOptions>;
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.9",
4
+ "version": "2.0.0-rc.2",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -12,24 +12,35 @@
12
12
  "type": "github",
13
13
  "url": "https://github.com/sponsors/ueberdosis"
14
14
  },
15
- "main": "dist/tiptap-extension-highlight.cjs.js",
16
- "umd": "dist/tiptap-extension-highlight.umd.js",
17
- "module": "dist/tiptap-extension-highlight.esm.js",
18
- "types": "dist/packages/extension-highlight/src/index.d.ts",
19
15
  "type": "module",
20
16
  "exports": {
21
17
  ".": {
22
- "import": "./dist/tiptap-extension-highlight.esm.js",
23
- "require": "./dist/tiptap-extension-highlight.cjs.js",
24
- "default": "./dist/tiptap-extension-highlight.esm.js"
18
+ "types": "./dist/packages/extension-highlight/src/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
25
21
  }
26
22
  },
23
+ "main": "dist/index.cjs",
24
+ "module": "dist/index.js",
25
+ "umd": "dist/index.umd.js",
26
+ "types": "dist/packages/extension-highlight/src/index.d.ts",
27
27
  "files": [
28
28
  "src",
29
29
  "dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@tiptap/core": "^2.0.0-beta.1"
32
+ "@tiptap/core": "^2.0.0-rc.1"
33
+ },
34
+ "devDependencies": {
35
+ "@tiptap/core": "^2.0.0-rc.1"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/ueberdosis/tiptap",
40
+ "directory": "packages/extension-highlight"
33
41
  },
34
- "gitHead": "fb1196c7a7d4abec583599802515fb4175128b55"
35
- }
42
+ "scripts": {
43
+ "clean": "rm -rf dist",
44
+ "build": "npm run clean && rollup -c"
45
+ }
46
+ }
package/src/highlight.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- Command,
3
2
  Mark,
4
3
  markInputRule,
5
4
  markPasteRule,
@@ -12,33 +11,35 @@ export interface HighlightOptions {
12
11
  }
13
12
 
14
13
  declare module '@tiptap/core' {
15
- interface Commands {
14
+ interface Commands<ReturnType> {
16
15
  highlight: {
17
16
  /**
18
17
  * Set a highlight mark
19
18
  */
20
- setHighlight: (attributes?: { color: string }) => Command,
19
+ setHighlight: (attributes?: { color: string }) => ReturnType,
21
20
  /**
22
21
  * Toggle a highlight mark
23
22
  */
24
- toggleHighlight: (attributes?: { color: string }) => Command,
23
+ toggleHighlight: (attributes?: { color: string }) => ReturnType,
25
24
  /**
26
25
  * Unset a highlight mark
27
26
  */
28
- unsetHighlight: () => Command,
27
+ unsetHighlight: () => ReturnType,
29
28
  }
30
29
  }
31
30
  }
32
31
 
33
- export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm
34
- export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm
32
+ export const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/
33
+ export const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g
35
34
 
36
35
  export const Highlight = Mark.create<HighlightOptions>({
37
36
  name: 'highlight',
38
37
 
39
- defaultOptions: {
40
- multicolor: false,
41
- HTMLAttributes: {},
38
+ addOptions() {
39
+ return {
40
+ multicolor: false,
41
+ HTMLAttributes: {},
42
+ }
42
43
  },
43
44
 
44
45
  addAttributes() {
@@ -49,11 +50,7 @@ export const Highlight = Mark.create<HighlightOptions>({
49
50
  return {
50
51
  color: {
51
52
  default: null,
52
- parseHTML: element => {
53
- return {
54
- color: element.getAttribute('data-color') || element.style.backgroundColor,
55
- }
56
- },
53
+ parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
57
54
  renderHTML: attributes => {
58
55
  if (!attributes.color) {
59
56
  return {}
@@ -61,7 +58,7 @@ export const Highlight = Mark.create<HighlightOptions>({
61
58
 
62
59
  return {
63
60
  'data-color': attributes.color,
64
- style: `background-color: ${attributes.color}`,
61
+ style: `background-color: ${attributes.color}; color: inherit`,
65
62
  }
66
63
  },
67
64
  },
@@ -83,13 +80,13 @@ export const Highlight = Mark.create<HighlightOptions>({
83
80
  addCommands() {
84
81
  return {
85
82
  setHighlight: attributes => ({ commands }) => {
86
- return commands.setMark('highlight', attributes)
83
+ return commands.setMark(this.name, attributes)
87
84
  },
88
85
  toggleHighlight: attributes => ({ commands }) => {
89
- return commands.toggleMark('highlight', attributes)
86
+ return commands.toggleMark(this.name, attributes)
90
87
  },
91
88
  unsetHighlight: () => ({ commands }) => {
92
- return commands.unsetMark('highlight')
89
+ return commands.unsetMark(this.name)
93
90
  },
94
91
  }
95
92
  },
@@ -102,13 +99,19 @@ export const Highlight = Mark.create<HighlightOptions>({
102
99
 
103
100
  addInputRules() {
104
101
  return [
105
- markInputRule(inputRegex, this.type),
102
+ markInputRule({
103
+ find: inputRegex,
104
+ type: this.type,
105
+ }),
106
106
  ]
107
107
  },
108
108
 
109
109
  addPasteRules() {
110
110
  return [
111
- markPasteRule(inputRegex, this.type),
111
+ markPasteRule({
112
+ find: pasteRegex,
113
+ type: this.type,
114
+ }),
112
115
  ]
113
116
  },
114
117
  })
package/CHANGELOG.md DELETED
@@ -1,182 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.0.0-beta.9](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.8...@tiptap/extension-highlight@2.0.0-beta.9) (2021-05-06)
7
-
8
-
9
- ### Bug Fixes
10
-
11
- * add exports to package.json ([1277fa4](https://github.com/ueberdosis/tiptap/commit/1277fa47151e9c039508cdb219bdd0ffe647f4ee))
12
-
13
-
14
-
15
-
16
-
17
- # [2.0.0-beta.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.7...@tiptap/extension-highlight@2.0.0-beta.8) (2021-05-06)
18
-
19
- **Note:** Version bump only for package @tiptap/extension-highlight
20
-
21
-
22
-
23
-
24
-
25
- # [2.0.0-beta.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.6...@tiptap/extension-highlight@2.0.0-beta.7) (2021-05-05)
26
-
27
- **Note:** Version bump only for package @tiptap/extension-highlight
28
-
29
-
30
-
31
-
32
-
33
- # [2.0.0-beta.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.5...@tiptap/extension-highlight@2.0.0-beta.6) (2021-04-23)
34
-
35
- **Note:** Version bump only for package @tiptap/extension-highlight
36
-
37
-
38
-
39
-
40
-
41
- # [2.0.0-beta.5](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.4...@tiptap/extension-highlight@2.0.0-beta.5) (2021-04-22)
42
-
43
- **Note:** Version bump only for package @tiptap/extension-highlight
44
-
45
-
46
-
47
-
48
-
49
- # [2.0.0-beta.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.3...@tiptap/extension-highlight@2.0.0-beta.4) (2021-04-21)
50
-
51
- **Note:** Version bump only for package @tiptap/extension-highlight
52
-
53
-
54
-
55
-
56
-
57
- # [2.0.0-beta.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.2...@tiptap/extension-highlight@2.0.0-beta.3) (2021-04-16)
58
-
59
- **Note:** Version bump only for package @tiptap/extension-highlight
60
-
61
-
62
-
63
-
64
-
65
- # [2.0.0-beta.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-beta.1...@tiptap/extension-highlight@2.0.0-beta.2) (2021-04-15)
66
-
67
- **Note:** Version bump only for package @tiptap/extension-highlight
68
-
69
-
70
-
71
-
72
-
73
- # [2.0.0-beta.1](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.11...@tiptap/extension-highlight@2.0.0-beta.1) (2021-03-05)
74
-
75
- **Note:** Version bump only for package @tiptap/extension-highlight
76
-
77
-
78
-
79
-
80
-
81
- # [2.0.0-alpha.11](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.10...@tiptap/extension-highlight@2.0.0-alpha.11) (2021-02-16)
82
-
83
- **Note:** Version bump only for package @tiptap/extension-highlight
84
-
85
-
86
-
87
-
88
-
89
- # [2.0.0-alpha.10](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.9...@tiptap/extension-highlight@2.0.0-alpha.10) (2021-02-07)
90
-
91
- **Note:** Version bump only for package @tiptap/extension-highlight
92
-
93
-
94
-
95
-
96
-
97
- # [2.0.0-alpha.9](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.8...@tiptap/extension-highlight@2.0.0-alpha.9) (2021-02-05)
98
-
99
- **Note:** Version bump only for package @tiptap/extension-highlight
100
-
101
-
102
-
103
-
104
-
105
- # [2.0.0-alpha.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.7...@tiptap/extension-highlight@2.0.0-alpha.8) (2021-01-29)
106
-
107
- **Note:** Version bump only for package @tiptap/extension-highlight
108
-
109
-
110
-
111
-
112
-
113
- # [2.0.0-alpha.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.6...@tiptap/extension-highlight@2.0.0-alpha.7) (2021-01-29)
114
-
115
- **Note:** Version bump only for package @tiptap/extension-highlight
116
-
117
-
118
-
119
-
120
-
121
- # [2.0.0-alpha.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.5...@tiptap/extension-highlight@2.0.0-alpha.6) (2021-01-28)
122
-
123
- **Note:** Version bump only for package @tiptap/extension-highlight
124
-
125
-
126
-
127
-
128
-
129
- # [2.0.0-alpha.5](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.4...@tiptap/extension-highlight@2.0.0-alpha.5) (2020-12-18)
130
-
131
- **Note:** Version bump only for package @tiptap/extension-highlight
132
-
133
-
134
-
135
-
136
-
137
- # [2.0.0-alpha.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.3...@tiptap/extension-highlight@2.0.0-alpha.4) (2020-12-02)
138
-
139
- **Note:** Version bump only for package @tiptap/extension-highlight
140
-
141
-
142
-
143
-
144
-
145
- # [2.0.0-alpha.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.2...@tiptap/extension-highlight@2.0.0-alpha.3) (2020-11-19)
146
-
147
- **Note:** Version bump only for package @tiptap/extension-highlight
148
-
149
-
150
-
151
-
152
-
153
- # [2.0.0-alpha.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@2.0.0-alpha.1...@tiptap/extension-highlight@2.0.0-alpha.2) (2020-11-19)
154
-
155
- **Note:** Version bump only for package @tiptap/extension-highlight
156
-
157
-
158
-
159
-
160
-
161
- # [2.0.0-alpha.1](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@1.0.0-alpha.2...@tiptap/extension-highlight@2.0.0-alpha.1) (2020-11-18)
162
-
163
- **Note:** Version bump only for package @tiptap/extension-highlight
164
-
165
-
166
-
167
-
168
-
169
- # [1.0.0-alpha.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-highlight@1.0.0-alpha.1...@tiptap/extension-highlight@1.0.0-alpha.2) (2020-11-16)
170
-
171
- **Note:** Version bump only for package @tiptap/extension-highlight
172
-
173
-
174
-
175
-
176
-
177
- # 1.0.0-alpha.1 (2020-11-16)
178
-
179
-
180
- ### Reverts
181
-
182
- * Revert "use global namespace" ([0c9ce26](https://github.com/ueberdosis/tiptap/commit/0c9ce26c02c07d88a757c01b0a9d7f9e2b0b7502))
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-highlight.cjs.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Command,\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 {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => Command,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => Command,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => Command,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))$/gm\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))/gm\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n defaultOptions: {\n multicolor: false,\n HTMLAttributes: {},\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => {\n return {\n color: element.getAttribute('data-color') || element.style.backgroundColor,\n }\n },\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}`,\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('highlight', attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark('highlight', attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark('highlight')\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(inputRegex, this.type),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule(inputRegex, this.type),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;MAgCa,UAAU,GAAG,uCAAsC;MACnD,UAAU,GAAG,sCAAqC;MAElD,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;IACrD,IAAI,EAAE,WAAW;IAEjB,cAAc,EAAE;QACd,UAAU,EAAE,KAAK;QACjB,cAAc,EAAE,EAAE;KACnB;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC5B,OAAO,EAAE,CAAA;SACV;QAED,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,OAAO;oBAChB,OAAO;wBACL,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;qBAC3E,CAAA;iBACF;gBACD,UAAU,EAAE,UAAU;oBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;wBACrB,OAAO,EAAE,CAAA;qBACV;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;wBAC9B,KAAK,EAAE,qBAAqB,UAAU,CAAC,KAAK,EAAE;qBAC/C,CAAA;iBACF;aACF;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,MAAM;aACZ;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBACvC,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACjD;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACpD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;aACvC;SACF,CAAA;KACF;IAED,oBAAoB;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;CACF;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-highlight.esm.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Command,\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 {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => Command,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => Command,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => Command,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))$/gm\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))/gm\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n defaultOptions: {\n multicolor: false,\n HTMLAttributes: {},\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => {\n return {\n color: element.getAttribute('data-color') || element.style.backgroundColor,\n }\n },\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}`,\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('highlight', attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark('highlight', attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark('highlight')\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(inputRegex, this.type),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule(inputRegex, this.type),\n ]\n },\n})\n"],"names":[],"mappings":";;MAgCa,UAAU,GAAG,uCAAsC;MACnD,UAAU,GAAG,sCAAqC;MAElD,SAAS,GAAG,IAAI,CAAC,MAAM,CAAmB;IACrD,IAAI,EAAE,WAAW;IAEjB,cAAc,EAAE;QACd,UAAU,EAAE,KAAK;QACjB,cAAc,EAAE,EAAE;KACnB;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC5B,OAAO,EAAE,CAAA;SACV;QAED,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,OAAO;oBAChB,OAAO;wBACL,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;qBAC3E,CAAA;iBACF;gBACD,UAAU,EAAE,UAAU;oBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;wBACrB,OAAO,EAAE,CAAA;qBACV;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;wBAC9B,KAAK,EAAE,qBAAqB,UAAU,CAAC,KAAK,EAAE;qBAC/C,CAAA;iBACF;aACF;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,MAAM;aACZ;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBACvC,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACjD;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACpD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;aACvC;SACF,CAAA;KACF;IAED,oBAAoB;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACL,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACL,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;CACF;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-highlight.umd.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Command,\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 {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => Command,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => Command,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => Command,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))$/gm\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))/gm\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n defaultOptions: {\n multicolor: false,\n HTMLAttributes: {},\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => {\n return {\n color: element.getAttribute('data-color') || element.style.backgroundColor,\n }\n },\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}`,\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('highlight', attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark('highlight', attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark('highlight')\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(inputRegex, this.type),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule(inputRegex, this.type),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;QAgCa,UAAU,GAAG,uCAAsC;QACnD,UAAU,GAAG,sCAAqC;QAElD,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;MACrD,IAAI,EAAE,WAAW;MAEjB,cAAc,EAAE;UACd,UAAU,EAAE,KAAK;UACjB,cAAc,EAAE,EAAE;OACnB;MAED,aAAa;UACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;cAC5B,OAAO,EAAE,CAAA;WACV;UAED,OAAO;cACL,KAAK,EAAE;kBACL,OAAO,EAAE,IAAI;kBACb,SAAS,EAAE,OAAO;sBAChB,OAAO;0BACL,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;uBAC3E,CAAA;mBACF;kBACD,UAAU,EAAE,UAAU;sBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;0BACrB,OAAO,EAAE,CAAA;uBACV;sBAED,OAAO;0BACL,YAAY,EAAE,UAAU,CAAC,KAAK;0BAC9B,KAAK,EAAE,qBAAqB,UAAU,CAAC,KAAK,EAAE;uBAC/C,CAAA;mBACF;eACF;WACF,CAAA;OACF;MAED,SAAS;UACP,OAAO;cACL;kBACE,GAAG,EAAE,MAAM;eACZ;WACF,CAAA;OACF;MAED,UAAU,CAAC,EAAE,cAAc,EAAE;UAC3B,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;OACjF;MAED,WAAW;UACT,OAAO;cACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;kBACvC,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;eACjD;cACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;kBAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;eACpD;cACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;kBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;eACvC;WACF,CAAA;OACF;MAED,oBAAoB;UAClB,OAAO;cACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;WAC5D,CAAA;OACF;MAED,aAAa;UACX,OAAO;cACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;WACrC,CAAA;OACF;MAED,aAAa;UACX,OAAO;cACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;WACrC,CAAA;OACF;GACF;;;;;;;;;;;;;"}