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.
- package/lib/app.css +20 -0
- package/lib/app.js +96 -0
- package/lib/assets/images/avatar/default_avatar.png +0 -0
- package/lib/assets/images/file/192/excel.png +0 -0
- package/lib/assets/images/file/192/file.png +0 -0
- package/lib/assets/images/file/192/music.png +0 -0
- package/lib/assets/images/file/192/pdf.png +0 -0
- package/lib/assets/images/file/192/pic.png +0 -0
- package/lib/assets/images/file/192/ppt.png +0 -0
- package/lib/assets/images/file/192/txt.png +0 -0
- package/lib/assets/images/file/192/video.png +0 -0
- package/lib/assets/images/file/192/word.png +0 -0
- package/lib/assets/images/file/24/excel.png +0 -0
- package/lib/assets/images/file/24/file.png +0 -0
- package/lib/assets/images/file/24/music.png +0 -0
- package/lib/assets/images/file/24/pdf.png +0 -0
- package/lib/assets/images/file/24/pic.png +0 -0
- package/lib/assets/images/file/24/ppt.png +0 -0
- package/lib/assets/images/file/24/txt.png +0 -0
- package/lib/assets/images/file/24/video.png +0 -0
- package/lib/assets/images/file/24/word.png +0 -0
- package/lib/assets/images/folder/folder-192.png +0 -0
- package/lib/assets/images/folder/folder-24.png +0 -0
- package/lib/components/cell-editor/checkbox-editor.js +111 -0
- package/lib/components/cell-editor/collaborator-editor.js +249 -0
- package/lib/components/cell-editor/date-editor.js +171 -0
- package/lib/components/cell-editor/index.js +40 -0
- package/lib/components/cell-editor/link-editor.js +321 -0
- package/lib/components/cell-editor/multiple-select-editor.js +250 -0
- package/lib/components/cell-editor/number-editor.js +162 -0
- package/lib/components/cell-editor/single-select-editor.js +216 -0
- package/lib/components/cell-editor/text-editor.js +129 -0
- package/lib/components/cell-editor-dialog/pc-file-editor-dialog.js +66 -0
- package/lib/components/cell-editor-dialog/pc-files-addition/index.js +1 -0
- package/lib/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +1 -0
- package/lib/components/cell-editor-dialog/pc-files-preview/index.js +1 -0
- package/lib/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +1 -0
- package/lib/components/cell-editor-popover/mb-collaborator-editor-popover.js +183 -0
- package/lib/components/cell-editor-popover/mb-date-editor-popover.js +262 -0
- package/lib/components/cell-editor-popover/mb-link-editor-popover.js +176 -0
- package/lib/components/cell-editor-popover/mb-select-editor-popover.js +243 -0
- package/lib/components/cell-editor-popover/pc-collaborator-editor-popover.js +124 -0
- package/lib/components/cell-editor-popover/pc-date-editor-popover.js +156 -0
- package/lib/components/cell-editor-popover/pc-link-editor-popover.js +128 -0
- package/lib/components/cell-editor-popover/pc-select-editor-popover.js +157 -0
- package/lib/components/cell-factory/cell-formatter-factory.js +28 -0
- package/lib/components/cell-formatter/auto-number-formatter.js +45 -0
- package/lib/components/cell-formatter/button-formatter.js +66 -0
- package/lib/components/cell-formatter/checkbox-formatter.js +56 -0
- package/lib/components/cell-formatter/collaborator-formatter.js +111 -0
- package/lib/components/cell-formatter/creator-formatter.js +105 -0
- package/lib/components/cell-formatter/ctime-formatter.js +70 -0
- package/lib/components/cell-formatter/date-formatter.js +73 -0
- package/lib/components/cell-formatter/duration-formatter.js +49 -0
- package/lib/components/cell-formatter/email-formatter.js +45 -0
- package/lib/components/cell-formatter/file-formatter.js +77 -0
- package/lib/components/cell-formatter/formatter-config.js +66 -0
- package/lib/components/cell-formatter/formula-formatter.js +189 -0
- package/lib/components/cell-formatter/geolocation-formatter.js +66 -0
- package/lib/components/cell-formatter/image-formatter.js +171 -0
- package/lib/components/cell-formatter/index.js +112 -0
- package/lib/components/cell-formatter/last-modifier-formatter.js +105 -0
- package/lib/components/cell-formatter/link-formatter.js +165 -0
- package/lib/components/cell-formatter/long-text-formatter.js +46 -0
- package/lib/components/cell-formatter/mtime-formatter.js +70 -0
- package/lib/components/cell-formatter/multiple-select-formatter.js +84 -0
- package/lib/components/cell-formatter/number-formatter.js +60 -0
- package/lib/components/cell-formatter/rate-formatter.js +93 -0
- package/lib/components/cell-formatter/single-select-formatter.js +84 -0
- package/lib/components/cell-formatter/text-formatter.js +67 -0
- package/lib/components/cell-formatter/url-formatter.js +45 -0
- package/lib/components/cell-formatter/widgets/file-item-formatter.js +63 -0
- package/lib/components/cell-formatter/widgets/image-previewer-lightbox.js +152 -0
- package/lib/components/cell-formatter/widgets/long-text-formatter/html-long-text-formatter.js +107 -0
- package/lib/components/cell-formatter/widgets/long-text-formatter/simple-long-text-formatter.js +110 -0
- package/lib/components/common/collaborator-item.js +79 -0
- package/lib/components/common/edit-editor-button.js +67 -0
- package/lib/components/common/images-lazy-load.js +158 -0
- package/lib/components/common/link-editor-option.js +121 -0
- package/lib/components/common/mobile/mb-editor-header.js +61 -0
- package/lib/components/common/modal-portal.js +51 -0
- package/lib/components/common/select-editor-option.js +122 -0
- package/lib/components/common/select-item.js +73 -0
- package/lib/components/file-uploader/index.js +63 -0
- package/lib/components/loading.js +16 -0
- package/lib/components/toast/alert.js +164 -0
- package/lib/components/toast/index.js +12 -0
- package/lib/components/toast/toast.js +223 -0
- package/lib/components/toast/toastManager.js +189 -0
- package/lib/components/toast/toaster.js +92 -0
- package/lib/constants/cell-types.js +54 -0
- package/lib/constants/index.js +70 -0
- package/lib/css/cell-editor.css +614 -0
- package/lib/css/cell-formatter.css +247 -0
- package/lib/css/custom-rc-calendar.css +118 -0
- package/lib/css/image-previewer-ligntbox.css +87 -0
- package/lib/css/loading.css +54 -0
- package/lib/index.js +64 -0
- package/lib/lang/index.js +66 -0
- package/lib/locals/de.js +7 -0
- package/lib/locals/en.js +22 -0
- package/lib/locals/fr.js +7 -0
- package/lib/locals/zh-CN.js +22 -0
- package/lib/utils/cell-value-validator.js +41 -0
- package/lib/utils/column-utils.js +15 -0
- package/lib/utils/editor-utils.js +81 -0
- package/lib/utils/markdown2html.js +68 -0
- package/lib/utils/normalize-long-text-value.js +74 -0
- package/lib/utils/number-precision.js +181 -0
- package/lib/utils/unified/index.js +470 -0
- package/lib/utils/utils.js +141 -0
- package/lib/utils/value-format-utils.js +545 -0
- package/lib/utils/vfile/core.js +172 -0
- package/lib/utils/vfile/index.js +48 -0
- package/package.json +3 -3
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
9
|
+
|
|
10
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
+
|
|
18
|
+
var _reactResponsive = _interopRequireDefault(require("react-responsive"));
|
|
19
|
+
|
|
20
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
21
|
+
|
|
22
|
+
var _valueFormatUtils = require("../../utils/value-format-utils");
|
|
23
|
+
|
|
24
|
+
var _pcDateEditorPopover = _interopRequireDefault(require("../cell-editor-popover/pc-date-editor-popover"));
|
|
25
|
+
|
|
26
|
+
var _mbDateEditorPopover = _interopRequireDefault(require("../cell-editor-popover/mb-date-editor-popover"));
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
var propTypes = {
|
|
33
|
+
isReadOnly: _propTypes.default.bool,
|
|
34
|
+
value: _propTypes.default.string,
|
|
35
|
+
lang: _propTypes.default.string,
|
|
36
|
+
column: _propTypes.default.object.isRequired,
|
|
37
|
+
onCommit: _propTypes.default.func.isRequired
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var DateEditor = /*#__PURE__*/function (_React$Component) {
|
|
41
|
+
(0, _inheritsLoose2.default)(DateEditor, _React$Component);
|
|
42
|
+
|
|
43
|
+
function DateEditor(props) {
|
|
44
|
+
var _this;
|
|
45
|
+
|
|
46
|
+
_this = _React$Component.call(this, props) || this;
|
|
47
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getDateFormat", function () {
|
|
48
|
+
var column = _this.props.column;
|
|
49
|
+
var defaultDateFormat = 'YYYY-MM-DD';
|
|
50
|
+
var dateFormat = column.data && column.data.format;
|
|
51
|
+
return dateFormat || defaultDateFormat;
|
|
52
|
+
});
|
|
53
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDateEditorToggle", function () {
|
|
54
|
+
var isReadOnly = _this.props.isReadOnly;
|
|
55
|
+
|
|
56
|
+
if (isReadOnly) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_this.setState({
|
|
61
|
+
isPopoverShow: !_this.state.isPopoverShow
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onValueChanged", function (value) {
|
|
65
|
+
if (value !== _this.state.newValue) {
|
|
66
|
+
_this.setState({
|
|
67
|
+
newValue: value
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
_this.onCommit(value);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCommit", function (newValue) {
|
|
74
|
+
var updated = {};
|
|
75
|
+
var column = _this.props.column;
|
|
76
|
+
updated[column.key] = newValue;
|
|
77
|
+
|
|
78
|
+
_this.props.onCommit(updated);
|
|
79
|
+
});
|
|
80
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClosePopover", function () {
|
|
81
|
+
_this.setState({
|
|
82
|
+
isPopoverShow: false
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
_this.state = {
|
|
86
|
+
isDateInit: false,
|
|
87
|
+
newValue: '',
|
|
88
|
+
isPopoverShow: false,
|
|
89
|
+
showHourAndMinute: false,
|
|
90
|
+
defaultCalendarValue: null
|
|
91
|
+
};
|
|
92
|
+
return _this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var _proto = DateEditor.prototype;
|
|
96
|
+
|
|
97
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
98
|
+
var _this$props = this.props,
|
|
99
|
+
value = _this$props.value,
|
|
100
|
+
lang = _this$props.lang;
|
|
101
|
+
|
|
102
|
+
_moment.default.locale(lang);
|
|
103
|
+
|
|
104
|
+
var dateFormat = this.getDateFormat();
|
|
105
|
+
this.setState({
|
|
106
|
+
isDateInit: true,
|
|
107
|
+
newValue: value,
|
|
108
|
+
dateFormat: dateFormat,
|
|
109
|
+
showHourAndMinute: dateFormat.indexOf('HH:mm') > -1
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
_proto.render = function render() {
|
|
114
|
+
if (!this.state.isDateInit) {
|
|
115
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
116
|
+
className: "cell-editor date-editor"
|
|
117
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
118
|
+
className: "date-editor-conteinr"
|
|
119
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
120
|
+
className: "control-form"
|
|
121
|
+
})));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var _this$props2 = this.props,
|
|
125
|
+
lang = _this$props2.lang,
|
|
126
|
+
column = _this$props2.column;
|
|
127
|
+
var _this$state = this.state,
|
|
128
|
+
newValue = _this$state.newValue,
|
|
129
|
+
isPopoverShow = _this$state.isPopoverShow,
|
|
130
|
+
dateFormat = _this$state.dateFormat,
|
|
131
|
+
showHourAndMinute = _this$state.showHourAndMinute;
|
|
132
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
133
|
+
className: "cell-editor dtable-ui-date-editor"
|
|
134
|
+
}, !isPopoverShow && /*#__PURE__*/_react.default.createElement("div", {
|
|
135
|
+
className: "dtable-ui-date-editor-container"
|
|
136
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
137
|
+
className: "form-control",
|
|
138
|
+
onClick: this.onDateEditorToggle
|
|
139
|
+
}, (0, _valueFormatUtils.getDateDisplayString)(newValue, dateFormat))), isPopoverShow && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactResponsive.default, {
|
|
140
|
+
query: '(min-width: 768px)'
|
|
141
|
+
}, /*#__PURE__*/_react.default.createElement(_pcDateEditorPopover.default, {
|
|
142
|
+
lang: lang,
|
|
143
|
+
value: newValue,
|
|
144
|
+
dateFormat: dateFormat,
|
|
145
|
+
showHourAndMinute: showHourAndMinute,
|
|
146
|
+
onValueChanged: this.onValueChanged
|
|
147
|
+
})), /*#__PURE__*/_react.default.createElement(_reactResponsive.default, {
|
|
148
|
+
query: '(max-width: 767.8px)'
|
|
149
|
+
}, /*#__PURE__*/_react.default.createElement(_mbDateEditorPopover.default, {
|
|
150
|
+
isReadOnly: this.props.isReadOnly,
|
|
151
|
+
lang: lang,
|
|
152
|
+
value: newValue,
|
|
153
|
+
dateFormat: dateFormat,
|
|
154
|
+
showHourAndMinute: showHourAndMinute,
|
|
155
|
+
column: column,
|
|
156
|
+
onValueChanged: this.onValueChanged,
|
|
157
|
+
onClosePopover: this.onClosePopover
|
|
158
|
+
}))));
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return DateEditor;
|
|
162
|
+
}(_react.default.Component);
|
|
163
|
+
|
|
164
|
+
(0, _defineProperty2.default)(DateEditor, "defaultProps", {
|
|
165
|
+
isReadOnly: false,
|
|
166
|
+
value: '',
|
|
167
|
+
lang: 'en'
|
|
168
|
+
});
|
|
169
|
+
DateEditor.propTypes = propTypes;
|
|
170
|
+
var _default = DateEditor;
|
|
171
|
+
exports.default = _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.TextEditor = exports.SingleSelectEditor = exports.NumberEditor = exports.MultipleSelectEditor = exports.LinkEditor = exports.DateEditor = exports.CollaboratorEditor = exports.CheckboxEditor = void 0;
|
|
7
|
+
|
|
8
|
+
require("../../css/cell-editor.css");
|
|
9
|
+
|
|
10
|
+
var _numberEditor = _interopRequireDefault(require("./number-editor"));
|
|
11
|
+
|
|
12
|
+
exports.NumberEditor = _numberEditor.default;
|
|
13
|
+
|
|
14
|
+
var _textEditor = _interopRequireDefault(require("./text-editor"));
|
|
15
|
+
|
|
16
|
+
exports.TextEditor = _textEditor.default;
|
|
17
|
+
|
|
18
|
+
var _checkboxEditor = _interopRequireDefault(require("./checkbox-editor"));
|
|
19
|
+
|
|
20
|
+
exports.CheckboxEditor = _checkboxEditor.default;
|
|
21
|
+
|
|
22
|
+
var _singleSelectEditor = _interopRequireDefault(require("./single-select-editor"));
|
|
23
|
+
|
|
24
|
+
exports.SingleSelectEditor = _singleSelectEditor.default;
|
|
25
|
+
|
|
26
|
+
var _multipleSelectEditor = _interopRequireDefault(require("./multiple-select-editor"));
|
|
27
|
+
|
|
28
|
+
exports.MultipleSelectEditor = _multipleSelectEditor.default;
|
|
29
|
+
|
|
30
|
+
var _collaboratorEditor = _interopRequireDefault(require("./collaborator-editor"));
|
|
31
|
+
|
|
32
|
+
exports.CollaboratorEditor = _collaboratorEditor.default;
|
|
33
|
+
|
|
34
|
+
var _linkEditor = _interopRequireDefault(require("./link-editor"));
|
|
35
|
+
|
|
36
|
+
exports.LinkEditor = _linkEditor.default;
|
|
37
|
+
|
|
38
|
+
var _dateEditor = _interopRequireDefault(require("./date-editor"));
|
|
39
|
+
|
|
40
|
+
exports.DateEditor = _dateEditor.default;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
9
|
+
|
|
10
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
+
|
|
18
|
+
var _reactResponsive = _interopRequireDefault(require("react-responsive"));
|
|
19
|
+
|
|
20
|
+
var _lang = require("../../lang");
|
|
21
|
+
|
|
22
|
+
var CellTypes = _interopRequireWildcard(require("../../constants/cell-types"));
|
|
23
|
+
|
|
24
|
+
var _valueFormatUtils = require("../../utils/value-format-utils");
|
|
25
|
+
|
|
26
|
+
var _editEditorButton = _interopRequireDefault(require("../common/edit-editor-button"));
|
|
27
|
+
|
|
28
|
+
var _linkEditorOption = _interopRequireDefault(require("../common/link-editor-option"));
|
|
29
|
+
|
|
30
|
+
var _pcLinkEditorPopover = _interopRequireDefault(require("../cell-editor-popover/pc-link-editor-popover"));
|
|
31
|
+
|
|
32
|
+
var _mbLinkEditorPopover = _interopRequireDefault(require("../cell-editor-popover/mb-link-editor-popover"));
|
|
33
|
+
|
|
34
|
+
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); }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
var propTypes = {
|
|
39
|
+
isReadOnly: _propTypes.default.bool,
|
|
40
|
+
row: _propTypes.default.object.isRequired,
|
|
41
|
+
column: _propTypes.default.object.isRequired,
|
|
42
|
+
currentTableId: _propTypes.default.string.isRequired,
|
|
43
|
+
linkMetaData: _propTypes.default.shape({
|
|
44
|
+
getLinkedCellValue: _propTypes.default.func.isRequired,
|
|
45
|
+
getLinkedTable: _propTypes.default.func.isRequired,
|
|
46
|
+
getLinkedRows: _propTypes.default.func.isRequired,
|
|
47
|
+
addLink: _propTypes.default.func.isRequired,
|
|
48
|
+
removeLink: _propTypes.default.func.isRequired
|
|
49
|
+
}).isRequired
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var LinkEditor = /*#__PURE__*/function (_React$Component) {
|
|
53
|
+
(0, _inheritsLoose2.default)(LinkEditor, _React$Component);
|
|
54
|
+
|
|
55
|
+
function LinkEditor(props) {
|
|
56
|
+
var _this;
|
|
57
|
+
|
|
58
|
+
_this = _React$Component.call(this, props) || this;
|
|
59
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDocumentToggle", function (e) {
|
|
60
|
+
if (_this.editorContainer !== e.target && !_this.editorContainer.contains(e.target)) {
|
|
61
|
+
_this.onClosePopover();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getLinkedCellValue", function () {
|
|
65
|
+
var _this$props = _this.props,
|
|
66
|
+
row = _this$props.row,
|
|
67
|
+
column = _this$props.column,
|
|
68
|
+
linkMetaData = _this$props.linkMetaData;
|
|
69
|
+
|
|
70
|
+
var _ref = column.data || {},
|
|
71
|
+
link_id = _ref.link_id,
|
|
72
|
+
table_id = _ref.table_id,
|
|
73
|
+
other_table_id = _ref.other_table_id;
|
|
74
|
+
|
|
75
|
+
_this.linkId = link_id;
|
|
76
|
+
_this.tableId = table_id;
|
|
77
|
+
_this.otherTableId = other_table_id;
|
|
78
|
+
return linkMetaData.getLinkedCellValue(_this.linkId, _this.tableId, _this.otherTableId, row._id);
|
|
79
|
+
});
|
|
80
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatLinkedValuesToOptions", function () {
|
|
81
|
+
var _this$props2 = _this.props,
|
|
82
|
+
column = _this$props2.column,
|
|
83
|
+
linkMetaData = _this$props2.linkMetaData;
|
|
84
|
+
var rowIds = _this.state.newValue;
|
|
85
|
+
|
|
86
|
+
if (rowIds && Array.isArray(rowIds) && rowIds.length > 0) {
|
|
87
|
+
var linkedRows = linkMetaData.getLinkedRows(_this.otherTableId, rowIds);
|
|
88
|
+
var linkedTable = linkMetaData.getLinkedTable(_this.otherTableId);
|
|
89
|
+
return linkedRows.map(function (linkedRow) {
|
|
90
|
+
var displayColumnKey = column.data.display_column_key; // format value to display
|
|
91
|
+
|
|
92
|
+
var displayValue = _this.getDisplayValue(linkedTable, linkedRow, displayColumnKey);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
id: linkedRow._id,
|
|
96
|
+
name: displayValue
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return [];
|
|
102
|
+
});
|
|
103
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getDisplayValue", function (linkedTable, linkedRow, displayColumnKey) {
|
|
104
|
+
var value = linkedRow[displayColumnKey];
|
|
105
|
+
var linkedColumn = linkedTable.columns.find(function (column) {
|
|
106
|
+
return column.key === displayColumnKey;
|
|
107
|
+
});
|
|
108
|
+
var type = linkedColumn.type,
|
|
109
|
+
data = linkedColumn.data;
|
|
110
|
+
|
|
111
|
+
switch (type) {
|
|
112
|
+
case CellTypes.NUMBER:
|
|
113
|
+
{
|
|
114
|
+
return (0, _valueFormatUtils.getNumberDisplayString)(value, data);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case CellTypes.DATE:
|
|
118
|
+
{
|
|
119
|
+
var format = data.format;
|
|
120
|
+
return (0, _valueFormatUtils.getDateDisplayString)(value, format);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
default:
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getAvailableLinkedOptions", function () {
|
|
128
|
+
var _this$props3 = _this.props,
|
|
129
|
+
column = _this$props3.column,
|
|
130
|
+
linkMetaData = _this$props3.linkMetaData;
|
|
131
|
+
var displayColumnKey = column.data.display_column_key;
|
|
132
|
+
var linkedTable = linkMetaData.getLinkedTable(_this.otherTableId);
|
|
133
|
+
var availableRows = linkedTable.rows.filter(function (row) {
|
|
134
|
+
return !!row[displayColumnKey];
|
|
135
|
+
});
|
|
136
|
+
var availableOptions = availableRows.map(function (row) {
|
|
137
|
+
var displayValue = _this.getDisplayValue(linkedTable, row, displayColumnKey);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
id: row._id,
|
|
141
|
+
name: displayValue
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
return availableOptions;
|
|
145
|
+
});
|
|
146
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCommit", function (newValue) {// nothing todo
|
|
147
|
+
});
|
|
148
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onAddOptionToggle", function (event) {
|
|
149
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
150
|
+
event.stopPropagation();
|
|
151
|
+
|
|
152
|
+
if (_this.props.isReadOnly) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var isPopoverShow = !_this.state.isPopoverShow;
|
|
157
|
+
|
|
158
|
+
if (isPopoverShow) {
|
|
159
|
+
var popoverPosition = _this.caculatePopoverPosition();
|
|
160
|
+
|
|
161
|
+
_this.setState({
|
|
162
|
+
isPopoverShow: isPopoverShow,
|
|
163
|
+
popoverPosition: popoverPosition
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
_this.setState({
|
|
167
|
+
isPopoverShow: isPopoverShow
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onOptionItemToggle", function (option) {
|
|
172
|
+
var _this$props4 = _this.props,
|
|
173
|
+
row = _this$props4.row,
|
|
174
|
+
linkMetaData = _this$props4.linkMetaData;
|
|
175
|
+
|
|
176
|
+
var newValue = _this.state.newValue.slice();
|
|
177
|
+
|
|
178
|
+
var optionIndex = newValue.findIndex(function (option_id) {
|
|
179
|
+
return option_id === option.id;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (optionIndex !== -1) {
|
|
183
|
+
newValue.splice(optionIndex, 1);
|
|
184
|
+
linkMetaData.removeLink(_this.linkId, _this.tableId, _this.otherTableId, row._id, option.id);
|
|
185
|
+
} else {
|
|
186
|
+
newValue.push(option.id);
|
|
187
|
+
linkMetaData.addLink(_this.linkId, _this.tableId, _this.otherTableId, row._id, option.id);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
_this.setState({
|
|
191
|
+
newValue: newValue
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDeleteOption", function (option) {
|
|
195
|
+
var _this$props5 = _this.props,
|
|
196
|
+
row = _this$props5.row,
|
|
197
|
+
linkMetaData = _this$props5.linkMetaData;
|
|
198
|
+
|
|
199
|
+
var newValue = _this.state.newValue.slice();
|
|
200
|
+
|
|
201
|
+
var optionIndex = newValue.findIndex(function (option_id) {
|
|
202
|
+
return option_id === option.id;
|
|
203
|
+
});
|
|
204
|
+
newValue.splice(optionIndex, 1);
|
|
205
|
+
|
|
206
|
+
_this.setState({
|
|
207
|
+
newValue: newValue
|
|
208
|
+
}, function () {
|
|
209
|
+
linkMetaData.removeLink(_this.linkId, _this.tableId, _this.otherTableId, row._id, option.id);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "caculatePopoverPosition", function () {
|
|
213
|
+
var POPOVER_MAX_HEIGHT = 200;
|
|
214
|
+
var innerHeight = window.innerHeight;
|
|
215
|
+
|
|
216
|
+
var _this$editor$getClien = _this.editor.getClientRects()[0],
|
|
217
|
+
top = _this$editor$getClien.top,
|
|
218
|
+
height = _this$editor$getClien.height;
|
|
219
|
+
|
|
220
|
+
var isBelow = innerHeight - (top + height) > POPOVER_MAX_HEIGHT;
|
|
221
|
+
var position = {
|
|
222
|
+
top: height + 1,
|
|
223
|
+
left: 0
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
if (!isBelow) {
|
|
227
|
+
var bottom = height + 1;
|
|
228
|
+
position = {
|
|
229
|
+
bottom: bottom,
|
|
230
|
+
left: 0
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return position;
|
|
235
|
+
});
|
|
236
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClosePopover", function () {
|
|
237
|
+
_this.setState({
|
|
238
|
+
isPopoverShow: false
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setEditorContainerRef", function (editorContainer) {
|
|
242
|
+
_this.editorContainer = editorContainer;
|
|
243
|
+
});
|
|
244
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setEditorRef", function (editor) {
|
|
245
|
+
_this.editor = editor;
|
|
246
|
+
});
|
|
247
|
+
_this.linkId = '';
|
|
248
|
+
_this.tableId = '';
|
|
249
|
+
_this.otherTableId = '';
|
|
250
|
+
_this.state = {
|
|
251
|
+
newValue: _this.getLinkedCellValue(),
|
|
252
|
+
isPopoverShow: false,
|
|
253
|
+
popoverPosition: {}
|
|
254
|
+
};
|
|
255
|
+
return _this;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
var _proto = LinkEditor.prototype;
|
|
259
|
+
|
|
260
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
261
|
+
document.addEventListener('click', this.onDocumentToggle);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
265
|
+
document.removeEventListener('click', this.onDocumentToggle);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
_proto.render = function render() {
|
|
269
|
+
var _this2 = this;
|
|
270
|
+
|
|
271
|
+
var isReadOnly = this.props.isReadOnly;
|
|
272
|
+
var _this$state = this.state,
|
|
273
|
+
isPopoverShow = _this$state.isPopoverShow,
|
|
274
|
+
popoverPosition = _this$state.popoverPosition;
|
|
275
|
+
var options = this.getAvailableLinkedOptions();
|
|
276
|
+
var selectedOptions = this.formatLinkedValuesToOptions();
|
|
277
|
+
var isShowRemoveIcon = !isReadOnly;
|
|
278
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
279
|
+
ref: this.setEditorContainerRef,
|
|
280
|
+
className: "cell-editor dtable-ui-link-editor"
|
|
281
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
282
|
+
ref: this.setEditorRef,
|
|
283
|
+
className: "dtable-ui-link-editor-container",
|
|
284
|
+
onClick: this.onAddOptionToggle
|
|
285
|
+
}, selectedOptions.length === 0 && /*#__PURE__*/_react.default.createElement(_editEditorButton.default, {
|
|
286
|
+
text: (0, _lang.getLocale)('Add_an_option')
|
|
287
|
+
}), selectedOptions.length !== 0 && selectedOptions.map(function (option) {
|
|
288
|
+
return /*#__PURE__*/_react.default.createElement(_linkEditorOption.default, {
|
|
289
|
+
key: option.id,
|
|
290
|
+
option: option,
|
|
291
|
+
isShowRemoveIcon: isShowRemoveIcon,
|
|
292
|
+
onDeleteLinkOption: _this2.onDeleteOption
|
|
293
|
+
});
|
|
294
|
+
})), isPopoverShow && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactResponsive.default, {
|
|
295
|
+
query: "(min-width: 768px)"
|
|
296
|
+
}, /*#__PURE__*/_react.default.createElement(_pcLinkEditorPopover.default, {
|
|
297
|
+
popoverPosition: popoverPosition,
|
|
298
|
+
options: options,
|
|
299
|
+
selectedOptions: selectedOptions,
|
|
300
|
+
onOptionItemToggle: this.onOptionItemToggle
|
|
301
|
+
})), /*#__PURE__*/_react.default.createElement(_reactResponsive.default, {
|
|
302
|
+
query: "(max-width: 767.8px)"
|
|
303
|
+
}, /*#__PURE__*/_react.default.createElement(_mbLinkEditorPopover.default, {
|
|
304
|
+
isReadOnly: this.props.isReadOnly,
|
|
305
|
+
value: this.state.newValue,
|
|
306
|
+
column: this.props.column,
|
|
307
|
+
options: options,
|
|
308
|
+
onOptionItemToggle: this.onOptionItemToggle,
|
|
309
|
+
onClosePopover: this.onClosePopover
|
|
310
|
+
}))));
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
return LinkEditor;
|
|
314
|
+
}(_react.default.Component);
|
|
315
|
+
|
|
316
|
+
(0, _defineProperty2.default)(LinkEditor, "defaultProps", {
|
|
317
|
+
isReadOnly: false
|
|
318
|
+
});
|
|
319
|
+
LinkEditor.propTypes = propTypes;
|
|
320
|
+
var _default = LinkEditor;
|
|
321
|
+
exports.default = _default;
|