@semcore/inline-input 16.2.2 → 17.0.0-prerelease.17

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,8 +1,3 @@
1
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _callSuper from "@babel/runtime/helpers/callSuper";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
2
  import { sstyled as _sstyled } from "@semcore/core";
8
3
  import { assignProps as _assignProps9 } from "@semcore/core";
@@ -14,254 +9,227 @@ import { assignProps as _assignProps4 } from "@semcore/core";
14
9
  import { assignProps as _assignProps3 } from "@semcore/core";
15
10
  import { assignProps as _assignProps2 } from "@semcore/core";
16
11
  import { assignProps as _assignProps } from "@semcore/core";
12
+ import { Box, InvalidStateBox } from '@semcore/base-components';
17
13
  import { ButtonLink } from '@semcore/button';
18
14
  import { createComponent, Component, sstyled, Root } from '@semcore/core';
19
- import autoFocusEnhance from '@semcore/core/lib/utils/enhances/autoFocusEnhance';
20
15
  import i18nEnhance from '@semcore/core/lib/utils/enhances/i18nEnhance';
21
16
  import { hasParent } from '@semcore/core/lib/utils/hasParent';
22
- import { Box, InvalidStateBox } from '@semcore/flex-box';
23
17
  import CheckM from '@semcore/icon/Check/m';
24
18
  import CloseM from '@semcore/icon/Close/m';
25
19
  import InputNumber from '@semcore/input-number';
26
20
  import Spin from '@semcore/spin';
27
21
  import React from 'react';
28
22
  /*!__reshadow-styles__:"./style/inline-input.shadow.css"*/
