wini-web-components 2.2.8 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/component/button/button.d.ts +16 -16
  2. package/dist/component/button/button.js +39 -39
  3. package/dist/component/calendar/calendar.d.ts +30 -46
  4. package/dist/component/calendar/calendar.js +437 -432
  5. package/dist/component/checkbox/checkbox.d.ts +24 -22
  6. package/dist/component/checkbox/checkbox.js +120 -81
  7. package/dist/component/component-status.d.ts +8 -8
  8. package/dist/component/component-status.js +39 -39
  9. package/dist/component/date-picker/date-picker.d.ts +25 -36
  10. package/dist/component/date-picker/date-picker.js +362 -359
  11. package/dist/component/dialog/dialog.d.ts +36 -34
  12. package/dist/component/dialog/dialog.js +99 -97
  13. package/dist/component/import-file/import-file.d.ts +24 -36
  14. package/dist/component/import-file/import-file.js +154 -119
  15. package/dist/component/infinite-scroll/infinite-scroll.d.ts +17 -17
  16. package/dist/component/infinite-scroll/infinite-scroll.js +103 -103
  17. package/dist/component/input-multi-select/input-multi-select.d.ts +21 -38
  18. package/dist/component/input-multi-select/input-multi-select.js +334 -323
  19. package/dist/component/input-opt/input-opt.d.ts +21 -21
  20. package/dist/component/input-opt/input-opt.js +157 -147
  21. package/dist/component/number-picker/number-picker.d.ts +19 -19
  22. package/dist/component/number-picker/number-picker.js +137 -127
  23. package/dist/component/pagination/pagination.d.ts +13 -13
  24. package/dist/component/pagination/pagination.js +93 -82
  25. package/dist/component/popup/popup.d.ts +33 -33
  26. package/dist/component/popup/popup.js +138 -105
  27. package/dist/component/progress-bar/progress-bar.d.ts +16 -16
  28. package/dist/component/progress-bar/progress-bar.js +35 -36
  29. package/dist/component/progress-circle/progress-circle.d.ts +14 -14
  30. package/dist/component/progress-circle/progress-circle.js +30 -31
  31. package/dist/component/radio-button/radio-button.d.ts +20 -20
  32. package/dist/component/radio-button/radio-button.js +64 -64
  33. package/dist/component/rating/rating.d.ts +23 -23
  34. package/dist/component/rating/rating.js +73 -74
  35. package/dist/component/select1/select1.d.ts +31 -50
  36. package/dist/component/select1/select1.js +320 -309
  37. package/dist/component/slider/slider.d.ts +31 -31
  38. package/dist/component/slider/slider.js +80 -81
  39. package/dist/component/switch/switch.d.ts +23 -23
  40. package/dist/component/switch/switch.js +80 -81
  41. package/dist/component/table/table.d.ts +51 -51
  42. package/dist/component/table/table.js +119 -119
  43. package/dist/component/tag/tag.d.ts +17 -17
  44. package/dist/component/tag/tag.js +39 -39
  45. package/dist/component/text/text.d.ts +16 -16
  46. package/dist/component/text/text.js +51 -51
  47. package/dist/component/text-area/text-area.d.ts +28 -28
  48. package/dist/component/text-area/text-area.js +83 -73
  49. package/dist/component/text-field/text-field.d.ts +33 -33
  50. package/dist/component/text-field/text-field.js +107 -97
  51. package/dist/component/toast-noti/toast-noti.d.ts +5 -5
  52. package/dist/component/toast-noti/toast-noti.js +28 -28
  53. package/dist/component/wini-icon/winicon.d.ts +16 -16
  54. package/dist/component/wini-icon/winicon.js +121 -112
  55. package/dist/form/login/view.d.ts +40 -40
  56. package/dist/form/login/view.js +66 -65
  57. package/dist/i18n.d.ts +2 -0
  58. package/dist/i18n.js +125 -0
  59. package/dist/index.d.ts +32 -31
  60. package/dist/index.js +1 -1
  61. package/dist/language/i18n.d.ts +2 -0
  62. package/dist/language/i18n.js +125 -0
  63. package/package.json +5 -3
