@apia/util 0.1.3 → 0.2.4

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
@@ -1,8 +1,6 @@
1
- import * as React$1 from 'react';
1
+ import * as React from 'react';
2
2
  import React__default, { EffectCallback, Dispatch, SetStateAction, MutableRefObject, DependencyList, FC, HTMLAttributes } from 'react';
3
3
  import { AxiosResponse } from 'axios';
4
- import * as theme_ui_jsx_runtime from 'theme-ui/jsx-runtime';
5
- import { TIconName, TIconType } from '@apia/icons';
6
4
 
7
5
  declare function animate(duration: number, callback: (progress: number) => unknown, onFinish?: () => unknown): () => void;
8
6
 
@@ -182,114 +180,6 @@ declare function usePanAndZoom<ContainerType extends HTMLElement = HTMLElement,
182
180
  elementRef: React__default.RefObject<ChildType>;
183
181
  };
184
182
 
185
- type TEventMap = Record<string, any>;
186
- type TEventKey<T extends TEventMap> = string & keyof T;
187
- type TEventReceiver<T> = (params: T) => unknown;
188
- type TFun = () => unknown;
189
- interface IEmitter<T extends TEventMap> {
190
- on<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): TFun;
191
- off<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): unknown;
192
- emit<K extends TEventKey<T>>(eventName: K, params?: T[K]): unknown;
193
- }
194
- /**
195
- * EventEmitter muy sencillo.
196
- *
197
- * El siguiente ejemplo es un fragmento de una clase
198
- * perteneciente al grupo de wai-aria helpers. Ver que el método #shout nada
199
- * tiene que ver con la clase EventEmitter, sino que es un método interno de la
200
- * clase WaiTypeAhead.
201
- *
202
- * Lo que realmente importa en el ejemplo es el tipado (Lo que va luego de
203
- * extends EventEmitter) y el this.emit en la creación del emitter; por otra
204
- * parte es importante el (instance).on(...) que se muestra al final del
205
- * ejemplo, que permite realizar suscripciones al EventEmitter creado.
206
- *
207
- * Además, es notable que cuando se realiza una suscripción mediante
208
- * (instance).on, este método devuelve un método que al ser llamado rompe la
209
- * suscripción; esto nos da la firma del método on como:
210
- *
211
- * on(eventName: string, callback: (ev: eventType) => unknown): Unsuscriptor;
212
- *
213
- * @example
214
- *
215
- * // Event emitter creation
216
- *
217
- * class WaiTypeAhead extends EventEmitter<{
218
- multipleKeys: string;
219
- singleKey: string;
220
- }> {
221
- // ...
222
- #shout({ clear } = { clear: true }) {
223
- if (this.typing.length === 1) {
224
- this.emit('singleKey', this.typing);
225
- } else if (this.typing.length > 1) {
226
- this.emit('multipleKeys', this.typing);
227
- }
228
- // ...
229
- }
230
- // ...
231
- }
232
-
233
- // Usage
234
-
235
- const wtype = new WaiTypeAhead();
236
- wtype.on('multipleKeys', (typing) => {
237
- write(`Multiple: ${typing}`);
238
- });
239
- */
240
- declare class EventEmitter<T extends TEventMap> implements IEmitter<T> {
241
- #private;
242
- on<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): () => void;
243
- off<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): void;
244
- emit<K extends TEventKey<T>>(eventName: K, params?: T[K]): void;
245
- }
246
-
247
- type TLiveEvent = {
248
- message: string;
249
- type: 'polite' | 'assertive' | 'reset';
250
- };
251
- /**
252
- * Este método se utiliza para emitir mensajes
253
- * a los usuarios con discapacidades. **IMPORTANTE:
254
- * El empleo de esta herramienta debe ser analizado
255
- * a conciencia**.
256
- *
257
- * **La forma que considero correcta de analizar el
258
- * problema es:**
259
- *
260
- * Si yo fuera un usuario ciego o discapacitado, qué
261
- * tipo de mensaje me gustaría recibir para entender
262
- * el uso de las herramientas en el contexto actual.
263
- *
264
- * Si se encuentra que esta forma de analizar el
265
- * problema tiene fallos o carencias, por favor
266
- * iniciar la discusión correspondiente ya que la idea
267
- * es ir mejorando esta herramienta.
268
- *
269
- * **El uso es muy sencillo:**
270
- *
271
- * Al llamar al método
272
- * AriaLiveEmitter.emit({ live: 'polite' | 'assertive',
273
- * message: 'un mensaje' }), se actualiza un div para
274
- * que contenta estas características, lo que termina
275
- * leyendo dicho mensaje al usuario.
276
- */
277
- declare const AriaLiveEmitter: {
278
- "__#1@#emitter": IEmitter<{
279
- live: TLiveEvent;
280
- }>;
281
- on<K extends "live">(eventName: K, fn: TEventReceiver<{
282
- live: TLiveEvent;
283
- }[K]>): () => void;
284
- off<K_1 extends "live">(eventName: K_1, fn: TEventReceiver<{
285
- live: TLiveEvent;
286
- }[K_1]>): void;
287
- emit<K_2 extends "live">(eventName: K_2, params?: {
288
- live: TLiveEvent;
289
- }[K_2] | undefined): void;
290
- };
291
- declare const LiveRegion: () => theme_ui_jsx_runtime.JSX.Element;
292
-
293
183
  /**
294
184
  * Existen algunos eventos que se disparan en la
295
185
  * aplicación con la finalidad de desencadenar
@@ -415,6 +305,68 @@ declare function disableChildrenFocus(parent: HTMLElement): void;
415
305
  */
