@guestbell/react-page-plugins
Version:
Plugins we use in GuestBell for working with amazing react-page package
114 lines (113 loc) • 4.21 kB
JavaScript
import * as React from 'react';
import { QuoteType } from '../../../slate/plugins/quote/quoteType';
import { HeadingType } from '../../../slate/plugins/heading/headingType';
import { ParagraphType } from '../../../slate/plugins/paragraph/withParagraph';
import { ListTypes } from '../../../slate/plugins/lists/listTypes';
import { EmphasizeTypes } from '../../../slate/plugins/emphasize/emphasizeTypes';
import { addAlignmentStyles } from '../../../slate/plugins/alignment/addAlignmentStyles';
import { addFontSizeStyles } from '../../../slate/plugins/fontSize/addFontSizeStyles';
import { defaultConfig } from '../../../slate/plugins/fontSize/fontSizeConfig';
import { LinkType } from '../../../slate/plugins/links/linkType';
import { ColorType } from '../../../slate/plugins/color/colorType';
import { addColorStyles } from '../../../slate/plugins/color';
import { Link as RouterLink } from 'react-router-dom';
import { getPathname, isSamePageUrl } from '../../utils/urlUtil';
var BLOCK_TAGS = {
a: LinkType,
blockquote: QuoteType,
h: HeadingType,
color: ColorType,
p: ParagraphType,
ul: ListTypes.UL,
ol: ListTypes.OL,
li: ListTypes.LI
};
// Add a dictionary of mark tags.
var MARK_TAGS = {
em: EmphasizeTypes.Italic,
strong: EmphasizeTypes.Bold,
u: EmphasizeTypes.Underline
};
var TEXT_RULE = function TEXT_RULE(text) {
var children;
var isWrapped = false;
if (text[MARK_TAGS.em]) {
var _children;
children = /*#__PURE__*/React.createElement("i", null, (_children = children) !== null && _children !== void 0 ? _children : text.text);
isWrapped = true;
}
if (text[MARK_TAGS.strong]) {
var _children2;
children = /*#__PURE__*/React.createElement("b", null, (_children2 = children) !== null && _children2 !== void 0 ? _children2 : text.text);
isWrapped = true;
}
if (text[MARK_TAGS.u]) {
var _children3;
children = /*#__PURE__*/React.createElement("u", null, (_children3 = children) !== null && _children3 !== void 0 ? _children3 : text.text);
isWrapped = true;
}
if (!isWrapped) {
children = /*#__PURE__*/React.createElement("span", null, text.text);
}
return addColorStyles(text, children);
};
var BLOCK_RULE = function BLOCK_RULE(node, children) {
var comp;
switch (node.type) {
case BLOCK_TAGS.a:
if (isSamePageUrl(node.url)) {
return /*#__PURE__*/React.createElement(RouterLink, {
to: getPathname(node.url)
}, children);
} else {
comp = /*#__PURE__*/React.createElement("a", {
href: node.url
}, children);
}
break;
case BLOCK_TAGS.p:
comp = /*#__PURE__*/React.createElement("p", null, children);
break;
case BLOCK_TAGS.p:
comp = /*#__PURE__*/React.createElement("p", null, children);
break;
case BLOCK_TAGS.h:
var level = node.level;
if (level === 2) {
comp = /*#__PURE__*/React.createElement("h2", null, children);
} else if (level === 3) {
comp = /*#__PURE__*/React.createElement("h3", null, children);
} else if (level === 4) {
comp = /*#__PURE__*/React.createElement("h4", null, children);
} else if (level === 5) {
comp = /*#__PURE__*/React.createElement("h5", null, children);
} else if (level === 6) {
comp = /*#__PURE__*/React.createElement("h6", null, children);
} else {
comp = /*#__PURE__*/React.createElement("h1", null, children);
}
break;
case BLOCK_TAGS.blockquote:
comp = /*#__PURE__*/React.createElement("blockquote", null, children);
break;
case BLOCK_TAGS.ol:
comp = /*#__PURE__*/React.createElement("ol", null, children);
break;
case BLOCK_TAGS.ul:
comp = /*#__PURE__*/React.createElement("ul", null, children);
break;
case BLOCK_TAGS.li:
comp = /*#__PURE__*/React.createElement("li", null, children);
break;
default:
comp = /*#__PURE__*/React.createElement("p", null, children);
break;
}
return addFontSizeStyles(defaultConfig, node, addAlignmentStyles(node, comp));
};
var rules = {
textRule: TEXT_RULE,
nodeRule: BLOCK_RULE
};
export default rules;
//# sourceMappingURL=rules.js.map