@tiptap/extension-focus 3.0.0-next.2 → 3.0.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024, Tiptap GmbH
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.
package/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # @tiptap/extension-focus
2
+
2
3
  [![Version](https://img.shields.io/npm/v/@tiptap/extension-focus.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-focus)
3
4
  [![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-focus.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
4
5
  [![License](https://img.shields.io/npm/l/@tiptap/extension-focus.svg)](https://www.npmjs.com/package/@tiptap/extension-focus)
5
6
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
7
 
7
8
  ## 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*.
9
+
10
+ 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
11
 
10
12
  ## Official Documentation
13
+
11
14
  Documentation can be found on the [Tiptap website](https://tiptap.dev).
12
15
 
13
16
  ## License
17
+
14
18
  Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
package/dist/index.cjs CHANGED
@@ -18,82 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- FocusClasses: () => FocusClasses,
24
- default: () => src_default
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Focus: () => import_extensions2.Focus,
24
+ FocusOptions: () => import_extensions2.FocusOptions,
25
+ default: () => index_default
25
26
  });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/focus.ts
29
- var import_core = require("@tiptap/core");
30
- var import_state = require("@tiptap/pm/state");
31
- var import_view = require("@tiptap/pm/view");
32
- var FocusClasses = import_core.Extension.create({
33
- name: "focus",
34
- addOptions() {
35
- return {
36
- className: "has-focus",
37
- mode: "all"
38
- };
39
- },
40
- addProseMirrorPlugins() {
41
- return [
42
- new import_state.Plugin({
43
- key: new import_state.PluginKey("focus"),
44
- props: {
45
- decorations: ({ doc, selection }) => {
46
- const { isEditable, isFocused } = this.editor;
47
- const { anchor } = selection;
48
- const decorations = [];
49
- if (!isEditable || !isFocused) {
50
- return import_view.DecorationSet.create(doc, []);
51
- }
52
- let maxLevels = 0;
53
- if (this.options.mode === "deepest") {
54
- doc.descendants((node, pos) => {
55
- if (node.isText) {
56
- return;
57
- }
58
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
59
- if (!isCurrent) {
60
- return false;
61
- }
62
- maxLevels += 1;
63
- });
64
- }
65
- let currentLevel = 0;
66
- doc.descendants((node, pos) => {
67
- if (node.isText) {
68
- return false;
69
- }
70
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
71
- if (!isCurrent) {
72
- return false;
73
- }
74
- currentLevel += 1;
75
- const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
76
- if (outOfScope) {
77
- return this.options.mode === "deepest";
78
- }
79
- decorations.push(
80
- import_view.Decoration.node(pos, pos + node.nodeSize, {
81
- class: this.options.className
82
- })
83
- );
84
- });
85
- return import_view.DecorationSet.create(doc, decorations);
86
- }
87
- }
88
- })
89
- ];
90
- }
91
- });
92
-
93
- // src/index.ts
94
- var src_default = FocusClasses;
27
+ module.exports = __toCommonJS(index_exports);
28
+ var import_extensions = require("@tiptap/extensions");
29
+ var import_extensions2 = require("@tiptap/extensions");
30
+ var index_default = import_extensions.Focus;
95
31
  // Annotate the CommonJS export names for ESM import in node:
96
32
  0 && (module.exports = {
97
- FocusClasses
33
+ Focus,
34
+ FocusOptions
98
35
  });
99
36
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/focus.ts"],"sourcesContent":["import { FocusClasses } from './focus.js'\n\nexport * from './focus.js'\n\nexport default FocusClasses\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAC1B,mBAAkC;AAClC,kBAA0C;AA2BnC,IAAM,eAAe,sBAAU,OAAqB;AAAA,EACzD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,MACX,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,OAAO;AAAA,QAC1B,OAAO;AAAA,UACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAAM;AACnC,kBAAM,EAAE,YAAY,UAAU,IAAI,KAAK;AACvC,kBAAM,EAAE,OAAO,IAAI;AACnB,kBAAM,cAA4B,CAAC;AAEnC,gBAAI,CAAC,cAAc,CAAC,WAAW;AAC7B,qBAAO,0BAAc,OAAO,KAAK,CAAC,CAAC;AAAA,YACrC;AAGA,gBAAI,YAAY;AAEhB,gBAAI,KAAK,QAAQ,SAAS,WAAW;AACnC,kBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,oBAAI,KAAK,QAAQ;AACf;AAAA,gBACF;AAEA,sBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK,WAAW;AAEnE,oBAAI,CAAC,WAAW;AACd,yBAAO;AAAA,gBACT;AAEA,6BAAa;AAAA,cACf,CAAC;AAAA,YACH;AAGA,gBAAI,eAAe;AAEnB,gBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,kBAAI,KAAK,QAAQ;AACf,uBAAO;AAAA,cACT;AAEA,oBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK,WAAW;AAEnE,kBAAI,CAAC,WAAW;AACd,uBAAO;AAAA,cACT;AAEA,8BAAgB;AAEhB,oBAAM,aAAc,KAAK,QAAQ,SAAS,aAAa,YAAY,eAAe,KAC5E,KAAK,QAAQ,SAAS,gBAAgB,eAAe;AAE3D,kBAAI,YAAY;AACd,uBAAO,KAAK,QAAQ,SAAS;AAAA,cAC/B;AAEA,0BAAY;AAAA,gBACV,uBAAW,KAAK,KAAK,MAAM,KAAK,UAAU;AAAA,kBACxC,OAAO,KAAK,QAAQ;AAAA,gBACtB,CAAC;AAAA,cACH;AAAA,YACF,CAAC;AAED,mBAAO,0BAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ADxGD,IAAO,cAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Focus } from '@tiptap/extensions'\n\nexport { Focus, FocusOptions } from '@tiptap/extensions'\n\nexport default Focus\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAsB;AAEtB,IAAAA,qBAAoC;AAEpC,IAAO,gBAAQ;","names":["import_extensions"]}
package/dist/index.d.cts CHANGED
@@ -1,28 +1,2 @@
1
- import { Extension } from '@tiptap/core';
2
-
3
- interface FocusOptions {
4
- /**
5
- * The class name that should be added to the focused node.
6
- * @default 'has-focus'
7
- * @example 'is-focused'
8
- */
9
- className: string;
10
- /**
11
- * The mode by which the focused node is determined.
12
- * - All: All nodes are marked as focused.
13
- * - Deepest: Only the deepest node is marked as focused.
14
- * - Shallowest: Only the shallowest node is marked as focused.
15
- *
16
- * @default 'all'
17
- * @example 'deepest'
18
- * @example 'shallowest'
19
- */
20
- mode: 'all' | 'deepest' | 'shallowest';
21
- }
22
- /**
23
- * This extension allows you to add a class to the focused node.
24
- * @see https://www.tiptap.dev/api/extensions/focus
25
- */
26
- declare const FocusClasses: Extension<FocusOptions, any>;
27
-
28
- export { FocusClasses, type FocusOptions, FocusClasses as default };
1
+ import { Focus } from '@tiptap/extensions';
2
+ export { Focus, FocusOptions, Focus as default } from '@tiptap/extensions';
package/dist/index.d.ts CHANGED
@@ -1,28 +1,2 @@
1
- import { Extension } from '@tiptap/core';
2
-
3
- interface FocusOptions {
4
- /**
5
- * The class name that should be added to the focused node.
6
- * @default 'has-focus'
7
- * @example 'is-focused'
8
- */
9
- className: string;
10
- /**
11
- * The mode by which the focused node is determined.
12
- * - All: All nodes are marked as focused.
13
- * - Deepest: Only the deepest node is marked as focused.
14
- * - Shallowest: Only the shallowest node is marked as focused.
15
- *
16
- * @default 'all'
17
- * @example 'deepest'
18
- * @example 'shallowest'
19
- */
20
- mode: 'all' | 'deepest' | 'shallowest';
21
- }
22
- /**
23
- * This extension allows you to add a class to the focused node.
24
- * @see https://www.tiptap.dev/api/extensions/focus
25
- */
26
- declare const FocusClasses: Extension<FocusOptions, any>;
27
-
28
- export { FocusClasses, type FocusOptions, FocusClasses as default };
1
+ import { Focus } from '@tiptap/extensions';
2
+ export { Focus, FocusOptions, Focus as default } from '@tiptap/extensions';
package/dist/index.js CHANGED
@@ -1,72 +1,10 @@
1
- // src/focus.ts
2
- import { Extension } from "@tiptap/core";
3
- import { Plugin, PluginKey } from "@tiptap/pm/state";
4
- import { Decoration, DecorationSet } from "@tiptap/pm/view";
5
- var FocusClasses = Extension.create({
6
- name: "focus",
7
- addOptions() {
8
- return {
9
- className: "has-focus",
10
- mode: "all"
11
- };
12
- },
13
- addProseMirrorPlugins() {
14
- return [
15
- new Plugin({
16
- key: new PluginKey("focus"),
17
- props: {
18
- decorations: ({ doc, selection }) => {
19
- const { isEditable, isFocused } = this.editor;
20
- const { anchor } = selection;
21
- const decorations = [];
22
- if (!isEditable || !isFocused) {
23
- return DecorationSet.create(doc, []);
24
- }
25
- let maxLevels = 0;
26
- if (this.options.mode === "deepest") {
27
- doc.descendants((node, pos) => {
28
- if (node.isText) {
29
- return;
30
- }
31
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
32
- if (!isCurrent) {
33
- return false;
34
- }
35
- maxLevels += 1;
36
- });
37
- }
38
- let currentLevel = 0;
39
- doc.descendants((node, pos) => {
40
- if (node.isText) {
41
- return false;
42
- }
43
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
44
- if (!isCurrent) {
45
- return false;
46
- }
47
- currentLevel += 1;
48
- const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
49
- if (outOfScope) {
50
- return this.options.mode === "deepest";
51
- }
52
- decorations.push(
53
- Decoration.node(pos, pos + node.nodeSize, {
54
- class: this.options.className
55
- })
56
- );
57
- });
58
- return DecorationSet.create(doc, decorations);
59
- }
60
- }
61
- })
62
- ];
63
- }
64
- });
65
-
66
1
  // src/index.ts
67
- var src_default = FocusClasses;
2
+ import { Focus } from "@tiptap/extensions";
3
+ import { Focus as Focus2, FocusOptions } from "@tiptap/extensions";
4
+ var index_default = Focus;
68
5
  export {
69
- FocusClasses,
70
- src_default as default
6
+ Focus2 as Focus,
7
+ FocusOptions,
8
+ index_default as default
71
9
  };
72
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/focus.ts","../src/index.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 /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\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","import { FocusClasses } from './focus.js'\n\nexport * from './focus.js'\n\nexport default FocusClasses\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AA2BnC,IAAM,eAAe,UAAU,OAAqB;AAAA,EACzD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,MACX,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,OAAO;AAAA,QAC1B,OAAO;AAAA,UACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAAM;AACnC,kBAAM,EAAE,YAAY,UAAU,IAAI,KAAK;AACvC,kBAAM,EAAE,OAAO,IAAI;AACnB,kBAAM,cAA4B,CAAC;AAEnC,gBAAI,CAAC,cAAc,CAAC,WAAW;AAC7B,qBAAO,cAAc,OAAO,KAAK,CAAC,CAAC;AAAA,YACrC;AAGA,gBAAI,YAAY;AAEhB,gBAAI,KAAK,QAAQ,SAAS,WAAW;AACnC,kBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,oBAAI,KAAK,QAAQ;AACf;AAAA,gBACF;AAEA,sBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK,WAAW;AAEnE,oBAAI,CAAC,WAAW;AACd,yBAAO;AAAA,gBACT;AAEA,6BAAa;AAAA,cACf,CAAC;AAAA,YACH;AAGA,gBAAI,eAAe;AAEnB,gBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,kBAAI,KAAK,QAAQ;AACf,uBAAO;AAAA,cACT;AAEA,oBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK,WAAW;AAEnE,kBAAI,CAAC,WAAW;AACd,uBAAO;AAAA,cACT;AAEA,8BAAgB;AAEhB,oBAAM,aAAc,KAAK,QAAQ,SAAS,aAAa,YAAY,eAAe,KAC5E,KAAK,QAAQ,SAAS,gBAAgB,eAAe;AAE3D,kBAAI,YAAY;AACd,uBAAO,KAAK,QAAQ,SAAS;AAAA,cAC/B;AAEA,0BAAY;AAAA,gBACV,WAAW,KAAK,KAAK,MAAM,KAAK,UAAU;AAAA,kBACxC,OAAO,KAAK,QAAQ;AAAA,gBACtB,CAAC;AAAA,cACH;AAAA,YACF,CAAC;AAED,mBAAO,cAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ACxGD,IAAO,cAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Focus } from '@tiptap/extensions'\n\nexport { Focus, FocusOptions } from '@tiptap/extensions'\n\nexport default Focus\n"],"mappings":";AAAA,SAAS,aAAa;AAEtB,SAAS,SAAAA,QAAO,oBAAoB;AAEpC,IAAO,gBAAQ;","names":["Focus"]}
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": "3.0.0-next.2",
4
+ "version": "3.0.0-next.4",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,7 +15,10 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
18
+ "types": {
19
+ "import": "./dist/index.d.ts",
20
+ "require": "./dist/index.d.cts"
21
+ },
19
22
  "import": "./dist/index.js",
20
23
  "require": "./dist/index.cjs"
21
24
  }
@@ -28,12 +31,10 @@
28
31
  "dist"
29
32
  ],
30
33
  "devDependencies": {
31
- "@tiptap/core": "^3.0.0-next.2",
32
- "@tiptap/pm": "^3.0.0-next.2"
34
+ "@tiptap/extensions": "3.0.0-next.4"
33
35
  },
34
36
  "peerDependencies": {
35
- "@tiptap/core": "^3.0.0-next.1",
36
- "@tiptap/pm": "^3.0.0-next.1"
37
+ "@tiptap/extensions": "3.0.0-next.4"
37
38
  },
38
39
  "repository": {
39
40
  "type": "git",
@@ -41,6 +42,7 @@
41
42
  "directory": "packages/extension-focus"
42
43
  },
43
44
  "scripts": {
44
- "build": "tsup"
45
+ "build": "tsup",
46
+ "lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
45
47
  }
46
- }
48
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { FocusClasses } from './focus.js'
1
+ import { Focus } from '@tiptap/extensions'
2
2
 
