dtable-ui-component 0.1.71 → 0.1.75-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React, { Component } from 'react';
6
+ import { processor } from '../../../../utils/markdown2html';
7
+
8
+ var HtmlLongTextFormatter = /*#__PURE__*/function (_Component) {
9
+ _inherits(HtmlLongTextFormatter, _Component);
10
+
11
+ var _super = _createSuper(HtmlLongTextFormatter);
12
+
13
+ function HtmlLongTextFormatter(_props) {
14
+ var _this;
15
+
16
+ _classCallCheck(this, HtmlLongTextFormatter);
17
+
18
+ _this = _super.call(this, _props);
19
+
20
+ _this.translateValue = function (props) {
21
+ var value = props.value;
22
+
23
+ if (!value) {
24
+ _this.setState({
25
+ innerHtml: null
26
+ });
27
+
28
+ return;
29
+ }
30
+
31
+ var valueType = Object.prototype.toString.call(value);
32
+
33
+ if (valueType === '[object String]') {
34
+ _this.convertMarkdown(value);
35
+
36
+ return;
37
+ }
38
+
39
+ if (valueType === '[object Object]') {
40
+ _this.convertMarkdown(value.text);
41
+
42
+ return;
43
+ }
44
+
45
+ return;
46
+ };
47
+
48
+ _this.convertMarkdown = function (mdFile) {
49
+ processor.process(mdFile).then(function (result) {
50
+ var innerHtml = String(result).replace(/<a /ig, '<a target="_blank" ');
51
+
52
+ _this.setState({
53
+ innerHtml: innerHtml
54
+ });
55
+ });
56
+ };
57
+
58
+ _this.state = {
59
+ innerHtml: null
60
+ };
61
+ return _this;
62
+ }
63
+
64
+ _createClass(HtmlLongTextFormatter, [{
65
+ key: "componentDidMount",
66
+ value: function componentDidMount() {
67
+ this.translateValue(this.props);
68
+ }
69
+ }, {
70
+ key: "UNSAFE_componentWillReceiveProps",
71
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
72
+ var value = this.props.value;
73
+
74
+ if (nextProps.value !== value) {
75
+ this.translateValue(nextProps);
76
+ }
77
+ }
78
+ }, {
79
+ key: "render",
80
+ value: function render() {
81
+ var innerHtml = this.state.innerHtml;
82
+ var className = this.props.className;
83
+ if (!innerHtml) return null;
84
+ return /*#__PURE__*/React.createElement("div", {
85
+ className: "".concat(className, " article"),
86
+ dangerouslySetInnerHTML: {
87
+ __html: innerHtml
88
+ }
89
+ });
90
+ }
91
+ }]);
92
+
93
+ return HtmlLongTextFormatter;
94
+ }(Component);
95
+
96
+ export default HtmlLongTextFormatter;
@@ -0,0 +1,104 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+ import getPreviewContent from '../../../../utils/normalize-long-text-value';
7
+
8
+ var SimpleLongTextFormatter = /*#__PURE__*/function (_React$Component) {
9
+ _inherits(SimpleLongTextFormatter, _React$Component);
10
+
11
+ var _super = _createSuper(SimpleLongTextFormatter);
12
+
13
+ function SimpleLongTextFormatter() {
14
+ var _this;
15
+
16
+ _classCallCheck(this, SimpleLongTextFormatter);
17
+
18
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
19
+ args[_key] = arguments[_key];
20
+ }
21
+
22
+ _this = _super.call.apply(_super, [this].concat(args));
23
+
24
+ _this.renderLinks = function (value) {
25
+ var links = value.links;
26
+ if (!Array.isArray(links) || links.length === 0) return null;
27
+ return /*#__PURE__*/React.createElement("span", {
28
+ className: "long-text-links"
29
+ }, /*#__PURE__*/React.createElement("i", {
30
+ className: "dtable-font dtable-icon-url"
31
+ }), links.length);
32
+ };
33
+
34
+ _this.renderCheckList = function (value) {
35
+ var checkList = value.checklist;
36
+ if (!checkList || checkList.total === 0) return null;
37
+ return /*#__PURE__*/React.createElement("span", {
38
+ className: "long-text-check-list"
39
+ }, /*#__PURE__*/React.createElement("i", {
40
+ className: "dtable-font dtable-icon-check-square-solid ".concat(checkList.completed === checkList.total ? 'long-text-check-list-completed' : '')
41
+ }), "".concat(checkList.completed, "/").concat(checkList.total));
42
+ };
43
+
44
+ _this.renderImages = function (value) {
45
+ var images = value.images;
46
+ if (!Array.isArray(images) || images.length === 0) return null;
47
+ return /*#__PURE__*/React.createElement("span", {
48
+ className: "long-text-images"
49
+ }, /*#__PURE__*/React.createElement("img", {
50
+ src: images[0],
51
+ alt: ""
52
+ }), /*#__PURE__*/React.createElement("i", {
53
+ className: "image-number"
54
+ }, images.length > 1 ? '+' + images.length : null));
55
+ };
56
+
57
+ _this.renderContent = function (value) {
58
+ return /*#__PURE__*/React.createElement("span", {
59
+ className: "long-text-content"
60
+ }, value.preview);
61
+ };
62
+
63
+ _this.translateValue = function () {
64
+ var value = _this.props.value;
65
+ if (!value) return {};
66
+ var valueType = Object.prototype.toString.call(value);
67
+
68
+ if (valueType === '[object String]') {
69
+ return getPreviewContent(value);
70
+ }
71
+
72
+ if (valueType === '[object Object]') {
73
+ return value;
74
+ }
75
+
76
+ return {};
77
+ };
78
+
79
+ return _this;
80
+ }
81
+
82
+ _createClass(SimpleLongTextFormatter, [{
83
+ key: "render",
84
+ value: function render() {
85
+ var className = this.props.className;
86
+ var value = this.translateValue();
87
+ return /*#__PURE__*/React.createElement("div", {
88
+ className: className
89
+ }, this.renderLinks(value), this.renderCheckList(value), this.renderImages(value), this.renderContent(value));
90
+ }
91
+ }]);
92
+
93
+ return SimpleLongTextFormatter;
94
+ }(React.Component);
95
+
96
+ SimpleLongTextFormatter.defaultProps = {
97
+ value: {
98
+ text: '',
99
+ images: [],
100
+ links: [],
101
+ preview: ''
102
+ }
103
+ };
104
+ export default SimpleLongTextFormatter;
@@ -64,6 +64,12 @@
64
64
  white-space: nowrap;
