@tiptap/extension-focus 3.0.0-next.3 → 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 +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +11 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -28
- package/dist/index.d.ts +2 -28
- package/dist/index.js +6 -68
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
- package/src/index.ts +3 -3
- package/src/focus.ts +0 -109
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
|
[](https://www.npmjs.com/package/@tiptap/extension-focus)
|
|
3
4
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
5
|
[](https://www.npmjs.com/package/@tiptap/extension-focus)
|
|
5
6
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
7
|
|
|
7
8
|
## Introduction
|
|
8
|
-
|
|
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
|
|
22
|
-
__export(
|
|
23
|
-
|
|
24
|
-
|
|
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(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
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
|
-
|
|
33
|
+
Focus,
|
|
34
|
+
FocusOptions
|
|
98
35
|
});
|
|
99
36
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
2
|
+
import { Focus } from "@tiptap/extensions";
|
|
3
|
+
import { Focus as Focus2, FocusOptions } from "@tiptap/extensions";
|
|
4
|
+
var index_default = Focus;
|
|
68
5
|
export {
|
|
69
|
-
|
|
70
|
-
|
|
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/
|
|
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.
|
|
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":
|
|
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/
|
|
32
|
-
"@tiptap/pm": "^3.0.0-next.3"
|
|
34
|
+
"@tiptap/extensions": "3.0.0-next.4"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|
|
35
|
-
"@tiptap/
|
|
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
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
|
-
})
|