dtable-ui-component 0.3.2-alpha4 → 0.3.2-alpha6

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,127 @@
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 React, { Fragment } from 'react';
6
+ import classnames from 'classnames';
7
+ import RowExpandImageImageFormatter from './row-expand-image-item-formatter';
8
+ import ImagePreviewerLightbox from '../ImagePreviewerLightbox';
9
+ import './index.css';
10
+
11
+ var RowExpandImageFormatter = /*#__PURE__*/function (_React$Component) {
12
+ _inherits(RowExpandImageFormatter, _React$Component);
13
+
14
+ var _super = _createSuper(RowExpandImageFormatter);
15
+
16
+ function RowExpandImageFormatter(props) {
17
+ var _this;
18
+
19
+ _classCallCheck(this, RowExpandImageFormatter);
20
+
21
+ _this = _super.call(this, props);
22
+
23
+ _this.onImageClick = function (index) {
24
+ _this.setState({
25
+ isPreviewImage: true,
26
+ previewImageIndex: index
27
+ });
28
+ };
29
+
30
+ _this.closeImagePopup = function () {
31
+ if (_this.props.onCloseCallback) {
32
+ _this.props.onCloseCallback();
33
+ }
34
+
35
+ _this.setState({
36
+ isPreviewImage: false,
37
+ previewImageIndex: -1
38
+ });
39
+ };
40
+
41
+ _this.movePrev = function () {
42
+ var images = _this.props.value;
43
+
44
+ _this.setState(function (prevState) {
45
+ return {
46
+ previewImageIndex: (prevState.previewImageIndex + images.length - 1) % images.length
47
+ };
48
+ });
49
+ };
50
+
51
+ _this.moveNext = function () {
52
+ var images = _this.props.value;
53
+
54
+ _this.setState(function (prevState) {
55
+ return {
56
+ previewImageIndex: (prevState.previewImageIndex + 1) % images.length
57
+ };
58
+ });
59
+ };
60
+
61
+ _this.state = {
62
+ isPreviewImage: false,
63
+ previewImageIndex: -1
64
+ };
65
+ return _this;
66
+ }
67
+
68
+ _createClass(RowExpandImageFormatter, [{
69
+ key: "render",
70
+ value: function render() {
71
+ var _this2 = this;
72
+
73
+ var _this$props = this.props,
74
+ value = _this$props.value,
75
+ server = _this$props.server,
76
+ containerClassName = _this$props.containerClassName,
77
+ readOnly = _this$props.readOnly,
78
+ column = _this$props.column,
79
+ downloadImage = _this$props.downloadImage;
80
+ var _this$state = this.state,
81
+ isPreviewImage = _this$state.isPreviewImage,
82
+ previewImageIndex = _this$state.previewImageIndex;
83
+
84
+ if (!Array.isArray(value) || value.length === 0) {
85
+ return null;
86
+ }
87
+
88
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
89
+ className: classnames('dtable-ui cell-formatter-container row-expand-image-formatter', containerClassName)
90
+ }, value.map(function (item, index) {
91
+ return /*#__PURE__*/React.createElement(RowExpandImageImageFormatter, {
92
+ url: item,
93
+ key: index,
94
+ index: index,
95
+ column: column,
96
+ downloadFile: downloadImage,
97
+ deleteFile: _this2.props.deleteFile,
98
+ readOnly: readOnly,
99
+ onImageClick: _this2.onImageClick
100
+ });
101
+ })), isPreviewImage && /*#__PURE__*/React.createElement(ImagePreviewerLightbox, {
102
+ imageItems: value,
103
+ imageIndex: previewImageIndex,
104
+ closeImagePopup: this.closeImagePopup,
105
+ moveToPrevImage: this.movePrev,
106
+ moveToNextImage: this.moveNext,
107
+ deleteImage: this.props.deleteFile,
108
+ downloadImage: downloadImage,
109
+ onRotateImage: this.props.rotateImage,
110
+ readOnly: readOnly,
111
+ server: server,
112
+ moveToPrevRowImage: this.props.moveToPrevRowImage,
113
+ moveToNextRowImage: this.props.moveToNextRowImage
114
+ }));
115
+ }
116
+ }]);
117
+
118
+ return RowExpandImageFormatter;
119
+ }(React.Component);
120
+
121
+ RowExpandImageFormatter.defaultProps = {
122
+ readOnly: true,
123
+ value: [],
124
+ server: '',
125
+ containerClassName: ''
126
+ };
127
+ export { RowExpandImageFormatter as default };
@@ -0,0 +1,128 @@
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 React, { Component } from 'react';
6
+ import { Tooltip } from 'reactstrap';
7
+ import { getLocale } from '../lang';
8
+ import DeleteTip from '../common/delete-tip';
9
+
10
+ var RowExpandImageItemFormatter = /*#__PURE__*/function (_Component) {
11
+ _inherits(RowExpandImageItemFormatter, _Component);
12
+
13
+ var _super = _createSuper(RowExpandImageItemFormatter);
14
+
15
+ function RowExpandImageItemFormatter(props) {
16
+ var _this;
17
+
18
+ _classCallCheck(this, RowExpandImageItemFormatter);
19
+
20
+ _this = _super.call(this, props);
21
+
22
+ _this.toggleTooltip = function () {
23
+ _this.setState({
24
+ isTooltipOpen: !_this.state.isTooltipOpen
25
+ });
26
+ };
27
+
28
+ _this.closeDeleteTip = function () {
29
+ _this.setState({
30
+ isDeleteTipOpen: false
31
+ });
32
+ };
33
+
34
+ _this.onClickDelete = function (e) {
35
+ e.preventDefault();
36
+ e.stopPropagation();
37
+ _this.position = {
38
+ top: e.clientY,
39
+ left: e.clientX
40
+ };
41
+
42
+ _this.setState({
43
+ isDeleteTipOpen: true
44
+ });
45
+ };
46
+
47
+ _this.onClickDownload = function (e) {
48
+ e.preventDefault();
49
+ e.stopPropagation();
50
+
51
+ _this.props.downloadFile(_this.props.url, e);
52
+ };
53
+
54
+ _this.onDelete = function (e) {
55
+ e.stopPropagation();
56
+
57
+ _this.closeDeleteTip();
58
+
59
+ _this.props.deleteFile(_this.props.index);
60
+ };
61
+
62
+ _this.onClickImage = function () {
63
+ _this.props.onImageClick(_this.props.index);
64
+ };
65
+
66
+ _this.state = {
67
+ isTooltipOpen: false,
68
+ isDeleteTipOpen: false
69
+ };
70
+ return _this;
71
+ }
72
+
73
+ _createClass(RowExpandImageItemFormatter, [{
74
+ key: "render",
75
+ value: function render() {
76
+ var _this$props = this.props,
77
+ url = _this$props.url,
78
+ column = _this$props.column,
79
+ index = _this$props.index,
80
+ readOnly = _this$props.readOnly,
81
+ downloadFile = _this$props.downloadFile,
82
+ deleteFile = _this$props.deleteFile;
83
+ var id = 'image-list-preview-item' + column.key + index;
84
+ var name = decodeURI(url.slice(url.lastIndexOf('/') + 1));
85
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
86
+ key: "image-".concat(index),
87
+ className: "row-expand-item-image",
88
+ id: id,
89
+ onClick: this.onClickImage
90
+ }, /*#__PURE__*/React.createElement("img", {
91
+ src: url,
92
+ id: "item-image-".concat(index),
93
+ alt: name
94
+ }), /*#__PURE__*/React.createElement("div", {
95
+ className: "dtable-image-icons-choice"
96
+ }, downloadFile && /*#__PURE__*/React.createElement("span", {
97
+ className: "image-icon",
98
+ onClick: this.onClickDownload
99
+ }, /*#__PURE__*/React.createElement("i", {
100
+ className: "dtable-font dtable-icon-download"
101
+ })), !readOnly && deleteFile && /*#__PURE__*/React.createElement("span", {
102
+ className: "image-icon",
103
+ onClick: this.onClickDelete
104
+ }, /*#__PURE__*/React.createElement("i", {
105
+ className: "dtable-font dtable-icon-fork-number"
106
+ })))), this.state.isDeleteTipOpen && /*#__PURE__*/React.createElement(DeleteTip, {
107
+ position: this.position,
108
+ toggle: this.closeDeleteTip,
109
+ onDelete: this.onDelete,
110
+ deleteTip: getLocale('Are_you_sure_you_want_to_delete_this_image')
111
+ }), /*#__PURE__*/React.createElement(Tooltip, {
112
+ placement: "bottom",
113
+ isOpen: this.state.isTooltipOpen,
114
+ toggle: this.toggleTooltip,
115
+ target: id,
116
+ delay: {
117
+ show: 0,
118
+ hide: 0
119
+ },
120
+ fade: false
121
+ }, name));
122
+ }
123
+ }]);
124
+
125
+ return RowExpandImageItemFormatter;
126
+ }(Component);
127
+
128
+ export { RowExpandImageItemFormatter as default };
@@ -0,0 +1,7 @@
1
+ export var getImageThumbnailUrl = function getImageThumbnailUrl(url, server) {
2
+ if (server && url.indexOf(server) > -1) {
3
+ return url.replace('/workspace', '/thumbnail/workspace') + '?size=256';
4
+ }
5
+
6
+ return url;
7
+ };
@@ -0,0 +1,164 @@
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 React, { Component } from 'react';
6
+ import CollaboratorItem from '../CollaboratorItem';
7
+
8
+ var CollaboratorItemFormatter = /*#__PURE__*/function (_Component) {
9
+ _inherits(CollaboratorItemFormatter, _Component);
10
+
11
+ var _super = _createSuper(CollaboratorItemFormatter);
12
+
13
+ function CollaboratorItemFormatter(_props) {
14
+ var _this;
15
+
16
+ _classCallCheck(this, CollaboratorItemFormatter);
17
+
18
+ _this = _super.call(this, _props);
19
+
20
+ _this.isValidEmail = function (email) {
21
+ var reg = /^[A-Za-zd]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,6}$/;
22
+ return reg.test(email);
23
+ };
24
+
25
+ _this.calculateCollaboratorData = function (props) {
26
+ var _this$props = _this.props,
27
+ context = _this$props.context,
28
+ collaborators = _this$props.collaborators;
29
+ var cellValue = props.cellValue;
30
+
31
+ if (!cellValue) {
32
+ _this.setState({
33
+ isDataLoaded: true,
34
+ collaborator: null
35
+ });
36
+
37
+ return;
38
+ }
39
+
40
+ _this.setState({
41
+ isDataLoaded: false,
42
+ collaborator: null
43
+ });
44
+
45
+ var collaborator = collaborators && collaborators.find(function (c) {
46
+ return c.name === cellValue;
47
+ });
48
+
49
+ if (collaborator) {
50
+ _this.setState({
51
+ isDataLoaded: true,
52
+ collaborator: collaborator
53
+ });
54
+
55
+ return;
56
+ }
57
+
58
+ if (!context) return;
59
+ var mediaUrl = context.getSetting('mediaUrl');
60
+ var defaultAvatarUrl = "".concat(mediaUrl, "/avatars/default.png");
61
+
62
+ if (cellValue === 'anonymous') {
63
+ collaborator = {
64
+ name: 'anonymous',
65
+ avatar_url: defaultAvatarUrl
66
+ };
67
+
68
+ _this.setState({
69
+ isDataLoaded: true,
70
+ collaborator: collaborator
71
+ });
72
+
73
+ return;
74
+ }
75
+
76
+ var collaboratorsCache = context.getSetting('collaboratorsCache');
77
+ collaborator = collaboratorsCache[cellValue];
78
+
79
+ if (collaborator) {
80
+ _this.setState({
81
+ isDataLoaded: true,
82
+ collaborator: collaborator
83
+ });
84
+
85
+ return;
86
+ }
87
+
88
+ if (!_this.isValidEmail(cellValue)) {
89
+ collaborator = {
90
+ name: cellValue,
91
+ avatar_url: defaultAvatarUrl
92
+ };
93
+ collaboratorsCache[cellValue] = collaborator;
94
+
95
+ _this.setState({
96
+ isDataLoaded: true,
97
+ collaborator: collaborator
98
+ });
99
+
100
+ return;
101
+ }
102
+
103
+ _this.props.context.getUserCommonInfo(cellValue).then(function (res) {
104
+ collaborator = res.data;
105
+ collaboratorsCache[cellValue] = collaborator;
106
+
107
+ _this.setState({
108
+ isDataLoaded: true,
109
+ collaborator: collaborator
110
+ });
111
+ }).catch(function () {
112
+ collaborator = {
113
+ name: cellValue,
114
+ avatar_url: defaultAvatarUrl
115
+ };
116
+ collaboratorsCache[cellValue] = collaborator;
117
+
118
+ _this.setState({
119
+ isDataLoaded: true,
120
+ collaborator: collaborator
121
+ });
122
+ });
123
+ };
124
+
125
+ _this.state = {
126
+ isDataLoaded: false,
127
+ collaborator: null
128
+ };
129
+ return _this;
130
+ }
131
+
132
+ _createClass(CollaboratorItemFormatter, [{
133
+ key: "componentDidMount",
134
+ value: function componentDidMount() {
135
+ this.calculateCollaboratorData(this.props);
136
+ }
137
+ }, {
138
+ key: "UNSAFE_componentWillReceiveProps",
139
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
140
+ this.calculateCollaboratorData(nextProps);
141
+ }
142
+ }, {
143
+ key: "render",
144
+ value: function render() {
145
+ var cellValue = this.props.cellValue;
146
+ var _this$state = this.state,
147
+ collaborator = _this$state.collaborator,
148
+ isDataLoaded = _this$state.isDataLoaded;
149
+
150
+ if (!isDataLoaded || !cellValue || !collaborator) {
151
+ return this.props.renderEmpty();
152
+ }
153
+
154
+ return /*#__PURE__*/React.createElement(CollaboratorItem, {
155
+ collaborator: collaborator,
156
+ enableDeleteCollaborator: false
157
+ });
158
+ }
159
+ }]);
160
+
161
+ return CollaboratorItemFormatter;
162
+ }(Component);
163
+
164
+ export { CollaboratorItemFormatter as default };
@@ -0,0 +1,20 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+
3
+ var _DURATION_ZERO_DISPLA, _DURATION_DECIMAL_DIG;
4
+
5
+ export var DURATION_FORMATS_MAP = {
6
+ H_MM: 'h:mm',
7
+ H_MM_SS: 'h:mm:ss',
8
+ H_MM_SS_S: 'h:mm:ss.s',
9
+ H_MM_SS_SS: 'h:mm:ss.ss',
10
+ H_MM_SS_SSS: 'h:mm:ss.sss'
11
+ };
12
+ export var DURATION_FORMATS = [{
13
+ name: DURATION_FORMATS_MAP.H_MM,
14
+ type: DURATION_FORMATS_MAP.H_MM
15
+ }, {
16
+ name: DURATION_FORMATS_MAP.H_MM_SS,
17
+ type: DURATION_FORMATS_MAP.H_MM_SS
18
+ }];
19
+ export var DURATION_ZERO_DISPLAY = (_DURATION_ZERO_DISPLA = {}, _defineProperty(_DURATION_ZERO_DISPLA, DURATION_FORMATS_MAP.H_MM, '0:00'), _defineProperty(_DURATION_ZERO_DISPLA, DURATION_FORMATS_MAP.H_MM_SS, '0:00'), _defineProperty(_DURATION_ZERO_DISPLA, DURATION_FORMATS_MAP.H_MM_SS_S, '0:00.0'), _defineProperty(_DURATION_ZERO_DISPLA, DURATION_FORMATS_MAP.H_MM_SS_SS, '0:00.00'), _defineProperty(_DURATION_ZERO_DISPLA, DURATION_FORMATS_MAP.H_MM_SS_SSS, '0:00.000'), _DURATION_ZERO_DISPLA);
20
+ export var DURATION_DECIMAL_DIGITS = (_DURATION_DECIMAL_DIG = {}, _defineProperty(_DURATION_DECIMAL_DIG, DURATION_FORMATS_MAP.H_MM, 0), _defineProperty(_DURATION_DECIMAL_DIG, DURATION_FORMATS_MAP.H_MM_SS, 0), _defineProperty(_DURATION_DECIMAL_DIG, DURATION_FORMATS_MAP.H_MM_SS_S, 1), _defineProperty(_DURATION_DECIMAL_DIG, DURATION_FORMATS_MAP.H_MM_SS_SS, 2), _defineProperty(_DURATION_DECIMAL_DIG, DURATION_FORMATS_MAP.H_MM_SS_SSS, 3), _DURATION_DECIMAL_DIG);
@@ -0,0 +1,127 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+
4
+ var DateUtils = /*#__PURE__*/function () {
5
+ function DateUtils() {
6
+ _classCallCheck(this, DateUtils);
7
+ }
8
+
9
+ _createClass(DateUtils, null, [{
10
+ key: "format",
11
+ value: function format(date, _format) {
12
+ var dateObject = this.getValidDate(date);
13
+
14
+ if (!dateObject) {
15
+ return date;
16
+ }
17
+
18
+ var upperCaseFormat = _format && _format.toUpperCase();
19
+
20
+ var year = dateObject.getFullYear();
21
+ var month = dateObject.getMonth() + 1;
22
+ var day = dateObject.getDate();
23
+ var displayMonth = month < 10 ? "0".concat(month) : month;
24
+ var displayDay = day < 10 ? "0".concat(day) : day;
25
+
26
+ switch (upperCaseFormat) {
27
+ case 'YYYY-MM-DD HH:MM:SS':
28
+ {
29
+ var hours = dateObject.getHours();
30
+ var minutes = dateObject.getMinutes();
31
+ var seconds = dateObject.getSeconds();
32
+ var displayHours = hours < 10 ? "0".concat(hours) : hours;
33
+ var displayMinutes = minutes < 10 ? "0".concat(minutes) : minutes;
34
+ var displaySeconds = seconds < 10 ? "0".concat(seconds) : seconds;
35
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay, " ").concat(displayHours, ":").concat(displayMinutes, ":").concat(displaySeconds);
36
+ }
37
+
38
+ case 'YYYY-MM-DD HH:MM':
39
+ case 'YYYY-MM-DD HH:mm':
40
+ {
41
+ var _hours = dateObject.getHours();
42
+
43
+ var _minutes = dateObject.getMinutes();
44
+
45
+ var _displayHours = _hours < 10 ? "0".concat(_hours) : _hours;
46
+
47
+ var _displayMinutes = _minutes < 10 ? "0".concat(_minutes) : _minutes;
48
+
49
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay, " ").concat(_displayHours, ":").concat(_displayMinutes);
50
+ }
51
+
52
+ case 'D/M/YYYY':
53
+ case 'DD/MM/YYYY':
54
+ {
55
+ return "".concat(displayDay, "/").concat(displayMonth, "/").concat(year);
56
+ }
57
+
58
+ case 'D/M/YYYY HH:mm':
59
+ case 'DD/MM/YYYY HH:mm':
60
+ {
61
+ var _hours2 = dateObject.getHours();
62
+
63
+ var _minutes2 = dateObject.getMinutes();
64
+
65
+ var _displayHours2 = _hours2 < 10 ? "0".concat(_hours2) : _hours2;
66
+
67
+ var _displayMinutes2 = _minutes2 < 10 ? "0".concat(_minutes2) : _minutes2;
68
+
69
+ return "".concat(displayDay, "/").concat(displayMonth, "/").concat(year, " ").concat(_displayHours2, ":").concat(_displayMinutes2);
70
+ }
71
+
72
+ case 'M/D/YYYY':
73
+ {
74
+ return "".concat(month, "/").concat(day, "/").concat(year);
75
+ }
76
+
77
+ case 'M/D/YYYY HH:mm':
78
+ {
79
+ var _hours3 = dateObject.getHours();
80
+
81
+ var _minutes3 = dateObject.getMinutes();
82
+
83
+ var _displayHours3 = _hours3 < 10 ? "0".concat(_hours3) : _hours3;
84
+
85
+ var _displayMinutes3 = _minutes3 < 10 ? "0".concat(_minutes3) : _minutes3;
86
+
87
+ return "".concat(month, "/").concat(day, "/").concat(year, " ").concat(_displayHours3, ":").concat(_displayMinutes3);
88
+ }
89
+
90
+ case 'YYYY-MM-DD':
91
+ {
92
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay);
93
+ }
94
+
95
+ default:
96
+ {
97
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay);
98
+ }
99
+ }
100
+ }
101
+ }, {
102
+ key: "isValidDateObject",
103
+ value: function isValidDateObject(dateObject) {
104
+ return dateObject instanceof Date && !isNaN(dateObject.getTime());
105
+ }
106
+ }, {
107
+ key: "getValidDate",
108
+ value: function getValidDate(date) {
109
+ if (!date) {
110
+ return null;
111
+ }
112
+
113
+ var isDateTypeString = typeof date === 'string';
114
+ var dateObject = isDateTypeString ? new Date(date) : date;
115
+ if (this.isValidDateObject(dateObject)) return dateObject;
116
+ if (!isDateTypeString) return null; //ios phone and safari browser not support use '2021-09-10 12:30', support '2021/09/10 12:30'
117
+
118
+ dateObject = new Date(date.replace(/-/g, '/'));
119
+ if (this.isValidDateObject(dateObject)) return dateObject;
120
+ return null;
121
+ }
122
+ }]);
123
+
124
+ return DateUtils;
125
+ }();
126
+
127
+ export default DateUtils;
@@ -0,0 +1,9 @@
1
+ import { CellType } from 'dtable-store';
2
+ export var FORMULA_RESULT_TYPE = {
3
+ NUMBER: 'number',
4
+ STRING: 'string',
5
+ DATE: 'date',
6
+ BOOL: 'bool',
7
+ ARRAY: 'array'
8
+ };
9
+ export var FORMULA_COLUMN_TYPES = [CellType.FORMULA, CellType.LINK_FORMULA];
@@ -0,0 +1,25 @@
1
+ .dtable-link-formatter {
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ align-items: center;
5
+ overflow: hidden;
6
+ width: 100%;
7
+ height: auto;
8
+ }
9
+
10
+ .dtable-link-formatter .row-expand-link-item {
11
+ flex-shrink: 0;
12
+ margin: 2px 4px 2px 0;
13
+ padding: 0 6px;
14
+ font-size: 13px;
15
+ max-width: 100%;
16
+ background: #eceff4;
17
+ border-radius: 3px;
18
+ align-items: center;
19
+ vertical-align: middle;
20
+ overflow: hidden;
21
+ white-space: nowrap;
22
+ text-overflow: ellipsis;
23
+ line-height: 20px;
24
+ width: fit-content;
25
+ }