@pisell/materials 1.0.387 → 1.0.388

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.
@@ -1,4 +1,8 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  var _excluded = ["picker", "onChange", "value", "format", "defaultValue", "showTime"];
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2
6
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
8
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -10,7 +14,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
10
14
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
15
  import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
12
16
  import dayjs from 'dayjs';
13
- import classNames from "classnames";
17
+ import classNames from 'classnames';
14
18
  import { Button, ConfigProvider, DatePicker, Drawer, Input, Modal } from 'antd';
15
19
  import BrowserSelect from "../browserSelect";
16
20
  import { isFunction } from '@pisell/utils';
@@ -62,7 +66,12 @@ var DatePickerCpt = function DatePickerCpt(props) {
62
66
  error = _useState12[0],
63
67
  setError = _useState12[1];
64
68
  var ref = useRef(null);
69
+ var panelRef = useRef(null);
65
70
  var canClose = useRef(true);
71
+ var _useState13 = useState(0),
72
+ _useState14 = _slicedToArray(_useState13, 2),
73
+ panelTimeWidth = _useState14[0],
74
+ setPanelTimeWidth = _useState14[1];
66
75
 
67
76
  // const isDesktop = useMediaQuery('@media (pointer: fine)');
68
77
 
@@ -75,7 +84,7 @@ var DatePickerCpt = function DatePickerCpt(props) {
75
84
  setValue(value);
76
85
  }, [value]);
77
86
  useEffect(function () {
78
- setValueStr((_value === null || _value === void 0 ? void 0 : _value.format(format)) || '');
87
+ setValueStr((_value === null || _value === void 0 ? void 0 : _value.format(format || 'YYYY-MM-DD')) || '');
79
88
  }, [_value]);