29
- var style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SInlineInput_10nzu_gg_{display:inline-flex;width:100%;height:100%;align-items:center;position:relative;z-index:0;vertical-align:middle;padding:1px;box-sizing:border-box;background-color:var(--intergalactic-bg-primary-neutral, #ffffff)}.___SInlineInput_10nzu_gg_ .___SConfirmIcon_10nzu_gg_{color:var(--intergalactic-icon-secondary-success, #00c192);cursor:pointer}@media (hover:hover){.___SInlineInput_10nzu_gg_ .___SConfirmIcon_10nzu_gg_:hover{color:var(--intergalactic-icon-secondary-success-hover-active, #049B75)}}.___SInlineInput_10nzu_gg_ .___SCancelIcon_10nzu_gg_{color:var(--intergalactic-icon-secondary-neutral, #a9abb6);cursor:pointer}@media (hover:hover){.___SInlineInput_10nzu_gg_ .___SCancelIcon_10nzu_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_{min-width:0;width:100%;height:100%;padding:0 var(--intergalactic-spacing-1x, 4px);border:0;box-sizing:border-box;color:var(--intergalactic-text-primary, #191b23);font-size:inherit;line-height:1.2;text-overflow:ellipsis;font-family:inherit;background:0 0;min-height:1em}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_:focus,.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_:focus-visible{outline:0}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_::-moz-placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_::placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_.__disabled_10nzu_gg_{-webkit-user-select:none;-moz-user-select:none;user-select:none}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_::-webkit-inner-spin-button,.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SInlineInput_10nzu_gg_ .___SValue_10nzu_gg_._type_number_10nzu_gg_{-moz-appearance:textfield}.___SUnderline_10nzu_gg_{display:flex;flex-direction:row;align-items:center;flex-grow:1;width:100%;height:100%;min-height:1em;border:1px solid transparent;border-bottom:1px solid var(--intergalactic-border-primary, #c4c7cf)}.___SAddon_10nzu_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:var(--intergalactic-icon-secondary-neutral, #a9abb6);padding:0 var(--intergalactic-spacing-1x, 4px)}.___SAddon_10nzu_gg_.__disabled_10nzu_gg_,.___SInlineInput_10nzu_gg_.__disabled_10nzu_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SUnderline_10nzu_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-info-active, #006dca);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset}.___SInlineInput_10nzu_gg_._state_valid_10nzu_gg_ .___SUnderline_10nzu_gg_{border-bottom-color:var(--intergalactic-border-success-active, #007c65)}.___SInlineInput_10nzu_gg_._state_valid_10nzu_gg_ .___SUnderline_10nzu_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-success-active, #007c65);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-color:var(--intergalactic-keyboard-focus-valid-outline, #009f81)}.___SInlineInput_10nzu_gg_._state_invalid_10nzu_gg_ .___SUnderline_10nzu_gg_{border-bottom-color:var(--intergalactic-border-critical-active, #d1002f)}.___SInlineInput_10nzu_gg_._state_invalid_10nzu_gg_ .___SUnderline_10nzu_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-critical-active, #d1002f);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-color:var(--intergalactic-keyboard-focus-invalid-outline, #ff4953)}.___SValue_10nzu_gg_:focus~.___SControls_10nzu_gg_{display:flex}.___SInvalidPattern_10nzu_gg_{margin-left:-1px;margin-top:-1px;border-radius:0;height:calc(100% - 3px)}", /*__inner_css_end__*/"10nzu_gg_"),
23
+ const style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SInlineInput_mw77c_gg_{display:inline-flex;width:100%;height:100%;align-items:center;position:relative;z-index:0;vertical-align:middle;padding:1px;box-sizing:border-box;background-color:var(--intergalactic-bg-primary-neutral, #ffffff)}.___SInlineInput_mw77c_gg_ .___SConfirmIcon_mw77c_gg_{color:var(--intergalactic-icon-secondary-success, #00c192);cursor:pointer}@media (hover:hover){.___SInlineInput_mw77c_gg_ .___SConfirmIcon_mw77c_gg_:hover{color:var(--intergalactic-icon-secondary-success-hover-active, #049B75)}}.___SInlineInput_mw77c_gg_ .___SCancelIcon_mw77c_gg_{color:var(--intergalactic-icon-secondary-neutral, #a9abb6);cursor:pointer}@media (hover:hover){.___SInlineInput_mw77c_gg_ .___SCancelIcon_mw77c_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_{min-width:0;width:100%;height:100%;padding:0 var(--intergalactic-spacing-1x, 4px);border:0;box-sizing:border-box;color:var(--intergalactic-text-primary, #191b23);font-size:inherit;line-height:1.2;text-overflow:ellipsis;font-family:inherit;background:0 0;min-height:1em}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_:focus,.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_:focus-visible{outline:0}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_::-moz-placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_::placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_.__disabled_mw77c_gg_{-webkit-user-select:none;-moz-user-select:none;user-select:none}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_::-webkit-inner-spin-button,.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SInlineInput_mw77c_gg_ .___SValue_mw77c_gg_._type_number_mw77c_gg_{-moz-appearance:textfield}.___SUnderline_mw77c_gg_{display:flex;flex-direction:row;align-items:center;flex-grow:1;width:100%;height:100%;min-height:1em;border:1px solid transparent;border-bottom:1px solid var(--intergalactic-border-primary, #c4c7cf)}.___SAddon_mw77c_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:var(--intergalactic-icon-secondary-neutral, #a9abb6);padding:0 var(--intergalactic-spacing-1x, 4px)}.___SAddon_mw77c_gg_.__disabled_mw77c_gg_,.___SInlineInput_mw77c_gg_.__disabled_mw77c_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SUnderline_mw77c_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-info-active, #006dca);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset}.___SInlineInput_mw77c_gg_._state_valid_mw77c_gg_ .___SUnderline_mw77c_gg_{border-bottom-color:var(--intergalactic-border-success-active, #007c65)}.___SInlineInput_mw77c_gg_._state_valid_mw77c_gg_ .___SUnderline_mw77c_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-success-active, #007c65);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-color:var(--intergalactic-keyboard-focus-valid-outline, #009f81)}.___SInlineInput_mw77c_gg_._state_invalid_mw77c_gg_ .___SUnderline_mw77c_gg_{border-bottom-color:var(--intergalactic-border-critical-active, #d1002f)}.___SInlineInput_mw77c_gg_._state_invalid_mw77c_gg_ .___SUnderline_mw77c_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-critical-active, #d1002f);outline-color:var(--intergalactic-keyboard-focus-outline, #008ff8);outline-style:solid;outline-width:2px;outline-offset:2px;transition-duration:calc(var(--intergalactic-duration-extra-fast, 100)*1ms);transition-timing-function:ease-in-out;transition-property:outline-color,outline-width,outline-offset;outline-color:var(--intergalactic-keyboard-focus-invalid-outline, #ff4953)}.___SValue_mw77c_gg_:focus~.___SControls_mw77c_gg_{display:flex}.___SInvalidPattern_mw77c_gg_{margin-left:-1px;margin-top:-1px;border-radius:0;height:calc(100% - 3px)}", /*__inner_css_end__*/"mw77c_gg_"),
30
24
  /*__reshadow_css_end__*/
31
25
  {
32
- "__SInlineInput": "___SInlineInput_10nzu_gg_",
33
- "_disabled": "__disabled_10nzu_gg_",
34
- "__SUnderline": "___SUnderline_10nzu_gg_",
35
- "__SAddon": "___SAddon_10nzu_gg_",
36
- "_state_valid": "_state_valid_10nzu_gg_",
37
- "_state_invalid": "_state_invalid_10nzu_gg_",
38
- "__SValue": "___SValue_10nzu_gg_",
39
- "__SControls": "___SControls_10nzu_gg_",
40
- "__SInvalidPattern": "___SInvalidPattern_10nzu_gg_",
41
- "__SConfirmIcon": "___SConfirmIcon_10nzu_gg_",
42
- "__SCancelIcon": "___SCancelIcon_10nzu_gg_",
43
- "_type_number": "_type_number_10nzu_gg_"
26
+ "__SInlineInput": "___SInlineInput_mw77c_gg_",
27
+ "_disabled": "__disabled_mw77c_gg_",
28
+ "__SUnderline": "___SUnderline_mw77c_gg_",
29
+ "__SAddon": "___SAddon_mw77c_gg_",
30
+ "_state_valid": "_state_valid_mw77c_gg_",
31
+ "_state_invalid": "_state_invalid_mw77c_gg_",
32
+ "__SValue": "___SValue_mw77c_gg_",
33
+ "__SControls": "___SControls_mw77c_gg_",
34
+ "__SInvalidPattern": "___SInvalidPattern_mw77c_gg_",
35
+ "__SConfirmIcon": "___SConfirmIcon_mw77c_gg_",
36
+ "__SCancelIcon": "___SCancelIcon_mw77c_gg_",
37
+ "_type_number": "_type_number_mw77c_gg_"
44
38
  });
45
39
  import { localizedMessages } from './translations/__intergalactic-dynamic-locales';
46
- var pointInsideOfRect = function pointInsideOfRect(_ref15) {
47
- var x = _ref15.x,
48
- y = _ref15.y,
49
- rect = _ref15.rect;
40
+ const pointInsideOfRect = ({
41
+ x,
42
+ y,
43
+ rect
44
+ }) => {
50
45
  return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
51
46
  };
52
- var InlineInputBase = /*#__PURE__*/function (_Component) {
53
- function InlineInputBase() {
54
- var _this;
55
- _classCallCheck(this, InlineInputBase);
56
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
57
- args[_key] = arguments[_key];
58
- }
59
- _this = _callSuper(this, InlineInputBase, [].concat(args));
60
- _defineProperty(_this, "rootRef", /*#__PURE__*/React.createRef());
61
- _defineProperty(_this, "inputRef", /*#__PURE__*/React.createRef());
62
- _defineProperty(_this, "inputHandlersRef", /*#__PURE__*/React.createRef());
63
- _defineProperty(_this, "initValue", '');
64
- _defineProperty(_this, "lastMouseDownPosition", null);
65
- _defineProperty(_this, "lastHandledKeyboardEvent", -1);
66
- _defineProperty(_this, "handleDocumentMouseDown", function (event) {
67
- _this.lastMouseDownPosition = {
47
+ class InlineInputBase extends Component {
48
+ constructor(...args) {
49
+ super(...args);
50
+ _defineProperty(this, "rootRef", /*#__PURE__*/React.createRef());
51
+ _defineProperty(this, "inputRef", /*#__PURE__*/React.createRef());
52
+ _defineProperty(this, "initValue", '');
53
+ _defineProperty(this, "lastMouseDownPosition", null);
54
+ _defineProperty(this, "lastHandledKeyboardEvent", -1);
55
+ _defineProperty(this, "handleDocumentMouseDown", event => {
56
+ this.lastMouseDownPosition = {
68
57
  x: event.clientX,
69
58
  y: event.clientY
70
59
  };
71
- _this.lastHandledKeyboardEvent = -1;
60
+ this.lastHandledKeyboardEvent = -1;
72
61
  });
73
- _defineProperty(_this, "handleDocumentKeyDown", function () {
74
- _this.lastMouseDownPosition = null;
62
+ _defineProperty(this, "handleDocumentKeyDown", () => {
63
+ this.lastMouseDownPosition = null;
75
64
  });
76
- _defineProperty(_this, "increment", function (event) {
77
- var _this$inputRef$curren, _this$inputRef$curren2, _this$inputRef$curren3, _this$inputHandlersRe, _this$inputRef$curren4;
65
+ _defineProperty(this, "increment", event => {
78
66
  // https://stackoverflow.com/questions/68010124/safari-number-input-stepup-stepdown-not-functioning-with-empty-value
79
- if (((_this$inputRef$curren = _this.inputRef.current) === null || _this$inputRef$curren === void 0 ? void 0 : _this$inputRef$curren.value) === '') _this.inputRef.current.value = _this.inputRef.current.min || '0';
80
- (_this$inputRef$curren2 = _this.inputRef.current) === null || _this$inputRef$curren2 === void 0 || (_this$inputRef$curren3 = _this$inputRef$curren2.stepUp) === null || _this$inputRef$curren3 === void 0 || _this$inputRef$curren3.call(_this$inputRef$curren2, event);
81
- (_this$inputHandlersRe = _this.inputHandlersRef.current) === null || _this$inputHandlersRe === void 0 || _this$inputHandlersRe.value((_this$inputRef$curren4 = _this.inputRef.current) === null || _this$inputRef$curren4 === void 0 ? void 0 : _this$inputRef$curren4.value, event);
67
+ if (this.inputRef.current?.value === '') this.inputRef.current.value = this.inputRef.current.min || '0';
68
+ this.inputRef.current?.stepUp?.(event);
82
69
  });
83
- _defineProperty(_this, "decrement", function (event) {
84
- var _this$inputRef$curren5, _this$inputRef$curren6, _this$inputRef$curren7, _this$inputHandlersRe2, _this$inputRef$curren8;
85
- if (((_this$inputRef$curren5 = _this.inputRef.current) === null || _this$inputRef$curren5 === void 0 ? void 0 : _this$inputRef$curren5.value) === '') _this.inputRef.current.value = _this.inputRef.current.max || '0';
86
- (_this$inputRef$curren6 = _this.inputRef.current) === null || _this$inputRef$curren6 === void 0 || (_this$inputRef$curren7 = _this$inputRef$curren6.stepDown) === null || _this$inputRef$curren7 === void 0 || _this$inputRef$curren7.call(_this$inputRef$curren6, event);
87
- (_this$inputHandlersRe2 = _this.inputHandlersRef.current) === null || _this$inputHandlersRe2 === void 0 || _this$inputHandlersRe2.value((_this$inputRef$curren8 = _this.inputRef.current) === null || _this$inputRef$curren8 === void 0 ? void 0 : _this$inputRef$curren8.value, event);
70
+ _defineProperty(this, "decrement", event => {
71
+ if (this.inputRef.current?.value === '') this.inputRef.current.value = this.inputRef.current.max || '0';
72
+ this.inputRef.current?.stepDown?.(event);
88
73
  });
89
- _defineProperty(_this, "handleMouseDownAddon", function (event) {
90
- var _this$inputRef$curren9;
74
+ _defineProperty(this, "handleMouseDownAddon", event => {
91
75
  event.preventDefault();
92
- (_this$inputRef$curren9 = _this.inputRef.current) === null || _this$inputRef$curren9 === void 0 || _this$inputRef$curren9.focus();
76
+ this.inputRef.current?.focus();
93
77
  });
94
- _defineProperty(_this, "handleConfirm", function (text, event) {
95
- var _this$asProps$onConfi, _this$asProps;
96
- (_this$asProps$onConfi = (_this$asProps = _this.asProps).onConfirm) === null || _this$asProps$onConfi === void 0 || _this$asProps$onConfi.call(_this$asProps, text, event);
78
+ _defineProperty(this, "handleConfirm", (text, event) => {
79
+ this.asProps.onConfirm?.(text, event);
97
80
  });
98
- _defineProperty(_this, "handleCancel", function (prevText, event) {
99
- var _this$asProps$onCance, _this$asProps2;
100
- (_this$asProps$onCance = (_this$asProps2 = _this.asProps).onCancel) === null || _this$asProps$onCance === void 0 || _this$asProps$onCance.call(_this$asProps2, prevText, event);
81
+ _defineProperty(this, "handleCancel", (prevText, event) => {
82
+ this.asProps.onCancel?.(prevText, event);
101
83
  });
102
- _defineProperty(_this, "handleBlur", function (event) {
103
- var _this$inputRef$curren0, _this$inputRef$curren1;
104
- var _this$asProps3 = _this.asProps,
105
- onConfirm = _this$asProps3.onConfirm,
106
- onCancel = _this$asProps3.onCancel,
107
- onBlurBehavior = _this$asProps3.onBlurBehavior;
84
+ _defineProperty(this, "handleBlur", event => {
85
+ const {
86
+ onConfirm,
87
+ onCancel,
88
+ onBlurBehavior
89
+ } = this.asProps;
108
90
  if (!onBlurBehavior) return;
109
- if (Date.now() - _this.lastHandledKeyboardEvent < 250) return;
110
- if (hasParent(event.relatedTarget, _this.rootRef.current)) return;
111
- if (_this.lastMouseDownPosition && _this.rootRef.current) {
112
- var _this$lastMouseDownPo = _this.lastMouseDownPosition,
113
- x = _this$lastMouseDownPo.x,
114
- y = _this$lastMouseDownPo.y;
115
- var rect = _this.rootRef.current.getBoundingClientRect();
91
+ if (Date.now() - this.lastHandledKeyboardEvent < 250) return;
92
+ if (hasParent(event.relatedTarget, this.rootRef.current)) return;
93
+ if (this.lastMouseDownPosition && this.rootRef.current) {
94
+ const {
95
+ x,
96
+ y
97
+ } = this.lastMouseDownPosition;
98
+ const rect = this.rootRef.current.getBoundingClientRect();
116
99
  if (pointInsideOfRect({
117
- x: x,
118
- y: y,
119
- rect: rect
100
+ x,
101
+ y,
102
+ rect
120
103
  })) {
121
104
  return;
122
105
  }
123
106
  }
124
- if (onBlurBehavior === 'confirm') onConfirm === null || onConfirm === void 0 || onConfirm((_this$inputRef$curren0 = (_this$inputRef$curren1 = _this.inputRef.current) === null || _this$inputRef$curren1 === void 0 ? void 0 : _this$inputRef$curren1.value) !== null && _this$inputRef$curren0 !== void 0 ? _this$inputRef$curren0 : '', event);
125
- if (onBlurBehavior === 'cancel') onCancel === null || onCancel === void 0 || onCancel(_this.initValue, event);
107
+ if (onBlurBehavior === 'confirm') onConfirm?.(this.inputRef.current?.value ?? '', event);
108
+ if (onBlurBehavior === 'cancel') onCancel?.(this.initValue, event);
126
109
  });
127
- _defineProperty(_this, "handleKeyDown", function (event) {
128
- var _this$asProps4 = _this.asProps,
129
- onConfirm = _this$asProps4.onConfirm,
130
- onCancel = _this$asProps4.onCancel;
110
+ _defineProperty(this, "handleKeyDown", event => {
111
+ const {
112
+ onConfirm,
113
+ onCancel
114
+ } = this.asProps;
131
115
  if (event.key === 'Enter') {
132
- var _this$inputRef$curren10, _this$inputRef$curren11;
133
- onConfirm === null || onConfirm === void 0 || onConfirm((_this$inputRef$curren10 = (_this$inputRef$curren11 = _this.inputRef.current) === null || _this$inputRef$curren11 === void 0 ? void 0 : _this$inputRef$curren11.value) !== null && _this$inputRef$curren10 !== void 0 ? _this$inputRef$curren10 : '', event);
134
- _this.lastHandledKeyboardEvent = Date.now();
116
+ onConfirm?.(this.inputRef.current?.value ?? '', event);
117
+ this.lastHandledKeyboardEvent = Date.now();
135
118
  }
136
119
  if (event.key === 'Escape') {
137
- onCancel === null || onCancel === void 0 || onCancel(_this.initValue, event);
138
- _this.lastHandledKeyboardEvent = Date.now();
120
+ onCancel?.(this.initValue, event);
121
+ this.lastHandledKeyboardEvent = Date.now();
139
122
  }
140
123
  });
141
- return _this;
142
124
  }
143
- _inherits(InlineInputBase, _Component);
144
- return _createClass(InlineInputBase, [{
145
- key: "componentDidMount",
146
- value: function componentDidMount() {
125
+ componentDidMount() {
126
+ this.updateInert();
127
+ if (!this.asProps.onBlurBehavior) return;
128
+ document.body.addEventListener('mousedown', this.handleDocumentMouseDown);
129
+ document.body.addEventListener('keydown', this.handleDocumentKeyDown);
130
+ }
131
+ componentDidUpdate(prevProps) {
132
+ if (prevProps.disabled !== this.asProps.disabled) {
147
133
  this.updateInert();
148
- if (!this.asProps.onBlurBehavior) return;
149
- document.body.addEventListener('mousedown', this.handleDocumentMouseDown);
150
- document.body.addEventListener('keydown', this.handleDocumentKeyDown);
151
- }
152
- }, {
153
- key: "componentDidUpdate",
154
- value: function componentDidUpdate(prevProps) {
155
- if (prevProps.disabled !== this.asProps.disabled) {
156
- this.updateInert();
157
- }
158
- }
159
- }, {
160
- key: "componentWillUnmount",
161
- value: function componentWillUnmount() {
162
- if (!this.asProps.onBlurBehavior) return;
163
- document.body.removeEventListener('mousedown', this.handleDocumentMouseDown);
164
- document.body.removeEventListener('keydown', this.handleDocumentKeyDown);
165
- }
166
- }, {
167
- key: "getAddonProps",
168
- value: function getAddonProps() {
169
- return {
170
- onMouseDown: this.handleMouseDownAddon
171
- };
172
- }
173
- }, {
174
- key: "getConfirmControlProps",
175
- value: function getConfirmControlProps() {
176
- var _this$asProps5 = this.asProps,
177
- loading = _this$asProps5.loading,
178
- getI18nText = _this$asProps5.getI18nText;
179
- return {
180
- inputRef: this.inputRef,
181
- loading: loading,
182
- onConfirm: this.handleConfirm,
183
- getI18nText: getI18nText
184
- };
185
134
  }
186
- }, {
187
- key: "getCancelControlProps",
188
- value: function getCancelControlProps() {
189
- var _this$asProps6 = this.asProps,
190
- loading = _this$asProps6.loading,
191
- disabled = _this$asProps6.disabled,
192
- getI18nText = _this$asProps6.getI18nText;
193
- return {
194
- value: this.initValue,
195
- // because double disabled(root disabled and addon disabled)
196
- disabled: loading && !disabled,
197
- onCancel: this.handleCancel,
198
- getI18nText: getI18nText
199
- };
200
- }
201
- }, {
202
- key: "getValueProps",
203
- value: function getValueProps() {
204
- var state = this.asProps.state;
205
- return {
206
- ref: this.inputRef,
207
- state: state,
208
- onKeyDown: this.handleKeyDown
209
- };
210
- }
211
- }, {
212
- key: "getNumberValueProps",
213
- value: function getNumberValueProps() {
214
- var numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
215
- style: 'decimal'
216
- });
217
- return {
218
- numberFormatter: numberFormatter,
219
- inputRef: this.inputRef,
220
- inputHandlerRefs: this.inputHandlersRef,
221
- increment: this.increment,
222
- decrement: this.decrement
223
- };
224
- }
225
- }, {
226
- key: "getNumberControlsProps",
227
- value: function getNumberControlsProps() {
228
- var getI18nText = this.asProps.getI18nText;
229
- return {
230
- increment: this.increment,
231
- decrement: this.decrement,
232
- getI18nText: getI18nText
233
- };
234
- }
235
- }, {
236
- key: "updateInert",
237
- value: function updateInert() {
238
- var disabled = this.asProps.disabled;
239
- if (!this.rootRef.current) return;
240
- if (disabled) {
241
- this.rootRef.current.setAttribute('inert', '');
242
- } else {
243
- this.rootRef.current.removeAttribute('inert');
244
- }
135
+ }
136
+ componentWillUnmount() {
137
+ if (!this.asProps.onBlurBehavior) return;
138
+ document.body.removeEventListener('mousedown', this.handleDocumentMouseDown);
139
+ document.body.removeEventListener('keydown', this.handleDocumentKeyDown);
140
+ }
141
+ getAddonProps() {
142
+ return {
143
+ onMouseDown: this.handleMouseDownAddon
144
+ };
145
+ }
146
+ getConfirmControlProps() {
147
+ const {
148
+ loading,
149
+ getI18nText
150
+ } = this.asProps;
151
+ return {
152
+ inputRef: this.inputRef,
153
+ loading,
154
+ onConfirm: this.handleConfirm,
155
+ getI18nText
156
+ };
157
+ }
158
+ getCancelControlProps() {
159
+ const {
160
+ loading,
161
+ disabled,
162
+ getI18nText
163
+ } = this.asProps;
164
+ return {
165
+ value: this.initValue,
166
+ // because double disabled(root disabled and addon disabled)
167
+ disabled: loading && !disabled,
168
+ onCancel: this.handleCancel,
169
+ getI18nText
170
+ };
171
+ }
172
+ getValueProps() {
173
+ const {
174
+ state
175
+ } = this.asProps;
176
+ return {
177
+ ref: this.inputRef,
178
+ state,
179
+ onKeyDown: this.handleKeyDown
180
+ };
181
+ }
182
+ getNumberValueProps() {
183
+ const numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
184
+ style: 'decimal'
185
+ });
186
+ return {
187
+ numberFormatter,
188
+ inputRef: this.inputRef,
189
+ increment: this.increment,
190
+ decrement: this.decrement
191
+ };
192
+ }
193
+ getNumberControlsProps() {
194
+ const {
195
+ getI18nText
196
+ } = this.asProps;
197
+ return {
198
+ increment: this.increment,
199
+ decrement: this.decrement,
200
+ getI18nText
201
+ };
202
+ }
203
+ updateInert() {
204
+ const {
205
+ disabled
206
+ } = this.asProps;
207
+ if (!this.rootRef.current) return;
208
+ if (disabled) {
209
+ this.rootRef.current.setAttribute('inert', '');
210
+ } else {
211
+ this.rootRef.current.removeAttribute('inert');
245
212
  }
246
- }, {
247
- key: "render",
248
- value: function render() {
249
- var _ref = this.asProps,
250
- _ref8;
251
- var SInlineInput = Box;
252
- var SUnderline = 'div';
253
- var SInvalidPattern = InvalidStateBox;
254
- var _this$asProps7 = this.asProps,
255
- Children = _this$asProps7.Children,
256
- styles = _this$asProps7.styles,
257
- state = _this$asProps7.state;
258
- return _ref8 = sstyled(styles), /*#__PURE__*/React.createElement(SInlineInput, _ref8.cn("SInlineInput", _objectSpread({}, _assignProps({
213
+ }
214
+ render() {
215
+ var _ref = this.asProps,
216
+ _ref8;
217
+ const SInlineInput = Box;
218
+ const SUnderline = 'div';
219
+ const SInvalidPattern = InvalidStateBox;
220
+ const {
221
+ Children,
222
+ styles,
223
+ state
224
+ } = this.asProps;
225
+ return _ref8 = sstyled(styles), /*#__PURE__*/React.createElement(SInlineInput, _ref8.cn("SInlineInput", {
226
+ ..._assignProps({
259
227
  "ref": this.rootRef,
260
228
  "onBlur": this.handleBlur
261
- }, _ref))), /*#__PURE__*/React.createElement(SUnderline, _ref8.cn("SUnderline", {}), state === 'invalid' && /*#__PURE__*/React.createElement(SInvalidPattern, _ref8.cn("SInvalidPattern", {})), /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {}))));
262
- }
263
- }]);
264
- }(Component);
229
+ }, _ref)
230
+ }), /*#__PURE__*/React.createElement(SUnderline, _ref8.cn("SUnderline", {}), state === 'invalid' && /*#__PURE__*/React.createElement(SInvalidPattern, _ref8.cn("SInvalidPattern", {})), /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {}))));
231
+ }
232
+ }
265
233
  _defineProperty(InlineInputBase, "displayName", 'InlineInput');
266
234
  _defineProperty(InlineInputBase, "enhance", [i18nEnhance(localizedMessages)]);
267
235
  _defineProperty(InlineInputBase, "defaultProps", {
@@ -271,60 +239,49 @@ _defineProperty(InlineInputBase, "defaultProps", {
271
239
  locale: 'en'
272
240
  });
273
241
  _defineProperty(InlineInputBase, "style", style);
274
- var Value = /*#__PURE__*/function (_Component2) {
275
- function Value() {
276
- _classCallCheck(this, Value);
277
- return _callSuper(this, Value, arguments);
242
+ class Value extends Component {
243
+ uncontrolledProps() {
244
+ return {
245
+ value: event => event.target.value
246
+ };
278
247
  }
279
- _inherits(Value, _Component2);
280
- return _createClass(Value, [{
281
- key: "uncontrolledProps",
282
- value: function uncontrolledProps() {
283
- return {
284
- value: function value(event) {
285
- return event.target.value;
286
- }
287
- };
288
- }
289
- }, {
290
- key: "render",
291
- value: function render() {
292
- var _ref2 = this.asProps,
293
- _ref9;
294
- var SValue = Box;
295
- return _ref9 = sstyled(this.asProps.styles), /*#__PURE__*/React.createElement(SValue, _ref9.cn("SValue", _objectSpread({}, _assignProps2({
248
+ render() {
249
+ var _ref2 = this.asProps,
250
+ _ref9;
251
+ const SValue = Box;
252
+ return _ref9 = sstyled(this.asProps.styles), /*#__PURE__*/React.createElement(SValue, _ref9.cn("SValue", {
253
+ ..._assignProps2({
296
254
  "tag": 'input',
297
255
  "type": 'text'
298
- }, _ref2))));
299
- }
300
- }]);
301
- }(Component);
256
+ }, _ref2)
257
+ }));
258
+ }
259
+ }
302
260
  _defineProperty(Value, "defaultProps", {
303
261
  defaultValue: ''
304
262
  });
305
- _defineProperty(Value, "enhance", [autoFocusEnhance()]);
306
- _defineProperty(Value, "hoistProps", ['disabled']);
307
- var Addon = function Addon(props) {
263
+ function Addon(props) {
308
264
  var _ref3 = arguments[0],
309
265
  _ref0;
310
- var SAddon = Box;
311
- return _ref0 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref0.cn("SAddon", _objectSpread({}, _assignProps3({}, _ref3))));
312
- };
313
- var ConfirmControl = function ConfirmControl(props) {
266
+ const SAddon = Box;
267
+ return _ref0 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref0.cn("SAddon", {
268
+ ..._assignProps3({}, _ref3)
269
+ }));
270
+ }
271
+ function ConfirmControl(props) {
314
272
  var _ref4 = arguments[0],
315
- _ref10,
316
- _props$title,
317
- _ref16;
318
- var SAddon = Box;
319
- var Children = props.Children,
320
- hasChildren = props.children,
321
- inputRef = props.inputRef;
322
- var title = (_props$title = props.title) !== null && _props$title !== void 0 ? _props$title : props.getI18nText('confirm');
323
- var handleConfirm = React.useCallback(function (event) {
324
- var _props$onConfirm, _inputRef$current$val, _inputRef$current;
325
- (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 || _props$onConfirm.call(props, (_inputRef$current$val = inputRef === null || inputRef === void 0 || (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) !== null && _inputRef$current$val !== void 0 ? _inputRef$current$val : '', event);
326
- }, [props.onConfirm, inputRef === null || inputRef === void 0 ? void 0 : inputRef.current]);
327
- var handleKeydown = React.useCallback(function (event) {
273
+ _ref10;
274
+ const SAddon = Box;
275
+ const {
276
+ Children,
277
+ children: hasChildren,
278
+ inputRef
279
+ } = props;
280
+ const title = props.title ?? props.getI18nText('confirm');
281
+ const handleConfirm = React.useCallback(event => {
282
+ props.onConfirm?.(inputRef?.current?.value ?? '', event);
283
+ }, [props.onConfirm, inputRef?.current]);
284
+ const handleKeydown = React.useCallback(event => {
328
285
  if (event.key === 'Enter' || event.key === ' ') {
329
286
  event.preventDefault();
330
287
  event.stopPropagation();
@@ -333,37 +290,40 @@ var ConfirmControl = function ConfirmControl(props) {
333
290
  }, [handleConfirm]);
334
291
  if (props.loading) {
335
292
  var _ref1;
336
- return _ref1 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref1.cn("SAddon", _objectSpread({}, _assignProps4({}, _ref4))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref1.cn("Children", {})) : /*#__PURE__*/React.createElement(Spin, _ref1.cn("Spin", {
293
+ return _ref1 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref1.cn("SAddon", {
294
+ ..._assignProps4({}, _ref4)
295
+ }), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref1.cn("Children", {})) : /*#__PURE__*/React.createElement(Spin, _ref1.cn("Spin", {
337
296
  "size": 'xs'
338
297
  })));
339
298
  }
340
- var sstyles = sstyled(props.styles);
341
- var sConfirmIconStyles = sstyles.cn('SConfirmIcon', {});
342
- return _ref10 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref10.cn("SAddon", _objectSpread({}, _assignProps5({
343
- "onKeyDown": handleKeydown
344
- }, _ref4))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref10.cn("Children", {})) : /*#__PURE__*/React.createElement(ButtonLink, _ref10.cn("ButtonLink", {
345
- "addonLeft": (_ref16 = props.icon) !== null && _ref16 !== void 0 ? _ref16 : CheckM,
299
+ const sstyles = sstyled(props.styles);
300
+ const sConfirmIconStyles = sstyles.cn('SConfirmIcon', {});
301
+ return _ref10 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref10.cn("SAddon", {
302
+ ..._assignProps5({
303
+ "onKeyDown": handleKeydown
304
+ }, _ref4)
305
+ }), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref10.cn("Children", {})) : /*#__PURE__*/React.createElement(ButtonLink, _ref10.cn("ButtonLink", {
306
+ "addonLeft": props.icon ?? CheckM,
346
307
  "use": 'secondary',
347
308
  "onClick": handleConfirm,
348
309
  "className": sConfirmIconStyles.className,
349
310
  "style": sConfirmIconStyles.style,
350
311
  "aria-label": title
351
312
  })));
352
- };
353
- var CancelControl = function CancelControl(props) {
313
+ }
314
+ function CancelControl(props) {
354
315
  var _ref5 = arguments[0],
355
- _ref12,
356
- _props$title2,
357
- _ref17;
358
- var SAddon = Box;
359
- var Children = props.Children,
360
- hasChildren = props.children;
361
- var title = (_props$title2 = props.title) !== null && _props$title2 !== void 0 ? _props$title2 : props.getI18nText('discard');
362
- var handleCancel = React.useCallback(function (event) {
363
- var _props$onCancel, _props$value;
364
- (_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 || _props$onCancel.call(props, (_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : '', event);
316
+ _ref12;
317
+ const SAddon = Box;
318
+ const {
319
+ Children,
320
+ children: hasChildren
321
+ } = props;
322
+ const title = props.title ?? props.getI18nText('discard');
323
+ const handleCancel = React.useCallback(event => {
324
+ props.onCancel?.(props.value ?? '', event);
365
325
  }, [props.onCancel, props.value]);
366
- var handleKeydown = React.useCallback(function (event) {
326
+ const handleKeydown = React.useCallback(event => {
367
327
  if (event.key === 'Enter' || event.key === ' ') {
368
328
  event.preventDefault();
369
329
  event.stopPropagation();
@@ -372,44 +332,53 @@ var CancelControl = function CancelControl(props) {
372
332
  }, [handleCancel]);
373
333
  if (props.disabled) {
374
334
  var _ref11;
375
- return _ref11 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref11.cn("SAddon", _objectSpread({}, _assignProps6({}, _ref5))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref11.cn("Children", {})) : /*#__PURE__*/React.createElement(CloseM, _ref11.cn("CloseM", {})));
335
+ return _ref11 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref11.cn("SAddon", {
336
+ ..._assignProps6({}, _ref5)
337
+ }), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref11.cn("Children", {})) : /*#__PURE__*/React.createElement(CloseM, _ref11.cn("CloseM", {})));
376
338
  }
377
- var sstyles = sstyled(props.styles);
378
- var sCancelIconStyles = sstyles.cn('SCancelIcon', {});
379
- return _ref12 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref12.cn("SAddon", _objectSpread({}, _assignProps7({
380
- "onKeyDown": handleKeydown
381
- }, _ref5))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref12.cn("Children", {})) : /*#__PURE__*/React.createElement(ButtonLink, _ref12.cn("ButtonLink", {
339
+ const sstyles = sstyled(props.styles);
340
+ const sCancelIconStyles = sstyles.cn('SCancelIcon', {});
341
+ return _ref12 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref12.cn("SAddon", {
342
+ ..._assignProps7({
343
+ "onKeyDown": handleKeydown
344
+ }, _ref5)
345
+ }), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref12.cn("Children", {})) : /*#__PURE__*/React.createElement(ButtonLink, _ref12.cn("ButtonLink", {
382
346
  "use": 'secondary',
383
- "addonLeft": (_ref17 = props.icon) !== null && _ref17 !== void 0 ? _ref17 : CloseM,
347
+ "addonLeft": props.icon ?? CloseM,
384
348
  "onClick": handleCancel,
385
349
  "className": sCancelIconStyles.className,
386
350
  "style": sCancelIconStyles.style,
387
351
  "aria-label": title
388
352
  })));
389
- };
390
- var NumberValue = function NumberValue(props) {
353
+ }
354
+ function NumberValue(props) {
391
355
  var _ref6 = arguments[0],
392
356
  _ref13;
393
- var SValue = InputNumber.Value;
394
- return _ref13 = sstyled(props.styles), /*#__PURE__*/React.createElement(SValue, _ref13.cn("SValue", _objectSpread({}, _assignProps8({}, _ref6))));
395
- };
357
+ const SValue = InputNumber.Value;
358
+ return _ref13 = sstyled(props.styles), /*#__PURE__*/React.createElement(SValue, _ref13.cn("SValue", {
359
+ ..._assignProps8({}, _ref6)
360
+ }));
361
+ }
362
+ ;
396
363
  function NumberControls(props) {
397
364
  var _ref7 = arguments[0],
398
365
  _ref14;
399
- var SControls = InputNumber.Controls;
400
- return _ref14 = sstyled(props.styles), /*#__PURE__*/React.createElement(SControls, _ref14.cn("SControls", _objectSpread({}, _assignProps9({
401
- "tag": InlineInput.Addon
402
- }, _ref7))));
366
+ const SControls = InputNumber.Controls;
367
+ return _ref14 = sstyled(props.styles), /*#__PURE__*/React.createElement(SControls, _ref14.cn("SControls", {
368
+ ..._assignProps9({
369
+ "tag": InlineInput.Addon
370
+ }, _ref7)
371
+ }));
403
372
  }
404
373
 
405
374
  /** `createComponent` currently exposes unrelated junk instead of typings, that the reason of to any cast */
406
- var InlineInput = createComponent(InlineInputBase, {
407
- Addon: Addon,
408
- Value: Value,
409
- ConfirmControl: ConfirmControl,
410
- CancelControl: CancelControl,
411
- NumberValue: NumberValue,
412
- NumberControls: NumberControls
375
+ const InlineInput = createComponent(InlineInputBase, {
376
+ Addon,
377
+ Value,
378
+ ConfirmControl,
379
+ CancelControl,
380
+ NumberValue,
381
+ NumberControls
413
382
  });
414
383
  export default InlineInput;
415
384
  //# sourceMappingURL=InlineInput.js.map