argous 1.2.158 → 1.2.159

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.
@@ -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 === null || cursor === void 0 ? void 0 : cursor.index) === itemIndex ? itemIndex : sectionIndex && (cursor === null || cursor === void 0 ? void 0 : 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,42 +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
300
  var _b;
299
- 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, _c = _a.onChange, onChange = _c === void 0 ? function (e) { return e; } : _c, _d = _a.textFieldProps, textFieldProps = _d === void 0 ? {} : _d, 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"]);
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"]);
300
302
  var classes = useStyles({ widthListBox: widthListBox });
301
- var _e = react_1.useState({
303
+ var _f = react_1.useState({
302
304
  lista: [],
303
305
  slide: true,
304
306
  cursor: { index: '', page: '' },
305
307
  direction: '',
306
308
  favoritosLength: '',
307
309
  pageNumber: favoritePage ? 1 : undefined,
308
- }), dados = _e[0], setDados = _e[1];
309
- var _f = react_1.useState(false), loading = _f[0], setLoading = _f[1];
310
- var _g = react_1.useState(''), inputValue = _g[0], setInputValue = _g[1];
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];
311
313
  var interval = react_1.useRef(null);
312
- var _h = react_1.useState(1), seconds = _h[0], setSeconds = _h[1];
314
+ var _j = react_1.useState(1), seconds = _j[0], setSeconds = _j[1];
313
315
  var startCounter = function () { return interval.current = setInterval(function () { return setSeconds(1); }, 1000); };
314
316
  var stopCounter = function () {
315
317
  clearInterval(interval.current);
@@ -356,7 +358,7 @@ var AutoCompleteFavorites = function (_a) {
356
358
  return [3 /*break*/, 4];
357
359
  case 3:
358
360
  if (res[resposta || 'result'])
359
- setDados({ lista: res[resposta || 'result'] || [] });
361
+ setDados(function (v) { return (__assign(__assign({}, v), { lista: res[resposta || 'result'] || [] })); });
360
362
  else
361
363
  api_1.setError('Erro ao tentar buscar dados.');
362
364
  _c.label = 4;
@@ -369,46 +371,106 @@ var AutoCompleteFavorites = function (_a) {
369
371
  react_1.useEffect(function () { return autoSearch && seconds === 1 && buscar(); }, [autoSearch, seconds, buscar]);
370
372
  // eslint-disable-next-line react-hooks/exhaustive-deps
371
373
  react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
372
- react_1.useEffect(function () { var _a, _b; return (value === null || value === void 0 ? void 0 : value[3]) !== ((_b = (_a = dados.cursor) === null || _a === void 0 ? void 0 : _a.linha) === null || _b === void 0 ? void 0 : _b[3]) && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: '', page: '' } })); }); }, [value, (_b = dados.cursor) === null || _b === void 0 ? void 0 : _b.linha]);
373
- var keyUp = function (e) {
374
+ 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]);
375
+ var keyDown = function (e) {
374
376
  e.preventDefault();
375
377
  e.stopPropagation();
376
378
  ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
377
379
  (e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
378
380
  };
379
- var keyDown = function (e) { return (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation(); };
381
+ var keyUp = function (e) { return (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation(); };
382
+ var numbersOnly = function (value) { return value.replace(/[^0-9]/g, ''); };
383
+ var getFinder = function (v) {
384
+ var _a;
385
+ var elInnerText = v.innerText;
386
+ var endIndexCode = elInnerText.indexOf('-') - 1;
387
+ var code = elInnerText.substring(0, endIndexCode);
388
+ var finder = ((_a = numbersOnly(code)) === null || _a === void 0 ? void 0 : _a.length) ? code : elInnerText;
389
+ return finder;
390
+ };
391
+ function validateLine(value, finder, el) {
392
+ var _a, _b, _c;
393
+ var retorno = false;
394
+ if (el) {
395
+ 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);
396
+ var itemSelecionado = (_c = dados.lista) === null || _c === void 0 ? void 0 : _c[elIndex];
397
+ if (lodash_1.isObject(itemSelecionado))
398
+ retorno = JSON.stringify(value) === JSON.stringify(itemSelecionado) ? true : false;
399
+ else if (lodash_1.isArray(itemSelecionado))
400
+ retorno = value.equals(itemSelecionado) ? true : false;
401
+ }
402
+ else if (lodash_1.isArray(value)) {
403
+ value.forEach(function (v) {
404
+ if (retorno)
405
+ return;
406
+ if (v && v.toString() === finder)
407
+ retorno = true;
408
+ });
409
+ }
410
+ else if (lodash_1.isObject(value)) {
411
+ Object.values(value).forEach(function (v) {
412
+ if (retorno)
413
+ return;
414
+ if (v && v.toString() === finder)
415
+ retorno = true;
416
+ });
417
+ }
418
+ return retorno;
419
+ }
380
420
  function selectListboxItem(key) {
381
421
  var _a;
382
422
  var directionIndex = key === 'ArrowDown' ? 1 : key === 'ArrowUp' ? -1 : 0;
383
423
  var itens = document.querySelectorAll('#listItem');
384
424
  var array = Array.from(itens);
385
425
  var el = '';
426
+ var linha = '';
386
427
  var indexCapture = 0;
387
- if (!value)
388
- el = array === null || array === void 0 ? void 0 : array[0];
389
- else {
428
+ if (value) {
390
429
  array.forEach(function (v, i) {
391
- var elInnerText = v.innerText;
392
- var endIndexCode = elInnerText.indexOf('-') - 1;
393
- var code = elInnerText.substring(0, endIndexCode);
394
- if (code === value[3]) {
430
+ var finder = getFinder(v);
431
+ if (linha)
432
+ return;
433
+ if (validateLine(value, finder, v)) {
395
434
  var nextIndex = i + directionIndex;
396
435
  if (nextIndex < array.length)
397
436
  indexCapture = nextIndex > -1 ? nextIndex : i;
398
437
  else
399
438
  indexCapture = i;
439
+ linha = dados.lista[indexCapture];
400
440
  }
401
441
  });
402
442
  el = array[indexCapture];
403
443
  }
404
- var elInnerText = el.innerText;
405
- var endIndexCode = elInnerText.indexOf('-') - 1;
406
- var code = elInnerText.substring(0, endIndexCode);
407
- 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];
408
- setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: indexCapture, page: v.pageNumber, linha: linha } })); });
444
+ if (!linha)
445
+ linha = dados.lista[indexCapture];
446
+ var elTop = 0;
447
+ var elTotalHeight = 0;
448
+ var lastScrollTop = 0;
449
+ var elListBox = document.getElementById('listBox');
450
+ if (el) {
451
+ elTop = (_a = el === null || el === void 0 ? void 0 : el.getBoundingClientRect()) === null || _a === void 0 ? void 0 : _a.top;
452
+ elTotalHeight = el.offsetHeight + el.offsetTop;
453
+ }
454
+ if (elListBox)
455
+ lastScrollTop = elListBox.scrollTop;
456
+ linha && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: indexCapture, page: v.pageNumber, linha: linha, elTop: elTop, elTotalHeight: elTotalHeight, lastScrollTop: lastScrollTop } })); });
409
457
  if (linha !== value)
