@apia/components 4.0.31 → 4.0.33

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.
package/dist/index.d.ts CHANGED
@@ -816,14 +816,14 @@ type AutocompleteProps = {
816
816
  * Si este flag es true, la búsqueda se realiza con .toLowerCase() en el valor y en la cadena de búsqueda.
817
817
  */
818
818
  caseInsensitive?: boolean;
819
+ icon?: TIconName;
819
820
  onChange?: (value: string, controller: AutocompleteController) => void | Promise<boolean>;
820
821
  /**
821
- * Si se pasa una función de búsqueda, cuando el usuario busque se llamará a esta función para determinar qué opciones deberán mostrarse. Las opciones devueltas deberán tener filtered !== true para mostrarse.
822
+ * Si se pasa una función de búsqueda, cuando el usuario busque se llamará a esta función para determinar qué opciones deberán mostrarse.
822
823
  *
823
824
  * La función de búsqueda será llamada mediante un debounce con tiempo = state.searchDebounce (ms).
824
825
  *
825
826
  * Si no se pasa función de búsqueda, la comparación se realizará contra this.state.options, siguiendo el algoritmo descrito en AutocompleteOption.
826
- *
827
827
  */
828
828
  onSearch?: (str: string, controller: AutocompleteController) => Promise<AutocompleteOption[]>;
829
829
  options: AutocompleteOption[];
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import React__default, { createContext, useContext, useEffect, useMemo, useState, useCallback, useRef, forwardRef, Fragment as Fragment$1, useDeferredValue, lazy, Suspense, useTransition, Children, memo, isValidElement, cloneElement, createRef } from 'react';
4
4
  import parse, { domToReact, Element } from 'html-react-parser';
5
5
  import { Spinner as Spinner$1, Box as Box$1 } from 'theme-ui';
6
- import { uniqueId as uniqueId$3, debounce, cloneDeep, isFunction } from 'lodash-es';
6
+ import { uniqueId as uniqueId$3, cloneDeep, isFunction } from 'lodash-es';
7
7
  import { Box, getVariant, useBreakpointIndex, Close, responsive, spacing, Heading, Link, Button, Spinner, createElement, Select, Input, Flex, IconButton as IconButton$1, Image, injectStyles, Progress, Label as Label$1, Paragraph, Container, Form, focusOutline, makeStyledComponent, useThemeUI, Grid, Textarea } from '@apia/theme';
8
8
  import { BarLoader } from 'react-spinners';
9
9
  import uniqueId$2 from 'lodash-es/uniqueId';
@@ -3146,7 +3146,7 @@ var __privateSet$5 = (obj, member, value, setter) => {
3146
3146
  member.set(obj, value);
3147
3147
  return value;
3148
3148
  };
3149
- var _timeout, _tooltipTimeout, _unsuscribe, _tooltip;
3149
+ var _timeout$1, _tooltipTimeout, _unsuscribe, _tooltip;
3150
3150
  let y$1 = 0, x$1 = 0;
3151
3151
  document?.addEventListener("mousemove", (ev) => {
3152
3152
  x$1 = ev.clientX;
@@ -3155,7 +3155,7 @@ document?.addEventListener("mousemove", (ev) => {
3155
3155
  class AutomaticTooltip {
3156
3156
  constructor(tooltip = null, handler) {
3157
3157
  this.handler = handler;
3158
- __privateAdd$8(this, _timeout, 500);
3158
+ __privateAdd$8(this, _timeout$1, 500);
3159
3159
  __privateAdd$8(this, _tooltipTimeout, 0);
3160
3160
  __privateAdd$8(this, _unsuscribe, null);
3161
3161
  __publicField$l(this, "ref", (el) => {
@@ -3172,7 +3172,7 @@ class AutomaticTooltip {
3172
3172
  ...__privateGet$7(this, _tooltip),
3173
3173
  anchorPoint: { left: x$1 + 3, top: y$1 + 3 }
3174
3174
  });
3175
- }, __privateGet$7(this, _timeout)));
3175
+ }, __privateGet$7(this, _timeout$1)));
3176
3176
  };
3177
3177
  const reset = () => {
3178
3178
  clearTimeout(__privateGet$7(this, _tooltipTimeout));
@@ -3195,11 +3195,11 @@ class AutomaticTooltip {
3195
3195
  });
3196
3196
  __privateSet$5(this, _tooltip, tooltip);
3197
3197
  if (tooltip?.timeout !== void 0) {
3198
- __privateSet$5(this, _timeout, tooltip?.timeout);
3198
+ __privateSet$5(this, _timeout$1, tooltip?.timeout);
3199
3199
  }
3200
3200
  }
