@tiptap/suggestion 3.0.0 → 3.0.2-beta.0
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 +268 -233
- package/dist/index.cjs.map +1 -1
- package/dist/{packages/suggestion/src/suggestion.d.ts → index.d.cts} +46 -11
- package/dist/index.d.ts +188 -0
- package/dist/index.js +241 -228
- package/dist/index.js.map +1 -1
- package/package.json +13 -11
- package/src/findSuggestionMatch.ts +10 -7
- package/src/suggestion.ts +65 -29
- package/dist/index.umd.js +0 -246
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +0 -15
- package/dist/packages/suggestion/src/index.d.ts +0 -4
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/suggestion
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/@tiptap/suggestion)
|
|
3
4
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
5
|
[](https://www.npmjs.com/package/@tiptap/suggestion)
|
|
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,244 +1,279 @@
|
|
|
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
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Suggestion: () => Suggestion,
|
|
24
|
+
SuggestionPluginKey: () => SuggestionPluginKey,
|
|
25
|
+
default: () => index_default,
|
|
26
|
+
findSuggestionMatch: () => findSuggestionMatch
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
4
29
|
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
30
|
+
// src/suggestion.ts
|
|
31
|
+
var import_state = require("@tiptap/pm/state");
|
|
32
|
+
var import_view = require("@tiptap/pm/view");
|
|
8
33
|
|
|
34
|
+
// src/findSuggestionMatch.ts
|
|
35
|
+
var import_core = require("@tiptap/core");
|
|
9
36
|
function findSuggestionMatch(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
// JavaScript doesn't have lookbehinds. This hacks a check that first character
|
|
28
|
-
// is a space or the start of the line
|
|
29
|
-
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
|
|
30
|
-
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix);
|
|
31
|
-
if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
// The absolute position of the match in the document
|
|
35
|
-
const from = textFrom + match.index;
|
|
36
|
-
let to = from + match[0].length;
|
|
37
|
-
// Edge case handling; if spaces are allowed and we're directly in between
|
|
38
|
-
// two triggers
|
|
39
|
-
if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
|
|
40
|
-
match[0] += ' ';
|
|
41
|
-
to += 1;
|
|
42
|
-
}
|
|
43
|
-
// If the $position is located within the matched substring, return that range
|
|
44
|
-
if (from < $position.pos && to >= $position.pos) {
|
|
45
|
-
return {
|
|
46
|
-
range: {
|
|
47
|
-
from,
|
|
48
|
-
to,
|
|
49
|
-
},
|
|
50
|
-
query: match[0].slice(char.length),
|
|
51
|
-
text: match[0],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
37
|
+
var _a;
|
|
38
|
+
const { char, allowSpaces: allowSpacesOption, allowToIncludeChar, allowedPrefixes, startOfLine, $position } = config;
|
|
39
|
+
const allowSpaces = allowSpacesOption && !allowToIncludeChar;
|
|
40
|
+
const escapedChar = (0, import_core.escapeForRegEx)(char);
|
|
41
|
+
const suffix = new RegExp(`\\s${escapedChar}$`);
|
|
42
|
+
const prefix = startOfLine ? "^" : "";
|
|
43
|
+
const finalEscapedChar = allowToIncludeChar ? "" : escapedChar;
|
|
44
|
+
const regexp = allowSpaces ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${finalEscapedChar}|$)`, "gm") : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${finalEscapedChar}]*`, "gm");
|
|
45
|
+
const text = ((_a = $position.nodeBefore) == null ? void 0 : _a.isText) && $position.nodeBefore.text;
|
|
46
|
+
if (!text) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const textFrom = $position.pos - text.length;
|
|
50
|
+
const match = Array.from(text.matchAll(regexp)).pop();
|
|
51
|
+
if (!match || match.input === void 0 || match.index === void 0) {
|
|
54
52
|
return null;
|
|
53
|
+
}
|
|
54
|
+
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
|
|
55
|
+
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes == null ? void 0 : allowedPrefixes.join("")}\0]?$`).test(matchPrefix);
|
|
56
|
+
if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const from = textFrom + match.index;
|
|
60
|
+
let to = from + match[0].length;
|
|
61
|
+
if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
|
|
62
|
+
match[0] += " ";
|
|
63
|
+
to += 1;
|
|
64
|
+
}
|
|
65
|
+
if (from < $position.pos && to >= $position.pos) {
|
|
66
|
+
return {
|
|
67
|
+
range: {
|
|
68
|
+
from,
|
|
69
|
+
to
|
|
70
|
+
},
|
|
71
|
+
query: match[0].slice(char.length),
|
|
72
|
+
text: match[0]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
55
76
|
}
|
|
56
77
|
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
: null,
|
|
112
|
-
};
|
|
113
|
-
if (handleStart) {
|
|
114
|
-
(_c = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeStart) === null || _c === void 0 ? void 0 : _c.call(renderer, props);
|
|
115
|
-
}
|
|
116
|
-
if (handleChange) {
|
|
117
|
-
(_d = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeUpdate) === null || _d === void 0 ? void 0 : _d.call(renderer, props);
|
|
118
|
-
}
|
|
119
|
-
if (handleChange || handleStart) {
|
|
120
|
-
props.items = await items({
|
|
121
|
-
editor,
|
|
122
|
-
query: state.query,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (handleExit) {
|
|
126
|
-
(_e = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _e === void 0 ? void 0 : _e.call(renderer, props);
|
|
127
|
-
}
|
|
128
|
-
if (handleChange) {
|
|
129
|
-
(_f = renderer === null || renderer === void 0 ? void 0 : renderer.onUpdate) === null || _f === void 0 ? void 0 : _f.call(renderer, props);
|
|
130
|
-
}
|
|
131
|
-
if (handleStart) {
|
|
132
|
-
(_g = renderer === null || renderer === void 0 ? void 0 : renderer.onStart) === null || _g === void 0 ? void 0 : _g.call(renderer, props);
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
destroy: () => {
|
|
136
|
-
var _a;
|
|
137
|
-
if (!props) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
(_a = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _a === void 0 ? void 0 : _a.call(renderer, props);
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
state: {
|
|
145
|
-
// Initialize the plugin's internal state.
|
|
146
|
-
init() {
|
|
147
|
-
const state = {
|
|
148
|
-
active: false,
|
|
149
|
-
range: {
|
|
150
|
-
from: 0,
|
|
151
|
-
to: 0,
|
|
152
|
-
},
|
|
153
|
-
query: null,
|
|
154
|
-
text: null,
|
|
155
|
-
composing: false,
|
|
156
|
-
};
|
|
157
|
-
return state;
|
|
158
|
-
},
|
|
159
|
-
// Apply changes to the plugin state from a view transaction.
|
|
160
|
-
apply(transaction, prev, _oldState, state) {
|
|
161
|
-
const { isEditable } = editor;
|
|
162
|
-
const { composing } = editor.view;
|
|
163
|
-
const { selection } = transaction;
|
|
164
|
-
const { empty, from } = selection;
|
|
165
|
-
const next = { ...prev };
|
|
166
|
-
next.composing = composing;
|
|
167
|
-
// We can only be suggesting if the view is editable, and:
|
|
168
|
-
// * there is no selection, or
|
|
169
|
-
// * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
|
|
170
|
-
if (isEditable && (empty || editor.view.composing)) {
|
|
171
|
-
// Reset active state if we just left the previous suggestion range
|
|
172
|
-
if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
|
|
173
|
-
next.active = false;
|
|
174
|
-
}
|
|
175
|
-
// Try to match against where our cursor currently is
|
|
176
|
-
const match = findSuggestionMatch$1({
|
|
177
|
-
char,
|
|
178
|
-
allowSpaces,
|
|
179
|
-
allowedPrefixes,
|
|
180
|
-
startOfLine,
|
|
181
|
-
$position: selection.$from,
|
|
182
|
-
});
|
|
183
|
-
const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
|
|
184
|
-
// If we found a match, update the current state to show it
|
|
185
|
-
if (match && allow({
|
|
186
|
-
editor, state, range: match.range, isActive: prev.active,
|
|
187
|
-
})) {
|
|
188
|
-
next.active = true;
|
|
189
|
-
next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
|
|
190
|
-
next.range = match.range;
|
|
191
|
-
next.query = match.query;
|
|
192
|
-
next.text = match.text;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
next.active = false;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
next.active = false;
|
|
200
|
-
}
|
|
201
|
-
// Make sure to empty the range if suggestion is inactive
|
|
202
|
-
if (!next.active) {
|
|
203
|
-
next.decorationId = null;
|
|
204
|
-
next.range = { from: 0, to: 0 };
|
|
205
|
-
next.query = null;
|
|
206
|
-
next.text = null;
|
|
207
|
-
}
|
|
208
|
-
return next;
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
props: {
|
|
212
|
-
// Call the keydown hook if suggestion is active.
|
|
213
|
-
handleKeyDown(view, event) {
|
|
214
|
-
var _a;
|
|
215
|
-
const { active, range } = plugin.getState(view.state);
|
|
216
|
-
if (!active) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
return ((_a = renderer === null || renderer === void 0 ? void 0 : renderer.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(renderer, { view, event, range })) || false;
|
|
220
|
-
},
|
|
221
|
-
// Setup decorator on the currently active suggestion.
|
|
222
|
-
decorations(state) {
|
|
223
|
-
const { active, range, decorationId } = plugin.getState(state);
|
|
224
|
-
if (!active) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
return view.DecorationSet.create(state.doc, [
|
|
228
|
-
view.Decoration.inline(range.from, range.to, {
|
|
229
|
-
nodeName: decorationTag,
|
|
230
|
-
class: decorationClass,
|
|
231
|
-
'data-decoration-id': decorationId,
|
|
232
|
-
}),
|
|
233
|
-
]);
|
|
78
|
+
// src/suggestion.ts
|
|
79
|
+
var SuggestionPluginKey = new import_state.PluginKey("suggestion");
|
|
80
|
+
function Suggestion({
|
|
81
|
+
pluginKey = SuggestionPluginKey,
|
|
82
|
+
editor,
|
|
83
|
+
char = "@",
|
|
84
|
+
allowSpaces = false,
|
|
85
|
+
allowToIncludeChar = false,
|
|
86
|
+
allowedPrefixes = [" "],
|
|
87
|
+
startOfLine = false,
|
|
88
|
+
decorationTag = "span",
|
|
89
|
+
decorationClass = "suggestion",
|
|
90
|
+
decorationContent = "",
|
|
91
|
+
decorationEmptyClass = "is-empty",
|
|
92
|
+
command = () => null,
|
|
93
|
+
items = () => [],
|
|
94
|
+
render = () => ({}),
|
|
95
|
+
allow = () => true,
|
|
96
|
+
findSuggestionMatch: findSuggestionMatch2 = findSuggestionMatch
|
|
97
|
+
}) {
|
|
98
|
+
let props;
|
|
99
|
+
const renderer = render == null ? void 0 : render();
|
|
100
|
+
const plugin = new import_state.Plugin({
|
|
101
|
+
key: pluginKey,
|
|
102
|
+
view() {
|
|
103
|
+
return {
|
|
104
|
+
update: async (view, prevState) => {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
106
|
+
const prev = (_a = this.key) == null ? void 0 : _a.getState(prevState);
|
|
107
|
+
const next = (_b = this.key) == null ? void 0 : _b.getState(view.state);
|
|
108
|
+
const moved = prev.active && next.active && prev.range.from !== next.range.from;
|
|
109
|
+
const started = !prev.active && next.active;
|
|
110
|
+
const stopped = prev.active && !next.active;
|
|
111
|
+
const changed = !started && !stopped && prev.query !== next.query;
|
|
112
|
+
const handleStart = started || moved && changed;
|
|
113
|
+
const handleChange = changed || moved;
|
|
114
|
+
const handleExit = stopped || moved && changed;
|
|
115
|
+
if (!handleStart && !handleChange && !handleExit) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const state = handleExit && !handleStart ? prev : next;
|
|
119
|
+
const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`);
|
|
120
|
+
props = {
|
|
121
|
+
editor,
|
|
122
|
+
range: state.range,
|
|
123
|
+
query: state.query,
|
|
124
|
+
text: state.text,
|
|
125
|
+
items: [],
|
|
126
|
+
command: (commandProps) => {
|
|
127
|
+
return command({
|
|
128
|
+
editor,
|
|
129
|
+
range: state.range,
|
|
130
|
+
props: commandProps
|
|
131
|
+
});
|
|
234
132
|
},
|
|
133
|
+
decorationNode,
|
|
134
|
+
// virtual node for positioning
|
|
135
|
+
// this can be used for building popups without a DOM node
|
|
136
|
+
clientRect: decorationNode ? () => {
|
|
137
|
+
var _a2;
|
|
138
|
+
const { decorationId } = (_a2 = this.key) == null ? void 0 : _a2.getState(editor.state);
|
|
139
|
+
const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`);
|
|
140
|
+
return (currentDecorationNode == null ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
|
|
141
|
+
} : null
|
|
142
|
+
};
|
|
143
|
+
if (handleStart) {
|
|
144
|
+
(_c = renderer == null ? void 0 : renderer.onBeforeStart) == null ? void 0 : _c.call(renderer, props);
|
|
145
|
+
}
|
|
146
|
+
if (handleChange) {
|
|
147
|
+
(_d = renderer == null ? void 0 : renderer.onBeforeUpdate) == null ? void 0 : _d.call(renderer, props);
|
|
148
|
+
}
|
|
149
|
+
if (handleChange || handleStart) {
|
|
150
|
+
props.items = await items({
|
|
151
|
+
editor,
|
|
152
|
+
query: state.query
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (handleExit) {
|
|
156
|
+
(_e = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _e.call(renderer, props);
|
|
157
|
+
}
|
|
158
|
+
if (handleChange) {
|
|
159
|
+
(_f = renderer == null ? void 0 : renderer.onUpdate) == null ? void 0 : _f.call(renderer, props);
|
|
160
|
+
}
|
|
161
|
+
if (handleStart) {
|
|
162
|
+
(_g = renderer == null ? void 0 : renderer.onStart) == null ? void 0 : _g.call(renderer, props);
|
|
163
|
+
}
|
|
235
164
|
},
|
|
236
|
-
|
|
237
|
-
|
|
165
|
+
destroy: () => {
|
|
166
|
+
var _a;
|
|
167
|
+
if (!props) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
(_a = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _a.call(renderer, props);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
state: {
|
|
175
|
+
// Initialize the plugin's internal state.
|
|
176
|
+
init() {
|
|
177
|
+
const state = {
|
|
178
|
+
active: false,
|
|
179
|
+
range: {
|
|
180
|
+
from: 0,
|
|
181
|
+
to: 0
|
|
182
|
+
},
|
|
183
|
+
query: null,
|
|
184
|
+
text: null,
|
|
185
|
+
composing: false
|
|
186
|
+
};
|
|
187
|
+
return state;
|
|
188
|
+
},
|
|
189
|
+
// Apply changes to the plugin state from a view transaction.
|
|
190
|
+
apply(transaction, prev, _oldState, state) {
|
|
191
|
+
const { isEditable } = editor;
|
|
192
|
+
const { composing } = editor.view;
|
|
193
|
+
const { selection } = transaction;
|
|
194
|
+
const { empty, from } = selection;
|
|
195
|
+
const next = { ...prev };
|
|
196
|
+
next.composing = composing;
|
|
197
|
+
if (isEditable && (empty || editor.view.composing)) {
|
|
198
|
+
if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
|
|
199
|
+
next.active = false;
|
|
200
|
+
}
|
|
201
|
+
const match = findSuggestionMatch2({
|
|
202
|
+
char,
|
|
203
|
+
allowSpaces,
|
|
204
|
+
allowToIncludeChar,
|
|
205
|
+
allowedPrefixes,
|
|
206
|
+
startOfLine,
|
|
207
|
+
$position: selection.$from
|
|
208
|
+
});
|
|
209
|
+
const decorationId = `id_${Math.floor(Math.random() * 4294967295)}`;
|
|
210
|
+
if (match && allow({
|
|
211
|
+
editor,
|
|
212
|
+
state,
|
|
213
|
+
range: match.range,
|
|
214
|
+
isActive: prev.active
|
|
215
|
+
})) {
|
|
216
|
+
next.active = true;
|
|
217
|
+
next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
|
|
218
|
+
next.range = match.range;
|
|
219
|
+
next.query = match.query;
|
|
220
|
+
next.text = match.text;
|
|
221
|
+
} else {
|
|
222
|
+
next.active = false;
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
next.active = false;
|
|
226
|
+
}
|
|
227
|
+
if (!next.active) {
|
|
228
|
+
next.decorationId = null;
|
|
229
|
+
next.range = { from: 0, to: 0 };
|
|
230
|
+
next.query = null;
|
|
231
|
+
next.text = null;
|
|
232
|
+
}
|
|
233
|
+
return next;
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
props: {
|
|
237
|
+
// Call the keydown hook if suggestion is active.
|
|
238
|
+
handleKeyDown(view, event) {
|
|
239
|
+
var _a;
|
|
240
|
+
const { active, range } = plugin.getState(view.state);
|
|
241
|
+
if (!active) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
return ((_a = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _a.call(renderer, { view, event, range })) || false;
|
|
245
|
+
},
|
|
246
|
+
// Setup decorator on the currently active suggestion.
|
|
247
|
+
decorations(state) {
|
|
248
|
+
const { active, range, decorationId, query } = plugin.getState(state);
|
|
249
|
+
if (!active) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
const isEmpty = !(query == null ? void 0 : query.length);
|
|
253
|
+
const classNames = [decorationClass];
|
|
254
|
+
if (isEmpty) {
|
|
255
|
+
classNames.push(decorationEmptyClass);
|
|
256
|
+
}
|
|
257
|
+
return import_view.DecorationSet.create(state.doc, [
|
|
258
|
+
import_view.Decoration.inline(range.from, range.to, {
|
|
259
|
+
nodeName: decorationTag,
|
|
260
|
+
class: classNames.join(" "),
|
|
261
|
+
"data-decoration-id": decorationId,
|
|
262
|
+
"data-decoration-content": decorationContent
|
|
263
|
+
})
|
|
264
|
+
]);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
return plugin;
|
|
238
269
|
}
|
|
239
270
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
exports
|
|
244
|
-
|
|
271
|
+
// src/index.ts
|
|
272
|
+
var index_default = Suggestion;
|
|
273
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
274
|
+
0 && (module.exports = {
|
|
275
|
+
Suggestion,
|
|
276
|
+
SuggestionPluginKey,
|
|
277
|
+
findSuggestionMatch
|
|
278
|
+
});
|
|
279
|
+
//# sourceMappingURL=index.cjs.map
|