dtable-ui-component 0.1.86 → 0.1.89

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,124 @@
1
+ .dtable-customize-collaborator-select.dtable-select {
2
+ position: unset;
3
+ }
4
+
5
+ .dtable-customize-collaborator-select .collaborator-avatar {
6
+ width: 16px;
7
+ height: 16px;
8
+ transform: translateY(-1px);
9
+ }
10
+
11
+ .dtable-customize-collaborator-select .option-group {
12
+ position: absolute;
13
+ left: 0px;
14
+ min-height: 60px;
15
+ max-height: unset;
16
+ min-width: 100%;
17
+ max-width: 15rem;
18
+ padding: 0.5rem 0;
19
+ box-shadow: 0 1px 2px 0 rgb(0 0 0 / 5%);
20
+ background: #fff;
21
+ border: 1px solid rgba(0,40,100,.12);
22
+ border-radius: 3px;
23
+ z-index: 10001;
24
+ }
25
+
26
+ .dtable-customize-collaborator-select .option-group .option-group-search {
27
+ width: 100%;
28
+ padding: 0 10px;
29
+ min-width: 170px;
30
+ }
31
+
32
+ .dtable-customize-collaborator-select .option-group-search .form-control {
33
+ height: 31px;
34
+ }
35
+
36
+ .dtable-customize-collaborator-select .option-group .none-search-result {
37
+ height: 100px;
38
+ width: 100%;
39
+ padding: 10px;
40
+ opacity: .5;
41
+ }
42
+
43
+ .dtable-customize-collaborator-select .option-group .option-group-content {
44
+ max-height: 252px;
45
+ overflow-y: auto;
46
+ padding: 10px;
47
+ }
48
+
49
+ .dtable-customize-collaborator-select .selected-option-show {
50
+ width: calc(100% - 20px);
51
+ height: 20px;
52
+ }
53
+
54
+ .dtable-customize-collaborator-select .selected-option {
55
+ width: auto;
56
+ overflow-x: auto;
57
+ }
58
+
59
+ .dtable-customize-collaborator-select .dtable-icon-drop-down {
60
+ margin-left: .5rem;
61
+ }
62
+
63
+ .dtable-customize-collaborator-select .option-collaborator {
64
+ display: flex;
65
+ }
66
+
67
+ .dtable-customize-collaborator-select .collaborator-container {
68
+ flex: 1 1;
69
+ }
70
+
71
+ .dtable-customize-collaborator-select .editor-list-delete .collaborator-container {
72
+ flex: 1 1;
73
+ display: inline;
74
+ }
75
+
76
+ .dtable-customize-collaborator-select .multiple-check-icon {
77
+ display: inline-flex;
78
+ width: 20px;
79
+ text-align: center;
80
+ }
81
+
82
+ .dtable-customize-collaborator-select .collaborator-check-icon .dtable-icon-check-mark,
83
+ .dtable-customize-collaborator-select .multiple-check-icon .dtable-icon-check-mark {
84
+ font-size: 12px;
85
+ color: #798d99;
86
+ }
87
+
88
+ .dtable-customize-collaborator-select.dtable-select .option-active,
89
+ .dtable-customize-collaborator-select.dtable-select .option:hover {
90
+ color: #212529;
91
+ background-color: #f7f7f7;
92
+ }
93
+
94
+ .dtable-customize-collaborator-select.dtable-select .option.option-active .select-option-name {
95
+ color: #202428;
96
+ }
97
+
98
+ .collaborator-select .option-group-content .collaborator,
99
+ .dtable-customize-collaborator-select .option-group .option-group-content .collaborator {
100
+ background: none;
101
+ }
102
+
103
+ .dtable-customize-collaborator-select .collaborator-avatar-container {
104
+ width: 16px;
105
+ }
106
+
107
+ .dtable-customize-collaborator-select .option-group-content .remove-container {
108
+ display: none;
109
+ }
110
+
111
+ .dtable-customize-collaborator-select .collaborator-container {
112
+ display: flex;
113
+ justify-content: space-between;
114
+ }
115
+
116
+ .collaborator-container .collaborator-name {
117
+ margin-left: 5px;
118
+ max-width: 200px;
119
+ color: #212529;
120
+ }
121
+
122
+ .collaborator-select .option-group {
123
+ max-height: fit-content;
124
+ }
@@ -0,0 +1,187 @@
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 classnames from 'classnames';
7
+ import { Popover } from 'reactstrap';
8
+ import SelectOptionGroup from '../SelectOptionGroup';
9
+ import { searchCollaborators } from './utils';
10
+ import './index.css';
11
+
12
+ var CollaboratorSelect = /*#__PURE__*/function (_Component) {
13
+ _inherits(CollaboratorSelect, _Component);
14
+
15
+ var _super = _createSuper(CollaboratorSelect);
16
+
17
+ function CollaboratorSelect(props) {
18
+ var _this;
19
+
20
+ _classCallCheck(this, CollaboratorSelect);
21
+
22
+ _this = _super.call(this, props);
23
+
24
+ _this.onSelectToggle = function (event) {
25
+ event.preventDefault();
26
+ /*
27
+ if select is showing, click events do not need to be monitored by other click events,
28
+ so it can be closed when other select is clicked.
29
+ */
30
+
31
+ if (_this.state.isShowSelectOptions) event.nativeEvent.stopImmediatePropagation();
32
+ var eventClassName = event.target.className;
33
+ if (_this.props.isLocked || eventClassName.indexOf('option-search-control') > -1 || eventClassName === 'option-group-search') return; //Prevent closing by pressing the spacebar in the search input
34
+
35
+ if (event.target.value === '') return;
36
+ _this.selectedOptionWidth = _this.selectedOptionRef.clientWidth;
37
+
38
+ _this.setState({
39
+ isShowSelectOptions: !_this.state.isShowSelectOptions
40
+ });
41
+ };
42
+
43
+ _this.onClick = function (event) {
44
+ var name = event.target.className;
45
+
46
+ if (name === 'select-placeholder' || name.includes('icon-fork-number')) {
47
+ return;
48
+ }
49
+
50
+ if (!_this.selector.contains(event.target)) {
51
+ _this.closeSelect();
52
+ }
53
+ };
54
+
55
+ _this.closeSelect = function () {
56
+ _this.setState({
57
+ isShowSelectOptions: false
58
+ });
59
+ };
60
+
61
+ _this.getFilterOptions = function (searchValue) {
62
+ var _this$props = _this.props,
63
+ options = _this$props.options,
64
+ searchable = _this$props.searchable;
65
+ if (!searchable) return options || [];
66
+ return searchCollaborators(options, searchValue);
67
+ };
68
+
69
+ _this.renderOptionGroup = function () {
70
+ var _this$props2 = _this.props,
71
+ value = _this$props2.value,
72
+ options = _this$props2.options,
73
+ searchable = _this$props2.searchable,
74
+ searchPlaceholder = _this$props2.searchPlaceholder,
75
+ noOptionsPlaceholder = _this$props2.noOptionsPlaceholder,
76
+ top = _this$props2.top,
77
+ left = _this$props2.left,
78
+ isUsePopover = _this$props2.isUsePopover;
79
+
80
+ if (!isUsePopover) {
81
+ return /*#__PURE__*/React.createElement(SelectOptionGroup, {
82
+ value: value,
83
+ top: top,
84
+ left: left,
85
+ minWidth: _this.btnWidth + 8 // 8px is padding
86
+ ,
87
+ options: options,
88
+ onSelectOption: _this.props.onSelectOption,
89
+ searchable: searchable,
90
+ searchPlaceholder: searchPlaceholder,
91
+ noOptionsPlaceholder: noOptionsPlaceholder,
92
+ closeSelect: _this.closeSelect,
93
+ getFilterOptions: _this.getFilterOptions,
94
+ supportMultipleSelect: _this.props.supportMultipleSelect,
95
+ stopClickEvent: true,
96
+ isShowSelected: true
97
+ });
98
+ }
99
+
100
+ return /*#__PURE__*/React.createElement(Popover, {
101
+ placement: "bottom",
102
+ isOpen: true,
103
+ target: _this.id,
104
+ fade: false,
105
+ hideArrow: true,
106
+ className: "dtable-customize-collaborator-select dtable-select"
107
+ }, /*#__PURE__*/React.createElement(SelectOptionGroup, {
108
+ value: value,
109
+ top: top,
110
+ left: left,
111
+ minWidth: _this.btnWidth + 8 // 8px is padding
112
+ ,
113
+ options: options,
114
+ onSelectOption: _this.props.onSelectOption,
115
+ searchable: searchable,
116
+ searchPlaceholder: searchPlaceholder,
117
+ noOptionsPlaceholder: noOptionsPlaceholder,
118
+ closeSelect: _this.closeSelect,
119
+ getFilterOptions: _this.getFilterOptions,
120
+ supportMultipleSelect: _this.props.supportMultipleSelect,
121
+ stopClickEvent: true,
122
+ isShowSelected: true
123
+ }));
124
+ };
125
+
126
+ _this.state = {
127
+ isShowSelectOptions: false
128
+ };
129
+ _this.id = 'collaborator-select-' + Math.trunc(Math.random() * 10000);
130
+ return _this;
131
+ }
132
+
133
+ _createClass(CollaboratorSelect, [{
134
+ key: "componentDidMount",
135
+ value: function componentDidMount() {
136
+ document.addEventListener('click', this.onClick);
137
+ this.btnWidth = this.selector.clientWidth;
138
+ }
139
+ }, {
140
+ key: "componentWillUnmount",
141
+ value: function componentWillUnmount() {
142
+ document.removeEventListener('click', this.onClick);
143
+ }
144
+ }, {
145
+ key: "render",
146
+ value: function render() {
147
+ var _this2 = this;
148
+
149
+ var _this$props3 = this.props,
150
+ className = _this$props3.className,
151
+ value = _this$props3.value,
152
+ placeholder = _this$props3.placeholder,
153
+ isLocked = _this$props3.isLocked;
154
+ return /*#__PURE__*/React.createElement("button", {
155
+ ref: function ref(node) {
156
+ return _this2.selector = node;
157
+ },
158
+ className: classnames('dtable-select custom-select collaborator-select', {
159
+ 'focus': this.state.isShowSelectOptions
160
+ }, {
161
+ 'disabled': isLocked
162
+ }, className),
163
+ id: this.id,
164
+ onClick: this.onSelectToggle
165
+ }, /*#__PURE__*/React.createElement("div", {
166
+ className: "selected-option",
167
+ ref: function ref(node) {
168
+ return _this2.selectedOptionRef = node;
169
+ }
170
+ }, value.label ? /*#__PURE__*/React.createElement("span", {
171
+ className: "selected-option-show"
172
+ }, value.label) : /*#__PURE__*/React.createElement("span", {
173
+ className: "select-placeholder"
174
+ }, placeholder), !isLocked && /*#__PURE__*/React.createElement("i", {
175
+ className: "dtable-font dtable-icon-drop-down"
176
+ })), this.state.isShowSelectOptions && this.renderOptionGroup());
177
+ }
178
+ }]);
179
+
180
+ return CollaboratorSelect;
181
+ }(Component);
182
+
183
+ CollaboratorSelect.defaultProps = {
184
+ top: -3,
185
+ left: -3
186
+ };
187
+ export default CollaboratorSelect;
@@ -0,0 +1,24 @@
1
+ export var searchCollaborators = function searchCollaborators(collaborators, searchValue) {
2
+ var validSearchValue = searchValue ? searchValue.trim().toLowerCase() : '';
3
+ var validCollaborators = Array.isArray(collaborators) && collaborators.length > 0 ? collaborators : [];
4
+ if (!validSearchValue) return validCollaborators;
5
+ return validCollaborators.filter(function (collaborator) {
6
+ var name = collaborator.name,
7
+ _collaborator$name_pi = collaborator.name_pinyin,
8
+ name_pinyin = _collaborator$name_pi === void 0 ? '' : _collaborator$name_pi;
9
+ if (name.toString().toLowerCase().indexOf(validSearchValue) > -1) return true;
10
+ if (!name_pinyin) return false;
11
+ var validNamePinyin = name_pinyin.toString().toLowerCase();
12
+ var validSearchPinyinValue = validSearchValue.replace(/ |'/g, ''); // complete
13
+
14
+ if (validNamePinyin.indexOf(validSearchPinyinValue) > -1) return true;
15
+ if (validNamePinyin.replace(/'/g, '').indexOf(validSearchPinyinValue) > -1) return true;
16
+ var validNamePinyinList = validNamePinyin.split('\''); // acronym
17
+
18
+ var namePinyinAcronym = validNamePinyinList.map(function (item) {
19
+ return item && item.trim() ? item.trim().slice(0, 1) : '';
20
+ });
21
+ if (namePinyinAcronym.join('').indexOf(validSearchPinyinValue) > -1) return true;
22
+ return false;
23
+ });
24
+ };
@@ -0,0 +1,155 @@
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 SelectOptionGroup from '../SelectOptionGroup';
7
+ import classnames from 'classnames';
8
+ import '../assets/css/DTableCustomSelect.css';
9
+
10
+ var DTableCustomizeSelect = /*#__PURE__*/function (_Component) {
11
+ _inherits(DTableCustomizeSelect, _Component);
12
+
13
+ var _super = _createSuper(DTableCustomizeSelect);
14
+
15
+ function DTableCustomizeSelect(props) {
16
+ var _this;
17
+
18
+ _classCallCheck(this, DTableCustomizeSelect);
19
+
20
+ _this = _super.call(this, props);
21
+
22
+ _this.onSelectToggle = function (event) {
23
+ event.preventDefault();
24
+ /*
25
+ if select is showing, click events do not need to be monitored by other click events,
26
+ so it can be closed when other select is clicked.
27
+ */
28
+
29
+ if (_this.state.isShowSelectOptions) event.nativeEvent.stopImmediatePropagation();
30
+ var eventClassName = event.target.className;
31
+ if (_this.props.isLocked || eventClassName.indexOf('option-search-control') > -1 || eventClassName === 'option-group-search') return; //Prevent closing by pressing the spacebar in the search input
32
+
33
+ if (event.target.value === '') return;
34
+
35
+ _this.setState({
36
+ isShowSelectOptions: !_this.state.isShowSelectOptions
37
+ });
38
+ };
39
+
40
+ _this.onClick = function (event) {
41
+ if (_this.props.isShowSelected && event.target.className.includes('icon-fork-number')) {
42
+ return;
43
+ }
44
+
45
+ if (!_this.selector.contains(event.target)) {
46
+ _this.closeSelect();
47
+ }
48
+ };
49
+
50
+ _this.closeSelect = function () {
51
+ _this.setState({
52
+ isShowSelectOptions: false
53
+ });
54
+ };
55
+
56
+ _this.getSelectedOptionTop = function () {
57
+ if (!_this.selector) return 38;
58
+
59
+ var _this$selector$getBou = _this.selector.getBoundingClientRect(),
60
+ height = _this$selector$getBou.height;
61
+
62
+ return height;
63
+ };
64
+
65
+ _this.getFilterOptions = function (searchValue) {
66
+ var _this$props = _this.props,
67
+ options = _this$props.options,
68
+ searchable = _this$props.searchable;
69
+ if (!searchable) return options || [];
70
+ var validSearchVal = searchValue.trim().toLowerCase();
71
+ if (!validSearchVal) return options || [];
72
+ return options.filter(function (option) {
73
+ var value = option.value,
74
+ name = option.name;
75
+
76
+ if (typeof name === 'string') {
77
+ return name.toLowerCase().indexOf(validSearchVal) > -1;
78
+ }
79
+
80
+ if (typeof value === 'object') {
81
+ return value.columnOption && value.columnOption.name.toLowerCase().indexOf(validSearchVal) > -1;
82
+ }
83
+
84
+ return false;
85
+ });
86
+ };
87
+
88
+ _this.state = {
89
+ isShowSelectOptions: false
90
+ };
91
+ return _this;
92
+ }
93
+
94
+ _createClass(DTableCustomizeSelect, [{
95
+ key: "componentDidMount",
96
+ value: function componentDidMount() {
97
+ document.addEventListener('click', this.onClick);
98
+ }
99
+ }, {
100
+ key: "componentWillUnmount",
101
+ value: function componentWillUnmount() {
102
+ document.removeEventListener('click', this.onClick);
103
+ }
104
+ }, {
105
+ key: "render",
106
+ value: function render() {
107
+ var _this2 = this;
108
+
109
+ var _this$props2 = this.props,
110
+ className = _this$props2.className,
111
+ value = _this$props2.value,
112
+ options = _this$props2.options,
113
+ placeholder = _this$props2.placeholder,
114
+ searchable = _this$props2.searchable,
115
+ searchPlaceholder = _this$props2.searchPlaceholder,
116
+ noOptionsPlaceholder = _this$props2.noOptionsPlaceholder,
117
+ isLocked = _this$props2.isLocked;
118
+ return /*#__PURE__*/React.createElement("div", {
119
+ ref: function ref(node) {
120
+ return _this2.selector = node;
121
+ },
122
+ className: classnames('dtable-select custom-select', {
123
+ 'focus': this.state.isShowSelectOptions
124
+ }, {
125
+ 'disabled': isLocked
126
+ }, className),
127
+ onClick: this.onSelectToggle
128
+ }, /*#__PURE__*/React.createElement("div", {
129
+ className: "selected-option"
130
+ }, value.label ? /*#__PURE__*/React.createElement("span", {
131
+ className: "selected-option-show"
132
+ }, value.label) : /*#__PURE__*/React.createElement("span", {
133
+ className: "select-placeholder"
134
+ }, placeholder), !isLocked && /*#__PURE__*/React.createElement("i", {
135
+ className: "dtable-font dtable-icon-drop-down"
136
+ })), this.state.isShowSelectOptions && /*#__PURE__*/React.createElement(SelectOptionGroup, {
137
+ value: value,
138
+ isShowSelected: this.props.isShowSelected,
139
+ top: this.getSelectedOptionTop(),
140
+ options: options,
141
+ onSelectOption: this.props.onSelectOption,
142
+ searchable: searchable,
143
+ searchPlaceholder: searchPlaceholder,
144
+ noOptionsPlaceholder: noOptionsPlaceholder,
145
+ closeSelect: this.closeSelect,
146
+ getFilterOptions: this.getFilterOptions,
147
+ supportMultipleSelect: this.props.supportMultipleSelect
148
+ }));
149
+ }
150
+ }]);
151
+
152
+ return DTableCustomizeSelect;
153
+ }(Component);
154
+
155
+ export default DTableCustomizeSelect;
@@ -0,0 +1,161 @@
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, Fragment } from 'react';
6
+ import classnames from 'classnames';
7
+ import { isFunction } from './utils';
8
+
9
+ var DtableSearchInput = /*#__PURE__*/function (_Component) {
10
+ _inherits(DtableSearchInput, _Component);
11
+
12
+ var _super = _createSuper(DtableSearchInput);
13
+
14
+ function DtableSearchInput(props) {
15
+ var _this;
16
+
17
+ _classCallCheck(this, DtableSearchInput);
18
+
19
+ _this = _super.call(this, props);
20
+
21
+ _this.onCompositionStart = function () {
22
+ _this.isInputtingChinese = true;
23
+ };
24
+
25
+ _this.onChange = function (e) {
26
+ _this.timer && clearTimeout(_this.timer);
27
+ var _this$props = _this.props,
28
+ onChange = _this$props.onChange,
29
+ wait = _this$props.wait;
30
+ var text = e.target.value;
31
+
32
+ _this.setState({
33
+ searchValue: text || ''
34
+ }, function () {
35
+ if (_this.isInputtingChinese) return;
36
+ _this.timer = setTimeout(function () {
37
+ onChange && onChange(_this.state.searchValue.trim());
38
+ }, wait);
39
+ });
40
+ };
41
+
42
+ _this.onCompositionEnd = function (e) {
43
+ _this.isInputtingChinese = false;
44
+
45
+ _this.onChange(e);
46
+ };
47
+
48
+ _this.clearSearch = function () {
49
+ var clearValue = _this.props.clearValue;
50
+
51
+ _this.setState({
52
+ searchValue: ''
53
+ }, function () {
54
+ clearValue && clearValue();
55
+ });
56
+ };
57
+
58
+ _this.setFocus = function (isSelectAllText) {
59
+ if (_this.inputRef === document.activeElement) return;
60
+
61
+ _this.inputRef.focus();
62
+
63
+ if (isSelectAllText) {
64
+ var txtLength = _this.state.searchValue.length;
65
+
66
+ _this.inputRef.setSelectionRange(0, txtLength);
67
+ }
68
+ };
69
+
70
+ _this.renderClear = function () {
71
+ var _this$props2 = _this.props,
72
+ isClearable = _this$props2.isClearable,
73
+ clearClassName = _this$props2.clearClassName,
74
+ _this$props2$componen = _this$props2.components,
75
+ components = _this$props2$componen === void 0 ? {} : _this$props2$componen;
76
+ var searchValue = _this.state.searchValue;
77
+ if (!isClearable || !searchValue) return null;
78
+ var ClearIndicator = components.ClearIndicator;
79
+
80
+ if (React.isValidElement(ClearIndicator)) {
81
+ return React.cloneElement(ClearIndicator, {
82
+ clearValue: _this.clearSearch
83
+ });
84
+ } else if (isFunction(ClearIndicator)) {
85
+ return /*#__PURE__*/React.createElement(ClearIndicator, {
86
+ clearValue: _this.clearSearch
87
+ });
88
+ }
89
+
90
+ return /*#__PURE__*/React.createElement("i", {
91
+ className: classnames('search-text-clear input-icon-addon', clearClassName),
92
+ onClick: _this.clearSearch
93
+ }, "\xD7");
94
+ };
95
+
96
+ _this.state = {
97
+ searchValue: props.value
98
+ };
99
+ _this.isInputtingChinese = false;
100
+ _this.timer = null;
101
+ _this.inputRef = null;
102
+ return _this;
103
+ }
104
+
105
+ _createClass(DtableSearchInput, [{
106
+ key: "componentWillReceiveProps",
107
+ value: function componentWillReceiveProps(nextProps) {
108
+ if (nextProps.value !== this.props.value) {
109
+ this.setState({
110
+ searchValue: nextProps.value
111
+ });
112
+ }
113
+ }
114
+ }, {
115
+ key: "componentWillUnmount",
116
+ value: function componentWillUnmount() {
117
+ this.timer && clearTimeout(this.timer);
118
+ this.timer = null;
119
+ this.inputRef = null;
120
+ }
121
+ }, {
122
+ key: "render",
123
+ value: function render() {
124
+ var _this2 = this;
125
+
126
+ var _this$props3 = this.props,
127
+ placeholder = _this$props3.placeholder,
128
+ autoFocus = _this$props3.autoFocus,
129
+ className = _this$props3.className,
130
+ onKeyDown = _this$props3.onKeyDown,
131
+ disabled = _this$props3.disabled,
132
+ style = _this$props3.style;
133
+ var searchValue = this.state.searchValue;
134
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("input", {
135
+ type: "text",
136
+ value: searchValue,
137
+ className: classnames('form-control', className),
138
+ onChange: this.onChange,
139
+ autoFocus: autoFocus,
140
+ placeholder: placeholder,
141
+ onCompositionStart: this.onCompositionStart,
142
+ onCompositionEnd: this.onCompositionEnd,
143
+ onKeyDown: onKeyDown,
144
+ disabled: disabled,
145
+ style: style,
146
+ ref: function ref(_ref) {
147
+ return _this2.inputRef = _ref;
148
+ }
149
+ }), this.renderClear());
150
+ }
151
+ }]);
152
+
153
+ return DtableSearchInput;
154
+ }(Component);
155
+
156
+ DtableSearchInput.defaultProps = {
157
+ wait: 100,
158
+ disabled: false,
159
+ value: ''
160
+ };
161
+ export default DtableSearchInput;
@@ -0,0 +1,4 @@
1
+ export var isFunction = function isFunction(functionToCheck) {
2
+ var getType = {};
3
+ return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
4
+ };
@@ -121,7 +121,8 @@ var ImagesLazyLoad = /*#__PURE__*/function (_React$Component) {
121
121
  marginLeft: '4px'
122
122
  };
123
123
  return /*#__PURE__*/React.createElement("div", {
124
- style: style
124
+ style: style,
125
+ className: "d-flex align-items-center"
125
126
  }, /*#__PURE__*/React.createElement(Loading, null));
126
127
  }
