@remirror/extension-mention
Advanced tools
Comparing version
# @remirror/extension-mention | ||
## 1.0.0-next.11 | ||
> 2020-07-26 | ||
### Patch Changes | ||
- 54461006: Remove the first parameter `extensions` from the lifecycle methods `onCreate`, `onView` | ||
and `onDestroy`. | ||
Switch to using method signatures for extension class methods as discussed in #360. The following | ||
methods have been affected: | ||
``` | ||
onCreate | ||
onView | ||
onStateUpdate | ||
onDestroy | ||
createAttributes | ||
createCommands | ||
createPlugin | ||
createExternalPlugins | ||
createSuggestions | ||
createHelpers | ||
fromObject | ||
onSetOptions | ||
``` | ||
- Updated dependencies [54461006] | ||
- @remirror/core@1.0.0-next.11 | ||
## 1.0.0-next.10 | ||
@@ -4,0 +34,0 @@ |
import { AddCustomHandler, ApplySchemaAttributes, CommandFunction, CustomHandlerKeyList, DefaultExtensionOptions, HandlerKeyList, MarkExtension, MarkExtensionSpec, RangeParameter, StaticKeyList } from '@remirror/core'; | ||
import { Suggestion } from '@remirror/pm/suggest'; | ||
import { MentionExtensionAttributes, MentionExtensionSuggestCommand, MentionOptions } from './mention-types'; | ||
import { MentionExtensionSuggestCommand, MentionOptions } from './mention-types'; | ||
/** | ||
@@ -38,3 +38,3 @@ * The mention extension wraps mentions as a prosemirror mark. It allows for | ||
createMarkSpec(extra: ApplySchemaAttributes): MarkExtensionSpec; | ||
createCommands: () => { | ||
createCommands(): { | ||
/** | ||
@@ -48,3 +48,3 @@ * Create a new mention | ||
keepSelection?: boolean; | ||
}) => CommandFunction; | ||
}) => CommandFunction<any, object>; | ||
/** | ||
@@ -58,3 +58,3 @@ * Update an existing mention. | ||
keepSelection?: boolean; | ||
}) => CommandFunction; | ||
}) => CommandFunction<any, object>; | ||
/** | ||
@@ -66,3 +66,3 @@ * Remove the mention(s) at the current selection or provided range. | ||
createPasteRules: any; | ||
createSuggestions: () => Suggestion<MentionExtensionSuggestCommand>[]; | ||
createSuggestions(): Suggestion<MentionExtensionSuggestCommand>[]; | ||
/** | ||
@@ -69,0 +69,0 @@ * The factory method for mention commands to update and create new mentions. |
@@ -92,6 +92,3 @@ 'use strict'; | ||
constructor() { | ||
var _this; | ||
super(...arguments); | ||
_this = this; | ||
@@ -127,34 +124,2 @@ _defineProperty(this, "characterEntryMethods", []); | ||
_defineProperty(this, "createCommands", () => { | ||
return { | ||
/** | ||
* Create a new mention | ||
*/ | ||
createMention: this.createMention({ | ||
shouldUpdate: false | ||
}), | ||
/** | ||
* Update an existing mention. | ||
*/ | ||
updateMention: this.createMention({ | ||
shouldUpdate: true | ||
}), | ||
/** | ||
* Remove the mention(s) at the current selection or provided range. | ||
*/ | ||
removeMention: function removeMention() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : core.object(), | ||
range = _ref.range; | ||
return core.removeMark({ | ||
type: _this.type, | ||
expand: true, | ||
range | ||
}); | ||
} | ||
}; | ||
}); | ||
_defineProperty(this, "createPasteRules", () => { | ||
@@ -181,88 +146,2 @@ return this.options.matchers.map(matcher => { | ||
_defineProperty(this, "createSuggestions", () => { | ||
return this.options.matchers.map(matcher => { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
var extension = this; | ||
return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), {}, { | ||
// The following properties are provided as getter so that the | ||
// prosemirror-suggest plugin always references the latest version of | ||
// the suggestion. This is not a good idea and should be fixed in a | ||
// better way soon. | ||
get noDecorations() { | ||
return extension.options.noDecorations; | ||
}, | ||
get suggestTag() { | ||
return extension.options.suggestTag; | ||
}, | ||
keyBindings: () => this.keyBindings, | ||
onCharacterEntry: this.onCharacterEntry, | ||
onChange: this.options.onChange, | ||
onExit: this.options.onExit, | ||
createCommand: (_ref2) => { | ||
var match = _ref2.match, | ||
reason = _ref2.reason, | ||
setMarkRemoved = _ref2.setMarkRemoved; | ||
var range = match.range, | ||
suggester = match.suggester; | ||
var name = suggester.name; | ||
var createMention = this.store.getCommands().createMention; | ||
var updateMention = this.store.getCommands().updateMention; | ||
var removeMention = this.store.getCommands().removeMention; | ||
var isActive = core.isMarkActive({ | ||
from: range.from, | ||
to: range.end, | ||
type: this.type, | ||
stateOrTransaction: this.store.getState() | ||
}); | ||
var method = isActive ? updateMention : createMention; | ||
var isSplit = suggest.isSplitReason(reason); | ||
var isInvalid = suggest.isInvalidSplitReason(reason); | ||
var isRemoved = suggest.isRemovedReason(reason); | ||
var isSelectionExit = suggest.isSelectionExitReason(reason); | ||
var remove = () => { | ||
setMarkRemoved(); | ||
try { | ||
// This might fail when a deletion has taken place. | ||
isInvalid ? removeMention({ | ||
range | ||
}) : core.noop(); | ||
} catch (_unused) {// This sometimes fails and it's best to ignore until more is | ||
// known about the impact. Please create an issue if this blocks | ||
// you in some way. | ||
} | ||
}; | ||
var update = (_ref3) => { | ||
var _ref3$replacementType = _ref3.replacementType, | ||
replacementType = _ref3$replacementType === void 0 ? isSplit ? 'partial' : 'full' : _ref3$replacementType, | ||
_ref3$id = _ref3.id, | ||
id = _ref3$id === void 0 ? match.queryText[replacementType] : _ref3$id, | ||
_ref3$label = _ref3.label, | ||
label = _ref3$label === void 0 ? match.matchText[replacementType] : _ref3$label, | ||
_ref3$appendText = _ref3.appendText, | ||
appendText = _ref3$appendText === void 0 ? this.options.appendText : _ref3$appendText, | ||
attributes = _objectWithoutProperties(_ref3, ["replacementType", "id", "label", "appendText"]); | ||
method(_objectSpread$1({ | ||
id, | ||
label, | ||
appendText, | ||
replacementType, | ||
name, | ||
range, | ||
keepSelection: isSelectionExit | ||
}, attributes)); | ||
}; | ||
var command = isInvalid || isRemoved ? remove : update; | ||
return command; | ||
} | ||
}); | ||
}); | ||
}); | ||
_defineProperty(this, "onCharacterEntry", parameter => { | ||
@@ -326,9 +205,9 @@ var _iterator = _createForOfIteratorHelper(this.characterEntryMethods), | ||
var _ref4 = node.attrs, | ||
_ = _ref4.label, | ||
id = _ref4.id, | ||
name = _ref4.name, | ||
replacementType = _ref4.replacementType, | ||
range = _ref4.range, | ||
attributes = _objectWithoutProperties(_ref4, ["label", "id", "name", "replacementType", "range"]); | ||
var _ref = node.attrs, | ||
_ = _ref.label, | ||
id = _ref.id, | ||
name = _ref.name, | ||
replacementType = _ref.replacementType, | ||
range = _ref.range, | ||
attributes = _objectWithoutProperties(_ref, ["label", "id", "name", "replacementType", "range"]); | ||
@@ -346,5 +225,126 @@ var matcher = this.options.matchers.find(matcher => matcher.name === name); | ||
createCommands() { | ||
var _this = this; | ||
return { | ||
/** | ||
* Create a new mention | ||
*/ | ||
createMention: this.createMention({ | ||
shouldUpdate: false | ||
}), | ||
/** | ||
* Update an existing mention. | ||
*/ | ||
updateMention: this.createMention({ | ||
shouldUpdate: true | ||
}), | ||
/** | ||
* Remove the mention(s) at the current selection or provided range. | ||
*/ | ||
removeMention: function removeMention() { | ||
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : core.object(), | ||
range = _ref2.range; | ||
return core.removeMark({ | ||
type: _this.type, | ||
expand: true, | ||
range | ||
}); | ||
} | ||
}; | ||
} | ||
createSuggestions() { | ||
return this.options.matchers.map(matcher => { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
var extension = this; | ||
return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), {}, { | ||
// The following properties are provided as getter so that the | ||
// prosemirror-suggest plugin always references the latest version of | ||
// the suggestion. This is not a good idea and should be fixed in a | ||
// better way soon. | ||
get noDecorations() { | ||
return extension.options.noDecorations; | ||
}, | ||
get suggestTag() { | ||
return extension.options.suggestTag; | ||
}, | ||
keyBindings: () => this.keyBindings, | ||
onCharacterEntry: this.onCharacterEntry, | ||
onChange: this.options.onChange, | ||
onExit: this.options.onExit, | ||
createCommand: (_ref3) => { | ||
var match = _ref3.match, | ||
reason = _ref3.reason, | ||
setMarkRemoved = _ref3.setMarkRemoved; | ||
var range = match.range, | ||
suggester = match.suggester; | ||
var name = suggester.name; | ||
var createMention = this.store.getCommands().createMention; | ||
var updateMention = this.store.getCommands().updateMention; | ||
var removeMention = this.store.getCommands().removeMention; | ||
var isActive = core.isMarkActive({ | ||
from: range.from, | ||
to: range.end, | ||
type: this.type, | ||
stateOrTransaction: this.store.getState() | ||
}); | ||
var method = isActive ? updateMention : createMention; | ||
var isSplit = suggest.isSplitReason(reason); | ||
var isInvalid = suggest.isInvalidSplitReason(reason); | ||
var isRemoved = suggest.isRemovedReason(reason); | ||
var isSelectionExit = suggest.isSelectionExitReason(reason); | ||
var remove = () => { | ||
setMarkRemoved(); | ||
try { | ||
// This might fail when a deletion has taken place. | ||
isInvalid ? removeMention({ | ||
range | ||
}) : core.noop(); | ||
} catch (_unused) {// This sometimes fails and it's best to ignore until more is | ||
// known about the impact. Please create an issue if this blocks | ||
// you in some way. | ||
} | ||
}; | ||
var update = (_ref4) => { | ||
var _ref4$replacementType = _ref4.replacementType, | ||
replacementType = _ref4$replacementType === void 0 ? isSplit ? 'partial' : 'full' : _ref4$replacementType, | ||
_ref4$id = _ref4.id, | ||
id = _ref4$id === void 0 ? match.queryText[replacementType] : _ref4$id, | ||
_ref4$label = _ref4.label, | ||
label = _ref4$label === void 0 ? match.matchText[replacementType] : _ref4$label, | ||
_ref4$appendText = _ref4.appendText, | ||
appendText = _ref4$appendText === void 0 ? this.options.appendText : _ref4$appendText, | ||
attributes = _objectWithoutProperties(_ref4, ["replacementType", "id", "label", "appendText"]); | ||
method(_objectSpread$1({ | ||
id, | ||
label, | ||
appendText, | ||
replacementType, | ||
name, | ||
range, | ||
keepSelection: isSelectionExit | ||
}, attributes)); | ||
}; | ||
var command = isInvalid || isRemoved ? remove : update; | ||
return command; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* The factory method for mention commands to update and create new mentions. | ||
*/ | ||
createMention(_ref5) { | ||
@@ -351,0 +351,0 @@ var shouldUpdate = _ref5.shouldUpdate; |
@@ -140,6 +140,4 @@ "use strict"; | ||
constructor() { | ||
var _this; | ||
super(...arguments), _this = this, _defineProperty(this, "characterEntryMethods", []), | ||
_defineProperty(this, "keyBindingsList", []), _defineProperty(this, "keyBindings", {}), | ||
_defineProperty(this, "onAddCustomHandler", parameter => { | ||
super(...arguments), _defineProperty(this, "characterEntryMethods", []), _defineProperty(this, "keyBindingsList", []), | ||
_defineProperty(this, "keyBindings", {}), _defineProperty(this, "onAddCustomHandler", parameter => { | ||
var keyBindings = parameter.keyBindings, onCharacterEntry = parameter.onCharacterEntry; | ||
@@ -154,18 +152,3 @@ return keyBindings ? (this.keyBindingsList = [ ...this.keyBindingsList, keyBindings ], | ||
}) : void 0; | ||
}), _defineProperty(this, "createCommands", () => ({ | ||
createMention: this.createMention({ | ||
shouldUpdate: !1 | ||
}), | ||
updateMention: this.createMention({ | ||
shouldUpdate: !0 | ||
}), | ||
removeMention: function() { | ||
var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : core.object(), range = _ref.range; | ||
return core.removeMark({ | ||
type: _this.type, | ||
expand: !0, | ||
range: range | ||
}); | ||
} | ||
})), _defineProperty(this, "createPasteRules", () => this.options.matchers.map(matcher => { | ||
}), _defineProperty(this, "createPasteRules", () => this.options.matchers.map(matcher => { | ||
var _DEFAULT_MATCHER$matc = _objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), startOfLine = _DEFAULT_MATCHER$matc.startOfLine, char = _DEFAULT_MATCHER$matc.char, supportedCharacters = _DEFAULT_MATCHER$matc.supportedCharacters, name = _DEFAULT_MATCHER$matc.name, regexp = new RegExp("(".concat(suggest.getRegexPrefix(startOfLine)).concat(suggest.escapeChar(char)).concat(suggest.regexToString(supportedCharacters), ")"), "g"); | ||
@@ -181,43 +164,2 @@ return core.markPasteRule({ | ||
}); | ||
})), _defineProperty(this, "createSuggestions", () => this.options.matchers.map(matcher => { | ||
var extension = this; | ||
return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), {}, { | ||
get noDecorations() { | ||
return extension.options.noDecorations; | ||
}, | ||
get suggestTag() { | ||
return extension.options.suggestTag; | ||
}, | ||
keyBindings: () => this.keyBindings, | ||
onCharacterEntry: this.onCharacterEntry, | ||
onChange: this.options.onChange, | ||
onExit: this.options.onExit, | ||
createCommand: _ref2 => { | ||
var match = _ref2.match, reason = _ref2.reason, setMarkRemoved = _ref2.setMarkRemoved, range = match.range, name = match.suggester.name, createMention = this.store.getCommands().createMention, updateMention = this.store.getCommands().updateMention, removeMention = this.store.getCommands().removeMention, method = core.isMarkActive({ | ||
from: range.from, | ||
to: range.end, | ||
type: this.type, | ||
stateOrTransaction: this.store.getState() | ||
}) ? updateMention : createMention, isSplit = suggest.isSplitReason(reason), isInvalid = suggest.isInvalidSplitReason(reason), isRemoved = suggest.isRemovedReason(reason), isSelectionExit = suggest.isSelectionExitReason(reason); | ||
return isInvalid || isRemoved ? () => { | ||
setMarkRemoved(); | ||
try { | ||
isInvalid ? removeMention({ | ||
range: range | ||
}) : core.noop(); | ||
} catch (_unused) {} | ||
} : _ref3 => { | ||
var _ref3$replacementType = _ref3.replacementType, replacementType = void 0 === _ref3$replacementType ? isSplit ? "partial" : "full" : _ref3$replacementType, _ref3$id = _ref3.id, id = void 0 === _ref3$id ? match.queryText[replacementType] : _ref3$id, _ref3$label = _ref3.label, label = void 0 === _ref3$label ? match.matchText[replacementType] : _ref3$label, _ref3$appendText = _ref3.appendText, appendText = void 0 === _ref3$appendText ? this.options.appendText : _ref3$appendText, attributes = _objectWithoutProperties(_ref3, [ "replacementType", "id", "label", "appendText" ]); | ||
method(_objectSpread$1({ | ||
id: id, | ||
label: label, | ||
appendText: appendText, | ||
replacementType: replacementType, | ||
name: name, | ||
range: range, | ||
keepSelection: isSelectionExit | ||
}, attributes)); | ||
}; | ||
} | ||
}); | ||
})), _defineProperty(this, "onCharacterEntry", parameter => { | ||
@@ -263,4 +205,4 @@ var _step, _iterator = _createForOfIteratorHelper(this.characterEntryMethods); | ||
toDOM: node => { | ||
var _matcher$mentionClass, _ref4 = node.attrs, id = (_ref4.label, _ref4.id), name = _ref4.name, attributes = (_ref4.replacementType, | ||
_ref4.range, _objectWithoutProperties(_ref4, [ "label", "id", "name", "replacementType", "range" ])), matcher = this.options.matchers.find(matcher => matcher.name === name), mentionClassName = matcher && null !== (_matcher$mentionClass = matcher.mentionClassName) && void 0 !== _matcher$mentionClass ? _matcher$mentionClass : DEFAULT_MATCHER.mentionClassName; | ||
var _matcher$mentionClass, _ref = node.attrs, id = (_ref.label, _ref.id), name = _ref.name, attributes = (_ref.replacementType, | ||
_ref.range, _objectWithoutProperties(_ref, [ "label", "id", "name", "replacementType", "range" ])), matcher = this.options.matchers.find(matcher => matcher.name === name), mentionClassName = matcher && null !== (_matcher$mentionClass = matcher.mentionClassName) && void 0 !== _matcher$mentionClass ? _matcher$mentionClass : DEFAULT_MATCHER.mentionClassName; | ||
return [ this.options.mentionTag, _objectSpread$1(_objectSpread$1(_objectSpread$1({}, extra.dom(node)), attributes), {}, { | ||
@@ -274,2 +216,65 @@ class: name ? "".concat(mentionClassName, " ").concat(mentionClassName, "-").concat(name) : mentionClassName, | ||
} | ||
createCommands() { | ||
var _this = this; | ||
return { | ||
createMention: this.createMention({ | ||
shouldUpdate: !1 | ||
}), | ||
updateMention: this.createMention({ | ||
shouldUpdate: !0 | ||
}), | ||
removeMention: function() { | ||
var _ref2 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : core.object(), range = _ref2.range; | ||
return core.removeMark({ | ||
type: _this.type, | ||
expand: !0, | ||
range: range | ||
}); | ||
} | ||
}; | ||
} | ||
createSuggestions() { | ||
return this.options.matchers.map(matcher => { | ||
var extension = this; | ||
return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), {}, { | ||
get noDecorations() { | ||
return extension.options.noDecorations; | ||
}, | ||
get suggestTag() { | ||
return extension.options.suggestTag; | ||
}, | ||
keyBindings: () => this.keyBindings, | ||
onCharacterEntry: this.onCharacterEntry, | ||
onChange: this.options.onChange, | ||
onExit: this.options.onExit, | ||
createCommand: _ref3 => { | ||
var match = _ref3.match, reason = _ref3.reason, setMarkRemoved = _ref3.setMarkRemoved, range = match.range, name = match.suggester.name, createMention = this.store.getCommands().createMention, updateMention = this.store.getCommands().updateMention, removeMention = this.store.getCommands().removeMention, method = core.isMarkActive({ | ||
from: range.from, | ||
to: range.end, | ||
type: this.type, | ||
stateOrTransaction: this.store.getState() | ||
}) ? updateMention : createMention, isSplit = suggest.isSplitReason(reason), isInvalid = suggest.isInvalidSplitReason(reason), isRemoved = suggest.isRemovedReason(reason), isSelectionExit = suggest.isSelectionExitReason(reason); | ||
return isInvalid || isRemoved ? () => { | ||
setMarkRemoved(); | ||
try { | ||
isInvalid ? removeMention({ | ||
range: range | ||
}) : core.noop(); | ||
} catch (_unused) {} | ||
} : _ref4 => { | ||
var _ref4$replacementType = _ref4.replacementType, replacementType = void 0 === _ref4$replacementType ? isSplit ? "partial" : "full" : _ref4$replacementType, _ref4$id = _ref4.id, id = void 0 === _ref4$id ? match.queryText[replacementType] : _ref4$id, _ref4$label = _ref4.label, label = void 0 === _ref4$label ? match.matchText[replacementType] : _ref4$label, _ref4$appendText = _ref4.appendText, appendText = void 0 === _ref4$appendText ? this.options.appendText : _ref4$appendText, attributes = _objectWithoutProperties(_ref4, [ "replacementType", "id", "label", "appendText" ]); | ||
method(_objectSpread$1({ | ||
id: id, | ||
label: label, | ||
appendText: appendText, | ||
replacementType: replacementType, | ||
name: name, | ||
range: range, | ||
keepSelection: isSelectionExit | ||
}, attributes)); | ||
}; | ||
} | ||
}); | ||
}); | ||
} | ||
createMention(_ref5) { | ||
@@ -276,0 +281,0 @@ var shouldUpdate = _ref5.shouldUpdate; |
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties'; | ||
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty'; | ||
import { bool, isPlainObject, pick, isString, MarkExtension, object, removeMark, markPasteRule, getMatchString, isMarkActive, MarkGroup, isElementDomNode, invariant, ErrorConstant, getMarkRange, replaceText, noop } from '@remirror/core'; | ||
import { bool, isPlainObject, pick, isString, MarkExtension, markPasteRule, getMatchString, MarkGroup, isElementDomNode, object, removeMark, isMarkActive, invariant, ErrorConstant, getMarkRange, replaceText, noop } from '@remirror/core'; | ||
import { DEFAULT_SUGGESTER, getRegexPrefix, escapeChar, regexToString, isSplitReason, isInvalidSplitReason, isRemovedReason, isSelectionExitReason } from '@remirror/pm/suggest'; | ||
@@ -86,6 +86,3 @@ | ||
constructor() { | ||
var _this; | ||
super(...arguments); | ||
_this = this; | ||
@@ -121,34 +118,2 @@ _defineProperty(this, "characterEntryMethods", []); | ||
_defineProperty(this, "createCommands", () => { | ||
return { | ||
/** | ||
* Create a new mention | ||
*/ | ||
createMention: this.createMention({ | ||
shouldUpdate: false | ||
}), | ||
/** | ||
* Update an existing mention. | ||
*/ | ||
updateMention: this.createMention({ | ||
shouldUpdate: true | ||
}), | ||
/** | ||
* Remove the mention(s) at the current selection or provided range. | ||
*/ | ||
removeMention: function removeMention() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : object(), | ||
range = _ref.range; | ||
return removeMark({ | ||
type: _this.type, | ||
expand: true, | ||
range | ||
}); | ||
} | ||
}; | ||
}); | ||
_defineProperty(this, "createPasteRules", () => { | ||
@@ -175,88 +140,2 @@ return this.options.matchers.map(matcher => { | ||
_defineProperty(this, "createSuggestions", () => { | ||
return this.options.matchers.map(matcher => { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
var extension = this; | ||
return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), {}, { | ||
// The following properties are provided as getter so that the | ||
// prosemirror-suggest plugin always references the latest version of | ||
// the suggestion. This is not a good idea and should be fixed in a | ||
// better way soon. | ||
get noDecorations() { | ||
return extension.options.noDecorations; | ||
}, | ||
get suggestTag() { | ||
return extension.options.suggestTag; | ||
}, | ||
keyBindings: () => this.keyBindings, | ||
onCharacterEntry: this.onCharacterEntry, | ||
onChange: this.options.onChange, | ||
onExit: this.options.onExit, | ||
createCommand: (_ref2) => { | ||
var match = _ref2.match, | ||
reason = _ref2.reason, | ||
setMarkRemoved = _ref2.setMarkRemoved; | ||
var range = match.range, | ||
suggester = match.suggester; | ||
var name = suggester.name; | ||
var createMention = this.store.getCommands().createMention; | ||
var updateMention = this.store.getCommands().updateMention; | ||
var removeMention = this.store.getCommands().removeMention; | ||
var isActive = isMarkActive({ | ||
from: range.from, | ||
to: range.end, | ||
type: this.type, | ||
stateOrTransaction: this.store.getState() | ||
}); | ||
var method = isActive ? updateMention : createMention; | ||
var isSplit = isSplitReason(reason); | ||
var isInvalid = isInvalidSplitReason(reason); | ||
var isRemoved = isRemovedReason(reason); | ||
var isSelectionExit = isSelectionExitReason(reason); | ||
var remove = () => { | ||
setMarkRemoved(); | ||
try { | ||
// This might fail when a deletion has taken place. | ||
isInvalid ? removeMention({ | ||
range | ||
}) : noop(); | ||
} catch (_unused) {// This sometimes fails and it's best to ignore until more is | ||
// known about the impact. Please create an issue if this blocks | ||
// you in some way. | ||
} | ||
}; | ||
var update = (_ref3) => { | ||
var _ref3$replacementType = _ref3.replacementType, | ||
replacementType = _ref3$replacementType === void 0 ? isSplit ? 'partial' : 'full' : _ref3$replacementType, | ||
_ref3$id = _ref3.id, | ||
id = _ref3$id === void 0 ? match.queryText[replacementType] : _ref3$id, | ||
_ref3$label = _ref3.label, | ||
label = _ref3$label === void 0 ? match.matchText[replacementType] : _ref3$label, | ||
_ref3$appendText = _ref3.appendText, | ||
appendText = _ref3$appendText === void 0 ? this.options.appendText : _ref3$appendText, | ||
attributes = _objectWithoutProperties(_ref3, ["replacementType", "id", "label", "appendText"]); | ||
method(_objectSpread$1({ | ||
id, | ||
label, | ||
appendText, | ||
replacementType, | ||
name, | ||
range, | ||
keepSelection: isSelectionExit | ||
}, attributes)); | ||
}; | ||
var command = isInvalid || isRemoved ? remove : update; | ||
return command; | ||
} | ||
}); | ||
}); | ||
}); | ||
_defineProperty(this, "onCharacterEntry", parameter => { | ||
@@ -320,9 +199,9 @@ var _iterator = _createForOfIteratorHelper(this.characterEntryMethods), | ||
var _ref4 = node.attrs, | ||
_ = _ref4.label, | ||
id = _ref4.id, | ||
name = _ref4.name, | ||
replacementType = _ref4.replacementType, | ||
range = _ref4.range, | ||
attributes = _objectWithoutProperties(_ref4, ["label", "id", "name", "replacementType", "range"]); | ||
var _ref = node.attrs, | ||
_ = _ref.label, | ||
id = _ref.id, | ||
name = _ref.name, | ||
replacementType = _ref.replacementType, | ||
range = _ref.range, | ||
attributes = _objectWithoutProperties(_ref, ["label", "id", "name", "replacementType", "range"]); | ||
@@ -340,5 +219,126 @@ var matcher = this.options.matchers.find(matcher => matcher.name === name); | ||
createCommands() { | ||
var _this = this; | ||
return { | ||
/** | ||
* Create a new mention | ||
*/ | ||
createMention: this.createMention({ | ||
shouldUpdate: false | ||
}), | ||
/** | ||
* Update an existing mention. | ||
*/ | ||
updateMention: this.createMention({ | ||
shouldUpdate: true | ||
}), | ||
/** | ||
* Remove the mention(s) at the current selection or provided range. | ||
*/ | ||
removeMention: function removeMention() { | ||
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : object(), | ||
range = _ref2.range; | ||
return removeMark({ | ||
type: _this.type, | ||
expand: true, | ||
range | ||
}); | ||
} | ||
}; | ||
} | ||
createSuggestions() { | ||
return this.options.matchers.map(matcher => { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
var extension = this; | ||
return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_MATCHER), matcher), {}, { | ||
// The following properties are provided as getter so that the | ||
// prosemirror-suggest plugin always references the latest version of | ||
// the suggestion. This is not a good idea and should be fixed in a | ||
// better way soon. | ||
get noDecorations() { | ||
return extension.options.noDecorations; | ||
}, | ||
get suggestTag() { | ||
return extension.options.suggestTag; | ||
}, | ||
keyBindings: () => this.keyBindings, | ||
onCharacterEntry: this.onCharacterEntry, | ||
onChange: this.options.onChange, | ||
onExit: this.options.onExit, | ||
createCommand: (_ref3) => { | ||
var match = _ref3.match, | ||
reason = _ref3.reason, | ||
setMarkRemoved = _ref3.setMarkRemoved; | ||
var range = match.range, | ||
suggester = match.suggester; | ||
var name = suggester.name; | ||
var createMention = this.store.getCommands().createMention; | ||
var updateMention = this.store.getCommands().updateMention; | ||
var removeMention = this.store.getCommands().removeMention; | ||
var isActive = isMarkActive({ | ||
from: range.from, | ||
to: range.end, | ||
type: this.type, | ||
stateOrTransaction: this.store.getState() | ||
}); | ||
var method = isActive ? updateMention : createMention; | ||
var isSplit = isSplitReason(reason); | ||
var isInvalid = isInvalidSplitReason(reason); | ||
var isRemoved = isRemovedReason(reason); | ||
var isSelectionExit = isSelectionExitReason(reason); | ||
var remove = () => { | ||
setMarkRemoved(); | ||
try { | ||
// This might fail when a deletion has taken place. | ||
isInvalid ? removeMention({ | ||
range | ||
}) : noop(); | ||
} catch (_unused) {// This sometimes fails and it's best to ignore until more is | ||
// known about the impact. Please create an issue if this blocks | ||
// you in some way. | ||
} | ||
}; | ||
var update = (_ref4) => { | ||
var _ref4$replacementType = _ref4.replacementType, | ||
replacementType = _ref4$replacementType === void 0 ? isSplit ? 'partial' : 'full' : _ref4$replacementType, | ||
_ref4$id = _ref4.id, | ||
id = _ref4$id === void 0 ? match.queryText[replacementType] : _ref4$id, | ||
_ref4$label = _ref4.label, | ||
label = _ref4$label === void 0 ? match.matchText[replacementType] : _ref4$label, | ||
_ref4$appendText = _ref4.appendText, | ||
appendText = _ref4$appendText === void 0 ? this.options.appendText : _ref4$appendText, | ||
attributes = _objectWithoutProperties(_ref4, ["replacementType", "id", "label", "appendText"]); | ||
method(_objectSpread$1({ | ||
id, | ||
label, | ||
appendText, | ||
replacementType, | ||
name, | ||
range, | ||
keepSelection: isSelectionExit | ||
}, attributes)); | ||
}; | ||
var command = isInvalid || isRemoved ? remove : update; | ||
return command; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* The factory method for mention commands to update and create new mentions. | ||
*/ | ||
createMention(_ref5) { | ||
@@ -345,0 +345,0 @@ var shouldUpdate = _ref5.shouldUpdate; |
{ | ||
"name": "@remirror/extension-mention", | ||
"version": "1.0.0-next.10", | ||
"version": "1.0.0-next.11", | ||
"description": "Mention extension for the remirror wysiwyg editor", | ||
@@ -22,7 +22,7 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/@remirror/extension-mention", | ||
"devDependencies": { | ||
"@remirror/core": "^1.0.0-next.10", | ||
"@remirror/core": "^1.0.0-next.11", | ||
"@remirror/pm": "^1.0.0-next.4" | ||
}, | ||
"peerDependencies": { | ||
"@remirror/core": "^1.0.0-next.10", | ||
"@remirror/core": "^1.0.0-next.11", | ||
"@remirror/pm": "^1.0.0-next.4" | ||
@@ -29,0 +29,0 @@ }, |
1438
0.21%71461
-0.08%