argous 1.2.157 → 1.2.160

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.
@@ -31,13 +31,9 @@ export interface ArgousComplexTableProps extends ArgousComplexTableBodyProps, Ar
31
31
  */
32
32
  footerProps?: object,
33
33
  /**
34
- * Array de dados fornecido para a tabela
34
+ * Array de dados fornecido paa a tabela
35
35
  */
36
36
  dados?: Array<Array<any> | Object>,
37
- /**
38
- * Objeto com parâmetros para controle de paginação pelo backend
39
- */
40
- paginationControl?: Object,
41
37
  /**
42
38
  * Número de linhas padrão por página
43
39
  */
@@ -239,8 +239,9 @@ var ListboxFavorites = react_1.forwardRef(function (props, ref) {
239
239
  }
240
240
  function retornaEstrutura(sectionIndex, item, itemIndex) {
241
241
  var _a;
242
+ var index = itemIndex ? itemIndex : sectionIndex;
242
243
  var content = react_1.default.createElement(exports.CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
243
- react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { id: 'listItem', key: item.key, className: clsx_1.default(classes.listItem, (_a = {}, _a[classes.hoverListItem] = cursor.index === itemIndex && cursor.page === pageNumber, _a)) }),
244
+ react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { id: 'listItem', key: item.key, className: clsx_1.default(classes.listItem, (_a = {}, _a[classes.hoverListItem] = (cursor === null || cursor === void 0 ? void 0 : cursor.index) === index && (cursor === null || cursor === void 0 ? void 0 : cursor.page) === pageNumber, _a)) }),
244
245
  react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText })));
245
246
  if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
246
247
  return react_1.default.createElement(core_1.Slide, { in: slide, direction: direction }, content);
@@ -274,41 +275,43 @@ var ListboxFavorites = react_1.forwardRef(function (props, ref) {
274
275
  return 'right';
275
276
  return 'left';
276
277
  }
277
- return react_1.default.createElement("ul", __assign({}, props, { className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }), children.map(function (section, sectionIndex) {
278
+ return react_1.default.createElement("ul", __assign({}, props, { id: 'listBox', className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }), children.map(function (section, sectionIndex) {
278
279
  var _a, _b, _c;
279
- return (react_1.default.createElement("ul", __assign({}, props, { className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }), group ?
280
+ return (group ?
280
281
  react_1.default.createElement(react_1.default.Fragment, null,
281
- react_1.default.createElement(core_1.ListSubheader, { className: classes.subHeader, style: { backgroundColor: groupHeaderColor === null || groupHeaderColor === void 0 ? void 0 : groupHeaderColor[sectionIndex], color: groupTitleColor === null || groupTitleColor === void 0 ? void 0 : groupTitleColor[sectionIndex] } },
282
- section.props.children[0].props.children,
283
- react_1.default.createElement(core_1.Fade, { in: sectionIndex === 0 && favoritePage && favoritosLength > 7 },
284
- react_1.default.createElement("div", { className: classes.divButton },
285
- react_1.default.createElement("div", { className: classes.areaButton },
286
- react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 1); }, className: clsx_1.default((_a = {}, _a[classes.buttonActive] = pageNumber === 1, _a), classes.button) }, "1")),
287
- react_1.default.createElement("div", { className: classes.areaButton },
288
- react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 2); }, className: clsx_1.default((_b = {}, _b[classes.buttonActive] = pageNumber === 2, _b), classes.button) }, "2")),
289
- favoritosLength > 14 &&
290
- react_1.default.createElement(react_1.default.Fragment, null,
291
- react_1.default.createElement("div", { className: classes.areaButton },
292
- react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 3); }, className: clsx_1.default((_c = {}, _c[classes.buttonActive] = pageNumber === 3, _c), classes.button) }, "3")))))),
293
- retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item, itemIndex); }))
294
- : retornaEstrutura(sectionIndex, section)));
282
+ react_1.default.createElement("ul", __assign({}, props, { id: 'listBox', className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }),
283
+ react_1.default.createElement(core_1.ListSubheader, { className: classes.subHeader, style: { backgroundColor: groupHeaderColor === null || groupHeaderColor === void 0 ? void 0 : groupHeaderColor[sectionIndex], color: groupTitleColor === null || groupTitleColor === void 0 ? void 0 : groupTitleColor[sectionIndex] } },
284
+ section.props.children[0].props.children,
285
+ react_1.default.createElement(core_1.Fade, { in: sectionIndex === 0 && favoritePage && favoritosLength > 7 },
286
+ react_1.default.createElement("div", { className: classes.divButton },
287
+ react_1.default.createElement("div", { className: classes.areaButton },
288
+ react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 1); }, className: clsx_1.default((_a = {}, _a[classes.buttonActive] = pageNumber === 1, _a), classes.button) }, "1")),
289
+ react_1.default.createElement("div", { className: classes.areaButton },
290
+ react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 2); }, className: clsx_1.default((_b = {}, _b[classes.buttonActive] = pageNumber === 2, _b), classes.button) }, "2")),
291
+ favoritosLength > 14 &&
292
+ react_1.default.createElement(react_1.default.Fragment, null,
293
+ react_1.default.createElement("div", { className: classes.areaButton },
294
+ react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 3); }, className: clsx_1.default((_c = {}, _c[classes.buttonActive] = pageNumber === 3, _c), classes.button) }, "3")))))),
295
+ retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item, itemIndex); })))
296
+ : retornaEstrutura(sectionIndex, section));
295
297
  }));
