fui-material 2.8.10 → 2.8.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/f-ui-kit.es.js +170 -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 +3 -1
- package/dist/types/context/requestObserver.d.ts +61 -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,144 @@ function fConvertDate(input, options) {
|
|
|
8863
8863
|
return "";
|
|
8864
8864
|
}
|
|
8865
8865
|
}
|
|
8866
|
-
const
|
|
8866
|
+
const getRequestNow = () => {
|
|
8867
|
+
if (typeof performance !== "undefined" && typeof performance.now === "function") {
|
|
8868
|
+
return performance.now();
|
|
8869
|
+
}
|
|
8870
|
+
return Date.now();
|
|
8871
|
+
};
|
|
8872
|
+
const calcDurationMs = (startTime) => {
|
|
8873
|
+
return Math.max(0, Math.round(getRequestNow() - startTime));
|
|
8874
|
+
};
|
|
8875
|
+
function classifyRequestError(error2) {
|
|
8876
|
+
var _a, _b, _c;
|
|
8877
|
+
if (!error2 || typeof error2 !== "object") {
|
|
8878
|
+
return {
|
|
8879
|
+
outcome: "failure",
|
|
8880
|
+
errorCategory: "unknown"
|
|
8881
|
+
};
|
|
8882
|
+
}
|
|
8883
|
+
const err = error2;
|
|
8884
|
+
const isCanceled = Boolean((_b = (_a = axios).isCancel) == null ? void 0 : _b.call(_a, error2)) || err.name === "CanceledError" || err.name === "AbortError" || err.code === "ERR_CANCELED";
|
|
8885
|
+
if (isCanceled) {
|
|
8886
|
+
return {
|
|
8887
|
+
outcome: "aborted",
|
|
8888
|
+
errorCategory: "abort",
|
|
8889
|
+
status: typeof ((_c = err.response) == null ? void 0 : _c.status) === "number" ? err.response.status : void 0
|
|
8890
|
+
};
|
|
8891
|
+
}
|
|
8892
|
+
if (err.response && typeof err.response.status === "number") {
|
|
8893
|
+
return {
|
|
8894
|
+
outcome: "failure",
|
|
8895
|
+
errorCategory: "http",
|
|
8896
|
+
status: err.response.status
|
|
8897
|
+
};
|
|
8898
|
+
}
|
|
8899
|
+
if (err.code === "ECONNABORTED" || typeof err.message === "string" && err.message.toLowerCase().includes("timeout")) {
|
|
8900
|
+
return {
|
|
8901
|
+
outcome: "failure",
|
|
8902
|
+
errorCategory: "timeout"
|
|
8903
|
+
};
|
|
8904
|
+
}
|
|
8905
|
+
if (err.code === "ERR_NETWORK" || Boolean(err.request && !err.response)) {
|
|
8906
|
+
return {
|
|
8907
|
+
outcome: "failure",
|
|
8908
|
+
errorCategory: "network"
|
|
8909
|
+
};
|
|
8910
|
+
}
|
|
8911
|
+
return {
|
|
8912
|
+
outcome: "failure",
|
|
8913
|
+
errorCategory: "unknown"
|
|
8914
|
+
};
|
|
8915
|
+
}
|
|
8916
|
+
function notifyRequestObserver(observer, observation) {
|
|
8917
|
+
if (!observer || typeof observer.onRequestComplete !== "function") {
|
|
8918
|
+
return;
|
|
8919
|
+
}
|
|
8920
|
+
try {
|
|
8921
|
+
observer.onRequestComplete(observation);
|
|
8922
|
+
} catch {
|
|
8923
|
+
}
|
|
8924
|
+
}
|
|
8925
|
+
async function observeRequest(observer, requestFn, method, url) {
|
|
8926
|
+
if (!observer) {
|
|
8927
|
+
return requestFn();
|
|
8928
|
+
}
|
|
8929
|
+
const normalizedMethod = (method || "GET").toUpperCase();
|
|
8930
|
+
const startTime = getRequestNow();
|
|
8931
|
+
try {
|
|
8932
|
+
const result = await requestFn();
|
|
8933
|
+
const durationMs = calcDurationMs(startTime);
|
|
8934
|
+
const status = typeof (result == null ? void 0 : result.status) === "number" ? result.status : void 0;
|
|
8935
|
+
notifyRequestObserver(observer, {
|
|
8936
|
+
method: normalizedMethod,
|
|
8937
|
+
url,
|
|
8938
|
+
status,
|
|
8939
|
+
durationMs,
|
|
8940
|
+
outcome: "success"
|
|
8941
|
+
});
|
|
8942
|
+
return result;
|
|
8943
|
+
} catch (error2) {
|
|
8944
|
+
const durationMs = calcDurationMs(startTime);
|
|
8945
|
+
const { outcome, errorCategory, status } = classifyRequestError(error2);
|
|
8946
|
+
notifyRequestObserver(observer, {
|
|
8947
|
+
method: normalizedMethod,
|
|
8948
|
+
url,
|
|
8949
|
+
status,
|
|
8950
|
+
durationMs,
|
|
8951
|
+
outcome,
|
|
8952
|
+
errorCategory
|
|
8953
|
+
});
|
|
8954
|
+
throw error2;
|
|
8955
|
+
}
|
|
8956
|
+
}
|
|
8957
|
+
const LibraryContext = createContext(null);
|
|
8958
|
+
const FLibraryProvider = ({
|
|
8959
|
+
children,
|
|
8960
|
+
config,
|
|
8961
|
+
requestObserver
|
|
8962
|
+
}) => {
|
|
8963
|
+
const effectiveObserver = requestObserver ?? (config == null ? void 0 : config.requestObserver);
|
|
8964
|
+
const contextValue = useMemo(() => {
|
|
8965
|
+
if (!effectiveObserver) {
|
|
8966
|
+
return config;
|
|
8967
|
+
}
|
|
8968
|
+
return {
|
|
8969
|
+
...config,
|
|
8970
|
+
requestObserver: effectiveObserver,
|
|
8971
|
+
apiService: {
|
|
8972
|
+
...config.apiService,
|
|
8973
|
+
request: (url, reqConfig) => {
|
|
8974
|
+
return observeRequest(
|
|
8975
|
+
effectiveObserver,
|
|
8976
|
+
() => config.apiService.request(url, reqConfig),
|
|
8977
|
+
(reqConfig == null ? void 0 : reqConfig.method) ?? "GET",
|
|
8978
|
+
url
|
|
8979
|
+
);
|
|
8980
|
+
}
|
|
8981
|
+
}
|
|
8982
|
+
};
|
|
8983
|
+
}, [config, effectiveObserver]);
|
|
8984
|
+
return /* @__PURE__ */ jsx(LibraryContext.Provider, { value: contextValue, children });
|
|
8985
|
+
};
|
|
8986
|
+
const useFLibraryContext = () => {
|
|
8987
|
+
const context = useContext(LibraryContext);
|
|
8988
|
+
if (!context) {
|
|
8989
|
+
throw new Error("[UIKit/Lib]: Вы должны обернуть приложение в <FLibraryProvider config={{ apiService }}>");
|
|
8990
|
+
}
|
|
8991
|
+
return context;
|
|
8992
|
+
};
|
|
8993
|
+
const useFLibraryContextOptional = () => {
|
|
8994
|
+
return useContext(LibraryContext);
|
|
8995
|
+
};
|
|
8996
|
+
const useFApi = ({
|
|
8997
|
+
doNotUseState = false,
|
|
8998
|
+
defaultState = null,
|
|
8999
|
+
getValueByPath = void 0,
|
|
9000
|
+
requestObserver = void 0
|
|
9001
|
+
} = {}) => {
|
|
9002
|
+
const libraryContext = useFLibraryContextOptional();
|
|
9003
|
+
const effectiveObserver = requestObserver ?? (libraryContext == null ? void 0 : libraryContext.requestObserver);
|
|
8867
9004
|
const [data, setData] = useState(defaultState === void 0 ? null : defaultState);
|
|
8868
9005
|
const [loading, setLoading] = useState(false);
|
|
8869
9006
|
const [error2, setError] = useState(null);
|
|
@@ -8871,8 +9008,20 @@ const useFApi = ({ doNotUseState = false, defaultState = null, getValueByPath =
|
|
|
8871
9008
|
var _a, _b, _c;
|
|
8872
9009
|
setLoading(true);
|
|
8873
9010
|
setError(null);
|
|
9011
|
+
const startTime = effectiveObserver ? getRequestNow() : 0;
|
|
9012
|
+
const method = (config.method || "GET").toUpperCase();
|
|
9013
|
+
const url = config.url ?? "";
|
|
8874
9014
|
try {
|
|
8875
9015
|
const response = await axios(config);
|
|
9016
|
+
if (effectiveObserver) {
|
|
9017
|
+
notifyRequestObserver(effectiveObserver, {
|
|
9018
|
+
method,
|
|
9019
|
+
url,
|
|
9020
|
+
status: response.status,
|
|
9021
|
+
durationMs: calcDurationMs(startTime),
|
|
9022
|
+
outcome: "success"
|
|
9023
|
+
});
|
|
9024
|
+
}
|
|
8876
9025
|
if (getValueByPath) {
|
|
8877
9026
|
let returnValue = response.data;
|
|
8878
9027
|
const pathParts = getValueByPath.split(".");
|
|
@@ -8891,6 +9040,17 @@ const useFApi = ({ doNotUseState = false, defaultState = null, getValueByPath =
|
|
|
8891
9040
|
return response.data;
|
|
8892
9041
|
}
|
|
8893
9042
|
} catch (error22) {
|
|
9043
|
+
if (effectiveObserver) {
|
|
9044
|
+
const { outcome, errorCategory, status } = classifyRequestError(error22);
|
|
9045
|
+
notifyRequestObserver(effectiveObserver, {
|
|
9046
|
+
method,
|
|
9047
|
+
url,
|
|
9048
|
+
status,
|
|
9049
|
+
durationMs: calcDurationMs(startTime),
|
|
9050
|
+
outcome,
|
|
9051
|
+
errorCategory
|
|
9052
|
+
});
|
|
9053
|
+
}
|
|
8894
9054
|
const err = error22;
|
|
8895
9055
|
const errorMessage = ((_b = (_a = err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || err.message || "Неизвестная ошибка";
|
|
8896
9056
|
fNotification({
|
|
@@ -8913,20 +9073,6 @@ const useFApi = ({ doNotUseState = false, defaultState = null, getValueByPath =
|
|
|
8913
9073
|
};
|
|
8914
9074
|
return { data, loading, error: error2, execute, reset };
|
|
8915
9075
|
};
|
|
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
9076
|
const useFApiMutation = (url, config, options) => {
|
|
8931
9077
|
const { apiService } = useFLibraryContext();
|
|
8932
9078
|
const queryClient = useQueryClient();
|
|
@@ -9389,6 +9535,9 @@ export {
|
|
|
9389
9535
|
FUnlinkIcon,
|
|
9390
9536
|
FUploadIcon,
|
|
9391
9537
|
FWaterErrorBoundaryPage,
|
|
9538
|
+
LibraryContext,
|
|
9539
|
+
calcDurationMs,
|
|
9540
|
+
classifyRequestError,
|
|
9392
9541
|
fAlert,
|
|
9393
9542
|
fBankRound,
|
|
9394
9543
|
fConfirm,
|
|
@@ -9406,9 +9555,14 @@ export {
|
|
|
9406
9555
|
fNotification,
|
|
9407
9556
|
fNotificationDelete,
|
|
9408
9557
|
fPrompt,
|
|
9558
|
+
getRequestNow,
|
|
9559
|
+
notifyRequestObserver,
|
|
9560
|
+
observeRequest,
|
|
9409
9561
|
useFApi,
|
|
9410
9562
|
useFApiMutation,
|
|
9411
9563
|
useFApiQuery,
|
|
9564
|
+
useFLibraryContext,
|
|
9565
|
+
useFLibraryContextOptional,
|
|
9412
9566
|
useFManualApiQuery
|
|
9413
9567
|
};
|
|
9414
9568
|
//# sourceMappingURL=f-ui-kit.es.js.map
|