openxiangda 1.0.154 → 1.0.155
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/openxiangda-skills/SKILL.md +1 -0
- package/openxiangda-skills/references/component-guide.md +2 -0
- package/openxiangda-skills/references/pages/page-sdk.md +19 -0
- package/openxiangda-skills/references/troubleshooting.md +5 -5
- package/openxiangda-skills/skills/openxiangda-form/SKILL.md +1 -0
- package/openxiangda-skills/skills/openxiangda-page/SKILL.md +1 -0
- package/package.json +1 -1
- package/packages/sdk/dist/runtime/index.cjs +806 -795
- package/packages/sdk/dist/runtime/index.cjs.map +1 -1
- package/packages/sdk/dist/runtime/index.d.mts +1 -1
- package/packages/sdk/dist/runtime/index.d.ts +1 -1
- package/packages/sdk/dist/runtime/index.mjs +192 -181
- package/packages/sdk/dist/runtime/index.mjs.map +1 -1
- package/packages/sdk/dist/runtime/react.cjs +234 -223
- package/packages/sdk/dist/runtime/react.cjs.map +1 -1
- package/packages/sdk/dist/runtime/react.d.mts +10 -2
- package/packages/sdk/dist/runtime/react.d.ts +10 -2
- package/packages/sdk/dist/runtime/react.mjs +106 -95
- package/packages/sdk/dist/runtime/react.mjs.map +1 -1
- package/templates/openxiangda-react-spa/AGENTS.md +1 -0
|
@@ -46,6 +46,7 @@ __export(react_exports, {
|
|
|
46
46
|
PublicAccessGate: () => PublicAccessGate,
|
|
47
47
|
RuntimeAuthGuard: () => RuntimeAuthGuard,
|
|
48
48
|
createAuthClient: () => createAuthClient,
|
|
49
|
+
createPageFormRuntimeApi: () => createPageFormRuntimeApi,
|
|
49
50
|
createPageSdk: () => createPageSdk,
|
|
50
51
|
createPublicAccessClient: () => createPublicAccessClient,
|
|
51
52
|
createReactPage: () => createReactPage,
|
|
@@ -66,6 +67,7 @@ __export(react_exports, {
|
|
|
66
67
|
useNavigation: () => useNavigation,
|
|
67
68
|
useOpenXiangda: () => useOpenXiangda,
|
|
68
69
|
usePageContext: () => usePageContext,
|
|
70
|
+
usePageFormRuntimeApi: () => usePageFormRuntimeApi,
|
|
69
71
|
usePageProps: () => usePageProps,
|
|
70
72
|
usePageRoute: () => usePageRoute,
|
|
71
73
|
usePageSdk: () => usePageSdk,
|
|
@@ -2699,9 +2701,8 @@ var usePageRoute = () => {
|
|
|
2699
2701
|
return usePageContext().route;
|
|
2700
2702
|
};
|
|
2701
2703
|
|
|
2702
|
-
// packages/sdk/src/runtime/react/
|
|
2703
|
-
var
|
|
2704
|
-
var import_antd5 = require("antd");
|
|
2704
|
+
// packages/sdk/src/runtime/react/formRuntime.ts
|
|
2705
|
+
var import_react7 = require("react");
|
|
2705
2706
|
|
|
2706
2707
|
// packages/sdk/src/components/core/imageCompression.ts
|
|
2707
2708
|
var DEFAULT_THUMB = {
|
|
@@ -3554,6 +3555,73 @@ function createFormRuntimeApi(config) {
|
|
|
3554
3555
|
return { ...defaults, ...overrides, request };
|
|
3555
3556
|
}
|
|
3556
3557
|
|
|
3558
|
+
// packages/sdk/src/runtime/react/formRuntime.ts
|
|
3559
|
+
var normalizeMethod2 = (method) => {
|
|
3560
|
+
const value = String(method || "get").toLowerCase();
|
|
3561
|
+
return ["get", "post", "put", "delete", "patch"].includes(value) ? value : "get";
|
|
3562
|
+
};
|
|
3563
|
+
var normalizeHeaders = (headers) => {
|
|
3564
|
+
if (!headers) return void 0;
|
|
3565
|
+
return Object.fromEntries(new Headers(headers).entries());
|
|
3566
|
+
};
|
|
3567
|
+
var toPageRequest = (config) => ({
|
|
3568
|
+
path: config.url,
|
|
3569
|
+
method: normalizeMethod2(config.method),
|
|
3570
|
+
query: config.params,
|
|
3571
|
+
body: config.data,
|
|
3572
|
+
headers: normalizeHeaders(config.headers)
|
|
3573
|
+
});
|
|
3574
|
+
var toRuntimeResponse = (response) => {
|
|
3575
|
+
if (response.raw && typeof response.raw === "object") {
|
|
3576
|
+
return response.raw;
|
|
3577
|
+
}
|
|
3578
|
+
return {
|
|
3579
|
+
code: Number(response.code) || 200,
|
|
3580
|
+
success: response.success,
|
|
3581
|
+
message: response.message,
|
|
3582
|
+
data: response.result,
|
|
3583
|
+
result: response.result
|
|
3584
|
+
};
|
|
3585
|
+
};
|
|
3586
|
+
var unwrapPageResult = (response) => response.result ?? response.data ?? null;
|
|
3587
|
+
var createPageFormRuntimeApi = (sdk) => {
|
|
3588
|
+
const request = async (config) => {
|
|
3589
|
+
const options = toPageRequest(config);
|
|
3590
|
+
if (config.responseType === "blob") {
|
|
3591
|
+
const response = await sdk.transport.download(options);
|
|
3592
|
+
return response.blob;
|
|
3593
|
+
}
|
|
3594
|
+
return toRuntimeResponse(await sdk.transport.request(options));
|
|
3595
|
+
};
|
|
3596
|
+
return createFormRuntimeApi({
|
|
3597
|
+
request,
|
|
3598
|
+
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => unwrapPageResult(
|
|
3599
|
+
await sdk.createFileAccessTicket(
|
|
3600
|
+
bucketName,
|
|
3601
|
+
objectName,
|
|
3602
|
+
fileName,
|
|
3603
|
+
purpose,
|
|
3604
|
+
options
|
|
3605
|
+
)
|
|
3606
|
+
),
|
|
3607
|
+
createDownloadTicket: async (bucketName, objectName, fileName) => unwrapPageResult(
|
|
3608
|
+
await sdk.request({
|
|
3609
|
+
path: "/file/download-ticket",
|
|
3610
|
+
method: "post",
|
|
3611
|
+
body: { bucketName, objectName, fileName }
|
|
3612
|
+
})
|
|
3613
|
+
)
|
|
3614
|
+
});
|
|
3615
|
+
};
|
|
3616
|
+
var usePageFormRuntimeApi = () => {
|
|
3617
|
+
const sdk = usePageSdk();
|
|
3618
|
+
return (0, import_react7.useMemo)(() => createPageFormRuntimeApi(sdk), [sdk]);
|
|
3619
|
+
};
|
|
3620
|
+
|
|
3621
|
+
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
3622
|
+
var import_react11 = __toESM(require("react"));
|
|
3623
|
+
var import_antd5 = require("antd");
|
|
3624
|
+
|
|
3557
3625
|
// packages/sdk/src/components/fields/shared/fieldFormat.ts
|
|
3558
3626
|
function getUserId(user) {
|
|
3559
3627
|
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
@@ -3977,7 +4045,7 @@ var convertHeicPreview = async (request, url) => {
|
|
|
3977
4045
|
};
|
|
3978
4046
|
|
|
3979
4047
|
// packages/sdk/src/components/file-preview/FilePreviewContent.tsx
|
|
3980
|
-
var
|
|
4048
|
+
var import_react8 = require("react");
|
|
3981
4049
|
var import_antd2 = require("antd");
|
|
3982
4050
|
var import_icons = require("@ant-design/icons");
|
|
3983
4051
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -4061,11 +4129,11 @@ var PayloadPreview = ({
|
|
|
4061
4129
|
url,
|
|
4062
4130
|
mode
|
|
4063
4131
|
}) => {
|
|
4064
|
-
const [payload, setPayload] = (0,
|
|
4065
|
-
const [loading, setLoading] = (0,
|
|
4066
|
-
const [error, setError] = (0,
|
|
4067
|
-
const [reloadKey, setReloadKey] = (0,
|
|
4068
|
-
(0,
|
|
4132
|
+
const [payload, setPayload] = (0, import_react8.useState)(null);
|
|
4133
|
+
const [loading, setLoading] = (0, import_react8.useState)(false);
|
|
4134
|
+
const [error, setError] = (0, import_react8.useState)("");
|
|
4135
|
+
const [reloadKey, setReloadKey] = (0, import_react8.useState)(0);
|
|
4136
|
+
(0, import_react8.useEffect)(() => {
|
|
4069
4137
|
let disposed = false;
|
|
4070
4138
|
setPayload(null);
|
|
4071
4139
|
setError("");
|
|
@@ -4173,9 +4241,9 @@ var ClientTextPreview = ({
|
|
|
4173
4241
|
request,
|
|
4174
4242
|
url
|
|
4175
4243
|
}) => {
|
|
4176
|
-
const [payload, setPayload] = (0,
|
|
4177
|
-
const [error, setError] = (0,
|
|
4178
|
-
(0,
|
|
4244
|
+
const [payload, setPayload] = (0, import_react8.useState)(null);
|
|
4245
|
+
const [error, setError] = (0, import_react8.useState)("");
|
|
4246
|
+
(0, import_react8.useEffect)(() => {
|
|
4179
4247
|
let disposed = false;
|
|
4180
4248
|
let textLimit = 1024 * 1024;
|
|
4181
4249
|
loadPreviewBlob(request, url).then(async (blob) => {
|
|
@@ -4211,10 +4279,10 @@ var ClientTextPreview = ({
|
|
|
4211
4279
|
] });
|
|
4212
4280
|
};
|
|
4213
4281
|
var DocxPreview = ({ request, url }) => {
|
|
4214
|
-
const containerRef = (0,
|
|
4215
|
-
const [loading, setLoading] = (0,
|
|
4216
|
-
const [error, setError] = (0,
|
|
4217
|
-
(0,
|
|
4282
|
+
const containerRef = (0, import_react8.useRef)(null);
|
|
4283
|
+
const [loading, setLoading] = (0, import_react8.useState)(true);
|
|
4284
|
+
const [error, setError] = (0, import_react8.useState)("");
|
|
4285
|
+
(0, import_react8.useEffect)(() => {
|
|
4218
4286
|
let disposed = false;
|
|
4219
4287
|
const container = containerRef.current;
|
|
4220
4288
|
if (!container || !url) return () => {
|
|
@@ -4273,9 +4341,9 @@ var HeicImagePreview = ({
|
|
|
4273
4341
|
url,
|
|
4274
4342
|
fileName
|
|
4275
4343
|
}) => {
|
|
4276
|
-
const [src, setSrc] = (0,
|
|
4277
|
-
const [error, setError] = (0,
|
|
4278
|
-
(0,
|
|
4344
|
+
const [src, setSrc] = (0, import_react8.useState)("");
|
|
4345
|
+
const [error, setError] = (0, import_react8.useState)("");
|
|
4346
|
+
(0, import_react8.useEffect)(() => {
|
|
4279
4347
|
let disposed = false;
|
|
4280
4348
|
let objectUrl = "";
|
|
4281
4349
|
convertHeicPreview(request, url).then((result) => {
|
|
@@ -4304,9 +4372,9 @@ var ClientSpreadsheetPreview = ({
|
|
|
4304
4372
|
request,
|
|
4305
4373
|
url
|
|
4306
4374
|
}) => {
|
|
4307
|
-
const [payload, setPayload] = (0,
|
|
4308
|
-
const [error, setError] = (0,
|
|
4309
|
-
(0,
|
|
4375
|
+
const [payload, setPayload] = (0, import_react8.useState)(null);
|
|
4376
|
+
const [error, setError] = (0, import_react8.useState)("");
|
|
4377
|
+
(0, import_react8.useEffect)(() => {
|
|
4310
4378
|
let disposed = false;
|
|
4311
4379
|
(async () => {
|
|
4312
4380
|
try {
|
|
@@ -4422,13 +4490,13 @@ var OnlyOfficePreview = ({
|
|
|
4422
4490
|
configUrl,
|
|
4423
4491
|
ticket
|
|
4424
4492
|
}) => {
|
|
4425
|
-
const editorId = (0,
|
|
4493
|
+
const editorId = (0, import_react8.useMemo)(
|
|
4426
4494
|
() => `openxiangda-onlyoffice-${String(ticket || "editor").replace(/[^a-zA-Z0-9_-]/g, "")}`,
|
|
4427
4495
|
[ticket]
|
|
4428
4496
|
);
|
|
4429
|
-
const [loading, setLoading] = (0,
|
|
4430
|
-
const [error, setError] = (0,
|
|
4431
|
-
(0,
|
|
4497
|
+
const [loading, setLoading] = (0, import_react8.useState)(true);
|
|
4498
|
+
const [error, setError] = (0, import_react8.useState)("");
|
|
4499
|
+
(0, import_react8.useEffect)(() => {
|
|
4432
4500
|
let disposed = false;
|
|
4433
4501
|
let editor;
|
|
4434
4502
|
setLoading(true);
|
|
@@ -4611,13 +4679,13 @@ var FilePreviewContent = ({
|
|
|
4611
4679
|
};
|
|
4612
4680
|
|
|
4613
4681
|
// packages/sdk/src/components/file-preview/FilePreviewPage.tsx
|
|
4614
|
-
var
|
|
4682
|
+
var import_react9 = require("react");
|
|
4615
4683
|
var import_antd3 = require("antd");
|
|
4616
4684
|
var import_icons2 = require("@ant-design/icons");
|
|
4617
4685
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
4618
4686
|
|
|
4619
4687
|
// packages/sdk/src/components/file-preview/useFilePreview.tsx
|
|
4620
|
-
var
|
|
4688
|
+
var import_react10 = require("react");
|
|
4621
4689
|
var import_antd4 = require("antd");
|
|
4622
4690
|
var import_icons3 = require("@ant-design/icons");
|
|
4623
4691
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
@@ -4646,7 +4714,7 @@ var useFilePreviewController = ({
|
|
|
4646
4714
|
enabled = true,
|
|
4647
4715
|
requireServerCapability = true
|
|
4648
4716
|
}) => {
|
|
4649
|
-
const itemSignature = (0,
|
|
4717
|
+
const itemSignature = (0, import_react10.useMemo)(
|
|
4650
4718
|
() => items.map(
|
|
4651
4719
|
(item, index) => [
|
|
4652
4720
|
getPreviewItemKey(item, index),
|
|
@@ -4659,17 +4727,17 @@ var useFilePreviewController = ({
|
|
|
4659
4727
|
).join("|"),
|
|
4660
4728
|
[items]
|
|
4661
4729
|
);
|
|
4662
|
-
const [capabilities, setCapabilities] = (0,
|
|
4730
|
+
const [capabilities, setCapabilities] = (0, import_react10.useState)(
|
|
4663
4731
|
() => buildCapabilityMap(items, requireServerCapability)
|
|
4664
4732
|
);
|
|
4665
|
-
const [openingKey, setOpeningKey] = (0,
|
|
4666
|
-
const [dialogPreview, setDialogPreview] = (0,
|
|
4667
|
-
const [imagePreview, setImagePreview] = (0,
|
|
4733
|
+
const [openingKey, setOpeningKey] = (0, import_react10.useState)("");
|
|
4734
|
+
const [dialogPreview, setDialogPreview] = (0, import_react10.useState)(null);
|
|
4735
|
+
const [imagePreview, setImagePreview] = (0, import_react10.useState)({
|
|
4668
4736
|
open: false,
|
|
4669
4737
|
current: 0,
|
|
4670
4738
|
items: []
|
|
4671
4739
|
});
|
|
4672
|
-
(0,
|
|
4740
|
+
(0, import_react10.useEffect)(() => {
|
|
4673
4741
|
let disposed = false;
|
|
4674
4742
|
const initial = buildCapabilityMap(items, requireServerCapability);
|
|
4675
4743
|
setCapabilities(initial);
|
|
@@ -4714,28 +4782,28 @@ var useFilePreviewController = ({
|
|
|
4714
4782
|
disposed = true;
|
|
4715
4783
|
};
|
|
4716
4784
|
}, [api, enabled, itemSignature, requireServerCapability]);
|
|
4717
|
-
const getCapability = (0,
|
|
4785
|
+
const getCapability = (0, import_react10.useCallback)(
|
|
4718
4786
|
(item) => {
|
|
4719
4787
|
const index = items.indexOf(item);
|
|
4720
4788
|
return capabilities[getPreviewItemKey(item, Math.max(index, 0))];
|
|
4721
4789
|
},
|
|
4722
4790
|
[capabilities, items]
|
|
4723
4791
|
);
|
|
4724
|
-
const canPreview = (0,
|
|
4792
|
+
const canPreview = (0, import_react10.useCallback)(
|
|
4725
4793
|
(item) => enabled && canActOnItem(item) && getCapability(item)?.canPreview === true,
|
|
4726
4794
|
[enabled, getCapability]
|
|
4727
4795
|
);
|
|
4728
|
-
const closeImagePreview = (0,
|
|
4796
|
+
const closeImagePreview = (0, import_react10.useCallback)(() => {
|
|
4729
4797
|
setImagePreview((current) => {
|
|
4730
4798
|
revokeImageItems(current.items);
|
|
4731
4799
|
return { open: false, current: 0, items: [] };
|
|
4732
4800
|
});
|
|
4733
4801
|
}, []);
|
|
4734
|
-
(0,
|
|
4802
|
+
(0, import_react10.useEffect)(
|
|
4735
4803
|
() => () => revokeImageItems(imagePreview.items),
|
|
4736
4804
|
[imagePreview.items]
|
|
4737
4805
|
);
|
|
4738
|
-
const resolvePreparedImageItem = (0,
|
|
4806
|
+
const resolvePreparedImageItem = (0, import_react10.useCallback)(
|
|
4739
4807
|
async (prepared, index) => {
|
|
4740
4808
|
const item = prepared.item;
|
|
4741
4809
|
const metadata = prepared.metadata;
|
|
@@ -4757,14 +4825,14 @@ var useFilePreviewController = ({
|
|
|
4757
4825
|
},
|
|
4758
4826
|
[api]
|
|
4759
4827
|
);
|
|
4760
|
-
const prepareImageItem = (0,
|
|
4828
|
+
const prepareImageItem = (0, import_react10.useCallback)(
|
|
4761
4829
|
async (item, index) => {
|
|
4762
4830
|
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4763
4831
|
return resolvePreparedImageItem(prepared, index);
|
|
4764
4832
|
},
|
|
4765
4833
|
[api, appType, bucketName, resolvePreparedImageItem]
|
|
4766
4834
|
);
|
|
4767
|
-
const openPreview = (0,
|
|
4835
|
+
const openPreview = (0, import_react10.useCallback)(
|
|
4768
4836
|
async (item) => {
|
|
4769
4837
|
const itemIndex = Math.max(items.indexOf(item), 0);
|
|
4770
4838
|
const key = getPreviewItemKey(item, itemIndex);
|
|
@@ -4827,7 +4895,7 @@ var useFilePreviewController = ({
|
|
|
4827
4895
|
resolvePreparedImageItem
|
|
4828
4896
|
]
|
|
4829
4897
|
);
|
|
4830
|
-
const downloadItem = (0,
|
|
4898
|
+
const downloadItem = (0, import_react10.useCallback)(
|
|
4831
4899
|
async (item, prepared) => {
|
|
4832
4900
|
let url = prepared?.metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url;
|
|
4833
4901
|
if (!isDirectStorageItem(item) && item.objectName && !prepared?.metadata.downloadUrl) {
|
|
@@ -4991,63 +5059,6 @@ function FileStatusText({
|
|
|
4991
5059
|
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
4992
5060
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
4993
5061
|
var EMPTY_ITEMS = [];
|
|
4994
|
-
var normalizeMethod2 = (method) => {
|
|
4995
|
-
const value = String(method || "get").toLowerCase();
|
|
4996
|
-
return ["get", "post", "put", "delete", "patch"].includes(value) ? value : "get";
|
|
4997
|
-
};
|
|
4998
|
-
var normalizeHeaders = (headers) => {
|
|
4999
|
-
if (!headers) return void 0;
|
|
5000
|
-
return Object.fromEntries(new Headers(headers).entries());
|
|
5001
|
-
};
|
|
5002
|
-
var toPageRequest = (config) => ({
|
|
5003
|
-
path: config.url,
|
|
5004
|
-
method: normalizeMethod2(config.method),
|
|
5005
|
-
query: config.params,
|
|
5006
|
-
body: config.data,
|
|
5007
|
-
headers: normalizeHeaders(config.headers)
|
|
5008
|
-
});
|
|
5009
|
-
var toRuntimeResponse = (response) => {
|
|
5010
|
-
if (response.raw && typeof response.raw === "object") {
|
|
5011
|
-
return response.raw;
|
|
5012
|
-
}
|
|
5013
|
-
return {
|
|
5014
|
-
code: Number(response.code) || 200,
|
|
5015
|
-
success: response.success,
|
|
5016
|
-
message: response.message,
|
|
5017
|
-
data: response.result,
|
|
5018
|
-
result: response.result
|
|
5019
|
-
};
|
|
5020
|
-
};
|
|
5021
|
-
var unwrapPageResult = (response) => response.result ?? response.data ?? null;
|
|
5022
|
-
var createPageFileRuntimeApi = (sdk) => {
|
|
5023
|
-
const request = async (config) => {
|
|
5024
|
-
const options = toPageRequest(config);
|
|
5025
|
-
if (config.responseType === "blob") {
|
|
5026
|
-
const response = await sdk.transport.download(options);
|
|
5027
|
-
return response.blob;
|
|
5028
|
-
}
|
|
5029
|
-
return toRuntimeResponse(await sdk.transport.request(options));
|
|
5030
|
-
};
|
|
5031
|
-
return createFormRuntimeApi({
|
|
5032
|
-
request,
|
|
5033
|
-
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => unwrapPageResult(
|
|
5034
|
-
await sdk.createFileAccessTicket(
|
|
5035
|
-
bucketName,
|
|
5036
|
-
objectName,
|
|
5037
|
-
fileName,
|
|
5038
|
-
purpose,
|
|
5039
|
-
options
|
|
5040
|
-
)
|
|
5041
|
-
),
|
|
5042
|
-
createDownloadTicket: async (bucketName, objectName, fileName) => unwrapPageResult(
|
|
5043
|
-
await sdk.request({
|
|
5044
|
-
path: "/file/download-ticket",
|
|
5045
|
-
method: "post",
|
|
5046
|
-
body: { bucketName, objectName, fileName }
|
|
5047
|
-
})
|
|
5048
|
-
)
|
|
5049
|
-
});
|
|
5050
|
-
};
|
|
5051
5062
|
var useFilePreview = ({
|
|
5052
5063
|
items = EMPTY_ITEMS,
|
|
5053
5064
|
appType,
|
|
@@ -5056,7 +5067,7 @@ var useFilePreview = ({
|
|
|
5056
5067
|
requireServerCapability = true
|
|
5057
5068
|
}) => {
|
|
5058
5069
|
const sdk = usePageSdk();
|
|
5059
|
-
const api = (0,
|
|
5070
|
+
const api = (0, import_react11.useMemo)(() => createPageFormRuntimeApi(sdk), [sdk]);
|
|
5060
5071
|
const preview = useFilePreviewController({
|
|
5061
5072
|
items,
|
|
5062
5073
|
api,
|
|
@@ -5148,8 +5159,8 @@ var AttachmentPreviewList = ({
|
|
|
5148
5159
|
};
|
|
5149
5160
|
var PreviewImageThumb = ({ item }) => {
|
|
5150
5161
|
const src = item.thumbUrl || item.previewUrl || item.url;
|
|
5151
|
-
const [failed, setFailed] = (0,
|
|
5152
|
-
|
|
5162
|
+
const [failed, setFailed] = (0, import_react11.useState)(false);
|
|
5163
|
+
import_react11.default.useEffect(() => setFailed(false), [src]);
|
|
5153
5164
|
return src && !failed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src, alt: item.name || "\u56FE\u7247", onError: () => setFailed(true) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sy-image-state", children: item.name || "\u56FE\u7247" });
|
|
5154
5165
|
};
|
|
5155
5166
|
var ImagePreviewGrid = ({
|
|
@@ -5244,12 +5255,12 @@ var ImagePreviewGrid = ({
|
|
|
5244
5255
|
};
|
|
5245
5256
|
|
|
5246
5257
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
5247
|
-
var
|
|
5258
|
+
var import_react17 = require("react");
|
|
5248
5259
|
var import_antd10 = require("antd");
|
|
5249
5260
|
var import_icons9 = require("@ant-design/icons");
|
|
5250
5261
|
|
|
5251
5262
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
5252
|
-
var
|
|
5263
|
+
var import_react12 = require("react");
|
|
5253
5264
|
var import_antd6 = require("antd");
|
|
5254
5265
|
var import_icons5 = require("@ant-design/icons");
|
|
5255
5266
|
|
|
@@ -5285,14 +5296,14 @@ var StickyActionBar = ({
|
|
|
5285
5296
|
position = "sticky",
|
|
5286
5297
|
surface = "default"
|
|
5287
5298
|
}) => {
|
|
5288
|
-
const [isMobile, setIsMobile] = (0,
|
|
5289
|
-
(0,
|
|
5299
|
+
const [isMobile, setIsMobile] = (0, import_react12.useState)(false);
|
|
5300
|
+
(0, import_react12.useEffect)(() => {
|
|
5290
5301
|
const update = () => setIsMobile(typeof window !== "undefined" && window.innerWidth <= 768);
|
|
5291
5302
|
update();
|
|
5292
5303
|
window.addEventListener("resize", update);
|
|
5293
5304
|
return () => window.removeEventListener("resize", update);
|
|
5294
5305
|
}, []);
|
|
5295
|
-
const visibleActions = (0,
|
|
5306
|
+
const visibleActions = (0, import_react12.useMemo)(
|
|
5296
5307
|
() => actions.filter((action) => action.visible !== false).sort((left, right) => getActionPriority(left) - getActionPriority(right)),
|
|
5297
5308
|
[actions]
|
|
5298
5309
|
);
|
|
@@ -5361,7 +5372,7 @@ var StickyActionBar = ({
|
|
|
5361
5372
|
};
|
|
5362
5373
|
|
|
5363
5374
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
5364
|
-
var
|
|
5375
|
+
var import_react13 = require("react");
|
|
5365
5376
|
var import_icons6 = require("@ant-design/icons");
|
|
5366
5377
|
|
|
5367
5378
|
// packages/sdk/src/components/core/constants.ts
|
|
@@ -5525,8 +5536,8 @@ var ApprovalTimeline = ({
|
|
|
5525
5536
|
compactMode = false,
|
|
5526
5537
|
showApproverInfo = true
|
|
5527
5538
|
}) => {
|
|
5528
|
-
const taskList = (0,
|
|
5529
|
-
const groups = (0,
|
|
5539
|
+
const taskList = (0, import_react13.useMemo)(() => Array.isArray(tasks) ? tasks : [], [tasks]);
|
|
5540
|
+
const groups = (0, import_react13.useMemo)(() => groupTasks(taskList), [taskList]);
|
|
5530
5541
|
if (taskList.length === 0) {
|
|
5531
5542
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
5532
5543
|
"div",
|
|
@@ -5672,7 +5683,7 @@ var ProcessPreview = ({
|
|
|
5672
5683
|
};
|
|
5673
5684
|
|
|
5674
5685
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
5675
|
-
var
|
|
5686
|
+
var import_react16 = require("react");
|
|
5676
5687
|
var import_antd9 = require("antd");
|
|
5677
5688
|
|
|
5678
5689
|
// packages/sdk/src/components/core/processApi.ts
|
|
@@ -5717,13 +5728,13 @@ async function getInitiatorSelectCandidates(request, params) {
|
|
|
5717
5728
|
}
|
|
5718
5729
|
|
|
5719
5730
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
5720
|
-
var
|
|
5731
|
+
var import_react15 = require("react");
|
|
5721
5732
|
var import_antd8 = require("antd");
|
|
5722
5733
|
var import_icons8 = require("@ant-design/icons");
|
|
5723
5734
|
var MobileAntd = __toESM(require("antd-mobile"));
|
|
5724
5735
|
|
|
5725
5736
|
// packages/sdk/src/components/fields/shared/useLazyDepartmentTree.ts
|
|
5726
|
-
var
|
|
5737
|
+
var import_react14 = require("react");
|
|
5727
5738
|
var toLazyNode = (node) => {
|
|
5728
5739
|
const normalized = normalizeDepartmentNode(node);
|
|
5729
5740
|
const id = getDepartmentId(normalized);
|
|
@@ -5773,15 +5784,15 @@ function buildIndexes(nodes) {
|
|
|
5773
5784
|
return { nodeMap, parentMap, flatNodes };
|
|
5774
5785
|
}
|
|
5775
5786
|
function useLazyDepartmentTree(api, configuredTreeData) {
|
|
5776
|
-
const [treeData, setTreeDataState] = (0,
|
|
5787
|
+
const [treeData, setTreeDataState] = (0, import_react14.useState)(
|
|
5777
5788
|
() => (configuredTreeData || []).map(toLazyNode)
|
|
5778
5789
|
);
|
|
5779
|
-
const [treeLoading, setTreeLoading] = (0,
|
|
5780
|
-
const treeDataRef = (0,
|
|
5781
|
-
const rootsLoadedRef = (0,
|
|
5782
|
-
const rootPromiseRef = (0,
|
|
5783
|
-
const childPromiseRef = (0,
|
|
5784
|
-
const setTreeData = (0,
|
|
5790
|
+
const [treeLoading, setTreeLoading] = (0, import_react14.useState)(false);
|
|
5791
|
+
const treeDataRef = (0, import_react14.useRef)(treeData);
|
|
5792
|
+
const rootsLoadedRef = (0, import_react14.useRef)(Boolean(configuredTreeData?.length));
|
|
5793
|
+
const rootPromiseRef = (0, import_react14.useRef)(null);
|
|
5794
|
+
const childPromiseRef = (0, import_react14.useRef)({});
|
|
5795
|
+
const setTreeData = (0, import_react14.useCallback)(
|
|
5785
5796
|
(next) => {
|
|
5786
5797
|
const resolved = typeof next === "function" ? next(treeDataRef.current) : next;
|
|
5787
5798
|
treeDataRef.current = resolved;
|
|
@@ -5790,13 +5801,13 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
5790
5801
|
},
|
|
5791
5802
|
[]
|
|
5792
5803
|
);
|
|
5793
|
-
(0,
|
|
5804
|
+
(0, import_react14.useEffect)(() => {
|
|
5794
5805
|
if (!configuredTreeData) return;
|
|
5795
5806
|
const next = configuredTreeData.map(toLazyNode);
|
|
5796
5807
|
rootsLoadedRef.current = next.length > 0;
|
|
5797
5808
|
setTreeData(next);
|
|
5798
5809
|
}, [configuredTreeData, setTreeData]);
|
|
5799
|
-
const loadRootDepartments = (0,
|
|
5810
|
+
const loadRootDepartments = (0, import_react14.useCallback)(async () => {
|
|
5800
5811
|
if (rootsLoadedRef.current) return treeDataRef.current;
|
|
5801
5812
|
if (rootPromiseRef.current) return rootPromiseRef.current;
|
|
5802
5813
|
setTreeLoading(true);
|
|
@@ -5812,7 +5823,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
5812
5823
|
rootPromiseRef.current = promise;
|
|
5813
5824
|
return promise;
|
|
5814
5825
|
}, [api, setTreeData]);
|
|
5815
|
-
const loadChildren = (0,
|
|
5826
|
+
const loadChildren = (0, import_react14.useCallback)(
|
|
5816
5827
|
async (parentId) => {
|
|
5817
5828
|
const id = String(parentId || "");
|
|
5818
5829
|
if (!id) return [];
|
|
@@ -5833,8 +5844,8 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
5833
5844
|
},
|
|
5834
5845
|
[api, setTreeData]
|
|
5835
5846
|
);
|
|
5836
|
-
const indexes = (0,
|
|
5837
|
-
(0,
|
|
5847
|
+
const indexes = (0, import_react14.useMemo)(() => buildIndexes(treeData), [treeData]);
|
|
5848
|
+
(0, import_react14.useEffect)(() => {
|
|
5838
5849
|
void loadRootDepartments();
|
|
5839
5850
|
}, [loadRootDepartments]);
|
|
5840
5851
|
return {
|
|
@@ -5879,24 +5890,24 @@ function UserPickerPanel({
|
|
|
5879
5890
|
flatNodes,
|
|
5880
5891
|
loadChildren
|
|
5881
5892
|
} = useLazyDepartmentTree(api, treeData);
|
|
5882
|
-
const [departmentKeyword, setDepartmentKeyword] = (0,
|
|
5883
|
-
const [memberKeyword, setMemberKeyword] = (0,
|
|
5884
|
-
const [mobileKeyword, setMobileKeyword] = (0,
|
|
5885
|
-
const [currentDeptId, setCurrentDeptId] = (0,
|
|
5886
|
-
const [expandedKeys, setExpandedKeys] = (0,
|
|
5887
|
-
const [members, setMembers] = (0,
|
|
5888
|
-
const [memberPage, setMemberPage] = (0,
|
|
5889
|
-
const [memberPageSize, setMemberPageSize] = (0,
|
|
5890
|
-
const [memberTotal, setMemberTotal] = (0,
|
|
5891
|
-
const [memberReloadKey, setMemberReloadKey] = (0,
|
|
5892
|
-
const [loading, setLoading] = (0,
|
|
5893
|
-
const [selected, setSelected] = (0,
|
|
5893
|
+
const [departmentKeyword, setDepartmentKeyword] = (0, import_react15.useState)("");
|
|
5894
|
+
const [memberKeyword, setMemberKeyword] = (0, import_react15.useState)("");
|
|
5895
|
+
const [mobileKeyword, setMobileKeyword] = (0, import_react15.useState)("");
|
|
5896
|
+
const [currentDeptId, setCurrentDeptId] = (0, import_react15.useState)("");
|
|
5897
|
+
const [expandedKeys, setExpandedKeys] = (0, import_react15.useState)([]);
|
|
5898
|
+
const [members, setMembers] = (0, import_react15.useState)(() => normalizeUsers(dataSource));
|
|
5899
|
+
const [memberPage, setMemberPage] = (0, import_react15.useState)(1);
|
|
5900
|
+
const [memberPageSize, setMemberPageSize] = (0, import_react15.useState)(DEFAULT_MEMBER_PAGE_SIZE);
|
|
5901
|
+
const [memberTotal, setMemberTotal] = (0, import_react15.useState)(() => normalizeUsers(dataSource).length);
|
|
5902
|
+
const [memberReloadKey, setMemberReloadKey] = (0, import_react15.useState)(0);
|
|
5903
|
+
const [loading, setLoading] = (0, import_react15.useState)(false);
|
|
5904
|
+
const [selected, setSelected] = (0, import_react15.useState)(() => normalizeUsers(value));
|
|
5894
5905
|
const selectedIds = selected.map(getUserId);
|
|
5895
5906
|
const MobileSearchBar = getMobileComponent("SearchBar");
|
|
5896
5907
|
const activeMemberKeyword = (mobile ? mobileKeyword : memberKeyword).trim();
|
|
5897
|
-
const staticUsers = (0,
|
|
5908
|
+
const staticUsers = (0, import_react15.useMemo)(() => normalizeUsers(dataSource), [dataSource]);
|
|
5898
5909
|
const hasStaticUserSource = staticUsers.length > 0;
|
|
5899
|
-
(0,
|
|
5910
|
+
(0, import_react15.useEffect)(() => {
|
|
5900
5911
|
if (mobile) return;
|
|
5901
5912
|
if (currentDeptId || deptTreeData.length === 0) return;
|
|
5902
5913
|
setExpandedKeys(deptTreeData.map((node) => getDepartmentId(node)));
|
|
@@ -5904,17 +5915,17 @@ function UserPickerPanel({
|
|
|
5904
5915
|
setCurrentDeptId(getDepartmentId(deptTreeData[0]));
|
|
5905
5916
|
}
|
|
5906
5917
|
}, [currentDeptId, deptTreeData, loadAllWhenNoDepartment, mobile]);
|
|
5907
|
-
(0,
|
|
5918
|
+
(0, import_react15.useEffect)(() => {
|
|
5908
5919
|
setMemberPage(1);
|
|
5909
5920
|
}, [activeMemberKeyword, currentDeptId, dataSource, mobile]);
|
|
5910
|
-
const handleDepartmentSelect = (0,
|
|
5921
|
+
const handleDepartmentSelect = (0, import_react15.useCallback)((deptId) => {
|
|
5911
5922
|
const nextDeptId = String(deptId || "");
|
|
5912
5923
|
setCurrentDeptId(nextDeptId);
|
|
5913
5924
|
setMemberKeyword("");
|
|
5914
5925
|
setMemberPage(1);
|
|
5915
5926
|
setMemberReloadKey((current) => current + 1);
|
|
5916
5927
|
}, []);
|
|
5917
|
-
(0,
|
|
5928
|
+
(0, import_react15.useEffect)(() => {
|
|
5918
5929
|
let active = true;
|
|
5919
5930
|
const keyword = activeMemberKeyword;
|
|
5920
5931
|
if (hasStaticUserSource) {
|
|
@@ -5987,7 +5998,7 @@ function UserPickerPanel({
|
|
|
5987
5998
|
memberReloadKey,
|
|
5988
5999
|
staticUsers
|
|
5989
6000
|
]);
|
|
5990
|
-
const currentPath = (0,
|
|
6001
|
+
const currentPath = (0, import_react15.useMemo)(() => {
|
|
5991
6002
|
if (!currentDeptId) return [];
|
|
5992
6003
|
const path = [];
|
|
5993
6004
|
let cursor = currentDeptId;
|
|
@@ -5999,7 +6010,7 @@ function UserPickerPanel({
|
|
|
5999
6010
|
}
|
|
6000
6011
|
return path;
|
|
6001
6012
|
}, [currentDeptId, nodeMap, parentMap]);
|
|
6002
|
-
const mobileDepartments = (0,
|
|
6013
|
+
const mobileDepartments = (0, import_react15.useMemo)(() => {
|
|
6003
6014
|
const keyword = mobileKeyword.trim().toLowerCase();
|
|
6004
6015
|
if (keyword) {
|
|
6005
6016
|
return flatNodes.filter((item) => item.name.toLowerCase().includes(keyword)).map((item) => item.node);
|
|
@@ -6263,19 +6274,19 @@ var RequirementSelect = ({
|
|
|
6263
6274
|
selectedUsers,
|
|
6264
6275
|
onChange
|
|
6265
6276
|
}) => {
|
|
6266
|
-
const [pickerOpen, setPickerOpen] = (0,
|
|
6267
|
-
const initialCandidates = (0,
|
|
6277
|
+
const [pickerOpen, setPickerOpen] = (0, import_react16.useState)(false);
|
|
6278
|
+
const initialCandidates = (0, import_react16.useMemo)(
|
|
6268
6279
|
() => (requirement.candidateUsers || []).map(normalizeCandidate).filter(Boolean),
|
|
6269
6280
|
[requirement.candidateUsers]
|
|
6270
6281
|
);
|
|
6271
|
-
const [optionsSource, setOptionsSource] = (0,
|
|
6272
|
-
const [loading, setLoading] = (0,
|
|
6273
|
-
(0,
|
|
6282
|
+
const [optionsSource, setOptionsSource] = (0, import_react16.useState)(initialCandidates);
|
|
6283
|
+
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
6284
|
+
(0, import_react16.useEffect)(() => {
|
|
6274
6285
|
setOptionsSource(
|
|
6275
6286
|
(current) => mergeUsers(initialCandidates, mergeUsers(current, selectedUsers))
|
|
6276
6287
|
);
|
|
6277
6288
|
}, [initialCandidates, selectedUsers]);
|
|
6278
|
-
const loadCandidates = (0,
|
|
6289
|
+
const loadCandidates = (0, import_react16.useCallback)(
|
|
6279
6290
|
async (keyword) => {
|
|
6280
6291
|
setLoading(true);
|
|
6281
6292
|
try {
|
|
@@ -6313,12 +6324,12 @@ var RequirementSelect = ({
|
|
|
6313
6324
|
},
|
|
6314
6325
|
[api, appType, formUuid, initialCandidates.length, requirement.nodeId, requirement.scope]
|
|
6315
6326
|
);
|
|
6316
|
-
(0,
|
|
6327
|
+
(0, import_react16.useEffect)(() => {
|
|
6317
6328
|
if (requirement.scope !== "all" && open && formUuid && appType && requirement.nodeId) {
|
|
6318
6329
|
void loadCandidates();
|
|
6319
6330
|
}
|
|
6320
6331
|
}, [appType, formUuid, loadCandidates, open, requirement.nodeId, requirement.scope]);
|
|
6321
|
-
const options = (0,
|
|
6332
|
+
const options = (0, import_react16.useMemo)(
|
|
6322
6333
|
() => optionsSource.map((user) => ({
|
|
6323
6334
|
value: user.id,
|
|
6324
6335
|
label: getUserLabel(user)
|
|
@@ -6403,9 +6414,9 @@ var InitiatorApproverSelector = ({
|
|
|
6403
6414
|
onOk,
|
|
6404
6415
|
onCancel
|
|
6405
6416
|
}) => {
|
|
6406
|
-
const [selected, setSelected] = (0,
|
|
6407
|
-
const wasOpenRef = (0,
|
|
6408
|
-
(0,
|
|
6417
|
+
const [selected, setSelected] = (0, import_react16.useState)({});
|
|
6418
|
+
const wasOpenRef = (0, import_react16.useRef)(false);
|
|
6419
|
+
(0, import_react16.useEffect)(() => {
|
|
6409
6420
|
if (open && !wasOpenRef.current) {
|
|
6410
6421
|
setSelected(value || EMPTY_SELECTED_MAP);
|
|
6411
6422
|
}
|
|
@@ -6463,20 +6474,20 @@ var normalizeCapabilities = (value) => {
|
|
|
6463
6474
|
function useProcessCapabilities(options) {
|
|
6464
6475
|
const { enabled = true, refreshKey, onError, ...params } = options;
|
|
6465
6476
|
const sdk = usePageSdk();
|
|
6466
|
-
const [capabilities, setCapabilities] = (0,
|
|
6477
|
+
const [capabilities, setCapabilities] = (0, import_react17.useState)(
|
|
6467
6478
|
null
|
|
6468
6479
|
);
|
|
6469
|
-
const [loading, setLoading] = (0,
|
|
6470
|
-
const [error, setError] = (0,
|
|
6471
|
-
const mountedRef = (0,
|
|
6480
|
+
const [loading, setLoading] = (0, import_react17.useState)(false);
|
|
6481
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
6482
|
+
const mountedRef = (0, import_react17.useRef)(true);
|
|
6472
6483
|
const paramsKey = JSON.stringify({ ...params, refreshKey });
|
|
6473
|
-
(0,
|
|
6484
|
+
(0, import_react17.useEffect)(() => {
|
|
6474
6485
|
mountedRef.current = true;
|
|
6475
6486
|
return () => {
|
|
6476
6487
|
mountedRef.current = false;
|
|
6477
6488
|
};
|
|
6478
6489
|
}, []);
|
|
6479
|
-
const refresh = (0,
|
|
6490
|
+
const refresh = (0, import_react17.useCallback)(async () => {
|
|
6480
6491
|
if (!enabled) return capabilities;
|
|
6481
6492
|
setLoading(true);
|
|
6482
6493
|
setError(null);
|
|
@@ -6502,7 +6513,7 @@ function useProcessCapabilities(options) {
|
|
|
6502
6513
|
}
|
|
6503
6514
|
}
|
|
6504
6515
|
}, [capabilities, enabled, onError, paramsKey, sdk]);
|
|
6505
|
-
(0,
|
|
6516
|
+
(0, import_react17.useEffect)(() => {
|
|
6506
6517
|
if (!enabled) return;
|
|
6507
6518
|
void refresh();
|
|
6508
6519
|
}, [enabled, paramsKey, refresh]);
|
|
@@ -6527,8 +6538,8 @@ var requireValue = (value, message3) => {
|
|
|
6527
6538
|
function useProcessActions(options) {
|
|
6528
6539
|
const { capabilities, formUuid, appType, getFormValues, onActionComplete } = options;
|
|
6529
6540
|
const sdk = usePageSdk();
|
|
6530
|
-
const [loadingAction, setLoadingAction] = (0,
|
|
6531
|
-
const buildUpdateFormDataJson = (0,
|
|
6541
|
+
const [loadingAction, setLoadingAction] = (0, import_react17.useState)(null);
|
|
6542
|
+
const buildUpdateFormDataJson = (0, import_react17.useCallback)(
|
|
6532
6543
|
(input) => {
|
|
6533
6544
|
if (input?.updateFormDataJson !== void 0) return input.updateFormDataJson;
|
|
6534
6545
|
const values = getFormValues?.();
|
|
@@ -6536,7 +6547,7 @@ function useProcessActions(options) {
|
|
|
6536
6547
|
},
|
|
6537
6548
|
[getFormValues]
|
|
6538
6549
|
);
|
|
6539
|
-
const executeOperation = (0,
|
|
6550
|
+
const executeOperation = (0, import_react17.useCallback)(
|
|
6540
6551
|
async (operation, input = {}) => {
|
|
6541
6552
|
if (!operation.enabled) return false;
|
|
6542
6553
|
setLoadingAction(operation.key);
|
|
@@ -6646,7 +6657,7 @@ function useProcessActions(options) {
|
|
|
6646
6657
|
sdk
|
|
6647
6658
|
]
|
|
6648
6659
|
);
|
|
6649
|
-
const execute = (0,
|
|
6660
|
+
const execute = (0, import_react17.useCallback)(
|
|
6650
6661
|
async (action, input) => {
|
|
6651
6662
|
const operation = (capabilities?.operations || []).find(
|
|
6652
6663
|
(item) => item.key === action
|
|
@@ -6721,7 +6732,7 @@ var ProcessActionBar = ({
|
|
|
6721
6732
|
position = "sticky"
|
|
6722
6733
|
}) => {
|
|
6723
6734
|
const [form] = import_antd10.Form.useForm();
|
|
6724
|
-
const [activeOperation, setActiveOperation] = (0,
|
|
6735
|
+
const [activeOperation, setActiveOperation] = (0, import_react17.useState)(null);
|
|
6725
6736
|
const autoCapabilities = useProcessCapabilities({
|
|
6726
6737
|
...capabilityParams || {},
|
|
6727
6738
|
enabled: Boolean(capabilityParams) && capabilityParams?.enabled !== false
|
|
@@ -6756,7 +6767,7 @@ var ProcessActionBar = ({
|
|
|
6756
6767
|
}
|
|
6757
6768
|
void actions.executeOperation(operation);
|
|
6758
6769
|
};
|
|
6759
|
-
const actionConfigs = (0,
|
|
6770
|
+
const actionConfigs = (0, import_react17.useMemo)(
|
|
6760
6771
|
() => operations.map((operation) => ({
|
|
6761
6772
|
key: operation.key,
|
|
6762
6773
|
label: operation.label || operation.key,
|
|
@@ -6870,7 +6881,7 @@ var ProcessTimeline = ({
|
|
|
6870
6881
|
var ProcessPreviewPanel = ProcessPreview;
|
|
6871
6882
|
|
|
6872
6883
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
6873
|
-
var
|
|
6884
|
+
var import_react19 = require("react");
|
|
6874
6885
|
|
|
6875
6886
|
// packages/sdk/src/runtime/core/fetch.ts
|
|
6876
6887
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -7095,7 +7106,7 @@ var createBrowserPageContext = (bootstrap, options = {}) => {
|
|
|
7095
7106
|
};
|
|
7096
7107
|
|
|
7097
7108
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
7098
|
-
var
|
|
7109
|
+
var import_react18 = require("react");
|
|
7099
7110
|
var import_antd11 = require("antd");
|
|
7100
7111
|
var import_icons10 = require("@ant-design/icons");
|
|
7101
7112
|
|
|
@@ -7279,7 +7290,7 @@ var getCurrentHref2 = () => typeof window === "undefined" ? "" : window.location
|
|
|
7279
7290
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
7280
7291
|
var useAuth = (options = {}) => {
|
|
7281
7292
|
const runtime = useOpenXiangda();
|
|
7282
|
-
const client = (0,
|
|
7293
|
+
const client = (0, import_react18.useMemo)(
|
|
7283
7294
|
() => createAuthClient({
|
|
7284
7295
|
appType: options.appType || runtime.appType,
|
|
7285
7296
|
servicePrefix: options.servicePrefix || runtime.servicePrefix,
|
|
@@ -7294,7 +7305,7 @@ var useAuth = (options = {}) => {
|
|
|
7294
7305
|
runtime.servicePrefix
|
|
7295
7306
|
]
|
|
7296
7307
|
);
|
|
7297
|
-
return (0,
|
|
7308
|
+
return (0, import_react18.useMemo)(
|
|
7298
7309
|
() => ({
|
|
7299
7310
|
client,
|
|
7300
7311
|
getMethods: client.getMethods,
|
|
@@ -7314,12 +7325,12 @@ var useAuth = (options = {}) => {
|
|
|
7314
7325
|
};
|
|
7315
7326
|
var useLoginMethods = (options = {}) => {
|
|
7316
7327
|
const auth = useAuth(options);
|
|
7317
|
-
const [state, setState] = (0,
|
|
7328
|
+
const [state, setState] = (0, import_react18.useState)({
|
|
7318
7329
|
data: null,
|
|
7319
7330
|
loading: true,
|
|
7320
7331
|
error: null
|
|
7321
7332
|
});
|
|
7322
|
-
const reload = (0,
|
|
7333
|
+
const reload = (0, import_react18.useCallback)(async () => {
|
|
7323
7334
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
7324
7335
|
try {
|
|
7325
7336
|
const data = await auth.getMethods();
|
|
@@ -7332,7 +7343,7 @@ var useLoginMethods = (options = {}) => {
|
|
|
7332
7343
|
});
|
|
7333
7344
|
}
|
|
7334
7345
|
}, [auth]);
|
|
7335
|
-
(0,
|
|
7346
|
+
(0, import_react18.useEffect)(() => {
|
|
7336
7347
|
let disposed = false;
|
|
7337
7348
|
const run = async () => {
|
|
7338
7349
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
@@ -7376,17 +7387,17 @@ var LoginPage = ({
|
|
|
7376
7387
|
const methodsState = useLoginMethods(authOptions);
|
|
7377
7388
|
const [passwordForm] = import_antd11.Form.useForm();
|
|
7378
7389
|
const [phoneForm] = import_antd11.Form.useForm();
|
|
7379
|
-
const [activeMethod, setActiveMethod] = (0,
|
|
7390
|
+
const [activeMethod, setActiveMethod] = (0, import_react18.useState)(
|
|
7380
7391
|
defaultMethod || "password"
|
|
7381
7392
|
);
|
|
7382
|
-
const [phonePurpose, setPhonePurpose] = (0,
|
|
7393
|
+
const [phonePurpose, setPhonePurpose] = (0, import_react18.useState)(
|
|
7383
7394
|
"login"
|
|
7384
7395
|
);
|
|
7385
|
-
const [phoneChallengeId, setPhoneChallengeId] = (0,
|
|
7386
|
-
const [passwordChallenge, setPasswordChallenge] = (0,
|
|
7387
|
-
const [submitting, setSubmitting] = (0,
|
|
7388
|
-
const [sendingCode, setSendingCode] = (0,
|
|
7389
|
-
const [error, setError] = (0,
|
|
7396
|
+
const [phoneChallengeId, setPhoneChallengeId] = (0, import_react18.useState)("");
|
|
7397
|
+
const [passwordChallenge, setPasswordChallenge] = (0, import_react18.useState)(null);
|
|
7398
|
+
const [submitting, setSubmitting] = (0, import_react18.useState)(false);
|
|
7399
|
+
const [sendingCode, setSendingCode] = (0, import_react18.useState)(false);
|
|
7400
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
7390
7401
|
const methods = methodsState.methods.filter((method) => method.enabled !== false);
|
|
7391
7402
|
const passwordMethod = findMethod(methods, "password");
|
|
7392
7403
|
const phoneMethod = findMethod(methods, "phone_code");
|
|
@@ -7394,7 +7405,7 @@ var LoginPage = ({
|
|
|
7394
7405
|
const ssoMethod = findMethod(methods, "sso");
|
|
7395
7406
|
const guestMethod = findMethod(methods, "guest");
|
|
7396
7407
|
const allowRegister = methodsState.data?.registration?.mode !== "reject";
|
|
7397
|
-
const tabItems = (0,
|
|
7408
|
+
const tabItems = (0, import_react18.useMemo)(() => {
|
|
7398
7409
|
const items = [];
|
|
7399
7410
|
if (passwordMethod) {
|
|
7400
7411
|
items.push({
|
|
@@ -7513,7 +7524,7 @@ var LoginPage = ({
|
|
|
7513
7524
|
sendingCode,
|
|
7514
7525
|
submitting
|
|
7515
7526
|
]);
|
|
7516
|
-
(0,
|
|
7527
|
+
(0, import_react18.useEffect)(() => {
|
|
7517
7528
|
const firstKey = tabItems[0]?.key;
|
|
7518
7529
|
if (firstKey && !tabItems.some((item) => item.key === activeMethod)) {
|
|
7519
7530
|
setActiveMethod(firstKey);
|
|
@@ -7853,26 +7864,26 @@ var RuntimeHttpError = class extends Error {
|
|
|
7853
7864
|
this.payload = snapshot.payload;
|
|
7854
7865
|
}
|
|
7855
7866
|
};
|
|
7856
|
-
var OpenXiangdaRuntimeContext = (0,
|
|
7867
|
+
var OpenXiangdaRuntimeContext = (0, import_react19.createContext)(null);
|
|
7857
7868
|
var OpenXiangdaProvider = ({
|
|
7858
7869
|
appType,
|
|
7859
7870
|
servicePrefix = "/service",
|
|
7860
7871
|
fetchImpl,
|
|
7861
7872
|
children
|
|
7862
7873
|
}) => {
|
|
7863
|
-
const resolvedFetch = (0,
|
|
7864
|
-
const resolvedAppType = (0,
|
|
7874
|
+
const resolvedFetch = (0, import_react19.useMemo)(() => createBoundFetch(fetchImpl), [fetchImpl]);
|
|
7875
|
+
const resolvedAppType = (0, import_react19.useMemo)(
|
|
7865
7876
|
() => appType || resolveAppTypeFromLocation(),
|
|
7866
7877
|
[appType]
|
|
7867
7878
|
);
|
|
7868
|
-
const [, setAccessTokenState] = (0,
|
|
7869
|
-
const [authState, setAuthState] = (0,
|
|
7879
|
+
const [, setAccessTokenState] = (0, import_react19.useState)(null);
|
|
7880
|
+
const [authState, setAuthState] = (0, import_react19.useState)({
|
|
7870
7881
|
status: "unknown",
|
|
7871
7882
|
error: null
|
|
7872
7883
|
});
|
|
7873
|
-
const accessTokenRef = (0,
|
|
7874
|
-
const refreshRequestRef = (0,
|
|
7875
|
-
const applyAccessToken = (0,
|
|
7884
|
+
const accessTokenRef = (0, import_react19.useRef)(null);
|
|
7885
|
+
const refreshRequestRef = (0, import_react19.useRef)(null);
|
|
7886
|
+
const applyAccessToken = (0, import_react19.useCallback)(
|
|
7876
7887
|
(nextAccessToken, options = {}) => {
|
|
7877
7888
|
if (!nextAccessToken && options.clearIfToken && accessTokenRef.current?.token !== options.clearIfToken) {
|
|
7878
7889
|
return accessTokenRef.current;
|
|
@@ -7890,7 +7901,7 @@ var OpenXiangdaProvider = ({
|
|
|
7890
7901
|
},
|
|
7891
7902
|
[]
|
|
7892
7903
|
);
|
|
7893
|
-
const setAccessToken = (0,
|
|
7904
|
+
const setAccessToken = (0, import_react19.useCallback)(
|
|
7894
7905
|
(nextAccessToken, options = {}) => {
|
|
7895
7906
|
const previousState = accessTokenRef.current;
|
|
7896
7907
|
const nextState = applyAccessToken(nextAccessToken, options);
|
|
@@ -7906,7 +7917,7 @@ var OpenXiangdaProvider = ({
|
|
|
7906
7917
|
},
|
|
7907
7918
|
[applyAccessToken]
|
|
7908
7919
|
);
|
|
7909
|
-
const markUnauthenticated = (0,
|
|
7920
|
+
const markUnauthenticated = (0, import_react19.useCallback)(
|
|
7910
7921
|
(error) => {
|
|
7911
7922
|
const runtimeError = normalizeRuntimeError(error);
|
|
7912
7923
|
applyAccessToken(null);
|
|
@@ -7914,7 +7925,7 @@ var OpenXiangdaProvider = ({
|
|
|
7914
7925
|
},
|
|
7915
7926
|
[applyAccessToken]
|
|
7916
7927
|
);
|
|
7917
|
-
const refreshAccessToken = (0,
|
|
7928
|
+
const refreshAccessToken = (0, import_react19.useCallback)(async () => {
|
|
7918
7929
|
if (!resolvedAppType) return null;
|
|
7919
7930
|
if (!refreshRequestRef.current) {
|
|
7920
7931
|
setAuthState((prev) => ({ ...prev, status: "refreshing", error: null }));
|
|
@@ -7975,7 +7986,7 @@ var OpenXiangdaProvider = ({
|
|
|
7975
7986
|
}
|
|
7976
7987
|
return refreshRequestRef.current;
|
|
7977
7988
|
}, [applyAccessToken, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
7978
|
-
const authorizedFetch = (0,
|
|
7989
|
+
const authorizedFetch = (0, import_react19.useMemo)(
|
|
7979
7990
|
() => createAuthorizedFetch({
|
|
7980
7991
|
appType: resolvedAppType,
|
|
7981
7992
|
baseFetch: resolvedFetch,
|
|
@@ -7985,18 +7996,18 @@ var OpenXiangdaProvider = ({
|
|
|
7985
7996
|
}),
|
|
7986
7997
|
[markUnauthenticated, refreshAccessToken, resolvedAppType, resolvedFetch]
|
|
7987
7998
|
);
|
|
7988
|
-
const getAuthHeaders = (0,
|
|
7999
|
+
const getAuthHeaders = (0, import_react19.useCallback)(() => {
|
|
7989
8000
|
const state2 = accessTokenRef.current;
|
|
7990
8001
|
if (!state2) return {};
|
|
7991
8002
|
const token = resolveAccessTokenForCurrentRoute(state2);
|
|
7992
8003
|
return token ? { authorization: `Bearer ${token}` } : {};
|
|
7993
8004
|
}, []);
|
|
7994
|
-
const [state, setState] = (0,
|
|
8005
|
+
const [state, setState] = (0, import_react19.useState)({
|
|
7995
8006
|
data: null,
|
|
7996
8007
|
loading: true,
|
|
7997
8008
|
error: null
|
|
7998
8009
|
});
|
|
7999
|
-
const reload = (0,
|
|
8010
|
+
const reload = (0, import_react19.useCallback)(async (options = {}) => {
|
|
8000
8011
|
if (!resolvedAppType) {
|
|
8001
8012
|
setState({
|
|
8002
8013
|
data: null,
|
|
@@ -8060,10 +8071,10 @@ var OpenXiangdaProvider = ({
|
|
|
8060
8071
|
}
|
|
8061
8072
|
}
|
|
8062
8073
|
}, [authorizedFetch, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
8063
|
-
(0,
|
|
8074
|
+
(0, import_react19.useEffect)(() => {
|
|
8064
8075
|
void reload();
|
|
8065
8076
|
}, [reload]);
|
|
8066
|
-
const value = (0,
|
|
8077
|
+
const value = (0, import_react19.useMemo)(
|
|
8067
8078
|
() => ({
|
|
8068
8079
|
...state,
|
|
8069
8080
|
appType: resolvedAppType,
|
|
@@ -8089,7 +8100,7 @@ var OpenXiangdaProvider = ({
|
|
|
8089
8100
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(OpenXiangdaRuntimeContext.Provider, { value, children });
|
|
8090
8101
|
};
|
|
8091
8102
|
var useOpenXiangda = () => {
|
|
8092
|
-
const context = (0,
|
|
8103
|
+
const context = (0, import_react19.useContext)(OpenXiangdaRuntimeContext);
|
|
8093
8104
|
if (!context) {
|
|
8094
8105
|
throw new Error("useOpenXiangda must be used inside OpenXiangdaProvider");
|
|
8095
8106
|
}
|
|
@@ -8106,7 +8117,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
8106
8117
|
navigation
|
|
8107
8118
|
}) => {
|
|
8108
8119
|
const runtime = useOpenXiangda();
|
|
8109
|
-
const context = (0,
|
|
8120
|
+
const context = (0, import_react19.useMemo)(() => {
|
|
8110
8121
|
const bootstrap = runtime.data;
|
|
8111
8122
|
const app = toRuntimeRecord(bootstrap?.app);
|
|
8112
8123
|
const user = toRuntimeRecord(bootstrap?.user);
|
|
@@ -8204,12 +8215,12 @@ var usePermission = () => {
|
|
|
8204
8215
|
};
|
|
8205
8216
|
var useCanAccessRoute = (input) => {
|
|
8206
8217
|
const runtime = useOpenXiangda();
|
|
8207
|
-
const [state, setState] = (0,
|
|
8218
|
+
const [state, setState] = (0, import_react19.useState)({
|
|
8208
8219
|
data: null,
|
|
8209
8220
|
loading: true,
|
|
8210
8221
|
error: null
|
|
8211
8222
|
});
|
|
8212
|
-
(0,
|
|
8223
|
+
(0, import_react19.useEffect)(() => {
|
|
8213
8224
|
let disposed = false;
|
|
8214
8225
|
const check = async () => {
|
|
8215
8226
|
const permissions = runtime.data?.permissions;
|
|
@@ -8340,7 +8351,7 @@ var PermissionBoundary = ({
|
|
|
8340
8351
|
};
|
|
8341
8352
|
var useRuntimeAuth = () => {
|
|
8342
8353
|
const runtime = useOpenXiangda();
|
|
8343
|
-
const resolveLoginUrl2 = (0,
|
|
8354
|
+
const resolveLoginUrl2 = (0, import_react19.useCallback)(
|
|
8344
8355
|
async (options = {}) => {
|
|
8345
8356
|
const redirectUri = options.redirectUri || getCurrentHref4();
|
|
8346
8357
|
const domain = options.domain || getCurrentHostname2();
|
|
@@ -8387,7 +8398,7 @@ var useRuntimeAuth = () => {
|
|
|
8387
8398
|
},
|
|
8388
8399
|
[runtime.baseFetchImpl, runtime.data?.app, runtime.servicePrefix]
|
|
8389
8400
|
);
|
|
8390
|
-
const redirectToLogin = (0,
|
|
8401
|
+
const redirectToLogin = (0, import_react19.useCallback)(
|
|
8391
8402
|
async (options = {}) => {
|
|
8392
8403
|
const loginUrl = await resolveLoginUrl2(options);
|
|
8393
8404
|
if (typeof window !== "undefined") {
|
|
@@ -8401,7 +8412,7 @@ var useRuntimeAuth = () => {
|
|
|
8401
8412
|
},
|
|
8402
8413
|
[resolveLoginUrl2]
|
|
8403
8414
|
);
|
|
8404
|
-
const logout = (0,
|
|
8415
|
+
const logout = (0, import_react19.useCallback)(async () => {
|
|
8405
8416
|
const response = await runtime.baseFetchImpl(
|
|
8406
8417
|
buildServiceUrl2(runtime.servicePrefix, "/api/auth/logout"),
|
|
8407
8418
|
{
|
|
@@ -8421,7 +8432,7 @@ var useRuntimeAuth = () => {
|
|
|
8421
8432
|
runtime.setAccessToken(null);
|
|
8422
8433
|
return payload;
|
|
8423
8434
|
}, [runtime.baseFetchImpl, runtime.servicePrefix, runtime.setAccessToken]);
|
|
8424
|
-
const logoutAndRedirect = (0,
|
|
8435
|
+
const logoutAndRedirect = (0, import_react19.useCallback)(
|
|
8425
8436
|
async (options = {}) => {
|
|
8426
8437
|
try {
|
|
8427
8438
|
await logout();
|
|
@@ -8432,7 +8443,7 @@ var useRuntimeAuth = () => {
|
|
|
8432
8443
|
},
|
|
8433
8444
|
[logout, redirectToLogin]
|
|
8434
8445
|
);
|
|
8435
|
-
return (0,
|
|
8446
|
+
return (0, import_react19.useMemo)(
|
|
8436
8447
|
() => ({
|
|
8437
8448
|
logout,
|
|
8438
8449
|
logoutAndRedirect,
|
|
@@ -8451,7 +8462,7 @@ var RuntimeAuthGuard = ({
|
|
|
8451
8462
|
}) => {
|
|
8452
8463
|
const runtime = useOpenXiangda();
|
|
8453
8464
|
const auth = useRuntimeAuth();
|
|
8454
|
-
const redirectedRef = (0,
|
|
8465
|
+
const redirectedRef = (0, import_react19.useRef)(false);
|
|
8455
8466
|
const currentPath = getCurrentPathname();
|
|
8456
8467
|
const excluded = isRuntimeAuthGuardExcluded(
|
|
8457
8468
|
currentPath,
|
|
@@ -8459,7 +8470,7 @@ var RuntimeAuthGuard = ({
|
|
|
8459
8470
|
excludedPaths
|
|
8460
8471
|
);
|
|
8461
8472
|
const shouldRedirect = !disabled && !excluded && !runtime.loading && (runtime.authState.status === "unauthenticated" || runtime.error?.type === "unauthenticated");
|
|
8462
|
-
(0,
|
|
8473
|
+
(0, import_react19.useEffect)(() => {
|
|
8463
8474
|
if (!shouldRedirect || redirectedRef.current) return;
|
|
8464
8475
|
redirectedRef.current = true;
|
|
8465
8476
|
void auth.redirectToLogin({
|
|
@@ -8802,7 +8813,7 @@ var resolveAppTypeFromLocation = () => {
|
|
|
8802
8813
|
};
|
|
8803
8814
|
|
|
8804
8815
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
8805
|
-
var
|
|
8816
|
+
var import_react20 = require("react");
|
|
8806
8817
|
|
|
8807
8818
|
// packages/sdk/src/runtime/core/publicAccess.ts
|
|
8808
8819
|
var PublicAccessClientError = class extends Error {
|
|
@@ -8935,14 +8946,14 @@ var usePublicAccess = (options = {}) => {
|
|
|
8935
8946
|
autoStart = true,
|
|
8936
8947
|
...sessionInput
|
|
8937
8948
|
} = options;
|
|
8938
|
-
const [session, setSession] = (0,
|
|
8939
|
-
const [error, setError] = (0,
|
|
8940
|
-
const [loading, setLoading] = (0,
|
|
8941
|
-
const activeSessionRef = (0,
|
|
8942
|
-
const mountedRef = (0,
|
|
8949
|
+
const [session, setSession] = (0, import_react20.useState)(null);
|
|
8950
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
8951
|
+
const [loading, setLoading] = (0, import_react20.useState)(Boolean(autoStart));
|
|
8952
|
+
const activeSessionRef = (0, import_react20.useRef)(null);
|
|
8953
|
+
const mountedRef = (0, import_react20.useRef)(true);
|
|
8943
8954
|
const sessionInputKey = JSON.stringify(sessionInput);
|
|
8944
|
-
const stableSessionInput = (0,
|
|
8945
|
-
const client = (0,
|
|
8955
|
+
const stableSessionInput = (0, import_react20.useMemo)(() => sessionInput, [sessionInputKey]);
|
|
8956
|
+
const client = (0, import_react20.useMemo)(
|
|
8946
8957
|
() => createPublicAccessClient({
|
|
8947
8958
|
appType,
|
|
8948
8959
|
servicePrefix,
|
|
@@ -8950,7 +8961,7 @@ var usePublicAccess = (options = {}) => {
|
|
|
8950
8961
|
}),
|
|
8951
8962
|
[appType, fetchImpl, servicePrefix]
|
|
8952
8963
|
);
|
|
8953
|
-
const startSession = (0,
|
|
8964
|
+
const startSession = (0, import_react20.useCallback)(
|
|
8954
8965
|
async (input = {}) => {
|
|
8955
8966
|
setLoading(true);
|
|
8956
8967
|
setError(null);
|
|
@@ -8996,11 +9007,11 @@ var usePublicAccess = (options = {}) => {
|
|
|
8996
9007
|
},
|
|
8997
9008
|
[client, reloadRuntime, setAccessToken, stableSessionInput]
|
|
8998
9009
|
);
|
|
8999
|
-
(0,
|
|
9010
|
+
(0, import_react20.useEffect)(() => {
|
|
9000
9011
|
if (!autoStart) return;
|
|
9001
9012
|
void startSession().catch(() => void 0);
|
|
9002
9013
|
}, [autoStart, startSession]);
|
|
9003
|
-
(0,
|
|
9014
|
+
(0, import_react20.useEffect)(
|
|
9004
9015
|
() => {
|
|
9005
9016
|
mountedRef.current = true;
|
|
9006
9017
|
return () => {
|