80
89
  var customPresetItems = useMemo(function () {
81
90
  var preset = [{
@@ -126,6 +135,7 @@ var DatePickerCpt = function DatePickerCpt(props) {
126
135
  }, [propsFormat, locale]);
127
136
  var handleSelectChange = function handleSelectChange(e) {
128
137
  var _presetDetailMap;
138
+ canClose.current = true;
129
139
  var shortcut = e.target.value;
130
140
  setCurrentShortcut(shortcut);
131
141
  var date = (_presetDetailMap = presetDetailMap[shortcut]) === null || _presetDetailMap === void 0 ? void 0 : _presetDetailMap.getValue();
@@ -135,6 +145,7 @@ var DatePickerCpt = function DatePickerCpt(props) {
135
145
  var handleTodayClick = function handleTodayClick() {
136
146
  var val = dayjs().startOf('day');
137
147
  handleChange(val);
148
+ handleOpenChange(false);
138
149
  };
139
150
  var handleOpenChange = function handleOpenChange(visible) {
140
151
  if (!visible) {
@@ -151,15 +162,19 @@ var DatePickerCpt = function DatePickerCpt(props) {
151
162
  };
152
163
  var handleOk = function handleOk(val) {
153
164
  var returnValue = val || _value;
154
- onChange === null || onChange === void 0 ? void 0 : onChange(returnValue, returnValue === null || returnValue === void 0 ? void 0 : returnValue.format(format));
165
+ onChange === null || onChange === void 0 ? void 0 : onChange(returnValue, returnValue === null || returnValue === void 0 ? void 0 : returnValue.format('YYYY-MM-DD'));
155
166
  handleOpenChange(false);
156
167
  };
157
- var handleChange = function handleChange(val, valStr) {
158
- canClose.current = true;
168
+ var handleChange = function handleChange(val, valStr, isNotChange) {
169
+ if (!showTime) {
170
+ canClose.current = true;
171
+ }
159
172
  setError(false);
160
173
  setCurrentShortcut('');
161
174
  setValue(val);
162
- handleOk(val);
175
+ if (!isNotChange) {
176
+ handleOk(val);
177
+ }
163
178
  };
164
179
  var handleApply = function handleApply() {
165
180
  if (error) return;
@@ -176,18 +191,75 @@ var DatePickerCpt = function DatePickerCpt(props) {
176
191
  setError(true);
177
192
  }
178
193
  };
179
- if ((!picker || picker === 'date') && !showTime && /^[^Hhms]*$/.test(format)) {
194
+ useEffect(function () {
195
+ var _panelRef$current;
196
+ var width = 0;
197
+ var childElements = ((_panelRef$current = panelRef.current) === null || _panelRef$current === void 0 ? void 0 : _panelRef$current.getElementsByClassName('pisell-lowcode-picker-time-panel')) || [];
198
+ if (childElements.length > 0) {
199
+ var childElement = childElements[0];
200
+ width = childElement.offsetWidth;
201
+ }
202
+ if (width > 0) {
203
+ setPanelTimeWidth(width);
204
+ }
205
+ }, [open]);
206
+ var handleSelect = function handleSelect(val) {
207
+ canClose.current = !showTime;
208
+ setValue(val);
209
+ };
210
+ var handleTimeChange = function handleTimeChange(val) {
211
+ setValue(function (preVal) {
212
+ var _preVal$set, _preVal$set$set;
213
+ return (preVal === null || preVal === void 0 ? void 0 : (_preVal$set = preVal.set('hour', (val === null || val === void 0 ? void 0 : val.get('hour')) || 0)) === null || _preVal$set === void 0 ? void 0 : (_preVal$set$set = _preVal$set.set('minute', (val === null || val === void 0 ? void 0 : val.get('minute')) || 0)) === null || _preVal$set$set === void 0 ? void 0 : _preVal$set$set.set('second', (val === null || val === void 0 ? void 0 : val.get('second')) || 0)) || null;
214
+ });
215
+ };
216
+ var timeInputProps = useMemo(function () {
217
+ var step = 1;
218
+ var _format = '';
219
+ if ((showTime === null || showTime === void 0 ? void 0 : showTime.format) === 'HH:mm') {
220
+ step = undefined;
221
+ _format = 'HH:mm';
222
+ } else if ((showTime === null || showTime === void 0 ? void 0 : showTime.format) === 'HH:mm:ss' || showTime) {
223
+ step = 1;
224
+ _format = 'HH:mm:ss';
225
+ }
226
+ return {
227
+ step: step,
228
+ onChange: function onChange(e) {
229
+ var val = e.target.value;
230
+ handleTimeChange(window.dayjs(val, _format));
231
+ },
232
+ value: _value === null || _value === void 0 ? void 0 : _value.format(_format)
233
+ };
234
+ }, [showTime, _value]);
235
+ if (!picker || picker === 'date') {
180
236
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DatePicker, _extends({}, others, {
181
- showTime: false,
182
237
  ref: ref,
238
+ onSelect: handleSelect,
239
+ showTime: isDesktop ? showTime : false,
183
240
  defaultValue: defaultValue,
184
241
  showNow: false,
185
- onChange: handleChange,
242
+ onChange: function onChange(val, valStr) {
243
+ return handleChange(val, valStr, !isDesktop && showTime);
244
+ },
186
245
  open: popupOpen,
187
- className: classNames("pisell-lowcode-mode-date-picker", others.className),
246
+ renderExtraFooter: !(!showTime || isDesktop) ? function () {
247
+ return /*#__PURE__*/React.createElement("div", {
248
+ onMouseDown: function onMouseDown(e) {
249
+ canClose.current = false;
250
+ e.stopPropagation();
251
+ }
252
+ }, /*#__PURE__*/React.createElement("div", {
253
+ className: "date-picker-time-label"
254
+ }, "Time"), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("input", _extends({
255
+ type: "time",
256
+ className: "date-picker-input-time"
257
+ }, timeInputProps))));
258
+ } : undefined,
259
+ className: classNames('pisell-lowcode-mode-date-picker', others.className),
188
260
  value: _value,
189
261
  onOpenChange: function onOpenChange(o) {
190
- if (!o && !canClose.current) {
262
+ if (!o && (!canClose.current || showTime)) {
191
263
  return;
192
264
  }
193
265
  handleOpenChange(o);
@@ -200,12 +272,16 @@ var DatePickerCpt = function DatePickerCpt(props) {
200
272
  } : format,
201
273
  panelRender: function panelRender(panelNode) {
202
274
  var dom = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
203
- className: "pisell-lowcode-date-picker-custom-wrap"
204
- }, /*#__PURE__*/React.createElement("div", {
275
+ className: classNames('pisell-lowcode-date-picker-custom-wrap', _defineProperty({}, 'pisell-lowcode-date-picker-custom-wrap-show-time', showTime)),
276
+ ref: panelRef
277
+ }, !showTime && /*#__PURE__*/React.createElement("div", {
205
278
  className: "pisell-lowcode-date-picker-custom-action",
206
279
  onMouseDown: function onMouseDown(e) {
207
280
  canClose.current = false;
208
281
  e.stopPropagation();
282
+ },
283
+ style: {
284
+ width: "calc(100% - 48px - ".concat(panelTimeWidth, "px)")
209
285
  }
210
286
  }, /*#__PURE__*/React.createElement("div", {
211
287
  style: {
@@ -213,7 +289,7 @@ var DatePickerCpt = function DatePickerCpt(props) {
213
289
  }
214
290
  }, /*#__PURE__*/React.createElement(Input, {
215
291
  size: "large",
216
- placeholder: dayjs().format(format),
292
+ placeholder: dayjs().format(format || 'YYYY-MM-DD'),
217
293
  value: valueStr,
218
294
  onChange: handleDataStrChange
219
295
  }), error && /*#__PURE__*/React.createElement("span", {
@@ -252,7 +328,7 @@ var DatePickerCpt = function DatePickerCpt(props) {
252
328
  return /*#__PURE__*/React.createElement(Drawer, {
253
329
  placement: "bottom",
254
330
  open: open,
255
- height: 565,
331
+ height: "auto",
256
332
  closable: false,
257
333
  styles: {
258
334
  content: {