dtable-ui-component 0.1.61 → 0.1.65
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.
- package/es/components/cell-formatter/long-text-formatter.js +15 -1
- package/es/utils/normalize-long-text-value.js +76 -49
- package/es/utils/slate2markdown/core.js +172 -0
- package/es/utils/slate2markdown/deserialize.js +645 -0
- package/es/utils/slate2markdown/index.js +4 -0
- package/es/utils/slate2markdown/markdown2html.js +43 -0
- package/es/utils/slate2markdown/serialize.js +415 -0
- package/es/utils/slate2markdown/unified.js +470 -0
- package/es/utils/slate2markdown/vfile.js +48 -0
- package/lib/components/cell-formatter/long-text-formatter.js +15 -1
- package/lib/utils/normalize-long-text-value.js +78 -49
- package/lib/utils/slate2markdown/core.js +172 -0
- package/lib/utils/slate2markdown/deserialize.js +625 -0
- package/lib/utils/slate2markdown/index.js +16 -0
- package/lib/utils/slate2markdown/markdown2html.js +62 -0
- package/lib/utils/slate2markdown/serialize.js +368 -0
- package/lib/utils/slate2markdown/unified.js +470 -0
- package/lib/utils/slate2markdown/vfile.js +48 -0
- package/package.json +23 -4
|
@@ -67,7 +67,21 @@ var LongTextFormatter = /*#__PURE__*/function (_React$Component) {
|
|
|
67
67
|
var valueType = Object.prototype.toString.call(value);
|
|
68
68
|
|
|
69
69
|
if (valueType === '[object String]') {
|
|
70
|
-
|
|
70
|
+
var _getPreviewContent = getPreviewContent(value),
|
|
71
|
+
previewText = _getPreviewContent.previewText,
|
|
72
|
+
images = _getPreviewContent.images,
|
|
73
|
+
links = _getPreviewContent.links,
|
|
74
|
+
checklist = _getPreviewContent.checklist;
|
|
75
|
+
|
|
76
|
+
var validValue = Object.assign({}, {
|
|
77
|
+
text: value,
|
|
78
|
+
preview: previewText,
|
|
79
|
+
images: images,
|
|
80
|
+
links: links,
|
|
81
|
+
checklist: checklist
|
|
82
|
+
});
|
|
83
|
+
console.log(validValue);
|
|
84
|
+
return validValue;
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
if (valueType === '[object Object]') {
|
|
@@ -1,68 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
1
|
+
import { Node } from 'slate';
|
|
2
|
+
import { deserialize } from './slate2markdown';
|
|
3
|
+
|
|
4
|
+
var getPreviewContent = function getPreviewContent(value) {
|
|
5
|
+
console.log('longText Source: ', value);
|
|
6
|
+
var content = deserialize(value);
|
|
7
|
+
var previewContent = {
|
|
8
|
+
previewText: '',
|
|
9
|
+
images: [],
|
|
9
10
|
links: [],
|
|
10
|
-
|
|
11
|
+
checklist: {
|
|
12
|
+
total: 0,
|
|
13
|
+
completed: 0
|
|
14
|
+
}
|
|
11
15
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
getPreviewInfo(content, previewContent);
|
|
17
|
+
getPreviewText(content, previewContent);
|
|
18
|
+
console.log('previewContent: ', previewContent);
|
|
19
|
+
return previewContent;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
var getPreviewInfo = function getPreviewInfo(nodes, previewContent) {
|
|
23
|
+
var nodeIndex = 0;
|
|
24
|
+
|
|
25
|
+
while (nodes && nodeIndex <= nodes.length - 1) {
|
|
26
|
+
var currentNode = nodes[nodeIndex];
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
if (currentNode.type === 'link') {
|
|
29
|
+
previewContent.links.push(currentNode.data.href);
|
|
30
|
+
} else if (currentNode.type === 'image') {
|
|
31
|
+
previewContent.images.push(currentNode.data.src);
|
|
32
|
+
} else if (currentNode.type === 'list_item' && currentNode.data) {
|
|
33
|
+
var data = currentNode.data;
|
|
34
|
+
|
|
35
|
+
if (data.hasOwnProperty('checked')) {
|
|
36
|
+
previewContent.checklist.total += 1;
|
|
37
|
+
|
|
38
|
+
if (data.checked) {
|
|
39
|
+
previewContent.checklist.completed++;
|
|
40
|
+
}
|
|
23
41
|
}
|
|
42
|
+
|
|
43
|
+
getPreviewInfo(currentNode.children, previewContent);
|
|
44
|
+
} else {
|
|
45
|
+
getPreviewInfo(currentNode.children, previewContent);
|
|
24
46
|
}
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
|
|
48
|
+
nodeIndex++;
|
|
49
|
+
}
|
|
27
50
|
};
|
|
28
51
|
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var newMarkdownContent = markdownContent.replace(hrefReg, '');
|
|
52
|
+
var getTextOfNode = function getTextOfNode(node) {
|
|
53
|
+
var text = '';
|
|
32
54
|
|
|
33
|
-
for (var index = 0; index <
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
preview += ' ';
|
|
38
|
-
} else {
|
|
39
|
-
preview += newMarkdownContent[index];
|
|
40
|
-
}
|
|
55
|
+
for (var index = 0; index < node.children.length; index++) {
|
|
56
|
+
var currentNode = node.children[index];
|
|
57
|
+
var data = currentNode.data;
|
|
58
|
+
var type = currentNode.type;
|
|
41
59
|
|
|
42
|
-
if (
|
|
43
|
-
|
|
60
|
+
if (type === 'link') {
|
|
61
|
+
text += '';
|
|
62
|
+
} else if (type === 'list_item') {
|
|
63
|
+
if (data && data.hasOwnProperty('checked')) {
|
|
64
|
+
text += '';
|
|
65
|
+
} else {
|
|
66
|
+
text += Node.text(currentNode) + ' ';
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
if (currentNode.hasOwnProperty('text')) {
|
|
70
|
+
text += currentNode.text;
|
|
71
|
+
} else {
|
|
72
|
+
text += Node.text(currentNode) + ' ';
|
|
73
|
+
}
|
|
44
74
|
}
|
|
45
75
|
}
|
|
46
76
|
|
|
47
|
-
|
|
77
|
+
return text;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var getPreviewText = function getPreviewText(content, previewContent) {
|
|
81
|
+
var previewText = '';
|
|
48
82
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
links = _getLinks.links;
|
|
83
|
+
for (var index = 0; index < content.length; index++) {
|
|
84
|
+
previewText += getTextOfNode(content[index]) + ' ';
|
|
85
|
+
var textLength = previewText.length;
|
|
53
86
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
links: links
|
|
58
|
-
};
|
|
87
|
+
if (textLength >= 150) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
91
|
|
|
61
|
-
|
|
62
|
-
preview: preview,
|
|
63
|
-
images: [],
|
|
64
|
-
links: []
|
|
65
|
-
};
|
|
92
|
+
previewContent.previewText = previewText;
|
|
66
93
|
};
|
|
67
94
|
|
|
68
95
|
export default getPreviewContent;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
|
|
5
|
+
var replace = require('replace-ext');
|
|
6
|
+
|
|
7
|
+
var buffer = require('is-buffer');
|
|
8
|
+
|
|
9
|
+
module.exports = VFile;
|
|
10
|
+
var own = {}.hasOwnProperty;
|
|
11
|
+
var proto = VFile.prototype;
|
|
12
|
+
proto.toString = toString;
|
|
13
|
+
/* Order of setting (least specific to most), we need this because
|
|
14
|
+
* otherwise `{stem: 'a', path: '~/b.js'}` would throw, as a path
|
|
15
|
+
* is needed before a stem can be set. */
|
|
16
|
+
|
|
17
|
+
var order = ['history', 'path', 'basename', 'stem', 'extname', 'dirname'];
|
|
18
|
+
/* Construct a new file. */
|
|
19
|
+
|
|
20
|
+
function VFile(options) {
|
|
21
|
+
var prop;
|
|
22
|
+
var index;
|
|
23
|
+
var length;
|
|
24
|
+
|
|
25
|
+
if (typeof options === 'number') {
|
|
26
|
+
options = options.toString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!options) {
|
|
30
|
+
options = {};
|
|
31
|
+
} else if (typeof options === 'string' || buffer(options)) {
|
|
32
|
+
options = {
|
|
33
|
+
contents: options
|
|
34
|
+
};
|
|
35
|
+
} else if ('message' in options && 'messages' in options) {
|
|
36
|
+
return options;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!(this instanceof VFile)) {
|
|
40
|
+
return new VFile(options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.data = {};
|
|
44
|
+
this.messages = [];
|
|
45
|
+
this.history = [];
|
|
46
|
+
this.cwd = process.cwd();
|
|
47
|
+
/* Set path related properties in the correct order. */
|
|
48
|
+
|
|
49
|
+
index = -1;
|
|
50
|
+
length = order.length;
|
|
51
|
+
|
|
52
|
+
while (++index < length) {
|
|
53
|
+
prop = order[index];
|
|
54
|
+
|
|
55
|
+
if (own.call(options, prop)) {
|
|
56
|
+
this[prop] = options[prop];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/* Set non-path related properties. */
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
for (prop in options) {
|
|
63
|
+
if (order.indexOf(prop) === -1) {
|
|
64
|
+
this[prop] = options[prop];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/* Access full path (`~/index.min.js`). */
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Object.defineProperty(proto, 'path', {
|
|
72
|
+
get: function get() {
|
|
73
|
+
return this.history[this.history.length - 1];
|
|
74
|
+
},
|
|
75
|
+
set: function set(path) {
|
|
76
|
+
assertNonEmpty(path, 'path');
|
|
77
|
+
|
|
78
|
+
if (path !== this.path) {
|
|
79
|
+
this.history.push(path);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
/* Access parent path (`~`). */
|
|
84
|
+
|
|
85
|
+
Object.defineProperty(proto, 'dirname', {
|
|
86
|
+
get: function get() {
|
|
87
|
+
return typeof this.path === 'string' ? path.dirname(this.path) : undefined;
|
|
88
|
+
},
|
|
89
|
+
set: function set(dirname) {
|
|
90
|
+
assertPath(this.path, 'dirname');
|
|
91
|
+
this.path = path.join(dirname || '', this.basename);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
/* Access basename (`index.min.js`). */
|
|
95
|
+
|
|
96
|
+
Object.defineProperty(proto, 'basename', {
|
|
97
|
+
get: function get() {
|
|
98
|
+
return typeof this.path === 'string' ? path.basename(this.path) : undefined;
|
|
99
|
+
},
|
|
100
|
+
set: function set(basename) {
|
|
101
|
+
assertNonEmpty(basename, 'basename');
|
|
102
|
+
assertPart(basename, 'basename');
|
|
103
|
+
this.path = path.join(this.dirname || '', basename);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
/* Access extname (`.js`). */
|
|
107
|
+
|
|
108
|
+
Object.defineProperty(proto, 'extname', {
|
|
109
|
+
get: function get() {
|
|
110
|
+
return typeof this.path === 'string' ? path.extname(this.path) : undefined;
|
|
111
|
+
},
|
|
112
|
+
set: function set(extname) {
|
|
113
|
+
var ext = extname || '';
|
|
114
|
+
assertPart(ext, 'extname');
|
|
115
|
+
assertPath(this.path, 'extname');
|
|
116
|
+
|
|
117
|
+
if (ext) {
|
|
118
|
+
if (ext.charAt(0) !== '.') {
|
|
119
|
+
throw new Error('`extname` must start with `.`');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (ext.indexOf('.', 1) !== -1) {
|
|
123
|
+
throw new Error('`extname` cannot contain multiple dots');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.path = replace(this.path, ext);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
/* Access stem (`index.min`). */
|
|
131
|
+
|
|
132
|
+
Object.defineProperty(proto, 'stem', {
|
|
133
|
+
get: function get() {
|
|
134
|
+
return typeof this.path === 'string' ? path.basename(this.path, this.extname) : undefined;
|
|
135
|
+
},
|
|
136
|
+
set: function set(stem) {
|
|
137
|
+
assertNonEmpty(stem, 'stem');
|
|
138
|
+
assertPart(stem, 'stem');
|
|
139
|
+
this.path = path.join(this.dirname || '', stem + (this.extname || ''));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/* Get the value of the file. */
|
|
143
|
+
|
|
144
|
+
function toString(encoding) {
|
|
145
|
+
var value = this.contents || '';
|
|
146
|
+
return buffer(value) ? value.toString(encoding) : String(value);
|
|
147
|
+
}
|
|
148
|
+
/* Assert that `part` is not a path (i.e., does
|
|
149
|
+
* not contain `path.sep`). */
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function assertPart(part, name) {
|
|
153
|
+
if (part.indexOf(path.sep) !== -1) {
|
|
154
|
+
throw new Error('`' + name + '` cannot be a path: did not expect `' + path.sep + '`');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/* Assert that `part` is not empty. */
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
function assertNonEmpty(part, name) {
|
|
161
|
+
if (!part) {
|
|
162
|
+
throw new Error('`' + name + '` cannot be empty');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/* Assert `path` exists. */
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
function assertPath(path, name) {
|
|
169
|
+
if (!path) {
|
|
170
|
+
throw new Error('Setting `' + name + '` requires `path` to be set too');
|
|
171
|
+
}
|
|
172
|
+
}
|