65
65
  }
66
66
 
67
+ .dtable-ui.long-text-formatter.article {
68
+ display: block;
69
+ height: auto;
70
+ overflow: auto;
71
+ }
72
+
67
73
  .dtable-ui.long-text-formatter .long-text-links,
68
74
  .dtable-ui.long-text-formatter .long-text-check-list {
69
75
  display: inline-block;
@@ -0,0 +1,62 @@
1
+ var unified = require('./unified');
2
+
3
+ var markdown = require('remark-parse');
4
+
5
+ var slug = require('remark-slug');
6
+
7
+ var breaks = require('remark-breaks');
8
+
9
+ var remark2rehype = require('remark-rehype');
10
+
11
+ var format = require('rehype-format');
12
+
13
+ var raw = require('rehype-raw');
14
+
15
+ var xtend = require('xtend');
16
+
17
+ var toHTML = require('hast-util-to-html');
18
+
19
+ var sanitize = require('hast-util-sanitize');
20
+
21
+ var gh = require('hast-util-sanitize/lib/github');
22
+
23
+ var deepmerge = require('deepmerge').default;
24
+
25
+ var mathjax = require('rehype-mathjax/browser');
26
+
27
+ var math = require('remark-math/block');
28
+
29
+ function stringify(config) {
30
+ var settings = xtend(config, this.data('settings'));
31
+ var schema = deepmerge(gh, {
32
+ 'attributes': {
33
+ 'input': ['type'],
34
+ 'li': ['className'],
35
+ 'code': ['className'],
36
+ 'span': ['className'],
37
+ 'div': ['className']
38
+ },
39
+ 'tagNames': ['input', 'code', 'span', 'div']
40
+ });
41
+ this.Compiler = compiler;
42
+
43
+ function compiler(tree) {
44
+ // use sanity to remove dangerous html, the default is
45
+ // GitHub style sanitation
46
+ var hast = sanitize(tree, schema);
47
+ return toHTML(hast, settings);
48
+ }
49
+ } // markdown -> mdast -> html AST -> html
50
+
51
+
52
+ var processor = unified().use(markdown, {
53
+ commonmark: true
54
+ }).use(math).use(breaks).use(slug).use(remark2rehype, {
55
+ allowDangerousHTML: true
56
+ }).use(mathjax, {
57
+ displayMath: ['$$', '$$']
58
+ }).use(raw).use(format).use(stringify);
59
+ var processorGetAST = unified().use(markdown, {
60
+ commonmark: true
61
+ }).use(slug);
62
+ export { processor, processorGetAST };
@@ -1,8 +1,8 @@
1
- var hrefReg = /\[.+\]\(\S+\)|<img src=(\S+).+\/>|!\[\]\(\S+\)|<\S+>/g,
2
- imageReg1 = /^<img src="(\S+)" .+\/>/,
3
- imageReg2 = /^!\[\]\((\S+)\)/,
4
- linkReg1 = /^\[.+\]\(\S+\)/,
5
- linkReg2 = /^<\S+>$/;
1
+ var hrefReg = /\[.+\]\(\S+\)|<img src=(\S+).+\/>|!\[\]\(\S+\)|<\S+>/g;
2
+ var imageReg1 = /^<img( width=[\\|/|"](\d)+[\\|/|"])? src="(\S+)" .?\/>/;
3
+ var imageReg2 = /^!\[\]\((\S+)\)/;
4
+ var linkReg1 = /^\[.+\]\(\S+\)/;
5
+ var linkReg2 = /^<\S+>$/;
6
6
 
7
7
  var getLinks = function getLinks(hrefList) {
8
8
  var hrefObj = {
@@ -39,7 +39,7 @@ var getPreviewContent = function getPreviewContent(markdownContent) {
39
39
  preview += newMarkdownContent[index];
40
40
  }
41
41
 
42
- if (preview.length === 30) {
42
+ if (preview.length === 150) {
43
43
  break;
44
44
  }
45
45
  }
@@ -61,7 +61,8 @@ var getPreviewContent = function getPreviewContent(markdownContent) {
61
61
  return {
62
62
  preview: preview,
63
63
  images: [],
64
- links: []
64
+ links: [],
65
+ text: markdownContent
65
66
  };
66
67
  };
67
68