fui-material 2.8.10 → 2.8.12
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/f-ui-kit.es.js +229 -16
- package/dist/f-ui-kit.es.js.map +1 -1
- package/dist/f-ui-kit.umd.js +2 -2
- package/dist/f-ui-kit.umd.js.map +1 -1
- package/dist/types/context/FLibraryProvider.d.ts +12 -2
- package/dist/types/context/index.d.ts +4 -1
- package/dist/types/context/requestObserver.d.ts +79 -0
- package/dist/types/hooks/useFApi/useFApi.d.ts +6 -1
- package/package.json +2 -1
package/dist/f-ui-kit.es.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React, { forwardRef, useRef, useState, useEffect, createContext, isValidElement, Children, Fragment as Fragment$1, cloneElement, useContext, useMemo, useLayoutEffect, useDeferredValue, useCallback, useId } from "react";
|
|
3
3
|
import ReactDOM, { createPortal } from "react-dom";
|
|
4
|
+
import axios from "axios";
|
|
4
5
|
import JSZip from "jszip";
|
|
5
6
|
import initializeModule from "allorion-exporting-html-to-docx";
|
|
6
7
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
7
8
|
import { initializeModule as initializeModule$1, installFormatCode } from "allorion-exporting-html-to-xlsx";
|
|
8
|
-
import axios from "axios";
|
|
9
9
|
import { useQueryClient, useMutation, useQuery } from "@tanstack/react-query";
|
|
10
10
|
import './index.css';const btn = "_btn_gdyy6_1";
|
|
11
11
|
const disabled$4 = "_disabled_gdyy6_31";
|
|
@@ -8863,7 +8863,201 @@ function fConvertDate(input, options) {
|
|
|
8863
8863
|
return "";
|
|
8864
8864
|
}
|
|
8865
8865
|
}
|
|
8866
|
-
const
|
|
8866
|
+
const LONG_ERROR_FIELD_LIMIT = 2048;
|
|
8867
|
+
const SHORT_ERROR_FIELD_LIMIT = 256;
|
|
8868
|
+
const ERROR_FIELDS = [
|
|
8869
|
+
"message",
|
|
8870
|
+
"error",
|
|
8871
|
+
"code",
|
|
8872
|
+
"title",
|
|
8873
|
+
"type",
|
|
8874
|
+
"detail",
|
|
8875
|
+
"traceId",
|
|
8876
|
+
"requestId",
|
|
8877
|
+
"timestamp"
|
|
8878
|
+
];
|
|
8879
|
+
function isScalar(value) {
|
|
8880
|
+
return typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
8881
|
+
}
|
|
8882
|
+
function isUnsupportedResponseData(data) {
|
|
8883
|
+
return Array.isArray(data) || typeof Blob !== "undefined" && data instanceof Blob || typeof ArrayBuffer !== "undefined" && (data instanceof ArrayBuffer || ArrayBuffer.isView(data));
|
|
8884
|
+
}
|
|
8885
|
+
function normalizeRequestErrorResponse(data) {
|
|
8886
|
+
try {
|
|
8887
|
+
if (typeof data === "string") {
|
|
8888
|
+
return data.length > 0 ? { message: data.slice(0, LONG_ERROR_FIELD_LIMIT) } : void 0;
|
|
8889
|
+
}
|
|
8890
|
+
if (!data || typeof data !== "object" || isUnsupportedResponseData(data)) {
|
|
8891
|
+
return void 0;
|
|
8892
|
+
}
|
|
8893
|
+
const result = {};
|
|
8894
|
+
for (const field of ERROR_FIELDS) {
|
|
8895
|
+
const value = data[field];
|
|
8896
|
+
if (!isScalar(value)) continue;
|
|
8897
|
+
const text = String(value);
|
|
8898
|
+
result[field] = text.slice(
|
|
8899
|
+
0,
|
|
8900
|
+
field === "message" || field === "detail" ? LONG_ERROR_FIELD_LIMIT : SHORT_ERROR_FIELD_LIMIT
|
|
8901
|
+
);
|
|
8902
|
+
}
|
|
8903
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
8904
|
+
} catch {
|
|
8905
|
+
return void 0;
|
|
8906
|
+
}
|
|
8907
|
+
}
|
|
8908
|
+
function getErrorResponseData(error2) {
|
|
8909
|
+
if (!error2 || typeof error2 !== "object") return void 0;
|
|
8910
|
+
try {
|
|
8911
|
+
const response = error2.response;
|
|
8912
|
+
if (!response || typeof response !== "object") return void 0;
|
|
8913
|
+
return response.data;
|
|
8914
|
+
} catch {
|
|
8915
|
+
return void 0;
|
|
8916
|
+
}
|
|
8917
|
+
}
|
|
8918
|
+
function getRequestErrorResponse(error2) {
|
|
8919
|
+
return normalizeRequestErrorResponse(getErrorResponseData(error2));
|
|
8920
|
+
}
|
|
8921
|
+
const getRequestNow = () => {
|
|
8922
|
+
if (typeof performance !== "undefined" && typeof performance.now === "function") {
|
|
8923
|
+
return performance.now();
|
|
8924
|
+
}
|
|
8925
|
+
return Date.now();
|
|
8926
|
+
};
|
|
8927
|
+
const calcDurationMs = (startTime) => {
|
|
8928
|
+
return Math.max(0, Math.round(getRequestNow() - startTime));
|
|
8929
|
+
};
|
|
8930
|
+
function classifyRequestError(error2) {
|
|
8931
|
+
var _a, _b, _c;
|
|
8932
|
+
if (!error2 || typeof error2 !== "object") {
|
|
8933
|
+
return {
|
|
8934
|
+
outcome: "failure",
|
|
8935
|
+
errorCategory: "unknown"
|
|
8936
|
+
};
|
|
8937
|
+
}
|
|
8938
|
+
const err = error2;
|
|
8939
|
+
const isCanceled = Boolean((_b = (_a = axios).isCancel) == null ? void 0 : _b.call(_a, error2)) || err.name === "CanceledError" || err.name === "AbortError" || err.code === "ERR_CANCELED";
|
|
8940
|
+
if (isCanceled) {
|
|
8941
|
+
return {
|
|
8942
|
+
outcome: "aborted",
|
|
8943
|
+
errorCategory: "abort",
|
|
8944
|
+
status: typeof ((_c = err.response) == null ? void 0 : _c.status) === "number" ? err.response.status : void 0
|
|
8945
|
+
};
|
|
8946
|
+
}
|
|
8947
|
+
if (err.response && typeof err.response.status === "number") {
|
|
8948
|
+
return {
|
|
8949
|
+
outcome: "failure",
|
|
8950
|
+
errorCategory: "http",
|
|
8951
|
+
status: err.response.status
|
|
8952
|
+
};
|
|
8953
|
+
}
|
|
8954
|
+
if (err.code === "ECONNABORTED" || typeof err.message === "string" && err.message.toLowerCase().includes("timeout")) {
|
|
8955
|
+
return {
|
|
8956
|
+
outcome: "failure",
|
|
8957
|
+
errorCategory: "timeout"
|
|
8958
|
+
};
|
|
8959
|
+
}
|
|
8960
|
+
if (err.code === "ERR_NETWORK" || Boolean(err.request && !err.response)) {
|
|
8961
|
+
return {
|
|
8962
|
+
outcome: "failure",
|
|
8963
|
+
errorCategory: "network"
|
|
8964
|
+
};
|
|
8965
|
+
}
|
|
8966
|
+
return {
|
|
8967
|
+
outcome: "failure",
|
|
8968
|
+
errorCategory: "unknown"
|
|
8969
|
+
};
|
|
8970
|
+
}
|
|
8971
|
+
function notifyRequestObserver(observer, observation) {
|
|
8972
|
+
if (!observer || typeof observer.onRequestComplete !== "function") {
|
|
8973
|
+
return;
|
|
8974
|
+
}
|
|
8975
|
+
try {
|
|
8976
|
+
observer.onRequestComplete(observation);
|
|
8977
|
+
} catch {
|
|
8978
|
+
}
|
|
8979
|
+
}
|
|
8980
|
+
async function observeRequest(observer, requestFn, method, url) {
|
|
8981
|
+
if (!observer) {
|
|
8982
|
+
return requestFn();
|
|
8983
|
+
}
|
|
8984
|
+
const normalizedMethod = (method || "GET").toUpperCase();
|
|
8985
|
+
const startTime = getRequestNow();
|
|
8986
|
+
try {
|
|
8987
|
+
const result = await requestFn();
|
|
8988
|
+
const durationMs = calcDurationMs(startTime);
|
|
8989
|
+
const status = typeof (result == null ? void 0 : result.status) === "number" ? result.status : void 0;
|
|
8990
|
+
notifyRequestObserver(observer, {
|
|
8991
|
+
method: normalizedMethod,
|
|
8992
|
+
url,
|
|
8993
|
+
status,
|
|
8994
|
+
durationMs,
|
|
8995
|
+
outcome: "success"
|
|
8996
|
+
});
|
|
8997
|
+
return result;
|
|
8998
|
+
} catch (error2) {
|
|
8999
|
+
const durationMs = calcDurationMs(startTime);
|
|
9000
|
+
const { outcome, errorCategory, status } = classifyRequestError(error2);
|
|
9001
|
+
const errorResponse = outcome === "failure" ? getRequestErrorResponse(error2) : void 0;
|
|
9002
|
+
notifyRequestObserver(observer, {
|
|
9003
|
+
method: normalizedMethod,
|
|
9004
|
+
url,
|
|
9005
|
+
status,
|
|
9006
|
+
durationMs,
|
|
9007
|
+
outcome,
|
|
9008
|
+
errorCategory,
|
|
9009
|
+
...errorResponse ? { errorResponse } : {}
|
|
9010
|
+
});
|
|
9011
|
+
throw error2;
|
|
9012
|
+
}
|
|
9013
|
+
}
|
|
9014
|
+
const LibraryContext = createContext(null);
|
|
9015
|
+
const FLibraryProvider = ({
|
|
9016
|
+
children,
|
|
9017
|
+
config,
|
|
9018
|
+
requestObserver
|
|
9019
|
+
}) => {
|
|
9020
|
+
const effectiveObserver = requestObserver ?? (config == null ? void 0 : config.requestObserver);
|
|
9021
|
+
const contextValue = useMemo(() => {
|
|
9022
|
+
if (!effectiveObserver) {
|
|
9023
|
+
return config;
|
|
9024
|
+
}
|
|
9025
|
+
return {
|
|
9026
|
+
...config,
|
|
9027
|
+
requestObserver: effectiveObserver,
|
|
9028
|
+
apiService: {
|
|
9029
|
+
...config.apiService,
|
|
9030
|
+
request: (url, reqConfig) => {
|
|
9031
|
+
return observeRequest(
|
|
9032
|
+
effectiveObserver,
|
|
9033
|
+
() => config.apiService.request(url, reqConfig),
|
|
9034
|
+
(reqConfig == null ? void 0 : reqConfig.method) ?? "GET",
|
|
9035
|
+
url
|
|
9036
|
+
);
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
};
|
|
9040
|
+
}, [config, effectiveObserver]);
|
|
9041
|
+
return /* @__PURE__ */ jsx(LibraryContext.Provider, { value: contextValue, children });
|
|
9042
|
+
};
|
|
9043
|
+
const useFLibraryContext = () => {
|
|
9044
|
+
const context = useContext(LibraryContext);
|
|
9045
|
+
if (!context) {
|
|
9046
|
+
throw new Error("[UIKit/Lib]: Вы должны обернуть приложение в <FLibraryProvider config={{ apiService }}>");
|
|
9047
|
+
}
|
|
9048
|
+
return context;
|
|
9049
|
+
};
|
|
9050
|
+
const useFLibraryContextOptional = () => {
|
|
9051
|
+
return useContext(LibraryContext);
|
|
9052
|
+
};
|
|
9053
|
+
const useFApi = ({
|
|
9054
|
+
doNotUseState = false,
|
|
9055
|
+
defaultState = null,
|
|
9056
|
+
getValueByPath = void 0,
|
|
9057
|
+
requestObserver = void 0
|
|
9058
|
+
} = {}) => {
|
|
9059
|
+
const libraryContext = useFLibraryContextOptional();
|
|
9060
|
+
const effectiveObserver = requestObserver ?? (libraryContext == null ? void 0 : libraryContext.requestObserver);
|
|
8867
9061
|
const [data, setData] = useState(defaultState === void 0 ? null : defaultState);
|
|
8868
9062
|
const [loading, setLoading] = useState(false);
|
|
8869
9063
|
const [error2, setError] = useState(null);
|
|
@@ -8871,8 +9065,20 @@ const useFApi = ({ doNotUseState = false, defaultState = null, getValueByPath =
|
|
|
8871
9065
|
var _a, _b, _c;
|
|
8872
9066
|
setLoading(true);
|
|
8873
9067
|
setError(null);
|
|
9068
|
+
const startTime = effectiveObserver ? getRequestNow() : 0;
|
|
9069
|
+
const method = (config.method || "GET").toUpperCase();
|
|
9070
|
+
const url = config.url ?? "";
|
|
8874
9071
|
try {
|
|
8875
9072
|
const response = await axios(config);
|
|
9073
|
+
if (effectiveObserver) {
|
|
9074
|
+
notifyRequestObserver(effectiveObserver, {
|
|
9075
|
+
method,
|
|
9076
|
+
url,
|
|
9077
|
+
status: response.status,
|
|
9078
|
+
durationMs: calcDurationMs(startTime),
|
|
9079
|
+
outcome: "success"
|
|
9080
|
+
});
|
|
9081
|
+
}
|
|
8876
9082
|
if (getValueByPath) {
|
|
8877
9083
|
let returnValue = response.data;
|
|
8878
9084
|
const pathParts = getValueByPath.split(".");
|
|
@@ -8891,6 +9097,19 @@ const useFApi = ({ doNotUseState = false, defaultState = null, getValueByPath =
|
|
|
8891
9097
|
return response.data;
|
|
8892
9098
|
}
|
|
8893
9099
|
} catch (error22) {
|
|
9100
|
+
if (effectiveObserver) {
|
|
9101
|
+
const { outcome, errorCategory, status } = classifyRequestError(error22);
|
|
9102
|
+
const errorResponse = outcome === "failure" ? getRequestErrorResponse(error22) : void 0;
|
|
9103
|
+
notifyRequestObserver(effectiveObserver, {
|
|
9104
|
+
method,
|
|
9105
|
+
url,
|
|
9106
|
+
status,
|
|
9107
|
+
durationMs: calcDurationMs(startTime),
|
|
9108
|
+
outcome,
|
|
9109
|
+
errorCategory,
|
|
9110
|
+
...errorResponse ? { errorResponse } : {}
|
|
9111
|
+
});
|
|
9112
|
+
}
|
|
8894
9113
|
const err = error22;
|
|
8895
9114
|
const errorMessage = ((_b = (_a = err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || err.message || "Неизвестная ошибка";
|
|
8896
9115
|
fNotification({
|
|
@@ -8913,20 +9132,6 @@ const useFApi = ({ doNotUseState = false, defaultState = null, getValueByPath =
|
|
|
8913
9132
|
};
|
|
8914
9133
|
return { data, loading, error: error2, execute, reset };
|
|
8915
9134
|
};
|
|
8916
|
-
const LibraryContext = createContext(null);
|
|
8917
|
-
const FLibraryProvider = ({
|
|
8918
|
-
children,
|
|
8919
|
-
config
|
|
8920
|
-
}) => {
|
|
8921
|
-
return /* @__PURE__ */ jsx(LibraryContext.Provider, { value: config, children });
|
|
8922
|
-
};
|
|
8923
|
-
const useFLibraryContext = () => {
|
|
8924
|
-
const context = useContext(LibraryContext);
|
|
8925
|
-
if (!context) {
|
|
8926
|
-
throw new Error("[UIKit/Lib]: Вы должны обернуть приложение в <FLibraryProvider config={{ apiService }}>");
|
|
8927
|
-
}
|
|
8928
|
-
return context;
|
|
8929
|
-
};
|
|
8930
9135
|
const useFApiMutation = (url, config, options) => {
|
|
8931
9136
|
const { apiService } = useFLibraryContext();
|
|
8932
9137
|
const queryClient = useQueryClient();
|
|
@@ -9389,6 +9594,9 @@ export {
|
|
|
9389
9594
|
FUnlinkIcon,
|
|
9390
9595
|
FUploadIcon,
|
|
9391
9596
|
FWaterErrorBoundaryPage,
|
|
9597
|
+
LibraryContext,
|
|
9598
|
+
calcDurationMs,
|
|
9599
|
+
classifyRequestError,
|
|
9392
9600
|
fAlert,
|
|
9393
9601
|
fBankRound,
|
|
9394
9602
|
fConfirm,
|
|
@@ -9406,9 +9614,14 @@ export {
|
|
|
9406
9614
|
fNotification,
|
|
9407
9615
|
fNotificationDelete,
|
|
9408
9616
|
fPrompt,
|
|
9617
|
+
getRequestNow,
|
|
9618
|
+
notifyRequestObserver,
|
|
9619
|
+
observeRequest,
|
|
9409
9620
|
useFApi,
|
|
9410
9621
|
useFApiMutation,
|
|
9411
9622
|
useFApiQuery,
|
|
9623
|
+
useFLibraryContext,
|
|
9624
|
+
useFLibraryContextOptional,
|
|
9412
9625
|
useFManualApiQuery
|
|
9413
9626
|
};
|
|
9414
9627
|
//# sourceMappingURL=f-ui-kit.es.js.map
|