@tiptap/extensions 3.0.0-next.3
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 +18 -0
- package/dist/focus/index.cjs +95 -0
- package/dist/focus/index.cjs.map +1 -0
- package/dist/focus/index.d.cts +28 -0
- package/dist/focus/index.d.ts +28 -0
- package/dist/focus/index.js +68 -0
- package/dist/focus/index.js.map +1 -0
- package/dist/gap-cursor/index.cjs +51 -0
- package/dist/gap-cursor/index.cjs.map +1 -0
- package/dist/gap-cursor/index.d.cts +25 -0
- package/dist/gap-cursor/index.d.ts +25 -0
- package/dist/gap-cursor/index.js +24 -0
- package/dist/gap-cursor/index.js.map +1 -0
- package/dist/index.cjs +222 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +191 -0
- package/dist/index.js.map +1 -0
- package/dist/selection/index.cjs +63 -0
- package/dist/selection/index.cjs.map +1 -0
- package/dist/selection/index.d.cts +17 -0
- package/dist/selection/index.d.ts +17 -0
- package/dist/selection/index.js +36 -0
- package/dist/selection/index.js.map +1 -0
- package/dist/trailing-node/index.cjs +78 -0
- package/dist/trailing-node/index.cjs.map +1 -0
- package/dist/trailing-node/index.d.cts +28 -0
- package/dist/trailing-node/index.d.ts +28 -0
- package/dist/trailing-node/index.js +51 -0
- package/dist/trailing-node/index.js.map +1 -0
- package/package.json +93 -0
- package/src/drop-cursor/drop-cursor.ts +47 -0
- package/src/drop-cursor/index.ts +1 -0
- package/src/focus/focus.ts +110 -0
- package/src/focus/index.ts +1 -0
- package/src/gap-cursor/gap-cursor.ts +46 -0
- package/src/gap-cursor/index.ts +1 -0
- package/src/index.ts +5 -0
- package/src/selection/index.ts +1 -0
- package/src/selection/selection.ts +51 -0
- package/src/trailing-node/index.ts +1 -0
- package/src/trailing-node/trailing-node.ts +84 -0
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @tiptap/extensions
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tiptap/extension-focus)
|
|
4
|
+
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
5
|
+
[](https://www.npmjs.com/package/@tiptap/extension-focus)
|
|
6
|
+
[](https://github.com/sponsors/ueberdosis)
|
|
7
|
+
|
|
8
|
+
## Introduction
|
|
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_.
|
|
11
|
+
|
|
12
|
+
## Official Documentation
|
|
13
|
+
|
|
14
|
+
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -0,0 +1,95 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/focus/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Focus: () => Focus
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/focus/focus.ts
|
|
28
|
+
var import_core = require("@tiptap/core");
|
|
29
|
+
var import_state = require("@tiptap/pm/state");
|
|
30
|
+
var import_view = require("@tiptap/pm/view");
|
|
31
|
+
var Focus = import_core.Extension.create({
|
|
32
|
+
name: "focus",
|
|
33
|
+
addOptions() {
|
|
34
|
+
return {
|
|
35
|
+
className: "has-focus",
|
|
36
|
+
mode: "all"
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
addProseMirrorPlugins() {
|
|
40
|
+
return [
|
|
41
|
+
new import_state.Plugin({
|
|
42
|
+
key: new import_state.PluginKey("focus"),
|
|
43
|
+
props: {
|
|
44
|
+
decorations: ({ doc, selection }) => {
|
|
45
|
+
const { isEditable, isFocused } = this.editor;
|
|
46
|
+
const { anchor } = selection;
|
|
47
|
+
const decorations = [];
|
|
48
|
+
if (!isEditable || !isFocused) {
|
|
49
|
+
return import_view.DecorationSet.create(doc, []);
|
|
50
|
+
}
|
|
51
|
+
let maxLevels = 0;
|
|
52
|
+
if (this.options.mode === "deepest") {
|
|
53
|
+
doc.descendants((node, pos) => {
|
|
54
|
+
if (node.isText) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
58
|
+
if (!isCurrent) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
maxLevels += 1;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
let currentLevel = 0;
|
|
65
|
+
doc.descendants((node, pos) => {
|
|
66
|
+
if (node.isText) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
70
|
+
if (!isCurrent) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
currentLevel += 1;
|
|
74
|
+
const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
|
|
75
|
+
if (outOfScope) {
|
|
76
|
+
return this.options.mode === "deepest";
|
|
77
|
+
}
|
|
78
|
+
decorations.push(
|
|
79
|
+
import_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
80
|
+
class: this.options.className
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
return import_view.DecorationSet.create(doc, decorations);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
Focus
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/focus/index.ts","../../src/focus/focus.ts"],"sourcesContent":["export * from './focus.js'\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 Focus = 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 =\n (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;;;ACAA,kBAA0B;AAC1B,mBAAkC;AAClC,kBAA0C;AA2BnC,IAAM,QAAQ,sBAAU,OAAqB;AAAA,EAClD,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,aACH,KAAK,QAAQ,SAAS,aAAa,YAAY,eAAe,KAC9D,KAAK,QAAQ,SAAS,gBAAgB,eAAe;AAExD,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;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Focus: Extension<FocusOptions, any>;
|
|
27
|
+
|
|
28
|
+
export { Focus, type FocusOptions };
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Focus: Extension<FocusOptions, any>;
|
|
27
|
+
|
|
28
|
+
export { Focus, type FocusOptions };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/focus/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 Focus = 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
|
+
export {
|
|
66
|
+
Focus
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/focus/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 Focus = 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 =\n (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,SAAS,iBAAiB;AAC1B,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AA2BnC,IAAM,QAAQ,UAAU,OAAqB;AAAA,EAClD,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,aACH,KAAK,QAAQ,SAAS,aAAa,YAAY,eAAe,KAC9D,KAAK,QAAQ,SAAS,gBAAgB,eAAe;AAExD,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;","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/gap-cursor/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Gapcursor: () => Gapcursor
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/gap-cursor/gap-cursor.ts
|
|
28
|
+
var import_core = require("@tiptap/core");
|
|
29
|
+
var import_gapcursor = require("@tiptap/pm/gapcursor");
|
|
30
|
+
var Gapcursor = import_core.Extension.create({
|
|
31
|
+
name: "gapCursor",
|
|
32
|
+
addProseMirrorPlugins() {
|
|
33
|
+
return [(0, import_gapcursor.gapCursor)()];
|
|
34
|
+
},
|
|
35
|
+
extendNodeSchema(extension) {
|
|
36
|
+
var _a;
|
|
37
|
+
const context = {
|
|
38
|
+
name: extension.name,
|
|
39
|
+
options: extension.options,
|
|
40
|
+
storage: extension.storage
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
allowGapCursor: (_a = (0, import_core.callOrReturn)((0, import_core.getExtensionField)(extension, "allowGapCursor", context))) != null ? _a : null
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
Gapcursor
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/gap-cursor/index.ts","../../src/gap-cursor/gap-cursor.ts"],"sourcesContent":["export * from './gap-cursor.js'\n","import { callOrReturn, Extension, getExtensionField, ParentConfig } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyE;AACzE,uBAA0B;AA0BnB,IAAM,YAAY,sBAAU,OAAO;AAAA,EACxC,MAAM;AAAA,EAEN,wBAAwB;AACtB,WAAO,KAAC,4BAAU,CAAC;AAAA,EACrB;AAAA,EAEA,iBAAiB,WAAW;AAlC9B;AAmCI,UAAM,UAAU;AAAA,MACd,MAAM,UAAU;AAAA,MAChB,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,iBAAgB,uCAAa,+BAAkB,WAAW,kBAAkB,OAAO,CAAC,MAApE,YAAyE;AAAA,IAC3F;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ParentConfig, Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
|
+
interface NodeConfig<Options, Storage> {
|
|
5
|
+
/**
|
|
6
|
+
* A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.
|
|
7
|
+
* @default null
|
|
8
|
+
*/
|
|
9
|
+
allowGapCursor?: boolean | null | ((this: {
|
|
10
|
+
name: string;
|
|
11
|
+
options: Options;
|
|
12
|
+
storage: Storage;
|
|
13
|
+
parent: ParentConfig<NodeConfig<Options>>['allowGapCursor'];
|
|
14
|
+
}) => boolean | null);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This extension allows you to add a gap cursor to your editor.
|
|
19
|
+
* A gap cursor is a cursor that appears when you click on a place
|
|
20
|
+
* where no content is present, for example inbetween nodes.
|
|
21
|
+
* @see https://tiptap.dev/api/extensions/gapcursor
|
|
22
|
+
*/
|
|
23
|
+
declare const Gapcursor: Extension<any, any>;
|
|
24
|
+
|
|
25
|
+
export { Gapcursor };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ParentConfig, Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
|
+
interface NodeConfig<Options, Storage> {
|
|
5
|
+
/**
|
|
6
|
+
* A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.
|
|
7
|
+
* @default null
|
|
8
|
+
*/
|
|
9
|
+
allowGapCursor?: boolean | null | ((this: {
|
|
10
|
+
name: string;
|
|
11
|
+
options: Options;
|
|
12
|
+
storage: Storage;
|
|
13
|
+
parent: ParentConfig<NodeConfig<Options>>['allowGapCursor'];
|
|
14
|
+
}) => boolean | null);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This extension allows you to add a gap cursor to your editor.
|
|
19
|
+
* A gap cursor is a cursor that appears when you click on a place
|
|
20
|
+
* where no content is present, for example inbetween nodes.
|
|
21
|
+
* @see https://tiptap.dev/api/extensions/gapcursor
|
|
22
|
+
*/
|
|
23
|
+
declare const Gapcursor: Extension<any, any>;
|
|
24
|
+
|
|
25
|
+
export { Gapcursor };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/gap-cursor/gap-cursor.ts
|
|
2
|
+
import { callOrReturn, Extension, getExtensionField } from "@tiptap/core";
|
|
3
|
+
import { gapCursor } from "@tiptap/pm/gapcursor";
|
|
4
|
+
var Gapcursor = Extension.create({
|
|
5
|
+
name: "gapCursor",
|
|
6
|
+
addProseMirrorPlugins() {
|
|
7
|
+
return [gapCursor()];
|
|
8
|
+
},
|
|
9
|
+
extendNodeSchema(extension) {
|
|
10
|
+
var _a;
|
|
11
|
+
const context = {
|
|
12
|
+
name: extension.name,
|
|
13
|
+
options: extension.options,
|
|
14
|
+
storage: extension.storage
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
allowGapCursor: (_a = callOrReturn(getExtensionField(extension, "allowGapCursor", context))) != null ? _a : null
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export {
|
|
22
|
+
Gapcursor
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/gap-cursor/gap-cursor.ts"],"sourcesContent":["import { callOrReturn, Extension, getExtensionField, ParentConfig } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n"],"mappings":";AAAA,SAAS,cAAc,WAAW,yBAAuC;AACzE,SAAS,iBAAiB;AA0BnB,IAAM,YAAY,UAAU,OAAO;AAAA,EACxC,MAAM;AAAA,EAEN,wBAAwB;AACtB,WAAO,CAAC,UAAU,CAAC;AAAA,EACrB;AAAA,EAEA,iBAAiB,WAAW;AAlC9B;AAmCI,UAAM,UAAU;AAAA,MACd,MAAM,UAAU;AAAA,MAChB,SAAS,UAAU;AAAA,MACnB,SAAS,UAAU;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,iBAAgB,kBAAa,kBAAkB,WAAW,kBAAkB,OAAO,CAAC,MAApE,YAAyE;AAAA,IAC3F;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Dropcursor: () => Dropcursor,
|
|
24
|
+
Focus: () => Focus,
|
|
25
|
+
Gapcursor: () => Gapcursor,
|
|
26
|
+
Selection: () => Selection,
|
|
27
|
+
TrailingNode: () => TrailingNode
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/drop-cursor/drop-cursor.ts
|
|
32
|
+
var import_core = require("@tiptap/core");
|
|
33
|
+
var import_dropcursor = require("@tiptap/pm/dropcursor");
|
|
34
|
+
var Dropcursor = import_core.Extension.create({
|
|
35
|
+
name: "dropCursor",
|
|
36
|
+
addOptions() {
|
|
37
|
+
return {
|
|
38
|
+
color: "currentColor",
|
|
39
|
+
width: 1,
|
|
40
|
+
class: void 0
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
addProseMirrorPlugins() {
|
|
44
|
+
return [(0, import_dropcursor.dropCursor)(this.options)];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/focus/focus.ts
|
|
49
|
+
var import_core2 = require("@tiptap/core");
|
|
50
|
+
var import_state = require("@tiptap/pm/state");
|
|
51
|
+
var import_view = require("@tiptap/pm/view");
|
|
52
|
+
var Focus = import_core2.Extension.create({
|
|
53
|
+
name: "focus",
|
|
54
|
+
addOptions() {
|
|
55
|
+
return {
|
|
56
|
+
className: "has-focus",
|
|
57
|
+
mode: "all"
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
addProseMirrorPlugins() {
|
|
61
|
+
return [
|
|
62
|
+
new import_state.Plugin({
|
|
63
|
+
key: new import_state.PluginKey("focus"),
|
|
64
|
+
props: {
|
|
65
|
+
decorations: ({ doc, selection }) => {
|
|
66
|
+
const { isEditable, isFocused } = this.editor;
|
|
67
|
+
const { anchor } = selection;
|
|
68
|
+
const decorations = [];
|
|
69
|
+
if (!isEditable || !isFocused) {
|
|
70
|
+
return import_view.DecorationSet.create(doc, []);
|
|
71
|
+
}
|
|
72
|
+
let maxLevels = 0;
|
|
73
|
+
if (this.options.mode === "deepest") {
|
|
74
|
+
doc.descendants((node, pos) => {
|
|
75
|
+
if (node.isText) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
79
|
+
if (!isCurrent) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
maxLevels += 1;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
let currentLevel = 0;
|
|
86
|
+
doc.descendants((node, pos) => {
|
|
87
|
+
if (node.isText) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
91
|
+
if (!isCurrent) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
currentLevel += 1;
|
|
95
|
+
const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
|
|
96
|
+
if (outOfScope) {
|
|
97
|
+
return this.options.mode === "deepest";
|
|
98
|
+
}
|
|
99
|
+
decorations.push(
|
|
100
|
+
import_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
101
|
+
class: this.options.className
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
return import_view.DecorationSet.create(doc, decorations);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// src/gap-cursor/gap-cursor.ts
|
|
114
|
+
var import_core3 = require("@tiptap/core");
|
|
115
|
+
var import_gapcursor = require("@tiptap/pm/gapcursor");
|
|
116
|
+
var Gapcursor = import_core3.Extension.create({
|
|
117
|
+
name: "gapCursor",
|
|
118
|
+
addProseMirrorPlugins() {
|
|
119
|
+
return [(0, import_gapcursor.gapCursor)()];
|
|
120
|
+
},
|
|
121
|
+
extendNodeSchema(extension) {
|
|
122
|
+
var _a;
|
|
123
|
+
const context = {
|
|
124
|
+
name: extension.name,
|
|
125
|
+
options: extension.options,
|
|
126
|
+
storage: extension.storage
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
allowGapCursor: (_a = (0, import_core3.callOrReturn)((0, import_core3.getExtensionField)(extension, "allowGapCursor", context))) != null ? _a : null
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// src/selection/selection.ts
|
|
135
|
+
var import_core4 = require("@tiptap/core");
|
|
136
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
137
|
+
var import_view2 = require("@tiptap/pm/view");
|
|
138
|
+
var Selection = import_core4.Extension.create({
|
|
139
|
+
name: "selection",
|
|
140
|
+
addOptions() {
|
|
141
|
+
return {
|
|
142
|
+
className: "selection"
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
addProseMirrorPlugins() {
|
|
146
|
+
const { editor, options } = this;
|
|
147
|
+
return [
|
|
148
|
+
new import_state2.Plugin({
|
|
149
|
+
key: new import_state2.PluginKey("selection"),
|
|
150
|
+
props: {
|
|
151
|
+
decorations(state) {
|
|
152
|
+
if (state.selection.empty || editor.isFocused) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
return import_view2.DecorationSet.create(state.doc, [
|
|
156
|
+
import_view2.Decoration.inline(state.selection.from, state.selection.to, {
|
|
157
|
+
class: options.className
|
|
158
|
+
})
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// src/trailing-node/trailing-node.ts
|
|
168
|
+
var import_core5 = require("@tiptap/core");
|
|
169
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
170
|
+
function nodeEqualsType({ types, node }) {
|
|
171
|
+
return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
|
|
172
|
+
}
|
|
173
|
+
var TrailingNode = import_core5.Extension.create({
|
|
174
|
+
name: "trailingNode",
|
|
175
|
+
addOptions() {
|
|
176
|
+
return {
|
|
177
|
+
node: "paragraph",
|
|
178
|
+
notAfter: []
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
addProseMirrorPlugins() {
|
|
182
|
+
const plugin = new import_state3.PluginKey(this.name);
|
|
183
|
+
const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(this.options.node).includes(node.name));
|
|
184
|
+
return [
|
|
185
|
+
new import_state3.Plugin({
|
|
186
|
+
key: plugin,
|
|
187
|
+
appendTransaction: (_, __, state) => {
|
|
188
|
+
const { doc, tr, schema } = state;
|
|
189
|
+
const shouldInsertNodeAtEnd = plugin.getState(state);
|
|
190
|
+
const endPosition = doc.content.size;
|
|
191
|
+
const type = schema.nodes[this.options.node];
|
|
192
|
+
if (!shouldInsertNodeAtEnd) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
return tr.insert(endPosition, type.create());
|
|
196
|
+
},
|
|
197
|
+
state: {
|
|
198
|
+
init: (_, state) => {
|
|
199
|
+
const lastNode = state.tr.doc.lastChild;
|
|
200
|
+
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
201
|
+
},
|
|
202
|
+
apply: (tr, value) => {
|
|
203
|
+
if (!tr.docChanged) {
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
const lastNode = tr.doc.lastChild;
|
|
207
|
+
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
215
|
+
0 && (module.exports = {
|
|
216
|
+
Dropcursor,
|
|
217
|
+
Focus,
|
|
218
|
+
Gapcursor,
|
|
219
|
+
Selection,
|
|
220
|
+
TrailingNode
|
|
221
|
+
});
|
|
222
|
+
//# sourceMappingURL=index.cjs.map
|