@semcore/inline-input 4.47.0 → 16.0.0-prerelease.11

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,305 +1,363 @@
1
- import k from "@babel/runtime/helpers/esm/objectSpread2";
2
- import R from "@babel/runtime/helpers/esm/classCallCheck";
3
- import E from "@babel/runtime/helpers/esm/createClass";
4
- import f from "@babel/runtime/helpers/esm/assertThisInitialized";
5
- import $ from "@babel/runtime/helpers/esm/inherits";
6
- import V from "@babel/runtime/helpers/esm/createSuper";
7
- import s from "@babel/runtime/helpers/esm/defineProperty";
8
- import { sstyled as M } from "@semcore/utils/lib/core/index";
9
- import K, { sstyled as m, assignProps as C, Component as D } from "@semcore/core";
10
- import u from "react";
11
- import { Box as I, InvalidStateBox as N } from "@semcore/flex-box";
12
- import U from "@semcore/utils/lib/enhances/autoFocusEnhance";
13
- import z from "@semcore/icon/Check/m";
14
- import w from "@semcore/icon/Close/m";
15
- import F from "@semcore/spin";
16
- import { ButtonLink as B } from "@semcore/button";
17
- import { localizedMessages as A } from "./translations/__intergalactic-dynamic-locales.mjs";
18
- import T from "@semcore/utils/lib/enhances/i18nEnhance";
19
- import H from "@semcore/input-number";
20
- import { hasParent as L } from "@semcore/utils/lib/hasParent";
21
- var j = (
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
5
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+ import { sstyled, createComponent, assignProps, Component } from "@semcore/core";
9
+ import React from "react";
10
+ import { Box, InvalidStateBox } from "@semcore/flex-box";
11
+ import autoFocusEnhance from "@semcore/core/lib/utils/enhances/autoFocusEnhance";
12
+ import CheckM from "@semcore/icon/Check/m";
13
+ import CloseM from "@semcore/icon/Close/m";
14
+ import Spin from "@semcore/spin";
15
+ import { ButtonLink } from "@semcore/button";
16
+ import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
17
+ import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
18
+ import InputNumber from "@semcore/input-number";
19
+ import { hasParent } from "@semcore/core/lib/utils/hasParent";
20
+ var style = (
22
21
  /*__reshadow_css_start__*/
23
- (M.insert(
22
+ (sstyled.insert(
24
23
  /*__inner_css_start__*/
25
- ".___SInlineInput_y9k9i_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_y9k9i_gg_ .___SConfirmIcon_y9k9i_gg_{color:var(--intergalactic-icon-secondary-success, #00c192);cursor:pointer}@media (hover:hover){.___SInlineInput_y9k9i_gg_ .___SConfirmIcon_y9k9i_gg_:hover{color:var(--intergalactic-icon-secondary-success-hover-active, #049B75)}}.___SInlineInput_y9k9i_gg_ .___SCancelIcon_y9k9i_gg_{color:var(--intergalactic-icon-secondary-neutral, #a9abb6);cursor:pointer}@media (hover:hover){.___SInlineInput_y9k9i_gg_ .___SCancelIcon_y9k9i_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SInlineInput_y9k9i_gg_.__disabled_y9k9i_gg_{cursor:default;pointer-events:none;opacity:var(--intergalactic-disabled-opacity, 0.3)}.___SValue_y9k9i_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}.___SValue_y9k9i_gg_:focus{outline:0}.___SValue_y9k9i_gg_::-moz-placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SValue_y9k9i_gg_::placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SValue_y9k9i_gg_.__disabled_y9k9i_gg_{-webkit-user-select:none;-moz-user-select:none;user-select:none}.___SValue_y9k9i_gg_::-webkit-inner-spin-button,.___SValue_y9k9i_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_y9k9i_gg_._type_number_y9k9i_gg_{-moz-appearance:textfield}.___SUnderline_y9k9i_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_y9k9i_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_y9k9i_gg_.__disabled_y9k9i_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SInlineInput_y9k9i_gg_.__focused_y9k9i_gg_{z-index:1}.___SInlineInput_y9k9i_gg_.__focused_y9k9i_gg_ .___SUnderline_y9k9i_gg_{border-bottom-color:var(--intergalactic-border-info-active, #006dca);box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5))}.___SInlineInput_y9k9i_gg_._state_valid_y9k9i_gg_ .___SUnderline_y9k9i_gg_{border-bottom-color:var(--intergalactic-border-success-active, #007c65)}.___SInlineInput_y9k9i_gg_._state_valid_y9k9i_gg_.__focused_y9k9i_gg_ .___SUnderline_y9k9i_gg_{border-bottom-color:var(--intergalactic-border-success-active, #007c65);box-shadow:var(--intergalactic-keyboard-focus-valid, 0px 0px 0px 3px rgba(0, 159, 129, 0.5))}.___SInlineInput_y9k9i_gg_._state_invalid_y9k9i_gg_ .___SUnderline_y9k9i_gg_{border-bottom-color:var(--intergalactic-border-critical-active, #d1002f)}.___SInlineInput_y9k9i_gg_._state_invalid_y9k9i_gg_.__focused_y9k9i_gg_ .___SUnderline_y9k9i_gg_{border-bottom-color:var(--intergalactic-border-critical-active, #d1002f);box-shadow:var(--intergalactic-keyboard-focus-invalid, 0px 0px 0px 3px rgba(255, 73, 83, 0.5))}.___SValue_y9k9i_gg_:focus~.___SControls_y9k9i_gg_{display:flex}.___SInvalidPattern_y9k9i_gg_{margin-left:-1px;margin-top:-1px;border-radius:0;height:calc(100% - 3px)}",
26
- "y9k9i_gg_"
24
+ ".___SInlineInput_xoujo_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_xoujo_gg_ .___SConfirmIcon_xoujo_gg_{color:var(--intergalactic-icon-secondary-success, #00c192);cursor:pointer}@media (hover:hover){.___SInlineInput_xoujo_gg_ .___SConfirmIcon_xoujo_gg_:hover{color:var(--intergalactic-icon-secondary-success-hover-active, #049B75)}}.___SInlineInput_xoujo_gg_ .___SCancelIcon_xoujo_gg_{color:var(--intergalactic-icon-secondary-neutral, #a9abb6);cursor:pointer}@media (hover:hover){.___SInlineInput_xoujo_gg_ .___SCancelIcon_xoujo_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SInlineInput_xoujo_gg_.__disabled_xoujo_gg_{cursor:default;pointer-events:none;opacity:var(--intergalactic-disabled-opacity, 0.3)}.___SValue_xoujo_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}.___SValue_xoujo_gg_:focus{outline:0}.___SValue_xoujo_gg_::-moz-placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SValue_xoujo_gg_::placeholder{color:var(--intergalactic-text-placeholder, #8a8e9b)}.___SValue_xoujo_gg_.__disabled_xoujo_gg_{-webkit-user-select:none;-moz-user-select:none;user-select:none}.___SValue_xoujo_gg_::-webkit-inner-spin-button,.___SValue_xoujo_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_xoujo_gg_._type_number_xoujo_gg_{-moz-appearance:textfield}.___SUnderline_xoujo_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_xoujo_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_xoujo_gg_.__disabled_xoujo_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SUnderline_xoujo_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-info-active, #006dca);box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5))}.___SInlineInput_xoujo_gg_._state_valid_xoujo_gg_ .___SUnderline_xoujo_gg_{border-bottom-color:var(--intergalactic-border-success-active, #007c65)}.___SInlineInput_xoujo_gg_._state_valid_xoujo_gg_ .___SUnderline_xoujo_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-success-active, #007c65);box-shadow:var(--intergalactic-keyboard-focus-valid, 0px 0px 0px 3px rgba(0, 159, 129, 0.5))}.___SInlineInput_xoujo_gg_._state_invalid_xoujo_gg_ .___SUnderline_xoujo_gg_{border-bottom-color:var(--intergalactic-border-critical-active, #d1002f)}.___SInlineInput_xoujo_gg_._state_invalid_xoujo_gg_ .___SUnderline_xoujo_gg_:has(input:focus-visible){border-bottom-color:var(--intergalactic-border-critical-active, #d1002f);box-shadow:var(--intergalactic-keyboard-focus-invalid, 0px 0px 0px 3px rgba(255, 73, 83, 0.5))}.___SValue_xoujo_gg_:focus~.___SControls_xoujo_gg_{display:flex}.___SInvalidPattern_xoujo_gg_{margin-left:-1px;margin-top:-1px;border-radius:0;height:calc(100% - 3px)}",
25
+ "xoujo_gg_"
27
26
  ), {
28
- __SInlineInput: "___SInlineInput_y9k9i_gg_",
29
- _disabled: "__disabled_y9k9i_gg_",
30
- __SUnderline: "___SUnderline_y9k9i_gg_",
31
- __SAddon: "___SAddon_y9k9i_gg_",
32
- _focused: "__focused_y9k9i_gg_",
33
- _state_valid: "_state_valid_y9k9i_gg_",
34
- _state_invalid: "_state_invalid_y9k9i_gg_",
35
- __SValue: "___SValue_y9k9i_gg_",
36
- __SControls: "___SControls_y9k9i_gg_",
37
- __SInvalidPattern: "___SInvalidPattern_y9k9i_gg_",
38
- __SConfirmIcon: "___SConfirmIcon_y9k9i_gg_",
39
- __SCancelIcon: "___SCancelIcon_y9k9i_gg_",
40
- _type_number: "_type_number_y9k9i_gg_"
27
+ "__SInlineInput": "___SInlineInput_xoujo_gg_",
28
+ "_disabled": "__disabled_xoujo_gg_",
29
+ "__SUnderline": "___SUnderline_xoujo_gg_",
30
+ "__SAddon": "___SAddon_xoujo_gg_",
31
+ "_state_valid": "_state_valid_xoujo_gg_",
32
+ "_state_invalid": "_state_invalid_xoujo_gg_",
33
+ "__SValue": "___SValue_xoujo_gg_",
34
+ "__SControls": "___SControls_xoujo_gg_",
35
+ "__SInvalidPattern": "___SInvalidPattern_xoujo_gg_",
36
+ "__SConfirmIcon": "___SConfirmIcon_xoujo_gg_",
37
+ "__SCancelIcon": "___SCancelIcon_xoujo_gg_",
38
+ "_type_number": "_type_number_xoujo_gg_"
41
39
  })
42
- ), O = function(n) {
43
- var l = n.x, e = n.y, t = n.rect;
44
- return l >= t.x && l <= t.x + t.width && e >= t.y && e <= t.y + t.height;
45
- }, x = /* @__PURE__ */ function(p) {
46
- $(l, p);
47
- var n = V(l);
48
- function l() {
49
- var e;
50
- R(this, l);
51
- for (var t = arguments.length, c = new Array(t), g = 0; g < t; g++)
52
- c[g] = arguments[g];
53
- return e = n.call.apply(n, [this].concat(c)), s(f(e), "state", {
54
- focused: !1
55
- }), s(f(e), "rootRef", /* @__PURE__ */ u.createRef()), s(f(e), "inputRef", /* @__PURE__ */ u.createRef()), s(f(e), "inputHandlersRef", /* @__PURE__ */ u.createRef()), s(f(e), "initValue", ""), s(f(e), "lastMouseDownPosition", null), s(f(e), "lastHandledKeyboardEvent", -1), s(f(e), "handleDocumentMouseDown", function(r) {
56
- e.lastMouseDownPosition = {
57
- x: r.clientX,
58
- y: r.clientY
59
- }, e.lastHandledKeyboardEvent = -1;
60
- }), s(f(e), "handleDocumentKeyDown", function() {
61
- e.lastMouseDownPosition = null;
62
- }), s(f(e), "increment", function(r) {
63
- var a, i, o, d, _;
64
- ((a = e.inputRef.current) === null || a === void 0 ? void 0 : a.value) === "" && (e.inputRef.current.value = e.inputRef.current.min || "0"), (i = e.inputRef.current) === null || i === void 0 || (o = i.stepUp) === null || o === void 0 || o.call(i, r), (d = e.inputHandlersRef.current) === null || d === void 0 || d.value((_ = e.inputRef.current) === null || _ === void 0 ? void 0 : _.value, r);
65
- }), s(f(e), "decrement", function(r) {
66
- var a, i, o, d, _;
67
- ((a = e.inputRef.current) === null || a === void 0 ? void 0 : a.value) === "" && (e.inputRef.current.value = e.inputRef.current.max || "0"), (i = e.inputRef.current) === null || i === void 0 || (o = i.stepDown) === null || o === void 0 || o.call(i, r), (d = e.inputHandlersRef.current) === null || d === void 0 || d.value((_ = e.inputRef.current) === null || _ === void 0 ? void 0 : _.value, r);
68
- }), s(f(e), "bindHandlerValueFocused", function(r) {
69
- return function() {
70
- e.setState({
71
- focused: r
72
- });
40
+ );
41
+ var pointInsideOfRect = function pointInsideOfRect2(_ref17) {
42
+ var x = _ref17.x, y = _ref17.y, rect = _ref17.rect;
43
+ return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
44
+ };
45
+ var InlineInputBase = /* @__PURE__ */ function(_Component) {
46
+ _inherits(InlineInputBase2, _Component);
47
+ var _super = _createSuper(InlineInputBase2);
48
+ function InlineInputBase2() {
49
+ var _this;
50
+ _classCallCheck(this, InlineInputBase2);
51
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
52
+ args[_key] = arguments[_key];
53
+ }
54
+ _this = _super.call.apply(_super, [this].concat(args));
55
+ _defineProperty(_assertThisInitialized(_this), "rootRef", /* @__PURE__ */ React.createRef());
56
+ _defineProperty(_assertThisInitialized(_this), "inputRef", /* @__PURE__ */ React.createRef());
57
+ _defineProperty(_assertThisInitialized(_this), "inputHandlersRef", /* @__PURE__ */ React.createRef());
58
+ _defineProperty(_assertThisInitialized(_this), "initValue", "");
59
+ _defineProperty(_assertThisInitialized(_this), "lastMouseDownPosition", null);
60
+ _defineProperty(_assertThisInitialized(_this), "lastHandledKeyboardEvent", -1);
61
+ _defineProperty(_assertThisInitialized(_this), "handleDocumentMouseDown", function(event) {
62
+ _this.lastMouseDownPosition = {
63
+ x: event.clientX,
64
+ y: event.clientY
73
65
  };
74
- }), s(f(e), "handleMouseDownAddon", function(r) {
75
- var a;
76
- r.preventDefault(), (a = e.inputRef.current) === null || a === void 0 || a.focus();
77
- }), s(f(e), "handleConfirm", function(r, a) {
78
- var i, o;
79
- (i = (o = e.asProps).onConfirm) === null || i === void 0 || i.call(o, r, a);
80
- }), s(f(e), "handleCancel", function(r, a) {
81
- var i, o;
82
- (i = (o = e.asProps).onCancel) === null || i === void 0 || i.call(o, r, a);
83
- }), s(f(e), "handleBlur", function(r) {
84
- var a, i, o = e.asProps, d = o.onConfirm, _ = o.onCancel, y = o.onBlurBehavior;
85
- if (y && !(Date.now() - e.lastHandledKeyboardEvent < 250) && !L(r.relatedTarget, e.rootRef.current)) {
86
- if (e.lastMouseDownPosition && e.rootRef.current) {
87
- var S = e.lastMouseDownPosition, v = S.x, h = S.y, b = e.rootRef.current.getBoundingClientRect();
88
- if (O({
89
- x: v,
90
- y: h,
91
- rect: b
92
- }))
93
- return;
66
+ _this.lastHandledKeyboardEvent = -1;
67
+ });
68
+ _defineProperty(_assertThisInitialized(_this), "handleDocumentKeyDown", function() {
69
+ _this.lastMouseDownPosition = null;
70
+ });
71
+ _defineProperty(_assertThisInitialized(_this), "increment", function(event) {
72
+ var _this$inputRef$curren, _this$inputRef$curren2, _this$inputRef$curren3, _this$inputHandlersRe, _this$inputRef$curren4;
73
+ 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";
74
+ (_this$inputRef$curren2 = _this.inputRef.current) === null || _this$inputRef$curren2 === void 0 ? void 0 : (_this$inputRef$curren3 = _this$inputRef$curren2.stepUp) === null || _this$inputRef$curren3 === void 0 ? void 0 : _this$inputRef$curren3.call(_this$inputRef$curren2, event);
75
+ (_this$inputHandlersRe = _this.inputHandlersRef.current) === null || _this$inputHandlersRe === void 0 ? void 0 : _this$inputHandlersRe.value((_this$inputRef$curren4 = _this.inputRef.current) === null || _this$inputRef$curren4 === void 0 ? void 0 : _this$inputRef$curren4.value, event);
76
+ });
77
+ _defineProperty(_assertThisInitialized(_this), "decrement", function(event) {
78
+ var _this$inputRef$curren5, _this$inputRef$curren6, _this$inputRef$curren7, _this$inputHandlersRe2, _this$inputRef$curren8;
79
+ 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";
80
+ (_this$inputRef$curren6 = _this.inputRef.current) === null || _this$inputRef$curren6 === void 0 ? void 0 : (_this$inputRef$curren7 = _this$inputRef$curren6.stepDown) === null || _this$inputRef$curren7 === void 0 ? void 0 : _this$inputRef$curren7.call(_this$inputRef$curren6, event);
81
+ (_this$inputHandlersRe2 = _this.inputHandlersRef.current) === null || _this$inputHandlersRe2 === void 0 ? void 0 : _this$inputHandlersRe2.value((_this$inputRef$curren8 = _this.inputRef.current) === null || _this$inputRef$curren8 === void 0 ? void 0 : _this$inputRef$curren8.value, event);
82
+ });
83
+ _defineProperty(_assertThisInitialized(_this), "handleMouseDownAddon", function(event) {
84
+ var _this$inputRef$curren9;
85
+ event.preventDefault();
86
+ (_this$inputRef$curren9 = _this.inputRef.current) === null || _this$inputRef$curren9 === void 0 ? void 0 : _this$inputRef$curren9.focus();
87
+ });
88
+ _defineProperty(_assertThisInitialized(_this), "handleConfirm", function(text, event) {
89
+ var _this$asProps$onConfi, _this$asProps;
90
+ (_this$asProps$onConfi = (_this$asProps = _this.asProps).onConfirm) === null || _this$asProps$onConfi === void 0 ? void 0 : _this$asProps$onConfi.call(_this$asProps, text, event);
91
+ });
92
+ _defineProperty(_assertThisInitialized(_this), "handleCancel", function(prevText, event) {
93
+ var _this$asProps$onCance, _this$asProps2;
94
+ (_this$asProps$onCance = (_this$asProps2 = _this.asProps).onCancel) === null || _this$asProps$onCance === void 0 ? void 0 : _this$asProps$onCance.call(_this$asProps2, prevText, event);
95
+ });
96
+ _defineProperty(_assertThisInitialized(_this), "handleBlur", function(event) {
97
+ var _this$inputRef$curren10, _this$inputRef$curren11;
98
+ var _this$asProps3 = _this.asProps, onConfirm = _this$asProps3.onConfirm, onCancel = _this$asProps3.onCancel, onBlurBehavior = _this$asProps3.onBlurBehavior;
99
+ if (!onBlurBehavior) return;
100
+ if (Date.now() - _this.lastHandledKeyboardEvent < 250) return;
101
+ if (hasParent(event.relatedTarget, _this.rootRef.current)) return;
102
+ if (_this.lastMouseDownPosition && _this.rootRef.current) {
103
+ var _this$lastMouseDownPo = _this.lastMouseDownPosition, x = _this$lastMouseDownPo.x, y = _this$lastMouseDownPo.y;
104
+ var rect = _this.rootRef.current.getBoundingClientRect();
105
+ if (pointInsideOfRect({
106
+ x,
107
+ y,
108
+ rect
109
+ })) {
110
+ return;
94
111
  }
95
- y === "confirm" && (d == null || d((a = (i = e.inputRef.current) === null || i === void 0 ? void 0 : i.value) !== null && a !== void 0 ? a : "", r)), y === "cancel" && (_ == null || _(e.initValue, r));
96
112
  }
97
- }), s(f(e), "handleKeyDown", function(r) {
98
- var a = e.asProps, i = a.onConfirm, o = a.onCancel;
99
- if (r.key === "Enter") {
100
- var d, _;
101
- i == null || i((d = (_ = e.inputRef.current) === null || _ === void 0 ? void 0 : _.value) !== null && d !== void 0 ? d : "", r), e.lastHandledKeyboardEvent = Date.now();
113
+ if (onBlurBehavior === "confirm") onConfirm === null || onConfirm === void 0 ? 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);
114
+ if (onBlurBehavior === "cancel") onCancel === null || onCancel === void 0 ? void 0 : onCancel(_this.initValue, event);
115
+ });
116
+ _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function(event) {
117
+ var _this$asProps4 = _this.asProps, onConfirm = _this$asProps4.onConfirm, onCancel = _this$asProps4.onCancel;
118
+ if (event.key === "Enter") {
119
+ var _this$inputRef$curren12, _this$inputRef$curren13;
120
+ onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm((_this$inputRef$curren12 = (_this$inputRef$curren13 = _this.inputRef.current) === null || _this$inputRef$curren13 === void 0 ? void 0 : _this$inputRef$curren13.value) !== null && _this$inputRef$curren12 !== void 0 ? _this$inputRef$curren12 : "", event);
121
+ _this.lastHandledKeyboardEvent = Date.now();
122
+ }
123
+ if (event.key === "Escape") {
124
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel(_this.initValue, event);
125
+ _this.lastHandledKeyboardEvent = Date.now();
102
126
  }
103
- r.key === "Escape" && (o == null || o(e.initValue, r), e.lastHandledKeyboardEvent = Date.now());
104
- }), e;
127
+ });
128
+ return _this;
105
129
  }
106
- return E(l, [{
130
+ _createClass(InlineInputBase2, [{
107
131
  key: "componentDidMount",
108
- value: function() {
109
- this.asProps.onBlurBehavior && (document.body.addEventListener("mousedown", this.handleDocumentMouseDown), document.body.addEventListener("keydown", this.handleDocumentKeyDown));
132
+ value: function componentDidMount() {
133
+ if (!this.asProps.onBlurBehavior) return;
134
+ document.body.addEventListener("mousedown", this.handleDocumentMouseDown);
135
+ document.body.addEventListener("keydown", this.handleDocumentKeyDown);
110
136
  }
111
137
  }, {
112
138
  key: "componentWillUnmount",
113
- value: function() {
114
- this.asProps.onBlurBehavior && (document.body.removeEventListener("mousedown", this.handleDocumentMouseDown), document.body.removeEventListener("keydown", this.handleDocumentKeyDown));
139
+ value: function componentWillUnmount() {
140
+ if (!this.asProps.onBlurBehavior) return;
141
+ document.body.removeEventListener("mousedown", this.handleDocumentMouseDown);
142
+ document.body.removeEventListener("keydown", this.handleDocumentKeyDown);
115
143
  }
116
144
  }, {
117
145
  key: "getAddonProps",
118
- value: function() {
146
+ value: function getAddonProps() {
119
147
  return {
120
148
  onMouseDown: this.handleMouseDownAddon
121
149
  };
122
150
  }
123
151
  }, {
124
152
  key: "getConfirmControlProps",
125
- value: function() {
126
- var t, c = this.asProps, g = c.loading, r = c.getI18nText;
153
+ value: function getConfirmControlProps() {
154
+ var _this$inputRef$curren14;
155
+ var _this$asProps5 = this.asProps, loading = _this$asProps5.loading, getI18nText = _this$asProps5.getI18nText;
127
156
  return {
128
- value: (t = this.inputRef.current) === null || t === void 0 ? void 0 : t.value,
129
- loading: g,
157
+ value: (_this$inputRef$curren14 = this.inputRef.current) === null || _this$inputRef$curren14 === void 0 ? void 0 : _this$inputRef$curren14.value,
158
+ loading,
130
159
  onConfirm: this.handleConfirm,
131
- getI18nText: r
160
+ getI18nText
132
161
  };
133
162
  }
134
163
  }, {
135
164
  key: "getCancelControlProps",
136
- value: function() {
137
- var t = this.asProps, c = t.loading, g = t.disabled, r = t.getI18nText;
165
+ value: function getCancelControlProps() {
166
+ var _this$asProps6 = this.asProps, loading = _this$asProps6.loading, disabled = _this$asProps6.disabled, getI18nText = _this$asProps6.getI18nText;
138
167
  return {
139
168
  value: this.initValue,
140
169
  // because double disabled(root disabled and addon disabled)
141
- disabled: c && !g,
170
+ disabled: loading && !disabled,
142
171
  onCancel: this.handleCancel,
143
- getI18nText: r
172
+ getI18nText
144
173
  };
145
174
  }
146
175
  }, {
147
176
  key: "getValueProps",
148
- value: function() {
149
- var t = this.asProps.state;
177
+ value: function getValueProps() {
178
+ var state = this.asProps.state;
150
179
  return {
151
180
  ref: this.inputRef,
152
- state: t,
153
- onKeyDown: this.handleKeyDown,
154
- onFocus: this.bindHandlerValueFocused(!0),
155
- onBlur: this.bindHandlerValueFocused(!1)
181
+ state,
182
+ onKeyDown: this.handleKeyDown
156
183
  };
157
184
  }
158
185
  }, {
159
186
  key: "getNumberValueProps",
160
- value: function() {
161
- var t = new Intl.NumberFormat(this.asProps.locale, {
187
+ value: function getNumberValueProps() {
188
+ var numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
162
189
  style: "decimal"
163
190
  });
164
191
  return {
165
- numberFormatter: t,
192
+ numberFormatter,
166
193
  inputRef: this.inputRef,
167
194
  inputHandlerRefs: this.inputHandlersRef,
168
195
  increment: this.increment,
169
- decrement: this.decrement,
170
- onFocus: this.bindHandlerValueFocused(!0),
171
- onBlur: this.bindHandlerValueFocused(!1)
196
+ decrement: this.decrement
172
197
  };
173
198
  }
174
199
  }, {
175
200
  key: "getNumberControlsProps",
176
- value: function() {
177
- var t = this.asProps.getI18nText;
201
+ value: function getNumberControlsProps() {
202
+ var getI18nText = this.asProps.getI18nText;
178
203
  return {
179
204
  increment: this.increment,
180
205
  decrement: this.decrement,
181
- getI18nText: t
206
+ getI18nText
182
207
  };
183
208
  }
184
209
  }, {
185
210
  key: "render",
186
- value: function() {
187
- var t = this.asProps, c, g = I, r = "div", a = N, i = this.asProps, o = i.Children, d = i.styles, _ = i.state, y = this.state.focused;
188
- return c = m(d), /* @__PURE__ */ u.createElement(g, c.cn("SInlineInput", k({}, C({
189
- ref: this.rootRef,
190
- focused: y,
191
- onBlur: this.handleBlur
192
- }, t))), /* @__PURE__ */ u.createElement(r, c.cn("SUnderline", {}), _ === "invalid" && /* @__PURE__ */ u.createElement(a, c.cn("SInvalidPattern", {})), /* @__PURE__ */ u.createElement(o, c.cn("Children", {}))));
211
+ value: function render() {
212
+ var _ref = this.asProps, _ref8;
213
+ var SInlineInput = Box;
214
+ var SUnderline = "div";
215
+ var SInvalidPattern = InvalidStateBox;
216
+ var _this$asProps7 = this.asProps, Children = _this$asProps7.Children, styles = _this$asProps7.styles, state = _this$asProps7.state;
217
+ return _ref8 = sstyled(styles), /* @__PURE__ */ React.createElement(SInlineInput, _ref8.cn("SInlineInput", _objectSpread({}, assignProps({
218
+ "ref": this.rootRef,
219
+ "onBlur": this.handleBlur
220
+ }, _ref))), /* @__PURE__ */ React.createElement(SUnderline, _ref8.cn("SUnderline", {}), state === "invalid" && /* @__PURE__ */ React.createElement(SInvalidPattern, _ref8.cn("SInvalidPattern", {})), /* @__PURE__ */ React.createElement(Children, _ref8.cn("Children", {}))));
193
221
  }
194
- }]), l;
195
- }(D);
196
- s(x, "displayName", "InlineInput");
197
- s(x, "enhance", [T(A)]);
198
- s(x, "defaultProps", {
222
+ }]);
223
+ return InlineInputBase2;
224
+ }(Component);
225
+ _defineProperty(InlineInputBase, "displayName", "InlineInput");
226
+ _defineProperty(InlineInputBase, "enhance", [i18nEnhance(localizedMessages)]);
227
+ _defineProperty(InlineInputBase, "defaultProps", {
199
228
  state: "normal",
200
229
  onBlurBehavior: "confirm",
201
- i18n: A,
230
+ i18n: localizedMessages,
202
231
  locale: "en"
203
232
  });
204
- s(x, "style", j);
205
- var P = /* @__PURE__ */ function(p) {
206
- $(l, p);
207
- var n = V(l);
208
- function l() {
209
- return R(this, l), n.apply(this, arguments);
233
+ _defineProperty(InlineInputBase, "style", style);
234
+ var Value = /* @__PURE__ */ function(_Component2) {
235
+ _inherits(Value2, _Component2);
236
+ var _super2 = _createSuper(Value2);
237
+ function Value2() {
238
+ _classCallCheck(this, Value2);
239
+ return _super2.apply(this, arguments);
210
240
  }
211
- return E(l, [{
241
+ _createClass(Value2, [{
212
242
  key: "uncontrolledProps",
213
- value: function() {
243
+ value: function uncontrolledProps() {
214
244
  return {
215
- value: function(c) {
216
- return c.target.value;
245
+ value: function value(event) {
246
+ return event.target.value;
217
247
  }
218
248
  };
219
249
  }
220
250
  }, {
221
251
  key: "render",
222
- value: function() {
223
- var t = this.asProps, c, g = I;
224
- return c = m(this.asProps.styles), /* @__PURE__ */ u.createElement(g, c.cn("SValue", k({}, C({
225
- tag: "input",
226
- type: "text"
227
- }, t))));
252
+ value: function render() {
253
+ var _ref2 = this.asProps, _ref9;
254
+ var SValue = Box;
255
+ return _ref9 = sstyled(this.asProps.styles), /* @__PURE__ */ React.createElement(SValue, _ref9.cn("SValue", _objectSpread({}, assignProps({
256
+ "tag": "input",
257
+ "type": "text"
258
+ }, _ref2))));
228
259
  }
229
- }]), l;
230
- }(D);
231
- s(P, "defaultProps", {
260
+ }]);
261
+ return Value2;
262
+ }(Component);
263
+ _defineProperty(Value, "defaultProps", {
232
264
  defaultValue: ""
233
265
  });
234
- s(P, "enhance", [U()]);
235
- s(P, "hoistProps", ["disabled"]);
236
- var W = function(n) {
237
- var l = arguments[0], e, t = I;
238
- return e = m(n.styles), /* @__PURE__ */ u.createElement(t, e.cn("SAddon", k({}, C({}, l))));
239
- }, X = function(n) {
240
- var l = arguments[0], e, t, c, g = I, r = n.Children, a = n.children, i = (t = n.title) !== null && t !== void 0 ? t : n.getI18nText("confirm"), o = u.useCallback(function(v) {
241
- var h, b;
242
- (h = n.onConfirm) === null || h === void 0 || h.call(n, (b = n.value) !== null && b !== void 0 ? b : "", v);
243
- }, [n.onConfirm, n.value]), d = u.useCallback(function(v) {
244
- (v.key === "Enter" || v.key === " ") && (v.preventDefault(), v.stopPropagation(), o(v));
245
- }, [o]);
246
- if (n.loading) {
247
- var _;
248
- return _ = m(n.styles), /* @__PURE__ */ u.createElement(g, _.cn("SAddon", k({}, C({}, l))), a ? /* @__PURE__ */ u.createElement(r, _.cn("Children", {})) : /* @__PURE__ */ u.createElement(F, _.cn("Spin", {
249
- size: "xs"
266
+ _defineProperty(Value, "enhance", [autoFocusEnhance()]);
267
+ _defineProperty(Value, "hoistProps", ["disabled"]);
268
+ var Addon = function Addon2(props) {
269
+ var _ref3 = arguments[0], _ref10;
270
+ var SAddon = Box;
271
+ return _ref10 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SAddon, _ref10.cn("SAddon", _objectSpread({}, assignProps({}, _ref3))));
272
+ };
273
+ var ConfirmControl = function ConfirmControl2(props) {
274
+ var _ref4 = arguments[0], _ref12, _props$title, _ref18;
275
+ var SAddon = Box;
276
+ var Children = props.Children, hasChildren = props.children;
277
+ var title = (_props$title = props.title) !== null && _props$title !== void 0 ? _props$title : props.getI18nText("confirm");
278
+ var handleConfirm = React.useCallback(function(event) {
279
+ var _props$onConfirm, _props$value;
280
+ (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 ? void 0 : _props$onConfirm.call(props, (_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : "", event);
281
+ }, [props.onConfirm, props.value]);
282
+ var handleKeydown = React.useCallback(function(event) {
283
+ if (event.key === "Enter" || event.key === " ") {
284
+ event.preventDefault();
285
+ event.stopPropagation();
286
+ handleConfirm(event);
287
+ }
288
+ }, [handleConfirm]);
289
+ if (props.loading) {
290
+ var _ref11;
291
+ return _ref11 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SAddon, _ref11.cn("SAddon", _objectSpread({}, assignProps({}, _ref4))), hasChildren ? /* @__PURE__ */ React.createElement(Children, _ref11.cn("Children", {})) : /* @__PURE__ */ React.createElement(Spin, _ref11.cn("Spin", {
292
+ "size": "xs"
250
293
  })));
251
294
  }
252
- var y = m(n.styles), S = y.cn("SConfirmIcon", {});
253
- return e = m(n.styles), /* @__PURE__ */ u.createElement(g, e.cn("SAddon", k({}, C({
254
- onKeyDown: d
255
- }, l))), a ? /* @__PURE__ */ u.createElement(r, e.cn("Children", {})) : /* @__PURE__ */ u.createElement(B, e.cn("ButtonLink", {
256
- addonLeft: (c = n.icon) !== null && c !== void 0 ? c : z,
257
- use: "secondary",
258
- onClick: o,
259
- className: S.className,
260
- style: S.style,
261
- "aria-label": i
295
+ var sstyles = sstyled(props.styles);
296
+ var sConfirmIconStyles = sstyles.cn("SConfirmIcon", {});
297
+ return _ref12 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SAddon, _ref12.cn("SAddon", _objectSpread({}, assignProps({
298
+ "onKeyDown": handleKeydown
299
+ }, _ref4))), hasChildren ? /* @__PURE__ */ React.createElement(Children, _ref12.cn("Children", {})) : /* @__PURE__ */ React.createElement(ButtonLink, _ref12.cn("ButtonLink", {
300
+ "addonLeft": (_ref18 = props.icon) !== null && _ref18 !== void 0 ? _ref18 : CheckM,
301
+ "use": "secondary",
302
+ "onClick": handleConfirm,
303
+ "className": sConfirmIconStyles.className,
304
+ "style": sConfirmIconStyles.style,
305
+ "aria-label": title
262
306
  })));
263
- }, Y = function(n) {
264
- var l = arguments[0], e, t, c, g = I, r = n.Children, a = n.children, i = (t = n.title) !== null && t !== void 0 ? t : n.getI18nText("discard"), o = u.useCallback(function(v) {
265
- var h, b;
266
- (h = n.onCancel) === null || h === void 0 || h.call(n, (b = n.value) !== null && b !== void 0 ? b : "", v);
267
- }, [n.onCancel, n.value]), d = u.useCallback(function(v) {
268
- (v.key === "Enter" || v.key === " ") && (v.preventDefault(), v.stopPropagation(), o(v));
269
- }, [o]);
270
- if (n.disabled) {
271
- var _;
272
- return _ = m(n.styles), /* @__PURE__ */ u.createElement(g, _.cn("SAddon", k({}, C({}, l))), a ? /* @__PURE__ */ u.createElement(r, _.cn("Children", {})) : /* @__PURE__ */ u.createElement(w, _.cn("CloseM", {})));
307
+ };
308
+ var CancelControl = function CancelControl2(props) {
309
+ var _ref5 = arguments[0], _ref14, _props$title2, _ref19;
310
+ var SAddon = Box;
311
+ var Children = props.Children, hasChildren = props.children;
312
+ var title = (_props$title2 = props.title) !== null && _props$title2 !== void 0 ? _props$title2 : props.getI18nText("discard");
313
+ var handleCancel = React.useCallback(function(event) {
314
+ var _props$onCancel, _props$value2;
315
+ (_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 ? void 0 : _props$onCancel.call(props, (_props$value2 = props.value) !== null && _props$value2 !== void 0 ? _props$value2 : "", event);
316
+ }, [props.onCancel, props.value]);
317
+ var handleKeydown = React.useCallback(function(event) {
318
+ if (event.key === "Enter" || event.key === " ") {
319
+ event.preventDefault();
320
+ event.stopPropagation();
321
+ handleCancel(event);
322
+ }
323
+ }, [handleCancel]);
324
+ if (props.disabled) {
325
+ var _ref13;
326
+ return _ref13 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SAddon, _ref13.cn("SAddon", _objectSpread({}, assignProps({}, _ref5))), hasChildren ? /* @__PURE__ */ React.createElement(Children, _ref13.cn("Children", {})) : /* @__PURE__ */ React.createElement(CloseM, _ref13.cn("CloseM", {})));
273
327
  }
274
- var y = m(n.styles), S = y.cn("SCancelIcon", {});
275
- return e = m(n.styles), /* @__PURE__ */ u.createElement(g, e.cn("SAddon", k({}, C({
276
- onKeyDown: d
277
- }, l))), a ? /* @__PURE__ */ u.createElement(r, e.cn("Children", {})) : /* @__PURE__ */ u.createElement(B, e.cn("ButtonLink", {
278
- use: "secondary",
279
- addonLeft: (c = n.icon) !== null && c !== void 0 ? c : w,
280
- onClick: o,
281
- className: S.className,
282
- style: S.style,
283
- "aria-label": i
328
+ var sstyles = sstyled(props.styles);
329
+ var sCancelIconStyles = sstyles.cn("SCancelIcon", {});
330
+ return _ref14 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SAddon, _ref14.cn("SAddon", _objectSpread({}, assignProps({
331
+ "onKeyDown": handleKeydown
332
+ }, _ref5))), hasChildren ? /* @__PURE__ */ React.createElement(Children, _ref14.cn("Children", {})) : /* @__PURE__ */ React.createElement(ButtonLink, _ref14.cn("ButtonLink", {
333
+ "use": "secondary",
334
+ "addonLeft": (_ref19 = props.icon) !== null && _ref19 !== void 0 ? _ref19 : CloseM,
335
+ "onClick": handleCancel,
336
+ "className": sCancelIconStyles.className,
337
+ "style": sCancelIconStyles.style,
338
+ "aria-label": title
284
339
  })));
285
- }, q = function(n) {
286
- var l = arguments[0], e, t = H.Value;
287
- return e = m(n.styles), /* @__PURE__ */ u.createElement(t, e.cn("SValue", k({}, C({}, l))));
288
340
  };
289
- function G(p) {
290
- var n = arguments[0], l, e = H.Controls;
291
- return l = m(p.styles), /* @__PURE__ */ u.createElement(e, l.cn("SControls", k({}, C({
292
- tag: J.Addon
293
- }, n))));
341
+ var NumberValue = function NumberValue2(props) {
342
+ var _ref6 = arguments[0], _ref15;
343
+ var SValue = InputNumber.Value;
344
+ return _ref15 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SValue, _ref15.cn("SValue", _objectSpread({}, assignProps({}, _ref6))));
345
+ };
346
+ function NumberControls(props) {
347
+ var _ref7 = arguments[0], _ref16;
348
+ var SControls = InputNumber.Controls;
349
+ return _ref16 = sstyled(props.styles), /* @__PURE__ */ React.createElement(SControls, _ref16.cn("SControls", _objectSpread({}, assignProps({
350
+ "tag": InlineInput.Addon
351
+ }, _ref7))));
294
352
  }
295
- var J = K(x, {
296
- Addon: W,
297
- Value: P,
298
- ConfirmControl: X,
299
- CancelControl: Y,
300
- NumberValue: q,
301
- NumberControls: G
353
+ var InlineInput = createComponent(InlineInputBase, {
354
+ Addon,
355
+ Value,
356
+ ConfirmControl,
357
+ CancelControl,
358
+ NumberValue,
359
+ NumberControls
302
360
  });
303
361
  export {
304
- J as default
362
+ InlineInput as default
305
363
  };
package/lib/esm/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import e from "./InlineInput.mjs";
1
+ import InlineInput from "./InlineInput.mjs";
2
2
  export {
3
- e as default
3
+ InlineInput as default
4
4
  };