dtable-ui-component 0.3.0 → 0.3.2-alpha1

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.
@@ -0,0 +1,369 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
+
7
+ var _emptyTypeMap;
8
+
9
+ import React, { Fragment } from 'react';
10
+ import { CellType } from 'dtable-store';
11
+ import { TextFormatter, NumberFormatter, CheckboxFormatter, DateFormatter, SingleSelectFormatter, MultipleSelectFormatter, CollaboratorFormatter, SimpleLongTextFormatter, GeolocationFormatter, LinkFormatter, CTimeFormatter, CreatorFormatter, LastModifierFormatter, MTimeFormatter, AutoNumberFormatter, UrlFormatter, EmailFormatter, DurationFormatter, RateFormatter, ButtonFormatter, ImageFormatter, RowExpandFileFormatter // LongTextFormatter,
12
+ // FormulaFormatter,
13
+ } from './index';
14
+ import { COLLABORATORS } from './data/dtable-value';
15
+ var emptyTypeMap = (_emptyTypeMap = {}, _defineProperty(_emptyTypeMap, CellType.TEXT, true), _defineProperty(_emptyTypeMap, CellType.LONG_TEXT, true), _defineProperty(_emptyTypeMap, CellType.GEOLOCATION, true), _defineProperty(_emptyTypeMap, CellType.SINGLE_SELECT, true), _defineProperty(_emptyTypeMap, CellType.MULTIPLE_SELECT, true), _defineProperty(_emptyTypeMap, CellType.CTIME, true), _defineProperty(_emptyTypeMap, CellType.MTIME, true), _defineProperty(_emptyTypeMap, CellType.DATE, true), _defineProperty(_emptyTypeMap, CellType.AUTO_NUMBER, true), _defineProperty(_emptyTypeMap, CellType.URL, true), _defineProperty(_emptyTypeMap, CellType.EMAIL, true), _defineProperty(_emptyTypeMap, CellType.DURATION, true), _defineProperty(_emptyTypeMap, CellType.IMAGE, true), _defineProperty(_emptyTypeMap, CellType.FILE, true), _emptyTypeMap);
16
+
17
+ var noop = function noop() {};
18
+
19
+ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
20
+ _inherits(EditorFormatter, _React$Component);
21
+
22
+ var _super = _createSuper(EditorFormatter);
23
+
24
+ function EditorFormatter(props) {
25
+ var _this;
26
+
27
+ _classCallCheck(this, EditorFormatter);
28
+
29
+ _this = _super.call(this, props);
30
+
31
+ _this.renderEmptyFormatter = function () {
32
+ var emptyFormatter = /*#__PURE__*/React.createElement("span", {
33
+ className: "row-cell-empty d-inline-block"
34
+ });
35
+
36
+ if (_this.props.type === 'row_title') {
37
+ emptyFormatter = /*#__PURE__*/React.createElement("span", null, "\u672A\u547D\u540D\u884C");
38
+ }
39
+
40
+ return emptyFormatter;
41
+ };
42
+
43
+ _this.renderFormatter = function () {
44
+ var _this$props = _this.props,
45
+ column = _this$props.column,
46
+ row = _this$props.row,
47
+ CellType = _this$props.CellType,
48
+ className = _this$props.className;
49
+ var columnType = column.type;
50
+ var collaborators = _this.state.collaborators;
51
+ var containerClassName = "dtable-".concat(columnType, "-formatter ").concat(className || '');
52
+ var cellValue = row[column.key];
53
+
54
+ if (!cellValue && emptyTypeMap[columnType]) {
55
+ return _this.renderEmptyFormatter();
56
+ }
57
+
58
+ switch (columnType) {
59
+ case CellType.TEXT:
60
+ {
61
+ return /*#__PURE__*/React.createElement(TextFormatter, {
62
+ value: cellValue,
63
+ containerClassName: containerClassName
64
+ });
65
+ }
66
+
67
+ case CellType.COLLABORATOR:
68
+ {
69
+ if (!cellValue || cellValue.length === 0) {
70
+ return _this.renderEmptyFormatter();
71
+ }
72
+
73
+ var collaboratorFormatter = /*#__PURE__*/React.createElement(CollaboratorFormatter, {
74
+ value: cellValue,
75
+ collaborators: collaborators,
76
+ containerClassName: containerClassName
77
+ });
78
+ return collaboratorFormatter;
79
+ }
80
+
81
+ case CellType.LONG_TEXT:
82
+ {
83
+ var longTextFormatter = /*#__PURE__*/React.createElement(SimpleLongTextFormatter, {
84
+ value: cellValue,
85
+ containerClassName: containerClassName
86
+ });
87
+
88
+ if (!cellValue) {
89
+ longTextFormatter = _this.renderEmptyFormatter();
90
+ }
91
+
92
+ return longTextFormatter;
93
+ }
94
+
95
+ case CellType.IMAGE:
96
+ {
97
+ var imageFormatter = /*#__PURE__*/React.createElement(ImageFormatter, {
98
+ value: cellValue
99
+ });
100
+
101
+ if (!cellValue || cellValue.length === 0) {
102
+ imageFormatter = _this.renderEmptyFormatter();
103
+ }
104
+
105
+ return imageFormatter;
106
+ }
107
+
108
+ case CellType.GEOLOCATION:
109
+ {
110
+ var geolocationFormatter = /*#__PURE__*/React.createElement(GeolocationFormatter, {
111
+ value: cellValue,
112
+ data: column.data,
113
+ containerClassName: containerClassName
114
+ });
115
+
116
+ if (!cellValue) {
117
+ geolocationFormatter = _this.renderEmptyFormatter();
118
+ }
119
+
120
+ return geolocationFormatter;
121
+ }
122
+
123
+ case CellType.NUMBER:
124
+ {
125
+ var numberFormatter = /*#__PURE__*/React.createElement(NumberFormatter, {
126
+ value: cellValue,
127
+ data: column.data,
128
+ containerClassName: containerClassName
129
+ });
130
+
131
+ if (!cellValue) {
132
+ numberFormatter = _this.renderEmptyFormatter();
133
+ }
134
+
135
+ return numberFormatter;
136
+ }
137
+
138
+ case CellType.DATE:
139
+ {
140
+ var dateFormatter = /*#__PURE__*/React.createElement(DateFormatter, {
141
+ value: cellValue,
142
+ format: column.data.format,
143
+ containerClassName: containerClassName
144
+ });
145
+
146
+ if (!cellValue) {
147
+ dateFormatter = _this.renderEmptyFormatter();
148
+ }
149
+
150
+ return dateFormatter;
151
+ }
152
+
153
+ case CellType.MULTIPLE_SELECT:
154
+ {
155
+ var options = column.data ? column.data.options : [];
156
+ var multipleSelectFormatter = /*#__PURE__*/React.createElement(MultipleSelectFormatter, {
157
+ value: cellValue,
158
+ options: options,
159
+ containerClassName: containerClassName
160
+ });
161
+
162
+ if (!cellValue || cellValue.length === 0) {
163
+ multipleSelectFormatter = _this.renderEmptyFormatter();
164
+ }
165
+
166
+ return multipleSelectFormatter;
167
+ }
168
+
169
+ case CellType.SINGLE_SELECT:
170
+ {
171
+ var _options = column.data ? column.data.options : [];
172
+
173
+ var singleSelectFormatter = /*#__PURE__*/React.createElement(SingleSelectFormatter, {
174
+ value: cellValue,
175
+ options: _options,
176
+ containerClassName: containerClassName
177
+ });
178
+
179
+ if (!cellValue) {
180
+ singleSelectFormatter = _this.renderEmptyFormatter();
181
+ }
182
+
183
+ return singleSelectFormatter;
184
+ }
185
+
186
+ case CellType.FILE:
187
+ {
188
+ var fileFormatter = /*#__PURE__*/React.createElement(RowExpandFileFormatter, {
189
+ value: cellValue,
190
+ column: column,
191
+ downloadFile: noop,
192
+ deleteFile: noop,
193
+ readOnly: false
194
+ });
195
+
196
+ if (!cellValue || cellValue.length === 0) {
197
+ fileFormatter = _this.renderEmptyFormatter();
198
+ }
199
+
200
+ return fileFormatter;
201
+ }
202
+
203
+ case CellType.CHECKBOX:
204
+ {
205
+ return /*#__PURE__*/React.createElement(CheckboxFormatter, {
206
+ value: cellValue
207
+ });
208
+ }
209
+
210
+ case CellType.CTIME:
211
+ {
212
+ var cTimeFormatter = /*#__PURE__*/React.createElement(CTimeFormatter, {
213
+ value: row._ctime,
214
+ containerClassName: containerClassName
215
+ });
216
+
217
+ if (!row._ctime) {
218
+ cTimeFormatter = _this.renderEmptyFormatter();
219
+ }
220
+
221
+ return cTimeFormatter;
222
+ }
223
+
224
+ case CellType.MTIME:
225
+ {
226
+ var mTimeFormatter = /*#__PURE__*/React.createElement(MTimeFormatter, {
227
+ value: row._mtime,
228
+ containerClassName: containerClassName
229
+ });
230
+
231
+ if (!row._mtime) {
232
+ mTimeFormatter = _this.renderEmptyFormatter();
233
+ }
234
+
235
+ return mTimeFormatter;
236
+ }
237
+
238
+ case CellType.CREATOR:
239
+ {
240
+ if (!cellValue) return _this.renderEmptyFormatter();
241
+ var creatorFormatter = /*#__PURE__*/React.createElement(CreatorFormatter, {
242
+ collaborators: collaborators,
243
+ value: cellValue,
244
+ containerClassName: containerClassName
245
+ });
246
+ return creatorFormatter;
247
+ }
248
+
249
+ case CellType.LAST_MODIFIER:
250
+ {
251
+ if (!cellValue) return _this.renderEmptyFormatter();
252
+ var lastModifierFormatter = /*#__PURE__*/React.createElement(LastModifierFormatter, {
253
+ collaborators: collaborators,
254
+ value: cellValue,
255
+ containerClassName: containerClassName
256
+ });
257
+ return lastModifierFormatter;
258
+ }
259
+
260
+ case CellType.FORMULA:
261
+ case CellType.LINK_FORMULA:
262
+ {
263
+ var textFormatter = /*#__PURE__*/React.createElement(TextFormatter, {
264
+ value: cellValue,
265
+ containerClassName: containerClassName
266
+ });
267
+
268
+ if (!cellValue) {
269
+ textFormatter = _this.renderEmptyFormatter();
270
+ }
271
+
272
+ return textFormatter;
273
+ }
274
+
275
+ case CellType.LINK:
276
+ {
277
+ if (!Array.isArray(cellValue) || cellValue.length === 0) return _this.renderEmptyFormatter();
278
+ return /*#__PURE__*/React.createElement(LinkFormatter, {
279
+ value: cellValue,
280
+ column: column,
281
+ collaborators: collaborators,
282
+ containerClassName: 'map-app-link-formatter',
283
+ renderEmptyFormatter: _this.renderEmptyFormatter,
284
+ getOptionColors: _this.props.getOptionColors,
285
+ getUserCommonInfo: function getUserCommonInfo() {},
286
+ CellType: CellType
287
+ });
288
+ }
289
+
290
+ case CellType.AUTO_NUMBER:
291
+ {
292
+ return /*#__PURE__*/React.createElement(AutoNumberFormatter, {
293
+ value: cellValue,
294
+ containerClassName: containerClassName
295
+ });
296
+ }
297
+
298
+ case CellType.URL:
299
+ {
300
+ return /*#__PURE__*/React.createElement(UrlFormatter, {
301
+ value: cellValue,
302
+ containerClassName: containerClassName
303
+ });
304
+ }
305
+
306
+ case CellType.EMAIL:
307
+ {
308
+ return /*#__PURE__*/React.createElement(EmailFormatter, {
309
+ value: cellValue,
310
+ containerClassName: containerClassName
311
+ });
312
+ }
313
+
314
+ case CellType.DURATION:
315
+ {
316
+ return /*#__PURE__*/React.createElement(DurationFormatter, {
317
+ value: cellValue,
318
+ format: column.data.duration_format,
319
+ containerClassName: containerClassName
320
+ });
321
+ }
322
+
323
+ case CellType.RATE:
324
+ {
325
+ return /*#__PURE__*/React.createElement(RateFormatter, {
326
+ value: cellValue,
327
+ data: column.data,
328
+ containerClassName: containerClassName
329
+ });
330
+ }
331
+
332
+ case CellType.BUTTON:
333
+ {
334
+ var _column$data = column.data,
335
+ data = _column$data === void 0 ? {} : _column$data;
336
+ var buttonFormatter = /*#__PURE__*/React.createElement(ButtonFormatter, {
337
+ data: data,
338
+ containerClassName: containerClassName
339
+ });
340
+
341
+ if (!data.button_name) {
342
+ buttonFormatter = _this.renderEmptyFormatter();
343
+ }
344
+
345
+ return buttonFormatter;
346
+ }
347
+
348
+ default:
349
+ return null;
350
+ }
351
+ };
352
+
353
+ _this.state = {
354
+ collaborators: COLLABORATORS
355
+ };
356
+ return _this;
357
+ }
358
+
359
+ _createClass(EditorFormatter, [{
360
+ key: "render",
361
+ value: function render() {
362
+ return /*#__PURE__*/React.createElement(Fragment, null, this.renderFormatter());
363
+ }
364
+ }]);
365
+
366
+ return EditorFormatter;
367
+ }(React.Component);
368
+
369
+ export default EditorFormatter;
package/lib/index.js CHANGED
@@ -32,7 +32,11 @@ export { default as RateFormatter } from './RateFormatter';
32
32
  export { default as ButtonFormatter } from './ButtonFormatter';