127
128
 
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ LeftArrow: 37,
3
+ UpArrow: 38,
4
+ RightArrow: 39,
5
+ DownArrow: 40,
6
+ Enter: 13,
7
+ Tab: 9,
8
+ Escape: 27,
9
+ Esc: 27
10
+ };
@@ -0,0 +1,217 @@
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 Option from './option';
7
+ import DTableSearchInput from '../DTableSearchInput';
8
+ import KeyCodes from './KeyCodes';
9
+ var OPTION_HEIGHT = 32;
10
+
11
+ var SelectOptionGroup = /*#__PURE__*/function (_Component) {
12
+ _inherits(SelectOptionGroup, _Component);
13
+
14
+ var _super = _createSuper(SelectOptionGroup);
15
+
16
+ function SelectOptionGroup(props) {
17
+ var _this;
18
+
19
+ _classCallCheck(this, SelectOptionGroup);
20
+
21
+ _this = _super.call(this, props);
22
+
23
+ _this.resetMenuStyle = function () {
24
+ var _this$optionGroupRef$ = _this.optionGroupRef.getBoundingClientRect(),
25
+ top = _this$optionGroupRef$.top,
26
+ height = _this$optionGroupRef$.height;
27
+
28
+ if (height + top > window.innerHeight) {
29
+ var borderWidth = 2;
30
+ _this.optionGroupRef.style.top = -1 * (height + borderWidth) + 'px';
31
+ }
32
+ };
33
+
34
+ _this.onHotKey = function (event) {
35
+ var keyCode = event.keyCode;
36
+
37
+ if (keyCode === KeyCodes.UpArrow) {
38
+ _this.onPressUp();
39
+ } else if (keyCode === KeyCodes.DownArrow) {
40
+ _this.onPressDown();
41
+ } else if (keyCode === KeyCodes.Enter) {
42
+ var option = _this.filterOptions && _this.filterOptions[_this.state.activeIndex];
43
+
44
+ if (option) {
45
+ _this.props.onSelectOption(option.value);
46
+
47
+ if (!_this.props.supportMultipleSelect) {
48
+ _this.props.closeSelect();
49
+ }
50
+ }
51
+ } else if (keyCode === KeyCodes.Tab || keyCode === KeyCodes.Escape) {
52
+ _this.props.closeSelect();
53
+ }
54
+ };
55
+
56
+ _this.onPressUp = function () {
57
+ if (_this.state.activeIndex > 0) {
58
+ _this.setState({
59
+ activeIndex: _this.state.activeIndex - 1
60
+ }, function () {
61
+ _this.scrollContent();
62
+ });
63
+ }
64
+ };
65
+
66
+ _this.onPressDown = function () {
67
+ if (_this.filterOptions && _this.state.activeIndex < _this.filterOptions.length - 1) {
68
+ _this.setState({
69
+ activeIndex: _this.state.activeIndex + 1
70
+ }, function () {
71
+ _this.scrollContent();
72
+ });
73
+ }
74
+ };
75
+
76
+ _this.onClick = function (e) {
77
+ if (_this.props.stopClickEvent && _this.optionGroupRef.contains(e.target) && !e.target.className.includes('dtable-font')) {
78
+ e.stopPropagation();
79
+ }
80
+ };
81
+
82
+ _this.scrollContent = function () {
83
+ var _this$optionGroupCont = _this.optionGroupContentRef,
84
+ offsetHeight = _this$optionGroupCont.offsetHeight,
85
+ scrollTop = _this$optionGroupCont.scrollTop;
86
+
87
+ if (_this.state.activeIndex * OPTION_HEIGHT < scrollTop) {
88
+ _this.optionGroupContentRef.scrollTop = scrollTop - OPTION_HEIGHT;
89
+ } else if (_this.state.activeIndex * OPTION_HEIGHT > offsetHeight + scrollTop) {
90
+ _this.optionGroupContentRef.scrollTop = scrollTop + OPTION_HEIGHT;
91
+ }
92
+ };
93
+
94
+ _this.changeIndex = function (index) {
95
+ _this.setState({
96
+ activeIndex: index
97
+ });
98
+ };
99
+
100
+ _this.onChangeSearch = function (searchVal) {
101
+ var value = searchVal || '';
102
+
103
+ if (value !== _this.state.searchVal) {
104
+ _this.setState({
105
+ searchVal: value,
106
+ activeIndex: -1
107
+ });
108
+ }
109
+ };
110
+
111
+ _this.renderOptGroup = function (searchVal) {
112
+ var _this$props = _this.props,
113
+ noOptionsPlaceholder = _this$props.noOptionsPlaceholder,
114
+ onSelectOption = _this$props.onSelectOption;
115
+ _this.filterOptions = _this.props.getFilterOptions(searchVal);
116
+
117
+ if (_this.filterOptions === 0) {
118
+ return /*#__PURE__*/React.createElement("div", {
119
+ className: "none-search-result"
120
+ }, noOptionsPlaceholder);
121
+ }
122
+
123
+ return _this.filterOptions.map(function (opt, i) {
124
+ var key = opt.value.column ? opt.value.column.key : i;
125
+ var isActive = _this.state.activeIndex === i;
126
+ return /*#__PURE__*/React.createElement(Option, {
127
+ key: key,
128
+ index: i,
129
+ isActive: isActive,
130
+ value: opt.value,
131
+ onSelectOption: onSelectOption,
132
+ changeIndex: _this.changeIndex,
133
+ supportMultipleSelect: _this.props.supportMultipleSelect
134
+ }, opt.label);
135
+ });
136
+ };
137
+
138
+ _this.state = {
139
+ searchVal: '',
140
+ activeIndex: -1
141
+ };
142
+ _this.filterOptions = null;
143
+ return _this;
144
+ }
145
+
146
+ _createClass(SelectOptionGroup, [{
147
+ key: "componentDidMount",
148
+ value: function componentDidMount() {
149
+ window.addEventListener('keydown', this.onHotKey);
150
+ window.addEventListener('click', this.onClick, true);
151
+ this.resetMenuStyle();
152
+ }
153
+ }, {
154
+ key: "componentWillUnmount",
155
+ value: function componentWillUnmount() {
156
+ this.filterOptions = null;
157
+ window.removeEventListener('click', this.onClick, true);
158
+ window.removeEventListener('keydown', this.onHotKey);
159
+ }
160
+ }, {
161
+ key: "render",
162
+ value: function render() {
163
+ var _this2 = this;
164
+
165
+ var _this$props2 = this.props,
166
+ searchable = _this$props2.searchable,
167
+ searchPlaceholder = _this$props2.searchPlaceholder,
168
+ top = _this$props2.top,
169
+ left = _this$props2.left,
170
+ minWidth = _this$props2.minWidth,
171
+ value = _this$props2.value,
172
+ isShowSelected = _this$props2.isShowSelected;
173
+ var searchVal = this.state.searchVal;
174
+ var style = {
175
+ top: top || 0,
176
+ left: left || 0
177
+ };
178
+
179
+ if (minWidth) {
180
+ style = {
181
+ top: top || 0,
182
+ left: left || 0,
183
+ minWidth: minWidth
184
+ };
185
+ }
186
+
187
+ return /*#__PURE__*/React.createElement("div", {
188
+ className: "option-group ".concat(isShowSelected ? 'pt-0' : ''),
189
+ ref: function ref(_ref2) {
190
+ return _this2.optionGroupRef = _ref2;
191
+ },
192
+ style: style
193
+ }, isShowSelected && /*#__PURE__*/React.createElement("div", {
194
+ className: "editor-list-delete mb-2",
195
+ onClick: function onClick(e) {
196
+ return e.stopPropagation();
197
+ }
198
+ }, value.label || ''), searchable && /*#__PURE__*/React.createElement("div", {
199
+ className: "option-group-search"
200
+ }, /*#__PURE__*/React.createElement(DTableSearchInput, {
201
+ className: "option-search-control",
202
+ placeholder: searchPlaceholder,
203
+ onChange: this.onChangeSearch,
204
+ autoFocus: true
205
+ })), /*#__PURE__*/React.createElement("div", {
206
+ className: "option-group-content",
207
+ ref: function ref(_ref) {
208
+ return _this2.optionGroupContentRef = _ref;
209
+ }
210
+ }, this.renderOptGroup(searchVal)));
211
+ }
212
+ }]);
213
+
214
+ return SelectOptionGroup;
215
+ }(Component);
216
+
217
+ export default SelectOptionGroup;
@@ -0,0 +1,60 @@
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
+
7
+ var Option = /*#__PURE__*/function (_Component) {
8
+ _inherits(Option, _Component);
9
+
10
+ var _super = _createSuper(Option);
11
+
12
+ function Option() {
13
+ var _this;
14
+
15
+ _classCallCheck(this, Option);
16
+
17
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
18
+ args[_key] = arguments[_key];
19
+ }
20
+
21
+ _this = _super.call.apply(_super, [this].concat(args));
22
+
23
+ _this.onSelectOption = function (value, event) {
24
+ _this.props.onSelectOption(value, event);
25
+ };
26
+
27
+ _this.onClick = function (event) {
28
+ if (_this.props.supportMultipleSelect) {
29
+ event.stopPropagation();
30
+ }
31
+ };
32
+
33
+ _this.onMouseEnter = function () {
34
+ _this.props.changeIndex(_this.props.index);
35
+ };
36
+
37
+ _this.onMouseLeave = function () {
38
+ _this.props.changeIndex(-1);
39
+ };
40
+
41
+ return _this;
42
+ }
43
+
44
+ _createClass(Option, [{
45
+ key: "render",
46
+ value: function render() {
47
+ return /*#__PURE__*/React.createElement("div", {
48
+ className: this.props.isActive ? 'option option-active' : 'option',
49
+ onMouseDown: this.onSelectOption.bind(this, this.props.value),
50
+ onClick: this.onClick,
51
+ onMouseEnter: this.onMouseEnter,
52
+ onMouseLeave: this.onMouseLeave
53
+ }, this.props.children);
54
+ }
55
+ }]);
56
+
57
+ return Option;
58
+ }(Component);
59
+
60
+ export default Option;
@@ -0,0 +1,148 @@
1
+ .dtable-select {
2
+ position: relative;
3
+ }
4
+
5
+ .dtable-select.custom-select {
6
+ display: flex;
7
+ padding: 0 10px;
8
+ border-radius: 3px;
9
+ align-items: center;
10
+ justify-content: space-between;
11
+ max-width: 900px;
12
+ user-select: none;
13
+ -webkit-user-select: none;
14
+ -moz-user-select: none;
15
+ -o-user-select: none;
16
+ -ms-user-select: none;
17
+ text-align: left;
18
+ }
19
+
20
+ .dtable-select.custom-select:focus,
21
+ .dtable-select.custom-select.focus {
22
+ border-color: #1991eb !important;
23
+ box-shadow: 0 0 0 2px rgba(70, 127, 207, 0.25);
24
+ }
25
+
26
+ .dtable-select.custom-select.disabled:focus,
27
+ .dtable-select.custom-select.focus.disabled,
28
+ .dtable-select.custom-select.disabled:hover {
29
+ border-color: rgba(0, 40, 100, 0.12) !important;
30
+ box-shadow: unset;
31
+ cursor: default;
32
+ }
33
+
34
+ .dtable-select.custom-select:hover {
35
+ cursor: pointer;
36
+ border-color: rgb(179, 179, 179);
37
+ }
38
+
39
+ .dtable-select .select-option-name {
40
+ color: #202428;
41
+ }
42
+
43
+ .dtable-select .dtable-icon-drop-down {
44
+ display: inline-block;
45
+ font-size: 12px;
46
+ color: #949494;
47
+ transform: scale(.8) translateY(2px);
48
+ transition: all .1s;
49
+ }
50
+
51
+ .dtable-select .dtable-icon-drop-down:hover {
52
+ color: #000;
53
+ }
54
+
55
+ .dtable-select .selected-option {
56
+ display: flex;
57
+ flex: 1;
58
+ overflow: hidden;
59
+ flex-wrap: nowrap;
60
+ align-items: center;
61
+ justify-content: space-between;
62
+ background: #fff;
63
+ }
64
+
65
+ .dtable-select .option-group {
66
+ position: absolute;
67
+ left: 0;
68
+ min-height: 60px;
69
+ max-height: 300px;
70
+ min-width: 100%;
71
+ max-width: 15rem;
72
+ padding: .5rem 0;
73
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
74
+ background: #fff;
75
+ border: 1px solid rgba(0, 40, 100, 0.12);
76
+ border-radius: 3px;
77
+ z-index: 10001;
78
+ }
79
+
80
+ .dtable-select .option-group .option-group-search {
81
+ width: 100%;
82
+ padding: 0 10px 6px 10px;
83
+ min-width: 170px;
84
+ }
85
+
86
+ .dtable-select .option-group-search .form-control {
87
+ height: 31px;
88
+ }
89
+
90
+ .dtable-select .option-group .none-search-result {
91
+ height: 100px;
92
+ width: 100%;
93
+ padding: 10px;
94
+ opacity: .5;
95
+ }
96
+
97
+ .dtable-select .option-group .option-group-content {
98
+ max-height: 252px;
99
+ overflow-y: auto;
100
+ }
101
+
102
+ .dtable-select .option {
103
+ display: block;
104
+ width: 100%;
105
+ line-height: 24px;
106
+ padding: .25rem 10px;
107
+ clear: both;
108
+ font-weight: 400;
109
+ color: #212529;
110
+ text-align: inherit;
111
+ background-color: transparent;
112
+ border: 0;
113
+ overflow: hidden;
114
+ text-overflow: ellipsis;
115
+ white-space: nowrap;
116
+ }
117
+
118
+ .dtable-select.selector-collaborator .option-group .option-group-content {
119
+ padding: 10px;
120
+ }
121
+
122
+ .dtable-select.selector-collaborator .option {
123
+ padding: 5px 0 5px 10px !important;
124
+ line-height: 20px;
125
+ }
126
+
127
+ .dtable-select .option.option-active {
128
+ background-color: #20a0ff;
129
+ color: #fff;
130
+ cursor: pointer;
131
+ }
132
+
133
+ .dtable-select .option.option-active .select-option-name {
134
+ color: #fff;
135
+ }
136
+
137
+ .dtable-select .selected-option-show {
138
+ overflow: hidden;
139
+ text-overflow: ellipsis;
140
+ white-space: nowrap;
141
+ }
142
+
143
+ .dtable-select .select-placeholder {
144
+ line-height: 1;
145
+ font-size: 14px;
146
+ color: #949494;
147
+ white-space: nowrap;
148
+ }
package/lib/index.js CHANGED
@@ -45,4 +45,7 @@ export { default as LinkEditor } from './LinkEditor'; // dtable custom
45
45
 
46
46
  export { default as DTablePopover } from './DTablePopover';
47
47
  export { default as DTableSelect } from './DTableSelect';
48
- export { default as DTableSwitch } from './DTableSwitch';
48
+ export { default as DTableSwitch } from './DTableSwitch';
49
+ export { default as DTableCustomizeSelect } from './DTableCustomizeSelect';
50
+ export { default as DTableCustomizeCollaboratorSelect } from './DTableCustomizeCollaboratorSelect';
51
+ export { default as DTableSearchInput } from './DTableSearchInput';
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "0.1.86",
3
+ "version": "0.1.89",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "0.0.9",
7
- "@seafile/seafile-calendar": "^0.0.19",
7
+ "@seafile/seafile-calendar": "^0.0.21",
8
8
  "antd-mobile": "^2.3.3",
9
9
  "astro-classname": "^2.1.0",
10
10
  "bail": "1.0.5",
11
- "dayjs": "^1.10.7",
11
+ "dayjs": "1.10.7",
12
12
  "deepmerge": "^2.1.0",
13
13
  "enzyme": "^3.11.0",
14
14
  "enzyme-adapter-react-16": "^1.15.2",