@@ -1,309 +1,320 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
- if (k2 === undefined) k2 = k;
30
- var desc = Object.getOwnPropertyDescriptor(m, k);
31
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
- desc = { enumerable: true, get: function() { return m[k]; } };
33
- }
34
- Object.defineProperty(o, k2, desc);
35
- }) : (function(o, m, k, k2) {
36
- if (k2 === undefined) k2 = k;
37
- o[k2] = m[k];
38
- }));
39
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
- Object.defineProperty(o, "default", { enumerable: true, value: v });
41
- }) : function(o, v) {
42
- o["default"] = v;
43
- });
44
- var __importStar = (this && this.__importStar) || function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
- __setModuleDefault(result, mod);
49
- return result;
50
- };
51
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
- return new (P || (P = Promise))(function (resolve, reject) {
54
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
55
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
56
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
- step((generator = generator.apply(thisArg, _arguments || [])).next());
58
- });
59
- };
60
- var __generator = (this && this.__generator) || function (thisArg, body) {
61
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
62
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- };
87
- var __importDefault = (this && this.__importDefault) || function (mod) {
88
- return (mod && mod.__esModule) ? mod : { "default": mod };
89
- };
90
- Object.defineProperty(exports, "__esModule", { value: true });
91
- exports.Select1 = void 0;
92
- var select1_module_css_1 = __importDefault(require("./select1.module.css"));
93
- var react_1 = __importStar(require("react"));
94
- var react_dom_1 = __importDefault(require("react-dom"));
95
- var winicon_1 = require("../wini-icon/winicon");
96
- var text_1 = require("../text/text");
97
- ;
98
- var Select1 = /** @class */ (function (_super) {
99
- __extends(Select1, _super);
100
- function Select1(props) {
101
- var _this = this;
102
- var _a, _b;
103
- _this = _super.call(this, props) || this;
104
- _this.containerRef = (0, react_1.createRef)();
105
- _this.inputRef = (0, react_1.createRef)();
106
- _this.onKeyDown = function (ev) {
107
- var _a, _b, _c, _d, _e, _f, _g;
108
- if ((((_a = _this.state.options) === null || _a === void 0 ? void 0 : _a.length) || ((_b = _this.state.search) === null || _b === void 0 ? void 0 : _b.length)) && _this.state.isOpen) {
109
- switch (ev.key.toLowerCase()) {
110
- case "enter":
111
- ev.preventDefault();
112
- var _selectItem = ((_c = _this.state.search) !== null && _c !== void 0 ? _c : _this.state.options).find(function (e) { return e.id === _this.state.selected; });
113
- if (_selectItem)
114
- _this.onSelect(_selectItem);
115
- break;
116
- case "arrowup":
117
- ev.preventDefault();
118
- if (_this.state.selected) {
119
- var _index = ((_d = _this.state.search) !== null && _d !== void 0 ? _d : _this.state.options).findIndex(function (e) { return e.id === _this.state.selected; });
120
- _index = ((_index === 0) ? _this.props.options.length : _index) - 1;
121
- _this.setState(__assign(__assign({}, _this.state), { selected: (_e = _this.props.options[_index]) === null || _e === void 0 ? void 0 : _e.id }));
122
- }
123
- break;
124
- case "arrowdown":
125
- ev.preventDefault();
126
- if (_this.state.selected) {
127
- var _index = ((_f = _this.state.search) !== null && _f !== void 0 ? _f : _this.state.options).findIndex(function (e) { return e.id === _this.state.selected; });
128
- _index = ((_index + 1 === _this.props.options.length) ? -1 : _index) + 1;
129
- _this.setState(__assign(__assign({}, _this.state), { selected: (_g = _this.props.options[_index]) === null || _g === void 0 ? void 0 : _g.id }));
130
- }
131
- break;
132
- default:
133
- break;
134
- }
135
- }
136
- };
137
- _this.state = {
138
- value: props.value,
139
- options: props.options,
140
- offset: {
141
- x: 0,
142
- y: 0,
143
- height: 0,
144
- width: 0,
145
- bottom: 0,
146
- left: 0,
147
- right: 0,
148
- top: 0,
149
- toJSON: function () {
150
- throw new Error('Function not implemented.');
151
- }
152
- },
153
- isOpen: false,
154
- onSelect: null,
155
- };
156
- _this.search = _this.search.bind(_this);
157
- _this.onSelect = _this.onSelect.bind(_this);
158
- _this.onKeyDown = _this.onKeyDown.bind(_this);
159
- if (_this.inputRef.current)
160
- _this.inputRef.current.value = "".concat((_b = (_a = _this.state.options.find(function (e) { return e.id === _this.state.value; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "");
161
- return _this;
162
- }
163
- Select1.prototype.search = function (ev) {
164
- var _a;
165
- return __awaiter(this, void 0, void 0, function () {
166
- var res;
167
- return __generator(this, function (_b) {
168
- switch (_b.label) {
169
- case 0:
170
- if (!ev.target.value.trim().length) return [3 /*break*/, 4];
171
- if (!((_a = this.props) === null || _a === void 0 ? void 0 : _a.handleSearch)) return [3 /*break*/, 2];
172
- return [4 /*yield*/, this.props.handleSearch(ev.target.value.trim())];
173
- case 1:
174
- res = _b.sent();
175
- this.setState(__assign(__assign({}, this.state), { search: res }));
176
- return [3 /*break*/, 3];
177
- case 2:
178
- this.setState(__assign(__assign({}, this.state), { search: this.props.options.filter(function (e) { return typeof e.name === "string" && e.name.toLowerCase().includes(ev.target.value.trim().toLowerCase()); }) }));
179
- _b.label = 3;
180
- case 3: return [3 /*break*/, 5];
181
- case 4:
182
- this.setState(__assign(__assign({}, this.state), { search: undefined }));
183
- _b.label = 5;
184
- case 5: return [2 /*return*/];
185
- }
186
- });
187
- });
188
- };
189
- Select1.prototype.onSelect = function (item) {
190
- var _a, _b;
191
- if (item.disabled) {
192
- this.setState(__assign(__assign({}, this.state), { isOpen: false, onSelect: undefined, selected: undefined }));
193
- (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
194
- }
195
- else {
196
- var newState = __assign(__assign({}, this.state), { isOpen: false, value: item.id, onSelect: undefined, selected: undefined });
197
- if (!newState.options.some(function (e) { return e.id === item.id; }))
198
- newState.options.push(item);
199
- this.setState(newState);
200
- (_b = this.inputRef.current) === null || _b === void 0 ? void 0 : _b.blur();
201
- }
202
- if (this.props.onChange)
203
- this.props.onChange(item);
204
- };
205
- Select1.prototype.componentDidUpdate = function (prevProps, prevState) {
206
- var _this = this;
207
- var _a, _b, _c, _d, _e, _f, _g, _h;
208
- if (prevProps.options !== this.props.options) {
209
- this.setState(__assign(__assign({}, this.state), { options: this.props.options }));
210
- if (this.inputRef.current)
211
- this.inputRef.current.value = "".concat((_b = (_a = this.props.options.find(function (e) { return e.id === _this.state.value; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "");
212
- }
213
- if (prevProps.value !== this.props.value)
214
- this.setState(__assign(__assign({}, this.state), { value: this.props.value }));
215
- if (prevState.value !== this.state.value && this.inputRef.current)
216
- this.inputRef.current.value = "".concat((_d = (_c = this.state.options.find(function (e) { return e.id === _this.state.value; })) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : "");
217
- //
218
- if (this.state.isOpen && prevState.isOpen !== this.state.isOpen) {
219
- var thisPopupRect = (_e = document.body.querySelector(":scope > .select1-popup")) === null || _e === void 0 ? void 0 : _e.getBoundingClientRect();
220
- if (thisPopupRect) {
221
- var style = void 0;
222
- if (thisPopupRect.right > document.body.offsetWidth) {
223
- style = {
224
- top: this.state.offset.y + this.state.offset.height + 2 + 'px',
225
- right: document.body.offsetWidth - this.state.offset.right + 'px'
226
- };
227
- }
228
- var _bottom = thisPopupRect.bottom - 8;
229
- var thisContainerRect = (_f = this.containerRef.current) === null || _f === void 0 ? void 0 : _f.getBoundingClientRect();
230
- if (thisContainerRect) {
231
- if (_bottom > document.body.offsetHeight) {
232
- style = __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { top: "".concat(thisContainerRect.y - 2 - thisPopupRect.height, "px") });
233
- }
234
- }
235
- if (style) {
236
- (_g = style.left) !== null && _g !== void 0 ? _g : (style.left = style.right ? undefined : "".concat(this.state.offset.x, "px"));
237
- (_h = style.width) !== null && _h !== void 0 ? _h : (style.width = "".concat(this.state.offset.width, "px"));
238
- this.setState(__assign(__assign({}, this.state), { style: style }));
239
- }
240
- }
241
- }
242
- };
243
- Select1.prototype.componentDidMount = function () {
244
- var _this = this;
245
- var _a, _b;
246
- if (this.inputRef.current)
247
- this.inputRef.current.value = "".concat((_b = (_a = this.state.options.find(function (e) { return e.id === _this.state.value; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "");
248
- };
249
- Select1.prototype.render = function () {
250
- var _this = this;
251
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
252
- var _value = this.state.options.find(function (e) { return e.id === _this.state.value; });
253
- return react_1.default.createElement("div", { id: this.props.id, ref: this.containerRef, className: "".concat(select1_module_css_1.default['select1-container'], " row ").concat(this.props.disabled ? select1_module_css_1.default['disabled'] : '', " ").concat(((_a = this.props.helperText) === null || _a === void 0 ? void 0 : _a.length) && select1_module_css_1.default['helper-text'], " ").concat((_b = this.props.className) !== null && _b !== void 0 ? _b : 'body-3'), "helper-text": this.props.helperText, style: this.props.style ? __assign(__assign({}, { '--helper-text-color': (_c = this.props.helperTextColor) !== null && _c !== void 0 ? _c : '#e14337' }), this.props.style) : { '--helper-text-color': (_d = this.props.helperTextColor) !== null && _d !== void 0 ? _d : '#e14337' }, onClick: function () {
254
- var _a, _b, _c;
255
- if (!_this.state.isOpen) {
256
- _this.setState(__assign(__assign({}, _this.state), { isOpen: true, style: undefined, offset: (_b = (_a = _this.containerRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect() }));
257
- (_c = _this.inputRef.current) === null || _c === void 0 ? void 0 : _c.focus();
258
- }
259
- } },
260
- this.props.prefix,
261
- (!_value || typeof _value.name === "string" || typeof _value.name === "number") ? react_1.default.createElement("input", { ref: this.inputRef, readOnly: this.props.readOnly, onChange: this.search, placeholder: this.props.placeholder, onKeyDown: this.onKeyDown, onBlur: function (ev) {
262
- if (_this.state.onSelect && !_this.props.readOnly)
263
- ev.target.focus();
264
- else if (!_this.state.onSelect)
265
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, onSelect: null }));
266
- } }) : _value.name, (_e = this.props.suffix) !== null && _e !== void 0 ? _e : react_1.default.createElement("div", { ref: function (iconRef) {
267
- if ((iconRef === null || iconRef === void 0 ? void 0 : iconRef.parentElement) && iconRef.parentElement.getBoundingClientRect().width < 100)
268
- iconRef.style.display = "none";
269
- }, className: 'row' },
270
- react_1.default.createElement(winicon_1.Winicon, { src: this.state.isOpen ? "fill/arrows/up-arrow" : "fill/arrows/down-arrow", size: "1.2rem" })),
271
- this.state.isOpen &&
272
- react_dom_1.default.createPortal(react_1.default.createElement("div", { ref: function (popupRef) {
273
- if (popupRef && _this.props.onOpenOptions)
274
- _this.props.onOpenOptions(popupRef);
275
- }, className: "".concat(select1_module_css_1.default['select1-popup'], " select1-popup col ").concat((_f = this.props.popupClassName) !== null && _f !== void 0 ? _f : ""), style: (_g = this.state.style) !== null && _g !== void 0 ? _g : {
276
- top: this.state.offset.y + this.state.offset.height + 2 + 'px',
277
- left: this.state.offset.x + 'px',
278
- width: this.state.offset.width,
279
- }, onMouseOver: function (ev) { return _this.setState(__assign(__assign({}, _this.state), { onSelect: ev.target })); }, onMouseOut: function () { return _this.setState(__assign(__assign({}, _this.state), { onSelect: null })); } },
280
- react_1.default.createElement("div", { className: "col ".concat(select1_module_css_1.default['select-body']), onScroll: this.props.handleLoadmore ? function (ev) {
281
- if (_this.props.handleLoadmore) {
282
- var scrollElement = ev.target;
283
- _this.props.handleLoadmore(Math.round(scrollElement.offsetHeight + scrollElement.scrollTop) >= (scrollElement.scrollHeight - 1), ev);
284
- }
285
- } : undefined },
286
- ((_h = this.state.search) !== null && _h !== void 0 ? _h : this.state.options).filter(function (e) { return !e.parentId; }).map(function (item) {
287
- var _a, _b;
288
- return react_1.default.createElement(OptionsItemTile, { key: item.id, item: item, children: ((_a = _this.state.search) !== null && _a !== void 0 ? _a : _this.state.options).filter(function (e) { return e.parentId === item.id; }), selected: _this.state.selected === item.id, onClick: _this.onSelect, treeData: ((_b = _this.state.search) !== null && _b !== void 0 ? _b : _this.state.options).some(function (e) { return e.parentId; }) });
289
- }),
290
- (((_j = this.state.search) === null || _j === void 0 ? void 0 : _j.length) === 0 || ((_k = this.props.options) === null || _k === void 0 ? void 0 : _k.length) === 0) && (react_1.default.createElement("div", { className: select1_module_css_1.default['no-results-found'] }, "No result found")))), document.body));
291
- };
292
- return Select1;
293
- }(react_1.default.Component));
294
- exports.Select1 = Select1;
295
- function OptionsItemTile(_a) {
296
- var item = _a.item, children = _a.children, selected = _a.selected, onClick = _a.onClick, treeData = _a.treeData;
297
- var _b = (0, react_1.useState)(false), isOpen = _b[0], setIsOpen = _b[1];
298
- return item.title && typeof item.title !== "string" ? react_1.default.createElement(react_1.default.Fragment, null, item.title(onClick)) : react_1.default.createElement("div", { className: 'col', style: { width: '100%' } },
299
- react_1.default.createElement("div", { className: "".concat(select1_module_css_1.default['select-tile'], " row ").concat(item.disabled ? select1_module_css_1.default["disabled"] : ""), style: { paddingLeft: item.parentId ? '4.4rem' : undefined, backgroundColor: selected ? "var(--neutral-selected-background-color)" : undefined }, onClick: function () {
300
- if (children === null || children === void 0 ? void 0 : children.length) {
301
- setIsOpen(!isOpen);
302
- }
303
- else
304
- onClick(item);
305
- } },
306
- treeData ? react_1.default.createElement("div", { className: 'row', style: { width: '1.4rem', height: '1.4rem' } }, (children === null || children === void 0 ? void 0 : children.length) ? react_1.default.createElement(winicon_1.Winicon, { src: isOpen ? "fill/arrows/triangle-down" : "fill/arrows/triangle-right", size: "1.2rem" }) : null) : undefined,
307
- react_1.default.createElement(text_1.Text, { className: 'body-3' }, item.title && typeof item.title === "string" ? item.title : item.name)),
308
- (children === null || children === void 0 ? void 0 : children.length) ? react_1.default.createElement("div", { className: 'col', style: { display: isOpen ? "flex" : "none", width: '100%' } }, children.map(function (e) { return react_1.default.createElement(OptionsItemTile, { key: e.id, item: e, onClick: onClick }); })) : undefined);
309
- }
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
61
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
62
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
63
+ return new (P || (P = Promise))(function (resolve, reject) {
64
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
65
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
66
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
67
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
68
+ });
69
+ };
70
+ var __generator = (this && this.__generator) || function (thisArg, body) {
71
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
72
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
73
+ function verb(n) { return function (v) { return step([n, v]); }; }
74
+ function step(op) {
75
+ if (f) throw new TypeError("Generator is already executing.");
76
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
77
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
78
+ if (y = 0, t) op = [op[0] & 2, t.value];
79
+ switch (op[0]) {
80
+ case 0: case 1: t = op; break;
81
+ case 4: _.label++; return { value: op[1], done: false };
82
+ case 5: _.label++; y = op[1]; op = [0]; continue;
83
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
84
+ default:
85
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
86
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
87
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
88
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
89
+ if (t[2]) _.ops.pop();
90
+ _.trys.pop(); continue;
91
+ }
92
+ op = body.call(thisArg, _);
93
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
94
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
95
+ }
96
+ };
97
+ var __importDefault = (this && this.__importDefault) || function (mod) {
98
+ return (mod && mod.__esModule) ? mod : { "default": mod };
99
+ };
100
+ Object.defineProperty(exports, "__esModule", { value: true });
101
+ exports.Select1 = void 0;
102
+ var select1_module_css_1 = __importDefault(require("./select1.module.css"));
103
+ var react_1 = __importStar(require("react"));
104
+ var react_dom_1 = __importDefault(require("react-dom"));
105
+ var winicon_1 = require("../wini-icon/winicon");
106
+ var text_1 = require("../text/text");
107
+ var react_i18next_1 = require("react-i18next");
108
+ ;
109
+ var TSelect1 = /** @class */ (function (_super) {
110
+ __extends(TSelect1, _super);
111
+ function TSelect1(props) {
112
+ var _a, _b;
113
+ var _this = _super.call(this, props) || this;
114
+ _this.containerRef = (0, react_1.createRef)();
115
+ _this.inputRef = (0, react_1.createRef)();
116
+ _this.onKeyDown = function (ev) {
117
+ var _a, _b, _c, _d, _e, _f, _g;
118
+ if ((((_a = _this.state.options) === null || _a === void 0 ? void 0 : _a.length) || ((_b = _this.state.search) === null || _b === void 0 ? void 0 : _b.length)) && _this.state.isOpen) {
119
+ switch (ev.key.toLowerCase()) {
120
+ case "enter":
121
+ ev.preventDefault();
122
+ var _selectItem = ((_c = _this.state.search) !== null && _c !== void 0 ? _c : _this.state.options).find(function (e) { return e.id === _this.state.selected; });
123
+ if (_selectItem)
124
+ _this.onSelect(_selectItem);
125
+ break;
126
+ case "arrowup":
127
+ ev.preventDefault();
128
+ if (_this.state.selected) {
129
+ var _index = ((_d = _this.state.search) !== null && _d !== void 0 ? _d : _this.state.options).findIndex(function (e) { return e.id === _this.state.selected; });
130
+ _index = ((_index === 0) ? _this.props.options.length : _index) - 1;
131
+ _this.setState(__assign(__assign({}, _this.state), { selected: (_e = _this.props.options[_index]) === null || _e === void 0 ? void 0 : _e.id }));
132
+ }
133
+ break;
134
+ case "arrowdown":
135
+ ev.preventDefault();
136
+ if (_this.state.selected) {
137
+ var _index = ((_f = _this.state.search) !== null && _f !== void 0 ? _f : _this.state.options).findIndex(function (e) { return e.id === _this.state.selected; });
138
+ _index = ((_index + 1 === _this.props.options.length) ? -1 : _index) + 1;
139
+ _this.setState(__assign(__assign({}, _this.state), { selected: (_g = _this.props.options[_index]) === null || _g === void 0 ? void 0 : _g.id }));
140
+ }
141
+ break;
142
+ default:
143
+ break;
144
+ }
145
+ }
146
+ };
147
+ _this.state = {
148
+ value: props.value,
149
+ options: props.options,
150
+ offset: {
151
+ x: 0,
152
+ y: 0,
153
+ height: 0,
154
+ width: 0,
155
+ bottom: 0,
156
+ left: 0,
157
+ right: 0,
158
+ top: 0,
159
+ toJSON: function () {
160
+ throw new Error('Function not implemented.');
161
+ }
162
+ },
163
+ isOpen: false,
164
+ onSelect: null,
165
+ };
166
+ _this.search = _this.search.bind(_this);
167
+ _this.onSelect = _this.onSelect.bind(_this);
168
+ _this.onKeyDown = _this.onKeyDown.bind(_this);
169
+ if (_this.inputRef.current)
170
+ _this.inputRef.current.value = "".concat((_b = (_a = _this.state.options.find(function (e) { return e.id === _this.state.value; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "");
171
+ return _this;
172
+ }
173
+ TSelect1.prototype.search = function (ev) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var res;
176
+ var _a;
177
+ return __generator(this, function (_b) {
178
+ switch (_b.label) {
179
+ case 0:
180
+ if (!ev.target.value.trim().length) return [3 /*break*/, 4];
181
+ if (!((_a = this.props) === null || _a === void 0 ? void 0 : _a.handleSearch)) return [3 /*break*/, 2];
182
+ return [4 /*yield*/, this.props.handleSearch(ev.target.value.trim())];
183
+ case 1:
184
+ res = _b.sent();
185
+ this.setState(__assign(__assign({}, this.state), { search: res }));
186
+ return [3 /*break*/, 3];
187
+ case 2:
188
+ this.setState(__assign(__assign({}, this.state), { search: this.props.options.filter(function (e) { return typeof e.name === "string" && e.name.toLowerCase().includes(ev.target.value.trim().toLowerCase()); }) }));
189
+ _b.label = 3;
190
+ case 3: return [3 /*break*/, 5];
191
+ case 4:
192
+ this.setState(__assign(__assign({}, this.state), { search: undefined }));
193
+ _b.label = 5;
194
+ case 5: return [2 /*return*/];
195
+ }
196
+ });
197
+ });
198
+ };
199
+ TSelect1.prototype.onSelect = function (item) {
200
+ var _a, _b;
201
+ if (item.disabled) {
202
+ this.setState(__assign(__assign({}, this.state), { isOpen: false, onSelect: undefined, selected: undefined }));
203
+ (_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
204
+ }
205
+ else {
206
+ var newState = __assign(__assign({}, this.state), { isOpen: false, value: item.id, onSelect: undefined, selected: undefined });
207
+ if (!newState.options.some(function (e) { return e.id === item.id; }))
208
+ newState.options.push(item);
209
+ this.setState(newState);
210
+ (_b = this.inputRef.current) === null || _b === void 0 ? void 0 : _b.blur();
211
+ }
212
+ if (this.props.onChange)
213
+ this.props.onChange(item);
214
+ };
215
+ TSelect1.prototype.componentDidUpdate = function (prevProps, prevState) {
216
+ var _this = this;
217
+ var _a, _b, _c, _d, _e, _f, _g, _h;
218
+ if (prevProps.options !== this.props.options) {
219
+ this.setState(__assign(__assign({}, this.state), { options: this.props.options }));
220
+ if (this.inputRef.current)
221
+ this.inputRef.current.value = "".concat((_b = (_a = this.props.options.find(function (e) { return e.id === _this.state.value; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "");
222
+ }
223
+ if (prevProps.value !== this.props.value)
224
+ this.setState(__assign(__assign({}, this.state), { value: this.props.value }));
225
+ if (prevState.value !== this.state.value && this.inputRef.current)
226
+ this.inputRef.current.value = "".concat((_d = (_c = this.state.options.find(function (e) { return e.id === _this.state.value; })) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : "");
227
+ //
228
+ if (this.state.isOpen && prevState.isOpen !== this.state.isOpen) {
229
+ var thisPopupRect = (_e = document.body.querySelector(":scope > .select1-popup")) === null || _e === void 0 ? void 0 : _e.getBoundingClientRect();
230
+ if (thisPopupRect) {
231
+ var style = void 0;
232
+ if (thisPopupRect.right > document.body.offsetWidth) {
233
+ style = {
234
+ top: this.state.offset.y + this.state.offset.height + 2 + 'px',
235
+ right: document.body.offsetWidth - this.state.offset.right + 'px'
236
+ };
237
+ }
238
+ var _bottom = thisPopupRect.bottom - 8;
239
+ var thisContainerRect = (_f = this.containerRef.current) === null || _f === void 0 ? void 0 : _f.getBoundingClientRect();
240
+ if (thisContainerRect) {
241
+ if (_bottom > document.body.offsetHeight) {
242
+ style = __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { top: "".concat(thisContainerRect.y - 2 - thisPopupRect.height, "px") });
243
+ }
244
+ }
245
+ if (style) {
246
+ (_g = style.left) !== null && _g !== void 0 ? _g : (style.left = style.right ? undefined : "".concat(this.state.offset.x, "px"));
247
+ (_h = style.width) !== null && _h !== void 0 ? _h : (style.width = "".concat(this.state.offset.width, "px"));
248
+ this.setState(__assign(__assign({}, this.state), { style: style }));
249
+ }
250
+ }
251
+ }
252
+ };
253
+ TSelect1.prototype.componentDidMount = function () {
254
+ var _this = this;
255
+ var _a, _b;
256
+ if (this.inputRef.current)
257
+ this.inputRef.current.value = "".concat((_b = (_a = this.state.options.find(function (e) { return e.id === _this.state.value; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "");
258
+ };
259
+ TSelect1.prototype.render = function () {
260
+ var _this = this;
261
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
262
+ var t = this.props.t;
263
+ var _value = this.state.options.find(function (e) { return e.id === _this.state.value; });
264
+ return react_1.default.createElement("div", { id: this.props.id, ref: this.containerRef, className: "".concat(select1_module_css_1.default['select1-container'], " row ").concat(this.props.disabled ? select1_module_css_1.default['disabled'] : '', " ").concat(((_a = this.props.helperText) === null || _a === void 0 ? void 0 : _a.length) && select1_module_css_1.default['helper-text'], " ").concat((_b = this.props.className) !== null && _b !== void 0 ? _b : 'body-3'), "helper-text": this.props.helperText, style: this.props.style ? __assign(__assign({}, { '--helper-text-color': (_c = this.props.helperTextColor) !== null && _c !== void 0 ? _c : '#e14337' }), this.props.style) : { '--helper-text-color': (_d = this.props.helperTextColor) !== null && _d !== void 0 ? _d : '#e14337' }, onClick: function () {
265
+ var _a, _b, _c;
266
+ if (!_this.state.isOpen) {
267
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: true, style: undefined, offset: (_b = (_a = _this.containerRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect() }));
268
+ (_c = _this.inputRef.current) === null || _c === void 0 ? void 0 : _c.focus();
269
+ }
270
+ } },
271
+ this.props.prefix,
272
+ (!_value || typeof _value.name === "string" || typeof _value.name === "number") ? react_1.default.createElement("input", { ref: this.inputRef, readOnly: this.props.readOnly, onChange: this.search, placeholder: this.props.placeholder, onKeyDown: this.onKeyDown, onBlur: function (ev) {
273
+ if (_this.state.onSelect && !_this.props.readOnly)
274
+ ev.target.focus();
275
+ else if (!_this.state.onSelect)
276
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, onSelect: null }));
277
+ } }) : _value.name, (_e = this.props.suffix) !== null && _e !== void 0 ? _e : react_1.default.createElement("div", { ref: function (iconRef) {
278
+ if ((iconRef === null || iconRef === void 0 ? void 0 : iconRef.parentElement) && iconRef.parentElement.getBoundingClientRect().width < 88)
279
+ iconRef.style.display = "none";
280
+ }, className: 'row' },
281
+ react_1.default.createElement(winicon_1.Winicon, { src: this.state.isOpen ? "fill/arrows/up-arrow" : "fill/arrows/down-arrow", size: "1.2rem" })),
282
+ this.state.isOpen &&
283
+ react_dom_1.default.createPortal(react_1.default.createElement("div", { ref: function (popupRef) {
284
+ if (popupRef && _this.props.onOpenOptions)
285
+ _this.props.onOpenOptions(popupRef);
286
+ }, className: "".concat(select1_module_css_1.default['select1-popup'], " select1-popup col ").concat((_f = this.props.popupClassName) !== null && _f !== void 0 ? _f : ""), style: (_g = this.state.style) !== null && _g !== void 0 ? _g : {
287
+ top: this.state.offset.y + this.state.offset.height + 2 + 'px',
288
+ left: this.state.offset.x + 'px',
289
+ width: this.state.offset.width,
290
+ }, onMouseOver: function (ev) { return _this.setState(__assign(__assign({}, _this.state), { onSelect: ev.target })); }, onMouseOut: function () { return _this.setState(__assign(__assign({}, _this.state), { onSelect: null })); } },
291
+ react_1.default.createElement("div", { className: "col ".concat(select1_module_css_1.default['select-body']), onScroll: this.props.handleLoadmore ? function (ev) {
292
+ if (_this.props.handleLoadmore) {
293
+ var scrollElement = ev.target;
294
+ _this.props.handleLoadmore(Math.round(scrollElement.offsetHeight + scrollElement.scrollTop) >= (scrollElement.scrollHeight - 1), ev);
295
+ }
296
+ } : undefined },
297
+ ((_h = this.state.search) !== null && _h !== void 0 ? _h : this.state.options).filter(function (e) { return !e.parentId; }).map(function (item) {
298
+ var _a, _b;
299
+ return react_1.default.createElement(OptionsItemTile, { key: item.id, item: item, children: ((_a = _this.state.search) !== null && _a !== void 0 ? _a : _this.state.options).filter(function (e) { return e.parentId === item.id; }), selected: _this.state.selected === item.id, onClick: _this.onSelect, treeData: ((_b = _this.state.search) !== null && _b !== void 0 ? _b : _this.state.options).some(function (e) { return e.parentId; }) });
300
+ }),
301
+ (((_j = this.state.search) === null || _j === void 0 ? void 0 : _j.length) === 0 || ((_k = this.props.options) === null || _k === void 0 ? void 0 : _k.length) === 0) && (react_1.default.createElement("div", { className: select1_module_css_1.default['no-results-found'] }, t("noResultFound"))))), document.body));
302
+ };
303
+ return TSelect1;
304
+ }(react_1.default.Component));
305
+ function OptionsItemTile(_a) {
306
+ var item = _a.item, children = _a.children, selected = _a.selected, onClick = _a.onClick, treeData = _a.treeData;
307
+ var _b = (0, react_1.useState)(false), isOpen = _b[0], setIsOpen = _b[1];
308
+ return item.title && typeof item.title !== "string" ? react_1.default.createElement(react_1.default.Fragment, null, item.title(onClick)) : react_1.default.createElement("div", { className: 'col', style: { width: '100%' } },
309
+ react_1.default.createElement("div", { className: "".concat(select1_module_css_1.default['select-tile'], " row ").concat(item.disabled ? select1_module_css_1.default["disabled"] : ""), style: { paddingLeft: item.parentId ? '4.4rem' : undefined, backgroundColor: selected ? "var(--neutral-selected-background-color)" : undefined }, onClick: function () {
310
+ if (children === null || children === void 0 ? void 0 : children.length) {
311
+ setIsOpen(!isOpen);
312
+ }
313
+ else
314
+ onClick(item);
315
+ } },
316
+ treeData ? react_1.default.createElement("div", { className: 'row', style: { width: '1.4rem', height: '1.4rem' } }, (children === null || children === void 0 ? void 0 : children.length) ? react_1.default.createElement(winicon_1.Winicon, { src: isOpen ? "fill/arrows/triangle-down" : "fill/arrows/triangle-right", size: "1.2rem" }) : null) : undefined,
317
+ react_1.default.createElement(text_1.Text, { className: 'body-3' }, item.title && typeof item.title === "string" ? item.title : item.name)),
318
+ (children === null || children === void 0 ? void 0 : children.length) ? react_1.default.createElement("div", { className: 'col', style: { display: isOpen ? "flex" : "none", width: '100%' } }, children.map(function (e) { return react_1.default.createElement(OptionsItemTile, { key: e.id, item: e, onClick: onClick }); })) : undefined);
319
+ }
320
+ exports.Select1 = (0, react_i18next_1.withTranslation)()(TSelect1);