33
33
  export { default as ImagePreviewerLightbox } from './ImagePreviewerLightbox';
34
34
  export { default as CollaboratorItem } from './CollaboratorItem';
35
- export { default as FileItemFormatter } from './FileItemFormatter'; // editor
35
+ export { default as FileItemFormatter } from './FileItemFormatter';
36
+ export { default as DigitalSignFormatter } from './DigitalSignFormatter';
37
+ export { default as SimpleLongTextFormatter } from './SimpleLongTextFormatter'; // row expand formatter
38
+
39
+ export { default as RowExpandFileFormatter } from './FileFormatter/row-expand-file-formatter'; // editor
36
40
 
37
41
  export { default as TextEditor } from './TextEditor';
38
42
  export { default as NumberEditor } from './NumberEditor';
package/lib/lang/index.js CHANGED
@@ -9,7 +9,7 @@ var langData = {
9
9
  'zh-cn': zh_CN
10
10
  };
11
11
  var LANGUAGE = 'en';
12
- var LANGUAGE_MAP = {};
12
+ var LANGUAGE_MAP = langData[LANGUAGE];
13
13
  export function setLocale(args) {
14
14
  var lang = typeof args === 'string' ? args : LANGUAGE;
15
15
  LANGUAGE_MAP = langData[lang] || langData[LANGUAGE];
package/lib/locals/en.js CHANGED
@@ -1,17 +1,20 @@
1
1
  var en = {
2
- Add_an_option: "Add an option",
3
- Find_an_option: "Find a option",
4
- No_options_available: "No options available",
5
- Current_option: "Current option",
6
- No_option: "No option",
7
- Choose_an_option: "Choose an option",
8
- Add_a_collaborator: "Add a collaborator",
9
- Find_a_collaborator: "Find a collaborator",
10
- No_collaborators_available: "No collaborators available",
2
+ Add_an_option: 'Add an option',
3
+ Find_an_option: 'Find a option',
4
+ No_options_available: 'No options available',
5
+ Current_option: 'Current option',
6
+ No_option: 'No option',
7
+ Choose_an_option: 'Choose an option',
8
+ Add_a_collaborator: 'Add a collaborator',
9
+ Find_a_collaborator: 'Find a collaborator',
10
+ No_collaborators_available: 'No collaborators available',
11
11
  Done: 'Done',
12
- Choose_a_collaborator: "Choose a collaborator",
13
- Please_input: "Please input",
14
- Please_select: "Please select",
15
- Clear: "Clear"
12
+ Choose_a_collaborator: 'Choose a collaborator',
13
+ Please_input: 'Please input',
14
+ Please_select: 'Please select',
15
+ Clear: 'Clear',
16
+ Are_you_sure_you_want_to_delete_this_file: 'Are you sure you want to delete this file?',
17
+ Cancel: 'Cancel',
18
+ Delete: 'Delete'
16
19
  };
17
20
  export default en;
@@ -1,17 +1,20 @@
1
1
  var zh_CN = {
2
2
  Add_an_option: '添加一个选项',
3
- Find_an_option: "查找标签",
4
- No_options_available: "没有找到标签。",
5
- Current_option: "当前标签",
6
- No_option: "没有标签",
7
- Choose_an_option: "选择一个标签",
8
- Add_a_collaborator: "添加协作者",
9
- Find_a_collaborator: "查找协作者",
10
- No_collaborators_available: "没有找到协作者",
3
+ Find_an_option: '查找标签',
4
+ No_options_available: '没有找到标签。',
5
+ Current_option: '当前标签',
6
+ No_option: '没有标签',
7
+ Choose_an_option: '选择一个标签',
8
+ Add_a_collaborator: '添加协作者',
9
+ Find_a_collaborator: '查找协作者',
10
+ No_collaborators_available: '没有找到协作者',
11
11
  Done: '完成',
12
- Choose_a_collaborator: "选择一个协作者",
13
- Please_input: "请输入",
14
- Please_select: "请选择",
15
- Clear: "清空"
12
+ Choose_a_collaborator: '选择一个协作者',
13
+ Please_input: '请输入',
14
+ Please_select: '请选择',
15
+ Clear: '清空',
16
+ Are_you_sure_you_want_to_delete_this_file: '你确定要删除此文件吗?',
17
+ Cancel: '取消',
18
+ Delete: '删除'
16
19
  };
17
20
  export default zh_CN;
@@ -41,4 +41,17 @@ export var isMac = function isMac() {
41
41
  var platform = navigator.platform; // eslint-disable-next-line eqeqeq
42
42
 
43
43
  return platform == 'Mac68K' || platform == 'MacPPC' || platform == 'Macintosh' || platform == 'MacIntel';
44
+ };
45
+ export var downloadFile = function downloadFile(downloadUrl) {
46
+ var downloadFrame = document.getElementById('dtableUiComponentDownloadFrame');
47
+
48
+ if (downloadFrame != null) {
49
+ document.body.removeChild(downloadFrame);
50
+ }
51
+
52
+ var iframe = document.createElement('iframe');
53
+ iframe.setAttribute('id', 'dtableUiComponentDownloadFrame');
54
+ iframe.style.display = 'none';
55
+ iframe.src = downloadUrl;
56
+ document.body.appendChild(iframe);
44
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "0.3.0",
3
+ "version": "0.3.2-alpha1",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "0.0.9",
@@ -9,8 +9,10 @@
9
9
  "antd-mobile": "^2.3.3",
10
10
  "astro-classname": "^2.1.0",
11
11
  "bail": "1.0.5",
12
+ "classnames": "^2.3.2",
12
13
  "dayjs": "1.10.7",
13
14
  "deepmerge": "^2.1.0",
15
+ "dtable-store": "4.1.0",
14
16
  "enzyme": "^3.11.0",
15
17
  "enzyme-adapter-react-16": "^1.15.2",
16
18
  "glamor": "^2.20.40",
@@ -38,6 +40,7 @@
38
40
  "xtend": "^4.0.1"
39
41
  },
40
42
  "scripts": {
43
+ "lint": "./node_modules/.bin/eslint ./src/ --fix",
41
44
  "clean:esm": "rm -rf es && mkdir es",
42
45
  "clean:lib": "rm -rf lib && mkdir lib",
43
46
  "clean:dist": "rm -rf dist && mkdir dist",