@tiptap/extension-focus 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).
@@ -3,26 +3,28 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@tiptap/core');
6
- var prosemirrorState = require('prosemirror-state');
7
- var prosemirrorView = require('prosemirror-view');
6
+ var state = require('@tiptap/pm/state');
7
+ var view = require('@tiptap/pm/view');
8
8
 
9
9
  const FocusClasses = core.Extension.create({
10
10
  name: 'focus',
11
- defaultOptions: {
12
- className: 'has-focus',
13
- mode: 'all',
11
+ addOptions() {
12
+ return {
13
+ className: 'has-focus',
14
+ mode: 'all',
15
+ };
14
16
  },
15
17
  addProseMirrorPlugins() {
16
18
  return [
17
- new prosemirrorState.Plugin({
18
- key: new prosemirrorState.PluginKey('focus'),
19
+ new state.Plugin({
20
+ key: new state.PluginKey('focus'),
19
21
  props: {
20
22
  decorations: ({ doc, selection }) => {
21
23
  const { isEditable, isFocused } = this.editor;
22
24
  const { anchor } = selection;
23
25
  const decorations = [];
24
26
  if (!isEditable || !isFocused) {
25
- return prosemirrorView.DecorationSet.create(doc, []);
27
+ return view.DecorationSet.create(doc, []);
26
28
  }
27
29
  // Maximum Levels
28
30
  let maxLevels = 0;
@@ -31,7 +33,7 @@ const FocusClasses = core.Extension.create({
31
33
  if (node.isText) {
32
34
  return;
33
35
  }
34
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
36
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
35
37
  if (!isCurrent) {
36
38
  return false;
37
39
  }
@@ -44,7 +46,7 @@ const FocusClasses = core.Extension.create({
44
46
  if (node.isText) {
45
47
  return false;
46
48
  }
47
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
49
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
48
50
  if (!isCurrent) {
49
51
  return false;
50
52
  }
@@ -54,11 +56,11 @@ const FocusClasses = core.Extension.create({
54
56
  if (outOfScope) {
55
57
  return this.options.mode === 'deepest';
56
58
  }
57
- decorations.push(prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
59
+ decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
58
60
  class: this.options.className,
59
61
  }));
60
62
  });
61
- return prosemirrorView.DecorationSet.create(doc, decorations);
63
+ return view.DecorationSet.create(doc, decorations);
62
64
  },
63
65
  },
64
66
  }),
@@ -67,5 +69,5 @@ const FocusClasses = core.Extension.create({
67
69
  });
68
70
 
69
71
  exports.FocusClasses = FocusClasses;
70
- exports.default = FocusClasses;
71
- //# sourceMappingURL=tiptap-extension-focus.cjs.js.map
72
+ exports["default"] = FocusClasses;
73
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n className: string\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;;;AASa,MAAA,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;AACzD,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,SAAS,EAAE,WAAW;AACtB,YAAA,IAAI,EAAE,KAAK;SACZ,CAAA;KACF;IAED,qBAA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M,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAA;4BAEpE,IAAI,CAAC,SAAS,EAAE;AACd,gCAAA,OAAO,KAAK,CAAA;AACb,6BAAA;4BAED,YAAY,IAAI,CAAC,CAAA;AAEjB,4BAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,GAAG,YAAY,GAAG,CAAC;AAC9E,oCAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,YAAY,GAAG,CAAC,CAAC,CAAA;AAE7D,4BAAA,IAAI,UAAU,EAAE;AACd,gCAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;AACvC,6BAAA;AAED,4BAAA,WAAW,CAAC,IAAI,CACdC,eAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;AAC9B,6BAAA,CAAC,CACH,CAAA;AACH,yBAAC,CAAC,CAAA;wBAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
@@ -1,12 +1,14 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import { Plugin, PluginKey } from 'prosemirror-state';
3
- import { DecorationSet, Decoration } from 'prosemirror-view';
2
+ import { Plugin, PluginKey } from '@tiptap/pm/state';
3
+ import { DecorationSet, Decoration } from '@tiptap/pm/view';
4
4
 
5
5
  const FocusClasses = Extension.create({
6
6
  name: 'focus',
7
- defaultOptions: {
8
- className: 'has-focus',
9
- mode: 'all',
7
+ addOptions() {
8
+ return {
9
+ className: 'has-focus',
10
+ mode: 'all',
11
+ };
10
12
  },
11
13
  addProseMirrorPlugins() {
12
14
  return [
@@ -27,7 +29,7 @@ const FocusClasses = Extension.create({
27
29
  if (node.isText) {
28
30
  return;
29
31
  }
30
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
32
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
31
33
  if (!isCurrent) {
32
34
  return false;
33
35
  }
@@ -40,7 +42,7 @@ const FocusClasses = Extension.create({
40
42
  if (node.isText) {
41
43
  return false;
42
44
  }
43
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
45
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
44
46
  if (!isCurrent) {
45
47
  return false;
46
48
  }
@@ -62,6 +64,5 @@ const FocusClasses = Extension.create({
62
64
  },
63
65
  });
64
66
 
65
- export default FocusClasses;
66
- export { FocusClasses };
67
- //# sourceMappingURL=tiptap-extension-focus.esm.js.map
67
+ export { FocusClasses, FocusClasses as default };
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n className: string\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;AASa,MAAA,YAAY,GAAG,SAAS,CAAC,MAAM,CAAe;AACzD,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,SAAS,EAAE,WAAW;AACtB,YAAA,IAAI,EAAE,KAAK;SACZ,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAI,MAAM,CAAC;AACT,gBAAA,GAAG,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC;AAC3B,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;wBAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;AAC7C,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;AAEpC,wBAAA,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,EAAE;4BAC7B,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AACrC,yBAAA;;wBAGD,IAAI,SAAS,GAAG,CAAC,CAAA;AAEjB,wBAAA,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;4BACn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,IAAI,CAAC,OAAO,CAAC,SAAS;AAC9B,6BAAA,CAAC,CACH,CAAA;AACH,yBAAC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
@@ -1,26 +1,28 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-state'), require('prosemirror-view')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-state', 'prosemirror-view'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@tiptap/extension-focus'] = {}, global.core, global.prosemirrorState, global.prosemirrorView));
5
- }(this, (function (exports, core, prosemirrorState, prosemirrorView) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('@tiptap/pm/state'), require('@tiptap/pm/view')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', '@tiptap/pm/state', '@tiptap/pm/view'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-focus"] = {}, global.core, global.state, global.view));
5
+ })(this, (function (exports, core, state, view) { 'use strict';
6
6
 
7
7
  const FocusClasses = core.Extension.create({
8
8
  name: 'focus',
9
- defaultOptions: {
10
- className: 'has-focus',
11
- mode: 'all',
9
+ addOptions() {
10
+ return {
11
+ className: 'has-focus',
12
+ mode: 'all',
13
+ };
12
14
  },
13
15
  addProseMirrorPlugins() {
14
16
  return [
15
- new prosemirrorState.Plugin({
16
- key: new prosemirrorState.PluginKey('focus'),
17
+ new state.Plugin({
18
+ key: new state.PluginKey('focus'),
17
19
  props: {
18
20
  decorations: ({ doc, selection }) => {
19
21
  const { isEditable, isFocused } = this.editor;
20
22
  const { anchor } = selection;
21
23
  const decorations = [];
22
24
  if (!isEditable || !isFocused) {
23
- return prosemirrorView.DecorationSet.create(doc, []);
25
+ return view.DecorationSet.create(doc, []);
24
26
  }
25
27
  // Maximum Levels
26
28
  let maxLevels = 0;
@@ -29,7 +31,7 @@
29
31
  if (node.isText) {
30
32
  return;
31
33
  }
32
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
34
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
33
35
  if (!isCurrent) {
34
36
  return false;
35
37
  }
@@ -42,7 +44,7 @@
42
44
  if (node.isText) {
43
45
  return false;
44
46
  }
45
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
47
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
46
48
  if (!isCurrent) {
47
49
  return false;
48
50
  }
@@ -52,11 +54,11 @@
52
54
  if (outOfScope) {
53
55
  return this.options.mode === 'deepest';
54
56
  }
55
- decorations.push(prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
57
+ decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
56
58
  class: this.options.className,
57
59
  }));
58
60
  });
59
- return prosemirrorView.DecorationSet.create(doc, decorations);
61
+ return view.DecorationSet.create(doc, decorations);
60
62
  },
61
63
  },
62
64
  }),
@@ -65,9 +67,9 @@
65
67
  });
66
68
 
67
69
  exports.FocusClasses = FocusClasses;
68
- exports.default = FocusClasses;
70
+ exports["default"] = FocusClasses;
69
71
 
70
72
  Object.defineProperty(exports, '__esModule', { value: true });
71
73
 
72
- })));
73
- //# sourceMappingURL=tiptap-extension-focus.umd.js.map
74
+ }));
75
+ //# sourceMappingURL=index.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n className: string\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;AASa,QAAA,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;EACzD,IAAA,IAAI,EAAE,OAAO;MAEb,UAAU,GAAA;UACR,OAAO;EACL,YAAA,SAAS,EAAE,WAAW;EACtB,YAAA,IAAI,EAAE,KAAK;WACZ,CAAA;OACF;MAED,qBAAqB,GAAA;UACnB,OAAO;EACL,YAAA,IAAIC,YAAM,CAAC;EACT,gBAAA,GAAG,EAAE,IAAIC,eAAS,CAAC,OAAO,CAAC;EAC3B,gBAAA,KAAK,EAAE;sBAC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,YAAY,IAAI,CAAC,CAAA;EAEjB,4BAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,GAAG,YAAY,GAAG,CAAC;EAC9E,oCAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,YAAY,GAAG,CAAC,CAAC,CAAA;EAE7D,4BAAA,IAAI,UAAU,EAAE;EACd,gCAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;EACvC,6BAAA;EAED,4BAAA,WAAW,CAAC,IAAI,CACdC,eAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;EACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;EAC9B,6BAAA,CAAC,CACH,CAAA;EACH,yBAAC,CAAC,CAAA;0BAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
@@ -3,4 +3,4 @@ export interface FocusOptions {
3
3
  className: string;
4
4
  mode: 'all' | 'deepest' | 'shallowest';
5
5
  }
6
- export declare const FocusClasses: Extension<FocusOptions>;
6
+ export declare const FocusClasses: Extension<FocusOptions, any>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-focus",
3
3
  "description": "focus 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,21 +12,37 @@
12
12
  "type": "github",
13
13
  "url": "https://github.com/sponsors/ueberdosis"
14
14
  },
15
- "main": "dist/tiptap-extension-focus.cjs.js",
16
- "umd": "dist/tiptap-extension-focus.umd.js",
17
- "module": "dist/tiptap-extension-focus.esm.js",
18
- "unpkg": "dist/tiptap-extension-focus.bundle.umd.min.js",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/packages/extension-focus/src/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "main": "dist/index.cjs",
24
+ "module": "dist/index.js",
25
+ "umd": "dist/index.umd.js",
19
26
  "types": "dist/packages/extension-focus/src/index.d.ts",
20
27
  "files": [
21
28
  "src",
22
29
  "dist"
23
30
  ],
24
31
  "peerDependencies": {
25
- "@tiptap/core": "^2.0.0-beta.1"
32
+ "@tiptap/core": "^2.0.0-rc.1",
33
+ "@tiptap/pm": "^2.0.0-rc.1"
34
+ },
35
+ "devDependencies": {
36
+ "@tiptap/core": "^2.0.0-rc.1",
37
+ "@tiptap/pm": "^2.0.0-rc.1"
26
38
  },
27
- "dependencies": {
28
- "prosemirror-state": "^1.3.4",
29
- "prosemirror-view": "^1.18.2"
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/ueberdosis/tiptap",
42
+ "directory": "packages/extension-focus"
30
43
  },
31
- "gitHead": "4b68a369a17269063b007008f7c5cba2f83f1f2c"
32
- }
44
+ "scripts": {
45
+ "clean": "rm -rf dist",
46
+ "build": "npm run clean && rollup -c"
47
+ }
48
+ }
package/src/focus.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import { Extension } from '@tiptap/core'
2
- import { Plugin, PluginKey } from 'prosemirror-state'
3
- import { DecorationSet, Decoration } from 'prosemirror-view'
2
+ import { Plugin, PluginKey } from '@tiptap/pm/state'
3
+ import { Decoration, DecorationSet } from '@tiptap/pm/view'
4
4
 
5
5
  export interface FocusOptions {
6
- className: string,
7
- mode: 'all' | 'deepest' | 'shallowest',
6
+ className: string
7
+ mode: 'all' | 'deepest' | 'shallowest'
8
8
  }
9
9
 
10
10
  export const FocusClasses = Extension.create<FocusOptions>({
11
11
  name: 'focus',
12
12
 
13
- defaultOptions: {
14
- className: 'has-focus',
15
- mode: 'all',
13
+ addOptions() {
14
+ return {
15
+ className: 'has-focus',
16
+ mode: 'all',
17
+ }
16
18
  },
17
19
 
18
20
  addProseMirrorPlugins() {
@@ -38,7 +40,7 @@ export const FocusClasses = Extension.create<FocusOptions>({
38
40
  return
39
41
  }
40
42
 
41
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1)
43
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1
42
44
 
43
45
  if (!isCurrent) {
44
46
  return false
@@ -56,7 +58,7 @@ export const FocusClasses = Extension.create<FocusOptions>({
56
58
  return false
57
59
  }
58
60
 
59
- const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1)
61
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1
60
62
 
61
63
  if (!isCurrent) {
62
64
  return false
@@ -71,9 +73,11 @@ export const FocusClasses = Extension.create<FocusOptions>({
71
73
  return this.options.mode === 'deepest'
72
74
  }
73
75
 
74
- decorations.push(Decoration.node(pos, pos + node.nodeSize, {
75
- class: this.options.className,
76
- }))
76
+ decorations.push(
77
+ Decoration.node(pos, pos + node.nodeSize, {
78
+ class: this.options.className,
79
+ }),
80
+ )
77
81
  })
78
82
 
79
83
  return DecorationSet.create(doc, decorations)
package/CHANGELOG.md DELETED
@@ -1,187 +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-focus@2.0.0-beta.8...@tiptap/extension-focus@2.0.0-beta.9) (2021-04-22)
7
-
8
- **Note:** Version bump only for package @tiptap/extension-focus
9
-
10
-
11
-
12
-
13
-
14
- # [2.0.0-beta.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.7...@tiptap/extension-focus@2.0.0-beta.8) (2021-04-16)
15
-
16
- **Note:** Version bump only for package @tiptap/extension-focus
17
-
18
-
19
-
20
-
21
-
22
- # [2.0.0-beta.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.6...@tiptap/extension-focus@2.0.0-beta.7) (2021-04-15)
23
-
24
- **Note:** Version bump only for package @tiptap/extension-focus
25
-
26
-
27
-
28
-
29
-
30
- # [2.0.0-beta.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.5...@tiptap/extension-focus@2.0.0-beta.6) (2021-03-31)
31
-
32
- **Note:** Version bump only for package @tiptap/extension-focus
33
-
34
-
35
-
36
-
37
-
38
- # [2.0.0-beta.5](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.4...@tiptap/extension-focus@2.0.0-beta.5) (2021-03-28)
39
-
40
- **Note:** Version bump only for package @tiptap/extension-focus
41
-
42
-
43
-
44
-
45
-
46
- # [2.0.0-beta.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.3...@tiptap/extension-focus@2.0.0-beta.4) (2021-03-25)
47
-
48
- **Note:** Version bump only for package @tiptap/extension-focus
49
-
50
-
51
-
52
-
53
-
54
- # [2.0.0-beta.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.2...@tiptap/extension-focus@2.0.0-beta.3) (2021-03-24)
55
-
56
- **Note:** Version bump only for package @tiptap/extension-focus
57
-
58
-
59
-
60
-
61
-
62
- # [2.0.0-beta.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.1...@tiptap/extension-focus@2.0.0-beta.2) (2021-03-18)
63
-
64
- **Note:** Version bump only for package @tiptap/extension-focus
65
-
66
-
67
-
68
-
69
-
70
- # [2.0.0-beta.1](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.12...@tiptap/extension-focus@2.0.0-beta.1) (2021-03-05)
71
-
72
- **Note:** Version bump only for package @tiptap/extension-focus
73
-
74
-
75
-
76
-
77
-
78
- # [2.0.0-alpha.12](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.11...@tiptap/extension-focus@2.0.0-alpha.12) (2021-02-26)
79
-
80
- **Note:** Version bump only for package @tiptap/extension-focus
81
-
82
-
83
-
84
-
85
-
86
- # [2.0.0-alpha.11](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.10...@tiptap/extension-focus@2.0.0-alpha.11) (2021-02-16)
87
-
88
- **Note:** Version bump only for package @tiptap/extension-focus
89
-
90
-
91
-
92
-
93
-
94
- # [2.0.0-alpha.10](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.9...@tiptap/extension-focus@2.0.0-alpha.10) (2021-02-07)
95
-
96
- **Note:** Version bump only for package @tiptap/extension-focus
97
-
98
-
99
-
100
-
101
-
102
- # [2.0.0-alpha.9](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.8...@tiptap/extension-focus@2.0.0-alpha.9) (2021-02-05)
103
-
104
- **Note:** Version bump only for package @tiptap/extension-focus
105
-
106
-
107
-
108
-
109
-
110
- # [2.0.0-alpha.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.7...@tiptap/extension-focus@2.0.0-alpha.8) (2021-01-29)
111
-
112
- **Note:** Version bump only for package @tiptap/extension-focus
113
-
114
-
115
-
116
-
117
-
118
- # [2.0.0-alpha.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.6...@tiptap/extension-focus@2.0.0-alpha.7) (2021-01-29)
119
-
120
- **Note:** Version bump only for package @tiptap/extension-focus
121
-
122
-
123
-
124
-
125
-
126
- # [2.0.0-alpha.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.5...@tiptap/extension-focus@2.0.0-alpha.6) (2021-01-28)
127
-
128
- **Note:** Version bump only for package @tiptap/extension-focus
129
-
130
-
131
-
132
-
133
-
134
- # [2.0.0-alpha.5](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.4...@tiptap/extension-focus@2.0.0-alpha.5) (2020-12-18)
135
-
136
- **Note:** Version bump only for package @tiptap/extension-focus
137
-
138
-
139
-
140
-
141
-
142
- # [2.0.0-alpha.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.3...@tiptap/extension-focus@2.0.0-alpha.4) (2020-12-02)
143
-
144
- **Note:** Version bump only for package @tiptap/extension-focus
145
-
146
-
147
-
148
-
149
-
150
- # [2.0.0-alpha.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.2...@tiptap/extension-focus@2.0.0-alpha.3) (2020-11-19)
151
-
152
- **Note:** Version bump only for package @tiptap/extension-focus
153
-
154
-
155
-
156
-
157
-
158
- # [2.0.0-alpha.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-alpha.1...@tiptap/extension-focus@2.0.0-alpha.2) (2020-11-19)
159
-
160
- **Note:** Version bump only for package @tiptap/extension-focus
161
-
162
-
163
-
164
-
165
-
166
- # [2.0.0-alpha.1](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@1.0.0-alpha.2...@tiptap/extension-focus@2.0.0-alpha.1) (2020-11-18)
167
-
168
- **Note:** Version bump only for package @tiptap/extension-focus
169
-
170
-
171
-
172
-
173
-
174
- # [1.0.0-alpha.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@1.0.0-alpha.1...@tiptap/extension-focus@1.0.0-alpha.2) (2020-11-16)
175
-
176
- **Note:** Version bump only for package @tiptap/extension-focus
177
-
178
-
179
-
180
-
181
-
182
- # 1.0.0-alpha.1 (2020-11-16)
183
-
184
-
185
- ### Reverts
186
-
187
- * 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) 2020, ü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.