@tiptap/extensions 3.30.2 → 3.30.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/character-count/index.cjs +84 -128
- package/dist/character-count/index.cjs.map +1 -1
- package/dist/character-count/index.d.cts +59 -58
- package/dist/character-count/index.d.cts.map +1 -0
- package/dist/character-count/index.d.ts +59 -58
- package/dist/character-count/index.d.ts.map +1 -0
- package/dist/character-count/index.js +82 -100
- package/dist/character-count/index.js.map +1 -1
- package/dist/drop-cursor/index.cjs +24 -44
- package/dist/drop-cursor/index.cjs.map +1 -1
- package/dist/drop-cursor/index.d.cts +23 -22
- package/dist/drop-cursor/index.d.cts.map +1 -0
- package/dist/drop-cursor/index.d.ts +23 -22
- package/dist/drop-cursor/index.d.ts.map +1 -0
- package/dist/drop-cursor/index.js +22 -16
- package/dist/drop-cursor/index.js.map +1 -1
- package/dist/focus/index.cjs +45 -92
- package/dist/focus/index.cjs.map +1 -1
- package/dist/focus/index.d.cts +22 -21
- package/dist/focus/index.d.cts.map +1 -0
- package/dist/focus/index.d.ts +22 -21
- package/dist/focus/index.d.ts.map +1 -0
- package/dist/focus/index.js +42 -63
- package/dist/focus/index.js.map +1 -1
- package/dist/gap-cursor/index.cjs +26 -48
- package/dist/gap-cursor/index.cjs.map +1 -1
- package/dist/gap-cursor/index.d.cts +16 -15
- package/dist/gap-cursor/index.d.cts.map +1 -0
- package/dist/gap-cursor/index.d.ts +16 -15
- package/dist/gap-cursor/index.d.ts.map +1 -0
- package/dist/gap-cursor/index.js +25 -21
- package/dist/gap-cursor/index.js.map +1 -1
- package/dist/index.cjs +667 -742
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +231 -220
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +231 -220
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +654 -703
- package/dist/index.js.map +1 -1
- package/dist/placeholder/index.cjs +344 -376
- package/dist/placeholder/index.cjs.map +1 -1
- package/dist/placeholder/index.d.cts +73 -69
- package/dist/placeholder/index.d.cts.map +1 -0
- package/dist/placeholder/index.d.ts +73 -69
- package/dist/placeholder/index.d.ts.map +1 -0
- package/dist/placeholder/index.js +340 -346
- package/dist/placeholder/index.js.map +1 -1
- package/dist/selection/index.cjs +62 -86
- package/dist/selection/index.cjs.map +1 -1
- package/dist/selection/index.d.cts +11 -10
- package/dist/selection/index.d.cts.map +1 -0
- package/dist/selection/index.d.ts +11 -10
- package/dist/selection/index.d.ts.map +1 -0
- package/dist/selection/index.js +58 -56
- package/dist/selection/index.js.map +1 -1
- package/dist/trailing-node/index.cjs +59 -89
- package/dist/trailing-node/index.cjs.map +1 -1
- package/dist/trailing-node/index.d.cts +17 -16
- package/dist/trailing-node/index.d.cts.map +1 -0
- package/dist/trailing-node/index.d.ts +17 -16
- package/dist/trailing-node/index.d.ts.map +1 -0
- package/dist/trailing-node/index.js +55 -59
- package/dist/trailing-node/index.js.map +1 -1
- package/dist/undo-redo/index.cjs +45 -63
- package/dist/undo-redo/index.cjs.map +1 -1
- package/dist/undo-redo/index.d.cts +31 -30
- package/dist/undo-redo/index.d.cts.map +1 -0
- package/dist/undo-redo/index.d.ts +31 -30
- package/dist/undo-redo/index.d.ts.map +1 -0
- package/dist/undo-redo/index.js +43 -35
- package/dist/undo-redo/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,92 +1,62 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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/trailing-node/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
TrailingNode: () => TrailingNode,
|
|
24
|
-
skipTrailingNodeMeta: () => skipTrailingNodeMeta
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
|
-
// src/trailing-node/trailing-node.ts
|
|
29
|
-
var import_core = require("@tiptap/core");
|
|
30
|
-
var import_state = require("@tiptap/pm/state");
|
|
31
|
-
var skipTrailingNodeMeta = "skipTrailingNode";
|
|
32
|
-
function nodeEqualsType({
|
|
33
|
-
types,
|
|
34
|
-
node
|
|
35
|
-
}) {
|
|
36
|
-
return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _tiptap_core = require("@tiptap/core");
|
|
3
|
+
let _tiptap_pm_state = require("@tiptap/pm/state");
|
|
4
|
+
//#region src/trailing-node/trailing-node.ts
|
|
5
|
+
const skipTrailingNodeMeta = "skipTrailingNode";
|
|
6
|
+
function nodeEqualsType({ types, node }) {
|
|
7
|
+
return node && Array.isArray(types) && types.includes(node.type) || (node === null || node === void 0 ? void 0 : node.type) === types;
|
|
37
8
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
-
0 && (module.exports = {
|
|
89
|
-
TrailingNode,
|
|
90
|
-
skipTrailingNodeMeta
|
|
9
|
+
/**
|
|
10
|
+
* This extension allows you to add an extra node at the end of the document.
|
|
11
|
+
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
12
|
+
*/
|
|
13
|
+
const TrailingNode = _tiptap_core.Extension.create({
|
|
14
|
+
name: "trailingNode",
|
|
15
|
+
addOptions() {
|
|
16
|
+
return {
|
|
17
|
+
node: void 0,
|
|
18
|
+
notAfter: []
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
addProseMirrorPlugins() {
|
|
22
|
+
var _this$editor$schema$t;
|
|
23
|
+
const plugin = new _tiptap_pm_state.PluginKey(this.name);
|
|
24
|
+
const defaultNode = this.options.node || ((_this$editor$schema$t = this.editor.schema.topNodeType.contentMatch.defaultType) === null || _this$editor$schema$t === void 0 ? void 0 : _this$editor$schema$t.name) || "paragraph";
|
|
25
|
+
const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(defaultNode).includes(node.name));
|
|
26
|
+
return [new _tiptap_pm_state.Plugin({
|
|
27
|
+
key: plugin,
|
|
28
|
+
appendTransaction: (transactions, __, state) => {
|
|
29
|
+
const { doc, tr, schema } = state;
|
|
30
|
+
const shouldInsertNodeAtEnd = plugin.getState(state);
|
|
31
|
+
const endPosition = doc.content.size;
|
|
32
|
+
const type = schema.nodes[defaultNode];
|
|
33
|
+
if (transactions.some((transaction) => transaction.getMeta("skipTrailingNode"))) return;
|
|
34
|
+
if (!shouldInsertNodeAtEnd) return;
|
|
35
|
+
return tr.insert(endPosition, type.create());
|
|
36
|
+
},
|
|
37
|
+
state: {
|
|
38
|
+
init: (_, state) => {
|
|
39
|
+
const lastNode = state.tr.doc.lastChild;
|
|
40
|
+
return !nodeEqualsType({
|
|
41
|
+
node: lastNode,
|
|
42
|
+
types: disabledNodes
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
apply: (tr, value) => {
|
|
46
|
+
if (!tr.docChanged) return value;
|
|
47
|
+
if (tr.getMeta("__uniqueIDTransaction")) return value;
|
|
48
|
+
const lastNode = tr.doc.lastChild;
|
|
49
|
+
return !nodeEqualsType({
|
|
50
|
+
node: lastNode,
|
|
51
|
+
types: disabledNodes
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})];
|
|
56
|
+
}
|
|
91
57
|
});
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.TrailingNode = TrailingNode;
|
|
60
|
+
exports.skipTrailingNodeMeta = skipTrailingNodeMeta;
|
|
61
|
+
|
|
92
62
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Extension","PluginKey","Plugin"],"sources":["../../src/trailing-node/trailing-node.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";;;;AAIA,MAAa,uBAAuB;AAEpC,SAAS,eAAe,EACtB,OACA,QAIC;CACD,OAAQ,QAAQ,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,IAAI,MAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAM,KAAM,UAAS;AACvF;;;;;AA2BA,MAAa,eAAeA,aAAAA,UAAU,OAA4B;CAChE,MAAM;CAEN,aAAa;EACX,OAAO;GACL,MAAM,KAAA;GACN,UAAU,CAAC;EACb;CACF;CAEA,wBAAwB;;EACtB,MAAM,SAAS,IAAIC,iBAAAA,UAAU,KAAK,IAAI;EACtC,MAAM,cACJ,KAAK,QAAQ,UAAA,wBACb,KAAK,OAAO,OAAO,YAAY,aAAa,iBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAa,SACzD;EAEF,MAAM,gBAAgB,OAAO,QAAQ,KAAK,OAAO,OAAO,KAAK,CAAC,CAC3D,KAAK,GAAG,WAAW,KAAK,CAAC,CACzB,QAAO,UAAS,KAAK,QAAQ,YAAY,CAAC,EAAA,CAAG,OAAO,WAAW,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC;EAEvF,OAAO,CACL,IAAIC,iBAAAA,OAAO;GACT,KAAK;GACL,oBAAoB,cAAc,IAAI,UAAU;IAC9C,MAAM,EAAE,KAAK,IAAI,WAAW;IAC5B,MAAM,wBAAwB,OAAO,SAAS,KAAK;IACnD,MAAM,cAAc,IAAI,QAAQ;IAChC,MAAM,OAAO,OAAO,MAAM;IAE1B,IAAI,aAAa,MAAK,gBAAe,YAAY,QAAA,kBAA4B,CAAC,GAC5E;IAGF,IAAI,CAAC,uBACH;IAGF,OAAO,GAAG,OAAO,aAAa,KAAK,OAAO,CAAC;GAC7C;GACA,OAAO;IACL,OAAO,GAAG,UAAU;KAClB,MAAM,WAAW,MAAM,GAAG,IAAI;KAE9B,OAAO,CAAC,eAAe;MAAE,MAAM;MAAU,OAAO;KAAc,CAAC;IACjE;IACA,QAAQ,IAAI,UAAU;KACpB,IAAI,CAAC,GAAG,YACN,OAAO;KAKT,IAAI,GAAG,QAAQ,uBAAuB,GACpC,OAAO;KAGT,MAAM,WAAW,GAAG,IAAI;KAExB,OAAO,CAAC,eAAe;MAAE,MAAM;MAAU,OAAO;KAAc,CAAC;IACjE;GACF;EACF,CAAC,CACH;CACF;AACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Extension } from
|
|
2
|
-
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
//#region src/trailing-node/trailing-node.d.ts
|
|
3
3
|
declare const skipTrailingNodeMeta = "skipTrailingNode";
|
|
4
4
|
/**
|
|
5
5
|
* Extension based on:
|
|
@@ -7,23 +7,24 @@ declare const skipTrailingNodeMeta = "skipTrailingNode";
|
|
|
7
7
|
* - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
|
|
8
8
|
*/
|
|
9
9
|
interface TrailingNodeOptions {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The node type that should be inserted at the end of the document.
|
|
12
|
+
* @note the node will always be added to the `notAfter` lists to
|
|
13
|
+
* prevent an infinite loop.
|
|
14
|
+
* @default undefined
|
|
15
|
+
*/
|
|
16
|
+
node?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The node types after which the trailing node should not be inserted.
|
|
19
|
+
* @default ['paragraph']
|
|
20
|
+
*/
|
|
21
|
+
notAfter?: string | string[];
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* This extension allows you to add an extra node at the end of the document.
|
|
25
25
|
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
26
26
|
*/
|
|
27
27
|
declare const TrailingNode: Extension<TrailingNodeOptions, any>;
|
|
28
|
-
|
|
29
|
-
export { TrailingNode,
|
|
28
|
+
//#endregion
|
|
29
|
+
export { TrailingNode, TrailingNodeOptions, skipTrailingNodeMeta };
|
|
30
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/trailing-node/trailing-node.ts"],"mappings":";;cAIa;;;;;;UAkBI;;;;;;;EAOf;;;;;EAKA;;;;;;cAOW,cAAY,UAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Extension } from
|
|
2
|
-
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
//#region src/trailing-node/trailing-node.d.ts
|
|
3
3
|
declare const skipTrailingNodeMeta = "skipTrailingNode";
|
|
4
4
|
/**
|
|
5
5
|
* Extension based on:
|
|
@@ -7,23 +7,24 @@ declare const skipTrailingNodeMeta = "skipTrailingNode";
|
|
|
7
7
|
* - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
|
|
8
8
|
*/
|
|
9
9
|
interface TrailingNodeOptions {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The node type that should be inserted at the end of the document.
|
|
12
|
+
* @note the node will always be added to the `notAfter` lists to
|
|
13
|
+
* prevent an infinite loop.
|
|
14
|
+
* @default undefined
|
|
15
|
+
*/
|
|
16
|
+
node?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The node types after which the trailing node should not be inserted.
|
|
19
|
+
* @default ['paragraph']
|
|
20
|
+
*/
|
|
21
|
+
notAfter?: string | string[];
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* This extension allows you to add an extra node at the end of the document.
|
|
25
25
|
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
26
26
|
*/
|
|
27
27
|
declare const TrailingNode: Extension<TrailingNodeOptions, any>;
|
|
28
|
-
|
|
29
|
-
export { TrailingNode,
|
|
28
|
+
//#endregion
|
|
29
|
+
export { TrailingNode, TrailingNodeOptions, skipTrailingNodeMeta };
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/trailing-node/trailing-node.ts"],"mappings":";;cAIa;;;;;;UAkBI;;;;;;;EAOf;;;;;EAKA;;;;;;cAOW,cAAY,UAAA"}
|
|
@@ -1,64 +1,60 @@
|
|
|
1
|
-
// src/trailing-node/trailing-node.ts
|
|
2
1
|
import { Extension } from "@tiptap/core";
|
|
3
2
|
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}) {
|
|
9
|
-
return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
|
|
3
|
+
//#region src/trailing-node/trailing-node.ts
|
|
4
|
+
const skipTrailingNodeMeta = "skipTrailingNode";
|
|
5
|
+
function nodeEqualsType({ types, node }) {
|
|
6
|
+
return node && Array.isArray(types) && types.includes(node.type) || (node === null || node === void 0 ? void 0 : node.type) === types;
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
8
|
+
/**
|
|
9
|
+
* This extension allows you to add an extra node at the end of the document.
|
|
10
|
+
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
11
|
+
*/
|
|
12
|
+
const TrailingNode = Extension.create({
|
|
13
|
+
name: "trailingNode",
|
|
14
|
+
addOptions() {
|
|
15
|
+
return {
|
|
16
|
+
node: void 0,
|
|
17
|
+
notAfter: []
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
addProseMirrorPlugins() {
|
|
21
|
+
var _this$editor$schema$t;
|
|
22
|
+
const plugin = new PluginKey(this.name);
|
|
23
|
+
const defaultNode = this.options.node || ((_this$editor$schema$t = this.editor.schema.topNodeType.contentMatch.defaultType) === null || _this$editor$schema$t === void 0 ? void 0 : _this$editor$schema$t.name) || "paragraph";
|
|
24
|
+
const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(defaultNode).includes(node.name));
|
|
25
|
+
return [new Plugin({
|
|
26
|
+
key: plugin,
|
|
27
|
+
appendTransaction: (transactions, __, state) => {
|
|
28
|
+
const { doc, tr, schema } = state;
|
|
29
|
+
const shouldInsertNodeAtEnd = plugin.getState(state);
|
|
30
|
+
const endPosition = doc.content.size;
|
|
31
|
+
const type = schema.nodes[defaultNode];
|
|
32
|
+
if (transactions.some((transaction) => transaction.getMeta("skipTrailingNode"))) return;
|
|
33
|
+
if (!shouldInsertNodeAtEnd) return;
|
|
34
|
+
return tr.insert(endPosition, type.create());
|
|
35
|
+
},
|
|
36
|
+
state: {
|
|
37
|
+
init: (_, state) => {
|
|
38
|
+
const lastNode = state.tr.doc.lastChild;
|
|
39
|
+
return !nodeEqualsType({
|
|
40
|
+
node: lastNode,
|
|
41
|
+
types: disabledNodes
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
apply: (tr, value) => {
|
|
45
|
+
if (!tr.docChanged) return value;
|
|
46
|
+
if (tr.getMeta("__uniqueIDTransaction")) return value;
|
|
47
|
+
const lastNode = tr.doc.lastChild;
|
|
48
|
+
return !nodeEqualsType({
|
|
49
|
+
node: lastNode,
|
|
50
|
+
types: disabledNodes
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})];
|
|
55
|
+
}
|
|
59
56
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { TrailingNode, skipTrailingNodeMeta };
|
|
59
|
+
|
|
64
60
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/trailing-node/trailing-node.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/trailing-node/trailing-node.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";;;AAIA,MAAa,uBAAuB;AAEpC,SAAS,eAAe,EACtB,OACA,QAIC;CACD,OAAQ,QAAQ,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,IAAI,MAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAM,KAAM,UAAS;AACvF;;;;;AA2BA,MAAa,eAAe,UAAU,OAA4B;CAChE,MAAM;CAEN,aAAa;EACX,OAAO;GACL,MAAM,KAAA;GACN,UAAU,CAAC;EACb;CACF;CAEA,wBAAwB;;EACtB,MAAM,SAAS,IAAI,UAAU,KAAK,IAAI;EACtC,MAAM,cACJ,KAAK,QAAQ,UAAA,wBACb,KAAK,OAAO,OAAO,YAAY,aAAa,iBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAa,SACzD;EAEF,MAAM,gBAAgB,OAAO,QAAQ,KAAK,OAAO,OAAO,KAAK,CAAC,CAC3D,KAAK,GAAG,WAAW,KAAK,CAAC,CACzB,QAAO,UAAS,KAAK,QAAQ,YAAY,CAAC,EAAA,CAAG,OAAO,WAAW,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC;EAEvF,OAAO,CACL,IAAI,OAAO;GACT,KAAK;GACL,oBAAoB,cAAc,IAAI,UAAU;IAC9C,MAAM,EAAE,KAAK,IAAI,WAAW;IAC5B,MAAM,wBAAwB,OAAO,SAAS,KAAK;IACnD,MAAM,cAAc,IAAI,QAAQ;IAChC,MAAM,OAAO,OAAO,MAAM;IAE1B,IAAI,aAAa,MAAK,gBAAe,YAAY,QAAA,kBAA4B,CAAC,GAC5E;IAGF,IAAI,CAAC,uBACH;IAGF,OAAO,GAAG,OAAO,aAAa,KAAK,OAAO,CAAC;GAC7C;GACA,OAAO;IACL,OAAO,GAAG,UAAU;KAClB,MAAM,WAAW,MAAM,GAAG,IAAI;KAE9B,OAAO,CAAC,eAAe;MAAE,MAAM;MAAU,OAAO;KAAc,CAAC;IACjE;IACA,QAAQ,IAAI,UAAU;KACpB,IAAI,CAAC,GAAG,YACN,OAAO;KAKT,IAAI,GAAG,QAAQ,uBAAuB,GACpC,OAAO;KAGT,MAAM,WAAW,GAAG,IAAI;KAExB,OAAO,CAAC,eAAe;MAAE,MAAM;MAAU,OAAO;KAAc,CAAC;IACjE;GACF;EACF,CAAC,CACH;CACF;AACF,CAAC"}
|
package/dist/undo-redo/index.cjs
CHANGED
|
@@ -1,66 +1,48 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _tiptap_core = require("@tiptap/core");
|
|
3
|
+
let _tiptap_pm_history = require("@tiptap/pm/history");
|
|
4
|
+
//#region src/undo-redo/undo-redo.ts
|
|
5
|
+
/**
|
|
6
|
+
* This extension allows you to undo and redo recent changes.
|
|
7
|
+
* @see https://www.tiptap.dev/api/extensions/undo-redo
|
|
8
|
+
*
|
|
9
|
+
* **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove
|
|
10
|
+
* the `undo-redo` extension, as it is not compatible with the `collaboration` extension.
|
|
11
|
+
*
|
|
12
|
+
* `@tiptap/extension-collaboration` uses its own history implementation.
|
|
13
|
+
*/
|
|
14
|
+
const UndoRedo = _tiptap_core.Extension.create({
|
|
15
|
+
name: "undoRedo",
|
|
16
|
+
addOptions() {
|
|
17
|
+
return {
|
|
18
|
+
depth: 100,
|
|
19
|
+
newGroupDelay: 500
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
addCommands() {
|
|
23
|
+
return {
|
|
24
|
+
undo: () => ({ state, dispatch }) => {
|
|
25
|
+
return (0, _tiptap_pm_history.undo)(state, dispatch);
|
|
26
|
+
},
|
|
27
|
+
redo: () => ({ state, dispatch }) => {
|
|
28
|
+
return (0, _tiptap_pm_history.redo)(state, dispatch);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
addProseMirrorPlugins() {
|
|
33
|
+
return [(0, _tiptap_pm_history.history)(this.options)];
|
|
34
|
+
},
|
|
35
|
+
addKeyboardShortcuts() {
|
|
36
|
+
return {
|
|
37
|
+
"Mod-z": () => this.editor.commands.undo(),
|
|
38
|
+
"Shift-Mod-z": () => this.editor.commands.redo(),
|
|
39
|
+
"Mod-y": () => this.editor.commands.redo(),
|
|
40
|
+
"Mod-я": () => this.editor.commands.undo(),
|
|
41
|
+
"Shift-Mod-я": () => this.editor.commands.redo()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
24
44
|
});
|
|
25
|
-
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.UndoRedo = UndoRedo;
|
|
26
47
|
|
|
27
|
-
// src/undo-redo/undo-redo.ts
|
|
28
|
-
var import_core = require("@tiptap/core");
|
|
29
|
-
var import_history = require("@tiptap/pm/history");
|
|
30
|
-
var UndoRedo = import_core.Extension.create({
|
|
31
|
-
name: "undoRedo",
|
|
32
|
-
addOptions() {
|
|
33
|
-
return {
|
|
34
|
-
depth: 100,
|
|
35
|
-
newGroupDelay: 500
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
addCommands() {
|
|
39
|
-
return {
|
|
40
|
-
undo: () => ({ state, dispatch }) => {
|
|
41
|
-
return (0, import_history.undo)(state, dispatch);
|
|
42
|
-
},
|
|
43
|
-
redo: () => ({ state, dispatch }) => {
|
|
44
|
-
return (0, import_history.redo)(state, dispatch);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
addProseMirrorPlugins() {
|
|
49
|
-
return [(0, import_history.history)(this.options)];
|
|
50
|
-
},
|
|
51
|
-
addKeyboardShortcuts() {
|
|
52
|
-
return {
|
|
53
|
-
"Mod-z": () => this.editor.commands.undo(),
|
|
54
|
-
"Shift-Mod-z": () => this.editor.commands.redo(),
|
|
55
|
-
"Mod-y": () => this.editor.commands.redo(),
|
|
56
|
-
// Russian keyboard layouts
|
|
57
|
-
"Mod-\u044F": () => this.editor.commands.undo(),
|
|
58
|
-
"Shift-Mod-\u044F": () => this.editor.commands.redo()
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
-
0 && (module.exports = {
|
|
64
|
-
UndoRedo
|
|
65
|
-
});
|
|
66
48
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Extension","undo","redo","history"],"sources":["../../src/undo-redo/undo-redo.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;AA6CA,MAAa,WAAWA,aAAAA,UAAU,OAAwB;CACxD,MAAM;CAEN,aAAa;EACX,OAAO;GACL,OAAO;GACP,eAAe;EACjB;CACF;CAEA,cAAc;EACZ,OAAO;GACL,aAEG,EAAE,OAAO,eAAe;IACvB,QAAA,GAAOC,mBAAAA,KAAAA,CAAK,OAAO,QAAQ;GAC7B;GACF,aAEG,EAAE,OAAO,eAAe;IACvB,QAAA,GAAOC,mBAAAA,KAAAA,CAAK,OAAO,QAAQ;GAC7B;EACJ;CACF;CAEA,wBAAwB;EACtB,OAAO,EAAA,GAACC,mBAAAA,QAAAA,CAAQ,KAAK,OAAO,CAAC;CAC/B;CAEA,uBAAuB;EACrB,OAAO;GACL,eAAe,KAAK,OAAO,SAAS,KAAK;GACzC,qBAAqB,KAAK,OAAO,SAAS,KAAK;GAC/C,eAAe,KAAK,OAAO,SAAS,KAAK;GAGzC,eAAe,KAAK,OAAO,SAAS,KAAK;GACzC,qBAAqB,KAAK,OAAO,SAAS,KAAK;EACjD;CACF;AACF,CAAC"}
|