410
458
  invokeOnChange('', linha);
411
459
  }
460
+ var scrollToSelected = react_1.useCallback(function () {
461
+ var _a, _b, _c, _d;
462
+ var elListBox = document.getElementById('listBox');
463
+ if (elListBox) {
464
+ var clientHeight = elListBox === null || elListBox === void 0 ? void 0 : elListBox.clientHeight;
465
+ if (clientHeight < ((_a = dados.cursor) === null || _a === void 0 ? void 0 : _a.elTotalHeight)) {
466
+ var valueScrollTop = ((_b = dados.cursor) === null || _b === void 0 ? void 0 : _b.elTop) - clientHeight;
467
+ if ((_c = dados.cursor) === null || _c === void 0 ? void 0 : _c.lastScrollTop)
468
+ valueScrollTop += (_d = dados.cursor) === null || _d === void 0 ? void 0 : _d.lastScrollTop;
469
+ elListBox.scrollTop = valueScrollTop;
470
+ }
471
+ }
472
+ }, [dados]);
473
+ 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]);
412
474
  var invokeOnChange = onChange;
413
475
  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,
414
476
  params.InputProps.endAdornment,
@@ -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 ? itemIndex : sectionIndex && 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({
@@ -278,7 +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'] || [] });
280
+ else if (res[resposta || 'result']) setDados(v => ({ ...v, lista: res[resposta || 'result'] || [] }));
282
281
  else setError('Erro ao tentar buscar dados.');
283
282
  setLoading(false);
284
283
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -288,45 +287,100 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
288
287
  // eslint-disable-next-line react-hooks/exhaustive-deps
289
288
  useEffect(() => isString(value) && buscar(value), []);
290
289
 
291
- useEffect(() => value?.[3] !== dados.cursor?.linha?.[3] && setDados(v => ({ ...v, cursor: { index: '', page: '' } })), [value, dados.cursor?.linha]);
290
+ useEffect(() => (value !== dados.cursor?.linha) && setDados(v => ({ ...v, cursor: { index: '', page: '' } })), [value, dados.cursor?.linha]);
292
291
 
293
- const keyUp = e => {
292
+ const keyDown = e => {
294
293
  e.preventDefault();
295
294
  e.stopPropagation();
296
295
  ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
297
296
  (e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
298
297
  };
299
298
 
300
- const keyDown = e => (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation();
299
+ const keyUp = e => (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation();
300
+
301
+ const numbersOnly = value => value.replace(/[^0-9]/g, '');
302
+
303
+ const getFinder = v => {
304
+ const elInnerText = v.innerText;
305
+ const endIndexCode = elInnerText.indexOf('-') - 1;
306
+ const code = elInnerText.substring(0, endIndexCode);
307
+ const finder = numbersOnly(code)?.length ? code : elInnerText;
308
+ return finder;
309
+ };
310
+
311
+ function validateLine(value, finder, el) {
312
+ let retorno = false;
313
+ if (el) {
314
+ const elIndex = parseInt(el?.attributes?.[4]?.value);
315
+ const itemSelecionado = dados.lista?.[elIndex];
316
+ if (isObject(itemSelecionado)) retorno = JSON.stringify(value) === JSON.stringify(itemSelecionado) ? true : false;
317
+ else if (isArray(itemSelecionado)) retorno = value.equals(itemSelecionado) ? true : false;
318
+ } else if (isArray(value)) {
319
+ value.forEach(v => {
320
+ if (retorno) return;
321
+ if (v && v.toString() === finder) retorno = true;
322
+ });
323
+ } else if (isObject(value)) {
324
+ Object.values(value).forEach(v => {
325
+ if (retorno) return;
326
+ if (v && v.toString() === finder) retorno = true;
327
+ });
328
+ }
329
+ return retorno;
330
+ }
301
331
 
302
332
  function selectListboxItem(key) {
303
333
  const directionIndex = key === 'ArrowDown' ? 1 : key === 'ArrowUp' ? -1 : 0;
304
334
  const itens = document.querySelectorAll('#listItem');
305
335
  const array = Array.from(itens);
336
+
306
337
  let el = '';
338
+ let linha = '';
307
339
  let indexCapture = 0;
308
- if (!value) el = array?.[0];
309
- else {
340
+
341
+ if (value) {
310
342
  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]) {
343
+ const finder = getFinder(v);
344
+ if (linha) return;
345
+ if (validateLine(value, finder, v)) {
315
346
  const nextIndex = i + directionIndex;
316
347
  if (nextIndex < array.length) indexCapture = nextIndex > -1 ? nextIndex : i;
317
348
  else indexCapture = i;
318
- }
349
+ linha = dados.lista[indexCapture];
350
+ }
319
351
  });
320
352
  el = array[indexCapture];
321
353
  }
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 } }));
354
+ if (!linha)linha = dados.lista[indexCapture];
355
+
356
+ let elTop = 0;
357
+ let elTotalHeight = 0;
358
+ let lastScrollTop = 0;
359
+ const elListBox = document.getElementById('listBox');
360
+
361
+ if (el) {
362
+ elTop = el?.getBoundingClientRect()?.top;
363
+ elTotalHeight = el.offsetHeight + el.offsetTop;
364
+ }
365
+ if (elListBox) lastScrollTop = elListBox.scrollTop;
366
+
367
+ linha && setDados(v => ({ ...v, cursor: { index: indexCapture, page: v.pageNumber, linha: linha, elTop: elTop, elTotalHeight: elTotalHeight, lastScrollTop: lastScrollTop } }));
327
368
  if (linha !== value) invokeOnChange('', linha);
