@apia/util 3.0.9 → 3.0.10

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
@@ -141,6 +141,14 @@ declare function downloadUrl(url: string, getNameFromResponse?: (blob: AxiosResp
141
141
  declare function downloadUrl(url: string, fileName: string): Promise<void>;
142
142
 
143
143
  declare function openAndReadFile(): Promise<string | ArrayBuffer | null>;
144
+ type TReadFile = {
145
+ content: string | ArrayBuffer;
146
+ name: string;
147
+ };
148
+ declare function openAndReadFiles(inputProps?: Partial<{
149
+ accept: string;
150
+ multiple: string;
151
+ }>): Promise<TReadFile[]>;
144
152
 
145
153
  interface IAutoDisconnectMutationObserverConf {
146
154
  /** Por defecto es true */
@@ -682,10 +690,12 @@ type TApiaFilter = {
682
690
  asAdditional?: boolean;
683
691
  column?: string;
684
692
  currentValue: TApiaFilterValue;
693
+ changeFiltersTimestamp?: number;
685
694
  deleteFiltersTimestamp?: number;
686
695
  error?: string;
687
696
  id: string | number;
688
697
  isMeta?: boolean;
698
+ isSize?: boolean;
689
699
  placeholder?: string;
690
700
  runAutomatically?: boolean;
691
701
  title?: string;
@@ -700,6 +710,7 @@ type TApiaFilter = {
700
710
  */
701
711
  group?: string;
702
712
  options?: TApiaFilterOption[];
713
+ sizeMultiplier?: number;
703
714
  type?: 'date' | 'D' | 'S' | 'number' | 'N' | 'apiaNumber';
704
715
  hide?: boolean;
705
716
  hideToFilter?: boolean;
@@ -963,7 +974,8 @@ type THistoryStepChange<T> = THistoryCount & THistoryStep<T> & {
963
974
  hasPrevious: boolean;
964
975
  hasNext: boolean;
965
976
  };
966
- type THistoryConfiguration = {
977
+ type THistoryConfiguration<T> = {
978
+ initialContent?: T;
967
979
  maxLength: number;
968
980
  };
969
981
  /**
@@ -999,7 +1011,6 @@ type THistoryConfiguration = {
999
1011
  declare class History<T> extends EventEmitter<{
1000
1012
  stepChange: THistoryStepChange<T>;
1001
1013
  }> {
1002
- private configuration;
1003
1014
  private autocloseTimeout;
1004
1015
  private currentStep;
1005
1016
  private content;
@@ -1007,7 +1018,8 @@ declare class History<T> extends EventEmitter<{
1007
1018
  protected enabled: boolean;
1008
1019
  private _isOpen;
1009
1020
  private timeoutMs;
1010
- constructor(onCloseWindow: (push: (newState: T) => void) => unknown, configuration?: THistoryConfiguration);
1021
+ private configuration;
1022
+ constructor(onCloseWindow: (push: (newState: T) => void) => unknown, configuration?: Partial<THistoryConfiguration<T>>);
1011
1023
  private closeWindow;
1012
1024
  private getEvent;
1013
1025
  private onCloseWindow;
@@ -1024,7 +1036,7 @@ declare class History<T> extends EventEmitter<{
1024
1036
  get isOpen(): boolean;
1025
1037
  openWindow: () => void;
1026
1038
  reset: () => void;
1027
- updateConfig: (newConfiguration: Partial<THistoryConfiguration>) => void;
1039
+ updateConfig: (newConfiguration: Partial<THistoryConfiguration<T>>) => void;
1028
1040
  useStep: () => Pick<THistoryStepChange<T>, "hasNext" | "hasPrevious" | "currentStep">;
1029
1041
  }
1030
1042
 
@@ -1862,5 +1874,5 @@ declare function toBoolean(value: unknown): boolean;
1862
1874
 
1863
1875
  declare const parseXmlAsync: <T>(xml: string) => Promise<T>;
1864
1876
 
1865
- export { BasicStoredElement, BouncingEmitter, type Callback, type DebounceOptions, type DownloadStringAsDocProps, EventEmitter, History, type IOnFocusConfiguration, type IParameter, type ISetBoundary, type Map, PropsSelectorUndefinedObject, PropsStore, StatefulEmitter, type StatefulStoreUpdateProps, type StatefulStoreUpdater, type TApiaAction, type TApiaActions, type TApiaCellDefinition, type TApiaComplexCell, type TApiaFieldPropsObj, type TApiaFilter, type TApiaFilterOption, type TApiaFilterValue, type TApiaFormButton, type TApiaFormElement, type TApiaFormElementOption, type TApiaFunction, type TApiaFunctionPageInfo, type TApiaLoad, type TApiaLoadForm, type TApiaLoadText, type TApiaMessage, type TApiaMultiplePossibleValue, type TApiaPossibleValue, type TApiaRadioPossibleValue, type TApiaRowDefinition, type TApiaSelectPossibleValue, type TApiaSystemMessageObj, type TApiaTableFunction, type TCallback, type TDateFormat, type TDispatchCallback, type TFieldEvent, type TFieldScriptEvent, type TFieldScriptEvents, type TFieldServerEvent, type TFieldServerEvents, type TFncParams, type TFocusRetriever, type THistoryCount, type THistoryStep, type THistoryStepChange, type TId, type TKey, type TMap$1 as TMap, type TMessage, type TModify, type TNotificationMessage, type TPropsComparator, type TPropsConfiguration, type TPropsSelector, type TRequireOnlyOne, type TShortcutBranch, type TUpdateFieldConfiguration, type ThrottleOptions, type UnSubscriber, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, cantFocusSelector, customEvents, dateToApiaFormat, debugDispatcher, decodeHTMLEntities, decrypt, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, getDateFormat, getFocusSelector, getIndex, getLabel, getSpecificParent, getValueByPath, globalFocus, isChild, isDebugDispatcherEnabled, isPropsConfigurationObject, isSetter, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, parseAsSize, parseXmlAsync, persistentStorage, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMount, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
1877
+ export { BasicStoredElement, BouncingEmitter, type Callback, type DebounceOptions, type DownloadStringAsDocProps, EventEmitter, History, type IOnFocusConfiguration, type IParameter, type ISetBoundary, type Map, PropsSelectorUndefinedObject, PropsStore, StatefulEmitter, type StatefulStoreUpdateProps, type StatefulStoreUpdater, type TApiaAction, type TApiaActions, type TApiaCellDefinition, type TApiaComplexCell, type TApiaFieldPropsObj, type TApiaFilter, type TApiaFilterOption, type TApiaFilterValue, type TApiaFormButton, type TApiaFormElement, type TApiaFormElementOption, type TApiaFunction, type TApiaFunctionPageInfo, type TApiaLoad, type TApiaLoadForm, type TApiaLoadText, type TApiaMessage, type TApiaMultiplePossibleValue, type TApiaPossibleValue, type TApiaRadioPossibleValue, type TApiaRowDefinition, type TApiaSelectPossibleValue, type TApiaSystemMessageObj, type TApiaTableFunction, type TCallback, type TDateFormat, type TDispatchCallback, type TFieldEvent, type TFieldScriptEvent, type TFieldScriptEvents, type TFieldServerEvent, type TFieldServerEvents, type TFncParams, type TFocusRetriever, type THistoryCount, type THistoryStep, type THistoryStepChange, type TId, type TKey, type TMap$1 as TMap, type TMessage, type TModify, type TNotificationMessage, type TPropsComparator, type TPropsConfiguration, type TPropsSelector, type TRequireOnlyOne, type TShortcutBranch, type TUpdateFieldConfiguration, type ThrottleOptions, type UnSubscriber, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, cantFocusSelector, customEvents, dateToApiaFormat, debugDispatcher, decodeHTMLEntities, decrypt, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, getDateFormat, getFocusSelector, getIndex, getLabel, getSpecificParent, getValueByPath, globalFocus, isChild, isDebugDispatcherEnabled, isPropsConfigurationObject, isSetter, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, openAndReadFiles, parseAsSize, parseXmlAsync, persistentStorage, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMount, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
1866
1878
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -401,6 +401,44 @@ function openAndReadFile() {
401
401
  });
402
402
  });
403
403
  }
404
+ function openAndReadFiles(inputProps) {
405
+ return new Promise((resolve) => {
406
+ const input = document.createElement("input");
407
+ input.type = "file";
408
+ input.style.display = "none";
409
+ document.body.append(input);
410
+ Object.assign(input, inputProps);
411
+ input.addEventListener("change", (ev) => {
412
+ const fileInput = ev.target;
413
+ if ((fileInput?.files?.length ?? 0) === 0) {
414
+ resolve([]);
415
+ } else {
416
+ const files = [];
417
+ const sources = fileInput.files;
418
+ [...sources].forEach((c) => {
419
+ const reader = new FileReader();
420
+ reader.onload = (event) => {
421
+ fileInput.value = "";
422
+ const content = event.target?.result;
423
+ if (content) {
424
+ files.push({
425
+ content,
426
+ name: c.name
427
+ });
428
+ } else {
429
+ files.push(null);
430
+ }
431
+ if (files.length === sources.length) {
432
+ resolve(files.filter((c2) => !!c2));
433
+ }
434
+ };
435
+ reader.readAsText(c);
436
+ });
437
+ }
438
+ });
439
+ input.click();
440
+ });
441
+ }
404
442
 
405
443
  function autoDisconnectMutationObserver(element, callback, conf) {
406
444
  let timeoutRegister = -1;
@@ -850,54 +888,55 @@ const useDebouncedCallback = (callback, { runWhenTriggered, timeout } = { runWhe
850
888
  );
851
889
  };
852
890
 
853
- function usePrevious$1(element) {
854
- const el = React__default.useRef(element);
855
- const last = React__default.useRef(null);
856
- last.current = el.current;
857
- el.current = element;
858
- return last;
891
+ function usePrevious(value) {
892
+ const previousValue = useRef(void 0);
893
+ const currentValue = useRef(void 0);
894
+ previousValue.current = currentValue.current;
895
+ currentValue.current = value;
896
+ return previousValue;
859
897
  }
860
898
 
861
- function shallowEqual$1(a, b) {
862
- if (Object.is(a, b))
863
- return true;
864
- if (!Object.is(a, b) && typeof a !== typeof b) {
899
+ function shallowEqual(a, b) {
900
+ if (typeof a !== typeof b)
865
901
  return false;
866
- }
867
- if (typeof a === "object") {
868
- if (Array.isArray(a)) {
869
- if (!Array.isArray(b) || a.length !== b.length) {
870
- return false;
871
- }
872
- for (let i = 0; i < a.length; i++) {
873
- if (!Object.is(a[i], b[i])) {
874
- return false;
875
- }
876
- }
877
- return true;
878
- } else if (a && b) {
879
- for (const [key, value] of Object.entries(a)) {
880
- if (!Object.is(value, b[key])) {
881
- return false;
882
- }
883
- }
884
- for (const [key, value] of Object.entries(b)) {
885
- if (!Object.is(value, a[key])) {
886
- return false;
887
- }
888
- }
889
- return true;
890
- } else if (a && !b || !a && b) {
902
+ if (typeof a === "object" && a && typeof b === "object" && b) {
903
+ const aKeys = Object.keys(a);
904
+ const bKeys = Object.keys(b);
905
+ if (aKeys.length !== bKeys.length)
891
906
  return false;
907
+ for (let i = 0; i < aKeys.length; i++) {
908
+ if (a[aKeys[i]] !== b[bKeys[i]])
909
+ return false;
892
910
  }
911
+ } else {
912
+ if (a !== b)
913
+ return false;
893
914
  }
894
- return a === b;
915
+ return true;
916
+ }
917
+ function shallowCompareArrays(a, b) {
918
+ if (a.length !== b.length)
919
+ return false;
920
+ for (let i = 0; i < a.length; i++) {
921
+ const differ = shallowEqual(a, b);
922
+ if (!differ)
923
+ return false;
924
+ }
925
+ return true;
926
+ }
927
+ function useShallowMemo(creator, deps) {
928
+ const value = useRef(creator());
929
+ const previousDeps = usePrevious(deps);
930
+ if (!shallowEqual(previousDeps.current ?? [], deps)) {
931
+ value.current = creator();
932
+ }
933
+ return value.current;
895
934
  }
896
935
 
897
936
  function useIntermediateValue(currentValue) {
898
937
  const [innerState, setInnerState] = useState(currentValue);
899
- const previousValue = usePrevious$1(currentValue);
900
- if (!shallowEqual$1(currentValue, previousValue.current)) {
938
+ const previousValue = usePrevious(currentValue);
939
+ if (!shallowEqual(currentValue, previousValue.current)) {
901
940
  setInnerState(currentValue);
902
941
  }
903
942
  return [innerState, setInnerState];
@@ -921,14 +960,6 @@ function useUnmount(unmountCallback) {
921
960
  }, []);
922
961
  }
923
962
 
924
- function usePrevious(value) {
925
- const previousValue = useRef(void 0);
926
- const currentValue = useRef(void 0);
927
- previousValue.current = currentValue.current;
928
- currentValue.current = value;
929
- return previousValue;
930
- }
931
-
932
963
  function useStateRef(initialState) {
933
964
  const [state, setState] = useState(initialState);
934
965
  const stateRef = useRef(state);
@@ -964,43 +995,6 @@ function useUpdateEffect(effect, deps) {
964
995
  }, deps);
965
996
  }
966
997
 
967
- function shallowEqual(a, b) {
968
- if (typeof a !== typeof b)
969
- return false;
970
- if (typeof a === "object" && a && typeof b === "object" && b) {
971
- const aKeys = Object.keys(a);
972
- const bKeys = Object.keys(b);
973
- if (aKeys.length !== bKeys.length)
974
- return false;
975
- for (let i = 0; i < aKeys.length; i++) {
976
- if (a[aKeys[i]] !== b[bKeys[i]])
977
- return false;
978
- }
979
- } else {
980
- if (a !== b)
981
- return false;
982
- }
983
- return true;
984
- }
985
- function shallowCompareArrays(a, b) {
986
- if (a.length !== b.length)
987
- return false;
988
- for (let i = 0; i < a.length; i++) {
989
- const differ = shallowEqual(a, b);
990
- if (!differ)
991
- return false;
992
- }
993
- return true;
994
- }
995
- function useShallowMemo(creator, deps) {
996
- const value = useRef(creator());
997
- const previousDeps = usePrevious(deps);
998
- if (!shallowEqual(previousDeps.current ?? [], deps)) {
999
- value.current = creator();
1000
- }
1001
- return value.current;
1002
- }
1003
-
1004
998
  function useWhyUpdated(label, e) {
1005
999
  const previousData = usePrevious(e);
1006
1000
  const diffs = [];
@@ -1964,9 +1958,8 @@ const focus = new (_a = class {
1964
1958
  }, _a)(document.getElementById("root"));
1965
1959
 
1966
1960
  class History extends EventEmitter {
1967
- constructor(onCloseWindow, configuration = { maxLength: 100 }) {
1961
+ constructor(onCloseWindow, configuration) {
1968
1962
  super();
1969
- this.configuration = configuration;
1970
1963
  this.autocloseTimeout = -1;
1971
1964
  this.currentStep = 0;
1972
1965
  this.content = [];
@@ -1987,14 +1980,17 @@ class History extends EventEmitter {
1987
1980
  currentStep: this.currentStep,
1988
1981
  stepCount,
1989
1982
  hasNext: this.currentStep < stepCount,
1990
- hasPrevious: this.currentStep >= 0
1983
+ hasPrevious: this.currentStep > 0
1991
1984
  };
1992
1985
  return event;
1993
1986
  };
1994
1987
  this.push = (el) => {
1995
1988
  this.content = [...this.content.slice(0, this.currentStep + 1), el];
1996
1989
  this.content = this.content.slice(
1997
- Math.max(0, this.content.length - this.configuration.maxLength)
1990
+ Math.max(
1991
+ 0,
1992
+ this.content.length - (this.configuration?.maxLength ?? Infinity)
1993
+ )
1998
1994
  );
1999
1995
  this.currentStep = this.content.length - 1;
2000
1996
  this.shoutStepChange(true);
@@ -2018,7 +2014,7 @@ class History extends EventEmitter {
2018
2014
  };
2019
2015
  this.back = () => {
2020
2016
  clearTimeout(this.autocloseTimeout);
2021
- if (this.currentStep >= 0) {
2017
+ if (this.currentStep > 0) {
2022
2018
  this.currentStep -= 1;
2023
2019
  this.shoutStepChange();
2024
2020
  }
@@ -2048,14 +2044,14 @@ class History extends EventEmitter {
2048
2044
  this.reset = () => {
2049
2045
  clearTimeout(this.autocloseTimeout);
2050
2046
  this.content = [];
2051
- this.currentStep = -1;
2047
+ this.currentStep = 0;
2052
2048
  this.openWindow();
2053
2049
  };
2054
2050
  this.updateConfig = (newConfiguration) => {
2055
2051
  this.configuration = { ...this.configuration, ...newConfiguration };
2056
2052
  };
2057
2053
  this.useStep = () => {
2058
- const [hasPrevious, setHasPrevious] = useState({ hasNext: false, hasPrevious: false, currentStep: 0 });
2054
+ const [hasPrevious, setHasPrevious] = useState({ hasNext: false, hasPrevious: false, currentStep: this.currentStep });
2059
2055
  useMount(() => {
2060
2056
  return this.on("stepChange", (ev) => {
2061
2057
  setHasPrevious({
@@ -2067,12 +2063,17 @@ class History extends EventEmitter {
2067
2063
  });
2068
2064
  return hasPrevious;
2069
2065
  };
2066
+ this.configuration = Object.assign({ maxLength: 15 }, configuration);
2067
+ this.content.push(configuration?.initialContent ?? null);
2070
2068
  this.onCloseWindow = onCloseWindow;
2071
2069
  }
2072
2070
  emit(eventName, params) {
2073
2071
  this.emitting++;
2074
- super.emit(eventName, params);
2075
- this.emitting--;
2072
+ try {
2073
+ super.emit(eventName, params);
2074
+ } finally {
2075
+ this.emitting--;
2076
+ }
2076
2077
  }
2077
2078
  get isOpen() {
2078
2079
  return this._isOpen;
@@ -2637,5 +2638,5 @@ const parseXmlAsync = async (xml) => {
2637
2638
  return result;
2638
2639
  };
2639
2640
 
2640
- export { BasicStoredElement, BouncingEmitter, EventEmitter, History, PropsSelectorUndefinedObject, PropsStore, StatefulEmitter, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, cantFocusSelector, customEvents, dateToApiaFormat, debugDispatcher, decodeHTMLEntities, decrypt, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, getDateFormat, getFocusSelector, getIndex, getLabel, getSpecificParent, getValueByPath, globalFocus, isChild, isDebugDispatcherEnabled, isPropsConfigurationObject, isSetter, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, parseAsSize, parseXmlAsync, persistentStorage$1 as persistentStorage, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents$1 as useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMount, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
2641
+ export { BasicStoredElement, BouncingEmitter, EventEmitter, History, PropsSelectorUndefinedObject, PropsStore, StatefulEmitter, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, cantFocusSelector, customEvents, dateToApiaFormat, debugDispatcher, decodeHTMLEntities, decrypt, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, getDateFormat, getFocusSelector, getIndex, getLabel, getSpecificParent, getValueByPath, globalFocus, isChild, isDebugDispatcherEnabled, isPropsConfigurationObject, isSetter, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, openAndReadFiles, parseAsSize, parseXmlAsync, persistentStorage$1 as persistentStorage, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents$1 as useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMount, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
2641
2642
  //# sourceMappingURL=index.js.map