@tiptap/suggestion 3.0.0-next.0 → 3.0.0-next.2

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.
Files changed (174) hide show
  1. package/dist/index.cjs +271 -233
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/{packages/suggestion/src/suggestion.d.ts → index.d.cts} +33 -10
  4. package/dist/index.d.ts +176 -0
  5. package/dist/index.js +244 -228
  6. package/dist/index.js.map +1 -1
  7. package/package.json +8 -10
  8. package/src/findSuggestionMatch.ts +7 -3
  9. package/src/suggestion.ts +11 -3
  10. package/dist/index.umd.js +0 -246
  11. package/dist/index.umd.js.map +0 -1
  12. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  13. package/dist/packages/core/src/Editor.d.ts +0 -159
  14. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  15. package/dist/packages/core/src/Extension.d.ts +0 -343
  16. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  17. package/dist/packages/core/src/InputRule.d.ts +0 -42
  18. package/dist/packages/core/src/Mark.d.ts +0 -451
  19. package/dist/packages/core/src/Node.d.ts +0 -611
  20. package/dist/packages/core/src/NodePos.d.ts +0 -44
  21. package/dist/packages/core/src/NodeView.d.ts +0 -31
  22. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  23. package/dist/packages/core/src/Tracker.d.ts +0 -11
  24. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  25. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  26. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  27. package/dist/packages/core/src/commands/command.d.ts +0 -18
  28. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  29. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  30. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  31. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  32. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  33. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  34. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  35. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  36. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  37. package/dist/packages/core/src/commands/first.d.ts +0 -14
  38. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  39. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  40. package/dist/packages/core/src/commands/index.d.ts +0 -55
  41. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  42. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  43. package/dist/packages/core/src/commands/join.d.ts +0 -41
  44. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  45. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  46. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  47. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  48. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  49. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  50. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  51. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  52. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  53. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  54. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  55. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  56. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  59. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  60. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  61. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  62. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  63. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  64. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  65. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  66. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  67. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  68. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  69. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  70. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  71. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  72. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  73. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  74. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  75. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  76. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  77. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  78. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  79. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  80. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  81. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  82. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  83. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  84. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  85. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  86. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  87. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  88. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  89. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  90. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  91. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  92. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  93. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  94. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  95. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  96. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  97. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  98. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  99. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  100. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  101. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  102. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  103. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  104. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  105. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  106. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  107. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  108. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  109. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  110. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  111. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  112. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  113. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  114. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  115. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  116. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  117. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  118. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  119. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  120. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  121. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  122. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  123. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  124. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  125. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  126. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  129. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  130. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  131. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
  132. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  133. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  134. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  136. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  137. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  138. package/dist/packages/core/src/index.d.ts +0 -24
  139. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  140. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  141. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  142. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  143. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  144. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  145. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  146. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  147. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  148. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  149. package/dist/packages/core/src/style.d.ts +0 -1
  150. package/dist/packages/core/src/types.d.ts +0 -253
  151. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  152. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  153. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  154. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  156. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  157. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  158. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  159. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  161. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  172. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  173. package/dist/packages/suggestion/src/findSuggestionMatch.d.ts +0 -15
  174. package/dist/packages/suggestion/src/index.d.ts +0 -4
