argous 1.2.158 → 1.2.161
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) ===
|
|
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 (
|
|
280
|
+
return (group ?
|
|
280
281
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
281
|
-
react_1.default.createElement(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
react_1.default.createElement(
|
|
285
|
-
react_1.default.createElement("div", { className: classes.
|
|
286
|
-
react_1.default.createElement("div", {
|
|
287
|
-
|
|
288
|
-
react_1.default.createElement("div", {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
react_1.default.createElement(
|
|
292
|
-
react_1.default.createElement("div", {
|
|
293
|
-
|
|
294
|
-
|
|
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,
|
|
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
|
|
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 =
|
|
309
|
-
var
|
|
310
|
-
var
|
|
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
|
|
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,9 +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'] || [] });
|
|
360
|
-
else
|
|
361
|
-
api_1.setError('Erro ao tentar buscar dados.');
|
|
361
|
+
setDados(function (v) { return (__assign(__assign({}, v), { lista: res[resposta || 'result'] || [] })); });
|
|
362
362
|
_c.label = 4;
|
|
363
363
|
case 4:
|
|
364
364
|
setLoading(false);
|
|
@@ -369,46 +369,104 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
369
369
|
react_1.useEffect(function () { return autoSearch && seconds === 1 && buscar(); }, [autoSearch, seconds, buscar]);
|
|
370
370
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
371
371
|
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
372
|
-
react_1.useEffect(function () { var _a
|
|
373
|
-
var
|
|
374
|
-
e.preventDefault();
|
|
375
|
-
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) {
|
|
376
374
|
((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
|
|
377
375
|
(e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
|
|
378
376
|
};
|
|
379
|
-
var
|
|
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
|
+
}
|
|
380
416
|
function selectListboxItem(key) {
|
|
381
417
|
var _a;
|
|
382
418
|
var directionIndex = key === 'ArrowDown' ? 1 : key === 'ArrowUp' ? -1 : 0;
|
|
383
419
|
var itens = document.querySelectorAll('#listItem');
|
|
384
420
|
var array = Array.from(itens);
|
|
385
421
|
var el = '';
|
|
422
|
+
var linha = '';
|
|
386
423
|
var indexCapture = 0;
|
|
387
|
-
if (
|
|
388
|
-
el = array === null || array === void 0 ? void 0 : array[0];
|
|
389
|
-
else {
|
|
424
|
+
if (value) {
|
|
390
425
|
array.forEach(function (v, i) {
|
|
391
|
-
var
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (
|
|
426
|
+
var finder = getFinder(v);
|
|
427
|
+
if (linha)
|
|
428
|
+
return;
|
|
429
|
+
if (validateLine(value, finder, v)) {
|
|
395
430
|
var nextIndex = i + directionIndex;
|
|
396
431
|
if (nextIndex < array.length)
|
|
397
432
|
indexCapture = nextIndex > -1 ? nextIndex : i;
|
|
398
433
|
else
|
|
399
434
|
indexCapture = i;
|
|
435
|
+
linha = dados.lista[indexCapture];
|
|
400
436
|
}
|
|
401
437
|
});
|
|
402
438
|
el = array[indexCapture];
|
|
403
439
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
var
|
|
407
|
-
var
|
|
408
|
-
|
|
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 } })); });
|
|
409
453
|
if (linha !== value)
|
|
410
454
|
invokeOnChange('', linha);
|
|
411
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]);
|
|
412
470
|
var invokeOnChange = onChange;
|
|
413
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,
|
|
414
472
|
params.InputProps.endAdornment,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { serverAction
|
|
1
|
+
import { serverAction } 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 ===
|
|
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
|
-
<
|
|
205
|
-
{
|
|
206
|
-
<
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
<
|
|
210
|
-
<div className={classes.
|
|
211
|
-
<div className={classes.
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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,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
|
|
289
|
+
useEffect(() => (value !== dados.cursor?.linha) && setDados(v => ({ ...v, cursor: { index: '', page: '' } })), [value, dados.cursor?.linha]);
|
|
292
290
|
|
|
293
|
-
const
|
|
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
|
|
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
|
-
|
|
309
|
-
|
|
337
|
+
|
|
338
|
+
if (value) {
|
|
310
339
|
array.forEach((v, i) => {
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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))}
|