296
298
  });
297
299
  var AutoCompleteFavorites = function (_a) {
298
- var action = _a.action, busca = _a.busca, resposta = _a.resposta, autoSearch = _a.autoSearch, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, group = _a.group, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, widthListBox = _a.widthListBox, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, _b = _a.onChange, onChange = _b === void 0 ? function (e) { return e; } : _b, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, searchParams = _a.searchParams, props = __rest(_a, ["action", "busca", "resposta", "autoSearch", "label", "value", "pgCode", "favoritePage", "group", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "widthListBox", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
300
+ var _b;
301
+ var action = _a.action, busca = _a.busca, resposta = _a.resposta, autoSearch = _a.autoSearch, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, _c = _a.group, group = _c === void 0 ? false : _c, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, widthListBox = _a.widthListBox, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, _e = _a.textFieldProps, textFieldProps = _e === void 0 ? {} : _e, searchParams = _a.searchParams, props = __rest(_a, ["action", "busca", "resposta", "autoSearch", "label", "value", "pgCode", "favoritePage", "group", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "widthListBox", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
299
302
  var classes = useStyles({ widthListBox: widthListBox });
300
- var _d = react_1.useState({
303
+ var _f = react_1.useState({
301
304
  lista: [],
302
305
  slide: true,
303
306
  cursor: { index: '', page: '' },
304
307
  direction: '',
305
308
  favoritosLength: '',
306
- pageNumber: favoritePage ? 1 : '',
307
- }), dados = _d[0], setDados = _d[1];
308
- var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
309
- var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
309
+ pageNumber: favoritePage ? 1 : undefined,
310
+ }), dados = _f[0], setDados = _f[1];
311
+ var _g = react_1.useState(false), loading = _g[0], setLoading = _g[1];
312
+ var _h = react_1.useState(''), inputValue = _h[0], setInputValue = _h[1];
310
313
  var interval = react_1.useRef(null);
311
- var _g = react_1.useState(1), seconds = _g[0], setSeconds = _g[1];
314
+ var _j = react_1.useState(1), seconds = _j[0], setSeconds = _j[1];
312
315
  var startCounter = function () { return interval.current = setInterval(function () { return setSeconds(1); }, 1000); };
313
316
  var stopCounter = function () {
314
317
  clearInterval(interval.current);
@@ -355,9 +358,7 @@ var AutoCompleteFavorites = function (_a) {
355
358
  return [3 /*break*/, 4];
356
359
  case 3:
357
360
  if (res[resposta || 'result'])
358
- setDados({ lista: res[resposta || 'result'] || [] });
359
- else
360
- api_1.setError('Erro ao tentar buscar dados.');
361
+ setDados(function (v) { return (__assign(__assign({}, v), { lista: res[resposta || 'result'] || [] })); });
361
362
  _c.label = 4;
362
363
  case 4:
363
364
  setLoading(false);
@@ -368,46 +369,104 @@ var AutoCompleteFavorites = function (_a) {
368
369
  react_1.useEffect(function () { return autoSearch && seconds === 1 && buscar(); }, [autoSearch, seconds, buscar]);
369
370
  // eslint-disable-next-line react-hooks/exhaustive-deps
370
371
  react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
371
- react_1.useEffect(function () { var _a; return (value === null || value === void 0 ? void 0 : value[3]) !== ((_a = dados.cursor.linha) === null || _a === void 0 ? void 0 : _a[3]) && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: '', page: '' } })); }); }, [value, dados.cursor.linha]);
372
- var keyUp = function (e) {
373
- e.preventDefault();
374
- e.stopPropagation();
372
+ react_1.useEffect(function () { var _a; return (value !== ((_a = dados.cursor) === null || _a === void 0 ? void 0 : _a.linha)) && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: '', page: '' } })); }); }, [value, (_b = dados.cursor) === null || _b === void 0 ? void 0 : _b.linha]);
373
+ var keyDown = function (e) {
375
374
  ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
376
375
  (e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
377
376
  };
378
- var keyDown = function (e) { return (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation(); };
377
+ var keyUp = function (e) { return (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation(); };
378
+ var numbersOnly = function (value) { return value.replace(/[^0-9]/g, ''); };
379
+ var getFinder = function (v) {
380
+ var _a;
381
+ var elInnerText = v.innerText;
382
+ var endIndexCode = elInnerText.indexOf('-') - 1;
383
+ var code = elInnerText.substring(0, endIndexCode);
384
+ var finder = ((_a = numbersOnly(code)) === null || _a === void 0 ? void 0 : _a.length) ? code : elInnerText;
385
+ return finder;
386
+ };
387
+ function validateLine(value, finder, el) {
388
+ var _a, _b, _c;
389
+ var retorno = false;
390
+ if (el) {
391
+ var elIndex = parseInt((_b = (_a = el === null || el === void 0 ? void 0 : el.attributes) === null || _a === void 0 ? void 0 : _a[4]) === null || _b === void 0 ? void 0 : _b.value);
392
+ var itemSelecionado = (_c = dados.lista) === null || _c === void 0 ? void 0 : _c[elIndex];
393
+ if (lodash_1.isObject(itemSelecionado))
394
+ retorno = JSON.stringify(value) === JSON.stringify(itemSelecionado) ? true : false;
395
+ else if (lodash_1.isArray(itemSelecionado))
396
+ retorno = value.equals(itemSelecionado) ? true : false;
397
+ }
398
+ else if (lodash_1.isArray(value)) {
399
+ value.forEach(function (v) {
400
+ if (retorno)
401
+ return;
402
+ if (v && v.toString() === finder)
403
+ retorno = true;
404
+ });
405
+ }
406
+ else if (lodash_1.isObject(value)) {
407
+ Object.values(value).forEach(function (v) {
408
+ if (retorno)
409
+ return;
410
+ if (v && v.toString() === finder)
411
+ retorno = true;
412
+ });
413
+ }
414
+ return retorno;
415
+ }
379
416
  function selectListboxItem(key) {
380
417
  var _a;
381
418
  var directionIndex = key === 'ArrowDown' ? 1 : key === 'ArrowUp' ? -1 : 0;
382
419
  var itens = document.querySelectorAll('#listItem');
383
420
  var array = Array.from(itens);
384
421
  var el = '';
422
+ var linha = '';
385
423
  var indexCapture = 0;
386
- if (!value)
387
- el = array === null || array === void 0 ? void 0 : array[0];
388
- else {
424
+ if (value) {
389
425
  array.forEach(function (v, i) {
390
- var elInnerText = v.innerText;
391
- var endIndexCode = elInnerText.indexOf('-') - 1;
392
- var code = elInnerText.substring(0, endIndexCode);
393
- if (code === value[3]) {
426
+ var finder = getFinder(v);
427
+ if (linha)
428
+ return;
429
+ if (validateLine(value, finder, v)) {
394
430
  var nextIndex = i + directionIndex;
395
431
  if (nextIndex < array.length)
396
432
  indexCapture = nextIndex > -1 ? nextIndex : i;
397
433
  else
398
434
  indexCapture = i;
435
+ linha = dados.lista[indexCapture];
399
436
  }
400
437
  });
401
438
  el = array[indexCapture];
402
439
  }
403
- var elInnerText = el.innerText;
404
- var endIndexCode = elInnerText.indexOf('-') - 1;
405
- var code = elInnerText.substring(0, endIndexCode);
406
- var linha = (_a = dados.lista.map(function (v) { return v[3] === code && v; }).filter(function (v) { return v && v; })) === null || _a === void 0 ? void 0 : _a[0];
407
- setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: indexCapture, page: v.pageNumber, linha: linha } })); });
440
+ if (!linha)
441
+ linha = dados.lista[indexCapture];
442
+ var elTop = 0;
443
+ var elTotalHeight = 0;
444
+ var lastScrollTop = 0;
445
+ var elListBox = document.getElementById('listBox');
446
+ if (el) {
447
+ elTop = (_a = el === null || el === void 0 ? void 0 : el.getBoundingClientRect()) === null || _a === void 0 ? void 0 : _a.top;
448
+ elTotalHeight = el.offsetHeight + el.offsetTop;
449
+ }
450
+ if (elListBox)
451
+ lastScrollTop = elListBox.scrollTop;
452
+ linha && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: indexCapture, page: v.pageNumber, linha: linha, elTop: elTop, elTotalHeight: elTotalHeight, lastScrollTop: lastScrollTop } })); });
408
453
  if (linha !== value)
