@plasmicpkgs/antd5 0.0.188 → 0.0.189
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 +5094 -4945
- 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 +5106 -4946
- 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/dist/registerForm.d.ts +0 -143
- package/skinny/registerForm.d.ts +0 -143
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { usePlasmicCanvasContext } from '@plasmicapp/host';
|
|
2
|
+
import { Form } from 'antd';
|
|
3
|
+
import React, { isValidElement, cloneElement } from 'react';
|
|
4
|
+
import { r as reactNodeToString, m as mergeProps } from './react-utils-79d444f6.esm.js';
|
|
5
|
+
import { e as ensureArray, g as get } from './utils-7d8f2418.esm.js';
|
|
6
|
+
import { u as useFormItemRelativeName, a as useFormItemFullName, P as PathContext, F as FormLayoutContext, I as InternalFormInstanceContext, b as useFormInstanceMaybe } from './contexts-4c7952c1.esm.js';
|
|
7
|
+
import 'classnames';
|
|
8
|
+
import '@plasmicapp/host/registerComponent';
|
|
9
|
+
import '@plasmicapp/host/registerGlobalContext';
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __defProps = Object.defineProperties;
|
|
13
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
14
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
17
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
+
var __spreadValues = (a, b) => {
|
|
19
|
+
for (var prop in b || (b = {}))
|
|
20
|
+
if (__hasOwnProp.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
if (__getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
24
|
+
if (__propIsEnum.call(b, prop))
|
|
25
|
+
__defNormalProp(a, prop, b[prop]);
|
|
26
|
+
}
|
|
27
|
+
return a;
|
|
28
|
+
};
|
|
29
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
30
|
+
var __objRest = (source, exclude) => {
|
|
31
|
+
var target = {};
|
|
32
|
+
for (var prop in source)
|
|
33
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
if (source != null && __getOwnPropSymbols)
|
|
36
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
37
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
38
|
+
target[prop] = source[prop];
|
|
39
|
+
}
|
|
40
|
+
return target;
|
|
41
|
+
};
|
|
42
|
+
const FormItem = Form.Item;
|
|
43
|
+
function plasmicRulesToAntdRules(plasmicRules, label) {
|
|
44
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
45
|
+
const effectiveLabel = label || "This field";
|
|
46
|
+
const rules = [];
|
|
47
|
+
for (const plasmicRule of plasmicRules) {
|
|
48
|
+
switch (plasmicRule.ruleType) {
|
|
49
|
+
case "enum":
|
|
50
|
+
rules.push({
|
|
51
|
+
type: "enum",
|
|
52
|
+
enum: (_b = (_a = plasmicRule.options) == null ? void 0 : _a.map((opt) => opt.value)) != null ? _b : [],
|
|
53
|
+
message: (_c = plasmicRule.message) != null ? _c : `${effectiveLabel} must be a valid value`
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
case "required":
|
|
57
|
+
rules.push({
|
|
58
|
+
required: true,
|
|
59
|
+
message: (_d = plasmicRule.message) != null ? _d : `${effectiveLabel} is required`
|
|
60
|
+
});
|
|
61
|
+
break;
|
|
62
|
+
case "regex":
|
|
63
|
+
rules.push({
|
|
64
|
+
pattern: new RegExp((_e = plasmicRule.pattern) != null ? _e : ""),
|
|
65
|
+
message: (_f = plasmicRule.message) != null ? _f : `${effectiveLabel} must be a valid value`
|
|
66
|
+
});
|
|
67
|
+
break;
|
|
68
|
+
case "whitespace":
|
|
69
|
+
rules.push({
|
|
70
|
+
whitespace: true,
|
|
71
|
+
message: (_g = plasmicRule.message) != null ? _g : `${effectiveLabel} is required`
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
case "min":
|
|
75
|
+
rules.push({
|
|
76
|
+
[plasmicRule.ruleType]: plasmicRule.length,
|
|
77
|
+
message: (_h = plasmicRule.message) != null ? _h : `${effectiveLabel} must be at least ${plasmicRule.length} characters`
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
case "max":
|
|
81
|
+
rules.push({
|
|
82
|
+
[plasmicRule.ruleType]: plasmicRule.length,
|
|
83
|
+
message: (_i = plasmicRule.message) != null ? _i : `${effectiveLabel} must be at most ${plasmicRule.length} characters`
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
case "advanced":
|
|
87
|
+
rules.push({
|
|
88
|
+
validator: (...args) => {
|
|
89
|
+
var _a2;
|
|
90
|
+
return ((_a2 = plasmicRule.custom) == null ? void 0 : _a2.apply(null, args)) ? Promise.resolve() : Promise.reject();
|
|
91
|
+
},
|
|
92
|
+
message: plasmicRule.message
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return rules;
|
|
97
|
+
}
|
|
98
|
+
function FormItemWrapper(props) {
|
|
99
|
+
var _b, _c, _d;
|
|
100
|
+
const _a = props, {
|
|
101
|
+
rules: plasmicRules,
|
|
102
|
+
description,
|
|
103
|
+
noLabel,
|
|
104
|
+
name,
|
|
105
|
+
hideValidationMessage,
|
|
106
|
+
customizeProps,
|
|
107
|
+
setControlContextData,
|
|
108
|
+
alignLabellessWithControls = true
|
|
109
|
+
} = _a, rest = __objRest(_a, [
|
|
110
|
+
"rules",
|
|
111
|
+
"description",
|
|
112
|
+
"noLabel",
|
|
113
|
+
"name",
|
|
114
|
+
"hideValidationMessage",
|
|
115
|
+
"customizeProps",
|
|
116
|
+
"setControlContextData",
|
|
117
|
+
"alignLabellessWithControls"
|
|
118
|
+
]);
|
|
119
|
+
const relativeFormItemName = useFormItemRelativeName(name);
|
|
120
|
+
const fullFormItemName = useFormItemFullName(name);
|
|
121
|
+
const pathCtx = React.useContext(PathContext);
|
|
122
|
+
const fieldEntity = React.useRef({
|
|
123
|
+
preserve: (_b = props.preserve) != null ? _b : true,
|
|
124
|
+
fullPath: pathCtx.fullPath,
|
|
125
|
+
name
|
|
126
|
+
}).current;
|
|
127
|
+
const bestEffortLabel = !noLabel && reactNodeToString(props.label) || ensureArray(props.name).slice(-1)[0];
|
|
128
|
+
const rules = plasmicRules ? plasmicRulesToAntdRules(
|
|
129
|
+
plasmicRules,
|
|
130
|
+
typeof bestEffortLabel === "number" ? "" + bestEffortLabel : bestEffortLabel
|
|
131
|
+
) : void 0;
|
|
132
|
+
const layoutContext = React.useContext(FormLayoutContext);
|
|
133
|
+
const inCanvas = !!usePlasmicCanvasContext();
|
|
134
|
+
const {
|
|
135
|
+
fireOnValuesChange,
|
|
136
|
+
forceRemount,
|
|
137
|
+
registerField,
|
|
138
|
+
initialValues,
|
|
139
|
+
internalFieldCtx
|
|
140
|
+
} = (_c = React.useContext(InternalFormInstanceContext)) != null ? _c : {};
|
|
141
|
+
if (inCanvas) {
|
|
142
|
+
const form = useFormInstanceMaybe();
|
|
143
|
+
const prevPropValues = React.useRef({
|
|
144
|
+
initialValue: props.initialValue,
|
|
145
|
+
name: props.name
|
|
146
|
+
});
|
|
147
|
+
(_d = props.setControlContextData) == null ? void 0 : _d.call(props, {
|
|
148
|
+
internalFieldCtx,
|
|
149
|
+
formInstance: form,
|
|
150
|
+
parentFormItemPath: pathCtx.fullPath,
|
|
151
|
+
layout: layoutContext
|
|
152
|
+
});
|
|
153
|
+
React.useEffect(() => {
|
|
154
|
+
if (prevPropValues.current.name !== props.name) {
|
|
155
|
+
forceRemount == null ? void 0 : forceRemount();
|
|
156
|
+
}
|
|
157
|
+
if (!fullFormItemName || get(initialValues, fullFormItemName) != null || props.initialValue == null) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
|
|
161
|
+
prevPropValues.current.initialValue = props.initialValue;
|
|
162
|
+
fireOnValuesChange == null ? void 0 : fireOnValuesChange();
|
|
163
|
+
}, [
|
|
164
|
+
form,
|
|
165
|
+
props.initialValue,
|
|
166
|
+
JSON.stringify(pathCtx.fullPath),
|
|
167
|
+
props.name,
|
|
168
|
+
props.preserve
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
var _a2;
|
|
173
|
+
fieldEntity.fullPath = [
|
|
174
|
+
...pathCtx.fullPath,
|
|
175
|
+
...props.name != null ? [props.name] : []
|
|
176
|
+
];
|
|
177
|
+
fieldEntity.name = props.name;
|
|
178
|
+
fieldEntity.preserve = (_a2 = props.preserve) != null ? _a2 : true;
|
|
179
|
+
}, [pathCtx.fullPath, props.name, props.preserve]);
|
|
180
|
+
React.useEffect(() => {
|
|
181
|
+
const unregister = registerField == null ? void 0 : registerField(fieldEntity);
|
|
182
|
+
return () => unregister == null ? void 0 : unregister();
|
|
183
|
+
}, []);
|
|
184
|
+
return /* @__PURE__ */ React.createElement(
|
|
185
|
+
FormItem,
|
|
186
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
187
|
+
label: noLabel ? void 0 : props.label,
|
|
188
|
+
name: relativeFormItemName,
|
|
189
|
+
rules,
|
|
190
|
+
extra: description,
|
|
191
|
+
help: hideValidationMessage ? "" : props.help,
|
|
192
|
+
colon: noLabel ? false : void 0,
|
|
193
|
+
valuePropName: deriveValuePropName(props),
|
|
194
|
+
trigger: deriveOnChangePropName(props),
|
|
195
|
+
wrapperCol: (layoutContext == null ? void 0 : layoutContext.layout) === "horizontal" && noLabel && alignLabellessWithControls && layoutContext.labelSpan ? { offset: layoutContext.labelSpan } : void 0
|
|
196
|
+
}),
|
|
197
|
+
/* @__PURE__ */ React.createElement(FormItemForwarder, { formItemProps: props })
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
function deriveValuePropName(props) {
|
|
201
|
+
var _a;
|
|
202
|
+
if (props.valuePropName) {
|
|
203
|
+
return props.valuePropName;
|
|
204
|
+
}
|
|
205
|
+
const valueProps = ((_a = React.Children.map(props.children, (child) => {
|
|
206
|
+
var _a2;
|
|
207
|
+
if (React.isValidElement(child)) {
|
|
208
|
+
const childType = child.type;
|
|
209
|
+
if (childType) {
|
|
210
|
+
const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.valueProp;
|
|
211
|
+
if (x) {
|
|
212
|
+
return x;
|
|
213
|
+
}
|
|
214
|
+
const plumeType = childType.__plumeType;
|
|
215
|
+
if (plumeType && (plumeType === "checkbox" || plumeType === "switch")) {
|
|
216
|
+
return "isChecked";
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return void 0;
|
|
221
|
+
})) != null ? _a : []).filter((x) => !!x);
|
|
222
|
+
if (valueProps.length > 0) {
|
|
223
|
+
return valueProps[0];
|
|
224
|
+
}
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
227
|
+
function deriveOnChangePropName(props) {
|
|
228
|
+
var _a;
|
|
229
|
+
if (props.trigger) {
|
|
230
|
+
return props.trigger;
|
|
231
|
+
}
|
|
232
|
+
const triggerProps = ((_a = React.Children.map(props.children, (child) => {
|
|
233
|
+
var _a2;
|
|
234
|
+
if (React.isValidElement(child)) {
|
|
235
|
+
const childType = child.type;
|
|
236
|
+
if (childType) {
|
|
237
|
+
const x = (_a2 = childType.__plasmicFormFieldMeta) == null ? void 0 : _a2.onChangeProp;
|
|
238
|
+
if (x) {
|
|
239
|
+
return x;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return void 0;
|
|
244
|
+
})) != null ? _a : []).filter((x) => !!x);
|
|
245
|
+
if (triggerProps.length > 0) {
|
|
246
|
+
return triggerProps[0];
|
|
247
|
+
}
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
function FormItemForwarder(_a) {
|
|
251
|
+
var _b = _a, { formItemProps } = _b, props = __objRest(_b, ["formItemProps"]);
|
|
252
|
+
var _a2;
|
|
253
|
+
const status = Form.Item.useStatus();
|
|
254
|
+
const internalFormCtx = React.useContext(InternalFormInstanceContext);
|
|
255
|
+
const data = {
|
|
256
|
+
status: status.status
|
|
257
|
+
};
|
|
258
|
+
(_a2 = props.setControlContextData) == null ? void 0 : _a2.call(props, {
|
|
259
|
+
internalFormCtx,
|
|
260
|
+
status
|
|
261
|
+
});
|
|
262
|
+
return React.Children.map(formItemProps.children, (child, i) => {
|
|
263
|
+
var _a3;
|
|
264
|
+
if (i === 0 && isValidElement(child)) {
|
|
265
|
+
let newProps = __spreadProps(__spreadValues(__spreadValues({
|
|
266
|
+
name: formItemProps.name
|
|
267
|
+
}, (_a3 = child.props) != null ? _a3 : {}), props), {
|
|
268
|
+
__plasmicFormField: true
|
|
269
|
+
});
|
|
270
|
+
if (formItemProps.customizeProps) {
|
|
271
|
+
newProps = mergeProps(
|
|
272
|
+
newProps,
|
|
273
|
+
formItemProps.customizeProps(data, newProps)
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
return cloneElement(child, newProps);
|
|
277
|
+
} else {
|
|
278
|
+
return child;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export { FormItemWrapper };
|
|
284
|
+
//# sourceMappingURL=FormItem.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormItem.esm.js","sources":["../src/form/FormItem.tsx"],"sourcesContent":["import { usePlasmicCanvasContext } from \"@plasmicapp/host\";\nimport { CanvasComponentProps } from \"@plasmicapp/host/registerComponent\";\nimport { Form } from \"antd\";\nimport type { FormItemProps } from \"antd/es/form/FormItem\";\nimport React, { cloneElement, isValidElement } from \"react\";\nimport { mergeProps, reactNodeToString } from \"../react-utils\";\nimport { ensureArray, get } from \"../utils\";\nimport {\n CommonFormControlContextData,\n FieldEntity,\n FormLayoutContext,\n InternalFormInstanceContext,\n PathContext,\n useFormInstanceMaybe,\n useFormItemFullName,\n useFormItemRelativeName,\n} from \"./contexts\";\n\nconst FormItem = Form.Item;\n\nexport interface FormItemControlContextData\n extends CommonFormControlContextData {\n parentFormItemPath: (string | number)[];\n status?: ReturnType<typeof Form.Item.useStatus>;\n}\n\ninterface CuratedFieldData {\n status: string | undefined;\n // path: (string | number)[];\n // errors: string[];\n // warnings: string[];\n // value: any;\n // trigger: (x: any) => void;\n}\n\nexport interface InternalFormItemProps\n extends Omit<FormItemProps, \"rules\" | \"name\">,\n CanvasComponentProps<FormItemControlContextData> {\n rules?: PlasmicRule[];\n description?: React.ReactNode;\n noLabel?: boolean;\n hideValidationMessage?: boolean;\n customizeProps?: (\n fieldData: CuratedFieldData,\n props: InternalFormItemProps\n ) => FormItemProps;\n alignLabellessWithControls?: boolean;\n name?: string;\n}\n\ninterface PlasmicRule {\n ruleType:\n | \"enum\"\n | \"len\"\n | \"max\"\n | \"min\"\n | \"regex\"\n | \"required\"\n | \"whitespace\"\n | \"advanced\";\n length?: number;\n pattern?: string;\n custom?: (...args: any[]) => any;\n options?: { value: any }[];\n message?: string;\n}\n\nfunction plasmicRulesToAntdRules(\n plasmicRules: PlasmicRule[],\n label: string | undefined\n) {\n const effectiveLabel = label || \"This field\";\n const rules: FormItemProps[\"rules\"] = [];\n for (const plasmicRule of plasmicRules) {\n switch (plasmicRule.ruleType) {\n case \"enum\":\n rules.push({\n type: \"enum\",\n enum: plasmicRule.options?.map((opt) => opt.value) ?? [],\n message:\n plasmicRule.message ?? `${effectiveLabel} must be a valid value`,\n });\n break;\n case \"required\":\n rules.push({\n required: true,\n message: plasmicRule.message ?? `${effectiveLabel} is required`,\n });\n break;\n case \"regex\":\n rules.push({\n pattern: new RegExp(plasmicRule.pattern ?? \"\"),\n message:\n plasmicRule.message ?? `${effectiveLabel} must be a valid value`,\n });\n break;\n case \"whitespace\":\n rules.push({\n whitespace: true,\n message: plasmicRule.message ?? `${effectiveLabel} is required`,\n });\n break;\n case \"min\":\n rules.push({\n [plasmicRule.ruleType]: plasmicRule.length,\n message:\n plasmicRule.message ??\n `${effectiveLabel} must be at least ${plasmicRule.length} characters`,\n });\n break;\n case \"max\":\n rules.push({\n [plasmicRule.ruleType]: plasmicRule.length,\n message:\n plasmicRule.message ??\n `${effectiveLabel} must be at most ${plasmicRule.length} characters`,\n });\n break;\n case \"advanced\":\n rules.push({\n validator: (...args) =>\n plasmicRule.custom?.apply(null, args)\n ? Promise.resolve()\n : Promise.reject(),\n message: plasmicRule.message,\n });\n }\n }\n return rules;\n}\n\nexport function FormItemWrapper(props: InternalFormItemProps) {\n const {\n rules: plasmicRules,\n description,\n noLabel,\n name,\n hideValidationMessage,\n customizeProps,\n setControlContextData,\n alignLabellessWithControls = true,\n ...rest\n } = props;\n const relativeFormItemName = useFormItemRelativeName(name);\n const fullFormItemName = useFormItemFullName(name);\n const pathCtx = React.useContext(PathContext);\n const fieldEntity = React.useRef<FieldEntity>({\n preserve: props.preserve ?? true,\n fullPath: pathCtx.fullPath,\n name,\n }).current;\n const bestEffortLabel =\n (!noLabel && reactNodeToString(props.label)) ||\n ensureArray(props.name).slice(-1)[0];\n const rules = plasmicRules\n ? plasmicRulesToAntdRules(\n plasmicRules,\n typeof bestEffortLabel === \"number\"\n ? \"\" + bestEffortLabel\n : bestEffortLabel\n )\n : undefined;\n const layoutContext = React.useContext(FormLayoutContext);\n const inCanvas = !!usePlasmicCanvasContext();\n const {\n fireOnValuesChange,\n forceRemount,\n registerField,\n initialValues,\n internalFieldCtx,\n } = React.useContext(InternalFormInstanceContext) ?? {};\n if (inCanvas) {\n const form = useFormInstanceMaybe();\n const prevPropValues = React.useRef({\n initialValue: props.initialValue,\n name: props.name,\n });\n props.setControlContextData?.({\n internalFieldCtx,\n formInstance: form,\n parentFormItemPath: pathCtx.fullPath,\n layout: layoutContext,\n });\n React.useEffect(() => {\n if (prevPropValues.current.name !== props.name) {\n forceRemount?.();\n }\n if (\n !fullFormItemName ||\n get(initialValues, fullFormItemName) != null ||\n props.initialValue == null\n ) {\n // this field value is set at the form level\n return;\n }\n form?.setFieldValue(fullFormItemName, props.initialValue);\n prevPropValues.current.initialValue = props.initialValue;\n fireOnValuesChange?.();\n }, [\n form,\n props.initialValue,\n JSON.stringify(pathCtx.fullPath),\n props.name,\n props.preserve,\n ]);\n }\n React.useEffect(() => {\n fieldEntity.fullPath = [\n ...pathCtx.fullPath,\n ...(props.name != null ? [props.name] : []),\n ];\n fieldEntity.name = props.name;\n fieldEntity.preserve = props.preserve ?? true;\n }, [pathCtx.fullPath, props.name, props.preserve]);\n React.useEffect(() => {\n const unregister = registerField?.(fieldEntity);\n return () => unregister?.();\n }, []);\n return (\n <FormItem\n {...rest}\n label={noLabel ? undefined : props.label}\n name={relativeFormItemName}\n rules={rules}\n extra={description}\n help={hideValidationMessage ? \"\" : props.help}\n colon={noLabel ? false : undefined}\n valuePropName={deriveValuePropName(props)}\n trigger={deriveOnChangePropName(props)}\n // If in horizontal mode and no label, then we align the content\n // with the rest of the controls in the grid\n // if alignLabellessWithControls is true\n wrapperCol={\n layoutContext?.layout === \"horizontal\" &&\n noLabel &&\n alignLabellessWithControls &&\n layoutContext.labelSpan\n ? { offset: layoutContext.labelSpan }\n : undefined\n }\n >\n <FormItemForwarder formItemProps={props} />\n </FormItem>\n );\n}\n\n/**\n * Derive the valuePropName to use, if the wrapped child has designated\n * one via its Component.__plasmicFormFieldMeta?.valueProp.\n */\nfunction deriveValuePropName(props: InternalFormItemProps): string | undefined {\n if (props.valuePropName) {\n // Always prefer an explicitly specified valuePropName\n return props.valuePropName;\n }\n\n const valueProps = (\n React.Children.map(props.children as any, (child) => {\n if (React.isValidElement(child)) {\n const childType = child.type;\n if (childType) {\n const x = (childType as any).__plasmicFormFieldMeta?.valueProp;\n if (x) {\n return x as string;\n }\n // Hard-coding \"isChecked\" for Plume checkbox / switch\n const plumeType = (childType as any).__plumeType;\n if (\n plumeType &&\n (plumeType === \"checkbox\" || plumeType === \"switch\")\n ) {\n return \"isChecked\";\n }\n }\n }\n return undefined;\n }) ?? []\n ).filter((x: any): x is string => !!x);\n if (valueProps.length > 0) {\n return valueProps[0];\n }\n return undefined;\n}\n\n/**\n * Derive the onChange prop to use, if the wrapped child has designated\n * one via its Component.__plasmicFormFieldMeta?.valueProp.\n */\nfunction deriveOnChangePropName(\n props: InternalFormItemProps\n): string | undefined {\n if (props.trigger) {\n // Always prefer an explicitly specified valuePropName\n return props.trigger;\n }\n\n const triggerProps = (\n React.Children.map(props.children as any, (child) => {\n if (React.isValidElement(child)) {\n const childType = child.type;\n if (childType) {\n const x = (childType as any).__plasmicFormFieldMeta?.onChangeProp;\n if (x) {\n return x as string;\n }\n }\n }\n return undefined;\n }) ?? []\n ).filter((x: any): x is string => !!x);\n if (triggerProps.length > 0) {\n return triggerProps[0];\n }\n return undefined;\n}\n\nfunction FormItemForwarder({ formItemProps, ...props }: any) {\n const status = Form.Item.useStatus();\n const internalFormCtx = React.useContext(InternalFormInstanceContext);\n // const value = props[formItemProps.valuePropName ?? \"value\"];\n // const trigger = props[formItemProps.trigger ?? \"onChange\"];\n const data: CuratedFieldData = {\n status: status.status,\n };\n props.setControlContextData?.({\n internalFormCtx,\n status,\n });\n return React.Children.map(formItemProps.children, (child, i) => {\n if (i === 0 && isValidElement(child)) {\n let newProps = {\n name: formItemProps.name,\n ...(child.props ?? {}),\n ...props,\n __plasmicFormField: true,\n };\n if (formItemProps.customizeProps) {\n newProps = mergeProps(\n newProps,\n formItemProps.customizeProps(data, newProps)\n );\n }\n return cloneElement(child, newProps);\n } else {\n return child;\n }\n });\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,WAAW,IA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,qBAAN,KAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,IAAA,IAA8B,CAAA,KAAA,EAAA;AAAA,IAC5B,eAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA,CAAA;AACA,EAAA,OAAO,MAAM,QAAS,CAAA,GAAA,CAAI,cAAc,QAAU,EAAA,CAAC,OAAO,CAAM,KAAA;AAxUlE,IAAAA,IAAAA,GAAAA,CAAAA;AAyUI,IAAA,IAAI,CAAM,KAAA,CAAA,IAAK,cAAe,CAAA,KAAK,CAAG,EAAA;AACpC,MAAA,IAAI,QAAW,GAAA,aAAA,CAAA,cAAA,CAAA,cAAA,CAAA;AAAA,QACb,MAAM,aAAc,CAAA,IAAA;AAAA,OAAA,EAAA,CAChBA,MAAA,KAAM,CAAA,KAAA,KAAN,OAAAA,GAAe,GAAA,KAChB,KAHU,CAAA,EAAA;AAAA,QAIb,kBAAoB,EAAA,IAAA;AAAA,OACtB,CAAA,CAAA;AACA,MAAA,IAAI,cAAc,cAAgB,EAAA;AAChC,QAAW,QAAA,GAAA,UAAA;AAAA,UACT,QAAA;AAAA,UACA,aAAA,CAAc,cAAe,CAAA,IAAA,EAAM,QAAQ,CAAA;AAAA,SAC7C,CAAA;AAAA,OACF;AACA,MAAO,OAAA,YAAA,CAAa,OAAO,QAAQ,CAAA,CAAA;AAAA,KAC9B,MAAA;AACL,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var host = require('@plasmicapp/host');
|
|
4
|
+
var antd = require('antd');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var contexts = require('./contexts-a2387bed.cjs.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defProps = Object.defineProperties;
|
|
14
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
15
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
19
|
+
var __spreadValues = (a, b) => {
|
|
20
|
+
for (var prop in b || (b = {}))
|
|
21
|
+
if (__hasOwnProp.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
if (__getOwnPropSymbols)
|
|
24
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
25
|
+
if (__propIsEnum.call(b, prop))
|
|
26
|
+
__defNormalProp(a, prop, b[prop]);
|
|
27
|
+
}
|
|
28
|
+
return a;
|
|
29
|
+
};
|
|
30
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
31
|
+
const FormList = antd.Form.List;
|
|
32
|
+
const FormListWrapper = React__default.default.forwardRef(function FormListWrapper2(props, ref) {
|
|
33
|
+
var _a;
|
|
34
|
+
const relativeFormItemName = contexts.useFormItemRelativeName(props.name);
|
|
35
|
+
const fullFormItemName = contexts.useFormItemFullName(props.name);
|
|
36
|
+
const operationsRef = React__default.default.useRef(
|
|
37
|
+
void 0
|
|
38
|
+
);
|
|
39
|
+
React__default.default.useImperativeHandle(
|
|
40
|
+
ref,
|
|
41
|
+
() => ({
|
|
42
|
+
add(defaultValue, insertIndex) {
|
|
43
|
+
if (operationsRef.current) {
|
|
44
|
+
const { add } = operationsRef.current[1];
|
|
45
|
+
add(defaultValue, insertIndex);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
remove(index) {
|
|
49
|
+
if (operationsRef.current) {
|
|
50
|
+
const { remove } = operationsRef.current[1];
|
|
51
|
+
remove(index);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
move(from, to) {
|
|
55
|
+
if (operationsRef.current) {
|
|
56
|
+
const { move } = operationsRef.current[1];
|
|
57
|
+
move(from, to);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
[operationsRef]
|
|
62
|
+
);
|
|
63
|
+
const inCanvas = !!host.usePlasmicCanvasContext();
|
|
64
|
+
if (inCanvas) {
|
|
65
|
+
const form = contexts.useFormInstanceMaybe();
|
|
66
|
+
const prevPropValues = React__default.default.useRef({
|
|
67
|
+
initialValue: props.initialValue,
|
|
68
|
+
name: props.name
|
|
69
|
+
});
|
|
70
|
+
const { fireOnValuesChange, forceRemount } = (_a = React__default.default.useContext(contexts.InternalFormInstanceContext)) != null ? _a : {};
|
|
71
|
+
React__default.default.useEffect(() => {
|
|
72
|
+
if (prevPropValues.current.name !== props.name) {
|
|
73
|
+
forceRemount == null ? void 0 : forceRemount();
|
|
74
|
+
}
|
|
75
|
+
if (fullFormItemName) {
|
|
76
|
+
form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
|
|
77
|
+
prevPropValues.current.initialValue = props.initialValue;
|
|
78
|
+
fireOnValuesChange == null ? void 0 : fireOnValuesChange();
|
|
79
|
+
}
|
|
80
|
+
}, [JSON.stringify(props.initialValue), JSON.stringify(fullFormItemName)]);
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ React__default.default.createElement(FormList, __spreadProps(__spreadValues({}, props), { name: relativeFormItemName != null ? relativeFormItemName : [] }), (...args) => {
|
|
83
|
+
operationsRef.current = args;
|
|
84
|
+
return args[0].map((field, index) => /* @__PURE__ */ React__default.default.createElement(
|
|
85
|
+
contexts.PathContext.Provider,
|
|
86
|
+
{
|
|
87
|
+
value: {
|
|
88
|
+
relativePath: [field.name],
|
|
89
|
+
fullPath: [...fullFormItemName != null ? fullFormItemName : [], field.name]
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
/* @__PURE__ */ React__default.default.createElement(host.DataProvider, { name: "currentField", data: field }, /* @__PURE__ */ React__default.default.createElement(host.DataProvider, { name: "currentFieldIndex", data: index }, host.repeatedElement(index, props.children)))
|
|
93
|
+
));
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
exports.FormListWrapper = FormListWrapper;
|
|
98
|
+
//# sourceMappingURL=FormList.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormList.cjs.js","sources":["../src/form/FormList.tsx"],"sourcesContent":["import {\n DataProvider,\n repeatedElement,\n usePlasmicCanvasContext,\n} from \"@plasmicapp/host\";\nimport { Form } from \"antd\";\nimport type { FormListOperation, FormListProps } from \"antd/es/form/FormList\";\nimport React from \"react\";\nimport {\n InternalFormInstanceContext,\n PathContext,\n useFormInstanceMaybe,\n useFormItemFullName,\n useFormItemRelativeName,\n} from \"./contexts\";\n\nconst FormList = Form.List;\n\ntype FormListWrapperProps = Omit<FormListProps, \"children\"> & {\n children: React.ReactNode;\n};\n\ntype FormListRenderFuncParams = Parameters<FormListProps[\"children\"]>;\n\nexport const FormListWrapper = React.forwardRef(function FormListWrapper(\n props: FormListWrapperProps,\n ref: React.Ref<FormListOperation>\n) {\n const relativeFormItemName = useFormItemRelativeName(props.name);\n const fullFormItemName = useFormItemFullName(props.name);\n const operationsRef = React.useRef<FormListRenderFuncParams | undefined>(\n undefined\n );\n React.useImperativeHandle(\n ref,\n () => ({\n add(defaultValue, insertIndex) {\n if (operationsRef.current) {\n const { add } = operationsRef.current[1];\n add(defaultValue, insertIndex);\n }\n },\n remove(index) {\n if (operationsRef.current) {\n const { remove } = operationsRef.current[1];\n remove(index);\n }\n },\n move(from, to) {\n if (operationsRef.current) {\n const { move } = operationsRef.current[1];\n move(from, to);\n }\n },\n }),\n [operationsRef]\n );\n const inCanvas = !!usePlasmicCanvasContext();\n if (inCanvas) {\n const form = useFormInstanceMaybe();\n const prevPropValues = React.useRef({\n initialValue: props.initialValue,\n name: props.name,\n });\n const { fireOnValuesChange, forceRemount } =\n React.useContext(InternalFormInstanceContext) ?? {};\n React.useEffect(() => {\n if (prevPropValues.current.name !== props.name) {\n forceRemount?.();\n }\n if (fullFormItemName) {\n form?.setFieldValue(fullFormItemName, props.initialValue);\n prevPropValues.current.initialValue = props.initialValue;\n fireOnValuesChange?.();\n }\n }, [JSON.stringify(props.initialValue), JSON.stringify(fullFormItemName)]);\n }\n return (\n <FormList {...props} name={relativeFormItemName ?? []}>\n {(...args) => {\n operationsRef.current = args;\n return args[0].map((field, index) => (\n <PathContext.Provider\n value={{\n relativePath: [field.name],\n fullPath: [...(fullFormItemName ?? []), field.name],\n }}\n >\n <DataProvider name={\"currentField\"} data={field}>\n <DataProvider name={\"currentFieldIndex\"} data={index}>\n {repeatedElement(index, props.children)}\n </DataProvider>\n </DataProvider>\n </PathContext.Provider>\n ));\n }}\n </FormList>\n );\n});\n"],"names":["Form","React","FormListWrapper","useFormItemRelativeName","useFormItemFullName","usePlasmicCanvasContext","useFormInstanceMaybe","InternalFormInstanceContext","PathContext","DataProvider","repeatedElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,WAAWA,SAAK,CAAA,IAAA,CAAA;AAQf,MAAM,kBAAkBC,sBAAM,CAAA,UAAA,CAAW,SAASC,gBAAAA,CACvD,OACA,GACA,EAAA;AA3BF,EAAA,IAAA,EAAA,CAAA;AA4BE,EAAM,MAAA,oBAAA,GAAuBC,gCAAwB,CAAA,KAAA,CAAM,IAAI,CAAA,CAAA;AAC/D,EAAM,MAAA,gBAAA,GAAmBC,4BAAoB,CAAA,KAAA,CAAM,IAAI,CAAA,CAAA;AACvD,EAAA,MAAM,gBAAgBH,sBAAM,CAAA,MAAA;AAAA,IAC1B,KAAA,CAAA;AAAA,GACF,CAAA;AACA,EAAMA,sBAAA,CAAA,mBAAA;AAAA,IACJ,GAAA;AAA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EAAa,IAAM,EAAA,mBAAA,EAAqB,MAAM,KAC5C,EAAA,EAAAC,oBAAA,CAAgB,OAAO,KAAM,CAAA,QAAQ,CACxC,CACF,CAAA;AAAA,KAEH,CAAA,CAAA;AAAA,GAEL,CAAA,CAAA;AAEJ,CAAC;;;;"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { usePlasmicCanvasContext, DataProvider, repeatedElement } from '@plasmicapp/host';
|
|
2
|
+
import { Form } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { u as useFormItemRelativeName, a as useFormItemFullName, b as useFormInstanceMaybe, I as InternalFormInstanceContext, P as PathContext } from './contexts-4c7952c1.esm.js';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
const FormList = Form.List;
|
|
26
|
+
const FormListWrapper = React.forwardRef(function FormListWrapper2(props, ref) {
|
|
27
|
+
var _a;
|
|
28
|
+
const relativeFormItemName = useFormItemRelativeName(props.name);
|
|
29
|
+
const fullFormItemName = useFormItemFullName(props.name);
|
|
30
|
+
const operationsRef = React.useRef(
|
|
31
|
+
void 0
|
|
32
|
+
);
|
|
33
|
+
React.useImperativeHandle(
|
|
34
|
+
ref,
|
|
35
|
+
() => ({
|
|
36
|
+
add(defaultValue, insertIndex) {
|
|
37
|
+
if (operationsRef.current) {
|
|
38
|
+
const { add } = operationsRef.current[1];
|
|
39
|
+
add(defaultValue, insertIndex);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
remove(index) {
|
|
43
|
+
if (operationsRef.current) {
|
|
44
|
+
const { remove } = operationsRef.current[1];
|
|
45
|
+
remove(index);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
move(from, to) {
|
|
49
|
+
if (operationsRef.current) {
|
|
50
|
+
const { move } = operationsRef.current[1];
|
|
51
|
+
move(from, to);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
[operationsRef]
|
|
56
|
+
);
|
|
57
|
+
const inCanvas = !!usePlasmicCanvasContext();
|
|
58
|
+
if (inCanvas) {
|
|
59
|
+
const form = useFormInstanceMaybe();
|
|
60
|
+
const prevPropValues = React.useRef({
|
|
61
|
+
initialValue: props.initialValue,
|
|
62
|
+
name: props.name
|
|
63
|
+
});
|
|
64
|
+
const { fireOnValuesChange, forceRemount } = (_a = React.useContext(InternalFormInstanceContext)) != null ? _a : {};
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (prevPropValues.current.name !== props.name) {
|
|
67
|
+
forceRemount == null ? void 0 : forceRemount();
|
|
68
|
+
}
|
|
69
|
+
if (fullFormItemName) {
|
|
70
|
+
form == null ? void 0 : form.setFieldValue(fullFormItemName, props.initialValue);
|
|
71
|
+
prevPropValues.current.initialValue = props.initialValue;
|
|
72
|
+
fireOnValuesChange == null ? void 0 : fireOnValuesChange();
|
|
73
|
+
}
|
|
74
|
+
}, [JSON.stringify(props.initialValue), JSON.stringify(fullFormItemName)]);
|
|
75
|
+
}
|
|
76
|
+
return /* @__PURE__ */ React.createElement(FormList, __spreadProps(__spreadValues({}, props), { name: relativeFormItemName != null ? relativeFormItemName : [] }), (...args) => {
|
|
77
|
+
operationsRef.current = args;
|
|
78
|
+
return args[0].map((field, index) => /* @__PURE__ */ React.createElement(
|
|
79
|
+
PathContext.Provider,
|
|
80
|
+
{
|
|
81
|
+
value: {
|
|
82
|
+
relativePath: [field.name],
|
|
83
|
+
fullPath: [...fullFormItemName != null ? fullFormItemName : [], field.name]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
/* @__PURE__ */ React.createElement(DataProvider, { name: "currentField", data: field }, /* @__PURE__ */ React.createElement(DataProvider, { name: "currentFieldIndex", data: index }, repeatedElement(index, props.children)))
|
|
87
|
+
));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export { FormListWrapper };
|
|
92
|
+
//# sourceMappingURL=FormList.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormList.esm.js","sources":["../src/form/FormList.tsx"],"sourcesContent":["import {\n DataProvider,\n repeatedElement,\n usePlasmicCanvasContext,\n} from \"@plasmicapp/host\";\nimport { Form } from \"antd\";\nimport type { FormListOperation, FormListProps } from \"antd/es/form/FormList\";\nimport React from \"react\";\nimport {\n InternalFormInstanceContext,\n PathContext,\n useFormInstanceMaybe,\n useFormItemFullName,\n useFormItemRelativeName,\n} from \"./contexts\";\n\nconst FormList = Form.List;\n\ntype FormListWrapperProps = Omit<FormListProps, \"children\"> & {\n children: React.ReactNode;\n};\n\ntype FormListRenderFuncParams = Parameters<FormListProps[\"children\"]>;\n\nexport const FormListWrapper = React.forwardRef(function FormListWrapper(\n props: FormListWrapperProps,\n ref: React.Ref<FormListOperation>\n) {\n const relativeFormItemName = useFormItemRelativeName(props.name);\n const fullFormItemName = useFormItemFullName(props.name);\n const operationsRef = React.useRef<FormListRenderFuncParams | undefined>(\n undefined\n );\n React.useImperativeHandle(\n ref,\n () => ({\n add(defaultValue, insertIndex) {\n if (operationsRef.current) {\n const { add } = operationsRef.current[1];\n add(defaultValue, insertIndex);\n }\n },\n remove(index) {\n if (operationsRef.current) {\n const { remove } = operationsRef.current[1];\n remove(index);\n }\n },\n move(from, to) {\n if (operationsRef.current) {\n const { move } = operationsRef.current[1];\n move(from, to);\n }\n },\n }),\n [operationsRef]\n );\n const inCanvas = !!usePlasmicCanvasContext();\n if (inCanvas) {\n const form = useFormInstanceMaybe();\n const prevPropValues = React.useRef({\n initialValue: props.initialValue,\n name: props.name,\n });\n const { fireOnValuesChange, forceRemount } =\n React.useContext(InternalFormInstanceContext) ?? {};\n React.useEffect(() => {\n if (prevPropValues.current.name !== props.name) {\n forceRemount?.();\n }\n if (fullFormItemName) {\n form?.setFieldValue(fullFormItemName, props.initialValue);\n prevPropValues.current.initialValue = props.initialValue;\n fireOnValuesChange?.();\n }\n }, [JSON.stringify(props.initialValue), JSON.stringify(fullFormItemName)]);\n }\n return (\n <FormList {...props} name={relativeFormItemName ?? []}>\n {(...args) => {\n operationsRef.current = args;\n return args[0].map((field, index) => (\n <PathContext.Provider\n value={{\n relativePath: [field.name],\n fullPath: [...(fullFormItemName ?? []), field.name],\n }}\n >\n <DataProvider name={\"currentField\"} data={field}>\n <DataProvider name={\"currentFieldIndex\"} data={index}>\n {repeatedElement(index, props.children)}\n </DataProvider>\n </DataProvider>\n </PathContext.Provider>\n ));\n }}\n </FormList>\n );\n});\n"],"names":["FormListWrapper"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,WAAW,IAAK,CAAA,IAAA,CAAA;AAQf,MAAM,kBAAkB,KAAM,CAAA,UAAA,CAAW,SAASA,gBAAAA,CACvD,OACA,GACA,EAAA;AA3BF,EAAA,IAAA,EAAA,CAAA;AA4BE,EAAM,MAAA,oBAAA,GAAuB,uBAAwB,CAAA,KAAA,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