react-antd-xform 1.0.0
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/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/_virtual/_commonjsHelpers.js +8 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/_virtual/index2.js +4 -0
- package/dist/_virtual/jsx-runtime.js +4 -0
- package/dist/_virtual/react-jsx-runtime.development.js +4 -0
- package/dist/_virtual/react-jsx-runtime.production.min.js +4 -0
- package/dist/_virtual/use-sync-external-store-shim.development.js +4 -0
- package/dist/_virtual/use-sync-external-store-shim.production.js +4 -0
- package/dist/form/array-helper.d.ts +12 -0
- package/dist/form/array-helper.js +115 -0
- package/dist/form/common-utils.d.ts +12 -0
- package/dist/form/common-utils.js +90 -0
- package/dist/form/context/formEnvContext.d.ts +6 -0
- package/dist/form/context/formEnvContext.js +23 -0
- package/dist/form/context/modelContext.d.ts +4 -0
- package/dist/form/context/modelContext.js +11 -0
- package/dist/form/enum.d.ts +9 -0
- package/dist/form/enum.js +15 -0
- package/dist/form/form-item.d.ts +15 -0
- package/dist/form/form-item.js +286 -0
- package/dist/form/index.d.ts +22 -0
- package/dist/form/index.js +73 -0
- package/dist/form/layout.d.ts +4 -0
- package/dist/form/layout.js +180 -0
- package/dist/form/model-utils.d.ts +23 -0
- package/dist/form/model-utils.js +171 -0
- package/dist/form/model.d.ts +103 -0
- package/dist/form/model.js +504 -0
- package/dist/form/type.d.ts +289 -0
- package/dist/form-ui/common-utils.d.ts +9 -0
- package/dist/form-ui/common-utils.js +17 -0
- package/dist/form-ui/default-button.d.ts +3 -0
- package/dist/form-ui/default-button.js +39 -0
- package/dist/form-ui/default-component.d.ts +2 -0
- package/dist/form-ui/default-component.js +63 -0
- package/dist/form-ui/type.d.ts +2 -0
- package/dist/helpers/AsyncValue.d.ts +38 -0
- package/dist/helpers/AsyncValue.js +154 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +20 -0
- package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +63 -0
- package/dist/node_modules/.pnpm/get-own-enumerable-keys@1.0.0/node_modules/get-own-enumerable-keys/index.js +10 -0
- package/dist/node_modules/.pnpm/invariant@2.2.4/node_modules/invariant/browser.js +32 -0
- package/dist/node_modules/.pnpm/is-obj@3.0.0/node_modules/is-obj/index.js +7 -0
- package/dist/node_modules/.pnpm/is-regexp@3.1.0/node_modules/is-regexp/index.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Hash.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_ListCache.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Map.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_MapCache.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_apply.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayMap.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayPush.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignValue.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseAssignValue.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFlatten.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGet.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseHasIn.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsArguments.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePick.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePickBy.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSet.js +33 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSetToString.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseToString.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_castPath.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_coreJsData.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_defineProperty.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_flatRest.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +6 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getMapData.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getNative.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getValue.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hasPath.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashClear.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashDelete.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashGet.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashHas.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashSet.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isFlattenable.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIndex.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKey.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKeyable.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_memoizeCapped.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overRest.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_setToString.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_shortOut.js +21 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stringToPath.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toKey.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toSource.js +19 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/constant.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/eq.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/flatten.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/hasIn.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/identity.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArguments.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArray.js +5 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isFunction.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isLength.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isSymbol.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/memoize.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/pick.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toString.js +9 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/ObserverComponent.js +5 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/index.js +18 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/observer.js +84 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/useObserver.js +72 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/UniversalFinalizationRegistry.js +96 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/assertEnvironment.js +8 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/observerBatching.js +17 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/observerFinalizationRegistry.js +9 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/printDebugValue.js +7 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.js +890 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.js +33 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js +12 -0
- package/dist/node_modules/.pnpm/stringify-object@5.0.0/node_modules/stringify-object/index.js +94 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@18.3.1/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +77 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@18.3.1/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +62 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@18.3.1/node_modules/use-sync-external-store/shim/index.js +12 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +58 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { action, runInAction, observable, toJS } from "mobx";
|
|
2
|
+
import { FieldType } from "./enum.js";
|
|
3
|
+
import { observableSetIn } from "./common-utils.js";
|
|
4
|
+
const modelUtils = {
|
|
5
|
+
clearError: action(function(model) {
|
|
6
|
+
model.iterateFields((field) => {
|
|
7
|
+
field.state.error = null;
|
|
8
|
+
});
|
|
9
|
+
model.iterateChecks((check) => {
|
|
10
|
+
check.error = null;
|
|
11
|
+
});
|
|
12
|
+
}),
|
|
13
|
+
scrollToFirstError(errorFields) {
|
|
14
|
+
var _a;
|
|
15
|
+
for (const field of errorFields) {
|
|
16
|
+
if (!((_a = field.config) == null ? void 0 : _a.htmlId)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const div = document.querySelector(
|
|
20
|
+
`*[data-xform-id="${field.config.htmlId}"]`
|
|
21
|
+
);
|
|
22
|
+
if (!div) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (typeof div.scrollIntoViewIfNeeded === "function") {
|
|
26
|
+
div.scrollIntoViewIfNeeded();
|
|
27
|
+
} else {
|
|
28
|
+
div.scrollIntoView({ block: "nearest" });
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
animateErrorFields(errorFields) {
|
|
34
|
+
var _a;
|
|
35
|
+
for (const field of errorFields) {
|
|
36
|
+
if (!((_a = field.config) == null ? void 0 : _a.htmlId)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const div = document.querySelector(
|
|
40
|
+
`*[data-xform-id="${field.config.htmlId}"]`
|
|
41
|
+
);
|
|
42
|
+
if (!div) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
div.animate(
|
|
46
|
+
[
|
|
47
|
+
{ offset: 0, transform: "translateX(0)" },
|
|
48
|
+
{ offset: 0.065, transform: "translateX(-6px) rotateY(-9deg)" },
|
|
49
|
+
{ offset: 0.185, transform: "translateX(5px) rotateY(7deg)" },
|
|
50
|
+
{ offset: 0.315, transform: "translateX(-3px) rotateY(-5deg)" },
|
|
51
|
+
{ offset: 0.435, transform: "translateX(2px) rotateY(3deg)" },
|
|
52
|
+
{ offset: 0.5, transform: "translateX(0)" }
|
|
53
|
+
],
|
|
54
|
+
{ duration: 750 }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
validateAll: action(function(model, trigger = "*") {
|
|
59
|
+
let hasError = false;
|
|
60
|
+
const errors = observable(model._valueShape === "array" ? [] : {});
|
|
61
|
+
const errorFields = [];
|
|
62
|
+
const promises = [];
|
|
63
|
+
model.iterateFields((field) => {
|
|
64
|
+
if (!field.isMounted) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
promises.push(
|
|
68
|
+
field.validate(trigger).then(
|
|
69
|
+
action((error) => {
|
|
70
|
+
if (error) {
|
|
71
|
+
hasError = true;
|
|
72
|
+
observableSetIn(errors, field.path, error);
|
|
73
|
+
errorFields.push(field);
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
model.iterateChecks((check) => {
|
|
80
|
+
promises.push(
|
|
81
|
+
check.validate().then(
|
|
82
|
+
action((error) => {
|
|
83
|
+
if (error) {
|
|
84
|
+
hasError = true;
|
|
85
|
+
observableSetIn(errors, check.path, error);
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
return Promise.all(promises).then(() => ({
|
|
92
|
+
hasError,
|
|
93
|
+
errors: toJS(errors),
|
|
94
|
+
errorFields
|
|
95
|
+
}));
|
|
96
|
+
}),
|
|
97
|
+
submit: action(async function(model, options = {}) {
|
|
98
|
+
const {
|
|
99
|
+
onError,
|
|
100
|
+
onSubmit,
|
|
101
|
+
valueFilter = "mounted",
|
|
102
|
+
mergeDefaultValue = true,
|
|
103
|
+
animateErrorFields = false,
|
|
104
|
+
scrollToFirstError = true
|
|
105
|
+
} = options;
|
|
106
|
+
const { hasError, errors, errorFields } = await modelUtils.validateAll(model);
|
|
107
|
+
if (hasError) {
|
|
108
|
+
if (scrollToFirstError) {
|
|
109
|
+
modelUtils.scrollToFirstError(errorFields);
|
|
110
|
+
}
|
|
111
|
+
if (animateErrorFields) {
|
|
112
|
+
modelUtils.animateErrorFields(errorFields);
|
|
113
|
+
}
|
|
114
|
+
onError == null ? void 0 : onError(errors, model);
|
|
115
|
+
} else if (typeof onSubmit === "function") {
|
|
116
|
+
runInAction(() => {
|
|
117
|
+
const result = observable(
|
|
118
|
+
valueFilter === "all" ? toJS(model.values) : model._valueShape === "array" ? [] : {}
|
|
119
|
+
);
|
|
120
|
+
_mergeValuesFromViewToTarget(result, model, { mergeDefaultValue });
|
|
121
|
+
onSubmit(toJS(result), model);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
reset: action(function(model, { onReset } = {}) {
|
|
126
|
+
model.values = {};
|
|
127
|
+
modelUtils.clearError(model);
|
|
128
|
+
onReset == null ? void 0 : onReset(model);
|
|
129
|
+
}),
|
|
130
|
+
acceptValuesFormView: action((model, opts = {}) => {
|
|
131
|
+
_mergeValuesFromViewToTarget(model.values, model, opts);
|
|
132
|
+
}),
|
|
133
|
+
mergeValuesFromViewToView: _mergeValuesFromViewToTarget
|
|
134
|
+
};
|
|
135
|
+
function _mergeValuesFromViewToTarget(target, model, { mergeDefaultValue = true } = {}) {
|
|
136
|
+
model.iterateFields((field) => {
|
|
137
|
+
if (!field.isMounted) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (field.fieldType === FieldType.normal) {
|
|
141
|
+
if (field.config.valueProp !== void 0) {
|
|
142
|
+
observableSetIn(target, field.path, field.config.valueProp);
|
|
143
|
+
} else if (field.value !== void 0) {
|
|
144
|
+
observableSetIn(target, field.path, field.value);
|
|
145
|
+
} else {
|
|
146
|
+
const defaultValueProp = field.config.defaultValueProp;
|
|
147
|
+
if (mergeDefaultValue && defaultValueProp !== void 0) {
|
|
148
|
+
observableSetIn(target, field.path, defaultValueProp);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} else if (field.fieldType === FieldType.tuple) {
|
|
152
|
+
const model2 = field.parent;
|
|
153
|
+
const hasValue = field.value.some((v) => v !== void 0);
|
|
154
|
+
if (hasValue) {
|
|
155
|
+
field._tupleParts.map((part, index) => {
|
|
156
|
+
observableSetIn(target, [...model2.path, part], field.value[index]);
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
const defaultValueProp = field.config.defaultValueProp;
|
|
160
|
+
if (mergeDefaultValue && defaultValueProp !== void 0) {
|
|
161
|
+
field._tupleParts.map((part, index) => {
|
|
162
|
+
observableSetIn(target, [...model2.path, part], defaultValueProp == null ? void 0 : defaultValueProp[index]);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
export {
|
|
170
|
+
modelUtils
|
|
171
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ModelType, FieldType } from './enum';
|
|
2
|
+
import { XName, ResolveXName, ValueShape, FieldConfig, CheckConfig, FieldState, FieldCreateOptions, FieldValidateTrigger, FormModelCreateOptions } from './type';
|
|
3
|
+
declare class IdGenerator {
|
|
4
|
+
private _nextId;
|
|
5
|
+
private prefix;
|
|
6
|
+
constructor(prefix: string);
|
|
7
|
+
getNextId(): string;
|
|
8
|
+
}
|
|
9
|
+
export declare class FormModel<D extends {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
} = unknown> implements FormModel<D> {
|
|
12
|
+
_modelIdGenerator: IdGenerator;
|
|
13
|
+
_fieldIdGenerator: IdGenerator;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
state: any;
|
|
16
|
+
readonly root: FormModel<any>;
|
|
17
|
+
readonly parent: FormModel<any>;
|
|
18
|
+
name: string;
|
|
19
|
+
/** 当前 Model 的类型,目前只有两种类型: rootModel 和 subModel */
|
|
20
|
+
_modelType: ModelType;
|
|
21
|
+
_values: D;
|
|
22
|
+
_fieldMap: Map<string, Field<unknown>>;
|
|
23
|
+
_valueShape: 'auto' | ValueShape;
|
|
24
|
+
_subModels: D extends any[] ? FormModel[] : {
|
|
25
|
+
[key: string]: FormModel;
|
|
26
|
+
};
|
|
27
|
+
_checkMap: Map<string, Check<D>>;
|
|
28
|
+
/**
|
|
29
|
+
* 标记当前 model 是否已经删除.
|
|
30
|
+
* 当某个对象从数组中移除时,该对象对应的 model 就被会标记为 _selfDeleted=true
|
|
31
|
+
* */
|
|
32
|
+
_selfDeleted: boolean;
|
|
33
|
+
get values(): D;
|
|
34
|
+
set values(nextValues: D);
|
|
35
|
+
get path(): string[];
|
|
36
|
+
constructor(initValues?: D, options?: FormModelCreateOptions);
|
|
37
|
+
getValue<N extends XName<D>>(name: N, defaultValue?: ResolveXName<D, N>): ResolveXName<D, N>;
|
|
38
|
+
setValue<N extends XName<D>>(name: N, value: ResolveXName<D, N>): void;
|
|
39
|
+
getSubModel<N extends XName<D>>(name: N | string[]): FormModel<ResolveXName<D, N>>;
|
|
40
|
+
getField<N extends XName<D>>(name: N | string[]): Field<ResolveXName<D, N>>;
|
|
41
|
+
getTupleField<NS extends (keyof D & string)[]>(...tupleParts: NS): Field<{
|
|
42
|
+
[Index in keyof NS]: NS[Index] extends keyof D ? D[NS[Index]] : never;
|
|
43
|
+
}>;
|
|
44
|
+
_asField(): Field<D>;
|
|
45
|
+
_updateValueShape(valueShape: 'array' | 'object'): void;
|
|
46
|
+
/** 递归前序遍历该 model 下所有的 model 对象(包含 model 本身) */
|
|
47
|
+
iterateModels(iteratee: (mod: FormModel) => void): void;
|
|
48
|
+
/** 递归遍历该 model 下(包括 model 本身)所有存在的 field 对象(包括 normal field 和 tuple field,也包括所有 fork) */
|
|
49
|
+
iterateFields(iteratee: (field: Field) => void): void;
|
|
50
|
+
/** 递归遍历该 model 下(包括 model 本身)所有存在的 check 对象) */
|
|
51
|
+
iterateChecks(iteratee: (check: Check) => void): void;
|
|
52
|
+
_getSubModelByShortName(name: string): FormModel<any>;
|
|
53
|
+
getCheck(name: string): Check<D>;
|
|
54
|
+
/** 判断当前 model 是否已经删除 */
|
|
55
|
+
get isDeleted(): boolean;
|
|
56
|
+
_markDeleted(): void;
|
|
57
|
+
}
|
|
58
|
+
export declare class Check<D = unknown> {
|
|
59
|
+
/** Check 是否在视图中被渲染 */
|
|
60
|
+
isMounted: boolean;
|
|
61
|
+
/** Check 配置的最新缓存(注意不要修改该值)*/
|
|
62
|
+
config?: CheckConfig<D>;
|
|
63
|
+
readonly parent: FormModel<D>;
|
|
64
|
+
readonly name: string;
|
|
65
|
+
error: any;
|
|
66
|
+
cancelValidation: () => void;
|
|
67
|
+
validating: boolean;
|
|
68
|
+
get path(): string[];
|
|
69
|
+
constructor(parent: FormModel<D>, name: string);
|
|
70
|
+
_track(config: CheckConfig<D>): () => void;
|
|
71
|
+
validate(): Promise<any>;
|
|
72
|
+
}
|
|
73
|
+
export declare class Field<V = unknown> {
|
|
74
|
+
static ORIGINAL: string;
|
|
75
|
+
static getHtmlId(prefix: string, field: Field): string;
|
|
76
|
+
/** 字段配置的最新缓存(注意不要修改该值)*/
|
|
77
|
+
config?: FieldConfig<V>;
|
|
78
|
+
/** 字段是否在视图中被渲染 */
|
|
79
|
+
isMounted: boolean;
|
|
80
|
+
readonly parent: FormModel<any>;
|
|
81
|
+
readonly name: string;
|
|
82
|
+
readonly _forkName: string;
|
|
83
|
+
readonly _tupleParts: string[];
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly _forkMap: Map<string, Field>;
|
|
86
|
+
readonly fieldType: FieldType;
|
|
87
|
+
readonly _readonlyValue: any;
|
|
88
|
+
state: FieldState;
|
|
89
|
+
get value(): V;
|
|
90
|
+
set value(value: V);
|
|
91
|
+
get path(): string[];
|
|
92
|
+
constructor(opts: FieldCreateOptions);
|
|
93
|
+
_track(config: FieldConfig<V>): () => void;
|
|
94
|
+
getFork(forkName: string): Field<V>;
|
|
95
|
+
validate(trigger?: FieldValidateTrigger): Promise<any>;
|
|
96
|
+
handleFocus: () => void;
|
|
97
|
+
handleBlur: () => Promise<any>;
|
|
98
|
+
handleChange: (nextValue: any, ...rest: any[]) => Promise<any>;
|
|
99
|
+
get isDeleted(): boolean;
|
|
100
|
+
/** 清理字段,将清空字段的错误与值 */
|
|
101
|
+
clear: () => void;
|
|
102
|
+
}
|
|
103
|
+
export {};
|