@taze-editor/taze-plugin-basic-marks
Version:
Basic marks plugin for Taze Editor (includes bold, italic, underline etc.)
236 lines (211 loc) • 5.01 kB
JavaScript
import { createPluginFactory, onKeyDownToggleMark } from '@taze-editor/taze-core';
import React from 'react';
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
const Bold = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("b", _extends({}, props, attributes), children);
const MARK_BOLD = "bold";
/**
* Enables support for bold formatting
*/
const createBoldPlugin = createPluginFactory({
key: MARK_BOLD,
type: MARK_BOLD,
isLeaf: true,
component: Bold,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+b"
}
});
const Code = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("code", _extends({}, props, attributes), children);
const MARK_CODE = "code";
/**
* Enables support for code formatting
*/
const createCodePlugin = createPluginFactory({
key: MARK_CODE,
type: MARK_CODE,
isLeaf: true,
component: Code,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+e"
}
});
const Italic = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("i", _extends({}, props, attributes), children);
const MARK_ITALIC = "italic";
/**
* Enables support for italic formatting.
*/
const createItalicPlugin = createPluginFactory({
key: MARK_ITALIC,
type: MARK_ITALIC,
isLeaf: true,
component: Italic,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+i"
}
});
const Strikethrough = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("s", _extends({}, props, attributes), children);
const MARK_STRIKETHROUGH = "strikethrough";
/**
* Enables support for strikethrough formatting.
*/
const createStrikethroughPlugin = createPluginFactory({
key: MARK_STRIKETHROUGH,
type: MARK_STRIKETHROUGH,
isLeaf: true,
component: Strikethrough,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+shift+x"
}
});
const Subscript = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("sub", _extends({}, props, attributes), children);
const MARK_SUBSCRIPT$1 = "subscript";
const MARK_SUPERSCRIPT$1 = "superscript";
/**
* Enables support for subscript formatting.
*/
const createSubscriptPlugin = createPluginFactory({
key: MARK_SUBSCRIPT$1,
type: MARK_SUBSCRIPT$1,
isLeaf: true,
component: Subscript,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+,",
clear: MARK_SUPERSCRIPT$1
}
});
const Superscript = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("sup", _extends({}, props, attributes), children);
const MARK_SUPERSCRIPT = "superscript";
const MARK_SUBSCRIPT = "subscript";
/**
* Enables support for superscript formatting.
*/
const createSuperscriptPlugin = createPluginFactory({
key: MARK_SUPERSCRIPT,
type: MARK_SUPERSCRIPT,
isLeaf: true,
component: Superscript,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+.",
clear: MARK_SUBSCRIPT
}
});
const Underline = ({
attributes,
children,
text,
leaf,
editor,
nodeProps,
...props
}) => /*#__PURE__*/React.createElement("u", _extends({}, props, attributes), children);
const MARK_UNDERLINE = "underline";
/**
* Enables support for underline formatting.
*/
const createUnderlinePlugin = createPluginFactory({
key: MARK_UNDERLINE,
type: MARK_UNDERLINE,
isLeaf: true,
component: Underline,
handlers: {
onKeyDown: onKeyDownToggleMark
},
options: {
hotkey: "mod+u"
}
});
/**
* Enables support for basic marks:
* - Bold
* - Code
* - Italic
* - Strikethrough
* - Subscript
* - Superscript
* - Underline
*/
const createBasicMarksPlugin = createPluginFactory({
key: "basicMarks",
plugins: [createBoldPlugin(), createCodePlugin(), createItalicPlugin(), createStrikethroughPlugin(), createSubscriptPlugin(), createSuperscriptPlugin(), createUnderlinePlugin()]
});
export { Bold, Code, Italic, MARK_BOLD, MARK_CODE, MARK_ITALIC, MARK_STRIKETHROUGH, MARK_SUBSCRIPT$1 as MARK_SUBSCRIPT, MARK_SUPERSCRIPT, MARK_UNDERLINE, Strikethrough, Subscript, Superscript, Underline, createBasicMarksPlugin, createBoldPlugin, createCodePlugin, createItalicPlugin, createStrikethroughPlugin, createSubscriptPlugin, createSuperscriptPlugin, createUnderlinePlugin };
//# sourceMappingURL=index.es.js.map