dtable-ui-component 0.1.75-beta → 0.1.75-beta1

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.
Files changed (115) hide show
  1. package/lib/app.css +20 -0
  2. package/lib/app.js +96 -0
  3. package/lib/assets/images/avatar/default_avatar.png +0 -0
  4. package/lib/assets/images/file/192/excel.png +0 -0
  5. package/lib/assets/images/file/192/file.png +0 -0
  6. package/lib/assets/images/file/192/music.png +0 -0
  7. package/lib/assets/images/file/192/pdf.png +0 -0
  8. package/lib/assets/images/file/192/pic.png +0 -0
  9. package/lib/assets/images/file/192/ppt.png +0 -0
  10. package/lib/assets/images/file/192/txt.png +0 -0
  11. package/lib/assets/images/file/192/video.png +0 -0
  12. package/lib/assets/images/file/192/word.png +0 -0
  13. package/lib/assets/images/file/24/excel.png +0 -0
  14. package/lib/assets/images/file/24/file.png +0 -0
  15. package/lib/assets/images/file/24/music.png +0 -0
  16. package/lib/assets/images/file/24/pdf.png +0 -0
  17. package/lib/assets/images/file/24/pic.png +0 -0
  18. package/lib/assets/images/file/24/ppt.png +0 -0
  19. package/lib/assets/images/file/24/txt.png +0 -0
  20. package/lib/assets/images/file/24/video.png +0 -0
  21. package/lib/assets/images/file/24/word.png +0 -0
  22. package/lib/assets/images/folder/folder-192.png +0 -0
  23. package/lib/assets/images/folder/folder-24.png +0 -0
  24. package/lib/components/cell-editor/checkbox-editor.js +111 -0
  25. package/lib/components/cell-editor/collaborator-editor.js +249 -0
  26. package/lib/components/cell-editor/date-editor.js +171 -0
  27. package/lib/components/cell-editor/index.js +40 -0
  28. package/lib/components/cell-editor/link-editor.js +321 -0
  29. package/lib/components/cell-editor/multiple-select-editor.js +250 -0
  30. package/lib/components/cell-editor/number-editor.js +162 -0
  31. package/lib/components/cell-editor/single-select-editor.js +216 -0
  32. package/lib/components/cell-editor/text-editor.js +129 -0
  33. package/lib/components/cell-editor-dialog/pc-file-editor-dialog.js +66 -0
  34. package/lib/components/cell-editor-dialog/pc-files-addition/index.js +1 -0
  35. package/lib/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +1 -0
  36. package/lib/components/cell-editor-dialog/pc-files-preview/index.js +1 -0
  37. package/lib/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +1 -0
  38. package/lib/components/cell-editor-popover/mb-collaborator-editor-popover.js +183 -0
  39. package/lib/components/cell-editor-popover/mb-date-editor-popover.js +262 -0
  40. package/lib/components/cell-editor-popover/mb-link-editor-popover.js +176 -0
  41. package/lib/components/cell-editor-popover/mb-select-editor-popover.js +243 -0
  42. package/lib/components/cell-editor-popover/pc-collaborator-editor-popover.js +124 -0
  43. package/lib/components/cell-editor-popover/pc-date-editor-popover.js +156 -0
  44. package/lib/components/cell-editor-popover/pc-link-editor-popover.js +128 -0
  45. package/lib/components/cell-editor-popover/pc-select-editor-popover.js +157 -0
  46. package/lib/components/cell-factory/cell-formatter-factory.js +28 -0
  47. package/lib/components/cell-formatter/auto-number-formatter.js +45 -0
  48. package/lib/components/cell-formatter/button-formatter.js +66 -0
  49. package/lib/components/cell-formatter/checkbox-formatter.js +56 -0
  50. package/lib/components/cell-formatter/collaborator-formatter.js +111 -0
  51. package/lib/components/cell-formatter/creator-formatter.js +105 -0
  52. package/lib/components/cell-formatter/ctime-formatter.js +70 -0
  53. package/lib/components/cell-formatter/date-formatter.js +73 -0
  54. package/lib/components/cell-formatter/duration-formatter.js +49 -0
  55. package/lib/components/cell-formatter/email-formatter.js +45 -0
  56. package/lib/components/cell-formatter/file-formatter.js +77 -0
  57. package/lib/components/cell-formatter/formatter-config.js +66 -0
  58. package/lib/components/cell-formatter/formula-formatter.js +189 -0
  59. package/lib/components/cell-formatter/geolocation-formatter.js +66 -0
  60. package/lib/components/cell-formatter/image-formatter.js +171 -0
  61. package/lib/components/cell-formatter/index.js +112 -0
  62. package/lib/components/cell-formatter/last-modifier-formatter.js +105 -0
  63. package/lib/components/cell-formatter/link-formatter.js +165 -0
  64. package/lib/components/cell-formatter/long-text-formatter.js +46 -0
  65. package/lib/components/cell-formatter/mtime-formatter.js +70 -0
  66. package/lib/components/cell-formatter/multiple-select-formatter.js +84 -0
  67. package/lib/components/cell-formatter/number-formatter.js +60 -0
  68. package/lib/components/cell-formatter/rate-formatter.js +93 -0
  69. package/lib/components/cell-formatter/single-select-formatter.js +84 -0
  70. package/lib/components/cell-formatter/text-formatter.js +67 -0
  71. package/lib/components/cell-formatter/url-formatter.js +45 -0
  72. package/lib/components/cell-formatter/widgets/file-item-formatter.js +63 -0
  73. package/lib/components/cell-formatter/widgets/image-previewer-lightbox.js +152 -0
  74. package/lib/components/cell-formatter/widgets/long-text-formatter/html-long-text-formatter.js +107 -0
  75. package/lib/components/cell-formatter/widgets/long-text-formatter/simple-long-text-formatter.js +110 -0
  76. package/lib/components/common/collaborator-item.js +79 -0
  77. package/lib/components/common/edit-editor-button.js +67 -0
  78. package/lib/components/common/images-lazy-load.js +158 -0
  79. package/lib/components/common/link-editor-option.js +121 -0
  80. package/lib/components/common/mobile/mb-editor-header.js +61 -0
  81. package/lib/components/common/modal-portal.js +51 -0
  82. package/lib/components/common/select-editor-option.js +122 -0
  83. package/lib/components/common/select-item.js +73 -0
  84. package/lib/components/file-uploader/index.js +63 -0
  85. package/lib/components/loading.js +16 -0
  86. package/lib/components/toast/alert.js +164 -0
  87. package/lib/components/toast/index.js +12 -0
  88. package/lib/components/toast/toast.js +223 -0
  89. package/lib/components/toast/toastManager.js +189 -0
  90. package/lib/components/toast/toaster.js +92 -0
  91. package/lib/constants/cell-types.js +54 -0
  92. package/lib/constants/index.js +70 -0
  93. package/lib/css/cell-editor.css +614 -0
  94. package/lib/css/cell-formatter.css +247 -0
  95. package/lib/css/custom-rc-calendar.css +118 -0
  96. package/lib/css/image-previewer-ligntbox.css +87 -0
  97. package/lib/css/loading.css +54 -0
  98. package/lib/index.js +64 -0
  99. package/lib/lang/index.js +66 -0
  100. package/lib/locals/de.js +7 -0
  101. package/lib/locals/en.js +22 -0
  102. package/lib/locals/fr.js +7 -0
  103. package/lib/locals/zh-CN.js +22 -0
  104. package/lib/utils/cell-value-validator.js +41 -0
  105. package/lib/utils/column-utils.js +15 -0
  106. package/lib/utils/editor-utils.js +81 -0
  107. package/lib/utils/markdown2html.js +68 -0
  108. package/lib/utils/normalize-long-text-value.js +74 -0
  109. package/lib/utils/number-precision.js +181 -0
  110. package/lib/utils/unified/index.js +470 -0
  111. package/lib/utils/utils.js +141 -0
  112. package/lib/utils/value-format-utils.js +545 -0
  113. package/lib/utils/vfile/core.js +172 -0
  114. package/lib/utils/vfile/index.js +48 -0
  115. package/package.json +3 -3
