@sheinx/base 3.8.0-beta.5 → 3.8.0-beta.8

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 (65) hide show
  1. package/cjs/cascader/cascader.d.ts.map +1 -1
  2. package/cjs/cascader/cascader.js +27 -2
  3. package/cjs/cascader/cascader.type.d.ts +7 -0
  4. package/cjs/cascader/cascader.type.d.ts.map +1 -1
  5. package/cjs/cascader/node.js +1 -1
  6. package/cjs/common/use-tip.js +1 -1
  7. package/cjs/date-picker/date-picker.d.ts.map +1 -1
  8. package/cjs/date-picker/date-picker.js +6 -2
  9. package/cjs/date-picker/date-picker.type.d.ts +2 -2
  10. package/cjs/date-picker/date-picker.type.d.ts.map +1 -1
  11. package/cjs/date-picker/day.d.ts.map +1 -1
  12. package/cjs/date-picker/day.js +3 -1
  13. package/cjs/date-picker/picker.d.ts.map +1 -1
  14. package/cjs/date-picker/picker.js +1 -0
  15. package/cjs/date-picker/picker.type.d.ts +2 -1
  16. package/cjs/date-picker/picker.type.d.ts.map +1 -1
  17. package/cjs/date-picker/result.d.ts +4 -4
  18. package/cjs/date-picker/result.d.ts.map +1 -1
  19. package/cjs/date-picker/result.js +1 -1
  20. package/cjs/input/input-password.d.ts.map +1 -1
  21. package/cjs/input/input-password.js +2 -1
  22. package/cjs/input/input.d.ts.map +1 -1
  23. package/cjs/input/input.js +1 -0
  24. package/cjs/input/input.type.d.ts +11 -5
  25. package/cjs/input/input.type.d.ts.map +1 -1
  26. package/cjs/input/simple-input.d.ts.map +1 -1
  27. package/cjs/input/simple-input.js +31 -5
  28. package/cjs/input/use-input-common.d.ts.map +1 -1
  29. package/cjs/input/use-input-common.js +42 -19
  30. package/cjs/textarea/textarea.d.ts.map +1 -1
  31. package/cjs/textarea/textarea.js +2 -1
  32. package/cjs/transfer/transfer-list.js +1 -1
  33. package/esm/cascader/cascader.d.ts.map +1 -1
  34. package/esm/cascader/cascader.js +27 -2
  35. package/esm/cascader/cascader.type.d.ts +7 -0
  36. package/esm/cascader/cascader.type.d.ts.map +1 -1
  37. package/esm/cascader/node.js +1 -1
  38. package/esm/common/use-tip.js +1 -1
  39. package/esm/date-picker/date-picker.d.ts.map +1 -1
  40. package/esm/date-picker/date-picker.js +6 -2
  41. package/esm/date-picker/date-picker.type.d.ts +2 -2
  42. package/esm/date-picker/date-picker.type.d.ts.map +1 -1
  43. package/esm/date-picker/day.d.ts.map +1 -1
  44. package/esm/date-picker/day.js +3 -1
  45. package/esm/date-picker/picker.d.ts.map +1 -1
  46. package/esm/date-picker/picker.js +1 -0
  47. package/esm/date-picker/picker.type.d.ts +2 -1
  48. package/esm/date-picker/picker.type.d.ts.map +1 -1
  49. package/esm/date-picker/result.d.ts +4 -4
  50. package/esm/date-picker/result.d.ts.map +1 -1
  51. package/esm/date-picker/result.js +1 -1
  52. package/esm/input/input-password.d.ts.map +1 -1
  53. package/esm/input/input-password.js +2 -1
  54. package/esm/input/input.d.ts.map +1 -1
  55. package/esm/input/input.js +1 -0
  56. package/esm/input/input.type.d.ts +11 -5
  57. package/esm/input/input.type.d.ts.map +1 -1
  58. package/esm/input/simple-input.d.ts.map +1 -1
  59. package/esm/input/simple-input.js +32 -6
  60. package/esm/input/use-input-common.d.ts.map +1 -1
  61. package/esm/input/use-input-common.js +42 -19
  62. package/esm/textarea/textarea.d.ts.map +1 -1
  63. package/esm/textarea/textarea.js +2 -1
  64. package/esm/transfer/transfer-list.js +1 -1
  65. package/package.json +2 -2
@@ -9,14 +9,14 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
9
9
  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; }
10
10
  import { useInput, useKeyEvent, usePersistFn, util } from '@sheinx/hooks';
11
11
  import classNames from 'classnames';
