@apia/util 4.0.30 → 4.0.31

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
@@ -29,6 +29,8 @@ declare function arrayOrArray<T>(o: T | T[] | undefined): T[];
29
29
  */
30
30
  declare function getIndex<T = unknown>(arr: T[], conditions: (boolean | (() => boolean))[], defaultIndex?: number): T;
31
31
 
32
+ declare function deepEqual(a: any, b: any, visited?: WeakMap<WeakKey, any>): boolean;
33
+
32
34
  declare const decrypt: (salt: string, iv: string, passPhrase: string, cipherText: string, keySize: number, iterationCount: number) => Promise<string>;
33
35
 
34
36
  declare const encrypt: (salt: string, iv: string, passPhrase: string, plainText: string, keySize: number, iterationCount: number) => Promise<string>;
@@ -212,6 +214,8 @@ declare function findOffsetRelativeToScrollParent(element: HTMLElement, which?:
212
214
  */
213
215
  declare function findScrollContainer(el: HTMLElement): HTMLElement | null;
214
216
 
217
+ declare function isFocusable(element: HTMLElement): boolean;
218
+
215
219
  /**
216
220
  * Mantiene visible `element` dentro de su contenedor con scroll,
217
221
  * compensando un posible header fijo (`fixedOffsetTop`).
@@ -1295,7 +1299,7 @@ declare function useImperativeComponentContext<Events extends TMap = TMap>(): {
1295
1299
  declare function getLabel(name: string, replaceTokens?: {
1296
1300
  text?: Record<string, string>;
1297
1301
  title?: Record<string, string>;
1298
- }): {
1302
+ }, outerWindow?: any): {
1299
1303
  text: string;
1300
1304
  title: string;
1301
1305
  };
@@ -1953,8 +1957,9 @@ declare class Mutex extends Semaphore {
1953
1957
  type Task<T> = () => Promise<T>;
1954
1958
  declare class TasksQueue {
1955
1959
  private mutex;
1960
+ get isBusy(): boolean;
1956
1961
  run<T>(task: Task<T>): Promise<T>;
1957
1962
  }
1958
1963
 
1959
- export { AudioRecorder, type AudioRecorderState, BasicStoredElement, BouncingEmitter, type Callback, ClassNameBuilder, type DebounceOptions, type DeepReadonly, type DownloadStringAsDocProps, EventEmitter, History, type IOnFocusConfiguration, type IParameter, type ISetBoundary, Locker, type Map, Mutex, PropsSelectorUndefinedObject, PropsStore, ScrollLocker, Semaphore, 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 TDownloadUrlOptions, 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 Task, TasksQueue, type ThrottleOptions, type UnSubscriber, Url, addBoundary, alignment, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, awaitTime, cantFocusSelector, cloneDeep, customEvents, dateToApiaFormat, debugDispatcher, decodeBase64ToUtf8, decodeHTMLEntities, decrypt, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, freezeDeep, getDateFormat, getFocusSelector, getIndex, getJSObjFromXML, getLabel, getSpecificParent, getValueByPath, globalFocus, globals, isChild, isDebugDispatcherEnabled, 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 };
1964
+ export { AudioRecorder, type AudioRecorderState, BasicStoredElement, BouncingEmitter, type Callback, ClassNameBuilder, type DebounceOptions, type DeepReadonly, type DownloadStringAsDocProps, EventEmitter, History, type IOnFocusConfiguration, type IParameter, type ISetBoundary, Locker, type Map, Mutex, PropsSelectorUndefinedObject, PropsStore, ScrollLocker, Semaphore, 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 TDownloadUrlOptions, 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 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, 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 };
1960
1965
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -134,6 +134,43 @@ function getIndex(arr, conditions, defaultIndex) {
134
134
  return arr[defaultIndex ?? -1];
135
135
  }
136
136
 
137
+ function deepEqual(a, b, visited = /* @__PURE__ */ new WeakMap()) {
138
+ if (a === b)
139
+ return true;
140
+ if (typeof a !== typeof b)
141
+ return false;
142
+ if (a === null || b === null)
143
+ return a === b;
144
+ if (a instanceof Date && b instanceof Date) {
145
+ return a.getTime() === b.getTime();
146
+ }
147
+ if (Array.isArray(a) && Array.isArray(b)) {
148
+ if (a.length !== b.length)
149
+ return false;
150
+ for (let i = 0; i < a.length; i++) {
151
+ if (!deepEqual(a[i], b[i], visited))
152
+ return false;
153
+ }
154
+ return true;
155
+ }
156
+ if (typeof a === "object" && typeof b === "object") {
157
+ if (visited.get(a) === b)
158
+ return true;
159
+ visited.set(a, b);
160
+ const aKeys = Object.keys(a);
161
+ const bKeys = Object.keys(b);
162
+ if (aKeys.length !== bKeys.length)
163
+ return false;
164
+ for (const key of aKeys) {
165
+ if (!bKeys.includes(key) || !deepEqual(a[key], b[key], visited)) {
166
+ return false;
167
+ }
168
+ }
169
+ return true;
170
+ }
171
+ return false;
172
+ }
173
+
137
174
  const generateKey = async (salt, passPhrase, keySize, iterationCount) => {
138
175
  const CryptoJS = (await import('crypto-js')).default;
139
176
  const key = CryptoJS.PBKDF2(passPhrase, CryptoJS.enc.Hex.parse(salt), {
@@ -348,11 +385,11 @@ const shortcutController = new class ShortcutController {
348
385
  }
349
386
  parseKey(keyString) {
350
387
  const elements = keyString.split("&");
351
- const altKey = elements.includes("alt");
352
- const ctrlKey = elements.includes("ctrl");
353
- const shiftKey = elements.includes("shift");
388
+ const altKey = !!elements.find((c) => c.toLowerCase() === "alt");
389
+ const ctrlKey = !!elements.find((c) => c.toLowerCase() === "ctrl");
390
+ const shiftKey = !!elements.find((c) => c.toLowerCase() === "shift");
354
391
  const key = elements.find(
355
- (current) => current !== "shift" && current !== "alt" && current !== "ctrl"
392
+ (current) => current.toLocaleLowerCase() !== "shift" && current.toLocaleLowerCase() !== "alt" && current.toLocaleLowerCase() !== "ctrl"
356
393
  );
357
394
  if (!key)
358
395
  throw new Error(`parseKey "${keyString}" does not have key.`);
@@ -584,6 +621,26 @@ function findOffsetRelativeToScrollParent(element, which = "Top") {
584
621
  return offset - scrollAmount;
585
622
  }
586
623
 
624
+ function isFocusable(element) {
625
+ if (element.disabled)
626
+ return false;
627
+ if (!element.isConnected)
628
+ return false;
629
+ if (element.offsetParent === null && getComputedStyle(element).position !== "fixed")
630
+ return false;
631
+ const tabIndex = element.getAttribute("tabindex");
632
+ if (tabIndex !== null && parseInt(tabIndex, 10) >= 0)
633
+ return true;
634
+ const focusableTags = ["INPUT", "SELECT", "TEXTAREA", "BUTTON"];
635
+ if (focusableTags.includes(element.tagName))
636
+ return true;
637
+ if (element.tagName === "A" && element.hasAttribute("href"))
638
+ return true;
639
+ if (element.hasAttribute("contenteditable") && element.getAttribute("contenteditable") !== "false")
640
+ return true;
641
+ return false;
642
+ }
643
+
587
644
  const scrollIntervals = {};
588
645
  function scrollParentIntoElement(element, fixedOffsetTop = 0, tries = 2, timeout = 100, scrollId) {
589
646
  const id = scrollId ?? `${Date.now()}_${Math.random()}`;
@@ -1758,6 +1815,12 @@ function awaitTime(ms) {
1758
1815
  });
1759
1816
  }
1760
1817
 
1818
+ class CancellablePromise extends Promise {
1819
+ constructor(executor, cancel) {
1820
+ super(executor);
1821
+ this.cancel = cancel;
1822
+ }
1823
+ }
1761
1824
  class Semaphore {
1762
1825
  /**
1763
1826
  * Creates a new instance of the Semaphore.
@@ -1789,9 +1852,16 @@ class Semaphore {
1789
1852
  this.current++;
1790
1853
  return Promise.resolve();
1791
1854
  }
1792
- return new Promise((resolve) => {
1793
- this.queue.push(resolve);
1794
- });
1855
+ let resolver = null;
1856
+ return new CancellablePromise(
1857
+ (resolve) => {
1858
+ resolver = resolve;
1859
+ this.queue.push(resolve);
1860
+ },
1861
+ () => {
1862
+ this.queue = this.queue.filter((c) => c !== resolver);
1863
+ }
1864
+ );
1795
1865
  }
1796
1866
  /**
1797
1867
  * Releases a previously acquired permit.
@@ -1819,6 +1889,9 @@ class TasksQueue {
1819
1889
  constructor() {
1820
1890
  this.mutex = new Mutex();
1821
1891
  }
1892
+ get isBusy() {
1893
+ return this.mutex.isBusy;
1894
+ }
1822
1895
  async run(task) {
1823
1896
  await this.mutex.acquire();
1824
1897
  try {
@@ -2413,9 +2486,10 @@ const formatMessage = (str, obj) => {
2413
2486
  return newStr;
2414
2487
  };
2415
2488
 
2416
- function getLabel(name, replaceTokens) {
2489
+ function getLabel(name, replaceTokens, outerWindow) {
2490
+ const actualWindow = outerWindow ?? window;
2417
2491
  const label = {
2418
- ...window.labels[name] ?? {
2492
+ ...actualWindow.labels[name] ?? {
2419
2493
  text: `Not preloaded: ${name}`,
2420
2494
  title: `Not preloaded: ${name}`
2421
2495
  }
@@ -2982,5 +3056,5 @@ const postNavigation = (url, data) => {
2982
3056
  form.submit();
2983
3057
  };
2984
3058
 
2985
- 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, defaultGetNameFromResponse, disableChildrenFocus, downloadStringAsDoc, downloadUrl, enableChildrenFocus, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, freezeDeep, getDateFormat, getFocusSelector, getIndex, getJSObjFromXML, getLabel, getSpecificParent, getValueByPath, globalFocus, globals, isChild, isDebugDispatcherEnabled, 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 };
3059
+ 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, 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 };
2986
3060
  //# sourceMappingURL=index.js.map