@apia/api 3.0.1 → 3.0.6

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.
@@ -1,15 +0,0 @@
1
- import { jsx } from '@apia/theme/jsx-runtime';
2
- import * as React from 'react';
3
- import { createContext } from 'react';
4
-
5
- const ApiaApiId = createContext("apiaApi");
6
- const ApiaApiContext = ({
7
- children,
8
- id
9
- }) => {
10
- return /* @__PURE__ */ jsx(ApiaApiId.Provider, { value: id, children });
11
- };
12
- var ApiaApiContext$1 = React.memo(ApiaApiContext);
13
-
14
- export { ApiaApiContext$1 as default };
15
- //# sourceMappingURL=ApiaApiContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApiaApiContext.js","sources":["../src/ApiaApiContext.tsx"],"sourcesContent":["import { createContext } from 'react';\nimport * as React from 'react';\n\nlet apiaApiId: string | undefined;\n\nexport function getApiaApiId() {\n if (!apiaApiId) throw new Error('There is no apia api id');\n return apiaApiId;\n}\n\nconst ApiaApiId = createContext<string | undefined>('apiaApi');\n\nconst ApiaApiContext = ({\n children,\n id,\n}: {\n id: string;\n children: React.ReactNode;\n}) => {\n apiaApiId = id;\n return <ApiaApiId.Provider value={id}>{children}</ApiaApiId.Provider>;\n};\n\nexport default React.memo(ApiaApiContext);\n"],"names":[],"mappings":";;;;AAUA,MAAM,SAAA,GAAY,cAAkC,SAAS,CAAA,CAAA;AAE7D,MAAM,iBAAiB,CAAC;AAAA,EACtB,QAAA;AAAA,EACA,EAAA;AACF,CAGM,KAAA;AAEJ,EAAA,2BAAQ,SAAU,CAAA,QAAA,EAAV,EAAmB,KAAA,EAAO,IAAK,QAAS,EAAA,CAAA,CAAA;AAClD,CAAA,CAAA;AAEA,uBAAe,KAAA,CAAM,KAAK,cAAc,CAAA;;;;"}
@@ -1,62 +0,0 @@
1
- import * as React from 'react';
2
- import { AxiosResponse } from 'axios';
3
- import { TApiaLoad, TModify, TApiaFormElement } from '@apia/util';
4
- import { notify } from '@apia/notifications';
5
- import { TModal } from '@apia/components';
6
- import { IApiaApiRequestConfig } from './types.js';
7
-
8
- type TMethod = {
9
- name: string;
10
- props: {
11
- attributes?: Record<string, unknown>;
12
- currentUrl?: string;
13
- funCall?: string;
14
- inlineArguments?: string[];
15
- messages?: unknown;
16
- };
17
- };
18
- type TApiaApiMethodHandler = {
19
- alert: typeof notify;
20
- close: () => void;
21
- configuration?: THandleConfiguration;
22
- formDefinition: TApiaLoad;
23
- setModalProps?: (configuration: THandleConfiguration, formDefinition?: TApiaLoad) => TModal | null;
24
- reset: () => void;
25
- setError: typeof notify;
26
- setMessage: (message: Record<string, unknown>) => unknown;
27
- setState: React.Dispatch<React.SetStateAction<IApiaApiHandlerState>>;
28
- state: IApiaApiHandlerState;
29
- setValue: (name: string, value: string) => void;
30
- };
31
- type TApiaApiMethod = (handler: TApiaApiMethodHandler, props: TMethod['props']) => Promise<void> | void;
32
- type TApiaApiField = TApiaApiMethodHandler & {
33
- element: TModify<TApiaFormElement, {
34
- onChange: React.ChangeEventHandler;
35
- }>;
36
- };
37
- type TStoredApiaApiMethod = (props?: TMethod['props']) => unknown;
38
- /**
39
- * Este método permite cargar en forma asíncrona un método que se encuentre
40
- * dentro del directorio /api/methods
41
- */
42
- declare function getFunction(name: string, handler: TApiaApiMethodHandler): Promise<TStoredApiaApiMethod | undefined>;
43
- interface IModalConfig {
44
- modalTitle?: string;
45
- onClose?: () => void;
46
- onMessage?: (message: Record<string, unknown>) => unknown;
47
- onMessageClose?: () => unknown;
48
- onSubmitted?: (handler: TApiaApiMethodHandler, response: AxiosResponse<Record<string, unknown> | null> | null) => unknown;
49
- }
50
- type THandleConfiguration = Partial<Pick<IApiaApiRequestConfig<unknown>, 'modalConfiguration' | 'methodsPath' | 'setModalProps'>>;
51
- interface IApiaApiHandlerState {
52
- disabled: boolean;
53
- isLoading: boolean;
54
- isMultipart: boolean;
55
- progress: number;
56
- errors: Record<string, string>;
57
- windowIndex: number;
58
- }
59
- declare const ApiaApiHandler: React.MemoExoticComponent<() => React.JSX.Element>;
60
-
61
- export { ApiaApiHandler, type IApiaApiHandlerState, type IModalConfig, type TApiaApiField, type TApiaApiMethod, type TApiaApiMethodHandler, type THandleConfiguration, getFunction };
62
- //# sourceMappingURL=ApiaApiHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApiaApiHandler.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,374 +0,0 @@
1
- import { jsx, jsxs } from '@apia/theme/jsx-runtime';
2
- import * as React from 'react';
3
- import { Box, getVariant } from '@apia/theme';
4
- import { EventEmitter, StatefulEmitter, arrayOrArray, focus, focusSelector, useLatest } from '@apia/util';
5
- import { notify } from '@apia/notifications';
6
- import { validationsStore, Form } from '@apia/validations';
7
- import { useModal, Modal, ProgressBar } from '@apia/components';
8
- import ApiaApiContext from './ApiaApiContext.js';
9
- import { ApiaActions } from './apiaApi.js';
10
- import { ApiaApiFieldsContainer } from './fields/ApiaApiFieldsContainer.js';
11
- import { ApiaApiButtonsContainer } from './buttons/ApiaApiButtonsContainer.js';
12
-
13
- const ApiaApiMessenger = new class extends EventEmitter {
14
- }();
15
- const FunctionsDispatcher = new class extends EventEmitter {
16
- }();
17
- const apiaApiForm = "ApiaApiForm";
18
- const methods = {};
19
- async function getFunction(name, handler) {
20
- return new Promise((resolve) => {
21
- try {
22
- const separateNameFromParametersRegex = /^\/?([\w\d_-]+)\/?(?:\(([^)]*)\))?$/;
23
- const match = name.match(separateNameFromParametersRegex);
24
- if (match) {
25
- const functionName = match[1];
26
- const parameters = match[2];
27
- const path = [
28
- ...handler.configuration?.methodsPath?.split("/").filter((current) => !!current) ?? [],
29
- functionName
30
- ].join("/");
31
- const storeMethodAndResolve = (result) => {
32
- if (typeof result.default !== "function")
33
- notFound();
34
- const method = result.default;
35
- methods[functionName] = (props) => {
36
- return method(handler, {
37
- ...props,
38
- inlineArguments: parameters?.split(",").map((argument) => {
39
- if (argument.startsWith("'") || argument.startsWith('"'))
40
- return argument.slice(1, argument.length - 1);
41
- return argument;
42
- }) ?? []
43
- });
44
- };
45
- resolve(methods[functionName]);
46
- };
47
- const notFound = () => {
48
- throw new Error(
49
- `${functionName}.ts not found at ${path}.ts nor ./${functionName}.ts`
50
- );
51
- };
52
- import(
53
- /* webpackChunkName: "api-methods-[request]" */
54
- `/api/methods/${path}.ts`
55
- ).then(storeMethodAndResolve).catch(() => {
56
- if (handler.configuration?.methodsPath !== void 0)
57
- import(
58
- /* webpackChunkName: "api-methods-[request]" */
59
- `/api/methods/${functionName}.ts`
60
- ).then(storeMethodAndResolve).catch(notFound);
61
- else {
62
- notFound();
63
- }
64
- });
65
- }
66
- } catch (e) {
67
- console.error(e);
68
- handler.reset();
69
- handler.setError({
70
- type: "danger",
71
- message: "Error while loading current method."
72
- });
73
- }
74
- });
75
- }
76
- function isForm(responseObject) {
77
- return responseObject.form !== void 0 && typeof responseObject.form === "object" && !!responseObject.form;
78
- }
79
- function isFunction(responseObject) {
80
- return typeof responseObject.canClose === "boolean" && typeof responseObject.type === "string" && !!responseObject.function;
81
- }
82
- function isMessage(responseObject) {
83
- if (typeof responseObject.canClose === "boolean" && typeof responseObject.type === "string" && typeof responseObject.text === "object" && responseObject.text && typeof responseObject.text.label === "string") {
84
- return true;
85
- }
86
- return false;
87
- }
88
- const modalConfigurationHandler = new StatefulEmitter();
89
- function useModalConfiguration() {
90
- const value = modalConfigurationHandler.useState("value");
91
- const latestValue = useLatest(value);
92
- return latestValue;
93
- }
94
- const currentFormDispatcher = new class currentFormDispatcher2 extends EventEmitter {
95
- emit(eventName, params) {
96
- super.emit(eventName, params);
97
- }
98
- }();
99
- function handle(responseObject, currentUrl, configuration) {
100
- modalConfigurationHandler.setState("value", configuration);
101
- if (isForm(responseObject)) {
102
- currentFormDispatcher.emit("form", responseObject);
103
- return true;
104
- }
105
- if (isFunction(responseObject)) {
106
- FunctionsDispatcher.emit("method", {
107
- name: responseObject.function.name,
108
- props: {
109
- messages: responseObject.function.messages,
110
- attributes: responseObject.function,
111
- currentUrl
112
- }
113
- });
114
- return true;
115
- }
116
- if (isMessage(responseObject)) {
117
- ApiaApiMessenger.emit("message", {
118
- predicate: responseObject.text.content,
119
- title: responseObject.text.title
120
- });
121
- return true;
122
- }
123
- return false;
124
- }
125
- const initialState = {
126
- disabled: false,
127
- isLoading: false,
128
- isMultipart: false,
129
- progress: 0,
130
- errors: {}
131
- };
132
- const ApiaApiHandlerNonMemoized = () => {
133
- const configuration = useModalConfiguration();
134
- const [state, setState] = React.useState({
135
- ...initialState,
136
- windowIndex: -1
137
- });
138
- const [currentForm2, setCurrentForm] = React.useState(
139
- void 0
140
- );
141
- React.useEffect(() => {
142
- return currentFormDispatcher.on("form", setCurrentForm);
143
- }, []);
144
- const setValue = React.useCallback((name, value) => {
145
- return validationsStore.setFieldValue(apiaApiForm, name, value);
146
- }, []);
147
- React.useEffect(() => {
148
- if (!currentForm2)
149
- return;
150
- const elements = arrayOrArray(currentForm2?.form?.elements?.element ?? []);
151
- let isMultipart = false;
152
- const elementsValues = Object.values(elements);
153
- let i = 0;
154
- while (i < elementsValues.length && !isMultipart) {
155
- if (elementsValues[i++].type === "file") {
156
- isMultipart = true;
157
- }
158
- }
159
- setState((currentState) => {
160
- return {
161
- ...currentState,
162
- ...initialState,
163
- isMultipart
164
- };
165
- });
166
- }, [currentForm2]);
167
- const { show, onClose, ...modalHookProps } = useModal();
168
- const close = React.useCallback(() => {
169
- onClose();
170
- currentFormDispatcher.emit("form", void 0);
171
- setState((currentState) => {
172
- return { ...currentState, ...initialState };
173
- });
174
- configuration.current?.modalConfiguration?.onClose?.();
175
- validationsStore.unregisterForm(apiaApiForm);
176
- }, [onClose, configuration]);
177
- const modalRef = React.useRef(null);
178
- React.useEffect(() => {
179
- const elements = modalRef.current?.querySelectorAll(
180
- "a,input,textarea,button"
181
- );
182
- if (elements?.length === 1)
183
- void focus.on([...elements][0]);
184
- });
185
- const setError = React.useCallback(
186
- (notification) => {
187
- notify({ ...notification });
188
- },
189
- []
190
- );
191
- const initialFocusGetter = React.useCallback((ref) => {
192
- return ref?.querySelector(focusSelector);
193
- }, []);
194
- const defaultModalProps = React.useMemo(
195
- () => ({
196
- onClose: close,
197
- id: apiaApiForm,
198
- title: configuration.current?.modalConfiguration?.modalTitle ?? currentForm2?.form.title,
199
- size: "md-fixed",
200
- shouldCloseOnEsc: !state.disabled,
201
- shouldCloseOnOverlayClick: !state.disabled,
202
- initialFocusGetter
203
- }),
204
- [
205
- close,
206
- configuration,
207
- currentForm2?.form.title,
208
- initialFocusGetter,
209
- state.disabled
210
- ]
211
- );
212
- const getModalProps = React.useCallback(
213
- (innerHandler) => {
214
- if (innerHandler.setModalProps) {
215
- const overrideProps = innerHandler.setModalProps?.(
216
- {
217
- methodsPath: innerHandler.configuration?.methodsPath,
218
- modalConfiguration: innerHandler.configuration?.modalConfiguration
219
- },
220
- innerHandler.formDefinition
221
- );
222
- if (overrideProps) {
223
- const currentOnClose = () => {
224
- overrideProps?.onClose?.();
225
- defaultModalProps.onClose?.();
226
- };
227
- const currentOnExited = () => {
228
- overrideProps?.onExited?.();
229
- modalHookProps?.onExited?.();
230
- };
231
- return {
232
- ...defaultModalProps,
233
- ...overrideProps,
234
- ...modalHookProps,
235
- onClose: currentOnClose,
236
- onExited: currentOnExited
237
- };
238
- }
239
- }
240
- return { ...defaultModalProps, ...modalHookProps };
241
- },
242
- [defaultModalProps, modalHookProps]
243
- );
244
- const getHandler = React.useCallback(() => {
245
- const newHandler = {
246
- alert,
247
- close,
248
- configuration: configuration.current,
249
- formDefinition: currentForm2,
250
- reset: () => {
251
- return setState((currentState) => {
252
- return {
253
- ...currentState,
254
- ...initialState
255
- };
256
- });
257
- },
258
- setError,
259
- setMessage: (message) => {
260
- if (configuration.current?.modalConfiguration?.onMessage)
261
- configuration.current.modalConfiguration.onMessage(message);
262
- },
263
- setState,
264
- state,
265
- setValue
266
- };
267
- return newHandler;
268
- }, [close, configuration, currentForm2, setError, state, setValue]);
269
- const handler = getHandler();
270
- const modalProps = getModalProps(handler);
271
- const handleAction = React.useCallback(
272
- async (action) => {
273
- const innerHandler = getHandler();
274
- if (action.toDo === "ajaxHiddeAll") {
275
- close();
276
- }
277
- if (action.toDo === "functionTimedCall") {
278
- const method = await getFunction(
279
- arrayOrArray(action.param)[1],
280
- innerHandler
281
- );
282
- if (method) {
283
- setTimeout(
284
- () => method({
285
- currentUrl: innerHandler.formDefinition?.form.action ?? "noUrl"
286
- }),
287
- Number(action.param[0])
288
- );
289
- }
290
- }
291
- },
292
- [close, getHandler]
293
- );
294
- const handleFunction = React.useCallback(
295
- async ({ name, props: { messages, attributes, currentUrl } }) => {
296
- const innerHandler = getHandler();
297
- const method = await getFunction(`${name}`, innerHandler);
298
- if (method) {
299
- method({ messages, attributes, currentUrl });
300
- }
301
- },
302
- [getHandler]
303
- );
304
- const handleMessage = React.useCallback(
305
- (ev) => {
306
- const innerHandler = getHandler();
307
- notify({
308
- message: ev.predicate,
309
- type: "warning",
310
- onClose: innerHandler.configuration?.modalConfiguration?.onMessageClose
311
- });
312
- const onMessage = innerHandler.configuration?.modalConfiguration?.onMessage;
313
- if (onMessage) {
314
- onMessage(ev);
315
- }
316
- },
317
- [getHandler]
318
- );
319
- React.useEffect(() => {
320
- const u1 = ApiaApiMessenger.on("message", handleMessage);
321
- const u2 = FunctionsDispatcher.on("method", handleFunction);
322
- const u3 = ApiaActions.on("action", handleAction);
323
- return () => {
324
- u1();
325
- u2();
326
- u3();
327
- };
328
- }, [handleAction, handleFunction, handleMessage, state.windowIndex]);
329
- React.useEffect(() => {
330
- if (currentForm2) {
331
- show();
332
- }
333
- }, [currentForm2]);
334
- const formRef = React.useCallback(
335
- async (el) => {
336
- if (el && currentForm2?.form.onLoad) {
337
- const method = await getFunction(
338
- `${currentForm2?.form.onLoad}`,
339
- getHandler()
340
- );
341
- if (method) {
342
- method();
343
- }
344
- }
345
- },
346
- [currentForm2?.form.onLoad, getHandler]
347
- );
348
- return /* @__PURE__ */ jsx(ApiaApiContext, { id: apiaApiForm, children: /* @__PURE__ */ jsx(Modal, { ...modalProps, ref: modalRef, children: currentForm2 && /* @__PURE__ */ jsx(Box, { ...getVariant("layout.common.modals.apiaApi"), children: /* @__PURE__ */ jsxs(
349
- Form,
350
- {
351
- name: apiaApiForm,
352
- unregisterOnUnmount: true,
353
- avoidFieldsOverride: true,
354
- className: "handler__form",
355
- children: [
356
- /* @__PURE__ */ jsx(ApiaApiFieldsContainer, { definition: currentForm2, ...handler }),
357
- state.isMultipart && state.progress > 0 && /* @__PURE__ */ jsx(Box, { className: "progressBox", children: /* @__PURE__ */ jsx(
358
- ProgressBar,
359
- {
360
- id: "ApiaApiHandler progress",
361
- progress: state.progress,
362
- loading: true
363
- }
364
- ) }),
365
- /* @__PURE__ */ jsx(ApiaApiButtonsContainer, { definition: currentForm2, ...handler }),
366
- /* @__PURE__ */ jsx(Box, { ref: formRef, sx: { display: "none" } })
367
- ]
368
- }
369
- ) }) }) });
370
- };
371
- const ApiaApiHandler = React.memo(ApiaApiHandlerNonMemoized);
372
-
373
- export { ApiaApiHandler, apiaApiForm, getFunction, handle, isForm, isFunction };
374
- //# sourceMappingURL=ApiaApiHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApiaApiHandler.js","sources":["../src/ApiaApiHandler.tsx"],"sourcesContent":["/* eslint-disable max-classes-per-file */\n\nimport * as React from 'react';\nimport { Box } from '@apia/theme';\nimport { AxiosResponse } from 'axios';\nimport {\n arrayOrArray,\n EventEmitter,\n focus,\n focusSelector,\n StatefulEmitter,\n TApiaAction,\n TApiaFormElement,\n TApiaFunction,\n TApiaLoad,\n TApiaLoadText,\n TModify,\n useLatest,\n} from '@apia/util';\nimport { notify } from '@apia/notifications';\nimport { Form, validationsStore } from '@apia/validations';\nimport { Modal, ProgressBar, TModal, useModal } from '@apia/components';\nimport { getVariant } from '@apia/theme';\nimport ApiaApiContext from './ApiaApiContext';\nimport { IApiaApiRequestConfig } from './types';\nimport { ApiaActions } from './apiaApi';\nimport { ApiaApiFieldsContainer } from './fields/ApiaApiFieldsContainer';\nimport { ApiaApiButtonsContainer } from './buttons/ApiaApiButtonsContainer';\n\nexport type TMessage = {\n isHtml?: boolean;\n predicate: string;\n title?: string;\n};\ntype TMessageLocal = { title: string; predicate: string };\ntype TMethod = {\n name: string;\n props: {\n attributes?: Record<string, unknown>;\n currentUrl?: string;\n funCall?: string;\n inlineArguments?: string[];\n messages?: unknown;\n };\n};\nconst ApiaApiMessenger = new (class extends EventEmitter<{\n message: TMessageLocal;\n}> {})();\nconst FunctionsDispatcher = new (class extends EventEmitter<{\n method: TMethod;\n}> {})();\n\nexport type TApiaApiMethodHandler = {\n alert: typeof notify;\n close: () => void;\n configuration?: THandleConfiguration;\n formDefinition: TApiaLoad;\n setModalProps?: (\n configuration: THandleConfiguration,\n formDefinition?: TApiaLoad,\n ) => TModal | null;\n reset: () => void;\n setError: typeof notify;\n setMessage: (message: Record<string, unknown>) => unknown;\n setState: React.Dispatch<React.SetStateAction<IApiaApiHandlerState>>;\n state: IApiaApiHandlerState;\n setValue: (name: string, value: string) => void;\n};\n\nexport type TApiaApiMethod = (\n handler: TApiaApiMethodHandler,\n props: TMethod['props'],\n) => Promise<void> | void;\n\nexport type TApiaApiField = TApiaApiMethodHandler & {\n element: TModify<TApiaFormElement, { onChange: React.ChangeEventHandler }>;\n};\n\nexport const apiaApiForm = 'ApiaApiForm';\n\ntype TStoredApiaApiMethod = (props?: TMethod['props']) => unknown;\n\nconst methods: Record<string, TStoredApiaApiMethod> = {};\n\n/**\n * Este método permite cargar en forma asíncrona un método que se encuentre\n * dentro del directorio /api/methods\n */\nexport async function getFunction(\n name: string,\n handler: TApiaApiMethodHandler,\n): Promise<TStoredApiaApiMethod | undefined> {\n return new Promise((resolve) => {\n try {\n const separateNameFromParametersRegex =\n /^\\/?([\\w\\d_-]+)\\/?(?:\\(([^)]*)\\))?$/;\n const match = name.match(separateNameFromParametersRegex);\n if (match) {\n const functionName = match[1];\n const parameters = match[2];\n const path: string = [\n ...(handler.configuration?.methodsPath\n ?.split('/')\n .filter((current) => !!current) ?? []),\n functionName,\n ].join('/');\n const storeMethodAndResolve = (result: { default: TApiaApiMethod }) => {\n if (typeof result.default !== 'function') notFound();\n const method = result.default;\n methods[functionName] = (props?: TMethod['props']) => {\n return method(handler, {\n ...props,\n inlineArguments:\n parameters?.split(',').map((argument) => {\n if (argument.startsWith(\"'\") || argument.startsWith('\"'))\n return argument.slice(1, argument.length - 1);\n return argument;\n }) ?? [],\n });\n };\n resolve(methods[functionName]);\n };\n\n const notFound = () => {\n throw new Error(\n `${functionName}.ts not found at ${path}.ts nor ./${functionName}.ts`,\n );\n };\n\n import(\n /* webpackChunkName: \"api-methods-[request]\" */ `/api/methods/${path}.ts`\n )\n .then(storeMethodAndResolve)\n .catch(() => {\n if (handler.configuration?.methodsPath !== undefined)\n import(\n /* webpackChunkName: \"api-methods-[request]\" */ `/api/methods/${functionName}.ts`\n )\n\n .then(storeMethodAndResolve)\n .catch(notFound);\n else {\n notFound();\n }\n });\n }\n } catch (e) {\n console.error(e);\n handler.reset();\n handler.setError({\n type: 'danger',\n message: 'Error while loading current method.',\n });\n }\n });\n}\n\nexport function isForm(\n responseObject: Record<string, unknown>,\n): responseObject is TApiaLoad {\n return (\n responseObject.form !== undefined &&\n typeof responseObject.form === 'object' &&\n !!responseObject.form\n );\n}\n\nexport function isFunction(\n responseObject: Record<string, unknown>,\n): responseObject is TApiaLoad<TApiaFunction> {\n return (\n typeof responseObject.canClose === 'boolean' &&\n typeof responseObject.type === 'string' &&\n !!responseObject.function\n );\n}\n\nfunction isMessage(\n responseObject: Record<string, unknown>,\n): responseObject is TApiaLoad<TApiaLoadText> {\n if (\n typeof responseObject.canClose === 'boolean' &&\n typeof responseObject.type === 'string' &&\n typeof responseObject.text === 'object' &&\n responseObject.text &&\n typeof (responseObject.text as Record<string, unknown>).label === 'string'\n ) {\n return true;\n }\n return false;\n}\n\nexport interface IModalConfig {\n modalTitle?: string;\n onClose?: () => void;\n onMessage?: (message: Record<string, unknown>) => unknown;\n onMessageClose?: () => unknown;\n onSubmitted?: (\n handler: TApiaApiMethodHandler,\n response: AxiosResponse<Record<string, unknown> | null> | null,\n ) => unknown;\n}\n\nconst modalConfigurationHandler = new StatefulEmitter<{\n value: THandleConfiguration;\n}>();\n\nfunction useModalConfiguration() {\n const value = modalConfigurationHandler.useState('value');\n const latestValue = useLatest(value);\n\n return latestValue;\n}\n\nexport type THandleConfiguration = Partial<\n Pick<\n IApiaApiRequestConfig<unknown>,\n 'modalConfiguration' | 'methodsPath' | 'setModalProps'\n >\n>;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nlet currentForm: TApiaLoad | undefined;\nconst currentFormDispatcher =\n new (class currentFormDispatcher extends EventEmitter<{\n form: TApiaLoad;\n }> {\n emit<K extends 'form'>(\n eventName: K,\n params?: { form: TApiaLoad }[K] | undefined,\n ): void {\n super.emit(eventName, params as TApiaLoad);\n currentForm = params;\n }\n })();\n\nexport function handle(\n responseObject: Record<string, unknown>,\n currentUrl: string,\n configuration: THandleConfiguration,\n) {\n modalConfigurationHandler.setState('value', configuration);\n if (isForm(responseObject)) {\n currentFormDispatcher.emit('form', responseObject);\n return true;\n }\n if (isFunction(responseObject)) {\n FunctionsDispatcher.emit('method', {\n name: responseObject.function.name,\n props: {\n messages: responseObject.function.messages,\n attributes: responseObject.function,\n currentUrl,\n },\n });\n return true;\n }\n if (isMessage(responseObject)) {\n ApiaApiMessenger.emit('message', {\n predicate: responseObject.text.content,\n title: responseObject.text.title,\n });\n return true;\n }\n return false;\n}\n\nexport interface IApiaApiHandlerState {\n disabled: boolean;\n isLoading: boolean;\n isMultipart: boolean;\n progress: number;\n errors: Record<string, string>;\n windowIndex: number;\n}\n\nconst initialState: Omit<IApiaApiHandlerState, 'windowIndex'> = {\n disabled: false,\n isLoading: false,\n isMultipart: false,\n progress: 0,\n errors: {},\n};\n\nconst ApiaApiHandlerNonMemoized = () => {\n const configuration = useModalConfiguration();\n\n const [state, setState] = React.useState<IApiaApiHandlerState>({\n ...initialState,\n windowIndex: -1,\n });\n\n const [currentForm, setCurrentForm] = React.useState<TApiaLoad | undefined>(\n undefined,\n );\n React.useEffect(() => {\n return currentFormDispatcher.on('form', setCurrentForm);\n }, []);\n\n const setValue = React.useCallback((name: string, value: string) => {\n return validationsStore.setFieldValue(apiaApiForm, name, value);\n }, []);\n\n React.useEffect(() => {\n if (!currentForm) return;\n const elements = arrayOrArray(currentForm?.form?.elements?.element ?? []);\n\n let isMultipart = false;\n const elementsValues = Object.values(elements);\n let i = 0;\n while (i < elementsValues.length && !isMultipart) {\n if (elementsValues[i++].type === 'file') {\n isMultipart = true;\n }\n }\n\n setState((currentState) => {\n return {\n ...currentState,\n ...initialState,\n isMultipart,\n };\n });\n }, [currentForm]);\n\n const { show, onClose, ...modalHookProps } = useModal();\n\n const close = React.useCallback(() => {\n onClose();\n currentFormDispatcher.emit('form', undefined);\n setState((currentState) => {\n return { ...currentState, ...initialState };\n });\n configuration.current?.modalConfiguration?.onClose?.();\n\n validationsStore.unregisterForm(apiaApiForm);\n }, [onClose, configuration]);\n\n const modalRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n const elements = modalRef.current?.querySelectorAll(\n 'a,input,textarea,button',\n );\n if (elements?.length === 1)\n void focus.on(([...elements] as HTMLElement[])[0]);\n });\n\n const setError = React.useCallback(\n (notification: Parameters<typeof notify>[0]) => {\n notify({ ...notification });\n },\n [],\n );\n\n const initialFocusGetter = React.useCallback((ref: HTMLElement) => {\n return ref?.querySelector(focusSelector) as HTMLElement;\n }, []);\n\n const defaultModalProps = React.useMemo(\n (): TModal => ({\n onClose: close,\n id: apiaApiForm,\n title:\n configuration.current?.modalConfiguration?.modalTitle ??\n currentForm?.form.title,\n size: 'md-fixed',\n shouldCloseOnEsc: !state.disabled,\n shouldCloseOnOverlayClick: !state.disabled,\n initialFocusGetter,\n }),\n [\n close,\n configuration,\n currentForm?.form.title,\n initialFocusGetter,\n state.disabled,\n ],\n );\n\n const getModalProps = React.useCallback(\n (innerHandler: TApiaApiMethodHandler) => {\n if (innerHandler.setModalProps) {\n const overrideProps = innerHandler.setModalProps?.(\n {\n methodsPath: innerHandler.configuration?.methodsPath,\n modalConfiguration: innerHandler.configuration?.modalConfiguration,\n },\n innerHandler.formDefinition,\n );\n if (overrideProps) {\n const currentOnClose = () => {\n overrideProps?.onClose?.();\n defaultModalProps.onClose?.();\n };\n const currentOnExited = () => {\n overrideProps?.onExited?.();\n modalHookProps?.onExited?.();\n };\n return {\n ...defaultModalProps,\n ...overrideProps,\n ...modalHookProps,\n onClose: currentOnClose,\n onExited: currentOnExited,\n };\n }\n }\n return { ...defaultModalProps, ...modalHookProps };\n },\n [defaultModalProps, modalHookProps],\n );\n\n const getHandler = React.useCallback(() => {\n const newHandler: TApiaApiMethodHandler = {\n alert,\n close,\n configuration: configuration.current,\n formDefinition: currentForm as TApiaLoad,\n reset: () => {\n return setState((currentState) => {\n return {\n ...currentState,\n ...initialState,\n };\n });\n },\n setError,\n setMessage: (message) => {\n if (configuration.current?.modalConfiguration?.onMessage)\n configuration.current.modalConfiguration.onMessage(message);\n },\n setState,\n state,\n setValue,\n };\n return newHandler;\n }, [close, configuration, currentForm, setError, state, setValue]);\n\n const handler = getHandler();\n const modalProps = getModalProps(handler);\n\n const handleAction = React.useCallback(\n async (action: TModify<TApiaAction, { param: string[] }>) => {\n const innerHandler = getHandler();\n if (action.toDo === 'ajaxHiddeAll') {\n close();\n }\n if (action.toDo === 'functionTimedCall') {\n const method = await getFunction(\n arrayOrArray(action.param)[1],\n innerHandler,\n );\n\n if (method) {\n /*\n * Aquí el timeout se utiliza debido a que Apia lo establece de esa\n * forma,\n * Existe un retorno de Apia llamado functionTimedCall que\n * espera que una función se ejecute luego de un timeout, y\n * yo solamente respeté dicho comportamiento.\n */\n setTimeout(\n () =>\n method({\n currentUrl: innerHandler.formDefinition?.form.action ?? 'noUrl',\n }),\n Number(action.param[0]),\n );\n }\n }\n },\n [close, getHandler],\n );\n\n const handleFunction = React.useCallback(\n async ({ name, props: { messages, attributes, currentUrl } }: TMethod) => {\n const innerHandler = getHandler();\n const method = await getFunction(`${name}`, innerHandler);\n if (method) {\n method({ messages, attributes, currentUrl });\n }\n },\n [getHandler],\n );\n\n const handleMessage = React.useCallback(\n (ev: TMessage) => {\n const innerHandler = getHandler();\n notify({\n message: ev.predicate,\n type: 'warning',\n onClose: innerHandler.configuration?.modalConfiguration?.onMessageClose,\n });\n const onMessage =\n innerHandler.configuration?.modalConfiguration?.onMessage;\n if (onMessage) {\n onMessage(ev);\n }\n },\n [getHandler],\n );\n\n React.useEffect(() => {\n const u1 = ApiaApiMessenger.on('message', handleMessage);\n const u2 = FunctionsDispatcher.on('method', handleFunction);\n const u3 = ApiaActions.on('action', handleAction);\n\n return () => {\n u1();\n u2();\n u3();\n };\n }, [handleAction, handleFunction, handleMessage, state.windowIndex]);\n\n React.useEffect(() => {\n if (currentForm) {\n show();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentForm]);\n\n const formRef = React.useCallback(\n async (el: HTMLElement) => {\n if (el && currentForm?.form.onLoad) {\n const method = await getFunction(\n `${currentForm?.form.onLoad}`,\n getHandler(),\n );\n if (method) {\n method();\n }\n }\n },\n [currentForm?.form.onLoad, getHandler],\n );\n\n return (\n <ApiaApiContext id={apiaApiForm}>\n <Modal {...modalProps} ref={modalRef}>\n {currentForm && (\n <Box {...getVariant('layout.common.modals.apiaApi')}>\n <Form\n name={apiaApiForm}\n unregisterOnUnmount\n avoidFieldsOverride\n className=\"handler__form\"\n >\n <ApiaApiFieldsContainer definition={currentForm} {...handler} />\n {state.isMultipart && state.progress > 0 && (\n <Box className=\"progressBox\">\n <ProgressBar\n id=\"ApiaApiHandler progress\"\n progress={state.progress}\n loading\n />\n </Box>\n )}\n <ApiaApiButtonsContainer definition={currentForm} {...handler} />\n <Box ref={formRef} sx={{ display: 'none' }} />\n </Form>\n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AA,EAAwB,UAAYA,EAAAA,YAAAA,EAAc,GAAG,OAAS,EAAA,CAAA;AAAA,wBAC/D,GAAA,CAAC,OAAI,GAAK,EAAA,OAAA,EAAS,IAAI,EAAE,OAAA,EAAS,QAAU,EAAA,CAAA;AAAA,OAAA;AAAA,KAAA;AAAA,GAC9C,EACF,GAEJ,CACF,EAAA,CAAA,CAAA;AAEJ,CAAA,CAAA;AAEa,MAAA,cAAA,GAAiB,KAAM,CAAA,IAAA,CAAK,yBAAyB;;;;"}
package/dist/apiaApi.d.ts DELETED
@@ -1,156 +0,0 @@
1
- import { TModify } from '@apia/util';
2
- import { AxiosResponse } from 'axios';
3
- import QueryString from 'qs';
4
- import { IApiaApiRequestConfig, TApiaApiResult } from './types.js';
5
-
6
- declare function getConfig<LoadType>(outerBehaveConfig?: IApiaApiRequestConfig<LoadType>): IApiaApiRequestConfig<unknown> & IApiaApiRequestConfig<LoadType> & Partial<IApiaApiRequestConfig<unknown>>;
7
- type TApiaApiAxiosResponse<LoadType> = AxiosResponse<LoadType | null> & {
8
- hasError: boolean;
9
- hasMessages: boolean;
10
- };
11
- /**
12
- * IMPORTANT!! The ApiaApi is programmed under the slogan that
13
- * **should never throw an exception**. **Errors** coming from
14
- * connectivity or exceptions on the server **will be handled
15
- * automatically** by ApiaApi, using the notification system
16
- * of the application. It is possible to determine in what context they should
17
- * be thrown those exceptions (global, main, modal) using the
18
- * alertsCategory configuration properties **(see errorsHandling.md)**.
19
- *
20
- * @param url String, the url you want to call
21
- * @param config interface IApiaApiRequestConfig<DataType>;
22
- *
23
- * @throws Nothing
24
- *
25
- * @example
26
- *
27
- * ApiaApi.post<ResponseType>('url...', {
28
- axiosConfig?: AxiosRequestConfig;
29
-
30
- // Configuración de postData
31
- postData? unknown;
32
- postDataTreatement?: 'stringify' | undefined;
33
-
34
- // Configuración de queryString
35
- queryData?: string | Record<string, unknown>;
36
- stringifyOptions?: QueryString.IStringifyOptions;
37
-
38
- // Response validator,
39
- // If it returns true, everything continues correctly
40
- // If it returns false, the ApiaApi throws a standard error.
41
- // If it returns string, ApiaApi throws the error returned in the string.
42
- validateResponse?: (
43
- response: AxiosResponse<DataType | null>,
44
- ) => boolean | string;
45
-
46
- // Configuración de alertas
47
- alertsImportance?: TAlertImportance;
48
-
49
- // Configuración de ApiaApiHandler, falta documentar
50
- handleLoad?: boolean;
51
- eventsHandler?: IEventsHandler;
52
-
53
- // other configuration
54
- colors?: TColors;
55
- debug?: boolean;
56
- }
57
- * @returns The type of the return value depends on the type passed when calling the function. If there was an error it returns null.
58
- */
59
- declare function post<LoadType extends Record<string, unknown> = Record<string, unknown>, DataType = unknown>(url: string | TModify<IApiaApiRequestConfig<LoadType>, {
60
- postData?: DataType;
61
- postDataTreatement?: 'stringify';
62
- }>, config?: TModify<IApiaApiRequestConfig<LoadType>, {
63
- postData?: DataType;
64
- postDataTreatement?: 'stringify';
65
- }>): TApiaApiResult<LoadType>;
66
- declare function post<LoadType extends Record<string, unknown> = Record<string, unknown>, DataType = unknown>(config: TModify<IApiaApiRequestConfig<LoadType>, {
67
- postData?: DataType;
68
- postDataTreatement?: 'stringify';
69
- }>): TApiaApiResult<LoadType>;
70
- /**
71
- * IMPORTANTE!! El ApiaApi está programado bajo la consigna de que
72
- * **no debe tirar núnca una excepción**. **Los errores** provenientes
73
- * de la conectividad o de excepciones en el servidor **serán manejados
74
- * automáticamente** por el ApiaApi utilizando el sistema de notificaciones
75
- * de la aplicación. Es posible determinar en qué contexto deben
76
- * ser lanzadas esas excepciones (global, main, modal) utilizando las
77
- * propiedades de configuración alertsCategory **(ver errorsHandling.md)**.
78
- *
79
- * @param url String, el url al que se desea llamar
80
- * @param config interface IApiaApiRequestConfig<DataType>;
81
- *
82
- * @throws Nothing
83
- *
84
- * @example
85
- *
86
- * ApiaApi.get<TipoDeRespuesta>('url...', {
87
- axiosConfig?: AxiosRequestConfig;
88
-
89
- // Configuración de queryString
90
- queryData?: string | Record<string, unknown>;
91
- stringifyOptions?: QueryString.IStringifyOptions;
92
-
93
- // Validador de respuesta,
94
- // Si devuelve true, todo sigue correctamente
95
- // Si devuelve false, el ApiaApi tira un error estándar.
96
- // Si devuelve string, el ApiaApi tira el error devuelto en el string.
97
- validateResponse?: (
98
- response: AxiosResponse<DataType | null>,
99
- ) => boolean | string;
100
-
101
- // Configuración de alertas
102
- alertsImportance?: TAlertImportance;
103
-
104
- // Configuración de ApiaApiHandler, falta documentar
105
- handleLoad?: boolean;
106
- eventsHandler?: IEventsHandler;
107
-
108
- // Otra configuración
109
- colors?: TColors;
110
- debug?: boolean;
111
- }
112
- * @returns El tipo del valor devuelto depende del tipo pasado al llamar a la función. Si hubo un error devuelve null
113
- */
114
- declare function get<LoadType extends Record<string, unknown> = Record<string, unknown>>(url: string | IApiaApiRequestConfig<LoadType>, config?: IApiaApiRequestConfig<LoadType>): TApiaApiResult<LoadType>;
115
- declare function get<LoadType extends Record<string, unknown> = Record<string, unknown>>(config: IApiaApiRequestConfig<LoadType>): TApiaApiResult<LoadType>;
116
- declare const ApiaApi: {
117
- get: typeof get;
118
- getConfig: typeof getConfig;
119
- post: typeof post;
120
- };
121
- /**
122
- * Creates an url based on the general requirements of Apia.
123
- * If the ajaxUrl property is not passed, it will use the
124
- * window.URL_REQUEST_AJAX. Its use is very simple, just pass the objects you
125
- * want to appear in the query string.
126
- *
127
- * @example makeApiaUrl({
128
- * ajaxUrl: 'the.endpoint.you.want',
129
- * queryString: 'an=existent&query=string',
130
- * action: 'theAction',
131
- * anotherProp: 15
132
- * })
133
- *
134
- * @returns the well formed url, in the example, the response url is:
135
- * /context/the.endpoint.you.want?an=existent&query=string&anotherProp=15&tabId=...&tokenId=...&action=theAction
136
- */
137
- declare function makeApiaUrl(props?: {
138
- action?: string;
139
- ajaxUrl?: string;
140
- queryString?: string;
141
- stringifyOptions?: QueryString.IStringifyOptions;
142
- tabId?: string | number;
143
- preventAsXmlParameter?: boolean;
144
- avoidTabId?: boolean;
145
- [key: string]: unknown;
146
- }): string;
147
- declare global {
148
- interface Window {
149
- TAB_ID_REQUEST: string;
150
- CONTEXT: string;
151
- URL_REQUEST_AJAX: string;
152
- }
153
- }
154
-
155
- export { type TApiaApiAxiosResponse, ApiaApi as default, makeApiaUrl };
156
- //# sourceMappingURL=apiaApi.d.ts.map