@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
27 lines • 1.41 kB
JavaScript
import { InputRule } from '../prosemirror';
export function defaultInputRuleHandler(inputRule) {
var originalHandler = inputRule.handler;
inputRule.handler = function (state, match, start, end) {
// Skip any input rule inside code
// https://product-fabric.atlassian.net/wiki/spaces/E/pages/37945345/Editor+content+feature+rules#Editorcontent/featurerules-Rawtextblocks
if (state.selection.$from.parent.type.spec.code) {
return;
}
return originalHandler(state, match, start, end);
};
return inputRule;
}
export function createInputRule(match, handler) {
return defaultInputRuleHandler(new InputRule(match, handler));
}
// ProseMirror uses the Unicode Character 'OBJECT REPLACEMENT CHARACTER' (U+FFFC) as text representation for
// leaf nodes, i.e. nodes that don't have any content or text property (e.g. hardBreak, emoji, mention, rule)
// It was introduced because of https://github.com/ProseMirror/prosemirror/issues/262
// This can be used in an input rule regex to be able to include or exclude such nodes.
export var leafNodeReplacementCharacter = '\ufffc';
// tslint:disable:no-bitwise
export var uuid = function () { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
}); };
//# sourceMappingURL=utils.js.map