@apia/util 4.0.58 → 4.0.63

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
@@ -177,6 +177,7 @@ declare function downloadUrl(url: string, getNameFromResponse?: (blob: AxiosResp
177
177
  * @param fileName The name the file will have as default in the save dialog
178
178
  */
179
179
  declare function downloadUrl(url: string, fileName: string | TDownloadUrlOptions): Promise<void>;
180
+ declare function downloadUrlWithoutCaching(downloadUrl: string, fileName?: string): Promise<void>;
180
181
 
181
182
  declare function openAndReadFile(accept?: string): Promise<string | ArrayBuffer | null>;
182
183
  type TReadFile = {
@@ -1397,12 +1398,13 @@ declare function useImperativeComponentContext<Events extends TMap = TMap>(): {
1397
1398
  eventsStore: TEventsHandlers<Events>;
1398
1399
  };
1399
1400
 
1401
+ type TLabel = {
1402
+ text: string;
1403
+ title: string;
1404
+ };
1400
1405
  interface ILabelsContainer {
1401
1406
  labels: {
1402
- [key: string]: {
1403
- text: string;
1404
- title: string;
1405
- };
1407
+ [key: string]: TLabel;
1406
1408
  };
1407
1409
  }
1408
1410
  /**
@@ -1435,10 +1437,9 @@ interface ILabelsContainer {
1435
1437
  declare function getLabel(name: string, replaceTokens?: {
1436
1438
  text?: Record<string, string>;
1437
1439
  title?: Record<string, string>;
1438
- }, outerWindow?: any): {
1439
- text: string;
1440
- title: string;
1441
- };
1440
+ }, outerWindow?: any): TLabel;
1441
+ declare function getLabelName(a: string | TLabel): string;
1442
+ declare function getLabelTooltip(a: string | TLabel): string;
1442
1443
 
1443
1444
  /**
1444
1445
  * Da formato a un mensaje con tokens incrustados.
@@ -2047,12 +2048,20 @@ declare function encodeStrToBase64Utf8(str: string): string;
2047
2048
  */
2048
2049
  declare function toBoolean(value: unknown): boolean;
2049
2050
 
2051
+ declare function makeDebouncedCallback<T extends any[]>(cb: (...args: T) => unknown, ms?: number): (...args: T) => void;
2052
+
2050
2053
  declare const getJSObjFromXML: (xml: XMLDocument | string) => Record<string, unknown>;
2051
2054
  declare const parseXmlAsync: <T>(xml: string) => Promise<T>;
2052
2055
  declare const parseXMLRequestResponse: (response: AxiosResponse<unknown, unknown>) => Record<string, unknown>;
2053
2056
 
2054
2057
  declare const postNavigation: (url: string, data: Record<string, any>) => void;
2055
2058
 
2059
+ type TAwaitConditionOptions = Partial<{
2060
+ delay: number;
2061
+ maxRetries: number;
2062
+ }>;
2063
+ declare function awaitCondition(condition: () => Promise<boolean> | boolean, props?: TAwaitConditionOptions): Promise<void>;
2064
+
2056
2065
  declare function awaitTime(ms: number): Promise<void>;
2057
2066
 
2058
2067
  /**
@@ -2101,5 +2110,5 @@ declare class TasksQueue {
2101
2110
  run<T>(task: Task<T>): Promise<T | undefined>;
2102
2111
  }
2103
2112
 
2104
- export { AudioRecorder, type AudioRecorderState, BasicStoredElement, BouncingEmitter, type Callback, ClassNameBuilder, type DebounceOptions, type DeepReadonly, type DownloadStringAsDocProps, EventEmitter, History, type ILabelsContainer, type IOnFocusConfiguration, type IParameter, type ISetBoundary, type IStatesSource, Locker, type Map, Mutex, type NotificationDefinition, type NotificationIcon, type NotificationType, PropsSelectorUndefinedObject, PropsStore, ScrollLocker, Semaphore, StatefulEmitter, type StatefulStoreUpdateProps, type StatefulStoreUpdater, type TActionBehavior, type TActionSource, 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 TAttribute, type TBasicAction, type TBehavior, type TCallback, type TCell, type TColumn, type TDateFormat, type TDispatchCallback, type TDownloadUrlOptions, type TFieldEvent, type TFieldScriptEvent, type TFieldScriptEvents, type TFieldServerEvent, type TFieldServerEvents, type TFilter, type TFncParams, type TFocusRetriever, type THistoryCount, type THistoryStep, type THistoryStepChange, type TId, type TKey, type TLoadStructure, type TMap$1 as TMap, type TMessage, type TModify, type TNotificationMessage, type TOption, type TPropsComparator, type TPropsConfiguration, type TPropsSelector, type TRefresh, type TRequireOnlyOne, type TRow, type TShortcutBranch, type TState, type TStateIcon, type TUpdateFieldConfiguration, type TWithAlignment, type TWithAttributes, type TWithOptions, type TWithStylesModifiers, type Task, TasksQueue, type ThrottleOptions, type UnSubscriber, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, awaitTime, cantFocusSelector, cloneDeep, customEvents, dateToApiaFormat, debugDispatcher, decodeBase64ToUtf8, decodeHTMLEntities, decrypt, deepEqual, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encodeStrToBase64Utf8, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, freezeDeep, getDateFormat, getFocusSelector, getIndex, getJSObjFromXML, getLabel, getSpecificParent, getValueByPath, globalFocus, globals, isChild, isDebugDispatcherEnabled, isFocusable, isPropsConfigurationObject, isSetter, isTrue, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, openAndReadFiles, parseAsSize, parseXMLRequestResponse, parseXmlAsync, persistentStorage, postNavigation, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, uniqueId, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMatchScrollDirection, useMount, useMountTransition, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
2113
+ export { AudioRecorder, type AudioRecorderState, BasicStoredElement, BouncingEmitter, type Callback, ClassNameBuilder, type DebounceOptions, type DeepReadonly, type DownloadStringAsDocProps, EventEmitter, History, type ILabelsContainer, type IOnFocusConfiguration, type IParameter, type ISetBoundary, type IStatesSource, Locker, type Map, Mutex, type NotificationDefinition, type NotificationIcon, type NotificationType, PropsSelectorUndefinedObject, PropsStore, ScrollLocker, Semaphore, StatefulEmitter, type StatefulStoreUpdateProps, type StatefulStoreUpdater, type TActionBehavior, type TActionSource, 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 TAttribute, type TAwaitConditionOptions, type TBasicAction, type TBehavior, type TCallback, type TCell, type TColumn, type TDateFormat, type TDispatchCallback, type TDownloadUrlOptions, type TFieldEvent, type TFieldScriptEvent, type TFieldScriptEvents, type TFieldServerEvent, type TFieldServerEvents, type TFilter, type TFncParams, type TFocusRetriever, type THistoryCount, type THistoryStep, type THistoryStepChange, type TId, type TKey, type TLabel, type TLoadStructure, type TMap$1 as TMap, type TMessage, type TModify, type TNotificationMessage, type TOption, type TPropsComparator, type TPropsConfiguration, type TPropsSelector, type TRefresh, type TRequireOnlyOne, type TRow, type TShortcutBranch, type TState, type TStateIcon, type TUpdateFieldConfiguration, type TWithAlignment, type TWithAttributes, type TWithOptions, type TWithStylesModifiers, type Task, TasksQueue, type ThrottleOptions, type UnSubscriber, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, awaitCondition, awaitTime, cantFocusSelector, cloneDeep, customEvents, dateToApiaFormat, debugDispatcher, decodeBase64ToUtf8, decodeHTMLEntities, decrypt, deepEqual, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, downloadUrlWithoutCaching, enableChildrenFocus, encodeStrToBase64Utf8, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, freezeDeep, getDateFormat, getFocusSelector, getIndex, getJSObjFromXML, getLabel, getLabelName, getLabelTooltip, getSpecificParent, getValueByPath, globalFocus, globals, isChild, isDebugDispatcherEnabled, isFocusable, isPropsConfigurationObject, isSetter, isTrue, makeDebouncedCallback, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, openAndReadFiles, parseAsSize, parseXMLRequestResponse, parseXmlAsync, persistentStorage, postNavigation, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, uniqueId, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMatchScrollDirection, useMount, useMountTransition, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
2105
2114
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -498,6 +498,14 @@ async function downloadUrl(url, secondParameter = defaultGetNameFromResponse) {
498
498
  FileSaver.saveAs(new Blob([blob.data]), actualFileName);
499
499
  }
500
500
  }
501
+ async function downloadUrlWithoutCaching(downloadUrl2, fileName) {
502
+ const link = document.createElement("a");
503
+ link.href = downloadUrl2;
504
+ link.setAttribute("download", fileName ?? "");
505
+ document.body.appendChild(link);
506
+ link.click();
507
+ document.body.removeChild(link);
508
+ }
501
509
 
502
510
  function openAndReadFile(accept) {
503
511
  return new Promise((resolve) => {
@@ -1809,6 +1817,36 @@ function useLocalStorage(prop, defaultValue) {
1809
1817
  ];
1810
1818
  }
1811
1819
 
1820
+ function awaitCondition(condition, props) {
1821
+ const { delay, maxRetries } = Object.assign(
1822
+ { delay: 50, maxRetries: 6 },
1823
+ props
1824
+ );
1825
+ let tries = 1;
1826
+ return new Promise((resolve, reject) => {
1827
+ (async () => {
1828
+ if (await condition()) {
1829
+ resolve();
1830
+ }
1831
+ const i = setInterval(async () => {
1832
+ try {
1833
+ if (await condition()) {
1834
+ resolve();
1835
+ }
1836
+ if (++tries >= maxRetries) {
1837
+ throw new Error(
1838
+ "Maximum number of attempts reached while waiting for the condition"
1839
+ );
1840
+ }
1841
+ } catch (_) {
1842
+ reject(_);
1843
+ clearInterval(i);
1844
+ }
1845
+ }, delay);
1846
+ })();
1847
+ });
1848
+ }
1849
+
1812
1850
  function awaitTime(ms) {
1813
1851
  return new Promise((resolve) => {
1814
1852
  setTimeout(resolve, ms);
@@ -2515,6 +2553,15 @@ function getLabel(name, replaceTokens, outerWindow) {
2515
2553
  label.title = formatMessage(label.title, replaceTokens.title);
2516
2554
  return label;
2517
2555
  }
2556
+ function isLabel(a) {
2557
+ return typeof a !== "string";
2558
+ }
2559
+ function getLabelName(a) {
2560
+ return isLabel(a) ? a.text : a;
2561
+ }
2562
+ function getLabelTooltip(a) {
2563
+ return isLabel(a) ? a.title : "";
2564
+ }
2518
2565
 
2519
2566
  function getValueByPath(obj, path, separator = ".") {
2520
2567
  const actualPath = typeof path === "string" ? path.split(separator) : path;
@@ -2688,7 +2735,7 @@ class PropsStore {
2688
2735
  return this.fields[fieldId];
2689
2736
  }
2690
2737
  removeField(fieldId) {
2691
- this.suscriptors[fieldId] = [];
2738
+ delete this.suscriptors[fieldId];
2692
2739
  delete this.fields[fieldId];
2693
2740
  if (this.log)
2694
2741
  console.info(`propsStore: removeNode ${fieldId}`);
@@ -2703,7 +2750,7 @@ class PropsStore {
2703
2750
  this.suscriptors[fieldId].push(callback);
2704
2751
  callback(this.fields[fieldId] ?? PropsSelectorUndefinedObject);
2705
2752
  return () => {
2706
- this.suscriptors[fieldId] = this.suscriptors[fieldId].filter(
2753
+ this.suscriptors[fieldId] = this.suscriptors[fieldId]?.filter(
2707
2754
  (current) => {
2708
2755
  return current !== callback;
2709
2756
  }
@@ -2970,6 +3017,16 @@ function toBoolean(value) {
2970
3017
  return !!value;
2971
3018
  }
2972
3019
 
3020
+ function makeDebouncedCallback(cb, ms = 50) {
3021
+ let timeout = -1;
3022
+ return (...args) => {
3023
+ clearTimeout(timeout);
3024
+ timeout = setTimeout(() => {
3025
+ cb(...args);
3026
+ }, ms);
3027
+ };
3028
+ }
3029
+
2973
3030
  const processAjaxEventTagNames = (name) => {
2974
3031
  return name;
2975
3032
  };
@@ -3081,5 +3138,5 @@ const postNavigation = (url, data) => {
3081
3138
  form.submit();
3082
3139
  };
3083
3140
 
3084
- export { AudioRecorder, BasicStoredElement, BouncingEmitter, ClassNameBuilder, EventEmitter, History, Locker, Mutex, PropsSelectorUndefinedObject, PropsStore, ScrollLocker, Semaphore, StatefulEmitter, TasksQueue, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, awaitTime, cantFocusSelector, cloneDeep, customEvents, dateToApiaFormat, debugDispatcher, decodeBase64ToUtf8, decodeHTMLEntities, decrypt, deepEqual, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encodeStrToBase64Utf8, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, freezeDeep, getDateFormat, getFocusSelector, getIndex, getJSObjFromXML, getLabel, getSpecificParent, getValueByPath, globalFocus, globals, isChild, isDebugDispatcherEnabled, isFocusable, isPropsConfigurationObject, isSetter, isTrue, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, openAndReadFiles, parseAsSize, parseXMLRequestResponse, parseXmlAsync, persistentStorage, postNavigation, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, uniqueId, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMatchScrollDirection, useMount, useMountTransition, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
3141
+ export { AudioRecorder, BasicStoredElement, BouncingEmitter, ClassNameBuilder, EventEmitter, History, Locker, Mutex, PropsSelectorUndefinedObject, PropsStore, ScrollLocker, Semaphore, StatefulEmitter, TasksQueue, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, awaitCondition, awaitTime, cantFocusSelector, cloneDeep, customEvents, dateToApiaFormat, debugDispatcher, decodeBase64ToUtf8, decodeHTMLEntities, decrypt, deepEqual, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, downloadUrlWithoutCaching, enableChildrenFocus, encodeStrToBase64Utf8, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, freezeDeep, getDateFormat, getFocusSelector, getIndex, getJSObjFromXML, getLabel, getLabelName, getLabelTooltip, getSpecificParent, getValueByPath, globalFocus, globals, isChild, isDebugDispatcherEnabled, isFocusable, isPropsConfigurationObject, isSetter, isTrue, makeDebouncedCallback, makeImperativeComponent, makeSingleImperativeComponent, makeStatefulStore, noNaN, notificationsSelector, openAndReadFile, openAndReadFiles, parseAsSize, parseXMLRequestResponse, parseXmlAsync, persistentStorage, postNavigation, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shallowCompareArrays, shallowEqual, shortcutController, toBoolean, ucfirst, uniqueId, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useIntermediateValue, useLatest, useLocalStorage, useMatchScrollDirection, useMount, useMountTransition, usePanAndZoom, usePrevious, usePropsSelector, useShallowMemo, useStateRef, useSubscription, useUnmount, useUpdateEffect, useWhyUpdated };
3085
3142
  //# sourceMappingURL=index.js.map