@tiptap/extension-focus 2.0.0-beta.21 → 2.0.0-beta.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +71 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +71 -0
- package/package.json +36 -10
- package/src/focus.ts +16 -12
- package/CHANGELOG.md +0 -292
- package/LICENSE.md +0 -21
- package/dist/packages/extension-focus/src/focus.d.ts +0 -6
- package/dist/packages/extension-focus/src/index.d.ts +0 -3
- package/dist/tiptap-extension-focus.cjs.js +0 -71
- package/dist/tiptap-extension-focus.cjs.js.map +0 -1
- package/dist/tiptap-extension-focus.esm.js +0 -67
- package/dist/tiptap-extension-focus.esm.js.map +0 -1
- package/dist/tiptap-extension-focus.umd.js +0 -73
- package/dist/tiptap-extension-focus.umd.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/focus.ts
|
|
2
|
+
var _core = require('@tiptap/core');
|
|
3
|
+
var _state = require('@tiptap/pm/state');
|
|
4
|
+
var _view = require('@tiptap/pm/view');
|
|
5
|
+
var FocusClasses = _core.Extension.create({
|
|
6
|
+
name: "focus",
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
className: "has-focus",
|
|
10
|
+
mode: "all"
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
addProseMirrorPlugins() {
|
|
14
|
+
return [
|
|
15
|
+
new (0, _state.Plugin)({
|
|
16
|
+
key: new (0, _state.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 _view.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
|
+
_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
54
|
+
class: this.options.className
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
return _view.DecorationSet.create(doc, decorations);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/index.ts
|
|
67
|
+
var src_default = FocusClasses;
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
exports.FocusClasses = FocusClasses; exports.default = src_default;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface FocusOptions {
|
|
4
|
+
className: string;
|
|
5
|
+
mode: 'all' | 'deepest' | 'shallowest';
|
|
6
|
+
}
|
|
7
|
+
declare const FocusClasses: Extension<FocusOptions, any>;
|
|
8
|
+
|
|
9
|
+
export { FocusClasses, FocusOptions, FocusClasses as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
// src/index.ts
|
|
67
|
+
var src_default = FocusClasses;
|
|
68
|
+
export {
|
|
69
|
+
FocusClasses,
|
|
70
|
+
src_default as default
|
|
71
|
+
};
|
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.
|
|
4
|
+
"version": "2.0.0-beta.211",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -12,20 +12,46 @@
|
|
|
12
12
|
"type": "github",
|
|
13
13
|
"url": "https://github.com/sponsors/ueberdosis"
|
|
14
14
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/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
|
+
"types": "dist/index.d.ts",
|
|
19
26
|
"files": [
|
|
20
27
|
"src",
|
|
21
28
|
"dist"
|
|
22
29
|
],
|
|
23
30
|
"peerDependencies": {
|
|
24
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
31
|
+
"@tiptap/core": "^2.0.0-beta.209",
|
|
32
|
+
"@tiptap/pm": "^2.0.0-beta.209"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@tiptap/core": "^2.0.0-beta.211",
|
|
36
|
+
"@tiptap/pm": "^2.0.0-beta.211"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
41
|
+
"directory": "packages/extension-focus"
|
|
25
42
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"prosemirror-view": "^1.18.8"
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup"
|
|
29
45
|
},
|
|
30
|
-
"
|
|
46
|
+
"tsup": {
|
|
47
|
+
"entry": [
|
|
48
|
+
"src/index.ts"
|
|
49
|
+
],
|
|
50
|
+
"dts": true,
|
|
51
|
+
"splitting": true,
|
|
52
|
+
"format": [
|
|
53
|
+
"esm",
|
|
54
|
+
"cjs"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
31
57
|
}
|
package/src/focus.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/core'
|
|
2
|
-
import { Plugin, PluginKey } from '
|
|
3
|
-
import {
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 <=
|
|
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 <=
|
|
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(
|
|
75
|
-
|
|
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,292 +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.21](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.20...@tiptap/extension-focus@2.0.0-beta.21) (2021-06-23)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [2.0.0-beta.20](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.19...@tiptap/extension-focus@2.0.0-beta.20) (2021-05-27)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [2.0.0-beta.19](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.18...@tiptap/extension-focus@2.0.0-beta.19) (2021-05-18)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# [2.0.0-beta.18](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.17...@tiptap/extension-focus@2.0.0-beta.18) (2021-05-17)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# [2.0.0-beta.17](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.16...@tiptap/extension-focus@2.0.0-beta.17) (2021-05-13)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# [2.0.0-beta.16](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.15...@tiptap/extension-focus@2.0.0-beta.16) (2021-05-07)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Bug Fixes
|
|
50
|
-
|
|
51
|
-
* revert adding exports ([bc320d0](https://github.com/ueberdosis/tiptap/commit/bc320d0b4b80b0e37a7e47a56e0f6daec6e65d98))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# [2.0.0-beta.15](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.14...@tiptap/extension-focus@2.0.0-beta.15) (2021-05-06)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### Bug Fixes
|
|
61
|
-
|
|
62
|
-
* revert adding type: module ([f8d6475](https://github.com/ueberdosis/tiptap/commit/f8d6475e2151faea6f96baecdd6bd75880d50d2c))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# [2.0.0-beta.14](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.13...@tiptap/extension-focus@2.0.0-beta.14) (2021-05-06)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
### Bug Fixes
|
|
72
|
-
|
|
73
|
-
* add exports to package.json ([1277fa4](https://github.com/ueberdosis/tiptap/commit/1277fa47151e9c039508cdb219bdd0ffe647f4ee))
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# [2.0.0-beta.13](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.12...@tiptap/extension-focus@2.0.0-beta.13) (2021-05-06)
|
|
80
|
-
|
|
81
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# [2.0.0-beta.12](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.11...@tiptap/extension-focus@2.0.0-beta.12) (2021-05-05)
|
|
88
|
-
|
|
89
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
# [2.0.0-beta.11](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.10...@tiptap/extension-focus@2.0.0-beta.11) (2021-05-04)
|
|
96
|
-
|
|
97
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# [2.0.0-beta.10](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-focus@2.0.0-beta.9...@tiptap/extension-focus@2.0.0-beta.10) (2021-04-23)
|
|
104
|
-
|
|
105
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
# [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)
|
|
112
|
-
|
|
113
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
# [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)
|
|
120
|
-
|
|
121
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
# [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)
|
|
128
|
-
|
|
129
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# [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)
|
|
136
|
-
|
|
137
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
# [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)
|
|
144
|
-
|
|
145
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# [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)
|
|
152
|
-
|
|
153
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
# [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)
|
|
160
|
-
|
|
161
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
# [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)
|
|
168
|
-
|
|
169
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
# [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)
|
|
176
|
-
|
|
177
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
# [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)
|
|
184
|
-
|
|
185
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
# [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)
|
|
192
|
-
|
|
193
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# [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)
|
|
200
|
-
|
|
201
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
# [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)
|
|
208
|
-
|
|
209
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
# [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)
|
|
216
|
-
|
|
217
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
# [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)
|
|
224
|
-
|
|
225
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
# [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)
|
|
232
|
-
|
|
233
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
# [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)
|
|
240
|
-
|
|
241
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
# [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)
|
|
248
|
-
|
|
249
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
# [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)
|
|
256
|
-
|
|
257
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
# [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)
|
|
264
|
-
|
|
265
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
# [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)
|
|
272
|
-
|
|
273
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
# [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)
|
|
280
|
-
|
|
281
|
-
**Note:** Version bump only for package @tiptap/extension-focus
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
# 1.0.0-alpha.1 (2020-11-16)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
### Reverts
|
|
291
|
-
|
|
292
|
-
* 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,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var core = require('@tiptap/core');
|
|
6
|
-
var prosemirrorState = require('prosemirror-state');
|
|
7
|
-
var prosemirrorView = require('prosemirror-view');
|
|
8
|
-
|
|
9
|
-
const FocusClasses = core.Extension.create({
|
|
10
|
-
name: 'focus',
|
|
11
|
-
defaultOptions: {
|
|
12
|
-
className: 'has-focus',
|
|
13
|
-
mode: 'all',
|
|
14
|
-
},
|
|
15
|
-
addProseMirrorPlugins() {
|
|
16
|
-
return [
|
|
17
|
-
new prosemirrorState.Plugin({
|
|
18
|
-
key: new prosemirrorState.PluginKey('focus'),
|
|
19
|
-
props: {
|
|
20
|
-
decorations: ({ doc, selection }) => {
|
|
21
|
-
const { isEditable, isFocused } = this.editor;
|
|
22
|
-
const { anchor } = selection;
|
|
23
|
-
const decorations = [];
|
|
24
|
-
if (!isEditable || !isFocused) {
|
|
25
|
-
return prosemirrorView.DecorationSet.create(doc, []);
|
|
26
|
-
}
|
|
27
|
-
// Maximum Levels
|
|
28
|
-
let maxLevels = 0;
|
|
29
|
-
if (this.options.mode === 'deepest') {
|
|
30
|
-
doc.descendants((node, pos) => {
|
|
31
|
-
if (node.isText) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
|
|
35
|
-
if (!isCurrent) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
maxLevels += 1;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
// Loop through current
|
|
42
|
-
let currentLevel = 0;
|
|
43
|
-
doc.descendants((node, pos) => {
|
|
44
|
-
if (node.isText) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
|
|
48
|
-
if (!isCurrent) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
currentLevel += 1;
|
|
52
|
-
const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
|
|
53
|
-
|| (this.options.mode === 'shallowest' && currentLevel > 1);
|
|
54
|
-
if (outOfScope) {
|
|
55
|
-
return this.options.mode === 'deepest';
|
|
56
|
-
}
|
|
57
|
-
decorations.push(prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
58
|
-
class: this.options.className,
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
65
|
-
];
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
exports.FocusClasses = FocusClasses;
|
|
70
|
-
exports.default = FocusClasses;
|
|
71
|
-
//# sourceMappingURL=tiptap-extension-focus.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-focus.cjs.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from 'prosemirror-state'\nimport { DecorationSet, Decoration } from 'prosemirror-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 defaultOptions: {\n className: 'has-focus',\n mode: 'all',\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(Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }))\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","Dec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AA;6BACb;4BAED,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAA;4BAEtE,IAAI,CAAC,SAAS,EAAE;gCACd,OAAO,KAAK,CAAA;6BACb;4BAED,YAAY,IAAI,CAAC,CAAA;4BAEjB,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,GAAG,YAAY,GAAG,CAAC;oCAC7E,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,YAAY,GAAG,CAAC,CAAC,CAAA;4BAE7D,IAAI,UAAU,EAAE;gCACd,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;6BACvC;4BAED,WAAW,CAAC,IAAI,CAACC,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;gCACzD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;6BAC9B,CAAC,CAAC,CAAA;yBACJ,CAAC,CAAA;wBAEF,OAAOD,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
-
import { DecorationSet, Decoration } from 'prosemirror-view';
|
|
4
|
-
|
|
5
|
-
const FocusClasses = Extension.create({
|
|
6
|
-
name: 'focus',
|
|
7
|
-
defaultOptions: {
|
|
8
|
-
className: 'has-focus',
|
|
9
|
-
mode: 'all',
|
|
10
|
-
},
|
|
11
|
-
addProseMirrorPlugins() {
|
|
12
|
-
return [
|
|
13
|
-
new Plugin({
|
|
14
|
-
key: new PluginKey('focus'),
|
|
15
|
-
props: {
|
|
16
|
-
decorations: ({ doc, selection }) => {
|
|
17
|
-
const { isEditable, isFocused } = this.editor;
|
|
18
|
-
const { anchor } = selection;
|
|
19
|
-
const decorations = [];
|
|
20
|
-
if (!isEditable || !isFocused) {
|
|
21
|
-
return DecorationSet.create(doc, []);
|
|
22
|
-
}
|
|
23
|
-
// Maximum Levels
|
|
24
|
-
let maxLevels = 0;
|
|
25
|
-
if (this.options.mode === 'deepest') {
|
|
26
|
-
doc.descendants((node, pos) => {
|
|
27
|
-
if (node.isText) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
|
|
31
|
-
if (!isCurrent) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
maxLevels += 1;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// Loop through current
|
|
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)
|
|
49
|
-
|| (this.options.mode === 'shallowest' && currentLevel > 1);
|
|
50
|
-
if (outOfScope) {
|
|
51
|
-
return this.options.mode === 'deepest';
|
|
52
|
-
}
|
|
53
|
-
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
54
|
-
class: this.options.className,
|
|
55
|
-
}));
|
|
56
|
-
});
|
|
57
|
-
return DecorationSet.create(doc, decorations);
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
}),
|
|
61
|
-
];
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
export default FocusClasses;
|
|
66
|
-
export { FocusClasses };
|
|
67
|
-
//# sourceMappingURL=tiptap-extension-focus.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-focus.esm.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from 'prosemirror-state'\nimport { DecorationSet, Decoration } from 'prosemirror-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 defaultOptions: {\n className: 'has-focus',\n mode: 'all',\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(Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }))\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;MASa,YAAY,GAAG,SAAS,CAAC,MAAM,CAAe;IACzD,IAAI,EAAE,OAAO;IAEb,cAAc,EA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C,CAAA;4BAEtE,IAAI,CAAC,SAAS,EAAE;gCACd,OAAO,KAAK,CAAA;6BACb;4BAED,YAAY,IAAI,CAAC,CAAA;4BAEjB,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,GAAG,YAAY,GAAG,CAAC;oCAC7E,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,YAAY,GAAG,CAAC,CAAC,CAAA;4BAE7D,IAAI,UAAU,EAAE;gCACd,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;6BACvC;4BAED,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;gCACzD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;6BAC9B,CAAC,CAAC,CAAA;yBACJ,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
|
|
@@ -1,73 +0,0 @@
|
|
|
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';
|
|
6
|
-
|
|
7
|
-
const FocusClasses = core.Extension.create({
|
|
8
|
-
name: 'focus',
|
|
9
|
-
defaultOptions: {
|
|
10
|
-
className: 'has-focus',
|
|
11
|
-
mode: 'all',
|
|
12
|
-
},
|
|
13
|
-
addProseMirrorPlugins() {
|
|
14
|
-
return [
|
|
15
|
-
new prosemirrorState.Plugin({
|
|
16
|
-
key: new prosemirrorState.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 prosemirrorView.DecorationSet.create(doc, []);
|
|
24
|
-
}
|
|
25
|
-
// Maximum Levels
|
|
26
|
-
let maxLevels = 0;
|
|
27
|
-
if (this.options.mode === 'deepest') {
|
|
28
|
-
doc.descendants((node, pos) => {
|
|
29
|
-
if (node.isText) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
|
|
33
|
-
if (!isCurrent) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
maxLevels += 1;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
// Loop through current
|
|
40
|
-
let currentLevel = 0;
|
|
41
|
-
doc.descendants((node, pos) => {
|
|
42
|
-
if (node.isText) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const isCurrent = anchor >= pos && anchor <= (pos + node.nodeSize - 1);
|
|
46
|
-
if (!isCurrent) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
currentLevel += 1;
|
|
50
|
-
const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
|
|
51
|
-
|| (this.options.mode === 'shallowest' && currentLevel > 1);
|
|
52
|
-
if (outOfScope) {
|
|
53
|
-
return this.options.mode === 'deepest';
|
|
54
|
-
}
|
|
55
|
-
decorations.push(prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
56
|
-
class: this.options.className,
|
|
57
|
-
}));
|
|
58
|
-
});
|
|
59
|
-
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
];
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
exports.FocusClasses = FocusClasses;
|
|
68
|
-
exports.default = FocusClasses;
|
|
69
|
-
|
|
70
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
71
|
-
|
|
72
|
-
})));
|
|
73
|
-
//# sourceMappingURL=tiptap-extension-focus.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-focus.umd.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from 'prosemirror-state'\nimport { DecorationSet, Decoration } from 'prosemirror-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 defaultOptions: {\n className: 'has-focus',\n mode: 'all',\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(Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }))\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;QASa,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;MACzD,IAAI,EAAE,OAAO;MAEb,cAAc,EAAE;UACd,SAAS,EAAE,WAAW;UACtB,IAAI,EAAE,KAAK;OACZ;MAED,qBAAqB;UACnB,OAAO;cACL,IAAIC,uBAAM,CAAC;kBACT,GAAG,EAAE,IAAIC,0BAAS,CAAC,OAAO,CAAC;kBAC3B,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;0BAC9B,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;0BAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;0BAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;0BAEpC,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,EAAE;8BAC7B,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;2BACrC;;0BAGD,IAAI,SAAS,GAAG,CAAC,CAAA;0BAEjB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;8BACnC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;kCACxB,IAAI,IAAI,CAAC,MAAM,EAAE;sCACf,OAAM;mCACP;kCAED,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAA;kCAEtE,IAAI,CAAC,SAAS,EAAE;sCACd,OAAO,KAAK,CAAA;mCACb;kCAED,SAAS,IAAI,C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