sy-form-components 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +68 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3672,7 +3672,12 @@ var CHUNK_UPLOAD_THRESHOLD = 10 * 1024 * 1024;
|
|
|
3672
3672
|
var trimTrailingSlash = (value) => String(value || "").replace(/\/$/, "");
|
|
3673
3673
|
var getDefaultBaseUrl = () => {
|
|
3674
3674
|
const globalEnv = globalThis.process?.env;
|
|
3675
|
-
|
|
3675
|
+
const envBaseUrl = globalEnv?.FORM_API_BASE_URL || globalEnv?.BASE_API_URL;
|
|
3676
|
+
if (envBaseUrl) return trimTrailingSlash(envBaseUrl);
|
|
3677
|
+
const browserGlobal = typeof window !== "undefined" ? window : void 0;
|
|
3678
|
+
const windowBaseUrl = browserGlobal?.FORM_API_BASE_URL || browserGlobal?.BASE_API_URL || browserGlobal?.__FORM_API_BASE_URL__ || browserGlobal?.__LOWCODE_API_BASE_URL__;
|
|
3679
|
+
if (windowBaseUrl) return trimTrailingSlash(windowBaseUrl);
|
|
3680
|
+
return typeof window !== "undefined" ? "/service" : "";
|
|
3676
3681
|
};
|
|
3677
3682
|
var appendQuery = (url, params) => {
|
|
3678
3683
|
if (!params) return url;
|
|
@@ -5481,6 +5486,22 @@ function useChangeRecords(options) {
|
|
|
5481
5486
|
|
|
5482
5487
|
// src/hooks/useFormNavigation.ts
|
|
5483
5488
|
import { useState as useState24, useCallback as useCallback11, useRef as useRef11, useEffect as useEffect31 } from "react";
|
|
5489
|
+
var normalizeBasePath = (basePath) => {
|
|
5490
|
+
const normalized = String(basePath || "").replace(/^\/+|\/+$/g, "");
|
|
5491
|
+
return normalized ? `/${normalized}` : "";
|
|
5492
|
+
};
|
|
5493
|
+
var inferBasePath = (appType) => {
|
|
5494
|
+
if (typeof window === "undefined") return "";
|
|
5495
|
+
const pathname = window.location?.pathname || "";
|
|
5496
|
+
const marker = `/${appType}/`;
|
|
5497
|
+
const markerIndex = pathname.indexOf(marker);
|
|
5498
|
+
if (markerIndex <= 0) return "";
|
|
5499
|
+
return pathname.slice(0, markerIndex);
|
|
5500
|
+
};
|
|
5501
|
+
var buildDetailUrl = (appType, formUuid, formInstId, detailType, basePath) => {
|
|
5502
|
+
const prefix = normalizeBasePath(basePath ?? inferBasePath(appType));
|
|
5503
|
+
return `${prefix}/${appType}/${detailType}/${formUuid}?formInstId=${encodeURIComponent(formInstId)}`;
|
|
5504
|
+
};
|
|
5484
5505
|
function useFormNavigation(options) {
|
|
5485
5506
|
const {
|
|
5486
5507
|
appType,
|
|
@@ -5488,6 +5509,7 @@ function useFormNavigation(options) {
|
|
|
5488
5509
|
formType = "form",
|
|
5489
5510
|
mode = "redirect",
|
|
5490
5511
|
redirectDelay = 3e3,
|
|
5512
|
+
basePath,
|
|
5491
5513
|
onStay
|
|
5492
5514
|
} = options;
|
|
5493
5515
|
const [isRedirecting, setIsRedirecting] = useState24(false);
|
|
@@ -5507,15 +5529,21 @@ function useFormNavigation(options) {
|
|
|
5507
5529
|
}, []);
|
|
5508
5530
|
const navigateToDetail = useCallback11(
|
|
5509
5531
|
(formInstId) => {
|
|
5510
|
-
window.location.href =
|
|
5532
|
+
window.location.href = buildDetailUrl(appType, formUuid, formInstId, "formDetail", basePath);
|
|
5511
5533
|
},
|
|
5512
|
-
[appType, formUuid]
|
|
5534
|
+
[appType, basePath, formUuid]
|
|
5513
5535
|
);
|
|
5514
5536
|
const navigateToProcessDetail = useCallback11(
|
|
5515
5537
|
(formInstId) => {
|
|
5516
|
-
window.location.href =
|
|
5538
|
+
window.location.href = buildDetailUrl(
|
|
5539
|
+
appType,
|
|
5540
|
+
formUuid,
|
|
5541
|
+
formInstId,
|
|
5542
|
+
"processDetail",
|
|
5543
|
+
basePath
|
|
5544
|
+
);
|
|
5517
5545
|
},
|
|
5518
|
-
[appType, formUuid]
|
|
5546
|
+
[appType, basePath, formUuid]
|
|
5519
5547
|
);
|
|
5520
5548
|
const startRedirectCountdown = useCallback11(
|
|
5521
5549
|
(targetUrl) => {
|
|
@@ -5569,10 +5597,16 @@ function useFormNavigation(options) {
|
|
|
5569
5597
|
onStay?.(formInstId);
|
|
5570
5598
|
return;
|
|
5571
5599
|
}
|
|
5572
|
-
const targetUrl =
|
|
5600
|
+
const targetUrl = buildDetailUrl(
|
|
5601
|
+
appType,
|
|
5602
|
+
formUuid,
|
|
5603
|
+
formInstId,
|
|
5604
|
+
formType === "process" ? "processDetail" : "formDetail",
|
|
5605
|
+
basePath
|
|
5606
|
+
);
|
|
5573
5607
|
startRedirectCountdown(targetUrl);
|
|
5574
5608
|
},
|
|
5575
|
-
[mode, formType, appType, formUuid, onStay, startRedirectCountdown]
|
|
5609
|
+
[mode, formType, appType, formUuid, basePath, onStay, startRedirectCountdown]
|
|
5576
5610
|
);
|
|
5577
5611
|
return {
|
|
5578
5612
|
navigateToDetail,
|
|
@@ -6250,6 +6284,12 @@ import { useState as useState29, useCallback as useCallback13 } from "react";
|
|
|
6250
6284
|
import { Button as Button9 } from "antd";
|
|
6251
6285
|
import { CheckCircleFilled } from "@ant-design/icons";
|
|
6252
6286
|
import { Fragment as Fragment5, jsx as jsx82, jsxs as jsxs28 } from "react/jsx-runtime";
|
|
6287
|
+
var pickFormInstanceId = (value) => {
|
|
6288
|
+
if (!value) return void 0;
|
|
6289
|
+
if (typeof value === "string") return value;
|
|
6290
|
+
if (typeof value !== "object") return void 0;
|
|
6291
|
+
return value.formInstanceId || value.formInstId || value.instanceId || value.id || pickFormInstanceId(value.result) || pickFormInstanceId(value.data);
|
|
6292
|
+
};
|
|
6253
6293
|
var SubmitSuccessCard = ({
|
|
6254
6294
|
info,
|
|
6255
6295
|
mode,
|
|
@@ -6299,7 +6339,7 @@ var InnerFormContent = ({
|
|
|
6299
6339
|
renderSuccess,
|
|
6300
6340
|
onSubmitSuccess
|
|
6301
6341
|
}) => {
|
|
6302
|
-
const { validateAll, getFormData: getFormData2, resetForm } = useFormContext();
|
|
6342
|
+
const { validateAll, getFormData: getFormData2, resetForm, api } = useFormContext();
|
|
6303
6343
|
const [submitted, setSubmitted] = useState29(false);
|
|
6304
6344
|
const [successInfo, setSuccessInfo] = useState29(null);
|
|
6305
6345
|
const [submitting, setSubmitting] = useState29(false);
|
|
@@ -6311,7 +6351,8 @@ var InnerFormContent = ({
|
|
|
6311
6351
|
appType: config.appType,
|
|
6312
6352
|
formUuid: config.formUuid,
|
|
6313
6353
|
formType,
|
|
6314
|
-
mode: submitSuccessMode === "continue" ? "stay" : submitSuccessMode
|
|
6354
|
+
mode: submitSuccessMode === "continue" ? "stay" : submitSuccessMode,
|
|
6355
|
+
basePath: config.navigation?.basePath
|
|
6315
6356
|
});
|
|
6316
6357
|
const handleSubmit = useCallback13(async () => {
|
|
6317
6358
|
const valid = await validateAll();
|
|
@@ -6326,9 +6367,24 @@ var InnerFormContent = ({
|
|
|
6326
6367
|
return;
|
|
6327
6368
|
}
|
|
6328
6369
|
}
|
|
6329
|
-
const
|
|
6370
|
+
const submitResponse = config.mode === "edit" && config.formInstanceId ? await api.updateFormData({
|
|
6371
|
+
appType: config.appType,
|
|
6372
|
+
formUuid: config.formUuid,
|
|
6373
|
+
formInstId: config.formInstanceId,
|
|
6374
|
+
formInstanceId: config.formInstanceId,
|
|
6375
|
+
updateFormDataJson: JSON.stringify(formData)
|
|
6376
|
+
}) : await api.submitFormData({
|
|
6377
|
+
appType: config.appType,
|
|
6378
|
+
formUuid: config.formUuid,
|
|
6379
|
+
data: formData
|
|
6380
|
+
});
|
|
6381
|
+
const formInstId = pickFormInstanceId(submitResponse) || config.formInstanceId || `inst_${Date.now()}`;
|
|
6330
6382
|
if (config.submit?.afterSubmit) {
|
|
6331
|
-
await config.submit.afterSubmit({
|
|
6383
|
+
await config.submit.afterSubmit({
|
|
6384
|
+
formInstanceId: formInstId,
|
|
6385
|
+
data: formData,
|
|
6386
|
+
response: submitResponse
|
|
6387
|
+
});
|
|
6332
6388
|
}
|
|
6333
6389
|
if (enableDraft) {
|
|
6334
6390
|
clearDraft();
|
|
@@ -6350,6 +6406,7 @@ var InnerFormContent = ({
|
|
|
6350
6406
|
validateAll,
|
|
6351
6407
|
getFormData2,
|
|
6352
6408
|
config,
|
|
6409
|
+
api,
|
|
6353
6410
|
enableDraft,
|
|
6354
6411
|
clearDraft,
|
|
6355
6412
|
onSubmitSuccess,
|