@@ -0,0 +1,545 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.formatStringToNumber = exports.formatNumberString = void 0;
7
+ exports.getCellValueDisplayString = getCellValueDisplayString;
8
+ exports.getOptionName = exports.getNumberDisplayString = exports.getMultipleOptionName = exports.getLongtextDisplayString = exports.getGeolocationDisplayString = exports.getFormulaDisplayString = exports.getDurationDisplayString = exports.getDateDisplayString = exports.getCollaboratorsName = void 0;
9
+
10
+ var _moment = _interopRequireDefault(require("moment"));
11
+
12
+ var _numberPrecision = _interopRequireDefault(require("./number-precision"));
13
+
14
+ var _constants = require("../constants");
15
+
16
+ var CellType = _interopRequireWildcard(require("../constants/cell-types"));
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ _numberPrecision.default.enableBoundaryChecking(false);
23
+
24
+ var _separatorMap = {
25
+ 'comma': ',',
26
+ 'dot': '.',
27
+ 'no': '',
28
+ 'space': ' '
29
+ };
30
+
31
+ var _toThousands = function _toThousands(num, isCurrency, formatData) {
32
+ var _ref = formatData || {},
33
+ _ref$decimal = _ref.decimal,
34
+ decimal = _ref$decimal === void 0 ? 'dot' : _ref$decimal,
35
+ _ref$thousands = _ref.thousands,
36
+ thousands = _ref$thousands === void 0 ? 'no' : _ref$thousands,
37
+ _ref$precision = _ref.precision,
38
+ precision = _ref$precision === void 0 ? 2 : _ref$precision,
39
+ _ref$enable_precision = _ref.enable_precision,
40
+ enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
41
+
42
+ var decimalString = _separatorMap[decimal];
43
+ var thousandsString = _separatorMap[thousands];
44
+ var decimalDigits = enable_precision ? precision : _getDecimalDigits(num);
45
+ var value = parseFloat(num.toFixed(decimalDigits));
46
+ var integer = Math.trunc(value);
47
+ var decimalValue = String(Math.abs(_numberPrecision.default.minus(value, integer)).toFixed(decimalDigits)).slice(1);
48
+
49
+ if (isCurrency) {
50
+ if (decimalValue.length === 2) {
51
+ decimalValue = decimalValue.padEnd(3, '0');
52
+ } else {
53
+ decimalValue = (decimalValue.substring(0, 3) || '.').padEnd(3, '0');
54
+ }
55
+
56
+ if (enable_precision) {
57
+ decimalValue = precision === 0 ? '' : decimalValue.slice(0, precision + 1);
58
+ }
59
+ }
60
+
61
+ decimalValue = decimalValue.replace(/./, decimalString);
62
+ var result = [],
63
+ counter = 0;
64
+ integer = Object.is(integer, -0) ? ['-', '0'] : integer.toString().split('');
65
+
66
+ for (var i = integer.length - 1; i >= 0; i--) {
67
+ counter++;
68
+ result.unshift(integer[i]);
69
+
70
+ if (!(counter % 3) && i !== 0) {
71
+ result.unshift(thousandsString);
72
+ }
73
+ }
74
+
75
+ return result.join('') + decimalValue;
76
+ };
77
+
78
+ var _getDecimalDigits = function _getDecimalDigits(num) {
79
+ if (Number.isInteger(num)) {
80
+ return 0;
81
+ }
82
+
83
+ var valueArr = (num + '').split('.');
84
+ var digitsLength = valueArr[1] ? valueArr[1].length : 8;
85
+ return digitsLength > 8 ? 8 : digitsLength;
86
+ };
87
+
88
+ var getNumberDisplayString = function getNumberDisplayString(value, formatData) {
89
+ // formatData: old version maybe 'null'
90
+ var type = Object.prototype.toString.call(value);
91
+
92
+ if (type !== '[object Number]') {
93
+ if (type === '[object String]' && value.startsWith('#')) {
94
+ return value;
95
+ }
96
+
97
+ return null;
98
+ }
99
+
100
+ if (isNaN(value) || value === Infinity || value === -Infinity || (value + '').indexOf('e') > -1) return value + '';
101
+
102
+ var _ref2 = formatData || {},
103
+ _ref2$format = _ref2.format,
104
+ format = _ref2$format === void 0 ? _constants.DEFAULT_NUMBER_FORMAT : _ref2$format;
105
+
106
+ switch (format) {
107
+ case 'number':
108
+ return _toThousands(value, false, formatData);
109
+
110
+ case 'percent':
111
+ {
112
+ return _toThousands(Number.parseFloat((value * 100).toFixed(8)), false, formatData) + "%";
113
+ }
114
+
115
+ case 'yuan':
116
+ return "\uFFE5" + _toThousands(value, true, formatData);
117
+
118
+ case 'dollar':
119
+ return "$" + _toThousands(value, true, formatData);
120
+
121
+ case 'euro':
122
+ return "\u20AC" + _toThousands(value, true, formatData);
123
+
124
+ case 'duration':
125
+ {
126
+ return getDurationDisplayString(value, formatData.duration_format);
127
+ }
128
+
129
+ default:
130
+ return '' + value;
131
+ }
132
+ };
133
+
134
+ exports.getNumberDisplayString = getNumberDisplayString;
135
+
136
+ var formatStringToNumber = function formatStringToNumber(value) {
137
+ var isIncludePercent = value.indexOf('%') > -1;
138
+ var newData = parseFloat(value.replace(/[^.-\d]/g, ''));
139
+
140
+ if (isIncludePercent && !isNaN(newData)) {
141
+ return newData / 100;
142
+ }
143
+
144
+ return isNaN(newData) ? '' : newData;
145
+ };
146
+
147
+ exports.formatStringToNumber = formatStringToNumber;
148
+
149
+ var formatNumberString = function formatNumberString(value, format) {
150
+ var formattedValue = '';
151
+
152
+ switch (format) {
153
+ case _constants.NUMBER_TYPES.NUMBER:
154
+ case _constants.NUMBER_TYPES.NUMBER_WITH_COMMAS:
155
+ formattedValue = value.replace(/[^.-\d,]/g, '');
156
+ break;
157
+
158
+ case _constants.NUMBER_TYPES.PERCENT:
159
+ formattedValue = value.replace(/[^.-\d,%]/g, '');
160
+ break;
161
+
162
+ case _constants.NUMBER_TYPES.YUAN:
163
+ formattedValue = value.replace(/[^.-\d¥,]/g, '');
164
+ break;
165
+
166
+ case _constants.NUMBER_TYPES.DOLLAR:
167
+ formattedValue = value.replace(/[^.-\d$,]/g, '');
168
+ break;
169
+
170
+ case _constants.NUMBER_TYPES.EURO:
171
+ formattedValue = value.replace(/[^.-\d€,]/g, '');
172
+ break;
173
+
174
+ default:
175
+ formattedValue = value.replace(/[^.-\d,]/g, '');
176
+ }
177
+
178
+ return formattedValue;
179
+ };
180
+
181
+ exports.formatNumberString = formatNumberString;
182
+
183
+ var getDateDisplayString = function getDateDisplayString(value, format) {
184
+ var formattedValue = '';
185
+
186
+ if (!value) {
187
+ // value === '', value === undefine, value === null
188
+ return formattedValue;
189
+ }
190
+
191
+ var date = (0, _moment.default)(value);
192
+ if (!date.isValid()) return value;
193
+
194
+ switch (format) {
195
+ case 'D/M/YYYY':
196
+ case 'DD/MM/YYYY':
197
+ var formatValue = date.format('YYYY-MM-DD');
198
+ var formatValueList = formatValue.split('-');
199
+ return formatValueList[2] + "/" + formatValueList[1] + "/" + formatValueList[0];
200
+
201
+ case 'D/M/YYYY HH:mm':
202
+ case 'DD/MM/YYYY HH:mm':
203
+ var formatValues = date.format('YYYY-MM-DD HH:mm');
204
+ var formatValuesList = formatValues.split(' ');
205
+ var formatDateList = formatValuesList[0].split('-');
206
+ return formatDateList[2] + "/" + formatDateList[1] + "/" + formatDateList[0] + " " + formatValuesList[1];
207
+
208
+ case 'M/D/YYYY':
209
+ return date.format('M/D/YYYY');
210
+
211
+ case 'M/D/YYYY HH:mm':
212
+ return date.format('M/D/YYYY HH:mm');
213
+
214
+ case 'YYYY-MM-DD':
215
+ return date.format('YYYY-MM-DD');
216
+
217
+ case 'YYYY-MM-DD HH:mm':
218
+ return date.format('YYYY-MM-DD HH:mm');
219
+
220
+ default:
221
+ return value;
222
+ }
223
+ };
224
+
225
+ exports.getDateDisplayString = getDateDisplayString;
226
+
227
+ var getDurationDisplayString = function getDurationDisplayString(value, duration_format) {
228
+ if (!value && value !== 0) return '';
229
+ duration_format = duration_format || _constants.DURATION_FORMATS_MAP.H_MM;
230
+
231
+ if (_constants.DURATION_FORMATS.findIndex(function (format) {
232
+ return format.type === duration_format;
233
+ }) < 0) {
234
+ return '';
235
+ }
236
+
237
+ if (value === 0) {
238
+ return _constants.DURATION_ZERO_DISPLAY[duration_format];
239
+ }
240
+
241
+ var includeDecimal = duration_format.indexOf('.') > -1;
242
+ var positiveValue = Math.abs(value);
243
+
244
+ if (!includeDecimal) {
245
+ positiveValue = Math.round(positiveValue);
246
+ }
247
+
248
+ positiveValue = getMathRoundedDuration(positiveValue, duration_format);
249
+ var decimalParts = (positiveValue + '').split('.');
250
+ var decimalPartsLen = decimalParts.length;
251
+ var decimal = 0;
252
+
253
+ if (decimalPartsLen > 1) {
254
+ decimal = decimalParts[decimalPartsLen - 1];
255
+ decimal = decimal ? decimal - 0 : 0;
256
+ }
257
+
258
+ var decimalDigits = _constants.DURATION_DECIMAL_DIGITS[duration_format];
259
+ var decimalSuffix = getDurationDecimalSuffix(duration_format, decimal);
260
+ var displayString = value < 0 ? '-' : '';
261
+ var hours = parseInt(positiveValue / 3600);
262
+ var minutes = parseInt((positiveValue - hours * 3600) / 60);
263
+
264
+ if (duration_format === _constants.DURATION_FORMATS_MAP.H_MM) {
265
+ displayString += hours + ":" + (minutes > 9 ? minutes : '0' + minutes);
266
+ return displayString;
267
+ }
268
+
269
+ var seconds = Number.parseFloat((positiveValue - hours * 3600 - minutes * 60).toFixed(decimalDigits));
270
+
271
+ if (hours > 0) {
272
+ displayString += hours + ":";
273
+ minutes = minutes > 9 ? minutes : "0" + minutes;
274
+ }
275
+
276
+ seconds = seconds > 9 ? seconds : "0" + seconds;
277
+ displayString += minutes + ":" + seconds + decimalSuffix;
278
+ return displayString;
279
+ };
280
+
281
+ exports.getDurationDisplayString = getDurationDisplayString;
282
+
283
+ var getMathRoundedDuration = function getMathRoundedDuration(num, duration_format) {
284
+ var decimalDigits = _constants.DURATION_DECIMAL_DIGITS[duration_format];
285
+
286
+ if (decimalDigits < 1) {
287
+ return num;
288
+ }
289
+
290
+ var ratio = Math.pow(10, decimalDigits);
291
+ return Math.round(num * ratio) / ratio;
292
+ };
293
+
294
+ var getDurationDecimalSuffix = function getDurationDecimalSuffix(duration_format, decimal) {
295
+ if (duration_format === _constants.DURATION_FORMATS_MAP.H_MM_SS_S) {
296
+ return decimal === 0 ? '.0' : '';
297
+ } else if (duration_format === _constants.DURATION_FORMATS_MAP.H_MM_SS_SS) {
298
+ if (decimal === 0) {
299
+ return '.00';
300
+ } else if (decimal < 10) {
301
+ return '0';
302
+ }
303
+ } else if (duration_format === _constants.DURATION_FORMATS_MAP.H_MM_SS_SSS) {
304
+ if (decimal === 0) {
305
+ return '.000';
306
+ } else if (decimal < 10) {
307
+ return '00';
308
+ } else if (decimal < 100) {
309
+ return '0';
310
+ }
311
+ }
312
+
313
+ return '';
314
+ };
315
+
316
+ var getOptionName = function getOptionName(options, targetOptionID) {
317
+ if (!targetOptionID || !options || !Array.isArray(options)) return null;
318
+ var option = options.find(function (option) {
319
+ return option.id === targetOptionID;
320
+ });
321
+ return option ? option.name : null;
322
+ };
323
+
324
+ exports.getOptionName = getOptionName;
325
+
326
+ var getMultipleOptionName = function getMultipleOptionName(options, cellVal) {
327
+ if (!cellVal || !options || !Array.isArray(options)) return null;
328
+ var selectedOptions = options.filter(function (option) {
329
+ return cellVal.includes(option.id);
330
+ });
331
+ if (selectedOptions.length === 0) return null;
332
+ return selectedOptions.map(function (option) {
333
+ return option.name;
334
+ }).join(', ');
335
+ };
336
+
337
+ exports.getMultipleOptionName = getMultipleOptionName;
338
+
339
+ var getLongtextDisplayString = function getLongtextDisplayString(value) {
340
+ var _ref3 = value || {},
341
+ text = _ref3.text;
342
+
343
+ if (!text) {
344
+ return null;
345
+ }
346
+
347
+ return text;
348
+ };
349
+
350
+ exports.getLongtextDisplayString = getLongtextDisplayString;
351
+
352
+ var getCollaboratorsName = function getCollaboratorsName(collaborators, cellVal) {
353
+ if (cellVal) {
354
+ var collaboratorsName = [];
355
+ cellVal.forEach(function (v) {
356
+ var collaborator = collaborators.find(function (c) {
357
+ return c.email === v;
358
+ });
359
+
360
+ if (collaborator) {
361
+ collaboratorsName.push(collaborator.name);
362
+ }
363
+ });
364
+
365
+ if (collaboratorsName.length === 0) {
366
+ return null;
367
+ }
368
+
369
+ return collaboratorsName.join(', ');
370
+ }
371
+
372
+ return null;
373
+ };
374
+
375
+ exports.getCollaboratorsName = getCollaboratorsName;
376
+
377
+ var getGeolocationDisplayString = function getGeolocationDisplayString(value, columnData) {
378
+ var _ref4 = columnData || {},
379
+ geo_format = _ref4.geo_format;
380
+
381
+ var cellValue = value || {};
382
+
383
+ if (!value) {
384
+ return null;
385
+ }
386
+
387
+ if (geo_format === 'lng_lat' && value.lng && value.lat) {
388
+ return cellValue.lng + ", " + cellValue.lat;
389
+ }
390
+
391
+ if (geo_format === 'country_region' && cellValue.country_region) {
392
+ return value.country_region || '';
393
+ }
394
+
395
+ var province = cellValue.province,
396
+ city = cellValue.city,
397
+ district = cellValue.district,
398
+ detail = cellValue.detail;
399
+
400
+ if (geo_format === 'province') {
401
+ return "" + (province || '');
402
+ }
403
+
404
+ if (geo_format === 'province_city') {
405
+ return "" + (province || '') + (city || '');
406
+ }
407
+
408
+ return "" + (province || '') + (city || '') + (district || '') + (detail || '');
409
+ };
410
+
411
+ exports.getGeolocationDisplayString = getGeolocationDisplayString;
412
+
413
+ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, columnData, _temp) {
414
+ var _ref5 = _temp === void 0 ? {} : _temp,
415
+ _ref5$collaborators = _ref5.collaborators,
416
+ collaborators = _ref5$collaborators === void 0 ? [] : _ref5$collaborators;
417
+
418
+ if (!columnData) {
419
+ return null;
420
+ }
421
+
422
+ var result_type = columnData.result_type;
423
+
424
+ if (result_type === _constants.FORMULA_RESULT_TYPE.NUMBER) {
425
+ return getNumberDisplayString(cellValue, columnData);
426
+ }
427
+
428
+ if (result_type === _constants.FORMULA_RESULT_TYPE.DATE) {
429
+ var format = columnData.format;
430
+ return getDateDisplayString(cellValue, format);
431
+ }
432
+
433
+ if (result_type === _constants.FORMULA_RESULT_TYPE.ARRAY) {
434
+ var array_type = columnData.array_type,
435
+ array_data = columnData.array_data;
436
+
437
+ if (!array_type) {
438
+ return null;
439
+ }
440
+
441
+ if (_constants.COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
442
+ return cellValue;
443
+ }
444
+
445
+ if (_constants.ARRAY_FORMAL_COLUMNS_TYPES.indexOf(array_type) < 0 && Array.isArray(cellValue)) {
446
+ return cellValue.map(function (val) {
447
+ return getCellValueDisplayString(val, array_type, {
448
+ data: array_data,
449
+ collaborators: collaborators
450
+ });
451
+ }).join(', ');
452
+ }
453
+
454
+ return getCellValueDisplayString(cellValue, array_type, {
455
+ data: array_data,
456
+ collaborators: collaborators
457
+ });
458
+ }
459
+
460
+ if (Object.prototype.toString.call(cellValue) === '[object Boolean]') {
461
+ return cellValue + '';
462
+ }
463
+
464
+ return cellValue;
465
+ };
466
+
467
+ exports.getFormulaDisplayString = getFormulaDisplayString;
468
+
469
+ function getCellValueDisplayString(cellValue, type, _temp2) {
470
+ var _ref6 = _temp2 === void 0 ? {} : _temp2,
471
+ data = _ref6.data,
472
+ _ref6$collaborators = _ref6.collaborators,
473
+ collaborators = _ref6$collaborators === void 0 ? [] : _ref6$collaborators;
474
+
475
+ var newData = data || {};
476
+
477
+ switch (type) {
478
+ case CellType.GEOLOCATION:
479
+ {
480
+ return getGeolocationDisplayString(cellValue, data);
481
+ }
482
+
483
+ case CellType.SINGLE_SELECT:
484
+ {
485
+ if (!data) return '';
486
+ var options = newData.options;
487
+ return getOptionName(options, cellValue);
488
+ }
489
+
490
+ case CellType.MULTIPLE_SELECT:
491
+ {
492
+ if (!data) return '';
493
+ var _options = newData.options;
494
+ return getMultipleOptionName(_options, cellValue);
495
+ }
496
+
497
+ case CellType.FORMULA:
498
+ case CellType.LINK_FORMULA:
499
+ {
500
+ return getFormulaDisplayString(cellValue, newData, {
501
+ collaborators: collaborators
502
+ });
503
+ }
504
+
505
+ case CellType.LONG_TEXT:
506
+ {
507
+ return getLongtextDisplayString(cellValue);
508
+ }
509
+
510
+ case CellType.NUMBER:
511
+ {
512
+ return getNumberDisplayString(cellValue, newData);
513
+ }
514
+
515
+ case CellType.DATE:
516
+ {
517
+ var _ref7 = newData || {},
518
+ _ref7$format = _ref7.format,
519
+ format = _ref7$format === void 0 ? _constants.DEFAULT_DATE_FORMAT : _ref7$format;
520
+
521
+ return getDateDisplayString(cellValue, format);
522
+ }
523
+
524
+ case CellType.CREATOR:
525
+ case CellType.LAST_MODIFIER:
526
+ {
527
+ return cellValue === 'anonymous' ? cellValue : getCollaboratorsName(collaborators, [cellValue]);
528
+ }
529
+
530
+ case CellType.COLLABORATOR:
531
+ {
532
+ return getCollaboratorsName(collaborators, cellValue);
533
+ }
534
+
535
+ case CellType.DURATION:
536
+ {
537
+ return getDurationDisplayString(cellValue, data);
538
+ }
539
+
540
+ default:
541
+ {
542
+ return cellValue ? cellValue + '' : '';
543
+ }
544
+ }
545
+ }
@@ -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
+ }