sy-form-components 0.2.2 → 0.2.3
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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +81 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4945,6 +4945,75 @@ function useFieldPermission(options) {
|
|
|
4945
4945
|
|
|
4946
4946
|
// src/hooks/useFormDetail.ts
|
|
4947
4947
|
import { useState as useState20, useEffect as useEffect27, useCallback as useCallback7, useRef as useRef7 } from "react";
|
|
4948
|
+
|
|
4949
|
+
// src/utils/formInstanceData.ts
|
|
4950
|
+
var FORM_INSTANCE_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
4951
|
+
"appType",
|
|
4952
|
+
"code",
|
|
4953
|
+
"createdAt",
|
|
4954
|
+
"createdBy",
|
|
4955
|
+
"createdByDepartmentId",
|
|
4956
|
+
"createdByDepartmentName",
|
|
4957
|
+
"createdByName",
|
|
4958
|
+
"creator",
|
|
4959
|
+
"data",
|
|
4960
|
+
"error",
|
|
4961
|
+
"formInstId",
|
|
4962
|
+
"formInstanceId",
|
|
4963
|
+
"formUuid",
|
|
4964
|
+
"instanceTitle",
|
|
4965
|
+
"message",
|
|
4966
|
+
"result",
|
|
4967
|
+
"success",
|
|
4968
|
+
"title",
|
|
4969
|
+
"updatedAt"
|
|
4970
|
+
]);
|
|
4971
|
+
var isPlainRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4972
|
+
var parseJsonRecord = (value) => {
|
|
4973
|
+
if (typeof value !== "string" || value.trim() === "") return null;
|
|
4974
|
+
try {
|
|
4975
|
+
const parsed = JSON.parse(value);
|
|
4976
|
+
return isPlainRecord(parsed) ? parsed : null;
|
|
4977
|
+
} catch {
|
|
4978
|
+
return null;
|
|
4979
|
+
}
|
|
4980
|
+
};
|
|
4981
|
+
var pickKnownFields = (source, fieldIds) => {
|
|
4982
|
+
if (fieldIds?.length) {
|
|
4983
|
+
const values = {};
|
|
4984
|
+
for (const fieldId of fieldIds) {
|
|
4985
|
+
if (Object.prototype.hasOwnProperty.call(source, fieldId)) {
|
|
4986
|
+
values[fieldId] = source[fieldId];
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
return values;
|
|
4990
|
+
}
|
|
4991
|
+
return Object.fromEntries(
|
|
4992
|
+
Object.entries(source).filter(([key]) => !FORM_INSTANCE_METADATA_KEYS.has(key))
|
|
4993
|
+
);
|
|
4994
|
+
};
|
|
4995
|
+
var extractFormValues = (formInstance, fieldIds) => {
|
|
4996
|
+
if (!isPlainRecord(formInstance)) return null;
|
|
4997
|
+
const nestedCandidates = [
|
|
4998
|
+
formInstance.data,
|
|
4999
|
+
parseJsonRecord(formInstance.data),
|
|
5000
|
+
formInstance.formData,
|
|
5001
|
+
parseJsonRecord(formInstance.formData),
|
|
5002
|
+
formInstance.values,
|
|
5003
|
+
formInstance.fieldValues,
|
|
5004
|
+
parseJsonRecord(formInstance.formDataJson),
|
|
5005
|
+
parseJsonRecord(formInstance.dataJson)
|
|
5006
|
+
];
|
|
5007
|
+
for (const candidate of nestedCandidates) {
|
|
5008
|
+
if (isPlainRecord(candidate)) {
|
|
5009
|
+
return pickKnownFields(candidate, fieldIds);
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
5012
|
+
const flatValues = pickKnownFields(formInstance, fieldIds);
|
|
5013
|
+
return Object.keys(flatValues).length > 0 ? flatValues : null;
|
|
5014
|
+
};
|
|
5015
|
+
|
|
5016
|
+
// src/hooks/useFormDetail.ts
|
|
4948
5017
|
function buildFieldBehaviors(permissions, mode) {
|
|
4949
5018
|
const behaviors = {};
|
|
4950
5019
|
if (!permissions) return behaviors;
|
|
@@ -4960,7 +5029,7 @@ function buildFieldBehaviors(permissions, mode) {
|
|
|
4960
5029
|
return behaviors;
|
|
4961
5030
|
}
|
|
4962
5031
|
function useFormDetail(options) {
|
|
4963
|
-
const { formUuid, appType, formInstanceId, onPermissionDenied } = options;
|
|
5032
|
+
const { formUuid, appType, formInstanceId, fieldIds, onPermissionDenied } = options;
|
|
4964
5033
|
const { api } = useFormContext();
|
|
4965
5034
|
const request = api.request;
|
|
4966
5035
|
const [loading, setLoading] = useState20(true);
|
|
@@ -4989,7 +5058,7 @@ function useFormDetail(options) {
|
|
|
4989
5058
|
}
|
|
4990
5059
|
setPermissions(permResult);
|
|
4991
5060
|
setInstanceInfo(formResult);
|
|
4992
|
-
setFormData(formResult
|
|
5061
|
+
setFormData(extractFormValues(formResult, fieldIds));
|
|
4993
5062
|
} catch (error) {
|
|
4994
5063
|
console.error("[useFormDetail] Failed to load data:", error);
|
|
4995
5064
|
if (mountedRef.current) {
|
|
@@ -5002,7 +5071,7 @@ function useFormDetail(options) {
|
|
|
5002
5071
|
setLoading(false);
|
|
5003
5072
|
}
|
|
5004
5073
|
}
|
|
5005
|
-
}, [request, formUuid, appType, formInstanceId, onPermissionDenied]);
|
|
5074
|
+
}, [request, formUuid, appType, formInstanceId, fieldIds, onPermissionDenied]);
|
|
5006
5075
|
useEffect27(() => {
|
|
5007
5076
|
loadData();
|
|
5008
5077
|
}, [loadData]);
|
|
@@ -5067,7 +5136,7 @@ function useFormDetail(options) {
|
|
|
5067
5136
|
// src/hooks/useProcessDetail.ts
|
|
5068
5137
|
import { useState as useState21, useEffect as useEffect28, useCallback as useCallback8, useRef as useRef8 } from "react";
|
|
5069
5138
|
function useProcessDetail(options) {
|
|
5070
|
-
const { formUuid, appType, formInstanceId } = options;
|
|
5139
|
+
const { formUuid, appType, formInstanceId, fieldIds } = options;
|
|
5071
5140
|
const { api } = useFormContext();
|
|
5072
5141
|
const request = api.request;
|
|
5073
5142
|
const [loading, setLoading] = useState21(true);
|
|
@@ -5115,7 +5184,7 @@ function useProcessDetail(options) {
|
|
|
5115
5184
|
setCanWithdraw(approvalResult?.canUndo ?? false);
|
|
5116
5185
|
setPermissions(permResult);
|
|
5117
5186
|
setInstanceInfo(formResult);
|
|
5118
|
-
setFormData(formResult
|
|
5187
|
+
setFormData(extractFormValues(formResult, fieldIds));
|
|
5119
5188
|
if (permResult?.operations?.includes("VIEW_PROCESS") || permResult?.operations?.length > 0) {
|
|
5120
5189
|
try {
|
|
5121
5190
|
const progress = await getProcessProgress(request, formInstanceId);
|
|
@@ -5149,7 +5218,7 @@ function useProcessDetail(options) {
|
|
|
5149
5218
|
setLoading(false);
|
|
5150
5219
|
}
|
|
5151
5220
|
}
|
|
5152
|
-
}, [request, formUuid, appType, formInstanceId]);
|
|
5221
|
+
}, [request, formUuid, appType, formInstanceId, fieldIds]);
|
|
5153
5222
|
useEffect28(() => {
|
|
5154
5223
|
loadData();
|
|
5155
5224
|
}, [loadData]);
|
|
@@ -6526,7 +6595,7 @@ var FormSubmitTemplate = ({
|
|
|
6526
6595
|
};
|
|
6527
6596
|
|
|
6528
6597
|
// src/templates/FormDetailTemplate.tsx
|
|
6529
|
-
import { useCallback as useCallback14 } from "react";
|
|
6598
|
+
import { useCallback as useCallback14, useMemo as useMemo8 } from "react";
|
|
6530
6599
|
|
|
6531
6600
|
// src/templates/PageSkeleton.tsx
|
|
6532
6601
|
import { Skeleton as Skeleton3 } from "antd";
|
|
@@ -6606,6 +6675,7 @@ var InnerDetailContent = ({
|
|
|
6606
6675
|
onDelete,
|
|
6607
6676
|
onSave
|
|
6608
6677
|
}) => {
|
|
6678
|
+
const fieldIds = useMemo8(() => schema.fields.map((field) => field.fieldId), [schema.fields]);
|
|
6609
6679
|
const {
|
|
6610
6680
|
loading,
|
|
6611
6681
|
mode,
|
|
@@ -6619,7 +6689,7 @@ var InnerDetailContent = ({
|
|
|
6619
6689
|
canEdit,
|
|
6620
6690
|
canDelete,
|
|
6621
6691
|
canViewChangeRecords
|
|
6622
|
-
} = useFormDetail({ formUuid, appType, formInstanceId });
|
|
6692
|
+
} = useFormDetail({ formUuid, appType, formInstanceId, fieldIds });
|
|
6623
6693
|
const {
|
|
6624
6694
|
records,
|
|
6625
6695
|
loading: recordsLoading,
|
|
@@ -6730,7 +6800,7 @@ var FormDetailTemplate = (props) => {
|
|
|
6730
6800
|
};
|
|
6731
6801
|
|
|
6732
6802
|
// src/templates/ProcessDetailTemplate.tsx
|
|
6733
|
-
import { useCallback as useCallback15, useRef as useRef12 } from "react";
|
|
6803
|
+
import { useCallback as useCallback15, useMemo as useMemo9, useRef as useRef12 } from "react";
|
|
6734
6804
|
import { Fragment as Fragment7, jsx as jsx85, jsxs as jsxs31 } from "react/jsx-runtime";
|
|
6735
6805
|
function FormDataBridge({
|
|
6736
6806
|
formDataRef
|
|
@@ -6752,6 +6822,7 @@ var InnerProcessContent = ({
|
|
|
6752
6822
|
onActionComplete
|
|
6753
6823
|
}) => {
|
|
6754
6824
|
const formDataRef = useRef12(void 0);
|
|
6825
|
+
const fieldIds = useMemo9(() => schema.fields.map((field) => field.fieldId), [schema.fields]);
|
|
6755
6826
|
const {
|
|
6756
6827
|
loading,
|
|
6757
6828
|
processInfo,
|
|
@@ -6768,7 +6839,7 @@ var InnerProcessContent = ({
|
|
|
6768
6839
|
switchToEdit,
|
|
6769
6840
|
switchToReadonly,
|
|
6770
6841
|
refreshProgress
|
|
6771
|
-
} = useProcessDetail({ formUuid, appType, formInstanceId });
|
|
6842
|
+
} = useProcessDetail({ formUuid, appType, formInstanceId, fieldIds });
|
|
6772
6843
|
const { approve, reject, withdraw, save, resubmit } = useApprovalActions({
|
|
6773
6844
|
formInstanceId,
|
|
6774
6845
|
formUuid,
|
|
@@ -6967,6 +7038,7 @@ export {
|
|
|
6967
7038
|
defineFormSchema,
|
|
6968
7039
|
deleteFormData,
|
|
6969
7040
|
evaluateEffects,
|
|
7041
|
+
extractFormValues,
|
|
6970
7042
|
getChangeRecords,
|
|
6971
7043
|
getFormData,
|
|
6972
7044
|
getProcessBasic,
|