dtable-ui-component 4.4.2 → 4.4.3-1
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/lib/DTableFiltersPopover/widgets/filter-list/index.css +21 -0
- package/lib/HtmlLongTextFormatter/index.js +1 -1
- package/package.json +2 -19
- package/lib/HtmlLongTextFormatter/markdown2html.js +0 -47
- package/lib/HtmlLongTextFormatter/unified/index.js +0 -400
- package/lib/HtmlLongTextFormatter/vfile/core.js +0 -155
- package/lib/HtmlLongTextFormatter/vfile/index.js +0 -40
|
@@ -211,6 +211,7 @@
|
|
|
211
211
|
.filters-list .multiple-option-name {
|
|
212
212
|
display: flex;
|
|
213
213
|
align-items: center;
|
|
214
|
+
justify-content: space-between;
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
.filters-list .multiple-check-icon,
|
|
@@ -319,3 +320,23 @@
|
|
|
319
320
|
color: #aaa;
|
|
320
321
|
cursor: default;
|
|
321
322
|
}
|
|
323
|
+
|
|
324
|
+
.option.option-active .filter-header-icon .dtable-font {
|
|
325
|
+
color: #fff;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.filters-list .single-select-option,
|
|
329
|
+
.filters-list .multiple-select-option {
|
|
330
|
+
display: block;
|
|
331
|
+
text-align: left;
|
|
332
|
+
width: min-content;
|
|
333
|
+
max-width: 150px;
|
|
334
|
+
line-height: 20px;
|
|
335
|
+
border-radius: 10px;
|
|
336
|
+
padding: 0px 10px;
|
|
337
|
+
margin: 0;
|
|
338
|
+
font-size: 13px;
|
|
339
|
+
overflow: hidden;
|
|
340
|
+
text-overflow: ellipsis;
|
|
341
|
+
white-space: nowrap;
|
|
342
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
|
-
import { processor } from '
|
|
3
|
+
import { processor } from '@seafile/seafile-editor';
|
|
4
4
|
import './index.css';
|
|
5
5
|
class HtmlLongTextFormatter extends Component {
|
|
6
6
|
constructor(_props) {
|
package/package.json
CHANGED
|
@@ -1,39 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtable-ui-component",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.3-1",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@seafile/react-image-lightbox": "2.0.5",
|
|
7
7
|
"@seafile/seafile-calendar": "0.0.24",
|
|
8
8
|
"@seafile/seafile-editor": "0.3.146",
|
|
9
9
|
"antd-mobile": "2.3.1",
|
|
10
|
-
"bail": "1.0.5",
|
|
11
10
|
"classnames": "^2.3.2",
|
|
12
11
|
"dayjs": "1.10.7",
|
|
13
|
-
"deepmerge": "^2.1.0",
|
|
14
12
|
"dtable-utils": "4.4.0",
|
|
15
|
-
"hast-util-sanitize": "^1.1.2",
|
|
16
|
-
"hast-util-to-html": "3.1.0",
|
|
17
13
|
"is-hotkey": "0.2.0",
|
|
18
14
|
"react": "17.0.2",
|
|
19
15
|
"react-app-polyfill": "^3.0.0",
|
|
20
16
|
"react-dom": "17.0.2",
|
|
21
17
|
"react-responsive": "9.0.2",
|
|
22
18
|
"react-select": "5.7.0",
|
|
23
|
-
"react-transition-group": "^4.4.1"
|
|
24
|
-
"reactstrap": "8.9.0",
|
|
25
|
-
"rehype-format": "^2.2.0",
|
|
26
|
-
"rehype-mathjax": "^2.0.0",
|
|
27
|
-
"rehype-raw": "^2.0.0",
|
|
28
|
-
"remark-breaks": "^1.0.0",
|
|
29
|
-
"remark-math": "^3.0.0",
|
|
30
|
-
"remark-parse": "^5.0.0",
|
|
31
|
-
"remark-rehype": "^3.0.0",
|
|
32
|
-
"remark-slug": "^5.0.0",
|
|
33
|
-
"trough": "1.0.5",
|
|
34
|
-
"vfile": "2.3.0",
|
|
35
|
-
"x-is-string": "0.1.0",
|
|
36
|
-
"xtend": "^4.0.1"
|
|
19
|
+
"react-transition-group": "^4.4.1"
|
|
37
20
|
},
|
|
38
21
|
"scripts": {
|
|
39
22
|
"lint": "./node_modules/.bin/eslint ./src/ --fix",
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
var markdown = require('remark-parse');
|
|
2
|
-
var slug = require('remark-slug');
|
|
3
|
-
var breaks = require('remark-breaks');
|
|
4
|
-
var remark2rehype = require('remark-rehype');
|
|
5
|
-
var format = require('rehype-format');
|
|
6
|
-
var raw = require('rehype-raw');
|
|
7
|
-
var xtend = require('xtend');
|
|
8
|
-
var toHTML = require('hast-util-to-html');
|
|
9
|
-
var sanitize = require('hast-util-sanitize');
|
|
10
|
-
var gh = require('hast-util-sanitize/lib/github');
|
|
11
|
-
var deepmerge = require('deepmerge').default;
|
|
12
|
-
const mathjax = require('rehype-mathjax/browser');
|
|
13
|
-
const math = require('remark-math/block');
|
|
14
|
-
var unified = require('./unified').default;
|
|
15
|
-
function stringify(config) {
|
|
16
|
-
var settings = xtend(config, this.data('settings'));
|
|
17
|
-
var schema = deepmerge(gh, {
|
|
18
|
-
'attributes': {
|
|
19
|
-
'input': ['type'],
|
|
20
|
-
'li': ['className'],
|
|
21
|
-
'code': ['className'],
|
|
22
|
-
'span': ['className'],
|
|
23
|
-
'div': ['className']
|
|
24
|
-
},
|
|
25
|
-
'tagNames': ['input', 'code', 'span', 'div']
|
|
26
|
-
});
|
|
27
|
-
this.Compiler = compiler;
|
|
28
|
-
function compiler(tree) {
|
|
29
|
-
// use sanity to remove dangerous html, the default is
|
|
30
|
-
// GitHub style sanitation
|
|
31
|
-
var hast = sanitize(tree, schema);
|
|
32
|
-
return toHTML(hast, settings);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// markdown -> mdast -> html AST -> html
|
|
37
|
-
var processor = unified().use(markdown, {
|
|
38
|
-
commonmark: true
|
|
39
|
-
}).use(math).use(breaks).use(slug).use(remark2rehype, {
|
|
40
|
-
allowDangerousHTML: true
|
|
41
|
-
}).use(mathjax, {
|
|
42
|
-
displayMath: ['$$', '$$']
|
|
43
|
-
}).use(raw).use(format).use(stringify);
|
|
44
|
-
var processorGetAST = unified().use(markdown, {
|
|
45
|
-
commonmark: true
|
|
46
|
-
}).use(slug);
|
|
47
|
-
export { processor, processorGetAST };
|
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/* Dependencies. */
|
|
5
|
-
var extend = require('extend');
|
|
6
|
-
var bail = require('bail');
|
|
7
|
-
var trough = require('trough');
|
|
8
|
-
var string = require('x-is-string');
|
|
9
|
-
var plain = require('is-plain-obj');
|
|
10
|
-
var vfile = require('../vfile').default;
|
|
11
|
-
var slice = [].slice;
|
|
12
|
-
var own = {}.hasOwnProperty;
|
|
13
|
-
|
|
14
|
-
/* Process pipeline. */
|
|
15
|
-
var pipeline = trough().use(pipelineParse).use(pipelineRun).use(pipelineStringify);
|
|
16
|
-
function pipelineParse(p, ctx) {
|
|
17
|
-
ctx.tree = p.parse(ctx.file);
|
|
18
|
-
}
|
|
19
|
-
function pipelineRun(p, ctx, next) {
|
|
20
|
-
p.run(ctx.tree, ctx.file, done);
|
|
21
|
-
function done(err, tree, file) {
|
|
22
|
-
if (err) {
|
|
23
|
-
next(err);
|
|
24
|
-
} else {
|
|
25
|
-
ctx.tree = tree;
|
|
26
|
-
ctx.file = file;
|
|
27
|
-
next();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function pipelineStringify(p, ctx) {
|
|
32
|
-
ctx.file.contents = p.stringify(ctx.tree, ctx.file);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/* Function to create the first processor. */
|
|
36
|
-
function unified() {
|
|
37
|
-
var attachers = [];
|
|
38
|
-
var transformers = trough();
|
|
39
|
-
var namespace = {};
|
|
40
|
-
var frozen = false;
|
|
41
|
-
var freezeIndex = -1;
|
|
42
|
-
|
|
43
|
-
/* Data management. */
|
|
44
|
-
processor.data = data;
|
|
45
|
-
|
|
46
|
-
/* Lock. */
|
|
47
|
-
processor.freeze = freeze;
|
|
48
|
-
|
|
49
|
-
/* Plug-ins. */
|
|
50
|
-
processor.attachers = attachers;
|
|
51
|
-
processor.use = use;
|
|
52
|
-
|
|
53
|
-
/* API. */
|
|
54
|
-
processor.parse = parse;
|
|
55
|
-
processor.stringify = stringify;
|
|
56
|
-
processor.run = run;
|
|
57
|
-
processor.runSync = runSync;
|
|
58
|
-
processor.process = process;
|
|
59
|
-
processor.processSync = processSync;
|
|
60
|
-
|
|
61
|
-
/* Expose. */
|
|
62
|
-
return processor;
|
|
63
|
-
|
|
64
|
-
/* Create a new processor based on the processor
|
|
65
|
-
* in the current scope. */
|
|
66
|
-
function processor() {
|
|
67
|
-
var destination = unified();
|
|
68
|
-
var length = attachers.length;
|
|
69
|
-
var index = -1;
|
|
70
|
-
while (++index < length) {
|
|
71
|
-
destination.use.apply(null, attachers[index]);
|
|
72
|
-
}
|
|
73
|
-
destination.data(extend(true, {}, namespace));
|
|
74
|
-
return destination;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* Freeze: used to signal a processor that has finished
|
|
78
|
-
* configuration.
|
|
79
|
-
*
|
|
80
|
-
* For example, take unified itself. It’s frozen.
|
|
81
|
-
* Plug-ins should not be added to it. Rather, it should
|
|
82
|
-
* be extended, by invoking it, before modifying it.
|
|
83
|
-
*
|
|
84
|
-
* In essence, always invoke this when exporting a
|
|
85
|
-
* processor. */
|
|
86
|
-
function freeze() {
|
|
87
|
-
var values;
|
|
88
|
-
var plugin;
|
|
89
|
-
var options;
|
|
90
|
-
var transformer;
|
|
91
|
-
if (frozen) {
|
|
92
|
-
return processor;
|
|
93
|
-
}
|
|
94
|
-
while (++freezeIndex < attachers.length) {
|
|
95
|
-
values = attachers[freezeIndex];
|
|
96
|
-
plugin = values[0];
|
|
97
|
-
options = values[1];
|
|
98
|
-
transformer = null;
|
|
99
|
-
if (options === false) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (options === true) {
|
|
103
|
-
values[1] = undefined;
|
|
104
|
-
}
|
|
105
|
-
transformer = plugin.apply(processor, values.slice(1));
|
|
106
|
-
if (typeof transformer === 'function') {
|
|
107
|
-
transformers.use(transformer);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
frozen = true;
|
|
111
|
-
freezeIndex = Infinity;
|
|
112
|
-
return processor;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* Data management.
|
|
116
|
-
* Getter / setter for processor-specific informtion. */
|
|
117
|
-
function data(key, value) {
|
|
118
|
-
if (string(key)) {
|
|
119
|
-
/* Set `key`. */
|
|
120
|
-
if (arguments.length === 2) {
|
|
121
|
-
assertUnfrozen('data', frozen);
|
|
122
|
-
namespace[key] = value;
|
|
123
|
-
return processor;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/* Get `key`. */
|
|
127
|
-
return own.call(namespace, key) && namespace[key] || null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/* Set space. */
|
|
131
|
-
if (key) {
|
|
132
|
-
assertUnfrozen('data', frozen);
|
|
133
|
-
namespace = key;
|
|
134
|
-
return processor;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/* Get space. */
|
|
138
|
-
return namespace;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/* Plug-in management.
|
|
142
|
-
*
|
|
143
|
-
* Pass it:
|
|
144
|
-
* * an attacher and options,
|
|
145
|
-
* * a preset,
|
|
146
|
-
* * a list of presets, attachers, and arguments (list
|
|
147
|
-
* of attachers and options). */
|
|
148
|
-
function use(value) {
|
|
149
|
-
var settings;
|
|
150
|
-
assertUnfrozen('use', frozen);
|
|
151
|
-
if (value === null || value === undefined) {
|
|
152
|
-
/* Empty */
|
|
153
|
-
} else if (typeof value === 'function') {
|
|
154
|
-
addPlugin.apply(null, arguments);
|
|
155
|
-
} else if (typeof value === 'object') {
|
|
156
|
-
if ('length' in value) {
|
|
157
|
-
addList(value);
|
|
158
|
-
} else {
|
|
159
|
-
addPreset(value);
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
throw new Error('Expected usable value, not `' + value + '`');
|
|
163
|
-
}
|
|
164
|
-
if (settings) {
|
|
165
|
-
namespace.settings = extend(namespace.settings || {}, settings);
|
|
166
|
-
}
|
|
167
|
-
return processor;
|
|
168
|
-
function addPreset(result) {
|
|
169
|
-
addList(result.plugins);
|
|
170
|
-
if (result.settings) {
|
|
171
|
-
settings = extend(settings || {}, result.settings);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function add(value) {
|
|
175
|
-
if (typeof value === 'function') {
|
|
176
|
-
addPlugin(value);
|
|
177
|
-
} else if (typeof value === 'object') {
|
|
178
|
-
if ('length' in value) {
|
|
179
|
-
addPlugin.apply(null, value);
|
|
180
|
-
} else {
|
|
181
|
-
addPreset(value);
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
throw new Error('Expected usable value, not `' + value + '`');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function addList(plugins) {
|
|
188
|
-
var length;
|
|
189
|
-
var index;
|
|
190
|
-
if (plugins === null || plugins === undefined) {
|
|
191
|
-
/* Empty */
|
|
192
|
-
} else if (typeof plugins === 'object' && 'length' in plugins) {
|
|
193
|
-
length = plugins.length;
|
|
194
|
-
index = -1;
|
|
195
|
-
while (++index < length) {
|
|
196
|
-
add(plugins[index]);
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
throw new Error('Expected a list of plugins, not `' + plugins + '`');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
function addPlugin(plugin, value) {
|
|
203
|
-
var entry = find(plugin);
|
|
204
|
-
if (entry) {
|
|
205
|
-
if (plain(entry[1]) && plain(value)) {
|
|
206
|
-
value = extend(entry[1], value);
|
|
207
|
-
}
|
|
208
|
-
entry[1] = value;
|
|
209
|
-
} else {
|
|
210
|
-
attachers.push(slice.call(arguments));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function find(plugin) {
|
|
215
|
-
var length = attachers.length;
|
|
216
|
-
var index = -1;
|
|
217
|
-
var entry;
|
|
218
|
-
while (++index < length) {
|
|
219
|
-
entry = attachers[index];
|
|
220
|
-
if (entry[0] === plugin) {
|
|
221
|
-
return entry;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/* Parse a file (in string or VFile representation)
|
|
227
|
-
* into a Unist node using the `Parser` on the
|
|
228
|
-
* processor. */
|
|
229
|
-
function parse(doc) {
|
|
230
|
-
var file = vfile(doc);
|
|
231
|
-
var Parser;
|
|
232
|
-
freeze();
|
|
233
|
-
Parser = processor.Parser;
|
|
234
|
-
assertParser('parse', Parser);
|
|
235
|
-
if (newable(Parser)) {
|
|
236
|
-
return new Parser(String(file), file).parse();
|
|
237
|
-
}
|
|
238
|
-
return Parser(String(file), file); // eslint-disable-line new-cap
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/* Run transforms on a Unist node representation of a file
|
|
242
|
-
* (in string or VFile representation), async. */
|
|
243
|
-
function run(node, file, cb) {
|
|
244
|
-
assertNode(node);
|
|
245
|
-
freeze();
|
|
246
|
-
if (!cb && typeof file === 'function') {
|
|
247
|
-
cb = file;
|
|
248
|
-
file = null;
|
|
249
|
-
}
|
|
250
|
-
if (!cb) {
|
|
251
|
-
return new Promise(executor);
|
|
252
|
-
}
|
|
253
|
-
executor(null, cb);
|
|
254
|
-
function executor(resolve, reject) {
|
|
255
|
-
transformers.run(node, vfile(file), done);
|
|
256
|
-
function done(err, tree, file) {
|
|
257
|
-
tree = tree || node;
|
|
258
|
-
if (err) {
|
|
259
|
-
reject(err);
|
|
260
|
-
} else if (resolve) {
|
|
261
|
-
resolve(tree);
|
|
262
|
-
} else {
|
|
263
|
-
cb(null, tree, file);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/* Run transforms on a Unist node representation of a file
|
|
270
|
-
* (in string or VFile representation), sync. */
|
|
271
|
-
function runSync(node, file) {
|
|
272
|
-
var complete = false;
|
|
273
|
-
var result;
|
|
274
|
-
run(node, file, done);
|
|
275
|
-
assertDone('runSync', 'run', complete);
|
|
276
|
-
return result;
|
|
277
|
-
function done(err, tree) {
|
|
278
|
-
complete = true;
|
|
279
|
-
bail(err);
|
|
280
|
-
result = tree;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/* Stringify a Unist node representation of a file
|
|
285
|
-
* (in string or VFile representation) into a string
|
|
286
|
-
* using the `Compiler` on the processor. */
|
|
287
|
-
function stringify(node, doc) {
|
|
288
|
-
var file = vfile(doc);
|
|
289
|
-
var Compiler;
|
|
290
|
-
freeze();
|
|
291
|
-
Compiler = processor.Compiler;
|
|
292
|
-
assertCompiler('stringify', Compiler);
|
|
293
|
-
assertNode(node);
|
|
294
|
-
if (newable(Compiler)) {
|
|
295
|
-
return new Compiler(node, file).compile();
|
|
296
|
-
}
|
|
297
|
-
return Compiler(node, file); // eslint-disable-line new-cap
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/* Parse a file (in string or VFile representation)
|
|
301
|
-
* into a Unist node using the `Parser` on the processor,
|
|
302
|
-
* then run transforms on that node, and compile the
|
|
303
|
-
* resulting node using the `Compiler` on the processor,
|
|
304
|
-
* and store that result on the VFile. */
|
|
305
|
-
function process(doc, cb) {
|
|
306
|
-
freeze();
|
|
307
|
-
assertParser('process', processor.Parser);
|
|
308
|
-
assertCompiler('process', processor.Compiler);
|
|
309
|
-
if (!cb) {
|
|
310
|
-
return new Promise(executor);
|
|
311
|
-
}
|
|
312
|
-
executor(null, cb);
|
|
313
|
-
function executor(resolve, reject) {
|
|
314
|
-
var file = vfile(doc);
|
|
315
|
-
pipeline.run(processor, {
|
|
316
|
-
file: file
|
|
317
|
-
}, done);
|
|
318
|
-
function done(err) {
|
|
319
|
-
if (err) {
|
|
320
|
-
reject(err);
|
|
321
|
-
} else if (resolve) {
|
|
322
|
-
resolve(file);
|
|
323
|
-
} else {
|
|
324
|
-
cb(null, file);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/* Process the given document (in string or VFile
|
|
331
|
-
* representation), sync. */
|
|
332
|
-
function processSync(doc) {
|
|
333
|
-
var complete = false;
|
|
334
|
-
var file;
|
|
335
|
-
freeze();
|
|
336
|
-
assertParser('processSync', processor.Parser);
|
|
337
|
-
assertCompiler('processSync', processor.Compiler);
|
|
338
|
-
file = vfile(doc);
|
|
339
|
-
process(file, done);
|
|
340
|
-
assertDone('processSync', 'process', complete);
|
|
341
|
-
return file;
|
|
342
|
-
function done(err) {
|
|
343
|
-
complete = true;
|
|
344
|
-
bail(err);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/* Check if `func` is a constructor. */
|
|
350
|
-
function newable(value) {
|
|
351
|
-
return typeof value === 'function' && keys(value.prototype);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/* Check if `value` is an object with keys. */
|
|
355
|
-
function keys(value) {
|
|
356
|
-
var key;
|
|
357
|
-
for (key in value) {
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/* Assert a parser is available. */
|
|
364
|
-
function assertParser(name, Parser) {
|
|
365
|
-
if (typeof Parser !== 'function') {
|
|
366
|
-
throw new Error('Cannot `' + name + '` without `Parser`');
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/* Assert a compiler is available. */
|
|
371
|
-
function assertCompiler(name, Compiler) {
|
|
372
|
-
if (typeof Compiler !== 'function') {
|
|
373
|
-
throw new Error('Cannot `' + name + '` without `Compiler`');
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/* Assert the processor is not frozen. */
|
|
378
|
-
function assertUnfrozen(name, frozen) {
|
|
379
|
-
if (frozen) {
|
|
380
|
-
throw new Error(['Cannot invoke `' + name + '` on a frozen processor.\nCreate a new ', 'processor first, by invoking it: use `processor()` instead of ', '`processor`.'].join(''));
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/* Assert `node` is a Unist node. */
|
|
385
|
-
function assertNode(node) {
|
|
386
|
-
if (!node || !string(node.type)) {
|
|
387
|
-
throw new Error('Expected node, got `' + node + '`');
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/* Assert that `complete` is `true`. */
|
|
392
|
-
function assertDone(name, asyncName, complete) {
|
|
393
|
-
if (!complete) {
|
|
394
|
-
throw new Error('`' + name + '` finished async. Use `' + asyncName + '` instead');
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/* Expose a frozen processor. */
|
|
399
|
-
const unified_freeze = unified().freeze();
|
|
400
|
-
export default unified_freeze;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var replace = require('replace-ext');
|
|
6
|
-
var buffer = require('is-buffer');
|
|
7
|
-
var own = {}.hasOwnProperty;
|
|
8
|
-
var proto = VFile.prototype;
|
|
9
|
-
proto.toString = toString;
|
|
10
|
-
|
|
11
|
-
/* Order of setting (least specific to most), we need this because
|
|
12
|
-
* otherwise `{stem: 'a', path: '~/b.js'}` would throw, as a path
|
|
13
|
-
* is needed before a stem can be set. */
|
|
14
|
-
var order = ['history', 'path', 'basename', 'stem', 'extname', 'dirname'];
|
|
15
|
-
|
|
16
|
-
/* Construct a new file. */
|
|
17
|
-
function VFile(options) {
|
|
18
|
-
var prop;
|
|
19
|
-
var index;
|
|
20
|
-
var length;
|
|
21
|
-
if (typeof options === 'number') {
|
|
22
|
-
options = options.toString();
|
|
23
|
-
}
|
|
24
|
-
if (!options) {
|
|
25
|
-
options = {};
|
|
26
|
-
} else if (typeof options === 'string' || buffer(options)) {
|
|
27
|
-
options = {
|
|
28
|
-
contents: options
|
|
29
|
-
};
|
|
30
|
-
} else if ('message' in options && 'messages' in options) {
|
|
31
|
-
return options;
|
|
32
|
-
}
|
|
33
|
-
if (!(this instanceof VFile)) {
|
|
34
|
-
return new VFile(options);
|
|
35
|
-
}
|
|
36
|
-
this.data = {};
|
|
37
|
-
this.messages = [];
|
|
38
|
-
this.history = [];
|
|
39
|
-
this.cwd = process.cwd();
|
|
40
|
-
|
|
41
|
-
/* Set path related properties in the correct order. */
|
|
42
|
-
index = -1;
|
|
43
|
-
length = order.length;
|
|
44
|
-
while (++index < length) {
|
|
45
|
-
prop = order[index];
|
|
46
|
-
if (own.call(options, prop)) {
|
|
47
|
-
this[prop] = options[prop];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/* Set non-path related properties. */
|
|
52
|
-
for (prop in options) {
|
|
53
|
-
if (order.indexOf(prop) === -1) {
|
|
54
|
-
this[prop] = options[prop];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* Access full path (`~/index.min.js`). */
|
|
60
|
-
Object.defineProperty(proto, 'path', {
|
|
61
|
-
get: function () {
|
|
62
|
-
return this.history[this.history.length - 1];
|
|
63
|
-
},
|
|
64
|
-
set: function (path) {
|
|
65
|
-
assertNonEmpty(path, 'path');
|
|
66
|
-
if (path !== this.path) {
|
|
67
|
-
this.history.push(path);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
/* Access parent path (`~`). */
|
|
73
|
-
Object.defineProperty(proto, 'dirname', {
|
|
74
|
-
get: function () {
|
|
75
|
-
return typeof this.path === 'string' ? path.dirname(this.path) : undefined;
|
|
76
|
-
},
|
|
77
|
-
set: function (dirname) {
|
|
78
|
-
assertPath(this.path, 'dirname');
|
|
79
|
-
this.path = path.join(dirname || '', this.basename);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
/* Access basename (`index.min.js`). */
|
|
84
|
-
Object.defineProperty(proto, 'basename', {
|
|
85
|
-
get: function () {
|
|
86
|
-
return typeof this.path === 'string' ? path.basename(this.path) : undefined;
|
|
87
|
-
},
|
|
88
|
-
set: function (basename) {
|
|
89
|
-
assertNonEmpty(basename, 'basename');
|
|
90
|
-
assertPart(basename, 'basename');
|
|
91
|
-
this.path = path.join(this.dirname || '', basename);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
/* Access extname (`.js`). */
|
|
96
|
-
Object.defineProperty(proto, 'extname', {
|
|
97
|
-
get: function () {
|
|
98
|
-
return typeof this.path === 'string' ? path.extname(this.path) : undefined;
|
|
99
|
-
},
|
|
100
|
-
set: function (extname) {
|
|
101
|
-
var ext = extname || '';
|
|
102
|
-
assertPart(ext, 'extname');
|
|
103
|
-
assertPath(this.path, 'extname');
|
|
104
|
-
if (ext) {
|
|
105
|
-
if (ext.charAt(0) !== '.') {
|
|
106
|
-
throw new Error('`extname` must start with `.`');
|
|
107
|
-
}
|
|
108
|
-
if (ext.indexOf('.', 1) !== -1) {
|
|
109
|
-
throw new Error('`extname` cannot contain multiple dots');
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
this.path = replace(this.path, ext);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
/* Access stem (`index.min`). */
|
|
117
|
-
Object.defineProperty(proto, 'stem', {
|
|
118
|
-
get: function () {
|
|
119
|
-
return typeof this.path === 'string' ? path.basename(this.path, this.extname) : undefined;
|
|
120
|
-
},
|
|
121
|
-
set: function (stem) {
|
|
122
|
-
assertNonEmpty(stem, 'stem');
|
|
123
|
-
assertPart(stem, 'stem');
|
|
124
|
-
this.path = path.join(this.dirname || '', stem + (this.extname || ''));
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
/* Get the value of the file. */
|
|
129
|
-
function toString(encoding) {
|
|
130
|
-
var value = this.contents || '';
|
|
131
|
-
return buffer(value) ? value.toString(encoding) : String(value);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/* Assert that `part` is not a path (i.e., does
|
|
135
|
-
* not contain `path.sep`). */
|
|
136
|
-
function assertPart(part, name) {
|
|
137
|
-
if (part.indexOf(path.sep) !== -1) {
|
|
138
|
-
throw new Error('`' + name + '` cannot be a path: did not expect `' + path.sep + '`');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/* Assert that `part` is not empty. */
|
|
143
|
-
function assertNonEmpty(part, name) {
|
|
144
|
-
if (!part) {
|
|
145
|
-
throw new Error('`' + name + '` cannot be empty');
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/* Assert `path` exists. */
|
|
150
|
-
function assertPath(path, name) {
|
|
151
|
-
if (!path) {
|
|
152
|
-
throw new Error('Setting `' + name + '` requires `path` to be set too');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
export default VFile;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
var VMessage = require('vfile-message');
|
|
2
|
-
var VFile = require('./core.js').default;
|
|
3
|
-
var proto = VFile.prototype;
|
|
4
|
-
proto.message = message;
|
|
5
|
-
proto.info = info;
|
|
6
|
-
proto.fail = fail;
|
|
7
|
-
|
|
8
|
-
/* Slight backwards compatibility. Remove in the future. */
|
|
9
|
-
proto.warn = message;
|
|
10
|
-
|
|
11
|
-
/* Create a message with `reason` at `position`.
|
|
12
|
-
* When an error is passed in as `reason`, copies the stack. */
|
|
13
|
-
function message(reason, position, origin) {
|
|
14
|
-
var filePath = this.path;
|
|
15
|
-
var message = new VMessage(reason, position, origin);
|
|
16
|
-
if (filePath) {
|
|
17
|
-
message.name = filePath + ':' + message.name;
|
|
18
|
-
message.file = filePath;
|
|
19
|
-
}
|
|
20
|
-
message.fatal = false;
|
|
21
|
-
this.messages.push(message);
|
|
22
|
-
return message;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* Fail. Creates a vmessage, associates it with the file,
|
|
26
|
-
* and throws it. */
|
|
27
|
-
function fail() {
|
|
28
|
-
var message = this.message.apply(this, arguments);
|
|
29
|
-
message.fatal = true;
|
|
30
|
-
throw message;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/* Info. Creates a vmessage, associates it with the file,
|
|
34
|
-
* and marks the fatality as null. */
|
|
35
|
-
function info() {
|
|
36
|
-
var message = this.message.apply(this, arguments);
|
|
37
|
-
message.fatal = null;
|
|
38
|
-
return message;
|
|
39
|
-
}
|
|
40
|
-
export default VFile;
|