@remirror/extension-mention
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0-beta.3
@@ -1,5 +0,20 @@ | ||
var _initClass, _MentionExtension, _dec, _dec2, _dec3, _dec4, _dec5, _initProto, _class; | ||
var _excluded = ["replacementType", "id", "label", "appendText"], | ||
_excluded2 = ["range", "appendText", "replacementType", "keepSelection", "name"]; | ||
var _initClass, _MentionExtension, _dec, _dec2, _dec3, _dec4, _dec5, _initProto, _class, _applyDecs2, _applyDecs2$e, _applyDecs2$c; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function createAddInitializerMethod(e, t) { return function (r) { assertNotFinished(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r); }; } | ||
function assertInstanceIfPrivate(e, t) { if (!e(t)) throw new TypeError("Attempted to access private element on non-instance"); } | ||
function memberDec(e, t, r, a, n, i, s, o, c, l, u) { var f; switch (i) { case 1: f = "accessor"; break; case 2: f = "method"; break; case 3: f = "getter"; break; case 4: f = "setter"; break; default: f = "field"; } var d, p, h = { kind: f, name: o ? "#" + r : r, static: s, private: o, metadata: u }, v = { v: !1 }; if (0 !== i && (h.addInitializer = createAddInitializerMethod(n, v)), o || 0 !== i && 2 !== i) { if (2 === i) d = function (e) { return assertInstanceIfPrivate(l, e), a.value; };else { var y = 0 === i || 1 === i; (y || 3 === i) && (d = o ? function (e) { return assertInstanceIfPrivate(l, e), a.get.call(e); } : function (e) { return a.get.call(e); }), (y || 4 === i) && (p = o ? function (e, t) { assertInstanceIfPrivate(l, e), a.set.call(e, t); } : function (e, t) { a.set.call(e, t); }); } } else d = function (e) { return e[r]; }, 0 === i && (p = function (e, t) { e[r] = t; }); var m = o ? l.bind() : function (e) { return r in e; }; h.access = d && p ? { get: d, set: p, has: m } : d ? { get: d, has: m } : { set: p, has: m }; try { return e.call(t, c, h); } finally { v.v = !0; } } | ||
function memberDec(e, t, r, a, n, i, s, o, c, l, u) { var f; switch (i) { case 1: f = "accessor"; break; case 2: f = "method"; break; case 3: f = "getter"; break; case 4: f = "setter"; break; default: f = "field"; } var d, p, h = { kind: f, name: o ? "#" + r : r, static: s, private: o, metadata: u }, v = { v: !1 }; if (0 !== i && (h.addInitializer = createAddInitializerMethod(n, v)), o || 0 !== i && 2 !== i) { if (2 === i) d = function d(e) { return assertInstanceIfPrivate(l, e), a.value; };else { var y = 0 === i || 1 === i; (y || 3 === i) && (d = o ? function (e) { return assertInstanceIfPrivate(l, e), a.get.call(e); } : function (e) { return a.get.call(e); }), (y || 4 === i) && (p = o ? function (e, t) { assertInstanceIfPrivate(l, e), a.set.call(e, t); } : function (e, t) { a.set.call(e, t); }); } } else d = function d(e) { return e[r]; }, 0 === i && (p = function p(e, t) { e[r] = t; }); var m = o ? l.bind() : function (e) { return r in e; }; h.access = d && p ? { get: d, set: p, has: m } : d ? { get: d, has: m } : { set: p, has: m }; try { return e.call(t, c, h); } finally { v.v = !0; } } | ||
function assertNotFinished(e, t) { if (e.v) throw new Error("attempted to call " + t + " after decoration was finished"); } | ||
@@ -10,4 +25,4 @@ function assertCallable(e, t) { if ("function" != typeof e) throw new TypeError(t + " must be a function"); } | ||
function curryThis2(e) { return function (t) { e(this, t); }; } | ||
function applyMemberDec(e, t, r, a, n, i, s, o, c, l, u) { var f, d, p, h, v, y, m = r[0]; a || Array.isArray(m) || (m = [m]), o ? f = 0 === i || 1 === i ? { get: curryThis1(r[3]), set: curryThis2(r[4]) } : 3 === i ? { get: r[3] } : 4 === i ? { set: r[3] } : { value: r[3] } : 0 !== i && (f = Object.getOwnPropertyDescriptor(t, n)), 1 === i ? p = { get: f.get, set: f.set } : 2 === i ? p = f.value : 3 === i ? p = f.get : 4 === i && (p = f.set); for (var g = a ? 2 : 1, b = m.length - 1; b >= 0; b -= g) { var I; if (void 0 !== (h = memberDec(m[b], a ? m[b - 1] : void 0, n, f, c, i, s, o, p, l, u))) assertValidReturnValue(i, h), 0 === i ? I = h : 1 === i ? (I = h.init, v = h.get || p.get, y = h.set || p.set, p = { get: v, set: y }) : p = h, void 0 !== I && (void 0 === d ? d = I : "function" == typeof d ? d = [d, I] : d.push(I)); } if (0 === i || 1 === i) { if (void 0 === d) d = function (e, t) { return t; };else if ("function" != typeof d) { var w = d; d = function (e, t) { for (var r = t, a = w.length - 1; a >= 0; a--) r = w[a].call(e, r); return r; }; } else { var M = d; d = function (e, t) { return M.call(e, t); }; } e.push(d); } 0 !== i && (1 === i ? (f.get = p.get, f.set = p.set) : 2 === i ? f.value = p : 3 === i ? f.get = p : 4 === i && (f.set = p), o ? 1 === i ? (e.push(function (e, t) { return p.get.call(e, t); }), e.push(function (e, t) { return p.set.call(e, t); })) : 2 === i ? e.push(p) : e.push(function (e, t) { return p.call(e, t); }) : Object.defineProperty(t, n, f)); } | ||
function applyMemberDecs(e, t, r, a) { for (var n, i, s, o = [], c = new Map(), l = new Map(), u = 0; u < t.length; u++) { var f = t[u]; if (Array.isArray(f)) { var d, p, h = f[1], v = f[2], y = f.length > 3, m = 16 & h, g = !!(8 & h), b = r; if (h &= 7, g ? (d = e, 0 !== h && (p = i = i || []), y && !s && (s = function (t) { return _checkInRHS(t) === e; }), b = s) : (d = e.prototype, 0 !== h && (p = n = n || [])), 0 !== h && !y) { var I = g ? l : c, w = I.get(v) || 0; if (!0 === w || 3 === w && 4 !== h || 4 === w && 3 !== h) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + v); I.set(v, !(!w && h > 2) || h); } applyMemberDec(o, d, f, m, v, h, g, y, p, b, a); } } return pushInitializers(o, n), pushInitializers(o, i), o; } | ||
function applyMemberDec(e, t, r, a, n, i, s, o, c, l, u) { var f, d, p, h, v, y, m = r[0]; a || Array.isArray(m) || (m = [m]), o ? f = 0 === i || 1 === i ? { get: curryThis1(r[3]), set: curryThis2(r[4]) } : 3 === i ? { get: r[3] } : 4 === i ? { set: r[3] } : { value: r[3] } : 0 !== i && (f = Object.getOwnPropertyDescriptor(t, n)), 1 === i ? p = { get: f.get, set: f.set } : 2 === i ? p = f.value : 3 === i ? p = f.get : 4 === i && (p = f.set); for (var g = a ? 2 : 1, b = m.length - 1; b >= 0; b -= g) { var I; if (void 0 !== (h = memberDec(m[b], a ? m[b - 1] : void 0, n, f, c, i, s, o, p, l, u))) assertValidReturnValue(i, h), 0 === i ? I = h : 1 === i ? (I = h.init, v = h.get || p.get, y = h.set || p.set, p = { get: v, set: y }) : p = h, void 0 !== I && (void 0 === d ? d = I : "function" == typeof d ? d = [d, I] : d.push(I)); } if (0 === i || 1 === i) { if (void 0 === d) d = function d(e, t) { return t; };else if ("function" != typeof d) { var w = d; d = function d(e, t) { for (var r = t, a = w.length - 1; a >= 0; a--) r = w[a].call(e, r); return r; }; } else { var M = d; d = function d(e, t) { return M.call(e, t); }; } e.push(d); } 0 !== i && (1 === i ? (f.get = p.get, f.set = p.set) : 2 === i ? f.value = p : 3 === i ? f.get = p : 4 === i && (f.set = p), o ? 1 === i ? (e.push(function (e, t) { return p.get.call(e, t); }), e.push(function (e, t) { return p.set.call(e, t); })) : 2 === i ? e.push(p) : e.push(function (e, t) { return p.call(e, t); }) : Object.defineProperty(t, n, f)); } | ||
function applyMemberDecs(e, t, r, a) { for (var n, i, s, o = [], c = new Map(), l = new Map(), u = 0; u < t.length; u++) { var f = t[u]; if (Array.isArray(f)) { var d, p, h = f[1], v = f[2], y = f.length > 3, m = 16 & h, g = !!(8 & h), b = r; if (h &= 7, g ? (d = e, 0 !== h && (p = i = i || []), y && !s && (s = function s(t) { return _checkInRHS(t) === e; }), b = s) : (d = e.prototype, 0 !== h && (p = n = n || [])), 0 !== h && !y) { var I = g ? l : c, w = I.get(v) || 0; if (!0 === w || 3 === w && 4 !== h || 4 === w && 3 !== h) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + v); I.set(v, !(!w && h > 2) || h); } applyMemberDec(o, d, f, m, v, h, g, y, p, b, a); } } return pushInitializers(o, n), pushInitializers(o, i), o; } | ||
function pushInitializers(e, t) { t && e.push(function (e) { for (var r = 0; r < t.length; r++) t[r].call(e); return e; }); } | ||
@@ -43,4 +58,4 @@ function applyClassDecs(e, t, r, a) { if (t.length) { for (var n = [], i = e, s = e.name, o = r ? 2 : 1, c = t.length - 1; c >= 0; c -= o) { var l = { v: !1 }; try { var u = t[c].call(r ? t[c - 1] : void 0, i, { kind: "class", name: s, addInitializer: createAddInitializerMethod(n, l), metadata: a }); } finally { l.v = !0; } void 0 !== u && (assertValidReturnValue(5, u), i = u); } return [defineMetadata(i, a), function () { for (var e = 0; e < n.length; e++) n[e].call(i); }]; } } | ||
}), _dec2 = command(), _dec3 = command(), _dec4 = command(), _dec5 = command(), (_class = class MentionExtension extends MarkExtension { | ||
constructor(...args) { | ||
super(...args); | ||
constructor() { | ||
super(...arguments); | ||
_initProto(this); | ||
@@ -58,16 +73,16 @@ } | ||
createMarkSpec(extra, override) { | ||
const dataAttributeId = "data-mention-id"; | ||
const dataAttributeName = "data-mention-name"; | ||
return { | ||
var _override$parseDOM; | ||
var dataAttributeId = "data-mention-id"; | ||
var dataAttributeName = "data-mention-name"; | ||
return _objectSpread(_objectSpread({ | ||
excludes: "_", | ||
inclusive: false, | ||
...override, | ||
attrs: { | ||
...extra.defaults(), | ||
inclusive: false | ||
}, override), {}, { | ||
attrs: _objectSpread(_objectSpread({}, extra.defaults()), {}, { | ||
id: {}, | ||
label: {}, | ||
name: {} | ||
}, | ||
}), | ||
parseDOM: [{ | ||
tag: `${this.options.mentionTag}[${dataAttributeId}]`, | ||
tag: "".concat(this.options.mentionTag, "[").concat(dataAttributeId, "]"), | ||
getAttrs: element => { | ||
@@ -77,28 +92,26 @@ if (!isElementDomNode(element)) { | ||
} | ||
const id = element.getAttribute(dataAttributeId); | ||
const name = element.getAttribute(dataAttributeName); | ||
const label = element.textContent; | ||
return { | ||
...extra.parse(element), | ||
var id = element.getAttribute(dataAttributeId); | ||
var name = element.getAttribute(dataAttributeName); | ||
var label = element.textContent; | ||
return _objectSpread(_objectSpread({}, extra.parse(element)), {}, { | ||
id, | ||
label, | ||
name | ||
}; | ||
}); | ||
} | ||
}, ...(override.parseDOM ?? [])], | ||
}, ...((_override$parseDOM = override.parseDOM) !== null && _override$parseDOM !== void 0 ? _override$parseDOM : [])], | ||
toDOM: mark => { | ||
const { | ||
id, | ||
name | ||
} = omitExtraAttributes(mark.attrs, extra); | ||
const matcher = this.options.matchers.find(matcher2 => matcher2.name === name); | ||
const mentionClassName = matcher ? matcher.mentionClassName ?? DEFAULT_MATCHER.mentionClassName : DEFAULT_MATCHER.mentionClassName; | ||
return [this.options.mentionTag, { | ||
...extra.dom(mark), | ||
class: name ? `${mentionClassName} ${mentionClassName}-${name}` : mentionClassName, | ||
var _matcher$mentionClass; | ||
var _omitExtraAttributes = omitExtraAttributes(mark.attrs, extra), | ||
id = _omitExtraAttributes.id, | ||
name = _omitExtraAttributes.name; | ||
var matcher = this.options.matchers.find(matcher2 => matcher2.name === name); | ||
var mentionClassName = matcher ? (_matcher$mentionClass = matcher.mentionClassName) !== null && _matcher$mentionClass !== void 0 ? _matcher$mentionClass : DEFAULT_MATCHER.mentionClassName : DEFAULT_MATCHER.mentionClassName; | ||
return [this.options.mentionTag, _objectSpread(_objectSpread({}, extra.dom(mark)), {}, { | ||
class: name ? "".concat(mentionClassName, " ").concat(mentionClassName, "-").concat(name) : mentionClassName, | ||
[dataAttributeId]: id, | ||
[dataAttributeName]: name | ||
}, 0]; | ||
}), 0]; | ||
} | ||
}; | ||
}); | ||
} | ||
@@ -114,3 +127,3 @@ onCreate() { | ||
clickMark: (event, clickState) => { | ||
const markRange = clickState.getMark(this.type); | ||
var markRange = clickState.getMark(this.type); | ||
if (!markRange) { | ||
@@ -130,14 +143,10 @@ return; | ||
return this.options.matchers.map(matcher => { | ||
const { | ||
startOfLine, | ||
var _DEFAULT_MATCHER$matc = _objectSpread(_objectSpread({}, DEFAULT_MATCHER), matcher), | ||
startOfLine = _DEFAULT_MATCHER$matc.startOfLine, | ||
char = _DEFAULT_MATCHER$matc.char, | ||
supportedCharacters = _DEFAULT_MATCHER$matc.supportedCharacters, | ||
name = _DEFAULT_MATCHER$matc.name, | ||
matchOffset = _DEFAULT_MATCHER$matc.matchOffset; | ||
var regexp = new RegExp("(".concat(createRegexFromSuggester({ | ||
char, | ||
supportedCharacters, | ||
name, | ||
matchOffset | ||
} = { | ||
...DEFAULT_MATCHER, | ||
...matcher | ||
}; | ||
const regexp = new RegExp(`(${createRegexFromSuggester({ | ||
char, | ||
matchOffset, | ||
@@ -149,3 +158,3 @@ startOfLine, | ||
multiline: false | ||
}).source})`, "g"); | ||
}).source, ")"), "g"); | ||
return { | ||
@@ -170,25 +179,23 @@ type: "mark", | ||
createSuggesters() { | ||
let cachedRange; | ||
const options = pick(this.options, ["invalidMarks", "invalidNodes", "isValidPosition", "validMarks", "validNodes", "suggestTag", "disableDecorations"]); | ||
return this.options.matchers.map(matcher => ({ | ||
...DEFAULT_MATCHER, | ||
...options, | ||
...matcher, | ||
var _this = this; | ||
var cachedRange; | ||
var options = pick(this.options, ["invalidMarks", "invalidNodes", "isValidPosition", "validMarks", "validNodes", "suggestTag", "disableDecorations"]); | ||
return this.options.matchers.map(matcher => _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, DEFAULT_MATCHER), options), matcher), {}, { | ||
onChange: props => { | ||
const command2 = (attrs = {}) => { | ||
this.mentionExitHandler(props, attrs)(this.store.helpers.getCommandProp()); | ||
var command2 = function command2() { | ||
var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_this.mentionExitHandler(props, attrs)(_this.store.helpers.getCommandProp()); | ||
}; | ||
this.options.onChange({ | ||
...props, | ||
this.options.onChange(_objectSpread(_objectSpread({}, props), {}, { | ||
defaultAppendTextValue: this.options.appendText | ||
}, command2); | ||
}), command2); | ||
}, | ||
checkNextValidSelection: ($pos, tr) => { | ||
var _cachedRange, _cachedRange2; | ||
const range = getMarkRange($pos, this.type); | ||
var range = getMarkRange($pos, this.type); | ||
if (!range || range.from === ((_cachedRange = cachedRange) === null || _cachedRange === void 0 ? void 0 : _cachedRange.from) && range.to === ((_cachedRange2 = cachedRange) === null || _cachedRange2 === void 0 ? void 0 : _cachedRange2.to)) { | ||
return; | ||
} | ||
const text = $pos.doc.textBetween(range.from, range.to, LEAF_NODE_REPLACING_CHARACTER, " "); | ||
const isValidMention = isValidMentionAttributes(range.mark.attrs) && this.options.isMentionValid(range.mark.attrs, text); | ||
var text = $pos.doc.textBetween(range.from, range.to, LEAF_NODE_REPLACING_CHARACTER, " "); | ||
var isValidMention = isValidMentionAttributes(range.mark.attrs) && this.options.isMentionValid(range.mark.attrs, text); | ||
if (isValidMention) { | ||
@@ -204,7 +211,9 @@ return; | ||
} | ||
mentionExitHandler(handler, attrs = {}) { | ||
mentionExitHandler(handler) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return props => { | ||
const reason = handler.exitReason ?? handler.changeReason; | ||
const isInvalid = isInvalidSplitReason(reason); | ||
const isRemoved = isRemovedReason(reason); | ||
var _handler$exitReason; | ||
var reason = (_handler$exitReason = handler.exitReason) !== null && _handler$exitReason !== void 0 ? _handler$exitReason : handler.changeReason; | ||
var isInvalid = isInvalidSplitReason(reason); | ||
var isRemoved = isRemovedReason(reason); | ||
if (isInvalid || isRemoved) { | ||
@@ -216,21 +225,15 @@ handler.setMarkRemoved(); | ||
})(props); | ||
} catch { | ||
} catch (_unused) { | ||
return true; | ||
} | ||
} | ||
const { | ||
tr | ||
} = props; | ||
const { | ||
range, | ||
text, | ||
query, | ||
name | ||
} = handler; | ||
const { | ||
var tr = props.tr; | ||
var range = handler.range, | ||
text = handler.text, | ||
query = handler.query, | ||
name = handler.name; | ||
var from = range.from, | ||
to = range.to; | ||
var isActive = isMarkActive({ | ||
from, | ||
to | ||
} = range; | ||
const isActive = isMarkActive({ | ||
from, | ||
to, | ||
@@ -240,12 +243,14 @@ type: this.type, | ||
}); | ||
const command2 = isActive ? this.updateMention.bind(this) : this.createMention.bind(this); | ||
const { | ||
replacementType = isSplitReason(reason) ? "partial" : "full", | ||
id = query[replacementType], | ||
label = text[replacementType], | ||
appendText = this.options.appendText, | ||
...rest | ||
} = attrs; | ||
const keepSelection = isSelectionExitReason(reason); | ||
return command2({ | ||
var command2 = isActive ? this.updateMention.bind(this) : this.createMention.bind(this); | ||
var _attrs$replacementTyp = attrs.replacementType, | ||
replacementType = _attrs$replacementTyp === void 0 ? isSplitReason(reason) ? "partial" : "full" : _attrs$replacementTyp, | ||
_attrs$id = attrs.id, | ||
id = _attrs$id === void 0 ? query[replacementType] : _attrs$id, | ||
_attrs$label = attrs.label, | ||
label = _attrs$label === void 0 ? text[replacementType] : _attrs$label, | ||
_attrs$appendText = attrs.appendText, | ||
appendText = _attrs$appendText === void 0 ? this.options.appendText : _attrs$appendText, | ||
rest = _objectWithoutProperties(attrs, _excluded); | ||
var keepSelection = isSelectionExitReason(reason); | ||
return command2(_objectSpread({ | ||
name, | ||
@@ -257,5 +262,4 @@ id, | ||
range, | ||
keepSelection, | ||
...rest | ||
})(props); | ||
keepSelection | ||
}, rest))(props); | ||
}; | ||
@@ -269,6 +273,6 @@ } | ||
} | ||
removeMention({ | ||
range | ||
} = {}) { | ||
const value = removeMark({ | ||
removeMention() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
range = _ref.range; | ||
var value = removeMark({ | ||
type: this.type, | ||
@@ -288,54 +292,49 @@ expand: true, | ||
}); | ||
const { | ||
range, | ||
appendText, | ||
replacementType, | ||
keepSelection, | ||
name, | ||
...attributes | ||
} = config; | ||
const allowedNames = this.options.matchers.map(({ | ||
name: name2 | ||
}) => name2); | ||
const matcher = getMatcher(name, this.options.matchers); | ||
var range = config.range, | ||
appendText = config.appendText, | ||
replacementType = config.replacementType, | ||
keepSelection = config.keepSelection, | ||
name = config.name, | ||
attributes = _objectWithoutProperties(config, _excluded2); | ||
var allowedNames = this.options.matchers.map(_ref2 => { | ||
var name2 = _ref2.name; | ||
return name2; | ||
}); | ||
var matcher = getMatcher(name, this.options.matchers); | ||
invariant(allowedNames.includes(name) && matcher, { | ||
code: ErrorConstant.EXTENSION, | ||
message: `The name '${name}' specified for this command is invalid. Please choose from: ${JSON.stringify(allowedNames)}.` | ||
message: "The name '".concat(name, "' specified for this command is invalid. Please choose from: ").concat(JSON.stringify(allowedNames), ".") | ||
}); | ||
return props => { | ||
const { | ||
tr | ||
} = props; | ||
const { | ||
from, | ||
to | ||
} = { | ||
from: (range === null || range === void 0 ? void 0 : range.from) ?? tr.selection.from, | ||
to: (range === null || range === void 0 ? void 0 : range.cursor) ?? tr.selection.to | ||
}; | ||
var _range$from, _range$cursor; | ||
var tr = props.tr; | ||
var _from$to = { | ||
from: (_range$from = range === null || range === void 0 ? void 0 : range.from) !== null && _range$from !== void 0 ? _range$from : tr.selection.from, | ||
to: (_range$cursor = range === null || range === void 0 ? void 0 : range.cursor) !== null && _range$cursor !== void 0 ? _range$cursor : tr.selection.to | ||
}, | ||
from = _from$to.from, | ||
to = _from$to.to; | ||
if (shouldUpdate) { | ||
let { | ||
oldFrom, | ||
oldTo | ||
} = { | ||
oldFrom: from, | ||
oldTo: range ? range.to : to | ||
}; | ||
const $oldTo = tr.doc.resolve(oldTo); | ||
({ | ||
var _getMarkRange, _getMarkRange2; | ||
var _oldFrom$oldTo = { | ||
oldFrom: from, | ||
oldTo: range ? range.to : to | ||
}, | ||
oldFrom = _oldFrom$oldTo.oldFrom, | ||
oldTo = _oldFrom$oldTo.oldTo; | ||
var $oldTo = tr.doc.resolve(oldTo); | ||
var _ref3 = (_getMarkRange2 = getMarkRange($oldTo, this.type)) !== null && _getMarkRange2 !== void 0 ? _getMarkRange2 : { | ||
from: oldFrom, | ||
to: oldTo | ||
} = getMarkRange($oldTo, this.type) ?? { | ||
from: oldFrom, | ||
to: oldTo | ||
}); | ||
}; | ||
oldFrom = _ref3.from; | ||
oldTo = _ref3.to; | ||
tr.removeMark(oldFrom, oldTo, this.type).setMeta("addToHistory", false); | ||
const $newTo = tr.selection.$from; | ||
const { | ||
from: newFrom, | ||
to: newTo | ||
} = getMarkRange($newTo, this.type) ?? { | ||
from: $newTo.pos, | ||
to: $newTo.pos | ||
}; | ||
var $newTo = tr.selection.$from; | ||
var _ref4 = (_getMarkRange = getMarkRange($newTo, this.type)) !== null && _getMarkRange !== void 0 ? _getMarkRange : { | ||
from: $newTo.pos, | ||
to: $newTo.pos | ||
}, | ||
newFrom = _ref4.from, | ||
newTo = _ref4.to; | ||
tr.removeMark(newFrom, newTo, this.type).setMeta("addToHistory", false); | ||
@@ -346,6 +345,5 @@ } | ||
type: this.type, | ||
attrs: { | ||
...attributes, | ||
attrs: _objectSpread(_objectSpread({}, attributes), {}, { | ||
name | ||
}, | ||
}), | ||
appendText: getAppendText(appendText, matcher.appendText), | ||
@@ -361,8 +359,6 @@ range: range ? { | ||
shouldSkipInputRule(props) { | ||
const { | ||
ruleType, | ||
state, | ||
end, | ||
start | ||
} = props; | ||
var ruleType = props.ruleType, | ||
state = props.state, | ||
end = props.end, | ||
start = props.start; | ||
if (ruleType === "node") { | ||
@@ -392,21 +388,19 @@ return false; | ||
var _suggestState$match; | ||
const suggestState = this.store.helpers.getSuggestState(); | ||
const names = new Set(this.options.matchers.map(({ | ||
name | ||
}) => name)); | ||
const activeName = (_suggestState$match = suggestState.match) === null || _suggestState$match === void 0 ? void 0 : _suggestState$match.suggester.name; | ||
return this.options.matchers.some(matcher => activeName === matcher.name) || suggestState.decorationSet.find(start, end, ({ | ||
name | ||
}) => names.has(name)).length > 0; | ||
var suggestState = this.store.helpers.getSuggestState(); | ||
var names = new Set(this.options.matchers.map(_ref5 => { | ||
var name = _ref5.name; | ||
return name; | ||
})); | ||
var activeName = (_suggestState$match = suggestState.match) === null || _suggestState$match === void 0 ? void 0 : _suggestState$match.suggester.name; | ||
return this.options.matchers.some(matcher => activeName === matcher.name) || suggestState.decorationSet.find(start, end, _ref6 => { | ||
var name = _ref6.name; | ||
return names.has(name); | ||
}).length > 0; | ||
} | ||
}, ({ | ||
e: [_initProto], | ||
c: [_MentionExtension, _initClass] | ||
} = _applyDecs(_class, [[_dec2, 2, "mentionExitHandler"], [_dec3, 2, "createMention"], [_dec4, 2, "updateMention"], [_dec5, 2, "removeMention"]], [_dec])), _initClass())), _MentionExtension); | ||
var DEFAULT_MATCHER = { | ||
...pick(DEFAULT_SUGGESTER, ["startOfLine", "supportedCharacters", "validPrefixCharacters", "invalidPrefixCharacters", "suggestClassName"]), | ||
}, (_applyDecs2 = _applyDecs(_class, [[_dec2, 2, "mentionExitHandler"], [_dec3, 2, "createMention"], [_dec4, 2, "updateMention"], [_dec5, 2, "removeMention"]], [_dec]), _applyDecs2$e = _slicedToArray(_applyDecs2.e, 1), _initProto = _applyDecs2$e[0], _applyDecs2$c = _slicedToArray(_applyDecs2.c, 2), _MentionExtension = _applyDecs2$c[0], _initClass = _applyDecs2$c[1]), _initClass())), _MentionExtension); | ||
var DEFAULT_MATCHER = _objectSpread(_objectSpread({}, pick(DEFAULT_SUGGESTER, ["startOfLine", "supportedCharacters", "validPrefixCharacters", "invalidPrefixCharacters", "suggestClassName"])), {}, { | ||
appendText: "", | ||
matchOffset: 1, | ||
mentionClassName: "mention" | ||
}; | ||
}); | ||
function isValidMentionAttributes(attributes) { | ||
@@ -416,7 +410,4 @@ return !!(attributes && isPlainObject(attributes) && attributes.id && isString(attributes.id) && attributes.label && isString(attributes.label) && attributes.name && isString(attributes.name)); | ||
function getMatcher(name, matchers) { | ||
const matcher = matchers.find(matcher2 => matcher2.name === name); | ||
return matcher ? { | ||
...DEFAULT_MATCHER, | ||
...matcher | ||
} : void 0; | ||
var matcher = matchers.find(matcher2 => matcher2.name === name); | ||
return matcher ? _objectSpread(_objectSpread({}, DEFAULT_MATCHER), matcher) : void 0; | ||
} | ||
@@ -423,0 +414,0 @@ function getAppendText(preferred, fallback) { |
{ | ||
"name": "@remirror/extension-mention", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0-beta.3", | ||
"description": "Mention extension for the remirror wysiwyg editor", | ||
@@ -34,4 +34,4 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/remirror__extension-mention", | ||
"@babel/runtime": "^7.22.3", | ||
"@remirror/core": "3.0.0-beta.2", | ||
"@remirror/extension-events": "3.0.0-beta.2", | ||
"@remirror/core": "3.0.0-beta.3", | ||
"@remirror/extension-events": "3.0.0-beta.3", | ||
"@remirror/messages": "3.0.0-beta.1", | ||
@@ -38,0 +38,0 @@ "escape-string-regexp": "^4.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
166643
1961
+ Added@remirror/core@3.0.0-beta.3(transitive)
+ Added@remirror/extension-events@3.0.0-beta.3(transitive)
- Removed@remirror/core@3.0.0-beta.2(transitive)
- Removed@remirror/extension-events@3.0.0-beta.2(transitive)
Updated@remirror/core@3.0.0-beta.3