409
454
  invokeOnChange('', linha);
410
455
  }
456
+ var scrollToSelected = react_1.useCallback(function () {
457
+ var _a, _b, _c, _d;
458
+ var elListBox = document.getElementById('listBox');
459
+ if (elListBox) {
460
+ var clientHeight = elListBox === null || elListBox === void 0 ? void 0 : elListBox.clientHeight;
461
+ if (clientHeight < ((_a = dados.cursor) === null || _a === void 0 ? void 0 : _a.elTotalHeight)) {
462
+ var valueScrollTop = ((_b = dados.cursor) === null || _b === void 0 ? void 0 : _b.elTop) - clientHeight;
463
+ if ((_c = dados.cursor) === null || _c === void 0 ? void 0 : _c.lastScrollTop)
464
+ valueScrollTop += (_d = dados.cursor) === null || _d === void 0 ? void 0 : _d.lastScrollTop;
465
+ elListBox.scrollTop = valueScrollTop;
466
+ }
467
+ }
468
+ }, [dados]);
469
+ react_1.useEffect(function () { var _a; return ((_a = dados.lista) === null || _a === void 0 ? void 0 : _a.length) && setTimeout(function () { return scrollToSelected(); }, 0); }, [dados.lista, scrollToSelected]);
411
470
  var invokeOnChange = onChange;