@@ -4,6 +4,7 @@ import { ResolvedPos } from '@tiptap/pm/model'
4
4
  export interface Trigger {
5
5
  char: string
6
6
  allowSpaces: boolean
7
+ allowToIncludeChar: boolean
7
8
  allowedPrefixes: string[] | null
8
9
  startOfLine: boolean
9
10
  $position: ResolvedPos
@@ -17,15 +18,18 @@ export type SuggestionMatch = {
17
18
 
18
19
  export function findSuggestionMatch(config: Trigger): SuggestionMatch {
19
20
  const {
20
- char, allowSpaces, allowedPrefixes, startOfLine, $position,
21
+ char, allowSpaces: allowSpacesOption, allowToIncludeChar, allowedPrefixes, startOfLine, $position,
21
22
  } = config
22
23
 
24
+ const allowSpaces = allowSpacesOption && !allowToIncludeChar
25
+
23
26
  const escapedChar = escapeForRegEx(char)
24
27
  const suffix = new RegExp(`\\s${escapedChar}$`)
25
28
  const prefix = startOfLine ? '^' : ''
29
+ const finalEscapedChar = allowToIncludeChar ? '' : escapedChar
26
30
  const regexp = allowSpaces
27
- ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
28
- : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm')
31
+ ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${finalEscapedChar}|$)`, 'gm')
32
+ : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${finalEscapedChar}]*`, 'gm')
29
33
 
30
34
  const text = $position.nodeBefore?.isText && $position.nodeBefore.text
31
35
 
package/src/suggestion.ts CHANGED
@@ -26,12 +26,18 @@ export interface SuggestionOptions<I = any, TSelected = any> {
26
26
  char?: string
27
27
 
28
28
  /**
29
- * Allow spaces in the suggestion query.
29
+ * Allow spaces in the suggestion query. Not compatible with `allowToIncludeChar`. Will be disabled if `allowToIncludeChar` is set to `true`.
30
30
  * @default false
31
31
  * @example true
32
32
  */
33
33
  allowSpaces?: boolean
34
34
 
35
+ /**
36
+ * Allow the character to be included in the suggestion query. Not compatible with `allowSpaces`.
37
+ * @default false
38
+ */
39
+ allowToIncludeChar?: boolean
40
+
35
41
  /**
36
42
  * Allow prefixes in the suggestion query.
37
43
  * @default [' ']
@@ -167,6 +173,7 @@ export function Suggestion<I = any, TSelected = any>({
167
173
  editor,
168
174
  char = '@',
169
175
  allowSpaces = false,
176
+ allowToIncludeChar = false,
170
177
  allowedPrefixes = [' '],
171
178
  startOfLine = false,
172
179
  decorationTag = 'span',
@@ -195,9 +202,9 @@ export function Suggestion<I = any, TSelected = any>({
195
202
  const stopped = prev.active && !next.active
196
203
  const changed = !started && !stopped && prev.query !== next.query
197
204
 
198
- const handleStart = started
205
+ const handleStart = started || (moved && changed)
199
206
  const handleChange = changed || moved
200
- const handleExit = stopped
207
+ const handleExit = stopped || (moved && changed)
201
208
 
202
209
  // Cancel when suggestion isn't active
203
210
  if (!handleStart && !handleChange && !handleExit) {
@@ -323,6 +330,7 @@ export function Suggestion<I = any, TSelected = any>({
323
330
  const match = findSuggestionMatch({
324
331
  char,
325
332
  allowSpaces,
333
+ allowToIncludeChar,
326
334
  allowedPrefixes,
327
335
  startOfLine,
328
336
  $position: selection.$from,
package/dist/index.umd.js DELETED
@@ -1,246 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/pm/state'), require('@tiptap/pm/view'), require('@tiptap/core')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/pm/state', '@tiptap/pm/view', '@tiptap/core'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/suggestion"] = {}, global.state, global.view, global.core));
5
- })(this, (function (exports, state, view, core) { 'use strict';
6
-
7
- function findSuggestionMatch(config) {
8
- var _a;
9
- const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config;
10
- const escapedChar = core.escapeForRegEx(char);
11
- const suffix = new RegExp(`\\s${escapedChar}$`);
12
- const prefix = startOfLine ? '^' : '';
13
- const regexp = allowSpaces
14
- ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
15
- : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm');
16
- const text = ((_a = $position.nodeBefore) === null || _a === void 0 ? void 0 : _a.isText) && $position.nodeBefore.text;
17
- if (!text) {
18
- return null;
19
- }
20
- const textFrom = $position.pos - text.length;
21
- const match = Array.from(text.matchAll(regexp)).pop();
22
- if (!match || match.input === undefined || match.index === undefined) {
23
- return null;
24
- }
25
- // JavaScript doesn't have lookbehinds. This hacks a check that first character
26
- // is a space or the start of the line
27
- const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index);
28
- const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix);
29
- if (allowedPrefixes !== null && !matchPrefixIsAllowed) {
30
- return null;
31
- }
32
- // The absolute position of the match in the document
33
- const from = textFrom + match.index;
34
- let to = from + match[0].length;
35
- // Edge case handling; if spaces are allowed and we're directly in between
36
- // two triggers
37
- if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {
38
- match[0] += ' ';
39
- to += 1;
40
- }
41
- // If the $position is located within the matched substring, return that range
42
- if (from < $position.pos && to >= $position.pos) {
43
- return {
44
- range: {
45
- from,
46
- to,
47
- },
48
- query: match[0].slice(char.length),
49
- text: match[0],
50
- };
51
- }
52
- return null;
53
- }
54
-
55
- const SuggestionPluginKey = new state.PluginKey('suggestion');
56
- /**
57
- * This utility allows you to create suggestions.
58
- * @see https://tiptap.dev/api/utilities/suggestion
59
- */
60
- function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, findSuggestionMatch: findSuggestionMatch$1 = findSuggestionMatch, }) {
61
- let props;
62
- const renderer = render === null || render === void 0 ? void 0 : render();
63
- const plugin = new state.Plugin({
64
- key: pluginKey,
65
- view() {
66
- return {
67
- update: async (view, prevState) => {
68
- var _a, _b, _c, _d, _e, _f, _g;
69
- const prev = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(prevState);
70
- const next = (_b = this.key) === null || _b === void 0 ? void 0 : _b.getState(view.state);
71
- // See how the state changed
72
- const moved = prev.active && next.active && prev.range.from !== next.range.from;
73
- const started = !prev.active && next.active;
74
- const stopped = prev.active && !next.active;
75
- const changed = !started && !stopped && prev.query !== next.query;
76
- const handleStart = started;
77
- const handleChange = changed || moved;
78
- const handleExit = stopped;
79
- // Cancel when suggestion isn't active
80
- if (!handleStart && !handleChange && !handleExit) {
81
- return;
82
- }
83
- const state = handleExit && !handleStart ? prev : next;
84
- const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`);
85
- props = {
86
- editor,
87
- range: state.range,
88
- query: state.query,
89
- text: state.text,
90
- items: [],
91
- command: commandProps => {
92
- return command({
93
- editor,
94
- range: state.range,
95
- props: commandProps,
96
- });
97
- },
98
- decorationNode,
99
- // virtual node for positioning
100
- // this can be used for building popups without a DOM node
101
- clientRect: decorationNode
102
- ? () => {
103
- var _a;
104
- // because of `items` can be asynchrounous we’ll search for the current decoration node
105
- const { decorationId } = (_a = this.key) === null || _a === void 0 ? void 0 : _a.getState(editor.state); // eslint-disable-line
106
- const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`);
107
- return (currentDecorationNode === null || currentDecorationNode === void 0 ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
108
- }
109
- : null,
110
- };
111
- if (handleStart) {
112
- (_c = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeStart) === null || _c === void 0 ? void 0 : _c.call(renderer, props);
113
- }
114
- if (handleChange) {
115
- (_d = renderer === null || renderer === void 0 ? void 0 : renderer.onBeforeUpdate) === null || _d === void 0 ? void 0 : _d.call(renderer, props);
116
- }
117
- if (handleChange || handleStart) {
118
- props.items = await items({
119
- editor,
120
- query: state.query,
121
- });
122
- }
123
- if (handleExit) {
124
- (_e = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _e === void 0 ? void 0 : _e.call(renderer, props);
125
- }
126
- if (handleChange) {
127
- (_f = renderer === null || renderer === void 0 ? void 0 : renderer.onUpdate) === null || _f === void 0 ? void 0 : _f.call(renderer, props);
128
- }
129
- if (handleStart) {
130
- (_g = renderer === null || renderer === void 0 ? void 0 : renderer.onStart) === null || _g === void 0 ? void 0 : _g.call(renderer, props);
131
- }
132
- },
133
- destroy: () => {
134
- var _a;
135
- if (!props) {
136
- return;
137
- }
138
- (_a = renderer === null || renderer === void 0 ? void 0 : renderer.onExit) === null || _a === void 0 ? void 0 : _a.call(renderer, props);
139
- },
140
- };
141
- },
142
- state: {
143
- // Initialize the plugin's internal state.
144
- init() {
145
- const state = {
146
- active: false,
147
- range: {
148
- from: 0,
149
- to: 0,
150
- },
151
- query: null,
152
- text: null,
153
- composing: false,
154
- };
155
- return state;
156
- },
157
- // Apply changes to the plugin state from a view transaction.
158
- apply(transaction, prev, _oldState, state) {
159
- const { isEditable } = editor;
160
- const { composing } = editor.view;
161
- const { selection } = transaction;
162
- const { empty, from } = selection;
163
- const next = { ...prev };
164
- next.composing = composing;
165
- // We can only be suggesting if the view is editable, and:
166
- // * there is no selection, or
167
- // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
168
- if (isEditable && (empty || editor.view.composing)) {
169
- // Reset active state if we just left the previous suggestion range
170
- if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
171
- next.active = false;
172
- }
173
- // Try to match against where our cursor currently is
174
- const match = findSuggestionMatch$1({
175
- char,
176
- allowSpaces,
177
- allowedPrefixes,
178
- startOfLine,
179
- $position: selection.$from,
180
- });
181
- const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
182
- // If we found a match, update the current state to show it
183
- if (match && allow({
184
- editor, state, range: match.range, isActive: prev.active,
185
- })) {
186
- next.active = true;
187
- next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
188
- next.range = match.range;
189
- next.query = match.query;
190
- next.text = match.text;
191
- }
192
- else {
193
- next.active = false;
194
- }
195
- }
196
- else {
197
- next.active = false;
198
- }
199
- // Make sure to empty the range if suggestion is inactive
200
- if (!next.active) {
201
- next.decorationId = null;
202
- next.range = { from: 0, to: 0 };
203
- next.query = null;
204
- next.text = null;
205
- }
206
- return next;
207
- },
208
- },
209
- props: {
210
- // Call the keydown hook if suggestion is active.
211
- handleKeyDown(view, event) {
212
- var _a;
213
- const { active, range } = plugin.getState(view.state);
214
- if (!active) {
215
- return false;
216
- }
217
- return ((_a = renderer === null || renderer === void 0 ? void 0 : renderer.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(renderer, { view, event, range })) || false;
218
- },
219
- // Setup decorator on the currently active suggestion.
220
- decorations(state) {
221
- const { active, range, decorationId } = plugin.getState(state);
222
- if (!active) {
223
- return null;
224
- }
225
- return view.DecorationSet.create(state.doc, [
226
- view.Decoration.inline(range.from, range.to, {
227
- nodeName: decorationTag,
228
- class: decorationClass,
229
- 'data-decoration-id': decorationId,
230
- }),
231
- ]);
232
- },
233
- },
234
- });
235
- return plugin;
236
- }
237
-
238
- exports.Suggestion = Suggestion;
239
- exports.SuggestionPluginKey = SuggestionPluginKey;
240
- exports.default = Suggestion;
241
- exports.findSuggestionMatch = findSuggestionMatch;
242
-
243
- Object.defineProperty(exports, '__esModule', { value: true });
244
-
245
- }));
246
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/findSuggestionMatch.ts","../src/suggestion.ts"],"sourcesContent":["import { escapeForRegEx, Range } from '@tiptap/core'\nimport { ResolvedPos } from '@tiptap/pm/model'\n\nexport interface Trigger {\n char: string\n allowSpaces: boolean\n allowedPrefixes: string[] | null\n startOfLine: boolean\n $position: ResolvedPos\n}\n\nexport type SuggestionMatch = {\n range: Range\n query: string\n text: string\n} | null\n\nexport function findSuggestionMatch(config: Trigger): SuggestionMatch {\n const {\n char, allowSpaces, allowedPrefixes, startOfLine, $position,\n } = config\n\n const escapedChar = escapeForRegEx(char)\n const suffix = new RegExp(`\\\\s${escapedChar}$`)\n const prefix = startOfLine ? '^' : ''\n const regexp = allowSpaces\n ? new RegExp(`${prefix}${escapedChar}.*?(?=\\\\s${escapedChar}|$)`, 'gm')\n : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\\\s${escapedChar}]*`, 'gm')\n\n const text = $position.nodeBefore?.isText && $position.nodeBefore.text\n\n if (!text) {\n return null\n }\n\n const textFrom = $position.pos - text.length\n const match = Array.from(text.matchAll(regexp)).pop()\n\n if (!match || match.input === undefined || match.index === undefined) {\n return null\n }\n\n // JavaScript doesn't have lookbehinds. This hacks a check that first character\n // is a space or the start of the line\n const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)\n const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes?.join('')}\\0]?$`).test(matchPrefix)\n\n if (allowedPrefixes !== null && !matchPrefixIsAllowed) {\n return null\n }\n\n // The absolute position of the match in the document\n const from = textFrom + match.index\n let to = from + match[0].length\n\n // Edge case handling; if spaces are allowed and we're directly in between\n // two triggers\n if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) {\n match[0] += ' '\n to += 1\n }\n\n // If the $position is located within the matched substring, return that range\n if (from < $position.pos && to >= $position.pos) {\n return {\n range: {\n from,\n to,\n },\n query: match[0].slice(char.length),\n text: match[0],\n }\n }\n\n return null\n}\n","import { Editor, Range } from '@tiptap/core'\nimport { EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet, EditorView } from '@tiptap/pm/view'\n\nimport { findSuggestionMatch as defaultFindSuggestionMatch } from './findSuggestionMatch.js'\n\nexport interface SuggestionOptions<I = any, TSelected = any> {\n /**\n * The plugin key for the suggestion plugin.\n * @default 'suggestion'\n * @example 'mention'\n */\n pluginKey?: PluginKey\n\n /**\n * The editor instance.\n * @default null\n */\n editor: Editor\n\n /**\n * The character that triggers the suggestion.\n * @default '@'\n * @example '#'\n */\n char?: string\n\n /**\n * Allow spaces in the suggestion query.\n * @default false\n * @example true\n */\n allowSpaces?: boolean\n\n /**\n * Allow prefixes in the suggestion query.\n * @default [' ']\n * @example [' ', '@']\n */\n allowedPrefixes?: string[] | null\n\n /**\n * Only match suggestions at the start of the line.\n * @default false\n * @example true\n */\n startOfLine?: boolean\n\n /**\n * The tag name of the decoration node.\n * @default 'span'\n * @example 'div'\n */\n decorationTag?: string\n\n /**\n * The class name of the decoration node.\n * @default 'suggestion'\n * @example 'mention'\n */\n decorationClass?: string\n\n /**\n * A function that is called when a suggestion is selected.\n * @param props The props object.\n * @param props.editor The editor instance.\n * @param props.range The range of the suggestion.\n * @param props.props The props of the selected suggestion.\n * @returns void\n * @example ({ editor, range, props }) => { props.command(props.props) }\n */\n command?: (props: { editor: Editor; range: Range; props: TSelected }) => void\n\n /**\n * A function that returns the suggestion items in form of an array.\n * @param props The props object.\n * @param props.editor The editor instance.\n * @param props.query The current suggestion query.\n * @returns An array of suggestion items.\n * @example ({ editor, query }) => [{ id: 1, label: 'John Doe' }]\n */\n items?: (props: { query: string; editor: Editor }) => I[] | Promise<I[]>\n\n /**\n * The render function for the suggestion.\n * @returns An object with render functions.\n */\n render?: () => {\n onBeforeStart?: (props: SuggestionProps<I, TSelected>) => void;\n onStart?: (props: SuggestionProps<I, TSelected>) => void;\n onBeforeUpdate?: (props: SuggestionProps<I, TSelected>) => void;\n onUpdate?: (props: SuggestionProps<I, TSelected>) => void;\n onExit?: (props: SuggestionProps<I, TSelected>) => void;\n onKeyDown?: (props: SuggestionKeyDownProps) => boolean;\n }\n\n /**\n * A function that returns a boolean to indicate if the suggestion should be active.\n * @param props The props object.\n * @returns {boolean}\n */\n allow?: (props: { editor: Editor; state: EditorState; range: Range, isActive?: boolean }) => boolean\n findSuggestionMatch?: typeof defaultFindSuggestionMatch\n}\n\nexport interface SuggestionProps<I = any, TSelected = any> {\n /**\n * The editor instance.\n */\n editor: Editor\n\n /**\n * The range of the suggestion.\n */\n range: Range\n\n /**\n * The current suggestion query.\n */\n query: string\n\n /**\n * The current suggestion text.\n */\n text: string\n\n /**\n * The suggestion items array.\n */\n items: I[]\n\n /**\n * A function that is called when a suggestion is selected.\n * @param props The props object.\n * @returns void\n */\n command: (props: TSelected) => void\n\n /**\n * The decoration node HTML element\n * @default null\n */\n decorationNode: Element | null\n\n /**\n * The function that returns the client rect\n * @default null\n * @example () => new DOMRect(0, 0, 0, 0)\n */\n clientRect?: (() => DOMRect | null) | null\n}\n\nexport interface SuggestionKeyDownProps {\n view: EditorView\n event: KeyboardEvent\n range: Range\n}\n\nexport const SuggestionPluginKey = new PluginKey('suggestion')\n\n/**\n * This utility allows you to create suggestions.\n * @see https://tiptap.dev/api/utilities/suggestion\n */\nexport function Suggestion<I = any, TSelected = any>({\n pluginKey = SuggestionPluginKey,\n editor,\n char = '@',\n allowSpaces = false,\n allowedPrefixes = [' '],\n startOfLine = false,\n decorationTag = 'span',\n decorationClass = 'suggestion',\n command = () => null,\n items = () => [],\n render = () => ({}),\n allow = () => true,\n findSuggestionMatch = defaultFindSuggestionMatch,\n}: SuggestionOptions<I, TSelected>) {\n let props: SuggestionProps<I, TSelected> | undefined\n const renderer = render?.()\n\n const plugin: Plugin<any> = new Plugin({\n key: pluginKey,\n\n view() {\n return {\n update: async (view, prevState) => {\n const prev = this.key?.getState(prevState)\n const next = this.key?.getState(view.state)\n\n // See how the state changed\n const moved = prev.active && next.active && prev.range.from !== next.range.from\n const started = !prev.active && next.active\n const stopped = prev.active && !next.active\n const changed = !started && !stopped && prev.query !== next.query\n\n const handleStart = started\n const handleChange = changed || moved\n const handleExit = stopped\n\n // Cancel when suggestion isn't active\n if (!handleStart && !handleChange && !handleExit) {\n return\n }\n\n const state = handleExit && !handleStart ? prev : next\n const decorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${state.decorationId}\"]`,\n )\n\n props = {\n editor,\n range: state.range,\n query: state.query,\n text: state.text,\n items: [],\n command: commandProps => {\n return command({\n editor,\n range: state.range,\n props: commandProps,\n })\n },\n decorationNode,\n // virtual node for positioning\n // this can be used for building popups without a DOM node\n clientRect: decorationNode\n ? () => {\n // because of `items` can be asynchrounous we’ll search for the current decoration node\n const { decorationId } = this.key?.getState(editor.state) // eslint-disable-line\n const currentDecorationNode = view.dom.querySelector(\n `[data-decoration-id=\"${decorationId}\"]`,\n )\n\n return currentDecorationNode?.getBoundingClientRect() || null\n }\n : null,\n }\n\n if (handleStart) {\n renderer?.onBeforeStart?.(props)\n }\n\n if (handleChange) {\n renderer?.onBeforeUpdate?.(props)\n }\n\n if (handleChange || handleStart) {\n props.items = await items({\n editor,\n query: state.query,\n })\n }\n\n if (handleExit) {\n renderer?.onExit?.(props)\n }\n\n if (handleChange) {\n renderer?.onUpdate?.(props)\n }\n\n if (handleStart) {\n renderer?.onStart?.(props)\n }\n },\n\n destroy: () => {\n if (!props) {\n return\n }\n\n renderer?.onExit?.(props)\n },\n }\n },\n\n state: {\n // Initialize the plugin's internal state.\n init() {\n const state: {\n active: boolean\n range: Range\n query: null | string\n text: null | string\n composing: boolean\n decorationId?: string | null\n } = {\n active: false,\n range: {\n from: 0,\n to: 0,\n },\n query: null,\n text: null,\n composing: false,\n }\n\n return state\n },\n\n // Apply changes to the plugin state from a view transaction.\n apply(transaction, prev, _oldState, state) {\n const { isEditable } = editor\n const { composing } = editor.view\n const { selection } = transaction\n const { empty, from } = selection\n const next = { ...prev }\n\n next.composing = composing\n\n // We can only be suggesting if the view is editable, and:\n // * there is no selection, or\n // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)\n if (isEditable && (empty || editor.view.composing)) {\n // Reset active state if we just left the previous suggestion range\n if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {\n next.active = false\n }\n\n // Try to match against where our cursor currently is\n const match = findSuggestionMatch({\n char,\n allowSpaces,\n allowedPrefixes,\n startOfLine,\n $position: selection.$from,\n })\n const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`\n\n // If we found a match, update the current state to show it\n if (match && allow({\n editor, state, range: match.range, isActive: prev.active,\n })) {\n next.active = true\n next.decorationId = prev.decorationId ? prev.decorationId : decorationId\n next.range = match.range\n next.query = match.query\n next.text = match.text\n } else {\n next.active = false\n }\n } else {\n next.active = false\n }\n\n // Make sure to empty the range if suggestion is inactive\n if (!next.active) {\n next.decorationId = null\n next.range = { from: 0, to: 0 }\n next.query = null\n next.text = null\n }\n\n return next\n },\n },\n\n props: {\n // Call the keydown hook if suggestion is active.\n handleKeyDown(view, event) {\n const { active, range } = plugin.getState(view.state)\n\n if (!active) {\n return false\n }\n\n return renderer?.onKeyDown?.({ view, event, range }) || false\n },\n\n // Setup decorator on the currently active suggestion.\n decorations(state) {\n const { active, range, decorationId } = plugin.getState(state)\n\n if (!active) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(range.from, range.to, {\n nodeName: decorationTag,\n class: decorationClass,\n 'data-decoration-id': decorationId,\n }),\n ])\n },\n },\n })\n\n return plugin\n}\n"],"names":["escapeForRegEx","PluginKey","findSuggestionMatch","defaultFindSuggestionMatch","Plugin","DecorationSet","Decoration"],"mappings":";;;;;;EAiBM,SAAU,mBAAmB,CAAC,MAAe,EAAA;;EACjD,IAAA,MAAM,EACJ,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,GAC3D,GAAG,MAAM,CAAA;EAEV,IAAA,MAAM,WAAW,GAAGA,mBAAc,CAAC,IAAI,CAAC,CAAA;MACxC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAM,GAAA,EAAA,WAAW,CAAG,CAAA,CAAA,CAAC,CAAA;MAC/C,MAAM,MAAM,GAAG,WAAW,GAAG,GAAG,GAAG,EAAE,CAAA;MACrC,MAAM,MAAM,GAAG,WAAW;EACxB,UAAE,IAAI,MAAM,CAAC,CAAG,EAAA,MAAM,CAAG,EAAA,WAAW,CAAY,SAAA,EAAA,WAAW,CAAK,GAAA,CAAA,EAAE,IAAI,CAAC;EACvE,UAAE,IAAI,MAAM,CAAC,GAAG,MAAM,CAAA,MAAA,EAAS,WAAW,CA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AAE;sBACrCC,eAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;EACtC,wBAAA,QAAQ,EAAE,aAAa;EACvB,wBAAA,KAAK,EAAE,eAAe;EACtB,wBAAA,oBAAoB,EAAE,YAAY;uBACnC,CAAC;EACH,iBAAA,CAAC,CAAA;eACH;EACF,SAAA;EACF,KAAA,CAAC,CAAA;EAEF,IAAA,OAAO,MAAM,CAAA;EACf;;;;;;;;;;;;;"}
@@ -1,20 +0,0 @@
1
- import { EditorState, Transaction } from '@tiptap/pm/state';
2
- import { Editor } from './Editor.js';
3
- import { AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands } from './types.js';
4
- export declare class CommandManager {
5
- editor: Editor;
6
- rawCommands: AnyCommands;
7
- customState?: EditorState;
8
- constructor(props: {
9
- editor: Editor;
10
- state?: EditorState;
11
- });
12
- get hasCustomState(): boolean;
13
- get state(): EditorState;
14
- get commands(): SingleCommands;
15
- get chain(): () => ChainedCommands;
16
- get can(): () => CanCommands;
17
- createChain(startTr?: Transaction, shouldDispatch?: boolean): ChainedCommands;
18
- createCan(startTr?: Transaction): CanCommands;
19
- buildProps(tr: Transaction, shouldDispatch?: boolean): CommandProps;
20
- }
@@ -1,159 +0,0 @@
1
- import { MarkType, NodeType, Schema } from '@tiptap/pm/model';
2
- import { EditorState, Plugin, PluginKey, Transaction } from '@tiptap/pm/state';
3
- import { EditorView } from '@tiptap/pm/view';
4
- import { EventEmitter } from './EventEmitter.js';
5
- import { ExtensionManager } from './ExtensionManager.js';
6
- import { NodePos } from './NodePos.js';
7
- import { CanCommands, ChainedCommands, EditorEvents, EditorOptions, JSONContent, SingleCommands, TextSerializer } from './types.js';
8
- export * as extensions from './extensions/index.js';
9
- export interface TiptapEditorHTMLElement extends HTMLElement {
10
- editor?: Editor;
11
- }
12
- export declare class Editor extends EventEmitter<EditorEvents> {
13
- private commandManager;
14
- extensionManager: ExtensionManager;
15
- private css;
16
- schema: Schema;
17
- view: EditorView;
18
- isFocused: boolean;
19
- extensionStorage: Record<string, any>;
20
- options: EditorOptions;
21
- constructor(options?: Partial<EditorOptions>);
22
- /**
23
- * Returns the editor storage.
24
- */
25
- get storage(): Record<string, any>;
26
- /**
27
- * An object of all registered commands.
28
- */
29
- get commands(): SingleCommands;
30
- /**
31
- * Create a command chain to call multiple commands at once.
32
- */
33
- chain(): ChainedCommands;
34
- /**
35
- * Check if a command or a command chain can be executed. Without executing it.
36
- */
37
- can(): CanCommands;
38
- /**
39
- * Inject CSS styles.
40
- */
41
- private injectCSS;
42
- /**
43
- * Update editor options.
44
- *
45
- * @param options A list of options
46
- */
47
- setOptions(options?: Partial<EditorOptions>): void;
48
- /**
49
- * Update editable state of the editor.
50
- */
51
- setEditable(editable: boolean, emitUpdate?: boolean): void;
52
- /**
53
- * Returns whether the editor is editable.
54
- */
55
- get isEditable(): boolean;
56
- /**
57
- * Returns the editor state.
58
- */
59
- get state(): EditorState;
60
- /**
61
- * Register a ProseMirror plugin.
62
- *
63
- * @param plugin A ProseMirror plugin
64
- * @param handlePlugins Control how to merge the plugin into the existing plugins.
65
- */
66
- registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void;
67
- /**
68
- * Unregister a ProseMirror plugin.
69
- *
70
- * @param nameOrPluginKey The plugins name
71
- */
72
- unregisterPlugin(nameOrPluginKey: string | PluginKey): void;
73
- /**
74
- * Creates an extension manager.
75
- */
76
- private createExtensionManager;
77
- /**
78
- * Creates an command manager.
79
- */
80
- private createCommandManager;
81
- /**
82
- * Creates a ProseMirror schema.
83
- */
84
- private createSchema;
85
- /**
86
- * Creates a ProseMirror view.
87
- */
88
- private createView;
89
- /**
90
- * Creates all node views.
91
- */
92
- createNodeViews(): void;
93
- /**
94
- * Prepend class name to element.
95
- */
96
- prependClass(): void;
97
- isCapturingTransaction: boolean;
98
- private capturedTransaction;
99
- captureTransaction(fn: Function): Transaction | null;
100
- /**
101
- * The callback over which to send transactions (state updates) produced by the view.
102
- *
103
- * @param transaction An editor state transaction
104
- */
105
- private dispatchTransaction;
106
- /**
107
- * Get attributes of the currently selected node or mark.
108
- */
109
- getAttributes(nameOrType: string | NodeType | MarkType): Record<string, any>;
110
- /**
111
- * Returns if the currently selected node or mark is active.
112
- *
113
- * @param name Name of the node or mark
114
- * @param attributes Attributes of the node or mark
115
- */
116
- isActive(name: string, attributes?: {}): boolean;
117
- isActive(attributes: {}): boolean;
118
- /**
119
- * Get the document as JSON.
120
- */
121
- getJSON(): JSONContent;
122
- /**
123
- * Get the document as HTML.
124
- */
125
- getHTML(): string;
126
- /**
127
- * Get the document as text.
128
- */
129
- getText(options?: {
130
- blockSeparator?: string;
131
- textSerializers?: Record<string, TextSerializer>;
132
- }): string;
133
- /**
134
- * Check if there is no content.
135
- */
136
- get isEmpty(): boolean;
137
- /**
138
- * Get the number of characters for the current document.
139
- *
140
- * @deprecated
141
- */
142
- getCharacterCount(): number;
143
- /**
144
- * Destroy the editor.
145
- */
146
- destroy(): void;
147
- /**
148
- * Check if the editor is already destroyed.
149
- */
150
- get isDestroyed(): boolean;
151
- $node(selector: string, attributes?: {
152
- [key: string]: any;
153
- }): NodePos | null;
154
- $nodes(selector: string, attributes?: {
155
- [key: string]: any;
156
- }): NodePos[] | null;
157
- $pos(pos: number): NodePos;
158
- get $doc(): NodePos;
159
- }
@@ -1,11 +0,0 @@
1
- type StringKeyOf<T> = Extract<keyof T, string>;
2
- type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
3
- type CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (...props: CallbackType<T, EventName>) => any;
4
- export declare class EventEmitter<T extends Record<string, any>> {
5
- private callbacks;
6
- on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this;
7
- emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this;
8
- off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this;
9
- removeAllListeners(): void;
10
- }
11
- export {};