328
369
  }
329
-
370
+
371
+ const scrollToSelected = useCallback(() => {
372
+ const elListBox = document.getElementById('listBox');
373
+ if (elListBox) {
374
+ const clientHeight = elListBox?.clientHeight;
375
+ if (clientHeight < dados.cursor?.elTotalHeight) {
376
+ let valueScrollTop = dados.cursor?.elTop - clientHeight;
377
+ if (dados.cursor?.lastScrollTop) valueScrollTop += dados.cursor?.lastScrollTop;
378
+ elListBox.scrollTop = valueScrollTop;
379
+ }
380
+ }
381
+ }, [dados]);
382
+ useEffect(() => dados.lista?.length && setTimeout(() => scrollToSelected(), 0), [dados.lista, scrollToSelected]);
383
+
330
384
  const invokeOnChange = onChange;
331
385
 
332
386
  return (
@@ -338,7 +392,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
338
392
  autoHighlight
339
393
  openText='Abrir'
340
394
  clearText='Limpar'
341
- filterSelectedOptions
395
+ filterSelectedOptions
342
396
  onInputChange={e => setInput(e?.target?.value || '')}
343
397
  getOptionSelected={(o, v) => o[0] === v}
344
398
  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.158",
3
+ "version": "1.2.159",
4
4
  "description": "Argous.",
5
5
  "main": "lib/index.js",
6
6
  "author": "Carlos Schneider",