3
- export * from './focus.js'
3
+ export { Focus, FocusOptions } from '@tiptap/extensions'
4
4
 
5
- export default FocusClasses
5
+ export default Focus
package/src/focus.ts DELETED
@@ -1,109 +0,0 @@
1
- import { Extension } from '@tiptap/core'
2
- import { Plugin, PluginKey } from '@tiptap/pm/state'
3
- import { Decoration, DecorationSet } from '@tiptap/pm/view'
4
-
5
- export interface FocusOptions {
6
- /**
7
- * The class name that should be added to the focused node.
8
- * @default 'has-focus'
9
- * @example 'is-focused'
10
- */
11
- className: string
12
-
13
- /**
14
- * The mode by which the focused node is determined.
15
- * - All: All nodes are marked as focused.
16
- * - Deepest: Only the deepest node is marked as focused.
17
- * - Shallowest: Only the shallowest node is marked as focused.
18
- *
19
- * @default 'all'
20
- * @example 'deepest'
21
- * @example 'shallowest'
22
- */
23
- mode: 'all' | 'deepest' | 'shallowest'
24
- }
25
-
26
- /**
27
- * This extension allows you to add a class to the focused node.
28
- * @see https://www.tiptap.dev/api/extensions/focus
29
- */
30
- export const FocusClasses = Extension.create<FocusOptions>({
31
- name: 'focus',
32
-
33
- addOptions() {
34
- return {
35
- className: 'has-focus',
36
- mode: 'all',
37
- }
38
- },
39
-
40
- addProseMirrorPlugins() {
41
- return [
42
- new Plugin({
43
- key: new PluginKey('focus'),
44
- props: {
45
- decorations: ({ doc, selection }) => {
46
- const { isEditable, isFocused } = this.editor
47
- const { anchor } = selection
48
- const decorations: Decoration[] = []
49
-
50
- if (!isEditable || !isFocused) {
51
- return DecorationSet.create(doc, [])
52
- }
53
-
54
- // Maximum Levels
55
- let maxLevels = 0
56
-
57
- if (this.options.mode === 'deepest') {
58
- doc.descendants((node, pos) => {
59
- if (node.isText) {
60
- return
61
- }
62
-
63
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1
64
-
65
- if (!isCurrent) {
66
- return false
67
- }
68
-
69
- maxLevels += 1
70
- })
71
- }
72
-
73
- // Loop through current
74
- let currentLevel = 0
75
-
76
- doc.descendants((node, pos) => {
77
- if (node.isText) {
78
- return false
79
- }
80
-
81
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1
82
-
83
- if (!isCurrent) {
84
- return false
85
- }
86
-
87
- currentLevel += 1
88
-
89
- const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
90
- || (this.options.mode === 'shallowest' && currentLevel > 1)
91
-
92
- if (outOfScope) {
93
- return this.options.mode === 'deepest'
94
- }
95
-
96
- decorations.push(
97
- Decoration.node(pos, pos + node.nodeSize, {
98
- class: this.options.className,
99
- }),
100
- )
101
- })
102
-
103
- return DecorationSet.create(doc, decorations)
104
- },
105
- },
106
- }),
107
- ]
108
- },
109
- })