linear-react-components-ui 1.0.14-beta.3 → 1.0.15-rc.0

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.
@@ -9,7 +9,7 @@
9
9
  // ".gitignore": true,
10
10
  },
11
11
  "editor.codeActionsOnSave": {
12
- "source.fixAll.eslint": "explicit"
12
+ "source.fixAll.eslint": true
13
13
  },
14
14
  "cSpell.words": [
15
15
  "licenca"
@@ -1,6 +1,6 @@
1
-
2
1
  @import "commons.scss";
3
2
  @import "effects.scss";
3
+
4
4
  .datepicker-component {
5
5
  @extend %component-box-shadow;
6
6
  height: auto;
@@ -14,5 +14,3 @@
14
14
  padding: 4px;
15
15
  border: none;
16
16
  }
17
-
18
-
@@ -1,5 +1,6 @@
1
1
  @import "commons.scss";
2
2
  @import "effects.scss";
3
+
3
4
  .periodpicker-component {
4
5
  height: auto;
5
6
  position: relative;
@@ -8,7 +9,7 @@
8
9
  border: 1px solid #dae1e8;
9
10
 
10
11
  .inputwrapper {
11
- border: none;
12
+ border: none;
12
13
  }
13
14
 
14
15
  .separation_icon {
@@ -21,7 +22,7 @@
21
22
  padding: 4px;
22
23
  border: none;
23
24
  }
24
-
25
+
25
26
  .input-base-component {
26
27
  flex: 1;
27
28
  }
@@ -39,11 +40,14 @@
39
40
  &:hover {
40
41
  background-color: $default-hover-color;
41
42
  }
43
+
42
44
  &.-selected {
43
45
  background-color: $default-hover-color;
44
46
  }
47
+
45
48
  &.-disabled {
46
49
  @extend %component-menu-disabled;
50
+
47
51
  &:hover {
48
52
  background-color: transparent;
49
53
  }
@@ -62,4 +66,4 @@
62
66
  overflow-x: hidden;
63
67
  /* margin-top: 2px; */
64
68
  z-index: 99999999999;
65
- }
69
+ }
@@ -1,4 +1,5 @@
1
1
  @import "colors.scss";
2
+
2
3
  %tab-closepanel {
3
4
  background-color: transparent;
4
5
  border: 0;
@@ -10,6 +11,7 @@
10
11
  visibility: hidden;
11
12
  transition: all 0.2s ease-in-out;
12
13
  border-radius: 4px;
14
+
13
15
  &:after {
14
16
  content: "×";
15
17
  font-size: 20px;
@@ -17,13 +19,16 @@
17
19
  color: $font-color-soft;
18
20
  transition: all 0.2s ease-in-out;
19
21
  }
22
+
20
23
  &:hover {
21
24
  background-color: $color-light-dark;
25
+
22
26
  &:after {
23
27
  color: $font-color-second;
24
28
  }
25
29
  }
26
30
  }
31
+
27
32
  %tab-component-menus {
28
33
  .menu {
29
34
  -webkit-box-shadow: 0px -1px 0px $component-border-color inset;
@@ -33,11 +38,13 @@
33
38
  flex-wrap: nowrap;
34
39
  justify-content: center;
35
40
  flex: 1;
36
- &.-firsttabident > .menuitem:first-child {
41
+
42
+ &.-firsttabident>.menuitem:first-child {
37
43
  margin-left: 15px;
38
44
  }
39
45
  }
40
- .menu > .menuitem {
46
+
47
+ .menu>.menuitem {
41
48
  border-bottom: 0;
42
49
  border-radius: 5px 5px 0px 0px;
43
50
  -moz-border-radius: 5px 5px 0px 0px;
@@ -51,27 +58,31 @@
51
58
  display: flex;
52
59
  justify-content: space-between;
53
60
  align-items: center;
61
+
54
62
  &.selected {
55
63
  border: 1px solid $component-border-color;
56
64
  background: $font-color-second;
57
65
  border-bottom: 1px solid $font-color-second;
58
66
  border-top: 2px solid $component-selected-color;
59
67
  box-shadow: 0;
60
- font-weight: bold; /* z-index: 2; */
68
+ font-weight: bold;
69
+ /* z-index: 2; */
61
70
  }
62
- &.selected > .closepanel,
63
- &:hover > .closepanel {
71
+
72
+ &.selected>.closepanel,
73
+ &:hover>.closepanel {
64
74
  visibility: visible;
65
75
  }
66
76
  }
67
- .menu > .menuitem > .menubutton {
77
+
78
+ .menu>.menuitem>.menubutton {
68
79
  white-space: nowrap;
69
80
  text-overflow: ellipsis;
70
81
  background: transparent;
71
82
  border: 0;
72
83
  }
73
84
 
74
- .menu > .menuitem > .closepanel {
85
+ .menu>.menuitem>.closepanel {
75
86
  @extend %tab-closepanel;
76
87
  }
77
88
 
@@ -90,27 +101,32 @@
90
101
  grid-template-rows: auto 1fr;
91
102
  width: 100%;
92
103
  height: 100%;
104
+ overflow: auto;
93
105
  @extend %tab-component-menus;
94
- > .menucontainer {
106
+
107
+ >.menucontainer {
95
108
  display: flex;
96
109
  flex-wrap: nowrap;
97
110
  width: 100%;
98
111
  min-height: 35px;
99
112
  overflow: hidden;
100
113
  @extend %tab-component-menus;
101
- > .dropdownbutton {
114
+
115
+ >.dropdownbutton {
102
116
  border-bottom: 1px solid $component-border-color;
103
117
  padding: 0 0.8rem;
104
118
  }
105
119
  }
106
- > .panel {
120
+
121
+ >.panel {
107
122
  background-color: $font-color-second;
108
123
  border: 1px solid $component-border-color;
109
124
  border-top: 0;
110
125
  padding: 10px;
111
126
  overflow: auto;
112
127
  }
113
- > .hidepanel {
128
+
129
+ >.hidepanel {
114
130
  display: none;
115
131
  }
116
132
  }
@@ -121,16 +137,19 @@
121
137
  .tabs-component.menu-left {
122
138
  grid-template-columns: auto 1fr;
123
139
  grid-template-rows: none;
124
- > .menucontainer {
125
- > .menu {
140
+
141
+ >.menucontainer {
142
+ >.menu {
126
143
  box-shadow: -1px 0px 0px 0px $component-border-color inset;
127
144
  flex-direction: column;
128
145
  justify-content: center;
129
146
  }
130
- > .menu > .menuitem {
147
+
148
+ >.menu>.menuitem {
131
149
  border-radius: 5px 0px 0px 5px;
132
150
  -moz-border-radius: 5px 0px 0px 5px;
133
151
  -webkit-border-radius: 5px 0px 0px 5px;
152
+
134
153
  &.selected {
135
154
  border: 1px solid $component-border-color;
136
155
  border-right: 1px solid $font-color-second;
@@ -138,11 +157,13 @@
138
157
  width: 100%;
139
158
  }
140
159
  }
141
- > .menu > .menuitem > .closepanel {
160
+
161
+ >.menu>.menuitem>.closepanel {
142
162
  float: left;
143
163
  }
144
164
  }
145
- > .panel {
165
+
166
+ >.panel {
146
167
  border-top: 1px solid $component-border-color;
147
168
  border-left: 0;
148
169
  }
@@ -153,14 +174,17 @@
153
174
  */
154
175
  .tabs-component.menu-bottom {
155
176
  grid-template-rows: 1fr auto;
177
+
156
178
  .menucontainer {
157
- > .menu {
179
+ >.menu {
158
180
  box-shadow: 0 1px 1px 0px $component-border-color inset;
159
181
  }
160
- > .menu > .menuitem {
182
+
183
+ >.menu>.menuitem {
161
184
  border-radius: 0px 0px 5px 5px;
162
185
  -moz-border-radius: 0px 0px 5px 5px;
163
186
  -webkit-border-radius: 0px 0px 5px 5px;
187
+
164
188
  &.selected {
165
189
  border: 1px solid $component-border-color;
166
190
  border-top: 1px solid $font-color-second;
@@ -169,7 +193,8 @@
169
193
  }
170
194
  }
171
195
  }
172
- > .panel {
196
+
197
+ >.panel {
173
198
  border-top: 1px solid $component-border-color;
174
199
  border-bottom: 0;
175
200
  }
@@ -181,16 +206,19 @@
181
206
  .tabs-component.menu-right {
182
207
  grid-template-columns: 1fr auto;
183
208
  grid-template-rows: none;
184
- .menucontainer{
185
- > .menu {
209
+
210
+ .menucontainer {
211
+ >.menu {
186
212
  box-shadow: 2px 0 0px -1px $component-border-color inset;
187
213
  flex-direction: column;
188
214
  justify-content: center;
189
215
  }
190
- > .menu > .menuitem {
216
+
217
+ >.menu>.menuitem {
191
218
  border-radius: 0px 5px 5px 0px;
192
219
  -moz-border-radius: 0px 5px 5px 0px;
193
220
  -webkit-border-radius: 0px 5px 5px 0px;
221
+
194
222
  &.selected {
195
223
  border: 1px solid $component-border-color;
196
224
  border-left: 1px solid $font-color-second;
@@ -199,7 +227,8 @@
199
227
  }
200
228
  }
201
229
  }
202
- > .panel {
230
+
231
+ >.panel {
203
232
  border-top: 1px solid $component-border-color;
204
233
  border-right: 0;
205
234
  }
@@ -216,10 +245,12 @@
216
245
  align-items: center;
217
246
  justify-content: space-between;
218
247
  min-height: 50px;
219
- > .closepanel {
248
+
249
+ >.closepanel {
220
250
  @extend %tab-closepanel;
221
251
  }
222
- &:hover > .closepanel {
252
+
253
+ &:hover>.closepanel {
223
254
  visibility: visible;
224
255
  }
225
256
  }
@@ -116,9 +116,10 @@ var FieldArray = function FieldArray(props) {
116
116
  }
117
117
  })), {
118
118
  label: label,
119
- name: name
120
- })), (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
121
- fieldErrors: showValidateMessages ? props.fieldErrors : {}
119
+ name: name,
120
+ errorMessages: (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
121
+ fieldErrors: showValidateMessages ? props.fieldErrors : {}
122
+ }))
122
123
  })));
123
124
  } else {
124
125
  content = /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(Component, _extends({}, rest, getDefaultProps(props, handleShowValidateMessages), getEvents(_objectSpread(_objectSpread({}, props), {}, {
@@ -127,9 +128,10 @@ var FieldArray = function FieldArray(props) {
127
128
  }
128
129
  })), {
129
130
  label: label,
130
- name: name
131
- })), (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
132
- fieldErrors: showValidateMessages ? props.fieldErrors : {}
131
+ name: name,
132
+ errorMessages: (0, _helpers.getErrorMessages)(_objectSpread(_objectSpread({}, props), {}, {
133
+ fieldErrors: showValidateMessages ? props.fieldErrors : {}
134
+ }))
133
135
  })));
134
136
  }
135
137
  }
@@ -7,12 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _lodash = _interopRequireDefault(require("lodash"));
10
+ var _gridlayout = _interopRequireDefault(require("../gridlayout"));
10
11
  var _withFieldHOC = _interopRequireDefault(require("./withFieldHOC"));
11
12
  var _helpers = require("./helpers");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
16
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
+ 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; }
18
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
16
20
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
21
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
22
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -29,13 +33,18 @@ var FieldPeriod = function FieldPeriod(props) {
29
33
  externalMessagesErrors = props.externalMessagesErrors,
30
34
  _onChange = props.onChange,
31
35
  validators = props.validators,
32
- originalData = props.originalData;
36
+ originalData = props.originalData,
37
+ gridLayout = props.gridLayout,
38
+ Component = props.component,
39
+ name = props.name,
40
+ externalFieldErrors = props.externalFieldErrors;
41
+ var content = null;
33
42
  var _useState = (0, _react.useState)(false),
34
43
  _useState2 = _slicedToArray(_useState, 2),
35
44
  showValidateMessages = _useState2[0],
36
45
  setShowValidateMessages = _useState2[1];
37
- var currentValue = _lodash.default.get(data, nameDateInitial);
38
- var originalValue = _lodash.default.get(originalData, nameDateInitial);
46
+ var currentValue = _lodash.default.get(data, name);
47
+ var originalValue = _lodash.default.get(originalData, name);
39
48
  (0, _react.useEffect)(function () {
40
49
  if (!_lodash.default.isEqual(currentValue, originalValue) && currentValue && (!!currentValue || currentValue === 0 || Array.isArray(currentValue) && currentValue.length > 0)) {
41
50
  setShowValidateMessages(true);
@@ -44,47 +53,52 @@ var FieldPeriod = function FieldPeriod(props) {
44
53
  }
45
54
  }, [currentValue]);
46
55
  var errorMessages = (0, _helpers.getErrorMessages)({
47
- name: nameDateInitial,
56
+ name: name,
48
57
  fieldErrors: showValidateMessages ? fieldErrors : {},
58
+ externalFieldErrors: externalFieldErrors,
49
59
  externalMessagesErrors: externalMessagesErrors
50
60
  });
51
- if (!props.component) return null;
52
- return /*#__PURE__*/_react.default.createElement(props.component, _extends({}, props, {
53
- errorMessages: errorMessages,
54
- onChange: function onChange(e, maskValue, _ref) {
55
- var initial = _ref.initial,
56
- final = _ref.final;
57
- if (validators && handlerFieldValidade) {
58
- handlerFieldValidade(nameDateInitial, {
61
+ if (Component) {
62
+ content = /*#__PURE__*/_react.default.createElement(Component, _extends({}, props, {
63
+ errorMessages: errorMessages,
64
+ onChange: function onChange(e, maskValue, _ref) {
65
+ var initial = _ref.initial,
66
+ final = _ref.final;
67
+ if (validators && handlerFieldValidade) {
68
+ var _handlerFieldValidade;
69
+ handlerFieldValidade(nameDateInitial, (_handlerFieldValidade = {}, _defineProperty(_handlerFieldValidade, nameDateInitial, initial), _defineProperty(_handlerFieldValidade, nameDateFinal, final), _handlerFieldValidade), validators);
70
+ setShowValidateMessages(true);
71
+ }
72
+ if (handlerFieldChange) {
73
+ var _value;
74
+ handlerFieldChange({
75
+ target: {
76
+ name: name,
77
+ value: (_value = {}, _defineProperty(_value, nameDateInitial, initial), _defineProperty(_value, nameDateFinal, final), _value)
78
+ }
79
+ });
80
+ }
81
+ if (_onChange) _onChange({
59
82
  initial: initial,
60
83
  final: final
61
- }, validators);
62
- setShowValidateMessages(true);
63
- }
64
- if (handlerFieldChange) {
65
- handlerFieldChange({
66
- target: {
67
- name: nameDateInitial,
68
- value: initial
69
- }
70
- });
71
- handlerFieldChange({
72
- target: {
73
- name: nameDateFinal,
74
- value: final
75
- }
76
84
  });
85
+ },
86
+ value: {
87
+ initial: _lodash.default.get(data, "".concat(name, ".").concat(nameDateInitial)),
88
+ final: _lodash.default.get(data, "".concat(name, ".").concat(nameDateFinal))
77
89
  }
78
- if (_onChange) _onChange({
79
- initial: initial,
80
- final: final
81
- });
82
- },
83
- value: {
84
- initial: _lodash.default.get(data, nameDateInitial),
85
- final: _lodash.default.get(data, nameDateFinal)
86
- }
87
- }));
90
+ }));
91
+ }
92
+ if (gridLayout !== undefined) {
93
+ return /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
94
+ customClass: "-withinput",
95
+ cols: gridLayout,
96
+ style: {
97
+ height: '100%'
98
+ }
99
+ }, content);
100
+ }
101
+ return content;
88
102
  };
89
103
  var _default = (0, _withFieldHOC.default)(FieldPeriod);
90
104
  exports.default = _default;
@@ -8,8 +8,8 @@ import '../@types/Period.js';
8
8
 
9
9
  type Validator = (value: string) => string | undefined;
10
10
  type PeriodValidator = (value: {
11
- initialData: string;
12
- finalData: string;
11
+ inicial: string;
12
+ final: string;
13
13
  }) => string | undefined;
14
14
  type OnFielChangeEvent = Event & {
15
15
  target: HTMLInputElement;
@@ -117,6 +117,7 @@ interface IFieldArrayProps extends WithFieldProps {
117
117
  disabled?: boolean;
118
118
  onBlur?: (event: ChangeEvent<HTMLInputElement>) => void;
119
119
  handlerFieldValidade?: (name: string, value: string, validatorsArray: Validator[] | Validator) => void;
120
+ required?: boolean;
120
121
  }
121
122
  type PeriodChangeEvent = {
122
123
  initial: string;
@@ -125,7 +126,9 @@ type PeriodChangeEvent = {
125
126
  type PeriodFieldChangeEvent = {
126
127
  target: {
127
128
  name: string;
128
- value: string;
129
+ value: {
130
+ [valueDate: string]: string;
131
+ };
129
132
  };
130
133
  };
131
134
  interface IFieldPeriodProps extends WithFieldProps {
@@ -142,8 +145,12 @@ interface IFieldPeriodProps extends WithFieldProps {
142
145
  [name: string]: string[];
143
146
  };
144
147
  externalMessagesErrors?: string[];
148
+ externalFieldErrors?: {
149
+ [name: string]: string[];
150
+ };
145
151
  handlerFieldValidade?: (name: string, value: object, validatorsArray: PeriodValidator[] | PeriodValidator) => void;
146
152
  onChange?: (event: PeriodChangeEvent) => PeriodChangeEvent;
153
+ gridLayout?: string;
147
154
  }
148
155
  interface FormContextProps {
149
156
  skeletonize?: boolean;
package/lib/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { default as List } from './list/index.js';
7
7
  export { default as Radio } from './radio/index.js';
8
8
  export { default as Tab } from './tabs/index.js';
9
9
  export { default as Dialog } from './dialog/base/index.js';
10
- import './types-fe4a1068.js';
10
+ import './types-b7be23b5.js';
11
11
  import 'react';
12
12
  import './@types/PermissionAttr.js';
13
13
  import './internals/colorStyles.js';
@@ -4,13 +4,13 @@ import 'react';
4
4
  import '../../@types/Period.js';
5
5
  import '../../@types/PermissionAttr.js';
6
6
 
7
- declare const getInputClass: ({ textAlign, readOnly, readOnlyClass }: {
7
+ declare const getInputClass: ({ textAlign, readOnly, readOnlyClass, }: {
8
8
  textAlign?: TextAlign | undefined;
9
9
  readOnly?: boolean | undefined;
10
10
  readOnlyClass?: string | undefined;
11
11
  }) => string;
12
12
  declare const getInputWrapperClass: (props: IBaseProps) => string;
13
13
  declare const getErrorMessages: (messages: string[]) => JSX.Element;
14
- declare const getRightElements: (errorMessages: string[], skeletonize: boolean, rightElements?: JSX.Element | JSX.Element[]) => JSX.Element | JSX.Element[] | null;
14
+ declare const getRightElements: (errorMessages: string[], skeletonize: boolean, rightElements?: JSX.Element | JSX.Element[]) => JSX.Element[] | null;
15
15
 
16
16
  export { getErrorMessages, getInputClass, getInputWrapperClass, getRightElements };
@@ -41,9 +41,7 @@ var getRightElements = function getRightElements(errorMessages, skeletonize, rig
41
41
  key: "rightelement-".concat(index + 1)
42
42
  });
43
43
  });
44
- if (errorMessages && errorMessages.length === 0) return elements;
45
- return /*#__PURE__*/_react.default.createElement("div", {
46
- className: "sidebuttons"
47
- }, elements);
44
+ if (errorMessages) return elements;
45
+ return elements;
48
46
  };
49
47
  exports.getRightElements = getRightElements;
@@ -188,7 +188,8 @@ var MultiSelectField = function MultiSelectField(props) {
188
188
  };
189
189
  (0, _react.useEffect)(function () {
190
190
  if (gridLayout) {
191
- var currentGridEl = document.querySelector("#".concat(componentId, ">.-withinput.grid-container"));
191
+ var _selectWrapper$curren;
192
+ var currentGridEl = (_selectWrapper$curren = selectWrapper.current) === null || _selectWrapper$curren === void 0 ? void 0 : _selectWrapper$curren.parentElement;
192
193
  if (currentGridEl) setElementStyles(window.getComputedStyle(currentGridEl));
193
194
  }
194
195
  window.addEventListener('resize', onScreenResize);
@@ -14,6 +14,7 @@ var _calendar = _interopRequireDefault(require("../../calendar"));
14
14
  var _buttons = _interopRequireDefault(require("../../buttons"));
15
15
  var _icons = _interopRequireDefault(require("../../icons"));
16
16
  var _Dialog = _interopRequireDefault(require("./Dialog"));
17
+ var _hint = _interopRequireDefault(require("../../hint"));
17
18
  var helperBase = _interopRequireWildcard(require("../base/helpers"));
18
19
  require("../../assets/styles/periodpicker.scss");
19
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -37,6 +38,7 @@ var PeriodPicker = function PeriodPicker(props) {
37
38
  openOnFocus = _props$openOnFocus === void 0 ? true : _props$openOnFocus,
38
39
  _props$shouldCloseOnS = props.shouldCloseOnSelect,
39
40
  shouldCloseOnSelect = _props$shouldCloseOnS === void 0 ? true : _props$shouldCloseOnS,
41
+ calendarColorStyle = props.calendarColorStyle,
40
42
  _props$showCalendarIn = props.showCalendarInDialog,
41
43
  showCalendarInDialog = _props$showCalendarIn === void 0 ? false : _props$showCalendarIn,
42
44
  _props$dialogSize = props.dialogSize,
@@ -44,27 +46,27 @@ var PeriodPicker = function PeriodPicker(props) {
44
46
  width: '350px',
45
47
  height: '350px'
46
48
  } : _props$dialogSize,
47
- calendarColorStyle = props.calendarColorStyle;
48
- var _useState = (0, _react.useState)(props.value && props.value.initial ? (0, _moment.default)(props.value.initial) : undefined),
49
+ hint = props.hint;
50
+ var _useState = (0, _react.useState)(props.value && (0, _moment.default)(props.value.initial, 'DD/MM/YYYY')),
49
51
  _useState2 = _slicedToArray(_useState, 2),
50
52
  valueInitial = _useState2[0],
51
53
  setValueInitial = _useState2[1];
52
- var _useState3 = (0, _react.useState)(props.value && props.value.final ? (0, _moment.default)(props.value.final) : undefined),
54
+ var _useState3 = (0, _react.useState)(props.value && (0, _moment.default)(props.value.final, 'DD/MM/YYYY')),
53
55
  _useState4 = _slicedToArray(_useState3, 2),
54
56
  valueFinal = _useState4[0],
55
57
  setValueFinal = _useState4[1];
56
- var _useState5 = (0, _react.useState)('valueInitial'),
58
+ var _useState5 = (0, _react.useState)('week'),
57
59
  _useState6 = _slicedToArray(_useState5, 2),
58
- changing = _useState6[0],
59
- setChanging = _useState6[1];
60
- var _useState7 = (0, _react.useState)('week'),
60
+ valuePeriodSelection = _useState6[0],
61
+ setValuePeriodSelection = _useState6[1];
62
+ var _useState7 = (0, _react.useState)(false),
61
63
  _useState8 = _slicedToArray(_useState7, 2),
62
- valuePeriodSelection = _useState8[0],
63
- setValuePeriodSelection = _useState8[1];
64
+ showCalendarValueInitial = _useState8[0],
65
+ setShowCalendarValueInitial = _useState8[1];
64
66
  var _useState9 = (0, _react.useState)(false),
65
67
  _useState10 = _slicedToArray(_useState9, 2),
66
- showCalendar = _useState10[0],
67
- setShowCalendar = _useState10[1];
68
+ showCalendarValueFinal = _useState10[0],
69
+ setShowCalendarValueFinal = _useState10[1];
68
70
  var _useState11 = (0, _react.useState)(false),
69
71
  _useState12 = _slicedToArray(_useState11, 2),
70
72
  showPeriodSelection = _useState12[0],
@@ -77,6 +79,7 @@ var PeriodPicker = function PeriodPicker(props) {
77
79
  _useState16 = _slicedToArray(_useState15, 2),
78
80
  onDenied = _useState16[0],
79
81
  setOnDenied = _useState16[1];
82
+ var wrapperBaseInputPeriodRef = (0, _react.useRef)(null);
80
83
  var inputContainerRef = (0, _react.useRef)(null);
81
84
  var inputInitialRef = (0, _react.useRef)(null);
82
85
  var buttonOpenRef = (0, _react.useRef)(null);
@@ -94,18 +97,31 @@ var PeriodPicker = function PeriodPicker(props) {
94
97
  if (target === inputContainerRef.current || target === inputInitialRef.current || target === inputFinalRef.current || target === buttonOpenRef.current || target === buttonSelectPeriodRef.current) {
95
98
  return;
96
99
  }
97
- if (dropdownCalendarContainer.current && dropdownCalendarContainer.current.contains(target)) return;
100
+ if (dropdownCalendarContainer.current && dropdownCalendarContainer.current.contains(target)) {
101
+ return;
102
+ }
98
103
  if (dropdownPeriodContainer.current && dropdownPeriodContainer.current.contains(target)) return;
99
- setShowCalendar(false);
104
+ setShowCalendarValueInitial(false);
105
+ setShowCalendarValueFinal(false);
100
106
  setShowPeriodSelection(false);
101
107
  };
108
+ var onCloseCalendarWithoutFocus = function onCloseCalendarWithoutFocus(event) {
109
+ if (event.key === 'Tab') {
110
+ if (wrapperBaseInputPeriodRef.current && wrapperBaseInputPeriodRef.current.contains(document.activeElement) && document.activeElement instanceof HTMLInputElement) {
111
+ setShowCalendarValueInitial(false);
112
+ setShowCalendarValueFinal(false);
113
+ }
114
+ }
115
+ };
102
116
  (0, _react.useEffect)(function () {
103
117
  window.addEventListener('resize', onScreenResize);
104
118
  document.addEventListener('click', onClickOutside);
119
+ document.addEventListener('keydown', onCloseCalendarWithoutFocus);
105
120
  if (inputContainerRef.current) onScreenResize();
106
121
  return function () {
107
122
  window.removeEventListener('resize', onScreenResize);
108
123
  document.removeEventListener('click', onClickOutside);
124
+ document.removeEventListener('keydown', onCloseCalendarWithoutFocus);
109
125
  };
110
126
  }, []);
111
127
  (0, _react.useEffect)(function () {
@@ -138,8 +154,14 @@ var PeriodPicker = function PeriodPicker(props) {
138
154
  setValueFinal(newValueFinal);
139
155
  }
140
156
  }, [props.value]);
141
- var openCalendar = function openCalendar() {
142
- setShowCalendar(true);
157
+ var openCalendar = function openCalendar(calendarName) {
158
+ if (calendarName === 'valueInitial') {
159
+ setShowCalendarValueFinal(false);
160
+ setShowCalendarValueInitial(true);
161
+ } else {
162
+ setShowCalendarValueInitial(false);
163
+ setShowCalendarValueFinal(true);
164
+ }
143
165
  setShowPeriodSelection(false);
144
166
  if (inputContainerRef.current) {
145
167
  setInputDimensions(inputContainerRef.current.getBoundingClientRect());
@@ -148,14 +170,17 @@ var PeriodPicker = function PeriodPicker(props) {
148
170
  var onInputFocus = function onInputFocus(e) {
149
171
  var _ref = e.target,
150
172
  name = _ref.name;
151
- setChanging(name);
152
- if (openOnFocus) openCalendar();
173
+ if (openOnFocus) openCalendar(name);
174
+ if (props.onFocus) props.onFocus(e);
175
+ };
176
+ var onInputBlur = function onInputBlur(e) {
177
+ if (props.onBlur) props.onBlur(e);
153
178
  };
154
179
  var onInputChange = function onInputChange(event, value) {
155
180
  if (event) {
156
181
  var _ref2 = event.target,
157
182
  changingAux = _ref2.name;
158
- if (value && value.replace(/\D/g, '') === '') {
183
+ if (value && value.replace(/\D/g, '').trim().length !== 0) {
159
184
  if (changingAux === 'valueInitial') {
160
185
  setValueInitial(undefined);
161
186
  } else {
@@ -164,25 +189,28 @@ var PeriodPicker = function PeriodPicker(props) {
164
189
  }
165
190
  }
166
191
  };
167
- var setValue = function setValue(e, value) {
192
+ var setValue = function setValue(event, value) {
193
+ var _inputInitialRef$curr, _inputFinalRef$curren;
168
194
  var shouldOpenDropdown = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
169
- var changingAux = e ? e.target.name : '';
195
+ var valueDateName = event ? event.target.name : '';
170
196
  var dateObj = (0, _moment.default)(value, 'DD/MM/YYYY');
171
- if (changingAux === 'valueInitial') {
197
+ if (showCalendarValueInitial) (_inputInitialRef$curr = inputInitialRef.current) === null || _inputInitialRef$curr === void 0 ? void 0 : _inputInitialRef$curr.focus();
198
+ if (showCalendarValueFinal) (_inputFinalRef$curren = inputFinalRef.current) === null || _inputFinalRef$curren === void 0 ? void 0 : _inputFinalRef$curren.focus();
199
+ if (valueDateName === 'valueInitial') {
172
200
  setValueInitial(dateObj);
173
201
  } else {
174
202
  setValueFinal(dateObj);
175
203
  }
176
- if (changingAux === 'valueInitial' && !valueFinal && shouldOpenDropdown) {
177
- var _inputFinalRef$curren;
178
- if (valueFinal) setChanging(valueFinal);
179
- setShowCalendar(false);
180
- (_inputFinalRef$curren = inputFinalRef.current) === null || _inputFinalRef$curren === void 0 ? void 0 : _inputFinalRef$curren.focus();
204
+ if (valueDateName === 'valueInitial' && !valueFinal && shouldOpenDropdown) {
205
+ var _inputFinalRef$curren2;
206
+ (_inputFinalRef$curren2 = inputFinalRef.current) === null || _inputFinalRef$curren2 === void 0 ? void 0 : _inputFinalRef$curren2.focus();
181
207
  setTimeout(function () {
182
- return setShowCalendar(true);
208
+ return setShowCalendarValueFinal(true);
183
209
  }, 100);
184
- } else if (shouldCloseOnSelect) {
185
- setShowCalendar(false);
210
+ }
211
+ if (shouldCloseOnSelect) {
212
+ setShowCalendarValueInitial(false);
213
+ setShowCalendarValueFinal(false);
186
214
  }
187
215
  };
188
216
  var shouldDisable = function shouldDisable() {
@@ -198,10 +226,9 @@ var PeriodPicker = function PeriodPicker(props) {
198
226
  name: "calendar"
199
227
  }),
200
228
  onClick: function onClick() {
201
- var _inputInitialRef$curr;
202
- (_inputInitialRef$curr = inputInitialRef.current) === null || _inputInitialRef$curr === void 0 ? void 0 : _inputInitialRef$curr.focus();
203
- setChanging('valueInitial');
204
- openCalendar();
229
+ var _inputInitialRef$curr2;
230
+ (_inputInitialRef$curr2 = inputInitialRef.current) === null || _inputInitialRef$curr2 === void 0 ? void 0 : _inputInitialRef$curr2.focus();
231
+ openCalendar('valueInitial');
205
232
  },
206
233
  customClass: "calendar-button",
207
234
  tabIndex: -1,
@@ -218,7 +245,8 @@ var PeriodPicker = function PeriodPicker(props) {
218
245
  });
219
246
  };
220
247
  var openPeriodSelecion = function openPeriodSelecion() {
221
- setShowCalendar(false);
248
+ setShowCalendarValueFinal(false);
249
+ setShowCalendarValueInitial(false);
222
250
  setShowPeriodSelection(true);
223
251
  if (inputContainerRef.current) {
224
252
  setInputDimensions(inputContainerRef.current.getBoundingClientRect());
@@ -231,6 +259,11 @@ var PeriodPicker = function PeriodPicker(props) {
231
259
  icon: /*#__PURE__*/_react.default.createElement(_icons.default, {
232
260
  name: "more1"
233
261
  }),
262
+ onBlur: function onBlur() {
263
+ return setTimeout(function () {
264
+ return setShowPeriodSelection(false);
265
+ }, 100);
266
+ },
234
267
  onClick: function onClick() {
235
268
  return openPeriodSelecion();
236
269
  },
@@ -242,13 +275,13 @@ var PeriodPicker = function PeriodPicker(props) {
242
275
  disabled: shouldDisable()
243
276
  });
244
277
  };
245
- var getCalendar = function getCalendar(value, calendarColorStyleCalendar, changingAux) {
278
+ var getCalendar = function getCalendar(value, calendarColorStyleCalendar, valueDateName) {
246
279
  return /*#__PURE__*/_react.default.createElement(_calendar.default, {
247
280
  currentDate: value !== undefined ? (0, _moment.default)(value) : (0, _moment.default)(),
248
281
  onDateChange: function onDateChange(date) {
249
282
  return setValue({
250
283
  target: {
251
- name: changingAux
284
+ name: valueDateName
252
285
  }
253
286
  }, date);
254
287
  },
@@ -257,12 +290,10 @@ var PeriodPicker = function PeriodPicker(props) {
257
290
  };
258
291
  var setPeriodDates = function setPeriodDates(selected, dates) {
259
292
  if (selected === 'custom') {
260
- var _inputInitialRef$curr2;
261
- (_inputInitialRef$curr2 = inputInitialRef.current) === null || _inputInitialRef$curr2 === void 0 ? void 0 : _inputInitialRef$curr2.focus();
293
+ var _inputInitialRef$curr3;
294
+ (_inputInitialRef$curr3 = inputInitialRef.current) === null || _inputInitialRef$curr3 === void 0 ? void 0 : _inputInitialRef$curr3.focus();
262
295
  setValuePeriodSelection(selected);
263
- setChanging('valueInitial');
264
296
  setShowPeriodSelection(false);
265
- setShowCalendar(true);
266
297
  return;
267
298
  }
268
299
  setValuePeriodSelection(selected);
@@ -274,16 +305,35 @@ var PeriodPicker = function PeriodPicker(props) {
274
305
  setShowPeriodSelection(false);
275
306
  }
276
307
  };
277
- var getWrapperComponentCalendar = function getWrapperComponentCalendar() {
278
- var value = changing === 'valueInitial' ? valueInitial : valueFinal;
308
+ var getWrapperComponentCalendarValueInitial = function getWrapperComponentCalendarValueInitial() {
309
+ if (onDenied && onDenied.readOnly) return null;
310
+ if (showCalendarInDialog) {
311
+ return /*#__PURE__*/_react.default.createElement(_Dialog.default, {
312
+ dialogSize: dialogSize,
313
+ handlerClose: function handlerClose() {
314
+ return setShowCalendarValueInitial(false);
315
+ }
316
+ }, getCalendar(valueInitial, calendarColorStyle, 'valueInitial'));
317
+ }
318
+ return /*#__PURE__*/_react.default.createElement(_Dropdown.default, {
319
+ targetElement: inputContainerRef.current,
320
+ topPosition: inputDimensions ? inputDimensions.top + inputDimensions.height + 5 : '',
321
+ leftPosition: inputDimensions ? inputDimensions.left : '',
322
+ width: inputDimensions ? inputDimensions.width : '',
323
+ dropdownRef: function dropdownRef(el) {
324
+ dropdownCalendarContainer.current = el;
325
+ }
326
+ }, getCalendar(valueInitial, calendarColorStyle, 'valueInitial'));
327
+ };
328
+ var getWrapperComponentCalendarValueFinal = function getWrapperComponentCalendarValueFinal() {
279
329
  if (onDenied && onDenied.readOnly) return null;
280
330
  if (showCalendarInDialog) {
281
331
  return /*#__PURE__*/_react.default.createElement(_Dialog.default, {
282
332
  dialogSize: dialogSize,
283
333
  handlerClose: function handlerClose() {
284
- return setShowCalendar(false);
334
+ return setShowCalendarValueFinal(false);
285
335
  }
286
- }, getCalendar(value, calendarColorStyle, changing));
336
+ }, getCalendar(valueFinal, calendarColorStyle, 'valueFinal'));
287
337
  }
288
338
  return /*#__PURE__*/_react.default.createElement(_Dropdown.default, {
289
339
  targetElement: inputContainerRef.current,
@@ -293,7 +343,7 @@ var PeriodPicker = function PeriodPicker(props) {
293
343
  dropdownRef: function dropdownRef(el) {
294
344
  dropdownCalendarContainer.current = el;
295
345
  }
296
- }, getCalendar(value, calendarColorStyle, changing));
346
+ }, getCalendar(valueFinal, calendarColorStyle, 'valueFinal'));
297
347
  };
298
348
  var getWrapperComponentPeriodSelection = function getWrapperComponentPeriodSelection() {
299
349
  if (showCalendarInDialog) {
@@ -316,6 +366,7 @@ var PeriodPicker = function PeriodPicker(props) {
316
366
  };
317
367
  if (onDenied && onDenied.unvisible) return null;
318
368
  return /*#__PURE__*/_react.default.createElement("div", {
369
+ ref: wrapperBaseInputPeriodRef,
319
370
  className: "input-base-component"
320
371
  }, props.label && /*#__PURE__*/_react.default.createElement("div", {
321
372
  className: "labelcontainer"
@@ -335,13 +386,16 @@ var PeriodPicker = function PeriodPicker(props) {
335
386
  value: !valueInitial ? '' : (0, _moment.default)(valueInitial).format('DD/MM/YYYY'),
336
387
  mask: "00/00/0000",
337
388
  onComplete: function onComplete(e, date) {
338
- setValue(e, date, false);
389
+ setValue(e, date, true);
339
390
  },
340
391
  onFocus: onInputFocus,
392
+ onBlur: function onBlur(e) {
393
+ return onInputBlur(e);
394
+ },
341
395
  isDateField: true,
342
396
  onChange: onInputChange,
343
397
  inputRef: function inputRef(el) {
344
- if (el) inputInitialRef.current = el;
398
+ inputInitialRef.current = el;
345
399
  },
346
400
  handlerSetOnDenied: function handlerSetOnDenied(denied) {
347
401
  setOnDenied(denied);
@@ -357,9 +411,12 @@ var PeriodPicker = function PeriodPicker(props) {
357
411
  mask: "00/00/0000",
358
412
  isDateField: true,
359
413
  onComplete: function onComplete(e, date) {
360
- setValue(e, date, false);
414
+ setValue(e, date, true);
361
415
  },
362
416
  onFocus: onInputFocus,
417
+ onBlur: function onBlur(e) {
418
+ return onInputBlur(e);
419
+ },
363
420
  onChange: onInputChange,
364
421
  inputRef: function inputRef(el) {
365
422
  inputFinalRef.current = el;
@@ -368,7 +425,11 @@ var PeriodPicker = function PeriodPicker(props) {
368
425
  return setOnDenied(denied);
369
426
  },
370
427
  required: props.required
371
- }), getButtonOpen(), getButtonSelectPeriod()), showCalendar && getWrapperComponentCalendar(), showPeriodSelection && getWrapperComponentPeriodSelection(), props.errorMessages && helperBase.getErrorMessages(props.errorMessages));
428
+ }), getButtonOpen(), getButtonSelectPeriod()), showCalendarValueInitial && getWrapperComponentCalendarValueInitial(), showCalendarValueFinal && getWrapperComponentCalendarValueFinal(), showPeriodSelection && getWrapperComponentPeriodSelection(), /*#__PURE__*/_react.default.createElement(_hint.default, {
429
+ visible: !!hint,
430
+ customClass: "hint",
431
+ description: hint
432
+ }), props.errorMessages && helperBase.getErrorMessages(props.errorMessages));
372
433
  };
373
434
  var _default = PeriodPicker;
374
435
  exports.default = _default;
@@ -7,6 +7,12 @@ import { CustomInputEvent } from '../base/types.js';
7
7
  import '../../@types/Align.js';
8
8
 
9
9
  type DateTypes = 'today' | 'week' | 'lastweek' | 'last15' | 'month' | 'lastmonth';
10
+ interface ChangeInputPeriodEvent {
11
+ target: {
12
+ value?: string;
13
+ name?: string;
14
+ };
15
+ }
10
16
  interface IPeriodOptions {
11
17
  id: DateTypes | 'custom';
12
18
  label?: string;
@@ -50,10 +56,13 @@ interface IPeriodPickerProps {
50
56
  permissionAttr?: PermissionAttr;
51
57
  errorMessages?: string[];
52
58
  name?: string;
59
+ hint?: string;
60
+ onBlur?: (e: CustomInputEvent) => void;
61
+ onFocus?: (e: CustomInputEvent) => void;
53
62
  }
54
63
  interface IPeriodListProps {
55
64
  handleOnSelect: (value: DateTypes | 'custom', date: Moment[] | null) => void;
56
65
  selected?: string;
57
66
  }
58
67
 
59
- export { DateTypes, IDialogProps, IPeriodDropdownProps, IPeriodListProps, IPeriodOptions, IPeriodPickerProps };
68
+ export { ChangeInputPeriodEvent, DateTypes, IDialogProps, IPeriodDropdownProps, IPeriodListProps, IPeriodOptions, IPeriodPickerProps };
@@ -1,4 +1,4 @@
1
- import { a as IPanelContentProps } from '../types-fe4a1068.js';
1
+ import { a as IPanelContentProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -13,6 +13,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
15
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
16
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
17
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
18
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
16
19
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
20
  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; }
18
21
  var PanelContent = function PanelContent(_ref) {
@@ -26,35 +29,55 @@ var PanelContent = function PanelContent(_ref) {
26
29
  onEndReachedThreshold = _useContext$onEndReac === void 0 ? 0.1 : _useContext$onEndReac,
27
30
  hideContent = _useContext.hideContent;
28
31
  var rootElementRef = (0, _react.useRef)(null);
29
- var enableOnEndReached = (0, _react.useRef)(true);
30
32
  var lastScrollHeight = (0, _react.useRef)(0);
31
- var onScrollEndReached = (0, _react.useCallback)(function () {
32
- var element = rootElementRef.current;
33
- if (element && onEndReached) {
34
- var scrollTop = element.scrollTop,
35
- scrollHeight = element.scrollHeight,
36
- clientHeight = element.clientHeight;
37
- var scrollOffset = scrollHeight - clientHeight - scrollTop - 1;
38
- var threshold = (0, _helpers.getCurrentThreshold)(element, onEndReachedThreshold);
39
- if (scrollOffset <= threshold && enableOnEndReached.current) {
40
- onEndReached();
41
- lastScrollHeight.current = scrollHeight;
42
- if (lastScrollHeight.current === scrollHeight) enableOnEndReached.current = false;
43
- } else if (scrollOffset > threshold && !enableOnEndReached.current) {
44
- enableOnEndReached.current = true;
33
+ var enableOnEndReached = (0, _react.useRef)(true);
34
+ var onScrollEndReached = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
35
+ var element, scrollTop, scrollHeight, clientHeight, scrollOffset, threshold;
36
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
37
+ while (1) switch (_context.prev = _context.next) {
38
+ case 0:
39
+ element = rootElementRef.current;
40
+ if (!(element && onEndReached)) {
41
+ _context.next = 10;
42
+ break;
43
+ }
44
+ scrollTop = element.scrollTop, scrollHeight = element.scrollHeight, clientHeight = element.clientHeight;
45
+ scrollOffset = scrollHeight - clientHeight - scrollTop - 1;
46
+ threshold = (0, _helpers.getCurrentThreshold)(element, onEndReachedThreshold);
47
+ if (!(scrollOffset <= threshold && enableOnEndReached.current)) {
48
+ _context.next = 10;
49
+ break;
50
+ }
51
+ enableOnEndReached.current = false;
52
+ _context.next = 9;
53
+ return new Promise(function (resolve) {
54
+ resolve(onEndReached());
55
+ });
56
+ case 9:
57
+ lastScrollHeight.current = scrollHeight;
58
+ case 10:
59
+ case "end":
60
+ return _context.stop();
45
61
  }
46
- }
47
- }, [onEndReached, onEndReachedThreshold, enableOnEndReached.current, rootElementRef.current, lastScrollHeight.current]);
62
+ }, _callee);
63
+ })), [onEndReached, onEndReachedThreshold, rootElementRef.current, lastScrollHeight.current]);
48
64
  (0, _react.useEffect)(function () {
49
- if (onEndReached) {
50
- var _rootElementRef$curre, _rootElementRef$curre2;
51
- (_rootElementRef$curre = rootElementRef.current) === null || _rootElementRef$curre === void 0 ? void 0 : _rootElementRef$curre.addEventListener('scroll', onScrollEndReached);
52
- (_rootElementRef$curre2 = rootElementRef.current) === null || _rootElementRef$curre2 === void 0 ? void 0 : _rootElementRef$curre2.addEventListener('resize', onScrollEndReached);
65
+ if (rootElementRef.current && onEndReached) {
66
+ var observer = new ResizeObserver(function () {
67
+ var _ref3 = rootElementRef.current,
68
+ scrollHeight = _ref3.scrollHeight;
69
+ if (scrollHeight !== lastScrollHeight.current) {
70
+ enableOnEndReached.current = true;
71
+ }
72
+ });
73
+ observer.observe(rootElementRef.current);
74
+ rootElementRef.current.addEventListener('scroll', onScrollEndReached);
75
+ rootElementRef.current.addEventListener('resize', onScrollEndReached);
53
76
  }
54
77
  return function () {
55
- var _rootElementRef$curre3, _rootElementRef$curre4;
56
- (_rootElementRef$curre3 = rootElementRef.current) === null || _rootElementRef$curre3 === void 0 ? void 0 : _rootElementRef$curre3.removeEventListener('scroll', onScrollEndReached);
57
- (_rootElementRef$curre4 = rootElementRef.current) === null || _rootElementRef$curre4 === void 0 ? void 0 : _rootElementRef$curre4.removeEventListener('resize', onScrollEndReached);
78
+ var _rootElementRef$curre, _rootElementRef$curre2;
79
+ (_rootElementRef$curre = rootElementRef.current) === null || _rootElementRef$curre === void 0 ? void 0 : _rootElementRef$curre.removeEventListener('scroll', onScrollEndReached);
80
+ (_rootElementRef$curre2 = rootElementRef.current) === null || _rootElementRef$curre2 === void 0 ? void 0 : _rootElementRef$curre2.removeEventListener('resize', onScrollEndReached);
58
81
  };
59
82
  }, [onScrollEndReached]);
60
83
  if (!opened) return null;
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { b as IPanelHeaderProps } from '../types-fe4a1068.js';
1
+ import { b as IPanelHeaderProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,4 +1,4 @@
1
- import { I as IPanelProps } from '../types-fe4a1068.js';
1
+ import { I as IPanelProps } from '../types-b7be23b5.js';
2
2
  import 'react';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
@@ -1,5 +1,5 @@
1
1
  import 'react';
2
- export { P as default, g as getCurrentThreshold, n as numberAroundZeroAndOne } from '../types-fe4a1068.js';
2
+ export { P as default, g as getCurrentThreshold, n as numberAroundZeroAndOne } from '../types-b7be23b5.js';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
5
5
  import '../@types/Icon.js';
@@ -6,7 +6,7 @@ export { default as SuccessPanel } from './SuccessPanel.js';
6
6
  export { default as InfoPanel } from './InfoPanel.js';
7
7
  export { default as PanelHeader } from './Header.js';
8
8
  export { default as PanelContent } from './Content.js';
9
- import '../types-fe4a1068.js';
9
+ import '../types-b7be23b5.js';
10
10
  import 'react';
11
11
  import '../@types/PermissionAttr.js';
12
12
  import '../internals/colorStyles.js';
@@ -1,5 +1,5 @@
1
1
  import 'react';
2
- export { C as ContextProps, a as IPanelContentProps, b as IPanelHeaderProps, I as IPanelProps, c as IParameterFunction } from '../types-fe4a1068.js';
2
+ export { A as AsyncFunc, C as ContextProps, F as Func, a as IPanelContentProps, b as IPanelHeaderProps, I as IPanelProps, c as IParameterFunction } from '../types-b7be23b5.js';
3
3
  import '../@types/PermissionAttr.js';
4
4
  import '../internals/colorStyles.js';
5
5
  import '../@types/Icon.js';
@@ -7,6 +7,8 @@ declare function numberAroundZeroAndOne({ props, propName, componentName }: IPar
7
7
  declare function getCurrentThreshold(element: HTMLDivElement, threshold: number): number;
8
8
  declare const PanelContext: React__default.Context<ContextProps>;
9
9
 
10
+ type Func = () => void;
11
+ type AsyncFunc = () => Promise<void>;
10
12
  interface IPanelProps extends Omit<ComponentPropsWithoutRef<'div'>, 'className'> {
11
13
  customClass?: string;
12
14
  startOpened?: boolean;
@@ -15,7 +17,7 @@ interface IPanelProps extends Omit<ComponentPropsWithoutRef<'div'>, 'className'>
15
17
  colorStyle?: typeof ColorStyles | string;
16
18
  gridCols?: string;
17
19
  title?: string;
18
- onEndReached?: () => void;
20
+ onEndReached?: Func | AsyncFunc;
19
21
  onEndReachedThreshold?: typeof numberAroundZeroAndOne | number;
20
22
  permissionAttr?: PermissionAttr | PermissionAttr[];
21
23
  }
@@ -36,7 +38,7 @@ type ContextProps = {
36
38
  handlerToggleable: () => void;
37
39
  opened: boolean;
38
40
  hideContent: boolean;
39
- onEndReached?: () => void;
41
+ onEndReached?: Func | AsyncFunc;
40
42
  onEndReachedThreshold: number;
41
43
  };
42
44
  interface IParameterFunction {
@@ -45,4 +47,4 @@ interface IParameterFunction {
45
47
  componentName: string;
46
48
  }
47
49
 
48
- export { ContextProps as C, IPanelProps as I, PanelContext as P, IPanelContentProps as a, IPanelHeaderProps as b, IParameterFunction as c, getCurrentThreshold as g, numberAroundZeroAndOne as n };
50
+ export { AsyncFunc as A, ContextProps as C, Func as F, IPanelProps as I, PanelContext as P, IPanelContentProps as a, IPanelHeaderProps as b, IParameterFunction as c, getCurrentThreshold as g, numberAroundZeroAndOne as n };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "1.0.14-beta.3",
3
+ "version": "1.0.15-rc.0",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.cjs",