@tiptap/suggestion
Advanced tools
Comparing version 2.0.0-beta.96 to 2.0.0-beta.97
@@ -6,3 +6,3 @@ import { Range } from '@tiptap/core'; | ||
allowSpaces: boolean; | ||
prefixSpace: boolean; | ||
allowedPrefixes: string[] | null; | ||
startOfLine: boolean; | ||
@@ -9,0 +9,0 @@ $position: ResolvedPos; |
@@ -9,4 +9,4 @@ import { Editor, Range } from '@tiptap/core'; | ||
allowSpaces?: boolean; | ||
allowedPrefixes?: string[] | null; | ||
startOfLine?: boolean; | ||
prefixSpace?: boolean; | ||
decorationTag?: string; | ||
@@ -53,2 +53,2 @@ decorationClass?: string; | ||
export declare const SuggestionPluginKey: PluginKey<any>; | ||
export declare function Suggestion<I = any>({ pluginKey, editor, char, allowSpaces, prefixSpace, startOfLine, decorationTag, decorationClass, command, items, render, allow, }: SuggestionOptions<I>): Plugin<any>; | ||
export declare function Suggestion<I = any>({ pluginKey, editor, char, allowSpaces, allowedPrefixes, startOfLine, decorationTag, decorationClass, command, items, render, allow, }: SuggestionOptions<I>): Plugin<any>; |
@@ -11,3 +11,3 @@ 'use strict'; | ||
var _a; | ||
const { char, allowSpaces, prefixSpace, startOfLine, $position, } = config; | ||
const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config; | ||
const escapedChar = core.escapeForRegEx(char); | ||
@@ -31,4 +31,4 @@ const suffix = new RegExp(`\\s${escapedChar}$`); | ||
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index); | ||
const matchPrefixIsSpace = /^[\s\0]?$/.test(matchPrefix); | ||
if (prefixSpace && !matchPrefixIsSpace) { | ||
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix); | ||
if (allowedPrefixes !== null && !matchPrefixIsAllowed) { | ||
return null; | ||
@@ -60,3 +60,3 @@ } | ||
const SuggestionPluginKey = new prosemirrorState.PluginKey('suggestion'); | ||
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, prefixSpace = true, startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) { | ||
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) { | ||
let props; | ||
@@ -148,5 +148,8 @@ const renderer = render === null || render === void 0 ? void 0 : render(); | ||
init() { | ||
return { | ||
const state = { | ||
active: false, | ||
range: {}, | ||
range: { | ||
from: 0, | ||
to: 0, | ||
}, | ||
query: null, | ||
@@ -156,2 +159,3 @@ text: null, | ||
}; | ||
return state; | ||
}, | ||
@@ -171,3 +175,3 @@ // Apply changes to the plugin state from a view transaction. | ||
// Reset active state if we just left the previous suggestion range | ||
if ((from < prev.range.from || from > prev.range.to) | ||
if (((from < prev.range.from) || from > prev.range.to) | ||
&& !composing | ||
@@ -181,3 +185,3 @@ && !prev.composing) { | ||
allowSpaces, | ||
prefixSpace, | ||
allowedPrefixes, | ||
startOfLine, | ||
@@ -205,3 +209,3 @@ $position: selection.$from, | ||
next.decorationId = null; | ||
next.range = {}; | ||
next.range = { from: 0, to: 0 }; | ||
next.query = null; | ||
@@ -208,0 +212,0 @@ next.text = null; |
@@ -7,3 +7,3 @@ import { PluginKey, Plugin } from 'prosemirror-state'; | ||
var _a; | ||
const { char, allowSpaces, prefixSpace, startOfLine, $position, } = config; | ||
const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config; | ||
const escapedChar = escapeForRegEx(char); | ||
@@ -27,4 +27,4 @@ const suffix = new RegExp(`\\s${escapedChar}$`); | ||
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index); | ||
const matchPrefixIsSpace = /^[\s\0]?$/.test(matchPrefix); | ||
if (prefixSpace && !matchPrefixIsSpace) { | ||
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix); | ||
if (allowedPrefixes !== null && !matchPrefixIsAllowed) { | ||
return null; | ||
@@ -56,3 +56,3 @@ } | ||
const SuggestionPluginKey = new PluginKey('suggestion'); | ||
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, prefixSpace = true, startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) { | ||
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) { | ||
let props; | ||
@@ -144,5 +144,8 @@ const renderer = render === null || render === void 0 ? void 0 : render(); | ||
init() { | ||
return { | ||
const state = { | ||
active: false, | ||
range: {}, | ||
range: { | ||
from: 0, | ||
to: 0, | ||
}, | ||
query: null, | ||
@@ -152,2 +155,3 @@ text: null, | ||
}; | ||
return state; | ||
}, | ||
@@ -167,3 +171,3 @@ // Apply changes to the plugin state from a view transaction. | ||
// Reset active state if we just left the previous suggestion range | ||
if ((from < prev.range.from || from > prev.range.to) | ||
if (((from < prev.range.from) || from > prev.range.to) | ||
&& !composing | ||
@@ -177,3 +181,3 @@ && !prev.composing) { | ||
allowSpaces, | ||
prefixSpace, | ||
allowedPrefixes, | ||
startOfLine, | ||
@@ -201,3 +205,3 @@ $position: selection.$from, | ||
next.decorationId = null; | ||
next.range = {}; | ||
next.range = { from: 0, to: 0 }; | ||
next.query = null; | ||
@@ -204,0 +208,0 @@ next.text = null; |
@@ -9,3 +9,3 @@ (function (global, factory) { | ||
var _a; | ||
const { char, allowSpaces, prefixSpace, startOfLine, $position, } = config; | ||
const { char, allowSpaces, allowedPrefixes, startOfLine, $position, } = config; | ||
const escapedChar = core.escapeForRegEx(char); | ||
@@ -29,4 +29,4 @@ const suffix = new RegExp(`\\s${escapedChar}$`); | ||
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index); | ||
const matchPrefixIsSpace = /^[\s\0]?$/.test(matchPrefix); | ||
if (prefixSpace && !matchPrefixIsSpace) { | ||
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.join('')}\0]?$`).test(matchPrefix); | ||
if (allowedPrefixes !== null && !matchPrefixIsAllowed) { | ||
return null; | ||
@@ -58,3 +58,3 @@ } | ||
const SuggestionPluginKey = new prosemirrorState.PluginKey('suggestion'); | ||
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, prefixSpace = true, startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) { | ||
function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, }) { | ||
let props; | ||
@@ -146,5 +146,8 @@ const renderer = render === null || render === void 0 ? void 0 : render(); | ||
init() { | ||
return { | ||
const state = { | ||
active: false, | ||
range: {}, | ||
range: { | ||
from: 0, | ||
to: 0, | ||
}, | ||
query: null, | ||
@@ -154,2 +157,3 @@ text: null, | ||
}; | ||
return state; | ||
}, | ||
@@ -169,3 +173,3 @@ // Apply changes to the plugin state from a view transaction. | ||
// Reset active state if we just left the previous suggestion range | ||
if ((from < prev.range.from || from > prev.range.to) | ||
if (((from < prev.range.from) || from > prev.range.to) | ||
&& !composing | ||
@@ -179,3 +183,3 @@ && !prev.composing) { | ||
allowSpaces, | ||
prefixSpace, | ||
allowedPrefixes, | ||
startOfLine, | ||
@@ -203,3 +207,3 @@ $position: selection.$from, | ||
next.decorationId = null; | ||
next.range = {}; | ||
next.range = { from: 0, to: 0 }; | ||
next.query = null; | ||
@@ -206,0 +210,0 @@ next.text = null; |
{ | ||
"name": "@tiptap/suggestion", | ||
"description": "suggestion plugin for tiptap", | ||
"version": "2.0.0-beta.96", | ||
"version": "2.0.0-beta.97", | ||
"homepage": "https://tiptap.dev", | ||
@@ -27,5 +27,5 @@ "keywords": [ | ||
"dependencies": { | ||
"prosemirror-model": "^1.17.0", | ||
"prosemirror-state": "^1.4.0", | ||
"prosemirror-view": "^1.25.0" | ||
"prosemirror-model": "1.18.1", | ||
"prosemirror-state": "1.4.1", | ||
"prosemirror-view": "1.26.2" | ||
}, | ||
@@ -37,3 +37,3 @@ "repository": { | ||
}, | ||
"gitHead": "a1e612bf897a14065b4f9ba6d48925c97d136811" | ||
"gitHead": "090c5a44566bcd936096574fa62bf301ab4a1285" | ||
} |
@@ -7,3 +7,3 @@ import { escapeForRegEx, Range } from '@tiptap/core' | ||
allowSpaces: boolean, | ||
prefixSpace: boolean, | ||
allowedPrefixes: string[] | null, | ||
startOfLine: boolean, | ||
@@ -23,3 +23,3 @@ $position: ResolvedPos, | ||
allowSpaces, | ||
prefixSpace, | ||
allowedPrefixes, | ||
startOfLine, | ||
@@ -52,5 +52,5 @@ $position, | ||
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index) | ||
const matchPrefixIsSpace = /^[\s\0]?$/.test(matchPrefix) | ||
const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes?.join('')}\0]?$`).test(matchPrefix) | ||
if (prefixSpace && !matchPrefixIsSpace) { | ||
if (allowedPrefixes !== null && !matchPrefixIsAllowed) { | ||
return null | ||
@@ -57,0 +57,0 @@ } |
@@ -12,4 +12,4 @@ import { Editor, Range } from '@tiptap/core' | ||
allowSpaces?: boolean, | ||
allowedPrefixes?: string[] | null, | ||
startOfLine?: boolean, | ||
prefixSpace?: boolean, | ||
decorationTag?: string, | ||
@@ -65,3 +65,3 @@ decorationClass?: string, | ||
allowSpaces = false, | ||
prefixSpace = true, | ||
allowedPrefixes = [' '], | ||
startOfLine = false, | ||
@@ -175,5 +175,15 @@ decorationTag = 'span', | ||
init() { | ||
return { | ||
const state: { | ||
active: boolean, | ||
range: Range, | ||
query: null | string | ||
text: null | string | ||
composing: boolean | ||
decorationId?: string | null | ||
} = { | ||
active: false, | ||
range: {}, | ||
range: { | ||
from: 0, | ||
to: 0, | ||
}, | ||
query: null, | ||
@@ -183,2 +193,4 @@ text: null, | ||
} | ||
return state | ||
}, | ||
@@ -202,3 +214,3 @@ | ||
if ( | ||
(from < prev.range.from || from > prev.range.to) | ||
((from < prev.range.from) || from > prev.range.to) | ||
&& !composing | ||
@@ -214,3 +226,3 @@ && !prev.composing | ||
allowSpaces, | ||
prefixSpace, | ||
allowedPrefixes, | ||
startOfLine, | ||
@@ -238,3 +250,3 @@ $position: selection.$from, | ||
next.decorationId = null | ||
next.range = {} | ||
next.range = { from: 0, to: 0 } | ||
next.query = null | ||
@@ -241,0 +253,0 @@ next.text = null |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111912
1096
+ Addedprosemirror-model@1.18.1(transitive)
+ Addedprosemirror-state@1.4.1(transitive)
+ Addedprosemirror-view@1.26.2(transitive)
Updatedprosemirror-model@1.18.1
Updatedprosemirror-state@1.4.1
Updatedprosemirror-view@1.26.2