412
471
  return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value }, { onChange: invokeOnChange, autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, onInputChange: function (e) { var _a; return setInput(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { onKeyUp: function (e) { return keyUp(e); }, inputProps: __assign(__assign({}, params.inputProps), { onKeyDown: function (e) { return keyDown(e); } }), InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
413
472
  params.InputProps.endAdornment,
@@ -31,13 +31,9 @@ export interface ArgousComplexTableProps extends ArgousComplexTableBodyProps, Ar
31
31
  */
32
32
  footerProps?: object,
33
33
  /**
34
- * Array de dados fornecido para a tabela
34
+ * Array de dados fornecido paa a tabela
35
35
  */
36
36
  dados?: Array<Array<any> | Object>,
37
- /**
38
- * Objeto com parâmetros para controle de paginação pelo backend
39
- */
40
- paginationControl?: Object,
41
37
  /**
42
38
  * Número de linhas padrão por página
43
39
  */
@@ -2,7 +2,7 @@ import { serverAction, setError } from '../../utils/api';
2
2
  import { CircularProgress, Fade, IconButton, ListItem, ListItemText, ListSubheader, makeStyles, Popper, Slide, TextField, Tooltip, withStyles } from '@material-ui/core';
3
3
  import { Autocomplete } from '@material-ui/lab';
4
4
  import clsx from 'clsx';
5
- import { isObject, isString } from 'lodash';
5
+ import { isArray, isObject, isString } from 'lodash';
6
6
  import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
7
7
  import { IoIosSearch } from 'react-icons/io';
8
8
 
@@ -133,7 +133,7 @@ const ListboxFavorites = forwardRef((props, ref) => {
133
133
 
134
134
  function retornaInicio() {
135
135
  switch (pageNumber) {
136
- case 1:
136
+ case 1:
137
137
  return 0;
138
138
  case 2:
139
139
  return 7;
@@ -161,8 +161,9 @@ const ListboxFavorites = forwardRef((props, ref) => {
161
161
  }
162
162
 
163
163
  function retornaEstrutura(sectionIndex, item, itemIndex) {
164
+ const index = itemIndex ? itemIndex : sectionIndex;
164
165
  const content = <CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
165
- <ListItem {...item.props} id='listItem' key={item.key} className={clsx(classes.listItem, { [classes.hoverListItem]: cursor.index === itemIndex && cursor.page === pageNumber })}>
166
+ <ListItem {...item.props} id='listItem' key={item.key} className={clsx(classes.listItem, { [classes.hoverListItem]: cursor?.index === index && cursor?.page === pageNumber })}>
166
167
  <ListItemText primary={item.props.children} className={classes.listItemText} />
167
168
  </ListItem>
168
169
  </CustomTooltip>;
@@ -199,41 +200,39 @@ const ListboxFavorites = forwardRef((props, ref) => {
199
200
  return 'left';
200
201
  }
201
202
 
202
- return <ul {...props} className={clsx('MuiAutocomplete-listbox', classes.box)}>
203
- {children.map((section, sectionIndex) => (
204
- <ul {...props} className={clsx('MuiAutocomplete-listbox', classes.box)}>
205
- {group ?
206
- <React.Fragment>
207
- <ListSubheader className={classes.subHeader} style={{ backgroundColor: groupHeaderColor?.[sectionIndex], color: groupTitleColor?.[sectionIndex] }}>
208
- {section.props.children[0].props.children}
209
- <Fade in={sectionIndex === 0 && favoritePage && favoritosLength > 7}>
210
- <div className={classes.divButton}>
211
- <div className={classes.areaButton}>
212
- <div onClick={e => buttonClick(e, 1)} className={clsx({ [classes.buttonActive]: pageNumber === 1 }, classes.button)}>1</div>
213
- </div>
214
- <div className={classes.areaButton}>
215
- <div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
216
- </div>
217
- {favoritosLength > 14 &&
218
- <React.Fragment>
219
- <div className={classes.areaButton}>
220
- <div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
221
- </div>
222
- </React.Fragment>
223
- }
203
+ return <ul {...props} id='listBox' className={clsx('MuiAutocomplete-listbox', classes.box)}>
204
+ {children.map((section, sectionIndex) => (group ?
205
+ <React.Fragment>
206
+ <ul {...props} id='listBox' className={clsx('MuiAutocomplete-listbox', classes.box)}>
207
+ <ListSubheader className={classes.subHeader} style={{ backgroundColor: groupHeaderColor?.[sectionIndex], color: groupTitleColor?.[sectionIndex] }}>
208
+ {section.props.children[0].props.children}
209
+ <Fade in={sectionIndex === 0 && favoritePage && favoritosLength > 7}>
210
+ <div className={classes.divButton}>
211
+ <div className={classes.areaButton}>
212
+ <div onClick={e => buttonClick(e, 1)} className={clsx({ [classes.buttonActive]: pageNumber === 1 }, classes.button)}>1</div>
224
213
  </div>
225
- </Fade>
226
- </ListSubheader>
227
- {retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item, itemIndex))}
228
- </React.Fragment>
229
- : retornaEstrutura(sectionIndex, section)
230
- }
231
- </ul>
214
+ <div className={classes.areaButton}>
215
+ <div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
216
+ </div>
217
+ {favoritosLength > 14 &&
218
+ <React.Fragment>
219
+ <div className={classes.areaButton}>
220
+ <div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
221
+ </div>
222
+ </React.Fragment>
223
+ }
224
+ </div>
225
+ </Fade>
226
+ </ListSubheader>
227
+ {retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item, itemIndex))}
228
+ </ul>
229
+ </React.Fragment>
230
+ : retornaEstrutura(sectionIndex, section)
232
231
  ))}
233
232
  </ul>;
234
233
  });
235
234
 
236
- const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, value, pgCode, favoritePage, group, groupName, groupHeaderColor, groupTitleColor, loadingColor, widthListBox, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
235
+ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, value, pgCode, favoritePage, group = false, groupName, groupHeaderColor, groupTitleColor, loadingColor, widthListBox, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
237
236
 
238
237
  const classes = useStyles({ widthListBox });
239
238
  const [dados, setDados] = useState({
@@ -242,7 +241,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
242
241
  cursor: { index: '', page: '' },
243
242
  direction: '',
244
243
  favoritosLength: '',
245
- pageNumber: favoritePage ? 1 : '',
244
+ pageNumber: favoritePage ? 1 : undefined,
246
245
  });
247
246
  const [loading, setLoading] = useState(false);
248
247
  const [inputValue, setInputValue] = useState('');
@@ -278,8 +277,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
278
277
  setLoading(true);
279
278
  const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
280
279
  if (res[resposta || 'result']?.length > 1 && group) await carimbaLista(res[resposta || 'result']);
281
- else if (res[resposta || 'result']) setDados({ lista: res[resposta || 'result'] || [] });
282
- else setError('Erro ao tentar buscar dados.');
280
+ else if (res[resposta || 'result']) setDados(v => ({ ...v, lista: res[resposta || 'result'] || [] }));
283
281
  setLoading(false);
284
282
  // eslint-disable-next-line react-hooks/exhaustive-deps
285
283
  }, [inputValue, searchParams]);
@@ -288,45 +286,98 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
288
286
  // eslint-disable-next-line react-hooks/exhaustive-deps
289
287
  useEffect(() => isString(value) && buscar(value), []);
290
288
 
291
- useEffect(() => value?.[3] !== dados.cursor.linha?.[3] && setDados(v => ({ ...v, cursor: { index: '', page: '' } })), [value, dados.cursor.linha]);
289
+ useEffect(() => (value !== dados.cursor?.linha) && setDados(v => ({ ...v, cursor: { index: '', page: '' } })), [value, dados.cursor?.linha]);
292
290
 
293
- const keyUp = e => {
294
- e.preventDefault();
295
- e.stopPropagation();
291
+ const keyDown = e => {
296
292
  ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
297
293
  (e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
298
294
  };
299
295
 
300
- const keyDown = e => (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation();
296
+ const keyUp = e => (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation();
297
+
298
+ const numbersOnly = value => value.replace(/[^0-9]/g, '');
299
+
300
+ const getFinder = v => {
301
+ const elInnerText = v.innerText;
302
+ const endIndexCode = elInnerText.indexOf('-') - 1;
303
+ const code = elInnerText.substring(0, endIndexCode);
304
+ const finder = numbersOnly(code)?.length ? code : elInnerText;
305
+ return finder;
306
+ };
307
+
308
+ function validateLine(value, finder, el) {
309
+ let retorno = false;
310
+ if (el) {
311
+ const elIndex = parseInt(el?.attributes?.[4]?.value);
312
+ const itemSelecionado = dados.lista?.[elIndex];
313
+ if (isObject(itemSelecionado)) retorno = JSON.stringify(value) === JSON.stringify(itemSelecionado) ? true : false;
314
+ else if (isArray(itemSelecionado)) retorno = value.equals(itemSelecionado) ? true : false;
315
+ } else if (isArray(value)) {
316
+ value.forEach(v => {
317
+ if (retorno) return;
318
+ if (v && v.toString() === finder) retorno = true;
319
+ });
320
+ } else if (isObject(value)) {
321
+ Object.values(value).forEach(v => {
322
+ if (retorno) return;
323
+ if (v && v.toString() === finder) retorno = true;
324
+ });
325
+ }
326
+ return retorno;
327
+ }
301
328
 
302
329
  function selectListboxItem(key) {
303
330
  const directionIndex = key === 'ArrowDown' ? 1 : key === 'ArrowUp' ? -1 : 0;
304
331
  const itens = document.querySelectorAll('#listItem');
305
332
  const array = Array.from(itens);
333
+
306
334
  let el = '';
335
+ let linha = '';
307
336
  let indexCapture = 0;
308
- if (!value) el = array?.[0];
309
- else {
337
+
338
+ if (value) {
310
339
  array.forEach((v, i) => {
311
- const elInnerText = v.innerText;
312
- const endIndexCode = elInnerText.indexOf('-') - 1;
313
- const code = elInnerText.substring(0, endIndexCode);
314
- if (code === value[3]) {
340
+ const finder = getFinder(v);
341
+ if (linha) return;
342
+ if (validateLine(value, finder, v)) {
315
343
  const nextIndex = i + directionIndex;
316
344
  if (nextIndex < array.length) indexCapture = nextIndex > -1 ? nextIndex : i;
317
345
  else indexCapture = i;
318
- }
346
+ linha = dados.lista[indexCapture];
347
+ }
319
348
  });
320
349
  el = array[indexCapture];
321
350
  }
322
- const elInnerText = el.innerText;
323
- const endIndexCode = elInnerText.indexOf('-') - 1;
324
- const code = elInnerText.substring(0, endIndexCode);
325
- const linha = dados.lista.map(v => v[3] === code && v).filter(v => v && v)?.[0];
326
- setDados(v => ({ ...v, cursor: { index: indexCapture, page: v.pageNumber, linha: linha } }));
351
+ if (!linha)linha = dados.lista[indexCapture];
352
+
353
+ let elTop = 0;
354
+ let elTotalHeight = 0;
355
+ let lastScrollTop = 0;
356
+ const elListBox = document.getElementById('listBox');
357
+
358
+ if (el) {
359
+ elTop = el?.getBoundingClientRect()?.top;
360
+ elTotalHeight = el.offsetHeight + el.offsetTop;
361
+ }
362
+ if (elListBox) lastScrollTop = elListBox.scrollTop;
363
+
364
+ linha && setDados(v => ({ ...v, cursor: { index: indexCapture, page: v.pageNumber, linha: linha, elTop: elTop, elTotalHeight: elTotalHeight, lastScrollTop: lastScrollTop } }));
327
365
  if (linha !== value) invokeOnChange('', linha);
328
366
  }
329
-
367
+
368
+ const scrollToSelected = useCallback(() => {
369
+ const elListBox = document.getElementById('listBox');
370
+ if (elListBox) {
371
+ const clientHeight = elListBox?.clientHeight;
372
+ if (clientHeight < dados.cursor?.elTotalHeight) {
373
+ let valueScrollTop = dados.cursor?.elTop - clientHeight;
374
+ if (dados.cursor?.lastScrollTop) valueScrollTop += dados.cursor?.lastScrollTop;
375
+ elListBox.scrollTop = valueScrollTop;
376
+ }
377
+ }
378
+ }, [dados]);
379
+ useEffect(() => dados.lista?.length && setTimeout(() => scrollToSelected(), 0), [dados.lista, scrollToSelected]);
380
+
330
381
  const invokeOnChange = onChange;
331
382
 
332
383
  return (
@@ -338,7 +389,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
338
389
  autoHighlight
339
390
  openText='Abrir'
340
391
  clearText='Limpar'
341
- filterSelectedOptions
392
+ filterSelectedOptions
342
393
  onInputChange={e => setInput(e?.target?.value || '')}
343
394
  getOptionSelected={(o, v) => o[0] === v}
344
395
  getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argous",
3
- "version": "1.2.157",
3
+ "version": "1.2.160",
4
4
  "description": "Argous.",
5
5
  "main": "lib/index.js",
6
6
  "author": "Carlos Schneider",