3201
3201
  }
3202
- _timeout = new WeakMap();
3202
+ _timeout$1 = new WeakMap();
3203
3203
  _tooltipTimeout = new WeakMap();
3204
3204
  _unsuscribe = new WeakMap();
3205
3205
  _tooltip = new WeakMap();
@@ -4008,7 +4008,7 @@ var __privateSet$2 = (obj, member, value, setter) => {
4008
4008
  member.set(obj, value);
4009
4009
  return value;
4010
4010
  };
4011
- var _actualSearch, _makeSearch, _search;
4011
+ var _actualSearch, _timeout;
4012
4012
  class AutocompleteController {
4013
4013
  constructor(properties) {
4014
4014
  __publicField$f(this, "state", {
@@ -4022,22 +4022,28 @@ class AutocompleteController {
4022
4022
  value: "",
4023
4023
  width: 55
4024
4024
  });
4025
- __privateAdd$4(this, _actualSearch, (str) => {
4026
- this.state.options.forEach((c) => {
4027
- if (this.state.caseInsensitive) {
4028
- c.filtered = (c.searchLabel ?? c.label?.toString?.() ?? c.value).toLowerCase().indexOf(str.toLowerCase()) === -1;
4029
- } else {
4030
- c.filtered = (c.searchLabel ?? c.label?.toString?.() ?? c.value)?.indexOf(str) === -1;
4031
- }
4032
- if (this.getOptionByValue(this.state.focusedValue)?.filtered) {
4033
- this.state.focusedValue = this.state.options.find((c2) => !c2.filtered)?.value || null;
4034
- }
4035
- });
4036
- });
4037
- __privateAdd$4(this, _makeSearch, () => {
4038
- return debounce(__privateGet$3(this, _actualSearch), this.state.searchDebounce);
4025
+ __privateAdd$4(this, _actualSearch, async (str) => {
4026
+ if (this.state.onSearch) {
4027
+ if (str === "")
4028
+ this.state.value = "";
4029
+ const newOptions = await this.state.onSearch(str, this);
4030
+ this.state.options = newOptions;
4031
+ } else {
4032
+ this.state.options.forEach((c) => {
4033
+ if (this.state.caseInsensitive) {
4034
+ c.filtered = (c.searchLabel ?? c.label?.toString?.() ?? c.value).toLowerCase().indexOf(str.toLowerCase()) === -1;
4035
+ } else {
4036
+ c.filtered = (c.searchLabel ?? c.label?.toString?.() ?? c.value)?.indexOf(
4037
+ str
4038
+ ) === -1;
4039
+ }
4040
+ if (this.getOptionByValue(this.state.focusedValue)?.filtered) {
4041
+ this.state.focusedValue = this.state.options.find((c2) => !c2.filtered)?.value || null;
4042
+ }
4043
+ });
4044
+ }
4039
4045
  });
4040
- __privateAdd$4(this, _search, __privateGet$3(this, _makeSearch).call(this));
4046
+ __privateAdd$4(this, _timeout, 0);
4041
4047
  __publicField$f(this, "tooltipRef", null);
4042
4048
  Object.assign(this.state, properties);
4043
4049
  if (properties.value) {
@@ -4050,12 +4056,6 @@ class AutocompleteController {
4050
4056
  getAutocompleteBox: false,
4051
4057
  getOptionByValue: false
4052
4058
  });
4053
- reaction(
4054
- () => this.state.searchDebounce,
4055
- () => {
4056
- __privateSet$2(this, _search, __privateGet$3(this, _makeSearch).call(this));
4057
- }
4058
- );
4059
4059
  reaction(
4060
4060
  () => this.state.focusedValue,
4061
4061
  () => {
@@ -4083,7 +4083,8 @@ class AutocompleteController {
4083
4083
  close(selectValue = true) {
4084
4084
  this.tooltipRef?.close();
4085
4085
  this.tooltipRef = null;
4086
- __privateGet$3(this, _actualSearch).call(this, "");
4086
+ if (!this.state.showValue)
4087
+ __privateGet$3(this, _actualSearch).call(this, "");
4087
4088
  if (selectValue) {
4088
4089
  let currentValue = this.state.options.find(
4089
4090
  (c) => c.value === this.state.focusedValue
@@ -4210,7 +4211,10 @@ class AutocompleteController {
4210
4211
  return;
4211
4212
  }
4212
4213
  this.state.showValue = str;
4213
- __privateGet$3(this, _search).call(this, str);
4214
+ clearTimeout(__privateGet$3(this, _timeout));
4215
+ __privateSet$2(this, _timeout, setTimeout(() => {
4216
+ __privateGet$3(this, _actualSearch).call(this, str);
4217
+ }, 100));
4214
4218
  }
4215
4219
  selectFocused() {
4216
4220
  this.close();
@@ -4239,8 +4243,7 @@ class AutocompleteController {
4239
4243
  }
4240
4244
  }
4241
4245
  _actualSearch = new WeakMap();
4242
- _makeSearch = new WeakMap();
4243
- _search = new WeakMap();
4246
+ _timeout = new WeakMap();
4244
4247
 
4245
4248
  const SearchBox = observer((props) => {
4246
4249
  const handler = useAutocompleteContext();
@@ -4271,7 +4274,7 @@ const SearchBox = observer((props) => {
4271
4274
  ...props,
4272
4275
  ref: inputRef,
4273
4276
  className: `autocomplete__search ${handler.state.disabled ? "disabled" : ""} ${handler.state.readOnly ? "readOnly" : ""}`,
4274
- onChange: (ev) => {
4277
+ onChange: async (ev) => {
4275
4278
  handler.search(ev.target.value);
4276
4279
  },
4277
4280
  onMouseDown: () => {
@@ -4293,7 +4296,7 @@ const SearchBox = observer((props) => {
4293
4296
  Icon$1,
4294
4297
  {
4295
4298
  title: "",
4296
- name: "ArrowDown",
4299
+ name: handler.state?.icon || "ArrowDown",
4297
4300
  className: "autocomplete__downArrow"
4298
4301
  }
4299
4302
  )
@@ -4910,6 +4913,7 @@ const DateInput = React__default.forwardRef(
4910
4913
  const { deleteFiltersTimestamp, ...otherProps } = props;
4911
4914
  const hasBlured = useRef(false);
4912
4915
  const [stateError, setError] = React__default.useState(error ?? null);
4916
+ const [isFocused, setIsFocused] = React__default.useState(false);
4913
4917
  const lastEmittedValue = React__default.useRef(outerValue ?? "");
4914
4918
  useUpdateEffect$1(() => {
4915
4919
  setInputValue(outerValue ?? "");
@@ -5044,6 +5048,9 @@ const DateInput = React__default.forwardRef(
5044
5048
  value: stateError ? "" : renderLabel ? renderLabel(inputValue) : inputValue,
5045
5049
  ref,
5046
5050
  onChange: (ev) => {
5051
+ if (props.readOnly) {
5052
+ return;
5053
+ }
5047
5054
  setInputValue(ev.target.value);
5048
5055
  if (getMaskForDateFormat().replaceAll("9", DEFAULT_MASK_PLACEHOLDER) !== ev.target.value && ev.target.value !== "") {
5049
5056
  setError(null);
@@ -5053,6 +5060,7 @@ const DateInput = React__default.forwardRef(
5053
5060
  }
5054
5061
  },
5055
5062
  onBlur: (ev) => {
5063
+ setIsFocused(false);
5056
5064
  if (!(props.readOnly || getCustomMask || document.querySelector(".overlay.screenLock")))
5057
5065
  setCalendarValue(ev.target.value, false, true);
5058
5066
  if (hasBlured.current) {
@@ -5061,6 +5069,9 @@ const DateInput = React__default.forwardRef(
5061
5069
  handleBlur(ev);
5062
5070
  }
5063
5071
  },
5072
+ onFocus: () => {
5073
+ setIsFocused(true);
5074
+ },
5064
5075
  onKeyDown: (ev) => {
5065
5076
  if (ev.key === "Enter")
5066
5077
  setCalendarValue(inputValue);
@@ -5088,25 +5099,38 @@ const DateInput = React__default.forwardRef(
5088
5099
  }),
5089
5100
  [outerButtonProps, props.disabled, props.readOnly]
5090
5101
  );
5091
- const additionalButtons = React__default.useMemo(
5092
- () => /* @__PURE__ */ jsx(
5093
- Close,
5102
+ const additionalButtons = React__default.useMemo(() => {
5103
+ const doDelete = (e) => {
5104
+ e?.stopPropagation();
5105
+ setCalendarValue("");
5106
+ onDelete?.();
5107
+ document.querySelector(`#DateInput${id} input`)?.focus();
5108
+ };
5109
+ return /* @__PURE__ */ jsx(
5110
+ "span",
5094
5111
  {
5095
- className: "delete_date_button",
5096
- onClick: () => {
5097
- setCalendarValue("");
5098
- onDelete?.();
5099
- document.querySelector(
5100
- `#DateInput${id} input`
5101
- )?.focus();
5112
+ role: "button",
5113
+ tabIndex: 0,
5114
+ onMouseDown: (e) => {
5115
+ e.preventDefault();
5116
+ e.stopPropagation();
5117
+ },
5118
+ onClick: (e) => {
5119
+ e.stopPropagation();
5120
+ doDelete(e);
5121
+ },
5122
+ onKeyDown: (e) => {
5123
+ if (e.key === "Enter" || e.key === " ") {
5124
+ e.preventDefault();
5125
+ doDelete(e);
5126
+ }
5102
5127
  },
5103
- title: getLabel("btnAiDelete").text,
5104
5128
  "aria-label": getLabel("btnAiDelete").text,
5105
- type: "button"
5129
+ title: getLabel("btnAiDelete").text,
5130
+ children: /* @__PURE__ */ jsx(Close, { type: "button", className: "delete_date_button" })
5106
5131
  }
5107
- ),
5108
- [id, onDelete, setCalendarValue]
5109
- );
5132
+ );
5133
+ }, [id, onDelete, setCalendarValue]);
5110
5134
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
5111
5135
  Box,
5112
5136
  {
@@ -5115,6 +5139,7 @@ const DateInput = React__default.forwardRef(
5115
5139
  id: `DateInput${id}`,
5116
5140
  ref: boxRef,
5117
5141
  onBlur: (e) => {
5142
+ setIsFocused(false);
5118
5143
  if (hasBlured.current) {
5119
5144
  hasBlured.current = false;
5120
5145
  } else if (!document.querySelector(".overlay.screenLock")) {
@@ -5124,10 +5149,14 @@ const DateInput = React__default.forwardRef(
5124
5149
  children: /* @__PURE__ */ jsx(
5125
5150
  IconInput,
5126
5151
  {
5127
- additionalButtons: inputValue && inputValue !== getMaskForDateFormat().replaceAll(
5128
- "9",
5129
- DEFAULT_MASK_PLACEHOLDER
5130
- ) && !props.readOnly && !props.disabled ? additionalButtons : void 0,
5152
+ additionalButtons: (
5153
+ // mostrar sólo si el campo tiene valor, no está en modo placeholder,
5154
+ // no es readOnly/disabled Y el input está enfocado
5155
+ inputValue && inputValue !== getMaskForDateFormat().replaceAll(
5156
+ "9",
5157
+ DEFAULT_MASK_PLACEHOLDER
5158
+ ) && !props.readOnly && !props.disabled && isFocused ? additionalButtons : void 0
5159
+ ),
5131
5160
  buttonProps,
5132
5161
  className: `${stateError !== null ? "field__withError" : ""}`,
5133
5162
  icon: FaCalendarAlt,