416
306
  declare function enableChildrenFocus(parent: HTMLElement): void;
417
307
 
308
+ type TEventMap = Record<string, any>;
309
+ type TEventKey<T extends TEventMap> = string & keyof T;
310
+ type TEventReceiver<T> = (params: T) => unknown;
311
+ type TFun = () => unknown;
312
+ interface IEmitter<T extends TEventMap> {
313
+ on<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): TFun;
314
+ off<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): unknown;
315
+ emit<K extends TEventKey<T>>(eventName: K, params?: T[K]): unknown;
316
+ }
317
+ /**
318
+ * EventEmitter muy sencillo.
319
+ *
320
+ * El siguiente ejemplo es un fragmento de una clase
321
+ * perteneciente al grupo de wai-aria helpers. Ver que el método #shout nada
322
+ * tiene que ver con la clase EventEmitter, sino que es un método interno de la
323
+ * clase WaiTypeAhead.
324
+ *
325
+ * Lo que realmente importa en el ejemplo es el tipado (Lo que va luego de
326
+ * extends EventEmitter) y el this.emit en la creación del emitter; por otra
327
+ * parte es importante el (instance).on(...) que se muestra al final del
328
+ * ejemplo, que permite realizar suscripciones al EventEmitter creado.
329
+ *
330
+ * Además, es notable que cuando se realiza una suscripción mediante
331
+ * (instance).on, este método devuelve un método que al ser llamado rompe la
332
+ * suscripción; esto nos da la firma del método on como:
333
+ *
334
+ * on(eventName: string, callback: (ev: eventType) => unknown): Unsuscriptor;
335
+ *
336
+ * @example
337
+ *
338
+ * // Event emitter creation
339
+ *
340
+ * class WaiTypeAhead extends EventEmitter<{
341
+ multipleKeys: string;
342
+ singleKey: string;
343
+ }> {
344
+ // ...
345
+ #shout({ clear } = { clear: true }) {
346
+ if (this.typing.length === 1) {
347
+ this.emit('singleKey', this.typing);
348
+ } else if (this.typing.length > 1) {
349
+ this.emit('multipleKeys', this.typing);
350
+ }
351
+ // ...
352
+ }
353
+ // ...
354
+ }
355
+
356
+ // Usage
357
+
358
+ const wtype = new WaiTypeAhead();
359
+ wtype.on('multipleKeys', (typing) => {
360
+ write(`Multiple: ${typing}`);
361
+ });
362
+ */
363
+ declare class EventEmitter<T extends TEventMap> implements IEmitter<T> {
364
+ #private;
365
+ on<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): () => void;
366
+ off<K extends TEventKey<T>>(eventName: K, fn: TEventReceiver<T[K]>): void;
367
+ emit<K extends TEventKey<T>>(eventName: K, params?: T[K]): void;
368
+ }
369
+
418
370
  /**
419
371
  * Esta clase ofrece la posibilidad de crear una variable que al ser
420
372
  * actualizada avisa sobre la actualización.
@@ -855,10 +807,11 @@ declare const focus: {
855
807
  id: string;
856
808
  name: string;
857
809
  selector: string;
858
- }, "className" | "id" | "name" | "selector">): void;
810
+ }, "name" | "className" | "id" | "selector">): void;
859
811
  /**
860
812
  * Da la instrucción de colocar el foco el elemento pasado como parámetro.
861
- * Se puede pasar también una función que devuelva HTMLElement | false | null.
813
+ * Se puede pasar también una función que devuelva HTMLElement | false |
814
+ * null.
862
815
  *
863
816
  * El segundo parámetro del método on es un objeto de tipo
864
817
  * ScrollIntoViewOptions, que permite modificar el comportamiento del scroll
@@ -904,7 +857,7 @@ declare const globalFocus: {
904
857
  *
905
858
  * return <Box ref={assignRefs} ...
906
859
  */
