dtable-ui-component 0.1.75-beta3 → 0.1.75-beta4

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