@tiptap/extension-focus 2.11.7 → 3.0.0-beta.1
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 +32 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +9 -72
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +4 -3
- package/dist/focus.d.ts +0 -26
- package/dist/focus.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -79
- package/dist/index.umd.js.map +0 -1
- package/src/focus.ts +0 -109
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, 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
|
@@ -1,77 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* This extension allows you to add a class to the focused node.
|
|
11
|
-
* @see https://www.tiptap.dev/api/extensions/focus
|
|
12
|
-
*/
|
|
13
|
-
const FocusClasses = core.Extension.create({
|
|
14
|
-
name: 'focus',
|
|
15
|
-
addOptions() {
|
|
16
|
-
return {
|
|
17
|
-
className: 'has-focus',
|
|
18
|
-
mode: 'all',
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
addProseMirrorPlugins() {
|
|
22
|
-
return [
|
|
23
|
-
new state.Plugin({
|
|
24
|
-
key: new state.PluginKey('focus'),
|
|
25
|
-
props: {
|
|
26
|
-
decorations: ({ doc, selection }) => {
|
|
27
|
-
const { isEditable, isFocused } = this.editor;
|
|
28
|
-
const { anchor } = selection;
|
|
29
|
-
const decorations = [];
|
|
30
|
-
if (!isEditable || !isFocused) {
|
|
31
|
-
return view.DecorationSet.create(doc, []);
|
|
32
|
-
}
|
|
33
|
-
// Maximum Levels
|
|
34
|
-
let maxLevels = 0;
|
|
35
|
-
if (this.options.mode === 'deepest') {
|
|
36
|
-
doc.descendants((node, pos) => {
|
|
37
|
-
if (node.isText) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
41
|
-
if (!isCurrent) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
maxLevels += 1;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
// Loop through current
|
|
48
|
-
let currentLevel = 0;
|
|
49
|
-
doc.descendants((node, pos) => {
|
|
50
|
-
if (node.isText) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
54
|
-
if (!isCurrent) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
currentLevel += 1;
|
|
58
|
-
const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
|
|
59
|
-
|| (this.options.mode === 'shallowest' && currentLevel > 1);
|
|
60
|
-
if (outOfScope) {
|
|
61
|
-
return this.options.mode === 'deepest';
|
|
62
|
-
}
|
|
63
|
-
decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
|
|
64
|
-
class: this.options.className,
|
|
65
|
-
}));
|
|
66
|
-
});
|
|
67
|
-
return view.DecorationSet.create(doc, decorations);
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
|
-
];
|
|
72
|
-
},
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Focus: () => import_extensions2.Focus,
|
|
24
|
+
default: () => index_default
|
|
73
25
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_extensions = require("@tiptap/extensions");
|
|
28
|
+
var import_extensions2 = require("@tiptap/extensions");
|
|
29
|
+
var index_default = import_extensions.Focus;
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
Focus
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Focus } from '@tiptap/extensions'\n\nexport type { FocusOptions } from '@tiptap/extensions'\nexport { Focus } from '@tiptap/extensions'\n\nexport default Focus\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAsB;AAGtB,IAAAA,qBAAsB;AAEtB,IAAO,gBAAQ;","names":["import_extensions"]}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,72 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name: 'focus',
|
|
11
|
-
addOptions() {
|
|
12
|
-
return {
|
|
13
|
-
className: 'has-focus',
|
|
14
|
-
mode: 'all',
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
addProseMirrorPlugins() {
|
|
18
|
-
return [
|
|
19
|
-
new Plugin({
|
|
20
|
-
key: new PluginKey('focus'),
|
|
21
|
-
props: {
|
|
22
|
-
decorations: ({ doc, selection }) => {
|
|
23
|
-
const { isEditable, isFocused } = this.editor;
|
|
24
|
-
const { anchor } = selection;
|
|
25
|
-
const decorations = [];
|
|
26
|
-
if (!isEditable || !isFocused) {
|
|
27
|
-
return DecorationSet.create(doc, []);
|
|
28
|
-
}
|
|
29
|
-
// Maximum Levels
|
|
30
|
-
let maxLevels = 0;
|
|
31
|
-
if (this.options.mode === 'deepest') {
|
|
32
|
-
doc.descendants((node, pos) => {
|
|
33
|
-
if (node.isText) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
37
|
-
if (!isCurrent) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
maxLevels += 1;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// Loop through current
|
|
44
|
-
let currentLevel = 0;
|
|
45
|
-
doc.descendants((node, pos) => {
|
|
46
|
-
if (node.isText) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
50
|
-
if (!isCurrent) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
currentLevel += 1;
|
|
54
|
-
const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
|
|
55
|
-
|| (this.options.mode === 'shallowest' && currentLevel > 1);
|
|
56
|
-
if (outOfScope) {
|
|
57
|
-
return this.options.mode === 'deepest';
|
|
58
|
-
}
|
|
59
|
-
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
60
|
-
class: this.options.className,
|
|
61
|
-
}));
|
|
62
|
-
});
|
|
63
|
-
return DecorationSet.create(doc, decorations);
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
}),
|
|
67
|
-
];
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export { FocusClasses, FocusClasses as default };
|
|
72
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Focus } from "@tiptap/extensions";
|
|
3
|
+
import { Focus as Focus2 } from "@tiptap/extensions";
|
|
4
|
+
var index_default = Focus;
|
|
5
|
+
export {
|
|
6
|
+
Focus2 as Focus,
|
|
7
|
+
index_default as default
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Focus } from '@tiptap/extensions'\n\nexport type { FocusOptions } from '@tiptap/extensions'\nexport { Focus } from '@tiptap/extensions'\n\nexport default Focus\n"],"mappings":";AAAA,SAAS,aAAa;AAGtB,SAAS,SAAAA,cAAa;AAEtB,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": "
|
|
4
|
+
"version": "3.0.0-beta.1",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,34 +15,34 @@
|
|
|
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
|
}
|
|
22
25
|
},
|
|
23
26
|
"main": "dist/index.cjs",
|
|
24
27
|
"module": "dist/index.js",
|
|
25
|
-
"umd": "dist/index.umd.js",
|
|
26
28
|
"types": "dist/index.d.ts",
|
|
27
29
|
"files": [
|
|
28
30
|
"src",
|
|
29
31
|
"dist"
|
|
30
32
|
],
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@tiptap/
|
|
33
|
-
"@tiptap/pm": "^2.11.7"
|
|
34
|
+
"@tiptap/extensions": "3.0.0-beta.1"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
|
-
"@tiptap/
|
|
37
|
-
"@tiptap/pm": "^2.7.0"
|
|
37
|
+
"@tiptap/extensions": "3.0.0-beta.1"
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
41
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
42
|
-
"directory": "packages/extension-focus"
|
|
42
|
+
"directory": "packages-deprecated/extension-focus"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Focus } from '@tiptap/extensions'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type { FocusOptions } from '@tiptap/extensions'
|
|
4
|
+
export { Focus } from '@tiptap/extensions'
|
|
4
5
|
|
|
5
|
-
export default
|
|
6
|
+
export default Focus
|
package/dist/focus.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
export interface FocusOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The class name that should be added to the focused node.
|
|
5
|
-
* @default 'has-focus'
|
|
6
|
-
* @example 'is-focused'
|
|
7
|
-
*/
|
|
8
|
-
className: string;
|
|
9
|
-
/**
|
|
10
|
-
* The mode by which the focused node is determined.
|
|
11
|
-
* - All: All nodes are marked as focused.
|
|
12
|
-
* - Deepest: Only the deepest node is marked as focused.
|
|
13
|
-
* - Shallowest: Only the shallowest node is marked as focused.
|
|
14
|
-
*
|
|
15
|
-
* @default 'all'
|
|
16
|
-
* @example 'deepest'
|
|
17
|
-
* @example 'shallowest'
|
|
18
|
-
*/
|
|
19
|
-
mode: 'all' | 'deepest' | 'shallowest';
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* This extension allows you to add a class to the focused node.
|
|
23
|
-
* @see https://www.tiptap.dev/api/extensions/focus
|
|
24
|
-
*/
|
|
25
|
-
export declare const FocusClasses: Extension<FocusOptions, any>;
|
|
26
|
-
//# sourceMappingURL=focus.d.ts.map
|
package/dist/focus.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../src/focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAIxC,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;;;;;;;OASG;IACH,IAAI,EAAE,KAAK,GAAG,SAAS,GAAG,YAAY,CAAA;CACvC;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,8BA+EvB,CAAA"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,cAAc,YAAY,CAAA;AAE1B,eAAe,YAAY,CAAA"}
|
package/dist/index.umd.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
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
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This extension allows you to add a class to the focused node.
|
|
9
|
-
* @see https://www.tiptap.dev/api/extensions/focus
|
|
10
|
-
*/
|
|
11
|
-
const FocusClasses = core.Extension.create({
|
|
12
|
-
name: 'focus',
|
|
13
|
-
addOptions() {
|
|
14
|
-
return {
|
|
15
|
-
className: 'has-focus',
|
|
16
|
-
mode: 'all',
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
addProseMirrorPlugins() {
|
|
20
|
-
return [
|
|
21
|
-
new state.Plugin({
|
|
22
|
-
key: new state.PluginKey('focus'),
|
|
23
|
-
props: {
|
|
24
|
-
decorations: ({ doc, selection }) => {
|
|
25
|
-
const { isEditable, isFocused } = this.editor;
|
|
26
|
-
const { anchor } = selection;
|
|
27
|
-
const decorations = [];
|
|
28
|
-
if (!isEditable || !isFocused) {
|
|
29
|
-
return view.DecorationSet.create(doc, []);
|
|
30
|
-
}
|
|
31
|
-
// Maximum Levels
|
|
32
|
-
let maxLevels = 0;
|
|
33
|
-
if (this.options.mode === 'deepest') {
|
|
34
|
-
doc.descendants((node, pos) => {
|
|
35
|
-
if (node.isText) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
39
|
-
if (!isCurrent) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
maxLevels += 1;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
// Loop through current
|
|
46
|
-
let currentLevel = 0;
|
|
47
|
-
doc.descendants((node, pos) => {
|
|
48
|
-
if (node.isText) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
52
|
-
if (!isCurrent) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
currentLevel += 1;
|
|
56
|
-
const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
|
|
57
|
-
|| (this.options.mode === 'shallowest' && currentLevel > 1);
|
|
58
|
-
if (outOfScope) {
|
|
59
|
-
return this.options.mode === 'deepest';
|
|
60
|
-
}
|
|
61
|
-
decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
|
|
62
|
-
class: this.options.className,
|
|
63
|
-
}));
|
|
64
|
-
});
|
|
65
|
-
return view.DecorationSet.create(doc, decorations);
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
}),
|
|
69
|
-
];
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
exports.FocusClasses = FocusClasses;
|
|
74
|
-
exports.default = FocusClasses;
|
|
75
|
-
|
|
76
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
77
|
-
|
|
78
|
-
}));
|
|
79
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 /**\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"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;EAyBA;;;EAGG;AACU,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;OACF;MAED,qBAAqB,GAAA;UACnB,OAAO;EACL,YAAA,IAAIC,YAAM,CAAC;EACT,gBAAA,GAAG,EAAE,IAAIC,eAAS,CAAC,OAAO,CAAC;EAC3B,gBAAA,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;0BAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM;EAC7C,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS;0BAC5B,MAAM,WAAW,GAAiB,EAAE;EAEpC,wBAAA,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,EAAE;8BAC7B,OAAOC,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC;;;0BAItC,IAAI,SAAS,GAAG,CAAC;0BAEjB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;8BACnC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,KAAI;EAC5B,gCAAA,IAAI,IAAI,CAAC,MAAM,EAAE;sCACf;;EAGF,gCAAA,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC;kCAEpE,IAAI,CAAC,SAAS,EAAE;EACd,oCAAA,OAAO,KAAK;;kCAGd,SAAS,IAAI,CAAC;EAChB,6BAAC,CAAC;;;0BAIJ,IAAI,YAAY,GAAG,CAAC;0BAEpB,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,KAAI;EAC5B,4BAAA,IAAI,IAAI,CAAC,MAAM,EAAE;EACf,gCAAA,OAAO,KAAK;;EAGd,4BAAA,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC;8BAEpE,IAAI,CAAC,SAAS,EAAE;EACd,gCAAA,OAAO,KAAK;;8BAGd,YAAY,IAAI,CAAC;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;8BAE7D,IAAI,UAAU,EAAE;EACd,gCAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS;;EAGxC,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;EACH,yBAAC,CAAC;0BAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH;OACF;EACF,CAAA;;;;;;;;;;;"}
|
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
|
-
})
|