dtable-ui-component 0.3.20 → 0.3.21
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/AutoNumberFormatter/index.js +2 -9
- package/lib/ButtonFormatter/index.js +4 -17
- package/lib/CTimeFormatter/index.js +2 -15
- package/lib/CheckboxEditor/index.js +0 -13
- package/lib/CheckboxFormatter/index.js +2 -11
- package/lib/CollaboratorEditor/index.js +6 -44
- package/lib/CollaboratorEditor/mb-collaborator-editor-popover/index.js +2 -27
- package/lib/CollaboratorEditor/pc-collaborator-editor-popover/index.js +2 -20
- package/lib/CollaboratorFormatter/index.js +6 -23
- package/lib/CollaboratorItem/index.js +2 -14
- package/lib/CreatorFormatter/index.js +6 -22
- package/lib/DTableCustomizeCollaboratorSelect/index.js +16 -37
- package/lib/DTableCustomizeCollaboratorSelect/utils.js +6 -5
- package/lib/DTableCustomizeSelect/index.js +14 -37
- package/lib/DTablePopover/index.js +8 -26
- package/lib/DTableRadio/index.js +0 -2
- package/lib/DTableSearchInput/index.js +12 -36
- package/lib/DTableSelect/index.js +13 -27
- package/lib/DTableSwitch/index.js +4 -6
- package/lib/DateEditor/index.js +8 -27
- package/lib/DateEditor/mb-date-editor-popover/index.js +8 -42
- package/lib/DateEditor/pc-date-editor-popover.js +7 -27
- package/lib/DateFormatter/index.js +3 -12
- package/lib/DigitalSignFormatter/index.js +8 -26
- package/lib/DigitalSignFormatter/utils.js +3 -6
- package/lib/DurationFormatter/index.js +3 -10
- package/lib/EditEditorButton/index.js +0 -7
- package/lib/EmailFormatter/index.js +2 -9
- package/lib/FieldDisplaySetting/field-item.js +6 -20
- package/lib/FieldDisplaySetting/index.js +8 -13
- package/lib/FileEditor/index.js +0 -8
- package/lib/FileFormatter/index.js +3 -14
- package/lib/FileItemFormatter/index.js +0 -13
- package/lib/FileItemFormatter/utils.js +0 -6
- package/lib/FileUploader/index.js +0 -16
- package/lib/FormulaFormatter/cell-value-validator.js +0 -10
- package/lib/FormulaFormatter/index.js +8 -38
- package/lib/FormulaFormatter/utils.js +0 -17
- package/lib/GeolocationFormatter/index.js +4 -13
- package/lib/HtmlLongTextFormatter/index.js +0 -21
- package/lib/HtmlLongTextFormatter/markdown2html.js +2 -17
- package/lib/HtmlLongTextFormatter/unified/index.js +29 -102
- package/lib/HtmlLongTextFormatter/vfile/core.js +13 -32
- package/lib/HtmlLongTextFormatter/vfile/index.js +4 -11
- package/lib/ImageFormatter/images-lazy-load.js +5 -35
- package/lib/ImageFormatter/index.js +7 -34
- package/lib/ImageFormatter/utils.js +0 -1
- package/lib/ImagePreviewerLightbox/index.js +11 -13
- package/lib/LastModifierFormatter/index.js +6 -22
- package/lib/LinkEditor/index.js +23 -69
- package/lib/LinkEditor/link-editor-option.js +2 -18
- package/lib/LinkEditor/mb-link-editor-popover/index.js +2 -27
- package/lib/LinkEditor/pc-link-editor-popover/index.js +2 -20
- package/lib/LinkFormatter/index.js +12 -35
- package/lib/LongTextFormatter/index.js +2 -6
- package/lib/MBEditorHeader/index.js +6 -13
- package/lib/MTimeFormatter/index.js +2 -15
- package/lib/ModalPortal/index.js +0 -8
- package/lib/MultipleSelectEditor/index.js +4 -42
- package/lib/MultipleSelectFormatter/index.js +4 -17
- package/lib/NotificationPopover/index.js +3 -22
- package/lib/NumberEditor/index.js +7 -35
- package/lib/NumberFormatter/index.js +3 -12
- package/lib/RateFormatter/index.js +10 -25
- package/lib/RowExpandEmailFormatter/index.js +2 -13
- package/lib/RowExpandFileFormatter/index.js +6 -15
- package/lib/RowExpandFileFormatter/row-expand-file-item-formatter.js +6 -24
- package/lib/RowExpandFormatter/index.js +10 -60
- package/lib/RowExpandFormulaFormatter/index.js +10 -41
- package/lib/RowExpandImageFormatter/index.js +8 -27
- package/lib/RowExpandImageFormatter/row-expand-image-item-formatter.js +11 -27
- package/lib/RowExpandImageFormatter/utils.js +0 -1
- package/lib/RowExpandLinkFormatter/collaborator-item-formatter.js +4 -35
- package/lib/RowExpandLinkFormatter/index.js +6 -28
- package/lib/RowExpandLinkFormatter/utils.js +0 -4
- package/lib/RowExpandLinkFormatter/value-display-utils.js +2 -2
- package/lib/RowExpandRateFormatter/index.js +8 -23
- package/lib/RowExpandUrlFormatter/index.js +2 -14
- package/lib/SelectItem/index.js +2 -13
- package/lib/SelectOptionGroup/index.js +13 -42
- package/lib/SelectOptionGroup/option.js +0 -14
- package/lib/SimpleLongTextFormatter/index.js +0 -26
- package/lib/SimpleLongTextFormatter/normalize-long-text-value.js +2 -12
- package/lib/SimpleLongTextFormatter/widgets/LongTextPreview.js +1 -16
- package/lib/SimpleLongTextFormatter/widgets/dtable-markdown-viewer.js +0 -17
- package/lib/SingleSelectEditor/index.js +4 -37
- package/lib/SingleSelectFormatter/index.js +5 -17
- package/lib/TextEditor/index.js +3 -22
- package/lib/TextFormatter/index.js +2 -15
- package/lib/UrlFormatter/index.js +2 -9
- package/lib/cellFormatterFactory/index.js +0 -5
- package/lib/common/delete-tip.js +4 -16
- package/lib/common/modal-portal.js +0 -8
- package/lib/formatterConfig/base-formatter-config.js +0 -2
- package/lib/formatterConfig/index.js +0 -4
- package/lib/index.js +12 -6
- package/lib/lang/index.js +0 -7
- package/lib/select-editor/mb-select-editor-popover/index.js +6 -38
- package/lib/select-editor/pc-select-editor-popover/index.js +3 -25
- package/lib/select-editor/select-editor-option.js +2 -17
- package/lib/toaster/alert.js +0 -12
- package/lib/toaster/toast.js +1 -22
- package/lib/toaster/toastManager.js +7 -30
- package/lib/toaster/toaster.js +4 -15
- package/lib/utils/editor-utils.js +0 -20
- package/lib/utils/utils.js +2 -5
- package/package.json +5 -5
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
// eslint-disable-next-line
|
|
2
2
|
'use strict';
|
|
3
|
-
/* Dependencies. */
|
|
4
3
|
|
|
4
|
+
/* Dependencies. */
|
|
5
5
|
var extend = require('extend');
|
|
6
|
-
|
|
7
6
|
var bail = require('bail');
|
|
8
|
-
|
|
9
7
|
var trough = require('trough');
|
|
10
|
-
|
|
11
8
|
var string = require('x-is-string');
|
|
12
|
-
|
|
13
9
|
var plain = require('is-plain-obj');
|
|
14
|
-
|
|
15
10
|
var vfile = require('../vfile').default;
|
|
16
|
-
|
|
17
11
|
var slice = [].slice;
|
|
18
12
|
var own = {}.hasOwnProperty;
|
|
19
|
-
/* Process pipeline. */
|
|
20
13
|
|
|
14
|
+
/* Process pipeline. */
|
|
21
15
|
var pipeline = trough().use(pipelineParse).use(pipelineRun).use(pipelineStringify);
|
|
22
|
-
|
|
23
16
|
function pipelineParse(p, ctx) {
|
|
24
17
|
ctx.tree = p.parse(ctx.file);
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
function pipelineRun(p, ctx, next) {
|
|
28
20
|
p.run(ctx.tree, ctx.file, done);
|
|
29
|
-
|
|
30
21
|
function done(err, tree, file) {
|
|
31
22
|
if (err) {
|
|
32
23
|
next(err);
|
|
@@ -37,55 +28,52 @@ function pipelineRun(p, ctx, next) {
|
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
|
-
|
|
41
31
|
function pipelineStringify(p, ctx) {
|
|
42
32
|
ctx.file.contents = p.stringify(ctx.tree, ctx.file);
|
|
43
33
|
}
|
|
44
|
-
/* Function to create the first processor. */
|
|
45
|
-
|
|
46
34
|
|
|
35
|
+
/* Function to create the first processor. */
|
|
47
36
|
function unified() {
|
|
48
37
|
var attachers = [];
|
|
49
38
|
var transformers = trough();
|
|
50
39
|
var namespace = {};
|
|
51
40
|
var frozen = false;
|
|
52
41
|
var freezeIndex = -1;
|
|
53
|
-
/* Data management. */
|
|
54
42
|
|
|
43
|
+
/* Data management. */
|
|
55
44
|
processor.data = data;
|
|
56
|
-
/* Lock. */
|
|
57
45
|
|
|
46
|
+
/* Lock. */
|
|
58
47
|
processor.freeze = freeze;
|
|
59
|
-
/* Plug-ins. */
|
|
60
48
|
|
|
49
|
+
/* Plug-ins. */
|
|
61
50
|
processor.attachers = attachers;
|
|
62
51
|
processor.use = use;
|
|
63
|
-
/* API. */
|
|
64
52
|
|
|
53
|
+
/* API. */
|
|
65
54
|
processor.parse = parse;
|
|
66
55
|
processor.stringify = stringify;
|
|
67
56
|
processor.run = run;
|
|
68
57
|
processor.runSync = runSync;
|
|
69
58
|
processor.process = process;
|
|
70
59
|
processor.processSync = processSync;
|
|
71
|
-
/* Expose. */
|
|
72
60
|
|
|
61
|
+
/* Expose. */
|
|
73
62
|
return processor;
|
|
63
|
+
|
|
74
64
|
/* Create a new processor based on the processor
|
|
75
65
|
* in the current scope. */
|
|
76
|
-
|
|
77
66
|
function processor() {
|
|
78
67
|
var destination = unified();
|
|
79
68
|
var length = attachers.length;
|
|
80
69
|
var index = -1;
|
|
81
|
-
|
|
82
70
|
while (++index < length) {
|
|
83
71
|
destination.use.apply(null, attachers[index]);
|
|
84
72
|
}
|
|
85
|
-
|
|
86
73
|
destination.data(extend(true, {}, namespace));
|
|
87
74
|
return destination;
|
|
88
75
|
}
|
|
76
|
+
|
|
89
77
|
/* Freeze: used to signal a processor that has finished
|
|
90
78
|
* configuration.
|
|
91
79
|
*
|
|
@@ -95,47 +83,37 @@ function unified() {
|
|
|
95
83
|
*
|
|
96
84
|
* In essence, always invoke this when exporting a
|
|
97
85
|
* processor. */
|
|
98
|
-
|
|
99
|
-
|
|
100
86
|
function freeze() {
|
|
101
87
|
var values;
|
|
102
88
|
var plugin;
|
|
103
89
|
var options;
|
|
104
90
|
var transformer;
|
|
105
|
-
|
|
106
91
|
if (frozen) {
|
|
107
92
|
return processor;
|
|
108
93
|
}
|
|
109
|
-
|
|
110
94
|
while (++freezeIndex < attachers.length) {
|
|
111
95
|
values = attachers[freezeIndex];
|
|
112
96
|
plugin = values[0];
|
|
113
97
|
options = values[1];
|
|
114
98
|
transformer = null;
|
|
115
|
-
|
|
116
99
|
if (options === false) {
|
|
117
100
|
continue;
|
|
118
101
|
}
|
|
119
|
-
|
|
120
102
|
if (options === true) {
|
|
121
103
|
values[1] = undefined;
|
|
122
104
|
}
|
|
123
|
-
|
|
124
105
|
transformer = plugin.apply(processor, values.slice(1));
|
|
125
|
-
|
|
126
106
|
if (typeof transformer === 'function') {
|
|
127
107
|
transformers.use(transformer);
|
|
128
108
|
}
|
|
129
109
|
}
|
|
130
|
-
|
|
131
110
|
frozen = true;
|
|
132
111
|
freezeIndex = Infinity;
|
|
133
112
|
return processor;
|
|
134
113
|
}
|
|
114
|
+
|
|
135
115
|
/* Data management.
|
|
136
116
|
* Getter / setter for processor-specific informtion. */
|
|
137
|
-
|
|
138
|
-
|
|
139
117
|
function data(key, value) {
|
|
140
118
|
if (string(key)) {
|
|
141
119
|
/* Set `key`. */
|
|
@@ -144,24 +122,22 @@ function unified() {
|
|
|
144
122
|
namespace[key] = value;
|
|
145
123
|
return processor;
|
|
146
124
|
}
|
|
147
|
-
/* Get `key`. */
|
|
148
|
-
|
|
149
125
|
|
|
126
|
+
/* Get `key`. */
|
|
150
127
|
return own.call(namespace, key) && namespace[key] || null;
|
|
151
128
|
}
|
|
152
|
-
/* Set space. */
|
|
153
|
-
|
|
154
129
|
|
|
130
|
+
/* Set space. */
|
|
155
131
|
if (key) {
|
|
156
132
|
assertUnfrozen('data', frozen);
|
|
157
133
|
namespace = key;
|
|
158
134
|
return processor;
|
|
159
135
|
}
|
|
160
|
-
/* Get space. */
|
|
161
|
-
|
|
162
136
|
|
|
137
|
+
/* Get space. */
|
|
163
138
|
return namespace;
|
|
164
139
|
}
|
|
140
|
+
|
|
165
141
|
/* Plug-in management.
|
|
166
142
|
*
|
|
167
143
|
* Pass it:
|
|
@@ -169,12 +145,9 @@ function unified() {
|
|
|
169
145
|
* * a preset,
|
|
170
146
|
* * a list of presets, attachers, and arguments (list
|
|
171
147
|
* of attachers and options). */
|
|
172
|
-
|
|
173
|
-
|
|
174
148
|
function use(value) {
|
|
175
149
|
var settings;
|
|
176
150
|
assertUnfrozen('use', frozen);
|
|
177
|
-
|
|
178
151
|
if (value === null || value === undefined) {
|
|
179
152
|
/* Empty */
|
|
180
153
|
} else if (typeof value === 'function') {
|
|
@@ -188,21 +161,16 @@ function unified() {
|
|
|
188
161
|
} else {
|
|
189
162
|
throw new Error('Expected usable value, not `' + value + '`');
|
|
190
163
|
}
|
|
191
|
-
|
|
192
164
|
if (settings) {
|
|
193
165
|
namespace.settings = extend(namespace.settings || {}, settings);
|
|
194
166
|
}
|
|
195
|
-
|
|
196
167
|
return processor;
|
|
197
|
-
|
|
198
168
|
function addPreset(result) {
|
|
199
169
|
addList(result.plugins);
|
|
200
|
-
|
|
201
170
|
if (result.settings) {
|
|
202
171
|
settings = extend(settings || {}, result.settings);
|
|
203
172
|
}
|
|
204
173
|
}
|
|
205
|
-
|
|
206
174
|
function add(value) {
|
|
207
175
|
if (typeof value === 'function') {
|
|
208
176
|
addPlugin(value);
|
|
@@ -216,17 +184,14 @@ function unified() {
|
|
|
216
184
|
throw new Error('Expected usable value, not `' + value + '`');
|
|
217
185
|
}
|
|
218
186
|
}
|
|
219
|
-
|
|
220
187
|
function addList(plugins) {
|
|
221
188
|
var length;
|
|
222
189
|
var index;
|
|
223
|
-
|
|
224
190
|
if (plugins === null || plugins === undefined) {
|
|
225
191
|
/* Empty */
|
|
226
192
|
} else if (typeof plugins === 'object' && 'length' in plugins) {
|
|
227
193
|
length = plugins.length;
|
|
228
194
|
index = -1;
|
|
229
|
-
|
|
230
195
|
while (++index < length) {
|
|
231
196
|
add(plugins[index]);
|
|
232
197
|
}
|
|
@@ -234,78 +199,62 @@ function unified() {
|
|
|
234
199
|
throw new Error('Expected a list of plugins, not `' + plugins + '`');
|
|
235
200
|
}
|
|
236
201
|
}
|
|
237
|
-
|
|
238
202
|
function addPlugin(plugin, value) {
|
|
239
203
|
var entry = find(plugin);
|
|
240
|
-
|
|
241
204
|
if (entry) {
|
|
242
205
|
if (plain(entry[1]) && plain(value)) {
|
|
243
206
|
value = extend(entry[1], value);
|
|
244
207
|
}
|
|
245
|
-
|
|
246
208
|
entry[1] = value;
|
|
247
209
|
} else {
|
|
248
210
|
attachers.push(slice.call(arguments));
|
|
249
211
|
}
|
|
250
212
|
}
|
|
251
213
|
}
|
|
252
|
-
|
|
253
214
|
function find(plugin) {
|
|
254
215
|
var length = attachers.length;
|
|
255
216
|
var index = -1;
|
|
256
217
|
var entry;
|
|
257
|
-
|
|
258
218
|
while (++index < length) {
|
|
259
219
|
entry = attachers[index];
|
|
260
|
-
|
|
261
220
|
if (entry[0] === plugin) {
|
|
262
221
|
return entry;
|
|
263
222
|
}
|
|
264
223
|
}
|
|
265
224
|
}
|
|
225
|
+
|
|
266
226
|
/* Parse a file (in string or VFile representation)
|
|
267
227
|
* into a Unist node using the `Parser` on the
|
|
268
228
|
* processor. */
|
|
269
|
-
|
|
270
|
-
|
|
271
229
|
function parse(doc) {
|
|
272
230
|
var file = vfile(doc);
|
|
273
231
|
var Parser;
|
|
274
232
|
freeze();
|
|
275
233
|
Parser = processor.Parser;
|
|
276
234
|
assertParser('parse', Parser);
|
|
277
|
-
|
|
278
235
|
if (newable(Parser)) {
|
|
279
236
|
return new Parser(String(file), file).parse();
|
|
280
237
|
}
|
|
281
|
-
|
|
282
238
|
return Parser(String(file), file); // eslint-disable-line new-cap
|
|
283
239
|
}
|
|
240
|
+
|
|
284
241
|
/* Run transforms on a Unist node representation of a file
|
|
285
242
|
* (in string or VFile representation), async. */
|
|
286
|
-
|
|
287
|
-
|
|
288
243
|
function run(node, file, cb) {
|
|
289
244
|
assertNode(node);
|
|
290
245
|
freeze();
|
|
291
|
-
|
|
292
246
|
if (!cb && typeof file === 'function') {
|
|
293
247
|
cb = file;
|
|
294
248
|
file = null;
|
|
295
249
|
}
|
|
296
|
-
|
|
297
250
|
if (!cb) {
|
|
298
251
|
return new Promise(executor);
|
|
299
252
|
}
|
|
300
|
-
|
|
301
253
|
executor(null, cb);
|
|
302
|
-
|
|
303
254
|
function executor(resolve, reject) {
|
|
304
255
|
transformers.run(node, vfile(file), done);
|
|
305
|
-
|
|
306
256
|
function done(err, tree, file) {
|
|
307
257
|
tree = tree || node;
|
|
308
|
-
|
|
309
258
|
if (err) {
|
|
310
259
|
reject(err);
|
|
311
260
|
} else if (resolve) {
|
|
@@ -316,28 +265,25 @@ function unified() {
|
|
|
316
265
|
}
|
|
317
266
|
}
|
|
318
267
|
}
|
|
268
|
+
|
|
319
269
|
/* Run transforms on a Unist node representation of a file
|
|
320
270
|
* (in string or VFile representation), sync. */
|
|
321
|
-
|
|
322
|
-
|
|
323
271
|
function runSync(node, file) {
|
|
324
272
|
var complete = false;
|
|
325
273
|
var result;
|
|
326
274
|
run(node, file, done);
|
|
327
275
|
assertDone('runSync', 'run', complete);
|
|
328
276
|
return result;
|
|
329
|
-
|
|
330
277
|
function done(err, tree) {
|
|
331
278
|
complete = true;
|
|
332
279
|
bail(err);
|
|
333
280
|
result = tree;
|
|
334
281
|
}
|
|
335
282
|
}
|
|
283
|
+
|
|
336
284
|
/* Stringify a Unist node representation of a file
|
|
337
285
|
* (in string or VFile representation) into a string
|
|
338
286
|
* using the `Compiler` on the processor. */
|
|
339
|
-
|
|
340
|
-
|
|
341
287
|
function stringify(node, doc) {
|
|
342
288
|
var file = vfile(doc);
|
|
343
289
|
var Compiler;
|
|
@@ -345,37 +291,30 @@ function unified() {
|
|
|
345
291
|
Compiler = processor.Compiler;
|
|
346
292
|
assertCompiler('stringify', Compiler);
|
|
347
293
|
assertNode(node);
|
|
348
|
-
|
|
349
294
|
if (newable(Compiler)) {
|
|
350
295
|
return new Compiler(node, file).compile();
|
|
351
296
|
}
|
|
352
|
-
|
|
353
297
|
return Compiler(node, file); // eslint-disable-line new-cap
|
|
354
298
|
}
|
|
299
|
+
|
|
355
300
|
/* Parse a file (in string or VFile representation)
|
|
356
301
|
* into a Unist node using the `Parser` on the processor,
|
|
357
302
|
* then run transforms on that node, and compile the
|
|
358
303
|
* resulting node using the `Compiler` on the processor,
|
|
359
304
|
* and store that result on the VFile. */
|
|
360
|
-
|
|
361
|
-
|
|
362
305
|
function process(doc, cb) {
|
|
363
306
|
freeze();
|
|
364
307
|
assertParser('process', processor.Parser);
|
|
365
308
|
assertCompiler('process', processor.Compiler);
|
|
366
|
-
|
|
367
309
|
if (!cb) {
|
|
368
310
|
return new Promise(executor);
|
|
369
311
|
}
|
|
370
|
-
|
|
371
312
|
executor(null, cb);
|
|
372
|
-
|
|
373
313
|
function executor(resolve, reject) {
|
|
374
314
|
var file = vfile(doc);
|
|
375
315
|
pipeline.run(processor, {
|
|
376
316
|
file: file
|
|
377
317
|
}, done);
|
|
378
|
-
|
|
379
318
|
function done(err) {
|
|
380
319
|
if (err) {
|
|
381
320
|
reject(err);
|
|
@@ -387,10 +326,9 @@ function unified() {
|
|
|
387
326
|
}
|
|
388
327
|
}
|
|
389
328
|
}
|
|
329
|
+
|
|
390
330
|
/* Process the given document (in string or VFile
|
|
391
331
|
* representation), sync. */
|
|
392
|
-
|
|
393
|
-
|
|
394
332
|
function processSync(doc) {
|
|
395
333
|
var complete = false;
|
|
396
334
|
var file;
|
|
@@ -401,73 +339,62 @@ function unified() {
|
|
|
401
339
|
process(file, done);
|
|
402
340
|
assertDone('processSync', 'process', complete);
|
|
403
341
|
return file;
|
|
404
|
-
|
|
405
342
|
function done(err) {
|
|
406
343
|
complete = true;
|
|
407
344
|
bail(err);
|
|
408
345
|
}
|
|
409
346
|
}
|
|
410
347
|
}
|
|
411
|
-
/* Check if `func` is a constructor. */
|
|
412
|
-
|
|
413
348
|
|
|
349
|
+
/* Check if `func` is a constructor. */
|
|
414
350
|
function newable(value) {
|
|
415
351
|
return typeof value === 'function' && keys(value.prototype);
|
|
416
352
|
}
|
|
417
|
-
/* Check if `value` is an object with keys. */
|
|
418
|
-
|
|
419
353
|
|
|
354
|
+
/* Check if `value` is an object with keys. */
|
|
420
355
|
function keys(value) {
|
|
421
356
|
var key;
|
|
422
|
-
|
|
423
357
|
for (key in value) {
|
|
424
358
|
return true;
|
|
425
359
|
}
|
|
426
|
-
|
|
427
360
|
return false;
|
|
428
361
|
}
|
|
429
|
-
/* Assert a parser is available. */
|
|
430
|
-
|
|
431
362
|
|
|
363
|
+
/* Assert a parser is available. */
|
|
432
364
|
function assertParser(name, Parser) {
|
|
433
365
|
if (typeof Parser !== 'function') {
|
|
434
366
|
throw new Error('Cannot `' + name + '` without `Parser`');
|
|
435
367
|
}
|
|
436
368
|
}
|
|
437
|
-
/* Assert a compiler is available. */
|
|
438
|
-
|
|
439
369
|
|
|
370
|
+
/* Assert a compiler is available. */
|
|
440
371
|
function assertCompiler(name, Compiler) {
|
|
441
372
|
if (typeof Compiler !== 'function') {
|
|
442
373
|
throw new Error('Cannot `' + name + '` without `Compiler`');
|
|
443
374
|
}
|
|
444
375
|
}
|
|
445
|
-
/* Assert the processor is not frozen. */
|
|
446
|
-
|
|
447
376
|
|
|
377
|
+
/* Assert the processor is not frozen. */
|
|
448
378
|
function assertUnfrozen(name, frozen) {
|
|
449
379
|
if (frozen) {
|
|
450
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(''));
|
|
451
381
|
}
|
|
452
382
|
}
|
|
453
|
-
/* Assert `node` is a Unist node. */
|
|
454
|
-
|
|
455
383
|
|
|
384
|
+
/* Assert `node` is a Unist node. */
|
|
456
385
|
function assertNode(node) {
|
|
457
386
|
if (!node || !string(node.type)) {
|
|
458
387
|
throw new Error('Expected node, got `' + node + '`');
|
|
459
388
|
}
|
|
460
389
|
}
|
|
461
|
-
/* Assert that `complete` is `true`. */
|
|
462
|
-
|
|
463
390
|
|
|
391
|
+
/* Assert that `complete` is `true`. */
|
|
464
392
|
function assertDone(name, asyncName, complete) {
|
|
465
393
|
if (!complete) {
|
|
466
394
|
throw new Error('`' + name + '` finished async. Use `' + asyncName + '` instead');
|
|
467
395
|
}
|
|
468
396
|
}
|
|
469
|
-
/* Expose a frozen processor. */
|
|
470
|
-
|
|
471
397
|
|
|
398
|
+
/* Expose a frozen processor. */
|
|
472
399
|
var unified_freeze = unified().freeze();
|
|
473
400
|
export default unified_freeze;
|
|
@@ -2,30 +2,25 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var path = require('path');
|
|
5
|
-
|
|
6
5
|
var replace = require('replace-ext');
|
|
7
|
-
|
|
8
6
|
var buffer = require('is-buffer');
|
|
9
|
-
|
|
10
7
|
var own = {}.hasOwnProperty;
|
|
11
8
|
var proto = VFile.prototype;
|
|
12
9
|
proto.toString = toString;
|
|
10
|
+
|
|
13
11
|
/* Order of setting (least specific to most), we need this because
|
|
14
12
|
* otherwise `{stem: 'a', path: '~/b.js'}` would throw, as a path
|
|
15
13
|
* is needed before a stem can be set. */
|
|
16
|
-
|
|
17
14
|
var order = ['history', 'path', 'basename', 'stem', 'extname', 'dirname'];
|
|
18
|
-
/* Construct a new file. */
|
|
19
15
|
|
|
16
|
+
/* Construct a new file. */
|
|
20
17
|
function VFile(options) {
|
|
21
18
|
var prop;
|
|
22
19
|
var index;
|
|
23
20
|
var length;
|
|
24
|
-
|
|
25
21
|
if (typeof options === 'number') {
|
|
26
22
|
options = options.toString();
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
if (!options) {
|
|
30
25
|
options = {};
|
|
31
26
|
} else if (typeof options === 'string' || buffer(options)) {
|
|
@@ -35,53 +30,46 @@ function VFile(options) {
|
|
|
35
30
|
} else if ('message' in options && 'messages' in options) {
|
|
36
31
|
return options;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
if (!(this instanceof VFile)) {
|
|
40
34
|
return new VFile(options);
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
this.data = {};
|
|
44
37
|
this.messages = [];
|
|
45
38
|
this.history = [];
|
|
46
39
|
this.cwd = process.cwd();
|
|
47
|
-
/* Set path related properties in the correct order. */
|
|
48
40
|
|
|
41
|
+
/* Set path related properties in the correct order. */
|
|
49
42
|
index = -1;
|
|
50
43
|
length = order.length;
|
|
51
|
-
|
|
52
44
|
while (++index < length) {
|
|
53
45
|
prop = order[index];
|
|
54
|
-
|
|
55
46
|
if (own.call(options, prop)) {
|
|
56
47
|
this[prop] = options[prop];
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
|
-
/* Set non-path related properties. */
|
|
60
|
-
|
|
61
50
|
|
|
51
|
+
/* Set non-path related properties. */
|
|
62
52
|
for (prop in options) {
|
|
63
53
|
if (order.indexOf(prop) === -1) {
|
|
64
54
|
this[prop] = options[prop];
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
}
|
|
68
|
-
/* Access full path (`~/index.min.js`). */
|
|
69
|
-
|
|
70
58
|
|
|
59
|
+
/* Access full path (`~/index.min.js`). */
|
|
71
60
|
Object.defineProperty(proto, 'path', {
|
|
72
61
|
get: function get() {
|
|
73
62
|
return this.history[this.history.length - 1];
|
|
74
63
|
},
|
|
75
64
|
set: function set(path) {
|
|
76
65
|
assertNonEmpty(path, 'path');
|
|
77
|
-
|
|
78
66
|
if (path !== this.path) {
|
|
79
67
|
this.history.push(path);
|
|
80
68
|
}
|
|
81
69
|
}
|
|
82
70
|
});
|
|
83
|
-
/* Access parent path (`~`). */
|
|
84
71
|
|
|
72
|
+
/* Access parent path (`~`). */
|
|
85
73
|
Object.defineProperty(proto, 'dirname', {
|
|
86
74
|
get: function get() {
|
|
87
75
|
return typeof this.path === 'string' ? path.dirname(this.path) : undefined;
|
|
@@ -91,8 +79,8 @@ Object.defineProperty(proto, 'dirname', {
|
|
|
91
79
|
this.path = path.join(dirname || '', this.basename);
|
|
92
80
|
}
|
|
93
81
|
});
|
|
94
|
-
/* Access basename (`index.min.js`). */
|
|
95
82
|
|
|
83
|
+
/* Access basename (`index.min.js`). */
|
|
96
84
|
Object.defineProperty(proto, 'basename', {
|
|
97
85
|
get: function get() {
|
|
98
86
|
return typeof this.path === 'string' ? path.basename(this.path) : undefined;
|
|
@@ -103,8 +91,8 @@ Object.defineProperty(proto, 'basename', {
|
|
|
103
91
|
this.path = path.join(this.dirname || '', basename);
|
|
104
92
|
}
|
|
105
93
|
});
|
|
106
|
-
/* Access extname (`.js`). */
|
|
107
94
|
|
|
95
|
+
/* Access extname (`.js`). */
|
|
108
96
|
Object.defineProperty(proto, 'extname', {
|
|
109
97
|
get: function get() {
|
|
110
98
|
return typeof this.path === 'string' ? path.extname(this.path) : undefined;
|
|
@@ -113,22 +101,19 @@ Object.defineProperty(proto, 'extname', {
|
|
|
113
101
|
var ext = extname || '';
|
|
114
102
|
assertPart(ext, 'extname');
|
|
115
103
|
assertPath(this.path, 'extname');
|
|
116
|
-
|
|
117
104
|
if (ext) {
|
|
118
105
|
if (ext.charAt(0) !== '.') {
|
|
119
106
|
throw new Error('`extname` must start with `.`');
|
|
120
107
|
}
|
|
121
|
-
|
|
122
108
|
if (ext.indexOf('.', 1) !== -1) {
|
|
123
109
|
throw new Error('`extname` cannot contain multiple dots');
|
|
124
110
|
}
|
|
125
111
|
}
|
|
126
|
-
|
|
127
112
|
this.path = replace(this.path, ext);
|
|
128
113
|
}
|
|
129
114
|
});
|
|
130
|
-
/* Access stem (`index.min`). */
|
|
131
115
|
|
|
116
|
+
/* Access stem (`index.min`). */
|
|
132
117
|
Object.defineProperty(proto, 'stem', {
|
|
133
118
|
get: function get() {
|
|
134
119
|
return typeof this.path === 'string' ? path.basename(this.path, this.extname) : undefined;
|
|
@@ -139,36 +124,32 @@ Object.defineProperty(proto, 'stem', {
|
|
|
139
124
|
this.path = path.join(this.dirname || '', stem + (this.extname || ''));
|
|
140
125
|
}
|
|
141
126
|
});
|
|
142
|
-
/* Get the value of the file. */
|
|
143
127
|
|
|
128
|
+
/* Get the value of the file. */
|
|
144
129
|
function toString(encoding) {
|
|
145
130
|
var value = this.contents || '';
|
|
146
131
|
return buffer(value) ? value.toString(encoding) : String(value);
|
|
147
132
|
}
|
|
133
|
+
|
|
148
134
|
/* Assert that `part` is not a path (i.e., does
|
|
149
135
|
* not contain `path.sep`). */
|
|
150
|
-
|
|
151
|
-
|
|
152
136
|
function assertPart(part, name) {
|
|
153
137
|
if (part.indexOf(path.sep) !== -1) {
|
|
154
138
|
throw new Error('`' + name + '` cannot be a path: did not expect `' + path.sep + '`');
|
|
155
139
|
}
|
|
156
140
|
}
|
|
157
|
-
/* Assert that `part` is not empty. */
|
|
158
|
-
|
|
159
141
|
|
|
142
|
+
/* Assert that `part` is not empty. */
|
|
160
143
|
function assertNonEmpty(part, name) {
|
|
161
144
|
if (!part) {
|
|
162
145
|
throw new Error('`' + name + '` cannot be empty');
|
|
163
146
|
}
|
|
164
147
|
}
|
|
165
|
-
/* Assert `path` exists. */
|
|
166
|
-
|
|
167
148
|
|
|
149
|
+
/* Assert `path` exists. */
|
|
168
150
|
function assertPath(path, name) {
|
|
169
151
|
if (!path) {
|
|
170
152
|
throw new Error('Setting `' + name + '` requires `path` to be set too');
|
|
171
153
|
}
|
|
172
154
|
}
|
|
173
|
-
|
|
174
155
|
export default VFile;
|
|
@@ -1,47 +1,40 @@
|
|
|
1
1
|
var VMessage = require('vfile-message');
|
|
2
|
-
|
|
3
2
|
var VFile = require('./core.js').default;
|
|
4
|
-
|
|
5
3
|
var proto = VFile.prototype;
|
|
6
4
|
proto.message = message;
|
|
7
5
|
proto.info = info;
|
|
8
6
|
proto.fail = fail;
|
|
9
|
-
/* Slight backwards compatibility. Remove in the future. */
|
|
10
7
|
|
|
8
|
+
/* Slight backwards compatibility. Remove in the future. */
|
|
11
9
|
proto.warn = message;
|
|
10
|
+
|
|
12
11
|
/* Create a message with `reason` at `position`.
|
|
13
12
|
* When an error is passed in as `reason`, copies the stack. */
|
|
14
|
-
|
|
15
13
|
function message(reason, position, origin) {
|
|
16
14
|
var filePath = this.path;
|
|
17
15
|
var message = new VMessage(reason, position, origin);
|
|
18
|
-
|
|
19
16
|
if (filePath) {
|
|
20
17
|
message.name = filePath + ':' + message.name;
|
|
21
18
|
message.file = filePath;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
message.fatal = false;
|
|
25
21
|
this.messages.push(message);
|
|
26
22
|
return message;
|
|
27
23
|
}
|
|
24
|
+
|
|
28
25
|
/* Fail. Creates a vmessage, associates it with the file,
|
|
29
26
|
* and throws it. */
|
|
30
|
-
|
|
31
|
-
|
|
32
27
|
function fail() {
|
|
33
28
|
var message = this.message.apply(this, arguments);
|
|
34
29
|
message.fatal = true;
|
|
35
30
|
throw message;
|
|
36
31
|
}
|
|
32
|
+
|
|
37
33
|
/* Info. Creates a vmessage, associates it with the file,
|
|
38
34
|
* and marks the fatality as null. */
|
|
39
|
-
|
|
40
|
-
|
|
41
35
|
function info() {
|
|
42
36
|
var message = this.message.apply(this, arguments);
|
|
43
37
|
message.fatal = null;
|
|
44
38
|
return message;
|
|
45
39
|
}
|
|
46
|
-
|
|
47
40
|
export default VFile;
|