907
- declare function useCombinedRefs<RefType = HTMLInputElement>(...refs: (React$1.ForwardedRef<unknown> | undefined)[]): React$1.Dispatch<React$1.SetStateAction<RefType | undefined>>;
860
+ declare function useCombinedRefs<RefType = HTMLInputElement>(...refs: (React.ForwardedRef<unknown> | undefined)[]): React.Dispatch<React.SetStateAction<RefType | undefined>>;
908
861
 
909
862
  declare const useDebouncedCallback: <Params extends any[]>(callback: (...params: Params) => unknown, { runWhenTriggered, timeout }?: {
910
863
  runWhenTriggered: boolean;
@@ -918,13 +871,13 @@ declare const useDebouncedCallback: <Params extends any[]>(callback: (...params:
918
871
  *
919
872
  * *Investigar qué es 'react stale state'*
920
873
  */
921
- declare function useLatest<T>(value: T): React$1.MutableRefObject<T>;
874
+ declare function useLatest<T>(value: T): React.MutableRefObject<T>;
922
875
 
923
876
  declare function useMount(effect: EffectCallback): void;
924
877
 
925
878
  declare function useUnmount(unmountCallback: () => void): void;
926
879
 
927
- declare function usePrevious<T>(value: T): React$1.MutableRefObject<T | undefined>;
880
+ declare function usePrevious<T>(value: T): React.MutableRefObject<T | undefined>;
928
881
 
929
882
  declare function useStateRef<T>(initialState?: T): [
930
883
  typeof initialState extends undefined ? T | undefined : T,
@@ -1022,23 +975,14 @@ declare function useImperativeComponentContext<Events extends TMap = TMap>(): {
1022
975
  eventsStore: TEventsHandlers<Events>;
1023
976
  };
1024
977
 
1025
- declare global {
1026
- interface Window {
1027
- labels: {
1028
- [key: string]: {
1029
- text: string;
1030
- tooltip: string;
1031
- };
1032
- };
1033
- }
1034
- }
1035
978
  /**
1036
979
  * Dado un nombre de etiqueta, devuelve el texto que esa etiqueta contiene en
1037
980
  * el idioma actual. En este momento, lo único que hace realmente esta función
1038
- * es devolver la variable del window con el mismo nombre que se está pidiendo.
981
+ * es devolver la variable del window con el mismo nombre que se está
982
+ * pidiendo.
1039
983
  *
1040
- * La idea de implementar esta función, es que en un futuro la fuente de la que
1041
- * provienen las labels pueda ser más diversa.
984
+ * La idea de implementar esta función, es que en un futuro la fuente de la
985
+ * que provienen las labels pueda ser más diversa.
1042
986
  *
1043
987
  * Permite el pasaje de tokens para el reemplazo automático de los mismos.
1044
988
  *
@@ -1080,99 +1024,6 @@ declare const formatMessage: (str: string, obj: {
1080
1024
  [key: string]: string;
1081
1025
  }) => string;
1082
1026
 
1083
- type TTabRenderer<AdditionalPropsType extends Record<string, unknown> = Record<string, unknown>> = (props: {
1084
- tab: TTab<AdditionalPropsType>;
1085
- }) => React.ReactElement;
1086
- type TApiaTabProps = {
1087
- originalUrl: string;
1088
- url: string;
1089
- };
1090
- type TTab<AdditionalPropsType extends Record<string, unknown> = Record<string, unknown>> = {
1091
- content: React.FunctionComponent<{
1092
- tab: TTab<AdditionalPropsType>;
1093
- }>;
1094
- icon?: TIconName | TIconType;
1095
- /**
1096
- * El id es importante ya que se utiliza por temas de accesibilidad. Es
1097
- * importante asegurarse de que sea único.*/
1098
- id: TId;
1099
- isClosable?: boolean;
1100
- isDisabled?: boolean;
1101
- /**
1102
- * Los tabs que estén marcados como fixed aparecerán al inicio del listado.
1103
- */
1104
- isFixed?: boolean;
1105
- isFocused?: boolean;
1106
- /**
1107
- * Si se marca como iconTab, se oculta el label y solamente se muestra el
1108
- * ícono.
1109
- */
1110
- isIconTab?: boolean;
1111
- isLoading?: boolean;
1112
- isOpen?: boolean;
1113
- /**
1114
- * Cuando se cierra un tab que tiene un método onBeforeClose, el mismo será
1115
- * llamado y deberá devolver un boolean o un string. Si devuelve true, se
1116
- * cierra. Si devuelve false, se muestra un cartel de confirmación genérico y
1117
- * si se devuelve un string, se muestra un cartel de confirmación con el
1118
- * string devuelto. En caso de que el usuario confirme el cuadro de diálogo,
1119
- * el tab será cerrado de todas formas. Es decir, no hay forma de evitar que
1120
- * el tab sea cerrado si el usuario decide continuar con la acción. Para
1121
- * evitar que un tab sea cerrado, debe pasarse isClosable=false
1122
- */
1123
- onBeforeClose?: () => boolean | string | Promise<boolean | string>;
1124
- /**
1125
- * Este callback será llamado cada vez que el tab sea abierto
1126
- */
1127
- onFocus?: (ev: TTab<AdditionalPropsType>) => unknown;
1128
- /**
1129
- * Es el texto que se va a mostrar en el tab
1130
- */
1131
- label: string;
1132
- labelRenderer?: TTabRenderer;
1133
- /**
1134
- * Se pueden pasar propiedades adicionales que serán recibidas en cada
1135
- * evento, de forma de poder compartir piezas de información útiles en las
1136
- * distintas partes de la aplicación.
1137
- */
1138
- tabAdditionalProps: AdditionalPropsType;
1139
- title?: string;
1140
- };
1141
- interface IMainTabsController<AdditionalPropsType extends Record<string, unknown> = Record<string, unknown>, TabType extends TTab<AdditionalPropsType> = TTab<AdditionalPropsType>> {
1142
- activeTabs: TabType[];
1143
- tabsList: TId[];
1144
- append(tab: Omit<TabType, 'tabAdditionalProps'> & Partial<Pick<TabType, 'tabAdditionalProps'>>): void;
1145
- closeAll(closeFixedTabsAsWell?: boolean, force?: boolean): Promise<void>;
1146
- closeToRight(targetId: TId): Promise<void>;
1147
- closeToLeft(targetId: TId): Promise<void>;
1148
- closeOthers(targetId: TId): Promise<void>;
1149
- closeTab(tabId: TId, force?: boolean): Promise<boolean>;
1150
- focusNextTab(): TId | null;
1151
- focusPreviousTab(): TId | null;
1152
- focusTab(tabId: TId): void;
1153
- getTabById(tabId: TId): TabType;
1154
- getTabElement(tabId: TId): Element | null;
1155
- handleKeyDown(ev: React.KeyboardEvent): void;
1156
- openNextTab(): TId | null;
1157
- openPreviousTab(): TId | null;
1158
- openTab(tabId: TId, justThis?: boolean): void;
1159
- }
1160
- interface ITabsController {
1161
- handler: IMainTabsController<TApiaTabProps>;
1162
- handlerSet: boolean;
1163
- closeActiveTab(force?: boolean): void;
1164
- closeAll(closeFixedTabsAsWell?: boolean, force?: boolean): void;
1165
- openMainMenu(): void;
1166
- openTabByUrl(title: string, url: string, options?: IOpenTabOptions): void;
1167
- setHandler(handler: IMainTabsController<TApiaTabProps>): void;
1168
- changeTabState(): void;
1169
- }
1170
- interface IOpenTabOptions {
1171
- funcId?: TId;
1172
- keepMenuOpen?: boolean;
1173
- parentTabId?: string;
1174
- }
1175
-
1176
1027
  interface ISetBoundary {
1177
1028
  number?: number | string;
1178
1029
  min?: number;
@@ -1504,7 +1355,7 @@ declare const screenLocker: {
1504
1355
  unlock(lockName?: string): void;
1505
1356
  force(): void;
1506
1357
  releaseForced(): void;
1507
- "__#1@#emitter": IEmitter<{
1358
+ "__#2@#emitter": IEmitter<{
1508
1359
  forcedStateChange: {
1509
1360
  hasReleasedFirstTime: boolean;
1510
1361
  isForced: boolean;
@@ -1637,10 +1488,4 @@ declare function toBoolean(value: unknown): boolean;
1637
1488
 
1638
1489
  declare const parseXmlAsync: <T>(xml: string) => Promise<T>;
1639
1490
 
1640
- declare global {
1641
- interface Window {
1642
- [key: string]: string;
1643
- }
1644
- }
1645
-
1646
- export { AriaLiveEmitter, EventEmitter, IOnFocusConfiguration, IParameter, ISetBoundary, ITabsController, LiveRegion, PropsSelectorUndefinedObject, PropsStore, TApiaAction, TApiaActions, TApiaCellDefinition, TApiaComplexCell, TApiaFieldPropsObj, TApiaFilter, TApiaFilterOption, TApiaFilterValue, TApiaFormButton, TApiaFormElement, TApiaFormElementOption, TApiaFunction, TApiaFunctionPageInfo, TApiaLoad, TApiaLoadForm, TApiaLoadText, TApiaMessage, TApiaMultiplePossibleValue, TApiaPossibleValue, TApiaRadioPossibleValue, TApiaRowDefinition, TApiaSelectPossibleValue, TApiaSystemMessageObj, TApiaTableFunction, TCallback, TDateFormat, TDispatchCallback, TFieldEvent, TFieldScriptEvent, TFieldScriptEvents, TFieldServerEvent, TFieldServerEvents, TFncParams, TFocusRetriever, TId, TKey, TMap$1 as TMap, TMessage, TModify, TNotificationMessage, TPropsComparator, TPropsConfiguration, TPropsSelector, TRequireOnlyOne, TShortcutBranch, TUpdateFieldConfiguration, Url, WithEventsValue, addBoundary, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, cantFocusSelector, customEvents, dateToApiaFormat, debugDispatcher, decrypt, disableChildrenFocus, downloadUrl, enableChildrenFocus, enableDebugDispatcher, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, getDateFormat, getFocusSelector, getIndex, getLabel, getSpecificParent, getValueByPath, globalFocus, isChild, isDebugDispatcherEnabled, isPropsConfigurationObject, makeImperativeComponent, makeSingleImperativeComponent, noNaN, notificationsSelector, parseAsSize, parseXmlAsync, persistentStorage, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shortcutController, toBoolean, ucfirst, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useLatest, useLocalStorage, useMount, usePanAndZoom, usePrevious, usePropsSelector, useStateRef, useUnmount, useUpdateEffect };
1491
+ export { EventEmitter, IOnFocusConfiguration, IParameter, ISetBoundary, PropsSelectorUndefinedObject, PropsStore, TApiaAction, TApiaActions, TApiaCellDefinition, TApiaComplexCell, TApiaFieldPropsObj, TApiaFilter, TApiaFilterOption, TApiaFilterValue, TApiaFormButton, TApiaFormElement, TApiaFormElementOption, TApiaFunction, TApiaFunctionPageInfo, TApiaLoad, TApiaLoadForm, TApiaLoadText, TApiaMessage, TApiaMultiplePossibleValue, TApiaPossibleValue, TApiaRadioPossibleValue, TApiaRowDefinition, TApiaSelectPossibleValue, TApiaSystemMessageObj, TApiaTableFunction, TCallback, TDateFormat, TDispatchCallback, TFieldEvent, TFieldScriptEvent, TFieldScriptEvents, TFieldServerEvent, TFieldServerEvents, TFncParams, TFocusRetriever, TId, TKey, TMap$1 as TMap, TMessage, TModify, TNotificationMessage, TPropsComparator, TPropsConfiguration, TPropsSelector, TRequireOnlyOne, TShortcutBranch, TUpdateFieldConfiguration, Url, WithEventsValue, addBoundary, animate, apiaDateToStandarFormat, arrayOrArray, autoDisconnectMutationObserver, cantFocusSelector, customEvents, dateToApiaFormat, debugDispatcher, decrypt, disableChildrenFocus, downloadUrl, enableChildrenFocus, enableDebugDispatcher, encrypt, findOffsetRelativeToScrollParent, findScrollContainer, focus, focusSelector, formatMessage, getDateFormat, getFocusSelector, getIndex, getLabel, getSpecificParent, getValueByPath, globalFocus, isChild, isDebugDispatcherEnabled, isPropsConfigurationObject, makeImperativeComponent, makeSingleImperativeComponent, noNaN, notificationsSelector, parseAsSize, parseXmlAsync, persistentStorage, propsStore, screenLocker, scrollParentIntoElement, setValueByPath, shortcutController, toBoolean, ucfirst, useCombinedRefs, useDebouncedCallback, useDebouncedState, useDomState, useImperativeComponentContext, useImperativeComponentEvents, useLatest, useLocalStorage, useMount, usePanAndZoom, usePrevious, usePropsSelector, useStateRef, useUnmount, useUpdateEffect };