12
- import React, { useContext } from 'react';
12
+ import React, { useContext, useRef } from 'react';
13
13
  import Icons from "../icons";
14
14
  import { useConfig } from "../config";
15
15
  import { FormFieldContext } from "../form/form-field-context";
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
18
  var Input = function Input(props) {
19
- var _jssStyle$input;
19
+ var _jssStyle$input, _inputElProps$value;
20
20
  var jssStyle = props.jssStyle,
21
21
  className = props.className,
22
22
  style = props.style,
@@ -34,20 +34,41 @@ var Input = function Input(props) {
34
34
  addEnd = props.addEnd,
35
35
  hasSuffix = props.hasSuffix,
36
36
  rest = _objectWithoutProperties(props, _excluded);
37
+ var _useRef = useRef({
38
+ needTriggerEnter: false
39
+ }),
40
+ context = _useRef.current;
37
41
  var inputStyle = jssStyle === null || jssStyle === void 0 || (_jssStyle$input = jssStyle.input) === null || _jssStyle$input === void 0 ? void 0 : _jssStyle$input.call(jssStyle);
38
42
  var config = useConfig();
39
43
  var _useContext = useContext(FormFieldContext),
40
44
  fieldId = _useContext.fieldId;
45
+ var showClearFromProp = props.showClear && !props.disabled;
41
46
  var _useInput = useInput(_objectSpread(_objectSpread({}, rest), {}, {
42
- onFocusedChange: onFocusedChange
47
+ onFocusedChange: onFocusedChange,
48
+ // 由于form的原生submit事件是在keydown中触发的,submit校验后触发scrollToError会导致当前焦点的input立即失焦,导致input的回车事件无法触发
49
+ // 所以这里在onKeyDown时机记录下needTriggerEnter标志,在onBlur时机判断是否需要触发onEnterPress
50
+ onKeyDown: function onKeyDown(e) {
51
+ var _props$onKeyDown;
52
+ if (e.key === 'Enter') {
53
+ context.needTriggerEnter = true;
54
+ }
55
+ (_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 || _props$onKeyDown.call(props, e);
56
+ },
57
+ onBlur: function onBlur(e) {
58
+ var _props$onBlur;
59
+ if (context.needTriggerEnter) {
60
+ context.needTriggerEnter = false;
61
+ _onEnterPress === null || _onEnterPress === void 0 || _onEnterPress(e.target.value || '', e);
62
+ }
63
+ (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, e);
64
+ }
43
65
  })),
44
66
  getRootProps = _useInput.getRootProps,
45
67
  getClearProps = _useInput.getClearProps,
46
68
  getInputProps = _useInput.getInputProps,
47
- showClear = _useInput.showClear,
69
+ showClearFromClearable = _useInput.showClear,
48
70
  focused = _useInput.focused,
49
71
  disabled = _useInput.disabled;
50
- var rootClass = classNames(className, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.rootClass, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapper, !!focused && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperFocus), !!disabled && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperDisabled), status === 'error' && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperError), size === 'small' && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperSmall), size === 'large' && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperLarge), !!underline && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperUnderline), !border && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperNoBorder), hasSuffix && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.password));
51
72
  var keyHandler = useKeyEvent({
52
73
  onEnterPress: function onEnterPress(e) {
53
74
  _onEnterPress === null || _onEnterPress === void 0 || _onEnterPress(e.target.value || '', e);
@@ -55,6 +76,10 @@ var Input = function Input(props) {
55
76
  });
56
77
  var onKeyUp = usePersistFn(function (e) {
57
78
  var _props$onKeyUp;
79
+ if (e.key === 'Enter') {
80
+ context.needTriggerEnter = false;
81
+ }
82
+ ;
58
83
  (_props$onKeyUp = props.onKeyUp) === null || _props$onKeyUp === void 0 || _props$onKeyUp.call(props, e);
59
84
  keyHandler(e);
60
85
  });
@@ -71,6 +96,7 @@ var Input = function Input(props) {
71
96
  if (typeof renderInput === 'function') {
72
97
  inputEl = renderInput(inputEl);
73
98
  }
99
+ var rootClass = classNames(className, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.rootClass, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapper, !!focused && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperFocus), !!disabled && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperDisabled), status === 'error' && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperError), size === 'small' && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperSmall), size === 'large' && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperLarge), !!underline && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperUnderline), !border && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperNoBorder), hasSuffix && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.password), showClearFromProp && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperShowClear), showClearFromProp && ((_inputElProps$value = inputElProps.value) === null || _inputElProps$value === void 0 ? void 0 : _inputElProps$value.length) > 0 && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperHasValue));
74
100
  return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread(_objectSpread({
75
101
  id: fieldId
76
102
  }, util.getDataAttribute(_defineProperty({}, 'input-border', 'true'))), getRootProps({
@@ -79,7 +105,7 @@ var Input = function Input(props) {
79
105
  })), {}, {
80
106
  children: [/*#__PURE__*/_jsxs("div", {
81
107
  className: classNames(inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperInnerTitleTop, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperInnerTitleBottom, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperPaddingBox, inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.content),
82
- children: [prefix, inputEl, showClear && /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
108
+ children: [prefix, inputEl, (showClearFromProp || showClearFromClearable) && /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
83
109
  className: inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.clearWrapper
84
110
  }, getClearProps()), {}, {
85
111
  children: /*#__PURE__*/_jsx("span", {
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-common.d.ts","sourceRoot":"","sources":["use-input-common.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAOvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAWhD,QAAA,MAAM,cAAc;;;;;;;;;;gCA6G8B,OAAO;;;;;;;gBAQnB,gBAAgB,CAAC,gBAAgB,CAAC;CAsBvE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"use-input-common.d.ts","sourceRoot":"","sources":["use-input-common.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAOvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAWhD,QAAA,MAAM,cAAc;;;;;;;;;;gCAkI8B,OAAO;;;;;;;gBAQnB,gBAAgB,CAAC,gBAAgB,CAAC;CAsBvE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,5 +1,5 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
1
  var _excluded = ["forwardRef", "forwardedRef", "htmlName", "value", "onChange", "defaultValue", "beforeChange", "clearable", "clearToUndefined", "style", "suffix", "info", "innerTitle", "placeTitle", "width", "delay", "onBlur", "tip", "error", "popover", "popoverProps", "status", "disabled", "size"];
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  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; }
@@ -30,7 +30,7 @@ var defaultInfo = function defaultInfo(num, msg) {
30
30
  return new Error(text);
31
31
  };
32
32
  var useInputCommon = function useInputCommon(props0) {
33
- var _ref, _props$jssStyle, _props$jssStyle$input;
33
+ var _ref, _props$jssStyle, _props$jssStyle$input, _infoState$error;
34
34
  var config = useConfig();
35
35
  var props = useWithFormConfig(props0);
36
36
  var forwardRef = props.forwardRef,
@@ -59,7 +59,7 @@ var useInputCommon = function useInputCommon(props0) {
59
59
  size = props.size,
60
60
  rest = _objectWithoutProperties(props, _excluded);
61
61
  var delay = (_ref = delayProps !== null && delayProps !== void 0 ? delayProps : config.delay) !== null && _ref !== void 0 ? _ref : 0;
62
- var inputStyle = (_props$jssStyle = props.jssStyle) === null || _props$jssStyle === void 0 || (_props$jssStyle$input = _props$jssStyle.input) === null || _props$jssStyle$input === void 0 ? void 0 : _props$jssStyle$input.call(_props$jssStyle);
62
+ var inputClasses = (_props$jssStyle = props.jssStyle) === null || _props$jssStyle === void 0 || (_props$jssStyle$input = _props$jssStyle.input) === null || _props$jssStyle$input === void 0 ? void 0 : _props$jssStyle$input.call(_props$jssStyle);
63
63
  var rootRef = React.useRef(null);
64
64
  var _React$useState = React.useState(false),
65
65
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -101,27 +101,50 @@ var useInputCommon = function useInputCommon(props0) {
101
101
  value: inputAbleProps.value,
102
102
  onChange: inputAbleProps.onChange
103
103
  });
104
- var getInfo = function getInfo() {
104
+ var getInfoState = function getInfoState() {
105
105
  var notNumber = typeof info !== 'number';
106
- if (typeof info !== 'function' && notNumber) return null;
107
- var textInfo = notNumber ? info : defaultInfo.bind(null, info);
108
- var res = textInfo(inputAbleProps.value);
109
- // empty
110
- if (!res) return null;
111
- var isError = res instanceof Error;
112
- var text = isError ? res.message : res;
106
+ if (typeof info !== 'function' && _typeof(info) !== 'object' && notNumber) return null;
107
+ var infoContent;
108
+ if (_typeof(info) === 'object') {
109
+ infoContent = info.content;
110
+ } else {
111
+ infoContent = info;
112
+ }
113
+ var notContentNumber = typeof infoContent !== 'number';
114
+ var textInfo = notContentNumber ? infoContent : defaultInfo.bind(null, infoContent);
115
+ var error = textInfo(inputAbleProps.value);
116
+ if (!error) return null;
117
+ var isError = error instanceof Error;
118
+ var text = isError ? error.message : error;
113
119
  if (!isError && !focused) return null;
114
- return /*#__PURE__*/_jsx("div", {
120
+ return {
121
+ text: text,
122
+ error: error
123
+ };
124
+ };
125
+ var infoState = useMemo(getInfoState, [info, inputAbleProps.value, focused]);
126
+ var infoPopoverProps = {
127
+ popover: props.popover || (_typeof(info) === 'object' ? info.position : 'bottom-right'),
128
+ popoverProps: Object.assign({
115
129
  style: {
116
- minWidth: 'auto'
130
+ width: 'auto',
131
+ fontSize: 12
117
132
  },
118
- className: classNames(inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.info, !!isError && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.infoError)),
119
- dir: config.direction,
120
- children: text
121
- }, 'info');
133
+ adjust: true
134
+ }, props.popoverProps),
135
+ error: infoState !== null && infoState !== void 0 && infoState.error && (infoState === null || infoState === void 0 ? void 0 : infoState.error) instanceof Error ? infoState === null || infoState === void 0 || (_infoState$error = infoState.error) === null || _infoState$error === void 0 ? void 0 : _infoState$error.message : undefined,
136
+ tip: /*#__PURE__*/_jsx("div", {
137
+ className: inputClasses === null || inputClasses === void 0 ? void 0 : inputClasses.info,
138
+ children: infoState === null || infoState === void 0 ? void 0 : infoState.text
139
+ })
122
140
  };
141
+ var infoPopoverNode = useTip(_objectSpread(_objectSpread({}, infoPopoverProps), {}, {
142
+ focused: focused,
143
+ rootRef: rootRef,
144
+ jssStyle: props.jssStyle
145
+ }));
123
146
  var mergeSuffix = /*#__PURE__*/_jsxs(React.Fragment, {
124
- children: [suffix, getInfo(), tipNode]
147
+ children: [suffix, (infoState === null || infoState === void 0 ? void 0 : infoState.text) && infoPopoverNode, tipNode]
125
148
  });
126
149
  var onFocusedChange = usePersistFn(function (focused) {
127
150
  setFocused(!!focused);
@@ -137,7 +160,7 @@ var useInputCommon = function useInputCommon(props0) {
137
160
  });
138
161
  return _objectSpread(_objectSpread(_objectSpread({}, rest), {}, {
139
162
  value: inputAbleProps.value,
140
- className: classNames(props.className, innerTitle && (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.wrapperInnerTitle)),
163
+ className: classNames(props.className, innerTitle && (inputClasses === null || inputClasses === void 0 ? void 0 : inputClasses.wrapperInnerTitle)),
141
164
  onChange: inputAbleProps.onChange,
142
165
  onBlur: handleBlur
143
166
  }, clearProps), {}, {
@@ -1 +1 @@
1
- {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0B,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;;AA6NhD,wBAAoC"}
1
+ {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0B,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;;AA8NhD,wBAAoC"}
@@ -156,7 +156,8 @@ var Textarea = function Textarea(props0) {
156
156
  style: {
157
157
  width: 'auto',
158
158
  fontSize: 12
159
- }
159
+ },
160
+ adjust: true
160
161
  }, resetProps.popoverProps),
161
162
  error: infoState !== null && infoState !== void 0 && infoState.error && (infoState === null || infoState === void 0 ? void 0 : infoState.error) instanceof Error ? infoState === null || infoState === void 0 || (_infoState$error = infoState.error) === null || _infoState$error === void 0 ? void 0 : _infoState$error.message : undefined,
162
163
  tip: /*#__PURE__*/_jsx("div", {
@@ -147,7 +147,7 @@ var TransferList = function TransferList(props) {
147
147
  className: styles.inputWrapper,
148
148
  children: /*#__PURE__*/_jsx(Input, {
149
149
  className: styles.input,
150
- clearable: true,
150
+ showClear: true,
151
151
  jssStyle: jssStyle,
152
152
  value: filterText,
153
153
  suffix: Icons.transfer.Search,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/base",
3
- "version": "3.8.0-beta.5",
3
+ "version": "3.8.0-beta.8",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "module": "./esm/index.js",
11
11
  "typings": "./cjs/index.d.ts",
12
12
  "dependencies": {
13
- "@sheinx/hooks": "3.8.0-beta.5",
13
+ "@sheinx/hooks": "3.8.0-beta.8",
14
14
  "immer": "^10.0.0",
15
15
  "classnames": "^2.0.0",
16
16
  "@shined/reactive": "^0.1.3-alpha.0"