@apia/util 3.0.10 → 3.0.11

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
@@ -4,6 +4,17 @@ import { AxiosResponse } from 'axios';
4
4
 
5
5
  declare function animate(duration: number, callback: (progress: number) => unknown, onFinish?: () => unknown): () => void;
6
6
 
7
+ type AudioRecorderState = {
8
+ recording: boolean;
9
+ };
10
+ declare class AudioRecorder {
11
+ private mediaRecorder;
12
+ state: AudioRecorderState;
13
+ constructor();
14
+ start(): Promise<Blob>;
15
+ stop(): void;
16
+ }
17
+
7
18
  declare function arrayOrArray<T>(o: T | T[] | undefined): T[];
8
19
 
9
20
  /**
@@ -140,7 +151,7 @@ declare function downloadUrl(url: string, getNameFromResponse?: (blob: AxiosResp
140
151
  */
141
152
  declare function downloadUrl(url: string, fileName: string): Promise<void>;
142
153
 
143
- declare function openAndReadFile(): Promise<string | ArrayBuffer | null>;
154
+ declare function openAndReadFile(accept?: string): Promise<string | ArrayBuffer | null>;
144
155
  type TReadFile = {
145
156
  content: string | ArrayBuffer;
146
157
  name: string;
@@ -1033,9 +1044,11 @@ declare class History<T> extends EventEmitter<{
1033
1044
  emit<K extends 'stepChange'>(eventName: K, params?: THistoryStepChange<T>): void;
1034
1045
  enable: () => void;
1035
1046
  forward: () => void;
1047
+ getContent(): T[];
1036
1048
  get isOpen(): boolean;
1037
1049
  openWindow: () => void;
1038
1050
  reset: () => void;
1051
+ runInWindow(cb: () => Promise<void>): Promise<void>;
1039
1052
  updateConfig: (newConfiguration: Partial<THistoryConfiguration<T>>) => void;
1040
1053
  useStep: () => Pick<THistoryStepChange<T>, "hasNext" | "hasPrevious" | "currentStep">;
1041
1054
  }
@@ -1246,7 +1259,7 @@ declare function getLabel(name: string, replaceTokens?: {
1246
1259
  title?: Record<string, string>;
1247
1260
  }): {
1248
1261
  text: string;
1249
- tooltip: string;
1262
+ title: string;
1250
1263
  };
1251
1264
 
1252
1265
  /**
@@ -1874,5 +1887,5 @@ declare function toBoolean(value: unknown): boolean;
1874
1887
 
1875
1888
  declare const parseXmlAsync: <T>(xml: string) => Promise<T>;
1876
1889
 
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 };
1890
+ export { AudioRecorder, type AudioRecorderState, 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 };
1878
1891
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import React__default, { useRef, useCallback, useState, useEffect, useMemo, createContext, useContext } from 'react';
4
4
  import uniqueId from 'lodash-es/uniqueId';
5
+ import { makeAutoObservable } from 'mobx';
5
6
  import isFunction from 'lodash-es/isFunction';
6
7
  import dayjs from 'dayjs';
7
8
  import customParseFormat from 'dayjs/plugin/customParseFormat';
@@ -71,6 +72,48 @@ function animate(duration, callback, onFinish) {
71
72
  };
72
73
  }
73
74
 
75
+ class AudioRecorder {
76
+ constructor() {
77
+ this.mediaRecorder = null;
78
+ this.state = {
79
+ recording: false
80
+ };
81
+ makeAutoObservable(this);
82
+ }
83
+ async start() {
84
+ if (this.state.recording) {
85
+ throw new Error("Cannot start a recording while other in progress");
86
+ }
87
+ return new Promise((resolve) => {
88
+ (async () => {
89
+ try {
90
+ this.state.recording = true;
91
+ const audioChunks = [];
92
+ const stream = await navigator.mediaDevices.getUserMedia({
93
+ audio: true
94
+ });
95
+ this.mediaRecorder = new MediaRecorder(stream);
96
+ this.mediaRecorder.ondataavailable = (event) => {
97
+ audioChunks.push(event.data);
98
+ };
99
+ this.mediaRecorder.onstop = async () => {
100
+ const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
101
+ resolve(audioBlob);
102
+ this.state.recording = false;
103
+ };
104
+ this.mediaRecorder.start();
105
+ } catch (e) {
106
+ this.state.recording = false;
107
+ throw e;
108
+ }
109
+ })();
110
+ });
111
+ }
112
+ stop() {
113
+ this.mediaRecorder?.stop();
114
+ }
115
+ }
116
+
74
117
  function arrayOrArray(o) {
75
118
  if (o === void 0)
76
119
  return [];
@@ -375,11 +418,12 @@ async function downloadUrl(url, secondParameter = defaultGetNameFromResponse) {
375
418
  );
376
419
  }
377
420
 
378
- function openAndReadFile() {
421
+ function openAndReadFile(accept) {
379
422
  return new Promise((resolve) => {
380
423
  const input = document.createElement("input");
381
424
  input.type = "file";
382
425
  input.style.display = "none";
426
+ input.accept = accept || "*";
383
427
  document.body.append(input);
384
428
  input.click();
385
429
  input.addEventListener("change", (ev) => {
@@ -2064,7 +2108,11 @@ class History extends EventEmitter {
2064
2108
  return hasPrevious;
2065
2109
  };
2066
2110
  this.configuration = Object.assign({ maxLength: 15 }, configuration);
2067
- this.content.push(configuration?.initialContent ?? null);
2111
+ if (configuration?.initialContent !== void 0) {
2112
+ this.content.push(configuration?.initialContent ?? null);
2113
+ } else {
2114
+ this.currentStep = -1;
2115
+ }
2068
2116
  this.onCloseWindow = onCloseWindow;
2069
2117
  }
2070
2118
  emit(eventName, params) {
@@ -2075,9 +2123,16 @@ class History extends EventEmitter {
2075
2123
  this.emitting--;
2076
2124
  }
2077
2125
  }
2126
+ getContent() {
2127
+ return this.content;
2128
+ }
2078
2129
  get isOpen() {
2079
2130
  return this._isOpen;
2080
2131
  }
2132
+ async runInWindow(cb) {
2133
+ await cb();
2134
+ this.onCloseWindow(this.push.bind(this));
2135
+ }
2081
2136
  }
2082
2137
 
2083
2138
  const ImperativeComponentContext = createContext(
@@ -2209,7 +2264,7 @@ function getLabel(name, replaceTokens) {
2209
2264
  if (replaceTokens?.text !== void 0)
2210
2265
  label.text = formatMessage(label.text, replaceTokens.text);
2211
2266
  if (replaceTokens?.title !== void 0)
2212
- label.tooltip = formatMessage(label.tooltip, replaceTokens.title);
2267
+ label.title = formatMessage(label.title, replaceTokens.title);
2213
2268
  return label;
2214
2269
  }
2215
2270
 
@@ -2638,5 +2693,5 @@ const parseXmlAsync = async (xml) => {
2638
2693
  return result;
2639
2694
  };
2640
2695
 
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 };
2696
+ export { AudioRecorder, 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 };
2642
2697
  //# sourceMappingURL=index.js.map