@plasmicpkgs/antd5 0.0.188 → 0.0.190
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/.tsbuildinfo +1 -1
- package/dist/antd.esm.js +5118 -4965
- package/dist/antd.esm.js.map +1 -1
- package/dist/form/Form.d.ts +72 -0
- package/dist/form/FormGroup.d.ts +6 -0
- package/dist/form/FormItem.d.ts +33 -0
- package/dist/form/FormList.d.ts +5 -0
- package/dist/form/SchemaForm.d.ts +9 -0
- package/dist/form/contexts.d.ts +40 -0
- package/dist/form/registerForm.d.ts +9 -0
- package/dist/form/registerFormGroup.d.ts +2 -0
- package/dist/form/registerFormItem.d.ts +2 -0
- package/dist/form/registerFormList.d.ts +2 -0
- package/dist/form/sharedRegistration.d.ts +14 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +5136 -4972
- package/dist/index.js.map +1 -1
- package/dist/names.d.ts +18 -0
- package/dist/registerButton.d.ts +1 -2
- package/dist/registerCheckbox.d.ts +0 -2
- package/dist/registerInput.d.ts +0 -4
- package/dist/registerRadio.d.ts +0 -3
- package/dist/registerSelect.d.ts +0 -3
- package/dist/registerSwitch.d.ts +0 -1
- package/package.json +5 -5
- package/skinny/Form.cjs.js +268 -0
- package/skinny/Form.cjs.js.map +1 -0
- package/skinny/Form.esm.js +256 -0
- package/skinny/Form.esm.js.map +1 -0
- package/skinny/FormGroup.cjs.js +26 -0
- package/skinny/FormGroup.cjs.js.map +1 -0
- package/skinny/FormGroup.esm.js +20 -0
- package/skinny/FormGroup.esm.js.map +1 -0
- package/skinny/FormItem.cjs.js +290 -0
- package/skinny/FormItem.cjs.js.map +1 -0
- package/skinny/FormItem.esm.js +284 -0
- package/skinny/FormItem.esm.js.map +1 -0
- package/skinny/FormList.cjs.js +98 -0
- package/skinny/FormList.cjs.js.map +1 -0
- package/skinny/FormList.esm.js +92 -0
- package/skinny/FormList.esm.js.map +1 -0
- package/skinny/SchemaForm.cjs.js +199 -0
- package/skinny/SchemaForm.cjs.js.map +1 -0
- package/skinny/SchemaForm.esm.js +191 -0
- package/skinny/SchemaForm.esm.js.map +1 -0
- package/skinny/contexts-4c7952c1.esm.js +20 -0
- package/skinny/contexts-4c7952c1.esm.js.map +1 -0
- package/skinny/contexts-a2387bed.cjs.js +31 -0
- package/skinny/contexts-a2387bed.cjs.js.map +1 -0
- package/skinny/names-3aea627b.cjs.js +34 -0
- package/skinny/names-3aea627b.cjs.js.map +1 -0
- package/skinny/names-73583568.esm.js +18 -0
- package/skinny/names-73583568.esm.js.map +1 -0
- package/skinny/names.d.ts +18 -0
- package/skinny/registerButton.cjs.js +3 -4
- package/skinny/registerButton.cjs.js.map +1 -1
- package/skinny/registerButton.d.ts +1 -2
- package/skinny/registerButton.esm.js +3 -3
- package/skinny/registerButton.esm.js.map +1 -1
- package/skinny/registerCheckbox.cjs.js +5 -8
- package/skinny/registerCheckbox.cjs.js.map +1 -1
- package/skinny/registerCheckbox.d.ts +0 -2
- package/skinny/registerCheckbox.esm.js +2 -3
- package/skinny/registerCheckbox.esm.js.map +1 -1
- package/skinny/registerForm.cjs.js +460 -1387
- package/skinny/registerForm.cjs.js.map +1 -1
- package/skinny/registerForm.esm.js +460 -1375
- package/skinny/registerForm.esm.js.map +1 -1
- package/skinny/registerInput.cjs.js +8 -15
- package/skinny/registerInput.cjs.js.map +1 -1
- package/skinny/registerInput.d.ts +0 -4
- package/skinny/registerInput.esm.js +2 -5
- package/skinny/registerInput.esm.js.map +1 -1
- package/skinny/registerRadio.cjs.js +6 -11
- package/skinny/registerRadio.cjs.js.map +1 -1
- package/skinny/registerRadio.d.ts +0 -3
- package/skinny/registerRadio.esm.js +2 -4
- package/skinny/registerRadio.esm.js.map +1 -1
- package/skinny/registerSelect.cjs.js +7 -12
- package/skinny/registerSelect.cjs.js.map +1 -1
- package/skinny/registerSelect.d.ts +0 -3
- package/skinny/registerSelect.esm.js +2 -4
- package/skinny/registerSelect.esm.js.map +1 -1
- package/skinny/registerSwitch.cjs.js +2 -3
- package/skinny/registerSwitch.cjs.js.map +1 -1
- package/skinny/registerSwitch.d.ts +0 -1
- package/skinny/registerSwitch.esm.js +2 -2
- package/skinny/registerSwitch.esm.js.map +1 -1
- package/skinny/registerUpload.cjs.js +10 -6
- package/skinny/registerUpload.cjs.js.map +1 -1
- package/skinny/registerUpload.esm.js +10 -6
- package/skinny/registerUpload.esm.js.map +1 -1
- package/dist/registerForm.d.ts +0 -143
- package/skinny/registerForm.d.ts +0 -143
package/dist/names.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const inputComponentName = "plasmic-antd5-input";
|
|
2
|
+
export declare const passwordComponentName = "plasmic-antd5-input-password";
|
|
3
|
+
export declare const inputNumberComponentName = "plasmic-antd5-input-number";
|
|
4
|
+
export declare const textAreaComponentName = "plasmic-antd5-textarea";
|
|
5
|
+
export declare const switchComponentName = "plasmic-antd5-switch";
|
|
6
|
+
export declare const selectComponentName = "plasmic-antd5-select";
|
|
7
|
+
export declare const optionComponentName = "plasmic-antd5-option";
|
|
8
|
+
export declare const optionGroupComponentName = "plasmic-antd5-option-group";
|
|
9
|
+
export declare const checkboxComponentName = "plasmic-antd5-checkbox";
|
|
10
|
+
export declare const checkboxGroupComponentName = "plasmic-antd5-checkbox-group";
|
|
11
|
+
export declare const radioComponentName = "plasmic-antd5-radio";
|
|
12
|
+
export declare const radioButtonComponentName = "plasmic-antd5-radio-button";
|
|
13
|
+
export declare const radioGroupComponentName = "plasmic-antd5-radio-group";
|
|
14
|
+
export declare const formListComponentName = "plasmic-antd5-form-list";
|
|
15
|
+
export declare const formComponentName = "plasmic-antd5-form";
|
|
16
|
+
export declare const formGroupComponentName = "plasmic-antd5-form-group";
|
|
17
|
+
export declare const formItemComponentName = "plasmic-antd5-form-item";
|
|
18
|
+
export declare const buttonComponentName = "plasmic-antd5-button";
|
package/dist/registerButton.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { Button } from "antd";
|
|
2
|
+
import React from "react";
|
|
3
3
|
import { Registerable } from "./utils";
|
|
4
4
|
export declare function AntdButton(props: Omit<React.ComponentProps<typeof Button>, "target"> & {
|
|
5
5
|
submitsForm?: boolean;
|
|
6
6
|
target?: React.ComponentProps<typeof Button>["target"] | boolean;
|
|
7
7
|
}): React.JSX.Element;
|
|
8
|
-
export declare const buttonComponentName = "plasmic-antd5-button";
|
|
9
8
|
export declare function registerButton(loader?: Registerable): void;
|
|
@@ -10,6 +10,4 @@ export declare namespace AntdCheckbox {
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
export declare const AntdCheckboxGroup: React.MemoExoticComponent<React.ForwardRefExoticComponent<import("antd/es/checkbox").CheckboxGroupProps & React.RefAttributes<HTMLDivElement>>>;
|
|
13
|
-
export declare const checkboxComponentName = "plasmic-antd5-checkbox";
|
|
14
|
-
export declare const checkboxGroupComponentName = "plasmic-antd5-checkbox-group";
|
|
15
13
|
export declare function registerCheckbox(loader?: Registerable): void;
|
package/dist/registerInput.d.ts
CHANGED
|
@@ -17,11 +17,7 @@ export declare const inputHelpers: {
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
export declare const inputComponentName = "plasmic-antd5-input";
|
|
21
20
|
export declare function registerInput(loader?: Registerable): void;
|
|
22
|
-
export declare const textAreaComponentName = "plasmic-antd5-textarea";
|
|
23
21
|
export declare function registerTextArea(loader?: Registerable): void;
|
|
24
|
-
export declare const passwordComponentName = "plasmic-antd5-input-password";
|
|
25
22
|
export declare function registerPasswordInput(loader?: Registerable): void;
|
|
26
|
-
export declare const inputNumberComponentName = "plasmic-antd5-input-number";
|
|
27
23
|
export declare function registerNumberInput(loader?: Registerable): void;
|
package/dist/registerRadio.d.ts
CHANGED
|
@@ -10,8 +10,5 @@ export declare function AntdRadioGroup(props: Omit<React.ComponentProps<typeof R
|
|
|
10
10
|
onChange?: (value?: string) => void;
|
|
11
11
|
useChildren?: boolean;
|
|
12
12
|
}): React.JSX.Element;
|
|
13
|
-
export declare const radioComponentName = "plasmic-antd5-radio";
|
|
14
|
-
export declare const radioButtonComponentName = "plasmic-antd5-radio-button";
|
|
15
|
-
export declare const radioGroupComponentName = "plasmic-antd5-radio-group";
|
|
16
13
|
export declare function registerRadio(loader?: Registerable): void;
|
|
17
14
|
export {};
|
package/dist/registerSelect.d.ts
CHANGED
|
@@ -9,7 +9,4 @@ export declare function AntdSelect(props: ComponentProps<typeof Select> & {
|
|
|
9
9
|
defaultStylesClassName?: string;
|
|
10
10
|
useChildren?: boolean;
|
|
11
11
|
}): React.JSX.Element;
|
|
12
|
-
export declare const selectComponentName = "plasmic-antd5-select";
|
|
13
|
-
export declare const optionComponentName = "plasmic-antd5-option";
|
|
14
|
-
export declare const optionGroupComponentName = "plasmic-antd5-option-group";
|
|
15
12
|
export declare function registerSelect(loader?: Registerable): void;
|
package/dist/registerSwitch.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/antd5",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.190",
|
|
4
4
|
"description": "Plasmic registration calls for antd components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"@babel/preset-env": "^7.22.15",
|
|
66
66
|
"@babel/preset-react": "^7.22.15",
|
|
67
67
|
"@babel/preset-typescript": "^7.22.15",
|
|
68
|
-
"@plasmicapp/data-sources": "0.1.
|
|
69
|
-
"@plasmicapp/host": "1.0.
|
|
68
|
+
"@plasmicapp/data-sources": "0.1.140",
|
|
69
|
+
"@plasmicapp/host": "1.0.182",
|
|
70
70
|
"@plasmicapp/query": "0.1.77",
|
|
71
|
-
"@plasmicapp/react-web": "0.2.
|
|
71
|
+
"@plasmicapp/react-web": "0.2.302",
|
|
72
72
|
"@rollup/plugin-commonjs": "^11.0.0",
|
|
73
73
|
"@rollup/plugin-json": "^4.0.0",
|
|
74
74
|
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "e0516f10c0a328e24f2f684b3e414184ea39915e"
|
|
112
112
|
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var antd = require('antd');
|
|
4
|
+
var equal = require('fast-deep-equal');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var utils = require('./utils-174b9d45.cjs.js');
|
|
7
|
+
var contexts = require('./contexts-a2387bed.cjs.js');
|
|
8
|
+
require('@plasmicapp/host/registerComponent');
|
|
9
|
+
require('@plasmicapp/host/registerGlobalContext');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var equal__default = /*#__PURE__*/_interopDefault(equal);
|
|
14
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
15
|
+
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __defProps = Object.defineProperties;
|
|
18
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
19
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
20
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
21
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
22
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
23
|
+
var __spreadValues = (a, b) => {
|
|
24
|
+
for (var prop in b || (b = {}))
|
|
25
|
+
if (__hasOwnProp.call(b, prop))
|
|
26
|
+
__defNormalProp(a, prop, b[prop]);
|
|
27
|
+
if (__getOwnPropSymbols)
|
|
28
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
29
|
+
if (__propIsEnum.call(b, prop))
|
|
30
|
+
__defNormalProp(a, prop, b[prop]);
|
|
31
|
+
}
|
|
32
|
+
return a;
|
|
33
|
+
};
|
|
34
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
35
|
+
var __objRest = (source, exclude) => {
|
|
36
|
+
var target = {};
|
|
37
|
+
for (var prop in source)
|
|
38
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
39
|
+
target[prop] = source[prop];
|
|
40
|
+
if (source != null && __getOwnPropSymbols)
|
|
41
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
42
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
43
|
+
target[prop] = source[prop];
|
|
44
|
+
}
|
|
45
|
+
return target;
|
|
46
|
+
};
|
|
47
|
+
var InputType = /* @__PURE__ */ ((InputType2) => {
|
|
48
|
+
InputType2["Text"] = "Text";
|
|
49
|
+
InputType2["TextArea"] = "Text Area";
|
|
50
|
+
InputType2["Password"] = "Password";
|
|
51
|
+
InputType2["Number"] = "Number";
|
|
52
|
+
InputType2["Select"] = "Select";
|
|
53
|
+
InputType2["Option"] = "Option";
|
|
54
|
+
InputType2["OptionGroup"] = "Option Group";
|
|
55
|
+
InputType2["Radio"] = "Radio";
|
|
56
|
+
InputType2["RadioGroup"] = "Radio Group";
|
|
57
|
+
InputType2["Checkbox"] = "Checkbox";
|
|
58
|
+
InputType2["DatePicker"] = "DatePicker";
|
|
59
|
+
InputType2["Unknown"] = "Unkown";
|
|
60
|
+
return InputType2;
|
|
61
|
+
})(InputType || {});
|
|
62
|
+
const SchemaFormContext = React__default.default.createContext(void 0);
|
|
63
|
+
var FormType = /* @__PURE__ */ ((FormType2) => {
|
|
64
|
+
FormType2[FormType2["NewEntry"] = 0] = "NewEntry";
|
|
65
|
+
FormType2[FormType2["UpdateEntry"] = 1] = "UpdateEntry";
|
|
66
|
+
return FormType2;
|
|
67
|
+
})(FormType || {});
|
|
68
|
+
const Internal = React__default.default.forwardRef(
|
|
69
|
+
(props, ref) => {
|
|
70
|
+
var _b, _c, _d, _e;
|
|
71
|
+
const [form] = antd.Form.useForm();
|
|
72
|
+
const values = form.getFieldsValue(true);
|
|
73
|
+
const lastValue = React__default.default.useRef(values);
|
|
74
|
+
const _a = props, {
|
|
75
|
+
extendedOnValuesChange,
|
|
76
|
+
forceRemount,
|
|
77
|
+
formLayout,
|
|
78
|
+
internalFieldCtx,
|
|
79
|
+
setInternalFieldCtx
|
|
80
|
+
} = _a, rest = __objRest(_a, [
|
|
81
|
+
"extendedOnValuesChange",
|
|
82
|
+
"forceRemount",
|
|
83
|
+
"formLayout",
|
|
84
|
+
"internalFieldCtx",
|
|
85
|
+
"setInternalFieldCtx"
|
|
86
|
+
]);
|
|
87
|
+
const childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
|
|
88
|
+
const fireOnValuesChange = React__default.default.useCallback(() => {
|
|
89
|
+
const values2 = form.getFieldsValue(true);
|
|
90
|
+
if (!equal__default.default(values2, lastValue.current)) {
|
|
91
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(values2);
|
|
92
|
+
lastValue.current = values2;
|
|
93
|
+
}
|
|
94
|
+
}, [form, lastValue]);
|
|
95
|
+
React__default.default.useEffect(() => {
|
|
96
|
+
fireOnValuesChange();
|
|
97
|
+
}, []);
|
|
98
|
+
React__default.default.useImperativeHandle(ref, () => ({
|
|
99
|
+
formInstance: form,
|
|
100
|
+
setFieldsValue: (newValues) => {
|
|
101
|
+
form.setFieldsValue(newValues);
|
|
102
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
103
|
+
},
|
|
104
|
+
setFieldValue: (namePath, value) => {
|
|
105
|
+
form.setFieldValue(namePath, value);
|
|
106
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
107
|
+
},
|
|
108
|
+
resetFields: () => {
|
|
109
|
+
form.resetFields();
|
|
110
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
111
|
+
},
|
|
112
|
+
validateFields: async (...args) => {
|
|
113
|
+
try {
|
|
114
|
+
return await form.validateFields(...args);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
return err;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
clearFields: () => {
|
|
120
|
+
const values2 = form.getFieldsValue(true);
|
|
121
|
+
utils.setFieldsToUndefined(values2);
|
|
122
|
+
form.setFieldsValue(values2);
|
|
123
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
const registerField = React__default.default.useCallback(
|
|
127
|
+
(fieldEntity) => {
|
|
128
|
+
setInternalFieldCtx((ctx) => ({
|
|
129
|
+
registeredFields: [...ctx.registeredFields, fieldEntity],
|
|
130
|
+
preservedRegisteredFields: [
|
|
131
|
+
...ctx.preservedRegisteredFields,
|
|
132
|
+
fieldEntity
|
|
133
|
+
]
|
|
134
|
+
}));
|
|
135
|
+
return () => {
|
|
136
|
+
setInternalFieldCtx((ctx) => ({
|
|
137
|
+
registeredFields: ctx.registeredFields.filter(
|
|
138
|
+
(ent) => ent !== fieldEntity
|
|
139
|
+
),
|
|
140
|
+
preservedRegisteredFields: ctx.preservedRegisteredFields.filter(
|
|
141
|
+
(ent) => ent !== fieldEntity || fieldEntity.preserve
|
|
142
|
+
)
|
|
143
|
+
}));
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
[setInternalFieldCtx]
|
|
147
|
+
);
|
|
148
|
+
const schemaFormCtx = React__default.default.useContext(SchemaFormContext);
|
|
149
|
+
(_b = props.setControlContextData) == null ? void 0 : _b.call(props, __spreadValues({
|
|
150
|
+
formInstance: form,
|
|
151
|
+
layout: formLayout,
|
|
152
|
+
internalFieldCtx
|
|
153
|
+
}, schemaFormCtx ? schemaFormCtx : {}));
|
|
154
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
155
|
+
contexts.InternalFormInstanceContext.Provider,
|
|
156
|
+
{
|
|
157
|
+
value: {
|
|
158
|
+
layout: formLayout,
|
|
159
|
+
fireOnValuesChange,
|
|
160
|
+
forceRemount,
|
|
161
|
+
registerField,
|
|
162
|
+
internalFieldCtx,
|
|
163
|
+
initialValues: (_c = props.initialValues) != null ? _c : {}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
/* @__PURE__ */ React__default.default.createElement(contexts.FormLayoutContext.Provider, { value: formLayout }, /* @__PURE__ */ React__default.default.createElement(
|
|
167
|
+
antd.Form,
|
|
168
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
169
|
+
key: props.initialValues ? JSON.stringify(props.initialValues) : void 0,
|
|
170
|
+
onValuesChange: (...args) => {
|
|
171
|
+
var _a2;
|
|
172
|
+
(_a2 = props.onValuesChange) == null ? void 0 : _a2.call(props, ...args);
|
|
173
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
174
|
+
},
|
|
175
|
+
onFinish: () => {
|
|
176
|
+
var _a2;
|
|
177
|
+
(_a2 = props.onFinish) == null ? void 0 : _a2.call(
|
|
178
|
+
props,
|
|
179
|
+
utils.pick(
|
|
180
|
+
form.getFieldsValue(true),
|
|
181
|
+
...internalFieldCtx.preservedRegisteredFields.map(
|
|
182
|
+
(field) => field.fullPath
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
form,
|
|
188
|
+
labelCol: ((_d = props.labelCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
|
|
189
|
+
wrapperCol: ((_e = props.wrapperCol) == null ? void 0 : _e.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
|
|
190
|
+
}),
|
|
191
|
+
/* @__PURE__ */ React__default.default.createElement("style", null, `
|
|
192
|
+
.ant-form-item-explain + div, .ant-form-item-margin-offset {
|
|
193
|
+
display: none;
|
|
194
|
+
}
|
|
195
|
+
`),
|
|
196
|
+
childrenNode
|
|
197
|
+
))
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
const FormWrapper = React__default.default.forwardRef(
|
|
202
|
+
(props, ref) => {
|
|
203
|
+
var _a;
|
|
204
|
+
const [remountKey, setRemountKey] = React__default.default.useState(0);
|
|
205
|
+
const forceRemount = React__default.default.useCallback(
|
|
206
|
+
() => setRemountKey((k) => k + 1),
|
|
207
|
+
[setRemountKey]
|
|
208
|
+
);
|
|
209
|
+
const previousInitialValues = utils.usePrevious(props.initialValues);
|
|
210
|
+
const wrapperRef = React__default.default.useRef(null);
|
|
211
|
+
React__default.default.useEffect(() => {
|
|
212
|
+
if (previousInitialValues !== props.initialValues && JSON.stringify(previousInitialValues) !== JSON.stringify(props.initialValues)) {
|
|
213
|
+
forceRemount();
|
|
214
|
+
}
|
|
215
|
+
}, [previousInitialValues, props.initialValues]);
|
|
216
|
+
const [internalFieldCtx, setInternalFieldCtx] = React__default.default.useState({
|
|
217
|
+
registeredFields: [],
|
|
218
|
+
preservedRegisteredFields: []
|
|
219
|
+
});
|
|
220
|
+
React__default.default.useImperativeHandle(
|
|
221
|
+
ref,
|
|
222
|
+
() => wrapperRef.current ? __spreadValues({}, wrapperRef.current) : {}
|
|
223
|
+
);
|
|
224
|
+
const formLayout = React__default.default.useMemo(
|
|
225
|
+
() => {
|
|
226
|
+
var _a2;
|
|
227
|
+
return {
|
|
228
|
+
layout: props.layout,
|
|
229
|
+
labelSpan: (_a2 = props.labelCol) == null ? void 0 : _a2.span
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
[props.layout, (_a = props.labelCol) == null ? void 0 : _a.span]
|
|
233
|
+
);
|
|
234
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
235
|
+
Internal,
|
|
236
|
+
__spreadValues({
|
|
237
|
+
key: remountKey,
|
|
238
|
+
forceRemount,
|
|
239
|
+
formLayout,
|
|
240
|
+
internalFieldCtx,
|
|
241
|
+
setInternalFieldCtx,
|
|
242
|
+
ref: wrapperRef
|
|
243
|
+
}, props)
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
const formHelpers = {
|
|
248
|
+
states: {
|
|
249
|
+
value: {
|
|
250
|
+
onMutate: (value, $ref) => {
|
|
251
|
+
var _a;
|
|
252
|
+
(_a = $ref == null ? void 0 : $ref.formInstance) == null ? void 0 : _a.setFieldsValue(value);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const OPTIMIZED_FORM_IMPORT = {
|
|
258
|
+
name: "FormWrapper",
|
|
259
|
+
path: "@plasmicpkgs/antd5/skinny/Form"
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
exports.FormType = FormType;
|
|
263
|
+
exports.FormWrapper = FormWrapper;
|
|
264
|
+
exports.InputType = InputType;
|
|
265
|
+
exports.OPTIMIZED_FORM_IMPORT = OPTIMIZED_FORM_IMPORT;
|
|
266
|
+
exports.SchemaFormContext = SchemaFormContext;
|
|
267
|
+
exports.formHelpers = formHelpers;
|
|
268
|
+
//# sourceMappingURL=Form.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Form.cjs.js","sources":["../src/form/Form.tsx"],"sourcesContent":["import type { DataOp, TableSchema } from \"@plasmicapp/data-sources\";\nimport { CodeComponentMode, ComponentHelpers } from \"@plasmicapp/host\";\nimport { CanvasComponentProps } from \"@plasmicapp/host/registerComponent\";\nimport { Form } from \"antd\";\nimport type { FormInstance, FormProps } from \"antd/es/form\";\nimport type { ColProps } from \"antd/es/grid/col\";\nimport equal from \"fast-deep-equal\";\nimport React from \"react\";\nimport { pick, setFieldsToUndefined, usePrevious } from \"../utils\";\nimport {\n CommonFormControlContextData,\n FieldEntity,\n FormLayoutContext,\n FormLayoutContextValue,\n InternalFieldCtx,\n InternalFormInstanceContext,\n} from \"./contexts\";\nimport { InternalFormItemProps } from \"./FormItem\";\n\nexport enum InputType {\n Text = \"Text\",\n TextArea = \"Text Area\",\n Password = \"Password\",\n Number = \"Number\",\n Select = \"Select\",\n Option = \"Option\",\n OptionGroup = \"Option Group\",\n Radio = \"Radio\",\n RadioGroup = \"Radio Group\",\n Checkbox = \"Checkbox\",\n DatePicker = \"DatePicker\",\n Unknown = \"Unkown\",\n}\n\nexport const SchemaFormContext = React.createContext<\n | {\n schema?: TableSchema;\n minimalFullLengthFields?: Partial<SimplifiedFormItemsProp>[];\n mergedFields?: SimplifiedFormItemsProp[];\n }\n | undefined\n>(undefined);\n\nexport interface SimplifiedFormItemsProp extends InternalFormItemProps {\n inputType: InputType;\n options?: {\n label: string;\n value: string;\n }[];\n optionType?: \"default\" | \"button\";\n showTime?: boolean;\n key?: string;\n}\n\nexport interface FormWrapperControlContextData\n extends CommonFormControlContextData {\n formInstance?: FormInstance<any>;\n schema?: TableSchema;\n minimalFullLengthFields?: Partial<SimplifiedFormItemsProp>[];\n mergedFields?: SimplifiedFormItemsProp[];\n}\n\nexport enum FormType {\n NewEntry,\n UpdateEntry,\n}\n\nexport interface FormWrapperProps\n extends FormProps,\n CanvasComponentProps<FormWrapperControlContextData> {\n /**\n * https://ant.design/components/form#setfieldsvalue-do-not-trigger-onfieldschange-or-onvalueschange\n * Because setFieldsValue doesn't trigger onValuesChange, we need to create our own onChange function.\n * This will allow us to trigger the onChange function and keep the value state updated in canvas.\n * We also don't invoke onValuesChange to avoid changing the standard behavior, since users may have\n * overridden this function in their codebase\n **/\n extendedOnValuesChange?: (\n values: Parameters<NonNullable<FormProps[\"onValuesChange\"]>>[1]\n ) => void;\n formItems?: SimplifiedFormItemsProp[];\n dataFormItems?: SimplifiedFormItemsProp[];\n mode?: CodeComponentMode;\n formType?: \"new-entry\" | \"update-entry\";\n submitSlot?: React.ReactNode;\n data?: DataOp;\n}\n\nconst Internal = React.forwardRef(\n (\n props: FormWrapperProps & {\n forceRemount: () => void;\n setInternalFieldCtx: React.Dispatch<\n React.SetStateAction<InternalFieldCtx>\n >;\n internalFieldCtx: InternalFieldCtx;\n labelCol?: ColProps & { horizontalOnly?: boolean };\n wrapperCol?: ColProps & { horizontalOnly?: boolean };\n formLayout: FormLayoutContextValue;\n },\n ref: React.Ref<FormRefActions>\n ) => {\n const [form] = Form.useForm();\n const values = form.getFieldsValue(true);\n const lastValue = React.useRef(values);\n const {\n extendedOnValuesChange,\n forceRemount,\n formLayout,\n internalFieldCtx,\n setInternalFieldCtx,\n ...rest\n } = props;\n // extracted from https://github.com/react-component/field-form/blob/master/src/Form.tsx#L120\n const childrenNode =\n typeof props.children === \"function\"\n ? props.children(values, form)\n : props.children;\n\n const fireOnValuesChange = React.useCallback(() => {\n const values = form.getFieldsValue(true);\n if (!equal(values, lastValue.current)) {\n extendedOnValuesChange?.(values);\n lastValue.current = values;\n }\n }, [form, lastValue]);\n\n React.useEffect(() => {\n fireOnValuesChange();\n }, []);\n React.useImperativeHandle(ref, () => ({\n formInstance: form,\n setFieldsValue: (newValues: Record<string, any>) => {\n form.setFieldsValue(newValues);\n extendedOnValuesChange?.(form.getFieldsValue(true));\n },\n setFieldValue: (\n namePath: string | number | (string | number)[],\n value: any\n ) => {\n form.setFieldValue(namePath, value);\n extendedOnValuesChange?.(form.getFieldsValue(true));\n },\n resetFields: () => {\n form.resetFields();\n extendedOnValuesChange?.(form.getFieldsValue(true));\n },\n validateFields: async (...args) => {\n try {\n return await form.validateFields(...(args as any));\n } catch (err) {\n return err as any;\n }\n },\n clearFields: () => {\n const values = form.getFieldsValue(true);\n setFieldsToUndefined(values);\n form.setFieldsValue(values);\n extendedOnValuesChange?.(form.getFieldsValue(true));\n },\n }));\n const registerField = React.useCallback(\n (fieldEntity: FieldEntity) => {\n setInternalFieldCtx((ctx) => ({\n registeredFields: [...ctx.registeredFields, fieldEntity],\n preservedRegisteredFields: [\n ...ctx.preservedRegisteredFields,\n fieldEntity,\n ],\n }));\n return () => {\n setInternalFieldCtx((ctx) => ({\n registeredFields: ctx.registeredFields.filter(\n (ent) => ent !== fieldEntity\n ),\n preservedRegisteredFields: ctx.preservedRegisteredFields.filter(\n (ent) => ent !== fieldEntity || fieldEntity.preserve\n ),\n }));\n };\n },\n [setInternalFieldCtx]\n );\n const schemaFormCtx = React.useContext(SchemaFormContext);\n props.setControlContextData?.({\n formInstance: form,\n layout: formLayout,\n internalFieldCtx,\n ...(schemaFormCtx ? schemaFormCtx : {}),\n });\n\n return (\n <InternalFormInstanceContext.Provider\n value={{\n layout: formLayout,\n fireOnValuesChange,\n forceRemount,\n registerField,\n internalFieldCtx,\n initialValues: props.initialValues ?? {},\n }}\n >\n <FormLayoutContext.Provider value={formLayout}>\n <Form\n {...rest}\n key={\n props.initialValues\n ? JSON.stringify(props.initialValues)\n : undefined\n }\n onValuesChange={(...args) => {\n props.onValuesChange?.(...args);\n extendedOnValuesChange?.(form.getFieldsValue(true));\n }}\n onFinish={() => {\n props.onFinish?.(\n pick(\n form.getFieldsValue(true),\n ...internalFieldCtx.preservedRegisteredFields.map(\n (field) => field.fullPath\n )\n )\n );\n }}\n form={form}\n labelCol={\n props.labelCol?.horizontalOnly && props.layout !== \"horizontal\"\n ? undefined\n : props.labelCol\n }\n wrapperCol={\n props.wrapperCol?.horizontalOnly && props.layout !== \"horizontal\"\n ? undefined\n : props.wrapperCol\n }\n >\n {/*Remove built-in spacing on form fields*/}\n <style>{`\n .ant-form-item-explain + div, .ant-form-item-margin-offset {\n display: none;\n }\n `}</style>\n {childrenNode}\n </Form>\n </FormLayoutContext.Provider>\n </InternalFormInstanceContext.Provider>\n );\n }\n);\n\nexport interface FormRefActions\n extends Pick<\n FormInstance<any>,\n \"setFieldsValue\" | \"resetFields\" | \"setFieldValue\" | \"validateFields\"\n > {\n clearFields: () => void;\n formInstance: FormInstance<any>;\n}\n\nexport const FormWrapper = React.forwardRef(\n (props: FormWrapperProps, ref: React.Ref<FormRefActions>) => {\n const [remountKey, setRemountKey] = React.useState(0);\n const forceRemount = React.useCallback(\n () => setRemountKey((k) => k + 1),\n [setRemountKey]\n );\n const previousInitialValues = usePrevious(props.initialValues);\n\n const wrapperRef = React.useRef<FormRefActions>(null);\n React.useEffect(() => {\n if (\n previousInitialValues !== props.initialValues &&\n JSON.stringify(previousInitialValues) !==\n JSON.stringify(props.initialValues)\n ) {\n forceRemount();\n }\n }, [previousInitialValues, props.initialValues]);\n const [internalFieldCtx, setInternalFieldCtx] =\n React.useState<InternalFieldCtx>({\n registeredFields: [],\n preservedRegisteredFields: [],\n });\n\n React.useImperativeHandle(ref, () =>\n wrapperRef.current ? { ...wrapperRef.current } : ({} as FormRefActions)\n );\n\n const formLayout = React.useMemo(\n () => ({\n layout: props.layout,\n labelSpan: props.labelCol?.span as number | undefined,\n }),\n [props.layout, props.labelCol?.span]\n );\n\n return (\n <Internal\n key={remountKey}\n forceRemount={forceRemount}\n formLayout={formLayout}\n internalFieldCtx={internalFieldCtx}\n setInternalFieldCtx={setInternalFieldCtx}\n ref={wrapperRef}\n {...props}\n />\n );\n }\n);\n\nexport const formHelpers: ComponentHelpers<FormWrapperProps> = {\n states: {\n value: {\n onMutate: (value, $ref) => {\n $ref?.formInstance?.setFieldsValue(value);\n },\n },\n },\n};\n\nexport const OPTIMIZED_FORM_IMPORT = {\n name: \"FormWrapper\",\n path: \"@plasmicpkgs/antd5/skinny/Form\",\n};\n"],"names":["InputType","React","FormType","Form","values","equal","setFieldsToUndefined","InternalFormInstanceContext","FormLayoutContext","_a","pick","usePrevious"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACL,EAAAA,WAAA,MAAO,CAAA,GAAA,MAAA,CAAA;AACP,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EA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A,GAAA,IAAA,CAAA,YAAA,KAAN,mBAAoB,cAAe,CAAA,KAAA,CAAA,CAAA;AAAA,OACrC;AAAA,KACF;AAAA,GACF;AACF,EAAA;AAEO,MAAM,qBAAwB,GAAA;AAAA,EACnC,IAAM,EAAA,aAAA;AAAA,EACN,IAAM,EAAA,gCAAA;AACR;;;;;;;;;"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Form } from 'antd';
|
|
2
|
+
import equal from 'fast-deep-equal';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { s as setFieldsToUndefined, p as pick, u as usePrevious } from './utils-7d8f2418.esm.js';
|
|
5
|
+
import { I as InternalFormInstanceContext, F as FormLayoutContext } from './contexts-4c7952c1.esm.js';
|
|
6
|
+
import '@plasmicapp/host/registerComponent';
|
|
7
|
+
import '@plasmicapp/host/registerGlobalContext';
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defProps = Object.defineProperties;
|
|
11
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
12
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
28
|
+
var __objRest = (source, exclude) => {
|
|
29
|
+
var target = {};
|
|
30
|
+
for (var prop in source)
|
|
31
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
if (source != null && __getOwnPropSymbols)
|
|
34
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
35
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
36
|
+
target[prop] = source[prop];
|
|
37
|
+
}
|
|
38
|
+
return target;
|
|
39
|
+
};
|
|
40
|
+
var InputType = /* @__PURE__ */ ((InputType2) => {
|
|
41
|
+
InputType2["Text"] = "Text";
|
|
42
|
+
InputType2["TextArea"] = "Text Area";
|
|
43
|
+
InputType2["Password"] = "Password";
|
|
44
|
+
InputType2["Number"] = "Number";
|
|
45
|
+
InputType2["Select"] = "Select";
|
|
46
|
+
InputType2["Option"] = "Option";
|
|
47
|
+
InputType2["OptionGroup"] = "Option Group";
|
|
48
|
+
InputType2["Radio"] = "Radio";
|
|
49
|
+
InputType2["RadioGroup"] = "Radio Group";
|
|
50
|
+
InputType2["Checkbox"] = "Checkbox";
|
|
51
|
+
InputType2["DatePicker"] = "DatePicker";
|
|
52
|
+
InputType2["Unknown"] = "Unkown";
|
|
53
|
+
return InputType2;
|
|
54
|
+
})(InputType || {});
|
|
55
|
+
const SchemaFormContext = React.createContext(void 0);
|
|
56
|
+
var FormType = /* @__PURE__ */ ((FormType2) => {
|
|
57
|
+
FormType2[FormType2["NewEntry"] = 0] = "NewEntry";
|
|
58
|
+
FormType2[FormType2["UpdateEntry"] = 1] = "UpdateEntry";
|
|
59
|
+
return FormType2;
|
|
60
|
+
})(FormType || {});
|
|
61
|
+
const Internal = React.forwardRef(
|
|
62
|
+
(props, ref) => {
|
|
63
|
+
var _b, _c, _d, _e;
|
|
64
|
+
const [form] = Form.useForm();
|
|
65
|
+
const values = form.getFieldsValue(true);
|
|
66
|
+
const lastValue = React.useRef(values);
|
|
67
|
+
const _a = props, {
|
|
68
|
+
extendedOnValuesChange,
|
|
69
|
+
forceRemount,
|
|
70
|
+
formLayout,
|
|
71
|
+
internalFieldCtx,
|
|
72
|
+
setInternalFieldCtx
|
|
73
|
+
} = _a, rest = __objRest(_a, [
|
|
74
|
+
"extendedOnValuesChange",
|
|
75
|
+
"forceRemount",
|
|
76
|
+
"formLayout",
|
|
77
|
+
"internalFieldCtx",
|
|
78
|
+
"setInternalFieldCtx"
|
|
79
|
+
]);
|
|
80
|
+
const childrenNode = typeof props.children === "function" ? props.children(values, form) : props.children;
|
|
81
|
+
const fireOnValuesChange = React.useCallback(() => {
|
|
82
|
+
const values2 = form.getFieldsValue(true);
|
|
83
|
+
if (!equal(values2, lastValue.current)) {
|
|
84
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(values2);
|
|
85
|
+
lastValue.current = values2;
|
|
86
|
+
}
|
|
87
|
+
}, [form, lastValue]);
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
fireOnValuesChange();
|
|
90
|
+
}, []);
|
|
91
|
+
React.useImperativeHandle(ref, () => ({
|
|
92
|
+
formInstance: form,
|
|
93
|
+
setFieldsValue: (newValues) => {
|
|
94
|
+
form.setFieldsValue(newValues);
|
|
95
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
96
|
+
},
|
|
97
|
+
setFieldValue: (namePath, value) => {
|
|
98
|
+
form.setFieldValue(namePath, value);
|
|
99
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
100
|
+
},
|
|
101
|
+
resetFields: () => {
|
|
102
|
+
form.resetFields();
|
|
103
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
104
|
+
},
|
|
105
|
+
validateFields: async (...args) => {
|
|
106
|
+
try {
|
|
107
|
+
return await form.validateFields(...args);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
return err;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
clearFields: () => {
|
|
113
|
+
const values2 = form.getFieldsValue(true);
|
|
114
|
+
setFieldsToUndefined(values2);
|
|
115
|
+
form.setFieldsValue(values2);
|
|
116
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
const registerField = React.useCallback(
|
|
120
|
+
(fieldEntity) => {
|
|
121
|
+
setInternalFieldCtx((ctx) => ({
|
|
122
|
+
registeredFields: [...ctx.registeredFields, fieldEntity],
|
|
123
|
+
preservedRegisteredFields: [
|
|
124
|
+
...ctx.preservedRegisteredFields,
|
|
125
|
+
fieldEntity
|
|
126
|
+
]
|
|
127
|
+
}));
|
|
128
|
+
return () => {
|
|
129
|
+
setInternalFieldCtx((ctx) => ({
|
|
130
|
+
registeredFields: ctx.registeredFields.filter(
|
|
131
|
+
(ent) => ent !== fieldEntity
|
|
132
|
+
),
|
|
133
|
+
preservedRegisteredFields: ctx.preservedRegisteredFields.filter(
|
|
134
|
+
(ent) => ent !== fieldEntity || fieldEntity.preserve
|
|
135
|
+
)
|
|
136
|
+
}));
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
[setInternalFieldCtx]
|
|
140
|
+
);
|
|
141
|
+
const schemaFormCtx = React.useContext(SchemaFormContext);
|
|
142
|
+
(_b = props.setControlContextData) == null ? void 0 : _b.call(props, __spreadValues({
|
|
143
|
+
formInstance: form,
|
|
144
|
+
layout: formLayout,
|
|
145
|
+
internalFieldCtx
|
|
146
|
+
}, schemaFormCtx ? schemaFormCtx : {}));
|
|
147
|
+
return /* @__PURE__ */ React.createElement(
|
|
148
|
+
InternalFormInstanceContext.Provider,
|
|
149
|
+
{
|
|
150
|
+
value: {
|
|
151
|
+
layout: formLayout,
|
|
152
|
+
fireOnValuesChange,
|
|
153
|
+
forceRemount,
|
|
154
|
+
registerField,
|
|
155
|
+
internalFieldCtx,
|
|
156
|
+
initialValues: (_c = props.initialValues) != null ? _c : {}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
/* @__PURE__ */ React.createElement(FormLayoutContext.Provider, { value: formLayout }, /* @__PURE__ */ React.createElement(
|
|
160
|
+
Form,
|
|
161
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
162
|
+
key: props.initialValues ? JSON.stringify(props.initialValues) : void 0,
|
|
163
|
+
onValuesChange: (...args) => {
|
|
164
|
+
var _a2;
|
|
165
|
+
(_a2 = props.onValuesChange) == null ? void 0 : _a2.call(props, ...args);
|
|
166
|
+
extendedOnValuesChange == null ? void 0 : extendedOnValuesChange(form.getFieldsValue(true));
|
|
167
|
+
},
|
|
168
|
+
onFinish: () => {
|
|
169
|
+
var _a2;
|
|
170
|
+
(_a2 = props.onFinish) == null ? void 0 : _a2.call(
|
|
171
|
+
props,
|
|
172
|
+
pick(
|
|
173
|
+
form.getFieldsValue(true),
|
|
174
|
+
...internalFieldCtx.preservedRegisteredFields.map(
|
|
175
|
+
(field) => field.fullPath
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
},
|
|
180
|
+
form,
|
|
181
|
+
labelCol: ((_d = props.labelCol) == null ? void 0 : _d.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.labelCol,
|
|
182
|
+
wrapperCol: ((_e = props.wrapperCol) == null ? void 0 : _e.horizontalOnly) && props.layout !== "horizontal" ? void 0 : props.wrapperCol
|
|
183
|
+
}),
|
|
184
|
+
/* @__PURE__ */ React.createElement("style", null, `
|
|
185
|
+
.ant-form-item-explain + div, .ant-form-item-margin-offset {
|
|
186
|
+
display: none;
|
|
187
|
+
}
|
|
188
|
+
`),
|
|
189
|
+
childrenNode
|
|
190
|
+
))
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
const FormWrapper = React.forwardRef(
|
|
195
|
+
(props, ref) => {
|
|
196
|
+
var _a;
|
|
197
|
+
const [remountKey, setRemountKey] = React.useState(0);
|
|
198
|
+
const forceRemount = React.useCallback(
|
|
199
|
+
() => setRemountKey((k) => k + 1),
|
|
200
|
+
[setRemountKey]
|
|
201
|
+
);
|
|
202
|
+
const previousInitialValues = usePrevious(props.initialValues);
|
|
203
|
+
const wrapperRef = React.useRef(null);
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
if (previousInitialValues !== props.initialValues && JSON.stringify(previousInitialValues) !== JSON.stringify(props.initialValues)) {
|
|
206
|
+
forceRemount();
|
|
207
|
+
}
|
|
208
|
+
}, [previousInitialValues, props.initialValues]);
|
|
209
|
+
const [internalFieldCtx, setInternalFieldCtx] = React.useState({
|
|
210
|
+
registeredFields: [],
|
|
211
|
+
preservedRegisteredFields: []
|
|
212
|
+
});
|
|
213
|
+
React.useImperativeHandle(
|
|
214
|
+
ref,
|
|
215
|
+
() => wrapperRef.current ? __spreadValues({}, wrapperRef.current) : {}
|
|
216
|
+
);
|
|
217
|
+
const formLayout = React.useMemo(
|
|
218
|
+
() => {
|
|
219
|
+
var _a2;
|
|
220
|
+
return {
|
|
221
|
+
layout: props.layout,
|
|
222
|
+
labelSpan: (_a2 = props.labelCol) == null ? void 0 : _a2.span
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
[props.layout, (_a = props.labelCol) == null ? void 0 : _a.span]
|
|
226
|
+
);
|
|
227
|
+
return /* @__PURE__ */ React.createElement(
|
|
228
|
+
Internal,
|
|
229
|
+
__spreadValues({
|
|
230
|
+
key: remountKey,
|
|
231
|
+
forceRemount,
|
|
232
|
+
formLayout,
|
|
233
|
+
internalFieldCtx,
|
|
234
|
+
setInternalFieldCtx,
|
|
235
|
+
ref: wrapperRef
|
|
236
|
+
}, props)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
const formHelpers = {
|
|
241
|
+
states: {
|
|
242
|
+
value: {
|
|
243
|
+
onMutate: (value, $ref) => {
|
|
244
|
+
var _a;
|
|
245
|
+
(_a = $ref == null ? void 0 : $ref.formInstance) == null ? void 0 : _a.setFieldsValue(value);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const OPTIMIZED_FORM_IMPORT = {
|
|
251
|
+
name: "FormWrapper",
|
|
252
|
+
path: "@plasmicpkgs/antd5/skinny/Form"
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export { FormType, FormWrapper, InputType, OPTIMIZED_FORM_IMPORT, SchemaFormContext, formHelpers };
|
|
256
|
+
//# sourceMappingURL=Form.esm.js.map
|